]> gitweb.factorcode.org Git - factor.git/commitdiff
Merge branch 'master' of git://github.com/slavapestov/factor
authorErik Charlebois <erikcharlebois@gmail.com>
Tue, 16 Feb 2010 11:27:33 +0000 (03:27 -0800)
committerErik Charlebois <erikcharlebois@gmail.com>
Tue, 16 Feb 2010 11:27:33 +0000 (03:27 -0800)
25 files changed:
basis/compiler/tree/escape-analysis/escape-analysis-tests.factor
basis/compiler/tree/escape-analysis/simple/simple.factor
basis/compiler/tree/propagation/transforms/transforms.factor
basis/io/backend/unix/unix.factor
basis/io/directories/unix/linux/linux.factor
basis/io/files/info/info.factor
basis/io/styles/styles.factor
basis/math/bitwise/bitwise.factor
basis/math/points/points.factor [deleted file]
basis/prettyprint/stylesheet/stylesheet.factor
basis/tools/annotations/annotations.factor
basis/tools/deploy/deploy-tests.factor
basis/tools/deploy/shaker/shaker.factor
basis/tools/deploy/test/18/18.factor [new file with mode: 0644]
basis/tools/deploy/test/18/authors.txt [new file with mode: 0644]
basis/tools/deploy/test/18/deploy.factor [new file with mode: 0644]
core/assocs/assocs-docs.factor
core/classes/classes-tests.factor
core/classes/classes.factor
core/classes/tuple/tuple-tests.factor
core/sets/sets-docs.factor
extra/benchmark/raytracer-simd/raytracer-simd.factor
extra/mason/source/source.factor
extra/math/points/points.factor [new file with mode: 0644]
extra/project-euler/ave-time/ave-time.factor

index 6c50347c3a82114d7ae61e227c6b57398fa57b4c..ca2f5ed19741ae10e08df6e9b105404a0980bfa9 100644 (file)
@@ -329,3 +329,18 @@ TUPLE: empty-tuple ;
     [ { vector } declare length>> ]
     count-unboxed-allocations
 ] unit-test
