Revert "runtime: map; llgo/ssa: MapUpdate"

This commit is contained in:
xushiwei
2024-06-14 22:50:23 +08:00
committed by GitHub
parent 78b8455bba
commit 5e45e38481
26 changed files with 149 additions and 3623 deletions

View File

@@ -159,10 +159,6 @@ func (b *Builder) TypeName(t types.Type) (ret string, pub bool) {
return "_llgo_any", true
}
return b.InterfaceName(t)
case *types.Map:
key, pub1 := b.TypeName(t.Key())
elem, pub2 := b.TypeName(t.Elem())
return fmt.Sprintf("map[%s]%s", key, elem), pub1 && pub2
}
log.Panicf("todo: %T\n", t)
return

View File

@@ -66,8 +66,6 @@ func (b Builder) abiTypeOf(t types.Type) func() Expr {
return b.abiFuncOf(t)
case *types.Slice:
return b.abiSliceOf(t)
case *types.Map:
return b.abiMapOf(t)
case *types.Array:
return b.abiArrayOf(t)
}
@@ -246,14 +244,6 @@ func (b Builder) abiPointerOf(t *types.Pointer) func() Expr {
}
}
func (b Builder) abiMapOf(t *types.Map) func() Expr {
key := b.abiType(t.Key())
elem := b.abiType(t.Elem())
return func() Expr {
return b.Call(b.Pkg.rtFunc("MapOf"), key, elem)
}
}
func (b Builder) abiSliceOf(t *types.Slice) func() Expr {
elem := b.abiType(t.Elem())
return func() Expr {

View File

@@ -360,63 +360,8 @@ func (b Builder) MapUpdate(m, k, v Expr) {
if debugInstr {
log.Printf("MapUpdate %v[%v] = %v\n", m.impl, k.impl, v.impl)
}
t := m.Type
if t.kind != vkMap {
panic("TODO: not a map")
}
tabi := b.abiType(t.raw.Type)
prog := b.Prog
mptr := b.dupAlloca(m)
ptrimpl := b.InlineCall(b.Pkg.rtFunc("MapAssign"), tabi, mptr, k).impl
ptr := Expr{ptrimpl, prog.Pointer(v.Type)}
b.Store(ptr, v) // TODO(xsw): indirect store
}
// -----------------------------------------------------------------------------
// The Range instruction yields an iterator over the domain and range
// of X, which must be a string or map.
//
// Elements are accessed via Next.
//
// Type() returns an opaque and degenerate "rangeIter" type.
//
// Pos() returns the ast.RangeStmt.For.
//
// Example printed form:
//
// t0 = range "hello":string
func (b Builder) Range(x Expr) Expr {
switch x.kind {
case vkString:
return b.InlineCall(b.Pkg.rtFunc("NewStringIter"), x)
}
panic("todo")
}
// The Next instruction reads and advances the (map or string)
// iterator Iter and returns a 3-tuple value (ok, k, v). If the
// iterator is not exhausted, ok is true and k and v are the next
// elements of the domain and range, respectively. Otherwise ok is
// false and k and v are undefined.
//
// Components of the tuple are accessed using Extract.
//
// The IsString field distinguishes iterators over strings from those
// over maps, as the Type() alone is insufficient: consider
// map[int]rune.
//
// Type() returns a *types.Tuple for the triple (ok, k, v).
// The types of k and/or v may be types.Invalid.
//
// Example printed form:
//
// t1 = next t0
func (b Builder) Next(iter Expr, isString bool) (ret Expr) {
if isString {
return b.InlineCall(b.Pkg.rtFunc("StringIterNext"), iter)
}
panic("todo")
// TODO(xsw)
// panic("todo")
}
// -----------------------------------------------------------------------------

View File

@@ -669,6 +669,53 @@ func castPtr(b llvm.Builder, x llvm.Value, t llvm.Type) llvm.Value {
// -----------------------------------------------------------------------------
// The Range instruction yields an iterator over the domain and range
// of X, which must be a string or map.
//
// Elements are accessed via Next.
//
// Type() returns an opaque and degenerate "rangeIter" type.
//
// Pos() returns the ast.RangeStmt.For.
//
// Example printed form:
//
// t0 = range "hello":string
func (b Builder) Range(x Expr) Expr {
switch x.kind {
case vkString:
return b.InlineCall(b.Pkg.rtFunc("NewStringIter"), x)
}
panic("todo")
}
// The Next instruction reads and advances the (map or string)
// iterator Iter and returns a 3-tuple value (ok, k, v). If the
// iterator is not exhausted, ok is true and k and v are the next
// elements of the domain and range, respectively. Otherwise ok is
// false and k and v are undefined.
//
// Components of the tuple are accessed using Extract.
//
// The IsString field distinguishes iterators over strings from those
// over maps, as the Type() alone is insufficient: consider
// map[int]rune.
//
// Type() returns a *types.Tuple for the triple (ok, k, v).
// The types of k and/or v may be types.Invalid.
//
// Example printed form:
//
// t1 = next t0
func (b Builder) Next(iter Expr, isString bool) (ret Expr) {
if isString {
return b.InlineCall(b.Pkg.rtFunc("StringIterNext"), iter)
}
panic("todo")
}
// -----------------------------------------------------------------------------
// The MakeClosure instruction yields a closure value whose code is
// Fn and whose free variables' values are supplied by Bindings.
//

View File

@@ -107,15 +107,16 @@ func aggregateInit(b llvm.Builder, ptr llvm.Value, tll llvm.Type, flds ...llvm.V
}
}
func (b Builder) dupAlloca(v Expr) Expr {
/*
func (b Builder) dupMalloc(v Expr) Expr {
prog := b.Prog
n := prog.SizeOf(v.Type)
tptr := prog.Pointer(v.Type)
ptr := b.Alloca(prog.Val(uintptr(n))).impl
ret := Expr{ptr, tptr}
b.Store(ret, v)
return ret
ptr := b.malloc(prog.Val(uintptr(n))).impl
b.Store(Expr{ptr, tptr}, v)
return Expr{ptr, tptr}
}
*/
// -----------------------------------------------------------------------------

View File

@@ -27,17 +27,6 @@ import (
"github.com/goplus/llvm"
)
func TestMapUpdate(t *testing.T) {
var b Builder
var m = Expr{Type: &aType{}}
defer func() {
if e := recover(); e == nil {
t.Log("MapUpdate: no error?")
}
}()
b.MapUpdate(m, m, m)
}
func TestEndDefer(t *testing.T) {
prog := NewProgram(nil)
pkg := prog.NewPackage("foo", "foo")