@echo off
+REM Compile the compiler
set SOURCE_FILES=src/onyx.c src/astnodes.c src/builtins.c src/checker.c src/clone.c src/doc.c src/entities.c src/errors.c src/lex.c src/parser.c src/symres.c src/types.c src/utils.c src/wasm_emit.c src/wasm_runtime.c
if "%1" == "1" (
set LINK_OPTIONS="%PWD%\lib\windows_x86_64\lib\wasmer.lib" ws2_32.lib Advapi32.lib userenv.lib bcrypt.lib /NODEFAULTLIB:msvcrt.lib /NODEFAULTLIB:libcmtd.lib /NODEFAULTLIB:msvcrtd.lib
set FLAGS=%FLAGS% "/I%PWD%\lib\common\include" /DENABLE_RUN_WITH_WASMER=1
+rc.exe misc/icon_resource.rc
+cl.exe %FLAGS% /Iinclude /std:c17 /TC %SOURCE_FILES% /link /IGNORE:4217 %LINK_OPTIONS% /DEBUG /OUT:onyx.exe /incremental:no /opt:ref /subsystem:console misc\icon_resource.res
+
del *.pdb > NUL 2> NUL
del *.ilk > NUL 2> NUL
+del *.obj > NUL 2> NUL
+del misc\icon_resource.res
+
+REM Compile the onyxrun tool
+set SOURCE_FILES=src/onyxrun.c src/wasm_runtime.c
rc.exe misc/icon_resource.rc
-cl.exe %FLAGS% /Iinclude /std:c17 /TC %SOURCE_FILES% /link /IGNORE:4217 %LINK_OPTIONS% /DEBUG /OUT:onyx.exe /incremental:no /opt:ref /subsystem:console misc\icon_resource.res
+cl.exe %FLAGS% /Iinclude /std:c17 /TC %SOURCE_FILES% /link /IGNORE:4217 %LINK_OPTIONS% /DEBUG /OUT:onyxrun.exe /incremental:no /opt:ref /subsystem:console misc\icon_resource.res
+del *.pdb > NUL 2> NUL
+del *.ilk > NUL 2> NUL
del *.obj > NUL 2> NUL
-del misc\icon_resource.res
\ No newline at end of file
+del misc\icon_resource.res
mkdir -p "$BUILD_DIR"
-for file in $C_FILES ; do
- echo "Compiling $file.c"
- $CC -o $BUILD_DIR/$file.o \
- $FLAGS \
- "-DCORE_INSTALLATION=\"$CORE_DIR\"" \
- -c src/$file.c \
- $INCLUDES $LIBS
-done
-
-echo "Linking $TARGET"
-$CC -o $TARGET $FLAGS $(for file in $C_FILES ; do printf "$BUILD_DIR/%s.o " $file ; done) $LIBS
-
-echo "Removing object files"
-for file in $C_FILES ; do rm -f "$BUILD_DIR/$file".o 2>/dev/null ; done
-
+compile() {
+ for file in $C_FILES ; do
+ echo "Compiling $file.c"
+ $CC -o $BUILD_DIR/$file.o \
+ $FLAGS \
+ "-DCORE_INSTALLATION=\"$CORE_DIR\"" \
+ -c src/$file.c \
+ $INCLUDES $LIBS
+ done
+
+ echo "Linking $TARGET"
+ $CC -o $TARGET $FLAGS $(for file in $C_FILES ; do printf "$BUILD_DIR/%s.o " $file ; done) $LIBS
+
+ echo "Removing object files"
+ for file in $C_FILES ; do rm -f "$BUILD_DIR/$file".o 2>/dev/null ; done
+}
+
+compile
echo "Installing onyx executable"
sudo cp ./bin/onyx "$BIN_DIR/onyx"
+C_FILES="onyxrun wasm_runtime"
+TARGET="./bin/onyxrun"
+
+compile
+echo "Installing onyxrun executable"
+sudo cp ./bin/onyxrun "$BIN_DIR/onyxrun"
+
# Otherwise the prompt ends on the same line
printf "\n"
--- /dev/null
+#define BH_DEFINE
+#define BH_NO_TABLE
+#define STB_DS_IMPLEMENTATION
+#include "bh.h"
+
+#include "wasm_emit.h"
+
+int main(int argc, char *argv[]) {
+ if (argc < 2) {
+ fprintf(stderr, "Expected a WASM file to run.\n");
+ return 1;
+ }
+
+ bh_file wasm_file;
+ bh_file_error err = bh_file_open(&wasm_file, argv[1]);
+ if (err != BH_FILE_ERROR_NONE) {
+ fprintf(stderr, "Failed to open file %s", argv[1]);
+ return 1;
+ }
+
+ bh_file_contents wasm_data = bh_file_read_contents(bh_heap_allocator(), &wasm_file);
+ bh_file_close(&wasm_file);
+
+ bh_buffer data;
+ data.data = wasm_data.data;
+ data.length = wasm_data.length;
+ return onyx_run_wasm(data, argc - 1, argv + 1);
+}
\ No newline at end of file