From bfaec5b2cfbd928b5aaebcd00d329c8e00c45082 Mon Sep 17 00:00:00 2001 From: Brendan Hansen Date: Tue, 30 Jun 2020 10:35:41 -0500 Subject: [PATCH] Code cleanup; starting on WASM globals --- README.md | 2 +- include/onyxparser.h | 2 +- misc/onyx.vim | 4 ++-- onyx | Bin 207800 -> 207800 bytes progs/break_test.onyx | 5 +++++ progs/test.onyx | 8 ++++++++ src/onyx.c | 6 +++--- src/onyxparser.c | 2 +- 8 files changed, 21 insertions(+), 8 deletions(-) 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 5efd862d4d244b3c8d906154ea89784eeba3b227..5315494571a3da2d56f489cedee4c57828380b97 100755 GIT binary patch delta 648 zcmXYtT}YE*6vv-)9^bj?zHGWu>Yes6zt9W3DvNio zmcqbAs@%PraltR3d~In*0C9 zH4ttp#>-W(gSB14NhoD%6W+wKdbZevSy0AfO&EjC@=qyK`&F{EOWHAM+kliFlynZs z&X$|;IP7Ff3syog?`XkJ02|Y{;v87nuU2#l^N}bw!7Esu51aUEA3n;0 zG4@~t>r=i-a*(f&;N5b5Cx!<>+;4gjFBst>SJp8?1!p6jl8~7Bd@Ah)SmQn&o!Sa3 k%w?wzoyWX!HxCck=_?8j<|?A)U|@kFdKf0zbP@gj56bM!3IG5A delta 636 zcmXYte@IhN6vyv5x2JD8x5?C0a%#}>2hJi(BUGN&_9UZ1Ee2Z_l=xp|4vhu{E@Q}| zG2%vu`A0-hiY0lK6cZ~81JNM=vD!b@vYdhy7Uk>h)%oZ0`JQvW-^&@A(+|z*`$f=s zR)|)ffh3rK~qeFq#IlVPuQ$-Wx>;XA_dfpI5?xjGQG`*{8~`3__l=9d2-Jh&)mhmb8rKP>Y}mj=UL>;0W7zfSGc`VYJ$Z?sSq9>?AKAJ;&*u>jB8 zVGnCRhtHsr$<25T?Jl<5j45E}(PoUortRN^WN|?-`vmcckl8CFj0n0Sp_Hw*;6Zg& z@?aHI@GBnd04QeqR{RVF>_;m)U@t3gLnoB;n{BEe6!X3dSiKFB_*xI%O@UE%dk|ez zuzcjoAl@k9p(vJtdcK)uJY#?pTw2FDs&YEgX#rP^d@-JO11xdBj!tie1?IHUB3+Z| d-}Rb!&`KvM*qAe)mVllG^JxW4u$g@N=`Y(j$kG4+ 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; -- 2.25.1