small changes in core libraries
authorBrendan Hansen <brendan.f.hansen@gmail.com>
Thu, 18 Feb 2021 13:13:21 +0000 (07:13 -0600)
committerBrendan Hansen <brendan.f.hansen@gmail.com>
Thu, 18 Feb 2021 13:13:21 +0000 (07:13 -0600)
core/array.onyx
core/string.onyx
docs/bugs

index edff7a78622ac68ef768487d5ee0a3c49e004840..f1a52cb162a7ecf6bc0e94851e20466eb72a3bef 100644 (file)
@@ -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;
 
index ffbde7f3bf8a4a1665b7e8a643884eeb8f356c5d..d8976b83a8bbc515924f789d19354f9c143682a8 100644 (file)
@@ -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;
index 9bc84678b94c7d2ac180d8b3c5adac9d7b729a2a..dff0c9f4e6e59a95ab77d2bf705f9a2bf0092902 100644 (file)
--- 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()
+    }