Code cleanup; starting on WASM globals
authorBrendan Hansen <brendan.f.hansen@gmail.com>
Tue, 30 Jun 2020 15:35:41 +0000 (10:35 -0500)
committerBrendan Hansen <brendan.f.hansen@gmail.com>
Tue, 30 Jun 2020 15:36:06 +0000 (10:36 -0500)
README.md
include/onyxparser.h
misc/onyx.vim
onyx
progs/break_test.onyx
progs/test.onyx
src/onyx.c
src/onyxparser.c

index 729b2dbae05d26de29012d992a60b34cfaa6a56d..02f46682023a5158443114d08376f3e2f3acf8c2 100644 (file)
--- 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 |
index 521a195f6004797f72f8b1a87966fbdddbcbea60..312b2d549894327cca195b9708086247dd9cdf21 100644 (file)
@@ -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;
 
index 725b61fa6f7df2a83c8ef6b27e5bb6e8692eebfb..6a37596621c11114515ba854e885d44c9bca6c47 100644 (file)
@@ -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 (executable)
Binary files a/onyx and b/onyx differ
index a90238307122a0c6d9fdc2ec857e31fbd2dde62c..c5cb7b20ee80579a2a4363b75a070ea8a780d6c5 100644 (file)
@@ -3,6 +3,11 @@ print :: foreign "host" "print" proc (val i32) ---
 
 export main :: proc {
 
+    while true {
+        print(8000);
+        break;
+    }
+
     x := 0;
     while x < 10 {
 
index b0b72f5b04857b7862e7781a1d55d119d6dd49be..1f635f5b537088d534bb59e59bae133086b0cd20 100644 (file)
@@ -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;
index ef5914e0a434b15fa5b1039ff624e5f2ac73d624..051d0562f6bccb651a5ec3419ca5ec55af0dfe95 100644 (file)
@@ -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;
 }
 
index c525961353463193024ee33355518d8bea505071..d045613e090a43f6daf574990f7714f8e1279116 100644 (file)
@@ -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;