Move operand type lists into the vm

This commit is contained in:
Ian Gulliver
2021-11-20 17:26:58 -10:00
parent 30ff003494
commit ae771823b0
4 changed files with 60 additions and 60 deletions

View File

@@ -44,7 +44,7 @@ func disassembleInstruction(in *vm.Instruction) (string, error) {
nameByOpCode[in.OpCode],
}
for i, t := range operandsByOpCode[in.OpCode] {
for i, t := range vm.OperandsByOpCode[in.OpCode] {
op, err := disassembleOperand(in.Operands[i], t)
if err != nil {
return "", err
@@ -58,7 +58,7 @@ func disassembleInstruction(in *vm.Instruction) (string, error) {
return encoded, nil
}
func disassembleOperand(op *vm.Operand, t operandType) (string, error) {
func disassembleOperand(op *vm.Operand, t vm.OperandNumericType) (string, error) {
switch op.Type {
case vm.GlobalMemoryIndex:
return fmt.Sprintf("g%d", op.Value), nil
@@ -68,13 +68,13 @@ func disassembleOperand(op *vm.Operand, t operandType) (string, error) {
case vm.Literal:
switch t {
case u:
case vm.OperandUnsigned:
return fmt.Sprintf("%d", op.Value), nil
case s:
case vm.OperandSigned:
return fmt.Sprintf("%+d", int64(op.Value)), nil
case us:
case vm.OperandSignedOrUnsigned:
// Take our best guess
if op.Value > math.MaxInt64 {
return fmt.Sprintf("%+d", int64(op.Value)), nil