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

gehe zum Quellcode dieser Datei

Makrodefinitionen

#define tostring(L, o)   ((ttype(o) == LUA_TSTRING) || (luaV_tostring(L, o)))
 
#define tonumber(o, n)
 
#define equalobj(L, o1, o2)   (ttype(o1) == ttype(o2) && luaV_equalval(L, o1, o2))
 

Funktionen

LUAI_FUNC int luaV_lessthan (lua_State *L, const TValue *l, const TValue *r)
 
LUAI_FUNC int luaV_equalval (lua_State *L, const TValue *t1, const TValue *t2)
 
LUAI_FUNC const TValueluaV_tonumber (const TValue *obj, TValue *n)
 
LUAI_FUNC int luaV_tostring (lua_State *L, StkId obj)
 
LUAI_FUNC void luaV_gettable (lua_State *L, const TValue *t, TValue *key, StkId val)
 
LUAI_FUNC void luaV_settable (lua_State *L, const TValue *t, TValue *key, StkId val)
 
LUAI_FUNC void luaV_execute (lua_State *L, int nexeccalls)
 
LUAI_FUNC void luaV_concat (lua_State *L, int total, int last)
 

Makro-Dokumentation

#define equalobj (   L,
  o1,
  o2 
)    (ttype(o1) == ttype(o2) && luaV_equalval(L, o1, o2))

Definiert in Zeile 21 der Datei lvm.h.

#define tonumber (   o,
  n 
)
Wert:
(ttype(o) == LUA_TNUMBER || \
(((o) = luaV_tonumber(o,n)) != NULL))

Definiert in Zeile 18 der Datei lvm.h.

#define tostring (   L,
  o 
)    ((ttype(o) == LUA_TSTRING) || (luaV_tostring(L, o)))

Definiert in Zeile 16 der Datei lvm.h.

Dokumentation der Funktionen

LUAI_FUNC void luaV_concat ( lua_State L,
int  total,
int  last 
)

Definiert in Zeile 298 der Datei lvm.c.

298  {
299  do {
300  StkId top = L->base + last + 1;
301  int n = 2; /* number of elements handled in this pass (at least 2) */
302  if (!(ttisstring(top-2) || ttisnumber(top-2)) || !tostring(L, top-1)) {
303  if (!call_binTM(L, top-2, top-1, top-2, TM_CONCAT))
304  luaG_concaterror(L, top-2, top-1);
305  } else if (tsvalue(top-1)->len == 0) /* second op is empty? */
306  (void)tostring(L, top - 2); /* result is first op (as string) */
307  else {
308  /* at least two string values; get as many as possible */
309  size_t tl = tsvalue(top-1)->len;
310  char *buffer;
311  int i;
312  /* collect total length */
313  for (n = 1; n < total && tostring(L, top-n-1); n++) {
314  size_t l = tsvalue(top-n-1)->len;
315  if (l >= MAX_SIZET - tl) luaG_runerror(L, "string length overflow");
316  tl += l;
317  }
318  buffer = luaZ_openspace(L, &G(L)->buff, tl);
319  tl = 0;
320  for (i=n; i>0; i--) { /* concat all strings */
321  size_t l = tsvalue(top-i)->len;
322  memcpy(buffer+tl, svalue(top-i), l);
323  tl += l;
324  }
325  setsvalue2s(L, top-n, luaS_newlstr(L, buffer, tl));
326  }
327  total -= n-1; /* got `n' strings to create 1 new */
328  last -= n-1;
329  } while (total > 1); /* repeat until only 1 result left */
330 }
LUAI_FUNC int luaV_equalval ( lua_State L,
const TValue t1,
const TValue t2 
)

Definiert in Zeile 271 der Datei lvm.c.

