Skip to content

Commit ba0a9c2

Browse files
committed
fixed: windows build and cleaned up code
1 parent 64a5c64 commit ba0a9c2

File tree

6 files changed

+37
-46
lines changed

6 files changed

+37
-46
lines changed

build.bat

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
@echo off
22

33
REM Compile the compiler
4-
set SOURCE_FILES=compiler/src/library_main.c compiler/cli/main.c compiler/src/astnodes.c compiler/src/builtins.c compiler/src/checker.c compiler/src/clone.c compiler/src/doc.c compiler/src/entities.c compiler/src/errors.c compiler/src/lex.c compiler/src/parser.c compiler/src/symres.c compiler/src/types.c compiler/src/utils.c compiler/src/wasm_emit.c compiler/src/wasm_runtime.c compiler/src/extensions.c
4+
set SOURCE_FILES=compiler/src/library_main.c compiler/cli/main.c compiler/src/astnodes.c compiler/src/builtins.c compiler/src/checker.c compiler/src/clone.c compiler/src/doc.c compiler/src/entities.c compiler/src/errors.c compiler/src/lex.c compiler/src/parser.c compiler/src/types.c compiler/src/utils.c compiler/src/wasm_emit.c compiler/src/wasm_runtime.c compiler/src/extensions.c
55

