From: Brendan Hansen Date: Fri, 18 Sep 2020 02:01:56 +0000 (-0500) Subject: code cleanup X-Git-Url: https://git.brendanfh.com/?a=commitdiff_plain;h=567c96adcf84b5d3292c94bfb623b2093da05fdf;p=onyx.git code cleanup --- diff --git a/CHANGELOG b/CHANGELOG index f895af03..5baaf7d9 100644 --- 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. diff --git a/include/onyxastnodes.h b/include/onyxastnodes.h index d86b9405..838b87e8 100644 --- a/include/onyxastnodes.h +++ b/include/onyxastnodes.h @@ -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 9975660a..3691c2fe 100755 Binary files a/onyx and b/onyx differ diff --git a/progs/wasi_test.onyx b/progs/wasi_test.onyx index 92798e39..01e3b829 100644 --- a/progs/wasi_test.onyx +++ b/progs/wasi_test.onyx @@ -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; diff --git a/src/onyxchecker.c b/src/onyxchecker.c index 30d08d16..64c61b93 100644 --- a/src/onyxchecker.c +++ b/src/onyxchecker.c @@ -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; diff --git a/src/onyxparser.c b/src/onyxparser.c index b4e0ea94..1b05461f 100644 --- a/src/onyxparser.c +++ b/src/onyxparser.c @@ -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; } diff --git a/src/onyxsymres.c b/src/onyxsymres.c index c28519cd..75591637 100644 --- a/src/onyxsymres.c +++ b/src/onyxsymres.c @@ -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; } diff --git a/src/onyxutils.c b/src/onyxutils.c index b13db668..f1099fb8 100644 --- a/src/onyxutils.c +++ b/src/onyxutils.c @@ -84,7 +84,7 @@ static const char* ast_node_names[] = { "JUMP", "DEFER", "SWITCH", - "SWITCH CASE" + "SWITCH CASE", "AST_NODE_KIND_COUNT", };