]> gitweb.factorcode.org Git - factor.git/commitdiff
a pile of bug fixes and improvements
authorSlava Pestov <slava@factorcode.org>
Tue, 9 Nov 2004 03:36:51 +0000 (03:36 +0000)
committerSlava Pestov <slava@factorcode.org>
Tue, 9 Nov 2004 03:36:51 +0000 (03:36 +0000)
42 files changed:
Makefile
TODO.FACTOR.txt
contrib/dejong.factor
contrib/mandel.factor
library/combinators.factor
library/compiler/alien-types.factor
library/factorspace/graphics-test.factor [deleted file]
library/factorspace/graphics.factor [deleted file]
library/factorspace/oop-test.factor [deleted file]
library/factorspace/oop.factor [deleted file]
library/factorspace/space.factor [deleted file]
library/math/arithmetic.factor
library/math/namespace-math.factor
library/platform/native/boot-stage2.factor
library/sdl/sdl-event.factor
library/sdl/sdl-utils.factor
library/sdl/sdl-video.factor
library/test/benchmark/ack.factor
library/test/combinators.factor
library/test/crashes.factor
library/test/lists/lists.factor
library/test/math/namespaces.factor
library/test/math/rational.factor
library/test/vectors.factor
library/vector-combinators.factor
native/arithmetic.c
native/bignum.c
native/error.c
native/factor.h
native/file.c
native/fixnum.c
native/float.c
native/misc.c
native/read.c
native/run.c
native/run.h
native/signal.c
native/stack.c
native/stack.h
native/types.h
native/word.c
native/write.c

index 74edaaed171c670a02be19cf7702c40dd10f6183..a4070b4858a4cf13fc6e33a3eaf7ebf135ab1986 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -1,5 +1,5 @@
-CC = gcc34
-DEFAULT_CFLAGS = -Wall -export-dynamic -g $(SITE_CFLAGS)
+CC = gcc
+DEFAULT_CFLAGS = -Wall -g $(SITE_CFLAGS)
 DEFAULT_LIBS = -lm
 
 STRIP = strip
@@ -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/signal.o
+       native/ffi.o native/signal.o native/boolean.o
 
 default:
        @echo "Run 'make' with one of the following parameters:"
@@ -24,6 +24,7 @@ default:
        @echo "bsd"
        @echo "bsd-nopthread - on FreeBSD 4, if you want to use profiling"
        @echo "linux"
+       @echo "macosx"
        @echo "solaris"
        @echo ""
        @echo "Also, you might want to set the SITE_CFLAGS environment"
@@ -34,17 +35,22 @@ default:
 
 bsd:
        $(MAKE) f \
-               CFLAGS="$(DEFAULT_CFLAGS) -DFFI -pthread" \
+               CFLAGS="$(DEFAULT_CFLAGS) -DFFI -export-dynamic -pthread" \
                LIBS="$(DEFAULT_LIBS)"
 
 bsd-nopthread:
+       $(MAKE) f \
+               CFLAGS="$(DEFAULT_CFLAGS) -DFFI -export-dynamic" \
+               LIBS="$(DEFAULT_LIBS)"
+
+macosx:
        $(MAKE) f \
                CFLAGS="$(DEFAULT_CFLAGS) -DFFI" \
                LIBS="$(DEFAULT_LIBS)"
 
 linux:
        $(MAKE) f \
-               CFLAGS="$(DEFAULT_CFLAGS) -DFFI" \
+               CFLAGS="$(DEFAULT_CFLAGS) -DFFI -export-dynamic" \
                LIBS="$(DEFAULT_LIBS) -ldl"
 
 solaris:
index 40ff4a310763cf7cfe1c7c911b3c3da8f736934c..0377795da4b6a399a245bc7745df91aab01be5e3 100644 (file)
@@ -36,6 +36,7 @@
 \r
 + listener/plugin:\r
 \r
+- extract word in wrong place\r
 - twice in completion list\r
 - accept multi-line input in listener\r
 - don't show listener on certain commands\r
@@ -51,6 +52,7 @@
 \r
 + kernel:\r
 \r
+- save restore stacks between longjmp in case they are in registers\r
 - profiler is inaccurate: wrong word on cs\r
 - better i/o scheduler\r
 - >lower, >upper for strings\r
index 5a262a2166471c525986d22b0f37634e4c9adb77..0eb755a8f9c79f62bd2d4f2be9fd8fe72f1d270b 100644 (file)
@@ -21,8 +21,6 @@ SYMBOL: a
 SYMBOL: b
 SYMBOL: c
 SYMBOL: d
-SYMBOL: width
-SYMBOL: height
 
 : next-x ( x y -- x ) a get * sin swap b get * cos - ;
 : next-y ( x y -- y ) swap c get * sin swap d get * cos - ;
@@ -52,15 +50,11 @@ SYMBOL: height
     2.4 c set
     -2.1 d set
 
-    640 dup width set
-    480 dup height set
-    32 SDL_HWSURFACE SDL_SetVideoMode drop
+    640 480 32 SDL_HWSURFACE [
+        [ 0 0 100000 draw-dejong ] with-surface
 
-    [
-        0 0 100000 draw-dejong
-    ] with-surface
-
-    <event> event-loop
-    SDL_Quit ;
+        <event> event-loop
+        SDL_Quit
+    ] with-screen ;
 
 dejong
index b22be2340ce73098c48e464ee15d9c643ae9fdbb..50d2a183bdffb8e62ecdcbd43841fe1c53365133 100644 (file)
@@ -84,17 +84,17 @@ SYMBOL: center
     ] with-pixels ;
 
 : mandel ( -- )
