1
0
mirror of https://github.com/janet-lang/janet synced 2024-11-25 09:47:17 +00:00

Allow calling next on abstracts.

This will allow the creation of infinte
streams, low cost generators, etc.
This commit is contained in:
Calvin Rose 2020-01-18 18:09:20 -06:00
parent 51678c1aba
commit f4077b678a
10 changed files with 20 additions and 3 deletions

View File

@ -91,7 +91,8 @@ static const JanetAbstractType it_s64_type = {
int64_unmarshal,
it_s64_tostring,
janet_int64_compare,
janet_int64_hash
janet_int64_hash,
NULL
};
static const JanetAbstractType it_u64_type = {
@ -104,7 +105,8 @@ static const JanetAbstractType it_u64_type = {
int64_unmarshal,
it_u64_tostring,
janet_uint64_compare,
janet_int64_hash
janet_int64_hash,
NULL
};
int64_t janet_unwrap_s64(Janet x) {

View File

@ -52,6 +52,7 @@ JanetAbstractType cfun_io_filetype = {
NULL,
NULL,
NULL,
NULL,
NULL
};

View File

@ -62,7 +62,8 @@ static JanetAbstractType JanetRNG_type = {
janet_rng_unmarshal,
NULL,
NULL,
NULL
NULL,
NULL,
};
JanetRNG *janet_default_rng(void) {

View File

@ -743,6 +743,7 @@ static JanetAbstractType janet_parse_parsertype = {
NULL,
NULL,
NULL,
NULL,
NULL
};

View File

@ -1214,6 +1214,7 @@ static const JanetAbstractType peg_type = {
peg_unmarshal,
NULL,
NULL,
NULL,
NULL
};

View File

@ -402,6 +402,7 @@ static JanetAbstractType Thread_AT = {
NULL,
NULL,
NULL,
NULL,
NULL
};

View File

@ -121,6 +121,7 @@ static const JanetAbstractType ta_buffer_type = {
ta_buffer_unmarshal,
NULL,
NULL,
NULL,
NULL
};
@ -287,6 +288,7 @@ static const JanetAbstractType ta_view_type = {
ta_view_unmarshal,
NULL,
NULL,
NULL,
NULL
};

View File

@ -427,6 +427,7 @@ static const JanetAbstractType type_wrap = {
NULL,
NULL,
NULL,
NULL,
NULL
};

View File

@ -87,6 +87,12 @@ Janet janet_next(Janet ds, Janet key) {
}
break;
}
case JANET_ABSTRACT: {
JanetAbstract abst = janet_unwrap_abstract(ds);
const JanetAbstractType *at = janet_abstract_type(abst);
if (NULL == at->next) break;
return at->next(abst, key);
}
}
return janet_wrap_nil();
}

View File

@ -907,6 +907,7 @@ struct JanetAbstractType {
void (*tostring)(void *p, JanetBuffer *buffer);
int (*compare)(void *lhs, void *rhs);
int32_t (*hash)(void *p, size_t len);
Janet(*next)(void *p, Janet key);
};
struct JanetReg {