callFunctionDeclaration method

dynamic callFunctionDeclaration(
  1. FunctionDeclaration declaration,
  2. List arguments
)

Implementation

dynamic callFunctionDeclaration(
    FunctionDeclaration declaration, List<dynamic> arguments) {
  Environment previousEnv = _environment;
  _environment = Environment(_globals);
  bool wasGlobalScope = _isGlobalScope;
  _isGlobalScope = false;

  try {
    for (int i = 0; i < declaration.parameters.length; i++) {
      _environment.define(declaration.parameters[i].lexeme, arguments[i]);
    }

    return evaluateNode(declaration.body);
  } finally {
    _environment = previousEnv;
    _isGlobalScope = wasGlobalScope;
  }
}