]> gitweb.factorcode.org Git - factor.git/commitdiff
SDL_gfx binding and many cleanups
authorSlava Pestov <slava@factorcode.org>
Sun, 17 Oct 2004 01:55:13 +0000 (01:55 +0000)
committerSlava Pestov <slava@factorcode.org>
Sun, 17 Oct 2004 01:55:13 +0000 (01:55 +0000)
37 files changed:
TODO.FACTOR.txt
factor/FactorInterpreter.java
factor/parser/PushWord.java [new file with mode: 0644]
library/assoc.factor
library/compiler/alien-types.factor
library/compiler/alien.factor
library/compiler/compile-all.factor
library/compiler/compiler.factor
library/compiler/generic.factor
library/compiler/ifte.factor
library/compiler/interpret-only.factor
library/cross-compiler.factor
library/lists.factor
library/platform/jvm/words.factor
library/platform/native/boot-stage2.factor
library/platform/native/math.factor
library/platform/native/parse-syntax.factor
library/platform/native/parser.factor
library/platform/native/primitives.factor
library/platform/native/words.factor
library/sdl/sdl-gfx.factor
library/sdl/sdl-video.factor
library/test/jvm-compiler/auxiliary.factor
library/test/jvm-compiler/compiler.factor
library/test/jvm-compiler/tail.factor
library/test/lists/assoc.factor
library/test/lists/java.factor
library/test/words.factor
library/words.factor
native/complex.c
native/complex.h
native/ffi.c
native/ffi.h
native/primitives.c
native/primitives.h
native/ratio.c
native/ratio.h

index f3497743b80a228dc87dce8abbe200ecf1ad2d4d..8f1c7ccada93486d0f75577f6ab1f542869968fe 100644 (file)
@@ -11,7 +11,7 @@ FFI:
 \r
 - when* compilation in jvm\r
 - compile word twice; no more 'cannot compile' error!\r
-- doc comments in assoc, image, inferior\r
+- doc comments in image, inferior\r
 - compiler: drop literal peephole optimization\r
 - compiling when*\r
 - compiling unless*\r
index 633de694f3c69465cf3871d3fd76c37b9b7bd839..1091a6bae7a0377ce6f5c3cf4b3261978e3b53e6 100644 (file)
@@ -214,6 +214,9 @@ public class FactorInterpreter implements FactorObject, Runnable
                FactorWord use = define("syntax","USE:");
                use.parsing = new Use(use);
 
+               FactorWord pushWord = define("syntax","\\");
+               pushWord.parsing = new PushWord(pushWord);
+
                FactorWord interpreterGet = define("builtins","interpreter");
                interpreterGet.def = new InterpreterGet(interpreterGet);
                interpreterGet.inline = true;
diff --git a/factor/parser/PushWord.java b/factor/parser/PushWord.java
new file mode 100644 (file)
index 0000000..226dbe5
--- /dev/null
@@ -0,0 +1,54 @@
+/* :folding=explicit: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.
+ */
+
+package factor.parser;
+
+import factor.*;
+
+public class PushWord extends FactorParsingDefinition
+{
+       //{{{ PushWord constructor
+       /**
+        * A new definition.
+        */
+       public PushWord(FactorWord word)
+               throws Exception
+       {
+               super(word);
+       } //}}}
+
+       public void eval(FactorInterpreter interp, FactorReader reader)
+               throws Exception
+       {
+               FactorWord word = reader.nextWord(false);
+               reader.append(new Cons(word,null));
+               reader.append(interp.searchVocabulary(
+                       new Cons("lists",null),"car"));
+       }
+}
index f397bf33a5edbf40f373f6ec20f9cee08b3f84c3..f0634cbe127bd181b522a1df3d0683739707f5a4 100644 (file)
@@ -31,9 +31,12 @@ USE: combinators
 USE: kernel
 USE: stack
 
+! An association list is a list of conses where the car of each
+! cons is a key, and the cdr is a value. See the Factor
+! Developer's Guide for details.
+
 : assoc? ( list -- ? )
-    #! Push if the list appears to be an alist (each element is
-    #! a cons).
+    #! Push if the list appears to be an alist.
     dup list? [ [ cons? ] all? ] [ drop f ] ifte ;
 
 : assoc* ( key alist -- [ key | value ] )
@@ -50,20 +53,22 @@ USE: stack
     ] ifte ;
 
 : assoc ( key alist -- value )
-    #! Looks up the key in an alist. An alist is a proper list
-    #! of comma pairs, the car of each pair is a key, the cdr is
-    #! the value. For example:
-    #! [ [ 1 | "one" ] [ 2 | "two" ] [ 3 | "three" ] ]
+    #! Looks up the key in an alist.
     assoc* dup [ cdr ] when ;
 
+: remove-assoc ( key alist -- alist )
+    #! Remove all key/value pairs with this key.
+    [ dupd car = not ] subset nip ;
+
 : acons ( value key alist -- alist )
+    #! Adds the key/value pair to the alist. Existing pairs with
+    #! this key are not removed; the new pair simply shadows
+    #! existing pairs.
     >r swons r> cons ;
 
 : set-assoc ( value key alist -- alist )
-    #! Sets the key in the alist. Does not modify the existing
-    #! list by consing a new key/value pair onto the alist. The
-    #! newly-added pair 'shadows' the previous value.
-    [ dupd car = not ] subset acons ;
+    #! Adds the key/value pair to the alist.
+    dupd remove-assoc acons ;
 
 : assoc-apply ( value-alist quot-alist -- )
     #! Looks up the key of each pair in the first list in the
