freak wrote:So under the hood, the procedure is actually always called with all parameters. The compiler changes the places where the procedure is called to pass the optional parameters as well. This is why it is not possible inside the procedure to tell how many arguments were passed. The answer is always: "all of them".
Thanks for explaining, I thought already, that this is running on this system. My vision was the following:
- The compiler is running through my code
- If the compiler finds a line which is calling my procedure, he sees, there is 1 parameters set
- The compiler writes a command, which sets the #PB_Compiler_CountProcedureParameters value to 1
- Immediately after this, the procedure is called and #PB_Compiler_CountProcedureParameters can be used inside the procedure.
That was my humble vision. Don't know, this can run. I never build a compiler
For me it would be enough, if
#PB_Compiler_CountProcedureParameters would be a global constant and I see no problems, if the constant is disturbed with a further procedure call inside the procedure.
For example. I'm typing the following code:
Code: Select all
Procedure Test (a, b=7)
Debug Str(a) + " " + Str(b)
Debug PB_Compiler_CountSetProcedureParameters
EndProcedure
Test (4)
Test (4, 5)
Compiler intern the code is prepared like this:
Code: Select all
Global PB_Compiler_CountSetProcedureParameters
Procedure Test (a, b=7)
Debug Str(a) + " " + Str(b)
Debug PB_Compiler_CountSetProcedureParameters
EndProcedure
PB_Compiler_CountSetProcedureParameters = 1 : Test (4)
PB_Compiler_CountSetProcedureParameters = 2 : Test (4, 5)