diff --git a/README.txt b/README.txt index cbe8d632ce..d257126323 100644 --- a/README.txt +++ b/README.txt @@ -41,8 +41,12 @@ parameters to build the Factor runtime: linux linux-ppc macosx + macosx-sdl windows +Note: If you wish to use the Factor UI on Mac OS X, you must build with the +macosx-sdl target. + The following options can be given to make: SITE_CFLAGS="..." @@ -108,20 +112,15 @@ naming the libraries during bootstrap, as in the next section. * Setting up SDL libraries for use with Factor -Factor's UI requires recent versions of the following three libraries in -order to operate: - - libSDL.so - libSDL_ttf.so - libSDL_gfx.so +The Windows binary package for Factor includes all prerequisite DLLs. On Unix, +you need recent versions of SDL and FreeType. If you have installed these libraries but the UI still fails with an error, you will need to find out the exact names that they are installed as, and issue a command similar to the following to bootstrap Factor: ./f boot.image. -libraries:sdl:name=libSDL-1.2.so - -libraries:sdl-ttf:name=libSDL_ttf.so - -libraries:sdl-gfx:name=libSDL_gfx.so + -libraries:freetype:name=libfreetype.so * Source organization @@ -133,6 +132,7 @@ as, and issue a command similar to the following to bootstrap Factor: collections/ - data types including but not limited to lists, vectors, hashtables, and operations on them compiler/ - optimizing native compiler + freetype/ - FreeType binding, rendering glyphs to OpenGL textures generic/ - generic words, for object oriented programming style help/ - online help system httpd/ - HTTP client, server, and web application framework @@ -140,7 +140,8 @@ as, and issue a command similar to the following to bootstrap Factor: useful development tool of its own io/ - input and output streams math/ - integers, ratios, floats, complex numbers, vectors, matrices - sdl/ - bindings for libSDL, libSDL_ttf and libSDL_gfx + opengl/ - OpenGL graphics library binding + sdl/ - SDL binding syntax/ - parser and object prettyprinter test/ - unit test framework and test suite tools/ - interactive development tools diff --git a/TODO.FACTOR.txt b/TODO.FACTOR.txt index 343f107a5c..0c9d7f6052 100644 --- a/TODO.FACTOR.txt +++ b/TODO.FACTOR.txt @@ -1,9 +1,8 @@ 0.79: -- fix prettyprinter -- syntax updates and testing for contrib/ -- get stuff in examples dir running in the ui -- pixelColor replacement +- test everything in contrib +- update handbook +- fix remaining GL issues + ui: diff --git a/contrib/httpd/test/html.factor b/contrib/httpd/test/html.factor index 703d6d05ee..22a180bccc 100644 --- a/contrib/httpd/test/html.factor +++ b/contrib/httpd/test/html.factor @@ -23,7 +23,7 @@ USING: html io kernel namespaces styles test ; [ "car" ] [ [ - [ [ foreground 255 0 255 ] [[ font "Monospaced" ]] ] + [ [ foreground 1 0 1 ] [[ font "Monospaced" ]] ] [ drop "car" write ] span-tag ] string-out @@ -41,7 +41,7 @@ USING: html io kernel namespaces styles test ; [ [ "car" - [ [ foreground 255 0 255 ] [[ font "Monospaced" ]] ] + [ [ foreground 1 0 1 ] [[ font "Monospaced" ]] ] html-format ] string-out ] unit-test diff --git a/contrib/math/TODO.txt b/contrib/math/TODO.txt index 5dd9f475d6..cc1a723d74 100644 --- a/contrib/math/TODO.txt +++ b/contrib/math/TODO.txt @@ -16,6 +16,7 @@ Nice to have: - square root of a matrix, e^matrix - finding roots of polynomials - Algebra: + - polynomial derivative - ^mod for polynomials - mod-inv for polynomials - arithmetic modulo a+sqrt(b) @@ -28,6 +29,10 @@ Nice to have: - interval arithmetic - combinatorics: stirling numbers - factoring polynomials over finite fields + - minimal and characteristic polynomials of algebraic numbers + - norm and trace of algebraic numbers + - minimal and characteristic polynomials of matrices + - eigenvalues of matrices - Graphs: - minimum spanning trees - Logic: diff --git a/contrib/math/polynomials.factor b/contrib/math/polynomials.factor index 82946a7974..498ed09463 100644 --- a/contrib/math/polynomials.factor +++ b/contrib/math/polynomials.factor @@ -5,10 +5,6 @@ USING: kernel sequences vectors math math-internals namespaces ; : zero-vector ( n -- vector ) 0 >vector ; -: nzero-pad ( n seq -- seq ) - #! extend seq by n zeros - >r zero-vector r> swap nappend ; - : zero-pad ( n seq -- seq ) #! extend seq by n zeros >r zero-vector r> swap append ; @@ -16,6 +12,10 @@ USING: kernel sequences vectors math math-internals namespaces ; : zero-pad-front ( n seq -- seq ) >r zero-vector r> append ; +: nzero-pad ( n seq -- ) + #! extend seq by n zeros + >r zero-vector r> swap nappend ; + : zero-extend ( n seq -- ) #! extend seq to max(n,length) with 0s [ length ] keep -rot - swap nzero-pad ; @@ -56,17 +56,14 @@ IN: math-contrib : conv*b ( seq -- seq ) rot dup pop drop 1 zero-vector swap append -rot ; -: conv ( p p -- p ) - conv*a [ 3dup -rot v* sum >r pick r> -rot set-nth conv*b ] repeat nip ; - -! polynomial multiply : p* ( p p -- p ) - conv ; + #! Multiply two polynomials. + conv*a [ 3dup -rot v* sum >r pick r> -rot set-nth conv*b ] repeat nip ; : p-sq ( p -- p-sq ) dup p* ; -IN: polynomial-internals +IN: polynomials-internals : pop-front ( seq -- seq ) 1 swap tail ; @@ -82,18 +79,22 @@ IN: polynomial-internals : (p/mod) 2dup /-last 2dup , n*p swapd p- dup pop drop swap pop-front ; -IN: math +IN: math-contrib : p/mod - p/mod-setup [ [ (p/mod) ] times ] { } make reverse nip swap 2ptrim pextend ; + p/mod-setup [ [ (p/mod) ] times ] V{ } make + reverse nip swap 2ptrim pextend ; : (pgcd) ( b a y x -- a d ) - dup { 0 } clone p= [ + dup V{ 0 } clone p= [ drop nip ] [ tuck p/mod >r pick p* swap >r swapd p- r> r> (pgcd) ] if ; : pgcd ( p p -- p ) - swap { 0 } clone { 1 } clone 2swap (pgcd) ; + swap V{ 0 } clone V{ 1 } clone 2swap (pgcd) ; +: pdiff ( p -- p' ) + #! Polynomial derivative. + [ length reverse-slice ] keep [ 1+ * ] 2map 1 swap head* ; diff --git a/examples/dejong.factor b/examples/dejong.factor deleted file mode 100644 index 2318e32d2a..0000000000 --- a/examples/dejong.factor +++ /dev/null @@ -1,70 +0,0 @@ -! DeJong attractor renderer. -! -! 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/dejong.factor" run-file - -! For details on DeJong attractors, see -! http://www.complexification.net/gallery/machines/peterdejong/ - -IN: dejong -USING: compiler kernel math namespaces sdl styles test ; - -SYMBOL: a -SYMBOL: b -SYMBOL: c -SYMBOL: d - -: 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 - ; - -: pixel ( C{ x y } color -- ) - >r >r surface get r> >rect r> pixelColor ; - -: iterate-dejong ( x y -- x y ) - 2dup next-y >r next-x r> ; - -: scale-dejong ( x y -- x y ) - swap width get 4 / * width get 2 / + >fixnum - swap height get 4 / * height get 2 / + >fixnum ; - -: draw-dejong ( x0 y0 iterations -- ) - [ - iterate-dejong 2dup scale-dejong rect> white rgb pixel - ] times 2drop ; compiled - -: event-loop ( event -- ) - dup SDL_WaitEvent [ - dup event-type SDL_QUIT = [ - drop - ] [ - event-loop - ] if - ] [ - drop - ] if ; compiled - -: dejong ( -- ) - ! Fiddle with these four values! - 1.0 a set - -1.3 b set - 0.8 c set - -2.1 d set - - 800 600 0 SDL_HWSURFACE [ - [ 0 0 200000 [ draw-dejong ] time ] with-surface - - event-loop - SDL_Quit - ] with-screen ; - -dejong diff --git a/examples/mandel.factor b/examples/mandel.factor index 5a95d1ad15..af7bf8602f 100644 --- a/examples/mandel.factor +++ b/examples/mandel.factor @@ -14,22 +14,15 @@ ! "examples/mandel.factor" run-file IN: mandel -USE: compiler -USE: alien -USE: errors -USE: kernel -USE: lists -USE: math -USE: namespaces -USE: sdl -USE: sdl-event -USE: sdl-gfx -USE: sdl-video -USE: vectors -USE: prettyprint -USE: sequences -USE: io -USE: test +USING: arrays compiler io kernel math namespaces sequences +strings test ; + +: max-color 360 ; inline +: zoom-fact 0.8 ; inline +: width 640 ; inline +: height 480 ; inline +: nb-iter 40 ; inline +: center -0.65 ; inline : f_ ( h s v i -- f ) >r swap rot >r 2dup r> 6 * r> - ; : p ( v s x -- v p x ) >r dupd neg 1 + * r> ; @@ -75,81 +68,65 @@ USE: test [ 1 0 0 ] [ 1 1 1 hsv>rgb ] unit-test [ 1/6 1/9 1/9 ] [ 1 1/3 1/6 hsv>rgb ] unit-test -: scale 255 * >fixnum ; +: scale 255 * >fixnum ; inline -: scale-rgb ( r g b a -- n ) - scale - swap scale 8 shift bitor - swap scale 16 shift bitor - swap scale 24 shift bitor ; +: scale-rgb ( r g b -- n ) + rot scale rot scale rot scale 3array ; -: sat 0.85 ; -: val 0.85 ; +: sat 0.85 ; inline +: val 0.85 ; inline : ( nb-cols -- map ) dup [ - 360 * swap 1 + / 360 / sat val - hsv>rgb 1.0 scale-rgb + 360 * swap 1+ / 360 / sat val + hsv>rgb scale-rgb ] map-with ; : iter ( c z nb-iter -- x ) over absq 4.0 >= over 0 = or - [ 2nip ] [ 1- >r sq dupd + r> iter ] if ; + [ 2nip ] [ 1- >r sq dupd + r> iter ] if ; inline -: max-color 360 ; - -SYMBOL: zoom-fact -SYMBOL: x-inc -SYMBOL: y-inc -SYMBOL: nb-iter SYMBOL: cols -SYMBOL: center -: init-mandel ( -- ) - width get 200000 zoom-fact get * / x-inc set - height get 150000 zoom-fact get * / y-inc set - nb-iter get max-color min cols set ; +: x-inc width 200000 zoom-fact * / ; inline +: y-inc height 150000 zoom-fact * / ; inline : c ( i j -- c ) >r - x-inc get * center get real x-inc get width get 2 / * - + >float + x-inc * center real x-inc width 2 / * - + >float r> - y-inc get * center get imaginary y-inc get height get 2 / * - + >float - rect> ; + y-inc * center imaginary y-inc height 2 / * - + >float + rect> ; inline : render ( -- ) + height [ + width [ + 2dup swap c 0 nb-iter iter dup 0 = [ + drop "\0\0\0" + ] [ + cols get [ length mod ] keep nth + ] if % + ] repeat + ] repeat ; + +: ppm-header ( w h -- ) + "P6\n" % swap # " " % # "\n255\n" % ; + +: sbuf-size width height * 3 * 100 + ; + +: run ( -- string ) [ - c 0 nb-iter get iter dup 0 = [ - drop 0 - ] [ - cols get [ length mod ] keep nth - ] if - ] with-pixels ; compiled + sbuf-size building set + width height ppm-header + nb-iter max-color min cols set + render + building get >string + ] with-scope ; -: event-loop ( event -- ) - dup SDL_WaitEvent [ - dup event-type SDL_QUIT = [ - drop - ] [ - event-loop - ] if - ] [ - drop - ] if ; compiled +: run>file ( file -- ) + "Generating " write dup write "..." print + [ run write ] with-stream ; -: mandel ( -- ) - 1280 1024 0 SDL_HWSURFACE [ - [ - 3.7 zoom-fact set - -0.45 center set - 100 nb-iter set - init-mandel - [ render ] time - "Done." print flush - ] with-surface +\ render compile - event-loop - SDL_Quit - ] with-screen ; - -mandel +[ "mandel.pnm" run>file ] time diff --git a/examples/raytracer.factor b/examples/raytracer.factor index 6a1aef618b..8ef7d21f23 100644 --- a/examples/raytracer.factor +++ b/examples/raytracer.factor @@ -1,7 +1,8 @@ ! Factor port of the raytracer benchmark from ! http://www.ffconsultancy.com/free/ray_tracer/languages.html -USING: arrays generic io kernel lists math namespaces sequences ; +USING: arrays compiler generic io kernel lists math namespaces +sequences test ; IN: ray ! parameters @@ -142,18 +143,24 @@ DEFER: create ( level c r -- scene ) ] map-with ] map ; -: pnm-header ( w h -- ) +: pgm-header ( w h -- ) "P5\n" % swap # " " % # "\n255\n" % ; -: pnm-pixel ( n -- ) 255 * 0.5 + >fixnum , ; +: pgm-pixel ( n -- ) 255 * 0.5 + >fixnum , ; : ray-trace ( scene -- pixels ) pixel-grid [ [ ray-pixel ] map-with ] map-with ; : run ( -- string ) levels { 0.0 -1.0 0.0 } 1.0 create ray-trace [ - size size pnm-header - [ [ oversampling sq / pnm-pixel ] each ] each + size size pgm-header + [ [ oversampling sq / pgm-pixel ] each ] each ] "" make ; -: run>file ( file -- ) [ run write ] with-stream ; +: run>file ( file -- ) + "Generating " write dup write "..." print + [ run write ] with-stream ; + +\ run compile + +[ "raytracer.pnm" run>file ] time diff --git a/library/syntax/prettyprint.factor b/library/syntax/prettyprint.factor index 05a38de1e1..45298aa5c2 100644 --- a/library/syntax/prettyprint.factor +++ b/library/syntax/prettyprint.factor @@ -346,19 +346,12 @@ M: wrapper pprint* ( wrapper -- ) : .o >oct print ; : .h >hex print ; -: define-open - #! The word will be pretty-printed as a block opener. - t "pprint-open" set-word-prop ; - -: define-close ( word -- ) - #! The word will be pretty-printed as a block closer. - t "pprint-close" set-word-prop ; - { POSTPONE: [ POSTPONE: [[ POSTPONE: { POSTPONE: V{ POSTPONE: H{ POSTPONE: T{ POSTPONE: W{ -} [ define-open ] each +} [ t "pprint-open" set-word-prop ] each -{ POSTPONE: [ POSTPONE: } POSTPONE: ]] } -[ define-close ] each +{ + POSTPONE: ] POSTPONE: } POSTPONE: ]] +} [ t "pprint-close" set-word-prop ] each diff --git a/library/ui/listener.factor b/library/ui/listener.factor index 3e7c6039f0..b6c43729d0 100644 --- a/library/ui/listener.factor +++ b/library/ui/listener.factor @@ -63,7 +63,7 @@ C: display ( -- display ) 1/2 ; : ( -- gadget ) - ""