public override DLR.Expression GenerateExpressionTree(GenScope scope) { var expression = Expression.GenerateExpressionTree(scope); if (Target is IdentifierExpression identifier) //Check if a new variable is introduced { var name = identifier.Name; if (!scope.TryGetVariable(name, out DLR.ParameterExpression variable)) //If it is, initialise it { variable = DLR.Expression.Variable(typeof(object), name); scope.Definitions[name] = variable; } return(DLR.Expression.Assign(variable, expression)); } var target = Target.GenerateExpressionTree(scope); switch (Operation) { case TokenType.Assign: return(DLR.Expression.Assign(target, expression)); default: throw new NotImplementedException(); // Add syntactic sugar operators } }
public override DLR.Expression GenerateExpressionTree(GenScope scope) { var args = new DLR.Expression[CellNames.Count + 1]; args[0] = DLR.Expression.Quote(DLR.Expression.Lambda(Expression.GenerateExpressionTree(scope))); for (var i = 1; i < CellNames.Count + 1; i++) { var varName = CellNames.ElementAt(i - 1); if (scope.TryGetVariable(varName, out DLR.ParameterExpression variable)) { args[i] = variable; } else { throw new ArgumentException($"Variable \"{varName}\" is not defined."); } } return(DLR.Expression.Dynamic( new CreateSignalInstanceBinder(), typeof(object), args)); }
public override DLR.Expression GenerateExpressionTree(GenScope scope) { if (scope.TryGetVariable(Name, out DLR.ParameterExpression result)) { return(result); } throw new InvalidOperationException($"\"{Name}\" is not defined!"); }
public override DLR.Expression GenerateExpressionTree(GenScope scope) { DLR.Expression result = null; var first = Expressions.First(); if (first is IdentifierExpression ident) { if (scope.TryGetVariable(ident.Name, out ParameterExpression variable)) //expression performed on a variable { result = variable; } else { result = DLR.Expression.Constant(new UnresolvedType(ident.Name)); //static or alias access } } else { result = first.GenerateExpressionTree(scope); } for (var element = 1; element < Expressions.Count; element++) { switch (Expressions.ElementAt(element)) { case IdentifierExpression identifier: { if (IsSetMember && element == Expressions.Count - 2) { result = DLR.Expression.Dynamic( new RilaSetMemberBinder(identifier.Name), typeof(object), result, Expressions.Last().GenerateExpressionTree(scope)); //The last expression is the new value element = Expressions.Count; } else { result = DLR.Expression.Dynamic(scope.Runtime.GetGetMemberBinder(identifier.Name), typeof(object), result); } } break; case CallExpression call: { var name = call.Function as IdentifierExpression; var args = new DLR.Expression[call.Arguments.Count + 1]; args[0] = result; for (var i = 1; i <= call.Arguments.Count; i++) { args[i] = call.Arguments.ElementAt(i - 1).GenerateExpressionTree(scope); } result = DLR.Expression.Dynamic( scope.Runtime.GetInvokeMemberBinder(new Tuple <string, CallInfo>(name.Name, new CallInfo(call.Arguments.Count))), typeof(object), args); } break; case IndexerExpression indexer: result = indexer.GenerateExpressionTree(scope); break; default: throw new ArgumentException("Expecting member access, call or indexer expression!"); } } return(result); }