public object Execute(FunctionEnvironment functionEnvironment, VariableEnvironment variableEnvironment) { if (!functionEnvironment.IsFunctionDefined(Identifier)) { throw new Exception("Calling undefined function: " + Identifier); } VariableEnvironment localVariables = new VariableEnvironment(); localVariables.ParentEnvironment = variableEnvironment;//todo: switch FunctionDefinition functionDefinition = functionEnvironment.GetDefinedFunction(Identifier); for (int i = 0; i < Arguments.Count; i++) { object obj = Arguments[i].Execute(functionEnvironment, variableEnvironment); BogieLangType bogieLangType = BogieLangTypeHelpr.ObjectToType(obj); if (functionDefinition.Parameters[i].Item1 == bogieLangType) { localVariables.DeclareVariable(functionDefinition.Parameters[i].Item2, functionDefinition.Parameters[i].Item1); localVariables.DefineVariable(functionDefinition.Parameters[i].Item2, obj); } } return(functionDefinition.Execute(functionEnvironment, localVariables)); }
public object Execute() { if (FunctionEnvironment.IsFunctionDefined("Main")) { return(FunctionEnvironment.GetDefinedFunction("Main").Execute(FunctionEnvironment, VariableEnvironment)); } else { throw new Exception("Cannot find Main."); } }