mirror of
https://github.com/janet-lang/janet
synced 2024-11-29 03:19:54 +00:00
Use ATEND macros to add fields to abstract types.
This means we can add new properties to abstract types without breaking old code. We can also make simple abstract types without needing to add many NULL fields to the type.
This commit is contained in:
parent
3c87d89df3
commit
2dd852da54
@ -92,7 +92,7 @@ static const JanetAbstractType it_s64_type = {
|
|||||||
it_s64_tostring,
|
it_s64_tostring,
|
||||||
janet_int64_compare,
|
janet_int64_compare,
|
||||||
janet_int64_hash,
|
janet_int64_hash,
|
||||||
NULL
|
JANET_ATEND_HASH
|
||||||
};
|
};
|
||||||
|
|
||||||
static const JanetAbstractType it_u64_type = {
|
static const JanetAbstractType it_u64_type = {
|
||||||
@ -106,7 +106,7 @@ static const JanetAbstractType it_u64_type = {
|
|||||||
it_u64_tostring,
|
it_u64_tostring,
|
||||||
janet_uint64_compare,
|
janet_uint64_compare,
|
||||||
janet_int64_hash,
|
janet_int64_hash,
|
||||||
NULL
|
JANET_ATEND_HASH
|
||||||
};
|
};
|
||||||
|
|
||||||
int64_t janet_unwrap_s64(Janet x) {
|
int64_t janet_unwrap_s64(Janet x) {
|
||||||
|
@ -47,13 +47,7 @@ JanetAbstractType cfun_io_filetype = {
|
|||||||
cfun_io_gc,
|
cfun_io_gc,
|
||||||
NULL,
|
NULL,
|
||||||
io_file_get,
|
io_file_get,
|
||||||
NULL,
|
JANET_ATEND_GET
|
||||||
NULL,
|
|
||||||
NULL,
|
|
||||||
NULL,
|
|
||||||
NULL,
|
|
||||||
NULL,
|
|
||||||
NULL
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Check arguments to fopen */
|
/* Check arguments to fopen */
|
||||||
|
@ -60,10 +60,7 @@ static JanetAbstractType JanetRNG_type = {
|
|||||||
NULL,
|
NULL,
|
||||||
janet_rng_marshal,
|
janet_rng_marshal,
|
||||||
janet_rng_unmarshal,
|
janet_rng_unmarshal,
|
||||||
NULL,
|
JANET_ATEND_UNMARSHAL
|
||||||
NULL,
|
|
||||||
NULL,
|
|
||||||
NULL,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
JanetRNG *janet_default_rng(void) {
|
JanetRNG *janet_default_rng(void) {
|
||||||
|
@ -738,13 +738,7 @@ static JanetAbstractType janet_parse_parsertype = {
|
|||||||
parsergc,
|
parsergc,
|
||||||
parsermark,
|
parsermark,
|
||||||
parserget,
|
parserget,
|
||||||
NULL,
|
JANET_ATEND_GET
|
||||||
NULL,
|
|
||||||
NULL,
|
|
||||||
NULL,
|
|
||||||
NULL,
|
|
||||||
NULL,
|
|
||||||
NULL
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/* C Function parser */
|
/* C Function parser */
|
||||||
|
@ -1212,10 +1212,7 @@ static const JanetAbstractType peg_type = {
|
|||||||
NULL,
|
NULL,
|
||||||
peg_marshal,
|
peg_marshal,
|
||||||
peg_unmarshal,
|
peg_unmarshal,
|
||||||
NULL,
|
JANET_ATEND_UNMARSHAL
|
||||||
NULL,
|
|
||||||
NULL,
|
|
||||||
NULL
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Convert Builder to Peg (Janet Abstract Value) */
|
/* Convert Builder to Peg (Janet Abstract Value) */
|
||||||
|
@ -397,13 +397,7 @@ static JanetAbstractType Thread_AT = {
|
|||||||
thread_gc,
|
thread_gc,
|
||||||
thread_mark,
|
thread_mark,
|
||||||
janet_thread_getter,
|
janet_thread_getter,
|
||||||
NULL,
|
JANET_ATEND_GET
|
||||||
NULL,
|
|
||||||
NULL,
|
|
||||||
NULL,
|
|
||||||
NULL,
|
|
||||||
NULL,
|
|
||||||
NULL
|
|
||||||
};
|
};
|
||||||
|
|
||||||
static JanetThread *janet_make_thread(JanetMailbox *mailbox, JanetTable *encode) {
|
static JanetThread *janet_make_thread(JanetMailbox *mailbox, JanetTable *encode) {
|
||||||
|
@ -119,10 +119,7 @@ static const JanetAbstractType ta_buffer_type = {
|
|||||||
NULL,
|
NULL,
|
||||||
ta_buffer_marshal,
|
ta_buffer_marshal,
|
||||||
ta_buffer_unmarshal,
|
ta_buffer_unmarshal,
|
||||||
NULL,
|
JANET_ATEND_UNMARSHAL
|
||||||
NULL,
|
|
||||||
NULL,
|
|
||||||
NULL
|
|
||||||
};
|
};
|
||||||
|
|
||||||
static int ta_mark(void *p, size_t s) {
|
static int ta_mark(void *p, size_t s) {
|
||||||
@ -286,10 +283,7 @@ static const JanetAbstractType ta_view_type = {
|
|||||||
ta_setter,
|
ta_setter,
|
||||||
ta_view_marshal,
|
ta_view_marshal,
|
||||||
ta_view_unmarshal,
|
ta_view_unmarshal,
|
||||||
NULL,
|
JANET_ATEND_UNMARSHAL
|
||||||
NULL,
|
|
||||||
NULL,
|
|
||||||
NULL
|
|
||||||
};
|
};
|
||||||
|
|
||||||
JanetTArrayBuffer *janet_tarray_buffer(size_t size) {
|
JanetTArrayBuffer *janet_tarray_buffer(size_t size) {
|
||||||
|
@ -419,16 +419,7 @@ void janet_cfuns(JanetTable *env, const char *regprefix, const JanetReg *cfuns)
|
|||||||
|
|
||||||
static const JanetAbstractType type_wrap = {
|
static const JanetAbstractType type_wrap = {
|
||||||
"core/type-info",
|
"core/type-info",
|
||||||
NULL,
|
JANET_ATEND_NAME
|
||||||
NULL,
|
|
||||||
NULL,
|
|
||||||
NULL,
|
|
||||||
NULL,
|
|
||||||
NULL,
|
|
||||||
NULL,
|
|
||||||
NULL,
|
|
||||||
NULL,
|
|
||||||
NULL
|
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
@ -910,6 +910,22 @@ struct JanetAbstractType {
|
|||||||
Janet(*next)(void *p, Janet key);
|
Janet(*next)(void *p, Janet key);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/* Some macros to let us add extra types to JanetAbstract types without
|
||||||
|
* needing to changing native modules that declare them as static const
|
||||||
|
* structures. If more fields are added, these macros are modified to include
|
||||||
|
* default values (usually NULL). This silences missing field warnings. */
|
||||||
|
#define JANET_ATEND_NAME NULL,JANET_ATEND_GC
|
||||||
|
#define JANET_ATEND_GC NULL,JANET_ATEND_GCMARK
|
||||||
|
#define JANET_ATEND_GCMARK NULL,JANET_ATEND_GET
|
||||||
|
#define JANET_ATEND_GET NULL,JANET_ATEND_PUT
|
||||||
|
#define JANET_ATEND_PUT NULL,JANET_ATEND_MARSHAL
|
||||||
|
#define JANET_ATEND_MARSHAL NULL,JANET_ATEND_UNMARSHAL
|
||||||
|
#define JANET_ATEND_UNMARSHAL NULL,JANET_ATEND_TOSTRING
|
||||||
|
#define JANET_ATEND_TOSTRING NULL,JANET_ATEND_COMPARE
|
||||||
|
#define JANET_ATEND_COMPARE NULL,JANET_ATEND_HASH
|
||||||
|
#define JANET_ATEND_HASH NULL,JANET_ATEND_NEXT
|
||||||
|
#define JANET_ATEND_NEXT
|
||||||
|
|
||||||
struct JanetReg {
|
struct JanetReg {
|
||||||
const char *name;
|
const char *name;
|
||||||
JanetCFunction cfun;
|
JanetCFunction cfun;
|
||||||
|
Loading…
Reference in New Issue
Block a user