]> gitweb.factorcode.org Git - factor.git/commitdiff
added plot3d example; some cleanups
authorSlava Pestov <slava@factorcode.org>
Mon, 23 May 2005 02:54:14 +0000 (02:54 +0000)
committerSlava Pestov <slava@factorcode.org>
Mon, 23 May 2005 02:54:14 +0000 (02:54 +0000)
TODO.FACTOR.txt
doc/handbook.tex
examples/cube3d.factor [deleted file]
examples/dump.factor [new file with mode: 0644]
examples/plot3d.factor [new file with mode: 0644]
library/bootstrap/boot-stage3.factor
library/tools/dump.factor [deleted file]

index a6d5ed4be1c32a4458b8d8d2138779dea60eb032..63ae9902b78e8adb3ec7b3af7f4943facaae7df3 100644 (file)
@@ -9,31 +9,19 @@
 - single-stepper and variable access: wrong namespace?\r
 - [ over ] generics no-method\r
 - investigate if COPYING_GEN needs a fix\r
-- simplifier:\r
-  - kill tag-fixnum/untag-fixnum\r
-  - kill replace after a peek\r
-  - merge inc-d's across VOPs that don't touch the stack\r
 - faster layout\r
-- tiled window manager\r
-- c primitive arrays: or just specialized arrays\r
-  float, complex, byte, char, cell...\r
 - add a socket timeout\r
 - virtual hosts\r
 - keep alive\r
 - sleep word\r
 - redo new compiler backend for PowerPC\r
-\r
-- plugin: supportsBackspace\r
-- if external factor is down, don't add tons of random shit to the       \r
-  dictionary\r
-- SDL_Rect** type\r
 - fix i/o on generic x86/ppc unix\r
 - alien primitives need a more general input type\r
 - 2map slow with lists\r
 - nappend: instead of using push, enlarge the sequence with set-length\r
   then add set the elements with set-nth\r
 - faster sequence operations\r
-- generic some? all? memq? all=?\r
+- generic some? all? memq? fiber?\r
 - index and index* are very slow with lists\r
 - code walker & exceptions\r
 - if two tasks write to a unix stream, the buffer can overflow\r
@@ -42,7 +30,6 @@
 - dipping seq-2nmap, seq-2each\r
 - array sort\r
 - images saved from plugin do not work\r
-- making an image from plugin hangs\r
 - generic skip\r
 - inference needs to be more robust with heavily recursive code\r
 - investigate orphans\r
 + plugin:\r
 \r
 - word preview for parsing words\r
+- plugin: supportsBackspace\r
+- if external factor is down, don't add tons of random shit to the       \r
+  dictionary\r
 \r
 + ui:\r
 \r
+- tiled window manager\r
 - faster repaint\r
 - console with presentations\r
 - ui browser\r
 \r
 + compiler:\r
 \r
+- simplifier:\r
+  - kill tag-fixnum/untag-fixnum\r
+  - kill replace after a peek\r
+  - merge inc-d's across VOPs that don't touch the stack\r
 - [ EAX 0 ] --> [ EAX ]\r
 - intrinsic char-slot set-char-slot integer-slot set-integer-slot\r
 - optimize the generic word prologue\r
@@ -93,6 +88,7 @@
 \r
 + sequences\r
 \r
+- specialized arrays\r
 - list map, subset: not tail recursive\r
 - phase out sbuf-append\r
 \r
