WebAssembly Text Format (.WAT)

So I've been thinking about making a JS-NATIVE variant which makes it so you can write WebAssembly directly as the body of a function.

Looking at the WebAssembly Text Format, it seems Ren-C is rather well-geared to be able to just LOAD it.

(module
  (table 2 funcref)
  (func $f1 (result i32)
    i32.const 42)
  (func $f2 (result i32)
    i32.const 13)
  (elem (i32.const 0) $f1 $f2)
  (type $return_i32 (func (result i32)))
  (func (export "callByIndex") (param $i i32) (result i32)
    local.get $i
    call_indirect (type $return_i32))
)

It's cool to be able to have that "just work" and wind up with a code format that you can manipulate, compose, process, analyze... all using mechanisms that are a sunk cost.

Historical Rebol didn't have $var-words and tu.ple (Redbol allows dots in names, so something like i32.const would be legal, but you'd have no particular conveniences to pick it apart.

Here's the full grammar.

I've seen some examples where the symbols have more embedded $ signs, like $FUNCSIG$ii:

(module
 (type $FUNCSIG$ii (func (param i32) (result i32)))
 (import "env" "puts" (func $puts (param i32) (result i32)))
 (table 0 anyfunc)
 (memory $0 1)
 (data (i32.const 16) "Hello World\00")
..........further text....
..........

It occurs to me that we can allow this--kind of like how we allow embedded apostrophes--or apostrophes at the tail of words.

>> word: first [f$]
== f$

>> word? word
== ~true~  ; anti

>> to var-word! word
== $f$

It's ugly but if it doesn't create any mechanical paradoxes or contradictions.

What can't be legal is things like $ or $$ as a WORD!, because you start down a rabbit hole of asking if $$ is its own WORD! or the VAR-WORD! variation of $. So you can't have a leading $ followed by another $. But other limits are arbitrary...and here's a reason to allow them.

1 Like

WebAssembly uses semicolons for comments, so it really is darn near loadable.

With backtick literals, we would free $NUM to be a different type from MONEY!, which sounds very good to me, because I've been wanting dollar-number for other things.

I'm assuming this is hex. But if it didn't act numerically, it wouldn't matter. Hex is a superset notationally of decimal, and you could use DEHEX instead of TO INTEGER! to convert it.

>> to integer! $10
== 10

>> dehex $10
== 16

>> to integer! $1000DECAFBAD2000
** Error: Non-Decimal Digit

Of course you're competing with VAR-WORD! here, but it could offer dehex too.

>> dehex $F
== 15

WebAssembly also has weird things like:

(f32.const -0x0p+0)

You can get ugly FUSED! things out of that, or hex denoted like 0x10DECAFBAD20, which don't make any real sense but you don't have to make sense. Just turn the FUSED! into a TEXT! and process it. (Or TO BINARY!, and if you give TO BINARY! a fused it will see what it can do for you.)

FUSED! seems like a compromise for those who wanted non-LOADable things to load as some mystery thing to decode (what Geomol called KWATZ!). How it breaks into parts may or may not be meaningful. If it's meaningful, great--leverage that. If it's not, convert it and process what you convert it to.