Add support for Strings in the Anoma backend #2789
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR adds support for the
String
type, String literals and string concatenation to the Nockma backend. Support for the builtinsshow
andintToString
is not supported.Example
test079.juvix
args.nockma
String representation
A String is a sequence of UTF-8 encoded bytes. We interpret these bytes as a sequence of bits to represent the string as an integer atom in nockma.
For example:
The string
"a"
is UTF-8 encoded as97
which is0b1100001
in bits.The string
"ab"
is UTF-8 encoded at the pair of bytes:97 98
which is0b1100001 0b1100010
.When we combine the bytes into a single sequence of bits we must take care to pad each binary representation with zeros to each byte boundary.
So the binary representation of
"ab"
as an atom is0b110000101100010
or24930
as an integer atom.String concatenation
We use the cat function in the Anoma stdlib to concatenate the bytes representing two strings.
We need to use the block parameter
3
in the Anoma call because we want to treat the atoms representing the strings as sequences of bytes (= 2^3 bits).To find the relevant Nock code to call
cat
with block parameter3
we use the urbit dojo as follows:Stdlib intercept in Evaluator
The evaluator has support for strings using
AtomHint
s, so strings can be printed and traced. The stdlibcat
call is also intercepted because evaluating the unjetted hoon version is slow.String support in pretty nockma
In a pretty nockma file or
nock
quasi-quote you can write double quoted string literals, e.g "abc". These are automatically translated to UTF-8 integer atoms as in the previous section.