Skip to content

Commit

Permalink
Update Anoma nock stdlib and use pow2 in appendRights
Browse files Browse the repository at this point in the history
The Nock stdlib now has multiple layers. We now use a Nock term to
to fetch each stdlib symbol's code because this can be obtained from
Urbit's dojo,

for example:

    > =>  anoma  !=(add)
    [9 20 0 15]

where `anoma` is the symbol where the anoma stdlib is loaded.

The stdlib is the Nock code associated with https://github.com/anoma/anoma/blob/6a4e15fe9c356225034f38445ce0eace2b43ab5e/hoon/anoma.hoon

The new stdlib contains the pow2 function, so we can replace our own
implementation.

The append rights function has been inlined.

This commit also adds unit tests for the stdlib / appendRights
functions. The tests use the evaluator with 'interceptStdlibCalls' both
enabled and disabled.
  • Loading branch information
paulcadman authored and lukaszcz committed Feb 8, 2024
1 parent ca0ba4f commit 90752c9
Show file tree
Hide file tree
Showing 7 changed files with 89 additions and 384 deletions.
1 change: 1 addition & 0 deletions src/Juvix/Compiler/Nockma/Evaluator.hs
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ eval inistack initerm =
StdlibMod -> binArith mod
StdlibLt -> binCmp (<)
StdlibLe -> binCmp (<=)
StdlibPow2 -> unaArith (2 ^)

goAutoConsCell :: AutoConsCell a -> Sem r (Term a)
goAutoConsCell c = do
Expand Down
11 changes: 0 additions & 11 deletions src/Juvix/Compiler/Nockma/Language.hs
Original file line number Diff line number Diff line change
Expand Up @@ -332,17 +332,6 @@ infixl 1 >>#
(>>#) :: (IsNock x, IsNock y) => x -> y -> Term Natural
a >># b = TermCell (a >>#. b)

stdlibNumArgs :: StdlibFunction -> Natural
stdlibNumArgs = \case
StdlibDec -> 1
StdlibAdd -> 2
StdlibSub -> 2
StdlibMul -> 2
StdlibMod -> 2
StdlibDiv -> 2
StdlibLe -> 2
StdlibLt -> 2

{-# COMPLETE Cell #-}

pattern Cell :: Term a -> Term a -> Cell a
Expand Down
295 changes: 0 additions & 295 deletions src/Juvix/Compiler/Nockma/Stdlib.hs
Original file line number Diff line number Diff line change
Expand Up @@ -326,298 +326,3 @@ stdlib =
909
]
|]

