@@ -3175,8 +3175,12 @@ gen_literal_array(codegen_scope *s, node *tree, mrb_bool sym, int val)
|
3175 | 3175 | { |
3176 | 3176 | if (val) { |
3177 | 3177 | int array_size = 0; |
| 3178 | +int first = 1; |
| 3179 | +int slimit = GEN_LIT_ARY_MAX; |
3178 | 3180 | node *current = tree; |
3179 | 3181 | |
| 3182 | +if (cursp() >= slimit) slimit = GEN_VAL_STACK_MAX; |
| 3183 | + |
3180 | 3184 | /* Process each segment separated by NODE_LITERAL_DELIM */ |
3181 | 3185 | while (current) { |
3182 | 3186 | /* Find the segment boundaries without allocating */ |
@@ -3213,6 +3217,24 @@ gen_literal_array(codegen_scope *s, node *tree, mrb_bool sym, int val)
|
3213 | 3217 | |
3214 | 3218 | /* Only process non-empty segments */ |
3215 | 3219 | if (!is_empty_segment) { |
| 3220 | +/* Flush accumulated elements when stack is full */ |
| 3221 | +if (cursp() >= slimit) { |
| 3222 | +if (array_size > 0) { |
| 3223 | +pop_n(array_size); |
| 3224 | +if (first) { |
| 3225 | +genop_2(s, OP_ARRAY, cursp(), array_size); |
| 3226 | +push(); |
| 3227 | +first = 0; |
| 3228 | + } |
| 3229 | +else { |
| 3230 | +pop(); |
| 3231 | +genop_2(s, OP_ARYPUSH, cursp(), array_size); |
| 3232 | +push(); |
| 3233 | + } |
| 3234 | +array_size = 0; |
| 3235 | + } |
| 3236 | + } |
| 3237 | + |
3216 | 3238 | /* Temporarily terminate the segment by saving and clearing the cdr */ |
3217 | 3239 | node *saved_cdr = NULL; |
3218 | 3240 | if (segment_prev) { |
@@ -3243,8 +3265,14 @@ gen_literal_array(codegen_scope *s, node *tree, mrb_bool sym, int val)
|
3243 | 3265 | } |
3244 | 3266 | } |
3245 | 3267 | |
3246 | | -/* Generate the array from pushed elements */ |
3247 | | -if (array_size > 0) { |
| 3268 | +/* Handle remaining elements */ |
| 3269 | +if (!first) { |
| 3270 | +if (array_size > 0) { |
| 3271 | +pop_n(array_size + 1); |
| 3272 | +genop_2(s, OP_ARYPUSH, cursp(), array_size); |
| 3273 | + } |
| 3274 | + } |
| 3275 | +else if (array_size > 0) { |
3248 | 3276 | pop_n(array_size); |
3249 | 3277 | genop_2(s, OP_ARRAY, cursp(), array_size); |
3250 | 3278 | } |
|