From 9b37a4695ebf50b37b5b4fb279ae948f23b5b6a0 Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Tue, 19 Mar 2019 10:53:18 -0300 Subject: New semantics for the integer 'for' loop The numerical 'for' loop over integers now uses a precomputed counter to control its number of iteractions. This change eliminates several weird cases caused by overflows (wrap-around) in the control variable. (It also ensures that every integer loop halts.) Also, the special opcodes for the usual case of step==1 were removed. (The new code is already somewhat complex for the usual case, but efficient.) --- lopcodes.h | 4 ---- 1 file changed, 4 deletions(-) (limited to 'lopcodes.h') diff --git a/lopcodes.h b/lopcodes.h index 3e100259..f867a01b 100644 --- a/lopcodes.h +++ b/lopcodes.h @@ -280,10 +280,6 @@ OP_RETURN,/* A B C return R(A), ... ,R(A+B-2) (see note) */ OP_RETURN0,/* return */ OP_RETURN1,/* A return R(A) */ -OP_FORLOOP1,/* A Bx R(A)++; - if R(A) <= R(A+1) then { pc-=Bx; R(A+3)=R(A) } */ -OP_FORPREP1,/* A Bx R(A)--; pc+=Bx */ - OP_FORLOOP,/* A Bx R(A)+=R(A+2); if R(A)