diff options
Diffstat (limited to 'lib/lua/includes')
-rw-r--r-- | lib/lua/includes/lapi.h | 4 | ||||
-rw-r--r-- | lib/lua/includes/lcode.h | 68 | ||||
-rw-r--r-- | lib/lua/includes/ldebug.h | 22 | ||||
-rw-r--r-- | lib/lua/includes/ldo.h | 51 | ||||
-rw-r--r-- | lib/lua/includes/lfunc.h | 30 | ||||
-rw-r--r-- | lib/lua/includes/lgc.h | 101 | ||||
-rw-r--r-- | lib/lua/includes/llex.h | 28 | ||||
-rw-r--r-- | lib/lua/includes/llimits.h | 144 | ||||
-rw-r--r-- | lib/lua/includes/lmem.h | 39 | ||||
-rw-r--r-- | lib/lua/includes/lobject.h | 191 | ||||
-rw-r--r-- | lib/lua/includes/lopcodes.h | 124 | ||||
-rw-r--r-- | lib/lua/includes/lparser.h | 29 | ||||
-rw-r--r-- | lib/lua/includes/lstate.h | 135 | ||||
-rw-r--r-- | lib/lua/includes/lstring.h | 18 | ||||
-rw-r--r-- | lib/lua/includes/ltable.h | 33 | ||||
-rw-r--r-- | lib/lua/includes/ltm.h | 17 | ||||
-rw-r--r-- | lib/lua/includes/lundump.h | 28 | ||||
-rw-r--r-- | lib/lua/includes/lvm.h | 21 | ||||
-rw-r--r-- | lib/lua/includes/lzio.h | 37 |
19 files changed, 618 insertions, 502 deletions
diff --git a/lib/lua/includes/lapi.h b/lib/lua/includes/lapi.h index 44445f7..c09c0b7 100644 --- a/lib/lua/includes/lapi.h +++ b/lib/lua/includes/lapi.h @@ -1,5 +1,5 @@ /* -** $Id: lapi.h,v 1.4 2004-11-27 21:46:06 pixel Exp $ +** $Id: lapi.h,v 1.5 2007-07-27 10:05:53 pixel Exp $ ** Auxiliary functions from Lua API ** See Copyright Notice in lua.h */ @@ -11,6 +11,6 @@ #include "lobject.h" -void luaA_pushobject (lua_State *L, const TObject *o); +LUAI_FUNC void luaA_pushobject (lua_State *L, const TValue *o); #endif diff --git a/lib/lua/includes/lcode.h b/lib/lua/includes/lcode.h index 0ba20f6..ad90c41 100644 --- a/lib/lua/includes/lcode.h +++ b/lib/lua/includes/lcode.h @@ -1,5 +1,5 @@ /* -** $Id: lcode.h,v 1.4 2004-11-27 21:46:06 pixel Exp $ +** $Id: lcode.h,v 1.5 2007-07-27 10:05:53 pixel Exp $ ** Code generator for Lua ** See Copyright Notice in lua.h */ @@ -24,7 +24,7 @@ ** grep "ORDER OPR" if you change these enums */ typedef enum BinOpr { - OPR_ADD, OPR_SUB, OPR_MULT, OPR_DIV, OPR_POW, + OPR_ADD, OPR_SUB, OPR_MUL, OPR_DIV, OPR_MOD, OPR_POW, OPR_CONCAT, OPR_NE, OPR_EQ, OPR_LT, OPR_LE, OPR_GT, OPR_GE, @@ -32,43 +32,45 @@ typedef enum BinOpr { OPR_NOBINOPR } BinOpr; -#define binopistest(op) ((op) >= OPR_NE) -typedef enum UnOpr { OPR_MINUS, OPR_NOT, OPR_NOUNOPR } UnOpr; +typedef enum UnOpr { OPR_MINUS, OPR_NOT, OPR_LEN, OPR_NOUNOPR } UnOpr; -#define getcode(fs,e) ((fs)->f->code[(e)->info]) +#define getcode(fs,e) ((fs)->f->code[(e)->u.s.info]) #define luaK_codeAsBx(fs,o,A,sBx) luaK_codeABx(fs,o,A,(sBx)+MAXARG_sBx) -int luaK_code (FuncState *fs, Instruction i, int line); -int luaK_codeABx (FuncState *fs, OpCode o, int A, unsigned int Bx); -int luaK_codeABC (FuncState *fs, OpCode o, int A, int B, int C); -void luaK_fixline (FuncState *fs, int line); -void luaK_nil (FuncState *fs, int from, int n); -void luaK_reserveregs (FuncState *fs, int n); -void luaK_checkstack (FuncState *fs, int n); -int luaK_stringK (FuncState *fs, TString *s); -int luaK_numberK (FuncState *fs, lua_Number r); -void luaK_dischargevars (FuncState *fs, expdesc *e); -int luaK_exp2anyreg (FuncState *fs, expdesc *e); -void luaK_exp2nextreg (FuncState *fs, expdesc *e); -void luaK_exp2val (FuncState *fs, expdesc *e); -int luaK_exp2RK (FuncState *fs, expdesc *e); -void luaK_self (FuncState *fs, expdesc *e, expdesc *key); -void luaK_indexed (FuncState *fs, expdesc *t, expdesc *k); -void luaK_goiftrue (FuncState *fs, expdesc *e); -void luaK_goiffalse (FuncState *fs, expdesc *e); -void luaK_storevar (FuncState *fs, expdesc *var, expdesc *e); -void luaK_setcallreturns (FuncState *fs, expdesc *var, int nresults); -int luaK_jump (FuncState *fs); -void luaK_patchlist (FuncState *fs, int list, int target); -void luaK_patchtohere (FuncState *fs, int list); -void luaK_concat (FuncState *fs, int *l1, int l2); -int luaK_getlabel (FuncState *fs); -void luaK_prefix (FuncState *fs, UnOpr op, expdesc *v); -void luaK_infix (FuncState *fs, BinOpr op, expdesc *v); -void luaK_posfix (FuncState *fs, BinOpr op, expdesc *v1, expdesc *v2); +#define luaK_setmultret(fs,e) luaK_setreturns(fs, e, LUA_MULTRET) + +LUAI_FUNC int luaK_codeABx (FuncState *fs, OpCode o, int A, unsigned int Bx); +LUAI_FUNC int luaK_codeABC (FuncState *fs, OpCode o, int A, int B, int C); +LUAI_FUNC void luaK_fixline (FuncState *fs, int line); +LUAI_FUNC void luaK_nil (FuncState *fs, int from, int n); +LUAI_FUNC void luaK_reserveregs (FuncState *fs, int n); +LUAI_FUNC void luaK_checkstack (FuncState *fs, int n); +LUAI_FUNC int luaK_stringK (FuncState *fs, TString *s); +LUAI_FUNC int luaK_numberK (FuncState *fs, lua_Number r); +LUAI_FUNC void luaK_dischargevars (FuncState *fs, expdesc *e); +LUAI_FUNC int luaK_exp2anyreg (FuncState *fs, expdesc *e); +LUAI_FUNC void luaK_exp2nextreg (FuncState *fs, expdesc *e); +LUAI_FUNC void luaK_exp2val (FuncState *fs, expdesc *e); +LUAI_FUNC int luaK_exp2RK (FuncState *fs, expdesc *e); +LUAI_FUNC void luaK_self (FuncState *fs, expdesc *e, expdesc *key); +LUAI_FUNC void luaK_indexed (FuncState *fs, expdesc *t, expdesc *k); +LUAI_FUNC void luaK_goiftrue (FuncState *fs, expdesc *e); +LUAI_FUNC void luaK_storevar (FuncState *fs, expdesc *var, expdesc *e); +LUAI_FUNC void luaK_setreturns (FuncState *fs, expdesc *e, int nresults); +LUAI_FUNC void luaK_setoneret (FuncState *fs, expdesc *e); +LUAI_FUNC int luaK_jump (FuncState *fs); +LUAI_FUNC void luaK_ret (FuncState *fs, int first, int nret); +LUAI_FUNC void luaK_patchlist (FuncState *fs, int list, int target); +LUAI_FUNC void luaK_patchtohere (FuncState *fs, int list); +LUAI_FUNC void luaK_concat (FuncState *fs, int *l1, int l2); +LUAI_FUNC int luaK_getlabel (FuncState *fs); +LUAI_FUNC void luaK_prefix (FuncState *fs, UnOpr op, expdesc *v); +LUAI_FUNC void luaK_infix (FuncState *fs, BinOpr op, expdesc *v); +LUAI_FUNC void luaK_posfix (FuncState *fs, BinOpr op, expdesc *v1, expdesc *v2); +LUAI_FUNC void luaK_setlist (FuncState *fs, int base, int nelems, int tostore); #endif diff --git a/lib/lua/includes/ldebug.h b/lib/lua/includes/ldebug.h index 9efa287..032711a 100644 --- a/lib/lua/includes/ldebug.h +++ b/lib/lua/includes/ldebug.h @@ -1,5 +1,5 @@ /* -** $Id: ldebug.h,v 1.4 2004-11-27 21:46:06 pixel Exp $ +** $Id: ldebug.h,v 1.5 2007-07-27 10:05:53 pixel Exp $ ** Auxiliary functions from Debug Interface module ** See Copyright Notice in lua.h */ @@ -18,14 +18,16 @@ #define resethookcount(L) (L->hookcount = L->basehookcount) -void luaG_inithooks (lua_State *L); -void luaG_typeerror (lua_State *L, const TObject *o, const char *opname); -void luaG_concaterror (lua_State *L, StkId p1, StkId p2); -void luaG_aritherror (lua_State *L, const TObject *p1, const TObject *p2); -int luaG_ordererror (lua_State *L, const TObject *p1, const TObject *p2); -void luaG_runerror (lua_State *L, const char *fmt, ...); -void luaG_errormsg (lua_State *L); -int luaG_checkcode (const Proto *pt); - +LUAI_FUNC void luaG_typeerror (lua_State *L, const TValue *o, + const char *opname); +LUAI_FUNC void luaG_concaterror (lua_State *L, StkId p1, StkId p2); +LUAI_FUNC void luaG_aritherror (lua_State *L, const TValue *p1, + const TValue *p2); +LUAI_FUNC int luaG_ordererror (lua_State *L, const TValue *p1, + const TValue *p2); +LUAI_FUNC void luaG_runerror (lua_State *L, const char *fmt, ...); +LUAI_FUNC void luaG_errormsg (lua_State *L); +LUAI_FUNC int luaG_checkcode (const Proto *pt); +LUAI_FUNC int luaG_checkopenop (Instruction i); #endif diff --git a/lib/lua/includes/ldo.h b/lib/lua/includes/ldo.h index 415da8c..d8a47bb 100644 --- a/lib/lua/includes/ldo.h +++ b/lib/lua/includes/ldo.h @@ -1,5 +1,5 @@ /* -** $Id: ldo.h,v 1.4 2004-11-27 21:46:06 pixel Exp $ +** $Id: ldo.h,v 1.5 2007-07-27 10:05:53 pixel Exp $ ** Stack and Call structure of Lua ** See Copyright Notice in lua.h */ @@ -13,48 +13,45 @@ #include "lzio.h" -/* -** macro to control inclusion of some hard tests on stack reallocation -*/ -#ifndef HARDSTACKTESTS -#define condhardstacktests(x) { /* empty */ } -#else -#define condhardstacktests(x) x -#endif - - #define luaD_checkstack(L,n) \ - if ((char *)L->stack_last - (char *)L->top <= (n)*(int)sizeof(TObject)) \ + if ((char *)L->stack_last - (char *)L->top <= (n)*(int)sizeof(TValue)) \ luaD_growstack(L, n); \ - else condhardstacktests(luaD_reallocstack(L, L->stacksize)); + else condhardstacktests(luaD_reallocstack(L, L->stacksize - EXTRA_STACK - 1)); #define incr_top(L) {luaD_checkstack(L,1); L->top++;} #define savestack(L,p) ((char *)(p) - (char *)L->stack) -#define restorestack(L,n) ((TObject *)((char *)L->stack + (n))) +#define restorestack(L,n) ((TValue *)((char *)L->stack + (n))) #define saveci(L,p) ((char *)(p) - (char *)L->base_ci) #define restoreci(L,n) ((CallInfo *)((char *)L->base_ci + (n))) +/* results from luaD_precall */ +#define PCRLUA 0 /* initiated a call to a Lua function */ +#define PCRC 1 /* did a call to a C function */ +#define PCRYIELD 2 /* C funtion yielded */ + + /* type of protected functions, to be ran by `runprotected' */ typedef void (*Pfunc) (lua_State *L, void *ud); -void luaD_resetprotection (lua_State *L); -int luaD_protectedparser (lua_State *L, ZIO *z, int bin); -void luaD_callhook (lua_State *L, int event, int line); -StkId luaD_precall (lua_State *L, StkId func); -void luaD_call (lua_State *L, StkId func, int nResults); -int luaD_pcall (lua_State *L, Pfunc func, void *u, - ptrdiff_t oldtop, ptrdiff_t ef); -void luaD_poscall (lua_State *L, int wanted, StkId firstResult); -void luaD_reallocCI (lua_State *L, int newsize); -void luaD_reallocstack (lua_State *L, int newsize); -void luaD_growstack (lua_State *L, int n); +LUAI_FUNC int luaD_protectedparser (lua_State *L, ZIO *z, const char *name); +LUAI_FUNC void luaD_callhook (lua_State *L, int event, int line); +LUAI_FUNC int luaD_precall (lua_State *L, StkId func, int nresults); +LUAI_FUNC void luaD_call (lua_State *L, StkId func, int nResults); +LUAI_FUNC int luaD_pcall (lua_State *L, Pfunc func, void *u, + ptrdiff_t oldtop, ptrdiff_t ef); +LUAI_FUNC int luaD_poscall (lua_State *L, StkId firstResult); +LUAI_FUNC void luaD_reallocCI (lua_State *L, int newsize); +LUAI_FUNC void luaD_reallocstack (lua_State *L, int newsize); +LUAI_FUNC void luaD_growstack (lua_State *L, int n); -void luaD_throw (lua_State *L, int errcode); -int luaD_rawrunprotected (lua_State *L, Pfunc f, void *ud); +LUAI_FUNC void luaD_throw (lua_State *L, int errcode); +LUAI_FUNC int luaD_rawrunprotected (lua_State *L, Pfunc f, void *ud); +LUAI_FUNC void luaD_seterrorobj (lua_State *L, int errcode, StkId oldtop); #endif + diff --git a/lib/lua/includes/lfunc.h b/lib/lua/includes/lfunc.h index df8f1c9..0f9de54 100644 --- a/lib/lua/includes/lfunc.h +++ b/lib/lua/includes/lfunc.h @@ -1,5 +1,5 @@ /* -** $Id: lfunc.h,v 1.5 2007-07-25 16:54:32 pixel Exp $ +** $Id: lfunc.h,v 1.6 2007-07-27 10:05:53 pixel Exp $ ** Auxiliary functions to manipulate prototypes and closures ** See Copyright Notice in lua.h */ @@ -12,21 +12,23 @@ #define sizeCclosure(n) (cast(int, sizeof(CClosure)) + \ - cast(int, sizeof(TObject)*((n)-1))) + cast(int, sizeof(TValue)*((n)-1))) #define sizeLclosure(n) (cast(int, sizeof(LClosure)) + \ - cast(int, sizeof(TObject *)*((n)-1))) - - -Proto *luaF_newproto (lua_State *L); -Closure *luaF_newCclosure (lua_State *L, int nelems); -Closure *luaF_newLclosure (lua_State *L, int nelems, TObject *e); -UpVal *luaF_findupval (lua_State *L, StkId level); -void luaF_close (lua_State *L, StkId level); -void luaF_freeproto (lua_State *L, Proto *f); -void luaF_freeclosure (lua_State *L, Closure *c); - -const char *luaF_getlocalname (const Proto *func, int local_number, int pc); + cast(int, sizeof(TValue *)*((n)-1))) + + +LUAI_FUNC Proto *luaF_newproto (lua_State *L); +LUAI_FUNC Closure *luaF_newCclosure (lua_State *L, int nelems, Table *e); +LUAI_FUNC Closure *luaF_newLclosure (lua_State *L, int nelems, Table *e); +LUAI_FUNC UpVal *luaF_newupval (lua_State *L); +LUAI_FUNC UpVal *luaF_findupval (lua_State *L, StkId level); +LUAI_FUNC void luaF_close (lua_State *L, StkId level); +LUAI_FUNC void luaF_freeproto (lua_State *L, Proto *f); +LUAI_FUNC void luaF_freeclosure (lua_State *L, Closure *c); +LUAI_FUNC void luaF_freeupval (lua_State *L, UpVal *uv); +LUAI_FUNC const char *luaF_getlocalname (const Proto *func, int local_number, + int pc); #endif diff --git a/lib/lua/includes/lgc.h b/lib/lua/includes/lgc.h index d3eb244..372b8b4 100644 --- a/lib/lua/includes/lgc.h +++ b/lib/lua/includes/lgc.h @@ -1,5 +1,5 @@ /* -** $Id: lgc.h,v 1.5 2004-12-27 19:52:23 pixel Exp $ +** $Id: lgc.h,v 1.6 2007-07-27 10:05:53 pixel Exp $ ** Garbage Collector ** See Copyright Notice in lua.h */ @@ -11,15 +11,100 @@ #include "lobject.h" -#define luaC_checkGC(L) { lua_assert(!(L->ci->state & CI_CALLING)); \ - if (G(L)->nblocks >= G(L)->GCthreshold) luaC_collectgarbage(L); } +/* +** Possible states of the Garbage Collector +*/ +#define GCSpause 0 +#define GCSpropagate 1 +#define GCSsweepstring 2 +#define GCSsweep 3 +#define GCSfinalize 4 + + +/* +** some userful bit tricks +*/ +#define resetbits(x,m) ((x) &= cast(lu_byte, ~(m))) +#define setbits(x,m) ((x) |= (m)) +#define testbits(x,m) ((x) & (m)) +#define bitmask(b) (1<<(b)) +#define bit2mask(b1,b2) (bitmask(b1) | bitmask(b2)) +#define l_setbit(x,b) setbits(x, bitmask(b)) +#define resetbit(x,b) resetbits(x, bitmask(b)) +#define testbit(x,b) testbits(x, bitmask(b)) +#define set2bits(x,b1,b2) setbits(x, (bit2mask(b1, b2))) +#define reset2bits(x,b1,b2) resetbits(x, (bit2mask(b1, b2))) +#define test2bits(x,b1,b2) testbits(x, (bit2mask(b1, b2))) + + + +/* +** Layout for bit use in `marked' field: +** bit 0 - object is white (type 0) +** bit 1 - object is white (type 1) +** bit 2 - object is black +** bit 3 - for userdata: has been finalized +** bit 3 - for tables: has weak keys +** bit 4 - for tables: has weak values +** bit 5 - object is fixed (should not be collected) +** bit 6 - object is "super" fixed (only the main thread) +*/ + + +#define WHITE0BIT 0 +#define WHITE1BIT 1 +#define BLACKBIT 2 +#define FINALIZEDBIT 3 +#define KEYWEAKBIT 3 +#define VALUEWEAKBIT 4 +#define FIXEDBIT 5 +#define SFIXEDBIT 6 +#define WHITEBITS bit2mask(WHITE0BIT, WHITE1BIT) + + +#define iswhite(x) test2bits((x)->gch.marked, WHITE0BIT, WHITE1BIT) +#define isblack(x) testbit((x)->gch.marked, BLACKBIT) +#define isgray(x) (!isblack(x) && !iswhite(x)) + +#define otherwhite(g) (g->currentwhite ^ WHITEBITS) +#define isdead(g,v) ((v)->gch.marked & otherwhite(g) & WHITEBITS) + +#define changewhite(x) ((x)->gch.marked ^= WHITEBITS) +#define gray2black(x) l_setbit((x)->gch.marked, BLACKBIT) + +#define valiswhite(x) (iscollectable(x) && iswhite(gcvalue(x))) + +#define luaC_white(g) cast(lu_byte, (g)->currentwhite & WHITEBITS) + + +#define luaC_checkGC(L) { \ + condhardstacktests(luaD_reallocstack(L, L->stacksize - EXTRA_STACK - 1)); \ + if (G(L)->totalbytes >= G(L)->GCthreshold) \ + luaC_step(L); } + + +#define luaC_barrier(L,p,v) { if (valiswhite(v) && isblack(obj2gco(p))) \ + luaC_barrierf(L,obj2gco(p),gcvalue(v)); } + +#define luaC_barriert(L,t,v) { if (valiswhite(v) && isblack(obj2gco(t))) \ + luaC_barrierback(L,t); } + +#define luaC_objbarrier(L,p,o) \ + { if (iswhite(obj2gco(o)) && isblack(obj2gco(p))) \ + luaC_barrierf(L,obj2gco(p),obj2gco(o)); } +#define luaC_objbarriert(L,t,o) \ + { if (iswhite(obj2gco(o)) && isblack(obj2gco(t))) luaC_barrierback(L,t); } -size_t luaC_separateudata (lua_State *L); -void luaC_callGCTM (lua_State *L); -void luaC_sweep (lua_State *L, int all); -void luaC_collectgarbage (lua_State *L); -void luaC_link (lua_State *L, GCObject *o, lu_byte tt); +LUAI_FUNC size_t luaC_separateudata (lua_State *L, int all); +LUAI_FUNC void luaC_callGCTM (lua_State *L); +LUAI_FUNC void luaC_freeall (lua_State *L); +LUAI_FUNC void luaC_step (lua_State *L); +LUAI_FUNC void luaC_fullgc (lua_State *L); +LUAI_FUNC void luaC_link (lua_State *L, GCObject *o, lu_byte tt); +LUAI_FUNC void luaC_linkupval (lua_State *L, UpVal *uv); +LUAI_FUNC void luaC_barrierf (lua_State *L, GCObject *o, GCObject *v); +LUAI_FUNC void luaC_barrierback (lua_State *L, Table *t); #endif diff --git a/lib/lua/includes/llex.h b/lib/lua/includes/llex.h index 805abc5..882163a 100644 --- a/lib/lua/includes/llex.h +++ b/lib/lua/includes/llex.h @@ -1,5 +1,5 @@ /* -** $Id: llex.h,v 1.4 2004-11-27 21:46:06 pixel Exp $ +** $Id: llex.h,v 1.5 2007-07-27 10:05:53 pixel Exp $ ** Lexical Analyzer ** See Copyright Notice in lua.h */ @@ -28,14 +28,18 @@ enum RESERVED { TK_IF, TK_IN, TK_LOCAL, TK_NIL, TK_NOT, TK_OR, TK_REPEAT, TK_RETURN, TK_THEN, TK_TRUE, TK_UNTIL, TK_WHILE, /* other terminal symbols */ - TK_NAME, TK_CONCAT, TK_DOTS, TK_EQ, TK_GE, TK_LE, TK_NE, TK_NUMBER, - TK_STRING, TK_EOS + TK_CONCAT, TK_DOTS, TK_EQ, TK_GE, TK_LE, TK_NE, TK_NUMBER, + TK_NAME, TK_STRING, TK_EOS }; /* number of reserved words */ #define NUM_RESERVED (cast(int, TK_WHILE-FIRST_RESERVED+1)) +/* array with token `names' */ +LUAI_DATA const char *const luaX_tokens []; + + typedef union { lua_Number r; TString *ts; @@ -59,17 +63,19 @@ typedef struct LexState { ZIO *z; /* input stream */ Mbuffer *buff; /* buffer for tokens */ TString *source; /* current source name */ - int nestlevel; /* level of nested non-terminals */ + char decpoint; /* locale decimal point */ } LexState; -void luaX_init (lua_State *L); -void luaX_setinput (lua_State *L, LexState *LS, ZIO *z, TString *source); -int luaX_lex (LexState *LS, SemInfo *seminfo); -void luaX_checklimit (LexState *ls, int val, int limit, const char *msg); -void luaX_syntaxerror (LexState *ls, const char *s); -void luaX_errorline (LexState *ls, const char *s, const char *token, int line); -const char *luaX_token2str (LexState *ls, int token); +LUAI_FUNC void luaX_init (lua_State *L); +LUAI_FUNC void luaX_setinput (lua_State *L, LexState *ls, ZIO *z, + TString *source); +LUAI_FUNC TString *luaX_newstring (LexState *ls, const char *str, size_t l); +LUAI_FUNC void luaX_next (LexState *ls); +LUAI_FUNC void luaX_lookahead (LexState *ls); +LUAI_FUNC void luaX_lexerror (LexState *ls, const char *msg, int token); +LUAI_FUNC void luaX_syntaxerror (LexState *ls, const char *s); +LUAI_FUNC const char *luaX_token2str (LexState *ls, int token); #endif diff --git a/lib/lua/includes/llimits.h b/lib/lua/includes/llimits.h index e5f18a9..9b48bcd 100644 --- a/lib/lua/includes/llimits.h +++ b/lib/lua/includes/llimits.h @@ -1,5 +1,5 @@ /* -** $Id: llimits.h,v 1.4 2004-11-27 21:46:06 pixel Exp $ +** $Id: llimits.h,v 1.5 2007-07-27 10:05:53 pixel Exp $ ** Limits, basic types, and some other `installation-dependent' definitions ** See Copyright Notice in lua.h */ @@ -15,45 +15,13 @@ #include "lua.h" -/* -** try to find number of bits in an integer -*/ -#ifndef BITS_INT -/* avoid overflows in comparison */ -#if INT_MAX-20 < 32760 -#define BITS_INT 16 -#else -#if INT_MAX > 2147483640L -/* machine has at least 32 bits */ -#define BITS_INT 32 -#else -#error "you must define BITS_INT with number of bits in an integer" -#endif -#endif -#endif +typedef LUAI_UINT32 lu_int32; +typedef LUAI_UMEM lu_mem; -/* -** the following types define integer types for values that may not -** fit in a `small int' (16 bits), but may waste space in a -** `large long' (64 bits). The current definitions should work in -** any machine, but may not be optimal. -*/ - -/* an unsigned integer to hold hash values */ -typedef unsigned int lu_hash; -/* its signed equivalent */ -typedef int ls_hash; +typedef LUAI_MEM l_mem; -/* an unsigned integer big enough to count the total memory used by Lua; */ -/* it should be at least as large as size_t */ -typedef unsigned long lu_mem; -#define MAX_LUMEM ULONG_MAX - - -/* an integer big enough to count the number of strings in use */ -typedef long ls_nstr; /* chars used as small naturals (so that `char' is reserved for characters) */ typedef unsigned char lu_byte; @@ -61,6 +29,8 @@ typedef unsigned char lu_byte; #define MAX_SIZET ((size_t)(~(size_t)0)-2) +#define MAX_LUMEM ((lu_mem)(~(lu_mem)0)-2) + #define MAX_INT (INT_MAX-2) /* maximum value of an int (-2 for safety) */ @@ -69,33 +39,30 @@ typedef unsigned char lu_byte; ** this is for hashing only; there is no problem if the integer ** cannot hold the whole pointer value */ -#define IntPoint(p) ((lu_hash)(p)) +#define IntPoint(p) ((unsigned int)(lu_mem)(p)) /* type to ensure maximum alignment */ -#ifndef LUSER_ALIGNMENT_T -typedef union { double u; void *s; long l; } L_Umaxalign; -#else -typedef LUSER_ALIGNMENT_T L_Umaxalign; -#endif +typedef LUAI_USER_ALIGNMENT_T L_Umaxalign; -/* result of `usual argument conversion' over lua_Number */ -#ifndef LUA_UACNUMBER -typedef double l_uacNumber; -#else -typedef LUA_UACNUMBER l_uacNumber; -#endif +/* result of a `usual argument conversion' over lua_Number */ +typedef LUAI_UACNUMBER l_uacNumber; -#ifndef lua_assert -#define lua_assert(c) /* empty */ -#endif +/* internal assertions for in-house debugging */ +#ifdef lua_assert + +#define check_exp(c,e) (lua_assert(c), (e)) +#define api_check(l,e) lua_assert(e) +#else + +#define lua_assert(c) ((void)0) +#define check_exp(c,e) (e) +#define api_check luai_apicheck -#ifndef check_exp -#define check_exp(c,e) (e) #endif @@ -108,58 +75,24 @@ typedef LUA_UACNUMBER l_uacNumber; #define cast(t, exp) ((t)(exp)) #endif +#define cast_byte(i) cast(lu_byte, (i)) +#define cast_num(i) cast(lua_Number, (i)) +#define cast_int(i) cast(int, (i)) + /* ** type for virtual-machine instructions ** must be an unsigned with (at least) 4 bytes (see details in lopcodes.h) */ -typedef unsigned long Instruction; - +typedef lu_int32 Instruction; -/* maximum depth for calls (unsigned short) */ -#ifndef LUA_MAXCALLS -#define LUA_MAXCALLS 4096 -#endif - - -/* -** maximum depth for C calls (unsigned short): Not too big, or may -** overflow the C stack... -*/ - -#ifndef LUA_MAXCCALLS -#define LUA_MAXCCALLS 200 -#endif - - -/* maximum size for the C stack */ -#ifndef LUA_MAXCSTACK -#define LUA_MAXCSTACK 2048 -#endif /* maximum stack for a Lua function */ #define MAXSTACK 250 -/* maximum number of variables declared in a function */ -#ifndef MAXVARS -#define MAXVARS 200 /* arbitrary limit (<MAXSTACK) */ -#endif - - -/* maximum number of upvalues per function */ -#ifndef MAXUPVALUES -#define MAXUPVALUES 32 -#endif - - -/* maximum number of parameters in a function */ -#ifndef MAXPARAMS -#define MAXPARAMS 100 /* arbitrary limit (<MAXLOCALS) */ -#endif - /* minimum size for the string table (must be power of 2) */ #ifndef MINSTRTABSIZE @@ -172,14 +105,29 @@ typedef unsigned long Instruction; #define LUA_MINBUFFER 32 #endif +void do_lua_lock(lua_State *); +void do_lua_unlock(lua_State *); -/* -** maximum number of syntactical nested non-terminals: Not too big, -** or may overflow the C stack... -*/ -#ifndef LUA_MAXPARSERLEVEL -#define LUA_MAXPARSERLEVEL 200 +#ifndef lua_lock +#define lua_lock(L) do_lua_lock(L); +#endif + +#ifndef lua_unlock +#define lua_unlock(L) do_lua_unlock(L); #endif +#ifndef luai_threadyield +#define luai_threadyield(L) {lua_unlock(L); lua_lock(L);} +#endif + + +/* +** macro to control inclusion of some hard tests on stack reallocation +*/ +#ifndef HARDSTACKTESTS +#define condhardstacktests(x) ((void)0) +#else +#define condhardstacktests(x) x +#endif #endif diff --git a/lib/lua/includes/lmem.h b/lib/lua/includes/lmem.h index 20bc584..4872cd1 100644 --- a/lib/lua/includes/lmem.h +++ b/lib/lua/includes/lmem.h @@ -1,5 +1,5 @@ /* -** $Id: lmem.h,v 1.4 2004-11-27 21:46:06 pixel Exp $ +** $Id: lmem.h,v 1.5 2007-07-27 10:05:53 pixel Exp $ ** Interface to Memory Manager ** See Copyright Notice in lua.h */ @@ -16,29 +16,34 @@ #define MEMERRMSG "not enough memory" -void *luaM_realloc (lua_State *L, void *oldblock, lu_mem oldsize, lu_mem size); +#define luaM_reallocv(L,b,on,n,e) \ + ((cast(size_t, (n)+1) <= MAX_SIZET/(e)) ? /* +1 to avoid warnings */ \ + luaM_realloc_(L, (b), (on)*(e), (n)*(e)) : \ + luaM_toobig(L)) -void *luaM_growaux (lua_State *L, void *block, int *size, int size_elem, - int limit, const char *errormsg); +#define luaM_freemem(L, b, s) luaM_realloc_(L, (b), (s), 0) +#define luaM_free(L, b) luaM_realloc_(L, (b), sizeof(*(b)), 0) +#define luaM_freearray(L, b, n, t) luaM_reallocv(L, (b), n, 0, sizeof(t)) -#define luaM_free(L, b, s) luaM_realloc(L, (b), (s), 0) -#define luaM_freelem(L, b) luaM_realloc(L, (b), sizeof(*(b)), 0) -#define luaM_freearray(L, b, n, t) luaM_realloc(L, (b), \ - cast(lu_mem, n)*cast(lu_mem, sizeof(t)), 0) - -#define luaM_malloc(L, t) luaM_realloc(L, NULL, 0, (t)) -#define luaM_new(L, t) cast(t *, luaM_malloc(L, sizeof(t))) -#define luaM_newvector(L, n,t) cast(t *, luaM_malloc(L, \ - cast(lu_mem, n)*cast(lu_mem, sizeof(t)))) +#define luaM_malloc(L,t) luaM_realloc_(L, NULL, 0, (t)) +#define luaM_new(L,t) cast(t *, luaM_malloc(L, sizeof(t))) +#define luaM_newvector(L,n,t) \ + cast(t *, luaM_reallocv(L, NULL, 0, n, sizeof(t))) #define luaM_growvector(L,v,nelems,size,t,limit,e) \ - if (((nelems)+1) > (size)) \ - ((v)=cast(t *, luaM_growaux(L,v,&(size),sizeof(t),limit,e))) + if ((nelems)+1 > (size)) \ + ((v)=cast(t *, luaM_growaux_(L,v,&(size),sizeof(t),limit,e))) #define luaM_reallocvector(L, v,oldn,n,t) \ - ((v)=cast(t *, luaM_realloc(L, v,cast(lu_mem, oldn)*cast(lu_mem, sizeof(t)), \ - cast(lu_mem, n)*cast(lu_mem, sizeof(t))))) + ((v)=cast(t *, luaM_reallocv(L, v, oldn, n, sizeof(t)))) + +LUAI_FUNC void *luaM_realloc_ (lua_State *L, void *block, size_t oldsize, + size_t size); +LUAI_FUNC void *luaM_toobig (lua_State *L); +LUAI_FUNC void *luaM_growaux_ (lua_State *L, void *block, int *size, + size_t size_elem, int limit, + const char *errormsg); #endif diff --git a/lib/lua/includes/lobject.h b/lib/lua/includes/lobject.h index 5bd6917..01c0db8 100644 --- a/lib/lua/includes/lobject.h +++ b/lib/lua/includes/lobject.h @@ -1,26 +1,33 @@ /* -** $Id: lobject.h,v 1.4 2004-11-27 21:46:06 pixel Exp $ +** $Id: lobject.h,v 1.5 2007-07-27 10:05:53 pixel Exp $ ** Type definitions for Lua objects ** See Copyright Notice in lua.h */ + #ifndef lobject_h #define lobject_h +#include <stdarg.h> + + #include "llimits.h" #include "lua.h" /* tags for values visible from Lua */ -#define NUM_TAGS LUA_TTHREAD +#define LAST_TAG LUA_TTHREAD + +#define NUM_TAGS (LAST_TAG+1) /* ** Extra tags for non-values */ -#define LUA_TPROTO (NUM_TAGS+1) -#define LUA_TUPVAL (NUM_TAGS+2) +#define LUA_TPROTO (LAST_TAG+1) +#define LUA_TUPVAL (LAST_TAG+2) +#define LUA_TDEADKEY (LAST_TAG+3) /* @@ -58,12 +65,14 @@ typedef union { /* -** Lua values (or `tagged objects') +** Tagged Values */ -typedef struct lua_TObject { - int tt; - Value value; -} TObject; + +#define TValuefields Value value; int tt + +typedef struct lua_TValue { + TValuefields; +} TValue; /* Macros to test type */ @@ -82,8 +91,10 @@ typedef struct lua_TObject { #define gcvalue(o) check_exp(iscollectable(o), (o)->value.gc) #define pvalue(o) check_exp(ttislightuserdata(o), (o)->value.p) #define nvalue(o) check_exp(ttisnumber(o), (o)->value.n) -#define tsvalue(o) check_exp(ttisstring(o), &(o)->value.gc->ts) -#define uvalue(o) check_exp(ttisuserdata(o), &(o)->value.gc->u) +#define rawtsvalue(o) check_exp(ttisstring(o), &(o)->value.gc->ts) +#define tsvalue(o) (&rawtsvalue(o)->tsv) +#define rawuvalue(o) check_exp(ttisuserdata(o), &(o)->value.gc->u) +#define uvalue(o) (&rawuvalue(o)->uv) #define clvalue(o) check_exp(ttisfunction(o), &(o)->value.gc->cl) #define hvalue(o) check_exp(ttistable(o), &(o)->value.gc->h) #define bvalue(o) check_exp(ttisboolean(o), (o)->value.b) @@ -91,59 +102,66 @@ typedef struct lua_TObject { #define l_isfalse(o) (ttisnil(o) || (ttisboolean(o) && bvalue(o) == 0)) +/* +** for internal debug only +*/ +#define checkconsistency(obj) \ + lua_assert(!iscollectable(obj) || (ttype(obj) == (obj)->value.gc->gch.tt)) + +#define checkliveness(g,obj) \ + lua_assert(!iscollectable(obj) || \ + ((ttype(obj) == (obj)->value.gc->gch.tt) && !isdead(g, (obj)->value.gc))) + + /* Macros to set values */ -#define setnvalue(obj,x) \ - { TObject *i_o=(obj); i_o->tt=LUA_TNUMBER; i_o->value.n=(x); } +#define setnilvalue(obj) ((obj)->tt=LUA_TNIL) -#define chgnvalue(obj,x) \ - check_exp(ttype(obj)==LUA_TNUMBER, (obj)->value.n=(x)) +#define setnvalue(obj,x) \ + { TValue *i_o=(obj); i_o->value.n=(x); i_o->tt=LUA_TNUMBER; } #define setpvalue(obj,x) \ - { TObject *i_o=(obj); i_o->tt=LUA_TLIGHTUSERDATA; i_o->value.p=(x); } + { TValue *i_o=(obj); i_o->value.p=(x); i_o->tt=LUA_TLIGHTUSERDATA; } #define setbvalue(obj,x) \ - { TObject *i_o=(obj); i_o->tt=LUA_TBOOLEAN; i_o->value.b=(x); } - -#define setsvalue(obj,x) \ - { TObject *i_o=(obj); i_o->tt=LUA_TSTRING; \ - i_o->value.gc=cast(GCObject *, (x)); \ - lua_assert(i_o->value.gc->gch.tt == LUA_TSTRING); } + { TValue *i_o=(obj); i_o->value.b=(x); i_o->tt=LUA_TBOOLEAN; } -#define setuvalue(obj,x) \ - { TObject *i_o=(obj); i_o->tt=LUA_TUSERDATA; \ - i_o->value.gc=cast(GCObject *, (x)); \ - lua_assert(i_o->value.gc->gch.tt == LUA_TUSERDATA); } +#define setsvalue(L,obj,x) \ + { TValue *i_o=(obj); \ + i_o->value.gc=cast(GCObject *, (x)); i_o->tt=LUA_TSTRING; \ + checkliveness(G(L),i_o); } -#define setthvalue(obj,x) \ - { TObject *i_o=(obj); i_o->tt=LUA_TTHREAD; \ - i_o->value.gc=cast(GCObject *, (x)); \ - lua_assert(i_o->value.gc->gch.tt == LUA_TTHREAD); } +#define setuvalue(L,obj,x) \ + { TValue *i_o=(obj); \ + i_o->value.gc=cast(GCObject *, (x)); i_o->tt=LUA_TUSERDATA; \ + checkliveness(G(L),i_o); } -#define setclvalue(obj,x) \ - { TObject *i_o=(obj); i_o->tt=LUA_TFUNCTION; \ - i_o->value.gc=cast(GCObject *, (x)); \ - lua_assert(i_o->value.gc->gch.tt == LUA_TFUNCTION); } +#define setthvalue(L,obj,x) \ + { TValue *i_o=(obj); \ + i_o->value.gc=cast(GCObject *, (x)); i_o->tt=LUA_TTHREAD; \ + checkliveness(G(L),i_o); } -#define sethvalue(obj,x) \ - { TObject *i_o=(obj); i_o->tt=LUA_TTABLE; \ - i_o->value.gc=cast(GCObject *, (x)); \ - lua_assert(i_o->value.gc->gch.tt == LUA_TTABLE); } +#define setclvalue(L,obj,x) \ + { TValue *i_o=(obj); \ + i_o->value.gc=cast(GCObject *, (x)); i_o->tt=LUA_TFUNCTION; \ + checkliveness(G(L),i_o); } -#define setnilvalue(obj) ((obj)->tt=LUA_TNIL) +#define sethvalue(L,obj,x) \ + { TValue *i_o=(obj); \ + i_o->value.gc=cast(GCObject *, (x)); i_o->tt=LUA_TTABLE; \ + checkliveness(G(L),i_o); } +#define setptvalue(L,obj,x) \ + { TValue *i_o=(obj); \ + i_o->value.gc=cast(GCObject *, (x)); i_o->tt=LUA_TPROTO; \ + checkliveness(G(L),i_o); } -/* -** for internal debug only -*/ -#define checkconsistency(obj) \ - lua_assert(!iscollectable(obj) || (ttype(obj) == (obj)->value.gc->gch.tt)) -#define setobj(obj1,obj2) \ - { const TObject *o2=(obj2); TObject *o1=(obj1); \ - checkconsistency(o2); \ - o1->tt=o2->tt; o1->value = o2->value; } +#define setobj(L,obj1,obj2) \ + { const TValue *o2=(obj2); TValue *o1=(obj1); \ + o1->value = o2->value; o1->tt=o2->tt; \ + checkliveness(G(L),o1); } /* @@ -155,6 +173,8 @@ typedef struct lua_TObject { /* to stack (not from same stack) */ #define setobj2s setobj #define setsvalue2s setsvalue +#define sethvalue2s sethvalue +#define setptvalue2s setptvalue /* from table to same table */ #define setobjt2t setobj /* to table */ @@ -170,7 +190,7 @@ typedef struct lua_TObject { -typedef TObject *StkId; /* index to stack elements */ +typedef TValue *StkId; /* index to stack elements */ /* @@ -181,7 +201,7 @@ typedef union TString { struct { CommonHeader; lu_byte reserved; - lu_hash hash; + unsigned int hash; size_t len; } tsv; } TString; @@ -197,6 +217,7 @@ typedef union Udata { struct { CommonHeader; struct Table *metatable; + struct Table *env; size_t len; } uv; } Udata; @@ -209,7 +230,7 @@ typedef union Udata { */ typedef struct Proto { CommonHeader; - TObject *k; /* constants used by the function */ + TValue *k; /* constants used by the function */ Instruction *code; struct Proto **p; /* functions defined inside the function */ int *lineinfo; /* map from opcodes to source lines */ @@ -222,7 +243,8 @@ typedef struct Proto { int sizelineinfo; int sizep; /* size of `p' */ int sizelocvars; - int lineDefined; + int linedefined; + int lastlinedefined; GCObject *gclist; lu_byte nups; /* number of upvalues */ lu_byte numparams; @@ -231,6 +253,12 @@ typedef struct Proto { } Proto; +/* masks for new-style vararg */ +#define VARARG_HASARG 1 +#define VARARG_ISVARARG 2 +#define VARARG_NEEDSARG 4 + + typedef struct LocVar { TString *varname; int startpc; /* first point where variable is active */ @@ -245,8 +273,14 @@ typedef struct LocVar { typedef struct UpVal { CommonHeader; - TObject *v; /* points to stack or to its own value */ - TObject value; /* the value (when closed) */ + TValue *v; /* points to stack or to its own value */ + union { + TValue value; /* the value (when closed) */ + struct { /* double linked list (when open) */ + struct UpVal *prev; + struct UpVal *next; + } l; + } u; } UpVal; @@ -255,19 +289,19 @@ typedef struct UpVal { */ #define ClosureHeader \ - CommonHeader; lu_byte isC; lu_byte nupvalues; GCObject *gclist + CommonHeader; lu_byte isC; lu_byte nupvalues; GCObject *gclist; \ + struct Table *env typedef struct CClosure { ClosureHeader; lua_CFunction f; - TObject upvalue[1]; + TValue upvalue[1]; } CClosure; typedef struct LClosure { ClosureHeader; struct Proto *p; - TObject g; /* global table for this closure */ UpVal *upvals[1]; } LClosure; @@ -286,10 +320,18 @@ typedef union Closure { ** Tables */ +typedef union TKey { + struct { + TValuefields; + struct Node *next; /* for chaining */ + } nk; + TValue tvk; +} TKey; + + typedef struct Node { - TObject i_key; - TObject i_val; - struct Node *next; /* for chaining */ + TValue i_val; + TKey i_key; } Node; @@ -298,9 +340,9 @@ typedef struct Table { lu_byte flags; /* 1<<p means tagmethod(p) is not present */ lu_byte lsizenode; /* log2 of size of `node' array */ struct Table *metatable; - TObject *array; /* array part */ + TValue *array; /* array part */ Node *node; - Node *firstfree; /* this position is free; all positions after it are full */ + Node *lastfree; /* any free position is before this position */ GCObject *gclist; int sizearray; /* size of `array' array */ } Table; @@ -311,26 +353,29 @@ typedef struct Table { ** `module' operation for hashing (size is always a power of 2) */ #define lmod(s,size) \ - check_exp((size&(size-1))==0, (cast(int, (s) & ((size)-1)))) + (check_exp((size&(size-1))==0, (cast(int, (s) & ((size)-1))))) #define twoto(x) (1<<(x)) #define sizenode(t) (twoto((t)->lsizenode)) +#define luaO_nilobject (&luaO_nilobject_) -extern const TObject luaO_nilobject; - -int luaO_log2 (unsigned int x); -int luaO_int2fb (unsigned int x); -#define fb2int(x) (((x) & 7) << ((x) >> 3)) +LUAI_DATA const TValue luaO_nilobject_; -int luaO_rawequalObj (const TObject *t1, const TObject *t2); -int luaO_str2d (const char *s, lua_Number *result); +#define ceillog2(x) (luaO_log2((x)-1) + 1) -const char *luaO_pushvfstring (lua_State *L, const char *fmt, va_list argp); -const char *luaO_pushfstring (lua_State *L, const char *fmt, ...); -void luaO_chunkid (char *out, const char *source, int len); +LUAI_FUNC int luaO_log2 (unsigned int x); +LUAI_FUNC int luaO_int2fb (unsigned int x); +LUAI_FUNC int luaO_fb2int (int x); +LUAI_FUNC int luaO_rawequalObj (const TValue *t1, const TValue *t2); +LUAI_FUNC int luaO_str2d (const char *s, lua_Number *result); +LUAI_FUNC const char *luaO_pushvfstring (lua_State *L, const char *fmt, + va_list argp); +LUAI_FUNC const char *luaO_pushfstring (lua_State *L, const char *fmt, ...); +LUAI_FUNC void luaO_chunkid (char *out, const char *source, size_t len); #endif + diff --git a/lib/lua/includes/lopcodes.h b/lib/lua/includes/lopcodes.h index c3da5b2..38a317c 100644 --- a/lib/lua/includes/lopcodes.h +++ b/lib/lua/includes/lopcodes.h @@ -1,5 +1,5 @@ /* -** $Id: lopcodes.h,v 1.4 2004-11-27 21:46:06 pixel Exp $ +** $Id: lopcodes.h,v 1.5 2007-07-27 10:05:53 pixel Exp $ ** Opcodes for Lua virtual machine ** See Copyright Notice in lua.h */ @@ -41,18 +41,19 @@ enum OpMode {iABC, iABx, iAsBx}; /* basic instruction format */ #define SIZE_OP 6 -#define POS_C SIZE_OP +#define POS_OP 0 +#define POS_A (POS_OP + SIZE_OP) +#define POS_C (POS_A + SIZE_A) #define POS_B (POS_C + SIZE_C) #define POS_Bx POS_C -#define POS_A (POS_B + SIZE_B) /* ** limits for opcode arguments. ** we use (signed) int to manipulate most arguments, -** so they must fit in BITS_INT-1 bits (-1 for sign) +** so they must fit in LUAI_BITSINT-1 bits (-1 for sign) */ -#if SIZE_Bx < BITS_INT-1 +#if SIZE_Bx < LUAI_BITSINT-1 #define MAXARG_Bx ((1<<SIZE_Bx)-1) #define MAXARG_sBx (MAXARG_Bx>>1) /* `sBx' is signed */ #else @@ -76,10 +77,11 @@ enum OpMode {iABC, iABx, iAsBx}; /* basic instruction format */ ** the following macros help to manipulate instructions */ -#define GET_OPCODE(i) (cast(OpCode, (i)&MASK1(SIZE_OP,0))) -#define SET_OPCODE(i,o) ((i) = (((i)&MASK0(SIZE_OP,0)) | cast(Instruction, o))) +#define GET_OPCODE(i) (cast(OpCode, ((i)>>POS_OP) & MASK1(SIZE_OP,0))) +#define SET_OPCODE(i,o) ((i) = (((i)&MASK0(SIZE_OP,POS_OP)) | \ + ((cast(Instruction, o)<<POS_OP)&MASK1(SIZE_OP,POS_OP)))) -#define GETARG_A(i) (cast(int, (i)>>POS_A)) +#define GETARG_A(i) (cast(int, ((i)>>POS_A) & MASK1(SIZE_A,0))) #define SETARG_A(i,u) ((i) = (((i)&MASK0(SIZE_A,POS_A)) | \ ((cast(Instruction, u)<<POS_A)&MASK1(SIZE_A,POS_A)))) @@ -99,16 +101,33 @@ enum OpMode {iABC, iABx, iAsBx}; /* basic instruction format */ #define SETARG_sBx(i,b) SETARG_Bx((i),cast(unsigned int, (b)+MAXARG_sBx)) -#define CREATE_ABC(o,a,b,c) (cast(Instruction, o) \ +#define CREATE_ABC(o,a,b,c) ((cast(Instruction, o)<<POS_OP) \ | (cast(Instruction, a)<<POS_A) \ | (cast(Instruction, b)<<POS_B) \ | (cast(Instruction, c)<<POS_C)) -#define CREATE_ABx(o,a,bc) (cast(Instruction, o) \ +#define CREATE_ABx(o,a,bc) ((cast(Instruction, o)<<POS_OP) \ | (cast(Instruction, a)<<POS_A) \ | (cast(Instruction, bc)<<POS_Bx)) +/* +** Macros to operate RK indices +*/ + +/* this bit 1 means constant (0 means register) */ +#define BITRK (1 << (SIZE_B - 1)) + +/* test whether value is a constant */ +#define ISK(x) ((x) & BITRK) + +/* gets the index of the constant */ +#define INDEXK(r) ((int)(r) & ~BITRK) + +#define MAXINDEXRK (BITRK - 1) + +/* code a constant index as a RK value */ +#define RKASK(x) ((x) | BITRK) /* @@ -120,7 +139,7 @@ enum OpMode {iABC, iABx, iAsBx}; /* basic instruction format */ /* ** R(x) - register ** Kst(x) - constant (in constant table) -** RK(x) == if x < MAXSTACK then R(x) else Kst(x-MAXSTACK) +** RK(x) == if ISK(x) then Kst(INDEXK(x)) else R(x) */ @@ -134,7 +153,7 @@ name args description ------------------------------------------------------------------------*/ OP_MOVE,/* A B R(A) := R(B) */ OP_LOADK,/* A Bx R(A) := Kst(Bx) */ -OP_LOADBOOL,/* A B C R(A) := (Bool)B; if (C) PC++ */ +OP_LOADBOOL,/* A B C R(A) := (Bool)B; if (C) pc++ */ OP_LOADNIL,/* A B R(A) := ... := R(B) := nil */ OP_GETUPVAL,/* A B R(A) := UpValue[B] */ @@ -153,86 +172,97 @@ OP_ADD,/* A B C R(A) := RK(B) + RK(C) */ OP_SUB,/* A B C R(A) := RK(B) - RK(C) */ OP_MUL,/* A B C R(A) := RK(B) * RK(C) */ OP_DIV,/* A B C R(A) := RK(B) / RK(C) */ +OP_MOD,/* A B C R(A) := RK(B) % RK(C) */ OP_POW,/* A B C R(A) := RK(B) ^ RK(C) */ OP_UNM,/* A B R(A) := -R(B) */ OP_NOT,/* A B R(A) := not R(B) */ +OP_LEN,/* A B R(A) := length of R(B) */ OP_CONCAT,/* A B C R(A) := R(B).. ... ..R(C) */ -OP_JMP,/* sBx PC += sBx */ +OP_JMP,/* sBx pc+=sBx */ OP_EQ,/* A B C if ((RK(B) == RK(C)) ~= A) then pc++ */ OP_LT,/* A B C if ((RK(B) < RK(C)) ~= A) then pc++ */ OP_LE,/* A B C if ((RK(B) <= RK(C)) ~= A) then pc++ */ -OP_TEST,/* A B C if (R(B) <=> C) then R(A) := R(B) else pc++ */ +OP_TEST,/* A C if not (R(A) <=> C) then pc++ */ +OP_TESTSET,/* A B C if (R(B) <=> C) then R(A) := R(B) else pc++ */ OP_CALL,/* A B C R(A), ... ,R(A+C-2) := R(A)(R(A+1), ... ,R(A+B-1)) */ OP_TAILCALL,/* A B C return R(A)(R(A+1), ... ,R(A+B-1)) */ OP_RETURN,/* A B return R(A), ... ,R(A+B-2) (see note) */ -OP_FORLOOP,/* A sBx R(A)+=R(A+2); if R(A) <?= R(A+1) then PC+= sBx */ - -OP_TFORLOOP,/* A C R(A+2), ... ,R(A+2+C) := R(A)(R(A+1), R(A+2)); - if R(A+2) ~= nil then pc++ */ -OP_TFORPREP,/* A sBx if type(R(A)) == table then R(A+1):=R(A), R(A):=next; - PC += sBx */ +OP_FORLOOP,/* A sBx R(A)+=R(A+2); + if R(A) <?= R(A+1) then { pc+=sBx; R(A+3)=R(A) }*/ +OP_FORPREP,/* A sBx R(A)-=R(A+2); pc+=sBx */ -OP_SETLIST,/* A Bx R(A)[Bx-Bx%FPF+i] := R(A+i), 1 <= i <= Bx%FPF+1 */ -OP_SETLISTO,/* A Bx */ +OP_TFORLOOP,/* A C R(A+3), ... ,R(A+2+C) := R(A)(R(A+1), R(A+2)); + if R(A+3) ~= nil then R(A+2)=R(A+3) else pc++ */ +OP_SETLIST,/* A B C R(A)[(C-1)*FPF+i] := R(A+i), 1 <= i <= B */ OP_CLOSE,/* A close all variables in the stack up to (>=) R(A)*/ -OP_CLOSURE/* A Bx R(A) := closure(KPROTO[Bx], R(A), ... ,R(A+n)) */ +OP_CLOSURE,/* A Bx R(A) := closure(KPROTO[Bx], R(A), ... ,R(A+n)) */ + +OP_VARARG/* A B R(A), R(A+1), ..., R(A+B-1) = vararg */ } OpCode; -#define NUM_OPCODES (cast(int, OP_CLOSURE+1)) +#define NUM_OPCODES (cast(int, OP_VARARG) + 1) /*=========================================================================== Notes: - (1) In OP_CALL, if (B == 0) then B = top. C is the number of returns - 1, + (*) In OP_CALL, if (B == 0) then B = top. C is the number of returns - 1, and can be 0: OP_CALL then sets `top' to last_result+1, so next open instruction (OP_CALL, OP_RETURN, OP_SETLIST) may use `top'. - (2) In OP_RETURN, if (B == 0) then return up to `top' + (*) In OP_VARARG, if (B == 0) then use actual number of varargs and + set top (like in OP_CALL with C == 0). + + (*) In OP_RETURN, if (B == 0) then return up to `top' - (3) For comparisons, B specifies what conditions the test should accept. + (*) In OP_SETLIST, if (B == 0) then B = `top'; + if (C == 0) then next `instruction' is real C - (4) All `skips' (pc++) assume that next instruction is a jump + (*) For comparisons, A specifies what condition the test should accept + (true or false). + + (*) All `skips' (pc++) assume that next instruction is a jump ===========================================================================*/ /* -** masks for instruction properties +** masks for instruction properties. The format is: +** bits 0-1: op mode +** bits 2-3: C arg mode +** bits 4-5: B arg mode +** bit 6: instruction set register A +** bit 7: operator is a test */ -enum OpModeMask { - OpModeBreg = 2, /* B is a register */ - OpModeBrk, /* B is a register/constant */ - OpModeCrk, /* C is a register/constant */ - OpModesetA, /* instruction set register A */ - OpModeK, /* Bx is a constant */ - OpModeT /* operator is a test */ - -}; +enum OpArgMask { + OpArgN, /* argument is not used */ + OpArgU, /* argument is used */ + OpArgR, /* argument is a register or a jump offset */ + OpArgK /* argument is a constant or register/constant */ +}; -extern const lu_byte luaP_opmodes[NUM_OPCODES]; - -#define getOpMode(m) (cast(enum OpMode, luaP_opmodes[m] & 3)) -#define testOpMode(m, b) (luaP_opmodes[m] & (1 << (b))) +LUAI_DATA const lu_byte luaP_opmodes[NUM_OPCODES]; +#define getOpMode(m) (cast(enum OpMode, luaP_opmodes[m] & 3)) +#define getBMode(m) (cast(enum OpArgMask, (luaP_opmodes[m] >> 4) & 3)) +#define getCMode(m) (cast(enum OpArgMask, (luaP_opmodes[m] >> 2) & 3)) +#define testAMode(m) (luaP_opmodes[m] & (1 << 6)) +#define testTMode(m) (luaP_opmodes[m] & (1 << 7)) -#ifdef LUA_OPNAMES -extern const char *const luaP_opnames[]; /* opcode names */ -#endif +LUAI_DATA const char *const luaP_opnames[NUM_OPCODES+1]; /* opcode names */ /* number of list items to accumulate before a SETLIST instruction */ -/* (must be a power of 2) */ -#define LFIELDS_PER_FLUSH 32 +#define LFIELDS_PER_FLUSH 50 #endif diff --git a/lib/lua/includes/lparser.h b/lib/lua/includes/lparser.h index acbda7f..7eac78c 100644 --- a/lib/lua/includes/lparser.h +++ b/lib/lua/includes/lparser.h @@ -1,5 +1,5 @@ /* -** $Id: lparser.h,v 1.4 2004-11-27 21:46:06 pixel Exp $ +** $Id: lparser.h,v 1.5 2007-07-27 10:05:53 pixel Exp $ ** Lua Parser ** See Copyright Notice in lua.h */ @@ -9,7 +9,6 @@ #include "llimits.h" #include "lobject.h" -#include "ltable.h" #include "lzio.h" @@ -23,6 +22,7 @@ typedef enum { VTRUE, VFALSE, VK, /* info = index of constant in `k' */ + VKNUM, /* nval = numerical value */ VLOCAL, /* info = local register */ VUPVAL, /* info = index of upvalue in `upvalues' */ VGLOBAL, /* info = index of table; aux = index of global name in `k' */ @@ -30,17 +30,27 @@ typedef enum { VJMP, /* info = instruction pc */ VRELOCABLE, /* info = instruction pc */ VNONRELOC, /* info = result register */ - VCALL /* info = result register */ + VCALL, /* info = instruction pc */ + VVARARG /* info = instruction pc */ } expkind; typedef struct expdesc { expkind k; - int info, aux; + union { + struct { int info, aux; } s; + lua_Number nval; + } u; int t; /* patch list of `exit when true' */ int f; /* patch list of `exit when false' */ } expdesc; +typedef struct upvaldesc { + lu_byte k; + lu_byte info; +} upvaldesc; + + struct BlockCnt; /* defined in lparser.c */ @@ -58,14 +68,15 @@ typedef struct FuncState { int freereg; /* first free register */ int nk; /* number of elements in `k' */ int np; /* number of elements in `p' */ - int nlocvars; /* number of elements in `locvars' */ - int nactvar; /* number of active local variables */ - expdesc upvalues[MAXUPVALUES]; /* upvalues */ - int actvar[MAXVARS]; /* declared-variable stack */ + short nlocvars; /* number of elements in `locvars' */ + lu_byte nactvar; /* number of active local variables */ + upvaldesc upvalues[LUAI_MAXUPVALUES]; /* upvalues */ + unsigned short actvar[LUAI_MAXVARS]; /* declared-variable stack */ } FuncState; -Proto *luaY_parser (lua_State *L, ZIO *z, Mbuffer *buff); +LUAI_FUNC Proto *luaY_parser (lua_State *L, ZIO *z, Mbuffer *buff, + const char *name); #endif diff --git a/lib/lua/includes/lstate.h b/lib/lua/includes/lstate.h index bd5c1d9..1bbacfe 100644 --- a/lib/lua/includes/lstate.h +++ b/lib/lua/includes/lstate.h @@ -1,5 +1,5 @@ /* -** $Id: lstate.h,v 1.7 2006-02-09 16:59:55 pixel Exp $ +** $Id: lstate.h,v 1.8 2007-07-27 10:05:53 pixel Exp $ ** Global State ** See Copyright Notice in lua.h */ @@ -14,46 +14,15 @@ #include "lzio.h" -/* -** macros for thread synchronization inside Lua core machine: -** all accesses to the global state and to global objects are synchronized. -** Because threads can read the stack of other threads -** (when running garbage collection), -** a thread must also synchronize any write-access to its own stack. -** Unsynchronized accesses are allowed only when reading its own stack, -** or when reading immutable fields from global objects -** (such as string values and udata values). -*/ - -void do_lua_lock(lua_State *); -void do_lua_unlock(lua_State *); - -#ifndef lua_lock -#define lua_lock(L) do_lua_lock(L) -#endif - -#ifndef lua_unlock -#define lua_unlock(L) do_lua_unlock(L) -#endif - - -#ifndef lua_userstateopen -#define lua_userstateopen(l) -#endif - - struct lua_longjmp; /* defined in ldo.c */ -/* default meta table (both for tables and udata) */ -#define defaultmeta(L) (&G(L)->_defaultmeta) - /* table of globals */ -#define gt(L) (&L->_gt) +#define gt(L) (&L->l_gt) /* registry */ -#define registry(L) (&G(L)->_registry) +#define registry(L) (&G(L)->l_registry) /* extra stack space to handle TM calls and some other extras */ @@ -68,7 +37,7 @@ struct lua_longjmp; /* defined in ldo.c */ typedef struct stringtable { GCObject **hash; - ls_nstr nuse; /* number of elements */ + lu_int32 nuse; /* number of elements */ int size; } stringtable; @@ -77,37 +46,20 @@ typedef struct stringtable { ** informations about a call */ typedef struct CallInfo { - StkId base; /* base for called function */ + StkId base; /* base for this function */ + StkId func; /* function index in the stack */ StkId top; /* top for this function */ - int state; /* bit fields; see below */ - union { - struct { /* for Lua functions */ - const Instruction *savedpc; - const Instruction **pc; /* points to `pc' variable in `luaV_execute' */ - int tailcalls; /* number of tail calls lost under this entry */ - } l; - struct { /* for C functions */ - int dummy; /* just to avoid an empty struct */ - } c; - } u; + const Instruction *savedpc; + int nresults; /* expected number of results from this function */ + int tailcalls; /* number of tail calls lost under this entry */ } CallInfo; -/* -** bit fields for `CallInfo.state' -*/ -#define CI_C (1<<0) /* 1 if function is a C function */ -/* 1 if (Lua) function has an active `luaV_execute' running it */ -#define CI_HASFRAME (1<<1) -/* 1 if Lua function is calling another Lua function (and therefore its - `pc' is being used by the other, and therefore CI_SAVEDPC is 1 too) */ -#define CI_CALLING (1<<2) -#define CI_SAVEDPC (1<<3) /* 1 if `savedpc' is updated */ -#define CI_YIELD (1<<4) /* 1 if thread is suspended */ -#define CI_BREAK (1<<5) /* 1 if user break */ - -#define ci_func(ci) (clvalue((ci)->base - 1)) +#define curr_func(L) (clvalue(L->ci->func)) +#define ci_func(ci) (clvalue((ci)->func)) +#define f_isLua(ci) (!ci_func(ci)->c.isC) +#define isLua(ci) (ttisfunction((ci)->func) && f_isLua(ci)) /* @@ -115,17 +67,29 @@ typedef struct CallInfo { */ typedef struct global_State { stringtable strt; /* hash table for strings */ - GCObject *rootgc; /* list of (almost) all collectable objects */ - GCObject *rootudata; /* (separated) list of all userdata */ - GCObject *tmudata; /* list of userdata to be GC */ + lua_Alloc frealloc; /* function to reallocate memory */ + void *ud; /* auxiliary data to `frealloc' */ + lu_byte currentwhite; + lu_byte gcstate; /* state of garbage collector */ + int sweepstrgc; /* position of sweep in `strt' */ + GCObject *rootgc; /* list of all collectable objects */ + GCObject **sweepgc; /* position of sweep in `rootgc' */ + GCObject *gray; /* list of gray objects */ + GCObject *grayagain; /* list of objects to be traversed atomically */ + GCObject *weak; /* list of weak tables (to be cleared) */ + GCObject *tmudata; /* last element of list of userdata to be GC */ Mbuffer buff; /* temporary buffer for string concatentation */ lu_mem GCthreshold; - lu_mem nblocks; /* number of `bytes' currently allocated */ + lu_mem totalbytes; /* number of bytes currently allocated */ + lu_mem estimate; /* an estimate of number of bytes actually in use */ + lu_mem gcdept; /* how much GC is `behind schedule' */ + int gcpause; /* size of pause between successive GCs */ + int gcstepmul; /* GC `granularity' */ lua_CFunction panic; /* to be called in unprotected errors */ - TObject _registry; - TObject _defaultmeta; + TValue l_registry; struct lua_State *mainthread; - Node dummynode[1]; /* common node array for all empty tables */ + UpVal uvhead; /* head of double-linked list of all open upvalues */ + struct Table *mt[NUM_TAGS]; /* metatables for basic types */ TString *tmname[TM_N]; /* array with tag-method names */ } global_State; @@ -135,30 +99,33 @@ typedef struct global_State { */ struct lua_State { CommonHeader; + lu_byte status; StkId top; /* first free slot in the stack */ StkId base; /* base of current function */ global_State *l_G; CallInfo *ci; /* call info for current function */ + const Instruction *savedpc; /* `savedpc' of current function */ StkId stack_last; /* last free slot in the stack */ StkId stack; /* stack base */ - int stacksize; CallInfo *end_ci; /* points after end of ci array*/ CallInfo *base_ci; /* array of CallInfo's */ - unsigned short size_ci; /* size of array `base_ci' */ + int stacksize; + int size_ci; /* size of array `base_ci' */ unsigned short nCcalls; /* number of nested C calls */ lu_byte hookmask; lu_byte allowhook; - lu_byte hookinit; int basehookcount; int hookcount; lua_Hook hook; - TObject _gt; /* table of globals */ + TValue l_gt; /* table of globals */ + TValue env; /* temporary place for environments */ GCObject *openupval; /* list of open upvalues in this stack */ GCObject *gclist; struct lua_longjmp *errorJmp; /* current error recover point */ ptrdiff_t errfunc; /* current error handling function (stack index) */ lua_CallWrap callwrap; lua_ThreadHook createhook, destroyhook; + lu_byte do_break; }; @@ -181,22 +148,24 @@ union GCObject { /* macros to convert a GCObject into a specific value */ -#define gcotots(o) check_exp((o)->gch.tt == LUA_TSTRING, &((o)->ts)) -#define gcotou(o) check_exp((o)->gch.tt == LUA_TUSERDATA, &((o)->u)) -#define gcotocl(o) check_exp((o)->gch.tt == LUA_TFUNCTION, &((o)->cl)) -#define gcotoh(o) check_exp((o)->gch.tt == LUA_TTABLE, &((o)->h)) -#define gcotop(o) check_exp((o)->gch.tt == LUA_TPROTO, &((o)->p)) -#define gcotouv(o) check_exp((o)->gch.tt == LUA_TUPVAL, &((o)->uv)) +#define rawgco2ts(o) check_exp((o)->gch.tt == LUA_TSTRING, &((o)->ts)) +#define gco2ts(o) (&rawgco2ts(o)->tsv) +#define rawgco2u(o) check_exp((o)->gch.tt == LUA_TUSERDATA, &((o)->u)) +#define gco2u(o) (&rawgco2u(o)->uv) +#define gco2cl(o) check_exp((o)->gch.tt == LUA_TFUNCTION, &((o)->cl)) +#define gco2h(o) check_exp((o)->gch.tt == LUA_TTABLE, &((o)->h)) +#define gco2p(o) check_exp((o)->gch.tt == LUA_TPROTO, &((o)->p)) +#define gco2uv(o) check_exp((o)->gch.tt == LUA_TUPVAL, &((o)->uv)) #define ngcotouv(o) \ check_exp((o) == NULL || (o)->gch.tt == LUA_TUPVAL, &((o)->uv)) -#define gcototh(o) check_exp((o)->gch.tt == LUA_TTHREAD, &((o)->th)) +#define gco2th(o) check_exp((o)->gch.tt == LUA_TTHREAD, &((o)->th)) -/* macro to convert any value into a GCObject */ -#define valtogco(v) (cast(GCObject *, (v))) +/* macro to convert any Lua object into a GCObject */ +#define obj2gco(v) (cast(GCObject *, (v))) -lua_State *luaE_newthread (lua_State *L); -void luaE_freethread (lua_State *L, lua_State *L1); +LUAI_FUNC lua_State *luaE_newthread (lua_State *L); +LUAI_FUNC void luaE_freethread (lua_State *L, lua_State *L1); #endif diff --git a/lib/lua/includes/lstring.h b/lib/lua/includes/lstring.h index 15745f5..21b7749 100644 --- a/lib/lua/includes/lstring.h +++ b/lib/lua/includes/lstring.h @@ -1,5 +1,5 @@ /* -** $Id: lstring.h,v 1.4 2004-11-27 21:46:06 pixel Exp $ +** $Id: lstring.h,v 1.5 2007-07-27 10:05:53 pixel Exp $ ** String table (keep all strings handled by Lua) ** See Copyright Notice in lua.h */ @@ -8,26 +8,24 @@ #define lstring_h +#include "lgc.h" #include "lobject.h" #include "lstate.h" +#define sizestring(s) (sizeof(union TString)+((s)->len+1)*sizeof(char)) -#define sizestring(l) (cast(lu_mem, sizeof(union TString))+ \ - (cast(lu_mem, l)+1)*sizeof(char)) - -#define sizeudata(l) (cast(lu_mem, sizeof(union Udata))+(l)) +#define sizeudata(u) (sizeof(union Udata)+(u)->len) #define luaS_new(L, s) (luaS_newlstr(L, s, strlen(s))) #define luaS_newliteral(L, s) (luaS_newlstr(L, "" s, \ (sizeof(s)/sizeof(char))-1)) -#define luaS_fix(s) ((s)->tsv.marked |= (1<<4)) +#define luaS_fix(s) l_setbit((s)->tsv.marked, FIXEDBIT) -void luaS_resize (lua_State *L, int newsize); -Udata *luaS_newudata (lua_State *L, size_t s); -void luaS_freeall (lua_State *L); -TString *luaS_newlstr (lua_State *L, const char *str, size_t l); +LUAI_FUNC void luaS_resize (lua_State *L, int newsize); +LUAI_FUNC Udata *luaS_newudata (lua_State *L, size_t s, Table *e); +LUAI_FUNC TString *luaS_newlstr (lua_State *L, const char *str, size_t l); #endif diff --git a/lib/lua/includes/ltable.h b/lib/lua/includes/ltable.h index 56920ee..2324b8f 100644 --- a/lib/lua/includes/ltable.h +++ b/lib/lua/includes/ltable.h @@ -1,5 +1,5 @@ /* -** $Id: ltable.h,v 1.4 2004-11-27 21:46:06 pixel Exp $ +** $Id: ltable.h,v 1.5 2007-07-27 10:05:53 pixel Exp $ ** Lua tables (hash) ** See Copyright Notice in lua.h */ @@ -11,21 +11,30 @@ #define gnode(t,i) (&(t)->node[i]) -#define gkey(n) (&(n)->i_key) +#define gkey(n) (&(n)->i_key.nk) #define gval(n) (&(n)->i_val) +#define gnext(n) ((n)->i_key.nk.next) +#define key2tval(n) (&(n)->i_key.tvk) -const TObject *luaH_getnum (Table *t, int key); -TObject *luaH_setnum (lua_State *L, Table *t, int key); -const TObject *luaH_getstr (Table *t, TString *key); -const TObject *luaH_get (Table *t, const TObject *key); -TObject *luaH_set (lua_State *L, Table *t, const TObject *key); -Table *luaH_new (lua_State *L, int narray, int lnhash); -void luaH_free (lua_State *L, Table *t); -int luaH_next (lua_State *L, Table *t, StkId key); -/* exported only for debugging */ -Node *luaH_mainposition (const Table *t, const TObject *key); +LUAI_FUNC const TValue *luaH_getnum (Table *t, int key); +LUAI_FUNC TValue *luaH_setnum (lua_State *L, Table *t, int key); +LUAI_FUNC const TValue *luaH_getstr (Table *t, TString *key); +LUAI_FUNC TValue *luaH_setstr (lua_State *L, Table *t, TString *key); +LUAI_FUNC const TValue *luaH_get (Table *t, const TValue *key); +LUAI_FUNC TValue *luaH_set (lua_State *L, Table *t, const TValue *key); +LUAI_FUNC Table *luaH_new (lua_State *L, int narray, int lnhash); +LUAI_FUNC void luaH_resizearray (lua_State *L, Table *t, int nasize); +LUAI_FUNC void luaH_free (lua_State *L, Table *t); +LUAI_FUNC int luaH_next (lua_State *L, Table *t, StkId key); +LUAI_FUNC int luaH_getn (Table *t); + + +#if defined(LUA_DEBUG) +LUAI_FUNC Node *luaH_mainposition (const Table *t, const TValue *key); +LUAI_FUNC int luaH_isdummy (Node *n); +#endif #endif diff --git a/lib/lua/includes/ltm.h b/lib/lua/includes/ltm.h index 73625c2..f430e6d 100644 --- a/lib/lua/includes/ltm.h +++ b/lib/lua/includes/ltm.h @@ -1,5 +1,5 @@ /* -** $Id: ltm.h,v 1.4 2004-11-27 21:46:06 pixel Exp $ +** $Id: ltm.h,v 1.5 2007-07-27 10:05:53 pixel Exp $ ** Tag methods ** See Copyright Notice in lua.h */ @@ -25,8 +25,10 @@ typedef enum { TM_SUB, TM_MUL, TM_DIV, + TM_MOD, TM_POW, TM_UNM, + TM_LEN, TM_LT, TM_LE, TM_CONCAT, @@ -36,16 +38,17 @@ typedef enum { -#define gfasttm(g,et,e) \ - (((et)->flags & (1u<<(e))) ? NULL : luaT_gettm(et, e, (g)->tmname[e])) +#define gfasttm(g,et,e) ((et) == NULL ? NULL : \ + ((et)->flags & (1u<<(e))) ? NULL : luaT_gettm(et, e, (g)->tmname[e])) #define fasttm(l,et,e) gfasttm(G(l), et, e) +LUAI_DATA const char *const luaT_typenames[]; -const TObject *luaT_gettm (Table *events, TMS event, TString *ename); -const TObject *luaT_gettmbyobj (lua_State *L, const TObject *o, TMS event); -void luaT_init (lua_State *L); -extern const char *const luaT_typenames[]; +LUAI_FUNC const TValue *luaT_gettm (Table *events, TMS event, TString *ename); +LUAI_FUNC const TValue *luaT_gettmbyobj (lua_State *L, const TValue *o, + TMS event); +LUAI_FUNC void luaT_init (lua_State *L); #endif diff --git a/lib/lua/includes/lundump.h b/lib/lua/includes/lundump.h index 7f33793..bec9bda 100644 --- a/lib/lua/includes/lundump.h +++ b/lib/lua/includes/lundump.h @@ -1,6 +1,6 @@ /* -** $Id: lundump.h,v 1.4 2004-11-27 21:46:06 pixel Exp $ -** load pre-compiled Lua chunks +** $Id: lundump.h,v 1.5 2007-07-27 10:05:53 pixel Exp $ +** load precompiled Lua chunks ** See Copyright Notice in lua.h */ @@ -11,24 +11,24 @@ #include "lzio.h" /* load one chunk; from lundump.c */ -Proto* luaU_undump (lua_State* L, ZIO* Z, Mbuffer* buff); +LUAI_FUNC Proto* luaU_undump (lua_State* L, ZIO* Z, Mbuffer* buff, const char* name); -/* find byte order; from lundump.c */ -int luaU_endianness (void); +/* make header; from lundump.c */ +LUAI_FUNC void luaU_header (char* h); /* dump one chunk; from ldump.c */ -void luaU_dump (lua_State* L, const Proto* Main, lua_Chunkwriter w, void* data); +LUAI_FUNC int luaU_dump (lua_State* L, const Proto* f, lua_Writer w, void* data, int strip); /* print one chunk; from print.c */ -void luaU_print (const Proto* Main); +LUAI_FUNC void luaU_print (const Proto* f, int full); -/* definitions for headers of binary files */ -#define LUA_SIGNATURE "\033Lua" /* binary files start with "<esc>Lua" */ -#define VERSION 0x50 /* last format change was in 5.0 */ -#define VERSION0 0x50 /* last major change was in 5.0 */ +/* for header of binary files -- this is Lua 5.1 */ +#define LUAC_VERSION 0x51 -/* a multiple of PI for testing native format */ -/* multiplying by 1E7 gives non-trivial integer values */ -#define TEST_NUMBER ((lua_Number)3.14159265358979323846E7) +/* for header of binary files -- this is the official format */ +#define LUAC_FORMAT 0 + +/* size of header of binary files */ +#define LUAC_HEADERSIZE 12 #endif diff --git a/lib/lua/includes/lvm.h b/lib/lua/includes/lvm.h index 20b75de..e0b9e4d 100644 --- a/lib/lua/includes/lvm.h +++ b/lib/lua/includes/lvm.h @@ -1,5 +1,5 @@ /* -** $Id: lvm.h,v 1.4 2004-11-27 21:46:06 pixel Exp $ +** $Id: lvm.h,v 1.5 2007-07-27 10:05:53 pixel Exp $ ** Lua virtual machine ** See Copyright Notice in lua.h */ @@ -22,14 +22,15 @@ (ttype(o1) == ttype(o2) && luaV_equalval(L, o1, o2)) -int luaV_lessthan (lua_State *L, const TObject *l, const TObject *r); -int luaV_equalval (lua_State *L, const TObject *t1, const TObject *t2); -const TObject *luaV_tonumber (const TObject *obj, TObject *n); -int luaV_tostring (lua_State *L, StkId obj); -const TObject *luaV_gettable (lua_State *L, const TObject *t, TObject *key, - int loop); -void luaV_settable (lua_State *L, const TObject *t, TObject *key, StkId val); -StkId luaV_execute (lua_State *L); -void luaV_concat (lua_State *L, int total, int last); +LUAI_FUNC int luaV_lessthan (lua_State *L, const TValue *l, const TValue *r); +LUAI_FUNC int luaV_equalval (lua_State *L, const TValue *t1, const TValue *t2); +LUAI_FUNC const TValue *luaV_tonumber (const TValue *obj, TValue *n); +LUAI_FUNC int luaV_tostring (lua_State *L, StkId obj); +LUAI_FUNC void luaV_gettable (lua_State *L, const TValue *t, TValue *key, + StkId val); +LUAI_FUNC void luaV_settable (lua_State *L, const TValue *t, TValue *key, + StkId val); +LUAI_FUNC void luaV_execute (lua_State *L, int nexeccalls); +LUAI_FUNC void luaV_concat (lua_State *L, int total, int last); #endif diff --git a/lib/lua/includes/lzio.h b/lib/lua/includes/lzio.h index 7d41fbd..0900405 100644 --- a/lib/lua/includes/lzio.h +++ b/lib/lua/includes/lzio.h @@ -1,5 +1,5 @@ /* -** $Id: lzio.h,v 1.4 2004-11-27 21:46:06 pixel Exp $ +** $Id: lzio.h,v 1.5 2007-07-27 10:05:53 pixel Exp $ ** Buffered streams ** See Copyright Notice in lua.h */ @@ -10,36 +10,31 @@ #include "lua.h" +#include "lmem.h" + #define EOZ (-1) /* end of stream */ typedef struct Zio ZIO; - #define char2int(c) cast(int, cast(unsigned char, (c))) #define zgetc(z) (((z)->n--)>0 ? char2int(*(z)->p++) : luaZ_fill(z)) -#define zname(z) ((z)->name) - -void luaZ_init (ZIO *z, lua_Chunkreader reader, void *data, const char *name); -size_t luaZ_read (ZIO* z, void* b, size_t n); /* read next n bytes */ -int luaZ_lookahead (ZIO *z); - - - typedef struct Mbuffer { char *buffer; + size_t n; size_t buffsize; } Mbuffer; - -char *luaZ_openspace (lua_State *L, Mbuffer *buff, size_t n); - #define luaZ_initbuffer(L, buff) ((buff)->buffer = NULL, (buff)->buffsize = 0) -#define luaZ_sizebuffer(buff) ((buff)->buffsize) #define luaZ_buffer(buff) ((buff)->buffer) +#define luaZ_sizebuffer(buff) ((buff)->buffsize) +#define luaZ_bufflen(buff) ((buff)->n) + +#define luaZ_resetbuffer(buff) ((buff)->n = 0) + #define luaZ_resizebuffer(L, buff, size) \ (luaM_reallocvector(L, (buff)->buffer, (buff)->buffsize, size, char), \ @@ -48,17 +43,25 @@ char *luaZ_openspace (lua_State *L, Mbuffer *buff, size_t n); #define luaZ_freebuffer(L, buff) luaZ_resizebuffer(L, buff, 0) +LUAI_FUNC char *luaZ_openspace (lua_State *L, Mbuffer *buff, size_t n); +LUAI_FUNC void luaZ_init (lua_State *L, ZIO *z, lua_Reader reader, + void *data); +LUAI_FUNC size_t luaZ_read (ZIO* z, void* b, size_t n); /* read next n bytes */ +LUAI_FUNC int luaZ_lookahead (ZIO *z); + + + /* --------- Private Part ------------------ */ struct Zio { size_t n; /* bytes still unread */ const char *p; /* current position in buffer */ - lua_Chunkreader reader; + lua_Reader reader; void* data; /* additional data */ - const char *name; + lua_State *L; /* Lua state (for reader) */ }; -int luaZ_fill (ZIO *z); +LUAI_FUNC int luaZ_fill (ZIO *z); #endif |