66
if "%1" == "1" (
77
set FLAGS=/Od /MTd /Z7
@@ -23,7 +23,7 @@ if %ERRORLEVEL% neq 0 (
2323
exit /b %ERRORLEVEL%
2424
)
2525

26-
set SOURCE_FILES=compiler/src/library_main.c compiler/src/astnodes.c compiler/src/builtins.c compiler/src/checker.c compiler/src/clone.c compiler/src/doc.c compiler/src/entities.c compiler/src/errors.c compiler/src/lex.c compiler/src/parser.c compiler/src/symres.c compiler/src/types.c compiler/src/utils.c compiler/src/wasm_emit.c compiler/src/wasm_runtime.c compiler/src/extensions.c
26+
set SOURCE_FILES=compiler/src/library_main.c compiler/src/astnodes.c compiler/src/builtins.c compiler/src/checker.c compiler/src/clone.c compiler/src/doc.c compiler/src/entities.c compiler/src/errors.c compiler/src/lex.c compiler/src/parser.c compiler/src/types.c compiler/src/utils.c compiler/src/wasm_emit.c compiler/src/wasm_runtime.c compiler/src/extensions.c
2727
cl.exe %FLAGS% /Icompiler/include /std:c17 /TC %SOURCE_FILES% /link /DLL /IGNORE:4217 %LINK_OPTIONS% /OUT:onyx.dll
2828

2929
REM Don't continue if we had compilation errors. This prevents CI to succeed.

compiler/include/astnodes.h

-6
Original file line numberDiff line numberDiff line change
@@ -284,8 +284,6 @@ typedef enum AstFlags {
284284
Ast_Flag_Address_Taken = BH_BIT(7),
285285

286286
// Type flags
287-
Ast_Flag_Type_Is_Considered_Complete = BH_BIT(8),
288-
289287
Ast_Flag_No_Clone = BH_BIT(9),
290288

291289
Ast_Flag_Cannot_Take_Addr = BH_BIT(10),
@@ -328,8 +326,6 @@ typedef enum AstFlags {
328326
Ast_Flag_Constraint_Is_Expression = BH_BIT(28),
329327

330328
Ast_Flag_Has_Been_Scheduled_For_Emit = BH_BIT(29),
331-
332-
Ast_Flag_Hack_Only_Check_Types = BH_BIT(30)
333329
} AstFlags;
334330

335331
typedef enum UnaryOp {
@@ -1524,7 +1520,6 @@ struct AstPolyQuery {
15241520
AstFunction *function_header;
15251521

15261522
b32 error_on_fail : 1; // Whether or not to report errors on failing to match.
1527-
b32 successful_symres : 1; // If something successful happened in symbol resolution
15281523
};
15291524

15301525

@@ -1847,7 +1842,6 @@ void entity_heap_add_job(EntityHeap *entities, enum TypeMatch (*func)(Context *,
18471842
// If target_arr is null, the entities will be placed directly in the heap.
18481843
void add_entities_for_node(EntityHeap *entities, bh_arr(Entity *)* target_arr, AstNode* node, Scope* scope, Package* package);
18491844

1850-
// void symres_entity(Context *context, Entity* ent);
18511845
void check_entity(Context *context, Entity* ent);
18521846
void emit_entity(Context *context, Entity* ent);
18531847

compiler/src/checker.c

+33-34
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,6 @@ typedef enum CheckStatus {
9292
Check_Complete, // The node is done processing
9393

9494
Check_Errors_Start,
95-
// Check_Return_To_Symres, // Return this node for further symres processing
9695
Check_Goto_Parse,
9796
Check_Yield,
9897
Check_Failed, // The node is done processing and should be put in the state of Failed.
@@ -206,7 +205,7 @@ CHECK_FUNC(symbol, AstNode** symbol_node) {
206205
OnyxToken* token = (*symbol_node)->token;
207206
AstNode* res = symbol_resolve(context, context->checker.current_scope, token);
208207

209-
if (!res) { // :SymresStall
208+
if (!res) {
210209
if (context->cycle_detected) {
211210
token_toggle_end(token);
212211
char *closest = find_closest_symbol_in_scope_and_parents(context, context->checker.current_scope, token->text);
@@ -435,6 +434,15 @@ CHECK_FUNC(for, AstFor* fornode) {
435434
CHECK(expression, &fornode->iter);
436435
resolve_expression_type(context, fornode->iter);
437436

437+
//
438+
// These locals have to be checked after the iterator value to avoid incorrect
439+
// symbol resolutions.
440+
//
441+
// for a in x {
442+
// for a in a { // <-
443+
// }
444+
// }
445+
//
438446
CHECK(local, &fornode->var);
439447
if (fornode->index_var) {
440448
fornode->index_var->flags |= Ast_Flag_Cannot_Take_Addr;
@@ -697,6 +705,15 @@ CHECK_FUNC(case, AstSwitchCase *casenode) {
697705
}
698706

699707
CHECK_FUNC(switch, AstSwitch* switchnode) {
708+
//
709+
// Checking switches is quite complicated and tricky because of the feature-set Onyx
710+
// supports. Switch bodies can contain arbitrary statements at parse-time, but must
711+
// be expanded to a tree of block-nodes with case-nodes as the leaves. This complicates
712+
// the checking, because case-bodies cannot be checked before they know the type of their
713+
// captured variables (if there are any), but the case values must be checked before the
714+
// switch node can do proper type checking.
715+
//
716+
700717
if (switchnode->initialization) {
701718
if (switchnode->scope == NULL) {
702719
switchnode->scope = scope_create(context, context->checker.current_scope, switchnode->token->pos);
@@ -746,11 +763,13 @@ CHECK_FUNC(switch, AstSwitch* switchnode) {
746763
switchnode->flags |= Ast_Flag_Has_Been_Checked;
747764
}
748765

749-
// Should the case block code be checked here?
750-
// Or should this just exist to resolve macros and expand #unquotes
751-
// then the cases are consumed into the array or cases, THEN the blocks
752-
// are actually checked?
753766
if (switchnode->cases == NULL) {
767+
//
768+
// Set CM_Dont_Check_Case_Bodies so the bodies of case nodes will be skipped.
769+
// This avoids weird type-checking and symbol resolution issues when a case
770+
// node comes from an #insert or macro expansion. They will be re-checked
771+
// fully in the next check_block below.
772+
//
754773
enable_mode(context, CM_Dont_Check_Case_Bodies);
755774
CHECK(block, switchnode->case_block);
756775
disable_mode(context, CM_Dont_Check_Case_Bodies);
@@ -2657,7 +2676,6 @@ CHECK_FUNC(field_access, AstFieldAccess** pfield) {
26572676
expr->kind == Ast_Kind_Compiler_Extension ||
26582677
expr->kind == Ast_Kind_Package) {
26592678
goto try_resolve_from_node;
2660-
// return Check_Return_To_Symres;
26612679
}
26622680
}
26632681

@@ -3768,10 +3786,6 @@ CHECK_FUNC(block, AstBlock* block) {
37683786
block->statement_idx++;
37693787
break;
37703788

3771-
// case Check_Return_To_Symres:
3772-
// block->statement_idx = 0;
3773-
// return cs;
3774-
37753789
case Check_Failed:
37763790
case Check_Error:
37773791
if (block->macro_generated_from) {
@@ -3808,7 +3822,6 @@ CHECK_FUNC(polyproc, AstFunction* pp) {
38083822
AstParam *param = &pp->params[p->idx];
38093823
if (param->default_value != NULL) {
38103824
CHECK(expression, &param->default_value);
3811-
// if (onyx_has_errors(context)) return Symres_Error;
38123825
}
38133826
}
38143827

@@ -3837,7 +3850,6 @@ CHECK_FUNC(function, AstFunction* func) {
38373850
scope_enter(context, func->scope);
38383851

38393852
if ((func->flags & Ast_Flag_Has_Been_Symres) == 0) {
3840-
// :EliminatingSymres
38413853
bh_arr_each(AstParam, param, func->params) {
38423854
// CLEANUP: Currently, in order to 'use' parameters, the type must be completely
38433855
// resolved and built. This is excessive because all that should need to be known
@@ -5552,12 +5564,9 @@ CHECK_FUNC(constraint_context, ConstraintContext *cc, Scope *scope, OnyxFilePos
55525564
}
55535565

55545566
CHECK_FUNC(polyquery, AstPolyQuery *query) {
5555-
query->successful_symres = 0;
5556-
55575567
if (query->function_header->scope == NULL)
55585568
query->function_header->scope = scope_create(context, query->proc->parent_scope_of_poly_proc, query->token->pos);
55595569

5560-
// query->function_header->flags |= Ast_Flag_Hack_Only_Check_Types;
55615570
enable_mode(context, CM_Dont_Resolve_Symbols);
55625571
check_temp_function_header(context, query->function_header);
55635572
disable_mode(context, CM_Dont_Resolve_Symbols);
@@ -5578,6 +5587,7 @@ CHECK_FUNC(polyquery, AstPolyQuery *query) {
55785587
}
55795588
}
55805589

5590+
b32 solved_something = 0;
55815591
bh_arr_each(AstParam, param, query->function_header->params) {
55825592
if (param->local->type_node != NULL) {
55835593
context->checker.resolved_a_symbol = 0;
@@ -5588,11 +5598,12 @@ CHECK_FUNC(polyquery, AstPolyQuery *query) {
55885598
param->local->flags &= ~Ast_Flag_Symbol_Invisible;
55895599
onyx_errors_enable(context);
55905600

5591-
if (context->checker.resolved_a_symbol) query->successful_symres = 1;
5601+
if (context->checker.resolved_a_symbol) {
5602+
solved_something = 1;
5603+
}
55925604
}
55935605
}
55945606

5595-
b32 solved_something = 0;
55965607
i32 solved_count = 0;
55975608
OnyxError err_msg = { 0 };
55985609

@@ -5623,7 +5634,7 @@ CHECK_FUNC(polyquery, AstPolyQuery *query) {
56235634

56245635
case TYPE_MATCH_YIELD:
56255636
case TYPE_MATCH_FAILED: {
5626-
if (query->successful_symres || solved_something) continue;
5637+
if (solved_something) continue;
56275638

56285639
if (query->error_on_fail || context->cycle_detected) {
56295640
ONYX_ERROR(query->token->pos, Error_Critical, "Error solving for polymorphic variable '%b'.", param->poly_sym->token->text, param->poly_sym->token->length);
@@ -5647,7 +5658,7 @@ CHECK_FUNC(polyquery, AstPolyQuery *query) {
56475658
scope_leave(context);
56485659

56495660
if (solved_count != bh_arr_length(query->proc->poly_params)) {
5650-
if (solved_something || query->successful_symres) {
5661+
if (solved_something) {
56515662
return Check_Yield;
56525663
} else {
56535664
return Check_Failed;
@@ -5824,22 +5835,10 @@ CHECK_FUNC(import, AstImport* import) {
58245835
// use X { a, b, c }
58255836
bh_arr_each(QualifiedImport, qi, import->only) {
58265837
AstNode* imported = symbol_resolve(context, import_scope, qi->symbol_name);
5827-
if (imported == NULL) { // :SymresStall
5838+
if (imported == NULL) {
58285839
YIELD_(qi->symbol_name->pos,
5829-
"The symbol '%b' was not found the package '%s'.",
5840+
"The symbol '%b' was not found package '%s'.",
58305841
qi->symbol_name->text, qi->symbol_name->length, package->package->name);
5831-
5832-
// if (context->checker.report_unresolved_symbols) {
5833-
// // TODO: Change package->name to package->qualified_name when
5834-
// // merged with the documentation generation branch.
5835-
// ONYX_ERROR(qi->symbol_name->pos, Error_Critical,
5836-
// "The symbol '%b' was not found the package '%s'.",
5837-
// qi->symbol_name->text, qi->symbol_name->length, package->package->name);
5838-
5839-
// return Symres_Error;
5840-
// } else {
5841-
// return Symres_Yield_Macro;
5842-
// }
58435842
}
58445843

58455844
symbol_introduce(context, context->checker.current_scope, qi->as_name, imported);

compiler/src/library_main.c

-1
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,6 @@ static b32 process_entity(Context *context, Entity* ent) {
409409
}
410410
break;
411411

412-
// case Entity_State_Resolve_Symbols: symres_entity(context, ent); break;
413412
case Entity_State_Check_Types: check_entity(context, ent); break;
414413
case Entity_State_Code_Gen: emit_entity(context, ent); break;
415414

compiler/src/polymorph.h

+1-2
Original file line numberDiff line numberDiff line change
@@ -787,7 +787,6 @@ static bh_arr(AstPolySolution) find_polymorphic_slns(Context *context, AstFuncti
787787
query->function_header->flags |= Ast_Flag_Header_Check_No_Error;
788788
query->function_header->scope = NULL;
789789
query->error_on_fail = necessary;
790-
query->successful_symres = 1;
791790

792791
bh_imap_put(&pp->active_queries, (u64) actual, (u64) query);
793792
add_entities_for_node(&context->entities, NULL, (AstNode *) query, NULL, NULL);
@@ -979,7 +978,7 @@ typedef struct AutoPolymorphVariable {
979978
AstType **replace;
980979
} AutoPolymorphVariable;
981980

982-
// This should be called after all the parameter types have been symresed, but before anything
981+
// This should be called after all the parameter types have been had symbols resolved, but before anything
983982
// happens to the body.
984983
b32 potentially_convert_function_to_polyproc(Context *context, AstFunction *func) {
985984
bh_arr(AutoPolymorphVariable) auto_vars = NULL;

compiler/src/utils.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -883,7 +883,7 @@ void expand_macro(Context *context, AstCall** pcall, AstFunction* template) {
883883
scope_include(context, argument_scope, template->poly_scope, call->token->pos);
884884

885885
if (bh_arr_length(nodes_that_need_entities) > 0) {
886-
// :CopyPaste from symres_function
886+
// :CopyPaste from check_function
887887
bh_arr_each(AstNode *, node, nodes_that_need_entities) {
888888
// This makes a lot of assumptions about how these nodes are being processed,
889889
// and I don't want to start using this with other nodes without considering

0 commit comments

Comments
 (0)