Commit f6ba06e8 authored by Kirill Smelkov's avatar Kirill Smelkov Committed by Kamil Kisiel

Make all opcode constants to have type byte

It was probably a thinko in d00e99e7 (Add more opcodes so we can read
Graphite's Carbon stream) which changed opcodes from string ("X") to
character ('X') constants and marked the first opcode with byte type,
probably with the idea that following opcodes will have the same type.

Unfortunately it is not so as the following program demonstrates:

	package main

	const (
	        opAAA byte = 'a'
	        opBBB      = 'b'
	)

	func main() {
	        op := opBBB
	        if true {
	                op = opAAA	// <-- line 11
	        }
	        println(op)
	}

	--> ./bc.go:11:6: cannot use opAAA (type byte) as type rune in assignment

Similarly if we try comparing opcodes, it also results in compile error:

	func main() {
	        op := opBBB
	        if op == opAAA {	// <-- line 10
	                panic(0)
	        }
	        println(op)
	}

	--> ./bc.go:10:8: invalid operation: op == opAAA (mismatched types rune and byte)

Since in the following patches it will be handy for encoder to e.g. set default
opcode first, and then change it under some conditions to another opcode,
exactly the same compile error(s) will pop up.

So let's fix all opcode constants to have their type as byte to avoid such
unexpected errors.
parent 0d8e88fa
......@@ -19,70 +19,70 @@ import (
// Opcodes
const (
opMark byte = '(' // push special markobject on stack
opStop = '.' // every pickle ends with STOP
opPop = '0' // discard topmost stack item
opPopMark = '1' // discard stack top through topmost markobject
opDup = '2' // duplicate top stack item
opFloat = 'F' // push float object; decimal string argument
opInt = 'I' // push integer or bool; decimal string argument
opBinint = 'J' // push four-byte signed int
opBinint1 = 'K' // push 1-byte unsigned int
opLong = 'L' // push long; decimal string argument
opBinint2 = 'M' // push 2-byte unsigned int
opNone = 'N' // push None
opPersid = 'P' // push persistent object; id is taken from string arg
opBinpersid = 'Q' // " " " ; " " " " stack
opReduce = 'R' // apply callable to argtuple, both on stack
opString = 'S' // push string; NL-terminated string argument
opBinstring = 'T' // push string; counted binary string argument
opShortBinstring = 'U' // " " ; " " " " < 256 bytes
opUnicode = 'V' // push Unicode string; raw-unicode-escaped"d argument
opBinunicode = 'X' // " " " ; counted UTF-8 string argument
opAppend = 'a' // append stack top to list below it
opBuild = 'b' // call __setstate__ or __dict__.update()
opGlobal = 'c' // push self.find_class(modname, name); 2 string args
opDict = 'd' // build a dict from stack items
opEmptyDict = '}' // push empty dict
opAppends = 'e' // extend list on stack by topmost stack slice
opGet = 'g' // push item from memo on stack; index is string arg
opBinget = 'h' // " " " " " " ; " " 1-byte arg
opInst = 'i' // build & push class instance
opLongBinget = 'j' // push item from memo on stack; index is 4-byte arg
opList = 'l' // build list from topmost stack items
opEmptyList = ']' // push empty list
opObj = 'o' // build & push class instance
opPut = 'p' // store stack top in memo; index is string arg
opBinput = 'q' // " " " " " ; " " 1-byte arg
opLongBinput = 'r' // " " " " " ; " " 4-byte arg
opSetitem = 's' // add key+value pair to dict
opTuple = 't' // build tuple from topmost stack items
opEmptyTuple = ')' // push empty tuple
opSetitems = 'u' // modify dict by adding topmost key+value pairs
opBinfloat = 'G' // push float; arg is 8-byte float encoding
opStop byte = '.' // every pickle ends with STOP
opPop byte = '0' // discard topmost stack item
opPopMark byte = '1' // discard stack top through topmost markobject
opDup byte = '2' // duplicate top stack item
opFloat byte = 'F' // push float object; decimal string argument
opInt byte = 'I' // push integer or bool; decimal string argument
opBinint byte = 'J' // push four-byte signed int
opBinint1 byte = 'K' // push 1-byte unsigned int
opLong byte = 'L' // push long; decimal string argument
opBinint2 byte = 'M' // push 2-byte unsigned int
opNone byte = 'N' // push None
opPersid byte = 'P' // push persistent object; id is taken from string arg
opBinpersid byte = 'Q' // " " " ; " " " " stack
opReduce byte = 'R' // apply callable to argtuple, both on stack
opString byte = 'S' // push string; NL-terminated string argument
opBinstring byte = 'T' // push string; counted binary string argument
opShortBinstring byte = 'U' // " " ; " " " " < 256 bytes
opUnicode byte = 'V' // push Unicode string; raw-unicode-escaped"d argument
opBinunicode byte = 'X' // " " " ; counted UTF-8 string argument
opAppend byte = 'a' // append stack top to list below it
opBuild byte = 'b' // call __setstate__ or __dict__.update()
opGlobal byte = 'c' // push self.find_class(modname, name); 2 string args
opDict byte = 'd' // build a dict from stack items
opEmptyDict byte = '}' // push empty dict
opAppends byte = 'e' // extend list on stack by topmost stack slice
opGet byte = 'g' // push item from memo on stack; index is string arg
opBinget byte = 'h' // " " " " " " ; " " 1-byte arg
opInst byte = 'i' // build & push class instance
opLongBinget byte = 'j' // push item from memo on stack; index is 4-byte arg
opList byte = 'l' // build list from topmost stack items
opEmptyList byte = ']' // push empty list
opObj byte = 'o' // build & push class instance
opPut byte = 'p' // store stack top in memo; index is string arg
opBinput byte = 'q' // " " " " " ; " " 1-byte arg
opLongBinput byte = 'r' // " " " " " ; " " 4-byte arg
opSetitem byte = 's' // add key+value pair to dict
opTuple byte = 't' // build tuple from topmost stack items
opEmptyTuple byte = ')' // push empty tuple
opSetitems byte = 'u' // modify dict by adding topmost key+value pairs
opBinfloat byte = 'G' // push float; arg is 8-byte float encoding
opTrue = "I01\n" // not an opcode; see INT docs in pickletools.py
opFalse = "I00\n" // not an opcode; see INT docs in pickletools.py
// Protocol 2
opProto = '\x80' // identify pickle protocol
opNewobj = '\x81' // build object by applying cls.__new__ to argtuple
opExt1 = '\x82' // push object from extension registry; 1-byte index
opExt2 = '\x83' // ditto, but 2-byte index
opExt4 = '\x84' // ditto, but 4-byte index
opTuple1 = '\x85' // build 1-tuple from stack top
opTuple2 = '\x86' // build 2-tuple from two topmost stack items
opTuple3 = '\x87' // build 3-tuple from three topmost stack items
opNewtrue = '\x88' // push True
opNewfalse = '\x89' // push False
opLong1 = '\x8a' // push long from < 256 bytes
opLong4 = '\x8b' // push really big long
opProto byte = '\x80' // identify pickle protocol
opNewobj byte = '\x81' // build object by applying cls.__new__ to argtuple
opExt1 byte = '\x82' // push object from extension registry; 1-byte index
opExt2 byte = '\x83' // ditto, but 2-byte index
opExt4 byte = '\x84' // ditto, but 4-byte index
opTuple1 byte = '\x85' // build 1-tuple from stack top
opTuple2 byte = '\x86' // build 2-tuple from two topmost stack items
opTuple3 byte = '\x87' // build 3-tuple from three topmost stack items
opNewtrue byte = '\x88' // push True
opNewfalse byte = '\x89' // push False
opLong1 byte = '\x8a' // push long from < 256 bytes
opLong4 byte = '\x8b' // push really big long
// Protocol 4
opShortBinUnicode = '\x8c' // push short string; UTF-8 length < 256 bytes
opStackGlobal = '\x93' // same as OpGlobal but using names on the stacks
opMemoize = '\x94' // store top of the stack in memo
opFrame = '\x95' // indicate the beginning of a new frame
opShortBinUnicode byte = '\x8c' // push short string; UTF-8 length < 256 bytes
opStackGlobal byte = '\x93' // same as OpGlobal but using names on the stacks
opMemoize byte = '\x94' // store top of the stack in memo
opFrame byte = '\x95' // indicate the beginning of a new frame
)
var errNotImplemented = errors.New("unimplemented opcode")
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment