CHDK_DE Vorschauversion  Trunk Rev. 6014
 Alle Datenstrukturen Dateien Funktionen Variablen Typdefinitionen Aufzählungen Aufzählungswerte Makrodefinitionen
lcode.h-Dateireferenz
#include "llex.h"
#include "lobject.h"
#include "lopcodes.h"
#include "lparser.h"
+ Include-Abhängigkeitsdiagramm für lcode.h:
+ Dieser Graph zeigt, welche Datei direkt oder indirekt diese Datei enthält:

gehe zum Quellcode dieser Datei

Makrodefinitionen

#define NO_JUMP   (-1)
 
#define getcode(fs, e)   ((fs)->f->code[(e)->u.s.info])
 
#define luaK_codeAsBx(fs, o, A, sBx)   luaK_codeABx(fs,o,A,(sBx)+MAXARG_sBx)
 
#define luaK_setmultret(fs, e)   luaK_setreturns(fs, e, LUA_MULTRET)
 

Typdefinitionen

typedef enum BinOpr BinOpr
 
typedef enum UnOpr UnOpr
 

Aufzählungen

enum  BinOpr {
  OPR_ADD, OPR_SUB, OPR_MUL, OPR_DIV,
  OPR_MOD, OPR_POW, OPR_CONCAT, OPR_NE,
  OPR_EQ, OPR_LT, OPR_LE, OPR_GT,
  OPR_GE, OPR_AND, OPR_OR, OPR_NOBINOPR
}
 
enum  UnOpr { OPR_MINUS, OPR_NOT, OPR_LEN, OPR_NOUNOPR }
 

Funktionen

LUAI_FUNC int luaK_codeABx (FuncState *fs, OpCode o, int A, unsigned int Bx)
 
LUAI_FUNC int luaK_codeABC (FuncState *fs, OpCode o, int A, int B, int C)
 
LUAI_FUNC void luaK_fixline (FuncState *fs, int line)
 
LUAI_FUNC void luaK_nil (FuncState *fs, int from, int n)
 
LUAI_FUNC void luaK_reserveregs (FuncState *fs, int n)
 
LUAI_FUNC void luaK_checkstack (FuncState *fs, int n)
 
LUAI_FUNC int luaK_stringK (FuncState *fs, TString *s)
 
LUAI_FUNC int luaK_numberK (FuncState *fs, lua_Number r)
 
LUAI_FUNC void luaK_dischargevars (FuncState *fs, expdesc *e)
 
LUAI_FUNC int luaK_exp2anyreg (FuncState *fs, expdesc *e)
 
LUAI_FUNC void luaK_exp2nextreg (FuncState *fs, expdesc *e)
 
LUAI_FUNC void luaK_exp2val (FuncState *fs, expdesc *e)
 
LUAI_FUNC int luaK_exp2RK (FuncState *fs, expdesc *e)
 
LUAI_FUNC void luaK_self (FuncState *fs, expdesc *e, expdesc *key)
 
LUAI_FUNC void luaK_indexed (FuncState *fs, expdesc *t, expdesc *k)
 
LUAI_FUNC void luaK_goiftrue (FuncState *fs, expdesc *e)
 
LUAI_FUNC void luaK_storevar (FuncState *fs, expdesc *var, expdesc *e)
 
LUAI_FUNC void luaK_setreturns (FuncState *fs, expdesc *e, int nresults)
 
LUAI_FUNC void luaK_setoneret (FuncState *fs, expdesc *e)
 
LUAI_FUNC int luaK_jump (FuncState *fs)
 
LUAI_FUNC void luaK_ret (FuncState *fs, int first, int nret)
 
LUAI_FUNC void luaK_patchlist (FuncState *fs, int list, int target)
 
LUAI_FUNC void luaK_patchtohere (FuncState *fs, int list)
 
LUAI_FUNC void luaK_concat (FuncState *fs, int *l1, int l2)
 
LUAI_FUNC int luaK_getlabel (FuncState *fs)
 
