From f9a9a206f21d745518cc031eec011cf3d724ac33 Mon Sep 17 00:00:00 2001 From: Joe Groff Date: Sat, 7 Nov 2009 21:50:45 -0600 Subject: [PATCH] eliminate more redundant empty quots from fry code generation --- basis/fry/fry.factor | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/basis/fry/fry.factor b/basis/fry/fry.factor index c2f0ddb125..d8a8fefa4c 100644 --- a/basis/fry/fry.factor +++ b/basis/fry/fry.factor @@ -74,14 +74,24 @@ INSTANCE: fried-callable fried [ >quotation make-curry ] if ] if-empty ; +: prune-curries ( seq -- seq' ) + dup [ empty? not ] find + [ [ 1 + tail ] dip but-last prefix ] + [ 2drop { } ] if* ; + : convert-curries ( seq -- tail seq' ) - unclip-slice [ 0 swap [ convert-curry ] map ] [ >quotation 1quotation ] bi* prefix ; + unclip-slice [ 0 swap [ convert-curry ] map ] dip + [ prune-curries ] + [ >quotation 1quotation prefix ] if-empty ; + +: mark-composes ( quot -- quot' ) + [ dup \ @ = [ drop [ _ @ ] ] [ 1quotation ] if ] map concat ; inline : shallow-fry ( quot -- quot' ) - check-fry - [ dup \ @ = [ drop [ _ @ ] ] [ 1quotation ] if ] map concat + check-fry mark-composes { _ } split convert-curries - spread>quot swap [ [ ] (make-curry) compose ] unless-zero ; + [ [ [ ] ] [ [ ] (make-curry) but-last ] if-zero ] + [ spread>quot swap [ [ ] (make-curry) compose ] unless-zero ] if-empty ; DEFER: dredge-fry