aboutsummaryrefslogtreecommitdiffhomepage
path: root/interp/memory.go
diff options
context:
space:
mode:
authorAyke van Laethem <[email protected]>2023-05-20 17:14:01 +0200
committerRon Evans <[email protected]>2023-05-20 23:57:20 +0200
commit54c07b7de81d04cda442bee10dabdb8cdb9a1e58 (patch)
treef7592353ae7c903351f69cb80ca95df08605f425 /interp/memory.go
parent2fb866ca86e16d527e0c1413d8cf1093e217b4c2 (diff)
downloadtinygo-54c07b7de81d04cda442bee10dabdb8cdb9a1e58.tar.gz
tinygo-54c07b7de81d04cda442bee10dabdb8cdb9a1e58.zip
interp: move some often-repeated code into a function
Diffstat (limited to 'interp/memory.go')
-rw-r--r--interp/memory.go16
1 files changed, 16 insertions, 0 deletions
diff --git a/interp/memory.go b/interp/memory.go
index f96387062..2065bcdf5 100644
--- a/interp/memory.go
+++ b/interp/memory.go
@@ -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: