]> gitweb.factorcode.org Git - factor.git/commitdiff
type inference changes, comment out smart-terminal reference in win32-console, win32...
authorSlava Pestov <slava@factorcode.org>
Wed, 29 Dec 2004 08:35:46 +0000 (08:35 +0000)
committerSlava Pestov <slava@factorcode.org>
Wed, 29 Dec 2004 08:35:46 +0000 (08:35 +0000)
54 files changed:
TODO.FACTOR.txt
examples/infix.factor
examples/mandel.factor
examples/more-random.factor
factor/ExternalFactor.java
factor/jedit/FactorPlugin.java
library/bootstrap/boot-stage2.factor
library/bootstrap/init-stage2.factor
library/bootstrap/primitives.factor
library/cli.factor
library/compiler/alien-types.factor
library/generic/builtin.factor
library/generic/generic.factor
library/gensym.factor
library/httpd/url-encoding.factor
library/inference/branches.factor
library/inference/inference.factor
library/inference/words.factor
library/io/ansi.factor
library/io/stdio.factor
library/io/stream.factor
library/io/win32-console.factor
library/lists.factor
library/math/arc-trig-hyp.factor
library/math/math-combinators.factor
library/math/math.factor
library/namespaces.factor
library/primitives.factor
library/random.factor
library/sdl/console.factor
library/sdl/hsv.factor
library/strings.factor
library/syntax/parse-stream.factor
library/syntax/parser.factor
library/syntax/prettyprint.factor
library/syntax/see.factor
library/syntax/unparser.factor
library/test/benchmark/ack.factor
library/test/benchmark/fac.factor
library/test/benchmark/fib.factor
library/test/benchmark/strings.factor
library/test/continuations.factor
library/test/dataflow.factor
library/test/inference.factor
library/test/strings.factor
library/test/test.factor
library/tools/debugger.factor
library/tools/heap-stats.factor
library/tools/listener.factor
library/tools/telnetd.factor
library/vectors.factor
native/signal.h
native/stack.c
native/unix/signal.c

index ea52a4df89916982de05ef67a357b0580bb445b6..9130aa10c1c03ff82115b32750392fa7096231c1 100644 (file)
 \r
 + listener/plugin:\r
 \r
+- listener should be multithreaded\r
+- fully socket based communication\r
+- compile all, infer all commands\r
+- type something -- no completions -- hit another key -- not inserted\r
 - faster completion\r
 - sidekick: still parsing too much\r
 - errors don't always disappear\r
index 995ad9c842d489af8b09ba2d2da741e9fa5743f6..bcdd97ef01efd198fad8d4bff383292344dbd7c5 100644 (file)
@@ -8,7 +8,7 @@ USE: words
 
 : vector-peek ( vector -- obj )
     #! Get value at end of vector without removing it.
-    dup vector-length pred swap vector-nth ;
+    dup vector-length 1 - swap vector-nth ;
 
 SYMBOL: exprs
 DEFER: infix
index 7296502ca60fbfed9f8ec9ae74eb5eb34cd55353..916b3cd1be26d3bdfa330e089681460c3c981b46 100644 (file)
@@ -44,7 +44,7 @@ USE: test
 : <color-map> ( nb-cols -- map )
     [
         dup [
-            360 * over succ / 360 / sat val
+            360 * over 1 + / 360 / sat val
             hsv>rgb 1.0 scale-rgba ,
         ] times*
     ] make-list list>vector nip ;
@@ -55,7 +55,7 @@ USE: test
     over absq 4 >= over 0 = or [
         nip nip
     ] [
-        pred >r sq dupd + r> iter
+        1 - >r sq dupd + r> iter
     ] ifte ;
 
 : max-color 360 ;
index c9d9f3357ed757c1364e5d9f0facec2f304f3048..d9db9d74d0ad91cbbf6692516569e7cdd6933c97 100644 (file)
@@ -14,7 +14,7 @@ USE: namespaces
 
 : random-element ( list -- random )
     #! Returns a random element from the given list.
-    dup >r length pred 0 swap random-int r> nth ;
+    dup >r length 1 - 0 swap random-int r> nth ;
 
 : random-subset ( list -- list )
     #! Returns a random subset of the given list. Each item is
