Skip to content

Commit

Permalink
Fix closure representation in the Nock backend (#3105)
Browse files Browse the repository at this point in the history
* Closes #3083 
* Closes #3042 

The representation of closures is changed to make it more efficient and
compatible with the Nock calling convention.
  • Loading branch information
lukaszcz authored Oct 18, 2024
1 parent c238429 commit 5d32e8f
Show file tree
Hide file tree
Showing 3 changed files with 155 additions and 209 deletions.
14 changes: 14 additions & 0 deletions src/Juvix/Compiler/Nockma/Language.hs
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,14 @@ makeLenses ''WithStack
makeLenses ''AtomInfo
makeLenses ''CellInfo

isCell :: Term a -> Bool
isCell = \case
TermCell {} -> True
_ -> False

isAtom :: Term a -> Bool
isAtom = not . isCell

atomHint :: Lens' (Atom a) (Maybe AtomHint)
atomHint = atomInfo . atomInfoHint

Expand Down Expand Up @@ -460,6 +468,12 @@ opAddress txt p = TermCell (txt @ OpAddress #. p)
opQuote :: (IsNock x) => Text -> x -> Term Natural
opQuote txt p = TermCell (txt @ OpQuote #. p)

opTrace :: Term Natural -> Term Natural
opTrace val = OpHint # (nockHintAtom NockHintPuts # val) # val

opTrace' :: Term Natural -> Term Natural -> Term Natural
opTrace' msg val = OpHint # (nockNilTagged "opTrace'" # msg) # val

{-# COMPLETE Cell #-}

pattern Cell :: Term a -> Term a -> Cell a
Expand Down
Loading

0 comments on commit 5d32e8f

Please sign in to comment.