summaryrefslogtreecommitdiff
path: root/src/lobject.h
diff options
context:
space:
mode:
authorLua Team <team@lua.org>2004-03-24 12:00:00 +0000
committerrepogen <>2004-03-24 12:00:00 +0000
commitced7bbbe7a257ce6de94069d5dbf6672aeafd4d9 (patch)
tree2a01a79e6a4f451dccd247c70310ad957204cefa /src/lobject.h
parente7731a8fb8a317aa5c444ef073bfad82fa5baa54 (diff)
downloadlua-github-5.1-work0.tar.gz
Lua 5.1-work05.1-work0
Diffstat (limited to 'src/lobject.h')
-rw-r--r--src/lobject.h122
1 files changed, 70 insertions, 52 deletions
diff --git a/src/lobject.h b/src/lobject.h
index 321a7e06..d5176a23 100644
--- a/src/lobject.h
+++ b/src/lobject.h
@@ -1,13 +1,17 @@
/*
-** $Id: lobject.h,v 1.159 2003/03/18 12:50:04 roberto Exp $
+** $Id: lobject.h,v 2.4 2004/03/15 21:04:33 roberto Exp $
** Type definitions for Lua objects
** See Copyright Notice in lua.h
*/
+
#ifndef lobject_h
#define lobject_h
+#include <stdarg.h>
+
+
#include "llimits.h"
#include "lua.h"
@@ -58,12 +62,12 @@ typedef union {
/*
-** Lua values (or `tagged objects')
+** Tagged Values
*/
-typedef struct lua_TObject {
+typedef struct lua_TValue {
int tt;
Value value;
-} TObject;
+} TValue;
/* Macros to test type */
@@ -82,8 +86,10 @@ typedef struct lua_TObject {
#define gcvalue(o) check_exp(iscollectable(o), (o)->value.gc)
#define pvalue(o) check_exp(ttislightuserdata(o), (o)->value.p)
#define nvalue(o) check_exp(ttisnumber(o), (o)->value.n)
-#define tsvalue(o) check_exp(ttisstring(o), &(o)->value.gc->ts)
-#define uvalue(o) check_exp(ttisuserdata(o), &(o)->value.gc->u)
+#define rawtsvalue(o) check_exp(ttisstring(o), &(o)->value.gc->ts)
+#define tsvalue(o) (&rawtsvalue(o)->tsv)
+#define rawuvalue(o) check_exp(ttisuserdata(o), &(o)->value.gc->u)
+#define uvalue(o) (&rawuvalue(o)->uv)
#define clvalue(o) check_exp(ttisfunction(o), &(o)->value.gc->cl)
#define hvalue(o) check_exp(ttistable(o), &(o)->value.gc->h)
#define bvalue(o) check_exp(ttisboolean(o), (o)->value.b)
@@ -91,59 +97,69 @@ typedef struct lua_TObject {
#define l_isfalse(o) (ttisnil(o) || (ttisboolean(o) && bvalue(o) == 0))
+/*
+** for internal debug only
+*/
+#define checkconsistency(obj) \
+ lua_assert(!iscollectable(obj) || (ttype(obj) == (obj)->value.gc->gch.tt))
+
+#define checkliveness(g,obj) \
+ lua_assert(!iscollectable(obj) || \
+ ((ttype(obj) == (obj)->value.gc->gch.tt) && !isdead(g, (obj)->value.gc)))
+
+
/* Macros to set values */
+#define setnilvalue(obj) ((obj)->tt=LUA_TNIL)
+
#define setnvalue(obj,x) \
- { TObject *i_o=(obj); i_o->tt=LUA_TNUMBER; i_o->value.n=(x); }
+ { TValue *i_o=(obj); i_o->value.n=(x); i_o->tt=LUA_TNUMBER; }
#define chgnvalue(obj,x) \
check_exp(ttype(obj)==LUA_TNUMBER, (obj)->value.n=(x))
#define setpvalue(obj,x) \
- { TObject *i_o=(obj); i_o->tt=LUA_TLIGHTUSERDATA; i_o->value.p=(x); }
+ { TValue *i_o=(obj); i_o->value.p=(x); i_o->tt=LUA_TLIGHTUSERDATA; }
#define setbvalue(obj,x) \
- { TObject *i_o=(obj); i_o->tt=LUA_TBOOLEAN; i_o->value.b=(x); }
+ { TValue *i_o=(obj); i_o->value.b=(x); i_o->tt=LUA_TBOOLEAN; }
-#define setsvalue(obj,x) \
- { TObject *i_o=(obj); i_o->tt=LUA_TSTRING; \
- i_o->value.gc=cast(GCObject *, (x)); \
- lua_assert(i_o->value.gc->gch.tt == LUA_TSTRING); }
+#define setsvalue(L,obj,x) \
+ { TValue *i_o=(obj); \
+ i_o->value.gc=cast(GCObject *, (x)); i_o->tt=LUA_TSTRING; \
+ checkliveness(G(L),i_o); }
-#define setuvalue(obj,x) \
- { TObject *i_o=(obj); i_o->tt=LUA_TUSERDATA; \
- i_o->value.gc=cast(GCObject *, (x)); \
- lua_assert(i_o->value.gc->gch.tt == LUA_TUSERDATA); }
+#define setuvalue(L,obj,x) \
+ { TValue *i_o=(obj); \
+ i_o->value.gc=cast(GCObject *, (x)); i_o->tt=LUA_TUSERDATA; \
+ checkliveness(G(L),i_o); }
-#define setthvalue(obj,x) \
- { TObject *i_o=(obj); i_o->tt=LUA_TTHREAD; \
- i_o->value.gc=cast(GCObject *, (x)); \
- lua_assert(i_o->value.gc->gch.tt == LUA_TTHREAD); }
+#define setthvalue(L,obj,x) \
+ { TValue *i_o=(obj); \
+ i_o->value.gc=cast(GCObject *, (x)); i_o->tt=LUA_TTHREAD; \
+ checkliveness(G(L),i_o); }
-#define setclvalue(obj,x) \
- { TObject *i_o=(obj); i_o->tt=LUA_TFUNCTION; \
- i_o->value.gc=cast(GCObject *, (x)); \
- lua_assert(i_o->value.gc->gch.tt == LUA_TFUNCTION); }
+#define setclvalue(L,obj,x) \
+ { TValue *i_o=(obj); \
+ i_o->value.gc=cast(GCObject *, (x)); i_o->tt=LUA_TFUNCTION; \
+ checkliveness(G(L),i_o); }
-#define sethvalue(obj,x) \
- { TObject *i_o=(obj); i_o->tt=LUA_TTABLE; \
- i_o->value.gc=cast(GCObject *, (x)); \
- lua_assert(i_o->value.gc->gch.tt == LUA_TTABLE); }
-
-#define setnilvalue(obj) ((obj)->tt=LUA_TNIL)
+#define sethvalue(L,obj,x) \
+ { TValue *i_o=(obj); \
+ i_o->value.gc=cast(GCObject *, (x)); i_o->tt=LUA_TTABLE; \
+ checkliveness(G(L),i_o); }
+#define setptvalue(L,obj,x) \
+ { TValue *i_o=(obj); \
+ i_o->value.gc=cast(GCObject *, (x)); i_o->tt=LUA_TPROTO; \
+ checkliveness(G(L),i_o); }
-/*
-** for internal debug only
-*/
-#define checkconsistency(obj) \
- lua_assert(!iscollectable(obj) || (ttype(obj) == (obj)->value.gc->gch.tt))
-#define setobj(obj1,obj2) \
- { const TObject *o2=(obj2); TObject *o1=(obj1); \
- checkconsistency(o2); \
- o1->tt=o2->tt; o1->value = o2->value; }
+#define setobj(L,obj1,obj2) \
+ { const TValue *o2=(obj2); TValue *o1=(obj1); \
+ o1->tt=o2->tt; o1->value = o2->value; \
+ checkliveness(G(L),o1); }
/*
@@ -155,6 +171,8 @@ typedef struct lua_TObject {
/* to stack (not from same stack) */
#define setobj2s setobj
#define setsvalue2s setsvalue
+#define sethvalue2s sethvalue
+#define setptvalue2s setptvalue
/* from table to same table */
#define setobjt2t setobj
/* to table */
@@ -170,7 +188,7 @@ typedef struct lua_TObject {
-typedef TObject *StkId; /* index to stack elements */
+typedef TValue *StkId; /* index to stack elements */
/*
@@ -181,7 +199,7 @@ typedef union TString {
struct {
CommonHeader;
lu_byte reserved;
- lu_hash hash;
+ unsigned int hash;
size_t len;
} tsv;
} TString;
@@ -209,7 +227,7 @@ typedef union Udata {
*/
typedef struct Proto {
CommonHeader;
- TObject *k; /* constants used by the function */
+ TValue *k; /* constants used by the function */
Instruction *code;
struct Proto **p; /* functions defined inside the function */
int *lineinfo; /* map from opcodes to source lines */
@@ -245,8 +263,8 @@ typedef struct LocVar {
typedef struct UpVal {
CommonHeader;
- TObject *v; /* points to stack or to its own value */
- TObject value; /* the value (when closed) */
+ TValue *v; /* points to stack or to its own value */
+ TValue value; /* the value (when closed) */
} UpVal;
@@ -260,14 +278,14 @@ typedef struct UpVal {
typedef struct CClosure {
ClosureHeader;
lua_CFunction f;
- TObject upvalue[1];
+ TValue upvalue[1];
} CClosure;
typedef struct LClosure {
ClosureHeader;
struct Proto *p;
- TObject g; /* global table for this closure */
+ TValue g; /* global table for this closure */
UpVal *upvals[1];
} LClosure;
@@ -287,8 +305,8 @@ typedef union Closure {
*/
typedef struct Node {
- TObject i_key;
- TObject i_val;
+ TValue i_key;
+ TValue i_val;
struct Node *next; /* for chaining */
} Node;
@@ -298,7 +316,7 @@ typedef struct Table {
lu_byte flags; /* 1<<p means tagmethod(p) is not present */
lu_byte lsizenode; /* log2 of size of `node' array */
struct Table *metatable;
- TObject *array; /* array part */
+ TValue *array; /* array part */
Node *node;
Node *firstfree; /* this position is free; all positions after it are full */
GCObject *gclist;
@@ -319,13 +337,13 @@ typedef struct Table {
-extern const TObject luaO_nilobject;
+extern const TValue luaO_nilobject;
int luaO_log2 (unsigned int x);
int luaO_int2fb (unsigned int x);
#define fb2int(x) (((x) & 7) << ((x) >> 3))
-int luaO_rawequalObj (const TObject *t1, const TObject *t2);
+int luaO_rawequalObj (const TValue *t1, const TValue *t2);
int luaO_str2d (const char *s, lua_Number *result);
const char *luaO_pushvfstring (lua_State *L, const char *fmt, va_list argp);