Skip to content

Commit 2b5ddd6

Browse files
authored
Merge pull request #181 from onyx-lang/fix/eliminate-symres
Fix: Eliminate symres phase
2 parents 00fd90b + 3b9d0b2 commit 2b5ddd6

File tree

17 files changed

+1792
-2482
lines changed

17 files changed

+1792
-2482
lines changed

build.bat

Lines changed: 2 additions & 2 deletions
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/build.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/bin/sh
22

3-
C_FILES="library_main astnodes builtins checker clone doc entities errors lex parser symres types utils wasm_emit extensions "
3+
C_FILES="library_main astnodes builtins checker clone doc entities errors lex parser types utils wasm_emit extensions "
44
LIBS="-lpthread -ldl -lm"
55
INCLUDES="-I./include -I../shared/include -I../shared/include/dyncall"
66

compiler/cli/main.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -588,7 +588,7 @@ static char *get_description_for_subcommand(char *path) {
588588
int previous_cursor = cursor;
589589
int name_length = uleb128_to_uint(d, &cursor);
590590

591-
if (strncmp("onyx-command-description", &d[cursor], name_length)) {
591+
if (strncmp("onyx-command-description", (const char *) &d[cursor], name_length)) {
592592
cursor = previous_cursor + section_length;
593593
continue;
594594
}
@@ -932,13 +932,19 @@ int main(int argc, char *argv[]) {
932932
case ONYX_EVENT_ALL_TYPES_CHECKED:
933933
break;
934934

935+
case ONYX_EVENT_PHASE_START:
936+
break;
937+
935938
case ONYX_EVENT_SYMBOL_DEFINED:
936939
// bh_printf("DEFINED SYMBOL AT %s:%d,%d\n",
937940
// onyx_event_field_str(ctx, i, "filename"),
938941
// onyx_event_field_int(ctx, i, "line"),
939942
// onyx_event_field_int(ctx, i, "column")
940943
// );
941944
break;
945+
946+
case ONYX_EVENT_UNKNOWN:
947+
break;
942948
}
943949
}
944950
}
@@ -959,8 +965,8 @@ int main(int argc, char *argv[]) {
959965

960966
printf("\nStatistics:\n");
961967
printf(" Time taken: %lf ms\n", (double) duration);
962-
printf(" Processed %llu lines (%f lines/second).\n", lines, lines_per_sec);
963-
printf(" Processed %llu tokens (%f tokens/second).\n", tokens, tokens_per_sec);
968+
printf(" Processed %d lines (%f lines/second).\n", lines, lines_per_sec);
969+
printf(" Processed %d tokens (%f tokens/second).\n", tokens, tokens_per_sec);
964970
printf("\n");
965971
}
966972

compiler/include/astnodes.h

Lines changed: 10 additions & 6 deletions
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_Resolved = BH_BIT(8),
288-
289287
Ast_Flag_No_Clone = BH_BIT(9),
290288

291289
Ast_Flag_Cannot_Take_Addr = BH_BIT(10),
@@ -327,7 +325,7 @@ typedef enum AstFlags {
327325

328326
Ast_Flag_Constraint_Is_Expression = BH_BIT(28),
329327

330-
Ast_Flag_Has_Been_Scheduled_For_Emit = BH_BIT(29)
328+
Ast_Flag_Has_Been_Scheduled_For_Emit = BH_BIT(29),
331329
} AstFlags;
332330

