Skip to content

Conversation

@bonbud-macryg
Copy link
Contributor

@bonbud-macryg bonbud-macryg commented Aug 18, 2025

MVP documentation for UrWasm; doesn't include threads-js.

Adds an overview and tutorial to "Build on Urbit", to which threads-js and hooks tutorials can be added later. Also adds data types and library reference to the %base docs, to which the rest the %base desk can be added later.

@bonbud-macryg bonbud-macryg mentioned this pull request Aug 18, 2025
@bonbud-macryg bonbud-macryg marked this pull request as ready for review August 18, 2025 14:17
@bonbud-macryg
Copy link
Contributor Author

Ready for review @quodss

@dozreg-toplud dozreg-toplud self-assigned this Aug 18, 2025

Since Lia's `+run-once` returns a pair of \[yield accumulator], we grab the yield with [`=<`](../../../hoon/rune/tis.md#tisgal) to get the head (`-`) of the result. `+yield-need` is a Lia function that asserts that a yield is successful and returns the unwrapped result.

Below, we build Lia's `+run-once` core and run it on our imported `.wasm-bin` module, which we give the empty argument `[~ ~]`. (That is, a pair of the initial accumulator state and a map of imports.) The `%$` is where we'd specify a runtime hint like `%bout`, but we stub it out here as we don't need it.
Copy link
Contributor

Choose a reason for hiding this comment

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

Not quite: we initialize a +run-once gate by passing it the molds of the yield and the accumulator, and then we pass it several arguments:

  1. wasm-bin binary;
  2. pair of the initial value of the accumulator and the map of imports [~ ~];
  3. hint value, which is ignored in +run-once case, so we default to %$. It is NOT a "runtime hint like %bout", it is a jet hint. +run-once jet only recognizes %none, which makes the jet punt and it is used for testing/debugging.
  4. The script itself, defined below

The text makes it look like we are in some imperative environment: we run +run-once with wasm-bin and the empty argument, and then we write some regular Hoon. No, the script below is one of the arguments for (run-once yil-mold acc-mold) gate

::
:: build Lia's +run-once core with our .yil-mold
:: and .acc-mold and run it with our .wasm-bin, which
:: will be given the empty state [~ ~]
Copy link
Contributor

Choose a reason for hiding this comment

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

Here and elsewhere the comments should follow the convention layed out here https://docs.urbit.org/hoon/style#comment-conventions:

::  comment is separated from code below
::
(add 2 2)

=, arr
```

We'll measure the input list and concatonate all of its elements into a single atom with [`+rep`](../../../hoon/stdlib/2c.md#rep).
Copy link
Contributor

Choose a reason for hiding this comment

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

concatonate typo

;< vec-out=octs try:m (memread &1.ptr-len (mul 8 &2.ptr-len))
```

Now we split the resulting octets atom (`$octs`, a cell of byte length and data) into a list of 64-bit atoms with [`+rip`](../../../hoon/stdlib/2c.md) and add missing trailing zeroes if necessary. (Note that UrWasm's [`+rope`](../../../urbit-os/base/wasm/lib-wasm-runner-op-def.md#rope) "BROKEN_LINK" would preserve the zeroes.)
Copy link
Contributor

Choose a reason for hiding this comment

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

(Note that UrWasm's [+rope] ... would preserve the zeroes.

This is a reference to a gate internal to Urwasm development. No need to have a link to it here

~
```

This is a ~10x speedup compared to the pure Hoon implementation.
Copy link
Contributor

Choose a reason for hiding this comment

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

This ratio might be a bit less in light of urbit/vere#836 merged, which sped up comparison jets.

Copy link
Contributor

Choose a reason for hiding this comment

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

if you don't mind, you could bench that again

- [Wasm parser](./lib-wasm-parser.md)
- [Wasm validator](./lib-wasm-validator.md)
- [Wasm operator definitions](./lib-wasm-runner-op-def.md)
- [Wasm interpreter](./wasm-interpreter-data-types.md)
Copy link
Contributor

Choose a reason for hiding this comment

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

this was probably meant to be a link to lib-wasm-runner-engine.md

(each (script-raw-form (list lia-value) *) (list lia-value))
```

Input type for [`+run`](#run). Either a new script to execute or cached values from previous execution.
Copy link
Contributor

Choose a reason for hiding this comment

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

the second option is not cached values but a resolved external call


Returns the script yield and final accumulator state.

### `+init:run-once` {#init-run-once}
Copy link
Contributor

Choose a reason for hiding this comment

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

this is internal to jetted +run-once and would not be called from outside


Stateful execution of a Wasm module. Can be used to run a new script or resume computation with the provided `$seed` state.

### `+init` {#init-run}
Copy link
Contributor

Choose a reason for hiding this comment

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

same as above

^- form:m
```

Calls an external (import) function. If no cached result is available, yields the function call request to the host environment. Otherwise returns the cached result.
Copy link
Contributor

Choose a reason for hiding this comment

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

First usage of "cached result" confused me but now I see a point, I guess it's fine

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants