@@ -535,6 +535,12 @@ proc rawExecute(c: PCtx, start: int, tos: PStackFrame): TFullReg =
535535 move (regs, tos.slots)
536536 var regs: seq [TFullReg ] # alias to tos.slots for performance
537537 updateRegsAlias
538+
539+ when callVMExecHooks:
540+ defer :
541+ if not c.exitHook.isNil:
542+ c.exitHook (c, pc, tos)
543+
538544 # echo "NEW RUN ------------------------"
539545 while true :
540546 # {.computedGoto.}
@@ -556,6 +562,11 @@ proc rawExecute(c: PCtx, start: int, tos: PStackFrame): TFullReg =
556562 # other useful variables: c.loopIterations
557563 echo " $# [$#] $#" % [c.config$ info, $ instr.opcode, c.config.sourceLine (info)]
558564 c.profiler.enter (c, tos)
565+
566+ when callVMExecHooks:
567+ if not c.enterHook.isNil:
568+ c.enterHook (c, pc, tos, instr)
569+
559570 case instr.opcode
560571 of opcEof: return regs[ra]
561572 of opcRet:
@@ -2109,14 +2120,19 @@ proc rawExecute(c: PCtx, start: int, tos: PStackFrame): TFullReg =
21092120 storeAny (regs[ra].node.strVal, typ, regs[rb].regToNode, c.config)
21102121
21112122 c.profiler.leave (c)
2112-
2123+ when callVMExecHooks:
2124+ if not c.leaveHook.isNil:
2125+ c.leaveHook (c, pc, tos, instr)
21132126 inc pc
21142127
21152128proc execute (c: PCtx , start: int ): PNode =
21162129 var tos = PStackFrame (prc: nil , comesFrom: 0 , next: nil )
21172130 newSeq (tos.slots, c.prc.regInfo.len)
21182131 result = rawExecute (c, start, tos).regToNode
21192132
2133+ proc execFromCtx * (c: PCtx , pc: int , tos: PStackFrame ): PNode =
2134+ result = rawExecute (c, pc, tos).regToNode
2135+
21202136proc execProc * (c: PCtx ; sym: PSym ; args: openArray [PNode ]): PNode =
21212137 c.loopIterations = c.config.maxLoopIterationsVM
21222138 if sym.kind in routineKinds:
0 commit comments