oldstdlib :: Term Natural
oldstdlib =
[nock|
[ [ [ 7
[ 8
[1 1 1]
[ 1
8
[1 0]
8
[ 1
6
[5 [1 0] 0 60]
[0 6]
9
2
10
[60 8 [9 342 0 31] 9 2 10 [6 0 124] 0 2]
10
[6 8 [9 20 0 31] 9 2 10 [6 [0 125] 0 14] 0 2]
0
1
]
9
2
0
1
]
0
1
]
11
[1.953.718.630 1 7.107.949 [0 7] 0]
0
1
]
[ [ 7
[ 8
[1 0 0]
[ 1
6
[5 [1 0] 0 12]
[0 13]
9
2
10
[6 [8 [9 342 0 7] 9 2 10 [6 0 28] 0 2] 4 0 13]
0
1
]
0
1
]
11
[1.953.718.630 1 6.579.297 [0 7] 0]
0
1
]
[ [ 7
[ 8
[1 0 0]
[ 1
6
[5 [0 12] 0 13]
[1 0]
6
[8 [9 343 0 7] 9 2 10 [6 [0 28] 0 29] 0 2]
[1 0]
1
1
]
0
1
]
11
[1.953.718.630 1 6.648.940 [0 7] 0]
0
1
]
[ 7
[ 8
[1 1 1]
[ 1
6
[5 [1 0] 0 13]
[0 0]
8
[1 0]
8
[ 1
6
[8 [9 343 0 31] 9 2 10 [6 [0 124] 0 125] 0 2]
[0 6]
9
2
10
[60 8 [9 47 0 31] 9 2 10 [6 [0 124] 0 125] 0 2]
10
[6 4 0 6]
0
1
]
9
2
0
1
]
0
1
]
11
[1.953.718.630 1 7.760.228 [0 7] 0]
0
1
]
[ 7
[ 8
[1 0]
[ 1
6
[5 [1 0] 0 6]
[0 0]
8
[1 0]
8
[1 6 [5 [0 30] 4 0 6] [0 6] 9 2 10 [6 4 0 6] 0 1]
9
2
0
1
]
0
1
]
11
[1.953.718.630 1 6.514.020 [0 7] 0]
0
1
]
7
[ 8
[1 0 0]
[ 1
6
[6 [5 [0 12] 0 13] [1 1] 1 0]
[ 6
[ 8
[ 1
6
[5 [1 0] 0 28]
[1 0]
6
[ 6
[6 [5 [1 0] 0 29] [1 1] 1 0]
[ 6
[ 9
2
10
[ 14
[8 [9 342 0 15] 9 2 10 [6 0 60] 0 2]
8
[9 342 0 15]
9
2
10
[6 0 61]
0
2
]
0
1
]
[1 0]
1
1
]
1
1
]
[1 0]
1
1
]
9
2
0
1
]
[1 0]
1
1
]
1
1
]
0
1
]
11
[1.953.718.630 1 6.845.548 [0 7] 0]
0
1
]
7
[8 [1 0 0] [1 6 [8 [9 84 0 7] 9 2 10 [6 [0 28] 0 29] 0 2] [1 1] 1 0] 0 1]
11
[1.953.718.630 1 6.845.543 [0 7] 0]
0
1
]
[ 7
[ 8
[1 0 0]
[1 6 [8 [9 343 0 7] 9 2 10 [6 [0 28] 0 29] 0 2] [1 1] 1 0]
0
1
]
11
[1.953.718.630 1 6.648.935 [0 7] 0]
0
1
]
[ 7
[ 8
[1 1 1]
[ 1
6
[5 [1 0] 0 13]
[0 0]
8
[9 47 0 7]
9
2
10
[ 6
[0 28]
7
[0 3]
8
[9 4 0 7]
9
2
10
[6 [0 29] 7 [0 3] 8 [9 170 0 7] 9 2 10 [6 [0 28] 0 29] 0 2]
0
2
]
0
2
]
0
1
]
11
[1.953.718.630 1 6.582.125 [0 7] 0]
0
1
]
7
[ 8
[1 0 0]
[ 1
6
[5 [1 0] 0 13]
[0 12]
9
2
10
[ 6
[8 [9 342 0 7] 9 2 10 [6 0 28] 0 2]
8
[9 342 0 7]
9
2
10
[6 0 29]
0
2
]
0
1
]
0
1
]
11
[1.953.718.630 1 6.452.595 [0 7] 0]
0
1
]
[0 3]
909
]
|]
24 changes: 1 addition & 23 deletions src/Juvix/Compiler/Nockma/StdlibFunction.hs
Original file line number Diff line number Diff line change
Expand Up @@ -19,26 +19,4 @@ stdlibPath = \case
StdlibMod -> [nock| [9 46 0 15] |]
StdlibLe -> [nock| [9 84 0 15] |]
StdlibLt -> [nock| [9 343 0 15] |]

oldstdlibPath :: StdlibFunction -> Term Natural
oldstdlibPath = \case
StdlibDec -> [nock| [9 342 0 1] |]
StdlibAdd -> [nock| [9 20 0 1] |]
StdlibSub -> [nock| [9 47 0 1] |]
StdlibMul -> [nock| [9 4 0 1] |]
StdlibDiv -> [nock| [9 170 0 1] |]
StdlibMod -> [nock| [9 46 0 1] |]
StdlibLe -> [nock| [9 84 0 1] |]
StdlibLt -> [nock| [9 343 0 1] |]

reallyoldstdlibPath :: StdlibFunction -> Path
reallyoldstdlibPath =
decodePath' . EncodedPath . \case
StdlibDec -> 342
StdlibAdd -> 20
StdlibSub -> 47
StdlibMul -> 4
StdlibDiv -> 170
StdlibMod -> 46
StdlibLe -> 84
StdlibLt -> 343
StdlibPow2 -> [nock| [9 4 0 1] |]
28 changes: 28 additions & 0 deletions src/Juvix/Compiler/Nockma/StdlibFunction/Base.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
module Juvix.Compiler.Nockma.StdlibFunction.Base where

import Juvix.Prelude hiding (Atom, Path)
import Juvix.Prelude.Pretty

instance Pretty StdlibFunction where
pretty = \case
StdlibDec -> "dec"
StdlibAdd -> "add"
StdlibSub -> "sub"
StdlibMul -> "mul"
StdlibDiv -> "div"
StdlibMod -> "mod"
StdlibLt -> "<"
StdlibLe -> "<="
StdlibPow2 -> "pow2"

data StdlibFunction
= StdlibDec
| StdlibAdd
| StdlibSub
| StdlibMul
| StdlibDiv
| StdlibMod
| StdlibLt
| StdlibLe
| StdlibPow2
deriving stock (Show, Lift, Eq, Bounded, Enum)
Loading

0 comments on commit 90752c9

Please sign in to comment.