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

Serialize Nockma output using nock jam #3066

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
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
7 changes: 4 additions & 3 deletions app/Commands/Compile/Anoma.hs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module Commands.Compile.Anoma where
import Commands.Base
import Commands.Compile.Anoma.Options
import Commands.Extra.NewCompile
import Juvix.Compiler.Nockma.Encoding.Jam qualified as Encoding
import Juvix.Compiler.Nockma.Pretty qualified as Nockma
import Juvix.Compiler.Nockma.Translation.FromTree qualified as Nockma

Expand All @@ -25,9 +26,9 @@ runCommand opts = do
res <- getRight r
outputAnomaResult (opts' ^. compileDebug) nockmaFile res

outputAnomaResult :: (Members '[EmbedIO, App] r) => Bool -> Path Abs File -> Nockma.AnomaResult -> Sem r ()
outputAnomaResult :: (Members '[EmbedIO, App, Files] r) => Bool -> Path Abs File -> Nockma.AnomaResult -> Sem r ()
outputAnomaResult debugOutput nockmaFile Nockma.AnomaResult {..} = do
let code = Nockma.ppSerialize _anomaClosure
let code = Encoding.jamToByteString _anomaClosure
prettyNockmaFile = replaceExtensions' [".debug", ".nockma"] nockmaFile
writeFileEnsureLn nockmaFile code
writeFileBS nockmaFile code
when debugOutput (writeFileEnsureLn prettyNockmaFile (Nockma.ppPrint _anomaClosure))
4 changes: 4 additions & 0 deletions src/Juvix/Compiler/Nockma/Encoding/Jam.hs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@ jamToBits =
. evalState (initJamState @a)
. jamSem

-- | jam encode a Nock term to the bytes encoding of an atom
jamToByteString :: forall a. (Integral a, Hashable a) => Term a -> ByteString
jamToByteString = vectorBitsToByteString . jamToBits

-- | jam encode a Nock term to an atom
jam :: forall a r. (Integral a, Hashable a, NockNatural a, Member (Error (ErrNockNatural a)) r) => Term a -> Sem r (Atom a)
jam t = do
Expand Down
Loading