-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathruntime_func.go
More file actions
121 lines (106 loc) · 2.9 KB
/
Copy pathruntime_func.go
File metadata and controls
121 lines (106 loc) · 2.9 KB
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
//go:build !llgo
// +build !llgo
package ixgo
import (
"path/filepath"
"reflect"
"runtime"
"unsafe"
"github.com/visualfc/funcval"
)
const (
Compiler = runtime.Compiler
IsLLGo = false
)
func init() {
if funcval.IsSupport {
RegisterExternal("(reflect.Value).Pointer", func(fr *frame, v reflect.Value) uintptr {
if v.Kind() == reflect.Func {
if fv, n := funcval.Get(v.Interface()); n == 1 {
if c := (*makeFuncVal)(unsafe.Pointer(fv)); c.interp == fr.interp {
return uintptr(c.pfn.base)
}
}
}
return v.Pointer()
})
RegisterExternal("(reflect.Value).UnsafePointer", func(fr *frame, v reflect.Value) unsafe.Pointer {
if v.Kind() == reflect.Func {
if fv, n := funcval.Get(v.Interface()); n == 1 {
if c := (*makeFuncVal)(unsafe.Pointer(fv)); c.interp == fr.interp {
return unsafe.Pointer(uintptr(c.pfn.base))
}
}
}
return v.UnsafePointer()
})
}
}
//go:linkname runtimePanic runtime.gopanic
func runtimePanic(e interface{})
type funcinl struct {
ones uint32 // set to ^0 to distinguish from _func
entry uintptr // entry of the real (the "outermost") frame
name string
file string
line int
}
func inlineFunc(entry uintptr) *funcinl {
return &funcinl{ones: ^uint32(0), entry: entry}
}
func isInlineFunc(f *runtime.Func) bool {
return (*funcinl)(unsafe.Pointer(f)).ones == ^uint32(0)
}
func runtimeFuncFileLine(fr *frame, f *runtime.Func, pc uintptr) (file string, line int) {
entry := f.Entry()
if isInlineFunc(f) && pc > entry {
interp := fr.interp
if pfn := findFuncByEntry(interp, int(entry)); pfn != nil {
// pc-1 : fn.instr.pos
pos := pfn.PosForPC(int(pc - entry - 1))
if !pos.IsValid() {
return "?", 0
}
fpos := interp.ctx.FileSet.Position(pos)
if fpos.Filename == "" {
return "??", fpos.Line
}
file, line = filepath.ToSlash(fpos.Filename), fpos.Line
return
}
}
return f.FileLine(pc)
}
const supportFuncVal = funcval.IsSupport
func dynamicFunCall(interp *Interp, iv register, ir register, ia []register) func(fr *frame) {
return func(fr *frame) {
fn := fr.reg(iv)
if fv, n := funcval.Get(fn); n == 1 {
if c := (*makeFuncVal)(unsafe.Pointer(fv)); c.interp == interp {
if c.pfn.Recover == nil {
interp.callFunctionByStackNoRecoverWithEnv(fr, c.pfn, ir, ia, c.env)
} else {
interp.callFunctionByStackWithEnv(fr, c.pfn, ir, ia, c.env)
}
return
}
}
v := reflect.ValueOf(fn)
interp.callExternalByStack(fr, v, ir, ia)
}
}
func (pfn *function) makeFunction(typ reflect.Type, env []value) reflect.Value {
interp := pfn.Interp
return reflect.MakeFunc(typ, func(args []reflect.Value) []reflect.Value {
return interp.callFunctionByReflect(interp.tryDeferFrame(), pfn, typ, args, env)
})
}
// makeFuncVal sync with function.makeFunction
type makeFuncVal struct {
funcval.FuncVal
interp *Interp
pfn *function
typ reflect.Type
env []interface{}
}
type interpExt struct{}