index 08f4a8bbd0828563268c47c2dba7871aee07ab5e..98b32a1689bbe77bf12cbfcdc80c8e9e28f85774 100644 (file)
@@ -83,24 +83,20 @@ USE: words
     drop [ "width" get ] bind + ;
 
 : define-constructor ( len -- )
-    [ <alien> ] cons
-    <% "<" % "struct-name" get % ">" % %>
-    "in" get create swap
-    define-compound ;
-
-: define-local-constructor ( len -- )
+    #! Make a word <foo> where foo is the structure name that
+    #! allocates a Factor heap-local instance of this structure.
+    #! Used for C functions that expect you to pass in a struct.
     [ <local-alien> ] cons
-    <% "<local-" % "struct-name" get % ">" % %>
+    <% "<" % "struct-name" get % ">" % %>
     "in" get create swap
     define-compound ;
 
-: define-struct-type ( len -- )
-    #! For example, if len is 32, make a C type with getter:
-    #! [ 32 >r alien-cell r> <alien> ] cons
+: define-struct-type ( -- )
     #! The setter just throws an error for now.
     [
-        [ >r alien-cell r> <alien> ] cons "getter" set
+        [ alien-cell <alien> ] "getter" set
         "unbox_alien" "unboxer" set
+        "box_alien" "boxer" set
         cell "width" set
     ] "struct-name" get "*" cat2 define-c-type ;
 
@@ -110,18 +106,16 @@ USE: words
 : FIELD: ( offset -- offset )
     scan scan define-field ; parsing
 
-: END-STRUCT ( offset -- )
-    dup define-constructor
-    dup define-local-constructor
-    define-struct-type ; parsing
+: END-STRUCT ( length -- )
+    define-constructor define-struct-type ; parsing
 
 global [ <namespace> "c-types" set ] bind
 
 [
-    [ alien-cell ] "getter" set
+    [ alien-cell <alien> ] "getter" set
     [ set-alien-cell ] "setter" set
     cell "width" set
-    "does_not_exist" "boxer" set
+    "box_alien" "boxer" set
     "unbox_alien" "unboxer" set
 ] "void*" define-c-type
 
index 296300357622abb7dda200a546e9f5f460331fa5..58922377feacc1dfa1ea49a8ff0fdf807bc998f3 100644 (file)
@@ -82,5 +82,4 @@ USE: words
 
 global [ <namespace> "libraries" set ] bind
 
-[ alien-call compile-alien-call ]
-unswons "compiling" set-word-property
+\ alien-call [ compile-alien-call ] "compiling" set-word-property
index 5cd79b1ba388d31fb464845c3ef77be9d66cebe1..e397683b9c49b8332eee1bdc7041c7dd8b3ff373 100644 (file)
@@ -98,16 +98,21 @@ DEFER: can-compile-vector?
     dup "can-compile" word-property [
         drop t
     ] [
-        t over "can-compile" set-word-property
-        dup >r (can-compile) dup r>
-        "can-compile" set-word-property
+        dup t "can-compile" set-word-property
+        dup (can-compile)
+        [ "can-compile" set-word-property ] keep
     ] ifte ;
 
 SYMBOL: compilable-word-list
 
+: reset-can-compile ( -- )
+    [ f "can-compile" set-word-property ] each-word ;
+
 : compilable-words ( -- list )
     #! Make a list of all words that can be compiled.
-    [, [ dup can-compile? [ , ] [ drop ] ifte ] each-word ,] ;
+    reset-can-compile
+    [, [ dup can-compile? [ , ] [ drop ] ifte ] each-word ,]
+    reset-can-compile ;
 
 : cannot-compile ( word -- )
     "verbose-compile" get [
index c8332533b94b44b7edfa2f72beefed2f5f8d91f9..742d52588f5dbfe2db5a07c306f2b19945132a21 100644 (file)
@@ -59,7 +59,7 @@ SYMBOL: compiled-xts
     compiled-offset swap compiled-xts acons@ ;
 
 : commit-xt ( xt word -- )
-    t over "compiled" set-word-property  set-word-xt ;
+    dup t "compiled" set-word-property  set-word-xt ;
 
 : commit-xts ( -- )
     compiled-xts get [ unswons commit-xt ] each
index 3b7fc63740af92d4f3351b5dab5a08df4fd0bf2e..2e8a7e6c2015e9f92f801945789979e74d5d540f 100644 (file)
@@ -89,5 +89,5 @@ USE: vectors
     pop-literal commit-literals
     ARITHMETIC-TYPE  compile-jump-table ;
 
-[ compile-generic ] \ generic "compiling" set-word-property
-[ compile-2generic ] \ 2generic "compiling" set-word-property
+\ generic [ compile-generic ] "compiling" set-word-property
+\ 2generic [ compile-2generic ] "compiling" set-word-property
index 84ae87e4867c53a3982d2b7340b79711971a46dd..5aa2af70bda23b7920eb7aea6ac17df0c99eb3e4 100644 (file)
@@ -82,6 +82,6 @@ USE: lists
     ( f -- ) compile-quot
     r> end-if ;
 
-[ compile-ifte ] \ ifte "compiling" set-word-property
-[ compile-when ] \ when "compiling" set-word-property
-[ compile-unless ] \ unless "compiling" set-word-property
+\ ifte [ compile-ifte ] "compiling" set-word-property
+\ when [ compile-when ] "compiling" set-word-property
+\ unless [ compile-unless ] "compiling" set-word-property
index 9740cb5c3ace730f46ab2f1ee00b1109cc31c78b..5befbece8c1224e3b3a872c610418219e8901905 100644 (file)
@@ -38,9 +38,8 @@ USE: words
     "Cannot compile " swap cat2 throw ;
 
 : word-interpret-only ( word -- )
-    t over "interpret-only" set-word-property
+    dup t "interpret-only" set-word-property
     dup word-name [ interpret-only-error ] cons
-    swap
     "compiling" set-word-property ;
 
 \ call word-interpret-only
index 1bd90ab0491a44b36e3c9c72b8206971ca1a1663..228b1e2b7b186ed988f94fd5d5a7bfb85a98bb99 100644 (file)
@@ -228,14 +228,12 @@ IN: image
         >float
         numerator
         denominator
-        >fraction
         fraction>
         str>float
         unparse-float
         float>bits
         real
         imaginary
-        >rect
         rect>
         fixnum=
         fixnum+
index d668506070feb2bd7bae578d845fb0919bcb05ce..385facadaf060a4cd2aa74876a8b8fe50ab01cff 100644 (file)
@@ -42,7 +42,6 @@ USE: vectors
     2list cons ;
 
 : append ( [ list1 ] [ list2 ] -- [ list1 list2 ] )
-    #! Append two lists.
     over [ >r uncons r> append cons ] [ nip ] ifte ;
 
 : contains? ( element list -- remainder )
@@ -56,8 +55,7 @@ USE: vectors
     ] ifte ;
 
 : nth ( n list -- list[n] )