271  {
272  const TValue *tm;
273  lua_assert(ttype(t1) == ttype(t2));
274  switch (ttype(t1)) {
275  case LUA_TNIL: return 1;
276  case LUA_TNUMBER: return luai_numeq(nvalue(t1), nvalue(t2));
277  case LUA_TBOOLEAN: return bvalue(t1) == bvalue(t2); /* true must be 1 !! */
278  case LUA_TLIGHTUSERDATA: return pvalue(t1) == pvalue(t2);
279  case LUA_TUSERDATA: {
280  if (uvalue(t1) == uvalue(t2)) return 1;
281  tm = get_compTM(L, uvalue(t1)->metatable, uvalue(t2)->metatable,
282  TM_EQ);
283  break; /* will try TM */
284  }
285  case LUA_TTABLE: {
286  if (hvalue(t1) == hvalue(t2)) return 1;
287  tm = get_compTM(L, hvalue(t1)->metatable, hvalue(t2)->metatable, TM_EQ);
288  break; /* will try TM */
289  }
290  default: return gcvalue(t1) == gcvalue(t2);
291  }
292  if (tm == NULL) return 0; /* no TM? */
293  callTMres(L, L->top, tm, t1, t2); /* call TM */
294  return !l_isfalse(L->top);
295 }
LUAI_FUNC void luaV_execute ( lua_State L,
int  nexeccalls 
)

Definiert in Zeile 393 der Datei lvm.c.

