From: Brendan Hansen Date: Tue, 30 Jun 2020 15:35:41 +0000 (-0500) Subject: Code cleanup; starting on WASM globals X-Git-Url: https://git.brendanfh.com/?a=commitdiff_plain;h=bfaec5b2cfbd928b5aaebcd00d329c8e00c45082;p=onyx.git Code cleanup; starting on WASM globals --- diff --git a/README.md b/README.md index 729b2dba..02f46682 100644 --- a/README.md +++ b/README.md @@ -18,6 +18,6 @@ This a small list of things I want in the language when all is said and done. Ma | Completed | Static symbol resolution where order does not matter | | Completed | Link to externally defined functions (WASM imports) | | Completed | Standard C-style control flow | -| Not Started | Global variables (WASM globals) | +| In Progress | Global variables (WASM globals) | | Not Started | Pointers | | Not Started | Structured data | diff --git a/include/onyxparser.h b/include/onyxparser.h index 521a195f..312b2d54 100644 --- a/include/onyxparser.h +++ b/include/onyxparser.h @@ -99,7 +99,7 @@ typedef enum OnyxAstFlags { // Top-level flags ONYX_AST_FLAG_EXPORTED = BH_BIT(0), ONYX_AST_FLAG_LVAL = BH_BIT(1), - ONYX_AST_FLAG_CONST = BH_BIT(2), + ONYX_AST_FLAG_CONST = BH_BIT(2), ONYX_AST_FLAG_COMPTIME = BH_BIT(3), } OnyxAstFlags; diff --git a/misc/onyx.vim b/misc/onyx.vim index 725b61fa..6a375966 100644 --- a/misc/onyx.vim +++ b/misc/onyx.vim @@ -10,10 +10,10 @@ endif let s:cpo_save = &cpo set cpo&vim -syn keyword onyxKeyword struct proc use export foreign global +syn keyword onyxKeyword struct proc use export foreign syn keyword onyxKeyword if elseif else syn keyword onyxKeyword for while loop return do -syn keyword onyxKeyword return +syn keyword onyxKeyword break continue return syn keyword onyxKeyword as syn keyword onyxType i32 diff --git a/onyx b/onyx index 5efd862d..53154945 100755 Binary files a/onyx and b/onyx differ diff --git a/progs/break_test.onyx b/progs/break_test.onyx index a9023830..c5cb7b20 100644 --- a/progs/break_test.onyx +++ b/progs/break_test.onyx @@ -3,6 +3,11 @@ print :: foreign "host" "print" proc (val i32) --- export main :: proc { + while true { + print(8000); + break; + } + x := 0; while x < 10 { diff --git a/progs/test.onyx b/progs/test.onyx index b0b72f5b..1f635f5b 100644 --- a/progs/test.onyx +++ b/progs/test.onyx @@ -14,6 +14,14 @@ something_else :: proc (n i32) -> i32 { return 100 * n; } +// symbol :: proc {} Global function +// symbol :: struct { x i32, y i32 } +// symbol :: foreign "" "" proc Global foreign function +// symbol :: foreign "" "" i32 Global foreign mutable i32 +// symbol :: 5 Global constant value +// symbol := 5 Global mutable variable +// symbol : i32 Global mutable i32 (defaults to 0 initial value) + // This is the entry point export main :: proc { i := 0; diff --git a/src/onyx.c b/src/onyx.c index ef5914e0..051d0562 100644 --- a/src/onyx.c +++ b/src/onyx.c @@ -152,7 +152,7 @@ i32 onyx_compile(OnyxCompileOptions* opts, CompilerState* compiler_state) { } bh_printf("Checking semantics and types\n"); - OnyxSemPassState sp_state = onyx_sempass_create( compiler_state->sp_alloc, compiler_state->ast_alloc, &compiler_state->msgs); + OnyxSemPassState sp_state = onyx_sempass_create(compiler_state->sp_alloc, compiler_state->ast_alloc, &compiler_state->msgs); onyx_sempass(&sp_state, root_file); if (onyx_message_has_errors(&compiler_state->msgs)) { @@ -179,8 +179,6 @@ i32 onyx_compile(OnyxCompileOptions* opts, CompilerState* compiler_state) { } void compiler_state_free(CompilerState* cs) { - // NOTE: There is a memory leak here because the token's aren't freed - bh_arena_free(&cs->ast_arena); bh_arena_free(&cs->msg_arena); bh_arena_free(&cs->sp_arena); @@ -239,6 +237,8 @@ int main(int argc, char *argv[]) { compiler_state_free(&compile_state); + bh_managed_heap_free(&global_heap); + return compiler_progress != ONYX_COMPILER_PROGRESS_SUCCESS; } diff --git a/src/onyxparser.c b/src/onyxparser.c index c5259613..d045613e 100644 --- a/src/onyxparser.c +++ b/src/onyxparser.c @@ -792,7 +792,7 @@ const char* onyx_ast_node_kind_string(OnyxAstNodeKind kind) { } // NOTE: This returns a void* so I don't need to cast it everytime I use it -void* onyx_ast_node_new(bh_allocator alloc, OnyxAstNodeKind kind) {\ +void* onyx_ast_node_new(bh_allocator alloc, OnyxAstNodeKind kind) { OnyxAstNode* node = bh_alloc_item(alloc, OnyxAstNode); node->kind = kind; node->flags = 0;