diff options
author | Camil Staps | 2023-01-30 21:56:16 +0100 |
---|---|---|
committer | Camil Staps | 2023-01-30 21:56:16 +0100 |
commit | a03283a775bb31d501de35a18ec07b4cc65a9dbe (patch) | |
tree | 94cc0a77ebf3045f98fc2e93c6b74dbb9bb9c01f /snug-clean/src/Snug/Compile | |
parent | Add documentation (diff) |
Add compilation for symbols with arity 0
Diffstat (limited to 'snug-clean/src/Snug/Compile')
-rw-r--r-- | snug-clean/src/Snug/Compile/Simulate.dcl | 1 | ||||
-rw-r--r-- | snug-clean/src/Snug/Compile/Simulate.icl | 10 |
2 files changed, 11 insertions, 0 deletions
diff --git a/snug-clean/src/Snug/Compile/Simulate.dcl b/snug-clean/src/Snug/Compile/Simulate.dcl index a61d631..9b938d5 100644 --- a/snug-clean/src/Snug/Compile/Simulate.dcl +++ b/snug-clean/src/Snug/Compile/Simulate.dcl @@ -19,6 +19,7 @@ from Snug.Syntax import :: BasicValue simulate :: !(Simulator a) -> [Instruction] buildCons :: !Label !Int -> Simulator () +buildThunk :: !Label !Int -> Simulator () pushBasicValue :: !BasicValue -> Simulator () diff --git a/snug-clean/src/Snug/Compile/Simulate.icl b/snug-clean/src/Snug/Compile/Simulate.icl index 620ec3e..b383936 100644 --- a/snug-clean/src/Snug/Compile/Simulate.icl +++ b/snug-clean/src/Snug/Compile/Simulate.icl @@ -87,6 +87,16 @@ buildCons cons nargs = mapM_ (\_ -> pop >>= write_heap) [1..nargs] >>| push addr +buildThunk :: !Label !Int -> Simulator () +buildThunk cons 0 = + write_heap (SVImmediate (Address 0 cons)) >>= \addr -> + modify (\s -> {s & hp_offset=s.hp_offset+4}) >>| // reserve space to overwrite with indir + push addr +buildThunk cons nargs = + write_heap (SVImmediate (Address 0 cons)) >>= \addr -> + mapM_ (\_ -> pop >>= write_heap) [1..nargs] >>| + push addr + pushBasicValue :: !BasicValue -> Simulator () pushBasicValue val = push (SVImmediate (Immediate imm)) where |