aboutsummaryrefslogtreecommitdiff
path: root/Sil/Compile.icl
diff options
context:
space:
mode:
authorCamil Staps2017-07-30 00:51:48 +0200
committerCamil Staps2017-07-30 00:54:02 +0200
commit05a47988d9466b827f7dbab44bab33a67228efe9 (patch)
treec9f2ce96dec969f1d756e25357dbbe2c79dfbad2 /Sil/Compile.icl
parentCleanup; add <> < > <= >= (diff)
Start with positional errors (see #5)
Diffstat (limited to 'Sil/Compile.icl')
-rw-r--r--Sil/Compile.icl25
1 files changed, 17 insertions, 8 deletions
diff --git a/Sil/Compile.icl b/Sil/Compile.icl
index d20eff1..ced497e 100644
--- a/Sil/Compile.icl
+++ b/Sil/Compile.icl
@@ -26,6 +26,7 @@ import qualified ABC.Assembler as ABC
import Sil.Error
import Sil.Syntax
import Sil.Types
+import Sil.Util.Parser
import Sil.Util.Printer
error :: Error -> RWST r w s (MaybeError Error) a
@@ -263,6 +264,9 @@ where
class gen a :: a -> Gen ()
+instance gen (Positioned a) | gen a
+where gen p = gen $ fromPositioned p
+
instance gen Program
where
gen p =
@@ -276,24 +280,27 @@ where
, 'ABC'.Jmp "_driver"
, 'ABC'.Annotation $ 'ABC'.OAnnot 0 []
, 'ABC'.Label "_sil_boot2" ] *>
- let gsize = foldr (+~) zero [typeSize i.init_type \\ i <- p.p_globals] in
+ let gsize = foldr (+~) zero [typeSize i.init_type \\ i <- globs] in
modify (\cs -> {cs & globalsize=(gsize.asize, gsize.bsize)}) *>
shrinkStack gsize *>
- mapM_ reserveVar [(i.init_name, i.init_type) \\ i <- p.p_globals] *>
+ mapM_ reserveVar [(i.init_name, i.init_type) \\ i <- globs] *>
mapM_ gen p.p_globals *>
tell [ 'ABC'.Jmp (toLabel "main") ] *>
pushTypeResolver typeresolver *>
- mapM_ addFunction p.p_funs *>
+ mapM_ (addFunction o fromPositioned) p.p_funs *>
mapM_ gen p.p_funs *>
popTypeResolver
where
typeresolver :: Name -> Maybe (MaybeError Error Type)
- typeresolver n = case [f \\ f <- p.p_funs | f.f_name == n] of
+ typeresolver n = case [f \\ f <- funs | f.f_name == n] of
[f:_] -> type typeresolver f
- [] -> case [g.init_type \\ g <- p.p_globals | g.init_name == n] of
+ [] -> case [g.init_type \\ g <- globs | g.init_name == n] of
[t:_] -> Just $ Ok t
[] -> Nothing
+ globs = map fromPositioned p.p_globals
+ funs = map fromPositioned p.p_funs
+
instance gen Function
where
gen f =
@@ -368,7 +375,7 @@ where
gen cb =
storeStackOffsets *>
gets stackoffsets >>= \so ->
- mapM_ reserveVar [(i.init_name, i.init_type) \\ i <- cb.cb_init] *>
+ mapM_ reserveVar [(i.init_name, i.init_type) \\ i <- init] *>
mapM_ gen cb.cb_init *>
addToReturn cleanup` *>
pushTypeResolver typeresolver *>
@@ -383,10 +390,12 @@ where
_ -> [ 'ABC'.Pop_a locals.asize
, 'ABC'.Pop_b locals.bsize
]
- locals = foldr (+~) zero [typeSize i.init_type \\ i <- cb.cb_init]
+ locals = foldr (+~) zero [typeSize i.init_type \\ i <- init]
typeresolver :: Name -> Maybe (MaybeError Error Type)
- typeresolver n = listToMaybe [Ok i.init_type \\ i <- cb.cb_init | i.init_name == n]
+ typeresolver n = listToMaybe [Ok i.init_type \\ i <- init | i.init_name == n]
+
+ init = map fromPositioned cb.cb_init
instance gen Initialisation
where