]> gitweb.factorcode.org Git - factor.git/commitdiff
minor stack inference fixes
authorSlava Pestov <slava@factorcode.org>
Sun, 26 Dec 2004 01:06:08 +0000 (01:06 +0000)
committerSlava Pestov <slava@factorcode.org>
Sun, 26 Dec 2004 01:06:08 +0000 (01:06 +0000)
factor/jedit/FactorPlugin.java
library/bootstrap/init-stage2.factor
library/compiler/compiler.factor
library/inference/branches.factor
library/test/inference.factor
library/tools/word-tools.factor

index cd9888456896289cfd58b4e579e9a196e4cf7799..1b98731104c6fa308a2237125983e1288c4ad298 100644 (file)
@@ -81,7 +81,17 @@ public class FactorPlugin extends EditPlugin
                        buffer = buffer.getNext();
                }
        } //}}}
-       
+
+       //{{{ addNonEmpty() method
+       private static void addNonEmpty(String[] input, List output)
+       {
+               for(int i = 0; i < input.length; i++)
+               {
+                       if(input[i].length() != 0)
+                               output.add(input[i]);
+               }
+       } //}}}
+
        //{{{ getExternalInstance() method
        /**
         * Returns the object representing a connection to an external Factor instance.
@@ -97,15 +107,17 @@ public class FactorPlugin extends EditPlugin
 
                        try
                        {
-                               String[] args = jEdit.getProperty("factor.external.args","-jedit")
+                               List args = new ArrayList();
+                               args.add(jEdit.getProperty("factor.external.program"));
+                               args.add(jEdit.getProperty("factor.external.image"));
+                               args.add("-no-ansi");
+                               args.add("-no-smart-terminal");
+                               String[] extraArgs = jEdit.getProperty(
+                                       "factor.external.args","-jedit")
                                        .split(" ");
-                               String[] nargs = new String[args.length + 4];
-                               nargs[0] = jEdit.getProperty("factor.external.program");
-                               nargs[1] = jEdit.getProperty("factor.external.image");
-                               nargs[2] = "-no-ansi";
-                               nargs[3] = "-no-smart-terminal";
-                               System.arraycopy(args,0,nargs,4,args.length);
-                               p = Runtime.getRuntime().exec(nargs);
+                               addNonEmpty(extraArgs,args);
+                               p = Runtime.getRuntime().exec((String[])args.toArray(
+                                       new String[args.size()]));
                                p.getErrorStream().close();
 
                                in = p.getInputStream();
index 00ec24088aedf3dc4251435933ef05e91b4a0660..5d550746d10a9e6589235c9ba935040f88037ba6 100644 (file)
@@ -70,6 +70,33 @@ USE: kernel-internals
 
 init-error-handler
 
+! An experiment gone wrong...
+
+! : usage+ ( key -- )
+!     dup "usages" word-property
+!     [ succ ] [ 1 ] ifte*
+!     "usages" set-word-property ;
+! 
+! GENERIC: count-usages ( quot -- )
+! M: object count-usages drop ;
+! M: word count-usages usage+ ;
+! M: cons count-usages unswons count-usages count-usages ;
+! 
+! : tally-usages ( -- )
+!     [ f "usages" set-word-property ] each-word
+!     [ word-parameter count-usages ] each-word ;
+! 
+! : auto-inline ( count -- )
+!     #! Automatically inline all words called less than a count
+!     #! number of times.
+!     [
+!         2dup "usages" word-property dup 0 ? >= [
+!             t "inline" set-word-property
+!         ] [
+!             drop
+!         ] ifte
+!     ] each-word drop ;
+
 ! "Counting word usages..." print
 ! tally-usages
 ! 
@@ -91,6 +118,9 @@ os "win32" = "compile" get and [
 "Compiling system..." print
 "compile" get [ compile-all ] when
 
+"Unless you're working on the compiler, ignore the errors above." print
+"Not every word compiles, by design." print
+
 0 [ compiled? [ succ ] when ] each-word
 unparse write " words compiled" print
 
index 0d017aee09f1f58a4b3b2636a9bd13f81e2ade80..9f604999c58926c9474763c92248c1f911d72836 100644 (file)
@@ -96,4 +96,8 @@ M: compound (compile) ( word -- )
 
 : compile-all ( -- )
     #! Compile all words.
-    [ try-compile ] each-word ;
+    supported-cpu? [
+        [ try-compile ] each-word
+    ] [
+        "Unsupported CPU" print
+    ] ifte ;
index 29d9ed301a72f917f7df62f73fcc11e81b14c4b3..b4025926a38969be5b441f4bbb614138cbc33d2b 100644 (file)
@@ -96,7 +96,9 @@ USE: prettyprint
     dup check-lengths unify-stacks ;
 
 : unify-effects ( list -- )
-    filter-terminators dup balanced? [
+    filter-terminators
+    [ "No branch has a stack effect" throw ] unless*
+    dup balanced? [
         dup unify-d-in d-in set
         dup unify-datastacks meta-d set
         unify-callstacks meta-r set
@@ -143,14 +145,19 @@ SYMBOL: dual-recursive-state
     ] catch ;
 
 : infer-base-cases ( branchlist -- list )
-    [ terminator-quot? not ] subset
-    dup [ dupd recursive-branch ] map nip
-    [ ] subset ;
+    dup [ dupd recursive-branch ] map [ ] subset nip ;
 
 : infer-base-case ( branchlist -- )
+    #! Can't do much if there is only one non-terminator branch.
+    #! Either the word is not recursive, or it is recursive
+    #! and the base case throws an error.
     [
-        infer-base-cases unify-effects
-        effect dual-recursive-state get set-base
+        [ terminator-quot? not ] subset dup length 1 > [
+            infer-base-cases unify-effects
+            effect dual-recursive-state get set-base
+        ] [
+            drop
+        ] ifte
     ] with-scope ;
 
 : (infer-branches) ( branchlist -- list )
index f9024082cbb5cfbd9360f72882e047d5015aa407..5381e28ddf07ebf09f7dd6b210bdaf26540b7752 100644 (file)
@@ -196,7 +196,16 @@ SYMBOL: sym-test
 
 [ [ 1 | 1 ] ] [ [ get ] infer old-effect ] unit-test
 
-! [ [ 1 | 1 ] ] [ [ str>number ] infer old-effect ] unit-test
+: terminator-branch
+    dup [
+        car
+    ] [
+        not-a-number
+    ] ifte ;
+
+[ [ 1 | 1 ] ] [ [ terminator-branch ] infer old-effect ] unit-test
+
+[ [ 1 | 1 ] ] [ [ str>number ] infer old-effect ] unit-test
 
 ! Type inference
 
index 0dbb06a6b73a2e480490e93cca6d5a92b9fdd9fd..b89e32434de83a520102f4e5172e7d2fe1279a22 100644 (file)
@@ -102,28 +102,3 @@ USE: math
 
 : words. ( vocab -- )
     words . ;
-
-: usage+ ( key -- )
-    dup "usages" word-property
-    [ succ ] [ 1 ] ifte*
-    "usages" set-word-property ;
-
-GENERIC: count-usages ( quot -- )
-M: object count-usages drop ;
-M: word count-usages usage+ ;
-M: cons count-usages unswons count-usages count-usages ;
-
-: tally-usages ( -- )
-    [ f "usages" set-word-property ] each-word
-    [ word-parameter count-usages ] each-word ;
-
-: auto-inline ( count -- )
-    #! Automatically inline all words called less than a count
-    #! number of times.
-    [
-        2dup "usages" word-property dup 0 ? >= [
-            t "inline" set-word-property
-        ] [
-            drop
-        ] ifte
-    ] each-word drop ;