|
552 | 552 |
|
553 | 553 | (define (expr-otype expr) |
554 | 554 | (match expr |
555 | | - [(? literal?) #f] |
| 555 | + [(? number?) #f] |
556 | 556 | [(? variable?) #f] |
557 | 557 | [(list 'if cond ift iff) (expr-otype ift)] |
558 | 558 | [(list op args ...) (impl-info op 'otype)])) |
559 | 559 |
|
560 | 560 | (define (type-verify expr otype) |
561 | 561 | (match expr |
562 | | - [(? literal?) '()] |
563 | | - [(? variable?) '((cons expr otype))] |
| 562 | + [(? number?) '()] |
| 563 | + [(? variable?) (list (cons expr otype))] |
564 | 564 | [(list 'if cond ift iff) |
565 | 565 | (define bool-repr (get-representation 'bool)) |
566 | 566 | (define combined |
|
584 | 584 |
|
585 | 585 | (define (expr->prog expr repr) |
586 | 586 | (match expr |
587 | | - [(? literal?) (literal (get-representation repr) expr)] |
| 587 | + [(? number?) (literal (representation-name repr) expr)] |
588 | 588 | [(? variable?) expr] |
589 | 589 | [`(if ,cond ,ift ,iff) |
590 | | - `(if ,(expr->prog cond repr) ,(expr->prog ift repr) ,(expr->prog iff repr))] |
591 | | - [`(,impl ,args ...) `(impl ,@(map (λ (arg) (expr->prog arg (impl-info impl 'itype))) args))])) |
| 590 | + `(if ,(expr->prog cond (get-representation 'bool)) |
| 591 | + ,(expr->prog ift repr) |
| 592 | + ,(expr->prog iff repr))] |
| 593 | + [`(,impl ,args ...) |
| 594 | + `(,impl ,@(for/list ([arg (in-list args)] |
| 595 | + [itype (in-list (impl-info impl 'itype))]) |
| 596 | + (expr->prog arg itype)))])) |
592 | 597 |
|
593 | 598 | (define (*fp-safe-simplify-rules*) |
594 | 599 | (reap [sow] |
|
613 | 618 | [(list 'commutes name expr rev-expr) |
614 | 619 | (define vars (impl-info impl 'vars)) |
615 | 620 | (define itype (car (impl-info impl 'itype))) |
| 621 | + (define otype (impl-info impl 'otype)) |
616 | 622 | (define r |
617 | 623 | (rule name |
618 | | - (expr->prog expr) |
619 | | - (expr->prog rev-expr) |
| 624 | + (expr->prog expr otype) |
| 625 | + (expr->prog rev-expr otype) |
620 | 626 | (for/hash ([v (in-list vars)]) |
621 | 627 | (values v itype)) |
622 | | - (impl-info impl 'otype))) ; Commutes by definition the types are matching |
| 628 | + otype)) ; Commutes by definition the types are matching |
623 | 629 | (sow r)] |
624 | 630 | [(list 'directed name lhs rhs) |
625 | 631 | (define lotype (expr-otype lhs)) |
|
635 | 641 | (define var-types (merge-bindings (type-verify lhs lotype) (type-verify rhs rotype))) |
636 | 642 | (define r |
637 | 643 | (rule name |
638 | | - (expr->prog lhs) |
639 | | - (expr->prog rhs) |
| 644 | + (expr->prog lhs lotype) |
| 645 | + (expr->prog rhs rotype) |
640 | 646 | (for/hash ([binding (in-list var-types)]) |
641 | 647 | (values (car binding) (cdr binding))) |
642 | 648 | (impl-info impl 'otype))) |
|
0 commit comments