diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2000-03-29 17:19:20 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2000-03-29 17:19:20 -0300 |
commit | a69356e9e0a7525b1cebadc928a0efcce8c39b46 (patch) | |
tree | c676ee2997c699d3e0b036323ecbafa7ea0d786f /lobject.h | |
parent | b53dc0c4853c56694dda727793e5f6188de39dd8 (diff) | |
download | lua-a69356e9e0a7525b1cebadc928a0efcce8c39b46.tar.gz lua-a69356e9e0a7525b1cebadc928a0efcce8c39b46.tar.bz2 lua-a69356e9e0a7525b1cebadc928a0efcce8c39b46.zip |
no more special cases for closures with 0 upvalues (performance is the same,
memory use a little higher, code much simpler).
Diffstat (limited to 'lobject.h')
-rw-r--r-- | lobject.h | 61 |
1 files changed, 29 insertions, 32 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lobject.h,v 1.55 2000/03/24 19:49:23 roberto Exp roberto $ | 2 | ** $Id: lobject.h,v 1.56 2000/03/27 20:10:21 roberto Exp roberto $ |
3 | ** Type definitions for Lua objects | 3 | ** Type definitions for Lua objects |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -23,7 +23,12 @@ | |||
23 | #endif | 23 | #endif |
24 | 24 | ||
25 | 25 | ||
26 | #ifdef DEBUG | ||
27 | /* to avoid warnings and make sure is is really unused */ | ||
28 | #define UNUSED(x) (x=0, (void)x) | ||
29 | #else | ||
26 | #define UNUSED(x) (void)x /* to avoid warnings */ | 30 | #define UNUSED(x) (void)x /* to avoid warnings */ |
31 | #endif | ||
27 | 32 | ||
28 | 33 | ||
29 | /* | 34 | /* |
@@ -36,17 +41,12 @@ typedef enum { | |||
36 | TAG_NUMBER, /* fixed tag for numbers */ | 41 | TAG_NUMBER, /* fixed tag for numbers */ |
37 | TAG_STRING, /* fixed tag for strings */ | 42 | TAG_STRING, /* fixed tag for strings */ |
38 | TAG_TABLE, /* default tag for tables */ | 43 | TAG_TABLE, /* default tag for tables */ |
39 | TAG_LPROTO, /* fixed tag for Lua functions */ | 44 | TAG_LCLOSURE, /* fixed tag for Lua closures */ |
40 | TAG_CPROTO, /* fixed tag for C functions */ | 45 | TAG_CCLOSURE, /* fixed tag for C closures */ |
41 | TAG_NIL, /* last "pre-defined" tag */ | 46 | TAG_NIL, /* last "pre-defined" tag */ |
42 | 47 | ||
43 | TAG_LCLOSURE, /* Lua closure */ | ||
44 | TAG_CCLOSURE, /* C closure */ | ||
45 | |||
46 | TAG_LCLMARK, /* mark for Lua closures */ | 48 | TAG_LCLMARK, /* mark for Lua closures */ |
47 | TAG_CCLMARK, /* mark for C closures */ | 49 | TAG_CCLMARK, /* mark for C closures */ |
48 | TAG_LMARK, /* mark for Lua prototypes */ | ||
49 | TAG_CMARK, /* mark for C prototypes */ | ||
50 | 50 | ||
51 | TAG_LINE | 51 | TAG_LINE |
52 | } lua_Type; | 52 | } lua_Type; |
@@ -58,20 +58,27 @@ typedef enum { | |||
58 | /* | 58 | /* |
59 | ** check whether `t' is a mark | 59 | ** check whether `t' is a mark |
60 | */ | 60 | */ |
61 | #define is_T_MARK(t) (TAG_LCLMARK <= (t) && (t) <= TAG_CMARK) | 61 | #define is_T_MARK(t) ((t) == TAG_LCLMARK || (t) == TAG_CCLMARK) |
62 | 62 | ||
63 | 63 | ||
64 | typedef union { | 64 | typedef union { |
65 | lua_CFunction f; /* TAG_CPROTO, TAG_CMARK */ | 65 | struct TString *ts; /* TAG_STRING, TAG_USERDATA */ |
66 | Number n; /* TAG_NUMBER */ | 66 | struct Closure *cl; /* TAG_[CL]CLOSURE, TAG_[CL]CLMARK */ |
67 | struct TString *ts; /* TAG_STRING, TAG_USERDATA */ | 67 | struct Hash *a; /* TAG_TABLE */ |
68 | struct Proto *tf; /* TAG_LPROTO, TAG_LMARK */ | 68 | Number n; /* TAG_NUMBER */ |
69 | struct Closure *cl; /* TAG_[CL]CLOSURE, TAG_[CL]CLMARK */ | 69 | int i; /* TAG_LINE */ |
70 | struct Hash *a; /* TAG_TABLE */ | ||
71 | int i; /* TAG_LINE */ | ||
72 | } Value; | 70 | } Value; |
73 | 71 | ||
74 | 72 | ||
73 | /* Macros to access values */ | ||
74 | #define ttype(o) ((o)->ttype) | ||
75 | #define nvalue(o) ((o)->value.n) | ||
76 | #define svalue(o) ((o)->value.ts->str) | ||
77 | #define tsvalue(o) ((o)->value.ts) | ||
78 | #define clvalue(o) ((o)->value.cl) | ||
79 | #define avalue(o) ((o)->value.a) | ||
80 | |||
81 | |||
75 | typedef struct TObject { | 82 | typedef struct TObject { |
76 | lua_Type ttype; | 83 | lua_Type ttype; |
77 | Value value; | 84 | Value value; |
@@ -135,28 +142,18 @@ typedef struct LocVar { | |||
135 | } LocVar; | 142 | } LocVar; |
136 | 143 | ||
137 | 144 | ||
138 | |||
139 | /* Macros to access structure members */ | ||
140 | #define ttype(o) ((o)->ttype) | ||
141 | #define nvalue(o) ((o)->value.n) | ||
142 | #define svalue(o) ((o)->value.ts->str) | ||
143 | #define tsvalue(o) ((o)->value.ts) | ||
144 | #define clvalue(o) ((o)->value.cl) | ||
145 | #define avalue(o) ((o)->value.a) | ||
146 | #define fvalue(o) ((o)->value.f) | ||
147 | #define tfvalue(o) ((o)->value.tf) | ||
148 | |||
149 | #define protovalue(o) ((o)->value.cl->consts) | ||
150 | |||
151 | |||
152 | /* | 145 | /* |
153 | ** Closures | 146 | ** Closures |
154 | */ | 147 | */ |
155 | typedef struct Closure { | 148 | typedef struct Closure { |
156 | struct Closure *next; | 149 | struct Closure *next; |
157 | int marked; | 150 | int marked; |
158 | int nelems; /* not including the first one (always the prototype) */ | 151 | union { |
159 | TObject consts[1]; /* at least one for prototype */ | 152 | lua_CFunction c; /* C functions */ |
153 | struct Proto *l; /* Lua functions */ | ||
154 | } f; | ||
155 | int nelems; | ||
156 | TObject consts[1]; | ||
160 | } Closure; | 157 | } Closure; |
161 | 158 | ||
162 | 159 | ||