Skip to content
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

Merged
merged 7 commits into from
Oct 20, 2023
Merged

Call spec #45

merged 7 commits into from
Oct 20, 2023

Conversation

andreaTP
Copy link
Collaborator

Cherry-picked #41 and all the tests were already passing :-)

@andreaTP andreaTP requested a review from bhelx October 17, 2023 11:40
@andreaTP andreaTP marked this pull request as draft October 17, 2023 11:58
@andreaTP andreaTP marked this pull request as ready for review October 17, 2023 12:36
@andreaTP
Copy link
Collaborator Author

@bhelx please review this last commit: 038a2a0

it makes the tests pass but I'm not 100% sure about the fix on frame.pc.

@@ -8,5 +8,5 @@
*/
@FunctionalInterface
public interface ExportFunction {
Value apply(Value... args) throws ChicoryException;
Value[] apply(Value... args) throws ChicoryException;
Copy link
Contributor

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;
Copy link
Contributor

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];
Copy link
Contributor

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();
Copy link
Contributor

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.

Copy link
Contributor

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.

@bhelx bhelx merged commit c48e471 into main Oct 20, 2023
6 checks passed
@bhelx bhelx mentioned this pull request Oct 20, 2023
@andreaTP andreaTP deleted the call-spec branch January 25, 2024 16:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants