diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2021-02-17 19:31:38 -0800 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2021-02-17 19:31:38 -0800 |
commit | c08daf0b459729d16ac60a565bd6fa974cb01f2e (patch) | |
tree | bd8bded9bfd4f1b7ad06ade66b017f35de191997 /share | |
parent | 26fc85257a9c20435e6f5e2bd9b728659478e406 (diff) | |
download | txr-c08daf0b459729d16ac60a565bd6fa974cb01f2e.tar.gz txr-c08daf0b459729d16ac60a565bd6fa974cb01f2e.tar.bz2 txr-c08daf0b459729d16ac60a565bd6fa974cb01f2e.zip |
compiler: use pattern matching for function form
* share/txr/stdlib/compiler.tl (compiler comp-fun-form):
Rewritten more compactly and extensibly using match-case.
Diffstat (limited to 'share')
-rw-r--r-- | share/txr/stdlib/compiler.tl | 18 |
1 files changed, 7 insertions, 11 deletions
diff --git a/share/txr/stdlib/compiler.tl b/share/txr/stdlib/compiler.tl index b283a0c8..3d69469b 100644 --- a/share/txr/stdlib/compiler.tl +++ b/share/txr/stdlib/compiler.tl @@ -1155,18 +1155,14 @@ me.(compile oreg env (expand qexp)))) (defmeth compiler comp-fun-form (me oreg env form) + (match-case form + ((@(@bin [%bin-op% @sym]) @a @b) + (set form ^(,bin ,a ,b))) + ((- @a) + (set form ^(neg ,a))) + ((@(or identity + * min max) @a) + (return-from comp-fun-form me.(compile oreg env a)))) (tree-bind (sym . args) form - (cond - ((= (len args) 2) - (iflet ((bin [%bin-op% sym])) - (set sym bin - form (cons sym args)))) - ((= (len args) 1) - (caseq sym - (- (set sym 'neg - form (cons sym args))) - ((identity + * min max) (return-from comp-fun-form - me.(compile oreg env (car args))))))) (let* ((fbind env.(lookup-fun sym t)) (cfrag me.(comp-call-impl oreg env (if fbind 'call 'gcall) (if fbind fbind.loc me.(get-sidx sym)) |