hirlite 0.0.2 → 0.0.2.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (106) hide show
  1. checksums.yaml +4 -4
  2. data/ext/hirlite_ext/extconf.rb +2 -2
  3. data/lib/hirlite/version.rb +1 -1
  4. data/vendor/rlite/deps/lua/Makefile +128 -0
  5. data/vendor/rlite/deps/lua/src/fpconv.c +205 -0
  6. data/vendor/rlite/deps/lua/src/fpconv.h +22 -0
  7. data/vendor/rlite/deps/lua/src/lapi.c +1087 -0
  8. data/vendor/rlite/deps/lua/src/lapi.h +16 -0
  9. data/vendor/rlite/deps/lua/src/lauxlib.c +652 -0
  10. data/vendor/rlite/deps/lua/src/lauxlib.h +174 -0
  11. data/vendor/rlite/deps/lua/src/lbaselib.c +653 -0
  12. data/vendor/rlite/deps/lua/src/lcode.c +831 -0
  13. data/vendor/rlite/deps/lua/src/lcode.h +76 -0
  14. data/vendor/rlite/deps/lua/src/ldblib.c +398 -0
  15. data/vendor/rlite/deps/lua/src/ldebug.c +638 -0
  16. data/vendor/rlite/deps/lua/src/ldebug.h +33 -0
  17. data/vendor/rlite/deps/lua/src/ldo.c +519 -0
  18. data/vendor/rlite/deps/lua/src/ldo.h +57 -0
  19. data/vendor/rlite/deps/lua/src/ldump.c +164 -0
  20. data/vendor/rlite/deps/lua/src/lfunc.c +174 -0
  21. data/vendor/rlite/deps/lua/src/lfunc.h +34 -0
  22. data/vendor/rlite/deps/lua/src/lgc.c +710 -0
  23. data/vendor/rlite/deps/lua/src/lgc.h +110 -0
  24. data/vendor/rlite/deps/lua/src/linit.c +38 -0
  25. data/vendor/rlite/deps/lua/src/liolib.c +556 -0
  26. data/vendor/rlite/deps/lua/src/llex.c +463 -0
  27. data/vendor/rlite/deps/lua/src/llex.h +81 -0
  28. data/vendor/rlite/deps/lua/src/llimits.h +128 -0
  29. data/vendor/rlite/deps/lua/src/lmathlib.c +263 -0
  30. data/vendor/rlite/deps/lua/src/lmem.c +86 -0
  31. data/vendor/rlite/deps/lua/src/lmem.h +49 -0
  32. data/vendor/rlite/deps/lua/src/loadlib.c +666 -0
  33. data/vendor/rlite/deps/lua/src/lobject.c +214 -0
  34. data/vendor/rlite/deps/lua/src/lobject.h +381 -0
  35. data/vendor/rlite/deps/lua/src/lopcodes.c +102 -0
  36. data/vendor/rlite/deps/lua/src/lopcodes.h +268 -0
  37. data/vendor/rlite/deps/lua/src/loslib.c +243 -0
  38. data/vendor/rlite/deps/lua/src/lparser.c +1339 -0
  39. data/vendor/rlite/deps/lua/src/lparser.h +82 -0
  40. data/vendor/rlite/deps/lua/src/lstate.c +214 -0
  41. data/vendor/rlite/deps/lua/src/lstate.h +169 -0
  42. data/vendor/rlite/deps/lua/src/lstring.c +111 -0
  43. data/vendor/rlite/deps/lua/src/lstring.h +31 -0
  44. data/vendor/rlite/deps/lua/src/lstrlib.c +871 -0
  45. data/vendor/rlite/deps/lua/src/ltable.c +588 -0
  46. data/vendor/rlite/deps/lua/src/ltable.h +40 -0
  47. data/vendor/rlite/deps/lua/src/ltablib.c +287 -0
  48. data/vendor/rlite/deps/lua/src/ltm.c +75 -0
  49. data/vendor/rlite/deps/lua/src/ltm.h +54 -0
  50. data/vendor/rlite/deps/lua/src/lua.c +392 -0
  51. data/vendor/rlite/deps/lua/src/lua.h +388 -0
  52. data/vendor/rlite/deps/lua/src/lua_bit.c +189 -0
  53. data/vendor/rlite/deps/lua/src/lua_cjson.c +1427 -0
  54. data/vendor/rlite/deps/lua/src/lua_cmsgpack.c +957 -0
  55. data/vendor/rlite/deps/lua/src/lua_struct.c +421 -0
  56. data/vendor/rlite/deps/lua/src/luac.c +200 -0
  57. data/vendor/rlite/deps/lua/src/luaconf.h +763 -0
  58. data/vendor/rlite/deps/lua/src/lualib.h +53 -0
  59. data/vendor/rlite/deps/lua/src/lundump.c +227 -0
  60. data/vendor/rlite/deps/lua/src/lundump.h +36 -0
  61. data/vendor/rlite/deps/lua/src/lvm.c +767 -0
  62. data/vendor/rlite/deps/lua/src/lvm.h +36 -0
  63. data/vendor/rlite/deps/lua/src/lzio.c +82 -0
  64. data/vendor/rlite/deps/lua/src/lzio.h +67 -0
  65. data/vendor/rlite/deps/lua/src/print.c +227 -0
  66. data/vendor/rlite/deps/lua/src/strbuf.c +251 -0
  67. data/vendor/rlite/deps/lua/src/strbuf.h +154 -0
  68. data/vendor/rlite/src/Makefile +97 -25
  69. data/vendor/rlite/{deps → src}/crc64.c +0 -0
  70. data/vendor/rlite/{deps → src}/crc64.h +0 -0
  71. data/vendor/rlite/src/dump.c +2 -2
  72. data/vendor/rlite/{deps → src}/endianconv.h +0 -0
  73. data/vendor/rlite/src/hirlite.c +134 -90
  74. data/vendor/rlite/src/hirlite.h +34 -1
  75. data/vendor/rlite/{deps → src}/hyperloglog.c +0 -0
  76. data/vendor/rlite/{deps → src}/hyperloglog.h +0 -0
  77. data/vendor/rlite/{deps → src}/lzf.h +0 -0
  78. data/vendor/rlite/{deps → src}/lzfP.h +0 -0
  79. data/vendor/rlite/{deps → src}/lzf_c.c +0 -0
  80. data/vendor/rlite/{deps → src}/lzf_d.c +0 -0
  81. data/vendor/rlite/src/page_btree.c +10 -10
  82. data/vendor/rlite/src/page_btree.h +2 -2
  83. data/vendor/rlite/src/page_list.c +3 -3
  84. data/vendor/rlite/src/page_list.h +1 -1
  85. data/vendor/rlite/src/page_multi_string.c +1 -1
  86. data/vendor/rlite/src/page_skiplist.c +1 -1
  87. data/vendor/rlite/src/page_skiplist.h +1 -1
  88. data/vendor/rlite/src/rand.c +93 -0
  89. data/vendor/rlite/src/rand.h +38 -0
  90. data/vendor/rlite/src/restore.c +286 -155
  91. data/vendor/rlite/src/restore.h +6 -0
  92. data/vendor/rlite/src/rlite.c +30 -30
  93. data/vendor/rlite/src/rlite.h +1 -1
  94. data/vendor/rlite/src/scripting.c +1138 -0
  95. data/vendor/rlite/src/scripting.h +10 -0
  96. data/vendor/rlite/{deps → src}/sha1.c +0 -0
  97. data/vendor/rlite/{deps → src}/sha1.h +0 -0
  98. data/vendor/rlite/src/solarisfixes.h +54 -0
  99. data/vendor/rlite/src/sort.c +4 -2
  100. data/vendor/rlite/src/sort.h +1 -1
  101. data/vendor/rlite/src/type_string.c +1 -1
  102. data/vendor/rlite/src/util.c +4 -4
  103. data/vendor/rlite/src/util.h +3 -3
  104. data/vendor/rlite/{deps → src}/utilfromredis.c +0 -0
  105. data/vendor/rlite/{deps → src}/utilfromredis.h +0 -0
  106. metadata +84 -15
