diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2004-12-03 18:50:25 -0200 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2004-12-03 18:50:25 -0200 |
commit | c78940f21a956064ac79f715af072e283538f35c (patch) | |
tree | 5a879991ef8d68bbfd437f35ab1da8b761bf9f14 /lcode.c | |
parent | 8b239eeba13877955b976ccd119ada038b67fa59 (diff) | |
download | lua-c78940f21a956064ac79f715af072e283538f35c.tar.gz lua-c78940f21a956064ac79f715af072e283538f35c.tar.bz2 lua-c78940f21a956064ac79f715af072e283538f35c.zip |
static names do not need `luaX_' prefix
Diffstat (limited to 'lcode.c')
-rw-r--r-- | lcode.c | 50 |
1 files changed, 25 insertions, 25 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lcode.c,v 2.6 2004/08/24 20:09:11 roberto Exp $ | 2 | ** $Id: lcode.c,v 2.7 2004/10/04 19:01:53 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 | */ |
@@ -53,13 +53,13 @@ int luaK_jump (FuncState *fs) { | |||
53 | } | 53 | } |
54 | 54 | ||
55 | 55 | ||
56 | static int luaK_condjump (FuncState *fs, OpCode op, int A, int B, int C) { | 56 | static int condjump (FuncState *fs, OpCode op, int A, int B, int C) { |
57 | luaK_codeABC(fs, op, A, B, C); | 57 | luaK_codeABC(fs, op, A, B, C); |
58 | return luaK_jump(fs); | 58 | return luaK_jump(fs); |
59 | } | 59 | } |
60 | 60 | ||
61 | 61 | ||
62 | static void luaK_fixjump (FuncState *fs, int pc, int dest) { | 62 | static void fixjump (FuncState *fs, int pc, int dest) { |
63 | Instruction *jmp = &fs->f->code[pc]; | 63 | Instruction *jmp = &fs->f->code[pc]; |
64 | int offset = dest-(pc+1); | 64 | int offset = dest-(pc+1); |
65 | lua_assert(dest != NO_JUMP); | 65 | lua_assert(dest != NO_JUMP); |
@@ -79,7 +79,7 @@ int luaK_getlabel (FuncState *fs) { | |||
79 | } | 79 | } |
80 | 80 | ||
81 | 81 | ||
82 | static int luaK_getjump (FuncState *fs, int pc) { | 82 | static int getjump (FuncState *fs, int pc) { |
83 | int offset = GETARG_sBx(fs->f->code[pc]); | 83 | int offset = GETARG_sBx(fs->f->code[pc]); |
84 | if (offset == NO_JUMP) /* point to itself represents end of list */ | 84 | if (offset == NO_JUMP) /* point to itself represents end of list */ |
85 | return NO_JUMP; /* end of list */ | 85 | return NO_JUMP; /* end of list */ |
@@ -102,7 +102,7 @@ static Instruction *getjumpcontrol (FuncState *fs, int pc) { | |||
102 | ** (or produce an inverted value) | 102 | ** (or produce an inverted value) |
103 | */ | 103 | */ |
104 | static int need_value (FuncState *fs, int list, int cond) { | 104 | static int need_value (FuncState *fs, int list, int cond) { |
105 | for (; list != NO_JUMP; list = luaK_getjump(fs, list)) { | 105 | for (; list != NO_JUMP; list = getjump(fs, list)) { |
106 | Instruction i = *getjumpcontrol(fs, list); | 106 | Instruction i = *getjumpcontrol(fs, list); |
107 | if (GET_OPCODE(i) != OP_TEST || GETARG_C(i) != cond) return 1; | 107 | if (GET_OPCODE(i) != OP_TEST || GETARG_C(i) != cond) return 1; |
108 | } | 108 | } |
@@ -116,25 +116,25 @@ static void patchtestreg (Instruction *i, int reg) { | |||
116 | } | 116 | } |
117 | 117 | ||
118 | 118 | ||
119 | static void luaK_patchlistaux (FuncState *fs, int list, | 119 | static void patchlistaux (FuncState *fs, int list, |
120 | int ttarget, int treg, int ftarget, int freg, int dtarget) { | 120 | int ttarget, int treg, int ftarget, int freg, int dtarget) { |
121 | while (list != NO_JUMP) { | 121 | while (list != NO_JUMP) { |
122 | int next = luaK_getjump(fs, list); | 122 | int next = getjump(fs, list); |
123 | Instruction *i = getjumpcontrol(fs, list); | 123 | Instruction *i = getjumpcontrol(fs, list); |
124 | if (GET_OPCODE(*i) != OP_TEST) { | 124 | if (GET_OPCODE(*i) != OP_TEST) { |
125 | lua_assert(dtarget != NO_JUMP); | 125 | lua_assert(dtarget != NO_JUMP); |
126 | luaK_fixjump(fs, list, dtarget); /* jump to default target */ | 126 | fixjump(fs, list, dtarget); /* jump to default target */ |
127 | } | 127 | } |
128 | else { | 128 | else { |
129 | if (GETARG_C(*i)) { | 129 | if (GETARG_C(*i)) { |
130 | lua_assert(ttarget != NO_JUMP); | 130 | lua_assert(ttarget != NO_JUMP); |
131 | patchtestreg(i, treg); | 131 | patchtestreg(i, treg); |
132 | luaK_fixjump(fs, list, ttarget); | 132 | fixjump(fs, list, ttarget); |
133 | } | 133 | } |
134 | else { | 134 | else { |
135 | lua_assert(ftarget != NO_JUMP); | 135 | lua_assert(ftarget != NO_JUMP); |
136 | patchtestreg(i, freg); | 136 | patchtestreg(i, freg); |
137 | luaK_fixjump(fs, list, ftarget); | 137 | fixjump(fs, list, ftarget); |
138 | } | 138 | } |
139 | } | 139 | } |
140 | list = next; | 140 | list = next; |
@@ -142,8 +142,8 @@ static void luaK_patchlistaux (FuncState *fs, int list, | |||
142 | } | 142 | } |
143 | 143 | ||
144 | 144 | ||
145 | static void luaK_dischargejpc (FuncState *fs) { | 145 | static void dischargejpc (FuncState *fs) { |
146 | luaK_patchlistaux(fs, fs->jpc, fs->pc, NO_REG, fs->pc, NO_REG, fs->pc); | 146 | patchlistaux(fs, fs->jpc, fs->pc, NO_REG, fs->pc, NO_REG, fs->pc); |
147 | fs->jpc = NO_JUMP; | 147 | fs->jpc = NO_JUMP; |
148 | } | 148 | } |
149 | 149 | ||
@@ -153,7 +153,7 @@ void luaK_patchlist (FuncState *fs, int list, int target) { | |||
153 | luaK_patchtohere(fs, list); | 153 | luaK_patchtohere(fs, list); |
154 | else { | 154 | else { |
155 | lua_assert(target < fs->pc); | 155 | lua_assert(target < fs->pc); |
156 | luaK_patchlistaux(fs, list, target, NO_REG, target, NO_REG, target); | 156 | patchlistaux(fs, list, target, NO_REG, target, NO_REG, target); |
157 | } | 157 | } |
158 | } | 158 | } |
159 | 159 | ||
@@ -171,9 +171,9 @@ void luaK_concat (FuncState *fs, int *l1, int l2) { | |||
171 | else { | 171 | else { |
172 | int list = *l1; | 172 | int list = *l1; |
173 | int next; | 173 | int next; |
174 | while ((next = luaK_getjump(fs, list)) != NO_JUMP) /* find last element */ | 174 | while ((next = getjump(fs, list)) != NO_JUMP) /* find last element */ |
175 | list = next; | 175 | list = next; |
176 | luaK_fixjump(fs, list, l2); | 176 | fixjump(fs, list, l2); |
177 | } | 177 | } |
178 | } | 178 | } |
179 | 179 | ||
@@ -365,7 +365,7 @@ static void discharge2anyreg (FuncState *fs, expdesc *e) { | |||
365 | } | 365 | } |
366 | 366 | ||
367 | 367 | ||
368 | static void luaK_exp2reg (FuncState *fs, expdesc *e, int reg) { | 368 | static void exp2reg (FuncState *fs, expdesc *e, int reg) { |
369 | discharge2reg(fs, e, reg); | 369 | discharge2reg(fs, e, reg); |
370 | if (e->k == VJMP) | 370 | if (e->k == VJMP) |
371 | luaK_concat(fs, &e->t, e->info); /* put this jump in `t' list */ | 371 | luaK_concat(fs, &e->t, e->info); /* put this jump in `t' list */ |
@@ -382,8 +382,8 @@ static void luaK_exp2reg (FuncState *fs, expdesc *e, int reg) { | |||
382 | luaK_patchtohere(fs, fj); | 382 | luaK_patchtohere(fs, fj); |
383 | } | 383 | } |
384 | final = luaK_getlabel(fs); | 384 | final = luaK_getlabel(fs); |
385 | luaK_patchlistaux(fs, e->f, p_f, NO_REG, final, reg, p_f); | 385 | patchlistaux(fs, e->f, p_f, NO_REG, final, reg, p_f); |
386 | luaK_patchlistaux(fs, e->t, final, reg, p_t, NO_REG, p_t); | 386 | patchlistaux(fs, e->t, final, reg, p_t, NO_REG, p_t); |
387 | } | 387 | } |
388 | e->f = e->t = NO_JUMP; | 388 | e->f = e->t = NO_JUMP; |
389 | e->info = reg; | 389 | e->info = reg; |
@@ -395,7 +395,7 @@ void luaK_exp2nextreg (FuncState *fs, expdesc *e) { | |||
395 | luaK_dischargevars(fs, e); | 395 | luaK_dischargevars(fs, e); |
396 | freeexp(fs, e); | 396 | freeexp(fs, e); |
397 | luaK_reserveregs(fs, 1); | 397 | luaK_reserveregs(fs, 1); |
398 | luaK_exp2reg(fs, e, fs->freereg - 1); | 398 | exp2reg(fs, e, fs->freereg - 1); |
399 | } | 399 | } |
400 | 400 | ||
401 | 401 | ||
@@ -404,7 +404,7 @@ int luaK_exp2anyreg (FuncState *fs, expdesc *e) { | |||
404 | if (e->k == VNONRELOC) { | 404 | if (e->k == VNONRELOC) { |
405 | if (!hasjumps(e)) return e->info; /* exp is already in a register */ | 405 | if (!hasjumps(e)) return e->info; /* exp is already in a register */ |
406 | if (e->info >= fs->nactvar) { /* reg. is not a local? */ | 406 | if (e->info >= fs->nactvar) { /* reg. is not a local? */ |
407 | luaK_exp2reg(fs, e, e->info); /* put value on it */ | 407 | exp2reg(fs, e, e->info); /* put value on it */ |
408 | return e->info; | 408 | return e->info; |
409 | } | 409 | } |
410 | } | 410 | } |
@@ -450,7 +450,7 @@ void luaK_storevar (FuncState *fs, expdesc *var, expdesc *ex) { | |||
450 | switch (var->k) { | 450 | switch (var->k) { |
451 | case VLOCAL: { | 451 | case VLOCAL: { |
452 | freeexp(fs, ex); | 452 | freeexp(fs, ex); |
453 | luaK_exp2reg(fs, ex, var->info); | 453 | exp2reg(fs, ex, var->info); |
454 | return; | 454 | return; |
455 | } | 455 | } |
456 | case VUPVAL: { | 456 | case VUPVAL: { |
@@ -502,13 +502,13 @@ static int jumponcond (FuncState *fs, expdesc *e, int cond) { | |||
502 | Instruction ie = getcode(fs, e); | 502 | Instruction ie = getcode(fs, e); |
503 | if (GET_OPCODE(ie) == OP_NOT) { | 503 | if (GET_OPCODE(ie) == OP_NOT) { |
504 | fs->pc--; /* remove previous OP_NOT */ | 504 | fs->pc--; /* remove previous OP_NOT */ |
505 | return luaK_condjump(fs, OP_TEST, NO_REG, GETARG_B(ie), !cond); | 505 | return condjump(fs, OP_TEST, NO_REG, GETARG_B(ie), !cond); |
506 | } | 506 | } |
507 | /* else go through */ | 507 | /* else go through */ |
508 | } | 508 | } |
509 | discharge2anyreg(fs, e); | 509 | discharge2anyreg(fs, e); |
510 | freeexp(fs, e); | 510 | freeexp(fs, e); |
511 | return luaK_condjump(fs, OP_TEST, NO_REG, e->info, cond); | 511 | return condjump(fs, OP_TEST, NO_REG, e->info, cond); |
512 | } | 512 | } |
513 | 513 | ||
514 | 514 | ||
@@ -660,7 +660,7 @@ static void codebinop (FuncState *fs, expdesc *res, BinOpr op, | |||
660 | temp = o1; o1 = o2; o2 = temp; /* o1 <==> o2 */ | 660 | temp = o1; o1 = o2; o2 = temp; /* o1 <==> o2 */ |
661 | } | 661 | } |
662 | else if (op == OPR_NE) cond = 0; | 662 | else if (op == OPR_NE) cond = 0; |
663 | res->info = luaK_condjump(fs, ops[op - OPR_NE], cond, o1, o2); | 663 | res->info = condjump(fs, ops[op - OPR_NE], cond, o1, o2); |
664 | res->k = VJMP; | 664 | res->k = VJMP; |
665 | } | 665 | } |
666 | } | 666 | } |
@@ -717,7 +717,7 @@ void luaK_fixline (FuncState *fs, int line) { | |||
717 | 717 | ||
718 | int luaK_code (FuncState *fs, Instruction i, int line) { | 718 | int luaK_code (FuncState *fs, Instruction i, int line) { |
719 | Proto *f = fs->f; | 719 | Proto *f = fs->f; |
720 | luaK_dischargejpc(fs); /* `pc' will change */ | 720 | dischargejpc(fs); /* `pc' will change */ |
721 | /* put new instruction in code array */ | 721 | /* put new instruction in code array */ |
722 | luaM_growvector(fs->L, f->code, fs->pc, f->sizecode, Instruction, | 722 | luaM_growvector(fs->L, f->code, fs->pc, f->sizecode, Instruction, |
723 | MAX_INT, "code size overflow"); | 723 | MAX_INT, "code size overflow"); |