Exemple #1
0
func frameInit(fr *interp.Frame) {
	topFrame = fr
	curFrame = fr
	frameIndex = 0
	curBlock = fr.Block()
	// EvalEnv = interp.MakeEnv(EvalEnvironment(), program, fr)
	for stackSize = 0; fr != nil; fr = fr.Caller(0) {
		stackSize++
	}
	switch TraceEvent {
	case ssa2.CALL_RETURN, ssa2.PROGRAM_TERMINATION:
		/* These guys are not in a basic block, so curFrame.Scope
		   won't work here. . Not sure why fr.Fn() memory crashes either.
		   Otherwise, I'd use fr.Fn().Scope
		*/
		curScope = nil

		/* A "block end" sets the frame block can be nil. There should
		   be a better way to do this inside the interpreter but I get:
		       panic: unexpected type: <nil>: <nil>
		   when I tried it and don't know why. */
		switch instr := (*Instr).(type) {
		case *ssa2.Return:
			if curBlock == nil {
				curBlock = instr.Block()
			}
		}

	default:
		// FIXME: may need other cases like defer_enter, panic,
		// block_end?
		curScope = curFrame.Scope()
	}
}
Exemple #2
0
func PrintStack(fr *interp.Frame, count int) {
	if fr == nil {
		return
	}
	for i := 0; fr != nil && i < count; fr = fr.Caller(0) {
		pointer := "   "
		if fr == curFrame {
			pointer = "=> "
		}
		Msg("%s#%d %s", pointer, i, fr.FnAndParamString())
		Msg("\t%s", fr.PositionRange())
		i++
	}
}