Skip to content
This repository has been archived by the owner on Oct 12, 2022. It is now read-only.

Commit

Permalink
WIP: wasi support
Browse files Browse the repository at this point in the history
  • Loading branch information
skoppe committed Aug 22, 2019
1 parent e9cdc29 commit f6d0b9e
Show file tree
Hide file tree
Showing 20 changed files with 555 additions and 5 deletions.
31 changes: 31 additions & 0 deletions src/core/stdc/config.d
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,37 @@ else version (Posix)
alias ulong cpp_ulonglong;
}
}
else version (WebAssembly)
{
static if ( (void*).sizeof > int.sizeof )
{
enum __c_longlong : long;
enum __c_ulonglong : ulong;

alias long c_long;
alias ulong c_ulong;

alias long cpp_long;
alias ulong cpp_ulong;

alias __c_longlong cpp_longlong;
alias __c_ulonglong cpp_ulonglong;
}
else
{
enum __c_long : int;
enum __c_ulong : uint;

alias int c_long;
alias uint c_ulong;

alias __c_long cpp_long;
alias __c_ulong cpp_ulong;

alias long cpp_longlong;
alias ulong cpp_ulonglong;
}
}

version (CRuntime_Microsoft)
{
Expand Down
137 changes: 137 additions & 0 deletions src/core/stdc/errno.d
Original file line number Diff line number Diff line change
Expand Up @@ -2037,6 +2037,143 @@ else version (Haiku)
enum B_NO_TRANSLATOR = (B_TRANSLATION_ERROR_BASE + 1);
enum B_ILLEGAL_DATA = (B_TRANSLATION_ERROR_BASE + 2);
}
else version(WebAssembly)
{
enum EPERM = 1;
enum ENOENT = 2;
enum ESRCH = 3;
enum EINTR = 4;
enum EIO = 5;
enum ENXIO = 6;
enum E2BIG = 7;
enum ENOEXEC = 8;
enum EBADF = 9;
enum ECHILD = 10;
enum EAGAIN = 11;
enum ENOMEM = 12;
enum EACCES = 13;
enum EFAULT = 14;
enum ENOTBLK = 15;
enum EBUSY = 16;
enum EEXIST = 17;
enum EXDEV = 18;
enum ENODEV = 19;
enum ENOTDIR = 20;
enum EISDIR = 21;
enum EINVAL = 22;
enum ENFILE = 23;
enum EMFILE = 24;
enum ENOTTY = 25;
enum ETXTBSY = 26;
enum EFBIG = 27;
enum ENOSPC = 28;
enum ESPIPE = 29;
enum EROFS = 30;
enum EMLINK = 31;
enum EPIPE = 32;
enum EDOM = 33;
enum ERANGE = 34;
enum EDEADLK = 35;
enum ENAMETOOLONG = 36;
enum ENOLCK = 37;
enum ENOSYS = 38;
enum ENOTEMPTY = 39;
enum ELOOP = 40;
enum EWOULDBLOCK = EAGAIN;
enum ENOMSG = 42;
enum EIDRM = 43;
enum ECHRNG = 44;
enum EL2NSYNC = 45;
enum EL3HLT = 46;
enum EL3RST = 47;
enum ELNRNG = 48;
enum EUNATCH = 49;
enum ENOCSI = 50;
enum EL2HLT = 51;
enum EBADE = 52;
enum EBADR = 53;
enum EXFULL = 54;
enum ENOANO = 55;
enum EBADRQC = 56;
enum EBADSLT = 57;
enum EDEADLOCK = EDEADLK;
enum EBFONT = 59;
enum ENOSTR = 60;
enum ENODATA = 61;
enum ETIME = 62;
enum ENOSR = 63;
enum ENONET = 64;
enum ENOPKG = 65;
enum EREMOTE = 66;
enum ENOLINK = 67;
enum EADV = 68;
enum ESRMNT = 69;
enum ECOMM = 70;
enum EPROTO = 71;
enum EMULTIHOP = 72;
enum EDOTDOT = 73;
enum EBADMSG = 74;
enum EOVERFLOW = 75;
enum ENOTUNIQ = 76;
enum EBADFD = 77;
enum EREMCHG = 78;
enum ELIBACC = 79;
enum ELIBBAD = 80;
enum ELIBSCN = 81;
enum ELIBMAX = 82;
enum ELIBEXEC = 83;
enum EILSEQ = 84;
enum ERESTART = 85;
enum ESTRPIPE = 86;
enum EUSERS = 87;
enum ENOTSOCK = 88;
enum EDESTADDRREQ = 89;
enum EMSGSIZE = 90;
enum EPROTOTYPE = 91;
enum ENOPROTOOPT = 92;
enum EPROTONOSUPPORT = 93;
enum ESOCKTNOSUPPORT = 94;
enum EOPNOTSUPP = 95;
enum ENOTSUP = EOPNOTSUPP;
enum EPFNOSUPPORT = 96;
enum EAFNOSUPPORT = 97;
enum EADDRINUSE = 98;
enum EADDRNOTAVAIL = 99;
enum ENETDOWN = 100;
enum ENETUNREACH = 101;
enum ENETRESET = 102;
enum ECONNABORTED = 103;
enum ECONNRESET = 104;
enum ENOBUFS = 105;
enum EISCONN = 106;
enum ENOTCONN = 107;
enum ESHUTDOWN = 108;
enum ETOOMANYREFS = 109;
enum ETIMEDOUT = 110;
enum ECONNREFUSED = 111;
enum EHOSTDOWN = 112;
enum EHOSTUNREACH = 113;
enum EALREADY = 114;
enum EINPROGRESS = 115;
enum ESTALE = 116;
enum EUCLEAN = 117;
enum ENOTNAM = 118;
enum ENAVAIL = 119;
enum EISNAM = 120;
enum EREMOTEIO = 121;
enum EDQUOT = 122;
enum ENOMEDIUM = 123;
enum EMEDIUMTYPE = 124;
enum ECANCELED = 125;
enum ENOKEY = 126;
enum EKEYEXPIRED = 127;
enum EKEYREVOKED = 128;
enum EKEYREJECTED = 129;
enum EOWNERDEAD = 130;
enum ENOTRECOVERABLE = 131;
enum ERFKILL = 132;
enum EHWPOISON = 133;
}
else
{
static assert(false, "Unsupported platform");
Expand Down
20 changes: 18 additions & 2 deletions src/core/stdc/fenv.d
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,14 @@ else version (CRuntime_Musl)
}
alias ushort fexcept_t;
}
else
else version(WebAssembly)
{
struct fenv_t
{
ulong __cw;
}
alias ulong fexcept_t;
} else
{
static assert(false, "Architecture not supported.");
}
Expand Down Expand Up @@ -783,11 +790,20 @@ else
FE_TOWARDZERO = 0x1, ///
}
}
else version (WebAssembly)
{
enum
{
FE_TONEAREST = 0x0, ///
FE_DOWNWARD = 0x3, /// don't known about these...
FE_UPWARD = 0x2, /// ...
FE_TOWARDZERO = 0x1, /// ...
}
}
else
{
static assert(0, "Unimplemented architecture");
}

}

