Refactored all of the desugaring code to no longer depend on memory being initialized to 0. Everything is about 12% faster now.
This commit is contained in:
parent
d71215d494
commit
ec404ca8fe
36 changed files with 411 additions and 417 deletions
|
|
@ -17,39 +17,26 @@ static HParseResult* parse_whitespace(void* env, HParseState *state) {
|
|||
|
||||
static const char SPACE_CHRS[6] = {' ', '\f', '\n', '\r', '\t', '\v'};
|
||||
|
||||
static HCFChoice* desugar_whitespace(HAllocator *mm__, void *env) {
|
||||
HCFChoice *ws = h_new(HCFChoice, 1);
|
||||
ws->type = HCF_CHOICE;
|
||||
ws->seq = h_new(HCFSequence*, 3);
|
||||
HCFSequence *nonempty = h_new(HCFSequence, 1);
|
||||
nonempty->items = h_new(HCFChoice*, 3);
|
||||
nonempty->items[0] = h_new(HCFChoice, 1);
|
||||
nonempty->items[0]->type = HCF_CHARSET;
|
||||
nonempty->items[0]->charset = new_charset(mm__);
|
||||
static void desugar_whitespace(HAllocator *mm__, HCFStack *stk__, void *env) {
|
||||
|
||||
HCharset ws_cs = new_charset(mm__);
|
||||
for(size_t i=0; i<sizeof(SPACE_CHRS); i++)
|
||||
charset_set(nonempty->items[0]->charset, SPACE_CHRS[i], 1);
|
||||
nonempty->items[1] = ws; // yay circular pointer!
|
||||
nonempty->items[2] = NULL;
|
||||
ws->seq[0] = nonempty;
|
||||
HCFSequence *empty = h_new(HCFSequence, 1);
|
||||
empty->items = h_new(HCFChoice*, 1);
|
||||
empty->items[0] = NULL;
|
||||
ws->seq[1] = empty;
|
||||
ws->seq[2] = NULL;
|
||||
|
||||
HCFChoice *ret = h_new(HCFChoice, 1);
|
||||
ret->type = HCF_CHOICE;
|
||||
ret->seq = h_new(HCFSequence*, 2);
|
||||
ret->seq[0] = h_new(HCFSequence, 1);
|
||||
ret->seq[0]->items = h_new(HCFChoice*, 3);
|
||||
ret->seq[0]->items[0] = ws;
|
||||
ret->seq[0]->items[1] = h_desugar(mm__, (HParser *)env);
|
||||
ret->seq[0]->items[2] = NULL;
|
||||
ret->seq[1] = NULL;
|
||||
|
||||
ret->reshape = h_act_last;
|
||||
charset_set(ws_cs, SPACE_CHRS[i], 1);
|
||||
|
||||
return ret;
|
||||
HCFS_BEGIN_CHOICE() {
|
||||
HCFS_BEGIN_SEQ() {
|
||||
HCFS_BEGIN_CHOICE() {
|
||||
HCFS_BEGIN_SEQ() {
|
||||
HCFS_ADD_CHARSET(ws_cs);
|
||||
HCFS_APPEND(HCFS_THIS_CHOICE); // yay circular pointer!
|
||||
} HCFS_END_SEQ();
|
||||
HCFS_BEGIN_SEQ() {
|
||||
} HCFS_END_SEQ();
|
||||
} HCFS_END_CHOICE();
|
||||
HCFS_DESUGAR( (HParser*)env );
|
||||
} HCFS_END_SEQ();
|
||||
HCFS_THIS_CHOICE->reshape = h_act_last;
|
||||
} HCFS_END_CHOICE();
|
||||
}
|
||||
|
||||
static bool ws_isValidRegular(void *env) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue