From: Brendan Hansen Date: Thu, 18 Feb 2021 13:13:21 +0000 (-0600) Subject: small changes in core libraries X-Git-Url: https://git.brendanfh.com/?a=commitdiff_plain;h=6dfab7f7b4cb8b46f3c2d638621a4e3a1a50f503;p=onyx.git small changes in core libraries --- diff --git a/core/array.onyx b/core/array.onyx index edff7a78..f1a52cb1 100644 --- a/core/array.onyx +++ b/core/array.onyx @@ -75,6 +75,18 @@ insert :: (arr: ^[..] $T, idx: u32, x: T) -> bool { return true; } +insert_empty :: (arr: ^[..] $T, idx: u32) -> bool { + if !ensure_capacity(arr, arr.count + 1) do return false; + + arr.count += 1; + while i := arr.count; i > idx { + arr.data[i] = arr.data[i - 1]; + i -= 1; + } + + return true; +} + remove :: (arr: ^[..] $T, elem: T) { move := 0; diff --git a/core/string.onyx b/core/string.onyx index ffbde7f3..d8976b83 100644 --- a/core/string.onyx +++ b/core/string.onyx @@ -23,14 +23,15 @@ length :: proc { }, } -alloc_copy :: (orig: str) -> str { +alloc_copy :: (orig: str, allocator := context.allocator) -> str { new_str : str; - new_str.data = calloc(sizeof u8 * orig.count); + new_str.data = raw_alloc(allocator, sizeof u8 * orig.count); new_str.count = orig.count; copy(orig, new_str); return new_str; } +// @Speed: This should use memory.copy? copy :: (orig: str, dest: str) { len := orig.count; if dest.count < len do len = dest.count; diff --git a/docs/bugs b/docs/bugs index 9bc84678..dff0c9f4 100644 --- a/docs/bugs +++ b/docs/bugs @@ -1 +1,19 @@ -List of known bugs: \ No newline at end of file +List of known bugs: + +[ ] Enum parsing causes segfaults if the syntax is not EXACTLY what is expected. Some cases that break: + enum { Foo, Bar, Baz }; + enum { Foo; Bar; Baz }; + +[ ] Aliasing in many cases does not work. For example: + + arr.data[idx] = x; + SomeNamespace :: struct { + foo :: () { ... } + bar :: ... + } + + { + SN :: SomeNamespace + + SN.foo() + }