runtime.MakeSmallMap

This commit is contained in:
xushiwei
2024-05-01 07:37:38 +08:00
parent ed8ffb228b
commit 673b9d9a5c
6 changed files with 67 additions and 3 deletions

View File

@@ -1,10 +1,13 @@
package main
/*
import (
"github.com/goplus/llgo/internal/runtime/c"
)
*/
func main() {
a := map[int]int{23: 100, 7: 29}
c.Printf(c.Str("Hello %d\n"), a[23])
_ = a
// c.Printf(c.Str("Hello %d\n"), a[23])
}

View File

@@ -0,0 +1,26 @@
; ModuleID = 'main'
source_filename = "main"
@"main.init$guard" = global ptr null
define void @main.init() {
_llgo_0:
%0 = load i1, ptr @"main.init$guard", align 1
br i1 %0, label %_llgo_2, label %_llgo_1
_llgo_1: ; preds = %_llgo_0
store i1 true, ptr @"main.init$guard", align 1
br label %_llgo_2
_llgo_2: ; preds = %_llgo_1, %_llgo_0
ret void
}
define void @main() {
_llgo_0:
call void @main.init()
%0 = call ptr @"github.com/goplus/llgo/internal/runtime.MakeSmallMap"()
ret void
}
declare ptr @"github.com/goplus/llgo/internal/runtime.MakeSmallMap"()

View File

@@ -489,6 +489,10 @@ func (p *context) compileInstr(b llssa.Builder, instr ssa.Instruction) {
elseb := fn.Block(succs[1].Index)
b.If(cond, thenb, elseb)
case *ssa.MapUpdate:
m := p.compileValue(b, v.Map)
key := p.compileValue(b, v.Key)
val := p.compileValue(b, v.Value)
b.MapUpdate(m, key, val)
case *ssa.Panic:
arg := p.compileValue(b, v.X).Do()
b.Panic(arg)

View File

@@ -29,7 +29,7 @@ func testCompile(t *testing.T, src, expected string) {
}
func TestFromTestrt(t *testing.T) {
cltest.FromDir(t, "map", "./_testrt", true)
cltest.FromDir(t, "", "./_testrt", true)
}
func TestFromTestdata(t *testing.T) {