LUAI_FUNC void luaK_prefix (FuncState *fs, UnOpr op, expdesc *v)
 
LUAI_FUNC void luaK_infix (FuncState *fs, BinOpr op, expdesc *v)
 
LUAI_FUNC void luaK_posfix (FuncState *fs, BinOpr op, expdesc *v1, expdesc *v2)
 
LUAI_FUNC void luaK_setlist (FuncState *fs, int base, int nelems, int tostore)
 

Makro-Dokumentation

#define getcode (   fs,
 
)    ((fs)->f->code[(e)->u.s.info])

Definiert in Zeile 39 der Datei lcode.h.

#define luaK_codeAsBx (   fs,
  o,
  A,
  sBx 
)    luaK_codeABx(fs,o,A,(sBx)+MAXARG_sBx)

Definiert in Zeile 41 der Datei lcode.h.

#define luaK_setmultret (   fs,
 
)    luaK_setreturns(fs, e, LUA_MULTRET)

Definiert in Zeile 43 der Datei lcode.h.

#define NO_JUMP   (-1)

Definiert in Zeile 20 der Datei lcode.h.

Dokumentation der benutzerdefinierten Typen

typedef enum BinOpr BinOpr
typedef enum UnOpr UnOpr

Dokumentation der Aufzählungstypen

enum BinOpr
Aufzählungswerte
OPR_ADD 
OPR_SUB 
OPR_MUL 
OPR_DIV 
OPR_MOD 
OPR_POW 
OPR_CONCAT 
OPR_NE 
OPR_EQ 
OPR_LT 
OPR_LE 
OPR_GT 
OPR_GE 
OPR_AND 
OPR_OR 
OPR_NOBINOPR 

Definiert in Zeile 26 der Datei lcode.h.

enum UnOpr
Aufzählungswerte
OPR_MINUS 
OPR_NOT 
OPR_LEN 
OPR_NOUNOPR 

Definiert in Zeile 36 der Datei lcode.h.

Dokumentation der Funktionen

LUAI_FUNC void luaK_checkstack ( FuncState fs,
int  n 
)

Definiert in Zeile 199 der Datei lcode.c.

199  {
200  int newstack = fs->freereg + n;
201  if (newstack > fs->f->maxstacksize) {
202  if (newstack >= MAXSTACK)
203  luaX_syntaxerror(fs->ls, "function or expression too complex");
204  fs->f->maxstacksize = cast_byte(newstack);
205  }
206 }
LUAI_FUNC int luaK_codeABC ( FuncState fs,
OpCode  o,
int  A,
int  B,
int  C 
)

Definiert in Zeile 804 der Datei lcode.c.

804  {
805  lua_assert(getOpMode(o) == iABC);
806  lua_assert(getBMode(o) != OpArgN || b == 0);
807  lua_assert(getCMode(o) != OpArgN || c == 0);
808  return luaK_code(fs, CREATE_ABC(o, a, b, c), fs->ls->lastline);
809 }
LUAI_FUNC int luaK_codeABx ( FuncState fs,
OpCode  o,
int  A,
unsigned int  Bx 
)

Definiert in Zeile 812 der Datei lcode.c.

812  {
813  lua_assert(getOpMode(o) == iABx || getOpMode(o) == iAsBx);
815  return luaK_code(fs, CREATE_ABx(o, a, bc), fs->ls->lastline);
816 }
LUAI_FUNC void luaK_concat ( FuncState fs,
int *  l1,
int  l2 
)

Definiert in Zeile 185 der Datei lcode.c.

185  {
186  if (l2 == NO_JUMP) return;
187  else if (*l1 == NO_JUMP)
188  *l1 = l2;
189  else {
190  int list = *l1;
191  int next;
192  while ((next = getjump(fs, list)) != NO_JUMP) /* find last element */
193  list = next;
194  fixjump(fs, list, l2);
195  }
196 }
LUAI_FUNC void luaK_dischargevars ( FuncState fs,
expdesc e 
)

Definiert in Zeile 304 der Datei lcode.c.

