diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2002-11-07 13:37:10 -0200 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2002-11-07 13:37:10 -0200 |
commit | dff9be4224a1cd0f338b544b9e01d42f0f4e537f (patch) | |
tree | 1dc8846da882dd37d9f420c10ea545ce92fb3b8a /lvm.c | |
parent | 118347d8c3b83ea0291918e81c5367937316fabb (diff) | |
download | lua-dff9be4224a1cd0f338b544b9e01d42f0f4e537f.tar.gz lua-dff9be4224a1cd0f338b544b9e01d42f0f4e537f.tar.bz2 lua-dff9be4224a1cd0f338b544b9e01d42f0f4e537f.zip |
new macros to distinguish different types of object moves (for future GC
evolution).
Diffstat (limited to 'lvm.c')
-rw-r--r-- | lvm.c | 68 |
1 files changed, 34 insertions, 34 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lvm.c,v 1.258 2002/10/25 20:05:28 roberto Exp roberto $ | 2 | ** $Id: lvm.c,v 1.259 2002/11/06 19:08:00 roberto Exp roberto $ |
3 | ** Lua virtual machine | 3 | ** Lua virtual machine |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -98,9 +98,9 @@ static void traceexec (lua_State *L) { | |||
98 | 98 | ||
99 | static void callTMres (lua_State *L, const TObject *f, | 99 | static void callTMres (lua_State *L, const TObject *f, |
100 | const TObject *p1, const TObject *p2) { | 100 | const TObject *p1, const TObject *p2) { |
101 | setobj(L->top, f); /* push function */ | 101 | setobj2s(L->top, f); /* push function */ |
102 | setobj(L->top+1, p1); /* 1st argument */ | 102 | setobj2s(L->top+1, p1); /* 1st argument */ |
103 | setobj(L->top+2, p2); /* 2nd argument */ | 103 | setobj2s(L->top+2, p2); /* 2nd argument */ |
104 | luaD_checkstack(L, 3); /* cannot check before (could invalidate p1, p2) */ | 104 | luaD_checkstack(L, 3); /* cannot check before (could invalidate p1, p2) */ |
105 | L->top += 3; | 105 | L->top += 3; |
106 | luaD_call(L, L->top - 3, 1); | 106 | luaD_call(L, L->top - 3, 1); |
@@ -111,10 +111,10 @@ static void callTMres (lua_State *L, const TObject *f, | |||
111 | 111 | ||
112 | static void callTM (lua_State *L, const TObject *f, | 112 | static void callTM (lua_State *L, const TObject *f, |
113 | const TObject *p1, const TObject *p2, const TObject *p3) { | 113 | const TObject *p1, const TObject *p2, const TObject *p3) { |
114 | setobj(L->top, f); /* push function */ | 114 | setobj2s(L->top, f); /* push function */ |
115 | setobj(L->top+1, p1); /* 1st argument */ | 115 | setobj2s(L->top+1, p1); /* 1st argument */ |
116 | setobj(L->top+2, p2); /* 2nd argument */ | 116 | setobj2s(L->top+2, p2); /* 2nd argument */ |
117 | setobj(L->top+3, p3); /* 3th argument */ | 117 | setobj2s(L->top+3, p3); /* 3th argument */ |
118 | luaD_checkstack(L, 4); /* cannot check before (could invalidate p1...p3) */ | 118 | luaD_checkstack(L, 4); /* cannot check before (could invalidate p1...p3) */ |
119 | L->top += 4; | 119 | L->top += 4; |
120 | luaD_call(L, L->top - 4, 0); | 120 | luaD_call(L, L->top - 4, 0); |
@@ -176,7 +176,7 @@ void luaV_settable (lua_State *L, const TObject *t, TObject *key, StkId val) { | |||
176 | TObject *oldval = luaH_set(L, h, key); /* do a primitive set */ | 176 | TObject *oldval = luaH_set(L, h, key); /* do a primitive set */ |
177 | if (!ttisnil(oldval) || /* result is no nil? */ | 177 | if (!ttisnil(oldval) || /* result is no nil? */ |
178 | (tm = fasttm(L, h->metatable, TM_NEWINDEX)) == NULL) { /* or no TM? */ | 178 | (tm = fasttm(L, h->metatable, TM_NEWINDEX)) == NULL) { /* or no TM? */ |
179 | setobj(oldval, val); | 179 | setobj2t(oldval, val); |
180 | return; | 180 | return; |
181 | } | 181 | } |
182 | /* else will try the tag method */ | 182 | /* else will try the tag method */ |
@@ -194,7 +194,7 @@ void luaV_settable (lua_State *L, const TObject *t, TObject *key, StkId val) { | |||
194 | 194 | ||
195 | 195 | ||
196 | static int call_binTM (lua_State *L, const TObject *p1, const TObject *p2, | 196 | static int call_binTM (lua_State *L, const TObject *p1, const TObject *p2, |
197 | TObject *res, TMS event) { | 197 | StkId res, TMS event) { |
198 | ptrdiff_t result = savestack(L, res); | 198 | ptrdiff_t result = savestack(L, res); |
199 | const TObject *tm = luaT_gettmbyobj(L, p1, event); /* try first operand */ | 199 | const TObject *tm = luaT_gettmbyobj(L, p1, event); /* try first operand */ |
200 | if (ttisnil(tm)) | 200 | if (ttisnil(tm)) |
@@ -202,7 +202,7 @@ static int call_binTM (lua_State *L, const TObject *p1, const TObject *p2, | |||
202 | if (!ttisfunction(tm)) return 0; | 202 | if (!ttisfunction(tm)) return 0; |
203 | callTMres(L, tm, p1, p2); | 203 | callTMres(L, tm, p1, p2); |
204 | res = restorestack(L, result); /* previous call may change stack */ | 204 | res = restorestack(L, result); /* previous call may change stack */ |
205 | setobj(res, L->top); | 205 | setobjs2s(res, L->top); |
206 | return 1; | 206 | return 1; |
207 | } | 207 | } |
208 | 208 | ||
@@ -311,7 +311,7 @@ void luaV_concat (lua_State *L, int total, int last) { | |||
311 | memcpy(buffer+tl, svalue(top-i), l); | 311 | memcpy(buffer+tl, svalue(top-i), l); |
312 | tl += l; | 312 | tl += l; |
313 | } | 313 | } |
314 | setsvalue(top-n, luaS_newlstr(L, buffer, tl)); | 314 | setsvalue2s(top-n, luaS_newlstr(L, buffer, tl)); |
315 | } | 315 | } |
316 | total -= n-1; /* got `n' strings to create 1 new */ | 316 | total -= n-1; /* got `n' strings to create 1 new */ |
317 | last -= n-1; | 317 | last -= n-1; |
@@ -338,7 +338,7 @@ static void Arith (lua_State *L, StkId ra, | |||
338 | luaG_runerror(L, "`pow' (for `^' operator) is not a function"); | 338 | luaG_runerror(L, "`pow' (for `^' operator) is not a function"); |
339 | callTMres(L, f, b, c); | 339 | callTMres(L, f, b, c); |
340 | ra = restorestack(L, res); /* previous call may change stack */ | 340 | ra = restorestack(L, res); /* previous call may change stack */ |
341 | setobj(ra, L->top); | 341 | setobjs2s(ra, L->top); |
342 | break; | 342 | break; |
343 | } | 343 | } |
344 | default: lua_assert(0); break; | 344 | default: lua_assert(0); break; |
@@ -399,11 +399,11 @@ StkId luaV_execute (lua_State *L) { | |||
399 | GET_OPCODE(i) == OP_RETURN || GET_OPCODE(i) == OP_SETLISTO); | 399 | GET_OPCODE(i) == OP_RETURN || GET_OPCODE(i) == OP_SETLISTO); |
400 | switch (GET_OPCODE(i)) { | 400 | switch (GET_OPCODE(i)) { |
401 | case OP_MOVE: { | 401 | case OP_MOVE: { |
402 | setobj(ra, RB(i)); | 402 | setobjs2s(ra, RB(i)); |
403 | break; | 403 | break; |
404 | } | 404 | } |
405 | case OP_LOADK: { | 405 | case OP_LOADK: { |
406 | setobj(ra, KBx(i)); | 406 | setobj2s(ra, KBx(i)); |
407 | break; | 407 | break; |
408 | } | 408 | } |
409 | case OP_LOADBOOL: { | 409 | case OP_LOADBOOL: { |
@@ -420,7 +420,7 @@ StkId luaV_execute (lua_State *L) { | |||
420 | } | 420 | } |
421 | case OP_GETUPVAL: { | 421 | case OP_GETUPVAL: { |
422 | int b = GETARG_B(i); | 422 | int b = GETARG_B(i); |
423 | setobj(ra, cl->upvals[b]->v); | 423 | setobj2s(ra, cl->upvals[b]->v); |
424 | break; | 424 | break; |
425 | } | 425 | } |
426 | case OP_GETGLOBAL: { | 426 | case OP_GETGLOBAL: { |
@@ -428,9 +428,9 @@ StkId luaV_execute (lua_State *L) { | |||
428 | const TObject *v; | 428 | const TObject *v; |
429 | lua_assert(ttisstring(rb) && ttistable(&cl->g)); | 429 | lua_assert(ttisstring(rb) && ttistable(&cl->g)); |
430 | v = luaH_getstr(hvalue(&cl->g), tsvalue(rb)); | 430 | v = luaH_getstr(hvalue(&cl->g), tsvalue(rb)); |
431 | if (!ttisnil(v)) { setobj(ra, v); } | 431 | if (!ttisnil(v)) { setobj2s(ra, v); } |
432 | else | 432 | else |
433 | setobj(RA(i), luaV_index(L, &cl->g, rb, 0)); | 433 | setobj2s(RA(i), luaV_index(L, &cl->g, rb, 0)); |
434 | break; | 434 | break; |
435 | } | 435 | } |
436 | case OP_GETTABLE: { | 436 | case OP_GETTABLE: { |
@@ -438,12 +438,12 @@ StkId luaV_execute (lua_State *L) { | |||
438 | TObject *rc = RKC(i); | 438 | TObject *rc = RKC(i); |
439 | if (ttistable(rb)) { | 439 | if (ttistable(rb)) { |
440 | const TObject *v = luaH_get(hvalue(rb), rc); | 440 | const TObject *v = luaH_get(hvalue(rb), rc); |
441 | if (!ttisnil(v)) { setobj(ra, v); } | 441 | if (!ttisnil(v)) { setobj2s(ra, v); } |
442 | else | 442 | else |
443 | setobj(RA(i), luaV_index(L, rb, rc, 0)); | 443 | setobj2s(RA(i), luaV_index(L, rb, rc, 0)); |
444 | } | 444 | } |
445 | else | 445 | else |
446 | setobj(RA(i), luaV_getnotable(L, rb, rc, 0)); | 446 | setobj2s(RA(i), luaV_getnotable(L, rb, rc, 0)); |
447 | break; | 447 | break; |
448 | } | 448 | } |
449 | case OP_SETGLOBAL: { | 449 | case OP_SETGLOBAL: { |
@@ -471,15 +471,15 @@ StkId luaV_execute (lua_State *L) { | |||
471 | StkId rb = RB(i); | 471 | StkId rb = RB(i); |
472 | TObject *rc = RKC(i); | 472 | TObject *rc = RKC(i); |
473 | runtime_check(L, ttisstring(rc)); | 473 | runtime_check(L, ttisstring(rc)); |
474 | setobj(ra+1, rb); | 474 | setobjs2s(ra+1, rb); |
475 | if (ttistable(rb)) { | 475 | if (ttistable(rb)) { |
476 | const TObject *v = luaH_getstr(hvalue(rb), tsvalue(rc)); | 476 | const TObject *v = luaH_getstr(hvalue(rb), tsvalue(rc)); |
477 | if (!ttisnil(v)) { setobj(ra, v); } | 477 | if (!ttisnil(v)) { setobj2s(ra, v); } |
478 | else | 478 | else |
479 | setobj(RA(i), luaV_index(L, rb, rc, 0)); | 479 | setobj2s(RA(i), luaV_index(L, rb, rc, 0)); |
480 | } | 480 | } |
481 | else | 481 | else |
482 | setobj(RA(i), luaV_getnotable(L, rb, rc, 0)); | 482 | setobj2s(RA(i), luaV_getnotable(L, rb, rc, 0)); |
483 | break; | 483 | break; |
484 | } | 484 | } |
485 | case OP_ADD: { | 485 | case OP_ADD: { |
@@ -548,7 +548,7 @@ StkId luaV_execute (lua_State *L) { | |||
548 | int b = GETARG_B(i); | 548 | int b = GETARG_B(i); |
549 | int c = GETARG_C(i); | 549 | int c = GETARG_C(i); |
550 | luaV_concat(L, c-b+1, c); /* may change `base' (and `ra') */ | 550 | luaV_concat(L, c-b+1, c); /* may change `base' (and `ra') */ |
551 | setobj(RA(i), base+b); | 551 | setobjs2s(RA(i), base+b); |
552 | luaV_checkGC(L, base+c+1); | 552 | luaV_checkGC(L, base+c+1); |
553 | break; | 553 | break; |
554 | } | 554 | } |
@@ -575,7 +575,7 @@ StkId luaV_execute (lua_State *L) { | |||
575 | TObject *rb = RB(i); | 575 | TObject *rb = RB(i); |
576 | if (l_isfalse(rb) == GETARG_C(i)) pc++; | 576 | if (l_isfalse(rb) == GETARG_C(i)) pc++; |
577 | else { | 577 | else { |
578 | setobj(ra, rb); | 578 | setobjs2s(ra, rb); |
579 | dojump(pc, GETARG_sBx(*pc) + 1); | 579 | dojump(pc, GETARG_sBx(*pc) + 1); |
580 | } | 580 | } |
581 | break; | 581 | break; |
@@ -609,7 +609,7 @@ StkId luaV_execute (lua_State *L) { | |||
609 | StkId ra1 = RA(i); /* `luaD_precall' may change the stack */ | 609 | StkId ra1 = RA(i); /* `luaD_precall' may change the stack */ |
610 | if (L->openupval) luaF_close(L, base); | 610 | if (L->openupval) luaF_close(L, base); |
611 | for (aux = 0; ra1+aux < L->top; aux++) /* move frame down */ | 611 | for (aux = 0; ra1+aux < L->top; aux++) /* move frame down */ |
612 | setobj(base+aux-1, ra1+aux); | 612 | setobjs2s(base+aux-1, ra1+aux); |
613 | (L->ci - 1)->top = L->top = base+aux; /* correct top */ | 613 | (L->ci - 1)->top = L->top = base+aux; /* correct top */ |
614 | lua_assert(L->ci->state & CI_SAVEDPC); | 614 | lua_assert(L->ci->state & CI_SAVEDPC); |
615 | (L->ci - 1)->u.l.savedpc = L->ci->u.l.savedpc; | 615 | (L->ci - 1)->u.l.savedpc = L->ci->u.l.savedpc; |
@@ -662,9 +662,9 @@ StkId luaV_execute (lua_State *L) { | |||
662 | break; | 662 | break; |
663 | } | 663 | } |
664 | case OP_TFORLOOP: { | 664 | case OP_TFORLOOP: { |
665 | setobj(ra+4, ra+2); | 665 | setobjs2s(ra+4, ra+2); |
666 | setobj(ra+3, ra+1); | 666 | setobjs2s(ra+3, ra+1); |
667 | setobj(ra+2, ra); | 667 | setobjs2s(ra+2, ra); |
668 | L->top = ra+5; | 668 | L->top = ra+5; |
669 | luaD_call(L, ra+2, GETARG_C(i) + 1); | 669 | luaD_call(L, ra+2, GETARG_C(i) + 1); |
670 | L->top = L->ci->top; | 670 | L->top = L->ci->top; |
@@ -674,8 +674,8 @@ StkId luaV_execute (lua_State *L) { | |||
674 | } | 674 | } |
675 | case OP_TFORPREP: { /* for compatibility only */ | 675 | case OP_TFORPREP: { /* for compatibility only */ |
676 | if (ttistable(ra)) { | 676 | if (ttistable(ra)) { |
677 | setobj(ra+1, ra); | 677 | setobjs2s(ra+1, ra); |
678 | setobj(ra, luaH_getstr(hvalue(gt(L)), luaS_new(L, "next"))); | 678 | setobj2s(ra, luaH_getstr(hvalue(gt(L)), luaS_new(L, "next"))); |
679 | } | 679 | } |
680 | dojump(pc, GETARG_sBx(i)); | 680 | dojump(pc, GETARG_sBx(i)); |
681 | break; | 681 | break; |
@@ -696,7 +696,7 @@ StkId luaV_execute (lua_State *L) { | |||
696 | } | 696 | } |
697 | bc &= ~(LFIELDS_PER_FLUSH-1); /* bc = bc - bc%FPF */ | 697 | bc &= ~(LFIELDS_PER_FLUSH-1); /* bc = bc - bc%FPF */ |
698 | for (; n > 0; n--) | 698 | for (; n > 0; n--) |
699 | setobj(luaH_setnum(L, h, bc+n), ra+n); | 699 | setobj2t(luaH_setnum(L, h, bc+n), ra+n); |
700 | break; | 700 | break; |
701 | } | 701 | } |
702 | case OP_CLOSE: { | 702 | case OP_CLOSE: { |