interp: move some often-repeated code into a function

This commit is contained in:
Ayke van Laethem
2023-05-20 17:14:01 +02:00
committed by Ron Evans
parent 2fb866ca86
commit 54c07b7de8
2 changed files with 20 additions and 44 deletions
+16
View File
@@ -373,6 +373,22 @@ type literalValue struct {
value interface{}
}
// Make a literalValue given the number of bits.
func makeLiteralInt(value uint64, bits int) literalValue {
switch bits {
case 64:
return literalValue{value}
case 32:
return literalValue{uint32(value)}
case 16:
return literalValue{uint16(value)}
case 8:
return literalValue{uint8(value)}
default:
panic("unknown integer size")
}
}
func (v literalValue) len(r *runner) uint32 {
switch v.value.(type) {
case uint64: