using System.Collections.Generic; using TLang.Common; namespace TLang.Common { public class BytecodeChunk { public int CurrentByteLength {get;set;}=0; public void Add(Instruction instruction) { var i = instruction as LabelInstruction; if(i != null) Offsets.Add(i.Key,CurrentByteLength); else { CurrentByteLength += instruction.CalculateLength(); Instructions.Add(instruction); } } public void SetLabelable() { foreach(var item in Instructions) { var item2 = item as ILabelable; if(item2 != null) { if(Offsets.ContainsKey(item2.Key)) item2.Value = Offsets[item2.Key]; } } } public Dictionary Offsets {get;set;}=new Dictionary(); public List Arguments {get;set;}=new List(); public List Instructions {get;set;}=new List(); } }