304  {
305  switch (e->k) {
306  case VLOCAL: {
307  e->k = VNONRELOC;
308  break;
309  }
310  case VUPVAL: {
311  e->u.s.info = luaK_codeABC(fs, OP_GETUPVAL, 0, e->u.s.info, 0);
312  e->k = VRELOCABLE;
313  break;
314  }
315  case VGLOBAL: {
316  e->u.s.info = luaK_codeABx(fs, OP_GETGLOBAL, 0, e->u.s.info);
317  e->k = VRELOCABLE;
318  break;
319  }
320  case VINDEXED: {
321  freereg(fs, e->u.s.aux);
322  freereg(fs, e->u.s.info);
323  e->u.s.info = luaK_codeABC(fs, OP_GETTABLE, 0, e->u.s.info, e->u.s.aux);
324  e->k = VRELOCABLE;
325  break;
326  }
327  case VVARARG:
328  case VCALL: {
329  luaK_setoneret(fs, e);
330  break;
331  }
332  default: break; /* there is one value available (somewhere) */
333  }
334 }
LUAI_FUNC int luaK_exp2anyreg ( FuncState fs,
expdesc e 
)

Definiert in Zeile 422 der Datei lcode.c.

422  {
423  luaK_dischargevars(fs, e);
424  if (e->k == VNONRELOC) {
425  if (!hasjumps(e)) return e->u.s.info; /* exp is already in a register */
426  if (e->u.s.info >= fs->nactvar) { /* reg. is not a local? */
427  exp2reg(fs, e, e->u.s.info); /* put value on it */
428  return e->u.s.info;
429  }
430  }
431  luaK_exp2nextreg(fs, e); /* default */
432  return e->u.s.info;
433 }
LUAI_FUNC void luaK_exp2nextreg ( FuncState fs,
expdesc e 
)

Definiert in Zeile 414 der Datei lcode.c.

414  {
415  luaK_dischargevars(fs, e);
416  freeexp(fs, e);
417  luaK_reserveregs(fs, 1);
418  exp2reg(fs, e, fs->freereg - 1);
419 }
LUAI_FUNC int luaK_exp2RK ( FuncState fs,
expdesc e 
)

Definiert in Zeile 444 der Datei lcode.c.

444  {
445  luaK_exp2val(fs, e);
446  switch (e->k) {
447  case VKNUM:
448  case VTRUE:
449  case VFALSE:
450  case VNIL: {
451  if (fs->nk <= MAXINDEXRK) { /* constant fit in RK operand? */
452  e->u.s.info = (e->k == VNIL) ? nilK(fs) :
453  (e->k == VKNUM) ? luaK_numberK(fs, e->u.nval) :
454  boolK(fs, (e->k == VTRUE));
455  e->k = VK;
456  return RKASK(e->u.s.info);
457  }
458  else break;
459  }
460  case VK: {
461  if (e->u.s.info <= MAXINDEXRK) /* constant fit in argC? */
462  return RKASK(e->u.s.info);
463  else break;
464  }
465  default: break;
466  }
467  /* not a constant in the right range: put it in a register */
468  return luaK_exp2anyreg(fs, e);
469 }
LUAI_FUNC void luaK_exp2val ( FuncState fs,
expdesc e 
)

Definiert in Zeile 436 der Datei lcode.c.

436  {
437  if (hasjumps(e))
438  luaK_exp2anyreg(fs, e);
439  else
440  luaK_dischargevars(fs, e);
441 }
LUAI_FUNC void luaK_fixline ( FuncState fs,
int  line 
)

Definiert in Zeile 784 der Datei lcode.c.

784  {
785  fs->f->lineinfo[fs->pc - 1] = line;
786 }
LUAI_FUNC int luaK_getlabel ( FuncState fs)

Definiert in Zeile 94 der Datei lcode.c.

94  {
95  fs->lasttarget = fs->pc;
96  return fs->pc;
97 }
LUAI_FUNC void luaK_goiftrue ( FuncState fs,
expdesc e 
)

