Пример #1
0
        protected DataElement.Ctrl CreateOperator(string operation)
        {
            // try to re-use existing operator symbol
            if (_usedOperators.ContainsKey(operation))
            {
                return(_usedOperators[operation]);
            }

            var op = new DataElement.Ctrl(_dataSet.CreateScriptValue(operation));

            _usedOperators[operation] = op;
            return(op);
        }
Пример #2
0
        public void Visit(BlockStmt stmt)
        {
            var start = EmitBlockStart();

            foreach (var statement in stmt.Statements)
            {
                // emit instructions for this statement
                statement.Accept(this);

                // all locals should be freed at the end of each statement
                Debug.Assert(!_usedLocals.ContainsValue(true), "Local not freed after statement evaluation");
            }

            EmitBlockEnd(start);
            BlockStart = start;
        }
Пример #3
0
        public DataElement.Ctrl CreateLabel(string name, string idString = null, string linkString = null)
        {
            if (!int.TryParse(idString, out int id))
            {
                id = -1;
            }
            if (!int.TryParse(linkString, out int link))
            {
                link = -1;
            }

            if (Format.Yks.BlockLabels.Contains(name))
            {
                // create new label
                var label = new DataElement.Ctrl(CreateScriptValue(name))
                {
                    Id = id
                };
                if (id == -1 || link == -1)
                {
                    throw new FormatException($"Block label must specify an id and a link: ':{id}:{name} [{link}]'");
                }

                // register label
                Debug.Assert(!BlockLabels.ContainsKey(id), $"Duplicate label id: ':{id}:{name} [{link}]'");
                BlockLabels[id] = label;

                // try to link block start and end
                if (BlockLabels.ContainsKey(link))
                {
                    LinkLabels(BlockLabels[link], label);
                }
                return(label);
            }
            else
            {
                DataElement.Ctrl label;
                if (!UniqueLabels.ContainsKey(name))
                {
                    // register new unique label
                    // may be caused by a reference instead of the
                    // label declaration (-> don't set id here)
                    label = new DataElement.Ctrl(CreateScriptValue(name));
                    UniqueLabels[name] = label;
                }
                else
                {
                    label = UniqueLabels[name];
                }

                // set id on label declaration only
                if (id != -1)
                {
                    label.Id = id;
                }

                if (link == -1)
                {
                    return(label);
                }

                // link the label to itself
                Debug.Assert(link == id, $"Unique label must link to itself: ':{id}:{name} [{link}]'");
                label.LinkedElement = label;
                return(label);
            }
        }
Пример #4
0
 public void LinkLabels(DataElement.Ctrl a, DataElement.Ctrl b)
 {
     a.LinkedElement = b;
     b.LinkedElement = a;
 }
Пример #5
0
        protected void EmitBlockEnd(DataElement.Ctrl start)
        {
            var end = EmitLabel("}");

            LinkLabels(start, end);
        }
Пример #6
0
 protected void LinkLabels(DataElement.Ctrl a, DataElement.Ctrl b)
 {
     a.LinkedElement = b;
     b.LinkedElement = a;
 }
Пример #7
0
 public LabelInstruction(DataElement.Ctrl label, InstructionList instructionList) : base(instructionList)
 {
     Label = label;
 }