]> gitweb.factorcode.org Git - factor.git/commitdiff
various cleanups, better memory signal handler
authorSlava Pestov <slava@factorcode.org>
Sun, 17 Oct 2004 23:01:16 +0000 (23:01 +0000)
committerSlava Pestov <slava@factorcode.org>
Sun, 17 Oct 2004 23:01:16 +0000 (23:01 +0000)
48 files changed:
Makefile
library/compiler/alien-types.factor
library/compiler/compiler.factor
library/cross-compiler.factor
library/inspect-vocabularies.factor
library/jedit/jedit.factor
library/namespaces.factor
library/platform/jvm/boot-mini.factor
library/platform/jvm/boot-sumo.factor
library/platform/jvm/namespaces.factor
library/platform/jvm/prettyprint.factor
library/platform/jvm/words.factor
library/platform/native/boot-stage2.factor
library/platform/native/boot.factor
library/platform/native/debugger.factor
library/platform/native/kernel.factor
library/platform/native/namespaces.factor
library/platform/native/network.factor
library/platform/native/prettyprint.factor
library/platform/native/stream.factor
library/platform/native/types.factor
library/platform/native/unparser.factor
library/platform/native/vocabularies.factor
library/platform/native/words.factor
library/stdio.factor
library/test/benchmark/continuations.factor [new file with mode: 0644]
library/test/benchmark/empty-loop.factor
library/test/benchmark/fac.factor
library/test/benchmark/fib.factor
library/test/benchmark/sort.factor
library/test/continuations.factor
library/test/crashes.factor
library/test/jvm-compiler/miscellaneous.factor
library/test/namespaces/java.factor
library/test/namespaces/namespaces.factor
library/test/prettyprint.factor
library/test/sbuf.factor
library/test/test.factor
library/test/unparser.factor
library/vocabularies.factor
native/error.c
native/error.h
native/factor.h
native/gc.c
native/run.c
native/run.h
native/signal.c [new file with mode: 0644]
native/signal.h [new file with mode: 0644]

index 1d5baee765284434081e0592b0b2e4a0f903575e..c49df74e8efab997b5c686c48ca75d561f9b3a52 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -16,7 +16,7 @@ OBJS = native/arithmetic.o native/array.o native/bignum.o \
        native/sbuf.o native/socket.o native/stack.o \
        native/string.o native/types.o native/vector.o \
        native/write.o native/word.o native/compiler.o \
-       native/ffi.o
+       native/ffi.o native/signal.o
 
 default:
        @echo "Run 'make' with one of the following parameters:"
index 98b32a1689bbe77bf12cbfcdc80c8e9e28f85774..83c2a4ebb0252136945ed615aae67f14c50d8083 100644 (file)
@@ -29,6 +29,7 @@ IN: alien
 USE: combinators
 USE: compiler
 USE: errors
+USE: hashtables
 USE: lists
 USE: math
 USE: namespaces
