public string Visit(LambdaDefinitionExpr lambdaDefinitionExpr, Scope context) { var arguments = from arg in lambdaDefinitionExpr.Arguments select arg.Name + " : " + arg.Type.Name; return(lambdaDefinitionExpr.Name + "(" + string.Join(", ", arguments.ToArray()) + ") : " + lambdaDefinitionExpr.ReturnType.Name); }
public Value Visit(LambdaDefinitionExpr lambda, Scope scope) { var value = Value.FromObject(lambda); scope.DefineIdentifier(lambda.Name, value, value.Type.ToString()); return(value); }
public void ReturnTypePropertyReturnsPassedReturnType() { var name = new IdentifierExpr(RandomGenerator.String()); var arguments = new VarDefinitionStmt[0]; var body = new ConstantExpr(RandomGenerator.Int()); var returnType = new IdentifierExpr(RandomGenerator.String()); var target = new LambdaDefinitionExpr(name, arguments, body, returnType); Assert.AreSame(returnType, target.ReturnType); }
public void BodyPropertyReturnsPassedBody() { var name = new IdentifierExpr(RandomGenerator.String()); var arguments = new VarDefinitionStmt[0]; var body = new ConstantExpr(RandomGenerator.Int()); var returnType = new IdentifierExpr(RandomGenerator.String()); var target = new LambdaDefinitionExpr(name, arguments, body, returnType); Assert.AreSame(body, target.Body); }
public void AcceptMethodCallsVisitOnVisitorWithThis() { var name = new IdentifierExpr(RandomGenerator.String()); var arguments = new VarDefinitionStmt[0]; var body = new ConstantExpr(RandomGenerator.Int()); var returnType = new IdentifierExpr(RandomGenerator.String()); var target = new LambdaDefinitionExpr(name, arguments, body, returnType); var visitor = new Mock <IExpressionVisitor <string, int> >(); target.Accept(visitor.Object, 0); visitor.Verify(x => x.Visit(target, 0), Times.Once); }
public void AcceptMethodCallsOnlyVisitOnVisitorWithThisAndNoOtherVisitMethods() { var name = new IdentifierExpr(RandomGenerator.String()); var arguments = new VarDefinitionStmt[0]; var body = new ConstantExpr(RandomGenerator.Int()); var returnType = new IdentifierExpr(RandomGenerator.String()); var target = new LambdaDefinitionExpr(name, arguments, body, returnType); // throw exception is any other methods called other than the PlusExpr overload. var visitor = new Mock <IExpressionVisitor <string, int> >(MockBehavior.Strict); visitor.Setup(x => x.Visit(target, 12345)).Returns(""); target.Accept(visitor.Object, 12345); }
public void LambdaCallTest() { var target = new EvaluateVisitor(); var functionName = RandomGenerator.String(); var functionNameExpr = new IdentifierExpr(functionName); var returnValue = RandomGenerator.String(); var functionDefinition = new LambdaDefinitionExpr(functionNameExpr, new VarDefinitionStmt[0], new ConstantExpr(returnValue), new IdentifierExpr("String")); var expr = new FunctionCallExpr(functionNameExpr, new Expression[0]); _scope.DefineIdentifier(functionName, Value.FromObject(functionDefinition)); var actual = target.Visit(expr, _scope); Assert.AreEqual(returnValue, actual.ToObject()); }
private Value RunFunction(LambdaDefinitionExpr func, Scope scope) { return(func.Body.Accept(this, scope)); }
public ValueType Visit(LambdaDefinitionExpr lambdaDefinitionExpr, Scope context) { return(ValueType.Function); }
public void LambdaCallTest() { var target = new EvaluateVisitor(); var functionName = RandomGenerator.String(); var functionNameExpr = new IdentifierExpr(functionName); var returnValue = RandomGenerator.String(); var functionDefinition = new LambdaDefinitionExpr(functionNameExpr, new VarDefinitionStmt[0], new ConstantExpr(returnValue), new IdentifierExpr("String")); var expr = new FunctionCallExpr(functionNameExpr, new Expression[0]); _scope.DefineIdentifier(functionName, Value.FromObject(functionDefinition)); var actual = target.Visit(expr, _scope); Assert.AreEqual(returnValue, actual.ToObject()); }
public void AcceptMethodCallsVisitOnVisitorWithThis() { var name = new IdentifierExpr(RandomGenerator.String()); var arguments = new VarDefinitionStmt[0]; var body = new ConstantExpr(RandomGenerator.Int()); var returnType = new IdentifierExpr(RandomGenerator.String()); var target = new LambdaDefinitionExpr(name, arguments, body, returnType); var visitor = new Mock<IExpressionVisitor<string, int>>(); target.Accept(visitor.Object, 0); visitor.Verify(x => x.Visit(target, 0), Times.Once); }
public void AcceptMethodCallsOnlyVisitOnVisitorWithThisAndNoOtherVisitMethods() { var name = new IdentifierExpr(RandomGenerator.String()); var arguments = new VarDefinitionStmt[0]; var body = new ConstantExpr(RandomGenerator.Int()); var returnType = new IdentifierExpr(RandomGenerator.String()); var target = new LambdaDefinitionExpr(name, arguments, body, returnType); // throw exception is any other methods called other than the PlusExpr overload. var visitor = new Mock<IExpressionVisitor<string, int>>(MockBehavior.Strict); visitor.Setup(x => x.Visit(target, 12345)).Returns(""); target.Accept(visitor.Object, 12345); }