JarrettBillingsley
Joined: 20 Jun 2006 Posts: 457 Location: Pennsylvania!
|
Posted: Sat Dec 02, 2006 1:41 am Post subject: December 1st -- Returns to native code, small API changes |
|
|
Not too much today, but I worked on making it possible to return values to native code.
Fixed
- Fixed a bug in tailcalls regarding return values, where the stack index wasn't getting set right, giving more return values than it was supposed to.
- Fixed some more bugs in the interpreter regarding the stack index being set incorrectly, and it's now possible to get return values from functions called from D code. It's a little odd though.
Changed
- Changed MDTable and MDArray .create() functions into variadic template functions. I was worried about performance but realized that the performance of the run-time type checking probably wasn't all that hot either. So now they're much smaller and much cleaner. I love variadic templates.
- Changed a lot of functions which used to accept MDValue* to inout MDValue.
- Made opIndexAssigns (in the D code!) return void because of the above change.
- Changed compiler.compile to take an out bool instead of a bool* for the atEOF parameter. Also added an overload to make it possible to call it without that parameter.
- MDState.easyCall() now takes an int for the number of returns instead of a uint (don't know why I had it uint before, as -1 means "as many returns as possible").
- MDState.call() and MDState.easyCall() now return the number of values returned by the function.
Added
- Added a "constructor" to MDValue to make it easier to convert from D types to MDValues.
Return values are a bit odd, though.. they're returned on the stack where the function was, though if you used easyCall() to call the function, that might not be entirely obvious. Here's how you call a function (assuming you have the reference to it in "func" and get all the returns from it:
Code: | uint firstReturn = state.numParams();
// The -1 means "get all returns"
uint numReturns = state.easyCall(func, -1);
for(int i = firstReturn; i < firstReturn + numReturns; i++)
writefln("value ", i - firstReturn, ": ", state.getParam(i).toString()); |
I'm probably going to rename the "param" functions since they're for more than getting parameters..
Hopefully, though, all this oddness will be hidden behind a pretty layer of templates! |
|