Calling Anoma Stdlib From Juvix

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 of anoma-lib in the original subject.
  • get-anoma-fn is a Nock term that evaluates to the Nock representation of anoma-fn when the subject is exactly anoma-lib.
  • get-args is a Nock term that evaluates to the application args 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:

  1. Its signature (and semantics).
  2. 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.

Going to write a quick summary of the results coming out of the meeting connected to this post so that we have some write-up:

  • @ray mentioned that some of the calling conventions in the above post may be a bit nonstandard. He wanted to provide a comment here.
  • The fact that Juvix has to deal with many layers of coordination for dealing with their compiled Nock code is evident.
    • Long term solution: defnock, a WIP.
    • Short term solution: better documentation, i.e. document all calling conventions that Juvix needs on the Node’s side, so that Juvix does not have to interact with Urbit/Hoon that much.
    • Problem: might still be a human error somewhere, as a lot of copy-pasting is involved.
      • Proposed solution: Node will write up their own examples calling code in the shape of the Juvix compiler, so that Juvix can beforehand be sure that the indices/calling conventions match what they need. This may solve the problem of e.g. defining things that are trivial like bytes length above from the Juvix side. Instead, Juvix will simply tell us “oh, bytes length is not in the standard library, but we need that function” and we say “ok, it probably shouldn’t be part of the Nockma standard library but I can give you the needed code for it” and include it in the examples.

Further coordination to be done at the Hacker House.

2 Likes