[Scummvm-devel] Decompiler survey: Variable stack effects
Johannes Schickel
lordhoto at scummvm.org
Sun Jun 13 02:31:08 CEST 2010
On 06/13/2010 01:46 AM, Paul Gilbert wrote:
> On Sat, Jun 12, 2010 at 10:47 PM, Michael Madsen
> <michael at birdiesoft.dk <mailto:michael at birdiesoft.dk>> wrote:
>
>
> This brings me to my questions:
> 1) Does your engine have any opcodes that act in a similar way?
> 2) If yes, do you know if this sort of thing is actually used in
> any scripts for your engine?
>
>
> Well, the Tinsel engine is probably one such example. It's stack
> based, and one of the fundamental opcodes is 'OP_LIBCALL'. This opcode
> is basically an interface to a whole bunch of intrinsic support
> functions. How many parameters get popped off the stack (as parameters
> for each method) depend on which method is called, which is passed as
> an immediate parameter along with the opcode.
I am not sure but that sounds easy to handle, since the parameter is an
immediate and not on the stack (which is what the "variable stack
effects" is all about :-), like it is with SCUMM's startScript.
As I understand SCUMM's (v6 btw.) startScript the first parameter passed
to it is the size of the argument list passed to the script. This can be
any number followed by the same number of parameters on the stack. Last
but not least there are two parameters: script and flags.
So a possible call might look like this (this is a *made up* example!):
push 0 ; flags
push 1 ; script
push 4 ; a4
push 3 ; a3
push 2 ; a2
push 1 ; a1
push 4 ; Number of arguments
startScript
In this case the opcode would take seven parameters from the stack. Of
course it might also be called like this:
push 0 ; flags
push 2 ; script
push 0 ; Number of arguments
startScript
There only three parameters are taken from the stack. As you can see the
number of arguments taken from the stack depends on a value on the stack
and NOT on the opcode alone.
As I get your description of OP_LIBCALL the number of stack parameters
taken is only dependent on the sub function called, which on the other
hand is exactly defined in the bytecode representation, i.e. it does not
depend on any values on the stack.
So as long as every method does have a constant number of arguments all
it would only be required is to properly output different instructions
in the TINSEL dissassembler.
// Johannes
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.scummvm.org/pipermail/scummvm-devel/attachments/20100613/7c2c66ba/attachment.html>
More information about the Scummvm-devel
mailing list