From c0c15f9d8f0e30ea4234d3d45e254d7fb9a12814 Mon Sep 17 00:00:00 2001 From: Camil Staps Date: Tue, 25 Jul 2017 12:31:42 +0200 Subject: Fix issue with local basic values; resolve #10: lazy || and && --- Sil/Compile.icl | 42 ++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 40 insertions(+), 2 deletions(-) (limited to 'Sil/Compile.icl') 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 -- cgit v1.2.3