]> gitweb.factorcode.org Git - factor.git/commitdiff
Merge branch 'master' of git://github.com/slavapestov/factor
authorAnton Gorenko <ex.rzrjck@gmail.com>
Sun, 16 Jan 2011 07:38:04 +0000 (13:38 +0600)
committerAnton Gorenko <ex.rzrjck@gmail.com>
Sun, 16 Jan 2011 07:38:04 +0000 (13:38 +0600)
263 files changed:
GNUmakefile
basis/alien/c-types/c-types-docs.factor
basis/alien/c-types/c-types-tests.factor
basis/alien/c-types/c-types.factor
basis/alien/data/data-docs.factor
basis/alien/data/data-tests.factor
basis/alien/data/data.factor
basis/alien/enums/enums-docs.factor
basis/alien/enums/enums.factor
basis/alien/fortran/fortran-tests.factor
basis/alien/fortran/fortran.factor
basis/alien/libraries/libraries-tests.factor [changed mode: 0644->0755]
basis/alien/libraries/libraries.factor
basis/alien/syntax/syntax-docs.factor
basis/biassocs/biassocs-docs.factor
basis/bit-sets/bit-sets-tests.factor
basis/bit-sets/bit-sets.factor
basis/cache/cache-tests.factor [new file with mode: 0755]
basis/cache/cache.factor [changed mode: 0644->0755]
basis/calendar/calendar-docs.factor
basis/calendar/unix/unix.factor
basis/checksums/md5/md5.factor
basis/colors/hex/authors.txt [new file with mode: 0644]
basis/colors/hex/hex-docs.factor [new file with mode: 0644]
basis/colors/hex/hex-tests.factor [new file with mode: 0644]
basis/colors/hex/hex.factor [new file with mode: 0644]
basis/colors/hex/summary.txt [new file with mode: 0644]
basis/compiler/tests/codegen.factor
basis/compiler/tests/intrinsics.factor
basis/compiler/tree/cleanup/cleanup-tests.factor
basis/compression/zlib/zlib.factor
basis/concurrency/combinators/combinators-docs.factor
basis/concurrency/count-downs/count-downs.factor [changed mode: 0644->0755]
basis/concurrency/distributed/distributed-tests.factor
basis/concurrency/locks/locks-docs.factor
basis/concurrency/mailboxes/debugger/authors.txt [new file with mode: 0755]
basis/concurrency/mailboxes/debugger/debugger.factor [new file with mode: 0755]
basis/concurrency/mailboxes/mailboxes.factor [changed mode: 0644->0755]
basis/concurrency/messaging/messaging-docs.factor
basis/core-foundation/numbers/numbers.factor
basis/core-graphics/core-graphics.factor
basis/cpu/x86/sse/sse.factor
basis/cpu/x86/x87/x87.factor
basis/db/db-docs.factor
basis/db/tuples/tuples-docs.factor
basis/debugger/debugger-docs.factor
basis/endian/endian.factor
basis/environment/unix/unix.factor
basis/eval/eval-docs.factor
basis/ftp/client/client.factor
basis/ftp/server/server-tests.factor
basis/furnace/actions/actions-docs.factor
basis/furnace/auth/auth.factor
basis/furnace/recaptcha/recaptcha.factor
basis/furnace/redirection/redirection.factor
basis/game/input/dinput/dinput.factor
basis/grouping/grouping-docs.factor
basis/help/handbook/handbook.factor
basis/help/help-docs.factor
basis/help/tutorial/tutorial.factor
basis/hints/hints-docs.factor
basis/hints/hints.factor
basis/html/templates/chloe/chloe-docs.factor
basis/http/client/client-docs.factor
basis/http/http-tests.factor
basis/http/server/remapping/remapping.factor
basis/images/jpeg/jpeg.factor
basis/io/backend/unix/multiplexers/select/select.factor
basis/io/backend/unix/unix.factor
basis/io/directories/directories-docs.factor
basis/io/directories/search/search-docs.factor
basis/io/directories/unix/linux/linux.factor
basis/io/directories/unix/unix.factor
basis/io/files/info/unix/macosx/macosx.factor
basis/io/files/info/unix/unix-docs.factor
basis/io/files/windows/windows.factor [changed mode: 0644->0755]
basis/io/launcher/launcher-docs.factor
basis/io/launcher/windows/windows.factor
basis/io/mmap/mmap-docs.factor
basis/io/monitors/windows/windows.factor
basis/io/servers/servers-docs.factor
basis/io/servers/servers-tests.factor
basis/io/servers/servers.factor [changed mode: 0644->0755]
basis/io/sockets/secure/secure.factor
basis/io/sockets/secure/unix/unix.factor
basis/io/sockets/sockets-docs.factor
basis/io/sockets/sockets-tests.factor
basis/io/sockets/sockets.factor
basis/io/sockets/unix/unix.factor
basis/io/sockets/windows/windows.factor
basis/io/styles/styles-docs.factor
basis/iokit/iokit.factor
basis/literals/literals-docs.factor
basis/logging/analysis/analysis.factor
basis/logging/insomniac/insomniac-docs.factor
basis/logging/insomniac/insomniac.factor
basis/logging/logging-tests.factor
basis/logging/parser/parser.factor
basis/math/floats/half/half.factor
basis/math/primes/erato/erato-docs.factor
basis/math/primes/erato/erato-tests.factor
basis/math/primes/erato/erato.factor
basis/models/arrow/arrow.factor
basis/multiline/multiline-docs.factor
basis/opengl/opengl.factor
basis/opengl/shaders/shaders.factor
basis/random/random.factor
basis/random/sfmt/sfmt.factor
basis/sequences/product/product.factor
basis/specialized-arrays/specialized-arrays-docs.factor
basis/specialized-arrays/specialized-arrays-tests.factor
basis/stack-checker/known-words/known-words.factor
basis/system-info/macosx/macosx.factor
basis/system-info/windows/windows.factor
basis/timers/timers-docs.factor
basis/tools/crossref/crossref-docs.factor
basis/tools/deploy/config/config-docs.factor
basis/tools/deploy/deploy-tests.factor
basis/tools/dns/authors.txt [new file with mode: 0644]
basis/tools/dns/dns.factor [new file with mode: 0644]
basis/ui/backend/cocoa/cocoa.factor
basis/ui/backend/cocoa/views/views.factor
basis/ui/backend/windows/windows.factor
basis/ui/pixel-formats/pixel-formats-docs.factor
basis/ui/ui-docs.factor
basis/unix/ffi/bsd/bsd.factor
basis/unix/ffi/bsd/freebsd/freebsd.factor
basis/unix/ffi/bsd/macosx/macosx.factor
basis/unix/ffi/bsd/openbsd/openbsd.factor
basis/unix/groups/groups.factor
basis/unix/types/freebsd/freebsd.factor
basis/unix/types/linux/linux.factor
basis/unix/types/macosx/macosx.factor
basis/unix/types/netbsd/netbsd.factor
basis/unix/types/openbsd/openbsd.factor
basis/unix/users/users-docs.factor
basis/unix/utilities/utilities.factor
basis/urls/encoding/encoding-docs.factor
basis/urls/urls-docs.factor
basis/urls/urls.factor
basis/windows/com/com-tests.factor
basis/windows/com/syntax/syntax.factor [changed mode: 0644->0755]
basis/windows/iphlpapi/iphlpapi.factor
basis/windows/registry/registry.factor
basis/windows/uniscribe/uniscribe.factor
basis/x11/clipboard/clipboard.factor
basis/x11/windows/windows.factor
basis/x11/xim/xim.factor
basis/x11/xinput2/xinput2.factor
basis/x11/xlib/xlib.factor
core/assocs/assocs-docs.factor
core/assocs/assocs.factor
core/bootstrap/primitives.factor
core/classes/algebra/algebra-docs.factor
core/classes/tuple/tuple-docs.factor
core/combinators/combinators-docs.factor
core/continuations/continuations-docs.factor
core/effects/effects-docs.factor
core/generic/generic-docs.factor
core/hash-sets/hash-sets.factor
core/hashtables/hashtables.factor
core/io/binary/binary-docs.factor
core/io/encodings/utf16n/utf16n-tests.factor
core/io/io-docs.factor
core/io/pathnames/pathnames-docs.factor
core/kernel/kernel-docs.factor
core/math/floats/floats-tests.factor
core/math/floats/floats.factor
core/math/integers/integers-tests.factor
core/math/integers/integers.factor
core/math/math-docs.factor
core/math/math.factor
core/parser/parser-docs.factor
core/sbufs/sbufs-docs.factor
core/sequences/sequences-docs.factor
core/sets/sets-docs.factor
core/sets/sets-tests.factor
core/sets/sets.factor
core/source-files/source-files-docs.factor
core/splitting/splitting.factor
core/syntax/syntax-docs.factor
core/vocabs/parser/parser-docs.factor
core/vocabs/vocabs-docs.factor
extra/alien/cxx/demangle/libstdcxx/libstdcxx.factor
extra/audio/engine/engine.factor
extra/audio/vorbis/vorbis.factor
extra/benchmark/ui-panes/deploy.factor [new file with mode: 0644]
extra/benchmark/ui-panes/ui-panes.factor
extra/bunny/model/model.factor
extra/central/authors.txt [deleted file]
extra/central/central-docs.factor [deleted file]
extra/central/central-tests.factor [deleted file]
extra/central/central.factor [deleted file]
extra/central/tags.txt [deleted file]
extra/cuda/contexts/contexts.factor
extra/cuda/cuda.factor
extra/cuda/devices/devices.factor
extra/cuda/gl/gl.factor
extra/cuda/libraries/libraries.factor
extra/cuda/memory/memory.factor
extra/dns/dns.factor
extra/dns/unix/authors.txt [new file with mode: 0644]
extra/dns/unix/platforms.txt [new file with mode: 0644]
extra/dns/unix/unix.factor [new file with mode: 0644]
extra/dns/windows/authors.txt [new file with mode: 0644]
extra/dns/windows/platforms.txt [new file with mode: 0644]
extra/dns/windows/windows.factor [new file with mode: 0644]
extra/ecdsa/ecdsa.factor
extra/game/loop/loop.factor [changed mode: 0644->0755]
extra/gpu/buffers/buffers.factor
extra/gpu/demos/bunny/bunny.factor
extra/gpu/framebuffers/framebuffers.factor
extra/gpu/shaders/shaders.factor
extra/gpu/state/state.factor
extra/html/parser/analyzer/analyzer.factor
extra/images/gif/gif.factor
extra/javascriptcore/javascriptcore.factor
extra/llvm/jit/jit.factor
extra/llvm/reader/reader.factor
extra/llvm/wrappers/wrappers.factor
extra/math/finance/finance-tests.factor
extra/math/finance/finance.factor
extra/morse/morse.factor
extra/openal/alut/macosx/macosx.factor
extra/openal/alut/other/other.factor
extra/openal/openal.factor
extra/opencl/ffi/ffi-tests.factor
extra/opencl/opencl-tests.factor
extra/opencl/opencl.factor
extra/path-finding/path-finding-docs.factor
extra/path-finding/path-finding-tests.factor
extra/path-finding/path-finding.factor
extra/project-euler/006/006.factor
extra/resolv-conf/authors.txt [new file with mode: 0644]
extra/resolv-conf/resolv-conf.factor [new file with mode: 0644]
extra/resolv-conf/resolv-conf.test [new file with mode: 0644]
extra/tokyo/assoc-functor/assoc-functor.factor
extra/trees/avl/avl.factor
extra/trees/trees.factor
extra/twitter/twitter.factor
extra/webapps/mason/backend/backend.factor
extra/webapps/mason/docs-update/docs-update.factor
extra/webapps/mason/download-package.xml
extra/webapps/mason/download-release.xml
extra/webapps/mason/package/package.factor
extra/webapps/planet/icons/feed-icon-14x14.png [new file with mode: 0644]
extra/webapps/planet/planet.factor
extra/webapps/planet/planet.xml
extra/websites/concatenative/concatenative.factor
extra/websites/factorcode/factor-macosx.png [new file with mode: 0644]
extra/websites/factorcode/factor-windows7.png [new file with mode: 0644]
extra/websites/factorcode/factorcode.factor
extra/websites/factorcode/license.txt [new file with mode: 0644]
vm/Config.windows [changed mode: 0644->0755]
vm/bignum.cpp
vm/gc.cpp
vm/gc_info.cpp
vm/gc_info.hpp
vm/math.cpp
vm/math.hpp
vm/primitives.hpp
vm/slot_visitor.hpp
vm/vm.hpp

index 38e3b0d7365e6ba68f3c955611bf3f001753c3f9..43fba15c0b78b6296853e9567574a82ccfecd976 100755 (executable)
@@ -154,12 +154,12 @@ solaris-x86-64:
        $(MAKE) $(ALL) CONFIG=vm/Config.solaris.x86.64
 
 winnt-x86-32:
-       $(MAKE) $(ALL) CONFIG=vm/Config.windows.nt.x86.32
-       $(MAKE) factor-console CONFIG=vm/Config.windows.nt.x86.32
+       $(MAKE) $(ALL) CONFIG=vm/Config.windows.x86.32
+       $(MAKE) factor-console CONFIG=vm/Config.windows.x86.32
 
 winnt-x86-64:
-       $(MAKE) $(ALL) CONFIG=vm/Config.windows.nt.x86.64
-       $(MAKE) factor-console CONFIG=vm/Config.windows.nt.x86.64
+       $(MAKE) $(ALL) CONFIG=vm/Config.windows.x86.64
+       $(MAKE) factor-console CONFIG=vm/Config.windows.x86.64
 
 ifdef CONFIG
 
index 32c1d18d51d0154eec25e0bd7faa69b3b1f536da..e14a5cb5e10ca7bbc9c2b28abff040ec029e905a 100644 (file)
@@ -38,16 +38,6 @@ HELP: set-alien-value
 { $description "Stores a value at a byte offset from a base C pointer." }
 { $errors "Throws a " { $link no-c-type } " error if the type does not exist." } ;
 
-HELP: define-deref
-{ $values { "c-type" "a C type" } }
-{ $description "Defines a word " { $snippet "*name" } " with stack effect " { $snippet "( c-ptr -- value )" } " for reading a value with C type " { $snippet "name" } " stored at an alien pointer." }
-{ $notes "This is an internal word called when defining C types, there is no need to call it on your own." } ;
-
-HELP: define-out
-{ $values { "c-type" "a C type" } }
-{ $description "Defines a word " { $snippet "<" { $emphasis "name" } ">" } " with stack effect " { $snippet "( value -- array )" } ". This word allocates a byte array large enough to hold a value with C type " { $snippet "name" } ", and writes the value at the top of the stack to the array." }
-{ $notes "This is an internal word called when defining C types, there is no need to call it on your own." } ;
-
 HELP: char
 { $description "This C type represents a one-byte signed integer type. Input values will be converted to " { $link math:integer } "s and truncated to eight bits; output values will be returned as " { $link math:fixnum } "s." } ;
 HELP: uchar
@@ -118,43 +108,6 @@ $nl
 "If this condition is not satisfied, " { $link "malloc" } " must be used instead."
 { $warning "Failure to comply with these requirements can lead to crashes, data corruption, and security exploits." } ;
 
-ARTICLE: "c-out-params" "Output parameters in C"
-"A frequently-occurring idiom in C code is the \"out parameter\". If a C function returns more than one value, the caller passes pointers of the correct type, and the C function writes its return values to those locations."
-$nl
-"Each numerical C type, together with " { $snippet "void*" } ", has an associated " { $emphasis "out parameter constructor" } " word which takes a Factor object as input, constructs a byte array of the correct size, and converts the Factor object to a C value stored into the byte array:"
-{ $subsections
-    <char>
-    <uchar>
-    <short>
-    <ushort>
-    <int>
-    <uint>
-    <long>
-    <ulong>
-    <longlong>
-    <ulonglong>
-    <float>
-    <double>
-    <void*>
-}
-"You call the out parameter constructor with the required initial value, then pass the byte array to the C function, which receives a pointer to the start of the byte array's data area. The C function then returns, leaving the result in the byte array; you read it back using the next set of words:"
-{ $subsections
-    *char
-    *uchar
-    *short
-    *ushort
-    *int
-    *uint
-    *long
-    *ulong
-    *longlong
-    *ulonglong
-    *float
-    *double
-    *void*
-}
-"Note that while structure and union types do not get these words defined for them, there is no loss of generality since " { $link <void*> } " and " { $link *void* } " may be used." ;
-
 ARTICLE: "c-types.primitives" "Primitive C types"
 "The following numerical types are defined in the " { $vocab-link "alien.c-types" } " vocabulary; a " { $snippet "u" } " prefix denotes an unsigned type:"
 { $table
index 5e4635e0188ada318d34c6dc87f98f65758f1151..661478e4bd0eb17437e0d0a01d9308bb75bef26e 100644 (file)
@@ -2,16 +2,13 @@ USING: alien alien.syntax alien.c-types alien.parser
 eval kernel tools.test sequences system libc alien.strings
 io.encodings.ascii io.encodings.utf8 math.constants classes.struct classes
 accessors compiler.units ;
+FROM: alien.c-types => short ;
 IN: alien.c-types.tests
 
 CONSTANT: xyz 123
 
 [ 492 ] [ { int xyz } heap-size ] unit-test
 
-[ -1 ] [ -1 <char> *char ] unit-test
-[ -1 ] [ -1 <short> *short ] unit-test
-[ -1 ] [ -1 <int> *int ] unit-test
-
 UNION-STRUCT: foo
     { a int }
     { b int } ;
@@ -52,14 +49,6 @@ TYPEDEF: int* MyIntArray
 
 [ t ] [ void* c-type MyIntArray c-type = ] unit-test
 
-[
-    0 B{ 1 2 3 4 } <displaced-alien> <void*>
-] must-fail
-
-os windows? cpu x86.64? and [
-    [ -2147467259 ] [ 2147500037 <long> *long ] unit-test
-] when
-
 [ 0 ] [ -10 uchar c-type-clamp ] unit-test
 [ 12 ] [ 12 uchar c-type-clamp ] unit-test
 [ -10 ] [ -10 char c-type-clamp ] unit-test
index 04755ea033062b95ddad3593685628a916e8d73f..19103ce3a8b55128b690b68f068b92919b49e587 100644 (file)
@@ -1,12 +1,9 @@
 ! Copyright (C) 2004, 2010 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: byte-arrays arrays assocs delegate kernel kernel.private math
-math.order math.parser namespaces make parser sequences strings
-words splitting cpu.architecture alien alien.accessors
-alien.strings quotations layouts system compiler.units io
-io.files io.encodings.binary io.streams.memory accessors
-combinators effects continuations fry classes vocabs
-vocabs.loader words.symbol macros ;
+USING: accessors alien alien.accessors arrays byte-arrays
+classes combinators compiler.units cpu.architecture delegate
+fry kernel layouts locals macros math math.order quotations
+sequences system words words.symbol ;
 QUALIFIED: math
 IN: alien.c-types
 
@@ -21,9 +18,6 @@ SYMBOLS:
 
 SINGLETON: void
 
-DEFER: <int>
-DEFER: *char
-
 TUPLE: abstract-c-type
 { class class initial: object }
 { boxed-class class initial: object }
@@ -111,8 +105,6 @@ M: c-type-name base-type c-type ;
 
 M: c-type base-type ;
 
-: little-endian? ( -- ? ) 1 <int> *char 1 = ; foldable
-
 GENERIC: heap-size ( name -- size )
 
 M: abstract-c-type heap-size size>> ;
@@ -170,19 +162,6 @@ TUPLE: long-long-type < c-type ;
 : <long-long-type> ( -- c-type )
     long-long-type new ;
 
-: define-deref ( c-type -- )
-    [ name>> CHAR: * prefix "alien.c-types" create ]
-    [ '[ 0 _ alien-value ] ]
-    bi (( c-ptr -- value )) define-inline ;
-
-: define-out ( c-type -- )
-    [ name>> "alien.c-types" constructor-word ]
-    [ dup '[ _ heap-size (byte-array) [ 0 _ set-alien-value ] keep ] ] bi
-    (( value -- c-ptr )) define-inline ;
-
-: define-primitive-type ( c-type name -- )
-    [ typedef ] [ define-deref ] [ define-out ] tri ;
-
 : if-void ( c-type true false -- )
     pick void? [ drop nip call ] [ nip call ] if ; inline
 
@@ -247,7 +226,7 @@ M: pointer c-type
         [ >c-ptr ] >>unboxer-quot
         "allot_alien" >>boxer
         "alien_offset" >>unboxer
-    \ void* define-primitive-type
+    \ void* typedef
 
     <c-type>
         fixnum >>class
@@ -260,7 +239,7 @@ M: pointer c-type
         "from_signed_2" >>boxer
         "to_signed_2" >>unboxer
         [ >fixnum ] >>unboxer-quot
-    \ short define-primitive-type
+    \ short typedef
 
     <c-type>
         fixnum >>class
@@ -273,7 +252,7 @@ M: pointer c-type
         "from_unsigned_2" >>boxer
         "to_unsigned_2" >>unboxer
         [ >fixnum ] >>unboxer-quot
-    \ ushort define-primitive-type
+    \ ushort typedef
 
     <c-type>
         fixnum >>class
@@ -286,7 +265,7 @@ M: pointer c-type
         "from_signed_1" >>boxer
         "to_signed_1" >>unboxer
         [ >fixnum ] >>unboxer-quot
-    \ char define-primitive-type
+    \ char typedef
 
     <c-type>
         fixnum >>class
@@ -299,7 +278,7 @@ M: pointer c-type
         "from_unsigned_1" >>boxer
         "to_unsigned_1" >>unboxer
         [ >fixnum ] >>unboxer-quot
-    \ uchar define-primitive-type
+    \ uchar typedef
 
     <c-type>
         math:float >>class
@@ -313,7 +292,7 @@ M: pointer c-type
         "to_float" >>unboxer
         float-rep >>rep
         [ >float ] >>unboxer-quot
-    \ float define-primitive-type
+    \ float typedef
 
     <c-type>
         math:float >>class
@@ -326,7 +305,7 @@ M: pointer c-type
         "to_double" >>unboxer
         double-rep >>rep
         [ >float ] >>unboxer-quot
-    \ double define-primitive-type
+    \ double typedef
 
     cell 8 = [
         <c-type>
@@ -340,7 +319,7 @@ M: pointer c-type
             "from_signed_4" >>boxer
             "to_signed_4" >>unboxer
             [ >fixnum ] >>unboxer-quot
-        \ int define-primitive-type
+        \ int typedef
     
         <c-type>
             fixnum >>class
@@ -353,7 +332,7 @@ M: pointer c-type
             "from_unsigned_4" >>boxer
             "to_unsigned_4" >>unboxer
             [ >fixnum ] >>unboxer-quot
-        \ uint define-primitive-type
+        \ uint typedef
 
         <c-type>
             integer >>class
@@ -365,7 +344,8 @@ M: pointer c-type
             8 >>align-first
             "from_signed_cell" >>boxer
             "to_fixnum" >>unboxer
-        \ longlong define-primitive-type
+            [ >integer ] >>unboxer-quot
+        \ longlong typedef
 
         <c-type>
             integer >>class
@@ -377,14 +357,15 @@ M: pointer c-type
             8 >>align-first
             "from_unsigned_cell" >>boxer
             "to_cell" >>unboxer
-        \ ulonglong define-primitive-type
+            [ >integer ] >>unboxer-quot
+        \ ulonglong typedef
 
         os windows? [
-            \ int c-type \ long define-primitive-type
-            \ uint c-type \ ulong define-primitive-type
+            \ int c-type \ long typedef
+            \ uint c-type \ ulong typedef
         ] [
-            \ longlong c-type \ long define-primitive-type
-            \ ulonglong c-type \ ulong define-primitive-type
+            \ longlong c-type \ long typedef
+            \ ulonglong c-type \ ulong typedef
         ] if
 
         \ longlong c-type \ ptrdiff_t typedef
@@ -403,7 +384,8 @@ M: pointer c-type
             4 >>align-first
             "from_signed_cell" >>boxer
             "to_fixnum" >>unboxer
-        \ int define-primitive-type
+            [ >integer ] >>unboxer-quot
+        \ int typedef
     
         <c-type>
             integer >>class
@@ -415,7 +397,8 @@ M: pointer c-type
             4 >>align-first
             "from_unsigned_cell" >>boxer
             "to_cell" >>unboxer
-        \ uint define-primitive-type
+            [ >integer ] >>unboxer-quot
+        \ uint typedef
 
         <long-long-type>
             integer >>class
@@ -426,7 +409,8 @@ M: pointer c-type
             8-byte-alignment
             "from_signed_8" >>boxer
             "to_signed_8" >>unboxer
-        \ longlong define-primitive-type
+            [ >integer ] >>unboxer-quot
+        \ longlong typedef
 
         <long-long-type>
             integer >>class
@@ -437,10 +421,11 @@ M: pointer c-type
             8-byte-alignment
             "from_unsigned_8" >>boxer
             "to_unsigned_8" >>unboxer
-        \ ulonglong define-primitive-type
+            [ >integer ] >>unboxer-quot
+        \ ulonglong typedef
 
-        \ int c-type \ long define-primitive-type
-        \ uint c-type \ ulong define-primitive-type
+        \ int c-type \ long typedef
+        \ uint c-type \ ulong typedef
 
         \ int c-type \ ptrdiff_t typedef
         \ int c-type \ intptr_t typedef
@@ -453,7 +438,7 @@ M: pointer c-type
         [ >c-bool ] >>unboxer-quot
         [ c-bool> ] >>boxer-quot
         object >>boxed-class
-    \ bool define-primitive-type
+    \ bool typedef
 
 ] with-compilation-unit
 
index 1bfaa007fc6d8db7cf9cda92753ed05053d4d29b..e860ff688948f554da1b4e20a7d949b3d1ec049d 100644 (file)
@@ -1,7 +1,7 @@
 USING: alien alien.c-types help.syntax help.markup libc
 kernel.private byte-arrays math strings hashtables alien.syntax
 alien.strings sequences io.encodings.string debugger destructors
-vocabs.loader classes.struct quotations ;
+vocabs.loader classes.struct quotations kernel ;
 IN: alien.data
 
 HELP: <c-array>
@@ -10,11 +10,6 @@ HELP: <c-array>
 { $notes "The appropriate specialized array vocabulary must be loaded; otherwise, an error will be thrown. The vocabulary can be loaded with the " { $link require-c-array } " word. See the " { $vocab-link "specialized-arrays" } " vocabulary for details on the underlying sequence type constructed." }
 { $errors "Throws an error if the type does not exist, the necessary specialized array vocabulary is not loaded, or the requested size is negative." } ;
 
-HELP: <c-object>
-{ $values { "type" "a C type" } { "array" byte-array } }
-{ $description "Creates a byte array suitable for holding a value with the given C type." }
-{ $errors "Throws an " { $link no-c-type } " error if the type does not exist." } ;
-
 HELP: memory>byte-array
 { $values { "alien" c-ptr } { "len" "a non-negative integer" } { "byte-array" byte-array } }
 { $description "Reads " { $snippet "len" } " bytes starting from " { $snippet "base" } " and stores them in a new byte array." } ;
@@ -125,6 +120,10 @@ ARTICLE: "c-pointers" "Passing pointers to C functions"
 { $warning
 "The Factor garbage collector can move byte arrays around, and code passing byte arrays, or objects backed by byte arrays, must obey important guidelines. See " { $link "byte-arrays-gc" } "." } ;
 
+ARTICLE: "c-boxes" "C value boxes"
+"Sometimes it is useful to create a byte array storing a single C value, like a struct with a single field. A pair of utility macros exist to make this more convenient:"
+{ $subsections <ref> deref } ;
+
 ARTICLE: "c-data" "Passing data between Factor and C"
 "Two defining characteristics of Factor are dynamic typing and automatic memory management, which are somewhat incompatible with the machine-level data model exposed by C. Factor's C library interface defines its own set of C data types, distinct from Factor language types, together with automatic conversion between Factor values and C types. For example, C integer types must be declared and are fixed-width, whereas Factor supports arbitrary-precision integers."
 $nl
@@ -135,13 +134,12 @@ $nl
     "malloc"
     "c-strings"
     "c-out-params"
+    "c-boxes"
 }
 "Important guidelines for passing data in byte arrays:"
 { $subsections "byte-arrays-gc" }
 "C-style enumerated types are supported:"
-{ $subsections "alien.enums" POSTPONE: ENUM: }
-"C types can be aliased for convenience and consistency with native library documentation:"
-{ $subsections POSTPONE: TYPEDEF: }
+{ $subsections "alien.enums" }
 "A utility for defining " { $link "destructors" } " for deallocating memory:"
 { $subsections "alien.destructors" }
 "C struct and union types can be defined with " { $link POSTPONE: STRUCT: } " and " { $link POSTPONE: UNION: } ". See " { $link "classes.struct" } " for details. For passing arrays to and from C, use the " { $link "specialized-arrays" } " vocabulary." ;
@@ -190,3 +188,20 @@ $nl
 { $subsections alien>string }
 "For example, if a C function returns a " { $link c-string } " but stipulates that the caller must deallocate the memory afterward, you must define the function as returning " { $snippet "char*" } " and call " { $link (free) } " yourself." ;
 
+HELP: <ref>
+{ $values { "value" object } { "c-type" "a C type" } { "c-ptr" c-ptr } }
+{ $description "Creates a new byte array to store a Factor object as a C value." }
+{ $examples
+    { $example "USING: alien.c-types alien.data prettyprint sequences ;" "123 int <ref> length ." "4" }
+} ;
+
+HELP: deref
+{ $values { "c-ptr" c-ptr } { "c-type" "a C type" } { "value" object } }
+{ $description "Loads a C value from a byte array." }
+{ $examples
+    { $example "USING: alien.c-types alien.data prettyprint sequences ;" "321 int <ref> int deref ." "321" }
+} ;
+
+ARTICLE: "c-out-params" "Output parameters in C"
+"A frequently-occurring idiom in C code is the \"out parameter\". If a C function returns more than one value, the caller passes pointers of the correct type, and the C function writes its return values to those locations."
+{ $subsection with-out-parameters } ;
index 20a6c26b84caadaba2be2406a773644d68772352..7d53c71815c79523baea390a5a3f0685aef58392 100644 (file)
@@ -1,9 +1,32 @@
-USING: alien alien.c-types alien.data alien.syntax
+USING: alien alien.data alien.syntax
 classes.struct kernel sequences specialized-arrays
-specialized-arrays.private tools.test compiler.units vocabs ;
+specialized-arrays.private tools.test compiler.units vocabs
+system ;
+QUALIFIED-WITH: alien.c-types c
 IN: alien.data.tests
 
-STRUCT: foo { a int } { b void* } { c bool } ;
+[ -1 ] [ -1 c:char <ref> c:char deref ] unit-test
+[ -1 ] [ -1 c:short <ref> c:short deref ] unit-test
+[ -1 ] [ -1 c:int <ref> c:int deref ] unit-test
+
+! I don't care if this throws an error or works, but at least
+! it should be consistent between platforms
+[ -1 ] [ -1.0 c:int <ref> c:int deref ] unit-test
+[ -1 ] [ -1.0 c:long <ref> c:long deref ] unit-test
+[ -1 ] [ -1.0 c:longlong <ref> c:longlong deref ] unit-test
+[ 1 ] [ 1.0 c:uint <ref> c:uint deref ] unit-test
+[ 1 ] [ 1.0 c:ulong <ref> c:ulong deref ] unit-test
+[ 1 ] [ 1.0 c:ulonglong <ref> c:ulonglong deref ] unit-test
+
+[
+    0 B{ 1 2 3 4 } <displaced-alien> c:void* <ref>
+] must-fail
+
+os windows? cpu x86.64? and [
+    [ -2147467259 ] [ 2147500037 c:long <ref> c:long deref ] unit-test
+] when
+
+STRUCT: foo { a c:int } { b c:void* } { c c:bool } ;
 
 SPECIALIZED-ARRAY: foo
 
index ab34bf5a4e7f645775db13874210032b6176e957..e17ed9dc3c511eda2e3fdbfc98b3ef47fbe7eef7 100644 (file)
@@ -7,6 +7,15 @@ stack-checker.dependencies combinators.short-circuit ;
 QUALIFIED: math
 IN: alien.data
 
+: <ref> ( value c-type -- c-ptr )
+    [ heap-size <byte-array> ] keep
+    '[ 0 _ set-alien-value ] keep ; inline
+
+: deref ( c-ptr c-type -- value )
+    [ 0 ] dip alien-value ; inline
+
+: little-endian? ( -- ? ) 1 int <ref> char deref 1 = ; foldable
+
 GENERIC: require-c-array ( c-type -- )
 
 M: array require-c-array first require-c-array ;
@@ -44,15 +53,6 @@ M: pointer <c-direct-array>
 : malloc-array ( n type -- array )
     [ heap-size calloc ] [ <c-direct-array> ] 2bi ; inline
 
-: (malloc-array) ( n type -- alien )
-    [ heap-size * malloc ] [ <c-direct-array> ] 2bi ; inline
-
-: <c-object> ( type -- array )
-    heap-size <byte-array> ; inline
-
-: (c-object) ( type -- array )
-    heap-size (byte-array) ; inline
-
 : malloc-byte-array ( byte-array -- alien )
     binary-object [ nip malloc dup ] 2keep memcpy ;
 
index cc23a40df3d4eb7456a096253479096091af2a72..0625b07799083a1f2d4b0d4ad7739aa9393d3145 100644 (file)
@@ -23,14 +23,6 @@ HELP: number>enum
 }
 { $description "Convert a number to an enum." } ;
 
-ARTICLE: "alien.enums" "Enumeration types"
-"The " { $vocab-link "alien.enums" } " vocab contains the implementation for " { $link POSTPONE: ENUM: } " C types, and provides words for converting between enum symbols and integers."
-$nl
-"Defining enums at run-time:"
-{ $subsection define-enum }
-"Conversions between enums and integers:"
-{ $subsections enum>number number>enum } ;
-
 { POSTPONE: ENUM: define-enum enum>number number>enum } related-words
 
 ABOUT: "alien.enums"
index f46702f450d802e6e19b2fe99aa505e1f8651f9b..b0755c130b249076b404c081b6d9a414caff0db5 100644 (file)
@@ -13,7 +13,7 @@ PRIVATE>
 
 GENERIC: enum>number ( enum -- number ) foldable
 M: integer enum>number ;
-M: symbol enum>number "enum-value" word-prop ;
+M: word enum>number "enum-value" word-prop ;
 
 <PRIVATE
 : enum-boxer ( members -- quot )
index dc0585cab8fcadce43ae066df092f676116e73ed..ad2a60ddc47f968813b5eb927252ed6d241a25a8 100644 (file)
@@ -192,10 +192,10 @@ intel-unix-abi fortran-abi [
         {
             [ {
                 [ ascii string>alien ]
-                [ <longlong> ]
-                [ <float> ]
+                [ longlong <ref> ]
+                [ float <ref> ]
                 [ <complex-float> ]
-                [ 1 0 ? <short> ]
+                [ 1 0 ? c:short <ref> ]
             } spread ]
             [ { [ length ] [ drop ] [ drop ] [ drop ] [ drop ] } spread ]
         } 5 ncleave
@@ -211,7 +211,7 @@ intel-unix-abi fortran-abi [
             [ drop ]
             [ drop ]
             [ drop ]
-            [ *float ]
+            [ float deref ]
             [ drop ]
             [ drop ]
         } spread
@@ -239,7 +239,7 @@ intel-unix-abi fortran-abi [
 
     [ [
         ! [<fortran-result>]
-        [ complex-float <c-object> ] 1 ndip
+        [ complex-float heap-size <byte-array> ] 1 ndip
         ! [fortran-args>c-args]
         { [ { [ ] } spread ] [ { [ drop ] } spread ] } 1 ncleave
         ! [fortran-invoke]
@@ -280,7 +280,7 @@ intel-unix-abi fortran-abi [
         {
             [ {
                 [ ascii string>alien ]
-                [ <float> ]
+                [ float <ref> ]
                 [ ascii string>alien ]
             } spread ]
             [ { [ length ] [ drop ] [ length ] } spread ]
@@ -298,7 +298,7 @@ intel-unix-abi fortran-abi [
             [ ascii alien>nstring ]
             [ ]
             [ ascii alien>nstring ]
-            [ *float ]
+            [ float deref ]
             [ ]
             [ ascii alien>nstring ]
         } spread
index 3d874310841dc3b81dc59b6ca5b8b6d9e46848e9..f17e91b90ce4e907aab131668acb05778647fc1d 100755 (executable)
@@ -1,5 +1,5 @@
 ! (c) 2009 Joe Groff, see BSD license
-USING: accessors alien alien.c-types alien.complex alien.data
+USING: accessors alien alien.complex alien.c-types alien.data
 alien.parser grouping alien.strings alien.syntax arrays ascii
 assocs byte-arrays combinators combinators.short-circuit fry
 generalizations kernel lexer macros math math.parser namespaces
@@ -211,11 +211,11 @@ GENERIC: (fortran-arg>c-args) ( type -- main-quot added-quot )
 M: integer-type (fortran-arg>c-args)
     [
         size>> {
-            { f [ [ <int>      ] [ drop ] ] }
-            { 1 [ [ <char>     ] [ drop ] ] }
-            { 2 [ [ <short>    ] [ drop ] ] }
-            { 4 [ [ <int>      ] [ drop ] ] }
-            { 8 [ [ <longlong> ] [ drop ] ] }
+            { f [ [ c:int <ref>     ] [ drop ] ] }
+            { 1 [ [ c:char <ref>    ] [ drop ] ] }
+            { 2 [ [ c:short <ref>   ] [ drop ] ] }
+            { 4 [ [ c:int <ref>     ] [ drop ] ] }
+            { 8 [ [ c:longlong <ref> ] [ drop ] ] }
             [ invalid-fortran-type ]
         } case
     ] args?dims ;
@@ -226,9 +226,9 @@ M: logical-type (fortran-arg>c-args)
 M: real-type (fortran-arg>c-args)
     [
         size>> {
-            { f [ [ <float>  ] [ drop ] ] }
-            { 4 [ [ <float>  ] [ drop ] ] }
-            { 8 [ [ <double> ] [ drop ] ] }
+            { f [ [ c:float <ref> ] [ drop ] ] }
+            { 4 [ [ c:float <ref> ] [ drop ] ] }
+            { 8 [ [ c:double <ref> ] [ drop ] ] }
             [ invalid-fortran-type ]
         } case
     ] args?dims ;
@@ -244,14 +244,14 @@ M: real-complex-type (fortran-arg>c-args)
     ] args?dims ;
 
 M: double-precision-type (fortran-arg>c-args)
-    [ drop [ <double> ] [ drop ] ] args?dims ;
+    [ drop [ c:double <ref> ] [ drop ] ] args?dims ;
 
 M: double-complex-type (fortran-arg>c-args)
     [ drop [ <complex-double> ] [ drop ] ] args?dims ;
 
 M: character-type (fortran-arg>c-args)
     fix-character-type single-char?
-    [ [ first <char> ] [ drop ] ]
+    [ [ first c:char <ref> ] [ drop ] ]
     [ [ ascii string>alien ] [ length ] ] if ;
 
 M: misc-type (fortran-arg>c-args)
@@ -263,23 +263,25 @@ GENERIC: (fortran-result>) ( type -- quots )
     [ dup dims>> [ drop { [ ] } ] ] dip if ; inline
 
 M: integer-type (fortran-result>)
-    [ size>> {
-        { f [ { [ *int      ] } ] }
-        { 1 [ { [ *char     ] } ] }
-        { 2 [ { [ *short    ] } ] }
-        { 4 [ { [ *int      ] } ] }
-        { 8 [ { [ *longlong ] } ] }
-        [ invalid-fortran-type ]
-    } case ] result?dims ;
+    [
+        size>> {
+            { f [ { [ c:int deref      ] } ] }
+            { 1 [ { [ c:char deref     ] } ] }
+            { 2 [ { [ c:short deref    ] } ] }
+            { 4 [ { [ c:int deref      ] } ] }
+            { 8 [ { [ c:longlong deref ] } ] }
+            [ invalid-fortran-type ]
+        } case
+    ] result?dims ;
 
 M: logical-type (fortran-result>)
     [ call-next-method first [ zero? not ] append 1array ] result?dims ;
 
 M: real-type (fortran-result>)
     [ size>> {
-        { f [ { [ *float  ] } ] }
-        { 4 [ { [ *float  ] } ] }
-        { 8 [ { [ *double ] } ] }
+        { f [ { [ c:float deref ] } ] }
+        { 4 [ { [ c:float deref ] } ] }
+        { 8 [ { [ c:double deref ] } ] }
         [ invalid-fortran-type ]
     } case ] result?dims ;
 
@@ -292,14 +294,14 @@ M: real-complex-type (fortran-result>)
     } case ] result?dims ;
 
 M: double-precision-type (fortran-result>)
-    [ drop { [ *double ] } ] result?dims ;
+    [ drop { [ c:double deref ] } ] result?dims ;
 
 M: double-complex-type (fortran-result>)
     [ drop { [ *complex-double ] } ] result?dims ;
 
 M: character-type (fortran-result>)
     fix-character-type single-char?
-    [ { [ *char 1string ] } ]
+    [ { [ c:char deref 1string ] } ]
     [ { [ ] [ ascii alien>nstring ] } ] if ;
 
 M: misc-type (fortran-result>)
@@ -308,7 +310,7 @@ M: misc-type (fortran-result>)
 GENERIC: (<fortran-result>) ( type -- quot )
 
 M: fortran-type (<fortran-result>) 
-    (fortran-type>c-type) \ <c-object> [ ] 2sequence ;
+    (fortran-type>c-type) \ heap-size \ <byte-array> [ ] 3sequence ;
 
 M: character-type (<fortran-result>)
     fix-character-type dims>> product dup
@@ -425,8 +427,11 @@ MACRO: fortran-invoke ( return library function parameters -- )
     { [ 2drop nip set-fortran-abi ] [ (fortran-invoke) ] } 4 ncleave ;
 
 : parse-arglist ( parameters return -- types effect )
-    [ 2 group unzip [ "," ?tail drop ] map ]
-    [ [ { } ] [ 1array ] if-void ]
+    [
+        2 group
+        [ unzip [ "," ?tail drop ] map ]
+        [ [ first "!" head? ] filter [ second "," ?tail drop "'" append ] map ] bi
+    ] [ [ ] [ prefix ] if-void ]
     bi* <effect> ;
 
 :: define-fortran-function ( return library function parameters -- )
old mode 100644 (file)
new mode 100755 (executable)
index f1dc228..2721ce4
@@ -1,4 +1,4 @@
-USING: alien.libraries alien.syntax tools.test kernel ;
+USING: alien alien.libraries alien.syntax tools.test kernel ;
 IN: alien.libraries.tests
 
 [ f ] [ DLL" fadfasdfsada" dll-valid? ] unit-test
@@ -8,3 +8,21 @@ IN: alien.libraries.tests
 [ ] [ "doesnotexist" dlopen dlclose ] unit-test
 
 [ "fdasfsf" dll-valid? drop ] must-fail
+
+[ t ] [
+    "test-library" "blah" cdecl add-library
+    "test-library" "BLAH" cdecl add-library?
+    "blah" remove-library
+] unit-test
+
+[ t ] [
+    "test-library" "blah" cdecl add-library
+    "test-library" "blah" stdcall add-library?
+    "blah" remove-library
+] unit-test
+
+[ f ] [
+    "test-library" "blah" cdecl add-library
+    "test-library" "blah" cdecl add-library?
+    "blah" remove-library
+] unit-test
index a3f52df09858237d0eed78251ec41f7b06d43f89..206db7b1882b5f44df1880972b02a68e3416e9f1 100755 (executable)
@@ -2,7 +2,7 @@
 ! See http://factorcode.org/license.txt for BSD license.
 USING: accessors alien alien.strings assocs io.backend
 kernel namespaces destructors sequences strings
-system io.pathnames ;
+system io.pathnames fry ;
 IN: alien.libraries
 
 : dlopen ( path -- dll ) native-string>alien (dlopen) ;
@@ -32,9 +32,15 @@ M: library dispose dll>> [ dispose ] when* ;
 : remove-library ( name -- )
     libraries get delete-at* [ dispose ] [ drop ] if ;
 
+: add-library? ( name path abi -- ? )
+    [ library ] 2dip
+    '[ [ path>> _ = ] [ abi>> _ = ] bi and not ] [ t ] if* ;
+
 : add-library ( name path abi -- )
-    [ 2drop remove-library ]
-    [ <library> swap libraries get set-at ] 3bi ;
+    3dup add-library? [
+        [ 2drop remove-library ]
+        [ <library> swap libraries get set-at ] 3bi
+    ] [ 3drop ] if ;
 
 : library-abi ( library -- abi )
     library [ abi>> ] [ cdecl ] if* ;
index c7ff228ab27679fd5ac5e3fb1571f60692b44c1e..8f60e7e0886688eb43b057fee7b3f1acf5ee9a4f 100644 (file)
@@ -123,3 +123,13 @@ HELP: C-GLOBAL:
 { $syntax "C-GLOBAL: type name" }
 { $values { "type" "a C type" } { "name" "a C global variable name" } }
 { $description "Defines a new word named " { $snippet "name" } " which accesses a global variable in the current library, set with " { $link POSTPONE: LIBRARY: } "." } ;
+
+ARTICLE: "alien.enums" "Enumeration types"
+"The " { $vocab-link "alien.enums" } " vocab contains the implementation for " { $link POSTPONE: ENUM: } " C types, and provides words for converting between enum singletons and integers. It is possible to dispatch off of members of an enum."
+$nl
+"Defining enums:"
+{ $subsection POSTPONE: ENUM: }
+"Defining enums at run-time:"
+{ $subsection define-enum }
+"Conversions between enums and integers:"
+{ $subsections enum>number number>enum } ;
index 5588920f2e41cd13009aac713526e9db37612c3c..ac5f4324a45eb7d85ad37398e0233dc27d69d381 100644 (file)
@@ -18,10 +18,10 @@ HELP: once-at
 
 HELP: >biassoc
 { $values { "assoc" assoc } { "biassoc" biassoc } }
-{ $description "Costructs a new biassoc with the same key/value pairs as the given assoc." } ;
+{ $description "Constructs a new biassoc with the same key/value pairs as the given assoc." } ;
 
 ARTICLE: "biassocs" "Bidirectional assocs"
-"A " { $emphasis "bidirectional assoc" } " combines a pair of assocs to form a data structure where both normal assoc opeartions (eg, " { $link at } "), as well as " { $link "assocs-values" } " (eg, " { $link value-at } ") run in sub-linear time."
+"A " { $emphasis "bidirectional assoc" } " combines a pair of assocs to form a data structure where both normal assoc operations (eg, " { $link at } "), as well as " { $link "assocs-values" } " (eg, " { $link value-at } ") run in sub-linear time."
 $nl
 "Bidirectional assocs implement the entire " { $link "assocs-protocol" } " with the exception of " { $link delete-at } ". Duplicate values are allowed, however value lookups with " { $link value-at } " only return the first key that a given value was stored with."
 $nl
index 0d4543f8f2fa3685873e6470dc70888ca291f8d3..379dc1befca4dde4237d7cd0e91a27e2dd1d9368 100644 (file)
@@ -64,3 +64,8 @@ IN: bit-sets.tests
 
 [ T{ bit-set f ?{ f } } T{ bit-set f ?{ t } } ]
 [ 1 <bit-set> dup clone 0 over adjoin ] unit-test
+
+[ 0 ] [ T{ bit-set f ?{ } } cardinality ] unit-test
+[ 0 ] [ T{ bit-set f ?{ f f f f } } cardinality ] unit-test
+[ 1 ] [ T{ bit-set f ?{ f t f f } } cardinality ] unit-test
+[ 2 ] [ T{ bit-set f ?{ f t f t } } cardinality ] unit-test
index aa74c2b9fbda35592b56ce12d22bd8e5550a96d1..97201256215263e5a87f30ddd81877ffa4101cd1 100644 (file)
@@ -1,6 +1,7 @@
 ! Copyright (C) 2009 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: kernel accessors sequences byte-arrays bit-arrays math hints sets ;
+USING: kernel accessors sequences byte-arrays bit-arrays math
+math.bitwise hints sets ;
 IN: bit-sets
 
 TUPLE: bit-set { table bit-array read-only } ;
@@ -14,19 +15,21 @@ M: bit-set in?
     over integer? [ table>> ?nth ] [ 2drop f ] if ; inline
 
 M: bit-set adjoin
-    ! This is allowed to crash when the elt couldn't go in the set
+    ! This is allowed to throw an error when the elt couldn't
+    ! go in the set
     [ t ] 2dip table>> set-nth ;
 
 M: bit-set delete
-    ! This isn't allowed to crash if the elt wasn't in the set
+    ! This isn't allowed to throw an error if the elt wasn't
+    ! in the set
     over integer? [
         table>> 2dup bounds-check? [
             [ f ] 2dip set-nth
         ] [ 2drop ] if
     ] [ 2drop ] if ;
 
-! If you do binary set operations with a bitset, it's expected
-! that the other thing can also be represented as a bitset
+! If you do binary set operations with a bit-set, it's expected
+! that the other thing can also be represented as a bit-set
 ! of the same length.
 <PRIVATE
 
@@ -70,7 +73,8 @@ M: bit-set members
 <PRIVATE
 
 : bit-set-like ( set bit-set -- bit-set' )
-    ! This crashes if there are keys that can't be put in the bit set
+    ! Throws an error if there are keys that can't be put
+    ! in the bit set
     over bit-set? [ 2dup [ table>> length ] bi@ = ] [ f ] if
     [ drop ] [
         [ members ] dip table>> length <bit-set>
@@ -84,3 +88,6 @@ M: bit-set set-like
 
 M: bit-set clone
     table>> clone bit-set boa ;
+
+M: bit-set cardinality
+    table>> bit-count ;
diff --git a/basis/cache/cache-tests.factor b/basis/cache/cache-tests.factor
new file mode 100755 (executable)
index 0000000..ea1c22b
--- /dev/null
@@ -0,0 +1,50 @@
+USING: cache tools.test accessors destructors kernel assocs\r
+namespaces ;\r
+IN: cache.tests\r
+\r
+TUPLE: mock-disposable < disposable n ;\r
+\r
+: <mock-disposable> ( n -- mock-disposable )\r
+    mock-disposable new-disposable swap >>n ;\r
+\r
+M: mock-disposable dispose* drop ;\r
+\r
+[ ] [ <cache-assoc> "cache" set ] unit-test\r
+\r
+[ 0 ] [ "cache" get assoc-size ] unit-test\r
+\r
+[ ] [ "cache" get 2 >>max-age drop ] unit-test\r
+\r
+[ ] [ 1 <mock-disposable> dup "a" set 2 "cache" get set-at ] unit-test\r
+\r
+[ 1 ] [ "cache" get assoc-size ] unit-test\r
+\r
+[ ] [ "cache" get purge-cache ] unit-test\r
+\r
+[ ] [ 2 <mock-disposable> 3 "cache" get set-at ] unit-test\r
+\r
+[ 2 ] [ "cache" get assoc-size ] unit-test\r
+\r
+[ ] [ "cache" get purge-cache ] unit-test\r
+\r
+[ 1 ] [ "cache" get assoc-size ] unit-test\r
+\r
+[ ] [ 3 <mock-disposable> dup "b" set 4 "cache" get set-at ] unit-test\r
+\r
+[ 2 ] [ "cache" get assoc-size ] unit-test\r
+\r
+[ ] [ "cache" get purge-cache ] unit-test\r
+\r
+[ 1 ] [ "cache" get assoc-size ] unit-test\r
+\r
+[ f ] [ 2 "cache" get key? ] unit-test\r
+\r
+[ 3 ] [ 4 "cache" get at n>> ] unit-test\r
+\r
+[ t ] [ "a" get disposed>> ] unit-test\r
+\r
+[ f ] [ "b" get disposed>> ] unit-test\r
+\r
+[ ] [ "cache" get clear-assoc ] unit-test\r
+\r
+[ t ] [ "b" get disposed>> ] unit-test\r
old mode 100644 (file)
new mode 100755 (executable)
index a226500..1247774
@@ -25,19 +25,21 @@ M: cache-assoc set-at
     [ <cache-entry> ] 2dip
     assoc>> set-at ;
 
-M: cache-assoc clear-assoc assoc>> clear-assoc ;
+M: cache-assoc clear-assoc
+    [ assoc>> values dispose-each ]
+    [ assoc>> clear-assoc ]
+    bi ;
 
 M: cache-assoc >alist assoc>> [ value>> ] { } assoc-map-as ;
 
 INSTANCE: cache-assoc assoc
 
-M: cache-assoc dispose*
-    [ values dispose-each ] [ clear-assoc ] bi ;
+M: cache-assoc dispose* clear-assoc ;
 
 PRIVATE>
 
 : purge-cache ( cache -- )
     dup max-age>> '[
-        [ nip [ 1 + ] change-age age>> _ >= ] assoc-partition
-        [ values dispose-each ] dip
+        [ nip [ 1 + ] change-age age>> _ < ] assoc-partition
+        values dispose-each
     ] change-assoc drop ;
index c31ddca2c19493e26896112b09dc9481dd79edb9..a520eca53b0bddfc291c9bd57ff0f7d5b3b244c9 100644 (file)
@@ -5,10 +5,10 @@ math.order ;
 IN: calendar
 
 HELP: duration
-{ $description "A duration is a period of time years, months, days, hours, minutes, and seconds.  All duration slots can store " { $link real } " numbers. Compare two durations with the " { $link <=> } " word." } ;
+{ $description "A duration is a period of time years, months, days, hours, minutes, and seconds. All duration slots can store " { $link real } " numbers. Compare two durations with the " { $link <=> } " word." } ;
 
 HELP: timestamp
-{ $description "A timestamp is a date and a time with a timezone offset.  Timestamp slots must store integers except for " { $snippet "seconds" } ", which stores reals, and " { $snippet "gmt-offset" } ", which stores a " { $link duration } ". Compare two durations with the " { $link <=> } " word." } ;
+{ $description "A timestamp is a date and a time with a timezone offset. Timestamp slots must store integers except for " { $snippet "seconds" } ", which stores reals, and " { $snippet "gmt-offset" } ", which stores a " { $link duration } ". Compare two durations with the " { $link <=> } " word." } ;
 
 { timestamp duration } related-words
 
@@ -33,7 +33,7 @@ HELP: month-names
 
 HELP: month-name
 { $values { "obj" { $or integer timestamp } } { "string" string } }
-{ $description "Looks up the month name and returns it as a string.  January has an index of 1 instead of zero." } ;
+{ $description "Looks up the month name and returns it as a string. January has an index of 1 instead of zero." } ;
 
 HELP: month-abbreviations
 { $values { "value" array } }
@@ -42,7 +42,7 @@ HELP: month-abbreviations
 
 HELP: month-abbreviation
 { $values { "n" integer } { "string" string } }
-{ $description "Looks up the abbreviated month name and returns it as a string.  January has an index of 1 instead of zero." } ;
+{ $description "Looks up the abbreviated month name and returns it as a string. January has an index of 1 instead of zero." } ;
 
 
 HELP: day-names
@@ -55,7 +55,7 @@ HELP: day-name
 
 HELP: day-abbreviations2
 { $values { "value" array } }
-{ $description "Returns an array with the abbreviated English names of the days of the week.  This abbreviation is two characters long." } ;
+{ $description "Returns an array with the abbreviated English names of the days of the week. This abbreviation is two characters long." } ;
 
 HELP: day-abbreviation2
 { $values { "n" integer } { "string" string } }
@@ -63,7 +63,7 @@ HELP: day-abbreviation2
 
 HELP: day-abbreviations3
 { $values { "value" array } }
-{ $description "Returns an array with the abbreviated English names of the days of the week.  This abbreviation is three characters long." } ;
+{ $description "Returns an array with the abbreviated English names of the days of the week. This abbreviation is three characters long." } ;
 
 HELP: day-abbreviation3
 { $values { "n" integer } { "string" string } }
@@ -101,7 +101,7 @@ HELP: seconds-per-year
 
 HELP: julian-day-number
 { $values { "year" integer } { "month" integer } { "day" integer } { "n" integer } }
-{ $description "Calculates the Julian day number from a year, month, and day.  The difference between two Julian day numbers is the number of days that have elapsed between the two corresponding dates." }
+{ $description "Calculates the Julian day number from a year, month, and day. The difference between two Julian day numbers is the number of days that have elapsed between the two corresponding dates." }
 { $warning "Not valid before year -4800 BCE." } ;
 
 HELP: julian-day-number>date
@@ -340,7 +340,7 @@ HELP: >gmt
 
 HELP: time*
 { $values { "obj1" object } { "obj2" object } { "obj3" object } }
-{ $description "Multiplies each time slot of a timestamp or duration by a number and make a new duration from the result.  Used in the implementation of " { $link before } "." } ;
+{ $description "Multiplies each time slot of a timestamp or duration by a number and make a new duration from the result. Used in the implementation of " { $link before } "." } ;
 { time+ time- time* } related-words
 
 HELP: before
@@ -355,7 +355,7 @@ HELP: before
 
 HELP: <zero>
 { $values { "timestamp" timestamp } }
-{ $description "Returns a zero timestamp that consists of zeros for every slot.  Used to see if timestamps are valid." } ;
+{ $description "Returns a zero timestamp that consists of zeros for every slot. Used to see if timestamps are valid." } ;
 
 HELP: valid-timestamp?
 { $values { "timestamp" timestamp } { "?" "a boolean" } }
@@ -419,7 +419,7 @@ HELP: zeller-congruence
 { $notes "User code should use the " { $link day-of-week } " word, which takes a " { $snippet "timestamp" } " instead of integers." } ;
 
 HELP: days-in-year
-{ $values { "obj" "a timestamp or an integer" } { "n" integer } } 
+{ $values { "obj" "a timestamp or an integer" } { "n" integer } }
 { $description "Calculates the number of days in a given year." }
 { $examples
     { $example "USING: calendar prettyprint ;"
index 9f7d1659254630d0e2ce08a418b71f1e4d688cb1..f5b3afe9eef3da0722eae29f56c9613ebcf71436 100644 (file)
@@ -1,7 +1,7 @@
 ! Copyright (C) 2008 Doug Coleman.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: alien alien.c-types alien.syntax arrays calendar
-kernel math unix unix.time unix.types namespaces system
+USING: alien alien.c-types alien.data alien.syntax arrays
+calendar kernel math unix unix.time unix.types namespaces system
 accessors classes.struct ;
 IN: calendar.unix
 
@@ -21,7 +21,7 @@ IN: calendar.unix
     timespec>duration since-1970 ;
 
 : get-time ( -- alien )
-    f time <time_t> localtime ;
+    f time time_t <ref> localtime ;
 
 : timezone-name ( -- string )
     get-time zone>> ;
index f83d0354f658ebc2f8b67134d4846870da5ab259..b2af09b7d59a710e4c7e9017eb4211d425276692 100644 (file)
@@ -1,11 +1,11 @@
 ! Copyright (C) 2006, 2008 Doug Coleman.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: alien.c-types kernel io io.binary io.files io.streams.byte-array math
-math.functions math.parser namespaces splitting grouping strings
-sequences byte-arrays locals sequences.private macros fry
-io.encodings.binary math.bitwise checksums accessors
-checksums.common checksums.stream combinators combinators.smart
-specialized-arrays literals hints ;
+USING: alien.c-types alien.data kernel io io.binary io.files
+io.streams.byte-array math math.functions math.parser namespaces
+splitting grouping strings sequences byte-arrays locals
+sequences.private macros fry io.encodings.binary math.bitwise
+checksums accessors checksums.common checksums.stream
+combinators combinators.smart specialized-arrays literals hints ;
 SPECIALIZED-ARRAY: uint
 IN: checksums.md5
 
diff --git a/basis/colors/hex/authors.txt b/basis/colors/hex/authors.txt
new file mode 100644 (file)
index 0000000..e091bb8
--- /dev/null
@@ -0,0 +1 @@
+John Benediktsson
diff --git a/basis/colors/hex/hex-docs.factor b/basis/colors/hex/hex-docs.factor
new file mode 100644 (file)
index 0000000..ca49692
--- /dev/null
@@ -0,0 +1,38 @@
+! Copyright (C) 2010 John Benediktsson
+! See http://factorcode.org/license.txt for BSD license
+
+USING: colors help.markup help.syntax strings ;
+
+IN: colors.hex
+
+HELP: hex>rgba
+{ $values { "hex" string } { "rgba" color } }
+{ $description "Converts a hexadecimal string value into a " { $link color } "." }
+;
+
+HELP: rgba>hex
+{ $values { "rgba" color } { "hex" string } }
+{ $description "Converts a " { $link color } " into a hexadecimal string value." }
+;
+
+HELP: HEXCOLOR:
+{ $syntax "HEXCOLOR: value" }
+{ $description "Parses as a " { $link color } " object with the given hexadecimal value." }
+{ $examples
+  { $code
+    "USING: colors.hex io.styles ;"
+    "\"Hello!\" { { foreground HEXCOLOR: 336699 } } format nl"
+  }
+} ;
+
+ARTICLE: "colors.hex" "HEX colors"
+"The " { $vocab-link "colors.hex" } " vocabulary implements colors specified "
+"by their hexidecimal value."
+{ $subsections
+    hex>rgba
+    rgba>hex
+    POSTPONE: HEXCOLOR:
+}
+{ $see-also "colors" } ;
+
+ABOUT: "colors.hex"
diff --git a/basis/colors/hex/hex-tests.factor b/basis/colors/hex/hex-tests.factor
new file mode 100644 (file)
index 0000000..0ab1fd5
--- /dev/null
@@ -0,0 +1,12 @@
+! Copyright (C) 2010 John Benediktsson
+! See http://factorcode.org/license.txt for BSD license
+
+USING: colors colors.hex tools.test ;
+
+IN: colors.hex.test
+
+[ HEXCOLOR: 000000 ] [ 0.0 0.0 0.0 1.0 <rgba> ] unit-test
+[ HEXCOLOR: FFFFFF ] [ 1.0 1.0 1.0 1.0 <rgba> ] unit-test
+[ HEXCOLOR: abcdef ] [ "abcdef" hex>rgba ] unit-test
+[ HEXCOLOR: abcdef ] [ "ABCDEF" hex>rgba ] unit-test
+[ "ABCDEF" ] [ HEXCOLOR: abcdef rgba>hex ] unit-test
diff --git a/basis/colors/hex/hex.factor b/basis/colors/hex/hex.factor
new file mode 100644 (file)
index 0000000..a4b1aef
--- /dev/null
@@ -0,0 +1,16 @@
+! Copyright (C) 2010 John Benediktsson
+! See http://factorcode.org/license.txt for BSD license
+
+USING: accessors colors formatting grouping kernel lexer math
+math.parser sequences ;
+
+IN: colors.hex
+
+: hex>rgba ( hex -- rgba )
+    2 group [ hex> 255 /f ] map first3 1.0 <rgba> ;
+
+: rgba>hex ( rgba -- hex )
+    [ red>> ] [ green>> ] [ blue>> ] tri
+    [ 255 * >integer ] tri@ "%02X%02X%02X" sprintf ;
+
+SYNTAX: HEXCOLOR: scan hex>rgba suffix! ;
diff --git a/basis/colors/hex/summary.txt b/basis/colors/hex/summary.txt
new file mode 100644 (file)
index 0000000..37b6aba
--- /dev/null
@@ -0,0 +1 @@
+Hexadecimal colors
index 4c4e8de94dd6c78bf1e705467ce5a67b6c97c584..f5555716f31d034ea1f492b07d66ac7a5b3c2bfe 100644 (file)
@@ -3,7 +3,7 @@ kernel.private math hashtables.private math.private namespaces
 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
+make alien.c-types alien.data combinators.short-circuit math.order
 math.libm math.parser math.functions alien.syntax memory
 stack-checker ;
 FROM: math => float ;
@@ -275,7 +275,8 @@ M: cucumber equal? "The cucumber has no equal" throw ;
 
 [ 4294967295 B{ 255 255 255 255 } -1 ]
 [
-    -1 <int> -1 <int>
+    -1 int <ref>
+    -1 int <ref>
     [ [ 0 alien-unsigned-4 swap ] [ 0 alien-signed-2 ] bi ]
     compile-call
 ] unit-test
index 53017ff45231449876c4e7346372d6149b32e6f6..00345081caaa9c24fcd670f80b72ec92e8530334 100644 (file)
@@ -6,6 +6,8 @@ sbufs strings.private slots.private alien math.order
 alien.accessors alien.c-types alien.data alien.syntax alien.strings
 namespaces libc io.encodings.ascii classes compiler.test ;
 FROM: math => float ;
+FROM: alien.c-types => short ;
+QUALIFIED-WITH: alien.c-types c
 IN: compiler.tests.intrinsics
 
 ! Make sure that intrinsic ops compile to correct code.
@@ -429,46 +431,46 @@ ERROR: bug-in-fixnum* x y a b ;
 [ ] [ "hello world" ascii malloc-string "s" set ] unit-test
 
 "s" get [
-    [ "hello world" ] [ "s" get <void*> [ { byte-array } declare *void* ] compile-call ascii alien>string ] unit-test
-    [ "hello world" ] [ "s" get <void*> [ { c-ptr } declare *void* ] compile-call ascii alien>string ] unit-test
+    [ "hello world" ] [ "s" get void* <ref> [ { byte-array } declare void* deref ] compile-call ascii alien>string ] unit-test
+    [ "hello world" ] [ "s" get void* <ref> [ { c-ptr } declare void* deref ] compile-call ascii alien>string ] unit-test
 
     [ ] [ "s" get free ] unit-test
 ] when
 
-[ ALIEN: 1234 ] [ ALIEN: 1234 [ { alien } declare <void*> ] compile-call *void* ] unit-test
-[ ALIEN: 1234 ] [ ALIEN: 1234 [ { c-ptr } declare <void*> ] compile-call *void* ] unit-test
-[ f ] [ f [ { POSTPONE: f } declare <void*> ] compile-call *void* ] unit-test
+[ ALIEN: 1234 ] [ ALIEN: 1234 [ { alien } declare void* <ref> ] compile-call void* deref ] unit-test
+[ ALIEN: 1234 ] [ ALIEN: 1234 [ { c-ptr } declare void* <ref> ] compile-call void* deref ] unit-test
+[ f ] [ f [ { POSTPONE: f } declare void* <ref> ] compile-call void* deref ] unit-test
 
 [ 252 ] [ B{ 1 2 3 -4 5 } 3 [ { byte-array fixnum } declare alien-unsigned-1 ] compile-call ] unit-test
 [ -4 ] [ B{ 1 2 3 -4 5 } 3 [ { byte-array fixnum } declare alien-signed-1 ] compile-call ] unit-test
 
-[ -100 ] [ -100 <char> [ { byte-array } declare *char ] compile-call ] unit-test
-[ 156 ] [ -100 <uchar> [ { byte-array } declare *uchar ] compile-call ] unit-test
+[ -100 ] [ -100 char <ref> [ { byte-array } declare char deref ] compile-call ] unit-test
+[ 156 ] [ -100 uchar <ref> [ { byte-array } declare uchar deref ] compile-call ] unit-test
 
-[ -100 ] [ -100 \ <char> def>> [ { fixnum } declare ] prepend compile-call *char ] unit-test
-[ 156 ] [ -100 \ <uchar> def>> [ { fixnum } declare ] prepend compile-call *uchar ] unit-test
+[ -100 ] [ -100 [ char <ref> ] [ { fixnum } declare ] prepend compile-call char deref ] unit-test
+[ 156 ] [ -100 [ uchar <ref> ] [ { fixnum } declare ] prepend compile-call uchar deref ] unit-test
 
-[ -1000 ] [ -1000 <short> [ { byte-array } declare *short ] compile-call ] unit-test
-[ 64536 ] [ -1000 <ushort> [ { byte-array } declare *ushort ] compile-call ] unit-test
+[ -1000 ] [ -1000 short <ref> [ { byte-array } declare short deref ] compile-call ] unit-test
+[ 64536 ] [ -1000 ushort <ref> [ { byte-array } declare ushort deref ] compile-call ] unit-test
 
-[ -1000 ] [ -1000 \ <short> def>> [ { fixnum } declare ] prepend compile-call *short ] unit-test
-[ 64536 ] [ -1000 \ <ushort> def>> [ { fixnum } declare ] prepend compile-call *ushort ] unit-test
+[ -1000 ] [ -1000 [ short <ref> ] [ { fixnum } declare ] prepend compile-call short deref ] unit-test
+[ 64536 ] [ -1000 [ ushort <ref> ] [ { fixnum } declare ] prepend compile-call ushort deref ] unit-test
 
-[ -100000 ] [ -100000 <int> [ { byte-array } declare *int ] compile-call ] unit-test
-[ 4294867296 ] [ -100000 <uint> [ { byte-array } declare *uint ] compile-call ] unit-test
+[ -100000 ] [ -100000 int <ref> [ { byte-array } declare int deref ] compile-call ] unit-test
+[ 4294867296 ] [ -100000 uint <ref> [ { byte-array } declare uint deref ] compile-call ] unit-test
 
-[ -100000 ] [ -100000 \ <int> def>> [ { fixnum } declare ] prepend compile-call *int ] unit-test
-[ 4294867296 ] [ -100000 \ <uint> def>> [ { fixnum } declare ] prepend compile-call *uint ] unit-test
+[ -100000 ] [ -100000 [ int <ref> ] [ { fixnum } declare ] prepend compile-call int deref ] unit-test
+[ 4294867296 ] [ -100000 [ uint <ref> ] [ { fixnum } declare ] prepend compile-call uint deref ] unit-test
 
-[ t ] [ pi pi <double> *double = ] unit-test
+[ t ] [ pi pi double <ref> double deref = ] unit-test
 
-[ t ] [ pi <double> [ { byte-array } declare *double ] compile-call pi = ] unit-test
+[ t ] [ pi double <ref> [ { byte-array } declare double deref ] compile-call pi = ] unit-test
 
 ! Silly
-[ t ] [ pi 4 <byte-array> [ [ { float byte-array } declare 0 set-alien-float ] compile-call ] keep *float pi - -0.001 0.001 between? ] unit-test
-[ t ] [ pi <float> [ { byte-array } declare *float ] compile-call pi - -0.001 0.001 between? ] unit-test
+[ t ] [ pi 4 <byte-array> [ [ { float byte-array } declare 0 set-alien-float ] compile-call ] keep c:float deref pi - -0.001 0.001 between? ] unit-test
+[ t ] [ pi c:float <ref> [ { byte-array } declare c:float deref ] compile-call pi - -0.001 0.001 between? ] unit-test
 
-[ t ] [ pi 8 <byte-array> [ [ { float byte-array } declare 0 set-alien-double ] compile-call ] keep *double pi = ] unit-test
+[ t ] [ pi 8 <byte-array> [ [ { float byte-array } declare 0 set-alien-double ] compile-call ] keep double deref pi = ] unit-test
 
 [ 4 ] [
     2 B{ 1 2 3 4 5 6 } <displaced-alien> [
@@ -532,12 +534,14 @@ ERROR: bug-in-fixnum* x y a b ;
     ] compile-call
 ] unit-test
 
+! These tests must fail because we're not allowed to store
+! a pointer to a byte array inside of an alien object
 [
-    B{ 0 0 0 0 } [ { byte-array } declare <void*> ] compile-call
+    B{ 0 0 0 0 } [ { byte-array } declare void* <ref> ] compile-call
 ] must-fail
 
 [
-    B{ 0 0 0 0 } [ { c-ptr } declare <void*> ] compile-call
+    B{ 0 0 0 0 } [ { c-ptr } declare void* <ref> ] compile-call
 ] must-fail
 
 [
index 88e7895c896b514f2948a8ff64349f6bd6114795..dfce70ae38107234aecacf686d9a33393dbef725 100644 (file)
@@ -1,11 +1,11 @@
 USING: tools.test kernel.private kernel arrays sequences
 math.private math generic words quotations alien alien.c-types
-strings sbufs sequences.private slots.private combinators
-definitions system layouts vectors math.partial-dispatch
-math.order math.functions accessors hashtables classes assocs
-io.encodings.utf8 io.encodings.ascii io.encodings fry slots
-sorting.private combinators.short-circuit grouping prettyprint
-generalizations
+alien.data strings sbufs sequences.private slots.private
+combinators definitions system layouts vectors
+math.partial-dispatch math.order math.functions accessors
+hashtables classes assocs io.encodings.utf8 io.encodings.ascii
+io.encodings fry slots sorting.private combinators.short-circuit
+grouping prettyprint generalizations
 compiler.tree
 compiler.tree.combinators
 compiler.tree.cleanup
@@ -17,6 +17,7 @@ compiler.tree.propagation.info
 compiler.tree.checker
 compiler.tree.debugger ;
 FROM: math => float ;
+QUALIFIED-WITH: alien.c-types c
 IN: compiler.tree.cleanup.tests
 
 [ t ] [ [ [ 1 ] [ 2 ] if ] cleaned-up-tree [ #if? ] contains-node? ] unit-test
@@ -244,22 +245,22 @@ cell-bits 32 = [
 ] when
 
 [ t ] [
-    [ B{ 1 0 } *short 0 number= ]
+    [ B{ 1 0 } c:short deref 0 number= ]
     \ number= inlined?
 ] unit-test
 
 [ t ] [
-    [ B{ 1 0 } *short 0 { number number } declare number= ]
+    [ B{ 1 0 } c:short deref 0 { number number } declare number= ]
     \ number= inlined?
 ] unit-test
 
 [ t ] [
-    [ B{ 1 0 } *short 0 = ]
+    [ B{ 1 0 } c:short deref 0 = ]
     \ number= inlined?
 ] unit-test
 
 [ t ] [
-    [ B{ 1 0 } *short dup number? [ 0 number= ] [ drop f ] if ]
+    [ B{ 1 0 } c:short deref dup number? [ 0 number= ] [ drop f ] if ]
     \ number= inlined?
 ] unit-test
 
@@ -520,8 +521,6 @@ cell-bits 32 = [
     ] cleaned-up-tree nodes>quot
 ] unit-test
 
-USING: alien alien.c-types ;
-
 [ t ] [
     [ int { } cdecl [ 2 2 + ] alien-callback ]
     { + } inlined?
index c662eec04970b05bcb868c0cdcd7ccd3cd697311..02a40defcf7170b1c42bd64e0baf49dc17c45805 100644 (file)
@@ -1,8 +1,8 @@
 ! Copyright (C) 2009 Doug Coleman.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: alien alien.c-types alien.syntax byte-arrays combinators
-kernel math math.functions sequences system accessors
-libc ;
+USING: alien alien.c-types alien.data alien.syntax byte-arrays
+combinators kernel math math.functions sequences system
+accessors libc ;
 QUALIFIED: compression.zlib.ffi
 IN: compression.zlib
 
@@ -36,15 +36,15 @@ ERROR: zlib-failed n string ;
 
 : compress ( byte-array -- compressed )
     [
-        [ compressed-size <byte-array> dup length <ulong> ] keep [
+        [ compressed-size <byte-array> dup length ulong <ref> ] keep [
             dup length compression.zlib.ffi:compress zlib-error
-        ] 3keep drop *ulong head
+        ] 3keep drop ulong deref head
     ] keep length <compressed> ;
 
 : uncompress ( compressed -- byte-array )
     [
-        length>> [ <byte-array> ] keep <ulong> 2dup
+        length>> [ <byte-array> ] keep ulong <ref> 2dup
     ] [
         data>> dup length
         compression.zlib.ffi:uncompress zlib-error
-    ] bi *ulong head ;
+    ] bi ulong deref head ;
index 57470209b6e9b53b58e7b88d675e918dafdb2223..c3389a1aec2f5fe104d2445a62ef81c0a4ccf133 100644 (file)
@@ -43,6 +43,6 @@ $nl
     parallel-spread\r
     parallel-napply\r
 }\r
-"The " { $vocab-link "concurrency.semaphores" } " vocabulary can be used in conjuction with the above combinators to limit the maximum number of concurrent operations." ;\r
+"The " { $vocab-link "concurrency.semaphores" } " vocabulary can be used in conjunction with the above combinators to limit the maximum number of concurrent operations." ;\r
 \r
 ABOUT: "concurrency.combinators"\r
old mode 100644 (file)
new mode 100755 (executable)
index d88fcef..51dfc9e
@@ -1,7 +1,7 @@
 ! Copyright (C) 2008 Slava Pestov.\r
 ! See http://factorcode.org/license.txt for BSD license.\r
 USING: dlists kernel math concurrency.promises\r
-concurrency.mailboxes debugger accessors fry ;\r
+concurrency.mailboxes accessors fry ;\r
 IN: concurrency.count-downs\r
 \r
 ! http://java.sun.com/j2se/1.5.0/docs/api/java/util/concurrent/CountDownLatch.html\r
index ebe5bc5da2c0dfb7ffeed2a0913b1a2b985b33a6..c0ae33150e2fd76abb06d60b87647be3e3455aa5 100644 (file)
@@ -16,7 +16,7 @@ CONSTANT: test-ip "127.0.0.1"
 : test-node-client ( -- addrspec )
     {
         { [ os unix? ] [ "distributed-concurrency-test" temp-file <local> ] }
-        { [ os windows? ] [ test-ip insecure-port <inet4> ] }
+        { [ os windows? ] [ insecure-addr ] }
     } cond ;
 
     
index f600b01056a1a3cb0bf9e0a05d53d2bedd82dd97..4a331e8f19fde30c4dbd3df8b3ba8127d3876338 100644 (file)
@@ -60,7 +60,7 @@ ARTICLE: "concurrency.locks.rw" "Read-write locks"
 $nl\r
 "While this can be achieved with a simple " { $link "concurrency.locks.mutex" } ", performance will suffer, since in fact multiple threads can view the structure at the same time; serialization must only be enforced for writes."\r
 $nl\r
-"Read/write locks allow any number of threads to hold the read lock simulateneously, however attempting to acquire a write lock blocks until all other threads release read locks and write locks."\r
+"Read/write locks allow any number of threads to hold the read lock simultaneously, however attempting to acquire a write lock blocks until all other threads release read locks and write locks."\r
 $nl\r
 "Read/write locks are reentrant. A thread holding a write lock may acquire a read lock or a write lock without blocking. However a thread holding a read lock may not acquire a write lock recursively since that could break invariants assumed by the code executing with the read lock held."\r
 { $subsections\r
diff --git a/basis/concurrency/mailboxes/debugger/authors.txt b/basis/concurrency/mailboxes/debugger/authors.txt
new file mode 100755 (executable)
index 0000000..56f4654
--- /dev/null
@@ -0,0 +1 @@
+Slava Pestov\r
diff --git a/basis/concurrency/mailboxes/debugger/debugger.factor b/basis/concurrency/mailboxes/debugger/debugger.factor
new file mode 100755 (executable)
index 0000000..c222ab0
--- /dev/null
@@ -0,0 +1,8 @@
+! Copyright (C) 2010 Slava Pestov.
+! See http://factorcode.org/license.txt for BSD license.
+USING: debugger accessors debugger.threads kernel
+concurrency.mailboxes ;
+IN: concurrency.mailboxes.debugger
+
+M: linked-error error.
+    [ thread>> error-in-thread. ] [ error>> error. ] bi ;
old mode 100644 (file)
new mode 100755 (executable)
index 1638735..df73c36
@@ -2,8 +2,7 @@
 ! See http://factorcode.org/license.txt for BSD license.
 USING: dlists deques threads sequences continuations namespaces
 math quotations words kernel arrays assocs init system
-concurrency.conditions accessors debugger debugger.threads
-locals fry ;
+concurrency.conditions accessors locals fry vocabs.loader ;
 IN: concurrency.mailboxes
 
 TUPLE: mailbox { threads dlist } { data dlist } ;
@@ -77,9 +76,6 @@ M: mailbox mailbox-get-timeout block-if-empty data>> pop-back ;
 
 TUPLE: linked-error error thread ;
 
-M: linked-error error.
-    [ thread>> error-in-thread. ] [ error>> error. ] bi ;
-
 C: <linked-error> linked-error
 
 : ?linked ( message -- message )
@@ -95,3 +91,5 @@ M: linked-thread error-in-thread
 
 : spawn-linked-to ( quot name mailbox -- thread )
     <linked-thread> [ (spawn) ] keep ;
+
+{ "concurrency.mailboxes" "debugger" } "concurrency.mailboxes.debugger" require-when
index 85870db4df8925bbc1c25ec26a7e419c615d2ab5..b2c0d656f4832261d06ab7ed4db1bad53ef04866 100644 (file)
@@ -1,35 +1,35 @@
 ! Copyright (C) 2006 Chris Double.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: help.syntax help.markup 
+USING: help.syntax help.markup
 threads kernel arrays quotations strings ;
 IN: concurrency.messaging
 
 HELP: send
-{ $values { "message" object } 
-          { "thread" thread } 
+{ $values { "message" object }
+          { "thread" thread }
 }
-{ $description "Send the message to the thread by placing it in the threads mailbox. This is an asynchronous operation and will return immediately. The receving thread will act on the message the next time it retrieves that item from its mailbox (usually using the " { $link receive } " word. The message can be any Factor object. For destinations that are instances of remote-thread the message must be a serializable Factor type." } 
+{ $description "Send the message to the thread by placing it in the threads mailbox. This is an asynchronous operation and will return immediately. The receiving thread will act on the message the next time it retrieves that item from its mailbox (usually using the " { $link receive } " word. The message can be any Factor object. For destinations that are instances of remote-thread the message must be a serializable Factor type." }
 { $see-also receive receive-if } ;
 
 HELP: receive
-{ $values { "message" object } 
+{ $values { "message" object }
 }
-{ $description "Return a message from the current threads mailbox. If the box is empty, suspend the thread until another thread places an item in the mailbox (usually via the " { $link send } " word." } 
+{ $description "Return a message from the current threads mailbox. If the box is empty, suspend the thread until another thread places an item in the mailbox (usually via the " { $link send } " word." }
 { $see-also send receive-if } ;
 
 HELP: receive-if
-{ $values { "pred" "a predicate with stack effect " { $snippet "( obj -- ? )" } }  
-          { "message" object } 
+{ $values { "pred" "a predicate with stack effect " { $snippet "( obj -- ? )" } }
+          { "message" object }
 }
-{ $description "Return the first message from the current threads mailbox that satisfies the predicate. To satisfy the predicate, " { $snippet "pred" } " is called with the item on the stack and the predicate should leave a boolean indicating whether it was satisfied or not. If nothing in the mailbox satisfies the predicate then the thread will block until something does." } 
+{ $description "Return the first message from the current threads mailbox that satisfies the predicate. To satisfy the predicate, " { $snippet "pred" } " is called with the item on the stack and the predicate should leave a boolean indicating whether it was satisfied or not. If nothing in the mailbox satisfies the predicate then the thread will block until something does." }
 { $see-also send receive } ;
 
 HELP: spawn-linked
 { $values { "quot" quotation }
           { "name" string }
-          { "thread" thread } 
+          { "thread" thread }
 }
-{ $description "Start a thread which runs the given quotation. If that quotation throws an error which is not caught then the error will get propagated to the thread that spawned it. This can be used to set up 'supervisor' threads that restart child threads that crash due to uncaught errors.\n" } 
+{ $description "Start a thread which runs the given quotation. If that quotation throws an error which is not caught then the error will get propagated to the thread that spawned it. This can be used to set up 'supervisor' threads that restart child threads that crash due to uncaught errors.\n" }
 { $see-also spawn } ;
 
 ARTICLE: { "concurrency" "messaging" } "Sending and receiving messages"
@@ -65,15 +65,15 @@ ARTICLE: { "concurrency" "synchronous-sends" } "Synchronous sends"
 } ;
 
 ARTICLE: { "concurrency" "exceptions" } "Linked exceptions"
-"A thread can handle exceptions using the standard Factor exception handling mechanism. If an exception is uncaught the thread will terminate. For example:" 
-{ $code "[ 1 0 / \"This will not print\" print ] \"division-by-zero\" spawn" } 
+"A thread can handle exceptions using the standard Factor exception handling mechanism. If an exception is uncaught the thread will terminate. For example:"
+{ $code "[ 1 0 / \"This will not print\" print ] \"division-by-zero\" spawn" }
 "Processes can be linked so that a parent thread can receive the exception that caused the child thread to terminate. In this way 'supervisor' threads can be created that are notified when child threads terminate and possibly restart them."
 { $subsections spawn-linked }
 "This will create a unidirectional link, such that if an uncaught exception causes the child to terminate, the parent thread can catch it:"
 { $code "["
 "  [ 1 0 / \"This will not print\" print ] \"linked-division\" spawn-linked drop"
 "  receive"
-"] [ \"Exception caught.\" print ] recover" } 
+"] [ \"Exception caught.\" print ] recover" }
 "Exceptions are only raised in the parent when the parent does a " { $link receive } " or " { $link receive-if } ". This is because the exception is sent from the child to the parent as a message." ;
 
 ARTICLE: "concurrency.messaging" "Message-passing concurrency"
index ae061cb4eb8e0e3dcf560e5f87700b7158cf63a3..81440e20f6d207e6e81a25ebb489e9bddc5614e4 100644 (file)
@@ -1,6 +1,7 @@
 ! Copyright (C) 2009 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: alien.c-types alien.syntax kernel math core-foundation ;
+USING: alien.c-types alien.data alien.syntax kernel math
+core-foundation ;
 FROM: math => float ;
 IN: core-foundation.numbers
 
@@ -30,14 +31,14 @@ FUNCTION: CFNumberRef CFNumberCreate ( CFAllocatorRef allocator, CFNumberType th
 GENERIC: <CFNumber> ( number -- alien )
 
 M: integer <CFNumber>
-    [ f kCFNumberLongLongType ] dip <longlong> CFNumberCreate ;
+    [ f kCFNumberLongLongType ] dip longlong <ref> CFNumberCreate ;
 
 M: float <CFNumber>
-    [ f kCFNumberDoubleType ] dip <double> CFNumberCreate ;
+    [ f kCFNumberDoubleType ] dip double <ref> CFNumberCreate ;
 
 M: t <CFNumber>
-    drop f kCFNumberIntType 1 <int> CFNumberCreate ;
+    drop f kCFNumberIntType 1 int <ref> CFNumberCreate ;
 
 M: f <CFNumber>
-    drop f kCFNumberIntType 0 <int> CFNumberCreate ;
+    drop f kCFNumberIntType 0 int <ref> CFNumberCreate ;
 
index d921789cb053031773962c217343517f8dbd42d6..8463bf145ff2f6db508bf7c5b17173cc1c992798 100644 (file)
@@ -1,9 +1,9 @@
 ! Copyright (C) 2009 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: alien alien.c-types alien.destructors alien.syntax accessors
-destructors fry kernel math math.bitwise sequences libc colors
-images images.memory core-graphics.types core-foundation.utilities
-opengl.gl literals ;
+USING: alien alien.c-types alien.data alien.destructors
+alien.syntax accessors destructors fry kernel math math.bitwise
+sequences libc colors images images.memory core-graphics.types
+core-foundation.utilities opengl.gl literals ;
 IN: core-graphics
 
 TYPEDEF: int CGImageAlphaInfo
index afcc877953826a1e280a2eef88ad823a4d1e5e73..0b71681d0d6929ad8197ef5ea85e0f362f5dc80d 100644 (file)
@@ -1,15 +1,16 @@
 ! Copyright (C) 2009, 2010 Joe Groff, Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: alien.c-types arrays assocs combinators fry kernel locals
+USING: alien.data arrays assocs combinators fry kernel locals
 macros math math.vectors namespaces quotations sequences system
 compiler.cfg.comparisons compiler.cfg.intrinsics
 compiler.codegen.fixup cpu.architecture cpu.x86
 cpu.x86.assembler cpu.x86.assembler.operands cpu.x86.features ;
+QUALIFIED-WITH: alien.c-types c
 IN: cpu.x86.sse
 
 ! Scalar floating point with SSE2
-M: x86 %load-float <float> float-rep %load-vector ;
-M: x86 %load-double <double> double-rep %load-vector ;
+M: x86 %load-float c:float <ref> float-rep %load-vector ;
+M: x86 %load-double c:double <ref> double-rep %load-vector ;
 
 M: float-rep copy-register* drop MOVAPS ;
 M: double-rep copy-register* drop MOVAPS ;
index 445b913bc9d24b509d5d0a0e5762f0c2a9243494..9ba707709bbea05a873843621cd3e1b95cfb8258 100644 (file)
@@ -1,7 +1,7 @@
 ! Copyright (C) 2010 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: alien.c-types combinators kernel locals system namespaces
-compiler.codegen.fixup compiler.constants
+USING: alien.c-types alien.data combinators kernel locals system
+namespaces compiler.codegen.fixup compiler.constants
 compiler.cfg.comparisons compiler.cfg.intrinsics
 cpu.architecture cpu.x86 cpu.x86.assembler
 cpu.x86.assembler.operands ;
@@ -38,12 +38,12 @@ M: double-rep copy-memory* copy-memory-x87 ;
 
 M: x86 %load-float
     0 [] FLDS
-    <float> rc-absolute rel-binary-literal
+    float <ref> rc-absolute rel-binary-literal
     shuffle-down FSTP ;
 
 M: x86 %load-double
     0 [] FLDL
-    <double> rc-absolute rel-binary-literal
+    double <ref> rc-absolute rel-binary-literal
     shuffle-down FSTP ;
 
 :: binary-op ( dst src1 src2 quot -- )
index 66c9f32f7fcf39b383fc99933913e595d827d858..cf358fa4b2ecae9ffe1870cba702f1198f297853 100644 (file)
@@ -271,24 +271,21 @@ ARTICLE: "db-lowlevel-tutorial" "Low-level database tutorial"
 { $subsections sql-query }
 "Here's an example usage where we'll make a book table, insert some objects, and query them." $nl
 "First, let's set up a custom combinator for using our database. See " { $link "db-custom-database-combinators" } " for more details."
-{ $code """
-USING: db.sqlite db io.files io.files.temp ;
+{ $code """USING: db.sqlite db io.files io.files.temp ;
 : with-book-db ( quot -- )
-    "book.db" temp-file <sqlite-db> swap with-db ; inline" }
+    "book.db" temp-file <sqlite-db> swap with-db ; inline""" }
 "Now let's create the table manually:"
-{ $code " "create table books
+{ $code """"create table books
     (id integer primary key, title text, author text, date_published timestamp,
      edition integer, cover_price double, condition text)"
     [ sql-command ] with-book-db""" }
 "Time to insert some books:"
-{ $code """
-"insert into books
+{ $code """"insert into books
     (title, author, date_published, edition, cover_price, condition)
     values('Factor for Sheeple', 'Mister Stacky Pants', date('now'), 1, 13.37, 'mint')"
 [ sql-command ] with-book-db""" }
 "Now let's select the book:"
-{ $code """
-"select id, title, cover_price from books;" [ sql-query ] with-book-db""" }
+{ $code """"select id, title, cover_price from books;" [ sql-query ] with-book-db""" }
 "Notice that the result of this query is a Factor array containing the database rows as arrays of strings. We would have to convert the " { $snippet "cover_price" } " from a string to a number in order to use it in a calculation." $nl
 "In conclusion, this method of accessing a database is supported, but it is fairly low-level and generally specific to a single database. The " { $vocab-link "db.tuples" } " vocabulary is a good alternative to writing SQL by hand." ;
 
@@ -298,10 +295,9 @@ ARTICLE: "db-custom-database-combinators" "Custom database combinators"
 "Make a " { $snippet "with-" } " combinator to open and close a database so that resources are not leaked." $nl
 
 "SQLite example combinator:"
-{ $code """
-USING: db.sqlite db io.files io.files.temp ;
+{ $code """USING: db.sqlite db io.files io.files.temp ;
 : with-sqlite-db ( quot -- )
-    "my-database.db" temp-file <sqlite-db> swap with-db ; inline""" } 
+    "my-database.db" temp-file <sqlite-db> swap with-db ; inline""" }
 
 "PostgreSQL example combinator:"
 { $code """USING: db.postgresql db ;
index 3f77f9abaf6b51b6e5aa2f2f628125ee48147f85..36e6b4bf2cd4e3c4cc8b59965fe723cab049a2b6 100644 (file)
@@ -70,14 +70,13 @@ HELP: define-persistent
     { "the name of a database column that maps to the slot" }        { "a database type (see " { $link "db.types" } ")" }
 } "Throws an error if the slot name (column one from each row) is not a slot in the tuple or its superclases." }
 { $examples
-    { $unchecked-example "USING: db.tuples db.types ;"
+    { $code "USING: db.tuples db.types ;"
         "TUPLE: boat id year name ;"
         "boat \"BOAT\" {"
         "    { \"id\" \"ID\" +db-assigned-id+ }"
         "    { \"year\" \"YEAR\" INTEGER }"
         "    { \"name\" \"NAME\" TEXT }"
         "} define-persistent"
-        ""
     }
 } ;
 
@@ -233,8 +232,7 @@ T{ book
     { date-published T{ timestamp { year 2009 } { month 3 } { day 3 } } }
     { edition 1 }
     { cover-price 13.37 }
-} book set
-""" }
+} book set""" }
 "Now we've created a book. Let's save it to the database."
 { $code """USING: db db.sqlite fry io.files.temp ;
 : with-book-tutorial ( quot -- )
@@ -243,8 +241,7 @@ T{ book
 [
     book recreate-table
     book get insert-tuple
-] with-book-tutorial
-""" }
+] with-book-tutorial""" }
 "Is it really there?"
 { $code """[
     T{ book { title "Factor for Sheeple" } } select-tuples .
index 4bcd9c5b789fa2edd3cbf08a48fd8ba9429cad77..50461226b55477bbb7b77bf7cbe294593ed74add 100644 (file)
@@ -117,7 +117,7 @@ HELP: signal-error.
         { "8 - Arithmetic exception. Most likely a divide by zero in " { $link /i } "." }
         { "10, 11 - Memory protection fault. This error suggests invalid values are being passed to C functions by an " { $link alien-invoke } ". Factor also uses memory protection to trap stack underflows and overflows, but usually these are reported as their own errors. Sometimes they'll show up as a generic signal 11, though." }
     }
-    "The Windows equivalent of a signal 11 is a SEH fault. When one occurs, the runtime throws a singal error, even though it does not correspond to a Unix signal."
+    "The Windows equivalent of a signal 11 is a SEH fault. When one occurs, the runtime throws a signal error, even though it does not correspond to a Unix signal."
 } ;
 
 HELP: array-size-error.
index 492845854315c969fbc2337d7d3664e960471a76..4f59f71f3a9066a3c5cba7d352cc19b49e3786f2 100644 (file)
@@ -1,13 +1,13 @@
 ! Copyright (C) 2009 Doug Coleman.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: alien.c-types namespaces io.binary fry
+USING: alien.c-types alien.data namespaces io.binary fry
 kernel math grouping sequences math.bitwise ;
 IN: endian
 
 SINGLETONS: big-endian little-endian ;
 
 : compute-native-endianness ( -- class )
-    1 <int> *char 0 = big-endian little-endian ? ;
+    1 int <ref> char deref 0 = big-endian little-endian ? ;
 
 SYMBOL: native-endianness
 native-endianness [ compute-native-endianness ] initialize
index ec41e919d8e2ce9157ad4930481cfca12fcc86e4..abfa15b5ed82dc2d61d0a88cfff11e2802a8eb97 100644 (file)
@@ -17,7 +17,7 @@ M: unix set-os-env ( value key -- ) swap 1 setenv io-error ;
 M: unix unset-os-env ( key -- ) unsetenv io-error ;
 
 M: unix (os-envs) ( -- seq )
-    environ *void* utf8 alien>strings ;
+    environ void* deref utf8 alien>strings ;
 
 : set-void* ( value alien -- ) 0 set-alien-cell ;
 
index f3ee35d91c543959c44c2043acae11babb1c2841..e7e3c023030fb909f25becc62f0ef1a17aacbfb0 100644 (file)
@@ -50,7 +50,7 @@ $nl
 { $code
     """USING: eval listener vocabs.parser ;
 [
-    "cad-objects" use-vocab
+    "cad.objects" use-vocab
     (( -- seq )) (eval)
 ] with-interactive-vocabs"""
 }
index 9d51ba259eec18fe0053d1b0769575aa3759ee06..c94d5a273a20bbc46e4774c61d3d606d47002acc 100644 (file)
@@ -61,7 +61,7 @@ ERROR: ftp-error got expected ;
     strings>> first "|" split 2 tail* first string>number ;
 
 : open-passive-client ( url protocol -- stream )
-    [ host>> ftp-epsv parse-epsv <inet> ] dip <client> drop ;
+    [ url-addr ftp-epsv parse-epsv with-port ] dip <client> drop ;
 
 : list ( url -- ftp-response )
     utf8 open-passive-client
@@ -84,7 +84,7 @@ ERROR: ftp-error got expected ;
     ftp-set-binary 200 ftp-assert ;
 
 : ftp-connect ( url -- stream )
-    [ host>> ] [ port>> ] bi <inet> utf8 <client> drop ;
+    url-addr utf8 <client> drop ;
 
 : with-ftp-client ( url quot -- )
     [ [ ftp-connect ] keep ] dip
index fa6afa30cc735234a59811b59a48059c2c179792..49ffc25e0ab8d007807679dc5a4e197432790754 100644 (file)
@@ -17,11 +17,8 @@ CONSTANT: test-file-contents "Files are so boring anymore."
     '[
         current-temporary-directory get
         0 <ftp-server> [
-            insecure-port
-            <url>
-                swap >>port
+            "ftp://localhost" >url insecure-addr set-url-addr
                 "ftp" >>protocol
-                "localhost" >>host
                 create-test-file >>path
                 @
         ] with-threaded-server
index ae9dd9b65c54b557326cf3b974ec8e704b4712e0..76f2ec036a2d3f9592f53b4e058c4811a8218507 100644 (file)
@@ -9,7 +9,7 @@ HELP: <action>
 
 HELP: <chloe-content>
 { $values
-     { "pair" "a pair with shape " { $snippet "{ class string }" } }
+     { "path" "a path" }
      { "response" response }
 }
 { $description "Creates an HTTP response which serves a Chloe template. See " { $link "html.templates.chloe" } "." } ;
index 2acb09919d8aa2a0fd35a3d8a154a7e315dab5bb..7cd2a890eeccba9397743bef48829f1ad24a2833 100644 (file)
@@ -1,9 +1,9 @@
-! Copyright (c) 2008 Slava Pestov\r
+! Copyright (c) 2008, 2010 Slava Pestov\r
 ! See http://factorcode.org/license.txt for BSD license.\r
 USING: accessors assocs namespaces kernel sequences sets\r
-destructors combinators fry logging\r
-io.encodings.utf8 io.encodings.string io.binary random\r
-checksums checksums.sha urls\r
+destructors combinators fry logging io.encodings.utf8\r
+io.encodings.string io.binary io.sockets.secure random checksums\r
+checksums.sha urls\r
 html.forms\r
 http.server\r
 http.server.filters\r
@@ -79,7 +79,7 @@ GENERIC: logged-in-username ( realm -- username )
         swap >>default\r
         users-in-db >>users\r
         sha-256 >>checksum\r
-        t >>secure ; inline\r
+        ssl-supported? >>secure ; inline\r
 \r
 : users ( -- provider )\r
     realm get users>> ;\r
index 38ba8e2b1fdaece1960b8b2b6aef9ed7f57fb61e..7889ffc626e43c898fa1af55a0121125062347e7 100644 (file)
@@ -21,7 +21,7 @@ M: recaptcha call-responder*
 
 <PRIVATE
 
-: (render-recaptcha) ( private-key -- xml )
+: (render-recaptcha) ( url -- xml )
     dup
     [XML
         <script type="text/javascript"
index ff81d73f7f7fd21017a898d59210c800d529e8f6..29bb5051421e5a3b0e049ff84a75d65c98f30230 100644 (file)
@@ -1,7 +1,7 @@
-! Copyright (C) 2008 Slava Pestov.
+! Copyright (C) 2008, 2010 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: kernel accessors combinators namespaces fry urls urls.secure
-http http.server http.server.redirection http.server.responses
+USING: kernel accessors combinators namespaces fry urls http
+http.server http.server.redirection http.server.responses
 http.server.remapping http.server.filters furnace.utilities ;
 IN: furnace.redirection
 
index f5b3520b12d9bdecffc14c6f22859c0999c25925..fd9d992f138941cb575bb2fbf982d94bc66e2e0f 100755 (executable)
@@ -1,12 +1,12 @@
-USING: accessors alien alien.c-types alien.strings arrays assocs
-byte-arrays combinators combinators.short-circuit continuations
-game.input game.input.dinput.keys-array io.encodings.utf16
-io.encodings.utf16n kernel locals math math.bitwise
-math.rectangles namespaces parser sequences shuffle
+USING: accessors alien alien.c-types alien.data alien.strings
+arrays assocs byte-arrays combinators combinators.short-circuit
+continuations game.input game.input.dinput.keys-array
+io.encodings.utf16 io.encodings.utf16n kernel locals math
+math.bitwise math.rectangles namespaces parser sequences shuffle
 specialized-arrays ui.backend.windows vectors windows.com
 windows.directx.dinput windows.directx.dinput.constants
 windows.kernel32 windows.messages windows.ole32 windows.errors
-windows.user32 classes.struct alien.data ;
+windows.user32 classes.struct ;
 SPECIALIZED-ARRAY: DIDEVICEOBJECTDATA
 IN: game.input.dinput
 
@@ -23,15 +23,15 @@ SYMBOLS: +dinput+ +keyboard-device+ +keyboard-state+
 
 : create-dinput ( -- )
     f GetModuleHandle DIRECTINPUT_VERSION IDirectInput8W-iid
-    f <void*> [ f DirectInput8Create ole32-error ] keep *void*
+    f void* <ref> [ f DirectInput8Create ole32-error ] keep void* deref
     +dinput+ set-global ;
 
 : delete-dinput ( -- )
     +dinput+ [ com-release f ] change-global ;
 
 : device-for-guid ( guid -- device )
-    +dinput+ get-global swap f <void*>
-    [ f IDirectInput8W::CreateDevice ole32-error ] keep *void* ;
+    +dinput+ get-global swap f void* <ref>
+    [ f IDirectInput8W::CreateDevice ole32-error ] keep void* deref ;
 
 : set-coop-level ( device -- )
     +device-change-window+ get-global DISCL_BACKGROUND DISCL_NONEXCLUSIVE bitor
@@ -303,8 +303,8 @@ CONSTANT: pov-values
     } 2cleave ;
 
 : read-device-buffer ( device buffer count -- buffer count' )
-    [ DIDEVICEOBJECTDATA heap-size ] 2dip <uint>
-    [ 0 IDirectInputDevice8W::GetDeviceData ole32-error ] 2keep *uint ;
+    [ DIDEVICEOBJECTDATA heap-size ] 2dip uint <ref>
+    [ 0 IDirectInputDevice8W::GetDeviceData ole32-error ] 2keep uint deref ;
 
 : (fill-mouse-state) ( state DIDEVICEOBJECTDATA -- state )
     [ dwData>> 32 >signed ] [ dwOfs>> ] bi {
index c91eb231ab6fee5f5d4e3235501ea3791e9bef8e..44da43a76b88157715631b30b0229efe82bc33c5 100644 (file)
@@ -26,7 +26,7 @@ ARTICLE: "grouping" "Groups and clumps"
             "{ 1 2 3 4 } dup" "2 <groups> concat sequence= ." "t"
         }
     }
-    { "With clumps, collecting the first element of each subsequence but the last one, together with the last subseqence, yields the original sequence:"
+    { "With clumps, collecting the first element of each subsequence but the last one, together with the last subsequence, yields the original sequence:"
         { $unchecked-example
             "USING: grouping ;"
             "{ 1 2 3 4 } 2 clump ." "{ { 1 2 } { 2 3 } { 3 4 } }"
index da5f2911f836cc436eed65a64b89ecf4ed1cec38..9c8464cae1316a8eb4a2c808d6e172c36f9f5ce6 100644 (file)
@@ -45,7 +45,7 @@ $nl
 $nl
 "Some generic words have " { $strong "Description" } " headings, and others have " { $strong "Contract" } " headings. A distinction is made between words which are not intended to be extended with user-defined methods, and those that are."
 { $heading "Vocabulary naming conventions" }
-"A vocabulary name ending in " { $snippet ".private" } " contains words which are either implementation details, unsafe, or both. For example, the " { $snippet "sequence.private" } " vocabulary contains words which access sequence elements without bounds checking (" { $link "sequences-unsafe" } "). You should avoid using private words from the Factor library unless absolutely necessary. Similarly, your own code can place words in private vocabularies using " { $link POSTPONE: <PRIVATE } " if you do not want other people using them without good reason."
+"A vocabulary name ending in " { $snippet ".private" } " contains words which are either implementation details, unsafe, or both. For example, the " { $snippet "sequences.private" } " vocabulary contains words which access sequence elements without bounds checking (" { $link "sequences-unsafe" } "). You should avoid using private words from the Factor library unless absolutely necessary. Similarly, your own code can place words in private vocabularies using " { $link POSTPONE: <PRIVATE } " if you do not want other people using them without good reason."
 { $heading "Word naming conventions" }
 "These conventions are not hard and fast, but are usually a good first step in understanding a word's behavior:"
 { $table
index e3bd50a6f2ddc399d004a7dcd9430ea694850c88..8e22aad21207c61de83699da9154adaa22ac0e22 100644 (file)
@@ -476,7 +476,8 @@ HELP: HELP:
 { $description "Defines documentation for a word." }
 { $examples
     { $code
-        ": foo 2 + ;"
+        "USING: help help.markup help.syntax math ;"
+        ": foo ( m -- n ) 2 + ;"
         "HELP: foo"
         "{ $values { \"m\" \"an integer\" } { \"n\" \"an integer\" } }"
         "{ $description \"Increments a value by 2.\" } ;"
index ee22782fdcfd4f97133683c6baf67fb3dec72601..c3924b9c8a7ec5403d19353545c6db4217865e71 100644 (file)
@@ -24,7 +24,7 @@ $nl
 ARTICLE: "first-program-logic" "Writing some logic in your first program"
 "Your " { $snippet "palindrome.factor" } " file should look like the following after the previous section:"
 { $code
-    "! Copyright (C) 2009 <your name here>"
+    "! Copyright (C) 2011 <your name here>"
     "! See http://factorcode.org/license.txt for BSD license."
     "USING: ;"
     "IN: palindrome"
@@ -127,7 +127,7 @@ $nl
 "Finally, pass the string and the quotation to the " { $link filter } " word:"
 { $code "filter" }
 "Now the stack should contain the following string:"
-{ "\"AmanaplanacanalPanama\"" }
+{ "\"AmanaplanacanalPanama\"" } ". "
 "This is almost what we want; we just need to convert the string to lower case now. This can be done by calling " { $link >lower } "; the " { $snippet ">" } " prefix is a naming convention for conversion operations, and should be read as “to”:"
 { $code ">lower" }
 "Finally, let's print the top of the stack and discard it:"
index 46bdc698b73a59874c1884ba25626bfec96aa5fa..b5e7b377258e2740c63f3f5aaff908c10d120360 100644 (file)
@@ -24,20 +24,25 @@ HELP: HINTS:
 { $description "Defines specialization hints for a word or a method."
 $nl
 "Each sequence in the list will cause a specialized version of the word to be compiled. Classes are tested for using their predicate, and literals are tested using " { $link eq? } "." }
-{ $examples "The " { $link append } " word has a specializer for the very common case where two strings or two arrays are appended:"
-{ $code "HINTS: append { string string } { array array } ;" }
-"Specializers can also be defined on methods:"
-{ $code
-    "GENERIC: count-occurrences ( elt obj -- n )"
-    ""
-    "M: sequence count-occurrences [ = ] with count ;"
-    ""
-    "M: assoc count-occurrences"
-    "    swap [ = nip ] curry assoc-filter assoc-size ;"
-    ""
-    "HINTS: M\ sequence count-occurrences { object array } ;"
-    "HINTS: M\ assoc count-occurrences { object hashtable } ;"
-}
+{ $examples
+    "The " { $link append } " word has a specializer for the very common case where two strings or two arrays are appended:"
+    { $code
+        "USING: arrays hints sequences strings ;"
+        "HINTS: append { string string } { array array } ;"
+    }
+    "Specializers can also be defined on methods:"
+    { $code
+        "USING: assocs hashtables hints kernel sequences ;"
+        "GENERIC: count-occurrences ( elt obj -- n )"
+        ""
+        "M: sequence count-occurrences [ = ] with count ;"
+        ""
+        "M: assoc count-occurrences"
+        "    swap [ = nip ] curry assoc-filter assoc-size ;"
+        ""
+        "HINTS: M\\ sequence count-occurrences { object array } ;"
+        "HINTS: M\\ assoc count-occurrences { object hashtable } ;"
+    }
 } ;
 
 ABOUT: "hints"
index dc16cf8b246b4b7e99eb9db215f3721ad1516339..abfb3199a2989574f3a1fc0546cc9a7d942c5310 100644 (file)
@@ -3,9 +3,9 @@
 USING: accessors arrays assocs byte-arrays byte-vectors classes
 combinators definitions effects fry generic generic.single
 generic.standard hashtables io.binary io.encodings
-io.streams.string kernel kernel.private math
-math.integers.private math.parser namespaces parser sbufs
-sequences splitting splitting.private strings vectors words ;
+io.streams.string kernel kernel.private math math.parser
+namespaces parser sbufs sequences splitting splitting.private
+strings vectors words ;
 IN: hints
 
 GENERIC: specializer-predicate ( spec -- quot )
@@ -130,6 +130,4 @@ M\ hashtable at* { { fixnum object } { word object } } "specializer" set-word-pr
 
 M\ hashtable set-at { { object fixnum object } { object word object } } "specializer" set-word-prop
 
-\ bignum/f { { bignum bignum } { bignum fixnum } { fixnum bignum } { fixnum fixnum } } "specializer" set-word-prop
-
 \ encode-string { string object object } "specializer" set-word-prop
index 2aca1c98aaf7e09894afd5973b97121edc6d59dc..7b5f6bc619a8fca5b19459db466884ead523802c 100644 (file)
@@ -84,13 +84,13 @@ ARTICLE: "html.templates.chloe.tags.boilerplate" "Boilerplate Chloe tags"
 $nl
 "The tags marked with (*) are only available if the " { $vocab-link "furnace.chloe-tags" } " vocabulary is loaded."
 { $table
-    { { $snippet "t:title" } "Sets the title from a child template" }
-    { { $snippet "t:write-title" } "Renders the child's title from a master template" }
-    { { $snippet "t:style" } "Adds CSS markup from a child template" }
-    { { $snippet "t:write-style" } "Renders the children's CSS from a master template" }
-    { { $snippet "t:atom" } "Adds an Atom feed link from a child template (*)" }
-    { { $snippet "t:write-atom" } "Renders the children's list of Atom feed links (*)" }
-    { { $snippet "t:call-next-template" } "Calls the child template from a master template" }
+    { { $snippet "t:title" } "Sets the title. Intended for use in a master template." }
+    { { $snippet "t:write-title" } "Renders the child's title. Intended for use in a child template." }
+    { { $snippet "t:style" } { "Adds CSS markup from the file named by the " { $snippet "t:include" } " attribute. Intended for use in a child template." } }
+    { { $snippet "t:write-style" } "Renders the children's CSS markup. Intended for use in a master template." }
+    { { $snippet "t:atom" } { "Adds an Atom feed link. The attributes are the same as the " { $snippet "t:link" } " tag. Intended for use in a child template. (*)" } }
+    { { $snippet "t:write-atom" } "Renders the children's list of Atom feed links. Intended for use in a master template. (*)" }
+    { { $snippet "t:call-next-template" } "Calls the next child template from a master template." }
 } ;
 
 ARTICLE: "html.templates.chloe.tags.control" "Control-flow Chloe tags"
index 04077fc2f7b0369b4cab6750041a1e57de778f6a..d5f50de109c408d35a0ba381c7942d4df866c6f9 100644 (file)
@@ -129,7 +129,7 @@ ARTICLE: "http.client.errors" "HTTP client errors"
 ARTICLE: "http.client" "HTTP client"
 "The " { $vocab-link "http.client" } " vocabulary implements an HTTP and HTTPS client on top of " { $link "http" } "."
 $nl
-"For HTTPS support, you must load the " { $vocab-link "urls.secure" } " vocab first. If you don't need HTTPS support, don't load " { $vocab-link "urls.secure" } "; this will reduce the size of images generated by " { $vocab-link "tools.deploy" } "."
+"For HTTPS support, you must load the " { $vocab-link "io.sockets.secure" } " vocab first. If you don't need HTTPS support, don't load " { $vocab-link "io.sockets.secure" } "; this will reduce the size of images generated by " { $vocab-link "tools.deploy" } "."
 $nl
 "There are two primary usage patterns, data retrieval with GET requests and form submission with POST requests:"
 { $subsections
@@ -139,7 +139,7 @@ $nl
 }
 "Submission data for POST and PUT requests:"
 { $subsections "http.client.post-data" }
-"More esoteric use-cases, for example HTTP methods other than the above, are accomodated by constructing an empty request object with " { $link <request> } " and filling everything in by hand."
+"More esoteric use-cases, for example HTTP methods other than the above, are accommodated by constructing an empty request object with " { $link <request> } " and filling everything in by hand."
 { $subsections
     "http.client.encoding"
     "http.client.errors"
index ed146d98de4ccf0d0d8d35b17ed05bb0f1fa7e88..f161b4276f0589c497d512db86631411da56c891 100644 (file)
@@ -3,7 +3,7 @@ multiline io.streams.string io.encodings.utf8 io.encodings.8-bit
 io.encodings.binary io.encodings.string io.encodings.ascii kernel
 arrays splitting sequences assocs io.sockets db db.sqlite
 continuations urls hashtables accessors namespaces xml.data
-io.encodings.8-bit.latin1 random ;
+io.encodings.8-bit.latin1 random combinators.short-circuit ;
 IN: http.tests
 
 [ "text/plain" "UTF-8" ] [ "text/plain" parse-content-type ] unit-test
@@ -16,6 +16,8 @@ IN: http.tests
 
 [ "localhost" f ] [ "localhost" parse-host ] unit-test
 [ "localhost" 8888 ] [ "localhost:8888" parse-host ] unit-test
+[ "::1" 8888 ] [ "::1:8888" parse-host ] unit-test
+[ "127.0.0.1" 8888 ] [ "127.0.0.1:8888" parse-host ] unit-test
 
 [ "localhost" ] [ T{ url { protocol "http" } { host "localhost" } } unparse-host ] unit-test
 [ "localhost" ] [ T{ url { protocol "http" } { host "localhost" } { port 80 } } unparse-host ] unit-test
@@ -219,12 +221,6 @@ http.server.dispatchers db.tuples ;
 
 : test-db ( -- db ) test-db-file <sqlite-db> ;
 
-[ test-db-file delete-file ] ignore-errors
-
-test-db [
-    init-furnace-tables
-] with-db
-
 : test-httpd ( responder -- )
     [
         main-responder set
@@ -232,16 +228,25 @@ test-db [
             0 >>insecure
             f >>secure
         start-server
-        servers>> random addr>> port>>
-    ] with-scope "port" set ;
+        threaded-server set
+        server-addrs random
+    ] with-scope "addr" set ;
 
-: add-port ( url -- url' )
-    >url clone "port" get >>port ;
+: add-addr ( url -- url' )
+    >url clone "addr" get set-url-addr ;
 
 : stop-test-httpd ( -- )
-    "http://localhost/quit" add-port http-get nip
+    "http://localhost/quit" add-addr http-get nip
     "Goodbye" assert= ;
 
+[ ] [
+    [ test-db-file delete-file ] ignore-errors
+
+    test-db [
+        init-furnace-tables
+    ] with-db
+] unit-test
+
 [ ] [
     <dispatcher>
         add-quit-action
@@ -257,14 +262,14 @@ test-db [
 
 [ t ] [
     "vocab:http/test/foo.html" ascii file-contents
-    "http://localhost/nested/foo.html" add-port http-get nip =
+    "http://localhost/nested/foo.html" add-addr http-get nip =
 ] unit-test
 
-[ "http://localhost/redirect-loop" add-port http-get nip ]
+[ "http://localhost/redirect-loop" add-addr http-get nip ]
 [ too-many-redirects? ] must-fail-with
 
 [ "Goodbye" ] [
-    "http://localhost/quit" add-port http-get nip
+    "http://localhost/quit" add-addr http-get nip
 ] unit-test
 
 ! HTTP client redirect bug
@@ -278,7 +283,7 @@ test-db [
 ] unit-test
 
 [ "Goodbye" ] [
-    "http://localhost/redirect" add-port http-get nip
+    "http://localhost/redirect" add-addr http-get nip
 ] unit-test
 
 
@@ -302,15 +307,20 @@ test-db [
     test-httpd
 ] unit-test
 
-: 404? ( response -- ? ) [ download-failed? ] [ response>> code>> 404 = ] bi and ;
+: 404? ( response -- ? )
+    {
+        [ download-failed? ]
+        [ response>> response? ]
+        [ response>> code>> 404 = ]
+    } 1&& ;
 
 ! This should give a 404 not an infinite redirect loop
-[ "http://localhost/d/blah" add-port http-get nip ] [ 404? ] must-fail-with
+[ "http://localhost/d/blah" add-addr http-get nip ] [ 404? ] must-fail-with
 
 ! This should give a 404 not an infinite redirect loop
-[ "http://localhost/blah/" add-port http-get nip ] [ 404? ] must-fail-with
+[ "http://localhost/blah/" add-addr http-get nip ] [ 404? ] must-fail-with
 
-[ "Goodbye" ] [ "http://localhost/quit" add-port http-get nip ] unit-test
+[ "Goodbye" ] [ "http://localhost/quit" add-addr http-get nip ] unit-test
 
 [ ] [
     <dispatcher>
@@ -324,9 +334,9 @@ test-db [
     test-httpd
 ] unit-test
 
-[ "Hi" ] [ "http://localhost/" add-port http-get nip ] unit-test
+[ "Hi" ] [ "http://localhost/" add-addr http-get nip ] unit-test
 
-[ "Goodbye" ] [ "http://localhost/quit" add-port http-get nip ] unit-test
+[ "Goodbye" ] [ "http://localhost/quit" add-addr http-get nip ] unit-test
 
 USING: html.components html.forms
 xml xml.traversal validators
@@ -356,7 +366,7 @@ SYMBOL: a
     string>xml body>> "input" deep-tag-named "value" attr ;
 
 [ "3" ] [
-    "http://localhost/" add-port http-get
+    "http://localhost/" add-addr http-get
     swap dup cookies>> "cookies" set session-id-key get-cookie
     value>> "session-id" set test-a
 ] unit-test
@@ -364,10 +374,10 @@ SYMBOL: a
 [ "4" ] [
     [
         "4" "a" set
-        "http://localhost" add-port "__u" set
+        "http://localhost" add-addr "__u" set
         "session-id" get session-id-key set
     ] H{ } make-assoc
-    "http://localhost/" add-port <post-request> "cookies" get >>cookies http-request nip test-a
+    "http://localhost/" add-addr <post-request> "cookies" get >>cookies http-request nip test-a
 ] unit-test
 
 [ 4 ] [ a get-global ] unit-test
@@ -376,15 +386,15 @@ SYMBOL: a
 [ "xyz" ] [
     [
         "xyz" "a" set
-        "http://localhost" add-port "__u" set
+        "http://localhost" add-addr "__u" set
         "session-id" get session-id-key set
     ] H{ } make-assoc
-    "http://localhost/" add-port <post-request> "cookies" get >>cookies http-request nip test-a
+    "http://localhost/" add-addr <post-request> "cookies" get >>cookies http-request nip test-a
 ] unit-test
 
 [ 4 ] [ a get-global ] unit-test
 
-[ "Goodbye" ] [ "http://localhost/quit" add-port http-get nip ] unit-test
+[ "Goodbye" ] [ "http://localhost/quit" add-addr http-get nip ] unit-test
 
 ! Test cloning
 [ f ] [ <404> dup clone "b" "a" set-header drop "a" header ] unit-test
@@ -402,7 +412,7 @@ SYMBOL: a
 ] unit-test
 
 [ t ] [
-    "http://localhost/" add-port http-get nip
+    "http://localhost/" add-addr http-get nip
     "vocab:http/test/foo.html" ascii file-contents =
 ] unit-test
 
@@ -424,12 +434,12 @@ SYMBOL: a
     test-httpd
 ] unit-test
 
-[ "OK" ] [ "data" "http://localhost/a" add-port http-post nip ] unit-test
+[ "OK" ] [ "data" "http://localhost/a" add-addr http-post nip ] unit-test
 
 ! Check that download throws errors (reported by Chris Double)
 [
     "resource:temp" [
-        "http://localhost/tweet_my_twat" add-port download
+        "http://localhost/tweet_my_twat" add-addr download
     ] with-directory
 ] must-fail
 
@@ -443,6 +453,6 @@ SYMBOL: a
     test-httpd
 ] unit-test
 
-[ "OK\n\n" ] [ "http://localhost/" add-port http-get nip ] unit-test
+[ "OK\n\n" ] [ "http://localhost/" add-addr http-get nip ] unit-test
 
 [ ] [ stop-test-httpd ] unit-test
index 6eed900accf510da3f9bd46e5ca56b7289562de8..9068b6c7d047bbd6275fc0ef2379aa864efcd3a9 100644 (file)
@@ -1,6 +1,6 @@
-! Copyright (C) 2008 Slava Pestov.
+! Copyright (C) 2008, 2010 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: namespaces assocs kernel io.servers ;
+USING: accessors namespaces assocs kernel io.servers ;
 IN: http.server.remapping
 
 SYMBOL: port-remapping
@@ -9,4 +9,4 @@ SYMBOL: port-remapping
     [ port-remapping get at ] keep or ;
 
 : secure-http-port ( -- n )
-    secure-port remap-port ;
+    secure-addr port>> remap-port ;
index 7da9f6fc09a1a5f126f633c3431ded1a0575a420..227aab21cd66b123ee9e86ad14473112299ef6e0 100644 (file)
@@ -121,16 +121,14 @@ TUPLE: jpeg-color-info
 
 : decode-huff-table ( chunk -- )
     data>> [ binary <byte-reader> ] [ length ] bi limit-stream [
+        [ input-stream get stream>> [ count>> ] [ limit>> ] bi < ]
         [
-            [ input-stream get stream>> [ count>> ] [ limit>> ] bi < ]
-            [
-                read4/4 swap 2 * +
-                16 read
-                dup [ ] [ + ] map-reduce read
-                binary [ [ read [ B{ } ] unless* ] { } map-as ] with-byte-reader
-                swap jpeg> huff-tables>> set-nth
-            ] while
-        ] with-input-stream*
+            read4/4 swap 2 * +
+            16 read
+            dup [ ] [ + ] map-reduce read
+            binary [ [ read [ B{ } ] unless* ] { } map-as ] with-byte-reader
+            swap jpeg> huff-tables>> set-nth
+        ] while
     ] stream-throw-on-eof ;
 
 : decode-scan ( chunk -- )
index 2cf406a941523e2d1e689ff14bf0071c425f9a29..3c1e5b06f786157f86c33392798fded2327d3685 100644 (file)
@@ -1,6 +1,6 @@
 ! Copyright (C) 2004, 2008 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: alien.c-types kernel bit-arrays sequences assocs math
+USING: alien.data kernel bit-arrays sequences assocs math
 namespaces accessors math.order locals fry io.ports
 io.backend.unix io.backend.unix.multiplexers unix unix.ffi
 unix.time ;
index fd9fed0472c1c56dc50e91047b3f5d3c4e768af0..22f0a339a90cb98ed9e215face6af0d63b8ee0c6 100755 (executable)
@@ -1,12 +1,12 @@
 ! Copyright (C) 2004, 2008 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: alien alien.c-types alien.syntax generic assocs kernel
-kernel.private math io.ports sequences strings sbufs threads
-unix unix.ffi vectors io.buffers io.backend io.encodings math.parser
-continuations system libc namespaces make io.timeouts
-io.encodings.utf8 destructors destructors.private accessors
-summary combinators locals unix.time unix.types fry
-io.backend.unix.multiplexers ;
+USING: alien alien.c-types alien.data alien.syntax generic
+assocs kernel kernel.private math io.ports sequences strings
+sbufs threads unix unix.ffi vectors io.buffers io.backend
+io.encodings math.parser continuations system libc namespaces
+make io.timeouts io.encodings.utf8 destructors
+destructors.private accessors summary combinators locals
+unix.time unix.types fry io.backend.unix.multiplexers ;
 QUALIFIED: io
 IN: io.backend.unix
 
@@ -146,7 +146,7 @@ M: stdin dispose*
 
 : wait-for-stdin ( stdin -- size )
     [ control>> CHAR: X over io:stream-write1 io:stream-flush ]
-    [ size>> ssize_t heap-size swap io:stream-read *int ]
+    [ size>> ssize_t heap-size swap io:stream-read int deref ]
     bi ;
 
 :: refill-stdin ( buffer stdin size -- )
@@ -167,11 +167,11 @@ M: stdin refill
 M: stdin cancel-operation
     [ size>> ] [ control>> ] bi [ cancel-operation ] bi@ ;
 
-: control-write-fd ( -- fd ) &: control_write *uint ;
+: control-write-fd ( -- fd ) &: control_write uint deref ;
 
-: size-read-fd ( -- fd ) &: size_read *uint ;
+: size-read-fd ( -- fd ) &: size_read uint deref ;
 
-: data-read-fd ( -- fd ) &: stdin_read *uint ;
+: data-read-fd ( -- fd ) &: stdin_read uint deref ;
 
 : <stdin> ( -- stdin )
     stdin new-disposable
index 3871f9be415753df2aeb2fc5e92ba44297a86399..6370fdb90d04255def2f25d79270c56c507183e0 100644 (file)
@@ -52,7 +52,7 @@ HELP: with-directory-files
 { $examples
     "Print all files in your home directory which are larger than a megabyte:"
     { $code
-        """USING: io.directoies io.files.info io.pathnames ;
+        """USING: io.directories io.files.info io.pathnames ;
 home [
     [
         dup link-info size>> 20 2^ >
index 4f7e0ba212c3b8005e8908c52eda4e9367ccaa47..de61aeaf0bc1541c751a86366fdef2a0eb3572b4 100644 (file)
@@ -64,7 +64,7 @@ HELP: find-by-extension
 }
 { $description "Searches a directory for all files with the given extension. File extension and filenames are converted to lower-case and compared using the " { $link tail? } " word. The file extension should contain the period." }
 { $examples
-    { $unchecked-example
+    { $code
         "USING: io.directories.search ;"
         "\"/\" \".mp3\" find-by-extension"
     }
@@ -77,7 +77,7 @@ HELP: find-by-extensions
 }
 { $description "Searches a directory for all files in the given list of extensions. File extensions and filenames are converted to lower-case and compared using the " { $link tail? } " word. File extensions should contain the period." }
 { $examples
-    { $unchecked-example
+    { $code
         "USING: io.directories.search ;"
         "\"/\" { \".jpg\" \".gif\" \".tiff\" \".png\" \".bmp\" } find-by-extensions"
     }
index 3d69c5f8908b8d874cb7aa3c92bb7e5d39fa844d..3429d5beb2096f15be37a9f0b5248b11011d49ba 100644 (file)
@@ -1,11 +1,11 @@
 ! Copyright (C) 2009 Doug Coleman.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: alien.c-types io.directories.unix kernel system unix
-classes.struct unix.ffi ;
+USING: alien.c-types alien.data io.directories.unix kernel
+system unix classes.struct unix.ffi ;
 IN: io.directories.unix.linux
 
 M: linux find-next-file ( DIR* -- dirent )
     dirent <struct>
-    f <void*>
+    f void* <ref>
     [ [ readdir64_r ] unix-system-call 0 = [ (io-error) ] unless ] 2keep
-    *void* [ drop f ] unless ;
+    void* deref [ drop f ] unless ;
index 0cc8aaa0e43766f2e508eaebd154e4a33fa61a4e..d5dc0ab90575cd3357f5ebddbd05f44fc85d3ffd 100644 (file)
@@ -1,10 +1,11 @@
 ! Copyright (C) 2008 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: accessors alien.c-types alien.strings combinators
-continuations destructors fry io io.backend io.backend.unix
-io.directories io.encodings.binary io.encodings.utf8 io.files
-io.pathnames io.files.types kernel math.bitwise sequences system
-unix unix.stat vocabs.loader classes.struct unix.ffi literals ;
+USING: accessors alien.c-types alien.data alien.strings
+combinators continuations destructors fry io io.backend
+io.backend.unix io.directories io.encodings.binary
+io.encodings.utf8 io.files io.pathnames io.files.types kernel
+math.bitwise sequences system unix unix.stat vocabs.loader
+classes.struct unix.ffi literals ;
 IN: io.directories.unix
 
 CONSTANT: touch-mode flags{ O_WRONLY O_APPEND O_CREAT O_EXCL }
@@ -37,9 +38,9 @@ HOOK: find-next-file os ( DIR* -- byte-array )
 
 M: unix find-next-file ( DIR* -- byte-array )
     dirent <struct>
-    f <void*>
+    f void* <ref>
     [ readdir_r 0 = [ (io-error) ] unless ] 2keep
-    *void* [ drop f ] unless ;
+    void* deref [ drop f ] unless ;
 
 : dirent-type>file-type ( ch -- type )
     {
index ac5f8c23b1119eac1d0017b3c4bfebffc52894a8..d0d4bb7c0575594b1e6e5290a7f2589498175d2d 100644 (file)
@@ -1,10 +1,10 @@
 ! Copyright (C) 2008 Doug Coleman.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: accessors alien.c-types alien.strings combinators
-grouping io.encodings.utf8 io.files kernel math sequences system
-unix io.files.unix arrays unix.statfs.macosx unix.statvfs.macosx
-unix.getfsstat.macosx io.files.info.unix io.files.info
-classes.struct specialized-arrays ;
+USING: accessors alien.c-types alien.data alien.strings
+combinators grouping io.encodings.utf8 io.files kernel math
+sequences system unix io.files.unix arrays unix.statfs.macosx
+unix.statvfs.macosx unix.getfsstat.macosx io.files.info.unix
+io.files.info classes.struct specialized-arrays ;
 SPECIALIZED-ARRAY: uint
 SPECIALIZED-ARRAY: statfs64
 IN: io.files.info.unix.macosx
@@ -13,8 +13,8 @@ TUPLE: macosx-file-system-info < unix-file-system-info
 io-size owner type-id filesystem-subtype ;
 
 M: macosx file-systems ( -- array )
-    f <void*> dup 0 getmntinfo64 dup io-error
-    [ *void* ] dip <direct-statfs64-array>
+    f void* <ref> dup 0 getmntinfo64 dup io-error
+    [ void* deref ] dip <direct-statfs64-array>
     [ f_mntonname>> utf8 alien>string file-system-info ] { } map-as ;
 
 M: macosx new-file-system-info macosx-file-system-info new ;
index 7b98788226bb53dc5dd7550d5f021425a2e2e448..c8fc965eca1e723b66f0e8070f067fd97664fd75 100644 (file)
@@ -2,7 +2,7 @@
 ! See http://factorcode.org/license.txt for BSD license.
 USING: classes help.markup help.syntax io.streams.string
 strings math calendar io.files.info io.files.info.unix ;
-IN: io.files.unix
+IN: io.files.info.unix
 
 HELP: add-file-permissions
 { $values
@@ -102,16 +102,15 @@ HELP: set-file-permissions
      { "path" "a pathname string" } { "n" "an integer, interepreted as a string of bits" } }
 { $description "Sets the file permissions for a given file with the supplied Unix permissions integer. Supplying an octal number with " { $link POSTPONE: OCT: } " is recommended." }
 { $examples "Using the tradidional octal value:"
-    { $unchecked-example "USING: io.files.unix kernel ;"
+    { $code "USING: io.files.info.unix kernel ;"
         "\"resource:license.txt\" OCT: 755 set-file-permissions"
-        ""
     }
     "Higher-level, setting named bits:"
-    { $unchecked-example "USING: io.files.unix kernel math.bitwise ;"
+    { $code "USING: io.files.info.unix kernel literals ;"
     "\"resource:license.txt\""
-    "{ USER-ALL GROUP-READ GROUP-EXECUTE OTHER-READ OTHER-EXECUTE }"
-    "flags set-file-permissions"
-    "" }
+    "flags{ USER-ALL GROUP-READ GROUP-EXECUTE OTHER-READ OTHER-EXECUTE }"
+    "set-file-permissions"
+    }
 } ;
 
 HELP: set-file-times
old mode 100644 (file)
new mode 100755 (executable)
index 024b278..6a83fce
@@ -3,13 +3,13 @@
 USING: accessors alien alien.c-types alien.data alien.strings
 alien.syntax arrays assocs classes.struct combinators
 combinators.short-circuit continuations destructors environment
-io io.backend io.binary io.buffers
-io.encodings.utf16n io.files io.files.private io.files.types
-io.pathnames io.ports io.streams.c io.streams.null io.timeouts
-kernel libc literals locals make math math.bitwise namespaces
-sequences specialized-arrays system
-threads tr windows windows.errors windows.handles
-windows.kernel32 windows.shell32 windows.time windows.types ;
+io io.backend io.binary io.buffers io.encodings.utf16n io.files
+io.files.private io.files.types io.pathnames io.ports
+io.streams.c io.streams.null io.timeouts kernel libc literals
+locals make math math.bitwise namespaces sequences
+specialized-arrays system threads tr windows windows.errors
+windows.handles windows.kernel32 windows.shell32 windows.time
+windows.types ;
 SPECIALIZED-ARRAY: ushort
 IN: io.files.windows
 
@@ -52,7 +52,7 @@ C: <FileArgs> FileArgs
         [ handle>> handle>> ]
         [ buffer>> ]
         [ buffer>> buffer-length ]
-        [ drop DWORD <c-object> ]
+        [ drop 0 DWORD <ref> ]
         [ FileArgs-overlapped ]
     } cleave <FileArgs> ;
     
@@ -131,7 +131,7 @@ M: winnt init-io ( -- )
 ERROR: invalid-file-size n ;
 
 : handle>file-size ( handle -- n )
-    0 <ulonglong> [ GetFileSizeEx win32-error=0/f ] keep *ulonglong ;
+    0 ulonglong <ref> [ GetFileSizeEx win32-error=0/f ] keep ulonglong deref ;
 
 ERROR: seek-before-start n ;
 
@@ -249,7 +249,7 @@ M: winnt init-stdio
     GetLastError ERROR_ALREADY_EXISTS = not ;
 
 : set-file-pointer ( handle length method -- )
-    [ [ handle>> ] dip d>w/w <uint> ] dip SetFilePointer
+    [ [ handle>> ] dip d>w/w uint <ref> ] dip SetFilePointer
     INVALID_SET_FILE_POINTER = [ "SetFilePointer failed" throw ] when ;
 
 M: windows (file-reader) ( path -- stream )
@@ -350,4 +350,4 @@ M: winnt home
         [ "HOMEDRIVE" os-env "HOMEPATH" os-env append-path ]
         [ "USERPROFILE" os-env ]
         [ my-documents ]
-    } 0|| ;
\ No newline at end of file
+    } 0|| ;
index cf74113506e6f2dc300a1e7e1253d8f3d165fc25..6f48cfcdc8275f4674ee9eb0fb8eefaad7331aa2 100644 (file)
@@ -128,7 +128,7 @@ HELP: kill-process
 HELP: kill-process*
 { $values { "handle" "a process handle" } }
 { $contract "Kills a running process." }
-{ $notes "User code should call " { $link kill-process } " intead." } ;
+{ $notes "User code should call " { $link kill-process } " instead." } ;
 
 HELP: process
 { $class-description "A class representing a process. Instances are created by calling " { $link <process> } "." } ;
index 0b58df2e43603fb1777e8a90a18827a8b0831195..4a84064c33b4fb3bcb140e3752b4fc845e9770e5 100755 (executable)
@@ -180,12 +180,12 @@ M: windows wait-for-processes ( -- ? )
     GetCurrentProcess ! source process
     swap handle>> ! handle
     GetCurrentProcess ! target process
-    f <void*> [ ! target handle
+    f void* <ref> [ ! target handle
         DUPLICATE_SAME_ACCESS ! desired access
         TRUE ! inherit handle
         0 ! options
         DuplicateHandle win32-error=0/f
-    ] keep *void* <win32-handle> &dispose ;
+    ] keep void* deref <win32-handle> &dispose ;
 
 ! /dev/null simulation
 : null-input ( -- pipe )
index d99bebbdc3baed7cbaf9691f0c2d5bae628414dd..7418eb0a196e48b5a6d42a6f9aa6d0c98fb39338 100644 (file)
@@ -12,7 +12,7 @@ HELP: mapped-file
 } ;
 
 HELP: <mapped-file>
-{ $values { "path" "a pathname string" }  { "mmap" mapped-file } }
+{ $values { "path" "a pathname string" } { "mmap" mapped-file } }
 { $contract "Opens a file and maps its contents into memory. The length is permitted to exceed the length of the file on disk, in which case the remaining space is padded with zero bytes." }
 { $notes "You must call " { $link dispose } " when you are finished working with the returned object, to reclaim resources. The " { $link with-mapped-file } " provides an abstraction which can close the mapped file for you." }
 { $errors "Throws an error if a memory mapping could not be established." } ;
@@ -35,7 +35,7 @@ HELP: close-mapped-file
 { $errors "Throws an error if a memory mapping could not be established." } ;
 
 HELP: <mapped-file-reader>
-{ $values { "path" "a pathname string" }  { "mmap" mapped-file } }
+{ $values { "path" "a pathname string" } { "mmap" mapped-file } }
 { $contract "Opens a file for reading only and maps its contents into memory. The length is permitted to exceed the length of the file on disk, in which case the remaining space is padded with zero bytes." }
 { $notes "You must call " { $link dispose } " when you are finished working with the returned object, to reclaim resources. The " { $link with-mapped-file } " provides an abstraction which can close the mapped file for you." }
 { $errors "Throws an error if a memory mapping could not be established." } ;
index 8887d718d11059b78d49dc8e64560ac8f0fdcbfb..43b3ac7ef4dcbf4479d6aa722c9745b94a5a7b62 100644 (file)
@@ -32,7 +32,7 @@ TUPLE: win32-monitor < monitor port ;
         [ recursive>> 1 0 ? ]
     } cleave
     FILE_NOTIFY_CHANGE_ALL
-    0 <uint>
+    0 uint <ref>
     (make-overlapped)
     [ f ReadDirectoryChangesW win32-error=0/f ] keep ;
 
index 051dfad9757ca152ddf1dbe0190d5a2bb078d7ba..a054a836dea0240a14d8c06abb9256bbc64c2905 100644 (file)
@@ -76,8 +76,8 @@ ARTICLE: "io.servers" "Threaded servers"
 "From within the dynamic scope of a client handler, several words can be used to interact with the threaded server:"
 { $subsections
     stop-this-server
-    secure-port
-    insecure-port
+    secure-addr
+    insecure-addr
 }
 "Additionally, the " { $link local-address } " and "
 { $subsections remote-address } " variables are set, as in " { $link with-client } "." ;
@@ -125,12 +125,12 @@ HELP: with-threaded-server
 }
 { $description "Runs a server and calls a quotation, stopping the server once the quotation returns." } ;
 
-HELP: secure-port
-{ $values { "n/f" { $maybe integer } } }
+HELP: secure-addr
+{ $values { "addrspec" "an addrspec" } }
 { $description "Outputs one of the port numbers on which the current threaded server accepts secure socket connections. Outputs " { $link f } " if the current threaded server does not accept secure socket connections." }
 { $notes "Can only be used from the dynamic scope of a " { $link handle-client* } " call." } ;
 
-HELP: insecure-port
-{ $values { "n/f" { $maybe integer } } }
+HELP: insecure-addr
+{ $values { "addrspec" "an addrspec" } }
 { $description "Outputs one of the port numbers on which the current threaded server accepts ordinary socket connections. Outputs " { $link f } " if the current threaded server does not accept ordinary socket connections." }
 { $notes "Can only be used from the dynamic scope of a " { $link handle-client* } " call." } ;
index bcba7f7d9083e4ff62d56e954e49400c3c8c8325..e081b655d3891011e18437b5dfa19ba6b16ae18d 100644 (file)
@@ -34,7 +34,7 @@ IN: io.servers
         0 >>insecure
         [ "Hello world." write stop-this-server ] >>handler
     [
-        "localhost" insecure-port <inet> ascii <client> drop stream-contents
+        insecure-addr ascii <client> drop stream-contents
     ] with-threaded-server
 ] unit-test
 
old mode 100644 (file)
new mode 100755 (executable)
index 66d0112..5eee753
@@ -86,7 +86,9 @@ M: f >insecure ;
     [ dup secure? [ <secure> ] unless ] map ;
 
 : listen-on ( threaded-server -- addrspecs )
-    [ secure>> >secure ] [ insecure>> >insecure ] bi append
+    [ secure>> ssl-supported? [ >secure ] [ drop { } ] if ]
+    [ insecure>> >insecure ]
+    bi append
     [ resolve-host ] map concat ;
 
 : accepted-connection ( remote local -- )
@@ -141,7 +143,7 @@ M: threaded-server handle-client* handler>> call( -- ) ;
 \ start-accept-loop NOTICE add-error-logging
 
 : create-secure-context ( threaded-server -- threaded-server )
-    dup secure>> [
+    dup secure>> ssl-supported? and [
         dup secure-config>> <secure-context> >>secure-context
     ] when ;
 
@@ -162,7 +164,8 @@ ERROR: no-ports-configured threaded-server ;
 
 : set-servers ( threaded-server -- threaded-server )
     dup [
-        dup dup listen-on [ no-ports-configured ] [ (make-servers) ] if-empty
+        dup dup listen-on
+        [ no-ports-configured ] [ (make-servers) ] if-empty
         >>servers
     ] with-existing-secure-context ;
 
@@ -221,21 +224,26 @@ PRIVATE>
 
 <PRIVATE
 
-: first-port ( quot -- n/f )
-    [ threaded-server get servers>> ] dip
-    filter [ f ] [ first addr>> port>> ] if-empty ; inline
+GENERIC: connect-addr ( addrspec -- addrspec )
 
-PRIVATE>
+M: inet4 connect-addr [ "127.0.0.1" ] dip port>> <inet4> ;
+
+M: inet6 connect-addr [ "::1" ] dip port>> <inet6> ;
+
+M: secure connect-addr addrspec>> connect-addr <secure> ;
 
-: secure-port ( -- n/f ) [ addr>> secure? ] first-port ;
+M: local connect-addr ;
+
+PRIVATE>
 
-: insecure-port ( -- n/f ) [ addr>> secure? not ] first-port ;
+: server-addrs ( -- addrspecs )
+    threaded-server get servers>> [ addr>> connect-addr ] map ;
 
-: secure-addr ( -- inet )
-    threaded-server get servers>> [ addr>> secure? ] filter random ;
+: secure-addr ( -- addrspec )
+    server-addrs [ secure? ] filter random ;
 
-: insecure-addr ( -- inet )
-    threaded-server get servers>> [ addr>> secure? not ] filter random addr>> ;
+: insecure-addr ( -- addrspec )
+    server-addrs [ secure? not ] filter random ;
     
 : server. ( threaded-server -- )
     [ [ "=== " write name>> ] [ ] bi write-object nl ]
index fbbea7c4c310ccf3158d2ae5695638ff56494a79..92403a58cb9d1682db45f4c756a069d3d972ee45 100644 (file)
@@ -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: accessors kernel namespaces continuations destructors io
 debugger io.sockets io.sockets.private sequences summary
@@ -11,6 +11,10 @@ SYMBOL: secure-socket-timeout
 
 SYMBOL: secure-socket-backend
 
+HOOK: ssl-supported? secure-socket-backend ( -- ? )
+
+M: object ssl-supported? f ;
+
 SINGLETONS: SSLv2 SSLv23 SSLv3 TLSv1 ;
 
 TUPLE: secure-config
index 8fe9facc0c49fd1f2b1cbe57d795fc56e9eeeef0..c856ef2bc8016bf95a9be85b2042965bc415fab9 100644 (file)
@@ -1,4 +1,4 @@
-! Copyright (C) 2007, 2008, Slava Pestov, Elie CHAFTARI.
+! Copyright (C) 2007, 2010, Slava Pestov, Elie CHAFTARI.
 ! See http://factorcode.org/license.txt for BSD license.
 USING: accessors unix byte-arrays kernel sequences namespaces
 math math.order combinators init alien alien.c-types
@@ -11,6 +11,8 @@ unix.ffi ;
 FROM: io.ports => shutdown ;
 IN: io.sockets.secure.unix
 
+M: openssl ssl-supported? t ;
+
 M: ssl-handle handle-fd file>> handle-fd ;
 
 : syscall-error ( r -- * )
index 95ad57a46da693c8d47ea3e4c82655723f4e132f..afd0ae1c4455a40be7aa5f48ed6b0c3b9153cf4a 100644 (file)
@@ -118,10 +118,10 @@ HELP: inet
 
 HELP: <inet>
 { $values { "host" "a host name" } { "port" "a port number" } { "inet" inet } }
-{ $description "Creates a new " { $link inet } " address specifier." } ;
+{ $description "Creates a new " { $link inet } " address specifier. If the host is an IPv4 address, an " { $link inet4 } " tuple will be returned; likewise for " { $link inet6 } "." } ;
 
 HELP: inet4
-{ $class-description "IPv4 address/port number specifier for TCP/IP and UDP/IP connections. The " { $snippet "host" } " and " { $snippet "port" } " slots hold the IPv4 address and port number, respectively. New instances are created by calling " { $link <inet4> } "." }
+{ $class-description "IPv4 address/port number specifier for TCP/IP and UDP/IP connections. The " { $snippet "host" } " and " { $snippet "port" } " slots hold the IPv4 address and port number, respectively. New instances are created by calling " { $link <inet4> } ". A host of " { $link f } " refers to localhost, and a port of " { $link f } " defers the port choice until later." }
 { $notes "Most applications do not operate on IPv4 addresses directly, and instead should use the " { $link inet } " address specifier, or call " { $link resolve-host } "." }
 { $examples
     { $code "\"127.0.0.1\" 8080 <inet4>" }
@@ -129,10 +129,10 @@ HELP: inet4
 
 HELP: <inet4>
 { $values { "host" "an IPv4 address" } { "port" "a port number" } { "inet4" inet4 } }
-{ $description "Creates a new " { $link inet4 } " address specifier." } ;
+{ $description "Creates a new " { $link inet4 } " address specifier. A value of " { $link f } " as the host refers to localhost, while " { $link f } " as the port defers the port choice until a later time." } ;
 
 HELP: inet6
-{ $class-description "IPv6 address/port number specifier for TCP/IP and UDP/IP connections. The " { $snippet "host" } " and " { $snippet "port" } " slots hold the IPv6 address and port number, respectively. New instances are created by calling " { $link <inet6> } "." }
+{ $class-description "IPv6 address/port number specifier for TCP/IP and UDP/IP connections. The " { $snippet "host" } " and " { $snippet "port" } " slots hold the IPv6 address and port number, respectively. New instances are created by calling " { $link <inet6> } ". A host of " { $link f } " refers to localhost, and a port of " { $link f } " defers the port choice until later." }
 { $notes "Most applications do not operate on IPv6 addresses directly, and instead should use the " { $link inet } " address specifier, or call " { $link resolve-host } "." }
 { $examples
     { $code "\"::1\" 8080 <inet6>" }
@@ -140,7 +140,7 @@ HELP: inet6
 
 HELP: <inet6>
 { $values { "host" "an IPv6 address" } { "port" "a port number" } { "inet6" inet6 } }
-{ $description "Creates a new " { $link inet6 } " address specifier." } ;
+{ $description "Creates a new " { $link inet6 } " address specifier. A value of " { $link f } " as the host refers to localhost, while " { $link f } " as the port defers the port choice until a later time." } ;
 
 HELP: <client>
 { $values { "remote" "an address specifier" } { "encoding" "an encding descriptor" } { "stream" "a bidirectional stream" } { "local" "an address specifier" } }
index 56939f484f406cac146b26a20fdec386a688a150..d6015127532ebb91b7fd7c14daa8bffbd4982643 100644 (file)
@@ -1,8 +1,21 @@
-IN: io.sockets.tests
 USING: io.sockets io.sockets.private sequences math tools.test
 namespaces accessors kernel destructors calendar io.timeouts
 io.encodings.utf8 io concurrency.promises threads
 io.streams.string ;
+IN: io.sockets.tests
+
+[ T{ inet4 f f 0 } ] [ f 0 <inet4> ] unit-test
+[ T{ inet6 f f 0 } ] [ f 0 <inet6> ] unit-test
+
+[ T{ inet f "google.com" f } ] [ "google.com" f <inet> ] unit-test
+
+[ T{ inet f "google.com" 0 } ] [ "google.com" 0 <inet> ] unit-test
+[ T{ inet f "google.com" 80 } ] [ "google.com" 0 <inet> 80 with-port ] unit-test
+[ T{ inet4 f "8.8.8.8" 0 } ] [ "8.8.8.8" 0 <inet4> ] unit-test
+[ T{ inet4 f "8.8.8.8" 53 } ] [ "8.8.8.8" 0 <inet4> 53 with-port ] unit-test
+[ T{ inet6 f "5:5:5:5:6:6:6:6" 12 } ] [ "5:5:5:5:6:6:6:6" 0 <inet6> 12 with-port ] unit-test
+
+[ T{ inet f "google.com" 80 } ] [ "google.com" 80 with-port ] unit-test
 
 [ B{ 1 2 3 4 } ]
 [ "1.2.3.4" T{ inet4 } inet-pton ] unit-test
@@ -132,3 +145,4 @@ io.streams.string ;
 
 ! Binding to all interfaces should work
 [ ] [ f 0 <inet4> <datagram> dispose ] unit-test
+[ ] [ f 0 <inet6> <datagram> dispose ] unit-test
index a48e6ffc95963b0211c9e421bb67a2a700882a50..fcdc00d1279e4bc2682c17b3a930bd0edb3b7f77 100644 (file)
@@ -16,6 +16,8 @@ IN: io.sockets
     { [ os unix? ] [ "unix.ffi" ] }
 } cond use-vocab >>
 
+GENERIC# with-port 1 ( addrspec port -- addrspec )
+
 ! Addressing
 <PRIVATE
 
@@ -37,8 +39,6 @@ GENERIC: inet-ntop ( data addrspec -- str )
 
 GENERIC: inet-pton ( str addrspec -- data )
 
-GENERIC# with-port 1 ( addrspec port -- addrspec )
-
 : make-sockaddr/size ( addrspec -- sockaddr size )
     [ make-sockaddr ] [ sockaddr-size ] bi ;
 
@@ -106,10 +106,10 @@ M: ipv4 make-sockaddr ( inet -- sockaddr )
         swap
         [ port>> htons >>port ]
         [ host>> "0.0.0.0" or ]
-        [ inet-pton *uint >>addr ] tri ;
+        [ inet-pton uint deref >>addr ] tri ;
 
 M: ipv4 parse-sockaddr ( sockaddr-in addrspec -- newaddrspec )
-    [ addr>> <uint> ] dip inet-ntop <ipv4> ;
+    [ addr>> uint <ref> ] dip inet-ntop <ipv4> ;
 
 TUPLE: inet4 < ipv4 { port integer read-only } ;
 
@@ -368,13 +368,18 @@ M: inet present
 C: <inet> inet
 
 M: string resolve-host
-    f prepare-addrinfo f <void*>
-    [ getaddrinfo addrinfo-error ] keep *void* addrinfo memory>struct
+    f prepare-addrinfo f void* <ref>
+    [ getaddrinfo addrinfo-error ] keep void* deref addrinfo memory>struct
     [ parse-addrinfo-list ] keep freeaddrinfo ;
 
+M: string with-port <inet> ;
+
 M: hostname resolve-host
     host>> resolve-host ;
 
+M: hostname with-port
+    [ host>> ] dip <inet> ;
+
 M: inet resolve-host
     [ call-next-method ] [ port>> ] bi '[ _ with-port ] map ;
 
index 4d6c6992113ac758b84a6da8fd7201dc894b8ceb..3f91c0e8b6e1afe3f152170f0f872720258a810a 100644 (file)
@@ -16,7 +16,7 @@ IN: io.sockets.unix
     socket dup io-error <fd> init-fd |dispose ;
 
 : set-socket-option ( fd level opt -- )
-    [ handle-fd ] 2dip 1 <int> dup byte-length setsockopt io-error ;
+    [ handle-fd ] 2dip 1 int <ref> dup byte-length setsockopt io-error ;
 
 M: unix addrinfo-error ( n -- )
     [ gai_strerror throw ] unless-zero ;
@@ -39,11 +39,11 @@ M: unix addrspec-of-family ( af -- addrspec )
 
 ! Client sockets - TCP and Unix domain
 M: object (get-local-address) ( handle remote -- sockaddr )
-    [ handle-fd ] dip empty-sockaddr/size <int>
+    [ handle-fd ] dip empty-sockaddr/size int <ref>
     [ getsockname io-error ] 2keep drop ;
 
 M: object (get-remote-address) ( handle local -- sockaddr )
-    [ handle-fd ] dip empty-sockaddr/size <int>
+    [ handle-fd ] dip empty-sockaddr/size int <ref>
     [ getpeername io-error ] 2keep drop ;
 
 : init-client-socket ( fd -- )
@@ -101,7 +101,7 @@ M: object (server) ( addrspec -- handle )
     ] with-destructors ;
 
 : do-accept ( server addrspec -- fd sockaddr )
-    [ handle>> handle-fd ] [ empty-sockaddr/size <int> ] bi*
+    [ handle>> handle-fd ] [ empty-sockaddr/size int <ref> ] bi*
     [ accept ] 2keep drop ; inline
 
 M: object (accept) ( server addrspec -- fd sockaddr )
@@ -138,7 +138,7 @@ CONSTANT: packet-size 65536
     packet-size ! nbytes
     0 ! flags
     sockaddr ! from
-    len <int> ! fromlen
+    len int <ref> ! fromlen
     recvfrom dup 0 >=
     [ receive-buffer get-global swap memory>byte-array sockaddr ]
     [ drop f f ]
index 157aa5c848b295f5c35774708dfae3fabd668910..aea801615650313318eb388b57efdc7ad25d92fc 100755 (executable)
@@ -48,11 +48,11 @@ M: win32-socket dispose* ( stream -- )
     opened-socket ;\r
 \r
 M: object (get-local-address) ( socket addrspec -- sockaddr )\r
-    [ handle>> ] dip empty-sockaddr/size <int>\r
+    [ handle>> ] dip empty-sockaddr/size int <ref>\r
     [ getsockname socket-error ] 2keep drop ;\r
 \r
 M: object (get-remote-address) ( socket addrspec -- sockaddr )\r
-    [ handle>> ] dip empty-sockaddr/size <int>\r
+    [ handle>> ] dip empty-sockaddr/size int <ref>\r
     [ getpeername socket-error ] 2keep drop ;\r
 \r
 : bind-socket ( win32-socket sockaddr len -- )\r
@@ -87,7 +87,7 @@ M: windows (raw) ( addrspec -- handle )
     [ SOCK_RAW server-socket ] with-destructors ;\r
 \r
 : malloc-int ( n -- alien )\r
-    <int> malloc-byte-array ; inline\r
+    int <ref> malloc-byte-array ; inline\r
 \r
 M: winnt WSASocket-flags ( -- DWORD )\r
     WSA_FLAG_OVERLAPPED ;\r
@@ -99,7 +99,7 @@ M: winnt WSASocket-flags ( -- DWORD )
     { void* }\r
     [\r
         void* heap-size\r
-        DWORD <c-object>\r
+        0 DWORD <ref>\r
         f\r
         f\r
         WSAIoctl SOCKET_ERROR = [\r
@@ -181,7 +181,8 @@ TUPLE: AcceptEx-args port
     } cleave AcceptEx drop winsock-error ; inline\r
 \r
 : (extract-remote-address) ( lpOutputBuffer dwReceiveDataLength dwLocalAddressLength dwRemoteAddressLength -- sockaddr )\r
-    f <void*> 0 <int> f <void*> [ 0 <int> GetAcceptExSockaddrs ] keep *void* ;\r
+    f void* <ref> 0 int <ref> f void* <ref>\r
+    [ 0 int <ref> GetAcceptExSockaddrs ] keep void* deref ;\r
 \r
 : extract-remote-address ( AcceptEx -- sockaddr )\r
     [\r
@@ -246,7 +247,7 @@ TUPLE: WSARecvFrom-args port
     [\r
         [ port>> addr>> empty-sockaddr dup ]\r
         [ lpFrom>> ]\r
-        [ lpFromLen>> *int ]\r
+        [ lpFromLen>> int deref ]\r
         tri memcpy\r
     ] bi ; inline\r
 \r
@@ -278,7 +279,7 @@ TUPLE: WSASendTo-args port
         swap make-send-buffer >>lpBuffers\r
         1 >>dwBufferCount\r
         0 >>dwFlags\r
-        0 <uint> >>lpNumberOfBytesSent\r
+        0 uint <ref> >>lpNumberOfBytesSent\r
         (make-overlapped) >>lpOverlapped ; inline\r
 \r
 : call-WSASendTo ( WSASendTo -- )\r
index 7750db8f1d46466b9bf4d3860d81c964a6a823de..98338639bb6f03a166ba65dc1fb79b2f36d453ba 100644 (file)
@@ -61,6 +61,7 @@ $nl
 "The " { $snippet "style" } " hashtable holds table style information. See " { $link "table-styles" } "." }
 { $examples
     { $code
+        "USING: io.styles prettyprint sequences ;"
         "{ { 1 2 } { 3 4 } }"
         "H{ { table-gap { 10 10 } } } ["
         "    [ [ [ [ . ] with-cell ] each ] with-row ] each"
@@ -201,12 +202,13 @@ HELP: bold-italic
 { $description "A value for the " { $link font-style } " character style denoting boldface italicized text." } ;
 
 HELP: foreground
-{ $description "Character style. An instance of " { $link color } ". See " { $link "colors" } "." } 
+{ $description "Character style. An instance of " { $link color } ". See " { $link "colors" } "." }
 { $examples
     { $code
+        "USING: colors.gray io.styles hashtables sequences kernel math ;"
         "10 iota ["
-            "    \"Hello world\\n\""
-            "    swap 10 / 1 <gray> foreground associate format"
+        "    \"Hello world\\n\""
+        "    swap 10 / 1 <gray> foreground associate format"
         "] each"
     }
 } ;
@@ -215,10 +217,11 @@ HELP: background
 { $description "Character style. An instance of " { $link color } ". See " { $link "colors" } "." }
 { $examples
     { $code
+        "USING: colors hashtables io io.styles kernel math sequences ;"
         "10 iota ["
-            "    \"Hello world\\n\""
-            "    swap 10 / 1 over - over 1 <rgba>"
-            "    background associate format nl"
+        "    \"Hello world\\n\""
+        "    swap 10 / 1 over - over 1 <rgba>"
+        "    background associate format nl"
         "] each"
     }
 } ;
@@ -227,14 +230,20 @@ HELP: font-name
 { $description "Character style. Font family named by a string." }
 { $examples
     "This example outputs some different font sizes:"
-    { $code "{ \"monospace\" \"serif\" \"sans-serif\" }\n[ dup font-name associate format nl ] each" }
+    { $code
+        "USING: hashtables io io.styles kernel sequences ;"
+        "{ \"monospace\" \"serif\" \"sans-serif\" }"
+        "[ dup font-name associate format nl ] each"
+    }
 } ;
 
 HELP: font-size
 { $description "Character style. Font size, an integer." }
 { $examples
     "This example outputs some different font sizes:"
-    { $code "{ 12 18 24 72 }"
+    { $code
+        "USING: hashtables io io.styles kernel sequences ;"
+        "{ 12 18 24 72 }"
         "[ \"Bigger\" swap font-size associate format nl ] each"
     }
 }  ;
@@ -243,28 +252,44 @@ HELP: font-style
 { $description "Character style. Font style, one of " { $link plain } ", " { $link bold } ", " { $link italic } ", or " { $link bold-italic } "." }
 { $examples
     "This example outputs text in all three styles:"
-    { $code "{ plain bold italic bold-italic }\n[ [ name>> ] keep font-style associate format nl ] each" }
+    { $code
+        "USING: accessors hashtables io io.styles kernel sequences ;"
+        "{ plain bold italic bold-italic }"
+        "[ [ name>> ] keep font-style associate format nl ] each"
+    }
 }  ;
 
 HELP: presented
 { $description "Character and paragraph style. An object associated with the text. In the Factor UI, this is shown as a clickable presentation of the object; left-clicking invokes a default command, and right-clicking shows a menu of commands." } ;
 
 HELP: page-color
-{ $description "Paragraph style. An instance of " { $link color } ". See " { $link "colors" } "." } 
+{ $description "Paragraph style. An instance of " { $link color } ". See " { $link "colors" } "." }
 { $examples
-    { $code "H{ { page-color T{ rgba f 1 0.8 0.5 1 } } }\n[ \"A background\" write ] with-nesting nl" }
+    { $code
+        "USING: colors io io.styles ;"
+        "H{ { page-color T{ rgba f 1 0.8 0.5 1 } } }"
+        "[ \"A background\" write ] with-nesting nl"
+    }
 } ;
 
 HELP: border-color
 { $description "Paragraph style. An instance of " { $link color } ". See " { $link "colors" } "." }
 { $examples
-    { $code "H{ { border-color T{ rgba f 1 0 0 1 } } }\n[ \"A border\" write ] with-nesting nl" }
+    { $code
+        "USING: colors io io.styles ;"
+        "H{ { border-color T{ rgba f 1 0 0 1 } } }"
+        "[ \"A border\" write ] with-nesting nl"
+    }
 } ;
 
 HELP: inset
-{ $description "Paragraph style. A pair of integers representing the number of pixels that the content should be inset from the border. The first number is the horizontal inset, and the second is the vertical inset." } 
+{ $description "Paragraph style. A pair of integers representing the number of pixels that the content should be inset from the border. The first number is the horizontal inset, and the second is the vertical inset." }
 { $examples
-    { $code "H{ { inset { 10 10 } } }\n[ \"Some inset text\" write ] with-nesting nl" }
+    { $code
+        "USING: io io.styles ;"
+        "H{ { inset { 10 10 } } }"
+        "[ \"Some inset text\" write ] with-nesting nl"
+    }
 } ;
 
 HELP: wrap-margin
@@ -284,7 +309,10 @@ HELP: input
 { $class-description "Class of input text presentations. Instances can be used passed to " { $link write-object } " to output a clickable piece of input. Input text presentations are created by calling " { $link <input> } "." }
 { $examples
     "This presentation class is used for the code examples you see in the online help:"
-    { $code "\"2 3 + .\" dup <input> write-object nl" }
+    { $code
+        "USING: io io.styles kernel ;"
+        "\"2 3 + .\" dup <input> write-object nl"
+    }
 } ;
 
 HELP: <input>
@@ -302,4 +330,4 @@ ARTICLE: "io.streams.plain" "Plain writer streams"
 { $link make-span-stream } ", "
 { $link make-block-stream } " and "
 { $link make-cell-stream } "."
-{ $subsections plain-writer } ;
\ No newline at end of file
+{ $subsections plain-writer } ;
index 4dc493222289aa2ed01b19bc0374ccb6a0b0bb45..c9de6f80355d756d7f94ce52f8498bf1e6a5396a 100644 (file)
@@ -156,9 +156,9 @@ TUPLE: mach-error error-code error-string ;
     io-objects-from-iterator* [ release-io-object ] dip ;
     
 : properties-from-io-object ( o -- o nsdictionary )
-    dup f <void*> [
+    dup f void* <ref> [
         kCFAllocatorDefault kNilOptions
         IORegistryEntryCreateCFProperties mach-error
     ]
-    keep *void* ;
+    keep void* deref ;
 
index 6fcf8a5e07c807970d6b510e9fef5704f0c68384..52aa1cd717742fc0c3b614bd0a75d01047488163 100644 (file)
@@ -8,23 +8,22 @@ HELP: $
 { $description "Executes " { $snippet "word" } " at parse time and adds the result(s) to the parser accumulator." }
 { $notes { $snippet "word" } "'s definition is looked up and " { $link call } "ed at parse time, so words that reference words in the current compilation unit cannot be used with " { $snippet "$" } "." }
 { $examples
-
-    { $example """
-USING: kernel literals prettyprint ;
-IN: scratchpad
-
-CONSTANT: five 5
-{ $ five } .
-    """ "{ 5 }" }
-
-    { $example """
-USING: kernel literals prettyprint ;
-IN: scratchpad
-
-: seven-eleven ( -- a b ) 7 11 ;
-{ $ seven-eleven } .
-    """ "{ 7 11 }" }
-
+    { $example
+        "USING: kernel literals prettyprint ;"
+        "IN: scratchpad"
+        ""
+        "CONSTANT: five 5"
+        "{ $ five } ."
+        "{ 5 }"
+    }
+    { $example
+        "USING: kernel literals prettyprint ;"
+        "IN: scratchpad"
+        ""
+        ": seven-eleven ( -- a b ) 7 11 ;"
+        "{ $ seven-eleven } ."
+        "{ 7 11 }"
+    }
 } ;
 
 HELP: $[
@@ -32,15 +31,14 @@ HELP: $[
 { $description "Calls " { $snippet "code" } " at parse time and adds the result(s) to the parser accumulator." }
 { $notes "Since " { $snippet "code" } " is " { $link call } "ed at parse time, it cannot reference any words defined in the same compilation unit." }
 { $examples
-
-    { $example """
-USING: kernel literals math prettyprint ;
-IN: scratchpad
-
-<< CONSTANT: five 5 >>
-{ $[ five dup 1 + dup 2 + ] } .
-    """ "{ 5 6 8 }" }
-
+    { $example
+        "USING: kernel literals math prettyprint ;"
+        "IN: scratchpad"
+        ""
+        "<< CONSTANT: five 5 >>"
+        "{ $[ five dup 1 + dup 2 + ] } ."
+        "{ 5 6 8 }"
+    }
 } ;
 
 HELP: ${
@@ -48,15 +46,14 @@ HELP: ${
 { $description "Outputs an array containing the results of executing " { $snippet "code" } " at parse time." }
 { $notes { $snippet "code" } "'s definition is looked up and " { $link call } "ed at parse time, so words that reference words in the current compilation unit cannot be used with " { $snippet "$" } "." }
 { $examples
-
-    { $example """
-USING: kernel literals math prettyprint ;
-IN: scratchpad
-
-CONSTANT: five 5
-CONSTANT: six 6
-${ five six 7 } .
-    """ "{ 5 6 7 }"
+    { $example
+        "USING: kernel literals math prettyprint ;"
+        "IN: scratchpad"
+        ""
+        "CONSTANT: five 5"
+        "CONSTANT: six 6"
+        "${ five six 7 } ."
+        "{ 5 6 7 }"
     }
 } ;
 
@@ -66,7 +63,8 @@ HELP: flags{
 { $values { "values" sequence } }
 { $description "Constructs a constant flag value from a sequence of integers or words that output integers. The resulting constant is computed at parse-time, which makes this word as efficient as using a literal integer." }
 { $examples
-    { $example "USING: literals kernel prettyprint ;"
+    { $example
+        "USING: literals kernel prettyprint ;"
         "IN: scratchpad"
         "CONSTANT: x HEX: 1"
         "flags{ HEX: 20 x BIN: 100 } .h"
@@ -77,13 +75,14 @@ HELP: flags{
 
 ARTICLE: "literals" "Interpolating code results into literal values"
 "The " { $vocab-link "literals" } " vocabulary contains words to run code at parse time and insert the results into more complex literal values."
-{ $example """
-USE: literals
-IN: scratchpad
-
-CONSTANT: five 5
-{ $ five $[ five dup 1 + dup 2 + ] } .
-    """ "{ 5 5 6 8 }" }
+{ $example
+    "USING: kernel literals math prettyprint ;"
+    "IN: scratchpad"
+    ""
+    "<< CONSTANT: five 5 >>"
+    "{ $ five $[ five dup 1 + dup 2 + ] } ."
+    "{ 5 5 6 8 }"
+}
 { $subsections
     POSTPONE: $
     POSTPONE: $[
index eb8a2eaf76b77c63a5113a7754a8a09478fdb07f..786aa77c52faeae180841cd8640b3944b08b389d 100644 (file)
@@ -1,8 +1,8 @@
-! Copyright (C) 2008 Slava Pestov.\r
+! Copyright (C) 2008, 2010 Slava Pestov.\r
 ! See http://factorcode.org/license.txt for BSD license.\r
 USING: kernel sequences namespaces words assocs logging sorting\r
 prettyprint io io.styles io.files io.encodings.utf8\r
-strings combinators accessors arrays\r
+strings combinators accessors arrays math\r
 logging.server logging.parser calendar.format ;\r
 IN: logging.analysis\r
 \r
@@ -20,6 +20,9 @@ SYMBOL: message-histogram
     ] when\r
     drop ;\r
 \r
+: recent-histogram ( assoc n -- alist )\r
+    [ >alist sort-values <reversed> ] dip short head ;\r
+\r
 : analyze-entries ( entries word-names -- errors word-histogram message-histogram )\r
     [\r
         word-names set\r
@@ -27,44 +30,40 @@ SYMBOL: message-histogram
         H{ } clone word-histogram set\r
         H{ } clone message-histogram set\r
 \r
-        [\r
-            analyze-entry\r
-        ] each\r
+        [ analyze-entry ] each\r
 \r
         errors get\r
-        word-histogram get\r
-        message-histogram get\r
+        word-histogram get 10 recent-histogram\r
+        message-histogram get 10 recent-histogram\r
     ] with-scope ;\r
 \r
 : histogram. ( assoc quot -- )\r
     standard-table-style [\r
-        [ >alist sort-values <reversed> ] dip [\r
+        [\r
             [ swapd with-cell pprint-cell ] with-row\r
         ] curry assoc-each\r
     ] tabular-output ; inline\r
 \r
-: log-entry. ( entry -- )\r
-    "====== " write\r
-    {\r
-        [ date>> (timestamp>string) bl ]\r
-        [ level>> pprint bl ]\r
-        [ word-name>> write nl ]\r
-        [ message>> "\n" join print ]\r
-    } cleave ;\r
+: 10-most-recent ( errors -- errors )\r
+    10 tail* "Only showing 10 most recent errors" print nl ;\r
 \r
 : errors. ( errors -- )\r
-    [ log-entry. ] each ;\r
+    dup length 10 >= [ 10-most-recent ] when\r
+    log-entries. ;\r
 \r
 : analysis. ( errors word-histogram message-histogram -- )\r
-    "==== INTERESTING MESSAGES:" print nl\r
+    nl "==== FREQUENT MESSAGES:" print nl\r
     "Total: " write dup values sum . nl\r
     [\r
-        dup level>> write ": " write message>> "\n" join write\r
+        [ first name>> write bl ]\r
+        [ second write ": " write ]\r
+        [ third "\n" join write ]\r
+        tri\r
     ] histogram.\r
-    nl\r
-    "==== WORDS:" print nl\r
+    nl nl\r
+    "==== FREQUENT WORDS:" print nl\r
     [ write ] histogram.\r
-    nl\r
+    nl nl\r
     "==== ERRORS:" print nl\r
     errors. ;\r
 \r
index ccec5e50cf17a324ffdb3d042a08413779ca740e..4a989cfc878e76ad8db2630d9a140cecc3fe5e5d 100644 (file)
@@ -8,11 +8,6 @@ HELP: insomniac-sender
 HELP: insomniac-recipients
 { $var-description "A sequence of e-mail addresses to mail log reports to. Must be set before " { $vocab-link "logging.insomniac" } " is used." } ;
 
-HELP: ?analyze-log
-{ $values { "service" "a log service name" } { "word-names" "a sequence of strings" } { "string/f" string } }
-{ $description "Analyzes the most recent log and outputs the string analysis, or outputs " { $link f } " if it doesn't exist." }
-{ $see-also analyze-log } ;
-
 HELP: email-log-report
 { $values { "service" "a log service name" } { "word-names" "a sequence of strings" } }
 { $description "E-mails a log report for the given log service. The " { $link insomniac-sender } " and " { $link insomniac-recipients } " parameters must be set up first. The " { $snippet "word-names" } " parameter is documented in " { $link analyze-entries } "." } ;
index 2a0be6aa79ed1fd571c1cf1269fb608ca08abc94..5f323d7ada5b78ee382229060f2e442f7c32f095 100644 (file)
@@ -1,31 +1,26 @@
-! Copyright (C) 2008 Slava Pestov.\r
+! Copyright (C) 2008, 2010 Slava Pestov.\r
 ! See http://factorcode.org/license.txt for BSD license.\r
 USING: logging.analysis logging.server logging smtp kernel\r
 io.files io.streams.string namespaces make timers assocs\r
-io.encodings.utf8 accessors calendar sequences ;\r
+io.encodings.utf8 accessors calendar sequences locals ;\r
 QUALIFIED: io.sockets\r
 IN: logging.insomniac\r
 \r
 SYMBOL: insomniac-sender\r
 SYMBOL: insomniac-recipients\r
 \r
-: ?analyze-log ( service word-names -- string/f )\r
-    [ analyze-log-file ] with-string-writer ;\r
-\r
 : email-subject ( service -- string )\r
     [\r
-        "[INSOMNIAC] " % % " on " % io.sockets:host-name %\r
+        "Log analysis for " % % " on " % io.sockets:host-name %\r
     ] "" make ;\r
 \r
-: (email-log-report) ( service word-names -- )\r
-    dupd ?analyze-log [ drop ] [\r
-        <email>\r
-            swap >>body\r
-            insomniac-recipients get >>to\r
-            insomniac-sender get >>from\r
-            swap email-subject >>subject\r
-        send-email\r
-    ] if-empty ;\r
+:: (email-log-report) ( service word-names -- )\r
+    <email>\r
+        [ service word-names analyze-log-file ] with-string-writer >>body\r
+        insomniac-recipients get >>to\r
+        insomniac-sender get >>from\r
+        service email-subject >>subject\r
+    send-email ;\r
 \r
 \ (email-log-report) NOTICE add-error-logging\r
 \r
@@ -33,5 +28,5 @@ SYMBOL: insomniac-recipients
     "logging.insomniac" [ (email-log-report) ] with-logging ;\r
 \r
 : schedule-insomniac ( service word-names -- )\r
-    [ [ email-log-report ] assoc-each rotate-logs ] 2curry\r
-    1 days delayed-every drop ;\r
+    [ email-log-report rotate-logs ] 2curry\r
+    1 days every drop ;\r
index 796c8769fc295febb25e4c7a84dddb41bce993fa..a7cc6c6f5f6d2e2c107ccca3c84e9f5a52b0eb89 100644 (file)
@@ -1,5 +1,5 @@
 IN: logging.tests
-USING: tools.test logging math ;
+USING: tools.test logging logging.analysis io math ;
 
 : input-logging-test ( a b -- c ) + ;
 
@@ -22,3 +22,5 @@ USING: tools.test logging math ;
     
     [ f ] [ 1 0 error-logging-test ] unit-test
 ] with-logging
+
+[ ] [ "logging-test" { "input-logging-test" } analyze-log-file ] unit-test
index dbc26c7efcc31c571ec307f84222a5c67abbb406..a359c9a25476a2d79eb525a7817903a135703e02 100644 (file)
@@ -1,9 +1,9 @@
-! Copyright (C) 2008 Slava Pestov.\r
+! Copyright (C) 2008, 2010 Slava Pestov.\r
 ! See http://factorcode.org/license.txt for BSD license.\r
 USING: accessors peg peg.parsers memoize kernel sequences\r
 logging arrays words strings vectors io io.files\r
 io.encodings.utf8 namespaces make combinators logging.server\r
-calendar calendar.format assocs ;\r
+calendar calendar.format assocs prettyprint ;\r
 IN: logging.parser\r
 \r
 TUPLE: log-entry date level word-name message ;\r
@@ -83,3 +83,20 @@ PEG: parse-log-line ( string -- entry ) 'log-line' ;
 : parse-log-file ( service -- entries )\r
     log-path 1 log# dup exists?\r
     [ utf8 file-lines parse-log ] [ drop f ] if ;\r
+\r
+GENERIC: log-timestamp. ( date -- )\r
+\r
+M: timestamp log-timestamp. (timestamp>string) ;\r
+M: word log-timestamp. drop "multiline" write ;\r
+\r
+: log-entry. ( entry -- )\r
+    "====== " write\r
+    {\r
+        [ date>> log-timestamp. bl ]\r
+        [ level>> pprint bl ]\r
+        [ word-name>> write nl ]\r
+        [ message>> "\n" join print ]\r
+    } cleave ;\r
+\r
+: log-entries. ( errors -- )\r
+    [ log-entry. ] each ;\r
index ffa3550452c788e7e249a5217c21d19a92311fe0..d82e3b1fdd0539b410dc84c86baff75b0b9cd4a9 100644 (file)
@@ -41,6 +41,6 @@ SYMBOL: half
     2 >>align
     2 >>align-first
     [ >float ] >>unboxer-quot
-\ half define-primitive-type
+\ half typedef
 
 >>
index 1e32818fe3ac8e07d31fb82ce995b2d7d324ed05..b9d9ea38df72d078e5b2b704f30c2f49e6220a07 100644 (file)
@@ -1,10 +1,14 @@
-USING: help.markup help.syntax ;
+USING: byte-arrays help.markup help.syntax kernel math ;
 IN: math.primes.erato
 
 HELP: sieve
-{ $values { "n" "the greatest odd number to consider" } { "arr" "a bit array" } }
-{ $description "Apply Eratostene sieve up to " { $snippet "n" } ". Primality can then be tested using " { $link sieve } "." } ;
+{ $values { "n" integer } { "arr" byte-array } }
+{ $description "Apply Eratostene sieve up to " { $snippet "n" }
+". " { $snippet "n" } " must be greater than 1"
+". Primality can then be tested using " { $link marked-prime? } "." } ;
 
 HELP: marked-prime?
-{ $values { "n" "an integer" } { "arr" "a byte array returned by " { $link sieve } } { "?" "a boolean" } }
-{ $description "Check whether a number between 3 and the limit given to " { $link sieve } " has been marked as a prime number."} ;
+{ $values { "n" integer } { "arr" byte-array } { "?" boolean } }
+{ $description "Checks whether " { $snippet "n" } " has been marked as a prime number. "
+{ $snippet "arr" } " must be " { $instance byte-array } " returned by " { $link sieve } ". "
+{ $snippet "n" } " must be between 2 and the limit given to " { $link sieve } "." } ;
index e6f7765bd693e8996b06b43083025a3f10b49bb4..ff44ec22103041a35240fded2c0c7d6592b280af 100644 (file)
@@ -1,4 +1,5 @@
-USING: byte-arrays math math.bitwise math.primes.erato sequences tools.test ;
+USING: kernel byte-arrays sequences tools.test ;
+USING: math math.bitwise math.ranges math.primes.erato ;
 
 [ B{ 255 251 247 126 } ] [ 100 sieve ] unit-test
 [ 1 100 sieve marked-prime? ] [ bounds-error? ] must-fail-with
@@ -8,3 +9,8 @@ USING: byte-arrays math math.bitwise math.primes.erato sequences tools.test ;
 
 ! There are 25997 primes below 300000. 1 must be removed and 3 5 7 added.
 [ 25997 ] [ 299999 sieve [ bit-count ] map-sum 2 + ] unit-test
+
+! Check sieve array length logic by making sure we get the right
+! end-point for numbers with all possibilities mod 30. If something
+! were to go wrong, we'd get a bounds-error.
+[ ] [ 2 100 [a,b] [ dup sieve marked-prime? drop ] each ] unit-test
index fdc2f9fc3bef158c64f13dacbf19d5afea5d6e87..4df724cfc23bba20f1f0e2229f214d27b82f8ece 100644 (file)
@@ -28,7 +28,7 @@ CONSTANT: masks B{ 0 128 0 0 0 0 0 64 0 0 0 32 0 16 0 0 0 8 0 4 0 0 0 2 0 0 0 0
         2drop
     ] if ;
 
-: init-sieve ( n -- arr ) 29 + 30 /i 255 <array> >byte-array ;
+: init-sieve ( n -- arr ) 30 /i 1 + 255 <array> >byte-array ;
 
 PRIVATE>
 
index e0cf73c7f115560c689e49b7731c6f78d115dccb..a1654ccc347596c001e7f86d226a6aab0ca50389 100644 (file)
@@ -1,18 +1,18 @@
 ! Copyright (C) 2008, 2009 Slava Pestov.\r
 ! See http://factorcode.org/license.txt for BSD license.\r
-USING: accessors models kernel ;\r
+USING: accessors models kernel sequences ;\r
 IN: models.arrow\r
 \r
-TUPLE: arrow < model model quot ;\r
+TUPLE: arrow < model quot ;\r
 \r
 : <arrow> ( model quot -- arrow )\r
     f arrow new-model\r
         swap >>quot\r
-        over >>model\r
         [ add-dependency ] keep ;\r
 \r
 M: arrow model-changed\r
     [ [ value>> ] [ quot>> ] bi* call( old -- new ) ] [ nip ] 2bi\r
     set-model ;\r
 \r
-M: arrow model-activated [ model>> ] keep model-changed ;\r
+M: arrow model-activated\r
+    [ dependencies>> ] keep [ model-changed ] curry each ;\r
index 9e7c28e89f43fd1c9c5fec54c370413b3f1b1912..09f86197ba5f5c3cb2e00949941c755b9b670352 100644 (file)
@@ -17,7 +17,7 @@ HELP: /*
 HELP: HEREDOC:
 { $syntax "HEREDOC: marker\n...text...\nmarker" }
 { $values { "marker" "a word (token)" } { "text" "arbitrary text" } { "value" string } }
-{ $description "Returns a string delimited by an arbitrary user-defined token. This delimiter must be exactly the text beginning at the first non-blank character after " { $link POSTPONE: HEREDOC: } " until the end of the line containing " { $link POSTPONE: HEREDOC: } ". Text is captured until a line is found conatining exactly this delimter string." }
+{ $description "Returns a string delimited by an arbitrary user-defined token. This delimiter must be exactly the text beginning at the first non-blank character after " { $link POSTPONE: HEREDOC: } " until the end of the line containing " { $link POSTPONE: HEREDOC: } ". Text is captured until a line is found containing exactly this delimiter string." }
 { $warning "Whitespace is significant." }
 { $examples
     { $example "USING: multiline prettyprint ;"
index fda840b281c73290359712d600cb9a3c09da2acc..0589e0eede0ba22e630a182cbfc1354904eaf4f3 100644 (file)
@@ -142,7 +142,7 @@ MACRO: all-enabled-client-state ( seq quot -- )
     [ 1 { uint } ] dip with-out-parameters ; inline
 
 : (delete-gl-object) ( id quot -- )
-    [ 1 swap <uint> ] dip call ; inline
+    [ 1 swap uint <ref> ] dip call ; inline
 
 : gen-gl-buffer ( -- id )
     [ glGenBuffers ] (gen-gl-object) ;
index 720665a1b8593928640abc712cbd819cc96faaef..1b7ac94f4d705608ad82db429acce81d66da4163 100644 (file)
@@ -1,14 +1,14 @@
 ! Copyright (C) 2008 Joe Groff.
 ! See http://factorcode.org/license.txt for BSD license.
 USING: kernel opengl.gl alien.c-types continuations namespaces
-assocs alien alien.data alien.strings libc opengl math sequences combinators
-macros arrays io.encodings.ascii fry specialized-arrays
-destructors accessors ;
+assocs alien alien.data alien.strings libc opengl math sequences
+combinators macros arrays io.encodings.ascii fry
+specialized-arrays destructors accessors ;
 SPECIALIZED-ARRAY: uint
 IN: opengl.shaders
 
 : with-gl-shader-source-ptr ( string quot -- )
-    swap ascii malloc-string [ <void*> swap call ] keep free ; inline
+    swap ascii malloc-string [ void* <ref> swap call ] keep free ; inline
 
 : <gl-shader> ( source kind -- shader )
     glCreateShader dup rot
@@ -47,7 +47,7 @@ IN: opengl.shaders
 : gl-shader-info-log ( shader -- log )
     dup gl-shader-info-log-length dup [
         1 calloc &free
-        [ 0 <int> swap glGetShaderInfoLog ] keep
+        [ 0 int <ref> swap glGetShaderInfoLog ] keep
         ascii alien>string
     ] with-destructors ;
 
@@ -90,7 +90,7 @@ PREDICATE: fragment-shader < gl-shader (fragment-shader?) ;
 : gl-program-info-log ( program -- log )
     dup gl-program-info-log-length dup [
         1 calloc &free
-        [ 0 <int> swap glGetProgramInfoLog ] keep
+        [ 0 int <ref> swap glGetProgramInfoLog ] keep
         ascii alien>string
     ] with-destructors ;
 
@@ -107,7 +107,7 @@ PREDICATE: fragment-shader < gl-shader (fragment-shader?) ;
 
 : gl-program-shaders ( program -- shaders )
     dup gl-program-shaders-length 2 *
-    0 <int>
+    0 int <ref>
     over <uint-array>
     [ glGetAttachedShaders ] keep [ zero? not ] filter ;
 
index ba5d9c7ca316f8fd951373607317241d7afacaca..bf99b47ba7f70504dac0c40462d19455ee014d67 100644 (file)
@@ -1,9 +1,9 @@
 ! Copyright (C) 2008 Doug Coleman.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: accessors alien.c-types arrays assocs byte-arrays
-byte-vectors combinators fry io.backend io.binary kernel locals
-math math.bitwise math.constants math.functions math.order
-math.ranges namespaces sequences sets summary system
+USING: accessors alien.c-types alien.data arrays assocs
+byte-arrays byte-vectors combinators fry io.backend io.binary
+kernel locals math math.bitwise math.constants math.functions
+math.order math.ranges namespaces sequences sets summary system
 vocabs.loader ;
 IN: random
 
@@ -90,8 +90,8 @@ ERROR: too-many-samples seq n ;
     secure-random-generator get swap with-random ; inline
 
 : uniform-random-float ( min max -- n )
-    4 random-bytes underlying>> *uint >float
-    4 random-bytes underlying>> *uint >float
+    4 random-bytes underlying>> uint deref >float
+    4 random-bytes underlying>> uint deref >float
     2.0 32 ^ * +
     [ over - 2.0 -64 ^ * ] dip
     * + ; inline
index ccccaac7eaf53eef675dcbd18327da8cf2f9ba6e..2efe6f6facf96b70b3b32212bc0e7e019d1f141f 100644 (file)
@@ -1,7 +1,7 @@
 ! Copyright (C) 2009 Doug Coleman.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: accessors alien.c-types kernel locals math math.ranges
-math.bitwise math.vectors math.vectors.simd random
+USING: accessors alien.c-types alien.data kernel locals math
+math.ranges math.bitwise math.vectors math.vectors.simd random
 sequences specialized-arrays sequences.private classes.struct
 combinators.short-circuit fry ;
 SPECIALIZED-ARRAY: uint
index 42900854821f1a73b708776108b9f46ec346c61f..487d7b2ecaccc1e8aebb4713f1c7945dc995a3f7 100644 (file)
@@ -14,7 +14,7 @@ M: product-sequence length lengths>> product ;
 <PRIVATE
 
 : ns ( n lengths -- ns )
-    [ V{ } clone ] 2dip [ /mod swap [ over push ] dip ] each drop ;
+    [ /mod ] map nip ;
 
 : nths ( ns seqs -- nths )
     [ nth ] { } 2map-as ;
@@ -38,10 +38,10 @@ M: product-sequence length lengths>> product ;
     [ 0 over [ 1 + ] change-nth ] dip carry-ns ;
 
 : start-product-iter ( sequences -- ns lengths )
-    [ [ drop 0 ] map ] [ [ length ] map ] bi ;
+    [ length 0 <array> ] [ [ length ] map ] bi ;
 
 : end-product-iter? ( ns lengths -- ? )
-    [ 1 tail* first ] bi@ = ;
+    [ last ] bi@ = ;
 
 PRIVATE>
 
index b476a4707251c5c6f50821831f1782b41b2b02b1..99036ac01374a564ac5954f596ca7af137acda09 100644 (file)
@@ -41,7 +41,7 @@ ARTICLE: "specialized-array-words" "Specialized array words"
     { { $snippet "T-array" } { "The class of arrays with elements of type " { $snippet "T" } } }
     { { $snippet "<T-array>" } { "Constructor for arrays with elements of type " { $snippet "T" } "; stack effect " { $snippet "( len -- array )" } } }
     { { $snippet "(T-array)" } { "Constructor for arrays with elements of type " { $snippet "T" } ", where the initial contents are uninitialized; stack effect " { $snippet "( len -- array )" } } }
-    { { $snippet "malloc-T-array" } { "Constructor for arrays with elements of type " { $snippet "T" } " backed by newly-allocated unmanaged memory; stack effect " { $snippet "( alien len -- array )" } } }
+    { { $snippet "malloc-T-array" } { "Constructor for arrays with elements of type " { $snippet "T" } " backed by newly-allocated, zeroed out, unmanaged memory; stack effect " { $snippet "( len -- array )" } } }
     { { $snippet "<direct-T-array>" } { "Constructor for arrays with elements of type " { $snippet "T" } " backed by raw memory; stack effect " { $snippet "( alien len -- array )" } } }
     { { $snippet "T-array-cast" } { "Converts a byte array into a specialized array by interpreting the bytes in as machine-specific values. Code which uses this word is unportable" } }
     { { $snippet ">T-array" } { "Converts a sequence into a specialized array of type " { $snippet "T" } "; stack effect " { $snippet "( seq -- array )" } } }
@@ -86,7 +86,7 @@ $nl
 }
 "Finally, sometimes a C library returns a pointer to an array in unmanaged memory, together with a length. In this case, a specialized array can be constructed to view this memory using " { $snippet "<direct-T-array>" } ":"
 { $code
-    "USING: alien.c-types classes.struct ;"
+    "USING: alien.c-types alien.data classes.struct ;"
     ""
     "STRUCT: device_info"
     "    { id int }"
@@ -94,7 +94,7 @@ $nl
     ""
     "FUNCTION: void get_device_info ( int* length ) ;"
     ""
-    "0 <int> [ get_device_info ] keep <direct-int-array> ."
+    "0 int <ref> [ get_device_info ] keep <direct-int-array> ."
 }
 "For a full discussion of Factor heap allocation versus unmanaged memory allocation, see " { $link "byte-arrays-gc" } "."
 $nl
index 02424a22fdc68cc9cd9c7b1a4ec521fa8c353177..e3770220e89e8f878cbd6b250c8fe894159f249c 100644 (file)
@@ -6,7 +6,8 @@ multiline eval words vocabs namespaces assocs prettyprint
 alien.data math.vectors definitions compiler.test ;
 FROM: specialized-arrays.private => specialized-array-vocab ;
 FROM: alien.c-types => int float bool char float ulonglong ushort uint
-heap-size little-endian? ;
+heap-size ;
+FROM: alien.data => little-endian? ;
 IN: specialized-arrays.tests
 
 SPECIALIZED-ARRAY: int
index 47e882f2277501705ddc2dfea87da23128876aca..43bff4e96a833b4e85aa0037036a90b43df17b19 100644 (file)
@@ -338,7 +338,6 @@ M: object infer-call* \ call bad-macro-input ;
 \ bignum> { bignum bignum } { object } define-primitive \ bignum> make-foldable
 \ bignum>= { bignum bignum } { object } define-primitive \ bignum>= make-foldable
 \ bignum>fixnum { bignum } { fixnum } define-primitive \ bignum>fixnum make-foldable
-\ bignum>float { bignum } { float } define-primitive \ bignum>float make-foldable
 \ bits>double { integer } { float } define-primitive \ bits>double make-foldable
 \ bits>float { integer } { float } define-primitive \ bits>float make-foldable
 \ both-fixnums? { object object } { object } define-primitive
index b51fd52995ae448b066274b5b3565273e424571a..d4f22771284537671bf10c36310935325a1db45b 100644 (file)
@@ -1,6 +1,6 @@
 ! Copyright (C) 2008 Doug Coleman.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: alien alien.c-types alien.strings alien.syntax
+USING: alien alien.c-types alien.data alien.strings alien.syntax
 byte-arrays kernel namespaces sequences unix
 system-info.backend system io.encodings.utf8 ;
 IN: system-info.macosx
@@ -11,23 +11,23 @@ LIBRARY: libc
 FUNCTION: int sysctl ( int* name, uint namelen, void* oldp, size_t* oldlenp, void* newp, size_t newlen ) ;
 
 : make-int-array ( seq -- byte-array )
-    [ <int> ] map concat ;
+    [ int <ref> ] map concat ;
 
 : (sysctl-query) ( name namelen oldp oldlenp -- oldp )
     over [ f 0 sysctl io-error ] dip ;
 
 : sysctl-query ( seq n -- byte-array )
     [ [ make-int-array ] [ length ] bi ] dip
-    [ <byte-array> ] [ <uint> ] bi (sysctl-query) ;
+    [ <byte-array> ] [ uint <ref> ] bi (sysctl-query) ;
 
 : sysctl-query-string ( seq -- n )
     4096 sysctl-query utf8 alien>string ;
 
 : sysctl-query-uint ( seq -- n )
-    4 sysctl-query *uint ;
+    4 sysctl-query uint deref ;
 
 : sysctl-query-ulonglong ( seq -- n )
-    8 sysctl-query *ulonglong ;
+    8 sysctl-query ulonglong deref ;
 
 : machine ( -- str ) { 6 1 } sysctl-query-string ;
 : model ( -- str ) { 6 2 } sysctl-query-string ;
index 0aba5eeff161bbe14ecaa8040516f9ea91cb0a13..4ff252bf25641cb91670e6d14023732f494e040d 100644 (file)
@@ -1,10 +1,9 @@
 ! Copyright (C) 2008 Doug Coleman.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: accessors alien alien.c-types alien.strings byte-arrays
-classes.struct combinators kernel math namespaces
-specialized-arrays system
-system-info.backend vocabs.loader windows windows.advapi32
-windows.errors windows.kernel32 words ;
+USING: accessors alien alien.c-types alien.data alien.strings
+byte-arrays classes.struct combinators kernel math namespaces
+specialized-arrays system system-info.backend vocabs.loader
+windows windows.advapi32 windows.errors windows.kernel32 words ;
 SPECIALIZED-ARRAY: ushort
 IN: system-info.windows
 
@@ -95,10 +94,10 @@ M: winnt available-virtual-mem ( -- n )
 
 : computer-name ( -- string )
     MAX_COMPUTERNAME_LENGTH 1 +
-    [ <byte-array> dup ] keep <uint>
+    [ <byte-array> dup ] keep uint <ref>
     GetComputerName win32-error=0/f alien>native-string ;
  
 : username ( -- string )
     UNLEN 1 +
-    [ <byte-array> dup ] keep <uint>
+    [ <byte-array> dup ] keep uint <ref>
     GetUserName win32-error=0/f alien>native-string ;
index f3a3e4437b5b646ff95727e0ced3d4a2756d2ab3..9a9b29cbf3c46258e85c46aacd1966a1cfcff724 100644 (file)
@@ -22,10 +22,9 @@ HELP: every
      { "timer" timer } }\r
 { $description "Creates a timer that calls the quotation repeatedly, using " { $snippet "duration" } " as the frequency. The first call of " { $snippet "quot" } " will happen immediately. If the quotation throws an exception, the timer will stop." }\r
 { $examples\r
-    { $unchecked-example\r
+    { $code\r
         "USING: timers io calendar ;"\r
         """[ "Hi Buddy." print flush ] 10 seconds every drop"""\r
-        ""\r
     }\r
 } ;\r
 \r
@@ -33,10 +32,9 @@ HELP: later
 { $values { "quot" quotation } { "delay-duration" duration } { "timer" timer } }\r
 { $description "Sleeps for " { $snippet "duration" } " and then calls a " { $snippet "quot" } ". The user may cancel the timer before " { $snippet "quot" } " runs. This timer is not repeated." }\r
 { $examples\r
-    { $unchecked-example\r
+    { $code\r
         "USING: timers io calendar ;"\r
         """[ "Break's over!" print flush ] 15 minutes later drop"""\r
-        ""\r
     }\r
 } ;\r
 \r
@@ -46,10 +44,9 @@ HELP: delayed-every
      { "timer" timer } }\r
 { $description "Creates a timer that calls " { $snippet "quot" } " repeatedly, waiting " { $snippet "duration" } " before calling " { $snippet "quot" } " the first time and then waiting " { $snippet "duration" } " between further calls. If the quotation throws an exception, the timer will stop." }\r
 { $examples\r
-    { $unchecked-example\r
+    { $code\r
         "USING: timers io calendar ;"\r
         """[ "Hi Buddy." print flush ] 10 seconds every drop"""\r
-        ""\r
     }\r
 } ;\r
 \r
index e8c45ee4a0db23095232bf0559d31918004cec48..29b3d26d104f6dfe8c75142198697658462f8624 100644 (file)
@@ -28,7 +28,7 @@ HELP: uses
 { $notes "The sequence might include the definition itself, if it is a recursive word." }
 { $examples
     "We can ask the " { $link sq } " word to produce a list of words it calls:"
-    { $unchecked-example "\ sq uses ." "{ dup * }" }
+    { $unchecked-example "\\ sq uses ." "{ dup * }" }
 } ;
 
 HELP: crossref
index 0b06abc29a2bf2412827c3cdf9febdce16584086..2f525471040c6e2ac75e8995d35ca22e26b4044f 100644 (file)
@@ -40,13 +40,15 @@ HELP: deploy-c-types?
 $nl
 "Off by default."
 $nl
-"The optimizing compiler is able to fold away calls to various words which take a C type as an input if the C type is a literal string:"
+"The optimizing compiler is able to fold away calls to various words which take a C type as an input if the C type is a literal string, for example,"
 { $list
     { $link c-type }
     { $link heap-size }
-    { $link <c-object> }
     { $link <c-array> }
+    { $link <c-direct-array> }
     { $link malloc-array }
+    { $link <ref> }
+    { $link deref }
 }
 "If your program looks up C types dynamically or from words which do not have a stack effect, you must enable this flag, because in these situations the C type lookup code is not folded away and the word properties must be consulted at runtime." } ;
 
index e8888717ab1804f49cffcbd7566d46b34c2e44ee..1da32f3f42c37eb1179048578d58bb53d3e9ee95 100644 (file)
@@ -134,3 +134,5 @@ os macosx? [
 [ ] [ "resource:license.txt" "license.txt" temp-file copy-file ] unit-test
 
 [ ] [ "tools.deploy.test.19" shake-and-bake run-temp-image ] unit-test
+
+[ ] [ "benchmark.ui-panes" shake-and-bake run-temp-image ] unit-test
diff --git a/basis/tools/dns/authors.txt b/basis/tools/dns/authors.txt
new file mode 100644 (file)
index 0000000..7c1b2f2
--- /dev/null
@@ -0,0 +1 @@
+Doug Coleman
diff --git a/basis/tools/dns/dns.factor b/basis/tools/dns/dns.factor
new file mode 100644 (file)
index 0000000..f59a9da
--- /dev/null
@@ -0,0 +1,24 @@
+! Copyright (C) 2010 Doug Coleman.
+! See http://factorcode.org/license.txt for BSD license.
+USING: dns io kernel math.parser sequences ;
+IN: tools.dns
+
+: a-line. ( host ip -- )
+    [ write " has address " write ] [ print ] bi* ;
+
+: a-message. ( message -- )
+    [ message>query-name ] [ message>names ] bi
+    [ a-line. ] with each ;
+
+: mx-line. ( host pair -- )
+    [ write " mail is handled by " write ]
+    [ first2 [ number>string write bl ] [ print ] bi* ] bi* ;
+
+: mx-message. ( message -- )
+    [ message>query-name ] [ message>mxs ] bi
+    [ mx-line. ] with each ;
+
+: host ( domain -- )
+    [ dns-A-query a-message. ]
+    [ dns-AAAA-query a-message. ]
+    [ dns-MX-query mx-message. ] tri ;
index 48647df92d0632ab5bba77342a92a88560b553b4..1e7777d9d7c3860d9afc0c0cec011183d4f93f1b 100644 (file)
@@ -128,7 +128,7 @@ CONSTANT: window-control>styleMask
 
 : make-context-transparent ( view -- )
     -> openGLContext
-    0 <int> NSOpenGLCPSurfaceOpacity -> setValues:forParameter: ;
+    0 int <ref> NSOpenGLCPSurfaceOpacity -> setValues:forParameter: ;
 
 M:: cocoa-ui-backend (open-window) ( world -- )
     world [ [ dim>> ] dip <FactorView> ]
index e98c31b295391d0f142fcc638e6f25057b486f02..7837402701bd46f7fa028f9475ceaddf521eed84 100644 (file)
@@ -332,7 +332,7 @@ CLASS: FactorView < NSOpenGLView NSTextInput
 ]
 
 : sync-refresh-to-screen ( GLView -- )
-    -> openGLContext -> CGLContextObj NSOpenGLCPSwapInterval 1 <int>
+    -> openGLContext -> CGLContextObj NSOpenGLCPSwapInterval 1 int <ref>
     CGLSetParameter drop ;
 
 : <FactorView> ( dim pixel-format -- view )
index 5178dbb49969fb5239ec42a5ce603642fec8a225..072924fa57d806a91b3accf1be5ef1857d52e2a9 100755 (executable)
@@ -1,21 +1,22 @@
 ! Copyright (C) 2005, 2006 Doug Coleman.
 ! Portions copyright (C) 2007, 2010 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: alien alien.c-types alien.strings arrays assocs ui
+USING: alien alien.data alien.strings arrays assocs ui
 ui.private ui.gadgets ui.gadgets.private ui.backend
 ui.clipboards ui.gadgets.worlds ui.gestures ui.event-loop io
 kernel math math.vectors namespaces make sequences strings
-vectors words windows.dwmapi system-info.windows windows.kernel32
-windows.gdi32 windows.user32 windows.opengl32 windows.messages
-windows.types windows.offscreen windows threads libc combinators
-fry combinators.short-circuit continuations command-line shuffle
-opengl ui.render math.bitwise locals accessors math.rectangles
-math.order calendar ascii sets io.encodings.utf16n
-windows.errors literals ui.pixel-formats
+vectors words windows.dwmapi system-info.windows
+windows.kernel32 windows.gdi32 windows.user32 windows.opengl32
+windows.messages windows.types windows.offscreen windows threads
+libc combinators fry combinators.short-circuit continuations
+command-line shuffle opengl ui.render math.bitwise locals
+accessors math.rectangles math.order calendar ascii sets
+io.encodings.utf16n windows.errors literals ui.pixel-formats
 ui.pixel-formats.private memoize classes colors
-specialized-arrays classes.struct alien.data ;
+specialized-arrays classes.struct ;
 FROM: namespaces => set ;
 SPECIALIZED-ARRAY: POINT
+QUALIFIED-WITH: alien.c-types c
 IN: ui.backend.windows
 
 SINGLETON: windows-ui-backend
@@ -59,14 +60,14 @@ PIXEL-FORMAT-ATTRIBUTE-TABLE: WGL_ARB { $ WGL_SUPPORT_OPENGL_ARB 1 } H{
     drop f ;
 
 : arb-make-pixel-format ( world attributes -- pf )
-    [ handle>> hDC>> ] dip >WGL_ARB-int-array f 1 { int int }
+    [ handle>> hDC>> ] dip >WGL_ARB-int-array f 1 { c:int c:int }
     [ wglChoosePixelFormatARB win32-error=0/f ] with-out-parameters drop ;
 
 : arb-pixel-format-attribute ( pixel-format attribute -- value )
     >WGL_ARB
     [ drop f ] [
         [ [ world>> handle>> hDC>> ] [ handle>> ] bi 0 1 ] dip
-        first <int> { int }
+        first c:int <ref> { c:int }
         [ wglGetPixelFormatAttribivARB win32-error=0/f ]
         with-out-parameters
     ] if-empty ;
@@ -95,7 +96,7 @@ CONSTANT: pfd-flag-map H{
 : >pfd ( attributes -- pfd )
     [ PIXELFORMATDESCRIPTOR <struct> ] dip
     {
-        [ drop PIXELFORMATDESCRIPTOR heap-size >>nSize ]
+        [ drop PIXELFORMATDESCRIPTOR c:heap-size >>nSize ]
         [ drop 1 >>nVersion ]
         [ >pfd-flags >>dwFlags ]
         [ drop PFD_TYPE_RGBA >>iPixelType ]
@@ -121,12 +122,12 @@ CONSTANT: pfd-flag-map H{
 
 : get-pfd ( pixel-format -- pfd )
     [ world>> handle>> hDC>> ] [ handle>> ] bi
-    PIXELFORMATDESCRIPTOR heap-size
+    PIXELFORMATDESCRIPTOR c:heap-size
     PIXELFORMATDESCRIPTOR <struct>
     [ DescribePixelFormat win32-error=0/f ] keep ;
 
 : pfd-flag? ( pfd flag -- ? )
-    [ dwFlags>> ] dip bitand c-bool> ;
+    [ dwFlags>> ] dip bitand c:c-bool> ;
 
 : (pfd-pixel-format-attribute) ( pfd attribute -- value )
     {
@@ -168,7 +169,7 @@ M: windows-ui-backend (pixel-format-attribute)
 
 PRIVATE>
 
-: lo-word ( wparam -- lo ) <short> *short ; inline
+: lo-word ( wparam -- lo ) c:short <ref> c:short deref ; inline
 : hi-word ( wparam -- hi ) -16 shift lo-word ; inline
 : >lo-hi ( WORD -- array ) [ lo-word ] [ hi-word ] bi 2array ;
 : GET_APPCOMMAND_LPARAM ( lParam -- appCommand )
@@ -524,7 +525,7 @@ SYMBOL: nc-buttons
 : make-TRACKMOUSEEVENT ( hWnd -- alien )
     TRACKMOUSEEVENT <struct>
         swap >>hwndTrack
-        TRACKMOUSEEVENT heap-size >>cbSize ;
+        TRACKMOUSEEVENT c:heap-size >>cbSize ;
 
 : handle-wm-mousemove ( hWnd uMsg wParam lParam -- )
     2nip
@@ -613,7 +614,7 @@ SYMBOL: trace-messages?
 
 ! return 0 if you handle the message, else just let DefWindowProc return its val
 : ui-wndproc ( -- object )
-    uint { void* uint long long } stdcall [
+    c:uint { c:void* c:uint c:long c:long } stdcall [
         pick
 
         trace-messages? get-global
@@ -635,7 +636,7 @@ M: windows-ui-backend do-events
 :: register-window-class ( class-name-ptr -- )
     WNDCLASSEX <struct> f GetModuleHandle
     class-name-ptr pick GetClassInfoEx 0 = [
-        WNDCLASSEX heap-size >>cbSize
+        WNDCLASSEX c:heap-size >>cbSize
         flags{ CS_HREDRAW CS_VREDRAW CS_OWNDC } >>style
         ui-wndproc >>lpfnWndProc
         0 >>cbClsExtra
@@ -798,7 +799,7 @@ M: windows-ui-backend system-alert
 : fullscreen-RECT ( hwnd -- RECT )
     MONITOR_DEFAULTTONEAREST MonitorFromWindow
     MONITORINFOEX <struct>
-        MONITORINFOEX heap-size >>cbSize
+        MONITORINFOEX c:heap-size >>cbSize
     [ GetMonitorInfo win32-error=0/f ] keep rcMonitor>> ;
 
 : client-area>RECT ( hwnd -- RECT )
index c82990a79e877e6d55cbafaebecc38a25a0741c9..6537f34727a9bc13ca0faee09b7d40f1111df479 100644 (file)
@@ -45,8 +45,7 @@ ARTICLE: "ui.pixel-formats-attributes" "Pixel format attributes"
 }
 { $examples
 "The following " { $link world } " subclass will request a double-buffered window with minimum 24-bit color and depth buffers, and will throw an error if the requirements aren't met:"
-{ $code """
-USING: kernel ui.worlds ui.pixel-formats ;
+{ $code """USING: kernel ui.gadgets.worlds ui.pixel-formats ;
 IN: ui.pixel-formats.examples
 
 TUPLE: picky-depth-buffered-world < world ;
@@ -63,8 +62,7 @@ M: picky-depth-buffered-world check-world-pixel-format
     [ double-buffered pixel-format-attribute 0 = [ "Not double buffered!" throw ] when ]
     [ color-bits pixel-format-attribute 24 < [ "Not enough color bits!" throw ] when ]
     [ depth-bits pixel-format-attribute 24 < [ "Not enough depth bits!" throw ] when ]
-    tri ;
-""" } }
+    tri ;""" } }
 ;
 
 HELP: double-buffered
index 64eb5db07ef113a882fe9eddd7f21fc99205ab4f..5e6d3150c731776ffb2f7a1141efda1ad04da536 100644 (file)
@@ -47,7 +47,7 @@ HELP: find-window
 HELP: register-window
 { $values { "world" world } { "handle" "a backend-specific handle" } }
 { $description "Adds a window to the global " { $link windows } " variable." }
-{ $notes "This word should only be called by the UI backend.  User code can open new windows with " { $link open-window } "." } ;
+{ $notes "This word should only be called by the UI backend. User code can open new windows with " { $link open-window } "." } ;
 
 HELP: unregister-window
 { $values { "handle" "a backend-specific handle" } }
@@ -75,7 +75,7 @@ HELP: raise-window
 HELP: with-ui
 { $values { "quot" { $quotation "( -- )" } } }
 { $description "Calls the quotation, starting the UI first if necessary. If the UI is started, this word does not return." }
-{ $notes "This word should be used in the " { $link POSTPONE: MAIN: } " word of an application that uses the UI in order for the vocabulary to work when run from either the UI listener (" { $snippet "\"my-app\" run" } " and the command line (" { $snippet "./factor -run=my-app" } ")." }
+{ $notes "This word should be used in the " { $link POSTPONE: MAIN: } " word of an application that uses the UI in order for the vocabulary to work when run from either the UI listener (" { $snippet "\"my-app\" run" } ") and the command line (" { $snippet "./factor -run=my-app" } ")." }
 { $examples "The " { $vocab-link "hello-ui" } " vocabulary implements a simple UI application which uses this word." } ;
 
 HELP: beep
@@ -255,7 +255,7 @@ $nl
 }
 "Gadgets implement a generic word to inform their parents of their preferred size:"
 { $subsections pref-dim* }
-"To get a gadget's preferred size, do not call the above word, instead use " { $link pref-dim  } ", which caches the result." ;
+"To get a gadget's preferred size, do not call the above word, instead use " { $link pref-dim } ", which caches the result." ;
 
 ARTICLE: "ui-null-layout" "Manual layouts"
 "When automatic layout is not appropriate, gadgets can be added to a parent with no layout policy, and then positioned and sized manually by setting the " { $snippet "loc" } " field." ;
index 3b3052af230d3f222eb9d6858b89f429ef76e15a..388fd5a692c624e76dc0610e72ebadb88efc8d15 100644 (file)
@@ -69,12 +69,10 @@ CONSTANT: SOCK_RAW 3
 CONSTANT: AF_UNSPEC 0
 CONSTANT: AF_UNIX 1
 CONSTANT: AF_INET 2
-CONSTANT: AF_INET6 30
 
 ALIAS: PF_UNSPEC AF_UNSPEC
 ALIAS: PF_UNIX AF_UNIX
 ALIAS: PF_INET AF_INET
-ALIAS: PF_INET6 AF_INET6
 
 CONSTANT: IPPROTO_TCP 6
 CONSTANT: IPPROTO_UDP 17
index 112758a3e8fdbcf984ad4327785b23551842f801..cb45cf2b2068d02e531dd9a9069cb2cda56b7533 100644 (file)
@@ -1,6 +1,9 @@
 USING: alien.c-types alien.syntax classes.struct unix.types ;
 IN: unix.ffi
 
+CONSTANT: AF_INET6 28
+ALIAS: PF_INET6 AF_INET6
+
 CONSTANT: FD_SETSIZE 1024
 
 STRUCT: addrinfo
index 2ca1d9315d8c7742d792ebb8aa8d76df0c3612ac..5a6775f2148289034ff41e499ebc0aee5ba45b72 100644 (file)
@@ -5,6 +5,9 @@ IN: unix.ffi
 
 CONSTANT: FD_SETSIZE 1024
 
+CONSTANT: AF_INET6 30
+ALIAS: PF_INET6 AF_INET6
+
 STRUCT: addrinfo
     { flags int }
     { family int } 
index 1f4eddef66cbf5138685357baa749fae0aad987a..dba7ddd3cd48df0bf9959112847472817954113e 100644 (file)
@@ -1,6 +1,9 @@
 USING: alien.c-types alien.syntax classes.struct unix.types ;
 IN: unix.ffi
 
+CONSTANT: AF_INET6 24
+ALIAS: PF_INET6 AF_INET6
+
 CONSTANT: FD_SETSIZE 1024
 
 STRUCT: addrinfo
index 5da7c189aef1669d701b6590860b5645956d2684..c4632c590fa7745c5d7f87309684645b77e1b2e1 100644 (file)
@@ -1,7 +1,7 @@
 ! Copyright (C) 2008 Doug Coleman.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: accessors alien alien.c-types alien.strings assocs
-byte-arrays classes.struct combinators
+USING: accessors alien alien.c-types alien.data alien.strings
+assocs byte-arrays classes.struct combinators
 combinators.short-circuit continuations fry io.backend.unix
 io.encodings.utf8 kernel math math.parser namespaces sequences
 splitting strings unix unix.ffi unix.users unix.utilities ;
@@ -22,10 +22,10 @@ GENERIC: group-struct ( obj -- group/f )
 
 : (group-struct) ( id -- group-struct id group-struct byte-array length void* )
     [ \ unix.ffi:group <struct> ] dip over 4096
-    [ <byte-array> ] keep f <void*> ;
+    [ <byte-array> ] keep f void* <ref> ;
 
 : check-group-struct ( group-struct ptr -- group-struct/f )
-    *void* [ drop f ] unless ;
+    void* deref [ drop f ] unless ;
 
 M: integer group-struct ( id -- group/f )
     (group-struct)
@@ -67,13 +67,13 @@ ERROR: no-group string ;
 <PRIVATE
 
 : >groups ( byte-array n -- groups )
-    [ 4 grouping:group ] dip head-slice [ *uint group-name ] map ;
+    [ 4 grouping:group ] dip head-slice [ uint deref group-name ] map ;
 
 : (user-groups) ( string -- seq )
     #! first group is -1337, legacy unix code
     -1337 unix.ffi:NGROUPS_MAX [ 4 * <byte-array> ] keep
-    <int> [ [ unix.ffi:getgrouplist ] unix-system-call drop ] 2keep
-    [ 4 tail-slice ] [ *int 1 - ] bi* >groups ;
+    int <ref> [ [ unix.ffi:getgrouplist ] unix-system-call drop ] 2keep
+    [ 4 tail-slice ] [ int deref 1 - ] bi* >groups ;
 
 PRIVATE>
     
index 4973df989da1c5a353e3774a47304ca2ba06ab47..41cf7ac18845095c2e170a10f42e554e0e1d00ae 100644 (file)
@@ -22,5 +22,3 @@ TYPEDEF: __uint32_t     fflags_t
 TYPEDEF: long           ssize_t
 TYPEDEF: int            pid_t
 TYPEDEF: long           time_t
-
-ALIAS: <time_t> <long>
index a3dddfc93e01e3cc3cfc58ec64e93862ae84f94f..7a09b0474aff9b2e48fadc814dd5dc37604207cf 100644 (file)
@@ -31,5 +31,3 @@ TYPEDEF: ulonglong __fsblkcnt64_t
 TYPEDEF: ulonglong __fsfilcnt64_t
 TYPEDEF: ulonglong ino64_t
 TYPEDEF: ulonglong off64_t
-
-ALIAS: <time_t> <long>
\ No newline at end of file
index 2bebc981f95baf00e39b5fae00747624ac972052..fc435cd9fbf878e42a49c065a550b17230c1ef45 100644 (file)
@@ -33,7 +33,3 @@ TYPEDEF: char[512] io_string_t
 TYPEDEF: kern_return_t IOReturn
 
 TYPEDEF: uint IOOptionBits
-
-
-
-ALIAS: <time_t> <long>
index 7dacc97061e492d1445f7a0bfa96d14fe0f65363..58fd5d400b21ce13ee2dd9ddcaa4e3e600b44821 100644 (file)
@@ -17,8 +17,6 @@ TYPEDEF: long           ssize_t
 TYPEDEF: int            pid_t
 TYPEDEF: int            time_t
 
-ALIAS: <time_t> <int>
-
 cell-bits {
     { 32 [ "unix.types.netbsd.32" require ] }
     { 64 [ "unix.types.netbsd.64" require ] }
index 7c8fbd2b9d825a01261fd259ac1b208eece71348..30bc539207d6af4ac33778b218a43fddaddcaf3a 100644 (file)
@@ -17,5 +17,3 @@ TYPEDEF: __uint32_t     fflags_t
 TYPEDEF: long           ssize_t
 TYPEDEF: int            pid_t
 TYPEDEF: int            time_t
-
-ALIAS: <time_t> <int>
\ No newline at end of file
index a0b2b264f7d9a7d9bc016c833873411e5845661f..fe0c3e853d985655d8eb303f5ae8231a77b3c47e 100644 (file)
@@ -20,7 +20,7 @@ HELP: new-passwd
 { $description "Creates a new passwd tuple dependent on the operating system." } ;
 
 HELP: passwd
-{ $description "A platform-specific tuple correspding to every field from the Unix passwd struct. BSD passwd structures have four extra slots: " { $slot "change" } ", " { $slot "class" } "," { $slot "expire" } ", " { $slot "fields" } "." } ;
+{ $description "A platform-specific tuple corresponding to every field from the Unix passwd struct. BSD passwd structures have four extra slots: " { $slot "change" } ", " { $slot "class" } ", " { $slot "expire" } ", " { $slot "fields" } "." } ;
 
 HELP: user-cache
 { $description "A symbol storing passwd structures indexed by user-ids when within a " { $link with-user-cache } "." } ;
@@ -82,7 +82,7 @@ HELP: with-real-user
 
 {
     real-user-name real-user-id set-real-user
-    effective-user-name effective-user-id          
+    effective-user-name effective-user-id
     set-effective-user
 } related-words
 
@@ -95,7 +95,7 @@ HELP: ?user-id
 
 HELP: all-user-names
 { $values
-    
+
     { "seq" sequence }
 }
 { $description "Returns a sequence of group names as strings." } ;
index 919b2ae8a2eabafebba8722633dbb30dbc8d1b63..cd32c91d3cbab2b0fd7934c28c859fddf32d0d6f 100644 (file)
@@ -8,14 +8,14 @@ IN: unix.utilities
 SPECIALIZED-ARRAY: void*
 
 : more? ( alien -- ? )
-    { [ ] [ *void* ] } 1&& ;
+    { [ ] [ void* deref ] } 1&& ;
 
 : advance ( void* -- void* )
     cell swap <displaced-alien> ;
 
 : alien>strings ( alien encoding -- strings )
     [ [ dup more? ] ] dip
-    '[ [ advance ] [ *void* _ alien>string ] bi ]
+    '[ [ advance ] [ void* deref _ alien>string ] bi ]
     produce nip ;
 
 : strings>alien ( strings encoding -- array )
index 39ce5c7bcac9c32eb42aa815d5adccead4454a1a..1f2b6e8e47f23d70d6b42ee764932400bc3da4c9 100644 (file)
@@ -1,4 +1,4 @@
-USING: strings help.markup help.syntax assocs ;
+USING: strings help.markup help.syntax assocs urls ;
 IN: urls.encoding
 
 HELP: url-decode
index a66ba146941fd201179bfe97109f711a4028f3e5..c177196786e534f72304757c00f8fa3654842e26 100644 (file)
@@ -76,7 +76,7 @@ HELP: ensure-port
 } ;
 
 HELP: parse-host
-{ $values { "string" string } { "host" string } { "port" { $maybe integer } } }
+{ $values { "string" string } { "host/f" { $maybe string } } { "port/f" { $maybe integer } } }
 { $description "Splits a string of the form " { $snippet "host:port" } " into a host and a port number. If the port number is not specified, outputs " { $link f } "." }
 { $notes "This word is used by " { $link >url } ". It can also be used directly to parse " { $snippet "host:port" } " strings which are not full URLs." }
 { $examples
index 0f89ba0d9f062f5d478b953664217285906cf3bf..19aea0fdaca2ec5b059afc5b891531390bf231a5 100644 (file)
@@ -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: kernel ascii combinators combinators.short-circuit
 sequences splitting fry namespaces make assocs arrays strings
@@ -24,14 +24,12 @@ TUPLE: url protocol username password host port path query anchor ;
         nip delete-query-param
     ] if ;
 
-: parse-host ( string -- host port )
+ERROR: malformed-port ;
+
+: parse-host ( string -- host/f port/f )
     [
-        ":" split1 [ url-decode ] [
-            dup [
-                string>number
-                dup [ "Invalid port" throw ] unless
-            ] when
-        ] bi*
+        ":" split1-last [ url-decode ]
+        [ dup [ string>number [ malformed-port ] unless* ] when ] bi*
     ] [ f f ] if* ;
 
 GENERIC: >url ( obj -- url )
@@ -68,22 +66,22 @@ url      = ((protocol "://")        => [[ first ]] auth hostname)?
 PRIVATE>
 
 M: string >url
+    [ <url> ] dip
     parse-url {
         [
             first [
-                [ first ] ! protocol
+                [ first >>protocol ]
                 [
                     second
-                    [ first [ first2 ] [ f f ] if* ] ! username, password
-                    [ second parse-host ] ! host, port
-                    bi
+                    [ first [ first2 [ >>username ] [ >>password ] bi* ] when* ]
+                    [ second parse-host [ >>host ] [ >>port ] bi* ] bi
                 ] bi
-            ] [ f f f f f ] if*
+            ] when*
         ]
-        [ second ] ! pathname
-        [ third ] ! query
-        [ fourth ] ! anchor
-    } cleave url boa
+        [ second >>path ]
+        [ third >>query ]
+        [ fourth >>anchor ]
+    } cleave
     dup host>> [ [ "/" or ] change-path ] when ;
 
 : protocol-port ( protocol -- port )
@@ -177,6 +175,9 @@ PRIVATE>
     ] [ protocol>> ] bi
     secure-protocol? [ >secure-addr ] when ;
 
+: set-url-addr ( url addr -- url )
+    [ host>> >>host ] [ port>> >>port ] bi ;
+
 : ensure-port ( url -- url' )
     clone dup protocol>> '[ _ protocol-port or ] change-port ;
 
@@ -186,3 +187,4 @@ SYNTAX: URL" lexer get skip-blank parse-string >url suffix! ;
 USE: vocabs.loader
 
 { "urls" "prettyprint" } "urls.prettyprint" require-when
+{ "urls" "io.sockets.secure" } "urls.secure" require-when
index fdc48adfbe5fc8fb2ea9fae2a9e5c8a0affa56ec..f11c930c856d744074ee28039b26879ca586eac7 100644 (file)
@@ -1,7 +1,8 @@
 USING: kernel windows.com windows.com.syntax windows.ole32
-windows.types alien alien.syntax tools.test libc alien.c-types
-namespaces arrays continuations accessors math windows.com.wrapper
-windows.com.wrapper.private destructors effects compiler.units ;
+windows.types alien alien.data alien.syntax tools.test libc
+alien.c-types namespaces arrays continuations accessors math
+windows.com.wrapper windows.com.wrapper.private destructors
+effects compiler.units ;
 IN: windows.com.tests
 
 COM-INTERFACE: ISimple IUnknown {216fb341-0eb2-44b1-8edb-60b76e353abc}
@@ -58,7 +59,7 @@ C: <test-implementation> test-implementation
         dup +guinea-pig-implementation+ set [ drop
 
             S_OK 1array [ +guinea-pig-implementation+ get ISimple::returnOK ] unit-test
-            E_FAIL <long> *long 1array [ +guinea-pig-implementation+ get ISimple::returnError ] unit-test
+            E_FAIL long <ref> long deref 1array [ +guinea-pig-implementation+ get ISimple::returnError ] unit-test
             20 1array [
                 +guinea-pig-implementation+ get
                 [ 20 IInherited::setX ]
old mode 100644 (file)
new mode 100755 (executable)
index dc6a060..2710599
@@ -1,6 +1,6 @@
-USING: alien alien.c-types alien.accessors alien.parser
-effects kernel windows.ole32 parser lexer splitting grouping
-sequences namespaces assocs quotations generalizations
+USING: alien alien.c-types alien.data alien.accessors
+alien.parser effects kernel windows.ole32 parser lexer splitting
+grouping sequences namespaces assocs quotations generalizations
 accessors words macros alien.syntax fry arrays layouts math
 classes.struct windows.kernel32 locals ;
 FROM: alien.parser.private => parse-pointers return-type-name ;
@@ -11,7 +11,7 @@ IN: windows.com.syntax
 MACRO: com-invoke ( n return parameters -- )
     [ 2nip length ] 3keep
     '[
-        _ npick *void* _ cell * alien-cell _ _
+        _ npick void* deref _ cell * alien-cell _ _
         stdcall alien-indirect
     ] ;
 
index cb00dde66b337d0fb83e234906b6a0e808c36063..9beb3bd9a6fec2925289272c9b37d8aa8291ce12 100644 (file)
@@ -1,6 +1,6 @@
 ! Copyright (C) 2010 Doug Coleman.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: accessors alien alien.c-types alien.syntax
+USING: accessors alien alien.c-types alien.data alien.syntax
 classes.struct io.encodings.string io.encodings.utf8 kernel
 make sequences windows.errors windows.types ;
 IN: windows.iphlpapi
@@ -63,7 +63,7 @@ TYPEDEF: FIXED_INFO* PFIXED_INFO
 FUNCTION: DWORD GetNetworkParams ( PFIXED_INFO pFixedInfo, PULONG pOutBufLen ) ;
 
 : get-fixed-info ( -- FIXED_INFO )
-    FIXED_INFO <struct> dup byte-length <ulong>
+    FIXED_INFO <struct> dup byte-length ulong <ref>
     [ GetNetworkParams n>win32-error-check ] 2keep drop ;
     
 : dns-server-ips ( -- sequence )
@@ -72,4 +72,4 @@ FUNCTION: DWORD GetNetworkParams ( PFIXED_INFO pFixedInfo, PULONG pOutBufLen ) ;
             [ IpAddress>> String>> [ 0 = ] trim-tail utf8 decode , ]
             [ Next>> ] bi dup
         ] loop drop
-    ] { } make ;
\ No newline at end of file
+    ] { } make ;
index 25c80061b2e464cd82bbf0e01a89e4ff2d751c6e..1d6a302b2aabebae806b6d47f4923bcba00a7428 100644 (file)
@@ -13,7 +13,7 @@ samDesired lpSecurityAttributes phkResult lpdwDisposition ;
 CONSTANT: registry-value-max-length 16384
 
 :: open-key ( key subkey mode -- hkey )
-    key subkey 0 mode HKEY <c-object>
+    key subkey 0 mode 0 HKEY <ref>
     [
         RegOpenKeyEx dup ERROR_SUCCESS = [
             drop
@@ -21,16 +21,16 @@ CONSTANT: registry-value-max-length 16384
             [ key subkey mode ] dip n>win32-error-string
             open-key-failed
         ] if
-    ] keep *uint ;
+    ] keep HKEY deref ;
 
 :: create-key* ( hKey lpSubKey lpClass dwOptions samDesired lpSecurityAttributes -- hkey new? )
-    hKey lpSubKey 0 lpClass dwOptions samDesired lpSecurityAttributes
-    HKEY <c-object>
-    DWORD <c-object>
     f :> ret!
+    hKey lpSubKey 0 lpClass dwOptions samDesired lpSecurityAttributes
+    0 HKEY <ref>
+    0 DWORD <ref>
     [ RegCreateKeyEx ret! ] 2keep
-    [ *uint ]
-    [ *uint REG_CREATED_NEW_KEY = ] bi*
+    [ HKEY deref ]
+    [ DWORD deref REG_CREATED_NEW_KEY = ] bi*
     ret ERROR_SUCCESS = [
         [
             hKey lpSubKey 0 lpClass dwOptions samDesired
@@ -67,11 +67,11 @@ CONSTANT: registry-value-max-length 16384
     length 2 * <byte-array> ;
 
 :: reg-query-value-ex ( key subkey ptr1 ptr2 buffer -- buffer )
-    buffer length <uint> :> pdword
+    buffer length uint <ref> :> pdword
     key subkey ptr1 ptr2 buffer pdword [ RegQueryValueEx ] 2keep
     rot :> ret
     ret ERROR_SUCCESS = [
-        *uint head
+        uint deref head
     ] [
         ret ERROR_MORE_DATA = [
             2drop
@@ -103,9 +103,9 @@ TUPLE: registry-enum-key ;
         registry-value-max-length TCHAR <c-array> dup :> registry-value
         registry-value length dup :> registry-value-length
         f
-        DWORD <c-object> dup :> type
-        f ! BYTE <c-object> dup :> data
-        f ! BYTE <c-object> dup :> buffer
+        0 DWORD <ref> dup :> type
+        f ! 0 BYTE <ref> dup :> data
+        f ! 0 BYTE <ref> dup :> buffer
         RegEnumKeyEx dup ERROR_SUCCESS = [
             
         ] [
@@ -116,27 +116,27 @@ TUPLE: registry-enum-key ;
     key
     MAX_PATH
     dup TCHAR <c-array> dup :> class-buffer
-    swap <int> dup :> class-buffer-length
+    swap int <ref> dup :> class-buffer-length
     f
-    DWORD <c-object> dup :> sub-keys
-    DWORD <c-object> dup :> longest-subkey
-    DWORD <c-object> dup :> longest-class-string
-    DWORD <c-object> dup :> #values
-    DWORD <c-object> dup :> max-value
-    DWORD <c-object> dup :> max-value-data
-    DWORD <c-object> dup :> security-descriptor
+    0 DWORD <ref> dup :> sub-keys
+    0 DWORD <ref> dup :> longest-subkey
+    0 DWORD <ref> dup :> longest-class-string
+    0 DWORD <ref> dup :> #values
+    0 DWORD <ref> dup :> max-value
+    0 DWORD <ref> dup :> max-value-data
+    0 DWORD <ref> dup :> security-descriptor
     FILETIME <struct> dup :> last-write-time
     RegQueryInfoKey :> ret
     ret ERROR_SUCCESS = [
         key
         class-buffer
-        sub-keys *uint
-        longest-subkey *uint
-        longest-class-string *uint
-        #values *uint
-        max-value *uint
-        max-value-data *uint
-        security-descriptor *uint
+        sub-keys uint deref
+        longest-subkey uint deref
+        longest-class-string uint deref
+        #values uint deref
+        max-value uint deref
+        max-value-data uint deref
+        security-descriptor uint deref
         last-write-time FILETIME>timestamp
         registry-info boa
     ] [
@@ -191,4 +191,4 @@ PRIVATE>
     21 2^ <byte-array> reg-query-value-ex ;
     
 : read-registry ( key subkey -- registry-info )
-    KEY_READ [ reg-query-info-key ] with-open-registry-key ;
\ No newline at end of file
+    KEY_READ [ reg-query-info-key ] with-open-registry-key ;
index cde6c11efb48368dea59e67cbde75f0ad0e73071..4c6593f92187709c2ba229e5f94f3c5630ce1a94 100755 (executable)
@@ -42,9 +42,9 @@ TUPLE: script-string < disposable font string metrics ssa size image ;
     f ! piDx
     f ! pTabdef
     f ! pbInClass
-    f <void*> ! pssa
+    f void* <ref> ! pssa
     [ ScriptStringAnalyse ] keep
-    [ ole32-error ] [ |ScriptStringFree *void* ] bi* ;
+    [ ole32-error ] [ |ScriptStringFree void* deref ] bi* ;
 
 : set-dc-colors ( dc font -- )
     [ background>> color>RGB SetBkColor drop ]
@@ -103,7 +103,7 @@ TUPLE: script-string < disposable font string metrics ssa size image ;
 PRIVATE>
 
 M: script-string dispose*
-    ssa>> <void*> ScriptStringFree ole32-error ;
+    ssa>> void* <ref> ScriptStringFree ole32-error ;
 
 SYMBOL: cached-script-strings
 
index 496b9d688c3ea9ee381e4f6bcf836a59d1d2b69f..319ca4671421d1be7ea8bd5cda39d71698eb0ccb 100644 (file)
@@ -1,7 +1,7 @@
 ! Copyright (C) 2006, 2010 Slava Pestov
 ! See http://factorcode.org/license.txt for BSD license.
-USING: accessors alien.c-types alien.strings classes.struct
-io.encodings.utf8 kernel namespaces sequences
+USING: accessors alien.c-types alien.data alien.strings
+classes.struct io.encodings.utf8 kernel namespaces sequences
 specialized-arrays x11 x11.constants x11.xlib ;
 SPECIALIZED-ARRAY: int
 IN: x11.clipboard
@@ -28,11 +28,11 @@ TUPLE: x-clipboard atom contents ;
     CurrentTime XConvertSelection drop ;
 
 : snarf-property ( prop-return -- string )
-    dup *void* [ *void* utf8 alien>string ] [ drop f ] if ;
+    dup void* deref [ void* deref utf8 alien>string ] [ drop f ] if ;
 
 : window-property ( win prop delete? -- string )
     [ [ dpy get ] 2dip 0 -1 ] dip AnyPropertyType
-    0 <Atom> 0 <int> 0 <ulong> 0 <ulong> f <void*>
+    0 Atom <ref> 0 int <ref> 0 ulong <ref> 0 ulong <ref> f void* <ref>
     [ XGetWindowProperty drop ] keep snarf-property ;
 
 : selection-from-event ( event window -- string )
@@ -53,7 +53,7 @@ TUPLE: x-clipboard atom contents ;
     [ dpy get ] dip
     [ requestor>> ]
     [ property>> XA_TIMESTAMP 32 PropModeReplace ]
-    [ time>> <int> ] tri
+    [ time>> int <ref> ] tri
     1 XChangeProperty drop ;
 
 : send-notify ( evt prop -- )
index 1becb30f45f352bee99b62a50b2511729226d3bb..72c0670482d96de5cd0d3fd11b43cba6a3a6e5fc 100644 (file)
@@ -1,8 +1,8 @@
 ! Copyright (C) 2005, 2010 Eduardo Cavazos, Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: accessors kernel math math.bitwise math.vectors
-namespaces sequences arrays fry classes.struct literals
-x11 x11.xlib x11.constants x11.events
+USING: accessors alien.c-types alien.data kernel math
+math.bitwise math.vectors namespaces sequences arrays fry
+classes.struct literals x11 x11.xlib x11.constants x11.events
 x11.glx ;
 IN: x11.windows
 
@@ -79,7 +79,7 @@ CONSTANT: event-mask
     dpy get swap XDestroyWindow drop ;
 
 : set-closable ( win -- )
-    dpy get swap XA_WM_DELETE_WINDOW <Atom> 1
+    dpy get swap XA_WM_DELETE_WINDOW Atom <ref> 1
     XSetWMProtocols drop ;
 
 : map-window ( win -- ) dpy get swap XMapWindow drop ;
index 06add388b18fa4744551f61c0e93110cd4e2f7b3..b9248bac05c584fcb630dd89f69ff3311843d37f 100644 (file)
@@ -1,8 +1,8 @@
 ! Copyright (C) 2007, 2008 Slava Pestov
 ! See http://factorcode.org/license.txt for BSD license.
-USING: alien alien.c-types alien.strings arrays byte-arrays
-hashtables io io.encodings.string kernel math namespaces
-sequences strings continuations x11 x11.xlib
+USING: alien alien.c-types alien.data alien.strings arrays
+byte-arrays hashtables io io.encodings.string kernel math
+namespaces sequences strings continuations x11 x11.xlib
 specialized-arrays accessors io.encodings.utf16n ;
 SPECIALIZED-ARRAY: uint
 IN: x11.xim
@@ -42,7 +42,7 @@ SYMBOL: keysym
 
 : prepare-lookup ( -- )
     buf-size <uint-array> keybuf set
-    0 <KeySym> keysym set ;
+    0 KeySym <ref> keysym set ;
 
 : finish-lookup ( len -- string keysym )
     keybuf get swap 2 * head utf16n decode
@@ -51,7 +51,7 @@ SYMBOL: keysym
 : lookup-string ( event xic -- string keysym )
     [
         prepare-lookup
-        swap keybuf get buf-size keysym get 0 <int>
+        swap keybuf get buf-size keysym get 0 int <ref>
         XwcLookupString
         finish-lookup
     ] with-scope ;
index 80aaf95d63e729f418ee393e8837fd715ca759eb..5e38d70cb6e8f0e5d5a2339f884f1f5b26bd85d2 100644 (file)
@@ -1,11 +1,11 @@
 ! Copyright (C) 2010 Niklas Waern.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: alien.c-types combinators kernel namespaces x11
-x11.constants x11.xinput2.ffi ;
+USING: alien.c-types alien.data combinators kernel namespaces
+x11 x11.constants x11.xinput2.ffi ;
 IN: x11.xinput2
 
 : (xi2-available?) ( display -- ? )
-    2 0 [ <int> ] bi@
+    2 0 [ int <ref> ] bi@
     XIQueryVersion
     {
         { BadRequest [ f ] }
index e20314bf11ac7b9c8a78d37bfeb79e5e14747b24..33293746c5aa50164e568480bb45610ca20378ce 100644 (file)
@@ -48,17 +48,11 @@ TYPEDEF: int Bool
 TYPEDEF: ulong VisualID
 TYPEDEF: ulong Time
 
-ALIAS: <XID> <ulong>
-ALIAS: <Window> <XID>
-ALIAS: <Drawable> <XID>
-ALIAS: <KeySym> <XID>
-ALIAS: <Atom> <ulong>
-
-ALIAS: *XID *ulong
+: *XID ( bytes -- n ) ulong deref ;
 ALIAS: *Window *XID
 ALIAS: *Drawable *XID
 ALIAS: *KeySym *XID
-ALIAS: *Atom *ulong
+: *Atom ( bytes -- n ) ulong deref ;
 !
 ! 2 - Display Functions
 !
index 2439f03aac33468ba38247b984d0ced53c302e94..9fee74897c10e6a62d1b4caf58d1a12aa75ad06d 100644 (file)
@@ -298,6 +298,10 @@ HELP: assoc-all?
 { $values { "assoc" assoc } { "quot" { $quotation "( ... key value -- ... ? )" } } { "?" "a boolean" } }
 { $description "Tests if all entries in the assoc satisfy a predicate by applying the quotation to each entry in turn. a predicate quotation to entry in the assoc. Iteration stops if an entry is found for which the quotation outputs " { $link f } ". If the assoc is empty, always outputs " { $link t } "." } ;
 
+HELP: assoc-refine
+{ $values { "seq" sequence } { "assoc" assoc } }
+{ $description "Outputs the intersection of all the assocs of the assocs sequence " { $snippet "seq" } ", or " { $link f } " if " { $snippet "seq" } " is empty." } ;
+
 HELP: assoc-subset?
 { $values { "assoc1" assoc } { "assoc2" assoc } { "?" "a new assoc" } }
 { $description "Tests if " { $snippet "assoc2" } " contains all key/value pairs of " { $snippet "assoc1" } "." } ;
index 58a2a29eb10bdb3d135aa485b331905068a794a6..0508d2e5696df81380b275154a00ffb6a56640f8 100644 (file)
@@ -117,7 +117,7 @@ M: assoc assoc-clone-like ( assoc exemplar -- newassoc )
     [ at* [ = ] [ 2drop f ] if ] with-assoc assoc-all? ;
 
 : assoc= ( assoc1 assoc2 -- ? )
-    [ assoc-subset? ] [ swap assoc-subset? ] 2bi and ;
+    2dup [ assoc-size ] bi@ eq? [ assoc-subset? ] [ 2drop f ] if ;
 
 : assoc-hashcode ( n assoc -- code )
     >alist hashcode* ;
index 8e3af26932377db2c1a3cf7bfae6f083d0b75e8e..90b48c6a375db455fb447dfddf3c4929c5e65e73 100755 (executable)
@@ -491,7 +491,6 @@ tuple
     { "bignum>" "math.private" "primitive_bignum_greater" (( x y -- ? )) }
     { "bignum>=" "math.private" "primitive_bignum_greatereq" (( x y -- ? )) }
     { "bignum>fixnum" "math.private" "primitive_bignum_to_fixnum" (( x -- y )) }
-    { "bignum>float" "math.private" "primitive_bignum_to_float" (( x -- y )) }
     { "fixnum-shift" "math.private" "primitive_fixnum_shift" (( x y -- z )) }
     { "fixnum/i" "math.private" "primitive_fixnum_divint" (( x y -- z )) }
     { "fixnum/mod" "math.private" "primitive_fixnum_divmod" (( x y -- z w )) }
index f913ca5fec372e52c38fe7b2d4087a46a64953d6..c4c65c6209c57c93ba33eefa31b23d25cec3b8e9 100644 (file)
@@ -50,7 +50,7 @@ HELP: class<=
 { $notes "Classes are partially ordered. This means that if " { $snippet "class1 <= class2" } " and " { $snippet "class2 <= class1" } ", then " { $snippet "class1 = class2" } ". Also, if " { $snippet "class1 <= class2" } " and " { $snippet "class2 <= class3" } ", then " { $snippet "class1 <= class3" } "." } ;\r
 \r
 HELP: sort-classes\r
-{ $values { "seq" "a sequence of class" } { "newseq" "a new seqence of classes" } }\r
+{ $values { "seq" "a sequence of class" } { "newseq" "a new sequence of classes" } }\r
 { $description "Outputs a linear sort of a sequence of classes. Larger classes come before their subclasses." } ;\r
 \r
 HELP: class-or\r
index 037ecf8715f98f18923fcf04d1caeaf06e275549..7443e02cc5cef07fe05b4abb1ce2278704eb0f5d 100644 (file)
@@ -190,7 +190,7 @@ $nl
 { $subsections
     "tuple-inheritance-example"
     "tuple-inheritance-anti-example"
-} 
+}
 "Declaring a tuple class final prohibits other classes from subclassing it:"
 { $subsections POSTPONE: final }
 { $see-also "call-next-method" "parametrized-constructors" "unions" "mixins" } ;
@@ -215,12 +215,14 @@ ARTICLE: "tuple-examples" "Tuple examples"
 { $table
     { "Reader" "Writer" "Setter" "Changer" }
     { { $snippet "name>>" } { $snippet "name<<" } { $snippet ">>name" } { $snippet "change-name" } }
+    { { $snippet "position>>" } { $snippet "position<<" } { $snippet ">>position" } { $snippet "change-position" } }
     { { $snippet "salary>>" } { $snippet "salary<<" } { $snippet ">>salary" } { $snippet "change-salary" } }
-    { { $snippet "position>>" } { $snippet "position<<" } { $snippet ">>position" } { $snippet "change-position" }   }
 }
 "We can define a constructor which makes an empty employee:"
-{ $code ": <employee> ( -- employee )"
-    "    employee new ;" }
+{ $code
+    ": <employee> ( -- employee )"
+    "    employee new ;"
+}
 "Or we may wish the default constructor to always give employees a starting salary:"
 { $code
     ": <employee> ( -- employee )"
index 67bf6da23c97806f300061c2ae0a7df9246fc5ee..23ead78d94f2332d30815c2745511c0c91c77baa 100644 (file)
@@ -150,7 +150,7 @@ $nl
 { $example "USE: classes" "\\ f class ." "word" }
 "On the other hand, " { $link t } " is just a word, and there is no class which it is a unique instance of."
 { $example "t \\ t eq? ." "t" }
-"Many words which search collections confuse the case of no element being present with an element being found equal to " { $link f } ". If this distinction is imporant, there is usually an alternative word which can be used; for example, compare " { $link at } " with " { $link at* } "." ;
+"Many words which search collections confuse the case of no element being present with an element being found equal to " { $link f } ". If this distinction is important, there is usually an alternative word which can be used; for example, compare " { $link at } " with " { $link at* } "." ;
 
 ARTICLE: "conditionals-boolean-equivalence" "Expressing conditionals with boolean logic"
 "Certain simple conditional forms can be expressed in a simpler manner using boolean logic."
@@ -253,7 +253,7 @@ HELP: execute-effect-unsafe
 { $values { "word" word } { "effect" effect } }
 { $description "Given a word and a stack effect, executes the word, blindly declaring at runtime that it has the given stack effect. This is a macro which expands given a literal effect parameter, and an arbitrary word which is not required at compile time." }
 { $warning "If the word being executed has an incorrect stack effect, undefined behavior will result. User code should use " { $link POSTPONE: execute( } " instead." } ;
-    
+
 { call-effect call-effect-unsafe execute-effect execute-effect-unsafe } related-words
 
 HELP: cleave
@@ -344,7 +344,7 @@ HELP: case
 { $description
     "Compares " { $snippet "obj" } " against the first element of every pair, first evaluating the first element if it is a word. If some pair matches, removes " { $snippet "obj" } " from the stack and calls the second element of that pair, which must be a quotation."
     $nl
-    "If there is no case matching " { $snippet "obj" } ", the default case is taken. If the last element of " { $snippet "cases" } " is a quotation, the quotation is called with " { $snippet "obj" } " on the stack. Otherwise, a " { $link no-cond } " error is rasied."
+    "If there is no case matching " { $snippet "obj" } ", the default case is taken. If the last element of " { $snippet "cases" } " is a quotation, the quotation is called with " { $snippet "obj" } " on the stack. Otherwise, a " { $link no-cond } " error is raised."
     $nl
     "The following two phrases are equivalent:"
     { $code "{ { X [ Y ] } { Z [ T ] } } case" }
@@ -372,10 +372,10 @@ HELP: recursive-hashcode
 
 HELP: cond>quot
 { $values { "assoc" "a sequence of pairs of quotations" } { "quot" quotation } }
-{ $description  "Creates a quotation that when called, has the same effect as applying " { $link cond } " to " { $snippet "assoc" } "."
+{ $description "Creates a quotation that when called, has the same effect as applying " { $link cond } " to " { $snippet "assoc" } "."
 $nl
 "The generated quotation is more efficient than the naive implementation of " { $link cond } ", though, since it expands into a series of conditionals, and no iteration through " { $snippet "assoc" } " has to be performed." }
-{ $notes "This word is used behind the scenes to compile " { $link cond } " forms efficiently; it can also be called directly,  which is useful for meta-programming." } ;
+{ $notes "This word is used behind the scenes to compile " { $link cond } " forms efficiently; it can also be called directly, which is useful for meta-programming." } ;
 
 HELP: case>quot
 { $values { "default" quotation } { "assoc" "a sequence of pairs of quotations" } { "quot" quotation } }
index dfecf75f90a5d35d1cea19dde5d7e174f7a70d73..300c9c63bc84da51c0f0f7ce2891b05b7c187857 100644 (file)
@@ -131,7 +131,7 @@ HELP: >continuation<
 
 HELP: ifcc
 { $values { "capture" { $quotation "( continuation -- )" } } { "restore" quotation } }
-{ $description "Reifies a continuation from the point immediately after which this word returns, and passes it to " { $snippet "capture" } ". When the continuation is restored, execution resumes and "{ $snippet "restore" } " is called." } ;
+{ $description "Reifies a continuation from the point immediately after which this word returns, and passes it to " { $snippet "capture" } ". When the continuation is restored, execution resumes and " { $snippet "restore" } " is called." } ;
 
 { callcc0 continue callcc1 continue-with ifcc } related-words
 
index db33aaa2440491aa513c864194f8a00ee6690721..44d216f87215e93659d60c5559cc3c7f1c4d4293 100644 (file)
@@ -19,7 +19,7 @@ $nl
 "Inputs and outputs are typically named after some pun on their data type, or a description of the value's purpose if the type is very general. The following are some examples of value names:"
 { $table
     { { { $snippet "?" } } "a boolean" }
-    { { { $snippet "<=>" } } { "an ordering sepcifier; see " { $link "order-specifiers" } } }
+    { { { $snippet "<=>" } } { "an ordering specifier; see " { $link "order-specifiers" } } }
     { { { $snippet "elt" } } "an object which is an element of a sequence" }
     { { { $snippet "m" } ", " { $snippet "n" } } "an integer" }
     { { { $snippet "obj" } } "an object" }
index 8d4f1f61a5fe94295c56b511d612f938b66a7a2a..c9673a95b8fec75f071f2226cebaecb5f50e97dd 100644 (file)
@@ -129,7 +129,7 @@ HELP: define-generic
 HELP: M\
 { $syntax "M\\ class generic" }
 { $class-description "Pushes a method on the stack." }
-{ $examples { $code "M\\ fixnum + see" } { $code "USING: ui.gadgets ui.gadgets.editors ;" "M\\ editor draw-gadget* edit" } } ;
+{ $examples { $code "M\\ fixnum + see" } { $code "USING: ui.gadgets.editors ui.render ;" "M\\ editor draw-gadget* edit" } } ;
 
 HELP: method
 { $values { "class" class } { "generic" generic } { "method/f" { $maybe method } } }
index ac198a2ca2023a3ce4813a991fc125b3c7f9e12d..028c324f6a8164669df4f53dfa7a8de54fb76207 100644 (file)
@@ -19,6 +19,7 @@ M: hash-set members table>> keys ; inline
 M: hash-set set-like drop dup hash-set? [ members <hash-set> ] unless ;
 M: hash-set clone table>> clone hash-set boa ;
 M: hash-set null? table>> assoc-empty? ;
+M: hash-set cardinality table>> assoc-size ;
 
 M: sequence fast-set <hash-set> ;
 M: f fast-set drop H{ } clone hash-set boa ;
index be5aa97634e02423ffff8382fa9ad96f14d3ebd4..e7acf1245439d421bc4ac01cea5d392c9759b80f 100644 (file)
@@ -151,10 +151,7 @@ M: hashtable clone
     (clone) [ clone ] change-array ; inline
 
 M: hashtable equal?
-    over hashtable? [
-        2dup [ assoc-size ] bi@ eq?
-        [ assoc= ] [ 2drop f ] if
-    ] [ 2drop f ] if ;
+    over hashtable? [ assoc= ] [ 2drop f ] if ;
 
 ! Default method
 M: assoc new-assoc drop <hashtable> ; inline
index 1339cc6090f23dbad541008787e99a23b6422105..443de70132046645ac5b6030c549ab78274e83c3 100644 (file)
@@ -6,7 +6,7 @@ ARTICLE: "stream-binary" "Working with binary data"
 $nl
 "There are two ways to order the bytes making up an integer; " { $emphasis "little endian" } " byte order outputs the least significant byte first, and the most significant byte last, whereas " { $emphasis "big endian" } " is the other way around."
 $nl
-"Consider the hexadecimal integer "{ $snippet "HEX: cafebabe" } ". Little endian byte order yields the following sequence of bytes:"
+"Consider the hexadecimal integer " { $snippet "HEX: cafebabe" } ". Little endian byte order yields the following sequence of bytes:"
 { $table
     { "Byte:" "1" "2" "3" "4" }
     { "Value:" { $snippet "be" } { $snippet "ba" } { $snippet "fe" } { $snippet "ca" } }
index 9f3f35ff2a7136f01ab3256eee86f100e025d970..96c4c29265b50ac31ea84a4cfcb7a29f6d356ba1 100644 (file)
@@ -1,4 +1,4 @@
-USING: accessors alien.c-types kernel
+USING: accessors alien.c-types alien.data kernel
 io.encodings.utf16 io.streams.byte-array tools.test ;
 IN: io.encodings.utf16n
 
index 11848cfa0369fbd1792dae53b661ee9a70c68701..86f27f5186ec4172626a56c621b2ecb5c9a44655 100644 (file)
@@ -12,7 +12,7 @@ ARTICLE: "stream-types" "Binary and text streams"
 $nl
 "Binary streams have an element type of " { $link +byte+ } ". Elements are integers in the range " { $snippet "[0,255]" } ", representing bytes. Reading a sequence of elements produces a " { $link byte-array } ". Any object implementing the " { $link >c-ptr } " and " { $link byte-length } " generic words can be written to a binary stream."
 $nl
-"Character streams have an element tye of " { $link +character+ } ". Elements are non-negative integers, representing Unicode code points. Only instances of the " { $link string } " class can be read or written on a character stream."
+"Character streams have an element type of " { $link +character+ } ". Elements are non-negative integers, representing Unicode code points. Only instances of the " { $link string } " class can be read or written on a character stream."
 $nl
 "Most external streams are binary streams, and can be wrapped in string streams once a suitable encoding has been provided; see " { $link "io.encodings" } "." ;
 
@@ -89,7 +89,7 @@ $io-error ;
 
 HELP: stream-copy
 { $values { "in" "an input stream" } { "out" "an output stream" } }
-{ $description "Copies the contents of one stream into another, closing both streams when done." } 
+{ $description "Copies the contents of one stream into another, closing both streams when done." }
 $io-error ;
 
 HELP: stream-tell
@@ -112,21 +112,21 @@ HELP: stream-seek
 
 HELP: seek-absolute
 { $values
-    
+
      { "value" "a seek singleton" }
 }
 { $description "Seeks to an offset from the beginning of the stream." } ;
 
 HELP: seek-end
 { $values
-    
+
      { "value" "a seek singleton" }
 }
 { $description "Seeks to an offset from the end of the stream. If the offset puts the stream pointer past the end of the data on an output stream, writing to it will pad the difference with zeros." } ;
 
 HELP: seek-relative
 { $values
-    
+
      { "value" "a seek singleton" }
 }
 { $description "Seeks to an offset from the current position of the stream pointer." } ;
@@ -203,19 +203,19 @@ $io-error ;
 
 HELP: with-input-stream
 { $values { "stream" "an input stream" } { "quot" quotation } }
-{ $description "Calls the quotation in a new dynamic scope, with " { $link input-stream } " rebound to  " { $snippet "stream" } ". The stream is closed if the quotation returns or throws an error." } ;
+{ $description "Calls the quotation in a new dynamic scope, with " { $link input-stream } " rebound to " { $snippet "stream" } ". The stream is closed if the quotation returns or throws an error." } ;
 
 HELP: with-output-stream
 { $values { "stream" "an output stream" } { "quot" quotation } }
-{ $description "Calls the quotation in a new dynamic scope, with " { $link output-stream } " rebound to  " { $snippet "stream" } ". The stream is closed if the quotation returns or throws an error." } ;
+{ $description "Calls the quotation in a new dynamic scope, with " { $link output-stream } " rebound to " { $snippet "stream" } ". The stream is closed if the quotation returns or throws an error." } ;
 
 HELP: with-streams
 { $values { "input" "an input stream" } { "output" "an output stream" } { "quot" quotation } }
-{ $description "Calls the quotation in a new dynamic scope, with " { $link input-stream } " rebound to  " { $snippet "input" } " and " { $link output-stream } " rebound to  " { $snippet "output" } ". The stream is closed if the quotation returns or throws an error." } ;
+{ $description "Calls the quotation in a new dynamic scope, with " { $link input-stream } " rebound to " { $snippet "input" } " and " { $link output-stream } " rebound to " { $snippet "output" } ". The stream is closed if the quotation returns or throws an error." } ;
 
 HELP: with-streams*
 { $values { "input" "an input stream" } { "output" "an output stream" } { "quot" quotation } }
-{ $description "Calls the quotation in a new dynamic scope, with " { $link input-stream } " rebound to  " { $snippet "input" } " and " { $link output-stream } " rebound to  " { $snippet "output" } "." }
+{ $description "Calls the quotation in a new dynamic scope, with " { $link input-stream } " rebound to " { $snippet "input" } " and " { $link output-stream } " rebound to " { $snippet "output" } "." }
 { $notes "This word does not close the stream. Compare with " { $link with-streams } "." } ;
 
 { with-input-stream with-input-stream* } related-words
@@ -224,12 +224,12 @@ HELP: with-streams*
 
 HELP: with-input-stream*
 { $values { "stream" "an input stream" } { "quot" quotation } }
-{ $description "Calls the quotation in a new dynamic scope, with " { $link input-stream } " rebound to  " { $snippet "stream" } "." }
+{ $description "Calls the quotation in a new dynamic scope, with " { $link input-stream } " rebound to " { $snippet "stream" } "." }
 { $notes "This word does not close the stream. Compare with " { $link with-input-stream } "." } ;
 
 HELP: with-output-stream*
 { $values { "stream" "an output stream" } { "quot" quotation } }
-{ $description "Calls the quotation in a new dynamic scope, with " { $link output-stream } " rebound to  " { $snippet "stream" } "." }
+{ $description "Calls the quotation in a new dynamic scope, with " { $link output-stream } " rebound to " { $snippet "stream" } "." }
 { $notes "This word does not close the stream. Compare with " { $link with-output-stream } "." } ;
 
 HELP: bl
@@ -262,6 +262,18 @@ HELP: contents
 { $description "Reads all elements in the " { $link input-stream } " until the stream is exhausted. The type of the sequence depends on the stream's element type." }
 $io-error ;
 
+HELP: tell-input
+{ $values
+        { "n" integer }
+}
+{ $description "Returns the index of the stream stored in " { $link input-stream } "." } ;
+
+HELP: tell-output
+{ $values
+        { "n" integer }
+}
+{ $description "Returns the index of the stream stored in " { $link output-stream } "." } ;
+
 ARTICLE: "stream-protocol" "Stream protocol"
 "The stream protocol consists of a large number of generic words, many of which are optional."
 $nl
@@ -290,6 +302,8 @@ $nl
 { $subsections
     stream-tell
     stream-seek
+    tell-input
+    tell-output
 }
 { $see-also "io.timeouts" } ;
 
@@ -370,12 +384,6 @@ $nl
 }
 "Seeking on the default output stream:"
 { $subsections seek-output }
-"Seeking descriptors:"
-{ $subsections
-    seek-absolute
-    seek-relative
-    seek-end
-}
 "A pair of combinators for rebinding the " { $link output-stream } " variable:"
 { $subsections
     with-output-stream
index cc637b59c353f89345eabf994557d8747933e23a..a3b933897877b8f483ec18f66e18a2454b595fb8 100644 (file)
@@ -106,7 +106,7 @@ HELP: absolute-path
     { "path" "a pathname string" }
     { "path'" "a pathname string" }
 }
-{ $description "Prepends the " { $link current-directory } " to the pathname and resolves a " { $snippet "resource:" } " or " { $snippet "voacb:" } " prefix, if present (see " { $link "io.pathnames.special" } ")." }
+{ $description "Prepends the " { $link current-directory } " to the pathname and resolves a " { $snippet "resource:" } " or " { $snippet "vocab:" } " prefix, if present (see " { $link "io.pathnames.special" } ")." }
 { $notes "This word is exaclty the same as " { $link normalize-path } ", except on Windows NT platforms, where it does not prepend the Unicode path prefix. Most code should call " { $link normalize-path } " instead." } ;
 
 HELP: resolve-symlinks
index 8d63dfdf54aaca7de480b144b64e9a6973d5c009..3412ec767e5c6177fc88496c0e8f1ba7e1967ca3 100644 (file)
@@ -242,7 +242,7 @@ HELP: bi
         "[ p ] [ q ] bi"
         "[ p ] keep q"
     }
-    
+
 } ;
 
 HELP: 2bi
@@ -512,7 +512,7 @@ HELP: bi-curry*
     "[ swap ] dip [ p ] [ q ] 2bi*"
   }
   "In other words, " { $snippet "bi-curry* bi*" } " handles the case where you have the four values " { $snippet "a b c d" } " on the stack, and you wish to apply " { $snippet "p" } " to " { $snippet "a c" } " and " { $snippet "q" } " to " { $snippet "b d" } "."
-  
+
 } ;
 
 HELP: tri-curry*
@@ -682,7 +682,7 @@ HELP: die
 { $notes
     "The term FEP originates from the Lisp machines of old. According to the Jargon File,"
     $nl
-    { $strong "fepped out" } " /fept owt/ " { $emphasis "adj." }  " The Symbolics 3600 LISP Machine has a Front-End Processor called a `FEP' (compare sense 2 of box). When the main processor gets wedged, the FEP takes control of the keyboard and screen. Such a machine is said to have `fepped out' or `dropped into the fep'." 
+    { $strong "fepped out" } " /fept owt/ " { $emphasis "adj." } " The Symbolics 3600 LISP Machine has a Front-End Processor called a `FEP' (compare sense 2 of box). When the main processor gets wedged, the FEP takes control of the keyboard and screen. Such a machine is said to have `fepped out' or `dropped into the fep'."
     $nl
     { $url "http://www.jargon.net/jargonfile/f/feppedout.html" }
 } ;
@@ -763,7 +763,7 @@ HELP: with
 { $description "Partial application on the left. The following two lines are equivalent:"
     { $code "swap [ swap A ] curry B" }
     { $code "[ A ] with B" }
-    
+
 }
 { $notes "This operation is efficient and does not copy the quotation." }
 { $examples
index 84f993c5ac9a95dae1c149c22a7353909356dcdb..3893e0cc9fc1a370a58f23d90aa8c587f8083b68 100644 (file)
@@ -62,6 +62,21 @@ unit-test
 
 [ 5 ] [ 10.5 1.9 /i ] unit-test
 
+[ t ] [ 0   0   /f                 fp-nan? ] unit-test
+[ t ] [ 0.0 0.0 /f                 fp-nan? ] unit-test
+[ t ] [ 0.0 0.0 /                  fp-nan? ] unit-test
+[ t ] [ 0   0   [ >bignum ] bi@ /f fp-nan? ] unit-test
+
+[ 1/0. ] [ 1 0 /f ] unit-test
+[ 1/0. ] [ 1.0 0.0 /f ] unit-test
+[ 1/0. ] [ 1.0 0.0 / ] unit-test
+[ 1/0. ] [ 1 0 [ >bignum ] bi@ /f ] unit-test
+
+[ -1/0. ] [ -1 0 /f ] unit-test
+[ -1/0. ] [ -1.0 0.0 /f ] unit-test
+[ -1/0. ] [ -1.0 0.0 / ] unit-test
+[ -1/0. ] [ -1 0 [ >bignum ] bi@ /f ] unit-test
+
 [ t ] [ 0/0. 0/0. unordered? ] unit-test
 [ t ] [ 1.0 0/0. unordered? ] unit-test
 [ t ] [ 0/0. 1.0 unordered? ] unit-test
index 45fce36ee6f5f23e645d0bd5c607769cbc0c337a..49e5ec30ccb3ff8cb747ff5c326f380cc8a1ca6c 100644 (file)
@@ -7,9 +7,6 @@ IN: math.floats.private
 : float-min ( x y -- z ) [ float< ] most ; foldable
 : float-max ( x y -- z ) [ float> ] most ; foldable
 
-M: fixnum >float fixnum>float ; inline
-M: bignum >float bignum>float ; inline
-
 M: float >fixnum float>fixnum ; inline
 M: float >bignum float>bignum ; inline
 M: float >float ; inline
index 6f57b06658e4b595732f99bd0a445ee963e1fbda..178bb544c119ee4b90956f3d55df6d0061bbad98 100644 (file)
@@ -216,8 +216,8 @@ unit-test
 
 : random-integer ( -- n )
     32 random-bits
-    1 random zero? [ neg ] when
-    1 random zero? [ >bignum ] when ;
+    { t f } random [ neg ] when
+    { t f } random [ >bignum ] when ;
 
 [ t ] [
     10000 [
@@ -232,5 +232,20 @@ unit-test
 [ HEX: 1.758bec11492f9p-54 ] [ 1 12345678901234567 /f ] unit-test
 [ HEX: -1.758bec11492f9p-54 ] [ 1 -12345678901234567 /f ] unit-test
 
+! Ensure that /f rounds to nearest and not to zero
+[ HEX: 1.0p55 ] [ HEX: 7f,ffff,ffff,ffff >bignum 1 /f ] unit-test
+[ HEX: 1.0p55 ] [ HEX: -7f,ffff,ffff,ffff >bignum -1 /f ] unit-test
+[ HEX: -1.0p55 ] [ HEX: -7f,ffff,ffff,ffff >bignum 1 /f ] unit-test
+[ HEX: -1.0p55 ] [ HEX: 7f,ffff,ffff,ffff >bignum -1 /f ] unit-test
+
 [ 17 ] [ 17 >bignum 5 max ] unit-test
 [ 5 ] [ 17 >bignum 5 min ] unit-test
+
+[ 1 ] [ 1 202402253307310618352495346718917307049556649764142118356901358027430339567995346891960383701437124495187077864316811911389808737385793476867013399940738509921517424276566361364466907742093216341239767678472745068562007483424692698618103355649159556340810056512358769552333414615230502532186327508646006263307707741093494784 /f double>bits ] unit-test
+[ 12 ] [ 3 50600563326827654588123836679729326762389162441035529589225339506857584891998836722990095925359281123796769466079202977847452184346448369216753349985184627480379356069141590341116726935523304085309941919618186267140501870856173174654525838912289889085202514128089692388083353653807625633046581877161501565826926935273373696 /f double>bits ] unit-test
+[ 123 ] [ 123 202402253307310618352495346718917307049556649764142118356901358027430339567995346891960383701437124495187077864316811911389808737385793476867013399940738509921517424276566361364466907742093216341239767678472745068562007483424692698618103355649159556340810056512358769552333414615230502532186327508646006263307707741093494784 /f double>bits ] unit-test
+[ 1234 ] [ 617 101201126653655309176247673359458653524778324882071059178450679013715169783997673445980191850718562247593538932158405955694904368692896738433506699970369254960758712138283180682233453871046608170619883839236372534281003741712346349309051677824579778170405028256179384776166707307615251266093163754323003131653853870546747392 /f double>bits ] unit-test
+[ 1/0. ] [ 2048 2^ 1 /f ] unit-test
+[ -1/0. ] [ 2048 2^ -1 /f ] unit-test
+[ -1/0. ] [ 2048 2^ neg 1 /f ] unit-test
+[ 1/0. ] [ 2048 2^ neg -1 /f ] unit-test
index 4dd948021aa2ad1f0996e67883f42abb6a5e75d8..940ffa65ac291287acff3abfe482903b5f33436d 100644 (file)
@@ -14,6 +14,7 @@ M: integer denominator drop 1 ; inline
 M: fixnum >fixnum ; inline
 M: fixnum >bignum fixnum>bignum ; inline
 M: fixnum >integer ; inline
+M: fixnum >float fixnum>float ; inline
 
 M: fixnum hashcode* nip ; inline
 M: fixnum equal? over bignum? [ >bignum bignum= ] [ 2drop f ] if ; inline
@@ -37,16 +38,6 @@ M: fixnum - fixnum- ; inline
 M: fixnum * fixnum* ; inline
 M: fixnum /i fixnum/i ; inline
 
-DEFER: bignum/f
-CONSTANT: bignum/f-threshold HEX: 20,0000,0000,0000
-
-: fixnum/f ( m n -- m/n )
-    [ >float ] bi@ float/f ; inline
-
-M: fixnum /f
-    2dup [ abs bignum/f-threshold >= ] either?
-    [ bignum/f ] [ fixnum/f ] if ; inline
-
 M: fixnum mod fixnum-mod ; inline
 
 M: fixnum /mod fixnum/mod ; inline
@@ -130,33 +121,49 @@ M: bignum (log2) bignum-log2 ; inline
     [ /mod ] dip ; inline
 
 ! Third step: post-scaling
-: unscaled-float ( mantissa -- n )
-    52 2^ 1 - bitand 1022 52 shift bitor bits>double ; inline
-
 : scale-float ( mantissa scale -- float' )
-    dup 0 < [ neg 2^ recip ] [ 2^ ] if * ; inline
+    {
+        { [ dup 1024 > ] [ 2drop 1/0. ] }
+        { [ dup -1023 < ] [ 1021 + shift bits>double ] }
+        [ [ 52 2^ 1 - bitand ] dip 1022 + 52 shift bitor bits>double ]
+    } cond ; inline
 
 : post-scale ( mantissa scale -- n )
     [ 2/ ] dip over log2 52 > [ [ 2/ ] [ 1 + ] bi* ] when
-    [ unscaled-float ] dip scale-float ; inline
+    scale-float ; inline
+
+: round-to-nearest ( fraction-and-guard rem -- fraction-and-guard' )
+    over odd?
+    [ zero? [ dup zero? [ 1 + ] unless ] [ 1 + ] if ] [ drop ] if ;
+    inline
 
 ! Main word
 : /f-abs ( m n -- f )
-    over zero? [
-        2drop 0.0
-    ] [
-        [
-            drop 1/0.
-        ] [
+    over zero? [ nip zero? 0/0. 0.0 ? ] [
+        [ drop 1/0. ] [
             pre-scale
             /f-loop
-            [ over odd? [ zero? [ 1 + ] unless ] [ drop ] if ] dip
+            [ round-to-nearest ] dip
             post-scale
         ] if-zero
     ] if ; inline
 
 : bignum/f ( m n -- f )
-    [ [ abs ] bi@ /f-abs ] [ [ 0 < ] bi@ xor ] 2bi [ neg ] when ;
+    [ [ abs ] bi@ /f-abs ] [ [ 0 < ] bi@ xor ] 2bi [ neg ] when ; inline
+
+M: bignum /f ( m n -- f ) { bignum bignum } declare bignum/f ;
+
+CONSTANT: bignum/f-threshold HEX: 20,0000,0000,0000
+
+: fixnum/f ( m n -- m/n )
+    [ >float ] bi@ float/f ; inline
+
+M: fixnum /f
+    { fixnum fixnum } declare
+    2dup [ abs bignum/f-threshold >= ] either?
+    [ bignum/f ] [ fixnum/f ] if ; inline
+
+: bignum>float ( bignum -- float )
+    { bignum } declare 1 >bignum bignum/f ;
 
-M: bignum /f ( m n -- f )
-    bignum/f ;
+M: bignum >float bignum>float ; inline
index 1de443b0c547319b1851638fb1204b05722a497f..079fa56acd60fde5e9d5bfb4e7cf81a31b85bdb6 100644 (file)
@@ -124,9 +124,9 @@ HELP: mod
 { $values { "x" rational } { "y" rational } { "z" rational } }
 { $description
     "Computes the remainder of dividing " { $snippet "x" } " by " { $snippet "y" } ", with the remainder being negative if " { $snippet "x" } " is negative."
-    { $list 
+    { $list
         "Modulus of fixnums always yields a fixnum."
-        "Modulus of bignums always yields a bignum."    
+        "Modulus of bignums always yields a bignum."
         { "Modulus of rationals always yields a rational. In this case, the remainder is computed using the formula " { $snippet "x - (x mod y) * y" } "." }
     }
 }
@@ -136,9 +136,9 @@ HELP: /mod
 { $values { "x" integer } { "y" integer } { "z" integer } { "w" integer } }
 { $description
     "Computes the quotient " { $snippet "z" } " and remainder " { $snippet "w" } " of dividing " { $snippet "x" } " by " { $snippet "y" } ", with the remainder being negative if " { $snippet "x" } " is negative."
-    { $list 
+    { $list
         "The quotient of two fixnums may overflow and yield a bignum; the remainder is always a fixnum"
-        "The quotient and remainder of two bignums is always a bignum."            
+        "The quotient and remainder of two bignums is always a bignum."
     }
 }
 { $see-also "division-by-zero" } ;
@@ -213,10 +213,10 @@ HELP: rem
 { $values { "x" rational } { "y" rational } { "z" rational } }
 { $description
     "Computes the remainder of dividing " { $snippet "x" } " by " { $snippet "y" } ", with the remainder always positive or zero."
-    { $list 
+    { $list
         "Given fixnums, always yields a fixnum."
         "Given bignums, always yields a bignum."
-        "Given rationals, always yields a rational."    
+        "Given rationals, always yields a rational."
     }
 }
 { $see-also "division-by-zero" mod } ;
@@ -244,7 +244,7 @@ HELP: 2/
 
 HELP: 2^
 { $values { "n" "a positive integer" } { "2^n" "a positive integer" } }
-{ $description "Computes two to the power of " { $snippet "n" } ". This word will only give correct results if " { $snippet "n" } " is greater than zero; for the general case, use " { $snippet  "2 swap ^" } "." } ;
+{ $description "Computes two to the power of " { $snippet "n" } ". This word will only give correct results if " { $snippet "n" } " is greater than zero; for the general case, use " { $snippet "2 swap ^" } "." } ;
 
 HELP: zero?
 { $values { "x" number } { "?" "a boolean" } }
@@ -421,7 +421,7 @@ HELP: all-integers?
 
 HELP: find-integer
 { $values { "n" integer } { "quot" { $quotation "( ... i -- ... ? )" } } { "i" "an integer or " { $link f } } }
-{ $description "Applies the quotation to each integer from 0 up to " { $snippet "n" } ", excluding " { $snippet "n" } ". Iterationi stops when the quotation outputs a true value or the end is reached. If the quotation yields a true value for some integer, this word outputs that integer. Otherwise, this word outputs " { $link f } "." }
+{ $description "Applies the quotation to each integer from 0 up to " { $snippet "n" } ", excluding " { $snippet "n" } ". Iteration stops when the quotation outputs a true value or the end is reached. If the quotation yields a true value for some integer, this word outputs that integer. Otherwise, this word outputs " { $link f } "." }
 { $notes "This word is used to implement " { $link find } "." } ;
 
 HELP: find-last-integer
index bc7658feba439629e44aa846561f907db80bd75e..e8f2813a959418d2408c37b5d2815a7edae7b8e0 100644 (file)
@@ -59,11 +59,7 @@ PRIVATE>
 ERROR: log2-expects-positive x ;
 
 : log2 ( x -- n )
-    dup 0 <= [
-        log2-expects-positive
-    ] [
-        (log2)
-    ] if ; inline
+    dup 0 <= [ log2-expects-positive ] [ (log2) ] if ; inline
 
 : zero? ( x -- ? ) 0 number= ; inline
 : 2/ ( x -- y ) -1 shift ; inline
@@ -74,8 +70,8 @@ ERROR: log2-expects-positive x ;
 : ?1+ ( x -- y ) [ 1 + ] [ 0 ] if* ; inline
 : rem ( x y -- z ) abs [ mod ] [ + ] [ mod ] tri ; foldable
 : 2^ ( n -- 2^n ) 1 swap shift ; inline
-: even? ( n -- ? ) 1 bitand zero? ;
-: odd? ( n -- ? ) 1 bitand 1 number= ;
+: even? ( n -- ? ) 1 bitand zero? ; inline
+: odd? ( n -- ? ) 1 bitand 1 number= ; inline
 
 : if-zero ( ..a n quot1: ( ..a -- ..b ) quot2: ( ..a n -- ..b ) -- ..b )
     [ dup zero? ] [ [ drop ] prepose ] [ ] tri* if ; inline
index 6889f497e17c4cb99739850a2ccc73fb2d91c2e2..24ddc0b7c9f82d1ed83758bbb3bdae6266f6e4de 100644 (file)
@@ -56,7 +56,7 @@ ARTICLE: "parsing-tokens" "Parsing raw tokens"
 "So far we have seen how to read individual tokens, or read a sequence of parsed objects until a delimiter. It is also possible to read raw tokens from the input and perform custom processing."
 $nl
 "One example is the " { $link POSTPONE: USING: } " parsing word."
-{ $see POSTPONE: USING: } 
+{ $see POSTPONE: USING: }
 "It reads a list of vocabularies terminated by " { $link POSTPONE: ; } ". However, the vocabulary names do not name words, except by coincidence; so " { $link parse-until } " cannot be used here. Instead, a set of lower-level combinators can be used:"
 { $subsections
     each-token
@@ -215,7 +215,7 @@ HELP: parse-fresh
 { $errors "Throws a parse error if the input is malformed." } ;
 
 HELP: filter-moved
-{ $values { "assoc1" assoc } { "assoc2" assoc } { "seq" "an seqence of definitions" } }
+{ $values { "assoc1" assoc } { "assoc2" assoc } { "seq" "an sequence of definitions" } }
 { $description "Removes all definitions from " { $snippet "assoc2" } " which are in " { $snippet "assoc1" } " or are are no longer present in the current " { $link file } "." } ;
 
 HELP: forget-smudged
index c1f48d661bb3aba3dae95c898a82fedac55539a9..fa2db15aad3001fd150614de6c1cb0fe57c0744b 100644 (file)
@@ -5,7 +5,7 @@ IN: sbufs
 ARTICLE: "sbufs" "String buffers"
 "The " { $vocab-link "sbufs" } " vocabulary implements resizable mutable sequence of characters. The literal syntax is covered in " { $link "syntax-sbufs" } "."
 $nl
-"String buffers implement the " { $link "sequence-protocol" } " and thus all " { $link "sequences" } " can be used with them. String buffers can be used to construct new strings by accumilating substrings and characters, however usually they are only used indirectly, since the sequence construction words are more convenient to use in most cases (see " { $link "namespaces-make" } ")."
+"String buffers implement the " { $link "sequence-protocol" } " and thus all " { $link "sequences" } " can be used with them. String buffers can be used to construct new strings by accumulating substrings and characters, however usually they are only used indirectly, since the sequence construction words are more convenient to use in most cases (see " { $link "namespaces-make" } ")."
 $nl
 "String buffers form a class of objects:"
 { $subsections
index ed0f4b16b072fecbbf9ff55d4cfd17f2d281a76d..12d6813ebdc2696aa8ba621132cd88c8b278f2ba 100644 (file)
@@ -15,7 +15,7 @@ HELP: length
 HELP: set-length
 { $values { "n" "a non-negative integer" } { "seq" "a resizable sequence" } }
 { $contract "Resizes a sequence. The initial contents of the new area is undefined." }
-{ $errors "Throws a " { $link no-method  } " error if the sequence is not resizable, and a " { $link bounds-error } " if the new length is negative." }
+{ $errors "Throws a " { $link no-method } " error if the sequence is not resizable, and a " { $link bounds-error } " if the new length is negative." }
 { $side-effects "seq" } ;
 
 HELP: lengthen
@@ -45,7 +45,7 @@ HELP: nths
      { "indices" sequence } { "seq" sequence }
      { "seq'" sequence } }
 { $description "Outputs a sequence of elements from the input sequence indexed by the indices." }
-{ $examples 
+{ $examples
     { $example "USING: prettyprint sequences ;"
                "{ 0 2 } { \"a\" \"b\" \"c\" } nths ."
                "{ \"a\" \"c\" }"
@@ -243,12 +243,12 @@ HELP: array-capacity
 { $warning "This word is in the " { $vocab-link "sequences.private" } " vocabulary because it is unsafe. It does not check types, so improper use can corrupt memory." } ;
 
 HELP: array-nth
-{ $values { "n" "a non-negative fixnum" } { "array" "an array" }  { "elt" object } }
+{ $values { "n" "a non-negative fixnum" } { "array" "an array" } { "elt" object } }
 { $description "Low-level array element accessor." }
 { $warning "This word is in the " { $vocab-link "sequences.private" } " vocabulary because it is unsafe. It does not check types or array bounds, and improper use can corrupt memory. User code must use " { $link nth } " instead." } ;
 
 HELP: set-array-nth
-{ $values { "elt" object } { "n" "a non-negative fixnum" } { "array" "an array" }  }
+{ $values { "elt" object } { "n" "a non-negative fixnum" } { "array" "an array" } }
 { $description "Low-level array element mutator." }
 { $warning "This word is in the " { $vocab-link "sequences.private" } " vocabulary because it is unsafe. It does not check types or array bounds, and improper use can corrupt memory. User code must use " { $link set-nth } " instead." } ;
 
@@ -430,7 +430,7 @@ HELP: all?
 
 HELP: push-if
 { $values { "elt" object } { "quot" { $quotation "( ..a elt -- ..b ? )" } } { "accum" "a resizable mutable sequence" } }
-{ $description "Adds the element at the end of the sequence if the quotation yields a true value." } 
+{ $description "Adds the element at the end of the sequence if the quotation yields a true value." }
 { $notes "This word is a factor of " { $link filter } "." } ;
 
 HELP: filter
@@ -557,7 +557,7 @@ HELP: append!
 HELP: prefix
 { $values { "seq" sequence } { "elt" object } { "newseq" sequence } }
 { $description "Outputs a new sequence obtained by adding " { $snippet "elt" } " at the beginning of " { $snippet "seq" } "." }
-{ $errors "Throws an error if the type of " { $snippet "elt" } " is not permitted in sequences of the same class as " { $snippet "seq1" } "." } 
+{ $errors "Throws an error if the type of " { $snippet "elt" } " is not permitted in sequences of the same class as " { $snippet "seq1" } "." }
 { $examples
 { $example "USING: prettyprint sequences ;" "{ 1 2 3 } 0 prefix ." "{ 0 1 2 3 }" }
 } ;
@@ -713,7 +713,7 @@ HELP: append
 { $values { "seq1" sequence } { "seq2" sequence } { "newseq" sequence } }
 { $description "Outputs a new sequence of the same type as " { $snippet "seq1" } " consisting of the elements of " { $snippet "seq1" } " followed by " { $snippet "seq2" } "." }
 { $errors "Throws an error if " { $snippet "seq2" } " contains elements not permitted in sequences of the same class as " { $snippet "seq1" } "." }
-{ $examples 
+{ $examples
     { $example "USING: prettyprint sequences ;"
         "{ 1 2 } B{ 3 4 } append ."
         "{ 1 2 3 4 }"
@@ -728,7 +728,7 @@ HELP: append-as
 { $values { "seq1" sequence } { "seq2" sequence } { "exemplar" sequence } { "newseq" sequence } }
 { $description "Outputs a new sequence of the same type as " { $snippet "exemplar" } " consisting of the elements of " { $snippet "seq1" } " followed by " { $snippet "seq2" } "." }
 { $errors "Throws an error if " { $snippet "seq1" } " or " { $snippet "seq2" } " contain elements not permitted in sequences of the same class as " { $snippet "exemplar" } "." }
-{ $examples 
+{ $examples
     { $example "USING: prettyprint sequences ;"
         "{ 1 2 } B{ 3 4 } B{ } append-as ."
         "B{ 1 2 3 4 }"
@@ -872,7 +872,7 @@ HELP: tail*
 
 HELP: shorter?
 { $values { "seq1" sequence } { "seq2" sequence } { "?" "a boolean" } }
-{ $description "Tets if the length of " { $snippet "seq1" } " is smaller than the length of " { $snippet "seq2" } "." } ;
+{ $description "Tests if the length of " { $snippet "seq1" } " is smaller than the length of " { $snippet "seq2" } "." } ;
 
 HELP: head?
 { $values { "seq" sequence } { "begin" sequence } { "?" "a boolean" } }
@@ -992,7 +992,7 @@ HELP: selector
 { $values
      { "quot" { $quotation "( ... elt -- ... ? )" } }
      { "selector" { $quotation "( ... elt -- ... )" } } { "accum" vector } }
-{ $description "Creates a new vector to accumulate the values which return true for a predicate.  Returns a new quotation which accepts an object to be tested and stored in the collector if the test yields true. The collector is left on the stack for convenience." }
+{ $description "Creates a new vector to accumulate the values which return true for a predicate. Returns a new quotation which accepts an object to be tested and stored in the collector if the test yields true. The collector is left on the stack for convenience." }
 { $example "! Find all the even numbers:" "USING: prettyprint sequences math kernel ;"
            "10 iota [ even? ] selector [ each ] dip ."
            "V{ 0 2 4 6 8 }"
@@ -1004,7 +1004,7 @@ HELP: trim-head
      { "seq" sequence } { "quot" quotation }
      { "newseq" sequence } }
 { $description "Removes elements starting from the left side of a sequence if they match a predicate. Once an element does not match, the test stops and the rest of the sequence is left on the stack as a new sequence." }
-{ $example "" "USING: prettyprint math sequences ;"
+{ $example "USING: prettyprint math sequences ;"
            "{ 0 0 1 2 3 0 0 } [ zero? ] trim-head ."
            "{ 1 2 3 0 0 }"
 } ;
@@ -1014,7 +1014,7 @@ HELP: trim-head-slice
      { "seq" sequence } { "quot" quotation }
      { "slice" slice } }
 { $description "Removes elements starting from the left side of a sequence if they match a predicate. Once an element does not match, the test stops and the rest of the sequence is left on the stack as a slice" }
-{ $example "" "USING: prettyprint math sequences ;"
+{ $example "USING: prettyprint math sequences ;"
            "{ 0 0 1 2 3 0 0 } [ zero? ] trim-head-slice ."
            "T{ slice { from 2 } { to 7 } { seq { 0 0 1 2 3 0 0 } } }"
 } ;
@@ -1024,7 +1024,7 @@ HELP: trim-tail
      { "seq" sequence } { "quot" quotation }
      { "newseq" sequence } }
 { $description "Removes elements starting from the right side of a sequence if they match a predicate. Once an element does not match, the test stops and the rest of the sequence is left on the stack as a new sequence." }
-{ $example "" "USING: prettyprint math sequences ;"
+{ $example "USING: prettyprint math sequences ;"
            "{ 0 0 1 2 3 0 0 } [ zero? ] trim-tail ."
            "{ 0 0 1 2 3 }"
 } ;
@@ -1034,7 +1034,7 @@ HELP: trim-tail-slice
      { "seq" sequence } { "quot" quotation }
      { "slice" slice } }
 { $description "Removes elements starting from the right side of a sequence if they match a predicate. Once an element does not match, the test stops and the rest of the sequence is left on the stack as a slice." }
-{ $example "" "USING: prettyprint math sequences ;"
+{ $example "USING: prettyprint math sequences ;"
            "{ 0 0 1 2 3 0 0 } [ zero? ] trim-tail-slice ."
            "T{ slice { from 0 } { to 5 } { seq { 0 0 1 2 3 0 0 } } }"
 } ;
@@ -1044,7 +1044,7 @@ HELP: trim
      { "seq" sequence } { "quot" quotation }
      { "newseq" sequence } }
 { $description "Removes elements starting from the left and right sides of a sequence if they match a predicate. Once an element does not match, the test stops and the rest of the sequence is left on the stack as a new sequence." }
-{ $example "" "USING: prettyprint math sequences ;"
+{ $example "USING: prettyprint math sequences ;"
            "{ 0 0 1 2 3 0 0 } [ zero? ] trim ."
            "{ 1 2 3 }"
 } ;
@@ -1054,7 +1054,7 @@ HELP: trim-slice
      { "seq" sequence } { "quot" quotation }
      { "slice" slice } }
 { $description "Removes elements starting from the left and right sides of a sequence if they match a predicate. Once an element does not match, the test stops and the rest of the sequence is left on the stack as a slice." }
-{ $example "" "USING: prettyprint math sequences ;"
+{ $example "USING: prettyprint math sequences ;"
            "{ 0 0 1 2 3 0 0 } [ zero? ] trim-slice ."
            "T{ slice { from 2 } { to 5 } { seq { 0 0 1 2 3 0 0 } } }"
 } ;
@@ -1065,8 +1065,8 @@ HELP: sift
 { $values
      { "seq" sequence }
      { "newseq" sequence } }
- { $description "Outputs a new sequence with all instance of " { $link f  } " removed." }
- { $examples 
+ { $description "Outputs a new sequence with all instance of " { $link f } " removed." }
+ { $examples
     { $example "USING: prettyprint sequences ;"
         "{ \"a\" 3 { } f } sift ."
         "{ \"a\" 3 { } }"
@@ -1078,7 +1078,7 @@ HELP: harvest
      { "seq" sequence }
      { "newseq" sequence } }
 { $description "Outputs a new sequence with all empty sequences removed." }
-{ $examples 
+{ $examples
     { $example "USING: prettyprint sequences ;"
                "{ { } { 2 3 } { 5 } { } } harvest ."
                "{ { 2 3 } { 5 } }"
@@ -1091,9 +1091,9 @@ HELP: set-first
 { $values
      { "first" object } { "seq" sequence } }
 { $description "Sets the first element of a sequence." }
-{ $examples 
+{ $examples
     { $example "USING: prettyprint kernel sequences ;"
-        "{ 1 2 3 4  } 5 over set-first ."
+        "{ 1 2 3 4 } 5 over set-first ."
         "{ 5 2 3 4 }"
     }
 } ;
@@ -1102,9 +1102,9 @@ HELP: set-second
 { $values
      { "second" object } { "seq" sequence } }
 { $description "Sets the second element of a sequence." }
-{ $examples 
+{ $examples
     { $example "USING: prettyprint kernel sequences ;"
-        "{ 1 2 3 4  } 5 over set-second ."
+        "{ 1 2 3 4 } 5 over set-second ."
         "{ 1 5 3 4 }"
     }
 } ;
@@ -1113,9 +1113,9 @@ HELP: set-third
 { $values
      { "third" object } { "seq" sequence } }
 { $description "Sets the third element of a sequence." }
-{ $examples 
+{ $examples
     { $example "USING: prettyprint kernel sequences ;"
-        "{ 1 2 3 4  } 5 over set-third ."
+        "{ 1 2 3 4 } 5 over set-third ."
         "{ 1 2 5 4 }"
     }
 } ;
@@ -1124,9 +1124,9 @@ HELP: set-fourth
 { $values
      { "fourth" object } { "seq" sequence } }
 { $description "Sets the fourth element of a sequence." }
-{ $examples 
+{ $examples
     { $example "USING: prettyprint kernel sequences ;"
-        "{ 1 2 3 4  } 5 over set-fourth ."
+        "{ 1 2 3 4 } 5 over set-fourth ."
         "{ 1 2 3 5 }"
     }
 } ;
@@ -1138,7 +1138,7 @@ HELP: replicate
      { "len" integer } { "quot" { $quotation "( ... -- ... newelt )" } }
      { "newseq" sequence } }
      { $description "Calls the quotation " { $snippet "len" } " times, collecting results into a new array." }
-{ $examples 
+{ $examples
     { $unchecked-example "USING: kernel prettyprint random sequences ;"
         "5 [ 100 random ] replicate ."
         "{ 52 10 45 81 30 }"
@@ -1150,7 +1150,7 @@ HELP: replicate-as
      { "len" integer } { "quot" { $quotation "( ... -- ... newelt )" } } { "exemplar" sequence }
      { "newseq" sequence } }
  { $description "Calls the quotation " { $snippet "len" } " times, collecting results into a new sequence of the same type as the exemplar sequence." }
-{ $examples 
+{ $examples
     { $unchecked-example "USING: prettyprint kernel sequences ;"
         "5 [ 100 random ] B{ } replicate-as ."
         "B{ 44 8 2 33 18 }"
@@ -1163,8 +1163,8 @@ HELP: partition
 { $values
      { "seq" sequence } { "quot" quotation }
      { "trueseq" sequence } { "falseseq" sequence } }
-     { $description "Calls a predicate quotation on each element of the input sequence.  If the test yields true, the element is added to " { $snippet "trueseq" } "; if false, it's added to " { $snippet "falseseq" } "." }
-{ $examples 
+     { $description "Calls a predicate quotation on each element of the input sequence. If the test yields true, the element is added to " { $snippet "trueseq" } "; if false, it's added to " { $snippet "falseseq" } "." }
+{ $examples
     { $example "USING: prettyprint kernel math sequences ;"
         "{ 1 2 3 4 5 } [ even? ] partition [ . ] bi@"
         "{ 2 4 }\n{ 1 3 5 }"
@@ -1198,7 +1198,7 @@ HELP: 2selector
 { $values
      { "quot" quotation }
      { "selector" quotation } { "accum1" vector } { "accum2" vector } }
-{ $description "Creates two new vectors to accumultate values based on a predicate. The first vector accumulates values for which the predicate yields true; the second for false." } ;
+{ $description "Creates two new vectors to accumulate values based on a predicate. The first vector accumulates values for which the predicate yields true; the second for false." } ;
 
 HELP: 2unclip-slice
 { $values
@@ -1235,7 +1235,7 @@ HELP: follow
 { $values
      { "obj" object } { "quot" { $quotation "( ... prev -- ... result/f )" } }
      { "seq" sequence } }
-{ $description "Outputs a sequence containing the input object and all of the objects generated by successively feeding the result of the quotation called on the input object to the quotation recursuively. Objects yielded by the quotation are added to the output sequence until the quotation yields " { $link f } ", at which point the recursion terminates." }
+{ $description "Outputs a sequence containing the input object and all of the objects generated by successively feeding the result of the quotation called on the input object to the quotation recursively. Objects yielded by the quotation are added to the output sequence until the quotation yields " { $link f } ", at which point the recursion terminates." }
 { $examples "Get random numbers until zero is reached:"
     { $unchecked-example
     "USING: random sequences prettyprint math ;"
@@ -1293,7 +1293,7 @@ HELP: new-like
 HELP: push-either
 { $values
      { "elt" object } { "quot" quotation } { "accum1" vector } { "accum2" vector } }
-{ $description "Pushes the input object onto one of the accumualators; the first if the quotation yields true, the second if false." } ;
+{ $description "Pushes the input object onto one of the accumulators; the first if the quotation yields true, the second if false." } ;
 
 HELP: sequence-hashcode
 { $values
@@ -1343,10 +1343,9 @@ HELP: assert-sequence=
 { $description "Throws an error if all the elements of two sequences, taken pairwise, are not equal." }
 { $notes "The sequences need not be of the same type." }
 { $examples
-  { $example
+  { $code
     "USING: prettyprint sequences ;"
     "{ 1 2 3 } V{ 1 2 3 } assert-sequence="
-    ""
   }
 } ;
 
index bf2b6904c3dba4c5ffb2e9a51df33a2557148772..5197e57ad0cf8c89e9ded298790b6d823ead58b5 100644 (file)
@@ -18,6 +18,8 @@ ARTICLE: "set-operations" "Operations on sets"
 { $subsections in? }
 "All sets can be represented as a sequence, without duplicates, of their members:"
 { $subsections members }
+"To get the number of elements in a set:"
+{ $subsections cardinality }
 "Sets can have members added or removed destructively:"
 { $subsections
     adjoin
@@ -184,3 +186,7 @@ HELP: without
 HELP: null?
 { $values { "set" set } { "?" "a boolean" } }
 { $description "Tests whether the given set is empty. This outputs " { $snippet "t" } " when given a null set of any type." } ;
+
+HELP: cardinality
+{ $values { "set" set } { "n" "a non-negative integer" } }
+{ $description "Returns the number of elements in the set. All sets support this operation." } ;
index 9a48acc4cfc0ef64bb85720f2e3d98a69fc2288a..df6185671c098c015e28d54f0e530b6c8159b586 100644 (file)
@@ -3,15 +3,19 @@
 USING: sets tools.test kernel prettyprint hash-sets sorting ;
 IN: sets.tests
 
-[ { } ] [ { } { } intersect  ] unit-test
+[ { } ] [ { } { } intersect ] unit-test
 [ { 2 3 } ] [ { 1 2 3 } { 2 3 4 } intersect ] unit-test
+[ { 2 3 } ] [ { 1 2 3 } { 2 3 4 5 } intersect ] unit-test
+[ { 2 3 4 } ] [ { 1 2 3 4 } { 2 3 4 } intersect ] unit-test
 [ { 2 3 } ] [ { 1 2 2 3 } { 2 3 3 4 } intersect ] unit-test
 
 [ { } ] [ { } { } diff ] unit-test
 [ { 1 } ] [ { 1 2 3 } { 2 3 4 } diff ] unit-test
+[ { 1 } ] [ { 1 2 3 } { 2 3 4 5 } diff ] unit-test
+[ { 1 } ] [ { 1 2 3 4 } { 2 3 4 } diff ] unit-test
 [ { 1 } ] [ { 1 1 2 3 } { 2 3 4 4 } diff ] unit-test
 
-[ { } ] [ { } { } within  ] unit-test
+[ { } ] [ { } { } within ] unit-test
 [ { 2 3 } ] [ { 1 2 3 } { 2 3 4 } within ] unit-test
 [ { 2 2 3 } ] [ { 1 2 2 3 } { 2 3 3 4 } within ] unit-test
 
@@ -64,3 +68,9 @@ IN: sets.tests
 
 [ t ] [ f null? ] unit-test
 [ f ] [ { 4 } null? ] unit-test
+
+[ 0 ] [ f cardinality ] unit-test
+[ 0 ] [ { } cardinality ] unit-test
+[ 1 ] [ { 1 } cardinality ] unit-test
+[ 1 ] [ HS{ 1 } cardinality ] unit-test
+[ 3 ] [ HS{ 1 2 3 } cardinality ] unit-test
index 9c1870aa2e57634feee580262f0813bf65771b93..06f6e04655417689af351b0194c2dbfe6635f173 100644 (file)
@@ -22,12 +22,17 @@ GENERIC: set= ( set1 set2 -- ? )
 GENERIC: duplicates ( set -- seq )
 GENERIC: all-unique? ( set -- ? )
 GENERIC: null? ( set -- ? )
+GENERIC: cardinality ( set -- n )
+
+M: f cardinality drop 0 ;
 
 ! Defaults for some methods.
 ! Override them for efficiency
 
 M: set null? members null? ; inline
 
+M: set cardinality members length ;
+
 M: set set-like drop ; inline
 
 M: set union
@@ -41,22 +46,25 @@ M: set union
 : sequence/tester ( set1 set2 -- set1' quot )
     [ members ] [ tester ] bi* ; inline
 
+: small/large ( set1 set2 -- set1' set2' )
+    2dup [ cardinality ] bi@ > [ swap ] when ;
+
 PRIVATE>
 
 M: set intersect
-    [ sequence/tester filter ] keep set-like ;
+    [ small/large sequence/tester filter ] keep set-like ;
 
 M: set diff
     [ sequence/tester [ not ] compose filter ] keep set-like ;
 
 M: set intersects?
-    sequence/tester any? ;
+    small/large sequence/tester any? ;
 
 M: set subset?
-    sequence/tester all? ;
-    
+    small/large sequence/tester all? ;
+
 M: set set=
-    2dup subset? [ swap subset? ] [ 2drop f ] if ;
+    2dup [ cardinality ] bi@ eq? [ subset? ] [ 2drop f ] if ;
 
 M: set fast-set ;
 
@@ -94,10 +102,13 @@ M: sequence set-like
 
 M: sequence members
     [ pruned ] keep like ;
-  
+
 M: sequence null?
     empty? ; inline
 
+M: sequence cardinality
+    length ;
+
 : combine ( sets -- set )
     [ f ]
     [ [ [ members ] map concat ] [ first ] bi set-like ]
index cb1e5e601708bde181a255f6d134f01d3c654c0c..fc99b7afd105870c48dd2d21f4246eebc6fe97e6 100644 (file)
@@ -39,7 +39,7 @@ HELP: source-file
 
 HELP: record-checksum
 { $values { "lines" "a sequence of strings" } { "source-file" source-file } }
-{ $description "Records the CRC32 checksm of the source file's contents." } 
+{ $description "Records the CRC32 checksum of the source file's contents." }
 $low-level-note ;
 
 HELP: reset-checksums
index 7e5c301711a46d6d0d88622a3bafe5c06311cdc6..c2ba53f1b67955a6819cf757d41dc6e318bd254d 100644 (file)
@@ -55,7 +55,7 @@ PRIVATE>
 
 <PRIVATE
 
-: (split) ( n seq quot: ( elt -- ? ) -- )
+: (split) ( n seq quot: ( ... elt -- ... ? ) -- )
     [ find-from drop ]
     [ [ [ 3dup swapd subseq , ] dip [ drop 1 + ] 2dip (split) ] 3curry ]
     [ drop [ swap [ tail ] unless-zero , ] 2curry ]
index 512e2de61a896500faba02096b13a82639262422..18434166b9933004b231dd34f948dc2923ee877b 100644 (file)
@@ -195,7 +195,7 @@ ARTICLE: "syntax-hash-sets" "Hash set syntax"
 
 ARTICLE: "syntax-tuples" "Tuple syntax"
 { $subsections POSTPONE: T{ }
-"Tuples are documented in " { $link "tuples" } "."  ;
+"Tuples are documented in " { $link "tuples" } "." ;
 
 ARTICLE: "syntax-quots" "Quotation syntax"
 { $subsections
@@ -340,37 +340,37 @@ $nl
 HELP: {
 { $syntax "{ elements... }" }
 { $values { "elements" "a list of objects" } }
-{ $description "Marks the beginning of a literal array. Literal arrays are terminated by " { $link POSTPONE: } } "." } 
+{ $description "Marks the beginning of a literal array. Literal arrays are terminated by " { $link POSTPONE: } } "." }
 { $examples { $code "{ 1 2 3 }" } } ;
 
 HELP: V{
 { $syntax "V{ elements... }" }
 { $values { "elements" "a list of objects" } }
-{ $description "Marks the beginning of a literal vector. Literal vectors are terminated by " { $link POSTPONE: } } "." } 
+{ $description "Marks the beginning of a literal vector. Literal vectors are terminated by " { $link POSTPONE: } } "." }
 { $examples { $code "V{ 1 2 3 }" } } ;
 
 HELP: B{
 { $syntax "B{ elements... }" }
 { $values { "elements" "a list of integers" } }
-{ $description "Marks the beginning of a literal byte array. Literal byte arrays are terminated by " { $link POSTPONE: } } "." } 
+{ $description "Marks the beginning of a literal byte array. Literal byte arrays are terminated by " { $link POSTPONE: } } "." }
 { $examples { $code "B{ 1 2 3 }" } } ;
 
 HELP: H{
 { $syntax "H{ { key value }... }" }
 { $values { "key" "an object" } { "value" "an object" } }
-{ $description "Marks the beginning of a literal hashtable, given as a list of two-element arrays holding key/value pairs. Literal hashtables are terminated by " { $link POSTPONE: } } "." } 
+{ $description "Marks the beginning of a literal hashtable, given as a list of two-element arrays holding key/value pairs. Literal hashtables are terminated by " { $link POSTPONE: } } "." }
 { $examples { $code "H{ { \"tuna\" \"fish\" } { \"jalapeno\" \"vegetable\" } }" } } ;
 
 HELP: HS{
 { $syntax "HS{ members ... }" }
 { $values { "members" "a list of objects" } }
-{ $description "Marks the beginning of a literal hash set, given as a list of its members. Literal hashtables are terminated by " { $link POSTPONE: } } "." } 
+{ $description "Marks the beginning of a literal hash set, given as a list of its members. Literal hashtables are terminated by " { $link POSTPONE: } } "." }
 { $examples { $code "HS{ 3 \"foo\" }" } } ;
 
 HELP: C{
 { $syntax "C{ real-part imaginary-part }" }
 { $values { "real-part" "a real number" } { "imaginary-part" "a real number" } }
-{ $description "Parses a complex number given in rectangular form as a pair of real numbers. Literal complex numbers are terminated by " { $link POSTPONE: } } "." }  ;
+{ $description "Parses a complex number given in rectangular form as a pair of real numbers. Literal complex numbers are terminated by " { $link POSTPONE: } } "." } ;
 
 HELP: T{
 { $syntax "T{ class }" "T{ class f slot-values... }" "T{ class { slot-name slot-value } ... }" }
@@ -453,7 +453,7 @@ HELP: SINGLETON:
 { $examples
     { $example "USING: classes.singleton kernel io ;" "IN: singleton-demo" "USE: prettyprint SINGLETON: foo\nGENERIC: bar ( obj -- )\nM: foo bar drop \"a foo!\" print ;\nfoo bar" "a foo!" }
 } ;
-    
+
 HELP: SINGLETONS:
 { $syntax "SINGLETONS: words... ;" }
 { $values { "words" "a sequence of new words to define" } }
@@ -533,13 +533,14 @@ HELP: QUALIFIED:
 { $examples { $example
     "USING: prettyprint ;"
     "QUALIFIED: math"
-    "1 2 math:+ ." "3"
+    "1 2 math:+ ."
+    "3"
 } } ;
 
 HELP: QUALIFIED-WITH:
 { $syntax "QUALIFIED-WITH: vocab word-prefix" }
 { $description "Like " { $link POSTPONE: QUALIFIED: } " but uses " { $snippet "word-prefix" } " as prefix." }
-{ $examples { $code
+{ $examples { $example
     "USING: prettyprint ;"
     "QUALIFIED-WITH: math m"
     "1 2 m:+ ."
@@ -559,7 +560,7 @@ HELP: FROM:
 
 HELP: EXCLUDE:
 { $syntax "EXCLUDE: vocab => words ... ;" }
-{ $description "Adds all words except for " { $snippet "words" } " from " { $snippet "vocab" } "  to the search path." }
+{ $description "Adds all words except for " { $snippet "words" } " from " { $snippet "vocab" } " to the search path." }
 { $examples { $code
     "EXCLUDE: math.parser => bin> hex> ;" "! imports everything but bin> and hex>" } } ;
 
@@ -727,7 +728,7 @@ HELP: HOOK:
         "TUPLE: air-transport ;"
         "HOOK: deliver transport ( destination -- )"
         "M: land-transport deliver \"Land delivery to \" write print ;"
-        "M: air-transport deliver \"Air delivery to \"  write print ;"
+        "M: air-transport deliver \"Air delivery to \" write print ;"
         "T{ air-transport } transport set"
         "\"New York City\" deliver"
         "Air delivery to New York City"
index 66900978a84b20d3cf6448bb5cefac933044094e..9f60f790479de189f247d7d9e1b18c972ad05d91 100644 (file)
@@ -1,7 +1,7 @@
 USING: help.markup help.syntax parser strings words assocs vocabs ;
 IN: vocabs.parser
 
-ARTICLE: "word-search-errors"  "Word lookup errors"
+ARTICLE: "word-search-errors" "Word lookup errors"
 "If the parser cannot not find a word in the current vocabulary search path, it attempts to look for the word in all loaded vocabularies."
 $nl
 "If " { $link auto-use? } " mode is off, a restartable error is thrown with a restart for each vocabulary in question, together with a restart which defers the word in the current vocabulary, as if " { $link POSTPONE: DEFER: } " was used."
@@ -142,7 +142,7 @@ HELP: add-words-from
 
 HELP: add-words-excluding
 { $values { "vocab" "a vocabulary specifier" } { "words" "a sequence of word names" } }
-{ $description "Adds all words except for " { $snippet "words" } " from " { $snippet "vocab" } "  to the manifest." }
+{ $description "Adds all words except for " { $snippet "words" } " from " { $snippet "vocab" } " to the manifest." }
 { $notes "This word is used to implement " { $link POSTPONE: EXCLUDE: } "." } ;
 
 HELP: add-renamed-word
index 3f8a71e76cf0b293277fcf46f127fb37aba5e695..b2cb422178ed41ca42839a5e748429bc86bfad49 100644 (file)
@@ -77,7 +77,7 @@ HELP: forget-vocab
 { $notes "This word must be called from inside " { $link with-compilation-unit } "." } ;
 
 HELP: load-vocab-hook
-{ $var-description { $quotation "( name -- vocab )" } " which loads a vocabulary. This quotation is called by " { $link load-vocab } ". The default value should not need to be changed; this functinality is implemented via a hook stored in a variable to break a circular dependency which would otherwise exist from " { $vocab-link "vocabs" } " to " { $vocab-link "vocabs.loader" } " to " { $vocab-link "parser" } " back to " { $vocab-link "vocabs" } "." } ;
+{ $var-description { $quotation "( name -- vocab )" } " which loads a vocabulary. This quotation is called by " { $link load-vocab } ". The default value should not need to be changed; this functionality is implemented via a hook stored in a variable to break a circular dependency which would otherwise exist from " { $vocab-link "vocabs" } " to " { $vocab-link "vocabs.loader" } " to " { $vocab-link "parser" } " back to " { $vocab-link "vocabs" } "." } ;
 
 HELP: words-named
 { $values { "str" string } { "seq" "a sequence of words" } }
index 403015bad5da397dc487b02855459acbdab2c85e..ae727ac3707bc5e057fde42b02a0b92889b484f9 100644 (file)
@@ -1,7 +1,7 @@
 ! (c)2010 Joe Groff bsd license
-USING: alien alien.c-types alien.libraries alien.strings
-alien.syntax combinators destructors io.encodings.ascii kernel
-libc locals sequences system ;
+USING: alien alien.c-types alien.data alien.libraries
+alien.strings alien.syntax combinators destructors
+io.encodings.ascii kernel libc locals sequences system ;
 IN: alien.cxx.demangle.libstdcxx
 
 FUNCTION: char* __cxa_demangle ( char* mangled_name, char* output_buffer, size_t* length, int* status ) ;
@@ -22,9 +22,9 @@ ERROR: invalid-demangle-args name ;
     "_Z" head? ;
 
 :: demangle ( mangled-name -- c++-name )
-    0 <ulong> :> length
-    0 <int> :> status [
+    0 ulong <ref> :> length
+    0 int <ref> :> status [
         mangled-name ascii string>alien f length status __cxa_demangle &(free) :> demangled-buf
-        mangled-name status *int demangle-error
+        mangled-name status int deref demangle-error
         demangled-buf ascii alien>string
     ] with-destructors ;
index d7079c4aaa75278de1bf4b7304fb79f55e30bd78..9932953822e9d7037c89ec0159a55aba30cefc02 100644 (file)
@@ -1,8 +1,8 @@
 ! (c)2009 Joe Groff bsd license
-USING: accessors alien audio classes.struct fry calendar timers
-combinators combinators.short-circuit destructors generalizations
-kernel literals locals math openal sequences
-sequences.generalizations specialized-arrays strings ;
+USING: accessors alien alien.data audio classes.struct fry
+calendar timers combinators combinators.short-circuit
+destructors generalizations kernel literals locals math openal
+sequences sequences.generalizations specialized-arrays strings ;
 QUALIFIED-WITH: alien.c-types c
 SPECIALIZED-ARRAYS: c:float c:uchar c:uint ;
 IN: audio.engine
@@ -122,7 +122,7 @@ ERROR: audio-context-not-available device-name ;
 
 :: flush-source ( al-source -- )
     al-source alSourceStop
-    0 c:<uint> :> dummy-buffer
+    0 c:uint <ref> :> dummy-buffer
     al-source AL_BUFFERS_PROCESSED get-source-param [
         al-source 1 dummy-buffer alSourceUnqueueBuffers
     ] times
@@ -161,7 +161,7 @@ ERROR: audio-context-not-available device-name ;
             audio-clip t >>done? drop
         ] [
             al-buffer audio-clip openal-format data size audio-clip sample-rate>> alBufferData
-            al-source 1 al-buffer c:<uint> alSourceQueueBuffers
+            al-source 1 al-buffer c:uint <ref> alSourceQueueBuffers
         ] if
     ] unless ;
 
@@ -190,10 +190,10 @@ M: static-audio-clip (update-audio-clip)
 
 M:: streaming-audio-clip (update-audio-clip) ( audio-clip -- )
     audio-clip al-source>> :> al-source
-    0 c:<uint> :> buffer
+    0 c:uint <ref> :> buffer
     al-source AL_BUFFERS_PROCESSED get-source-param [
         al-source 1 buffer alSourceUnqueueBuffers
-        audio-clip buffer c:*uint queue-clip-buffer
+        audio-clip buffer c:uint deref queue-clip-buffer
     ] times ;
 
 : update-audio-clip ( audio-clip -- )
@@ -256,7 +256,7 @@ M: audio-engine dispose*
     audio-engine get-available-source :> al-source
 
     al-source [
-        1 0 c:<uint> [ alGenBuffers ] keep c:*uint :> al-buffer
+        1 0 c:uint <ref> [ alGenBuffers ] keep c:uint deref :> al-buffer
         al-buffer audio { [ openal-format ] [ data>> ] [ size>> ] [ sample-rate>> ] } cleave
             alBufferData
 
@@ -301,7 +301,7 @@ M: audio-clip dispose*
 
 M: static-audio-clip dispose*
     [ call-next-method ]
-    [ [ 1 ] dip al-buffer>> c:<uint> alDeleteBuffers ] bi ;
+    [ [ 1 ] dip al-buffer>> c:uint <ref> alDeleteBuffers ] bi ;
 
 M: streaming-audio-clip dispose*
     [ call-next-method ]
index e67c7b7934ebf3a72a05a93d3810301f08af732b..2ae957812e8c53cf0cfd71cdc96a9592c0f8a08e 100644 (file)
@@ -1,9 +1,9 @@
 ! (c)2007, 2010 Chris Double, Joe Groff bsd license
-USING: accessors alien alien.c-types audio.engine byte-arrays
-classes.struct combinators destructors fry io io.files
-io.encodings.binary kernel libc locals make math math.order
-math.parser ogg ogg.vorbis sequences specialized-arrays
-specialized-vectors ;
+USING: accessors alien alien.c-types alien.data audio.engine
+byte-arrays classes.struct combinators destructors fry io
+io.files io.encodings.binary kernel libc locals make math
+math.order math.parser ogg ogg.vorbis sequences
+specialized-arrays specialized-vectors ;
 FROM: alien.c-types => float short void* ;
 SPECIALIZED-ARRAYS: float void* ;
 SPECIALIZED-VECTOR: short
@@ -157,7 +157,7 @@ ERROR: no-vorbis-in-ogg ;
     [ init-vorbis-codec ] if ;
 
 : get-pending-decoded-audio ( vorbis-stream -- pcm len )
-    dsp-state>> f <void*> [ vorbis_synthesis_pcmout ] keep *void* swap ;
+    dsp-state>> f void* <ref> [ vorbis_synthesis_pcmout ] keep void* deref swap ;
 
 : float>short-sample ( float -- short )
     -32767.5 * 0.5 - >integer -32768 32767 clamp ; inline
diff --git a/extra/benchmark/ui-panes/deploy.factor b/extra/benchmark/ui-panes/deploy.factor
new file mode 100644 (file)
index 0000000..90bd34b
--- /dev/null
@@ -0,0 +1,15 @@
+USING: tools.deploy.config ;
+H{
+    { deploy-ui? t }
+    { deploy-word-defs? f }
+    { deploy-threads? t }
+    { deploy-math? t }
+    { deploy-io 1 }
+    { deploy-reflection 1 }
+    { deploy-unicode? f }
+    { "stop-after-last-window?" t }
+    { deploy-console? f }
+    { deploy-word-props? f }
+    { deploy-c-types? f }
+    { deploy-name "benchmark.ui-panes" }
+}
index 9d16f75e15d2da7b4ced9d835b34f04b01aa2ddd..f50a96621810311814dd1ddc1c1df81aa3c48ebf 100644 (file)
@@ -1,7 +1,7 @@
-USING: ui.gadgets.panes prettyprint io sequences ;
+USING: io kernel math.parser sequences ui.gadgets.panes ;
 IN: benchmark.ui-panes
 
 : ui-pane-benchmark ( -- )
-    <pane> <pane-stream> [ 10000 iota [ . ] each ] with-output-stream* ;
+    [ 10000 iota [ number>string print ] each ] make-pane drop ;
 
 MAIN: ui-pane-benchmark
index cfe95956c050d88cf80561e586f5db4f6f22b4b1..0f22b531c69ba12e837a76d8e9f94bc2d88d471c 100644 (file)
@@ -42,7 +42,7 @@ IN: bunny.model
 
 : model-path ( -- path ) "bun_zipper.ply" temp-file ;
 
-: model-url ( -- url ) "http://factorcode.org/bun_zipper.ply" ;
+: model-url ( -- url ) "http://factorcode.org/slava/bun_zipper.ply" ;
 
 : maybe-download ( -- path )
     model-path dup exists? [
diff --git a/extra/central/authors.txt b/extra/central/authors.txt
deleted file mode 100644 (file)
index 5645cd9..0000000
+++ /dev/null
@@ -1 +0,0 @@
-Matthew Willis
diff --git a/extra/central/central-docs.factor b/extra/central/central-docs.factor
deleted file mode 100644 (file)
index 458f528..0000000
+++ /dev/null
@@ -1,16 +0,0 @@
-USING: central destructors help.markup help.syntax ;
-
-HELP: CENTRAL:
-{ $description
-    "This parsing word defines a pair of words useful for "
-    "implementing the \"central\" pattern: " { $snippet "symbol" } " and "
-    { $snippet "with-symbol" } ".  This is a middle ground between excessive "
-    "stack manipulation and full-out locals, meant to solve the case where "
-    "one object is operated on by several related words."
-} ;
-
-HELP: DISPOSABLE-CENTRAL:
-{ $description
-    "Like " { $link POSTPONE: CENTRAL: } ", but generates " { $snippet "with-" }
-    " words that are wrapped in a " { $link with-disposal } "."
-} ;
\ No newline at end of file
diff --git a/extra/central/central-tests.factor b/extra/central/central-tests.factor
deleted file mode 100644 (file)
index 17c5ee9..0000000
+++ /dev/null
@@ -1,19 +0,0 @@
-USING: accessors central destructors kernel math tools.test ;
-
-IN: scratchpad
-
-CENTRAL: test-central
-
-[ 3 ] [ 3 [ test-central ] with-test-central ] unit-test
-
-TUPLE: test-disp-cent value disposed ;
-
-! A phony destructor that adds 1 to the value so we can make sure it got called.
-M: test-disp-cent dispose* dup value>> 1 + >>value drop ;
-
-DISPOSABLE-CENTRAL: t-d-c
-
-: test-t-d-c ( -- n )
-    test-disp-cent new 3 >>value [ t-d-c ] with-t-d-c value>> ;
-
-[ 4 ] [ test-t-d-c ] unit-test
diff --git a/extra/central/central.factor b/extra/central/central.factor
deleted file mode 100644 (file)
index f717514..0000000
+++ /dev/null
@@ -1,28 +0,0 @@
-USING: destructors kernel lexer namespaces parser sequences words ;
-
-IN: central
-
-: define-central-getter ( word -- )
-    dup [ get ] curry (( -- obj )) define-declared ;
-
-: define-centrals ( str -- getter setter )
-    [ create-in dup define-central-getter ]
-    [ "with-" prepend create-in dup make-inline ] bi ;
-
-: central-setter-def ( word with-word -- with-word quot )
-    [ with-variable ] with ;
-
-: disposable-setter-def ( word with-word -- with-word quot )
-    [ pick [ drop with-variable ] with-disposal ] with ;
-
-: declare-central ( with-word quot -- ) (( object quot -- )) define-declared ;
-
-: define-central ( word-name -- )
-    define-centrals central-setter-def declare-central ;
-
-: define-disposable-central ( word-name -- )
-    define-centrals disposable-setter-def declare-central ;
-
-SYNTAX: CENTRAL: ( -- ) scan define-central ;
-
-SYNTAX: DISPOSABLE-CENTRAL: ( -- ) scan define-disposable-central ;
\ No newline at end of file
diff --git a/extra/central/tags.txt b/extra/central/tags.txt
deleted file mode 100644 (file)
index f427429..0000000
+++ /dev/null
@@ -1 +0,0 @@
-extensions
index 7a9ab59a6a5bc51911152c897ea9b57ec752b4c8..5218f7b23eed1f6665cdfdce0b6a88559fe20fa3 100644 (file)
@@ -9,14 +9,14 @@ IN: cuda.contexts
 
 : create-context ( device flags -- context )
     swap
-    [ CUcontext <c-object> ] 2dip
-    [ cuCtxCreate cuda-error ] 3keep 2drop *void* ; inline
+    [ { CUcontext } ] 2dip
+    '[ _ _ cuCtxCreate cuda-error ] with-out-parameters ; inline
 
 : sync-context ( -- )
     cuCtxSynchronize cuda-error ; inline
 
 : context-device ( -- n )
-    CUdevice <c-object> [ cuCtxGetDevice cuda-error ] keep *int ; inline
+    { CUdevice } [ cuCtxGetDevice cuda-error ] with-out-parameters ; inline
 
 : destroy-context ( context -- ) cuCtxDestroy cuda-error ; inline
 
index 2e2cdd660f0768c179dd9ca5180336b85cae18cb..c86fbacc69f0349935dd2a2cd969be5a193fc9f5 100644 (file)
@@ -16,7 +16,7 @@ TUPLE: cuda-error code ;
     dup CUDA_SUCCESS = [ drop ] [ \ cuda-error boa throw ] if ;
 
 : cuda-version ( -- n )
-    c:int <c-object> [ cuDriverGetVersion cuda-error ] keep c:*int ;
+    { c:int } [ cuDriverGetVersion cuda-error ] with-out-parameters ;
 
 : init-cuda ( -- )
     0 cuInit cuda-error ; inline
index 4e7a50e6f20e4b81e12c7745de488b14da9e1ae7..079234b2ee26dd858a2f3b16ba66a478c972b09e 100644 (file)
@@ -8,10 +8,10 @@ prettyprint sequences ;
 IN: cuda.devices
 
 : #cuda-devices ( -- n )
-    int <c-object> [ cuDeviceGetCount cuda-error ] keep *int ;
+    { int } [ cuDeviceGetCount cuda-error ] with-out-parameters ;
 
 : n>cuda-device ( n -- device )
-    [ CUdevice <c-object> ] dip [ cuDeviceGet cuda-error ] 2keep drop *int ;
+    [ { CUdevice } ] dip '[ _ cuDeviceGet cuda-error ] with-out-parameters ;
 
 : enumerate-cuda-devices ( -- devices )
     #cuda-devices iota [ n>cuda-device ] map ;
@@ -32,19 +32,17 @@ IN: cuda.devices
     [ 2drop utf8 alien>string ] 3bi ;
 
 : cuda-device-capability ( n -- pair )
-    [ int <c-object> int <c-object> ] dip
-    [ cuDeviceComputeCapability cuda-error ]
-    [ drop [ *int ] bi@ ] 3bi 2array ;
+    [ { int int } ] dip
+    '[ _ cuDeviceComputeCapability cuda-error ] with-out-parameters
+    2array ;
 
 : cuda-device-memory ( n -- bytes )
-    [ uint <c-object> ] dip
-    [ cuDeviceTotalMem cuda-error ]
-    [ drop *uint ] 2bi ;
+    [ { uint } ] dip
+    '[ _ cuDeviceTotalMem cuda-error ] with-out-parameters ;
 
 : cuda-device-attribute ( attribute n -- n )
-    [ int <c-object> ] 2dip
-    [ cuDeviceGetAttribute cuda-error ]
-    [ 2drop *int ] 3bi ;
+    [ { int } ] 2dip
+    '[ _ _ cuDeviceGetAttribute cuda-error ] with-out-parameters ;
 
 : cuda-device. ( n -- )
     {
index d4943e1350a4ce9d47eb4551ff3dbde588c36ecf..e4e093c1e95146c298422b29d425353efdca70e8 100644 (file)
@@ -6,29 +6,29 @@ IN: cuda.gl
 
 : create-gl-cuda-context ( device flags -- context )
     swap
-    [ CUcontext <c-object> ] 2dip
-    [ cuGLCtxCreate cuda-error ] 3keep 2drop *void* ; inline
+    [ { CUcontext } ] 2dip
+    '[ _ _ cuGLCtxCreate cuda-error ] with-out-parameters ; inline
 
 : with-gl-cuda-context ( device flags quot -- )
     [ set-up-cuda-context create-gl-cuda-context ] dip (with-cuda-context) ; inline 
 
 : gl-buffer>resource ( gl-buffer flags -- resource )
     enum>number
-    [ CUgraphicsResource <c-object> ] 2dip
-    [ cuGraphicsGLRegisterBuffer cuda-error ] 3keep 2drop *void* ; inline
+    [ { CUgraphicsResource } ] 2dip
+    '[ _ _ cuGraphicsGLRegisterBuffer cuda-error ] with-out-parameters ; inline
 
 : buffer>resource ( buffer flags -- resource )
     [ handle>> ] dip gl-buffer>resource ; inline
 
 : map-resource ( resource -- device-ptr size )
-    [ 1 swap <void*> f cuGraphicsMapResources cuda-error ] [
-        [ CUdeviceptr <c-object> uint <c-object> ] dip
-        [ cuGraphicsResourceGetMappedPointer cuda-error ] 3keep drop
-        [ *uint ] [ *uint ] bi*
+    [ 1 swap void* <ref> f cuGraphicsMapResources cuda-error ] [
+        [ { CUdeviceptr uint } ] dip
+        '[ _ cuGraphicsResourceGetMappedPointer cuda-error ]
+        with-out-parameters
     ] bi ; inline
 
 : unmap-resource ( resource -- )
-    1 swap <void*> f cuGraphicsUnmapResources cuda-error ; inline
+    1 swap void* <ref> f cuGraphicsUnmapResources cuda-error ; inline
 
 DESTRUCTOR: unmap-resource
 
index e930745a17d08b23dc3093e2b4182378f96a33c8..faf50bb39b049a94df86ef3b5b1f3c4b99c80d50 100644 (file)
@@ -74,8 +74,8 @@ M: sequence grid-dim
 PRIVATE>
 
 : load-module ( path -- module )
-    [ CUmodule <c-object> ] dip
-    [ cuModuleLoad cuda-error ] 2keep drop c:*void* ;
+    [ { CUmodule } ] dip
+    '[ _ cuModuleLoad cuda-error ] with-out-parameters ;
 
 : unload-module ( module -- )
     cuModuleUnload cuda-error ;
@@ -151,8 +151,8 @@ MACRO: cuda-arguments ( c-types abi -- quot: ( args... function -- ) )
     [ [ 0 cuda-param-size ] ] swap '[ _ [cuda-arguments] ] if-empty ;
 
 : get-function-ptr ( module string -- function )
-    [ CUfunction <c-object> ] 2dip
-    [ cuModuleGetFunction cuda-error ] 3keep 2drop c:*void* ;
+    [ { CUfunction } ] 2dip
+    '[ _ _ cuModuleGetFunction cuda-error ] with-out-parameters ;
 
 : cached-module ( module-name -- alien )
     lookup-cuda-library
@@ -170,9 +170,9 @@ MACRO: cuda-invoke ( module-name function-name arguments -- )
     ] ;
 
 : cuda-global* ( module-name symbol-name -- device-ptr size )
-    [ CUdeviceptr <c-object> c:uint <c-object> ] 2dip
+    [ { CUdeviceptr { c:uint initial: 0 } } ] 2dip
     [ cached-module ] dip 
-    '[ _ _ cuModuleGetGlobal cuda-error ] 2keep [ c:*uint ] bi@ ; inline
+    '[ _ _ cuModuleGetGlobal cuda-error ] with-out-parameters ; inline
 
 : cuda-global ( module-name symbol-name -- device-ptr )
     cuda-global* drop ; inline
index f3c452093a7ea044e2e2d6e732c82406698bd527..2369851292af4dfb8a6492cc7cba06d21775740e 100644 (file)
@@ -8,9 +8,8 @@ QUALIFIED-WITH: alien.c-types c
 IN: cuda.memory
 
 : cuda-malloc ( n -- ptr )
-    [ CUdeviceptr <c-object> ] dip
-    '[ _ cuMemAlloc cuda-error ] keep
-    c:*int ; inline
+    [ { CUdeviceptr } ] dip
+    '[ _ cuMemAlloc cuda-error ] with-out-parameters ; inline
 
 : cuda-malloc-type ( n type -- ptr )
     c:heap-size * cuda-malloc ; inline
index 61bdebfedd3c3327add87b4d20bb7758ace0a960..a0e6ba5f6e8656561370a4ed5fd5038f2d81bb6d 100644 (file)
@@ -1,28 +1,15 @@
 ! Copyright (C) 2010 Doug Coleman.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: accessors alien.enums alien.syntax arrays assocs
-byte-arrays calendar combinators combinators.smart constructors
-destructors fry grouping io io.binary io.buffers
-io.encodings.binary io.encodings.string io.encodings.utf8
-io.files io.ports io.sockets io.streams.byte-array io.timeouts
-kernel make math math.bitwise math.parser math.ranges
-math.statistics memoize namespaces random sequences
-slots.syntax splitting strings system unicode.categories
-vectors nested-comments io.sockets.private ;
+USING: accessors alien.enums alien.syntax arrays calendar
+combinators combinators.smart constructors destructors grouping
+io io.binary io.encodings.binary io.encodings.string
+io.encodings.utf8 io.sockets io.sockets.private
+io.streams.byte-array io.timeouts kernel make math math.bitwise
+math.parser namespaces nested-comments random sequences
+slots.syntax splitting system vectors vocabs.loader ;
 IN: dns
 
-GENERIC: stream-peek1 ( stream -- byte/f )
-
-M: input-port stream-peek1
-    dup check-disposed dup wait-to-read
-    [ drop f ] [ buffer>> buffer-peek ] if ; inline
-
-M: byte-reader stream-peek1
-    [ i>> ] [ underlying>> ] bi ?nth ;
-
-: peek1 ( -- byte ) input-stream get stream-peek1 ;
-
-: with-temporary-input-seek ( n seek-type quot -- )
+: with-input-seek ( n seek-type quot -- )
     tell-input [
         [ seek-input ] dip call
     ] dip seek-absolute seek-input ; inline
@@ -59,17 +46,6 @@ SYMBOL: dns-servers
 : clear-dns-servers ( -- )
     V{ } clone dns-servers set-global ;
 
-! Google DNS servers
-CONSTANT: initial-dns-servers { "8.8.8.8" "8.8.4.4" }
-
-: load-resolve.conf ( -- seq )
-    "/etc/resolv.conf" utf8 file-lines
-    [ [ blank? ] trim ] map
-    [ "#" head? not ] filter
-    [ [ " " split1 swap ] dip push-at ] sequence>hashtable "nameserver" swap at ;
-
-dns-servers [ initial-dns-servers >vector ] initialize
-
 : >dotted ( domain -- domain' )
     dup "." tail? [ "." append ] unless ;
 
@@ -172,7 +148,8 @@ CONSTANT: ipv4-arpa-suffix ".in-addr.arpa"
 CONSTANT: ipv6-arpa-suffix ".ip6.arpa"
 
 : ipv6>arpa ( string -- string )
-    ipv6>byte-array [ [ -4 shift 4 bits ] [ 4 bits ] bi 2array ] { } map-as
+    ipv6>byte-array
+    [ [ -4 shift 4 bits ] [ 4 bits ] bi 2array ] { } map-as
     B{ } concat-as reverse
     [ >hex ] { } map-as "." join ipv6-arpa-suffix append ;
 
@@ -190,21 +167,21 @@ CONSTANT: ipv6-arpa-suffix ".ip6.arpa"
         first2 swap [ hex> ] bi@ [ 4 shift ] [ ] bi* bitor
     ] B{ } map-as byte-array>ipv6 ;
 
-: parse-length-bytes ( -- seq ) read1 read utf8 decode ;
+: parse-length-bytes ( byte -- sequence ) read utf8 decode ;
 
 : (parse-name) ( -- )
-    peek1 [
-        read1 drop
-    ] [
-        HEX: C0 mask? [
-            2 read be> HEX: 3fff bitand
-            seek-absolute [ parse-length-bytes , (parse-name) ] with-temporary-input-seek
+    read1 [
+        dup HEX: C0 mask? [
+            8 shift read1 bitor HEX: 3fff bitand
+            seek-absolute [
+                read1 parse-length-bytes , (parse-name)
+            ] with-input-seek
         ] [
             parse-length-bytes , (parse-name)
         ] if
-    ] if-zero ;
+    ] unless-zero ;
 
-: parse-name ( -- seq )
+: parse-name ( -- sequence )
     [ (parse-name) ] { } make "." join ;
 
 : parse-query ( -- query )
@@ -246,7 +223,7 @@ M: SOA parse-rdata 2drop parse-soa ;
         4 read be> >>ttl
         2 read be> over type>> parse-rdata >>rdata ;
 
-: parse-message ( ba -- message )
+: parse-message ( byte-array -- message )
     [ message new ] dip
     binary [
         2 read be> >>id
@@ -261,12 +238,12 @@ M: SOA parse-rdata 2drop parse-soa ;
         [ [ parse-rr ] replicate ] change-additional-section
     ] with-byte-reader ;
 
-: >n/label ( string -- ba )
+: >n/label ( string -- byte-array )
     [ length 1array ] [ utf8 encode ] bi B{ } append-as ;
 
-: >name ( dn -- ba ) "." split [ >n/label ] map concat ;
+: >name ( domain -- byte-array ) "." split [ >n/label ] map concat ;
 
-: query>byte-array ( query -- ba )
+: query>byte-array ( query -- byte-array )
     [
         {
             [ name>> >name ]
@@ -309,7 +286,7 @@ M: SOA rdata>byte-array
         } cleave
     ] B{ } append-outputs-as ;
 
-: rr>byte-array ( rr -- ba )
+: rr>byte-array ( rr -- byte-array )
     [
         {
             [ name>> >name ]
@@ -323,7 +300,7 @@ M: SOA rdata>byte-array
         } cleave
     ] B{ } append-outputs-as ;
 
-: message>byte-array ( message -- ba )
+: message>byte-array ( message -- byte-array )
     [
         {
             [ id>> 2 >be ]
@@ -341,7 +318,7 @@ M: SOA rdata>byte-array
 
 : udp-query ( bytes server -- bytes' )
     f 0 <inet4> <datagram>
-    5 seconds over set-timeout [
+    30 seconds over set-timeout [
         [ send ] [ receive drop ] bi
     ] with-disposal ;
 
@@ -369,6 +346,10 @@ M: SOA rdata>byte-array
 : message>names ( message -- names )
     answer-section>> [ rdata>> name>> ] map ;
 
+: message>a-names ( message -- names )
+    answer-section>>
+    [ rdata>> ] map [ a? ] filter [ name>> ] map ;
+
 : message>mxs ( message -- assoc )
     answer-section>> [ rdata>> [ preference>> ] [ exchange>> ] bi 2array ] map ;
 
@@ -387,22 +368,21 @@ M: SOA rdata>byte-array
 : message>query-name ( message -- string )
     query>> first name>> dotted> ;
 
-: a-line. ( host ip -- )
-    [ write " has address " write ] [ print ] bi* ;
-
-: a-message. ( message -- )
-    [ message>query-name ] [ message>names ] bi
-    [ a-line. ] with each ;
-
-: mx-line. ( host pair -- )
-    [ write " mail is handled by " write ]
-    [ first2 [ number>string write bl ] [ print ] bi* ] bi* ;
-
-: mx-message. ( message -- )
-    [ message>query-name ] [ message>mxs ] bi
-    [ mx-line. ] with each ;
-
-: host ( domain -- )
-    [ dns-A-query a-message. ]
-    [ dns-AAAA-query a-message. ]
-    [ dns-MX-query mx-message. ] tri ;
+USE: nested-comments
+(*
+M: string resolve-host
+    dup >lower "localhost" = [
+        drop resolve-localhost
+    ] [
+        dns-A-query message>a-names [ <ipv4> ] map
+    ] if ;
+*)
+    
+HOOK: initial-dns-servers os ( -- sequence )
+
+{
+    { [ os windows? ] [ "dns.windows" ] }
+    { [ os unix? ] [ "dns.unix" ] }
+} cond require
+    
+dns-servers [ initial-dns-servers >vector ] initialize
diff --git a/extra/dns/unix/authors.txt b/extra/dns/unix/authors.txt
new file mode 100644 (file)
index 0000000..7c1b2f2
--- /dev/null
@@ -0,0 +1 @@
+Doug Coleman
diff --git a/extra/dns/unix/platforms.txt b/extra/dns/unix/platforms.txt
new file mode 100644 (file)
index 0000000..509143d
--- /dev/null
@@ -0,0 +1 @@
+unix
diff --git a/extra/dns/unix/unix.factor b/extra/dns/unix/unix.factor
new file mode 100644 (file)
index 0000000..31af530
--- /dev/null
@@ -0,0 +1,7 @@
+! Copyright (C) 2010 Doug Coleman.
+! See http://factorcode.org/license.txt for BSD license.
+USING: accessors dns resolv-conf system ;
+IN: dns.unix
+
+M: unix initial-dns-servers
+    default-resolv.conf nameserver>> ;
diff --git a/extra/dns/windows/authors.txt b/extra/dns/windows/authors.txt
new file mode 100644 (file)
index 0000000..7c1b2f2
--- /dev/null
@@ -0,0 +1 @@
+Doug Coleman
diff --git a/extra/dns/windows/platforms.txt b/extra/dns/windows/platforms.txt
new file mode 100644 (file)
index 0000000..8e1a559
--- /dev/null
@@ -0,0 +1 @@
+windows
diff --git a/extra/dns/windows/windows.factor b/extra/dns/windows/windows.factor
new file mode 100644 (file)
index 0000000..a43eede
--- /dev/null
@@ -0,0 +1,6 @@
+! Copyright (C) 2010 Doug Coleman.
+! See http://factorcode.org/license.txt for BSD license.
+USING: dns system windows.iphlpapi ;
+IN: dns.windows
+
+M: windows initial-dns-servers dns-server-ips ;
\ No newline at end of file
index 547b7b9ae926d2b1f234142b2cd947d3e38a7d3b..74fdad63eac9c1e35639d9312bc928cda4d9a77f 100644 (file)
@@ -67,9 +67,9 @@ PRIVATE>
 :: ecdsa-sign ( DGST -- sig )
     ec-key-handle :> KEY
     KEY ECDSA_size dup ssl-error <byte-array> :> SIG
-    0 <uint> :> LEN
+    0 uint <ref> :> LEN
     0 DGST dup length SIG LEN KEY ECDSA_sign ssl-error
-    LEN *uint SIG resize ;
+    LEN uint deref SIG resize ;
 
 : ecdsa-verify ( dgst sig -- ? )
     ec-key-handle [ 0 -rot [ dup length ] bi@ ] dip ECDSA_verify 0 > ;
old mode 100644 (file)
new mode 100755 (executable)
index 1bdcece..fa9d17e
@@ -2,7 +2,7 @@
 USING: accessors timers alien.c-types calendar classes.struct
 continuations destructors fry kernel math math.order memory
 namespaces sequences specialized-vectors system
-tools.memory ui ui.gadgets.worlds vm vocabs.loader arrays
+ui ui.gadgets.worlds vm vocabs.loader arrays
 tools.time.struct locals ;
 IN: game.loop
 
index 6172c8ad8ce616dd789e1fddf8babdd0c9e719c4..9ea08a7c837dc86d6182cf8982593966e463d81f 100644 (file)
@@ -57,7 +57,7 @@ TUPLE: buffer < gpu-object
     } case ; inline
 
 : get-buffer-int ( target enum -- value )
-    0 <int> [ glGetBufferParameteriv ] keep *int ; inline
+    0 int <ref> [ glGetBufferParameteriv ] keep int deref ; inline
 
 : bind-buffer ( buffer -- target )
     [ kind>> gl-target dup ] [ handle>> glBindBuffer ] bi ; inline
index f29e12c1a27a4673393d40e1fe6f71da7caa83f9..0491191c63421ddc2caec50bda217df462c65d62 100644 (file)
@@ -145,7 +145,7 @@ UNIFORM-TUPLE: loading-uniforms
 
 : bunny-model-path ( -- path ) "bun_zipper.ply" temp-file ;
 
-CONSTANT: bunny-model-url "http://factorcode.org/bun_zipper.ply"
+CONSTANT: bunny-model-url "http://factorcode.org/slava/bun_zipper.ply"
 
 : download-bunny ( -- path )
     bunny-model-path dup exists? [
index 1aa9ae33df895449eb409b1b51a1a3561908c427..9a594c1cd072d13e19940b020f22a0860f746fa9 100644 (file)
@@ -1,8 +1,8 @@
 ! (c)2009 Joe Groff bsd license
-USING: accessors alien.c-types arrays byte-arrays combinators
-destructors gpu gpu.buffers gpu.private gpu.textures
-gpu.textures.private images kernel locals math math.rectangles opengl
-opengl.framebuffers opengl.gl opengl.textures sequences
+USING: accessors alien.c-types alien.data arrays byte-arrays
+combinators destructors gpu gpu.buffers gpu.private gpu.textures
+gpu.textures.private images kernel locals math math.rectangles
+opengl opengl.framebuffers opengl.gl opengl.textures sequences
 specialized-arrays typed ui.gadgets.worlds variants ;
 SPECIALIZED-ARRAY: int
 SPECIALIZED-ARRAY: uint
@@ -18,7 +18,8 @@ TUPLE: renderbuffer < gpu-object
 <PRIVATE
 
 : get-framebuffer-int ( enum -- value )
-    GL_RENDERBUFFER swap 0 <int> [ glGetRenderbufferParameteriv ] keep *int ;
+    GL_RENDERBUFFER swap 0 int <ref>
+    [ glGetRenderbufferParameteriv ] keep int deref ;
 
 PRIVATE>
 
index d1c137128aa254e212e18b797abce5e6f8e51e7f..b032004d40d66ea9dadfbbb94fb2b9999deca43f 100755 (executable)
@@ -199,7 +199,7 @@ TR: hyphens>underscores "-" "_" ;
     name length 1 + :> name-buffer-length
     {
         index name-buffer-length dup
-        [ f 0 <int> 0 <int> ] dip <byte-array>
+        [ f 0 int <ref> 0 int <ref> ] dip <byte-array>
         [ glGetTransformFeedbackVarying ] 3keep
         ascii alien>string
         vertex-attribute assert-feedback-attribute    
index db767740384560dced591ffeebb77f7e8ae0cb7c..31a86780605c9b2257f6e4eb4fcea45a309c686c 100755 (executable)
@@ -416,11 +416,11 @@ M: mask-state set-gpu-state*
     [ set-gpu-state* ] if ; inline
 
 : get-gl-bool ( enum -- value )
-    0 <uchar> [ glGetBooleanv ] keep *uchar c-bool> ;
+    0 uchar <ref> [ glGetBooleanv ] keep uchar deref c-bool> ;
 : get-gl-int ( enum -- value )
-    0 <int> [ glGetIntegerv ] keep *int ;
+    0 int <ref> [ glGetIntegerv ] keep int deref ;
 : get-gl-float ( enum -- value )
-    0 <float> [ glGetFloatv ] keep *float ;
+    0 c:float <ref> [ glGetFloatv ] keep c:float deref ;
 
 : get-gl-bools ( enum count -- value )
     <byte-array> [ glGetBooleanv ] keep [ c-bool> ] { } map-as ;
index c67a03cbfcd85cad0956a047661f302bc8284c84..d9ae88675abfcd2dbb13930a26f6631b3ab064f8 100644 (file)
@@ -171,8 +171,8 @@ ERROR: undefined-find-nth m n seq quot ;
     [ [ name>> { "form" "input" } member? ] filter ] map ;
 
 : find-html-objects ( vector string -- vector' )
-    dupd find-opening-tags-by-name
-    [ first2 find-between* ] curry map ;
+    over find-opening-tags-by-name
+    [ first2 find-between* ] with map ;
 
 : form-action ( vector -- string )
     [ name>> "form" = ] find nip "action" attribute ;
index c72f06f13931ccb2ef777f992500a1e97c359329..b06210fc00a83d86c0dd7db5039c868ce4dac058 100644 (file)
@@ -3,7 +3,7 @@
 USING: accessors arrays combinators compression.lzw
 constructors destructors grouping images images.loader io
 io.binary io.buffers io.encodings.string io.encodings.utf8
-io.ports kernel make math math.bitwise namespaces sequences ;
+kernel make math math.bitwise namespaces sequences ;
 IN: images.gif
 
 SINGLETON: gif-image
@@ -74,14 +74,6 @@ CONSTANT: block-terminator HEX: 00
         V{ } clone >>comment-extensions
         t >>loading? ;
 
-GENERIC: stream-peek1 ( stream -- byte )
-
-M: input-port stream-peek1
-    dup check-disposed dup wait-to-read
-    [ drop f ] [ buffer>> buffer-peek ] if ; inline
-
-: peek1 ( -- byte ) input-stream get stream-peek1 ;
-
 : (read-sub-blocks) ( -- )
     read1 [ read , (read-sub-blocks) ] unless-zero ;
 
index 738f1749bca588a25cfc6e1029b61a22ea13c707..e3465a324ba3087aaffead9dce9eac660fa2f312 100644 (file)
@@ -37,8 +37,8 @@ SYMBOL: js-context
 
 : eval-js ( string -- result-string )
     [ js-context get dup ] dip
-    JSStringCreateWithUTF8CString f f 0 JSValueRef <c-object>
-    [ JSEvaluateScript ] keep *void*
+    JSStringCreateWithUTF8CString f f 0
+    { { void* initial: f } } [ JSEvaluateScript ] with-out-parameters
     dup [ nip JSValueRef>string javascriptcore-error ] [ drop JSValueRef>string ] if ;
 
 : eval-js-standalone ( string -- result-string )
index fc755fd00fa6c93e48909ffc3054b73aae036096..eb3bebe819f2a5e51686434ad15bb00e83adbd84 100644 (file)
@@ -1,7 +1,8 @@
 ! Copyright (C) 2009 Matthew Willis.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: accessors alien.c-types alien.syntax assocs destructors
-kernel llvm.core llvm.engine llvm.wrappers namespaces ;
+USING: accessors alien.c-types alien.data alien.syntax assocs
+destructors kernel llvm.core llvm.engine llvm.wrappers
+namespaces ;
 
 IN: llvm.jit
 
@@ -25,9 +26,9 @@ TUPLE: jit ee mps ;
     LLVMGetFirstFunction dup ALIEN: 0 = [ drop ] [ (remove-functions) ] if ;
 
 : remove-provider ( provider -- )
-    current-jit ee>> value>> swap value>> f <void*> f <void*>
-    [ LLVMRemoveModuleProvider drop ] 2keep *void* [ llvm-throw ] when*
-    *void* module new swap >>value
+    current-jit ee>> value>> swap value>> f void* <ref> f void* <ref>
+    [ LLVMRemoveModuleProvider drop ] 2keep void* deref [ llvm-throw ] when*
+    void* deref module new swap >>value
     [ value>> remove-functions ] with-disposal ;
 
 : remove-module ( name -- )
@@ -44,5 +45,5 @@ TUPLE: jit ee mps ;
 
 : function-pointer ( name -- alien )
     current-jit ee>> value>> dup
-    rot f <void*> [ LLVMFindFunction drop ] keep
-    *void* LLVMGetPointerToGlobal ;
\ No newline at end of file
+    rot f void* <ref> [ LLVMFindFunction drop ] keep
+    void* deref LLVMGetPointerToGlobal ;
index 8c324b41e47d736450927b87b6b0891449e1ba0f..90cf36f955bbf0c38f8eeb53b54363b00b9dadcc 100644 (file)
@@ -1,15 +1,16 @@
 ! Copyright (C) 2009 Matthew Willis.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: accessors alien.c-types alien.syntax destructors kernel
-llvm.core llvm.engine llvm.jit llvm.wrappers ;
+USING: accessors alien.c-types alien.data alien.syntax
+destructors kernel llvm.core llvm.engine llvm.jit llvm.wrappers
+;
 
 IN: llvm.reader
 
 : buffer>module ( buffer -- module )
     [
-        value>> f <void*> f <void*>
+        value>> f void* <ref> f void* <ref>
         [ LLVMParseBitcode drop ] 2keep
-        *void* [ llvm-throw ] when* *void*
+        void* deref [ llvm-throw ] when* void* deref
         module new swap >>value
     ] with-disposal ;
 
@@ -17,4 +18,4 @@ IN: llvm.reader
     <buffer> buffer>module ;
 
 : load-into-jit ( path name -- )
-    [ load-module ] dip add-module ;
\ No newline at end of file
+    [ load-module ] dip add-module ;
index 05aafce973ead3f82c61e3c38b532f4773817bce..27c8a0592a3575d5ee0c0b0fe8c18569d00f9d5d 100644 (file)
@@ -1,6 +1,6 @@
 ! Copyright (C) 2009 Matthew Willis.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: accessors alien.c-types alien.strings
+USING: accessors alien.c-types alien.data alien.strings
 io.encodings.utf8 destructors kernel
 llvm.core llvm.engine ;
 
@@ -33,9 +33,9 @@ M: engine dispose* value>> LLVMDisposeExecutionEngine ;
 
 : (engine) ( provider -- engine )
     [
-        value>> f <void*> f <void*>
+        value>> f void* <ref> f void* <ref>
         [ swapd 0 swap LLVMCreateJITCompiler drop ] 2keep
-        *void* [ llvm-throw ] when* *void*
+        void* deref [ llvm-throw ] when* void* deref
     ]
     [ t >>disposed drop ] bi
     engine <dispose> ;
@@ -57,6 +57,6 @@ TUPLE: buffer value disposed ;
 M: buffer dispose* value>> LLVMDisposeMemoryBuffer ;
 
 : <buffer> ( path -- module )
-    f <void*> f <void*>
+    f void* <ref> f void* <ref>
     [ LLVMCreateMemoryBufferWithContentsOfFile drop ] 2keep
-    *void* [ llvm-throw ] when* *void* buffer <dispose> ;
\ No newline at end of file
+    void* deref [ llvm-throw ] when* void* deref buffer <dispose> ;
index fc4ad0d07e928244d253fd5fa257be263c933d79..eb4b238f6157416ca30f3a1bf0124b5dea77485e 100644 (file)
@@ -2,6 +2,8 @@ USING: kernel math math.functions math.finance tools.test ;
 
 IN: math.finance.tests
 
+[ { 1 2 3 4 } ] [ { 1 2 3 4 5 } 1 ema ] unit-test
+
 [ { 2 4 } ] [ { 1 3 5 } 2 sma ] unit-test
 
 [ { 1 3 1 } ] [ { 1 3 2 6 3 } 2 momentum ] unit-test
index f1c608bad912017f37f4afce36f527952f61544c..12f58c891bf9a2fd79a3f138fe2f0b055cde2bd8 100644 (file)
@@ -15,7 +15,7 @@ IN: math.finance
 PRIVATE>
 
 : ema ( seq n -- newseq )
-    a swap unclip [ [ dup ] 2dip spin weighted ] accumulate 2nip ;
+    a swap unclip [ swap pick weighted ] accumulate 2nip ;
 
 : sma ( seq n -- newseq )
     clump [ mean ] map ;
index c6f1601955d178df47b494ef4c3f8983b922e5bd..6803dfa67b8887b0d7b6b464763e5e428abebb69 100755 (executable)
@@ -1,6 +1,9 @@
 ! Copyright (C) 2007, 2008, 2009 Alex Chapman, 2009 Diego Martinelli
 ! See http://factorcode.org/license.txt for BSD license.
-USING: accessors ascii assocs biassocs combinators hashtables kernel lists literals math namespaces make multiline openal openal.alut parser sequences splitting strings synth synth.buffers ;
+USING: accessors ascii assocs biassocs combinators hashtables
+kernel lists literals math namespaces make multiline openal
+openal.alut parser sequences splitting strings synth
+synth.buffers ;
 IN: morse
 
 ERROR: no-morse-ch ch ;
index 54439b762ca2f34f935041286e094ac89c0dd53f..ccc4238533ba7b3ed020cf31608db937734f0586 100755 (executable)
@@ -1,6 +1,6 @@
 ! Copyright (C) 2007 Chris Double.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: alien.c-types kernel alien alien.syntax shuffle
+USING: alien.c-types alien.data kernel alien alien.syntax shuffle
 openal openal.alut.backend namespaces system generalizations ;
 IN: openal.alut.macosx
 
@@ -9,6 +9,6 @@ LIBRARY: alut
 FUNCTION: void alutLoadWAVFile ( c-string fileName, ALenum* format, void** data, ALsizei* size, ALsizei* frequency ) ;
 
 M: macosx load-wav-file ( path -- format data size frequency )
-    0 <int> f <void*> 0 <int> 0 <int>
+    0 int <ref> f void* <ref> 0 int <ref> 0 int <ref>
     [ alutLoadWAVFile ] 4 nkeep
-    [ [ [ *int ] dip *void* ] dip *int ] dip *int ;
+    [ [ [ int deref ] dip void* deref ] dip int deref ] dip int deref ;
index 8b1cbd0cb35996a8dd50d9e520bab1637202b7a6..8b446c3f5c26c76d7bf10409886eca2952b50b85 100755 (executable)
@@ -1,7 +1,7 @@
 ! Copyright (C) 2007 Chris Double.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: alien.c-types alien.syntax combinators generalizations
-kernel openal openal.alut.backend ;
+USING: alien.c-types alien.data alien.syntax combinators
+generalizations kernel openal openal.alut.backend ;
 IN: openal.alut.other
 
 LIBRARY: alut
@@ -9,6 +9,9 @@ LIBRARY: alut
 FUNCTION: void alutLoadWAVFile ( c-string fileName, ALenum* format, void** data, ALsizei* size, ALsizei* frequency, ALboolean* looping ) ;
 
 M: object load-wav-file ( filename -- format data size frequency )
-    0 <int> f <void*> 0 <int> 0 <int>
-    [ 0 <char> alutLoadWAVFile ] 4 nkeep
-    { [ *int ] [ *void* ] [ *int ] [ *int ] } spread ;
+    0 int <ref>
+    f void* <ref>
+    0 int <ref>
+    0 int <ref>
+    [ 0 char <ref> alutLoadWAVFile ] 4 nkeep
+    { [ int deref ] [ void* deref ] [ int deref ] [ int deref ] } spread ;
index 853b33b38627b2a1d31034000be6006d2acd6c72..8f2d77b1e41f1ff75d5d227f959992211d1e545b 100755 (executable)
@@ -1,10 +1,11 @@
 ! Copyright (C) 2007 Chris Double.
 ! See http://factorcode.org/license.txt for BSD license.
 USING: kernel accessors arrays alien system combinators
-alien.syntax namespaces alien.c-types sequences vocabs.loader
+alien.syntax namespaces sequences vocabs.loader
 shuffle alien.libraries generalizations
-specialized-arrays alien.destructors ;
-FROM: alien.c-types => float short ;
+specialized-arrays alien.destructors alien.data ;
+FROM: alien.c-types => char double float int short uchar uint
+ushort void ;
 SPECIALIZED-ARRAY: uint
 IN: openal
 
@@ -264,13 +265,13 @@ DESTRUCTOR: alcDestroyContext
     alSourcei ;
 
 : get-source-param ( source param -- value )
-    0 <uint> dup [ alGetSourcei ] dip *uint ;
+    0 uint <ref> dup [ alGetSourcei ] dip uint deref ;
 
 : set-buffer-param ( source param value -- )
     alBufferi ;
 
 : get-buffer-param ( source param -- value )
-    0 <uint> dup [ alGetBufferi ] dip *uint ;
+    0 uint <ref> dup [ alGetBufferi ] dip uint deref ;
 
 : source-play ( source -- ) alSourcePlay ;
 
index 1ec96e4c769427833b927ff6f33c24cb04e7e081..60083a0b0a7db596c3339ae996c8491522622ab2 100644 (file)
@@ -29,33 +29,33 @@ ERROR: cl-error err ;
     str-alien str-buffer dup length memcpy str-alien ;
     
 :: opencl-square ( in -- out )
-    0 f 0 <uint> [ clGetPlatformIDs cl-success ] keep *uint
+    0 f 0 uint <ref> [ clGetPlatformIDs cl-success ] keep uint deref
     dup <void*-array> [ f clGetPlatformIDs cl-success ] keep first
-    CL_DEVICE_TYPE_DEFAULT 1 f <void*> [ f clGetDeviceIDs cl-success ] keep *void* :> device-id
-    f 1 device-id <void*> f f 0 <int> [ clCreateContext ] keep *int cl-success   :> context
-    context device-id 0 0 <int> [ clCreateCommandQueue ] keep *int cl-success    :> queue
+    CL_DEVICE_TYPE_DEFAULT 1 f void* <ref> [ f clGetDeviceIDs cl-success ] keep void* deref :> device-id
+    f 1 device-id void* <ref> f f 0 int <ref> [ clCreateContext ] keep int deref cl-success   :> context
+    context device-id 0 0 int <ref> [ clCreateCommandQueue ] keep int deref cl-success    :> queue
  
     [
-        context 1 kernel-source cl-string-array <void*>
-        f 0 <int> [ clCreateProgramWithSource ] keep *int cl-success
+        context 1 kernel-source cl-string-array void* <ref>
+        f 0 int <ref> [ clCreateProgramWithSource ] keep int deref cl-success
         [ 0 f f f f clBuildProgram cl-success ]
-        [ "square" cl-string-array 0 <int> [ clCreateKernel ] keep *int cl-success ]
+        [ "square" cl-string-array 0 int <ref> [ clCreateKernel ] keep int deref cl-success ]
         [ ] tri
     ] with-destructors :> ( kernel program )
 
     context CL_MEM_READ_ONLY in byte-length f
-    0 <int> [ clCreateBuffer ] keep *int cl-success :> input
+    0 int <ref> [ clCreateBuffer ] keep int deref cl-success :> input
     
     context CL_MEM_WRITE_ONLY in byte-length f
-    0 <int> [ clCreateBuffer ] keep *int cl-success :> output
+    0 int <ref> [ clCreateBuffer ] keep int deref cl-success :> output
 
     queue input CL_TRUE 0 in byte-length in 0 f f clEnqueueWriteBuffer cl-success
 
-    kernel 0 cl_mem heap-size input <void*> clSetKernelArg cl-success
-    kernel 1 cl_mem heap-size output <void*> clSetKernelArg cl-success
-    kernel 2 uint heap-size in length <uint> clSetKernelArg cl-success
+    kernel 0 cl_mem heap-size input void* <ref> clSetKernelArg cl-success
+    kernel 1 cl_mem heap-size output void* <ref> clSetKernelArg cl-success
+    kernel 2 uint heap-size in length uint <ref> clSetKernelArg cl-success
  
-    queue kernel 1 f in length <ulonglong> f
+    queue kernel 1 f in length ulonglong <ref> f
     0 f f clEnqueueNDRangeKernel cl-success
  
     queue clFinish cl-success
index 6fd7bb581d5513b201857ca0ebe82db1c8b801eb..628a9b0d63a216caef4370ef95133207b5f87432 100644 (file)
@@ -32,7 +32,7 @@ __kernel void square(
             cl-read-access num-bytes in <cl-buffer> &dispose :> in-buffer
             cl-write-access num-bytes f <cl-buffer> &dispose :> out-buffer
             
-            kernel in-buffer out-buffer num-floats <uint> 3array
+            kernel in-buffer out-buffer num-floats uint <ref> 3array
             { num-floats } [ ] cl-queue-kernel &dispose drop
             
             cl-finish
index 17f0143ae1c067a9af94f3ff23b60f42f4381675..01ceb4e88f35d4d51354502b773b7d37f20d9d0c 100644 (file)
@@ -1,9 +1,10 @@
 ! Copyright (C) 2010 Erik Charlebois.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: accessors alien alien.c-types arrays byte-arrays combinators
-combinators.smart destructors io.encodings.ascii io.encodings.string
-kernel libc locals math namespaces opencl.ffi sequences shuffle
-specialized-arrays variants ;
+USING: accessors alien alien.c-types alien.data arrays
+byte-arrays combinators combinators.smart destructors
+io.encodings.ascii io.encodings.string kernel libc locals math
+namespaces opencl.ffi sequences shuffle specialized-arrays
+variants ;
 IN: opencl
 SPECIALIZED-ARRAYS: void* char size_t ;
 
@@ -17,7 +18,7 @@ ERROR: cl-error err ;
     dup f = [ cl-error ] [ drop ] if ; inline
  
 : info-data-size ( handle name info-quot -- size_t )
-    [ 0 f 0 <size_t> ] dip [ call cl-success ] 2keep drop *size_t ; inline
+    [ 0 f 0 <size_t> ] dip [ call cl-success ] 2keep drop size_t deref ; inline
 
 : info-data-bytes ( handle name info-quot size -- bytes )
     swap [ dup <byte-array> f ] dip [ call cl-success ] 3keep 2drop ; inline
@@ -26,7 +27,7 @@ ERROR: cl-error err ;
     [ 3dup info-data-size info-data-bytes ] dip call ; inline
 
 : 2info-data-size ( handle1 handle2 name info-quot -- size_t )
-    [ 0 f 0 <size_t> ] dip [ call cl-success ] 2keep drop *size_t ; inline
+    [ 0 f 0 <size_t> ] dip [ call cl-success ] 2keep drop size_t deref ; inline
 
 : 2info-data-bytes ( handle1 handle2 name info-quot size -- bytes )
     swap [ dup <byte-array> f ] dip [ call cl-success ] 3keep 2drop ; inline
@@ -35,22 +36,22 @@ ERROR: cl-error err ;
     [ 4dup 2info-data-size 2info-data-bytes ] dip call ; inline
     
 : info-bool ( handle name quot -- ? )
-    [ *uint CL_TRUE = ] info ; inline
+    [ uint deref CL_TRUE = ] info ; inline
 
 : info-ulong ( handle name quot -- ulong )
-    [ *ulonglong ] info ; inline
+    [ ulonglong deref ] info ; inline
 
 : info-int ( handle name quot -- int )
-    [ *int ] info ; inline
+    [ int deref ] info ; inline
 
 : info-uint ( handle name quot -- uint )
-    [ *uint ] info ; inline
+    [ uint deref ] info ; inline
 
 : info-size_t ( handle name quot -- size_t )
-    [ *size_t ] info ; inline
+    [ size_t deref ] info ; inline
 
 : 2info-size_t ( handle1 handle2 name quot -- size_t )
-    [ *size_t ] 2info ; inline
+    [ size_t deref ] 2info ; inline
 
 : info-string ( handle name quot -- string )
     [ ascii decode 1 head* ] info ; inline
@@ -311,7 +312,7 @@ M: cl-filter-linear  filter-mode-constant drop CL_FILTER_LINEAR ;
 
 : platform-devices ( platform-id -- devices )
     CL_DEVICE_TYPE_ALL [
-        0 f 0 <uint> [ clGetDeviceIDs cl-success ] keep *uint
+        0 f 0 uint <ref> [ clGetDeviceIDs cl-success ] keep uint deref
     ] [
         rot dup <void*-array> [ f clGetDeviceIDs cl-success ] keep
     ] 2bi ; inline
@@ -340,7 +341,7 @@ M: cl-filter-linear  filter-mode-constant drop CL_FILTER_LINEAR ;
         [ length ]
         [ strings>char*-array ]
         [ [ length ] size_t-array{ } map-as ] tri
-        0 <int> [ clCreateProgramWithSource ] keep *int cl-success
+        0 int <ref> [ clCreateProgramWithSource ] keep int deref cl-success
     ] with-destructors ;
 
 :: (build-program) ( program-handle device options -- program )
@@ -403,7 +404,7 @@ M: cl-filter-linear  filter-mode-constant drop CL_FILTER_LINEAR ;
     [ clGetEventProfilingInfo ] info-ulong ;
 
 : bind-kernel-arg-buffer ( kernel index buffer -- )
-    [ handle>> ] [ cl_mem heap-size ] [ handle>> <void*> ] tri*
+    [ handle>> ] [ cl_mem heap-size ] [ handle>> void* deref ] tri*
     clSetKernelArg cl-success ; inline
 
 : bind-kernel-arg-data ( kernel index byte-array -- )
@@ -425,7 +426,7 @@ PRIVATE>
     ] dip bind ; inline
 
 : cl-platforms ( -- platforms )
-    0 f 0 <uint> [ clGetPlatformIDs cl-success ] keep *uint
+    0 f 0 uint <ref> [ clGetPlatformIDs cl-success ] keep uint deref
     dup <void*-array> [ f clGetPlatformIDs cl-success ] keep
     [
         dup
@@ -437,14 +438,14 @@ PRIVATE>
 : <cl-context> ( devices -- cl-context )
     [ f ] dip
     [ length ] [ [ id>> ] void*-array{ } map-as ] bi
-    f f 0 <int> [ clCreateContext ] keep *int cl-success
+    f f 0 int <ref> [ clCreateContext ] keep int deref cl-success
     cl-context new-disposable swap >>handle ;
 
 : <cl-queue> ( context device out-of-order? profiling? -- command-queue )
     [ [ handle>> ] [ id>> ] bi* ] 2dip
     [ [ CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE ] [ 0 ] if ]
     [ [ CL_QUEUE_PROFILING_ENABLE ] [ 0 ] if ] bi* bitor
-    0 <int> [ clCreateCommandQueue ] keep *int cl-success
+    0 int <ref> [ clCreateCommandQueue ] keep int deref cl-success
     cl-queue new-disposable swap >>handle ;
 
 : cl-out-of-order-execution? ( command-queue -- ? )
@@ -462,7 +463,7 @@ PRIVATE>
         [ buffer-access-constant ]
         [ [ CL_MEM_COPY_HOST_PTR ] [ CL_MEM_ALLOC_HOST_PTR ] if ] tri* bitor
     ] 2dip
-    0 <int> [ clCreateBuffer ] keep *int cl-success
+    0 int <ref> [ clCreateBuffer ] keep int deref cl-success
     cl-buffer new-disposable swap >>handle ;
 
 : cl-read-buffer ( buffer-range -- byte-array )
@@ -488,7 +489,7 @@ PRIVATE>
         [ [ buffer>> handle>> ] [ offset>> ] bi ]
         tri* swapd
     ] 2dip [ length ] keep [ f ] [ [ handle>> ] void*-array{ } map-as ] if-empty
-    f <void*> [ clEnqueueCopyBuffer cl-success ] keep *void* cl-event
+    f void* <ref> [ clEnqueueCopyBuffer cl-success ] keep void* deref cl-event
     new-disposable swap >>handle ;
 
 : cl-queue-read-buffer ( buffer-range alien dependent-events -- event )
@@ -496,7 +497,7 @@ PRIVATE>
         [ (current-cl-queue) handle>> ] dip
         [ buffer>> handle>> CL_FALSE ] [ offset>> ] [ size>> ] tri
     ] 2dip [ length ] keep [ f ] [ [ handle>> ] void*-array{ } map-as ] if-empty
-    f <void*> [ clEnqueueReadBuffer cl-success ] keep *void* cl-event
+    f void* <ref> [ clEnqueueReadBuffer cl-success ] keep void* <ref> cl-event
     new-disposable swap >>handle ;
 
 : cl-queue-write-buffer ( buffer-range alien dependent-events -- event )
@@ -504,7 +505,7 @@ PRIVATE>
         [ (current-cl-queue) handle>> ] dip
         [ buffer>> handle>> CL_FALSE ] [ offset>> ] [ size>> ] tri
     ] 2dip [ length ] keep [ f ] [ [ handle>> ] void*-array{ } map-as ] if-empty
-    f <void*> [ clEnqueueWriteBuffer cl-success ] keep *void* cl-event
+    f void* <ref> [ clEnqueueWriteBuffer cl-success ] keep void* deref cl-event
     new-disposable swap >>handle ;
 
 : <cl-sampler> ( normalized-coords? addressing-mode filter-mode -- sampler )
@@ -512,7 +513,7 @@ PRIVATE>
     [ [ CL_TRUE ] [ CL_FALSE ] if ]
     [ addressing-mode-constant ]
     [ filter-mode-constant ]
-    tri* 0 <int> [ clCreateSampler ] keep *int cl-success 
+    tri* 0 int <ref> [ clCreateSampler ] keep int deref cl-success 
     cl-sampler new-disposable swap >>handle ;
 
 : cl-normalized-coords? ( sampler -- ? )
@@ -531,7 +532,7 @@ PRIVATE>
 
 : <cl-kernel> ( program kernel-name -- kernel )
     [ handle>> ] [ ascii encode 0 suffix ] bi*
-    0 <int> [ clCreateKernel ] keep *int cl-success
+    0 int <ref> [ clCreateKernel ] keep int deref cl-success
     cl-kernel new-disposable swap >>handle ; inline
 
 : cl-kernel-name ( kernel -- string )
@@ -549,7 +550,7 @@ PRIVATE>
     kernel handle>>
     sizes [ length f ] [ [ ] size_t-array{ } map-as f ] bi
     dependent-events [ length ] [ [ f ] [ [ handle>> ] void*-array{ } map-as ] if-empty ] bi
-    f <void*> [ clEnqueueNDRangeKernel cl-success ] keep *void*
+    f void* <ref> [ clEnqueueNDRangeKernel cl-success ] keep void* deref
     cl-event new-disposable swap >>handle ;
 
 : cl-event-type ( event -- command-type )
@@ -573,7 +574,7 @@ PRIVATE>
 
 : cl-marker ( -- event )
     (current-cl-queue)
-    f <void*> [ clEnqueueMarker cl-success ] keep *void* cl-event new-disposable
+    f void* <ref> [ clEnqueueMarker cl-success ] keep void* deref cl-event new-disposable
     swap >>handle ; inline
 
 : cl-barrier ( -- )
index 46f1048ba7983797c037be4cfc76c5c2100b57fd..c282aa1dc0e596cbfcbb4c18a7870d776295f052 100644 (file)
@@ -1,9 +1,9 @@
 ! Copyright (C) 2010 Samuel Tardieu.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: help.markup help.syntax ;
+USING: help.markup help.syntax assocs ;
 IN: path-finding
 
-{ <astar> <bfs> } related-words
+{ <astar> <bfs> <dijkstra> } related-words
 
 HELP: astar
 { $description "This tuple must be subclassed and its method " { $link cost } ", "
@@ -45,7 +45,7 @@ HELP: <astar>
   { "neighbours" "a quotation with stack effect ( node -- seq )" }
   { "cost" "a quotation with stack effect ( from to -- cost )" }
   { "heuristic" "a quotation with stack effect ( pos target -- cost )" }
-  { "astar" "a astar tuple" }
+  { "astar" astar }
 }
 { $description "Build an astar object from the given quotations. The "
   { $snippet "neighbours" } " one builds the list of neighbours. The "
@@ -57,19 +57,31 @@ HELP: <astar>
 
 HELP: <bfs>
 { $values
-  { "neighbours" "an assoc" }
-  { "astar" "a astar tuple" }
+  { "neighbours" assoc }
+  { "astar" astar }
 }
 { $description "Build an astar object from the " { $snippet "neighbours" } " assoc. "
   "When used with " { $link find-path } ", this astar tuple will use the breadth-first search (BFS) "
   "path finding algorithm which is a particular case of the general A* algorithm."
 } ;
 
+HELP: <dijkstra>
+{ $values
+  { "costs" assoc }
+  { "astar" astar }
+}
+{ $description "Build an astar object from the " { $snippet "costs" } " assoc. "
+  "The assoc keys are edges of the graph, while the corresponding values are assocs whose keys are "
+  "the edges that can be reached and whose values are the costs to reach those edges. When used with "
+  { $link find-path } ", this astar tuple will use the Dijkstra path finding algorithm which is "
+  "a particular case of the general A* algorithm."
+} ;
+
 HELP: find-path
 { $values
   { "start" "a node" }
   { "target" "a node" }
-  { "astar" "a astar tuple" }
+  { "astar" astar }
   { "path/f" "an optimal path from " { $snippet "start" } " to " { $snippet "target" }
     ", or f if no such path exists" }
 }
@@ -79,7 +91,7 @@ HELP: find-path
 
 HELP: considered
 { $values
-  { "astar" "a astar tuple" }
+  { "astar" astar }
   { "considered" "a sequence" }
 }
 { $description "When called after a call to " { $link find-path } ", return a list of nodes "
index 11a047cb89684cb0c2430a12d7246266213acc56..0e9b5289b11a3de262f07aaa0a18f3333f42cda1 100644 (file)
@@ -120,3 +120,21 @@ MEMO: routes ( -- hash ) $[ { "ABD" "BC" "C" "DCE" "ECF" } [ unclip swap 2array
 
 [ f ] [ "FA" first2 routes <bfs> find-path ] unit-test
 [ "DC" ] [ "DC" first2 routes <bfs> find-path >string ] unit-test
+
+<<
+
+! Build the costs as expected by the dijkstra word.
+
+MEMO: costs ( -- costs )
+    routes keys [ dup dup n [ dup [ c ] dip swap 2array ] with { } map-as >hashtable 2array ] map >hashtable ;
+
+: test3 ( fromto -- path considered )
+    first2 costs <dijkstra> [ find-path ] [ considered natural-sort >string ] bi ;
+
+>>
+
+! Check path from A to C -- all nodes but F must have been examined
+[ "ADC" "ABCDE" ] [ "AC" test3 [ >string ] dip ] unit-test
+
+! No path from D to B -- all nodes reachable from D must have been examined
+[ f "CDEF" ] [ "DB" test3 ] unit-test
index cd63a5c8d52c78cc48301811ac91f579263b717b..4b11616c201c91633e48f66bf0b63e9feb9b17f0 100644 (file)
@@ -74,6 +74,11 @@ M: bfs cost 3drop 1 ;
 M: bfs heuristic 3drop 0 ;
 M: bfs neighbours neighbours>> at ;
 
+TUPLE: dijkstra < astar costs ;
+M: dijkstra cost costs>> swapd at at ;
+M: dijkstra heuristic 3drop 0 ;
+M: dijkstra neighbours costs>> at keys ;
+
 PRIVATE>
 
 : find-path ( start target astar -- path/f )
@@ -87,3 +92,6 @@ PRIVATE>
 
 : <bfs> ( neighbours -- astar )
     [ bfs new ] dip >>neighbours ;
+
+: <dijkstra> ( costs -- astar )
+    [ dijkstra new ] dip >>costs ;
index 00a5c447713e87b36b3d46c8828ba8209e481777..c786c98c6ccf32b94c00bec7295b7b7d6cf8cf14 100644 (file)
@@ -15,7 +15,7 @@ IN: project-euler.006
 !    (1 + 2 + ... + 10)² = 55² = 3025
 
 ! Hence the difference between the sum of the squares of the first ten natural
-! numbers and the square of the sum is 3025 385 = 2640.
+! numbers and the square of the sum is 3025 385 = 2640.
 
 ! Find the difference between the sum of the squares of the first one hundred
 ! natural numbers and the square of the sum.
diff --git a/extra/resolv-conf/authors.txt b/extra/resolv-conf/authors.txt
new file mode 100644 (file)
index 0000000..7c1b2f2
--- /dev/null
@@ -0,0 +1 @@
+Doug Coleman
diff --git a/extra/resolv-conf/resolv-conf.factor b/extra/resolv-conf/resolv-conf.factor
new file mode 100644 (file)
index 0000000..d8d370a
--- /dev/null
@@ -0,0 +1,97 @@
+! Copyright (C) 2010 Doug Coleman.
+! See http://factorcode.org/license.txt for BSD license.
+USING: accessors combinators constructors io.encodings.utf8
+io.files kernel math math.parser sequences splitting
+unicode.categories ;
+IN: resolv-conf
+
+TUPLE: network ip netmask ;
+CONSTRUCTOR: network ( ip netmask -- network ) ;
+
+TUPLE: options
+debug?
+edns0?
+insecure1?
+insecure2?
+{ ndots integer initial: 1 }
+{ timeout integer initial: 5 }
+{ attempts integer initial: 2 }
+rotate? no-check-names? inet6? tcp? ;
+
+CONSTRUCTOR: options ( -- options ) ;
+
+TUPLE: resolv.conf nameserver domain lookup search sortlist options ;
+
+CONSTRUCTOR: resolv.conf ( -- resolv.conf )
+    V{ } clone >>nameserver
+    V{ } clone >>domain
+    V{ } clone >>search
+    V{ } clone >>sortlist
+    V{ } clone >>lookup
+    <options> >>options ;
+
+<PRIVATE
+
+: trim-blanks ( string -- string' ) [ blank? ] trim ;
+
+: split-line ( resolv.conf string -- resolv.conf seq resolv.conf )
+    trim-blanks " " split
+    [ trim-blanks ] map harvest over ;
+
+: parse-nameserver ( resolv.conf string -- resolv.conf )
+    split-line nameserver>> push-all ;
+
+: parse-domain ( resolv.conf string -- resolv.conf )
+    split-line domain>> push-all ;
+
+: parse-lookup ( resolv.conf string -- resolv.conf )
+    split-line lookup>> push-all ;
+
+: parse-search ( resolv.conf string -- resolv.conf )
+    split-line search>> push-all ;
+
+: parse-sortlist ( resolv.conf string -- resolv.conf )
+    trim-blanks " " split
+    [ trim-blanks "/" split1 <network> ] map >>sortlist ;
+
+ERROR: unsupported-resolv.conf-option string ;
+
+: parse-integer ( string -- n )
+    trim-blanks ":" ?head drop trim-blanks string>number ;
+
+: parse-option ( resolv.conf string -- resolv.conf )
+    [ dup options>> ] dip trim-blanks {
+        { [ "debug" ?head ] [ drop t >>debug? ] }
+        { [ "ndots:" ?head ] [ parse-integer >>ndots ] }
+        { [ "timeout" ?head ] [ parse-integer >>timeout ] }
+        { [ "attempts" ?head ] [ parse-integer >>attempts ] }
+        { [ "rotate" ?head ] [ drop t >>rotate? ] }
+        { [ "no-check-names" ?head ] [ drop t >>no-check-names? ] }
+        { [ "inet6" ?head ] [ drop t >>inet6? ] }
+        [ unsupported-resolv.conf-option ]
+    } cond drop ;
+
+ERROR: unsupported-resolv.conf-line string ;
+
+: parse-resolv.conf-line ( resolv.conf string -- resolv.conf )
+    {
+        { [ "nameserver" ?head ] [ parse-nameserver ] }
+        { [ "domain" ?head ] [ parse-domain ] }
+        { [ "lookup" ?head ] [ parse-lookup ] }
+        { [ "search" ?head ] [ parse-search ] }
+        { [ "sortlist" ?head ] [ parse-sortlist ] }
+        { [ "options" ?head ] [ parse-option ] }
+        [ unsupported-resolv.conf-line ]
+    } cond ;
+
+PRIVATE>
+
+: parse-resolve.conf ( path -- resolv.conf )
+    [ <resolv.conf> ] dip
+    utf8 file-lines
+    [ [ blank? ] trim ] map harvest
+    [ "#" head? not ] filter
+    [ parse-resolv.conf-line ] each ;
+
+: default-resolv.conf ( -- resolv.conf )
+    "/etc/resolv.conf" parse-resolve.conf ;
diff --git a/extra/resolv-conf/resolv-conf.test b/extra/resolv-conf/resolv-conf.test
new file mode 100644 (file)
index 0000000..1b17c3a
--- /dev/null
@@ -0,0 +1,28 @@
+#
+# Mac OS X Notice
+#
+# This file is not used by the host name and address resolution
+# or the DNS query routing mechanisms used by most processes on
+# this Mac OS X system.
+ #  
+ # This file is automatically generated.
+ #
+ nameserver  8.8.8.8 
+ domain  hmm.lol.com  
+ search  a.com  b.com  c.com 
+
+sortlist 130.155.160.0/255.255.240.0 130.155.0.0 131.155.160.0/255.255.240.0 130.155.0.1
+
+ options   debug
+ options   ndots:10  
+ options   timeout:11 
+ options   attempts : 12 
+ options   rotate
+ options   no-check-names
+ options   inet6 
+
+
+
+
+
+
index de160f5598ea3ddbb590489c834e098a0bac4c4f..acc1d7999f18b12f29dbaeef24667259bf684a86 100644 (file)
@@ -1,7 +1,8 @@
 ! Copyright (C) 2009 Bruno Deferrari
 ! See http://factorcode.org/license.txt for BSD license.
-USING: accessors alien.c-types arrays assocs destructors fry functors
-kernel locals sequences serialize tokyo.alien.tcutil tokyo.utils vectors ;
+USING: accessors alien.c-types alien.data arrays assocs
+destructors fry functors kernel locals sequences serialize
+tokyo.alien.tcutil tokyo.utils vectors ;
 IN: tokyo.assoc-functor
 
 FUNCTOR: define-tokyo-assoc-api ( T N -- )
@@ -28,14 +29,14 @@ INSTANCE: TYPE assoc
 M: TYPE dispose* [ DBDEL f ] change-handle drop ;
 
 M: TYPE at* ( key db -- value/f ? )
-    handle>> swap object>bytes dup length 0 <int>
+    handle>> swap object>bytes dup length 0 int <ref>
     DBGET [ [ memory>object ] [ tcfree ] bi t ] [ f f ] if* ;
 
 M: TYPE assoc-size ( db -- size ) handle>> DBRNUM ;
 
 : DBKEYS ( db -- keys )
     [ assoc-size <vector> ] [ handle>> ] bi
-    dup DBITERINIT drop 0 <int>
+    dup DBITERINIT drop 0 int <ref>
     [ 2dup DBITERNEXT dup ] [
         [ memory>object ] [ tcfree ] bi
         [ pick ] dip swap push
index 9b4819d3aa19cbdbcd22feca4b159bab12fdde1b..68efbdd2b4e40398f9b67b93fea4b523206b5903 100644 (file)
@@ -3,13 +3,13 @@
 USING: combinators kernel generic math math.functions
 math.parser namespaces io sequences trees shuffle
 assocs parser accessors math.order prettyprint.custom
-trees.private ;
+trees.private fry ;
 IN: trees.avl
 
 TUPLE: avl < tree ;
 
 : <avl> ( -- tree )
-    avl new-tree ;
+    avl new-tree ; inline
 
 <PRIVATE
 
@@ -17,15 +17,16 @@ TUPLE: avl-node < node balance ;
 
 : <avl-node> ( key value -- node )
     avl-node new-node
-        0 >>balance ;
+        0 >>balance ; inline
 
-: increase-balance ( node amount -- )
-    swap [ + ] change-balance drop ;
+: increase-balance ( node amount -- node )
+    '[ _ + ] change-balance ;
 
 : rotate ( node -- node )
-    dup node+link
-    dup node-link
-    pick set-node+link
+    dup
+    [ node+link ]
+    [ node-link ]
+    [ set-node+link ] tri
     [ set-node-link ] keep ;    
 
 : single-rotate ( node -- node )
@@ -36,8 +37,8 @@ TUPLE: avl-node < node balance ;
 : pick-balances ( a node -- balance balance )
     balance>> {
         { [ dup zero? ] [ 2drop 0 0 ] }
-        { [ over = ] [ neg 0 ] }
-        [ 0 swap ]
+        { [ 2dup = ] [ nip neg 0 ] }
+        [ drop 0 swap ]
     } cond ;
 
 : double-rotate ( node -- node )
@@ -57,9 +58,8 @@ TUPLE: avl-node < node balance ;
 : balance-insert ( node -- node taller? )
     dup balance>> {
         { [ dup zero? ] [ drop f ] }
-        { [ dup abs 2 = ]
-          [ sgn neg [ select-rotate ] with-side f ] }
-        { [ drop t ] [ t ] } ! balance is -1 or 1, tree is taller
+        { [ dup abs 2 = ] [ sgn neg [ select-rotate ] with-side f ] }
+        [ drop t ] ! balance is -1 or 1, tree is taller
     } cond ;
 
 DEFER: avl-set
@@ -68,7 +68,7 @@ DEFER: avl-set
     2dup key>> before? left right ? [
         [ node-link avl-set ] keep swap
         [ [ set-node-link ] keep ] dip
-        [ dup current-side get increase-balance balance-insert ]
+        [ current-side get increase-balance balance-insert ]
         [ f ] if
     ] with-side ;
 
@@ -95,14 +95,14 @@ M: avl set-at ( value key node -- node )
     dup balance>> {
         { [ dup zero? ] [ drop t ] }
         { [ dup abs 2 = ] [ sgn neg [ delete-select-rotate ] with-side ] }
-        { [ drop t ] [ f ] } ! balance is -1 or 1, tree is not shorter
+        [ drop f ] ! balance is -1 or 1, tree is not shorter
     } cond ;
 
 : balance-delete ( node -- node shorter? )
     current-side get over balance>> {
         { [ dup zero? ] [ drop neg over balance<< f ] }
-        { [ dupd = ] [ drop 0 >>balance t ] }
-        [ dupd neg increase-balance rebalance-delete ]
+        { [ 2dup = ] [ 2drop 0 >>balance t ] }
+        [ drop neg increase-balance rebalance-delete ]
     } cond ;
 
 : avl-replace-with-extremity ( to-replace node -- node shorter? )
@@ -155,7 +155,7 @@ M: avl new-assoc 2drop <avl> ;
 PRIVATE>
 
 : >avl ( assoc -- avl )
-    T{ avl f f 0 } assoc-clone-like ;
+    T{ avl } assoc-clone-like ;
 
 M: avl assoc-like
     drop dup avl? [ >avl ] unless ;
index d56e33823451a2de6a0a94085d6c0f66c9d0da99..76a8e39d8337be9623160b2dd2eac802ad9120bb 100644 (file)
@@ -5,7 +5,7 @@ prettyprint.private kernel.private assocs random combinators
 parser math.order accessors deques make prettyprint.custom ;
 IN: trees
 
-TUPLE: tree root count ;
+TUPLE: tree root { count integer } ;
 
 <PRIVATE
 
@@ -28,7 +28,7 @@ TUPLE: node key value left right ;
 : new-node ( key value class -- node )
     new
         swap >>value
-        swap >>key ;
+        swap >>key ; inline
 
 : <node> ( key value -- node )
     node new-node ;
index 9236cc9504db965ed715f64362ac143631e00632..81a676ec24589893cc5d26621a16d824733e5048 100644 (file)
@@ -2,7 +2,7 @@
 ! See http://factorcode.org/license.txt for BSD license.
 USING: accessors assocs combinators hashtables http
 http.client json.reader kernel macros namespaces sequences
-urls.secure fry oauth urls system ;
+io.sockets.secure fry oauth urls ;
 IN: twitter
 
 ! Configuration
@@ -20,9 +20,8 @@ twitter-source [ "factor" ] initialize
     ] with-scope ; inline
 
 : twitter-url ( string -- string' )
-    os windows?
-    "http://twitter.com/"
-    "https://twitter.com/" ? prepend ;
+    ssl-supported?
+    "https://twitter.com/" "http://twitter.com/" ? prepend ;
 
 PRIVATE>
 
index 217e6b8a1a0935761e7cd0e18b5fdf0dc3111582..bb77dd81437a049792b3a2af3f7eb3be5968b0ff 100644 (file)
@@ -1,7 +1,8 @@
 ! Copyright (C) 2010 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
 USING: accessors calendar db db.sqlite db.tuples db.types kernel
-math math.order sequences combinators.short-circuit ;
+math math.order sequences combinators.short-circuit
+io.pathnames ;
 IN: webapps.mason.backend
 
 CONSTANT: +idle+ "idle"
@@ -72,7 +73,7 @@ counter "COUNTER" {
 : os/cpu ( builder -- string )
     [ os>> ] [ cpu>> ] bi "/" glue ;
 
-: mason-db ( -- db ) "resource:mason.db" <sqlite-db> ;
+: mason-db ( -- db ) home "mason.db" append-path <sqlite-db> ;
 
 : with-mason-db ( quot -- )
     mason-db [ with-transaction ] with-db ; inline
index 7b685890e75167debee4c0db27d7f740e2bec80f..2df1f9ee8395e2374bc48800a011fd3632f64fae 100644 (file)
@@ -1,15 +1,20 @@
 ! Copyright (C) 2010 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: accessors continuations furnace.actions help.html
+USING: accessors furnace.actions help.html
 http.server.responses io.directories io.directories.hierarchy
-io.launcher io.files io.pathnames kernel memoize threads
-webapps.mason.utils ;
+io.files io.launcher io.pathnames kernel mason.config memoize
+namespaces sequences threads webapps.mason.utils ;
 IN: webapps.mason.docs-update
 
+: docs-path ( -- path )
+    docs-directory get "docs.tar.gz" append-path ;
+
 : update-docs ( -- )
     home [
+        "newdocs" exists? [ "newdocs" delete-tree ] when
+
         "newdocs" make-directory
-        "newdocs" [ { "tar" "xfz" "../docs.tar.gz" } try-process ] with-directory
+        "newdocs" [ { "tar" "xfz" } docs-path suffix try-process ] with-directory
 
         "docs" exists? [ "docs" "docs.old" move-file ] when
         "newdocs/docs" "docs" move-file
index ff366fb4f49861ca194c959f57a499abc8168f5f..1d56d3e3cbe8264cf42c51747617e1c637531c78 100644 (file)
@@ -7,7 +7,7 @@
 
        <t:title>Factor binary package for <t:label t:name="platform" /></t:title>
 
-       <div><img src="http://factorcode.org/graphics/logo.png" alt="Logo" /></div>
+       <div><img src="http://factorcode.org/logo.png" alt="Logo" /></div>
 
        <h1>Factor binary package for <t:label t:name="platform" /></h1>
 
index ffb485e1730fad8dc598cfb237ef0fe188800771..a1d4766206e3d967d72b88c03d838b04cddabf5a 100644 (file)
@@ -7,7 +7,7 @@
 
        <t:title>Factor binary package for <t:label t:name="platform" /></t:title>
 
-       <div><img src="http://factorcode.org/graphics/logo.png" alt="Logo" /></div>
+       <div><img src="http://factorcode.org/logo.png" alt="Logo" /></div>
 
        <h1>Factor binary package for <t:label t:name="platform" /></h1>
 
index 224c586f2f3a8da51f2086e12c9a8d8d6bab357c..b8409b01231ab86ad5589b22bed99955a1ed3da2 100644 (file)
@@ -44,7 +44,7 @@ IN: webapps.mason.package
     packages-url dup link ;
 
 : clean-image-url ( builder -- url )
-    platform "http://factorcode.org/images/clean/" prepend ;
+    platform "http://downloads.factorcode.org/images/clean/" prepend ;
 
 : clean-image-link ( builder -- link )
     clean-image-url dup link ;
diff --git a/extra/webapps/planet/icons/feed-icon-14x14.png b/extra/webapps/planet/icons/feed-icon-14x14.png
new file mode 100644 (file)
index 0000000..b3c949d
Binary files /dev/null and b/extra/webapps/planet/icons/feed-icon-14x14.png differ
index a2beb513ab2b54900bb5c259a563a186bcacb87f..cf48f6dfbcf48509f29a05ebb447e2da0d94ee66 100644 (file)
@@ -8,6 +8,7 @@ html.forms
 html.components
 http.server
 http.server.dispatchers
+http.server.static
 furnace
 furnace.actions
 furnace.redirection
@@ -190,6 +191,7 @@ posting "POSTINGS"
         <planet-action> "" add-responder
         <planet-feed-action> "feed.xml" add-responder
         <planet-admin> "admin" add-responder
+        "vocab:webapps/planet/icons/" <static> "icons" add-responder
     <boilerplate>
         { planet "planet-common" } >>template ;
 
index 08cf07d4ceca4cc52f13776f5f1c670f259d6d51..c7c124d23cc99a626e5cea3762678f0fabc7721c 100644 (file)
@@ -48,7 +48,7 @@
                                    <a href="http://planet.lisp.org">Planet Lisp</a>.
                                </p>
                                <p>
-                                   <img src="http://factorcode.org/feed-icon-14x14.png" />
+                                   <img src="http://planet.factorcode.org/icons/feed-icon-14x14.png" />
                                    <t:a t:href="$planet/feed.xml">Syndicate</t:a>
                                </p>
                        </td>
index 379ba32a576a0948d6a6a725dd24cd932cf8262a..b91d58f43390a0bf22c9007042e5032ad41cb040 100644 (file)
@@ -3,7 +3,7 @@
 USING: accessors kernel sequences assocs io.files io.pathnames
 io.sockets io.sockets.secure io.servers
 namespaces db db.tuples db.sqlite smtp urls
-logging.insomniac
+logging.insomniac calendar timers
 html.templates.chloe
 http.server
 http.server.dispatchers
@@ -27,15 +27,16 @@ webapps.user-admin
 webapps.help
 webapps.mason
 webapps.mason.backend
+webapps.mason.backend.watchdog
 websites.factorcode ;
 IN: websites.concatenative
 
-: test-db ( -- db ) "resource:test.db" <sqlite-db> ;
+: website-db ( -- db ) home "website.db" append-path <sqlite-db> ;
 
 : init-factor-db ( -- )
     mason-db [ init-mason-db ] with-db
 
-    test-db [
+    website-db [
         init-furnace-tables
 
         {
@@ -59,25 +60,22 @@ TUPLE: concatenative-website < dispatcher ;
         allow-edit-profile
         allow-deactivation ;
 
+SYMBOLS: factor-recaptcha-public-key factor-recaptcha-private-key ;
+
 : <factor-recaptcha> ( responder -- responder' )
     <recaptcha>
         "concatenative.org" >>domain
-        "6LeJWQgAAAAAAFlYV7SuBClE9uSpGtV_ZS-qVON7" >>public-key
-        "6LeJWQgAAAAAALh-XJgSSQ6xKygRgJ8-029Ip2Xv" >>private-key ;
+        factor-recaptcha-public-key get >>public-key
+        factor-recaptcha-private-key get >>private-key ;
 
 : <concatenative-website> ( -- responder )
     concatenative-website new-dispatcher
         URL" /wiki/view/Front Page" <redirect-responder> "" add-responder ;
 
-SYMBOL: key-password
-SYMBOL: key-file
-SYMBOL: dh-file
+SYMBOLS: key-password key-file dh-file ;
 
 : common-configuration ( -- )
-    "concatenative.org" 25 <inet> smtp-server set-global
     "noreply@concatenative.org" lost-password-from set-global
-    "website@concatenative.org" insomniac-sender set-global
-    { "slava@factorcode.org" } insomniac-recipients set-global
     init-factor-db ;
 
 : init-testing ( -- )
@@ -92,7 +90,7 @@ SYMBOL: dh-file
         <planet> <login-config> <factor-boilerplate> "planet" add-responder
         <mason-app> <login-config> <factor-boilerplate> "mason" add-responder
         "/tmp/docs/" <help-webapp> "docs" add-responder
-    test-db <alloy>
+    website-db <alloy>
     main-responder set-global ;
 
 : <gitweb> ( path -- responder )
@@ -106,13 +104,12 @@ SYMBOL: dh-file
         <concatenative-website>
             <wiki> "wiki" add-responder
             <user-admin> "user-admin" add-responder
-        <login-config> <factor-boilerplate> test-db <alloy> "concatenative.org" add-responder
-        <pastebin> <factor-recaptcha> <login-config> <factor-boilerplate> test-db <alloy> "paste.factorcode.org" add-responder
-        <planet> <login-config> <factor-boilerplate> test-db <alloy> "planet.factorcode.org" add-responder
-        <mason-app> <login-config> <factor-boilerplate> test-db <alloy> "builds.factorcode.org" add-responder
+        <login-config> <factor-boilerplate> website-db <alloy> "concatenative.org" add-responder
+        <pastebin> <factor-recaptcha> <login-config> <factor-boilerplate> website-db <alloy> "paste.factorcode.org" add-responder
+        <planet> <login-config> <factor-boilerplate> website-db <alloy> "planet.factorcode.org" add-responder
+        <mason-app> <login-config> <factor-boilerplate> website-db <alloy> "builds.factorcode.org" add-responder
         home "docs" append-path <help-webapp> "docs.factorcode.org" add-responder
         home "cgi" append-path <gitweb> "gitweb.factorcode.org" add-responder
-        <factor-website> "new.factorcode.org" add-responder
     main-responder set-global ;
 
 : <factor-secure-config> ( -- config )
@@ -127,8 +124,12 @@ SYMBOL: dh-file
         8080 >>insecure
         8431 >>secure ;
 
+: start-watchdog ( -- )
+    [ check-builders ] 6 hours every drop ;
+
 : start-website ( -- server )
-    test-db start-expiring
-    test-db start-update-task
+    website-db start-expiring
+    website-db start-update-task
     http-insomniac
+    start-watchdog
     <concatenative-website-server> start-server ;
diff --git a/extra/websites/factorcode/factor-macosx.png b/extra/websites/factorcode/factor-macosx.png
new file mode 100644 (file)
index 0000000..06e44ec
Binary files /dev/null and b/extra/websites/factorcode/factor-macosx.png differ
diff --git a/extra/websites/factorcode/factor-windows7.png b/extra/websites/factorcode/factor-windows7.png
new file mode 100644 (file)
index 0000000..aa6f178
Binary files /dev/null and b/extra/websites/factorcode/factor-windows7.png differ
index 36450509b3d01f73d34b955db9ae9ba490c3206d..d4abba7988ccacd3c24bad23facf3b1820b3caa0 100644 (file)
@@ -4,14 +4,9 @@ USING: accessors http.server http.server.dispatchers
 http.server.static kernel namespaces sequences ;
 IN: websites.factorcode
 
-SYMBOL: users
-
 : <factor-website> ( -- website )
     <dispatcher>
-        "resource:extra/websites/factorcode/" <static> enable-fhtml >>default
-        users get [
-            [ "/home/" "/www/" surround <static> ] keep add-responder
-        ] each ;
+        "resource:extra/websites/factorcode/" <static> enable-fhtml >>default ;
 
 : init-testing ( -- )
     <factor-website> main-responder set-global ;
diff --git a/extra/websites/factorcode/license.txt b/extra/websites/factorcode/license.txt
new file mode 100644 (file)
index 0000000..e9cd58a
--- /dev/null
@@ -0,0 +1,20 @@
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+
+1. Redistributions of source code must retain the above copyright notice,
+   this list of conditions and the following disclaimer.
+
+2. Redistributions in binary form must reproduce the above copyright notice,
+   this list of conditions and the following disclaimer in the documentation
+   and/or other materials provided with the distribution.
+
+THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
+INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+DEVELOPERS AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
old mode 100644 (file)
new mode 100755 (executable)
index 1886ee7..1ae91b1
@@ -5,6 +5,7 @@ SHARED_DLL_EXTENSION=.dll
 
 LIBS = -lm
 
+PLAF_DLL_OBJS += vm/os-windows.o vm/mvm-windows.o
 PLAF_EXE_OBJS += vm/resources.o vm/main-windows.o
 
 EXE_SUFFIX=
index 47896340cd8ce45dfaa686d5b9a1f4eeadb2e0b4..adcfa6f4da4655943615233b5da092bb350d7b20 100755 (executable)
@@ -381,25 +381,11 @@ FOO_TO_BIGNUM(ulong_long,u64,s64,u64)
                }                                                       \
        }
 
-BIGNUM_TO_FOO(cell,cell,fixnum,cell);
-BIGNUM_TO_FOO(fixnum,fixnum,fixnum,cell);
+BIGNUM_TO_FOO(cell,cell,fixnum,cell)
+BIGNUM_TO_FOO(fixnum,fixnum,fixnum,cell)
 BIGNUM_TO_FOO(long_long,s64,s64,u64)
 BIGNUM_TO_FOO(ulong_long,u64,s64,u64)
 
-double factor_vm::bignum_to_double(bignum * bignum)
-{
-       if (BIGNUM_ZERO_P (bignum))
-               return (0);
-       {
-               double accumulator = 0;
-               bignum_digit_type * start = (BIGNUM_START_PTR (bignum));
-               bignum_digit_type * scan = (start + (BIGNUM_LENGTH (bignum)));
-               while (start < scan)
-                       accumulator = ((accumulator * BIGNUM_RADIX) + (*--scan));
-               return ((BIGNUM_NEGATIVE_P (bignum)) ? (-accumulator) : accumulator);
-       }
-}
-
 #define DTB_WRITE_DIGIT(factor)                                                \
 {                                                                      \
        significand *= (factor);                                        \
index 0de3dac91f6d480c3d1d56eae3186b6e5afcccfd..1bb339a70ab7bd9c949db886d1685d3d789c2738 100755 (executable)
--- a/vm/gc.cpp
+++ b/vm/gc.cpp
@@ -230,8 +230,8 @@ struct call_frame_scrubber {
                gc_info *info = compiled->block_gc_info();
 
                assert(return_address < compiled->size());
-               int index = info->return_address_index(return_address);
-               if(index != -1)
+               cell index = info->return_address_index(return_address);
+               if(index != (cell)-1)
                        ctx->scrub_stacks(info,index);
        }
 };
index 7c727aac0d0b863a49ebb0c32091667e72f1e387..a693fc54557f39a373edb008c827e66a907bcb1b 100644 (file)
@@ -13,7 +13,7 @@ cell gc_info::return_address_index(cell return_address)
                        return i;
        }
 
-       return gc_info_missing_value;
+       return (cell)-1;
 }
 
 }
index eee7b1a8e8b427fa69602cd8e847469fb737b831..9bff88b9b2882b67da956d3a983d975233a6886e 100644 (file)
@@ -1,8 +1,6 @@
 namespace factor
 {
 
-const u32 gc_info_missing_value = (u32)-1;
-
 struct gc_info {
        u32 scrub_d_count;
        u32 scrub_r_count;
@@ -58,7 +56,7 @@ struct gc_info {
                        + index * gc_root_count;
        }
 
-       cell lookup_base_pointer(cell index, cell derived_root)
+       u32 lookup_base_pointer(cell index, cell derived_root)
        {
                return base_pointer_map()[index * derived_root_count + derived_root];
        }
index 67cab3570dc756378a7a0a122c23ce692e32dc9a..4bc918ad66ab29d81fe82a2cacbba08f57050d82 100755 (executable)
@@ -255,11 +255,6 @@ void factor_vm::primitive_fixnum_to_float()
        ctx->replace(allot_float(fixnum_to_float(ctx->peek())));
 }
 
-void factor_vm::primitive_bignum_to_float()
-{
-       ctx->replace(allot_float(bignum_to_float(ctx->peek())));
-}
-
 void factor_vm::primitive_format_float()
 {
        byte_array *array = allot_byte_array(100);
index ffe60dced5f0f0e0c04e198dedea7588d1a10ff0..62c007be8df605cf522ab14a65804e4ad3319fe0 100644 (file)
@@ -33,11 +33,6 @@ inline bignum *factor_vm::float_to_bignum(cell tagged)
        return double_to_bignum(untag_float(tagged));
 }
 
-inline double factor_vm::bignum_to_float(cell tagged)
-{
-       return bignum_to_double(untag<bignum>(tagged));
-}
-
 inline double factor_vm::untag_float(cell tagged)
 {
        return untag<boxed_float>(tagged)->n;
index ce40ca0a7e97de642cf8a94f96663e49d4a5f6a7..573f91b072ba71757170727a5fb94bb554eaff5b 100644 (file)
@@ -27,7 +27,6 @@ namespace factor
        _(bignum_shift) \
        _(bignum_subtract) \
        _(bignum_to_fixnum) \
-       _(bignum_to_float) \
        _(bignum_xor) \
        _(bits_double) \
        _(bits_float) \
index 303fc37544512e9f3fa242399d3678fb2d27fad3..b2dd40e58230c64456fc275fc8c8fbf1a649d0a0 100755 (executable)
@@ -292,8 +292,8 @@ struct call_frame_slot_visitor {
                gc_info *info = compiled->block_gc_info();
 
                assert(return_address < compiled->size());
-               u32 callsite = info->return_address_index(return_address);
-               if(callsite == gc_info_missing_value)
+               cell callsite = info->return_address_index(return_address);
+               if(callsite == (cell)-1)
                        return;
 
 #ifdef DEBUG_GC_MAPS
@@ -305,8 +305,8 @@ struct call_frame_slot_visitor {
                /* Subtract old value of base pointer from every derived pointer. */
                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)
+                       u32 base_pointer = info->lookup_base_pointer(callsite, spill_slot);
+                       if(base_pointer != (u32)-1)
                        {
 #ifdef DEBUG_GC_MAPS
                                std::cout << "visiting derived root " << spill_slot
@@ -334,8 +334,8 @@ struct call_frame_slot_visitor {
                /* 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)
+                       u32 base_pointer = info->lookup_base_pointer(callsite, spill_slot);
+                       if(base_pointer != (u32)-1)
                                stack_pointer[spill_slot] += stack_pointer[base_pointer];
                }
        }
index f940bd593734bf6167c30f0e4f14e8589e80c803..38eb5033d77060239706363b600a83e34db4a581 100755 (executable)
--- a/vm/vm.hpp
+++ b/vm/vm.hpp
@@ -192,7 +192,6 @@ struct factor_vm
        fixnum bignum_to_fixnum(bignum * bignum);
        s64 bignum_to_long_long(bignum * bignum);
        u64 bignum_to_ulong_long(bignum * bignum);
-       double bignum_to_double(bignum * bignum);
        bignum *double_to_bignum(double x);
        int bignum_equal_p_unsigned(bignum * x, bignum * y);
        enum bignum_comparison bignum_compare_unsigned(bignum * x, bignum * y);
@@ -457,7 +456,6 @@ struct factor_vm
        inline cell unbox_array_size();
        cell unbox_array_size_slow();
        void primitive_fixnum_to_float();
-       void primitive_bignum_to_float();
        void primitive_format_float();
        void primitive_float_eq();
        void primitive_float_add();
@@ -487,7 +485,6 @@ struct factor_vm
        inline cell from_unsigned_cell(cell x);
        inline cell allot_float(double n);
        inline bignum *float_to_bignum(cell tagged);
-       inline double bignum_to_float(cell tagged);
        inline double untag_float(cell tagged);
        inline double untag_float_check(cell tagged);
        inline fixnum float_to_fixnum(cell tagged);