diff options
Diffstat (limited to '')
| -rw-r--r-- | lapi.c | 18 | ||||
| -rw-r--r-- | ldo.c | 58 | ||||
| -rw-r--r-- | ldo.h | 5 | ||||
| -rw-r--r-- | lvm.c | 6 |
4 files changed, 36 insertions, 51 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lapi.c,v 1.45 1999/05/14 12:24:20 roberto Exp roberto $ | 2 | ** $Id: lapi.c,v 1.46 1999/06/17 17:04:03 roberto Exp roberto $ |
| 3 | ** Lua API | 3 | ** Lua API |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -131,7 +131,7 @@ int lua_callfunction (lua_Object function) | |||
| 131 | else { | 131 | else { |
| 132 | luaD_openstack((L->stack.top-L->stack.stack)-L->Cstack.base); | 132 | luaD_openstack((L->stack.top-L->stack.stack)-L->Cstack.base); |
| 133 | set_normalized(L->stack.stack+L->Cstack.base, Address(function)); | 133 | set_normalized(L->stack.stack+L->Cstack.base, Address(function)); |
| 134 | return luaD_protectedrun(MULT_RET); | 134 | return luaD_protectedrun(); |
| 135 | } | 135 | } |
| 136 | } | 136 | } |
| 137 | 137 | ||
| @@ -675,17 +675,15 @@ lua_Object lua_getref (int ref) { | |||
| 675 | ** API: set a function as a fallback | 675 | ** API: set a function as a fallback |
| 676 | */ | 676 | */ |
| 677 | 677 | ||
| 678 | static void do_unprotectedrun (lua_CFunction f, int nParams, int nResults) | 678 | static void do_unprotectedrun (lua_CFunction f, int nParams, int nResults) { |
| 679 | { | ||
| 680 | StkId base = (L->stack.top-L->stack.stack)-nParams; | ||
| 681 | luaD_openstack(nParams); | 679 | luaD_openstack(nParams); |
| 682 | L->stack.stack[base].ttype = LUA_T_CPROTO; | 680 | (L->stack.top-nParams)->ttype = LUA_T_CPROTO; |
| 683 | L->stack.stack[base].value.f = f; | 681 | (L->stack.top-nParams)->value.f = f; |
| 684 | luaD_call(base+1, nResults); | 682 | luaD_calln(nParams, nResults); |
| 685 | } | 683 | } |
| 686 | 684 | ||
| 687 | lua_Object lua_setfallback (char *name, lua_CFunction fallback) | 685 | |
| 688 | { | 686 | lua_Object lua_setfallback (char *name, lua_CFunction fallback) { |
| 689 | lua_pushstring(name); | 687 | lua_pushstring(name); |
| 690 | lua_pushcfunction(fallback); | 688 | lua_pushcfunction(fallback); |
| 691 | do_unprotectedrun(luaT_setfallback, 2, 1); | 689 | do_unprotectedrun(luaT_setfallback, 2, 1); |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: ldo.c,v 1.43 1999/05/24 17:53:03 roberto Exp roberto $ | 2 | ** $Id: ldo.c,v 1.44 1999/06/17 17:04:03 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 | */ |
| @@ -145,8 +145,7 @@ static StkId callC (lua_CFunction f, StkId base) { | |||
| 145 | } | 145 | } |
| 146 | 146 | ||
| 147 | 147 | ||
| 148 | static StkId callCclosure (struct Closure *cl, lua_CFunction f, StkId base) | 148 | static StkId callCclosure (struct Closure *cl, lua_CFunction f, StkId base) { |
| 149 | { | ||
| 150 | TObject *pbase; | 149 | TObject *pbase; |
| 151 | int nup = cl->nelems; /* number of upvalues */ | 150 | int nup = cl->nelems; /* number of upvalues */ |
| 152 | luaD_checkstack(nup); | 151 | luaD_checkstack(nup); |
| @@ -168,15 +167,17 @@ void luaD_callTM (TObject *f, int nParams, int nResults) { | |||
| 168 | 167 | ||
| 169 | 168 | ||
| 170 | /* | 169 | /* |
| 171 | ** Call a function (C or Lua). The parameters must be on the L->stack.stack, | 170 | ** Call a function (C or Lua). The parameters must be on the stack, |
| 172 | ** between [L->stack.stack+base,L->stack.top). The function to be called is at L->stack.stack+base-1. | 171 | ** between [top-nArgs,top). The function to be called is right below the |
| 173 | ** When returns, the results are on the L->stack.stack, between [L->stack.stack+base-1,L->stack.top). | 172 | ** arguments. |
| 173 | ** When returns, the results are on the stack, between [top-nArgs-1,top). | ||
| 174 | ** The number of results is nResults, unless nResults=MULT_RET. | 174 | ** The number of results is nResults, unless nResults=MULT_RET. |
| 175 | */ | 175 | */ |
| 176 | void luaD_call (StkId base, int nResults) | 176 | void luaD_calln (int nArgs, int nResults) { |
| 177 | { | 177 | struct Stack *S = &L->stack; /* to optimize */ |
| 178 | StkId base = (S->top-S->stack)-nArgs; | ||
| 179 | TObject *func = S->stack+base-1; | ||
| 178 | StkId firstResult; | 180 | StkId firstResult; |
| 179 | TObject *func = L->stack.stack+base-1; | ||
| 180 | int i; | 181 | int i; |
| 181 | switch (ttype(func)) { | 182 | switch (ttype(func)) { |
| 182 | case LUA_T_CPROTO: | 183 | case LUA_T_CPROTO: |
| @@ -201,24 +202,20 @@ void luaD_call (StkId base, int nResults) | |||
| 201 | TObject *im = luaT_getimbyObj(func, IM_FUNCTION); | 202 | TObject *im = luaT_getimbyObj(func, IM_FUNCTION); |
| 202 | if (ttype(im) == LUA_T_NIL) | 203 | if (ttype(im) == LUA_T_NIL) |
| 203 | lua_error("call expression not a function"); | 204 | lua_error("call expression not a function"); |
| 204 | luaD_callTM(im, (L->stack.top-L->stack.stack)-(base-1), nResults); | 205 | luaD_callTM(im, (S->top-S->stack)-(base-1), nResults); |
| 205 | return; | 206 | return; |
| 206 | } | 207 | } |
| 207 | } | 208 | } |
| 208 | /* adjust the number of results */ | 209 | /* adjust the number of results */ |
| 209 | if (nResults != MULT_RET) | 210 | if (nResults == MULT_RET) |
| 211 | nResults = (S->top-S->stack)-firstResult; | ||
| 212 | else | ||
| 210 | luaD_adjusttop(firstResult+nResults); | 213 | luaD_adjusttop(firstResult+nResults); |
| 211 | /* move results to base-1 (to erase parameters and function) */ | 214 | /* move results to base-1 (to erase parameters and function) */ |
| 212 | base--; | 215 | base--; |
| 213 | nResults = L->stack.top - (L->stack.stack+firstResult); /* actual number of results */ | ||
| 214 | for (i=0; i<nResults; i++) | 216 | for (i=0; i<nResults; i++) |
| 215 | *(L->stack.stack+base+i) = *(L->stack.stack+firstResult+i); | 217 | *(S->stack+base+i) = *(S->stack+firstResult+i); |
| 216 | L->stack.top -= firstResult-base; | 218 | S->top -= firstResult-base; |
| 217 | } | ||
| 218 | |||
| 219 | |||
| 220 | void luaD_calln (int nArgs, int nResults) { | ||
| 221 | luaD_call((L->stack.top-L->stack.stack)-nArgs, nResults); | ||
| 222 | } | 219 | } |
| 223 | 220 | ||
| 224 | 221 | ||
| @@ -258,32 +255,23 @@ void lua_error (char *s) { | |||
| 258 | } | 255 | } |
| 259 | } | 256 | } |
| 260 | 257 | ||
| 261 | /* | ||
| 262 | ** Call the function at L->Cstack.base, and incorporate results on | ||
| 263 | ** the Lua2C structure. | ||
| 264 | */ | ||
| 265 | static void do_callinc (int nResults) | ||
| 266 | { | ||
| 267 | StkId base = L->Cstack.base; | ||
| 268 | luaD_call(base+1, nResults); | ||
| 269 | L->Cstack.lua2C = base; /* position of the new results */ | ||
| 270 | L->Cstack.num = (L->stack.top-L->stack.stack) - base; /* number of results */ | ||
| 271 | L->Cstack.base = base + L->Cstack.num; /* incorporate results on stack */ | ||
| 272 | } | ||
| 273 | |||
| 274 | 258 | ||
| 275 | /* | 259 | /* |
| 276 | ** Execute a protected call. Assumes that function is at L->Cstack.base and | 260 | ** Execute a protected call. Assumes that function is at L->Cstack.base and |
| 277 | ** parameters are on top of it. Leave nResults on the stack. | 261 | ** parameters are on top of it. Leave nResults on the stack. |
| 278 | */ | 262 | */ |
| 279 | int luaD_protectedrun (int nResults) { | 263 | int luaD_protectedrun (void) { |
| 280 | volatile struct C_Lua_Stack oldCLS = L->Cstack; | 264 | volatile struct C_Lua_Stack oldCLS = L->Cstack; |
| 281 | struct lua_longjmp myErrorJmp; | 265 | struct lua_longjmp myErrorJmp; |
| 282 | volatile int status; | 266 | volatile int status; |
| 283 | struct lua_longjmp *volatile oldErr = L->errorJmp; | 267 | struct lua_longjmp *volatile oldErr = L->errorJmp; |
| 284 | L->errorJmp = &myErrorJmp; | 268 | L->errorJmp = &myErrorJmp; |
| 285 | if (setjmp(myErrorJmp.b) == 0) { | 269 | if (setjmp(myErrorJmp.b) == 0) { |
| 286 | do_callinc(nResults); | 270 | StkId base = L->Cstack.base; |
| 271 | luaD_calln((L->stack.top-L->stack.stack)-base-1, MULT_RET); | ||
| 272 | L->Cstack.lua2C = base; /* position of the new results */ | ||
| 273 | L->Cstack.num = (L->stack.top-L->stack.stack) - base; | ||
| 274 | L->Cstack.base = base + L->Cstack.num; /* incorporate results on stack */ | ||
| 287 | status = 0; | 275 | status = 0; |
| 288 | } | 276 | } |
| 289 | else { /* an error occurred: restore L->Cstack and L->stack.top */ | 277 | else { /* an error occurred: restore L->Cstack and L->stack.top */ |
| @@ -338,7 +326,7 @@ static int do_main (ZIO *z, int bin) { | |||
| 338 | else { | 326 | else { |
| 339 | unsigned long newelems2 = 2*(L->nblocks-old_blocks); | 327 | unsigned long newelems2 = 2*(L->nblocks-old_blocks); |
| 340 | L->GCthreshold += newelems2; | 328 | L->GCthreshold += newelems2; |
| 341 | status = luaD_protectedrun(MULT_RET); | 329 | status = luaD_protectedrun(); |
| 342 | L->GCthreshold -= newelems2; | 330 | L->GCthreshold -= newelems2; |
| 343 | } | 331 | } |
| 344 | } while (bin && status == 0); | 332 | } while (bin && status == 0); |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: ldo.h,v 1.4 1997/12/15 16:17:20 roberto Exp roberto $ | 2 | ** $Id: ldo.h,v 1.5 1998/07/12 16:14:34 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 | */ |
| @@ -35,10 +35,9 @@ void luaD_adjusttop (StkId newtop); | |||
| 35 | void luaD_openstack (int nelems); | 35 | void luaD_openstack (int nelems); |
| 36 | void luaD_lineHook (int line); | 36 | void luaD_lineHook (int line); |
| 37 | void luaD_callHook (StkId base, TProtoFunc *tf, int isreturn); | 37 | void luaD_callHook (StkId base, TProtoFunc *tf, int isreturn); |
| 38 | void luaD_call (StkId base, int nResults); | ||
| 39 | void luaD_calln (int nArgs, int nResults); | 38 | void luaD_calln (int nArgs, int nResults); |
| 40 | void luaD_callTM (TObject *f, int nParams, int nResults); | 39 | void luaD_callTM (TObject *f, int nParams, int nResults); |
| 41 | int luaD_protectedrun (int nResults); | 40 | int luaD_protectedrun (void); |
| 42 | void luaD_gcIM (TObject *o); | 41 | void luaD_gcIM (TObject *o); |
| 43 | void luaD_travstack (int (*fn)(TObject *)); | 42 | void luaD_travstack (int (*fn)(TObject *)); |
| 44 | void luaD_checkstack (int n); | 43 | void luaD_checkstack (int n); |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lvm.c,v 1.56 1999/05/21 17:23:15 roberto Exp roberto $ | 2 | ** $Id: lvm.c,v 1.57 1999/05/21 19:41:49 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 | */ |
| @@ -342,11 +342,11 @@ StkId luaV_execute (Closure *cl, TProtoFunc *tf, StkId base) { | |||
| 342 | goto ret; | 342 | goto ret; |
| 343 | 343 | ||
| 344 | case CALL: aux = *pc++; | 344 | case CALL: aux = *pc++; |
| 345 | luaD_call((S->top-S->stack)-(*pc++), aux); | 345 | luaD_calln(*pc++, aux); |
| 346 | break; | 346 | break; |
| 347 | 347 | ||
| 348 | case TAILCALL: aux = *pc++; | 348 | case TAILCALL: aux = *pc++; |
| 349 | luaD_call((S->top-S->stack)-(*pc++), MULT_RET); | 349 | luaD_calln(*pc++, MULT_RET); |
| 350 | base += aux; | 350 | base += aux; |
| 351 | goto ret; | 351 | goto ret; |
| 352 | 352 | ||
