Example #1
0
        public override IValue interpret(Context context)
        {
            IValue value = expression.interpret(context);

            if (value != NullValue.Instance)
            {
                IType target = getTargetType(context, type, mutable);
                if (!target.Equals(value.GetIType()))
                {
                    if (target == DecimalType.Instance && value is IntegerValue)
                    {
                        value = new value.DecimalValue(((IntegerValue)value).DoubleValue);
                    }
                    else if (target == IntegerType.Instance && value is value.DecimalValue)
                    {
                        value = new IntegerValue(((value.DecimalValue)value).LongValue);
                    }
                    else if (value.GetIType().isAssignableFrom(context, target))
                    {
                        value.SetIType(type);
                    }
                    else if (!target.isAssignableFrom(context, value.GetIType()))
                    {
                        throw new SyntaxError("Cannot cast " + value.GetIType().ToString() + " to " + target.ToString());
                    }
                }
            }
            return(value);
        }
Example #2
0
 public IValue interpret(Context context, IValue value)
 {
     context = context.newChildContext();
     context.registerValue(new Variable(Name, value.GetIType()));
     context.setValue(Name, value);
     Statements.interpret(context);
     return(null);
 }
Example #3
0
 private IValue interpretPromotion(IValue item)
 {
     if (item == null)
     {
         return(item);
     }
     if (DecimalType.Instance == itemType && item.GetIType() == IntegerType.Instance)
     {
         return(new prompto.value.DecimalValue(((prompto.value.IntegerValue)item).DoubleValue));
     }
     else if (TextType.Instance == itemType && item.GetIType() == CharacterType.Instance)
     {
         return(((CharacterValue)item).AsText());
     }
     else
     {
         return(item);
     }
 }
Example #4
0
        private IValue interpretOperator(Context context, IValue value, Operator oper)
        {
            IMethodDeclaration decl = declaration.findOperator(context, oper, value.GetIType());

            context = context.newInstanceContext(this, false).newChildContext();
            decl.registerParameters(context);
            IParameter arg = decl.getParameters()[0];

            context.setValue(arg.GetName(), value);
            return(decl.interpret(context));
        }
Example #5
0
        private long?InterpretLimit(Context context, IExpression exp)
        {
            if (exp == null)
            {
                return(null);
            }
            IValue value = exp.interpret(context);

            if (!(value is prompto.value.IntegerValue))
            {
                throw new InvalidValueError("Expecting an Integer, found:" + value.GetIType().GetTypeName());
            }
            return(((prompto.value.IntegerValue)value).LongValue);
        }
Example #6
0
        IValue interpretPredicate(Context context)
        {
            IValue lval = left.interpret(context);

            if (lval is IContainer)
            {
                IType              itemType  = ((ContainerType)lval.GetIType()).GetItemType();
                ArrowExpression    arrow     = ((PredicateExpression)right).ToArrowExpression();
                Predicate <IValue> predicate = arrow.GetFilter(context, itemType);
                return(interpretPredicate(context, (IContainer)lval, predicate));
            }
            else
            {
                throw new SyntaxError("Expecting collection");
            }
        }
Example #7
0
 private bool isA(Context context, IValue lval, IValue rval)
 {
     if (rval is TypeValue)
     {
         IType actual = lval.GetIType();
         if (actual == NullType.Instance)
         {
             return(false);
         }
         IType toCheck = ((TypeValue)rval).GetValue();
         return(toCheck.isAssignableFrom(context, actual));
     }
     else
     {
         return(false);
     }
 }
Example #8
0
        private IType interpretParentInstance(Context context)
        {
            IValue value = parent.interpret(context);

            if (value == null || value == NullValue.Instance)
            {
                throw new NullReferenceError();
            }
            IType type = value.GetIType();

            if (parent is SuperExpression)
            {
                return(((CategoryType)type).getSuperType(context));
            }
            else
            {
                return(type);
            }
        }
Example #9
0
        public IValue interpret(Context context)
        {
            IValue o = expression.interpret(context);

            if (!(o is TupleValue))
            {
                throw new SyntaxError("Expecting a tuple expression, got " + o.GetType().Name);
            }
            TupleValue tuple = (TupleValue)o;

            for (int i = 0; i < names.Count; i++)
            {
                String name  = names[i];
                IValue value = tuple[i];
                if (context.getRegisteredValue <INamed>(name) == null)
                {
                    context.registerValue(new Variable(name, value.GetIType()));
                }
                context.setValue(name, value);
            }
            return(null);
        }
Example #10
0
        public void interpretQuery(Context context, IQueryBuilder builder)
        {
            AttributeDeclaration decl = left.CheckAttribute(context);

            if (decl == null || !decl.Storable)
            {
                throw new SyntaxError("Unable to interpret predicate");
            }
            IValue  value   = right.interpret(context);
            MatchOp matchOp = getMatchOp(context, decl.getIType(), value.GetIType(), this.oper, false);

            if (value is IInstance)
            {
                value = ((IInstance)value).GetMemberValue(context, "dbId", false);
            }
            AttributeInfo info = decl.getAttributeInfo();
            Object        data = value == null ? null : value.GetStorableData();

            builder.Verify <Object>(info, matchOp, data);
            if (oper.ToString().StartsWith("NOT_"))
            {
                builder.Not();
            }
        }