@@ -53,7 +54,7 @@ USE: words
 
 : c-type ( name -- type )
     global [
-        dup "c-types" get get* dup [
+        dup "c-types" get hash dup [
             nip
         ] [
             drop "No such C type: " swap cat2 throw
index 742d52588f5dbfe2db5a07c306f2b19945132a21..74b768b0afd71f37f1801a770917372bb6327903 100644 (file)
@@ -211,7 +211,7 @@ SYMBOL: compile-callstack
 
 : (compile) ( word -- )
     #! Should be called inside the with-compiler scope.
-    intern dup save-xt word-parameter compile-quot RET ;
+    dup save-xt word-parameter compile-quot RET ;
 
 : compile-postponed ( -- )
     compile-words get [
index 228b1e2b7b186ed988f94fd5d5a7bfb85a98bb99..53c90c64fac5f0c1061bb8bf5436285a9a4e4f70 100644 (file)
@@ -185,7 +185,7 @@ DEFER: word-plist
 DEFER: set-word-plist
 
 IN: unparser
-DEFER: unparse-float
+DEFER: (unparse-float)
 
 IN: image
 
@@ -230,7 +230,7 @@ IN: image
         denominator
         fraction>
         str>float
-        unparse-float
+        (unparse-float)
         float>bits
         real
         imaginary
index ec092ea78b769c5c593f454f2def5179fa8eb0b9..b5658b48fbac6da98fa8b3582fdc6dbf87abffda 100644 (file)
@@ -64,11 +64,7 @@ USE: unparser
 
 : usages. ( word -- )
     #! List all usages of a word in all vocabularies.
-    intern [
-        vocabs [ dupd usages-in-vocab. ] each drop
-    ] [
-        "Not defined" print
-    ] ifte* ;
+    vocabs [ dupd usages-in-vocab. ] each drop ;
 
 : vocab-apropos ( substring vocab -- list )
     #! Push a list of all words in a vocabulary whose names
index beb2580b3607e7984fb99d142d2ca1345abe4894..179d39bcb346f83f7376634c562da7dd1435ed6b 100644 (file)
@@ -67,12 +67,8 @@ USE: words
     word-file ;
 
 : jedit ( word -- )
-    intern dup [
-        word-line/file dup [
-            jedit-line/file
-        ] [
-            3drop "Unknown source" print
-        ] ifte
+    word-line/file dup [
+        jedit-line/file
     ] [
-        "Not defined" print
+        3drop "Unknown source" print
     ] ifte ;
index 23b3df9b459391a4bb0d0b5d81b7b74f561daf93..4c1cfc3083d5f5f7d3799e6c67d13301a2a63017 100644 (file)
@@ -65,10 +65,6 @@ USE: vectors
     #! Push the current namespace.
     namestack* vector-peek ; inline
 
-: bind ( namespace quot -- )
-    #! Execute a quotation with a namespace on the namestack.
-    swap namespace-of >n call n> drop ; inline
-
 : with-scope ( quot -- )
     #! Execute a quotation with a new namespace on the
     #! namestack.
@@ -97,7 +93,7 @@ USE: vectors
     #! An object path is a list of strings. Each string is a
     #! variable name in the object namespace at that level.
     #! Returns f if any of the objects are not set.
-    this swap (object-path) ;
+    namespace swap (object-path) ;
 
 : (set-object-path) ( name -- namespace )
     dup namespace get* dup [
index 8dce73547698b7f071bad402011cbd147a8c09fa..76a72ccc209c53fb2bd0358799293d1a91d73016 100644 (file)
@@ -69,6 +69,7 @@ USE: parser
 "/library/platform/jvm/stream.factor"       run-resource ! streams
 "/library/platform/jvm/files.factor"        run-resource ! files
 "/library/stdio.factor"                     run-resource ! stdio
+"/library/extend-stream.factor"             run-resource ! streams
 "/library/platform/jvm/unparser.factor"     run-resource ! unparser
 "/library/platform/jvm/parser.factor"       run-resource ! parser
 "/library/styles.factor"                    run-resource ! styles
index 4845e8125cef42e15fc8a0249111c48dd7509b70..9f98e574f89f2f1e0da5ec248814bc8ab9c53f35 100644 (file)
@@ -69,6 +69,7 @@ USE: parser
 "/library/platform/jvm/stream.factor"       run-resource ! streams
 "/library/platform/jvm/files.factor"        run-resource ! files
 "/library/stdio.factor"                     run-resource ! stdio
+"/library/extend-stream.factor"             run-resource ! streams
 "/library/platform/jvm/unparser.factor"     run-resource ! unparser
 "/library/platform/jvm/parser.factor"       run-resource ! parser
 "/library/styles.factor"                    run-resource ! styles
@@ -86,7 +87,6 @@ USE: parser
 
 !!! Development tools.
 "/library/platform/jvm/processes.factor"   run-resource ! processes
-"/library/extend-stream.factor"            run-resource ! streams
 "/library/stdio-binary.factor"             run-resource ! stdio
 "/library/vocabulary-style.factor"         run-resource ! style
 "/library/prettyprint.factor"              run-resource ! prettyprint
index eaa0c1b3f6cdabd12e4f11aeb88ff932be8a5fda..affc8e5f35b4e2678c579b066d3ac55205fcbd43 100644 (file)
@@ -34,6 +34,8 @@ USE: stack
 USE: strings
 
 DEFER: namespace
+DEFER: >n
+DEFER: n>
 
 : namestack* ( -- stack )
     #! Push the namespace stack.
@@ -96,6 +98,10 @@ DEFER: namespace
     [ "java.lang.Object" ] "factor.FactorJava" "toNamespace"
     jinvoke-static ;
 
+: bind ( namespace quot -- )
+    #! Execute a quotation with a namespace on the namestack.
+    swap namespace-of >n call n> drop ; inline
+
 : has-namespace? ( a -- boolean )
     "factor.FactorObject" is ; inline
 
index 3a74bcf3adbf3d3e7de0f7d9119ea0e20a984926..83d2335b0e2da94d8cb7998b9f8e60c68a7bba81 100644 (file)
@@ -57,7 +57,7 @@ USE: words
 
 : see ( word -- )
     0 swap
-    intern dup worddef
+    dup worddef
     [
         [ compound-or-compiled? ] [ word-parameter prettyprint-:; ]
         [ shuffle? ] [ word-parameter prettyprint-~<<>>~ ]
index b00b0caa842ab2493110fc4f84946b1b8b702274..b01cc5ba19a73daa0f1f1d2ad287395a366a0ef2 100644 (file)
@@ -33,10 +33,15 @@ USE: lists
 USE: logic
 USE: namespaces
 USE: stack
+USE: strings
 
 : worddef? ( obj -- boolean )
     "factor.FactorWordDefinition" is ;
 
+: intern ( "word" -- word )
+    #! Returns the top of the stack if it already been interned.
+    dup string? [ "use" get search ] when ;
+
 : worddef ( word -- worddef )
     dup worddef? [
         intern dup [ [ "def" get ] bind ] when
index a65a2f1ac95e1c2d86ffb922960164942dd789fd..9a0dfc5895bcab3b0a813bce496d7067d628ccd7 100644 (file)
@@ -68,6 +68,7 @@ USE: stdio
     "/library/platform/native/io-internals.factor"
     "/library/platform/native/stream.factor"
     "/library/stdio.factor"
+    "/library/extend-stream.factor"
     "/library/platform/native/words.factor"
     "/library/words.factor"
     "/library/platform/native/vocabularies.factor"
@@ -94,7 +95,6 @@ USE: stdio
     "/library/math/arc-trig-hyp.factor"
     "/library/math/list-math.factor"
 
-    "/library/extend-stream.factor"
     "/library/platform/native/in-thread.factor"
     "/library/platform/native/network.factor"
     "/library/logging.factor"
index b96d10d2e5fe5451231a5c22997e1baea0cb16b9..d63bc48561c28f7d91f79d8205aab0da1787c8c3 100644 (file)
@@ -61,6 +61,7 @@ primitives,
     "/library/platform/native/io-internals.factor"
     "/library/platform/native/stream.factor"
     "/library/stdio.factor"
+    "/library/extend-stream.factor"
     "/library/platform/native/words.factor"
     "/library/words.factor"
     "/library/platform/native/vocabularies.factor"
index 5a4d7b82959c165f0302e66c74eeb38532c41b02..e4f778cf1eef134662096a4f4f0b66e72cb944bd 100644 (file)
@@ -94,6 +94,18 @@ USE: words
 : ffi-error ( obj -- )
     "FFI: " write print ;
 
+: datastack-underflow-error ( obj -- )
+    drop "Datastack underflow" print ;
+
+: datastack-overflow-error ( obj -- )
+    drop "Datastack overflow" print ;
+
+: callstack-underflow-error ( obj -- )
+    drop "Callstack underflow" print ;
+
+: callstack-overflow-error ( obj -- )
+    drop "Callstack overflow" print ;
+
 : kernel-error. ( obj n -- str )
     {
         expired-error
@@ -111,6 +123,10 @@ USE: words
         c-string-error
         ffi-disabled-error
         ffi-error
+        datastack-underflow-error
+        datastack-overflow-error
+        callstack-underflow-error
+        callstack-overflow-error
     } vector-nth execute ;
 
 : kernel-error? ( obj -- ? )
index c20e9a29ce8017b8f914e07ed2338dbacb0da1a0..04ea348da69bdf2ec10d23ef6f632d99fa53d6cc 100644 (file)
@@ -32,18 +32,12 @@ DEFER: vector-hashcode
 IN: kernel
 
 USE: combinators
-USE: errors
-USE: io-internals
 USE: lists
-USE: logic
 USE: math
-USE: namespaces
 USE: stack
-USE: stdio
 USE: strings
 USE: vectors
 USE: words
-USE: unparser
 USE: vectors
 
 : cpu ( -- arch )
@@ -112,13 +106,6 @@ IN: kernel
     #! Test if a = c, b = d.
     swapd = [ = ] [ 2drop f ] ifte ;
 
-: clone ( obj -- obj )
-    [
-        [ vector? ] [ vector-clone ]
-        [ sbuf? ] [ sbuf-clone ]
-        [ drop t ] [ ( return the object ) ]
-    ] cond ;
-
 : set-boot ( quot -- )
     #! Set the boot quotation.
     8 setenv ;
index 09d33b1592af0d02be6cc86e3a6aa4cab3ff5685..9304a36849e1727c7a4b291cd0743a1182015e8c 100644 (file)
@@ -37,6 +37,7 @@ USE: vectors
 
 DEFER: namespace
 DEFER: >n
+DEFER: n>
 
 : namestack* ( -- ns ) 3 getenv ;
 : set-namestack* ( ns -- ) 3 setenv ;
@@ -58,8 +59,7 @@ DEFER: >n
     namespace-buckets <hashtable> ;
 
 : get* ( var namespace -- value ) hash ;
-: set*  ( value variable namespace -- ) set-hash ;
-: put* swapd set* ;
+: set* ( value variable namespace -- ) set-hash ;
 
 : namestack-search ( var n -- )
     #! Internal word for searching the namestack.
@@ -78,15 +78,16 @@ DEFER: >n
     #! from the top down.
     namestack* vector-length namestack-search ;
 
-: set ( value variable -- ) namespace set* ;
-: put ( variable value -- ) namespace put* ;
+: set ( value variable -- ) namespace set-hash ;
+: put ( variable value -- ) swap set ;
+
+: bind ( namespace quot -- )
+    #! Execute a quotation with a namespace on the namestack.
+    swap >n call n> drop ; inline
 
 : vars-values ( -- list ) namespace hash>alist ;
-: vars ( -- list ) vars-values [ car ] map ;
-: values ( -- list ) vars-values [ cdr ] map ;
+: vars ( -- list ) namespace hash-keys ;
+: values ( -- list ) namespace hash-values ;
 
 ! We don't have bound objects in native Factor.
-: namespace? hashtable? ;
-: namespace-of ;
-: this namespace ;
 : has-namespace? hashtable? ;
index 59975e50bb1079732017c256d2c10e5048f4d570..99bc281cd01aaa1901f0a2e1d9bff0c5204d59cc 100644 (file)
@@ -30,6 +30,7 @@ USE: combinators
 USE: continuations
 USE: io-internals
 USE: errors
+USE: hashtables
 USE: kernel
 USE: logic
 USE: stack
@@ -58,4 +59,4 @@ USE: unparser
 
 : accept ( server -- client )
     #! Accept a connection from a server socket.
-    "socket" swap get* blocking-accept <client-stream> ;
+    "socket" swap hash blocking-accept <client-stream> ;
index 61e46e3173e27813150d2d334ad67807ac300904..c720821d4787c9a8de860342215b9c667c590588 100644 (file)
@@ -74,7 +74,6 @@ USE: words
 
 : see ( name -- )
     #! Show a word definition.
-    intern
     [
         [ compound? ] [ see-compound ]
         [ symbol? ] [ see-symbol ]
index 3b6959d462de718cbc15e345bff43b5dada39a20..acca4d19d1e59904c7537101b8177fc3fcea32e4 100644 (file)
@@ -30,6 +30,7 @@ USE: combinators
 USE: continuations
 USE: io-internals
 USE: errors
+USE: hashtables
 USE: kernel
 USE: logic
 USE: stack
@@ -84,7 +85,7 @@ USE: namespaces
     #! Copy the contents of the fd-stream 'from' to the
     #! fd-stream 'to'. Use fcopy; this word does not close
     #! streams.
-    "out" swap get* >r "in" swap get* r> blocking-copy ;
+    "out" swap hash >r "in" swap hash r> blocking-copy ;
 
 : fcopy ( from to -- )
     #! Copy the contents of the fd-stream 'from' to the
index 793b8916d5ce5eb07e1be9d2a47933da4637741f..daf245bb31b4f6a7ff391f1fd309a5e9da4dbdd6 100644 (file)
@@ -72,5 +72,5 @@ IN: kernel
     ] assoc ;
 
 : num-types ( -- n )
-    #! One more than the maximum value from type-of.
+    #! One more than the maximum value from type primitive.
     17 ;
index f78dca2b3d1d98aad2ce099963bee78c9c3d7bb2..b64e58447863e8e7027900d4acacce7986b4d636 100644 (file)
@@ -60,21 +60,10 @@ USE: words
         integer%
     ] ifte reverse%> ;
 
-: >dec ( num -- string )
-    #! Convert an integer to its decimal representation.
-    10 >base ;
-
-: >bin ( num -- string )
-    #! Convert an integer to its binary representation.
-    2 >base ;
-
-: >oct ( num -- string )
-    #! Convert an integer to its octal representation.
-    8 >base ;
-
-: >hex ( num -- string )
-    #! Convert an integer to its hexadecimal representation.
-    16 >base ;
+: >dec ( num -- string ) 10 >base ;
+: >bin ( num -- string ) 2 >base ;
+: >oct ( num -- string ) 8 >base ;
+: >hex ( num -- string ) 16 >base ;
 
 DEFER: unparse
 
@@ -121,6 +110,8 @@ DEFER: unparse
     #! output.
     "." over str-contains? [ ".0" cat2 ] unless ;
 
+: unparse-float ( float -- str ) (unparse-float) fix-float ;
+
 : unparse-unknown ( obj -- str )
     <% "#<" %
     dup type type-name %
@@ -128,15 +119,26 @@ DEFER: unparse
     address unparse %
     ">" % %> ;
 
+: unparse-t drop "t" ;
+: unparse-f drop "f" ;
+
 : unparse ( obj -- str )
-    [
-        [ t eq?    ] [ drop "t" ]
-        [ f eq?    ] [ drop "f" ]
-        [ word?    ] [ unparse-word ]
-        [ integer? ] [ >dec ]
-        [ ratio?   ] [ unparse-ratio ]
-        [ float?   ] [ unparse-float fix-float ]
-        [ complex? ] [ unparse-complex ]
-        [ string?  ] [ unparse-str ]
-        [ drop t   ] [ unparse-unknown ]
-    ] cond ;
+    {
+        >dec
+        unparse-word
+        unparse-unknown
+        unparse-unknown
+        unparse-ratio
+        unparse-complex
+        unparse-f
+        unparse-t
+        unparse-unknown
+        unparse-unknown
+        unparse-str
+        unparse-unknown
+        unparse-unknown
+        >dec
+        unparse-float
+        unparse-unknown
+        unparse-unknown
+    } generic ;
index 4bb3498870e1283417ef1761f1a043329206e568..687a0b9dc53d41b74067cc53961aaa7ac2a16385 100644 (file)
 
 IN: words
 USE: combinators
+USE: hashtables
 USE: lists
 USE: namespaces
 USE: stack
 
 : (search) ( name vocab -- word )
-    vocab dup [ get* ] [ 2drop f ] ifte ;
+    vocab dup [ hash ] [ 2drop f ] ifte ;
 
 : search ( name list -- word )
     #! Search for a word in a list of vocabularies.
@@ -53,15 +54,14 @@ USE: stack
     #! Create an undefined word without adding to a vocabulary.
     <plist> 0 f rot <word> ;
 
-: word+ ( name vocab word -- )
-    swap vocab* put* ;
+: reveal ( word -- )
+    #! Add a new word to its vocabulary.
+    "vocabularies" get [
+        dup word-vocabulary over word-name 2list set-object-path
+    ] bind ;
 
 : create ( name vocab -- word )
     #! Create a new word in a vocabulary. If the vocabulary
     #! already contains the word, the existing instance is
     #! returned.
-    2dup (search) dup [
-        nip nip
-    ] [
-        drop 2dup (create) dup >r word+ r>
-    ] ifte ;
+    2dup (search) [ nip nip ] [ (create) dup reveal ] ifte* ;
index 4eb7eeacfb7d78dae80e596c357ce84d9f9f6999..e0e160995bc9a3eed5fc31247575070613a41e09 100644 (file)
@@ -38,29 +38,24 @@ USE: stack
     swap word-plist assoc ;
 
 : set-word-property ( word pvalue pname -- )
-    pick word-plist pick [ set-assoc ] [ remove-assoc nip ] ifte
+    pick word-plist
+    pick [ set-assoc ] [ remove-assoc nip ] ifte
     swap set-word-plist ;
 
-: defined? ( obj -- ? )
-    dup word? [ word-primitive 0 = not ] [ drop f ] ifte ;
+: ?word-primitive ( obj -- prim/0 )
+    dup word? [ word-primitive ] [ drop 0 ] ifte ;
 
-: compound? ( obj -- ? )
-    dup word? [ word-primitive 1 = ] [ drop f ] ifte ;
+: defined?   ( obj -- ? ) ?word-primitive 0 = not ;
+: compound?  ( obj -- ? ) ?word-primitive 1 = ;
+: primitive? ( obj -- ? ) ?word-primitive 2 > ;
+: symbol?    ( obj -- ? ) ?word-primitive 2 = ;
 
-: primitive? ( obj -- ? )
-    dup word? [ word-primitive 2 > ] [ drop f ] ifte ;
+: comment?
+    #! Comments are not first-class objects in CFactor.
+    drop f ;
 
-: symbol? ( obj -- ? )
-    dup word? [ word-primitive 2 = ] [ drop f ] ifte ;
-
-! Various features not supported by native Factor.
-: comment? drop f ;
-
-: word ( -- word )
-    global [ "last-word" get ] bind ;
-
-: set-word ( word -- )
-    global [ "last-word" set ] bind ;
+: word ( -- word ) global [ "last-word" get ] bind ;
+: set-word ( word -- ) global [ "last-word" set ] bind ;
 
 : define-compound ( word def -- )
     over set-word-parameter
@@ -70,8 +65,5 @@ USE: stack
     dup dup set-word-parameter
     2 swap set-word-primitive ;
 
-: stack-effect ( word -- str )
-    "stack-effect" word-property ;
-
-: documentation ( word -- str )
-    "documentation" word-property ;
+: stack-effect ( word -- str ) "stack-effect" word-property ;
+: documentation ( word -- str ) "documentation" word-property ;
index 0638cf1fad85c1bce6b9faec5d819c51acadbb01..02c6eda322827b93f6af74ebab1931e321756d75 100644 (file)
@@ -25,6 +25,9 @@
 ! OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
 ! ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
+IN: streams
+DEFER: <extend-stream>
+
 IN: stdio
 USE: combinators
 USE: errors
@@ -34,20 +37,6 @@ USE: namespaces
 USE: stack
 USE: streams
 
-: <stdio-stream> ( stream -- stream )
-    #! We disable fclose on stdio so that various tricks like
-    #! with-stream can work.
-    clone [
-        ( string -- )
-        [
-            namespace fwrite
-            "\n" namespace fwrite
-            namespace fflush
-        ] "fprint" set
-
-        [ ] "fclose" set
-    ] extend ;
-
 : flush ( -- )
     "stdio" get fflush ;
 
@@ -93,3 +82,13 @@ USE: streams
     1024 <string-output-stream> [
         call "stdio" get stream>str
     ] with-stream ;
+
+: <stdio-stream> ( stream -- stream )
+    #! We disable fclose on stdio so that various tricks like
+    #! with-stream can work.
+    <extend-stream> [
+        ( string -- )
+        [ write "\n" write flush ] "fprint" set
+
+        [ ] "fclose" set
+    ] extend ;
diff --git a/library/test/benchmark/continuations.factor b/library/test/benchmark/continuations.factor
new file mode 100644 (file)
index 0000000..937b08f
--- /dev/null
@@ -0,0 +1,8 @@
+IN: scratchpad
+USE: combinators
+USE: continuations
+USE: math
+USE: test
+
+! This caused the Java Factor to run out of memory
+[ ] [ 100000 [ [ call ] callcc0 ] times ] unit-test
index 531a015598d966ee4f73e5006d47f9bde7fd17eb..b43130f8285179c8ff55e7f3292f0ab34bd37f0c 100644 (file)
@@ -3,5 +3,5 @@ USE: math
 USE: stack
 USE: test
 
-[ 5000000 [ ] times ] time
-[ 5000000 [ drop ] times* ] time
+[ ] [ 5000000 [ ] times ] unit-test
+[ ] [ 5000000 [ drop ] times* ] unit-test
index 55d14f0ef3c0b71295ec85a511cd43db80a32b75..e22cca4170aec39a7921b795932aafa1d29198a8 100644 (file)
@@ -3,4 +3,4 @@ USE: math
 USE: stack
 USE: test
 
-[ 30000 fac drop ] time
+[ 1 ] [ 10000 fac 10000 [ succ / ] times* ] unit-test
index 9bcbc34b9175d05a25dda6c8ff0f31caae1e8e56..a83e7d4482c713a773ef35af9a5d04b7afb0dc48 100644 (file)
@@ -3,4 +3,4 @@ USE: math
 USE: stack
 USE: test
 
-[ 35 fib drop ] time
+[ 9227465 ] [ 34 fib ] unit-test
index ce8daa85ddb514750cb3c6b14f222244837a290a..e5464bad9bd1f64a2c20480d1b8f075182d1e9db 100644 (file)
@@ -5,4 +5,4 @@ USE: random
 USE: stack
 USE: test
 
-[ [, 100000 [ 0 10000 random-int , ] times ,] num-sort drop ] time
+[ ] [ [, 100000 [ 0 10000 random-int , ] times ,] num-sort drop ] unit-test
index 6159ec0e8e4d232477c715821cc8c11e08eaddc5..8fb47c3cd44d1d38cff41bd5362b7600a44344dc 100644 (file)
@@ -28,6 +28,3 @@ USE: test
 
 [ t ] [ 10 callcc1-test 10 count = ] unit-test
 [ t ] [ callcc-namespace-test ] unit-test
-
-! This caused the Java Factor to run out of memory
-[ ] [ 100000 [ [ call ] callcc0 ] times ] unit-test
index e9a1c63a38a7a0590f63402ee245e324cc436dcc..cdfc0eb0edf8b399950bd5b3a549335f7205b7ab 100644 (file)
@@ -28,7 +28,7 @@ USE: lists
 
 10 <vector> "x" set
 [ -2 "x" get set-vector-length ] [ drop ] catch
-[ "x" get clone drop ] [ drop ] catch
+[ "x" get vector-clone drop ] [ drop ] catch
 
 10 [ [ -1000000 <vector> ] [ drop ] catch ] times
 
index 1865674d2406bd8c1d560acffa5cecda4e646004..7c713d8b2056126f7f2fc056c04ede1c41a1c2db 100644 (file)
@@ -75,7 +75,7 @@ test-word
 
 : doc-test ( -- ) ;
 
-[ t ] [ "doc-test" ] [ intern word-parameter car comment? ] test-word
+[ t ] [ \ doc-test word-parameter car comment? ] unit-test
 
 [ [ 2 1 0 0 ] ] [ [ is ] ] [ balance>list ] test-word
 [ t ] [ "java.lang.Integer" ] [ 0 100 random-int swap is ] test-word
@@ -90,4 +90,4 @@ test-word
 
 [ [ 1 1 0 0 ] ] [ [ system-property ] ] [ balance>list ] test-word
 
-[ t ] [ "ifte" intern dup worddef word-of-worddef = ] unit-test
+[ t ] [ \ ifte dup worddef word-of-worddef = ] unit-test
index 1e0369b3266502d16ad52222a23bce41d749b8a3..d4fe033670ac27d3bcbdbdb90b4e1ce6542f75aa 100644 (file)
@@ -39,4 +39,9 @@ USE: words
 [ f ] [ ] [ 10 namespace-tail-call-bug "x" get 0 = ] test-word
 
 ! I did a n> in extend and forgot the obvious case
-[ t ] [ "dup" intern dup ] [ [ ] extend = ] test-word
+[ t ] [ \ dup dup ] [ [ ] extend = ] test-word
+
+: test-this-1 ( -- )
+    <namespace> dup [ this = ] bind ;
+
+[ t ] [ test-this-1    ] unit-test
index d1c39881f90e152bb9f4eee4d153208ba43b320e..8916be0ed0f659e759b6f85560aefc1ca1b57beb 100644 (file)
@@ -10,11 +10,7 @@ USE: words
 : test-namespace ( -- )
     <namespace> dup [ namespace = ] bind ;
 
-: test-this-1 ( -- )
-    <namespace> dup [ this = ] bind ;
-
 [ t ] [ test-namespace ] unit-test
-[ t ] [ test-this-1    ] unit-test
 
 ! Object paths should not resolve further up in the namestack.
 
@@ -28,12 +24,12 @@ unit-test
 unit-test
 
 [ t ]
-[ this [ ] object-path = ]
+[ namespace [ ] object-path = ]
 unit-test
 
 [ t ]
 [
-    "test-word" intern
+    \ test-word
     global [ [ "vocabularies" "test" "test-word" ] object-path ] bind
     =
 ] unit-test
index ada973ad015fd9314e906388aa1b10445da9e8fa..0fa8751ba9e1f5e6c64a003f1cad4d7e5318ba63 100644 (file)
@@ -4,4 +4,4 @@ USE: prettyprint
 USE: test
 USE: words
 
-[ vocabs [ words [ see ] each ] each ] time
+[ ] [ vocabs [ words [ see ] each ] each ] unit-test
index 6c3e5a38115d60fd4e01eaf657eac7e7a1506495..58c7ff3a153549a116e47298efe4f32096377b52 100644 (file)
@@ -9,21 +9,19 @@ USE: stack
 USE: strings
 USE: test
 
-native? [
-    [ t ] [ "Foo" str>sbuf "Foo" str>sbuf = ] unit-test
-    [ f ] [ "Foo" str>sbuf "Foob" str>sbuf = ] unit-test
-    [ f ] [ 34 "Foo" str>sbuf = ] unit-test
-    
-    [ "Hello" ] [
-        100 <sbuf> "buf" set
-        "Hello" "buf" get sbuf-append
-        "buf" get clone "buf-clone" set
-        "World" "buf-clone" get sbuf-append
-        "buf" get sbuf>str
-    ] unit-test
+[ t ] [ "Foo" str>sbuf "Foo" str>sbuf = ] unit-test
+[ f ] [ "Foo" str>sbuf "Foob" str>sbuf = ] unit-test
+[ f ] [ 34 "Foo" str>sbuf = ] unit-test
 
-    [ t ] [
-        "Hello world" str>sbuf hashcode
-        "Hello world" hashcode =
-    ] unit-test
-] when
+[ "Hello" ] [
+    100 <sbuf> "buf" set
+    "Hello" "buf" get sbuf-append
+    "buf" get sbuf-clone "buf-clone" set
+    "World" "buf-clone" get sbuf-append
+    "buf" get sbuf>str
+] unit-test
+
+[ t ] [
+    "Hello world" str>sbuf hashcode
+    "Hello world" hashcode =
+] unit-test
index a71210905a00e7f73f9dcab594f1f02458324b50..86f704a9217fda5ef70e93dcf63bf4ac7ab8f8fe 100644 (file)
@@ -28,12 +28,20 @@ USE: unparser
 : keep-datastack ( quot -- )
     datastack >r call r> set-datastack drop ;
 
+: time ( code -- )
+    #! Evaluates the given code and prints the time taken to
+    #! execute it.
+    millis >r call millis r> -
+    unparse write " milliseconds" print ;
+
 : unit-test ( output input -- )
     [
-        2dup print-test
-        swap >r >r clear r> call datastack vector>list r>
-        = assert
-    ] keep-datastack 2drop ;
+        [
+            2dup print-test
+            swap >r >r clear r> call datastack vector>list r>
+            = assert
+        ] keep-datastack 2drop
+    ] time ;
 
 : unit-test-fails ( quot -- )
     #! Assert that the quotation throws an error.
@@ -47,26 +55,18 @@ USE: unparser
     #! Flag for tests that are known not to work.
     3drop ;
 
-: time ( code -- )
-    #! Evaluates the given code and prints the time taken to
-    #! execute it.
-    "Timing " write dup .
-    millis >r call millis r> - . ;
-
 : test ( name -- )
     ! Run the given test.
     depth pred >r
     "Testing " write dup write "..." print
     "/library/test/" swap ".factor" cat3 run-resource
     "Checking before/after depth..." print
-    depth r> = assert
-    ;
+    depth r> = assert ;
 
 : all-tests ( -- )
     "Running Factor test suite..." print
     "vocabularies" get [ f "scratchpad" set ] bind
     [
-        "crashes"
         "lists/cons"
         "lists/lists"
         "lists/assoc"
@@ -76,7 +76,6 @@ USE: unparser
         "errors"
         "hashtables"
         "strings"
-        "sbuf"
         "namespaces/namespaces"
         "files"
         "format"
@@ -111,6 +110,8 @@ USE: unparser
     ] each
     
     native? [
+        "crashes" test
+        "sbuf" test
         "threads" test
 
         cpu "x86" = [
@@ -139,4 +140,10 @@ USE: unparser
         ] [
             test
         ] each
-    ] when ;
+    ] when
+
+    "benchmark/empty-loop" test
+    "benchmark/fac" test
+    "benchmark/fib" test
+    "benchmark/sort" test 
+    "benchmark/continuations" test ;
index 7649ad065a528cbc5240ab40db74d1fc20e3b593..fb29224e02ae5feb59baaee573ee4871c1dc425f 100644 (file)
@@ -1,4 +1,6 @@
 IN: scratchpad
+USE: lists
+USE: math
 USE: parser
 USE: test
 USE: unparser
@@ -17,3 +19,10 @@ test-word
 [ "\e" ]
 [ unparse ]
 test-word
+
+[ "1.0" ] [ 1.0 unparse ] unit-test
+[ "f" ] [ f unparse ] unit-test
+[ "t" ] [ t unparse ] unit-test
+[ "car" ] [ \ car unparse ] unit-test
+[ "#{ 1/2 2/3 }" ] [ #{ 1/2 2/3 } unparse ] unit-test
+[ "1267650600228229401496703205376" ] [ 1 100 shift unparse ] unit-test
index cb5ecb9b658f122e53432a1bb3f5b537be737143..6c4cb0e1412cb79edb754e9a46868679ee28ee66 100644 (file)
@@ -41,29 +41,11 @@ USE: strings
     #! Get a vocabulary.
     global [ "vocabularies" get get* ] bind ;
 
-: <vocab> ( name -- vocab )
-    #! Create a vocabulary.
-    <namespace> dup >r "vocabularies" get put* r> ;
-
-: vocab* ( name -- vocab )
-    #! Get a vocabulary, creating it if it doesn't exist.
-    global [
-        dup "vocabularies" get get* dup [
-            nip
-        ] [
-            drop <vocab>
-        ] ifte
-    ] bind ;
-
 : words ( vocab -- list )
     #! Push a list of all words in a vocabulary.
     #! Filter empty slots.
     vocab [ values ] bind [ ] subset ;
 
-: intern ( "word" -- word )
-    #! Returns the top of the stack if it already been interned.
-    dup string? [ "use" get search ] when ;
-
 : init-search-path ( -- )
     ! For files
     "scratchpad" "file-in" set
index 263b94475853aaa9eb24552343276aee1a1a7ffb..08aab5bbaa29b19223f14be8299a742b64e4a0a5 100644 (file)
@@ -13,20 +13,8 @@ void critical_error(char* msg, CELL tagged)
        exit(1);
 }
 
-void fix_stacks(void)
-{
-       if(STACK_UNDERFLOW(ds,ds_bot)
-               || STACK_OVERFLOW(ds,ds_bot))
-               reset_datastack();
-       if(STACK_UNDERFLOW(cs,cs_bot)
-               || STACK_OVERFLOW(cs,cs_bot))
-               reset_callstack();
-}
-
 void throw_error(CELL error)
 {
-       fix_stacks();
-
        dpush(error);
        /* Execute the 'throw' word */
        call(userenv[BREAK_ENV]);
index c6d0c3057b04b9c76b4f0c8d6dbb737560c222b0..c5cad745713b658e19bbea8032b705cab57e37ce 100644 (file)
 #define ERROR_C_STRING (12<<3)
 #define ERROR_FFI_DISABLED (13<<3)
 #define ERROR_FFI (14<<3)
+#define ERROR_DATASTACK_UNDERFLOW (15<<3)
+#define ERROR_DATASTACK_OVERFLOW (16<<3)
+#define ERROR_CALLSTACK_UNDERFLOW (17<<3)
+#define ERROR_CALLSTACK_OVERFLOW (18<<3)
 
 void fatal_error(char* msg, CELL tagged);
 void critical_error(char* msg, CELL tagged);
-void fix_stacks(void);
 void throw_error(CELL object);
 void general_error(CELL error, CELL tagged);
 void type_error(CELL type, CELL tagged);
index 6957cb43ef213a1fd340c2388af31d9f9eee5dc0..d5d310ab81b3ec6e30483d984c08db4098573602 100644 (file)
@@ -49,11 +49,10 @@ typedef unsigned short CHAR;
 /* must always be 8 bits */
 typedef unsigned char BYTE;
 
-/* Memory heap size */
+/* Memory areas */
 #define DEFAULT_ARENA (64 * 1024 * 1024)
-#define COMPILE_ZONE_SIZE (4 * 1024 * 1024)
-
-#define STACK_SIZE 16384
+#define COMPILE_ZONE_SIZE (64 * 1024 * 1024)
+#define STACK_SIZE (2 * 1024 * 1024)
 
 #include "memory.h"
 #include "error.h"
@@ -61,6 +60,7 @@ typedef unsigned char BYTE;
 #include "types.h"
 #include "word.h"
 #include "run.h"
+#include "signal.h"
 #include "fixnum.h"
 #include "array.h"
 #include "s48_bignumint.h"
index 005c20b382b01abbf113bab87dde5727fcad57ec..f26ca948a86699207cab88dc62ddb024985a2e2c 100644 (file)
@@ -132,7 +132,6 @@ void collect_roots(void)
 
 void primitive_gc(void)
 {
-       fprintf(stderr,"GC!\n");
        gc_in_progress = true;
 
        flip_zones();
@@ -156,17 +155,5 @@ are also reachable via the GC roots. */
 void maybe_garbage_collection(void)
 {
        if(active.here > active.alarm)
-       {
-               if(active.here > active.limit)
-               {
-                       fprintf(stderr,"Out of memory\n");
-                       fprintf(stderr,"active.base  = %ld\n",active.base);
-                       fprintf(stderr,"active.here  = %ld\n",active.here);
-                       fprintf(stderr,"active.limit = %ld\n",active.limit);
-                       fflush(stderr);
-                       exit(1);
-               }
-               else
-                       primitive_gc();
-       }
+               primitive_gc();
 }
index 9c547662b12fe3c0a3f4e81f3a2906294187f055..3590b28b8abd8305a512eef82f8c4fd3a78ccdbb 100644 (file)
@@ -1,44 +1,5 @@
 #include "factor.h"
 
-void signal_handler(int signal, siginfo_t* siginfo, void* uap)
-{
-       general_error(ERROR_SIGNAL,tag_fixnum(signal));
-}
-
-/* Called from a signal handler. XXX - is this safe? */
-void call_profiling_step(int signal, siginfo_t* siginfo, void* uap)
-{
-       CELL depth = (cs - cs_bot) / CELLS;
-       int i;
-       CELL obj;
-       for(i = profile_depth; i < depth; i++)
-       {
-               obj = get(cs_bot + i * CELLS);
-               if(TAG(obj) == WORD_TYPE)
-                       untag_word(obj)->call_count++;
-       }
-
-       executing->call_count++;
-}
-
-void init_signals(void)
-{
-       struct sigaction custom_sigaction;
-       struct sigaction profiling_sigaction;
-       struct sigaction ign_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;
-       ign_sigaction.sa_handler = SIG_IGN;
-       sigaction(SIGABRT,&custom_sigaction,NULL);
-       sigaction(SIGFPE,&custom_sigaction,NULL);
-       sigaction(SIGBUS,&custom_sigaction,NULL);
-       sigaction(SIGSEGV,&custom_sigaction,NULL);
-       sigaction(SIGPIPE,&ign_sigaction,NULL);
-       sigaction(SIGPROF,&profiling_sigaction,NULL);
-}
-
 void clear_environment(void)
 {
        int i;
@@ -132,27 +93,3 @@ void primitive_setenv(void)
                range_error(F,e,USER_ENV);
        userenv[e] = value;
 }
-
-void primitive_call_profiling(void)
-{
-       CELL d = dpop();
-       if(d == F)
-       {
-               timerclear(&prof_timer.it_interval);
-               timerclear(&prof_timer.it_value);
-
-               profile_depth = 0;
-       }
-       else
-       {
-               prof_timer.it_interval.tv_sec = 0;
-               prof_timer.it_interval.tv_usec = 1000;
-               prof_timer.it_value.tv_sec = 0;
-               prof_timer.it_value.tv_usec = 1000;
-
-               profile_depth = to_fixnum(d);
-       }
-
-       if(setitimer(ITIMER_PROF,&prof_timer,NULL) < 0)
-               io_error(__FUNCTION__);
-}
index dfb316464848ddf46ae85bb2e8d500c45b2badb6..c0a455d380d2f55576678538f89aa3f0839a4c6b 100644 (file)
@@ -93,9 +93,6 @@ INLINE void call(CELL quot)
        callframe = quot;
 }
 
-void signal_handler(int signal, siginfo_t* siginfo, void* uap);
-void call_profiling_step(int signal, siginfo_t* siginfo, void* uap);
-void init_signals(void);
 void clear_environment(void);
 
 void run(void);
@@ -107,6 +104,3 @@ void primitive_call(void);
 void primitive_ifte(void);
 void primitive_getenv(void);
 void primitive_setenv(void);
-void primitive_exit(void);
-void primitive_os_env(void);
-void primitive_call_profiling(void);
diff --git a/native/signal.c b/native/signal.c
new file mode 100644 (file)
index 0000000..f886528
--- /dev/null
@@ -0,0 +1,102 @@
+#include "factor.h"
+
+void signal_handler(int signal, siginfo_t* siginfo, void* uap)
+{
+       general_error(ERROR_SIGNAL,tag_fixnum(signal));
+}
+
+void memory_signal_handler(int signal, siginfo_t* siginfo, void* uap)
+{
+       if(STACK_UNDERFLOW(ds,ds_bot))
+       {
+               reset_datastack();
+               general_error(ERROR_DATASTACK_UNDERFLOW,F);
+       }
+       else if(STACK_OVERFLOW(ds,ds_bot))
+       {
+               reset_datastack();
+               general_error(ERROR_DATASTACK_OVERFLOW,F);
+       }
+       else if(STACK_UNDERFLOW(cs,cs_bot))
+       {
+               reset_callstack();
+               general_error(ERROR_CALLSTACK_UNDERFLOW,F);
+       }
+       else if(STACK_OVERFLOW(cs,cs_bot))
+       {
+               reset_callstack();
+               general_error(ERROR_CALLSTACK_OVERFLOW,F);
+       }
+       else if(active.here > active.limit)
+       {
+               fprintf(stderr,"Out of memory\n");
+               fprintf(stderr,"active.base  = %ld\n",active.base);
+               fprintf(stderr,"active.here  = %ld\n",active.here);
+               fprintf(stderr,"active.limit = %ld\n",active.limit);
+               fflush(stderr);
+               exit(1);
+       }
+       else
+               general_error(ERROR_SIGNAL,tag_fixnum(signal));
+}
+
+/* Called from a signal handler. XXX - is this safe? */
+void call_profiling_step(int signal, siginfo_t* siginfo, void* uap)
+{
+       CELL depth = (cs - cs_bot) / CELLS;
+       int i;
+       CELL obj;
+       for(i = profile_depth; i < depth; i++)
+       {
+               obj = get(cs_bot + i * CELLS);
+               if(TAG(obj) == WORD_TYPE)
+                       untag_word(obj)->call_count++;
+       }
+
+       executing->call_count++;
+}
+
+void init_signals(void)
+{
+       struct sigaction custom_sigaction;
+       struct sigaction profiling_sigaction;
+       struct sigaction memory_sigaction;
+       struct sigaction ign_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;
+       memory_sigaction.sa_sigaction = memory_signal_handler;
+       memory_sigaction.sa_flags = SA_SIGINFO;
+       ign_sigaction.sa_handler = SIG_IGN;
+       sigaction(SIGABRT,&custom_sigaction,NULL);
+       sigaction(SIGFPE,&custom_sigaction,NULL);
+       sigaction(SIGBUS,&memory_sigaction,NULL);
+       sigaction(SIGSEGV,&memory_sigaction,NULL);
+       sigaction(SIGPIPE,&ign_sigaction,NULL);
+       sigaction(SIGPROF,&profiling_sigaction,NULL);
+}
+
+void primitive_call_profiling(void)
+{
+       CELL d = dpop();
+       if(d == F)
+       {
+               timerclear(&prof_timer.it_interval);
+               timerclear(&prof_timer.it_value);
+
+               profile_depth = 0;
+       }
+       else
+       {
+               prof_timer.it_interval.tv_sec = 0;
+               prof_timer.it_interval.tv_usec = 1000;
+               prof_timer.it_value.tv_sec = 0;
+               prof_timer.it_value.tv_usec = 1000;
+
+               profile_depth = to_fixnum(d);
+       }
+
+       if(setitimer(ITIMER_PROF,&prof_timer,NULL) < 0)
+               io_error(__FUNCTION__);
+}
diff --git a/native/signal.h b/native/signal.h
new file mode 100644 (file)
index 0000000..07570df
--- /dev/null
@@ -0,0 +1,4 @@
+void signal_handler(int signal, siginfo_t* siginfo, void* uap);
+void call_profiling_step(int signal, siginfo_t* siginfo, void* uap);
+void init_signals(void);
+void primitive_call_profiling(void);