From: Brendan Hansen Date: Wed, 2 Sep 2020 14:14:55 +0000 (-0500) Subject: 'builtin' package is implicitly included; multiple unqualified uses are eliminated X-Git-Url: https://git.brendanfh.com/?a=commitdiff_plain;h=3c5aab8b045b900d01650a65de23aee4cf7f45bc;p=onyx.git 'builtin' package is implicitly included; multiple unqualified uses are eliminated --- diff --git a/core/file.onyx b/core/file.onyx index 83ca7188..348e3e03 100644 --- a/core/file.onyx +++ b/core/file.onyx @@ -3,7 +3,7 @@ package core_file // Many of these functions will be improved when // multiple return values are implemented. -use package builtin + use package core use package wasi diff --git a/core/js/webgl.onyx b/core/js/webgl.onyx index 738f8b12..d738253c 100644 --- a/core/js/webgl.onyx +++ b/core/js/webgl.onyx @@ -1,7 +1,7 @@ package gl // To be used with the corresponding gl.js -use package builtin + // ClearBufferMask DEPTH_BUFFER_BIT :: 0x00000100 diff --git a/core/ptrmap.onyx b/core/ptrmap.onyx index e828771b..8951cd00 100644 --- a/core/ptrmap.onyx +++ b/core/ptrmap.onyx @@ -10,7 +10,7 @@ PtrMapEntry :: struct { key : rawptr; value : rawptr; - next : i32; + next : i32; } ptrmap_init :: proc (use pmap: ^PtrMap, hash_count: i32 = 16) { @@ -95,7 +95,7 @@ PtrMapLookupResult :: struct { ptrmap_lookup :: proc (use pmap: ^PtrMap, key: rawptr) -> PtrMapLookupResult { lr := PtrMapLookupResult.{}; - hash := cast(u32) 0xcbf29ce4 ^ cast(u32) key; + hash := cast(u32) 0xcbf29ce7 ^ cast(u32) key; lr.hash_index = hash % hashes.count; lr.entry_index = hashes[lr.hash_index]; diff --git a/core/std/js.onyx b/core/std/js.onyx index 69b0473b..9df405cc 100644 --- a/core/std/js.onyx +++ b/core/std/js.onyx @@ -1,6 +1,6 @@ package core -use package builtin + #include_file "core/alloc" #include_file "core/array" diff --git a/core/std/wasi.onyx b/core/std/wasi.onyx index 0c8d9495..b9f6e40d 100644 --- a/core/std/wasi.onyx +++ b/core/std/wasi.onyx @@ -1,6 +1,6 @@ package core -use package builtin + #include_file "core/alloc" #include_file "core/array" diff --git a/core/sys/js.onyx b/core/sys/js.onyx index 69d47149..5f9be60b 100644 --- a/core/sys/js.onyx +++ b/core/sys/js.onyx @@ -1,6 +1,6 @@ package system -use package builtin + use package core use package main as main diff --git a/core/sys/wasi.onyx b/core/sys/wasi.onyx index 828aefb7..eda86edb 100644 --- a/core/sys/wasi.onyx +++ b/core/sys/wasi.onyx @@ -2,7 +2,7 @@ package system #include_file "core/wasi" -use package builtin + use package wasi use package core use package main as main diff --git a/core/wasi.onyx b/core/wasi.onyx index 088192e6..307007a3 100644 --- a/core/wasi.onyx +++ b/core/wasi.onyx @@ -1,6 +1,6 @@ package wasi -use package builtin + use package core { memory_init, stdio_init, diff --git a/docs/plan b/docs/plan index 4e947f74..60b058bf 100644 --- a/docs/plan +++ b/docs/plan @@ -226,7 +226,9 @@ HOW: [X] #file and #line directives - string and u32 respectively that represent the current file and line number where the directive is - [ ] ** Put type info in data section so it is runtime accessible + [ ] data structure based iteration + + [ ] Put type info in data section so it is runtime accessible - type name - size - alignment diff --git a/include/onyxastnodes.h b/include/onyxastnodes.h index 84d721f4..34537780 100644 --- a/include/onyxastnodes.h +++ b/include/onyxastnodes.h @@ -542,6 +542,8 @@ typedef struct Entity { struct Package { char *name; + bh_arr(Package *) unqualified_uses; + Scope *scope; Scope *include_scope; Scope *private_scope; @@ -575,6 +577,7 @@ extern AstBasicType basic_type_f32; extern AstBasicType basic_type_f64; extern AstBasicType basic_type_rawptr; +extern AstNode builtin_package_node; extern AstNumLit builtin_heap_start; extern AstGlobal builtin_stack_top; extern AstType *builtin_string_type; diff --git a/onyx b/onyx index 03ec709f..a21c5056 100755 Binary files a/onyx and b/onyx differ diff --git a/progs/poly_test.onyx b/progs/poly_test.onyx index 335d0052..69f65488 100644 --- a/progs/poly_test.onyx +++ b/progs/poly_test.onyx @@ -2,7 +2,6 @@ package main #include_file "core/std/wasi" -use package builtin use package core print_arr_details :: proc (arr: ^[..] $T) { @@ -75,7 +74,7 @@ main :: proc (args: [] cstring) { print_arr_details(^s.b); for i: 0, 100 { - array_push(^s.a, 5 * i); + array_push(^s.a, (5 * i) % 21); array_push(^s.b, 3l * cast(i64) i); } @@ -94,7 +93,7 @@ main :: proc (args: [] cstring) { print("\n\n"); map : PtrMap; - ptrmap_init(^map); + ptrmap_init(^map, 50); defer ptrmap_free(^map); for i: 0, 100 do ptrmap_put(^map, ^s.a[i], ^s.b[i]); diff --git a/progs/wasi_test.onyx b/progs/wasi_test.onyx index 45a4cb31..92798e39 100644 --- a/progs/wasi_test.onyx +++ b/progs/wasi_test.onyx @@ -10,7 +10,7 @@ package main #include_file "string" #include_file "file" -use package builtin + // NOTE: Didn't realize this would work so easily use package core { string_builder_append as sba } diff --git a/src/onyxbuiltins.c b/src/onyxbuiltins.c index d1cd9261..b1f4e487 100644 --- a/src/onyxbuiltins.c +++ b/src/onyxbuiltins.c @@ -17,6 +17,9 @@ AstBasicType basic_type_f32 = { Ast_Kind_Basic_Type, 0, NULL, "f32" , &basi AstBasicType basic_type_f64 = { Ast_Kind_Basic_Type, 0, NULL, "f64" , &basic_types[Basic_Kind_F64] }; AstBasicType basic_type_rawptr = { Ast_Kind_Basic_Type, 0, NULL, "rawptr", &basic_types[Basic_Kind_Rawptr] }; +static OnyxToken builtin_package_token = { Token_Type_Symbol, 7, "builtin ", { 0 } }; +AstNode builtin_package_node = { Ast_Kind_Symbol, Ast_Flag_No_Clone, &builtin_package_token, NULL }; + static OnyxToken builtin_heap_start_token = { Token_Type_Symbol, 12, "__heap_start ", { 0 } }; static OnyxToken builtin_stack_top_token = { Token_Type_Symbol, 11, "__stack_top ", { 0 } }; AstNumLit builtin_heap_start = { Ast_Kind_NumLit, Ast_Flag_Const, &builtin_heap_start_token, NULL, (AstType *) &basic_type_rawptr, NULL, 0 }; @@ -45,6 +48,9 @@ const BuiltinSymbol builtin_symbols[] = { }; void initialize_builtins(bh_allocator a, ProgramInfo* prog) { + // HACK + builtin_package_token.text = bh_strdup(global_heap_allocator, builtin_package_token.text); + BuiltinSymbol* bsym = (BuiltinSymbol *) &builtin_symbols[0]; while (bsym->sym != NULL) { if (bsym->package == NULL) diff --git a/src/onyxparser.c b/src/onyxparser.c index 1f12e851..3c511d70 100644 --- a/src/onyxparser.c +++ b/src/onyxparser.c @@ -1959,6 +1959,10 @@ ParseResults onyx_parse(OnyxParser *parser) { parser->package = package; } + AstUsePackage* implicit_use_builtin = make_node(AstUsePackage, Ast_Kind_Use_Package); + implicit_use_builtin->package = (AstPackage *) &builtin_package_node; + add_node_to_process(parser, (AstNode *) implicit_use_builtin); + while (parser->curr->type != Token_Type_End_Stream) { if (parser->hit_unexpected_token) return parser->results; diff --git a/src/onyxsymres.c b/src/onyxsymres.c index 23ba952f..ece7115f 100644 --- a/src/onyxsymres.c +++ b/src/onyxsymres.c @@ -503,7 +503,13 @@ void symres_function(AstFunction* func) { param->local->type = param->default_value->type; } - if (param->local->type == NULL) break; + if (param->local->type == NULL) { + onyx_report_error(param->local->token->pos, + "Unable to resolve type for parameter, '%b'.\n", + param->local->token->text, + param->local->token->length); + return; + } symbol_introduce(semstate.curr_scope, param->local->token, (AstNode *) param->local); @@ -591,8 +597,21 @@ static void symres_use_package(AstUsePackage* package) { } } - if (package->alias == NULL && package->only == NULL) + if (package->alias == NULL && package->only == NULL) { + b32 already_included = 0; + bh_arr_each(Package *, included_package, semstate.curr_package->unqualified_uses) { + if (*included_package == p) { + already_included = 1; + break; + } + } + + if (already_included) return; + scope_include(semstate.curr_package->include_scope, p->scope); + + bh_arr_push(semstate.curr_package->unqualified_uses, p); + } } static void symres_enum(AstEnumType* enum_node) { diff --git a/src/onyxutils.c b/src/onyxutils.c index a5eec07c..9c057fd2 100644 --- a/src/onyxutils.c +++ b/src/onyxutils.c @@ -122,6 +122,8 @@ Package* program_info_package_lookup_or_create(ProgramInfo* prog, char* package_ package->include_scope = scope_create(alloc, parent_scope); package->scope = scope_create(alloc, package->include_scope); package->private_scope = scope_create(alloc, package->scope); + package->unqualified_uses = NULL; + bh_arr_new(global_heap_allocator, package->unqualified_uses, 4); bh_table_put(Package *, prog->packages, pac_name, package);