diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1997-09-26 12:02:26 -0300 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1997-09-26 12:02:26 -0300 |
| commit | a580480b07cdf7201306b246deeb2fe84f2c25a9 (patch) | |
| tree | 30e9d4798228156eea5be2589834f1ff2db4355e /lobject.h | |
| parent | 0dd6d1080e7f58eb17cb8a2ad3fc5801ed7c0532 (diff) | |
| download | lua-a580480b07cdf7201306b246deeb2fe84f2c25a9.tar.gz lua-a580480b07cdf7201306b246deeb2fe84f2c25a9.tar.bz2 lua-a580480b07cdf7201306b246deeb2fe84f2c25a9.zip | |
new implementation for globals: Global value is stored in TaggedString
Diffstat (limited to 'lobject.h')
| -rw-r--r-- | lobject.h | 113 |
1 files changed, 55 insertions, 58 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: $ | 2 | ** $Id: lobject.h,v 1.1 1997/09/16 19:25:59 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 | */ |
| @@ -29,30 +29,43 @@ typedef unsigned short Word; /* unsigned 16 bits */ | |||
| 29 | typedef unsigned int IntPoint; /* unsigned with same size as a pointer (for hashing) */ | 29 | typedef unsigned int IntPoint; /* unsigned with same size as a pointer (for hashing) */ |
| 30 | 30 | ||
| 31 | 31 | ||
| 32 | |||
| 33 | |||
| 34 | /* | 32 | /* |
| 35 | ** String headers for string table | 33 | ** Lua TYPES |
| 34 | ** WARNING: if you change the order of this enumeration, | ||
| 35 | ** grep "ORDER LUA_T" | ||
| 36 | */ | 36 | */ |
| 37 | typedef enum { | ||
| 38 | LUA_T_NIL = -10, | ||
| 39 | LUA_T_NUMBER = -9, | ||
| 40 | LUA_T_STRING = -8, | ||
| 41 | LUA_T_ARRAY = -7, /* array==table */ | ||
| 42 | LUA_T_PROTO = -6, | ||
| 43 | LUA_T_FUNCTION = -5, | ||
| 44 | LUA_T_CFUNCTION= -4, | ||
| 45 | LUA_T_MARK = -3, | ||
| 46 | LUA_T_CMARK = -2, | ||
| 47 | LUA_T_LINE = -1, | ||
| 48 | LUA_T_USERDATA = 0 | ||
| 49 | } lua_Type; | ||
| 37 | 50 | ||
| 38 | #define NOT_USED 0xFFFE | 51 | #define NUM_TYPES 11 |
| 52 | |||
| 53 | |||
| 54 | typedef union { | ||
| 55 | lua_CFunction f; /* LUA_T_CFUNCTION, LUA_T_CMARK */ | ||
| 56 | real n; /* LUA_T_NUMBER */ | ||
| 57 | struct TaggedString *ts; /* LUA_T_STRING, LUA_T_USERDATA */ | ||
| 58 | struct TProtoFunc *tf; /* LUA_T_PROTO */ | ||
| 59 | struct Closure *cl; /* LUA_T_FUNCTION, LUA_T_MARK */ | ||
| 60 | struct Hash *a; /* LUA_T_ARRAY */ | ||
| 61 | int i; /* LUA_T_LINE */ | ||
| 62 | } Value; | ||
| 39 | 63 | ||
| 40 | typedef struct TaggedString { | 64 | |
| 41 | int tag; /* if != LUA_T_STRING, this is a userdata */ | 65 | typedef struct TObject { |
| 42 | union { | 66 | lua_Type ttype; |
| 43 | unsigned long hash; | 67 | Value value; |
| 44 | struct TaggedString *next; | 68 | } TObject; |
| 45 | } uu; | ||
| 46 | union { | ||
| 47 | struct { | ||
| 48 | Word varindex; /* != NOT_USED if this is a symbol */ | ||
| 49 | Word constindex; /* hint to reuse constant indexes */ | ||
| 50 | } s; | ||
| 51 | void *v; /* if this is a userdata, here is its value */ | ||
| 52 | } u; | ||
| 53 | int marked; /* for garbage collection; never collect (nor change) if > 1 */ | ||
| 54 | char str[1]; /* \0 byte already reserved */ | ||
| 55 | } TaggedString; | ||
| 56 | 69 | ||
| 57 | 70 | ||
| 58 | 71 | ||
| @@ -66,6 +79,27 @@ typedef struct GCnode { | |||
| 66 | 79 | ||
| 67 | 80 | ||
| 68 | /* | 81 | /* |
| 82 | ** String headers for string table | ||
| 83 | */ | ||
| 84 | |||
| 85 | typedef struct TaggedString { | ||
| 86 | GCnode head; | ||
| 87 | int constindex; /* hint to reuse constants (= -1 if this is a userdata) */ | ||
| 88 | unsigned long hash; | ||
| 89 | union { | ||
| 90 | TObject globalval; | ||
| 91 | struct { | ||
| 92 | void *v; /* if this is a userdata, here is its value */ | ||
| 93 | int tag; | ||
| 94 | } d; | ||
| 95 | } u; | ||
| 96 | char str[1]; /* \0 byte already reserved */ | ||
| 97 | } TaggedString; | ||
| 98 | |||
| 99 | |||
| 100 | |||
| 101 | |||
| 102 | /* | ||
| 69 | ** Function Prototypes | 103 | ** Function Prototypes |
| 70 | */ | 104 | */ |
| 71 | typedef struct TProtoFunc { | 105 | typedef struct TProtoFunc { |
| @@ -87,43 +121,6 @@ typedef struct LocVar { | |||
| 87 | 121 | ||
| 88 | 122 | ||
| 89 | 123 | ||
| 90 | /* | ||
| 91 | ** Lua TYPES | ||
| 92 | ** WARNING: if you change the order of this enumeration, | ||
| 93 | ** grep "ORDER LUA_T" | ||
| 94 | */ | ||
| 95 | typedef enum { | ||
| 96 | LUA_T_NIL = -10, | ||
| 97 | LUA_T_NUMBER = -9, | ||
| 98 | LUA_T_STRING = -8, | ||
| 99 | LUA_T_ARRAY = -7, /* array==table */ | ||
| 100 | LUA_T_PROTO = -6, | ||
| 101 | LUA_T_FUNCTION = -5, | ||
| 102 | LUA_T_CFUNCTION= -4, | ||
| 103 | LUA_T_MARK = -3, | ||
| 104 | LUA_T_CMARK = -2, | ||
| 105 | LUA_T_LINE = -1, | ||
| 106 | LUA_T_USERDATA = 0 | ||
| 107 | } lua_Type; | ||
| 108 | |||
| 109 | #define NUM_TYPES 11 | ||
| 110 | |||
| 111 | |||
| 112 | typedef union { | ||
| 113 | lua_CFunction f; | ||
| 114 | real n; | ||
| 115 | TaggedString *ts; | ||
| 116 | TProtoFunc *tf; | ||
| 117 | struct Closure *cl; | ||
| 118 | struct Hash *a; | ||
| 119 | int i; | ||
| 120 | } Value; | ||
| 121 | |||
| 122 | typedef struct TObject { | ||
| 123 | lua_Type ttype; | ||
| 124 | Value value; | ||
| 125 | } TObject; | ||
| 126 | |||
| 127 | 124 | ||
| 128 | /* Macros to access structure members */ | 125 | /* Macros to access structure members */ |
| 129 | #define ttype(o) ((o)->ttype) | 126 | #define ttype(o) ((o)->ttype) |
