breaking: moved `onyx-pkg` to `onyx pkg`
authorBrendan Hansen <brendan.f.hansen@gmail.com>
Tue, 28 Feb 2023 18:46:23 +0000 (12:46 -0600)
committerBrendan Hansen <brendan.f.hansen@gmail.com>
Tue, 28 Feb 2023 18:46:23 +0000 (12:46 -0600)
`onyx-pkg` command is now gone. All functionality moved into `onyx pkg` command.

bin/onyx-pkg [deleted file]
build.sh
compiler/src/onyx.c
compiler/src/parser.c
core/container/result.onyx
scripts/onyx-pkg.onyx
shared/include/bh.h

diff --git a/bin/onyx-pkg b/bin/onyx-pkg
deleted file mode 100755 (executable)
index e219bd2..0000000
+++ /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
index 04e95866fbeb39fc3bb194a654c703895ad7f7d6..59e9e1396acd0217ac8923955cbe1b7ca837d1b5 100755 (executable)
--- 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"
 
index b6b53252cff58eab7279e8dda5403dda84e3c63d..caab41f69d406c72100749023f23d6e0a3074174 100644 (file)
 #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 <target file>] [--verbose] <input files>\n"
-    "\tonyx check [--verbose] <input files>\n"
+    "\tonyx check <input files>\n"
 #ifdef ENABLE_RUN_WITH_WASMER
     "\tonyx run <input files> -- <args>\n"
 #endif
+    "\tonyx pkg\n"
     // "\tonyx doc <input files>\n"
     "\tonyx help\n"
     "\n"
-    "Flags:\n"
+    "Compile Flags:\n"
     "\t<input files>           List of initial files\n"
     "\t-o <target_file>        Specify the target file (default: out.wasm).\n"
+    "\t   --output <target_file>\n"
     "\t--runtime, -r <runtime> 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")) {
index fb01ac60047b458a2f85fab0b88e9620ba6cbb09..dee10bd9427294ceb5f8ac9c28fb64c47776f1c1 100644 (file)
@@ -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;
             }
 
index 0e97d51a1f47cd58617090991ddd16e2727618c1..e8f609d227c2d332626ff5044f10efafacc9a2e8 100644 (file)
@@ -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.
     """
index a3f2a38ad5893bc488277ec4d18912e88f085661..175c597e28c5c10534be064a36640c5ca238a553 100644 (file)
@@ -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.
 //
 
index 70e129e73ab926b1e3c81d5a07625305c8adf93d..bad259a275c72a74445ef0f98cc0f7be451c231d 100644 (file)
@@ -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);