mirror of
https://github.com/janet-lang/janet
synced 2024-12-27 00:40:26 +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,
|
||||
janet_int64_compare,
|
||||
janet_int64_hash,
|
||||
NULL
|
||||
JANET_ATEND_HASH
|
||||
};
|
||||
|
||||
static const JanetAbstractType it_u64_type = {
|
||||
@ -106,7 +106,7 @@ static const JanetAbstractType it_u64_type = {
|
||||
it_u64_tostring,
|
||||
janet_uint64_compare,
|
||||
janet_int64_hash,
|
||||
NULL
|
||||
JANET_ATEND_HASH
|
||||
};
|
||||
|
||||
int64_t janet_unwrap_s64(Janet x) {
|
||||
|
@ -47,13 +47,7 @@ JanetAbstractType cfun_io_filetype = {
|
||||
cfun_io_gc,
|
||||
NULL,
|
||||
io_file_get,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL
|
||||
JANET_ATEND_GET
|
||||
};
|
||||
|
||||
/* Check arguments to fopen */
|
||||
|
@ -60,10 +60,7 @@ static JanetAbstractType JanetRNG_type = {
|
||||
NULL,
|
||||
janet_rng_marshal,
|
||||
janet_rng_unmarshal,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
JANET_ATEND_UNMARSHAL
|
||||
};
|
||||
|
||||
JanetRNG *janet_default_rng(void) {
|
||||
|
@ -738,13 +738,7 @@ static JanetAbstractType janet_parse_parsertype = {
|
||||
parsergc,
|
||||
parsermark,
|
||||
parserget,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL
|
||||
JANET_ATEND_GET
|
||||
};
|
||||
|
||||
/* C Function parser */
|
||||
|
@ -1212,10 +1212,7 @@ static const JanetAbstractType peg_type = {
|
||||
NULL,
|
||||
peg_marshal,
|
||||
peg_unmarshal,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL
|
||||
JANET_ATEND_UNMARSHAL
|
||||
};
|
||||
|
||||
/* Convert Builder to Peg (Janet Abstract Value) */
|
||||
|
@ -397,13 +397,7 @@ static JanetAbstractType Thread_AT = {
|
||||
thread_gc,
|
||||
thread_mark,
|
||||
janet_thread_getter,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL
|
||||
JANET_ATEND_GET
|
||||
};
|
||||
|
||||
static JanetThread *janet_make_thread(JanetMailbox *mailbox, JanetTable *encode) {
|
||||
|
@ -119,10 +119,7 @@ static const JanetAbstractType ta_buffer_type = {
|
||||
NULL,
|
||||
ta_buffer_marshal,
|
||||
ta_buffer_unmarshal,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL
|
||||
JANET_ATEND_UNMARSHAL
|
||||
};
|
||||
|
||||
static int ta_mark(void *p, size_t s) {
|
||||
@ -286,10 +283,7 @@ static const JanetAbstractType ta_view_type = {
|
||||
ta_setter,
|
||||
ta_view_marshal,
|
||||
ta_view_unmarshal,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL
|
||||
JANET_ATEND_UNMARSHAL
|
||||
};
|
||||
|
||||
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 = {
|
||||
"core/type-info",
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL
|
||||
JANET_ATEND_NAME
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
|
@ -910,6 +910,22 @@ struct JanetAbstractType {
|
||||
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 {
|
||||
const char *name;
|
||||
JanetCFunction cfun;
|
||||
|
Loading…
Reference in New Issue
Block a user