forked from gnolang/gno
-
Notifications
You must be signed in to change notification settings - Fork 0
/
frame.go
85 lines (76 loc) · 2.02 KB
/
frame.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
package gno
import "fmt"
//----------------------------------------
// (runtime) Frame
type Frame struct {
// general
Label Name // for break/continue
Source Node // source of frame
NumOps int // number of ops in stack
NumValues int // number of values in stack
NumExprs int // number of exprs in stack
NumStmts int // number of statements in stack
NumBlocks int // number of blocks in stack
// call frame
Func *FuncValue // function value
GoFunc *NativeValue // go function value
Receiver TypedValue // if bound method
NumArgs int // number of arguments in call
IsVarg bool // is form fncall(???, vargs...)
Defers []Defer // deferred calls
LastPackage *PackageValue // previous package context
LastRealm *Realm // previous realm context
}
func (fr Frame) String() string {
if fr.Func != nil {
return fmt.Sprintf("[FRAME FUNC:%v RECV:%s (%d args) %d/%d/%d/%d/%d LASTPKG:%s LASTRLM:%v]",
fr.Func,
fr.Receiver,
fr.NumArgs,
fr.NumOps,
fr.NumValues,
fr.NumExprs,
fr.NumStmts,
fr.NumBlocks,
fr.LastPackage.PkgPath,
fr.LastRealm)
} else if fr.GoFunc != nil {
return fmt.Sprintf("[FRAME GOFUNC:%v RECV:%s (%d args) %d/%d/%d/%d/%d]",
fr.GoFunc.Value,
fr.Receiver,
fr.NumArgs,
fr.NumOps,
fr.NumValues,
fr.NumExprs,
fr.NumStmts,
fr.NumBlocks)
} else {
return fmt.Sprintf("[FRAME LABEL: %s %d/%d/%d/%d/%d]",
fr.Label,
fr.NumOps,
fr.NumValues,
fr.NumExprs,
fr.NumStmts,
fr.NumBlocks)
}
}
func (fr *Frame) PushDefer(dfr Defer) {
fr.Defers = append(fr.Defers, dfr)
}
func (fr *Frame) PopDefer() (res Defer, ok bool) {
if len(fr.Defers) > 0 {
ok = true
res = fr.Defers[len(fr.Defers)-1]
fr.Defers = fr.Defers[:len(fr.Defers)-1]
}
return
}
//----------------------------------------
// Defer
type Defer struct {
Func *FuncValue // function value
GoFunc *NativeValue // go function value
Args []TypedValue // arguments
Source *DeferStmt // source
Parent *Block
}