Ah. So the issue is that a LibraryFunction defines its variable references at construction time like this:
Note that it makes up the names of the function arguments, since the actual method for a LibraryFunction does not care.
Very interesting. I would refactor things like this:
Currently: FunctionCall:
saveBindings
iterate over parameters and build an array of values
iterate over values and bind them to variable references
call target.execute
restoreBindings
UserDefinedFunction:
(has saveBindings and restoreBindings)
execute simply executes the scope
LibraryFunction
(has no saveBindings and RestoreBindings)
execute iterates over variable references and makes an array of values - exactly like the one built by FunctionCall
invokes the method
Seems to me it could do this:
FunctionCall:
iterate over parameters and build an array of values
call target.execute( values )
UserDefinedFunction:
saveBindings
iterate over values and bind them to variable references
executes the scope
restoreBindings
LibraryFunction
invokes the method with values array
In other words, bind variable references only for UserDefinedFunction, don't duplicate building values array, and so on.
I'll do it. How hard can it be?
Code:
for ( int i = 1; i <= params.length; ++i )
{
Variable variable = new Variable( params[ i - 1 ] );
this.variableReferences.add( new VariableReference( variable ) );
args[ i ] = Value.class;
}
Very interesting. I would refactor things like this:
Currently: FunctionCall:
saveBindings
iterate over parameters and build an array of values
iterate over values and bind them to variable references
call target.execute
restoreBindings
UserDefinedFunction:
(has saveBindings and restoreBindings)
execute simply executes the scope
LibraryFunction
(has no saveBindings and RestoreBindings)
execute iterates over variable references and makes an array of values - exactly like the one built by FunctionCall
invokes the method
Seems to me it could do this:
FunctionCall:
iterate over parameters and build an array of values
call target.execute( values )
UserDefinedFunction:
saveBindings
iterate over values and bind them to variable references
executes the scope
restoreBindings
LibraryFunction
invokes the method with values array
In other words, bind variable references only for UserDefinedFunction, don't duplicate building values array, and so on.
I'll do it. How hard can it be?