mirror of
https://github.com/anoma/juvix.git
synced 2024-12-13 11:16:48 +03:00
b981405e45
When we first implemented the Nockma backend we wrongly assumed that the only entry point for Juvix compiled Nockma modules would be the main function. Using this assumption we could add a setup step in the main function that put the Anoma stdlib and compiled functions from the Juvix module in a static place in the Nockma subject. References to the Anoma stdlib and functions in the module could then be resolved statically. However, one of the use cases for Juvix -> Nockma compilation is for Anoma to run logic functions that are fields of a transaction. So the user writes a Juvix program with main function that returns a transaction. The result of the main function is passed to Anoma. When Anoma calls the logic function on a field of the transaction, the setup part of the main function is not run so the subject is not in the required state. In fact, the logic function is not even callable by Anoma because non-main functions in the Juvix module use a calling convention that assumes the subject has a particular shape. This PR solves the problem by making all functions in the Juvix module use the Anoma calling convention. We make all compiled closures (including, for example, the logic functions stored on resources in a transaction) self contained, i.e they contain the functions library and anoma standard library. Modules that contain many closures produce large nockma output files which slows down the evaluator. This will need to be fixed in the future either with Nockma compression ([jam serialization](https://developers.urbit.org/reference/hoon/stdlib/2p)) or otherwise. But it does not block the compilation and execution of Anoma transactions. Other fixes / additions: * Extra tracing. You can now annotate output cells with a tag that will be displayed in the output * Unittests for listToTuple, appendRights helper functions * Fixes for the nockma parser when parsing 'pretty nockma', specifically stdlib calls, tags and functions_library atom. * Adds `juvix dev nock run` command that can run a program output with the `anoma` target. * Remove the `nockma` target. As described above we always use the Anoma calling convention so there's no need for a separate target for the 'juvix calling convention' * Adds a `--profile` flag to `juvix dev nock run` which outputs a count of Nockma ops used in the evaluation * In tests we no longer serialise the compiled program to force full evaluation of the compiled code. We added a negative test to check that strings are not allowed in Nockma/Anoma programs, it is output in a file `OUTPUT.profile` and has the following form: ``` quote : 15077 apply : 0 isCell : 0 suc : 0 = : 4517 if : 5086 seq : 5086 push : 0 call : 4896 replace : 1 hint : 8 scry : 0 trace : 0 ``` --------- Co-authored-by: Jan Mas Rovira <janmasrovira@gmail.com>
16 lines
523 B
Haskell
16 lines
523 B
Haskell
module Commands.Dev.Nockma where
|
|
|
|
import Commands.Base
|
|
import Commands.Dev.Nockma.Eval as Eval
|
|
import Commands.Dev.Nockma.Format as Format
|
|
import Commands.Dev.Nockma.Options
|
|
import Commands.Dev.Nockma.Repl as Repl
|
|
import Commands.Dev.Nockma.Run as Run
|
|
|
|
runCommand :: forall r. (Members '[EmbedIO, App] r) => NockmaCommand -> Sem r ()
|
|
runCommand = \case
|
|
NockmaRepl opts -> Repl.runCommand opts
|
|
NockmaEval opts -> Eval.runCommand opts
|
|
NockmaFormat opts -> Format.runCommand opts
|
|
NockmaRun opts -> Run.runCommand opts
|