diff --git a/basis/bootstrap/image/download/download.factor b/basis/bootstrap/image/download/download.factor index eeaccd9347..15a0e679c5 100644 --- a/basis/bootstrap/image/download/download.factor +++ b/basis/bootstrap/image/download/download.factor @@ -4,7 +4,7 @@ USING: http.client checksums checksums.md5 splitting assocs kernel io.files bootstrap.image sequences io urls ; IN: bootstrap.image.download -CONSTANT: url URL" http://factorcode.org/images/latest/" +CONSTANT: url URL" http://downloads.factorcode.org/images/latest/" : download-checksums ( -- alist ) url "checksums.txt" >url derive-url http-get nip diff --git a/basis/bootstrap/image/upload/upload.factor b/basis/bootstrap/image/upload/upload.factor index 7f25ce9c01..29f84c8151 100644 --- a/basis/bootstrap/image/upload/upload.factor +++ b/basis/bootstrap/image/upload/upload.factor @@ -10,7 +10,7 @@ SYMBOL: upload-images-destination : destination ( -- dest ) upload-images-destination get - "slava@factorcode.org:/var/www/factorcode.org/newsite/images/latest/" + "slava_pestov@downloads.factorcode.org:downloads.factorcode.org/images/latest/" or ; : checksums ( -- temp ) "checksums.txt" temp-file ; diff --git a/basis/channels/remote/remote-docs.factor b/basis/channels/remote/remote-docs.factor index 266d774056..2215d959a3 100644 --- a/basis/channels/remote/remote-docs.factor +++ b/basis/channels/remote/remote-docs.factor @@ -1,7 +1,7 @@ ! Copyright (C) 2007 Chris Double. ! See http://factorcode.org/license.txt for BSD license. USING: channels concurrency.distributed help.markup help.syntax -io.servers.connection ; +io.servers ; IN: channels.remote HELP: diff --git a/basis/compiler/cfg/alias-analysis/alias-analysis.factor b/basis/compiler/cfg/alias-analysis/alias-analysis.factor index 775bf65fe5..697a9dfcdd 100644 --- a/basis/compiler/cfg/alias-analysis/alias-analysis.factor +++ b/basis/compiler/cfg/alias-analysis/alias-analysis.factor @@ -14,7 +14,8 @@ compiler.cfg.representations.preferred ; FROM: namespaces => set ; IN: compiler.cfg.alias-analysis -! We try to eliminate redundant slot operations using some simple heuristics. +! We try to eliminate redundant slot operations using some +! simple heuristics. ! ! All heap-allocated objects which are loaded from the stack, or ! other object slots are pessimistically assumed to belong to @@ -108,7 +109,7 @@ SYMBOL: heap-ac 2dup eq? [ 2drop ] [ [ ac>vregs ] dip [ vregs>acs get '[ [ _ ] dip _ set-at ] each ] - [ acs>vregs get at push-all ] + [ ac>vregs push-all ] 2bi ] if ; @@ -129,7 +130,7 @@ ERROR: vreg-not-new vreg ; #! Set alias class of newly-seen vreg. vreg vregs>acs get key? [ vreg vreg-not-new ] when ac vreg vregs>acs get set-at - vreg ac acs>vregs get push-at ; + vreg ac ac>vregs push ; : live-slot ( slot#/f vreg -- vreg' ) #! If the slot number is unknown, we never reuse a previous diff --git a/basis/compiler/cfg/instructions/instructions.factor b/basis/compiler/cfg/instructions/instructions.factor index c51d41443a..210489f8b0 100644 --- a/basis/compiler/cfg/instructions/instructions.factor +++ b/basis/compiler/cfg/instructions/instructions.factor @@ -830,13 +830,16 @@ UNION: conditional-branch-insn UNION: ##read ##slot ##slot-imm ##vm-field ##alien-global ; UNION: ##write ##set-slot ##set-slot-imm ##set-vm-field ; -! Instructions that contain subroutine calls to functions which -! can callback arbitrary Factor code -UNION: factor-call-insn +UNION: alien-call-insn ##alien-invoke ##alien-indirect ##alien-assembly ; +! Instructions that contain subroutine calls to functions which +! can callback arbitrary Factor code +UNION: factor-call-insn +alien-call-insn ; + ! Instructions that contain subroutine calls to functions which ! allocate memory UNION: gc-map-insn @@ -848,15 +851,10 @@ factor-call-insn ; M: gc-map-insn clone call-next-method [ clone ] change-gc-map ; ! Each one has a gc-map slot -TUPLE: gc-map scrub-d scrub-r gc-roots ; +TUPLE: gc-map scrub-d scrub-r gc-roots derived-roots ; : ( -- gc-map ) gc-map new ; -UNION: alien-call-insn -##alien-invoke -##alien-indirect -##alien-assembly ; - ! Instructions that clobber registers. They receive inputs and ! produce outputs in spill slots. UNION: hairy-clobber-insn diff --git a/basis/compiler/cfg/linear-scan/assignment/assignment.factor b/basis/compiler/cfg/linear-scan/assignment/assignment.factor index 9a66307a93..96235b6807 100644 --- a/basis/compiler/cfg/linear-scan/assignment/assignment.factor +++ b/basis/compiler/cfg/linear-scan/assignment/assignment.factor @@ -146,9 +146,15 @@ RENAMING: assign [ vreg>reg ] [ vreg>reg ] [ vreg>reg ] M: vreg-insn assign-registers-in-insn [ assign-insn-defs ] [ assign-insn-uses ] [ assign-insn-temps ] tri ; +: assign-gc-roots ( gc-map -- ) + [ [ vreg>spill-slot ] map ] change-gc-roots drop ; + +: assign-derived-roots ( gc-map -- ) + [ [ [ vreg>spill-slot ] bi@ ] assoc-map ] change-derived-roots drop ; + M: gc-map-insn assign-registers-in-insn [ [ assign-insn-defs ] [ assign-insn-uses ] [ assign-insn-temps ] tri ] - [ gc-map>> [ [ vreg>spill-slot ] map ] change-gc-roots drop ] + [ gc-map>> [ assign-gc-roots ] [ assign-derived-roots ] bi ] bi ; M: insn assign-registers-in-insn drop ; diff --git a/basis/compiler/cfg/liveness/liveness-tests.factor b/basis/compiler/cfg/liveness/liveness-tests.factor index a6bd82183a..ba870fbc75 100644 --- a/basis/compiler/cfg/liveness/liveness-tests.factor +++ b/basis/compiler/cfg/liveness/liveness-tests.factor @@ -205,4 +205,43 @@ V{ [ H{ { 0 0 } } ] [ 2 get 4 get edge-live-in ] unit-test -[ H{ { 1 1 } } ] [ 3 get 4 get edge-live-in ] unit-test \ No newline at end of file +[ H{ { 1 1 } } ] [ 3 get 4 get edge-live-in ] unit-test + + +V{ + T{ ##prologue } + T{ ##branch } +} 0 test-bb + +V{ + T{ ##peek f 0 D 0 } + T{ ##tagged>integer f 1 0 } + T{ ##call-gc f T{ gc-map } } + T{ ##replace f 0 D 0 } + T{ ##call-gc f T{ gc-map } } + T{ ##replace f 1 D 0 } + T{ ##branch } +} 1 test-bb + +V{ + T{ ##epilogue } + T{ ##return } +} 2 test-bb + +0 1 edge +1 2 edge + +H{ + { 0 tagged-rep } + { 1 int-rep } +} representations set + +[ ] [ cfg new 0 get >>entry dup cfg set compute-live-sets ] unit-test + +[ V{ { 1 0 } } ] [ 1 get instructions>> 2 swap nth gc-map>> derived-roots>> ] unit-test + +[ { 0 } ] [ 1 get instructions>> 2 swap nth gc-map>> gc-roots>> ] unit-test + +[ V{ { 1 0 } } ] [ 1 get instructions>> 4 swap nth gc-map>> derived-roots>> ] unit-test + +[ { 0 } ] [ 1 get instructions>> 4 swap nth gc-map>> gc-roots>> ] unit-test \ No newline at end of file diff --git a/basis/compiler/cfg/liveness/liveness.factor b/basis/compiler/cfg/liveness/liveness.factor index 25d78a8d8f..772e4f390f 100644 --- a/basis/compiler/cfg/liveness/liveness.factor +++ b/basis/compiler/cfg/liveness/liveness.factor @@ -1,15 +1,28 @@ ! Copyright (C) 2009, 2010 Slava Pestov. ! See http://factorcode.org/license.txt for BSD license. -USING: kernel accessors assocs fry deques dlists namespaces -sequences sets compiler.cfg compiler.cfg.def-use -compiler.cfg.instructions compiler.cfg.registers -compiler.cfg.utilities compiler.cfg.predecessors -compiler.cfg.rpo cpu.architecture ; +USING: arrays kernel accessors assocs fry locals combinators +deques dlists namespaces sequences sets compiler.cfg +compiler.cfg.def-use compiler.cfg.instructions +compiler.cfg.registers compiler.cfg.utilities +compiler.cfg.predecessors compiler.cfg.rpo cpu.architecture ; FROM: namespaces => set ; IN: compiler.cfg.liveness -! See http://en.wikipedia.org/wiki/Liveness_analysis +! Similar to http://en.wikipedia.org/wiki/Liveness_analysis, +! with three additions: +! 1) With SSA, it is not sufficient to have a single live-in set +! per block. There is also there is an edge-live-in set per +! edge, consisting of phi inputs from each predecessor. +! 2) Liveness analysis annotates call sites with GC maps +! indicating the spill slots in the stack frame that contain +! tagged pointers, and thus have to be visited if a GC occurs +! inside the call. +! 3) GC maps can contain derived pointers. A derived pointer is +! a pointer into the middle of a data heap object. Each derived +! pointer has a base pointer, to keep it up to date when objects +! are moved by the garbage collector. This extends live +! intervals and inserts new ##phi instructions. SYMBOL: live-ins : live-in ( bb -- set ) @@ -27,6 +40,8 @@ SYMBOL: edge-live-ins : edge-live-in ( predecessor basic-block -- set ) edge-live-ins get at at ; +SYMBOL: base-pointers + GENERIC: visit-insn ( live-set insn -- live-set ) : kill-defs ( live-set insn -- live-set ) @@ -35,20 +50,64 @@ GENERIC: visit-insn ( live-set insn -- live-set ) : gen-uses ( live-set insn -- live-set ) uses-vregs [ over conjoin ] each ; inline -M: vreg-insn visit-insn [ kill-defs ] [ gen-uses ] bi ; +M: vreg-insn visit-insn + [ kill-defs ] [ gen-uses ] bi ; -! Our liveness analysis annotates call sites with GC maps -! indicating the spill slots in the stack frame that contain -! tagged pointers, and thus have to be visited if a GC occurs -! inside the call. +DEFER: lookup-base-pointer + +GENERIC: lookup-base-pointer* ( insn -- vreg/f ) + +M: ##tagged>integer lookup-base-pointer* src>> ; + +M: ##unbox-any-c-ptr lookup-base-pointer* + ! If the input to unbox-any-c-ptr was an alien and not a + ! byte array, then the derived pointer will be outside of + ! the data heap. The GC has to handle this case and ignore + ! it. + src>> ; + +M: ##copy lookup-base-pointer* src>> lookup-base-pointer ; + +M: ##add-imm lookup-base-pointer* src1>> lookup-base-pointer ; + +M: ##sub-imm lookup-base-pointer* src1>> lookup-base-pointer ; + +M: ##add lookup-base-pointer* + ! If both operands have a base pointer, then the user better + ! not be doing memory reads and writes on the object, since + ! we don't give it a base pointer in that case at all. + [ src1>> ] [ src2>> ] bi [ lookup-base-pointer ] bi@ xor ; + +M: ##sub lookup-base-pointer* + src1>> lookup-base-pointer ; + +M: vreg-insn lookup-base-pointer* drop f ; + +: lookup-base-pointer ( vreg -- vreg/f ) + base-pointers get [ insn-of lookup-base-pointer* ] cache ; + +:: visit-derived-root ( vreg derived-roots gc-roots -- ) + vreg lookup-base-pointer :> base + base [ + { vreg base } derived-roots push + base gc-roots adjoin + ] when ; + +: visit-gc-root ( vreg derived-roots gc-roots -- ) + pick rep-of { + { tagged-rep [ nip adjoin ] } + { int-rep [ visit-derived-root ] } + [ 2drop 2drop ] + } case ; + +: gc-roots ( live-set -- derived-roots gc-roots ) + V{ } clone HS{ } clone + [ '[ drop _ _ visit-gc-root ] assoc-each ] 2keep + members ; : fill-gc-map ( live-set insn -- live-set ) - representations get [ - gc-map>> over keys - [ rep-of tagged-rep? ] filter - >>gc-roots - ] when - drop ; + [ representations get [ dup gc-roots ] [ f f ] if ] dip + gc-map>> [ gc-roots<< ] [ derived-roots<< ] bi ; M: gc-map-insn visit-insn [ kill-defs ] [ fill-gc-map ] [ gen-uses ] tri ; @@ -60,9 +119,6 @@ M: insn visit-insn drop ; : transfer-liveness ( live-set instructions -- live-set' ) [ clone ] [ ] bi* [ visit-insn ] each ; -: local-live-in ( instructions -- live-set ) - [ H{ } ] dip transfer-liveness keys ; - SYMBOL: work-list : add-to-work-list ( basic-blocks -- ) @@ -98,11 +154,13 @@ SYMBOL: work-list : compute-live-sets ( cfg -- ) needs-predecessors + dup compute-insns work-list set H{ } clone live-ins set H{ } clone edge-live-ins set H{ } clone live-outs set + H{ } clone base-pointers set post-order add-to-work-list work-list get [ liveness-step ] slurp-deque ; diff --git a/basis/compiler/codegen/fixup/fixup-tests.factor b/basis/compiler/codegen/fixup/fixup-tests.factor index f068861126..70dcdf8988 100644 --- a/basis/compiler/codegen/fixup/fixup-tests.factor +++ b/basis/compiler/codegen/fixup/fixup-tests.factor @@ -9,13 +9,14 @@ STRUCT: gc-info { scrub-d-count uint } { scrub-r-count uint } { gc-root-count uint } +{ derived-root-count uint } { return-address-count uint } ; SINGLETON: fake-cpu fake-cpu \ cpu set -M: fake-cpu gc-root-offsets ; +M: fake-cpu gc-root-offset ; [ ] [ [ @@ -27,7 +28,7 @@ M: fake-cpu gc-root-offsets ; 50 % - T{ gc-map f B{ 0 1 1 1 0 } B{ 1 0 } V{ 1 3 } } gc-map-here + T{ gc-map f B{ 0 1 1 1 0 } B{ 1 0 } V{ 1 3 } V{ { 2 4 } } } gc-map-here emit-gc-info ] B{ } make @@ -54,7 +55,10 @@ M: fake-cpu gc-root-offsets ; f t f t } underlying>> % - ! Return addresses - 4 bytes + ! Derived pointers + uint-array{ -1 -1 4 } underlying>> % + + ! Return addresses uint-array{ 100 } underlying>> % ! GC info footer - 16 bytes @@ -62,6 +66,7 @@ M: fake-cpu gc-root-offsets ; { scrub-d-count 5 } { scrub-r-count 2 } { gc-root-count 4 } + { derived-root-count 3 } { return-address-count 1 } } (underlying)>> % ] B{ } make diff --git a/basis/compiler/codegen/fixup/fixup.factor b/basis/compiler/codegen/fixup/fixup.factor index b4ef317b67..7df85c390d 100644 --- a/basis/compiler/codegen/fixup/fixup.factor +++ b/basis/compiler/codegen/fixup/fixup.factor @@ -2,8 +2,8 @@ ! See http://factorcode.org/license.txt for BSD license. USING: arrays bit-arrays byte-arrays byte-vectors generic assocs hashtables io.binary kernel kernel.private math namespaces make -sequences words quotations strings alien.accessors alien.strings -layouts system combinators math.bitwise math.order +sequences words quotations strings sorting alien.accessors +alien.strings layouts system combinators math.bitwise math.order combinators.short-circuit combinators.smart accessors growable fry memoize compiler.constants compiler.cfg.instructions cpu.architecture ; @@ -144,12 +144,14 @@ MEMO: cached-string>symbol ( symbol -- obj ) string>symbol ; ! - ! - ! - +! uint[] ! uint[] ! uint ! uint ! uint -! uint - +! uint +! int +! SYMBOLS: return-addresses gc-maps ; : gc-map-needed? ( gc-map -- ? ) @@ -160,6 +162,7 @@ SYMBOLS: return-addresses gc-maps ; [ scrub-d>> empty? ] [ scrub-r>> empty? ] [ gc-roots>> empty? ] + [ derived-roots>> empty? ] } 1&& not ] when ; @@ -169,33 +172,64 @@ SYMBOLS: return-addresses gc-maps ; compiled-offset return-addresses get push ] [ drop ] if ; +: longest ( seqs -- n ) + [ length ] [ max ] map-reduce ; + : emit-scrub ( seqs -- n ) ! seqs is a sequence of sequences of 0/1 - dup [ length ] [ max ] map-reduce + dup longest [ '[ [ 0 = ] ?{ } map-as _ f pad-tail % ] each ] keep ; : integers>bits ( seq n -- bit-array ) [ '[ [ t ] dip _ set-nth ] each ] keep ; +: largest-spill-slot ( seqs -- n ) + [ [ 0 ] [ supremum 1 + ] if-empty ] [ max ] map-reduce ; + : emit-gc-roots ( seqs -- n ) ! seqs is a sequence of sequences of integers 0..n-1 - dup [ [ 0 ] [ supremum 1 + ] if-empty ] [ max ] map-reduce + dup largest-spill-slot [ '[ _ integers>bits % ] each ] keep ; : emit-uint ( n -- ) building get push-uint ; +: emit-uints ( n -- ) + [ emit-uint ] each ; + +: gc-root-offsets ( gc-map -- offsets ) + gc-roots>> [ gc-root-offset ] map ; + +: emit-gc-info-bitmaps ( -- scrub-d-count scrub-r-count gc-root-count ) + [ + gc-maps get { + [ [ scrub-d>> ] map emit-scrub ] + [ [ scrub-r>> ] map emit-scrub ] + [ [ gc-root-offsets ] map emit-gc-roots ] + } cleave + ] ?{ } make underlying>> % ; + +: emit-base-table ( alist longest -- ) + -1 swap assoc-union! seq>> emit-uints ; + +: derived-root-offsets ( gc-map -- offsets ) + derived-roots>> [ [ gc-root-offset ] bi@ ] assoc-map ; + +: emit-base-tables ( -- count ) + gc-maps get [ derived-root-offsets ] map + dup [ keys ] map largest-spill-slot + [ '[ _ emit-base-table ] each ] keep ; + +: emit-return-addresses ( -- ) + return-addresses get emit-uints ; + : gc-info ( -- byte-array ) [ return-addresses get empty? [ 0 emit-uint ] [ - gc-maps get - [ - [ [ scrub-d>> ] map emit-scrub ] - [ [ scrub-r>> ] map emit-scrub ] - [ [ gc-roots>> gc-root-offsets ] map emit-gc-roots ] tri - ] ?{ } make underlying>> % - return-addresses get [ emit-uint ] each - [ emit-uint ] tri@ + emit-gc-info-bitmaps + emit-base-tables + emit-return-addresses + 4array emit-uints return-addresses get length emit-uint ] if ] B{ } make ; diff --git a/basis/compiler/tests/alien.factor b/basis/compiler/tests/alien.factor index 65e67e66d2..60e132bb76 100755 --- a/basis/compiler/tests/alien.factor +++ b/basis/compiler/tests/alien.factor @@ -823,25 +823,3 @@ TUPLE: some-tuple x ; aa-indirect-1 >>x ] compile-call ] unit-test - -! Write barrier elimination was being done before scheduling and -! GC check insertion, and didn't take subroutine calls into -! account. Oops... -: write-barrier-elim-in-wrong-place ( -- obj ) - ! A callback used below - void { } cdecl [ compact-gc ] alien-callback - ! Allocate an object A in the nursery - 1 f - ! Subroutine call promotes the object to tenured - swap void { } cdecl alien-indirect - ! Allocate another object B in the nursery, store it into - ! the first - 1 f over set-first - ! Now object A's card should be marked and minor GC should - ! promote B to aging - minor-gc - ! Do stuff - [ 100 [ ] times ] infer. - ; - -[ { { f } } ] [ write-barrier-elim-in-wrong-place ] unit-test diff --git a/basis/compiler/tests/codegen.factor b/basis/compiler/tests/codegen.factor index e9127f71e4..4c4e8de94d 100644 --- a/basis/compiler/tests/codegen.factor +++ b/basis/compiler/tests/codegen.factor @@ -4,7 +4,8 @@ sequences tools.test namespaces.private slots.private sequences.private byte-arrays alien alien.accessors layouts words definitions compiler.units io combinators vectors grouping make alien.c-types combinators.short-circuit math.order -math.libm math.parser math.functions alien.syntax ; +math.libm math.parser math.functions alien.syntax memory +stack-checker ; FROM: math => float ; QUALIFIED: namespaces.private IN: compiler.tests.codegen @@ -463,6 +464,13 @@ TUPLE: myseq { underlying1 byte-array read-only } { underlying2 byte-array read- [ [ HEX: f bitand ] bi@ [ shift ] [ drop -3 shift ] 2bi ] compile-call ] unit-test +! Alias analysis bug +[ t ] [ + [ + 10 10 [ underlying>> ] keep eq? + ] compile-call +] unit-test + ! GC root offsets were computed wrong on x86 : gc-root-messup ( a -- b ) dup [ @@ -473,9 +481,45 @@ TUPLE: myseq { underlying1 byte-array read-only } { underlying2 byte-array read- [ ] [ 2000 [ "hello" clone dup gc-root-messup first eq? t assert= ] times ] unit-test -! Alias analysis bug -[ t ] [ - [ - 10 10 [ underlying>> ] keep eq? - ] compile-call -] unit-test +! Write barrier elimination was being done before scheduling and +! GC check insertion, and didn't take subroutine calls into +! account. Oops... +: write-barrier-elim-in-wrong-place ( -- obj ) + ! A callback used below + void { } cdecl [ compact-gc ] alien-callback + ! Allocate an object A in the nursery + 1 f + ! Subroutine call promotes the object to tenured + swap void { } cdecl alien-indirect + ! Allocate another object B in the nursery, store it into + ! the first + 1 f over set-first + ! Now object A's card should be marked and minor GC should + ! promote B to aging + minor-gc + ! Do stuff + [ 100 [ ] times ] infer. + ; + +[ { { f } } ] [ write-barrier-elim-in-wrong-place ] unit-test + +! GC maps must support derived pointers +: (derived-pointer-test-1) ( -- byte-array ) + 2 ; + +: derived-pointer-test-1 ( -- byte-array ) + ! A callback used below + void { } cdecl [ compact-gc ] alien-callback + ! Put the construction in a word since instruction selection + ! eliminates the untagged pointer entirely if the value is a + ! byte array + (derived-pointer-test-1) { c-ptr } declare + ! Store into an array, an untagged pointer to the payload + ! is now an available expression + 123 over 0 set-alien-unsigned-1 + ! GC, moving the array and derived pointer + swap void { } cdecl alien-indirect + ! Store into the array again + 231 over 1 set-alien-unsigned-1 ; + +[ B{ 123 231 } ] [ derived-pointer-test-1 ] unit-test diff --git a/basis/concurrency/distributed/distributed-tests.factor b/basis/concurrency/distributed/distributed-tests.factor index 3a6693c440..ebe5bc5da2 100644 --- a/basis/concurrency/distributed/distributed-tests.factor +++ b/basis/concurrency/distributed/distributed-tests.factor @@ -1,7 +1,7 @@ USING: tools.test concurrency.distributed kernel io.files io.files.temp io.directories arrays io.sockets system calendar combinators threads math sequences concurrency.messaging -continuations accessors prettyprint io.servers.connection ; +continuations accessors prettyprint io.servers ; FROM: concurrency.messaging => receive send ; IN: concurrency.distributed.tests @@ -36,4 +36,4 @@ test-node-server [ test-node-client "thread-a" send 100 seconds receive-timeout ] unit-test -] with-threaded-server \ No newline at end of file +] with-threaded-server diff --git a/basis/concurrency/distributed/distributed.factor b/basis/concurrency/distributed/distributed.factor index f18f5279ea..153f0c9ad6 100644 --- a/basis/concurrency/distributed/distributed.factor +++ b/basis/concurrency/distributed/distributed.factor @@ -1,7 +1,7 @@ ! Copyright (C) 2005 Chris Double. All Rights Reserved. ! See http://factorcode.org/license.txt for BSD license. USING: serialize sequences concurrency.messaging threads io -io.servers.connection io.encodings.binary assocs init +io.servers io.encodings.binary assocs init arrays namespaces kernel accessors ; FROM: io.sockets => host-name with-client ; IN: concurrency.distributed diff --git a/basis/cpu/architecture/architecture.factor b/basis/cpu/architecture/architecture.factor index 4f6e2677f3..3f2100b787 100644 --- a/basis/cpu/architecture/architecture.factor +++ b/basis/cpu/architecture/architecture.factor @@ -225,7 +225,7 @@ M: object vm-stack-space 0 ; ! %store-memory work HOOK: complex-addressing? cpu ( -- ? ) -HOOK: gc-root-offsets cpu ( seq -- seq' ) +HOOK: gc-root-offset cpu ( spill-slot -- n ) HOOK: %load-immediate cpu ( reg val -- ) HOOK: %load-reference cpu ( reg obj -- ) diff --git a/basis/cpu/x86/x86.factor b/basis/cpu/x86/x86.factor index a13b44197d..6f72e44b9a 100644 --- a/basis/cpu/x86/x86.factor +++ b/basis/cpu/x86/x86.factor @@ -503,8 +503,8 @@ M:: x86 %check-nursery-branch ( label size cc temp1 temp2 -- ) { cc/<= [ label JG ] } } case ; -M: x86 gc-root-offsets - [ n>> spill-offset special-offset cell + cell /i ] map f like ; +M: x86 gc-root-offset + n>> spill-offset special-offset cell + cell /i ; M: x86 %call-gc ( gc-map -- ) \ minor-gc %call diff --git a/basis/ftp/server/server-tests.factor b/basis/ftp/server/server-tests.factor index 2954db0f8b..fa6afa30cc 100644 --- a/basis/ftp/server/server-tests.factor +++ b/basis/ftp/server/server-tests.factor @@ -1,6 +1,6 @@ USING: calendar ftp.server io.encodings.ascii io.files io.files.unique namespaces threads tools.test kernel -io.servers.connection ftp.client accessors urls +io.servers ftp.client accessors urls io.pathnames io.directories sequences fry io.backend continuations ; FROM: ftp.client => ftp-get ; diff --git a/basis/ftp/server/server.factor b/basis/ftp/server/server.factor index e6a47c3ffd..c1508f8ad5 100644 --- a/basis/ftp/server/server.factor +++ b/basis/ftp/server/server.factor @@ -5,7 +5,7 @@ combinators.short-circuit concurrency.promises continuations destructors ftp io io.directories io.encodings io.encodings.8-bit.latin1 io.encodings.binary io.encodings.utf8 io.files io.files.info io.files.types io.pathnames -io.servers.connection io.sockets io.streams.string io.timeouts +io.servers io.sockets io.streams.string io.timeouts kernel logging math math.bitwise math.parser namespaces sequences simple-tokenizer splitting strings threads tools.files unicode.case ; diff --git a/basis/furnace/sessions/sessions-tests.factor b/basis/furnace/sessions/sessions-tests.factor index 49311ee891..1ac3dbd51a 100644 --- a/basis/furnace/sessions/sessions-tests.factor +++ b/basis/furnace/sessions/sessions-tests.factor @@ -1,6 +1,6 @@ USING: tools.test http furnace.sessions furnace.actions http.server http.server.responses math namespaces make kernel -accessors io.sockets io.servers.connection prettyprint +accessors io.sockets io.servers prettyprint io.streams.string io.files io.files.temp io.directories splitting destructors sequences db db.tuples db.sqlite continuations urls math.parser furnace furnace.utilities ; diff --git a/basis/furnace/utilities/utilities.factor b/basis/furnace/utilities/utilities.factor index dc90ad4e8c..94762d7591 100644 --- a/basis/furnace/utilities/utilities.factor +++ b/basis/furnace/utilities/utilities.factor @@ -1,4 +1,4 @@ -! Copyright (C) 2008 Slava Pestov. +! Copyright (C) 2008, 2010 Slava Pestov. ! See http://factorcode.org/license.txt for BSD license. USING: namespaces make assocs sequences kernel classes splitting words vocabs.loader accessors strings combinators arrays @@ -27,10 +27,12 @@ ERROR: no-such-word name vocab ; : each-responder ( quot -- ) nested-responders swap each ; inline -: base-path ( string -- pair ) +ERROR: no-such-responder responder ; + +: base-path ( string -- seq ) dup responder-nesting get [ second class superclasses [ name>> = ] with any? ] with find nip - [ first ] [ "No such responder: " swap append throw ] ?if ; + [ first ] [ no-such-responder ] ?if ; : resolve-base-path ( string -- string' ) "$" ?head [ diff --git a/basis/http/http-tests.factor b/basis/http/http-tests.factor index 7be7c43399..1a74e3fc6d 100644 --- a/basis/http/http-tests.factor +++ b/basis/http/http-tests.factor @@ -205,7 +205,7 @@ Set-Cookie: oo="bar; a=b"; comment="your mom"; httponly=yes ! Live-fire exercise USING: http.server.static furnace.sessions furnace.alloy furnace.actions furnace.auth furnace.auth.login furnace.db -io.servers.connection io.files io.files.temp io.directories io +io.servers io.files io.files.temp io.directories io threads http.server.responses http.server.redirection furnace.redirection http.server.dispatchers db.tuples ; diff --git a/basis/http/server/remapping/remapping.factor b/basis/http/server/remapping/remapping.factor index 36e769731b..6eed900acc 100644 --- a/basis/http/server/remapping/remapping.factor +++ b/basis/http/server/remapping/remapping.factor @@ -1,6 +1,6 @@ ! Copyright (C) 2008 Slava Pestov. ! See http://factorcode.org/license.txt for BSD license. -USING: namespaces assocs kernel io.servers.connection ; +USING: namespaces assocs kernel io.servers ; IN: http.server.remapping SYMBOL: port-remapping diff --git a/basis/http/server/server-docs.factor b/basis/http/server/server-docs.factor index 7e8d230971..5d1b231f60 100644 --- a/basis/http/server/server-docs.factor +++ b/basis/http/server/server-docs.factor @@ -1,5 +1,5 @@ USING: help.markup help.syntax io.streams.string quotations strings urls -http vocabs.refresh math io.servers.connection assocs ; +http vocabs.refresh math io.servers assocs ; IN: http.server HELP: trivial-responder @@ -109,7 +109,7 @@ ARTICLE: "http.server.variables" "HTTP server variables" } ; ARTICLE: "http.server" "HTTP server" -"The " { $vocab-link "http.server" } " vocabulary implements an HTTP and HTTPS server on top of " { $vocab-link "io.servers.connection" } "." +"The " { $vocab-link "http.server" } " vocabulary implements an HTTP and HTTPS server on top of " { $vocab-link "io.servers" } "." { $subsections "http.server.responders" "http.server.requests" diff --git a/basis/http/server/server.factor b/basis/http/server/server.factor index 9e4a8ac4bf..c5bc88f81f 100644 --- a/basis/http/server/server.factor +++ b/basis/http/server/server.factor @@ -15,7 +15,7 @@ io.encodings.binary io.streams.limited io.streams.string io.streams.throwing -io.servers.connection +io.servers io.timeouts io.crlf fry logging logging.insomniac calendar urls urls.encoding diff --git a/basis/io/servers/connection/authors.txt b/basis/io/servers/authors.txt similarity index 100% rename from basis/io/servers/connection/authors.txt rename to basis/io/servers/authors.txt diff --git a/basis/io/servers/connection/connection-docs.factor b/basis/io/servers/servers-docs.factor similarity index 94% rename from basis/io/servers/connection/connection-docs.factor rename to basis/io/servers/servers-docs.factor index 4dd8efdbe3..051dfad975 100644 --- a/basis/io/servers/connection/connection-docs.factor +++ b/basis/io/servers/servers-docs.factor @@ -1,6 +1,6 @@ USING: calendar classes concurrency.semaphores help.markup help.syntax io io.sockets io.sockets.secure math quotations ; -IN: io.servers.connection +IN: io.servers ARTICLE: "server-config" "Threaded server configuration" "The " { $link threaded-server } " tuple has a variety of slots which can be set before starting the server with " { $link start-server } "." @@ -52,8 +52,8 @@ $nl ARTICLE: "server-examples" "Threaded server examples" "The " { $vocab-link "time-server" } " vocabulary implements a simple threaded server which sends the current time to the client. The " { $vocab-link "concurrency.distributed" } ", " { $vocab-link "ftp.server" } ", and " { $vocab-link "http.server" } " vocabularies demonstrate more complex usage of the threaded server library." ; -ARTICLE: "io.servers.connection" "Threaded servers" -"The " { $vocab-link "io.servers.connection" } " vocabulary implements a generic server abstraction for " { $link "network-connection" } ". A set of threads listen for connections, and additional threads are spawned for each client connection. In addition to this basic functionality, it provides some advanced features such as logging, connection limits and secure socket support." +ARTICLE: "io.servers" "Threaded servers" +"The " { $vocab-link "io.servers" } " vocabulary implements a generic server abstraction for " { $link "network-connection" } ". A set of threads listen for connections, and additional threads are spawned for each client connection. In addition to this basic functionality, it provides some advanced features such as logging, connection limits and secure socket support." { $subsections "server-examples" } "Creating threaded servers with client handler quotations:" { $subsections } @@ -82,7 +82,7 @@ ARTICLE: "io.servers.connection" "Threaded servers" "Additionally, the " { $link local-address } " and " { $subsections remote-address } " variables are set, as in " { $link with-client } "." ; -ABOUT: "io.servers.connection" +ABOUT: "io.servers" HELP: threaded-server { $var-description "In client handlers, stores the current threaded server instance." } diff --git a/basis/io/servers/connection/connection-tests.factor b/basis/io/servers/servers-tests.factor similarity index 89% rename from basis/io/servers/connection/connection-tests.factor rename to basis/io/servers/servers-tests.factor index 72f4706957..bcba7f7d90 100644 --- a/basis/io/servers/connection/connection-tests.factor +++ b/basis/io/servers/servers-tests.factor @@ -1,8 +1,8 @@ USING: accessors calendar concurrency.promises fry io -io.encodings.ascii io.servers.connection -io.servers.connection.private io.sockets kernel namespaces +io.encodings.ascii io.servers +io.servers.private io.sockets kernel namespaces sequences threads tools.test ; -IN: io.servers.connection +IN: io.servers [ t ] [ ascii listen-on empty? ] unit-test diff --git a/basis/io/servers/connection/connection.factor b/basis/io/servers/servers.factor similarity index 77% rename from basis/io/servers/connection/connection.factor rename to basis/io/servers/servers.factor index fbe5421cea..66d0112561 100644 --- a/basis/io/servers/connection/connection.factor +++ b/basis/io/servers/servers.factor @@ -8,7 +8,7 @@ io io.sockets io.sockets.secure io.streams.duplex io.styles io.timeouts kernel logging make math math.parser namespaces present prettyprint random sequences sets strings threads ; FROM: namespaces => set ; -IN: io.servers.connection +IN: io.servers TUPLE: threaded-server < identity-tuple name @@ -22,7 +22,8 @@ semaphore timeout encoding handler -server-stopped ; +server-stopped +secure-context ; SYMBOL: running-servers running-servers [ HS{ } clone ] initialize @@ -69,23 +70,20 @@ GENERIC: handle-client* ( threaded-server -- ) insecure) ( obj -- obj ) +GENERIC: >insecure ( obj -- obj ) -M: inet (>insecure) ; -M: inet4 (>insecure) ; -M: inet6 (>insecure) ; -M: local (>insecure) ; -M: integer (>insecure) internet-server ; -M: string (>insecure) internet-server ; -M: array (>insecure) [ (>insecure) ] map ; -M: f (>insecure) ; - -: >insecure ( obj -- seq ) - (>insecure) dup sequence? [ 1array ] unless ; +M: inet >insecure 1array ; +M: inet4 >insecure 1array ; +M: inet6 >insecure 1array ; +M: local >insecure 1array ; +M: integer >insecure internet-server 1array ; +M: string >insecure internet-server 1array ; +M: array >insecure [ >insecure ] map ; +M: f >insecure ; : >secure ( addrspec -- addrspec' ) >insecure - [ dup { [ secure? ] [ not ] } 1|| [ ] unless ] map ; + [ dup secure? [ ] unless ] map ; : listen-on ( threaded-server -- addrspecs ) [ secure>> >secure ] [ insecure>> >insecure ] bi append @@ -131,14 +129,24 @@ M: threaded-server handle-client* handler>> call( -- ) ; [ (accept-connection) ] if* ; +: with-existing-secure-context ( threaded-server quot -- ) + [ secure-context>> secure-context ] dip with-variable ; inline + : accept-loop ( server -- ) [ accept-connection ] [ accept-loop ] bi ; -: start-accept-loop ( server -- ) accept-loop ; +: start-accept-loop ( threaded-server server -- ) + '[ _ accept-loop ] with-existing-secure-context ; \ start-accept-loop NOTICE add-error-logging +: create-secure-context ( threaded-server -- threaded-server ) + dup secure>> [ + dup secure-config>> >>secure-context + ] when ; + : init-server ( threaded-server -- threaded-server ) + create-secure-context >>server-stopped dup semaphore>> [ dup max-connections>> [ @@ -153,48 +161,45 @@ ERROR: no-ports-configured threaded-server ; '[ [ _ |dispose ] map ] with-destructors ; : set-servers ( threaded-server -- threaded-server ) - dup dup listen-on [ no-ports-configured ] [ (make-servers) ] if-empty - >>servers ; + dup [ + dup dup listen-on [ no-ports-configured ] [ (make-servers) ] if-empty + >>servers + ] with-existing-secure-context ; : server-thread-name ( threaded-server addrspec -- string ) [ name>> ] [ addr>> present ] bi* " server on " glue ; -: (start-server) ( threaded-server -- ) - init-server - dup threaded-server [ - [ ] [ name>> ] bi - [ - set-servers - dup add-running-server - dup servers>> - [ - [ nip '[ _ [ start-accept-loop ] with-disposal ] ] - [ server-thread-name ] 2bi spawn drop - ] with each - ] with-logging - ] with-variable ; - PRIVATE> : start-server ( threaded-server -- threaded-server ) - #! Only create a secure-context if we want to listen on - #! a secure port, otherwise start-server won't work at - #! all if SSL is not available. - dup dup secure>> [ - dup secure-config>> [ - (start-server) - ] with-secure-context - ] [ - (start-server) - ] if ; + init-server + [ + dup threaded-server [ + [ ] [ name>> ] bi + [ + set-servers + dup add-running-server + dup servers>> + [ + [ '[ _ _ [ start-accept-loop ] with-disposal ] ] + [ server-thread-name ] 2bi spawn drop + ] with each + ] with-logging + ] with-variable + ] keep ; : server-running? ( threaded-server -- ? ) server-stopped>> [ value>> not ] [ f ] if* ; : stop-server ( threaded-server -- ) dup server-running? [ - [ [ f ] change-servers drop dispose-each ] [ remove-running-server ] + [ + [ + [ secure-context>> [ &dispose drop ] when* ] + [ [ f ] change-servers drop dispose-each ] bi + ] with-destructors + ] [ server-stopped>> raise-flag ] tri ] [ drop diff --git a/basis/io/servers/connection/summary.txt b/basis/io/servers/summary.txt similarity index 100% rename from basis/io/servers/connection/summary.txt rename to basis/io/servers/summary.txt diff --git a/basis/io/servers/connection/tags.txt b/basis/io/servers/tags.txt similarity index 100% rename from basis/io/servers/connection/tags.txt rename to basis/io/servers/tags.txt diff --git a/basis/io/sockets/sockets-docs.factor b/basis/io/sockets/sockets-docs.factor index d0977dd3d0..95ad57a46d 100644 --- a/basis/io/sockets/sockets-docs.factor +++ b/basis/io/sockets/sockets-docs.factor @@ -52,7 +52,7 @@ $nl { { $link inet4 } " - a TCP/IP connection to an IPv4 address and port number; no name lookup is performed" } { { $link inet6 } " - a TCP/IP connection to an IPv6 address and port number; no name lookup is performed" } } -"The " { $vocab-link "io.servers.connection" } " library defines high-level wrappers around " { $link } " which makes it easy to listen for IPv4, IPv6 and secure socket connections simultaneously, perform logging, and optionally only allow connections from the loopback interface." +"The " { $vocab-link "io.servers" } " library defines high-level wrappers around " { $link } " which makes it easy to listen for IPv4, IPv6 and secure socket connections simultaneously, perform logging, and optionally only allow connections from the loopback interface." $nl "The " { $vocab-link "io.sockets.secure" } " vocabulary implements secure, encrypted sockets via SSL and TLS." ; @@ -170,7 +170,7 @@ HELP: { $code "f 1234 resolve-host" } "To start a server which listens for connections from the loopback interface only, use an address specifier returned by the following code, where 1234 is the desired port number:" { $code "\"localhost\" 1234 resolve-host" } - "Since " { $link resolve-host } " can return multiple address specifiers, your server code must listen on them all to work properly. The " { $vocab-link "io.servers.connection" } " vocabulary can be used to help with this." + "Since " { $link resolve-host } " can return multiple address specifiers, your server code must listen on them all to work properly. The " { $vocab-link "io.servers" } " vocabulary can be used to help with this." $nl "To start a TCP/IP server which listens for connections on a randomly-assigned port, set the port number in the address specifier to 0, and then read the " { $snippet "addr" } " slot of the server instance to obtain the actual port number it is listening on:" { $unchecked-example diff --git a/basis/io/streams/limited/limited-docs.factor b/basis/io/streams/limited/limited-docs.factor index 5a06dedf0d..18b4545fde 100644 --- a/basis/io/streams/limited/limited-docs.factor +++ b/basis/io/streams/limited/limited-docs.factor @@ -38,7 +38,7 @@ HELP: limited-input { $description "Wraps the current " { $link input-stream } " in a " { $link limited-stream } "." } ; ARTICLE: "io.streams.limited" "Limited input streams" -"The " { $vocab-link "io.streams.limited" } " vocabulary wraps a stream to behave as if it had only a limited number of bytes, either throwing an error or returning " { $link f } " upon reaching the end. Limiting a non-seekable stream keeps a byte count and triggers the end-of-stream behavior when this byte count has been reached. However, limiting a seekable stream creates a window of bytes that supports seeking and re-reading of bytes in that window." $nl +"The " { $vocab-link "io.streams.limited" } " vocabulary wraps a stream to behave as if it had only a limited number of bytes. Limiting a seekable stream creates a window of bytes that supports seeking and re-reading of bytes in that window. If it is desirable for a stream to throw an exception upon exhaustion, use the " { $vocab-link "io.streams.throwing" } " vocabulary in conjunction with this one." $nl "Wrap a stream in a limited stream:" { $subsections limited-stream } "Wrap the current " { $link input-stream } " in a limited stream:" diff --git a/basis/io/streams/throwing/throwing-docs.factor b/basis/io/streams/throwing/throwing-docs.factor new file mode 100644 index 0000000000..14ceb6c790 --- /dev/null +++ b/basis/io/streams/throwing/throwing-docs.factor @@ -0,0 +1,44 @@ +! Copyright (C) 2010 Doug Coleman. +! See http://factorcode.org/license.txt for BSD license. +USING: help.markup help.syntax io kernel quotations words +math ; +IN: io.streams.throwing + +HELP: stream-exhausted +{ $values + { "n" integer } { "stream" "an input stream" } { "word" word } +} +{ $description "The exception that gets thrown when a stream is exhausted." } ; + +HELP: stream-throw-on-eof +{ $values + { "stream" "an input stream" } { "quot" quotation } +} +{ $description "Wraps a stream in a " { $link } " tuple and calls the quotation with this stream as the " { $link input-stream } " variable. Causes a " { $link stream-exhausted } " exception to be thrown upon stream exhaustion. The stream is left open after this combinator returns." } +"This example will throw a " { $link stream-exhausted } " exception:" +{ $unchecked-example """USING: io.streams.throwing prettyprint ; +"abc" [ 4 read ] stream-throw-on-eof""" +"" +} ; + +HELP: throw-on-eof +{ $values + { "quot" quotation } +} +{ $description "Wraps the value stored in the " { $link input-stream } " variable and causes a stream read that exhausts the input stream to throw a " { $link stream-exhausted } " exception. The stream is left open after this combinator returns." } $nl +"This example will throw a " { $link stream-exhausted } " exception:" +{ $unchecked-example """USING: io.streams.throwing prettyprint ; +"abc" [ [ 4 read ] throw-on-eof ] with-string-reader""" +"" +} ; + +ARTICLE: "io.streams.throwing" "Throwing exceptions on stream exhaustion" +"The " { $vocab-link "io.streams.throwing" } " vocabulary implements combinators for changing the behavior of a stream to throw an exception upon exhaustion instead of returning " { $link f } "." $nl +"A general combinator to wrap any stream:" +{ $subsections stream-throw-on-eof } +"A combinator for the " { $link input-stream } " variable:" +{ $subsections throw-on-eof } +"The exception itself:" +{ $subsections stream-exhausted } ; + +ABOUT: "io.streams.throwing" diff --git a/basis/io/streams/throwing/throwing-tests.factor b/basis/io/streams/throwing/throwing-tests.factor index 1c9e32914b..f1567be842 100644 --- a/basis/io/streams/throwing/throwing-tests.factor +++ b/basis/io/streams/throwing/throwing-tests.factor @@ -15,9 +15,8 @@ IN: io.streams.throwing.tests [ [ - "asdf" &dispose [ - [ 4 swap stream-read ] - [ stream-read1 ] bi + "asdf" [ + 4 read read1 ] stream-throw-on-eof ] with-destructors ] [ stream-exhausted? ] must-fail-with diff --git a/basis/io/streams/throwing/throwing.factor b/basis/io/streams/throwing/throwing.factor index f2cdeab4f7..0b1f214d07 100644 --- a/basis/io/streams/throwing/throwing.factor +++ b/basis/io/streams/throwing/throwing.factor @@ -6,12 +6,12 @@ IN: io.streams.throwing ERROR: stream-exhausted n stream word ; - throws-on-eof-stream +> stream-element-type ; M: throws-on-eof-stream dispose stream>> dispose ; @@ -41,7 +41,7 @@ M: throws-on-eof-stream stream-read-until PRIVATE> : stream-throw-on-eof ( ..a stream quot: ( ..a stream' -- ..b ) -- ..b ) - [ ] dip call ; inline + [ ] dip with-input-stream* ; inline : throw-on-eof ( ..a quot: ( ..a -- ..b ) -- ..b ) [ input-stream get ] dip with-input-stream* ; inline diff --git a/basis/mime/multipart/multipart-tests.factor b/basis/mime/multipart/multipart-tests.factor index 6c3094fe22..bfeb1335ee 100644 --- a/basis/mime/multipart/multipart-tests.factor +++ b/basis/mime/multipart/multipart-tests.factor @@ -2,7 +2,7 @@ ! See http://factorcode.org/license.txt for BSD license. USING: accessors assocs continuations fry http.server io io.encodings.ascii io.files io.files.unique -io.servers.connection io.streams.duplex io.streams.string +io.servers io.streams.duplex io.streams.string kernel math.ranges mime.multipart multiline namespaces random sequences strings threads tools.test ; IN: mime.multipart.tests diff --git a/basis/tools/deploy/deploy-tests.factor b/basis/tools/deploy/deploy-tests.factor index fa446ad44c..e8888717ab 100644 --- a/basis/tools/deploy/deploy-tests.factor +++ b/basis/tools/deploy/deploy-tests.factor @@ -52,7 +52,7 @@ os macosx? [ ] each USING: http.client http.server http.server.dispatchers -http.server.responses http.server.static io.servers.connection ; +http.server.responses http.server.static io.servers ; SINGLETON: quit-responder diff --git a/build-support/factor.cmd b/build-support/factor.cmd index 57a41f24eb..4a3d48654c 100644 --- a/build-support/factor.cmd +++ b/build-support/factor.cmd @@ -46,7 +46,7 @@ nmake /nologo /f Nmakefile %_target% if errorlevel 1 goto fail echo Fetching %_bootimage_version% boot image... -cscript /nologo build-support\http-get.vbs http://factorcode.org/images/%_bootimage_path%/%_bootimage% %_bootimage% +cscript /nologo build-support\http-get.vbs http://downloads.factorcode.org/images/%_bootimage_path%/%_bootimage% %_bootimage% if errorlevel 1 goto fail echo Bootstrapping... diff --git a/build-support/factor.sh b/build-support/factor.sh index 9da4ae295a..08af7a5c39 100755 --- a/build-support/factor.sh +++ b/build-support/factor.sh @@ -447,7 +447,7 @@ update_boot_images() { $DELETE $BOOT_IMAGE.{?,??} > /dev/null 2>&1 $DELETE temp/staging.*.image > /dev/null 2>&1 if [[ -f $BOOT_IMAGE ]] ; then - get_url http://factorcode.org/images/latest/checksums.txt + get_url http://downloads.factorcode.org/images/latest/checksums.txt factorcode_md5=`cat checksums.txt|grep $BOOT_IMAGE|cut -f2 -d' '`; set_md5sum case $OS in @@ -469,7 +469,7 @@ update_boot_images() { get_boot_image() { $ECHO "Downloading boot image $BOOT_IMAGE." - get_url http://factorcode.org/images/latest/$BOOT_IMAGE + get_url http://downloads.factorcode.org/images/latest/$BOOT_IMAGE } get_url() { diff --git a/extra/fuel/remote/remote.factor b/extra/fuel/remote/remote.factor index a8007bd858..e7b797fc19 100644 --- a/extra/fuel/remote/remote.factor +++ b/extra/fuel/remote/remote.factor @@ -1,8 +1,7 @@ ! Copyright (C) 2009, 2010 Jose Antonio Ortega Ruiz. ! See http://factorcode.org/license.txt for BSD license. -USING: accessors debugger io io.encodings.utf8 io.servers.connection +USING: accessors debugger io io.encodings.utf8 io.servers kernel listener math namespaces ; - IN: fuel.remote ( port -- ) diff --git a/extra/webapps/mason/utils/utils.factor b/extra/webapps/mason/utils/utils.factor index 05435893f5..bffc78970a 100644 --- a/extra/webapps/mason/utils/utils.factor +++ b/extra/webapps/mason/utils/utils.factor @@ -44,13 +44,13 @@ IN: webapps.mason.utils "http://downloads.factorcode.org/" prepend ; : package-url ( builder -- url ) - [ URL" $mason-app/package" ] dip + [ URL" http://builds.factorcode.org/package" ] dip [ os>> "os" set-query-param ] [ cpu>> "cpu" set-query-param ] bi adjust-url ; : release-url ( builder -- url ) - [ URL" $mason-app/release" ] dip + [ URL" http://builds.factorcode.org/release" ] dip [ os>> "os" set-query-param ] [ cpu>> "cpu" set-query-param ] bi adjust-url ; diff --git a/extra/webapps/site-watcher/site-watcher.factor b/extra/webapps/site-watcher/site-watcher.factor index 05fabfcf9d..a354544399 100644 --- a/extra/webapps/site-watcher/site-watcher.factor +++ b/extra/webapps/site-watcher/site-watcher.factor @@ -8,7 +8,7 @@ furnace.auth.features.registration furnace.auth.login furnace.boilerplate furnace.redirection html.forms http.server http.server.dispatchers kernel namespaces site-watcher site-watcher.db site-watcher.private urls validators io.sockets.secure.unix.debug -io.servers.connection io.files.temp db db.tuples sequences +io.servers io.files.temp db db.tuples sequences webapps.site-watcher.common webapps.site-watcher.watching webapps.site-watcher.spidering ; QUALIFIED: assocs diff --git a/extra/webapps/todo/todo.factor b/extra/webapps/todo/todo.factor index e5753f3c53..01ed2402f7 100644 --- a/extra/webapps/todo/todo.factor +++ b/extra/webapps/todo/todo.factor @@ -122,7 +122,7 @@ furnace.auth.features.edit-profile furnace.auth.features.deactivate-user db.sqlite furnace.alloy -io.servers.connection +io.servers io.sockets.secure ; : ( responder -- responder' ) diff --git a/extra/websites/concatenative/concatenative.factor b/extra/websites/concatenative/concatenative.factor index 35e4150ba9..379ba32a57 100644 --- a/extra/websites/concatenative/concatenative.factor +++ b/extra/websites/concatenative/concatenative.factor @@ -1,7 +1,7 @@ ! Copyright (c) 2008, 2010 Slava Pestov ! See http://factorcode.org/license.txt for BSD license. USING: accessors kernel sequences assocs io.files io.pathnames -io.sockets io.sockets.secure io.servers.connection +io.sockets io.sockets.secure io.servers namespaces db db.tuples db.sqlite smtp urls logging.insomniac html.templates.chloe @@ -26,7 +26,8 @@ webapps.wiki webapps.user-admin webapps.help webapps.mason -webapps.mason.backend ; +webapps.mason.backend +websites.factorcode ; IN: websites.concatenative : test-db ( -- db ) "resource:test.db" ; @@ -44,11 +45,11 @@ IN: websites.concatenative } ensure-tables ] with-db ; -TUPLE: factor-website < dispatcher ; +TUPLE: concatenative-website < dispatcher ; : ( responder -- responder' ) - { factor-website "page" } >>template ; + { concatenative-website "page" } >>template ; : ( responder -- responder' ) "Factor website" @@ -64,8 +65,8 @@ TUPLE: factor-website < dispatcher ; "6LeJWQgAAAAAAFlYV7SuBClE9uSpGtV_ZS-qVON7" >>public-key "6LeJWQgAAAAAALh-XJgSSQ6xKygRgJ8-029Ip2Xv" >>private-key ; -: ( -- responder ) - factor-website new-dispatcher +: ( -- responder ) + concatenative-website new-dispatcher URL" /wiki/view/Front Page" "" add-responder ; SYMBOL: key-password @@ -84,7 +85,7 @@ SYMBOL: dh-file "vocab:openssl/test/server.pem" key-file set-global "password" key-password set-global common-configuration - + "wiki" add-responder "user-admin" add-responder "pastebin" add-responder @@ -102,7 +103,7 @@ SYMBOL: dh-file : init-production ( -- ) common-configuration - + "wiki" add-responder "user-admin" add-responder test-db "concatenative.org" add-responder @@ -111,6 +112,7 @@ SYMBOL: dh-file test-db "builds.factorcode.org" add-responder home "docs" append-path "docs.factorcode.org" add-responder home "cgi" append-path "gitweb.factorcode.org" add-responder + "new.factorcode.org" add-responder main-responder set-global ; : ( -- config ) @@ -119,7 +121,7 @@ SYMBOL: dh-file dh-file get >>dh-file key-password get >>password ; -: ( -- threaded-server ) +: ( -- threaded-server ) >>secure-config 8080 >>insecure @@ -129,4 +131,4 @@ SYMBOL: dh-file test-db start-expiring test-db start-update-task http-insomniac - start-server ; + start-server ; diff --git a/extra/websites/factorcode/bg_header.jpg b/extra/websites/factorcode/bg_header.jpg new file mode 100644 index 0000000000..10dbd74e8a Binary files /dev/null and b/extra/websites/factorcode/bg_header.jpg differ diff --git a/extra/websites/factorcode/examples.txt b/extra/websites/factorcode/examples.txt new file mode 100644 index 0000000000..420035c5fb --- /dev/null +++ b/extra/websites/factorcode/examples.txt @@ -0,0 +1,57 @@ +USING: io math sequences ; + +"Hello world" print +10 [ "Hello, Factor" print ] times +"Hello, " "Factor" append print +---- +USING: io kernel sequences +http.client xml xml.data xml.traversal ; + +"http://factorcode.org" http-get nip string>xml +"a" deep-tags-named +[ "href" attr ] map +[ print ] each +---- +USING: accessors kernel math math.constants +math.functions prettyprint ; +IN: shapes + +TUPLE: circle radius ; +TUPLE: rectangle width height ; + +GENERIC: area ( shape -- area ) +M: circle area radius>> sq pi * ; +M: rectangle area [ width>> ] [ height>> ] bi * ; + +rectangle new 10 >>width 20 >>height area . +---- +USING: accessors smtp ; + +<email> + "john@foobar.com" >>from + { "jane@foobar.com" } >>to + "Up for lunch?" >>subject + "At Tracy's." >>body +send-email +---- +USING: io.files io.encodings.utf8 kernel +sequences splitting ; + +"table.txt" utf8 [ + file-lines + [ "|" split ] map flip [ "|" join ] map +] 2keep +set-file-lines +---- +USING: sequences xml.syntax xml.writer ; + +{ "three" "blind" "mice" } +[ [XML <li><-></li> XML] ] map +[XML <ul><-></ul> XML] +pprint-xml +---- +USING: inspector io.files.info io.pathnames system tools.files ; + +home directory. +home file-system-info free-space>> . +image file-info describe diff --git a/extra/websites/factorcode/factorcode.factor b/extra/websites/factorcode/factorcode.factor new file mode 100644 index 0000000000..36450509b3 --- /dev/null +++ b/extra/websites/factorcode/factorcode.factor @@ -0,0 +1,17 @@ +! Copyright (c) 2010 Slava Pestov +! See http://factorcode.org/license.txt for BSD license. +USING: accessors http.server http.server.dispatchers +http.server.static kernel namespaces sequences ; +IN: websites.factorcode + +SYMBOL: users + +: ( -- website ) + + "resource:extra/websites/factorcode/" enable-fhtml >>default + users get [ + [ "/home/" "/www/" surround ] keep add-responder + ] each ; + +: init-testing ( -- ) + main-responder set-global ; diff --git a/extra/websites/factorcode/index.fhtml b/extra/websites/factorcode/index.fhtml new file mode 100644 index 0000000000..ab901eaaff --- /dev/null +++ b/extra/websites/factorcode/index.fhtml @@ -0,0 +1,103 @@ +<% USING: namespaces http.client kernel io.files splitting random io io.encodings.utf8 sequences +webapps.mason.version.data webapps.mason.backend webapps.mason.grids webapps.mason.downloads +webapps.mason.utils html.elements accessors +xml.writer ; %> + + + + + + + + Factor programming language + + + + + +
Factor programming language
+ + + + + + + + + +
+ +