-    #! Gets the nth element of a proper list by successively
-    #! iterating down the cdr pointer.
+    #! Push the nth element of a proper list.
     #! Supplying n <= 0 pushes the first element of the list.
     #! Supplying an argument beyond the end of the list raises
     #! an error.
@@ -65,15 +63,10 @@ USE: vectors
 
 : last* ( list -- last )
     #! Pushes last cons of a list.
-    #! For example, given a proper list, pushes a cons cell
-    #! whose car is the last element of the list, and whose cdr
-    #! is f.
     dup cdr cons? [ cdr last* ] when ;
 
 : last ( list -- last )
-    #! Pushes last element of a list. Since this pushes the
-    #! car of the last cons cell, the list may be an improper
-    #! list.
+    #! Pushes last element of a list.
     last* car ;
 
 : list? ( list -- boolean )
@@ -155,29 +148,25 @@ DEFER: tree-contains?
     #! already contained in the list.
     2dup contains? [ nip ] [ cons ] ifte ;
 
-: each ( list quotation -- )
+: each-step ( list quot -- list quot )
+    >r uncons r> tuck 2slip ; inline interpret-only
+
+: each ( list quot -- )
     #! Push each element of a proper list in turn, and apply a
-    #! quotation to each element.
-    #!
-    #! The quotation must consume one more value than it
-    #! produces.
-    over [ >r uncons r> tuck 2slip each ] [ 2drop ] ifte ;
+    #! quotation with effect ( X -- ) to each element.
+    over [ each-step each ] [ 2drop ] ifte ;
     inline interpret-only
 
 : reverse ( list -- list )
     #! Push a new list that is the reverse of a proper list.
     [ ] swap [ swons ] each ;
 
-: map ( list code -- list )
-    #! Applies the code to each item, returns a list that
-    #! contains the result of each application.
-    #!
-    #! The quotation must consume as many values as it
-    #! produces.
-    f transp [
-        ! accum code elem -- accum code
-        transp over >r >r call r> cons r>
-    ] each drop reverse ; inline interpret-only
+: map ( list quot -- list )
+    #! Push each element of a proper list in turn, and collect
+    #! return values of applying a quotation with effect
+    #! ( X -- Y ) to each element into a new list.
+    over [ each-step rot >r map r> swons ] [ drop ] ifte ;
+    inline interpret-only
 
 : 2uncons ( list1 list2 -- car1 car2 cdr1 cdr2 )
     uncons >r >r uncons r> swap r> ;
index a0e5072a58abc1d1e33d692f0f45a8e4d9e58a2b..b00b0caa842ab2493110fc4f84946b1b8b702274 100644 (file)
@@ -45,8 +45,8 @@ USE: stack
 : word-property ( word pname -- pvalue )
     swap [ get ] bind ;
 
-: set-word-property ( pvalue word pname -- )
-    swap [ set ] bind ;
+: set-word-property ( word pvalue pname -- )
+    rot [ set ] bind ;
 
 : redefine ( word def -- )
     swap [ "def" set ] bind ;
