From 6babe4bf3f47444a9f01291d26172ceafdbb7aaf Mon Sep 17 00:00:00 2001 From: Joe Groff Date: Tue, 3 Feb 2009 20:09:28 -0600 Subject: [PATCH 1/8] fill some holes in quadtree docs, rename quadtrees:prune to prune-quadtree to avoid colliding with sets:prune, and kill silly call to boa --- extra/quadtrees/quadtrees-docs.factor | 12 +++++++++--- extra/quadtrees/quadtrees-tests.factor | 6 +++--- extra/quadtrees/quadtrees.factor | 7 +++++-- 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/extra/quadtrees/quadtrees-docs.factor b/extra/quadtrees/quadtrees-docs.factor index f2de89ce3d..8240ac5db9 100644 --- a/extra/quadtrees/quadtrees-docs.factor +++ b/extra/quadtrees/quadtrees-docs.factor @@ -2,9 +2,11 @@ USING: arrays assocs help.markup help.syntax math.geometry.rect quadtrees quotat IN: quadtrees ARTICLE: "quadtrees" "Quadtrees" -"The " { $snippet "quadtrees" } " vocabulary implements the quadtree structure in Factor. Quadtrees follow the " { $link "assocs-protocol" } " for insertion, deletion, and querying of exact points, using two-dimensional vectors as keys. Additional words are provided for spatial queries and pruning the tree structure:" -{ $subsection prune } +"The " { $snippet "quadtrees" } " vocabulary implements the quadtree data structure in Factor." +{ $subsection } +"Quadtrees follow the " { $link "assocs-protocol" } " for insertion, deletion, and querying of exact points, using two-dimensional vectors as keys. Additional words are provided for spatial queries and pruning the tree structure:" { $subsection in-rect } +{ $subsection prune-quadtree } "The following words are provided to help write quadtree algorithms:" { $subsection descend } { $subsection each-quadrant } @@ -12,7 +14,11 @@ ARTICLE: "quadtrees" "Quadtrees" ABOUT: "quadtrees" -HELP: prune +HELP: +{ $values { "bounds" rect } { "quadtree" quadtree } } +{ $description "Constructs an empty quadtree covering the axis-aligned rectangle indicated by " { $snippet "bounds" } ". All the keys of " { $snippet "quadtree" } " must be two-dimensional vectors lying inside " { $snippet "bounds" } "." } ; + +HELP: prune-quadtree { $values { "tree" quadtree } } { $description "Removes empty nodes from " { $snippet "tree" } "." } ; diff --git a/extra/quadtrees/quadtrees-tests.factor b/extra/quadtrees/quadtrees-tests.factor index b96cdd82bf..118ac60a8c 100644 --- a/extra/quadtrees/quadtrees-tests.factor +++ b/extra/quadtrees/quadtrees-tests.factor @@ -98,7 +98,7 @@ IN: quadtrees.tests "d" { 0.75 0.25 } value>>key { 0.25 0.25 } delete>>key - prune + prune-quadtree ] unit-test [ T{ quadtree f T{ rect f { -1.0 -1.0 } { 2.0 2.0 } } f f @@ -116,7 +116,7 @@ IN: quadtrees.tests { 0.25 0.25 } delete>>key { 0.75 0.25 } delete>>key - prune + prune-quadtree ] unit-test [ T{ quadtree f T{ rect f { -1.0 -1.0 } { 2.0 2.0 } } f f @@ -160,7 +160,7 @@ IN: quadtrees.tests "g" { 0.25 0.25 } value>>key "h" { 0.75 0.75 } value>>key - prune + prune-quadtree ] unit-test [ 8 ] [ diff --git a/extra/quadtrees/quadtrees.factor b/extra/quadtrees/quadtrees.factor index 60446f4bf8..a47b55b760 100644 --- a/extra/quadtrees/quadtrees.factor +++ b/extra/quadtrees/quadtrees.factor @@ -6,7 +6,10 @@ IN: quadtrees TUPLE: quadtree { bounds rect } point value ll lr ul ur leaf? ; -: ( bounds -- quadtree ) f f f f f f t quadtree boa ; +: ( bounds -- quadtree ) + quadtree new + swap >>bounds + t >>leaf? ; : rect-ll ( rect -- point ) loc>> ; : rect-lr ( rect -- point ) [ loc>> ] [ width ] bi v+x ; @@ -165,7 +168,7 @@ DEFER: in-rect* PRIVATE> -: prune ( tree -- tree ) [ (prune) ] keep ; +: prune-quadtree ( tree -- tree ) [ (prune) ] keep ; : in-rect ( tree rect -- values ) [ 16 ] 2dip in-rect* ; From eec86d6043b09b6773ff887da61baef81669ef90 Mon Sep 17 00:00:00 2001 From: Doug Coleman Date: Wed, 4 Feb 2009 13:05:52 -0600 Subject: [PATCH 2/8] Fix io.launcher on Windows -- Microsoft does the same thing with devenv --- Makefile | 12 +++++++----- vm/Config.windows | 1 + vm/Config.windows.nt | 1 + vm/Config.windows.nt.x86.32 | 1 + vm/Config.windows.nt.x86.64 | 1 + vm/os-windows.c | 11 ----------- 6 files changed, 11 insertions(+), 16 deletions(-) diff --git a/Makefile b/Makefile index b41e756729..68c2c97426 100644 --- a/Makefile +++ b/Makefile @@ -130,18 +130,20 @@ solaris-x86-64: $(MAKE) $(EXECUTABLE) CONFIG=vm/Config.solaris.x86.64 freetype6.dll: - wget http://factorcode.org/dlls/freetype6.dll + wget $(DLL_PATH)/freetype6.dll chmod 755 freetype6.dll zlib1.dll: - wget http://factorcode.org/dlls/zlib1.dll + wget $(DLL_PATH)/zlib1.dll chmod 755 zlib1.dll -winnt-x86-32: freetype6.dll zlib1.dll +windows-dlls: freetype6.dll zlib1.dll + +winnt-x86-32: windows-dlls $(MAKE) $(EXECUTABLE) CONFIG=vm/Config.windows.nt.x86.32 $(MAKE) $(CONSOLE_EXECUTABLE) CONFIG=vm/Config.windows.nt.x86.32 -winnt-x86-64: +winnt-x86-64: windows-dlls $(MAKE) $(EXECUTABLE) CONFIG=vm/Config.windows.nt.x86.64 $(MAKE) $(CONSOLE_EXECUTABLE) CONFIG=vm/Config.windows.nt.x86.64 @@ -167,7 +169,7 @@ factor: $(DLL_OBJS) $(EXE_OBJS) factor-console: $(DLL_OBJS) $(EXE_OBJS) $(LINKER) $(ENGINE) $(DLL_OBJS) $(CC) $(LIBS) $(LIBPATH) -L. $(LINK_WITH_ENGINE) \ - $(CFLAGS) $(CFLAGS_CONSOLE) -o $@$(EXE_SUFFIX)$(EXE_EXTENSION) $(EXE_OBJS) + $(CFLAGS) $(CFLAGS_CONSOLE) -o factor$(EXE_SUFFIX)$(CONSOLE_EXTENSION) $(EXE_OBJS) clean: rm -f vm/*.o diff --git a/vm/Config.windows b/vm/Config.windows index 41eca86b5c..45d2f0cb98 100644 --- a/vm/Config.windows +++ b/vm/Config.windows @@ -2,6 +2,7 @@ CFLAGS += -DWINDOWS -mno-cygwin LIBS = -lm PLAF_DLL_OBJS += vm/os-windows.o EXE_EXTENSION=.exe +CONSOLE_EXTENSION=.com DLL_EXTENSION=.dll LINKER = $(CC) -shared -mno-cygwin -o LINK_WITH_ENGINE = -l$(DLL_PREFIX)factor$(DLL_SUFFIX) diff --git a/vm/Config.windows.nt b/vm/Config.windows.nt index de28ba64ba..ffaa899fe1 100644 --- a/vm/Config.windows.nt +++ b/vm/Config.windows.nt @@ -6,4 +6,5 @@ PLAF_EXE_OBJS += vm/resources.o PLAF_EXE_OBJS += vm/main-windows-nt.o CFLAGS += -mwindows CFLAGS_CONSOLE += -mconsole +CONSOLE_EXTENSION = .com include vm/Config.windows diff --git a/vm/Config.windows.nt.x86.32 b/vm/Config.windows.nt.x86.32 index 9a020a7bc1..d27629fe83 100644 --- a/vm/Config.windows.nt.x86.32 +++ b/vm/Config.windows.nt.x86.32 @@ -1,3 +1,4 @@ +DLL_PATH=http://factorcode.org/dlls WINDRES=windres include vm/Config.windows.nt include vm/Config.x86.32 diff --git a/vm/Config.windows.nt.x86.64 b/vm/Config.windows.nt.x86.64 index f0c0a068cb..ddb61480e5 100644 --- a/vm/Config.windows.nt.x86.64 +++ b/vm/Config.windows.nt.x86.64 @@ -1,3 +1,4 @@ +DLL_PATH=http://factorcode.org/dlls/64 CC=$(WIN64_PATH)-gcc.exe WINDRES=$(WIN64_PATH)-windres.exe include vm/Config.windows.nt diff --git a/vm/os-windows.c b/vm/os-windows.c index c4d29ea57f..2abc04cb3b 100755 --- a/vm/os-windows.c +++ b/vm/os-windows.c @@ -109,17 +109,6 @@ const F_CHAR *default_image_path(void) snwprintf(temp_path, sizeof(temp_path)-1, L"%s.image", full_path); temp_path[sizeof(temp_path) - 1] = 0; - if(!windows_stat(temp_path)) { - unsigned int len = wcslen(full_path); - F_CHAR magic[] = L"-console"; - unsigned int magic_len = wcslen(magic); - - if(!wcsncmp(full_path + len - magic_len, magic, MIN(len, magic_len))) - full_path[len - magic_len] = 0; - snwprintf(temp_path, sizeof(temp_path)-1, L"%s.image", full_path); - temp_path[sizeof(temp_path) - 1] = 0; - } - return safe_strdup(temp_path); } From 3d84d17cc6fe1521b267cecf80316060ae4ffc52 Mon Sep 17 00:00:00 2001 From: Doug Coleman Date: Wed, 4 Feb 2009 13:28:19 -0600 Subject: [PATCH 3/8] use the console factor for tests --- basis/io/launcher/windows/nt/nt-tests.factor | 25 +++++++++++--------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/basis/io/launcher/windows/nt/nt-tests.factor b/basis/io/launcher/windows/nt/nt-tests.factor index 93b1e8c2ff..4dd0eebed3 100644 --- a/basis/io/launcher/windows/nt/nt-tests.factor +++ b/basis/io/launcher/windows/nt/nt-tests.factor @@ -1,7 +1,7 @@ USING: io.launcher tools.test calendar accessors environment namespaces kernel system arrays io io.files io.encodings.ascii sequences parser assocs hashtables math continuations eval -io.files.temp io.directories io.pathnames ; +io.files.temp io.directories io.pathnames splitting ; IN: io.launcher.windows.nt.tests [ ] [ @@ -23,9 +23,12 @@ IN: io.launcher.windows.nt.tests [ f ] [ "notepad" get process-running? ] unit-test +: console-vm ( -- path ) + vm ".exe" ?tail [ ".com" append ] when ; + [ ] [ - vm "-quiet" "-run=hello-world" 3array >>command + console-vm "-quiet" "-run=hello-world" 3array >>command "out.txt" temp-file >>stdout try-process ] unit-test @@ -36,7 +39,7 @@ IN: io.launcher.windows.nt.tests [ ] [ - vm "-run=listener" 2array >>command + console-vm "-run=listener" 2array >>command +closed+ >>stdin try-process ] unit-test @@ -47,7 +50,7 @@ IN: io.launcher.windows.nt.tests [ ] [ launcher-test-path [ - vm "-script" "stderr.factor" 3array >>command + console-vm "-script" "stderr.factor" 3array >>command "out.txt" temp-file >>stdout "err.txt" temp-file >>stderr try-process @@ -65,7 +68,7 @@ IN: io.launcher.windows.nt.tests [ ] [ launcher-test-path [ - vm "-script" "stderr.factor" 3array >>command + console-vm "-script" "stderr.factor" 3array >>command "out.txt" temp-file >>stdout +stdout+ >>stderr try-process @@ -79,7 +82,7 @@ IN: io.launcher.windows.nt.tests [ "output" ] [ launcher-test-path [ - vm "-script" "stderr.factor" 3array >>command + console-vm "-script" "stderr.factor" 3array >>command "err2.txt" temp-file >>stderr ascii lines first ] with-directory @@ -92,7 +95,7 @@ IN: io.launcher.windows.nt.tests [ t ] [ launcher-test-path [ - vm "-script" "env.factor" 3array >>command + console-vm "-script" "env.factor" 3array >>command ascii contents ] with-directory eval @@ -102,7 +105,7 @@ IN: io.launcher.windows.nt.tests [ t ] [ launcher-test-path [ - vm "-script" "env.factor" 3array >>command + console-vm "-script" "env.factor" 3array >>command +replace-environment+ >>environment-mode os-envs >>environment ascii contents @@ -114,7 +117,7 @@ IN: io.launcher.windows.nt.tests [ "B" ] [ launcher-test-path [ - vm "-script" "env.factor" 3array >>command + console-vm "-script" "env.factor" 3array >>command { { "A" "B" } } >>environment ascii contents ] with-directory eval @@ -125,7 +128,7 @@ IN: io.launcher.windows.nt.tests [ f ] [ launcher-test-path [ - vm "-script" "env.factor" 3array >>command + console-vm "-script" "env.factor" 3array >>command { { "USERPROFILE" "XXX" } } >>environment +prepend-environment+ >>environment-mode ascii contents @@ -151,7 +154,7 @@ IN: io.launcher.windows.nt.tests 2 [ launcher-test-path [ - vm "-script" "append.factor" 3array >>command + console-vm "-script" "append.factor" 3array >>command "append-test" temp-file >>stdout try-process ] with-directory From cdc5529070268743f56d6c87a07c35fa99c0e4d6 Mon Sep 17 00:00:00 2001 From: Doug Coleman Date: Wed, 4 Feb 2009 13:31:57 -0600 Subject: [PATCH 4/8] ignore a windows file --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 05a53c02c6..435595f502 100644 --- a/.gitignore +++ b/.gitignore @@ -11,6 +11,7 @@ Factor/factor *.image *.dylib factor +factor.com *#*# .DS_Store .gdb_history From b6c3bc892d22af12681487303d89cdc4f06f0816 Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 4 Feb 2009 18:21:58 -0600 Subject: [PATCH 5/8] Fix the build support for windows again, have the makefile load Config.* files in the top level so that freetype.dll and zlib1.dll targets can make --- Makefile | 5 ++--- build-support/factor.sh | 14 +++++++++++++- vm/Config.windows.nt.x86.64 | 1 + 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index 68c2c97426..e84a5f9c5a 100644 --- a/Makefile +++ b/Makefile @@ -17,9 +17,8 @@ else CFLAGS += -O3 $(SITE_CFLAGS) endif -ifdef CONFIG - include $(CONFIG) -endif +CONFIG = $(shell ./build-support/factor.sh config-target) +include $(CONFIG) ENGINE = $(DLL_PREFIX)factor$(DLL_SUFFIX)$(DLL_EXTENSION) diff --git a/build-support/factor.sh b/build-support/factor.sh index 44c047155d..e70ef40e5c 100755 --- a/build-support/factor.sh +++ b/build-support/factor.sh @@ -236,7 +236,7 @@ find_word_size() { set_factor_binary() { case $OS in - winnt) FACTOR_BINARY=factor-console.exe;; + winnt) FACTOR_BINARY=factor.com;; *) FACTOR_BINARY=factor;; esac } @@ -260,6 +260,7 @@ echo_build_info() { $ECHO FACTOR_BINARY=$FACTOR_BINARY $ECHO FACTOR_LIBRARY=$FACTOR_LIBRARY $ECHO FACTOR_IMAGE=$FACTOR_IMAGE + $ECHO CONFIG_TARGET=$CONFIG_TARGET $ECHO MAKE_TARGET=$MAKE_TARGET $ECHO BOOT_IMAGE=$BOOT_IMAGE $ECHO MAKE_IMAGE_TARGET=$MAKE_IMAGE_TARGET @@ -289,20 +290,30 @@ set_build_info() { if [[ $OS == macosx && $ARCH == ppc ]] ; then MAKE_IMAGE_TARGET=macosx-ppc MAKE_TARGET=macosx-ppc + CONFIG_TARGET=macosx.ppc elif [[ $OS == linux && $ARCH == ppc ]] ; then MAKE_IMAGE_TARGET=linux-ppc MAKE_TARGET=linux-ppc + CONFIG_TARGET=linux.ppc elif [[ $OS == winnt && $ARCH == x86 && $WORD == 64 ]] ; then MAKE_IMAGE_TARGET=winnt-x86.64 MAKE_TARGET=winnt-x86-64 + CONFIG_TARGET=windows.nt.x86.64 + elif [[ $OS == winnt && $ARCH == x86 && $WORD == 32 ]] ; then + MAKE_IMAGE_TARGET=winnt-x86.32 + MAKE_TARGET=winnt-x86-32 + CONFIG_TARGET=windows.nt.x86.32 elif [[ $ARCH == x86 && $WORD == 64 ]] ; then MAKE_IMAGE_TARGET=unix-x86.64 MAKE_TARGET=$OS-x86-64 + CONFIG_TARGET=$OS.x86.64 else MAKE_IMAGE_TARGET=$ARCH.$WORD MAKE_TARGET=$OS-$ARCH-$WORD + CONFIG_TARGET=$OS.$ARCH.$WORD fi BOOT_IMAGE=boot.$MAKE_IMAGE_TARGET.image + CONFIG_TARGET=vm/Config.$CONFIG_TARGET } parse_build_info() { @@ -570,5 +581,6 @@ case "$1" in dlls) get_config_info; maybe_download_dlls;; net-bootstrap) get_config_info; update_boot_images; bootstrap ;; make-target) ECHO=false; find_build_info; echo $MAKE_TARGET ;; + config-target) ECHO=false; find_build_info; echo $CONFIG_TARGET ;; *) usage ;; esac diff --git a/vm/Config.windows.nt.x86.64 b/vm/Config.windows.nt.x86.64 index ddb61480e5..13ef665b19 100644 --- a/vm/Config.windows.nt.x86.64 +++ b/vm/Config.windows.nt.x86.64 @@ -1,3 +1,4 @@ +#error "lol" DLL_PATH=http://factorcode.org/dlls/64 CC=$(WIN64_PATH)-gcc.exe WINDRES=$(WIN64_PATH)-windres.exe From ccdd8999e1964eb698a199c564d5b315ae8669d7 Mon Sep 17 00:00:00 2001 From: Joe Groff Date: Wed, 4 Feb 2009 19:46:19 -0600 Subject: [PATCH 6/8] swizzle word to swizzle sequences --- basis/math/geometry/rect/rect.factor | 5 ++++ basis/math/vectors/vectors.factor | 3 ++ extra/quadtrees/quadtrees-tests.factor | 41 +++++++++++++++++++++++++- extra/quadtrees/quadtrees.factor | 20 +++++++++---- 4 files changed, 62 insertions(+), 7 deletions(-) diff --git a/basis/math/geometry/rect/rect.factor b/basis/math/geometry/rect/rect.factor index a7cefceae8..08cfbbcc46 100644 --- a/basis/math/geometry/rect/rect.factor +++ b/basis/math/geometry/rect/rect.factor @@ -60,9 +60,14 @@ M: rect set-height! ( rect height -- rect ) over dim>> set-second ; M: rect set-x! ( rect x -- rect ) over loc>> set-first ; M: rect set-y! ( rect y -- rect ) over loc>> set-second ; +: rect-containing ( points -- rect ) + [ vleast ] [ vgreatest ] bi + [ drop ] [ swap v- ] 2bi ; + ! Accessing corners : top-left ( rect -- point ) loc>> ; : top-right ( rect -- point ) [ loc>> ] [ width 1 - ] bi v+x ; : bottom-left ( rect -- point ) [ loc>> ] [ height 1 - ] bi v+y ; : bottom-right ( rect -- point ) [ loc>> ] [ dim>> ] bi v+ { 1 1 } v- ; + diff --git a/basis/math/vectors/vectors.factor b/basis/math/vectors/vectors.factor index a6967a7218..4d9a0916b5 100644 --- a/basis/math/vectors/vectors.factor +++ b/basis/math/vectors/vectors.factor @@ -19,6 +19,9 @@ IN: math.vectors : vmax ( u v -- w ) [ max ] 2map ; : vmin ( u v -- w ) [ min ] 2map ; +: vgreatest ( array -- vmax ) { -1.0/0.0 -1.0/0.0 } [ vmax ] reduce ; +: vleast ( array -- vmax ) { 1.0/0.0 1.0/0.0 } [ vmin ] reduce ; + : v. ( u v -- x ) [ * ] [ + ] 2map-reduce ; : norm-sq ( v -- x ) [ absq ] [ + ] map-reduce ; : norm ( v -- x ) norm-sq sqrt ; diff --git a/extra/quadtrees/quadtrees-tests.factor b/extra/quadtrees/quadtrees-tests.factor index 118ac60a8c..7a17c1fb44 100644 --- a/extra/quadtrees/quadtrees-tests.factor +++ b/extra/quadtrees/quadtrees-tests.factor @@ -1,5 +1,5 @@ ! (c) 2009 Joe Groff, see BSD license -USING: assocs kernel tools.test quadtrees math.geometry.rect sorting ; +USING: accessors assocs kernel tools.test quadtrees math.geometry.rect sorting ; IN: quadtrees.tests : unit-bounds ( -- rect ) { -1.0 -1.0 } { 2.0 2.0 } ; @@ -200,3 +200,42 @@ IN: quadtrees.tests >alist natural-sort ] unit-test +TUPLE: pointy-thing center ; + +[ { + T{ pointy-thing f { 0 0 } } + T{ pointy-thing f { 1 0 } } + T{ pointy-thing f { 0 1 } } + T{ pointy-thing f { 1 1 } } + T{ pointy-thing f { 2 0 } } + T{ pointy-thing f { 3 0 } } + T{ pointy-thing f { 2 1 } } + T{ pointy-thing f { 3 1 } } + T{ pointy-thing f { 0 2 } } + T{ pointy-thing f { 1 2 } } + T{ pointy-thing f { 0 3 } } + T{ pointy-thing f { 1 3 } } + T{ pointy-thing f { 2 2 } } + T{ pointy-thing f { 3 2 } } + T{ pointy-thing f { 2 3 } } + T{ pointy-thing f { 3 3 } } +} ] [ + { + T{ pointy-thing f { 3 1 } } + T{ pointy-thing f { 2 3 } } + T{ pointy-thing f { 3 2 } } + T{ pointy-thing f { 0 1 } } + T{ pointy-thing f { 2 2 } } + T{ pointy-thing f { 1 1 } } + T{ pointy-thing f { 3 0 } } + T{ pointy-thing f { 3 3 } } + T{ pointy-thing f { 1 3 } } + T{ pointy-thing f { 2 1 } } + T{ pointy-thing f { 0 0 } } + T{ pointy-thing f { 2 0 } } + T{ pointy-thing f { 1 0 } } + T{ pointy-thing f { 0 2 } } + T{ pointy-thing f { 1 2 } } + T{ pointy-thing f { 0 3 } } + } [ center>> ] swizzle +] unit-test diff --git a/extra/quadtrees/quadtrees.factor b/extra/quadtrees/quadtrees.factor index a47b55b760..d9bdbe4aeb 100644 --- a/extra/quadtrees/quadtrees.factor +++ b/extra/quadtrees/quadtrees.factor @@ -1,7 +1,7 @@ ! (c) 2009 Joe Groff, see BSD license USING: assocs kernel math.geometry.rect combinators accessors math.vectors vectors sequences math math.points math.geometry -combinators.short-circuit arrays fry locals ; +combinators.short-circuit arrays fry ; IN: quadtrees TUPLE: quadtree { bounds rect } point value ll lr ul ur leaf? ; @@ -29,11 +29,13 @@ TUPLE: quadtree { bounds rect } point value ll lr ul ur leaf? ; : descend ( pt node -- pt subnode ) [ drop ] [ quadrant ] 2bi ; inline -:: each-quadrant ( node quot -- ) - node ll>> quot call - node lr>> quot call - node ul>> quot call - node ur>> quot call ; inline +: each-quadrant ( node quot -- ) + { + [ [ ll>> ] [ call ] bi* ] + [ [ lr>> ] [ call ] bi* ] + [ [ ul>> ] [ call ] bi* ] + [ [ ur>> ] [ call ] bi* ] + } 2cleave ; inline : map-quadrant ( node quot: ( child-node -- x ) -- array ) each-quadrant 4array ; inline @@ -76,6 +78,7 @@ DEFER: in-rect* [ node-insert ] [ node-insert ] bi ; : leaf-replaceable? ( pt leaf -- ? ) point>> { [ nip not ] [ = ] } 2|| ; + : leaf-insert ( value point leaf -- ) 2dup leaf-replaceable? [ [ (>>point) ] [ (>>value) ] bi ] @@ -189,3 +192,8 @@ M: quadtree clear-assoc ( assoc -- ) f >>value drop ; +: swizzle ( sequence quot -- sequence' ) + [ dup ] dip map + [ zip ] [ rect-containing ] bi + [ '[ first2 _ set-at ] each ] [ values ] bi ; + From 91c06344517d0a0d7872b874084fed1351f5e941 Mon Sep 17 00:00:00 2001 From: Joe Groff Date: Wed, 4 Feb 2009 20:05:26 -0600 Subject: [PATCH 7/8] docs for swizzle --- extra/quadtrees/quadtrees-docs.factor | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/extra/quadtrees/quadtrees-docs.factor b/extra/quadtrees/quadtrees-docs.factor index 8240ac5db9..7b0d3772a0 100644 --- a/extra/quadtrees/quadtrees-docs.factor +++ b/extra/quadtrees/quadtrees-docs.factor @@ -10,7 +10,9 @@ ARTICLE: "quadtrees" "Quadtrees" "The following words are provided to help write quadtree algorithms:" { $subsection descend } { $subsection each-quadrant } -{ $subsection map-quadrant } ; +{ $subsection map-quadrant } +"Quadtrees can be used to \"swizzle\" a sequence to improve the locality of spatial data in memory:" +{ $subsection swizzle } ; ABOUT: "quadtrees" @@ -38,3 +40,6 @@ HELP: map-quadrant { $values { "node" quadtree } { "quot" quotation } { "array" array } } { $description "Calls " { $snippet "quot" } " with each subnode of " { $snippet "node" } " on the top of the stack in turn, collecting the four results into " { $snippet "array" } "." } ; +HELP: swizzle +{ $values { "sequence" sequence } { "quot" quotation } { "sequence'" sequence } } +{ $description "Swizzles " { $snippet "sequence" } " based on the two-dimensional vector values returned by calling " { $snippet "quot" } " on each element of " { $snippet "sequence" } "." } ; From 4019752811ed5e6e14c5324dfc131c8c782855b1 Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 4 Feb 2009 23:15:10 -0600 Subject: [PATCH 8/8] remove hacks from the makefile and build-support --- Makefile | 23 +++++++---------------- build-support/factor.sh | 9 --------- 2 files changed, 7 insertions(+), 25 deletions(-) diff --git a/Makefile b/Makefile index e84a5f9c5a..5461ea5de9 100644 --- a/Makefile +++ b/Makefile @@ -17,11 +17,12 @@ else CFLAGS += -O3 $(SITE_CFLAGS) endif -CONFIG = $(shell ./build-support/factor.sh config-target) -include $(CONFIG) - ENGINE = $(DLL_PREFIX)factor$(DLL_SUFFIX)$(DLL_EXTENSION) +ifdef CONFIG + include $(CONFIG) +endif + DLL_OBJS = $(PLAF_DLL_OBJS) \ vm/alien.o \ vm/bignum.o \ @@ -128,21 +129,11 @@ solaris-x86-32: solaris-x86-64: $(MAKE) $(EXECUTABLE) CONFIG=vm/Config.solaris.x86.64 -freetype6.dll: - wget $(DLL_PATH)/freetype6.dll - chmod 755 freetype6.dll - -zlib1.dll: - wget $(DLL_PATH)/zlib1.dll - chmod 755 zlib1.dll - -windows-dlls: freetype6.dll zlib1.dll - -winnt-x86-32: windows-dlls +winnt-x86-32: $(MAKE) $(EXECUTABLE) CONFIG=vm/Config.windows.nt.x86.32 $(MAKE) $(CONSOLE_EXECUTABLE) CONFIG=vm/Config.windows.nt.x86.32 -winnt-x86-64: windows-dlls +winnt-x86-64: $(MAKE) $(EXECUTABLE) CONFIG=vm/Config.windows.nt.x86.64 $(MAKE) $(CONSOLE_EXECUTABLE) CONFIG=vm/Config.windows.nt.x86.64 @@ -159,7 +150,7 @@ macosx.app: factor -change libfactor.dylib \ @executable_path/../Frameworks/libfactor.dylib \ Factor.app/Contents/MacOS/factor - + factor: $(DLL_OBJS) $(EXE_OBJS) $(LINKER) $(ENGINE) $(DLL_OBJS) $(CC) $(LIBS) $(LIBPATH) -L. $(LINK_WITH_ENGINE) \ diff --git a/build-support/factor.sh b/build-support/factor.sh index e70ef40e5c..36d52601a5 100755 --- a/build-support/factor.sh +++ b/build-support/factor.sh @@ -260,7 +260,6 @@ echo_build_info() { $ECHO FACTOR_BINARY=$FACTOR_BINARY $ECHO FACTOR_LIBRARY=$FACTOR_LIBRARY $ECHO FACTOR_IMAGE=$FACTOR_IMAGE - $ECHO CONFIG_TARGET=$CONFIG_TARGET $ECHO MAKE_TARGET=$MAKE_TARGET $ECHO BOOT_IMAGE=$BOOT_IMAGE $ECHO MAKE_IMAGE_TARGET=$MAKE_IMAGE_TARGET @@ -290,30 +289,23 @@ set_build_info() { if [[ $OS == macosx && $ARCH == ppc ]] ; then MAKE_IMAGE_TARGET=macosx-ppc MAKE_TARGET=macosx-ppc - CONFIG_TARGET=macosx.ppc elif [[ $OS == linux && $ARCH == ppc ]] ; then MAKE_IMAGE_TARGET=linux-ppc MAKE_TARGET=linux-ppc - CONFIG_TARGET=linux.ppc elif [[ $OS == winnt && $ARCH == x86 && $WORD == 64 ]] ; then MAKE_IMAGE_TARGET=winnt-x86.64 MAKE_TARGET=winnt-x86-64 - CONFIG_TARGET=windows.nt.x86.64 elif [[ $OS == winnt && $ARCH == x86 && $WORD == 32 ]] ; then MAKE_IMAGE_TARGET=winnt-x86.32 MAKE_TARGET=winnt-x86-32 - CONFIG_TARGET=windows.nt.x86.32 elif [[ $ARCH == x86 && $WORD == 64 ]] ; then MAKE_IMAGE_TARGET=unix-x86.64 MAKE_TARGET=$OS-x86-64 - CONFIG_TARGET=$OS.x86.64 else MAKE_IMAGE_TARGET=$ARCH.$WORD MAKE_TARGET=$OS-$ARCH-$WORD - CONFIG_TARGET=$OS.$ARCH.$WORD fi BOOT_IMAGE=boot.$MAKE_IMAGE_TARGET.image - CONFIG_TARGET=vm/Config.$CONFIG_TARGET } parse_build_info() { @@ -581,6 +573,5 @@ case "$1" in dlls) get_config_info; maybe_download_dlls;; net-bootstrap) get_config_info; update_boot_images; bootstrap ;; make-target) ECHO=false; find_build_info; echo $MAKE_TARGET ;; - config-target) ECHO=false; find_build_info; echo $CONFIG_TARGET ;; *) usage ;; esac