From 695cc69cb08a46aff7fa5d3de06b747a15e86aec Mon Sep 17 00:00:00 2001 From: Brendan Hansen Date: Tue, 28 Feb 2023 12:46:23 -0600 Subject: [PATCH] breaking: moved `onyx-pkg` to `onyx pkg` `onyx-pkg` command is now gone. All functionality moved into `onyx pkg` command. --- bin/onyx-pkg | 4 ---- build.sh | 1 - compiler/src/onyx.c | 34 ++++++++++++++++------------------ compiler/src/parser.c | 5 ++++- core/container/result.onyx | 2 +- scripts/onyx-pkg.onyx | 13 ++++++++----- shared/include/bh.h | 11 +++++++++++ 7 files changed, 40 insertions(+), 30 deletions(-) delete mode 100755 bin/onyx-pkg diff --git a/bin/onyx-pkg b/bin/onyx-pkg deleted file mode 100755 index e219bd27..00000000 --- a/bin/onyx-pkg +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/sh - -# @Cleanup this assumes that this is the path, but it could be modified. -onyx run /usr/share/onyx/tools/onyx-pkg.onyx -- $@ \ No newline at end of file diff --git a/build.sh b/build.sh index 04e95866..59e9e139 100755 --- a/build.sh +++ b/build.sh @@ -8,7 +8,6 @@ sudo mkdir -p "$CORE_DIR" sudo cp -r ./core/ "$CORE_DIR" -sudo cp ./bin/onyx-pkg "$BIN_DIR/onyx-pkg" sudo mkdir -p "$CORE_DIR/tools" sudo cp ./scripts/onyx-pkg.onyx "$CORE_DIR/tools" diff --git a/compiler/src/onyx.c b/compiler/src/onyx.c index b6b53252..caab41f6 100644 --- a/compiler/src/onyx.c +++ b/compiler/src/onyx.c @@ -14,36 +14,27 @@ #define VERSION "v0.1.0" -// #ifndef CORE_INSTALLATION -// #ifdef _BH_LINUX -// #define CORE_INSTALLATION "/usr/share/onyx" -// #elif defined(_WIN32) || defined(_WIN64) -// #define CORE_INSTALLATION "\\dev\\onyx\\" -// #endif -// #endif - - - - Context context; -static const char* docstring = "Onyx compiler version " VERSION "\n" +static const char* docstring = "Onyx toolchain version " VERSION "\n" "\n" - "The compiler for the Onyx programming language, created by Brendan Hansen.\n" + "The toolchain for the Onyx programming language, created by Brendan Hansen.\n" "\n" "Usage:\n" "\tonyx compile [-o ] [--verbose] \n" - "\tonyx check [--verbose] \n" + "\tonyx check \n" #ifdef ENABLE_RUN_WITH_WASMER "\tonyx run -- \n" #endif + "\tonyx pkg\n" // "\tonyx doc \n" "\tonyx help\n" "\n" - "Flags:\n" + "Compile Flags:\n" "\t List of initial files\n" "\t-o Specify the target file (default: out.wasm).\n" + "\t --output \n" "\t--runtime, -r Specifies the runtime. Can be: onyx, wasi, js, custom.\n" "\t--verbose, -V Verbose output.\n" "\t -VV Very verbose output.\n" @@ -113,7 +104,7 @@ static CompileOptions compile_opts_parse(bh_allocator alloc, int argc, char *arg i32 arg_parse_start = 1; if (!strcmp(argv[1], "help")) options.action = ONYX_COMPILE_ACTION_PRINT_HELP; - if (!strcmp(argv[1], "compile")) { + if (!strcmp(argv[1], "compile") || !strcmp(argv[1], "build")) { options.action = ONYX_COMPILE_ACTION_COMPILE; arg_parse_start = 2; } @@ -121,17 +112,24 @@ static CompileOptions compile_opts_parse(bh_allocator alloc, int argc, char *arg options.action = ONYX_COMPILE_ACTION_CHECK; arg_parse_start = 2; } + if (!strcmp(argv[1], "pkg") || !strcmp(argv[1], "package")) { + options.action = ONYX_COMPILE_ACTION_RUN; + options.passthrough_argument_count = argc - 2; + options.passthrough_argument_data = &argv[2]; + arg_parse_start = argc; + + bh_arr_push(options.files, bh_aprintf(global_heap_allocator, "%s/tools/onyx-pkg.onyx", core_installation)); + } #ifdef ENABLE_RUN_WITH_WASMER else if (!strcmp(argv[1], "run")) { options.action = ONYX_COMPILE_ACTION_RUN; arg_parse_start = 2; } #endif - else options.action = ONYX_COMPILE_ACTION_COMPILE; if (options.action != ONYX_COMPILE_ACTION_PRINT_HELP) { fori(i, arg_parse_start, argc) { - if (!strcmp(argv[i], "-o")) { + if (!strcmp(argv[i], "-o") || !strcmp(argv[i], "--output")) { options.target_file = argv[++i]; } else if (!strcmp(argv[i], "--verbose") || !strcmp(argv[i], "-V")) { diff --git a/compiler/src/parser.c b/compiler/src/parser.c index fb01ac60..dee10bd9 100644 --- a/compiler/src/parser.c +++ b/compiler/src/parser.c @@ -799,7 +799,10 @@ static AstTyped* parse_factor(OnyxParser* parser) { onyx_report_error((parser->curr - 2)->pos, Error_Critical, "#Self is only allowed in an #inject block."); } - retval = parser->injection_point; + AstAlias* alias = make_node(AstAlias, Ast_Kind_Alias); + alias->token = parser->injection_point->token; + alias->alias = parser->injection_point; + retval = (AstTyped *) alias; break; } diff --git a/core/container/result.onyx b/core/container/result.onyx index 0e97d51a..e8f609d2 100644 --- a/core/container/result.onyx +++ b/core/container/result.onyx @@ -159,7 +159,7 @@ Result_Data :: struct (T: type_expr, E: type_expr) { If result contains Err, the given code is run. This code is expected to either: - Return a good value with `return` - - Return an error value with `return #enclosing_scope` + - Return an error value with `return #from_enclosing` This procedure is subject to change. """ diff --git a/scripts/onyx-pkg.onyx b/scripts/onyx-pkg.onyx index a3f2a38a..175c597e 100644 --- a/scripts/onyx-pkg.onyx +++ b/scripts/onyx-pkg.onyx @@ -75,14 +75,14 @@ Command :: struct { #tag Command.{ "help", "Show help.", "", require_config_file=false } run_help_command :: (args: [] cstr) { - printf("onyx-pkg version {}\n", Version); + printf("onyx pkg version {}\n", Version); printf("Package dependency resolver and synchronizer for Onyx.\n\nUsage:\n"); command_procedures := runtime.info.get_procedures_with_tag(Command); defer delete(^command_procedures); for command_procedures { printf("{}\n", it.tag.description); - printf(" onyx-pkg {} {}\n", it.tag.command, it.tag.arguments); + printf(" onyx pkg {} {}\n", it.tag.command, it.tag.arguments); if it.tag.argument_descriptions.count > 0 { lines := string.split(it.tag.argument_descriptions, #char "\n", context.temp_allocator); @@ -460,9 +460,12 @@ run_test_command :: (args: [] cstr) { } } -#tag Command.{ "new", "Create a new project from an installed template." } +#tag Command.{ "new", "Create a new project in the current directory." } run_new_command :: (args: [] cstr) { - + // Create onyx-pkg.ini + // Create onyx-lsp.ini + // Create src/main.onyx + // Create .gitignore } @@ -631,7 +634,7 @@ build_package_file_to_load :: () { io.write(^w, """ // -// THIS FILE WAS AUTOMATICALLY GENERATED BY onyx-pkg. +// THIS FILE WAS AUTOMATICALLY GENERATED BY onyx pkg. // DO NOT MODIFY UNLESS YOU KNOW WHAT YOU ARE DOING. // diff --git a/shared/include/bh.h b/shared/include/bh.h index 70e129e7..bad259a2 100644 --- a/shared/include/bh.h +++ b/shared/include/bh.h @@ -334,6 +334,7 @@ BH_ALLOCATOR_PROC(bh_scratch_allocator_proc); b32 bh_str_starts_with(char* str, char* start); b32 bh_str_ends_with(char* str, char* end); +b32 bh_str_contains(char *str, char *needle); char* bh_strdup(bh_allocator a, char* str); @@ -1481,6 +1482,16 @@ b32 bh_str_ends_with(char* str, char* end) { return *e == *s; } +b32 bh_str_contains(char *str, char *needle) { + while (*str) { + char *walk = needle; + while (*str == *walk && *walk) walk++, str++; + if (*walk) return 1; + } + + return 0; +} + char* bh_strdup(bh_allocator a, char* str) { u32 len = strlen(str); char* buf = bh_alloc(a, len + 1); -- 2.25.1