mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-13 15:33:40 +00:00
Implement len() for map types
This commit is contained in:
@@ -1095,6 +1095,13 @@ func (c *Compiler) parseBuiltin(frame *Frame, args []ssa.Value, callName string)
|
||||
default:
|
||||
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:
|
||||
return c.builder.CreateExtractValue(value, 1, "len"), nil
|
||||
default:
|
||||
|
||||
Reference in New Issue
Block a user