@@ -14,6 +14,7 @@ local Scope = require("prometheus.scope");
1414local logger = require (" logger" );
1515local util = require (" prometheus.util" );
1616local visitast = require (" prometheus.visitast" )
17+ local randomStrings = require (" prometheus.randomStrings" )
1718
1819local lookupify = util .lookupify ;
1920local AstKind = Ast .AstKind ;
@@ -139,6 +140,8 @@ function Compiler:compile(ast)
139140 self .getmetatableVar = self .scope :addVariable ();
140141 self .selectVar = self .scope :addVariable ();
141142
143+ local argVar = self .scope :addVariable ();
144+
142145 self .containerFuncScope = Scope :new (self .scope );
143146 self .whileScope = Scope :new (self .containerFuncScope );
144147
@@ -277,6 +280,7 @@ function Compiler:compile(ast)
277280 Ast .VariableExpression (self .scope , self .setmetatableVar ),
278281 Ast .VariableExpression (self .scope , self .getmetatableVar ),
279282 Ast .VariableExpression (self .scope , self .selectVar ),
283+ Ast .VariableExpression (self .scope , argVar ),
280284 unpack (util .shuffle ({
281285 Ast .VariableExpression (self .scope , self .containerFuncVar ),
282286 Ast .VariableExpression (self .scope , self .createClosureVar ),
@@ -294,7 +298,7 @@ function Compiler:compile(ast)
294298 Ast .FunctionCallExpression (Ast .FunctionCallExpression (Ast .VariableExpression (self .scope , self .createClosureVar ), {
295299 Ast .NumberExpression (self .startBlockId );
296300 Ast .TableConstructorExpression (upvalEntries );
297- }), {});
301+ }), {Ast . FunctionCallExpression ( Ast . VariableExpression ( self . scope , self . unpackVar ), { Ast . VariableExpression ( self . scope , argVar )}) });
298302 }
299303 }, self .scope ));
300304
@@ -306,6 +310,9 @@ function Compiler:compile(ast)
306310 Ast .VariableExpression (newGlobalScope , setmetatableVar );
307311 Ast .VariableExpression (newGlobalScope , getmetatableVar );
308312 Ast .VariableExpression (newGlobalScope , selectVar );
313+ Ast .TableConstructorExpression ({
314+ Ast .TableEntry (Ast .VarargExpression ());
315+ })
309316 })};
310317 }, psc ), newGlobalScope );
311318end
839846
840847function Compiler :setPos (scope , val )
841848 if not val then
842- local v ;
843- if math.random (1 , 2 ) == 1 then
844- v = Ast .NilExpression ();
845- else
846- v = Ast .BooleanExpression (false );
847- end
849+
850+ local v = Ast .IndexExpression (self :env (scope ), randomStrings .randomStringNode (math.random (12 , 14 ))); -- Ast.NilExpression();
848851 scope :addReferenceToHigherScope (self .containerFuncScope , self .posVar );
849852 return Ast .AssignmentStatement ({Ast .AssignmentVariable (self .containerFuncScope , self .posVar )}, {v });
850853 end
880883function Compiler :compileTopNode (node )
881884 -- Create Initial Block
882885 local startBlock = self :createBlock ();
886+ local scope = startBlock .scope ;
883887 self .startBlockId = startBlock .id ;
884888 self :setActiveBlock (startBlock );
885889
@@ -913,6 +917,12 @@ function Compiler:compileTopNode(node)
913917 end
914918 end , nil , nil )
915919
920+ self .varargReg = self :allocRegister (true );
921+ scope :addReferenceToHigherScope (self .containerFuncScope , self .argsVar );
922+ scope :addReferenceToHigherScope (self .scope , self .selectVar );
923+ scope :addReferenceToHigherScope (self .scope , self .unpackVar );
924+ self :addStatement (self :setRegister (scope , self .varargReg , Ast .VariableExpression (self .containerFuncScope , self .argsVar )), {self .varargReg }, {}, false );
925+
916926 -- Compile Block
917927 self :compileBlock (node .body , 0 );
918928 if (self .activeBlock .advanceToNextBlock ) then
@@ -2088,7 +2098,8 @@ function Compiler:compileExpression(expression, funcDepth, numReturns)
20882098 local entryRegs = {};
20892099 for i , entry in ipairs (expression .entries ) do
20902100 if (entry .kind == AstKind .TableEntry ) then
2091- if i == # expression .entries and entry .kind == AstKind .FunctionCallExpression or expression .kind == AstKind .PassSelfFunctionCallExpression or expression .kind == AstKind .VarargExpression then
2101+ local value = entry .value ;
2102+ if i == # expression .entries and (value .kind == AstKind .FunctionCallExpression or value .kind == AstKind .PassSelfFunctionCallExpression or value .kind == AstKind .VarargExpression ) then
20922103 local reg = self :compileExpression (entry .value , funcDepth , self .RETURN_ALL )[1 ];
20932104 table.insert (entries , Ast .TableEntry (Ast .FunctionCallExpression (
20942105 self :unpack (scope ),
0 commit comments