MightyPirates / OpenComputers

Home of the OpenComputers mod for Minecraft.
https://oc.cil.li
Other
1.59k stars 431 forks source link

switch to JVM-based eris, using wasm2kotlin #3379

Closed SoniEx2 closed 3 years ago

SoniEx2 commented 3 years ago

you can use wasm2kotlin to make eris for the JVM. https://github.com/SoniEx2/wabt/tree/wasm2kotlin

then you can remove JNI, LuaJ and enable bytecode loading.

currently missing is porting the emscripten runtime to kotlin.

SoniEx2 commented 3 years ago

this doesn't export any of the lua symbols because emscripten doesn't support doing that, but, this is eris for lua 5.3, as a kotlin source file.

lua.txt

SoniEx2 commented 3 years ago

you can drop eris entirely too and dump/load the wasm memory instead. slightly less space-efficient tho.

lucsoft commented 3 years ago

Hey im making a port to 1.16 do you have some knowledge about wasm2kotlin

https://github.com/lucsoft/OpenComputers/issues/2

SoniEx2 commented 3 years ago

this lua is just the interpreter, without the necessary API symbols. because we fucked up. .-.

uh we'd recommend not implementing the native io.* APIs provided by C (just make them throw instead), nor any other blocking stuff. instead force lua to yield, so that you can save/load the whole wasm memory and not bother with eris at all. also wasm2kotlin has some issues - the generated files are sometimes too big for kotlinc. (kotlinc just completely refuses to compile files bigger than 20MB. it just ignores them entirely.)

anyway wasm2kotlin needs more work tbh, sorry. .-.

lucsoft commented 3 years ago

so we can keep JNI, LuaJ in the new version of OpenComputers?

SoniEx2 commented 3 years ago

JNI is a pain, and LuaJ is broken. wasm2kotlin is blocked on https://youtrack.jetbrains.com/issue/KT-43829 tbh.

lucsoft commented 3 years ago

why cant wasm2kotlin split files that are larger then 20MB?

SoniEx2 commented 3 years ago

kotlinc can't accept files larger than 20MB. wasm2kotlin outputs them just fine.

SoniEx2 commented 3 years ago

update: managed to get lua.kt down in size a bit.

1607718734

it works!

payonel commented 3 years ago

@SoniEx2 make a PR for this and I can test it