-    640 480 32 SDL_HWSURFACE SDL_SetVideoMode drop
-
-    [
-        0.8 zoom-fact set
-        -0.65 center set
-        100 nb-iter set
-        [ render ] time
-        "Done." print flush
-    ] with-surface
-
-    <event> event-loop
-    SDL_Quit ;
+    640 480 32 SDL_HWSURFACE [
+        [
+            0.8 zoom-fact set
+            -0.65 center set
+            100 nb-iter set
+            [ render ] time
+            "Done." print flush
+        ] with-surface
+
+        <event> event-loop
+        SDL_Quit
+    ] with-screen ;
 
 mandel
index a2044ac4f687fd0638aeffbfa3b9d981a19e7155..8c06f0bdfdffe7602d9a0151a10b8661be83b073 100644 (file)
@@ -44,6 +44,11 @@ USE: stack
     #! after the quotation returns.
     over >r call r> ;
 
+: 2keep ( a b quot -- a b )
+    #! Execute the quotation with a and b on the stack, and
+    #! restore a and b after the quotation returns.
+    over >r pick >r call r> r> ;
+
 : apply ( code input -- code output )
     #! Apply code to input.
     swap dup >r call r> swap ;
index 2ea4c0948d7b1e34c6e7df96b229a32e2350ffaf..dadf09dc60d6bee783c5ac9a3ed9c6ffa0bc7293 100644 (file)
@@ -30,7 +30,9 @@ USE: combinators
 USE: compiler
 USE: errors
 USE: hashtables
+USE: kernel
 USE: lists
+USE: logic
 USE: math
 USE: namespaces
 USE: parser
@@ -188,3 +190,11 @@ global [ <namespace> "c-types" set ] bind
     "box_c_string" "boxer" set
     "unbox_c_string" "unboxer" set
 ] "char*" define-c-type