version (GNUFP)
Expand Down
5 changes: 5 additions & 0 deletions src/core/stdc/stddef.d
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,8 @@ else version (Posix)
///
alias dchar wchar_t;
}
else version (WebAssembly)
{
///
alias dchar wchar_t;
}
35 changes: 35 additions & 0 deletions src/core/stdc/stdint.d
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,41 @@ else version (Posix)
alias intmax_t = long; ///
alias uintmax_t = ulong; ///
}
else version (WebAssembly)
{
alias int8_t = byte; ///
alias int16_t = short; ///
alias uint8_t = ubyte; ///
alias uint16_t = ushort; ///
alias int32_t = int; ///
alias uint32_t = uint; ///
alias int64_t = long; ///
alias uint64_t = ulong; ///

alias int_least8_t = byte; ///
alias uint_least8_t = ubyte; ///
alias int_least16_t = short; ///
alias uint_least16_t = ushort; ///
alias int_least32_t = int; ///
alias uint_least32_t = uint; ///
alias int_least64_t = long; ///
alias uint_least64_t = ulong; ///

alias int_fast8_t = byte; ///
alias uint_fast8_t = ubyte; ///
alias int_fast16_t = ptrdiff_t; ///
alias uint_fast16_t = size_t; ///
alias int_fast32_t = ptrdiff_t; ///
alias uint_fast32_t = size_t; ///

alias int_fast64_t = long; ///
alias uint_fast64_t = ulong; ///

alias intptr_t = ptrdiff_t; ///
alias uintptr_t = size_t; ///
alias intmax_t = long; ///
alias uintmax_t = ulong; ///
}
else
{
static assert(0);
Expand Down
72 changes: 72 additions & 0 deletions src/core/stdc/stdio.d
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,24 @@ else version (CRuntime_UClibc)
L_tmpnam = 20
}
}
else version (WebAssembly)
{
enum
{
///
BUFSIZ = 1024,
///
EOF = -1,
///
FOPEN_MAX = 1000,
///
FILENAME_MAX = 4096,
///
TMP_MAX = 10000,
///
L_tmpnam = 20
}
}
else
{
static assert( false, "Unsupported platform" );
Expand Down Expand Up @@ -449,6 +467,20 @@ else version (CRuntime_Glibc)
///
alias shared(_IO_FILE) FILE;
}
else version (WebAssembly)
{
union fpos_t
{
char[16] __opaque = 0;
double __align;
}
struct _IO_FILE;

///
alias _IO_FILE _iobuf; // needed for phobos
///
alias shared(_IO_FILE) FILE;
}
else version (CRuntime_Musl)
{
union fpos_t
Expand Down Expand Up @@ -1126,6 +1158,24 @@ else version (CRuntime_UClibc)
///
extern shared FILE* stderr;
}
else version (WebAssembly)
{
// needs tail const
extern shared FILE* stdin;
///
extern shared FILE* stdout;
///
extern shared FILE* stderr;
enum
{
///
_IOFBF = 0,
///
_IOLBF = 1,
///
_IONBF = 2,
}
}
else
{
static assert( false, "Unsupported platform" );
Expand Down Expand Up @@ -1689,6 +1739,28 @@ else version (CRuntime_UClibc)
///
int vsnprintf(scope char* s, size_t n, scope const char* format, va_list arg);
}
else version (WebAssembly)
{
// No unsafe pointer manipulation.
@trusted
{
///
void rewind(FILE* stream);
///
pure void clearerr(FILE* stream);
///
pure int feof(FILE* stream);
///
pure int ferror(FILE* stream);
///
int fileno(FILE *);
}

///
int snprintf(scope char* s, size_t n, scope const char* format, ...);
///
int vsnprintf(scope char* s, size_t n, scope const char* format, va_list arg);
}
else
{
static assert( false, "Unsupported platform" );
Expand Down
1 change: 1 addition & 0 deletions src/core/stdc/stdlib.d
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ else version (Solaris) enum RAND_MAX = 0x7fff;
else version (CRuntime_Bionic) enum RAND_MAX = 0x7fffffff;
else version (CRuntime_Musl) enum RAND_MAX = 0x7fffffff;
else version (CRuntime_UClibc) enum RAND_MAX = 0x7fffffff;
else version (WebAssembly) enum RAND_MAX = 0x7fffffff;
else static assert( false, "Unsupported platform" );

///
Expand Down
Loading

0 comments on commit f6d0b9e

Please sign in to comment.