-
Notifications
You must be signed in to change notification settings - Fork 35
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
Call spec #45
Conversation
@@ -8,5 +8,5 @@ | |||
*/ | |||
@FunctionalInterface | |||
public interface ExportFunction { | |||
Value apply(Value... args) throws ChicoryException; | |||
Value[] apply(Value... args) throws ChicoryException; |
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.
NIce!
@@ -137,6 +137,24 @@ public Instance instantiate(HostFunction[] hostFunctions) { | |||
exports.put("_start", export); | |||
} | |||
|
|||
Table table = null; |
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.
This code is a little bit naive on my part but I think it works for the time being. We can update it when we get to the other specs that address tables and elements.
@@ -41,27 +41,27 @@ public void shouldWorkFactorial() { | |||
var module = Module.build("src/test/resources/wasm/iterfact.wat.wasm"); | |||
var instance = module.instantiate(); | |||
var iterFact = instance.getExport("iterFact"); | |||
var result = iterFact.apply(Value.i32(5)); | |||
var result = iterFact.apply(Value.i32(5))[0]; |
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.
Not a big deal for now, but I wonder if it makes sense to have another method similar to get export, or maybe something on ExportFunction that can make this a little cleaner if you know it only has 1 return.
// and pass as args to the function call | ||
var args = extractArgsForParams(type.getParams()); | ||
call(funcId, args, false); | ||
frame.pc = instruction.getAddress(); |
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.
What's the intention of this? So, pc
(program counter or instruction pointer or whatever you prefer) refers to the index of the instruction in the function body. And address here refers to the place in file memory where this instruction is (which has no meaning at runtime). You don't typically need to manage this. call
adds a new frame to the call stack. Each frame has it's own pc. So when call returns it should "remember" the old pc having popped all the frames off the stack.
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.
Okay discussed offline. removing it for the time being then i will investigate.
Cherry-picked #41 and all the tests were already passing :-)