diff --git a/src/compiler.c b/src/compiler.c index 38091f7..41423e8 100644 --- a/src/compiler.c +++ b/src/compiler.c @@ -1223,12 +1223,13 @@ static void block(size_t indentation, const char * blockName) { static void doUpvalues(Compiler * compiler, KrkCodeObject * function) { assert(!!function->upvalueCount == !!compiler->upvalues); for (size_t i = 0; i < function->upvalueCount; ++i) { - emitByte(compiler->upvalues[i].isLocal ? 1 : 0); - if (i > 255) { - emitByte((compiler->upvalues[i].index >> 16) & 0xFF); - emitByte((compiler->upvalues[i].index >> 8) & 0xFF); + size_t index = compiler->upvalues[i].index; + emitByte((compiler->upvalues[i].isLocal ? 1 : 0) | ((index > 255) ? 2 : 0)); + if (index > 255) { + emitByte((index >> 16) & 0xFF); + emitByte((index >> 8) & 0xFF); } - emitByte((compiler->upvalues[i].index) & 0xFF); + emitByte(index & 0xFF); } } diff --git a/src/debug.c b/src/debug.c index f605310..dd611ec 100644 --- a/src/debug.c +++ b/src/debug.c @@ -103,7 +103,15 @@ static int isJumpTarget(KrkCodeObject * func, size_t startPoint) { case opc ## _LONG: { size = 4; more; break; } #define JUMP(opc,sign) case opc: { uint16_t jump = (chunk->code[offset + 1] << 8) | (chunk->code[offset + 2]); \ if ((size_t)(offset + 3 sign jump) == startPoint) return 1; size = 3; break; } -#define CLOSURE_MORE size += AS_codeobject(chunk->constants.values[constant])->upvalueCount * 2 +#define CLOSURE_MORE \ + KrkCodeObject * function = AS_codeobject(chunk->constants.values[constant]); \ + for (size_t j = 0; j < function->upvalueCount; ++j) { \ + int isLocal = chunk->code[offset++ + size]; \ + offset++; \ + if (isLocal & 2) { \ + offset += 2; \ + } \ + } #define EXPAND_ARGS_MORE #define LOCAL_MORE @@ -130,22 +138,20 @@ static int isJumpTarget(KrkCodeObject * func, size_t startPoint) { #define CONSTANT(opc,more) case opc: { size_t constant = chunk->code[offset + 1]; \ fprintf(f, "%-16s %4d ", opcodeClean(#opc), (int)constant); \ krk_printValueSafe(f, chunk->constants.values[constant]); \ - more; \ - size = 2; break; } \ + size = 2; more; break; } \ case opc ## _LONG: { size_t constant = (chunk->code[offset + 1] << 16) | \ (chunk->code[offset + 2] << 8) | (chunk->code[offset + 3]); \ fprintf(f, "%-16s %4d ", opcodeClean(#opc "_LONG"), (int)constant); \ krk_printValueSafe(f, chunk->constants.values[constant]); \ - more; size = 4; break; } + size = 4; more; break; } #define OPERANDB(opc,more) case opc: { uint32_t operand = chunk->code[offset + 1]; \ fprintf(f, "%-16s %4d", opcodeClean(#opc), (int)operand); \ - more; size = 2; break; } + size = 2; more; break; } #define OPERAND(opc,more) OPERANDB(opc,more) \ case opc ## _LONG: { uint32_t operand = (chunk->code[offset + 1] << 16) | \ (chunk->code[offset + 2] << 8) | (chunk->code[offset + 3]); \ fprintf(f, "%-16s %4d", opcodeClean(#opc "_LONG"), (int)operand); \ - more; fprintf(f,"\n"); \ - size = 4; break; } + size = 4; more; fprintf(f,"\n"); break; } #define JUMP(opc,sign) case opc: { uint16_t jump = (chunk->code[offset + 1] << 8) | \ (chunk->code[offset + 2]); \ fprintf(f, "%-16s %4d (to %d)", opcodeClean(#opc), (int)jump, (int)(offset + 3 sign jump)); \ @@ -155,9 +161,13 @@ static int isJumpTarget(KrkCodeObject * func, size_t startPoint) { KrkCodeObject * function = AS_codeobject(chunk->constants.values[constant]); \ fprintf(f, " "); \ for (size_t j = 0; j < function->upvalueCount; ++j) { \ - int isLocal = chunk->code[offset++ + 2]; \ - int index = chunk->code[offset++ + 2]; \ - if (isLocal) { \ + int isLocal = chunk->code[offset++ + size]; \ + int index = chunk->code[offset++ + size]; \ + if (isLocal & 2) { \ + index = (index << 16) | (chunk->code[offset + size] << 8) | chunk->code[offset + 1 + size]; \ + offset += 2; \ + } \ + if (isLocal & 1) { \ for (size_t i = 0; i < func->localNameCount; ++i) { \ if (func->localNames[i].id == (size_t)index && func->localNames[i].birthday <= offset && func->localNames[i].deathday >= offset) { \ fprintf(f, "%s", func->localNames[i].name->chars); \ @@ -621,7 +631,15 @@ KRK_FUNC(build,{ (chunk->code[offset + 2] << 8) | (chunk->code[offset + 3]); size = 4; more; break; } #define JUMP(opc,sign) case opc: { jump = 0 sign ((chunk->code[offset + 1] << 8) | (chunk->code[offset + 2])); \ size = 3; break; } -#define CLOSURE_MORE size += AS_codeobject(chunk->constants.values[constant])->upvalueCount * 2 +#define CLOSURE_MORE \ + KrkCodeObject * function = AS_codeobject(chunk->constants.values[constant]); \ + for (size_t j = 0; j < function->upvalueCount; ++j) { \ + int isLocal = chunk->code[offset++ + size]; \ + offset++; \ + if (isLocal & 2) { \ + offset += 2; \ + } \ + } #define EXPAND_ARGS_MORE #define LOCAL_MORE local = operand; static KrkValue _examineInternal(KrkCodeObject* func) { diff --git a/src/vm.c b/src/vm.c index 0b0cba2..0943a32 100644 --- a/src/vm.c +++ b/src/vm.c @@ -2807,13 +2807,12 @@ _finishReturn: (void)0; krk_push(OBJECT_VAL(closure)); for (size_t i = 0; i < closure->upvalueCount; ++i) { int isLocal = READ_BYTE(); - int index = 0; - if (i > 255) { - index = (frame->ip[0] << 16) | (frame->ip[1] << 8); + int index = READ_BYTE(); + if (isLocal & 2) { + index = (index << 16) | (frame->ip[0] << 8) | (frame->ip[1]); frame->ip += 2; } - index |= READ_BYTE(); - if (isLocal) { + if (isLocal & 1) { closure->upvalues[i] = captureUpvalue(frame->slots + index); } else { closure->upvalues[i] = frame->closure->upvalues[index]; diff --git a/test/testLotsOfUpvalues.krk b/test/testLotsOfUpvalues.krk new file mode 100644 index 0000000..f4c119d --- /dev/null +++ b/test/testLotsOfUpvalues.krk @@ -0,0 +1,1045 @@ +if True: + let red_herring_0 = 0 + let red_herring_1 = 1 + let red_herring_2 = 2 + let red_herring_3 = 3 + let red_herring_4 = 4 + let red_herring_5 = 5 + let red_herring_6 = 6 + let red_herring_7 = 7 + let red_herring_8 = 8 + let red_herring_9 = 9 + let red_herring_10 = 10 + let red_herring_11 = 11 + let red_herring_12 = 12 + let red_herring_13 = 13 + let red_herring_14 = 14 + let red_herring_15 = 15 + let red_herring_16 = 16 + let red_herring_17 = 17 + let red_herring_18 = 18 + let red_herring_19 = 19 + let a_0 = 0 + let a_1 = 1 + let a_2 = 2 + let a_3 = 3 + let a_4 = 4 + let a_5 = 5 + let a_6 = 6 + let a_7 = 7 + let a_8 = 8 + let a_9 = 9 + let a_10 = 10 + let a_11 = 11 + let a_12 = 12 + let a_13 = 13 + let a_14 = 14 + let a_15 = 15 + let a_16 = 16 + let a_17 = 17 + let a_18 = 18 + let a_19 = 19 + let a_20 = 20 + let a_21 = 21 + let a_22 = 22 + let a_23 = 23 + let a_24 = 24 + let a_25 = 25 + let a_26 = 26 + let a_27 = 27 + let a_28 = 28 + let a_29 = 29 + let a_30 = 30 + let a_31 = 31 + let a_32 = 32 + let a_33 = 33 + let a_34 = 34 + let a_35 = 35 + let a_36 = 36 + let a_37 = 37 + let a_38 = 38 + let a_39 = 39 + let a_40 = 40 + let a_41 = 41 + let a_42 = 42 + let a_43 = 43 + let a_44 = 44 + let a_45 = 45 + let a_46 = 46 + let a_47 = 47 + let a_48 = 48 + let a_49 = 49 + let a_50 = 50 + let a_51 = 51 + let a_52 = 52 + let a_53 = 53 + let a_54 = 54 + let a_55 = 55 + let a_56 = 56 + let a_57 = 57 + let a_58 = 58 + let a_59 = 59 + let a_60 = 60 + let a_61 = 61 + let a_62 = 62 + let a_63 = 63 + let a_64 = 64 + let a_65 = 65 + let a_66 = 66 + let a_67 = 67 + let a_68 = 68 + let a_69 = 69 + let a_70 = 70 + let a_71 = 71 + let a_72 = 72 + let a_73 = 73 + let a_74 = 74 + let a_75 = 75 + let a_76 = 76 + let a_77 = 77 + let a_78 = 78 + let a_79 = 79 + let a_80 = 80 + let a_81 = 81 + let a_82 = 82 + let a_83 = 83 + let a_84 = 84 + let a_85 = 85 + let a_86 = 86 + let a_87 = 87 + let a_88 = 88 + let a_89 = 89 + let a_90 = 90 + let a_91 = 91 + let a_92 = 92 + let a_93 = 93 + let a_94 = 94 + let a_95 = 95 + let a_96 = 96 + let a_97 = 97 + let a_98 = 98 + let a_99 = 99 + let a_100 = 100 + let a_101 = 101 + let a_102 = 102 + let a_103 = 103 + let a_104 = 104 + let a_105 = 105 + let a_106 = 106 + let a_107 = 107 + let a_108 = 108 + let a_109 = 109 + let a_110 = 110 + let a_111 = 111 + let a_112 = 112 + let a_113 = 113 + let a_114 = 114 + let a_115 = 115 + let a_116 = 116 + let a_117 = 117 + let a_118 = 118 + let a_119 = 119 + let a_120 = 120 + let a_121 = 121 + let a_122 = 122 + let a_123 = 123 + let a_124 = 124 + let a_125 = 125 + let a_126 = 126 + let a_127 = 127 + let a_128 = 128 + let a_129 = 129 + let a_130 = 130 + let a_131 = 131 + let a_132 = 132 + let a_133 = 133 + let a_134 = 134 + let a_135 = 135 + let a_136 = 136 + let a_137 = 137 + let a_138 = 138 + let a_139 = 139 + let a_140 = 140 + let a_141 = 141 + let a_142 = 142 + let a_143 = 143 + let a_144 = 144 + let a_145 = 145 + let a_146 = 146 + let a_147 = 147 + let a_148 = 148 + let a_149 = 149 + let a_150 = 150 + let a_151 = 151 + let a_152 = 152 + let a_153 = 153 + let a_154 = 154 + let a_155 = 155 + let a_156 = 156 + let a_157 = 157 + let a_158 = 158 + let a_159 = 159 + let a_160 = 160 + let a_161 = 161 + let a_162 = 162 + let a_163 = 163 + let a_164 = 164 + let a_165 = 165 + let a_166 = 166 + let a_167 = 167 + let a_168 = 168 + let a_169 = 169 + let a_170 = 170 + let a_171 = 171 + let a_172 = 172 + let a_173 = 173 + let a_174 = 174 + let a_175 = 175 + let a_176 = 176 + let a_177 = 177 + let a_178 = 178 + let a_179 = 179 + let a_180 = 180 + let a_181 = 181 + let a_182 = 182 + let a_183 = 183 + let a_184 = 184 + let a_185 = 185 + let a_186 = 186 + let a_187 = 187 + let a_188 = 188 + let a_189 = 189 + let a_190 = 190 + let a_191 = 191 + let a_192 = 192 + let a_193 = 193 + let a_194 = 194 + let a_195 = 195 + let a_196 = 196 + let a_197 = 197 + let a_198 = 198 + let a_199 = 199 + let a_200 = 200 + let a_201 = 201 + let a_202 = 202 + let a_203 = 203 + let a_204 = 204 + let a_205 = 205 + let a_206 = 206 + let a_207 = 207 + let a_208 = 208 + let a_209 = 209 + let a_210 = 210 + let a_211 = 211 + let a_212 = 212 + let a_213 = 213 + let a_214 = 214 + let a_215 = 215 + let a_216 = 216 + let a_217 = 217 + let a_218 = 218 + let a_219 = 219 + let a_220 = 220 + let a_221 = 221 + let a_222 = 222 + let a_223 = 223 + let a_224 = 224 + let a_225 = 225 + let a_226 = 226 + let a_227 = 227 + let a_228 = 228 + let a_229 = 229 + let a_230 = 230 + let a_231 = 231 + let a_232 = 232 + let a_233 = 233 + let a_234 = 234 + let a_235 = 235 + let a_236 = 236 + let a_237 = 237 + let a_238 = 238 + let a_239 = 239 + let a_240 = 240 + let a_241 = 241 + let a_242 = 242 + let a_243 = 243 + let a_244 = 244 + let a_245 = 245 + let a_246 = 246 + let a_247 = 247 + let a_248 = 248 + let a_249 = 249 + let a_250 = 250 + let a_251 = 251 + let a_252 = 252 + let a_253 = 253 + let a_254 = 254 + let a_255 = 255 + let a_256 = 256 + let a_257 = 257 + let a_258 = 258 + let a_259 = 259 + let a_260 = 260 + let a_261 = 261 + let a_262 = 262 + let a_263 = 263 + let a_264 = 264 + let a_265 = 265 + let a_266 = 266 + let a_267 = 267 + let a_268 = 268 + let a_269 = 269 + let a_270 = 270 + let a_271 = 271 + let a_272 = 272 + let a_273 = 273 + let a_274 = 274 + let a_275 = 275 + let a_276 = 276 + let a_277 = 277 + let a_278 = 278 + let a_279 = 279 + let a_280 = 280 + let a_281 = 281 + let a_282 = 282 + let a_283 = 283 + let a_284 = 284 + let a_285 = 285 + let a_286 = 286 + let a_287 = 287 + let a_288 = 288 + let a_289 = 289 + let a_290 = 290 + let a_291 = 291 + let a_292 = 292 + let a_293 = 293 + let a_294 = 294 + let a_295 = 295 + let a_296 = 296 + let a_297 = 297 + let a_298 = 298 + let a_299 = 299 + let a_300 = 300 + let a_301 = 301 + let a_302 = 302 + let a_303 = 303 + let a_304 = 304 + let a_305 = 305 + let a_306 = 306 + let a_307 = 307 + let a_308 = 308 + let a_309 = 309 + let a_310 = 310 + let a_311 = 311 + let a_312 = 312 + let a_313 = 313 + let a_314 = 314 + let a_315 = 315 + let a_316 = 316 + let a_317 = 317 + let a_318 = 318 + let a_319 = 319 + let a_320 = 320 + let a_321 = 321 + let a_322 = 322 + let a_323 = 323 + let a_324 = 324 + let a_325 = 325 + let a_326 = 326 + let a_327 = 327 + let a_328 = 328 + let a_329 = 329 + let a_330 = 330 + let a_331 = 331 + let a_332 = 332 + let a_333 = 333 + let a_334 = 334 + let a_335 = 335 + let a_336 = 336 + let a_337 = 337 + let a_338 = 338 + let a_339 = 339 + let a_340 = 340 + let a_341 = 341 + let a_342 = 342 + let a_343 = 343 + let a_344 = 344 + let a_345 = 345 + let a_346 = 346 + let a_347 = 347 + let a_348 = 348 + let a_349 = 349 + let a_350 = 350 + let a_351 = 351 + let a_352 = 352 + let a_353 = 353 + let a_354 = 354 + let a_355 = 355 + let a_356 = 356 + let a_357 = 357 + let a_358 = 358 + let a_359 = 359 + let a_360 = 360 + let a_361 = 361 + let a_362 = 362 + let a_363 = 363 + let a_364 = 364 + let a_365 = 365 + let a_366 = 366 + let a_367 = 367 + let a_368 = 368 + let a_369 = 369 + let a_370 = 370 + let a_371 = 371 + let a_372 = 372 + let a_373 = 373 + let a_374 = 374 + let a_375 = 375 + let a_376 = 376 + let a_377 = 377 + let a_378 = 378 + let a_379 = 379 + let a_380 = 380 + let a_381 = 381 + let a_382 = 382 + let a_383 = 383 + let a_384 = 384 + let a_385 = 385 + let a_386 = 386 + let a_387 = 387 + let a_388 = 388 + let a_389 = 389 + let a_390 = 390 + let a_391 = 391 + let a_392 = 392 + let a_393 = 393 + let a_394 = 394 + let a_395 = 395 + let a_396 = 396 + let a_397 = 397 + let a_398 = 398 + let a_399 = 399 + let a_400 = 400 + let a_401 = 401 + let a_402 = 402 + let a_403 = 403 + let a_404 = 404 + let a_405 = 405 + let a_406 = 406 + let a_407 = 407 + let a_408 = 408 + let a_409 = 409 + let a_410 = 410 + let a_411 = 411 + let a_412 = 412 + let a_413 = 413 + let a_414 = 414 + let a_415 = 415 + let a_416 = 416 + let a_417 = 417 + let a_418 = 418 + let a_419 = 419 + let a_420 = 420 + let a_421 = 421 + let a_422 = 422 + let a_423 = 423 + let a_424 = 424 + let a_425 = 425 + let a_426 = 426 + let a_427 = 427 + let a_428 = 428 + let a_429 = 429 + let a_430 = 430 + let a_431 = 431 + let a_432 = 432 + let a_433 = 433 + let a_434 = 434 + let a_435 = 435 + let a_436 = 436 + let a_437 = 437 + let a_438 = 438 + let a_439 = 439 + let a_440 = 440 + let a_441 = 441 + let a_442 = 442 + let a_443 = 443 + let a_444 = 444 + let a_445 = 445 + let a_446 = 446 + let a_447 = 447 + let a_448 = 448 + let a_449 = 449 + let a_450 = 450 + let a_451 = 451 + let a_452 = 452 + let a_453 = 453 + let a_454 = 454 + let a_455 = 455 + let a_456 = 456 + let a_457 = 457 + let a_458 = 458 + let a_459 = 459 + let a_460 = 460 + let a_461 = 461 + let a_462 = 462 + let a_463 = 463 + let a_464 = 464 + let a_465 = 465 + let a_466 = 466 + let a_467 = 467 + let a_468 = 468 + let a_469 = 469 + let a_470 = 470 + let a_471 = 471 + let a_472 = 472 + let a_473 = 473 + let a_474 = 474 + let a_475 = 475 + let a_476 = 476 + let a_477 = 477 + let a_478 = 478 + let a_479 = 479 + let a_480 = 480 + let a_481 = 481 + let a_482 = 482 + let a_483 = 483 + let a_484 = 484 + let a_485 = 485 + let a_486 = 486 + let a_487 = 487 + let a_488 = 488 + let a_489 = 489 + let a_490 = 490 + let a_491 = 491 + let a_492 = 492 + let a_493 = 493 + let a_494 = 494 + let a_495 = 495 + let a_496 = 496 + let a_497 = 497 + let a_498 = 498 + let a_499 = 499 + def inner(): + let s = 0 + let inner_red_herring0 = 0 + let inner_red_herring1 = 1 + let inner_red_herring2 = 2 + let inner_red_herring3 = 3 + let inner_red_herring4 = 4 + let inner_red_herring5 = 5 + let inner_red_herring6 = 6 + let inner_red_herring7 = 7 + let inner_red_herring8 = 8 + let inner_red_herring9 = 9 + let inner_red_herring10 = 10 + let inner_red_herring11 = 11 + let inner_red_herring12 = 12 + let inner_red_herring13 = 13 + let inner_red_herring14 = 14 + let inner_red_herring15 = 15 + let inner_red_herring16 = 16 + let inner_red_herring17 = 17 + let inner_red_herring18 = 18 + let inner_red_herring19 = 19 + s += a_0 + s += a_1 + s += a_2 + s += a_3 + s += a_4 + s += a_5 + s += a_6 + s += a_7 + s += a_8 + s += a_9 + s += a_10 + s += a_11 + s += a_12 + s += a_13 + s += a_14 + s += a_15 + s += a_16 + s += a_17 + s += a_18 + s += a_19 + s += a_20 + s += a_21 + s += a_22 + s += a_23 + s += a_24 + s += a_25 + s += a_26 + s += a_27 + s += a_28 + s += a_29 + s += a_30 + s += a_31 + s += a_32 + s += a_33 + s += a_34 + s += a_35 + s += a_36 + s += a_37 + s += a_38 + s += a_39 + s += a_40 + s += a_41 + s += a_42 + s += a_43 + s += a_44 + s += a_45 + s += a_46 + s += a_47 + s += a_48 + s += a_49 + s += a_50 + s += a_51 + s += a_52 + s += a_53 + s += a_54 + s += a_55 + s += a_56 + s += a_57 + s += a_58 + s += a_59 + s += a_60 + s += a_61 + s += a_62 + s += a_63 + s += a_64 + s += a_65 + s += a_66 + s += a_67 + s += a_68 + s += a_69 + s += a_70 + s += a_71 + s += a_72 + s += a_73 + s += a_74 + s += a_75 + s += a_76 + s += a_77 + s += a_78 + s += a_79 + s += a_80 + s += a_81 + s += a_82 + s += a_83 + s += a_84 + s += a_85 + s += a_86 + s += a_87 + s += a_88 + s += a_89 + s += a_90 + s += a_91 + s += a_92 + s += a_93 + s += a_94 + s += a_95 + s += a_96 + s += a_97 + s += a_98 + s += a_99 + s += a_100 + s += a_101 + s += a_102 + s += a_103 + s += a_104 + s += a_105 + s += a_106 + s += a_107 + s += a_108 + s += a_109 + s += a_110 + s += a_111 + s += a_112 + s += a_113 + s += a_114 + s += a_115 + s += a_116 + s += a_117 + s += a_118 + s += a_119 + s += a_120 + s += a_121 + s += a_122 + s += a_123 + s += a_124 + s += a_125 + s += a_126 + s += a_127 + s += a_128 + s += a_129 + s += a_130 + s += a_131 + s += a_132 + s += a_133 + s += a_134 + s += a_135 + s += a_136 + s += a_137 + s += a_138 + s += a_139 + s += a_140 + s += a_141 + s += a_142 + s += a_143 + s += a_144 + s += a_145 + s += a_146 + s += a_147 + s += a_148 + s += a_149 + s += a_150 + s += a_151 + s += a_152 + s += a_153 + s += a_154 + s += a_155 + s += a_156 + s += a_157 + s += a_158 + s += a_159 + s += a_160 + s += a_161 + s += a_162 + s += a_163 + s += a_164 + s += a_165 + s += a_166 + s += a_167 + s += a_168 + s += a_169 + s += a_170 + s += a_171 + s += a_172 + s += a_173 + s += a_174 + s += a_175 + s += a_176 + s += a_177 + s += a_178 + s += a_179 + s += a_180 + s += a_181 + s += a_182 + s += a_183 + s += a_184 + s += a_185 + s += a_186 + s += a_187 + s += a_188 + s += a_189 + s += a_190 + s += a_191 + s += a_192 + s += a_193 + s += a_194 + s += a_195 + s += a_196 + s += a_197 + s += a_198 + s += a_199 + s += a_200 + s += a_201 + s += a_202 + s += a_203 + s += a_204 + s += a_205 + s += a_206 + s += a_207 + s += a_208 + s += a_209 + s += a_210 + s += a_211 + s += a_212 + s += a_213 + s += a_214 + s += a_215 + s += a_216 + s += a_217 + s += a_218 + s += a_219 + s += a_220 + s += a_221 + s += a_222 + s += a_223 + s += a_224 + s += a_225 + s += a_226 + s += a_227 + s += a_228 + s += a_229 + s += a_230 + s += a_231 + s += a_232 + s += a_233 + s += a_234 + s += a_235 + s += a_236 + s += a_237 + s += a_238 + s += a_239 + s += a_240 + s += a_241 + s += a_242 + s += a_243 + s += a_244 + s += a_245 + s += a_246 + s += a_247 + s += a_248 + s += a_249 + s += a_250 + s += a_251 + s += a_252 + s += a_253 + s += a_254 + s += a_255 + s += a_256 + s += a_257 + s += a_258 + s += a_259 + s += a_260 + s += a_261 + s += a_262 + s += a_263 + s += a_264 + s += a_265 + s += a_266 + s += a_267 + s += a_268 + s += a_269 + s += a_270 + s += a_271 + s += a_272 + s += a_273 + s += a_274 + s += a_275 + s += a_276 + s += a_277 + s += a_278 + s += a_279 + s += a_280 + s += a_281 + s += a_282 + s += a_283 + s += a_284 + s += a_285 + s += a_286 + s += a_287 + s += a_288 + s += a_289 + s += a_290 + s += a_291 + s += a_292 + s += a_293 + s += a_294 + s += a_295 + s += a_296 + s += a_297 + s += a_298 + s += a_299 + s += a_300 + s += a_301 + s += a_302 + s += a_303 + s += a_304 + s += a_305 + s += a_306 + s += a_307 + s += a_308 + s += a_309 + s += a_310 + s += a_311 + s += a_312 + s += a_313 + s += a_314 + s += a_315 + s += a_316 + s += a_317 + s += a_318 + s += a_319 + s += a_320 + s += a_321 + s += a_322 + s += a_323 + s += a_324 + s += a_325 + s += a_326 + s += a_327 + s += a_328 + s += a_329 + s += a_330 + s += a_331 + s += a_332 + s += a_333 + s += a_334 + s += a_335 + s += a_336 + s += a_337 + s += a_338 + s += a_339 + s += a_340 + s += a_341 + s += a_342 + s += a_343 + s += a_344 + s += a_345 + s += a_346 + s += a_347 + s += a_348 + s += a_349 + s += a_350 + s += a_351 + s += a_352 + s += a_353 + s += a_354 + s += a_355 + s += a_356 + s += a_357 + s += a_358 + s += a_359 + s += a_360 + s += a_361 + s += a_362 + s += a_363 + s += a_364 + s += a_365 + s += a_366 + s += a_367 + s += a_368 + s += a_369 + s += a_370 + s += a_371 + s += a_372 + s += a_373 + s += a_374 + s += a_375 + s += a_376 + s += a_377 + s += a_378 + s += a_379 + s += a_380 + s += a_381 + s += a_382 + s += a_383 + s += a_384 + s += a_385 + s += a_386 + s += a_387 + s += a_388 + s += a_389 + s += a_390 + s += a_391 + s += a_392 + s += a_393 + s += a_394 + s += a_395 + s += a_396 + s += a_397 + s += a_398 + s += a_399 + s += a_400 + s += a_401 + s += a_402 + s += a_403 + s += a_404 + s += a_405 + s += a_406 + s += a_407 + s += a_408 + s += a_409 + s += a_410 + s += a_411 + s += a_412 + s += a_413 + s += a_414 + s += a_415 + s += a_416 + s += a_417 + s += a_418 + s += a_419 + s += a_420 + s += a_421 + s += a_422 + s += a_423 + s += a_424 + s += a_425 + s += a_426 + s += a_427 + s += a_428 + s += a_429 + s += a_430 + s += a_431 + s += a_432 + s += a_433 + s += a_434 + s += a_435 + s += a_436 + s += a_437 + s += a_438 + s += a_439 + s += a_440 + s += a_441 + s += a_442 + s += a_443 + s += a_444 + s += a_445 + s += a_446 + s += a_447 + s += a_448 + s += a_449 + s += a_450 + s += a_451 + s += a_452 + s += a_453 + s += a_454 + s += a_455 + s += a_456 + s += a_457 + s += a_458 + s += a_459 + s += a_460 + s += a_461 + s += a_462 + s += a_463 + s += a_464 + s += a_465 + s += a_466 + s += a_467 + s += a_468 + s += a_469 + s += a_470 + s += a_471 + s += a_472 + s += a_473 + s += a_474 + s += a_475 + s += a_476 + s += a_477 + s += a_478 + s += a_479 + s += a_480 + s += a_481 + s += a_482 + s += a_483 + s += a_484 + s += a_485 + s += a_486 + s += a_487 + s += a_488 + s += a_489 + s += a_490 + s += a_491 + s += a_492 + s += a_493 + s += a_494 + s += a_495 + s += a_496 + s += a_497 + s += a_498 + s += a_499 + return s + print(inner()) diff --git a/test/testLotsOfUpvalues.krk.expect b/test/testLotsOfUpvalues.krk.expect new file mode 100644 index 0000000..0e24920 --- /dev/null +++ b/test/testLotsOfUpvalues.krk.expect @@ -0,0 +1 @@ +124750 diff --git a/tools/make_test_upvalues.krk b/tools/make_test_upvalues.krk new file mode 100644 index 0000000..f3e4a27 --- /dev/null +++ b/tools/make_test_upvalues.krk @@ -0,0 +1,17 @@ +import fileio + +if __name__ == '__main__': + with fileio.open('test/testLotsOfUpvalues.krk','w') as f: + f.write('if True:\n') + for i in range(20): + f.write(f' let red_herring_{i} = {i}\n') + for i in range(500): + f.write(f' let a_{i} = {i}\n') + f.write(' def inner():\n') + f.write(' let s = 0\n') + for i in range(20): + f.write(f' let inner_red_herring{i} = {i}\n') + for i in range(500): + f.write(f' s += a_{i}\n') + f.write(' return s\n') + f.write(' print(inner())\n')