proc (b: f32) -> f64 { return ~~(b + 6); }));
- arr : [..] i32;
+ arr : [..] f32;
array.init(^arr);
defer array.free(^arr);
}
array_map :: proc (arr: [..] $T, f: proc (T) -> T) {
+ test2();
+
+ foo := #solidify math.max { T = T };
+ is := (#type InternalStruct(T)).{ foo = foo(6, 2) };
+ printf("%i\n", is.foo);
+
for ^v: arr do *v = f(*v);
+
+ test2 :: proc () { test(); println("WORLD!!!!"); };
+ test :: proc () { println("HELLO!!!"); };
+
+ InternalStruct :: struct ($SOMETHING) {
+ foo : SOMETHING;
+ };
}
double :: proc (v: $V) -> V do return v * 2;
\ No newline at end of file
}
static void add_node_to_process(OnyxParser* parser, AstNode* node) {
+ Scope* scope = parser->file_scope;
+
+ if (!bh_arr_is_empty(parser->block_stack)) {
+ Scope* binding_scope = parser->block_stack[bh_arr_length(parser->block_stack) - 1]->binding_scope;
+
+ if (binding_scope != NULL)
+ scope = binding_scope;
+ }
+
bh_arr_push(parser->results.nodes_to_process, ((NodeToProcess) {
.package = parser->package,
- .scope = parser->file_scope,
+ .scope = scope,
.node = node,
}));
}
expect_token(parser, ':');
if (parser->curr->type == ':') {
- AstBinding* binding = parse_top_level_binding(parser, symbol);
+ AstBlock* current_block = parser->block_stack[bh_arr_length(parser->block_stack) - 1];
+ if (current_block->binding_scope == NULL) {
+ // TODO: Check this is right. I suspect it may allow more things to be
+ // valid than I want it to.
+
+ Scope* parent_scope = parser->file_scope;
+ if (bh_arr_length(parser->block_stack) > 1) {
+ parent_scope = parser->block_stack[bh_arr_length(parser->block_stack) - 2]->binding_scope;
+ }
- bh_arr_push(parser->block_stack[0]->bindings, binding);
+ current_block->binding_scope = scope_create(parser->allocator, parent_scope, current_block->token->pos);
+ }
+
+ AstBinding* binding = parse_top_level_binding(parser, symbol);
+ symbol_introduce(current_block->binding_scope, symbol, binding->node);
return 1;
}
AstNode** next = &block->body;
AstNode* stmt = NULL;
while (parser->curr->type != '}') {
- if (parser->hit_unexpected_token) return block;
+ if (parser->hit_unexpected_token) {
+ bh_arr_pop(parser->block_stack);
+ return block;
+ }
stmt = parse_statement(parser);
scope_enter(block->scope);
bh_arr_push(semstate.block_stack, block);
- bh_arr_each(AstBinding *, binding, block->bindings)
- symbol_introduce(semstate.curr_scope, (*binding)->token, (*binding)->node);
+ if (block->binding_scope != NULL)
+ scope_include(block->scope, block->binding_scope, block->token->pos);
if (block->body)
symres_statement_chain(&block->body);