Definiert in Zeile 539 der Datei lcode.c.

539  {
540  int pc; /* pc of last jump */
541  luaK_dischargevars(fs, e);
542  switch (e->k) {
543  case VK: case VKNUM: case VTRUE: {
544  pc = NO_JUMP; /* always true; do nothing */
545  break;
546  }
547  case VJMP: {
548  invertjump(fs, e);
549  pc = e->u.s.info;
550  break;
551  }
552  default: {
553  pc = jumponcond(fs, e, 0);
554  break;
555  }
556  }
557  luaK_concat(fs, &e->f, pc); /* insert last jump in `f' list */
558  luaK_patchtohere(fs, e->t);
559  e->t = NO_JUMP;
560 }
LUAI_FUNC void luaK_indexed ( FuncState fs,
expdesc t,
expdesc k 
)

Definiert in Zeile 621 der Datei lcode.c.

621  {
622  t->u.s.aux = luaK_exp2RK(fs, k);
623  t->k = VINDEXED;
624 }
LUAI_FUNC void luaK_infix ( FuncState fs,
BinOpr  op,
expdesc v 
)

Definiert in Zeile 710 der Datei lcode.c.

710  {
711  switch (op) {
712  case OPR_AND: {
713  luaK_goiftrue(fs, v);
714  break;
715  }
716  case OPR_OR: {
717  luaK_goiffalse(fs, v);
718  break;
719  }
720  case OPR_CONCAT: {
721  luaK_exp2nextreg(fs, v); /* operand must be on the `stack' */
722  break;
723  }
724  case OPR_ADD: case OPR_SUB: case OPR_MUL: case OPR_DIV:
725  case OPR_MOD: case OPR_POW: {
726  if (!isnumeral(v)) luaK_exp2RK(fs, v);
727  break;
728  }
729  default: {
730  luaK_exp2RK(fs, v);
731  break;
732  }
733  }
734 }
LUAI_FUNC int luaK_jump ( FuncState fs)

Definiert in Zeile 59 der Datei lcode.c.

59  {
60  int jpc = fs->jpc; /* save list of jumps to here */
61  int j;
62  fs->jpc = NO_JUMP;
63  j = luaK_codeAsBx(fs, OP_JMP, 0, NO_JUMP);
64  luaK_concat(fs, &j, jpc); /* keep them on hold */
65  return j;
66 }
LUAI_FUNC void luaK_nil ( FuncState fs,
int  from,
int  n 
)

Definiert in Zeile 35 der Datei lcode.c.

35  {
36  Instruction *previous;
37  if (fs->pc > fs->lasttarget) { /* no jumps to current position? */
38  if (fs->pc == 0) { /* function start? */
39  if (from >= fs->nactvar)
40  return; /* positions are already clean */
41  }
42  else {
43  previous = &fs->f->code[fs->pc-1];
44  if (GET_OPCODE(*previous) == OP_LOADNIL) {
45  int pfrom = GETARG_A(*previous);
46  int pto = GETARG_B(*previous);
47  if (pfrom <= from && from <= pto+1) { /* can connect both? */
48  if (from+n-1 > pto)
49  SETARG_B(*previous, from+n-1);
50  return;
51  }
52  }
53  }
54  }
55  luaK_codeABC(fs, OP_LOADNIL, from, from+n-1, 0); /* else no optimization */
56 }
LUAI_FUNC int luaK_numberK ( FuncState fs,
lua_Number  r 
)

Definiert in Zeile 257 der Datei lcode.c.

257  {
258  TValue o;
259  setnvalue(&o, r);
260  return addk(fs, &o, &o);
261 }
LUAI_FUNC void luaK_patchlist ( FuncState fs,
int  list,
int  target 
)

Definiert in Zeile 169 der Datei lcode.c.

169  {
170  if (target == fs->pc)
171  luaK_patchtohere(fs, list);
172  else {
173  lua_assert(target < fs->pc);
174  patchlistaux(fs, list, target, NO_REG, target);
175  }
176 }
LUAI_FUNC void luaK_patchtohere ( FuncState fs,
int  list 
)

