From a56ad07fd9fb8a77682656f4eaddb33375a42806 Mon Sep 17 00:00:00 2001 From: Matthew Butterick Date: Wed, 6 Apr 2022 14:23:59 -0700 Subject: [PATCH] more lenient pass macro --- quad2/attr.rkt | 3 +-- quad2/pipeline.rkt | 16 +++++++++++----- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/quad2/attr.rkt b/quad2/attr.rkt index 3fe42bcf..659f3dcb 100644 --- a/quad2/attr.rkt +++ b/quad2/attr.rkt @@ -39,8 +39,7 @@ ;; otherwise treat return value as new attr value [new-av (hash-set! attrs ak new-av)])) (set-add! attrs-seen attrs)) - (loop (quad-elems q))))) - qs) + (loop (quad-elems q)))))) (define-pass (upgrade-attr-keys qs) ;; convert attr keys from symbols to attr struct types diff --git a/quad2/pipeline.rkt b/quad2/pipeline.rkt index e4bbc7a0..81d6b219 100644 --- a/quad2/pipeline.rkt +++ b/quad2/pipeline.rkt @@ -40,9 +40,15 @@ (when (current-use-preconditions?) (unless (PRECOND-PROC ARG) (raise-argument-error 'PASS-NAME (format "~a (as precondition)" 'PRECOND-PROC) ARG))) - (define res (let () EXPRS ...)) - (when (current-use-postconditions?) - (unless (POSTCOND-PROC res) - (raise-argument-error 'PASS-NAME (format "~a (as postcondition)" 'POSTCOND-PROC) res))) - res)) + ;; a pass can be functional or mutational. + ;; if it returns void, assume mutational + ;; and return the input item. + (define res (match (let () EXPRS ...) + [(? void?) ARG] + [val val])) + (begin0 + res + (when (current-use-postconditions?) + (unless (POSTCOND-PROC res) + (raise-argument-error 'PASS-NAME (format "~a (as postcondition)" 'POSTCOND-PROC) res)))))) 'PASS-NAME))))])) \ No newline at end of file