various little changes
authorBrendan Hansen <brendan.f.hansen@gmail.com>
Wed, 27 Jan 2021 16:15:15 +0000 (10:15 -0600)
committerBrendan Hansen <brendan.f.hansen@gmail.com>
Wed, 27 Jan 2021 16:15:15 +0000 (10:15 -0600)
bin/onyx
core/array.onyx
include/onyxastnodes.h
onyx.exe
project.4coder [new file with mode: 0644]
src/onyx.c
src/onyxchecker.c
src/onyxutils.c
src/onyxwasm.c

index 10117b08792905b5f16c8138023edd4d548c7458..c8d8b8dddc6e52d92a2281f574b3597951d9cb7a 100755 (executable)
Binary files a/bin/onyx and b/bin/onyx differ
index 4bd68f707e3b7a9f1f4cdc29f3aa505dd7de7ce6..0fcfa04716666abe4fc02cc648e25f88d64129ca 100644 (file)
@@ -160,3 +160,25 @@ fold_slice :: proc (arr: [] $T, init: $R, f: proc (T, R) -> R) -> R {
 map :: proc (arr: ^[..] $T, data: $R, f: proc (T, R) -> T) {
     for ^it: *arr do *it = f(*it, data);
 }
+
+#private_file
+greatest_impl :: (arr: ^$T, count: i32) -> (i32, T) {
+    greatest_idx := 0;
+    greatest     := arr[0];
+    
+    for i: 1 .. count {
+        if arr[i] > greatest {
+            greatest_idx = i;
+            greatest     = arr[i];
+        }
+    }
+    
+    return greatest_idx, greatest;
+}
+
+// This pattern should be expanded on to make all kinds of folding functions.
+greatest :: proc {
+    (arr: [..] $T) -> (i32, T) { return greatest_impl(arr.data, arr.count); },
+    (arr: [] $T)   -> (i32, T) { return greatest_impl(arr.data, arr.count); },
+    (arr: [$N] $T) -> (i32, T) { return greatest_impl(cast(^T) arr, N); },
+}
index c4b4c5c9627a5c5f98a5b44b41d35d37820a4dca..2ed9744427657a15af143c70fb7134271c5f361e 100644 (file)
@@ -179,10 +179,10 @@ typedef enum AstFlags {
     Ast_Flag_Private_File          = BH_BIT(6),
 
     // Global flags
-    Ast_Flag_Global_Stack_Top      = BH_BIT(7), // These can go away for something better,
-    Ast_Flag_Global_Stack_Base     = BH_BIT(8), // like just checking the pointers since they will be unique.
+    Ast_Flag_Global_Stack_Top      = BH_BIT(7),
 
     // Function flags
+    Ast_Flag_Already_Checked       = BH_BIT(8),
     Ast_Flag_Intrinsic             = BH_BIT(10),
     Ast_Flag_Function_Used         = BH_BIT(11),
 
index 8b6348ea96f3bd714d2b340b6fbec91db8938c06..918dd1c5bea5301d50b139277dbba1079daa42fa 100644 (file)
Binary files a/onyx.exe and b/onyx.exe differ
diff --git a/project.4coder b/project.4coder
new file mode 100644 (file)
index 0000000..8980e3a
--- /dev/null
@@ -0,0 +1,45 @@
+version(1);
+project_name = "Onyx";
+
+patterns = {
+"*.c",
+"*.cpp",
+"*.h",
+"*.onyx",
+"*.js",
+"*.bat",
+"*.sh",
+"*.4coder",
+"*.txt",
+};
+blacklist_patterns = {
+".*",
+};
+load_paths_custom = {
+ {"."},
+};
+load_paths = {
+ { load_paths_custom, .os = "win"  },
+ { load_paths_custom, .os = "linux"},
+ { load_paths_custom, .os = "mac"  },
+};
+
+build_debug_win32   = "build.bat";
+build_release_win32 = "build.bat 1";
+build_debug_linux   = "./build.sh debug";
+build_release_linux = "./build.sh";
+
+command_list = {
+ { .name = "Build Debug",
+   .out = "*compilation*", .footer_panel = true, .save_dirty_files = true,
+   .cmd = { {build_debug_win32, .os ="win"  },
+            {build_debug_linux, .os ="linux"}, }, },
+ { .name = "Build Release",
+   .out = "*compilation*", .footer_panel = true, .save_dirty_files = true,
+   .cmd = { {build_release_win32, .os ="win" },
+            {build_release_linux, .os ="linux" }, }, },
+};
+
+fkey_command[1] = "Build Debug";
+fkey_command[2] = "Build Release";
index a46a6a62d99402b41ac8e495c339fa94a7dc1aea..6b2bf28f842d62fbd76fabe53d9005fc922b529a 100644 (file)
@@ -397,7 +397,6 @@ static CompilerProgress process_source_file(char* filename) {
     bh_file file;
     bh_file_error err = bh_file_open(&file, filename);
     if (err != BH_FILE_ERROR_NONE) {
-        // bh_printf_err("Failed to open file %s\n", filename);
         onyx_report_error((OnyxFilePos) { 0 }, "Failed to open file %s\n", filename);
         return ONYX_COMPILER_PROGRESS_FAILED_READ;
     }
@@ -405,17 +404,6 @@ static CompilerProgress process_source_file(char* filename) {
     bh_file_contents fc = bh_file_read_contents(context.token_alloc, &file);
     bh_file_close(&file);
 
-    // POTENTIAL BUG: If there are too many files and too many collisions in the table,
-    // there is a chance that the inner arrays of the table will be repositioned. That
-    // would completely break the pointer taken here, which would break all references
-    // to file contents anywhere else in the program.
-    //
-    // A good solution would be to not use a table and just use a array of char* and
-    // ensure that the filename is not in that list.
-    //                                                      - brendanfh 2020/09/03
-
-
-    // NOTE: Need to reget the value out of the table so token references work
     bh_arr_push(context.loaded_files, fc);
 
     if (context.options->verbose_output == 2) {
index 74ee72f71fdd6c0587ed6534f164f0fb05416193..3ec011bb4915277eca67099cff663134f20e58b2 100644 (file)
@@ -457,30 +457,25 @@ CheckStatus check_call(AstCall* call) {
     //      9. Check types of formal and actual params against each other, handling varargs
 
     CHECK(expression, &call->callee);
-    AstFunction* callee = (AstFunction *) call->callee;
-
     check_arguments(&call->args);
 
-    if (callee->kind == Ast_Kind_Overloaded_Function) {
-        call->callee = match_overloaded_function(&call->args, ((AstOverloadedFunction *) callee)->overloads);
-
+    if (call->callee->kind == Ast_Kind_Overloaded_Function) {
+        call->callee = match_overloaded_function(&call->args, ((AstOverloadedFunction *) call->callee)->overloads);
         if (call->callee == NULL) {
             report_unable_to_match_overload(call);
             return Check_Error;
         }
-
-        callee = (AstFunction *) call->callee;
     }
 
-    if (callee->kind == Ast_Kind_Polymorphic_Proc) {
+    if (call->callee->kind == Ast_Kind_Polymorphic_Proc) {
         call->callee = (AstTyped *) polymorphic_proc_lookup((AstPolyProc *) call->callee, PPLM_By_Arguments, &call->args, call->token);
-
         if (call->callee == NULL) return Check_Error;
 
-        callee = (AstFunction *) call->callee;
         arguments_remove_baked(&call->args);
     }
 
+    AstFunction* callee = (AstFunction *) call->callee;
+
     // NOTE: Build callee's type
     fill_in_type((AstTyped *) callee);
     if (callee->type == NULL) {
@@ -1454,6 +1449,10 @@ CheckStatus check_expression(AstTyped** pexpr) {
         case Ast_Kind_Polymorphic_Proc: break;
         case Ast_Kind_Package: break;
         case Ast_Kind_Error: break;
+        
+        // NOTE: The only way to have an Intrinsic_Call node is to have gone through the
+        // checking of a call node at least once.
+        case Ast_Kind_Intrinsic_Call: break;
 
         default:
             retval = Check_Error;
@@ -1533,6 +1532,8 @@ CheckStatus check_block(AstBlock* block) {
 }
 
 CheckStatus check_function(AstFunction* func) {
+    if (func->flags & Ast_Flag_Already_Checked) return Check_Success;
+    
     expected_return_type = func->type->Function.return_type;
     if (func->body) {
         CheckStatus status = check_block(func->body);
@@ -1541,6 +1542,8 @@ CheckStatus check_function(AstFunction* func) {
 
         return status;
     }
+    
+    func->flags |= Ast_Flag_Already_Checked;
 
     return Check_Success;
 }
index 09a97de69e5519e9ffb1de4103d2da5b8e5d525a..e26f2352993831bb675dae5eab3c11848b6aeb3b 100644 (file)
@@ -1107,7 +1107,10 @@ b32 fill_in_arguments(Arguments* args, AstNode* provider, char** err_msg) {
     b32 success = 1;
     fori (idx, 0, bh_arr_length(args->values)) {
         if (args->values[idx] == NULL) args->values[idx] = (AstTyped *) lookup_default_value_by_idx(provider, idx);
-        if (args->values[idx] == NULL) success = 0;
+        if (args->values[idx] == NULL) {
+            *err_msg = bh_aprintf(global_scratch_allocator, "No value given for %d%s argument.", idx + 1, bh_num_suffix(idx + 1));
+            success = 0;
+        }
     }
 
     return success;
index aafd83cca07ff64fe51eb6768d4b2bbc1b50cb5e..75f20d9a0b53026e51ed50e54affb122ec89a21d 100644 (file)
@@ -236,7 +236,7 @@ EMIT_FUNC(local_location,                AstLocal* local, u64* offset_return);
 EMIT_FUNC(memory_reservation_location,   AstMemRes* memres);
 EMIT_FUNC(location_return_offset,        AstTyped* expr, u64* offset_return);
 EMIT_FUNC(location,                      AstTyped* expr);
-EMIT_FUNC(compound_load,                   Type* type, u64 offset);
+EMIT_FUNC(compound_load,                 Type* type, u64 offset);
 EMIT_FUNC(struct_lval,                   AstTyped* lval);
 EMIT_FUNC(struct_literal,                AstStructLiteral* sl);
 EMIT_FUNC(compound_store,                Type* type, u64 offset, b32 location_first);