From: Brendan Hansen Date: Mon, 1 Feb 2021 19:52:58 +0000 (-0600) Subject: more random cleanups X-Git-Url: https://git.brendanfh.com/?a=commitdiff_plain;h=b7d2fb5df88ee48bca5c16c43b87c5c47184bfbc;p=onyx.git more random cleanups --- diff --git a/bin/onyx b/bin/onyx index b760869b..c9f7b5c2 100755 Binary files a/bin/onyx and b/bin/onyx differ diff --git a/onyx.exe b/onyx.exe index 20936ed8..eee67d05 100644 Binary files a/onyx.exe and b/onyx.exe differ diff --git a/src/onyx.c b/src/onyx.c index 1393fb56..0be1e45a 100644 --- a/src/onyx.c +++ b/src/onyx.c @@ -32,7 +32,7 @@ static const char* docstring = "Onyx compiler version " VERSION "\n" "\n" "Usage:\n" "\tonyx [-o ] [--verbose] \n" - "\tonyx doc \n" + // "\tonyx doc \n" "\tonyx help\n" "\n" "Flags:\n" @@ -62,15 +62,11 @@ static CompileOptions compile_opts_parse(bh_allocator alloc, int argc, char *arg if (argc == 1) return options; - if (!strcmp(argv[1], "doc")) { - options.action = ONYX_COMPILE_ACTION_DOCUMENT; - } - else if (!strcmp(argv[1], "help")) { - options.action = ONYX_COMPILE_ACTION_PRINT_HELP; - } - else { - options.action = ONYX_COMPILE_ACTION_COMPILE; - } + if (!strcmp(argv[1], "help")) options.action = ONYX_COMPILE_ACTION_PRINT_HELP; + // else if (!strcmp(argv[1], "doc")) { + // options.action = ONYX_COMPILE_ACTION_DOCUMENT; + // } + else options.action = ONYX_COMPILE_ACTION_COMPILE; if (options.action == ONYX_COMPILE_ACTION_COMPILE) { fori(i, 1, argc) { @@ -119,8 +115,6 @@ static void compile_opts_free(CompileOptions* opts) { typedef enum CompilerProgress { - ONYX_COMPILER_PROGRESS_FAILED_READ, - ONYX_COMPILER_PROGRESS_FAILED_PARSE, ONYX_COMPILER_PROGRESS_ERROR, ONYX_COMPILER_PROGRESS_FAILED_OUTPUT, ONYX_COMPILER_PROGRESS_SUCCESS @@ -226,21 +220,19 @@ static void parse_source_file(bh_file_contents* file_contents) { onyx_parser_free(&parser); } -static CompilerProgress process_source_file(char* filename) { +static void process_source_file(char* filename) { bh_arr_each(bh_file_contents, fc, context.loaded_files) { // CLEANUP: Add duplicate resolutions, such as // ./foo and ./test/../foo // should be the same thing. - if (!strcmp(fc->filename, filename)) { - return ONYX_COMPILER_PROGRESS_SUCCESS; - } + if (!strcmp(fc->filename, filename)) return; } bh_file file; bh_file_error err = bh_file_open(&file, filename); if (err != BH_FILE_ERROR_NONE) { onyx_report_error((OnyxFilePos) { 0 }, "Failed to open file %s\n", filename); - return ONYX_COMPILER_PROGRESS_FAILED_READ; + return; } bh_file_contents fc = bh_file_read_contents(context.token_alloc, &file); @@ -248,17 +240,10 @@ static CompilerProgress process_source_file(char* filename) { bh_arr_push(context.loaded_files, fc); - if (context.options->verbose_output == 2) { + if (context.options->verbose_output == 2) bh_printf("Processing source file: %s (%d bytes)\n", file.filename, fc.length); - } parse_source_file(&fc); - - if (onyx_has_errors()) { - return ONYX_COMPILER_PROGRESS_FAILED_PARSE; - } else { - return ONYX_COMPILER_PROGRESS_SUCCESS; - } } static void process_load_entity(Entity* ent) { @@ -340,7 +325,6 @@ static i32 onyx_compile() { while (!bh_arr_is_empty(context.entities.entities)) { Entity ent = entity_heap_top(&context.entities); entity_heap_remove_top(&context.entities); - if (ent.state == Entity_State_Finalized) continue; #if defined(_BH_LINUX) if (context.options->fun_output) { @@ -360,19 +344,14 @@ static i32 onyx_compile() { if (onyx_has_errors()) return ONYX_COMPILER_PROGRESS_ERROR; - // SPEED: Not checking if the entity is already finalized does diminish speeds - // a little bit, but it makes the fun visualization look better... so... I'm - // gonna keep this how it is for now. - brendanfh 2020/12/15 - - // if (changed && ent.state != Entity_State_Finalized) - entity_heap_insert(&context.entities, ent); + if (changed && ent.state != Entity_State_Finalized) + entity_heap_insert(&context.entities, ent); } // NOTE: Output to file bh_file output_file; - if (bh_file_create(&output_file, context.options->target_file) != BH_FILE_ERROR_NONE) { + if (bh_file_create(&output_file, context.options->target_file) != BH_FILE_ERROR_NONE) return ONYX_COMPILER_PROGRESS_FAILED_OUTPUT; - } if (context.options->verbose_output) bh_printf("Outputting to WASM file: %s\n", output_file.filename); @@ -404,31 +383,18 @@ int main(int argc, char *argv[]) { CompileOptions compile_opts = compile_opts_parse(global_heap_allocator, argc, argv); context_init(&compile_opts); - CompilerProgress compiler_progress = ONYX_COMPILER_PROGRESS_FAILED_READ; + CompilerProgress compiler_progress = ONYX_COMPILER_PROGRESS_ERROR; switch (compile_opts.action) { - case ONYX_COMPILE_ACTION_PRINT_HELP: - // NOTE: This could probably be made better - bh_printf(docstring); - return 1; + case ONYX_COMPILE_ACTION_PRINT_HELP: bh_printf(docstring); return 1; case ONYX_COMPILE_ACTION_COMPILE: compiler_progress = onyx_compile(); break; - case ONYX_COMPILE_ACTION_DOCUMENT: - bh_printf("Documentation has not been fully implemented yet.\n"); - exit(EXIT_FAILURE); - break; - default: break; } switch (compiler_progress) { - case ONYX_COMPILER_PROGRESS_FAILED_READ: - // NOTE: Do nothing since it was already printed above - break; - - case ONYX_COMPILER_PROGRESS_FAILED_PARSE: case ONYX_COMPILER_PROGRESS_ERROR: onyx_errors_print(); break; diff --git a/src/onyxparser.c b/src/onyxparser.c index da187e9f..9251f6c7 100644 --- a/src/onyxparser.c +++ b/src/onyxparser.c @@ -1,11 +1,10 @@ -// CLEANUP: With all the changes that have happened to the language over time, -// the focus of the parser has kind of been lost. Originally the parser's job -// was to collect everything that had to be processed later into an array, and -// then return that array. And for the most part, that is how it still works. -// But now, there is an entity system that supports dropping in new entities -// at any point, so I think it should be easy to drop out the middle man and -// directly add the entities during parse time. This would also get rid of -// having to allocate the temporary array for the parse results. +// The job of the parser for Onyx is to do two things: +// 1. Submit nodes to the entity heap for further processing. +// Nodes such as procedure defintions, string literals, etc. +// +// 2. Insert static symbols into scopes. +// Things defined at top level or inside of static scopes such +// as bindings in procedures or in struct scopes. // Things that need to be cleaned up in the parser: // - control block local variables should be more extensible and reuse more code @@ -787,10 +786,9 @@ static AstTyped* parse_expression(OnyxParser* parser, b32 assignment_allowed) { right = parse_factor(parser); bin_op->right = right; } - - bh_arr_free(tree_stack); - + expression_done: + bh_arr_free(tree_stack); return root; } @@ -1046,11 +1044,10 @@ static i32 parse_possible_symbol_declaration(OnyxParser* parser, AstNode** ret) expect_token(parser, ':'); if (parser->curr->type == ':') { - Scope* insertion_scope = bh_arr_last(parser->scope_stack); - AstBinding* binding = parse_top_level_binding(parser, symbol); if (parser->hit_unexpected_token) return 2; - + + Scope* insertion_scope = bh_arr_last(parser->scope_stack); symbol_introduce(insertion_scope, symbol, binding->node); return 2; } diff --git a/src/onyxsymres.c b/src/onyxsymres.c index 3eaddbb1..2a88efe6 100644 --- a/src/onyxsymres.c +++ b/src/onyxsymres.c @@ -405,9 +405,6 @@ static void symres_expression(AstTyped** expr) { case Ast_Kind_Binary_Op: symres_expression(&((AstBinaryOp *)(*expr))->left); symres_expression(&((AstBinaryOp *)(*expr))->right); - - if (((AstBinaryOp *) (*expr))->left) - (*expr)->type_node = ((AstBinaryOp *)(*expr))->left->type_node; break; case Ast_Kind_Unary_Op: symres_unaryop((AstUnaryOp **) expr); break;