diff options
author | Konstantin Yegupov <[email protected]> | 2019-01-30 23:22:29 +1000 |
---|---|---|
committer | Ayke van Laethem <[email protected]> | 2019-01-31 16:34:59 +0100 |
commit | f8a1e5f4491b8206b23f351721c9b10e37526c8c (patch) | |
tree | 0a030aea7e49be6e0ffcbed1f195b733069fe26b /interp/values.go | |
parent | 0308c92e67f833ea83c9699c78c26a192bff89dc (diff) | |
download | tinygo-f8a1e5f4491b8206b23f351721c9b10e37526c8c.tar.gz tinygo-f8a1e5f4491b8206b23f351721c9b10e37526c8c.zip |
interp: support map literals with integer keys
Diffstat (limited to 'interp/values.go')
-rw-r--r-- | interp/values.go | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/interp/values.go b/interp/values.go index 97c414c02..c4f6e302d 100644 --- a/interp/values.go +++ b/interp/values.go @@ -561,6 +561,38 @@ func (v *MapValue) PutString(keyBuf, keyLen, valPtr Value) { v.Values = append(v.Values, &LocalValue{v.Eval, value}) } +// PutBinary does a map assign operation. +func (v *MapValue) PutBinary(keyPtr, valPtr Value) { + if !v.Underlying.IsNil() { + panic("map already created") + } + + var value llvm.Value + switch valPtr := valPtr.(type) { + case *PointerCastValue: + value = valPtr.Underlying.Load() + if v.ValueType.IsNil() { + v.ValueType = value.Type() + if int(v.Eval.TargetData.TypeAllocSize(v.ValueType)) != v.ValueSize { + panic("interp: map store value type has the wrong size") + } + } else { + if value.Type() != v.ValueType { + panic("interp: map store value type is inconsistent") + } + } + default: + panic("interp: todo: handle map value pointer") + } + + key := keyPtr.(*PointerCastValue).Underlying.Load() + v.KeyType = key.Type() + + // TODO: avoid duplicate keys + v.Keys = append(v.Keys, &LocalValue{v.Eval, key}) + v.Values = append(v.Values, &LocalValue{v.Eval, value}) +} + // Get FNV-1a hash of this string. // // https://en.wikipedia.org/wiki/Fowler%E2%80%93Noll%E2%80%93Vo_hash_function#FNV-1a_hash |