]> gitweb.factorcode.org Git - factor.git/commitdiff
new files vocab, dissolved builtins vocab, moved tutorial programs to doc/tutorial/
authorSlava Pestov <slava@factorcode.org>
Sat, 28 Aug 2004 20:43:43 +0000 (20:43 +0000)
committerSlava Pestov <slava@factorcode.org>
Sat, 28 Aug 2004 20:43:43 +0000 (20:43 +0000)
32 files changed:
README.SRC.txt
TODO.FACTOR.txt
build.xml
doc/tutorial/numbers-game.factor [new file with mode: 0644]
doc/tutorial/timesheet.factor [new file with mode: 0644]
factor/FactorInterpreter.java
factor/FactorReader.java
library/cross-compiler.factor
library/files.factor [new file with mode: 0644]
library/httpd/file-responder.factor
library/httpd/quit-responder.factor
library/init.factor
library/logic.factor
library/platform/jvm/boot-sumo.factor
library/platform/jvm/boot.factor
library/platform/jvm/cross-compiler.factor
library/platform/jvm/init.factor
library/platform/jvm/parser.factor
library/platform/jvm/stack2.factor
library/platform/jvm/stream.factor
library/platform/jvm/strings.factor
library/platform/jvm/test.factor
library/platform/native/boot-stage2.factor
library/platform/native/debugger.factor
library/platform/native/parse-syntax.factor
library/platform/native/profiler.factor
library/platform/native/random.factor
library/platform/native/vocabularies.factor
library/stdio.factor
library/test/files.factor [new file with mode: 0644]
library/test/test.factor
library/vocabularies.factor

index 731db554efdb3a5971d20298356dfb087afad06b..50e0f76a38ae0943ab0bbe89fd1fe8b4c0be554d 100644 (file)
@@ -16,8 +16,8 @@ inspection of source code, as well as stack effect checking.
 build.xml - Ant buildfile for Java interpreter.
 factor/ - source code for Factor interpreter written in Java.
 org/objectweb/asm/ - helper library for Java interpreter.
-Factor.jar - compiled, stand-alone Java interpreter
 library/platform/jvm - JVM-specific Factor code
+Factor.jar - compiled, stand-alone Java interpreter
 
 C interpreter
 -------------
@@ -27,21 +27,27 @@ of achieving the highest possible flexibility/lines of code
 ratio. It runs faster than the Java interpreter, and uses
 far less memory.
 
+Makefile - Makefile for building C interpreter.
 native/ - source code for Factor interpreter written in C.
-native/build.sh - build script for C interpreter.
-native/f - compiled C interpreter - needs image to run
-native/factor.image - cross-compiler output
 library/platform/native - C interpreter-specific code
+f - compiled C interpreter - needs image to run
+boot.image.le - image for x86
+boot.image.be - image for 32-bit SPARC and 32-bit PowerPC
 
 Notes on the C interpreter
 --------------------------
 
-At the moment it assumes little endian byte order, 32-bit
-words. This pretty much means x86.
+When you run the interpreter with a boot image, it loads a
+bunch of files and saves a 'factor.image'. Run the
+interpreter again with this image.
+
+At the moment it assumes a 32-bit architecture. Your C
+compiler's types must be as follows:
 
-Very soon I will add image input and output in both byte
-orders - this will allow Factor to run on powerpc and
-sparc.
+short - signed 16 bits
+long - signed 32 bits
+long long - signed 64 bits
+double -IEEE double precision 64-bit float
 
 Moving to 64-bits would require a few changes in the image
 cross-compiler, namely in the way it packs strings.
index 18833ec194e6a9615e9672b0dc304ba9d2e7bf16..d9587eda36c23797f8bfb8e7cf1913c85d9e200c 100644 (file)
@@ -58,6 +58,7 @@ to_c_string allots too much
 \r
 + native:\r
 \r
+- eliminate usage of long long\r
 - is the profiler using correct stack depth?\r
 - read1\r
 - sbuf-hashcode\r
@@ -82,7 +83,6 @@ to_c_string allots too much
 + misc:\r
 \r
 - alist -vs- assoc terminology\r
-- dissolve builtins vocabulary\r
 - 'cascading' styles\r
 - jedit ==> jedit-word, jedit takes a file name\r
 - some way to run httpd from command line\r
