|
371 | 371 |
|
372 | 372 | function Ast.OrExpression(lhs, rhs, simplify) |
373 | 373 | if(simplify and rhs.isConstant and lhs.isConstant) then |
374 | | - local val = lhs.value or rhs.value; |
375 | | - return Ast.ConstantNode(val); |
| 374 | + local success, val = pcall(function() return lhs.value or rhs.value end); |
| 375 | + if success then |
| 376 | + return Ast.ConstantNode(val); |
| 377 | + end |
376 | 378 | end |
377 | 379 |
|
378 | 380 | return { |
|
385 | 387 |
|
386 | 388 | function Ast.AndExpression(lhs, rhs, simplify) |
387 | 389 | if(simplify and rhs.isConstant and lhs.isConstant) then |
388 | | - local val = lhs.value and rhs.value; |
389 | | - return Ast.ConstantNode(val); |
| 390 | + local success, val = pcall(function() return lhs.value and rhs.value end); |
| 391 | + if success then |
| 392 | + return Ast.ConstantNode(val); |
| 393 | + end |
390 | 394 | end |
391 | 395 |
|
392 | 396 | return { |
|
399 | 403 |
|
400 | 404 | function Ast.LessThanExpression(lhs, rhs, simplify) |
401 | 405 | if(simplify and rhs.isConstant and lhs.isConstant) then |
402 | | - local val = lhs.value < rhs.value; |
403 | | - return Ast.ConstantNode(val); |
| 406 | + local success, val = pcall(function() return lhs.value < rhs.value end); |
| 407 | + if success then |
| 408 | + return Ast.ConstantNode(val); |
| 409 | + end |
404 | 410 | end |
405 | 411 |
|
406 | 412 | return { |
|
413 | 419 |
|
414 | 420 | function Ast.GreaterThanExpression(lhs, rhs, simplify) |
415 | 421 | if(simplify and rhs.isConstant and lhs.isConstant) then |
416 | | - local val = lhs.value > rhs.value; |
417 | | - return Ast.ConstantNode(val); |
| 422 | + local success, val = pcall(function() return lhs.value > rhs.value end); |
| 423 | + if success then |
| 424 | + return Ast.ConstantNode(val); |
| 425 | + end |
418 | 426 | end |
419 | 427 |
|
420 | 428 | return { |
|
427 | 435 |
|
428 | 436 | function Ast.LessThanOrEqualsExpression(lhs, rhs, simplify) |
429 | 437 | if(simplify and rhs.isConstant and lhs.isConstant) then |
430 | | - local val = lhs.value <= rhs.value; |
431 | | - return Ast.ConstantNode(val); |
| 438 | + local success, val = pcall(function() return lhs.value <= rhs.value end); |
| 439 | + if success then |
| 440 | + return Ast.ConstantNode(val); |
| 441 | + end |
432 | 442 | end |
433 | 443 |
|
434 | 444 | return { |
|
441 | 451 |
|
442 | 452 | function Ast.GreaterThanOrEqualsExpression(lhs, rhs, simplify) |
443 | 453 | if(simplify and rhs.isConstant and lhs.isConstant) then |
444 | | - local val = lhs.value >= rhs.value; |
445 | | - return Ast.ConstantNode(val); |
| 454 | + local success, val = pcall(function() return lhs.value >= rhs.value end); |
| 455 | + if success then |
| 456 | + return Ast.ConstantNode(val); |
| 457 | + end |
446 | 458 | end |
447 | 459 |
|
448 | 460 | return { |
|
455 | 467 |
|
456 | 468 | function Ast.NotEqualsExpression(lhs, rhs, simplify) |
457 | 469 | if(simplify and rhs.isConstant and lhs.isConstant) then |
458 | | - local val = lhs.value ~= rhs.value; |
459 | | - return Ast.ConstantNode(val); |
| 470 | + local success, val = pcall(function() return lhs.value ~= rhs.value end); |
| 471 | + if success then |
| 472 | + return Ast.ConstantNode(val); |
| 473 | + end |
460 | 474 | end |
461 | 475 |
|
462 | 476 | return { |
|
469 | 483 |
|
470 | 484 | function Ast.EqualsExpression(lhs, rhs, simplify) |
471 | 485 | if(simplify and rhs.isConstant and lhs.isConstant) then |
472 | | - local val = lhs.value == rhs.value; |
473 | | - return Ast.ConstantNode(val); |
| 486 | + local success, val = pcall(function() return lhs.value == rhs.value end); |
| 487 | + if success then |
| 488 | + return Ast.ConstantNode(val); |
| 489 | + end |
474 | 490 | end |
475 | 491 |
|
476 | 492 | return { |
|
483 | 499 |
|
484 | 500 | function Ast.StrCatExpression(lhs, rhs, simplify) |
485 | 501 | if(simplify and rhs.isConstant and lhs.isConstant) then |
486 | | - local val = lhs.value .. rhs.value; |
487 | | - return Ast.ConstantNode(val); |
| 502 | + local success, val = pcall(function() return lhs.value .. rhs.value end); |
| 503 | + if success then |
| 504 | + return Ast.ConstantNode(val); |
| 505 | + end |
488 | 506 | end |
489 | 507 |
|
490 | 508 | return { |
|
497 | 515 |
|
498 | 516 | function Ast.AddExpression(lhs, rhs, simplify) |
499 | 517 | if(simplify and rhs.isConstant and lhs.isConstant) then |
500 | | - local val = lhs.value + rhs.value; |
501 | | - return Ast.ConstantNode(val); |
| 518 | + local success, val = pcall(function() return lhs.value + rhs.value end); |
| 519 | + if success then |
| 520 | + return Ast.ConstantNode(val); |
| 521 | + end |
502 | 522 | end |
503 | 523 |
|
504 | 524 | return { |
|
511 | 531 |
|
512 | 532 | function Ast.SubExpression(lhs, rhs, simplify) |
513 | 533 | if(simplify and rhs.isConstant and lhs.isConstant) then |
514 | | - local val = lhs.value - rhs.value; |
515 | | - return Ast.ConstantNode(val); |
| 534 | + local success, val = pcall(function() return lhs.value - rhs.value end); |
| 535 | + if success then |
| 536 | + return Ast.ConstantNode(val); |
| 537 | + end |
516 | 538 | end |
517 | 539 |
|
518 | 540 | return { |
|
525 | 547 |
|
526 | 548 | function Ast.MulExpression(lhs, rhs, simplify) |
527 | 549 | if(simplify and rhs.isConstant and lhs.isConstant) then |
528 | | - local val = lhs.value * rhs.value; |
529 | | - return Ast.ConstantNode(val); |
| 550 | + local success, val = pcall(function() return lhs.value * rhs.value end); |
| 551 | + if success then |
| 552 | + return Ast.ConstantNode(val); |
| 553 | + end |
530 | 554 | end |
531 | 555 |
|
532 | 556 | return { |
|
539 | 563 |
|
540 | 564 | function Ast.DivExpression(lhs, rhs, simplify) |
541 | 565 | if(simplify and rhs.isConstant and lhs.isConstant) then |
542 | | - local val = lhs.value / rhs.value; |
543 | | - return Ast.ConstantNode(val); |
| 566 | + local success, val = pcall(function() return lhs.value / rhs.value end); |
| 567 | + if success then |
| 568 | + return Ast.ConstantNode(val); |
| 569 | + end |
544 | 570 | end |
545 | 571 |
|
546 | 572 | return { |
|
553 | 579 |
|
554 | 580 | function Ast.ModExpression(lhs, rhs, simplify) |
555 | 581 | if(simplify and rhs.isConstant and lhs.isConstant) then |
556 | | - local val = lhs.value % rhs.value; |
557 | | - return Ast.ConstantNode(val); |
| 582 | + local success, val = pcall(function() return lhs.value % rhs.value end); |
| 583 | + if success then |
| 584 | + return Ast.ConstantNode(val); |
| 585 | + end |
558 | 586 | end |
559 | 587 |
|
560 | 588 | return { |
|
567 | 595 |
|
568 | 596 | function Ast.NotExpression(rhs, simplify) |
569 | 597 | if(simplify and rhs.isConstant) then |
570 | | - local val = not rhs.value; |
571 | | - return Ast.ConstantNode(val); |
| 598 | + local success, val = pcall(function() return not rhs.value end); |
| 599 | + if success then |
| 600 | + return Ast.ConstantNode(val); |
| 601 | + end |
572 | 602 | end |
573 | 603 |
|
574 | 604 | return { |
|
580 | 610 |
|
581 | 611 | function Ast.NegateExpression(rhs, simplify) |
582 | 612 | if(simplify and rhs.isConstant) then |
583 | | - local val = -rhs.value; |
584 | | - return Ast.ConstantNode(val); |
| 613 | + local success, val = pcall(function() return -rhs.value end); |
| 614 | + if success then |
| 615 | + return Ast.ConstantNode(val); |
| 616 | + end |
585 | 617 | end |
586 | 618 |
|
587 | 619 | return { |
|
593 | 625 |
|
594 | 626 | function Ast.LenExpression(rhs, simplify) |
595 | 627 | if(simplify and rhs.isConstant) then |
596 | | - local val = #(rhs.value); |
597 | | - return Ast.ConstantNode(val); |
| 628 | + local success, val = pcall(function() return #rhs.value end); |
| 629 | + if success then |
| 630 | + return Ast.ConstantNode(val); |
| 631 | + end |
598 | 632 | end |
599 | 633 |
|
600 | 634 | return { |
|
606 | 640 |
|
607 | 641 | function Ast.PowExpression(lhs, rhs, simplify) |
608 | 642 | if(simplify and rhs.isConstant and lhs.isConstant) then |
609 | | - local val = lhs.value ^ rhs.value; |
610 | | - return Ast.ConstantNode(val); |
| 643 | + local success, val = pcall(function() return lhs.value ^ rhs.value end); |
| 644 | + if success then |
| 645 | + return Ast.ConstantNode(val); |
| 646 | + end |
611 | 647 | end |
612 | 648 |
|
613 | 649 | return { |
|
0 commit comments