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; }
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 } ); }
public void SetLoc(TotemAst globalParent, IndexSpan span) { _span = span; _parent = globalParent; }
public void SetLoc(TotemAst globalParent, int start, int end) { _span = new IndexSpan(start, end > start ? end - start : start); _parent = globalParent; }
public abstract LightLambdaExpression ReduceAst(TotemAst instance, string name);
public virtual void PrepareScope(TotemAst ast, ReadOnlyCollectionBuilder<MSAst.ParameterExpression> locals, List<MSAst.Expression> init) { }
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; } }
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; } }
public override bool Walk(TotemAst node) { return true; }
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); }
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)); }
public LookupVisitor(TotemAst ast, MSAst.Expression globalContext) { _globalContext = globalContext; _curScope = ast; }
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)); }
internal static void BindAst(TotemAst ast, CompilerContext context) { Assert.NotNull(ast, context); TotemNameBinder binder = new TotemNameBinder(context); binder.Bind(ast); }
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; }
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); } }
public TotemAst ParseSingleStatement() { try { _globalParent = new TotemAst(false, true, _context); StartParsing(); Statement statement = ParseStatement(); EatEndOfInput(); return FinishParsing(statement); } catch (BadSourceException bse) { throw; } }
public virtual ScriptCode MakeScriptCode(TotemAst ast) { return new RuntimeScriptCode(ast, ast.CodeContext); }
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); }
public override ScriptCode MakeScriptCode(TotemAst ast) { return new TotemScriptCode(ast); }