cleaning up old test files; will add more examples soon
authorBrendan Hansen <brendan.f.hansen@gmail.com>
Tue, 18 Aug 2020 20:59:06 +0000 (15:59 -0500)
committerBrendan Hansen <brendan.f.hansen@gmail.com>
Tue, 18 Aug 2020 20:59:06 +0000 (15:59 -0500)
21 files changed:
Makefile
core/alloc.onyx
core/core.onyx [new file with mode: 0644]
core/random.onyx [new file with mode: 0644]
core/string.onyx
docs/plan
onyx
progs/alloc_test.onyx [deleted file]
progs/arrays.onyx [deleted file]
progs/basic.onyx [deleted file]
progs/ez.onyx [deleted file]
progs/fcf.onyx [deleted file]
progs/filetest [deleted file]
progs/heap_resize_test.onyx [deleted file]
progs/stack_based.onyx
progs/structs.onyx [deleted file]
progs/ufc.onyx [deleted file]
src/onyxmsgs.c
src/onyxsymres.c
src/onyxtypes.c
src/onyxutils.c

index f88f1fecc91a608f684d4ad1d541b6deb226b89c..bf49f2a03cc027e8f5141d9eb0d79cc12d682958 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -1,4 +1,4 @@
-RELEASE=0
+RELEASE=1
 
 OBJ_FILES=\
        build/onyxlex.o \
@@ -30,8 +30,9 @@ build/%.o: src/%.c include/bh.h
 $(TARGET): $(OBJ_FILES)
        $(CC) $(FLAGS) $(OBJ_FILES) -o $@ $(LIBS)
 
