@@ -3042,16 +3042,28 @@ function CodeGenerator:processStatementList(statementList)
30423042 end
30433043end
30443044
3045- function CodeGenerator :processBlockNode (blockNode , variables , isFunction )
3046- self :enterScope (isFunction )
3047- if variables then
3048- -- Declare variables while in the scope.
3049- self :declareLocalVariables (variables )
3050- end
3045+ function CodeGenerator :processBlockNode (blockNode )
3046+ self :enterScope ()
30513047 self :processStatementList (blockNode .Statements )
30523048 self :leaveScope ()
30533049end
30543050
3051+ function CodeGenerator :processFunctionBody (node )
3052+ self :enterScope (true )
3053+ for _ , paramName in ipairs (node .Parameters ) do
3054+ self :declareLocalVariable (paramName )
3055+ end
3056+
3057+ if node .IsVararg then
3058+ -- Declare implicit "arg" variable to hold vararg values.
3059+ self :declareLocalVariable (" arg" )
3060+ end
3061+
3062+ self :processStatementList (node .Body .Statements )
3063+ self :emitInstruction (" RETURN" , 0 , 1 , 0 ) -- Default return statement
3064+ self :leaveScope ()
3065+ end
3066+
30553067-- Processes and compiles a function node into a function prototype.
30563068--
30573069-- functionNode - The AST node representing the function.
@@ -3064,8 +3076,7 @@ function CodeGenerator:processFunction(functionNode, closureRegister)
30643076 numParams = # functionNode .Parameters ,
30653077 })
30663078 self .proto = childProto
3067- self :processBlockNode (functionNode .Body , functionNode .Parameters , true )
3068- self :emitInstruction (" RETURN" , 0 , 1 , 0 ) -- Default return statement
3079+ self :processFunctionBody (functionNode )
30693080 self .proto = parentProto
30703081
30713082 if closureRegister then
0 commit comments