@@ -122,6 +122,9 @@ typedef enum {
122122
123123 // loop
124124 ISN_FOR, // get next item from a list, uses isn_arg.forloop
125+ ISN_WHILE, // jump if condition false, store funcref count, uses
126+ // isn_arg.whileloop
127+ ISN_ENDLOOP, // handle variables for closures, uses isn_arg.endloop
125128
126129 ISN_TRY, // add entry to ec_trystack, uses isn_arg.tryref
127130 ISN_THROW, // pop value of stack, store in v:exception
@@ -240,6 +243,7 @@ typedef enum {
240243 JUMP_ALWAYS,
241244 JUMP_NEVER,
242245 JUMP_IF_FALSE, // pop and jump if false
246+ JUMP_WHILE_FALSE, // pop and jump if false for :while
243247 JUMP_AND_KEEP_IF_TRUE, // jump if top of stack is truthy, drop if not
244248 JUMP_IF_COND_TRUE, // jump if top of stack is true, drop if not
245249 JUMP_IF_COND_FALSE, // jump if top of stack is false, drop if not
@@ -263,6 +267,19 @@ typedef struct {
263267 int for_end; // position to jump to after done
264268} forloop_T;
265269
270+ // arguments to ISN_WHILE
271+ typedef struct {
272+ int while_funcref_idx; // variable index for funcref count
273+ int while_end; // position to jump to after done
274+ } whileloop_T;
275+
276+ // arguments to ISN_ENDLOOP
277+ typedef struct {
278+ short end_funcref_idx; // variable index of funcrefs.ga_len
279+ short end_var_idx; // first variable declared in the loop
280+ short end_var_count; // number of variables declared in the loop
281+ } endloop_T;
282+
266283// indirect arguments to ISN_TRY
267284typedef struct {
268285 int try_catch; // position to jump to on throw
@@ -446,6 +463,8 @@ struct isn_S {
446463 jump_T jump;
447464 jumparg_T jumparg;
448465 forloop_T forloop;
466+ whileloop_T whileloop;
467+ endloop_T endloop;
449468 try_T tryref;
450469 trycont_T trycont;
451470 cbfunc_T bfunc;
@@ -597,6 +616,9 @@ typedef struct {
597616typedef struct {
598617 int ws_top_label; // instruction idx at WHILE
599618 endlabel_T *ws_end_label; // instructions to set end
619+ int ws_funcref_idx; // index of var that holds funcref count
620+ int ws_local_count; // ctx_locals.ga_len at :while
621+ int ws_closure_count; // ctx_closure_count at :while
600622} whilescope_T;
601623
602624/*
@@ -605,6 +627,9 @@ typedef struct {
605627typedef struct {
606628 int fs_top_label; // instruction idx at FOR
607629 endlabel_T *fs_end_label; // break instructions
630+ int fs_funcref_idx; // index of var that holds funcref count
631+ int fs_local_count; // ctx_locals.ga_len at :for
632+ int fs_closure_count; // ctx_closure_count at :for
608633} forscope_T;
609634
610635/*
@@ -726,8 +751,10 @@ struct cctx_S {
726751
727752 garray_T ctx_locals; // currently visible local variables
728753
729- int ctx_has_closure; // set to one if a closure was created in
730- // the function
754+ int ctx_has_closure; // set to one if a FUNCREF was used in the
755+ // function
756+ int ctx_closure_count; // incremented for each closure created in
757+ // the function.
731758
732759 skip_T ctx_skip;
733760 scope_T *ctx_scope; // current scope, NULL at toplevel
0 commit comments