-install: $(TARGET)
+install: $(TARGET) core/*
        cp $(TARGET) /usr/bin/
+       cp -r core/ /usr/share/onyx
 
 install_syntax: misc/onyx.vim misc/onyx.sublime-syntax
        cp ./misc/onyx.vim /usr/share/vim/vim82/syntax/onyx.vim
index 377b758960dd0ac6aa8fc4c2a2dbf0e9cb22af70..f1ae45093e34364e485a1caad667e702d18a1b11 100644 (file)
@@ -19,7 +19,7 @@ alloc_proc :: #type proc (rawptr, AllocAction, u32, u32, rawptr) -> rawptr;
 
 Allocator :: struct {
     data: rawptr;
-    func: alloc_proc; 
+    func: alloc_proc;
 }
 
 alloc :: proc (use a: Allocator, size: u32) -> rawptr {
@@ -100,7 +100,7 @@ heap_alloc :: proc (size_: u32, align: u32) -> rawptr {
 
     new_pages :: ((size - heap_state.remaining_space) >> 16) + 1;
     if memory_grow(new_pages) == -1 {
-        // out of memory    
+        // out of memory
         return null;
     }
     heap_state.remaining_space += new_pages << 16;
@@ -208,4 +208,4 @@ scratch_alloc_init :: proc (a: ^Allocator, ss: ^ScratchState) {
 
 memory_init :: proc {
     heap_init();
-}
\ No newline at end of file
+}
diff --git a/core/core.onyx b/core/core.onyx
new file mode 100644 (file)
index 0000000..4534607
--- /dev/null
@@ -0,0 +1,8 @@
+package core
+
+#include_file "alloc"
+#include_file "intrinsics"
+#include_file "memory"
+#include_file "printing"
+#include_file "random"
+#include_file "string"
diff --git a/core/random.onyx b/core/random.onyx
new file mode 100644 (file)
index 0000000..d23b7f8
--- /dev/null
@@ -0,0 +1,12 @@
+package random
+
+#private
+seed := 8675309
+
+random_seed :: proc (s: u32) do seed = s;
+random :: proc -> u32 {
+       seed = seed * 5831 + 102847;
+       return seed;
+}
+
+random_between :: proc (lo: i32, hi: i32) -> i32 do return random() % (hi + 1 - lo) + lo;
\ No newline at end of file
index 6c472832e13529d502bb6b984216553508af6b51..8beabf83d703bc8882bfac7d332f282c9c99f346 100644 (file)
@@ -3,8 +3,8 @@ package core
 use package memory
 
 Buffer :: struct {
-    length : u32    = 0;
     data   : rawptr = null;
+    length : u32    = 0;
 }
 
 string :: struct {
index 947e130dc64dd3ff86f48070b8b3ee22c9c3a18b..50f6ee14e5c0f00dd4916fec27769727d2df21f0 100644 (file)
--- a/docs/plan
+++ b/docs/plan
@@ -186,7 +186,7 @@ HOW:
 
         [X] returning structs
             - This will put forward a lot of the work that will be done for multiple return values
-            
+
         [ ] Add slices
             - Arrays without a size
             - Converted to a struct that looks like:    
@@ -213,8 +213,13 @@ HOW:
 
         [ ] All code paths return correct value
 
-        [ ] Type parameterized structs
+        [ ] Put type info in data section so it is runtime accessible
+            - size
+            - alignment
+            - struct member names
+            - array length
 
+        [ ] Type parameterized structs
 
         [ ] Arrays need to be much better
             - Currently, they are basically just a pointer.
diff --git a/onyx b/onyx
index 090504e34b29eac8e502a1f982c8ed4a851a9c6f..9af74f0d190be2d06bf4524e5cb926acb4f9f9dc 100755 (executable)
Binary files a/onyx and b/onyx differ
diff --git a/progs/alloc_test.onyx b/progs/alloc_test.onyx
deleted file mode 100644 (file)
index 6126ea9..0000000
+++ /dev/null
@@ -1,56 +0,0 @@
-#include_file "alloc"
-#include_file "printing"
-
-use package memory
-use package printing
-
-deferred_example :: proc -> i32 {
-    arr := cast(^i64) malloc(sizeof [8] i64);
-    if cast(rawptr) arr == null do return 0;
-    defer mfree(arr);
-
-    for i: 0, 8 do arr[i] = cast(i64) (i * i);
-
-    walker := arr;
-    for _: 0, 8 {
-        print_u64(*walker);
-        walker += 1;
-    }
-
-    return cast(i32) (arr[1] + arr[7]);
-}
-
-proc #export "start" {
-    print(#file_contents "progs/filetest");
-    heap_init();
-
-    print(deferred_example());
-
-    first: [4] i32;
-    for i: 0, 4 do first[i] = i * 2;
-
-    second := cast(^f32) malloc(sizeof [24] f32);
-    for i: 0, 24 do second[i] = cast(f32) i;
-
-    print(cast(u32) first);
-    print(cast(u32) second);
-
-    for i: 0, 4  do print(first[i]);
-    for i: 0, 24 do print(second[i]);
-
-    mfree(first);
-
-    third := cast(^i32) malloc(sizeof i32);
-
-    print(cast(u32) third);
-    *third = 1234;
-    print(*third);
-
-    mfree(second);
-
-    fourth := cast(^i32) malloc(sizeof [128]i32);
-    print(cast(u32) fourth);
-
-    fifth := cast(^i32) malloc(sizeof i32);
-    print(cast(u32) fifth);
-}
\ No newline at end of file
diff --git a/progs/arrays.onyx b/progs/arrays.onyx
deleted file mode 100644 (file)
index 7dff60d..0000000
+++ /dev/null
@@ -1,110 +0,0 @@
-use "progs/intrinsics"
-use "progs/print_funcs"
-
-use package printing
-
-global_arr :: global []i32;
-
-min_i32 :: proc (a: i32, b: i32) -> i32 {
-    least := a;
-    if b < a least = b;
-    return least;
-}
-
-min_i64 :: proc (a: i64, b: i64) -> i64 {
-    least := a;
-    if b < a least = b;
-    return least;
-}
-
-min :: proc #overloaded {
-    min_i32, min_i64, min_f32, min_f64
-}
-
-// NOTE: in-place insertion sort
-sort :: proc (src: []i32, len: i32, cmp: proc (i32, i32) -> i32) {
-    for i: 0, len {
-        smallest := i;
-
-        for j: i + 1, len
-            if cmp(src[j], src[smallest]) < 0 smallest = j;
-
-        tmp :: src[smallest];
-        src[smallest] = src[i];
-        src[i] = tmp;
-    }
-}
-
-for_test :: proc {
-    // 0 to 9
-    for i: 0, 10 print(i);
-}
-
-str_test :: proc #export {
-    hello_str :: "Hello World! 123";
-
-    // Address of and dereference cancel each other out
-    print(^*hello_str);
-
-    print(cast([] u8) hello_str, 5);
-
-    for i: 0, 10, 2 print(i);
-
-    for y: 0, 5 for x: 0, 5 print(x + y * 5);
-}
-
-abs_i32 :: proc (n: i32) -> i32 {
-    if n < 0 return -n;
-    return n;
-}
-
-// Don't need to bind this function to a symbol
-proc #export "main" {
-    len :: 10;
-    global_arr = cast([] i32) alloc(sizeof [10]i32);
-
-    for i: 0, len global_arr[i] = (len - i) * 10;
-
-    print(global_arr, len);
-
-    sort(global_arr, len, proc (a: i32, b: i32) -> i32 {
-        return abs_i32(a - 50) - abs_i32(b - 50);
-    });
-
-    print(1234567);
-    print(global_arr, len);
-}
-
-
-
-
-
-
-
-
-
-
-
-alloc :: proc (size: u32) -> rawptr {
-    heap_u32    :: cast(^i32) __heap_start;
-
-    curr_offset := *heap_u32;
-    if curr_offset == 0 curr_offset = 8;
-
-    *heap_u32   = curr_offset + size;
-
-    return cast(rawptr) (cast(u32) __heap_start  + curr_offset);
-}
-
-alloc_2darr :: proc (rows: u32, cols: u32) -> []^i32 {
-    arr := cast([] ^i32) alloc(rows * 4);
-    for i: 0, cols arr[i] = cast(^i32) alloc(cols * 4);
-    return arr;
-}
-
-multi_arr_test :: proc #export "main2" {
-    arrs := alloc_2darr(10, 10);
-
-    for y: 0, 10 for x: 0, 10 arrs[y][x] = x + y * 10;
-    for y: 0, 10 for x: 0, 10 print(arrs[x][y]);
-}
diff --git a/progs/basic.onyx b/progs/basic.onyx
deleted file mode 100644 (file)
index 31dcbc3..0000000
+++ /dev/null
@@ -1,69 +0,0 @@
-pointer_test :: proc {
-    p := 0 as ^i32;
-}
-
-print :: proc
-    #foreign "host" "print"
-    (val: i32) ---
-
-printf :: proc
-    #foreign "host" "print"
-    (val: f32) ---
-
-test :: proc (a: bool) -> bool {
-    return !a;
-}
-
-foo :: proc (n: i32) -> i32 {
-    a :: shl_i32(n, 1);
-    b :: shl_i32(n, 2);
-    return or_i32(a, b);
-}
-
-// THOUGHT: This could be a WASM global that is immutable and it
-// would be accessed using global.get
-// OR
-// This could be immediately substituted in the expression tree. i.e.
-//      4 + global       =>       4 + (5 * 2 + 6)
-global_value :: 5 * 2 + 6
-
-// WASM globals would be declared as such:
-wasm_global :: global i32
-
-main :: proc #export {
-    a : i32 = 16;
-    print(clz_i32(a));
-
-    wasm_global = 5 + global_value;
-    print(wasm_global);
-
-    print(4 + global_value);
-
-    b := 1 + foo(2);
-    if b == 13 b += 10;
-    print(b);
-
-    if b == 13 print(5678);
-    else       print(1024);
-
-    if b == 13 ---
-
-    while true {
-        while true {
-            while true {
-                foo := 20;
-                foo = global_value + 10;
-                print(foo);
-                break;
-            }
-            break;
-        }
-        break;
-    }
-
-    cond :: true;
-    print(cast(i32) test(cond));
-}
-
-use "progs/intrinsics"
-
diff --git a/progs/ez.onyx b/progs/ez.onyx
deleted file mode 100644 (file)
index 8f80c7e..0000000
+++ /dev/null
@@ -1,77 +0,0 @@
-use "progs/print_funcs"
-use "progs/intrinsics"
-
-use package printing {
-    print, PrintableArray,
-    print_f32 as pf32
-}
-
-Foo :: struct {
-    x : i32;
-    y : i32;
-
-    st : SomeType;
-}
-
-foo_sum :: proc (use this: ^Foo) -> i32 {
-    foo_other(this);
-    return x + y;
-}
-
-foo_other :: proc (use this: ^Foo) {
-    print(cast(i32) st);
-}
-
-asdf :: proc (pa: PrintableArray) {
-    for i: 0, pa.len print(cast(i32) pa.data[i]);
-}
-
-SomeType :: enum {
-    Value1;
-    Value2;
-    Value3;
-    Value4;
-}
-
-print_st :: proc (st: SomeType, other: i32) {
-    print(cast(i32) st);
-}
-
-single_int : u32
-
-N :: 1024
-array : [N] Foo
-
-proc #export "main" {
-    print("Hello World! this is slightly longer\n");
-
-    print(cast(i32) __heap_start);
-
-    single_int = 10;
-    print(single_int);
-
-    array[4].y = 1234;
-    print(array[4].y);
-
-    st: SomeType = SomeType.Value4;
-    print_st(st, 10);
-
-    foo := cast(^Foo) __heap_start;
-    foo.x = 123;
-    foo.y = 321;
-    foo.st = st;
-    print(alignof Foo);
-    print(sizeof Foo);
-    print(foo_sum(foo));
-    print_st(foo.st, 20);
-
-    pa := cast(^PrintableArray) (cast(i32) __heap_start + sizeof Foo);
-    pa.data = cast(^u8) __heap_start;
-    pa.len = 5;
-    asdf(*pa);
-
-    print(1234);
-
-    pf32(sqrt_f32(123.0f));
-}
-
diff --git a/progs/fcf.onyx b/progs/fcf.onyx
deleted file mode 100644 (file)
index 12500c0..0000000
+++ /dev/null
@@ -1,112 +0,0 @@
-#include_folder "./core"
-
-#include_file "printing"
-#include_file "intrinsics"
-
-use package printing
-
-call_me :: proc (f: proc (i32) -> i32, val: i32) {
-    f(val);
-}
-
-funcs : [5] proc (i32, i32) -> i32
-
-add :: proc (a: i32, b: i32) -> i32 { return a + b; }
-sub :: proc (a: i32, b: i32) -> i32 { return a - b; }
-mul :: proc (a: i32, b: i32) -> i32 { return a * b; }
-div :: proc (a: i32, b: i32) -> i32 { return a / b; }
-mod :: proc (a: i32, b: i32) -> i32 { return a % b; }
-
-deferred_proc :: #type proc (i32, i32) -> i32
-my_int :: #type i32;
-
-DeferredCall :: struct {
-    func  : deferred_proc;
-    left  : i32;
-    right : i32;
-}
-
-execute :: proc (use dc: ^DeferredCall) -> i32 {
-    return func(left, right);
-}
-
-echo :: proc (i: i32) -> i32 {
-    print(i);
-    return i;
-}
-
-I32Array :: struct {
-    length : i32;
-    data   : ^i32;
-}
-
-array_map :: proc (arr: I32Array, map: proc (i32) -> i32) {
-    for i: 0, arr.length do arr.data[i] = map(arr.data[i]);
-}
-
-minus_one :: proc (n: i32) -> i32 { return n - 1; }
-double    :: proc (n: i32) -> i32 { return n << 1; }
-
-proc #export "start" {
-    call_me(echo, 10);
-
-    print(cast(my_int) add);
-
-    funcs[0] = add;
-    funcs[1] = sub;
-    funcs[2] = mul;
-    funcs[3] = div;
-    funcs[4] = mod;
-
-    for i: 0, 5 do print(funcs[i](10, 3));
-
-    dc := cast(^DeferredCall) __heap_start;
-    dc.func = add;
-    dc.left = 40;
-    dc.right = 19;
-
-    print(execute(dc));
-
-    len :: 10;
-    data := cast(^i32) (cast(i32) __heap_start + sizeof DeferredCall);
-    for i: 0, len do data[i] = i;
-    print(cast([] i32) data, len);
-
-    add_one :: proc (n: i32) -> i32 { return n + 1; };
-
-    arr : I32Array;
-    arr.length = len;
-    arr.data = data;
-    array_map(arr, add_one);
-    print(cast([] i32) data, len);
-
-    cheese := Cheeses.Cheddar;
-
-    // Closest thing to a switch statement at the moment
-    {
-        if cheese == Cheeses.Cheddar {
-            print(1);
-            break;
-        }
-
-        print(2);
-
-        if cheese == Cheeses.Muenster {
-            print(10);
-            break;
-        }
-
-        print(2);
-
-        if cheese == Cheeses.Mozerella {
-            print(100);
-            break;
-        }
-    }
-}
-
-Cheeses :: enum {
-    Cheddar;
-    Muenster;
-    Mozerella;
-}
diff --git a/progs/filetest b/progs/filetest
deleted file mode 100644 (file)
index b2bc325..0000000
+++ /dev/null
@@ -1 +0,0 @@
-This is a test from a file!
\ No newline at end of file
diff --git a/progs/heap_resize_test.onyx b/progs/heap_resize_test.onyx
deleted file mode 100644 (file)
index 94af0da..0000000
+++ /dev/null
@@ -1,99 +0,0 @@
-#include_folder "./core"
-
-#include_file "printing"
-#include_file "alloc"
-
-use package memory
-use package printing
-
-Vec2 :: struct {
-    x : i32;
-    y : i32; 
-}
-
-other :: proc (use v: ^Vec2) -> i32 {
-    o : Vec2;
-    o.x = -100;
-    o.y = -10;
-
-    return x * o.x + y * o.y;
-}
-
-proc #export "start" {
-    heap_init();
-
-    v : Vec2;
-    v.x = 10;
-    v.y = 100;
-
-    if false {
-        v : Vec2;
-        v2 : Vec2;
-
-        x := 1;
-        y := 1.0f;
-        z := 1.0;
-        w := 1.0f;
-    }
-    if false {
-        v : Vec2;
-
-        x := 1;
-        y := 1.0f;
-        z := 1.0;
-    }
-    if false {
-        v : Vec2;
-
-        x := 1;
-        y := 1.0f;
-        z := 1.0;
-    }
-    if false {
-        v : Vec2;
-
-        x := 1;
-        y := 1.0f;
-        z := 1.0;
-    }
-
-    other(^v) |> print();
-}
-
-// proc #export "start2" {
-//     heap_init();
-// 
-//     print("Creating initial memories");
-//     arr1 := cast(^u32) malloc(sizeof [10] u32);
-//     print_hex(cast(u64) arr1);
-// 
-//     arr2 := cast(^u32) malloc(sizeof [40] u32);
-//     print_hex(cast(u64) arr2);
-// 
-//     print("Freeing arr1");
-//     mfree(arr1);
-// 
-//     print("Resizing arr2 (shouldn't change location)");
-//     arr2 = cast(^u32) mresize(arr2, sizeof [60] u32);
-//     print_hex(cast(u64) arr2);
-// 
-//     print("Allocating arr3 (should be bigger than arr2)");
-//     arr3 := cast(^u32) malloc(sizeof [30] u32);
-//     print_hex(cast(u64) arr3);
-// 
-//     print("Allocating arr1 (should be in the same place as before)");
-//     arr1 = cast(^u32) malloc(sizeof [5] u32);
-//     print_hex(cast(u64) arr1);
-//     for i: 0, 5 do arr1[i] = i;
-// 
-//     print("Resizing arr1 (should be in the same place as before)");
-//     arr1 = cast(^u32) mresize(arr1, sizeof[10] u32);
-//     print_hex(cast(u64) arr1);
-// 
-//     print("Resizing arr1 (should have moved to after arr3)");
-//     arr1 = cast(^u32) mresize(arr1, sizeof[100] u32);
-//     print_hex(cast(u64) arr1);
-// 
-//     print("Testing if the data was copied.");
-//     for i: 0, 5 do print(arr1[i]);
-// }// 
\ No newline at end of file
index 44889389b9c176b464b15557dc746ee4e17091ec..809e0af5d41143f1e1a57d8bfdba9b870caa1490 100644 (file)
@@ -1,6 +1,6 @@
 package main
 
-#include_folder "./core"
+#include_folder "/usr/share/onyx/core"
 
 #include_file "printing"
 #include_file "alloc"
@@ -109,7 +109,7 @@ start :: proc #export {
 
     print(10 |> ret_val(4));
     print(11 |> ret_val(5));
-    
+
     for i: 0, N do print(arr[1][i]);
 
     soa: struct { x: [5] i32; y: [5] i32; };
@@ -149,7 +149,7 @@ start :: proc #export {
 
     v1 := Vec3.{};
     v2 := vmul(vadd(v1, Vec3.{ 1, 2, 3 }), 3);
-  
+
     print(v2.x);
     print(v2.y);
     print(v2.z);
@@ -180,4 +180,4 @@ vmul :: proc (use v: Vec3, s: i32) -> Vec3 {
 UnionTest :: struct #union {
     i : i32;
     f : f32;
-}
\ No newline at end of file
+}
diff --git a/progs/structs.onyx b/progs/structs.onyx
deleted file mode 100644 (file)
index e1c16c7..0000000
+++ /dev/null
@@ -1,220 +0,0 @@
-use "progs/print_funcs"
-use "progs/intrinsics"
-
-use package printing
-
-N :: 5
-
-Foo :: struct {
-    v   : Vec3;
-    i   : i32;
-    l   : i64;
-    f   : f32;
-    d   : f64;
-    foo : ^Foo;
-}
-
-alloc :: proc (size: u32) -> rawptr {
-    heap_u32    :: cast(^u32) __heap_start;
-
-    curr_offset := *heap_u32;
-    if curr_offset == 0 curr_offset = 8;
-
-    *heap_u32   = curr_offset + size;
-
-    return cast(rawptr) (cast(u32) __heap_start + curr_offset);
-}
-
-foo_make :: proc -> ^Foo {
-    return cast(^Foo) alloc(sizeof Foo);
-}
-
-foo_get :: proc (fooarr: []Foo, i: i32) -> ^Foo {
-    return ^fooarr[i];
-}
-
-Mut1 :: struct {
-    bar : i32;
-    other : Mut2;
-}
-
-Mut2 :: struct {
-    foo : i32;
-    other : ^Mut1;
-}
-
-mut_func :: proc #export (mut: ^Mut1) -> ^Mut1 {
-    return mut.other.other;
-}
-
-
-Link :: struct {
-    data : i32;
-    next : ^Link;
-}
-
-link_create :: proc (data: i32, parent: ^^Link) {
-    link := cast(^Link) alloc(sizeof Link);
-    link.data = data;
-    link.next = *parent;
-    *parent = link;
-}
-
-link_print :: proc (start: ^Link) -> i32 {
-    count := 0;
-
-    walker := start;
-    while cast(i32) walker != 0 {
-        print(walker.data);
-        walker = walker.next;
-        count += 1;
-    }
-
-    return count;
-}
-
-link_test :: proc #export "main4" {
-    node_head := cast(^^Link) alloc(sizeof ^Link);
-    *node_head = cast(^Link) 0;
-
-    link_create(0, node_head);
-    link_create(1, node_head);
-    link_create(2, node_head);
-    link_create(3, node_head);
-    link_create(4, node_head);
-
-    link_print(*node_head);
-}
-
-
-
-// TODO: Make everything below this comment work
-multi_arr :: proc #export "main2" {
-    arr1 := cast([5][5] i32) alloc(sizeof [5][5] i32); // Sizeof 25 * 4
-    arr2 := cast([5] ^i32) alloc(sizeof [5]^ i32); // Sizeof 20
-
-    arr2[3][2] = 5; // (arr1 + (3 * 5 * 4) + (2 * 4))
-    print(arr2[3][2]);
-    // arr2[3][2] = 5; // (arr1[3] + 2 * 4)
-}
-                
-Vec2 :: struct {
-    x : i32;
-    y : i32;
-}
-
-Vec3 :: struct {
-    x : i32;
-    y : i32;
-    z : i32;
-}
-
-v2magnitude :: proc (v: ^Vec2) -> f32 {
-    return sqrt_f32(cast(f32) (v.x * v.x + v.y * v.y));
-}
-
-v3magnitude :: proc (v: ^Vec3) -> f32 {
-    return sqrt_f32(cast(f32) (v.x * v.x + v.y * v.y + v.z * v.z));
-}
-
-magnitude :: proc #overloaded { v2magnitude, v3magnitude };
-
-minus :: proc (n: i32, k: i32) -> i32 {
-    return n - k;
-}
-
-Fool :: struct {
-    bar : ^Bar;
-}
-
-Bar :: struct {
-    i: i32;
-    j: i64;
-}
-
-print_bar :: proc (bar: Bar) {
-    print(bar.i);
-    print(bar.j);
-}
-
-proc #export "main" {
-    v2 := cast(^Vec2) alloc(sizeof Vec2);
-    v2.x = 5;
-    v2.y = 12;
-    print(v2.magnitude());
-
-    v3 := cast(^Vec3) alloc(sizeof Vec3);
-    v3.x = 1;
-    v3.y = 1;
-    v3.z = 1;
-    print(v3.magnitude());
-
-    (*v2).vec2_splat(*v3);
-
-    print((1).minus(2));
-
-    foo := cast(^Fool) alloc(sizeof Fool);
-    foo.bar = cast(^Bar) alloc(sizeof Bar);
-    foo.bar.i = 50;
-    foo.bar.j = cast(i64) 70;
-
-    (*foo.bar).print_bar();
-}
-
-SOA :: struct {
-    positions  : [10] Vec2;
-    velocities : [10] Vec2;
-    things     : [10] ^Vec2;
-}
-
-vec2_set :: proc (v: ^Vec2) {
-    v.x = 1234;
-    v.y = 5678;
-}
-
-vec2_splat :: proc (v: Vec2, other: Vec3) {
-    print(other.x);
-    print(other.y);
-    print(other.z);
-
-    print(v.x);
-    print(v.y);
-}
-
-soa_test :: proc #export "main9" {
-
-    // print(sizeof SOA);  // 240
-
-    soa := cast(^SOA) alloc(sizeof SOA + 20 * sizeof Vec2);
-
-    for i: 0, 10 {
-        soa.things[i] = cast(^Vec2) alloc(sizeof Vec2);
-    }
-
-    soa.velocities[2].x = 10;
-    soa.velocities[2].y = 12;
-    soa.positions[5].x = 1;
-    soa.positions[5].y = 2;
-    soa.positions[2].x = 1001;
-    (^(soa.positions[6])).vec2_set();
-    vec2_set(soa.things[2]);
-
-    print((^(soa.positions[6])).v2magnitude());
-
-    print(soa.positions[5].y);
-    print(soa.velocities[2].x);
-    print(soa.things[2].x);
-    print(soa.things[2].y);
-    print(soa.positions[6].x);
-    print(soa.positions[6].y);
-
-    m_arr := cast([5][5] i32) alloc(sizeof [5][5]i32);
-
-    for y: 0, 5 {
-        for x: 0, 5 {
-            m_arr[y][x] = x + y * 5;
-        }
-    }
-
-    for i: 0, 25 print((cast([] i32) m_arr)[i]);
-}
\ No newline at end of file
diff --git a/progs/ufc.onyx b/progs/ufc.onyx
deleted file mode 100644 (file)
index 7d352ac..0000000
+++ /dev/null
@@ -1,103 +0,0 @@
-// EVERYTHING IN THIS FILE IS VERY BROKEN SINCE UFC HAS BEEN
-// DISABLED.
-
-use "progs/intrinsics"
-use "progs/print_funcs"
-
-use package printing as printing
-
-alloc :: proc (size: u32) -> rawptr {
-    heap_u32    :: cast(^u32) __heap_start;
-
-    curr_offset := *heap_u32;
-    if curr_offset == 0 curr_offset = 8;
-
-    *heap_u32   = curr_offset + size;
-
-    return cast(rawptr) (cast(u32) __heap_start + curr_offset);
-}
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-Vec2 :: struct {
-       x : f32;
-       y : f32;
-}
-
-vec2_magnitude :: proc (use v: ^Vec2) -> i32 {
-       return cast(i32) sqrt_f32(x * x + y * y);
-}
-
-Vec3 :: struct {
-       x : f32;
-       y : f32;
-       z : f32;
-}
-
-vec3_magnitude :: proc (use v: ^Vec3) -> f32 {
-       return sqrt_f32(x * x + y * y + z * z); 
-}
-
-magnitude :: proc #overloaded {
-       vec2_magnitude,
-       vec3_magnitude,
-}
-
-dot :: proc (v: Vec2, u: Vec2) -> f32 {
-       return v.x * u.x + v.y * u.y;
-}
-
-
-// SomeType :: enum (u32) { Value1, Value2 }
-
-
-proc #export "main" {
-       vec := cast(^Vec2) alloc(sizeof Vec2);
-       vec.x = 5.0f;
-       vec.y = 12.0f;
-
-       printing.print(vec.x);
-       printing.print(vec.y);
-
-       mag :: vec.magnitude();
-
-       printing.print(mag);
-
-       printing.print((*vec).dot(1.0f, 1.0f));
-       printing.print(dot(2.0f, 4.0f, -6.0f, 3.0f));
-
-
-       v3 := cast(^Vec3) alloc(sizeof Vec3);
-       v3.x = 5.0f;
-       v3.y = 12.0f;
-       v3.z = 13.0f;
-
-       printing.print(v3.magnitude());
-
-       foo := 5;
-       foo <<= 2;
-       foo &= 6;
-       foo |= 5;
-       foo >>= 1;
-       printing.print(foo);
-}
\ No newline at end of file
index 516375ad880874f27b72382ac17b1e0cece8553e..c65b0d72f76b74275272acd30c96040e0f337087 100644 (file)
@@ -2,7 +2,7 @@
 #include "onyxmsgs.h"
 #include "onyxutils.h"
 
-#define MAX_MSGS 10
+#define MAX_MSGS 100
 
 OnyxMessages msgs;
 
index 3739f72f2b6a926f9b547219769fbefbd98b7944..573f89c2a51a4c7286924c0d96f2433b150ab677 100644 (file)
@@ -110,8 +110,10 @@ static AstType* symres_type(AstType* type) {
         return type;
     }
 
-    assert(("Bad type node", 0));
-    return NULL;
+    onyx_message_add(Msg_Type_Literal,
+            (OnyxFilePos) { 0 },
+            onyx_ast_node_kind_string(type->kind));
+    return type;
 }
 
 static void symres_local(AstLocal** local) {
@@ -230,6 +232,7 @@ static void symres_struct_literal(AstStructLiteral* sl) {
                 onyx_message_add(Msg_Type_No_Field,
                         (*smem)->token->pos,
                         (*smem)->token->text, type_get_name(sl->type));
+                token_toggle_end((*smem)->token);
                 return;
             }
             token_toggle_end((*smem)->token);
index 7f1c6aa4542ee30e58ebe864bc42a8974e7b8ccb..e6cdc36c5aca68d554da05dfa7d198830c1e382f 100644 (file)
@@ -357,9 +357,7 @@ Type* type_build_from_ast(bh_allocator alloc, AstType* type_node) {
             assert(("symbol node in type expression", 0));
             return NULL;
 
-        default:
-            assert(("Node is not a type node", 0));
-            return NULL;
+        default: return NULL;
     }
 }
 
@@ -474,8 +472,10 @@ b32 type_is_array(Type* type) {
 }
 
 b32 type_is_struct(Type* type) {
+    if (type == NULL) return 0;
     if (type->kind == Type_Kind_Struct) return 1;
-    if (type->kind == Type_Kind_Pointer && type->Pointer.elem->kind == Type_Kind_Struct) return 1;
+    if (type->kind == Type_Kind_Pointer)
+        if (type->Pointer.elem != NULL && type->Pointer.elem->kind == Type_Kind_Struct) return 1;
     return 0;
 }
 
index f4bd1703df33ffa2643a7a1de10352e4fbc43ad2..049d120370009f18699255bbcc736cf1239491c3 100644 (file)
@@ -20,13 +20,13 @@ static const char* ast_node_names[] = {
     "INCLUDE FOLDER",
     "USE PACKAGE",
     "ALIAS",
-    "MEMORY RESERVATION"
+    "MEMORY RESERVATION",
 
     "BINDING",
     "FUNCTION",
     "OVERLOADED_FUNCTION",
     "BLOCK",
-    "SCOPE",
+    "LOCAL GROUP",
     "LOCAL",
     "GLOBAL",
     "SYMBOL",
@@ -52,14 +52,17 @@ static const char* ast_node_names[] = {
     "PARAM",
     "ARGUMENT",
     "CALL",
+    "INTRINSIC CALL",
     "RETURN",
     "ADDRESS OF",
     "DEREFERENCE",
     "ARRAY_ACCESS",
     "FIELD_ACCESS",
+    "UFC",
     "SIZE OF",
-    "ALIGN OF"
-    "FILE CONTENTS"
+    "ALIGN OF",
+    "FILE CONTENTS",
+    "STRUCT LITERAL",
 
     "IF",
     "FOR",