summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--eval.c4
-rw-r--r--infer.c1
-rw-r--r--main.c1
-rw-r--r--std/arr.toc2
-rw-r--r--test.toc21
5 files changed, 14 insertions, 15 deletions
diff --git a/eval.c b/eval.c
index df6f469..b40fe4d 100644
--- a/eval.c
+++ b/eval.c
@@ -584,6 +584,10 @@ static Status eval_val_ptr_at_index(Location where, Value *arr, U64 i, Type *arr
err_print(where, "Slice out of bounds (%lu, slice size = %lu)\n", (unsigned long)i, (unsigned long)slice_sz);
return false;
}
+ if (!arr->slice.data) {
+ err_print(where, "Indexing null slice.");
+ return false;
+ }
*ptr = (char *)arr->slice.data + compiler_sizeof(arr_type->slice) * i;
if (type) *type = arr_type->slice;
} break;
diff --git a/infer.c b/infer.c
index e895251..bcb3103 100644
--- a/infer.c
+++ b/infer.c
@@ -148,7 +148,6 @@ static bool infer_from_expr(Typer *tr, Expression *match, Expression *to, Identi
return true;
}
-/* wheres points to a Location, with more locations wheres_stride bytes apart */
static bool infer_from_type(Typer *tr, Type *match, Type *to, Identifier *idents, Value *vals, Type *types, Location where) {
assert(to->flags & TYPE_IS_RESOLVED);
assert(!(match->flags & TYPE_IS_RESOLVED));
diff --git a/main.c b/main.c
index 6cbc1ce..f53cce2 100644
--- a/main.c
+++ b/main.c
@@ -8,7 +8,6 @@
/*
TODO:
-make sure a,b::=, works
variadic fns
#foreign variadic fns
#returns_code (function/struct body is a block, to be evaluated at compile time, which returns the actual statements -- you can use this for implementation of printf)
diff --git a/std/arr.toc b/std/arr.toc
index c973777..a2d202b 100644
--- a/std/arr.toc
+++ b/std/arr.toc
@@ -9,13 +9,13 @@ resv ::= fn(t ::=, a : &Arr(t), n: int) {
if a.cap >= n {
return;
}
+ a.cap = n;
new_data := new(t, a.cap);
new_data.len = a.data.len;
for x, i := &new_data {
*x = a.data[i];
}
a.data = new_data;
- a.cap = n;
};
add ::= fn(t ::=, a : &Arr(t), x : t) {
diff --git a/test.toc b/test.toc
index eb51a96..f9e9d40 100644
--- a/test.toc
+++ b/test.toc
@@ -1,22 +1,19 @@
#include "std/io.toc", io;
-#include "std/arr.toc", arr;
-arr_sum ::= fn(t::=, a:arr.Arr(t)) t {
+arr_sum ::= fn(t,n::=, a:[n]t) t {
total := 0 as t;
- for x := a.data {
+ for x := a {
total += x;
}
total
};
-mk_arr ::= fn(x:int, y:int, z:int) a:arr.Arr(int) {
- arr.add(&a, x);
- arr.add(&a, y);
- arr.add(&a, z);
-};
-
main ::= fn() {
- a := mk_arr(1,2,3);
- io.puti(arr.len(a));
- io.puti(arr_sum(a));
+ a : [3]int;
+ a[0] = 1;
+ a[1] = 1;
+ a[2] = 1;
+
+ io.puti(arr_sum(a));
};
+main(); \ No newline at end of file