Add a limited form of re-entrant calls.

This doesn't let you arbitrarily call back into the VM from within
foreign methods. I'm still not sure if that's even a good idea since
God knows what that would mean if you switch fibers while doing that.

But this does allow the very important use case of being able to call
a foreign method from within a call to wrenCall(). In other words,
foreign methods need to always be leaf calls on the call stack, but the
root of that stack can now come from runInterpreter() or wrenCall().

Fix #510.
This commit is contained in:
Bob Nystrom
2019-02-08 17:09:39 -08:00
parent 27a08151e7
commit a5147aa2d9
10 changed files with 111 additions and 16 deletions
+17
View File
@@ -0,0 +1,17 @@
// Regression test for https://github.com/munificent/wren/issues/510.
//
// Tests that re-entrant API calls are handled correctly. The host uses
// `wrenCall()` to invoke `CallCallsForeign.call()`. That in turn calls
// `CallCallsForeign.api()`, which goes back through the API.
class CallCallsForeign {
foreign static api()
static call(param) {
System.print(api())
// expect: slots before 2
// expect: [1, 2, 3, 4, 5, 6, 7, 8, 9]
System.print(param) // expect: parameter
// expect: slots after 1
return "result"
}
}