compiler: support compile-time hashmap with int keys

This commit is contained in:
Ayke van Laethem
2018-09-15 01:03:22 +02:00
parent 152e12e4b0
commit 38efc5653d
2 changed files with 19 additions and 5 deletions
+16 -2
View File
@@ -1016,8 +1016,22 @@ func (c *Compiler) getInterpretedValue(value Value) (llvm.Value, error) {
return llvm.Value{}, nil
}
keyString := constant.StringVal(key.(*ConstValue).Expr.Value)
hash := stringhash(&keyString)
constVal := key.(*ConstValue).Expr
var keyBuf []byte
switch constVal.Type().Underlying().(*types.Basic).Kind() {
case types.String:
keyBuf = []byte(constant.StringVal(constVal.Value))
case types.Int:
keyBuf = make([]byte, c.targetData.TypeAllocSize(c.intType))
n, _ := constant.Uint64Val(constVal.Value)
for i := range keyBuf {
keyBuf[i] = byte(n)
n >>= 8
}
default:
return llvm.Value{}, errors.New("todo: init: map key not implemented: " + constVal.Type().Underlying().String())
}
hash := hashmapHash(keyBuf)
if i%8 == 0 && i != 0 {
// Bucket is full, create a new one.