code cleanup
authorBrendan Hansen <brendan.f.hansen@gmail.com>
Fri, 18 Sep 2020 02:01:56 +0000 (21:01 -0500)
committerBrendan Hansen <brendan.f.hansen@gmail.com>
Fri, 18 Sep 2020 02:01:56 +0000 (21:01 -0500)
CHANGELOG
include/onyxastnodes.h
onyx
progs/wasi_test.onyx
src/onyxchecker.c
src/onyxparser.c
src/onyxsymres.c
src/onyxutils.c

index f895af03b32f1c103826925f7d0b5f69933c6bbb..5baaf7d9af33d039175ce884a95b023e506b020d 100644 (file)
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -7,7 +7,7 @@ Additions:
 * Added println to core library; print followed by a newline.
 * Added tests/ folder and runtests.sh which will compile and execute the programs in the
     folder and test against their expected output.
-* #private_file for specifying symbols at the file scope
+* #private_file for specifying symbols at the file scope.
 
 Removals:
 
@@ -19,4 +19,4 @@ Changes:
 Bug fixes:
 * Fixed error message index for struct literal member type mismatch.
 * Fixed freeing non-allocated memory when generating documentation.
-* Fixed alignment issue with struct members
+* Fixed alignment issue with struct members.
index d86b940555901fe9ed2f39ee39df467800c66d11..838b87e8a359a92f9317a99d5242f5b7495c116c 100644 (file)
@@ -164,10 +164,8 @@ typedef enum AstFlags {
     Ast_Flag_Global_Stack_Base = BH_BIT(8),
 
     // Function flags
-    Ast_Flag_Inline            = BH_BIT(9),
     Ast_Flag_Intrinsic         = BH_BIT(10),
     Ast_Flag_Function_Used     = BH_BIT(11),
-    Ast_Flag_No_Stack          = BH_BIT(12),
 
     // Expression flags
     Ast_Flag_Expr_Ignored      = BH_BIT(13),
diff --git a/onyx b/onyx
index 9975660a7ff32b15b7aa1feba2eb5878776fc296..3691c2febeca9090994741ee6603f419eff94555 100755 (executable)
Binary files a/onyx and b/onyx differ
index 92798e390c578487437dc47c90680ea056621419..01e3b829b39d1ac88db2405922cb2284dfb02a90 100644 (file)
@@ -1,32 +1,17 @@
 package main
 
-#include_folder "/usr/share/onyx/core"
-
-#include_file "builtin"
-#include_file "wasi"
-#include_file "alloc"
-#include_file "intrinsics"
-#include_file "random"
-#include_file "string"
-#include_file "file"
-
-
+#include_file "core/std/wasi"
 
 // NOTE: Didn't realize this would work so easily
 use package core { string_builder_append as sba }
 use package core
-
-use package memory
+use package core_file
 use package wasi
-use package intrinsics
-use package random
-use package file
-use package stdio
 
 // print_rights :: proc (rights: Rights) {
 //     print(cast(u32) rights, 2);
 //     print("\n");
-// 
+//
 //     if rights & Rights.DataSync != cast(Rights) 0 do print("DataSync\n");
 //     if rights & Rights.Read != cast(Rights) 0 do print("Read\n");
 //     if rights & Rights.Seek != cast(Rights) 0 do print("Seek\n");
@@ -108,7 +93,7 @@ timer_end :: proc (start_time: Timestamp) -> Timestamp {
 
 is_prime :: proc (n := 0) -> bool {
     sqrt :: cast(i32) (sqrt_f32(cast(f32) n));
-    for i: 2, sqrt + 1 do if n % i == 0 do return false;
+    for i: 2 .. sqrt + 1 do if n % i == 0 do return false;
     return true;
 }
 
@@ -140,7 +125,7 @@ output_s :: proc (sb: ^StringBuilder, s: ^S) -> ^StringBuilder {
 print_arr :: proc (sb: ^StringBuilder, arr: [] $T) {
     sb |> string_builder_clear();
 
-    for i: 0, arr.count {
+    for i: 0 .. arr.count {
         sb |> sba(cast(u64) arr[i]) |> sba(" ");
     }
 
@@ -149,7 +134,7 @@ print_arr :: proc (sb: ^StringBuilder, arr: [] $T) {
 
 make_i32_arr :: proc (a := context.allocator, len := 10) -> [] i32 {
     arr := cast(^i32) alloc(a, sizeof i32 * len);
-    return arr[0 : len];
+    return arr[0 .. len];
 }
 
 main :: proc (args: []cstring) {
@@ -174,7 +159,7 @@ main :: proc (args: []cstring) {
         |> sba(cast(u64) args.count)
         |> sba(" arguments.\n");
 
-    for i: 0, args.count do ^sb |> sba(args[i]) |> sba(" ");
+    for i: 0 .. args.count do ^sb |> sba(args[i]) |> sba(" ");
     ^sb |> sba("\n")
         |> string_builder_to_string()
         |> print();
@@ -184,7 +169,7 @@ main :: proc (args: []cstring) {
     print(cont);
 
     sum := 0l;
-    for i: 0, 20000 do if is_prime(i) do sum += cast(u64) i;
+    for i: 0 .. 20000 do if is_prime(i) do sum += cast(u64) i;
     print("Sum of primes less than 20000 is: ");
     print_i64(sum);
     print("\n");
@@ -193,7 +178,7 @@ main :: proc (args: []cstring) {
     defer cfree(matches.data);
 
     string_builder_clear(^sb);
-    for i: 0, matches.count {
+    for i: 0 .. matches.count {
         ^sb |> sba(matches[i])
             |> sba("\n");
     }
@@ -205,7 +190,7 @@ main :: proc (args: []cstring) {
     defer cfree(tokens.data);
 
     acc := 0;
-    for i: 0, tokens.count {
+    for i: 0 .. tokens.count {
         switch tokens[i][0] {
             case #char "+" do acc += 1;
             case #char "-" do acc -= 1;
@@ -264,9 +249,9 @@ main :: proc (args: []cstring) {
 
 
     arr : [128] i32;
-    for i: 0, 128 do arr[i] = i * i;
+    for i: 0 .. 128 do arr[i] = i * i;
 
-    print_arr(^sb, arr[5 : 10]);
+    print_arr(^sb, arr[5 .. 10]);
 
     ss := string_substr("Hello, World!", "World");
     if ss.count > 0 do print(ss);
@@ -299,8 +284,8 @@ main :: proc (args: []cstring) {
 
     dynarr : [..] Vec3;
     array_init(^dynarr);
-    for i: 0, 16 do array_add(^dynarr, Vec3.{ cast(f32) i, cast(f32) (i * i), cast(f32) (i * i * i) });
-    for i: 0, 16 {
+    for i: 0 .. 16 do array_push(^dynarr, Vec3.{ cast(f32) i, cast(f32) (i * i), cast(f32) (i * i * i) });
+    for i: 0 .. 16 {
         print(cast(u32) dynarr.data[i].x);
         print(" ");
         print(cast(u32) dynarr.data[i].y);
@@ -342,7 +327,7 @@ multi_poly :: proc (a: $T, b: $R) -> R {
 }
 
 make_slice :: proc (ptr: ^$T, count: u32) -> [] T {
-    return ptr[4 : count];
+    return ptr[4 .. count];
 }
 
-get_slice_length :: proc (s: ^[] $T) -> u32 do return s.count;
\ No newline at end of file
+get_slice_length :: proc (s: ^[] $T) -> u32 do return s.count;
index 30d08d169888aea502590b5889d058aa94c631db..64c61b93deb52aadb17d0bdf4ccd4ae63dc190e0 100644 (file)
@@ -1287,11 +1287,6 @@ b32 check_function_header(AstFunction* func) {
             return 1;
         }
 
-        if ((func->flags & Ast_Flag_Inline) != 0) {
-            onyx_report_error(func->token->pos, "exporting a inlined function");
-            return 1;
-        }
-
         if (func->exported_name == NULL) {
             onyx_report_error(func->token->pos, "exporting function without a name");
             return 1;
index b4e0ea9463e076687c6b50f7b4c34720106c2378..1b05461faa377eab3208528af2350f91a0fbba10 100644 (file)
@@ -1612,10 +1612,6 @@ static AstFunction* parse_function_definition(OnyxParser* parser) {
             }
         }
 
-        else if (parse_possible_directive(parser, "inline")) {
-            func_def->flags |= Ast_Flag_Inline;
-        }
-
         else if (parse_possible_directive(parser, "foreign")) {
             func_def->foreign_module = expect_token(parser, Token_Type_Literal_String);
             func_def->foreign_name   = expect_token(parser, Token_Type_Literal_String);
@@ -1632,10 +1628,6 @@ static AstFunction* parse_function_definition(OnyxParser* parser) {
             }
         }
 
-        else if (parse_possible_directive(parser, "nostack")) {
-            func_def->flags |= Ast_Flag_No_Stack;
-        }
-
         else {
             OnyxToken* directive_token = expect_token(parser, '#');
             OnyxToken* symbol_token = expect_token(parser, Token_Type_Symbol);
@@ -2048,21 +2040,16 @@ ParseResults onyx_parse(OnyxParser *parser) {
                         break;
 
                     case Ast_Kind_Binding: {
-                        if (((AstBinding *) curr_stmt)->node->flags & Ast_Flag_Private_Package) {
-                            symbol_introduce(parser->package->private_scope,
-                                ((AstBinding *) curr_stmt)->token,
-                                ((AstBinding *) curr_stmt)->node);
-
-                        } else if (((AstBinding *) curr_stmt)->node->flags & Ast_Flag_Private_File) {
-                            symbol_introduce(parser->file_scope,
-                                ((AstBinding *) curr_stmt)->token,
-                                ((AstBinding *) curr_stmt)->node);
-
-                        } else {
-                            symbol_introduce(parser->package->scope,
-                                ((AstBinding *) curr_stmt)->token,
-                                ((AstBinding *) curr_stmt)->node);
-                        }
+                        Scope* target_scope = parser->package->scope;
+
+                        if (((AstBinding *) curr_stmt)->node->flags & Ast_Flag_Private_Package)
+                            target_scope = parser->package->private_scope;
+                        if (((AstBinding *) curr_stmt)->node->flags & Ast_Flag_Private_File)
+                            target_scope = parser->file_scope;
+
+                        symbol_introduce(target_scope,
+                            ((AstBinding *) curr_stmt)->token,
+                            ((AstBinding *) curr_stmt)->node);
                         break;
                     }
 
index c28519cd22961533e652173dfdd2e8700020771f..755916370f80631a5d60eab9dace7a96f007145b 100644 (file)
@@ -231,7 +231,7 @@ static void symres_pipe(AstBinaryOp** pipe) {
     symres_expression(&(*pipe)->left);
 
     if (call_node->kind != Ast_Kind_Call) {
-        onyx_report_error((*pipe)->token->pos, "universal function call expected call on right side");
+        onyx_report_error((*pipe)->token->pos, "Pipe operator expected call on right side.");
         return;
     }
 
index b13db6683fab5c9f973f8f69caeb076e1118c3da..f1099fb8fea76382eaf6c7e496696562d78705b7 100644 (file)
@@ -84,7 +84,7 @@ static const char* ast_node_names[] = {
     "JUMP",
     "DEFER",
     "SWITCH",
-    "SWITCH CASE"
+    "SWITCH CASE",
 
     "AST_NODE_KIND_COUNT",
 };