object CreateObject(string objTypeName, string expressionText, EvalEnv env) { var objType = FindType (objTypeName); return CreateObject (objType, expressionText, env); }
object CreateObject(Type objType, string expressionText, EvalEnv env) { if (string.IsNullOrEmpty (expressionText)) { if (objType == typeof (string)) { return string.Empty; } else { return Activator.CreateInstance (objType); } } else { var expr = Expression.Parse (expressionText); return expr.Eval (new ObjectEvalEnv (null, objType, env)); } }
public override object Eval(EvalEnv env) { return env.Lookup (Name); }
object AssignObject(object obj, Type objType, ObjectLiteralExpression literal, EvalEnv env) { throw new NotImplementedException (); }
public override object Eval(EvalEnv env) { if (Constructor == null) throw new InvalidOperationException ("Cannot eval object literal without Constructor"); var obj = Constructor.Eval (env); var objType = obj.GetType (); foreach (var a in Assignments) { var members = objType.GetMember (a.Name, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static); if (members == null || members.Length == 0) { throw new Exception ("'" + a.Name + "' not found in '" + objType.FullName + "'"); } var value = a.Value.Eval (env); SetValue (obj, members[0], value); } return obj; }
public override object Eval(EvalEnv env) { var a = Value.Eval (env); if (a is double) { if (Operator == TokenType.Subtract) return -(double)a; } else if (a is float) { if (Operator == TokenType.Subtract) return -(float)a; } else if (a is decimal) { if (Operator == TokenType.Subtract) return -(decimal)a; } else if (a is ulong) { if (Operator == TokenType.Subtract) throw new NotSupportedException ("Cannot negate UInt64"); } else if (a is long) { if (Operator == TokenType.Subtract) return -(long)a; } else if (a is uint) { if (Operator == TokenType.Subtract) return -(uint)a; } else { if (Operator == TokenType.Subtract) return -Convert.ToInt32 (a); } throw new NotImplementedException (Operator.ToString ()); }
public ObjectEvalEnv(EvalEnv parent = null) : base(parent) { _obj = null; _objType = typeof (object); }
public ObjectEvalEnv(object obj, Type objType, EvalEnv parent = null) : base(parent) { _obj = obj; _objType = objType; }
public override object Eval(EvalEnv env) { var obj = Object.Eval (env); if (obj == null) { throw new NullReferenceException ("Object is null when accessing '" + Name + "'"); } var members = obj.GetType ().GetMember (Name); if (members == null || members.Length == 0) { throw new MissingMemberException (obj.GetType ().FullName, Name); } var member = members[0]; var prop = member as PropertyInfo; if (prop != null) { return prop.GetValue (obj, null); } else { var field = member as FieldInfo; if (field != null) { return field.GetValue (obj); } else { throw new NotSupportedException (member.MemberType.ToString ()); } } }
public override object Eval(EvalEnv env) { Type ty = null; if (string.IsNullOrEmpty (TypeName)) { var p = env; while (p != null) { if (p is ObjectEvalEnv) { ty = ((ObjectEvalEnv)p).ObjectType; break; } p = p.Parent; } if (ty == null) { throw new Exception ("No context to create anonymous type"); } } else { ty = Test.FindType (TypeName); } var args = Arguments.Select (a => a.Eval (env)).ToArray (); return Activator.CreateInstance (ty, args); }
public LocalsEvalEnv(EvalEnv parent = null) : base(parent) { }
public abstract object Eval(EvalEnv env);
public EvalEnv(EvalEnv parent = null) { _parent = parent; }
public override object Eval(EvalEnv env) { return Value; }
public override object Eval(EvalEnv env) { var left = Left.Eval (env); switch (Operator) { case TokenType.LogicalAnd: return (bool)left && (bool)Right.Eval (env); case TokenType.LogicalOr: return (bool)left || (bool)Right.Eval (env); case TokenType.Equal: return left.Equals (Right.Eval (env)); case TokenType.NotEqual: return !left.Equals (Right.Eval (env)); case TokenType.Add: return Add (left, Right.Eval (env)); case TokenType.Subtract: return Subtract (left, Right.Eval (env)); case TokenType.Multiply: return Multiply (left, Right.Eval (env)); case TokenType.Divide: return Divide (left, Right.Eval (env)); case TokenType.GreaterThan: return GreaterThan (left, Right.Eval (env)); case TokenType.LessThan: return LessThan (left, Right.Eval (env)); case TokenType.GreaterThanOrEqual: return GreaterThanOrEqual (left, Right.Eval (env)); case TokenType.LessThanOrEqual: return LessThanOrEqual (left, Right.Eval (env)); default: throw new NotImplementedException (Operator.ToString ()); } }