Skip to content

Commit

Permalink
interp.Func: implement same interface as runtime.Func
Browse files Browse the repository at this point in the history
this allows calling code to interchange both types
  • Loading branch information
bailsman authored and Emanuel Rietveld committed Jan 1, 2022
1 parent 7acf89f commit 5262f9a
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions interp/interp.go
Original file line number Diff line number Diff line change
Expand Up @@ -581,21 +581,33 @@ func funcName(n *node) string {
// by analogy to runtime.FuncForPC()
type Func struct {
Pos token.Position
Name string
Entry uintptr
name string
entry uintptr
}

func (interp *Interpreter) FuncForCall(handle uintptr) *Func {
func (f *Func) Entry() uintptr {
return f.entry
}

func (f *Func) FileLine(pc uintptr) (string, int) {
return f.Pos.Filename, f.Pos.Line
}

func (f *Func) Name() string {
return f.name
}

func (interp *Interpreter) FuncForCall(handle uintptr) (*Func, error) {
n, ok := interp.calls[handle]
if !ok {
return nil
return nil, fmt.Errorf("Call not found")
}
pos := n.interp.fset.Position(n.pos)
return &Func{
pos,
funcName(n),
handle,
}
}, nil
}

func (interp *Interpreter) FilterStack(stack []byte) []byte {
Expand Down

0 comments on commit 5262f9a

Please sign in to comment.