From 7223b8c63735e6a19b685970d1faff248ec307c1 Mon Sep 17 00:00:00 2001 From: slava Date: Thu, 27 Jul 2006 22:21:49 +0000 Subject: [PATCH] Minor inference cleanups --- TODO.FACTOR.txt | 6 +++--- library/compiler/inference/branches.factor | 20 ++++++++------------ library/compiler/inference/inference.factor | 18 +++++++++--------- 3 files changed, 20 insertions(+), 24 deletions(-) diff --git a/TODO.FACTOR.txt b/TODO.FACTOR.txt index 33f0ec8a39..1f34cfd271 100644 --- a/TODO.FACTOR.txt +++ b/TODO.FACTOR.txt @@ -1,5 +1,8 @@ + 0.83: +- nasty inference regressions +- [ [ dup call ] dup call ] infer hangs +- the invalid recursion form case needs to be fixed, for inlines too - windows port from erg - editor: - scroll to caret @@ -100,7 +103,6 @@ + compiler/ffi: -- nasty inference regressions - instead of decompiling words, add them to a 'recompile' set; compiler treats words in the recompile set as if they were not compiled - mac intel: struct returns from objc methods @@ -115,8 +117,6 @@ - intrinsic fixnum>float float>fixnum - remove literal table - C functions returning structs by value -- [ [ dup call ] dup call ] infer hangs -- the invalid recursion form case needs to be fixed, for inlines too - code gc - infer which variables are read, written in a quotation diff --git a/library/compiler/inference/branches.factor b/library/compiler/inference/branches.factor index b71a4d9ddf..5d01a2ed5e 100644 --- a/library/compiler/inference/branches.factor +++ b/library/compiler/inference/branches.factor @@ -1,17 +1,14 @@ -! Copyright (C) 2004, 2005 Slava Pestov. -! See http://factor.sf.net/license.txt for BSD license. +! Copyright (C) 2004, 2006 Slava Pestov. +! See http://factorcode.org/license.txt for BSD license. IN: inference USING: arrays errors generic hashtables interpreter kernel math namespaces parser prettyprint sequences strings vectors words ; -: add-inputs ( n stack -- stack ) - tuck length - dup 0 > - [ value-vector dup rot nappend ] [ drop ] if ; - : unify-lengths ( seq -- seq ) #! Pad all vectors to the same length. If one vector is #! shorter, pad it with unknown results at the bottom. - dup 0 [ length max ] reduce swap [ add-inputs ] map-with ; + dup 0 [ length max ] reduce + swap [ add-inputs nip ] map-with ; : unify-values ( seq -- value ) #! If all values in list are equal, return the value. @@ -34,9 +31,8 @@ namespaces parser prettyprint sequences strings vectors words ; 0 [ [ max ] when* ] reduce ; : unbalanced-branches ( in out -- ) - { "Unbalanced branches:" } -rot [ - swap unparse " " rot length unparse append3 - ] 2map append "\n" join inference-error ; + [ swap unparse " " rot length unparse append3 ] 2map + "Unbalanced branches:" add* "\n" join inference-error ; : unify-effect ( in out -- in out ) #! In is a sequence of integers; out is a sequence of stacks. @@ -52,7 +48,7 @@ namespaces parser prettyprint sequences strings vectors words ; ] map-with ; : datastack-effect ( seq -- ) - dup d-in active-variable + d-in over [ hash ] map-with swap meta-d active-variable unify-effect meta-d set d-in set ; @@ -66,7 +62,7 @@ namespaces parser prettyprint sequences strings vectors words ; [ terminated? swap hash ] all? terminated? set ; : unify-dataflow ( effects -- nodes ) - [ [ dataflow-graph get ] bind ] map ; + [ dataflow-graph swap hash ] map ; : copy-inference ( -- ) meta-r [ clone ] change diff --git a/library/compiler/inference/inference.factor b/library/compiler/inference/inference.factor index c2aaf33686..9faaddf707 100644 --- a/library/compiler/inference/inference.factor +++ b/library/compiler/inference/inference.factor @@ -1,5 +1,5 @@ -! Copyright (C) 2004, 2005 Slava Pestov. -! See http://factor.sf.net/license.txt for BSD license. +! Copyright (C) 2004, 2006 Slava Pestov. +! See http://factorcode.org/license.txt for BSD license. IN: inference USING: arrays errors generic inspector interpreter io kernel math namespaces parser prettyprint sequences strings @@ -30,7 +30,7 @@ M: object value-literal ( value -- ) ! - infer - quotation with custom inference behavior; 'if' uses ! this. Word is passed on the stack. -! Vector of results we had to add to the datastack. Ie, the +! Number of values we had to add to the datastack. Ie, the ! inputs. SYMBOL: d-in @@ -40,13 +40,13 @@ SYMBOL: d-in : value-vector ( n -- vector ) [ drop ] map >vector ; +: add-inputs ( n stack -- n stack ) + tuck length - dup 0 > + [ dup value-vector [ rot nappend ] keep ] + [ drop 0 swap ] if ; + : ensure-values ( n -- ) - meta-d get length 2dup > [ - - dup d-in [ + ] change - value-vector meta-d [ dupd nappend ] change - ] [ - 2drop - ] if ; + meta-d [ add-inputs ] change d-in [ + ] change ; : effect ( -- { in# out# } ) #! After inference is finished, collect information.