-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add a wasmtime-specific wasmtime_wat2wasm
C API
#1206
Add a wasmtime-specific wasmtime_wat2wasm
C API
#1206
Conversation
This commit implements a wasmtime-specific C API for converting the text format to the binary format. An upstream spec issue exists for adding this to the C API, but in the meantime we can experiment with our own version of this API and use it in the C# extension, for example! Closes bytecodealliance#1000
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great! Just the two comments below.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 Thanks for fixing this so we could remove all the .wasm files, they were bugging me too.
Question: Would it be possible to support line number and column info for parse failure - ie. separate from error message? Or maybe just prepare API for now - and then add info later if it becomes possible to support. Just to avoid having to change API later. |
I believe the |
EDITED: Looking at https://webassembly.github.io/spec/core/text/lexical.html - it seems that null-terminator is allowed in comments. Or am I misunderstanding something here. Hmm - thought I saw it using const char* - but looking again it is using a wasm_byte_vec_t which is good for the API itself. But maybe double check if null-terminator is supported internally.
|
Oh sorry, I misread that. As separate pieces of information, not how we're doing it currently, no. @alexcrichton is there an error type we can extract the line and column from? |
Yes the wat/wast crates have enough information to return line numbers of errors. The C API in general doesn't do super well with errors and adding rich information like filename/line number (as opposed to just a string) would likely require us to invent new idioms/machinery/etc. I don't think there's any reason why we can't do that, but I would imagine that if we were to focus on errors in the C API we should take a look at them as a whole instead of only situation-solving one API. |
Maybe add some note in API documentation about if UTF-8 BOM is allowed or not. Not sure if Rust runtime will strip it. If it is supposed to work then it would be good to have a wat test file with a BOM. |
Oh I forgot to mention earlier, but your comment about the nul byte was previously correct when it was using For BOM handling Rust doesn't do anything special there, it would be up to the lexer, if anything, to skip it. Currently the wat parser doesn't skip it and will fail on any file that contains the BOM marker. Looking at the lexical structure of the text format I don't think the BOM is allowed, so it sounds like this may be a spec question/update/tweak to bring up with the official repo. |
Thanks @alexcrichton. But one note - BOM, if handled, should only be done at the decoding/encoding layer and not passed on to the internal Unicode representation. So not direct impact here for lexer. |
Ok I'm gonna go ahead and land this and we can continue to iterate on specifics in-tree. |
This commit implements a wasmtime-specific C API for converting the text
format to the binary format. An upstream spec issue exists for adding
this to the C API, but in the meantime we can experiment with our own
version of this API and use it in the C# extension, for example!
Closes #1000