more general cleanup
authorBrendan Hansen <brendan.f.hansen@gmail.com>
Mon, 1 Feb 2021 06:17:16 +0000 (00:17 -0600)
committerBrendan Hansen <brendan.f.hansen@gmail.com>
Mon, 1 Feb 2021 06:17:16 +0000 (00:17 -0600)
bin/onyx
src/onyx.c
src/onyxparser.c
src/onyxtypes.c
src/onyxwasm.c

index c8e3b8f67302d94e257bdafe34edc4c58e8ba12f..b760869b68775990a4e66c42fd874c7be1b0a38c 100755 (executable)
Binary files a/bin/onyx and b/bin/onyx differ
index 33df061cca200f472e47148920b111215e2f6baf..1393fb569f1c8a324015fdda04dba054393f7be6 100644 (file)
@@ -86,15 +86,20 @@ static CompileOptions compile_opts_parse(bh_allocator alloc, int argc, char *arg
             else if (!strcmp(argv[i], "-VVV")) {
                 options.verbose_output = 3;
             }
-            else if (!strcmp(argv[i], "--fun") || !strcmp(argv[i], "-F")) {
-                options.fun_output = 1;
-            }
             else if (!strcmp(argv[i], "--print-function-mappings")) {
                 options.print_function_mappings = 1;
             }
             else if (!strcmp(argv[i], "-I")) {
                 bh_arr_push(options.included_folders, argv[++i]);
             }
+#if defined(_BH_LINUX)
+            // NOTE: Fun output is only enabled for Linux because Windows command line
+            // is not ANSI compatible and for a silly feature, I don't want to learn
+            // how to properly do arbitrary graphics in it.
+            else if (!strcmp(argv[i], "--fun") || !strcmp(argv[i], "-F")) {
+                options.fun_output = 1;
+            }
+#endif
             else {
                 bh_arr_push(options.files, argv[i]);
             }
@@ -156,27 +161,13 @@ static void context_init(CompileOptions* opts) {
         .package = NULL,
         .include = create_load(context.ast_alloc, "core/builtin"),
     }));
-
-    entity_heap_insert(&context.entities, ((Entity) {
-        .state = Entity_State_Resolve_Symbols,
-        .type = Entity_Type_Global_Header,
-        .global = &builtin_stack_top
-    }));
     
-    entity_heap_insert(&context.entities, ((Entity) {
-        .state = Entity_State_Resolve_Symbols,
-        .type = Entity_Type_Global,
-        .global = &builtin_stack_top
-    }));
+    add_entities_for_node((AstNode *) &builtin_stack_top, context.global_scope, NULL);
 
     // NOTE: Add all files passed by command line to the queue
     bh_arr_each(const char *, filename, opts->files) {
-        entity_heap_insert(&context.entities, ((Entity) {
-            .state = Entity_State_Parse,
-            .type = Entity_Type_Load_File,
-            .package = NULL,
-            .include = create_load(context.ast_alloc, (char *) *filename),
-        }));
+        AstInclude* load_node = create_load(context.ast_alloc, (char *) *filename);
+        add_entities_for_node((AstNode *) load_node, context.global_scope, NULL);
     }
 }
 
@@ -270,7 +261,7 @@ static CompilerProgress process_source_file(char* filename) {
     }
 }
 
-static b32 process_load_entity(Entity* ent) {
+static void process_load_entity(Entity* ent) {
     assert(ent->type == Entity_Type_Load_File || ent->type == Entity_Type_Load_Path);
     AstInclude* include = ent->include;
 
@@ -283,8 +274,6 @@ static b32 process_load_entity(Entity* ent) {
     } else if (include->kind == Ast_Kind_Load_Path) {
         bh_arr_push(context.options->included_folders, include->name);
     }
-
-    return 1;
 }
 
 static b32 process_entity(Entity* ent) {
@@ -327,6 +316,7 @@ static b32 process_entity(Entity* ent) {
 }
 
 // Just having fun with some visual output - brendanfh 2020/12/14
+#if defined(_BH_LINUX)
 static void output_dummy_progress_bar() {
     EntityHeap* eh = &context.entities;
 
@@ -339,6 +329,7 @@ static void output_dummy_progress_bar() {
         printf("\n");
     }
 }
+#endif
 
 static i32 onyx_compile() {
     u64 start_time = bh_time_curr();
@@ -351,22 +342,20 @@ static i32 onyx_compile() {
         entity_heap_remove_top(&context.entities);
         if (ent.state == Entity_State_Finalized) continue;
 
-        if (context.options->fun_output) {
+#if defined(_BH_LINUX)
+            if (context.options->fun_output) {
             output_dummy_progress_bar();
-
-            // Slowing things down for the effect
-#if defined(_BH_WINDOWS)
-            Sleep(1);
-#elif defined(_BH_LINUX)
-            usleep(1000);
-#endif
-
+            
             if (ent.expr->token) {
                 OnyxFilePos pos = ent.expr->token->pos;
                 printf("\e[0K%s on %s in %s:%d:%d\n", entity_state_strings[ent.state], entity_type_strings[ent.type], pos.filename, pos.line, pos.column);
             }
+            
+            // Slowing things down for the effect
+            usleep(1000);
         }
-
+#endif
+        
         b32 changed = process_entity(&ent);
 
         if (onyx_has_errors()) return ONYX_COMPILER_PROGRESS_ERROR;
index b44571683e34355fba038db3e1f153aa7deab99a..da187e9f9273db5d1becedc4f400e61a9482d69a 100644 (file)
@@ -9,6 +9,8 @@
 
 // Things that need to be cleaned up in the parser:
 //  - control block local variables should be more extensible and reuse more code
+//  - outermost loops that parse the top level elements
+//  - package name parsing
 
 #include "onyxlex.h"
 #include "onyxerrors.h"
index 26ccd63ae4a113d23792160adfe2a8737ca13a1c..993f97f24c5c55ec1b5cc47330d5ac42dc3c798b 100644 (file)
@@ -689,7 +689,7 @@ Type* type_make_varargs(bh_allocator alloc, Type* of) {
 void build_linear_types_with_offset(Type* type, bh_arr(TypeWithOffset)* pdest, u32 offset) {
     if (type_is_structlike_strict(type)) {
         u32 mem_count = type_structlike_mem_count(type);
-        StructMember smem;
+        StructMember smem = { 0 };
         fori (i, 0, mem_count) {
             type_lookup_member_by_idx(type, i, &smem);
             build_linear_types_with_offset(smem.type, pdest, offset + smem.offset);
index 6c40d41bbb031472f62ed50203c6296b31029b58..a0d90f42978c8e9903465e6bb97d7ebbc17700a1 100644 (file)
@@ -2731,12 +2731,14 @@ static void emit_string_literal(OnyxWasmModule* mod, AstStrLit* strlit) {
     // in a string literal that create more bytes than already
     // existed. You can create less however ('\n' => 0x0a).
     i8* strdata = bh_alloc_array(global_heap_allocator, i8, strlit->token->length + 1);
-    i32 length =string_process_escape_seqs(strdata, strlit->token->text, strlit->token->length);
+    i32 length  = string_process_escape_seqs(strdata, strlit->token->text, strlit->token->length);
 
     if (bh_table_has(StrLitInfo, mod->string_literals, (char *) strdata)) {
         StrLitInfo sti = bh_table_get(StrLitInfo, mod->string_literals, (char *) strdata);
         strlit->addr   = sti.addr;
         strlit->length = sti.len;
+        
+        bh_free(global_heap_allocator, strdata);
         return;
     }