333331
typedef enum UnaryOp {
@@ -1489,6 +1487,7 @@ struct AstFunction {
14891487
b32 is_intrinsic : 1;
14901488

14911489
b32 named_return_locals_added : 1;
1490+
b32 ready_for_body_to_be_checked : 1;
14921491
};
14931492

14941493
struct AstCaptureBlock {
@@ -1521,7 +1520,6 @@ struct AstPolyQuery {
15211520
AstFunction *function_header;
15221521

15231522
b32 error_on_fail : 1; // Whether or not to report errors on failing to match.
1524-
b32 successful_symres : 1; // If something successful happened in symbol resolution
15251523
};
15261524

15271525

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

1847-
void symres_entity(Context *context, Entity* ent);
18481845
void check_entity(Context *context, Entity* ent);
18491846
void emit_entity(Context *context, Entity* ent);
18501847

@@ -1915,6 +1912,11 @@ typedef struct OnyxDocInfo {
19151912
u32 next_file_id;
19161913
} OnyxDocInfo;
19171914

1915+
typedef enum CheckerMode {
1916+
CM_Dont_Resolve_Symbols = BH_BIT(1),
1917+
CM_Dont_Check_Case_Bodies = BH_BIT(2),
1918+
CM_Allow_Init_Expressions = BH_BIT(3),
1919+
} CheckerMode;
19181920

19191921
typedef struct CheckerData {
19201922
b32 expression_types_must_be_known;
@@ -1928,9 +1930,11 @@ typedef struct CheckerData {
19281930
bh_arr(bh_arr(AstLocal *)) named_return_values_stack;
19291931

19301932
u32 current_checking_level;
1933+
CheckerMode mode;
19311934

19321935
Scope *current_scope;
1933-
b32 report_unresolved_symbols;
1936+
bh_arr(Scope *) scope_stack;
1937+
19341938
b32 resolved_a_symbol;
19351939
} CheckerData;
19361940

compiler/src/astnodes.c

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -588,9 +588,6 @@ b32 convert_numlit_to_type(Context *context, AstNumLit* num, Type* to_type, b32
588588
return 0;
589589
}
590590

591-
// TODO: This function should be able return a "yield" condition. There
592-
// are a couple cases that need to yield in order to be correct, like
593-
// polymorphic functions with a typeof for the return type.
594591
TypeMatch unify_node_and_type_(Context *context, AstTyped** pnode, Type* type, b32 permanent) {
595592
AstTyped* node = *pnode;
596593
if (type == NULL) return TYPE_MATCH_FAILED;
@@ -773,14 +770,13 @@ TypeMatch unify_node_and_type_(Context *context, AstTyped** pnode, Type* type, b
773770
// node does not match the given type:
774771
//
775772
// If the nodes type is a function type and that function has an automatic return
776-
// value placeholder, fill in that placeholder with the actual type.
773+
// value placeholder, wait for the return type to be solved by the function first.
777774
// :AutoReturnType
778775
if (node_type && node_type->kind == Type_Kind_Function
779776
&& node_type->Function.return_type == context->types.auto_return
780777
&& type->kind == Type_Kind_Function) {
781778

782-
node_type->Function.return_type = type->Function.return_type;
783-
return TYPE_MATCH_SUCCESS;
779+
return TYPE_MATCH_YIELD;
784780
}
785781

786782
// If the node is an auto cast (~~) node, then check to see if the cast is legal
@@ -1555,7 +1551,7 @@ TypeMatch implicit_cast_to_bool(Context *context, AstTyped **pnode) {
15551551
return TYPE_MATCH_YIELD;
15561552
}
15571553

1558-
static char *sanitize_name(bh_allocator a, const char *name) {
1554+
static char *sanitize_name(bh_allocator a, char *name) {
15591555
if (!name) return name;
15601556

15611557
char *sanitized = bh_strdup(a, name);
@@ -1599,7 +1595,7 @@ char* get_function_assembly_name(Context *context, AstFunction* func) {
15991595
if (func->token) {
16001596
return bh_aprintf(context->ast_alloc,
16011597
"unnamed_at_%s_%d",
1602-
sanitize_name(context->scratch_alloc, func->token->pos.filename),
1598+
sanitize_name(context->scratch_alloc, (char *) func->token->pos.filename),
16031599
func->token->pos.line);
16041600
}
16051601

0 commit comments

Comments
 (0)