index 4ee51f03132a6f32e496279e7d71750f0f738809..0fdd9b1c2ea195044ed1e3256b6b4aaf4523126a 100644 (file)
--- a/build.xml
+++ b/build.xml
@@ -51,6 +51,7 @@
                                <include name="factor/**/*.txt"/>
                                <include name="*.xml"/>
                                <include name="library/**/*.factor"/>
+                               <include name="library/**/*.txt"/>
                                <include name="org/**/*.class"/>
                                <include name="*.factor"/>
                                <include name="doc/**/*.html"/>
diff --git a/doc/tutorial/numbers-game.factor b/doc/tutorial/numbers-game.factor
new file mode 100644 (file)
index 0000000..0cb72b4
--- /dev/null
@@ -0,0 +1,39 @@
+! Numbers game example
+
+IN: numbers-game
+USE: kernel
+USE: math
+USE: parser
+USE: random
+USE: stdio
+USE: stack
+
+: read-number ( -- n ) read parse-number ;
+
+: guess-banner
+    "I'm thinking of a number between 0 and 100." print ;
+: guess-prompt "Enter your guess: " write ;
+: too-high "Too high" print ;
+: too-low "Too low" print ;
+: correct "Correct - you win!" print ;
+
+: inexact-guess ( actual guess -- )
+     < [ too-high ] [ too-low ] ifte ;
+
+: judge-guess ( actual guess -- ? )
+    2dup = [
+        correct f
+    ] [
+        inexact-guess t
+    ] ifte ;
+
+: number-to-guess ( -- n ) 0 100 random-int ;
+
+: numbers-game-loop ( actual -- )
+    dup guess-prompt read-number judge-guess [
+        numbers-game-loop
+    ] [
+        drop
+    ] ifte ;
+
+: numbers-game number-to-guess numbers-game-loop ;
diff --git a/doc/tutorial/timesheet.factor b/doc/tutorial/timesheet.factor
new file mode 100644 (file)
index 0000000..e3803a7
--- /dev/null
@@ -0,0 +1,74 @@
+! Contractor timesheet example
+
+IN: timesheet
+USE: combinators
+USE: errors
+USE: format
+USE: kernel
+USE: lists
+USE: math
+USE: parser
+USE: stack
+USE: stdio
+USE: strings
+USE: unparser
+USE: vectors
+
+! Adding a new entry to the time sheet.
+
+: measure-duration ( -- duration )
+    millis
+    read drop
+    millis swap - 1000 /i 60 /i ;
+
+: add-entry-prompt ( -- duration description )
+    "Start work on the task now. Press ENTER when done." print
+    measure-duration
+    "Please enter a description:" print
+    read ;
+
+: add-entry ( timesheet -- )
+    add-entry-prompt cons swap vector-push ;
+
+! Printing the timesheet.
+
+: hh ( duration -- str ) 60 /i ;
+: mm ( duration -- str ) 60 mod unparse 2 digits ;
+: hh:mm ( millis -- str ) <% dup hh % ":" % mm % %> ;
+
+: print-entry ( duration description -- )
+    dup write
+    60 swap pad-string write
+    hh:mm print ;
+
+: print-timesheet ( timesheet -- )
+    "TIMESHEET:" print
+    [ uncons print-entry ] vector-each ;
+
+! Displaying a menu
+
+: print-menu ( menu -- )
+    terpri [ cdr car print ] each terpri
+    "Enter a letter between ( ) to execute that action." print ;
+
+: menu-prompt ( menu -- )
+    read swap assoc dup [
+        cdr call
+    ] [
+        "Invalid input: " swap unparse cat2 throw
+    ] ifte ;
+
+: menu ( menu -- )
+    dup print-menu menu-prompt ;
+
+! Main menu
+
+: main-menu ( timesheet -- )
+    [
+        [ "e" "(E)xit" drop ]
+        [ "a" "(A)dd entry" dup add-entry main-menu ]
+        [ "p" "(P)rint timesheet" dup print-timesheet main-menu ]
+    ] menu ;
+
+: timesheet-app ( -- )
+    10 <vector> main-menu ;
index cbd61c7d4a344faf26cdf81bf4fafd2b0c5517f9..796c0c4969b4da03329d132d98cd7828333d29d6 100644 (file)
@@ -35,7 +35,11 @@ import java.io.*;
 
 public class FactorInterpreter implements FactorObject, Runnable
 {
-       public static final String VERSION = "0.64";
+       public static final String VERSION = "0.65";
+
+       public static final Cons DEFAULT_USE = new Cons("builtins",
+               new Cons("syntax",new Cons("scratchpad",null)));
+       public static final String DEFAULT_IN = "scratchpad";
 
        // command line arguments are stored here.
        public Cons args;
@@ -63,18 +67,12 @@ public class FactorInterpreter implements FactorObject, Runnable
        /**
         * Vocabulary search path for interactive parser.
         */
-       public Cons use;
+       public Cons use = DEFAULT_USE;
 
        /**
         * Vocabulary to define new words in.
         */
-       public String in;
-
-       /**
-        * Kernel vocabulary. Re-created on each startup, contains
-        * primitives and parsing words.
-        */
-       public FactorNamespace builtins;
+       public String in = DEFAULT_IN;
 
        /**
         * Most recently defined word.
@@ -110,7 +108,6 @@ public class FactorInterpreter implements FactorObject, Runnable
                this.vocabularies = interp.vocabularies;
                this.use = interp.use;
                this.in = interp.in;
-               this.builtins = interp.builtins;
                this.last = interp.last;
                this.global = interp.global;
                this.startupDone = true;
@@ -148,73 +145,71 @@ public class FactorInterpreter implements FactorObject, Runnable
        //{{{ initBuiltinDictionary() method
        private void initBuiltinDictionary() throws Exception
        {
-               builtins = new FactorNamespace();
-               vocabularies.setVariable("builtins",builtins);
-
-               in = "builtins";
-               use = new Cons(in,null);
+               vocabularies.setVariable("builtins",new FactorNamespace());
+               vocabularies.setVariable("combinators",new FactorNamespace());
+               vocabularies.setVariable("syntax",new FactorNamespace());
 
                /* comments */
-               FactorWord lineComment = define("builtins","!");
+               FactorWord lineComment = define("syntax","!");
                lineComment.parsing = new LineComment(lineComment,false);
-               FactorWord stackComment = define("builtins","(");
+               FactorWord stackComment = define("syntax","(");
                stackComment.parsing = new StackComment(stackComment);
-               FactorWord docComment = define("builtins","#!");
+               FactorWord docComment = define("syntax","#!");
                docComment.parsing = new LineComment(docComment,true);
 
                /* strings */
-               FactorWord str = define("builtins","\"");
+               FactorWord str = define("syntax","\"");
                str.parsing = new StringLiteral(str,true);
-               FactorWord ch = define("builtins","CHAR:");
+               FactorWord ch = define("syntax","CHAR:");
                ch.parsing = new CharLiteral(ch);
 
                /* constants */
-               FactorWord t = define("builtins","t");
+               FactorWord t = define("syntax","t");
                t.parsing = new T(t);
-               FactorWord f = define("builtins","f");
+               FactorWord f = define("syntax","f");
                f.parsing = new F(f);
-               FactorWord complex = define("builtins","#{");
+               FactorWord complex = define("syntax","#{");
                complex.parsing = new ComplexLiteral(complex,"}");
 
                /* lists */
-               FactorWord bra = define("builtins","[");
+               FactorWord bra = define("syntax","[");
                bra.parsing = new Bra(bra);
-               FactorWord ket = define("builtins","]");
+               FactorWord ket = define("syntax","]");
                ket.parsing = new Ket(bra,ket);
-               FactorWord bar = define("builtins","|");
+               FactorWord bar = define("syntax","|");
                bar.parsing = new Bar(bar);
 
                /* vectors */
-               FactorWord beginVector = define("builtins","{");
+               FactorWord beginVector = define("syntax","{");
                beginVector.parsing = new BeginVector(beginVector);
-               FactorWord endVector = define("builtins","}");
+               FactorWord endVector = define("syntax","}");
                endVector.parsing = new EndVector(beginVector,endVector);
 
                /* word defs */
-               FactorWord def = define("builtins",":");
+               FactorWord def = define("syntax",":");
                def.parsing = new Def(def);
                def.getNamespace().setVariable("doc-comments",Boolean.TRUE);
-               FactorWord ine = define("builtins",";");
+               FactorWord ine = define("syntax",";");
                ine.parsing = new Ine(def,ine);
-               FactorWord shuffle = define("builtins","~<<");
+               FactorWord shuffle = define("syntax","~<<");
                shuffle.parsing = new Shuffle(shuffle,">>~");
 
                /* reading numbers with another base */
-               FactorWord bin = define("builtins","BIN:");
+               FactorWord bin = define("syntax","BIN:");
                bin.parsing = new Base(bin,2);
-               FactorWord oct = define("builtins","OCT:");
+               FactorWord oct = define("syntax","OCT:");
                oct.parsing = new Base(oct,8);
-               FactorWord hex = define("builtins","HEX:");
+               FactorWord hex = define("syntax","HEX:");
                hex.parsing = new Base(hex,16);
 
                /* vocabulary parsing words */
-               FactorWord noParsing = define("builtins","POSTPONE:");
+               FactorWord noParsing = define("syntax","POSTPONE:");
                noParsing.parsing = new NoParsing(noParsing);
-               FactorWord defer = define("builtins","DEFER:");
+               FactorWord defer = define("syntax","DEFER:");
                defer.parsing = new Defer(defer);
-               FactorWord in = define("builtins","IN:");
+               FactorWord in = define("syntax","IN:");
                in.parsing = new In(in);
-               FactorWord use = define("builtins","USE:");
+               FactorWord use = define("syntax","USE:");
                use.parsing = new Use(use);
 
                FactorWord interpreterGet = define("builtins","interpreter");
@@ -258,12 +253,12 @@ public class FactorInterpreter implements FactorObject, Runnable
                define.def = new Define(define);
 
                // combinators
-               FactorWord execute = define("builtins","execute");
+               FactorWord execute = define("words","execute");
                execute.def = new Execute(execute);
-               FactorWord call = define("builtins","call");
+               FactorWord call = define("combinators","call");
                call.def = new Call(call);
                call.inline = true;
-               FactorWord ifte = define("builtins","ifte");
+               FactorWord ifte = define("combinators","ifte");
                ifte.def = new Ifte(ifte);
                ifte.inline = true;
        } //}}}
