summaryrefslogtreecommitdiff
path: root/lcode.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2002-05-13 10:07:48 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2002-05-13 10:07:48 -0300
commitb55fded18c270412e127259a5f28c785620dbf1a (patch)
treef113a11efa905c272d679e93e66ce0cbc1587fb0 /lcode.c
parent2dadc8182282afa4b1fe6e6287704a54cd8e5123 (diff)
downloadlua-b55fded18c270412e127259a5f28c785620dbf1a.tar.gz
lua-b55fded18c270412e127259a5f28c785620dbf1a.tar.bz2
lua-b55fded18c270412e127259a5f28c785620dbf1a.zip
details about jump optimization
Diffstat (limited to 'lcode.c')
-rw-r--r--lcode.c35
1 files changed, 22 insertions, 13 deletions
diff --git a/lcode.c b/lcode.c
index 26a90430..f057da2b 100644
--- a/lcode.c
+++ b/lcode.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lcode.c,v 1.101 2002/05/10 17:02:32 roberto Exp roberto $ 2** $Id: lcode.c,v 1.102 2002/05/10 19:22:11 roberto Exp roberto $
3** Code generator for Lua 3** Code generator for Lua
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -75,12 +75,6 @@ int luaK_getlabel (FuncState *fs) {
75} 75}
76 76
77 77
78void luaK_dischargejpc (FuncState *fs) {
79 luaK_patchlist(fs, fs->jpc, fs->pc); /* discharge old list `jpc' */
80 fs->jpc = NO_JUMP;
81}
82
83
84static int luaK_getjump (FuncState *fs, int pc) { 78static int luaK_getjump (FuncState *fs, int pc) {
85 int offset = GETARG_sBx(fs->f->code[pc]); 79 int offset = GETARG_sBx(fs->f->code[pc]);
86 if (offset == NO_JUMP) /* point to itself represents end of list */ 80 if (offset == NO_JUMP) /* point to itself represents end of list */
@@ -144,9 +138,19 @@ static void luaK_patchlistaux (FuncState *fs, int list,
144} 138}
145 139
146 140
141void luaK_dischargejpc (FuncState *fs) {
142 luaK_patchlistaux(fs, fs->jpc, fs->pc, NO_REG, fs->pc, NO_REG, fs->pc);
143 fs->jpc = NO_JUMP;
144}
145
146
147void luaK_patchlist (FuncState *fs, int list, int target) { 147void luaK_patchlist (FuncState *fs, int list, int target) {
148 lua_assert(target <= fs->pc); 148 if (target == fs->pc)
149 luaK_patchlistaux(fs, list, target, NO_REG, target, NO_REG, target); 149 luaK_patchtohere(fs, list);
150 else {
151 lua_assert(target < fs->pc);
152 luaK_patchlistaux(fs, list, target, NO_REG, target, NO_REG, target);
153 }
150} 154}
151 155
152 156
@@ -342,12 +346,12 @@ static void luaK_exp2reg (FuncState *fs, expdesc *e, int reg) {
342 int p_f = NO_JUMP; /* position of an eventual LOAD false */ 346 int p_f = NO_JUMP; /* position of an eventual LOAD false */
343 int p_t = NO_JUMP; /* position of an eventual LOAD true */ 347 int p_t = NO_JUMP; /* position of an eventual LOAD true */
344 if (need_value(fs, e->t, 1) || need_value(fs, e->f, 0)) { 348 if (need_value(fs, e->t, 1) || need_value(fs, e->f, 0)) {
345 if (e->k != VJMP) { 349 int fj = NO_JUMP; /* first jump (over LOAD ops.) */
346 luaK_getlabel(fs); /* this instruction may be a jump target */ 350 if (e->k != VJMP)
347 luaK_codeAsBx(fs, OP_JMP, 0, 2); /* to jump over both pushes */ 351 fj = luaK_jump(fs);
348 }
349 p_f = code_label(fs, reg, 0, 1); 352 p_f = code_label(fs, reg, 0, 1);
350 p_t = code_label(fs, reg, 1, 0); 353 p_t = code_label(fs, reg, 1, 0);
354 luaK_patchtohere(fs, fj);
351 } 355 }
352 final = luaK_getlabel(fs); 356 final = luaK_getlabel(fs);
353 luaK_patchlistaux(fs, e->f, p_f, NO_REG, final, reg, p_f); 357 luaK_patchlistaux(fs, e->f, p_f, NO_REG, final, reg, p_f);
@@ -724,6 +728,11 @@ void luaK_posfix (FuncState *fs, BinOpr op, expdesc *e1, expdesc *e2) {
724} 728}
725 729
726 730
731void luaK_fixline (FuncState *fs, int line) {
732 fs->f->lineinfo[fs->pc - 1] = line;
733}
734
735
727int luaK_code (FuncState *fs, Instruction i, int line) { 736int luaK_code (FuncState *fs, Instruction i, int line) {
728 Proto *f = fs->f; 737 Proto *f = fs->f;
729 int oldsize = f->sizecode; 738 int oldsize = f->sizecode;