summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLeo Tenenbaum <pommicket@gmail.com>2020-07-10 17:07:09 -0400
committerLeo Tenenbaum <pommicket@gmail.com>2020-07-10 17:07:09 -0400
commit1c0e87ce47c22512878edef083577aa573fd7876 (patch)
tree3ee51312c97771dea5773e762967b384b3a8dc8c
parent2aea7ec331f80c72822dedfa2c9c0054a72975d1 (diff)
oops fixed setting stack-allocated arrs/structs
-rw-r--r--eval.c11
-rw-r--r--test.toc23
2 files changed, 27 insertions, 7 deletions
diff --git a/eval.c b/eval.c
index 8542eb4..a948da2 100644
--- a/eval.c
+++ b/eval.c
@@ -553,8 +553,8 @@ static void eval_deref_set(void *set, Value *to, Type *type) {
assert(type->flags & TYPE_IS_RESOLVED);
switch (type->kind) {
case TYPE_PTR: *(void **)set = to->ptr; break;
- case TYPE_ARR: memcpy(set, to->arr, compiler_sizeof(type)); break;
- case TYPE_STRUCT: memcpy(set, to->struc, compiler_sizeof(type)); break;
+ case TYPE_ARR: memmove(set, to->arr, compiler_sizeof(type)); break;
+ case TYPE_STRUCT: memmove(set, to->struc, compiler_sizeof(type)); break;
case TYPE_FN: *(FnExpr **)set = to->fn; break;
case TYPE_TUPLE: *(Value **)set = to->tuple; break;
case TYPE_BUILTIN:
@@ -803,6 +803,7 @@ static Status eval_address_of(Evaluator *ev, Expression *e, void **ptr) {
}
static Status eval_set(Evaluator *ev, Expression *set, Value *to) {
+ Type *t = &set->type;
switch (set->kind) {
case EXPR_IDENT: {
Identifier i = set->ident;
@@ -810,14 +811,14 @@ static Status eval_set(Evaluator *ev, Expression *set, Value *to) {
if (!ival) {
return false;
}
- *ival = *to;
+ eval_deref_set(val_get_ptr(ival, t), to, t);
} break;
case EXPR_UNARY_OP:
switch (set->unary.op) {
case UNARY_DEREF: {
Value ptr;
if (!eval_expr(ev, set->unary.of, &ptr)) return false;
- eval_deref_set(ptr.ptr, to, &set->type);
+ eval_deref_set(ptr.ptr, to, t);
} break;
default: assert(0); break;
}
@@ -837,7 +838,7 @@ static Status eval_set(Evaluator *ev, Expression *set, Value *to) {
void *ptr;
if (!eval_ptr_to_struct_field(ev, set, &ptr))
return false;
- eval_deref_set(ptr, to, &set->type);
+ eval_deref_set(ptr, to, t);
} break;
default: assert(0); break;
}
diff --git a/test.toc b/test.toc
index dfcbe51..86c3855 100644
--- a/test.toc
+++ b/test.toc
@@ -1,5 +1,24 @@
-#include "std/mem.toc";
+#include "std/io.toc", io;
+Point ::= struct {
+ x, y: int;
+}
main ::= fn(){
- a : []int = news(int, 5);
+ a, b: Point;
+ b.x = 15;
+ b.y = 12;
+ a = b;
+ a = a;
+ c, d: [5]int;
+ c[0] = 39;
+
+ d = c;
+ d = d;
+ c = d;
+ io.puti(a.x);
+ io.puti(a.y);
+ io.puti(b.x);
+ io.puti(b.y);
+ io.puti(c[0]);
+ io.puti(d[0]);
}
main();