Skip to content

Commit

Permalink
More about how logical exp and JMP are handled. Function and UpVal.
Browse files Browse the repository at this point in the history
  • Loading branch information
middlefeng committed Jan 21, 2015
1 parent e832ad2 commit d1a2c3e
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 1 deletion.
3 changes: 2 additions & 1 deletion CodeConvention.txt
Expand Up @@ -16,4 +16,5 @@ LuaS String-related API
LuaT Meta-table-related API

LuaL Util
luaG Debug
LuaG Debug
LuaM Memory
10 changes: 10 additions & 0 deletions lcode.c
Expand Up @@ -211,6 +211,16 @@ patchlistaux(fs, fs->jpc, fs->pc, NO_REG, fs->pc)



static int code_label (FuncState *fs, int A, int b, int jump)
==========================================================================
Emit the last two instructions for a logical expression, one for the case the yielded
value is TRUE, the other for FALSE.

All sub-expressions in the same logical expression, which yield non-bollean values,
jumps to the instruction following the last instruction generated by this function.
The location of that instruction (the one following the last) is called "vtarget".



static void patchlistaux (FuncState *fs, int list, int vtarget, int reg, int dtarget)
==========================================================================
Expand Down
6 changes: 6 additions & 0 deletions lfunc.c
Expand Up @@ -7,3 +7,9 @@ Close all open upvals when a block is out of execution flow.
- Upvals belonging to the about-to-exit block has the "v" field higher than "level".
- "level" is the base of a function call, or the nactvar of a block.
("nactvar" is the number of active locals outside a block.)

This function is invoked in two places:
- Returning from a function. (OP_RETURN)
- Exit a block in which some local variables are used as UpVals. Whether there being any
variables in a block are used UpVals is determined by BlockCnt::upval and BlockCnt::prev. (OP_JMP)
BockCnt::prev is used to determine if it is the topmost level in a chunck (i.e. loaded source code).
1 change: 1 addition & 0 deletions lparser.c
Expand Up @@ -285,6 +285,7 @@ VFALSE |
VK |
VKFLT |
VKINT |
VJMP: The expression is a comparison expression (i.e. EQ, LT, LE, NE, GE, GT).
VRELOCABLE: The target register (usually R(A)) is not yet determined (set as 0).
The instruction is already put into Proto.
e->u.info stores the location of the instruction.
Expand Down

0 comments on commit d1a2c3e

Please sign in to comment.