Implement len() for map types
Этот коммит содержится в:
родитель
005665aee6
коммит
e884221fad
2 изменённых файлов: 8 добавлений и 0 удалений
|
@ -1095,6 +1095,13 @@ func (c *Compiler) parseBuiltin(frame *Frame, args []ssa.Value, callName string)
|
||||||
default:
|
default:
|
||||||
return llvm.Value{}, errors.New("todo: len: unknown basic type")
|
return llvm.Value{}, errors.New("todo: len: unknown basic type")
|
||||||
}
|
}
|
||||||
|
case *types.Map:
|
||||||
|
indices := []llvm.Value{
|
||||||
|
llvm.ConstInt(llvm.Int32Type(), 0, false),
|
||||||
|
llvm.ConstInt(llvm.Int32Type(), 2, false), // hashmap.count
|
||||||
|
}
|
||||||
|
ptr := c.builder.CreateGEP(value, indices, "lenptr")
|
||||||
|
return c.builder.CreateLoad(ptr, "len"), nil
|
||||||
case *types.Slice:
|
case *types.Slice:
|
||||||
return c.builder.CreateExtractValue(value, 1, "len"), nil
|
return c.builder.CreateExtractValue(value, 1, "len"), nil
|
||||||
default:
|
default:
|
||||||
|
|
|
@ -98,6 +98,7 @@ func hashmapSet(m *hashmap, key string, value unsafe.Pointer) {
|
||||||
bucket = bucket.next
|
bucket = bucket.next
|
||||||
}
|
}
|
||||||
if emptySlotKey != nil {
|
if emptySlotKey != nil {
|
||||||
|
m.count++
|
||||||
*emptySlotKey = key
|
*emptySlotKey = key
|
||||||
memcpy(emptySlotValue, value, uintptr(m.valueSize))
|
memcpy(emptySlotValue, value, uintptr(m.valueSize))
|
||||||
*emptySlotTophash = tophash
|
*emptySlotTophash = tophash
|
||||||
|
|
Загрузка…
Создание таблицы
Сослаться в новой задаче