@@ -289,7 +284,6 @@ public class FactorInterpreter implements FactorObject, Runnable
                        "args",
                        "dump",
                        "interactive",
-                       "builtins",
                        "in",
                        "last",
                        "use"
index 8a4f910bef243cd2116bb52bf8683ec79a1730b0..95485de782fb070a5e850fd111d30b66b2b97fc0 100644 (file)
@@ -38,10 +38,6 @@ import java.util.*;
  */
 public class FactorReader
 {
-       public static final Cons DEFAULT_USE = new Cons("builtins",
-               new Cons("scratchpad",null));
-       public static final String DEFAULT_IN = "scratchpad";
-
        private FactorInterpreter interp;
        private FactorScanner scanner;
        private Cons states;
@@ -265,8 +261,8 @@ public class FactorReader
                pushState(toplevel,null);
                this.alwaysDocComments = alwaysDocComments;
                this.interactive = interactive;
-               this.in = DEFAULT_IN;
-               this.use = DEFAULT_USE;
+               this.in = FactorInterpreter.DEFAULT_IN;
+               this.use = FactorInterpreter.DEFAULT_USE;
        } //}}}
 
        //{{{ getScanner() method
index 03193a2b63a33cb8c1f9fba0868ba3f5e70cecfc..895f06d55aa6f6d53519268813e6b226d9d7f6d6 100644 (file)
@@ -26,6 +26,7 @@
 ! ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
 IN: cross-compiler
