This book is an authoritative work of Il, written by the Il development team:
Tail call
The End call is similar to the method call (JMP). Both give up the current method and pass the parameter to the end call (jump) method. However, because the parameters called at the end must be explicitly loaded on the computing stack (unlike the jump, the stack frame of the current method is discarded by the tail call [1] (stack frame ), it protects the stack framework and can use loaded parameters.) Unlike redirection, tail invocation does not require all signatures of called methods to match the signature of the calling method; the return type must be the same or compatible. Tail call is very useful in large-scale recursive method implementation; the caller's stack frame will be discarded in the tail call process. Therefore, no matter how deep the recursion is, stack Overflow is not risky. This is very important for functional languages. They use recursion to replace loops.
Tail calls are identified by prefix tail before call, callvirt, or calli commands:
LTail. (0xfe 0x14)Mark subsequent call commands as tail calls. This command does not use parameters and stacks. Like other prefix commands unaligned. And volatite., ilasm requires that the commands and Subsequent commands should be separated by at least one space character.
The difference between a jump method and a tail call is that the tail call command pair is verifiable in principle, as long as the command is followed by the RET command (which depends on the verifiable call parameter ). Like other prefix commands, skipping the prefix and directly transferring it to the prefix command (such as call, callvirt, or calli) is invalid.
[1]: stack frame, that is, a stack frame, is an area in the stack. It stores the return address of a function and the local data used inside the function ), it is created by sub ESP, 48 h, and Other statements At the function entrance.
For more information, see http://www.zaoxue.com/article/tech-32942.htm.
In addition, the following exceptions are provided:
Zero X 80131899 |
Can not pass byref to a tail call. |
0x 8013189a |
Missing ret. |
0x8013189b |
Void RET type expected for Tail call. |
0x 8013189c |
Tail call return type not compatible. |
0x8013189d |
Stack not empty after tail call. |