"Load File",
"Binding (Declaration)",
"Use Package",
+ "Import",
"Static If",
"String Literal",
"File Contents",
if (import->import_package_itself) {
OnyxToken *name = bh_arr_last(package->path);
- name = import->qualified_package_name ?: name; // Had to find somewhere to use the Elvis operator in the codebase :)
+ name = import->qualified_package_name ? import->qualified_package_name : name;
symbol_introduce(
current_entity->scope,
self.state[7] += h;
}
-CH :: macro (x, y, z: u32) => (x & y) ^ (~x & z);
-MAJ :: macro (x, y, z: u32) => (x & y) ^ (x & z) ^ (y & z);
-EP0 :: macro (x: u32) => wasm.rotr_i32(x, 2) ^ wasm.rotr_i32(x, 13) ^ wasm.rotr_i32(x, 22);
-EP1 :: macro (x: u32) => wasm.rotr_i32(x, 6) ^ wasm.rotr_i32(x, 11) ^ wasm.rotr_i32(x, 25);
-SIG0 :: macro (x: u32) => wasm.rotr_i32(x, 7) ^ wasm.rotr_i32(x, 18) ^ ((x) >> 3);
-SIG1 :: macro (x: u32) => wasm.rotr_i32(x, 17) ^ wasm.rotr_i32(x, 19) ^ ((x) >> 10);
+#local {
+ CH :: macro (x, y, z: u32) => (x & y) ^ (~x & z);
+ MAJ :: macro (x, y, z: u32) => (x & y) ^ (x & z) ^ (y & z);
+ EP0 :: macro (x: u32) => wasm.rotr_i32(x, 2) ^ wasm.rotr_i32(x, 13) ^ wasm.rotr_i32(x, 22);
+ EP1 :: macro (x: u32) => wasm.rotr_i32(x, 6) ^ wasm.rotr_i32(x, 11) ^ wasm.rotr_i32(x, 25);
+ SIG0 :: macro (x: u32) => wasm.rotr_i32(x, 7) ^ wasm.rotr_i32(x, 18) ^ ((x) >> 3);
+ SIG1 :: macro (x: u32) => wasm.rotr_i32(x, 17) ^ wasm.rotr_i32(x, 19) ^ ((x) >> 10);
+}
#local
k := u32.[
FLAGS="-Ofast -fno-stack-protector"
LIBS="-pthread"
TARGET="../shared/lib/linux_$(uname -m)/lib/libovmwasm.so"
-C_FILES="src/wasm.c src/vm/*.c src/wasm/*.c src/debug/*.c"
+C_FILES="src/ovmwasm.c src/vm/*.c src/wasm/*.c src/debug/*.c"
INCLUDES="-I../shared/include -Iinclude"
echo "Compiling libovmwasm.so"
+++ /dev/null
-#ifndef _ASSEMBLER_H
-#define _ASSEMBLER_H
-
-typedef enum token_type_t token_type_t;
-typedef struct token_t token_t;
-
-enum token_type_t {
- token_none,
- token_newline,
-
- token_integer,
- token_integer_long,
- token_float,
- token_float_double,
-
- token_command,
- token_symbol,
- token_register,
- token_label,
- token_comma,
-};
-
-struct token_t {
- token_type_t type;
- char *text;
- int line;
-};
-
-token_t asm_lexer_next_token();
-token_t asm_lexer_peek_token();
-void asm_lexer_input(char *data, int size);
-
-extern char *token_names[];
-
-#endif
-
+++ /dev/null
-#include "vm.h"
-
-#include <math.h>
-
-void print_result(void *data, ovm_value_t *params, ovm_value_t *result) {
- switch (params[0].type) {
- case OVM_TYPE_I32: printf("Result: %d\n", params[0].i32); break;
- case OVM_TYPE_F32: printf("Result: %f\n", params[0].f32); break;
- }
-}
-
-void c_call_1f64(void *data, ovm_value_t *params, ovm_value_t *result) {
- result->type = OVM_TYPE_F32;
- result->f32 = (f32) ((f64 (*)(f64)) data)(params[0].f32);
-}
-
-int main(int argc, char *argv[]) {
-
- static ovm_linkable_func_t native_funcs[] = {
- { "dummy", 0, { print_result, NULL } },
- { "print", 1, { print_result, NULL } },
- { "sin", 1, { c_call_1f64, sin } },
- { NULL },
- };
-
- ovm_store_t *store = ovm_store_new();
- ovm_program_t *prog = ovm_program_new(store);
- ovm_engine_t *engine = ovm_engine_new(store);
- ovm_state_t *state = ovm_state_new(engine, prog);
-
- ovm_program_load_from_file(prog, engine, argv[1]);
-
- static int func_table[] = { 0, 1, 6 };
- ovm_program_register_static_ints(prog, 3, func_table);
-
- ovm_state_link_external_funcs(prog, state, native_funcs);
-
- state->pc = 0;
- ovm_value_t values[] = {
- { .type = OVM_TYPE_I32, .i32 = 1 },
- { .type = OVM_TYPE_I32, .i32 = 2 },
- };
- ovm_value_t result = ovm_func_call(engine, state, prog, 5, 0, values);
- // printf("%d %d\n", result.type, result.i32);
-
- ovm_state_delete(state);
- ovm_engine_delete(engine);
- ovm_program_delete(prog);
- ovm_store_delete(store);
-
- return 0;
-}
--- /dev/null
+#define BH_DEFINE
+#define BH_NO_TABLE
+#define BH_INTERNAL
+#define STB_DS_IMPLEMENTATION
+#include "bh.h"
+#include "stb_ds.h"
+
+#include "ovm_wasm.h"
+++ /dev/null
-#define BH_DEFINE
-#define BH_NO_TABLE
-#define BH_INTERNAL
-#define STB_DS_IMPLEMENTATION
-#include "bh.h"
-#include "stb_ds.h"
-
-#include "ovm_wasm.h"
+++ /dev/null
-#define BH_DEFINE
-#include "bh.h"
-#include "wasm.h"
-
-#include "ovm_wasm.h"
-#include "vm.h"
-
-
-int main(int argc, char *argv[]) {
- wasm_config_t *config = wasm_config_new();
-
- // TODO: Add this to public header
- void wasm_config_enable_debug(wasm_config_t *, bool);
- wasm_config_enable_debug(config, true);
-
- wasm_engine_t *engine = wasm_engine_new_with_config(config);
-
- wasm_store_t *store = wasm_store_new(engine);
-
- wasm_byte_vec_t wasm_bytes;
- {
- bh_file_contents contents = bh_file_read_contents(bh_heap_allocator(), argv[1]);
-
- wasm_bytes.size = contents.length;
- wasm_bytes.data = contents.data;
- }
-
- wasm_module_t *module = wasm_module_new(store, &wasm_bytes);
- assert(module);
-
- wasm_importtype_vec_t imports;
- wasm_module_imports(module, &imports);
-
- fori (i, 0, (int) imports.size) {
- const wasm_name_t *module_name = wasm_importtype_module(imports.data[i]);
- const wasm_name_t *import_name = wasm_importtype_name(imports.data[i]);
- bh_printf("imports: %b.%b\n", module_name->data, module_name->size, import_name->data, import_name->size);
- }
-
-
- wasm_exporttype_vec_t exports;
- wasm_module_exports(module, &exports);
-
- fori (i, 0, (int) exports.size) {
- const wasm_name_t *export_name = wasm_exporttype_name(exports.data[i]);
- bh_printf("exports: %b %d\n", export_name->data, export_name->size, wasm_externtype_kind(wasm_exporttype_type(exports.data[i])));
- }
-}
-