From df13e3ab8294d23b428fb0772fa8cbc5ffb93ce4 Mon Sep 17 00:00:00 2001 From: xushiwei Date: Mon, 27 May 2024 09:56:42 +0800 Subject: [PATCH] PrintIface --- cl/_testgo/errors/in.go | 21 +++++++++++++++++++++ cl/_testgo/errors/out.ll | 0 internal/runtime/z_print.go | 4 ++++ ssa/expr.go | 2 ++ ssa/interface.go | 2 +- 5 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 cl/_testgo/errors/in.go create mode 100644 cl/_testgo/errors/out.ll diff --git a/cl/_testgo/errors/in.go b/cl/_testgo/errors/in.go new file mode 100644 index 00000000..ada33367 --- /dev/null +++ b/cl/_testgo/errors/in.go @@ -0,0 +1,21 @@ +package main + +// New returns an error that formats as the given text. +// Each call to New returns a distinct error value even if the text is identical. +func New(text string) error { + return &errorString{text} +} + +// errorString is a trivial implementation of error. +type errorString struct { + s string +} + +func (e *errorString) Error() string { + return e.s +} + +func main() { + err := New("an error") + println(err, err.Error()) +} diff --git a/cl/_testgo/errors/out.ll b/cl/_testgo/errors/out.ll new file mode 100644 index 00000000..e69de29b diff --git a/internal/runtime/z_print.go b/internal/runtime/z_print.go index 27a47ac7..8edbbb69 100644 --- a/internal/runtime/z_print.go +++ b/internal/runtime/z_print.go @@ -69,3 +69,7 @@ func PrintSlice(s Slice) { func PrintEface(e Eface) { print("(", e._type, ",", e.data, ")") } + +func PrintIface(i Iface) { + print("(", i.tab, ",", i.data, ")") +} diff --git a/ssa/expr.go b/ssa/expr.go index c013da55..bdaa64df 100644 --- a/ssa/expr.go +++ b/ssa/expr.go @@ -1080,6 +1080,8 @@ func (b Builder) BuiltinCall(fn string, args ...Expr) (ret Expr) { fn = "PrintString" case vkEface: fn = "PrintEface" + case vkIface: + fn = "PrintIface" // case vkComplex: // fn = "PrintComplex" default: diff --git a/ssa/interface.go b/ssa/interface.go index a318a78d..86fa5762 100644 --- a/ssa/interface.go +++ b/ssa/interface.go @@ -127,7 +127,7 @@ func (b Builder) abiNamedOf(t *types.Named) Expr { func (b Builder) abiPointerOf(t *types.Pointer) Expr { elem := b.abiTypeOf(t.Elem()) - return b.Call(b.Pkg.rtFunc("Pointer"), elem) + return b.Call(b.Pkg.rtFunc("PointerTo"), elem) } // func Struct(pkgPath string, size uintptr, fields []abi.StructField)