Please take these as suggestions and not criticism :)
https://github.com/thomscoder/luna/blob/009b20c9afd88d0a6572...
The list splitting here is currently un-necessary. Your example for users is
const result = startAeonRuntime(wasmBinary, "addNumbers", n1, n2, n3);
So you can just do something like
const startAeonRuntime(wasm, funcName, ...params) => {
const ast = createAST(wasm);
return invokeFunction(ast, funcName, ...params);
}
However, this leaves me with questions. Why should we need to create/parse the AST each time we want to invoke a function? A wasmBinary can provide multiple functions. Creating the AST each time seems extremely wasteful, but also a bit confusing since I don't think it's necessary. My personal opinion is the function "startAeonRuntime" should be more something like "createAeonRuntime" that returns a partially parameterized version of invokeFunction that I can re-use over and over without it needing to create an AST each time. So something like
In user code I have
const runtime = createAeonRuntime(wasmBinary);
const additionResult = runtime("addNumbers", 1, 2, 3);
const multiplicationResult = runtime("multiplyNumbers, 2, 4, 6);
Then in the library for the runtime the implementation looks like.
const createAeonRuntime = (wasmBinary) => {
const ast = createAST(wasmBinary);
return (funcName, params) => invokeFunction(ast, funcName, params);
}