Merge remote-tracking branch 'upstream/master' into fix-wrong_bit_length

This commit is contained in:
Sven M. Hallberg 2015-12-07 11:05:05 +01:00
commit 50a73f6ab2
47 changed files with 372 additions and 135 deletions

View file

@ -81,6 +81,7 @@ static const HParserVtable action_vt = {
.isValidCF = action_isValidCF,
.desugar = desugar_action,
.compile_to_rvm = action_ctrvm,
.higher = true,
};
HParser* h_action(const HParser* p, const HAction a, void* user_data) {

View file

@ -17,6 +17,7 @@ static const HParserVtable and_vt = {
revision. --mlp, 18/12/12 */
.isValidCF = h_false, /* despite TODO above, this remains false. */
.compile_to_rvm = h_not_regular,
.higher = true,
};

View file

@ -79,6 +79,7 @@ static const HParserVtable attr_bool_vt = {
.isValidCF = ab_isValidCF,
.desugar = desugar_ab,
.compile_to_rvm = ab_ctrvm,
.higher = true,
};

View file

@ -4,7 +4,6 @@ typedef struct {
const HParser *p;
HContinuation k;
void *env;
HAllocator *mm__;
} BindEnv;
// an HAllocator backed by an HArena
@ -39,13 +38,11 @@ static HParseResult *parse_bind(void *be_, HParseState *state) {
if(!res)
return NULL;
// create a temporary arena allocator for the continuation
HArena *arena = h_new_arena(be->mm__, 0);
ArenaAllocator aa = {{aa_alloc, aa_realloc, aa_free}, arena};
// create a wrapper arena allocator for the continuation
ArenaAllocator aa = {{aa_alloc, aa_realloc, aa_free}, state->arena};
HParser *kx = be->k((HAllocator *)&aa, res->ast, be->env);
if(!kx) {
h_delete_arena(arena);
return NULL;
}
@ -53,7 +50,6 @@ static HParseResult *parse_bind(void *be_, HParseState *state) {
if(res2)
res2->bit_length = 0; // recalculate
h_delete_arena(arena);
return res2;
}
@ -62,6 +58,7 @@ static const HParserVtable bind_vt = {
.isValidRegular = h_false,
.isValidCF = h_false,
.compile_to_rvm = h_not_regular,
.higher = true,
};
HParser *h_bind(const HParser *p, HContinuation k, void *env)
@ -77,7 +74,6 @@ HParser *h_bind__m(HAllocator *mm__,
be->p = p;
be->k = k;
be->env = env;
be->mm__ = mm__;
return h_new_parser(mm__, &bind_vt, be);
}

View file

@ -102,6 +102,7 @@ static const HParserVtable bits_vt = {
.isValidCF = h_true,
.desugar = desugar_bits,
.compile_to_rvm = bits_ctrvm,
.higher = false,
};
HParser* h_bits(size_t len, bool sign) {

View file

@ -40,6 +40,7 @@ static const HParserVtable butnot_vt = {
.isValidRegular = h_false,
.isValidCF = h_false, // XXX should this be true if both p1 and p2 are CF?
.compile_to_rvm = h_not_regular,
.higher = true,
};
HParser* h_butnot(const HParser* p1, const HParser* p2) {

View file

@ -47,6 +47,7 @@ static const HParserVtable ch_vt = {
.isValidCF = h_true,
.desugar = desugar_ch,
.compile_to_rvm = ch_ctrvm,
.higher = false,
};
HParser* h_ch(const uint8_t c) {

View file

@ -76,6 +76,7 @@ static const HParserVtable charset_vt = {
.isValidCF = h_true,
.desugar = desugar_charset,
.compile_to_rvm = cs_ctrvm,
.higher = false,
};
HParser* h_ch_range(const uint8_t lower, const uint8_t upper) {

View file

@ -75,6 +75,7 @@ static const HParserVtable choice_vt = {
.isValidCF = choice_isValidCF,
.desugar = desugar_choice,
.compile_to_rvm = choice_ctrvm,
.higher = true,
};
HParser* h_choice(HParser* p, ...) {

View file

@ -39,6 +39,7 @@ static HParserVtable difference_vt = {
.isValidRegular = h_false,
.isValidCF = h_false, // XXX should this be true if both p1 and p2 are CF?
.compile_to_rvm = h_not_regular,
.higher = true,
};
HParser* h_difference(const HParser* p1, const HParser* p2) {

View file

@ -25,6 +25,7 @@ static const HParserVtable end_vt = {
.isValidCF = h_true,
.desugar = desugar_end,
.compile_to_rvm = end_ctrvm,
.higher = false,
};
HParser* h_end_p() {

View file

@ -46,6 +46,7 @@ static const HParserVtable endianness_vt = {
.isValidCF = h_false,
.desugar = NULL,
.compile_to_rvm = h_not_regular,
.higher = true,
};
HParser* h_with_endianness(char endianness, const HParser *p)

View file

@ -18,6 +18,7 @@ static const HParserVtable epsilon_vt = {
.isValidCF = h_true,
.desugar = desugar_epsilon,
.compile_to_rvm = epsilon_ctrvm,
.higher = false,
};
HParser* h_epsilon_p() {

View file

@ -49,6 +49,7 @@ static const HParserVtable ignore_vt = {
.isValidCF = ignore_isValidCF,
.desugar = desugar_ignore,
.compile_to_rvm = ignore_ctrvm,
.higher = true,
};
HParser* h_ignore(const HParser* p) {

View file

@ -105,6 +105,7 @@ static const HParserVtable ignoreseq_vt = {
.isValidCF = is_isValidCF,
.desugar = desugar_ignoreseq,
.compile_to_rvm = is_ctrvm,
.higher = true,
};

View file

@ -31,6 +31,7 @@ static const HParserVtable indirect_vt = {
.isValidCF = indirect_isValidCF,
.desugar = desugar_indirect,
.compile_to_rvm = h_not_regular,
.higher = true,
};
void h_bind_indirect__m(HAllocator *mm__, HParser* indirect, const HParser* inner) {

View file

@ -117,6 +117,7 @@ static const HParserVtable int_range_vt = {
.isValidCF = h_true,
.desugar = desugar_int_range,
.compile_to_rvm = ir_ctrvm,
.higher = false,
};
HParser* h_int_range(const HParser *p, const int64_t lower, const int64_t upper) {

View file

@ -10,7 +10,10 @@ typedef struct {
static HParseResult *parse_many(void* env, HParseState *state) {
HRepeat *env_ = (HRepeat*) env;
HCountedArray *seq = h_carray_new_sized(state->arena, (env_->count > 0 ? env_->count : 4));
size_t size = env_->count;
if(size <= 0) size = 4;
if(size > 1024) size = 1024; // let's try parsing some elements first...
HCountedArray *seq = h_carray_new_sized(state->arena, size);
size_t count = 0;
HInputStream bak;
while (env_->min_p || env_->count > count) {
@ -199,6 +202,7 @@ static const HParserVtable many_vt = {
.isValidCF = many_isValidCF,
.desugar = desugar_many,
.compile_to_rvm = many_ctrvm,
.higher = true,
};
HParser* h_many(const HParser* p) {

View file

@ -15,6 +15,7 @@ static const HParserVtable not_vt = {
.isValidRegular = h_false, /* see and.c for why */
.isValidCF = h_false,
.compile_to_rvm = h_not_regular, // Is actually regular, but the generation step is currently unable to handle it. TODO: fix this.
.higher = true,
};
HParser* h_not(const HParser* p) {

View file

@ -22,6 +22,7 @@ static const HParserVtable nothing_vt = {
.isValidCF = h_true,
.desugar = desugar_nothing,
.compile_to_rvm = nothing_ctrvm,
.higher = false,
};
HParser* h_nothing_p() {

View file

@ -84,6 +84,7 @@ static const HParserVtable optional_vt = {
.isValidCF = opt_isValidCF,
.desugar = desugar_optional,
.compile_to_rvm = opt_ctrvm,
.higher = true,
};
HParser* h_optional(const HParser* p) {

View file

@ -104,6 +104,7 @@ static const HParserVtable permutation_vt = {
.isValidCF = h_false,
.desugar = NULL,
.compile_to_rvm = h_not_regular,
.higher = true,
};
HParser* h_permutation(HParser* p, ...) {

View file

@ -93,6 +93,7 @@ static const HParserVtable sequence_vt = {
.isValidCF = sequence_isValidCF,
.desugar = desugar_sequence,
.compile_to_rvm = sequence_ctrvm,
.higher = true,
};
HParser* h_sequence(HParser* p, ...) {
@ -116,26 +117,33 @@ HParser* h_sequence__v(HParser* p, va_list ap) {
}
HParser* h_sequence__mv(HAllocator* mm__, HParser *p, va_list ap_) {
va_list ap;
size_t len = 0;
const HParser *arg;
va_copy(ap, ap_);
do {
len++;
arg = va_arg(ap, HParser *);
} while (arg);
va_end(ap);
HSequence *s = h_new(HSequence, 1);
s->p_array = h_new(HParser *, len);
s->len = 0;
va_copy(ap, ap_);
s->p_array[0] = p;
for (size_t i = 1; i < len; i++) {
s->p_array[i] = va_arg(ap, HParser *);
} while (arg);
va_end(ap);
if(p) {
// non-empty sequence
const HParser *arg;
size_t len = 0;
va_list ap;
va_copy(ap, ap_);
do {
len++;
arg = va_arg(ap, HParser *);
} while (arg);
va_end(ap);
s->p_array = h_new(HParser *, len);
va_copy(ap, ap_);
s->p_array[0] = p;
for (size_t i = 1; i < len; i++) {
s->p_array[i] = va_arg(ap, HParser *);
} while (arg);
va_end(ap);
s->len = len;
}
s->len = len;
return h_new_parser(mm__, &sequence_vt, s);
}

View file

@ -73,6 +73,7 @@ const HParserVtable token_vt = {
.isValidCF = h_true,
.desugar = desugar_token,
.compile_to_rvm = token_ctrvm,
.higher = false,
};
HParser* h_token(const uint8_t *str, const size_t len) {

View file

@ -18,6 +18,7 @@ static const HParserVtable unimplemented_vt = {
.isValidCF = h_false,
.desugar = NULL,
.compile_to_rvm = h_not_regular,
.higher = true,
};
static HParser unimplemented = {

View file

@ -26,6 +26,7 @@ static const HParserVtable put_vt = {
.isValidRegular = h_false,
.isValidCF = h_false,
.compile_to_rvm = h_not_regular,
.higher = true,
};
HParser* h_put_value(const HParser* p, const char* name) {
@ -55,6 +56,7 @@ static const HParserVtable get_vt = {
.isValidRegular = h_false,
.isValidCF = h_false,
.compile_to_rvm = h_not_regular,
.higher = true,
};
HParser* h_get_value(const char* name) {

View file

@ -75,6 +75,7 @@ static const HParserVtable whitespace_vt = {
.isValidCF = ws_isValidCF,
.desugar = desugar_whitespace,
.compile_to_rvm = ws_ctrvm,
.higher = false,
};
HParser* h_whitespace(const HParser* p) {

View file

@ -36,6 +36,7 @@ static const HParserVtable xor_vt = {
.isValidRegular = h_false,
.isValidCF = h_false, // XXX should this be true if both p1 and p2 are CF?
.compile_to_rvm = h_not_regular,
.higher = true,
};
HParser* h_xor(const HParser* p1, const HParser* p2) {