Definiert in Zeile 179 der Datei lcode.c.

179  {
180  luaK_getlabel(fs);
181  luaK_concat(fs, &fs->jpc, list);
182 }
LUAI_FUNC void luaK_posfix ( FuncState fs,
BinOpr  op,
expdesc v1,
expdesc v2 
)

Definiert in Zeile 737 der Datei lcode.c.

737  {
738  switch (op) {
739  case OPR_AND: {
740  lua_assert(e1->t == NO_JUMP); /* list must be closed */
741  luaK_dischargevars(fs, e2);
742  luaK_concat(fs, &e2->f, e1->f);
743  *e1 = *e2;
744  break;
745  }
746  case OPR_OR: {
747  lua_assert(e1->f == NO_JUMP); /* list must be closed */
748  luaK_dischargevars(fs, e2);
749  luaK_concat(fs, &e2->t, e1->t);
750  *e1 = *e2;
751  break;
752  }
753  case OPR_CONCAT: {
754  luaK_exp2val(fs, e2);
755  if (e2->k == VRELOCABLE && GET_OPCODE(getcode(fs, e2)) == OP_CONCAT) {
756  lua_assert(e1->u.s.info == GETARG_B(getcode(fs, e2))-1);
757  freeexp(fs, e1);
758  SETARG_B(getcode(fs, e2), e1->u.s.info);
759  e1->k = VRELOCABLE; e1->u.s.info = e2->u.s.info;
760  }
761  else {
762  luaK_exp2nextreg(fs, e2); /* operand must be on the 'stack' */
763  codearith(fs, OP_CONCAT, e1, e2);
764  }
765  break;
766  }
767  case OPR_ADD: codearith(fs, OP_ADD, e1, e2); break;
768  case OPR_SUB: codearith(fs, OP_SUB, e1, e2); break;
769  case OPR_MUL: codearith(fs, OP_MUL, e1, e2); break;
770  case OPR_DIV: codearith(fs, OP_DIV, e1, e2); break;
771  case OPR_MOD: codearith(fs, OP_MOD, e1, e2); break;
772  case OPR_POW: codearith(fs, OP_POW, e1, e2); break;
773  case OPR_EQ: codecomp(fs, OP_EQ, 1, e1, e2); break;
774  case OPR_NE: codecomp(fs, OP_EQ, 0, e1, e2); break;
775  case OPR_LT: codecomp(fs, OP_LT, 1, e1, e2); break;
776  case OPR_LE: codecomp(fs, OP_LE, 1, e1, e2); break;
777  case OPR_GT: codecomp(fs, OP_LT, 0, e1, e2); break;
778  case OPR_GE: codecomp(fs, OP_LE, 0, e1, e2); break;
779  default: lua_assert(0);
780  }
781 }
LUAI_FUNC void luaK_prefix ( FuncState fs,
UnOpr  op,
expdesc v 
)

Definiert in Zeile 689 der Datei lcode.c.

689  {
690  expdesc e2;
691  e2.t = e2.f = NO_JUMP; e2.k = VKNUM; e2.u.nval = 0;
692  switch (op) {
693  case OPR_MINUS: {
694  if (!isnumeral(e))
695  luaK_exp2anyreg(fs, e); /* cannot operate on non-numeric constants */
696  codearith(fs, OP_UNM, e, &e2);
697  break;
698  }
699  case OPR_NOT: codenot(fs, e); break;
700  case OPR_LEN: {
701  luaK_exp2anyreg(fs, e); /* cannot operate on constants */
702  codearith(fs, OP_LEN, e, &e2);
703  break;
704  }
705  default: lua_assert(0);
706  }
707 }
LUAI_FUNC void luaK_reserveregs ( FuncState fs,
int  n 
)

Definiert in Zeile 209 der Datei lcode.c.

209  {
210  luaK_checkstack(fs, n);
211  fs->freereg += n;
212 }
LUAI_FUNC void luaK_ret ( FuncState fs,
int  first,
int  nret 
)

