From 2f243de6ce9402f880677a07b832c0e56a7f688d Mon Sep 17 00:00:00 2001 From: lemon Date: Mon, 29 Aug 2022 21:57:58 +0200 Subject: many things ,varags --- src/fold.cff | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) (limited to 'src/fold.cff') diff --git a/src/fold.cff b/src/fold.cff index 2e7cae3..8814d32 100644 --- a/src/fold.cff +++ b/src/fold.cff @@ -7,6 +7,12 @@ fn numcast(ex *Expr, to *const Type) void { let iu = &ex.u.IntLit; let f = &ex.u.FloLit; let b = &ex.u.BoolLit; + if to->is(:Enum) { + to = unconstify(to.u.Enum.intty); + } + if from->is(:Enum) { + from = unconstify(from.u.Enum.intty); + } switch { case to == from; // pass @@ -43,6 +49,7 @@ fn numcast(ex *Expr, to *const Type) void { case to->is(:Bool) and from->is(:Int); *b = iu.u == 0; case else; + efmt("%t <- %t\n",to,from); assert(#f, "bad numcast"); } @@ -192,7 +199,15 @@ fn findex(ex *Expr) void { } else { assert(#f,"bad"); } - +} +fn fas(ex *Expr) void { + let src = ex.u.Cast; + if !fold(src) or !(ex.ty->is(:Int) or ex.ty->is(:Flo) or ex.ty->is(:Enum) or ex.ty->is(:Bool)) { + return; + } + let ty = ex.ty; + *ex = *src; + numcast(ex, ty); } extern fn fold(ex *Expr) bool { @@ -213,6 +228,9 @@ extern fn fold(ex *Expr) bool { case :Cond; fcond(ex); + case :Cast; + fas(ex); + case :Index; findex(ex); -- cgit v1.2.3