[lonetix/bgp] Fix Bgp_VmDoBreak() logic for nested BLKs

This commit is contained in:
Lorenzo Cogotti 2021-10-18 16:35:14 +02:00
parent ef77abb25a
commit 207924beac
1 changed files with 14 additions and 5 deletions

View File

@ -174,19 +174,28 @@ FORCE_INLINE void Bgp_VmDoLoadn(Bgpvm *vm)
} }
/// Break out of current `BLK`. /// Break out of current `BLK`.
FORCE_INLINE void Bgp_VmDoBreak(Bgpvm *vm) INLINE void Bgp_VmDoBreak(Bgpvm *vm)
{ {
Bgpvmopc opc; Bgpvmopc opc;
unsigned n = 1;
do do {
opc = BGP_VMOPC(vm->prog[vm->pc++]); opc = BGP_VMOPC(vm->prog[vm->pc]);
while (opc != BGP_VMOP_ENDBLK && opc != BGP_VMOP_END); if (opc == BGP_VMOP_END) // shouldn't happen with decent bytecode...
break;
if (opc == BGP_VMOP_BLK)
n++;
if (opc == BGP_VMOP_ENDBLK)
n--;
vm->pc++;
} while (n > 0);
if (opc == BGP_VMOP_ENDBLK) if (opc == BGP_VMOP_ENDBLK)
vm->nblk--; vm->nblk--;
} }
/// Execute `CALL` of function `vm->funcs[idx]`. /// Execute `CALL` of function `vm->funcs[idx]`.
FORCE_INLINE void Bgp_VmDoCall(Bgpvm *vm, Uint8 idx) FORCE_INLINE void Bgp_VmDoCall(Bgpvm *vm, Uint8 idx)
{ {