diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2018-12-24 04:26:07 +0100 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2018-12-24 04:26:07 +0100 |
commit | a7732d11204d04f14ec69103128a3a6bec7d525d (patch) | |
tree | a38ee54d158fcc5d3ff56999ba9b3fc17bcc4cae /miscutils/bc.c | |
parent | 81293c8af04913a632c32a305e505dcbf059d9d5 (diff) | |
download | busybox-w32-a7732d11204d04f14ec69103128a3a6bec7d525d.tar.gz busybox-w32-a7732d11204d04f14ec69103128a3a6bec7d525d.tar.bz2 busybox-w32-a7732d11204d04f14ec69103128a3a6bec7d525d.zip |
bc: rename common INST constants to XC_, dc-specific ones to DC_
This will assist in disentangling dc and bc LEX constants
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to '')
-rw-r--r-- | miscutils/bc.c | 485 |
1 files changed, 242 insertions, 243 deletions
diff --git a/miscutils/bc.c b/miscutils/bc.c index ac3eaff96..7d3b6b7ed 100644 --- a/miscutils/bc.c +++ b/miscutils/bc.c | |||
@@ -251,26 +251,25 @@ typedef enum BcInst { | |||
251 | BC_INST_INC_POST, | 251 | BC_INST_INC_POST, |
252 | BC_INST_DEC_POST, | 252 | BC_INST_DEC_POST, |
253 | #endif | 253 | #endif |
254 | 254 | XC_INST_NEG, | |
255 | BC_INST_NEG, | 255 | |
256 | 256 | XC_INST_POWER, | |
257 | BC_INST_POWER, | 257 | XC_INST_MULTIPLY, |
258 | BC_INST_MULTIPLY, | 258 | XC_INST_DIVIDE, |
259 | BC_INST_DIVIDE, | 259 | XC_INST_MODULUS, |
260 | BC_INST_MODULUS, | 260 | XC_INST_PLUS, |
261 | BC_INST_PLUS, | 261 | XC_INST_MINUS, |
262 | BC_INST_MINUS, | 262 | |
263 | 263 | XC_INST_REL_EQ, | |
264 | BC_INST_REL_EQ, | 264 | XC_INST_REL_LE, |
265 | BC_INST_REL_LE, | 265 | XC_INST_REL_GE, |
266 | BC_INST_REL_GE, | 266 | XC_INST_REL_NE, |
267 | BC_INST_REL_NE, | 267 | XC_INST_REL_LT, |
268 | BC_INST_REL_LT, | 268 | XC_INST_REL_GT, |
269 | BC_INST_REL_GT, | 269 | |
270 | 270 | XC_INST_BOOL_NOT, | |
271 | BC_INST_BOOL_NOT, | 271 | XC_INST_BOOL_OR, |
272 | BC_INST_BOOL_OR, | 272 | XC_INST_BOOL_AND, |
273 | BC_INST_BOOL_AND, | ||
274 | 273 | ||
275 | #if ENABLE_BC | 274 | #if ENABLE_BC |
276 | BC_INST_ASSIGN_POWER, | 275 | BC_INST_ASSIGN_POWER, |
@@ -280,26 +279,26 @@ typedef enum BcInst { | |||
280 | BC_INST_ASSIGN_PLUS, | 279 | BC_INST_ASSIGN_PLUS, |
281 | BC_INST_ASSIGN_MINUS, | 280 | BC_INST_ASSIGN_MINUS, |
282 | #endif | 281 | #endif |
283 | BC_INST_ASSIGN, | 282 | XC_INST_ASSIGN, |
284 | 283 | ||
285 | BC_INST_NUM, | 284 | XC_INST_NUM, |
286 | BC_INST_VAR, | 285 | XC_INST_VAR, |
287 | BC_INST_ARRAY_ELEM, | 286 | XC_INST_ARRAY_ELEM, |
288 | BC_INST_ARRAY, | 287 | XC_INST_ARRAY, |
289 | BC_INST_SCALE_FUNC, | 288 | XC_INST_SCALE_FUNC, |
290 | 289 | ||
291 | BC_INST_IBASE, // order of these constans should match other enums | 290 | XC_INST_IBASE, // order of these constans should match other enums |
292 | BC_INST_OBASE, // order of these constans should match other enums | 291 | XC_INST_OBASE, // order of these constans should match other enums |
293 | BC_INST_SCALE, // order of these constans should match other enums | 292 | XC_INST_SCALE, // order of these constans should match other enums |
294 | IF_BC(BC_INST_LAST,) // order of these constans should match other enums | 293 | IF_BC(BC_INST_LAST,) // order of these constans should match other enums |
295 | BC_INST_LENGTH, | 294 | XC_INST_LENGTH, |
296 | BC_INST_READ, | 295 | XC_INST_READ, |
297 | BC_INST_SQRT, | 296 | XC_INST_SQRT, |
298 | 297 | ||
299 | BC_INST_PRINT, | 298 | XC_INST_PRINT, |
300 | BC_INST_PRINT_POP, | 299 | XC_INST_PRINT_POP, |
301 | BC_INST_STR, | 300 | XC_INST_STR, |
302 | BC_INST_PRINT_STR, | 301 | XC_INST_PRINT_STR, |
303 | 302 | ||
304 | #if ENABLE_BC | 303 | #if ENABLE_BC |
305 | BC_INST_HALT, | 304 | BC_INST_HALT, |
@@ -309,35 +308,35 @@ typedef enum BcInst { | |||
309 | BC_INST_CALL, | 308 | BC_INST_CALL, |
310 | BC_INST_RET0, | 309 | BC_INST_RET0, |
311 | #endif | 310 | #endif |
312 | BC_INST_RET, | 311 | XC_INST_RET, |
313 | 312 | ||
314 | BC_INST_POP, | 313 | XC_INST_POP, |
315 | #if ENABLE_DC | 314 | #if ENABLE_DC |
316 | BC_INST_POP_EXEC, | 315 | DC_INST_POP_EXEC, |
317 | 316 | ||
318 | BC_INST_MODEXP, | 317 | DC_INST_MODEXP, |
319 | BC_INST_DIVMOD, | 318 | DC_INST_DIVMOD, |
320 | 319 | ||
321 | BC_INST_EXECUTE, | 320 | DC_INST_EXECUTE, |
322 | BC_INST_EXEC_COND, | 321 | DC_INST_EXEC_COND, |
323 | 322 | ||
324 | BC_INST_ASCIIFY, | 323 | DC_INST_ASCIIFY, |
325 | BC_INST_PRINT_STREAM, | 324 | DC_INST_PRINT_STREAM, |
326 | 325 | ||
327 | BC_INST_PRINT_STACK, | 326 | DC_INST_PRINT_STACK, |
328 | BC_INST_CLEAR_STACK, | 327 | DC_INST_CLEAR_STACK, |
329 | BC_INST_STACK_LEN, | 328 | DC_INST_STACK_LEN, |
330 | BC_INST_DUPLICATE, | 329 | DC_INST_DUPLICATE, |
331 | BC_INST_SWAP, | 330 | DC_INST_SWAP, |
332 | 331 | ||
333 | BC_INST_LOAD, | 332 | DC_INST_LOAD, |
334 | BC_INST_PUSH_VAR, | 333 | DC_INST_PUSH_VAR, |
335 | BC_INST_PUSH_TO_VAR, | 334 | DC_INST_PUSH_TO_VAR, |
336 | 335 | ||
337 | BC_INST_QUIT, | 336 | DC_INST_QUIT, |
338 | BC_INST_NQUIT, | 337 | DC_INST_NQUIT, |
339 | 338 | ||
340 | BC_INST_INVALID = -1, | 339 | DC_INST_INVALID = -1, |
341 | #endif | 340 | #endif |
342 | } BcInst; | 341 | } BcInst; |
343 | 342 | ||
@@ -364,10 +363,10 @@ typedef enum BcResultType { | |||
364 | 363 | ||
365 | BC_RESULT_STR, | 364 | BC_RESULT_STR, |
366 | 365 | ||
367 | //code uses "inst - BC_INST_IBASE + BC_RESULT_IBASE" construct, | 366 | //code uses "inst - XC_INST_IBASE + BC_RESULT_IBASE" construct, |
368 | BC_RESULT_IBASE, // relative order should match for: BC_INST_IBASE | 367 | BC_RESULT_IBASE, // relative order should match for: XC_INST_IBASE |
369 | BC_RESULT_OBASE, // relative order should match for: BC_INST_OBASE | 368 | BC_RESULT_OBASE, // relative order should match for: XC_INST_OBASE |
370 | BC_RESULT_SCALE, // relative order should match for: BC_INST_SCALE | 369 | BC_RESULT_SCALE, // relative order should match for: XC_INST_SCALE |
371 | IF_BC(BC_RESULT_LAST,) // relative order should match for: BC_INST_LAST | 370 | IF_BC(BC_RESULT_LAST,) // relative order should match for: BC_INST_LAST |
372 | BC_RESULT_CONSTANT, | 371 | BC_RESULT_CONSTANT, |
373 | BC_RESULT_ONE, | 372 | BC_RESULT_ONE, |
@@ -452,9 +451,9 @@ typedef enum BcLexType { | |||
452 | BC_LEX_KEY_ELSE, | 451 | BC_LEX_KEY_ELSE, |
453 | BC_LEX_KEY_FOR, | 452 | BC_LEX_KEY_FOR, |
454 | BC_LEX_KEY_HALT, | 453 | BC_LEX_KEY_HALT, |
455 | // code uses "type - BC_LEX_KEY_IBASE + BC_INST_IBASE" construct, | 454 | // code uses "type - BC_LEX_KEY_IBASE + XC_INST_IBASE" construct, |
456 | BC_LEX_KEY_IBASE, // relative order should match for: BC_INST_IBASE | 455 | BC_LEX_KEY_IBASE, // relative order should match for: XC_INST_IBASE |
457 | BC_LEX_KEY_OBASE, // relative order should match for: BC_INST_OBASE | 456 | BC_LEX_KEY_OBASE, // relative order should match for: XC_INST_OBASE |
458 | BC_LEX_KEY_IF, | 457 | BC_LEX_KEY_IF, |
459 | IF_BC(BC_LEX_KEY_LAST,) // relative order should match for: BC_INST_LAST | 458 | IF_BC(BC_LEX_KEY_LAST,) // relative order should match for: BC_INST_LAST |
460 | BC_LEX_KEY_LENGTH, | 459 | BC_LEX_KEY_LENGTH, |
@@ -485,10 +484,10 @@ typedef enum BcLexType { | |||
485 | BC_LEX_ASCIIFY, | 484 | BC_LEX_ASCIIFY, |
486 | BC_LEX_PRINT_STREAM, | 485 | BC_LEX_PRINT_STREAM, |
487 | 486 | ||
488 | // code uses "t - BC_LEX_STORE_IBASE + BC_INST_IBASE" construct, | 487 | // code uses "t - BC_LEX_STORE_IBASE + XC_INST_IBASE" construct, |
489 | BC_LEX_STORE_IBASE, // relative order should match for: BC_INST_IBASE | 488 | BC_LEX_STORE_IBASE, // relative order should match for: XC_INST_IBASE |
490 | BC_LEX_STORE_OBASE, // relative order should match for: BC_INST_OBASE | 489 | BC_LEX_STORE_OBASE, // relative order should match for: XC_INST_OBASE |
491 | BC_LEX_STORE_SCALE, // relative order should match for: BC_INST_SCALE | 490 | BC_LEX_STORE_SCALE, // relative order should match for: XC_INST_SCALE |
492 | BC_LEX_LOAD, | 491 | BC_LEX_LOAD, |
493 | BC_LEX_LOAD_POP, | 492 | BC_LEX_LOAD_POP, |
494 | BC_LEX_STORE_PUSH, | 493 | BC_LEX_STORE_PUSH, |
@@ -656,32 +655,32 @@ dc_char_to_LEX[] = { | |||
656 | /* {|}~ */ | 655 | /* {|}~ */ |
657 | BC_LEX_LBRACE, BC_LEX_OP_MODEXP, BC_LEX_INVALID, BC_LEX_OP_DIVMOD, | 656 | BC_LEX_LBRACE, BC_LEX_OP_MODEXP, BC_LEX_INVALID, BC_LEX_OP_DIVMOD, |
658 | }; | 657 | }; |
659 | static const //BcInst - should be this type. Using signed narrow type since BC_INST_INVALID is -1 | 658 | static const //BcInst - should be this type. Using signed narrow type since DC_INST_INVALID is -1 |
660 | int8_t | 659 | int8_t |
661 | dc_LEX_to_INST[] = { // (so many INVALIDs b/c dc parser does not generate these LEXs) // corresponding BC_LEX_xyz: | 660 | dc_LEX_to_INST[] = { // (so many INVALIDs b/c dc parser does not generate these LEXs) // corresponding BC_LEX_xyz: |
662 | BC_INST_INVALID, BC_INST_INVALID, BC_INST_INVALID, BC_INST_REL_GE, // EOF INVALID OP_INC OP_DEC | 661 | DC_INST_INVALID, DC_INST_INVALID, DC_INST_INVALID, XC_INST_REL_GE, // EOF INVALID OP_INC OP_DEC |
663 | BC_INST_INVALID, BC_INST_POWER, BC_INST_MULTIPLY, BC_INST_DIVIDE, // NEG OP_POWER OP_MULTIPLY OP_DIVIDE | 662 | DC_INST_INVALID, XC_INST_POWER, XC_INST_MULTIPLY, XC_INST_DIVIDE, // NEG OP_POWER OP_MULTIPLY OP_DIVIDE |
664 | BC_INST_MODULUS, BC_INST_PLUS, BC_INST_MINUS, // OP_MODULUS OP_PLUS OP_MINUS | 663 | XC_INST_MODULUS, XC_INST_PLUS, XC_INST_MINUS, // OP_MODULUS OP_PLUS OP_MINUS |
665 | BC_INST_INVALID, BC_INST_INVALID, BC_INST_INVALID, BC_INST_INVALID, // OP_REL_EQ OP_REL_LE OP_REL_GE OP_REL_NE | 664 | DC_INST_INVALID, DC_INST_INVALID, DC_INST_INVALID, DC_INST_INVALID, // OP_REL_EQ OP_REL_LE OP_REL_GE OP_REL_NE |
666 | BC_INST_INVALID, BC_INST_INVALID, // OP_REL_LT OP_REL_GT | 665 | DC_INST_INVALID, DC_INST_INVALID, // OP_REL_LT OP_REL_GT |
667 | BC_INST_BOOL_NOT, BC_INST_INVALID, BC_INST_INVALID, // OP_BOOL_NOT OP_BOOL_OR OP_BOOL_AND | 666 | XC_INST_BOOL_NOT, DC_INST_INVALID, DC_INST_INVALID, // OP_BOOL_NOT OP_BOOL_OR OP_BOOL_AND |
668 | BC_INST_INVALID, BC_INST_INVALID, BC_INST_INVALID, BC_INST_INVALID, // OP_ASSIGN_POWER OP_ASSIGN_MULTIPLY OP_ASSIGN_DIVIDE OP_ASSIGN_MODULUS | 667 | DC_INST_INVALID, DC_INST_INVALID, DC_INST_INVALID, DC_INST_INVALID, // OP_ASSIGN_POWER OP_ASSIGN_MULTIPLY OP_ASSIGN_DIVIDE OP_ASSIGN_MODULUS |
669 | BC_INST_INVALID, BC_INST_INVALID, BC_INST_INVALID, // OP_ASSIGN_PLUS OP_ASSIGN_MINUS OP_ASSIGN | 668 | DC_INST_INVALID, DC_INST_INVALID, DC_INST_INVALID, // OP_ASSIGN_PLUS OP_ASSIGN_MINUS OP_ASSIGN |
670 | BC_INST_INVALID, BC_INST_INVALID, BC_INST_REL_GT, BC_INST_INVALID, // NLINE WHITESPACE LPAREN RPAREN | 669 | DC_INST_INVALID, DC_INST_INVALID, XC_INST_REL_GT, DC_INST_INVALID, // NLINE WHITESPACE LPAREN RPAREN |
671 | BC_INST_INVALID, BC_INST_INVALID, BC_INST_INVALID, BC_INST_REL_GE, // LBRACKET COMMA RBRACKET LBRACE | 670 | DC_INST_INVALID, DC_INST_INVALID, DC_INST_INVALID, XC_INST_REL_GE, // LBRACKET COMMA RBRACKET LBRACE |
672 | BC_INST_INVALID, BC_INST_INVALID, // SCOLON RBRACE | 671 | DC_INST_INVALID, DC_INST_INVALID, // SCOLON RBRACE |
673 | BC_INST_INVALID, BC_INST_INVALID, BC_INST_INVALID, // STR NAME NUMBER | 672 | DC_INST_INVALID, DC_INST_INVALID, DC_INST_INVALID, // STR NAME NUMBER |
674 | BC_INST_INVALID, BC_INST_INVALID, BC_INST_INVALID, BC_INST_INVALID, // KEY_AUTO KEY_BREAK KEY_CONTINUE KEY_DEFINE | 673 | DC_INST_INVALID, DC_INST_INVALID, DC_INST_INVALID, DC_INST_INVALID, // KEY_AUTO KEY_BREAK KEY_CONTINUE KEY_DEFINE |
675 | BC_INST_INVALID, BC_INST_INVALID, BC_INST_INVALID, BC_INST_IBASE, // KEY_ELSE KEY_FOR KEY_HALT KEY_IBASE | 674 | DC_INST_INVALID, DC_INST_INVALID, DC_INST_INVALID, XC_INST_IBASE, // KEY_ELSE KEY_FOR KEY_HALT KEY_IBASE |
676 | BC_INST_OBASE, BC_INST_INVALID, IF_BC(BC_INST_INVALID,) BC_INST_LENGTH,//KEY_OBASE KEY_IF KEY_LAST(bc) KEY_LENGTH | 675 | XC_INST_OBASE, DC_INST_INVALID, IF_BC(DC_INST_INVALID,) XC_INST_LENGTH,//KEY_OBASE KEY_IF KEY_LAST(bc) KEY_LENGTH |
677 | BC_INST_INVALID, BC_INST_PRINT, BC_INST_QUIT, BC_INST_INVALID, // KEY_LIMITS KEY_PRINT KEY_QUIT KEY_READ | 676 | DC_INST_INVALID, XC_INST_PRINT, DC_INST_QUIT, DC_INST_INVALID, // KEY_LIMITS KEY_PRINT KEY_QUIT KEY_READ |
678 | BC_INST_INVALID, BC_INST_SCALE, BC_INST_SQRT, BC_INST_INVALID, // KEY_RETURN KEY_SCALE KEY_SQRT KEY_WHILE | 677 | DC_INST_INVALID, XC_INST_SCALE, XC_INST_SQRT, DC_INST_INVALID, // KEY_RETURN KEY_SCALE KEY_SQRT KEY_WHILE |
679 | BC_INST_REL_EQ, BC_INST_MODEXP, BC_INST_DIVMOD, BC_INST_INVALID, // EQ_NO_REG OP_MODEXP OP_DIVMOD COLON | 678 | XC_INST_REL_EQ, DC_INST_MODEXP, DC_INST_DIVMOD, DC_INST_INVALID, // EQ_NO_REG OP_MODEXP OP_DIVMOD COLON |
680 | BC_INST_INVALID, BC_INST_EXECUTE, BC_INST_PRINT_STACK, BC_INST_CLEAR_STACK, //ELSE EXECUTE PRINT_STACK CLEAR_STACK | 679 | DC_INST_INVALID, DC_INST_EXECUTE, DC_INST_PRINT_STACK, DC_INST_CLEAR_STACK, //ELSE EXECUTE PRINT_STACK CLEAR_STACK |
681 | BC_INST_STACK_LEN, BC_INST_DUPLICATE, BC_INST_SWAP, BC_INST_POP, // STACK_LEVEL DUPLICATE SWAP POP | 680 | DC_INST_STACK_LEN, DC_INST_DUPLICATE, DC_INST_SWAP, XC_INST_POP, // STACK_LEVEL DUPLICATE SWAP POP |
682 | BC_INST_ASCIIFY, BC_INST_PRINT_STREAM, BC_INST_INVALID, BC_INST_INVALID, //ASCIIFY PRINT_STREAM STORE_IBASE STORE_OBASE | 681 | DC_INST_ASCIIFY, DC_INST_PRINT_STREAM, DC_INST_INVALID, DC_INST_INVALID, //ASCIIFY PRINT_STREAM STORE_IBASE STORE_OBASE |
683 | BC_INST_INVALID, BC_INST_INVALID, BC_INST_INVALID, BC_INST_INVALID, // STORE_SCALE LOAD LOAD_POP STORE_PUSH | 682 | DC_INST_INVALID, DC_INST_INVALID, DC_INST_INVALID, DC_INST_INVALID, // STORE_SCALE LOAD LOAD_POP STORE_PUSH |
684 | BC_INST_PRINT, BC_INST_NQUIT, BC_INST_SCALE_FUNC, // PRINT_POP NQUIT SCALE_FACTOR | 683 | XC_INST_PRINT, DC_INST_NQUIT, XC_INST_SCALE_FUNC, // PRINT_POP NQUIT SCALE_FACTOR |
685 | }; | 684 | }; |
686 | #endif // ENABLE_DC | 685 | #endif // ENABLE_DC |
687 | 686 | ||
@@ -3569,7 +3568,7 @@ static BC_STATUS zbc_parse_pushSTR(BcParse *p) | |||
3569 | { | 3568 | { |
3570 | char *str = xstrdup(p->l.t.v.v); | 3569 | char *str = xstrdup(p->l.t.v.v); |
3571 | 3570 | ||
3572 | bc_parse_push(p, BC_INST_STR); | 3571 | bc_parse_push(p, XC_INST_STR); |
3573 | bc_parse_pushIndex(p, p->func->strs.len); | 3572 | bc_parse_pushIndex(p, p->func->strs.len); |
3574 | bc_vec_push(&p->func->strs, &str); | 3573 | bc_vec_push(&p->func->strs, &str); |
3575 | 3574 | ||
@@ -3588,7 +3587,7 @@ static void bc_parse_pushNUM(BcParse *p) | |||
3588 | #else // DC | 3587 | #else // DC |
3589 | size_t idx = bc_vec_push(&G.prog.consts, &num); | 3588 | size_t idx = bc_vec_push(&G.prog.consts, &num); |
3590 | #endif | 3589 | #endif |
3591 | bc_parse_push(p, BC_INST_NUM); | 3590 | bc_parse_push(p, XC_INST_NUM); |
3592 | bc_parse_pushIndex(p, idx); | 3591 | bc_parse_pushIndex(p, idx); |
3593 | } | 3592 | } |
3594 | 3593 | ||
@@ -3701,13 +3700,13 @@ static size_t bc_program_addFunc(char *name) | |||
3701 | 3700 | ||
3702 | #define BC_PARSE_TOP_OP(p) (*((BcLexType *) bc_vec_top(&(p)->ops))) | 3701 | #define BC_PARSE_TOP_OP(p) (*((BcLexType *) bc_vec_top(&(p)->ops))) |
3703 | #define BC_PARSE_LEAF(p, rparen) \ | 3702 | #define BC_PARSE_LEAF(p, rparen) \ |
3704 | (((p) >= BC_INST_NUM && (p) <= BC_INST_SQRT) || (rparen) || \ | 3703 | (((p) >= XC_INST_NUM && (p) <= XC_INST_SQRT) || (rparen) || \ |
3705 | (p) == BC_INST_INC_POST || (p) == BC_INST_DEC_POST) | 3704 | (p) == BC_INST_INC_POST || (p) == BC_INST_DEC_POST) |
3706 | 3705 | ||
3707 | // We can calculate the conversion between tokens and exprs by subtracting the | 3706 | // We can calculate the conversion between tokens and exprs by subtracting the |
3708 | // position of the first operator in the lex enum and adding the position of the | 3707 | // position of the first operator in the lex enum and adding the position of the |
3709 | // first in the expr enum. Note: This only works for binary operators. | 3708 | // first in the expr enum. Note: This only works for binary operators. |
3710 | #define BC_TOKEN_2_INST(t) ((char) ((t) - BC_LEX_NEG + BC_INST_NEG)) | 3709 | #define BC_TOKEN_2_INST(t) ((char) ((t) - BC_LEX_NEG + XC_INST_NEG)) |
3711 | 3710 | ||
3712 | static BcStatus bc_parse_expr_empty_ok(BcParse *p, uint8_t flags); | 3711 | static BcStatus bc_parse_expr_empty_ok(BcParse *p, uint8_t flags); |
3713 | 3712 | ||
@@ -3878,9 +3877,9 @@ static BC_STATUS zbc_parse_name(BcParse *p, BcInst *type, uint8_t flags) | |||
3878 | s = bc_error_bad_expression(); | 3877 | s = bc_error_bad_expression(); |
3879 | goto err; | 3878 | goto err; |
3880 | } | 3879 | } |
3881 | *type = BC_INST_ARRAY; | 3880 | *type = XC_INST_ARRAY; |
3882 | } else { | 3881 | } else { |
3883 | *type = BC_INST_ARRAY_ELEM; | 3882 | *type = XC_INST_ARRAY_ELEM; |
3884 | flags &= ~(BC_PARSE_PRINT | BC_PARSE_REL); | 3883 | flags &= ~(BC_PARSE_PRINT | BC_PARSE_REL); |
3885 | s = zbc_parse_expr(p, flags); | 3884 | s = zbc_parse_expr(p, flags); |
3886 | if (s) goto err; | 3885 | if (s) goto err; |
@@ -3898,8 +3897,8 @@ static BC_STATUS zbc_parse_name(BcParse *p, BcInst *type, uint8_t flags) | |||
3898 | *type = BC_INST_CALL; | 3897 | *type = BC_INST_CALL; |
3899 | s = zbc_parse_call(p, name, flags); | 3898 | s = zbc_parse_call(p, name, flags); |
3900 | } else { | 3899 | } else { |
3901 | *type = BC_INST_VAR; | 3900 | *type = XC_INST_VAR; |
3902 | bc_parse_push(p, BC_INST_VAR); | 3901 | bc_parse_push(p, XC_INST_VAR); |
3903 | bc_parse_pushName(p, name); | 3902 | bc_parse_pushName(p, name); |
3904 | free(name); | 3903 | free(name); |
3905 | } | 3904 | } |
@@ -3923,7 +3922,7 @@ static BC_STATUS zbc_parse_read(BcParse *p) | |||
3923 | if (s) RETURN_STATUS(s); | 3922 | if (s) RETURN_STATUS(s); |
3924 | if (p->l.t.t != BC_LEX_RPAREN) RETURN_STATUS(bc_error_bad_token()); | 3923 | if (p->l.t.t != BC_LEX_RPAREN) RETURN_STATUS(bc_error_bad_token()); |
3925 | 3924 | ||
3926 | bc_parse_push(p, BC_INST_READ); | 3925 | bc_parse_push(p, XC_INST_READ); |
3927 | 3926 | ||
3928 | RETURN_STATUS(zbc_lex_next(&p->l)); | 3927 | RETURN_STATUS(zbc_lex_next(&p->l)); |
3929 | } | 3928 | } |
@@ -3948,7 +3947,7 @@ static BC_STATUS zbc_parse_builtin(BcParse *p, BcLexType type, uint8_t flags, | |||
3948 | 3947 | ||
3949 | if (p->l.t.t != BC_LEX_RPAREN) RETURN_STATUS(bc_error_bad_token()); | 3948 | if (p->l.t.t != BC_LEX_RPAREN) RETURN_STATUS(bc_error_bad_token()); |
3950 | 3949 | ||
3951 | *prev = (type == BC_LEX_KEY_LENGTH) ? BC_INST_LENGTH : BC_INST_SQRT; | 3950 | *prev = (type == BC_LEX_KEY_LENGTH) ? XC_INST_LENGTH : XC_INST_SQRT; |
3952 | bc_parse_push(p, *prev); | 3951 | bc_parse_push(p, *prev); |
3953 | 3952 | ||
3954 | RETURN_STATUS(zbc_lex_next(&p->l)); | 3953 | RETURN_STATUS(zbc_lex_next(&p->l)); |
@@ -3963,12 +3962,12 @@ static BC_STATUS zbc_parse_scale(BcParse *p, BcInst *type, uint8_t flags) | |||
3963 | if (s) RETURN_STATUS(s); | 3962 | if (s) RETURN_STATUS(s); |
3964 | 3963 | ||
3965 | if (p->l.t.t != BC_LEX_LPAREN) { | 3964 | if (p->l.t.t != BC_LEX_LPAREN) { |
3966 | *type = BC_INST_SCALE; | 3965 | *type = XC_INST_SCALE; |
3967 | bc_parse_push(p, BC_INST_SCALE); | 3966 | bc_parse_push(p, XC_INST_SCALE); |
3968 | RETURN_STATUS(BC_STATUS_SUCCESS); | 3967 | RETURN_STATUS(BC_STATUS_SUCCESS); |
3969 | } | 3968 | } |
3970 | 3969 | ||
3971 | *type = BC_INST_SCALE_FUNC; | 3970 | *type = XC_INST_SCALE_FUNC; |
3972 | flags &= ~(BC_PARSE_PRINT | BC_PARSE_REL); | 3971 | flags &= ~(BC_PARSE_PRINT | BC_PARSE_REL); |
3973 | 3972 | ||
3974 | s = zbc_lex_next(&p->l); | 3973 | s = zbc_lex_next(&p->l); |
@@ -3978,7 +3977,7 @@ static BC_STATUS zbc_parse_scale(BcParse *p, BcInst *type, uint8_t flags) | |||
3978 | if (s) RETURN_STATUS(s); | 3977 | if (s) RETURN_STATUS(s); |
3979 | if (p->l.t.t != BC_LEX_RPAREN) | 3978 | if (p->l.t.t != BC_LEX_RPAREN) |
3980 | RETURN_STATUS(bc_error_bad_token()); | 3979 | RETURN_STATUS(bc_error_bad_token()); |
3981 | bc_parse_push(p, BC_INST_SCALE_FUNC); | 3980 | bc_parse_push(p, XC_INST_SCALE_FUNC); |
3982 | 3981 | ||
3983 | RETURN_STATUS(zbc_lex_next(&p->l)); | 3982 | RETURN_STATUS(zbc_lex_next(&p->l)); |
3984 | } | 3983 | } |
@@ -3992,9 +3991,9 @@ static BC_STATUS zbc_parse_incdec(BcParse *p, BcInst *prev, bool *paren_expr, | |||
3992 | char inst; | 3991 | char inst; |
3993 | BcInst etype = *prev; | 3992 | BcInst etype = *prev; |
3994 | 3993 | ||
3995 | if (etype == BC_INST_VAR || etype == BC_INST_ARRAY_ELEM | 3994 | if (etype == XC_INST_VAR || etype == XC_INST_ARRAY_ELEM |
3996 | || etype == BC_INST_SCALE || etype == BC_INST_LAST | 3995 | || etype == XC_INST_SCALE || etype == BC_INST_LAST |
3997 | || etype == BC_INST_IBASE || etype == BC_INST_OBASE | 3996 | || etype == XC_INST_IBASE || etype == XC_INST_OBASE |
3998 | ) { | 3997 | ) { |
3999 | *prev = inst = BC_INST_INC_POST + (p->l.t.t != BC_LEX_OP_INC); | 3998 | *prev = inst = BC_INST_INC_POST + (p->l.t.t != BC_LEX_OP_INC); |
4000 | bc_parse_push(p, inst); | 3999 | bc_parse_push(p, inst); |
@@ -4018,7 +4017,7 @@ static BC_STATUS zbc_parse_incdec(BcParse *p, BcInst *prev, bool *paren_expr, | |||
4018 | case BC_LEX_KEY_IBASE: | 4017 | case BC_LEX_KEY_IBASE: |
4019 | case BC_LEX_KEY_LAST: | 4018 | case BC_LEX_KEY_LAST: |
4020 | case BC_LEX_KEY_OBASE: | 4019 | case BC_LEX_KEY_OBASE: |
4021 | bc_parse_push(p, type - BC_LEX_KEY_IBASE + BC_INST_IBASE); | 4020 | bc_parse_push(p, type - BC_LEX_KEY_IBASE + XC_INST_IBASE); |
4022 | s = zbc_lex_next(&p->l); | 4021 | s = zbc_lex_next(&p->l); |
4023 | break; | 4022 | break; |
4024 | case BC_LEX_KEY_SCALE: | 4023 | case BC_LEX_KEY_SCALE: |
@@ -4027,7 +4026,7 @@ static BC_STATUS zbc_parse_incdec(BcParse *p, BcInst *prev, bool *paren_expr, | |||
4027 | if (p->l.t.t == BC_LEX_LPAREN) | 4026 | if (p->l.t.t == BC_LEX_LPAREN) |
4028 | s = bc_error_bad_token(); | 4027 | s = bc_error_bad_token(); |
4029 | else | 4028 | else |
4030 | bc_parse_push(p, BC_INST_SCALE); | 4029 | bc_parse_push(p, XC_INST_SCALE); |
4031 | break; | 4030 | break; |
4032 | default: | 4031 | default: |
4033 | s = bc_error_bad_token(); | 4032 | s = bc_error_bad_token(); |
@@ -4052,7 +4051,7 @@ static BC_STATUS zbc_parse_minus(BcParse *p, BcInst *prev, size_t ops_bgn, | |||
4052 | if (s) RETURN_STATUS(s); | 4051 | if (s) RETURN_STATUS(s); |
4053 | 4052 | ||
4054 | type = rparen || etype == BC_INST_INC_POST || etype == BC_INST_DEC_POST || | 4053 | type = rparen || etype == BC_INST_INC_POST || etype == BC_INST_DEC_POST || |
4055 | (etype >= BC_INST_NUM && etype <= BC_INST_SQRT) ? | 4054 | (etype >= XC_INST_NUM && etype <= XC_INST_SQRT) ? |
4056 | BC_LEX_OP_MINUS : | 4055 | BC_LEX_OP_MINUS : |
4057 | BC_LEX_NEG; | 4056 | BC_LEX_NEG; |
4058 | *prev = BC_TOKEN_2_INST(type); | 4057 | *prev = BC_TOKEN_2_INST(type); |
@@ -4083,7 +4082,7 @@ static BC_STATUS zbc_parse_print(BcParse *p) | |||
4083 | s = zbc_parse_expr(p, 0); | 4082 | s = zbc_parse_expr(p, 0); |
4084 | } | 4083 | } |
4085 | if (s) RETURN_STATUS(s); | 4084 | if (s) RETURN_STATUS(s); |
4086 | bc_parse_push(p, BC_INST_PRINT_POP); | 4085 | bc_parse_push(p, XC_INST_PRINT_POP); |
4087 | if (p->l.t.t != BC_LEX_COMMA) | 4086 | if (p->l.t.t != BC_LEX_COMMA) |
4088 | break; | 4087 | break; |
4089 | } | 4088 | } |
@@ -4118,7 +4117,7 @@ static BC_STATUS zbc_parse_return(BcParse *p) | |||
4118 | IF_ERROR_RETURN_POSSIBLE(if (s) RETURN_STATUS(s)); | 4117 | IF_ERROR_RETURN_POSSIBLE(if (s) RETURN_STATUS(s)); |
4119 | } | 4118 | } |
4120 | 4119 | ||
4121 | bc_parse_push(p, BC_INST_RET); | 4120 | bc_parse_push(p, XC_INST_RET); |
4122 | } | 4121 | } |
4123 | 4122 | ||
4124 | dbg_lex_done("%s:%d done", __func__, __LINE__); | 4123 | dbg_lex_done("%s:%d done", __func__, __LINE__); |
@@ -4238,7 +4237,7 @@ static BC_STATUS zbc_parse_for(BcParse *p) | |||
4238 | 4237 | ||
4239 | if (p->l.t.t != BC_LEX_SCOLON) { | 4238 | if (p->l.t.t != BC_LEX_SCOLON) { |
4240 | s = zbc_parse_expr(p, 0); | 4239 | s = zbc_parse_expr(p, 0); |
4241 | bc_parse_push(p, BC_INST_POP); | 4240 | bc_parse_push(p, XC_INST_POP); |
4242 | if (s) RETURN_STATUS(s); | 4241 | if (s) RETURN_STATUS(s); |
4243 | } else { | 4242 | } else { |
4244 | s = bc_POSIX_does_not_allow_empty_X_expression_in_for("init"); | 4243 | s = bc_POSIX_does_not_allow_empty_X_expression_in_for("init"); |
@@ -4281,7 +4280,7 @@ static BC_STATUS zbc_parse_for(BcParse *p) | |||
4281 | s = zbc_parse_expr(p, 0); | 4280 | s = zbc_parse_expr(p, 0); |
4282 | if (s) RETURN_STATUS(s); | 4281 | if (s) RETURN_STATUS(s); |
4283 | if (p->l.t.t != BC_LEX_RPAREN) RETURN_STATUS(bc_error_bad_token()); | 4282 | if (p->l.t.t != BC_LEX_RPAREN) RETURN_STATUS(bc_error_bad_token()); |
4284 | bc_parse_push(p, BC_INST_POP); | 4283 | bc_parse_push(p, XC_INST_POP); |
4285 | } else { | 4284 | } else { |
4286 | s = bc_POSIX_does_not_allow_empty_X_expression_in_for("update"); | 4285 | s = bc_POSIX_does_not_allow_empty_X_expression_in_for("update"); |
4287 | IF_ERROR_RETURN_POSSIBLE(if (s) RETURN_STATUS(s);) | 4286 | IF_ERROR_RETURN_POSSIBLE(if (s) RETURN_STATUS(s);) |
@@ -4541,7 +4540,7 @@ static BC_STATUS zbc_parse_stmt_possibly_auto(BcParse *p, bool auto_allowed) | |||
4541 | break; | 4540 | break; |
4542 | case BC_LEX_STR: | 4541 | case BC_LEX_STR: |
4543 | s = zbc_parse_pushSTR(p); | 4542 | s = zbc_parse_pushSTR(p); |
4544 | bc_parse_push(p, BC_INST_PRINT_STR); | 4543 | bc_parse_push(p, XC_INST_PRINT_STR); |
4545 | break; | 4544 | break; |
4546 | case BC_LEX_KEY_BREAK: | 4545 | case BC_LEX_KEY_BREAK: |
4547 | case BC_LEX_KEY_CONTINUE: | 4546 | case BC_LEX_KEY_CONTINUE: |
@@ -4622,7 +4621,7 @@ static BC_STATUS zbc_parse_stmt_or_funcdef(BcParse *p) | |||
4622 | static BcStatus bc_parse_expr_empty_ok(BcParse *p, uint8_t flags) | 4621 | static BcStatus bc_parse_expr_empty_ok(BcParse *p, uint8_t flags) |
4623 | { | 4622 | { |
4624 | BcStatus s = BC_STATUS_SUCCESS; | 4623 | BcStatus s = BC_STATUS_SUCCESS; |
4625 | BcInst prev = BC_INST_PRINT; | 4624 | BcInst prev = XC_INST_PRINT; |
4626 | BcLexType top, t = p->l.t.t; | 4625 | BcLexType top, t = p->l.t.t; |
4627 | size_t nexprs = 0, ops_bgn = p->ops.len; | 4626 | size_t nexprs = 0, ops_bgn = p->ops.len; |
4628 | unsigned nparens, nrelops; | 4627 | unsigned nparens, nrelops; |
@@ -4645,7 +4644,7 @@ static BcStatus bc_parse_expr_empty_ok(BcParse *p, uint8_t flags) | |||
4645 | case BC_LEX_OP_MINUS: | 4644 | case BC_LEX_OP_MINUS: |
4646 | s = zbc_parse_minus(p, &prev, ops_bgn, rprn, &nexprs); | 4645 | s = zbc_parse_minus(p, &prev, ops_bgn, rprn, &nexprs); |
4647 | rprn = get_token = false; | 4646 | rprn = get_token = false; |
4648 | bin_last = prev == BC_INST_MINUS; | 4647 | bin_last = prev == XC_INST_MINUS; |
4649 | break; | 4648 | break; |
4650 | case BC_LEX_OP_ASSIGN_POWER: | 4649 | case BC_LEX_OP_ASSIGN_POWER: |
4651 | case BC_LEX_OP_ASSIGN_MULTIPLY: | 4650 | case BC_LEX_OP_ASSIGN_MULTIPLY: |
@@ -4654,9 +4653,9 @@ static BcStatus bc_parse_expr_empty_ok(BcParse *p, uint8_t flags) | |||
4654 | case BC_LEX_OP_ASSIGN_PLUS: | 4653 | case BC_LEX_OP_ASSIGN_PLUS: |
4655 | case BC_LEX_OP_ASSIGN_MINUS: | 4654 | case BC_LEX_OP_ASSIGN_MINUS: |
4656 | case BC_LEX_OP_ASSIGN: | 4655 | case BC_LEX_OP_ASSIGN: |
4657 | if (prev != BC_INST_VAR && prev != BC_INST_ARRAY_ELEM | 4656 | if (prev != XC_INST_VAR && prev != XC_INST_ARRAY_ELEM |
4658 | && prev != BC_INST_SCALE && prev != BC_INST_IBASE | 4657 | && prev != XC_INST_SCALE && prev != XC_INST_IBASE |
4659 | && prev != BC_INST_OBASE && prev != BC_INST_LAST | 4658 | && prev != XC_INST_OBASE && prev != BC_INST_LAST |
4660 | ) { | 4659 | ) { |
4661 | s = bc_error("bad assignment:" | 4660 | s = bc_error("bad assignment:" |
4662 | " left side must be variable" | 4661 | " left side must be variable" |
@@ -4680,7 +4679,7 @@ static BcStatus bc_parse_expr_empty_ok(BcParse *p, uint8_t flags) | |||
4680 | case BC_LEX_OP_BOOL_OR: | 4679 | case BC_LEX_OP_BOOL_OR: |
4681 | case BC_LEX_OP_BOOL_AND: | 4680 | case BC_LEX_OP_BOOL_AND: |
4682 | if (((t == BC_LEX_OP_BOOL_NOT) != bin_last) | 4681 | if (((t == BC_LEX_OP_BOOL_NOT) != bin_last) |
4683 | || (t != BC_LEX_OP_BOOL_NOT && prev == BC_INST_BOOL_NOT) | 4682 | || (t != BC_LEX_OP_BOOL_NOT && prev == XC_INST_BOOL_NOT) |
4684 | ) { | 4683 | ) { |
4685 | return bc_error_bad_expression(); | 4684 | return bc_error_bad_expression(); |
4686 | } | 4685 | } |
@@ -4700,7 +4699,7 @@ static BcStatus bc_parse_expr_empty_ok(BcParse *p, uint8_t flags) | |||
4700 | bc_vec_push(&p->ops, &t); | 4699 | bc_vec_push(&p->ops, &t); |
4701 | break; | 4700 | break; |
4702 | case BC_LEX_RPAREN: | 4701 | case BC_LEX_RPAREN: |
4703 | if (bin_last || prev == BC_INST_BOOL_NOT) | 4702 | if (bin_last || prev == XC_INST_BOOL_NOT) |
4704 | return bc_error_bad_expression(); | 4703 | return bc_error_bad_expression(); |
4705 | if (nparens == 0) { | 4704 | if (nparens == 0) { |
4706 | s = BC_STATUS_SUCCESS; | 4705 | s = BC_STATUS_SUCCESS; |
@@ -4730,7 +4729,7 @@ static BcStatus bc_parse_expr_empty_ok(BcParse *p, uint8_t flags) | |||
4730 | return bc_error_bad_expression(); | 4729 | return bc_error_bad_expression(); |
4731 | bc_parse_pushNUM(p); | 4730 | bc_parse_pushNUM(p); |
4732 | nexprs++; | 4731 | nexprs++; |
4733 | prev = BC_INST_NUM; | 4732 | prev = XC_INST_NUM; |
4734 | paren_expr = get_token = true; | 4733 | paren_expr = get_token = true; |
4735 | rprn = bin_last = false; | 4734 | rprn = bin_last = false; |
4736 | break; | 4735 | break; |
@@ -4739,7 +4738,7 @@ static BcStatus bc_parse_expr_empty_ok(BcParse *p, uint8_t flags) | |||
4739 | case BC_LEX_KEY_OBASE: | 4738 | case BC_LEX_KEY_OBASE: |
4740 | if (BC_PARSE_LEAF(prev, rprn)) | 4739 | if (BC_PARSE_LEAF(prev, rprn)) |
4741 | return bc_error_bad_expression(); | 4740 | return bc_error_bad_expression(); |
4742 | prev = (char) (t - BC_LEX_KEY_IBASE + BC_INST_IBASE); | 4741 | prev = (char) (t - BC_LEX_KEY_IBASE + XC_INST_IBASE); |
4743 | bc_parse_push(p, (char) prev); | 4742 | bc_parse_push(p, (char) prev); |
4744 | paren_expr = get_token = true; | 4743 | paren_expr = get_token = true; |
4745 | rprn = bin_last = false; | 4744 | rprn = bin_last = false; |
@@ -4762,7 +4761,7 @@ static BcStatus bc_parse_expr_empty_ok(BcParse *p, uint8_t flags) | |||
4762 | paren_expr = true; | 4761 | paren_expr = true; |
4763 | rprn = get_token = bin_last = false; | 4762 | rprn = get_token = bin_last = false; |
4764 | ++nexprs; | 4763 | ++nexprs; |
4765 | prev = BC_INST_READ; | 4764 | prev = XC_INST_READ; |
4766 | break; | 4765 | break; |
4767 | case BC_LEX_KEY_SCALE: | 4766 | case BC_LEX_KEY_SCALE: |
4768 | if (BC_PARSE_LEAF(prev, rprn)) | 4767 | if (BC_PARSE_LEAF(prev, rprn)) |
@@ -4771,7 +4770,7 @@ static BcStatus bc_parse_expr_empty_ok(BcParse *p, uint8_t flags) | |||
4771 | paren_expr = true; | 4770 | paren_expr = true; |
4772 | rprn = get_token = bin_last = false; | 4771 | rprn = get_token = bin_last = false; |
4773 | ++nexprs; | 4772 | ++nexprs; |
4774 | prev = BC_INST_SCALE; | 4773 | prev = XC_INST_SCALE; |
4775 | break; | 4774 | break; |
4776 | default: | 4775 | default: |
4777 | s = bc_error_bad_token(); | 4776 | s = bc_error_bad_token(); |
@@ -4797,7 +4796,7 @@ static BcStatus bc_parse_expr_empty_ok(BcParse *p, uint8_t flags) | |||
4797 | bc_vec_pop(&p->ops); | 4796 | bc_vec_pop(&p->ops); |
4798 | } | 4797 | } |
4799 | 4798 | ||
4800 | if (prev == BC_INST_BOOL_NOT || nexprs != 1) | 4799 | if (prev == XC_INST_BOOL_NOT || nexprs != 1) |
4801 | return bc_error_bad_expression(); | 4800 | return bc_error_bad_expression(); |
4802 | 4801 | ||
4803 | if (!(flags & BC_PARSE_REL) && nrelops) { | 4802 | if (!(flags & BC_PARSE_REL) && nrelops) { |
@@ -4809,8 +4808,8 @@ static BcStatus bc_parse_expr_empty_ok(BcParse *p, uint8_t flags) | |||
4809 | } | 4808 | } |
4810 | 4809 | ||
4811 | if (flags & BC_PARSE_PRINT) { | 4810 | if (flags & BC_PARSE_PRINT) { |
4812 | if (paren_first || !assign) bc_parse_push(p, BC_INST_PRINT); | 4811 | if (paren_first || !assign) bc_parse_push(p, XC_INST_PRINT); |
4813 | bc_parse_push(p, BC_INST_POP); | 4812 | bc_parse_push(p, XC_INST_POP); |
4814 | } | 4813 | } |
4815 | 4814 | ||
4816 | dbg_lex_done("%s:%d done", __func__, __LINE__); | 4815 | dbg_lex_done("%s:%d done", __func__, __LINE__); |
@@ -4843,7 +4842,7 @@ static void dc_parse_string(BcParse *p) | |||
4843 | dbg_lex_enter("%s:%d entered", __func__, __LINE__); | 4842 | dbg_lex_enter("%s:%d entered", __func__, __LINE__); |
4844 | 4843 | ||
4845 | str = xstrdup(p->l.t.v.v); | 4844 | str = xstrdup(p->l.t.v.v); |
4846 | bc_parse_push(p, BC_INST_STR); | 4845 | bc_parse_push(p, XC_INST_STR); |
4847 | bc_parse_pushIndex(p, len); | 4846 | bc_parse_pushIndex(p, len); |
4848 | bc_vec_push(&G.prog.strs, &str); | 4847 | bc_vec_push(&G.prog.strs, &str); |
4849 | 4848 | ||
@@ -4865,9 +4864,9 @@ static BC_STATUS zdc_parse_mem(BcParse *p, uint8_t inst, bool name, bool store) | |||
4865 | } | 4864 | } |
4866 | 4865 | ||
4867 | if (store) { | 4866 | if (store) { |
4868 | bc_parse_push(p, BC_INST_SWAP); | 4867 | bc_parse_push(p, DC_INST_SWAP); |
4869 | bc_parse_push(p, BC_INST_ASSIGN); | 4868 | bc_parse_push(p, XC_INST_ASSIGN); |
4870 | bc_parse_push(p, BC_INST_POP); | 4869 | bc_parse_push(p, XC_INST_POP); |
4871 | } | 4870 | } |
4872 | 4871 | ||
4873 | RETURN_STATUS(BC_STATUS_SUCCESS); | 4872 | RETURN_STATUS(BC_STATUS_SUCCESS); |
@@ -4879,7 +4878,7 @@ static BC_STATUS zdc_parse_cond(BcParse *p, uint8_t inst) | |||
4879 | BcStatus s; | 4878 | BcStatus s; |
4880 | 4879 | ||
4881 | bc_parse_push(p, inst); | 4880 | bc_parse_push(p, inst); |
4882 | bc_parse_push(p, BC_INST_EXEC_COND); | 4881 | bc_parse_push(p, DC_INST_EXEC_COND); |
4883 | 4882 | ||
4884 | s = zdc_parse_register(p); | 4883 | s = zdc_parse_register(p); |
4885 | if (s) RETURN_STATUS(s); | 4884 | if (s) RETURN_STATUS(s); |
@@ -4919,13 +4918,13 @@ static BC_STATUS zdc_parse_token(BcParse *p, BcLexType t) | |||
4919 | case BC_LEX_OP_REL_LT: | 4918 | case BC_LEX_OP_REL_LT: |
4920 | case BC_LEX_OP_REL_GT: | 4919 | case BC_LEX_OP_REL_GT: |
4921 | dbg_lex("%s:%d LEX_OP_REL_xyz", __func__, __LINE__); | 4920 | dbg_lex("%s:%d LEX_OP_REL_xyz", __func__, __LINE__); |
4922 | s = zdc_parse_cond(p, t - BC_LEX_OP_REL_EQ + BC_INST_REL_EQ); | 4921 | s = zdc_parse_cond(p, t - BC_LEX_OP_REL_EQ + XC_INST_REL_EQ); |
4923 | get_token = false; | 4922 | get_token = false; |
4924 | break; | 4923 | break; |
4925 | case BC_LEX_SCOLON: | 4924 | case BC_LEX_SCOLON: |
4926 | case BC_LEX_COLON: | 4925 | case BC_LEX_COLON: |
4927 | dbg_lex("%s:%d LEX_[S]COLON", __func__, __LINE__); | 4926 | dbg_lex("%s:%d LEX_[S]COLON", __func__, __LINE__); |
4928 | s = zdc_parse_mem(p, BC_INST_ARRAY_ELEM, true, t == BC_LEX_COLON); | 4927 | s = zdc_parse_mem(p, XC_INST_ARRAY_ELEM, true, t == BC_LEX_COLON); |
4929 | break; | 4928 | break; |
4930 | case BC_LEX_STR: | 4929 | case BC_LEX_STR: |
4931 | dbg_lex("%s:%d LEX_STR", __func__, __LINE__); | 4930 | dbg_lex("%s:%d LEX_STR", __func__, __LINE__); |
@@ -4938,7 +4937,7 @@ static BC_STATUS zdc_parse_token(BcParse *p, BcLexType t) | |||
4938 | if (p->l.t.t != BC_LEX_NUMBER) | 4937 | if (p->l.t.t != BC_LEX_NUMBER) |
4939 | RETURN_STATUS(bc_error_bad_token()); | 4938 | RETURN_STATUS(bc_error_bad_token()); |
4940 | bc_parse_pushNUM(p); | 4939 | bc_parse_pushNUM(p); |
4941 | bc_parse_push(p, BC_INST_NEG); | 4940 | bc_parse_push(p, XC_INST_NEG); |
4942 | break; | 4941 | break; |
4943 | case BC_LEX_NUMBER: | 4942 | case BC_LEX_NUMBER: |
4944 | dbg_lex("%s:%d LEX_NUMBER", __func__, __LINE__); | 4943 | dbg_lex("%s:%d LEX_NUMBER", __func__, __LINE__); |
@@ -4946,26 +4945,26 @@ static BC_STATUS zdc_parse_token(BcParse *p, BcLexType t) | |||
4946 | break; | 4945 | break; |
4947 | case BC_LEX_KEY_READ: | 4946 | case BC_LEX_KEY_READ: |
4948 | dbg_lex("%s:%d LEX_KEY_READ", __func__, __LINE__); | 4947 | dbg_lex("%s:%d LEX_KEY_READ", __func__, __LINE__); |
4949 | bc_parse_push(p, BC_INST_READ); | 4948 | bc_parse_push(p, XC_INST_READ); |
4950 | break; | 4949 | break; |
4951 | case BC_LEX_OP_ASSIGN: | 4950 | case BC_LEX_OP_ASSIGN: |
4952 | case BC_LEX_STORE_PUSH: | 4951 | case BC_LEX_STORE_PUSH: |
4953 | dbg_lex("%s:%d LEX_OP_ASSIGN/STORE_PUSH", __func__, __LINE__); | 4952 | dbg_lex("%s:%d LEX_OP_ASSIGN/STORE_PUSH", __func__, __LINE__); |
4954 | assign = t == BC_LEX_OP_ASSIGN; | 4953 | assign = t == BC_LEX_OP_ASSIGN; |
4955 | inst = assign ? BC_INST_VAR : BC_INST_PUSH_TO_VAR; | 4954 | inst = assign ? XC_INST_VAR : DC_INST_PUSH_TO_VAR; |
4956 | s = zdc_parse_mem(p, inst, true, assign); | 4955 | s = zdc_parse_mem(p, inst, true, assign); |
4957 | break; | 4956 | break; |
4958 | case BC_LEX_LOAD: | 4957 | case BC_LEX_LOAD: |
4959 | case BC_LEX_LOAD_POP: | 4958 | case BC_LEX_LOAD_POP: |
4960 | dbg_lex("%s:%d LEX_OP_LOAD[_POP]", __func__, __LINE__); | 4959 | dbg_lex("%s:%d LEX_OP_LOAD[_POP]", __func__, __LINE__); |
4961 | inst = t == BC_LEX_LOAD_POP ? BC_INST_PUSH_VAR : BC_INST_LOAD; | 4960 | inst = t == BC_LEX_LOAD_POP ? DC_INST_PUSH_VAR : DC_INST_LOAD; |
4962 | s = zdc_parse_mem(p, inst, true, false); | 4961 | s = zdc_parse_mem(p, inst, true, false); |
4963 | break; | 4962 | break; |
4964 | case BC_LEX_STORE_IBASE: | 4963 | case BC_LEX_STORE_IBASE: |
4965 | case BC_LEX_STORE_SCALE: | 4964 | case BC_LEX_STORE_SCALE: |
4966 | case BC_LEX_STORE_OBASE: | 4965 | case BC_LEX_STORE_OBASE: |
4967 | dbg_lex("%s:%d LEX_OP_STORE_I/OBASE/SCALE", __func__, __LINE__); | 4966 | dbg_lex("%s:%d LEX_OP_STORE_I/OBASE/SCALE", __func__, __LINE__); |
4968 | inst = t - BC_LEX_STORE_IBASE + BC_INST_IBASE; | 4967 | inst = t - BC_LEX_STORE_IBASE + XC_INST_IBASE; |
4969 | s = zdc_parse_mem(p, inst, false, true); | 4968 | s = zdc_parse_mem(p, inst, false, true); |
4970 | break; | 4969 | break; |
4971 | default: | 4970 | default: |
@@ -4986,7 +4985,7 @@ static BC_STATUS zdc_parse_expr(BcParse *p) | |||
4986 | BcStatus s; | 4985 | BcStatus s; |
4987 | 4986 | ||
4988 | inst = dc_LEX_to_INST[p->l.t.t]; | 4987 | inst = dc_LEX_to_INST[p->l.t.t]; |
4989 | if (inst != BC_INST_INVALID) { | 4988 | if (inst != DC_INST_INVALID) { |
4990 | bc_parse_push(p, inst); | 4989 | bc_parse_push(p, inst); |
4991 | s = zbc_lex_next(&p->l); | 4990 | s = zbc_lex_next(&p->l); |
4992 | } else { | 4991 | } else { |
@@ -5183,7 +5182,7 @@ static BC_STATUS zbc_program_op(char inst) | |||
5183 | bc_num_init_DEF_SIZE(&res.d.n); | 5182 | bc_num_init_DEF_SIZE(&res.d.n); |
5184 | 5183 | ||
5185 | s = BC_STATUS_SUCCESS; | 5184 | s = BC_STATUS_SUCCESS; |
5186 | IF_ERROR_RETURN_POSSIBLE(s =) zbc_program_ops[inst - BC_INST_POWER](n1, n2, &res.d.n, G.prog.scale); | 5185 | IF_ERROR_RETURN_POSSIBLE(s =) zbc_program_ops[inst - XC_INST_POWER](n1, n2, &res.d.n, G.prog.scale); |
5187 | if (s) goto err; | 5186 | if (s) goto err; |
5188 | bc_program_binOpRetire(&res); | 5187 | bc_program_binOpRetire(&res); |
5189 | 5188 | ||
@@ -5233,7 +5232,7 @@ static BC_STATUS zbc_program_read(void) | |||
5233 | ip.inst_idx = 0; | 5232 | ip.inst_idx = 0; |
5234 | IF_BC(ip.results_len_before_call = G.prog.results.len;) | 5233 | IF_BC(ip.results_len_before_call = G.prog.results.len;) |
5235 | 5234 | ||
5236 | bc_parse_push(&parse, BC_INST_RET); | 5235 | bc_parse_push(&parse, XC_INST_RET); |
5237 | bc_vec_push(&G.prog.exestack, &ip); | 5236 | bc_vec_push(&G.prog.exestack, &ip); |
5238 | exec_err: | 5237 | exec_err: |
5239 | bc_parse_free(&parse); | 5238 | bc_parse_free(&parse); |
@@ -5533,7 +5532,7 @@ static BC_STATUS zbc_program_print(char inst, size_t idx) | |||
5533 | BcStatus s; | 5532 | BcStatus s; |
5534 | BcResult *r; | 5533 | BcResult *r; |
5535 | BcNum *num; | 5534 | BcNum *num; |
5536 | bool pop = inst != BC_INST_PRINT; | 5535 | bool pop = inst != XC_INST_PRINT; |
5537 | 5536 | ||
5538 | if (!STACK_HAS_MORE_THAN(&G.prog.results, idx)) | 5537 | if (!STACK_HAS_MORE_THAN(&G.prog.results, idx)) |
5539 | RETURN_STATUS(bc_error_stack_has_too_few_elements()); | 5538 | RETURN_STATUS(bc_error_stack_has_too_few_elements()); |
@@ -5553,7 +5552,7 @@ static BC_STATUS zbc_program_print(char inst, size_t idx) | |||
5553 | idx = (r->t == BC_RESULT_STR) ? r->d.id.idx : num->rdx; | 5552 | idx = (r->t == BC_RESULT_STR) ? r->d.id.idx : num->rdx; |
5554 | str = *bc_program_str(idx); | 5553 | str = *bc_program_str(idx); |
5555 | 5554 | ||
5556 | if (inst == BC_INST_PRINT_STR) { | 5555 | if (inst == XC_INST_PRINT_STR) { |
5557 | for (;;) { | 5556 | for (;;) { |
5558 | char c = *str++; | 5557 | char c = *str++; |
5559 | if (c == '\0') break; | 5558 | if (c == '\0') break; |
@@ -5563,7 +5562,7 @@ static BC_STATUS zbc_program_print(char inst, size_t idx) | |||
5563 | } | 5562 | } |
5564 | } else { | 5563 | } else { |
5565 | bc_program_printString(str); | 5564 | bc_program_printString(str); |
5566 | if (inst == BC_INST_PRINT) bb_putchar('\n'); | 5565 | if (inst == XC_INST_PRINT) bb_putchar('\n'); |
5567 | } | 5566 | } |
5568 | } | 5567 | } |
5569 | 5568 | ||
@@ -5604,29 +5603,29 @@ static BC_STATUS zbc_program_logical(char inst) | |||
5604 | 5603 | ||
5605 | bc_num_init_DEF_SIZE(&res.d.n); | 5604 | bc_num_init_DEF_SIZE(&res.d.n); |
5606 | 5605 | ||
5607 | if (inst == BC_INST_BOOL_AND) | 5606 | if (inst == XC_INST_BOOL_AND) |
5608 | cond = bc_num_cmp(n1, &G.prog.zero) && bc_num_cmp(n2, &G.prog.zero); | 5607 | cond = bc_num_cmp(n1, &G.prog.zero) && bc_num_cmp(n2, &G.prog.zero); |
5609 | else if (inst == BC_INST_BOOL_OR) | 5608 | else if (inst == XC_INST_BOOL_OR) |
5610 | cond = bc_num_cmp(n1, &G.prog.zero) || bc_num_cmp(n2, &G.prog.zero); | 5609 | cond = bc_num_cmp(n1, &G.prog.zero) || bc_num_cmp(n2, &G.prog.zero); |
5611 | else { | 5610 | else { |
5612 | cond = bc_num_cmp(n1, n2); | 5611 | cond = bc_num_cmp(n1, n2); |
5613 | switch (inst) { | 5612 | switch (inst) { |
5614 | case BC_INST_REL_EQ: | 5613 | case XC_INST_REL_EQ: |
5615 | cond = (cond == 0); | 5614 | cond = (cond == 0); |
5616 | break; | 5615 | break; |
5617 | case BC_INST_REL_LE: | 5616 | case XC_INST_REL_LE: |
5618 | cond = (cond <= 0); | 5617 | cond = (cond <= 0); |
5619 | break; | 5618 | break; |
5620 | case BC_INST_REL_GE: | 5619 | case XC_INST_REL_GE: |
5621 | cond = (cond >= 0); | 5620 | cond = (cond >= 0); |
5622 | break; | 5621 | break; |
5623 | case BC_INST_REL_LT: | 5622 | case XC_INST_REL_LT: |
5624 | cond = (cond < 0); | 5623 | cond = (cond < 0); |
5625 | break; | 5624 | break; |
5626 | case BC_INST_REL_GT: | 5625 | case XC_INST_REL_GT: |
5627 | cond = (cond > 0); | 5626 | cond = (cond > 0); |
5628 | break; | 5627 | break; |
5629 | default: // = case BC_INST_REL_NE: | 5628 | default: // = case XC_INST_REL_NE: |
5630 | //cond = (cond != 0); - not needed | 5629 | //cond = (cond != 0); - not needed |
5631 | break; | 5630 | break; |
5632 | } | 5631 | } |
@@ -5714,7 +5713,7 @@ static BC_STATUS zbc_program_assign(char inst) | |||
5714 | BcStatus s; | 5713 | BcStatus s; |
5715 | BcResult *left, *right, res; | 5714 | BcResult *left, *right, res; |
5716 | BcNum *l = NULL, *r = NULL; | 5715 | BcNum *l = NULL, *r = NULL; |
5717 | bool assign = inst == BC_INST_ASSIGN, ib, sc; | 5716 | bool assign = inst == XC_INST_ASSIGN, ib, sc; |
5718 | 5717 | ||
5719 | s = zbc_program_binOpPrep(&left, &l, &right, &r, assign); | 5718 | s = zbc_program_binOpPrep(&left, &l, &right, &r, assign); |
5720 | if (s) RETURN_STATUS(s); | 5719 | if (s) RETURN_STATUS(s); |
@@ -5844,7 +5843,7 @@ static BC_STATUS zbc_program_pushArray(char *code, size_t *bgn, char inst) | |||
5844 | 5843 | ||
5845 | r.d.id.name = bc_program_name(code, bgn); | 5844 | r.d.id.name = bc_program_name(code, bgn); |
5846 | 5845 | ||
5847 | if (inst == BC_INST_ARRAY) { | 5846 | if (inst == XC_INST_ARRAY) { |
5848 | r.t = BC_RESULT_ARRAY; | 5847 | r.t = BC_RESULT_ARRAY; |
5849 | bc_vec_push(&G.prog.results, &r); | 5848 | bc_vec_push(&G.prog.results, &r); |
5850 | } else { | 5849 | } else { |
@@ -5968,13 +5967,13 @@ static BC_STATUS zbc_program_return(char inst) | |||
5968 | size_t i; | 5967 | size_t i; |
5969 | BcInstPtr *ip = bc_vec_top(&G.prog.exestack); | 5968 | BcInstPtr *ip = bc_vec_top(&G.prog.exestack); |
5970 | 5969 | ||
5971 | if (!STACK_HAS_EQUAL_OR_MORE_THAN(&G.prog.results, ip->results_len_before_call + (inst == BC_INST_RET))) | 5970 | if (!STACK_HAS_EQUAL_OR_MORE_THAN(&G.prog.results, ip->results_len_before_call + (inst == XC_INST_RET))) |
5972 | RETURN_STATUS(bc_error_stack_has_too_few_elements()); | 5971 | RETURN_STATUS(bc_error_stack_has_too_few_elements()); |
5973 | 5972 | ||
5974 | f = bc_program_func(ip->func); | 5973 | f = bc_program_func(ip->func); |
5975 | res.t = BC_RESULT_TEMP; | 5974 | res.t = BC_RESULT_TEMP; |
5976 | 5975 | ||
5977 | if (inst == BC_INST_RET) { | 5976 | if (inst == XC_INST_RET) { |
5978 | BcStatus s; | 5977 | BcStatus s; |
5979 | BcNum *num; | 5978 | BcNum *num; |
5980 | BcResult *operand = bc_vec_top(&G.prog.results); | 5979 | BcResult *operand = bc_vec_top(&G.prog.results); |
@@ -6029,7 +6028,7 @@ static BC_STATUS zbc_program_builtin(char inst) | |||
6029 | BcResult *opnd; | 6028 | BcResult *opnd; |
6030 | BcNum *num = NULL; | 6029 | BcNum *num = NULL; |
6031 | BcResult res; | 6030 | BcResult res; |
6032 | bool len = inst == BC_INST_LENGTH; | 6031 | bool len = inst == XC_INST_LENGTH; |
6033 | 6032 | ||
6034 | if (!STACK_HAS_MORE_THAN(&G.prog.results, 0)) | 6033 | if (!STACK_HAS_MORE_THAN(&G.prog.results, 0)) |
6035 | RETURN_STATUS(bc_error_stack_has_too_few_elements()); | 6034 | RETURN_STATUS(bc_error_stack_has_too_few_elements()); |
@@ -6045,7 +6044,7 @@ static BC_STATUS zbc_program_builtin(char inst) | |||
6045 | 6044 | ||
6046 | bc_num_init_DEF_SIZE(&res.d.n); | 6045 | bc_num_init_DEF_SIZE(&res.d.n); |
6047 | 6046 | ||
6048 | if (inst == BC_INST_SQRT) | 6047 | if (inst == XC_INST_SQRT) |
6049 | s = zbc_num_sqrt(num, &res.d.n, G.prog.scale); | 6048 | s = zbc_num_sqrt(num, &res.d.n, G.prog.scale); |
6050 | #if ENABLE_BC | 6049 | #if ENABLE_BC |
6051 | else if (len != 0 && opnd->t == BC_RESULT_ARRAY) { | 6050 | else if (len != 0 && opnd->t == BC_RESULT_ARRAY) { |
@@ -6361,7 +6360,7 @@ static BC_STATUS zdc_program_execStr(char *code, size_t *bgn, bool cond) | |||
6361 | bc_vec_pop_all(&f->code); | 6360 | bc_vec_pop_all(&f->code); |
6362 | goto exit; | 6361 | goto exit; |
6363 | } | 6362 | } |
6364 | bc_parse_push(&prs, BC_INST_POP_EXEC); | 6363 | bc_parse_push(&prs, DC_INST_POP_EXEC); |
6365 | bc_parse_free(&prs); | 6364 | bc_parse_free(&prs); |
6366 | } | 6365 | } |
6367 | 6366 | ||
@@ -6384,10 +6383,10 @@ static void bc_program_pushGlobal(char inst) | |||
6384 | BcResult res; | 6383 | BcResult res; |
6385 | unsigned long val; | 6384 | unsigned long val; |
6386 | 6385 | ||
6387 | res.t = inst - BC_INST_IBASE + BC_RESULT_IBASE; | 6386 | res.t = inst - XC_INST_IBASE + BC_RESULT_IBASE; |
6388 | if (inst == BC_INST_IBASE) | 6387 | if (inst == XC_INST_IBASE) |
6389 | val = (unsigned long) G.prog.ib_t; | 6388 | val = (unsigned long) G.prog.ib_t; |
6390 | else if (inst == BC_INST_SCALE) | 6389 | else if (inst == XC_INST_SCALE) |
6391 | val = (unsigned long) G.prog.scale; | 6390 | val = (unsigned long) G.prog.scale; |
6392 | else | 6391 | else |
6393 | val = (unsigned long) G.prog.ob_t; | 6392 | val = (unsigned long) G.prog.ob_t; |
@@ -6449,34 +6448,34 @@ static BC_STATUS zbc_program_exec(void) | |||
6449 | dbg_exec("BC_INST_HALT:"); | 6448 | dbg_exec("BC_INST_HALT:"); |
6450 | QUIT_OR_RETURN_TO_MAIN; | 6449 | QUIT_OR_RETURN_TO_MAIN; |
6451 | break; | 6450 | break; |
6452 | case BC_INST_RET: | 6451 | case XC_INST_RET: |
6453 | case BC_INST_RET0: | 6452 | case BC_INST_RET0: |
6454 | dbg_exec("BC_INST_RET[0]:"); | 6453 | dbg_exec("BC_INST_RET[0]:"); |
6455 | s = zbc_program_return(inst); | 6454 | s = zbc_program_return(inst); |
6456 | goto read_updated_ip; | 6455 | goto read_updated_ip; |
6457 | case BC_INST_BOOL_OR: | 6456 | case XC_INST_BOOL_OR: |
6458 | case BC_INST_BOOL_AND: | 6457 | case XC_INST_BOOL_AND: |
6459 | #endif // ENABLE_BC | 6458 | #endif // ENABLE_BC |
6460 | case BC_INST_REL_EQ: | 6459 | case XC_INST_REL_EQ: |
6461 | case BC_INST_REL_LE: | 6460 | case XC_INST_REL_LE: |
6462 | case BC_INST_REL_GE: | 6461 | case XC_INST_REL_GE: |
6463 | case BC_INST_REL_NE: | 6462 | case XC_INST_REL_NE: |
6464 | case BC_INST_REL_LT: | 6463 | case XC_INST_REL_LT: |
6465 | case BC_INST_REL_GT: | 6464 | case XC_INST_REL_GT: |
6466 | dbg_exec("BC_INST_BOOL:"); | 6465 | dbg_exec("BC_INST_BOOL:"); |
6467 | s = zbc_program_logical(inst); | 6466 | s = zbc_program_logical(inst); |
6468 | break; | 6467 | break; |
6469 | case BC_INST_READ: | 6468 | case XC_INST_READ: |
6470 | dbg_exec("BC_INST_READ:"); | 6469 | dbg_exec("XC_INST_READ:"); |
6471 | s = zbc_program_read(); | 6470 | s = zbc_program_read(); |
6472 | goto read_updated_ip; | 6471 | goto read_updated_ip; |
6473 | case BC_INST_VAR: | 6472 | case XC_INST_VAR: |
6474 | dbg_exec("BC_INST_VAR:"); | 6473 | dbg_exec("XC_INST_VAR:"); |
6475 | s = zbc_program_pushVar(code, &ip->inst_idx, false, false); | 6474 | s = zbc_program_pushVar(code, &ip->inst_idx, false, false); |
6476 | break; | 6475 | break; |
6477 | case BC_INST_ARRAY_ELEM: | 6476 | case XC_INST_ARRAY_ELEM: |
6478 | case BC_INST_ARRAY: | 6477 | case XC_INST_ARRAY: |
6479 | dbg_exec("BC_INST_ARRAY[_ELEM]:"); | 6478 | dbg_exec("XC_INST_ARRAY[_ELEM]:"); |
6480 | s = zbc_program_pushArray(code, &ip->inst_idx, inst); | 6479 | s = zbc_program_pushArray(code, &ip->inst_idx, inst); |
6481 | break; | 6480 | break; |
6482 | #if ENABLE_BC | 6481 | #if ENABLE_BC |
@@ -6486,54 +6485,54 @@ static BC_STATUS zbc_program_exec(void) | |||
6486 | bc_vec_push(&G.prog.results, &r); | 6485 | bc_vec_push(&G.prog.results, &r); |
6487 | break; | 6486 | break; |
6488 | #endif | 6487 | #endif |
6489 | case BC_INST_IBASE: | 6488 | case XC_INST_IBASE: |
6490 | case BC_INST_OBASE: | 6489 | case XC_INST_OBASE: |
6491 | case BC_INST_SCALE: | 6490 | case XC_INST_SCALE: |
6492 | dbg_exec("BC_INST_internalvar(%d):", inst - BC_INST_IBASE); | 6491 | dbg_exec("XC_INST_internalvar(%d):", inst - XC_INST_IBASE); |
6493 | bc_program_pushGlobal(inst); | 6492 | bc_program_pushGlobal(inst); |
6494 | break; | 6493 | break; |
6495 | case BC_INST_SCALE_FUNC: | 6494 | case XC_INST_SCALE_FUNC: |
6496 | case BC_INST_LENGTH: | 6495 | case XC_INST_LENGTH: |
6497 | case BC_INST_SQRT: | 6496 | case XC_INST_SQRT: |
6498 | dbg_exec("BC_INST_builtin:"); | 6497 | dbg_exec("BC_INST_builtin:"); |
6499 | s = zbc_program_builtin(inst); | 6498 | s = zbc_program_builtin(inst); |
6500 | break; | 6499 | break; |
6501 | case BC_INST_NUM: | 6500 | case XC_INST_NUM: |
6502 | dbg_exec("BC_INST_NUM:"); | 6501 | dbg_exec("XC_INST_NUM:"); |
6503 | r.t = BC_RESULT_CONSTANT; | 6502 | r.t = BC_RESULT_CONSTANT; |
6504 | r.d.id.idx = bc_program_index(code, &ip->inst_idx); | 6503 | r.d.id.idx = bc_program_index(code, &ip->inst_idx); |
6505 | bc_vec_push(&G.prog.results, &r); | 6504 | bc_vec_push(&G.prog.results, &r); |
6506 | break; | 6505 | break; |
6507 | case BC_INST_POP: | 6506 | case XC_INST_POP: |
6508 | dbg_exec("BC_INST_POP:"); | 6507 | dbg_exec("XC_INST_POP:"); |
6509 | if (!STACK_HAS_MORE_THAN(&G.prog.results, 0)) | 6508 | if (!STACK_HAS_MORE_THAN(&G.prog.results, 0)) |
6510 | s = bc_error_stack_has_too_few_elements(); | 6509 | s = bc_error_stack_has_too_few_elements(); |
6511 | else | 6510 | else |
6512 | bc_vec_pop(&G.prog.results); | 6511 | bc_vec_pop(&G.prog.results); |
6513 | break; | 6512 | break; |
6514 | case BC_INST_PRINT: | 6513 | case XC_INST_PRINT: |
6515 | case BC_INST_PRINT_POP: | 6514 | case XC_INST_PRINT_POP: |
6516 | case BC_INST_PRINT_STR: | 6515 | case XC_INST_PRINT_STR: |
6517 | dbg_exec("BC_INST_PRINTxyz:"); | 6516 | dbg_exec("XC_INST_PRINTxyz:"); |
6518 | s = zbc_program_print(inst, 0); | 6517 | s = zbc_program_print(inst, 0); |
6519 | break; | 6518 | break; |
6520 | case BC_INST_STR: | 6519 | case XC_INST_STR: |
6521 | dbg_exec("BC_INST_STR:"); | 6520 | dbg_exec("XC_INST_STR:"); |
6522 | r.t = BC_RESULT_STR; | 6521 | r.t = BC_RESULT_STR; |
6523 | r.d.id.idx = bc_program_index(code, &ip->inst_idx); | 6522 | r.d.id.idx = bc_program_index(code, &ip->inst_idx); |
6524 | bc_vec_push(&G.prog.results, &r); | 6523 | bc_vec_push(&G.prog.results, &r); |
6525 | break; | 6524 | break; |
6526 | case BC_INST_POWER: | 6525 | case XC_INST_POWER: |
6527 | case BC_INST_MULTIPLY: | 6526 | case XC_INST_MULTIPLY: |
6528 | case BC_INST_DIVIDE: | 6527 | case XC_INST_DIVIDE: |
6529 | case BC_INST_MODULUS: | 6528 | case XC_INST_MODULUS: |
6530 | case BC_INST_PLUS: | 6529 | case XC_INST_PLUS: |
6531 | case BC_INST_MINUS: | 6530 | case XC_INST_MINUS: |
6532 | dbg_exec("BC_INST_binaryop:"); | 6531 | dbg_exec("BC_INST_binaryop:"); |
6533 | s = zbc_program_op(inst); | 6532 | s = zbc_program_op(inst); |
6534 | break; | 6533 | break; |
6535 | case BC_INST_BOOL_NOT: | 6534 | case XC_INST_BOOL_NOT: |
6536 | dbg_exec("BC_INST_BOOL_NOT:"); | 6535 | dbg_exec("XC_INST_BOOL_NOT:"); |
6537 | s = zbc_program_prep(&ptr, &num); | 6536 | s = zbc_program_prep(&ptr, &num); |
6538 | if (s) RETURN_STATUS(s); | 6537 | if (s) RETURN_STATUS(s); |
6539 | bc_num_init_DEF_SIZE(&r.d.n); | 6538 | bc_num_init_DEF_SIZE(&r.d.n); |
@@ -6542,8 +6541,8 @@ static BC_STATUS zbc_program_exec(void) | |||
6542 | //else bc_num_zero(&r.d.n); - already is | 6541 | //else bc_num_zero(&r.d.n); - already is |
6543 | bc_program_retire(&r, BC_RESULT_TEMP); | 6542 | bc_program_retire(&r, BC_RESULT_TEMP); |
6544 | break; | 6543 | break; |
6545 | case BC_INST_NEG: | 6544 | case XC_INST_NEG: |
6546 | dbg_exec("BC_INST_NEG:"); | 6545 | dbg_exec("XC_INST_NEG:"); |
6547 | s = zbc_program_negate(); | 6546 | s = zbc_program_negate(); |
6548 | break; | 6547 | break; |
6549 | #if ENABLE_BC | 6548 | #if ENABLE_BC |
@@ -6554,56 +6553,56 @@ static BC_STATUS zbc_program_exec(void) | |||
6554 | case BC_INST_ASSIGN_PLUS: | 6553 | case BC_INST_ASSIGN_PLUS: |
6555 | case BC_INST_ASSIGN_MINUS: | 6554 | case BC_INST_ASSIGN_MINUS: |
6556 | #endif | 6555 | #endif |
6557 | case BC_INST_ASSIGN: | 6556 | case XC_INST_ASSIGN: |
6558 | dbg_exec("BC_INST_ASSIGNxyz:"); | 6557 | dbg_exec("BC_INST_ASSIGNxyz:"); |
6559 | s = zbc_program_assign(inst); | 6558 | s = zbc_program_assign(inst); |
6560 | break; | 6559 | break; |
6561 | #if ENABLE_DC | 6560 | #if ENABLE_DC |
6562 | case BC_INST_POP_EXEC: | 6561 | case DC_INST_POP_EXEC: |
6563 | dbg_exec("BC_INST_POP_EXEC:"); | 6562 | dbg_exec("DC_INST_POP_EXEC:"); |
6564 | bc_vec_pop(&G.prog.exestack); | 6563 | bc_vec_pop(&G.prog.exestack); |
6565 | goto read_updated_ip; | 6564 | goto read_updated_ip; |
6566 | case BC_INST_MODEXP: | 6565 | case DC_INST_MODEXP: |
6567 | dbg_exec("BC_INST_MODEXP:"); | 6566 | dbg_exec("DC_INST_MODEXP:"); |
6568 | s = zdc_program_modexp(); | 6567 | s = zdc_program_modexp(); |
6569 | break; | 6568 | break; |
6570 | case BC_INST_DIVMOD: | 6569 | case DC_INST_DIVMOD: |
6571 | dbg_exec("BC_INST_DIVMOD:"); | 6570 | dbg_exec("DC_INST_DIVMOD:"); |
6572 | s = zdc_program_divmod(); | 6571 | s = zdc_program_divmod(); |
6573 | break; | 6572 | break; |
6574 | case BC_INST_EXECUTE: | 6573 | case DC_INST_EXECUTE: |
6575 | case BC_INST_EXEC_COND: | 6574 | case DC_INST_EXEC_COND: |
6576 | dbg_exec("BC_INST_EXEC[_COND]:"); | 6575 | dbg_exec("DC_INST_EXEC[_COND]:"); |
6577 | s = zdc_program_execStr(code, &ip->inst_idx, inst == BC_INST_EXEC_COND); | 6576 | s = zdc_program_execStr(code, &ip->inst_idx, inst == DC_INST_EXEC_COND); |
6578 | goto read_updated_ip; | 6577 | goto read_updated_ip; |
6579 | case BC_INST_PRINT_STACK: { | 6578 | case DC_INST_PRINT_STACK: { |
6580 | size_t idx; | 6579 | size_t idx; |
6581 | dbg_exec("BC_INST_PRINT_STACK:"); | 6580 | dbg_exec("DC_INST_PRINT_STACK:"); |
6582 | for (idx = 0; idx < G.prog.results.len; ++idx) { | 6581 | for (idx = 0; idx < G.prog.results.len; ++idx) { |
6583 | s = zbc_program_print(BC_INST_PRINT, idx); | 6582 | s = zbc_program_print(XC_INST_PRINT, idx); |
6584 | if (s) break; | 6583 | if (s) break; |
6585 | } | 6584 | } |
6586 | break; | 6585 | break; |
6587 | } | 6586 | } |
6588 | case BC_INST_CLEAR_STACK: | 6587 | case DC_INST_CLEAR_STACK: |
6589 | dbg_exec("BC_INST_CLEAR_STACK:"); | 6588 | dbg_exec("DC_INST_CLEAR_STACK:"); |
6590 | bc_vec_pop_all(&G.prog.results); | 6589 | bc_vec_pop_all(&G.prog.results); |
6591 | break; | 6590 | break; |
6592 | case BC_INST_STACK_LEN: | 6591 | case DC_INST_STACK_LEN: |
6593 | dbg_exec("BC_INST_STACK_LEN:"); | 6592 | dbg_exec("DC_INST_STACK_LEN:"); |
6594 | dc_program_stackLen(); | 6593 | dc_program_stackLen(); |
6595 | break; | 6594 | break; |
6596 | case BC_INST_DUPLICATE: | 6595 | case DC_INST_DUPLICATE: |
6597 | dbg_exec("BC_INST_DUPLICATE:"); | 6596 | dbg_exec("DC_INST_DUPLICATE:"); |
6598 | if (!STACK_HAS_MORE_THAN(&G.prog.results, 0)) | 6597 | if (!STACK_HAS_MORE_THAN(&G.prog.results, 0)) |
6599 | RETURN_STATUS(bc_error_stack_has_too_few_elements()); | 6598 | RETURN_STATUS(bc_error_stack_has_too_few_elements()); |
6600 | ptr = bc_vec_top(&G.prog.results); | 6599 | ptr = bc_vec_top(&G.prog.results); |
6601 | dc_result_copy(&r, ptr); | 6600 | dc_result_copy(&r, ptr); |
6602 | bc_vec_push(&G.prog.results, &r); | 6601 | bc_vec_push(&G.prog.results, &r); |
6603 | break; | 6602 | break; |
6604 | case BC_INST_SWAP: { | 6603 | case DC_INST_SWAP: { |
6605 | BcResult *ptr2; | 6604 | BcResult *ptr2; |
6606 | dbg_exec("BC_INST_SWAP:"); | 6605 | dbg_exec("DC_INST_SWAP:"); |
6607 | if (!STACK_HAS_MORE_THAN(&G.prog.results, 1)) | 6606 | if (!STACK_HAS_MORE_THAN(&G.prog.results, 1)) |
6608 | RETURN_STATUS(bc_error_stack_has_too_few_elements()); | 6607 | RETURN_STATUS(bc_error_stack_has_too_few_elements()); |
6609 | ptr = bc_vec_item_rev(&G.prog.results, 0); | 6608 | ptr = bc_vec_item_rev(&G.prog.results, 0); |
@@ -6613,34 +6612,34 @@ static BC_STATUS zbc_program_exec(void) | |||
6613 | memcpy(ptr2, &r, sizeof(BcResult)); | 6612 | memcpy(ptr2, &r, sizeof(BcResult)); |
6614 | break; | 6613 | break; |
6615 | } | 6614 | } |
6616 | case BC_INST_ASCIIFY: | 6615 | case DC_INST_ASCIIFY: |
6617 | dbg_exec("BC_INST_ASCIIFY:"); | 6616 | dbg_exec("DC_INST_ASCIIFY:"); |
6618 | s = zdc_program_asciify(); | 6617 | s = zdc_program_asciify(); |
6619 | break; | 6618 | break; |
6620 | case BC_INST_PRINT_STREAM: | 6619 | case DC_INST_PRINT_STREAM: |
6621 | dbg_exec("BC_INST_STREAM:"); | 6620 | dbg_exec("DC_INST_PRINT_STREAM:"); |
6622 | s = zdc_program_printStream(); | 6621 | s = zdc_program_printStream(); |
6623 | break; | 6622 | break; |
6624 | case BC_INST_LOAD: | 6623 | case DC_INST_LOAD: |
6625 | case BC_INST_PUSH_VAR: { | 6624 | case DC_INST_PUSH_VAR: { |
6626 | bool copy = inst == BC_INST_LOAD; | 6625 | bool copy = inst == DC_INST_LOAD; |
6627 | s = zbc_program_pushVar(code, &ip->inst_idx, true, copy); | 6626 | s = zbc_program_pushVar(code, &ip->inst_idx, true, copy); |
6628 | break; | 6627 | break; |
6629 | } | 6628 | } |
6630 | case BC_INST_PUSH_TO_VAR: { | 6629 | case DC_INST_PUSH_TO_VAR: { |
6631 | char *name = bc_program_name(code, &ip->inst_idx); | 6630 | char *name = bc_program_name(code, &ip->inst_idx); |
6632 | s = zbc_program_copyToVar(name, true); | 6631 | s = zbc_program_copyToVar(name, true); |
6633 | free(name); | 6632 | free(name); |
6634 | break; | 6633 | break; |
6635 | } | 6634 | } |
6636 | case BC_INST_QUIT: | 6635 | case DC_INST_QUIT: |
6637 | dbg_exec("BC_INST_QUIT:"); | 6636 | dbg_exec("DC_INST_QUIT:"); |
6638 | if (G.prog.exestack.len <= 2) | 6637 | if (G.prog.exestack.len <= 2) |
6639 | QUIT_OR_RETURN_TO_MAIN; | 6638 | QUIT_OR_RETURN_TO_MAIN; |
6640 | bc_vec_npop(&G.prog.exestack, 2); | 6639 | bc_vec_npop(&G.prog.exestack, 2); |
6641 | goto read_updated_ip; | 6640 | goto read_updated_ip; |
6642 | case BC_INST_NQUIT: | 6641 | case DC_INST_NQUIT: |
6643 | dbg_exec("BC_INST_NQUIT:"); | 6642 | dbg_exec("DC_INST_NQUIT:"); |
6644 | s = zdc_program_nquit(); | 6643 | s = zdc_program_nquit(); |
6645 | //goto read_updated_ip; - just fall through to it | 6644 | //goto read_updated_ip; - just fall through to it |
6646 | #endif // ENABLE_DC | 6645 | #endif // ENABLE_DC |