diff options
author | Camil Staps | 2017-07-27 13:15:57 +0200 |
---|---|---|
committer | Camil Staps | 2017-07-27 13:15:57 +0200 |
commit | 2836dc2a1f15940a984211eeeec3f5a161b50762 (patch) | |
tree | 3d278ba3cf51e5fb5fdd4136563ae204dcaa6b35 /Sil | |
parent | Resolve #4: mandatory initial values for basic locals (diff) |
Resolve #11: special case for Void main
Diffstat (limited to 'Sil')
-rw-r--r-- | Sil/Compile.icl | 22 |
1 files changed, 18 insertions, 4 deletions
diff --git a/Sil/Compile.icl b/Sil/Compile.icl index 254cc67..d59573d 100644 --- a/Sil/Compile.icl +++ b/Sil/Compile.icl @@ -277,8 +277,9 @@ where typeresolver n = listToMaybe [Ok a.arg_type \\ a <- f.f_args | a.arg_name == n] mainBootstrap :: Gen () - mainBootstrap = case (f.f_name, (typeSize f.f_type).bsize) of - ("main", 1) -> + mainBootstrap + | f.f_name == "main" + | (typeSize f.f_type).bsize == 1 = fresh "main" >>= \lab -> tell [ 'ABC'.Annotation $ 'ABC'.DAnnot 0 [] , 'ABC'.Jsr lab @@ -295,8 +296,21 @@ where type = case f.f_type of TBool -> 'ABC'.BT_Bool TInt -> 'ABC'.BT_Int - _ -> - nop + | f.f_type == TVoid = + fresh "main" >>= \lab -> + tell [ 'ABC'.Annotation $ 'ABC'.DAnnot 0 [] + , 'ABC'.Jsr lab + , 'ABC'.Annotation $ 'ABC'.OAnnot 0 [] + , 'ABC'.Create + , 'ABC'.Raw "\tfillh e__predef_d_Unit 0 0" + , 'ABC'.Annotation $ 'ABC'.DAnnot 1 [] + , 'ABC'.Rtn + ] *> + comment "Reset sos" *> + modify (\cs -> {cs & stackoffsets=(0, 0)}) *> + tell [ 'ABC'.Label lab ] + | otherwise = nop + | otherwise = nop instance gen CodeBlock where |