-
Notifications
You must be signed in to change notification settings - Fork 157
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
Nelua support #204
Comments
I'm investigating this at my free time, I'll give an update (maybe on discord instead) once I got some progress. |
I made some progress with this and have a minimal cart compiling and running:
#!/bin/sh -e
CFLAGS="-mexec-model=reactor -Wl,--allow-undefined,-zstack-size=1024,--no-entry,--import-memory,--initial-memory=65536,--max-memory=65536,--global-base=6560,--export-dynamic"
./nelua \
--cc "$WASI_SDK_PATH/bin/clang --sysroot=$WASI_SDK_PATH/share/wasi-sysroot" \
--cflags="$CFLAGS" --verbose -Pabort="'trap'" \
./wasm4-test.nelua -o out.wasm --release
-- Pointer to WASM-4 memory register
local DRAW_COLORS = (@*uint16)(0x14);
-- Import some WASM-4 functions
local function text (str: cstring <const>, x: int32, y: int32): void <cimport> end
local function trace (str: cstring <const>): void <cimport> end
-- Hack to call Nelua initialization
local function nelua_main (argc: integer, argv: integer): void <cimport, nodecl> end
local function _start (): void <cexport, codename "_start">
nelua_main(0, 0)
end
local x = 69
local function update (): void <cexport, codename "update">
-- $ is used to deref a pointer
$DRAW_COLORS = 0x23
-- Call an imported function
text("Hello from Nelua!", x, 20)
x = (x + 1) % 160
trace("Trace works")
end
trace("Hello from initializer") Some possible next steps:
|
For example: The |
add function bindings to nelua, move cflags from Makefile to wasm4.nelua (#204)
Thanks for flagging about spaces in the compiler path, that should be fixed now. It was actually affecting our C/C++ template too, it's been fixed there as well. |
@aduros To fix the issue that made debug builds fail, I've recently made changes in the Nelua compiler to allow the user to setup a custom error writer, so then calls to There is the new pragma --[[
Changes how messages are written to stderr when a runtime error occur (panic, assert, check, etc).
This pragma can be one of the following values:
* `'none'`: the application with call system's `exit(-1)`
* `'hooked'`: will call error message handler defined by the application, then you must define
`function nelua_write_stderr(msg: cstring, len: usize, flush: boolean): void`
* `'stdout'`: messages will be printed to stdout
* `'stderr': messages will be printed to stderr (this is the default)
]]
writestderr = shaper.one_of{'none', 'hooked', 'stdout', 'stderr'}:is_optional(), You could use it with the command line `-Pwritestderr="'none'" to ignore error messages, but it's ideal to print them, so I suggest adding this to the template: require 'stringbuilder' -- for print()
global function trace(str: cstring <const>): void <cimport> end
-- Make abort generate an invalid instruction instead of calling C `abort()`.
## context.rootpragmas.abort = 'trap'
-- Hook runtime errors to write using `trace()` instead of writing to C `stderr`.
## context.rootpragmas.writestderr = 'hooked'
local function write_stderr(msg: cstring, len: usize, flush: boolean): void <codename'nelua_write_stderr'>
trace(msg)
end
-- Replace global print function to write using `trace()` instead of writing to C `stdout`.
global function print(...: varargs)
local sb: stringbuilder <close>
## for i=1,select('#', ...) do
## if i > 1 then
sb:write('\t')
## end
sb:write(#[select(i, ...)]#)
## end
trace(sb:view())
end Notice that I've already set the necessary pragmas in the above code, if you do the same way you can remove the I've also overridden |
Nelua can compile to WebAssembly using Emscripten. An example can be found here: https://github.com/edubart/nelua-game2048
w4 new
: Add new project templatew4 watch
: Add new filename suffix + build/run supportw4 png2src
: Add new language parameterThe text was updated successfully, but these errors were encountered: