poorna2152 / nballerina

WebAssembly Backend for the nBallerina compiler
https://ballerina.io/
Apache License 2.0
4 stars 0 forks source link

Defining runtime functions #31

Closed poorna2152 closed 2 years ago

poorna2152 commented 2 years ago

Previously I was using the print.wasm module to define and add functions runtime functions. https://github.com/poorna2152/nballerina/blob/wback_subset04/compiler/modules/wback/build.bal#L277

But defining runtime functions like this seems like a lot of code and it is an unnecessary use of the print.wasm module.

Other approaches which we can do is, Create a separate wat files which include implementation of runtime functions and these files acts like header files. (e.g. mapping.wat, list.wat).

Then we can do two things.

  1. Create wasm files from this wat header files and export the runtime functions from these header files. Then import them to the our module through JS.
  2. Directly add the function and type definitions in the header wat file as text to the wat file we are generating.

Emscripten and Assemblyscript has all definitions of runtime functions within one file.

poorna2152 commented 2 years ago

Following the approach one. https://github.com/poorna2152/nballerina/blob/wback_subset04/compiler/modules/wback/module.bal#L97 Doing this at the moment.