393  {
394  LClosure *cl;
395  StkId base;
396  TValue *k;
397  const Instruction *pc;
398  reentry: /* entry point */
399  lua_assert(isLua(L->ci));
400  pc = L->savedpc;
401  cl = &clvalue(L->ci->func)->l;
402  base = L->base;
403  k = cl->p->k;
404  /* main loop of interpreter */
405  for (;;) {
406  const Instruction i = *pc++;
407  StkId ra;
408  if ((L->hookmask & (LUA_MASKLINE | LUA_MASKCOUNT)) &&
409  (--L->hookcount == 0 || L->hookmask & LUA_MASKLINE)) {
410  traceexec(L, pc);
411  if (L->status == LUA_YIELD) { /* did hook yield? */
412  L->savedpc = pc - 1;
413  return;
414  }
415  base = L->base;
416  }
417  /* warning!! several calls may realloc the stack and invalidate `ra' */
418  ra = RA(i);
419  lua_assert(base == L->base && L->base == L->ci->base);
420  lua_assert(base <= L->top && L->top <= L->stack + L->stacksize);
421  lua_assert(L->top == L->ci->top || luaG_checkopenop(i));
422  switch (GET_OPCODE(i)) {
423  case OP_MOVE: {
424  setobjs2s(L, ra, RB(i));
425  continue;
426  }
427  case OP_LOADK: {
428  setobj2s(L, ra, KBx(i));
429  continue;
430  }
431  case OP_LOADBOOL: {
432  setbvalue(ra, GETARG_B(i));
433  if (GETARG_C(i)) pc++; /* skip next instruction (if C) */
434  continue;
435  }
436  case OP_LOADNIL: {
437  TValue *rb = RB(i);
438  do {
439  setnilvalue(rb--);
440  } while (rb >= ra);
441  continue;
442  }
443  case OP_GETUPVAL: {
444  int b = GETARG_B(i);
445  setobj2s(L, ra, cl->upvals[b]->v);
446  continue;
447  }
448  case OP_GETGLOBAL: {
449  TValue g;
450  TValue *rb = KBx(i);
451  sethvalue(L, &g, cl->env);
452  lua_assert(ttisstring(rb));
453  Protect(luaV_gettable(L, &g, rb, ra));
454  continue;
455  }
456  case OP_GETTABLE: {
457  Protect(luaV_gettable(L, RB(i), RKC(i), ra));
458  continue;
459  }
460  case OP_SETGLOBAL: {
461  TValue g;
462  sethvalue(L, &g, cl->env);
464  Protect(luaV_settable(L, &g, KBx(i), ra));
465  continue;
466  }
467  case OP_SETUPVAL: {
468  UpVal *uv = cl->upvals[GETARG_B(i)];
469  setobj(L, uv->v, ra);
470  luaC_barrier(L, uv, ra);
471  continue;
472  }
473  case OP_SETTABLE: {
474  Protect(luaV_settable(L, ra, RKB(i), RKC(i)));
475  continue;
476  }
477  case OP_NEWTABLE: {
478  int b = GETARG_B(i);
479  int c = GETARG_C(i);
480  sethvalue(L, ra, luaH_new(L, luaO_fb2int(b), luaO_fb2int(c)));
481  Protect(luaC_checkGC(L));
482  continue;
483  }
484  case OP_SELF: {
485  StkId rb = RB(i);
486  setobjs2s(L, ra+1, rb);
487  Protect(luaV_gettable(L, rb, RKC(i), ra));
488  continue;
489  }
490  case OP_ADD: {
491  arith_op(luai_numadd, TM_ADD);
492  continue;
493  }
494  case OP_SUB: {
495  arith_op(luai_numsub, TM_SUB);
496  continue;
497  }
498  case OP_MUL: {
499  arith_op(luai_nummul, TM_MUL);
500  continue;
501  }
502  case OP_DIV: {
503  arith_op(luai_numdiv, TM_DIV);
504  continue;
505  }
506  case OP_MOD: {
507  arith_op(luai_nummod, TM_MOD);
508  continue;
509  }
510  case OP_POW: {
511  arith_op(luai_numpow, TM_POW);
512  continue;
513  }
514  case OP_UNM: {
515  TValue *rb = RB(i);
516  if (ttisnumber(rb)) {
517  lua_Number nb = nvalue(rb);
518  setnvalue(ra, luai_numunm(nb));
519  }
520  else {
521  Protect(Arith(L, ra, rb, rb, TM_UNM));
522  }
523  continue;
524  }
525  case OP_NOT: {
526  int res = l_isfalse(RB(i)); /* next assignment may change this value */
527  setbvalue(ra, res);
528  continue;
529  }
530  case OP_LEN: {
531  const TValue *rb = RB(i);
532  switch (ttype(rb)) {
533  case LUA_TTABLE: {
534  setnvalue(ra, cast_num(luaH_getn(hvalue(rb))));
535  break;
536  }
537  case LUA_TSTRING: {
538  setnvalue(ra, cast_num(tsvalue(rb)->len));
539  break;
540  }
541  default: { /* try metamethod */
542  Protect(
543  if (!call_binTM(L, rb, luaO_nilobject, ra, TM_LEN))
544  luaG_typeerror(L, rb, "get length of");
545  )
546  }
547  }
548  continue;
549  }
550  case OP_CONCAT: {
551  int b = GETARG_B(i);
552  int c = GETARG_C(i);
553  Protect(luaV_concat(L, c-b+1, c); luaC_checkGC(L));
554  setobjs2s(L, RA(i), base+b);
555  continue;
556  }
557  case OP_JMP: {
558  dojump(L, pc, GETARG_sBx(i));
559  continue;
560  }
561  case OP_EQ: {
562  TValue *rb = RKB(i);
563  TValue *rc = RKC(i);
564  Protect(
565  if (equalobj(L, rb, rc) == GETARG_A(i))
566  dojump(L, pc, GETARG_sBx(*pc));
567  )
568  pc++;
569  continue;
570  }
571  case OP_LT: {
572  Protect(
573  if (luaV_lessthan(L, RKB(i), RKC(i)) == GETARG_A(i))
574  dojump(L, pc, GETARG_sBx(*pc));
575  )
576  pc++;
577  continue;
578  }
579  case OP_LE: {
580  Protect(
581  if (lessequal(L, RKB(i), RKC(i)) == GETARG_A(i))
582  dojump(L, pc, GETARG_sBx(*pc));
583  )
584  pc++;
585  continue;
586  }
587  case OP_TEST: {
588  if (l_isfalse(ra) != GETARG_C(i))
589  dojump(L, pc, GETARG_sBx(*pc));
590  pc++;
591  continue;
592  }
593  case OP_TESTSET: {
594  TValue *rb = RB(i);
595  if (l_isfalse(rb) != GETARG_C(i)) {
596  setobjs2s(L, ra, rb);
597  dojump(L, pc, GETARG_sBx(*pc));
598  }
599  pc++;
600  continue;
601  }
602  case OP_CALL: {
603  int b = GETARG_B(i);
604  int nresults = GETARG_C(i) - 1;
605  if (b != 0) L->top = ra+b; /* else previous instruction set top */
606  L->savedpc = pc;
607  switch (luaD_precall(L, ra, nresults)) {
608  case PCRLUA: {
609  nexeccalls++;
610  goto reentry; /* restart luaV_execute over new Lua function */
611  }
612  case PCRC: {
613  /* it was a C function (`precall' called it); adjust results */
614  if (nresults >= 0) L->top = L->ci->top;
615  base = L->base;
616  continue;
617  }
618  default: {
619  return; /* yield */
620  }
621  }
622  }
623  case OP_TAILCALL: {
624  int b = GETARG_B(i);
625  if (b != 0) L->top = ra+b; /* else previous instruction set top */
626  L->savedpc = pc;
627  lua_assert(GETARG_C(i) - 1 == LUA_MULTRET);
628  switch (luaD_precall(L, ra, LUA_MULTRET)) {
629  case PCRLUA: {
630  /* tail call: put new frame in place of previous one */
631  CallInfo *ci = L->ci - 1; /* previous frame */
632  int aux;
633  StkId func = ci->func;
634  StkId pfunc = (ci+1)->func; /* previous function index */
635  if (L->openupval) luaF_close(L, ci->base);
636  L->base = ci->base = ci->func + ((ci+1)->base - pfunc);
637  for (aux = 0; pfunc+aux < L->top; aux++) /* move frame down */
638  setobjs2s(L, func+aux, pfunc+aux);
639  ci->top = L->top = func+aux; /* correct top */
640  lua_assert(L->top == L->base + clvalue(func)->l.p->maxstacksize);
641  ci->savedpc = L->savedpc;
642  ci->tailcalls++; /* one more call lost */
643  L->ci--; /* remove new frame */
644  goto reentry;
645  }
646  case PCRC: { /* it was a C function (`precall' called it) */
647  base = L->base;
648  continue;
649  }
650  default: {
651  return; /* yield */
652  }
653  }
654  }
655  case OP_RETURN: {
656  int b = GETARG_B(i);
657  if (b != 0) L->top = ra+b-1;
658  if (L->openupval) luaF_close(L, base);
659  L->savedpc = pc;
660  b = luaD_poscall(L, ra);
661  if (--nexeccalls == 0) /* was previous function running `here'? */
662  return; /* no: return */
663  else { /* yes: continue its execution */
664  if (b) L->top = L->ci->top;
665  lua_assert(isLua(L->ci));
666  lua_assert(GET_OPCODE(*((L->ci)->savedpc - 1)) == OP_CALL);
667  goto reentry;
668  }
669  }
670  case OP_FORLOOP: {
671  lua_Number step = nvalue(ra+2);
672  lua_Number idx = luai_numadd(nvalue(ra), step); /* increment index */
673  lua_Number limit = nvalue(ra+1);
674  if (luai_numlt(0, step) ? luai_numle(idx, limit)
675  : luai_numle(limit, idx)) {
676  dojump(L, pc, GETARG_sBx(i)); /* jump back */
677  setnvalue(ra, idx); /* update internal index... */
678  setnvalue(ra+3, idx); /* ...and external index */
679  }
680  continue;
681  }
682  case OP_FORPREP: {
683  const TValue *init = ra;
684  const TValue *plimit = ra+1;
685  const TValue *pstep = ra+2;
686  L->savedpc = pc; /* next steps may throw errors */
687  if (!tonumber(init, ra))
688  luaG_runerror(L, LUA_QL("for") " initial value must be a number");
689  else if (!tonumber(plimit, ra+1))
690  luaG_runerror(L, LUA_QL("for") " limit must be a number");
691  else if (!tonumber(pstep, ra+2))
692  luaG_runerror(L, LUA_QL("for") " step must be a number");
693  setnvalue(ra, luai_numsub(nvalue(ra), nvalue(pstep)));
694  dojump(L, pc, GETARG_sBx(i));
695  continue;
696  }
697  case OP_TFORLOOP: {
698  StkId cb = ra + 3; /* call base */
699  setobjs2s(L, cb+2, ra+2);
700  setobjs2s(L, cb+1, ra+1);
701  setobjs2s(L, cb, ra);
702  L->top = cb+3; /* func. + 2 args (state and index) */
703  Protect(luaD_call(L, cb, GETARG_C(i)));
704  L->top = L->ci->top;
705  cb = RA(i) + 3; /* previous call may change the stack */
706  if (!ttisnil(cb)) { /* continue loop? */
707  setobjs2s(L, cb-1, cb); /* save control variable */
708  dojump(L, pc, GETARG_sBx(*pc)); /* jump back */
709  }
710  pc++;
711  continue;
712  }
713  case OP_SETLIST: {
714  int n = GETARG_B(i);
715  int c = GETARG_C(i);
716  int last;
717  Table *h;
718  if (n == 0) {
719  n = cast_int(L->top - ra) - 1;
720  L->top = L->ci->top;
721  }
722  if (c == 0) c = cast_int(*pc++);
723  runtime_check(L, ttistable(ra));
724  h = hvalue(ra);
725  last = ((c-1)*LFIELDS_PER_FLUSH) + n;
726  if (last > h->sizearray) /* needs more space? */
727  luaH_resizearray(L, h, last); /* pre-alloc it at once */
728  for (; n > 0; n--) {
729  TValue *val = ra+n;
730  setobj2t(L, luaH_setnum(L, h, last--), val);
731  luaC_barriert(L, h, val);
732  }
733  continue;
734  }
735  case OP_CLOSE: {
736  luaF_close(L, ra);
737  continue;
738  }
739  case OP_CLOSURE: {
740  Proto *p;
741  Closure *ncl;
742  int nup, j;
743  p = cl->p->p[GETARG_Bx(i)];
744  nup = p->nups;
745  ncl = luaF_newLclosure(L, nup, cl->env);
746  ncl->l.p = p;
747  for (j=0; j<nup; j++, pc++) {
748  if (GET_OPCODE(*pc) == OP_GETUPVAL)
749  ncl->l.upvals[j] = cl->upvals[GETARG_B(*pc)];
750  else {
751  lua_assert(GET_OPCODE(*pc) == OP_MOVE);
752  ncl->l.upvals[j] = luaF_findupval(L, base + GETARG_B(*pc));
753  }
754  }
755  setclvalue(L, ra, ncl);
756  Protect(luaC_checkGC(L));
757  continue;
758  }
759  case OP_VARARG: {
760  int b = GETARG_B(i) - 1;
761  int j;
762  CallInfo *ci = L->ci;
763  int n = cast_int(ci->base - ci->func) - cl->p->numparams - 1;
764  if (b == LUA_MULTRET) {
765  Protect(luaD_checkstack(L, n));
766  ra = RA(i); /* previous call may change the stack */
767  b = n;
768  L->top = ra + n;
769  }
770  for (j = 0; j < b; j++) {
771  if (j < n) {
772  setobjs2s(L, ra + j, ci->base - n + j);
773  }
774  else {
775  setnilvalue(ra + j);
776  }
777  }
778  continue;
779  }
780  }
781  }
782 }
LUAI_FUNC void luaV_gettable ( lua_State L,
const TValue t,
TValue key,
StkId  val 
)