+
+[
+    [ alien-4 0 = not ] "getter" set
+    [ 1 0 ? set-alien-4 ] "setter" set
+    cell "width" set
+    "box_boolean" "boxer" set
+    "unbox_boolean" "unboxer" set
+] "bool" define-c-type
diff --git a/library/factorspace/graphics-test.factor b/library/factorspace/graphics-test.factor
deleted file mode 100644 (file)
index 7cb6b67..0000000
+++ /dev/null
@@ -1,26 +0,0 @@
-IN: scratchpad
-USE: graphics
-USE: test
-USE: namespaces
-USE: lists
-USE: kernel
-
-<rectangle> [
-    #{ 0 0 } from set
-    #{ 20 20 } to set
-] extend "rect" set
-
-[ t ] [ #{ 5 5 } "rect" get inside? ] unit-test
-[ f ] [ #{ 5 50 } "rect" get inside? ] unit-test
-[ f ] [ #{ 30 5 } "rect" get inside? ] unit-test
-
-<rectangle> [
-    #{ 10 15 } from set
-    #{ 20 35 } to set
-] extend "another-rect" set
-
-"rect" get "another-rect" get 2list "scene" set
-
-[ t ] [ #{ 5 5 } "scene" get grab "rect" get eq? ] unit-test
-[ t ] [ #{ 19 30 } "scene" get grab "another-rect" get eq? ] unit-test
-[ f ] [ #{ 50 50 } "scene" get grab ] unit-test
diff --git a/library/factorspace/graphics.factor b/library/factorspace/graphics.factor
deleted file mode 100644 (file)
index fdaaf86..0000000
+++ /dev/null
@@ -1,103 +0,0 @@
-! :sidekick.parser=none:
-
-IN: graphics
-
-USE: alien
-USE: combinators
-USE: errors
-USE: kernel
-USE: lists
-USE: logic
-USE: math
-USE: namespaces
-USE: sdl
-USE: stack
-USE: vectors
-USE: oop
-
-: black 0 0 0 255 rgba ;
-: white 255 255 255 255 rgba ;
-
-: clear-surface ( -- )
-    #! Crappy
-    surface get
-    NULL
-    surface get surface-format 255 255 255 SDL_MapRGB
-    SDL_FillRect drop ;
-
-! These variables are set in shape objects.
-SYMBOL: from ( complex number, x/y )
-SYMBOL: to ( complex number, w/h )
-SYMBOL: filled?
-SYMBOL: color
-SYMBOL: string ( text objects only )
-
-! Draw an object.
-GENERIC: draw ( obj -- )
-
-! Return if the point is inside the object.
-GENERIC: inside? ( #{ x y } obj -- ? )
-
-! Scale factor for all rendering, can be set in object too
-SYMBOL: scale
-
-! Translation
-SYMBOL: origin
-
-: center ( -- #{ x y } )
-    width get 2 / height get 2 / rect> ;
-
-: scene>screen ( #{ x y } -- #{ x y } )
-    origin get - scale get * center + ;
-
-: screen>scene ( #{ x y } -- #{ x y } )
-    center - scale get / origin get + ;
-
-: 2>irect >r >rect swap >fixnum swap >fixnum r> >rect swap >fixnum swap >fixnum ;
-
-: (rect) ( -- surface x y w h color )
-    surface get
-    from get scene>screen
-    to get scene>screen
-    2>irect  color get ;
-
-: in-rect? ( #{ x y } #{ x1 y1 } #{ x2 y2 } -- ? )
-    #! Return if x/y is in the rectangle bounded by x1/y1, x2/y2
-    3dup
-    rot real rot real rot real between? >r
-    rot imaginary rot imaginary rot imaginary between? r> and ;
-
-TRAITS: rectangle
-M: rectangle draw ( -- )
-    (rect) filled? get [
-        boxColor
-    ] [
-        rectangleColor
-    ] ifte ;M
-
-M: rectangle inside? ( #{ x y } -- ? )
-    from get to get in-rect? ;M
-
-TRAITS: line
-M: line draw ( -- )
-    (rect) lineColor ;M
-
-M: line inside? ( #{ x y } -- ? )
-    from get to get in-rect? [
-        t
-    ] [
-        f
-    ] ifte ;M
-
-TRAITS: text
-M: text draw ( -- )
-    surface get  from get >rect  color get  string get
-    stringColor ;M
-
-: grab ( #{ x y } list -- shape )
-    #! Return shape containing x/y.
-    dup [
-        2dup car inside? [ nip car ] [ cdr grab ] ifte
-    ] [
-        2drop f
-    ] ifte ;
diff --git a/library/factorspace/oop-test.factor b/library/factorspace/oop-test.factor
deleted file mode 100644 (file)
index f56c8be..0000000
+++ /dev/null
@@ -1,22 +0,0 @@
-IN: scratchpad
-USE: test
-USE: namespaces
-USE: oop
-USE: stack
-
-TRAITS: test-traits
-
-[ t ] [ <test-traits> test-traits? ] unit-test
-[ f ] [ "hello" test-traits? ] unit-test
-[ f ] [ <namespace> test-traits? ] unit-test
-
-GENERIC: foo
-
-M: test-traits foo 12 ;M
-
-TRAITS: another-test
-
-M: another-test foo 13 ;M
-
-[ 12 ] [ <test-traits> foo ] unit-test
-[ 13 ] [ <another-test> foo ] unit-test
diff --git a/library/factorspace/oop.factor b/library/factorspace/oop.factor
deleted file mode 100644 (file)
index 08c32d7..0000000
+++ /dev/null
@@ -1,78 +0,0 @@
-! :sidekick.parser=none:
-IN: oop
-
-USE: combinators
-USE: errors
-USE: kernel
-USE: lists
-USE: namespaces
-USE: parser
-USE: stack
-USE: strings
-USE: words
-
-SYMBOL: traits
-
-: traits-map ( word -- hash )
-    #! The method map word property maps selector words to
-    #! definitions.
-    "traits-map" word-property ;
-
-: object-map ( obj -- hash )
-    dup has-namespace? [ traits swap get* ] [ drop f ] ifte ;
-
-: init-traits-map ( word -- )
-    <namespace> "traits-map" set-word-property ;
-
-: no-method
-    "No applicable method." throw ;
-
-: method ( traits selector -- quot )
-    #! Execute the method with the traits object on the stack.
-    over object-map get* [ [ no-method ] ] unless* ;
-
-: constructor-word ( word -- word )
-    word-name "<" swap ">" cat3 "in" get create ;
-
-: define-constructor ( word -- )
-    #! <foo> where foo is a traits type creates a new instance
-    #! of foo.
-    [ constructor-word [ <namespace> ] ] keep
-    traits-map [ traits pick set* ] cons append
-    define-compound ;
-
-: predicate-word ( word -- word )
-    word-name "?" cat2 "in" get create ;
-
-: define-predicate ( word -- )
-    #! foo? where foo is a traits type tests if the top of stack
-    #! is of this type.
-    dup predicate-word swap
-    [ object-map ] swap traits-map [ eq? ] cons append
-    define-compound ;
-
-: TRAITS:
-    #! TRAITS: foo creates a new traits type. Instances can be
-    #! created with <foo>, and tested with foo?.
-    CREATE
-    dup define-symbol
-    dup init-traits-map
-    dup define-constructor
-    define-predicate ; parsing
-
-: GENERIC:
-    #! GENERIC: bar creates a generic word bar that calls the
-    #! bar method on the traits object, with the traits object
-    #! on the namestack.
-    CREATE
-    dup unit [ car method bind ] cons
-    define-compound ; parsing
-
-: M:
-    #! M: foo bar begins a definition of the bar generic word
-    #! specialized to the foo type.
-    scan-word scan-word f ; parsing
-
-: ;M
-    #! ;M ends a method definition.
-    reverse transp traits-map set* ; parsing
diff --git a/library/factorspace/space.factor b/library/factorspace/space.factor
deleted file mode 100644 (file)
index 9fd2914..0000000
+++ /dev/null
@@ -1,134 +0,0 @@
-! :sidekick.parser=none:
-
-IN: graphics
-
-USE: combinators
-USE: errors
-USE: kernel
-USE: lists
-USE: logic
-USE: math
-USE: namespaces
-USE: sdl
-USE: stack
-USE: vectors
-USE: stdio
-USE: prettyprint
-USE: inspector
-
-SYMBOL: scene
-SYMBOL: tool
-SYMBOL: current ( shape we're drawing right now )
-SYMBOL: moving? ( are we moving or resizing current shape? )
-SYMBOL: buttons ( mouse buttons down )
-SYMBOL: clicked ( mouse click location )
-
-: ch>tool ( ch -- quot )
-    [
-        [ CHAR: a ]
-        [ CHAR: r <rectangle> ]
-        [ CHAR: l <line> ]
-    ] assoc ;
-
-: render ( -- )
-    clear-surface
-    scene get [ draw ] each
-    current get [ draw ] when* ;
-
-: mouse-xy ( mouse-event -- #{ x y } )
-    dup motion-event-x swap motion-event-y rect> ;
-
-: begin-draw ( #{ x y } -- )
-    tool get call [
-        dup from set to set
-        black color set
-    ] extend current set ;
-
-: begin-move ( #{ x y } -- )
-    scene get grab
-    [ dup scene remove@ current set  moving? on ] when* ;
-
-: button-down ( event -- )
-    button-event-button buttons unique@ ;
-
-: mouse-down-event ( event -- )
-    dup button-down
-    1 buttons get contains? [
-        mouse-xy screen>scene tool get [ begin-draw ] [ begin-move ] ifte
-    ] [
-        drop
-    ] ifte ;
-
-: button-up ( event -- )
-    button-event-button buttons remove@ ;
-
-: mouse-up-event ( event -- )
-    button-up
-    current get [
-        scene cons@  current off  moving? off
-    ] when* ;
-
-: mouse-delta ( mouse-event -- #{ x y } )
-    dup motion-event-xrel swap motion-event-yrel rect> ;
-
-: mouse-motion-event ( event -- )
-    2 buttons get contains? [
-        mouse-delta scale get / origin -@
-    ] [
-        current get dup [
-            [
-                moving? get [
-                    mouse-delta scale get / dup from +@ to +@
-                ] [
-                    mouse-xy screen>scene to set
-                ] ifte
-            ] bind
-        ] [
-            2drop
-        ] ifte
-    ] ifte ;
-
-: key-down-event
-    keyboard-event-sym [
-        [ CHAR: - = ] [ drop 1.1 scale /@ ]
-        [ CHAR: = = ] [ drop 1.1 scale *@ ]
-        [ drop t ] [ ch>tool tool set ]
-    ] cond ;
-
-: debug-event ( event -- ? )
-    [
-        [ event-type SDL_MOUSEBUTTONDOWN = ] [ mouse-down-event t ]
-        [ event-type SDL_MOUSEBUTTONUP = ] [ mouse-up-event t ]
-        [ event-type SDL_MOUSEMOTION = ] [ mouse-motion-event t ]
-        [ event-type SDL_KEYDOWN = ] [ key-down-event t ]
-        [ event-type SDL_QUIT = ] [ drop f ]
-        [ drop t ] [ drop t ]
-    ] cond ;
-
-: debug-event-loop ( event -- )
-    dup SDL_WaitEvent 1 = [
-        dup debug-event [
-            [ render ] with-surface
-            debug-event-loop
-        ] [
-            drop
-        ] ifte
-    ] [
-        drop
-    ] ifte ;
-
-: zui-test ( -- )
-    640 480 32 SDL_HWSURFACE SDL_SetVideoMode drop
-    1 scale set
-    0 origin set
-    buttons off
-    640 width set
-    480 height set
-
-    scene off
-    [ <line> ] tool set
-    
-    <event> debug-event-loop
-    SDL_Quit ;
-
-zui-test
index 9011f28277e0f1e0bd1eecf2937f888e777af0dc..ead58048c8cfaf8697552597537b080e0c1964ac 100644 (file)
@@ -64,3 +64,11 @@ USE: stack
 
 : neg 0 swap - ; inline
 : recip 1 swap / ; inline
+
+: rem ( x y -- x%y )
+    #! Like modulus, but always gives a positive result.
+    dup >r + r> mod ;
+
+: sgn ( n -- -1/0/1 )
+    #! Push the sign of a real number.
+    dup 0 = [ drop 0 ] [ 1 < -1 1 ? ] ifte ;
index 5b3ce221a45016e6d4abf7003b4dd7b4f8fc7e0e..f856f78c7b73f6a6b1758e535455471994d0ac41 100644 (file)
@@ -35,5 +35,7 @@ USE: stack
 : -@ ( num var -- ) tuck get swap - put ;
 : *@ ( num var -- ) tuck get * put ;
 : /@ ( num var -- ) tuck get swap / put ;
+: mod@ ( num var -- ) tuck get swap mod put ;
+: rem@ ( num var -- ) tuck get swap rem put ;
 : pred@ ( var -- ) dup get pred put ;
 : succ@ ( var -- ) dup get succ put ;
index 2aea3245ca9ef9efc990de2648008031daba5bd2..e68a697293cccea728dda44aefc62e22acde22db 100644 (file)
@@ -194,6 +194,9 @@ DEFER: init-listener
 
 compilable-words compilable-word-list set
 
+"Bootstrapping is complete." print
+"Now, you can run ./f factor.image" print
+
 ! Save a bit of space
 global [ "stdio" off ] bind
 
index 72d992a31734ab71f39a21e0b643bfae83a580d8..70a9c3b545cdb392580d9e43cec0254f3a981f21 100644 (file)
@@ -195,3 +195,6 @@ END-UNION
 
 : SDL_WaitEvent ( event -- )
     "int" "sdl" "SDL_WaitEvent" [ "event*" ] alien-call ;
+
+: SDL_PollEvent ( event -- ? )
+    "bool" "sdl" "SDL_PollEvent" [ "event*" ] alien-call ;
index b9844756d9919ae94f1427b58404896b738cae87..8aa346681f47d1a0455dc2354023d64f9cdfb2f7 100644 (file)
@@ -16,33 +16,47 @@ USE: prettyprint
 SYMBOL: surface
 SYMBOL: width
 SYMBOL: height
+SYMBOL: bpp
+SYMBOL: surface
+
+: with-screen ( width height bpp flags quot -- )
+    #! Set up SDL graphics and call the quotation.
+    [
+        >r
+        >r 3dup bpp set height set width set r>
+        SDL_SetVideoMode surface set
+        r> call SDL_Quit
+    ] with-scope ;
 
 : rgba ( r g b a -- n )
     swap 8 shift bitor
     swap 16 shift bitor
     swap 24 shift bitor ;
 
+: black 0 0 0 255 rgba ;
+: white 255 255 255 255 rgba ;
+: red 255 0 0 255 rgba ;
+: green 0 255 0 255 rgba ;
+: blue 0 0 255 255 rgba ;
+
+: clear-surface ( color -- )
+    >r surface get 0 0 width get height get r> boxColor ;
+
 : pixel-step ( quot #{ x y } -- )
     tuck >r call >r surface get r> r> >rect rot pixelColor ;
 
 : with-pixels ( w h quot -- )
     -rot rect> [ over >r pixel-step r> ] 2times* drop ;
 
-: (surface) ( -- surface )
-    SDL_GetVideoSurface
-    dup surface set
-    dup surface-w width set
-    dup surface-h height set ;
-
 : with-surface ( quot -- )
     #! Execute a quotation, locking the current surface if it
     #! is required (eg, hardware surface).
     [
-        (surface) dup must-lock-surface? [
+        surface get dup must-lock-surface? [
             dup SDL_LockSurface slip dup SDL_UnlockSurface
         ] [
             slip
-        ] ifte SDL_Flip
+        ] ifte SDL_Flip drop
     ] with-scope ;
 
 : event-loop ( event -- )
index 98f619b566bb5ce9b76f5ac0f3690b3ea6321ff1..e57fc6e16b14e449aeb6f10b6426d0ad703914e1 100644 (file)
@@ -147,17 +147,17 @@ END-STRUCT
 ! UpdateRects, UpdateRect
 
 : SDL_Flip ( surface -- )
-    "void" "sdl" "SDL_Flip" [ "surface*" ] alien-call ;
+    "bool" "sdl" "SDL_Flip" [ "surface*" ] alien-call ;
 
 ! SDL_SetGamma: float types
 
 : SDL_FillRect ( surface rect color -- n )
     #! If rect is null, fills entire surface.
-    "int" "sdl" "SDL_FillRect"
+    "bool" "sdl" "SDL_FillRect"
     [ "surface*" "rect*" "uint" ] alien-call ;
 
 : SDL_LockSurface ( surface -- )
-    "int" "sdl" "SDL_LockSurface" [ "surface*" ] alien-call ;
+    "bool" "sdl" "SDL_LockSurface" [ "surface*" ] alien-call ;
 
 : SDL_UnlockSurface ( surface -- )
     "void" "sdl" "SDL_UnlockSurface" [ "surface*" ] alien-call ;
@@ -165,3 +165,7 @@ END-STRUCT
 : SDL_MapRGB ( surface r g b -- )
     "uint" "sdl" "SDL_MapRGB"
     [ "surface*" "uchar" "uchar" "uchar" ] alien-call ;
+
+: SDL_WM_SetCaption ( title icon -- )
+    "void" "sdl" "SDL_WM_SetCaption"
+    [ "char*" "char*" ] alien-call ;
index ca7ecdd51eb4f97f554e74fe8dade4f09540113a..59bd1eab4aa841c58b845625916b5c558bc3a4ba 100644 (file)
@@ -7,7 +7,7 @@ USE: test
 
 ! http://inferno.bell-labs.com/cm/cs/who/bwk/interps/pap.html
 
-: ack ( m n -- )
+: ack ( m n -- )
     over 0 = [
         nip succ
     ] [
index edae9aa96d70c08d568d7c0709127c29d8d41285..9bb67eb12a246e67046bc58b303b5e999ffe8fd2 100644 (file)
@@ -18,6 +18,10 @@ USE: test
 
 [ 6 ] [ 2 [ sq ] keep + ] unit-test
 
+[ [ ] 2keep ] unit-test-fails
+[ 1 [ ] 2keep ] unit-test-fails
+[ 3 1 2 ] [ 1 2 [ 2drop 3 ] 2keep ] unit-test
+
 [ cond ] unit-test-fails
 [ [ [ 1 = ] [ ] ] cond ] unit-test-fails
 
index cdfc0eb0edf8b399950bd5b3a549335f7205b7ab..b03abf466770c9abf26278423da552b51f6126b8 100644 (file)
@@ -55,3 +55,7 @@ USE: lists
 
 ! f -vs- hitype
 [ ] [ [ f vector-length ] [ drop ] catch ] unit-test
+
+! See how well callstack overflow is handled
+: callstack-overflow callstack-overflow f ;
+[ callstack-overflow ] unit-test-fails
index ba6a02ff15416d8b7e492ae147bb8b836d19d465..42fb2eed871c97694df4484ab117953444de1213 100644 (file)
@@ -6,6 +6,7 @@ USE: math
 USE: namespaces
 USE: stack
 USE: test
+USE: strings
 
 [ [ ]           ] [ [ ]   [ ]       append ] unit-test
 [ [ 1 ]         ] [ [ 1 ] [ ]       append ] unit-test
index b6789c3b34987ce613cffefef299faf856719e31..5bfebc4a3cf3c81c62786d1ee6b2f5f7c4db481d 100644 (file)
@@ -11,3 +11,5 @@ USE: math
 [ 2 ] [ 5 "x" /@ "x" get ] unit-test
 [ 1 ] [ "x" pred@ "x" get ] unit-test
 [ 2 ] [ "x" succ@ "x" get ] unit-test
+[ 7 ] [ -3 "x" set 10 "x" rem@ ] unit-test 
+[ -3 ] [ -3 "x" set 10 "x" rem@ ] unit-test 
index 502564add6a7c40d533b13c5defc8725e84fe261..7c5a507373b4e88d9de4d89af87d760f580c5f64 100644 (file)
@@ -79,3 +79,10 @@ USE: unparser
 [ t ]
 [ 1000000000000/999999999999 1000000000001/999999999998 < ]
 unit-test
+
+[ -3 ] [ -3 10 mod ] unit-test
+[ 7 ] [ -3 10 rem ] unit-test
+
+[ -1 ] [ -12.55 sgn ] unit-test
+[ 1 ] [ 100000000000000000000000000000000 sgn ] unit-test
+[ 0 ] [ 0.0 sgn ] unit-test
index 1b635eb90689ca6c3179166e0eedde18128822cc..0f7f3e4381a58f4f72bc3d70dd73572add1b6d62 100644 (file)
@@ -5,6 +5,7 @@ USE: random
 USE: stack
 USE: test
 USE: vectors
+USE: strings
 
 [ { } ] [ [ ] list>vector ] unit-test
 [ { 1 2 } ] [ [ 1 2 ] list>vector ] unit-test
@@ -36,6 +37,10 @@ USE: vectors
 [ { 1 2 3 4 5 6 } ]
 [ { 1 2 3 } vector-clone dup { 4 5 6 } vector-append ] unit-test
 
+[ { "" "a" "aa" "aaa" } ]
+[ 4 [ CHAR: a fill ] vector-project ]
+unit-test
+
 [ { 6 8 10 12 } ]
 [ { 1 2 3 4 } { 5 6 7 8 } [ + ] vector-2map ]
 unit-test
index 16d882f25bca9f58aff1adb82e01fa7d9a5d893d..76a13bc0e4bd2c9ecbb3957b58f72e72c2b2b4f4 100644 (file)
@@ -59,9 +59,10 @@ USE: stack
     #! Destructively append v2 to v1.
     [ over vector-push ] vector-each drop ;
 
-: vector-collect ( n quot -- accum )
+: vector-project ( n quot -- accum )
     #! Execute the quotation n times, passing the loop counter
-    #! the quotation, and collect results in a new vector.
+    #! the quotation as it ranges from 0..n-1. Collect results
+    #! in a new vector.
     over <vector> rot [
         -rot 2dup >r >r slip vector-push r> r>
     ] times* nip ;
index 66d497131c7c98527241621e8068434939df3ad2..6c4e36e9d3a7f7c7942009cc34c8c359bcb3a52f 100644 (file)
@@ -95,8 +95,8 @@ bool realp(CELL tagged)
 
 void primitive_numberp(void)
 {
-       CELL tagged = dpeek();
-       drepl(tag_boolean(realp(tagged) || type_of(tagged) == COMPLEX_TYPE));
+       CELL tagged = dpop();
+       box_boolean(realp(tagged) || type_of(tagged) == COMPLEX_TYPE);
 }
 
 bool zerop(CELL tagged)
index 3f01c8e494852d513ef2da8f12ad427713513427..ffd229573ee2e76ef588a631f7572150c309eddb 100644 (file)
@@ -75,7 +75,7 @@ void primitive_bignum_eq(void)
 {
        ARRAY* y = to_bignum(dpop());
        ARRAY* x = to_bignum(dpop());
-       dpush(tag_boolean(s48_bignum_equal_p(x,y)));
+       box_boolean(s48_bignum_equal_p(x,y));
 }
 
 #define GC_AND_POP_BIGNUMS(x,y) \
@@ -163,9 +163,7 @@ void primitive_bignum_less(void)
 {
        ARRAY* y = to_bignum(dpop());
        ARRAY* x = to_bignum(dpop());
-       dpush(tag_boolean(
-               s48_bignum_compare(x,y)
-               == bignum_comparison_less));
+       box_boolean(s48_bignum_compare(x,y) == bignum_comparison_less);
 }
 
 void primitive_bignum_lesseq(void)
@@ -192,9 +190,7 @@ void primitive_bignum_greater(void)
 {
        ARRAY* y = to_bignum(dpop());
        ARRAY* x = to_bignum(dpop());
-       dpush(tag_boolean(
-               s48_bignum_compare(x,y)
-               == bignum_comparison_greater));
+       box_boolean(s48_bignum_compare(x,y) == bignum_comparison_greater);
 }
 
 void primitive_bignum_greatereq(void)
index 350c6e2dfc51cc0ceb04fa547fff27514c709772..131fc59fe6c02193a4d6eb208042c737cfc693af 100644 (file)
@@ -20,8 +20,6 @@ void critical_error(char* msg, CELL tagged)
 
 void throw_error(CELL error)
 {
-       /* dpush(error); */
-       /* call(userenv[BREAK_ENV]); */
        thrown_error = error;
 
        /* Return to run() method */
index 2b29cf9d5bc46c03d8e7d75296e942a0888b9b36..47ceb79b5169567191536ea21e6de45350aee8ad 100644 (file)
@@ -1,6 +1,30 @@
 #ifndef __FACTOR_H__
 #define __FACTOR_H__
 
+#if defined(i386) || defined(__i386) || defined(__i386__)
+    #define FACTOR_X86
+#endif
+
+/* CELL must be 32 bits and your system must have 32-bit pointers */
+typedef unsigned long int CELL;
+#define CELLS ((signed)sizeof(CELL))
+
+/* raw pointer to datastack bottom */
+CELL ds_bot;
+
+/* raw pointer to datastack top */
+#ifdef FACTOR_X86
+register CELL ds asm("%esi");
+#else
+CELL ds;
+#endif
+
+/* raw pointer to callstack bottom */
+CELL cs_bot;
+
+/* raw pointer to callstack top */
+CELL cs;
+
 #include <dirent.h>
 #include <errno.h>
 #include <fcntl.h>
 #include <dlfcn.h>
 #endif /* FFI */
 
-#if defined(i386) || defined(__i386) || defined(__i386__)
-    #define FACTOR_X86
-#endif
-
 #define INLINE inline static
 
-/* CELL must be 32 bits and your system must have 32-bit pointers */
-typedef unsigned long int CELL;
-#define CELLS ((signed)sizeof(CELL))
-
 #define FIXNUM_MAX (LONG_MAX >> TAG_BITS)
 #define FIXNUM_MIN (LONG_MIN >> TAG_BITS)
 
@@ -62,6 +78,7 @@ typedef unsigned char BYTE;
 #include "error.h"
 #include "gc.h"
 #include "types.h"
+#include "boolean.h"
 #include "word.h"
 #include "run.h"
 #include "signal.h"
index 4dfbf086369050aa523150c7c0994e145f352ffd..b5f5153a914b285e0e7a0741ebb8c9d261e68b9a 100644 (file)
@@ -2,8 +2,8 @@
 
 void primitive_open_file(void)
 {
-       bool write = untag_boolean(dpop());
-       bool read = untag_boolean(dpop());
+       bool write = unbox_boolean();
+       bool read = unbox_boolean();
 
        char* path;
        int mode, fd;
index 95449da51a97cfee7c03c7d4e6c2ddd64ef1d3d0..b8807c9680b2f0bf572ea43f2ef057b0503e65ba 100644 (file)
@@ -36,7 +36,7 @@ void primitive_fixnum_eq(void)
 {
        FIXNUM y = to_fixnum(dpop());
        FIXNUM x = to_fixnum(dpop());
-       dpush(tag_boolean(x == y));
+       box_boolean(x == y);
 }
 
 void primitive_fixnum_add(void)
@@ -174,28 +174,28 @@ void primitive_fixnum_less(void)
 {
        FIXNUM y = to_fixnum(dpop());
        FIXNUM x = to_fixnum(dpop());
-       dpush(tag_boolean(x < y));
+       box_boolean(x < y);
 }
 
 void primitive_fixnum_lesseq(void)
 {
        FIXNUM y = to_fixnum(dpop());
        FIXNUM x = to_fixnum(dpop());
-       dpush(tag_boolean(x <= y));
+       box_boolean(x <= y);
 }
 
 void primitive_fixnum_greater(void)
 {
        FIXNUM y = to_fixnum(dpop());
        FIXNUM x = to_fixnum(dpop());
-       dpush(tag_boolean(x > y));
+       box_boolean(x > y);
 }
 
 void primitive_fixnum_greatereq(void)
 {
        FIXNUM y = to_fixnum(dpop());
        FIXNUM x = to_fixnum(dpop());
-       dpush(tag_boolean(x >= y));
+       box_boolean(x >= y);
 }
 
 void primitive_fixnum_not(void)
index cc302c003ebb9c74600d52bd80b6748cde1a4ddd..929bededb24ff2ea374aa81dd27994b092e9cfcc 100644 (file)
@@ -80,7 +80,7 @@ void primitive_float_to_bits(void)
 void primitive_float_eq(void)
 {
        GC_AND_POP_FLOATS(x,y);
-       dpush(tag_boolean(x == y));
+       box_boolean(x == y);
 }
 
 void primitive_float_add(void)
@@ -109,30 +109,26 @@ void primitive_float_divfloat(void)
 
 void primitive_float_less(void)
 {
-       double y = to_float(dpop());
-       double x = to_float(dpop());
-       dpush(tag_boolean(x < y));
+       GC_AND_POP_FLOATS(x,y);
+       box_boolean(x < y);
 }
 
 void primitive_float_lesseq(void)
 {
-       double y = to_float(dpop());
-       double x = to_float(dpop());
-       dpush(tag_boolean(x <= y));
+       GC_AND_POP_FLOATS(x,y);
+       box_boolean(x <= y);
 }
 
 void primitive_float_greater(void)
 {
-       double y = to_float(dpop());
-       double x = to_float(dpop());
-       dpush(tag_boolean(x > y));
+       GC_AND_POP_FLOATS(x,y);
+       box_boolean(x > y);
 }
 
 void primitive_float_greatereq(void)
 {
-       double y = to_float(dpop());
-       double x = to_float(dpop());
-       dpush(tag_boolean(x >= y));
+       GC_AND_POP_FLOATS(x,y);
+       box_boolean(x >= y);
 }
 
 void primitive_facos(void)
index fc71056790329e1a9a13aa4d613cc4e5e7100a40..137032a05635c0ee76f7b31c9d49384a14898e90 100644 (file)
@@ -21,7 +21,7 @@ void primitive_os_env(void)
 
 void primitive_eq(void)
 {
-       dpush(tag_boolean(dpop() == dpop()));
+       box_boolean(dpop() == dpop());
 }
 
 void primitive_millis(void)
index 0bf9d0f570b24f6629f52ff6a6677080bfb35739..882c2565313948185e16fc8bc073b2343cc72c38 100644 (file)
@@ -102,7 +102,7 @@ bool can_read_line(PORT* port)
 void primitive_can_read_line(void)
 {
        PORT* port = untag_port(dpop());
-       dpush(tag_boolean(can_read_line(port)));
+       box_boolean(can_read_line(port));
 }
 
 void primitive_add_read_line_io_task(void)
@@ -214,7 +214,7 @@ void primitive_can_read_count(void)
 
        port = untag_port(dpop());
        len = to_fixnum(dpop());
-       dpush(tag_boolean(can_read_count(port,len)));
+       box_boolean(can_read_count(port,len));
 }
 
 void primitive_add_read_count_io_task(void)
index 136ce257d340f83ba64acd3033741deeb81ab93a..1d7469acc4c355a0bee4771493446b26f20fa836 100644 (file)
@@ -18,6 +18,7 @@ void run(void)
        sigsetjmp(toplevel, 1);
        if(thrown_error != F)
        {
+               fix_stacks();
                dpush(thrown_error);
                /* Notify any 'catch' blocks */
                call(userenv[BREAK_ENV]);
index 77235875df9139ebc01b58b7788b2346893130d8..32a5e8536190494b6efffc669760be692dd60720 100644 (file)
@@ -21,22 +21,6 @@ sigjmp_buf toplevel;
 /* TAGGED currently executing quotation */
 CELL callframe;
 
-/* raw pointer to datastack bottom */
-CELL ds_bot;
-
-/* raw pointer to datastack top */
-#ifdef FACTOR_X86
-register CELL ds asm("%esi");
-#else
-CELL ds;
-#endif
-
-/* raw pointer to callstack bottom */
-CELL cs_bot;
-
-/* raw pointer to callstack top */
-CELL cs;
-
 /* raw pointer to currently executing word */
 WORD* executing;
 
index f88652826dd33722a0deca769d1f4a708c44bd85..402b2d5364b054a203a1176bb5c27d43966f86d1 100644 (file)
@@ -7,27 +7,8 @@ void signal_handler(int signal, siginfo_t* siginfo, void* uap)
 
 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,"memory signal\n");
+       if(active.here > active.limit)
        {
                fprintf(stderr,"Out of memory\n");
                fprintf(stderr,"active.base  = %ld\n",active.base);
index 97737b526c003ce9e7a5bb24a0aeca46046b87e4..46a586992b2fe2c8348d70b0d0fe6c1071f2e51d 100644 (file)
@@ -10,6 +10,18 @@ void reset_callstack(void)
        cs = cs_bot - CELLS;
 }
 
+void fix_stacks(void)
+{
+       if(STACK_UNDERFLOW(ds,ds_bot))
+               reset_datastack();
+       else if(STACK_OVERFLOW(ds,ds_bot))
+               reset_datastack();
+       else if(STACK_UNDERFLOW(cs,cs_bot))
+               reset_callstack();
+       else if(STACK_OVERFLOW(cs,cs_bot))
+               reset_callstack();
+}
+
 void init_stacks(void)
 {
        ds_bot = (CELL)alloc_guarded(STACK_SIZE);
index 061b97d92d2f7911b93ccd60f3dc080094516a20..5152483b66401b145687dd37e0796530eb1eca66 100644 (file)
@@ -3,6 +3,7 @@
 
 void reset_datastack(void);
 void reset_callstack(void);
+void fix_stacks(void);
 void init_stacks(void);
 
 void primitive_drop(void);
index 00a00d3bc358a813ceb5f0874e8cdbd36c8a842e..fdf756dc2d829b76cdb23fe54edb7691139dcb7f 100644 (file)
@@ -46,16 +46,6 @@ CELL T;
 CELL type_of(CELL tagged);
 bool typep(CELL type, CELL tagged);
 
-INLINE CELL tag_boolean(CELL untagged)
-{
-       return (untagged == false ? F : T);
-}
-
-INLINE bool untag_boolean(CELL tagged)
-{
-       return (tagged == F ? false : true);
-}
-
 INLINE CELL tag_header(CELL cell)
 {
        return RETAG(cell << TAG_BITS,HEADER_TYPE);
index e611fd4d4568bf1cd1db3ccb616f33e52cfd4436..86ff360a9966e6f561dd341a38afb3ef8285d86e 100644 (file)
@@ -110,10 +110,8 @@ void primitive_set_word_allot_count(void)
 
 void primitive_word_compiledp(void)
 {
-       WORD* word = untag_word(dpeek());
-       /* is it bad to hardcode this? */
-       drepl(tag_boolean(word->xt != (CELL)docol
-               && word->xt != (CELL)dosym));
+       WORD* word = untag_word(dpop());
+       box_boolean(word->xt != (CELL)docol && word->xt != (CELL)dosym);
 }
 
 void fixup_word(WORD* word)
index 363805b6bed2dbe0e1cbb026621b66e2b5aff7c9..c64a5ab541d4299ad0f1c4f6808a5ea3e20cf161 100644 (file)
@@ -46,7 +46,7 @@ void primitive_can_write(void)
        port = untag_port(dpop());
        len = to_fixnum(dpop());
        pending_io_error(port);
-       dpush(tag_boolean(can_write(port,len)));
+       box_boolean(can_write(port,len));
 }
 
 void primitive_add_write_io_task(void)