From 4d04c56efbdfc9b33d6148c96ba2b0dcd6f93742 Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Sun, 23 Aug 2020 13:56:55 +0300 Subject: [PATCH] compiler: make `toShortForm` accept an opcode --- pkg/compiler/codegen.go | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/pkg/compiler/codegen.go b/pkg/compiler/codegen.go index 44cee3b30..3b7771ddf 100644 --- a/pkg/compiler/codegen.go +++ b/pkg/compiler/codegen.go @@ -1699,13 +1699,13 @@ func shortenJumps(b []byte, offsets []int) []byte { // 2. Convert instructions. copyOffset := 0 l := len(offsets) - b[offsets[0]] = toShortForm(b[offsets[0]]) + b[offsets[0]] = byte(toShortForm(opcode.Opcode(b[offsets[0]]))) for i := 0; i < l; i++ { start := offsets[i] + 2 end := len(b) if i != l-1 { end = offsets[i+1] + 2 - b[offsets[i+1]] = toShortForm(b[offsets[i+1]]) + b[offsets[i+1]] = byte(toShortForm(opcode.Opcode(b[offsets[i+1]]))) } copy(b[start-copyOffset:], b[start+3:end]) copyOffset += longToShortRemoveCount @@ -1731,28 +1731,28 @@ func calcOffsetCorrection(ip, target int, offsets []int) int { return cnt } -func toShortForm(b byte) byte { - switch op := opcode.Opcode(b); op { +func toShortForm(op opcode.Opcode) opcode.Opcode { + switch op { case opcode.JMPL: - return byte(opcode.JMP) + return opcode.JMP case opcode.JMPIFL: - return byte(opcode.JMPIF) + return opcode.JMPIF case opcode.JMPIFNOTL: - return byte(opcode.JMPIFNOT) + return opcode.JMPIFNOT case opcode.JMPEQL: - return byte(opcode.JMPEQ) + return opcode.JMPEQ case opcode.JMPNEL: - return byte(opcode.JMPNE) + return opcode.JMPNE case opcode.JMPGTL: - return byte(opcode.JMPGT) + return opcode.JMPGT case opcode.JMPGEL: - return byte(opcode.JMPGE) + return opcode.JMPGE case opcode.JMPLEL: - return byte(opcode.JMPLE) + return opcode.JMPLE case opcode.JMPLTL: - return byte(opcode.JMPLT) + return opcode.JMPLT case opcode.CALLL: - return byte(opcode.CALL) + return opcode.CALL default: panic(fmt.Errorf("invalid opcode: %s", op)) }