Exemplo n.º 1
0
        public IdentifierOperand DefineInternal(string name, bool canHaveMultiple = false)
        {
            name = "#" + name;

            var frameScope = GetFrameScope();
            var id         = frameScope._nextId++;

            IdentifierOperand identifier;

            if (canHaveMultiple)
            {
                var    n = 0;
                string numberedName;

                while (true)
                {
                    numberedName = $"{name}_{n++}";

                    if (!IsDefined(numberedName))
                    {
                        break;
                    }
                }

                identifier = new IdentifierOperand(_localIndex, id, numberedName, false);
                _identifiers.Add(numberedName, identifier);
                return(identifier);
            }

            identifier = new IdentifierOperand(_localIndex, id, name, false);
            _identifiers.Add(name, identifier);
            return(identifier);
        }
Exemplo n.º 2
0
        public int Store(IdentifierOperand operand)
        {
            if (operand.FrameIndex != LocalIndex)
            {
                Emit(new Instruction(InstructionType.StLoc, operand));
            }
            else
            {
                Emit(new Instruction(InstructionType.StLocF, new ImmediateOperand(operand.Id)));
            }

            return(-1);
        }
Exemplo n.º 3
0
        public bool Define(string name, bool isReadOnly)
        {
            if (IsDefined(name))
            {
                return(false);
            }

            var frameScope = GetFrameScope();
            var id         = frameScope._nextId++;
            var identifier = new IdentifierOperand(_localIndex, id, name, isReadOnly);

            _identifiers.Add(name, identifier);
            return(true);
        }
Exemplo n.º 4
0
        public FunctionContext(ExpressionCompiler compiler, int frameIndex, Scope prevScope, string parentName, string name)
        {
            _instructions = new List <Instruction>();
            _loopLabels   = new IndexedStack <Tuple <LabelOperand, LabelOperand> >();

            Compiler   = compiler;
            FrameIndex = frameIndex;

            Scope = new Scope(frameIndex, 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;
        }
Exemplo n.º 5
0
 public int Store(IdentifierOperand operand)
 {
     Emit(new Instruction(InstructionType.StLoc, operand));
     return(-1);
 }