diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1997-12-15 14:17:20 -0200 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1997-12-15 14:17:20 -0200 |
commit | 45e533599f08d849951b49bcab0be4fd735a966d (patch) | |
tree | b8e3b175989f694391dd3da4191894f5df1e7d75 /lvm.c | |
parent | 94144a7821c0fa412d5d228ab5197a8ebaaa3c25 (diff) | |
download | lua-45e533599f08d849951b49bcab0be4fd735a966d.tar.gz lua-45e533599f08d849951b49bcab0be4fd735a966d.tar.bz2 lua-45e533599f08d849951b49bcab0be4fd735a966d.zip |
optimization: closures without upvalues don't need to be closures
Diffstat (limited to 'lvm.c')
-rw-r--r-- | lvm.c | 28 |
1 files changed, 15 insertions, 13 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lvm.c,v 1.15 1997/11/21 19:00:46 roberto Exp roberto $ | 2 | ** $Id: lvm.c,v 1.16 1997/12/09 13:35:19 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 | */ |
@@ -79,13 +79,15 @@ int luaV_tostring (TObject *obj) | |||
79 | 79 | ||
80 | void luaV_closure (int nelems) | 80 | void luaV_closure (int nelems) |
81 | { | 81 | { |
82 | struct Stack *S = &L->stack; | 82 | if (nelems > 0) { |
83 | Closure *c = luaF_newclosure(nelems); | 83 | struct Stack *S = &L->stack; |
84 | c->consts[0] = *(S->top-1); | 84 | Closure *c = luaF_newclosure(nelems); |
85 | memcpy(&c->consts[1], S->top-(nelems+1), nelems*sizeof(TObject)); | 85 | c->consts[0] = *(S->top-1); |
86 | S->top -= nelems; | 86 | memcpy(&c->consts[1], S->top-(nelems+1), nelems*sizeof(TObject)); |
87 | ttype(S->top-1) = LUA_T_FUNCTION; | 87 | S->top -= nelems; |
88 | (S->top-1)->value.cl = c; | 88 | ttype(S->top-1) = LUA_T_CLOSURE; |
89 | (S->top-1)->value.cl = c; | ||
90 | } | ||
89 | } | 91 | } |
90 | 92 | ||
91 | 93 | ||
@@ -279,13 +281,13 @@ static void adjust_varargs (StkId first_extra_arg) | |||
279 | ** [stack+base,top). Returns n such that the the results are between | 281 | ** [stack+base,top). Returns n such that the the results are between |
280 | ** [stack+n,top). | 282 | ** [stack+n,top). |
281 | */ | 283 | */ |
282 | StkId luaV_execute (Closure *cl, StkId base) | 284 | StkId luaV_execute (Closure *cl, TProtoFunc *tf, StkId base) |
283 | { | 285 | { |
284 | struct Stack *S = &L->stack; /* to optimize */ | 286 | struct Stack *S = &L->stack; /* to optimize */ |
285 | Byte *pc = cl->consts[0].value.tf->code; | 287 | Byte *pc = tf->code; |
286 | TObject *consts = cl->consts[0].value.tf->consts; | 288 | TObject *consts = tf->consts; |
287 | if (lua_callhook) | 289 | if (lua_callhook) |
288 | luaD_callHook(base, LUA_T_PROTO, 0); | 290 | luaD_callHook(base, tf, 0); |
289 | luaD_checkstack((*pc++)+EXTRA_STACK); | 291 | luaD_checkstack((*pc++)+EXTRA_STACK); |
290 | while (1) { | 292 | while (1) { |
291 | int aux; | 293 | int aux; |
@@ -679,7 +681,7 @@ StkId luaV_execute (Closure *cl, StkId base) | |||
679 | /* goes through */ | 681 | /* goes through */ |
680 | case RETCODE: | 682 | case RETCODE: |
681 | if (lua_callhook) | 683 | if (lua_callhook) |
682 | luaD_callHook(base, LUA_T_PROTO, 1); | 684 | luaD_callHook(base, NULL, 1); |
683 | return (base + ((aux==RETCODE) ? *pc : 0)); | 685 | return (base + ((aux==RETCODE) ? *pc : 0)); |
684 | 686 | ||
685 | case SETLINEW: | 687 | case SETLINEW: |