public override void Prepare(SpanLocation memory) { operandResolver.AddOperands(Operands, memory.Bytes); Size = 1 + Operands.Size; OpCode = Bits.BottomFour(memory.Bytes[0]); Operation = OpCode switch { 0x00 => new Operation(nameof(JZ), JZ, hasBranch: true), 0x01 => new Operation(nameof(GetSibling), GetSibling, hasBranch: true, hasStore: true), 0x02 => new Operation(nameof(GetChild), GetChild, hasStore: true, hasBranch: true), 0x03 => new Operation(nameof(GetParent), GetParent, hasStore: true), 0x05 => new Operation(nameof(Inc), Inc), 0x06 => new Operation(nameof(Dec), Dec), 0x0A => new Operation(nameof(PrintObj), PrintObj), 0x0B => new Operation(nameof(Ret), Ret), 0x0C => new Operation(nameof(Jump), Jump), 0x0d => new Operation(nameof(PrintPaddr), PrintPaddr), _ => throw new InvalidOperationException($"Unknown OP1 opcode {OpCode:X}") }; if (Operation.HasStore) { StoreResult = memory.Bytes[Size]; Size += 1; } if (Operation.HasBranch) { var branchData = machine.Memory.SpanAt(memory.Address + Size); Branch = branchResolver.ResolveBranch(branchData); Size += Branch.Size; } DumpToLog(memory, Size); }
public override void Prepare(SpanLocation memory) { Size = 1; OpCode = Bits.BottomFour(memory.Bytes[0]); Operation = OpCode switch { 0x00 => new Operation(nameof(RetTrue), RetTrue), 0x01 => new Operation(nameof(RetFalse), RetFalse), 0x02 => new Operation(nameof(Print), Print, hasText: true), 0x08 => new Operation(nameof(RetPopped), RetPopped), 0x0B => new Operation(nameof(NewLine), NewLine), _ => throw new InvalidOperationException($"Unknown OP0 opcode {OpCode:X}") }; if (Operation.HasText) { var decoded = textResolver.Decode(memory.Forward(1)); Size += decoded.BytesConsumed; Text = decoded.Text; } if (Operation.HasStore) { StoreResult = memory.Bytes[Size]; Size += 1; } if (Operation.HasBranch) { var branchData = machine.Memory.SpanAt(memory.Address + Size); Branch = branchResolver.ResolveBranch(branchData); Size += Branch.Size; } DumpToLog(memory, Size); }