1
1
mirror of https://github.com/anoma/juvix.git synced 2024-12-04 17:07:28 +03:00
juvix/test/Nockma/Compile.hs

8 lines
171 B
Haskell
Raw Normal View History

Nockma compile (#2570) This PR is a snapshot of the current work on the JuvixAsm -> Nockma translation. The compilation of Juvix programs to Nockma now works so we decided to raise this PR now to avoid it getting too large. ## Juvix -> Nockma compilation You can compile a frontend Juvix file to Nockma as follows: example.juvix ``` module example; import Stdlib.Prelude open; fib : Nat → Nat → Nat → Nat | zero x1 _ := x1 | (suc n) x1 x2 := fib n x2 (x1 + x2); fibonacci (n : Nat) : Nat := fib n 0 1; sumList (xs : List Nat) : Nat := for (acc := 0) (x in xs) acc + x; main : Nat := fibonacci 9 + sumList [1; 2; 3; 4]; ``` ``` $ juvix compile -t nockma example.juvix ``` This will generate a file `example.nockma` which can be run using the nockma evaluator: ``` $ juvix dev nockma eval example.nockma ``` Alternatively you can compile JuvixAsm to Nockma: ``` $ juvix dev asm compile -t nockma example.jva ``` ## Tests We compile an evaluate the JuvixAsm tests in https://github.com/anoma/juvix/blob/cb3659e08e552ee9ca40860077e39a4070cf3303/test/Nockma/Compile/Asm/Positive.hs We currently skip some because either: 1. They are too slow to run in the current evaluator (due to arithmetic operations using the unjetted nock code from the anoma nock stdlib). 2. They trace data types like lists and booleans which are represented differently by the asm interpreter and the nock interpreter 3. They operate on raw negative numbers, nock only supports raw natural numbers ## Next steps On top of this PR we will work on improving the evaluator so that we can enable the slow compilation tests. --------- Co-authored-by: Paul Cadman <git@paulcadman.dev> Co-authored-by: Lukasz Czajka <lukasz@heliax.dev>
2024-01-17 13:15:38 +03:00
module Nockma.Compile where
import Base
import Nockma.Compile.Tree.Positive qualified as Tree
Nockma compile (#2570) This PR is a snapshot of the current work on the JuvixAsm -> Nockma translation. The compilation of Juvix programs to Nockma now works so we decided to raise this PR now to avoid it getting too large. ## Juvix -> Nockma compilation You can compile a frontend Juvix file to Nockma as follows: example.juvix ``` module example; import Stdlib.Prelude open; fib : Nat → Nat → Nat → Nat | zero x1 _ := x1 | (suc n) x1 x2 := fib n x2 (x1 + x2); fibonacci (n : Nat) : Nat := fib n 0 1; sumList (xs : List Nat) : Nat := for (acc := 0) (x in xs) acc + x; main : Nat := fibonacci 9 + sumList [1; 2; 3; 4]; ``` ``` $ juvix compile -t nockma example.juvix ``` This will generate a file `example.nockma` which can be run using the nockma evaluator: ``` $ juvix dev nockma eval example.nockma ``` Alternatively you can compile JuvixAsm to Nockma: ``` $ juvix dev asm compile -t nockma example.jva ``` ## Tests We compile an evaluate the JuvixAsm tests in https://github.com/anoma/juvix/blob/cb3659e08e552ee9ca40860077e39a4070cf3303/test/Nockma/Compile/Asm/Positive.hs We currently skip some because either: 1. They are too slow to run in the current evaluator (due to arithmetic operations using the unjetted nock code from the anoma nock stdlib). 2. They trace data types like lists and booleans which are represented differently by the asm interpreter and the nock interpreter 3. They operate on raw negative numbers, nock only supports raw natural numbers ## Next steps On top of this PR we will work on improving the evaluator so that we can enable the slow compilation tests. --------- Co-authored-by: Paul Cadman <git@paulcadman.dev> Co-authored-by: Lukasz Czajka <lukasz@heliax.dev>
2024-01-17 13:15:38 +03:00
allTests :: TestTree
allTests = testGroup "Nockma compile" [Tree.allTests]