diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2018-10-29 14:26:48 -0300 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2018-10-29 14:26:48 -0300 |
| commit | a006514ea138a29b6031058d9002b48a572b5dd6 (patch) | |
| tree | b289a8af0c0497f2555784a0cf666659ceab0236 /lcode.c | |
| parent | 6e9b719694bffb8de711f182d405ec37d32ae0b1 (diff) | |
| download | lua-a006514ea138a29b6031058d9002b48a572b5dd6.tar.gz lua-a006514ea138a29b6031058d9002b48a572b5dd6.tar.bz2 lua-a006514ea138a29b6031058d9002b48a572b5dd6.zip | |
Big revamp in the implmentation of labels/gotos
Added restriction that, when a label is created, there cannot be
another label with the same name visible. That allows backward goto's
to be resolved when they are read. Backward goto's get a close if
they jump out of the scope of some variable; labels get a close only
if previous goto to it jumps out of the scope of some upvalue.
Diffstat (limited to 'lcode.c')
| -rw-r--r-- | lcode.c | 34 |
1 files changed, 0 insertions, 34 deletions
| @@ -276,40 +276,6 @@ void luaK_patchtohere (FuncState *fs, int list) { | |||
| 276 | 276 | ||
| 277 | 277 | ||
| 278 | /* | 278 | /* |
| 279 | ** Correct a jump list to jump to 'target'. If 'hasclose' is true, | ||
| 280 | ** 'target' contains an OP_CLOSE instruction (see first assert). | ||
| 281 | ** Only the jumps with ('m' == true) need that close; other jumps | ||
| 282 | ** avoid it jumping to the next instruction. | ||
| 283 | */ | ||
| 284 | void luaK_patchgoto (FuncState *fs, int list, int target, int hasclose) { | ||
| 285 | lua_assert(!hasclose || GET_OPCODE(fs->f->code[target]) == OP_CLOSE); | ||
| 286 | while (list != NO_JUMP) { | ||
| 287 | int next = getjump(fs, list); | ||
| 288 | lua_assert(!GETARG_m(fs->f->code[list]) || hasclose); | ||
| 289 | patchtestreg(fs, list, NO_REG); /* do not generate values */ | ||
| 290 | if (!hasclose || GETARG_m(fs->f->code[list])) | ||
| 291 | fixjump(fs, list, target); | ||
| 292 | else /* there is a CLOSE instruction but jump does not need it */ | ||
| 293 | fixjump(fs, list, target + 1); /* avoid CLOSE instruction */ | ||
| 294 | list = next; | ||
| 295 | } | ||
| 296 | } | ||
| 297 | |||
| 298 | |||
| 299 | /* | ||
| 300 | ** Mark (using the 'm' arg) all jumps in 'list' to close upvalues. Mark | ||
| 301 | ** will instruct 'luaK_patchgoto' to make these jumps go to OP_CLOSE | ||
| 302 | ** instructions. | ||
| 303 | */ | ||
| 304 | void luaK_patchclose (FuncState *fs, int list) { | ||
| 305 | for (; list != NO_JUMP; list = getjump(fs, list)) { | ||
| 306 | lua_assert(GET_OPCODE(fs->f->code[list]) == OP_JMP); | ||
| 307 | SETARG_m(fs->f->code[list], 1); | ||
| 308 | } | ||
| 309 | } | ||
| 310 | |||
| 311 | |||
| 312 | /* | ||
| 313 | ** MAXimum number of successive Instructions WiTHout ABSolute line | 279 | ** MAXimum number of successive Instructions WiTHout ABSolute line |
| 314 | ** information. | 280 | ** information. |
| 315 | */ | 281 | */ |