Why Factor?

+ +

The Factor programming language combines powerful language features with a full-featured library. The implementation is fully compiled for performance, while still supporting interactive development. Factor applications are portable between all common platforms. Factor can deploy stand-alone applications on all platforms. Full source code for the Factor project is available under a BSD license.

+ + + +

Most of the above links point to pages on the concatenative.org wiki.

+
+ +

Show me some code!

+ +

Factor belongs to the family of concatenative languages: this means that, at the lowest level, a Factor program is a series of words (functions) that manipulate a stack of references to dynamically-typed values. This gives the language a powerful foundation which allows many abstractions and paradigms to be built on top. Reload this page to see a random code example below.

+ +
+<%
+"resource:extra/websites/factorcode/examples.txt" utf8 file-lines
+{ "----" } split random "\n" join write
+%>
+
+ +

See the example programs page on the wiki for more.

+ +
+ +

Downloads

+ +<% [ %> + +

To download a binary, follow the link corresponding to your computer's CPU/OS configuration. Binary packages are the recommended route for new users who wish to try Factor.

+ +

Stable release: +<% latest-version > =href a> ] [ version>> write ] bi %> +

+ + + <% release-grid write-xml %> +
+ +

Source code: +<% latest-version > download-url =href a> ] [ version>> write ] bi %> +