+USE: combinators
 USE: kernel
 USE: lists
 USE: math
diff --git a/library/files.factor b/library/files.factor
new file mode 100644 (file)
index 0000000..d5026d5
--- /dev/null
@@ -0,0 +1,63 @@
+! :folding=indent:collapseFolds=1:
+
+! $Id$
+!
+! Copyright (C) 2004 Slava Pestov.
+! 
+! Redistribution and use in source and binary forms, with or without
+! modification, are permitted provided that the following conditions are met:
+! 
+! 1. Redistributions of source code must retain the above copyright notice,
+!    this list of conditions and the following disclaimer.
+! 
+! 2. Redistributions in binary form must reproduce the above copyright notice,
+!    this list of conditions and the following disclaimer in the documentation
+!    and/or other materials provided with the distribution.
+! 
+! THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
+! INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+! FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+! DEVELOPERS AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+! SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+! PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+! OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+! WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+! OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+! ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+IN: files
+USE: combinators
+USE: lists
+USE: namespaces
+USE: stack
+USE: strings
+
+: set-mime-types ( assoc -- )
+    "mime-types" global set* ;
+
+: mime-types ( -- assoc )
+    "mime-types" global get* ;
+
+: file-extension ( filename -- extension )
+    "." split cdr dup [ last ] when ;
+
+: mime-type ( filename -- mime-type )
+    file-extension mime-types assoc [ "text/plain" ] unless* ;
+
+[
+    [ "html"   | "text/html"                ]
+    [ "txt"    | "text/plain"               ]
+                                           
+    [ "gif"    | "image/gif"                ]
+    [ "png"    | "image/png"                ]
+    [ "jpg"    | "image/jpeg"               ]
+    [ "jpeg"   | "image/jpeg"               ]
+               
+    [ "jar"    | "application/octet-stream" ]
+    [ "zip"    | "application/octet-stream" ]
+    [ "tgz"    | "application/octet-stream" ]
+    [ "tar.gz" | "application/octet-stream" ]
+    [ "gz"     | "application/octet-stream" ]
+      
+    [ "factor" | "application/x-factor"     ]
+] set-mime-types
index 0b9c8c73336f74d66d8abdd5edb0c0a2da49b012..261139be3f8c0242295b3219a352d25d0fec07b8 100644 (file)
@@ -30,6 +30,7 @@ USE: combinators
 USE: html
 USE: kernel
 USE: lists
