From d1a2c3e0c104d24084906d0ffc4bbd714a154d75 Mon Sep 17 00:00:00 2001 From: Dong Feng Date: Wed, 21 Jan 2015 00:00:13 -0800 Subject: [PATCH] More about how logical exp and JMP are handled. Function and UpVal. --- CodeConvention.txt | 3 ++- lcode.c | 10 ++++++++++ lfunc.c | 6 ++++++ lparser.c | 1 + 4 files changed, 19 insertions(+), 1 deletion(-) diff --git a/CodeConvention.txt b/CodeConvention.txt index 6b8ff57..621d8b3 100644 --- a/CodeConvention.txt +++ b/CodeConvention.txt @@ -16,4 +16,5 @@ LuaS String-related API LuaT Meta-table-related API LuaL Util -luaG Debug +LuaG Debug +LuaM Memory diff --git a/lcode.c b/lcode.c index 9f3a067..a1a926c 100644 --- a/lcode.c +++ b/lcode.c @@ -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) ========================================================================== diff --git a/lfunc.c b/lfunc.c index 0088c6b..1838fa7 100644 --- a/lfunc.c +++ b/lfunc.c @@ -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). diff --git a/lparser.c b/lparser.c index 29065c8..1e1b775 100644 --- a/lparser.c +++ b/lparser.c @@ -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.