aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Sil/Compile.icl11
-rw-r--r--examples/while.sil7
2 files changed, 14 insertions, 4 deletions
diff --git a/Sil/Compile.icl b/Sil/Compile.icl
index 50cc86b..22b6532 100644
--- a/Sil/Compile.icl
+++ b/Sil/Compile.icl
@@ -96,7 +96,7 @@ typeresolvers cs = cs.typeresolvers
fresh :: a -> Gen 'ABC'.Label | toString a
fresh n = gets labels
>>= \labs -> modify (\cs -> {cs & labels=tl labs})
- $> n <+ hd labs
+ $> toLabel (n <+ hd labs)
storeStackOffset :: Gen ()
storeStackOffset = modify \cs -> {cs & storedoffsets=[cs.stackoffset:cs.storedoffsets]}
@@ -170,7 +170,7 @@ where
, 'ABC'.Annotation $ 'ABC'.RawAnnot ["module", "m_sil_compiled", "\"sil_compiled\""]
, 'ABC'.Label "__sil_boot"
, 'ABC'.Create
- , 'ABC'.Fill "_" 0 "main" 0
+ , 'ABC'.Fill "_" 0 (toLabel "main") 0
, 'ABC'.Jmp "_driver"
] *>
pushTypeResolver typeresolver *>
@@ -187,7 +187,7 @@ instance gen Function
where
gen f =
tell [ 'ABC'.Annotation $ 'ABC'.OAnnot args []
- , 'ABC'.Label f.f_name
+ , 'ABC'.Label $ toLabel f.f_name
] *>
foldM reserveVar locals [a.arg_name \\ a <- reverse f.f_args] *>
newReturn cleanup` *>
@@ -315,7 +315,7 @@ where
comment "Retrieve arguments" *> mapM gen args *>
comment "Apply function" *>
tell [ 'ABC'.Annotation $ 'ABC'.DAnnot fs.fs_arity []
- , 'ABC'.Jsr n
+ , 'ABC'.Jsr $ toLabel n
, 'ABC'.Annotation $ 'ABC'.OAnnot (typeSize fs.fs_rettype) []
] *>
shrinkStack (fs.fs_arity - typeSize fs.fs_rettype)
@@ -381,3 +381,6 @@ where
comment :: String -> Gen ()
comment s = tell ['ABC'.Comment s]
+
+toLabel :: a -> 'ABC'.Label | toString a
+toLabel n = "__sil_" <+ n
diff --git a/examples/while.sil b/examples/while.sil
index 49186fb..fb2778b 100644
--- a/examples/while.sil
+++ b/examples/while.sil
@@ -1,3 +1,9 @@
+Void sleep(Int n) {
+ |~ pushI_a 0
+ |~ ccall sleep "I:I"
+ |~ pop_b 1
+}
+
Void print(Int n) {
|~ push_a 0
|~.d 1 0
@@ -8,6 +14,7 @@ Void print(Int n) {
Int loop(Int start, Int end) {
while (!(start == end)) {
print(start);
+ sleep(start);
start := start + 1;
}
return start;