diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2001-06-05 16:41:24 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2001-06-05 16:41:24 -0300 |
commit | 943b8f5b1801c72fee8bf1050919cf1acb600555 (patch) | |
tree | 6bef02079082422a78a933230619867bbb2e00e7 | |
parent | 762d059a13d83eb367238a6115bbb4f5f13fcb49 (diff) | |
download | lua-943b8f5b1801c72fee8bf1050919cf1acb600555.tar.gz lua-943b8f5b1801c72fee8bf1050919cf1acb600555.tar.bz2 lua-943b8f5b1801c72fee8bf1050919cf1acb600555.zip |
details
-rw-r--r-- | ldo.c | 22 | ||||
-rw-r--r-- | ldo.h | 7 | ||||
-rw-r--r-- | lgc.c | 8 | ||||
-rw-r--r-- | lgc.h | 7 | ||||
-rw-r--r-- | lparser.c | 5 | ||||
-rw-r--r-- | lvm.c | 27 |
6 files changed, 44 insertions, 32 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: ldo.c,v 1.133 2001/04/06 19:26:06 roberto Exp roberto $ | 2 | ** $Id: ldo.c,v 1.134 2001/04/11 18:39:37 roberto Exp roberto $ |
3 | ** Stack and Call structure of Lua | 3 | ** Stack and Call structure of Lua |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -48,17 +48,15 @@ void luaD_init (lua_State *L, int stacksize) { | |||
48 | } | 48 | } |
49 | 49 | ||
50 | 50 | ||
51 | void luaD_checkstack (lua_State *L, int n) { | 51 | void luaD_stackerror (lua_State *L) { |
52 | if (L->stack_last - L->top <= n) { /* stack overflow? */ | 52 | if (L->stack_last == L->stack+L->stacksize-1) { |
53 | if (L->stack_last == L->stack+L->stacksize-1) { | 53 | /* overflow while handling overflow */ |
54 | /* overflow while handling overflow */ | 54 | luaD_breakrun(L, LUA_ERRERR); /* break run without error message */ |
55 | luaD_breakrun(L, LUA_ERRERR); /* break run without error message */ | 55 | } |
56 | } | 56 | else { |
57 | else { | 57 | L->stack_last += EXTRA_STACK; /* to be used by error message */ |
58 | L->stack_last += EXTRA_STACK; /* to be used by error message */ | 58 | lua_assert(L->stack_last == L->stack+L->stacksize-1); |
59 | lua_assert(L->stack_last == L->stack+L->stacksize-1); | 59 | luaD_error(L, l_s("stack overflow")); |
60 | luaD_error(L, l_s("stack overflow")); | ||
61 | } | ||
62 | } | 60 | } |
63 | } | 61 | } |
64 | 62 | ||
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: ldo.h,v 1.31 2001/02/23 17:17:25 roberto Exp roberto $ | 2 | ** $Id: ldo.h,v 1.32 2001/03/07 18:09:25 roberto Exp roberto $ |
3 | ** Stack and Call structure of Lua | 3 | ** Stack and Call structure of Lua |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -19,11 +19,14 @@ | |||
19 | #define incr_top {if (L->top == L->stack_last) luaD_checkstack(L, 1); L->top++;} | 19 | #define incr_top {if (L->top == L->stack_last) luaD_checkstack(L, 1); L->top++;} |
20 | 20 | ||
21 | 21 | ||
22 | #define luaD_checkstack(L,n) if (L->stack_last-(n)<=L->top) luaD_stackerror(L) | ||
23 | |||
24 | |||
22 | void luaD_init (lua_State *L, int stacksize); | 25 | void luaD_init (lua_State *L, int stacksize); |
23 | void luaD_adjusttop (lua_State *L, StkId base, int extra); | 26 | void luaD_adjusttop (lua_State *L, StkId base, int extra); |
24 | void luaD_lineHook (lua_State *L, int line, lua_Hook linehook); | 27 | void luaD_lineHook (lua_State *L, int line, lua_Hook linehook); |
25 | void luaD_call (lua_State *L, StkId func, int nResults); | 28 | void luaD_call (lua_State *L, StkId func, int nResults); |
26 | void luaD_checkstack (lua_State *L, int n); | 29 | void luaD_stackerror (lua_State *L); |
27 | 30 | ||
28 | void luaD_error (lua_State *L, const l_char *s); | 31 | void luaD_error (lua_State *L, const l_char *s); |
29 | void luaD_breakrun (lua_State *L, int errcode); | 32 | void luaD_breakrun (lua_State *L, int errcode); |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lgc.c,v 1.97 2001/04/17 17:35:54 roberto Exp roberto $ | 2 | ** $Id: lgc.c,v 1.98 2001/06/05 18:17:01 roberto Exp roberto $ |
3 | ** Garbage Collector | 3 | ** Garbage Collector |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -389,9 +389,3 @@ void luaC_collectgarbage (lua_State *L) { | |||
389 | callgcTM(L, &luaO_nilobject); | 389 | callgcTM(L, &luaO_nilobject); |
390 | } | 390 | } |
391 | 391 | ||
392 | |||
393 | void luaC_checkGC (lua_State *L) { | ||
394 | if (G(L)->nblocks >= G(L)->GCthreshold) | ||
395 | luaC_collectgarbage(L); | ||
396 | } | ||
397 | |||
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lgc.h,v 1.8 2000/10/02 14:47:43 roberto Exp roberto $ | 2 | ** $Id: lgc.h,v 1.9 2001/02/02 16:23:20 roberto Exp roberto $ |
3 | ** Garbage Collector | 3 | ** Garbage Collector |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -11,9 +11,12 @@ | |||
11 | #include "lobject.h" | 11 | #include "lobject.h" |
12 | 12 | ||
13 | 13 | ||
14 | #define luaC_checkGC(L) if (G(L)->nblocks >= G(L)->GCthreshold) \ | ||
15 | luaC_collectgarbage(L) | ||
16 | |||
17 | |||
14 | void luaC_collect (lua_State *L, int all); | 18 | void luaC_collect (lua_State *L, int all); |
15 | void luaC_collectgarbage (lua_State *L); | 19 | void luaC_collectgarbage (lua_State *L); |
16 | void luaC_checkGC (lua_State *L); | ||
17 | 20 | ||
18 | 21 | ||
19 | #endif | 22 | #endif |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lparser.c,v 1.142 2001/04/06 18:25:00 roberto Exp roberto $ | 2 | ** $Id: lparser.c,v 1.143 2001/06/05 18:17:01 roberto Exp roberto $ |
3 | ** LL(1) Parser and code generator for Lua | 3 | ** LL(1) Parser and code generator for Lua |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -495,7 +495,6 @@ static void recfield (LexState *ls, expdesc *t) { | |||
495 | static int recfields (LexState *ls, expdesc *t) { | 495 | static int recfields (LexState *ls, expdesc *t) { |
496 | /* recfields -> recfield { `,' recfield } [`,'] */ | 496 | /* recfields -> recfield { `,' recfield } [`,'] */ |
497 | int n = 1; /* at least one element */ | 497 | int n = 1; /* at least one element */ |
498 | luaK_exp2nextreg(ls->fs, t); | ||
499 | recfield(ls, t); | 498 | recfield(ls, t); |
500 | while (ls->t.token == l_c(',')) { | 499 | while (ls->t.token == l_c(',')) { |
501 | next(ls); | 500 | next(ls); |
@@ -513,7 +512,6 @@ static int listfields (LexState *ls, expdesc *t) { | |||
513 | FuncState *fs = ls->fs; | 512 | FuncState *fs = ls->fs; |
514 | int n = 1; /* at least one element */ | 513 | int n = 1; /* at least one element */ |
515 | int reg; | 514 | int reg; |
516 | luaK_exp2nextreg(ls->fs, t); | ||
517 | reg = fs->freereg; | 515 | reg = fs->freereg; |
518 | expr(ls, &v); | 516 | expr(ls, &v); |
519 | while (ls->t.token == l_c(',') && | 517 | while (ls->t.token == l_c(',') && |
@@ -578,6 +576,7 @@ static void constructor (LexState *ls, expdesc *t) { | |||
578 | Constdesc cd; | 576 | Constdesc cd; |
579 | pc = luaK_codeABc(fs, OP_NEWTABLE, 0, 0); | 577 | pc = luaK_codeABc(fs, OP_NEWTABLE, 0, 0); |
580 | init_exp(t, VRELOCABLE, pc); | 578 | init_exp(t, VRELOCABLE, pc); |
579 | luaK_exp2nextreg(ls->fs, t); /* fix it at stack top (for gc) */ | ||
581 | check(ls, l_c('{')); | 580 | check(ls, l_c('{')); |
582 | constructor_part(ls, t, &cd); | 581 | constructor_part(ls, t, &cd); |
583 | n = cd.n; | 582 | n = cd.n; |
@@ -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 | } |