+USE: files
 USE: namespaces
 USE: parser
 USE: regexp
@@ -41,27 +42,6 @@ USE: strings
 USE: httpd
 USE: httpd-responder
 
-!!! Support words.
-: mime-types ( -- alist )
-    [
-        [  "html"   | "text/html"                ]
-        [  "txt"    | "text/plain"               ]
-                                                
-        [  "gif"    | "image/gif"                ]
-        [  "png"    | "image/png"                ]
-        [  "jpg"    | "image/jpeg"               ]
-        [  "jpeg"   | "image/jpeg"               ]
-                    
-        [  "jar"    | "application/octet-stream" ]
-        [  "zip"    | "application/octet-stream" ]
-        [  "tgz"    | "application/octet-stream" ]
-        [  "tar.gz" | "application/octet-stream" ]
-        [  "gz"     | "application/octet-stream" ]
-    ] ;
-
-: mime-type ( filename -- mime-type )
-    file-extension mime-types assoc [ "text/plain" ] unless* ;
-
 !!! Serving files.
 : file-header ( filename -- header )
     "200 Document follows" swap mime-type response ;
@@ -72,7 +52,7 @@ USE: httpd-responder
 !!! Serving directories.
 : file>html ( filename -- ... )
     "<li><a href=\"" swap
-    !dup directory? [ "/" cat2 ] when
+    ! dup directory? [ "/" cat2 ] when
     chars>entities
     "\">" over "</a></li>" ;
 
index 40c00069409ef9f96659efbe1eb2e864ab1e9c0d..cb77914d981c638d0a77f2890113d0ddee1d2a9a 100644 (file)
@@ -26,6 +26,7 @@
 ! ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
 IN: quit-responder
+USE: combinators
 USE: namespaces
 USE: stdio
 USE: stack
index 7bcdb1338deffe07da1e427c8d6f3c046f82d3d6..043ea075707d1b40cc5a926ef9dbe0c7de373172 100644 (file)
@@ -87,26 +87,10 @@ USE: words
     #! Parse command line arguments.
     parse-switches run-files ;
 
