Skip to content

Commit 122d33b

Browse files
committed
changed: compiler options to not be a pointer
1 parent ff51bd9 commit 122d33b

13 files changed

+81
-85
lines changed

compiler/include/astnodes.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2205,7 +2205,7 @@ struct Context {
22052205

22062206
Scope *global_scope;
22072207

2208-
CompileOptions* options;
2208+
CompileOptions options;
22092209

22102210
bh_arena ast_arena;
22112211
bh_allocator token_alloc, ast_alloc;

compiler/src/builtins.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -565,7 +565,7 @@ void initalize_special_globals(Context *context) {
565565
context->builtins.tagged_procedures_node = (AstTyped *) symbol_raw_resolve(context, p->scope, "tagged_procedures");
566566
context->builtins.tagged_globals_node = (AstTyped *) symbol_raw_resolve(context, p->scope, "tagged_globals");
567567

568-
if (context->options->stack_trace_enabled) {
568+
if (context->options.stack_trace_enabled) {
569569
context->builtins.stack_trace_type = (AstType *) symbol_raw_resolve(context, p->scope, "Stack_Trace");
570570
}
571571
}
@@ -585,20 +585,20 @@ void introduce_build_options(Context *context) {
585585
return;
586586
}
587587

588-
AstNumLit* runtime_type = make_int_literal(context, context->options->runtime);
588+
AstNumLit* runtime_type = make_int_literal(context, context->options.runtime);
589589
runtime_type->type_node = Runtime_Type;
590590
add_entities_for_node(&context->entities, NULL, (AstNode *) runtime_type, NULL, NULL);
591591
symbol_builtin_introduce(context, p->scope, "runtime", (AstNode *) runtime_type);
592592

593-
AstNumLit* multi_threaded = make_int_literal(context, context->options->use_multi_threading);
593+
AstNumLit* multi_threaded = make_int_literal(context, context->options.use_multi_threading);
594594
multi_threaded->type_node = (AstType *) &context->basic_types.type_bool;
595595
symbol_builtin_introduce(context, p->scope, "Multi_Threading_Enabled", (AstNode *) multi_threaded);
596596

597-
AstNumLit* debug_mode = make_int_literal(context, context->options->debug_info_enabled);
597+
AstNumLit* debug_mode = make_int_literal(context, context->options.debug_info_enabled);
598598
debug_mode->type_node = (AstType *) &context->basic_types.type_bool;
599599
symbol_builtin_introduce(context, p->scope, "Debug_Mode_Enabled", (AstNode *) debug_mode);
600600

601-
AstNumLit* stack_trace = make_int_literal(context, context->options->stack_trace_enabled);
601+
AstNumLit* stack_trace = make_int_literal(context, context->options.stack_trace_enabled);
602602
stack_trace->type_node = (AstType *) &context->basic_types.type_bool;
603603
symbol_builtin_introduce(context, p->scope, "Stack_Trace_Enabled", (AstNode *) stack_trace);
604604

@@ -655,7 +655,7 @@ void introduce_build_options(Context *context) {
655655
add_entities_for_node(&context->entities, NULL, (AstNode *) arch_type, NULL, NULL);
656656
symbol_builtin_introduce(context, p->scope, "arch", (AstNode *) arch_type);
657657

658-
if (context->options->generate_foreign_info) {
658+
if (context->options.generate_foreign_info) {
659659
AstNumLit* foreign_info = make_int_literal(context, 1);
660660
foreign_info->type_node = (AstType *) &context->basic_types.type_bool;
661661
symbol_builtin_introduce(context, p->scope, "Generated_Foreign_Info", (AstNode *) foreign_info);

compiler/src/checker.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4538,7 +4538,7 @@ CHECK_FUNC(function_header, AstFunction* func) {
45384538
CHECK(expression, &func->foreign.import_name);
45394539
}
45404540

4541-
if (context->options->stack_trace_enabled) {
4541+
if (context->options.stack_trace_enabled) {
45424542
if (!func->stack_trace_local) {
45434543
OnyxToken *stack_trace_token = bh_alloc_item(context->ast_alloc, OnyxToken);
45444544
stack_trace_token->type = Token_Type_Symbol;
@@ -4835,7 +4835,7 @@ CHECK_FUNC(static_if, AstIf* static_if) {
48354835

48364836
b32 resolution = static_if_resolution(context, static_if);
48374837

4838-
if (context->options->print_static_if_results)
4838+
if (context->options.print_static_if_results)
48394839
bh_printf("Static if statement at %s:%d:%d resulted in %s\n",
48404840
static_if->token->pos.filename,
48414841
static_if->token->pos.line,
@@ -5634,7 +5634,7 @@ CHECK_FUNC(file_contents, AstFileContents* fc) {
56345634
ERROR(fc->token->pos, "Expected given expression to be a compile-time stirng literal.");
56355635
}
56365636

5637-
if (context->options->no_file_contents) {
5637+
if (context->options.no_file_contents) {
56385638
ERROR(fc->token->pos, "#file_contents is disabled for this compilation.");
56395639
}
56405640

@@ -5691,7 +5691,7 @@ CHECK_FUNC(foreign_block, AstForeignBlock *fb) {
56915691
}
56925692
}
56935693

5694-
if (context->options->generate_foreign_info) {
5694+
if (context->options.generate_foreign_info) {
56955695
// When generating foreign info, we have to pass this on to codegen
56965696
// so it can build the static data that goes in the binary.
56975697
return Check_Success;
@@ -5763,7 +5763,7 @@ CHECK_FUNC(import, AstImport* import) {
57635763
}
57645764

57655765
CHECK_FUNC(compiler_extension, AstCompilerExtension *ext) {
5766-
if (context->options->no_compiler_extensions) {
5766+
if (context->options.no_compiler_extensions) {
57675767
ERROR(ext->token->pos, "Compiler extensions are disabled in this compilation.");
57685768
}
57695769

compiler/src/doc.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ void onyx_docs_emit_symbol_info(Context *context, bh_buffer *out_buffer) {
4545
bh_buffer_write_u32(&sym_def_section, sym->line);
4646
bh_buffer_write_u32(&sym_def_section, sym->column);
4747

48-
if (context->options->generate_lsp_info_file) {
48+
if (context->options.generate_lsp_info_file) {
4949
if (sym->documentation_length > 0) {
5050
bh_buffer_write_u32(&sym_def_section, docs_section.length);
5151
bh_buffer_write_u32(&sym_def_section, sym->documentation_length);
@@ -73,7 +73,7 @@ void onyx_docs_emit_symbol_info(Context *context, bh_buffer *out_buffer) {
7373
bh_buffer_append(&header_section, "OSYM", 4);
7474

7575
u32 header_size = 32;
76-
if (context->options->generate_lsp_info_file) {
76+
if (context->options.generate_lsp_info_file) {
7777
bh_buffer_write_u32(&header_section, 2);
7878
header_size = 40;
7979
} else {
@@ -87,7 +87,7 @@ void onyx_docs_emit_symbol_info(Context *context, bh_buffer *out_buffer) {
8787
bh_buffer_write_u32(&header_section, header_size + file_section.length + sym_def_section.length);
8888
bh_buffer_write_u32(&header_section, bh_arr_length(syminfo->symbols_resolutions));
8989

90-
if (context->options->generate_lsp_info_file) {
90+
if (context->options.generate_lsp_info_file) {
9191
bh_buffer_write_u32(&header_section, header_size + file_section.length + sym_def_section.length + sym_res_section.length);
9292
bh_buffer_write_u32(&header_section, docs_section.length);
9393
}
@@ -98,7 +98,7 @@ void onyx_docs_emit_symbol_info(Context *context, bh_buffer *out_buffer) {
9898
bh_buffer_append(out_buffer, sym_def_section.data, sym_def_section.length);
9999
bh_buffer_append(out_buffer, sym_res_section.data, sym_res_section.length);
100100

101-
if (context->options->generate_lsp_info_file) {
101+
if (context->options.generate_lsp_info_file) {
102102
bh_buffer_append(out_buffer, docs_section.data, docs_section.length);
103103
}
104104

compiler/src/lex.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -613,7 +613,7 @@ OnyxTokenizer onyx_tokenizer_create(Context *context, bh_file_contents *fc) {
613613
.line_start = fc->data,
614614
.tokens = NULL,
615615

616-
.optional_semicolons = context->options->enable_optional_semicolons,
616+
.optional_semicolons = context->options.enable_optional_semicolons,
617617
.insert_semicolon = 0,
618618
};
619619

compiler/src/library_main.c

Lines changed: 31 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -137,12 +137,9 @@ onyx_context_t *onyx_context_create() {
137137
prepare_builtins(context);
138138
compiler_events_init(context);
139139

140-
// Options should be moved directly inside of the context instead of through a pointer...
141-
context->options = malloc(sizeof(* context->options));
142-
memset(context->options, 0, sizeof(* context->options));
143-
context->options->use_post_mvp_features = 1;
144-
context->options->enable_optional_semicolons = 1;
145-
context->options->generate_type_info = 1;
140+
context->options.use_post_mvp_features = 1;
141+
context->options.enable_optional_semicolons = 1;
142+
context->options.generate_type_info = 1;
146143

147144
OnyxFilePos internal_location = { 0 };
148145
internal_location.filename = "<compiler internal>";
@@ -175,8 +172,7 @@ void onyx_context_free(onyx_context_t *ctx) {
175172
bh_scratch_free(&context->scratch);
176173
bh_managed_heap_free(&context->heap);
177174

178-
bh_arr_free(context->options->mapped_folders);
179-
free(context->options);
175+
bh_arr_free(context->options.mapped_folders);
180176
free(ctx);
181177

182178
HACK_global_heap_allocator = NULL;
@@ -212,7 +208,7 @@ static b32 process_source_file(Context *context, char* filename) {
212208

213209
bh_arr_push(context->loaded_files, fc);
214210

215-
// if (context->options->verbose_output == 2)
211+
// if (context->options.verbose_output == 2)
216212
// bh_printf("Processing source file: %s (%d bytes)\n", file.filename, fc.length);
217213

218214
parse_source_file(context, &bh_arr_last(context->loaded_files));
@@ -233,7 +229,7 @@ static b32 process_load_entity(Context *context, Entity* ent) {
233229
include->name,
234230
parent_folder,
235231
".onyx",
236-
context->options->mapped_folders,
232+
context->options.mapped_folders,
237233
context->gp_alloc
238234
);
239235

@@ -259,7 +255,7 @@ static b32 process_load_entity(Context *context, Entity* ent) {
259255
include->name,
260256
parent_folder,
261257
"",
262-
context->options->mapped_folders,
258+
context->options.mapped_folders,
263259
context->gp_alloc
264260
);
265261
bh_path_convert_separators(folder);
@@ -418,7 +414,7 @@ static void prime_pump(Context *context) {
418414
.include = create_load(context, "core:runtime/build_opts", -1),
419415
}));
420416

421-
if (context->options->runtime != Runtime_Custom) {
417+
if (context->options.runtime != Runtime_Custom) {
422418
// HACK
423419
context->special_global_entities.remaining = 5;
424420

@@ -461,7 +457,7 @@ static void prime_pump(Context *context) {
461457
add_entities_for_node(&context->entities, NULL, (AstNode *) &context->builtins.closure_base, context->global_scope, NULL);
462458
add_entities_for_node(&context->entities, NULL, (AstNode *) &context->builtins.stack_trace, context->global_scope, NULL);
463459

464-
if (!context->options->no_core) {
460+
if (!context->options.no_core) {
465461
entity_heap_insert(&context->entities, ((Entity) {
466462
.state = Entity_State_Parse,
467463
.type = Entity_Type_Load_File,
@@ -470,15 +466,15 @@ static void prime_pump(Context *context) {
470466
}));
471467
}
472468

473-
if (context->options->generate_symbol_info_file) {
469+
if (context->options.generate_symbol_info_file) {
474470
context->symbol_info = bh_alloc_item(context->gp_alloc, SymbolInfoTable);
475471
bh_imap_init(&context->symbol_info->node_to_id, context->gp_alloc, 512);
476472
bh_arr_new(context->gp_alloc, context->symbol_info->symbols, 128);
477473
bh_arr_new(context->gp_alloc, context->symbol_info->symbols_resolutions, 128);
478474
sh_new_arena(context->symbol_info->files);
479475
}
480476

481-
if (context->options->generate_odoc) {
477+
if (context->options.generate_odoc) {
482478
context->doc_info = bh_alloc_item(context->gp_alloc, OnyxDocInfo);
483479
memset(context->doc_info, 0, sizeof(OnyxDocInfo));
484480
bh_arr_new(context->gp_alloc, context->doc_info->procedures, 128);
@@ -517,7 +513,7 @@ onyx_pump_t onyx_pump(onyx_context_t *ctx) {
517513
u64 perf_start;
518514
EntityType perf_entity_type;
519515
EntityState perf_entity_state;
520-
if (context->options->running_perf) {
516+
if (context->options.running_perf) {
521517
perf_start = bh_time_curr_micro();
522518
perf_entity_type = ent->type;
523519
perf_entity_state = ent->state;
@@ -568,7 +564,7 @@ onyx_pump_t onyx_pump(onyx_context_t *ctx) {
568564
if (ent->state != Entity_State_Finalized && ent->state != Entity_State_Failed)
569565
entity_heap_insert_existing(&context->entities, ent);
570566

571-
if (context->options->running_perf) {
567+
if (context->options.running_perf) {
572568
u64 perf_end = bh_time_curr_micro();
573569

574570
u64 duration = perf_end - perf_start;
@@ -660,23 +656,23 @@ int32_t onyx_set_option_bytes(onyx_context_t *ctx, onyx_option_t opt, char *valu
660656

661657
int32_t onyx_set_option_int(onyx_context_t *ctx, onyx_option_t opt, int32_t value) {
662658
switch (opt) {
663-
case ONYX_OPTION_POST_MVP_FEATURES: ctx->context.options->use_post_mvp_features = value; return 1;
664-
case ONYX_OPTION_MULTI_THREADING: ctx->context.options->use_multi_threading = value; return 1;
665-
case ONYX_OPTION_GENERATE_FOREIGN_INFO: ctx->context.options->generate_foreign_info = value; return 1;
666-
case ONYX_OPTION_GENERATE_TYPE_INFO: ctx->context.options->generate_type_info = value; return 1;
667-
case ONYX_OPTION_GENERATE_METHOD_INFO: ctx->context.options->generate_method_info = value; return 1;
668-
case ONYX_OPTION_GENERATE_DEBUG_INFO: ctx->context.options->debug_info_enabled = value; return 1;
669-
case ONYX_OPTION_GENERATE_STACK_TRACE: ctx->context.options->stack_trace_enabled = value; return 1;
670-
case ONYX_OPTION_GENERATE_NAME_SECTION: ctx->context.options->generate_name_section = value; return 1;
671-
case ONYX_OPTION_GENERATE_SYMBOL_INFO: ctx->context.options->generate_symbol_info_file = value; return 1;
672-
case ONYX_OPTION_GENERATE_LSP_INFO: ctx->context.options->generate_lsp_info_file = value; return 1;
673-
case ONYX_OPTION_GENERATE_DOC_INFO: ctx->context.options->generate_odoc = value; return 1;
674-
case ONYX_OPTION_DISABLE_CORE: ctx->context.options->no_core = value; return 1;
675-
case ONYX_OPTION_DISABLE_STALE_CODE: ctx->context.options->no_stale_code = value; return 1;
676-
case ONYX_OPTION_OPTIONAL_SEMICOLONS: ctx->context.options->enable_optional_semicolons = value; return 1;
677-
case ONYX_OPTION_DISABLE_FILE_CONTENTS: ctx->context.options->no_file_contents = value; return 1;
678-
case ONYX_OPTION_DISABLE_EXTENSIONS: ctx->context.options->no_compiler_extensions = value; return 1;
679-
case ONYX_OPTION_PLATFORM: ctx->context.options->runtime = value; return 1;
659+
case ONYX_OPTION_POST_MVP_FEATURES: ctx->context.options.use_post_mvp_features = value; return 1;
660+
case ONYX_OPTION_MULTI_THREADING: ctx->context.options.use_multi_threading = value; return 1;
661+
case ONYX_OPTION_GENERATE_FOREIGN_INFO: ctx->context.options.generate_foreign_info = value; return 1;
662+
case ONYX_OPTION_GENERATE_TYPE_INFO: ctx->context.options.generate_type_info = value; return 1;
663+
case ONYX_OPTION_GENERATE_METHOD_INFO: ctx->context.options.generate_method_info = value; return 1;
664+
case ONYX_OPTION_GENERATE_DEBUG_INFO: ctx->context.options.debug_info_enabled = value; return 1;
665+
case ONYX_OPTION_GENERATE_STACK_TRACE: ctx->context.options.stack_trace_enabled = value; return 1;
666+
case ONYX_OPTION_GENERATE_NAME_SECTION: ctx->context.options.generate_name_section = value; return 1;
667+
case ONYX_OPTION_GENERATE_SYMBOL_INFO: ctx->context.options.generate_symbol_info_file = value; return 1;
668+
case ONYX_OPTION_GENERATE_LSP_INFO: ctx->context.options.generate_lsp_info_file = value; return 1;
669+
case ONYX_OPTION_GENERATE_DOC_INFO: ctx->context.options.generate_odoc = value; return 1;
670+
case ONYX_OPTION_DISABLE_CORE: ctx->context.options.no_core = value; return 1;
671+
case ONYX_OPTION_DISABLE_STALE_CODE: ctx->context.options.no_stale_code = value; return 1;
672+
case ONYX_OPTION_OPTIONAL_SEMICOLONS: ctx->context.options.enable_optional_semicolons = value; return 1;
673+
case ONYX_OPTION_DISABLE_FILE_CONTENTS: ctx->context.options.no_file_contents = value; return 1;
674+
case ONYX_OPTION_DISABLE_EXTENSIONS: ctx->context.options.no_compiler_extensions = value; return 1;
675+
case ONYX_OPTION_PLATFORM: ctx->context.options.runtime = value; return 1;
680676

681677
default:
682678
break;
@@ -711,7 +707,7 @@ void onyx_add_mapped_dir(onyx_context_t *ctx, char *mapped_name, int32_t mapped_
711707
if (mapped_length < 0) mapped_length = strlen(mapped_name);
712708
if (dir_length < 0) dir_length = strlen(dir);
713709

714-
bh_arr_push(ctx->context.options->mapped_folders, ((bh_mapped_folder) {
710+
bh_arr_push(ctx->context.options.mapped_folders, ((bh_mapped_folder) {
715711
bh_strdup_len(ctx->context.ast_alloc, mapped_name, mapped_length),
716712
bh_strdup_len(ctx->context.ast_alloc, dir, dir_length)
717713
}));

compiler/src/onyx.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11

2-
if (context->options->verbose_output > 0) {
2+
if (context->options.verbose_output > 0) {
33
bh_printf("Mapped folders:\n");
4-
bh_arr_each(bh_mapped_folder, p, context->options->mapped_folders) {
4+
bh_arr_each(bh_mapped_folder, p, context->options.mapped_folders) {
55
bh_printf("\t%s: %s\n", p->name, p->folder);
66
}
77
bh_printf("\n");
88
}
99

1010

11-
if (context->options->verbose_output == 2)
11+
if (context->options.verbose_output == 2)
1212
bh_printf("Processing source file: %s (%d bytes)\n", file.filename, fc.length);
1313

1414
static char verbose_output_buffer[512];
15-
if (context->options->verbose_output == 3) {
15+
if (context->options.verbose_output == 3) {
1616
if (ent->expr && ent->expr->token)
1717
snprintf(verbose_output_buffer, 511,
1818
"%20s | %24s (%d, %d) | %5d | %s:%i:%i \n",
@@ -35,7 +35,7 @@
3535
}
3636

3737
b32 changed = ent->state != before_state;
38-
if (context->options->verbose_output == 3) {
38+
if (context->options.verbose_output == 3) {
3939
if (changed) printf("SUCCESS to %20s | %s", entity_state_strings[ent->state], verbose_output_buffer);
4040
else printf("YIELD to %20s | %s", entity_state_strings[ent->state], verbose_output_buffer);
4141
}
@@ -86,11 +86,11 @@ static void output_dummy_progress_bar(Context *context) {
8686
#endif
8787

8888

89-
if (context->options->fun_output)
89+
if (context->options.fun_output)
9090
printf("\e[2J");
9191

9292
#if defined(_BH_LINUX) || defined(_BH_DARWIN)
93-
if (context->options->fun_output) {
93+
if (context->options.fun_output) {
9494
output_dummy_progress_bar(context);
9595

9696
if (ent->expr->token) {
@@ -120,11 +120,11 @@ static void output_dummy_progress_bar(Context *context) {
120120

121121
u64 duration = bh_time_duration(start_time);
122122

123-
if (context->options->verbose_output > 0) {
123+
if (context->options.verbose_output > 0) {
124124
printf("Type table size: %d bytes\n", context->wasm_module->type_info_size);
125125
}
126126

127-
if (context->options->running_perf) {
127+
if (context->options.running_perf) {
128128
fori (i, 0, Entity_State_Count) {
129129
printf("| %27s | %10llu us |\n", entity_state_strings[i], context->stats.microseconds_per_state[i]);
130130
}

compiler/src/parser.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4781,7 +4781,7 @@ void onyx_parse(OnyxParser *parser) {
47814781

47824782
if (parse_possible_directive(parser, "allow_stale_code")
47834783
&& !parser->package->is_included_somewhere
4784-
&& !parser->context->options->no_stale_code) {
4784+
&& !parser->context->options.no_stale_code) {
47854785
bh_arr_new(parser->context->gp_alloc, parser->package->buffered_entities, 32);
47864786
bh_arr_push(parser->alternate_entity_placement_stack, &parser->package->buffered_entities);
47874787
}

compiler/src/utils.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1690,7 +1690,7 @@ static u32 symbol_info_get_file_id(SymbolInfoTable *syminfo, const char *filenam
16901690
}
16911691

16921692
void track_declaration_for_symbol_info(Context *context, OnyxFilePos pos, AstNode *node) {
1693-
if (!context->options->generate_symbol_info_file) return;
1693+
if (!context->options.generate_symbol_info_file) return;
16941694
if (pos.filename == NULL) return;
16951695

16961696
SymbolInfoTable *syminfo = context->symbol_info;
@@ -1714,8 +1714,8 @@ void track_declaration_for_symbol_info(Context *context, OnyxFilePos pos, AstNod
17141714
}
17151715

17161716
void track_documentation_for_symbol_info(Context *context, AstNode *node, AstBinding *binding) {
1717-
if (!context->options->generate_lsp_info_file) return;
1718-
if (!context->options->generate_symbol_info_file) return;
1717+
if (!context->options.generate_lsp_info_file) return;
1718+
if (!context->options.generate_symbol_info_file) return;
17191719

17201720
SymbolInfoTable *syminfo = context->symbol_info;
17211721
assert(syminfo);
@@ -1736,7 +1736,7 @@ void track_documentation_for_symbol_info(Context *context, AstNode *node, AstBin
17361736
}
17371737

17381738
void track_resolution_for_symbol_info(Context *context, AstNode *original, AstNode *resolved) {
1739-
if (!context->options->generate_symbol_info_file) return;
1739+
if (!context->options.generate_symbol_info_file) return;
17401740
if (!resolved) return;
17411741

17421742
SymbolInfoTable *syminfo = context->symbol_info;

0 commit comments

Comments
 (0)