private object AccessItem(bool isSet, Engine engine, object value)
 {
     var op = isSet ? Op.SetItem : Op.GetItem;
     var context = engine.GetContext(Path, CodeTree);
     if (Arguments.Count != 0)
     {
         var combinedArgs = new object[] { context }.Concat(Arguments.Get(engine));
         if (isSet) combinedArgs.Concat(new object[] { value });
         return engine.Operator(op, combinedArgs.ToArray());
     }
     var type = engine.GetType(TypeProperty, TypePath, TypeCodeTree);
     var index = engine.Get(IndexProperty, IndexPath, IndexCodeTree, type);
     if (!isSet) return engine.Operator(op, context, index);
     return engine.Operator(op, context, index, value);
 }
 protected override void OnExecute(Engine engine)
 {
     var type = engine.GetType(TypeProperty, TypePath, TypeCodeTree);
     var value = engine.Get(ValueProperty, Path, CodeTree, type);
     bool foundMatch = false;
     bool executedStatement = false;
     foreach (var statement in Body)
     {
         if (statement is Case)
         {
             // Fell through to a new case group.
             if (executedStatement) return;
             var caseStatement = statement as Case;
             if (!foundMatch)
             {
                 var testValue = caseStatement.Get(engine);
                 if (engine.ShouldInterrupt) return;
                 foundMatch = (bool)engine.Operator(Op.Equals, value, testValue);
             }
         }
         else
         {
             // Found a match
             if (foundMatch)
             {
                 statement.Execute(engine);
                 executedStatement = true;
                 if (engine.ShouldInterrupt) return;
             }
         }
     }
     if (!executedStatement) Default.Execute(engine);
 }
 protected override object OnGet(Engine engine)
 {
     if (Op == AssignmentOp.Assign) return LValue.Set(engine, RValue.Get(engine));
     return LValue.Set(engine, engine.Operator(Op, LValue.Get(engine), RValue.Get(engine)));
 }
Beispiel #4
0
        protected override void OnExecute(Engine engine)
        {
            // Use the same name and type for the whole loop.
            var name = engine.GetVariable(Var, VarCodeTree);
            var type = engine.GetType(TypeProperty, TypePath, TypeCodeTree);
            if (type == null && (UpperLimit != null || Increment != null)) type = typeof(int);

            // If no name is specified then forever.
            if (name == null)
            {
                engine.SetBreakFrame();
                while (true)
                {
                    Body.Execute(engine);
                    engine.ClearShouldContinue();
                    if (engine.ShouldInterrupt) break;
                }
                return;
            }

            // Normal loop processing.
            SetLoopValue(name, engine.Get(ValueProperty, Path, CodeTree, type), type, engine);
            engine.SetBreakFrame();
            while (true)
            {
                if (While != null)
                {
                    if (!(bool)engine.Get(WhileProperty, WhilePath, WhileCodeTree, typeof(bool))) break;
                }
                else if (UpperLimit != null)
                {
                    var limit = engine.Get(UpperLimitProperty, UpperLimitPath, UpperLimitCodeTree, type);
                    if (!(bool)engine.Operator(Op.LessThan, GetLoopValue(name, type, engine), limit)) break;
                }
                Body.Execute(engine);
                engine.ClearShouldContinue();
                if (engine.ShouldInterrupt) break;
                if (Next.Count != 0)
                    Next.Execute(engine);
                else if (Increment != null)
                {
                    var increment = engine.Get(IncrementProperty, IncrementPath, IncrementCodeTree, type);
                    SetLoopValue(name, engine.Operator(Op.Plus, GetLoopValue(name, type, engine), increment), type, engine);
                }
            }
        }
Beispiel #5
0
 protected override object OnGet(Engine engine)
 {
     if (Path != null && CodeTree.Compile(engine, CodeType.Get, Path).IsSetOrIncrement)
         return CodeTree.Get(engine);
     var value = engine.Get(ValueProperty, ValuePath, ValueCodeTree);
     if (Var != null)
     {
         var variable = engine.GetVariable(Var, VarCodeTree);
         if (Op != AssignmentOp.Assign)
         {
             var oldValue = engine.GetVariable(variable);
             value = engine.Operator(Op, oldValue, value);
         }
         engine.DefineVariableInParentScope(variable, value);
         return value;
     }
     if (IsBareTarget)
     {
         var target = engine.Get(TargetProperty);
         target = engine.Operator(Op, target, value);
         Target = value;
         return value;
     }
     var context = engine.Context;
     var type = engine.GetType(TypeProperty, TypePath, TypeCodeTree);
     if (Op != AssignmentOp.Assign)
     {
         object oldValue = null;
         if (DependencyProperty != null)
             oldValue = PathHelper.GetDependencyProperty(engine, context as DependencyObject, DependencyProperty);
         else if (PropertyName != null)
             oldValue = PathHelper.GetProperty(engine, context, PropertyName);
         else if (FieldName != null)
             oldValue = PathHelper.GetField(engine, context, FieldName);
         else if (StaticPropertyName != null)
             oldValue = PathHelper.GetStaticProperty(engine, type, StaticPropertyName);
         else if (StaticFieldName != null)
             oldValue = PathHelper.GetStaticField(engine, type, StaticFieldName);
         else if (Path != null)
             oldValue = engine.GetPath(Path, CodeTree);
         else
             oldValue = context;
         value = engine.Operator(Op, oldValue, value);
     }
     if (DependencyProperty != null)
         PathHelper.SetDependencyProperty(engine, context as DependencyObject, DependencyProperty, value);
     else if (PropertyName != null)
         PathHelper.SetProperty(engine, context, PropertyName, value);
     else if (FieldName != null)
         PathHelper.SetField(engine, context, FieldName, value);
     else if (StaticPropertyName != null)
         PathHelper.SetStaticProperty(engine, type, StaticPropertyName, value);
     else if (StaticFieldName != null)
         PathHelper.SetStaticField(engine, type, StaticFieldName, value);
     else if (Path != null)
         engine.SetPath(Path, SetCodeTree, value);
     else
         Context = value;
     return value;
 }
 protected override object OnGet(Engine engine)
 {
     if (Op == default(Op)) engine.Throw("missing operator");
     var type = engine.GetType(TypeProperty, TypePath, TypeCodeTree);
     if (Arguments.Count == 0)
     {
         var arity = Op.GetArity();
         if (arity == 1)
             return engine.Operator(Op, engine.Get(ValueProperty, Path, CodeTree, type));
         var value1 = engine.Get(Value1Property, Path1, CodeTree1, type);
         var value2 = engine.Get(Value2Property, Path2, CodeTree2, type);
         return engine.Operator(Op, value1, value2);
     }
     return engine.Operator(Op, Arguments);
 }