index 90ce9f227e488602e830b3103a2788e60677d884..cc4f04bdd50a273980923153d87161e979678fa3 100644 (file)
@@ -2359,7 +2359,7 @@ Outputs a new list containing all elements of the \texttt{list} except \texttt{o
 Outputs a list of elements present in both lists.
 \wordtable{
 \vocabulary{lists}
-\ordinaryword{intersection}{difference ( l1 l2 -- list )}
+\ordinaryword{difference}{difference ( l1 l2 -- list )}
 }
 Outputs a list of elements present in \texttt{l2} but not \texttt{l1}.
 
@@ -2533,6 +2533,11 @@ String buffers support the stream output protocol (\ref{stream-protocol}).
 
 \subsection{\label{virtual-seq}Virtual sequences}
 
+\glossary{name=virtual sequence,
+description={a sequence that is not backed by actual storage, but instead either computes its values, or take them from an underlying sequence}}
+\glossary{name=repeated sequence,
+description={an instance of the \texttt{repeated} class, which is a virtual, immutable sequence consisting of a fixed element repeated a certain number of times}}
+
 Virtual sequences are not backed by actual storage, but instead either compute their values, or take them from an underlying sequence.
 
 \wordtable{
@@ -2547,6 +2552,8 @@ Creates an immutable sequence consisting of \verb|object| repeated $n$ times. No
 [ "hey" "hey" "hey" "hey" "hey" ]
 \end{alltt}
 
+\glossary{name=range sequence,
+description={an instance of the \texttt{range} class, which is a virtual sequence of integers}}
 \wordtable{
 \vocabulary{sequences}
 \ordinaryword{<range>}{<range> ( a b -- seq )}
@@ -2560,6 +2567,8 @@ Creates an immutable sequence consisting of all integers in the interval $[a,b)$
 \textbf{ok} CHAR: z CHAR: a 1 - <range> >string .
 "zyxwvutsrqponmlkjihgfedcba"
 \end{alltt}
+\glossary{name=slice,
+description={an instance of the \texttt{slice} class, which is a virtual sequence sharing structure with a subrange of some underlying sequence}}
 
 \wordtable{
 \vocabulary{sequences}
@@ -2583,16 +2592,19 @@ Creates a slice viewing all elements of the sequence, starting at the $n$th inde
 }
 Creates a slice viewing the last $n$ elements of the input sequence.
 
-There is a natural duality between the four slicing words above, and the four subsequence words from \ref{subseq}:
+There is a correspondence between the four slicing words above, and the subsequence words from \ref{subseq}:
 
-\begin{tabular}[t]{l|l|l}
+\begin{tabular}[t]{l|l}
 Subsequence&Slice\\
+\hline
 \verb|subseq|&\verb|<slice>|\\
 \verb|head|&\verb|head-slice|\\
 \verb|tail|&\verb|tail-slice|\\
 \verb|tail*|&\verb|tail-slice*|
 \end{tabular}
 
+The slice words output a new virtual sequence that shares structure with the original sequence, whereas the subsequence words output a fresh copied sequence.
+
 \subsection{\label{make-seq}Constructing sequences}
 
 The library supports an idiom where sequences can be constructed without passing the partial sequence being built on the stack. This reduces stack noise, and thus simplifies code and makes it easier to understand.
diff --git a/examples/cube3d.factor b/examples/cube3d.factor
deleted file mode 100644 (file)
index 89fc24d..0000000
+++ /dev/null
@@ -1,112 +0,0 @@
-! Rotating 3d cube.
-!
-! To run this code, bootstrap Factor like so:
-!
-! ./f boot.image.le32
-!     -libraries:sdl:name=libSDL.so
-!     -libraries:sdl-gfx:name=libSDL_gfx.so
-!
-! (But all on one line)
-!
-! Then, start Factor as usual (./f factor.image) and enter this
-! at the listener:
-!
-! "examples/cube3d.factor" run-file
-
-IN: cube3d
-USING: compiler kernel lists math matrices namespaces sdl
-sequences ;
-
-! A 2x2x2 cube.
-: points
-    [
-        [[ { 1 1 1 } { 1 1 -1 } ]]
-        [[ { 1 1 1 } { 1 -1 1 } ]]
-        [[ { 1 1 1 } { -1 1 1 } ]]
-        [[ { -1 1 1 } { -1 1 -1 } ]]
-        [[ { -1 1 1 } { -1 -1 1 } ]]
-        [[ { 1 -1 1 } { -1 -1 1 } ]]
-        [[ { 1 -1 1 } { 1 -1 -1 } ]]
-        [[ { 1 1 -1 } { -1 1 -1 } ]]
-        [[ { 1 1 -1 } { 1 -1 -1 } ]]
-        [[ { -1 1 -1 } { -1 -1 -1 } ]]
-        [[ { -1 -1 1 } { -1 -1 -1 } ]]
-        [[ { 1 -1 -1 } { -1 -1 -1 } ]]
-    ] ;
-
-: 3vector ( x y z -- { x y z } )
-    [ rot , swap , , ] make-vector ;
-
-: rotation-matrix-1 ( theta -- )
-    [
-        dup cos ,     dup sin , 0 ,
-        dup sin neg , cos ,     0 ,
-        0 ,           0 ,       1 ,
-    ] make-vector 3 3 rot <matrix> ;
-
-: rotation-matrix-2 ( theta -- )
-    [
-        1 , 0 ,           0 ,
-        0 , dup cos ,     dup sin ,
-        0 , dup sin neg , cos ,
-    ] make-vector 3 3 rot <matrix> ;
-
-: rotation-matrix-3 ( theta -- )
-    [
-        dup cos , 0 , dup sin neg ,
-        0 ,       1 , 0 ,
-        dup sin , 0 , cos ,
-    ] make-vector 3 3 rot <matrix> ;
-
-SYMBOL: theta
-SYMBOL: phi
-SYMBOL: psi
-
-SYMBOL: rotation
-
-: update-matrix
-    theta get rotation-matrix-1
-    phi get rotation-matrix-2 m.
-    psi get rotation-matrix-3 m. rotation set ;
-
-: >scene ( { x y z } -- { x y z } )
-    rotation get swap m.v ;
-
-: >screen ( { x y z } -- x y )
-    200 swap n*v width get 2 / height get 2 / 0 3vector v+
-    0 over nth 1 rot nth ;
-
-: redraw ( -- )
-    surface get 0 0 width get height get black rgb boxColor
-    points [
-        uncons >r >r surface get
-        r> >scene >screen
-        r> >scene >screen
-        red rgb lineColor
-    ] each ;
-
-: event-loop ( event -- )
-    theta [ 0.01 + ] change
-    phi [ 0.02 + ] change
-    psi [ 0.03 + ] change
-    update-matrix
-    [ redraw ] with-surface
-    dup SDL_PollEvent [
-        dup event-type SDL_QUIT = [
-            drop
-        ] [
-            event-loop
-        ] ifte
-    ] [
-        event-loop
-    ] ifte ;
-
-: cube3d ( -- )
-    800 600 0 SDL_HWSURFACE [
-        0 theta set
-        0 phi set
-        0 psi set
-        <event> event-loop SDL_Quit
-    ] with-screen ;
-
-cube3d
diff --git a/examples/dump.factor b/examples/dump.factor
new file mode 100644 (file)
index 0000000..b570914
--- /dev/null
@@ -0,0 +1,30 @@
+! Copyright (C) 2004, 2005 Slava Pestov.
+! See http://factor.sf.net/license.txt for BSD license.
+IN: dump
+USING: alien assembler generic kernel kernel-internals lists
+math memory sequences stdio strings unparser ;
+
+: cell. >hex cell 2 * CHAR: 0 pad write ;
+
+: slot@ ( address n -- n ) cell * swap 7 bitnot bitand + ;
+
+: dump-line ( address n value -- )
+    >r slot@ cell. ": " write r> cell. terpri ;
+
+: (dump) ( address list -- )
+    0 swap [ >r 2dup r> dump-line 1 + ] each 2drop ;
+
+: integer-slots ( obj -- list )
+    dup size cell / [ integer-slot ] project-with ;
+
+: dump ( obj -- )
+    #! Dump an object's memory.
+    dup address swap integer-slots (dump) ;
+
+: alien-slots ( address length -- list )
+    cell / [ cell * alien-unsigned-4 ] project-with ;
+
+: dump* ( alien len -- )
+    #! Dump an alien's memory.
+    dup string? [ c-size ] when 
+    >r [ alien-address ] keep r> alien-slots (dump) ;
diff --git a/examples/plot3d.factor b/examples/plot3d.factor
new file mode 100644 (file)
index 0000000..69358cc
--- /dev/null
@@ -0,0 +1,154 @@
+! 3d surface plotter.
+!
+! To run this code, bootstrap Factor like so:
+!
+! ./f boot.image.le32
+!     -libraries:sdl:name=libSDL.so
+!     -libraries:sdl-gfx:name=libSDL_gfx.so
+!
+! (But all on one line)
+!
+! Then, start Factor as usual (./f factor.image) and enter this
+! at the listener:
+!
+! "contrib/gl/load.factor" run-file
+! "examples/plot3d.factor" run-file
+
+IN: plot3d
+USING: alien compiler errors gl kernel lists math matrices
+namespaces prettyprint sdl sequences ;
+
+: display-list 1 ;
+
+: plot-vertex ( matrix i j -- )
+    rot matrix-get 3unlist glVertex3f ;
+
+: plot-face ( matrix i j -- face )
+    GL_QUADS glBegin
+       [ rot matrix-get ] 3keep
+       [ 1 + rot matrix-get v- ] 3keep
+       [ rot matrix-get ] 3keep
+       [ >r 1 + r> rot matrix-get v- cross normalize >list 3unlist glNormal3f ] 3keep
+       [ plot-vertex ] 3keep
+       [ 1 + plot-vertex ] 3keep
+       [ >r 1 + r> 1 + plot-vertex ] 3keep
+       >r 1 + r> plot-vertex
+    glEnd ;
+
+: plot-faces ( points -- )
+    dup matrix-rows 1 - over matrix-cols 1 - [
+        3dup plot-face
+    ] 2repeat drop ;
+
+SYMBOL: theta
+
+: plot-axes ( -- )
+    GL_LIGHTING glDisable
+    1.0 1.0 1.0 glColor3f
+    GL_LINES glBegin
+        0 0 0 glVertex3f
+        1 0 0 glVertex3f
+        0 0 0 glVertex3f
+        -1 0 0 glVertex3f
+        0 0 0 glVertex3f
+        0 1 0 glVertex3f
+        0 0 0 glVertex3f
+        0 -1 0 glVertex3f
+        0 0 0 glVertex3f
+        0 0 1 glVertex3f
+        0 0 0 glVertex3f
+        0 0 -1 glVertex3f
+    glEnd
+    GL_LIGHTING glEnable ;
+
+: i/j>x/y ( i j -- x y )
+    swap 15 - 30 / swap 15 - 30 / ;
+
+: max-z ( seq -- z )
+    0.1 swap [ 2 swap nth max ] each ;
+
+: min-z ( seq -- z )
+    -0.1 swap [ 2 swap nth min ] each ;
+
+: normalize-points ( seq -- )
+    dup min-z over [ over >r 3unlist r> - 3list ] nmap drop
+    dup max-z swap [ over >r 3unlist r> / 3list ] nmap drop ;
+
+: valuate-points ( quot -- matrix )
+    >r 30 30 r>
+    [ i/j>x/y ] swap unit [ 2keep rot 3list ] append3
+    make-matrix ;
+
+: make-plot
+    [ rect> sq exp real ] valuate-points
+    dup matrix-sequence normalize-points
+    display-list GL_COMPILE glNewList
+        plot-faces
+        plot-axes
+    glEndList ;
+
+: flags
+    SDL_OPENGL SDL_RESIZABLE bitor SDL_HWSURFACE bitor SDL_DOUBLEBUF bitor ;
+
+: fov          60.0 ; inline
+: near         0.1 ; inline
+: far          100.0 ; inline
+
+: >float-array ( seq -- float-array )
+    dup length <float-array> over length [
+        [ tuck >r >r swap nth r> r> swap set-float-nth ] 3keep
+    ] repeat nip ;
+
+: init-gl
+    GL_PROJECTION glMatrixMode
+    GL_DEPTH_TEST glEnable
+    GL_LIGHTING glEnable
+    GL_LIGHT0 glEnable
+    GL_LIGHT1 glEnable
+    glLoadIdentity
+    fov width get height get /f near far gluPerspective
+    GL_LIGHT0 GL_POSITION [ 1.0 1.0 -2.0 1.0 ] >float-array glLightfv
+    GL_LIGHT0 GL_DIFFUSE [ 1.0 0.5 0.0 1.0 ] >float-array glLightfv
+    GL_LIGHT0 GL_SPECULAR [ 1.0 0.5 1.0 1.0 ] >float-array glLightfv
+    GL_LIGHT0 GL_AMBIENT [ 1.0 1.0 0.5 1.0 ] >float-array glLightfv
+    GL_LIGHT1 GL_POSITION [ 1.0 3.0 2.0 -1.0 ] >float-array glLightfv
+    GL_LIGHT1 GL_DIFFUSE [ 1.0 0.5 0.3 1.0 ] >float-array glLightfv
+    GL_LIGHT1 GL_SPECULAR [ 1.0 1.0 0.5 1.0 ] >float-array glLightfv
+    GL_LIGHT1 GL_AMBIENT [ 0.0 0.0 1.0 1.0 ] >float-array glLightfv
+    GL_MODELVIEW glMatrixMode
+    glLoadIdentity
+    GL_SMOOTH glShadeModel
+    
+    0.0 0.0 0.0 0.0 glClearColor
+    1.0 0.0 0.0 glColor3f ;
+
+: render ( -- )
+    GL_COLOR_BUFFER_BIT GL_DEPTH_BUFFER_BIT bitor glClear
+    GL_MODELVIEW glMatrixMode
+    glLoadIdentity
+    0.0 -0.5 -1.5 glTranslatef
+    -45 1 0 0 glRotatef
+    theta get 0 0 1 glRotatef
+    display-list glCallList
+    SDL_GL_SwapBuffers ;
+
+: event-loop ( event -- )
+    theta [ 1 + ] change
+    render
+    dup SDL_PollEvent [
+        dup event-type SDL_QUIT = [
+            drop
+        ] [
+            event-loop
+        ] ifte
+    ] [
+        event-loop
+    ] ifte ;
+
+: plot3d ( -- )
+    1024 768 16 flags [
+        init-gl
+        0 theta set
+        make-plot
+        <event> event-loop SDL_Quit
+    ] with-screen ;
index 5a6cf1a61dad099b7ecf08dd961b5e82cd338bac..70a3ff82a5838d71013b59920de61a011bba1742 100644 (file)
@@ -65,7 +65,6 @@ t [
     "/library/tools/profiler.factor"
     "/library/tools/walker.factor"
     "/library/tools/annotations.factor"
-    "/library/tools/dump.factor"
     "/library/bootstrap/image.factor"
     
     "/library/io/logging.factor"
diff --git a/library/tools/dump.factor b/library/tools/dump.factor
deleted file mode 100644 (file)
index b570914..0000000
+++ /dev/null
@@ -1,30 +0,0 @@
-! Copyright (C) 2004, 2005 Slava Pestov.
-! See http://factor.sf.net/license.txt for BSD license.
-IN: dump
-USING: alien assembler generic kernel kernel-internals lists
-math memory sequences stdio strings unparser ;
-
-: cell. >hex cell 2 * CHAR: 0 pad write ;
-
-: slot@ ( address n -- n ) cell * swap 7 bitnot bitand + ;
-
-: dump-line ( address n value -- )
-    >r slot@ cell. ": " write r> cell. terpri ;
-
-: (dump) ( address list -- )
-    0 swap [ >r 2dup r> dump-line 1 + ] each 2drop ;
-
-: integer-slots ( obj -- list )
-    dup size cell / [ integer-slot ] project-with ;
-
-: dump ( obj -- )
-    #! Dump an object's memory.
-    dup address swap integer-slots (dump) ;
-
-: alien-slots ( address length -- list )
-    cell / [ cell * alien-unsigned-4 ] project-with ;
-
-: dump* ( alien len -- )
-    #! Dump an alien's memory.
-    dup string? [ c-size ] when 
-    >r [ alien-address ] keep r> alien-slots (dump) ;