Feeding the Snake
compiler-string-builtins

Add string builtins to the compiler. str_len, str_addr, and print_str need WAT implementations.

str_len(s) compiles to: s, then i64.const 65536, then i64.rem_s.
str_addr(s) compiles to: s, then i64.const 65536, then i64.div_s.

For print_str, we'll import a host function from the runtime:

(import "env" "print_str" (func $print_str (param i32) (param i32)))

The import goes at the top of the module. The compiler decomposes the packed string into (addr, len) and calls the imported function.