public override Value Invoke(List<Value> parameters) { if (parameters.Count == parameterNames.Count) { // create new scope for the method call var methodScope = new Scope(); for (int i = 0; i < parameterNames.Count; i++) { methodScope.Define(parameterNames[i]); methodScope.Assign(parameterNames[i], parameters[i]); } var nodeStream = new CommonTreeNodeStream(functionBody); // Create a tree walker to evaluate this method's code block var walker = new SGLTreeWalker(nodeStream, methodScope); // Ok, executing the function then Value returnValue = walker.main().Evaluate(); if (returnValue.Type == ValType.Return) { return returnValue.ReturnValue; } else { return returnValue; } // we shouldn't check the return type /*if (!returnValue.GetVarType().Equals(this.returnType)) { throw new Exception("The method doesn't return the expected return type (" + returnValue.ToString() + " is not from type " + this.returnType + ")"); }*/ } throw new CompilerException(definedLine, 318, name, parameterNames.Count.ToString(), parameters.Count.ToString()); }
public Value Invoke(Value objectVar, List<Value> parameters) { if (parameters.Count == parameterNames.Count) { // create new scope for the method call var methodScope = new Scope(); methodScope.Define("this"); methodScope.Assign("this", objectVar); for (int i = 0; i < parameterNames.Count; i++) { methodScope.Define(parameterNames[i]); methodScope.Assign(parameterNames[i], parameters[i]); } var nodeStream = new CommonTreeNodeStream(functionBody); // Create a tree walker to evaluate this method's code block var walker = new SGLTreeWalker(nodeStream, methodScope); Value returnValue = null; // Ok, executing the function then returnValue = walker.main().Evaluate(); // we shouldn't check the return type /*if (!returnValue.GetVarType().Equals(this.returnType)) { throw new Exception("The method doesn't return the expected return type (" + returnValue.ToString() + " is not from type " + this.returnType + ")"); }*/ return returnValue; } // TODO: Exception throw new Exception(); }