MCPcopy Create free account
hub / github.com/crossoverJie/gscript / pushStack

Method pushStack

visitor.go:38–74  ·  view source on GitHub ↗

** 栈帧入栈 */

(frame *stack.Frame)

Source from the content-addressed store, hash-verified

36栈帧入栈
37*/
38func (v *Visitor) pushStack(frame *stack.Frame) {
39 // todo crossoverJie parentFrame 设置
40 if !v.stack.IsEmpty() {
41 // 栈顶开始查找
42 for i := v.stack.Size() - 1; i > 0; i-- {
43 f := v.stack.Get(i).(*stack.Frame)
44
45 // 函数是一等公民时,需要根据变量的作用域进行判断
46 funcObject, ok := frame.GetObject().(*stack.FuncObject)
47
48 // 新写入的栈帧的 parent 与当前的 parent 相同时
49 if f.GetScope().GetEncloseScope() == frame.GetScope().GetEncloseScope() {
50 frame.SetParent(f.GetParent())
51 break
52 } else if f.GetScope() == frame.GetScope().GetEncloseScope() {
53 // 新写入的栈帧是某个已有的栈帧的下级
54 frame.SetParent(f)
55 break
56 } else if ok {
57 referenceVariable := funcObject.GetReferenceVariable()
58 if referenceVariable != nil && referenceVariable.GetEncloseScope() == f.GetScope() {
59 frame.SetParent(f)
60 break
61 }
62 }
63
64 }
65
66 if frame.GetParent() == nil {
67 // 上一级作用域作为本级作用域的父级
68 frame.SetParent(v.stack.Peek().(*stack.Frame))
69 }
70
71 }
72
73 v.stack.Push(frame)
74}
75
76func (v *Visitor) popStack() {
77 v.stack.Pop()

Callers 7

VisitProgMethod · 0.95
VisitBlockMethod · 0.95
initClassObjectMethod · 0.95
executeFunctionCallMethod · 0.95
receiveFunctionCallMethod · 0.95
VisitStmForMethod · 0.95
VisitStmWhileMethod · 0.95

Calls 11

IsEmptyMethod · 0.80
GetMethod · 0.80
GetScopeMethod · 0.80
SetParentMethod · 0.80
GetParentMethod · 0.80
GetReferenceVariableMethod · 0.80
PushMethod · 0.80
GetEncloseScopeMethod · 0.65
SizeMethod · 0.45
GetObjectMethod · 0.45
PeekMethod · 0.45

Tested by

no test coverage detected