From: Brendan Hansen Date: Tue, 7 Mar 2023 23:18:59 +0000 (-0600) Subject: added: syntax highlighting for `dyn_str`; bugfix: array.insert X-Git-Url: https://git.brendanfh.com/?a=commitdiff_plain;h=84402d2a4af4b3711c377990d14f539cc7c3fd33;p=onyx.git added: syntax highlighting for `dyn_str`; bugfix: array.insert --- diff --git a/core/container/array.onyx b/core/container/array.onyx index cfe352e6..340eeae8 100644 --- a/core/container/array.onyx +++ b/core/container/array.onyx @@ -140,7 +140,7 @@ insert :: (arr: &[..] $T, idx: u32, new_arr: [] T) -> bool { arr.count += new_arr.count; while i := arr.count; i > idx { - arr.data[i] = arr.data[i - 1]; + arr.data[i] = arr.data[i - new_arr.count]; i -= 1; } diff --git a/core/string/string.onyx b/core/string/string.onyx index 4295c327..ba6e4c66 100644 --- a/core/string/string.onyx +++ b/core/string/string.onyx @@ -16,7 +16,10 @@ as_str :: macro (t: $T/HasAsStrMethod) -> str { -free :: (s: str, allocator := context.allocator) do raw_free(allocator, s.data); +free :: #match #locked { + (s: str, allocator := context.allocator) { raw_free(allocator, s.data); }, + (s: &dyn_str) { core.array.free(s); }, +} alloc_copy :: (original: str, allocator := context.allocator) -> str { if original.count == 0 do return .{}; diff --git a/misc/onyx-mode.el b/misc/onyx-mode.el index 73edbfd3..5f8e5ab6 100644 --- a/misc/onyx-mode.el +++ b/misc/onyx-mode.el @@ -52,7 +52,7 @@ (defconst onyx-typenames '("u64" "u32" "u16" "u8" "i64" "i32" "i16" "i8" - "f32" "f64" "str" "cstr" "any" "type_expr" + "f32" "f64" "str" "cstr" "dyn_str" "any" "type_expr" "bool" "void" "rawptr" "i8x16" "i16x8" "i32x4" "i64x2" "f32x4" "f64x2" "v128")) diff --git a/misc/onyx.sublime-syntax b/misc/onyx.sublime-syntax index ccce2161..1bbf0fea 100644 --- a/misc/onyx.sublime-syntax +++ b/misc/onyx.sublime-syntax @@ -32,7 +32,7 @@ contexts: - match: '\b(package|struct|interface|use|where|global|enum|if|elseif|else|for|while|do|break|continue|fallthrough|return|cast|sizeof|alignof|typeof|defer|switch|case|macro)\b' scope: keyword.control.onyx - - match: '\b(bool|void|i8|u8|i16|u16|i32|u32|i64|u64|f32|f64|rawptr|str|cstr|range|type_expr|any)\b' + - match: '\b(bool|void|i8|u8|i16|u16|i32|u32|i64|u64|f32|f64|rawptr|str|cstr|dyn_str|range|type_expr|any)\b' scope: storage.type - match: '\b(i8x16|i16x8|i32x4|i64x2|f32x4|f64x2|v128)\b' diff --git a/misc/onyx.vim b/misc/onyx.vim index 4d90cba9..53eccd91 100644 --- a/misc/onyx.vim +++ b/misc/onyx.vim @@ -23,7 +23,7 @@ syn keyword onyxType i32 u32 syn keyword onyxType i64 u64 syn keyword onyxType f32 f64 syn keyword onyxType rawptr -syn keyword onyxType str cstr +syn keyword onyxType str cstr dyn_str syn keyword onyxType i8x16 i16x8 i32x4 i64x2 f32x4 f64x2 v128 syn keyword onyxType type_expr any diff --git a/misc/vscode/onyx-0.1.5.vsix b/misc/vscode/onyx-0.1.5.vsix index ddeb2156..82722466 100644 Binary files a/misc/vscode/onyx-0.1.5.vsix and b/misc/vscode/onyx-0.1.5.vsix differ diff --git a/misc/vscode/syntaxes/onyx.tmLanguage b/misc/vscode/syntaxes/onyx.tmLanguage index 43605084..aa669a9b 100644 --- a/misc/vscode/syntaxes/onyx.tmLanguage +++ b/misc/vscode/syntaxes/onyx.tmLanguage @@ -271,7 +271,7 @@ match - \b(str|cstr|type_expr|any)\b + \b(str|cstr|dyn_str|type_expr|any)\b name storage.type.onyx diff --git a/tests/bugs/print_formatters b/tests/bugs/print_formatters new file mode 100644 index 00000000..5867894e --- /dev/null +++ b/tests/bugs/print_formatters @@ -0,0 +1,5 @@ +{ +Hello{}World +Hello{}World +}{hello}{ +}3R{ diff --git a/tests/bugs/print_formatters.onyx b/tests/bugs/print_formatters.onyx new file mode 100644 index 00000000..ccd5ecf6 --- /dev/null +++ b/tests/bugs/print_formatters.onyx @@ -0,0 +1,10 @@ +use core + +main :: () { + printf("{\n"); + printf("Hello{"); + printf("}World\n"); + printf("Hello{{}}World\n"); + printf("}{hello}{\n", 123); + printf("}{b32}{\n", 123); +} \ No newline at end of file diff --git a/tests/dyn_str b/tests/dyn_str new file mode 100644 index 00000000..e69de29b diff --git a/tests/dyn_str.onyx b/tests/dyn_str.onyx new file mode 100644 index 00000000..1918c79b --- /dev/null +++ b/tests/dyn_str.onyx @@ -0,0 +1,15 @@ +use core + + +main :: () { + output: dyn_str; + defer string.free(&output); + + string.append(&output, "Hello"); + string.append(&output, "World"); + string.append(&output, "!"); + + string.insert(&output, 5, ", "); + + println(output); +} \ No newline at end of file