index 758ead07f92e70627335a6ca608ac09338f0ca28..a65a2f1ac95e1c2d86ffb922960164942dd789fd 100644 (file)
@@ -161,6 +161,7 @@ cpu "x86" = [
         "/library/sdl/sdl-video.factor"
         "/library/sdl/sdl-event.factor"
         "/library/sdl/sdl-gfx.factor"
+        "/library/sdl/sdl-utils.factor"
         "/library/sdl/hsv.factor"
     ] [
         dup print
@@ -190,6 +191,9 @@ DEFER: init-interpreter
 
 compilable-words compilable-word-list set
 
+! Save a bit of space
+global [ "stdio" off ] bind
+
 garbage-collection
 "factor.image" save-image
 0 exit*
index 926d9b7e402543e61f270017ed89650f9798ef76..48246fe19c65816425fc1fab5ebea0a69f5d60cc 100644 (file)
@@ -39,6 +39,7 @@ USE: words
 : reduce ( x y -- x' y' )
     dup 0 < [ swap neg swap neg ] when 2dup gcd tuck /i >r /i r> ;
 : ratio ( x y -- x/y ) reduce fraction> ;
+: >fraction ( a/b -- a b ) dup numerator swap denominator ;
 : 2>fraction ( a/b c/d -- a b c d ) >r >fraction r> >fraction ;
 
 : ratio= ( a/b c/d -- ? ) 2>fraction 2= ;
@@ -55,6 +56,7 @@ USE: words
 : ratio> ( x y -- ? ) ratio-scale > ;
 : ratio>= ( x y -- ? ) ratio-scale >= ;
 
+: >rect ( x -- x:re x: im ) dup real swap imaginary ;
 : 2>rect ( x y -- x:re x:im y:re y:im ) >r >rect r> >rect ;
 
 : complex= ( x y -- ? ) 2>rect 2= ;
index dae895b62a19cc187341c87c3479e92cb76a95ce..cc623d42899348e29c162e15fdcf992f738138aa 100644 (file)
@@ -44,14 +44,13 @@ USE: unparser
 ! Colon defs
 : CREATE ( -- word )
     scan "in" get create dup set-word
-    f over "documentation" set-word-property
-    f over "stack-effect" set-word-property ;
+    dup f "documentation" set-word-property
+    dup f "stack-effect" set-word-property ;
 
 : remember-where ( word -- )
-    "line-number" get over "line" set-word-property
-    "col"         get over "col"  set-word-property
-    "file"        get over "file" set-word-property
-    drop ;
+    dup "line-number" get "line" set-word-property
+    dup "col"         get "col"  set-word-property
+        "file"        get "file" set-word-property ;
 
 ! \x
 : unicode-escape>ch ( -- esc )
@@ -92,22 +91,20 @@ USE: unparser
 
 : parsed-stack-effect ( parsed str -- parsed )
     over doc-comment-here? [
-        word "stack-effect" set-word-property
+        word swap "stack-effect" set-word-property
     ] [
         drop
     ] ifte ;
 
-: documentation+ ( str word -- )
-    [
-        "documentation" word-property [
-            swap "\n" swap cat3
-        ] when*
-    ] keep
+: documentation+ ( word str -- )
+    over "documentation" word-property [
+        swap "\n" swap cat3
+    ] when*
     "documentation" set-word-property ;
 
 : parsed-documentation ( parsed str -- parsed )
     over doc-comment-here? [
-        word documentation+
+        word swap documentation+
     ] [
         drop
     ] ifte ;
index 383faa1b51c0a68bb0738571bebd128eb6fea47a..6f0f61d8140cc5b0dad78371edcd7f3c3bfcb3eb 100644 (file)
@@ -59,7 +59,7 @@ USE: unparser
     #! Mark the most recently defined word to execute at parse
     #! time, rather than run time. The word can use 'scan' to
     #! read ahead in the input stream.
-    t word "parsing" set-word-property ;
+    word t "parsing" set-word-property ;
 
 : end? ( -- ? )
     "col" get "line" get str-length >= ;
@@ -185,4 +185,4 @@ USE: unparser
 ! Once this file has loaded, we can use 'parsing' normally.
 ! This hack is needed because in Java Factor, 'parsing' is
 ! not parsing, but in CFactor, it is.
-t "parsing" [ "parser" ] search "parsing" set-word-property
+\ parsing t "parsing" set-word-property
index 19f299b485d7af002e4c7bd224cf560a0409fd2e..2a8d12c213e1feadde23f347798b8e5bd3bac149 100644 (file)
@@ -82,14 +82,12 @@ USE: words
     [ >float                 | " n -- float " ]
     [ numerator              | " a/b -- a " ]
     [ denominator            | " a/b -- b " ]
-    [ >fraction              | " a/b -- a b " ]
     [ fraction>              | " a b -- a/b " ]
     [ str>float              | " str -- float " ]
     [ unparse-float          | " float -- str " ]
     [ float>bits             | " float -- n " ]
     [ real                   | " #{ re im } -- re " ]
     [ imaginary              | " #{ re im } -- im " ]
-    [ >rect                  | " #{ re im } -- re im " ]
     [ rect>                  | " re im -- #{ re im } " ]
     [ fixnum=                | " x y -- ? " ]
     [ fixnum+                | " x y -- x+y " ]
@@ -222,7 +220,7 @@ USE: words
     [ dlsym                  | " name dll -- ptr " ]
     [ dlsym-self             | " name -- ptr " ]
     [ dlclose                | " dll -- " ]
-    [ <alien>                | " ptr len -- alien " ]
+    [ <alien>                | " ptr -- alien " ]
     [ <local-alien>          | " len -- alien " ]
     [ alien-cell             | " alien off -- n " ]
     [ set-alien-cell         | " n alien off -- " ]
@@ -235,5 +233,5 @@ USE: words
     [ heap-stats             | " -- instances bytes " ]
     [ throw                  | " error -- " ]
 ] [
-    unswons "stack-effect" set-word-property
+    uncons "stack-effect" set-word-property
 ] each
