]> gitweb.factorcode.org Git - factor.git/commitdiff
Merge branch 'master' of git://factorcode.org/git/factor into experimental
authorAlex Chapman <chapman.alex@gmail.com>
Sun, 16 Mar 2008 01:41:43 +0000 (12:41 +1100)
committerAlex Chapman <chapman.alex@gmail.com>
Sun, 16 Mar 2008 01:41:43 +0000 (12:41 +1100)
165 files changed:
Makefile
core/bootstrap/primitives.factor
core/classes/classes-docs.factor
core/classes/classes-tests.factor
core/classes/classes.factor
core/compiler/errors/errors-docs.factor
core/continuations/continuations-docs.factor
core/io/files/files-docs.factor
core/io/files/files-tests.factor
core/io/files/files.factor
core/kernel/kernel-docs.factor
core/parser/parser-tests.factor
core/parser/parser.factor
core/source-files/source-files-docs.factor
core/source-files/source-files.factor
core/vocabs/loader/loader-docs.factor
core/vocabs/loader/loader-tests.factor
core/vocabs/loader/loader.factor
extra/assocs/lib/lib.factor
extra/benchmark/benchmark.factor
extra/benchmark/fasta/fasta.factor [changed mode: 0644->0755]
extra/bootstrap/tools/tools.factor
extra/builder/benchmark/benchmark.factor
extra/builder/builder.factor [changed mode: 0755->0644]
extra/builder/test/test.factor
extra/bunny/deploy.factor
extra/bunny/outlined/outlined.factor [changed mode: 0644->0755]
extra/cairo-demo/cairo-demo.factor
extra/cairo/authors.txt
extra/cairo/cairo.factor [deleted file]
extra/cairo/ffi/ffi.factor [new file with mode: 0644]
extra/cairo/lib/lib.factor [new file with mode: 0644]
extra/cairo/png/png.factor [new file with mode: 0644]
extra/combinators/cleave/cleave-docs.factor
extra/combinators/cleave/cleave.factor
extra/combinators/lib/lib.factor
extra/db/db-tests.factor [new file with mode: 0755]
extra/db/postgresql/postgresql.factor
extra/db/sqlite/ffi/ffi.factor
extra/db/sqlite/lib/lib.factor
extra/db/sqlite/sqlite.factor
extra/db/tuples/tuples-tests.factor
extra/db/tuples/tuples.factor
extra/destructors/destructors.factor
extra/editors/editors.factor
extra/hello-world/deploy.factor
extra/help/cookbook/cookbook.factor
extra/help/handbook/handbook.factor
extra/help/lint/lint.factor [changed mode: 0644->0755]
extra/help/markup/markup.factor
extra/help/topics/topics.factor [changed mode: 0644->0755]
extra/help/tutorial/tutorial.factor
extra/http/client/client-tests.factor
extra/http/client/client.factor
extra/http/http.factor
extra/http/server/actions/actions-tests.factor
extra/http/server/actions/actions.factor
extra/http/server/auth/login/edit-profile.fhtml [new file with mode: 0755]
extra/http/server/auth/login/login.factor
extra/http/server/auth/login/login.fhtml
extra/http/server/auth/login/recover-1.fhtml
extra/http/server/auth/login/recover-3.fhtml
extra/http/server/auth/login/recover-4.fhtml
extra/http/server/auth/login/register.fhtml
extra/http/server/auth/providers/assoc/assoc-tests.factor
extra/http/server/auth/providers/assoc/assoc.factor
extra/http/server/auth/providers/db/db-tests.factor
extra/http/server/auth/providers/db/db.factor
extra/http/server/auth/providers/null/null.factor
extra/http/server/auth/providers/providers.factor
extra/http/server/callbacks/callbacks.factor
extra/http/server/components/components-tests.factor
extra/http/server/components/components.factor
extra/http/server/server.factor
extra/http/server/sessions/sessions-tests.factor
extra/http/server/sessions/sessions.factor
extra/http/server/sessions/storage/assoc/assoc.factor [new file with mode: 0755]
extra/http/server/sessions/storage/db/db-tests.factor [new file with mode: 0755]
extra/http/server/sessions/storage/db/db.factor [new file with mode: 0755]
extra/http/server/sessions/storage/storage.factor [new file with mode: 0755]
extra/http/server/static/static.factor
extra/http/server/validators/validators-tests.factor
extra/http/server/validators/validators.factor
extra/io/encodings/ascii/ascii-tests.factor [new file with mode: 0644]
extra/io/encodings/ascii/ascii.factor
extra/io/encodings/latin1/latin1-tests.factor [new file with mode: 0644]
extra/io/encodings/latin1/latin1.factor
extra/io/mmap/mmap-tests.factor [changed mode: 0644->0755]
extra/io/unix/files/files.factor
extra/io/unix/freebsd/freebsd.factor
extra/io/unix/unix.factor
extra/io/windows/files/files.factor [changed mode: 0644->0755]
extra/io/windows/launcher/launcher.factor
extra/io/windows/nt/nt.factor
extra/io/windows/windows.factor
extra/jamshred/jamshred.factor [changed mode: 0644->0755]
extra/ldap/libldap/libldap.factor
extra/locals/locals.factor
extra/logging/server/server.factor
extra/math/matrices/matrices.factor [changed mode: 0644->0755]
extra/namespaces/lib/lib-tests.factor [new file with mode: 0755]
extra/namespaces/lib/lib.factor [changed mode: 0644->0755]
extra/opengl/demo-support/demo-support.factor [changed mode: 0644->0755]
extra/opengl/gl/gl-docs.factor [new file with mode: 0644]
extra/opengl/opengl-docs.factor
extra/opengl/opengl.factor
extra/opengl/shaders/shaders.factor [changed mode: 0644->0755]
extra/openssl/libcrypto/libcrypto.factor
extra/openssl/libssl/libssl.factor
extra/pack/pack.factor
extra/pdf/authors.txt [deleted file]
extra/pdf/libhpdf/libhpdf.factor [deleted file]
extra/pdf/pdf-tests.factor [deleted file]
extra/pdf/pdf.factor [deleted file]
extra/pdf/readme.txt [deleted file]
extra/sequences/lib/lib-tests.factor
extra/sequences/lib/lib.factor
extra/sudoku/deploy.factor
extra/symbols/symbols-tests.factor [changed mode: 0644->0755]
extra/symbols/symbols.factor [changed mode: 0644->0755]
extra/tools/browser/authors.txt [deleted file]
extra/tools/browser/browser-docs.factor [deleted file]
extra/tools/browser/browser-tests.factor [deleted file]
extra/tools/browser/browser.factor [deleted file]
extra/tools/browser/tags.txt [deleted file]
extra/tools/deploy/backend/backend.factor
extra/tools/deploy/config/config.factor
extra/tools/deploy/deploy-tests.factor
extra/tools/deploy/shaker/shaker.factor
extra/tools/deploy/test/1/1.factor [new file with mode: 0755]
extra/tools/deploy/test/1/deploy.factor [new file with mode: 0755]
extra/tools/deploy/test/2/2.factor [new file with mode: 0755]
extra/tools/deploy/test/2/deploy.factor [new file with mode: 0755]
extra/tools/deploy/test/3/3.factor [new file with mode: 0755]
extra/tools/deploy/test/3/deploy.factor [new file with mode: 0755]
extra/tools/disassembler/disassembler-tests.factor [new file with mode: 0755]
extra/tools/disassembler/disassembler.factor
extra/tools/test/test.factor
extra/tools/vocabs/browser/authors.txt [new file with mode: 0755]
extra/tools/vocabs/browser/browser-docs.factor [new file with mode: 0755]
extra/tools/vocabs/browser/browser-tests.factor [new file with mode: 0755]
extra/tools/vocabs/browser/browser.factor [new file with mode: 0755]
extra/tools/vocabs/browser/tags.txt [new file with mode: 0644]
extra/tools/vocabs/monitor/authors.txt [new file with mode: 0644]
extra/tools/vocabs/monitor/monitor.factor [new file with mode: 0755]
extra/tools/vocabs/monitor/summary.txt [new file with mode: 0644]
extra/tools/vocabs/vocabs-docs.factor [new file with mode: 0755]
extra/tools/vocabs/vocabs.factor [new file with mode: 0755]
extra/ui/freetype/freetype.factor
extra/ui/render/render-docs.factor
extra/ui/tools/operations/operations.factor
extra/ui/tools/search/search.factor
extra/ui/tools/tools.factor
extra/ui/windows/windows.factor
extra/unix/types/freebsd/freebsd.factor [changed mode: 0644->0755]
extra/vocabs/monitor/authors.txt [deleted file]
extra/vocabs/monitor/monitor.factor [deleted file]
extra/vocabs/monitor/summary.txt [deleted file]
misc/factor.el
misc/target
unmaintained/pdf/authors.txt [new file with mode: 0644]
unmaintained/pdf/libhpdf/libhpdf.factor [new file with mode: 0644]
unmaintained/pdf/pdf-tests.factor [new file with mode: 0755]
unmaintained/pdf/pdf.factor [new file with mode: 0644]
unmaintained/pdf/readme.txt [new file with mode: 0644]

index 6f126338719bd43e10357b27359a85c7f7d3ad8a..054d57b641bd89c6892e8c30500dc997f3bed4fc 100755 (executable)
--- a/Makefile
+++ b/Makefile
@@ -46,10 +46,10 @@ DLL_OBJS = $(PLAF_DLL_OBJS) \
 EXE_OBJS = $(PLAF_EXE_OBJS)
 
 default: misc/wordsize
-       make `./misc/target`
+       $(MAKE) `./misc/target`
 
 help:
-       @echo "Run 'make' with one of the following parameters:"
+       @echo "Run '$(MAKE)' with one of the following parameters:"
        @echo ""
        @echo "freebsd-x86-32"
        @echo "freebsd-x86-64"
index aeb5ec1d829f7d634cb6412543ef6b90549ed146..52067b888cbebd82640e1dc532891452bc8d7845 100755 (executable)
@@ -98,26 +98,36 @@ H{ } clone class<map set
 H{ } clone update-map set
 
 ! Builtin classes
-: builtin-predicate ( class predicate -- )
+: builtin-predicate-quot ( class -- quot )
     [
-        over "type" word-prop dup
+        "type" word-prop dup
         \ tag-mask get < \ tag \ type ? , , \ eq? ,
-    ] [ ] make define-predicate* ;
+    ] [ ] make ;
 
-: register-builtin ( class -- )
-    dup "type" word-prop builtins get set-nth ;
+: define-builtin-predicate ( class -- )
+    dup
+    dup builtin-predicate-quot define-predicate
+    predicate-word make-inline ;
 
 : lookup-type-number ( word -- n )
     global [ target-word ] bind type-number ;
 
-: define-builtin ( symbol predicate slotspec -- )
-    >r dup make-inline >r
-    dup dup lookup-type-number "type" set-word-prop
+: register-builtin ( class -- )
+    dup
+    dup lookup-type-number "type" set-word-prop
+    dup "type" word-prop builtins get set-nth ;
+
+: define-builtin-slots ( symbol slotspec -- )
+    dupd 1 simple-slots
+    2dup "slots" set-word-prop
+    define-slots ;
+
+: define-builtin ( symbol slotspec -- )
+    >r
+    dup register-builtin
     dup f f builtin-class define-class
-    dup r> builtin-predicate
-    dup r> 1 simple-slots 2dup "slots" set-word-prop
-    dupd define-slots
-    register-builtin ;
+    dup define-builtin-predicate
+    r> define-builtin-slots ;
 
 H{ } clone typemap set
 num-types get f <array> builtins set
@@ -128,17 +138,15 @@ num-types get f <array> builtins set
 
 "null" "kernel" create drop
 
-"fixnum" "math" create "fixnum?" "math" create { } define-builtin
+"fixnum" "math" create { } define-builtin
 "fixnum" "math" create ">fixnum" "math" create 1quotation "coercer" set-word-prop
 
-"bignum" "math" create "bignum?" "math" create { } define-builtin
+"bignum" "math" create { } define-builtin
 "bignum" "math" create ">bignum" "math" create 1quotation "coercer" set-word-prop
 
-"tuple" "kernel" create "tuple?" "kernel" create
-{ } define-builtin
+"tuple" "kernel" create { } define-builtin
 
-"ratio" "math" create "ratio?" "math" create
-{
+"ratio" "math" create {
     {
         { "integer" "math" }
         "numerator"
@@ -153,11 +161,10 @@ num-types get f <array> builtins set
     }
 } define-builtin
 
-"float" "math" create "float?" "math" create { } define-builtin
+"float" "math" create { } define-builtin
 "float" "math" create ">float" "math" create 1quotation "coercer" set-word-prop
 
-"complex" "math" create "complex?" "math" create
-{
+"complex" "math" create {
     {
         { "real" "math" }
         "real-part"
@@ -172,14 +179,13 @@ num-types get f <array> builtins set
     }
 } define-builtin
 
-"f" "syntax" lookup "not" "kernel" create
-{ } define-builtin
+"f" "syntax" lookup { } define-builtin
 
-"array" "arrays" create "array?" "arrays" create
-{ } define-builtin
+! do not word...
 
-"wrapper" "kernel" create "wrapper?" "kernel" create
-{
+"array" "arrays" create { } define-builtin
+
+"wrapper" "kernel" create {
     {
         { "object" "kernel" }
         "wrapped"
@@ -188,8 +194,7 @@ num-types get f <array> builtins set
     }
 } define-builtin
 
-"string" "strings" create "string?" "strings" create
-{
+"string" "strings" create {
     {
         { "array-capacity" "sequences.private" }
         "length"
@@ -203,8 +208,7 @@ num-types get f <array> builtins set
     }
 } define-builtin
 
-"quotation" "quotations" create "quotation?" "quotations" create
-{
+"quotation" "quotations" create {
     {
         { "object" "kernel" }
         "array"
@@ -219,8 +223,7 @@ num-types get f <array> builtins set
     }
 } define-builtin
 
-"dll" "alien" create "dll?" "alien" create
-{
+"dll" "alien" create {
     {
         { "byte-array" "byte-arrays" }
         "path"
@@ -230,8 +233,7 @@ num-types get f <array> builtins set
 }
 define-builtin
 
-"alien" "alien" create "alien?" "alien" create
-{
+"alien" "alien" create {
     {
         { "c-ptr" "alien" }
         "alien"
@@ -246,8 +248,7 @@ define-builtin
 }
 define-builtin
 
-"word" "words" create "word?" "words" create
-{
+"word" "words" create {
     f
     {
         { "object" "kernel" }
@@ -287,26 +288,25 @@ define-builtin
     }
 } define-builtin
 
-"byte-array" "byte-arrays" create
-"byte-array?" "byte-arrays" create
-{ } define-builtin
+"byte-array" "byte-arrays" create { } define-builtin
 
-"bit-array" "bit-arrays" create
-"bit-array?" "bit-arrays" create
-{ } define-builtin
+"bit-array" "bit-arrays" create { } define-builtin
 
-"float-array" "float-arrays" create
-"float-array?" "float-arrays" create
-{ } define-builtin
+"float-array" "float-arrays" create { } define-builtin
 
-"callstack" "kernel" create "callstack?" "kernel" create
-{ } define-builtin
+"callstack" "kernel" create { } define-builtin
 
 ! Define general-t type, which is any object that is not f.
 "general-t" "kernel" create
 "f" "syntax" lookup builtins get remove [ ] subset f union-class
 define-class
 
+"f" "syntax" create [ not ] "predicate" set-word-prop
+"f?" "syntax" create "syntax" vocab-words delete-at
+
+"general-t" "kernel" create [ ] "predicate" set-word-prop
+"general-t?" "kernel" create "syntax" vocab-words delete-at
+
 ! Catch-all class for providing a default method.
 "object" "kernel" create [ drop t ] "predicate" set-word-prop
 "object" "kernel" create
index df97a3eff5b64b6c583f9d908c160ff6184903e0..1e711731537fe630ba760b7f76cd707cbbdecb74 100755 (executable)
@@ -1,7 +1,7 @@
 USING: help.markup help.syntax kernel kernel.private
 namespaces sequences words arrays layouts help effects math
 layouts classes.private classes.union classes.mixin
-classes.predicate ;
+classes.predicate quotations ;
 IN: classes
 
 ARTICLE: "builtin-classes" "Built-in classes"
@@ -114,24 +114,9 @@ HELP: predicate-word
 { $values { "word" "a word" } { "predicate" "a predicate word" } }
 { $description "Suffixes the word's name with \"?\" and creates a word with that name in the same vocabulary as the word itself." } ;
 
-HELP: define-predicate*
-{ $values { "class" class } { "predicate" "a predicate word" } { "quot" "a quotation" } }
-{ $description
-    "Defines a predicate word. This is identical to a word definition associating " { $snippet "quot" } " with " { $snippet "predicate" } " with the added perk that three word properties are set:"
-    { $list
-        { "the class word's " { $snippet "\"predicate\"" } " property is set to a quotation that calls the predicate" }
-        { "the predicate word's " { $snippet "\"predicating\"" } " property is set to the class word" }
-        { "the predicate word's " { $snippet "\"declared-effect\"" } " word property is set to a descriptive " { $link effect } }
-    }
-    "These properties are used by method dispatch and the help system."
-}
-$low-level-note ;
-
 HELP: define-predicate
-{ $values { "class" class } { "quot" "a quotation" } }
-{ $description
-    "Defines a predicate word named " { $snippet "class?" } " with " { $link define-predicate* } "."
-}
+{ $values { "class" class } { "quot" quotation } }
+{ $description "Defines a predicate word for a class." }
 $low-level-note ;
 
 HELP: superclass
index 640439312d3d31d90ef5c113f589e1814c47aaa5..dbc1bcace2484dba972d35d9eb7e03a4c6b147ee 100755 (executable)
@@ -178,39 +178,39 @@ UNION: forget-class-bug-2 forget-class-bug-1 dll ;
 
 [ f ] [ forget-class-bug-2 typemap get values [ memq? ] with contains? ] unit-test
 
-DEFER: mixin-forget-test-g
-
-[ "mixin-forget-test" forget-source ] with-compilation-unit
-
-[ ] [
-    {
-        "USING: sequences ;"
-        "IN: classes.tests"
-        "MIXIN: mixin-forget-test"
-        "INSTANCE: sequence mixin-forget-test"
-        "GENERIC: mixin-forget-test-g ( x -- y )"
-        "M: mixin-forget-test mixin-forget-test-g ;"
-    } "\n" join <string-reader> "mixin-forget-test"
-    parse-stream drop
-] unit-test
-
-[ { } ] [ { } mixin-forget-test-g ] unit-test
-[ H{ } mixin-forget-test-g ] must-fail
-
-[ ] [
-    {
-        "USING: hashtables ;"
-        "IN: classes.tests"
-        "MIXIN: mixin-forget-test"
-        "INSTANCE: hashtable mixin-forget-test"
-        "GENERIC: mixin-forget-test-g ( x -- y )"
-        "M: mixin-forget-test mixin-forget-test-g ;"
-    } "\n" join <string-reader> "mixin-forget-test"
-    parse-stream drop
-] unit-test
-
-[ { } mixin-forget-test-g ] must-fail
-[ H{ } ] [ H{ } mixin-forget-test-g ] unit-test
+2 [
+    [ "mixin-forget-test" forget-source ] with-compilation-unit
+    
+    [ ] [
+        {
+            "USING: sequences ;"
+            "IN: classes.tests"
+            "MIXIN: mixin-forget-test"
+            "INSTANCE: sequence mixin-forget-test"
+            "GENERIC: mixin-forget-test-g ( x -- y )"
+            "M: mixin-forget-test mixin-forget-test-g ;"
+        } "\n" join <string-reader> "mixin-forget-test"
+        parse-stream drop
+    ] unit-test
+    
+    [ { } ] [ { } "mixin-forget-test-g" "classes.tests" lookup execute ] unit-test
+    [ H{ } "mixin-forget-test-g" "classes.tests" lookup execute ] must-fail
+    
+    [ ] [
+        {
+            "USING: hashtables ;"
+            "IN: classes.tests"
+            "MIXIN: mixin-forget-test"
+            "INSTANCE: hashtable mixin-forget-test"
+            "GENERIC: mixin-forget-test-g ( x -- y )"
+            "M: mixin-forget-test mixin-forget-test-g ;"
+        } "\n" join <string-reader> "mixin-forget-test"
+        parse-stream drop
+    ] unit-test
+    
+    [ { } "mixin-forget-test-g" "classes.tests" lookup execute ] must-fail
+    [ H{ } ] [ H{ } "mixin-forget-test-g" "classes.tests" lookup execute ] unit-test
+] times
 
 ! Method flattening interfered with mixin update
 MIXIN: flat-mx-1
index 48ddb2adf56eeec2ed8311761710f65023dfeb76..e60d3ba2236c0d568f0ac42db6be6fe36ef3bcd7 100755 (executable)
@@ -31,17 +31,9 @@ PREDICATE: class tuple-class
 
 PREDICATE: word predicate "predicating" word-prop >boolean ;
 
-: define-predicate* ( class predicate quot -- )
-    over [
-        dupd predicate-effect define-declared
-        2dup 1quotation "predicate" set-word-prop
-        swap "predicating" set-word-prop
-    ] [ 3drop ] if ;
-
 : define-predicate ( class quot -- )
-    over "forgotten" word-prop [ 2drop ] [
-        >r dup predicate-word r> define-predicate*
-    ] if ;
+    >r "predicate" word-prop first
+    r> predicate-effect define-declared ;
 
 : superclass ( class -- super )
     "superclass" word-prop ;
@@ -257,6 +249,8 @@ PRIVATE>
     over reset-class
     over deferred? [ over define-symbol ] when
     >r dup word-props r> union over set-word-props
+    dup predicate-word 2dup 1quotation "predicate" set-word-prop
+    over "predicating" set-word-prop
     t "class" set-word-prop ;
 
 GENERIC: update-predicate ( class -- )
index 6cce72eed08b993db6d7b7f220fcb16ed006fa1f..dd71eb704f49cb2e08760efe853e41365ed8961f 100755 (executable)
@@ -9,7 +9,7 @@ ARTICLE: "compiler-errors" "Compiler warnings and errors"
 { $subsection :errors }
 { $subsection :warnings }
 { $subsection :linkage }
-"Words such as " { $link require } " and " { $link refresh-all } " use a combinator which counts errors and prints a report at the end:"
+"Words such as " { $link require } " use a combinator which counts errors and prints a report at the end:"
 { $link with-compiler-errors } ;
 
 HELP: compiler-errors
index 81063031f9a4e7e7c13eaea0c65ce7ea58c45488..7209b7ec4d6f555c3a6dc74e3ff5fbd87a6b41ab 100755 (executable)
@@ -29,7 +29,9 @@ $nl
 { $subsection ignore-errors }
 "Unhandled errors are reported in the listener and can be debugged using various tools. See " { $link "debugger" } "."
 { $subsection "errors-restartable" }
-{ $subsection "errors-post-mortem" } ;
+{ $subsection "errors-post-mortem" }
+"When Factor encouters a critical error, it calls the following word:"
+{ $subsection die } ;
 
 ARTICLE: "continuations.private" "Continuation implementation details"
 "A continuation is simply a tuple holding the contents of the five stacks:"
index 1ff972b5055cb418d73be21be96bc294cd16031c..df9c78fe47e2dfe1fd0e2ef5aba31e31f5be6a0a 100755 (executable)
@@ -1,5 +1,5 @@
 USING: help.markup help.syntax io io.styles strings
-io.backend io.files.private quotations ;
+       io.backend io.files.private quotations ;
 IN: io.files
 
 ARTICLE: "file-streams" "Reading and writing files"
@@ -43,13 +43,19 @@ ARTICLE: "directories" "Directories"
 { $subsection make-directory }
 { $subsection make-directories } ;
 
+! ARTICLE: "file-types" "File Types"
+
+!   { $table { +directory+ "" } }
+
+! ;
+
 ARTICLE: "fs-meta" "File meta-data"
+
 { $subsection file-info }
 { $subsection link-info }
 { $subsection exists? }
 { $subsection directory? }
-{ $subsection file-length }
-{ $subsection file-modified }
+! { $subsection file-modified }
 { $subsection stat } ;
 
 ARTICLE: "delete-move-copy" "Deleting, moving, copying files"
@@ -119,11 +125,26 @@ HELP: file-name
 ! need a $class-description file-info
 
 HELP: file-info
+
   { $values { "path" "a pathname string" }
-            { "info" "a file-info tuple" } }
+            { "info" file-info } }
   { $description "Queries the file system for meta data. "
                  "If path refers to a symbolic link, it is followed."
-                 "If the file does not exist, an exception is thrown." } ;
+                 "If the file does not exist, an exception is thrown." }
+
+  { $class-description "File meta data" }
+
+  { $table 
+           { "type" { "One of the following:"
+                      { $list { $link +regular-file+ }
+                              { $link +directory+ }
+                              { $link +symbolic-link+ } } } }
+
+           { "size"     "Size of the file in bytes" }
+           { "modified" "Last modification timestamp." } }
+
+  ;
+
 ! need a see also to link-info
 
 HELP: link-info
@@ -135,6 +156,8 @@ HELP: link-info
                  "If the file does not exist, an exception is thrown." } ;
 ! need a see also to file-info
 
+{ file-info link-info } related-words
+
 HELP: <file-reader>
 { $values { "path" "a pathname string" } { "encoding" "an encoding descriptor" { "stream" "an input stream" } }
     { "stream" "an input stream" } }
@@ -199,7 +222,7 @@ HELP: stat ( path -- directory? permissions length modified )
     "Queries the file system for file meta data. If the file does not exist, outputs " { $link f } " for all four values."
 } ;
 
-{ stat exists? directory? file-length file-modified } related-words
+{ stat exists? directory? } related-words
 
 HELP: path+
 { $values { "str1" "a string" } { "str2" "a string" } { "str" "a string" } }
@@ -227,13 +250,9 @@ HELP: directory*
 { $description "Outputs the contents of a directory named by " { $snippet "path" } "." }
 { $notes "Unlike " { $link directory } ", this word prepends the directory's path to all file names in the list." } ;
 
-HELP: file-length
-{ $values { "path" "a pathname string" } { "n" "a non-negative integer or " { $link f } } }
-{ $description "Outputs the length of the file in bytes, or " { $link f } " if it does not exist." } ;
-
-HELP: file-modified
-{ $values { "path" "a pathname string" } { "n" "a non-negative integer or " { $link f } } }
-{ $description "Outputs a file's last modification time, since midnight January 1, 1970. If the file does not exist, outputs " { $link f } "." } ;
+! HELP: file-modified
+! { $values { "path" "a pathname string" } { "n" "a non-negative integer or " { $link f } } }
+! { $description "Outputs a file's last modification time, since midnight January 1, 1970. If the file does not exist, outputs " { $link f } "." } ;
 
 HELP: resource-path
 { $values { "path" "a pathname string" } { "newpath" "a pathname string" } }
index e2eeef6528e4e258c3706de5f3d15303877e8a6d..e347e3e3d6bccf182ed857c35fda28c016647aaa 100755 (executable)
@@ -1,6 +1,10 @@
 IN: io.files.tests
 USING: tools.test io.files io threads kernel continuations io.encodings.ascii ;
 
+[ ] [ "blahblah" temp-file dup exists? [ delete-directory ] [ drop ] if ] unit-test
+[ ] [ "blahblah" temp-file make-directory ] unit-test
+[ t ] [ "blahblah" temp-file directory? ] unit-test
+
 [ "passwd" ] [ "/etc/passwd" file-name ] unit-test
 [ "awk" ] [ "/usr/libexec/awk/" file-name ] unit-test
 [ "awk" ] [ "/usr/libexec/awk///" file-name ] unit-test
@@ -123,3 +127,7 @@ USING: tools.test io.files io threads kernel continuations io.encodings.ascii ;
 [ ] [ "copy-tree-test" temp-file delete-tree ] unit-test
 
 [ t ] [ cwd "misc" resource-path [ ] with-directory cwd = ] unit-test
+
+[ ] [ "append-test" temp-file dup exists? [ delete-file ] [ drop ] if ] unit-test
+
+[ ] [ "append-test" ascii <file-appender> dispose ] unit-test
index cbb6e77ff97f806b89c22283215a5f714f606399..18cdbd379129110f895623d59a17c9fb3789b35b 100755 (executable)
@@ -86,15 +86,17 @@ SYMBOL: +unknown+
 : stat ( path -- directory? permissions length modified )
     normalize-pathname (stat) ;
 
-: file-length ( path -- n ) stat drop 2nip ;
+: file-length ( path -- n ) stat drop 2nip ;
 
 : file-modified ( path -- n ) stat >r 3drop r> ;
 
-: file-permissions ( path -- perm ) stat 2drop nip ;
+: file-permissions ( path -- perm ) stat 2drop nip ;
 
 : exists? ( path -- ? ) file-modified >boolean ;
 
-: directory? ( path -- ? ) stat 3drop ;
+! : directory? ( path -- ? ) stat 3drop ;
+
+: directory? ( path -- ? ) file-info file-info-type +directory+ = ;
 
 ! Current working directory
 HOOK: cd io-backend ( path -- )
@@ -220,7 +222,10 @@ M: pathname <=> [ pathname-string ] compare ;
     >r <file-reader> r> with-stream ; inline
 
 : file-contents ( path encoding -- str )
-    dupd [ file-length read ] with-file-reader ;
+    dupd [ file-info file-info-size read ] with-file-reader ;
+
+! : file-contents ( path encoding -- str )
+!     dupd [ file-length read ] with-file-reader ;
 
 : with-file-writer ( path encoding quot -- )
     >r <file-writer> r> with-stream ; inline
index 8e107975bb589a854663d3be5a82753eaf702419..0babb14fa75ce99edb886bea2dce410c77ba4e7c 100755 (executable)
@@ -429,7 +429,14 @@ $nl
 { $code "[ X ] [ Y ] ?if" "dup [ nip X ] [ drop Y ] if" } } ;
 
 HELP: die
-{ $description "Starts the front-end processor (FEP), which is a low-level debugger which can inspect memory addresses and the like. The FEP is also entered when a critical error occurs." } ;
+{ $description "Starts the front-end processor (FEP), which is a low-level debugger which can inspect memory addresses and the like. The FEP is also entered when a critical error occurs." }
+{ $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'." 
+    $nl
+    { $url "http://www.jargon.net/jargonfile/f/feppedout.html" }
+} ;
 
 HELP: (clone) ( obj -- newobj )
 { $values { "obj" object } { "newobj" "a shallow copy" } }
index 89783d1b3c335ab63df784ce979664312da456ea..a69e28ab97ca3cb799cada5691d7d9b7089550da 100755 (executable)
@@ -430,3 +430,20 @@ IN: parser.tests
 [ "resource:core/parser/test/assert-depth.factor" run-file ]
 [ relative-overflow-stack { 1 2 3 } sequence= ]
 must-fail-with
+
+2 [
+    [ ] [
+        "IN: parser.tests DEFER: d-f-s d-f-s SYMBOL: d-f-s d-f-s"
+        <string-reader> "d-f-s-test" parse-stream drop
+    ] unit-test
+
+    [ ] [
+        "IN: parser.tests DEFER: d-f-s d-f-s FORGET: d-f-s SYMBOL: d-f-s d-f-s"
+        <string-reader> "d-f-s-test" parse-stream drop
+    ] unit-test
+
+    [ ] [
+        "IN: parser.tests DEFER: d-f-s d-f-s SYMBOL: d-f-s d-f-s"
+        <string-reader> "d-f-s-test" parse-stream drop
+    ] unit-test
+] times
index 81c9b68668b38710ce3f9ebc7f3fab6083be16b3..50f8f582d352ab32cf753b78cf5439754276d36b 100755 (executable)
@@ -416,6 +416,7 @@ SYMBOL: interactive-vocabs
     "tools.test"
     "tools.threads"
     "tools.time"
+    "tools.vocabs"
     "vocabs"
     "vocabs.loader"
     "words"
@@ -483,7 +484,6 @@ SYMBOL: interactive-vocabs
 : finish-parsing ( lines quot -- )
     file get
     [ record-form ] keep
-    [ record-modified ] keep
     [ record-definitions ] keep
     record-checksum ;
 
index 2371c27e5226ceb3f208e3dff2f5b6923a838c2d..2f2f8fd0c02d71f74dd754ac6625b6485f83c460 100755 (executable)
@@ -3,16 +3,13 @@ definitions quotations compiler.units ;
 IN: source-files
 
 ARTICLE: "source-files" "Source files"
-"Words in the " { $vocab-link "source-files" } " vocabulary are used to keep track of loaded source files. This is used to implement features such as " { $link refresh-all } "."
+"Words in the " { $vocab-link "source-files" } " vocabulary are used to keep track of loaded source files. This is used to implement " { $link "tools.vocabs" } "."
 $nl
 "The source file database:"
 { $subsection source-files }
 "The class of source files:"
 { $subsection source-file }
-"Testing if a source file has been changed on disk:"
-{ $subsection source-modified? }
 "Words intended for the parser:"
-{ $subsection record-modified }
 { $subsection record-checksum }
 { $subsection record-form }
 { $subsection xref-source }
@@ -34,22 +31,12 @@ HELP: source-file
 { $class-description "Instances retain information about loaded source files, and have the following slots:"
     { $list
         { { $link source-file-path } " - a pathname string." }
-        { { $link source-file-modified } " - the result of " { $link file-modified } " at the time the source file was most recently loaded." }
         { { $link source-file-checksum } " - the CRC32 checksum of the source file's contents at the time it was most recently loaded." }
         { { $link source-file-uses } " - an assoc whose keys are words referenced from this source file's top level form." }
         { { $link source-file-definitions } " - a pair of assocs, containing definitions and classes defined in this source file, respectively" }
     }
 } ;
 
-HELP: source-modified?
-{ $values { "path" "a pathname string" } { "?" "a boolean" } }
-{ $description "Tests if the source file has been modified since it was last loaded. This compares the file's modification time and CRC32 checksum of the file's contents against previously-recorded values." } ;
-
-HELP: record-modified
-{ $values { "source-file" source-file } }
-{ $description "Records the modification time of the source file." } 
-$low-level-note ;
-
 HELP: record-checksum
 { $values { "source-file" source-file } { "lines" "a sequence of strings" } }
 { $description "Records the CRC32 checksm of the source file's contents." } 
@@ -75,7 +62,7 @@ HELP: record-form
 $low-level-note ;
 
 HELP: reset-checksums
-{ $description "Resets recorded modification times and CRC32 checksums for all loaded source files, creating a checkpoint for " { $link refresh } "." } ;
+{ $description "Resets recorded modification times and CRC32 checksums for all loaded source files, creating a checkpoint for " { $link "tools.vocabs" } "." } ;
 
 HELP: forget-source
 { $values { "path" "a pathname string" } }
index 98438b48d8e179961cab29a239c19b0e8587695f..f4428e4e8b7bb9935950e33e58e3ad868fc66546 100755 (executable)
@@ -1,44 +1,25 @@
-! Copyright (C) 2007 Slava Pestov.
+! Copyright (C) 2007, 2008 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: arrays definitions generic assocs kernel math
-namespaces prettyprint sequences strings vectors words
-quotations inspector io.styles io combinators sorting
-splitting math.parser effects continuations debugger
-io.files io.crc32 io.streams.string vocabs
-hashtables graphs compiler.units io.encodings.utf8 ;
+USING: arrays definitions generic assocs kernel math namespaces
+prettyprint sequences strings vectors words quotations inspector
+io.styles io combinators sorting splitting math.parser effects
+continuations debugger io.files io.crc32 vocabs hashtables
+graphs compiler.units io.encodings.utf8 ;
 IN: source-files
 
 SYMBOL: source-files
 
 TUPLE: source-file
 path
-modified checksum
+checksum
 uses definitions ;
 
-: (source-modified?) ( path modified checksum -- ? )
-    pick file-modified rot [ 0 or ] 2apply >
-    [ swap utf8 file-lines lines-crc32 = not ] [ 2drop f ] if ;
-
-: source-modified? ( path -- ? )
-    dup source-files get at [
-        dup source-file-path ?resource-path
-        over source-file-modified
-        rot source-file-checksum
-        (source-modified?)
-    ] [
-        resource-exists?
-    ] ?if ;
-
-: record-modified ( source-file -- )
-    dup source-file-path ?resource-path file-modified
-    swap set-source-file-modified ;
-
 : record-checksum ( lines source-file -- )
-    swap lines-crc32 swap set-source-file-checksum ;
+    >r lines-crc32 r> set-source-file-checksum ;
 
 : (xref-source) ( source-file -- pathname uses )
-    dup source-file-path <pathname> swap source-file-uses
-    [ crossref? ] subset ;
+    dup source-file-path <pathname>
+    swap source-file-uses [ crossref? ] subset ;
 
 : xref-source ( source-file -- )
     (xref-source) crossref get add-vertex ;
@@ -67,9 +48,7 @@ uses definitions ;
 
 : reset-checksums ( -- )
     source-files get [
-        swap ?resource-path dup exists?
-        [
-            over record-modified
+        swap ?resource-path dup exists? [
             utf8 file-lines swap record-checksum
         ] [ 2drop ] if
     ] assoc-each ;
index 9f7b2b5b9f5438d3720862e51538dcf9e961e8dc..c7652c34c78aa012cdac232dc9b70a210d3dc51d 100755 (executable)
@@ -23,9 +23,6 @@ $nl
 "Application vocabularies can define a main entry point, giving the user a convenient way to run the application:"
 { $subsection POSTPONE: MAIN: }
 { $subsection run }
-"Reloading source files changed on disk:"
-{ $subsection refresh }
-{ $subsection refresh-all }
 { $see-also "vocabularies" "parser-files" "source-files" } ;
 
 ABOUT: "vocabs.loader"
@@ -42,20 +39,12 @@ HELP: vocab-main
 HELP: vocab-roots
 { $var-description "A sequence of pathname strings to search for vocabularies." } ;
 
-HELP: vocab-tests
-{ $values { "vocab" "a vocabulary specifier" } { "tests" "a sequence of pathname strings" } }
-{ $description "Outputs a sequence of pathnames where the unit tests for " { $snippet "vocab" } " are located." } ;
-
 HELP: find-vocab-root
 { $values { "vocab" "a vocabulary specifier" } { "path/f" "a pathname string" } }
 { $description "Searches for a vocabulary in the vocabulary roots." } ;
 
 { vocab-root find-vocab-root } related-words
 
-HELP: vocab-files
-{ $values { "vocab" "a vocabulary specifier" } { "seq" "a sequence of pathname strings" } }
-{ $description "Outputs a sequence of files comprising this vocabulary, or " { $link f } " if the vocabulary does not have a directory on disk." } ;
-
 HELP: no-vocab
 { $values { "name" "a vocabulary name" } } 
 { $description "Throws a " { $link no-vocab } "." }
@@ -80,7 +69,7 @@ HELP: reload
 HELP: require
 { $values { "vocab" "a vocabulary specifier" } }
 { $description "Loads a vocabulary if it has not already been loaded." }
-{ $notes "To unconditionally reload a vocabulary, use " { $link reload } ". To reload changed source files, use " { $link refresh } " or " { $link refresh-all } "." } ;
+{ $notes "To unconditionally reload a vocabulary, use " { $link reload } ". To reload changed source files only, use the words in " { $link "tools.vocabs" } "." } ;
 
 HELP: run
 { $values { "vocab" "a vocabulary specifier" } }
@@ -93,12 +82,3 @@ HELP: vocab-source-path
 HELP: vocab-docs-path
 { $values { "vocab" "a vocabulary specifier" } { "path/f" "a pathname string or " { $link f } } }
 { $description "Outputs a pathname where the documentation for " { $snippet "vocab" } " might be found. Outputs " { $link f } " if the vocabulary does not have a directory on disk." } ;
-
-HELP: refresh
-{ $values { "prefix" string } }
-{ $description "Reloads source files and documentation belonging to loaded vocabularies whose names are prefixed by " { $snippet "prefix" } " which have been modified on disk." } ;
-
-HELP: refresh-all
-{ $description "Reloads source files and documentation for all loaded vocabularies which have been modified on disk." } ;
-
-{ refresh refresh-all } related-words
index f99bf94aa4398bdbeff66e0ad3d2c3b80a692135..514e45f10f6f64849834d3f16c45dd8ef7473abe 100755 (executable)
@@ -3,7 +3,7 @@ IN: vocabs.loader.tests
 USING: vocabs.loader tools.test continuations vocabs math
 kernel arrays sequences namespaces io.streams.string
 parser source-files words assocs tuples definitions
-debugger compiler.units ;
+debugger compiler.units tools.vocabs ;
 
 ! This vocab should not exist, but just in case...
 [ ] [
index 885bccddd156e61a374f4fb94b04c25d79e68463..fa9ff5b504ea2e04c4f6774d9f360234fc3826b9 100755 (executable)
@@ -48,27 +48,6 @@ M: string vocab-root
 M: vocab-link vocab-root
     vocab-link-root ;
 
-: vocab-tests ( vocab -- tests )
-    dup vocab-root [
-        [
-            f >vocab-link dup
-
-            dup "-tests.factor" vocab-dir+ vocab-path+
-            dup resource-exists? [ , ] [ drop ] if
-
-            dup vocab-dir "tests" path+ vocab-path+ dup
-            ?resource-path directory keys [ ".factor" tail? ] subset
-            [ path+ , ] with each
-        ] { } make
-    ] [ drop f ] if ;
-
-: vocab-files ( vocab -- seq )
-    f >vocab-link [
-        dup vocab-source-path [ , ] when*
-        dup vocab-docs-path [ , ] when*
-        vocab-tests %
-    ] { } make ;
-
 SYMBOL: load-help?
 
 : source-was-loaded t swap set-vocab-source-loaded? ;
@@ -119,68 +98,7 @@ SYMBOL: load-help?
         "To define one, refer to \\ MAIN: help" print
     ] ?if ;
 
-: modified ( seq quot -- seq )
-    [ dup ] swap compose { } map>assoc
-    [ nip ] assoc-subset
-    [ nip source-modified? ] assoc-subset keys ; inline
-
-: modified-sources ( vocabs -- seq )
-    [ vocab-source-path ] modified ;
-
-: modified-docs ( vocabs -- seq )
-    [ vocab-docs-path ] modified ;
-
-: update-roots ( vocabs -- )
-    [ dup find-vocab-root swap vocab set-vocab-root ] each ;
-
-: to-refresh ( prefix -- modified-sources modified-docs )
-    child-vocabs
-    dup update-roots
-    dup modified-sources swap modified-docs ;
-
-: vocab-heading. ( vocab -- )
-    nl
-    "==== " write
-    dup vocab-name swap vocab write-object ":" print
-    nl ;
-
-: load-error. ( triple -- )
-    dup first vocab-heading.
-    dup second print-error
-    drop ;
-
-: load-failures. ( failures -- )
-    [ load-error. nl ] each ;
-
 SYMBOL: blacklist
-SYMBOL: failures
-
-: require-all ( vocabs -- failures )
-    [
-        V{ } clone blacklist set
-        V{ } clone failures set
-        [
-            [ require ]
-            [ swap vocab-name failures get set-at ]
-            recover
-        ] each
-        failures get
-    ] with-compiler-errors ;
-
-: do-refresh ( modified-sources modified-docs -- )
-    2dup
-    [ f swap set-vocab-docs-loaded? ] each
-    [ f swap set-vocab-source-loaded? ] each
-    append prune require-all load-failures. ;
-
-: refresh ( prefix -- ) to-refresh do-refresh ;
-
-SYMBOL: sources-changed?
-
-[ t sources-changed? set-global ] "vocabs.loader" add-init-hook
-
-: refresh-all ( -- )
-    "" refresh f sources-changed? set-global ;
 
 GENERIC: (load-vocab) ( name -- vocab )
 
index 88095759e67c67ebc93e957ac83d6830ad6a2d26..2500940373ada62a6a99919374f0b2fbb6ea31ee 100755 (executable)
@@ -1,4 +1,5 @@
-USING: assocs kernel vectors sequences namespaces ;
+USING: arrays assocs kernel vectors sequences namespaces
+random math.parser ;
 IN: assocs.lib
 
 : >set ( seq -- hash )
@@ -35,3 +36,13 @@ IN: assocs.lib
     [ with each ] curry assoc-each ; inline
 
 : insert ( value variable -- ) namespace insert-at ;
+
+: 2seq>assoc ( keys values exemplar -- assoc )
+    >r 2array flip r> assoc-like ;
+
+: generate-key ( assoc -- str )
+    >r random-256 >hex r>
+    2dup key? [ nip generate-key ] [ drop ] if ;
+
+: set-at-unique ( value assoc -- key )
+    dup generate-key [ swap set-at ] keep ;
index 231c6edf50a542e3de72d03d9f7847c9f07d8237..26f1a9e96d6967f37851e01e01115c6938a136f4 100755 (executable)
@@ -1,28 +1,28 @@
 ! Copyright (C) 2007, 2008 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: kernel vocabs vocabs.loader tools.time tools.browser
+USING: kernel vocabs vocabs.loader tools.time tools.vocabs
 arrays assocs io.styles io help.markup prettyprint sequences
-continuations debugger ;
+continuations debugger combinators.cleave ;
 IN: benchmark
 
 : run-benchmark ( vocab -- result )
-  [ dup require [ run ] benchmark ] [ error. drop f f ] recover 2array ;
+  [ [ require ] [ [ run ] benchmark nip ] bi ] curry
+  [ error. f ] recover ;
 
 : run-benchmarks ( -- assoc )
-  "benchmark" all-child-vocabs values concat [ vocab-name ] map
+  "benchmark" all-child-vocabs-seq
   [ dup run-benchmark ] { } map>assoc ;
 
 : benchmarks. ( assoc -- )
     standard-table-style [
         [
             [ "Benchmark" write ] with-cell
-            [ "Run time (ms)" write ] with-cell
-            [ "GC time (ms)" write ] with-cell
+            [ "Time (ms)" write ] with-cell
         ] with-row
         [
             [
-                swap [ dup ($vocab-link) ] with-cell
-                first2 pprint-cell pprint-cell
+                [ [ 1array $vocab-link ] with-cell ]
+                [ pprint-cell ] bi*
             ] with-row
         ] assoc-each
     ] tabular-output ;
old mode 100644 (file)
new mode 100755 (executable)
index 3c9c78d..30c3beb
@@ -51,7 +51,7 @@ HINTS: random fixnum ;
     dup keys >byte-array
     swap values >float-array unclip [ + ] accumulate swap add ;
 
-:: select-random ( seed chars floats -- elt )
+:: select-random ( seed chars floats -- seed elt )
     floats seed random -rot
     [ >= ] curry find drop
     chars nth-unsafe ; inline
@@ -71,7 +71,7 @@ HINTS: random fixnum ;
     write-description
     [ make-random-fasta ] 2curry split-lines ; inline
 
-:: make-repeat-fasta ( k len alu -- )
+:: make-repeat-fasta ( k len alu -- k' )
     [let | kn [ alu length ] |
         len [ k + kn mod alu nth-unsafe ] B{ } map-as print
         k len +
index 718f73308cdb4ea948692b2974fb72e0e79b037c..0bf7a032ee176765e17c1e45870b4cc4be15191f 100755 (executable)
@@ -11,5 +11,7 @@ USING: vocabs.loader sequences ;
     "tools.test"
     "tools.time"
     "tools.threads"
+    "tools.vocabs"
+    "tools.vocabs.browser"
     "editors"
 } [ require ] each
index 48891593d2350b735cfd16bb3419e05b16b04008..444e5b6ea703f93c28e1f7e6196ed6aebf1f4d02 100644 (file)
@@ -21,7 +21,7 @@ IN: builder.benchmark
   [ benchmark-difference ] with map ;
 
 : benchmark-deltas ( -- table )
-  "../../benchmarks" "../benchmarks" [ eval-file ] 2apply
+  "../benchmarks" "benchmarks" [ eval-file ] 2apply
   compare-tables
   sort-values ;
 
old mode 100755 (executable)
new mode 100644 (file)
index da96e51..7d95ce2
@@ -4,6 +4,7 @@ USING: kernel namespaces sequences splitting system combinators continuations
        bootstrap.image benchmark vars bake smtp builder.util accessors
        io.encodings.utf8
        calendar
+       tools.test
        builder.common
        builder.benchmark
        builder.release ;
@@ -131,7 +132,12 @@ SYMBOL: build-status
       "Test time: " write "test-time" eval-file milli-seconds>time print nl
 
       "Did not pass load-everything: " print "load-everything-vocabs" cat
+      
       "Did not pass test-all: "        print "test-all-vocabs"        cat
+                                             "test-failures"          cat
+      
+!       "test-failures" eval-file test-failures.
+      
       "help-lint results:"             print "help-lint"              cat
 
       "Benchmarks: " print "benchmarks" eval-file benchmarks.
index dd3c640a84f662fa9e11176e32e970ebce15c98d..3634082f56ebeb6e83a55b74b7c6e62d700f6827 100644 (file)
@@ -4,7 +4,7 @@ USING: kernel namespaces sequences assocs builder continuations
        io
        io.files
        prettyprint
-       tools.browser
+       tools.vocabs
        tools.test
        io.encodings.utf8
        combinators.cleave
@@ -21,13 +21,19 @@ IN: builder.test
 
 : do-tests ( -- )
   run-all-tests
-  "../test-all-vocabs" utf8
-    [
-        [ keys . ]
-        [ test-failures. ]
-      bi
-    ]
-  with-file-writer ;
+    [ keys "../test-all-vocabs" utf8 [ .              ] with-file-writer ]
+    [      "../test-failures"   utf8 [ test-failures. ] with-file-writer ]
+  bi ;
+
+! : do-tests ( -- )
+!   run-all-tests
+!   "../test-all-vocabs" utf8
+!     [
+!         [ keys . ]
+!         [ test-failures. ]
+!       bi
+!     ]
+!   with-file-writer ;
 
 : do-help-lint ( -- )
   "" run-help-lint "../help-lint" utf8 [ typos. ] with-file-writer ;
index 12aaffc19c53c5b44372380ce36de489c37f6172..a3f61747266e30a8d093cef8e4fa194d88a91e05 100755 (executable)
@@ -1,12 +1,14 @@
 USING: tools.deploy.config ;
-V{
+H{
+    { deploy-math? t }
+    { deploy-reflection 1 }
+    { deploy-name "Bunny" }
+    { deploy-threads? t }
+    { deploy-word-props? f }
+    { "stop-after-last-window?" t }
     { deploy-ui? t }
     { deploy-io 3 }
-    { deploy-reflection 1 }
     { deploy-compiler? t }
-    { deploy-math? t }
-    { deploy-word-props? f }
+    { deploy-word-defs? f }
     { deploy-c-types? f }
-    { "stop-after-last-window?" t }
-    { deploy-name "Bunny" }
 }
old mode 100644 (file)
new mode 100755 (executable)
index d7064eb..012aa1f
@@ -1,7 +1,7 @@
 USING: arrays bunny.model bunny.cel-shaded
 combinators.lib continuations kernel math multiline
 opengl opengl.shaders opengl.framebuffers opengl.gl
-opengl.capabilities sequences ui.gadgets ;
+opengl.capabilities sequences ui.gadgets combinators.cleave ;
 IN: bunny.outlined
 
 STRING: outlined-pass1-fragment-shader-main-source
@@ -177,7 +177,7 @@ TUPLE: bunny-outlined
             [ bunny-outlined-normal-texture [ delete-texture ] when* ]
             [ bunny-outlined-depth-texture  [ delete-texture ] when* ]
             [ f swap set-bunny-outlined-framebuffer-dim ]
-        } call-with
+        } cleave
     ] [ drop ] if ;
 
 : remake-framebuffer-if-needed ( draw -- )
@@ -237,4 +237,4 @@ M: bunny-outlined dispose
         [ bunny-outlined-pass1-program [ delete-gl-program ] when* ]
         [ bunny-outlined-pass2-program [ delete-gl-program ] when* ]
         [ dispose-framebuffer ]
-    } call-with ;
+    } cleave ;
index 316479d53cdd7c857ff48e153de603a8fbafe3ad..ab8858efb3d8c234be78619ec3193b22fd7c07eb 100644 (file)
@@ -6,7 +6,7 @@
 !  http://cairographics.org/samples/text/
 
 
-USING: cairo math math.constants byte-arrays kernel ui ui.render
+USING: cairo.ffi math math.constants byte-arrays kernel ui ui.render
            ui.gadgets opengl.gl ;
 
 IN: cairo-demo
@@ -22,14 +22,16 @@ IN: cairo-demo
 
 TUPLE: cairo-gadget image-array cairo-t ;
 
-M: cairo-gadget draw-gadget* ( gadget -- )
-   0 0 glRasterPos2i
-   1.0 -1.0 glPixelZoom
-   >r 384 256 GL_RGBA GL_UNSIGNED_BYTE r>
-   cairo-gadget-image-array glDrawPixels ;
+M: cairo-gadget draw-gadget* ( gadget -- )
+   0 0 glRasterPos2i
+   1.0 -1.0 glPixelZoom
+   >r 384 256 GL_RGBA GL_UNSIGNED_BYTE r>
+   cairo-gadget-image-array glDrawPixels ;
 
 : create-surface ( gadget -- cairo_surface_t )
-  make-image-array dup >r swap set-cairo-gadget-image-array r> convert-array-to-surface ;
+    make-image-array
+    [ swap set-cairo-gadget-image-array ] keep
+    convert-array-to-surface ;
 
 : init-cairo ( gadget -- cairo_t )
    create-surface cairo_create ;
@@ -56,10 +58,10 @@ M: cairo-gadget pref-dim* drop { 384 256 0 } ;
   cairo_fill ;
 
 M: cairo-gadget graft* ( gadget -- )
-   dup dup init-cairo swap set-cairo-gadget-cairo-t draw-hello-world ;
+  dup dup init-cairo swap set-cairo-gadget-cairo-t draw-hello-world ;
 
-M: cairo-gadget ungraft* ( gadget -- )
-   cairo-gadget-cairo-t cairo_destroy ;
+M: cairo-gadget ungraft* ( gadget -- )
+   cairo-gadget-cairo-t cairo_destroy ;
 
 : <cairo-gadget> ( -- gadget )
   cairo-gadget construct-gadget ;
index 4a2736dd934b5c2e533ca263d87e80cf0f7c9aa3..68d35d192b42a2515c48045af4ab6a419eb0ca2e 100644 (file)
@@ -1 +1,2 @@
 Sampo Vuori
+Doug Coleman
diff --git a/extra/cairo/cairo.factor b/extra/cairo/cairo.factor
deleted file mode 100644 (file)
index 0d3e0c2..0000000
+++ /dev/null
@@ -1,459 +0,0 @@
-! Bindings for Cairo library
-!  Copyright (c) 2007 Sampo Vuori
-!    License: http://factorcode.org/license.txt
-
-! Unimplemented:
-!  - most of the font stuff
-!  - most of the matrix stuff
-!  - most of the query functions
-
-
-USING: alien alien.syntax combinators system ;
-
-IN: cairo
-
-<< "cairo" {
-        { [ win32? ] [ "cairo.dll" ] }
-        ! { [ macosx? ] [ "libcairo.dylib" ] }
-        { [ macosx? ] [ "/opt/local/lib/libcairo.dylib" ] }
-        { [ unix? ] [ "libcairo.so.2" ] }
-  } cond "cdecl" add-library >>
-
-LIBRARY: cairo
-
-TYPEDEF: int cairo_status_t
-C-ENUM:
-    CAIRO_STATUS_SUCCESS
-    CAIRO_STATUS_NO_MEMORY
-    CAIRO_STATUS_INVALID_RESTORE
-    CAIRO_STATUS_INVALID_POP_GROUP
-    CAIRO_STATUS_NO_CURRENT_POINT
-    CAIRO_STATUS_INVALID_MATRIX
-    CAIRO_STATUS_INVALID_STATUS
-    CAIRO_STATUS_NULL_POINTER
-    CAIRO_STATUS_INVALID_STRING
-    CAIRO_STATUS_INVALID_PATH_DATA
-    CAIRO_STATUS_READ_ERROR
-    CAIRO_STATUS_WRITE_ERROR
-    CAIRO_STATUS_SURFACE_FINISHED
-    CAIRO_STATUS_SURFACE_TYPE_MISMATCH
-    CAIRO_STATUS_PATTERN_TYPE_MISMATCH
-    CAIRO_STATUS_INVALID_CONTENT
-    CAIRO_STATUS_INVALID_FORMAT
-    CAIRO_STATUS_INVALID_VISUAL
-    CAIRO_STATUS_FILE_NOT_FOUND
-    CAIRO_STATUS_INVALID_DASH
-    CAIRO_STATUS_INVALID_DSC_COMMENT
-    CAIRO_STATUS_INVALID_INDEX
-    CAIRO_STATUS_CLIP_NOT_REPRESENTABLE
-;
-
-TYPEDEF: int cairo_content_t
-: CAIRO_CONTENT_COLOR HEX: 1000 ;
-: CAIRO_CONTENT_ALPHA HEX: 2000 ;
-: CAIRO_CONTENT_COLOR_ALPHA HEX: 3000 ;
-
-TYPEDEF: int cairo_operator_t
-C-ENUM:
-    CAIRO_OPERATOR_CLEAR
-    CAIRO_OPERATOR_SOURCE
-    CAIRO_OPERATOR_OVER
-    CAIRO_OPERATOR_IN
-    CAIRO_OPERATOR_OUT
-    CAIRO_OPERATOR_ATOP
-    CAIRO_OPERATOR_DEST
-    CAIRO_OPERATOR_DEST_OVER
-    CAIRO_OPERATOR_DEST_IN
-    CAIRO_OPERATOR_DEST_OUT
-    CAIRO_OPERATOR_DEST_ATOP
-    CAIRO_OPERATOR_XOR
-    CAIRO_OPERATOR_ADD
-    CAIRO_OPERATOR_SATURATE
-;
-
-TYPEDEF: int cairo_line_cap_t
-C-ENUM:
-    CAIRO_LINE_CAP_BUTT
-    CAIRO_LINE_CAP_ROUND
-    CAIRO_LINE_CAP_SQUARE
-;
-
-TYPEDEF: int cair_line_join_t
-C-ENUM:
-    CAIRO_LINE_JOIN_MITER
-    CAIRO_LINE_JOIN_ROUND
-    CAIRO_LINE_JOIN_BEVEL
-;
-
-TYPEDEF: int cairo_fill_rule_t
-C-ENUM:
-    CAIRO_FILL_RULE_WINDING
-    CAIRO_FILL_RULE_EVEN_ODD
-;
-
-TYPEDEF: int cairo_font_slant_t
-C-ENUM:
-    CAIRO_FONT_SLANT_NORMAL
-    CAIRO_FONT_SLANT_ITALIC
-    CAIRO_FONT_SLANT_OBLIQUE
-;
-
-TYPEDEF: int cairo_font_weight_t
-C-ENUM:
-    CAIRO_FONT_WEIGHT_NORMAL
-    CAIRO_FONT_WEIGHT_BOLD
-;
-
-C-STRUCT: cairo_font_t
-    { "int" "refcount" }
-    { "uint" "scale" } ;
-
-C-STRUCT: cairo_rectangle_t
-    { "short" "x" }
-    { "short" "y" }
-    { "ushort" "width" }
-    { "ushort" "height" } ;
-
-C-STRUCT: cairo_clip_rec_t
-    { "cairo_rectangle_t" "rect" }
-    { "void*" "region" }
-    { "void*" "surface" } ;
-
-C-STRUCT: cairo_matrix_t
-    { "void*" "m" } ;
-
-C-STRUCT: cairo_gstate_t
-    { "uint" "operator" }
-    { "double" "tolerance" }
-    { "double" "line_width" }
-    { "uint" "line_cap" }
-    { "uint" "line_join" }
-    { "double" "miter_limit" }
-    { "uint" "fill_rule" }
-    { "void*" "dash" }
-    { "int" "num_dashes" }
-    { "double" "dash_offset" }
-    { "char*" "font_family " }
-    { "uint" "font_slant" }
-    { "uint" "font_weight" }
-    { "void*" "font" }
-    { "void*" "surface" }
-    { "void*" "pattern " }
-    { "double" "alpha" }
-    { "cairo_clip_rec_t" "clip" }
-    { "double" "pixels_per_inch" }
-    { "cairo_matrix_t" "font_matrix" }
-    { "cairo_matrix_t" "ctm" }
-    { "cairo_matrix_t" "ctm_inverse" }
-    { "void*" "path" }
-    { "void*" "pen_regular" }
-    { "void*" "next" } ;
-
-C-STRUCT: cairo_t
-    { "uint" "ref_count" }
-    { "cairo_gstate_t*" "gstate" }
-    { "uint" "status ! cairo_status_t" } ;
-
-C-STRUCT: cairo_matrix_t
-        { "double" "xx" }
-        { "double" "yx" }
-        { "double" "xy" }
-        { "double" "yy" }
-        { "double" "x0" }
-        { "double" "y0" } ;
-
-TYPEDEF: int cairo_format_t
-C-ENUM:
-    CAIRO_FORMAT_ARGB32
-    CAIRO_FORMAT_RGB24
-    CAIRO_FORMAT_A8
-    CAIRO_FORMAT_A1
-;
-
-TYPEDEF: int cairo_antialias_t
-C-ENUM:
-    CAIRO_ANTIALIAS_DEFAULT
-    CAIRO_ANTIALIAS_NONE
-    CAIRO_ANTIALIAS_GRAY
-    CAIRO_ANTIALIAS_SUBPIXEL
-;
-
-TYPEDEF: int cairo_subpixel_order_t
-C-ENUM:
-    CAIRO_SUBPIXEL_ORDER_DEFAULT
-    CAIRO_SUBPIXEL_ORDER_RGB
-    CAIRO_SUBPIXEL_ORDER_BGR
-    CAIRO_SUBPIXEL_ORDER_VRGB
-    CAIRO_SUBPIXEL_ORDER_VBGR
-;
-
-TYPEDEF: int cairo_hint_style_t
-C-ENUM:
-    CAIRO_HINT_STYLE_DEFAULT
-    CAIRO_HINT_STYLE_NONE
-    CAIRO_HINT_STYLE_SLIGHT
-    CAIRO_HINT_STYLE_MEDIUM
-    CAIRO_HINT_STYLE_FULL
-;
-
-TYPEDEF: int cairo_hint_metrics_t
-C-ENUM:
-    CAIRO_HINT_METRICS_DEFAULT
-    CAIRO_HINT_METRICS_OFF
-    CAIRO_HINT_METRICS_ON
-;
-
-: cairo_create ( cairo_surface_t -- cairo_t )
-    "cairo_t*" "cairo" "cairo_create" [ "void*" ] alien-invoke ;
-
-: cairo_reference ( cairo_t -- cairo_t )
-        "cairo_t*" "cairo" "cairo_reference" [ "cairo_t*" ] alien-invoke ;
-
-: cairo_destroy ( cairo_t -- )
-    "void" "cairo" "cairo_destroy" [ "cairo_t*" ] alien-invoke ;
-
-: cairo_save ( cairo_t -- )
-        "void" "cairo" "cairo_save" [ "cairo_t*" ] alien-invoke ;
-
-: cairo_restore ( cairo_t -- )
-        "void" "cairo" "cairo_restore" [ "cairo_t*" ] alien-invoke ;
-
-: cairo_set_operator ( cairo_t cairo_operator_t -- )
-    "void" "cairo" "cairo_set_operator" [ "cairo_t*" "int" ] alien-invoke ;
-
-: cairo_set_source ( cairo_t cairo_pattern_t -- )
-    "void" "cairo" "cairo_set_source" [ "cairo_t*" "void*" ] alien-invoke ;
-
-: cairo_set_source_rgb ( cairo_t red green blue -- )
-    "void" "cairo" "cairo_set_source_rgb" [ "cairo_t*" "double" "double" "double" ] alien-invoke ;
-
-: cairo_set_source_rgba ( cairo_t red green blue alpha -- )
-    "void" "cairo" "cairo_set_source_rgb" [ "cairo_t*" "double" "double" "double" "double" ] alien-invoke ;
-
-: cairo_set_source_surface ( cairo_t cairo_surface_t x y -- )
-    "void" "cairo" "cairo_set_source_surface" [ "cairo_t*" "void*" "double" "double" ] alien-invoke ;
-
-: cairo_set_tolerance ( cairo_t tolerance -- )
-    "void" "cairo" "cairo_set_tolerance" [ "cairo_t*" "double" ] alien-invoke ;
-
-: cairo_image_surface_create_for_data ( data format width height stride -- cairo_surface_t )
-    "void*" "cairo" "cairo_image_surface_create_for_data" [ "void*" "uint" "int" "int" "int" ] alien-invoke ;
-    
-
-: cairo_set_antialias ( cairo_t cairo_antialias_t -- )
-    "void" "cairo" "cairo_set_antialias" [ "cairo_t*" "int" ] alien-invoke ;
-
-: cairo_set_fill_rule ( cairo_t cairo_fill_rule_t -- )
-    "void" "cairo" "cairo_set_fill_rule" [ "cairo_t*" "int" ] alien-invoke ;
-
-: cairo_set_line_width ( cairo_t width -- )
-    "void" "cairo" "cairo_set_line_width" [ "cairo_t*" "double" ] alien-invoke ;
-
-: cairo_set_line_cap ( cairo_t cairo_line_cap_t -- )
-    "void" "cairo" "cairo_set_line_cap" [ "cairo_t*" "int" ] alien-invoke ;
-
-: cairo_set_line_join ( cairo_t cairo_line_join_t -- )
-    "void" "cairo" "cairo_set_line_join" [ "cairo_t*" "int" ] alien-invoke ;
-
-: cairo_set_dash ( cairo_t dashes num_dashes offset -- )
-    "void" "cairo" "cairo_set_dash" [ "cairo_t*" "double" "int" "double" ] alien-invoke ;
-
-: cairo_set_miter_limit ( cairo_t limit -- )
-    "void" "cairo" "cairo_set_miter_limit" [ "cairo_t*" "double" ] alien-invoke ;
-
-: cairo_translate ( cairo_t x y -- )
-    "void" "cairo" "cairo_translate" [ "cairo_t*" "double" "double" ] alien-invoke ;
-
-: cairo_scale ( cairo_t sx sy -- )
-    "void" "cairo" "cairo_scale" [ "cairo_t*" "double" "double" ] alien-invoke ;
-
-: cairo_rotate ( cairo_t angle -- )
-    "void" "cairo" "cairo_rotate" [ "cairo_t*" "double" ] alien-invoke ;
-
-: cairo_transform ( cairo_t cairo_matrix_t -- )
-        "void" "cairo" "cairo_transform" [ "cairo_t*" "cairo_matrix_t*" ] alien-invoke ;
-
-: cairo_set_matrix ( cairo_t cairo_matrix_t -- )
-        "void" "cairo" "cairo_set_matrix" [ "cairo_t*" "cairo_matrix_t*" ] alien-invoke ;
-
-: cairo_identity_matrix ( cairo_t -- )
-        "void" "cairo" "cairo_identity_matrix" [ "cairo_t*" ] alien-invoke ;
-
-! cairo path creating functions
-
-: cairo_new_path ( cairo_t -- )
-    "void" "cairo" "cairo_new_path" [ "cairo_t*" ] alien-invoke ;
-
-: cairo_move_to ( cairo_t x y -- )
-    "void" "cairo" "cairo_move_to" [ "cairo_t*" "double" "double" ] alien-invoke ;
-
-: cairo_new_sub_path ( cairo_t -- )
-    "void" "cairo" "cairo_new_sub_path" [ "cairo_t*" ] alien-invoke ;
-    
-: cairo_line_to ( cairo_t x y -- )
-    "void" "cairo" "cairo_line_to" [ "cairo_t*" "double" "double" ] alien-invoke ;
-
-: cairo_curve_to ( cairo_t x1 y1 x2 y2 x3 y3 -- )
-    "void" "cairo" "cairo_curve_to" [ "cairo_t*" "double" "double" "double" "double" "double" "double" ] alien-invoke ;
-
-: cairo_arc ( cairo_t xc yc radius angle1 angle2 -- )
-    "void" "cairo" "cairo_arc" [ "cairo_t*" "double" "double" "double" "double" "double" ] alien-invoke ;
-
-: cairo_arc_negative ( cairo_t xc yc radius angle1 angle2 -- )
-    "void" "cairo" "cairo_arc_negative" [ "cairo_t*" "double" "double" "double" "double" "double" ] alien-invoke ;
-    
-: cairo_rel_move_to ( cairo_t dx dy -- )
-    "void" "cairo" "cairo_rel_move_to" [ "cairo_t*" "double" "double" ] alien-invoke ;
-    
-: cairo_rel_line_to ( cairo_t dx dy -- )
-    "void" "cairo" "cairo_rel_line_to" [ "cairo_t*" "double" "double" ] alien-invoke ;
-
-: cairo_rel_curve_to ( cairo_t dx1 dy1 dx2 dy2 dx3 dy3 -- )
-    "void" "cairo" "cairo_rel_curve_to" [ "cairo_t*" "double" "double" "double" "double" "double" "double" ] alien-invoke ;
-
-: cairo_rectangle ( cairo_t x y width height -- )
-    "void" "cairo" "cairo_rectangle" [ "cairo_t*" "double" "double" "double" "double" ] alien-invoke ;
-
-: cairo_close_path ( cairo_t -- )
-    "void" "cairo" "cairo_close_path" [ "cairo_t*" ] alien-invoke ;
-
-! Surface manipulation
-
-: cairo_surface_create_similar ( cairo_surface_t cairo_content_t width height -- cairo_surface_t )
-    "cairo_surface_t*" "cairo" "cairo_surface_create_similar" [ "cairo_surface_t*" "uint" "int" "int" ] alien-invoke ;
-
-: cairo_surface_reference ( cairo_surface_t -- cairo_surface_t )
-    "cairo_surface_t*" "cairo" "cairo_surface_reference" [ "cairo_surface_t*" ] alien-invoke ;
-
-: cairo_surface_finish ( cairo_surface_t -- )
-    "void" "cairo" "cairo_surface_finish" [ "cairo_surface_t*" ] alien-invoke ;
-
-: cairo_surface_destroy ( cairo_surface_t -- )
-    "void" "cairo" "cairo_surface_destroy" [ "cairo_surface_t*" ] alien-invoke ;
-
-: cairo_surface_get_reference_count ( cairo_surface_t -- count )
-    "uint" "cairo" "cairo_surface_get_reference_count" [ "cairo_surface_t*" ] alien-invoke ;
-
-: cairo_surface_status ( cairo_surface_t -- cairo_status_t )
-    "uint" "cairo" "cairo_surface_status" [ "cairo_surface_t*" ] alien-invoke ;
-
-: cairo_surface_flush ( cairo_surface_t -- )
-    "void" "cairo" "cairo_surface_flush" [ "cairo_surface_t*" ] alien-invoke ;
-
-! painting functions
-: cairo_paint ( cairo_t -- )
-    "void" "cairo" "cairo_paint" [ "cairo_t*" ] alien-invoke ;
-
-: cairo_paint_with_alpha ( cairo_t alpha -- )
-    "void" "cairo" "cairo_paint_with_alpha" [ "cairo_t*" "double" ] alien-invoke ;
-
-: cairo_mask ( cairo_t cairo_pattern_t -- )
-    "void" "cairo" "cairo_mask" [ "cairo_t*" "void*" ] alien-invoke ;
-
-: cairo_mask_surface ( cairo_t cairo_pattern_t surface-x surface-y -- )
-    "void" "cairo" "cairo_mask_surface" [ "cairo_t*" "void*" "double" "double" ] alien-invoke ;
-
-: cairo_stroke ( cairo_t -- )
-    "void" "cairo" "cairo_stroke" [ "cairo_t*" ] alien-invoke ;
-
-: cairo_stroke_preserve ( cairo_t -- )
-    "void" "cairo" "cairo_stroke_preserve" [ "cairo_t*" ] alien-invoke ;
-
-: cairo_fill ( cairo_t -- )
-    "void" "cairo" "cairo_fill" [ "cairo_t*" ] alien-invoke ;
-
-: cairo_fill_preserve ( cairo_t -- )
-    "void" "cairo" "cairo_fill_preserve" [ "cairo_t*" ] alien-invoke ;
-
-: cairo_copy_page ( cairo_t -- )
-    "void" "cairo" "cairo_copy_page" [ "cairo_t*" ] alien-invoke ;
-
-: cairo_show_page ( cairo_t -- )
-    "void" "cairo" "cairo_show_page" [ "cairo_t*" ] alien-invoke ;
-
-! insideness testing
-: cairo_in_stroke ( cairo_t x y -- t/f )
-    "int" "cairo" "cairo_in_stroke" [ "cairo_t*" "double" "double" ] alien-invoke ;
-
-: cairo_in_fill ( cairo_t x y -- t/f )
-    "int" "cairo" "cairo_in_fill" [ "cairo_t*" "double" "double" ] alien-invoke ;
-
-! rectangular extents
-: cairo_stroke_extents ( cairo_t x1 y1 x2 y2 -- )
-    "void" "cairo" "cairo_stroke_extents" [ "cairo_t*" "double" "double" "double" "double" ] alien-invoke ;
-
-: cairo_fill_extents ( cairo_t x1 y1 x2 y2 -- )
-    "void" "cairo" "cairo_fill_extents" [ "cairo_t*" "double" "double" "double" "double" ] alien-invoke ;
-
-! clipping
-: cairo_reset_clip ( cairo_t -- )
-    "void" "cairo" "cairo_reset_clip" [ "cairo_t*" ] alien-invoke ;
-
-: cairo_clip ( cairo_t -- )
-    "void" "cairo" "cairo_clip" [ "cairo_t*" ] alien-invoke ;
-
-: cairo_clip_preserve ( cairo_t -- )
-    "void" "cairo" "cairo_clip_preserve" [ "cairo_t*" ] alien-invoke ;
-
-
-: cairo_pattern_create_linear ( x0 y0 x1 y1 -- cairo_pattern_t )
-    "void*" "cairo" "cairo_pattern_create_linear" [ "double" "double" "double" "double" ] alien-invoke ;
-
-: cairo_pattern_create_radial ( cx0 cy0 radius0 cx1 cy1 radius1 -- cairo_pattern_t )
-    "void*" "cairo" "cairo_pattern_create_radial" [ "double" "double" "double" "double" "double" "double" ] alien-invoke ;
-
-: cairo_pattern_add_color_stop_rgba ( pattern offset red green blue alpha -- status )
-    "uint" "cairo" "cairo_pattern_add_color_stop_rgba" [ "void*" "double" "double" "double" "double" "double" ] alien-invoke ;
-
-: cairo_show_text ( cairo_t msg_utf8 -- )
-    "void" "cairo" "cairo_show_text" [ "cairo_t*" "char*" ] alien-invoke ;
-
-: cairo_text_path ( cairo_t msg_utf8 -- )
-    "void" "cairo" "cairo_text_path" [ "cairo_t*" "char*" ] alien-invoke ;
-
-: cairo_select_font_face ( cairo_t family font_slant font_weight -- )
-    "void" "cairo" "cairo_select_font_face" [ "cairo_t*" "char*" "uint" "uint" ] alien-invoke ;
-
-: cairo_set_font_size ( cairo_t scale -- )
-    "void" "cairo" "cairo_set_font_size" [ "cairo_t*" "double" ] alien-invoke ;
-
-: cairo_set_font_matrix ( cairo_t cairo_matrix_t -- )
-        "void" "cairo" "cairo_set_font_matrix" [ "cairo_t*" "cairo_matrix_t*" ] alien-invoke ;
-
-: cairo_get_font_matrix ( cairo_t cairo_matrix_t -- )
-        "void" "cairo" "cairo_get_font_matrix" [ "cairo_t*" "cairo_matrix_t*" ] alien-invoke ;
-
-FUNCTION: uchar* cairo_image_surface_get_data ( cairo_surface_t* surface ) ;
-FUNCTION: cairo_format_t cairo_image_surface_get_format ( cairo_surface_t* surface ) ;
-FUNCTION: int cairo_image_surface_get_width ( cairo_surface_t* surface ) ;
-FUNCTION: int cairo_image_surface_get_height ( cairo_surface_t* surface ) ;
-FUNCTION: int cairo_image_surface_get_stride ( cairo_surface_t* surface ) ;
-
-! Cairo pdf
-
-: cairo_pdf_surface_create ( filename width height -- surface )
-  "void*" "cairo" "cairo_pdf_surface_create" [ "char*" "double" "double" ] alien-invoke ;
-
-! Missing:
-
-! cairo_public cairo_surface_t *
-! cairo_pdf_surface_create_for_stream (cairo_write_func_t write_func,
-!                                      void              *closure,
-!                                      double             width_in_points,
-!                                      double             height_in_points);
-
-: cairo_pdf_surface_set_size ( surface width height -- )
-  "void" "cairo" "cairo_pdf_surface_set_size" [ "void*" "double" "double" ] alien-invoke ;
-
-! Cairo png
-
-TYPEDEF: void* cairo_write_func_t
-TYPEDEF: void* cairo_read_func_t
-
-FUNCTION: cairo_surface_t* cairo_image_surface_create_from_png ( char* filename ) ;
-
-FUNCTION: cairo_surface_t* cairo_image_surface_create_from_png_stream ( cairo_read_func_t read_func, void* closure ) ;
-
-FUNCTION: cairo_status_t cairo_surface_write_to_png ( cairo_surface_t* surface, char* filename ) ;
-
-FUNCTION: cairo_status_t cairo_surface_write_to_png_stream ( cairo_surface_t* surface, cairo_write_func_t write_func, void* closure ) ;
diff --git a/extra/cairo/ffi/ffi.factor b/extra/cairo/ffi/ffi.factor
new file mode 100644 (file)
index 0000000..d7aa90c
--- /dev/null
@@ -0,0 +1,459 @@
+! Bindings for Cairo library
+!  Copyright (c) 2007 Sampo Vuori
+!    License: http://factorcode.org/license.txt
+
+! Unimplemented:
+!  - most of the font stuff
+!  - most of the matrix stuff
+!  - most of the query functions
+
+
+USING: alien alien.syntax combinators system ;
+
+IN: cairo.ffi
+
+<< "cairo" {
+        { [ win32? ] [ "cairo.dll" ] }
+        ! { [ macosx? ] [ "libcairo.dylib" ] }
+        { [ macosx? ] [ "/opt/local/lib/libcairo.dylib" ] }
+        { [ unix? ] [ "libcairo.so.2" ] }
+  } cond "cdecl" add-library >>
+
+LIBRARY: cairo
+
+TYPEDEF: int cairo_status_t
+C-ENUM:
+    CAIRO_STATUS_SUCCESS
+    CAIRO_STATUS_NO_MEMORY
+    CAIRO_STATUS_INVALID_RESTORE
+    CAIRO_STATUS_INVALID_POP_GROUP
+    CAIRO_STATUS_NO_CURRENT_POINT
+    CAIRO_STATUS_INVALID_MATRIX
+    CAIRO_STATUS_INVALID_STATUS
+    CAIRO_STATUS_NULL_POINTER
+    CAIRO_STATUS_INVALID_STRING
+    CAIRO_STATUS_INVALID_PATH_DATA
+    CAIRO_STATUS_READ_ERROR
+    CAIRO_STATUS_WRITE_ERROR
+    CAIRO_STATUS_SURFACE_FINISHED
+    CAIRO_STATUS_SURFACE_TYPE_MISMATCH
+    CAIRO_STATUS_PATTERN_TYPE_MISMATCH
+    CAIRO_STATUS_INVALID_CONTENT
+    CAIRO_STATUS_INVALID_FORMAT
+    CAIRO_STATUS_INVALID_VISUAL
+    CAIRO_STATUS_FILE_NOT_FOUND
+    CAIRO_STATUS_INVALID_DASH
+    CAIRO_STATUS_INVALID_DSC_COMMENT
+    CAIRO_STATUS_INVALID_INDEX
+    CAIRO_STATUS_CLIP_NOT_REPRESENTABLE
+;
+
+TYPEDEF: int cairo_content_t
+: CAIRO_CONTENT_COLOR HEX: 1000 ;
+: CAIRO_CONTENT_ALPHA HEX: 2000 ;
+: CAIRO_CONTENT_COLOR_ALPHA HEX: 3000 ;
+
+TYPEDEF: int cairo_operator_t
+C-ENUM:
+    CAIRO_OPERATOR_CLEAR
+    CAIRO_OPERATOR_SOURCE
+    CAIRO_OPERATOR_OVER
+    CAIRO_OPERATOR_IN
+    CAIRO_OPERATOR_OUT
+    CAIRO_OPERATOR_ATOP
+    CAIRO_OPERATOR_DEST
+    CAIRO_OPERATOR_DEST_OVER
+    CAIRO_OPERATOR_DEST_IN
+    CAIRO_OPERATOR_DEST_OUT
+    CAIRO_OPERATOR_DEST_ATOP
+    CAIRO_OPERATOR_XOR
+    CAIRO_OPERATOR_ADD
+    CAIRO_OPERATOR_SATURATE
+;
+
+TYPEDEF: int cairo_line_cap_t
+C-ENUM:
+    CAIRO_LINE_CAP_BUTT
+    CAIRO_LINE_CAP_ROUND
+    CAIRO_LINE_CAP_SQUARE
+;
+
+TYPEDEF: int cair_line_join_t
+C-ENUM:
+    CAIRO_LINE_JOIN_MITER
+    CAIRO_LINE_JOIN_ROUND
+    CAIRO_LINE_JOIN_BEVEL
+;
+
+TYPEDEF: int cairo_fill_rule_t
+C-ENUM:
+    CAIRO_FILL_RULE_WINDING
+    CAIRO_FILL_RULE_EVEN_ODD
+;
+
+TYPEDEF: int cairo_font_slant_t
+C-ENUM:
+    CAIRO_FONT_SLANT_NORMAL
+    CAIRO_FONT_SLANT_ITALIC
+    CAIRO_FONT_SLANT_OBLIQUE
+;
+
+TYPEDEF: int cairo_font_weight_t
+C-ENUM:
+    CAIRO_FONT_WEIGHT_NORMAL
+    CAIRO_FONT_WEIGHT_BOLD
+;
+
+C-STRUCT: cairo_font_t
+    { "int" "refcount" }
+    { "uint" "scale" } ;
+
+C-STRUCT: cairo_rectangle_t
+    { "short" "x" }
+    { "short" "y" }
+    { "ushort" "width" }
+    { "ushort" "height" } ;
+
+C-STRUCT: cairo_clip_rec_t
+    { "cairo_rectangle_t" "rect" }
+    { "void*" "region" }
+    { "void*" "surface" } ;
+
+C-STRUCT: cairo_matrix_t
+    { "void*" "m" } ;
+
+C-STRUCT: cairo_gstate_t
+    { "uint" "operator" }
+    { "double" "tolerance" }
+    { "double" "line_width" }
+    { "uint" "line_cap" }
+    { "uint" "line_join" }
+    { "double" "miter_limit" }
+    { "uint" "fill_rule" }
+    { "void*" "dash" }
+    { "int" "num_dashes" }
+    { "double" "dash_offset" }
+    { "char*" "font_family " }
+    { "uint" "font_slant" }
+    { "uint" "font_weight" }
+    { "void*" "font" }
+    { "void*" "surface" }
+    { "void*" "pattern " }
+    { "double" "alpha" }
+    { "cairo_clip_rec_t" "clip" }
+    { "double" "pixels_per_inch" }
+    { "cairo_matrix_t" "font_matrix" }
+    { "cairo_matrix_t" "ctm" }
+    { "cairo_matrix_t" "ctm_inverse" }
+    { "void*" "path" }
+    { "void*" "pen_regular" }
+    { "void*" "next" } ;
+
+C-STRUCT: cairo_t
+    { "uint" "ref_count" }
+    { "cairo_gstate_t*" "gstate" }
+    { "uint" "status ! cairo_status_t" } ;
+
+C-STRUCT: cairo_matrix_t
+        { "double" "xx" }
+        { "double" "yx" }
+        { "double" "xy" }
+        { "double" "yy" }
+        { "double" "x0" }
+        { "double" "y0" } ;
+
+TYPEDEF: int cairo_format_t
+C-ENUM:
+    CAIRO_FORMAT_ARGB32
+    CAIRO_FORMAT_RGB24
+    CAIRO_FORMAT_A8
+    CAIRO_FORMAT_A1
+;
+
+TYPEDEF: int cairo_antialias_t
+C-ENUM:
+    CAIRO_ANTIALIAS_DEFAULT
+    CAIRO_ANTIALIAS_NONE
+    CAIRO_ANTIALIAS_GRAY
+    CAIRO_ANTIALIAS_SUBPIXEL
+;
+
+TYPEDEF: int cairo_subpixel_order_t
+C-ENUM:
+    CAIRO_SUBPIXEL_ORDER_DEFAULT
+    CAIRO_SUBPIXEL_ORDER_RGB
+    CAIRO_SUBPIXEL_ORDER_BGR
+    CAIRO_SUBPIXEL_ORDER_VRGB
+    CAIRO_SUBPIXEL_ORDER_VBGR
+;
+
+TYPEDEF: int cairo_hint_style_t
+C-ENUM:
+    CAIRO_HINT_STYLE_DEFAULT
+    CAIRO_HINT_STYLE_NONE
+    CAIRO_HINT_STYLE_SLIGHT
+    CAIRO_HINT_STYLE_MEDIUM
+    CAIRO_HINT_STYLE_FULL
+;
+
+TYPEDEF: int cairo_hint_metrics_t
+C-ENUM:
+    CAIRO_HINT_METRICS_DEFAULT
+    CAIRO_HINT_METRICS_OFF
+    CAIRO_HINT_METRICS_ON
+;
+
+: cairo_create ( cairo_surface_t -- cairo_t )
+    "cairo_t*" "cairo" "cairo_create" [ "void*" ] alien-invoke ;
+
+: cairo_reference ( cairo_t -- cairo_t )
+        "cairo_t*" "cairo" "cairo_reference" [ "cairo_t*" ] alien-invoke ;
+
+: cairo_destroy ( cairo_t -- )
+    "void" "cairo" "cairo_destroy" [ "cairo_t*" ] alien-invoke ;
+
+: cairo_save ( cairo_t -- )
+        "void" "cairo" "cairo_save" [ "cairo_t*" ] alien-invoke ;
+
+: cairo_restore ( cairo_t -- )
+        "void" "cairo" "cairo_restore" [ "cairo_t*" ] alien-invoke ;
+
+: cairo_set_operator ( cairo_t cairo_operator_t -- )
+    "void" "cairo" "cairo_set_operator" [ "cairo_t*" "int" ] alien-invoke ;
+
+: cairo_set_source ( cairo_t cairo_pattern_t -- )
+    "void" "cairo" "cairo_set_source" [ "cairo_t*" "void*" ] alien-invoke ;
+
+: cairo_set_source_rgb ( cairo_t red green blue -- )
+    "void" "cairo" "cairo_set_source_rgb" [ "cairo_t*" "double" "double" "double" ] alien-invoke ;
+
+: cairo_set_source_rgba ( cairo_t red green blue alpha -- )
+    "void" "cairo" "cairo_set_source_rgb" [ "cairo_t*" "double" "double" "double" "double" ] alien-invoke ;
+
+: cairo_set_source_surface ( cairo_t cairo_surface_t x y -- )
+    "void" "cairo" "cairo_set_source_surface" [ "cairo_t*" "void*" "double" "double" ] alien-invoke ;
+
+: cairo_set_tolerance ( cairo_t tolerance -- )
+    "void" "cairo" "cairo_set_tolerance" [ "cairo_t*" "double" ] alien-invoke ;
+
+: cairo_image_surface_create_for_data ( data format width height stride -- cairo_surface_t )
+    "void*" "cairo" "cairo_image_surface_create_for_data" [ "void*" "uint" "int" "int" "int" ] alien-invoke ;
+    
+
+: cairo_set_antialias ( cairo_t cairo_antialias_t -- )
+    "void" "cairo" "cairo_set_antialias" [ "cairo_t*" "int" ] alien-invoke ;
+
+: cairo_set_fill_rule ( cairo_t cairo_fill_rule_t -- )
+    "void" "cairo" "cairo_set_fill_rule" [ "cairo_t*" "int" ] alien-invoke ;
+
+: cairo_set_line_width ( cairo_t width -- )
+    "void" "cairo" "cairo_set_line_width" [ "cairo_t*" "double" ] alien-invoke ;
+
+: cairo_set_line_cap ( cairo_t cairo_line_cap_t -- )
+    "void" "cairo" "cairo_set_line_cap" [ "cairo_t*" "int" ] alien-invoke ;
+
+: cairo_set_line_join ( cairo_t cairo_line_join_t -- )
+    "void" "cairo" "cairo_set_line_join" [ "cairo_t*" "int" ] alien-invoke ;
+
+: cairo_set_dash ( cairo_t dashes num_dashes offset -- )
+    "void" "cairo" "cairo_set_dash" [ "cairo_t*" "double" "int" "double" ] alien-invoke ;
+
+: cairo_set_miter_limit ( cairo_t limit -- )
+    "void" "cairo" "cairo_set_miter_limit" [ "cairo_t*" "double" ] alien-invoke ;
+
+: cairo_translate ( cairo_t x y -- )
+    "void" "cairo" "cairo_translate" [ "cairo_t*" "double" "double" ] alien-invoke ;
+
+: cairo_scale ( cairo_t sx sy -- )
+    "void" "cairo" "cairo_scale" [ "cairo_t*" "double" "double" ] alien-invoke ;
+
+: cairo_rotate ( cairo_t angle -- )
+    "void" "cairo" "cairo_rotate" [ "cairo_t*" "double" ] alien-invoke ;
+
+: cairo_transform ( cairo_t cairo_matrix_t -- )
+        "void" "cairo" "cairo_transform" [ "cairo_t*" "cairo_matrix_t*" ] alien-invoke ;
+
+: cairo_set_matrix ( cairo_t cairo_matrix_t -- )
+        "void" "cairo" "cairo_set_matrix" [ "cairo_t*" "cairo_matrix_t*" ] alien-invoke ;
+
+: cairo_identity_matrix ( cairo_t -- )
+        "void" "cairo" "cairo_identity_matrix" [ "cairo_t*" ] alien-invoke ;
+
+! cairo path creating functions
+
+: cairo_new_path ( cairo_t -- )
+    "void" "cairo" "cairo_new_path" [ "cairo_t*" ] alien-invoke ;
+
+: cairo_move_to ( cairo_t x y -- )
+    "void" "cairo" "cairo_move_to" [ "cairo_t*" "double" "double" ] alien-invoke ;
+
+: cairo_new_sub_path ( cairo_t -- )
+    "void" "cairo" "cairo_new_sub_path" [ "cairo_t*" ] alien-invoke ;
+    
+: cairo_line_to ( cairo_t x y -- )
+    "void" "cairo" "cairo_line_to" [ "cairo_t*" "double" "double" ] alien-invoke ;
+
+: cairo_curve_to ( cairo_t x1 y1 x2 y2 x3 y3 -- )
+    "void" "cairo" "cairo_curve_to" [ "cairo_t*" "double" "double" "double" "double" "double" "double" ] alien-invoke ;
+
+: cairo_arc ( cairo_t xc yc radius angle1 angle2 -- )
+    "void" "cairo" "cairo_arc" [ "cairo_t*" "double" "double" "double" "double" "double" ] alien-invoke ;
+
+: cairo_arc_negative ( cairo_t xc yc radius angle1 angle2 -- )
+    "void" "cairo" "cairo_arc_negative" [ "cairo_t*" "double" "double" "double" "double" "double" ] alien-invoke ;
+    
+: cairo_rel_move_to ( cairo_t dx dy -- )
+    "void" "cairo" "cairo_rel_move_to" [ "cairo_t*" "double" "double" ] alien-invoke ;
+    
+: cairo_rel_line_to ( cairo_t dx dy -- )
+    "void" "cairo" "cairo_rel_line_to" [ "cairo_t*" "double" "double" ] alien-invoke ;
+
+: cairo_rel_curve_to ( cairo_t dx1 dy1 dx2 dy2 dx3 dy3 -- )
+    "void" "cairo" "cairo_rel_curve_to" [ "cairo_t*" "double" "double" "double" "double" "double" "double" ] alien-invoke ;
+
+: cairo_rectangle ( cairo_t x y width height -- )
+    "void" "cairo" "cairo_rectangle" [ "cairo_t*" "double" "double" "double" "double" ] alien-invoke ;
+
+: cairo_close_path ( cairo_t -- )
+    "void" "cairo" "cairo_close_path" [ "cairo_t*" ] alien-invoke ;
+
+! Surface manipulation
+
+: cairo_surface_create_similar ( cairo_surface_t cairo_content_t width height -- cairo_surface_t )
+    "cairo_surface_t*" "cairo" "cairo_surface_create_similar" [ "cairo_surface_t*" "uint" "int" "int" ] alien-invoke ;
+
+: cairo_surface_reference ( cairo_surface_t -- cairo_surface_t )
+    "cairo_surface_t*" "cairo" "cairo_surface_reference" [ "cairo_surface_t*" ] alien-invoke ;
+
+: cairo_surface_finish ( cairo_surface_t -- )
+    "void" "cairo" "cairo_surface_finish" [ "cairo_surface_t*" ] alien-invoke ;
+
+: cairo_surface_destroy ( cairo_surface_t -- )
+    "void" "cairo" "cairo_surface_destroy" [ "cairo_surface_t*" ] alien-invoke ;
+
+: cairo_surface_get_reference_count ( cairo_surface_t -- count )
+    "uint" "cairo" "cairo_surface_get_reference_count" [ "cairo_surface_t*" ] alien-invoke ;
+
+: cairo_surface_status ( cairo_surface_t -- cairo_status_t )
+    "uint" "cairo" "cairo_surface_status" [ "cairo_surface_t*" ] alien-invoke ;
+
+: cairo_surface_flush ( cairo_surface_t -- )
+    "void" "cairo" "cairo_surface_flush" [ "cairo_surface_t*" ] alien-invoke ;
+
+! painting functions
+: cairo_paint ( cairo_t -- )
+    "void" "cairo" "cairo_paint" [ "cairo_t*" ] alien-invoke ;
+
+: cairo_paint_with_alpha ( cairo_t alpha -- )
+    "void" "cairo" "cairo_paint_with_alpha" [ "cairo_t*" "double" ] alien-invoke ;
+
+: cairo_mask ( cairo_t cairo_pattern_t -- )
+    "void" "cairo" "cairo_mask" [ "cairo_t*" "void*" ] alien-invoke ;
+
+: cairo_mask_surface ( cairo_t cairo_pattern_t surface-x surface-y -- )
+    "void" "cairo" "cairo_mask_surface" [ "cairo_t*" "void*" "double" "double" ] alien-invoke ;
+
+: cairo_stroke ( cairo_t -- )
+    "void" "cairo" "cairo_stroke" [ "cairo_t*" ] alien-invoke ;
+
+: cairo_stroke_preserve ( cairo_t -- )
+    "void" "cairo" "cairo_stroke_preserve" [ "cairo_t*" ] alien-invoke ;
+
+: cairo_fill ( cairo_t -- )
+    "void" "cairo" "cairo_fill" [ "cairo_t*" ] alien-invoke ;
+
+: cairo_fill_preserve ( cairo_t -- )
+    "void" "cairo" "cairo_fill_preserve" [ "cairo_t*" ] alien-invoke ;
+
+: cairo_copy_page ( cairo_t -- )
+    "void" "cairo" "cairo_copy_page" [ "cairo_t*" ] alien-invoke ;
+
+: cairo_show_page ( cairo_t -- )
+    "void" "cairo" "cairo_show_page" [ "cairo_t*" ] alien-invoke ;
+
+! insideness testing
+: cairo_in_stroke ( cairo_t x y -- t/f )
+    "int" "cairo" "cairo_in_stroke" [ "cairo_t*" "double" "double" ] alien-invoke ;
+
+: cairo_in_fill ( cairo_t x y -- t/f )
+    "int" "cairo" "cairo_in_fill" [ "cairo_t*" "double" "double" ] alien-invoke ;
+
+! rectangular extents
+: cairo_stroke_extents ( cairo_t x1 y1 x2 y2 -- )
+    "void" "cairo" "cairo_stroke_extents" [ "cairo_t*" "double" "double" "double" "double" ] alien-invoke ;
+
+: cairo_fill_extents ( cairo_t x1 y1 x2 y2 -- )
+    "void" "cairo" "cairo_fill_extents" [ "cairo_t*" "double" "double" "double" "double" ] alien-invoke ;
+
+! clipping
+: cairo_reset_clip ( cairo_t -- )
+    "void" "cairo" "cairo_reset_clip" [ "cairo_t*" ] alien-invoke ;
+
+: cairo_clip ( cairo_t -- )
+    "void" "cairo" "cairo_clip" [ "cairo_t*" ] alien-invoke ;
+
+: cairo_clip_preserve ( cairo_t -- )
+    "void" "cairo" "cairo_clip_preserve" [ "cairo_t*" ] alien-invoke ;
+
+
+: cairo_pattern_create_linear ( x0 y0 x1 y1 -- cairo_pattern_t )
+    "void*" "cairo" "cairo_pattern_create_linear" [ "double" "double" "double" "double" ] alien-invoke ;
+
+: cairo_pattern_create_radial ( cx0 cy0 radius0 cx1 cy1 radius1 -- cairo_pattern_t )
+    "void*" "cairo" "cairo_pattern_create_radial" [ "double" "double" "double" "double" "double" "double" ] alien-invoke ;
+
+: cairo_pattern_add_color_stop_rgba ( pattern offset red green blue alpha -- status )
+    "uint" "cairo" "cairo_pattern_add_color_stop_rgba" [ "void*" "double" "double" "double" "double" "double" ] alien-invoke ;
+
+: cairo_show_text ( cairo_t msg_utf8 -- )
+    "void" "cairo" "cairo_show_text" [ "cairo_t*" "char*" ] alien-invoke ;
+
+: cairo_text_path ( cairo_t msg_utf8 -- )
+    "void" "cairo" "cairo_text_path" [ "cairo_t*" "char*" ] alien-invoke ;
+
+: cairo_select_font_face ( cairo_t family font_slant font_weight -- )
+    "void" "cairo" "cairo_select_font_face" [ "cairo_t*" "char*" "uint" "uint" ] alien-invoke ;
+
+: cairo_set_font_size ( cairo_t scale -- )
+    "void" "cairo" "cairo_set_font_size" [ "cairo_t*" "double" ] alien-invoke ;
+
+: cairo_set_font_matrix ( cairo_t cairo_matrix_t -- )
+        "void" "cairo" "cairo_set_font_matrix" [ "cairo_t*" "cairo_matrix_t*" ] alien-invoke ;
+
+: cairo_get_font_matrix ( cairo_t cairo_matrix_t -- )
+        "void" "cairo" "cairo_get_font_matrix" [ "cairo_t*" "cairo_matrix_t*" ] alien-invoke ;
+
+FUNCTION: uchar* cairo_image_surface_get_data ( cairo_surface_t* surface ) ;
+FUNCTION: cairo_format_t cairo_image_surface_get_format ( cairo_surface_t* surface ) ;
+FUNCTION: int cairo_image_surface_get_width ( cairo_surface_t* surface ) ;
+FUNCTION: int cairo_image_surface_get_height ( cairo_surface_t* surface ) ;
+FUNCTION: int cairo_image_surface_get_stride ( cairo_surface_t* surface ) ;
+
+! Cairo pdf
+
+: cairo_pdf_surface_create ( filename width height -- surface )
+  "void*" "cairo" "cairo_pdf_surface_create" [ "char*" "double" "double" ] alien-invoke ;
+
+! Missing:
+
+! cairo_public cairo_surface_t *
+! cairo_pdf_surface_create_for_stream (cairo_write_func_t write_func,
+!                                      void              *closure,
+!                                      double             width_in_points,
+!                                      double             height_in_points);
+
+: cairo_pdf_surface_set_size ( surface width height -- )
+  "void" "cairo" "cairo_pdf_surface_set_size" [ "void*" "double" "double" ] alien-invoke ;
+
+! Cairo png
+
+TYPEDEF: void* cairo_write_func_t
+TYPEDEF: void* cairo_read_func_t
+
+FUNCTION: cairo_surface_t* cairo_image_surface_create_from_png ( char* filename ) ;
+
+FUNCTION: cairo_surface_t* cairo_image_surface_create_from_png_stream ( cairo_read_func_t read_func, void* closure ) ;
+
+FUNCTION: cairo_status_t cairo_surface_write_to_png ( cairo_surface_t* surface, char* filename ) ;
+
+FUNCTION: cairo_status_t cairo_surface_write_to_png_stream ( cairo_surface_t* surface, cairo_write_func_t write_func, void* closure ) ;
diff --git a/extra/cairo/lib/lib.factor b/extra/cairo/lib/lib.factor
new file mode 100644 (file)
index 0000000..9e226ee
--- /dev/null
@@ -0,0 +1,40 @@
+! Copyright (C) 2008 Doug Coleman.
+! See http://factorcode.org/license.txt for BSD license.
+USING: alien.c-types cairo.ffi continuations destructors
+kernel libc locals math combinators.cleave shuffle new-slots
+accessors ;
+IN: cairo.lib
+
+TUPLE: cairo-t alien ;
+C: <cairo-t> cairo-t
+M: cairo-t dispose ( alien -- ) alien>> cairo_destroy ;
+: cairo-t-destroy-always ( alien -- ) <cairo-t> add-always-destructor ;
+: cairo-t-destroy-later ( alien -- ) <cairo-t> add-error-destructor ;
+    
+TUPLE: cairo-surface-t alien ;
+C: <cairo-surface-t> cairo-surface-t
+M: cairo-surface-t dispose ( alien -- ) alien>> cairo_surface_destroy ;
+
+: cairo-surface-t-destroy-always ( alien -- )
+    <cairo-surface-t> add-always-destructor ;
+
+: cairo-surface-t-destroy-later ( alien -- )
+    <cairo-surface-t> add-error-destructor ;
+
+: cairo-surface>array ( surface -- cairo-t byte-array )
+    [
+        dup
+        [ drop CAIRO_FORMAT_ARGB32 ]
+        [ cairo_image_surface_get_width ]
+        [ cairo_image_surface_get_height ] tri
+        over 4 *
+        2dup * [
+            malloc dup free-always [
+                5 -nrot cairo_image_surface_create_for_data
+                dup cairo-surface-t-destroy-always
+                cairo_create dup cairo-t-destroy-later
+                [ swap 0 0 cairo_set_source_surface ] keep
+                dup cairo_paint
+            ] keep
+        ] keep memory>byte-array
+    ] with-destructors ;
diff --git a/extra/cairo/png/png.factor b/extra/cairo/png/png.factor
new file mode 100644 (file)
index 0000000..b9da140
--- /dev/null
@@ -0,0 +1,45 @@
+! Copyright (C) 2008 Doug Coleman.
+! See http://factorcode.org/license.txt for BSD license.
+USING: arrays combinators.cleave kernel new-slots
+accessors math ui.gadgets ui.render opengl.gl byte-arrays
+namespaces opengl cairo.ffi cairo.lib ;
+IN: cairo.png
+
+TUPLE: png surface width height cairo-t array ;
+TUPLE: png-gadget png ;
+
+: <png> ( path -- png )
+    cairo_image_surface_create_from_png
+    dup [ cairo_image_surface_get_width ]
+    [ cairo_image_surface_get_height ] [ ] tri
+    cairo-surface>array png construct-boa ;
+
+: write-png ( png path -- )
+    >r png-surface r>
+    cairo_surface_write_to_png
+    zero? [ "write png failed" throw ] unless ;
+
+: <png-gadget> ( path -- gadget )
+    png-gadget construct-gadget swap
+    <png> >>png ;
+
+M: png-gadget pref-dim* ( gadget -- )
+    png>>
+    [ width>> ] [ height>> ] bi 2array ;
+
+M: png-gadget draw-gadget* ( gadget -- )
+    origin get [
+        0 0 glRasterPos2i
+        1.0 -1.0 glPixelZoom
+        png>>
+        [ width>> ]
+        [ height>> GL_RGBA GL_UNSIGNED_BYTE ]
+        [ array>> ] tri
+        glDrawPixels
+    ] with-translation ;
+
+M: png-gadget graft* ( gadget -- )
+    drop ;
+
+M: png-gadget ungraft* ( gadget -- )
+    png>> surface>> cairo_destroy ;
index 0c491b88b1688cb6a51167b54f7ef2158e2e8455..46e9abcd9ffa1ed1a2584f826b67fb403f9a90a8 100644 (file)
@@ -7,9 +7,18 @@ IN: combinators.cleave
 
 ARTICLE: "cleave-combinators" "Cleave Combinators"
 
+"Basic cleavers:"
+
 { $subsection bi  }
 { $subsection tri }
 
+"General cleave: "
+{ $subsection cleave }
+
+"Cleave combinators for quotations with arity 2:"
+{ $subsection 2bi  }
+{ $subsection 2tri }
+
 { $notes
   "From the Merriam-Webster Dictionary: "
   $nl
@@ -49,10 +58,21 @@ HELP: tri
 
 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
 
+HELP: cleave
+
+{ $code "( obj { q1 q2 ... qN } -- q1(obj) q2(obj) ... qN(obj) )" } ;
+
+! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+
+{ bi tri cleave 2bi 2tri } related-words
+
+! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+
 ARTICLE: "spread-combinators" "Spread Combinators"
 
 { $subsection bi* }
-{ $subsection tri* } ;
+{ $subsection tri* }
+{ $subsection spread } ;
 
 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
 
@@ -80,3 +100,9 @@ HELP: tri*
             { "p(x)" "p applied to x" }
             { "q(y)" "q applied to y" }
             { "r(z)" "r applied to z" } } ;
+
+! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+
+HELP: spread
+
+{ $code "( v1 v2 ... vN { q1 q2 ... qN } -- q1(v1) q2(v2) ... qN(vN) )" } ;
\ No newline at end of file
index 5359512610ab63cc4c63b8a1a31fa05cb6f32301..049c8bf2a94245db39e587569c6992cef494ad6e 100644 (file)
@@ -15,7 +15,10 @@ IN: combinators.cleave
 
 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
 
-: 2bi ( obj obj quot quot -- val val ) >r 2keep r> call ; inline
+: 2bi ( x y p q -- p(x,y) q(x,y) ) >r 2keep r> call ; inline
+
+: 2tri ( x y z p q r -- p(x,y,z) q(x,y,z) r(x,y,z) )
+  >r >r 2keep r> 2keep r> call ; inline
 
 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
 
@@ -33,6 +36,18 @@ MACRO: cleave ( seq -- )
     [ drop ]
   append ;
 
+MACRO: 2cleave ( seq -- )
+  dup
+    [ drop [ 2dup ] ] map concat
+  swap
+  dup
+    [ drop [ >r >r ] ] map concat
+  swap
+    [ [ r> r> ] append ] map concat
+  3append
+    [ 2drop ]
+  append ;
+
 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
 ! The spread family
 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
@@ -55,3 +70,29 @@ MACRO: spread ( seq -- )
   swap
     [ [ r> ] swap append ] map concat
   append ;
+
+! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+! Cleave into array
+! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+
+USING: words quotations fry arrays.lib ;
+
+: >quot ( obj -- quot ) dup word? [ 1quotation ] when ;
+
+: >quots ( seq -- seq ) [ >quot ] map ;
+
+MACRO: <arr> ( seq -- )
+  [ >quots ] [ length ] bi
+ '[ , cleave , narray ] ;
+
+MACRO: <2arr> ( seq -- )
+  [ >quots ] [ length ] bi
+ '[ , 2cleave , narray ] ;
+
+! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+! Spread into array
+! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+
+MACRO: <arr*> ( seq -- )
+  [ >quots ] [ length ] bi
+ '[ , spread , narray ] ;
index f65b94dc115a680f86d04fdc1332794029880b98..7c93f805cd6175fadc55cc742d46387666b715bd 100755 (executable)
@@ -133,9 +133,6 @@ MACRO: parallel-call ( quots -- )
 : (make-call-with) ( quots -- quot ) 
     [ [ keep ] curry ] map concat [ drop ] append ;
 
-MACRO: call-with ( quots -- )
-    (make-call-with) ;
-
 MACRO: map-call-with ( quots -- )
     [ (make-call-with) ] keep length [ narray ] curry compose ;
 
@@ -143,9 +140,6 @@ MACRO: map-call-with ( quots -- )
     [ [ 2dup >r >r ] swap append [ r> r> ] append ] map concat
     [ 2drop ] append ;
 
-MACRO: call-with2 ( quots -- )
-    (make-call-with2) ;
-
 MACRO: map-call-with2 ( quots -- )
     [ (make-call-with2) ] keep length [ narray ] curry append ;
 
diff --git a/extra/db/db-tests.factor b/extra/db/db-tests.factor
new file mode 100755 (executable)
index 0000000..9c32f9e
--- /dev/null
@@ -0,0 +1,5 @@
+IN: db.tests\r
+USING: tools.test db kernel ;\r
+\r
+{ 1 0 } [ [ drop ] query-each ] must-infer-as\r
+{ 1 1 } [ [ ] query-map ] must-infer-as\r
index 26b6cbe75c49e631bce7be4cb70acba874a28c4f..b2042c98bd2404c65d3deed091a69114a31f2c5c 100755 (executable)
@@ -119,8 +119,8 @@ M: postgresql-db bind% ( spec -- )
 
 : postgresql-make ( class quot -- )
     >r sql-props r>
-    [ postgresql-counter off ] swap compose
-    { "" { } { } } nmake <postgresql-statement> ;
+    [ postgresql-counter off call ] { "" { } { } } nmake
+    <postgresql-statement> ; inline
 
 : create-table-sql ( class -- statement )
     [
index 63bce0a8c3520250cc0b316c6ae506b6ad833b07..1d356b15921a4f6f0ca8daeb592156d1326b858e 100755 (executable)
@@ -127,6 +127,6 @@ FUNCTION: char* sqlite3_column_decltype ( sqlite3_stmt* pStmt, int col ) ;
 FUNCTION: int sqlite3_column_int ( sqlite3_stmt* pStmt, int col ) ;
 FUNCTION: sqlite3_int64 sqlite3_column_int64 ( sqlite3_stmt* pStmt, int col ) ;
 FUNCTION: double sqlite3_column_double ( sqlite3_stmt* pStmt, int col ) ;
-FUNCTION: int sqlite3_column_name ( sqlite3_stmt* pStmt, int col ) ;
+FUNCTION: char* sqlite3_column_name ( sqlite3_stmt* pStmt, int col ) ;
 FUNCTION: char* sqlite3_column_text ( sqlite3_stmt* pStmt, int col ) ;
 FUNCTION: int sqlite3_column_type ( sqlite3_stmt* pStmt, int col ) ;
index dbada854fbff974632a76cce672e971cb5554f1b..d630522eb86becfa0bce40e2c180f49f36155d75 100755 (executable)
@@ -102,17 +102,10 @@ IN: db.sqlite.lib
         [ no-sql-type ]
     } case ;
 
-: sqlite-finalize ( handle -- )
-    sqlite3_finalize sqlite-check-result ;
-
-: sqlite-reset ( handle -- )
-    sqlite3_reset sqlite-check-result ;
-
-: sqlite-#columns ( query -- int )
-    sqlite3_column_count ;
-
-: sqlite-column ( handle index -- string )
-    sqlite3_column_text ;
+: sqlite-finalize ( handle -- ) sqlite3_finalize sqlite-check-result ;
+: sqlite-reset ( handle -- ) sqlite3_reset sqlite-check-result ;
+: sqlite-#columns ( query -- int ) sqlite3_column_count ;
+: sqlite-column ( handle index -- string ) sqlite3_column_text ;
 
 : sqlite-column-blob ( handle index -- byte-array/f )
     [ sqlite3_column_bytes ] 2keep
index b72d7886052ab05386257ffd5e91c6f8aa52df6a..3466301390f6c487eab245feb83cd9b217d6c9c6 100755 (executable)
@@ -17,16 +17,11 @@ M: sqlite-db db-open ( db -- )
     dup sqlite-db-path sqlite-open <db>
     swap set-delegate ;
 
-M: sqlite-db db-close ( handle -- )
-    sqlite-close ;
-
+M: sqlite-db db-close ( handle -- ) sqlite-close ;
 M: sqlite-db dispose ( db -- ) dispose-db ;
-
-: with-sqlite ( path quot -- )
-    sqlite-db swap with-db ; inline
+: with-sqlite ( path quot -- ) sqlite-db swap with-db ; inline
 
 TUPLE: sqlite-statement ;
-
 TUPLE: sqlite-result-set has-more? ;
 
 M: sqlite-db <simple-statement> ( str in out -- obj )
@@ -51,8 +46,7 @@ M: sqlite-result-set dispose ( result-set -- )
 : sqlite-bind ( triples handle -- )
     swap [ first3 sqlite-bind-type ] with each ;
 
-: reset-statement ( statement -- )
-    statement-handle sqlite-reset ;
+: reset-statement ( statement -- ) statement-handle sqlite-reset ;
 
 M: sqlite-statement bind-statement* ( statement -- )
     dup statement-bound? [ dup reset-statement ] when
@@ -98,18 +92,13 @@ M: sqlite-statement query-results ( query -- result-set )
     dup statement-handle sqlite-result-set <result-set>
     dup advance-row ;
 
-M: sqlite-db begin-transaction ( -- )
-    "BEGIN" sql-command ;
-
-M: sqlite-db commit-transaction ( -- )
-    "COMMIT" sql-command ;
-
-M: sqlite-db rollback-transaction ( -- )
-    "ROLLBACK" sql-command ;
+M: sqlite-db begin-transaction ( -- ) "BEGIN" sql-command ;
+M: sqlite-db commit-transaction ( -- ) "COMMIT" sql-command ;
+M: sqlite-db rollback-transaction ( -- ) "ROLLBACK" sql-command ;
 
 : sqlite-make ( class quot -- )
     >r sql-props r>
-    { "" { } { } } nmake <simple-statement> ;
+    { "" { } { } } nmake <simple-statement> ; inline
 
 M: sqlite-db create-sql-statement ( class -- statement )
     [
@@ -123,9 +112,7 @@ M: sqlite-db create-sql-statement ( class -- statement )
     ] sqlite-make ;
 
 M: sqlite-db drop-sql-statement ( class -- statement )
-    [
-        "drop table " 0% 0% ";" 0% drop
-    ] sqlite-make ;
+    [ "drop table " 0% 0% ";" 0% drop ] sqlite-make ;
 
 M: sqlite-db <insert-native-statement> ( tuple -- statement )
     [
@@ -195,10 +182,9 @@ M: sqlite-db modifier-table ( -- hashtable )
         { +not-null+ "not null" }
     } ;
 
-M: sqlite-db compound-modifier ( str obj -- newstr )
-    compound-type ;
+M: sqlite-db compound-modifier ( str obj -- str' ) compound-type ;
 
-M: sqlite-db compound-type ( str seq -- newstr )
+M: sqlite-db compound-type ( str seq -- str' )
     over {
         { "default" [ first number>string join-space ] }
         [ 2drop ] !  "no sqlite compound data type" 3array throw ]
@@ -219,5 +205,4 @@ M: sqlite-db type-table ( -- assoc )
         { FACTOR-BLOB "blob" }
     } ;
 
-M: sqlite-db create-type-table
-    type-table ;
+M: sqlite-db create-type-table ( symbol -- str ) type-table ;
index 584282e1c8bab07f7ba61b88ff67ac39c024602c..ba6441bc53e4a19e748c45e78c1609c78eed9816 100755 (executable)
@@ -30,9 +30,11 @@ SYMBOL: person3
 SYMBOL: person4
 
 : test-tuples ( -- )
-    [ person drop-table ] [ drop ] recover
+    [ ] [ person ensure-table ] unit-test
+    [ ] [ person drop-table ] unit-test
     [ ] [ person create-table ] unit-test
     [ person create-table ] must-fail
+    [ ] [ person ensure-table ] unit-test
     
     [ ] [ person1 get insert-tuple ] unit-test
 
@@ -191,8 +193,8 @@ TUPLE: annotation n paste-id summary author mode contents ;
 [ native-person-schema test-tuples ] test-sqlite
 [ assigned-person-schema test-tuples ] test-sqlite
 
-[ native-person-schema test-tuples ] test-postgresql
-[ assigned-person-schema test-tuples ] test-postgresql
+[ native-person-schema test-tuples ] test-postgresql
+[ assigned-person-schema test-tuples ] test-postgresql
 
 TUPLE: serialize-me id data ;
 
@@ -211,7 +213,7 @@ TUPLE: serialize-me id data ;
     ] [ T{ serialize-me f 1 } select-tuples ] unit-test ;
 
 [ test-serialize ] test-sqlite
-[ test-serialize ] test-postgresql
+[ test-serialize ] test-postgresql
 
 TUPLE: exam id name score ; 
 
@@ -237,3 +239,9 @@ TUPLE: exam id name score ;
     ;
 
 ! [ test-ranges ] test-sqlite
+
+\ insert-tuple must-infer
+\ update-tuple must-infer
+\ delete-tuple must-infer
+\ select-tuple must-infer
+\ define-persistent must-infer
index 32055ccedc35b84795238362e3f6678cbc709ce2..d50e42c0fb6f853e7ab580f493cb6f0c76d54176 100755 (executable)
@@ -3,7 +3,8 @@
 USING: arrays assocs classes db kernel namespaces
 tuples words sequences slots math
 math.parser io prettyprint db.types continuations
-mirrors sequences.lib tools.walker combinators.lib ;
+mirrors sequences.lib tools.walker combinators.lib
+combinators.cleave ;
 IN: db.tuples
 
 : define-persistent ( class table columns -- )
@@ -35,7 +36,7 @@ HOOK: <update-tuples-statement> db ( class -- obj )
 HOOK: <delete-tuple-statement> db ( class -- obj )
 HOOK: <delete-tuples-statement> db ( class -- obj )
 
-HOOK: <select-by-slots-statement> db ( tuple -- tuple )
+HOOK: <select-by-slots-statement> db ( tuple class -- tuple )
 
 HOOK: insert-tuple* db ( tuple statement -- )
 
@@ -73,6 +74,9 @@ HOOK: insert-tuple* db ( tuple statement -- )
 : drop-table ( class -- )
     drop-sql-statement [ execute-statement ] with-disposals ;
 
+: ensure-table ( class -- )
+    [ dup drop-table ] ignore-errors create-table ;
+
 : insert-native ( tuple -- )
     dup class
     db get db-insert-statements [ <insert-native-statement> ] cache
index b2561c74395af64d16c2392b2c43da1ea36cdf10..1b98d2ee0d88561ff39026402643622d8258c4ef 100755 (executable)
@@ -26,11 +26,14 @@ M: destructor dispose
 : add-always-destructor ( obj -- )
     <destructor> always-destructors get push ;
 
+: dispose-each ( seq -- )
+    <reversed> [ dispose ] each ;
+
 : do-always-destructors ( -- )
-    always-destructors get [ dispose ] each ;
+    always-destructors get dispose-each ;
 
 : do-error-destructors ( -- )
-    error-destructors get [ dispose ] each ;
+    error-destructors get dispose-each ;
 
 : with-destructors ( quot -- )
     [
index 3b65466225dde5d7682682c14b44087be2701bb6..4ee906bccbb224ed0a92f0257ba9f995d6925342 100755 (executable)
@@ -1,7 +1,7 @@
 ! Copyright (C) 2005, 2007 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
 USING: parser kernel namespaces sequences definitions io.files
-inspector continuations tuples tools.crossref tools.browser 
+inspector continuations tuples tools.crossref tools.vocabs 
 io prettyprint source-files assocs vocabs vocabs.loader ;
 IN: editors
 
@@ -13,8 +13,7 @@ M: no-edit-hook summary
 SYMBOL: edit-hook
 
 : available-editors ( -- seq )
-    "editors" all-child-vocabs
-    values concat [ vocab-name ] map ;
+    "editors" all-child-vocabs-seq [ vocab-name ] map ;
 
 : editor-restarts ( -- alist )
     available-editors
index 45d19cb891c752fb1ba024dc511fd364264be78f..2341aabc9ddf302ff44eb74f7b1c7d92f8365835 100755 (executable)
@@ -1,14 +1,14 @@
 USING: tools.deploy.config ;
 H{
-    { deploy-io 2 }
-    { deploy-math? f }
-    { deploy-threads? f }
-    { deploy-compiler? f }
-    { deploy-word-props? f }
-    { deploy-word-defs? f }
     { deploy-name "Hello world (console)" }
-    { deploy-reflection 2 }
+    { deploy-threads? f }
     { deploy-c-types? f }
+    { deploy-compiler? f }
     { deploy-ui? f }
+    { deploy-math? f }
+    { deploy-reflection 1 }
+    { deploy-word-defs? f }
+    { deploy-io 2 }
+    { deploy-word-props? f }
     { "stop-after-last-window?" t }
 }
index 72b300b58587e37462f8a7a4924bfdab860178c5..319dd1586badb563814b2c1e1909cbff9ce251ee 100755 (executable)
@@ -199,7 +199,7 @@ ARTICLE: "cookbook-io" "Input and output cookbook"
 }
 "Convert a file of 4-byte cells from little to big endian or vice versa, by directly mapping it into memory and operating on it with sequence words:"
 { $code
-    "\"mydata.dat\" dup file-length ["
+    "\"mydata.dat\" dup file-info file-info-length ["
     "    4 <sliced-groups> [ reverse-here ] change-each"
     "] with-mapped-file"
 }
index d77cc9268d80404393eb8d9da8583c6a3d128e2c..1310b581338f470e7933825044a485100d52f1f2 100755 (executable)
@@ -196,6 +196,7 @@ ARTICLE: "io" "Input and output"
 { $subsection "io.timeouts" } ;
 
 ARTICLE: "tools" "Developer tools"
+{ $subsection "tools.vocabs" }
 "Exploratory tools:"
 { $subsection "editor" }
 { $subsection "tools.crossref" }
old mode 100644 (file)
new mode 100755 (executable)
index 22a1945..d8a4f83
@@ -1,7 +1,7 @@
 ! Copyright (C) 2006, 2007 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
 USING: sequences parser kernel help help.markup help.topics
-words strings classes tools.browser namespaces io
+words strings classes tools.vocabs namespaces io
 io.streams.string prettyprint definitions arrays vectors
 combinators splitting debugger hashtables sorting effects vocabs
 vocabs.loader assocs editors continuations classes.predicate
index d81e9cd81e4e01f7d17be8af768c68a7013b39a7..710671857e871e02cb6da3401a9e710ff693bccf 100755 (executable)
@@ -169,7 +169,8 @@ M: f print-element drop ;
         ] if
     ] ($subsection) ;
 
-: $vocab-link ( element -- ) first dup ($vocab-link) ;
+: $vocab-link ( element -- )
+    first dup vocab-name swap ($vocab-link) ;
 
 : $vocabulary ( element -- )
     first word-vocabulary [
old mode 100644 (file)
new mode 100755 (executable)
index c5abc19..4a86d49
@@ -7,6 +7,10 @@ IN: help.topics
 
 TUPLE: link name ;
 
+MIXIN: topic
+INSTANCE: link topic
+INSTANCE: word topic
+
 GENERIC: >link ( obj -- obj )
 M: link >link ;
 M: vocab-spec >link ;
index f6b1faf3852b390681af44aeba0c519fc5ca07b4..f01840d9272d8c41e61c80b596894fe5b65a1d4d 100755 (executable)
@@ -1,6 +1,6 @@
 USING: help.markup help.syntax ui.commands ui.operations
 ui.tools.search ui.tools.workspace editors vocabs.loader
-kernel sequences prettyprint tools.test strings
+kernel sequences prettyprint tools.test tools.vocabs strings
 unicode.categories unicode.case ;
 IN: help.tutorial
 
index 661f63ab599f8fa4d470fc6369f9532d2c20bb1a..0f684f782af39a08cca1770eba11c4b9e8568f9d 100755 (executable)
@@ -18,6 +18,7 @@ tuple-syntax namespaces ;
         port: 80
         version: "1.1"
         cookies: V{ }
+        header: H{ }
     }
 ] [
     [
index ee0d5f7f3b192516e7aebf75b24841affb9cc9f2..6d875ef5608e5e8d591b87f0b296839cacc6a8f1 100755 (executable)
@@ -95,5 +95,4 @@ PRIVATE>
     swap >>post-data-type ;
 
 : http-post ( content-type content url -- response string )
-    #! The content is URL encoded for you.
-    >r url-encode r> <post-request> http-request contents ;
+    <post-request> http-request contents ;
index c72a631d16a90c6951c0879ec720a905a3a42682..421a40963907d4c043a3151218c126dbbeec9b22 100755 (executable)
@@ -4,7 +4,8 @@ USING: fry hashtables io io.streams.string kernel math
 namespaces math.parser assocs sequences strings splitting ascii
 io.encodings.utf8 io.encodings.string namespaces unicode.case
 combinators vectors sorting new-slots accessors calendar
-calendar.format quotations arrays ;
+calendar.format quotations arrays combinators.cleave
+combinators.lib byte-arrays ;
 IN: http
 
 : http-port 80 ; inline
@@ -12,18 +13,21 @@ IN: http
 : url-quotable? ( ch -- ? )
     #! In a URL, can this character be used without
     #! URL-encoding?
-    dup letter?
-    over LETTER? or
-    over digit? or
-    swap "/_-." member? or ; foldable
+    {
+        [ dup letter? ]
+        [ dup LETTER? ]
+        [ dup digit? ]
+        [ dup "/_-.:" member? ]
+    } || nip ; foldable
 
 : push-utf8 ( ch -- )
-    1string utf8 encode [ CHAR: % , >hex 2 CHAR: 0 pad-left % ] each ;
+    1string utf8 encode
+    [ CHAR: % , >hex 2 CHAR: 0 pad-left % ] each ;
 
 : url-encode ( str -- str )
-    [ [
-        dup url-quotable? [ , ] [ push-utf8 ] if
-    ] each ] "" make ;
+    [
+        [ dup url-quotable? [ , ] [ push-utf8 ] if ] each
+    ] "" make ;
 
 : url-decode-hex ( index str -- )
     2dup length 2 - >= [
@@ -108,7 +112,12 @@ IN: http
     ] when ;
 
 : assoc>query ( hash -- str )
-    [ [ url-encode ] 2apply "=" swap 3append ] { } assoc>map
+    [
+        [ url-encode ]
+        [ dup number? [ number>string ] when url-encode ]
+        bi*
+        "=" swap 3append
+    ] { } assoc>map
     "&" join ;
 
 TUPLE: cookie name value path domain expires http-only ;
@@ -169,10 +178,11 @@ cookies ;
 
 : <request>
     request construct-empty
-    "1.1" >>version
-    http-port >>port
-    H{ } clone >>query
-    V{ } clone >>cookies ;
+        "1.1" >>version
+        http-port >>port
+        H{ } clone >>header
+        H{ } clone >>query
+        V{ } clone >>cookies ;
 
 : query-param ( request key -- value )
     swap query>> at ;
@@ -245,6 +255,10 @@ SYMBOL: max-post-request
 : extract-post-data-type ( request -- request )
     dup "content-type" header >>post-data-type ;
 
+: parse-post-data ( request -- request )
+    dup post-data-type>> "application/x-www-form-urlencoded" =
+    [ dup post-data>> query>assoc >>post-data ] when ;
+
 : extract-cookies ( request -- request )
     dup "cookie" header [ parse-cookies >>cookies ] when* ;
 
@@ -257,24 +271,31 @@ SYMBOL: max-post-request
     read-post-data
     extract-host
     extract-post-data-type
+    parse-post-data
     extract-cookies ;
 
 : write-method ( request -- request )
     dup method>> write bl ;
 
-: write-url ( request -- request )
-    dup path>> url-encode write
-    dup query>> dup assoc-empty? [ drop ] [
-        "?" write
-        assoc>query write
-    ] if ;
+: (link>string) ( url query -- url' )
+    [ url-encode ] [ assoc>query ] bi*
+    dup empty? [ drop ] [ "?" swap 3append ] if ;
+
+: write-url ( request -- )
+    [ path>> ] [ query>> ] bi (link>string) write ;
 
 : write-request-url ( request -- request )
-    write-url bl ;
+    dup write-url bl ;
 
 : write-version ( request -- request )
     "HTTP/" write dup request-version write crlf ;
 
+: unparse-post-data ( request -- request )
+    dup post-data>> dup sequence? [ drop ] [
+        assoc>query >>post-data
+        "application/x-www-form-urlencoded" >>post-data-type
+    ] if ;
+
 : write-request-header ( request -- request )
     dup header>> >hashtable
     over host>> [ "host" pick set-at ] when*
@@ -287,6 +308,7 @@ SYMBOL: max-post-request
     dup post-data>> [ write ] when* ;
 
 : write-request ( request -- )
+    unparse-post-data
     write-method
     write-request-url
     write-version
@@ -297,15 +319,16 @@ SYMBOL: max-post-request
 
 : request-url ( request -- url )
     [
-        dup host>> [
-            "http://" write
-            dup host>> url-encode write
-            ":" write
-            dup port>> number>string write
-        ] when
-        dup path>> "/" head? [ "/" write ] unless
-        write-url
-        drop
+        [
+            dup host>> [
+                [ "http://" write host>> url-encode write ]
+                [ ":" write port>> number>string write ]
+                bi
+            ] [ drop ] if
+        ]
+        [ path>> "/" head? [ "/" write ] unless ]
+        [ write-url ]
+        tri
     ] with-string-writer ;
 
 : set-header ( request/response value key -- request/response )
index 98a92e083aa7be75af5ad14cf989aaa3b790ef34..c604b8a4270becea3ff5a9f53db82a3a1f4303bf 100755 (executable)
@@ -1,11 +1,16 @@
 IN: http.server.actions.tests
-USING: http.server.actions tools.test math math.parser
-multiline namespaces http io.streams.string http.server
-sequences accessors ;
+USING: http.server.actions http.server.validators
+tools.test math math.parser multiline namespaces http
+io.streams.string http.server sequences accessors ;
+
+[
+    "a" [ v-number ] { { "a" "123" } } validate-param
+    [ 123 ] [ "a" get ] unit-test
+] with-scope
 
 <action>
     [ "a" get "b" get + ] >>display
-    { { "a" [ string>number ] } { "b" [ string>number ] } } >>get-params
+    { { "a" [ v-number ] } { "b" [ v-number ] } } >>get-params
 "action-1" set
 
 STRING: action-request-test-1
@@ -23,12 +28,13 @@ blah
 
 <action>
     [ +path+ get "xxx" get "X" <repetition> concat append ] >>submit
-    { { +path+ [ ] } { "xxx" [ string>number ] } } >>post-params
+    { { +path+ [ ] } { "xxx" [ v-number ] } } >>post-params
 "action-2" set
 
 STRING: action-request-test-2
 POST http://foo/bar/baz HTTP/1.1
 content-length: 5
+content-type: application/x-www-form-urlencoded
 
 xxx=4
 ;
index bab55eef0c5adb41a4b5ae571c48000a63531548..91671392c7e8c059a02caedd951fefe1656c7804 100755 (executable)
@@ -2,7 +2,7 @@
 ! See http://factorcode.org/license.txt for BSD license.\r
 USING: accessors new-slots sequences kernel assocs combinators\r
 http.server http.server.validators http hashtables namespaces\r
-combinators.cleave fry continuations ;\r
+combinators.cleave fry continuations locals ;\r
 IN: http.server.actions\r
 \r
 SYMBOL: +path+\r
@@ -17,25 +17,13 @@ TUPLE: action init display submit get-params post-params ;
         [ <400> ] >>display\r
         [ <400> ] >>submit ;\r
 \r
-: extract-params ( path -- assoc )\r
-    +path+ associate\r
-    request get dup method>> {\r
-        { "GET" [ query>> ] }\r
-        { "HEAD" [ query>> ] }\r
-        { "POST" [ post-data>> query>assoc ] }\r
-    } case union ;\r
-\r
-: with-validator ( string quot -- result error? )\r
-    '[ , @ f ] [\r
-        dup validation-error? [ t ] [ rethrow ] if\r
-    ] recover ; inline\r
-\r
-: validate-param ( name validator assoc -- error? )\r
-    swap pick\r
-    >r >r at r> with-validator swap r> set ;\r
+:: validate-param ( name validator assoc -- )\r
+    name assoc at validator with-validator name set ; inline\r
 \r
 : action-params ( validators -- error? )\r
-    [ params get validate-param ] { } assoc>map [ ] contains? ;\r
+    validation-failed? off\r
+    params get '[ , validate-param ] assoc-each\r
+    validation-failed? get ;\r
 \r
 : handle-get ( -- response )\r
     action get get-params>> action-params [ <400> ] [\r
@@ -50,12 +38,10 @@ TUPLE: action init display submit get-params post-params ;
     action get display>> call exit-with ;\r
 \r
 M: action call-responder ( path action -- response )\r
-    [ extract-params params set ]\r
-    [\r
-        action set\r
-        request get method>> {\r
-            { "GET" [ handle-get ] }\r
-            { "HEAD" [ handle-get ] }\r
-            { "POST" [ handle-post ] }\r
-        } case\r
-    ] bi* ;\r
+    [ +path+ associate request-params union params set ]\r
+    [ action set ] bi*\r
+    request get method>> {\r
+        { "GET" [ handle-get ] }\r
+        { "HEAD" [ handle-get ] }\r
+        { "POST" [ handle-post ] }\r
+    } case ;\r
diff --git a/extra/http/server/auth/login/edit-profile.fhtml b/extra/http/server/auth/login/edit-profile.fhtml
new file mode 100755 (executable)
index 0000000..7d94ca1
--- /dev/null
@@ -0,0 +1,77 @@
+<% USING: http.server.components http.server.auth.login\r
+http.server namespaces kernel combinators ; %>\r
+<html>\r
+<body>\r
+<h1>Edit profile</h1>\r
+\r
+<form method="POST" action="edit-profile">\r
+<% hidden-form-field %>\r
+\r
+<table>\r
+\r
+<tr>\r
+<td>User name:</td>\r
+<td><% "username" component render-view %></td>\r
+</tr>\r
+\r
+<tr>\r
+<td>Real name:</td>\r
+<td><% "realname" component render-edit %></td>\r
+</tr>\r
+\r
+<tr>\r
+<td></td>\r
+<td>Specifying a real name is optional.</td>\r
+</tr>\r
+\r
+<tr>\r
+<td>Current password:</td>\r
+<td><% "password" component render-edit %></td>\r
+</tr>\r
+\r
+<tr>\r
+<td></td>\r
+<td>If you don't want to change your current password, leave this field blank.</td>\r
+</tr>\r
+\r
+<tr>\r
+<td>New password:</td>\r
+<td><% "new-password" component render-edit %></td>\r
+</tr>\r
+\r
+<tr>\r
+<td>Verify:</td>\r
+<td><% "verify-password" component render-edit %></td>\r
+</tr>\r
+\r
+<tr>\r
+<td></td>\r
+<td>If you are changing your password, enter it twice to ensure it is correct.</td>\r
+</tr>\r
+\r
+<tr>\r
+<td>E-mail:</td>\r
+<td><% "email" component render-edit %></td>\r
+</tr>\r
+\r
+<tr>\r
+<td></td>\r
+<td>Specifying an e-mail address is optional. It enables the "recover password" feature.</td>\r
+</tr>\r
+\r
+</table>\r
+\r
+<p><input type="submit" value="Update" />\r
+\r
+<% {\r
+    { [ login-failed? get ] [ "invalid password" render-error ] }\r
+    { [ password-mismatch? get ] [ "passwords do not match" render-error ] }\r
+    { [ t ] [ ] }\r
+} cond %>\r
+\r
+</p>\r
+\r
+</form>\r
+\r
+</body>\r
+</html>\r
index 7d92c727c6986d56c6795198aea167c6a6bc3741..a1c99f749c91bc26c5ee19c56128e70a7a0ec3aa 100755 (executable)
@@ -13,6 +13,8 @@ QUALIFIED: smtp
 \r
 TUPLE: login users ;\r
 \r
+: users login get users>> ;\r
+\r
 SYMBOL: post-login-url\r
 SYMBOL: login-failed?\r
 \r
@@ -30,7 +32,8 @@ SYMBOL: login-failed?
 \r
 : successful-login ( user -- response )\r
     logged-in-user sset\r
-    post-login-url sget f <permanent-redirect> ;\r
+    post-login-url sget "" or f <permanent-redirect>\r
+    f post-login-url sset ;\r
 \r
 :: <login-action> ( -- action )\r
     [let | form [ <login-form> ] |\r
@@ -48,7 +51,7 @@ SYMBOL: login-failed?
                 form validate-form\r
 \r
                 "password" value "username" value\r
-                login get users>> check-login [\r
+                users check-login [\r
                     successful-login\r
                 ] [\r
                     login-failed? on\r
@@ -66,7 +69,7 @@ SYMBOL: login-failed?
             t >>required\r
             add-field\r
         "realname" <string> add-field\r
-        "password" <password>\r
+        "new-password" <password>\r
             t >>required\r
             add-field\r
         "verify-password" <password>\r
@@ -79,7 +82,7 @@ SYMBOL: password-mismatch?
 SYMBOL: user-exists?\r
 \r
 : same-password-twice ( -- )\r
-    "password" value "verify-password" value = [ \r
+    "new-password" value "verify-password" value = [ \r
         password-mismatch? on\r
         validation-failed\r
     ] unless ;\r
@@ -101,14 +104,13 @@ SYMBOL: user-exists?
 \r
                 same-password-twice\r
 \r
-                <user> values get [\r
-                    "username" get >>username\r
-                    "realname" get >>realname\r
-                    "password" get >>password\r
-                    "email" get >>email\r
-                ] bind\r
+                <user>\r
+                    "username" value >>username\r
+                    "realname" value >>realname\r
+                    "new-password" value >>password\r
+                    "email" value >>email\r
 \r
-                login get users>> new-user [\r
+                users new-user [\r
                     user-exists? on\r
                     validation-failed\r
                 ] unless*\r
@@ -117,6 +119,64 @@ SYMBOL: user-exists?
             ] >>submit\r
     ] ;\r
 \r
+! ! ! Editing user profile\r
+\r
+: <edit-profile-form> ( -- form )\r
+    "edit-profile" <form>\r
+        "resource:extra/http/server/auth/login/edit-profile.fhtml" >>edit-template\r
+        "username" <username> add-field\r
+        "realname" <string> add-field\r
+        "password" <password> add-field\r
+        "new-password" <password> add-field\r
+        "verify-password" <password> add-field\r
+        "email" <email> add-field ;\r
+\r
+SYMBOL: previous-page\r
+\r
+:: <edit-profile-action> ( -- action )\r
+    [let | form [ <edit-profile-form> ] |\r
+        <action>\r
+            [\r
+                blank-values\r
+                logged-in-user sget\r
+                dup username>> "username" set-value\r
+                dup realname>> "realname" set-value\r
+                dup email>> "email" set-value\r
+            ] >>init\r
+\r
+            [\r
+                "text/html" <content>\r
+                [ form edit-form ] >>body\r
+            ] >>display\r
+\r
+            [\r
+                blank-values\r
+                uid "username" set-value\r
+\r
+                form validate-form\r
+\r
+                "password" value empty? [\r
+                    logged-in-user sget\r
+                ] [\r
+                    same-password-twice\r
+\r
+                    "password" value uid users check-login\r
+                    [ login-failed? on validation-failed ] unless\r
+\r
+                    "new-password" value uid users set-password\r
+                    [ "User deleted" throw ] unless*\r
+                ] if\r
+\r
+                "realname" value >>realname\r
+                "email" value >>email\r
+\r
+                dup users update-user\r
+                logged-in-user sset\r
+\r
+                previous-page sget f <permanent-redirect>\r
+            ] >>submit\r
+    ] ;\r
+\r
 ! ! ! Password recovery\r
 \r
 SYMBOL: lost-password-from\r
@@ -185,7 +245,7 @@ SYMBOL: lost-password-from
                 form validate-form\r
 \r
                 "email" value "username" value\r
-                login get users>> issue-ticket [\r
+                users issue-ticket [\r
                     send-password-email\r
                 ] when*\r
 \r
@@ -199,7 +259,7 @@ SYMBOL: lost-password-from
         "username" <username> <hidden>\r
             t >>required\r
             add-field\r
-        "password" <password>\r
+        "new-password" <password>\r
             t >>required\r
             add-field\r
         "verify-password" <password>\r
@@ -238,9 +298,9 @@ SYMBOL: lost-password-from
 \r
                 "ticket" value\r
                 "username" value\r
-                login get users>> claim-ticket [\r
-                    "password" value >>password\r
-                    login get users>> update-user\r
+                users claim-ticket [\r
+                    "new-password" value >>password\r
+                    users update-user\r
 \r
                     "resource:extra/http/server/auth/login/recover-4.fhtml"\r
                     serve-template\r
@@ -264,13 +324,18 @@ TUPLE: protected responder ;
 \r
 C: <protected> protected\r
 \r
+: show-login-page ( -- response )\r
+    request get request-url post-login-url sset\r
+    "login" f <permanent-redirect> ;\r
+\r
 M: protected call-responder ( path responder -- response )\r
-    logged-in-user sget [ responder>> call-responder ] [\r
+    logged-in-user sget [\r
+        request get request-url previous-page sset\r
+        responder>> call-responder\r
+    ] [\r
         2drop\r
-        request get method>> { "GET" "HEAD" } member? [\r
-            request get request-url post-login-url sset\r
-            "login" f <permanent-redirect>\r
-        ] [ <400> ] if\r
+        request get method>> { "GET" "HEAD" } member?\r
+        [ show-login-page ] [ <400> ] if\r
     ] if ;\r
 \r
 M: login call-responder ( path responder -- response )\r
@@ -282,10 +347,13 @@ M: login call-responder ( path responder -- response )
         swap <protected> >>default\r
         <login-action> "login" add-responder\r
         <logout-action> "logout" add-responder\r
-        no >>users ;\r
+        no-users >>users ;\r
 \r
 ! ! ! Configuration\r
 \r
+: allow-edit-profile ( login -- login )\r
+    <edit-profile-action> <protected> "edit-profile" add-responder ;\r
+\r
 : allow-registration ( login -- login )\r
     <register-action> "register" add-responder ;\r
 \r
@@ -293,6 +361,9 @@ M: login call-responder ( path responder -- response )
     <recover-action-1> "recover-password" add-responder\r
     <recover-action-3> "new-password" add-responder ;\r
 \r
+: allow-edit-profile? ( -- ? )\r
+    login get responders>> "edit-profile" swap key? ;\r
+\r
 : allow-registration? ( -- ? )\r
     login get responders>> "register" swap key? ;\r
 \r
index 8e879420a98d7920e5cd12ab1b292a0ed6340d09..07201719e56d6ce73997742eb5d74c7b35405213 100755 (executable)
@@ -1,10 +1,13 @@
-<% USING: http.server.auth.login http.server.components kernel\r
-namespaces ; %>\r
+<% USING: http.server.auth.login http.server.components http.server\r
+kernel namespaces ; %>\r
 <html>\r
 <body>\r
 <h1>Login required</h1>\r
 \r
 <form method="POST" action="login">\r
+\r
+<% hidden-form-field %>\r
+\r
 <table>\r
 \r
 <tr>\r
@@ -30,10 +33,12 @@ login-failed? get
 \r
 <p>\r
 <% allow-registration? [ %>\r
-    <a href="register">Register</a>\r
+    <a href="<% "register" f write-link %>">Register</a>\r
 <% ] when %>\r
 <% allow-password-recovery? [ %>\r
-    <a href="recover-password">Recover Password</a>\r
+    <a href="<% "recover-password" f write-link %>">\r
+       Recover Password\r
+    </a>\r
 <% ] when %>\r
 </p>\r
 \r
index 3e8448f64b71d0819ed7e819d3d6342bc1443fcc..8ec01f22e9d0bf36d0a1b9fa67e8df3d12292386 100755 (executable)
@@ -1,4 +1,4 @@
-<% USING: http.server.components ; %>\r
+<% USING: http.server.components http.server ; %>\r
 <html>\r
 <body>\r
 <h1>Recover lost password: step 1 of 4</h1>\r
@@ -6,6 +6,9 @@
 <p>Enter the username and e-mail address you used to register for this site, and you will receive a link for activating a new password.</p>\r
 \r
 <form method="POST" action="recover-password">\r
+\r
+<% hidden-form-field %>\r
+\r
 <table>\r
 \r
 <tr>\r
index b220cc4f75ec91ce197f2874e3d5190e149379e2..ca4823baab53a06713eab0db5ab1ba01c2560e89 100755 (executable)
@@ -1,4 +1,4 @@
-<% USING: http.server.components http.server.auth.login\r
+<% USING: http.server.components http.server.auth.login http.server\r
 namespaces kernel combinators ; %>\r
 <html>\r
 <body>\r
@@ -7,6 +7,9 @@ namespaces kernel combinators ; %>
 <p>Choose a new password for your account.</p>\r
 \r
 <form method="POST" action="new-password">\r
+\r
+<% hidden-form-field %>\r
+\r
 <table>\r
 \r
 <% "username" component render-edit %>\r
@@ -14,7 +17,7 @@ namespaces kernel combinators ; %>
 \r
 <tr>\r
 <td>Password:</td>\r
-<td><% "password" component render-edit %></td>\r
+<td><% "new-password" component render-edit %></td>\r
 </tr>\r
 \r
 <tr>\r
@@ -32,7 +35,7 @@ namespaces kernel combinators ; %>
 <p><input type="submit" value="Set password" />\r
 \r
 <% password-mismatch? get [\r
-"passwords do not match" render-error\r
+    "passwords do not match" render-error\r
 ] when %>\r
 \r
 </p>\r
index dec7a5404f599a4822c661b9f54317bbdffad4fd..239d71d293415e7208453c3307d5f3ec3f793cc4 100755 (executable)
@@ -1,10 +1,10 @@
-<% USING: http.server.components http.server.auth.login\r
-namespaces kernel combinators ; %>\r
+<% USING: http.server ; %>\r
 <html>\r
 <body>\r
 <h1>Recover lost password: step 4 of 4</h1>\r
 \r
-<p>Your password has been reset. You may now <a href="login">log in</a>.</p>\r
+<p>Your password has been reset.\r
+You may now <a href="<% "login" f write-link %>">log in</a>.</p>\r
 \r
 </body>\r
 </html>\r
index c7e274e626887b0f3afc85d70406037ab352fc00..9106497defafc34875314a3877d4b9e6d9358fd5 100755 (executable)
@@ -1,10 +1,12 @@
 <% USING: http.server.components http.server.auth.login\r
-namespaces kernel combinators ; %>\r
+http.server namespaces kernel combinators ; %>\r
 <html>\r
 <body>\r
 <h1>New user registration</h1>\r
 \r
 <form method="POST" action="register">\r
+<% hidden-form-field %>\r
+\r
 <table>\r
 \r
 <tr>\r
@@ -24,7 +26,7 @@ namespaces kernel combinators ; %>
 \r
 <tr>\r
 <td>Password:</td>\r
-<td><% "password" component render-edit %></td>\r
+<td><% "new-password" component render-edit %></td>\r
 </tr>\r
 \r
 <tr>\r
index 12c799816d3cee1d817830b39c0cc88134f8bfdb..ae4c5d051fee88241ab0759a8535fdf50e27a062 100755 (executable)
@@ -3,7 +3,7 @@ USING: http.server.auth.providers
 http.server.auth.providers.assoc tools.test\r
 namespaces accessors kernel ;\r
 \r
-<in-memory> "provider" set\r
+<users-in-memory> "provider" set\r
 \r
 [ t ] [\r
     <user>\r
@@ -26,7 +26,7 @@ namespaces accessors kernel ;
 \r
 [ f ] [ "xx" "blah" "provider" get set-password ] unit-test\r
 \r
-[ t ] [ "fdasf" "slava" "provider" get set-password ] unit-test\r
+[ t ] [ "fdasf" "slava" "provider" get set-password >boolean ] unit-test\r
 \r
 [ t ] [ "fdasf" "slava" "provider" get check-login >boolean ] unit-test\r
 \r
index 8433e54fda68ad54b790d5003883c829428594c6..e8ab908406ba3b283a57fa499c48b74c417969d1 100755 (executable)
@@ -4,16 +4,16 @@ IN: http.server.auth.providers.assoc
 USING: new-slots accessors assocs kernel\r
 http.server.auth.providers ;\r
 \r
-TUPLE: in-memory assoc ;\r
+TUPLE: users-in-memory assoc ;\r
 \r
-: <in-memory> ( -- provider )\r
-    H{ } clone in-memory construct-boa ;\r
+: <users-in-memory> ( -- provider )\r
+    H{ } clone users-in-memory construct-boa ;\r
 \r
-M: in-memory get-user ( username provider -- user/f )\r
+M: users-in-memory get-user ( username provider -- user/f )\r
     assoc>> at ;\r
 \r
-M: in-memory update-user ( user provider -- ) 2drop ;\r
+M: users-in-memory update-user ( user provider -- ) 2drop ;\r
 \r
-M: in-memory new-user ( user provider -- user/f )\r
+M: users-in-memory new-user ( user provider -- user/f )\r
     >r dup username>> r> assoc>>\r
     2dup key? [ 3drop f ] [ pick >r set-at r> ] if ;\r
index 247359aea4556339345a4f7c4843f43d02d2b494..1ee727816344cc6d6d331487dc35ecf66b0ea880 100755 (executable)
@@ -4,12 +4,11 @@ http.server.auth.providers.db tools.test
 namespaces db db.sqlite db.tuples continuations\r
 io.files accessors kernel ;\r
 \r
-from-db "provider" set\r
+users-in-db "provider" set\r
 \r
 "auth-test.db" temp-file sqlite-db [\r
 \r
-    [ user drop-table ] ignore-errors\r
-    [ user create-table ] ignore-errors\r
+    init-users-table\r
 \r
     [ t ] [\r
         <user>\r
@@ -32,7 +31,7 @@ from-db "provider" set
 \r
     [ f ] [ "xx" "blah" "provider" get set-password ] unit-test\r
 \r
-    [ t ] [ "fdasf" "slava" "provider" get set-password ] unit-test\r
+    [ t ] [ "fdasf" "slava" "provider" get set-password >boolean ] unit-test\r
 \r
     [ t ] [ "fdasf" "slava" "provider" get check-login >boolean ] unit-test\r
 \r
index e9e79ff82fdf087f1bf241fdeaaba6e22758418e..aec64d3384cf238b62ddfc1161107f17fdaaac9d 100755 (executable)
@@ -1,7 +1,8 @@
 ! Copyright (C) 2008 Slava Pestov.\r
 ! See http://factorcode.org/license.txt for BSD license.\r
 USING: db db.tuples db.types new-slots accessors\r
-http.server.auth.providers kernel continuations ;\r
+http.server.auth.providers kernel continuations\r
+singleton ;\r
 IN: http.server.auth.providers.db\r
 \r
 user "USERS"\r
@@ -14,24 +15,20 @@ user "USERS"
     { "profile" "PROFILE" FACTOR-BLOB }\r
 } define-persistent\r
 \r
-: init-users-table ( -- )\r
-    [ user drop-table ] ignore-errors\r
-    user create-table ;\r
+: init-users-table user ensure-table ;\r
 \r
-TUPLE: from-db ;\r
-\r
-: from-db T{ from-db } ;\r
+SINGLETON: users-in-db\r
 \r
 : find-user ( username -- user )\r
     <user>\r
         swap >>username\r
     select-tuple ;\r
 \r
-M: from-db get-user\r
+M: users-in-db get-user\r
     drop\r
     find-user ;\r
 \r
-M: from-db new-user\r
+M: users-in-db new-user\r
     drop\r
     [\r
         dup username>> find-user [\r
@@ -41,5 +38,5 @@ M: from-db new-user
         ] if\r
     ] with-transaction ;\r
 \r
-M: from-db update-user\r
+M: users-in-db update-user\r
     drop update-tuple ;\r
index 7b8bfc627ce377821c6d403f9caca3ff855f06e4..30f6dbd06e0bd7744a80a691cdec2e7b8083f126 100755 (executable)
@@ -3,14 +3,12 @@
 USING: http.server.auth.providers kernel ;\r
 IN: http.server.auth.providers.null\r
 \r
-! Named "no" because we can say  no >>users\r
+TUPLE: no-users ;\r
 \r
-TUPLE: no ;\r
+: no-users T{ no-users } ;\r
 \r
-: no T{ no } ;\r
+M: no-users get-user 2drop f ;\r
 \r
-M: no get-user 2drop f ;\r
+M: no-users new-user 2drop f ;\r
 \r
-M: no new-user 2drop f ;\r
-\r
-M: no update-user 2drop ;\r
+M: no-users update-user 2drop ;\r
index 0aa27f870d2bf8259d1c32b3dd9508f8817a4af2..cd9cc995c738094c6140c86b9d51046372cd9779 100755 (executable)
@@ -17,12 +17,12 @@ GENERIC: new-user ( user provider -- user/f )
 : check-login ( password username provider -- user/f )\r
     get-user dup [ [ password>> = ] keep and ] [ 2drop f ] if ;\r
 \r
-:: set-password ( password username provider -- ? )\r
+:: set-password ( password username provider -- user/f )\r
     [let | user [ username provider get-user ] |\r
         user [\r
             user\r
                 password >>password\r
-            provider update-user t\r
+            dup provider update-user\r
         ] [ f ] if\r
     ] ;\r
 \r
index ac03e0efc824209ebde7a38d04734074c87b421f..45a6ff85f8f22fc2847aac89eb25239f4dfe76a4 100755 (executable)
@@ -4,7 +4,7 @@
 USING: html http http.server io kernel math namespaces\r
 continuations calendar sequences assocs new-slots hashtables\r
 accessors arrays alarms quotations combinators\r
-combinators.cleave fry ;\r
+combinators.cleave fry assocs.lib ;\r
 IN: http.server.callbacks\r
 \r
 SYMBOL: responder\r
index 2a507e6416a52bf2a5b9559322047dd0bbd5c83d..09d31202c5152d6a6e8b6e052b5178ef956c5864 100755 (executable)
@@ -86,3 +86,24 @@ TUPLE: test-tuple text number more-text ;
 \r
     [ t ] [ "number" value validation-error? ] unit-test\r
 ] with-scope\r
+\r
+[\r
+    [ ] [\r
+        "n" <number>\r
+            0 >>min-value\r
+            10 >>max-value\r
+        "n" set\r
+    ] unit-test\r
+\r
+    [ "123" ] [\r
+        "123" "n" get validate value>>\r
+    ] unit-test\r
+    \r
+    [ ] [ "n" get t >>integer drop ] unit-test\r
+\r
+    [ 3 ] [\r
+        "3" "n" get validate\r
+    ] unit-test\r
+] with-scope\r
+\r
+[ t ] [ "wake up sheeple" dup "n" <text> validate = ] unit-test\r
index bb0fc4b3dd1eddb3542ea064cadf648cf435ec4a..02c992651a2dc3fa43fa6111dd48215de798a157 100755 (executable)
@@ -7,8 +7,6 @@ http.server.actions splitting mirrors hashtables
 combinators.cleave fry continuations math ;
 IN: http.server.components
 
-SYMBOL: validation-failed?
-
 SYMBOL: components
 
 TUPLE: component id required default ;
@@ -30,16 +28,13 @@ SYMBOL: values
 
 : validate ( value component -- result )
     '[
-        , ,
+        ,
         over empty? [
             [ default>> [ v-default ] when* ]
             [ required>> [ v-required ] when ]
             bi
         ] [ validate* ] if
-    ] [
-        dup validation-error?
-        [ validation-failed? on ] [ rethrow ] if
-    ] recover ;
+    ] with-validator ;
 
 : render-view ( component -- )
     [ id>> value ] [ render-view* ] bi ;
@@ -192,15 +187,16 @@ M: password render-error*
     render-edit* render-error ;
 
 ! Number fields
-TUPLE: number min-value max-value ;
+TUPLE: number min-value max-value integer ;
 
 : <number> ( id -- component ) number <component> ;
 
 M: number validate*
     [ v-number ] [
+        [ integer>> [ v-integer ] when ]
         [ min-value>> [ v-min-value ] when* ]
         [ max-value>> [ v-max-value ] when* ]
-        bi
+        tri
     ] bi* ;
 
 M: number render-view*
@@ -215,7 +211,12 @@ M: number render-error*
 ! Text areas
 TUPLE: text ;
 
-: <text> ( id -- component ) <string> text construct-delegate ;
+: <text> ( id -- component ) text <component> ;
+
+M: text validate* drop ;
+
+M: text render-view*
+    drop write ;
 
 : render-textarea
     <textarea
index 37f21278dfdfde59b7cf5a6b7bded7f519e752ec..ce6a1244cb0961511c260a39a968fe060b3d3455 100755 (executable)
@@ -3,15 +3,23 @@
 USING: assocs kernel namespaces io io.timeouts strings splitting
 threads http sequences prettyprint io.server logging calendar
 new-slots html.elements accessors math.parser combinators.lib
-vocabs.loader debugger html continuations random combinators
+tools.vocabs debugger html continuations random combinators
 destructors io.encodings.latin1 fry combinators.cleave ;
 IN: http.server
 
 GENERIC: call-responder ( path responder -- response )
 
+: request-params ( -- assoc )
+    request get dup method>> {
+        { "GET" [ query>> ] }
+        { "HEAD" [ query>> ] }
+        { "POST" [ post-data>> ] }
+    } case ;
+
 : <content> ( content-type -- response )
     <response>
         200 >>code
+        "Document follows" >>message
         swap set-content-type ;
 
 TUPLE: trivial-responder response ;
@@ -44,19 +52,27 @@ SYMBOL: 404-responder
 
 [ <404> ] <trivial-responder> 404-responder set-global
 
-: url-redirect ( to query -- url )
-    #! Different host.
-    dup assoc-empty? [
-        drop
-    ] [
-        assoc>query "?" swap 3append
-    ] if ;
+SYMBOL: link-hook
+
+: modify-query ( query -- query )
+    link-hook get [ ] or call ;
+
+: link>string ( url query -- url' )
+    modify-query (link>string) ;
+
+: write-link ( url query -- )
+    link>string write ;
+
+SYMBOL: form-hook
+
+: hidden-form-field ( -- )
+    form-hook get [ ] or call ;
 
 : absolute-redirect ( to query -- url )
     #! Same host.
     request get clone
         swap [ >>query ] when*
-        swap >>path
+        swap url-encode >>path
     request-url ;
 
 : replace-last-component ( path with -- path' )
@@ -66,11 +82,12 @@ SYMBOL: 404-responder
     request get clone
     swap [ >>query ] when*
     swap [ '[ , replace-last-component ] change-path ] when*
+    dup query>> modify-query >>query
     request-url ;
 
 : derive-url ( to query -- url )
     {
-        { [ over "http://" head? ] [ url-redirect ] }
+        { [ over "http://" head? ] [ link>string ] }
         { [ over "/" head? ] [ absolute-redirect ] }
         { [ t ] [ relative-redirect ] }
     } cond ;
@@ -91,10 +108,6 @@ TUPLE: dispatcher default responders ;
 : <dispatcher> ( -- dispatcher )
     404-responder get H{ } clone dispatcher construct-boa ;
 
-: set-main ( dispatcher name -- dispatcher )
-    '[ , f <permanent-redirect> ] <trivial-responder>
-    >>default ;
-
 : split-path ( path -- rest first )
     [ CHAR: / = ] left-trim "/" split1 swap ;
 
@@ -107,28 +120,36 @@ TUPLE: dispatcher default responders ;
 
 M: dispatcher call-responder ( path dispatcher -- response )
     over [
-        2dup find-responder call-responder [
-            2nip
-        ] [
-            default>> [
-                call-responder
-            ] [
-                drop f
-            ] if*
-        ] if*
+        find-responder call-responder
     ] [
         2drop redirect-with-/
     ] if ;
 
+: <webapp> ( class -- dispatcher )
+    <dispatcher> swap construct-delegate ; inline
+
+TUPLE: vhost-dispatcher default responders ;
+
+: <vhost-dispatcher> ( -- dispatcher )
+    404-responder get H{ } clone vhost-dispatcher construct-boa ;
+
+: find-vhost ( dispatcher -- responder )
+    request get host>> over responders>> at*
+    [ nip ] [ drop default>> ] if ;
+
+M: vhost-dispatcher call-responder ( path dispatcher -- response )
+    find-vhost call-responder ;
+
+: set-main ( dispatcher name -- dispatcher )
+    '[ , f <permanent-redirect> ] <trivial-responder>
+    >>default ;
+
 : add-responder ( dispatcher responder path -- dispatcher )
     pick responders>> set-at ;
 
 : add-main-responder ( dispatcher responder path -- dispatcher )
     [ add-responder ] keep set-main ;
 
-: <webapp> ( class -- dispatcher )
-    <dispatcher> swap construct-delegate ; inline
-
 SYMBOL: main-responder
 
 main-responder global
@@ -202,11 +223,3 @@ SYMBOL: exit-continuation
 : httpd-main ( -- ) 8888 httpd ;
 
 MAIN: httpd-main
-
-! Utility
-: generate-key ( assoc -- str )
-    >r random-256 >hex r>
-    2dup key? [ nip generate-key ] [ drop ] if ;
-
-: set-at-unique ( value assoc -- key )
-    dup generate-key [ swap set-at ] keep ;
index 5c2d3a57cdec43ac038199f66c3b2f2d8880829d..a6a42f9129edad5832dcec6d761a8a3ae6fc1b5f 100755 (executable)
@@ -1,6 +1,10 @@
 IN: http.server.sessions.tests\r
-USING: tools.test http.server.sessions math namespaces\r
-kernel accessors ;\r
+USING: tools.test http http.server.sessions\r
+http.server.sessions.storage http.server.sessions.storage.assoc\r
+http.server math namespaces kernel accessors prettyprint\r
+io.streams.string splitting destructors ;\r
+\r
+[ H{ } ] [ H{ } add-session-id ] unit-test\r
 \r
 : with-session \ session swap with-variable ; inline\r
 \r
@@ -10,7 +14,18 @@ C: <foo> foo
 \r
 M: foo init-session* drop 0 "x" sset ;\r
 \r
-f <session> [\r
+M: foo call-responder\r
+    2drop\r
+    "x" [ 1+ ] schange\r
+    "text/html" <content> [ "x" sget pprint ] >>body ;\r
+\r
+[\r
+    "123" session-id set\r
+    H{ } clone session set\r
+    session-changed? off\r
+\r
+    [ H{ { "factorsessid" "123" } } ] [ H{ } add-session-id ] unit-test\r
+\r
     [ ] [ 3 "x" sset ] unit-test\r
     \r
     [ 9 ] [ "x" sget sq ] unit-test\r
@@ -18,22 +33,88 @@ f <session> [
     [ ] [ "x" [ 1- ] schange ] unit-test\r
     \r
     [ 4 ] [ "x" sget sq ] unit-test\r
-] with-session\r
+\r
+    [ t ] [ session-changed? get ] unit-test\r
+] with-scope\r
 \r
 [ t ] [ f <url-sessions> url-sessions? ] unit-test\r
 [ t ] [ f <cookie-sessions> cookie-sessions? ] unit-test\r
 \r
 [ ] [\r
     <foo> <url-sessions>\r
+        <sessions-in-memory> >>sessions\r
     "manager" set\r
 ] unit-test\r
 \r
 [ { 5 0 } ] [\r
     [\r
-        "manager" get new-session\r
-        dup "manager" get get-session [ 5 "a" sset ] with-session\r
-        dup "manager" get get-session [ "a" sget , ] with-session\r
-        dup "manager" get get-session [ "x" sget , ] with-session\r
-        "manager" get get-session delete-session\r
+        "manager" get begin-session drop\r
+        dup "manager" get sessions>> get-session [ 5 "a" sset ] with-session\r
+        dup "manager" get sessions>> get-session [ "a" sget , ] with-session\r
+        dup "manager" get sessions>> get-session [ "x" sget , ] with-session\r
+        "manager" get sessions>> get-session\r
+        "manager" get sessions>> delete-session\r
     ] { } make\r
 ] unit-test\r
+\r
+[ ] [\r
+    <request>\r
+        "GET" >>method\r
+    request set\r
+    "/etc" "manager" get call-responder\r
+    response set\r
+] unit-test\r
+\r
+[ 307 ] [ response get code>> ] unit-test\r
+\r
+[ ] [ response get "location" header "=" split1 nip "id" set ] unit-test\r
+\r
+: url-responder-mock-test\r
+    [\r
+        <request>\r
+        "GET" >>method\r
+        "id" get session-id-key set-query-param\r
+        "/" >>path\r
+        request set\r
+        "/" "manager" get call-responder\r
+        [ write-response-body drop ] with-string-writer\r
+    ] with-destructors ;\r
+\r
+[ "1" ] [ url-responder-mock-test ] unit-test\r
+[ "2" ] [ url-responder-mock-test ] unit-test\r
+[ "3" ] [ url-responder-mock-test ] unit-test\r
+[ "4" ] [ url-responder-mock-test ] unit-test\r
+\r
+[ ] [\r
+    <foo> <cookie-sessions>\r
+        <sessions-in-memory> >>sessions\r
+    "manager" set\r
+] unit-test\r
+\r
+[\r
+    <request>\r
+    "GET" >>method\r
+    "/" >>path\r
+    request set\r
+    "/etc" "manager" get call-responder response set\r
+    [ "1" ] [ [ response get write-response-body drop ] with-string-writer ] unit-test\r
+    response get\r
+] with-destructors\r
+response set\r
+\r
+[ ] [ response get cookies>> "cookies" set ] unit-test\r
+\r
+: cookie-responder-mock-test\r
+    [\r
+        <request>\r
+        "GET" >>method\r
+        "cookies" get >>cookies\r
+        "/" >>path\r
+        request set\r
+        "/" "manager" get call-responder\r
+        [ write-response-body drop ] with-string-writer\r
+    ] with-destructors ;\r
+\r
+[ "2" ] [ cookie-responder-mock-test ] unit-test\r
+[ "3" ] [ cookie-responder-mock-test ] unit-test\r
+[ "4" ] [ cookie-responder-mock-test ] unit-test\r
index 1d90a32faf1fce4de8fa11a1587b2ad1646a8e14..76f022e28cc7a2de6cc57d9a928cdc9c19072b35 100755 (executable)
@@ -1,8 +1,10 @@
 ! Copyright (C) 2008 Doug Coleman, Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
 USING: assocs calendar kernel math.parser namespaces random
-boxes alarms new-slots accessors http http.server
-quotations hashtables sequences fry combinators.cleave ;
+new-slots accessors http http.server
+http.server.sessions.storage http.server.sessions.storage.assoc
+quotations hashtables sequences fry combinators.cleave
+html.elements symbols continuations destructors ;
 IN: http.server.sessions
 
 ! ! ! ! ! !
@@ -16,62 +18,48 @@ M: dispatcher init-session* drop ;
 TUPLE: session-manager responder sessions ;
 
 : <session-manager> ( responder class -- responder' )
-    >r H{ } clone session-manager construct-boa r>
-    construct-delegate ; inline
+    >r <sessions-in-memory> session-manager construct-boa
+    r> construct-delegate ; inline
 
-TUPLE: session manager id namespace alarm ;
+SYMBOLS: session session-id session-changed? ;
 
-: <session> ( manager -- session )
-    f H{ } clone <box> \ session construct-boa ;
+: sget ( key -- value )
+    session get at ;
 
-: timeout ( -- dt ) 20 minutes ;
+: sset ( value key -- )
+    session get set-at
+    session-changed? on ;
 
-: cancel-timeout ( session -- )
-    alarm>> [ cancel-alarm ] if-box? ;
+: schange ( key quot -- )
+    session get swap change-at
+    session-changed? on ; inline
 
-: delete-session ( session -- )
-    [ cancel-timeout ]
-    [ dup manager>> sessions>> delete-at ]
-    bi ;
+: sessions session-manager get sessions>> ;
 
-: touch-session ( session -- session )
-    [ cancel-timeout ]
-    [ [ '[ , delete-session ] timeout later ] keep alarm>> >box ]
-    [ ]
-    tri ;
+: managed-responder session-manager get responder>> ;
 
-: session ( -- assoc ) \ session get namespace>> ;
+: init-session ( managed -- session )
+    H{ } clone [ session [ init-session* ] with-variable ] keep ;
 
-: sget ( key -- value ) session at ;
+: begin-session ( responder -- id session )
+    [ responder>> init-session ] [ sessions>> ] bi
+    [ new-session ] [ drop ] 2bi ;
 
-: sset ( value key -- ) session set-at ;
+! Destructor
+TUPLE: session-saver id session ;
 
-: schange ( key quot -- ) session swap change-at ; inline
+C: <session-saver> session-saver
 
-: init-session ( session -- session )
-    dup dup \ session [
-        manager>> responder>> init-session*
-    ] with-variable ;
+M: session-saver dispose
+    session-changed? get [
+        [ session>> ] [ id>> ] bi
+        sessions update-session
+    ] [ drop ] if ;
 
-: new-session ( responder -- id )
-    [ <session> init-session touch-session ]
-    [ [ sessions>> set-at-unique ] [ drop swap >>id ] 2bi ]
-    bi id>> ;
-
-: get-session ( id responder -- session/f )
-    sessions>> at* [ touch-session ] when ;
-
-: call-responder/session ( path responder session -- response )
-    \ session set responder>> call-responder ;
-
-: sessions ( -- manager/f )
-    \ session get dup [ manager>> ] when ;
-
-GENERIC: session-link* ( url query sessions -- string )
-
-M: object session-link* 2drop url-encode ;
-
-: session-link ( url query -- string ) sessions session-link* ;
+: call-responder/session ( path responder id session -- response )
+    [ <session-saver> add-always-destructor ]
+    [ [ session-id set ] [ session set ] bi* ] 2bi
+    [ session-manager set ] [ responder>> call-responder ] bi ;
 
 TUPLE: null-sessions ;
 
@@ -79,49 +67,64 @@ TUPLE: null-sessions ;
     null-sessions <session-manager> ;
 
 M: null-sessions call-responder ( path responder -- response )
-    dup <session> call-responder/session ;
+    H{ } clone f call-responder/session ;
 
 TUPLE: url-sessions ;
 
 : <url-sessions> ( responder -- responder' )
     url-sessions <session-manager> ;
 
-: sess-id "factorsessid" ;
+: session-id-key "factorsessid" ;
 
-: current-session ( responder request -- session )
-    sess-id query-param swap get-session ;
+: current-url-session ( responder -- id/f session/f )
+    [ request-params session-id-key swap at ] [ sessions>> ] bi*
+    [ drop ] [ get-session ] 2bi ;
+
+: add-session-id ( query -- query' )
+    session-id get [ session-id-key associate union ] when* ;
+
+: session-form-field ( -- )
+    <input
+        "hidden" =type
+        session-id-key =id
+        session-id-key =name
+        session-id get =value
+    input/> ;
+
+: new-url-session ( responder -- response )
+    [ f ] [ begin-session drop session-id-key associate ] bi*
+    <temporary-redirect> ;
 
 M: url-sessions call-responder ( path responder -- response )
-    dup request get current-session [
+    [ add-session-id ] link-hook set
+    [ session-form-field ] form-hook set
+    dup current-url-session dup [
         call-responder/session
     ] [
-        nip
-        f swap new-session sess-id associate <temporary-redirect>
-    ] if* ;
-
-M: url-sessions session-link*
-    drop
-    url-encode
-    \ session get id>> sess-id associate union assoc>query
-    dup assoc-empty? [ drop ] [ "?" swap 3append ] if ;
+        2drop nip new-url-session
+    ] if ;
 
 TUPLE: cookie-sessions ;
 
 : <cookie-sessions> ( responder -- responder' )
     cookie-sessions <session-manager> ;
 
-: get-session-cookie ( responder -- cookie )
-    request get sess-id get-cookie
-    [ value>> swap get-session ] [ drop f ] if* ;
+: current-cookie-session ( responder -- id namespace/f )
+    request get session-id-key get-cookie dup
+    [ value>> dup rot sessions>> get-session ] [ 2drop f f ] if ;
 
 : <session-cookie> ( id -- cookie )
-    sess-id <cookie> ;
+    session-id-key <cookie> ;
+
+: call-responder/new-session ( path responder -- response )
+    dup begin-session
+    [ call-responder/session ]
+    [ drop <session-cookie> ] 2bi
+    put-cookie ;
 
 M: cookie-sessions call-responder ( path responder -- response )
-    dup get-session-cookie [
+    dup current-cookie-session dup [
         call-responder/session
     ] [
-        dup new-session
-        [ over get-session call-responder/session ] keep
-        <session-cookie> put-cookie
-    ] if* ;
+        2drop call-responder/new-session
+    ] if ;
diff --git a/extra/http/server/sessions/storage/assoc/assoc.factor b/extra/http/server/sessions/storage/assoc/assoc.factor
new file mode 100755 (executable)
index 0000000..1339e3c
--- /dev/null
@@ -0,0 +1,38 @@
+! Copyright (C) 2008 Slava Pestov.\r
+! See http://factorcode.org/license.txt for BSD license.\r
+USING: assocs assocs.lib new-slots accessors\r
+http.server.sessions.storage combinators.cleave alarms kernel\r
+fry http.server ;\r
+IN: http.server.sessions.storage.assoc\r
+\r
+TUPLE: sessions-in-memory sessions alarms ;\r
+\r
+: <sessions-in-memory> ( -- storage )\r
+    H{ } clone H{ } clone sessions-in-memory construct-boa ;\r
+\r
+: cancel-session-timeout ( id storage -- )\r
+    alarms>> at [ cancel-alarm ] when* ;\r
+\r
+: touch-session ( id storage -- )\r
+    [ cancel-session-timeout ]\r
+    [ '[ , , delete-session ] timeout later ]\r
+    [ alarms>> set-at ]\r
+    2tri ;\r
+\r
+M: sessions-in-memory get-session ( id storage -- namespace )\r
+    [ sessions>> at ] [ touch-session ] 2bi ;\r
+\r
+M: sessions-in-memory update-session ( namespace id storage -- )\r
+    [ sessions>> set-at ]\r
+    [ touch-session ]\r
+    2bi ;\r
+\r
+M: sessions-in-memory delete-session ( id storage -- )\r
+    [ sessions>> delete-at ]\r
+    [ cancel-session-timeout ]\r
+    2bi ;\r
+\r
+M: sessions-in-memory new-session ( namespace storage -- id )\r
+    [ sessions>> set-at-unique ]\r
+    [ [ touch-session ] [ drop ] 2bi ]\r
+    bi ;\r
diff --git a/extra/http/server/sessions/storage/db/db-tests.factor b/extra/http/server/sessions/storage/db/db-tests.factor
new file mode 100755 (executable)
index 0000000..4e6ae8a
--- /dev/null
@@ -0,0 +1,24 @@
+IN: http.server.sessions.storage.db\r
+USING: http.server.sessions.storage\r
+http.server.sessions.storage.db namespaces io.files\r
+db.sqlite db accessors math tools.test kernel assocs\r
+sequences ;\r
+\r
+sessions-in-db "storage" set\r
+\r
+"auth-test.db" temp-file sqlite-db [\r
+    [ ] [ init-sessions-table ] unit-test\r
+\r
+    [ f ] [ H{ } "storage" get new-session empty? ] unit-test\r
+\r
+    H{ } "storage" get new-session "id" set\r
+\r
+    "id" get "storage" get get-session "session" set\r
+    "a" "b" "session" get set-at\r
+\r
+    "session" get "id" get "storage" get update-session\r
+\r
+    [ H{ { "b" "a" } } ] [\r
+        "id" get "storage" get get-session\r
+    ] unit-test\r
+] with-db\r
diff --git a/extra/http/server/sessions/storage/db/db.factor b/extra/http/server/sessions/storage/db/db.factor
new file mode 100755 (executable)
index 0000000..6ef655b
--- /dev/null
@@ -0,0 +1,52 @@
+! Copyright (C) 2008 Slava Pestov.\r
+! See http://factorcode.org/license.txt for BSD license.\r
+USING: assocs new-slots accessors http.server.sessions.storage\r
+alarms kernel http.server db.tuples db.types singleton\r
+combinators.cleave math.parser ;\r
+IN: http.server.sessions.storage.db\r
+\r
+SINGLETON: sessions-in-db\r
+\r
+TUPLE: session id namespace ;\r
+\r
+session "SESSIONS"\r
+{\r
+    { "id" "ID" INTEGER +native-id+ }\r
+    { "namespace" "NAMESPACE" FACTOR-BLOB }\r
+} define-persistent\r
+\r
+: init-sessions-table session ensure-table ;\r
+\r
+: <session> ( id -- session )\r
+    session construct-empty\r
+        swap dup [ string>number ] when >>id ;\r
+\r
+USING: namespaces io prettyprint ;\r
+M: sessions-in-db get-session ( id storage -- namespace/f )\r
+    global [ "get " write over print flush ] bind\r
+    drop\r
+    dup [\r
+        <session>\r
+        select-tuple dup [ namespace>> ] when global [ dup . ] bind\r
+    ] when ;\r
+\r
+M: sessions-in-db update-session ( namespace id storage -- )\r
+    global [ "update " write over print flush ] bind\r
+    drop\r
+    <session>\r
+        swap  global [ dup . ] bind >>namespace\r
+    dup update-tuple\r
+    id>> <session> select-tuple global [ . flush ] bind\r
+    ;\r
+\r
+M: sessions-in-db delete-session ( id storage -- )\r
+    drop\r
+    <session>\r
+    delete-tuple ;\r
+\r
+M: sessions-in-db new-session ( namespace storage -- id )\r
+    global [ "new " print flush ] bind\r
+    drop\r
+    f <session>\r
+        swap  global [ dup . ] bind >>namespace\r
+    [ insert-tuple ] [ id>> number>string ] bi ;\r
diff --git a/extra/http/server/sessions/storage/storage.factor b/extra/http/server/sessions/storage/storage.factor
new file mode 100755 (executable)
index 0000000..df96c81
--- /dev/null
@@ -0,0 +1,14 @@
+! Copyright (C) 2008 Slava Pestov.\r
+! See http://factorcode.org/license.txt for BSD license.\r
+USING: calendar ;\r
+IN: http.server.sessions.storage\r
+\r
+: timeout 20 minutes ;\r
+\r
+GENERIC: get-session ( id storage -- namespace )\r
+\r
+GENERIC: update-session ( namespace id storage -- )\r
+\r
+GENERIC: delete-session ( id storage -- )\r
+\r
+GENERIC: new-session ( namespace storage -- id )\r
index 6c365ad87bfcbc03e3a1da0336844e8346399494..b408b1b6b095e5f892b21df726ebcf3b77200752 100755 (executable)
@@ -7,16 +7,11 @@ calendar.format new-slots accessors io.encodings.binary
 combinators.cleave fry ;\r
 IN: http.server.static\r
 \r
-SYMBOL: responder\r
-\r
 ! special maps mime types to quots with effect ( path -- )\r
 TUPLE: file-responder root hook special ;\r
 \r
-: unix-time>timestamp ( n -- timestamp )\r
-    >r unix-1970 r> seconds time+ ;\r
-\r
 : file-http-date ( filename -- string )\r
-    file-modified unix-time>timestamp timestamp>http-string ;\r
+    file-info file-info-modified timestamp>http-string ;\r
 \r
 : last-modified-matches? ( filename -- ? )\r
     file-http-date dup [\r
@@ -33,7 +28,7 @@ TUPLE: file-responder root hook special ;
     [\r
         <content>\r
         swap\r
-        [ file-length "content-length" set-header ]\r
+        [ file-info file-info-size "content-length" set-header ]\r
         [ file-http-date "last-modified" set-header ]\r
         [ '[ , binary <file-reader> stdio get stream-copy ] >>body ]\r
         tri\r
index 3ef2b6c8631c2e3018db01b6421a35745302f4b0..82827ac450f74b97c774bfde6d68ca1988227acc 100755 (executable)
@@ -2,7 +2,8 @@ IN: http.server.validators.tests
 USING: kernel sequences tools.test http.server.validators
 accessors ;
 
-[ "foo" v-number ] [ validation-error? ] must-fail-with
+[ "foo" v-number ] must-fail
+[ 123 ] [ "123" v-number ] unit-test
 
 [ "slava@factorcode.org" ] [
     "slava@factorcode.org" v-email
@@ -13,10 +14,10 @@ accessors ;
 ] unit-test
 
 [ "slava@factorcode.o" v-email ]
-[ reason>> "invalid e-mail" = ] must-fail-with
+[ "invalid e-mail" = ] must-fail-with
 
 [ "sla@@factorcode.o" v-email ]
-[ reason>> "invalid e-mail" = ] must-fail-with
+[ "invalid e-mail" = ] must-fail-with
 
 [ "slava@factorcodeorg" v-email ]
-[ reason>> "invalid e-mail" = ] must-fail-with
+[ "invalid e-mail" = ] must-fail-with
index 7eb5163d33da5322e6fb1e5d996aa5dd706ce182..539a58d19f52d13b6785bcc08e581784d6059045 100755 (executable)
@@ -5,21 +5,26 @@ math.parser assocs new-slots regexp fry unicode.categories
 combinators.cleave sequences ;
 IN: http.server.validators
 
+SYMBOL: validation-failed?
+
 TUPLE: validation-error value reason ;
 
-: validation-error ( value reason -- * )
-    \ validation-error construct-boa throw ;
+C: <validation-error> validation-error
+
+: with-validator ( value quot -- result )
+    [ validation-failed? on <validation-error> ] recover ;
+    inline
 
 : v-default ( str def -- str )
     over empty? spin ? ;
 
 : v-required ( str -- str )
-    dup empty? [ "required" validation-error ] when ;
+    dup empty? [ "required" throw ] when ;
 
 : v-min-length ( str n -- str )
     over length over < [
         [ "must be at least " % # " characters" % ] "" make
-        validation-error
+        throw
     ] [
         drop
     ] if ;
@@ -27,35 +32,34 @@ TUPLE: validation-error value reason ;
 : v-max-length ( str n -- str )
     over length over > [
         [ "must be no more than " % # " characters" % ] "" make
-        validation-error
+        throw
     ] [
         drop
     ] if ;
 
 : v-number ( str -- n )
-    dup string>number [ ] [
-        "must be a number" validation-error
-    ] ?if ;
+    dup string>number [ ] [ "must be a number" throw ] ?if ;
+
+: v-integer ( n -- n )
+    dup integer? [ "must be an integer" throw ] unless ;
 
 : v-min-value ( x n -- x )
     2dup < [
-        [ "must be at least " % # ] "" make
-        validation-error
+        [ "must be at least " % # ] "" make throw
     ] [
         drop
     ] if ;
 
 : v-max-value ( x n -- x )
     2dup > [
-        [ "must be no more than " % # ] "" make
-        validation-error
+        [ "must be no more than " % # ] "" make throw
     ] [
         drop
     ] if ;
 
 : v-regexp ( str what regexp -- str )
     >r over r> matches?
-    [ drop ] [ "invalid " swap append validation-error ] if ;
+    [ drop ] [ "invalid " swap append throw ] if ;
 
 : v-email ( str -- str )
     #! From http://www.regular-expressions.info/email.html
@@ -64,12 +68,12 @@ TUPLE: validation-error value reason ;
     v-regexp ;
 
 : v-captcha ( str -- str )
-    dup empty? [ "must remain blank" validation-error ] unless ;
+    dup empty? [ "must remain blank" throw ] unless ;
 
 : v-one-line ( str -- str )
     dup "\r\n" seq-intersect empty?
-    [ "must be a single line" validation-error ] unless ;
+    [ "must be a single line" throw ] unless ;
 
 : v-one-word ( str -- str )
     dup [ alpha? ] all?
-    [ "must be a single word" validation-error ] unless ;
+    [ "must be a single word" throw ] unless ;
diff --git a/extra/io/encodings/ascii/ascii-tests.factor b/extra/io/encodings/ascii/ascii-tests.factor
new file mode 100644 (file)
index 0000000..4f6d288
--- /dev/null
@@ -0,0 +1,9 @@
+USING: io.encodings.string io.encodings.ascii tools.test strings arrays ;
+IN: io.encodings.ascii.tests
+
+[ B{ CHAR: f CHAR: o CHAR: o } ] [ "foo" ascii encode ] unit-test
+[ { 128 } >string ascii encode ] must-fail
+[ B{ 127 } ] [ { 127 } ascii encode ] unit-test
+
+[ "bar" ] [ "bar" ascii decode ] unit-test
+[ { CHAR: b HEX: fffd CHAR: r } ] [ { CHAR: b 233 CHAR: r } ascii decode >array ] unit-test
index 1c50e4c2a4e196ae70d0022e1605bf910c1f0c59..bd71b733f1f919b8f7b5a5c0945e02debfd5d4ea 100644 (file)
@@ -3,13 +3,16 @@
 USING: io io.encodings strings kernel math sequences byte-arrays io.encodings ;
 IN: io.encodings.ascii
 
-: encode-check<= ( string stream max -- )
+: encode-check< ( string stream max -- )
     [ pick <= [ encode-error ] [ stream-write1 ] if ] 2curry each ;
 
+: push-if< ( sbuf character max -- )
+    over <= [ drop HEX: fffd ] when swap push ;
+
 TUPLE: ascii ;
 
 M: ascii stream-write-encoded ( string stream encoding -- )
-    drop 128 encode-check<= ;
+    drop 128 encode-check< ;
 
 M: ascii decode-step
-    drop dup 128 >= [ decode-error ] [ swap push ] if ;
+    drop 128 push-if< ;
diff --git a/extra/io/encodings/latin1/latin1-tests.factor b/extra/io/encodings/latin1/latin1-tests.factor
new file mode 100644 (file)
index 0000000..a89bfe0
--- /dev/null
@@ -0,0 +1,9 @@
+USING: io.encodings.string io.encodings.latin1 tools.test strings arrays ;
+IN: io.encodings.latin1.tests
+
+[ B{ CHAR: f CHAR: o CHAR: o } ] [ "foo" latin1 encode ] unit-test
+[ { 256 } >string latin1 encode ] must-fail
+[ B{ 255 } ] [ { 255 } latin1 encode ] unit-test
+
+[ "bar" ] [ "bar" latin1 decode ] unit-test
+[ { CHAR: b 233 CHAR: r } ] [ { CHAR: b 233 CHAR: r } latin1 decode >array ] unit-test
index 3cb361b2fd2c585724792f4855df79695c0fc182..71e98a1747eb8ffb4181dd4606e3e6d6c622131e 100755 (executable)
@@ -6,7 +6,7 @@ IN: io.encodings.latin1
 TUPLE: latin1 ;
 
 M: latin1 stream-write-encoded 
-    drop 256 encode-check<= ;
+    drop 256 encode-check< ;
 
 M: latin1 decode-step
     drop swap push ;
old mode 100644 (file)
new mode 100755 (executable)
index f1c6517..b17d7ae
@@ -4,7 +4,7 @@ IN: io.mmap.tests
 
 [ "mmap-test-file.txt" resource-path delete-file ] ignore-errors
 [ ] [ "12345" "mmap-test-file.txt" resource-path ascii set-file-contents ] unit-test
-[ ] [ "mmap-test-file.txt" resource-path dup file-length [ CHAR: 2 0 pick set-nth drop ] with-mapped-file ] unit-test
-[ 5 ] [ "mmap-test-file.txt" resource-path dup file-length [ length ] with-mapped-file ] unit-test
+[ ] [ "mmap-test-file.txt" resource-path dup file-info file-info-size [ CHAR: 2 0 pick set-nth drop ] with-mapped-file ] unit-test
+[ 5 ] [ "mmap-test-file.txt" resource-path dup file-info file-info-size [ length ] with-mapped-file ] unit-test
 [ "22345" ] [ "mmap-test-file.txt" resource-path ascii file-contents ] unit-test
 [ "mmap-test-file.txt" resource-path delete-file ] ignore-errors
index 73090ea724c4082f8394d4ee5835a9e7c183c4c7..1e7d6823140c9e14fad5f8f0a30eaeef58b0d323 100755 (executable)
@@ -1,15 +1,15 @@
 ! Copyright (C) 2005, 2008 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
 USING: io.backend io.nonblocking io.unix.backend io.files io
-unix unix.stat unix.time kernel math continuations math.bitfields
-byte-arrays alien combinators combinators.cleave calendar
-io.encodings.binary ;
+unix unix.stat unix.time kernel math continuations
+math.bitfields byte-arrays alien combinators combinators.cleave
+calendar io.encodings.binary ;
 
 IN: io.unix.files
 
 M: unix-io cwd
-    MAXPATHLEN dup <byte-array> swap
-    getcwd [ (io-error) ] unless* ;
+    MAXPATHLEN [ <byte-array> ] [ ] bi getcwd
+    [ (io-error) ] unless* ;
 
 M: unix-io cd
     chdir io-error ;
@@ -68,7 +68,9 @@ M: unix-io delete-directory ( path -- )
     ] with-disposal ;
 
 M: unix-io copy-file ( from to -- )
-    [ (copy-file) ] 2keep swap file-permissions chmod io-error ;
+    [ (copy-file) ]
+    [ swap file-info file-info-permissions chmod  io-error ]
+    2bi ;
 
 : stat>type ( stat -- type )
     stat-st_mode {
@@ -82,8 +84,8 @@ M: unix-io copy-file ( from to -- )
         { [ t            ] [ +unknown+          ] }
       } cond nip ;
 
-M: unix-io file-info ( path -- info )
-    stat* {
+: stat>file-info ( stat -- info )
+    {
         [ stat>type ]
         [ stat-st_size ]
         [ stat-st_mode ]
@@ -91,11 +93,8 @@ M: unix-io file-info ( path -- info )
     } cleave
     \ file-info construct-boa ;
 
+M: unix-io file-info ( path -- info )
+    stat* stat>file-info ;
+
 M: unix-io link-info ( path -- info )
-    lstat* {
-        [ stat>type ]
-        [ stat-st_size ]
-        [ stat-st_mode ]
-        [ stat-st_mtim timespec-sec seconds unix-1970 time+ ]
-    } cleave
-    \ file-info construct-boa ;
+    lstat* stat>file-info ;
index 2aad0bdb1ae9e1f3f1a99d76c69b6a07404d086f..65b4a6f0f7f606487d6fb073f552d1c431691d00 100644 (file)
@@ -1,5 +1,5 @@
 IN: io.unix.freebsd
-USING: io.unix.bsd io.backend core-foundation.fsevents ;
+USING: io.unix.bsd io.backend ;
 
 TUPLE: freebsd-io ;
 
index 64e2cc3c3d859f01626dc54e0141a85b8eae378e..01e29866ebdaeb768a07083ce7c11d5a7a94c9e2 100755 (executable)
@@ -4,4 +4,4 @@ combinators namespaces system vocabs.loader sequences ;
 
 "io.unix." os append require
 
-"vocabs.monitor" require
+"tools.vocabs.monitor" require
old mode 100644 (file)
new mode 100755 (executable)
index 3d51e65..35aaf45
@@ -3,43 +3,36 @@
 USING: alien.c-types io.files io.windows kernel
 math windows windows.kernel32 combinators.cleave
 windows.time calendar combinators math.functions
-sequences combinators.lib namespaces words symbols ;
+sequences namespaces words symbols ;
 IN: io.windows.files
 
 SYMBOLS: +read-only+ +hidden+ +system+
-+directory+ +archive+ +device+ +normal+ +temporary+
++archive+ +device+ +normal+ +temporary+
 +sparse-file+ +reparse-point+ +compressed+ +offline+
 +not-content-indexed+ +encrypted+ ;
 
-: expand-constants ( word/obj -- obj'/obj )
-    dup word? [ execute ] when ;
+: win32-file-attribute ( n attr symbol -- n )
+    >r dupd mask? [ r> , ] [ r> drop ] if ;
 
-: get-flags ( n seq -- seq' )
+: win32-file-attributes ( n -- seq )
     [
-        [
-            first2 expand-constants
-            [ swapd mask? [ , ] [ drop ] if ] 2curry
-        ] map call-with
+        FILE_ATTRIBUTE_READONLY +read-only+ win32-file-attribute
+        FILE_ATTRIBUTE_HIDDEN +hidden+ win32-file-attribute
+        FILE_ATTRIBUTE_SYSTEM +system+ win32-file-attribute
+        FILE_ATTRIBUTE_DIRECTORY +directory+ win32-file-attribute
+        FILE_ATTRIBUTE_ARCHIVE +archive+ win32-file-attribute
+        FILE_ATTRIBUTE_DEVICE +device+ win32-file-attribute
+        FILE_ATTRIBUTE_NORMAL +normal+ win32-file-attribute
+        FILE_ATTRIBUTE_TEMPORARY +temporary+ win32-file-attribute
+        FILE_ATTRIBUTE_SPARSE_FILE +sparse-file+ win32-file-attribute
+        FILE_ATTRIBUTE_REPARSE_POINT +reparse-point+ win32-file-attribute
+        FILE_ATTRIBUTE_COMPRESSED +compressed+ win32-file-attribute
+        FILE_ATTRIBUTE_OFFLINE +offline+ win32-file-attribute
+        FILE_ATTRIBUTE_NOT_CONTENT_INDEXED +not-content-indexed+ win32-file-attribute
+        FILE_ATTRIBUTE_ENCRYPTED +encrypted+ win32-file-attribute
+        drop
     ] { } make ;
 
-: win32-file-attributes ( n -- seq )
-    {
-        { +read-only+ FILE_ATTRIBUTE_READONLY }
-        { +hidden+ FILE_ATTRIBUTE_HIDDEN }
-        { +system+ FILE_ATTRIBUTE_SYSTEM }
-        { +directory+ FILE_ATTRIBUTE_DIRECTORY }
-        { +archive+ FILE_ATTRIBUTE_ARCHIVE }
-        { +device+ FILE_ATTRIBUTE_DEVICE }
-        { +normal+ FILE_ATTRIBUTE_NORMAL }
-        { +temporary+ FILE_ATTRIBUTE_TEMPORARY }
-        { +sparse-file+ FILE_ATTRIBUTE_SPARSE_FILE }
-        { +reparse-point+ FILE_ATTRIBUTE_REPARSE_POINT }
-        { +compressed+ FILE_ATTRIBUTE_COMPRESSED }
-        { +offline+ FILE_ATTRIBUTE_OFFLINE }
-        { +not-content-indexed+ FILE_ATTRIBUTE_NOT_CONTENT_INDEXED }
-        { +encrypted+ FILE_ATTRIBUTE_ENCRYPTED }
-    } get-flags ;
-
 : win32-file-type ( n -- symbol )
     FILE_ATTRIBUTE_DIRECTORY mask? +directory+ +regular-file+ ? ;
 
index b09d867e10efbd9bd450cf5cedb82e7ba64947ff..3e49f1dc10aed37fc20826d12851c6fcf159e5c6 100755 (executable)
@@ -5,7 +5,7 @@ io.windows io.windows.nt.pipes libc io.nonblocking
 io.streams.duplex windows.types math windows.kernel32 windows
 namespaces io.launcher kernel sequences windows.errors assocs
 splitting system threads init strings combinators
-io.backend new-slots accessors ;
+io.backend new-slots accessors concurrency.flags ;
 IN: io.windows.launcher
 
 TUPLE: CreateProcess-args
@@ -137,18 +137,18 @@ M: windows-io kill-process* ( handle -- )
     dup HEX: ffffffff = [ win32-error ] when
     dup WAIT_TIMEOUT = [ 2drop t ] [ swap nth process-exited f ] if ;
 
+SYMBOL: wait-flag
+
 : wait-loop ( -- )
     processes get dup assoc-empty?
-    [ drop f sleep-until ]
+    [ drop wait-flag get-global lower-flag ]
     [ wait-for-processes [ 100 sleep ] when ] if ;
 
-SYMBOL: wait-thread
-
 : start-wait-thread ( -- )
-    [ wait-loop t ] "Process wait" spawn-server
-    wait-thread set-global ;
+    <flag> wait-flag set-global
+    [ wait-loop t ] "Process wait" spawn-server drop ;
 
 M: windows-io register-process
-    drop wait-thread get-global interrupt ;
+    drop wait-flag get-global raise-flag ;
 
 [ start-wait-thread ] "io.windows.launcher" add-init-hook
index 9bc587e00e7513a2f40154ed29376844548a9864..319acc35f8b1c77c029eb7f41831bce67243c014 100755 (executable)
@@ -14,4 +14,4 @@ USE: io.backend
 
 T{ windows-nt-io } set-io-backend
 
-"vocabs.monitor" require
+"tools.vocabs.monitor" require
index 094a6ec0d67d1ffbb692d2393f46a74a6dca0d54..dac55664a4a63c6cfdfb363947323bfe49d7b4b3 100755 (executable)
@@ -76,11 +76,8 @@ M: win32-file close-handle ( handle -- )
     ] when drop ;
 
 : open-append ( path -- handle length )
-    dup file-length dup [
-        >r (open-append) r> 2dup set-file-pointer
-    ] [
-        drop open-write
-    ] if ;
+    [ dup file-info file-info-size ] [ drop 0 ] recover
+    >r (open-append) r> 2dup set-file-pointer ;
 
 TUPLE: FileArgs
     hFile lpBuffer nNumberOfBytesToRead lpNumberOfBytesRet lpOverlapped ;
old mode 100644 (file)
new mode 100755 (executable)
index 8beecc9..42414b9
@@ -59,7 +59,7 @@ M: jamshred-gadget ungraft* ( gadget -- )
 
 USE: vocabs.loader
 jamshred-gadget H{
-    { T{ key-down f f "r" } [ jamshred-restart refresh-all ] }
+    { T{ key-down f f "r" } [ jamshred-restart ] }
     { T{ key-down f f " " } [ jamshred-gadget-jamshred toggle-running ] }
     { T{ motion } [ handle-mouse-motion ] }
 } set-gestures
index ae613bd461009fab3b25a29a0d6c96af8bbc102f..6db68840712a579f7a7f5d94978f7410288e44c6 100755 (executable)
@@ -10,9 +10,9 @@ USING: alien alien.syntax combinators kernel system ;
 IN: ldap.libldap
 
 << "libldap" {
-    { [ win32? ] [ "libldap.dll" "stdcall" ] }
+    { [ win32? ]  [ "libldap.dll" "stdcall" ] }
     { [ macosx? ] [ "libldap.dylib" "cdecl" ] }
-    { [ unix? ] [ "$LD_LIBRARY_PATH/libldap.so" "cdecl" ] }
+    { [ unix? ]   [ "libldap.so" "cdecl" ] }
 } cond add-library >>
  
 : LDAP_VERSION1     1 ; inline
index 956504be2cc4a6e5281c2ccea1a54a421424cf2e..9819e65e37438337b7f97ac7b90bfcddc7a5d387 100755 (executable)
@@ -5,7 +5,7 @@ inference.transforms parser words quotations debugger macros
 arrays macros splitting combinators prettyprint.backend
 definitions prettyprint hashtables combinators.lib
 prettyprint.sections sequences.private effects generic
-compiler.units ;
+compiler.units combinators.cleave ;
 IN: locals
 
 ! Inspired by
@@ -108,8 +108,8 @@ UNION: special local quote local-word local-reader local-writer ;
     if ;
 
 : (point-free) ( quot args -- newquot )
-    { [ load-locals ] [ point-free-body ] [ point-free-end ] }
-    map-call-with2 concat >quotation ;
+    [ load-locals ] [ point-free-body ] [ point-free-end ]
+    2tri 3append >quotation ;
 
 : point-free ( quot args -- newquot )
     over empty? [ drop ] [ (point-free) ] if ;
index d181ab8a169574b4a1af26395cc72b1452569587..372216c45e3d9d4d90eeec9af6f527930cab7294 100755 (executable)
@@ -3,8 +3,8 @@
 USING: namespaces kernel io calendar sequences io.files\r
 io.sockets continuations prettyprint assocs math.parser\r
 words debugger math combinators concurrency.messaging\r
-threads arrays init math.ranges strings calendar.format
-io.encodings.ascii ;\r
+threads arrays init math.ranges strings calendar.format\r
+io.encodings.utf8 ;\r
 IN: logging.server\r
 \r
 : log-root ( -- string )\r
@@ -21,7 +21,7 @@ SYMBOL: log-files
 : open-log-stream ( service -- stream )\r
     log-path\r
     dup make-directories\r
-    1 log# ascii <file-appender> ;\r
+    1 log# utf8 <file-appender> ;\r
 \r
 : log-stream ( service -- stream )\r
     log-files get [ open-log-stream ] cache ;\r
old mode 100644 (file)
new mode 100755 (executable)
index df9a87f..e74ffc6
@@ -1,7 +1,7 @@
-! Copyright (C) 2005, 2007 Slava Pestov.
+! Copyright (C) 2005, 2008 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
 USING: arrays kernel sequences math math.functions
-math.vectors ;
+math.vectors combinators.cleave ;
 IN: math.matrices
 
 ! Matrices
@@ -33,23 +33,22 @@ IN: math.matrices
 : mmax ( m -- n ) >r -1/0. r> [ [ max ] each ] each ;
 : mnorm ( m -- n ) dup mmax abs m/n ;
 
-: cross-i ( vec1 vec2 -- i )
-    over third over second * >r
-    swap second swap third * r> - ;
+<PRIVATE
 
-: cross-j ( vec1 vec2 -- j )
-    over first over third * >r
-    swap third swap first * r> - ;
+: x first ; inline
+: y second ; inline
+: z third ; inline
 
-: cross-k ( vec1 vec2 -- k )
-    over first over second * >r
-    swap second swap first * r> - ;
+: i [ [ y ] [ z ] bi* * ] [ [ z ] [ y ] bi* * ] 2bi - ;
+: j [ [ z ] [ x ] bi* * ] [ [ x ] [ z ] bi* * ] 2bi - ;
+: k [ [ y ] [ x ] bi* * ] [ [ x ] [ y ] bi* * ] 2bi - ;
 
-: cross ( vec1 vec2 -- vec3 )
-    [ cross-i ] 2keep [ cross-j ] 2keep cross-k 3array ;
+PRIVATE>
+
+: cross ( vec1 vec2 -- vec3 ) [ i ] [ j ] [ k ] 2tri 3array ;
 
 : proj ( v u -- w )
-    [ [ v. ] keep norm-sq / ] keep n*v ;
+    [ [ v. ] [ norm-sq ] bi / ] keep n*v ;
 
 : (gram-schmidt) ( v seq -- newseq )
     [ dupd proj v- ] each ;
diff --git a/extra/namespaces/lib/lib-tests.factor b/extra/namespaces/lib/lib-tests.factor
new file mode 100755 (executable)
index 0000000..20769e1
--- /dev/null
@@ -0,0 +1,6 @@
+IN: namespaces.lib.tests\r
+USING: namespaces.lib tools.test ;\r
+\r
+[ ] [ [ ] { } nmake ] unit-test\r
+\r
+[ { 1 } { 2 } ] [ [ 1 0, 2 1, ] { { } { } } nmake ] unit-test\r
old mode 100644 (file)
new mode 100755 (executable)
index 76ba0ac..47b6b33
@@ -2,7 +2,7 @@
 ! USING: kernel quotations namespaces sequences assocs.lib ;
 
 USING: kernel namespaces namespaces.private quotations sequences
-       assocs.lib math.parser math sequences.lib ;
+       assocs.lib math.parser math sequences.lib locals ;
 
 IN: namespaces.lib
 
@@ -42,11 +42,19 @@ SYMBOL: building-seq
 : 4% 4 n% ;
 : 4# 4 n# ;
 
-: nmake ( quot exemplars -- seqs )
-    dup length dup zero? [ 1+ ] when
-    [
+MACRO:: nmake ( quot exemplars -- )
+    [let | n [ exemplars length ] |
         [
-            [ drop 1024 swap new-resizable ] 2map
-            [ building-seq set call ] keep
-        ] 2keep >r [ like ] 2map r> firstn 
-    ] with-scope ;
+            [
+                exemplars
+                [ 0 swap new-resizable ] map
+                building-seq set
+
+                quot call
+
+                building-seq get
+                exemplars [ like ] 2map
+                n firstn
+            ] with-scope
+        ]
+    ] ;
old mode 100644 (file)
new mode 100755 (executable)
index 59b7a3b..8fee559
@@ -1,5 +1,5 @@
 USING: arrays combinators.lib kernel math math.functions math.vectors namespaces
-       opengl opengl.gl sequences ui ui.gadgets ui.gestures ui.render ;
+       opengl opengl.gl sequences ui ui.gadgets ui.gestures ui.render combinators.cleave ;
 IN: opengl.demo-support
 
 : NEAR-PLANE 1.0 64.0 / ; inline
@@ -47,14 +47,15 @@ M: demo-gadget pref-dim* ( gadget -- dim )
     GL_COLOR_BUFFER_BIT GL_DEPTH_BUFFER_BIT bitor glClear
     GL_MODELVIEW glMatrixMode
     glLoadIdentity
-    { [ >r 0.0 0.0 r> demo-gadget-distance neg glTranslatef ]
-      [ demo-gadget-pitch 1.0 0.0 0.0 glRotatef ]
-      [ demo-gadget-yaw   0.0 1.0 0.0 glRotatef ] } call-with ;
+    [ >r 0.0 0.0 r> demo-gadget-distance neg glTranslatef ]
+    [ demo-gadget-pitch 1.0 0.0 0.0 glRotatef ]
+    [ demo-gadget-yaw   0.0 1.0 0.0 glRotatef ]
+    tri ;
 
 : reset-last-drag-rel ( -- )
-    { 0 0 } last-drag-loc set ;
+    { 0 0 } last-drag-loc set-global ;
 : last-drag-rel ( -- rel )
-    drag-loc [ last-drag-loc get v- ] keep last-drag-loc set ;
+    drag-loc [ last-drag-loc get v- ] keep last-drag-loc set-global ;
 
 : drag-yaw-pitch ( -- yaw pitch )
     last-drag-rel MOUSE-MOTION-SCALE v*n first2 ;
diff --git a/extra/opengl/gl/gl-docs.factor b/extra/opengl/gl/gl-docs.factor
new file mode 100644 (file)
index 0000000..84004cb
--- /dev/null
@@ -0,0 +1,70 @@
+
+USING: help.syntax help.markup ;
+
+IN: opengl.gl
+
+ARTICLE: "opengl-low-level" "OpenGL Library (low level)"
+  { $subsection "opengl-specifying-vertices" }
+  { $subsection "opengl-geometric-primitives" } ;  
+
+ARTICLE: "opengl-specifying-vertices" "Specifying Vertices"
+
+  { $subsection glVertex2d }
+  { $subsection glVertex2f }
+  { $subsection glVertex2i }
+  { $subsection glVertex2s }
+  { $subsection glVertex3d }
+  { $subsection glVertex3f }
+  { $subsection glVertex3i }
+  { $subsection glVertex3s }
+  { $subsection glVertex4d }
+  { $subsection glVertex4f }
+  { $subsection glVertex4i }
+  { $subsection glVertex4s }
+  { $subsection glVertex2dv }
+  { $subsection glVertex2fv }
+  { $subsection glVertex2iv }
+  { $subsection glVertex2sv }
+  { $subsection glVertex3dv }
+  { $subsection glVertex3fv }
+  { $subsection glVertex3iv }
+  { $subsection glVertex3sv }
+  { $subsection glVertex4dv }
+  { $subsection glVertex4fv }
+  { $subsection glVertex4iv }
+  { $subsection glVertex4sv } ;
+
+ARTICLE: "opengl-geometric-primitives" "OpenGL Geometric Primitives"
+
+  { $table
+      { { $link GL_POINTS         } "individual points" }
+      { { $link GL_LINES          } { "pairs of vertices interpreted as "
+                                      "individual line segments" } }
+      { { $link GL_LINE_STRIP     } "series of connected line segments" }
+      { { $link GL_LINE_LOOP      } { "same as above, with a segment added "
+                                      "between last and first vertices" } }
+      { { $link GL_TRIANGLES      }
+        "triples of vertices interpreted as triangles" }
+      { { $link GL_TRIANGLE_STRIP } "linked strip of triangles" }
+      { { $link GL_TRIANGLE_FAN   } "linked fan of triangles" }
+      { { $link GL_QUADS          }
+        "quadruples of vertices interpreted as four-sided polygons" }
+      { { $link GL_QUAD_STRIP     } "linked strip of quadrilaterals" }
+      { { $link GL_POLYGON        } "boundary of a simple, convex polygon" } }
+
+;
+
+HELP: glBegin
+  { $values { "mode"
+              { "One of the " { $link "opengl-geometric-primitives" } } } } ;
+
+HELP: glPolygonMode
+  { $values { "face" { "One of the following:"
+                       { $list { $link GL_FRONT }
+                               { $link GL_BACK }
+                               { $link GL_FRONT_AND_BACK } } } }
+            { "mode" { "One of the following:"
+                       { $list
+                         { $link GL_POINT }
+                         { $link GL_LINE }
+                         { $link GL_FILL } } } } } ;
\ No newline at end of file
index 97120237ecf88ff4547fd20fca35de63989e20cd..5b1ee0d565ed43c9ce9e39de50eee1ddbe959ce6 100644 (file)
@@ -10,7 +10,11 @@ HELP: gl-error
 { $description "If the most recent OpenGL call resulted in an error, print the error to the " { $link stdio } " stream." } ;
 
 HELP: do-state
-{ $values { "what" integer } { "quot" quotation } }
+  {
+    $values
+      { "mode" { "One of the " { $link "opengl-geometric-primitives" } } }
+      { "quot" quotation }
+  }
 { $description "Wraps a quotation in " { $link glBegin } "/" { $link glEnd } " calls." } ;
 
 HELP: do-enabled
index 5afb6ef0702a1f46a93850640a95b084ad0906fd..08e3cb204b35a193e95681150f7d3213610a760e 100755 (executable)
@@ -25,7 +25,7 @@ IN: opengl
         "GL error: " over gluErrorString append throw
     ] unless drop ;
 
-: do-state ( what quot -- )
+: do-state ( mode quot -- )
     swap glBegin call glEnd ; inline
 
 : do-enabled ( what quot -- )
old mode 100644 (file)
new mode 100755 (executable)
index fbbc4c4..ceda434
@@ -2,7 +2,7 @@
 ! See http://factorcode.org/license.txt for BSD license.
 USING: kernel opengl.gl alien.c-types continuations namespaces
 assocs alien libc opengl math sequences combinators.lib 
-macros arrays ;
+macros arrays combinators.cleave ;
 IN: opengl.shaders
 
 : with-gl-shader-source-ptr ( string quot -- )
@@ -117,7 +117,7 @@ PREDICATE: gl-shader fragment-shader (fragment-shader?) ;
 : (make-with-gl-program) ( uniforms quot -- q )
     [
         \ dup ,
-        [ swap (with-gl-program-uniforms) , \ call-with , % ]
+        [ swap (with-gl-program-uniforms) , \ cleave , % ]
         [ ] make ,
         \ (with-gl-program) ,
     ] [ ] make ;
index 8378a1195617d1740ca7364d21a277d37c016fcb..bc65f7243549f59e6cb9b51b917272be24738ad4 100755 (executable)
@@ -9,11 +9,13 @@ USING: alien alien.syntax combinators kernel system ;
 
 IN: openssl.libcrypto
 
+<<
 "libcrypto" {
-    { [ win32? ] [ "libeay32.dll" "stdcall" ] }
+    { [ win32? ]  [ "libeay32.dll" "stdcall" ] }
     { [ macosx? ] [ "libcrypto.dylib" "cdecl" ] }
-    { [ unix? ] [ "$LD_LIBRARY_PATH/libcrypto.so" "cdecl" ] }
+    { [ unix? ]   [ "libcrypto.so" "cdecl" ] }
 } cond add-library
+>>
 
 C-STRUCT: bio-method
     { "int" "type" }
index 8d1b3b524704364f8f6ac8d0aa756d9bbfe07daa..d8709cbf539a61ba37169431fd681198f31b8b5c 100644 (file)
@@ -10,9 +10,9 @@ USING: alien alien.syntax combinators kernel system ;
 IN: openssl.libssl
 
 << "libssl" {
-    { [ win32? ] [ "ssleay32.dll" "stdcall" ] }
+    { [ win32? ]  [ "ssleay32.dll" "stdcall" ] }
     { [ macosx? ] [ "libssl.dylib" "cdecl" ] }
-    { [ unix? ] [ "$LD_LIBRARY_PATH/libssl.so" "cdecl" ] }
+    { [ unix? ]   [ "libssl.so" "cdecl" ] }
 } cond add-library >>
 
 : X509_FILETYPE_PEM       1 ; inline
index a2958d5beacf2673bec4de2f3b9d36c8a83f8a96..f5ba0fd11defd38f7afed143cbb94727756b0383 100755 (executable)
@@ -88,7 +88,7 @@ M: string b, ( n string -- ) heap-size b, ;
     read [ zero? ] right-trim dup empty? [ drop f ] when ;
 
 : (read-128-ber) ( n -- n )
-    1 read first
+    read1
     [ >r 7 shift r> 7 clear-bit bitor ] keep
     7 bit? [ (read-128-ber) ] when ;
     
diff --git a/extra/pdf/authors.txt b/extra/pdf/authors.txt
deleted file mode 100644 (file)
index 7c29e7c..0000000
+++ /dev/null
@@ -1 +0,0 @@
-Elie Chaftari
diff --git a/extra/pdf/libhpdf/libhpdf.factor b/extra/pdf/libhpdf/libhpdf.factor
deleted file mode 100644 (file)
index a40b7cd..0000000
+++ /dev/null
@@ -1,180 +0,0 @@
-! Copyright (C) 2007 Elie CHAFTARI
-! See http://factorcode.org/license.txt for BSD license.
-!
-! Tested with libharu2 2.0.8 on Mac OS X 10.4.9 PowerPC
-!
-! export LD_LIBRARY_PATH=/opt/local/lib
-
-USING: alien alien.syntax combinators system ;
-
-IN: pdf.libhpdf
-
-<< "libhpdf" {
-    { [ win32? ] [ "libhpdf.dll" "stdcall" ] }
-    { [ macosx? ] [ "libhpdf.dylib" "cdecl" ] }
-    { [ unix? ] [ "$LD_LIBRARY_PATH/libhpdf.so" "cdecl" ] }
-} cond add-library >>
-
-! compression mode
-: HPDF_COMP_NONE      HEX: 00 ; inline ! No contents are compressed
-: HPDF_COMP_TEXT      HEX: 01 ; inline ! Compress contents stream of page
-: HPDF_COMP_IMAGE     HEX: 02 ; inline ! Compress streams of image objects
-: HPDF_COMP_METADATA  HEX: 04 ; inline ! Compress other data (fonts, cmaps...)
-: HPDF_COMP_ALL       HEX: 0F ; inline ! All stream data are compressed
-: HPDF_COMP_MASK      HEX: FF ; inline
-
-! page mode
-C-ENUM:
-    HPDF_PAGE_MODE_USE_NONE
-    HPDF_PAGE_MODE_USE_OUTLINE
-    HPDF_PAGE_MODE_USE_THUMBS
-    HPDF_PAGE_MODE_FULL_SCREEN
-    HPDF_PAGE_MODE_EOF
-;
-
-: error-code ( -- seq ) {
-     { HEX: 1001  "HPDF_ARRAY_COUNT_ERR\nInternal error. The consistency of the data was lost." }
-     { HEX: 1002  "HPDF_ARRAY_ITEM_NOT_FOUND\nInternal error. The consistency of the data was lost." }
-     { HEX: 1003  "HPDF_ARRAY_ITEM_UNEXPECTED_TYPE\nInternal error. The consistency of the data was lost." }
-     { HEX: 1004  "HPDF_BINARY_LENGTH_ERR\nThe length of the data exceeds HPDF_LIMIT_MAX_STRING_LEN." }
-     { HEX: 1005  "HPDF_CANNOT_GET_PALLET\nCannot get a pallet data from PNG image." }
-     { HEX: 1007  "HPDF_DICT_COUNT_ERR\nThe count of elements of a dictionary exceeds HPDF_LIMIT_MAX_DICT_ELEMENT" }
-     { HEX: 1008  "HPDF_DICT_ITEM_NOT_FOUND\nInternal error. The consistency of the data was lost." }
-     { HEX: 1009  "HPDF_DICT_ITEM_UNEXPECTED_TYPE\nInternal error. The consistency of the data was lost." }  
-     { HEX: 100A  "HPDF_DICT_STREAM_LENGTH_NOT_FOUND\nInternal error. The consistency of the data was lost." }  
-     { HEX: 100B  "HPDF_DOC_ENCRYPTDICT_NOT_FOUND\nHPDF_SetPermission() OR HPDF_SetEncryptMode() was called before a password is set." }
-     { HEX: 100C  "HPDF_DOC_INVALID_OBJECT\nInternal error. The consistency of the data was lost." }
-     { HEX: 100E  "HPDF_DUPLICATE_REGISTRATION\nTried to register a font that has been registered." }
-     { HEX: 100F  "HPDF_EXCEED_JWW_CODE_NUM_LIMIT\nCannot register a character to the japanese word wrap characters list." }
-     { HEX: 1011  "HPDF_ENCRYPT_INVALID_PASSWORD\nTried to set the owner password to NULL. owner password and user password is the same." }
-     { HEX: 1013  "HPDF_ERR_UNKNOWN_CLASS\nInternal error. The consistency of the data was lost." }
-     { HEX: 1014  "HPDF_EXCEED_GSTATE_LIMIT\nThe depth of the stack exceeded HPDF_LIMIT_MAX_GSTATE." }
-     { HEX: 1015  "HPDF_FAILED_TO_ALLOC_MEM\nMemory allocation failed." }
-     { HEX: 1016  "HPDF_FILE_IO_ERROR\nFile processing failed. (A detailed code is set.)" }
-     { HEX: 1017  "HPDF_FILE_OPEN_ERROR\nCannot open a file. (A detailed code is set.)" }
-     { HEX: 1019  "HPDF_FONT_EXISTS\nTried to load a font that has already been registered." }
-     { HEX: 101A  "HPDF_FONT_INVALID_WIDTHS_TABLE\nThe format of a font-file is invalid . Internal error. The consistency of the data was lost." }
-     { HEX: 101B  "HPDF_INVALID_AFM_HEADER\nCannot recognize a header of an afm file." }
-     { HEX: 101C  "HPDF_INVALID_ANNOTATION\nThe specified annotation handle is invalid." }
-     { HEX: 101E  "HPDF_INVALID_BIT_PER_COMPONENT\nBit-per-component of a image which was set as mask-image is invalid." }
-     { HEX: 101F  "HPDF_INVALID_CHAR_MATRICS_DATA\nCannot recognize char-matrics-data  of an afm file." }
-     { HEX: 1020  "HPDF_INVALID_COLOR_SPACE\n1. The color_space parameter of HPDF_LoadRawImage is invalid.\n2. Color-space of a image which was set as mask-image is invalid.\n3. The function which is invalid in the present color-space was invoked." }
-     { HEX: 1021  "HPDF_INVALID_COMPRESSION_MODE\nInvalid value was set when invoking HPDF_SetCommpressionMode()." }
-     { HEX: 1022  "HPDF_INVALID_DATE_TIME\nAn invalid date-time value was set." }
-     { HEX: 1023  "HPDF_INVALID_DESTINATION\nAn invalid destination handle was set." }
-     { HEX: 1025  "HPDF_INVALID_DOCUMENT\nAn invalid document handle is set." }
-     { HEX: 1026  "HPDF_INVALID_DOCUMENT_STATE\nThe function which is invalid in the present state was invoked." }
-     { HEX: 1027  "HPDF_INVALID_ENCODER\nAn invalid encoder handle was set." }
-     { HEX: 1028  "HPDF_INVALID_ENCODER_TYPE\nA combination between font and encoder is wrong." }
-     { HEX: 102B  "HPDF_INVALID_ENCODING_NAME\nAn Invalid encoding name is specified." }
-     { HEX: 102C  "HPDF_INVALID_ENCRYPT_KEY_LEN\nThe lengh of the key of encryption is invalid." }
-     { HEX: 102D  "HPDF_INVALID_FONTDEF_DATA\n1. An invalid font handle was set.\n2. Unsupported font format." }
-     { HEX: 102E  "HPDF_INVALID_FONTDEF_TYPE\nInternal error. The consistency of the data was lost." }
-     { HEX: 102F  "HPDF_INVALID_FONT_NAME\nA font which has the specified name is not found." }
-     { HEX: 1030  "HPDF_INVALID_IMAGE\nUnsupported image format." }
-     { HEX: 1031  "HPDF_INVALID_JPEG_DATA\nUnsupported image format." }
-     { HEX: 1032  "HPDF_INVALID_N_DATA\nCannot read a postscript-name from an afm file." }
-     { HEX: 1033  "HPDF_INVALID_OBJECT\n1. An invalid object is set.\n2. Internal error. The consistency of the data was lost." }
-     { HEX: 1034  "HPDF_INVALID_OBJ_ID\nInternal error. The consistency of the data was lost." }
-     { HEX: 1035  "HPDF_INVALID_OPERATION\nInvoked HPDF_Image_SetColorMask() against the image-object which was set a mask-image." }
-     { HEX: 1036  "HPDF_INVALID_OUTLINE\nAn invalid outline-handle was specified." }
-     { HEX: 1037  "HPDF_INVALID_PAGE\nAn invalid page-handle was specified." }
-     { HEX: 1038  "HPDF_INVALID_PAGES\nAn invalid pages-handle was specified. (internal error)" }
-     { HEX: 1039  "HPDF_INVALID_PARAMETER\nAn invalid value is set." }
-     { HEX: 103B  "HPDF_INVALID_PNG_IMAGE\nInvalid PNG image format." }
-     { HEX: 103C  "HPDF_INVALID_STREAM\nInternal error. The consistency of the data was lost." }
-     { HEX: 103D  "HPDF_MISSING_FILE_NAME_ENTRY\nInternal error. The \"_FILE_NAME\" entry for delayed loading is missing." }
-     { HEX: 103F  "HPDF_INVALID_TTC_FILE\nInvalid .TTC file format." }
-     { HEX: 1040  "HPDF_INVALID_TTC_INDEX\nThe index parameter was exceed the number of included fonts" }
-     { HEX: 1041  "HPDF_INVALID_WX_DATA\nCannot read a width-data from an afm file." }
-     { HEX: 1042  "HPDF_ITEM_NOT_FOUND\nInternal error. The consistency of the data was lost." }
-     { HEX: 1043  "HPDF_LIBPNG_ERROR\nAn error has returned from PNGLIB while loading an image." }
-     { HEX: 1044  "HPDF_NAME_INVALID_VALUE\nInternal error. The consistency of the data was lost." }
-     { HEX: 1045  "HPDF_NAME_OUT_OF_RANGE\nInternal error. The consistency of the data was lost." }
-     { HEX: 1049  "HPDF_PAGES_MISSING_KIDS_ENTRY\nInternal error. The consistency of the data was lost." }
-     { HEX: 104A  "HPDF_PAGE_CANNOT_FIND_OBJECT\nInternal error. The consistency of the data was lost." }
-     { HEX: 104B  "HPDF_PAGE_CANNOT_GET_ROOT_PAGES\nInternal error. The consistency of the data was lost." }
-     { HEX: 104C  "HPDF_PAGE_CANNOT_RESTORE_GSTATE\nThere are no graphics-states to be restored." }
-     { HEX: 104D  "HPDF_PAGE_CANNOT_SET_PARENT\nInternal error. The consistency of the data was lost." }
-     { HEX: 104E  "HPDF_PAGE_FONT_NOT_FOUND\nThe current font is not set." }
-     { HEX: 104F  "HPDF_PAGE_INVALID_FONT\nAn invalid font-handle was specified." }
-     { HEX: 1050  "HPDF_PAGE_INVALID_FONT_SIZE\nAn invalid font-size was set." }
-     { HEX: 1051  "HPDF_PAGE_INVALID_GMODE\nSee Graphics mode." }
-     { HEX: 1052  "HPDF_PAGE_INVALID_INDEX\nInternal error. The consistency of the data was lost." }
-     { HEX: 1053  "HPDF_PAGE_INVALID_ROTATE_VALUE\nThe specified value is not a multiple of 90." }
-     { HEX: 1054  "HPDF_PAGE_INVALID_SIZE\nAn invalid page-size was set." }
-     { HEX: 1055  "HPDF_PAGE_INVALID_XOBJECT\nAn invalid image-handle was set." }
-     { HEX: 1056  "HPDF_PAGE_OUT_OF_RANGE\nThe specified value is out of range." }
-     { HEX: 1057  "HPDF_REAL_OUT_OF_RANGE\nThe specified value is out of range." }
-     { HEX: 1058  "HPDF_STREAM_EOF\nUnexpected EOF marker was detected." }
-     { HEX: 1059  "HPDF_STREAM_READLN_CONTINUE\nInternal error. The consistency of the data was lost." }
-     { HEX: 105B  "HPDF_STRING_OUT_OF_RANGE\nThe length of the specified text is too long." }
-     { HEX: 105C  "HPDF_THIS_FUNC_WAS_SKIPPED\nThe execution of a function was skipped because of other errors." }
-     { HEX: 105D  "HPDF_TTF_CANNOT_EMBEDDING_FONT\nThis font cannot be embedded. (restricted by license.)" }
-     { HEX: 105E  "HPDF_TTF_INVALID_CMAP\nUnsupported ttf format. (cannot find unicode cmap.)" }
-     { HEX: 105F  "HPDF_TTF_INVALID_FOMAT\nUnsupported ttf format." }
-     { HEX: 1060  "HPDF_TTF_MISSING_TABLE\nUnsupported ttf format. (cannot find a necessary table.)" }
-     { HEX: 1061  "HPDF_UNSUPPORTED_FONT_TYPE\nInternal error. The consistency of the data was lost." }
-     { HEX: 1062  "HPDF_UNSUPPORTED_FUNC\n1. The library is not configured to use PNGLIB.\n2. Internal error. The consistency of the data was lost." }
-     { HEX: 1063  "HPDF_UNSUPPORTED_JPEG_FORMAT\nUnsupported Jpeg format." }
-     { HEX: 1064  "HPDF_UNSUPPORTED_TYPE1_FONT\nFailed to parse .PFB file." }
-     { HEX: 1065  "HPDF_XREF_COUNT_ERR\nInternal error. The consistency of the data was lost." }
-     { HEX: 1066  "HPDF_ZLIB_ERROR\nAn error has occurred while executing a function of Zlib." }
-     { HEX: 1067  "HPDF_INVALID_PAGE_INDEX\nAn error returned from Zlib." }
-     { HEX: 1068  "HPDF_INVALID_URI\nAn invalid URI was set." }
-     { HEX: 1069  "HPDF_PAGELAYOUT_OUT_OF_RANGE\nAn invalid page-layout was set." }
-     { HEX: 1070  "HPDF_PAGEMODE_OUT_OF_RANGE\nAn invalid page-mode was set." }
-     { HEX: 1071  "HPDF_PAGENUM_STYLE_OUT_OF_RANGE\nAn invalid page-num-style was set." }
-     { HEX: 1072  "HPDF_ANNOT_INVALID_ICON\nAn invalid icon was set." }
-     { HEX: 1073  "HPDF_ANNOT_INVALID_BORDER_STYLE\nAn invalid border-style was set." }
-     { HEX: 1074  "HPDF_PAGE_INVALID_DIRECTION\nAn invalid page-direction was set." }
-     { HEX: 1075  "HPDF_INVALID_FONT\nAn invalid font-handle was specified." }
-} ;
-
-LIBRARY: libhpdf
-
-! ===============================================
-! hpdf.h
-! ===============================================
-
-FUNCTION: void* HPDF_New ( void* user_error_fn, void* user_data ) ;
-
-FUNCTION: void* HPDF_Free ( void* pdf ) ;
-
-FUNCTION: ulong HPDF_SetCompressionMode ( void* pdf, uint mode ) ;
-
-FUNCTION: ulong HPDF_SetPageMode ( void* pdf, uint mode ) ;
-
-FUNCTION: void* HPDF_AddPage ( void* pdf ) ;
-
-FUNCTION: ulong HPDF_SaveToFile ( void* pdf, char* file_name ) ;
-
-FUNCTION: float HPDF_Page_GetHeight ( void* page ) ;
-
-FUNCTION: float HPDF_Page_GetWidth ( void* page ) ;
-
-FUNCTION: ulong HPDF_Page_SetLineWidth ( void* page, float line_width ) ;
-
-FUNCTION: ulong HPDF_Page_Rectangle ( void* page, float x, float y,
-                                      float width, float height ) ;
-
-FUNCTION: ulong HPDF_Page_Stroke ( void* page ) ;
-
-FUNCTION: void* HPDF_GetFont ( void* pdf, char* font_name,
-                               char* encoding_name ) ;
-
-FUNCTION: ulong HPDF_Page_SetFontAndSize ( void* page, void* font,
-                                           float size ) ;
-
-FUNCTION: float HPDF_Page_TextWidth ( void* page, char* text ) ;
-
-FUNCTION: ulong HPDF_Page_BeginText ( void* page ) ;
-
-FUNCTION: ulong HPDF_Page_TextOut ( void* page, float xpos, float ypos,
-                                    char* text ) ;
-
-FUNCTION: ulong HPDF_Page_EndText ( void*  page ) ;
-
-FUNCTION: ulong HPDF_Page_MoveTextPos ( void* page, float x, float y ) ;
-
-FUNCTION: ulong HPDF_Page_ShowText ( void* page, char* text ) ;
diff --git a/extra/pdf/pdf-tests.factor b/extra/pdf/pdf-tests.factor
deleted file mode 100755 (executable)
index 290773a..0000000
+++ /dev/null
@@ -1,98 +0,0 @@
-USING: io.files kernel math namespaces pdf pdf.libhpdf prettyprint sequences ;
-IN: pdf.tests
-
-SYMBOL: font
-
-SYMBOL: width
-SYMBOL: height
-SYMBOL: twidth
-
-: font-list ( -- seq ) {
-    "Courier"
-    "Courier-Bold"
-    "Courier-Oblique"
-    "Courier-BoldOblique"
-    "Helvetica"
-    "Helvetica-Bold"
-    "Helvetica-Oblique"
-    "Helvetica-BoldOblique"
-    "Times-Roman"
-    "Times-Bold"
-    "Times-Italic"
-    "Times-BoldItalic"
-    "Symbol"
-    "ZapfDingbats"
-} ;
-
-[
-    ! HPDF_COMP_ALL set-compression-mode
-
-    ! HPDF_PAGE_MODE_USE_OUTLINE set-page-mode
-
-    ! Add a new page object
-    add-page
-
-    get-page-height height set
-
-    get-page-width width set
-
-    ! Print the lines of the page
-    1 set-page-line-width
-
-    50 50 width get 100 - height get 110 - page-rectangle
-
-    page-stroke
-
-    ! Print the title of the page (with positioning center)
-    "Helvetica" f get-font font set
-
-    font get 24 set-page-font-and-size
-
-    "Font Demo" page-text-width twidth set
-
-    [
-        width get twidth get - 2 / height get 50 - "Font Demo" page-text-out
-
-    ] with-text
-
-    ! Print subtitle
-    [
-        font get 16 set-page-font-and-size
-
-        60 height get 80 - "<Standard Type1 font samples>" page-text-out
-
-    ] with-text
-
-    ! Print font list
-    [
-        60 height get 105 - page-move-text-pos
-
-        SYMBOL: fontname
-
-        font-list [
-
-            fontname set
-
-            fontname get f get-font font set
-
-            ! print a label of text
-            font get 9 set-page-font-and-size
-
-            fontname get page-show-text
-
-            0 -18 page-move-text-pos
-
-            ! print a sample text
-            font get 20 set-page-font-and-size
-
-            "abcdefgABCDEFG12345!#$%&+-@?" page-show-text
-
-            0 -20 page-move-text-pos
-
-        ] each
-
-    ] with-text
-
-    "font_test.pdf" temp-file save-to-file
-
-] with-pdf
diff --git a/extra/pdf/pdf.factor b/extra/pdf/pdf.factor
deleted file mode 100644 (file)
index 98c94e5..0000000
+++ /dev/null
@@ -1,97 +0,0 @@
-! Copyright (C) 2007 Elie CHAFTARI
-! See http://factorcode.org/license.txt for BSD license.
-!
-! Tested with libharu2 2.0.8 on Mac OS X 10.4.9 PowerPC
-
-USING: assocs continuations hashtables kernel math namespaces pdf.libhpdf ;
-
-IN: pdf
-
-SYMBOL: pdf
-SYMBOL: page
-
-! =========================================================
-! Error handling routines
-! =========================================================
-
-: check-status ( status -- )
-    dup zero? [ 
-        drop
-    ] [
-        error-code >hashtable at throw   
-    ] if ;
-
-! =========================================================
-! Document handling routines
-! =========================================================
-
-: new-pdf ( error-handler user-data -- )
-    HPDF_New pdf set ;
-
-: free-pdf ( -- )
-    pdf get HPDF_Free drop ;
-
-: with-pdf ( quot -- )
-    [ f f new-pdf [ free-pdf ] [ ] cleanup ] with-scope ; inline
-
-: set-compression-mode ( mode -- )
-    pdf get swap HPDF_SetCompressionMode check-status ;
-
-: set-page-mode ( mode -- )
-    pdf get swap HPDF_SetPageMode check-status ;
-
-: add-page ( -- )
-    pdf get HPDF_AddPage page set ;
-
-: save-to-file ( filename -- )
-    pdf get swap HPDF_SaveToFile check-status ;
-
-: get-font ( fontname encoding -- font )
-    pdf get -rot HPDF_GetFont ;
-
-! =========================================================
-! Page Handling routines
-! =========================================================
-
-: get-page-height ( -- height )
-    page get HPDF_Page_GetHeight ;
-
-: get-page-width ( -- width )
-    page get HPDF_Page_GetWidth ;
-
-: page-text-width ( text -- width )
-    page get swap HPDF_Page_TextWidth ;
-
-! =========================================================
-! Graphics routines
-! =========================================================
-
-: set-page-line-width ( linewidth -- )
-    page get swap HPDF_Page_SetLineWidth check-status ;
-
-: page-rectangle ( x y width height -- )
-    >r >r >r >r page get r> r> r> r> HPDF_Page_Rectangle check-status ;
-
-: page-stroke ( -- )
-    page get HPDF_Page_Stroke check-status ;
-
-: set-page-font-and-size ( font size -- )
-    page get -rot HPDF_Page_SetFontAndSize check-status ;
-
-: page-begin-text ( -- )
-    page get HPDF_Page_BeginText check-status ;
-
-: page-text-out ( xpos ypos text -- )
-    page get -roll HPDF_Page_TextOut check-status ;
-
-: page-end-text ( -- )
-    page get HPDF_Page_EndText check-status ;
-
-: with-text ( -- )
-    [ page-begin-text [ page-end-text ] [ ] cleanup ] with-scope ; inline
-
-: page-move-text-pos ( x y -- )
-    page get -rot HPDF_Page_MoveTextPos check-status ;
-
-: page-show-text ( text -- )
-    page get swap HPDF_Page_ShowText check-status ;
diff --git a/extra/pdf/readme.txt b/extra/pdf/readme.txt
deleted file mode 100644 (file)
index fd52944..0000000
+++ /dev/null
@@ -1,9 +0,0 @@
-To build libharu as a shared dylib on Mac OS X, modify the Makefile after calling ./configure --shared\r\rHere are the relevant sections and the lines to be changed:\r\r...\rCC=cc\rPREFIX=/usr/local\r\rLIBNAME=libhpdf.a\rSONAME=libhpdf.dylib\rSOVER1=.1\rSOVER2=.0.0\rLIBTARGET=libhpdf.dylib\rCFLAGS=-Iinclude -fPIC -fno-common -c\r...\r$(SONAME): $(OBJS)\r$(CC) -dynamiclib -o $(SONAME)$(SOVER1)$(SOVER2) $(OBJS) $(LDFLAGS) -Wl\rln -sf $(SONAME)$(SOVER1)$(SOVER2) $(SONAME)$(SOVER1)\rln -sf $(SONAME)$(SOVER1) $(SONAME)
-
-Now you can build and install:
-
-make clean
-make
-make install
-
-Test PDF files from pdf-tests.factor are generated in the test folder.
\ No newline at end of file
index b19c2f39c9ee15e18e6b9344cd9c772766af11e4..6e6a92438215c045755955944975be6433c2bab9 100755 (executable)
@@ -79,3 +79,6 @@ IN: sequences.lib.tests
 [ { 910 911 912 } ] [ 10 900 3 [ + + ] map-with2 ] unit-test
 
 [ 1 2 3 4 ] [ { 1 2 3 4 } 4 firstn ] unit-test
+
+[ ] [ { } 0 firstn ] unit-test
+[ "a" ] [ { "a" } 1 firstn ] unit-test
index 050de0ae1c41671cbe053b6ca04d4f1ff7cf0e0f..a6b6b7314833b2df9c8df62c9fd86b7e111aa890 100755 (executable)
@@ -3,7 +3,8 @@
 ! See http://factorcode.org/license.txt for BSD license.
 USING: combinators.lib kernel sequences math namespaces assocs 
 random sequences.private shuffle math.functions mirrors
-arrays math.parser math.private sorting strings ascii macros ;
+arrays math.parser math.private sorting strings ascii macros
+assocs.lib quotations ;
 IN: sequences.lib
 
 : each-withn ( seq quot n -- ) nwith each ; inline
@@ -19,8 +20,9 @@ IN: sequences.lib
 : map-with2 ( obj obj list quot -- newseq ) 2 map-withn ; inline
 
 MACRO: firstn ( n -- )
-    [ [ swap nth ] curry
-    [ keep ] curry ] map concat [ drop ] compose ;
+    [ [ swap nth ] curry [ keep ] curry ] map
+    concat >quotation
+    [ drop ] compose ;
 
 : prepare-index ( seq quot -- seq n quot )
     >r dup length r> ; inline
@@ -192,7 +194,7 @@ USE: continuations
 : ?tail* ( seq n -- seq/f ) (tail) ?subseq ;
 
 : accumulator ( quot -- quot vec )
-    V{ } clone [ [ push ] curry compose ] keep ;
+    V{ } clone [ [ push ] curry compose ] keep ; inline
 
 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
 
@@ -220,3 +222,6 @@ PRIVATE>
 
 : nths ( indices seq -- seq' )
     [ swap nth ] with map ;
+
+: replace ( str oldseq newseq -- str' )
+    H{ } 2seq>assoc substitute ;
index de60bed20bf8e8cca929ee31177934e450d99c65..11a06f46bc685bd9e1c0a020f2668f892d4a436f 100755 (executable)
@@ -1,13 +1,14 @@
 USING: tools.deploy.config ;
 H{
-    { deploy-reflection 2 }
-    { deploy-word-props? f }
+    { deploy-name "Sudoku" }
+    { deploy-threads? f }
+    { deploy-c-types? f }
     { deploy-compiler? t }
+    { deploy-ui? f }
     { deploy-math? f }
-    { deploy-c-types? f }
+    { deploy-reflection 1 }
+    { deploy-word-defs? f }
     { deploy-io 2 }
-    { deploy-ui? f }
-    { deploy-name "Sudoku" }
+    { deploy-word-props? f }
     { "stop-after-last-window?" t }
-    { deploy-word-defs? f }
 }
old mode 100644 (file)
new mode 100755 (executable)
index 84a6150..0eacbbf
@@ -1,7 +1,15 @@
-USING: kernel symbols tools.test ;
+USING: kernel symbols tools.test parser generic words ;
 IN: symbols.tests
 
 [ ] [ SYMBOLS: a b c ; ] unit-test
 [ a ] [ a ] unit-test
 [ b ] [ b ] unit-test
 [ c ] [ c ] unit-test
+
+DEFER: blah
+
+[ ] [ "IN: symbols.tests GENERIC: blah" eval ] unit-test
+[ ] [ "IN: symbols.tests USE: symbols SYMBOLS: blah ;" eval ] unit-test
+
+[ f ] [ \ blah generic? ] unit-test
+[ t ] [ \ blah symbol? ] unit-test
old mode 100644 (file)
new mode 100755 (executable)
index 8e074f4..f6254f1
@@ -1,8 +1,9 @@
-! Copyright (C) 2008 Slava Pestov.
+! Copyright (C) 2008 Doug Coleman.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: parser sequences words ;
+USING: parser sequences words kernel ;
 IN: symbols
 
 : SYMBOLS:
-    ";" parse-tokens [ create-in define-symbol ] each ;
+    ";" parse-tokens
+    [ create-in dup reset-generic define-symbol ] each ;
     parsing
diff --git a/extra/tools/browser/authors.txt b/extra/tools/browser/authors.txt
deleted file mode 100755 (executable)
index 1901f27..0000000
+++ /dev/null
@@ -1 +0,0 @@
-Slava Pestov
diff --git a/extra/tools/browser/browser-docs.factor b/extra/tools/browser/browser-docs.factor
deleted file mode 100755 (executable)
index 28bef58..0000000
+++ /dev/null
@@ -1,52 +0,0 @@
-USING: help.markup help.syntax io strings ;
-IN: tools.browser
-
-ARTICLE: "vocab-index" "Vocabulary index"
-{ $tags }
-{ $authors }
-{ $describe-vocab "" } ;
-
-ARTICLE: "tools.browser" "Vocabulary browser"
-"Getting and setting vocabulary meta-data:"
-{ $subsection vocab-file-contents }
-{ $subsection set-vocab-file-contents }
-{ $subsection vocab-summary }
-{ $subsection set-vocab-summary }
-{ $subsection vocab-tags }
-{ $subsection set-vocab-tags }
-{ $subsection add-vocab-tags }
-"Global meta-data:"
-{ $subsection all-vocabs }
-{ $subsection all-vocabs-seq }
-{ $subsection all-tags }
-{ $subsection all-authors }
-"Because loading the above data is expensive, it is cached. The cache is flushed by the " { $vocab-link "vocabs.monitor" } " vocabulary. It can also be flushed manually when file system change monitors are not available:"
-{ $subsection reset-cache } ;
-
-HELP: vocab-file-contents
-{ $values { "vocab" "a vocabulary specifier" } { "name" string } { "seq" "a sequence of lines, or " { $link f } } }
-{ $description "Outputs the contents of the file named " { $snippet "name" } " from the vocabulary's directory, or " { $link f } " if the file does not exist." } ;
-
-HELP: set-vocab-file-contents
-{ $values { "seq" "a sequence of lines" } { "vocab" "a vocabulary specifier" } { "name" string } }
-{ $description "Stores a sequence of lines to the file named " { $snippet "name" } " from the vocabulary's directory." } ;
-
-HELP: vocab-summary
-{ $values { "vocab" "a vocabulary specifier" } { "summary" "a string or " { $link f } } }
-{ $description "Outputs a one-line string description of the vocabulary's intended purpose from the " { $snippet "summary.txt" } " file in the vocabulary's directory. Outputs " { $link f } " if the file does not exist." } ;
-
-HELP: set-vocab-summary
-{ $values { "string" "a string or " { $link f } } { "vocab" "a vocabulary specifier" } }
-{ $description "Stores a one-line string description of the vocabulary to the " { $snippet "summary.txt" } " file in the vocabulary's directory." } ;
-
-HELP: vocab-tags
-{ $values { "vocab" "a vocabulary specifier" } { "tags" "a sequence of strings" } }
-{ $description "Outputs a list of short tags classifying the vocabulary from the " { $snippet "tags.txt" } " file in the vocabulary's directory. Outputs " { $link f } " if the file does not exist." } ;
-
-HELP: set-vocab-tags
-{ $values { "tags" "a sequence of strings" } { "vocab" "a vocabulary specifier" } }
-{ $description "Stores a list of short tags classifying the vocabulary to the " { $snippet "tags.txt" } " file in the vocabulary's directory." } ;
-
-HELP: all-vocabs
-{ $values { "assoc" "an association list mapping vocabulary roots to sequences of vocabulary specifiers" } }
-{ $description "Outputs an association list of all vocabularies which have been loaded or are available for loading." } ;
diff --git a/extra/tools/browser/browser-tests.factor b/extra/tools/browser/browser-tests.factor
deleted file mode 100755 (executable)
index 38d9ae6..0000000
+++ /dev/null
@@ -1,4 +0,0 @@
-IN: tools.browser.tests
-USING: tools.browser tools.test help.markup ;
-
-[ ] [ { $describe-vocab "scratchpad" } print-content ] unit-test
diff --git a/extra/tools/browser/browser.factor b/extra/tools/browser/browser.factor
deleted file mode 100755 (executable)
index c189a6f..0000000
+++ /dev/null
@@ -1,364 +0,0 @@
-! Copyright (C) 2007, 2008 Slava Pestov.
-! See http://factorcode.org/license.txt for BSD license.
-USING: namespaces splitting sequences io.files kernel assocs
-words vocabs vocabs.loader definitions parser continuations
-inspector debugger io io.styles hashtables
-sorting prettyprint source-files arrays combinators strings
-system math.parser help.markup help.topics help.syntax
-help.stylesheet memoize io.encodings.utf8 ;
-IN: tools.browser
-
-MEMO: (vocab-file-contents) ( path -- lines )
-    ?resource-path dup exists?
-    [ utf8 file-lines ] [ drop f ] if ;
-
-: vocab-file-contents ( vocab name -- seq )
-    vocab-path+ dup [ (vocab-file-contents) ] when ;
-
-: set-vocab-file-contents ( seq vocab name -- )
-    dupd vocab-path+ [
-        ?resource-path utf8 set-file-lines
-    ] [
-        "The " swap vocab-name
-        " vocabulary was not loaded from the file system"
-        3append throw
-    ] ?if ;
-
-: vocab-summary-path ( vocab -- string )
-    vocab-dir "summary.txt" path+ ;
-
-: vocab-summary ( vocab -- summary )
-    dup dup vocab-summary-path vocab-file-contents
-    dup empty? [
-        drop vocab-name " vocabulary" append
-    ] [
-        nip first
-    ] if ;
-
-M: vocab summary
-    [
-        dup vocab-summary %
-        " (" %
-        vocab-words assoc-size #
-        " words)" %
-    ] "" make ;
-
-M: vocab-link summary vocab-summary ;
-
-: set-vocab-summary ( string vocab -- )
-    >r 1array r>
-    dup vocab-summary-path
-    set-vocab-file-contents ;
-
-: vocab-tags-path ( vocab -- string )
-    vocab-dir "tags.txt" path+ ;
-
-: vocab-tags ( vocab -- tags )
-    dup vocab-tags-path vocab-file-contents ;
-
-: set-vocab-tags ( tags vocab -- )
-    dup vocab-tags-path set-vocab-file-contents ;
-
-: add-vocab-tags ( tags vocab -- )
-    [ vocab-tags append prune ] keep set-vocab-tags ;
-
-: vocab-authors-path ( vocab -- string )
-    vocab-dir "authors.txt" path+ ;
-
-: vocab-authors ( vocab -- authors )
-    dup vocab-authors-path vocab-file-contents ;
-
-: set-vocab-authors ( authors vocab -- )
-    dup vocab-authors-path set-vocab-file-contents ;
-
-: subdirs ( dir -- dirs )
-    directory [ second ] subset keys natural-sort ;
-
-: (all-child-vocabs) ( root name -- vocabs )
-    [ vocab-dir path+ ?resource-path subdirs ] keep
-    dup empty? [
-        drop
-    ] [
-        swap [ "." swap 3append ] with map
-    ] if ;
-
-: vocabs-in-dir ( root name -- )
-    dupd (all-child-vocabs) [
-        2dup vocab-dir? [ 2dup swap >vocab-link , ] when
-        vocabs-in-dir
-    ] with each ;
-
-: all-vocabs ( -- assoc )
-    vocab-roots get [
-        dup [ "" vocabs-in-dir ] { } make
-    ] { } map>assoc ;
-
-MEMO: all-vocabs-seq ( -- seq )
-    all-vocabs values concat ;
-
-: dangerous? ( name -- ? )
-    #! Hack
-    {
-        { [ "cpu." ?head ] [ t ] }
-        { [ "io.unix" ?head ] [ t ] }
-        { [ "io.windows" ?head ] [ t ] }
-        { [ "ui.x11" ?head ] [ t ] }
-        { [ "ui.windows" ?head ] [ t ] }
-        { [ "ui.cocoa" ?head ] [ t ] }
-        { [ "cocoa" ?head ] [ t ] }
-        { [ "core-foundation" ?head ] [ t ] }
-        { [ "vocabs.loader.test" ?head ] [ t ] }
-        { [ "editors." ?head ] [ t ] }
-        { [ ".windows" ?tail ] [ t ] }
-        { [ ".unix" ?tail ] [ t ] }
-        { [ "unix." ?head ] [ t ] }
-        { [ ".linux" ?tail ] [ t ] }
-        { [ ".bsd" ?tail ] [ t ] }
-        { [ ".macosx" ?tail ] [ t ] }
-        { [ "windows." ?head ] [ t ] }
-        { [ "cocoa" ?head ] [ t ] }
-        { [ ".test" ?tail ] [ t ] }
-        { [ "raptor" ?head ] [ t ] }
-        { [ dup "tools.deploy.app" = ] [ t ] }
-        { [ t ] [ f ] }
-    } cond nip ;
-
-: filter-dangerous ( seq -- seq' )
-    [ vocab-name dangerous? not ] subset ;
-
-: try-everything ( -- failures )
-    all-vocabs-seq
-    filter-dangerous
-    require-all ;
-
-: load-everything ( -- )
-    try-everything load-failures. ;
-
-: unrooted-child-vocabs ( prefix -- seq )
-    dup empty? [ CHAR: . add ] unless
-    vocabs
-    [ vocab-root not ] subset
-    [
-        vocab-name swap ?head CHAR: . rot member? not and
-    ] with subset
-    [ vocab ] map ;
-
-: all-child-vocabs ( prefix -- assoc )
-    vocab-roots get [
-        over dupd dupd (all-child-vocabs)
-        swap [ >vocab-link ] curry map
-    ] { } map>assoc
-    f rot unrooted-child-vocabs 2array add ;
-
-: load-children ( prefix -- )
-    all-child-vocabs values concat
-    filter-dangerous
-    require-all
-    load-failures. ;
-
-: vocab-status-string ( vocab -- string )
-    {
-        { [ dup not ] [ drop "" ] }
-        { [ dup vocab-main ] [ drop "[Runnable]" ] }
-        { [ t ] [ drop "[Loaded]" ] }
-    } cond ;
-
-: write-status ( vocab -- )
-    vocab vocab-status-string write ;
-
-: vocab. ( vocab -- )
-    [
-        dup [ write-status ] with-cell
-        dup [ ($link) ] with-cell
-        [ vocab-summary write ] with-cell
-    ] with-row ;
-
-: vocab-headings. ( -- )
-    [
-        [ "State" write ] with-cell
-        [ "Vocabulary" write ] with-cell
-        [ "Summary" write ] with-cell
-    ] with-row ;
-
-: root-heading. ( root -- )
-    [ "Children from " swap append ] [ "Children" ] if*
-    $heading ;
-
-: vocabs. ( assoc -- )
-    [
-        dup empty? [
-            2drop
-        ] [
-            swap root-heading.
-            standard-table-style [
-                vocab-headings. [ vocab. ] each
-            ] ($grid)
-        ] if
-    ] assoc-each ;
-
-: describe-summary ( vocab -- )
-    vocab-summary [
-        "Summary" $heading print-element
-    ] when* ;
-
-TUPLE: vocab-tag name ;
-
-C: <vocab-tag> vocab-tag
-
-: tags. ( seq -- ) [ <vocab-tag> ] map $links ;
-
-: describe-tags ( vocab -- )
-    vocab-tags f like [
-        "Tags" $heading tags.
-    ] when* ;
-
-TUPLE: vocab-author name ;
-
-C: <vocab-author> vocab-author
-
-: authors. ( seq -- ) [ <vocab-author> ] map $links ;
-
-: describe-authors ( vocab -- )
-    vocab-authors f like [
-        "Authors" $heading authors.
-    ] when* ;
-
-: describe-help ( vocab -- )
-    vocab-help [
-        "Documentation" $heading nl ($link)
-    ] when* ;
-
-: describe-children ( vocab -- )
-    vocab-name all-child-vocabs vocabs. ;
-
-: describe-files ( vocab -- )
-    vocab-files [ <pathname> ] map [
-        "Files" $heading
-        [
-            snippet-style get [
-                code-style get [
-                    stack.
-                ] with-nesting
-            ] with-style
-        ] ($block)
-    ] when* ;
-
-: describe-words ( vocab -- )
-    words dup empty? [
-        "Words" $heading
-        dup natural-sort $links
-    ] unless drop ;
-
-: map>set ( seq quot -- )
-    map concat prune natural-sort ; inline
-
-: vocab-xref ( vocab quot -- vocabs )
-    >r dup vocab-name swap words r> map
-    [ [ word? ] subset [ word-vocabulary ] map ] map>set
-    remove [ ] subset [ vocab ] map ; inline
-
-: vocab-uses ( vocab -- vocabs ) [ uses ] vocab-xref ;
-
-: vocab-usage ( vocab -- vocabs ) [ usage ] vocab-xref ;
-
-: describe-uses ( vocab -- )
-    vocab-uses dup empty? [
-        "Uses" $heading
-        dup $links
-    ] unless drop ;
-
-: describe-usage ( vocab -- )
-    vocab-usage dup empty? [
-        "Used by" $heading
-        dup $links
-    ] unless drop ;
-
-: $describe-vocab ( element -- )
-    first
-    dup describe-children
-    dup vocab-root over vocab-dir? [
-        dup describe-summary
-        dup describe-tags
-        dup describe-authors
-        dup describe-files
-    ] when
-    dup vocab [
-        dup describe-help
-        dup describe-words
-        dup describe-uses
-        dup describe-usage
-    ] when drop ;
-
-: keyed-vocabs ( str quot -- seq )
-    all-vocabs [
-        swap >r
-        [ >r 2dup r> swap call member? ] subset
-        r> swap
-    ] assoc-map 2nip ; inline
-
-: tagged ( tag -- assoc )
-    [ vocab-tags ] keyed-vocabs ;
-
-: authored ( author -- assoc )
-    [ vocab-authors ] keyed-vocabs ;
-
-: $tagged-vocabs ( element -- )
-    first tagged vocabs. ;
-
-MEMO: all-tags ( -- seq )
-    all-vocabs-seq [ vocab-tags ] map>set ;
-
-: $authored-vocabs ( element -- )
-    first authored vocabs. ;
-
-MEMO: all-authors ( -- seq )
-    all-vocabs-seq [ vocab-authors ] map>set ;
-
-: $tags ( element -- )
-    drop "Tags" $heading all-tags tags. ;
-
-: $authors ( element -- )
-    drop "Authors" $heading all-authors authors. ;
-
-M: vocab-spec article-title vocab-name " vocabulary" append ;
-
-M: vocab-spec article-name vocab-name ;
-
-M: vocab-spec article-content
-    vocab-name \ $describe-vocab swap 2array ;
-
-M: vocab-spec article-parent drop "vocab-index" ;
-
-M: vocab-tag >link ;
-
-M: vocab-tag article-title
-    vocab-tag-name "Vocabularies tagged ``" swap "''" 3append ;
-
-M: vocab-tag article-name vocab-tag-name ;
-
-M: vocab-tag article-content
-    \ $tagged-vocabs swap vocab-tag-name 2array ;
-
-M: vocab-tag article-parent drop "vocab-index" ;
-
-M: vocab-tag summary article-title ;
-
-M: vocab-author >link ;
-
-M: vocab-author article-title
-    vocab-author-name "Vocabularies by " swap append ;
-
-M: vocab-author article-name vocab-author-name ;
-
-M: vocab-author article-content
-    \ $authored-vocabs swap vocab-author-name 2array ;
-
-M: vocab-author article-parent drop "vocab-index" ;
-
-M: vocab-author summary article-title ;
-
-: reset-cache ( -- )
-    \ (vocab-file-contents) reset-memoized
-    \ all-vocabs-seq reset-memoized
-    \ all-authors reset-memoized
-    \ all-tags reset-memoized ;
diff --git a/extra/tools/browser/tags.txt b/extra/tools/browser/tags.txt
deleted file mode 100644 (file)
index ef1aab0..0000000
+++ /dev/null
@@ -1 +0,0 @@
-tools
index 301ffa3378d5f7e1eba8573d01d2fa3ca4374b82..60dc11257f138696e0d7de0af96b995ea264bf4e 100755 (executable)
@@ -34,56 +34,62 @@ IN: tools.deploy.backend
 
 : ?, [ , ] [ drop ] if ;
 
-: bootstrap-profile ( config -- profile )
+: bootstrap-profile ( -- profile )
     [
-        [
-            "math" deploy-math? get ?,
-            "compiler" deploy-compiler? get ?,
-            "ui" deploy-ui? get ?,
-            "io" native-io? ?,
-        ] { } make
-    ] bind ;
+        "math" deploy-math? get ?,
+        "compiler" deploy-compiler? get ?,
+        "ui" deploy-ui? get ?,
+        "io" native-io? ?,
+    ] { } make ;
 
-: staging-image-name ( profile -- name )
-    "staging." swap bootstrap-profile "-" join ".image" 3append ;
+: staging-image-name ( -- name )
+    "staging."
+    bootstrap-profile strip-word-names? [ "strip" add ] when
+    "-" join ".image" 3append ;
 
 : staging-command-line ( config -- flags )
     [
-        "-i=" my-boot-image-name append ,
+        [
+            "-i=" my-boot-image-name append ,
 
-        "-output-image=" over staging-image-name append ,
+            "-output-image=" staging-image-name append ,
 
-        "-include=" swap bootstrap-profile " " join append ,
+            "-include=" bootstrap-profile " " join append ,
 
-        "-no-stack-traces" ,
+            strip-word-names? [ "-no-stack-traces" , ] when
 
-        "-no-user-init" ,
-    ] { } make ;
+            "-no-user-init" ,
+        ] { } make
+    ] bind ;
 
 : run-factor ( vm flags -- )
     swap add* dup . run-with-output ; inline
 
-: make-staging-image ( vm config -- )
-    staging-command-line run-factor ;
+: make-staging-image ( config -- )
+    vm swap staging-command-line run-factor ;
+
+: ?make-staging-image ( config -- )
+    dup [ staging-image-name ] bind exists?
+    [ drop ] [ make-staging-image ] if ;
 
 : deploy-command-line ( image vocab config -- flags )
     [
-        "-i=" swap staging-image-name append ,
+        [
+            "-i=" staging-image-name append ,
 
-        "-run=tools.deploy.shaker" ,
+            "-run=tools.deploy.shaker" ,
 
-        "-deploy-vocab=" swap append ,
+            "-deploy-vocab=" swap append ,
 
-        "-output-image=" swap append ,
+            "-output-image=" swap append ,
 
-        "-no-stack-traces" ,
-    ] { } make ;
+            strip-word-names? [ "-no-stack-traces" , ] when
+        ] { } make
+    ] bind ;
 
 : make-deploy-image ( vm image vocab config -- )
     make-boot-image
-    dup staging-image-name exists? [
-        >r pick r> tuck make-staging-image
-    ] unless
+    dup ?make-staging-image
     deploy-command-line run-factor ;
 
 SYMBOL: deploy-implementation
index 64f863b7307a46f082aca2677026a2128a3b7290..78f1d487de97a04408c1f5cabccfddfa48e71702 100755 (executable)
@@ -2,7 +2,7 @@
 ! See http://factorcode.org/license.txt for BSD license.
 USING: vocabs.loader io.files io kernel sequences assocs
 splitting parser prettyprint namespaces math vocabs
-hashtables tools.browser ;
+hashtables tools.vocabs ;
 IN: tools.deploy.config
 
 SYMBOL: deploy-name
index d473d8f6403b37b2021d8ddccc55f250e5c28ed1..6d3385d0a4d63cb23f5c38dfcea508aa06bc2a0e 100755 (executable)
@@ -1,22 +1,47 @@
 IN: tools.deploy.tests\r
 USING: tools.test system io.files kernel tools.deploy.config\r
-tools.deploy.backend math ;\r
+tools.deploy.backend math sequences io.launcher arrays ;\r
 \r
-: shake-and-bake\r
+: shake-and-bake ( vocab -- )\r
     "." resource-path [\r
-        vm\r
-        "hello.image" temp-file\r
-        rot dup deploy-config make-deploy-image\r
+        >r vm\r
+        "test.image" temp-file\r
+        r> dup deploy-config make-deploy-image\r
     ] with-directory ;\r
 \r
+: small-enough? ( n -- ? )\r
+    >r "test.image" temp-file file-info file-info-size r> <= ;\r
+\r
 [ ] [ "hello-world" shake-and-bake ] unit-test\r
 \r
 [ t ] [\r
-    "hello.image" temp-file file-length 500000 <=\r
+    500000 small-enough?\r
+] unit-test\r
+\r
+[ ] [ "sudoku" shake-and-bake ] unit-test\r
+\r
+[ t ] [\r
+    1500000 small-enough?\r
 ] unit-test\r
 \r
 [ ] [ "hello-ui" shake-and-bake ] unit-test\r
 \r
 [ t ] [\r
-    "hello.image" temp-file file-length 2000000 <=\r
+    2000000 small-enough?\r
+] unit-test\r
+\r
+[ ] [ "bunny" shake-and-bake ] unit-test\r
+\r
+[ t ] [\r
+    3000000 small-enough?\r
+] unit-test\r
+\r
+[ ] [\r
+    "tools.deploy.test.1" shake-and-bake\r
+    vm "-i=" "test.image" temp-file append 2array try-process\r
+] unit-test\r
+\r
+[ ] [\r
+    "tools.deploy.test.2" shake-and-bake\r
+    vm "-i=" "test.image" temp-file append 2array try-process\r
 ] unit-test\r
index 0ddc2d570780f37480423487df691e8cdd94e132..edf78de4799588124857de122f85725a2ec46694 100755 (executable)
@@ -1,11 +1,28 @@
-! Copyright (C) 2007 Slava Pestov.
+! Copyright (C) 2007, 2008 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: namespaces continuations.private kernel.private init
-assocs kernel vocabs words sequences memory io system arrays
-continuations math definitions mirrors splitting parser classes
-inspector layouts vocabs.loader prettyprint.config prettyprint
-debugger io.streams.c io.streams.duplex io.files io.backend
-quotations words.private tools.deploy.config compiler.units ;
+USING: qualified io.streams.c init fry namespaces assocs kernel
+parser tools.deploy.config vocabs sequences words words.private
+memory kernel.private continuations io prettyprint
+vocabs.loader debugger system strings ;
+QUALIFIED: bootstrap.stage2
+QUALIFIED: classes
+QUALIFIED: compiler.errors.private
+QUALIFIED: compiler.units
+QUALIFIED: continuations
+QUALIFIED: definitions
+QUALIFIED: init
+QUALIFIED: inspector
+QUALIFIED: io.backend
+QUALIFIED: io.thread
+QUALIFIED: layouts
+QUALIFIED: libc.private
+QUALIFIED: libc.private
+QUALIFIED: listener
+QUALIFIED: prettyprint.config
+QUALIFIED: random.private
+QUALIFIED: source-files
+QUALIFIED: threads
+QUALIFIED: vocabs
 IN: tools.deploy.shaker
 
 : strip-init-hooks ( -- )
@@ -43,9 +60,6 @@ IN: tools.deploy.shaker
         run-file
     ] when ;
 
-: strip-assoc ( retained-keys assoc -- newassoc )
-    swap [ nip member? ] curry assoc-subset ;
-
 : strip-word-names ( words -- )
     "Stripping word names" show
     [ f over set-word-name f swap set-word-vocabulary ] each ;
@@ -57,8 +71,11 @@ IN: tools.deploy.shaker
 : strip-word-props ( retain-props words -- )
     "Stripping word properties" show
     [
-        [ word-props strip-assoc f assoc-like ] keep
-        set-word-props
+        [
+            word-props swap
+            '[ , nip member? ] assoc-subset
+            f assoc-like
+        ] keep set-word-props
     ] with each ;
 
 : retained-props ( -- seq )
@@ -81,10 +98,103 @@ IN: tools.deploy.shaker
     strip-word-names? [ dup strip-word-names ] when
     2drop ;
 
-: strip-environment ( retain-globals -- )
+: strip-recompile-hook ( -- )
+    [ [ f ] { } map>assoc ]
+    compiler.units:recompile-hook
+    set-global ;
+
+: strip-vocab-globals ( except names -- words )
+    [ child-vocabs [ words ] map concat ] map concat seq-diff ;
+
+: stripped-globals ( -- seq )
+    [
+        random.private:mt ,
+
+        {
+            bootstrap.stage2:bootstrap-time
+            continuations:error
+            continuations:error-continuation
+            continuations:error-thread
+            continuations:restarts
+            error-hook
+            init:init-hooks
+            inspector:inspector-hook
+            io.thread:io-thread
+            libc.private:mallocs
+            source-files:source-files
+            stderr
+            stdio
+        } %
+
+        deploy-threads? [
+            threads:initial-thread ,
+        ] unless
+
+        strip-io? [ io.backend:io-backend , ] when
+
+        [
+            io.backend:io-backend
+            "default-buffer-size" "io.nonblocking" lookup ,
+        ] { "alarms" "io" "tools" } strip-vocab-globals %
+
+        strip-dictionary? [
+            { } { "cpu" } strip-vocab-globals %
+
+            {
+                vocabs:dictionary
+                lexer-factory
+                vocabs:load-vocab-hook
+                layouts:num-tags
+                layouts:num-types
+                layouts:tag-mask
+                layouts:tag-numbers
+                layouts:type-numbers
+                classes:typemap
+                vocab-roots
+                definitions:crossref
+                compiled-crossref
+                interactive-vocabs
+                word
+                compiler.units:recompile-hook
+                listener:listener-hook
+                lexer-factory
+                classes:update-map
+                classes:class<map
+            } %
+        ] when
+
+        strip-prettyprint? [
+            {
+                prettyprint.config:margin
+                prettyprint.config:string-limit
+                prettyprint.config:tab-size
+            } %
+        ] when
+
+        strip-debugger? [
+            {
+                compiler.errors.private:compiler-errors
+                continuations:thread-error-hook
+            } %
+        ] when
+
+        deploy-c-types? get [
+            "c-types" "alien.c-types" lookup ,
+        ] unless
+
+        deploy-ui? get [
+            "ui-error-hook" "ui.gadgets.worlds" lookup ,
+        ] when
+    ] { } make ;
+
+: strip-globals ( stripped-globals -- )
     strip-globals? [
-        "Stripping environment" show
-        global strip-assoc 21 setenv
+        "Stripping globals" show
+        global swap
+        '[ drop , member? not ] assoc-subset
+        [ drop string? not ] assoc-subset ! strip CLI args
+        dup keys .
+        21 setenv
     ] [ drop ] if ;
 
 : finish-deploy ( final-image -- )
@@ -108,55 +218,6 @@ SYMBOL: deploy-vocab
     ] [ ] make "Boot quotation: " write dup . flush
     set-boot-quot ;
 
-: retained-globals ( -- seq )
-    [
-        builtins ,
-        strip-io? [ io-backend , ] unless
-
-        strip-dictionary? [
-            {
-                dictionary
-                inspector-hook
-                lexer-factory
-                load-vocab-hook
-                num-tags
-                num-types
-                tag-bits
-                tag-mask
-                tag-numbers
-                typemap
-                vocab-roots
-            } %
-        ] unless
-
-        strip-prettyprint? [
-            {
-                tab-size
-                margin
-            } %
-        ] unless
-
-        deploy-c-types? get [
-            "c-types" "alien.c-types" lookup ,
-        ] when
-
-        native-io? [
-            "default-buffer-size" "io.nonblocking" lookup ,
-        ] when
-
-        deploy-ui? get [
-            "ui" child-vocabs
-            "cocoa" child-vocabs
-            deploy-vocab get child-vocabs 3append
-            global keys [ word? ] subset
-            swap [ >r word-vocabulary r> member? ] curry
-            subset %
-        ] when
-    ] { } make dup . ;
-
-: strip-recompile-hook ( -- )
-    [ [ f ] { } map>assoc ] recompile-hook set-global ;
-
 : strip ( -- )
     strip-libc
     strip-cocoa
@@ -165,7 +226,7 @@ SYMBOL: deploy-vocab
     strip-init-hooks
     deploy-vocab get vocab-main set-boot-quot*
     retained-props >r
-    retained-globals strip-environment
+    stripped-globals strip-globals
     r> strip-words ;
 
 : (deploy) ( final-image vocab config -- )
diff --git a/extra/tools/deploy/test/1/1.factor b/extra/tools/deploy/test/1/1.factor
new file mode 100755 (executable)
index 0000000..0bf8b10
--- /dev/null
@@ -0,0 +1,6 @@
+IN: tools.deploy.test.1\r
+USING: threads ;\r
+\r
+: deploy-test-1 1000 sleep ;\r
+\r
+MAIN: deploy-test-1\r
diff --git a/extra/tools/deploy/test/1/deploy.factor b/extra/tools/deploy/test/1/deploy.factor
new file mode 100755 (executable)
index 0000000..f06bcbc
--- /dev/null
@@ -0,0 +1,14 @@
+USING: tools.deploy.config ;
+H{
+    { deploy-c-types? f }
+    { deploy-io 2 }
+    { deploy-reflection 1 }
+    { deploy-threads? t }
+    { deploy-word-props? f }
+    { deploy-word-defs? f }
+    { deploy-name "tools.deploy.test.1" }
+    { deploy-math? t }
+    { deploy-compiler? t }
+    { "stop-after-last-window?" t }
+    { deploy-ui? f }
+}
diff --git a/extra/tools/deploy/test/2/2.factor b/extra/tools/deploy/test/2/2.factor
new file mode 100755 (executable)
index 0000000..e029e30
--- /dev/null
@@ -0,0 +1,6 @@
+IN: tools.deploy.test.2\r
+USING: calendar calendar.format ;\r
+\r
+: deploy-test-2 now (timestamp>string) ;\r
+\r
+MAIN: deploy-test-2\r
diff --git a/extra/tools/deploy/test/2/deploy.factor b/extra/tools/deploy/test/2/deploy.factor
new file mode 100755 (executable)
index 0000000..bd087d6
--- /dev/null
@@ -0,0 +1,14 @@
+USING: tools.deploy.config ;
+H{
+    { deploy-c-types? f }
+    { deploy-io 2 }
+    { deploy-reflection 1 }
+    { deploy-threads? t }
+    { deploy-word-props? f }
+    { deploy-word-defs? f }
+    { deploy-name "tools.deploy.test.2" }
+    { deploy-math? t }
+    { deploy-compiler? t }
+    { "stop-after-last-window?" t }
+    { deploy-ui? f }
+}
diff --git a/extra/tools/deploy/test/3/3.factor b/extra/tools/deploy/test/3/3.factor
new file mode 100755 (executable)
index 0000000..443e82f
--- /dev/null
@@ -0,0 +1,8 @@
+IN: tools.deploy.test.3\r
+USING: io.encodings.ascii io.files kernel ;\r
+\r
+: deploy-test-3\r
+    "resource:extra/tools/deploy/test/3/3.factor"\r
+    ?resource-path ascii file-contents drop ;\r
+\r
+MAIN: deploy-test-3\r
diff --git a/extra/tools/deploy/test/3/deploy.factor b/extra/tools/deploy/test/3/deploy.factor
new file mode 100755 (executable)
index 0000000..b8b8bf4
--- /dev/null
@@ -0,0 +1,14 @@
+USING: tools.deploy.config ;
+H{
+    { deploy-math? t }
+    { deploy-reflection 1 }
+    { deploy-name "tools.deploy.test.3" }
+    { deploy-threads? t }
+    { deploy-word-props? f }
+    { "stop-after-last-window?" t }
+    { deploy-ui? f }
+    { deploy-io 3 }
+    { deploy-compiler? t }
+    { deploy-word-defs? f }
+    { deploy-c-types? f }
+}
diff --git a/extra/tools/disassembler/disassembler-tests.factor b/extra/tools/disassembler/disassembler-tests.factor
new file mode 100755 (executable)
index 0000000..9983db7
--- /dev/null
@@ -0,0 +1,6 @@
+IN: tools.disassembler.tests\r
+USING: math tuples prettyprint.backend tools.disassembler\r
+tools.test strings ;\r
+\r
+[ ] [ \ + disassemble ] unit-test\r
+[ ] [ { string pprint* } disassemble ] unit-test\r
index 2fa882ff687bef1aaf7f7ae2d98346ef075f5bb2..479ae9c42c8358995f5d5b58fcf6f68c6d9bb8f5 100755 (executable)
@@ -2,7 +2,8 @@
 ! See http://factorcode.org/license.txt for BSD license.
 USING: io.files io words alien kernel math.parser alien.syntax
 io.launcher system assocs arrays sequences namespaces qualified
-system math generator.fixup io.encodings.ascii accessors ;
+system math generator.fixup io.encodings.ascii accessors
+generic ;
 IN: tools.disassembler
 
 : in-file "gdb-in.txt" temp-file ;
@@ -22,6 +23,9 @@ M: pair make-disassemble-cmd
         [ number>string write bl ] each
     ] with-file-writer ;
 
+M: method-spec make-disassemble-cmd
+    first2 method make-disassemble-cmd ;
+
 : run-gdb ( -- lines )
     <process>
         +closed+ >>stdin
index 259b91c3af4ede686382161f6f56a55413438652..031b3c3af8892cfc13f27b77e19460ac8d9cd5f2 100755 (executable)
@@ -4,7 +4,7 @@ USING: namespaces arrays prettyprint sequences kernel
 vectors quotations words parser assocs combinators
 continuations debugger io io.files vocabs tools.time
 vocabs.loader source-files compiler.units inspector
-inference effects ;
+inference effects tools.vocabs ;
 IN: tools.test
 
 SYMBOL: failures
diff --git a/extra/tools/vocabs/browser/authors.txt b/extra/tools/vocabs/browser/authors.txt
new file mode 100755 (executable)
index 0000000..1901f27
--- /dev/null
@@ -0,0 +1 @@
+Slava Pestov
diff --git a/extra/tools/vocabs/browser/browser-docs.factor b/extra/tools/vocabs/browser/browser-docs.factor
new file mode 100755 (executable)
index 0000000..3765efb
--- /dev/null
@@ -0,0 +1,7 @@
+USING: help.markup help.syntax io strings ;
+IN: tools.vocabs.browser
+
+ARTICLE: "vocab-index" "Vocabulary index"
+{ $tags }
+{ $authors }
+{ $describe-vocab "" } ;
diff --git a/extra/tools/vocabs/browser/browser-tests.factor b/extra/tools/vocabs/browser/browser-tests.factor
new file mode 100755 (executable)
index 0000000..7e12a56
--- /dev/null
@@ -0,0 +1,4 @@
+IN: tools.vocabs.browser.tests
+USING: tools.vocabs.browser tools.test help.markup ;
+
+[ ] [ { $describe-vocab "scratchpad" } print-content ] unit-test
diff --git a/extra/tools/vocabs/browser/browser.factor b/extra/tools/vocabs/browser/browser.factor
new file mode 100755 (executable)
index 0000000..2c66305
--- /dev/null
@@ -0,0 +1,207 @@
+! Copyright (C) 2007, 2008 Slava Pestov.
+! See http://factorcode.org/license.txt for BSD license.
+USING: kernel combinators vocabs vocabs.loader tools.vocabs io
+io.files io.styles help.markup help.stylesheet sequences assocs
+help.topics namespaces prettyprint words sorting definitions
+arrays inspector ;
+IN: tools.vocabs.browser
+
+: vocab-status-string ( vocab -- string )
+    {
+        { [ dup not ] [ drop "" ] }
+        { [ dup vocab-main ] [ drop "[Runnable]" ] }
+        { [ t ] [ drop "[Loaded]" ] }
+    } cond ;
+
+: write-status ( vocab -- )
+    vocab vocab-status-string write ;
+
+: vocab. ( vocab -- )
+    [
+        dup [ write-status ] with-cell
+        dup [ ($link) ] with-cell
+        [ vocab-summary write ] with-cell
+    ] with-row ;
+
+: vocab-headings. ( -- )
+    [
+        [ "State" write ] with-cell
+        [ "Vocabulary" write ] with-cell
+        [ "Summary" write ] with-cell
+    ] with-row ;
+
+: root-heading. ( root -- )
+    [ "Children from " swap append ] [ "Children" ] if*
+    $heading ;
+
+: vocabs. ( assoc -- )
+    [
+        dup empty? [
+            2drop
+        ] [
+            swap root-heading.
+            standard-table-style [
+                vocab-headings. [ vocab. ] each
+            ] ($grid)
+        ] if
+    ] assoc-each ;
+
+: describe-summary ( vocab -- )
+    vocab-summary [
+        "Summary" $heading print-element
+    ] when* ;
+
+TUPLE: vocab-tag name ;
+
+INSTANCE: vocab-tag topic
+
+C: <vocab-tag> vocab-tag
+
+: tags. ( seq -- ) [ <vocab-tag> ] map $links ;
+
+: describe-tags ( vocab -- )
+    vocab-tags f like [
+        "Tags" $heading tags.
+    ] when* ;
+
+TUPLE: vocab-author name ;
+
+INSTANCE: vocab-author topic
+
+C: <vocab-author> vocab-author
+
+: authors. ( seq -- ) [ <vocab-author> ] map $links ;
+
+: describe-authors ( vocab -- )
+    vocab-authors f like [
+        "Authors" $heading authors.
+    ] when* ;
+
+: describe-help ( vocab -- )
+    vocab-help [
+        "Documentation" $heading nl ($link)
+    ] when* ;
+
+: describe-children ( vocab -- )
+    vocab-name all-child-vocabs vocabs. ;
+
+: describe-files ( vocab -- )
+    vocab-files [ <pathname> ] map [
+        "Files" $heading
+        [
+            snippet-style get [
+                code-style get [
+                    stack.
+                ] with-nesting
+            ] with-style
+        ] ($block)
+    ] when* ;
+
+: describe-words ( vocab -- )
+    words dup empty? [
+        "Words" $heading
+        dup natural-sort $links
+    ] unless drop ;
+
+: vocab-xref ( vocab quot -- vocabs )
+    >r dup vocab-name swap words r> map
+    [ [ word? ] subset [ word-vocabulary ] map ] map>set
+    remove [ ] subset [ vocab ] map ; inline
+
+: vocab-uses ( vocab -- vocabs ) [ uses ] vocab-xref ;
+
+: vocab-usage ( vocab -- vocabs ) [ usage ] vocab-xref ;
+
+: describe-uses ( vocab -- )
+    vocab-uses dup empty? [
+        "Uses" $heading
+        dup $links
+    ] unless drop ;
+
+: describe-usage ( vocab -- )
+    vocab-usage dup empty? [
+        "Used by" $heading
+        dup $links
+    ] unless drop ;
+
+: $describe-vocab ( element -- )
+    first
+    dup describe-children
+    dup vocab-root over vocab-dir? [
+        dup describe-summary
+        dup describe-tags
+        dup describe-authors
+        dup describe-files
+    ] when
+    dup vocab [
+        dup describe-help
+        dup describe-words
+        dup describe-uses
+        dup describe-usage
+    ] when drop ;
+
+: keyed-vocabs ( str quot -- seq )
+    all-vocabs [
+        swap >r
+        [ >r 2dup r> swap call member? ] subset
+        r> swap
+    ] assoc-map 2nip ; inline
+
+: tagged ( tag -- assoc )
+    [ vocab-tags ] keyed-vocabs ;
+
+: authored ( author -- assoc )
+    [ vocab-authors ] keyed-vocabs ;
+
+: $tagged-vocabs ( element -- )
+    first tagged vocabs. ;
+
+: $authored-vocabs ( element -- )
+    first authored vocabs. ;
+
+: $tags ( element -- )
+    drop "Tags" $heading all-tags tags. ;
+
+: $authors ( element -- )
+    drop "Authors" $heading all-authors authors. ;
+
+INSTANCE: vocab topic
+
+INSTANCE: vocab-link topic
+
+M: vocab-spec article-title vocab-name " vocabulary" append ;
+
+M: vocab-spec article-name vocab-name ;
+
+M: vocab-spec article-content
+    vocab-name \ $describe-vocab swap 2array ;
+
+M: vocab-spec article-parent drop "vocab-index" ;
+
+M: vocab-tag >link ;
+
+M: vocab-tag article-title
+    vocab-tag-name "Vocabularies tagged ``" swap "''" 3append ;
+
+M: vocab-tag article-name vocab-tag-name ;
+
+M: vocab-tag article-content
+    \ $tagged-vocabs swap vocab-tag-name 2array ;
+
+M: vocab-tag article-parent drop "vocab-index" ;
+
+M: vocab-tag summary article-title ;
+
+M: vocab-author >link ;
+
+M: vocab-author article-title
+    vocab-author-name "Vocabularies by " swap append ;
+
+M: vocab-author article-name vocab-author-name ;
+
+M: vocab-author article-content
+    \ $authored-vocabs swap vocab-author-name 2array ;
+
+M: vocab-author article-parent drop "vocab-index" ;
+
+M: vocab-author summary article-title ;
diff --git a/extra/tools/vocabs/browser/tags.txt b/extra/tools/vocabs/browser/tags.txt
new file mode 100644 (file)
index 0000000..ef1aab0
--- /dev/null
@@ -0,0 +1 @@
+tools
diff --git a/extra/tools/vocabs/monitor/authors.txt b/extra/tools/vocabs/monitor/authors.txt
new file mode 100644 (file)
index 0000000..1901f27
--- /dev/null
@@ -0,0 +1 @@
+Slava Pestov
diff --git a/extra/tools/vocabs/monitor/monitor.factor b/extra/tools/vocabs/monitor/monitor.factor
new file mode 100755 (executable)
index 0000000..071f179
--- /dev/null
@@ -0,0 +1,24 @@
+! Copyright (C) 2008 Slava Pestov.\r
+! See http://factorcode.org/license.txt for BSD license.\r
+USING: threads io.files io.monitors init kernel\r
+vocabs.loader tools.vocabs namespaces continuations ;\r
+IN: tools.vocabs.monitor\r
+\r
+! Use file system change monitoring to flush the tags/authors\r
+! cache\r
+SYMBOL: vocab-monitor\r
+\r
+: monitor-thread ( -- )\r
+    vocab-monitor get-global\r
+    next-change 2drop\r
+    t sources-changed? set-global reset-cache ;\r
+\r
+: start-monitor-thread\r
+    #! Silently ignore errors during monitor creation since\r
+    #! monitors are not supported on all platforms.\r
+    [\r
+        "" resource-path t <monitor> vocab-monitor set-global\r
+        [ monitor-thread t ] "Vocabulary monitor" spawn-server drop\r
+    ] ignore-errors ;\r
+\r
+[ start-monitor-thread ] "tools.vocabs.monitor" add-init-hook\r
diff --git a/extra/tools/vocabs/monitor/summary.txt b/extra/tools/vocabs/monitor/summary.txt
new file mode 100644 (file)
index 0000000..27c0d38
--- /dev/null
@@ -0,0 +1 @@
+Use io.monitors to clear tools.browser authors/tags/summary cache
diff --git a/extra/tools/vocabs/vocabs-docs.factor b/extra/tools/vocabs/vocabs-docs.factor
new file mode 100755 (executable)
index 0000000..33f197d
--- /dev/null
@@ -0,0 +1,75 @@
+USING: help.markup help.syntax strings ;\r
+IN: tools.vocabs\r
+\r
+ARTICLE: "tools.vocabs" "Vocabulary tools"\r
+"Reloading source files changed on disk:"\r
+{ $subsection refresh }\r
+{ $subsection refresh-all }\r
+"Vocabulary summaries:"\r
+{ $subsection vocab-summary }\r
+{ $subsection set-vocab-summary }\r
+"Vocabulary tags:"\r
+{ $subsection vocab-tags }\r
+{ $subsection set-vocab-tags }\r
+{ $subsection add-vocab-tags }\r
+"Getting and setting vocabulary meta-data:"\r
+{ $subsection vocab-file-contents }\r
+{ $subsection set-vocab-file-contents }\r
+"Global meta-data:"\r
+{ $subsection all-vocabs }\r
+{ $subsection all-vocabs-seq }\r
+{ $subsection all-tags }\r
+{ $subsection all-authors }\r
+"Because loading the above data is expensive, it is cached. The cache is flushed by the " { $vocab-link "tools.vocabs.monitor" } " vocabulary. It can also be flushed manually when file system change monitors are not available:"\r
+{ $subsection reset-cache } ;\r
+\r
+ABOUT: "tools.vocabs"\r
+\r
+HELP: vocab-files\r
+{ $values { "vocab" "a vocabulary specifier" } { "seq" "a sequence of pathname strings" } }\r
+{ $description "Outputs a sequence of files comprising this vocabulary, or " { $link f } " if the vocabulary does not have a directory on disk." } ;\r
+\r
+HELP: vocab-tests\r
+{ $values { "vocab" "a vocabulary specifier" } { "tests" "a sequence of pathname strings" } }\r
+{ $description "Outputs a sequence of pathnames where the unit tests for " { $snippet "vocab" } " are located." } ;\r
+\r
+HELP: source-modified?\r
+{ $values { "path" "a pathname string" } { "?" "a boolean" } }\r
+{ $description "Tests if the source file has been modified since it was last loaded. This compares the file's CRC32 checksum of the file's contents against the previously-recorded value." } ;\r
+\r
+HELP: refresh\r
+{ $values { "prefix" string } }\r
+{ $description "Reloads source files and documentation belonging to loaded vocabularies whose names are prefixed by " { $snippet "prefix" } " which have been modified on disk." } ;\r
+\r
+HELP: refresh-all\r
+{ $description "Reloads source files and documentation for all loaded vocabularies which have been modified on disk." } ;\r
+\r
+{ refresh refresh-all } related-words\r
+\r
+HELP: vocab-file-contents\r
+{ $values { "vocab" "a vocabulary specifier" } { "name" string } { "seq" "a sequence of lines, or " { $link f } } }\r
+{ $description "Outputs the contents of the file named " { $snippet "name" } " from the vocabulary's directory, or " { $link f } " if the file does not exist." } ;\r
+\r
+HELP: set-vocab-file-contents\r
+{ $values { "seq" "a sequence of lines" } { "vocab" "a vocabulary specifier" } { "name" string } }\r
+{ $description "Stores a sequence of lines to the file named " { $snippet "name" } " from the vocabulary's directory." } ;\r
+\r
+HELP: vocab-summary\r
+{ $values { "vocab" "a vocabulary specifier" } { "summary" "a string or " { $link f } } }\r
+{ $description "Outputs a one-line string description of the vocabulary's intended purpose from the " { $snippet "summary.txt" } " file in the vocabulary's directory. Outputs " { $link f } " if the file does not exist." } ;\r
+\r
+HELP: set-vocab-summary\r
+{ $values { "string" "a string or " { $link f } } { "vocab" "a vocabulary specifier" } }\r
+{ $description "Stores a one-line string description of the vocabulary to the " { $snippet "summary.txt" } " file in the vocabulary's directory." } ;\r
+\r
+HELP: vocab-tags\r
+{ $values { "vocab" "a vocabulary specifier" } { "tags" "a sequence of strings" } }\r
+{ $description "Outputs a list of short tags classifying the vocabulary from the " { $snippet "tags.txt" } " file in the vocabulary's directory. Outputs " { $link f } " if the file does not exist." } ;\r
+\r
+HELP: set-vocab-tags\r
+{ $values { "tags" "a sequence of strings" } { "vocab" "a vocabulary specifier" } }\r
+{ $description "Stores a list of short tags classifying the vocabulary to the " { $snippet "tags.txt" } " file in the vocabulary's directory." } ;\r
+\r
+HELP: all-vocabs\r
+{ $values { "assoc" "an association list mapping vocabulary roots to sequences of vocabulary specifiers" } }\r
+{ $description "Outputs an association list of all vocabularies which have been loaded or are available for loading." } ;\r
diff --git a/extra/tools/vocabs/vocabs.factor b/extra/tools/vocabs/vocabs.factor
new file mode 100755 (executable)
index 0000000..675a2e1
--- /dev/null
@@ -0,0 +1,268 @@
+! Copyright (C) 2007, 2008 Slava Pestov.\r
+! See http://factorcode.org/license.txt for BSD license.\r
+USING: io.files kernel io.encodings.utf8 vocabs.loader vocabs\r
+sequences namespaces math.parser arrays hashtables assocs\r
+memoize inspector sorting splitting combinators source-files\r
+io debugger continuations compiler.errors init io.crc32 ;\r
+IN: tools.vocabs\r
+\r
+: vocab-tests-file, ( vocab -- )\r
+    dup "-tests.factor" vocab-dir+ vocab-path+\r
+    dup resource-exists? [ , ] [ drop ] if ;\r
+\r
+: vocab-tests-dir, ( vocab -- )\r
+    dup vocab-dir "tests" path+ vocab-path+\r
+    dup resource-exists? [\r
+        dup ?resource-path directory keys\r
+        [ ".factor" tail? ] subset\r
+        [ path+ , ] with each\r
+    ] [ drop ] if ;\r
+\r
+: vocab-tests ( vocab -- tests )\r
+    dup vocab-root [\r
+        [\r
+            f >vocab-link dup\r
+            vocab-tests-file,\r
+            vocab-tests-dir,\r
+        ] { } make\r
+    ] [ drop f ] if ;\r
+\r
+: vocab-files ( vocab -- seq )\r
+    f >vocab-link [\r
+        dup vocab-source-path [ , ] when*\r
+        dup vocab-docs-path [ , ] when*\r
+        vocab-tests %\r
+    ] { } make ;\r
+\r
+: source-modified? ( path -- ? )\r
+    dup source-files get at [\r
+        dup source-file-path ?resource-path utf8 file-lines lines-crc32\r
+        swap source-file-checksum = not\r
+    ] [\r
+        resource-exists?\r
+    ] ?if ;\r
+\r
+: modified ( seq quot -- seq )\r
+    [ dup ] swap compose { } map>assoc\r
+    [ nip ] assoc-subset\r
+    [ nip source-modified? ] assoc-subset keys ; inline\r
+\r
+: modified-sources ( vocabs -- seq )\r
+    [ vocab-source-path ] modified ;\r
+\r
+: modified-docs ( vocabs -- seq )\r
+    [ vocab-docs-path ] modified ;\r
+\r
+: update-roots ( vocabs -- )\r
+    [ dup find-vocab-root swap vocab set-vocab-root ] each ;\r
+\r
+: to-refresh ( prefix -- modified-sources modified-docs )\r
+    child-vocabs\r
+    dup update-roots\r
+    dup modified-sources swap modified-docs ;\r
+\r
+: vocab-heading. ( vocab -- )\r
+    nl\r
+    "==== " write\r
+    dup vocab-name swap vocab write-object ":" print\r
+    nl ;\r
+\r
+: load-error. ( triple -- )\r
+    dup first vocab-heading.\r
+    dup second print-error\r
+    drop ;\r
+\r
+: load-failures. ( failures -- )\r
+    [ load-error. nl ] each ;\r
+\r
+SYMBOL: failures\r
+\r
+: require-all ( vocabs -- failures )\r
+    [\r
+        V{ } clone blacklist set\r
+        V{ } clone failures set\r
+        [\r
+            [ require ]\r
+            [ swap vocab-name failures get set-at ]\r
+            recover\r
+        ] each\r
+        failures get\r
+    ] with-compiler-errors ;\r
+\r
+: do-refresh ( modified-sources modified-docs -- )\r
+    2dup\r
+    [ f swap set-vocab-docs-loaded? ] each\r
+    [ f swap set-vocab-source-loaded? ] each\r
+    append prune require-all load-failures. ;\r
+\r
+: refresh ( prefix -- ) to-refresh do-refresh ;\r
+\r
+SYMBOL: sources-changed?\r
+\r
+[ t sources-changed? set-global ] "tools.vocabs" add-init-hook\r
+\r
+: refresh-all ( -- )\r
+    "" refresh f sources-changed? set-global ;\r
+\r
+MEMO: (vocab-file-contents) ( path -- lines )\r
+    ?resource-path dup exists?\r
+    [ utf8 file-lines ] [ drop f ] if ;\r
+\r
+: vocab-file-contents ( vocab name -- seq )\r
+    vocab-path+ dup [ (vocab-file-contents) ] when ;\r
+\r
+: set-vocab-file-contents ( seq vocab name -- )\r
+    dupd vocab-path+ [\r
+        ?resource-path utf8 set-file-lines\r
+    ] [\r
+        "The " swap vocab-name\r
+        " vocabulary was not loaded from the file system"\r
+        3append throw\r
+    ] ?if ;\r
+\r
+: vocab-summary-path ( vocab -- string )\r
+    vocab-dir "summary.txt" path+ ;\r
+\r
+: vocab-summary ( vocab -- summary )\r
+    dup dup vocab-summary-path vocab-file-contents\r
+    dup empty? [\r
+        drop vocab-name " vocabulary" append\r
+    ] [\r
+        nip first\r
+    ] if ;\r
+\r
+M: vocab summary\r
+    [\r
+        dup vocab-summary %\r
+        " (" %\r
+        vocab-words assoc-size #\r
+        " words)" %\r
+    ] "" make ;\r
+\r
+M: vocab-link summary vocab-summary ;\r
+\r
+: set-vocab-summary ( string vocab -- )\r
+    >r 1array r>\r
+    dup vocab-summary-path\r
+    set-vocab-file-contents ;\r
+\r
+: vocab-tags-path ( vocab -- string )\r
+    vocab-dir "tags.txt" path+ ;\r
+\r
+: vocab-tags ( vocab -- tags )\r
+    dup vocab-tags-path vocab-file-contents ;\r
+\r
+: set-vocab-tags ( tags vocab -- )\r
+    dup vocab-tags-path set-vocab-file-contents ;\r
+\r
+: add-vocab-tags ( tags vocab -- )\r
+    [ vocab-tags append prune ] keep set-vocab-tags ;\r
+\r
+: vocab-authors-path ( vocab -- string )\r
+    vocab-dir "authors.txt" path+ ;\r
+\r
+: vocab-authors ( vocab -- authors )\r
+    dup vocab-authors-path vocab-file-contents ;\r
+\r
+: set-vocab-authors ( authors vocab -- )\r
+    dup vocab-authors-path set-vocab-file-contents ;\r
+\r
+: subdirs ( dir -- dirs )\r
+    directory [ second ] subset keys natural-sort ;\r
+\r
+: (all-child-vocabs) ( root name -- vocabs )\r
+    [ vocab-dir path+ ?resource-path subdirs ] keep\r
+    dup empty? [\r
+        drop\r
+    ] [\r
+        swap [ "." swap 3append ] with map\r
+    ] if ;\r
+\r
+: vocabs-in-dir ( root name -- )\r
+    dupd (all-child-vocabs) [\r
+        2dup vocab-dir? [ 2dup swap >vocab-link , ] when\r
+        vocabs-in-dir\r
+    ] with each ;\r
+\r
+: all-vocabs ( -- assoc )\r
+    vocab-roots get [\r
+        dup [ "" vocabs-in-dir ] { } make\r
+    ] { } map>assoc ;\r
+\r
+MEMO: all-vocabs-seq ( -- seq )\r
+    all-vocabs values concat ;\r
+\r
+: dangerous? ( name -- ? )\r
+    #! Hack\r
+    {\r
+        { [ "cpu." ?head ] [ t ] }\r
+        { [ "io.unix" ?head ] [ t ] }\r
+        { [ "io.windows" ?head ] [ t ] }\r
+        { [ "ui.x11" ?head ] [ t ] }\r
+        { [ "ui.windows" ?head ] [ t ] }\r
+        { [ "ui.cocoa" ?head ] [ t ] }\r
+        { [ "cocoa" ?head ] [ t ] }\r
+        { [ "core-foundation" ?head ] [ t ] }\r
+        { [ "vocabs.loader.test" ?head ] [ t ] }\r
+        { [ "editors." ?head ] [ t ] }\r
+        { [ ".windows" ?tail ] [ t ] }\r
+        { [ ".unix" ?tail ] [ t ] }\r
+        { [ "unix." ?head ] [ t ] }\r
+        { [ ".linux" ?tail ] [ t ] }\r
+        { [ ".bsd" ?tail ] [ t ] }\r
+        { [ ".macosx" ?tail ] [ t ] }\r
+        { [ "windows." ?head ] [ t ] }\r
+        { [ "cocoa" ?head ] [ t ] }\r
+        { [ ".test" ?tail ] [ t ] }\r
+        { [ "raptor" ?head ] [ t ] }\r
+        { [ dup "tools.deploy.app" = ] [ t ] }\r
+        { [ t ] [ f ] }\r
+    } cond nip ;\r
+\r
+: filter-dangerous ( seq -- seq' )\r
+    [ vocab-name dangerous? not ] subset ;\r
+\r
+: try-everything ( -- failures )\r
+    all-vocabs-seq\r
+    filter-dangerous\r
+    require-all ;\r
+\r
+: load-everything ( -- )\r
+    try-everything load-failures. ;\r
+\r
+: unrooted-child-vocabs ( prefix -- seq )\r
+    dup empty? [ CHAR: . add ] unless\r
+    vocabs\r
+    [ vocab-root not ] subset\r
+    [\r
+        vocab-name swap ?head CHAR: . rot member? not and\r
+    ] with subset\r
+    [ vocab ] map ;\r
+\r
+: all-child-vocabs ( prefix -- assoc )\r
+    vocab-roots get [\r
+        over dupd dupd (all-child-vocabs)\r
+        swap [ >vocab-link ] curry map\r
+    ] { } map>assoc\r
+    f rot unrooted-child-vocabs 2array add ;\r
+\r
+: all-child-vocabs-seq ( prefix -- assoc )\r
+    vocab-roots get swap [\r
+        dupd (all-child-vocabs)\r
+        [ vocab-dir? ] with subset\r
+    ] curry map concat ;\r
+\r
+: map>set ( seq quot -- )\r
+    map concat prune natural-sort ; inline\r
+\r
+MEMO: all-tags ( -- seq )\r
+    all-vocabs-seq [ vocab-tags ] map>set ;\r
+\r
+MEMO: all-authors ( -- seq )\r
+    all-vocabs-seq [ vocab-authors ] map>set ;\r
+\r
+: reset-cache ( -- )\r
+    \ (vocab-file-contents) reset-memoized\r
+    \ all-vocabs-seq reset-memoized\r
+    \ all-authors reset-memoized\r
+    \ all-tags reset-memoized ;\r
index 8078ec4a338fd1161dfcc50fb4e5a144920473b0..8dca72c29e2ece43eba41d5d150d3b164f9f7244 100755 (executable)
@@ -4,6 +4,7 @@ USING: alien alien.accessors alien.c-types arrays io kernel libc
 math math.vectors namespaces opengl opengl.gl prettyprint assocs
 sequences io.files io.styles continuations freetype
 ui.gadgets.worlds ui.render ui.backend byte-arrays ;
+
 IN: ui.freetype
 
 TUPLE: freetype-renderer ;
@@ -74,7 +75,7 @@ M: freetype-renderer free-fonts ( world -- )
 : open-face ( font style -- face )
     ttf-name ttf-path
     dup malloc-file-contents
-    swap file-length
+    swap file-info file-info-size
     (open-face) ;
 
 SYMBOL: dpi
index 2f82d983cce358512630d5bd3445eb61e9f58964..fb4c00097135fd949955c6014993e4c14402c9af 100755 (executable)
@@ -1,5 +1,5 @@
 USING: ui.gadgets ui.gestures help.markup help.syntax
-kernel classes strings opengl.gl ;
+kernel classes strings opengl.gl models ;
 IN: ui.render
 
 HELP: gadget
@@ -15,7 +15,7 @@ HELP: gadget
         { { $link gadget-clipped? } " - a boolean indicating if clipping will be enabled when drawing this gadget's children." }
         { { $link gadget-interior } " - an object whose class implements the " { $link draw-interior } " generic word." }
         { { $link gadget-boundary } " - an object whose class implements the " { $link draw-boundary } " generic word." }
-        { { $link gadget-model } " - XXX" }
+        { { $link gadget-model } " - a " { $link model } " or " { $link f } "; see " { $link "ui-control-impl" } }
     }
 "Gadgets delegate to " { $link rect } " instances holding their location and dimensions." }
 { $notes
index 093222f17b8288625bdf4dff1a52ccdd4bffa25b..51a545db47693d37a48b3f3b1499c0bb4751f7c5 100755 (executable)
@@ -8,7 +8,7 @@ namespaces parser prettyprint quotations tools.annotations
 editors tools.profiler tools.test tools.time tools.walker
 ui.commands ui.gadgets.editors ui.gestures ui.operations
 ui.tools.deploy vocabs vocabs.loader words sequences
-tools.browser classes compiler.units ;
+tools.vocabs classes compiler.units ;
 IN: ui.tools.operations
 
 V{ } clone operations set-global
@@ -84,11 +84,7 @@ UNION: definition word method-spec link vocab vocab-link ;
     { +secondary+ t }
 } define-operation
 
-[
-    class
-    { link word vocab vocab-link vocab-tag vocab-author }
-    memq?
-] \ com-follow H{
+[ topic? ] \ com-follow H{
     { +keyboard+ T{ key-down f { C+ } "H" } }
     { +primary+ t }
 } define-operation
index b37b4ca7076def37fdb761a545b1a7c8d68d7e7f..45ac64539262e6b684cf2bbcd86b143605d5d2c4 100755 (executable)
@@ -7,7 +7,7 @@ source-files definitions strings tools.completion tools.crossref
 tuples ui.commands ui.gadgets ui.gadgets.editors
 ui.gadgets.lists ui.gadgets.scrollers ui.gadgets.tracks
 ui.gestures ui.operations vocabs words vocabs.loader
-tools.browser unicode.case calendar ui ;
+tools.vocabs unicode.case calendar ui ;
 IN: ui.tools.search
 
 TUPLE: live-search field list ;
index b98b1dba28112fa28afbb7f762e62e3d01b2f9a6..d71b6574910721850c16dba3b08ec1614e6ffc02 100755 (executable)
@@ -8,7 +8,8 @@ prettyprint quotations sequences ui ui.commands ui.gadgets
 ui.gadgets.books ui.gadgets.buttons ui.gadgets.labelled
 ui.gadgets.scrollers ui.gadgets.tracks ui.gadgets.worlds
 ui.gadgets.presentations ui.gestures words vocabs.loader
-tools.test ui.gadgets.buttons ui.gadgets.status-bar mirrors ;
+tools.test tools.vocabs ui.gadgets.buttons ui.gadgets.status-bar
+mirrors ;
 IN: ui.tools
 
 : <workspace-tabs> ( -- tabs )
index f65f293ca457ca6436fe5ce12772c934dab65f4d..8eb5fe59aae119c27e73012245d0e8dd6e84f505 100755 (executable)
@@ -266,11 +266,6 @@ SYMBOL: nc-buttons
     key-modifiers swap message>button
     [ <button-down> ] [ <button-up> ] if ;
 
-: mouse-buttons ( -- seq ) WM_LBUTTONDOWN WM_RBUTTONDOWN 2array ;
-
-: capture-mouse? ( umsg -- ? )
-    mouse-buttons member? ;
-
 : prepare-mouse ( hWnd uMsg wParam lParam -- button coordinate world )
     nip >r mouse-event>gesture r> >lo-hi rot window ;
 
@@ -287,8 +282,10 @@ SYMBOL: nc-buttons
     mouse-captured off ;
 
 : handle-wm-buttondown ( hWnd uMsg wParam lParam -- )
-    >r >r dup capture-mouse? [ over set-capture ] when r> r>
-    prepare-mouse send-button-down ;
+    >r >r
+    over set-capture
+    dup message>button drop nc-buttons get delete
+    r> r> prepare-mouse send-button-down ;
 
 : handle-wm-buttonup ( hWnd uMsg wParam lParam -- )
     mouse-captured get [ release-capture ] when
old mode 100644 (file)
new mode 100755 (executable)
index 8d2d11e..6e01ae9
@@ -2,6 +2,10 @@ USING: alien.syntax ;
 
 IN: unix.types
 
+! FreeBSD 7 x86.32
+
+! Need to verify on 64-bit
+
 TYPEDEF: ushort          __uint16_t
 TYPEDEF: uint           __uint32_t
 TYPEDEF: int            __int32_t
@@ -16,4 +20,7 @@ TYPEDEF: __uint32_t     gid_t
 TYPEDEF: __int64_t      off_t
 TYPEDEF: __int64_t      blkcnt_t
 TYPEDEF: __uint32_t     blksize_t
-TYPEDEF: __uint32_t     fflags_t
\ No newline at end of file
+TYPEDEF: __uint32_t     fflags_t
+TYPEDEF: int            ssize_t
+TYPEDEF: int            pid_t
+TYPEDEF: int            time_t
\ No newline at end of file
diff --git a/extra/vocabs/monitor/authors.txt b/extra/vocabs/monitor/authors.txt
deleted file mode 100644 (file)
index 1901f27..0000000
+++ /dev/null
@@ -1 +0,0 @@
-Slava Pestov
diff --git a/extra/vocabs/monitor/monitor.factor b/extra/vocabs/monitor/monitor.factor
deleted file mode 100755 (executable)
index 78e2339..0000000
+++ /dev/null
@@ -1,24 +0,0 @@
-! Copyright (C) 2008 Slava Pestov.\r
-! See http://factorcode.org/license.txt for BSD license.\r
-USING: threads io.files io.monitors init kernel\r
-tools.browser namespaces continuations vocabs.loader ;\r
-IN: vocabs.monitor\r
-\r
-! Use file system change monitoring to flush the tags/authors\r
-! cache\r
-SYMBOL: vocab-monitor\r
-\r
-: monitor-thread ( -- )\r
-    vocab-monitor get-global\r
-    next-change 2drop\r
-    t sources-changed? set-global reset-cache ;\r
-\r
-: start-monitor-thread\r
-    #! Silently ignore errors during monitor creation since\r
-    #! monitors are not supported on all platforms.\r
-    [\r
-        "" resource-path t <monitor> vocab-monitor set-global\r
-        [ monitor-thread t ] "Vocabulary monitor" spawn-server drop\r
-    ] ignore-errors ;\r
-\r
-[ start-monitor-thread ] "vocabs.monitor" add-init-hook\r
diff --git a/extra/vocabs/monitor/summary.txt b/extra/vocabs/monitor/summary.txt
deleted file mode 100644 (file)
index 27c0d38..0000000
+++ /dev/null
@@ -1 +0,0 @@
-Use io.monitors to clear tools.browser authors/tags/summary cache
index 7225ef91fde379f20f04f6a5053b4529079a1a1e..5515476c221cc135966948ae661305d70a457574 100644 (file)
@@ -83,7 +83,9 @@
     (" !.*$" . font-lock-comment-face)
     ("( .* )" . font-lock-comment-face)
     "MAIN:"
-    "IN:" "USING:" "TUPLE:" "^C:" "^M:" "USE:" "REQUIRE:" "PROVIDE:"
+    "IN:" "USING:" "TUPLE:" "^C:" "^M:"
+    "METHOD:"
+    "USE:" "REQUIRE:" "PROVIDE:"
     "REQUIRES:"
     "GENERIC:" "GENERIC#" "SYMBOL:" "PREDICATE:" "VAR:" "VARS:"
     "C-STRUCT:"
index 2be071c17dedefe1536621ba16f23e0d8a415b99..880de8f47a0794c6b2abd438564b122b1abd3223 100755 (executable)
@@ -1,6 +1,9 @@
-#!/bin/bash
+#!/bin/sh
 
-if [ \( `uname -s` = Darwin \) -a \( `uname -p` = powerpc \) ]
+if [ \( `uname -s ` = FreeBSD \) -a \( `uname -p` = i386 \) ]
+then
+  echo freebsd-x86-32
+elif [ \( `uname -s` = Darwin \) -a \( `uname -p` = powerpc \) ]
 then
   echo macosx-ppc
 elif [ `uname -s` = Darwin ]
@@ -17,4 +20,4 @@ then
   echo winnt-x86-`./misc/wordsize`
 else
   echo help
-fi
\ No newline at end of file
+fi
diff --git a/unmaintained/pdf/authors.txt b/unmaintained/pdf/authors.txt
new file mode 100644 (file)
index 0000000..7c29e7c
--- /dev/null
@@ -0,0 +1 @@
+Elie Chaftari
diff --git a/unmaintained/pdf/libhpdf/libhpdf.factor b/unmaintained/pdf/libhpdf/libhpdf.factor
new file mode 100644 (file)
index 0000000..a40b7cd
--- /dev/null
@@ -0,0 +1,180 @@
+! Copyright (C) 2007 Elie CHAFTARI
+! See http://factorcode.org/license.txt for BSD license.
+!
+! Tested with libharu2 2.0.8 on Mac OS X 10.4.9 PowerPC
+!
+! export LD_LIBRARY_PATH=/opt/local/lib
+
+USING: alien alien.syntax combinators system ;
+
+IN: pdf.libhpdf
+
+<< "libhpdf" {
+    { [ win32? ] [ "libhpdf.dll" "stdcall" ] }
+    { [ macosx? ] [ "libhpdf.dylib" "cdecl" ] }
+    { [ unix? ] [ "$LD_LIBRARY_PATH/libhpdf.so" "cdecl" ] }
+} cond add-library >>
+
+! compression mode
+: HPDF_COMP_NONE      HEX: 00 ; inline ! No contents are compressed
+: HPDF_COMP_TEXT      HEX: 01 ; inline ! Compress contents stream of page
+: HPDF_COMP_IMAGE     HEX: 02 ; inline ! Compress streams of image objects
+: HPDF_COMP_METADATA  HEX: 04 ; inline ! Compress other data (fonts, cmaps...)
+: HPDF_COMP_ALL       HEX: 0F ; inline ! All stream data are compressed
+: HPDF_COMP_MASK      HEX: FF ; inline
+
+! page mode
+C-ENUM:
+    HPDF_PAGE_MODE_USE_NONE
+    HPDF_PAGE_MODE_USE_OUTLINE
+    HPDF_PAGE_MODE_USE_THUMBS
+    HPDF_PAGE_MODE_FULL_SCREEN
+    HPDF_PAGE_MODE_EOF
+;
+
+: error-code ( -- seq ) {
+     { HEX: 1001  "HPDF_ARRAY_COUNT_ERR\nInternal error. The consistency of the data was lost." }
+     { HEX: 1002  "HPDF_ARRAY_ITEM_NOT_FOUND\nInternal error. The consistency of the data was lost." }
+     { HEX: 1003  "HPDF_ARRAY_ITEM_UNEXPECTED_TYPE\nInternal error. The consistency of the data was lost." }
+     { HEX: 1004  "HPDF_BINARY_LENGTH_ERR\nThe length of the data exceeds HPDF_LIMIT_MAX_STRING_LEN." }
+     { HEX: 1005  "HPDF_CANNOT_GET_PALLET\nCannot get a pallet data from PNG image." }
+     { HEX: 1007  "HPDF_DICT_COUNT_ERR\nThe count of elements of a dictionary exceeds HPDF_LIMIT_MAX_DICT_ELEMENT" }
+     { HEX: 1008  "HPDF_DICT_ITEM_NOT_FOUND\nInternal error. The consistency of the data was lost." }
+     { HEX: 1009  "HPDF_DICT_ITEM_UNEXPECTED_TYPE\nInternal error. The consistency of the data was lost." }  
+     { HEX: 100A  "HPDF_DICT_STREAM_LENGTH_NOT_FOUND\nInternal error. The consistency of the data was lost." }  
+     { HEX: 100B  "HPDF_DOC_ENCRYPTDICT_NOT_FOUND\nHPDF_SetPermission() OR HPDF_SetEncryptMode() was called before a password is set." }
+     { HEX: 100C  "HPDF_DOC_INVALID_OBJECT\nInternal error. The consistency of the data was lost." }
+     { HEX: 100E  "HPDF_DUPLICATE_REGISTRATION\nTried to register a font that has been registered." }
+     { HEX: 100F  "HPDF_EXCEED_JWW_CODE_NUM_LIMIT\nCannot register a character to the japanese word wrap characters list." }
+     { HEX: 1011  "HPDF_ENCRYPT_INVALID_PASSWORD\nTried to set the owner password to NULL. owner password and user password is the same." }
+     { HEX: 1013  "HPDF_ERR_UNKNOWN_CLASS\nInternal error. The consistency of the data was lost." }
+     { HEX: 1014  "HPDF_EXCEED_GSTATE_LIMIT\nThe depth of the stack exceeded HPDF_LIMIT_MAX_GSTATE." }
+     { HEX: 1015  "HPDF_FAILED_TO_ALLOC_MEM\nMemory allocation failed." }
+     { HEX: 1016  "HPDF_FILE_IO_ERROR\nFile processing failed. (A detailed code is set.)" }
+     { HEX: 1017  "HPDF_FILE_OPEN_ERROR\nCannot open a file. (A detailed code is set.)" }
+     { HEX: 1019  "HPDF_FONT_EXISTS\nTried to load a font that has already been registered." }
+     { HEX: 101A  "HPDF_FONT_INVALID_WIDTHS_TABLE\nThe format of a font-file is invalid . Internal error. The consistency of the data was lost." }
+     { HEX: 101B  "HPDF_INVALID_AFM_HEADER\nCannot recognize a header of an afm file." }
+     { HEX: 101C  "HPDF_INVALID_ANNOTATION\nThe specified annotation handle is invalid." }
+     { HEX: 101E  "HPDF_INVALID_BIT_PER_COMPONENT\nBit-per-component of a image which was set as mask-image is invalid." }
+     { HEX: 101F  "HPDF_INVALID_CHAR_MATRICS_DATA\nCannot recognize char-matrics-data  of an afm file." }
+     { HEX: 1020  "HPDF_INVALID_COLOR_SPACE\n1. The color_space parameter of HPDF_LoadRawImage is invalid.\n2. Color-space of a image which was set as mask-image is invalid.\n3. The function which is invalid in the present color-space was invoked." }
+     { HEX: 1021  "HPDF_INVALID_COMPRESSION_MODE\nInvalid value was set when invoking HPDF_SetCommpressionMode()." }
+     { HEX: 1022  "HPDF_INVALID_DATE_TIME\nAn invalid date-time value was set." }
+     { HEX: 1023  "HPDF_INVALID_DESTINATION\nAn invalid destination handle was set." }
+     { HEX: 1025  "HPDF_INVALID_DOCUMENT\nAn invalid document handle is set." }
+     { HEX: 1026  "HPDF_INVALID_DOCUMENT_STATE\nThe function which is invalid in the present state was invoked." }
+     { HEX: 1027  "HPDF_INVALID_ENCODER\nAn invalid encoder handle was set." }
+     { HEX: 1028  "HPDF_INVALID_ENCODER_TYPE\nA combination between font and encoder is wrong." }
+     { HEX: 102B  "HPDF_INVALID_ENCODING_NAME\nAn Invalid encoding name is specified." }
+     { HEX: 102C  "HPDF_INVALID_ENCRYPT_KEY_LEN\nThe lengh of the key of encryption is invalid." }
+     { HEX: 102D  "HPDF_INVALID_FONTDEF_DATA\n1. An invalid font handle was set.\n2. Unsupported font format." }
+     { HEX: 102E  "HPDF_INVALID_FONTDEF_TYPE\nInternal error. The consistency of the data was lost." }
+     { HEX: 102F  "HPDF_INVALID_FONT_NAME\nA font which has the specified name is not found." }
+     { HEX: 1030  "HPDF_INVALID_IMAGE\nUnsupported image format." }
+     { HEX: 1031  "HPDF_INVALID_JPEG_DATA\nUnsupported image format." }
+     { HEX: 1032  "HPDF_INVALID_N_DATA\nCannot read a postscript-name from an afm file." }
+     { HEX: 1033  "HPDF_INVALID_OBJECT\n1. An invalid object is set.\n2. Internal error. The consistency of the data was lost." }
+     { HEX: 1034  "HPDF_INVALID_OBJ_ID\nInternal error. The consistency of the data was lost." }
+     { HEX: 1035  "HPDF_INVALID_OPERATION\nInvoked HPDF_Image_SetColorMask() against the image-object which was set a mask-image." }
+     { HEX: 1036  "HPDF_INVALID_OUTLINE\nAn invalid outline-handle was specified." }
+     { HEX: 1037  "HPDF_INVALID_PAGE\nAn invalid page-handle was specified." }
+     { HEX: 1038  "HPDF_INVALID_PAGES\nAn invalid pages-handle was specified. (internal error)" }
+     { HEX: 1039  "HPDF_INVALID_PARAMETER\nAn invalid value is set." }
+     { HEX: 103B  "HPDF_INVALID_PNG_IMAGE\nInvalid PNG image format." }
+     { HEX: 103C  "HPDF_INVALID_STREAM\nInternal error. The consistency of the data was lost." }
+     { HEX: 103D  "HPDF_MISSING_FILE_NAME_ENTRY\nInternal error. The \"_FILE_NAME\" entry for delayed loading is missing." }
+     { HEX: 103F  "HPDF_INVALID_TTC_FILE\nInvalid .TTC file format." }
+     { HEX: 1040  "HPDF_INVALID_TTC_INDEX\nThe index parameter was exceed the number of included fonts" }
+     { HEX: 1041  "HPDF_INVALID_WX_DATA\nCannot read a width-data from an afm file." }
+     { HEX: 1042  "HPDF_ITEM_NOT_FOUND\nInternal error. The consistency of the data was lost." }
+     { HEX: 1043  "HPDF_LIBPNG_ERROR\nAn error has returned from PNGLIB while loading an image." }
+     { HEX: 1044  "HPDF_NAME_INVALID_VALUE\nInternal error. The consistency of the data was lost." }
+     { HEX: 1045  "HPDF_NAME_OUT_OF_RANGE\nInternal error. The consistency of the data was lost." }
+     { HEX: 1049  "HPDF_PAGES_MISSING_KIDS_ENTRY\nInternal error. The consistency of the data was lost." }
+     { HEX: 104A  "HPDF_PAGE_CANNOT_FIND_OBJECT\nInternal error. The consistency of the data was lost." }
+     { HEX: 104B  "HPDF_PAGE_CANNOT_GET_ROOT_PAGES\nInternal error. The consistency of the data was lost." }
+     { HEX: 104C  "HPDF_PAGE_CANNOT_RESTORE_GSTATE\nThere are no graphics-states to be restored." }
+     { HEX: 104D  "HPDF_PAGE_CANNOT_SET_PARENT\nInternal error. The consistency of the data was lost." }
+     { HEX: 104E  "HPDF_PAGE_FONT_NOT_FOUND\nThe current font is not set." }
+     { HEX: 104F  "HPDF_PAGE_INVALID_FONT\nAn invalid font-handle was specified." }
+     { HEX: 1050  "HPDF_PAGE_INVALID_FONT_SIZE\nAn invalid font-size was set." }
+     { HEX: 1051  "HPDF_PAGE_INVALID_GMODE\nSee Graphics mode." }
+     { HEX: 1052  "HPDF_PAGE_INVALID_INDEX\nInternal error. The consistency of the data was lost." }
+     { HEX: 1053  "HPDF_PAGE_INVALID_ROTATE_VALUE\nThe specified value is not a multiple of 90." }
+     { HEX: 1054  "HPDF_PAGE_INVALID_SIZE\nAn invalid page-size was set." }
+     { HEX: 1055  "HPDF_PAGE_INVALID_XOBJECT\nAn invalid image-handle was set." }
+     { HEX: 1056  "HPDF_PAGE_OUT_OF_RANGE\nThe specified value is out of range." }
+     { HEX: 1057  "HPDF_REAL_OUT_OF_RANGE\nThe specified value is out of range." }
+     { HEX: 1058  "HPDF_STREAM_EOF\nUnexpected EOF marker was detected." }
+     { HEX: 1059  "HPDF_STREAM_READLN_CONTINUE\nInternal error. The consistency of the data was lost." }
+     { HEX: 105B  "HPDF_STRING_OUT_OF_RANGE\nThe length of the specified text is too long." }
+     { HEX: 105C  "HPDF_THIS_FUNC_WAS_SKIPPED\nThe execution of a function was skipped because of other errors." }
+     { HEX: 105D  "HPDF_TTF_CANNOT_EMBEDDING_FONT\nThis font cannot be embedded. (restricted by license.)" }
+     { HEX: 105E  "HPDF_TTF_INVALID_CMAP\nUnsupported ttf format. (cannot find unicode cmap.)" }
+     { HEX: 105F  "HPDF_TTF_INVALID_FOMAT\nUnsupported ttf format." }
+     { HEX: 1060  "HPDF_TTF_MISSING_TABLE\nUnsupported ttf format. (cannot find a necessary table.)" }
+     { HEX: 1061  "HPDF_UNSUPPORTED_FONT_TYPE\nInternal error. The consistency of the data was lost." }
+     { HEX: 1062  "HPDF_UNSUPPORTED_FUNC\n1. The library is not configured to use PNGLIB.\n2. Internal error. The consistency of the data was lost." }
+     { HEX: 1063  "HPDF_UNSUPPORTED_JPEG_FORMAT\nUnsupported Jpeg format." }
+     { HEX: 1064  "HPDF_UNSUPPORTED_TYPE1_FONT\nFailed to parse .PFB file." }
+     { HEX: 1065  "HPDF_XREF_COUNT_ERR\nInternal error. The consistency of the data was lost." }
+     { HEX: 1066  "HPDF_ZLIB_ERROR\nAn error has occurred while executing a function of Zlib." }
+     { HEX: 1067  "HPDF_INVALID_PAGE_INDEX\nAn error returned from Zlib." }
+     { HEX: 1068  "HPDF_INVALID_URI\nAn invalid URI was set." }
+     { HEX: 1069  "HPDF_PAGELAYOUT_OUT_OF_RANGE\nAn invalid page-layout was set." }
+     { HEX: 1070  "HPDF_PAGEMODE_OUT_OF_RANGE\nAn invalid page-mode was set." }
+     { HEX: 1071  "HPDF_PAGENUM_STYLE_OUT_OF_RANGE\nAn invalid page-num-style was set." }
+     { HEX: 1072  "HPDF_ANNOT_INVALID_ICON\nAn invalid icon was set." }
+     { HEX: 1073  "HPDF_ANNOT_INVALID_BORDER_STYLE\nAn invalid border-style was set." }
+     { HEX: 1074  "HPDF_PAGE_INVALID_DIRECTION\nAn invalid page-direction was set." }
+     { HEX: 1075  "HPDF_INVALID_FONT\nAn invalid font-handle was specified." }
+} ;
+
+LIBRARY: libhpdf
+
+! ===============================================
+! hpdf.h
+! ===============================================
+
+FUNCTION: void* HPDF_New ( void* user_error_fn, void* user_data ) ;
+
+FUNCTION: void* HPDF_Free ( void* pdf ) ;
+
+FUNCTION: ulong HPDF_SetCompressionMode ( void* pdf, uint mode ) ;
+
+FUNCTION: ulong HPDF_SetPageMode ( void* pdf, uint mode ) ;
+
+FUNCTION: void* HPDF_AddPage ( void* pdf ) ;
+
+FUNCTION: ulong HPDF_SaveToFile ( void* pdf, char* file_name ) ;
+
+FUNCTION: float HPDF_Page_GetHeight ( void* page ) ;
+
+FUNCTION: float HPDF_Page_GetWidth ( void* page ) ;
+
+FUNCTION: ulong HPDF_Page_SetLineWidth ( void* page, float line_width ) ;
+
+FUNCTION: ulong HPDF_Page_Rectangle ( void* page, float x, float y,
+                                      float width, float height ) ;
+
+FUNCTION: ulong HPDF_Page_Stroke ( void* page ) ;
+
+FUNCTION: void* HPDF_GetFont ( void* pdf, char* font_name,
+                               char* encoding_name ) ;
+
+FUNCTION: ulong HPDF_Page_SetFontAndSize ( void* page, void* font,
+                                           float size ) ;
+
+FUNCTION: float HPDF_Page_TextWidth ( void* page, char* text ) ;
+
+FUNCTION: ulong HPDF_Page_BeginText ( void* page ) ;
+
+FUNCTION: ulong HPDF_Page_TextOut ( void* page, float xpos, float ypos,
+                                    char* text ) ;
+
+FUNCTION: ulong HPDF_Page_EndText ( void*  page ) ;
+
+FUNCTION: ulong HPDF_Page_MoveTextPos ( void* page, float x, float y ) ;
+
+FUNCTION: ulong HPDF_Page_ShowText ( void* page, char* text ) ;
diff --git a/unmaintained/pdf/pdf-tests.factor b/unmaintained/pdf/pdf-tests.factor
new file mode 100755 (executable)
index 0000000..290773a
--- /dev/null
@@ -0,0 +1,98 @@
+USING: io.files kernel math namespaces pdf pdf.libhpdf prettyprint sequences ;
+IN: pdf.tests
+
+SYMBOL: font
+
+SYMBOL: width
+SYMBOL: height
+SYMBOL: twidth
+
+: font-list ( -- seq ) {
+    "Courier"
+    "Courier-Bold"
+    "Courier-Oblique"
+    "Courier-BoldOblique"
+    "Helvetica"
+    "Helvetica-Bold"
+    "Helvetica-Oblique"
+    "Helvetica-BoldOblique"
+    "Times-Roman"
+    "Times-Bold"
+    "Times-Italic"
+    "Times-BoldItalic"
+    "Symbol"
+    "ZapfDingbats"
+} ;
+
+[
+    ! HPDF_COMP_ALL set-compression-mode
+
+    ! HPDF_PAGE_MODE_USE_OUTLINE set-page-mode
+
+    ! Add a new page object
+    add-page
+
+    get-page-height height set
+
+    get-page-width width set
+
+    ! Print the lines of the page
+    1 set-page-line-width
+
+    50 50 width get 100 - height get 110 - page-rectangle
+
+    page-stroke
+
+    ! Print the title of the page (with positioning center)
+    "Helvetica" f get-font font set
+
+    font get 24 set-page-font-and-size
+
+    "Font Demo" page-text-width twidth set
+
+    [
+        width get twidth get - 2 / height get 50 - "Font Demo" page-text-out
+
+    ] with-text
+
+    ! Print subtitle
+    [
+        font get 16 set-page-font-and-size
+
+        60 height get 80 - "<Standard Type1 font samples>" page-text-out
+
+    ] with-text
+
+    ! Print font list
+    [
+        60 height get 105 - page-move-text-pos
+
+        SYMBOL: fontname
+
+        font-list [
+
+            fontname set
+
+            fontname get f get-font font set
+
+            ! print a label of text
+            font get 9 set-page-font-and-size
+
+            fontname get page-show-text
+
+            0 -18 page-move-text-pos
+
+            ! print a sample text
+            font get 20 set-page-font-and-size
+
+            "abcdefgABCDEFG12345!#$%&+-@?" page-show-text
+
+            0 -20 page-move-text-pos
+
+        ] each
+
+    ] with-text
+
+    "font_test.pdf" temp-file save-to-file
+
+] with-pdf
diff --git a/unmaintained/pdf/pdf.factor b/unmaintained/pdf/pdf.factor
new file mode 100644 (file)
index 0000000..98c94e5
--- /dev/null
@@ -0,0 +1,97 @@
+! Copyright (C) 2007 Elie CHAFTARI
+! See http://factorcode.org/license.txt for BSD license.
+!
+! Tested with libharu2 2.0.8 on Mac OS X 10.4.9 PowerPC
+
+USING: assocs continuations hashtables kernel math namespaces pdf.libhpdf ;
+
+IN: pdf
+
+SYMBOL: pdf
+SYMBOL: page
+
+! =========================================================
+! Error handling routines
+! =========================================================
+
+: check-status ( status -- )
+    dup zero? [ 
+        drop
+    ] [
+        error-code >hashtable at throw   
+    ] if ;
+
+! =========================================================
+! Document handling routines
+! =========================================================
+
+: new-pdf ( error-handler user-data -- )
+    HPDF_New pdf set ;
+
+: free-pdf ( -- )
+    pdf get HPDF_Free drop ;
+
+: with-pdf ( quot -- )
+    [ f f new-pdf [ free-pdf ] [ ] cleanup ] with-scope ; inline
+
+: set-compression-mode ( mode -- )
+    pdf get swap HPDF_SetCompressionMode check-status ;
+
+: set-page-mode ( mode -- )
+    pdf get swap HPDF_SetPageMode check-status ;
+
+: add-page ( -- )
+    pdf get HPDF_AddPage page set ;
+
+: save-to-file ( filename -- )
+    pdf get swap HPDF_SaveToFile check-status ;
+
+: get-font ( fontname encoding -- font )
+    pdf get -rot HPDF_GetFont ;
+
+! =========================================================
+! Page Handling routines
+! =========================================================
+
+: get-page-height ( -- height )
+    page get HPDF_Page_GetHeight ;
+
+: get-page-width ( -- width )
+    page get HPDF_Page_GetWidth ;
+
+: page-text-width ( text -- width )
+    page get swap HPDF_Page_TextWidth ;
+
+! =========================================================
+! Graphics routines
+! =========================================================
+
+: set-page-line-width ( linewidth -- )
+    page get swap HPDF_Page_SetLineWidth check-status ;
+
+: page-rectangle ( x y width height -- )
+    >r >r >r >r page get r> r> r> r> HPDF_Page_Rectangle check-status ;
+
+: page-stroke ( -- )
+    page get HPDF_Page_Stroke check-status ;
+
+: set-page-font-and-size ( font size -- )
+    page get -rot HPDF_Page_SetFontAndSize check-status ;
+
+: page-begin-text ( -- )
+    page get HPDF_Page_BeginText check-status ;
+
+: page-text-out ( xpos ypos text -- )
+    page get -roll HPDF_Page_TextOut check-status ;
+
+: page-end-text ( -- )
+    page get HPDF_Page_EndText check-status ;
+
+: with-text ( -- )
+    [ page-begin-text [ page-end-text ] [ ] cleanup ] with-scope ; inline
+
+: page-move-text-pos ( x y -- )
+    page get -rot HPDF_Page_MoveTextPos check-status ;
+
+: page-show-text ( text -- )
+    page get swap HPDF_Page_ShowText check-status ;
diff --git a/unmaintained/pdf/readme.txt b/unmaintained/pdf/readme.txt
new file mode 100644 (file)
index 0000000..fd52944
--- /dev/null
@@ -0,0 +1,9 @@
+To build libharu as a shared dylib on Mac OS X, modify the Makefile after calling ./configure --shared\r\rHere are the relevant sections and the lines to be changed:\r\r...\rCC=cc\rPREFIX=/usr/local\r\rLIBNAME=libhpdf.a\rSONAME=libhpdf.dylib\rSOVER1=.1\rSOVER2=.0.0\rLIBTARGET=libhpdf.dylib\rCFLAGS=-Iinclude -fPIC -fno-common -c\r...\r$(SONAME): $(OBJS)\r$(CC) -dynamiclib -o $(SONAME)$(SOVER1)$(SOVER2) $(OBJS) $(LDFLAGS) -Wl\rln -sf $(SONAME)$(SOVER1)$(SOVER2) $(SONAME)$(SOVER1)\rln -sf $(SONAME)$(SOVER1) $(SONAME)
+
+Now you can build and install:
+
+make clean
+make
+make install
+
+Test PDF files from pdf-tests.factor are generated in the test folder.
\ No newline at end of file