-
Notifications
You must be signed in to change notification settings - Fork 2
/
icall_gen_117.go
93 lines (80 loc) · 2.07 KB
/
icall_gen_117.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
//go:build ignore
// +build ignore
package main
import (
"bytes"
"fmt"
"io/ioutil"
"strconv"
"strings"
)
var head = `// +build !js js,wasm
// +build go1.17,goexperiment.regabireflect
package reflectx
import (
"log"
)
var (
check_max_itype = true
check_max_index = true
)
func icall(t int, i int, max int, ptrto bool, output bool) interface{} {
if t >= max_itype_index {
if check_max_itype {
check_max_itype = false
log.Println("warning, too many types interface call >", t)
}
return func(p, a unsafeptr) {}
}
if i >= max_icall_index {
if check_max_index {
check_max_index = false
log.Println("warning, too many methods interface call >", i)
}
return func(p, a unsafeptr) {}
}
if ptrto {
if output {
return icall_ptr_output[t*max_icall_index+i]
}
return icall_ptr[t*max_icall_index+i]
} else {
if output {
return icall_typ_output[t*max_icall_index+i]
}
return icall_typ[t*max_icall_index+i]
}
}
const max_itype_index = $max_itype
const max_icall_index = $max_index
`
var templ_fn = ` func(p unsafeptr, a iparam) { i_y($itype, $index, p, a, $ptr) },
`
var templ_fn_output = ` func(p unsafeptr, a iparam) iparam { return i_y($itype, $index, p, a, $ptr) },
`
func main() {
writeFile("./icall_go117.go", 64, 256)
}
func writeFile(filename string, max_itype int, max_index int) {
var buf bytes.Buffer
r := strings.NewReplacer("$max_itype", strconv.Itoa(max_itype),
"$max_index", strconv.Itoa(max_index))
buf.WriteString(r.Replace(head))
fnWrite := func(name string, t string, ptr string) {
buf.WriteString(fmt.Sprintf("\nvar %v = []interface{}{\n", name))
for i := 0; i < max_itype; i++ {
for j := 0; j < max_index; j++ {
r := strings.NewReplacer("$itype", strconv.Itoa(i),
"$index", strconv.Itoa(j),
"$ptr", ptr)
buf.WriteString(r.Replace(t))
}
}
buf.WriteString("}\n")
}
fnWrite("icall_typ", templ_fn, "false")
fnWrite("icall_typ_output", templ_fn_output, "false")
fnWrite("icall_ptr", templ_fn, "true")
fnWrite("icall_ptr_output", templ_fn_output, "true")
ioutil.WriteFile(filename, buf.Bytes(), 0666)
}