Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Double substitute the Nockma functions placeholder in the main function #2715

Merged
merged 3 commits into from
Apr 10, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 16 additions & 16 deletions src/Juvix/Compiler/Nockma/Translation/FromTree.hs
Original file line number Diff line number Diff line change
Expand Up @@ -728,8 +728,8 @@ runCompilerWith opts constrs moduleFuns mainFun = makeAnomaFun
<$> [(f ^. compilerFunctionName, runCompilerFunction compilerCtx f) | f <- libFuns]
)

exportEnv :: Term Natural
exportEnv = Str.theFunctionsLibrary @ makeList compiledFuns
funcsLib :: Term Natural
funcsLib = Str.theFunctionsLibrary @ makeList compiledFuns

makeLibraryFunction :: (Text, Term Natural) -> Term Natural
makeLibraryFunction (funName, c) =
Expand Down Expand Up @@ -779,24 +779,24 @@ runCompilerWith opts constrs moduleFuns mainFun = makeAnomaFun
}
)

-- Replaces all instances of functionsLibraryPlaceHolder by the actual
-- functions library. Note that the functions library will have
-- functionsLibraryPlaceHolders, but this is not an issue because they
-- are not directly accessible from anoma so they'll never be entrypoints.
substFuncsLib :: Term Natural -> Term Natural
substFuncsLib = \case
TermAtom a
| a ^. atomHint == Just AtomHintFunctionsPlaceholder -> funcsLib
| otherwise -> TermAtom a
TermCell (Cell' l r i) ->
-- note that we do not need to recurse into terms inside the CellInfo because those terms will never be an entry point from anoma
TermCell (Cell' (substFuncsLib l) (substFuncsLib r) i)

makeAnomaFun :: AnomaResult
makeAnomaFun =
AnomaResult
{ _anomaClosure = substEnv mainClosure
{ _anomaClosure = substFuncsLib (substFuncsLib mainClosure)
}
where
-- Replaces all instances of functionsLibraryPlaceHolder by the actual
-- functions library. Note that the functions library will have
-- functionsLibraryPlaceHolders, but this is not an issue because they
-- are not directly accessible from anoma so they'll never be entrypoints.
substEnv :: Term Natural -> Term Natural
substEnv = \case
TermAtom a
| a ^. atomHint == Just AtomHintFunctionsPlaceholder -> exportEnv
| otherwise -> TermAtom a
TermCell (Cell' l r i) ->
-- note that we do not need to recurse into terms inside the CellInfo because those terms will never be an entry point from anoma
TermCell (Cell' (substEnv l) (substEnv r) i)

functionsLibraryPlaceHolder :: Term Natural
functionsLibraryPlaceHolder =
Expand Down
Loading