aboutsummaryrefslogtreecommitdiff
path: root/Sil/Compile.icl
diff options
context:
space:
mode:
authorCamil Staps2017-07-19 12:57:01 +0000
committerCamil Staps2017-07-19 12:57:01 +0000
commit407a0c8e7e14b96c2a0487cefe09cdc021f002b0 (patch)
tree6f2f8eec4691c6c292f0cc77734729ac0b27fcf7 /Sil/Compile.icl
parentNomenclature: Application type is now Expression (diff)
Add while and !, fix error in consecutive declarations
Diffstat (limited to 'Sil/Compile.icl')
-rw-r--r--Sil/Compile.icl19
1 files changed, 16 insertions, 3 deletions
diff --git a/Sil/Compile.icl b/Sil/Compile.icl
index b4854ba..ca375b1 100644
--- a/Sil/Compile.icl
+++ b/Sil/Compile.icl
@@ -184,7 +184,7 @@ instance gen Statement
where
gen st=:(Declaration n app) = gets addresses >>= \addrs -> case 'M'.get n addrs of
Just i -> comment (toString st) *> gen app *>
- tell ['ABC'.Update_a 0 $ i+1, 'ABC'.Pop_a 1]
+ tell ['ABC'.Update_a 0 $ i+1, 'ABC'.Pop_a 1] *> shrinkStack 1
_ -> liftT $ Error $ UndefinedName n
gen (Application e) = comment "Application" *> gen e *> tell ['ABC'.Pop_a 1]
gen (Return (Just e)) = comment "Return" *> gen e *> cleanup *> tell ['ABC'.Rtn]
@@ -208,6 +208,15 @@ where
genelse :: 'ABC'.Label (Maybe CodeBlock) -> Gen ()
genelse end Nothing = tell ['ABC'.Label end]
genelse end (Just cb) = gen cb *> tell ['ABC'.Label end]
+ gen (While cond do) =
+ fresh "while" >>= \loop -> fresh "whileend" >>= \end ->
+ tell [ 'ABC'.Label loop ] *>
+ gen cond *>
+ toBStack 'ABC'.BT_Bool 1 *>
+ tell [ 'ABC'.JmpFalse end ] *>
+ gen do *>
+ tell [ 'ABC'.Jmp loop
+ , 'ABC'.Label end ]
instance gen Expression
where
@@ -237,12 +246,16 @@ where
instance gen Op1
where
gen op =
- toBStack 'ABC'.BT_Int 1 *>
+ toBStack type 1 *>
tell [instr] *>
- BtoAStack 'ABC'.BT_Int
+ BtoAStack type
where
instr = case op of
Neg -> 'ABC'.NegI
+ Not -> 'ABC'.NotB
+ type = case op of
+ Neg -> 'ABC'.BT_Int
+ Not -> 'ABC'.BT_Bool
instance gen Op2
where