qse/ase/lsp/obj.h

162 lines
3.8 KiB
C
Raw Normal View History

2005-02-04 15:39:11 +00:00
/*
2007-02-17 15:27:19 +00:00
* $Id: obj.h,v 1.17 2007-02-17 15:27:19 bacon Exp $
2007-02-03 10:52:36 +00:00
*
* {License}
2005-02-04 15:39:11 +00:00
*/
2006-10-24 04:22:40 +00:00
#ifndef _ASE_LSP_OBJ_H_
#define _ASE_LSP_OBJ_H_
2005-02-04 15:39:11 +00:00
2006-10-26 08:17:38 +00:00
#ifndef _ASE_LSP_LSP_H_
#error Never include this file directly. Include <ase/lsp/lsp.h> instead
#endif
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
{
2006-10-24 04:22:40 +00:00
ASE_LSP_OBJ_NIL = 0,
ASE_LSP_OBJ_TRUE,
ASE_LSP_OBJ_INT,
ASE_LSP_OBJ_REAL,
2006-10-25 13:42:31 +00:00
ASE_LSP_OBJ_SYM,
ASE_LSP_OBJ_STR,
2006-10-24 04:22:40 +00:00
ASE_LSP_OBJ_CONS,
ASE_LSP_OBJ_FUNC,
ASE_LSP_OBJ_MACRO,
ASE_LSP_OBJ_PRIM,
ASE_LSP_TYPE_COUNT // the number of lsp object types
2005-02-04 15:39:11 +00:00
};
2006-10-26 08:17:38 +00:00
typedef struct ase_lsp_objhdr_t ase_lsp_objhdr_t;
typedef struct ase_lsp_obj_nil_t ase_lsp_obj_nil_t;
typedef struct ase_lsp_obj_true_t ase_lsp_obj_true_t;
typedef struct ase_lsp_obj_int_t ase_lsp_obj_int_t;
typedef struct ase_lsp_obj_real_t ase_lsp_obj_real_t;
typedef struct ase_lsp_obj_sym_t ase_lsp_obj_sym_t;
typedef struct ase_lsp_obj_str_t ase_lsp_obj_str_t;
typedef struct ase_lsp_obj_cons_t ase_lsp_obj_cons_t;
typedef struct ase_lsp_obj_func_t ase_lsp_obj_func_t;
typedef struct ase_lsp_obj_macro_t ase_lsp_obj_macro_t;
typedef struct ase_lsp_obj_prim_t ase_lsp_obj_prim_t;
2006-10-24 04:22:40 +00:00
struct ase_lsp_objhdr_t
2005-09-21 15:53:55 +00:00
{
2006-10-30 14:31:37 +00:00
ase_uint32_t type: 8;
2006-11-02 10:12:01 +00:00
ase_uint32_t mark: 4;
ase_uint32_t perm: 4;
2006-10-30 14:31:37 +00:00
ase_uint32_t lock: 16;
2006-10-24 04:22:40 +00:00
ase_size_t size;
ase_lsp_obj_t* link;
2005-09-21 15:53:55 +00:00
};
2005-02-04 15:39:11 +00:00
2006-10-24 04:22:40 +00:00
struct ase_lsp_obj_t
2005-02-04 15:39:11 +00:00
{
2006-10-24 04:22:40 +00:00
ase_lsp_objhdr_t hdr;
2005-02-04 15:39:11 +00:00
};
2006-10-24 04:22:40 +00:00
struct ase_lsp_obj_nil_t
2005-02-04 15:39:11 +00:00
{
2006-10-24 04:22:40 +00:00
ase_lsp_objhdr_t hdr;
2005-02-04 15:39:11 +00:00
};
2006-10-24 04:22:40 +00:00
struct ase_lsp_obj_true_t
2005-02-04 15:39:11 +00:00
{
2006-10-24 04:22:40 +00:00
ase_lsp_objhdr_t hdr;
2005-02-04 15:39:11 +00:00
};
2006-10-24 04:22:40 +00:00
struct ase_lsp_obj_int_t
2005-02-04 15:39:11 +00:00
{
2006-10-24 04:22:40 +00:00
ase_lsp_objhdr_t hdr;
2006-10-25 13:42:31 +00:00
ase_long_t value;
2005-02-04 15:39:11 +00:00
};
2006-10-24 04:22:40 +00:00
struct ase_lsp_obj_real_t
2005-02-04 15:39:11 +00:00
{
2006-10-24 04:22:40 +00:00
ase_lsp_objhdr_t hdr;
2006-10-25 13:42:31 +00:00
ase_real_t value;
2005-02-04 15:39:11 +00:00
};
2006-10-25 13:42:31 +00:00
struct ase_lsp_obj_sym_t
2005-02-04 15:39:11 +00:00
{
2006-10-24 04:22:40 +00:00
ase_lsp_objhdr_t hdr;
2007-02-17 15:27:19 +00:00
#if defined(__GNUC__)
2006-10-24 04:22:40 +00:00
ase_char_t buffer[0];
2005-02-04 15:39:11 +00:00
#endif
};
2006-10-25 13:42:31 +00:00
struct ase_lsp_obj_str_t
2005-02-04 15:39:11 +00:00
{
2006-10-24 04:22:40 +00:00
ase_lsp_objhdr_t hdr;
2007-02-17 15:27:19 +00:00
#if defined(__GNUC__)
2006-10-24 04:22:40 +00:00
ase_char_t buffer[0];
2005-02-04 15:39:11 +00:00
#endif
};
2006-10-24 04:22:40 +00:00
struct ase_lsp_obj_cons_t
2005-02-04 15:39:11 +00:00
{
2006-10-24 04:22:40 +00:00
ase_lsp_objhdr_t hdr;
2006-10-26 09:31:28 +00:00
ase_lsp_obj_t* car;
ase_lsp_obj_t* cdr;
2005-02-04 15:39:11 +00:00
};
2006-10-24 04:22:40 +00:00
struct ase_lsp_obj_func_t
2005-02-04 15:39:11 +00:00
{
2006-10-24 04:22:40 +00:00
ase_lsp_objhdr_t hdr;
2006-10-26 09:31:28 +00:00
ase_lsp_obj_t* formal;
ase_lsp_obj_t* body;
2005-02-04 15:39:11 +00:00
};
2006-10-24 04:22:40 +00:00
struct ase_lsp_obj_macro_t
2005-02-04 15:39:11 +00:00
{
2006-10-24 04:22:40 +00:00
ase_lsp_objhdr_t hdr;
2006-10-26 09:31:28 +00:00
ase_lsp_obj_t* formal;
ase_lsp_obj_t* body;
2005-02-04 15:39:11 +00:00
};
2006-10-24 04:22:40 +00:00
struct ase_lsp_obj_prim_t
2005-02-04 15:39:11 +00:00
{
2006-10-24 04:22:40 +00:00
ase_lsp_objhdr_t hdr;
2006-10-29 13:00:39 +00:00
ase_lsp_prim_t impl;
ase_size_t min_args;
ase_size_t max_args;
2005-02-04 15:39:11 +00:00
};
2005-09-21 15:53:55 +00:00
/* header access */
2006-11-02 10:12:01 +00:00
#define ASE_LSP_TYPE(x) (((ase_lsp_obj_t*)x)->hdr.type)
#define ASE_LSP_SIZE(x) (((ase_lsp_obj_t*)x)->hdr.size)
#define ASE_LSP_MARK(x) (((ase_lsp_obj_t*)x)->hdr.mark)
#define ASE_LSP_PERM(x) (((ase_lsp_obj_t*)x)->hdr.perm)
#define ASE_LSP_LOCK(x) (((ase_lsp_obj_t*)x)->hdr.lock)
#define ASE_LSP_LINK(x) (((ase_lsp_obj_t*)x)->hdr.link)
2005-02-04 15:39:11 +00:00
2005-09-21 15:53:55 +00:00
/* value access */
2006-11-02 06:46:31 +00:00
#define ASE_LSP_IVAL(x) (((ase_lsp_obj_int_t*)x)->value)
#define ASE_LSP_RVAL(x) (((ase_lsp_obj_real_t*)x)->value)
2005-02-04 15:39:11 +00:00
2007-02-17 15:27:19 +00:00
#if defined(__GNUC__)
#define ASE_LSP_SYMPTR(x) (((ase_lsp_obj_sym_t*)x)->buffer)
2005-02-04 15:39:11 +00:00
#else
2007-02-17 15:27:19 +00:00
#define ASE_LSP_SYMPTR(x) ((ase_char_t*)(((ase_lsp_obj_sym_t*)x) + 1))
2005-02-04 15:39:11 +00:00
#endif
2006-11-02 06:46:31 +00:00
#define ASE_LSP_SYMLEN(x) ((((ase_lsp_obj_sym_t*)x)->hdr.size - sizeof(ase_lsp_obj_t)) / sizeof(ase_char_t) - 1)
2005-02-04 15:39:11 +00:00
2007-02-17 15:27:19 +00:00
#if defined(__GNUC__)
#define ASE_LSP_STRPTR(x) (((ase_lsp_obj_str_t*)x)->buffer)
2005-02-04 15:39:11 +00:00
#else
2007-02-17 15:27:19 +00:00
#define ASE_LSP_STRPTR(x) ((ase_char_t*)(((ase_lsp_obj_str_t*)x) + 1))
2005-02-04 15:39:11 +00:00
#endif
2006-11-02 06:46:31 +00:00
#define ASE_LSP_STRLEN(x) ((((ase_lsp_obj_str_t*)x)->hdr.size - sizeof(ase_lsp_obj_t)) / sizeof(ase_char_t) - 1)
2006-10-24 04:22:40 +00:00
#define ASE_LSP_CAR(x) (((ase_lsp_obj_cons_t*)x)->car)
#define ASE_LSP_CDR(x) (((ase_lsp_obj_cons_t*)x)->cdr)
#define ASE_LSP_FFORMAL(x) (((ase_lsp_obj_func_t*)x)->formal)
#define ASE_LSP_FBODY(x) (((ase_lsp_obj_func_t*)x)->body)
#define ASE_LSP_MFORMAL(x) (((ase_lsp_obj_macro_t*)x)->formal)
#define ASE_LSP_MBODY(x) (((ase_lsp_obj_macro_t*)x)->body)
2006-10-29 13:00:39 +00:00
#define ASE_LSP_PIMPL(x) (((ase_lsp_obj_prim_t*)x)->impl)
#define ASE_LSP_PMINARGS(x) (((ase_lsp_obj_prim_t*)x)->min_args)
#define ASE_LSP_PMAXARGS(x) (((ase_lsp_obj_prim_t*)x)->max_args)
2005-02-04 15:39:11 +00:00
#endif