Gm m3 #3

Merged
msydneyslaga merged 4 commits from gm-m3 into main 2023-12-01 14:45:08 -07:00
Showing only changes of commit e0dc3f58f7 - Show all commits

View File

@@ -20,6 +20,7 @@ import Text.Printf
import Text.PrettyPrint hiding ((<>))
import Text.PrettyPrint.HughesPJ (maybeParens)
import Data.Foldable (traverse_)
import Debug.Trace
import System.IO (Handle, hPutStrLn)
import Data.Heap
import Core
@@ -321,6 +322,21 @@ buildInitialHeap (Program ss) = mapAccumL allocateSc mempty compiled
<> [MkAp]
-- << [ref/compileC]
compileC g (Let NonRec bs e) =
mconcat binders <> compileC g' e <> [Slide d]
where
d = length bs
(g',binders) = mapAccumL compileBinder (argOffset d g) addressed
-- kinda gross. revisit this
addressed = bs `zip` reverse [0 .. d-1]
compileBinder :: Env -> (Binding, Int) -> (Env, Code)
compileBinder m (k := v,a) = (m',c)
where
m' = (k,a) : m
-- make note that we use m rather than m'!
c = compileC m v
-- | offset each address in the environment by n
argOffset :: Int -> Env -> Env
argOffset n = each . _2 %~ (+n)