Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add nockma evaluator #2564

Merged
merged 38 commits into from
Jan 11, 2024
Merged

Add nockma evaluator #2564

merged 38 commits into from
Jan 11, 2024

Conversation

paulcadman
Copy link
Collaborator

@paulcadman paulcadman commented Dec 12, 2023

This PR adds an parser, pretty printer, evaluator, repl and quasi-quoter for Nock terms.

Parser / Pretty Printer

The parser and pretty printer handle both standard Nock terms and 'pretty' Nock terms (where op codes and paths can be named). Standard and pretty Nock forms can be mixed in the same term.

For example instead of [0 2] you can write [@ L].

See

instance Pretty NockOp where
for the correspondence between pretty Nock and Nock operators.

In pretty Nock, paths are represented as strings of L (for head) and R (for tail) instead of the number encoding in standard nock. The character S is used to refer to the whole subject, i.e it is sugar for 1 in standard Nock.

See

encodePath :: Path -> EncodedPath
for the correspondence between pretty Nock path and standard Nock position.

Quasi-quoter

A quasi-quoter is added so Nock terms can be included in the source, e.g [nock| [@ LL] |].

REPL

Launch the repl with juvix dev nockma repl.

A Nock [subject formula] cell is input as subject / formula , e.g:

nockma>  [1 0] / [@ L]
1

The subject can be set using :set-stack.

nockma> :set-stack [1 0]
nockma> [@ L]
1

The subject can be viewed using :get-stack.

nockma> :set-stack [1 0]
nockma> :get-stack
[1 0]

You can assign a Nock term to a variable and use it in another expression:

nockma> r := [@ L]
nockma> [1 0] / r
1

A list of assignments can be read from a file:

$ cat stack.nock
r := [@ L]
$ juvix dev nockma repl
nockma> :load stack.nock
nockma> [1 0] / r
1

import Juvix.Compiler.Nockma.Translation.FromSource.QQ
import Juvix.Prelude

stdlib :: Term Natural
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't seem to be used anywhere. Is it used for compilation? I think it might be a pain to keep it up-to-date with the actual Nockma stdlib. Maybe a better solution is to have an extra instruction StdLibCall with an enum of functions and translate them to library calls only at serialization, and implement them directly in Haskell for the interpreter?

@paulcadman paulcadman merged commit a9995b8 into main Jan 11, 2024
4 checks passed
@paulcadman paulcadman deleted the nockma-eval branch January 11, 2024 12:04
@paulcadman paulcadman mentioned this pull request Jan 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Nock language and evaluator
3 participants