-: (word-of-the-day) ( -- word )
-    vocabs random-element words dup [
-        random-element
-    ] [
-        drop (word-of-the-day) ( empty vocab )
-    ] ifte ;
-
-: word-of-the-day ( -- )
-    #! Something to entertain the poor hacker.
-    (word-of-the-day) dup defined? [
-        "WORD OF THE DAY: " print see
-    ] [
-        drop word-of-the-day
-    ] ifte ;
-
 : init-interpreter ( -- )
     init-history
 
     print-banner
-    word-of-the-day
     room.
 
     interpreter-loop ;
index 60c953127ef96feeb4fdf7ba86f690dccee5ef13..db93b48b67c72864585d3d0f2ecf43f0b57d4684 100644 (file)
 ! OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
 ! ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
-IN: logic USE: kernel USE: stack
+IN: logic
+USE: combinators
+USE: kernel
+USE: stack
 
 : ? ( cond t f -- t/f )
     #! Push t if cond is true, otherwise push f.
index 38ab919c7bb5de8456f1fc8fd1d63e1677535207..f971951d841ca065b0a8e3cacd5bf2c31eea8fdd 100644 (file)
@@ -73,6 +73,7 @@ USE: parser
 "/library/styles.factor"                    run-resource ! styles
 "/library/platform/jvm/threads.factor"      run-resource ! threads
 "/library/logging.factor"                   run-resource ! logging
+"/library/files.factor"                     run-resource ! files
 
 !!! Math library.
 "/library/platform/jvm/real-math.factor" run-resource ! real-math
index 013573a9d5bc4cc918475f4f5a0c1b162353cc0d..f2891f0e4828f1490a73b0efffdcf485cc84092f 100644 (file)
@@ -28,6 +28,8 @@
 !!! Minimum amount of words needed to be able to read other
 !!! resources.
 
+USE: combinators
+
 IN: stack
 
 ~<< dup A -- A A >>~
index d81cf75cccf3708e6b4cb113f244527a117b118f..ebfb392b802f7b7aae8d00f7bdfc4e1ffb65d8c2 100644 (file)
@@ -26,6 +26,7 @@
 ! ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
 IN: cross-compiler
+USE: combinators
 USE: kernel
 USE: lists
 USE: math
index 9c84841413267e1a027a10d5b02422ad04bd1bb6..282b73f0874d058446470f45376de242d6338eb2 100644 (file)
@@ -83,4 +83,4 @@ USE: words
 
     t "startup-done" set
     
-    "interactive" get [ init-interpreter ] when ;
+    "interactive" get [ init-interpreter 1 exit* ] when ;
index 8755de0790dcb1c3c979ef2d3ba9e827d9170b7b..be49b87a94e2a09135d8288e8c4c43e4a8f27cb1 100644 (file)
@@ -26,6 +26,7 @@
 ! ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
 IN: parser
+USE: combinators
 USE: errors
 USE: namespaces
 USE: stack
index 417dfecef45f336e295622f6c05e205b9cfc24ac..c148d666874c7a2afe8f44fe0a4d04bca4cc69da 100644 (file)
@@ -26,6 +26,7 @@
 ! ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
 IN: stack
+USE: combinators
 USE: kernel
 USE: vectors
 
index c6f5ab3c664ccfbf3a7c86b6e0657c468306b956..5f2821a589311fecb14abf0aea16f1b7917b7d0b 100644 (file)
@@ -212,9 +212,6 @@ USE: strings
     [ "java.io.File" ] "java.io.File" "renameTo"
     jinvoke ;
 
-: file-extension ( filename -- extension )
-    ".*\\.(.*)" group1 ;
-
 : <sreader> ( string -- reader )
     [ "java.lang.String" ] "java.io.StringReader" jnew ;
 
index b93d9a72704bc880fdb37f2265229a6c8fd44281..1e037658f80dddddc3b28f0ad70f0d70a8be6eb1 100644 (file)
@@ -26,6 +26,7 @@
 ! ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
 IN: strings
+USE: combinators
 USE: kernel
 USE: logic
 USE: stack
index 2a4df6f9c3d6689539caa8cef965e7878a1995c2..4302ab67cd1504e6de48a4a662f2fb8ce21cc93f 100644 (file)
@@ -1,4 +1,5 @@
 IN: test
+USE: combinators
 USE: compiler
 USE: namespaces
 USE: stdio
