diff options
Diffstat (limited to 'lvm.c')
-rw-r--r-- | lvm.c | 27 |
1 files changed, 21 insertions, 6 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lvm.c,v 1.178 2001/04/06 18:25:00 roberto Exp roberto $ | 2 | ** $Id: lvm.c,v 1.179 2001/06/05 18:17:01 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 | */ |
@@ -28,6 +28,16 @@ | |||
28 | 28 | ||
29 | 29 | ||
30 | 30 | ||
31 | static void luaV_checkGC (lua_State *L, StkId top) { | ||
32 | if (G(L)->nblocks >= G(L)->GCthreshold) { | ||
33 | StkId temp = L->top; | ||
34 | L->top = top; | ||
35 | luaC_collectgarbage(L); | ||
36 | L->top = temp; /* restore old top position */ | ||
37 | } | ||
38 | } | ||
39 | |||
40 | |||
31 | const TObject *luaV_tonumber (const TObject *obj, TObject *n) { | 41 | const TObject *luaV_tonumber (const TObject *obj, TObject *n) { |
32 | if (ttype(obj) == LUA_TNUMBER) return obj; | 42 | if (ttype(obj) == LUA_TNUMBER) return obj; |
33 | if (ttype(obj) == LUA_TSTRING && luaO_str2d(svalue(obj), &nvalue(n))) { | 43 | if (ttype(obj) == LUA_TSTRING && luaO_str2d(svalue(obj), &nvalue(n))) { |
@@ -262,6 +272,7 @@ int luaV_lessthan (lua_State *L, const TObject *l, const TObject *r) { | |||
262 | 272 | ||
263 | 273 | ||
264 | void luaV_strconc (lua_State *L, int total, StkId top) { | 274 | void luaV_strconc (lua_State *L, int total, StkId top) { |
275 | luaV_checkGC(L, top); | ||
265 | do { | 276 | do { |
266 | int n = 2; /* number of elements handled in this pass (at least 2) */ | 277 | int n = 2; /* number of elements handled in this pass (at least 2) */ |
267 | if (tostring(L, top-2) || tostring(L, top-1)) { | 278 | if (tostring(L, top-2) || tostring(L, top-1)) { |
@@ -353,7 +364,11 @@ StkId luaV_execute (lua_State *L, const Closure *cl, StkId base) { | |||
353 | lua_Hook linehook; | 364 | lua_Hook linehook; |
354 | if (tf->is_vararg) /* varargs? */ | 365 | if (tf->is_vararg) /* varargs? */ |
355 | adjust_varargs(L, base, tf->numparams); | 366 | adjust_varargs(L, base, tf->numparams); |
356 | luaD_adjusttop(L, base, tf->maxstacksize); | 367 | if (base > L->stack_last - tf->maxstacksize) |
368 | luaD_stackerror(L); | ||
369 | while (L->top < base+tf->maxstacksize) | ||
370 | setnilvalue(L->top++); | ||
371 | L->top = base+tf->maxstacksize; | ||
357 | pc = tf->code; | 372 | pc = tf->code; |
358 | L->ci->pc = &pc; | 373 | L->ci->pc = &pc; |
359 | linehook = L->linehook; | 374 | linehook = L->linehook; |
@@ -406,8 +421,9 @@ StkId luaV_execute (lua_State *L, const Closure *cl, StkId base) { | |||
406 | break; | 421 | break; |
407 | } | 422 | } |
408 | case OP_NEWTABLE: { | 423 | case OP_NEWTABLE: { |
409 | luaC_checkGC(L); | 424 | StkId ra = RA(i); |
410 | sethvalue(RA(i), luaH_new(L, GETARG_Bc(i))); | 425 | sethvalue(ra, luaH_new(L, GETARG_Bc(i))); |
426 | luaV_checkGC(L, ra+1); | ||
411 | break; | 427 | break; |
412 | } | 428 | } |
413 | case OP_SELF: { | 429 | case OP_SELF: { |
@@ -463,7 +479,6 @@ StkId luaV_execute (lua_State *L, const Closure *cl, StkId base) { | |||
463 | StkId rb = RB(i); | 479 | StkId rb = RB(i); |
464 | luaV_strconc(L, top-rb, top); | 480 | luaV_strconc(L, top-rb, top); |
465 | setobj(RA(i), rb); | 481 | setobj(RA(i), rb); |
466 | luaC_checkGC(L); | ||
467 | break; | 482 | break; |
468 | } | 483 | } |
469 | case OP_CJMP: | 484 | case OP_CJMP: |
@@ -630,10 +645,10 @@ StkId luaV_execute (lua_State *L, const Closure *cl, StkId base) { | |||
630 | Proto *p = tf->kproto[GETARG_Bc(i)]; | 645 | Proto *p = tf->kproto[GETARG_Bc(i)]; |
631 | int nup = p->nupvalues; | 646 | int nup = p->nupvalues; |
632 | StkId ra = RA(i); | 647 | StkId ra = RA(i); |
648 | luaV_checkGC(L, ra+nup); | ||
633 | L->top = ra+nup; | 649 | L->top = ra+nup; |
634 | luaV_Lclosure(L, p, nup); | 650 | luaV_Lclosure(L, p, nup); |
635 | L->top = base+tf->maxstacksize; | 651 | L->top = base+tf->maxstacksize; |
636 | luaC_checkGC(L); | ||
637 | break; | 652 | break; |
638 | } | 653 | } |
639 | } | 654 | } |