comparison src/structs.h @ 30333:fc0830246f49 v9.0.0502

patch 9.0.0502: a closure in a nested loop in a :def function does not work Commit: https://github.com/vim/vim/commit/cc34181f9994d64f8c8fa2f5845eaf0cc963067f Author: Bram Moolenaar <Bram@vim.org> Date: Mon Sep 19 15:54:34 2022 +0100 patch 9.0.0502: a closure in a nested loop in a :def function does not work Problem: A closure in a nested loop in a :def function does not work. Solution: Use an array of loopvars, one per loop level.
author Bram Moolenaar <Bram@vim.org>
date Mon, 19 Sep 2022 17:00:07 +0200
parents 029c59bf78f1
children 7fc27d7ce3b0
comparison
equal deleted inserted replaced
30332:462d122636b3 30333:fc0830246f49
2106 int lvs_refcount; // nr of closures referencing this loopvars 2106 int lvs_refcount; // nr of closures referencing this loopvars
2107 int lvs_min_refcount; // nr of closures on this loopvars 2107 int lvs_min_refcount; // nr of closures on this loopvars
2108 int lvs_copyID; // for garbage collection 2108 int lvs_copyID; // for garbage collection
2109 }; 2109 };
2110 2110
2111 // maximum nesting of :while and :for loops in a :def function
2112 #define MAX_LOOP_DEPTH 10
2113
2111 typedef struct outer_S outer_T; 2114 typedef struct outer_S outer_T;
2112 struct outer_S { 2115 struct outer_S {
2113 garray_T *out_stack; // stack from outer scope, or a copy 2116 garray_T *out_stack; // stack from outer scope, or a copy
2114 // containing only arguments and local vars 2117 // containing only arguments and local vars
2115 int out_frame_idx; // index of stack frame in out_stack 2118 int out_frame_idx; // index of stack frame in out_stack
2116 outer_T *out_up; // outer scope of outer scope or NULL 2119 outer_T *out_up; // outer scope of outer scope or NULL
2117 partial_T *out_up_partial; // partial owning out_up or NULL 2120 partial_T *out_up_partial; // partial owning out_up or NULL
2118 2121
2119 garray_T *out_loop_stack; // stack from outer scope, or a copy 2122 struct {
2123 garray_T *stack; // stack from outer scope, or a copy
2120 // containing only vars inside the loop 2124 // containing only vars inside the loop
2121 short out_loop_var_idx; // first variable defined in a loop 2125 short var_idx; // first variable defined in a loop in
2122 // in out_loop_stack 2126 // out_loop_stack
2123 short out_loop_var_count; // number of variables defined in a loop 2127 short var_count; // number of variables defined in a loop
2128 } out_loop[MAX_LOOP_DEPTH];
2124 }; 2129 };
2125 2130
2126 struct partial_S 2131 struct partial_S
2127 { 2132 {
2128 int pt_refcount; // reference count 2133 int pt_refcount; // reference count
2139 // For a partial of a partial: use pt_outer values of this partial. 2144 // For a partial of a partial: use pt_outer values of this partial.
2140 partial_T *pt_outer_partial; 2145 partial_T *pt_outer_partial;
2141 2146
2142 funcstack_T *pt_funcstack; // copy of stack, used after context 2147 funcstack_T *pt_funcstack; // copy of stack, used after context
2143 // function returns 2148 // function returns
2144 loopvars_T *pt_loopvars; // copy of loop variables, used after loop 2149 loopvars_T *(pt_loopvars[MAX_LOOP_DEPTH]);
2150 // copy of loop variables, used after loop
2145 // block ends 2151 // block ends
2146 2152
2147 typval_T *pt_argv; // arguments in allocated array 2153 typval_T *pt_argv; // arguments in allocated array
2148 int pt_argc; // number of arguments 2154 int pt_argc; // number of arguments
2149 2155
2150 int pt_copyID; // funcstack may contain pointer to partial 2156 int pt_copyID; // funcstack may contain pointer to partial
2151 dict_T *pt_dict; // dict for "self" 2157 dict_T *pt_dict; // dict for "self"
2152 }; 2158 };
2159
2160 typedef struct {
2161 short lvi_depth; // current nested loop depth
2162 struct {
2163 short var_idx; // index of first variable inside loop
2164 short var_count; // number of variables inside loop
2165 } lvi_loop[MAX_LOOP_DEPTH];
2166 } loopvarinfo_T;
2153 2167
2154 typedef struct AutoPatCmd_S AutoPatCmd_T; 2168 typedef struct AutoPatCmd_S AutoPatCmd_T;
2155 2169
2156 /* 2170 /*
2157 * Entry in the execution stack "exestack". 2171 * Entry in the execution stack "exestack".