예제 #1
0
        public RuntimeScriptCode(TotemAst/*!*/ ast, CodeContext/*!*/ codeContext)
            : base(ast)
        {
            Debug.Assert(codeContext.GlobalScope.GetExtension(codeContext.LanguageContext.ContextId) != null);
            Debug.Assert(ast.Type == typeof(MSAst.Expression<Func<FunctionCode, object>>));

            _optimizedContext = codeContext;
        }
예제 #2
0
 public override LightLambdaExpression ReduceAst(TotemAst instance, string name)
 {
     return Utils.LightLambda<LookupCompilationDelegate>(
         typeof(object),
         AstUtils.Convert(instance.ReduceWorker(), typeof(object)),
         name,
         TotemAst._arrayFuncParams
     );
 }
 public override LightLambdaExpression ReduceAst(TotemAst instance, string name)
 {
     return Utils.LightLambda<Func<FunctionCode, object>>(
         typeof(object),
         Ast.Block(
             new[] { TotemAst._globalArray, TotemAst._globalContext },
             Ast.Assign(TotemAst._globalArray, instance.GlobalArrayInstance),
             Ast.Assign(TotemAst._globalContext, Ast.Constant(instance.CodeContext.GlobalContext)),
             AstUtils.Convert(instance.ReduceWorker(), typeof(object))
         ),
         name,
         new[] { TotemAst._functionCode }
     );
 }
예제 #4
0
파일: Node.cs 프로젝트: Alxandr/IronTotem
 public void SetLoc(TotemAst globalParent, IndexSpan span)
 {
     _span = span;
     _parent = globalParent;
 }
예제 #5
0
파일: Node.cs 프로젝트: Alxandr/IronTotem
 public void SetLoc(TotemAst globalParent, int start, int end)
 {
     _span = new IndexSpan(start, end > start ? end - start : start);
     _parent = globalParent;
 }
예제 #6
0
 public abstract LightLambdaExpression ReduceAst(TotemAst instance, string name);
예제 #7
0
 public virtual void PrepareScope(TotemAst ast, ReadOnlyCollectionBuilder<MSAst.ParameterExpression> locals, List<MSAst.Expression> init)
 {
 }
예제 #8
0
        public TotemAst ParseTopExpression()
        {
            try
            {
                _globalParent = new TotemAst(false, false, _context);
                StartParsing();

                ReturnStatement ret = new ReturnStatement(ParseExpression());
                ret.SetLoc(_globalParent, 0, 0);
                return FinishParsing(ret);
            }
            catch (BadSourceException bse)
            {
                throw;
            }
        }
예제 #9
0
        public TotemAst ParseInteractiveCode(out ScriptCodeParseResult properties)
        {
            bool parsingMultiLineCmpdStmt;
            bool isEmptyStmt = false;

            properties = ScriptCodeParseResult.Complete;
            StartParsing();

            _globalParent = new TotemAst(false, true, _context);
            Statement ret = InternalParseInteractiveInput(out parsingMultiLineCmpdStmt, out isEmptyStmt);

            if (_errorCode == 0)
            {
                if (isEmptyStmt)
                    properties = ScriptCodeParseResult.Empty;
                else if (parsingMultiLineCmpdStmt)
                    properties = ScriptCodeParseResult.IncompleteStatement;

                if (isEmptyStmt)
                    return null;

                return FinishParsing(ret);
            }
            else
            {
                if ((_errorCode & ErrorCodes.IncompleteStatement) != 0)
                {
                    if ((_errorCode & ErrorCodes.IncompleteToken) != 0)
                    {
                        properties = ScriptCodeParseResult.IncompleteToken;
                        return null;
                    }

                    properties = ScriptCodeParseResult.IncompleteStatement;
                    return null;
                }

                properties = ScriptCodeParseResult.Invalid;
                return null;
            }
        }
예제 #10
0
 public override bool Walk(TotemAst node)
 {
     return true;
 }
예제 #11
0
 public override void PostWalk(TotemAst node)
 {
     // Do not add the global suite to the list of processed nodes,
     // the publishing must be done after the class local binding.
     Debug.Assert(_currentScope == node);
     _currentScope = _currentScope.Parent;
     _finallyCount.RemoveAt(_finallyCount.Count - 1);
 }
