Cannot manually import procedures with inline WAT
Opened this issue · 0 comments
angelcaru commented
Context
I am currently building a WASM layer for p5.js and, just for fun, I wanted to add Porth support. However, I am running into an issue with importing one of my functions. Since print
is a Porth intrinsic, I could not import a procedure with the same name. So I resorted to this:
wasm
"(import \"env\" \"print\" (func $print (param i32)))"
end
// -- 88 lines of "import proc <name> <signature> in end"
inline proc print-i32 int -- in
wasm int -- in
"(call $pop)"
"(call $print)"
end
end
However, I get an error from wasm2wat
:
web/examples/colors.wat:127:2: error: imports must occur before all non-import definitions
(import "env" "print" (func $print (param i32))) ;; OP_INJECT_CODE 0
^^^^^^
I tried putting the (import "env" ...)
before include "wasm-core.porth"
and it still gives the same error (just different line numbers). Is there anything I can do or do I have to not include this procedure for now until you (maybe) fix it? (I already had to omit quite a few functions because of floats)