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); }
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; }
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); } }
public void LinkLabels(DataElement.Ctrl a, DataElement.Ctrl b) { a.LinkedElement = b; b.LinkedElement = a; }
protected void EmitBlockEnd(DataElement.Ctrl start) { var end = EmitLabel("}"); LinkLabels(start, end); }
protected void LinkLabels(DataElement.Ctrl a, DataElement.Ctrl b) { a.LinkedElement = b; b.LinkedElement = a; }
public LabelInstruction(DataElement.Ctrl label, InstructionList instructionList) : base(instructionList) { Label = label; }