Definiert in Zeile 124 der Datei lvm.c.

124  {
125  int loop;
126  for (loop = 0; loop < MAXTAGLOOP; loop++) {
127  const TValue *tm;
128  if (ttistable(t)) { /* `t' is a table? */
129  Table *h = hvalue(t);
130  const TValue *res = luaH_get(h, key); /* do a primitive get */
131  if (!ttisnil(res) || /* result is no nil? */
132  (tm = fasttm(L, h->metatable, TM_INDEX)) == NULL) { /* or no TM? */
133  setobj2s(L, val, res);
134  return;
135  }
136  /* else will try the tag method */
137  }
138  else if (ttisnil(tm = luaT_gettmbyobj(L, t, TM_INDEX)))
139  luaG_typeerror(L, t, "index");
140  if (ttisfunction(tm)) {
141  callTMres(L, val, tm, t, key);
142  return;
143  }
144  t = tm; /* else repeat with `tm' */
145  }
146  luaG_runerror(L, "loop in gettable");
147 }
LUAI_FUNC int luaV_lessthan ( lua_State L,
const TValue l,
const TValue r 
)

Definiert in Zeile 241 der Datei lvm.c.

241  {
242  int res;
243  if (ttype(l) != ttype(r))
244  return luaG_ordererror(L, l, r);
245  else if (ttisnumber(l))
246  return luai_numlt(nvalue(l), nvalue(r));
247  else if (ttisstring(l))
248  return l_strcmp(rawtsvalue(l), rawtsvalue(r)) < 0;
249  else if ((res = call_orderTM(L, l, r, TM_LT)) != -1)
250  return res;
251  return luaG_ordererror(L, l, r);
252 }
LUAI_FUNC void luaV_settable ( lua_State L,
const TValue t,
TValue key,
StkId  val 
)

