Variable Arguments

Lähettäjä: "Mystifier" <rohitlodha@hotwireindia.com>
Aihe: Re: Variable Arguments

I am asking VM level. I am currently writing a stack based VM for Ruby
from scratch. It is going to run ruby after compiling it to byte codes.

In the process, I have to think about the bytecodes, the calling
convention etc. A very basic toy could be ready early. I am also looking
out for better performance and am willing to drop / alter ruby
specifications, though my approach is to find a way without opting for
the change.

Currently, I am writing an Interpreter while the specifications are
fluid. Once it is stabilized, I shall move over to jit compiler.

Arity did give me a possible way to resolve my issue. Thanks.

Glad that you found a way. It being a somewhat interesting topic,
though, I'm interested in the issue at the VM level. From what I
understand, you'll compile the Ruby code

def foo(x, y, *z)
end
foo.bar(5, 4, 5, 6)

to bytecode, i.e.

  method-call :foo [5, 4, 5, 6] # Or whatever

Which is then expanded to a new stack frame with the passed-in
variables at the ready. I'm guessing your problem is how to assign
the parameters to variables? For this, the pseudo-bytecode sequence
would change to something like:

  method-call :foo :foo-call [5,4,5,6]
  c-param-check :foo :foo-call # Expected params
  c-assign-param :foo-call :x [5]
  c-assign-param :foo-call :y [4]
  c-assign-array :foo-call :z [5,6]
  call :foo-call :foo
  
This of course if you don't just want to delegate the whole process
to the stack builder.

Regards,
Mystifier

E