GitHub

Original file line numberDiff line numberDiff line change

@@ -3175,8 +3175,12 @@ gen_literal_array(codegen_scope *s, node *tree, mrb_bool sym, int val)

31753175

{

31763176

if (val) {

31773177

int array_size = 0;

3178+

int first = 1;

3179+

int slimit = GEN_LIT_ARY_MAX;

31783180

node *current = tree;

31793181
3182+

if (cursp() >= slimit) slimit = GEN_VAL_STACK_MAX;

3183+
31803184

/* Process each segment separated by NODE_LITERAL_DELIM */

31813185

while (current) {

31823186

/* Find the segment boundaries without allocating */

@@ -3213,6 +3217,24 @@ gen_literal_array(codegen_scope *s, node *tree, mrb_bool sym, int val)

32133217
32143218

/* Only process non-empty segments */

32153219

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+
32163238

/* Temporarily terminate the segment by saving and clearing the cdr */

32173239

node *saved_cdr = NULL;

32183240

if (segment_prev) {

@@ -3243,8 +3265,14 @@ gen_literal_array(codegen_scope *s, node *tree, mrb_bool sym, int val)

32433265

}

32443266

}

32453267
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) {

32483276

pop_n(array_size);

32493277

genop_2(s, OP_ARRAY, cursp(), array_size);

32503278

}

Read the original on github.com ↗