2005-02-04 15:39:11 +00:00
|
|
|
/*
|
2005-09-21 15:53:55 +00:00
|
|
|
* $Id: obj.h,v 1.4 2005-09-21 15:53:55 bacon Exp $
|
2005-02-04 15:39:11 +00:00
|
|
|
*/
|
|
|
|
|
2005-09-18 11:54:23 +00:00
|
|
|
#ifndef _XP_LSP_OBJ_H_
|
|
|
|
#define _XP_LSP_OBJ_H_
|
2005-02-04 15:39:11 +00:00
|
|
|
|
2005-05-28 13:34:26 +00:00
|
|
|
#include <xp/lsp/types.h>
|
2005-02-04 15:39:11 +00:00
|
|
|
|
2005-09-21 15:53:55 +00:00
|
|
|
/* object types */
|
2005-02-04 15:39:11 +00:00
|
|
|
enum
|
|
|
|
{
|
2005-09-18 08:10:50 +00:00
|
|
|
XP_LSP_OBJ_NIL = 0,
|
|
|
|
XP_LSP_OBJ_TRUE,
|
|
|
|
XP_LSP_OBJ_INT,
|
2005-09-20 11:19:15 +00:00
|
|
|
XP_LSP_OBJ_REAL,
|
2005-09-18 08:10:50 +00:00
|
|
|
XP_LSP_OBJ_SYMBOL,
|
|
|
|
XP_LSP_OBJ_STRING,
|
|
|
|
XP_LSP_OBJ_CONS,
|
|
|
|
XP_LSP_OBJ_FUNC,
|
|
|
|
XP_LSP_OBJ_MACRO,
|
|
|
|
XP_LSP_OBJ_PRIM,
|
|
|
|
|
|
|
|
XP_LSP_TYPE_COUNT // the number of lsp object types
|
2005-02-04 15:39:11 +00:00
|
|
|
};
|
|
|
|
|
2005-09-21 15:53:55 +00:00
|
|
|
typedef struct xp_lsp_objhdr_t xp_lsp_objhdr_t;
|
|
|
|
typedef struct xp_lsp_obj_t xp_lsp_obj_t;
|
|
|
|
typedef struct xp_lsp_obj_nil_t xp_lsp_obj_nil_t;
|
|
|
|
typedef struct xp_lsp_obj_true_t xp_lsp_obj_true_t;
|
|
|
|
typedef struct xp_lsp_obj_int_t xp_lsp_obj_int_t;
|
|
|
|
typedef struct xp_lsp_obj_real_t xp_lsp_obj_real_t;
|
|
|
|
typedef struct xp_lsp_obj_symbol_t xp_lsp_obj_symbol_t;
|
|
|
|
typedef struct xp_lsp_obj_string_t xp_lsp_obj_string_t;
|
|
|
|
typedef struct xp_lsp_obj_cons_t xp_lsp_obj_cons_t;
|
|
|
|
typedef struct xp_lsp_obj_func_t xp_lsp_obj_func_t;
|
|
|
|
typedef struct xp_lsp_obj_macro_t xp_lsp_obj_macro_t;
|
|
|
|
typedef struct xp_lsp_obj_prim_t xp_lsp_obj_prim_t;
|
|
|
|
|
|
|
|
struct xp_lsp_objhdr_t
|
|
|
|
{
|
|
|
|
xp_uint32_t type: 24;
|
|
|
|
xp_uint32_t mark: 4;
|
|
|
|
xp_uint32_t lock: 4;
|
|
|
|
xp_size_t size;
|
|
|
|
xp_lsp_obj_t* link;
|
|
|
|
};
|
2005-02-04 15:39:11 +00:00
|
|
|
|
2005-09-18 08:10:50 +00:00
|
|
|
struct xp_lsp_obj_t
|
2005-02-04 15:39:11 +00:00
|
|
|
{
|
2005-09-21 15:53:55 +00:00
|
|
|
xp_lsp_objhdr_t hdr;
|
2005-02-04 15:39:11 +00:00
|
|
|
};
|
|
|
|
|
2005-09-18 08:10:50 +00:00
|
|
|
struct xp_lsp_obj_nil_t
|
2005-02-04 15:39:11 +00:00
|
|
|
{
|
2005-09-21 15:53:55 +00:00
|
|
|
xp_lsp_objhdr_t hdr;
|
2005-02-04 15:39:11 +00:00
|
|
|
};
|
|
|
|
|
2005-09-18 08:10:50 +00:00
|
|
|
struct xp_lsp_obj_true_t
|
2005-02-04 15:39:11 +00:00
|
|
|
{
|
2005-09-21 15:53:55 +00:00
|
|
|
xp_lsp_objhdr_t hdr;
|
2005-02-04 15:39:11 +00:00
|
|
|
};
|
|
|
|
|
2005-09-18 08:10:50 +00:00
|
|
|
struct xp_lsp_obj_int_t
|
2005-02-04 15:39:11 +00:00
|
|
|
{
|
2005-09-21 15:53:55 +00:00
|
|
|
xp_lsp_objhdr_t hdr;
|
2005-09-18 08:10:50 +00:00
|
|
|
xp_lsp_int_t value;
|
2005-02-04 15:39:11 +00:00
|
|
|
};
|
|
|
|
|
2005-09-20 11:19:15 +00:00
|
|
|
struct xp_lsp_obj_real_t
|
2005-02-04 15:39:11 +00:00
|
|
|
{
|
2005-09-21 15:53:55 +00:00
|
|
|
xp_lsp_objhdr_t hdr;
|
2005-09-18 08:10:50 +00:00
|
|
|
xp_lsp_real_t value;
|
2005-02-04 15:39:11 +00:00
|
|
|
};
|
|
|
|
|
2005-09-18 08:10:50 +00:00
|
|
|
struct xp_lsp_obj_symbol_t
|
2005-02-04 15:39:11 +00:00
|
|
|
{
|
2005-09-21 15:53:55 +00:00
|
|
|
xp_lsp_objhdr_t hdr;
|
2005-02-04 15:39:11 +00:00
|
|
|
#ifdef __BORLANDC__
|
|
|
|
#else
|
2005-02-07 15:10:41 +00:00
|
|
|
xp_char_t buffer[0];
|
2005-02-04 15:39:11 +00:00
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
2005-09-18 08:10:50 +00:00
|
|
|
struct xp_lsp_obj_string_t
|
2005-02-04 15:39:11 +00:00
|
|
|
{
|
2005-09-21 15:53:55 +00:00
|
|
|
xp_lsp_objhdr_t hdr;
|
2005-02-04 15:39:11 +00:00
|
|
|
#ifdef __BORLANDC__
|
|
|
|
#else
|
2005-02-07 15:10:41 +00:00
|
|
|
xp_char_t buffer[0];
|
2005-02-04 15:39:11 +00:00
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
2005-09-18 08:10:50 +00:00
|
|
|
struct xp_lsp_obj_cons_t
|
2005-02-04 15:39:11 +00:00
|
|
|
{
|
2005-09-21 15:53:55 +00:00
|
|
|
xp_lsp_objhdr_t hdr;
|
2005-09-18 08:10:50 +00:00
|
|
|
struct xp_lsp_obj_t* car;
|
|
|
|
struct xp_lsp_obj_t* cdr;
|
2005-02-04 15:39:11 +00:00
|
|
|
};
|
|
|
|
|
2005-09-18 08:10:50 +00:00
|
|
|
struct xp_lsp_obj_func_t
|
2005-02-04 15:39:11 +00:00
|
|
|
{
|
2005-09-21 15:53:55 +00:00
|
|
|
xp_lsp_objhdr_t hdr;
|
2005-09-18 08:10:50 +00:00
|
|
|
struct xp_lsp_obj_t* formal;
|
|
|
|
struct xp_lsp_obj_t* body;
|
2005-02-04 15:39:11 +00:00
|
|
|
};
|
|
|
|
|
2005-09-18 08:10:50 +00:00
|
|
|
struct xp_lsp_obj_macro_t
|
2005-02-04 15:39:11 +00:00
|
|
|
{
|
2005-09-21 15:53:55 +00:00
|
|
|
xp_lsp_objhdr_t hdr;
|
2005-09-18 08:10:50 +00:00
|
|
|
struct xp_lsp_obj_t* formal;
|
|
|
|
struct xp_lsp_obj_t* body;
|
2005-02-04 15:39:11 +00:00
|
|
|
};
|
|
|
|
|
2005-09-18 08:10:50 +00:00
|
|
|
struct xp_lsp_obj_prim_t
|
2005-02-04 15:39:11 +00:00
|
|
|
{
|
2005-09-21 15:53:55 +00:00
|
|
|
xp_lsp_objhdr_t hdr;
|
2005-09-20 12:06:51 +00:00
|
|
|
void* impl; /* xp_lsp_prim_t */
|
2005-02-04 15:39:11 +00:00
|
|
|
};
|
|
|
|
|
2005-09-21 15:53:55 +00:00
|
|
|
/* header access */
|
|
|
|
#define XP_LSP_TYPE(x) (((xp_lsp_obj_t*)x)->hdr.type)
|
|
|
|
#define XP_LSP_SIZE(x) (((xp_lsp_obj_t*)x)->hdr.size)
|
|
|
|
#define XP_LSP_MARK(x) (((xp_lsp_obj_t*)x)->hdr.mark)
|
|
|
|
#define XP_LSP_LOCK(x) (((xp_lsp_obj_t*)x)->hdr.lock)
|
|
|
|
#define XP_LSP_LINK(x) (((xp_lsp_obj_t*)x)->hdr.link)
|
2005-02-04 15:39:11 +00:00
|
|
|
|
2005-09-21 15:53:55 +00:00
|
|
|
/* value access */
|
2005-09-18 08:10:50 +00:00
|
|
|
#define XP_LSP_IVALUE(x) (((xp_lsp_obj_int_t*)x)->value)
|
2005-09-20 11:19:15 +00:00
|
|
|
#define XP_LSP_RVALUE(x) (((xp_lsp_obj_real_t*)x)->value)
|
2005-02-04 15:39:11 +00:00
|
|
|
|
|
|
|
#ifdef __BORLANDC__
|
2005-09-18 08:10:50 +00:00
|
|
|
#define XP_LSP_SYMVALUE(x) ((xp_char_t*)(((xp_lsp_obj_symbol_t*)x) + 1))
|
2005-02-04 15:39:11 +00:00
|
|
|
#else
|
2005-09-18 08:10:50 +00:00
|
|
|
#define XP_LSP_SYMVALUE(x) (((xp_lsp_obj_symbol_t*)x)->buffer)
|
2005-02-04 15:39:11 +00:00
|
|
|
#endif
|
2005-09-21 15:53:55 +00:00
|
|
|
#define XP_LSP_SYMLEN(x) ((((xp_lsp_obj_symbol_t*)x)->hdr.size - sizeof(xp_lsp_obj_t)) / sizeof(xp_char_t) - 1)
|
2005-02-04 15:39:11 +00:00
|
|
|
|
|
|
|
#ifdef __BORLANDC__
|
2005-09-18 08:10:50 +00:00
|
|
|
#define XP_LSP_STRVALUE(x) ((xp_char_t*)(((xp_lsp_obj_string_t*)x) + 1))
|
2005-02-04 15:39:11 +00:00
|
|
|
#else
|
2005-09-18 08:10:50 +00:00
|
|
|
#define XP_LSP_STRVALUE(x) (((xp_lsp_obj_string_t*)x)->buffer)
|
2005-02-04 15:39:11 +00:00
|
|
|
#endif
|
2005-09-21 15:53:55 +00:00
|
|
|
#define XP_LSP_STRLEN(x) ((((xp_lsp_obj_string_t*)x)->hdr.size - sizeof(xp_lsp_obj_t)) / sizeof(xp_char_t) - 1)
|
2005-09-18 08:10:50 +00:00
|
|
|
|
|
|
|
#define XP_LSP_CAR(x) (((xp_lsp_obj_cons_t*)x)->car)
|
|
|
|
#define XP_LSP_CDR(x) (((xp_lsp_obj_cons_t*)x)->cdr)
|
|
|
|
#define XP_LSP_FFORMAL(x) (((xp_lsp_obj_func_t*)x)->formal)
|
|
|
|
#define XP_LSP_FBODY(x) (((xp_lsp_obj_func_t*)x)->body)
|
|
|
|
#define XP_LSP_MFORMAL(x) (((xp_lsp_obj_macro_t*)x)->formal)
|
|
|
|
#define XP_LSP_MBODY(x) (((xp_lsp_obj_macro_t*)x)->body)
|
2005-09-20 12:06:51 +00:00
|
|
|
#define XP_LSP_PRIM(x) ((xp_lsp_prim_t)(((xp_lsp_obj_prim_t*)x)->impl))
|
2005-02-04 15:39:11 +00:00
|
|
|
|
|
|
|
#endif
|