summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--allocator.c2
-rw-r--r--eval.c33
-rw-r--r--main.c1
-rw-r--r--test.toc6
4 files changed, 23 insertions, 19 deletions
diff --git a/allocator.c b/allocator.c
index 793c6cc..69e18fb 100644
--- a/allocator.c
+++ b/allocator.c
@@ -1,4 +1,4 @@
-/* #define NO_ALLOCATOR 1 */
+#define NO_ALLOCATOR 1
/* number of bytes a page hold, not including the header */
#define PAGE_BYTES (16384 - sizeof(Page))
#define PAGE_MAX_ALIGNS (PAGE_BYTES / sizeof(max_align_t))
diff --git a/eval.c b/eval.c
index d5e6751..7754f57 100644
--- a/eval.c
+++ b/eval.c
@@ -395,8 +395,7 @@ static bool eval_set(Evaluator *ev, Expression *set, Value *to) {
switch (set->unary.op) {
case UNARY_DEREF: {
Value ptr;
- if (!eval_expr(ev, set->unary.of, &ptr)) return false;
- printf("%p\n",ptr.ptr);
+ if (!eval_expr(ev, set->unary.of, &ptr)) return false;
eval_deref_set(ptr.ptr, to, &set->type);
} break;
default: assert(0); break;
@@ -427,7 +426,7 @@ static bool eval_set(Evaluator *ev, Expression *set, Value *to) {
err_print(set->where, "Array out of bounds (%lu, array size = %lu)\n", (unsigned long)i, (unsigned long)arr_sz);
return false;
}
- eval_deref_set((char *)arr.arr + compiler_sizeof(&set->binary.lhs->type) * i, to, &set->binary.lhs->type);
+ eval_deref_set((char *)arr.arr + compiler_sizeof(set->binary.lhs->type.arr.of) * i, to, &set->binary.lhs->type);
} break;
default: break;
}
@@ -569,7 +568,8 @@ static bool eval_expr(Evaluator *ev, Expression *e, Value *v) {
err_print(o->where, "Array out of bounds (%lu, array size = %lu)\n", (unsigned long)i, (unsigned long)arr_sz);
return false;
}
- v->ptr = (char *)arr.arr + compiler_sizeof(&o->binary.lhs->type) * i;
+ v->ptr = ((char *)arr.arr) + compiler_sizeof(o->binary.lhs->type.arr.of) * i;
+ printf("%p\n",v->ptr);
} break;
default: break;
}
@@ -611,7 +611,9 @@ static bool eval_expr(Evaluator *ev, Expression *e, Value *v) {
case BINARY_ADD:
eval_binary_op_nums_only(+); break;
case BINARY_SUB:
- eval_binary_op_nums_only(-); break;
+ eval_binary_op_nums_only(-);
+ printf("%p %p\n", lhs.ptr, rhs.ptr);
+ break;
case BINARY_MUL:
eval_binary_op_nums_only(*); break;
case BINARY_DIV:
@@ -768,25 +770,30 @@ static bool eval_expr(Evaluator *ev, Expression *e, Value *v) {
v->arr = err_calloc(1, compiler_sizeof(&e->new.type));
else
v->ptr = err_calloc(1, compiler_sizeof(&e->new.type));
-
break;
}
return true;
}
static bool eval_decl(Evaluator *ev, Declaration *d) {
+ Value val = {0};
+ int has_expr = d->flags & DECL_FLAG_HAS_EXPR;
+ if (has_expr) {
+ if (!eval_expr(ev, &d->expr, &val))
+ return false;
+ d->flags |= DECL_FLAG_HAS_EXPR;
+ }
+ long index = 0;
arr_foreach(d->idents, Identifier, i) {
IdentDecl *id = ident_decl(*i);
id->flags |= IDECL_FLAG_HAS_VAL;
- assert(id->decl == d);
- if (d->flags & DECL_FLAG_HAS_EXPR) {
- if (!eval_expr(ev, &d->expr, &id->val))
- return false;
- } else if (d->type.kind == TYPE_ARR) {
- /* stack array allocation */
+ if (has_expr && d->expr.kind == EXPR_TUPLE) {
+ id->val = val.tuple[index++];
+ } else if (!has_expr && d->type.kind == TYPE_ARR) {
+ /* "stack" array */
id->val.arr = err_calloc(d->type.arr.n, compiler_sizeof(d->type.arr.of));
} else {
- id->val = (Value){0};
+ id->val = val;
}
}
return true;
diff --git a/main.c b/main.c
index e77b6cb..9024d1d 100644
--- a/main.c
+++ b/main.c
@@ -1,5 +1,6 @@
/*
TODO:
+fix double eval_expr problem
call fns at compile time
finish evaluator
improve casting: do you really need "as"?
diff --git a/test.toc b/test.toc
index bfe8561..81dbee0 100644
--- a/test.toc
+++ b/test.toc
@@ -1,7 +1,3 @@
main @= fn() {
- // foo @= true;
- // N, M @= 8 * if foo { 8 } else { 3} - 3, 894;
- // foo @= new[3]int;
- // x : [foo[0]]int;
- y : [{x : [3]int; p : &int = &x[2]; *p = 734; x[2] }]f32;
+ ASDF : [{x:[3]int; p, q := &x[0], &x[2]; *q = 3412; *q}]f32;
}; \ No newline at end of file