From 8251248edbb8048e2bfb4ce92ea96a30baa7baa9 Mon Sep 17 00:00:00 2001 From: Brendan Hansen Date: Mon, 27 Nov 2023 10:44:52 -0600 Subject: [PATCH] added: string literals to `cstr`s; miscellaneous bugfixes --- compiler/src/astnodes.c | 14 ++++++++++++++ core/encoding/json/decoder.onyx | 2 +- scripts/onyx-pkg.onyx | 5 ++++- 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/compiler/src/astnodes.c b/compiler/src/astnodes.c index d0102cb5..0f96e128 100644 --- a/compiler/src/astnodes.c +++ b/compiler/src/astnodes.c @@ -744,6 +744,20 @@ TypeMatch unify_node_and_type_(AstTyped** pnode, Type* type, b32 permanent) { return TYPE_MATCH_SUCCESS; } } + + // String literals implicitly become c-strings for convience. + if (node->kind == Ast_Kind_StrLit + && type->kind == Type_Kind_MultiPointer + && type->MultiPointer.elem == &basic_types[Basic_Kind_U8]) { + + if (permanent) { + AstStrLit *strlit = (AstStrLit *) node; + strlit->is_cstr = 1; + strlit->type = type; + } + + return TYPE_MATCH_SUCCESS; + } // If the destination type is a slice, then automatically convert arrays, dynamic // arrays, and var args, if they are the same type. This is big convenience feature diff --git a/core/encoding/json/decoder.onyx b/core/encoding/json/decoder.onyx index 9937db7f..fd2f7b27 100644 --- a/core/encoding/json/decoder.onyx +++ b/core/encoding/json/decoder.onyx @@ -100,5 +100,5 @@ decode_into :: (data: str, out: &$T) -> Error { defer delete(obj); as_any(obj.root, out); - return .None; + return .{ .None }; } diff --git a/scripts/onyx-pkg.onyx b/scripts/onyx-pkg.onyx index 398ed6cf..c974b1a0 100644 --- a/scripts/onyx-pkg.onyx +++ b/scripts/onyx-pkg.onyx @@ -374,6 +374,9 @@ run_rebuild_command :: (args: [] cstr) { } dep := string.as_str(args[0]); + if config.dependencies->has(dep) { + dep = config.dependencies->get(dep)->unwrap().source.Git->unwrap(); + } info_print("Rebuild", "{}\n", dep); if success, err := rebuild_native_library(dep); success { @@ -392,7 +395,7 @@ run_publish_command :: (args: [] cstr) { if !os.dir_exists(".git") { error_print("Not in Git repository.\n"); printf("It does not look like you are in a Git repository. In order to publish packages\n"); - printf("with onyx-pkg, you have to initailize a Git repository in the current directory.\n\n"); + printf("with onyx-pkg, you have to initialize a Git repository in the current directory.\n\n"); return; } -- 2.25.1