Merge pull request #1387 from luoliwoshang/runtime/iface/func
fix(runtime): segmentation fault when calling interface private methods cross-package
This commit is contained in:
356
_demo/go/gotoken/main.go
Normal file
356
_demo/go/gotoken/main.go
Normal file
@@ -0,0 +1,356 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"go/token"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
testPos()
|
||||||
|
testToken()
|
||||||
|
testFileSet()
|
||||||
|
testFile()
|
||||||
|
testPosition()
|
||||||
|
testTokenPrecedence()
|
||||||
|
testTokenKeywords()
|
||||||
|
testUtilityFunctions()
|
||||||
|
}
|
||||||
|
|
||||||
|
func testPos() {
|
||||||
|
fmt.Println("=== Test Pos ===")
|
||||||
|
|
||||||
|
pos1 := token.Pos(100)
|
||||||
|
pos2 := token.Pos(200)
|
||||||
|
|
||||||
|
if pos1 != 100 {
|
||||||
|
panic(fmt.Sprintf("Expected pos1 to be 100, got %d", pos1))
|
||||||
|
}
|
||||||
|
if pos2 != 200 {
|
||||||
|
panic(fmt.Sprintf("Expected pos2 to be 200, got %d", pos2))
|
||||||
|
}
|
||||||
|
fmt.Printf("Pos1: %d, Pos2: %d\n", pos1, pos2)
|
||||||
|
|
||||||
|
if !pos1.IsValid() {
|
||||||
|
panic("Expected pos1.IsValid() to be true")
|
||||||
|
}
|
||||||
|
fmt.Printf("Pos1.IsValid(): %v\n", pos1.IsValid())
|
||||||
|
|
||||||
|
noPos := token.NoPos
|
||||||
|
if noPos != 0 {
|
||||||
|
panic(fmt.Sprintf("Expected NoPos to be 0, got %d", noPos))
|
||||||
|
}
|
||||||
|
if noPos.IsValid() {
|
||||||
|
panic("Expected NoPos.IsValid() to be false")
|
||||||
|
}
|
||||||
|
fmt.Printf("NoPos: %d, IsValid: %v\n", noPos, noPos.IsValid())
|
||||||
|
|
||||||
|
fmt.Println("SUCCESS: Pos operations work correctly\n")
|
||||||
|
}
|
||||||
|
|
||||||
|
func testToken() {
|
||||||
|
fmt.Println("\n=== Test Token Types ===")
|
||||||
|
|
||||||
|
expectedStrings := map[token.Token]string{
|
||||||
|
token.ADD: "+",
|
||||||
|
token.SUB: "-",
|
||||||
|
token.MUL: "*",
|
||||||
|
token.QUO: "/",
|
||||||
|
token.LPAREN: "(",
|
||||||
|
token.RPAREN: ")",
|
||||||
|
token.EQL: "==",
|
||||||
|
token.NEQ: "!=",
|
||||||
|
}
|
||||||
|
|
||||||
|
for tok, expected := range expectedStrings {
|
||||||
|
if tok.String() != expected {
|
||||||
|
panic(fmt.Sprintf("Expected %v.String() to be %q, got %q", tok, expected, tok.String()))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
tokens := []token.Token{
|
||||||
|
token.ILLEGAL,
|
||||||
|
token.EOF,
|
||||||
|
token.COMMENT,
|
||||||
|
token.IDENT,
|
||||||
|
token.INT,
|
||||||
|
token.FLOAT,
|
||||||
|
token.IMAG,
|
||||||
|
token.CHAR,
|
||||||
|
token.STRING,
|
||||||
|
token.ADD,
|
||||||
|
token.SUB,
|
||||||
|
token.MUL,
|
||||||
|
token.QUO,
|
||||||
|
token.REM,
|
||||||
|
token.AND,
|
||||||
|
token.OR,
|
||||||
|
token.XOR,
|
||||||
|
token.SHL,
|
||||||
|
token.SHR,
|
||||||
|
token.AND_NOT,
|
||||||
|
token.ADD_ASSIGN,
|
||||||
|
token.SUB_ASSIGN,
|
||||||
|
token.MUL_ASSIGN,
|
||||||
|
token.QUO_ASSIGN,
|
||||||
|
token.REM_ASSIGN,
|
||||||
|
token.AND_ASSIGN,
|
||||||
|
token.OR_ASSIGN,
|
||||||
|
token.XOR_ASSIGN,
|
||||||
|
token.SHL_ASSIGN,
|
||||||
|
token.SHR_ASSIGN,
|
||||||
|
token.AND_NOT_ASSIGN,
|
||||||
|
token.LAND,
|
||||||
|
token.LOR,
|
||||||
|
token.ARROW,
|
||||||
|
token.INC,
|
||||||
|
token.DEC,
|
||||||
|
token.EQL,
|
||||||
|
token.LSS,
|
||||||
|
token.GTR,
|
||||||
|
token.ASSIGN,
|
||||||
|
token.NOT,
|
||||||
|
token.NEQ,
|
||||||
|
token.LEQ,
|
||||||
|
token.GEQ,
|
||||||
|
token.DEFINE,
|
||||||
|
token.ELLIPSIS,
|
||||||
|
token.LPAREN,
|
||||||
|
token.LBRACK,
|
||||||
|
token.LBRACE,
|
||||||
|
token.COMMA,
|
||||||
|
token.PERIOD,
|
||||||
|
token.RPAREN,
|
||||||
|
token.RBRACK,
|
||||||
|
token.RBRACE,
|
||||||
|
token.SEMICOLON,
|
||||||
|
token.COLON,
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, tok := range tokens {
|
||||||
|
fmt.Printf("Token: %s (String: %q)\n", tok, tok.String())
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Println("SUCCESS: Token types work correctly\n")
|
||||||
|
}
|
||||||
|
|
||||||
|
func testTokenKeywords() {
|
||||||
|
fmt.Println("\n=== Test Keywords ===")
|
||||||
|
|
||||||
|
keywords := []token.Token{
|
||||||
|
token.BREAK,
|
||||||
|
token.CASE,
|
||||||
|
token.CHAN,
|
||||||
|
token.CONST,
|
||||||
|
token.CONTINUE,
|
||||||
|
token.DEFAULT,
|
||||||
|
token.DEFER,
|
||||||
|
token.ELSE,
|
||||||
|
token.FALLTHROUGH,
|
||||||
|
token.FOR,
|
||||||
|
token.FUNC,
|
||||||
|
token.GO,
|
||||||
|
token.GOTO,
|
||||||
|
token.IF,
|
||||||
|
token.IMPORT,
|
||||||
|
token.INTERFACE,
|
||||||
|
token.MAP,
|
||||||
|
token.PACKAGE,
|
||||||
|
token.RANGE,
|
||||||
|
token.RETURN,
|
||||||
|
token.SELECT,
|
||||||
|
token.STRUCT,
|
||||||
|
token.SWITCH,
|
||||||
|
token.TYPE,
|
||||||
|
token.VAR,
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, kw := range keywords {
|
||||||
|
if !kw.IsKeyword() {
|
||||||
|
panic(fmt.Sprintf("Expected %s to be a keyword", kw))
|
||||||
|
}
|
||||||
|
fmt.Printf("Keyword: %s, IsKeyword: %v\n", kw, kw.IsKeyword())
|
||||||
|
}
|
||||||
|
|
||||||
|
if token.ADD.IsKeyword() {
|
||||||
|
panic("Expected ADD operator to not be a keyword")
|
||||||
|
}
|
||||||
|
if token.IDENT.IsKeyword() {
|
||||||
|
panic("Expected IDENT token to not be a keyword")
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Println("SUCCESS: Keyword checks work correctly\n")
|
||||||
|
}
|
||||||
|
|
||||||
|
func testTokenPrecedence() {
|
||||||
|
fmt.Println("\n=== Test Token Precedence ===")
|
||||||
|
|
||||||
|
if token.MUL.Precedence() <= token.ADD.Precedence() {
|
||||||
|
panic("Expected MUL to have higher precedence than ADD")
|
||||||
|
}
|
||||||
|
if token.LAND.Precedence() <= token.LOR.Precedence() {
|
||||||
|
panic("Expected LAND to have higher precedence than LOR")
|
||||||
|
}
|
||||||
|
if token.MUL.Precedence() != token.QUO.Precedence() {
|
||||||
|
panic("Expected MUL and QUO to have same precedence")
|
||||||
|
}
|
||||||
|
if token.ADD.Precedence() != token.SUB.Precedence() {
|
||||||
|
panic("Expected ADD and SUB to have same precedence")
|
||||||
|
}
|
||||||
|
|
||||||
|
operators := []token.Token{
|
||||||
|
token.ADD,
|
||||||
|
token.SUB,
|
||||||
|
token.MUL,
|
||||||
|
token.QUO,
|
||||||
|
token.REM,
|
||||||
|
token.LAND,
|
||||||
|
token.LOR,
|
||||||
|
token.EQL,
|
||||||
|
token.LSS,
|
||||||
|
token.GTR,
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, op := range operators {
|
||||||
|
fmt.Printf("Operator: %s, Precedence: %d\n", op, op.Precedence())
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Println("SUCCESS: Precedence operations work correctly\n")
|
||||||
|
}
|
||||||
|
|
||||||
|
func testFileSet() {
|
||||||
|
fmt.Println("\n=== Test FileSet ===")
|
||||||
|
|
||||||
|
fset := token.NewFileSet()
|
||||||
|
|
||||||
|
file1 := fset.AddFile("file1.go", -1, 1000)
|
||||||
|
file2 := fset.AddFile("file2.go", -1, 2000)
|
||||||
|
|
||||||
|
fmt.Printf("Added file1: %s, Base: %d, Size: %d\n", file1.Name(), file1.Base(), file1.Size())
|
||||||
|
fmt.Printf("Added file2: %s, Base: %d, Size: %d\n", file2.Name(), file2.Base(), file2.Size())
|
||||||
|
|
||||||
|
pos := file1.Pos(100)
|
||||||
|
retrievedFile := fset.File(pos)
|
||||||
|
if retrievedFile != file1 {
|
||||||
|
panic("FileSet.File failed to retrieve correct file")
|
||||||
|
}
|
||||||
|
|
||||||
|
position := fset.Position(pos)
|
||||||
|
fmt.Printf("Position at offset 100: %s\n", position)
|
||||||
|
|
||||||
|
fmt.Println("SUCCESS: FileSet operations work correctly\n")
|
||||||
|
}
|
||||||
|
|
||||||
|
func testFile() {
|
||||||
|
fmt.Println("\n=== Test File ===")
|
||||||
|
|
||||||
|
fset := token.NewFileSet()
|
||||||
|
file := fset.AddFile("test.go", -1, 1000)
|
||||||
|
|
||||||
|
if file.Name() != "test.go" {
|
||||||
|
panic(fmt.Sprintf("Expected file name to be 'test.go', got %q", file.Name()))
|
||||||
|
}
|
||||||
|
if file.Size() != 1000 {
|
||||||
|
panic(fmt.Sprintf("Expected file size to be 1000, got %d", file.Size()))
|
||||||
|
}
|
||||||
|
|
||||||
|
file.AddLine(0)
|
||||||
|
file.AddLine(50)
|
||||||
|
file.AddLine(100)
|
||||||
|
|
||||||
|
if file.LineCount() != 3 {
|
||||||
|
panic(fmt.Sprintf("Expected line count to be 3, got %d", file.LineCount()))
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Printf("File name: %s\n", file.Name())
|
||||||
|
fmt.Printf("File base: %d\n", file.Base())
|
||||||
|
fmt.Printf("File size: %d\n", file.Size())
|
||||||
|
fmt.Printf("File line count: %d\n", file.LineCount())
|
||||||
|
|
||||||
|
pos := file.Pos(50)
|
||||||
|
fmt.Printf("Pos at offset 50: %d\n", pos)
|
||||||
|
|
||||||
|
offset := file.Offset(pos)
|
||||||
|
if offset != 50 {
|
||||||
|
panic(fmt.Sprintf("Expected offset to be 50, got %d", offset))
|
||||||
|
}
|
||||||
|
fmt.Printf("Offset of pos: %d\n", offset)
|
||||||
|
|
||||||
|
line := file.Line(pos)
|
||||||
|
if line != 2 {
|
||||||
|
panic(fmt.Sprintf("Expected line to be 2, got %d", line))
|
||||||
|
}
|
||||||
|
fmt.Printf("Line number at pos: %d\n", line)
|
||||||
|
|
||||||
|
lineStart := file.LineStart(2)
|
||||||
|
fmt.Printf("Line 2 starts at pos: %d\n", lineStart)
|
||||||
|
|
||||||
|
position := file.Position(pos)
|
||||||
|
fmt.Printf("Position: %s\n", position)
|
||||||
|
|
||||||
|
fmt.Println("SUCCESS: File operations work correctly\n")
|
||||||
|
}
|
||||||
|
|
||||||
|
func testPosition() {
|
||||||
|
fmt.Println("\n=== Test Position ===" )
|
||||||
|
|
||||||
|
pos := token.Position{
|
||||||
|
Filename: "test.go",
|
||||||
|
Offset: 100,
|
||||||
|
Line: 5,
|
||||||
|
Column: 10,
|
||||||
|
}
|
||||||
|
|
||||||
|
if !pos.IsValid() {
|
||||||
|
panic("Expected valid position to be valid")
|
||||||
|
}
|
||||||
|
if pos.Filename != "test.go" {
|
||||||
|
panic(fmt.Sprintf("Expected filename to be 'test.go', got %q", pos.Filename))
|
||||||
|
}
|
||||||
|
if pos.Line != 5 {
|
||||||
|
panic(fmt.Sprintf("Expected line to be 5, got %d", pos.Line))
|
||||||
|
}
|
||||||
|
if pos.Column != 10 {
|
||||||
|
panic(fmt.Sprintf("Expected column to be 10, got %d", pos.Column))
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Printf("Position: %s\n", pos.String())
|
||||||
|
fmt.Printf("Filename: %s, Line: %d, Column: %d, Offset: %d\n",
|
||||||
|
pos.Filename, pos.Line, pos.Column, pos.Offset)
|
||||||
|
fmt.Printf("IsValid: %v\n", pos.IsValid())
|
||||||
|
|
||||||
|
invalidPos := token.Position{}
|
||||||
|
if invalidPos.IsValid() {
|
||||||
|
panic("Expected empty position to be invalid")
|
||||||
|
}
|
||||||
|
fmt.Printf("Invalid position IsValid: %v\n", invalidPos.IsValid())
|
||||||
|
|
||||||
|
fmt.Println("SUCCESS: Position operations work correctly\n")
|
||||||
|
}
|
||||||
|
|
||||||
|
func testUtilityFunctions() {
|
||||||
|
fmt.Println("\n=== Test Utility Functions ===")
|
||||||
|
|
||||||
|
fmt.Printf("IsExported(\"Foo\"): %v\n", token.IsExported("Foo"))
|
||||||
|
fmt.Printf("IsExported(\"foo\"): %v\n", token.IsExported("foo"))
|
||||||
|
fmt.Printf("IsExported(\"_foo\"): %v\n", token.IsExported("_foo"))
|
||||||
|
|
||||||
|
fmt.Printf("IsIdentifier(\"foo\"): %v\n", token.IsIdentifier("foo"))
|
||||||
|
fmt.Printf("IsIdentifier(\"foo123\"): %v\n", token.IsIdentifier("foo123"))
|
||||||
|
fmt.Printf("IsIdentifier(\"123foo\"): %v\n", token.IsIdentifier("123foo"))
|
||||||
|
fmt.Printf("IsIdentifier(\"foo-bar\"): %v\n", token.IsIdentifier("foo-bar"))
|
||||||
|
|
||||||
|
fmt.Printf("IsKeyword(\"func\"): %v\n", token.IsKeyword("func"))
|
||||||
|
fmt.Printf("IsKeyword(\"if\"): %v\n", token.IsKeyword("if"))
|
||||||
|
fmt.Printf("IsKeyword(\"foo\"): %v\n", token.IsKeyword("foo"))
|
||||||
|
|
||||||
|
lookupFunc := token.Lookup("func")
|
||||||
|
fmt.Printf("Lookup(\"func\"): %s\n", lookupFunc)
|
||||||
|
|
||||||
|
lookupIdent := token.Lookup("myVar")
|
||||||
|
fmt.Printf("Lookup(\"myVar\"): %s\n", lookupIdent)
|
||||||
|
|
||||||
|
lookupFor := token.Lookup("for")
|
||||||
|
fmt.Printf("Lookup(\"for\"): %s\n", lookupFor)
|
||||||
|
|
||||||
|
fmt.Println("SUCCESS: Utility functions work correctly\n")
|
||||||
|
}
|
||||||
488
_demo/go/gotypes/main.go
Normal file
488
_demo/go/gotypes/main.go
Normal file
@@ -0,0 +1,488 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"go/token"
|
||||||
|
"go/types"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
testBasicTypes()
|
||||||
|
testObjects()
|
||||||
|
testScope()
|
||||||
|
testPackage()
|
||||||
|
testNamed()
|
||||||
|
testInterface()
|
||||||
|
testStruct()
|
||||||
|
testSignature()
|
||||||
|
testTuple()
|
||||||
|
testArray()
|
||||||
|
testSlice()
|
||||||
|
testPointer()
|
||||||
|
testMap()
|
||||||
|
testChan()
|
||||||
|
testTypeComparison()
|
||||||
|
testTypeChecking()
|
||||||
|
testStringFunctions()
|
||||||
|
testLookupFunctions()
|
||||||
|
testUtilityFunctions()
|
||||||
|
}
|
||||||
|
|
||||||
|
func testBasicTypes() {
|
||||||
|
fmt.Println("=== Test Basic Types ===")
|
||||||
|
|
||||||
|
intType := types.Typ[types.Int]
|
||||||
|
fmt.Printf("Int type: %v, Kind: %v\n", intType, intType.Kind())
|
||||||
|
if intType.Kind() != types.Int {
|
||||||
|
panic(fmt.Sprintf("Int type kind mismatch: expected %v, got %v", types.Int, intType.Kind()))
|
||||||
|
}
|
||||||
|
|
||||||
|
stringType := types.Typ[types.String]
|
||||||
|
fmt.Printf("String type: %v, Kind: %v\n", stringType, stringType.Kind())
|
||||||
|
if stringType.Kind() != types.String {
|
||||||
|
panic(fmt.Sprintf("String type kind mismatch: expected %v, got %v", types.String, stringType.Kind()))
|
||||||
|
}
|
||||||
|
|
||||||
|
boolType := types.Typ[types.Bool]
|
||||||
|
fmt.Printf("Bool type: %v, Kind: %v\n", boolType, boolType.Kind())
|
||||||
|
if boolType.Kind() != types.Bool {
|
||||||
|
panic(fmt.Sprintf("Bool type kind mismatch: expected %v, got %v", types.Bool, boolType.Kind()))
|
||||||
|
}
|
||||||
|
|
||||||
|
float64Type := types.Typ[types.Float64]
|
||||||
|
fmt.Printf("Float64 type: %v, Kind: %v\n", float64Type, float64Type.Kind())
|
||||||
|
if float64Type.Kind() != types.Float64 {
|
||||||
|
panic(fmt.Sprintf("Float64 type kind mismatch: expected %v, got %v", types.Float64, float64Type.Kind()))
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Println("SUCCESS: Basic types work correctly\n")
|
||||||
|
}
|
||||||
|
|
||||||
|
func testObjects() {
|
||||||
|
fmt.Println("\n=== Test Objects (Var, Const, Func, TypeName) ===")
|
||||||
|
|
||||||
|
varObj := types.NewVar(token.NoPos, nil, "x", types.Typ[types.Int])
|
||||||
|
fmt.Printf("Var: Name=%s, Type=%v\n", varObj.Name(), varObj.Type())
|
||||||
|
if varObj.Name() != "x" {
|
||||||
|
panic(fmt.Sprintf("Var name mismatch: expected x, got %s", varObj.Name()))
|
||||||
|
}
|
||||||
|
if varObj.Type() != types.Typ[types.Int] {
|
||||||
|
panic(fmt.Sprintf("Var type mismatch: expected int, got %v", varObj.Type()))
|
||||||
|
}
|
||||||
|
|
||||||
|
constObj := types.NewConst(token.NoPos, nil, "pi", types.Typ[types.Float64], nil)
|
||||||
|
fmt.Printf("Const: Name=%s, Type=%v\n", constObj.Name(), constObj.Type())
|
||||||
|
if constObj.Name() != "pi" {
|
||||||
|
panic(fmt.Sprintf("Const name mismatch: expected pi, got %s", constObj.Name()))
|
||||||
|
}
|
||||||
|
if constObj.Type() != types.Typ[types.Float64] {
|
||||||
|
panic(fmt.Sprintf("Const type mismatch: expected float64, got %v", constObj.Type()))
|
||||||
|
}
|
||||||
|
|
||||||
|
sig := types.NewSignatureType(nil, nil, nil, nil, nil, false)
|
||||||
|
funcObj := types.NewFunc(token.NoPos, nil, "foo", sig)
|
||||||
|
fmt.Printf("Func: Name=%s, Type=%v\n", funcObj.Name(), funcObj.Type())
|
||||||
|
if funcObj.Name() != "foo" {
|
||||||
|
panic(fmt.Sprintf("Func name mismatch: expected foo, got %s", funcObj.Name()))
|
||||||
|
}
|
||||||
|
|
||||||
|
typeObj := types.NewTypeName(token.NoPos, nil, "MyInt", types.Typ[types.Int])
|
||||||
|
fmt.Printf("TypeName: Name=%s, Type=%v\n", typeObj.Name(), typeObj.Type())
|
||||||
|
if typeObj.Name() != "MyInt" {
|
||||||
|
panic(fmt.Sprintf("TypeName name mismatch: expected MyInt, got %s", typeObj.Name()))
|
||||||
|
}
|
||||||
|
|
||||||
|
var obj types.Object = varObj
|
||||||
|
if obj.Name() != "x" {
|
||||||
|
panic("Object interface conversion failed")
|
||||||
|
}
|
||||||
|
fmt.Println("SUCCESS: Object interface works correctly\n")
|
||||||
|
}
|
||||||
|
|
||||||
|
func testScope() {
|
||||||
|
fmt.Println("\n=== Test Scope ===")
|
||||||
|
|
||||||
|
scope := types.NewScope(nil, 0, 0, "test")
|
||||||
|
obj := types.NewVar(0, nil, "x", types.Typ[types.Int])
|
||||||
|
|
||||||
|
scope.Insert(obj)
|
||||||
|
result := scope.Lookup("x")
|
||||||
|
if result != obj {
|
||||||
|
panic("Scope.Lookup failed")
|
||||||
|
}
|
||||||
|
|
||||||
|
names := scope.Names()
|
||||||
|
if len(names) != 1 || names[0] != "x" {
|
||||||
|
panic("Scope.Names failed")
|
||||||
|
}
|
||||||
|
|
||||||
|
num := scope.Len()
|
||||||
|
if num != 1 {
|
||||||
|
panic("Scope.Len failed")
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Printf("Scope contains %d object(s): %v\n", num, names)
|
||||||
|
fmt.Println("SUCCESS: Scope operations work correctly\n")
|
||||||
|
}
|
||||||
|
|
||||||
|
func testPackage() {
|
||||||
|
fmt.Println("\n=== Test Package ===")
|
||||||
|
|
||||||
|
pkg := types.NewPackage("example.com/test", "test")
|
||||||
|
fmt.Printf("Package: Path=%s, Name=%s\n", pkg.Path(), pkg.Name())
|
||||||
|
if pkg.Path() != "example.com/test" {
|
||||||
|
panic(fmt.Sprintf("Package path mismatch: expected example.com/test, got %s", pkg.Path()))
|
||||||
|
}
|
||||||
|
if pkg.Name() != "test" {
|
||||||
|
panic(fmt.Sprintf("Package name mismatch: expected test, got %s", pkg.Name()))
|
||||||
|
}
|
||||||
|
|
||||||
|
scope := pkg.Scope()
|
||||||
|
if scope == nil {
|
||||||
|
panic("Package.Scope returned nil")
|
||||||
|
}
|
||||||
|
|
||||||
|
varObj := types.NewVar(token.NoPos, pkg, "x", types.Typ[types.Int])
|
||||||
|
scope.Insert(varObj)
|
||||||
|
|
||||||
|
result := pkg.Scope().Lookup("x")
|
||||||
|
if result != varObj {
|
||||||
|
panic("Package scope lookup failed")
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Println("SUCCESS: Package operations work correctly\n")
|
||||||
|
}
|
||||||
|
|
||||||
|
func testNamed() {
|
||||||
|
fmt.Println("\n=== Test Named Types ===")
|
||||||
|
|
||||||
|
pkg := types.NewPackage("example.com/test", "test")
|
||||||
|
typeName := types.NewTypeName(token.NoPos, pkg, "MyInt", nil)
|
||||||
|
named := types.NewNamed(typeName, types.Typ[types.Int], nil)
|
||||||
|
|
||||||
|
fmt.Printf("Named type: %v, Underlying: %v\n", named, named.Underlying())
|
||||||
|
|
||||||
|
if named.Obj() != typeName {
|
||||||
|
panic("Named.Obj failed")
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Println("SUCCESS: Named type operations work correctly\n")
|
||||||
|
}
|
||||||
|
|
||||||
|
func testInterface() {
|
||||||
|
fmt.Println("\n=== Test Interface ===")
|
||||||
|
|
||||||
|
pkg := types.NewPackage("example.com/test", "test")
|
||||||
|
|
||||||
|
posMethod := types.NewFunc(token.NoPos, pkg, "Pos", types.NewSignatureType(nil, nil, nil, nil, types.NewTuple(types.NewVar(0, pkg, "", types.Typ[types.Int])), false))
|
||||||
|
endMethod := types.NewFunc(token.NoPos, pkg, "End", types.NewSignatureType(nil, nil, nil, nil, types.NewTuple(types.NewVar(0, pkg, "", types.Typ[types.Int])), false))
|
||||||
|
|
||||||
|
methods := []*types.Func{posMethod, endMethod}
|
||||||
|
iface := types.NewInterfaceType(methods, nil)
|
||||||
|
iface.Complete()
|
||||||
|
|
||||||
|
fmt.Printf("Interface with %d methods\n", iface.NumMethods())
|
||||||
|
if iface.NumMethods() != 2 {
|
||||||
|
panic(fmt.Sprintf("Interface method count mismatch: expected 2, got %d", iface.NumMethods()))
|
||||||
|
}
|
||||||
|
|
||||||
|
method := iface.Method(0)
|
||||||
|
fmt.Printf("Method 0: %s\n", method.Name())
|
||||||
|
if method.Name() != "End" && method.Name() != "Pos" {
|
||||||
|
panic(fmt.Sprintf("Unexpected method name: %s", method.Name()))
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Println("SUCCESS: Interface operations work correctly\n")
|
||||||
|
}
|
||||||
|
|
||||||
|
func testStruct() {
|
||||||
|
fmt.Println("\n=== Test Struct ===")
|
||||||
|
|
||||||
|
fields := []*types.Var{
|
||||||
|
types.NewField(token.NoPos, nil, "X", types.Typ[types.Int], false),
|
||||||
|
types.NewField(token.NoPos, nil, "Y", types.Typ[types.String], false),
|
||||||
|
}
|
||||||
|
|
||||||
|
structType := types.NewStruct(fields, nil)
|
||||||
|
fmt.Printf("Struct with %d fields\n", structType.NumFields())
|
||||||
|
if structType.NumFields() != 2 {
|
||||||
|
panic(fmt.Sprintf("Struct field count mismatch: expected 2, got %d", structType.NumFields()))
|
||||||
|
}
|
||||||
|
|
||||||
|
field0 := structType.Field(0)
|
||||||
|
fmt.Printf("Field 0: Name=%s, Type=%v\n", field0.Name(), field0.Type())
|
||||||
|
if field0.Name() != "X" {
|
||||||
|
panic(fmt.Sprintf("Field 0 name mismatch: expected X, got %s", field0.Name()))
|
||||||
|
}
|
||||||
|
if field0.Type() != types.Typ[types.Int] {
|
||||||
|
panic(fmt.Sprintf("Field 0 type mismatch: expected int, got %v", field0.Type()))
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Println("SUCCESS: Struct operations work correctly\n")
|
||||||
|
}
|
||||||
|
|
||||||
|
func testSignature() {
|
||||||
|
fmt.Println("\n=== Test Signature ===")
|
||||||
|
|
||||||
|
params := types.NewTuple(
|
||||||
|
types.NewVar(token.NoPos, nil, "x", types.Typ[types.Int]),
|
||||||
|
types.NewVar(token.NoPos, nil, "y", types.Typ[types.String]),
|
||||||
|
)
|
||||||
|
|
||||||
|
results := types.NewTuple(
|
||||||
|
types.NewVar(token.NoPos, nil, "", types.Typ[types.Bool]),
|
||||||
|
)
|
||||||
|
|
||||||
|
sig := types.NewSignatureType(nil, nil, nil, params, results, false)
|
||||||
|
|
||||||
|
fmt.Printf("Signature: %d params, %d results\n", sig.Params().Len(), sig.Results().Len())
|
||||||
|
if sig.Params().Len() != 2 {
|
||||||
|
panic(fmt.Sprintf("Signature param count mismatch: expected 2, got %d", sig.Params().Len()))
|
||||||
|
}
|
||||||
|
if sig.Results().Len() != 1 {
|
||||||
|
panic(fmt.Sprintf("Signature result count mismatch: expected 1, got %d", sig.Results().Len()))
|
||||||
|
}
|
||||||
|
|
||||||
|
param0 := sig.Params().At(0)
|
||||||
|
fmt.Printf("Param 0: Name=%s, Type=%v\n", param0.Name(), param0.Type())
|
||||||
|
if param0.Name() != "x" {
|
||||||
|
panic(fmt.Sprintf("Param 0 name mismatch: expected x, got %s", param0.Name()))
|
||||||
|
}
|
||||||
|
if param0.Type() != types.Typ[types.Int] {
|
||||||
|
panic(fmt.Sprintf("Param 0 type mismatch: expected int, got %v", param0.Type()))
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Println("SUCCESS: Signature operations work correctly\n")
|
||||||
|
}
|
||||||
|
|
||||||
|
func testTuple() {
|
||||||
|
fmt.Println("\n=== Test Tuple ===")
|
||||||
|
|
||||||
|
tuple := types.NewTuple(
|
||||||
|
types.NewVar(token.NoPos, nil, "a", types.Typ[types.Int]),
|
||||||
|
types.NewVar(token.NoPos, nil, "b", types.Typ[types.String]),
|
||||||
|
)
|
||||||
|
|
||||||
|
fmt.Printf("Tuple length: %d\n", tuple.Len())
|
||||||
|
if tuple.Len() != 2 {
|
||||||
|
panic(fmt.Sprintf("Tuple length mismatch: expected 2, got %d", tuple.Len()))
|
||||||
|
}
|
||||||
|
|
||||||
|
var0 := tuple.At(0)
|
||||||
|
fmt.Printf("Element 0: Name=%s, Type=%v\n", var0.Name(), var0.Type())
|
||||||
|
if var0.Name() != "a" {
|
||||||
|
panic(fmt.Sprintf("Tuple element 0 name mismatch: expected a, got %s", var0.Name()))
|
||||||
|
}
|
||||||
|
if var0.Type() != types.Typ[types.Int] {
|
||||||
|
panic(fmt.Sprintf("Tuple element 0 type mismatch: expected int, got %v", var0.Type()))
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Println("SUCCESS: Tuple operations work correctly\n")
|
||||||
|
}
|
||||||
|
|
||||||
|
func testArray() {
|
||||||
|
fmt.Println("\n=== Test Array ===")
|
||||||
|
|
||||||
|
arrayType := types.NewArray(types.Typ[types.Int], 10)
|
||||||
|
fmt.Printf("Array type: %v, Elem: %v, Len: %d\n", arrayType, arrayType.Elem(), arrayType.Len())
|
||||||
|
if arrayType.Len() != 10 {
|
||||||
|
panic(fmt.Sprintf("Array length mismatch: expected 10, got %d", arrayType.Len()))
|
||||||
|
}
|
||||||
|
if arrayType.Elem() != types.Typ[types.Int] {
|
||||||
|
panic(fmt.Sprintf("Array element type mismatch: expected int, got %v", arrayType.Elem()))
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Println("SUCCESS: Array operations work correctly\n")
|
||||||
|
}
|
||||||
|
|
||||||
|
func testSlice() {
|
||||||
|
fmt.Println("\n=== Test Slice ===")
|
||||||
|
|
||||||
|
sliceType := types.NewSlice(types.Typ[types.String])
|
||||||
|
fmt.Printf("Slice type: %v, Elem: %v\n", sliceType, sliceType.Elem())
|
||||||
|
if sliceType.Elem() != types.Typ[types.String] {
|
||||||
|
panic(fmt.Sprintf("Slice element type mismatch: expected string, got %v", sliceType.Elem()))
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Println("SUCCESS: Slice operations work correctly\n")
|
||||||
|
}
|
||||||
|
|
||||||
|
func testPointer() {
|
||||||
|
fmt.Println("\n=== Test Pointer ===")
|
||||||
|
|
||||||
|
ptrType := types.NewPointer(types.Typ[types.Int])
|
||||||
|
fmt.Printf("Pointer type: %v, Elem: %v\n", ptrType, ptrType.Elem())
|
||||||
|
if ptrType.Elem() != types.Typ[types.Int] {
|
||||||
|
panic(fmt.Sprintf("Pointer element type mismatch: expected int, got %v", ptrType.Elem()))
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Println("SUCCESS: Pointer operations work correctly\n")
|
||||||
|
}
|
||||||
|
|
||||||
|
func testMap() {
|
||||||
|
fmt.Println("\n=== Test Map ===")
|
||||||
|
|
||||||
|
mapType := types.NewMap(types.Typ[types.String], types.Typ[types.Int])
|
||||||
|
fmt.Printf("Map type: %v, Key: %v, Elem: %v\n", mapType, mapType.Key(), mapType.Elem())
|
||||||
|
if mapType.Key() != types.Typ[types.String] {
|
||||||
|
panic(fmt.Sprintf("Map key type mismatch: expected string, got %v", mapType.Key()))
|
||||||
|
}
|
||||||
|
if mapType.Elem() != types.Typ[types.Int] {
|
||||||
|
panic(fmt.Sprintf("Map element type mismatch: expected int, got %v", mapType.Elem()))
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Println("SUCCESS: Map operations work correctly\n")
|
||||||
|
}
|
||||||
|
|
||||||
|
func testChan() {
|
||||||
|
fmt.Println("\n=== Test Chan ===" )
|
||||||
|
|
||||||
|
chanType := types.NewChan(types.SendRecv, types.Typ[types.Int])
|
||||||
|
fmt.Printf("Chan type: %v, Dir: %v, Elem: %v\n", chanType, chanType.Dir(), chanType.Elem())
|
||||||
|
if chanType.Dir() != types.SendRecv {
|
||||||
|
panic(fmt.Sprintf("Chan direction mismatch: expected SendRecv, got %v", chanType.Dir()))
|
||||||
|
}
|
||||||
|
if chanType.Elem() != types.Typ[types.Int] {
|
||||||
|
panic(fmt.Sprintf("Chan element type mismatch: expected int, got %v", chanType.Elem()))
|
||||||
|
}
|
||||||
|
|
||||||
|
sendChan := types.NewChan(types.SendOnly, types.Typ[types.String])
|
||||||
|
fmt.Printf("SendOnly chan: %v, Dir: %v\n", sendChan, sendChan.Dir())
|
||||||
|
if sendChan.Dir() != types.SendOnly {
|
||||||
|
panic(fmt.Sprintf("SendOnly chan direction mismatch: expected SendOnly, got %v", sendChan.Dir()))
|
||||||
|
}
|
||||||
|
|
||||||
|
recvChan := types.NewChan(types.RecvOnly, types.Typ[types.Bool])
|
||||||
|
fmt.Printf("RecvOnly chan: %v, Dir: %v\n", recvChan, recvChan.Dir())
|
||||||
|
if recvChan.Dir() != types.RecvOnly {
|
||||||
|
panic(fmt.Sprintf("RecvOnly chan direction mismatch: expected RecvOnly, got %v", recvChan.Dir()))
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Println("SUCCESS: Chan operations work correctly\n")
|
||||||
|
}
|
||||||
|
|
||||||
|
func testTypeComparison() {
|
||||||
|
fmt.Println("\n=== Test Type Comparison Functions ===")
|
||||||
|
|
||||||
|
t1 := types.Typ[types.Int]
|
||||||
|
t2 := types.Typ[types.Int]
|
||||||
|
t3 := types.Typ[types.String]
|
||||||
|
|
||||||
|
if !types.Identical(t1, t2) {
|
||||||
|
panic("Identical failed: int should be identical to int")
|
||||||
|
}
|
||||||
|
fmt.Printf("Identical(int, int): %v\n", types.Identical(t1, t2))
|
||||||
|
fmt.Printf("Identical(int, string): %v\n", types.Identical(t1, t3))
|
||||||
|
|
||||||
|
if !types.AssignableTo(t1, t2) {
|
||||||
|
panic("AssignableTo failed")
|
||||||
|
}
|
||||||
|
fmt.Printf("AssignableTo(int, int): %v\n", types.AssignableTo(t1, t2))
|
||||||
|
fmt.Printf("AssignableTo(int, string): %v\n", types.AssignableTo(t1, t3))
|
||||||
|
|
||||||
|
fmt.Printf("Comparable(int): %v\n", types.Comparable(t1))
|
||||||
|
fmt.Printf("Comparable(string): %v\n", types.Comparable(t3))
|
||||||
|
|
||||||
|
fmt.Printf("ConvertibleTo(int, int): %v\n", types.ConvertibleTo(t1, t2))
|
||||||
|
|
||||||
|
fmt.Println("SUCCESS: Type comparison functions work correctly\n")
|
||||||
|
}
|
||||||
|
|
||||||
|
func testTypeChecking() {
|
||||||
|
fmt.Println("\n=== Test Type Checking Functions ===")
|
||||||
|
|
||||||
|
pkg := types.NewPackage("example.com/test", "test")
|
||||||
|
|
||||||
|
m1 := types.NewFunc(token.NoPos, pkg, "Method1", types.NewSignatureType(nil, nil, nil, nil, nil, false))
|
||||||
|
m2 := types.NewFunc(token.NoPos, pkg, "Method2", types.NewSignatureType(nil, nil, nil, nil, nil, false))
|
||||||
|
iface := types.NewInterfaceType([]*types.Func{m1, m2}, nil)
|
||||||
|
iface.Complete()
|
||||||
|
|
||||||
|
fields := []*types.Var{
|
||||||
|
types.NewField(token.NoPos, nil, "x", types.Typ[types.Int], false),
|
||||||
|
}
|
||||||
|
structType := types.NewStruct(fields, nil)
|
||||||
|
|
||||||
|
fmt.Printf("Implements(struct, interface): %v\n", types.Implements(structType, iface))
|
||||||
|
fmt.Printf("Implements(int, interface): %v\n", types.Implements(types.Typ[types.Int], iface))
|
||||||
|
|
||||||
|
emptyIface := types.NewInterfaceType(nil, nil)
|
||||||
|
emptyIface.Complete()
|
||||||
|
fmt.Printf("Implements(int, empty interface): %v\n", types.Implements(types.Typ[types.Int], emptyIface))
|
||||||
|
|
||||||
|
fmt.Printf("AssertableTo(interface, int): %v\n", types.AssertableTo(iface, types.Typ[types.Int]))
|
||||||
|
|
||||||
|
fmt.Println("SUCCESS: Type checking functions work correctly\n")
|
||||||
|
}
|
||||||
|
|
||||||
|
func testStringFunctions() {
|
||||||
|
fmt.Println("\n=== Test String Functions ===")
|
||||||
|
|
||||||
|
pkg := types.NewPackage("example.com/test", "test")
|
||||||
|
varObj := types.NewVar(token.NoPos, pkg, "myVar", types.Typ[types.Int])
|
||||||
|
|
||||||
|
objStr := types.ObjectString(varObj, nil)
|
||||||
|
fmt.Printf("ObjectString: %s\n", objStr)
|
||||||
|
|
||||||
|
objStrQual := types.ObjectString(varObj, types.RelativeTo(pkg))
|
||||||
|
fmt.Printf("ObjectString (qualified): %s\n", objStrQual)
|
||||||
|
|
||||||
|
typeStr := types.TypeString(types.Typ[types.Int], nil)
|
||||||
|
fmt.Printf("TypeString(int): %s\n", typeStr)
|
||||||
|
|
||||||
|
sliceType := types.NewSlice(types.Typ[types.String])
|
||||||
|
sliceStr := types.TypeString(sliceType, nil)
|
||||||
|
fmt.Printf("TypeString([]string): %s\n", sliceStr)
|
||||||
|
|
||||||
|
fmt.Println("SUCCESS: String functions work correctly\n")
|
||||||
|
}
|
||||||
|
|
||||||
|
func testLookupFunctions() {
|
||||||
|
fmt.Println("\n=== Test Lookup Functions ===")
|
||||||
|
|
||||||
|
pkg := types.NewPackage("example.com/test", "test")
|
||||||
|
|
||||||
|
fields := []*types.Var{
|
||||||
|
types.NewField(token.NoPos, pkg, "X", types.Typ[types.Int], false),
|
||||||
|
types.NewField(token.NoPos, pkg, "Y", types.Typ[types.String], false),
|
||||||
|
}
|
||||||
|
structType := types.NewStruct(fields, nil)
|
||||||
|
|
||||||
|
obj, index, indirect := types.LookupFieldOrMethod(structType, false, pkg, "X")
|
||||||
|
if obj == nil {
|
||||||
|
panic("LookupFieldOrMethod failed to find X")
|
||||||
|
}
|
||||||
|
fmt.Printf("LookupFieldOrMethod found: %s, index: %v, indirect: %v\n", obj.Name(), index, indirect)
|
||||||
|
|
||||||
|
obj2, index2, indirect2 := types.LookupFieldOrMethod(structType, false, pkg, "NonExistent")
|
||||||
|
fmt.Printf("LookupFieldOrMethod (non-existent): found=%v, index=%v, indirect=%v\n", obj2 != nil, index2, indirect2)
|
||||||
|
|
||||||
|
mset := types.NewMethodSet(structType)
|
||||||
|
fmt.Printf("NewMethodSet: %d methods\n", mset.Len())
|
||||||
|
|
||||||
|
fmt.Println("SUCCESS: Lookup functions work correctly\n")
|
||||||
|
}
|
||||||
|
|
||||||
|
func testUtilityFunctions() {
|
||||||
|
fmt.Println("\n=== Test Utility Functions ===")
|
||||||
|
|
||||||
|
pkg := types.NewPackage("example.com/test", "test")
|
||||||
|
|
||||||
|
iface := types.NewInterfaceType(nil, nil)
|
||||||
|
iface.Complete()
|
||||||
|
|
||||||
|
fmt.Printf("IsInterface(interface): %v\n", types.IsInterface(iface))
|
||||||
|
fmt.Printf("IsInterface(int): %v\n", types.IsInterface(types.Typ[types.Int]))
|
||||||
|
|
||||||
|
typedNil := types.Typ[types.UntypedNil]
|
||||||
|
defaultType := types.Default(typedNil)
|
||||||
|
fmt.Printf("Default(UntypedNil): %v\n", defaultType)
|
||||||
|
|
||||||
|
intDefault := types.Default(types.Typ[types.Int])
|
||||||
|
fmt.Printf("Default(int): %v\n", intDefault)
|
||||||
|
|
||||||
|
idStr := types.Id(pkg, "MyType")
|
||||||
|
fmt.Printf("Id(pkg, \"MyType\"): %s\n", idStr)
|
||||||
|
|
||||||
|
fmt.Println("SUCCESS: Utility functions work correctly\n")
|
||||||
|
}
|
||||||
25
cl/_testdata/geometry1370/geometry.go
Normal file
25
cl/_testdata/geometry1370/geometry.go
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
package geometry1370
|
||||||
|
|
||||||
|
type Shape interface {
|
||||||
|
Area() float64
|
||||||
|
validate() bool
|
||||||
|
setID(int)
|
||||||
|
}
|
||||||
|
|
||||||
|
type Rectangle struct {
|
||||||
|
Width, Height float64
|
||||||
|
id int
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *Rectangle) Area() float64 { return r.Width * r.Height }
|
||||||
|
func (r *Rectangle) validate() bool { return r.Width > 0 && r.Height > 0 }
|
||||||
|
func (r *Rectangle) setID(id int) { r.id = id }
|
||||||
|
func (r *Rectangle) GetID() int { return r.id }
|
||||||
|
|
||||||
|
func NewRectangle(width, height float64) *Rectangle {
|
||||||
|
return &Rectangle{Width: width, Height: height}
|
||||||
|
}
|
||||||
|
|
||||||
|
func RegisterShape(s Shape, id int) {
|
||||||
|
s.setID(id)
|
||||||
|
}
|
||||||
90
cl/_testdata/geometry1370/out.ll
Normal file
90
cl/_testdata/geometry1370/out.ll
Normal file
@@ -0,0 +1,90 @@
|
|||||||
|
; ModuleID = 'github.com/goplus/llgo/cl/_testdata/geometry1370'
|
||||||
|
source_filename = "github.com/goplus/llgo/cl/_testdata/geometry1370"
|
||||||
|
|
||||||
|
%"github.com/goplus/llgo/cl/_testdata/geometry1370.Rectangle" = type { double, double, i64 }
|
||||||
|
%"github.com/goplus/llgo/runtime/internal/runtime.iface" = type { ptr, ptr }
|
||||||
|
|
||||||
|
@"github.com/goplus/llgo/cl/_testdata/geometry1370.init$guard" = global i1 false, align 1
|
||||||
|
|
||||||
|
define ptr @"github.com/goplus/llgo/cl/_testdata/geometry1370.NewRectangle"(double %0, double %1) {
|
||||||
|
_llgo_0:
|
||||||
|
%2 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.AllocZ"(i64 24)
|
||||||
|
%3 = getelementptr inbounds %"github.com/goplus/llgo/cl/_testdata/geometry1370.Rectangle", ptr %2, i32 0, i32 0
|
||||||
|
%4 = getelementptr inbounds %"github.com/goplus/llgo/cl/_testdata/geometry1370.Rectangle", ptr %2, i32 0, i32 1
|
||||||
|
store double %0, ptr %3, align 8
|
||||||
|
store double %1, ptr %4, align 8
|
||||||
|
ret ptr %2
|
||||||
|
}
|
||||||
|
|
||||||
|
define double @"github.com/goplus/llgo/cl/_testdata/geometry1370.(*Rectangle).Area"(ptr %0) {
|
||||||
|
_llgo_0:
|
||||||
|
%1 = getelementptr inbounds %"github.com/goplus/llgo/cl/_testdata/geometry1370.Rectangle", ptr %0, i32 0, i32 0
|
||||||
|
%2 = load double, ptr %1, align 8
|
||||||
|
%3 = getelementptr inbounds %"github.com/goplus/llgo/cl/_testdata/geometry1370.Rectangle", ptr %0, i32 0, i32 1
|
||||||
|
%4 = load double, ptr %3, align 8
|
||||||
|
%5 = fmul double %2, %4
|
||||||
|
ret double %5
|
||||||
|
}
|
||||||
|
|
||||||
|
define i64 @"github.com/goplus/llgo/cl/_testdata/geometry1370.(*Rectangle).GetID"(ptr %0) {
|
||||||
|
_llgo_0:
|
||||||
|
%1 = getelementptr inbounds %"github.com/goplus/llgo/cl/_testdata/geometry1370.Rectangle", ptr %0, i32 0, i32 2
|
||||||
|
%2 = load i64, ptr %1, align 4
|
||||||
|
ret i64 %2
|
||||||
|
}
|
||||||
|
|
||||||
|
define void @"github.com/goplus/llgo/cl/_testdata/geometry1370.(*Rectangle).setID"(ptr %0, i64 %1) {
|
||||||
|
_llgo_0:
|
||||||
|
%2 = getelementptr inbounds %"github.com/goplus/llgo/cl/_testdata/geometry1370.Rectangle", ptr %0, i32 0, i32 2
|
||||||
|
store i64 %1, ptr %2, align 4
|
||||||
|
ret void
|
||||||
|
}
|
||||||
|
|
||||||
|
define i1 @"github.com/goplus/llgo/cl/_testdata/geometry1370.(*Rectangle).validate"(ptr %0) {
|
||||||
|
_llgo_0:
|
||||||
|
%1 = getelementptr inbounds %"github.com/goplus/llgo/cl/_testdata/geometry1370.Rectangle", ptr %0, i32 0, i32 0
|
||||||
|
%2 = load double, ptr %1, align 8
|
||||||
|
%3 = fcmp ogt double %2, 0.000000e+00
|
||||||
|
br i1 %3, label %_llgo_1, label %_llgo_2
|
||||||
|
|
||||||
|
_llgo_1: ; preds = %_llgo_0
|
||||||
|
%4 = getelementptr inbounds %"github.com/goplus/llgo/cl/_testdata/geometry1370.Rectangle", ptr %0, i32 0, i32 1
|
||||||
|
%5 = load double, ptr %4, align 8
|
||||||
|
%6 = fcmp ogt double %5, 0.000000e+00
|
||||||
|
br label %_llgo_2
|
||||||
|
|
||||||
|
_llgo_2: ; preds = %_llgo_1, %_llgo_0
|
||||||
|
%7 = phi i1 [ false, %_llgo_0 ], [ %6, %_llgo_1 ]
|
||||||
|
ret i1 %7
|
||||||
|
}
|
||||||
|
|
||||||
|
define void @"github.com/goplus/llgo/cl/_testdata/geometry1370.RegisterShape"(%"github.com/goplus/llgo/runtime/internal/runtime.iface" %0, i64 %1) {
|
||||||
|
_llgo_0:
|
||||||
|
%2 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.IfacePtrData"(%"github.com/goplus/llgo/runtime/internal/runtime.iface" %0)
|
||||||
|
%3 = extractvalue %"github.com/goplus/llgo/runtime/internal/runtime.iface" %0, 0
|
||||||
|
%4 = getelementptr ptr, ptr %3, i64 4
|
||||||
|
%5 = load ptr, ptr %4, align 8
|
||||||
|
%6 = insertvalue { ptr, ptr } undef, ptr %5, 0
|
||||||
|
%7 = insertvalue { ptr, ptr } %6, ptr %2, 1
|
||||||
|
%8 = extractvalue { ptr, ptr } %7, 1
|
||||||
|
%9 = extractvalue { ptr, ptr } %7, 0
|
||||||
|
call void %9(ptr %8, i64 %1)
|
||||||
|
ret void
|
||||||
|
}
|
||||||
|
|
||||||
|
define void @"github.com/goplus/llgo/cl/_testdata/geometry1370.init"() {
|
||||||
|
_llgo_0:
|
||||||
|
%0 = load i1, ptr @"github.com/goplus/llgo/cl/_testdata/geometry1370.init$guard", align 1
|
||||||
|
br i1 %0, label %_llgo_2, label %_llgo_1
|
||||||
|
|
||||||
|
_llgo_1: ; preds = %_llgo_0
|
||||||
|
store i1 true, ptr @"github.com/goplus/llgo/cl/_testdata/geometry1370.init$guard", align 1
|
||||||
|
br label %_llgo_2
|
||||||
|
|
||||||
|
_llgo_2: ; preds = %_llgo_1, %_llgo_0
|
||||||
|
ret void
|
||||||
|
}
|
||||||
|
|
||||||
|
declare ptr @"github.com/goplus/llgo/runtime/internal/runtime.AllocZ"(i64)
|
||||||
|
|
||||||
|
declare ptr @"github.com/goplus/llgo/runtime/internal/runtime.IfacePtrData"(%"github.com/goplus/llgo/runtime/internal/runtime.iface")
|
||||||
11
cl/_testgo/interface1370/in.go
Normal file
11
cl/_testgo/interface1370/in.go
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/goplus/llgo/cl/_testdata/geometry1370"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
rect := geometry1370.NewRectangle(5.0, 3.0)
|
||||||
|
geometry1370.RegisterShape(rect, 42)
|
||||||
|
println("ID:", rect.GetID())
|
||||||
|
}
|
||||||
333
cl/_testgo/interface1370/out.ll
Normal file
333
cl/_testgo/interface1370/out.ll
Normal file
@@ -0,0 +1,333 @@
|
|||||||
|
; ModuleID = 'github.com/goplus/llgo/cl/_testgo/interface1370'
|
||||||
|
source_filename = "github.com/goplus/llgo/cl/_testgo/interface1370"
|
||||||
|
|
||||||
|
%"github.com/goplus/llgo/runtime/internal/runtime.iface" = type { ptr, ptr }
|
||||||
|
%"github.com/goplus/llgo/runtime/internal/runtime.String" = type { ptr, i64 }
|
||||||
|
%"github.com/goplus/llgo/runtime/abi.StructField" = type { %"github.com/goplus/llgo/runtime/internal/runtime.String", ptr, i64, %"github.com/goplus/llgo/runtime/internal/runtime.String", i1 }
|
||||||
|
%"github.com/goplus/llgo/runtime/internal/runtime.Slice" = type { ptr, i64, i64 }
|
||||||
|
%"github.com/goplus/llgo/runtime/abi.Method" = type { %"github.com/goplus/llgo/runtime/internal/runtime.String", ptr, ptr, ptr }
|
||||||
|
%"github.com/goplus/llgo/runtime/abi.Imethod" = type { %"github.com/goplus/llgo/runtime/internal/runtime.String", ptr }
|
||||||
|
|
||||||
|
@"github.com/goplus/llgo/cl/_testgo/interface1370.init$guard" = global i1 false, align 1
|
||||||
|
@"_llgo_github.com/goplus/llgo/cl/_testdata/geometry1370.Rectangle" = linkonce global ptr null, align 8
|
||||||
|
@0 = private unnamed_addr constant [48 x i8] c"github.com/goplus/llgo/cl/_testdata/geometry1370", align 1
|
||||||
|
@1 = private unnamed_addr constant [9 x i8] c"Rectangle", align 1
|
||||||
|
@_llgo_float64 = linkonce global ptr null, align 8
|
||||||
|
@_llgo_int = linkonce global ptr null, align 8
|
||||||
|
@"github.com/goplus/llgo/cl/_testgo/interface1370.struct$EuRbjzGGO7GwkW6RxZGl-8lEjTdEMzAFD8LnY_SpVoQ" = linkonce global ptr null, align 8
|
||||||
|
@2 = private unnamed_addr constant [5 x i8] c"Width", align 1
|
||||||
|
@3 = private unnamed_addr constant [6 x i8] c"Height", align 1
|
||||||
|
@4 = private unnamed_addr constant [2 x i8] c"id", align 1
|
||||||
|
@5 = private unnamed_addr constant [47 x i8] c"github.com/goplus/llgo/cl/_testgo/interface1370", align 1
|
||||||
|
@6 = private unnamed_addr constant [4 x i8] c"Area", align 1
|
||||||
|
@"_llgo_func$UYiLlmcWxoOKZPPzvR4LByitNeKoVGoTrB_5ubdOWW8" = linkonce global ptr null, align 8
|
||||||
|
@7 = private unnamed_addr constant [5 x i8] c"GetID", align 1
|
||||||
|
@"_llgo_func$ETeB8WwW04JEq0ztcm-XPTJtuYvtpkjIsAc0-2NT9zA" = linkonce global ptr null, align 8
|
||||||
|
@8 = private unnamed_addr constant [5 x i8] c"setID", align 1
|
||||||
|
@9 = private unnamed_addr constant [54 x i8] c"github.com/goplus/llgo/cl/_testdata/geometry1370.setID", align 1
|
||||||
|
@"_llgo_func$VZ-8VPNF1RaLICwxc1Ghn7BbgyFX3v762OCdx127EkA" = linkonce global ptr null, align 8
|
||||||
|
@10 = private unnamed_addr constant [8 x i8] c"validate", align 1
|
||||||
|
@11 = private unnamed_addr constant [57 x i8] c"github.com/goplus/llgo/cl/_testdata/geometry1370.validate", align 1
|
||||||
|
@_llgo_bool = linkonce global ptr null, align 8
|
||||||
|
@"_llgo_func$YHeRw3AOvQtzv982-ZO3Yn8vh3Fx89RM3VvI8E4iKVk" = linkonce global ptr null, align 8
|
||||||
|
@"*_llgo_github.com/goplus/llgo/cl/_testdata/geometry1370.Rectangle" = linkonce global ptr null, align 8
|
||||||
|
@"github.com/goplus/llgo/cl/_testgo/interface1370.iface$OopIVfjRcxQr1gmJyGi5G7hHt__vH05AREEM7PthH9o" = linkonce global ptr null, align 8
|
||||||
|
@12 = private unnamed_addr constant [3 x i8] c"ID:", align 1
|
||||||
|
|
||||||
|
define void @"github.com/goplus/llgo/cl/_testgo/interface1370.init"() {
|
||||||
|
_llgo_0:
|
||||||
|
%0 = load i1, ptr @"github.com/goplus/llgo/cl/_testgo/interface1370.init$guard", align 1
|
||||||
|
br i1 %0, label %_llgo_2, label %_llgo_1
|
||||||
|
|
||||||
|
_llgo_1: ; preds = %_llgo_0
|
||||||
|
store i1 true, ptr @"github.com/goplus/llgo/cl/_testgo/interface1370.init$guard", align 1
|
||||||
|
call void @"github.com/goplus/llgo/cl/_testdata/geometry1370.init"()
|
||||||
|
call void @"github.com/goplus/llgo/cl/_testgo/interface1370.init$after"()
|
||||||
|
br label %_llgo_2
|
||||||
|
|
||||||
|
_llgo_2: ; preds = %_llgo_1, %_llgo_0
|
||||||
|
ret void
|
||||||
|
}
|
||||||
|
|
||||||
|
define void @"github.com/goplus/llgo/cl/_testgo/interface1370.main"() {
|
||||||
|
_llgo_0:
|
||||||
|
%0 = call ptr @"github.com/goplus/llgo/cl/_testdata/geometry1370.NewRectangle"(double 5.000000e+00, double 3.000000e+00)
|
||||||
|
%1 = load ptr, ptr @"_llgo_github.com/goplus/llgo/cl/_testdata/geometry1370.Rectangle", align 8
|
||||||
|
%2 = load ptr, ptr @"*_llgo_github.com/goplus/llgo/cl/_testdata/geometry1370.Rectangle", align 8
|
||||||
|
%3 = load ptr, ptr @"_llgo_func$UYiLlmcWxoOKZPPzvR4LByitNeKoVGoTrB_5ubdOWW8", align 8
|
||||||
|
%4 = load ptr, ptr @"_llgo_func$VZ-8VPNF1RaLICwxc1Ghn7BbgyFX3v762OCdx127EkA", align 8
|
||||||
|
%5 = load ptr, ptr @"_llgo_func$YHeRw3AOvQtzv982-ZO3Yn8vh3Fx89RM3VvI8E4iKVk", align 8
|
||||||
|
%6 = load ptr, ptr @"github.com/goplus/llgo/cl/_testgo/interface1370.iface$OopIVfjRcxQr1gmJyGi5G7hHt__vH05AREEM7PthH9o", align 8
|
||||||
|
%7 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.NewItab"(ptr %6, ptr %2)
|
||||||
|
%8 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.iface" undef, ptr %7, 0
|
||||||
|
%9 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.iface" %8, ptr %0, 1
|
||||||
|
call void @"github.com/goplus/llgo/cl/_testdata/geometry1370.RegisterShape"(%"github.com/goplus/llgo/runtime/internal/runtime.iface" %9, i64 42)
|
||||||
|
%10 = call i64 @"github.com/goplus/llgo/cl/_testdata/geometry1370.(*Rectangle).GetID"(ptr %0)
|
||||||
|
call void @"github.com/goplus/llgo/runtime/internal/runtime.PrintString"(%"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @12, i64 3 })
|
||||||
|
call void @"github.com/goplus/llgo/runtime/internal/runtime.PrintByte"(i8 32)
|
||||||
|
call void @"github.com/goplus/llgo/runtime/internal/runtime.PrintInt"(i64 %10)
|
||||||
|
call void @"github.com/goplus/llgo/runtime/internal/runtime.PrintByte"(i8 10)
|
||||||
|
ret void
|
||||||
|
}
|
||||||
|
|
||||||
|
declare void @"github.com/goplus/llgo/cl/_testdata/geometry1370.init"()
|
||||||
|
|
||||||
|
declare ptr @"github.com/goplus/llgo/cl/_testdata/geometry1370.NewRectangle"(double, double)
|
||||||
|
|
||||||
|
declare void @"github.com/goplus/llgo/cl/_testdata/geometry1370.RegisterShape"(%"github.com/goplus/llgo/runtime/internal/runtime.iface", i64)
|
||||||
|
|
||||||
|
define void @"github.com/goplus/llgo/cl/_testgo/interface1370.init$after"() {
|
||||||
|
_llgo_0:
|
||||||
|
%0 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.NewNamed"(%"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @0, i64 48 }, %"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @1, i64 9 }, i64 25, i64 24, i64 0, i64 4)
|
||||||
|
%1 = load ptr, ptr @"_llgo_github.com/goplus/llgo/cl/_testdata/geometry1370.Rectangle", align 8
|
||||||
|
%2 = icmp eq ptr %1, null
|
||||||
|
br i1 %2, label %_llgo_1, label %_llgo_2
|
||||||
|
|
||||||
|
_llgo_1: ; preds = %_llgo_0
|
||||||
|
store ptr %0, ptr @"_llgo_github.com/goplus/llgo/cl/_testdata/geometry1370.Rectangle", align 8
|
||||||
|
br label %_llgo_2
|
||||||
|
|
||||||
|
_llgo_2: ; preds = %_llgo_1, %_llgo_0
|
||||||
|
%3 = load ptr, ptr @_llgo_float64, align 8
|
||||||
|
%4 = icmp eq ptr %3, null
|
||||||
|
br i1 %4, label %_llgo_3, label %_llgo_4
|
||||||
|
|
||||||
|
_llgo_3: ; preds = %_llgo_2
|
||||||
|
%5 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.Basic"(i64 46)
|
||||||
|
store ptr %5, ptr @_llgo_float64, align 8
|
||||||
|
br label %_llgo_4
|
||||||
|
|
||||||
|
_llgo_4: ; preds = %_llgo_3, %_llgo_2
|
||||||
|
%6 = load ptr, ptr @_llgo_float64, align 8
|
||||||
|
%7 = load ptr, ptr @_llgo_int, align 8
|
||||||
|
%8 = icmp eq ptr %7, null
|
||||||
|
br i1 %8, label %_llgo_5, label %_llgo_6
|
||||||
|
|
||||||
|
_llgo_5: ; preds = %_llgo_4
|
||||||
|
%9 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.Basic"(i64 34)
|
||||||
|
store ptr %9, ptr @_llgo_int, align 8
|
||||||
|
br label %_llgo_6
|
||||||
|
|
||||||
|
_llgo_6: ; preds = %_llgo_5, %_llgo_4
|
||||||
|
%10 = load ptr, ptr @_llgo_int, align 8
|
||||||
|
%11 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.Basic"(i64 46)
|
||||||
|
%12 = call %"github.com/goplus/llgo/runtime/abi.StructField" @"github.com/goplus/llgo/runtime/internal/runtime.StructField"(%"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @2, i64 5 }, ptr %11, i64 0, %"github.com/goplus/llgo/runtime/internal/runtime.String" zeroinitializer, i1 false)
|
||||||
|
%13 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.Basic"(i64 46)
|
||||||
|
%14 = call %"github.com/goplus/llgo/runtime/abi.StructField" @"github.com/goplus/llgo/runtime/internal/runtime.StructField"(%"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @3, i64 6 }, ptr %13, i64 8, %"github.com/goplus/llgo/runtime/internal/runtime.String" zeroinitializer, i1 false)
|
||||||
|
%15 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.Basic"(i64 34)
|
||||||
|
%16 = call %"github.com/goplus/llgo/runtime/abi.StructField" @"github.com/goplus/llgo/runtime/internal/runtime.StructField"(%"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @4, i64 2 }, ptr %15, i64 16, %"github.com/goplus/llgo/runtime/internal/runtime.String" zeroinitializer, i1 false)
|
||||||
|
%17 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.AllocU"(i64 168)
|
||||||
|
%18 = getelementptr %"github.com/goplus/llgo/runtime/abi.StructField", ptr %17, i64 0
|
||||||
|
store %"github.com/goplus/llgo/runtime/abi.StructField" %12, ptr %18, align 8
|
||||||
|
%19 = getelementptr %"github.com/goplus/llgo/runtime/abi.StructField", ptr %17, i64 1
|
||||||
|
store %"github.com/goplus/llgo/runtime/abi.StructField" %14, ptr %19, align 8
|
||||||
|
%20 = getelementptr %"github.com/goplus/llgo/runtime/abi.StructField", ptr %17, i64 2
|
||||||
|
store %"github.com/goplus/llgo/runtime/abi.StructField" %16, ptr %20, align 8
|
||||||
|
%21 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.Slice" undef, ptr %17, 0
|
||||||
|
%22 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.Slice" %21, i64 3, 1
|
||||||
|
%23 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.Slice" %22, i64 3, 2
|
||||||
|
%24 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.Struct"(%"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @5, i64 47 }, i64 24, %"github.com/goplus/llgo/runtime/internal/runtime.Slice" %23)
|
||||||
|
store ptr %24, ptr @"github.com/goplus/llgo/cl/_testgo/interface1370.struct$EuRbjzGGO7GwkW6RxZGl-8lEjTdEMzAFD8LnY_SpVoQ", align 8
|
||||||
|
%25 = load ptr, ptr @"github.com/goplus/llgo/cl/_testgo/interface1370.struct$EuRbjzGGO7GwkW6RxZGl-8lEjTdEMzAFD8LnY_SpVoQ", align 8
|
||||||
|
br i1 %2, label %_llgo_7, label %_llgo_8
|
||||||
|
|
||||||
|
_llgo_7: ; preds = %_llgo_6
|
||||||
|
%26 = load ptr, ptr @"_llgo_func$UYiLlmcWxoOKZPPzvR4LByitNeKoVGoTrB_5ubdOWW8", align 8
|
||||||
|
%27 = icmp eq ptr %26, null
|
||||||
|
br i1 %27, label %_llgo_9, label %_llgo_10
|
||||||
|
|
||||||
|
_llgo_8: ; preds = %_llgo_18, %_llgo_6
|
||||||
|
%28 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.NewNamed"(%"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @0, i64 48 }, %"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @1, i64 9 }, i64 25, i64 24, i64 0, i64 4)
|
||||||
|
%29 = load ptr, ptr @"*_llgo_github.com/goplus/llgo/cl/_testdata/geometry1370.Rectangle", align 8
|
||||||
|
%30 = icmp eq ptr %29, null
|
||||||
|
br i1 %30, label %_llgo_19, label %_llgo_20
|
||||||
|
|
||||||
|
_llgo_9: ; preds = %_llgo_7
|
||||||
|
%31 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.AllocU"(i64 0)
|
||||||
|
%32 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.Slice" undef, ptr %31, 0
|
||||||
|
%33 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.Slice" %32, i64 0, 1
|
||||||
|
%34 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.Slice" %33, i64 0, 2
|
||||||
|
%35 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.Basic"(i64 46)
|
||||||
|
%36 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.AllocU"(i64 8)
|
||||||
|
%37 = getelementptr ptr, ptr %36, i64 0
|
||||||
|
store ptr %35, ptr %37, align 8
|
||||||
|
%38 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.Slice" undef, ptr %36, 0
|
||||||
|
%39 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.Slice" %38, i64 1, 1
|
||||||
|
%40 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.Slice" %39, i64 1, 2
|
||||||
|
%41 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.Func"(%"github.com/goplus/llgo/runtime/internal/runtime.Slice" %34, %"github.com/goplus/llgo/runtime/internal/runtime.Slice" %40, i1 false)
|
||||||
|
call void @"github.com/goplus/llgo/runtime/internal/runtime.SetDirectIface"(ptr %41)
|
||||||
|
store ptr %41, ptr @"_llgo_func$UYiLlmcWxoOKZPPzvR4LByitNeKoVGoTrB_5ubdOWW8", align 8
|
||||||
|
br label %_llgo_10
|
||||||
|
|
||||||
|
_llgo_10: ; preds = %_llgo_9, %_llgo_7
|
||||||
|
%42 = load ptr, ptr @"_llgo_func$UYiLlmcWxoOKZPPzvR4LByitNeKoVGoTrB_5ubdOWW8", align 8
|
||||||
|
%43 = insertvalue %"github.com/goplus/llgo/runtime/abi.Method" { %"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @6, i64 4 }, ptr undef, ptr undef, ptr undef }, ptr %42, 1
|
||||||
|
%44 = insertvalue %"github.com/goplus/llgo/runtime/abi.Method" %43, ptr @"github.com/goplus/llgo/cl/_testdata/geometry1370.(*Rectangle).Area", 2
|
||||||
|
%45 = insertvalue %"github.com/goplus/llgo/runtime/abi.Method" %44, ptr @"github.com/goplus/llgo/cl/_testdata/geometry1370.(*Rectangle).Area", 3
|
||||||
|
%46 = load ptr, ptr @"_llgo_func$ETeB8WwW04JEq0ztcm-XPTJtuYvtpkjIsAc0-2NT9zA", align 8
|
||||||
|
%47 = icmp eq ptr %46, null
|
||||||
|
br i1 %47, label %_llgo_11, label %_llgo_12
|
||||||
|
|
||||||
|
_llgo_11: ; preds = %_llgo_10
|
||||||
|
%48 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.AllocU"(i64 0)
|
||||||
|
%49 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.Slice" undef, ptr %48, 0
|
||||||
|
%50 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.Slice" %49, i64 0, 1
|
||||||
|
%51 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.Slice" %50, i64 0, 2
|
||||||
|
%52 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.Basic"(i64 34)
|
||||||
|
%53 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.AllocU"(i64 8)
|
||||||
|
%54 = getelementptr ptr, ptr %53, i64 0
|
||||||
|
store ptr %52, ptr %54, align 8
|
||||||
|
%55 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.Slice" undef, ptr %53, 0
|
||||||
|
%56 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.Slice" %55, i64 1, 1
|
||||||
|
%57 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.Slice" %56, i64 1, 2
|
||||||
|
%58 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.Func"(%"github.com/goplus/llgo/runtime/internal/runtime.Slice" %51, %"github.com/goplus/llgo/runtime/internal/runtime.Slice" %57, i1 false)
|
||||||
|
call void @"github.com/goplus/llgo/runtime/internal/runtime.SetDirectIface"(ptr %58)
|
||||||
|
store ptr %58, ptr @"_llgo_func$ETeB8WwW04JEq0ztcm-XPTJtuYvtpkjIsAc0-2NT9zA", align 8
|
||||||
|
br label %_llgo_12
|
||||||
|
|
||||||
|
_llgo_12: ; preds = %_llgo_11, %_llgo_10
|
||||||
|
%59 = load ptr, ptr @"_llgo_func$ETeB8WwW04JEq0ztcm-XPTJtuYvtpkjIsAc0-2NT9zA", align 8
|
||||||
|
%60 = insertvalue %"github.com/goplus/llgo/runtime/abi.Method" { %"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @7, i64 5 }, ptr undef, ptr undef, ptr undef }, ptr %59, 1
|
||||||
|
%61 = insertvalue %"github.com/goplus/llgo/runtime/abi.Method" %60, ptr @"github.com/goplus/llgo/cl/_testdata/geometry1370.(*Rectangle).GetID", 2
|
||||||
|
%62 = insertvalue %"github.com/goplus/llgo/runtime/abi.Method" %61, ptr @"github.com/goplus/llgo/cl/_testdata/geometry1370.(*Rectangle).GetID", 3
|
||||||
|
%63 = load ptr, ptr @"_llgo_func$VZ-8VPNF1RaLICwxc1Ghn7BbgyFX3v762OCdx127EkA", align 8
|
||||||
|
%64 = icmp eq ptr %63, null
|
||||||
|
br i1 %64, label %_llgo_13, label %_llgo_14
|
||||||
|
|
||||||
|
_llgo_13: ; preds = %_llgo_12
|
||||||
|
%65 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.Basic"(i64 34)
|
||||||
|
%66 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.AllocU"(i64 8)
|
||||||
|
%67 = getelementptr ptr, ptr %66, i64 0
|
||||||
|
store ptr %65, ptr %67, align 8
|
||||||
|
%68 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.Slice" undef, ptr %66, 0
|
||||||
|
%69 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.Slice" %68, i64 1, 1
|
||||||
|
%70 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.Slice" %69, i64 1, 2
|
||||||
|
%71 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.AllocU"(i64 0)
|
||||||
|
%72 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.Slice" undef, ptr %71, 0
|
||||||
|
%73 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.Slice" %72, i64 0, 1
|
||||||
|
%74 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.Slice" %73, i64 0, 2
|
||||||
|
%75 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.Func"(%"github.com/goplus/llgo/runtime/internal/runtime.Slice" %70, %"github.com/goplus/llgo/runtime/internal/runtime.Slice" %74, i1 false)
|
||||||
|
call void @"github.com/goplus/llgo/runtime/internal/runtime.SetDirectIface"(ptr %75)
|
||||||
|
store ptr %75, ptr @"_llgo_func$VZ-8VPNF1RaLICwxc1Ghn7BbgyFX3v762OCdx127EkA", align 8
|
||||||
|
br label %_llgo_14
|
||||||
|
|
||||||
|
_llgo_14: ; preds = %_llgo_13, %_llgo_12
|
||||||
|
%76 = load ptr, ptr @"_llgo_func$VZ-8VPNF1RaLICwxc1Ghn7BbgyFX3v762OCdx127EkA", align 8
|
||||||
|
%77 = insertvalue %"github.com/goplus/llgo/runtime/abi.Method" { %"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @9, i64 54 }, ptr undef, ptr undef, ptr undef }, ptr %76, 1
|
||||||
|
%78 = insertvalue %"github.com/goplus/llgo/runtime/abi.Method" %77, ptr @"github.com/goplus/llgo/cl/_testdata/geometry1370.(*Rectangle).setID", 2
|
||||||
|
%79 = insertvalue %"github.com/goplus/llgo/runtime/abi.Method" %78, ptr @"github.com/goplus/llgo/cl/_testdata/geometry1370.(*Rectangle).setID", 3
|
||||||
|
%80 = load ptr, ptr @_llgo_bool, align 8
|
||||||
|
%81 = icmp eq ptr %80, null
|
||||||
|
br i1 %81, label %_llgo_15, label %_llgo_16
|
||||||
|
|
||||||
|
_llgo_15: ; preds = %_llgo_14
|
||||||
|
%82 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.Basic"(i64 33)
|
||||||
|
store ptr %82, ptr @_llgo_bool, align 8
|
||||||
|
br label %_llgo_16
|
||||||
|
|
||||||
|
_llgo_16: ; preds = %_llgo_15, %_llgo_14
|
||||||
|
%83 = load ptr, ptr @_llgo_bool, align 8
|
||||||
|
%84 = load ptr, ptr @"_llgo_func$YHeRw3AOvQtzv982-ZO3Yn8vh3Fx89RM3VvI8E4iKVk", align 8
|
||||||
|
%85 = icmp eq ptr %84, null
|
||||||
|
br i1 %85, label %_llgo_17, label %_llgo_18
|
||||||
|
|
||||||
|
_llgo_17: ; preds = %_llgo_16
|
||||||
|
%86 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.AllocU"(i64 0)
|
||||||
|
%87 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.Slice" undef, ptr %86, 0
|
||||||
|
%88 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.Slice" %87, i64 0, 1
|
||||||
|
%89 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.Slice" %88, i64 0, 2
|
||||||
|
%90 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.Basic"(i64 33)
|
||||||
|
%91 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.AllocU"(i64 8)
|
||||||
|
%92 = getelementptr ptr, ptr %91, i64 0
|
||||||
|
store ptr %90, ptr %92, align 8
|
||||||
|
%93 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.Slice" undef, ptr %91, 0
|
||||||
|
%94 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.Slice" %93, i64 1, 1
|
||||||
|
%95 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.Slice" %94, i64 1, 2
|
||||||
|
%96 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.Func"(%"github.com/goplus/llgo/runtime/internal/runtime.Slice" %89, %"github.com/goplus/llgo/runtime/internal/runtime.Slice" %95, i1 false)
|
||||||
|
call void @"github.com/goplus/llgo/runtime/internal/runtime.SetDirectIface"(ptr %96)
|
||||||
|
store ptr %96, ptr @"_llgo_func$YHeRw3AOvQtzv982-ZO3Yn8vh3Fx89RM3VvI8E4iKVk", align 8
|
||||||
|
br label %_llgo_18
|
||||||
|
|
||||||
|
_llgo_18: ; preds = %_llgo_17, %_llgo_16
|
||||||
|
%97 = load ptr, ptr @"_llgo_func$YHeRw3AOvQtzv982-ZO3Yn8vh3Fx89RM3VvI8E4iKVk", align 8
|
||||||
|
%98 = insertvalue %"github.com/goplus/llgo/runtime/abi.Method" { %"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @11, i64 57 }, ptr undef, ptr undef, ptr undef }, ptr %97, 1
|
||||||
|
%99 = insertvalue %"github.com/goplus/llgo/runtime/abi.Method" %98, ptr @"github.com/goplus/llgo/cl/_testdata/geometry1370.(*Rectangle).validate", 2
|
||||||
|
%100 = insertvalue %"github.com/goplus/llgo/runtime/abi.Method" %99, ptr @"github.com/goplus/llgo/cl/_testdata/geometry1370.(*Rectangle).validate", 3
|
||||||
|
%101 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.AllocU"(i64 160)
|
||||||
|
%102 = getelementptr %"github.com/goplus/llgo/runtime/abi.Method", ptr %101, i64 0
|
||||||
|
store %"github.com/goplus/llgo/runtime/abi.Method" %45, ptr %102, align 8
|
||||||
|
%103 = getelementptr %"github.com/goplus/llgo/runtime/abi.Method", ptr %101, i64 1
|
||||||
|
store %"github.com/goplus/llgo/runtime/abi.Method" %62, ptr %103, align 8
|
||||||
|
%104 = getelementptr %"github.com/goplus/llgo/runtime/abi.Method", ptr %101, i64 2
|
||||||
|
store %"github.com/goplus/llgo/runtime/abi.Method" %79, ptr %104, align 8
|
||||||
|
%105 = getelementptr %"github.com/goplus/llgo/runtime/abi.Method", ptr %101, i64 3
|
||||||
|
store %"github.com/goplus/llgo/runtime/abi.Method" %100, ptr %105, align 8
|
||||||
|
%106 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.Slice" undef, ptr %101, 0
|
||||||
|
%107 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.Slice" %106, i64 4, 1
|
||||||
|
%108 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.Slice" %107, i64 4, 2
|
||||||
|
call void @"github.com/goplus/llgo/runtime/internal/runtime.InitNamed"(ptr %0, ptr %25, { ptr, i64, i64 } zeroinitializer, %"github.com/goplus/llgo/runtime/internal/runtime.Slice" %108)
|
||||||
|
br label %_llgo_8
|
||||||
|
|
||||||
|
_llgo_19: ; preds = %_llgo_8
|
||||||
|
%109 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.PointerTo"(ptr %28)
|
||||||
|
call void @"github.com/goplus/llgo/runtime/internal/runtime.SetDirectIface"(ptr %109)
|
||||||
|
store ptr %109, ptr @"*_llgo_github.com/goplus/llgo/cl/_testdata/geometry1370.Rectangle", align 8
|
||||||
|
br label %_llgo_20
|
||||||
|
|
||||||
|
_llgo_20: ; preds = %_llgo_19, %_llgo_8
|
||||||
|
%110 = load ptr, ptr @"_llgo_func$UYiLlmcWxoOKZPPzvR4LByitNeKoVGoTrB_5ubdOWW8", align 8
|
||||||
|
%111 = load ptr, ptr @"_llgo_func$VZ-8VPNF1RaLICwxc1Ghn7BbgyFX3v762OCdx127EkA", align 8
|
||||||
|
%112 = load ptr, ptr @"_llgo_func$YHeRw3AOvQtzv982-ZO3Yn8vh3Fx89RM3VvI8E4iKVk", align 8
|
||||||
|
%113 = insertvalue %"github.com/goplus/llgo/runtime/abi.Imethod" { %"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @6, i64 4 }, ptr undef }, ptr %110, 1
|
||||||
|
%114 = insertvalue %"github.com/goplus/llgo/runtime/abi.Imethod" { %"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @9, i64 54 }, ptr undef }, ptr %111, 1
|
||||||
|
%115 = insertvalue %"github.com/goplus/llgo/runtime/abi.Imethod" { %"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @11, i64 57 }, ptr undef }, ptr %112, 1
|
||||||
|
%116 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.AllocU"(i64 72)
|
||||||
|
%117 = getelementptr %"github.com/goplus/llgo/runtime/abi.Imethod", ptr %116, i64 0
|
||||||
|
store %"github.com/goplus/llgo/runtime/abi.Imethod" %113, ptr %117, align 8
|
||||||
|
%118 = getelementptr %"github.com/goplus/llgo/runtime/abi.Imethod", ptr %116, i64 1
|
||||||
|
store %"github.com/goplus/llgo/runtime/abi.Imethod" %114, ptr %118, align 8
|
||||||
|
%119 = getelementptr %"github.com/goplus/llgo/runtime/abi.Imethod", ptr %116, i64 2
|
||||||
|
store %"github.com/goplus/llgo/runtime/abi.Imethod" %115, ptr %119, align 8
|
||||||
|
%120 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.Slice" undef, ptr %116, 0
|
||||||
|
%121 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.Slice" %120, i64 3, 1
|
||||||
|
%122 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.Slice" %121, i64 3, 2
|
||||||
|
%123 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.Interface"(%"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @5, i64 47 }, %"github.com/goplus/llgo/runtime/internal/runtime.Slice" %122)
|
||||||
|
store ptr %123, ptr @"github.com/goplus/llgo/cl/_testgo/interface1370.iface$OopIVfjRcxQr1gmJyGi5G7hHt__vH05AREEM7PthH9o", align 8
|
||||||
|
ret void
|
||||||
|
}
|
||||||
|
|
||||||
|
declare ptr @"github.com/goplus/llgo/runtime/internal/runtime.NewNamed"(%"github.com/goplus/llgo/runtime/internal/runtime.String", %"github.com/goplus/llgo/runtime/internal/runtime.String", i64, i64, i64, i64)
|
||||||
|
|
||||||
|
declare ptr @"github.com/goplus/llgo/runtime/internal/runtime.Basic"(i64)
|
||||||
|
|
||||||
|
declare ptr @"github.com/goplus/llgo/runtime/internal/runtime.Struct"(%"github.com/goplus/llgo/runtime/internal/runtime.String", i64, %"github.com/goplus/llgo/runtime/internal/runtime.Slice")
|
||||||
|
|
||||||
|
declare %"github.com/goplus/llgo/runtime/abi.StructField" @"github.com/goplus/llgo/runtime/internal/runtime.StructField"(%"github.com/goplus/llgo/runtime/internal/runtime.String", ptr, i64, %"github.com/goplus/llgo/runtime/internal/runtime.String", i1)
|
||||||
|
|
||||||
|
declare ptr @"github.com/goplus/llgo/runtime/internal/runtime.AllocU"(i64)
|
||||||
|
|
||||||
|
declare void @"github.com/goplus/llgo/runtime/internal/runtime.InitNamed"(ptr, ptr, %"github.com/goplus/llgo/runtime/internal/runtime.Slice", %"github.com/goplus/llgo/runtime/internal/runtime.Slice")
|
||||||
|
|
||||||
|
declare ptr @"github.com/goplus/llgo/runtime/internal/runtime.Func"(%"github.com/goplus/llgo/runtime/internal/runtime.Slice", %"github.com/goplus/llgo/runtime/internal/runtime.Slice", i1)
|
||||||
|
|
||||||
|
declare void @"github.com/goplus/llgo/runtime/internal/runtime.SetDirectIface"(ptr)
|
||||||
|
|
||||||
|
declare double @"github.com/goplus/llgo/cl/_testdata/geometry1370.(*Rectangle).Area"(ptr)
|
||||||
|
|
||||||
|
declare i64 @"github.com/goplus/llgo/cl/_testdata/geometry1370.(*Rectangle).GetID"(ptr)
|
||||||
|
|
||||||
|
declare void @"github.com/goplus/llgo/cl/_testdata/geometry1370.(*Rectangle).setID"(ptr, i64)
|
||||||
|
|
||||||
|
declare i1 @"github.com/goplus/llgo/cl/_testdata/geometry1370.(*Rectangle).validate"(ptr)
|
||||||
|
|
||||||
|
declare ptr @"github.com/goplus/llgo/runtime/internal/runtime.PointerTo"(ptr)
|
||||||
|
|
||||||
|
declare ptr @"github.com/goplus/llgo/runtime/internal/runtime.Interface"(%"github.com/goplus/llgo/runtime/internal/runtime.String", %"github.com/goplus/llgo/runtime/internal/runtime.Slice")
|
||||||
|
|
||||||
|
declare ptr @"github.com/goplus/llgo/runtime/internal/runtime.NewItab"(ptr, ptr)
|
||||||
|
|
||||||
|
declare void @"github.com/goplus/llgo/runtime/internal/runtime.PrintString"(%"github.com/goplus/llgo/runtime/internal/runtime.String")
|
||||||
|
|
||||||
|
declare void @"github.com/goplus/llgo/runtime/internal/runtime.PrintByte"(i8)
|
||||||
|
|
||||||
|
declare void @"github.com/goplus/llgo/runtime/internal/runtime.PrintInt"(i64)
|
||||||
@@ -365,7 +365,7 @@ func NewItab(inter *InterfaceType, typ *Type) *Itab {
|
|||||||
ret.fun[0] = 0
|
ret.fun[0] = 0
|
||||||
} else {
|
} else {
|
||||||
data := (*uintptr)(c.Advance(ptr, int(itabHdrSize)))
|
data := (*uintptr)(c.Advance(ptr, int(itabHdrSize)))
|
||||||
mthds := methods(u, inter.PkgPath_)
|
mthds := u.Methods()
|
||||||
for i, m := range inter.Methods {
|
for i, m := range inter.Methods {
|
||||||
fn := findMethod(mthds, m)
|
fn := findMethod(mthds, m)
|
||||||
if fn == nil {
|
if fn == nil {
|
||||||
@@ -395,13 +395,6 @@ func findMethod(mthds []abi.Method, im abi.Imethod) abi.Text {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func methods(u *abi.UncommonType, from string) []abi.Method {
|
|
||||||
if u.PkgPath_ == from {
|
|
||||||
return u.Methods()
|
|
||||||
}
|
|
||||||
return u.ExportedMethods()
|
|
||||||
}
|
|
||||||
|
|
||||||
func IfaceType(i iface) *abi.Type {
|
func IfaceType(i iface) *abi.Type {
|
||||||
if i.tab == nil {
|
if i.tab == nil {
|
||||||
return nil
|
return nil
|
||||||
|
|||||||
Reference in New Issue
Block a user