aboutsummaryrefslogtreecommitdiff
path: root/src/fold.cff
diff options
context:
space:
mode:
Diffstat (limited to 'src/fold.cff')
-rw-r--r--src/fold.cff31
1 files changed, 31 insertions, 0 deletions
diff --git a/src/fold.cff b/src/fold.cff
index a2c95b8..c9991b7 100644
--- a/src/fold.cff
+++ b/src/fold.cff
@@ -53,6 +53,37 @@ fn numcast(ex *Expr, to *const Type) void {
}
fn funary(ex *Expr) void {
+ let r = ex.u.UnOp.ex;
+ let ty = ex.ty;
+ let iu = &ex.u.IntLit;
+ let f = &ex.u.FloLit;
+ let b = &ex.u.BoolLit;
+
+ if !fold(r) {
+ return;
+ }
+ switch ex.u.UnOp.op {
+ case :neg;
+ *ex = *r;
+ if r.ty->is(:Int) {
+ iu.i = -iu.i;
+ } else if r.ty->is(:Flo) {
+ *f = -*f;
+ } else {
+ assert(#f, "neg");
+ }
+ numcast(ex, ty);
+ case :compl;
+ *ex = *r;
+ iu.i = ~iu.i;
+ assert(r.ty->is(:Int), "compl");
+ numcast(ex, ty);
+ case :not;
+ *ex = *r;
+ *b = !*b;
+ assert(r.ty->is(:Bool), "not");
+ }
+ ex.ty = ty;
}
fn fbinary(ex *Expr) void {