Beispiel #1
0
 public override void SetChildrenScopes(KumaScope scope)
 {
     TryBlock.SetScope(scope);
     RescueBlocks.ForEach(block => block.SetScope(scope));
     EnsureBlock.SetScope(scope);
     ElseBlock.SetScope(scope);
 }
Beispiel #2
0
        private static dynamic InstanceEval(object self, string eval, KumaScope scope)
        {
            if (!(self is KumaInstance instance))
            {
                return(null);
            }

            var        xexpression = string.Format("{0};", eval);
            var        res         = KumaParser.Parse(xexpression);
            Expression block;

            if (res != null)
            {
                scope["self"] = scope["super"] = instance;
                scope["<kuma_context_invokemember>"] = true;
                string selfName;
                var    selfScope = scope.SearchForObject(instance, out selfName);
                if (selfScope != null && selfName != null)
                {
                    scope["<kuma_context_selfscope>"] = selfScope;
                    scope["<kuma_context_selfname>"]  = selfName;
                }
                block = KumaExpression.KumaBlock(res);
                // We want eval'd expressions to execute in the current scope, not its own child scopes.  This ensures assignment evals work properly.
                ((BlockExpression)block).Scope = scope;
                ((BlockExpression)block).SetChildrenScopes(scope);
            }
            else
            {
                return(null);
            }
            var val = CompilerServices.CreateLambdaForExpression(block)();

            return(val);
        }
Beispiel #3
0
 public override void SetChildrenScopes(KumaScope scope)
 {
     Body.SetScope(scope);
     Init.SetScope(((KumaExpression)Body).Scope);
     Test.SetScope(((KumaExpression)Body).Scope);
     Step.SetScope(((KumaExpression)Body).Scope);
 }
 public override void SetChildrenScopes(KumaScope scope)
 {
     foreach (var arg in Arguments)
     {
         arg.Value.SetScope(scope);
     }
 }
 public override void SetChildrenScopes(KumaScope scope)
 {
     foreach (var expr in Body)
     {
         expr.SetScope(scope);
     }
 }
        internal BlockExpression(List <Expression> body, KumaScope scope)
        {
            body.RemoveAll(e => e == null);

            Body = body;
            SetScope(scope);
        }
Beispiel #7
0
 public override void SetChildrenScopes(KumaScope scope)
 {
     foreach (var value in Values)
     {
         value.SetScope(scope);
     }
 }
 private static void SetParentScopeIfBlock(this Expression expr, KumaScope scope)
 {
     if (expr is BlockExpression)
     {
         expr.SetParentScope(scope);
     }
     else if (expr is IScopeExpression)
     {
         (expr as IScopeExpression).SetScope(scope);
     }
 }
 private static void SetParentScope(this Expression expr, KumaScope scope)
 {
     if (!(expr is BlockExpression block))
     {
         return;
     }
     if (block.Scope == null)
     {
         block.Scope = new KumaScope();
     }
     block.Scope.ParentScope = scope;
 }
Beispiel #10
0
 public override void SetChildrenScopes(KumaScope scope)
 {
     LeftHandValues.ForEach(value => {
         if (value.Value is KumaExpression)
         {
             value.Value.SetScope(scope);
         }
     });
     RightHandValues.ForEach(value => {
         if (value.Value is KumaExpression)
         {
             value.Value.SetScope(scope);
         }
     });
 }
Beispiel #11
0
 public override void SetChildrenScopes(KumaScope scope)
 {
     Test.SetScope(scope);
     if (DefaultBody != null)
     {
         DefaultBody.SetScope(scope);
     }
     foreach (var @case in Cases)
     {
         foreach (var test in @case.TestValues)
         {
             test.SetScope(scope);
         }
         @case.Body.SetScope(scope);
     }
 }
Beispiel #12
0
        private static dynamic Eval(string eval, KumaScope scope)
        {
            var xexpression = string.Format("{0};", eval);

            var        res = KumaParser.Parse(xexpression);
            Expression block;

            if (res != null)
            {
                block = KumaExpression.KumaBlock(res);
                // We want eval'd expressions to execute in the current scope, not its own child scopes.  This ensures assignment evals work properly.
                ((BlockExpression)block).Scope = scope;
                ((BlockExpression)block).SetChildrenScopes(scope);
            }
            else
            {
                return(null);
            }
            var val = CompilerServices.CreateLambdaForExpression(block)();

            return(val);
        }
Beispiel #13
0
        private static dynamic ClassEval(object self, string eval, KumaScope scope)
        {
            KumaClass @class;
            var       instance = self as KumaInstance;

            if (instance != null)
            {
                @class = instance.Class;
            }
            else
            {
                @class = self as KumaClass;
            }
            if (@class == null)
            {
                return(null);
            }

            var xexpression = string.Format("{0};", eval);

            var res = KumaParser.Parse(xexpression);

            return(res != null?RuntimeOperations.DefineCategory(@class, res.ToList(), scope) : null);
        }
Beispiel #14
0
 public override void SetChildrenScopes(KumaScope scope)
 {
     LValue.SetScope(scope);
     Key.SetScope(scope);
 }
Beispiel #15
0
 public override void SetChildrenScopes(KumaScope scope)
 {
     Function.SetScope(scope);
 }
 public override void SetChildrenScopes(KumaScope scope)
 {
     Name.SetScope(scope);
     Contents.ForEach(content => content.SetScope(scope));
 }
Beispiel #17
0
 public override void SetChildrenScopes(KumaScope scope)
 {
     Start.SetScope(scope);
     End.SetScope(scope);
 }
Beispiel #18
0
 public override void SetChildrenScopes(KumaScope scope)
 {
     Body.SetScope(scope);
 }
Beispiel #19
0
 public override void SetChildrenScopes(KumaScope scope)
 {
     Test.SetScope(scope);
     IfTrue.SetScope(scope);
     IfFalse.SetScope(scope);
 }
 public override void SetChildrenScopes(KumaScope scope)
 {
     Enumerator.SetScope(scope);
     Body.SetScope(scope);
 }
 public static void SetScope(this Expression expr, KumaScope scope)
 {
     expr.SetParentScopeIfBlock(scope);
 }
Beispiel #22
0
 public static dynamic BoxNoCache(object obj, KumaScope scope = null)
 {
     return(KumaBoxedInstance.BoxNoCache(obj, scope ?? new KumaScope()));
 }
 public override void SetChildrenScopes(KumaScope scope)
 {
     ExceptionObject.SetScope(scope);
 }
 /// <summary>
 ///     Called by SetScope to set the children scope on expressions.  Should be overridden to tell the runtime which
 ///     children should have scopes set.
 /// </summary>
 /// <param name="scope"></param>
 public virtual void SetChildrenScopes(KumaScope scope)
 {
 }
Beispiel #25
0
 public override void SetChildrenScopes(KumaScope scope)
 {
     TargetType.SetScope(scope);
     Method.SetScope(scope);
 }
 public override void SetChildrenScopes(KumaScope scope)
 {
     base.SetChildrenScopes(scope);
     Value.SetScope(scope);
 }
 public override void SetChildrenScopes(KumaScope scope)
 {
     Expression.SetScope(scope);
 }
Beispiel #28
0
 public override void SetChildrenScopes(KumaScope scope)
 {
     Left.SetScope(scope);
     Right.SetScope(scope);
 }
 /// <summary>
 ///     Sets the scope used by this expression.
 /// </summary>
 /// <param name="scope">Scope for this expression</param>
 public void SetScope(KumaScope scope)
 {
     _scope = scope;
     SetChildrenScopes(scope);
 }