History

Lua 5.0.1

Lua Team committed 22 years ago

Commit a985bf41 parent 488a64b15 files · +822 −155Browse files

Showing the changes to src (9 of 15 files). Show all

Unified · Split

9 files
  1. src/ldo.c +19 −6
  2. src/lgc.c +14 −9
  3. src/lgc.h +2 −2
  4. src/lib/lbaselib.c +2 −2
  5. src/lib/liolib.c +3 −3
  6. src/lparser.c +7 −3
  7. src/luac/Makefile +1 −1
  8. src/luac/luac.c +3 −1
  9. src/lvm.c +4 −6
src/ldo.c+19−6
@@ -1,5 +1,5 @@
1/*1/*
2** $Id: ldo.c,v 1.217 2003/04/03 13:35:34 roberto Exp $2** $Id: ldo.c,v 1.217a 2003/04/03 13:35:34 roberto Exp $
3** Stack and Call structure of Lua3** Stack and Call structure of Lua
4** See Copyright Notice in lua.h4** See Copyright Notice in lua.h
5*/5*/
@@ -322,11 +322,11 @@ static void resume (lua_State *L, void *ud) { · 316 unmodified lines
322 int nargs = *cast(int *, ud);322 int nargs = *cast(int *, ud);
323 CallInfo *ci = L->ci;323 CallInfo *ci = L->ci;
324 if (ci == L->base_ci) { /* no activation record? */324 if (ci == L->base_ci) { /* no activation record? */
325 if (nargs >= L->top - L->base)325 lua_assert(nargs < L->top - L->base);
326 luaG_runerror(L, "cannot resume dead coroutine");
327 luaD_precall(L, L->top - (nargs + 1)); /* start coroutine */326 luaD_precall(L, L->top - (nargs + 1)); /* start coroutine */
328 }327 }
329 else if (ci->state & CI_YIELD) { /* inside a yield? */328 else { /* inside a yield */
329 lua_assert(ci->state & CI_YIELD);
330 if (ci->state & CI_C) { /* `common' yield? */330 if (ci->state & CI_C) { /* `common' yield? */
331 /* finish interrupted execution of `OP_CALL' */331 /* finish interrupted execution of `OP_CALL' */
332 int nresults;332 int nresults;
@@ -341,18 +341,31 @@ static void resume (lua_State *L, void *ud) { · 8 unmodified lines
341 ci->state &= ~CI_YIELD;341 ci->state &= ~CI_YIELD;
342 }342 }
343 }343 }
344 else
345 luaG_runerror(L, "cannot resume non-suspended coroutine");
346 firstResult = luaV_execute(L);344 firstResult = luaV_execute(L);
347 if (firstResult != NULL) /* return? */345 if (firstResult != NULL) /* return? */
348 luaD_poscall(L, LUA_MULTRET, firstResult); /* finalize this coroutine */346 luaD_poscall(L, LUA_MULTRET, firstResult); /* finalize this coroutine */
349}347}
350 348
351 349
350static int resume_error (lua_State *L, const char *msg) {
351 L->top = L->ci->base;
352 setsvalue2s(L->top, luaS_new(L, msg));
353 incr_top(L);
354 lua_unlock(L);
355 return LUA_ERRRUN;
356}
357
358
352LUA_API int lua_resume (lua_State *L, int nargs) {359LUA_API int lua_resume (lua_State *L, int nargs) {
353 int status;360 int status;
354 lu_byte old_allowhooks;361 lu_byte old_allowhooks;
355 lua_lock(L);362 lua_lock(L);
363 if (L->ci == L->base_ci) {
364 if (nargs >= L->top - L->base)
365 return resume_error(L, "cannot resume dead coroutine");
366 }
367 else if (!(L->ci->state & CI_YIELD)) /* not inside a yield? */
368 return resume_error(L, "cannot resume non-suspended coroutine");
356 old_allowhooks = L->allowhook;369 old_allowhooks = L->allowhook;
357 lua_assert(L->errfunc == 0 && L->nCcalls == 0);370 lua_assert(L->errfunc == 0 && L->nCcalls == 0);
358 status = luaD_rawrunprotected(L, resume, &nargs);371 status = luaD_rawrunprotected(L, resume, &nargs);
src/lgc.c+14−9
@@ -1,5 +1,5 @@
1/*1/*
2** $Id: lgc.c,v 1.171 2003/04/03 13:35:34 roberto Exp $2** $Id: lgc.c,v 1.171a 2003/04/03 13:35:34 roberto Exp $
3** Garbage Collector3** Garbage Collector
4** See Copyright Notice in lua.h4** See Copyright Notice in lua.h
5*/5*/
@@ -110,7 +110,8 @@ static void marktmu (GCState *st) { · 104 unmodified lines
110 110
111 111
112/* move `dead' udata that need finalization to list `tmudata' */112/* move `dead' udata that need finalization to list `tmudata' */
113void luaC_separateudata (lua_State *L) {113size_t luaC_separateudata (lua_State *L) {
114 size_t deadmem = 0;
114 GCObject **p = &G(L)->rootudata;115 GCObject **p = &G(L)->rootudata;
115 GCObject *curr;116 GCObject *curr;
116 GCObject *collected = NULL; /* to collect udata with gc event */117 GCObject *collected = NULL; /* to collect udata with gc event */
@@ -125,6 +126,7 @@ void luaC_separateudata (lua_State *L) { · 8 unmodified lines
125 p = &curr->gch.next;126 p = &curr->gch.next;
126 }127 }
127 else { /* must call its gc method */128 else { /* must call its gc method */
129 deadmem += sizeudata(gcotou(curr)->uv.len);
128 *p = curr->gch.next;130 *p = curr->gch.next;
129 curr->gch.next = NULL; /* link `curr' at the end of `collected' list */131 curr->gch.next = NULL; /* link `curr' at the end of `collected' list */
130 *lastcollected = curr;132 *lastcollected = curr;
@@ -134,6 +136,7 @@ void luaC_separateudata (lua_State *L) { · 3 unmodified lines
134 /* insert collected udata with gc event into `tmudata' list */136 /* insert collected udata with gc event into `tmudata' list */
135 *lastcollected = G(L)->tmudata;137 *lastcollected = G(L)->tmudata;
136 G(L)->tmudata = collected;138 G(L)->tmudata = collected;
139 return deadmem;
137}140}
138 141
139 142
@@ -244,7 +247,7 @@ static void traversestack (GCState *st, lua_State *L1) { · 104 unmodified lines
244 for (ci = L1->base_ci; ci <= L1->ci; ci++) {247 for (ci = L1->base_ci; ci <= L1->ci; ci++) {
245 lua_assert(ci->top <= L1->stack_last);248 lua_assert(ci->top <= L1->stack_last);
246 lua_assert(ci->state & (CI_C | CI_HASFRAME | CI_SAVEDPC));249 lua_assert(ci->state & (CI_C | CI_HASFRAME | CI_SAVEDPC));
247 if (!(ci->state & CI_C) && lim < ci->top)250 if (lim < ci->top)
248 lim = ci->top;251 lim = ci->top;
249 }252 }
250 for (o = L1->stack; o < L1->top; o++)253 for (o = L1->stack; o < L1->top; o++)
@@ -387,7 +390,7 @@ static void sweepstrings (lua_State *L, int all) { · 136 unmodified lines
387}390}
388 391
389 392
390static void checkSizes (lua_State *L) {393static void checkSizes (lua_State *L, size_t deadmem) {
391 /* check size of string hash */394 /* check size of string hash */
392 if (G(L)->strt.nuse < cast(ls_nstr, G(L)->strt.size/4) &&395 if (G(L)->strt.nuse < cast(ls_nstr, G(L)->strt.size/4) &&
393 G(L)->strt.size > MINSTRTABSIZE*2)396 G(L)->strt.size > MINSTRTABSIZE*2)
@@ -397,7 +400,7 @@ static void checkSizes (lua_State *L) { · 3 unmodified lines
397 size_t newsize = luaZ_sizebuffer(&G(L)->buff) / 2;400 size_t newsize = luaZ_sizebuffer(&G(L)->buff) / 2;
398 luaZ_resizebuffer(L, &G(L)->buff, newsize);401 luaZ_resizebuffer(L, &G(L)->buff, newsize);
399 }402 }
400 G(L)->GCthreshold = 2*G(L)->nblocks; /* new threshold */403 G(L)->GCthreshold = 2*G(L)->nblocks - deadmem; /* new threshold */
401}404}
402 405
403 406
@@ -451,7 +454,8 @@ static void markroot (GCState *st, lua_State *L) { · 47 unmodified lines
451}454}
452 455
453 456
454static void mark (lua_State *L) {457static size_t mark (lua_State *L) {
458 size_t deadmem;
455 GCState st;459 GCState st;
456 GCObject *wkv;460 GCObject *wkv;
457 st.g = G(L);461 st.g = G(L);
@@ -464,7 +468,7 @@ static void mark (lua_State *L) { · 6 unmodified lines
464 wkv = st.wkv; /* keys must be cleared after preserving udata */468 wkv = st.wkv; /* keys must be cleared after preserving udata */
465 st.wkv = NULL;469 st.wkv = NULL;
466 st.wv = NULL;470 st.wv = NULL;
467 luaC_separateudata(L); /* separate userdata to be preserved */471 deadmem = luaC_separateudata(L); /* separate userdata to be preserved */
468 marktmu(&st); /* mark `preserved' userdata */472 marktmu(&st); /* mark `preserved' userdata */
469 propagatemarks(&st); /* remark, to propagate `preserveness' */473 propagatemarks(&st); /* remark, to propagate `preserveness' */
470 cleartablekeys(wkv);474 cleartablekeys(wkv);
@@ -473,13 +477,14 @@ static void mark (lua_State *L) { · 2 unmodified lines
473 cleartablevalues(st.wv);477 cleartablevalues(st.wv);
474 cleartablekeys(st.wkv);478 cleartablekeys(st.wkv);
475 cleartablevalues(st.wkv);479 cleartablevalues(st.wkv);
480 return deadmem;
476}481}
477 482
478 483
479void luaC_collectgarbage (lua_State *L) {484void luaC_collectgarbage (lua_State *L) {
480 mark(L);485 size_t deadmem = mark(L);
481 luaC_sweep(L, 0);486 luaC_sweep(L, 0);
482 checkSizes(L);487 checkSizes(L, deadmem);
483 luaC_callGCTM(L);488 luaC_callGCTM(L);
484}489}
485 490
src/lgc.h+2−2
@@ -1,5 +1,5 @@
1/*1/*
2** $Id: lgc.h,v 1.19 2003/02/28 19:45:15 roberto Exp $2** $Id: lgc.h,v 1.19a 2003/02/28 19:45:15 roberto Exp $
3** Garbage Collector3** Garbage Collector
4** See Copyright Notice in lua.h4** See Copyright Notice in lua.h
5*/5*/
@@ -15,7 +15,7 @@ · 9 unmodified lines
15 if (G(L)->nblocks >= G(L)->GCthreshold) luaC_collectgarbage(L); }15 if (G(L)->nblocks >= G(L)->GCthreshold) luaC_collectgarbage(L); }
16 16
17 17
18void luaC_separateudata (lua_State *L);18size_t luaC_separateudata (lua_State *L);
19void luaC_callGCTM (lua_State *L);19void luaC_callGCTM (lua_State *L);
20void luaC_sweep (lua_State *L, int all);20void luaC_sweep (lua_State *L, int all);
21void luaC_collectgarbage (lua_State *L);21void luaC_collectgarbage (lua_State *L);
src/lib/lbaselib.c+2−2
@@ -1,5 +1,5 @@
1/*1/*
2** $Id: lbaselib.c,v 1.130 2003/04/03 13:35:34 roberto Exp $2** $Id: lbaselib.c,v 1.130a 2003/04/03 13:35:34 roberto Exp $
3** Basic library3** Basic library
4** See Copyright Notice in lua.h4** See Copyright Notice in lua.h
5*/5*/
@@ -324,7 +324,7 @@ static int luaB_xpcall (lua_State *L) { · 318 unmodified lines
324 324
325 325
326static int luaB_tostring (lua_State *L) {326static int luaB_tostring (lua_State *L) {
327 char buff[64];327 char buff[128];
328 luaL_checkany(L, 1);328 luaL_checkany(L, 1);
329 if (luaL_callmeta(L, 1, "__tostring")) /* is there a metafield? */329 if (luaL_callmeta(L, 1, "__tostring")) /* is there a metafield? */
330 return 1; /* use its value */330 return 1; /* use its value */
src/lib/liolib.c+3−3
@@ -1,5 +1,5 @@
1/*1/*
2** $Id: liolib.c,v 2.39 2003/03/19 21:16:12 roberto Exp $2** $Id: liolib.c,v 2.39a 2003/03/19 21:16:12 roberto Exp $
3** Standard I/O (and system) library3** Standard I/O (and system) library
4** See Copyright Notice in lua.h4** See Copyright Notice in lua.h
5*/5*/
@@ -158,7 +158,7 @@ static int aux_close (lua_State *L) { · 152 unmodified lines
158 158
159 159
160static int io_close (lua_State *L) {160static int io_close (lua_State *L) {
161 if (lua_isnone(L, 1)) {161 if (lua_isnone(L, 1) && lua_type(L, lua_upvalueindex(1)) == LUA_TTABLE) {
162 lua_pushstring(L, IO_OUTPUT);162 lua_pushstring(L, IO_OUTPUT);
163 lua_rawget(L, lua_upvalueindex(1));163 lua_rawget(L, lua_upvalueindex(1));
164 }164 }
@@ -175,7 +175,7 @@ static int io_gc (lua_State *L) { · 10 unmodified lines
175 175
176 176
177static int io_tostring (lua_State *L) {177static int io_tostring (lua_State *L) {
178 char buff[32];178 char buff[128];
179 FILE **f = topfile(L, 1);179 FILE **f = topfile(L, 1);
180 if (*f == NULL)180 if (*f == NULL)
181 strcpy(buff, "closed");181 strcpy(buff, "closed");
src/lparser.c+7−3
@@ -1,5 +1,5 @@
1/*1/*
2** $Id: lparser.c,v 1.208 2003/04/03 13:35:34 roberto Exp $2** $Id: lparser.c,v 1.208a 2003/04/03 13:35:34 roberto Exp $
3** Lua Parser3** Lua Parser
4** See Copyright Notice in lua.h4** See Copyright Notice in lua.h
5*/5*/
@@ -1141,11 +1141,15 @@ static void ifstat (LexState *ls, int line) { · 1135 unmodified lines
1141 1141
1142static void localfunc (LexState *ls) {1142static void localfunc (LexState *ls) {
1143 expdesc v, b;1143 expdesc v, b;
1144 FuncState *fs = ls->fs;
1144 new_localvar(ls, str_checkname(ls), 0);1145 new_localvar(ls, str_checkname(ls), 0);
1145 init_exp(&v, VLOCAL, ls->fs->freereg++);1146 init_exp(&v, VLOCAL, fs->freereg);
1147 luaK_reserveregs(fs, 1);
1146 adjustlocalvars(ls, 1);1148 adjustlocalvars(ls, 1);
1147 body(ls, &b, 0, ls->linenumber);1149 body(ls, &b, 0, ls->linenumber);
1148 luaK_storevar(ls->fs, &v, &b);1150 luaK_storevar(fs, &v, &b);
1151 /* debug information will only see the variable after this point! */
1152 getlocvar(fs, fs->nactvar - 1).startpc = fs->pc;
1149}1153}
1150 1154
1151 1155
src/luac/Makefile+1−1
@@ -13,7 +13,7 @@ T= $(BIN)/luac · 12 unmodified lines
13all: $T13all: $T
14 14
15$T: $(OBJS) $(LIB)/liblua.a $(LIB)/liblualib.a15$T: $(OBJS) $(LIB)/liblua.a $(LIB)/liblualib.a
16 $(CC) -o $@ $(MYLDFLAGS) $(OBJS) -L$(LIB) -llua -llualib $(EXTRA_LIBS)16 $(CC) -o $@ $(MYLDFLAGS) $(OBJS) -L$(LIB) -llua -llualib $(EXTRA_LIBS) $(DLLIB)
17 17
18# print.c needs opcode names from lopcodes.c18# print.c needs opcode names from lopcodes.c
19lopcodes.o: ../lopcodes.c ../lopcodes.h19lopcodes.o: ../lopcodes.c ../lopcodes.h
src/luac/luac.c+3−1
@@ -1,5 +1,5 @@
1/*1/*
2** $Id: luac.c,v 1.44 2003/04/07 20:34:20 lhf Exp $2** $Id: luac.c,v 1.44a 2003/04/07 20:34:20 lhf Exp $
3** Lua compiler (saves bytecodes to files; also list bytecodes)3** Lua compiler (saves bytecodes to files; also list bytecodes)
4** See Copyright Notice in lua.h4** See Copyright Notice in lua.h
5*/5*/
@@ -182,7 +182,9 @@ int main(int argc, char* argv[]) · 176 unmodified lines
182 FILE* D=fopen(output,"wb");182 FILE* D=fopen(output,"wb");
183 if (D==NULL) cannot(output,"open","out");183 if (D==NULL) cannot(output,"open","out");
184 if (stripping) strip(L,f);184 if (stripping) strip(L,f);
185 lua_lock(L);
185 luaU_dump(L,f,writer,D);186 luaU_dump(L,f,writer,D);
187 lua_unlock(L);
186 if (ferror(D)) cannot(output,"write","out");188 if (ferror(D)) cannot(output,"write","out");
187 fclose(D);189 fclose(D);
188 }190 }
src/lvm.c+4−6
@@ -1,5 +1,5 @@
1/*1/*
2** $Id: lvm.c,v 1.284 2003/04/03 13:35:34 roberto Exp $2** $Id: lvm.c,v 1.284a 2003/04/03 13:35:34 roberto Exp $
3** Lua virtual machine3** Lua virtual machine
4** See Copyright Notice in lua.h4** See Copyright Notice in lua.h
5*/5*/
@@ -66,7 +66,7 @@ int luaV_tostring (lua_State *L, StkId obj) { · 60 unmodified lines
66 66
67static void traceexec (lua_State *L) {67static void traceexec (lua_State *L) {
68 lu_byte mask = L->hookmask;68 lu_byte mask = L->hookmask;
69 if (mask > LUA_MASKLINE) { /* instruction-hook set? */69 if (mask & LUA_MASKCOUNT) { /* instruction-hook set? */
70 if (L->hookcount == 0) {70 if (L->hookcount == 0) {
71 resethookcount(L);71 resethookcount(L);
72 luaD_callhook(L, LUA_HOOKCOUNT, -1);72 luaD_callhook(L, LUA_HOOKCOUNT, -1);
@@ -399,10 +399,10 @@ StkId luaV_execute (lua_State *L) { · 326 unmodified lines
399 TObject *k;399 TObject *k;
400 const Instruction *pc;400 const Instruction *pc;
401 callentry: /* entry point when calling new functions */401 callentry: /* entry point when calling new functions */
402 L->ci->u.l.pc = &pc;
403 if (L->hookmask & LUA_MASKCALL)402 if (L->hookmask & LUA_MASKCALL)
404 luaD_callhook(L, LUA_HOOKCALL, -1);403 luaD_callhook(L, LUA_HOOKCALL, -1);
405 retentry: /* entry point when returning to old functions */404 retentry: /* entry point when returning to old functions */
405 L->ci->u.l.pc = &pc;
406 lua_assert(L->ci->state == CI_SAVEDPC ||406 lua_assert(L->ci->state == CI_SAVEDPC ||
407 L->ci->state == (CI_SAVEDPC | CI_CALLING));407 L->ci->state == (CI_SAVEDPC | CI_CALLING));
408 L->ci->state = CI_HASFRAME; /* activate frame */408 L->ci->state = CI_HASFRAME; /* activate frame */
@@ -673,9 +673,7 @@ StkId luaV_execute (lua_State *L) { · 264 unmodified lines
673 }673 }
674 else { /* yes: continue its execution */674 else { /* yes: continue its execution */
675 int nresults;675 int nresults;
676 lua_assert(ci->u.l.pc == &pc &&676 lua_assert(ttisfunction(ci->base - 1) && (ci->state & CI_SAVEDPC));
677 ttisfunction(ci->base - 1) &&
678 (ci->state & CI_SAVEDPC));
679 lua_assert(GET_OPCODE(*(ci->u.l.savedpc - 1)) == OP_CALL);677 lua_assert(GET_OPCODE(*(ci->u.l.savedpc - 1)) == OP_CALL);
680 nresults = GETARG_C(*(ci->u.l.savedpc - 1)) - 1;678 nresults = GETARG_C(*(ci->u.l.savedpc - 1)) - 1;
681 luaD_poscall(L, nresults, ra);679 luaD_poscall(L, nresults, ra);

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t