It's not really needed that I add to this request, but
I think it might be useful to understand why it is like
it is.
The jump in your example is not necessary, of course.
It is there in case there is still some cleanup to do.
Actually, every procedurereturn will set the EAX/RAX
register, jump to the cleanup part, clean up while
preserving EAX/RAX and THEN restore the stack pointer
and return.
So what you actually want is a micro-optimization for
procedures that do not need any cleanup. That's fine
by me
To illustrate what is going on, I compiled the following
code:
Code: Select all
Procedure test(a.l)
s.s = "hi"
ProcedureReturn 2
ProcedureReturn
EndProcedure
which produces this commented assembler output (x64)
Code: Select all
_Procedure0:
MOV qword [rsp+8],rcx
PS0=64
XOR rax,rax
PUSH rax
PUSH rax
SUB rsp,40
; s.s = "hi"
MOV rdx,_S1
LEA rcx,[rsp+40]
CALL SYS_FastAllocateStringFree4
; ProcedureReturn 2
MOV rax,2
JMP _EndProcedure1
; ProcedureReturn
JMP _EndProcedure1
; EndProcedure
XOR rax,rax
_EndProcedure1:
PUSH rax
MOV rcx,qword [rsp+48]
SUB rsp,40
CALL SYS_FreeString
ADD rsp,40
POP rax
ADD rsp,56
RET
As you can see, every ProcedureReturn jumps to the
cleanup code. Of course this is only necessary if
there is cleanup to do and it is not needed if the
ProcedureReturn is the last statement before
EndProcedure.
I'm absolutely in favor of this request but I think Fred
has a lot of other things on his To-do list. Meanwhile
even if it breaks in the future, you may want to insert
that RETN 4 yourself. When I use risky stuff, I usually
put it within a compiler-version check:
Code: Select all
CompilerIf #PB_Compiler_Version = 460
;stuff
CompilerElse
CompilerError "Check if still valid"
CompilerEndIf
If you already knew this, I apologize. It just seemed
worthwhile to mention.
greetz
Remi