Definiert in Zeile 69 der Datei lcode.c.

69  {
70  luaK_codeABC(fs, OP_RETURN, first, nret+1, 0);
71 }
LUAI_FUNC void luaK_self ( FuncState fs,
expdesc e,
expdesc key 
)

Definiert in Zeile 503 der Datei lcode.c.

503  {
504  int func;
505  luaK_exp2anyreg(fs, e);
506  freeexp(fs, e);
507  func = fs->freereg;
508  luaK_reserveregs(fs, 2);
509  luaK_codeABC(fs, OP_SELF, func, e->u.s.info, luaK_exp2RK(fs, key));
510  freeexp(fs, key);
511  e->u.s.info = func;
512  e->k = VNONRELOC;
513 }
LUAI_FUNC void luaK_setlist ( FuncState fs,
int  base,
int  nelems,
int  tostore 
)

Definiert in Zeile 819 der Datei lcode.c.

819  {
820  int c = (nelems - 1)/LFIELDS_PER_FLUSH + 1;
821  int b = (tostore == LUA_MULTRET) ? 0 : tostore;
822  lua_assert(tostore != 0);
823  if (c <= MAXARG_C)
824  luaK_codeABC(fs, OP_SETLIST, base, b, c);
825  else {
826  luaK_codeABC(fs, OP_SETLIST, base, b, 0);
827  luaK_code(fs, cast(Instruction, c), fs->ls->lastline);
828  }
829  fs->freereg = base + 1; /* free registers with list values */
830 }
LUAI_FUNC void luaK_setoneret ( FuncState fs,
expdesc e 
)

Definiert in Zeile 292 der Datei lcode.c.

292  {
293  if (e->k == VCALL) { /* expression is an open function call? */
294  e->k = VNONRELOC;
295  e->u.s.info = GETARG_A(getcode(fs, e));
296  }
297  else if (e->k == VVARARG) {
298  SETARG_B(getcode(fs, e), 2);
299  e->k = VRELOCABLE; /* can relocate its simple result */
300  }
301 }
LUAI_FUNC void luaK_setreturns ( FuncState fs,
expdesc e,
int  nresults 
)

Definiert in Zeile 280 der Datei lcode.c.

280  {
281  if (e->k == VCALL) { /* expression is an open function call? */
282  SETARG_C(getcode(fs, e), nresults+1);
283  }
284  else if (e->k == VVARARG) {
285  SETARG_B(getcode(fs, e), nresults+1);
286  SETARG_A(getcode(fs, e), fs->freereg);
287  luaK_reserveregs(fs, 1);
288  }
289 }
LUAI_FUNC void luaK_storevar ( FuncState fs,
expdesc var,
expdesc e 
)

Definiert in Zeile 472 der Datei lcode.c.

472  {
473  switch (var->k) {
474  case VLOCAL: {
475  freeexp(fs, ex);
476  exp2reg(fs, ex, var->u.s.info);
477  return;
478  }
479  case VUPVAL: {
480  int e = luaK_exp2anyreg(fs, ex);
481  luaK_codeABC(fs, OP_SETUPVAL, e, var->u.s.info, 0);
482  break;
483  }
484  case VGLOBAL: {
485  int e = luaK_exp2anyreg(fs, ex);
486  luaK_codeABx(fs, OP_SETGLOBAL, e, var->u.s.info);
487  break;
488  }
489  case VINDEXED: {
490  int e = luaK_exp2RK(fs, ex);
491  luaK_codeABC(fs, OP_SETTABLE, var->u.s.info, var->u.s.aux, e);
492  break;
493  }
494  default: {
495  lua_assert(0); /* invalid var kind to store */
496  break;
497  }
498  }
499  freeexp(fs, ex);
500 }
LUAI_FUNC int luaK_stringK ( FuncState fs,
TString s 
)

Definiert in Zeile 250 der Datei lcode.c.

250  {
251  TValue o;
252  setsvalue(fs->L, &o, s);
253  return addk(fs, &o, &o);
254 }