Piers Cawley <[EMAIL PROTECTED]> writes:

> Leopold Toetsch <[EMAIL PROTECTED]> writes:
> 
> > Piers Cawley <[EMAIL PROTECTED]> wrote:
> >
> >> I'm not sure you can optimize it to a jump opcode when you're tail
> >> calling another function can you? You could be tailcalling into a
> >> closure so you'll need to use invoke to do the right thing with the
> >> lexical stack etc.
> >
> > Argh, yes. What about:
> >
> > If the subroutine is constructed inside the sub, parrot sees the class
> > and can decide at compile time to either jump or invoke.
> >
> > If the subroutine is passed in, a runtime check could be done:
> >
> >   if sub.isa("Sub") goto do_jump
> >   invoke
> 
> Umm... not sure quite what you mean there. Don't forget that the sub
> could be got by doing:
> 
>     find_lex P0, 'sub_name'

One of my projects is to allow tail-calls in languages/scheme (Don't
assume anything in the near future; i currently work on the io-system
and its near and far friends). My plan for this is to use a new
emitting instruction _tail_call_function which does emit
  find_lex P0, 'name'
  invoke              # this does not change P1
instead of
  find_lex P0, 'name'
  save P1
  invokecc            # this uses P1 as return address
  restore P1          # invoke P1 from the function brings us back here
  invoke P1           # this brings us back to our caller
which the current _call_function would emit

Thinking a little about it, even call/cc is very simple to implement
  # checking of arguments
  set P0, P5          # first argument is the function which will be called
  set P5, P1          # first argument of the called function is cc
  invoke              # tail call

No jumps are needed in this code. Jump should get translated
jmp/branch -> invoke
jsr/bsr    -> invokecc
ret        -> invoke P1

bye
boe
-- 
Juergen Boemmels                        [EMAIL PROTECTED]
Fachbereich Physik                      Tel: ++49-(0)631-205-2817
Universitaet Kaiserslautern             Fax: ++49-(0)631-205-3906
PGP Key fingerprint = 9F 56 54 3D 45 C1 32 6F  23 F6 C7 2F 85 93 DD 47

Reply via email to