* the local variables defined by the parameters of the macro definition
*/
@Override
public void caseACallCommand(ACallCommand node) {
String macroName = makeWord(node.getMacro());
Macro macro = context.findMacro(macroName);
// Make sure that the number of arguments passed to the macro match the
// number expected.
if (node.getArguments().size() != macro.getArgumentCount()) {
throw new JSilverInterpreterException("Number of arguments to macro " + macroName + " ("
+ node.getArguments().size() + ") does not match " + "number of expected arguments ("
+ macro.getArgumentCount() + ")");
}
int numArgs = node.getArguments().size();
if (numArgs > 0) {
Value[] argValues = new Value[numArgs];
// We must first evaluate the parameters we are passing or there could be
// conflicts if new argument names match existing variables.
Iterator<PExpression> argumentValues = node.getArguments().iterator();
for (int i = 0; argumentValues.hasNext(); i++) {
argValues[i] = expressionEvaluator.evaluate(argumentValues.next());
}
// No need to bother pushing and popping the variable scope stack
// if there are no new local variables to declare.
dataContext.pushVariableScope();
for (int i = 0; i < argValues.length; i++) {
setTempVariable(macro.getArgumentName(i), argValues[i]);
}
}
try {
macro.render(context);
} catch (IOException e) {
throw new JSilverIOException(e);
}
if (numArgs > 0) {
// No need to bother pushing and popping the variable scope stack