aboutsummaryrefslogtreecommitdiff
path: root/src/fold.cff
diff options
context:
space:
mode:
Diffstat (limited to 'src/fold.cff')
-rw-r--r--src/fold.cff20
1 files changed, 19 insertions, 1 deletions
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);