public Scope(int id, int argIndex, int localIndex, Scope previous, Action popAction = null) { _identifiers = new Dictionary<string, IdentifierOperand>(); _argIndex = argIndex; _localIndex = localIndex; _nextId = 0; Id = id; Previous = previous; PopAction = popAction; }
public ExpressionCompiler(bool generateDebugInfo = true) { _contexts = new List<FunctionContext>(); _currentScope = null; _labelIndex = 0; FrameIndex = -1; GeneratingDebugInfo = generateDebugInfo; NumberPool = new ConstantPool<double>(); StringPool = new ConstantPool<string>(); }
public FunctionContext(ExpressionCompiler compiler, int argIndex, int localIndex, Scope prevScope, string parentName, string name) { _instructions = new List<Instruction>(); _loopLabels = new IndexedStack<Tuple<LabelOperand, LabelOperand>>(); Compiler = compiler; ArgIndex = argIndex; LocalIndex = localIndex; Scope = prevScope; ParentName = parentName; Name = name; FullName = string.Format("{0}{1}{2}", parentName, string.IsNullOrEmpty(parentName) ? "" : ".", Name ?? ""); AssignedName = name != null ? prevScope.Get(name) : null; Label = Compiler.MakeLabel("function"); IdentifierCount = 0; }
public virtual void PushScope() { Compiler.ScopeDepth++; var scopeId = Compiler.ScopeId++; // don't do extra work if we dont need it if (Compiler.Options.DebugInfo <= MondDebugInfoLevel.StackTrace) { Scope = new Scope(scopeId, ArgIndex, LocalIndex, Scope); return; } var startLabel = MakeLabel("scopeStart"); var endLabel = MakeLabel("scopeEnd"); var newScope = new Scope(scopeId, ArgIndex, LocalIndex, Scope, () => Bind(endLabel)); Emit(new Instruction(InstructionType.Scope, new IInstructionOperand[] { new ImmediateOperand(scopeId), new ImmediateOperand(Compiler.ScopeDepth), new ImmediateOperand(Scope != null ? Scope.Id : -1), startLabel, endLabel, new DeferredOperand<ListOperand<DebugIdentifierOperand>>(() => { var operands = newScope.Identifiers .Select(i => new DebugIdentifierOperand(String(i.Name), i.IsReadOnly, i.FrameIndex, i.Id)) .ToList(); return new ListOperand<DebugIdentifierOperand>(operands); }) })); Bind(startLabel); Scope = newScope; }
public virtual void PopScope() { var popAction = Scope.PopAction; if (popAction != null) popAction(); Scope = Scope.Previous; Compiler.ScopeDepth--; }
public void PushScope() { _currentScope = new Scope(FrameIndex, _currentScope); }
public void PopScope() { _currentScope = _currentScope.Previous; }