private AphidObject CallFunctionCore(AphidFunction function, IEnumerable <AphidObject> parms)
        {
            var functionScope = new AphidScope(new AphidObject(), function.ParentScope);

            var i = 0;

            foreach (var arg in parms)
            {
                if (function.Args.Length == i)
                {
                    break;
                }

                functionScope.Variables.Add(function.Args[i++], arg);
            }

            var lastScope = _currentScope;

            _currentScope = functionScope;

            Interpret(function.Body);

            var retVal = GetReturnValue();

            _currentScope = lastScope;

            return(retVal);
        }
        public bool LeaveChildScope(bool bubbleReturnValue = false)
        {
            if (bubbleReturnValue)
            {
                var ret = GetReturnValue();
                _currentScope = _currentScope.Parent;

                if (ret != null)
                {
                    SetReturnValue(ret);

                    return(true);
                }
            }
            else
            {
                _currentScope = _currentScope.Parent;
            }

            return(false);
        }
        public AphidInterpreter()
        {
            Init();

            _currentScope = new AphidScope(new AphidObject());
            _currentScope.Variables.Add(
                "__initList",
                ValueHelper.Wrap(new AphidFunction()
            {
                Args = new[] { "x" },
                Body = new List <Expression>()
            }));

            _currentScope.Variables.Add(
                "__initString",
                ValueHelper.Wrap(new AphidFunction()
            {
                Args = new[] { "x" },
                Body = new List <Expression>()
            }));
        }
        public AphidInterpreter()
        {
            Init();

            _currentScope = new AphidScope(new AphidObject());
            _currentScope.Variables.Add(
                "__initList",
                ValueHelper.Wrap(new AphidFunction()
                {
                    Args = new[] { "x" },
                    Body = new List<Expression>()
                }));

            _currentScope.Variables.Add(
                "__initString",
                ValueHelper.Wrap(new AphidFunction()
                {
                    Args = new[] { "x" },
                    Body = new List<Expression>()
                }));
        }
 public AphidInterpreter(AphidScope currentScope)
 {
     Init();
     _currentScope = currentScope;
 }
 public void EnterChildScope()
 {
     _currentScope = new AphidScope(new AphidObject(), _currentScope);
 }
        private AphidObject InterpretIdentifierExpression(IdentifierExpression expression, AphidScope scope = null)
        {
            if (scope == null)
            {
                scope = _currentScope;
            }

            AphidObject obj;

            if (scope.Variables.TryGetValue(expression.Identifier, out obj))
            {
                return(obj);
            }
            else if (scope.Parent != null)
            {
                return(InterpretIdentifierExpression(expression, scope.Parent));
            }
            else
            {
                return(null);
            }
        }
 public AphidScope(AphidObject variables, AphidScope parent)
     : this(variables)
 {
     Parent = parent;
 }
 public void EnterChildScope()
 {
     _currentScope = new AphidScope(new AphidObject(), _currentScope);
 }
        private AphidObject InterpretIdentifierExpression(IdentifierExpression expression, AphidScope scope = null)
        {
            if (scope == null)
            {
                scope = _currentScope;
            }

            AphidObject obj;
            if (scope.Variables.TryGetValue(expression.Identifier, out obj))
            {
                return obj;
            }
            else if (scope.Parent != null)
            {
                return InterpretIdentifierExpression(expression, scope.Parent);
            }
            else
            {
                return null;
            }
        }
 public AphidInterpreter(AphidScope currentScope)
 {
     Init();
     _currentScope = currentScope;
 }
        private AphidObject CallFunctionCore(AphidFunction function, IEnumerable<AphidObject> parms)
        {
            var functionScope = new AphidScope(new AphidObject(), function.ParentScope);

            var i = 0;
            foreach (var arg in parms)
            {
                if (function.Args.Length == i)
                {
                    break;
                }

                functionScope.Variables.Add(function.Args[i++], arg);
            }

            var lastScope = _currentScope;
            _currentScope = functionScope;

            Interpret(function.Body);

            var retVal = GetReturnValue();

            _currentScope = lastScope;

            return retVal;
        }
        public bool LeaveChildScope(bool bubbleReturnValue = false)
        {
            if (bubbleReturnValue)
            {
                var ret = GetReturnValue();
                _currentScope = _currentScope.Parent;

                if (ret != null)
                {
                    SetReturnValue(ret);

                    return true;
                }
            }
            else
            {
                _currentScope = _currentScope.Parent;
            }

            return false;
        }
Esempio n. 14
0
 public AphidScope(AphidObject variables, AphidScope parent)
     : this(variables)
 {
     Parent = parent;
 }