From 23eeaac32323bf70c1f84cb9a13d9e5a57bc04ee Mon Sep 17 00:00:00 2001 From: Camil Staps Date: Mon, 17 Jul 2017 22:44:24 +0000 Subject: Fix some incorrect ABC instructions --- Sil/Compile.icl | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'Sil/Compile.icl') diff --git a/Sil/Compile.icl b/Sil/Compile.icl index 4313c0e..495f277 100644 --- a/Sil/Compile.icl +++ b/Sil/Compile.icl @@ -17,6 +17,7 @@ from Text import <+ import qualified ABC.Assembler as ABC import Sil.Syntax +import Sil.Util instance toString CompileError where @@ -62,7 +63,7 @@ fresh = gets labels *> pure (hd labs) reserveVar :: Int Name -> Gen Int -reserveVar i n = modify (\cs -> {cs & addresses='M'.put n (StackAddr i) cs.addresses}) *> pure (i + 1) +reserveVar i n = modify (\cs -> {cs & addresses='M'.put n (StackAddr i) cs.addresses}) *> pure (i+1) class gen a :: a -> Gen () @@ -72,7 +73,7 @@ where instance gen CodeBlock where - gen cb = foldM reserveVar 1 [i.init_name \\ i <- cb.cb_init] *> + gen cb = foldM reserveVar 0 [i.init_name \\ i <- cb.cb_init] *> mapM_ gen cb.cb_init *> mapM_ gen cb.cb_content @@ -82,8 +83,9 @@ where instance gen Statement where - gen (Declaration n app) = gets addresses >>= \addrs -> case 'M'.get n addrs of - Just (StackAddr i) -> comment "Declaration" *> gen app *> tell ['ABC'.Fill_a 0 i] + gen st=:(Declaration n app) = gets addresses >>= \addrs -> case 'M'.get n addrs of + Just (StackAddr i) -> comment (toString st) *> gen app *> + tell ['ABC'.Update_a 0 $ i+1, 'ABC'.Pop_a 1] Just (LabelAddr _) -> liftT $ Error VariableLabel _ -> liftT $ Error $ UndefinedName n gen (Application app) = comment "Application" *> gen app @@ -93,11 +95,11 @@ where instance gen Application where gen (Name n) = gets addresses >>= \addrs -> case 'M'.get n addrs of - Just (StackAddr i) -> comment "Retrieve name" *> tell ['ABC'.Push_a i] + Just (StackAddr i) -> tell ['ABC'.Push_a i] Just (LabelAddr _) -> liftT $ Error VariableLabel _ -> liftT $ Error $ UndefinedName n - gen (Literal (BLit b)) = comment "Literal" *> tell ['ABC'.Create, 'ABC'.FillB b 0] - gen (Literal (ILit i)) = comment "Literal" *> tell ['ABC'.Create, 'ABC'.FillI i 0] + gen (Literal (BLit b)) = tell ['ABC'.Create, 'ABC'.FillB b 0] + gen (Literal (ILit i)) = tell ['ABC'.Create, 'ABC'.FillI i 0] gen (App n args) = gets addresses >>= \addrs -> case 'M'.get n addrs of Just (LabelAddr l) -> comment "Retrieve arguments" *> mapM gen args *> -- cgit v1.2.3