Version française
Home     About     Download     Resources     Contact us    
Browse thread
The 'restart' Bytecode
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Xavier Leroy <Xavier.Leroy@i...>
Subject: Re: [Caml-list] The 'restart' Bytecode
> 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