34 #define CO_OBJ_INTERNAL
40 #include "extern/halloc.h"
56 #define _fixext16 0xd8
88 #define CO_TYPE(J) (((co_obj_t *)J)->_type)
91 #define _LIST_ELEMENT(J,I) co_obj_data_ptr(co_list_element(J,I))
94 #define IS_NIL(J) (CO_TYPE(J) == _nil)
95 #define IS_FIXINT(J) (CO_TYPE(J) < 128)
96 #define IS_BOOL(J) (IS_FALSE(J) || IS_TRUE(J))
97 #define IS_TRUE(J) (CO_TYPE(J) == _true)
98 #define IS_FALSE(J) (CO_TYPE(J) == _false)
99 #define IS_BIN(J) ((CO_TYPE(J) == _bin8) || (CO_TYPE(J) == _bin16) || (CO_TYPE(J) == _bin32))
100 #define IS_EXT(J) ((CO_TYPE(J) == _ext8) || (CO_TYPE(J) == _ext16) || (CO_TYPE(J) == _ext32))
101 #define IS_FIXEXT(J) ((CO_TYPE(J) == _fixext1) || (CO_TYPE(J) == _fixext2) || (CO_TYPE(J) == _fixext4) || (CO_TYPE(J) == _fixext8) || (CO_TYPE(J) == _fixext16))
102 #define IS_FLOAT(J) ((CO_TYPE(J) == _float32) || (CO_TYPE(J) == _float64))
103 #define IS_UINT(J) ((CO_TYPE(J) == _uint8) || (CO_TYPE(J) == _uint16) || (CO_TYPE(J) == _uint32) || (CO_TYPE(J) == _uint64))
104 #define IS_INT(J) ((CO_TYPE(J) == _int8) || (CO_TYPE(J) == _int16) || (CO_TYPE(J) == _int32) || (CO_TYPE(J) == _int64))
105 #define IS_STR(J) ((CO_TYPE(J) == _str8) || (CO_TYPE(J) == _str16) || (CO_TYPE(J) == _str32))
106 #define IS_LIST(J) ((CO_TYPE(J) == _list16) || (CO_TYPE(J) == _list32))
107 #define IS_TREE(J) ((CO_TYPE(J) == _tree16) || (CO_TYPE(J) == _tree32))
108 #define IS_CHAR(J) (IS_BIN(J) || IS_STR(J))
109 #define IS_EXTENSION(J) (IS_EXT(J) || IS_FIXEXT(J))
110 #define IS_INTEGER(J) (IS_INT(J) || IS_UINT(J) || IS_FIXINT(J))
111 #define IS_COMPLEX(J) (IS_LIST(J) || IS_TREE(J))
114 #define IS_CMD(J) (IS_EXT(J) && ((co_cmd_t *)J)->_exttype == _cmd)
115 #define IS_PLUG(J) (IS_EXT(J) && ((co_plugin_t *)J)->_exttype == _plug)
116 #define IS_PROFILE(J) (IS_EXT(J) && ((co_profile_t *)J)->_exttype == _profile)
117 #define IS_CBPTR(J) (IS_EXT(J) && ((co_cbptr_t *)J)->_exttype == _cbptr)
118 #define IS_FD(J) (IS_EXT(J) && ((co_fd_t *)J)->_exttype == _fd)
119 #define IS_SOCK(J) (IS_EXT(J) && ((co_socket_t *)J)->_exttype == _sock)
120 #define IS_TIMER(J) (IS_EXT(J) && ((co_timer_t *)J)->_exttype == _co_timer)
121 #define IS_PROCESS(J) (IS_EXT(J) && ((co_process_t *)J)->_exttype == _process)
122 #define IS_IFACE(J) (IS_EXT(J) && ((co_iface_t *)J)->_exttype == _iface)
127 typedef uint8_t _type_t;
139 } __attribute__ ((packed));
144 typedef int (*co_cb_t)(
co_obj_t *
self, co_obj_t **output, co_obj_t *params);
149 #define _DECLARE_CHAR(T, L) typedef struct __attribute__((packed)) { co_obj_t _header; uint##L##_t _len; \
150 char data[1]; } co_##T##L##_t; int co_##T##L##_alloc(co_obj_t *output, \
151 const size_t out_size, const char *input, const size_t in_size, \
152 const uint8_t flags ); co_obj_t *co_##T##L##_create(const char *input, \
153 const size_t input_size, const uint8_t flags);
155 _DECLARE_CHAR(bin, 8);
156 _DECLARE_CHAR(bin, 16);
157 _DECLARE_CHAR(bin, 32);
158 _DECLARE_CHAR(str, 8);
159 _DECLARE_CHAR(str, 16);
160 _DECLARE_CHAR(str, 32);
192 #define _DECLARE_INTEGER(T, L) typedef struct __attribute__((packed)) { co_obj_t _header; T##L##_t data; }\
193 co_##T##L##_t; int co_##T##L##_alloc(co_obj_t *output, \
194 const T##L##_t input, const uint8_t flags); co_obj_t *co_##T##L##_create(\
195 const T##L##_t input, const uint8_t flags);
197 _DECLARE_INTEGER(
int, 8);
198 _DECLARE_INTEGER(
int, 16);
199 _DECLARE_INTEGER(
int, 32);
200 _DECLARE_INTEGER(
int, 64);
201 _DECLARE_INTEGER(uint, 8);
202 _DECLARE_INTEGER(uint, 16);
203 _DECLARE_INTEGER(uint, 32);
204 _DECLARE_INTEGER(uint, 64);
216 int co_nil_alloc(co_obj_t *output,
const uint8_t flags);
217 co_obj_t * co_nil_create(
const uint8_t flags);
225 int co_bool_alloc(co_obj_t *output,
const bool input,
const uint8_t flags);
226 co_obj_t * co_bool_create(
const bool input,
const uint8_t flags);
234 int co_fixint_alloc(co_obj_t *output,
const int input,
const uint8_t flags);
235 co_obj_t * co_fixint_create(
const int input,
const uint8_t flags);
244 int co_float32_alloc(co_obj_t *output,
const float input,
const uint8_t flags);
245 co_obj_t * co_float32_create(
const double input,
const uint8_t flags);
254 int co_float64_alloc(co_obj_t *output,
const double input,
const uint8_t flags);
255 co_obj_t * co_float64_create(
const double input,
const uint8_t flags);
261 void co_obj_free(co_obj_t *
object);
266 size_t co_obj_raw(
char **data,
const co_obj_t *
object);
268 size_t co_obj_data(
char **data,
const co_obj_t *
object);
270 #define co_obj_data_ptr(J) ({ char *d = NULL; co_obj_data(&d,J); d; })
272 size_t co_obj_import(co_obj_t **output,
const char *input,
const size_t in_size,
const uint8_t flags);
274 int co_obj_getflags(
const co_obj_t *
object);
276 void co_obj_setflags(co_obj_t *
object,
const int flags);
282 int co_str_copy(co_obj_t *dst,
const co_obj_t *src,
const size_t size);
284 int co_str_cat(co_obj_t *dst,
const co_obj_t *src,
const size_t size);
286 int co_str_cmp(
const co_obj_t *a,
const co_obj_t *b);
288 #define co_str_cmp_str(J,S) ({ co_obj_t *s = co_str8_create(S,sizeof(S),0); \
289 int i = co_str_cmp(J,s); co_obj_free(s); i; })
291 #define co_str_len(J) ({ char *v = NULL; co_obj_data(&v,J); })
debug macros for the Commotion daemon