This post describes how we call Anoma stdlib functions from Juvix and how we obtain Anoma stdlib function specifications.
I made this in preparation for a meeting with @cwgoes @ArtemG @ray @mariari to discuss this topic.
Calling Anoma Stdlib From Juvix
We compile a Anoma stdlib function application:
anoma-fn args
to the following nock:
[8
[7 [0 anoma-lib-position] get-anoma-fn]
9 2 6 [10 7 [0 3] get-args] 0 2]
where:
anoma-lib-position
is the position ofanoma-lib
in the original subject.get-anoma-fn
is a Nock term that evaluates to the Nock representation ofanoma-fn
when the subject is exactlyanoma-lib
.get-args
is a Nock term that evaluates to the applicationargs
in the original subject.- The original subject is the subject before this nock code is evaluated.
anoma-lib
is the Nock code for the Anoma standard library.
Anoma Stdlib Calling Specification
To call a function in the Anoma stdlib we need to know:
- Its signature (and semantics).
- The
get-anoma-fn
Nock code, as described in the previous section.
We currently compute get-anoma-fn
using the Urbit dojo and paste the results into the Juvix compiler code:
Examples
NB: The get-anoma-fn
are correct when evaluated against this version of the Anoma resource machine code.
Name | get-anoma-fn |
Signature | Description |
---|---|---|---|
Decrement | [9 342 0 511] |
UAtom -> UAtom |
This function decrements its argument |
Add | [9 20 0 511] |
UAtom -> UAtom -> UAtom |
This function adds two unsigned atoms |
Concatenate bytes | [8 [9 10 0 63] 9 4 10 [6 7 [0 3] 1 3] 0 2] |
Bytes -> Bytes -> Bytes |
This function concatenates two atoms that represent LE byte ordering |
PRNG init | [8 [1 0] [1 8 [9 47 0 31] 10 [6 0 14] 0 2] 0 1] |
Atom -> PRNG |
This function initializes a PRNG from a seed |
PRNG next bytes | [8 [1 0 0] [1 8 [7 [0 12] 9 4 0 1] 9 2 10 [6 0 29] 0 2] 0 1] |
PRNG -> UAtom -> Bytes |
This function generates n bytes of data (given by the second argument) from the given PRNG. The bytes are encoded as an Atom using LE byte ordering. |
We also may use functions that are composed from other standard library functions which are useful.
Name | get-anoma-fn |
Signature | Description |
---|---|---|---|
Bytes length | see nock code | Bytes -> UAtom |
Compute the number of bytes in the given bytes atom |
Current method for finding get-anoma-fn
We currently load the standard library hoon file into the Urbit dojo and paste hoon code snippets into it. We then copy the resulting Nock into the Juvix compiler source.