EndProcedure value
Posted: Wed Apr 13, 2016 1:46 pm
Allow EndProcedure to accept a value.
This would make these two examples equivalent:
For those curious what the point of supporting this is, then it will not just save you one line of source code.
PureBasic (under the hood) Does a ProcedureReturn 0 for all procedures. So with the first example there are actually two ProcedureReturns.
I forget how many (assembly) lines of code that is but it's at least 1 or two lines of code.
Now this should not affect performance, but it's code that is never used.
I thought about asking if the compiler could automatically drop the under the hood procedurereturn if the last line of code was a ProcedureReturn.
But as EndProcedure is not used for anything else and adding the value to that will simplify the parsing of the code versus checking for the last used ProcedureReturn.
"EndProcedure result" as I suggest here will replace the under the hood hidden ProcedureReturn.
Now it's been a while since I last looked at the assembly output of PureBasic, but as far as I know the compiler does not optimize that hidden procedurereturn away currently (correct me if I'm wrong).
This would make these two examples equivalent:
Code: Select all
Procedure.i Test(input.i)
Protected result.i = 0
If input = 5
result = 1
EndIf
ProcedureReturn result
EndProcedure
Code: Select all
Procedure.i Test(input.i)
Protected result.i = 0
If input = 5
result = 1
EndIf
EndProcedure result
PureBasic (under the hood) Does a ProcedureReturn 0 for all procedures. So with the first example there are actually two ProcedureReturns.
I forget how many (assembly) lines of code that is but it's at least 1 or two lines of code.
Now this should not affect performance, but it's code that is never used.
I thought about asking if the compiler could automatically drop the under the hood procedurereturn if the last line of code was a ProcedureReturn.
But as EndProcedure is not used for anything else and adding the value to that will simplify the parsing of the code versus checking for the last used ProcedureReturn.
"EndProcedure result" as I suggest here will replace the under the hood hidden ProcedureReturn.
Now it's been a while since I last looked at the assembly output of PureBasic, but as far as I know the compiler does not optimize that hidden procedurereturn away currently (correct me if I'm wrong).