func (fr *Frame) caller() *Frame {
	if fp := fr.prev; fr.state != nil && fp != &fr.state.base {
		return fp
	}
	return nil
}
caller returns the frame's caller frame.
package lua
import "github.com/Azure/golua/lua/vm"
type callStatus uint
const (
	callStatusAllowHook = 1 << iota  
	callStatusTail  
)
type (
	CallInfo struct {
	}
	Frame struct {
		prev, next *Frame            
		closure    *Closure          
		vararg     []Value           
		locals     []Value           
		state      *State            
		depth      int               
		fnID       int               
		rets       int               
		pc         int               
		up         map[int]*upValue  
		status     callStatus        
	}
)
func (fr *Frame) checkstack(needed int) bool {
	if space := cap(fr.locals) - fr.gettop(); space < needed {
		fr.extend(needed - space)
	}
	return true
}
func (fr *Frame) extend(grow int) {
	fr.locals = append(
		fr.locals,
		make([]Value, grow, grow)...,
	)[:len(fr.locals)]
}
func (fr *Frame) absindex(index int) int {
	if index > 0 || isPseudoIndex(index) {
		return index
	}
	return fr.gettop() + index + 1
}
func (fr *Frame) settop(top int) {
	switch diff := fr.gettop() - top; {
	case diff >= 0:  
		for i := 0; i < diff; i++ {
			fr.pop()
		}
	case diff < 0:  
		for i := 0; i > diff; i-- {
			fr.push(None)
		}
	}
}
func (fr *Frame) reverse(src, dst int) {
	for locals := fr.locals; src < dst; {
		locals[src], locals[dst] = locals[dst], locals[src]
		src++
		dst--
	}
}
func (fr *Frame) function() *Closure {
	if fr != nil && fr.closure != nil {
		return fr.closure
	}
	return nil
}
func (fr *Frame) replace(index int) {
	if v := fr.pop(); fr.gettop() == 0 {
		fr.push(v)
	} else {
		fr.set(index, v)
	}
}
func (fr *Frame) rotate(index, n int) {
	var (
		abs = fr.absindex(index) - 1  
		top = fr.gettop() - 1         
		mid int
	)
	if n >= 0 {
		mid = top - n
	} else {
		mid = abs - n - 1
	}
	fr.reverse(abs, mid)    
	fr.reverse(mid+1, top)  
	fr.reverse(abs, top)    
}
func (fr *Frame) remove(index int) {
	fr.rotate(fr.absindex(index), -1)
	fr.pop()
}
func (fr *Frame) insert(index int) { fr.rotate(index, 1) }