aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCamil Staps2017-07-25 12:31:42 +0200
committerCamil Staps2017-07-25 12:31:42 +0200
commitc0c15f9d8f0e30ea4234d3d45e254d7fb9a12814 (patch)
tree0c8a1627cb2ed99e3e9bf4890efc18ec8366a5de
parentFix erroneous change (diff)
Fix issue with local basic values; resolve #10: lazy || and &&
-rw-r--r--Sil/Compile.icl42
1 files changed, 40 insertions, 2 deletions
diff --git a/Sil/Compile.icl b/Sil/Compile.icl
index 2cc6e01..9bfd4f5 100644
--- a/Sil/Compile.icl
+++ b/Sil/Compile.icl
@@ -424,8 +424,46 @@ where
] *>
growStack (foldl (-~) (typeSize fs.fs_rettype) $ map typeSize fs.fs_argtypes)
_ -> liftT $ Error $ UndefinedName n
- gen (BuiltinApp op arg) = gen arg *> gen op
- gen (BuiltinApp2 e1 op e2) = mapM gen [e2,e1] *> gen op
+ gen (BuiltinApp op arg) = genToBStack arg *> gen op
+ gen (BuiltinApp2 e1 LogOr e2) =
+ checkType TBool e1 *>
+ checkType TBool e2 *>
+ fresh "or_true" >>= \true ->
+ fresh "or_end" >>= \end ->
+ storeStackOffsets *>
+ genToBStack e1 *>
+ tell [ 'ABC'.JmpTrue true ] *>
+ genToBStack e2 *>
+ tell [ 'ABC'.Jmp end ] *>
+ restoreStackOffsets *>
+ tell [ 'ABC'.Label true
+ , 'ABC'.PushB True ] *>
+ growStack {zero & bsize=1} *>
+ tell [ 'ABC'.Label end ]
+ gen (BuiltinApp2 e1 LogAnd e2) =
+ checkType TBool e1 *>
+ checkType TBool e2 *>
+ fresh "and_false" >>= \false ->
+ fresh "and_end" >>= \end ->
+ storeStackOffsets *>
+ genToBStack e1 *>
+ tell [ 'ABC'.JmpFalse false ] *>
+ genToBStack e2 *>
+ tell [ 'ABC'.Jmp end ] *>
+ restoreStackOffsets *>
+ tell [ 'ABC'.Label false
+ , 'ABC'.PushB False ] *>
+ growStack {zero & bsize=1} *>
+ tell [ 'ABC'.Label end ]
+ gen (BuiltinApp2 e1 op e2) = mapM genToBStack [e2,e1] *> gen op
+
+genToBStack :: Expression -> Gen ()
+genToBStack (Name n) = findVar n >>= getLoc
+where
+ getLoc :: Address -> Gen ()
+ getLoc (AAddr i) = tell ['ABC'.PushI_a $ i] *> growStack {zero & bsize=1}
+ getLoc (BAddr i) = tell ['ABC'.Push_b $ i] *> growStack {zero & bsize=1}
+genToBStack e = gen e
instance gen Op1
where