From cc94b260b2ee57ee0f9dfd86baf58cecdeb470e9 Mon Sep 17 00:00:00 2001 From: Leo Tenenbaum Date: Sun, 20 Oct 2019 18:57:18 -0400 Subject: fixing eval --- eval.c | 7 +++++-- out.c | 17 ++++++++++------- test.toc | 23 ++++++++++++----------- vgcore.218438 | Bin 0 -> 6537216 bytes vgcore.218454 | Bin 0 -> 6537216 bytes vgcore.218567 | Bin 0 -> 6537216 bytes vgcore.218588 | Bin 0 -> 6537216 bytes vgcore.218644 | Bin 0 -> 6537216 bytes 8 files changed, 27 insertions(+), 20 deletions(-) create mode 100644 vgcore.218438 create mode 100644 vgcore.218454 create mode 100644 vgcore.218567 create mode 100644 vgcore.218588 create mode 100644 vgcore.218644 diff --git a/eval.c b/eval.c index 1a473ec..f171a71 100644 --- a/eval.c +++ b/eval.c @@ -502,7 +502,9 @@ static bool eval_expr(Evaluator *ev, Expression *e, Value *v) { eval_binary_op_one(f32, F32, op); \ eval_binary_op_one(f64, F64, op) + #define eval_binary_op_nums_only(op) \ + /* fix casting to bool */ val_cast(&lhs, &e->binary.lhs->type, &lhs, &e->type); \ val_cast(&rhs, &e->binary.rhs->type, &rhs, &e->type); \ assert(e->type.kind == TYPE_BUILTIN); \ @@ -534,7 +536,8 @@ static bool eval_expr(Evaluator *ev, Expression *e, Value *v) { assert(e->type.kind == TYPE_BUILTIN); \ switch (builtin) { \ eval_binary_bool_op_nums(builtin, op); \ - default: assert(0); break; \ + default:printf("%d\n",(int)builtin); \ + assert(!"Invalid builtin to "#op); break; \ } @@ -629,7 +632,7 @@ static bool eval_expr(Evaluator *ev, Expression *e, Value *v) { if (e->binary.op != BINARY_SET) if (!eval_expr(ev, e->binary.lhs, &lhs)) return false; if (!eval_expr(ev, e->binary.rhs, &rhs)) return false; - BuiltinType builtin = e->type.builtin; + BuiltinType builtin = e->binary.lhs->type.builtin; switch (e->binary.op) { case BINARY_ADD: eval_binary_op_nums_only(+); break; diff --git a/out.c b/out.c index d165db8..31f95d2 100644 --- a/out.c +++ b/out.c @@ -17,7 +17,7 @@ typedef struct { void *data; u64 n; } slice_; /* declarations */ -void puti(i64 x); +i64 foo(void); void main__(void); /* code */ int main() { @@ -25,17 +25,20 @@ int main() { return 0; } -void puti(i64 x) { +i64 foo(void) { { - }} + i64 i; { + i64 expr__; expr__ = 0;i = expr__;} + while ((i<100)) { + i = (i+1);; + }; + }return i; +} void main__(void) { { - i64((* Ar)[5]); { - i64((* expr__)[5]); expr__ = ((i64((*)[5]))calloc(1, sizeof(i64([5]))));Ar = expr__;} - slice_ A; { - slice_ expr__; slice_ a0_; a0_.data = calloc(100, sizeof(i64)); a0_.n = 100;expr__ = a0_;A = expr__;} + i64( Ar[1]) = {0}; }} diff --git a/test.toc b/test.toc index d182a0f..8b5c7fc 100644 --- a/test.toc +++ b/test.toc @@ -1,24 +1,25 @@ // #C("#include // #define kasfdhkjasdfhjk "); -puti @= fn(x: int) { +// puti @= fn(x: int) { // #C("printf(\"%ld\\n\", (long)x)"); -}; +// }; foo @= fn() int { - X := new([100]int); + // X := new([100]int); i := 0; while i < 100 { - (*X)[i] = i; - i = i + 1; - } - total := 0; - i = 0; - while i < 100 { - total = total + (*X)[i]; + // (*X)[i] = i; i = i + 1; } - total + i + // total := 0; + // i = 0; + // while i < 100 { + // total = total + (*X)[i]; + // i = i + 1; + // } + // total }; main @= fn() { diff --git a/vgcore.218438 b/vgcore.218438 new file mode 100644 index 0000000..eeae9d6 Binary files /dev/null and b/vgcore.218438 differ diff --git a/vgcore.218454 b/vgcore.218454 new file mode 100644 index 0000000..5a3a550 Binary files /dev/null and b/vgcore.218454 differ diff --git a/vgcore.218567 b/vgcore.218567 new file mode 100644 index 0000000..ccd3cb9 Binary files /dev/null and b/vgcore.218567 differ diff --git a/vgcore.218588 b/vgcore.218588 new file mode 100644 index 0000000..cf38c22 Binary files /dev/null and b/vgcore.218588 differ diff --git a/vgcore.218644 b/vgcore.218644 new file mode 100644 index 0000000..a728f98 Binary files /dev/null and b/vgcore.218644 differ -- cgit v1.2.3