diff options
Diffstat (limited to 'miscutils/bc.c')
-rw-r--r-- | miscutils/bc.c | 33 |
1 files changed, 19 insertions, 14 deletions
diff --git a/miscutils/bc.c b/miscutils/bc.c index 1bf3e373e..630a343d1 100644 --- a/miscutils/bc.c +++ b/miscutils/bc.c | |||
@@ -617,12 +617,8 @@ struct BcParse; | |||
617 | 617 | ||
618 | struct BcProgram; | 618 | struct BcProgram; |
619 | 619 | ||
620 | typedef BC_STATUS (*BcParseParse)(struct BcParse *) FAST_FUNC; | ||
621 | |||
622 | typedef struct BcParse { | 620 | typedef struct BcParse { |
623 | 621 | ||
624 | BcParseParse parse; | ||
625 | |||
626 | BcLex l; | 622 | BcLex l; |
627 | 623 | ||
628 | BcVec flags; | 624 | BcVec flags; |
@@ -3483,6 +3479,17 @@ static void bc_parse_number(BcParse *p, BcInst *prev, size_t *nexs) | |||
3483 | (*prev) = BC_INST_NUM; | 3479 | (*prev) = BC_INST_NUM; |
3484 | } | 3480 | } |
3485 | 3481 | ||
3482 | static BC_STATUS zbc_parse_parse(BcParse *p); | ||
3483 | static BC_STATUS zdc_parse_parse(BcParse *p); | ||
3484 | |||
3485 | static BC_STATUS zcommon_parse(BcParse *p) | ||
3486 | { | ||
3487 | if (IS_BC) { | ||
3488 | IF_BC(RETURN_STATUS(zbc_parse_parse(p));) | ||
3489 | } | ||
3490 | IF_DC(RETURN_STATUS(zdc_parse_parse(p));) | ||
3491 | } | ||
3492 | |||
3486 | static BC_STATUS zbc_parse_text(BcParse *p, const char *text) | 3493 | static BC_STATUS zbc_parse_text(BcParse *p, const char *text) |
3487 | { | 3494 | { |
3488 | BcStatus s; | 3495 | BcStatus s; |
@@ -3492,7 +3499,7 @@ static BC_STATUS zbc_parse_text(BcParse *p, const char *text) | |||
3492 | if (!text[0] && !BC_PARSE_CAN_EXEC(p)) { | 3499 | if (!text[0] && !BC_PARSE_CAN_EXEC(p)) { |
3493 | p->l.t.t = BC_LEX_INVALID; | 3500 | p->l.t.t = BC_LEX_INVALID; |
3494 | s = BC_STATUS_SUCCESS; | 3501 | s = BC_STATUS_SUCCESS; |
3495 | ERROR_RETURN(s =) p->parse(p); | 3502 | ERROR_RETURN(s =) zcommon_parse(p); |
3496 | if (s) RETURN_STATUS(s); | 3503 | if (s) RETURN_STATUS(s); |
3497 | if (!BC_PARSE_CAN_EXEC(p)) | 3504 | if (!BC_PARSE_CAN_EXEC(p)) |
3498 | RETURN_STATUS(bc_error("file is not executable")); | 3505 | RETURN_STATUS(bc_error("file is not executable")); |
@@ -3556,8 +3563,7 @@ static void bc_parse_free(BcParse *p) | |||
3556 | bc_lex_free(&p->l); | 3563 | bc_lex_free(&p->l); |
3557 | } | 3564 | } |
3558 | 3565 | ||
3559 | static void bc_parse_create(BcParse *p, size_t func, | 3566 | static void bc_parse_create(BcParse *p, size_t func, BcLexNext next) |
3560 | BcParseParse parse, BcLexNext next) | ||
3561 | { | 3567 | { |
3562 | memset(p, 0, sizeof(BcParse)); | 3568 | memset(p, 0, sizeof(BcParse)); |
3563 | 3569 | ||
@@ -3568,7 +3574,6 @@ static void bc_parse_create(BcParse *p, size_t func, | |||
3568 | bc_vec_pushZeroByte(&p->flags); | 3574 | bc_vec_pushZeroByte(&p->flags); |
3569 | bc_vec_init(&p->ops, sizeof(BcLexType), NULL); | 3575 | bc_vec_init(&p->ops, sizeof(BcLexType), NULL); |
3570 | 3576 | ||
3571 | p->parse = parse; | ||
3572 | // p->auto_part = p->nbraces = 0; - already is | 3577 | // p->auto_part = p->nbraces = 0; - already is |
3573 | bc_parse_updateFunc(p, func); | 3578 | bc_parse_updateFunc(p, func); |
3574 | } | 3579 | } |
@@ -4630,7 +4635,7 @@ static BC_STATUS zbc_parse_stmt(BcParse *p) | |||
4630 | # define zbc_parse_stmt(...) (zbc_parse_stmt(__VA_ARGS__), BC_STATUS_SUCCESS) | 4635 | # define zbc_parse_stmt(...) (zbc_parse_stmt(__VA_ARGS__), BC_STATUS_SUCCESS) |
4631 | #endif | 4636 | #endif |
4632 | 4637 | ||
4633 | static FAST_FUNC BC_STATUS zbc_parse_parse(BcParse *p) | 4638 | static BC_STATUS zbc_parse_parse(BcParse *p) |
4634 | { | 4639 | { |
4635 | BcStatus s; | 4640 | BcStatus s; |
4636 | 4641 | ||
@@ -4930,7 +4935,7 @@ static BC_STATUS zbc_parse_expr(BcParse *p, uint8_t flags, BcParseNext next) | |||
4930 | 4935 | ||
4931 | static void bc_parse_init(BcParse *p, size_t func) | 4936 | static void bc_parse_init(BcParse *p, size_t func) |
4932 | { | 4937 | { |
4933 | bc_parse_create(p, func, zbc_parse_parse, zbc_lex_token); | 4938 | bc_parse_create(p, func, zbc_lex_token); |
4934 | } | 4939 | } |
4935 | 4940 | ||
4936 | static BC_STATUS zbc_parse_expression(BcParse *p, uint8_t flags) | 4941 | static BC_STATUS zbc_parse_expression(BcParse *p, uint8_t flags) |
@@ -5134,7 +5139,7 @@ static BC_STATUS zdc_parse_expr(BcParse *p, uint8_t flags) | |||
5134 | # define zdc_parse_expr(...) (zdc_parse_expr(__VA_ARGS__), BC_STATUS_SUCCESS) | 5139 | # define zdc_parse_expr(...) (zdc_parse_expr(__VA_ARGS__), BC_STATUS_SUCCESS) |
5135 | #endif | 5140 | #endif |
5136 | 5141 | ||
5137 | static FAST_FUNC BC_STATUS zdc_parse_parse(BcParse *p) | 5142 | static BC_STATUS zdc_parse_parse(BcParse *p) |
5138 | { | 5143 | { |
5139 | BcStatus s; | 5144 | BcStatus s; |
5140 | 5145 | ||
@@ -5156,7 +5161,7 @@ static FAST_FUNC BC_STATUS zdc_parse_parse(BcParse *p) | |||
5156 | 5161 | ||
5157 | static void dc_parse_init(BcParse *p, size_t func) | 5162 | static void dc_parse_init(BcParse *p, size_t func) |
5158 | { | 5163 | { |
5159 | bc_parse_create(p, func, zdc_parse_parse, zdc_lex_token); | 5164 | bc_parse_create(p, func, zdc_lex_token); |
5160 | } | 5165 | } |
5161 | 5166 | ||
5162 | #endif // ENABLE_DC | 5167 | #endif // ENABLE_DC |
@@ -7011,7 +7016,7 @@ static BC_STATUS zbc_vm_process(const char *text) | |||
7011 | if (s) RETURN_STATUS(s); | 7016 | if (s) RETURN_STATUS(s); |
7012 | 7017 | ||
7013 | while (G.prs.l.t.t != BC_LEX_EOF) { | 7018 | while (G.prs.l.t.t != BC_LEX_EOF) { |
7014 | ERROR_RETURN(s =) G.prs.parse(&G.prs); | 7019 | ERROR_RETURN(s =) zcommon_parse(&G.prs); |
7015 | if (s) RETURN_STATUS(s); | 7020 | if (s) RETURN_STATUS(s); |
7016 | } | 7021 | } |
7017 | 7022 | ||
@@ -7347,7 +7352,7 @@ static BC_STATUS zbc_vm_exec(void) | |||
7347 | if (DEBUG_LIB && s) RETURN_STATUS(s); | 7352 | if (DEBUG_LIB && s) RETURN_STATUS(s); |
7348 | 7353 | ||
7349 | while (G.prs.l.t.t != BC_LEX_EOF) { | 7354 | while (G.prs.l.t.t != BC_LEX_EOF) { |
7350 | ERROR_RETURN(s =) G.prs.parse(&G.prs); | 7355 | ERROR_RETURN(s =) zcommon_parse(&G.prs); |
7351 | if (DEBUG_LIB && s) RETURN_STATUS(s); | 7356 | if (DEBUG_LIB && s) RETURN_STATUS(s); |
7352 | } | 7357 | } |
7353 | s = zbc_program_exec(); | 7358 | s = zbc_program_exec(); |