aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>1997-11-19 15:31:19 -0200
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>1997-11-19 15:31:19 -0200
commitb79ffdc4cef96ababe0cc068a6c11afdc71782eb (patch)
tree3900162dc96b809924852bcb5105109bc77eac6c
parent592a3f289b428e3ee5cc595a266607ad7f5d94ff (diff)
downloadlua-b79ffdc4cef96ababe0cc068a6c11afdc71782eb.tar.gz
lua-b79ffdc4cef96ababe0cc068a6c11afdc71782eb.tar.bz2
lua-b79ffdc4cef96ababe0cc068a6c11afdc71782eb.zip
global state for Lua interpreter
-rw-r--r--lstate.c52
-rw-r--r--lstate.h82
2 files changed, 134 insertions, 0 deletions
diff --git a/lstate.c b/lstate.c
new file mode 100644
index 00000000..653c4ba3
--- /dev/null
+++ b/lstate.c
@@ -0,0 +1,52 @@
1/*
2** $Id: $
3** Global State
4** See Copyright Notice in lua.h
5*/
6
7
8#include "lbuiltin.h"
9#include "ldo.h"
10#include "llex.h"
11#include "lmem.h"
12#include "lstate.h"
13#include "lstring.h"
14#include "ltable.h"
15#include "ltm.h"
16
17
18LState *lua_state = NULL;
19
20
21void lua_open (void)
22{
23 if (lua_state) return;
24 lua_state = luaM_new(LState);
25 L->numCblocks = 0;
26 L->Cstack.base = 0;
27 L->Cstack.lua2C = 0;
28 L->Cstack.num = 0;
29 L->errorJmp = NULL;
30 L->rootproto.next = NULL;
31 L->rootproto.marked = 0;
32 L->rootcl.next = NULL;
33 L->rootcl.marked = 0;
34 L->rootglobal.next = NULL;
35 L->rootglobal.marked = 0;
36 L->roottable.next = NULL;
37 L->roottable.marked = 0;
38 L->refArray = NULL;
39 L->refSize = 0;
40 L->Mbuffsize = 0;
41 L->Mbuffer = NULL;
42 L->GCthreshold = GARBAGE_BLOCK;
43 L->nblocks = 0;
44 luaD_init();
45 luaS_init();
46 luaX_init();
47 luaT_init();
48 L->globalbag.ttype = LUA_T_ARRAY;
49 L->globalbag.value.a = luaH_new(0);
50 luaB_predefine();
51}
52
diff --git a/lstate.h b/lstate.h
new file mode 100644
index 00000000..45897d5b
--- /dev/null
+++ b/lstate.h
@@ -0,0 +1,82 @@
1/*
2** $Id: $
3** Global State
4** See Copyright Notice in lua.h
5*/
6
7#ifndef lstate_h
8#define lstate_h
9
10#include "lobject.h"
11
12
13#define MAX_C_BLOCKS 10
14
15#define GARBAGE_BLOCK 150
16
17
18typedef int StkId; /* index to stack elements */
19
20struct Stack {
21 TObject *last;
22 TObject *stack;
23 TObject *top;
24};
25
26struct C_Lua_Stack {
27 StkId base; /* when Lua calls C or C calls Lua, points to */
28 /* the first slot after the last parameter. */
29 StkId lua2C; /* points to first element of "array" lua2C */
30 int num; /* size of "array" lua2C */
31};
32
33
34typedef struct {
35 int size;
36 int nuse; /* number of elements (including EMPTYs) */
37 TaggedString **hash;
38} stringtable;
39
40
41struct ref {
42 TObject o;
43 enum {LOCK, HOLD, FREE, COLLECTED} status;
44};
45
46
47typedef struct LState {
48 struct C_Lua_Stack Cblocks[MAX_C_BLOCKS];
49 int numCblocks; /* number of nested Cblocks */
50 TObject *functofind; /* auxiliar */
51 struct Stack stack; /* Lua stack */
52 struct C_Lua_Stack Cstack; /* C2lua struct */
53 int stacklimit; /* limit for stack overflow */
54 void *errorJmp; /* current error recover point */
55 TObject errorim; /* error tag method */
56 GCnode rootproto; /* list of all prototypes */
57 GCnode rootcl; /* list of all closures */
58 GCnode roottable; /* list of all tables */
59 GCnode rootglobal; /* list of strings with global values */
60 stringtable *string_root; /* array of hash tables for strings and udata */
61 struct IM *IMtable; /* table for tag methods */
62 int IMtable_size; /* size of IMtable */
63 int last_tag; /* last used tag in IMtable */
64 struct FuncState *mainState, *currState; /* point to local structs in yacc */
65 struct LexState *lexstate; /* point to local struct in yacc */
66 struct ref *refArray; /* locked objects */
67 int refSize; /* size of refArray */
68 unsigned long GCthreshold;
69 unsigned long nblocks; /* number of 'blocks' currently allocated */
70 TObject globalbag; /* table for generic use by C */
71 char *Mbuffer; /* global buffer, used by luaM_buffer */
72 unsigned long Mbuffsize; /* size of Mbuffer */
73} LState;
74
75
76extern LState *lua_state;
77
78
79#define L lua_state
80
81
82#endif