* The 'restart' Bytecode
@ 2005-07-20 10:47 Christian Lindig
2005-07-23 12:11 ` [Caml-list] " Xavier Leroy
0 siblings, 1 reply; 2+ messages in thread
From: Christian Lindig @ 2005-07-20 10:47 UTC (permalink / raw)
To: Caml List
To verify that some function is indeed tail recursive I sometimes
inspect its bytecode using "ocaml -dinstr". The 'appterm' instruction
implements the desired tail call and thus is what I am looking for.
However, sometimes the appterm instruction is followed by a restart
instruction. I could neither figure out what it does (by looking at
interp.c) nor I was expecting code following an appterm to be reachable
at all. For example:
L3: grab 1
const ' '
push
acc 2
push
getglobal String!
getfield 0
apply 2
push
const "\n"
push
acc 2
push
envacc 1
apply 2
push
envacc 1
appterm 2, 4
restart
I would be grateful if some could elaborate what restart does and how
it interacts with tail calls. Some information about the OCaml Bytecode
machine can be found here, and also in Xavier's ZINC paper.
http://pauillac.inria.fr/~lebotlan/docaml_eng.html
-- Christian
--
http://www.st.cs.uni-sb.de/~lindig/
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [Caml-list] The 'restart' Bytecode
2005-07-20 10:47 The 'restart' Bytecode Christian Lindig
@ 2005-07-23 12:11 ` Xavier Leroy
0 siblings, 0 replies; 2+ messages in thread
From: Xavier Leroy @ 2005-07-23 12:11 UTC (permalink / raw)
To: Christian Lindig; +Cc: Caml List
> To verify that some function is indeed tail recursive I sometimes
> inspect its bytecode using "ocaml -dinstr". The 'appterm' instruction
> implements the desired tail call and thus is what I am looking for.
> However, sometimes the appterm instruction is followed by a restart
> instruction.
The "restart" is actually part of the following function. "grab"
instructions that mark the beginning of a multiple-argument function
are always preceded by a "restart" instruction. If not enough
arguments are provided to the function, "grab" returns a closure
pointing to the preceding "restart" instruction and containing the
values of the provided arguments. When this partial application
closure is applied, "restart" executes, pushes back the saved
arguments on the stack, and reexecutes (by falling through) the "grab"
instruction.
So, nothing to worry about concerning tail calls.
- Xavier Leroy
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2005-07-23 12:11 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-07-20 10:47 The 'restart' Bytecode Christian Lindig
2005-07-23 12:11 ` [Caml-list] " Xavier Leroy
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox