- Foreign functions will rename in the code because it is turning out
to be a nightmare to remove them. Lot's of refactoring... ugh
- [ ] Package system
+ [X] Package system
[ ] Enum types
typedef struct Entity {
EntityType type;
- Scope *scope;
+ Package *package;
union {
AstUsePackage *use_package;
struct Package {
char *name;
+
Scope *scope;
+ Scope *include_scope;
};
// NOTE: Simple data structure for storing what comes out of the parser
typedef struct NodeToProcess {
Scope *scope;
+ Package *package;
AstNode *node;
} NodeToProcess;
bh_allocator allocator;
ProgramInfo *program;
- Scope *package_scope;
+ Package *package;
// NOTE: not used since all tokens are lexed before parsing starts
OnyxTokenizer *tokenizer;
ProgramInfo* program;
// NOTE: Used in symbol resolution phase
+ Package* curr_package;
Scope* global_scope;
Scope* curr_scope;
AstFunction* curr_function;
p.print(1234);
print_f32(123.0f);
-}
\ No newline at end of file
+}
+
AstNode* node = n->node;
AstKind nkind = node->kind;
- ent.scope = n->scope;
+ ent.package = n->package;
switch (nkind) {
case Ast_Kind_Function: {
static void add_node_to_process(OnyxParser* parser, AstNode* node) {
bh_arr_push(parser->results.nodes_to_process, ((NodeToProcess) {
- .scope = parser->package_scope,
+ .package = parser->package,
+ .scope = parser->package->scope,
.node = node,
}));
}
parser->allocator);
token_toggle_end(symbol);
- parser->package_scope = package->scope;
+ parser->package = package;
} else {
Package *package = program_info_package_lookup_or_create(
parser->program->global_scope,
parser->allocator);
- parser->package_scope = package->scope;
+ parser->package = package;
}
while (parser->curr->type != Token_Type_End_Stream) {
switch (curr_stmt->kind) {
case Ast_Kind_Include_File: bh_arr_push(parser->results.files, (AstIncludeFile *) curr_stmt); break;
case Ast_Kind_Binding: {
- symbol_introduce(parser->package_scope,
+ symbol_introduce(parser->package->scope,
((AstBinding *) curr_stmt)->token,
((AstBinding *) curr_stmt)->node);
break;
static void symres_use_package(AstUsePackage* package);
static void scope_enter(Scope* new_scope) {
- new_scope->parent = semstate.curr_scope;
+ if (new_scope->parent == NULL)
+ new_scope->parent = semstate.curr_scope;
semstate.curr_scope = new_scope;
}
if (package->alias != NULL) {
AstPackage *pac_node = onyx_ast_node_new(semstate.node_allocator, sizeof(AstPackage), Ast_Kind_Package);
pac_node->package = p;
+ pac_node->token = package->alias;
- symbol_introduce(semstate.curr_scope, package->alias, (AstNode *) pac_node);
+ symbol_introduce(semstate.curr_package->include_scope, package->alias, (AstNode *) pac_node);
}
if (package->only != NULL) {
"not found in package");
return;
}
- symbol_introduce(semstate.curr_scope, *tkn, thing);
+ symbol_introduce(semstate.curr_package->include_scope, *tkn, thing);
}
}
if (package->alias == NULL && package->only == NULL)
- scope_include(semstate.curr_scope, p->scope);
+ scope_include(semstate.curr_package->include_scope, p->scope);
}
void onyx_resolve_symbols() {
}
bh_arr_each(Entity, entity, semstate.program->entities) {
- scope_enter(entity->scope);
+ scope_enter(entity->package->scope);
+ semstate.curr_package = entity->package;
switch (entity->type) {
case Entity_Type_Use_Package: symres_use_package(entity->use_package); break;
memcpy(pac_name, package_name, strlen(package_name) + 1);
package->name = pac_name;
- package->scope = scope_create(alloc, parent_scope);
+ package->include_scope = scope_create(alloc, parent_scope);
+ package->scope = scope_create(alloc, package->include_scope);
bh_table_put(Package *, prog->packages, pac_name, package);
}
}
- if (res == NULL ) {
+ if (res == NULL) {
onyx_message_add(Msg_Type_Unknown_Symbol,
tkn->pos,
tkn->text);