/// <summary> /// Enter a new segment. When this method returns <see cref="Count"/> will be zero, and the stack will appear empty. /// </summary> /// <returns>An <see cref="IDisposable"/> that will return the stack to the previously active segment when disposed.</returns> public IDisposable EnterSegment() { var reset = new StackSegment(this, _activeSegmentBase); _activeSegmentBase = _next; return(reset); }
public string Emit() { StringBuilder sb = new StringBuilder(); StackSegment stack = new StackSegment(); sb.AppendLine(stack.Generate()); if (mDataSegment.Count > 0) { sb.AppendLine(DataSegmentElement.GetDataSegmentKeyword()); foreach (DataSegmentElement data in mDataSegment) { sb.AppendLine(data.Generate()); } } sb.AppendLine(CodeSegmentElement.GetCodeSegmentKeyword()); if (mCodeSegment.ContainsKey("init")) { sb.AppendLine("init:"); foreach (CodeSegmentElement elm in mCodeSegment["init"]) { sb.AppendLine(elm.Generate()); } mCodeSegment.Remove("init"); } if (mCodeSegment.ContainsKey("main")) { sb.AppendLine("start:"); sb.AppendLine(Commands.GetCommand(Command.call, "main")); sb.AppendLine("teminate:"); sb.AppendLine(Commands.GetCommand(Command.exit)); sb.AppendLine(Commands.GetCommand(Command.nop)); } foreach (string label in mCodeSegment.Keys) { foreach (CodeSegmentElement elm in mCodeSegment[label]) { sb.AppendLine(elm.Generate()); } } return(sb.ToString()); }