fastvm / web49 Goto Github PK
View Code? Open in Web Editor NEWWeb49: WebAssembly Interpeter
License: MIT License
Web49: WebAssembly Interpeter
License: MIT License
There is a lot code require setjmp
to build into wasm, emcc support it by build into javascript
backend. (and all mainstream browser support setjmp
and exception
). https://webassembly.org/roadmap/
I can see FastVM use goto
every where, maybe microwasm
can add setjmp
/longjmp
support base on goto
?
a lot library don't use exception
but require setjmp
, add setjmp
will allow a lot wasm only run in browser/nodejs
work for web49
.
memory.copy seems not to be implemented in the binary parser.
however the error message is:
unknown opcode sequence: 0xFC 0x10
which should be 0xFC 0x0A.
It looks like it's printed decimal in table.c (web49_bytes_to_opcode):
unknown opcode sequence: 0xFC 0x%" PRIu8
same for the other sequences.
So, I downloaded the mac asset from last successful action workflow, and compiled this:
#include "raylib.h"
int main(void) {
const int screenWidth = 800;
const int screenHeight = 450;
InitWindow(screenWidth, screenHeight, "raylib [textures] example - texture loading and drawing");
Texture2D texture = LoadTexture("raylib_logo.png");
while (!WindowShouldClose()) {
BeginDrawing();
ClearBackground(RAYWHITE);
DrawTexture(texture, screenWidth / 2 - texture.width / 2, screenHeight / 2 - texture.height / 2, WHITE);
DrawText("this IS a texture!", 360, 370, 10, GRAY);
EndDrawing();
}
UnloadTexture(texture);
CloseWindow();
return 0;
}
with ./emraylib textures_logo_raylib.c -o textures_logo_raylib
then ran ./raywasm textures_logo_raylib.wasm
, and it opens and closes, without error. Do I need to structure my code differently?
Hi!
I'd like to add web49
to the lists of runtimes libsodium can support for testing wasm32-wasi
.
web49
currently doesn't implement wasi_random_get
, which I added a simple implementation for.
But in benchmark mode, it's not even required by most tests.
However, many tests, when run under web49
, either cause the interpreter to segfault, or return incorrect values.
For example scalarmult.wasm
segfaults, and xchacha20.wasm
trips on many assertions due to incorrect computations.
The benchmark files used for the most recent round of the libsodium benchmark can be downloaded here.
These benchmarks, or the test files that are faster to execute and still trigger the issues with web49
, can be created simply by running the zig build -Drelease-fast -Dtarget=wasm32-wasi
command in the root directory of the libsodium source code.
on mac 13.0.1 intel, if I run make
or make CC=gcc
I get this error:
main/miniwasm.c:127:73: error: implicit declaration of function 'isnanf' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
if (data[n].f32 == expected || (isnanf(expected) && isnanf(data[n].f32))) {
^
1 error generated.
I am using this to route WASI calls to web49_api_wasi
web49_env_func_t web49_main_import_func(void* state, const char* mod, const char* func) {
printf("called: %s.%s\n", mod, func);
if (strcmp(mod, "null0") == 0) {
return web49_api_null0(state, mod, func);
} else if (strcmp(mod, "wasi_snapshot_preview1") == 0) {
return web49_api_wasi(state, mod, func);
}
fprintf(stderr, "Unhandled import: %s.%s\n", mod, func);
return NULL;
}
and for a printf
from the wasm, it seems to just output huge chunks of memory. Do I need to put more in state
?
I want to use web49 to interact with native. I found web49 call native easy but not vice versa.
This is a great project and I love it.
I'm on macOS Ventura; I did the following:
The output I get is this:
$$$ ./bin/wat2wasm test/core/address.wast
unexpected word: `` byte=256
How do I provide an argument to a function? I looked around in code, and didn't really see anything.
For example, I want to expose malloc
from my wasm, it has 1 arg (size
):
// How to insert an arg here?
web49_interp_data_t* data = web49_interp_block_run(interp, &interp->funcs[mallocID]);
uint32_t wptr = data->i32_u;
Related sidenote: is there a better way to allocate a buffer in wasm-memory?
I have a function that takes a string param, like this:
uint32_t font_measure(uint32_t fontID, char* text);
That I am trying to expose, like this:
static web49_interp_data_t wasi_import_font_measure(void* wasi_untyped, web49_interp_t interp) {
uint32_t fontID = interp.locals[0].i32_u;
uint32_t textPtr = interp.locals[1].i32_u;
char text[512];
memcpy(text, WEB49_INTERP_ADDR(void *, interp, textPtr, 512), 512);
return (web49_interp_data_t){.i32_u = font_measure(fontID, text)};
}
This works, but seems like the wrong way to me (using max-length of 512 to pull the whole thing.) Is this the right way to pull the string? Is there a better way to get the string-length up-front? Should I rewrite all functions that take string params to include length param, too?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.