Пример #1
0
        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;
        }
Пример #2
0
        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>();
        }
Пример #3
0
        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;
        }
Пример #4
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;
        }
Пример #5
0
        public virtual void PopScope()
        {
            var popAction = Scope.PopAction;
            if (popAction != null)
                popAction();

            Scope = Scope.Previous;
            Compiler.ScopeDepth--;
        }
Пример #6
0
 public void PushScope()
 {
     _currentScope = new Scope(FrameIndex, _currentScope);
 }
Пример #7
0
 public void PopScope()
 {
     _currentScope = _currentScope.Previous;
 }