index be1de3629f1c022f9e6433d51382866c1d50655c..89984a5b3e6f177c80acca4e5b4771538057aa4e 100644 (file)
@@ -98,6 +98,7 @@ USE: stdio
     "/library/random.factor"
     "/library/stdio-binary.factor"
     "/library/platform/native/prettyprint.factor"
+    "/library/files.factor"
     "/library/interpreter.factor"
     "/library/inspector.factor"
     "/library/inspect-vocabularies.factor"
index 0f4699ef38bb00da4b4507bd0389d288902020f8..daa368480c1cc5c3ae6da2800a8eca2a5c036cab 100644 (file)
@@ -39,6 +39,7 @@ USE: stdio
 USE: strings
 USE: unparser
 USE: vectors
+USE: words
 
 : expired-port-error ( obj -- )
     "Expired port: " write . ;
index a0972c98091dee9c0c19c3ed72d67a196da3e858..8ab770adf721a25e953b1b1361f596533787f7d1 100644 (file)
@@ -27,7 +27,7 @@
 
 ! Parsing words. 'builtins' is a stupid vocabulary name now
 ! that it does not contain Java words anymore!
-IN: builtins
+IN: syntax
 
 USE: combinators
 USE: cross-compiler
index aab8b89ed6f4380e9cb04b15a759c4cf1297090d..199a411314bc34459ada6f8e7a666a4caec0d0ee 100644 (file)
@@ -26,6 +26,7 @@
 ! ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
 IN: profiler
+USE: combinators
 USE: kernel
 USE: lists
 USE: math
index 1fc064de8954ef9e57ddc4037bf8c569a8d2df5c..1bfb2162eba50be35b329a5d83019791cc845871 100644 (file)
@@ -26,6 +26,7 @@
 ! ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
 IN: random
+USE: combinators
 USE: kernel
 USE: math
 USE: stack
index e9030a896bc80dfe4b9f4efdc07aed05496b5cb5..7b222e7e651ae64b74aef77dc0c6428acffc1d8c 100644 (file)
@@ -26,6 +26,7 @@
 ! ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
 IN: words
+USE: combinators
 USE: lists
 USE: namespaces
 USE: stack
index 55a6b5c86c4656050714b5fa495fb5102b1ff0c8..cb4c273117e9fc2f508ab98867fcfdfeb967c146 100644 (file)
@@ -26,6 +26,7 @@
 ! ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
 IN: stdio
+USE: combinators
 USE: errors
 USE: kernel
 USE: namespaces
diff --git a/library/test/files.factor b/library/test/files.factor
new file mode 100644 (file)
index 0000000..fad63a7
--- /dev/null
@@ -0,0 +1,9 @@
+IN: scratchpad
+USE: files
+USE: test
+
+[ "txt" ] [ "foo.txt" file-extension ] unit-test
+[ f ] [ "foobar" file-extension ] unit-test
+[ "txt" ] [ "foo.bar.txt" file-extension ] unit-test
+[ "text/plain" ] [ "foo.bar.txt" mime-type ] unit-test
+[ "text/html" ] [ "index.html" mime-type ] unit-test
index d1584e1584c83b3f127a41ee75e671cb5b2e0f7a..65ee9ada209d478af202e0faf3c3e34735c0e7bd 100644 (file)
@@ -73,6 +73,7 @@ USE: unparser
         "hashtables"
         "strings"
         "namespaces/namespaces"
+        "files"
         "format"
         "parser"
         "parse-number"
index cffac64c5e00e80325cde5d93248b5619570763d..db0ba4c93b68f0bfdcc427234a757af5548f28c8 100644 (file)
@@ -66,10 +66,10 @@ USE: strings
 
 : init-search-path ( -- )
     ! For files
-    "user" "file-in" set
-    [ "user" "builtins" ] "file-use" set
+    "scratchpad" "file-in" set
+    [ "builtins" "syntax" "scratchpad" ] "file-use" set
     ! For interactive
-    "user" "in" set
+    "scratchpad" "in" set
     [
         "user"
         "arithmetic"
@@ -95,6 +95,7 @@ USE: strings
         "streams"
         "stdio"
         "strings"
+        "syntax"
         "test"
         "threads"
         "trace"