+
+! Bug found while tweaking benchmark.raytracer-simd
+
+TUPLE: point-2d { x read-only } { y read-only } ;
+TUPLE: point-3d < point-2d { z read-only } ;
+
+[ 0 ] [
+    [ { point-2d } declare dup point-3d? [ z>> ] [ x>> ] if ]
+    count-unboxed-allocations
+] unit-test
+
+[ 0 ] [
+    [ point-2d boa dup point-3d? [ z>> ] [ x>> ] if ]
+    count-unboxed-allocations
+] unit-test
index 5be206f2f8211f8557bdc5f5cf481775665a28a8..9634bdf2594431058ce5245a3c185813f45a8e28 100644 (file)
@@ -61,22 +61,28 @@ M: #push escape-analysis*
 
 : record-tuple-allocation ( #call -- )
     dup immutable-tuple-boa?
-    [ [ in-d>> but-last ] [ out-d>> first ] bi record-allocation ]
+    [ [ in-d>> but-last { } like ] [ out-d>> first ] bi record-allocation ]
     [ record-unknown-allocation ]
     if ;
 
 : slot-offset ( #call -- n/f )
-    dup in-d>>
-    [ second node-value-info literal>> ]
-    [ first node-value-info class>> ] 2bi
-    2dup [ fixnum? ] [ tuple class<= ] bi* and [
-        over 2 >= [ drop 2 - ] [ 2drop f ] if
+    dup in-d>> second node-value-info literal>> dup [ 2 - ] when ;
+
+: valid-slot-offset? ( slot# in -- ? )
+    over [
+        allocation dup [
+            dup array? [ bounds-check? ] [ 2drop f ] if
+        ] [ 2drop t ] if
     ] [ 2drop f ] if ;
 
+: unknown-slot-call ( out slot# in -- )
+    [ unknown-allocation ] [ drop ] [ add-escaping-value ] tri* ;
+
 : record-slot-call ( #call -- )
-    [ out-d>> first ] [ slot-offset ] [ in-d>> first ] tri over
+    [ out-d>> first ] [ slot-offset ] [ in-d>> first ] tri
+    2dup valid-slot-offset?
     [ [ record-slot-access ] [ copy-slot-value ] 3bi ]
-    [ [ unknown-allocation ] [ drop ] [ add-escaping-value ] tri* ]
+    [ unknown-slot-call ]
     if ;
 
 M: #call escape-analysis*
index da3bd58f74da06478f1cfb24cadd54c8828b7ea7..0077d0f1231b90af01b9da143d701d4b4e0a6841 100644 (file)
@@ -103,13 +103,10 @@ IN: compiler.tree.propagation.transforms
 
 ! Speeds up 2^
 : 2^? ( #call -- ? )
-    in-d>> first2 [ value-info ] bi@
-    [ { [ literal>> 1 = ] [ class>> fixnum class<= ] } 1&& ]
-    [ class>> fixnum class<= ]
-    bi* and ;
+    in-d>> first value-info literal>> 1 eq? ;
 
 \ shift [
-     2^? [
+    2^? [
         cell-bits tag-bits get - 1 -
         '[
             >fixnum dup 0 < [ 2drop 0 ] [
index 1797edccf61b8e4e9564bce0466bddb46ff382ad..39f0a5fec381bd1d2e2bebfbc41a0017ce74bcee 100644 (file)
@@ -22,10 +22,6 @@ TUPLE: fd < disposable fd ;
     ] with-destructors ;
 
 : <fd> ( n -- fd )
-    #! We drop the error code rather than calling io-error,
-    #! since on OS X 10.3, this operation fails from init-io
-    #! when running the Factor.app (presumably because fd 0 and
-    #! 1 are closed).
     fd new-disposable swap >>fd ;
 
 M: fd dispose
@@ -197,5 +193,5 @@ TUPLE: mx-port < port mx ;
         [ drop 0 ] [ (io-error) ] if
     ] when ;
 
-: ?flag ( n mask symbol -- n )
-    pick rot bitand 0 > [ , ] [ drop ] if ;
+:: ?flag ( n mask symbol -- n )
+    n mask bitand 0 > [ symbol , ] when n ;
index 932cbe230b85262286ca34185c5e8ed7c0125314..3d69c5f8908b8d874cb7aa3c92bb7e5d39fa844d 100644 (file)
@@ -4,7 +4,7 @@ USING: alien.c-types io.directories.unix kernel system unix
 classes.struct unix.ffi ;
 IN: io.directories.unix.linux
 
-M: unix find-next-file ( DIR* -- dirent )
+M: linux find-next-file ( DIR* -- dirent )
     dirent <struct>
     f <void*>
     [ [ readdir64_r ] unix-system-call 0 = [ (io-error) ] unless ] 2keep
index 500fd62cd3338889a7e2b668cca46d7070272dd1..a314361e9d7db4fcd7a67dcff5e3e48e72a0e477 100644 (file)
@@ -26,7 +26,7 @@ available-space free-space used-space total-space ;
 HOOK: file-system-info os ( path -- file-system-info )
 
 {
-    { [ os unix? ] [ "io.files.info" ] }
+    { [ os unix? ] [ "io.files.info.unix" ] }
     { [ os windows? ] [ "io.files.info.windows" ] }
 } cond require
 
index ae493be8490c26f97c741246ece4a79625d30663..d4e1d2c557a4df20e7382a0a7c2be2b3c79fc690 100644 (file)
@@ -163,9 +163,3 @@ M: input summary
 : write-object ( str obj -- ) presented associate format ;
 
 : write-image ( image -- ) [ "" ] dip image associate format ;
-
-SYMBOL: stack-effect-style
-H{
-    { foreground COLOR: FactorDarkGreen }
-    { font-style plain }
-} stack-effect-style set-global
index 204f2959447ac0e1e7ef4a56d99620f2abc1935c..6b301fa97bf071ca3eae841c015a5d12355bbead 100644 (file)
@@ -99,7 +99,7 @@ M: bignum (bit-count)
     ] if ;
 
 : byte-array-bit-count ( byte-array -- n )
-    0 [ byte-bit-count + ] reduce ;
+    0 [ byte-bit-count + ] reduce ; inline
 
 PRIVATE>
 
diff --git a/basis/math/points/points.factor b/basis/math/points/points.factor
deleted file mode 100644 (file)
index 107e81d..0000000
+++ /dev/null
@@ -1,26 +0,0 @@
-USING: kernel arrays math.vectors sequences math ;
-
-IN: math.points
-
-<PRIVATE
-
-: X ( x -- point )      0   0 3array ;
-: Y ( y -- point ) 0 swap   0 3array ;
-: Z ( z -- point ) 0    0 rot 3array ;
-
-PRIVATE>
-
-: v+x ( seq x -- seq ) X v+ ;
-: v-x ( seq x -- seq ) X v- ;
-
-: v+y ( seq y -- seq ) Y v+ ;
-: v-y ( seq y -- seq ) Y v- ;
-
-: v+z ( seq z -- seq ) Z v+ ;
-: v-z ( seq z -- seq ) Z v- ;
-
-: rise ( pt2 pt1 -- n ) [ second ] bi@ - ;
-: run ( pt2 pt1 -- n ) [ first ] bi@ - ;
-: slope ( pt pt -- slope ) [ rise ] [ run ] 2bi / ;
-: midpoint ( point point -- point ) v+ 2 v/n ;
-: linear-solution ( pt pt -- x ) [ drop first2 ] [ slope ] 2bi / - ;
\ No newline at end of file
index 42a701d60f6639ad5e5068433a2b20fe70efaf85..bd25438b7499beea450244f356bdac0d133c06f1 100644 (file)
@@ -42,5 +42,12 @@ PRIVATE>
 : vocab-style ( vocab -- style )
     dim-color colored-presentation-style ;
 
+SYMBOL: stack-effect-style
+
+H{
+    { foreground COLOR: FactorDarkGreen }
+    { font-style plain }
+} stack-effect-style set-global
+
 : effect-style ( effect -- style )
     presented associate stack-effect-style get assoc-union ;
index 5d4a9226ceb5b348eb4a6865c948cd853de4c6a5..c9dfc4a5625163b6586c5c45239e2eb89312f6ea 100644 (file)
@@ -1,4 +1,4 @@
-! Copyright (C) 2005, 2009 Slava Pestov.
+! Copyright (C) 2005, 2010 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
 USING: accessors kernel math sorting words parser io summary
 quotations sequences prettyprint continuations effects
@@ -108,5 +108,5 @@ PRIVATE>
 
 : word-timing. ( -- )
     word-timing get
-    >alist [ 1000000 /f ] assoc-map sort-values
+    >alist [ 1,000,000,000 /f ] assoc-map sort-values
     simple-table. ;
index 1412e65f95f487a291598d5f94bbd43ba2e7b572..987b4aa8a1bcdc05b198070ad5cbf2f6cdc072a5 100644 (file)
@@ -117,3 +117,9 @@ os macosx? [
 [ ] [ "tools.deploy.test.16" shake-and-bake run-temp-image ] unit-test\r
 \r
 [ ] [ "tools.deploy.test.17" shake-and-bake run-temp-image ] unit-test\r
+\r
+[ t ] [\r
+    "tools.deploy.test.18" shake-and-bake\r
+    deploy-test-command ascii [ readln ] with-process-reader\r
+    "test.image" temp-file =\r
+] unit-test\r
index 5897712a023f46fd647d6d2d4f35514d9bc3d9dc..1060853343b3b0d530dc459c9c201a3018336795 100755 (executable)
@@ -1,11 +1,11 @@
 ! Copyright (C) 2007, 2010 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: arrays accessors io.backend io.streams.c init fry
-namespaces math make assocs kernel parser parser.notes lexer
-strings.parser vocabs sequences sequences.deep sequences.private
-words memory kernel.private continuations io vocabs.loader
-system strings sets vectors quotations byte-arrays sorting
-compiler.units definitions generic generic.standard
+USING: arrays accessors io.backend io.pathnames io.streams.c
+init fry namespaces math make assocs kernel parser parser.notes
+lexer strings.parser vocabs sequences sequences.deep
+sequences.private words memory kernel.private continuations io
+vocabs.loader system strings sets vectors quotations byte-arrays
+sorting compiler.units definitions generic generic.standard
 generic.single tools.deploy.config combinators classes
 classes.builtin slots.private grouping command-line ;
 QUALIFIED: bootstrap.stage2
@@ -43,13 +43,11 @@ IN: tools.deploy.shaker
         "io.thread" startup-hooks get delete-at
     ] unless
     strip-io? [
-        "io.files" startup-hooks get delete-at
         "io.backend" startup-hooks get delete-at
         "io.thread" startup-hooks get delete-at
     ] when
     strip-dictionary? [
         {
-            ! "compiler.units"
             "vocabs"
             "vocabs.cache"
             "source-files.errors"
@@ -294,6 +292,9 @@ IN: tools.deploy.shaker
             input-stream
             output-stream
             error-stream
+            vm
+            image
+            current-directory
         } %
 
         "io-thread" "io.thread" lookup ,
diff --git a/basis/tools/deploy/test/18/18.factor b/basis/tools/deploy/test/18/18.factor
new file mode 100644 (file)
index 0000000..0676376
--- /dev/null
@@ -0,0 +1,8 @@
+! Copyright (C) 2010 Slava Pestov.
+! See http://factorcode.org/license.txt for BSD license.
+USING: accessors io.streams.c math.parser system ;
+IN: tools.deploy.test.18
+
+: main ( -- ) image show ;
+
+MAIN: main
diff --git a/basis/tools/deploy/test/18/authors.txt b/basis/tools/deploy/test/18/authors.txt
new file mode 100644 (file)
index 0000000..d4f5d6b
--- /dev/null
@@ -0,0 +1 @@
+Slava Pestov
\ No newline at end of file
diff --git a/basis/tools/deploy/test/18/deploy.factor b/basis/tools/deploy/test/18/deploy.factor
new file mode 100644 (file)
index 0000000..66069d6
--- /dev/null
@@ -0,0 +1,14 @@
+USING: tools.deploy.config ;
+H{
+    { deploy-name "tools.deploy.test.18" }
+    { deploy-ui? f }
+    { deploy-c-types? f }
+    { deploy-unicode? f }
+    { "stop-after-last-window?" t }
+    { deploy-io 1 }
+    { deploy-reflection 1 }
+    { deploy-word-props? f }
+    { deploy-math? f }
+    { deploy-threads? f }
+    { deploy-word-defs? f }
+}
index ecbc2e6bc7e942812b7e21be51797bab7a537242..0d5a884832ce003eafa0d8e13ab79999a9b236d9 100644 (file)
@@ -1,7 +1,8 @@
 ! Copyright (C) 2007, 2009 Daniel Ehrenberg, Slava Pestov, and Doug Coleman
 ! See http://factorcode.org/license.txt for BSD license.
 USING: help.markup help.syntax kernel sequences
-sequences.private namespaces math quotations assocs.private ;
+sequences.private namespaces math quotations assocs.private
+sets ;
 IN: assocs
 
 ARTICLE: "alists" "Association lists"
@@ -90,6 +91,8 @@ ARTICLE: "assocs-values" "Transposed assoc operations"
 
 ARTICLE: "assocs-sets" "Set-theoretic operations on assocs"
 "It is often useful to use the keys of an associative mapping as a set, exploiting the constant or logarithmic lookup time of most implementations (" { $link "alists" } " being a notable exception)."
+$nl
+"Set-theoretic operations:"
 { $subsections
     assoc-subset?
     assoc-intersect
@@ -98,6 +101,11 @@ ARTICLE: "assocs-sets" "Set-theoretic operations on assocs"
     substitute
     extract-keys
 }
+"Adding elements to sets:"
+{ $subsections
+    conjoin
+    conjoin-at
+}
 "Destructive operations:"
 { $subsections
     assoc-union!
index 10a5f674bd8fabfc68f50f8b38ddaa0c525b0c07..2b02d7c5a18363c9f650d065698f1b3f988682e7 100644 (file)
@@ -119,3 +119,9 @@ TUPLE: forgotten-predicate-test ;
 
 [ ] [ [ \ forgotten-predicate-test forget ] with-compilation-unit ] unit-test
 [ f ] [ \ forgotten-predicate-test? predicate? ] unit-test
+
+GENERIC: generic-predicate? ( a -- b )
+
+[ ] [ "IN: classes.tests TUPLE: generic-predicate ;" eval( -- ) ] unit-test
+
+[ f ] [ \ generic-predicate? generic? ] unit-test
index 6d68ad7fb4ef5a02d2a13f1d4679215d82718f04..28f0b192ee209dba6d286f4d6dc8d554349e75de 100644 (file)
@@ -59,14 +59,15 @@ PRIVATE>
 
 : classes ( -- seq ) implementors-map get keys ;
 
+PREDICATE: predicate < word "predicating" word-prop >boolean ;
+
 : create-predicate-word ( word -- predicate )
-    [ name>> "?" append ] [ vocabulary>> ] bi create ;
+    [ name>> "?" append ] [ vocabulary>> ] bi create
+    dup predicate? [ dup reset-generic ] unless ;
 
 : predicate-word ( word -- predicate )
     "predicate" word-prop first ;
 
-PREDICATE: predicate < word "predicating" word-prop >boolean ;
-
 M: predicate flushable? drop t ;
 
 M: predicate forget*
index f452d8fb28b8ddaec6a80898eea6b244e84bcc1e..36d402c61dbec55d849e9b42a50bc566c07c025f 100644 (file)
@@ -764,3 +764,9 @@ DEFER: factor-crashes-anymore
 ] unit-test
 
 [ 31337 ] [ factor-crashes-anymore ] unit-test
+
+TUPLE: tuple-predicate-redefine-test ;
+
+[ ] [ "IN: classes.tuple.tests TUPLE: tuple-predicate-redefine-test ;" eval( -- ) ] unit-test
+
+[ t ] [ \ tuple-predicate-redefine-test? predicate? ] unit-test
index 999e963f36d9fdb2eacf40ca4682f13c56066f25..d9b1271152b201c4b93938cd4cb26203fe0761e0 100644 (file)
@@ -29,8 +29,6 @@ $nl
 "Adding elements to sets:"
 { $subsections
     adjoin
-    conjoin
-    conjoin-at
 }
 { $see-also member? member-eq? any? all? "assocs-sets" } ;
 
index dcdc911cbf676b08389f56a2b546c0b7935a159b..e90708c62d734e95f81ae4cb21174f6cb20998ac 100644 (file)
@@ -1,13 +1,14 @@
 ! Factor port of the raytracer benchmark from
-! http://www.ffconsultancy.com/free/ray_tracer/languages.html
+! http://www.ffconsultancy.com/languages/ray_tracer/index.html
 
 USING: arrays accessors io io.files io.files.temp
 io.encodings.binary kernel math math.constants math.functions
-math.vectors math.vectors.simd math.vectors.simd.cords math.parser
-make sequences sequences.private words hints classes.struct ;
-QUALIFIED-WITH: alien.c-types c
+math.vectors math.vectors.simd math.vectors.simd.cords
+math.parser make sequences words combinators ;
 IN: benchmark.raytracer-simd
 
+<< SYNTAX: no-compile word t "no-compile" set-word-prop ; >>
+
 ! parameters
 
 ! Normalized { -1 -3 2 }.
@@ -25,7 +26,7 @@ CONSTANT: levels 3
 
 CONSTANT: size 200
 
-: delta ( -- n ) epsilon sqrt ; inline
+: delta ( -- n ) epsilon sqrt ; inline no-compile
 
 TUPLE: ray { orig double-4 read-only } { dir double-4 read-only } ;
 
@@ -35,80 +36,69 @@ TUPLE: hit { normal double-4 read-only } { lambda float read-only } ;
 
 C: <hit> hit
 
-GENERIC: intersect-scene ( hit ray scene -- hit )
-
 TUPLE: sphere { center double-4 read-only } { radius float read-only } ;
 
 C: <sphere> sphere
 
-: sphere-v ( sphere ray -- v )
-    [ center>> ] [ orig>> ] bi* v- ; inline
+: sphere-v ( sphere ray -- v ) [ center>> ] [ orig>> ] bi* v- ; inline no-compile
 
-: sphere-b ( v ray -- b )
-    dir>> v. ; inline
+: sphere-b ( v ray -- b ) dir>> v. ; inline no-compile
 
-: sphere-d ( sphere b v -- d )
-    [ radius>> sq ] [ sq ] [ norm-sq ] tri* - + ; inline
+: sphere-d ( sphere b v -- d ) [ radius>> sq ] [ sq ] [ norm-sq ] tri* - + ; inline no-compile
 
-: -+ ( x y -- x-y x+y )
-    [ - ] [ + ] 2bi ; inline
+: -+ ( x y -- x-y x+y ) [ - ] [ + ] 2bi ; inline no-compile
 
 : sphere-t ( b d -- t )
     -+ dup 0.0 <
-    [ 2drop 1/0. ] [ [ [ 0.0 > ] keep ] dip ? ] if ; inline
+    [ 2drop 1/0. ] [ [ [ 0.0 > ] keep ] dip ? ] if ; inline no-compile
 
 : sphere-b&v ( sphere ray -- b v )
     [ sphere-v ] [ nip ] 2bi
-    [ sphere-b ] [ drop ] 2bi ; inline
+    [ sphere-b ] [ drop ] 2bi ; inline no-compile
 
 : ray-sphere ( sphere ray -- t )
     [ drop ] [ sphere-b&v ] 2bi
     [ drop ] [ sphere-d ] 3bi
-    dup 0.0 < [ 3drop 1/0. ] [ sqrt sphere-t nip ] if ; inline
+    dup 0.0 < [ 3drop 1/0. ] [ sqrt sphere-t nip ] if ; inline no-compile
 
-: if-ray-sphere ( hit ray sphere quot -- hit )
-    #! quot: hit ray sphere l -- hit
+: if-ray-sphere ( hit ray sphere quot: ( hit ray sphere l -- hit ) -- hit )
     [
         [ ] [ swap ray-sphere nip ] [ 2drop lambda>> ] 3tri
         [ drop ] [ < ] 2bi
-    ] dip [ 3drop ] if ; inline
+    ] dip [ 3drop ] if ; inline no-compile
 
 : sphere-n ( ray sphere l -- n )
     [ [ orig>> ] [ dir>> ] bi ] [ center>> ] [ ] tri*
-    swap [ v*n ] dip v- v+ ; inline
-
-M: sphere intersect-scene ( hit ray sphere -- hit )
-    [ [ sphere-n normalize ] keep <hit> nip ] if-ray-sphere ;
-
-HINTS: M\ sphere intersect-scene { hit ray sphere } ;
+    swap [ v*n ] dip v- v+ ; inline no-compile
 
 TUPLE: group < sphere { objs array read-only } ;
 
 : <group> ( objs bound -- group )
-    [ center>> ] [ radius>> ] bi rot group boa ; inline
+    swap [ [ center>> ] [ radius>> ] bi ] dip group boa ; inline no-compile
 
 : make-group ( bound quot -- )
-    swap [ { } make ] dip <group> ; inline
+    swap [ { } make ] dip <group> ; inline no-compile
 
-M: group intersect-scene ( hit ray group -- hit )
-    [ drop objs>> [ intersect-scene ] with each ] if-ray-sphere ;
-
-HINTS: M\ group intersect-scene { hit ray group } ;
+: intersect-scene ( hit ray scene -- hit )
+    {
+        { [ dup group? ] [ [ drop objs>> [ intersect-scene ] with each ] if-ray-sphere ] }
+        { [ dup sphere? ] [ [ [ sphere-n normalize ] keep <hit> nip ] if-ray-sphere ] }
+    } cond ; inline recursive no-compile
 
 CONSTANT: initial-hit T{ hit f double-4{ 0.0 0.0 0.0 0.0 } 1/0. }
 
 : initial-intersect ( ray scene -- hit )
-    [ initial-hit ] 2dip intersect-scene ; inline
+    [ initial-hit ] 2dip intersect-scene ; inline no-compile
 
 : ray-o ( ray hit -- o )
     [ [ orig>> ] [ normal>> delta v*n ] bi* ]
     [ [ dir>> ] [ lambda>> ] bi* v*n ]
-    2bi v+ v+ ; inline
+    2bi v+ v+ ; inline no-compile
 
 : sray-intersect ( ray scene hit -- ray )
-    swap [ ray-o light vneg <ray> ] dip initial-intersect ; inline
+    swap [ ray-o light vneg <ray> ] dip initial-intersect ; inline no-compile
 
-: ray-g ( hit -- g ) normal>> light v. ; inline
+: ray-g ( hit -- g ) normal>> light v. ; inline no-compile
 
 : cast-ray ( ray scene -- g )
     2dup initial-intersect dup lambda>> 1/0. = [
@@ -116,66 +106,61 @@ CONSTANT: initial-hit T{ hit f double-4{ 0.0 0.0 0.0 0.0 } 1/0. }
     ] [
         [ sray-intersect lambda>> 1/0. = ] keep swap
         [ ray-g neg ] [ drop 0.0 ] if
-    ] if ; inline
+    ] if ; inline no-compile
 
 : create-center ( c r d -- c2 )
-    [ 3.0 12.0 sqrt / * ] dip n*v v+ ; inline
+    [ 3.0 12.0 sqrt / * ] dip n*v v+ ; inline no-compile
 
 DEFER: create ( level c r -- scene )
 
 : create-step ( level c r d -- scene )
     over [ create-center ] dip 2.0 / [ 1 - ] 2dip create ;
 
-: create-offsets ( quot -- )
+CONSTANT: create-offsets
     {
         double-4{ -1.0 1.0 -1.0 0.0 }
         double-4{ 1.0 1.0 -1.0 0.0 }
         double-4{ -1.0 1.0 1.0 0.0 }
         double-4{ 1.0 1.0 1.0 0.0 }
-    } swap each ; inline
+    }
 
 : create-bound ( c r -- sphere ) 3.0 * <sphere> ;
 
 : create-group ( level c r -- scene )
     2dup create-bound [
         2dup <sphere> ,
-        [ [ 3dup ] dip create-step , ] create-offsets 3drop
+        create-offsets [ create-step , ] with with with each
     ] make-group ;
 
 : create ( level c r -- scene )
     pick 1 = [ <sphere> nip ] [ create-group ] if ;
 
 : ss-point ( dx dy -- point )
-    [ oversampling /f ] bi@ 0.0 0.0 double-4-boa ;
-
-: ss-grid ( -- ss-grid )
-    oversampling iota [ oversampling iota [ ss-point ] with map ] map ;
-
-: ray-grid ( point ss-grid -- ray-grid )
-    [
-        [ v+ normalize double-4{ 0.0 0.0 -4.0 0.0 } swap <ray> ] with map
-    ] with map ;
-
-: ray-pixel ( scene point -- n )
-    ss-grid ray-grid [ 0.0 ] 2dip
-    [ [ swap cast-ray + ] with each ] with each ;
-
-: pixel-grid ( -- grid )
-    size iota reverse [
+    [ oversampling /f ] bi@ 0.0 0.0 double-4-boa ; inline no-compile
+
+: ray-pixel ( scene point -- ray-grid )
+    [ 0.0 ] 2dip
+    oversampling iota [
+        oversampling iota [
+            ss-point v+ normalize
+            double-4{ 0.0 0.0 -4.0 0.0 } swap <ray>
+            swap cast-ray +
+        ] with with with each
+    ] with with each ; inline no-compile
+
+: ray-trace ( scene -- grid )
+    size iota <reversed> [
         size iota [
             [ size 0.5 * - ] bi@ swap size
-            0.0 double-4-boa
-        ] with map
-    ] map ;
+            0.0 double-4-boa ray-pixel
+        ] with with map
+    ] with map ;
 
 : pgm-header ( w h -- )
     "P5\n" % swap # " " % # "\n255\n" % ;
 
 : pgm-pixel ( n -- ) 255 * 0.5 + >fixnum , ;
 
-: ray-trace ( scene -- pixels )
-    pixel-grid [ [ ray-pixel ] with map ] with map ;
-
 : run ( -- string )
     levels double-4{ 0.0 -1.0 0.0 0.0 } 1.0 create ray-trace [
         size size pgm-header
index 3a3d6a66b77c3384f6dad73c500d73d702e67f41..72c63660e310af3df1baa847eb29c35703fa3bb1 100644 (file)
@@ -8,11 +8,17 @@ IN: mason.source
 : clone-factor ( -- )
     { "git" "clone" } home "factor" append-path suffix try-process ;
 
+: save-git-id ( -- )
+    git-id "git-id" to-file ;
+
+: delete-git-tree ( -- )
+    ".git" delete-tree ;
+
+: download-images ( -- )
+    images [ download-image ] each ;
+
 : prepare-source ( -- )
-    "factor" [
-        ".git" delete-tree
-        images [ download-image ] each
-    ] with-directory ;
+    "factor" [ save-git-id delete-git-tree download-images ] with-directory ;
 
 : package-name ( version -- string )
     "factor-src-" ".zip" surround ;
diff --git a/extra/math/points/points.factor b/extra/math/points/points.factor
new file mode 100644 (file)
index 0000000..107e81d
--- /dev/null
@@ -0,0 +1,26 @@
+USING: kernel arrays math.vectors sequences math ;
+
+IN: math.points
+
+<PRIVATE
+
+: X ( x -- point )      0   0 3array ;
+: Y ( y -- point ) 0 swap   0 3array ;
+: Z ( z -- point ) 0    0 rot 3array ;
+
+PRIVATE>
+
+: v+x ( seq x -- seq ) X v+ ;
+: v-x ( seq x -- seq ) X v- ;
+
+: v+y ( seq y -- seq ) Y v+ ;
+: v-y ( seq y -- seq ) Y v- ;
+
+: v+z ( seq z -- seq ) Z v+ ;
+: v-z ( seq z -- seq ) Z v- ;
+
+: rise ( pt2 pt1 -- n ) [ second ] bi@ - ;
+: run ( pt2 pt1 -- n ) [ first ] bi@ - ;
+: slope ( pt pt -- slope ) [ rise ] [ run ] 2bi / ;
+: midpoint ( point point -- point ) v+ 2 v/n ;
+: linear-solution ( pt pt -- x ) [ drop first2 ] [ slope ] 2bi / - ;
\ No newline at end of file
index ec190fed187da15b7c51c00c970a1b1cc855f3c2..9927486eb7b7167d5609ec13afa57d1a2cbf522f 100644 (file)
@@ -1,11 +1,11 @@
 ! Copyright (c) 2007, 2008 Aaron Schaefer.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: combinators.smart formatting fry io kernel macros math
-math.functions math.statistics memory sequences tools.time ;
+USING: combinators.smart formatting fry io kernel macros math math.functions
+math.statistics memory sequences tools.time ;
 IN: project-euler.ave-time
 
 MACRO: collect-benchmarks ( quot n -- seq )
-    swap '[ _ [ [ [ _ nullary ] preserving ] gc benchmark 1000 / ] replicate ] ;
+    swap '[ _ [ [ [ _ nullary ] preserving ] gc benchmark 6 10^ / ] replicate ] ;
 
 : ave-time ( quot n -- )
     [