index 65717fb3d115271f05f634448df3930c4114fcdb..69708e5f63266b4514f13c6637fac35bdc2620e6 100644 (file)
@@ -40,41 +40,57 @@ import org.gjt.sp.util.Log;
 public class ExternalFactor extends DefaultVocabularyLookup
 {
        //{{{ ExternalFactor constructor
-       /**
-        * We are given two streams that point to a bare REPL.
-        */
-       public ExternalFactor(Process proc, InputStream in, OutputStream out)
+       public ExternalFactor(int port)
        {
-               if(proc == null || in == null || out == null)
-                       closed = true;
-               else
-               {
-                       this.proc = proc;
+               /* Start stream server */;
+               streamServer = port;
 
+               for(int i = 1; i < 6; i++)
+               {
+                       Log.log(Log.DEBUG,this,"Factor connection, try #" + i);
                        try
                        {
-                               this.in = new DataInputStream(in);
-                               this.out = new DataOutputStream(out);
-
-                               out.write("USE: jedit wire-server\n".getBytes("ASCII"));
-                               out.flush();
-
-                               waitForAck();
-
-                               /* Start stream server */
-                               streamServer = 9999;
-                               eval("USE: telnetd [ 9999 telnetd ] in-thread");
-
-                               /* Ensure we're ready for a connection immediately */
-                               eval("nop");
+                               Thread.sleep(1000);
+                               openWire();
+                               Log.log(Log.DEBUG,this,"Connection established");
+                               return;
                        }
                        catch(Exception e)
                        {
-                               close();
+                               Log.log(Log.ERROR,this,e);
                        }
+                       
                }
+
+               Log.log(Log.ERROR,this,"Cannot connect to Factor on port " + port);
+               if(in != null && out != null)
+                       close();
+       } //}}}
+
+       //{{{ openWireSocket() method
+       /**
+        * Return a listener stream.
+        */
+       public Socket openWireSocket() throws IOException
+       {
+               if(closed)
+                       throw new IOException("Socket closed");
+               return new Socket("localhost",streamServer);
        } //}}}
 
+       //{{{ openWire() method
+       private void openWire() throws Exception
+       {
+               Socket client = openWireSocket();
+               in = new DataInputStream(new BufferedInputStream(
+                       client.getInputStream()));
+               out = new DataOutputStream(new BufferedOutputStream(
+                       client.getOutputStream()));
+               out.write("USE: jedit wire-server\n".getBytes("ASCII"));
+               out.flush();
+               waitForAck();
+       }
+
        //{{{ waitForAck() method
        private void waitForAck() throws IOException
        {
@@ -132,22 +148,16 @@ public class ExternalFactor extends DefaultVocabularyLookup
         */
        public FactorStream openStream()
        {
-               if(closed)
-                       return null;
-               else
+               try
                {
-                       try
-                       {
-                               Socket client = new Socket("localhost",streamServer);
-                               return new FactorStream(client);
-                       }
-                       catch(Exception e)
-                       {
-                               Log.log(Log.ERROR,this,"Cannot open stream connection to "
-                                       + "external Factor:");
-                               Log.log(Log.ERROR,this,e);
-                               return null;
-                       }
+                       return new FactorStream(openWireSocket());
+               }
+               catch(Exception e)
+               {
+                       Log.log(Log.ERROR,this,"Cannot open stream connection to "
+                               + "external Factor:");
+                       Log.log(Log.ERROR,this,e);
+                       return null;
                }
        } //}}}
 
@@ -279,7 +289,6 @@ public class ExternalFactor extends DefaultVocabularyLookup
                
                try
                {
-                       proc.waitFor();
                        in.close();
                        out.close();
                }
@@ -289,7 +298,6 @@ public class ExternalFactor extends DefaultVocabularyLookup
                        Log.log(Log.DEBUG,this,e);
                }
 
-               proc = null;
                in = null;
                out = null;
        } //}}}
@@ -303,7 +311,6 @@ public class ExternalFactor extends DefaultVocabularyLookup
        //{{{ Private members
        private boolean closed;
 
-       private Process proc;
        private DataInputStream in;
        private DataOutputStream out;
        
index 1b98731104c6fa308a2237125983e1288c4ad298..3e7420b09f894e8f2d3f75422f4e1b382f2a5c19 100644 (file)
@@ -42,6 +42,8 @@ import sidekick.*;
 public class FactorPlugin extends EditPlugin
 {
        private static ExternalFactor external;
+       private static Process process;
+       private static int PORT = 9999;
 
        //{{{ getPluginPath() method
        private String getPluginPath()
@@ -101,7 +103,6 @@ public class FactorPlugin extends EditPlugin
        {
                if(external == null)
                {
-                       Process p = null;
                        InputStream in = null;
                        OutputStream out = null;
 
@@ -110,27 +111,28 @@ public class FactorPlugin extends EditPlugin
                                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");
+                               args.add("-shell=telnet");
+                               args.add("-telnetd-port=" + PORT);
                                String[] extraArgs = jEdit.getProperty(
-                                       "factor.external.args","-jedit")
+                                       "factor.external.args")
                                        .split(" ");
                                addNonEmpty(extraArgs,args);
-                               p = Runtime.getRuntime().exec((String[])args.toArray(
+                               process = Runtime.getRuntime().exec((String[])args.toArray(
                                        new String[args.size()]));
-                               p.getErrorStream().close();
 
-                               in = p.getInputStream();
-                               out = p.getOutputStream();
+                               external = new ExternalFactor(PORT);
+
+                               process.getErrorStream().close();
+                               process.getInputStream().close();
+                               process.getOutputStream().close();
                        }
-                       catch(IOException io)
+                       catch(Exception e)
                        {
                                Log.log(Log.ERROR,FactorPlugin.class,
                                        "Cannot start external Factor:");
-                               Log.log(Log.ERROR,FactorPlugin.class,io);
+                               Log.log(Log.ERROR,FactorPlugin.class,e);
+                               process = null;
                        }
-
-                       external = new ExternalFactor(p,in,out);
                }
 
                return external;
@@ -153,6 +155,14 @@ public class FactorPlugin extends EditPlugin
                if(external != null)
                {
                        external.close();
+                       try
+                       {
+                               process.waitFor();
+                       }
+                       catch(Exception e)
+                       {
+                               Log.log(Log.DEBUG,FactorPlugin.class,e);
+                       }
                        external = null;
                }
        } //}}}
index a7b4c477dbe1fd8f5c7db791ebc4c175f530cd40..a60881b94b939fc06e76f3d6f4d84bcf76206f71 100644 (file)
@@ -114,8 +114,8 @@ USE: namespaces
 \r
     "/library/inference/dataflow.factor"\r
     "/library/inference/inference.factor"\r
-    "/library/inference/words.factor"\r
     "/library/inference/branches.factor"\r
+    "/library/inference/words.factor"\r
     "/library/inference/stack.factor"\r
 \r
     "/library/compiler/assembler.factor"\r
@@ -165,10 +165,10 @@ os "win32" = [
         "/library/io/buffer.factor"\r
         "/library/win32/win32-io.factor"\r
         "/library/win32/win32-errors.factor"\r
-        "/library/win32/winsock.factor"
+        "/library/win32/winsock.factor"\r
         "/library/io/win32-io-internals.factor"\r
         "/library/io/win32-stream.factor"\r
-        "/library/io/win32-server.factor"
+        "/library/io/win32-server.factor"\r
         "/library/io/win32-console.factor"\r
     ] [\r
         dup print\r
index bf2a459fa2cb72f86a1df66478bfad1fdaaabf93..f6c854405b219b7b3d83b829c217990f397876d6 100644 (file)
@@ -45,10 +45,19 @@ USE: unparser
 USE: kernel-internals
 USE: console
 
-: init-smart-terminal
-    "smart-terminal" get [
-        stdio smart-term-hook get change 
-    ] when ;
+: default-cli-args
+    #! Some flags are *on* by default, unless user specifies
+    #! -no-<flag> CLI switch
+    "user-init" on
+    "interactive" on
+    "smart-terminal" on
+    "verbose-compile" on
+    "compile" on
+    os "win32" = [
+        "sdl" "shell" set
+    ] [
+        "ansi" "shell" set
+    ] ifte ;
 
 : warm-boot ( -- )
     #! A fully bootstrapped image has this as the boot
@@ -59,18 +68,15 @@ USE: console
     default-cli-args
     parse-command-line ;
 
+: shell ( str -- )
+    #! This handles the -shell:<foo> cli argument.
+    [ "shells" ] search execute ;
+
 [
     warm-boot
     garbage-collection
     run-user-init
-    "graphical" get [
-        start-console
-    ] [
-        "interactive" get [
-            init-smart-terminal
-            print-banner listener
-        ] when
-    ] ifte
+    "shell" get shell
     0 exit* 
 ] set-boot
 
@@ -136,10 +142,10 @@ terpri
 "Not every word compiles, by design." print
 terpri
 
-0 [ compiled? [ succ ] when ] each-word
+0 [ compiled? [ 1 + ] when ] each-word
 unparse write " words compiled" print
 
-0 [ drop succ ] each-word
+0 [ drop 1 + ] each-word
 unparse write " words total" print 
 
 "Bootstrapping is complete." print
index 91c889f7e421c54fb8d97724a9a68b10b4d96be8..5fc225c065be87d7d31e3fff637be9e8576b7a12 100644 (file)
@@ -223,5 +223,5 @@ vocabularies get [
     [ "kernel-internals" | "set-integer-slot" ]
     [ "kernel-internals" | "grow-array" ]
 ] [
-    unswons create swap succ [ f define ] keep
+    unswons create swap 1 + [ f define ] keep
 ] each drop
index 91774132a75a31cdca7c8f6790ee96601b65d260..afb242a9450cd9e80e3c16b8a81342a63f734f86 100644 (file)
@@ -82,16 +82,6 @@ USE: kernel-internals
 : run-files ( args -- )
     [ [ run-file ] when* ] each ;
 
-: default-cli-args
-    #! Some flags are *on* by default, unless user specifies
-    #! -no-<flag> CLI switch
-    "user-init" on
-    "interactive" on
-    "smart-terminal" on
-    "verbose-compile" on
-    "compile" on
-    os "win32" = [ "graphical" on ] when ;
-
 : cli-args ( -- args ) 10 getenv ;
 
 : parse-command-line ( -- )
index 5abf6963b9b12ecaffd5df9b990264e280998fb6..20bafabaef59255d49e9537ca4e99b61ccfc306d 100644 (file)
@@ -53,7 +53,7 @@ USE: words
     scan str>number ; parsing
 
 : ENUM:
-    dup CREATE swap unit define-compound succ ; parsing
+    dup CREATE swap unit define-compound 1 + ; parsing
 
 : END-ENUM
     drop ; parsing
index 515314ec04273e22853c2219c0f09ca45a6a60ad..1db73197fd92f9bc863357dc147d4c713b35da6d 100644 (file)
@@ -77,9 +77,6 @@ builtin 50 "priority" set-word-property
 : builtin-type ( n -- symbol )
     unit classes get hash ;
 
-: type-name ( n -- string )
-    builtin-type word-name ;
-
 : class ( obj -- class )
     #! Analogous to the type primitive. Pushes the builtin
     #! class of an object.
index 5dc7dee8fc33438c58af3ffcd37f10192ec5782c..02a289fbf11361f48192d307b9b9639b00cb2b89 100644 (file)
@@ -118,6 +118,9 @@ USE: math-internals
         dup <namespace> [ "methods" set-word-property ] keep
     ] unless* <vtable> define-generic ;
 
+PREDICATE: word generic ( word -- ? )
+    "combination" word-property ;
+
 : single-combination ( obj vtable -- )
     >r dup type r> dispatch ; inline
 
index ac186b18b94b5b17291bb1681ce7de6a03ebb57b..cb561a6d41bf96eb52c0077968b432213a6456a2 100644 (file)
@@ -36,7 +36,7 @@ SYMBOL: gensym-count
 
 : (gensym) ( -- name )
     "G:" global [
-        gensym-count [ succ dup ] change
+        gensym-count [ 1 + dup ] change
     ] bind unparse cat2 ;
 
 : gensym ( -- word )
index d9936d26aab55e54b9febf3907eacbff5d8ec23d..0993a14cfa41e6c37f8c7e86567f99a77aea764c 100644 (file)
@@ -49,14 +49,14 @@ USE: unparser
     2dup str-length 2 - >= [
         2drop
     ] [
-        >r succ dup 2 + r> substring  catch-hex> [ , ] when*
+        >r 1 + dup 2 + r> substring  catch-hex> [ , ] when*
     ] ifte ;
 
 : url-decode-% ( index str -- index str )
     2dup url-decode-hex >r 3 + r> ;
 
 : url-decode-+-or-other ( index str ch -- index str )
-    dup CHAR: + = [ drop CHAR: \s ] when , >r succ r> ;
+    dup CHAR: + = [ drop CHAR: \s ] when , >r 1 + r> ;
 
 : url-decode-iter ( index str -- )
     2dup str-length >= [
index ce648c5ecf2784db9143ae6c4317e4ab13a57661..9421beda241489c5d7711f13e494bbd3cc196493 100644 (file)
@@ -39,10 +39,6 @@ USE: words
 USE: hashtables
 USE: prettyprint
 
-! If this symbol is on, partial evalution of conditionals is
-! disabled.
-SYMBOL: inferring-base-case
-
 : vector-length< ( vec1 vec2 -- ? )
     swap vector-length swap vector-length < ;
 
@@ -65,7 +61,11 @@ SYMBOL: inferring-base-case
 : unify-results ( value value -- value )
     #! Replace values with unknown result if they differ,
     #! otherwise retain them.
-    2dup = [ drop ] [ unify-classes <computed> ] ifte ;
+    2dup = [
+        drop
+    ] [
+        unify-classes <computed>
+    ] ifte ;
 
 : unify-stacks ( list -- stack )
     #! Replace differing literals in stacks with unknown
@@ -109,10 +109,23 @@ SYMBOL: inferring-base-case
 
 SYMBOL: cloned
 
+: assq* ( key alist -- [ key | value ] )
+    #! Looks up the key in an alist. Push the key/value pair.
+    #! Most of the time you want to use assq not assq*.
+    dup [
+        2dup car car eq? [ nip car ] [ cdr assq* ] ifte
+    ] [
+        2drop f
+    ] ifte ;
+
+: assq ( key alist -- value )
+    #! Looks up the key in an alist.
+    assq* dup [ cdr ] when ;
+
 : deep-clone ( vector -- vector )
     #! Clone a vector if it hasn't already been cloned in this
     #! with-deep-clone scope.
-    dup cloned get assoc dup [
+    dup cloned get assq dup [
         nip
     ] [
         drop vector-clone [ dup cloned [ acons ] change ] keep
@@ -120,7 +133,7 @@ SYMBOL: cloned
 
 : deep-clone-vector ( vector -- vector )
     #! Clone a vector of vectors.
-    [ ( deep-clone ) vector-clone ] vector-map ;
+    [ deep-clone ] vector-map ;
 
 : copy-inference ( -- )
     #! We avoid cloning the same object more than once in order
@@ -133,7 +146,7 @@ SYMBOL: cloned
 
 : infer-branch ( value -- namespace )
     <namespace> [
-        uncons [ unswons [ \ value-class set ] bind ] when*
+        uncons [ unswons set-value-class ] when*
         dup value-recursion recursive-state set
         copy-inference
         literal-value infer-quot
@@ -151,6 +164,45 @@ SYMBOL: cloned
     #! given one in the list.
     [ over eq? not ] subset nip car car value-recursion ;
 
+! FIXME this is really bad
+: old-effect ( [ in-types out-types ] -- [ in | out ] )
+    uncons car length >r length r> cons ;
+
+: foo>effect ( [ in-types out-types ] -- [ in | out ] )
+    [ effect old-effect ] bind ;
+
+: raise ( [ in | out ] -- [ in | out ] )
+    uncons 2dup min tuck - >r - r> cons ;
+
+: effect>foo ( [ in | out ] -- [ intypes outtypes ] )
+    <namespace> [
+        uncons
+        [ drop object <computed> ] vector-project meta-d set
+        [ drop object <computed> ] vector-project d-in set
+        { } meta-r set
+    ] extend ;
+
+: decompose ( first second -- solution )
+    #! Return a stack effect such that first*solution = second.
+    2dup 2car
+    2dup > [ "No solution to decomposition" throw ] when
+    swap - -rot 2cdr >r + r> cons raise effect>foo ;
+
+: set-base ( effect rstate -- )
+    #! Set the base case of the current word.
+    dup [
+        car cdr [
+            entry-effect get old-effect dup [ 0 | 0 ] = [
+                drop
+            ] [
+                swap foo>effect decompose
+            ] ifte
+            base-case cons@
+        ] bind
+    ] [
+        2drop
+    ] ifte ;
+
 : recursive-branch ( branch branchlist -- )
     [
         dupd dual-branch >r infer-branch r> set-base
@@ -158,6 +210,16 @@ SYMBOL: cloned
         [ 2drop ] when
     ] catch ;
 
+: no-base-case ( word -- )
+    word-name " does not have a base case." cat2 throw ;
+
+: get-base ( word rstate -- effect )
+    [ base-case get ] bind dup [
+        nip [ unify-effects effect ] with-scope
+    ] [
+        drop no-base-case
+    ] ifte ;
+
 : infer-base-case ( branchlist -- )
     [
         inferring-base-case on
@@ -192,7 +254,18 @@ SYMBOL: cloned
     #! the branches has an undecidable stack effect, we set the
     #! base case to this stack effect and try again. The inputs
     #! parameter is a vector.
-    (infer-branches) dup unify-effects unify-dataflow ;
+    (infer-branches)  dup unify-effects unify-dataflow ;
+
+: (with-block) ( label quot -- )
+    #! Call a quotation in a new namespace, and transfer
+    #! inference state from the outer scope.
+    swap >r [
+        dataflow-graph off
+        call
+        d-in get meta-d get meta-r get get-dataflow
+    ] with-scope
+    r> swap #label dataflow, [ node-label set ] bind
+    meta-r set meta-d set d-in set ;
 
 : static-branch? ( value -- )
     literal? inferring-base-case get not and ;
@@ -221,11 +294,11 @@ SYMBOL: cloned
     [ object general-list general-list ] ensure-d
     dataflow-drop, pop-d
     dataflow-drop, pop-d swap
-    peek-d static-branch? [
-        static-ifte
-    ] [
+!    peek-d static-branch? [
+!        static-ifte
+!    ] [
         dynamic-ifte
-    ] ifte ;
+    ( ] ifte ) ;
 
 \ ifte [ infer-ifte ] "infer" set-word-property
 
index ed0e91268bda224439b46d8eb1c12a7d80aa0a95..7353d3afd6da4c0cdde93cd6c4b343a349738423 100644 (file)
@@ -39,6 +39,10 @@ USE: hashtables
 USE: generic
 USE: prettyprint
 
+! If this symbol is on, partial evalution of conditionals is
+! disabled.
+SYMBOL: inferring-base-case
+
 ! Word properties that affect inference:
 ! - infer-effect -- must be set. controls number of inputs
 ! expected, and number of outputs produced.
@@ -64,6 +68,7 @@ GENERIC: literal-value ( value -- obj )
 GENERIC: value= ( literal value -- ? )
 GENERIC: value-class ( value -- class )
 GENERIC: value-class-and ( class value -- )
+GENERIC: set-value-class ( class value -- )
 
 TRAITS: computed
 C: computed ( class -- value )
@@ -79,6 +84,8 @@ M: computed value-class ( value -- class )
     [ \ value-class get ] bind ;
 M: computed value-class-and ( class value -- )
     [ \ value-class [ class-and ] change ] bind ;
+M: computed set-value-class ( class value -- )
+    [ \ value-class set ] bind ;
 
 TRAITS: literal
 C: literal ( obj rstate -- value )
@@ -91,6 +98,8 @@ M: literal value-class ( value -- class )
     literal-value class ;
 M: literal value-class-and ( class value -- )
     value-class class-and drop ;
+M: literal set-value-class ( class value -- )
+    2drop ;
 
 : value-recursion ( value -- rstate )
     [ recursive-state get ] bind ;
@@ -98,7 +107,7 @@ M: literal value-class-and ( class value -- )
 : (ensure-types) ( typelist n stack -- )
     pick [
         3dup >r >r car r> r> vector-nth value-class-and
-        >r >r cdr r> succ r> (ensure-types)
+        >r >r cdr r> 1 + r> (ensure-types)
     ] [
         3drop
     ] ifte ;
@@ -131,9 +140,6 @@ M: literal value-class-and ( class value -- )
     d-in get [ value-class ] vector-map vector>list
     meta-d get [ value-class ] vector-map vector>list 2list ;
 
-: old-effect ( [ in-types out-types ] | [ in | out ] )
-    uncons car length >r length r> cons ;
-
 : <recursive-state> ( -- state )
     <namespace> [
         base-case off  effect entry-effect set
@@ -162,37 +168,6 @@ DEFER: apply-word
     #! quotations.
     [ apply-object ] each ;
 
-: raise ( [ in | out ] -- [ in | out ] )
-    uncons 2dup min tuck - >r - r> cons ;
-
-: new-effect ( [ in | out ] -- [ intypes outtypes ] )
-    uncons
-    swap [ drop object ] project
-    swap [ drop object ] project
-    2list ;
-
-: decompose ( first second -- solution )
-    #! Return a stack effect such that first*solution = second.
-    over [ [ ] [ ] ] = [
-        nip
-    ] [
-        swap old-effect swap old-effect
-        2dup 2car
-        2dup > [ "No solution to decomposition" throw ] when
-        swap - -rot 2cdr >r + r> cons raise new-effect
-    ] ifte ;
-
-: set-base ( [ in | out ] rstate -- )
-    #! Set the base case of the current word.
-    dup [
-        car cdr [
-            [ effect ] bind entry-effect get swap decompose
-            base-case set
-        ] bind
-    ] [
-        2drop
-    ] ifte ;
-
 : check-return ( -- )
     #! Raise an error if word leaves values on return stack.
     meta-r get vector-length 0 = [
index 168aae8fad957132a6759e127200e14de2b16a34..3b5bad573d49bc44947f6a66c46e7da19dbb44d3 100644 (file)
@@ -78,27 +78,16 @@ USE: prettyprint
 : no-effect ( word -- )
     "Unknown stack effect: " swap word-name cat2 throw ;
 
-: with-recursive-state ( word label quot -- )
-    >r
-    <recursive-state> [ recursive-label set ] extend dupd cons
-    recursive-state cons@
-    r> call ;
-
-: (with-block) ( label quot -- )
-    #! Call a quotation in a new namespace, and transfer
-    #! inference state from the outer scope.
-    swap >r [
-        dataflow-graph off
-        call
-        d-in get meta-d get meta-r get get-dataflow
-    ] with-scope
-    r> swap #label dataflow, [ node-label set ] bind
-    meta-r set meta-d set d-in set ;
-
 : with-block ( word label quot -- )
     #! Execute a quotation with the word on the stack, and add
     #! its dataflow contribution to a new block node in the IR.
-    over [ with-recursive-state ] (with-block) ;
+    over [
+        >r
+        <recursive-state> [ recursive-label set ] extend
+        dupd cons
+        recursive-state cons@
+        r> call
+    ] (with-block) ;
 
 : inline-compound ( word -- effect )
     #! Infer the stack effect of a compound word in the current
@@ -131,9 +120,6 @@ M: symbol (apply-word) ( word -- )
     #! Push word we're currently inferring effect of.
     recursive-state get car car ;
 
-: no-base-case ( word -- )
-    word-name " does not have a base case." cat2 throw ;
-
 : check-recursion ( -- )
     #! If at the location of the recursive call, we're taking
     #! more items from the stack than producing, we have a
@@ -147,32 +133,25 @@ M: symbol (apply-word) ( word -- )
     #! Handle a recursive call, by either applying a previously
     #! inferred base case, or raising an error. If the recursive
     #! call is to a local block, emit a label call node.
-    base-case over hash dup [
-        swap [ recursive-label get ] bind ( word effect label )
-        dup [
-            rot drop #call-label rot
-        ] [
-            drop #call swap
-        ] ifte (consume/produce)
+    [ get-base ] 2keep [ recursive-label get ] bind
+    dup [
+        ( word effect label )
+        nip #call-label
     ] [
-        2drop no-base-case
-    ] ifte ;
+        drop #call
+    ] ifte rot (consume/produce) ;
 
 : apply-word ( word -- )
     #! Apply the word's stack effect to the inferencer state.
-    dup recursive-state get assoc dup [
+    dup recursive-state get assoc [
         check-recursion recursive-word
     ] [
-        drop dup "infer-effect" word-property dup [
+        dup "infer-effect" word-property [
             apply-effect
         ] [
-            drop dup "no-effect" word-property [
-                no-effect
-            ] [
-                (apply-word)
-            ] ifte
-        ] ifte
-    ] ifte ;
+            (apply-word)
+        ] ifte*
+    ] ifte* ;
 
 : infer-call ( -- )
     [ general-list ] ensure-d
index 456636e5a4d91dd09033018348faafdb41cfa2b2..bd3d00dfd9e3daffbc69ac64b39deaa1aee620a0 100644 (file)
@@ -91,4 +91,7 @@ C: ansi-stream ( stream -- stream )
     #! ansi-bg - background color
     [ delegate set ] extend ;
 
-global [ [ <ansi-stream> ] smart-term-hook set ] bind
+IN: shells
+
+: ansi
+    stdio [ <ansi-stream> ] change tty ;
index 04b0457829adb1b8f6a68abd1cc640fee48a4aaf..df04ef1a40389ad6dd26b7d84ccca046aa26695e 100644 (file)
@@ -77,6 +77,3 @@ C: stdio-stream ( delegate -- stream )
     swap stdio get <prefix-stream> [
         stdio set call
     ] with-scope ; inline
-
-! Set this to a quotation in init code, depending on OS.
-SYMBOL: smart-term-hook
index e6172a2cd56d9af7930e26c0d881a023f28a3929..c81c43041334d67492d7feb9795b47f126ebf3fb 100644 (file)
@@ -48,7 +48,9 @@ GENERIC: fclose      ( stream -- )
     f swap fwrite-attr ;
 
 : fprint ( string stream -- )
-    tuck fwrite "\n" over fwrite fauto-flush ;
+    [ fwrite ] keep
+    [ "\n" swap fwrite ] keep
+    fauto-flush ;
 
 TRAITS: string-output-stream
 
index 5f5cbb82f35349e8a1a5acef2ad2236f039a22b9..1492a8d9d4921885653fd84d90a9a7732486a4b7 100644 (file)
@@ -85,5 +85,5 @@ M: win32-console-stream fwrite-attr ( string style stream -- )
 C: win32-console-stream ( stream -- stream )
     [ -11 GetStdHandle handle set delegate set ] extend ;
 
-global [ [ <win32-console-stream> ] smart-term-hook set ] bind
+global [ [ <win32-console-stream> ] smart-term-hook set ] bind
 
index 3463e8f4aceba0beb3e5ba89892fe6730f669462..e05f288cd9cc83a1bac313f92dccb796c15c4ba1 100644 (file)
@@ -126,7 +126,7 @@ DEFER: tree-contains?
     [ dupd = not ] subset nip ;
 
 : length ( list -- length )
-    0 swap [ drop succ ] each ;
+    0 swap [ drop 1 + ] each ;
 
 : prune ( list -- list )
     #! Remove duplicate elements.
@@ -168,7 +168,7 @@ M: cons = ( obj cons -- ? )
         2drop 0
     ] [
         over cons? [
-            pred >r uncons r> tuck
+            1 - >r uncons r> tuck
             cons-hashcode >r
             cons-hashcode r>
             bitxor
@@ -191,7 +191,7 @@ M: cons hashcode ( cons -- hash ) 4 cons-hashcode ;
 
 : head ( list n -- list )
     #! Return the first n elements of the list.
-    dup 0 > [ >r uncons r> pred head cons ] [ 2drop f ] ifte ;
+    dup 0 > [ >r uncons r> 1 - head cons ] [ 2drop f ] ifte ;
 
 : tail ( list n -- tail )
     #! Return the rest of the list, from the nth index onward.
index 0eff0791f213c9cbc52c606c836ef89e56ac6ad6..7b093f741b1e01964f4f2dbeb3a6f25b1973492b 100644 (file)
@@ -36,11 +36,11 @@ USE: math-internals
 ! Inverse hyperbolic functions:
 !    acosh asech asinh acosech atanh acoth
 
-: acosh dup sq pred sqrt + log ;
+: acosh dup sq 1 - sqrt + log ;
 : asech recip acosh ;
-: asinh dup sq succ sqrt + log ;
+: asinh dup sq 1 + sqrt + log ;
 : acosech recip asinh ;
-: atanh dup succ swap pred neg / log 2 / ;
+: atanh dup 1 + swap 1 - neg / log 2 / ;
 : acoth recip atanh ;
 : <=1 ( x -- ? ) dup complex? [ drop f ] [ abs 1 <= ] ifte ;
 : asin dup <=1 [ fasin ] [ i * asinh -i * ] ifte ;
index 6acdfe144ad0eb77a2192b525d9d08cea3de30d8..5d6179446315ee05296066f120557238f1842f72 100644 (file)
@@ -33,14 +33,14 @@ USE: kernel
     #!
     #! In order to compile, the code must produce as many values
     #! as it consumes.
-    tuck >r dup 0 <= [ r> 3drop ] [ pred slip r> times ] ifte ;
+    tuck >r dup 0 <= [ r> 3drop ] [ 1 - slip r> times ] ifte ;
     inline
 
 : (times) ( limit n quot -- )
     pick pick <= [
         3drop
     ] [
-        rot pick succ pick 3slip (times)
+        rot pick 1 + pick 3slip (times)
     ] ifte ; inline
 
 : times* ( n quot -- )
@@ -52,15 +52,15 @@ USE: kernel
     0 swap (times) ; inline
 
 : fac ( n -- n! )
-    1 swap [ succ * ] times* ;
+    1 swap [ 1 + * ] times* ;
 
 : 2times-succ ( #{ a b } #{ c d } -- z )
     #! Lexicographically add #{ 0 1 } to a complex number.
     #! If d + 1 == b, return #{ c+1 0 }. Otherwise, #{ c d+1 }.
-    2dup imaginary succ swap imaginary = [
-        nip real succ
+    2dup imaginary 1 + swap imaginary = [
+        nip real 1 +
     ] [
-        nip >rect succ rect>
+        nip >rect 1 + rect>
     ] ifte ; inline
 
 : 2times<= ( #{ a b } #{ c d } -- ? )
@@ -77,3 +77,15 @@ USE: kernel
     #! Apply a quotation to each pair of complex numbers
     #! #{ a b } such that a < w, b < h.
     0 swap (2times) ; inline
+
+: (repeat) ( i n quot -- )
+    pick pick >= [
+        3drop
+    ] [
+        [ swap >r call 1 + r> ] keep (repeat)
+    ] ifte ;
+
+: repeat ( n quot -- )
+    #! Execute a quotation n times. The loop counter is kept on
+    #! the stack, and ranges from 0 to n-1.
+    0 -rot (repeat) ;
index fa2306493ce4176d3698b87f4477edb8505e357e..6750d42facec7d6ab0debf4765329987f87490e6 100644 (file)
@@ -87,9 +87,6 @@ M: number = ( n n -- ? ) number= ;
 
 : sq dup * ; inline
 
-: pred 1 - ; inline
-: succ 1 + ; inline
-
 : neg 0 swap - ; inline
 : recip 1 swap / ; inline
 
index 2d669d5d955a4822c829c0f74f2b6246196b1e80..c1f6ca523e3d6592df0c050626eea52442aef9d9 100644 (file)
@@ -30,6 +30,7 @@ USE: hashtables
 USE: kernel
 USE: kernel-internals
 USE: lists
+USE: vectors
 
 ! Other languages have classes, objects, variables, etc.
 ! Factor has similar concepts.
@@ -50,8 +51,8 @@ USE: lists
 ! bind ( namespace quot -- ) executes a quotation with a
 ! namespace pushed on the namespace stack.
 
-: namestack ( -- ns ) 3 getenv ;
-: set-namestack ( ns -- ) 3 setenv ;
+: namestack ( -- ns ) 3 getenv ; inline
+: set-namestack ( ns -- ) 3 setenv ; inline
 
 : namespace ( -- namespace )
     #! Push the current namespace.
@@ -59,7 +60,7 @@ USE: lists
 
 : >n ( namespace -- n:namespace )
     #! Push a namespace on the namespace stack.
-    namestack cons set-namestack ; inline
+    >vector namestack cons set-namestack ; inline
 
 : n> ( n:namespace -- namespace )
     #! Pop the top of the namespace stack.
index 14d593a39e6959f09268d8e865b8f19b1a28f4ee..3a66b98189497f23cf41650fe18509a495d05421 100644 (file)
@@ -98,7 +98,7 @@ USE: words
     [ fixnum<=               " x y -- ? "                         [ [ fixnum fixnum ] [ boolean ] ] ]
     [ fixnum>                " x y -- ? "                         [ [ fixnum fixnum ] [ boolean ] ] ]
     [ fixnum>=               " x y -- ? "                         [ [ fixnum fixnum ] [ boolean ] ] ]
-    [ bignum=                " x y -- ? "                         [ [ fixnum fixnum ] [ boolean ] ] ]
+    [ bignum=                " x y -- ? "                         [ [ bignum bignum ] [ boolean ] ] ]
     [ bignum+                " x y -- x+y "                       [ [ bignum bignum ] [ bignum ] ] ]
     [ bignum-                " x y -- x-y "                       [ [ bignum bignum ] [ bignum ] ] ]
     [ bignum*                " x y -- x*y "                       [ [ bignum bignum ] [ bignum ] ] ]
index 313106d08c5d71eb3a7dcf1871947bd6e66c7e5a..312c45a75feb670730bf83184f902e85aefbac20 100644 (file)
@@ -34,14 +34,14 @@ USE: math
     dup dup neg bitand = ;
 
 : (random-int-0) ( n bits val -- n )
-    3dup - + pred 0 < [
+    3dup - + 1 < [
         2drop (random-int) 2dup swap mod (random-int-0)
     ] [
         nip nip
     ] ifte ;
 
 : random-int-0 ( max -- n )
-    succ dup power-of-2? [
+    1 + dup power-of-2? [
         (random-int) * -31 shift
     ] [
         (random-int) 2dup swap mod (random-int-0)
index 94d70a57ae652bcaba3cfdc962855841b38ee451..66664500c01e63b4bd53428e09a86df5f82d656a 100644 (file)
@@ -111,7 +111,7 @@ SYMBOL: line-editor
 
 : add-line ( text -- )
     lines get vector-push
-    lines get vector-length succ first-line get - visible-lines -
+    lines get vector-length 1 + first-line get - visible-lines -
     dup 0 >= [
         first-line [ + ] change
     ] [
@@ -198,7 +198,7 @@ M: backspace-key key-down ( key -- )
     line-editor get dup sbuf-length 0 = [
         drop
     ] [
-        [ sbuf-length pred ] keep set-sbuf-length
+        [ sbuf-length 1 - ] keep set-sbuf-length
     ] ifte ;
 
 M: integer key-down ( key -- )
@@ -250,7 +250,9 @@ M: alien handle-event ( event -- ? )
 
 SYMBOL: escape-continuation
 
-: start-console ( -- )
+IN: shells
+
+: sdl ( -- )
     <namespace> [
         800 600 32 SDL_HWSURFACE init-screen
         init-console
index fbaf8c14242ae1a2cdc552e9ddc2810f5d41fdd3..23a953d706af62f78e84ae121df98f02aa7c7952 100644 (file)
@@ -14,9 +14,9 @@ USE: namespaces
 USE: vectors
 
 : f_ ( h s v i -- f ) >r swap rot >r 2dup r> 6 * r> - ;
-: p ( v s x -- v p x ) >r dupd neg succ * r> ;
-: q ( v s f -- q ) * neg succ * ;
-: t_ ( v s f -- t_ ) neg succ * neg succ * ;
+: p ( v s x -- v p x ) >r dupd neg 1 + * r> ;
+: q ( v s f -- q ) * neg 1 + * ;
+: t_ ( v s f -- t_ ) neg 1 + * neg 1 + * ;
 
 : mod-cond ( p vector -- )
     #! Call p mod q'th entry of the vector of quotations, where
index 6b4fda404ac019f929b1eb6058e67bb052c95138..27cf3b94693951afdc3b00c4dcf7b2ca2569cc7a 100644 (file)
@@ -96,7 +96,7 @@ UNION: text string integer ;
     #! Returns 2 strings, that when concatenated yield the
     #! original string, without the character at the given
     #! index.
-    [ swap str-head ] 2keep succ swap str-tail ;
+    [ swap str-head ] 2keep 1 + swap str-tail ;
 
 : str-head? ( str begin -- ? )
     2dup str-length< [
index a5832180cda14741e31b6ccdcf4b543569e2b07e..2c84fa87d92ad4bac9792bcb40bf7d7f80ee4a23 100644 (file)
@@ -42,7 +42,7 @@ USE: strings
 
 : next-line ( -- str )
     "parse-stream" get freadln
-    "line-number" [ succ ] change ;
+    "line-number" [ 1 + ] change ;
 
 : (read-lines) ( quot -- )
     next-line dup [
index 9b81047823e102ef7e3f8570f51969bccd2a049f..4322ea64ecb3fe8569f54601f37a08c95b7222a8 100644 (file)
@@ -66,7 +66,7 @@ USE: unparser
     "line" off "col" off ;
 
 : ch ( -- ch ) "col" get "line" get str-nth ;
-: advance ( -- ) "col" [ succ ] change ;
+: advance ( -- ) "col" [ 1 + ] change ;
 
 : skip ( n line quot -- n )
     #! Find the next character that satisfies the quotation,
@@ -75,7 +75,7 @@ USE: unparser
         2dup str-nth r> dup >r call [
             r> 2drop
         ] [
-            >r succ r> r> skip
+            >r 1 + r> r> skip
         ] ifte
     ] [
         r> drop nip str-length
@@ -101,7 +101,7 @@ USE: unparser
     dup >r skip-blank dup r>
     2dup str-length < [
         2dup str-nth denotation? [
-            drop succ
+            drop 1 +
         ] [
             skip-word
         ] ifte
@@ -159,7 +159,7 @@ USE: unparser
     "col" get "line" get rot index-of* ;
 
 : (until) ( index -- str )
-    "col" get swap dup succ "col" set "line" get substring ;
+    "col" get swap dup 1 + "col" set "line" get substring ;
 
 : until ( ch -- str )
     ch-search (until) ;
index a6f15114ac01fca2e84589a6afb98f6b467f1c3e..2120f31a1d92839994b77718271829c9ba42d04e 100644 (file)
@@ -40,6 +40,8 @@ USE: vectors
 USE: words
 USE: hashtables
 
+SYMBOL: prettyprint-limit
+
 GENERIC: prettyprint* ( indent obj -- indent )
 
 M: object prettyprint* ( indent obj -- indent )
@@ -49,10 +51,6 @@ M: object prettyprint* ( indent obj -- indent )
     #! Change this to suit your tastes.
     4 ;
 
-: prettyprint-limit ( -- limit )
-    #! Avoid infinite loops -- maximum indent, 10 levels.
-    "prettyprint-limit" get [ 40 ] unless* ;
-
 : indent ( indent -- )
     #! Print the given number of spaces.
     " " fill write ;
@@ -64,7 +62,7 @@ M: object prettyprint* ( indent obj -- indent )
     " " write ;
 
 : prettyprint-element ( indent obj -- indent )
-    over prettyprint-limit >= [
+    over prettyprint-limit get >= [
         unparse write
     ] [
         prettyprint*
@@ -186,7 +184,7 @@ M: hashtable prettyprint* ( indent hashtable -- indent )
 : . ( obj -- )
     [
         "prettyprint-single-line" on
-        tab-size 4 * "prettyprint-limit" set
+        16 prettyprint-limit set
         prettyprint
     ] with-scope ;
 
@@ -207,3 +205,5 @@ M: hashtable prettyprint* ( indent hashtable -- indent )
 : .b >bin print ;
 : .o >oct print ;
 : .h >hex print ;
+
+global [ 40 prettyprint-limit set ] bind
index fde6db2df03af18dad216bbd935c933ed0e93137..5b7276de89b252041c75668e851766bbdf35e0c9 100644 (file)
@@ -37,15 +37,24 @@ USE: unparser
 USE: words
 
 ! Prettyprinting words
-: vocab-attrs ( word -- attrs )
-    vocab-link "object-link" default-style acons ;
+: vocab-actions ( search -- list )
+    [
+        [ "Words"   | "words."        ]
+        [ "Use"     | "\"use\" cons@" ]
+        [ "In"      | "\"in\" set" ]
+    ] ;
+
+: vocab-attrs ( vocab -- attrs )
+    #! Words without a vocabulary do not get a link or an action
+    #! popup.
+    unparse vocab-actions <actions> "actions" swons unit ;
 
 : prettyprint-vocab ( vocab -- )
     dup vocab-attrs write-attr ;
 
-: prettyprint-IN: ( indent word -- )
+: prettyprint-IN: ( word -- )
     \ IN: prettyprint* prettyprint-space
-    word-vocabulary prettyprint-vocab prettyprint-newline ;
+    word-vocabulary prettyprint-vocab prettyprint-space ;
 
 : prettyprint-: ( indent -- indent )
     \ : prettyprint* prettyprint-space
@@ -95,19 +104,22 @@ M: object see ( obj -- )
     "Not a word: " write . ;
 
 M: compound see ( word -- )
-    0 swap
-    [ dupd prettyprint-IN: prettyprint-: ] keep
+    [ prettyprint-IN: ] keep
+    0 prettyprint-: swap
     [ prettyprint-1 ] keep
     [ prettyprint-docs ] keep
     [ word-parameter prettyprint-list prettyprint-; ] keep
     prettyprint-plist prettyprint-newline ;
 
 M: primitive see ( word -- )
-    "PRIMITIVE: " write dup unparse write stack-effect. terpri ;
+    dup prettyprint-IN:
+    "PRIMITIVE: " write dup prettyprint-1 stack-effect. terpri ;
 
 M: symbol see ( word -- )
-    0 over prettyprint-IN:
+    dup prettyprint-IN:
+    0 swap
     \ SYMBOL: prettyprint-1 prettyprint-space . ;
 
 M: undefined see ( word -- )
-    drop "Not defined" print ;
+    dup prettyprint-IN:
+    \ DEFER: prettyprint-1 prettyprint-space . ;
index c77bf13c56f02fb66bf1dd1779a51cff0c5d6e71..16e013b37707b8c03029a3b8f3b163b8a9c8da46 100644 (file)
@@ -41,7 +41,7 @@ GENERIC: unparse ( obj -- str )
 M: object unparse ( obj -- str )
     [
         "#<" ,
-        dup type type-name ,
+        dup class unparse ,
         " @ " , 
         address unparse ,
         ">" ,
@@ -51,10 +51,10 @@ M: object unparse ( obj -- str )
     dup 10 < [ CHAR: 0 + ] [ 10 - CHAR: a + ] ifte ;
 
 : integer, ( num radix -- )
-    tuck /mod >digit , dup 0 > [
-        swap integer,
+    dup >r /mod >digit , dup 0 > [
+        r> integer,
     ] [
-        2drop
+        r> 2drop
     ] ifte ;
 
 : >base ( num radix -- string )
index 2f22ea1a4029866c90add3bf85b3a76f265520c8..51632cf84828bbad7dcf5a7f2e79f42a432b1b3d 100644 (file)
@@ -7,12 +7,12 @@ USE: test
 
 : ack ( m n -- x )
     over 0 = [
-        nip succ
+        nip 1 +
     ] [
         dup 0 = [
-            drop pred 1 ack
+            drop 1 - 1 ack
         ] [
-            dupd pred ack >r pred r> ack
+            dupd 1 - ack >r 1 - r> ack
         ] ifte
     ] ifte ; compiled
 
index c72c123d3d70d8f935b46145d6de4d658780fefc..13f6f14379a69dc0ca64582bb7457a18e97d85ff 100644 (file)
@@ -4,6 +4,6 @@ USE: test
 USE: compiler
 
 : fac-benchmark
-    10000 fac 10000 [ succ / ] times* ; compiled
+    10000 fac 10000 [ 1 + / ] times* ; compiled
 
 [ 1 ] [ fac-benchmark ] unit-test
index 2ece5d2111f1a515dcbdffb12585979c21ed6038..48cfede1cafa4b3ab3fe7b56c2312005e9a8df77 100644 (file)
@@ -5,7 +5,7 @@ USE: math
 USE: test
 
 : fib ( n -- nth fibonacci number )
-    dup 1 <= [ drop 1 ] [ pred dup fib swap pred fib + ] ifte ;
+    dup 1 <= [ drop 1 ] [ 1 - dup fib swap 1 - fib + ] ifte ;
     compiled
 
 [ 9227465 ] [ 34 fib ] unit-test
index 986387bab21773c43df9ec810ab6a42064a29eef..bf12d7390e04bd5d4c7ccd2320abd4d448f5a376 100644 (file)
@@ -11,7 +11,7 @@ USE: compiler
     2dup str-length > [
         dup [ "123" , , "456" , , "789" , ] make-string
         dup dup str-length 2 /i 0 swap rot substring
-        swap dup str-length 2 /i succ 1 swap rot substring cat2
+        swap dup str-length 2 /i 1 + 1 swap rot substring cat2
         string-step
     ] [
         2drop
index 22a50a65fc3a667f71bb8cfe31fdaa7300df714a..f7137aeac46c41dc7c0b4d33b3ce93357944ab4d 100644 (file)
@@ -9,7 +9,7 @@ USE: test
 : callcc1-test ( x -- list )
     [
         "test-cc" set [ ] [
-            swap pred tuck swons
+            swap 1 - tuck swons
             over 0 = [ "test-cc" get call ] when
         ] forever
     ] callcc1 nip ;
index ec395c7616b52d5ed1e92d5869b5c31f92dabc32..1de418a356e2b08c5a0b29ec30199ece63f8b987 100644 (file)
@@ -79,7 +79,7 @@ SYMBOL: #test
     {{
         [ node-op | #test ]
         [ node-param | 5 ]
-    }} "foobar" [ [ node-param get ] bind succ ] apply-dataflow
+    }} "foobar" [ [ node-param get ] bind 1 + ] apply-dataflow
 ] unit-test
 
 #test [ [ node-param get ] bind sq ] "foobar" set-word-property
@@ -88,7 +88,7 @@ SYMBOL: #test
     {{
         [ node-op | #test ]
         [ node-param | 5 ]
-    }} "foobar" [ [ node-param get ] bind succ ] apply-dataflow
+    }} "foobar" [ [ node-param get ] bind 1 + ] apply-dataflow
 ] unit-test
 
 ! Somebody (cough) got the order of ifte nodes wrong.
index 09696199a51e642b0f79f9c5a5ecfe8a79d0971a..13b9c2ab54517b513ce9fb51f19f0e06c5bbc78f 100644 (file)
@@ -215,11 +215,11 @@ SYMBOL: sym-test
 
 ! Type inference
 
-[ [ [ object ] [ ] ] ] [ [ drop ] infer ] unit-test
-[ [ [ object ] [ object object ] ] ] [ [ dup ] infer ] unit-test
-[ [ [ object object ] [ cons ] ] ] [ [ cons ] infer ] unit-test
-[ [ [ cons ] [ cons ] ] ] [ [ uncons cons ] infer ] unit-test
-[ [ [ object ] [ object ] ] ] [ [ dup [ car ] when ] infer ] unit-test
+[ [ [ object ] [ ] ] ] [ [ drop ] infer ] unit-test
+[ [ [ object ] [ object object ] ] ] [ [ dup ] infer ] unit-test
+[ [ [ object object ] [ cons ] ] ] [ [ cons ] infer ] unit-test
+[ [ [ cons ] [ cons ] ] ] [ [ uncons cons ] infer ] unit-test
+[ [ [ object ] [ object ] ] ] [ [ dup [ car ] when ] infer ] unit-test
 ! [ [ [ vector ] [ vector ] ] ] [ [ vector-clone ] infer ] unit-test
 ! [ [ [ number ] [ number ] ] ] [ [ dup + ] infer ] unit-test
 ! [ [ [ number number number ] [ number ] ] ] [ [ digit+ ] infer ] unit-test
index 177bd87fbea1ebb373f1a9e3a5d12638f963654e..a4247dfef6875d8af5f3787c407e1a412d076a25 100644 (file)
@@ -83,7 +83,7 @@ unit-test
 
 [ 4 ] [
     0 "There are Four Upper Case characters"
-    [ LETTER? [ succ ] when ] str-each
+    [ LETTER? [ 1 + ] when ] str-each
 ] unit-test
 
 [ "Replacing+spaces+with+plus" ]
index e04efbbffff4ba1854d6a4d57c05fb91e5a4a925..5757e6213d861a4dfbedcc72a4ce5f332ed4f737 100644 (file)
@@ -55,7 +55,7 @@ USE: unparser
 
 : test ( name -- )
     ! Run the given test.
-    depth pred >r
+    depth 1 - >r
     "Testing " write dup write "..." print
     "/library/test/" swap ".factor" cat3 run-resource
     "Checking before/after depth..." print
index 1e14440fc6c552b64313f9133c3fe2d7afb47bd1..3c3931c0aabd3c331090095b93f225b0fd3a12fd 100644 (file)
@@ -63,7 +63,7 @@ USE: generic
     "Type check error" print
     uncons car dup "Object: " write .
     "Object type: " write class .
-    "Expected type: " write type-name print ;
+    "Expected type: " write builtin-type . ;
 
 : range-error ( list -- )
     "Range check error" print
index f5c9cab4710c30428a47d6d654119a7aaaeb1c81..a8ab447470425a5bb66ca204ff35b46577e4dd9b 100644 (file)
@@ -48,4 +48,4 @@ USE: generic
 
 : heap-stats. ( -- )
     #! Print heap allocation breakdown.
-    0 heap-stats [ dupd uncons heap-stat. succ ] each drop ;
+    0 heap-stats [ dupd uncons heap-stat. 1 + ] each drop ;
index 9b7684d6980cbfd40e32da8e3d94f4c8a8f39c4c..625dbc07e5b0eacf440d9f8abdc18c529a3faba9 100644 (file)
@@ -38,6 +38,7 @@ USE: presentation
 USE: words
 USE: unparser
 USE: vectors
+USE: ansi
 
 SYMBOL: cont-prompt
 SYMBOL: listener-prompt
@@ -143,3 +144,8 @@ global [
     terpri
     "HTTP SERVER:             USE: httpd 8888 httpd" print
     "TELNET SERVER:           USE: telnetd 9999 telnetd" print ;
+
+IN: shells
+
+: tty
+    print-banner listener ;
index a691ca5399aafda51b1b327340918f2716959804..95e146993b6a7a097e57489768620bda79ab116b 100644 (file)
@@ -34,6 +34,7 @@ USE: namespaces
 USE: stdio
 USE: streams
 USE: threads
+USE: parser
 
 : telnet-client ( socket -- )
     dup [
@@ -52,3 +53,10 @@ USE: threads
     [
         <server> [ telnetd-loop ] [ swap fclose rethrow ] catch
     ] with-logging ;
+
+IN: shells
+
+: telnet
+    "telnetd-port" get str>number telnetd ;
+
+global [ 9999 "telnetd-port" set ] bind
index a30d9ac760c4a7ce07bae8ce895272293caebc2c..aec6b8404239adec96c11810ca17ab5707e6ae32 100644 (file)
@@ -75,11 +75,11 @@ BUILTIN: vector 11
 
 : vector-peek ( vector -- obj )
     #! Get value at end of vector.
-    dup vector-length pred swap vector-nth ;
+    dup vector-length 1 - swap vector-nth ;
 
 : vector-pop ( vector -- obj )
     #! Get value at end of vector and remove it.
-    dup vector-length pred ( vector top )
+    dup vector-length 1 - ( vector top )
     2dup swap vector-nth >r swap set-vector-length r> ;
 
 : >pop> ( stack -- stack )
index d659eb73b42b4646f3b1c78de978fa9fe3e3c101..086698f9bafdbc6ad203403696d63681bb6a639b 100644 (file)
@@ -1,5 +1,6 @@
 #ifndef WIN32
 void signal_handler(int signal, siginfo_t* siginfo, void* uap);
+void dump_stack_signal(int signal, siginfo_t* siginfo, void* uap);
 void call_profiling_step(int signal, siginfo_t* siginfo, void* uap);
 void init_signals(void);
 #endif
index 1f6d3e7a88f8d7f30fb8bf3f29f3479276fb2d19..8e89917dd1c69538d5b0081420fea0230c1e2e1f 100644 (file)
@@ -15,11 +15,17 @@ void fix_stacks(void)
        if(STACK_UNDERFLOW(ds,ds_bot))
                reset_datastack();
        else if(STACK_OVERFLOW(ds,ds_bot))
+       {
+               fprintf(stderr,"ds oveflow\n");
                reset_datastack();
+       }
        else if(STACK_UNDERFLOW(cs,cs_bot))
                reset_callstack();
        else if(STACK_OVERFLOW(cs,cs_bot))
+       {
+               fprintf(stderr,"cs oveflow\n");
                reset_callstack();
+       }
 }
 
 void init_stacks(void)
index f101c6fa3e1ecaa510a10f645b178b7668258bdc..41d3f489ba4a63c18d709fdc05846d8abba13151 100644 (file)
@@ -15,6 +15,11 @@ void signal_handler(int signal, siginfo_t* siginfo, void* uap)
                signal_error(signal);
 }
 
+void dump_stack_signal(int signal, siginfo_t* siginfo, void* uap)
+{
+       dump_stacks();
+}
+
 /* Called from a signal handler. XXX - is this safe? */
 void call_profiling_step(int signal, siginfo_t* siginfo, void* uap)
 {
@@ -36,10 +41,13 @@ void init_signals(void)
        struct sigaction custom_sigaction;
        struct sigaction profiling_sigaction;
        struct sigaction ign_sigaction;
+       struct sigaction dump_sigaction;
        custom_sigaction.sa_sigaction = signal_handler;
        custom_sigaction.sa_flags = SA_SIGINFO;
        profiling_sigaction.sa_sigaction = call_profiling_step;
        profiling_sigaction.sa_flags = SA_SIGINFO;
+       dump_sigaction.sa_sigaction = dump_stack_signal;
+       dump_sigaction.sa_flags = SA_SIGINFO;
        ign_sigaction.sa_handler = SIG_IGN;
        sigaction(SIGABRT,&custom_sigaction,NULL);
        sigaction(SIGFPE,&custom_sigaction,NULL);
@@ -47,6 +55,7 @@ void init_signals(void)
        sigaction(SIGSEGV,&custom_sigaction,NULL);
        sigaction(SIGPIPE,&ign_sigaction,NULL);
        sigaction(SIGPROF,&profiling_sigaction,NULL);
+       sigaction(SIGQUIT,&dump_sigaction,NULL);
 }
 
 void primitive_call_profiling(void)