print_check "$name"
- if ! ./bin/onyx --use-post-mvp-features "$test_file" -o "./tests/$name.wasm" >/dev/null; then
+ if ! ./bin/onyx -r js --use-post-mvp-features "$test_file" -o "./tests/$name.wasm" >/dev/null; then
print "\n❌ Failed to compile $name.onyx.\n"
failed=1
continue
+++ /dev/null
-package core.io
-
-use package core
-use package wasi as wasi
-use package wasi {
- FileDescriptor,
- FDFlags, OFlags, Rights,
- LookupFlags, Errno,
- IOVec, IOVecArray, Size,
- FileStat, Whence
-}
-
-OpenMode :: enum {
- Invalid;
- Read;
- Write;
- Append;
-}
-
-File :: struct {
- fd : FileDescriptor;
-
- mode : OpenMode = OpenMode.Invalid;
- rights : Rights = ~~ 0;
- flags : FDFlags = ~~ 0;
-}
-
-file_open :: (path: str, mode := OpenMode.Read, flags := FDFlags.Sync) -> (File, bool) {
- // Currently the directory's file descriptor appears to always be 3
- DIR_FD :: 3;
-
- // Requesting all of the rights because why not.
- rights :=
- Rights.DataSync
- | Rights.Read
- | Rights.Seek
- | Rights.FdStatSetFlags
- | Rights.Sync
- | Rights.Tell
- | Rights.Write
- | Rights.Advise
- | Rights.Allocate
- | Rights.PathCreateDirectory
- | Rights.PathCreateFile
- | Rights.PathLinkSource
- | Rights.PathLinkTarget
- | Rights.PathOpen
- | Rights.ReadDir
- | Rights.PathReadlink
- | Rights.PathRenameSource
- | Rights.PathRenameTarget
- | Rights.PathFilestatGet
- | Rights.PathFilestateSetSize
- | Rights.PathFilestateSetTimes
- | Rights.FilestatGet
- | Rights.FilestatSetSize
- | Rights.FilestatSetTimes
- | Rights.PathSymlink
- | Rights.PathRemoveDirectory
- | Rights.PathUnlinkFile
- | Rights.PollFDReadWrite;
-
- open_flags := cast(OFlags) 0;
- fd_flags := flags;
-
- switch mode {
- case OpenMode.Write {
- open_flags |= OFlags.Creat | OFlags.Trunc;
- rights |= Rights.Write;
- }
-
- case OpenMode.Append {
- open_flags |= OFlags.Creat;
- rights |= Rights.Write;
- fd_flags |= FDFlags.Append;
- }
-
- case OpenMode.Read {
- rights |= Rights.Read | Rights.Seek | Rights.Tell;
- }
- }
-
- file := File.{ fd = -1 };
-
- if err := wasi.path_open(
- DIR_FD,
- LookupFlags.SymLinkFollow,
- path,
- open_flags,
- rights,
- rights,
- fd_flags,
- ^file.fd);
- err != Errno.Success {
- return file, false;
- }
-
- file.mode = mode;
- file.rights = rights;
- file.flags = fd_flags;
- return file, true;
-}
-
-file_close :: (file: File) -> bool {
- if wasi.fd_close(file.fd) != Errno.Success {
- return false;
- }
-
- return true;
-}
-
-file_write :: (file: File, data: str) {
- vec := IOVec.{ buf = cast(u32) data.data, len = data.count };
- tmp : Size;
- wasi.fd_write(file.fd, IOVecArray.{ cast(u32) ^vec, 1 }, ^tmp);
- wasi.fd_datasync(file.fd);
-}
-
-get_size :: (file: File) -> u64 {
- fs: FileStat;
- if wasi.fd_filestat_get(file.fd, ^fs) != Errno.Success do return 0;
-
- return fs.size;
-}
-
-get_contents_from_file :: (file: File) -> str {
- size := cast(u32) get_size(file);
-
- data := cast(^u8) raw_alloc(context.allocator, size);
-
- prev_loc: i64;
- wasi.fd_tell(file.fd, ^prev_loc);
-
- dummy: i64;
- wasi.fd_seek(file.fd, 0, Whence.Set, ^dummy);
-
- dummy2: u32;
- buf := IOVec.{ cast(u32) data, size };
- wasi.fd_pread(file.fd, IOVecArray.{ cast(u32) ^buf, 1 }, 0, ^dummy2);
-
- wasi.fd_seek(file.fd, prev_loc, Whence.Set, ^dummy);
-
- return data[0 .. size];
-}
-
-get_contents :: proc {
- get_contents_from_file,
-
- proc (path: str) -> str {
- tmp_file, success := file_open(path, OpenMode.Read);
- if !success do return str.{ null, 0 };
- defer file_close(tmp_file);
-
- return get_contents(tmp_file);
- }
-}
-
-FileStream :: struct {
- use stream : Stream;
- use file : File;
-}
-
-open :: (path: str, mode := OpenMode.Read) -> (Error, FileStream) {
- fs := FileStream.{
- stream = Stream.{ vtable = null },
- file = File.{ fd = -1 },
- };
-
- file, success := file_open(path, mode);
- if !success do return Error.NotFound, fs;
-
- fs.file = file;
- fs.vtable = ^file_stream_vtable;
- return Error.None, fs;
-}
-
-#private
-file_stream_vtable := Stream_Vtable.{
- seek = (use fs: ^FileStream, to: i32, whence: SeekFrom) -> Error {
- // Currently, the new offset is just ignored.
- newoffset : wasi.Filesize;
- error := wasi.fd_seek(file.fd, ~~ to, ~~ whence, ^newoffset);
- if error != Errno.Success do return Error.BadFile;
-
- return Error.None;
- },
-
- tell = (use fs: ^FileStream) -> (Error, u32) {
- location : wasi.Filesize;
- error := wasi.fd_tell(file.fd, ^location);
- if error != Errno.Success do return Error.BadFile, 0;
-
- return Error.None, ~~location;
- },
-
- read = (use fs: ^FileStream, buffer: [] u8) -> (Error, u32) {
- bytes_read : wasi.Size;
- vec := IOVec.{ buf = cast(u32) buffer.data, len = buffer.count };
- error := wasi.fd_read(file.fd, IOVecArray.{ cast(u32) ^vec, 1 }, ^bytes_read);
- if error != Errno.Success do return Error.BadFile, 0;
-
- return Error.None, bytes_read;
- },
-
- read_at = (use fs: ^FileStream, at: u32, buffer: [] u8) -> (Error, u32) {
- bytes_read : wasi.Size;
- vec := IOVec.{ buf = cast(u32) buffer.data, len = buffer.count };
- error := wasi.fd_pread(file.fd, IOVecArray.{ cast(u32) ^vec, 1 }, ~~at, ^bytes_read);
-
- // FIX: Maybe report Error.OutOfBounds if the 'at' was out of bounds?
- if error != Errno.Success do return Error.BadFile, 0;
-
- return Error.None, bytes_read;
- },
-
- read_byte = (use fs: ^FileStream) -> (Error, u8) {
- bytes_read : wasi.Size;
- byte : u8;
- vec := IOVec.{ buf = cast(u32) ^byte, len = 1};
- error := wasi.fd_read(file.fd, IOVecArray.{ cast(u32) ^vec, 1 }, ^bytes_read);
- if error != Errno.Success do return Error.BadFile, 0;
-
- return Error.None, byte;
- },
-
- unread_byte = (use fs: ^FileStream) -> Error {
- return Error.NotImplemented;
- },
-
- write = (use fs: ^FileStream, buffer: [] u8) -> (Error, u32) {
- bytes_written : wasi.Size;
- vec := IOVec.{ buf = cast(u32) buffer.data, len = buffer.count };
- error := wasi.fd_write(file.fd, IOVecArray.{ cast(u32) ^vec, 1 }, ^bytes_written);
- if error != Errno.Success do return Error.BadFile, 0;
-
- return Error.None, bytes_written;
- },
-
- write_at = (use fs: ^FileStream, at: u32, buffer: [] u8) -> (Error, u32) {
- bytes_written : wasi.Size;
- vec := IOVec.{ buf = cast(u32) buffer.data, len = buffer.count };
- error := wasi.fd_pwrite(file.fd, IOVecArray.{ cast(u32) ^vec, 1 }, ~~at, ^bytes_written);
-
- // FIX: Maybe report Error.OutOfBounds if the 'at' was out of bounds?
- if error != Errno.Success do return Error.BadFile, 0;
-
- return Error.None, bytes_written;
- },
-
- write_byte = (use fs: ^FileStream, byte: u8) -> Error {
- bytes_written : wasi.Size;
- byte_to_write := byte;
- vec := IOVec.{ buf = cast(u32) ^byte_to_write, len = 1 };
- error := wasi.fd_write(file.fd, IOVecArray.{ cast(u32) ^vec, 1 }, ^bytes_written);
- if error != Errno.Success do return Error.BadFile;
-
- return Error.None;
- },
-
- close = (use fs: ^FileStream) -> Error {
- file_close(file);
- return Error.None;
- },
-
- flush = (use fs: ^FileStream) -> Error {
- wasi.fd_datasync(file.fd);
- return Error.None;
- },
-
- size = (use fs: ^FileStream) -> i32 {
- file_stat: FileStat;
- if wasi.fd_filestat_get(file.fd, ^file_stat) != Errno.Success do return 0;
-
- return ~~ file_stat.size;
- },
-}
--- /dev/null
+package core.io
+
+use package build_opts as build_opts
+#if build_opts.Runtime != build_opts.Runtime_Wasi {
+ #error "The file system library is currently only available on the WASI runtime, and should only be included if that is the chosen runtime."
+}
+
+use package core
+use package wasi as wasi
+use package wasi {
+ FileDescriptor,
+ FDFlags, OFlags, Rights,
+ LookupFlags, Errno,
+ IOVec, IOVecArray, Size,
+ FileStat, Whence
+}
+
+OpenMode :: enum {
+ Invalid;
+ Read;
+ Write;
+ Append;
+}
+
+File :: struct {
+ fd : FileDescriptor;
+
+ mode : OpenMode = OpenMode.Invalid;
+ rights : Rights = ~~ 0;
+ flags : FDFlags = ~~ 0;
+}
+
+file_open :: (path: str, mode := OpenMode.Read, flags := FDFlags.Sync) -> (File, bool) {
+ // Currently the directory's file descriptor appears to always be 3
+ DIR_FD :: 3;
+
+ // Requesting all of the rights because why not.
+ rights :=
+ Rights.DataSync
+ | Rights.Read
+ | Rights.Seek
+ | Rights.FdStatSetFlags
+ | Rights.Sync
+ | Rights.Tell
+ | Rights.Write
+ | Rights.Advise
+ | Rights.Allocate
+ | Rights.PathCreateDirectory
+ | Rights.PathCreateFile
+ | Rights.PathLinkSource
+ | Rights.PathLinkTarget
+ | Rights.PathOpen
+ | Rights.ReadDir
+ | Rights.PathReadlink
+ | Rights.PathRenameSource
+ | Rights.PathRenameTarget
+ | Rights.PathFilestatGet
+ | Rights.PathFilestateSetSize
+ | Rights.PathFilestateSetTimes
+ | Rights.FilestatGet
+ | Rights.FilestatSetSize
+ | Rights.FilestatSetTimes
+ | Rights.PathSymlink
+ | Rights.PathRemoveDirectory
+ | Rights.PathUnlinkFile
+ | Rights.PollFDReadWrite;
+
+ open_flags := cast(OFlags) 0;
+ fd_flags := flags;
+
+ switch mode {
+ case OpenMode.Write {
+ open_flags |= OFlags.Creat | OFlags.Trunc;
+ rights |= Rights.Write;
+ }
+
+ case OpenMode.Append {
+ open_flags |= OFlags.Creat;
+ rights |= Rights.Write;
+ fd_flags |= FDFlags.Append;
+ }
+
+ case OpenMode.Read {
+ rights |= Rights.Read | Rights.Seek | Rights.Tell;
+ }
+ }
+
+ file := File.{ fd = -1 };
+
+ if err := wasi.path_open(
+ DIR_FD,
+ LookupFlags.SymLinkFollow,
+ path,
+ open_flags,
+ rights,
+ rights,
+ fd_flags,
+ ^file.fd);
+ err != Errno.Success {
+ return file, false;
+ }
+
+ file.mode = mode;
+ file.rights = rights;
+ file.flags = fd_flags;
+ return file, true;
+}
+
+file_close :: (file: File) -> bool {
+ if wasi.fd_close(file.fd) != Errno.Success {
+ return false;
+ }
+
+ return true;
+}
+
+file_write :: (file: File, data: str) {
+ vec := IOVec.{ buf = cast(u32) data.data, len = data.count };
+ tmp : Size;
+ wasi.fd_write(file.fd, IOVecArray.{ cast(u32) ^vec, 1 }, ^tmp);
+ wasi.fd_datasync(file.fd);
+}
+
+get_size :: (file: File) -> u64 {
+ fs: FileStat;
+ if wasi.fd_filestat_get(file.fd, ^fs) != Errno.Success do return 0;
+
+ return fs.size;
+}
+
+get_contents_from_file :: (file: File) -> str {
+ size := cast(u32) get_size(file);
+
+ data := cast(^u8) raw_alloc(context.allocator, size);
+
+ prev_loc: i64;
+ wasi.fd_tell(file.fd, ^prev_loc);
+
+ dummy: i64;
+ wasi.fd_seek(file.fd, 0, Whence.Set, ^dummy);
+
+ dummy2: u32;
+ buf := IOVec.{ cast(u32) data, size };
+ wasi.fd_pread(file.fd, IOVecArray.{ cast(u32) ^buf, 1 }, 0, ^dummy2);
+
+ wasi.fd_seek(file.fd, prev_loc, Whence.Set, ^dummy);
+
+ return data[0 .. size];
+}
+
+get_contents :: proc {
+ get_contents_from_file,
+
+ proc (path: str) -> str {
+ tmp_file, success := file_open(path, OpenMode.Read);
+ if !success do return str.{ null, 0 };
+ defer file_close(tmp_file);
+
+ return get_contents(tmp_file);
+ }
+}
+
+FileStream :: struct {
+ use stream : Stream;
+ use file : File;
+}
+
+open :: (path: str, mode := OpenMode.Read) -> (Error, FileStream) {
+ fs := FileStream.{
+ stream = Stream.{ vtable = null },
+ file = File.{ fd = -1 },
+ };
+
+ file, success := file_open(path, mode);
+ if !success do return Error.NotFound, fs;
+
+ fs.file = file;
+ fs.vtable = ^file_stream_vtable;
+ return Error.None, fs;
+}
+
+#private
+file_stream_vtable := Stream_Vtable.{
+ seek = (use fs: ^FileStream, to: i32, whence: SeekFrom) -> Error {
+ // Currently, the new offset is just ignored.
+ newoffset : wasi.Filesize;
+ error := wasi.fd_seek(file.fd, ~~ to, ~~ whence, ^newoffset);
+ if error != Errno.Success do return Error.BadFile;
+
+ return Error.None;
+ },
+
+ tell = (use fs: ^FileStream) -> (Error, u32) {
+ location : wasi.Filesize;
+ error := wasi.fd_tell(file.fd, ^location);
+ if error != Errno.Success do return Error.BadFile, 0;
+
+ return Error.None, ~~location;
+ },
+
+ read = (use fs: ^FileStream, buffer: [] u8) -> (Error, u32) {
+ bytes_read : wasi.Size;
+ vec := IOVec.{ buf = cast(u32) buffer.data, len = buffer.count };
+ error := wasi.fd_read(file.fd, IOVecArray.{ cast(u32) ^vec, 1 }, ^bytes_read);
+ if error != Errno.Success do return Error.BadFile, 0;
+
+ return Error.None, bytes_read;
+ },
+
+ read_at = (use fs: ^FileStream, at: u32, buffer: [] u8) -> (Error, u32) {
+ bytes_read : wasi.Size;
+ vec := IOVec.{ buf = cast(u32) buffer.data, len = buffer.count };
+ error := wasi.fd_pread(file.fd, IOVecArray.{ cast(u32) ^vec, 1 }, ~~at, ^bytes_read);
+
+ // FIX: Maybe report Error.OutOfBounds if the 'at' was out of bounds?
+ if error != Errno.Success do return Error.BadFile, 0;
+
+ return Error.None, bytes_read;
+ },
+
+ read_byte = (use fs: ^FileStream) -> (Error, u8) {
+ bytes_read : wasi.Size;
+ byte : u8;
+ vec := IOVec.{ buf = cast(u32) ^byte, len = 1};
+ error := wasi.fd_read(file.fd, IOVecArray.{ cast(u32) ^vec, 1 }, ^bytes_read);
+ if error != Errno.Success do return Error.BadFile, 0;
+
+ return Error.None, byte;
+ },
+
+ unread_byte = (use fs: ^FileStream) -> Error {
+ return Error.NotImplemented;
+ },
+
+ write = (use fs: ^FileStream, buffer: [] u8) -> (Error, u32) {
+ bytes_written : wasi.Size;
+ vec := IOVec.{ buf = cast(u32) buffer.data, len = buffer.count };
+ error := wasi.fd_write(file.fd, IOVecArray.{ cast(u32) ^vec, 1 }, ^bytes_written);
+ if error != Errno.Success do return Error.BadFile, 0;
+
+ return Error.None, bytes_written;
+ },
+
+ write_at = (use fs: ^FileStream, at: u32, buffer: [] u8) -> (Error, u32) {
+ bytes_written : wasi.Size;
+ vec := IOVec.{ buf = cast(u32) buffer.data, len = buffer.count };
+ error := wasi.fd_pwrite(file.fd, IOVecArray.{ cast(u32) ^vec, 1 }, ~~at, ^bytes_written);
+
+ // FIX: Maybe report Error.OutOfBounds if the 'at' was out of bounds?
+ if error != Errno.Success do return Error.BadFile, 0;
+
+ return Error.None, bytes_written;
+ },
+
+ write_byte = (use fs: ^FileStream, byte: u8) -> Error {
+ bytes_written : wasi.Size;
+ byte_to_write := byte;
+ vec := IOVec.{ buf = cast(u32) ^byte_to_write, len = 1 };
+ error := wasi.fd_write(file.fd, IOVecArray.{ cast(u32) ^vec, 1 }, ^bytes_written);
+ if error != Errno.Success do return Error.BadFile;
+
+ return Error.None;
+ },
+
+ close = (use fs: ^FileStream) -> Error {
+ file_close(file);
+ return Error.None;
+ },
+
+ flush = (use fs: ^FileStream) -> Error {
+ wasi.fd_datasync(file.fd);
+ return Error.None;
+ },
+
+ size = (use fs: ^FileStream) -> i32 {
+ file_stat: FileStat;
+ if wasi.fd_filestat_get(file.fd, ^file_stat) != Errno.Success do return 0;
+
+ return ~~ file_stat.size;
+ },
+}
--- /dev/null
+package core
+
+
+#load "core/build_opts"
+
+#load "core/alloc"
+#load "core/memory"
+
+#load "core/array"
+#load "core/map"
+
+#load "core/conv"
+#load "core/math"
+#load "core/random"
+
+#load "core/string"
+#load "core/string/builder"
+#load "core/string/reader"
+
+#load "core/intrinsics/wasm"
+
+#load "core/io/io"
+#load "core/io/stream"
+#load "core/io/reader"
+#load "core/io/writer"
+#load "core/io/binary"
+
+use package build_opts as build_opts
+#if build_opts.Runtime == build_opts.Runtime_Wasi {
+ #load "core/sys/wasi"
+ #load "core/wasi"
+ #load "core/io/file"
+}
+
+#if build_opts.Runtime == build_opts.Runtime_Js {
+ #load "core/sys/js"
+}
+
+#if build_opts.Runtime != build_opts.Runtime_Custom {
+ #load "core/stdio"
+}
+++ /dev/null
-package core
-
-
-
-#load "core/alloc"
-#load "core/array"
-#load "core/conv"
-#load "core/intrinsics/wasm"
-#load "core/map"
-#load "core/math"
-#load "core/memory"
-#load "core/random"
-#load "core/stdio"
-#load "core/string"
-#load "core/string/builder"
-#load "core/string/reader"
-
-#load "core/io/io"
-#load "core/io/stream"
-#load "core/io/reader"
-#load "core/io/writer"
-
-#load "core/sys/js"
-
-
+++ /dev/null
-package core
-
-
-
-#load "core/alloc"
-#load "core/array"
-#load "core/conv"
-#load "core/file"
-#load "core/intrinsics/wasm"
-#load "core/map"
-#load "core/math"
-#load "core/memory"
-#load "core/random"
-#load "core/stdio"
-#load "core/string"
-#load "core/string/builder"
-#load "core/string/reader"
-#load "core/wasi"
-
-#load "core/io/io"
-#load "core/io/stream"
-#load "core/io/reader"
-#load "core/io/writer"
-#load "core/io/binary"
-
-#load "core/sys/wasi"
-
-
// It is expected that a file will be included that will be part
// of the system package
-use package system as system
+
+use package build_opts as build_opts
+#if build_opts.Runtime != build_opts.Runtime_Custom {
+ use package system as system
+} else {
+ #error "'stdio' can only be included in the 'wasi' or 'js' runtime."
+}
#private_file print_stream : io.DynamicStringStream;
#private_file print_writer : io.Writer;
// added to the queue of files to load. When all files in the queue have been parsed,
// the compiler can continue with the compilation process. You can also include the
// same file as many times as you want. The redudant copies will be discarded.
-#load "core/std/wasi"
+#load "core/std"
// All of the functionality we need is in the 'core' package. Unlike other package systems,
// there is no way to reference symbols in a package without specifically 'using' it. This
// This time, we are not adding, 'package main' to the top of the file, since
// every file is automatically part of the main package unless specified otherwise.
-#load "core/std/wasi"
+#load "core/std"
use package core
// Now, lets go over the basic types and control flow mechanisms in Onyx.
-#load "core/std/wasi"
+#load "core/std"
use package core
// This file will give examples of all of these things, as well as some of the gotchas
// you need to be aware of.
-#load "core/std/wasi"
+#load "core/std"
use package core
// is a powerful construct to have. In fact, strings in Onyx, i.e.
// the 'str' type, is actually just a slice of u8.
-#load "core/std/wasi"
+#load "core/std"
use package core
// Dynamic arrays in Onyx are easy to use on purpose, because I
// know how useful they are in almost every program I write.
-#load "core/std/wasi"
+#load "core/std"
use package core
// 'structs' in Onyx are very similar to structs in C and C++, with a couple
// of additional capabilities to make using them even easier.
-#load "core/std/wasi"
+#load "core/std"
use package core
// Enumerations (or enums for short) in Onyx work very similar to how they do
// in C and C++.
-#load "core/std/wasi"
+#load "core/std"
use package core
// in Onyx are extremely simple to use by design and should make programming very
// enjoyable. But I digress, let's look at some examples.
-#load "core/std/wasi"
+#load "core/std"
use package core
-#load "core/std/wasi"
+#load "core/std"
use package core
-#load "core/std/wasi"
+#load "core/std"
use package core
-#load "core/std/wasi"
+#load "core/std"
use package core
-#load "core/std/wasi"
+#load "core/std"
use package core
-#load "core/std/wasi"
+#load "core/std"
use package core
-#load "core/std/wasi"
+#load "core/std"
use package core
-#load "core/std/wasi"
+#load "core/std"
use package core { println }
ONYX_COMPILE_ACTION_PRINT_HELP,
};
+
+// ROBUSTNESS: The Runtime definitions here must match those in build_opts.onyx!!
+typedef enum Runtime Runtime;
+enum Runtime {
+ Runtime_Unknown = 0,
+ Runtime_Wasi = 1,
+ Runtime_Js = 2,
+ Runtime_Custom = 3,
+};
+
+
typedef struct CompileOptions CompileOptions;
struct CompileOptions {
bh_allocator allocator;
b32 use_post_mvp_features : 1;
+ Runtime runtime;
+
bh_arr(const char *) included_folders;
bh_arr(const char *) files;
const char* target_file;
-#load "core/std/wasi"
+#load "core/std"
#load "progs/foo_test"
use package core
package main
-#load "core/std/wasi"
+#load "core/std"
#load "core/intrinsics/simd"
use package core
-#load "core/std/wasi"
+#load "core/std"
use package core
package main
-#load "core/std/wasi"
+#load "core/std"
#load "core/intrinsics/simd"
use package core
package main
-#load "core/std/wasi"
+#load "core/std"
use package core;
package main
-#load "core/std/wasi"
+#load "core/std"
// NOTE: Didn't realize this would work so easily
use package core { string_builder_append as sba }
"Flags:\n"
"\t<input files> List of initial files\n"
"\t-o <target_file> Specify the target file (default: out.wasm)\n"
+ "\t-r <runtime> Specifies a runtime. Can be: wasi, js, custom.\n"
"\t--verbose Verbose output\n";
static CompileOptions compile_opts_parse(bh_allocator alloc, int argc, char *argv[]) {
.print_function_mappings = 0,
.use_post_mvp_features = 0,
+ .runtime = Runtime_Wasi,
+
.files = NULL,
.target_file = "out.wasm",
};
else if (!strcmp(argv[i], "-I")) {
bh_arr_push(options.included_folders, argv[++i]);
}
+ else if (!strcmp(argv[i], "-r")) {
+ i += 1;
+ if (!strcmp(argv[i], "wasi")) options.runtime = Runtime_Wasi;
+ else if (!strcmp(argv[i], "js")) options.runtime = Runtime_Js;
+ else if (!strcmp(argv[i], "custom")) options.runtime = Runtime_Custom;
+ else {
+ bh_printf("WARNING: '%s' is not a valid runtime. Defaulting to 'wasi'.\n", argv[i]);
+ options.runtime = Runtime_Wasi;
+ }
+ }
#if defined(_BH_LINUX)
// NOTE: Fun output is only enabled for Linux because Windows command line
// is not ANSI compatible and for a silly feature, I don't want to learn
#define REDUCE_UNOP_INT(op) \
if (type_is_small_integer(unop->type) || type_is_bool(unop->type)) { \
res->value.i = op ((AstNumLit *) unop->expr)->value.i; \
- } else if (type_is_integer(unop->type)) { \
+ } else if (type_is_integer(unop->type) || res->type->Basic.kind == Basic_Kind_Int_Unsized) { \
res->value.l = op ((AstNumLit *) unop->expr)->value.l; \
}
void introduce_build_options(bh_allocator a) {
Package* p = package_lookup_or_create("build_opts", context.global_scope, a);
- AstNumLit* runtime_type = make_int_literal(a, 1);
+ AstNumLit* runtime_type = make_int_literal(a, context.options->runtime);
symbol_builtin_introduce(p->scope, "Runtime", (AstNode *) runtime_type);
}
\ No newline at end of file
-#load "core/std/js"
+#load "core/std"
use package core
-#load "core/std/js"
+#load "core/std"
use package core
use package core.string.reader as reader
-#load "core/std/js"
+#load "core/std"
use package core
use package core.string.reader as reader
-#load "core/std/js"
+#load "core/std"
use package core
use package core.string.reader as reader
-#load "core/std/js"
+#load "core/std"
use package core
use package core.string.reader as reader
-#load "core/std/js"
+#load "core/std"
use package core
use package core.string.reader as reader
-#load "core/std/js"
+#load "core/std"
use package core
use package core.string.reader as reader
-#load "core/std/js"
+#load "core/std"
use package core
use package core.string.reader as reader
-#load "core/std/js"
+#load "core/std"
use package core
use package core.string.reader as reader
-#load "core/std/js"
+#load "core/std"
use package core
use package core.string.reader as reader
-#load "core/std/js"
+#load "core/std"
use package core
use package core.string.reader as reader
package main
-#load "core/std/js"
+#load "core/std"
use package core
-#load "core/std/js"
+#load "core/std"
use package core
use package core.string.reader as reader
-#load "core/std/js"
+#load "core/std"
use package core
use package core.string.reader as reader
-#load "core/std/js"
+#load "core/std"
use package core
use package core.string.reader as reader
-#load "core/std/js"
+#load "core/std"
use package core
-#load "core/std/js"
+#load "core/std"
use package core
use package core.string.reader as reader
-#load "core/std/js"
+#load "core/std"
use package core
use package core.string.reader as reader
-#load "core/std/js"
+#load "core/std"
use package core
-#load "core/std/js"
+#load "core/std"
use package core
-#load "core/std/js"
+#load "core/std"
use package core
-#load "core/std/js"
+#load "core/std"
use package core
-#load "core/std/js"
+#load "core/std"
use package core
use package core.string.reader as reader
-#load "core/std/js"
+#load "core/std"
use package core
use package core.string.reader as reader
-#load "core/std/js"
+#load "core/std"
use package core
use package core.string.reader as reader
-#load "core/std/js"
+#load "core/std"
use package core
-#load "core/std/js"
+#load "core/std"
use package core
-#load "core/std/js"
+#load "core/std"
use package core
-#load "core/std/js"
+#load "core/std"
use package core
package main
-#load "core/std/js"
+#load "core/std"
use package core
package main
-#load "core/std/js"
+#load "core/std"
use package core
package main
-#load "core/std/js"
+#load "core/std"
use package core
-#load "core/std/js"
+#load "core/std"
use package core
-#load "core/std/js"
+#load "core/std"
use package core
// This is a needlessly complicated test of some of the newer features with structs.
-#load "core/std/js"
+#load "core/std"
use package core
-#load "core/std/js"
+#load "core/std"
use package core
-#load "core/std/js"
+#load "core/std"
use package core
-#load "core/std/js"
+#load "core/std"
use package core
-#load "core/std/js"
+#load "core/std"
use package core
-#load "core/std/js"
+#load "core/std"
use package core
+#load "core/std"
+
use package core
main :: proc (args: [] cstr) {
printf("PolyUnion(%i)\n", pu.r_data);
}
}
-
-#load "core/std/js"
\ No newline at end of file
package main
-#load "core/std/js"
+#load "core/std"
use package core;