From: Brendan Hansen Date: Tue, 4 Apr 2023 03:13:11 +0000 (-0500) Subject: bugfixes; cleanup old files X-Git-Url: https://git.brendanfh.com/?a=commitdiff_plain;h=df910c4c4473ec413e2325df6c94f1c4dabd8d08;p=onyx.git bugfixes; cleanup old files --- diff --git a/compiler/src/astnodes.c b/compiler/src/astnodes.c index cfab106c..f7e81e86 100644 --- a/compiler/src/astnodes.c +++ b/compiler/src/astnodes.c @@ -155,6 +155,7 @@ const char* entity_type_strings[Entity_Type_Count] = { "Load File", "Binding (Declaration)", "Use Package", + "Import", "Static If", "String Literal", "File Contents", diff --git a/compiler/src/symres.c b/compiler/src/symres.c index f56d4a50..a5e86621 100644 --- a/compiler/src/symres.c +++ b/compiler/src/symres.c @@ -1686,7 +1686,7 @@ static SymresStatus symres_import(AstImport* import) { 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, diff --git a/core/hash/sha256.onyx b/core/hash/sha256.onyx index 7926bc1c..3c0e29ba 100644 --- a/core/hash/sha256.onyx +++ b/core/hash/sha256.onyx @@ -148,12 +148,14 @@ do_cycle :: (self: &Hasher, data: [] u8) { 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.[ diff --git a/interpreter/build.sh b/interpreter/build.sh index c58d91f5..c1e69bed 100755 --- a/interpreter/build.sh +++ b/interpreter/build.sh @@ -7,7 +7,7 @@ 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" diff --git a/interpreter/include/assembler.h b/interpreter/include/assembler.h deleted file mode 100644 index 7ea656eb..00000000 --- a/interpreter/include/assembler.h +++ /dev/null @@ -1,36 +0,0 @@ -#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 - diff --git a/interpreter/src/ovm_cli_test.c b/interpreter/src/ovm_cli_test.c deleted file mode 100644 index 57810442..00000000 --- a/interpreter/src/ovm_cli_test.c +++ /dev/null @@ -1,52 +0,0 @@ -#include "vm.h" - -#include - -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; -} diff --git a/interpreter/src/ovmwasm.c b/interpreter/src/ovmwasm.c new file mode 100644 index 00000000..6b0da56a --- /dev/null +++ b/interpreter/src/ovmwasm.c @@ -0,0 +1,8 @@ +#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" diff --git a/interpreter/src/wasm.c b/interpreter/src/wasm.c deleted file mode 100644 index 6b0da56a..00000000 --- a/interpreter/src/wasm.c +++ /dev/null @@ -1,8 +0,0 @@ -#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" diff --git a/interpreter/src/wasm_cli_test.c b/interpreter/src/wasm_cli_test.c deleted file mode 100644 index b6ca26fb..00000000 --- a/interpreter/src/wasm_cli_test.c +++ /dev/null @@ -1,49 +0,0 @@ -#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]))); - } -} -