jrd wrote
I have encountered two conceptual programming issues that I would appreciate some clarity on:
1) When implementing VMWriter function declaration routine (i.e., writeFunction), one needs to know the number of local variables (i.e., nLocals) that a given function will subsequently utilize. However, at the point in the source code when a function's declaration-related tokens are being parsed, the function's local variables have not yet been encountered/are NOT yet declared.
This is correct. You need to delay generation of the "function" command until after the local variables are parsed.
2) When implementing VMWriter function invocation routine (i.e., writeCall) as part of a "do statement," one needs to know the number of arguments (i.e., nArgs) that have been previously pushed onto the stack for the given function. However, the number of arguments for a given function are included in a Subroutine Scope Table that was created and destroyed at the point in the source code when the function was initially declared...
The function that you are calling my not be in the source file that you are compiling, so you have no choice but to count the number of arguments that are being pushed:
do Foo.bar(x, y, z);
My compiler's CompileExpressionList() routine returns the number of expressions that were compiled.
--Mark