Definiert in Zeile 150 der Datei lvm.c.

150  {
151  int loop;
152  TValue temp;
153  for (loop = 0; loop < MAXTAGLOOP; loop++) {
154  const TValue *tm;
155  if (ttistable(t)) { /* `t' is a table? */
156  Table *h = hvalue(t);
157  TValue *oldval = luaH_set(L, h, key); /* do a primitive set */
158  if (!ttisnil(oldval) || /* result is no nil? */
159  (tm = fasttm(L, h->metatable, TM_NEWINDEX)) == NULL) { /* or no TM? */
160  setobj2t(L, oldval, val);
161  h->flags = 0;
162  luaC_barriert(L, h, val);
163  return;
164  }
165  /* else will try the tag method */
166  }
167  else if (ttisnil(tm = luaT_gettmbyobj(L, t, TM_NEWINDEX)))
168  luaG_typeerror(L, t, "index");
169  if (ttisfunction(tm)) {
170  callTM(L, tm, t, key, val);
171  return;
172  }
173  /* else repeat with `tm' */
174  setobj(L, &temp, tm); /* avoid pointing inside table (may rehash) */
175  t = &temp;
176  }
177  luaG_runerror(L, "loop in settable");
178 }
LUAI_FUNC const TValue* luaV_tonumber ( const TValue obj,
TValue n 
)

Definiert in Zeile 51 der Datei lvm.c.

51  {
53  if (ttisnumber(obj)) return obj;
54  if (ttisstring(obj) && luaO_str2d(svalue(obj), &num)) {
55  setnvalue(n, num);
56  return n;
57  }
58  else
59  return NULL;
60 }
LUAI_FUNC int luaV_tostring ( lua_State L,
StkId  obj 
)

Definiert in Zeile 63 der Datei lvm.c.

63  {
64  if (!ttisnumber(obj))
65  return 0;
66  else {
67  char s[LUAI_MAXNUMBER2STR];
68  lua_Number n = nvalue(obj);
69  lua_number2str(s, n);
70  setsvalue2s(L, obj, luaS_new(L, s));
71  return 1;
72  }
73 }