+ +

Development release

+ + + <% package-grid write-xml %> +
+ +<% ] with-mason-db %> + +

Stable and development releases are built and uploaded by the build farm. Follow @FactorBuilds on Twitter to receive notifications. If you're curious, take a look at the build farm dashboard.

+ +

Source code is stored in our GIT repository. Source can can be browsed online via github or gitweb.

+ +

More

+ + + + + diff --git a/extra/websites/factorcode/logo.png b/extra/websites/factorcode/logo.png new file mode 100644 index 0000000000..9907d2c727 Binary files /dev/null and b/extra/websites/factorcode/logo.png differ diff --git a/extra/websites/factorcode/master.css b/extra/websites/factorcode/master.css new file mode 100644 index 0000000000..72088b72ab --- /dev/null +++ b/extra/websites/factorcode/master.css @@ -0,0 +1,144 @@ +body { + font:75%/1.6em "Lucida Grande", "Lucida Sans Unicode", verdana, geneva, sans-serif; +} + +ul { + margin:10px 10px 10px 0; + padding:0 0 0 15px; +} + +li { + margin:0 0 0 10px; + padding:5px; +} + +a { + color:#222; + border-bottom:1px solid #aaa; + text-decoration:none; +} + +a:hover { + border-bottom:1px solid #ccc; +} + +ol.subnav { + margin:-10px -10px 0 -5px; + padding:0; +} + +ol.subnav li { + font:85%/0.9em "Lucida Grande", "Lucida Sans Unicode", verdana, geneva, sans-serif; + float:left; + list-style:none; + margin:0; + padding:0; +} + +ol.subnav a { + font-weight:bold; + color:#555; + border-top:2px solid #fff; + display:block; + padding:5px; + text-decoration:none; + margin:0 5px 0 0; + border-bottom:none; +} + +ol.subnav a:hover { + border-top:2px solid #943329; + color:#121212; + border-bottom:none; +} + +#downloads { + width: 520px; + padding: 0; + margin: 0; +} + +caption { + padding: 0 0 5px 0; + width: 520px; + font: italic 11px "Trebuchet MS", Verdana, Arial, Helvetica, sans-serif; + text-align: right; +} + +th { + font: bold 11px "Trebuchet MS", Verdana, Arial, Helvetica, sans-serif; + color: #4f6b72; + border-right: 1px solid #C1DAD7; + border-bottom: 1px solid #C1DAD7; + border-top: 1px solid #C1DAD7; + letter-spacing: 2px; + text-transform: uppercase; + padding: 6px 6px 6px 6px; + background: #CAE8EA url(bg_header.jpg) no-repeat; +} + +th.nobg { + border-top: 0; + border-left: 0; + border-right: 1px solid #C1DAD7; + background: none; +} + +pre { + border: 1px dashed #ccc; + background-color: #f5f5f5; + font-size: 120%; +} + +td.alt { + background: #F5FAFA; + color: #797268; +} + +td.doesnotexist { + background: #E5EAEA; +} + + +td.unsupported { + background: #ffaaaa; +} + + +td.supported { + background: #aaffaa; +} + +td.supported :hover { background-color: #88ff88; } + +td.nobinary { + background: #eeee88; +} + +div.bigdiv { + width: 100px; + text-align: center; + color: #050; +} + +th.spec { + border-left: 1px solid #C1DAD7; + border-top: 0; + background: #fff; + font: bold 10px "Trebuchet MS", Verdana, Arial, Helvetica, sans-serif; +} + +th.specalt { + border-left: 1px solid #C1DAD7; + border-top: 0; + background: #f5fafa; + font: bold 10px "Trebuchet MS", Verdana, Arial, Helvetica, sans-serif; + color: #797268; +} + +th.allbg { + border-top: 0; + border-left: 0; + border-right: 0; + background: none; +} diff --git a/vm/contexts.cpp b/vm/contexts.cpp index 3d3008c2ab..b31c42f0f4 100644 --- a/vm/contexts.cpp +++ b/vm/contexts.cpp @@ -60,9 +60,9 @@ void context::scrub_stacks(gc_info *info, cell index) u8 *bitmap = info->gc_info_bitmap(); { - cell base = info->scrub_d_base(index); + cell base = info->callsite_scrub_d(index); - for(int loc = 0; loc < info->scrub_d_count; loc++) + for(cell loc = 0; loc < info->scrub_d_count; loc++) { if(bitmap_p(bitmap,base + loc)) { @@ -75,9 +75,9 @@ void context::scrub_stacks(gc_info *info, cell index) } { - cell base = info->scrub_r_base(index); + cell base = info->callsite_scrub_r(index); - for(int loc = 0; loc < info->scrub_r_count; loc++) + for(cell loc = 0; loc < info->scrub_r_count; loc++) { if(bitmap_p(bitmap,base + loc)) { diff --git a/vm/gc_info.cpp b/vm/gc_info.cpp index 9a3252aa2c..7c727aac0d 100644 --- a/vm/gc_info.cpp +++ b/vm/gc_info.cpp @@ -3,17 +3,17 @@ namespace factor { -int gc_info::return_address_index(cell return_address) +cell gc_info::return_address_index(cell return_address) { u32 *return_address_array = return_addresses(); - for(int i = 0; i < return_address_count; i++) + for(cell i = 0; i < return_address_count; i++) { if(return_address == return_address_array[i]) return i; } - return -1; + return gc_info_missing_value; } } diff --git a/vm/gc_info.hpp b/vm/gc_info.hpp index dbbe11b9d7..eee7b1a8e8 100644 --- a/vm/gc_info.hpp +++ b/vm/gc_info.hpp @@ -1,15 +1,23 @@ namespace factor { +const u32 gc_info_missing_value = (u32)-1; + struct gc_info { - int scrub_d_count; - int scrub_r_count; - int gc_root_count; - int return_address_count; + u32 scrub_d_count; + u32 scrub_r_count; + u32 gc_root_count; + u32 derived_root_count; + u32 return_address_count; + + cell callsite_bitmap_size() + { + return scrub_d_count + scrub_r_count + gc_root_count; + } cell total_bitmap_size() { - return return_address_count * (scrub_d_count + scrub_r_count + gc_root_count); + return return_address_count * callsite_bitmap_size(); } cell total_bitmap_bytes() @@ -19,33 +27,43 @@ struct gc_info { u32 *return_addresses() { - return (u32 *)((u8 *)this - return_address_count * sizeof(u32)); + return (u32 *)this - return_address_count; + } + + u32 *base_pointer_map() + { + return return_addresses() - return_address_count * derived_root_count; } u8 *gc_info_bitmap() { - return (u8 *)return_addresses() - total_bitmap_bytes(); + return (u8 *)base_pointer_map() - total_bitmap_bytes(); } - cell scrub_d_base(cell index) + cell callsite_scrub_d(cell index) { return index * scrub_d_count; } - cell scrub_r_base(cell index) + cell callsite_scrub_r(cell index) { return return_address_count * scrub_d_count + index * scrub_r_count; } - cell spill_slot_base(cell index) + cell callsite_gc_roots(cell index) { return return_address_count * scrub_d_count + return_address_count * scrub_r_count + index * gc_root_count; } - int return_address_index(cell return_address); + cell lookup_base_pointer(cell index, cell derived_root) + { + return base_pointer_map()[index * derived_root_count + derived_root]; + } + + cell return_address_index(cell return_address); }; } diff --git a/vm/slot_visitor.hpp b/vm/slot_visitor.hpp index d4479ee102..303fc37544 100755 --- a/vm/slot_visitor.hpp +++ b/vm/slot_visitor.hpp @@ -292,27 +292,52 @@ struct call_frame_slot_visitor { gc_info *info = compiled->block_gc_info(); assert(return_address < compiled->size()); - int index = info->return_address_index(return_address); - if(index == -1) + u32 callsite = info->return_address_index(return_address); + if(callsite == gc_info_missing_value) return; #ifdef DEBUG_GC_MAPS std::cout << "call frame code block " << compiled << " with offset " << return_address << std::endl; #endif - u8 *bitmap = info->gc_info_bitmap(); - cell base = info->spill_slot_base(index); cell *stack_pointer = (cell *)(parent->frame_successor(frame) + 1); + u8 *bitmap = info->gc_info_bitmap(); - for(int spill_slot = 0; spill_slot < info->gc_root_count; spill_slot++) + /* Subtract old value of base pointer from every derived pointer. */ + for(cell spill_slot = 0; spill_slot < info->derived_root_count; spill_slot++) { - if(bitmap_p(bitmap,base + spill_slot)) + cell base_pointer = info->lookup_base_pointer(callsite, spill_slot); + if(base_pointer != gc_info_missing_value) { #ifdef DEBUG_GC_MAPS - std::cout << "visiting spill slot " << spill_slot << std::endl; + std::cout << "visiting derived root " << spill_slot + << " with base pointer " << base_pointer + << std::endl; +#endif + stack_pointer[spill_slot] -= stack_pointer[base_pointer]; + } + } + + /* Update all GC roots, including base pointers. */ + cell callsite_gc_roots = info->callsite_gc_roots(callsite); + + for(cell spill_slot = 0; spill_slot < info->gc_root_count; spill_slot++) + { + if(bitmap_p(bitmap,callsite_gc_roots + spill_slot)) + { +#ifdef DEBUG_GC_MAPS + std::cout << "visiting GC root " << spill_slot << std::endl; #endif visitor->visit_handle(stack_pointer + spill_slot); } } + + /* Add the base pointers to obtain new derived pointer values. */ + for(cell spill_slot = 0; spill_slot < info->derived_root_count; spill_slot++) + { + cell base_pointer = info->lookup_base_pointer(callsite, spill_slot); + if(base_pointer != gc_info_missing_value) + stack_pointer[spill_slot] += stack_pointer[base_pointer]; + } } }; diff --git a/vm/vm.hpp b/vm/vm.hpp index d9c7186c4e..f940bd5937 100755 --- a/vm/vm.hpp +++ b/vm/vm.hpp @@ -329,14 +329,16 @@ struct factor_vm return (Type *)allot_object(Type::type_number,size); } + inline bool in_data_heap_p(cell pointer) + { + return (pointer >= data->seg->start && pointer < data->seg->end); + } + inline void check_data_pointer(object *pointer) { #ifdef FACTOR_DEBUG if(!(current_gc && current_gc->op == collect_growing_heap_op)) - { - assert((cell)pointer >= data->seg->start - && (cell)pointer < data->seg->end); - } + assert(in_data_heap_p((cell)pointer)); #endif }