@mcc first off: nothing but browser and node.js will provide you with the ability to interoperate with JS
second: if you want specifically `console.log` as an import, you'll probably have to write some adapter code to run it with wasmtime, because you are now the embedder who is in control (and you get all the drawbacks of having total control)
wasmtime isn't a browser thing and it makes no attempt to emulate a browser environment
@mcc third: the browser doesn't provide anything by default either, you have to tell it to provide a `console.log` export explicitly
anyway, i would probably use the wasmtime python bindings and add the functions you want via Python. there are examples on doing so, ping me if you have issues
@whitequark Okay. Imagine it doesn't need to be console.log— what is the shortest path to printing a string to STDOUT from inside of a binary running in wasmtime? Or is the shortest path actually python?
@mcc consider that wasmtime doesn't have a conception of strings (strings aren't first-class in wasm), so any print method would involve accessing the linear memory directly and parsing your specific string format (is it null terminated? length prefixed? length passed explicitly? etc)
I would like to be able to examine the state of my program while it is running, so I can tell if it is running correctly. Usually, printfs are the easiest way to do this.
Do either wasmtime, or the wabt utilities, to your knowledge offer an interpreter with a non-painful memory debugger?
@mcc - you can debug wasmtime-generated code with gdb or lldb or what other native code debugger you have. however, this requires you to emit DWARF debug information, which i think doesn't even survive a roundtrip through the text format, so it's probably off the table - you can examine the linear memory yourself - you can do printfs
@mcc Wasm is a very low-level API, it's better to think about it like "an instruction set built for virtualization" than "it's a web thing that runs programs"; the former more accurately reflects the kind of integration you'll have to work on
@mcc I would suggest looking at WASI and also building some C programs using wasi-sdk to see how they use the WASI APIs, this might be the most illustrative at this point
@tedmielczarek@mcc it does but if I start telling Andi about components she'll probably give up because of the dazzling level of complexity those involve (and how difficult it is to write those manually in the text format)
@whitequark "you can examine the linear memory yourself"
Can I? How?
This project is based entirely around the state of a single array of integers, because I intentionally though that would be the easiest sort of project to do in handwritten wasm. If I can identify a location in memory and read it as sequential bytes/integers that's good enough. Doing this with wasm-interp sounds less scary as I assume the VM memory is better contained than wasmtime (which I think creates a native executable?)
@whitequark@tedmielczarek The output of this program is a single integer, which is easy to export by just writing a function that returns an integer, so killing debuggability is an option D:
@mcc wasmtime is a JIT compiler; it abstracts away the details of how it runs your code though (also creating a static native executable isn't really an option with it)
I'm not aware of a way to get wasmtime to dump the memory contents via the command line. it's trivial if you embed it though