Unified · Split
| @@ -68,7 +68,6 @@ Not critical: · 67 unmodified lines | ||
| 68 | 68 | to suppress VT_LOCAL and use a base register instead). |
| 69 | 69 | - interactive mode / integrated debugger |
| 70 | 70 | - fix preprocessor symbol redefinition |
| 71 | −- better constant opt (&&, ||, ?:) | |
| 72 | 71 | - add portable byte code generator and interpreter for other |
| 73 | 72 | unsupported architectures. |
| 74 | 73 | - C++: variable declaration in for, minimal 'class' support. |
| @@ -4453,80 +4453,83 @@ static void expr_or(void) · 4452 unmodified lines | ||
| 4453 | 4453 | } |
| 4454 | 4454 | } |
| 4455 | 4455 | |
| 4456 | −/* XXX: fix this mess */ | |
| 4457 | −static void expr_land_const(void) | |
| 4458 | −{ | |
| 4459 | − expr_or(); | |
| 4460 | − while (tok == TOK_LAND) { | |
| 4461 | − next(); | |
| 4462 | − expr_or(); | |
| 4463 | − gen_op(TOK_LAND); | |
| 4464 | − } | |
| 4465 | −} | |
| 4466 | − | |
| 4467 | −/* XXX: fix this mess */ | |
| 4468 | −static void expr_lor_const(void) | |
| 4469 | −{ | |
| 4470 | − expr_land_const(); | |
| 4471 | − while (tok == TOK_LOR) { | |
| 4472 | − next(); | |
| 4473 | − expr_land_const(); | |
| 4474 | − gen_op(TOK_LOR); | |
| 4475 | − } | |
| 4476 | −} | |
| 4477 | − | |
| 4478 | −/* only used if non constant */ | |
| 4479 | 4456 | static void expr_land(void) |
| 4480 | 4457 | { |
| 4481 | − int t; | |
| 4482 | − | |
| 4483 | 4458 | expr_or(); |
| 4484 | 4459 | if (tok == TOK_LAND) { |
| 4485 | − t = 0; | |
| 4486 | − save_regs(1); | |
| 4487 | − for(;;) { | |
| 4488 | − t = gvtst(1, t); | |
| 4489 | − if (tok != TOK_LAND) { | |
| 4490 | − vseti(VT_JMPI, t); | |
| 4491 | − break; | |
| 4492 | − } | |
| 4460 | + if ((vtop->r & (VT_VALMASK | VT_LVAL | VT_SYM)) == VT_CONST) { | |
| 4461 | + CType ctb, cti; | |
| 4462 | + ctb.t = VT_BOOL; | |
| 4463 | + cti.t = VT_INT; | |
| 4493 | 4464 | next(); |
| 4494 | − expr_or(); | |
| 4465 | + gen_cast(&ctb); | |
| 4466 | + if (vtop->c.i) { | |
| 4467 | + vpop(); | |
| 4468 | + expr_land(); | |
| 4469 | + gen_cast(&ctb); | |
| 4470 | + } else { | |
| 4471 | + expr_land(); | |
| 4472 | + vpop(); | |
| 4473 | + } | |
| 4474 | + gen_cast(&cti); | |
| 4475 | + } else { | |
| 4476 | + int t = 0; | |
| 4477 | + save_regs(1); | |
| 4478 | + for(;;) { | |
| 4479 | + t = gvtst(1, t); | |
| 4480 | + if (tok != TOK_LAND) { | |
| 4481 | + vseti(VT_JMPI, t); | |
| 4482 | + break; | |
| 4483 | + } | |
| 4484 | + next(); | |
| 4485 | + expr_or(); | |
| 4486 | + } | |
| 4495 | 4487 | } |
| 4496 | 4488 | } |
| 4497 | 4489 | } |
| 4498 | 4490 | |
| 4499 | 4491 | static void expr_lor(void) |
| 4500 | 4492 | { |
| 4501 | − int t; | |
| 4502 | − | |
| 4503 | 4493 | expr_land(); |
| 4504 | 4494 | if (tok == TOK_LOR) { |
| 4505 | − t = 0; | |
| 4506 | − save_regs(1); | |
| 4507 | − for(;;) { | |
| 4508 | − t = gvtst(0, t); | |
| 4509 | − if (tok != TOK_LOR) { | |
| 4510 | − vseti(VT_JMP, t); | |
| 4511 | − break; | |
| 4512 | − } | |
| 4495 | + if ((vtop->r & (VT_VALMASK | VT_LVAL | VT_SYM)) == VT_CONST) { | |
| 4496 | + CType ctb, cti; | |
| 4497 | + ctb.t = VT_BOOL; | |
| 4498 | + cti.t = VT_INT; | |
| 4513 | 4499 | next(); |
| 4514 | − expr_land(); | |
| 4500 | + gen_cast(&ctb); | |
| 4501 | + if (vtop->c.i) { | |
| 4502 | + expr_lor(); | |
| 4503 | + vpop(); | |
| 4504 | + } else { | |
| 4505 | + vpop(); | |
| 4506 | + expr_lor(); | |
| 4507 | + gen_cast(&ctb); | |
| 4508 | + } | |
| 4509 | + gen_cast(&cti); | |
| 4510 | + } else { | |
| 4511 | + int t = 0; | |
| 4512 | + save_regs(1); | |
| 4513 | + for(;;) { | |
| 4514 | + t = gvtst(0, t); | |
| 4515 | + if (tok != TOK_LOR) { | |
| 4516 | + vseti(VT_JMP, t); | |
| 4517 | + break; | |
| 4518 | + } | |
| 4519 | + next(); | |
| 4520 | + expr_land(); | |
| 4521 | + } | |
| 4515 | 4522 | } |
| 4516 | 4523 | } |
| 4517 | 4524 | } |
| 4518 | 4525 | |
| 4519 | −/* XXX: better constant handling */ | |
| 4520 | 4526 | static void expr_cond(void) |
| 4521 | 4527 | { |
| 4522 | 4528 | int tt, u, r1, r2, rc, t1, t2, bt1, bt2; |
| 4523 | 4529 | SValue sv; |
| 4524 | 4530 | CType type, type1, type2; |
| 4525 | 4531 | |
| 4526 | − if (const_wanted) | |
| 4527 | − expr_lor_const(); | |
| 4528 | − else | |
| 4529 | − expr_lor(); | |
| 4532 | + expr_lor(); | |
| 4530 | 4533 | if (tok == '?') { |
| 4531 | 4534 | next(); |
| 4532 | 4535 | if ((vtop->r & (VT_VALMASK | VT_LVAL | VT_SYM)) == VT_CONST) { |
| @@ -17,9 +17,13 @@ void f2(void) · 16 unmodified lines | ||
| 17 | 17 | { |
| 18 | 18 | goto start; |
| 19 | 19 | { |
| 20 | − int a[1 ? 1 : 1]; /* not a variable-length array */ | |
| 20 | + int a[1 && 1]; /* not a variable-length array */ | |
| 21 | + int b[1 || 1]; /* not a variable-length array */ | |
| 22 | + int c[1 ? 1 : 1]; /* not a variable-length array */ | |
| 21 | 23 | start: |
| 22 | 24 | a[0] = 0; |
| 25 | + b[0] = 0; | |
| 26 | + c[0] = 0; | |
| 23 | 27 | } |
| 24 | 28 | } |
| 25 | 29 | |