예제 #12
0
 internal virtual void RewriteBody(TotemAst.LookupVisitor visitor)
 {
     _funcCode = null;
 }
 public override void PrepareScope(TotemAst ast, ReadOnlyCollectionBuilder<MSAst.ParameterExpression> locals, List<MSAst.Expression> init)
 {
     locals.Add(TotemAst._globalArray);
     init.Add(Ast.Assign(TotemAst._globalArray, ast._arrayExpression));
 }
예제 #14
0
 public LookupVisitor(TotemAst ast, MSAst.Expression globalContext)
 {
     _globalContext = globalContext;
     _curScope = ast;
 }
예제 #15
0
        internal override void RewriteBody(TotemAst.LookupVisitor visitor)
        {
            _dlrBody = null;    // clear the cached body if we've been reduced

            MSAst.Expression funcCode = GlobalParent.Constant(GetOrMakeFunctionCode());
            FuncCodeExpr = funcCode;

            Body = new TotemAst.RewrittenBodyStatement(Body, visitor.Visit(Body));
        }
예제 #16
0
        internal static void BindAst(TotemAst ast, CompilerContext context)
        {
            Assert.NotNull(ast, context);

            TotemNameBinder binder = new TotemNameBinder(context);
            binder.Bind(ast);
        }
예제 #17
0
        public TotemAst FinishParsing(Statement ret)
        {
            var res = _globalParent;
            _globalParent = null;
            var lineLocs = _tokenizer.GetLineLocations();
            // update line mapping
            if (_sourceUnit.HasLineMapping)
            {
                List<int> newLineMapping = new List<int>();
                int last = 0;
                for (int i = 0; i < lineLocs.Length; i++)
                {
                    while (newLineMapping.Count < i)
                        newLineMapping.Add(last);

                    last = lineLocs[i] + 1;
                    newLineMapping.Add(lineLocs[i]);
                }

                lineLocs = newLineMapping.ToArray();
            }
            res.ParsingFinished(lineLocs, ret);

            return res;
        }
예제 #18
0
        private void Bind(TotemAst unboundAst)
        {
            Assert.NotNull(unboundAst);

            _currentScope = _globalScope = unboundAst;
            _finallyCount.Add(0);

            // Find all scopes and variables
            unboundAst.Walk(this);

            // Bind
            foreach (ScopeStatement scope in _scopes)
            {
                scope.Bind(this);
            }

            // Finish the globals
            unboundAst.Bind(this);

            // Finish Binding w/ outer most scopes first.
            for (int i = _scopes.Count - 1; i >= 0; i--)
            {
                _scopes[i].FinishBind(this);
            }

            // Finish the globals
            unboundAst.FinishBind(this);

            // Run flow checker
            foreach (ScopeStatement scope in _scopes)
            {
                FlowChecker.Check(scope);
            }
        }
예제 #19
0
        public TotemAst ParseSingleStatement()
        {
            try
            {
                _globalParent = new TotemAst(false, true, _context);
                StartParsing();

                Statement statement = ParseStatement();
                EatEndOfInput();
                return FinishParsing(statement);
            }
            catch (BadSourceException bse)
            {
                throw;
            }
        }
예제 #20
0
 public virtual ScriptCode MakeScriptCode(TotemAst ast)
 {
     return new RuntimeScriptCode(ast, ast.CodeContext);
 }
예제 #21
0
        private TotemAst ParseFileWorker(bool makeModule, bool returnValue)
        {
            _globalParent = new TotemAst(makeModule, false, _context);
            StartParsing();

            List<Statement> l = new List<Statement>();

            while (true)
            {
                if (MaybeEat(TokenKind.EndOfFile)) break;

                Statement s = ParseStatement();
                l.Add(s);
            }

            Statement[] stmts = l.ToArray();

            if (returnValue && stmts.Length > 0)
            {
                ExpressionStatement exprStmt = stmts[stmts.Length - 1] as ExpressionStatement;
                if (exprStmt != null)
                {
                    var retStmt = new ReturnStatement(exprStmt.Expression);
                    stmts[stmts.Length - 1] = retStmt;
                    retStmt.SetLoc(_globalParent, exprStmt.Expression.IndexSpan);
                }
            }

            SuiteStatement ret = new SuiteStatement(stmts);
            ret.SetLoc(_globalParent, 0, GetEnd());
            return FinishParsing(ret);
        }
예제 #22
0
 public override ScriptCode MakeScriptCode(TotemAst ast)
 {
     return new TotemScriptCode(ast);
 }