1
1
mirror of https://github.com/anoma/juvix.git synced 2024-12-18 12:21:46 +03:00
juvix/scripts/nockma-stdlib-parser.sh

20 lines
613 B
Bash
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
#!/usr/bin/env bash
#
# Description:
# A script that extracts the Nock locations of functions from comments in the the
# anoma.hoon standard library:
#
# For example we want to extract the location "342" for the function dec.:
# https://github.com/anoma/anoma/blob/9904ff81218c1a690027a481beb0b6d39e378a07/hoon/anoma.hoon#L12
# ```
# ++ dec :: +342
# ```
#
# Usage:
# chmod +x nockma-stdlib-parser.sh
# ./nockma-stdlib-parser.sh < anoma.hoon
# Use grep to find lines matching the pattern and awk to format the output
# Reads from stdin
grep -oP '\+\+ \K\w+\s+::\s+\+\d+' | awk '{gsub(":: \\+", ""); print}'