예제 #1
0
파일: interpreter.go 프로젝트: cretz/jvm.go
func _loop(thread *rtda.Thread) {
	defer _catchErr(thread) // todo

	for {
		frame := thread.CurrentFrame()
		pc := frame.NextPC()
		thread.SetPC(pc)

		// fetch instruction
		method := frame.Method()
		if method.Instructions == nil {
			method.Instructions = decodeMethod(method.Code())
		}
		insts := method.Instructions.([]instructions.Instruction)
		inst := insts[pc]
		instCount := len(insts)

		// update nextPC
		for {
			pc++
			if pc >= instCount || insts[pc] != nil {
				break
			}
		}
		frame.SetNextPC(pc)

		// execute instruction
		//_logInstruction(frame, inst)
		inst.Execute(frame)
		if thread.IsStackEmpty() {
			break
		}
	}
}
예제 #2
0
파일: interpreter.go 프로젝트: cretz/jvm.go
func _logFrames(thread *rtda.Thread) {
	for !thread.IsStackEmpty() {
		frame := thread.PopFrame()
		method := frame.Method()
		className := method.Class().Name()
		lineNum := method.GetLineNumber(frame.NextPC())
		fmt.Printf(">> line:%4d pc:%4d %v.%v%v \n",
			lineNum, frame.NextPC(), className, method.Name(), method.Descriptor())
	}
}