index 2f662fed5ecb996945a7b8f9d815c9299a5deeb5..4eb7eeacfb7d78dae80e596c357ce84d9f9f6999 100644 (file)
@@ -37,8 +37,9 @@ USE: stack
 : word-property ( word pname -- pvalue )
     swap word-plist assoc ;
 
-: set-word-property ( pvalue word pname -- )
-    swap [ word-plist set-assoc ] keep set-word-plist ;
+: set-word-property ( word pvalue pname -- )
+    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 ;
index 7b2a5ce0894de49669f798cc3bf300d3d30ebb59..816f211725c91e2b1695cfd7886b8ae30b1e92e5 100644 (file)
 IN: sdl
 USE: alien
-USE: math
-USE: namespaces
-USE: stack
-USE: compiler
-USE: words
-USE: parser
-USE: kernel
-USE: errors
-USE: combinators
-USE: lists
-USE: logic
-
-! This is a kind of high level wrapper around SDL, and turtle
-! graphics, in one messy, undocumented package. Will be improved
-! later, and heavily refactored, so don't count on this
-! interface remaining unchanged.
-
-SYMBOL: surface
-SYMBOL: pixels
-SYMBOL: format
-SYMBOL: pen
-SYMBOL: angle
-SYMBOL: color
-
-: xy-4 ( #{ x y } -- offset )
-    >rect surface get surface-pitch * swap 4 * + ;
-
-: set-pixel-4 ( color #{ x y } -- )
-    xy-4 pixels get swap set-alien-4 ;
-
-: rgb ( r g b -- value )
-    >r >r >r format get r> r> r> SDL_MapRGB ;
-
-: pixel-4-step ( quot #{ x y } -- )
-    dup >r swap call rgb r> set-pixel-4 ;
-
-: with-pixels-4 ( w h quot -- )
-    -rot rect> [ over >r pixel-4-step r> ] 2times* drop ;
-
-: move ( #{ x y } -- )
-    pen +@ ;
-
-: turn ( angle -- )
-    angle +@ ;
-
-: move-d ( distance -- )
-    angle get cis * move ;
-
-: pixel ( -- )
-    color get pen get set-pixel-4 ;
-
-: sgn ( x -- -1/0/1 ) dup 0 = [ 0 < -1 1 ? ] unless ;
-
-: line-h-step ( #{ dx dy } #{ px py } p -- p )
-    over real fixnum- dup 0 < [
-        swap imaginary fixnum+ swap
-    ] [
-        nip swap real
-    ] ifte move pixel ;
-
-: line-more-h ( #{ dx dy } #{ px py } -- )
-    dup imaginary 2 fixnum/i over imaginary [
-        >r 2dup r> line-h-step
-    ] times 3drop ;
-
-: line-v-step ( #{ dx dy } #{ px py } p -- p )
-    over imaginary fixnum- dup 0 fixnum< [
-        swap real fixnum+ swap
-    ] [
-        nip swap imaginary 0 swap rect>
-    ] ifte move pixel ;
-
-: line-more-v ( #{ dx dy } #{ px py } -- )
-    dup real 2 fixnum/i over real [
-        >r 2dup r> line-v-step
-    ] times 3drop ;
-
-: line ( #{ x y } -- )
-    pixel ( first point )
-    dup >r >rect swap sgn swap sgn rect> r>
-    >rect swap abs swap abs 2dup fixnum< [
-        rect> line-more-h
-    ] [
-        rect> line-more-v
-    ] ifte ;
-
-: line-d ( distance -- )
-    angle get cis * line ;
-
-: with-surface ( quot -- )
-    #! Execute a quotation, locking the current surface if it
-    #! is required (eg, hardware surface).
-    surface get dup must-lock-surface? [
-        dup SDL_LockSurface slip SDL_UnlockSurface
-    ] [
-        drop call
-    ] ifte surface get SDL_Flip ;
-
-: event-loop ( event -- )
-    dup SDL_WaitEvent 1 = [
-        dup event-type SDL_QUIT = [
-            drop
-        ] [
-            event-loop
-        ] ifte
-    ] [
-        drop
-    ] ifte ;
+
+: pixelColor ( surface x y color -- )
+    "void" "sdl-gfx" "pixelColor"
+    [ "surface*" "short" "short" "uint" ]
+    alien-call ;
+
+: hlineColor ( surface x1 x2 y color -- )
+    "void" "sdl-gfx" "hlineColor"
+    [ "surface*" "short" "short" "short" "uint" ]
+    alien-call ;
+
+: vlineColor ( surface x y1 y2 color -- )
+    "void" "sdl-gfx" "vlineColor"
+    [ "surface*" "short" "short" "short" "uint" ]
+    alien-call ;
+
+: rectangleColor ( surface x1 y1 x2 y2 color -- )
+    "void" "sdl-gfx" "rectangleColor"
+    [ "surface*" "short" "short" "short" "short" "uint" ]
+    alien-call ;
+
+: boxColor ( surface x1 y1 x2 y2 color -- )
+    "void" "sdl-gfx" "boxColor"
+    [ "surface*" "short" "short" "short" "short" "uint" ]
+    alien-call ;
+
+: lineColor ( surface x1 y1 x2 y2 color -- )
+    "void" "sdl-gfx" "lineColor"
+    [ "surface*" "short" "short" "short" "short" "uint" ]
+    alien-call ;
+
+: aalineColor ( surface x1 y1 x2 y2 color -- )
+    "void" "sdl-gfx" "aalineColor"
+    [ "surface*" "short" "short" "short" "short" "uint" ]
+    alien-call ;
+
+: circleColor ( surface x y r color -- )
+    "void" "sdl-gfx" "circleColor"
+    [ "surface*" "short" "short" "short" "uint" ]
+    alien-call ;
+
+: aacircleColor ( surface x y r color -- )
+    "void" "sdl-gfx" "aacircleColor"
+    [ "surface*" "short" "short" "short" "uint" ]
+    alien-call ;
+
+: filledCircleColor ( surface x y r color -- )
+    "void" "sdl-gfx" "filledCircleColor"
+    [ "surface*" "short" "short" "short" "uint" ]
+    alien-call ;
+
+: ellipseColor ( surface x y rx ry color -- )
+    "void" "sdl-gfx" "ellipseColor"
+    [ "surface*" "short" "short" "short" "short" "uint" ]
+    alien-call ;
+
+: aaellipseColor ( surface x y rx ry color -- )
+    "void" "sdl-gfx" "aaellipseColor"
+    [ "surface*" "short" "short" "short" "short" "uint" ]
+    alien-call ;
+
+: filledEllipseColor ( surface x y rx ry color -- )
+    "void" "sdl-gfx" "filledEllipseColor"
+    [ "surface*" "short" "short" "short" "short" "uint" ]
+    alien-call ;
+
+: pieColor ( surface x y rad start end color -- )
+    "void" "sdl-gfx" "pieColor"
+    [ "surface*" "short" "short" "short" "short" "short" "uint" ]
+    alien-call ;
+
+: filledPieColor ( surface x y rad start end color -- )
+    "void" "sdl-gfx" "filledPieColor"
+    [ "surface*" "short" "short" "short" "short" "short" "uint" ]
+    alien-call ;
+
+: trigonColor ( surface x1 y1 x2 y2 x3 y3 color -- )
+    "void" "sdl-gfx" "trigonColor"
+    [ "surface*" "short" "short" "short" "short" "short" "short" "uint" ]
+    alien-call ;
+
+: aatrigonColor ( surface x1 y1 x2 y2 x3 y3 color -- )
+    "void" "sdl-gfx" "aatrigonColor"
+    [ "surface*" "short" "short" "short" "short" "short" "short" "uint" ]
+    alien-call ;
+
+: filledTrigonColor ( surface x1 y1 x2 y2 x3 y3 color -- )
+    "void" "sdl-gfx" "filledTrigonColor"
+    [ "surface*" "short" "short" "short" "short" "short" "short" "uint" ]
+    alien-call ;
+
+: characterColor ( surface x y c color -- )
+    "void" "sdl-gfx" "characterColor"
+    [ "surface*" "short" "short" "char" "uint" ]
+    alien-call ;
+
+: stringColor ( surface x y str color -- )
+    "void" "sdl-gfx" "stringColor"
+    [ "surface*" "short" "short" "char*" "uint" ]
+    alien-call ;
index 6078de03905121af20e1d7e97b7b91ea1dd3ee77..e2ba6c08475c83329b586566efe174974ae1f431 100644 (file)
@@ -114,7 +114,7 @@ END-STRUCT
     ] ifte ;
 
 : SDL_VideoInit ( driver-name flags -- )
-    "int" "sdl" "SDL_SetVideoMode"
+    "int" "sdl" "SDL_VideoInit"
     [ "char*" "int" ] alien-call ;
 
 : SDL_VideoQuit ( -- )
@@ -134,7 +134,7 @@ END-STRUCT
 ! SDL_ListModes needs array of structs support
 
 : SDL_SetVideoMode ( width height bpp flags -- )
-    "int" "sdl" "SDL_SetVideoMode"
+    "surface*" "sdl" "SDL_SetVideoMode"
     [ "int" "int" "int" "int" ] alien-call ;
 
 ! UpdateRects, UpdateRect
index 84790b188c2e9ab76b1358bde7062ac68ae679ba..ac118eecf2cc58a49001a8eca687833cab6aaa75 100644 (file)
@@ -33,10 +33,6 @@ USE: words
 [ ] [ ] [ ??nop ] test-word
 [ ] [ ] [ ???nop ] test-word
 
-: while-test [ f ] [ ] while ; word must-compile
-
-[ ] [ ] [ while-test ] test-word
-
 : times-test-1 [ nop ] times ; word must-compile
 : times-test-2 [ succ ] times ; word must-compile
 : times-test-3 0 10 [ succ ] times ; word must-compile
index 380e9c886abf2960493d59438cda394561fe2ecb..dd5e7e28fc0b26e012da1c5a2adedc5a1822b170 100644 (file)
@@ -45,10 +45,10 @@ USE: words
 
 [ [ 0 0 0 0 ] ] [ [ null-rec ] ] [ balance>list ] test-word
 
-: null-rec ( -- )
-    t [ drop null-rec ] when* ; word must-compile
-
-[ [ 0 0 0 0 ] ] [ [ null-rec ] ] [ balance>list ] test-word
+: null-rec ( -- )
+    t [ drop null-rec ] when* ; word must-compile
+! 
+[ [ 0 0 0 0 ] ] [ [ null-rec ] ] [ balance>list ] test-word
 
 !: null-rec ( -- )
 !    t [ t null-rec ] unless* drop ; word must-compile test-null-rec
index 6e58ab50543199217fe90c8f6d86a48f8bc11df3..9f66955454fb3ee9a72e05e9334b3fcb7f01d27d 100644 (file)
@@ -23,11 +23,6 @@ USE: words
 
 [ ] [ ] [ tail-call-1 ] test-word
 
-: tail-call-2 ( list -- f )
-    [ dup cons? ] [ uncons nip ] while ; word must-compile
-
-[ f ] [ [ 1 2 3 ] ] [ tail-call-2 ] test-word
-
 : tail-call-3 ( x y -- z )
     >r dup succ r> swap 6 = [
         +
index 26bbc346c7bbcbd9ef3b1349fc1f552a993e7ea8..66511cd005103bc7f6736c55796040fd9787db72 100644 (file)
@@ -41,3 +41,7 @@ USE: test
 
 [ 8 ] [ 1 "value-alist" get "quot-alist" get assoc-apply ] unit-test
 [ 1 ] [ 1 "value-alist" get f assoc-apply ] unit-test
+
+[ [ [ "one" + ] [ "four" * ] ] ] [
+    "three" "quot-alist" get remove-assoc
+] unit-test
index 3ef6163ce7cb9f9c66925c0b4b817679a6bc6562..671eb11d8f4e8f25814db5b639417d39a04ea4c8 100644 (file)
@@ -9,7 +9,6 @@ USE: test
 [ [ 3 1 0 0 ] ] [ [ 3list ] ] [ balance>list ] test-word
 [ [ 2 1 0 0 ] ] [ [ append ] ] [ balance>list ] test-word
 [ [ 1 1 0 0 ] ] [ [ array>list ] ] [ balance>list ] test-word
-[ [ 2 0 0 0 ] ] [ [ add@ ] ] [ balance>list ] test-word
 [ [ 1 1 0 0 ] ] [ [ car ] ] [ balance>list ] test-word
 [ [ 1 1 0 0 ] ] [ [ cdr ] ] [ balance>list ] test-word
 [ [ 2 1 0 0 ] ] [ [ cons ] ] [ balance>list ] test-word
@@ -21,7 +20,6 @@ USE: test
 [ [ 1 1 0 0 ] ] [ [ last ] ] [ balance>list ] test-word
 [ [ 1 1 0 0 ] ] [ [ length ] ] [ balance>list ] test-word
 [ [ 1 1 0 0 ] ] [ [ list? ] ] [ balance>list ] test-word
-[ [ 1 1 0 0 ] ] [ [ nreverse ] ] [ balance>list ] test-word
 [ [ 1 1 0 0 ] ] [ [ cons? ] ] [ balance>list ] test-word
 [ [ 2 1 0 0 ] ] [ [ remove ] ] [ balance>list ] test-word
 [ [ 1 1 0 0 ] ] [ [ reverse ] ] [ balance>list ] test-word
index 042591472508692173eedaf6b3ba6b3a7e3229ce..b26e067f0f5d471ab48030a3be1587188ca209be 100644 (file)
@@ -16,6 +16,17 @@ USE: lists
 
 [ t           ] [                 ] [ words-test        ] test-word
 
+DEFER: plist-test
+
+[ t ] [
+    \ plist-test t "sample-property" set-word-property
+    \ plist-test "sample-property" word-property
+] unit-test
+
+[ f ] [
+    \ plist-test f "sample-property" set-word-property
+    \ plist-test "sample-property" word-property
+] unit-test
 
 : test-last ( -- ) ;
 word word-name "last-word-test" set
index 35fc4cec68ec7b99fd505f6139cfa587747d445a..8a5963622b35003192f2de0a603963bdf8ae9663 100644 (file)
@@ -36,15 +36,9 @@ USE: stack
 : word-name ( word -- name )
     "name" word-property ;
 
-: set-word-name ( word name -- )
-    "name" set-word-property ;
-
 : word-vocabulary ( word -- vocab )
     "vocabulary" word-property ;
 
-: set-word-vocabulary ( word vocab -- )
-    "vocabulary" set-word-property ;
-
 : each-word ( quot -- )
     #! Apply a quotation to each word in the image.
     vocabs [ words [ swap dup >r call r> ] each ] each drop ;
index 34ccbf7d31ca8159f77a8c9d63bce9747331c89f..9167a117b5c6e352cae31ba1fbc051aec19fb088 100644 (file)
@@ -38,28 +38,6 @@ void primitive_imaginary(void)
        }
 }
 
-void primitive_to_rect(void)
-{
-       COMPLEX* c;
-       switch(type_of(dpeek()))
-       {
-       case FIXNUM_TYPE:
-       case BIGNUM_TYPE:
-       case FLOAT_TYPE:
-       case RATIO_TYPE:
-               dpush(tag_fixnum(0));
-               break;
-       case COMPLEX_TYPE:
-               c = untag_complex(dpop());
-               dpush(c->real);
-               dpush(c->imaginary);
-               break;
-       default:
-               type_error(NUMBER_TYPE,dpeek());
-               break;
-       }
-}
-
 void primitive_from_rect(void)
 {
        CELL imaginary, real;
index 5640c4244a377e298bbd93071a56ca1e4abc01eb..02f8152f97563987d671c2b92b603c026de87cfd 100644 (file)
@@ -16,5 +16,4 @@ INLINE CELL tag_complex(COMPLEX* complex)
 
 void primitive_real(void);
 void primitive_imaginary(void);
-void primitive_to_rect(void);
 void primitive_from_rect(void);
index 93fa0e3f974ccd27734161a71d7d4ff2f5776c02..8ae3daabadf42f39b0f4c0eb9bf012d486463150 100644 (file)
@@ -81,18 +81,39 @@ void primitive_dlclose(void)
 #endif
 }
 
+#ifdef FFI
+CELL unbox_alien(void)
+{
+       return untag_alien(dpop())->ptr;
+}
+
+void box_alien(CELL ptr)
+{
+       ALIEN* alien = allot_object(ALIEN_TYPE,sizeof(ALIEN));
+       alien->ptr = ptr;
+       alien->local = false;
+       dpush(tag_object(alien));
+}
+
+INLINE CELL alien_pointer(void)
+{
+       FIXNUM offset = unbox_integer();
+       ALIEN* alien = untag_alien(dpop());
+       CELL ptr = alien->ptr;
+
+       if(ptr == NULL)
+               general_error(ERROR_EXPIRED,tag_object(alien));
+
+       return ptr + offset;
+}
+#endif
+
 void primitive_alien(void)
 {
 #ifdef FFI
-       CELL length = unbox_integer();
        CELL ptr = unbox_integer();
-       ALIEN* alien;
        maybe_garbage_collection();
-       alien = allot_object(ALIEN_TYPE,sizeof(ALIEN));
-       alien->ptr = ptr;
-       alien->length = length;
-       alien->local = false;
-       dpush(tag_object(alien));
+       box_alien(ptr);
 #else
        general_error(ERROR_FFI_DISABLED,F);
 #endif
@@ -108,7 +129,6 @@ void primitive_local_alien(void)
        alien = allot_object(ALIEN_TYPE,sizeof(ALIEN));
        local = string(length / CHARS,'\0');
        alien->ptr = (CELL)local + sizeof(STRING);
-       alien->length = length;
        alien->local = true;
        dpush(tag_object(alien));
 #else
@@ -116,31 +136,6 @@ void primitive_local_alien(void)
 #endif
 }
 
-#ifdef FFI
-CELL unbox_alien(void)
-{
-       return untag_alien(dpop())->ptr;
-}
-
-INLINE CELL alien_pointer(void)
-{
-       FIXNUM offset = unbox_integer();
-       ALIEN* alien = untag_alien(dpop());
-       CELL ptr = alien->ptr;
-
-       if(ptr == NULL)
-               general_error(ERROR_EXPIRED,tag_object(alien));
-
-       if(offset < 0 || offset >= alien->length)
-       {
-               range_error(tag_object(alien),offset,alien->length);
-               return 0; /* can't happen */
-       }
-       else
-               return ptr + offset;
-}
-#endif
-
 void primitive_alien_cell(void)
 {
 #ifdef FFI
index bfda3ad72321af78b0d97de8b1c4aac5ec716dbe..32a95cf9cd7a4626e48870b697ded6556b53a85e 100644 (file)
@@ -8,7 +8,6 @@ DLL* untag_dll(CELL tagged);
 typedef struct {
        CELL header;
        CELL ptr;
-       CELL length;
        /* local aliens are heap-allocated as strings and must be collected. */
        bool local;
 } ALIEN;
index a3c05b0ca7c865497be43a5161aac8e78e40ae98..9f7c9d72273cc3e1584466dd6695b89eb4a2f409 100644 (file)
@@ -41,14 +41,12 @@ XT primitives[] = {
        primitive_to_float,
        primitive_numerator,
        primitive_denominator,
-       primitive_to_fraction,
        primitive_from_fraction,
        primitive_str_to_float,
        primitive_float_to_str,
        primitive_float_to_bits,
        primitive_real,
        primitive_imaginary,
-       primitive_to_rect,
        primitive_from_rect,
        primitive_fixnum_eq,
        primitive_fixnum_add,
index fcaddc66ee1bd273e0eb4fe84adede44e7612a65..c41f8b479683b3598b4042b856963ede5a3bc84d 100644 (file)
@@ -1,4 +1,4 @@
 extern XT primitives[];
-#define PRIMITIVE_COUNT 194
+#define PRIMITIVE_COUNT 191
 
 CELL primitive_to_xt(CELL primitive);
index 2df44e6f08c3004dcf95d9275d697b40378526cd..c8b0eb097f589479c4602826256b699945b25c10 100644 (file)
@@ -23,27 +23,6 @@ void primitive_from_fraction(void)
        }
 }
 
-void primitive_to_fraction(void)
-{
-       RATIO* r;
-
-       switch(type_of(dpeek()))
-       {
-       case FIXNUM_TYPE:
-       case BIGNUM_TYPE:
-               dpush(tag_fixnum(1));
-               break;
-       case RATIO_TYPE:
-               r = untag_ratio(dpeek());
-               drepl(r->numerator);
-               dpush(r->denominator);
-               break;
-       default:
-               type_error(RATIONAL_TYPE,dpeek());
-               break;
-       }
-}
-
 void primitive_numerator(void)
 {
        switch(type_of(dpeek()))
index 4f83905991098c726b8f430b75fc2b98ef08af67..fd09cb9d44969c57c4460389837b2eb63c46069e 100644 (file)
@@ -17,4 +17,3 @@ INLINE CELL tag_ratio(RATIO* ratio)
 void primitive_numerator(void);
 void primitive_denominator(void);
 void primitive_from_fraction(void);
-void primitive_to_fraction(void);