From a580480b07cdf7201306b246deeb2fe84f2c25a9 Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Fri, 26 Sep 1997 12:02:26 -0300 Subject: new implementation for globals: Global value is stored in TaggedString --- lobject.h | 113 ++++++++++++++++++++++++++++++-------------------------------- 1 file changed, 55 insertions(+), 58 deletions(-) (limited to 'lobject.h') diff --git a/lobject.h b/lobject.h index 710d4a6a..398155f2 100644 --- a/lobject.h +++ b/lobject.h @@ -1,5 +1,5 @@ /* -** $Id: $ +** $Id: lobject.h,v 1.1 1997/09/16 19:25:59 roberto Exp roberto $ ** Type definitions for Lua objects ** See Copyright Notice in lua.h */ @@ -29,30 +29,43 @@ typedef unsigned short Word; /* unsigned 16 bits */ typedef unsigned int IntPoint; /* unsigned with same size as a pointer (for hashing) */ - - /* -** String headers for string table +** Lua TYPES +** WARNING: if you change the order of this enumeration, +** grep "ORDER LUA_T" */ +typedef enum { + LUA_T_NIL = -10, + LUA_T_NUMBER = -9, + LUA_T_STRING = -8, + LUA_T_ARRAY = -7, /* array==table */ + LUA_T_PROTO = -6, + LUA_T_FUNCTION = -5, + LUA_T_CFUNCTION= -4, + LUA_T_MARK = -3, + LUA_T_CMARK = -2, + LUA_T_LINE = -1, + LUA_T_USERDATA = 0 +} lua_Type; -#define NOT_USED 0xFFFE +#define NUM_TYPES 11 + + +typedef union { + lua_CFunction f; /* LUA_T_CFUNCTION, LUA_T_CMARK */ + real n; /* LUA_T_NUMBER */ + struct TaggedString *ts; /* LUA_T_STRING, LUA_T_USERDATA */ + struct TProtoFunc *tf; /* LUA_T_PROTO */ + struct Closure *cl; /* LUA_T_FUNCTION, LUA_T_MARK */ + struct Hash *a; /* LUA_T_ARRAY */ + int i; /* LUA_T_LINE */ +} Value; -typedef struct TaggedString { - int tag; /* if != LUA_T_STRING, this is a userdata */ - union { - unsigned long hash; - struct TaggedString *next; - } uu; - union { - struct { - Word varindex; /* != NOT_USED if this is a symbol */ - Word constindex; /* hint to reuse constant indexes */ - } s; - void *v; /* if this is a userdata, here is its value */ - } u; - int marked; /* for garbage collection; never collect (nor change) if > 1 */ - char str[1]; /* \0 byte already reserved */ -} TaggedString; + +typedef struct TObject { + lua_Type ttype; + Value value; +} TObject; @@ -65,6 +78,27 @@ typedef struct GCnode { } GCnode; +/* +** String headers for string table +*/ + +typedef struct TaggedString { + GCnode head; + int constindex; /* hint to reuse constants (= -1 if this is a userdata) */ + unsigned long hash; + union { + TObject globalval; + struct { + void *v; /* if this is a userdata, here is its value */ + int tag; + } d; + } u; + char str[1]; /* \0 byte already reserved */ +} TaggedString; + + + + /* ** Function Prototypes */ @@ -87,43 +121,6 @@ typedef struct LocVar { -/* -** Lua TYPES -** WARNING: if you change the order of this enumeration, -** grep "ORDER LUA_T" -*/ -typedef enum { - LUA_T_NIL = -10, - LUA_T_NUMBER = -9, - LUA_T_STRING = -8, - LUA_T_ARRAY = -7, /* array==table */ - LUA_T_PROTO = -6, - LUA_T_FUNCTION = -5, - LUA_T_CFUNCTION= -4, - LUA_T_MARK = -3, - LUA_T_CMARK = -2, - LUA_T_LINE = -1, - LUA_T_USERDATA = 0 -} lua_Type; - -#define NUM_TYPES 11 - - -typedef union { - lua_CFunction f; - real n; - TaggedString *ts; - TProtoFunc *tf; - struct Closure *cl; - struct Hash *a; - int i; -} Value; - -typedef struct TObject { - lua_Type ttype; - Value value; -} TObject; - /* Macros to access structure members */ #define ttype(o) ((o)->ttype) -- cgit v1.2.3-55-g6feb