@@ -0,0 +1,82 @@
1
+ /*
2
+ ** $Id: lparser.h,v 1.57.1.1 2007/12/27 13:02:25 roberto Exp $
3
+ ** Lua Parser
4
+ ** See Copyright Notice in lua.h
5
+ */
6
+
7
+ #ifndef lparser_h
8
+ #define lparser_h
9
+
10
+ #include "llimits.h"
11
+ #include "lobject.h"
12
+ #include "lzio.h"
13
+
14
+
15
+ /*
16
+ ** Expression descriptor
17
+ */
18
+
19
+ typedef enum {
20
+ VVOID, /* no value */
21
+ VNIL,
22
+ VTRUE,
23
+ VFALSE,
24
+ VK, /* info = index of constant in `k' */
25
+ VKNUM, /* nval = numerical value */
26
+ VLOCAL, /* info = local register */
27
+ VUPVAL, /* info = index of upvalue in `upvalues' */
28
+ VGLOBAL, /* info = index of table; aux = index of global name in `k' */
29
+ VINDEXED, /* info = table register; aux = index register (or `k') */
30
+ VJMP, /* info = instruction pc */
31
+ VRELOCABLE, /* info = instruction pc */
32
+ VNONRELOC, /* info = result register */
33
+ VCALL, /* info = instruction pc */
34
+ VVARARG /* info = instruction pc */
35
+ } expkind;
36
+
37
+ typedef struct expdesc {
38
+ expkind k;
39
+ union {
40
+ struct { int info, aux; } s;
41
+ lua_Number nval;
42
+ } u;
43
+ int t; /* patch list of `exit when true' */
44
+ int f; /* patch list of `exit when false' */
45
+ } expdesc;
46
+
47
+
48
+ typedef struct upvaldesc {
49
+ lu_byte k;
50
+ lu_byte info;
51
+ } upvaldesc;
52
+
53
+
54
+ struct BlockCnt; /* defined in lparser.c */
55
+
56
+
57
+ /* state needed to generate code for a given function */
58
+ typedef struct FuncState {
59
+ Proto *f; /* current function header */
60
+ Table *h; /* table to find (and reuse) elements in `k' */
61
+ struct FuncState *prev; /* enclosing function */
62
+ struct LexState *ls; /* lexical state */
63
+ struct lua_State *L; /* copy of the Lua state */
64
+ struct BlockCnt *bl; /* chain of current blocks */
65
+ int pc; /* next position to code (equivalent to `ncode') */
66
+ int lasttarget; /* `pc' of last `jump target' */
67
+ int jpc; /* list of pending jumps to `pc' */
68
+ int freereg; /* first free register */
69
+ int nk; /* number of elements in `k' */
70
+ int np; /* number of elements in `p' */
71
+ short nlocvars; /* number of elements in `locvars' */
72
+ lu_byte nactvar; /* number of active local variables */
73
+ upvaldesc upvalues[LUAI_MAXUPVALUES]; /* upvalues */
74
+ unsigned short actvar[LUAI_MAXVARS]; /* declared-variable stack */
75
+ } FuncState;
76
+
77
+
78
+ LUAI_FUNC Proto *luaY_parser (lua_State *L, ZIO *z, Mbuffer *buff,
79
+ const char *name);
80
+
81
+
82
+ #endif
@@ -0,0 +1,214 @@
1
+ /*
2
+ ** $Id: lstate.c,v 2.36.1.2 2008/01/03 15:20:39 roberto Exp $
3
+ ** Global State
4
+ ** See Copyright Notice in lua.h
5
+ */
6
+
7
+
8
+ #include <stddef.h>
9
+
10
+ #define lstate_c
11
+ #define LUA_CORE
12
+
13
+ #include "lua.h"
14
+
15
+ #include "ldebug.h"
16
+ #include "ldo.h"
17
+ #include "lfunc.h"
18
+ #include "lgc.h"
19
+ #include "llex.h"
20
+ #include "lmem.h"
21
+ #include "lstate.h"
22
+ #include "lstring.h"
23
+ #include "ltable.h"
24
+ #include "ltm.h"
25
+
26
+
27
+ #define state_size(x) (sizeof(x) + LUAI_EXTRASPACE)
28
+ #define fromstate(l) (cast(lu_byte *, (l)) - LUAI_EXTRASPACE)
29
+ #define tostate(l) (cast(lua_State *, cast(lu_byte *, l) + LUAI_EXTRASPACE))
30
+
31
+
32
+ /*
33
+ ** Main thread combines a thread state and the global state
34
+ */
35
+ typedef struct LG {
36
+ lua_State l;
37
+ global_State g;
38
+ } LG;
39
+
40
+
41
+
42
+ static void stack_init (lua_State *L1, lua_State *L) {
43
+ /* initialize CallInfo array */
44
+ L1->base_ci = luaM_newvector(L, BASIC_CI_SIZE, CallInfo);
45
+ L1->ci = L1->base_ci;
46
+ L1->size_ci = BASIC_CI_SIZE;
47
+ L1->end_ci = L1->base_ci + L1->size_ci - 1;
48
+ /* initialize stack array */
49
+ L1->stack = luaM_newvector(L, BASIC_STACK_SIZE + EXTRA_STACK, TValue);
50
+ L1->stacksize = BASIC_STACK_SIZE + EXTRA_STACK;
51
+ L1->top = L1->stack;
52
+ L1->stack_last = L1->stack+(L1->stacksize - EXTRA_STACK)-1;
53
+ /* initialize first ci */
54
+ L1->ci->func = L1->top;
55
+ setnilvalue(L1->top++); /* `function' entry for this `ci' */
56
+ L1->base = L1->ci->base = L1->top;
57
+ L1->ci->top = L1->top + LUA_MINSTACK;
58
+ }
59
+
60
+
61
+ static void freestack (lua_State *L, lua_State *L1) {
62
+ luaM_freearray(L, L1->base_ci, L1->size_ci, CallInfo);
63
+ luaM_freearray(L, L1->stack, L1->stacksize, TValue);
64
+ }
65
+
66
+
67
+ /*
68
+ ** open parts that may cause memory-allocation errors
69
+ */
70
+ static void f_luaopen (lua_State *L, void *ud) {
71
+ global_State *g = G(L);
72
+ UNUSED(ud);
73
+ stack_init(L, L); /* init stack */
74
+ sethvalue(L, gt(L), luaH_new(L, 0, 2)); /* table of globals */
75
+ sethvalue(L, registry(L), luaH_new(L, 0, 2)); /* registry */
76
+ luaS_resize(L, MINSTRTABSIZE); /* initial size of string table */
77
+ luaT_init(L);
78
+ luaX_init(L);
79
+ luaS_fix(luaS_newliteral(L, MEMERRMSG));
80
+ g->GCthreshold = 4*g->totalbytes;
81
+ }
82
+
83
+
84
+ static void preinit_state (lua_State *L, global_State *g) {
85
+ G(L) = g;
86
+ L->stack = NULL;
87
+ L->stacksize = 0;
88
+ L->errorJmp = NULL;
89
+ L->hook = NULL;
90
+ L->hookmask = 0;
91
+ L->basehookcount = 0;
92
+ L->allowhook = 1;
93
+ resethookcount(L);
94
+ L->openupval = NULL;
95
+ L->size_ci = 0;
96
+ L->nCcalls = L->baseCcalls = 0;
97
+ L->status = 0;
98
+ L->base_ci = L->ci = NULL;
99
+ L->savedpc = NULL;
100
+ L->errfunc = 0;
101
+ setnilvalue(gt(L));
102
+ }
103
+
104
+
105
+ static void close_state (lua_State *L) {
106
+ global_State *g = G(L);
107
+ luaF_close(L, L->stack); /* close all upvalues for this thread */
108
+ luaC_freeall(L); /* collect all objects */
109
+ lua_assert(g->rootgc == obj2gco(L));
110
+ lua_assert(g->strt.nuse == 0);
111
+ luaM_freearray(L, G(L)->strt.hash, G(L)->strt.size, TString *);
112
+ luaZ_freebuffer(L, &g->buff);
113
+ freestack(L, L);
114
+ lua_assert(g->totalbytes == sizeof(LG));
115
+ (*g->frealloc)(g->ud, fromstate(L), state_size(LG), 0);
116
+ }
117
+
118
+
119
+ lua_State *luaE_newthread (lua_State *L) {
120
+ lua_State *L1 = tostate(luaM_malloc(L, state_size(lua_State)));
121
+ luaC_link(L, obj2gco(L1), LUA_TTHREAD);
122
+ preinit_state(L1, G(L));
123
+ stack_init(L1, L); /* init stack */
124
+ setobj2n(L, gt(L1), gt(L)); /* share table of globals */
125
+ L1->hookmask = L->hookmask;
126
+ L1->basehookcount = L->basehookcount;
127
+ L1->hook = L->hook;
128
+ resethookcount(L1);
129
+ lua_assert(iswhite(obj2gco(L1)));
130
+ return L1;
131
+ }
132
+
133
+
134
+ void luaE_freethread (lua_State *L, lua_State *L1) {
135
+ luaF_close(L1, L1->stack); /* close all upvalues for this thread */
136
+ lua_assert(L1->openupval == NULL);
137
+ luai_userstatefree(L1);
138
+ freestack(L, L1);
139
+ luaM_freemem(L, fromstate(L1), state_size(lua_State));
140
+ }
141
+
142
+
143
+ LUA_API lua_State *lua_newstate (lua_Alloc f, void *ud) {
144
+ int i;
145
+ lua_State *L;
146
+ global_State *g;
147
+ void *l = (*f)(ud, NULL, 0, state_size(LG));
148
+ if (l == NULL) return NULL;
149
+ L = tostate(l);
150
+ g = &((LG *)L)->g;
151
+ L->next = NULL;
152
+ L->tt = LUA_TTHREAD;
153
+ g->currentwhite = bit2mask(WHITE0BIT, FIXEDBIT);
154
+ L->marked = luaC_white(g);
155
+ set2bits(L->marked, FIXEDBIT, SFIXEDBIT);
156
+ preinit_state(L, g);
157
+ g->frealloc = f;
158
+ g->ud = ud;
159
+ g->mainthread = L;
160
+ g->uvhead.u.l.prev = &g->uvhead;
161
+ g->uvhead.u.l.next = &g->uvhead;
162
+ g->GCthreshold = 0; /* mark it as unfinished state */
163
+ g->strt.size = 0;
164
+ g->strt.nuse = 0;
165
+ g->strt.hash = NULL;
166
+ setnilvalue(registry(L));
167
+ luaZ_initbuffer(L, &g->buff);
168
+ g->panic = NULL;
169
+ g->gcstate = GCSpause;
170
+ g->rootgc = obj2gco(L);
171
+ g->sweepstrgc = 0;
172
+ g->sweepgc = &g->rootgc;
173
+ g->gray = NULL;
174
+ g->grayagain = NULL;
175
+ g->weak = NULL;
176
+ g->tmudata = NULL;
177
+ g->totalbytes = sizeof(LG);
178
+ g->gcpause = LUAI_GCPAUSE;
179
+ g->gcstepmul = LUAI_GCMUL;
180
+ g->gcdept = 0;
181
+ for (i=0; i<NUM_TAGS; i++) g->mt[i] = NULL;
182
+ if (luaD_rawrunprotected(L, f_luaopen, NULL) != 0) {
183
+ /* memory allocation error: free partial state */
184
+ close_state(L);
185
+ L = NULL;
186
+ }
187
+ else
188
+ luai_userstateopen(L);
189
+ return L;
190
+ }
191
+
192
+
193
+ static void callallgcTM (lua_State *L, void *ud) {
194
+ UNUSED(ud);
195
+ luaC_callGCTM(L); /* call GC metamethods for all udata */
196
+ }
197
+
198
+
199
+ LUA_API void lua_close (lua_State *L) {
200
+ L = G(L)->mainthread; /* only the main thread can be closed */
201
+ lua_lock(L);
202
+ luaF_close(L, L->stack); /* close all upvalues for this thread */
203
+ luaC_separateudata(L, 1); /* separate udata that have GC metamethods */
204
+ L->errfunc = 0; /* no error function during GC metamethods */
205
+ do { /* repeat until no more errors */
206
+ L->ci = L->base_ci;
207
+ L->base = L->top = L->ci->base;
208
+ L->nCcalls = L->baseCcalls = 0;
209
+ } while (luaD_rawrunprotected(L, callallgcTM, NULL) != 0);
210
+ lua_assert(G(L)->tmudata == NULL);
211
+ luai_userstateclose(L);
212
+ close_state(L);
213
+ }
214
+
@@ -0,0 +1,169 @@
1
+ /*
2
+ ** $Id: lstate.h,v 2.24.1.2 2008/01/03 15:20:39 roberto Exp $
3
+ ** Global State
4
+ ** See Copyright Notice in lua.h
5
+ */
6
+
7
+ #ifndef lstate_h
8
+ #define lstate_h
9
+
10
+ #include "lua.h"
11
+
12
+ #include "lobject.h"
13
+ #include "ltm.h"
14
+ #include "lzio.h"
15
+
16
+
17
+
18
+ struct lua_longjmp; /* defined in ldo.c */
19
+
20
+
21
+ /* table of globals */
22
+ #define gt(L) (&L->l_gt)
23
+
24
+ /* registry */
25
+ #define registry(L) (&G(L)->l_registry)
26
+
27
+
28
+ /* extra stack space to handle TM calls and some other extras */
29
+ #define EXTRA_STACK 5
30
+
31
+
32
+ #define BASIC_CI_SIZE 8
33
+
34
+ #define BASIC_STACK_SIZE (2*LUA_MINSTACK)
35
+
36
+
37
+
38
+ typedef struct stringtable {
39
+ GCObject **hash;
40
+ lu_int32 nuse; /* number of elements */
41
+ int size;
42
+ } stringtable;
43
+
44
+
45
+ /*
46
+ ** informations about a call
47
+ */
48
+ typedef struct CallInfo {
49
+ StkId base; /* base for this function */
50
+ StkId func; /* function index in the stack */
51
+ StkId top; /* top for this function */
52
+ const Instruction *savedpc;
53
+ int nresults; /* expected number of results from this function */
54
+ int tailcalls; /* number of tail calls lost under this entry */
55
+ } CallInfo;
56
+
57
+
58
+
59
+ #define curr_func(L) (clvalue(L->ci->func))
60
+ #define ci_func(ci) (clvalue((ci)->func))
61
+ #define f_isLua(ci) (!ci_func(ci)->c.isC)
62
+ #define isLua(ci) (ttisfunction((ci)->func) && f_isLua(ci))
63
+
64
+
65
+ /*
66
+ ** `global state', shared by all threads of this state
67
+ */
68
+ typedef struct global_State {
69
+ stringtable strt; /* hash table for strings */
70
+ lua_Alloc frealloc; /* function to reallocate memory */
71
+ void *ud; /* auxiliary data to `frealloc' */
72
+ lu_byte currentwhite;
73
+ lu_byte gcstate; /* state of garbage collector */
74
+ int sweepstrgc; /* position of sweep in `strt' */
75
+ GCObject *rootgc; /* list of all collectable objects */
76
+ GCObject **sweepgc; /* position of sweep in `rootgc' */
77
+ GCObject *gray; /* list of gray objects */
78
+ GCObject *grayagain; /* list of objects to be traversed atomically */
79
+ GCObject *weak; /* list of weak tables (to be cleared) */
80
+ GCObject *tmudata; /* last element of list of userdata to be GC */
81
+ Mbuffer buff; /* temporary buffer for string concatentation */
82
+ lu_mem GCthreshold;
83
+ lu_mem totalbytes; /* number of bytes currently allocated */
84
+ lu_mem estimate; /* an estimate of number of bytes actually in use */
85
+ lu_mem gcdept; /* how much GC is `behind schedule' */
86
+ int gcpause; /* size of pause between successive GCs */
87
+ int gcstepmul; /* GC `granularity' */
88
+ lua_CFunction panic; /* to be called in unprotected errors */
89
+ TValue l_registry;
90
+ struct lua_State *mainthread;
91
+ UpVal uvhead; /* head of double-linked list of all open upvalues */
92
+ struct Table *mt[NUM_TAGS]; /* metatables for basic types */
93
+ TString *tmname[TM_N]; /* array with tag-method names */
94
+ } global_State;
95
+
96
+
97
+ /*
98
+ ** `per thread' state
99
+ */
100
+ struct lua_State {
101
+ CommonHeader;
102
+ lu_byte status;
103
+ StkId top; /* first free slot in the stack */
104
+ StkId base; /* base of current function */
105
+ global_State *l_G;
106
+ CallInfo *ci; /* call info for current function */
107
+ const Instruction *savedpc; /* `savedpc' of current function */
108
+ StkId stack_last; /* last free slot in the stack */
109
+ StkId stack; /* stack base */
110
+ CallInfo *end_ci; /* points after end of ci array*/
111
+ CallInfo *base_ci; /* array of CallInfo's */
112
+ int stacksize;
113
+ int size_ci; /* size of array `base_ci' */
114
+ unsigned short nCcalls; /* number of nested C calls */
115
+ unsigned short baseCcalls; /* nested C calls when resuming coroutine */
116
+ lu_byte hookmask;
117
+ lu_byte allowhook;
118
+ int basehookcount;
119
+ int hookcount;
120
+ lua_Hook hook;
121
+ TValue l_gt; /* table of globals */
122
+ TValue env; /* temporary place for environments */
123
+ GCObject *openupval; /* list of open upvalues in this stack */
124
+ GCObject *gclist;
125
+ struct lua_longjmp *errorJmp; /* current error recover point */
126
+ ptrdiff_t errfunc; /* current error handling function (stack index) */
127
+ };
128
+
129
+
130
+ #define G(L) (L->l_G)
131
+
132
+
133
+ /*
134
+ ** Union of all collectable objects
135
+ */
136
+ union GCObject {
137
+ GCheader gch;
138
+ union TString ts;
139
+ union Udata u;
140
+ union Closure cl;
141
+ struct Table h;
142
+ struct Proto p;
143
+ struct UpVal uv;
144
+ struct lua_State th; /* thread */
145
+ };
146
+
147
+
148
+ /* macros to convert a GCObject into a specific value */
149
+ #define rawgco2ts(o) check_exp((o)->gch.tt == LUA_TSTRING, &((o)->ts))
150
+ #define gco2ts(o) (&rawgco2ts(o)->tsv)
151
+ #define rawgco2u(o) check_exp((o)->gch.tt == LUA_TUSERDATA, &((o)->u))
152
+ #define gco2u(o) (&rawgco2u(o)->uv)
153
+ #define gco2cl(o) check_exp((o)->gch.tt == LUA_TFUNCTION, &((o)->cl))
154
+ #define gco2h(o) check_exp((o)->gch.tt == LUA_TTABLE, &((o)->h))
155
+ #define gco2p(o) check_exp((o)->gch.tt == LUA_TPROTO, &((o)->p))
156
+ #define gco2uv(o) check_exp((o)->gch.tt == LUA_TUPVAL, &((o)->uv))
157
+ #define ngcotouv(o) \
158
+ check_exp((o) == NULL || (o)->gch.tt == LUA_TUPVAL, &((o)->uv))
159
+ #define gco2th(o) check_exp((o)->gch.tt == LUA_TTHREAD, &((o)->th))
160
+
161
+ /* macro to convert any Lua object into a GCObject */
162
+ #define obj2gco(v) (cast(GCObject *, (v)))
163
+
164
+
165
+ LUAI_FUNC lua_State *luaE_newthread (lua_State *L);
166
+ LUAI_FUNC void luaE_freethread (lua_State *L, lua_State *L1);
167
+
168
+ #endif
169
+
@@ -0,0 +1,111 @@
1
+ /*
2
+ ** $Id: lstring.c,v 2.8.1.1 2007/12/27 13:02:25 roberto Exp $
3
+ ** String table (keeps all strings handled by Lua)
4
+ ** See Copyright Notice in lua.h
5
+ */
6
+
7
+
8
+ #include <string.h>
9
+
10
+ #define lstring_c
11
+ #define LUA_CORE
12
+
13
+ #include "lua.h"
14
+
15
+ #include "lmem.h"
16
+ #include "lobject.h"
17
+ #include "lstate.h"
18
+ #include "lstring.h"
19
+
20
+
21
+
22
+ void luaS_resize (lua_State *L, int newsize) {
23
+ GCObject **newhash;
24
+ stringtable *tb;
25
+ int i;
26
+ if (G(L)->gcstate == GCSsweepstring)
27
+ return; /* cannot resize during GC traverse */
28
+ newhash = luaM_newvector(L, newsize, GCObject *);
29
+ tb = &G(L)->strt;
30
+ for (i=0; i<newsize; i++) newhash[i] = NULL;
31
+ /* rehash */
32
+ for (i=0; i<tb->size; i++) {
33
+ GCObject *p = tb->hash[i];
34
+ while (p) { /* for each node in the list */
35
+ GCObject *next = p->gch.next; /* save next */
36
+ unsigned int h = gco2ts(p)->hash;
37
+ int h1 = lmod(h, newsize); /* new position */
38
+ lua_assert(cast_int(h%newsize) == lmod(h, newsize));
39
+ p->gch.next = newhash[h1]; /* chain it */
40
+ newhash[h1] = p;
41
+ p = next;
42
+ }
43
+ }
44
+ luaM_freearray(L, tb->hash, tb->size, TString *);
45
+ tb->size = newsize;
46
+ tb->hash = newhash;
47
+ }
48
+
49
+
50
+ static TString *newlstr (lua_State *L, const char *str, size_t l,
51
+ unsigned int h) {
52
+ TString *ts;
53
+ stringtable *tb;
54
+ if (l+1 > (MAX_SIZET - sizeof(TString))/sizeof(char))
55
+ luaM_toobig(L);
56
+ ts = cast(TString *, luaM_malloc(L, (l+1)*sizeof(char)+sizeof(TString)));
57
+ ts->tsv.len = l;
58
+ ts->tsv.hash = h;
59
+ ts->tsv.marked = luaC_white(G(L));
60
+ ts->tsv.tt = LUA_TSTRING;
61
+ ts->tsv.reserved = 0;
62
+ memcpy(ts+1, str, l*sizeof(char));
63
+ ((char *)(ts+1))[l] = '\0'; /* ending 0 */
64
+ tb = &G(L)->strt;
65
+ h = lmod(h, tb->size);
66
+ ts->tsv.next = tb->hash[h]; /* chain new entry */
67
+ tb->hash[h] = obj2gco(ts);
68
+ tb->nuse++;
69
+ if (tb->nuse > cast(lu_int32, tb->size) && tb->size <= MAX_INT/2)
70
+ luaS_resize(L, tb->size*2); /* too crowded */
71
+ return ts;
72
+ }
73
+
74
+
75
+ TString *luaS_newlstr (lua_State *L, const char *str, size_t l) {
76
+ GCObject *o;
77
+ unsigned int h = cast(unsigned int, l); /* seed */
78
+ size_t step = (l>>5)+1; /* if string is too long, don't hash all its chars */
79
+ size_t l1;
80
+ for (l1=l; l1>=step; l1-=step) /* compute hash */
81
+ h = h ^ ((h<<5)+(h>>2)+cast(unsigned char, str[l1-1]));
82
+ for (o = G(L)->strt.hash[lmod(h, G(L)->strt.size)];
83
+ o != NULL;
84
+ o = o->gch.next) {
85
+ TString *ts = rawgco2ts(o);
86
+ if (ts->tsv.len == l && (memcmp(str, getstr(ts), l) == 0)) {
87
+ /* string may be dead */
88
+ if (isdead(G(L), o)) changewhite(o);
89
+ return ts;
90
+ }
91
+ }
92
+ return newlstr(L, str, l, h); /* not found */
93
+ }
94
+
95
+
96
+ Udata *luaS_newudata (lua_State *L, size_t s, Table *e) {
97
+ Udata *u;
98
+ if (s > MAX_SIZET - sizeof(Udata))
99
+ luaM_toobig(L);
100
+ u = cast(Udata *, luaM_malloc(L, s + sizeof(Udata)));
101
+ u->uv.marked = luaC_white(G(L)); /* is not finalized */
102
+ u->uv.tt = LUA_TUSERDATA;
103
+ u->uv.len = s;
104
+ u->uv.metatable = NULL;
105
+ u->uv.env = e;
106
+ /* chain it on udata list (after main thread) */
107
+ u->uv.next = G(L)->mainthread->next;
108
+ G(L)->mainthread->next = obj2gco(u);
109
+ return u;
110
+ }
111
+
@@ -0,0 +1,31 @@
1
+ /*
2
+ ** $Id: lstring.h,v 1.43.1.1 2007/12/27 13:02:25 roberto Exp $
3
+ ** String table (keep all strings handled by Lua)
4
+ ** See Copyright Notice in lua.h
5
+ */
6
+
7
+ #ifndef lstring_h
8
+ #define lstring_h
9
+
10
+
11
+ #include "lgc.h"
12
+ #include "lobject.h"
13
+ #include "lstate.h"
14
+
15
+
16
+ #define sizestring(s) (sizeof(union TString)+((s)->len+1)*sizeof(char))
17
+
18
+ #define sizeudata(u) (sizeof(union Udata)+(u)->len)
19
+
20
+ #define luaS_new(L, s) (luaS_newlstr(L, s, strlen(s)))
21
+ #define luaS_newliteral(L, s) (luaS_newlstr(L, "" s, \
22
+ (sizeof(s)/sizeof(char))-1))
23
+
24
+ #define luaS_fix(s) l_setbit((s)->tsv.marked, FIXEDBIT)
25
+
26
+ LUAI_FUNC void luaS_resize (lua_State *L, int newsize);
27
+ LUAI_FUNC Udata *luaS_newudata (lua_State *L, size_t s, Table *e);
28
+ LUAI_FUNC TString *luaS_newlstr (lua_State *L, const char *str, size_t l);
29
+
30
+
31
+ #endif