]> gitweb.factorcode.org Git - factor.git/commitdiff
Merge branch 'master' of git://repo.or.cz/factor/jcg
authorDoug Coleman <doug.coleman@gmail.com>
Wed, 10 Dec 2008 03:16:37 +0000 (21:16 -0600)
committerDoug Coleman <doug.coleman@gmail.com>
Wed, 10 Dec 2008 03:16:37 +0000 (21:16 -0600)
Conflicts:

basis/ui/cocoa/cocoa.factor

269 files changed:
basis/alarms/alarms.factor
basis/alien/c-types/c-types.factor
basis/alien/prettyprint/prettyprint.factor [new file with mode: 0644]
basis/alien/strings/strings-docs.factor
basis/alien/strings/strings-tests.factor
basis/alien/strings/strings.factor
basis/alien/strings/unix/unix.factor [new file with mode: 0644]
basis/alien/strings/windows/windows.factor [new file with mode: 0644]
basis/alien/syntax/syntax.factor
basis/bit-arrays/bit-arrays.factor
basis/bit-vectors/bit-vectors.factor
basis/bootstrap/bootstrap-error.factor [new file with mode: 0644]
basis/bootstrap/compiler/compiler.factor
basis/bootstrap/finish-bootstrap.factor [new file with mode: 0644]
basis/bootstrap/finish-staging.factor [new file with mode: 0644]
basis/bootstrap/math/math.factor
basis/bootstrap/stage2.factor
basis/bootstrap/threads/threads.factor
basis/byte-vectors/byte-vectors-docs.factor [new file with mode: 0644]
basis/byte-vectors/byte-vectors-tests.factor [new file with mode: 0644]
basis/byte-vectors/byte-vectors.factor [new file with mode: 0644]
basis/byte-vectors/summary.txt [new file with mode: 0644]
basis/byte-vectors/tags.txt [new file with mode: 0644]
basis/calendar/format/format.factor
basis/checksums/md5/md5.factor
basis/checksums/openssl/openssl.factor
basis/checksums/sha1/sha1.factor
basis/checksums/stream/stream.factor [new file with mode: 0644]
basis/cocoa/application/application.factor
basis/cocoa/messages/messages.factor
basis/cocoa/subclassing/subclassing.factor
basis/command-line/command-line.factor
basis/compiler/cfg/alias-analysis/alias-analysis-tests.factor
basis/compiler/cfg/dead-code/dead-code-tests.factor
basis/compiler/cfg/debugger/debugger.factor
basis/compiler/cfg/intrinsics/allot/allot.factor
basis/compiler/cfg/intrinsics/intrinsics.factor
basis/compiler/cfg/registers/registers.factor
basis/compiler/cfg/value-numbering/value-numbering-tests.factor
basis/compiler/cfg/write-barrier/write-barrier-tests.factor
basis/compiler/codegen/fixup/fixup.factor
basis/compiler/compiler.factor
basis/compiler/tree/dead-code/recursive/recursive.factor
basis/compiler/tree/debugger/debugger.factor
basis/compiler/tree/propagation/inlining/inlining.factor
basis/compiler/tree/propagation/slots/slots.factor
basis/concurrency/combinators/combinators.factor
basis/core-foundation/core-foundation-tests.factor [new file with mode: 0644]
basis/core-foundation/core-foundation.factor
basis/core-foundation/run-loop/run-loop.factor
basis/core-foundation/run-loop/thread/thread.factor
basis/cpu/x86/32/bootstrap.factor
basis/cpu/x86/64/bootstrap.factor
basis/cpu/x86/64/unix/bootstrap.factor
basis/cpu/x86/64/winnt/bootstrap.factor
basis/cpu/x86/assembler/assembler.factor
basis/cpu/x86/bootstrap.factor
basis/db/db-docs.factor
basis/debugger/debugger.factor
basis/delegate/delegate.factor
basis/delegate/protocols/protocols.factor
basis/environment/winnt/winnt.factor
basis/functors/functors.factor
basis/generalizations/generalizations-docs.factor
basis/generalizations/generalizations.factor
basis/help/definitions/definitions.factor
basis/help/handbook/handbook.factor
basis/help/lint/lint.factor
basis/http/client/client.factor
basis/http/client/debugger/debugger.factor [new file with mode: 0644]
basis/http/http.factor
basis/io/encodings/utf16/utf16-tests.factor
basis/io/encodings/utf16n/utf16n-docs.factor [new file with mode: 0644]
basis/io/encodings/utf16n/utf16n-tests.factor [new file with mode: 0644]
basis/io/encodings/utf16n/utf16n.factor [new file with mode: 0644]
basis/io/files/unique/backend/backend.factor [deleted file]
basis/io/files/unique/unique-docs.factor
basis/io/files/unique/unique.factor
basis/io/paths/authors.txt [new file with mode: 0755]
basis/io/paths/paths-tests.factor [new file with mode: 0644]
basis/io/paths/paths.factor [new file with mode: 0755]
basis/io/paths/windows/authors.txt [new file with mode: 0644]
basis/io/paths/windows/tags.txt [new file with mode: 0644]
basis/io/paths/windows/windows.factor [new file with mode: 0644]
basis/io/ports/ports.factor
basis/io/servers/connection/connection.factor
basis/io/sockets/secure/openssl/openssl.factor
basis/io/sockets/sockets.factor
basis/io/streams/byte-array/byte-array-docs.factor [new file with mode: 0644]
basis/io/streams/byte-array/byte-array-tests.factor [new file with mode: 0644]
basis/io/streams/byte-array/byte-array.factor [new file with mode: 0644]
basis/io/streams/duplex/duplex.factor
basis/io/streams/limited/limited.factor
basis/io/styles/styles.factor
basis/io/unix/backend/backend.factor
basis/io/unix/epoll/epoll.factor
basis/io/unix/files/macosx/macosx.factor
basis/io/unix/files/unique/unique.factor
basis/io/unix/kqueue/kqueue.factor
basis/io/unix/launcher/launcher.factor
basis/io/unix/linux/linux.factor
basis/io/unix/macosx/macosx.factor
basis/io/unix/sockets/secure/secure.factor
basis/io/windows/files/files.factor
basis/io/windows/files/unique/unique.factor
basis/io/windows/nt/files/files.factor [changed mode: 0644->0755]
basis/io/windows/nt/monitors/monitors.factor
basis/listener/listener.factor
basis/locals/definitions/definitions.factor [new file with mode: 0644]
basis/locals/errors/errors.factor [new file with mode: 0644]
basis/locals/fry/fry.factor [new file with mode: 0644]
basis/locals/locals-docs.factor
basis/locals/locals-tests.factor
basis/locals/locals.factor
basis/locals/macros/macros.factor [new file with mode: 0644]
basis/locals/parser/parser.factor [new file with mode: 0644]
basis/locals/prettyprint/prettyprint.factor [new file with mode: 0644]
basis/locals/rewrite/closures/closures.factor [new file with mode: 0644]
basis/locals/rewrite/point-free/point-free.factor [new file with mode: 0644]
basis/locals/rewrite/sugar/sugar.factor [new file with mode: 0644]
basis/locals/types/types.factor [new file with mode: 0644]
basis/logging/analysis/analysis.factor
basis/math/complex/complex.factor
basis/math/complex/prettyprint/prettyprint.factor [new file with mode: 0644]
basis/nibble-arrays/nibble-arrays.factor
basis/peg/debugger/debugger.factor [new file with mode: 0644]
basis/peg/ebnf/ebnf.factor
basis/peg/peg.factor
basis/persistent/hashtables/hashtables.factor
basis/persistent/vectors/vectors.factor
basis/present/present.factor
basis/prettyprint/backend/backend-docs.factor
basis/prettyprint/backend/backend.factor
basis/prettyprint/custom/custom-docs.factor [new file with mode: 0644]
basis/prettyprint/custom/custom.factor [new file with mode: 0644]
basis/prettyprint/prettyprint-docs.factor
basis/prettyprint/prettyprint.factor
basis/qualified/qualified.factor
basis/regexp/regexp.factor
basis/specialized-arrays/double/double.factor
basis/specialized-arrays/functor/functor.factor
basis/specialized-vectors/functor/functor.factor
basis/stack-checker/backend/backend.factor
basis/stack-checker/errors/errors.factor
basis/stack-checker/errors/prettyprint/prettyprint.factor [new file with mode: 0644]
basis/stack-checker/known-words/known-words.factor
basis/summary/summary.factor
basis/tools/cocoa/cocoa.factor [new file with mode: 0644]
basis/tools/cocoa/tags.txt [new file with mode: 0644]
basis/tools/deploy/backend/backend.factor
basis/tools/deploy/config/config-docs.factor
basis/tools/deploy/config/config.factor
basis/tools/deploy/config/editor/editor-docs.factor [new file with mode: 0644]
basis/tools/deploy/config/editor/editor.factor [new file with mode: 0644]
basis/tools/deploy/deploy-docs.factor
basis/tools/deploy/deploy-tests.factor
basis/tools/deploy/macosx/macosx.factor
basis/tools/deploy/shaker/shaker.factor
basis/tools/deploy/shaker/strip-cocoa.factor
basis/tools/deploy/unix/unix.factor
basis/tools/deploy/windows/windows.factor
basis/tools/disassembler/disassembler-tests.factor
basis/tools/files/files-tests.factor
basis/tools/files/files.factor
basis/tools/memory/memory.factor
basis/tools/walker/walker.factor
basis/ui/cocoa/cocoa.factor [changed mode: 0644->0755]
basis/ui/freetype/freetype.factor
basis/ui/gadgets/labelled/labelled.factor
basis/ui/gadgets/presentations/presentations.factor
basis/ui/gadgets/worlds/worlds.factor
basis/ui/tools/deploy/deploy.factor
basis/ui/ui.factor
basis/ui/windows/windows.factor
basis/ui/x11/x11.factor
basis/unicode/syntax/syntax.factor
basis/unix/debugger/debugger.factor [new file with mode: 0644]
basis/unix/debugger/tags.txt [new file with mode: 0644]
basis/unix/kqueue/kqueue.factor
basis/unix/linux/epoll/epoll.factor
basis/unix/unix.factor
basis/urls/prettyprint/prettyprint.factor [new file with mode: 0644]
basis/urls/urls.factor
basis/vlists/vlists.factor
basis/windows/shell32/shell32.factor
basis/windows/windows.factor
basis/windows/winsock/winsock.factor
basis/x11/xim/xim.factor
core/assocs/assocs-docs.factor
core/assocs/assocs.factor
core/bootstrap/primitives.factor
core/bootstrap/stage1.factor
core/bootstrap/syntax.factor
core/byte-arrays/byte-arrays.factor
core/byte-vectors/byte-vectors-docs.factor [deleted file]
core/byte-vectors/byte-vectors-tests.factor [deleted file]
core/byte-vectors/byte-vectors.factor [deleted file]
core/byte-vectors/summary.txt [deleted file]
core/byte-vectors/tags.txt [deleted file]
core/checksums/checksums.factor
core/classes/algebra/algebra-docs.factor
core/classes/tuple/tuple-docs.factor
core/classes/tuple/tuple.factor
core/combinators/combinators-docs.factor
core/growable/growable-docs.factor
core/io/streams/byte-array/byte-array-docs.factor [deleted file]
core/io/streams/byte-array/byte-array-tests.factor [deleted file]
core/io/streams/byte-array/byte-array.factor [deleted file]
core/kernel/kernel-docs.factor
core/kernel/kernel.factor
core/math/integers/integers.factor
core/memory/memory-tests.factor
core/memory/memory.factor
core/sequences/sequences-docs.factor
core/slots/slots.factor
core/source-files/source-files.factor
core/strings/parser/parser-tests.factor [new file with mode: 0644]
core/strings/parser/parser.factor
core/syntax/syntax.factor
core/vocabs/loader/loader-tests.factor
core/vocabs/loader/loader.factor
core/vocabs/loader/test/j/j.factor [new file with mode: 0644]
core/vocabs/loader/test/j/tags.txt [new file with mode: 0644]
core/vocabs/loader/test/k/k.factor [new file with mode: 0644]
core/vocabs/loader/test/k/tags.txt [new file with mode: 0644]
extra/bind-in/bind-in.factor
extra/crypto/barrett/barrett-tests.factor
extra/descriptive/descriptive.factor
extra/fuel/fuel.factor
extra/game-input/backend/dinput/dinput.factor
extra/hello-world/deploy.factor
extra/io/paths/authors.txt [deleted file]
extra/io/paths/paths.factor [deleted file]
extra/io/paths/windows/authors.txt [deleted file]
extra/io/paths/windows/tags.txt [deleted file]
extra/io/paths/windows/windows.factor [deleted file]
extra/math/binpack/authors.txt [new file with mode: 0644]
extra/math/binpack/binpack-docs.factor [new file with mode: 0644]
extra/math/binpack/binpack-tests.factor [new file with mode: 0644]
extra/math/binpack/binpack.factor [new file with mode: 0644]
extra/math/binpack/summary.txt [new file with mode: 0644]
extra/monads/monads-tests.factor
extra/multi-methods/multi-methods.factor
extra/parser-combinators/regexp/regexp.factor
extra/processing/gallery/trails/trails.factor [deleted file]
extra/reports/noise/noise.factor
extra/time/authors.txt [new file with mode: 0644]
extra/time/time-docs.factor [new file with mode: 0644]
extra/time/time-tests.factor [new file with mode: 0644]
extra/time/time.factor [new file with mode: 0644]
extra/trails/trails.factor [new file with mode: 0644]
extra/ui/offscreen/offscreen.factor [changed mode: 0644->0755]
misc/fuel/README
misc/fuel/factor-mode.el
misc/fuel/fuel-debug.el [new file with mode: 0644]
misc/fuel/fuel-eval.el
misc/fuel/fuel-font-lock.el
misc/fuel/fuel-help.el
misc/fuel/fuel-listener.el
misc/fuel/fuel-mode.el
vm/code_heap.c
vm/data_gc.c
vm/data_gc.h
vm/factor.c
vm/primitives.c
vm/quotations.c
vm/quotations.h
vm/types.c
vm/types.h

index ad1838b3df4421afcbf4b34c7b2b29fd5912c694..9cc05b41591cd8974def94d2f10646a3f7598e8a 100644 (file)
@@ -1,7 +1,7 @@
 ! Copyright (C) 2005, 2008 Slava Pestov, Doug Coleman.
 ! See http://factorcode.org/license.txt for BSD license.
 USING: accessors arrays calendar combinators generic init
-kernel math namespaces sequences heaps boxes threads debugger
+kernel math namespaces sequences heaps boxes threads
 quotations assocs math.order ;
 IN: alarms
 
index c3ae644b47856cf1b4cd436a306a7ab408da1e6d..ae148e3ac06f6263c204934bc5b21dc30fdd793f 100644 (file)
@@ -204,7 +204,7 @@ M: byte-array byte-length length ;
     dup length [ nip malloc dup ] 2keep memcpy ;
 
 : memory>byte-array ( alien len -- byte-array )
-    [ nip <byte-array> dup ] 2keep memcpy ;
+    [ nip (byte-array) dup ] 2keep memcpy ;
 
 : byte-array>memory ( byte-array base -- )
     swap dup length memcpy ;
diff --git a/basis/alien/prettyprint/prettyprint.factor b/basis/alien/prettyprint/prettyprint.factor
new file mode 100644 (file)
index 0000000..0794ab7
--- /dev/null
@@ -0,0 +1,14 @@
+! Copyright (C) 2008 Slava Pestov.
+! See http://factorcode.org/license.txt for BSD license.
+USING: kernel combinators alien alien.strings alien.syntax
+prettyprint.backend prettyprint.custom prettyprint.sections ;
+IN: alien.prettyprint
+
+M: alien pprint*
+    {
+        { [ dup expired? ] [ drop \ BAD-ALIEN pprint-word ] }
+        { [ dup pinned-c-ptr? not ] [ drop "( displaced alien )" text ] }
+        [ \ ALIEN: [ alien-address pprint* ] pprint-prefix ]
+    } cond ;
+
+M: dll pprint* dll-path dup "DLL\" " "\"" pprint-string ;
index 3dc358336c451c135395a5bda0cdaffafa8e8430..19c29e613e9913a824b05a4de151e1916868904e 100644 (file)
@@ -31,10 +31,6 @@ HELP: string>symbol
 $nl
 "On Windows CE, symbols are represented as UCS2 strings, and on all other platforms they are ASCII strings." } ;
 
-HELP: utf16n
-{ $class-description "The encoding descriptor for UTF-16 without a byte order mark in native endian order. This is useful mostly for FFI calls which take input of strings of the type wchar_t*" }
-{ $see-also "encodings-introduction" } ;
-
 ARTICLE: "c-strings" "C strings"
 "C string types are arrays with shape " { $snippet "{ \"char*\" encoding }" } ", where " { $snippet "encoding" } " is an encoding descriptor. The type " { $snippet "\"char*\"" } " is an alias for " { $snippet "{ \"char*\" utf8 }" } ". See " { $link "encodings-descriptors" } " for information about encoding descriptors."
 $nl
index c1a509041ec5c0e1bdc8db052cf9f750912f9bfd..263453ba1cd7414d5b5c65b246aa60c57b647c1e 100644 (file)
@@ -1,6 +1,6 @@
 USING: alien.strings tools.test kernel libc
 io.encodings.8-bit io.encodings.utf8 io.encodings.utf16
-io.encodings.ascii alien io.encodings.string ;
+io.encodings.utf16n io.encodings.ascii alien io.encodings.string ;
 IN: alien.strings.tests
 
 [ "\u0000ff" ]
index d4826347726ca15867673f3e9f85c120e9373cd7..e9053cd5c1cabca1546e7736508bd7439d83e81e 100644 (file)
@@ -2,8 +2,8 @@
 ! See http://factorcode.org/license.txt for BSD license.
 USING: arrays sequences kernel accessors math alien.accessors
 alien.c-types byte-arrays words io io.encodings
-io.streams.byte-array io.streams.memory io.encodings.utf8
-io.encodings.utf16 system alien strings cpu.architecture fry ;
+io.encodings.utf8 io.streams.byte-array io.streams.memory system
+alien strings cpu.architecture fry vocabs.loader combinators ;
 IN: alien.strings
 
 GENERIC# alien>string 1 ( c-ptr encoding -- string/f )
@@ -88,27 +88,22 @@ M: string-type c-type-getter
 M: string-type c-type-setter
     drop [ set-alien-cell ] ;
 
-! Native-order UTF-16
+HOOK: alien>native-string os ( alien -- string )
 
-SINGLETON: utf16n
-
-: utf16n ( -- descriptor )
-    little-endian? utf16le utf16be ? ; foldable
-
-M: utf16n <decoder> drop utf16n <decoder> ;
-
-M: utf16n <encoder> drop utf16n <encoder> ;
-
-: alien>native-string ( alien -- string )
-    os windows? [ utf16n ] [ utf8 ] if alien>string ;
+HOOK: native-string>alien os ( string -- alien )
 
 : dll-path ( dll -- string )
     path>> alien>native-string ;
 
 : string>symbol ( str -- alien )
-    [ os wince? [ utf16n ] [ utf8 ] if string>alien ]
-    over string? [ call ] [ map ] if ;
+    dup string?
+    [ native-string>alien ]
+    [ [ native-string>alien ] map ] if ;
 
 { "char*" utf8 } "char*" typedef
-{ "char*" utf16n } "wchar_t*" typedef
 "char*" "uchar*" typedef
+
+{
+    { [ os windows? ] [ "alien.strings.windows" require ] }
+    { [ os unix? ] [ "alien.strings.unix" require ] }
+} cond
diff --git a/basis/alien/strings/unix/unix.factor b/basis/alien/strings/unix/unix.factor
new file mode 100644 (file)
index 0000000..a7b1467
--- /dev/null
@@ -0,0 +1,8 @@
+! Copyright (C) 2008 Slava Pestov.
+! See http://factorcode.org/license.txt for BSD license.
+USING: alien.strings io.encodings.utf8 system ;
+IN: alien.strings.unix
+
+M: unix alien>native-string utf8 alien>string ;
+
+M: unix native-string>alien utf8 string>alien ;
diff --git a/basis/alien/strings/windows/windows.factor b/basis/alien/strings/windows/windows.factor
new file mode 100644 (file)
index 0000000..55c6924
--- /dev/null
@@ -0,0 +1,13 @@
+! Copyright (C) 2008 Slava Pestov.
+! See http://factorcode.org/license.txt for BSD license.
+USING: alien.strings alien.c-types io.encodings.utf8
+io.encodings.utf16n system ;
+IN: alien.strings.windows
+
+M: windows alien>native-string utf16n alien>string ;
+
+M: wince native-string>alien utf16n string>alien ;
+
+M: winnt native-string>alien utf8 string>alien ;
+
+{ "char*" utf16n } "wchar_t*" typedef
index d10c97cd3ddd15033bd57dcf066e4c1eba48608f..b0ba10a316176e501699e8487a993e168d50f482 100644 (file)
@@ -3,8 +3,7 @@
 USING: accessors arrays alien alien.c-types alien.structs
 alien.arrays alien.strings kernel math namespaces parser
 sequences words quotations math.parser splitting grouping
-effects prettyprint prettyprint.sections prettyprint.backend
-assocs combinators lexer strings.parser alien.parser ;
+effects assocs combinators lexer strings.parser alien.parser ;
 IN: alien.syntax
 
 : DLL" lexer get skip-blank parse-string dlopen parsed ; parsing
@@ -34,12 +33,3 @@ IN: alien.syntax
     dup length
     [ [ create-in ] dip 1quotation define ] 2each ;
     parsing
-
-M: alien pprint*
-    {
-        { [ dup expired? ] [ drop \ BAD-ALIEN pprint-word ] }
-        { [ dup pinned-c-ptr? not ] [ drop "( displaced alien )" text ] }
-        [ \ ALIEN: [ alien-address pprint* ] pprint-prefix ]
-    } cond ;
-
-M: dll pprint* dll-path dup "DLL\" " "\"" pprint-string ;
index 4cb2032f4f27e8434dc3a8182a0c5efd9501ef79..d407f0b84d08583d2a83a5c1663fa9d2e6fd7925 100644 (file)
@@ -2,7 +2,7 @@
 ! See http://factorcode.org/license.txt for BSD license.
 USING: alien.c-types accessors math alien.accessors kernel
 kernel.private locals sequences sequences.private byte-arrays
-parser prettyprint.backend fry ;
+parser prettyprint.custom fry ;
 IN: bit-arrays
 
 TUPLE: bit-array
@@ -73,11 +73,11 @@ M: bit-array byte-length length 7 + -3 shift ;
 :: integer>bit-array ( n -- bit-array ) 
     n zero? [ 0 <bit-array> ] [
         [let | out [ n log2 1+ <bit-array> ] i! [ 0 ] n'! [ n ] |
-            [ n' zero? not ] [
+            [ n' zero? ] [
                 n' out underlying>> i set-alien-unsigned-1
                 n' -8 shift n'!
                 i 1+ i!
-            ] [ ] while
+            ] [ ] until
             out
         ]
     ] if ;
index 404b26829b332b1f4d39ab8e4ec2713c1457ea79..85bea80b2dbadc239747c2a20fa22d65314a5c4e 100644 (file)
@@ -1,7 +1,7 @@
 ! Copyright (C) 2008 Slava Pestov.\r
 ! See http://factorcode.org/license.txt for BSD license.\r
 USING: arrays kernel kernel.private math sequences\r
-sequences.private growable bit-arrays prettyprint.backend\r
+sequences.private growable bit-arrays prettyprint.custom\r
 parser accessors ;\r
 IN: bit-vectors\r
 \r
diff --git a/basis/bootstrap/bootstrap-error.factor b/basis/bootstrap/bootstrap-error.factor
new file mode 100644 (file)
index 0000000..01eb002
--- /dev/null
@@ -0,0 +1,8 @@
+USING: continuations kernel io debugger vocabs words system namespaces ;
+
+:c
+:error
+"listener" vocab
+[ restarts. vocab-main execute ]
+[ die ] if*
+1 exit
index 9968af4330e6c3b752b4e117ee7a3b6d57a45eb3..f0d9e8e131cb43afff4ad18349f235041890f51a 100644 (file)
@@ -5,17 +5,22 @@ sequences namespaces parser kernel kernel.private classes
 classes.private arrays hashtables vectors classes.tuple sbufs
 hashtables.private sequences.private math classes.tuple.private
 growable namespaces.private assocs words command-line vocabs io
-io.encodings.string prettyprint libc splitting math.parser
+io.encodings.string libc splitting math.parser
 compiler.units math.order compiler.tree.builder
 compiler.tree.optimizer compiler.cfg.optimizer ;
 IN: bootstrap.compiler
 
 ! Don't bring this in when deploying, since it will store a
 ! reference to 'eval' in a global variable
-"deploy-vocab" get [
+"deploy-vocab" get "staging" get or [
     "alien.remote-control" require
 ] unless
 
+"prettyprint" vocab [
+    "stack-checker.errors.prettyprint" require
+    "alien.prettyprint" require
+] when
+
 "cpu." cpu name>> append require
 
 enable-compiler
@@ -86,7 +91,7 @@ nl
 "." write flush
 
 {
-    malloc calloc free memcpy
+    malloc calloc free memcpy
 } compile-uncompiled
 
 "." write flush
diff --git a/basis/bootstrap/finish-bootstrap.factor b/basis/bootstrap/finish-bootstrap.factor
new file mode 100644 (file)
index 0000000..133b64a
--- /dev/null
@@ -0,0 +1,16 @@
+USING: init command-line debugger system continuations
+namespaces eval kernel vocabs.loader io ;
+
+[
+    boot
+    do-init-hooks
+    [
+        (command-line) parse-command-line
+        load-vocab-roots
+        run-user-init
+        "e" get [ eval ] when*
+        ignore-cli-args? not script get and
+        [ run-script ] [ "run" get run ] if*
+        output-stream get [ stream-flush ] when*
+    ] [ print-error 1 exit ] recover
+] set-boot-quot
diff --git a/basis/bootstrap/finish-staging.factor b/basis/bootstrap/finish-staging.factor
new file mode 100644 (file)
index 0000000..a60ce04
--- /dev/null
@@ -0,0 +1,10 @@
+USING: init command-line system namespaces kernel vocabs.loader
+io ;
+
+[
+    boot
+    do-init-hooks
+    (command-line) parse-command-line
+    "run" get run
+    output-stream get [ stream-flush ] when*
+] set-boot-quot
index a293efd33eae01d46d8c9c12c4dfe0d7cce6c10a..347969af0d6698cb65230ddaec7a8aa90efea2bf 100644 (file)
@@ -1,5 +1,7 @@
-USE: vocabs.loader
+USING: vocabs vocabs.loader kernel ;
 
 "math.ratios" require
 "math.floats" require
 "math.complex" require
+
+"prettyprint" vocab [ "math.complex.prettyprint" require ] when
index 4ab36ec94e9361a6efbf23a2a2550416735c9738..fb7292b989caaa7508711711a014c8d935dc27f7 100644 (file)
@@ -2,10 +2,10 @@
 ! See http://factorcode.org/license.txt for BSD license.
 USING: accessors init namespaces words io
 kernel.private math memory continuations kernel io.files
-io.backend system parser vocabs sequences prettyprint
+io.backend system parser vocabs sequences
 vocabs.loader combinators splitting source-files strings
 definitions assocs compiler.errors compiler.units
-math.parser generic sets debugger command-line ;
+math.parser generic sets command-line ;
 IN: bootstrap.stage2
 
 SYMBOL: core-bootstrap-time
@@ -86,25 +86,22 @@ SYMBOL: bootstrap-time
     f error set-global
     f error-continuation set-global
 
+    millis swap - bootstrap-time set-global
+    print-report
+
     "deploy-vocab" get [
         "tools.deploy.shaker" run
     ] [
-        [
-            boot
-            do-init-hooks
-            handle-command-line
-        ] set-boot-quot
-
-        millis swap - bootstrap-time set-global
-        print-report
+        "staging" get [
+            "resource:basis/bootstrap/finish-staging.factor" run-file
+        ] [
+            "resource:basis/bootstrap/finish-bootstrap.factor" run-file
+        ] if
 
         "output-image" get save-image-and-exit
     ] if
 ] [
-    :c
-    dup print-error flush
-    "listener" vocab
-    [ restarts. vocab-main execute ]
-    [ die ] if*
-    1 exit
+    drop
+    load-help? off
+    "resource:basis/bootstrap/bootstrap-error.factor" run-file
 ] recover
index 6c30489bb4cc44db602f044189a0a2b87eaf5605..8b751f8458ca431b53f1e4bf5603614dfee97e50 100644 (file)
@@ -1,7 +1,11 @@
 ! Copyright (C) 2008 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
+USING: vocabs vocabs.loader kernel ;
 IN: bootstrap.threads
 
 USE: io.thread
 USE: threads
-USE: debugger.threads
+
+"debugger" vocab [
+    "debugger.threads" require
+] when
diff --git a/basis/byte-vectors/byte-vectors-docs.factor b/basis/byte-vectors/byte-vectors-docs.factor
new file mode 100644 (file)
index 0000000..3873f73
--- /dev/null
@@ -0,0 +1,37 @@
+USING: arrays byte-arrays help.markup help.syntax kernel\r
+byte-vectors.private combinators ;\r
+IN: byte-vectors\r
+\r
+ARTICLE: "byte-vectors" "Byte vectors"\r
+"A byte vector is a resizable mutable sequence of unsigned bytes. Byte vector words are found in the " { $vocab-link "byte-vectors" } " vocabulary."\r
+$nl\r
+"Byte vectors form a class:"\r
+{ $subsection byte-vector }\r
+{ $subsection byte-vector? }\r
+"Creating byte vectors:"\r
+{ $subsection >byte-vector }\r
+{ $subsection <byte-vector> }\r
+"Literal syntax:"\r
+{ $subsection POSTPONE: BV{ }\r
+"If you don't care about initial capacity, a more elegant way to create a new byte vector is to write:"\r
+{ $code "BV{ } clone" } ;\r
+\r
+ABOUT: "byte-vectors"\r
+\r
+HELP: byte-vector\r
+{ $description "The class of resizable byte vectors. See " { $link "byte-vectors" } " for information." } ;\r
+\r
+HELP: <byte-vector>\r
+{ $values { "n" "a positive integer specifying initial capacity" } { "byte-vector" byte-vector } }\r
+{ $description "Creates a new byte vector that can hold " { $snippet "n" } " bytes before resizing." } ;\r
+\r
+HELP: >byte-vector\r
+{ $values { "seq" "a sequence" } { "byte-vector" byte-vector } }\r
+{ $description "Outputs a freshly-allocated byte vector with the same elements as a given sequence." }\r
+{ $errors "Throws an error if the sequence contains elements other than integers." } ;\r
+\r
+HELP: BV{\r
+{ $syntax "BV{ elements... }" }\r
+{ $values { "elements" "a list of bytes" } }\r
+{ $description "Marks the beginning of a literal byte vector. Literal byte vectors are terminated by " { $link POSTPONE: } } "." } \r
+{ $examples { $code "BV{ 1 2 3 12 }" } } ;\r
diff --git a/basis/byte-vectors/byte-vectors-tests.factor b/basis/byte-vectors/byte-vectors-tests.factor
new file mode 100644 (file)
index 0000000..9a100d9
--- /dev/null
@@ -0,0 +1,17 @@
+IN: byte-vectors.tests\r
+USING: tools.test byte-vectors vectors sequences kernel\r
+prettyprint ;\r
+\r
+[ 0 ] [ 123 <byte-vector> length ] unit-test\r
+\r
+: do-it\r
+    123 [ over push ] each ;\r
+\r
+[ t ] [\r
+    3 <byte-vector> do-it\r
+    3 <vector> do-it sequence=\r
+] unit-test\r
+\r
+[ t ] [ BV{ } byte-vector? ] unit-test\r
+\r
+[ "BV{ }" ] [ BV{ } unparse ] unit-test\r
diff --git a/basis/byte-vectors/byte-vectors.factor b/basis/byte-vectors/byte-vectors.factor
new file mode 100644 (file)
index 0000000..d146017
--- /dev/null
@@ -0,0 +1,51 @@
+! Copyright (C) 2008 Slava Pestov.\r
+! See http://factorcode.org/license.txt for BSD license.\r
+USING: arrays kernel kernel.private math sequences\r
+sequences.private growable byte-arrays accessors parser\r
+prettyprint.custom ;\r
+IN: byte-vectors\r
+\r
+TUPLE: byte-vector\r
+{ underlying byte-array }\r
+{ length array-capacity } ;\r
+\r
+: <byte-vector> ( n -- byte-vector )\r
+    (byte-array) 0 byte-vector boa ; inline\r
+\r
+: >byte-vector ( seq -- byte-vector )\r
+    T{ byte-vector f B{ } 0 } clone-like ;\r
+\r
+M: byte-vector like\r
+    drop dup byte-vector? [\r
+        dup byte-array?\r
+        [ dup length byte-vector boa ] [ >byte-vector ] if\r
+    ] unless ;\r
+\r
+M: byte-vector new-sequence\r
+    drop [ (byte-array) ] [ >fixnum ] bi byte-vector boa ;\r
+\r
+M: byte-vector equal?\r
+    over byte-vector? [ sequence= ] [ 2drop f ] if ;\r
+\r
+M: byte-array like\r
+    #! If we have an byte-array, we're done.\r
+    #! If we have a byte-vector, and it's at full capacity,\r
+    #! we're done. Otherwise, call resize-byte-array, which is a\r
+    #! relatively fast primitive.\r
+    drop dup byte-array? [\r
+        dup byte-vector? [\r
+            [ length ] [ underlying>> ] bi\r
+            2dup length eq?\r
+            [ nip ] [ resize-byte-array ] if\r
+        ] [ >byte-array ] if\r
+    ] unless ;\r
+\r
+M: byte-array new-resizable drop <byte-vector> ;\r
+\r
+: BV{ \ } [ >byte-vector ] parse-literal ; parsing\r
+\r
+M: byte-vector pprint* pprint-object ;\r
+M: byte-vector pprint-delims drop \ BV{ \ } ;\r
+M: byte-vector >pprint-sequence ;\r
+\r
+INSTANCE: byte-vector growable\r
diff --git a/basis/byte-vectors/summary.txt b/basis/byte-vectors/summary.txt
new file mode 100644 (file)
index 0000000..e914ebb
--- /dev/null
@@ -0,0 +1 @@
+Growable byte arrays
diff --git a/basis/byte-vectors/tags.txt b/basis/byte-vectors/tags.txt
new file mode 100644 (file)
index 0000000..42d711b
--- /dev/null
@@ -0,0 +1 @@
+collections
index 8d34e8a3a4ee15dc76dc74d109227bd5ba4644b1..a7c4410aa560516d1239b5fde1eccda750b9d14b 100644 (file)
@@ -1,7 +1,8 @@
-USING: math math.order math.parser math.functions kernel sequences io\r
-accessors arrays io.streams.string splitting\r
-combinators accessors debugger\r
-calendar calendar.format.macros ;\r
+! Copyright (C) 2008 Slava Pestov.\r
+! See http://factorcode.org/license.txt for BSD license.\r
+USING: math math.order math.parser math.functions kernel\r
+sequences io accessors arrays io.streams.string splitting\r
+combinators accessors calendar calendar.format.macros present ;\r
 IN: calendar.format\r
 \r
 : pad-00 ( n -- str ) number>string 2 CHAR: 0 pad-left ;\r
@@ -288,3 +289,5 @@ ERROR: invalid-timestamp-format ;
             ]\r
         } formatted\r
     ] with-string-writer ;\r
+\r
+M: timestamp present timestamp>string ;\r
index 257fd930c46c08818d5d0830b50c4103c98f5d0c..d919b0e31305b366b1b05cb6691429d9cfc74856 100644 (file)
@@ -4,7 +4,7 @@ USING: kernel io io.binary io.files io.streams.byte-array math
 math.functions math.parser namespaces splitting grouping strings
 sequences byte-arrays locals sequences.private
 io.encodings.binary symbols math.bitwise checksums
-checksums.common ;
+checksums.common checksums.stream ;
 IN: checksums.md5
 
 ! See http://www.faqs.org/rfcs/rfc1321.html
@@ -180,7 +180,7 @@ PRIVATE>
 
 SINGLETON: md5
 
-INSTANCE: md5 checksum
+INSTANCE: md5 stream-checksum
 
 M: md5 checksum-stream ( stream -- byte-array )
     drop [ initialize-md5 stream>md5 get-md5 ] with-input-stream ;
index 821cbe2f3afe282195aacc66dbd075cdb8d7e0c5..4bc7a7964a11c6e0d46f7ad8f29701fe45e1945f 100644 (file)
@@ -1,7 +1,8 @@
 ! Copyright (C) 2008 Slava Pestov
 ! See http://factorcode.org/license.txt for BSD license.
 USING: accessors byte-arrays alien.c-types kernel continuations
-destructors sequences io openssl openssl.libcrypto checksums ;
+destructors sequences io openssl openssl.libcrypto checksums
+checksums.stream ;
 IN: checksums.openssl
 
 ERROR: unknown-digest name ;
@@ -12,7 +13,7 @@ TUPLE: openssl-checksum name ;
 
 : openssl-sha1 T{ openssl-checksum f "sha1" } ;
 
-INSTANCE: openssl-checksum checksum
+INSTANCE: openssl-checksum stream-checksum
 
 C: <openssl-checksum> openssl-checksum
 
index 3767af7c5590877907c9882380c8e58352e6edf6..6cdc9270aa7262b8057db66b94007975e359f2f7 100644 (file)
@@ -3,7 +3,8 @@
 USING: arrays combinators kernel io io.encodings.binary io.files
 io.streams.byte-array math.vectors strings sequences namespaces
 make math parser sequences assocs grouping vectors io.binary
-hashtables symbols math.bitwise checksums checksums.common ;
+hashtables symbols math.bitwise checksums checksums.common
+checksums.stream ;
 IN: checksums.sha1
 
 ! Implemented according to RFC 3174.
@@ -113,7 +114,7 @@ SYMBOLS: h0 h1 h2 h3 h4 A B C D E w K ;
 
 SINGLETON: sha1
 
-INSTANCE: sha1 checksum
+INSTANCE: sha1 stream-checksum
 
 M: sha1 checksum-stream ( stream -- sha1 )
     drop [ initialize-sha1 stream>sha1 get-sha1 ] with-input-stream ;
diff --git a/basis/checksums/stream/stream.factor b/basis/checksums/stream/stream.factor
new file mode 100644 (file)
index 0000000..e753467
--- /dev/null
@@ -0,0 +1,12 @@
+! Copyright (C) 2008 Slava Pestov.
+! See http://factorcode.org/license.txt for BSD license.
+USING: io.encodings.binary io.streams.byte-array kernel
+checksums ;
+IN: checksums.stream
+
+MIXIN: stream-checksum
+
+M: stream-checksum checksum-bytes
+    [ binary <byte-reader> ] dip checksum-stream ;
+
+INSTANCE: stream-checksum checksum
index ab12a93a31b86407a5746088bb19c53ee1bbda63..e2c853ea77ed19d0c7fbd48f62f65a497a9c97ab 100644 (file)
@@ -1,9 +1,9 @@
-! Copyright (C) 2006, 2007 Slava Pestov
+! Copyright (C) 2006, 2008 Slava Pestov
 ! See http://factorcode.org/license.txt for BSD license.
 USING: alien alien.syntax io kernel namespaces core-foundation
 core-foundation.run-loop cocoa.messages cocoa cocoa.classes
-cocoa.runtime sequences threads debugger init summary
-kernel.private assocs ;
+cocoa.runtime sequences threads init summary kernel.private
+assocs ;
 IN: cocoa.application
 
 : <NSString> ( str -- alien ) <CFString> -> autorelease ;
index e33217a691cc9d35478c2b824debb7130e5363cd..ebe98a2df1f26bb8c96976b2580620a3f1c94464 100644 (file)
@@ -2,21 +2,17 @@
 ! See http://factorcode.org/license.txt for BSD license.
 USING: accessors alien alien.c-types alien.strings arrays assocs
 continuations combinators compiler compiler.alien kernel math
-namespaces make parser prettyprint prettyprint.sections
-quotations sequences strings words cocoa.runtime io macros
-memoize debugger io.encodings.ascii effects libc libc.private
-parser lexer init core-foundation fry generalizations
-specialized-arrays.direct.alien ;
+namespaces make parser quotations sequences strings words
+cocoa.runtime io macros memoize io.encodings.utf8
+effects libc libc.private parser lexer init core-foundation fry
+generalizations specialized-arrays.direct.alien ;
 IN: cocoa.messages
 
 : make-sender ( method function -- quot )
     [ over first , f , , second , \ alien-invoke , ] [ ] make ;
 
-: sender-stub-name ( method function -- string )
-    [ % "_" % unparse % ] "" make ;
-
 : sender-stub ( method function -- word )
-    [ sender-stub-name f <word> dup ] 2keep
+    [ "( sender-stub )" f <word> dup ] 2dip
     over first large-struct? [ "_stret" append ] when
     make-sender define ;
 
@@ -78,12 +74,8 @@ MACRO: (send) ( selector super? -- quot )
 
 : send ( receiver args... selector -- return... ) f (send) ; inline
 
-\ send soft "break-after" set-word-prop
-
 : super-send ( receiver args... selector -- return... ) t (send) ; inline
 
-\ super-send soft "break-after" set-word-prop
-
 ! Runtime introspection
 SYMBOL: class-init-hooks
 
@@ -188,7 +180,7 @@ assoc-union alien>objc-types set-global
 
 : method-arg-type ( method i -- type )
     method_copyArgumentType
-    [ ascii alien>string parse-objc-type ] keep
+    [ utf8 alien>string parse-objc-type ] keep
     (free) ;
 
 : method-arg-types ( method -- args )
@@ -197,7 +189,7 @@ assoc-union alien>objc-types set-global
 
 : method-return-type ( method -- ctype )
     method_copyReturnType
-    [ ascii alien>string parse-objc-type ] keep
+    [ utf8 alien>string parse-objc-type ] keep
     (free) ;
 
 : register-objc-method ( method -- )
@@ -216,17 +208,6 @@ assoc-union alien>objc-types set-global
 : register-objc-methods ( class -- )
     [ register-objc-method ] each-method-in-class ;
 
-: method. ( method -- )
-    {
-        [ method_getName sel_getName ]
-        [ method-return-type ]
-        [ method-arg-types ]
-        [ method_getImplementation ]
-    } cleave 4array . ;
-
-: methods. ( class -- )
-    [ method. ] each-method-in-class ;
-
 : class-exists? ( string -- class ) objc_getClass >boolean ;
 
 : define-objc-class-word ( quot name -- )
@@ -238,11 +219,8 @@ assoc-union alien>objc-types set-global
 
 : import-objc-class ( name quot -- )
     over define-objc-class-word
-    '[
-        _
-        [ objc-class register-objc-methods ]
-        [ objc-meta-class register-objc-methods ] bi
-    ] try ;
+    [ objc-class register-objc-methods ]
+    [ objc-meta-class register-objc-methods ] bi ;
 
 : root-class ( class -- root )
     dup class_getSuperclass [ root-class ] [ ] ?if ;
index b49d55a30b51a3ef884648e4f88a068dd4c53be7..be533641854870558189b44da174219ebd5b8b77 100644 (file)
@@ -3,12 +3,12 @@
 USING: alien alien.c-types alien.strings arrays assocs
 combinators compiler hashtables kernel libc math namespaces
 parser sequences words cocoa.messages cocoa.runtime locals
-compiler.units io.encodings.ascii continuations make fry ;
+compiler.units io.encodings.utf8 continuations make fry ;
 IN: cocoa.subclassing
 
 : init-method ( method -- sel imp types )
     first3 swap
-    [ sel_registerName ] [ execute ] [ ascii string>alien ]
+    [ sel_registerName ] [ execute ] [ utf8 string>alien ]
     tri* ;
 
 : throw-if-false ( obj what -- )
index 1b58053b64d2af681760f542902957fb147bd51f..7d5a041951a6320fbb2872afb9b2410e20e5c38e 100644 (file)
@@ -1,8 +1,8 @@
 ! Copyright (C) 2003, 2008 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: init continuations debugger hashtables io
-io.encodings.utf8 io.files kernel kernel.private namespaces
-parser sequences strings system splitting eval vocabs.loader ;
+USING: init continuations hashtables io io.encodings.utf8
+io.files kernel kernel.private namespaces parser sequences
+strings system splitting vocabs.loader ;
 IN: command-line
 
 SYMBOL: script
@@ -31,8 +31,6 @@ SYMBOL: command-line
         ] [ drop ] if
     ] when ;
 
-<PRIVATE
-
 : var-param ( name value -- ) swap set-global ;
 
 : bool-param ( name -- ) "no-" ?head not var-param ;
@@ -43,8 +41,6 @@ SYMBOL: command-line
 : run-script ( file -- )
     t "quiet" set-global run-file ;
 
-PRIVATE>
-
 : parse-command-line ( args -- )
     [ command-line off script off ] [
         unclip "-" ?head
@@ -76,15 +72,4 @@ SYMBOL: main-vocab-hook
 
 : script-mode ( -- ) ;
 
-: handle-command-line ( -- )
-    [
-        (command-line) parse-command-line
-        load-vocab-roots
-        run-user-init
-        "e" get [ eval ] when*
-        ignore-cli-args? not script get and
-        [ run-script ] [ "run" get run ] if*
-        output-stream get [ stream-flush ] when*
-    ] [ print-error 1 exit ] recover ;
-
 [ default-cli-args ] "command-line" add-init-hook
index c7094c8c360e2d2b8100165a0858ca5ed88f1f34..d8bad5ec410a61f511759732f7cde7ab6a9a48a6 100644 (file)
@@ -1,6 +1,6 @@
 USING: compiler.cfg.instructions compiler.cfg.registers
-compiler.cfg.alias-analysis cpu.architecture tools.test
-kernel ;
+compiler.cfg.alias-analysis compiler.cfg.debugger
+cpu.architecture tools.test kernel ;
 IN: compiler.cfg.alias-analysis.tests
 
 [ ] [
index b9c3af521543a22a93cd3271dd727c6e8f83fc43..ee7d8d2a434688986b367ea668f1f8872cdfdf06 100644 (file)
@@ -1,5 +1,6 @@
 USING: compiler.cfg.dead-code compiler.cfg.instructions
-compiler.cfg.registers cpu.architecture tools.test ;
+compiler.cfg.registers compiler.cfg.debugger
+cpu.architecture tools.test ;
 IN: compiler.cfg.dead-code.tests
 
 [ { } ] [
index 7b1b9100c407df35eaa4eb86489038c70632d94d..ba58e60a4ad0c15f8df8f12f3ecc0cbd6f69d88b 100644 (file)
@@ -2,10 +2,12 @@
 ! See http://factorcode.org/license.txt for BSD license.
 USING: kernel words sequences quotations namespaces io
 classes.tuple accessors prettyprint prettyprint.config
-compiler.tree.builder compiler.tree.optimizer
+prettyprint.backend prettyprint.custom prettyprint.sections
+parser compiler.tree.builder compiler.tree.optimizer
 compiler.cfg.builder compiler.cfg.linearization
-compiler.cfg.stack-frame compiler.cfg.linear-scan
-compiler.cfg.two-operand compiler.cfg.optimizer ;
+compiler.cfg.registers compiler.cfg.stack-frame
+compiler.cfg.linear-scan compiler.cfg.two-operand
+compiler.cfg.optimizer ;
 IN: compiler.cfg.debugger
 
 GENERIC: test-cfg ( quot -- cfgs )
@@ -40,3 +42,15 @@ SYMBOL: allocate-registers?
         instructions>> [ insn. ] each
         nl
     ] each ;
+
+! Prettyprinting
+M: vreg pprint*
+    <block
+    \ V pprint-word [ reg-class>> pprint* ] [ n>> pprint* ] bi
+    block> ;
+
+: pprint-loc ( loc word -- ) <block pprint-word n>> pprint* block> ;
+
+M: ds-loc pprint* \ D pprint-loc ;
+
+M: rs-loc pprint* \ R pprint-loc ;
index ceac5e960cfb20aa82372fb43fb8cedd9b8c4cc5..3a4c702bc563535758057098911c9a15c41c10eb 100644 (file)
@@ -54,15 +54,19 @@ IN: compiler.cfg.intrinsics.allot
 
 : bytes>cells ( m -- n ) cell align cell /i ;
 
-:: emit-<byte-array> ( node -- )
-    [let | len [ node node-input-infos first literal>> ] |
-        len expand-<byte-array>? [
-            [let | elt [ 0 ^^load-literal ]
-                   reg [ len ^^allot-byte-array ] |
-                ds-drop
-                len reg store-length
-                elt reg len bytes>cells store-initial-element
-                reg ds-push
-            ]
-        ] [ node emit-primitive ] if
-    ] ;
+: emit-allot-byte-array ( len -- dst )
+    ds-drop
+    dup ^^allot-byte-array
+    [ store-length ] [ ds-push ] [ ] tri ;
+
+: emit-(byte-array) ( node -- )
+    dup node-input-infos first literal>> dup expand-<byte-array>?
+    [ nip emit-allot-byte-array drop ] [ drop emit-primitive ] if ;
+
+: emit-<byte-array> ( node -- )
+    dup node-input-infos first literal>> dup expand-<byte-array>? [
+        nip
+        [ 0 ^^load-literal ] dip
+        [ emit-allot-byte-array ] keep
+        bytes>cells store-initial-element
+    ] [ drop emit-primitive ] if ;
index 6656cd11f7646047e95e11317dfb6a7779a501c3..5f753308655f96a8aa1e108057b89fe8a90b695b 100644 (file)
@@ -52,6 +52,7 @@ IN: compiler.cfg.intrinsics
     classes.tuple.private:<tuple-boa>
     arrays:<array>
     byte-arrays:<byte-array>
+    byte-arrays:(byte-array)
     math.private:<complex>
     math.private:<ratio>
     kernel:<wrapper>
@@ -139,6 +140,7 @@ IN: compiler.cfg.intrinsics
         { \ classes.tuple.private:<tuple-boa> [ emit-<tuple-boa> iterate-next ] }
         { \ arrays:<array> [ emit-<array> iterate-next ] }
         { \ byte-arrays:<byte-array> [ emit-<byte-array> iterate-next ] }
+        { \ byte-arrays:(byte-array) [ emit-(byte-array) iterate-next ] }
         { \ math.private:<complex> [ emit-simple-allot iterate-next ] }
         { \ math.private:<ratio> [ emit-simple-allot iterate-next ] }
         { \ kernel:<wrapper> [ emit-simple-allot iterate-next ] }
index 21572ec6153efcc9d033645781776aa680d6ac98..2b9d3df6f674896fb4e42a3a7759fb1e5eb17f9e 100644 (file)
@@ -1,7 +1,6 @@
 ! Copyright (C) 2008 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: accessors namespaces kernel arrays
-parser prettyprint.backend prettyprint.sections ;
+USING: accessors namespaces kernel arrays parser ;
 IN: compiler.cfg.registers
 
 ! Virtual registers, used by CFG and machine IRs
@@ -18,20 +17,6 @@ C: <ds-loc> ds-loc
 TUPLE: rs-loc < loc ;
 C: <rs-loc> rs-loc
 
-! Prettyprinting
 : V scan-word scan-word vreg boa parsed ; parsing
-
-M: vreg pprint*
-    <block
-    \ V pprint-word [ reg-class>> pprint* ] [ n>> pprint* ] bi
-    block> ;
-
-: pprint-loc ( loc word -- ) <block pprint-word n>> pprint* block> ;
-
 : D scan-word <ds-loc> parsed ; parsing
-
-M: ds-loc pprint* \ D pprint-loc ;
-
 : R scan-word <rs-loc> parsed ; parsing
-
-M: rs-loc pprint* \ R pprint-loc ;
index 8adeaa21f4ddd4485942102614a0d76542e21b9d..641ccceb5daee5f43514caaec892a28e9e45174b 100644 (file)
@@ -1,7 +1,8 @@
 IN: compiler.cfg.value-numbering.tests
 USING: compiler.cfg.value-numbering compiler.cfg.instructions
-compiler.cfg.registers cpu.architecture tools.test kernel math
-combinators.short-circuit accessors sequences ;
+compiler.cfg.registers compiler.cfg.debugger cpu.architecture
+tools.test kernel math combinators.short-circuit accessors
+sequences ;
 
 : trim-temps ( insns -- insns )
     [
index 7a4b1c488faa4f7ebce1d2387f0e889f5d214537..73748dbc37c33fa4d89f7f488b7e176bdbc6abe4 100644 (file)
@@ -1,5 +1,6 @@
 USING: compiler.cfg.write-barrier compiler.cfg.instructions
-compiler.cfg.registers cpu.architecture arrays tools.test ;
+compiler.cfg.registers compiler.cfg.debugger cpu.architecture
+arrays tools.test ;
 IN: compiler.cfg.write-barrier.tests
 
 [
index a56ae04a7b87de4248285afa0c7e426fe30f5bd8..e0f391deb5f925740c9f410253bb638701f32cd2 100755 (executable)
@@ -1,10 +1,10 @@
 ! Copyright (C) 2007, 2008 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: arrays byte-arrays generic assocs hashtables io.binary
-kernel kernel.private math namespaces make sequences words
-quotations strings alien.accessors alien.strings layouts system
-combinators math.bitwise words.private math.order accessors
-growable cpu.architecture compiler.constants ;
+USING: arrays byte-arrays byte-vectors generic assocs hashtables
+io.binary kernel kernel.private math namespaces make sequences
+words quotations strings alien.accessors alien.strings layouts
+system combinators math.bitwise words.private math.order
+accessors growable cpu.architecture compiler.constants ;
 IN: compiler.codegen.fixup
 
 GENERIC: fixup* ( obj -- )
index e5cbd888d94f0ddc93127ce810380103882a2255..0d24daef7103220b2ced01f573a0f42fb2e52333 100644 (file)
@@ -1,15 +1,14 @@
 ! Copyright (C) 2004, 2008 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: accessors kernel namespaces arrays sequences io debugger
-words fry continuations vocabs assocs dlists definitions
-math threads graphs generic combinators deques search-deques
-prettyprint io stack-checker stack-checker.state
-stack-checker.inlining compiler.errors compiler.units
-compiler.tree.builder compiler.tree.optimizer
-compiler.cfg.builder compiler.cfg.optimizer
-compiler.cfg.linearization compiler.cfg.two-operand
-compiler.cfg.linear-scan compiler.cfg.stack-frame
-compiler.codegen ;
+USING: accessors kernel namespaces arrays sequences io
+words fry continuations vocabs assocs dlists definitions math
+threads graphs generic combinators deques search-deques io
+stack-checker stack-checker.state stack-checker.inlining
+compiler.errors compiler.units compiler.tree.builder
+compiler.tree.optimizer compiler.cfg.builder
+compiler.cfg.optimizer compiler.cfg.linearization
+compiler.cfg.two-operand compiler.cfg.linear-scan
+compiler.cfg.stack-frame compiler.codegen ;
 IN: compiler
 
 SYMBOL: compile-queue
@@ -45,7 +44,7 @@ SYMBOL: +failed+
     2bi ;
 
 : start ( word -- )
-    "trace-compilation" get [ dup . flush ] when
+    "trace-compilation" get [ dup name>> print flush ] when
     H{ } clone dependencies set
     H{ } clone generic-dependencies set
     f swap compiler-error ;
index 02dc42f058072de723d24693dfcc4ef146138c24..71830d07e7e16b268fde37a767e5dc2ef10a03bc 100644 (file)
@@ -22,14 +22,11 @@ M: #call-recursive compute-live-values*
     [ out-d>> ] [ label>> return>> in-d>> ] bi look-at-mapping ;
 
 :: drop-dead-inputs ( inputs outputs -- #shuffle )
-    [let* | live-inputs [ inputs filter-live ]
-            new-live-inputs [ outputs inputs filter-corresponding make-values ] |
-        live-inputs
-        new-live-inputs
-        outputs
-        inputs
-        drop-values
-    ] ;
+    inputs filter-live
+    outputs inputs filter-corresponding make-values
+    outputs
+    inputs
+    drop-values ;
 
 M: #enter-recursive remove-dead-code*
     [ filter-live ] change-out-d ;
@@ -79,12 +76,12 @@ M: #call-recursive remove-dead-code*
         bi
     ] ;
 
-M:: #recursive remove-dead-code* ( node -- nodes )
-    [let* | drop-inputs [ node drop-recursive-inputs ]
-            drop-outputs [ node drop-recursive-outputs ] |
-         node [ (remove-dead-code) ] change-child drop
-         node label>> [ filter-live ] change-enter-out drop
-         { drop-inputs node drop-outputs }
-    ] ;
+M: #recursive remove-dead-code* ( node -- nodes )
+    [ drop-recursive-inputs ]
+    [
+        [ (remove-dead-code) ] change-child
+        dup label>> [ filter-live ] change-enter-out drop
+    ]
+    [ drop-recursive-outputs ] tri 3array ;
 
 M: #return-recursive remove-dead-code* ;
index 8d764a28333c81d7092163e8f51e4c7b9fe33132..e75e7f60469af5bf79589e34d418917a04ee4b71 100644 (file)
@@ -2,8 +2,9 @@
 ! See http://factorcode.org/license.txt for BSD license.
 USING: kernel assocs match fry accessors namespaces make effects
 sequences sequences.private quotations generic macros arrays
-prettyprint prettyprint.backend prettyprint.sections math words
-combinators combinators.short-circuit io sorting hints qualified
+prettyprint prettyprint.backend prettyprint.custom
+prettyprint.sections math words combinators
+combinators.short-circuit io sorting hints qualified
 compiler.tree
 compiler.tree.recursive
 compiler.tree.normalization
@@ -150,14 +151,14 @@ SYMBOL: node-count
         H{ } clone intrinsics-called set
 
         0 swap [
-            >r 1+ r>
+            [ 1+ ] dip
             dup #call? [
                 word>> {
                     { [ dup "intrinsics" word-prop over "if-intrinsics" word-prop or ] [ intrinsics-called ] }
                     { [ dup generic? ] [ generics-called ] }
                     { [ dup method-body? ] [ methods-called ] }
                     [ words-called ]
-                } cond 1 -rot get at+
+                } cond inc-at
             ] [ drop ] if
         ] each-node
         node-count set
index fcc3b01dc046cdf818ac4c4df52f1b3ddc166962..bd6d65744243b5e8800770656bd3aeb8f3fbace2 100644 (file)
@@ -48,9 +48,11 @@ M: callable splicing-nodes
     ] [ 2drop f >>method f >>body f >>class drop f ] if ;
 
 : inlining-standard-method ( #call word -- class/f method/f )
-    [ in-d>> <reversed> ] [ [ dispatch# ] keep ] bi*
-    [ swap nth value-info class>> dup ] dip
-    specific-method ;
+    dup "methods" word-prop assoc-empty? [ 2drop f f ] [
+        [ in-d>> <reversed> ] [ [ dispatch# ] keep ] bi*
+        [ swap nth value-info class>> dup ] dip
+        specific-method
+    ] if ;
 
 : inline-standard-method ( #call word -- ? )
     dupd inlining-standard-method eliminate-dispatch ;
@@ -150,7 +152,7 @@ DEFER: (flat-length)
 SYMBOL: history
 
 : remember-inlining ( word -- )
-    [ [ 1 ] dip inlining-count get at+ ]
+    [ inlining-count get inc-at ]
     [ history [ swap suffix ] change ]
     bi ;
 
index 83e71c336314c6201cbb2a5526ba1d633f63857b..8192b1c5209b3ad3b1f4d3e3990d69f112792919 100644 (file)
@@ -14,12 +14,13 @@ IN: compiler.tree.propagation.slots
 UNION: fixed-length-sequence array byte-array string ;
 
 : sequence-constructor? ( word -- ? )
-    { <array> <byte-array> <string> } memq? ;
+    { <array> <byte-array> (byte-array) <string> } memq? ;
 
 : constructor-output-class ( word -- class )
     {
         { <array> array }
         { <byte-array> byte-array }
+        { (byte-array) byte-array }
         { <string> string }
     } at ;
 
index 4608faf79ba572231422a5864a05f92cb3d99562..932605fc36df3c878eacd478a83f8c44dde336b1 100644 (file)
@@ -22,7 +22,7 @@ PRIVATE>
     ] (parallel-each) ; inline\r
 \r
 : parallel-filter ( seq quot -- newseq )\r
-    over [ pusher [ each ] dip ] dip like ; inline\r
+    over [ pusher [ parallel-each ] dip ] dip like ; inline\r
 \r
 <PRIVATE\r
 \r
diff --git a/basis/core-foundation/core-foundation-tests.factor b/basis/core-foundation/core-foundation-tests.factor
new file mode 100644 (file)
index 0000000..c1d6788
--- /dev/null
@@ -0,0 +1,9 @@
+! Copyright (C) 2008 Slava Pestov.
+! See http://factorcode.org/license.txt for BSD license.
+USING: core-foundation tools.test kernel ;
+IN: core-foundation
+
+[ ] [ "Hello" <CFString> CFRelease ] unit-test
+[ "Hello" ] [ "Hello" <CFString> [ CF>string ] [ CFRelease ] bi ] unit-test
+[ "Hello\u003456" ] [ "Hello\u003456" <CFString> [ CF>string ] [ CFRelease ] bi ] unit-test
+[ "Hello\u013456" ] [ "Hello\u013456" <CFString> [ CF>string ] [ CFRelease ] bi ] unit-test
index d63a66dbe7f0b9dca903b1bad80fa9819d1d20ec..48d7b7e4832b5243bdf580ce59965eff78bf6d21 100644 (file)
@@ -1,7 +1,8 @@
 ! Copyright (C) 2006, 2008 Slava Pestov
 ! See http://factorcode.org/license.txt for BSD license.
 USING: alien alien.c-types alien.strings alien.syntax kernel
-math sequences io.encodings.utf16 destructors accessors combinators ;
+math sequences io.encodings.utf8 destructors accessors
+combinators byte-arrays ;
 IN: core-foundation
 
 TYPEDEF: void* CFAllocatorRef
@@ -69,12 +70,53 @@ FUNCTION: CFURLRef CFURLCreateWithString ( CFAllocatorRef allocator, CFStringRef
 
 FUNCTION: CFURLRef CFURLCopyFileSystemPath ( CFURLRef url, int pathStyle ) ;
 
-FUNCTION: CFStringRef CFStringCreateWithCharacters ( CFAllocatorRef allocator, wchar_t* cStr, CFIndex numChars ) ;
+TYPEDEF: int CFStringEncoding
+: kCFStringEncodingMacRoman HEX: 0 ;
+: kCFStringEncodingWindowsLatin1 HEX: 0500 ;
+: kCFStringEncodingISOLatin1 HEX: 0201 ;
+: kCFStringEncodingNextStepLatin HEX: 0B01 ;
+: kCFStringEncodingASCII HEX: 0600 ;
+: kCFStringEncodingUnicode HEX: 0100 ;
+: kCFStringEncodingUTF8 HEX: 08000100 ;
+: kCFStringEncodingNonLossyASCII HEX: 0BFF ;
+: kCFStringEncodingUTF16 HEX: 0100 ;
+: kCFStringEncodingUTF16BE HEX: 10000100 ;
+: kCFStringEncodingUTF16LE HEX: 14000100 ;
+: kCFStringEncodingUTF32 HEX: 0c000100 ;
+: kCFStringEncodingUTF32BE HEX: 18000100 ;
+: kCFStringEncodingUTF32LE HEX: 1c000100 ;
+
+FUNCTION: CFStringRef CFStringCreateFromExternalRepresentation (
+   CFAllocatorRef alloc,
+   CFDataRef data,
+   CFStringEncoding encoding
+) ;
+
+FUNCTION: CFStringRef CFStringCreateWithBytes (
+   CFAllocatorRef alloc,
+   UInt8* bytes,
+   CFIndex numBytes,
+   CFStringEncoding encoding,
+   Boolean isExternalRepresentation
+) ;
 
 FUNCTION: CFIndex CFStringGetLength ( CFStringRef theString ) ;
 
 FUNCTION: void CFStringGetCharacters ( void* theString, CFIndex start, CFIndex length, void* buffer ) ;
 
+FUNCTION: Boolean CFStringGetCString (
+   CFStringRef theString,
+   char* buffer,
+   CFIndex bufferSize,
+   CFStringEncoding encoding
+) ;
+
+FUNCTION: CFStringRef CFStringCreateWithCString (
+   CFAllocatorRef alloc,
+   char* cStr,
+   CFStringEncoding encoding
+) ;
+
 FUNCTION: CFNumberRef CFNumberCreate ( CFAllocatorRef allocator, CFNumberType theType, void* valuePtr ) ;
 
 FUNCTION: CFDataRef CFDataCreate ( CFAllocatorRef allocator, uchar* bytes, CFIndex length ) ;
@@ -97,12 +139,16 @@ FUNCTION: CFTypeID CFGetTypeID ( CFTypeRef cf ) ;
     [ [ dupd ] dip CFArraySetValueAtIndex ] 2each ;
 
 : <CFString> ( string -- alien )
-    f swap dup length CFStringCreateWithCharacters ;
+    f swap utf8 string>alien kCFStringEncodingUTF8 CFStringCreateWithCString
+    [ "CFStringCreateWithCString failed" throw ] unless* ;
 
 : CF>string ( alien -- string )
-    dup CFStringGetLength 1+ "ushort" <c-array> [
-        [ 0 over CFStringGetLength ] dip CFStringGetCharacters
-    ] keep utf16n alien>string ;
+    dup CFStringGetLength 4 * 1 + <byte-array> [
+        dup length
+        kCFStringEncodingUTF8
+        CFStringGetCString
+        [ "CFStringGetCString failed" throw ] unless
+    ] keep utf8 alien>string ;
 
 : CF>string-array ( alien -- seq )
     CF>array [ CF>string ] map ;
index c334297122941f7a277a2778e1345a4992e8c0e6..39f4101301352e85226bfe93037672459bf6ebf4 100644 (file)
@@ -1,7 +1,6 @@
 ! Copyright (C) 2008 Slava Pestov
 ! See http://factorcode.org/license.txt for BSD license.
-USING: alien.syntax kernel threads init namespaces alien
-core-foundation calendar ;
+USING: alien alien.syntax core-foundation kernel namespaces ;
 IN: core-foundation.run-loop
 
 : kCFRunLoopRunFinished 1 ; inline
@@ -40,11 +39,3 @@ FUNCTION: void CFRunLoopAddSource (
         "kCFRunLoopDefaultMode" <CFString>
         dup \ CFRunLoopDefaultMode set-global
     ] when ;
-
-: run-loop-thread ( -- )
-    CFRunLoopDefaultMode 0 f CFRunLoopRunInMode
-    kCFRunLoopRunHandledSource = [ 1 seconds sleep ] unless
-    run-loop-thread ;
-
-: start-run-loop-thread ( -- )
-    [ run-loop-thread t ] "CFRunLoop dispatcher" spawn-server drop ;
index 326226ec0e3bba002106155cade28598bd242184..aeeff312cb826e567529cda5cf5f669e4219faea 100644 (file)
@@ -1,8 +1,16 @@
 ! Copyright (C) 2008 Slava Pestov
 ! See http://factorcode.org/license.txt for BSD license.
-USING: init core-foundation.run-loop ;
+USING: calendar core-foundation.run-loop init kernel threads ;
 IN: core-foundation.run-loop.thread
 
 ! Load this vocabulary if you need a run loop running.
 
+: run-loop-thread ( -- )
+    CFRunLoopDefaultMode 0 f CFRunLoopRunInMode
+    kCFRunLoopRunHandledSource = [ 1 seconds sleep ] unless
+    run-loop-thread ;
+
+: start-run-loop-thread ( -- )
+    [ run-loop-thread t ] "CFRunLoop dispatcher" spawn-server drop ;
+
 [ start-run-loop-thread ] "core-foundation.run-loop.thread" add-init-hook
index 04bdcca68b8498f392623d5212b33b8182cdaf78..698c3a17668f0e815555593530e6790cbb0fc2a1 100644 (file)
@@ -10,19 +10,19 @@ IN: bootstrap.x86
 : shift-arg ( -- reg ) ECX ;
 : div-arg ( -- reg ) EAX ;
 : mod-arg ( -- reg ) EDX ;
-: arg0 ( -- reg ) EAX ;
-: arg1 ( -- reg ) EDX ;
-: arg2 ( -- reg ) ECX ;
-: temp-reg ( -- reg ) EBX ;
+: temp0 ( -- reg ) EAX ;
+: temp1 ( -- reg ) EDX ;
+: temp2 ( -- reg ) ECX ;
+: temp3 ( -- reg ) EBX ;
 : stack-reg ( -- reg ) ESP ;
 : ds-reg ( -- reg ) ESI ;
 : rs-reg ( -- reg ) EDI ;
-: fixnum>slot@ ( -- ) arg0 1 SAR ;
+: fixnum>slot@ ( -- ) temp0 1 SAR ;
 : rex-length ( -- n ) 0 ;
 
 [
-    arg0 0 [] MOV                              ! load stack_chain
-    arg0 [] stack-reg MOV                      ! save stack pointer
+    temp0 0 [] MOV                              ! load stack_chain
+    temp0 [] stack-reg MOV                      ! save stack pointer
 ] rc-absolute-cell rt-stack-chain 2 jit-save-stack jit-define
 
 [
index 83a72d6dd308ade8135c68a27ce0f883033a6721..efa3de3065a681933ab059358f3903f59d5075e7 100644 (file)
@@ -9,7 +9,10 @@ IN: bootstrap.x86
 : shift-arg ( -- reg ) RCX ;
 : div-arg ( -- reg ) RAX ;
 : mod-arg ( -- reg ) RDX ;
-: temp-reg ( -- reg ) RBX ;
+: temp0 ( -- reg ) RDI ;
+: temp1 ( -- reg ) RSI ;
+: temp2 ( -- reg ) RDX ;
+: temp3 ( -- reg ) RBX ;
 : stack-reg ( -- reg ) RSP ;
 : ds-reg ( -- reg ) R14 ;
 : rs-reg ( -- reg ) R15 ;
@@ -17,14 +20,14 @@ IN: bootstrap.x86
 : rex-length ( -- n ) 1 ;
 
 [
-    arg0 0 MOV                                 ! load stack_chain
-    arg0 arg0 [] MOV
-    arg0 [] stack-reg MOV                      ! save stack pointer
+    temp0 0 MOV                                 ! load stack_chain
+    temp0 temp0 [] MOV
+    temp0 [] stack-reg MOV                      ! save stack pointer
 ] rc-absolute-cell rt-stack-chain 1 rex-length + jit-save-stack jit-define
 
 [
-    arg1 0 MOV                                 ! load XT
-    arg1 JMP                                   ! go
+    temp1 0 MOV                                 ! load XT
+    temp1 JMP                                   ! go
 ] rc-absolute-cell rt-primitive 1 rex-length + jit-primitive jit-define
 
 << "resource:basis/cpu/x86/bootstrap.factor" parse-file parsed >>
index f0ca56da1472bda5f28b42bf614c30b7cf3fe221..a21c4534d25e153ee03382a784ac824f5b3d7fb3 100644 (file)
@@ -5,9 +5,6 @@ cpu.x86.assembler layouts vocabs parser ;
 IN: bootstrap.x86
 
 : stack-frame-size ( -- n ) 4 bootstrap-cells ;
-: arg0 ( -- reg ) RDI ;
-: arg1 ( -- reg ) RSI ;
-: arg2 ( -- reg ) RDX ;
 
 << "resource:basis/cpu/x86/64/bootstrap.factor" parse-file parsed >>
 call
index 459945d82e4d9715c6ede20b493dd9b6165c8aff..709f138463c6bbb1aa5cf008853520171e78ba00 100644 (file)
@@ -5,9 +5,6 @@ cpu.x86.assembler layouts vocabs parser ;
 IN: bootstrap.x86
 
 : stack-frame-size ( -- n ) 8 bootstrap-cells ;
-: arg0 ( -- reg ) RCX ;
-: arg1 ( -- reg ) RDX ;
-: arg2 ( -- reg ) R8 ;
 
 << "resource:basis/cpu/x86/64/bootstrap.factor" parse-file parsed >>
 call
index 2bea8872959c25e721db740bcd4de08c99878dfd..3a98d474160caefe4b475db8c477953bb2c41524 100644 (file)
@@ -346,7 +346,7 @@ M: label JUMPcc (JUMPcc) label-fixup ;
 : LEAVE ( -- ) HEX: c9 , ;
 
 : RET ( n -- )
-    dup zero? [ drop HEX: c3 , ] [ HEX: C2 , 2, ] if ;
+    dup zero? [ drop HEX: c3 , ] [ HEX: c2 , 2, ] if ;
 
 ! Arithmetic
 
index 597a2c9d319963f2c20730686a5f62c0f1a9a5de..3451da78e1dda774e1f52ad894382d17d4396158 100644 (file)
@@ -12,28 +12,35 @@ big-endian off
 
 [
     ! Load word
-    temp-reg 0 MOV
+    temp0 0 MOV
     ! Bump profiling counter
-    temp-reg profile-count-offset [+] 1 tag-fixnum ADD
+    temp0 profile-count-offset [+] 1 tag-fixnum ADD
     ! Load word->code
-    temp-reg temp-reg word-code-offset [+] MOV
+    temp0 temp0 word-code-offset [+] MOV
     ! Compute word XT
-    temp-reg compiled-header-size ADD
+    temp0 compiled-header-size ADD
     ! Jump to XT
-    temp-reg JMP
+    temp0 JMP
 ] rc-absolute-cell rt-immediate 1 rex-length + jit-profiling jit-define
 
 [
-    temp-reg 0 MOV                             ! load XT
-    stack-frame-size PUSH                      ! save stack frame size
-    temp-reg PUSH                              ! push XT
-    stack-reg stack-frame-size 3 bootstrap-cells - SUB   ! alignment
+    ! load XT
+    temp0 0 MOV
+    ! save stack frame size
+    stack-frame-size PUSH
+    ! push XT
+    temp0 PUSH
+    ! alignment
+    stack-reg stack-frame-size 3 bootstrap-cells - SUB
 ] rc-absolute-cell rt-label 1 rex-length + jit-prolog jit-define
 
 [
-    arg0 0 MOV                                 ! load literal
-    ds-reg bootstrap-cell ADD                  ! increment datastack pointer
-    ds-reg [] arg0 MOV                         ! store literal on datastack
+    ! load literal
+    temp0 0 MOV
+    ! increment datastack pointer
+    ds-reg bootstrap-cell ADD
+    ! store literal on datastack
+    ds-reg [] temp0 MOV
 ] rc-absolute-cell rt-immediate 1 rex-length + jit-push-immediate jit-define
 
 [
@@ -45,73 +52,85 @@ big-endian off
 ] rc-relative rt-xt 1 jit-word-call jit-define
 
 [
-    arg0 ds-reg [] MOV                         ! load boolean
-    ds-reg bootstrap-cell SUB                  ! pop boolean
-    arg0 \ f tag-number CMP                    ! compare boolean with f
-    f JNE                                      ! jump to true branch if not equal
+    ! load boolean
+    temp0 ds-reg [] MOV
+    ! pop boolean
+    ds-reg bootstrap-cell SUB
+    ! compare boolean with f
+    temp0 \ f tag-number CMP
+    ! jump to true branch if not equal
+    f JNE
 ] rc-relative rt-xt 10 rex-length 3 * + jit-if-1 jit-define
 
 [
-    f JMP                                      ! jump to false branch if equal
+    ! jump to false branch if equal
+    f JMP
 ] rc-relative rt-xt 1 jit-if-2 jit-define
 
 [
-    arg1 0 MOV                                 ! load dispatch table
-    arg0 ds-reg [] MOV                         ! load index
-    fixnum>slot@                               ! turn it into an array offset
-    ds-reg bootstrap-cell SUB                  ! pop index
-    arg0 arg1 ADD                              ! compute quotation location
-    arg0 arg0 array-start-offset [+] MOV       ! load quotation
-    arg0 quot-xt-offset [+] JMP                ! execute branch
+    ! load dispatch table
+    temp1 0 MOV
+    ! load index
+    temp0 ds-reg [] MOV
+    ! turn it into an array offset
+    fixnum>slot@
+    ! pop index
+    ds-reg bootstrap-cell SUB
+    ! compute quotation location
+    temp0 temp1 ADD
+    ! load quotation
+    temp0 temp0 array-start-offset [+] MOV
+    ! execute branch
+    temp0 quot-xt-offset [+] JMP
 ] rc-absolute-cell rt-immediate 1 rex-length + jit-dispatch jit-define
 
 : jit->r ( -- )
     rs-reg bootstrap-cell ADD
-    arg0 ds-reg [] MOV
+    temp0 ds-reg [] MOV
     ds-reg bootstrap-cell SUB
-    rs-reg [] arg0 MOV ;
+    rs-reg [] temp0 MOV ;
 
 : jit-2>r ( -- )
     rs-reg 2 bootstrap-cells ADD
-    arg0 ds-reg [] MOV
-    arg1 ds-reg -1 bootstrap-cells [+] MOV
+    temp0 ds-reg [] MOV
+    temp1 ds-reg -1 bootstrap-cells [+] MOV
     ds-reg 2 bootstrap-cells SUB
-    rs-reg [] arg0 MOV
-    rs-reg -1 bootstrap-cells [+] arg1 MOV ;
+    rs-reg [] temp0 MOV
+    rs-reg -1 bootstrap-cells [+] temp1 MOV ;
 
 : jit-3>r ( -- )
     rs-reg 3 bootstrap-cells ADD
-    arg0 ds-reg [] MOV
-    arg1 ds-reg -1 bootstrap-cells [+] MOV
-    arg2 ds-reg -2 bootstrap-cells [+] MOV
+    temp0 ds-reg [] MOV
+    temp1 ds-reg -1 bootstrap-cells [+] MOV
+    temp2 ds-reg -2 bootstrap-cells [+] MOV
     ds-reg 3 bootstrap-cells SUB
-    rs-reg [] arg0 MOV
-    rs-reg -1 bootstrap-cells [+] arg1 MOV
-    rs-reg -2 bootstrap-cells [+] arg2 MOV ;
+    rs-reg [] temp0 MOV
+    rs-reg -1 bootstrap-cells [+] temp1 MOV
+    rs-reg -2 bootstrap-cells [+] temp2 MOV ;
 
 : jit-r> ( -- )
     ds-reg bootstrap-cell ADD
-    arg0 rs-reg [] MOV
+    temp0 rs-reg [] MOV
     rs-reg bootstrap-cell SUB
-    ds-reg [] arg0 MOV ;
+    ds-reg [] temp0 MOV ;
 
 : jit-2r> ( -- )
     ds-reg 2 bootstrap-cells ADD
-    arg0 rs-reg [] MOV
-    arg1 rs-reg -1 bootstrap-cells [+] MOV
+    temp0 rs-reg [] MOV
+    temp1 rs-reg -1 bootstrap-cells [+] MOV
     rs-reg 2 bootstrap-cells SUB
-    ds-reg [] arg0 MOV
-    ds-reg -1 bootstrap-cells [+] arg1 MOV ;
+    ds-reg [] temp0 MOV
+    ds-reg -1 bootstrap-cells [+] temp1 MOV ;
 
 : jit-3r> ( -- )
     ds-reg 3 bootstrap-cells ADD
-    arg0 rs-reg [] MOV
-    arg1 rs-reg -1 bootstrap-cells [+] MOV
-    arg2 rs-reg -2 bootstrap-cells [+] MOV
+    temp0 rs-reg [] MOV
+    temp1 rs-reg -1 bootstrap-cells [+] MOV
+    temp2 rs-reg -2 bootstrap-cells [+] MOV
     rs-reg 3 bootstrap-cells SUB
-    ds-reg [] arg0 MOV
-    ds-reg -1 bootstrap-cells [+] arg1 MOV
-    ds-reg -2 bootstrap-cells [+] arg2 MOV ;
+    ds-reg [] temp0 MOV
+    ds-reg -1 bootstrap-cells [+] temp1 MOV
+    ds-reg -2 bootstrap-cells [+] temp2 MOV ;
 
 [
     jit->r
@@ -126,13 +145,14 @@ big-endian off
 ] rc-relative rt-xt 17 rex-length 6 * + jit-2dip jit-define
 
 [
-    jit-3>r                                    
+    jit-3>r
     f CALL
     jit-3r>
 ] rc-relative rt-xt 23 rex-length 8 * + jit-3dip jit-define
 
 [
-    stack-reg stack-frame-size bootstrap-cell - ADD ! unwind stack frame
+    ! unwind stack frame
+    stack-reg stack-frame-size bootstrap-cell - ADD
 ] f f f jit-epilog jit-define
 
 [ 0 RET ] f f f jit-return jit-define
@@ -141,34 +161,51 @@ big-endian off
 
 ! Quotations and words
 [
-    arg0 ds-reg [] MOV                         ! load from stack
-    ds-reg bootstrap-cell SUB                  ! pop stack
-    arg0 quot-xt-offset [+] JMP                ! call quotation
+    ! load from stack
+    temp0 ds-reg [] MOV
+    ! pop stack
+    ds-reg bootstrap-cell SUB
+    ! call quotation
+    temp0 quot-xt-offset [+] JMP
 ] f f f \ (call) define-sub-primitive
 
 [
-    arg0 ds-reg [] MOV                         ! load from stack
-    ds-reg bootstrap-cell SUB                  ! pop stack
-    arg0 word-xt-offset [+] JMP                ! execute word
+    ! load from stack
+    temp0 ds-reg [] MOV
+    ! pop stack
+    ds-reg bootstrap-cell SUB
+    ! execute word
+    temp0 word-xt-offset [+] JMP
 ] f f f \ (execute) define-sub-primitive
 
 ! Objects
 [
-    arg1 ds-reg [] MOV                         ! load from stack
-    arg1 tag-mask get AND                      ! compute tag
-    arg1 tag-bits get SHL                      ! tag the tag
-    ds-reg [] arg1 MOV                         ! push to stack
+    ! load from stack
+    temp0 ds-reg [] MOV
+    ! compute tag
+    temp0 tag-mask get AND
+    ! tag the tag
+    temp0 tag-bits get SHL
+    ! push to stack
+    ds-reg [] temp0 MOV
 ] f f f \ tag define-sub-primitive
 
 [
-    arg0 ds-reg [] MOV                         ! load slot number
-    ds-reg bootstrap-cell SUB                  ! adjust stack pointer
-    arg1 ds-reg [] MOV                         ! load object
-    fixnum>slot@                               ! turn slot number into offset
-    arg1 tag-bits get SHR                      ! mask off tag
-    arg1 tag-bits get SHL
-    arg0 arg1 arg0 [+] MOV                     ! load slot value
-    ds-reg [] arg0 MOV                         ! push to stack
+    ! load slot number
+    temp0 ds-reg [] MOV
+    ! adjust stack pointer
+    ds-reg bootstrap-cell SUB
+    ! load object
+    temp1 ds-reg [] MOV
+    ! turn slot number into offset
+    fixnum>slot@
+    ! mask off tag
+    temp1 tag-bits get SHR
+    temp1 tag-bits get SHL
+    ! load slot value
+    temp0 temp1 temp0 [+] MOV
+    ! push to stack
+    ds-reg [] temp0 MOV
 ] f f f \ slot define-sub-primitive
 
 ! Shufflers
@@ -185,100 +222,100 @@ big-endian off
 ] f f f \ 3drop define-sub-primitive
 
 [
-    arg0 ds-reg [] MOV
+    temp0 ds-reg [] MOV
     ds-reg bootstrap-cell ADD
-    ds-reg [] arg0 MOV
+    ds-reg [] temp0 MOV
 ] f f f \ dup define-sub-primitive
 
 [
-    arg0 ds-reg [] MOV
-    arg1 ds-reg bootstrap-cell neg [+] MOV
+    temp0 ds-reg [] MOV
+    temp1 ds-reg bootstrap-cell neg [+] MOV
     ds-reg 2 bootstrap-cells ADD
-    ds-reg [] arg0 MOV
-    ds-reg bootstrap-cell neg [+] arg1 MOV
+    ds-reg [] temp0 MOV
+    ds-reg bootstrap-cell neg [+] temp1 MOV
 ] f f f \ 2dup define-sub-primitive
 
 [
-    arg0 ds-reg [] MOV
-    arg1 ds-reg -1 bootstrap-cells [+] MOV
-    temp-reg ds-reg -2 bootstrap-cells [+] MOV
+    temp0 ds-reg [] MOV
+    temp1 ds-reg -1 bootstrap-cells [+] MOV
+    temp3 ds-reg -2 bootstrap-cells [+] MOV
     ds-reg 3 bootstrap-cells ADD
-    ds-reg [] arg0 MOV
-    ds-reg -1 bootstrap-cells [+] arg1 MOV
-    ds-reg -2 bootstrap-cells [+] temp-reg MOV
+    ds-reg [] temp0 MOV
+    ds-reg -1 bootstrap-cells [+] temp1 MOV
+    ds-reg -2 bootstrap-cells [+] temp3 MOV
 ] f f f \ 3dup define-sub-primitive
 
 [
-    arg0 ds-reg [] MOV
+    temp0 ds-reg [] MOV
     ds-reg bootstrap-cell SUB
-    ds-reg [] arg0 MOV
+    ds-reg [] temp0 MOV
 ] f f f \ nip define-sub-primitive
 
 [
-    arg0 ds-reg [] MOV
+    temp0 ds-reg [] MOV
     ds-reg 2 bootstrap-cells SUB
-    ds-reg [] arg0 MOV
+    ds-reg [] temp0 MOV
 ] f f f \ 2nip define-sub-primitive
 
 [
-    arg0 ds-reg -1 bootstrap-cells [+] MOV
+    temp0 ds-reg -1 bootstrap-cells [+] MOV
     ds-reg bootstrap-cell ADD
-    ds-reg [] arg0 MOV
+    ds-reg [] temp0 MOV
 ] f f f \ over define-sub-primitive
 
 [
-    arg0 ds-reg -2 bootstrap-cells [+] MOV
+    temp0 ds-reg -2 bootstrap-cells [+] MOV
     ds-reg bootstrap-cell ADD
-    ds-reg [] arg0 MOV
+    ds-reg [] temp0 MOV
 ] f f f \ pick define-sub-primitive
 
 [
-    arg0 ds-reg [] MOV
-    arg1 ds-reg -1 bootstrap-cells [+] MOV
-    ds-reg [] arg1 MOV
+    temp0 ds-reg [] MOV
+    temp1 ds-reg -1 bootstrap-cells [+] MOV
+    ds-reg [] temp1 MOV
     ds-reg bootstrap-cell ADD
-    ds-reg [] arg0 MOV
+    ds-reg [] temp0 MOV
 ] f f f \ dupd define-sub-primitive
 
 [
-    arg0 ds-reg [] MOV
-    arg1 ds-reg -1 bootstrap-cells [+] MOV
+    temp0 ds-reg [] MOV
+    temp1 ds-reg -1 bootstrap-cells [+] MOV
     ds-reg bootstrap-cell ADD
-    ds-reg [] arg0 MOV
-    ds-reg -1 bootstrap-cells [+] arg1 MOV
-    ds-reg -2 bootstrap-cells [+] arg0 MOV
+    ds-reg [] temp0 MOV
+    ds-reg -1 bootstrap-cells [+] temp1 MOV
+    ds-reg -2 bootstrap-cells [+] temp0 MOV
 ] f f f \ tuck define-sub-primitive
 
 [
-    arg0 ds-reg [] MOV
-    arg1 ds-reg bootstrap-cell neg [+] MOV
-    ds-reg bootstrap-cell neg [+] arg0 MOV
-    ds-reg [] arg1 MOV
+    temp0 ds-reg [] MOV
+    temp1 ds-reg bootstrap-cell neg [+] MOV
+    ds-reg bootstrap-cell neg [+] temp0 MOV
+    ds-reg [] temp1 MOV
 ] f f f \ swap define-sub-primitive
 
 [
-    arg0 ds-reg -1 bootstrap-cells [+] MOV
-    arg1 ds-reg -2 bootstrap-cells [+] MOV
-    ds-reg -2 bootstrap-cells [+] arg0 MOV
-    ds-reg -1 bootstrap-cells [+] arg1 MOV
+    temp0 ds-reg -1 bootstrap-cells [+] MOV
+    temp1 ds-reg -2 bootstrap-cells [+] MOV
+    ds-reg -2 bootstrap-cells [+] temp0 MOV
+    ds-reg -1 bootstrap-cells [+] temp1 MOV
 ] f f f \ swapd define-sub-primitive
 
 [
-    arg0 ds-reg [] MOV
-    arg1 ds-reg -1 bootstrap-cells [+] MOV
-    temp-reg ds-reg -2 bootstrap-cells [+] MOV
-    ds-reg -2 bootstrap-cells [+] arg1 MOV
-    ds-reg -1 bootstrap-cells [+] arg0 MOV
-    ds-reg [] temp-reg MOV
+    temp0 ds-reg [] MOV
+    temp1 ds-reg -1 bootstrap-cells [+] MOV
+    temp3 ds-reg -2 bootstrap-cells [+] MOV
+    ds-reg -2 bootstrap-cells [+] temp1 MOV
+    ds-reg -1 bootstrap-cells [+] temp0 MOV
+    ds-reg [] temp3 MOV
 ] f f f \ rot define-sub-primitive
 
 [
-    arg0 ds-reg [] MOV
-    arg1 ds-reg -1 bootstrap-cells [+] MOV
-    temp-reg ds-reg -2 bootstrap-cells [+] MOV
-    ds-reg -2 bootstrap-cells [+] arg0 MOV
-    ds-reg -1 bootstrap-cells [+] temp-reg MOV
-    ds-reg [] arg1 MOV
+    temp0 ds-reg [] MOV
+    temp1 ds-reg -1 bootstrap-cells [+] MOV
+    temp3 ds-reg -2 bootstrap-cells [+] MOV
+    ds-reg -2 bootstrap-cells [+] temp0 MOV
+    ds-reg -1 bootstrap-cells [+] temp3 MOV
+    ds-reg [] temp1 MOV
 ] f f f \ -rot define-sub-primitive
 
 [ jit->r ] f f f \ >r define-sub-primitive
@@ -287,14 +324,20 @@ big-endian off
 
 ! Comparisons
 : jit-compare ( insn -- )
-    temp-reg 0 MOV                             ! load t
-    arg1 \ f tag-number MOV                    ! load f
-    arg0 ds-reg [] MOV                         ! load first value
-    ds-reg bootstrap-cell SUB                  ! adjust stack pointer
-    ds-reg [] arg0 CMP                         ! compare with second value
-    [ arg1 temp-reg ] dip execute              ! move t if true
-    ds-reg [] arg1 MOV                         ! store
-    ;
+    ! load t
+    temp3 0 MOV
+    ! load f
+    temp1 \ f tag-number MOV
+    ! load first value
+    temp0 ds-reg [] MOV
+    ! adjust stack pointer
+    ds-reg bootstrap-cell SUB
+    ! compare with second value
+    ds-reg [] temp0 CMP
+    ! move t if true
+    [ temp1 temp3 ] dip execute
+    ! store
+    ds-reg [] temp1 MOV ;
 
 : define-jit-compare ( insn word -- )
     [ [ jit-compare ] curry rc-absolute-cell rt-immediate 1 rex-length + ] dip
@@ -308,22 +351,30 @@ big-endian off
 
 ! Math
 : jit-math ( insn -- )
-    arg0 ds-reg [] MOV                         ! load second input
-    ds-reg bootstrap-cell SUB                  ! pop stack
-    [ ds-reg [] arg0 ] dip execute             ! compute result
-    ;
+    ! load second input
+    temp0 ds-reg [] MOV
+    ! pop stack
+    ds-reg bootstrap-cell SUB
+    ! compute result
+    [ ds-reg [] temp0 ] dip execute ;
 
 [ \ ADD jit-math ] f f f \ fixnum+fast define-sub-primitive
 
 [ \ SUB jit-math ] f f f \ fixnum-fast define-sub-primitive
 
 [
-    arg0 ds-reg [] MOV                         ! load second input
-    ds-reg bootstrap-cell SUB                  ! pop stack
-    arg1 ds-reg [] MOV                         ! load first input
-    arg0 tag-bits get SAR                      ! untag second input
-    arg0 arg1 IMUL2                            ! multiply
-    ds-reg [] arg1 MOV                         ! push result
+    ! load second input
+    temp0 ds-reg [] MOV
+    ! pop stack
+    ds-reg bootstrap-cell SUB
+    ! load first input
+    temp1 ds-reg [] MOV
+    ! untag second input
+    temp0 tag-bits get SAR
+    ! multiply
+    temp0 temp1 IMUL2
+    ! push result
+    ds-reg [] temp1 MOV
 ] f f f \ fixnum*fast define-sub-primitive
 
 [ \ AND jit-math ] f f f \ fixnum-bitand define-sub-primitive
@@ -333,75 +384,106 @@ big-endian off
 [ \ XOR jit-math ] f f f \ fixnum-bitxor define-sub-primitive
 
 [
-    ds-reg [] NOT                              ! complement
-    ds-reg [] tag-mask get XOR                 ! clear tag bits
+    ! complement
+    ds-reg [] NOT
+    ! clear tag bits
+    ds-reg [] tag-mask get XOR
 ] f f f \ fixnum-bitnot define-sub-primitive
 
 [
-    shift-arg ds-reg [] MOV                    ! load shift count
-    shift-arg tag-bits get SAR                 ! untag shift count
-    ds-reg bootstrap-cell SUB                  ! adjust stack pointer
-    temp-reg ds-reg [] MOV                     ! load value
-    arg1 temp-reg MOV                          ! make a copy
-    arg1 CL SHL                                ! compute positive shift value in arg1
-    shift-arg NEG                              ! compute negative shift value in arg0
-    temp-reg CL SAR
-    temp-reg tag-mask get bitnot AND
-    shift-arg 0 CMP                            ! if shift count was negative, move arg0 to arg1
-    arg1 temp-reg CMOVGE
-    ds-reg [] arg1 MOV                         ! push to stack
+    ! load shift count
+    shift-arg ds-reg [] MOV
+    ! untag shift count
+    shift-arg tag-bits get SAR
+    ! adjust stack pointer
+    ds-reg bootstrap-cell SUB
+    ! load value
+    temp3 ds-reg [] MOV
+    ! make a copy
+    temp1 temp3 MOV
+    ! compute positive shift value in temp1
+    temp1 CL SHL
+    shift-arg NEG
+    ! compute negative shift value in temp3
+    temp3 CL SAR
+    temp3 tag-mask get bitnot AND
+    shift-arg 0 CMP
+    ! if shift count was negative, move temp0 to temp1
+    temp1 temp3 CMOVGE
+    ! push to stack
+    ds-reg [] temp1 MOV
 ] f f f \ fixnum-shift-fast define-sub-primitive
 
 : jit-fixnum-/mod ( -- )
-    temp-reg ds-reg [] MOV                     ! load second parameter
-    div-arg ds-reg bootstrap-cell neg [+] MOV  ! load first parameter
-    mod-arg div-arg MOV                        ! make a copy
-    mod-arg bootstrap-cell-bits 1- SAR         ! sign-extend
-    temp-reg IDIV ;                            ! divide
+    ! load second parameter
+    temp3 ds-reg [] MOV
+    ! load first parameter
+    div-arg ds-reg bootstrap-cell neg [+] MOV
+    ! make a copy
+    mod-arg div-arg MOV
+    ! sign-extend
+    mod-arg bootstrap-cell-bits 1- SAR
+    ! divide
+    temp3 IDIV ;
 
 [
     jit-fixnum-/mod
-    ds-reg bootstrap-cell SUB                  ! adjust stack pointer
-    ds-reg [] mod-arg MOV                      ! push to stack
+    ! adjust stack pointer
+    ds-reg bootstrap-cell SUB
+    ! push to stack
+    ds-reg [] mod-arg MOV
 ] f f f \ fixnum-mod define-sub-primitive
 
 [
     jit-fixnum-/mod
-    ds-reg bootstrap-cell SUB                  ! adjust stack pointer
-    div-arg tag-bits get SHL                   ! tag it
-    ds-reg [] div-arg MOV                      ! push to stack
+    ! adjust stack pointer
+    ds-reg bootstrap-cell SUB
+    ! tag it
+    div-arg tag-bits get SHL
+    ! push to stack
+    ds-reg [] div-arg MOV
 ] f f f \ fixnum/i-fast define-sub-primitive
 
 [
     jit-fixnum-/mod
-    div-arg tag-bits get SHL                   ! tag it
-    ds-reg [] mod-arg MOV                      ! push to stack
+    ! tag it
+    div-arg tag-bits get SHL
+    ! push to stack
+    ds-reg [] mod-arg MOV
     ds-reg bootstrap-cell neg [+] div-arg MOV
 ] f f f \ fixnum/mod-fast define-sub-primitive
 
 [
-    arg0 ds-reg [] MOV
+    temp0 ds-reg [] MOV
     ds-reg bootstrap-cell SUB
-    arg0 ds-reg [] OR
-    arg0 tag-mask get AND
-    arg0 \ f tag-number MOV
-    arg1 1 tag-fixnum MOV
-    arg0 arg1 CMOVE
-    ds-reg [] arg0 MOV
+    temp0 ds-reg [] OR
+    temp0 tag-mask get AND
+    temp0 \ f tag-number MOV
+    temp1 1 tag-fixnum MOV
+    temp0 temp1 CMOVE
+    ds-reg [] temp0 MOV
 ] f f f \ both-fixnums? define-sub-primitive
 
 [
-    arg0 ds-reg [] MOV                         ! load local number
-    fixnum>slot@                               ! turn local number into offset
-    arg0 rs-reg arg0 [+] MOV                   ! load local value
-    ds-reg [] arg0 MOV                         ! push to stack
+    ! load local number
+    temp0 ds-reg [] MOV
+    ! turn local number into offset
+    fixnum>slot@
+    ! load local value
+    temp0 rs-reg temp0 [+] MOV
+    ! push to stack
+    ds-reg [] temp0 MOV
 ] f f f \ get-local define-sub-primitive
 
 [
-    arg0 ds-reg [] MOV                         ! load local count
-    ds-reg bootstrap-cell SUB                  ! adjust stack pointer
-    fixnum>slot@                               ! turn local number into offset
-    rs-reg arg0 SUB                            ! decrement retain stack pointer
+    ! load local count
+    temp0 ds-reg [] MOV
+    ! adjust stack pointer
+    ds-reg bootstrap-cell SUB
+    ! turn local number into offset
+    fixnum>slot@
+    ! decrement retain stack pointer
+    rs-reg temp0 SUB
 ] f f f \ drop-locals define-sub-primitive
 
 [ "bootstrap.x86" forget-vocab ] with-compilation-unit
index 52dc389fe64d592717419cc7198636596c66f3b5..8173ff6a5b137ac24122a582d4ad61cf3e815b99 100644 (file)
@@ -229,7 +229,7 @@ ARTICLE: "db-protocol" "Low-level database protocol"
 { $subsection db-open }
 "Closing a database:"
 { $subsection db-close }
-"Creating tatements:"
+"Creating statements:"
 { $subsection <simple-statement> }
 { $subsection <prepared-statement> }
 "Using statements with the database:"
index 35b09713d3c7da0558e9db448e3f2bd24d87955a..4e0c4e88405d05d9daa852ff9c4973b2693f09c1 100644 (file)
@@ -22,9 +22,6 @@ M: tuple error-help class ;
 
 M: string error. print ;
 
-: :error ( -- )
-    error get error. ;
-
 : :s ( -- )
     error-continuation get data>> stack. ;
 
@@ -63,6 +60,9 @@ M: string error. print ;
     [ global [ "Error in print-error!" print drop ] bind ]
     recover ;
 
+: :error ( -- )
+    error get print-error ;
+
 : print-error-and-restarts ( error -- )
     print-error
     restarts.
index e7ea370b8dc3335ebe7b5b67a1befed3cc434ceb..57f9b35c96373bff90e534fd3023fbab35b06dbf 100644 (file)
@@ -2,7 +2,7 @@
 ! See http://factorcode.org/license.txt for BSD license.
 USING: accessors parser generic kernel classes classes.tuple
 words slots assocs sequences arrays vectors definitions
-prettyprint math hashtables sets generalizations namespaces make ;
+math hashtables sets generalizations namespaces make ;
 IN: delegate
 
 : protocol-words ( protocol -- words )
@@ -100,6 +100,4 @@ M: protocol definition protocol-words show-words ;
 
 M: protocol definer drop \ PROTOCOL: \ ; ;
 
-M: protocol synopsis* word-synopsis ; ! Necessary?
-
 M: protocol group-words protocol-words ;
index 81310c16c0715ab63d481d619a40371f06a05f65..c21f33ec8ef44524aa832b0c5596f2f70f58a10c 100644 (file)
@@ -1,8 +1,7 @@
 ! Copyright (C) 2007 Daniel Ehrenberg
 ! See http://factorcode.org/license.txt for BSD license.
 USING: delegate sequences.private sequences assocs
-prettyprint.sections io definitions kernel continuations
-listener ;
+io definitions kernel continuations ;
 IN: delegate.protocols
 
 PROTOCOL: sequence-protocol
@@ -16,7 +15,7 @@ PROTOCOL: assoc-protocol
 
 PROTOCOL: input-stream-protocol
     stream-read1 stream-read stream-read-partial stream-readln
-    stream-read-until stream-read-quot ;
+    stream-read-until ;
 
 PROTOCOL: output-stream-protocol
     stream-flush stream-write1 stream-write stream-format
index 33cf6a698be58e869c3dc14fc167d39fabd144cb..2ad3393aecb8aa65edeb52abd4404cd2ed8c7a21 100644 (file)
@@ -1,6 +1,6 @@
 ! Copyright (C) 2008 Doug Coleman.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: alien.strings fry io.encodings.utf16 kernel
+USING: alien.strings fry io.encodings.utf16n kernel
 splitting windows windows.kernel32 system environment
 alien.c-types sequences windows.errors io.streams.memory
 io.encodings io ;
index 7126806c3d20d013f6ab022e0fbafe94c8277bce..2029c0cf2526e6672cb5dab84a26443834a07f07 100644 (file)
@@ -1,9 +1,9 @@
 ! Copyright (C) 2008 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: kernel locals.private quotations classes.tuple make
-combinators generic words interpolate namespaces sequences
-io.streams.string fry classes.mixin effects lexer parser
-classes.tuple.parser effects.parser ;
+USING: kernel quotations classes.tuple make combinators generic
+words interpolate namespaces sequences io.streams.string fry
+classes.mixin effects lexer parser classes.tuple.parser
+effects.parser locals.types locals.parser locals.rewrite.closures ;
 IN: functors
 
 : scan-param ( -- obj )
@@ -99,8 +99,8 @@ DEFER: ;FUNCTOR delimiter
 
 : (FUNCTOR:) ( -- word def )
     CREATE
-    parse-locals
+    parse-locals dup push-locals
     parse-functor-body swap pop-locals <lambda>
-    lambda-rewrite first ;
+    rewrite-closures first ;
 
 : FUNCTOR: (FUNCTOR:) define ; parsing
index 2380f5614d784cfadd0b97ee0b4c057adaea9452..3979e0518a413a2a50cb5b04956db2d3b2b9dd80 100644 (file)
@@ -1,5 +1,5 @@
 USING: help.syntax help.markup kernel sequences quotations\r
-math arrays ;\r
+math arrays combinators ;\r
 IN: generalizations\r
 \r
 HELP: nsequence\r
@@ -234,6 +234,18 @@ HELP: napply
     }\r
 } ;\r
 \r
+HELP: ncleave\r
+{ $values { "quots" "a sequence of quotations" } { "n" integer } }\r
+{ $description "A generalization of " { $link cleave } " and " { $link 2cleave } " that can work for any quotation arity."\r
+} \r
+{ $examples\r
+  "Some core words expressed in terms of " { $link ncleave } ":"\r
+    { $table\r
+        { { $link cleave } { $snippet "1 ncleave" } }\r
+        { { $link 2cleave } { $snippet "2 ncleave" } }\r
+    }\r
+} ;\r
+\r
 HELP: mnswap\r
 { $values { "m" integer } { "n" integer } }\r
 { $description "Swaps the top " { $snippet "m" } " stack elements with the " { $snippet "n" } " elements directly underneath." }\r
@@ -269,6 +281,7 @@ $nl
 { $subsection nslip }\r
 { $subsection nkeep }\r
 { $subsection napply }\r
+{ $subsection ncleave }\r
 "Generalized quotation construction:"\r
 { $subsection ncurry } \r
 { $subsection nwith } ;\r
index 3c24d20c8a15b24ecb376c8481f13754f79804e4..ae7437b346b8cd23795da57944a525856ee58862 100644 (file)
@@ -69,6 +69,10 @@ MACRO: ncurry ( n -- )
 MACRO: nwith ( n -- )
     [ with ] n*quot ;
 
+MACRO: ncleave ( quots n -- )
+    [ '[ _ '[ _ _ nkeep ] ] map [ ] join ] [ '[ _ ndrop ] ] bi
+    compose ;
+
 MACRO: napply ( n -- )
     2 [a,b]
     [ [ 1- ] [ ] bi '[ _ ntuck _ nslip ] ]
index e5202e13064b0bdbc2b397516351cb3b531f4804..3e4066d8b75bfdf5c0332654546f16321188cb76 100644 (file)
@@ -1,7 +1,8 @@
 ! Copyright (C) 2007, 2008 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
 USING: accessors definitions help help.topics help.syntax
-prettyprint.backend prettyprint words kernel effects ;
+prettyprint.backend prettyprint.custom prettyprint words kernel
+effects ;
 IN: help.definitions
 
 ! Definition protocol implementation
index 2ed86a0a19b5f68c0bdc081b9b729715778c6897..cc36e9faab9f27b7949407dca6a907b54d7977e1 100644 (file)
@@ -1,7 +1,7 @@
 USING: help help.markup help.syntax help.definitions help.topics
 namespaces words sequences classes assocs vocabs kernel arrays
-prettyprint.backend kernel.private io generic math system
-strings sbufs vectors byte-arrays quotations
+prettyprint.backend prettyprint.custom kernel.private io generic
+math system strings sbufs vectors byte-arrays quotations
 io.streams.byte-array classes.builtin parser lexer
 classes.predicate classes.union classes.intersection
 classes.singleton classes.tuple tools.vocabs.browser math.parser
index 0a392733acc12d02cc575a4ab8415e5ad383f4d2..fbebc7f0f6b0661bc35f649f51425c9c7dbf2442 100644 (file)
@@ -150,7 +150,7 @@ M: help-error error.
     ] [
         [
             swap vocab-heading.
-            [ error. nl ] each
+            [ print-error nl ] each
         ] assoc-each
     ] if-empty ;
 
index 9260f15a7b3df0aab9f3d6730a983ea64b640076..119fa23567ce0b1e590d6bb62819b953d6c54d51 100644 (file)
@@ -3,14 +3,14 @@
 USING: accessors assocs kernel math math.parser namespaces make
 sequences io io.sockets io.streams.string io.files io.timeouts
 strings splitting calendar continuations accessors vectors
-math.order hashtables byte-arrays prettyprint destructors
+math.order hashtables byte-arrays destructors
 io.encodings
 io.encodings.string
 io.encodings.ascii
 io.encodings.8-bit
 io.encodings.binary
 io.streams.duplex
-fry debugger summary ascii urls urls.encoding present
+fry ascii urls urls.encoding present
 http http.parsers ;
 IN: http.client
 
@@ -84,10 +84,6 @@ M: f >post-data ;
 
 ERROR: too-many-redirects ;
 
-M: too-many-redirects summary
-    drop
-    [ "Redirection limit of " % max-redirects # " exceeded" % ] "" make ;
-
 <PRIVATE
 
 DEFER: (with-http-request)
@@ -161,10 +157,6 @@ PRIVATE>
 
 ERROR: download-failed response ;
 
-M: download-failed error.
-    "HTTP request failed:" print nl
-    response>> . ;
-
 : check-response ( response -- response )
     dup code>> success? [ download-failed ] unless ;
 
@@ -203,3 +195,7 @@ M: download-failed error.
 
 : http-post ( post-data url -- response data )
     <post-request> http-request ;
+
+USING: vocabs vocabs.loader ;
+
+"debugger" vocab [ "http.client.debugger" require ] when
diff --git a/basis/http/client/debugger/debugger.factor b/basis/http/client/debugger/debugger.factor
new file mode 100644 (file)
index 0000000..413ae7b
--- /dev/null
@@ -0,0 +1,13 @@
+! Copyright (C) 2008 Slava Pestov.
+! See http://factorcode.org/license.txt for BSD license.
+USING: kernel summary debugger io make math.parser
+prettyprint http.client accessors ;
+IN: http.client.debugger
+
+M: too-many-redirects summary
+    drop
+    [ "Redirection limit of " % max-redirects # " exceeded" % ] "" make ;
+
+M: download-failed error.
+    "HTTP request failed:" print nl
+    response>> . ;
index d006c86462c944f47680919cea2ed87cf5ba1191..bbb0335ae43a7126617a4b947899e4d733329d92 100644 (file)
@@ -1,9 +1,9 @@
 ! Copyright (C) 2003, 2008 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: accessors kernel combinators math namespaces make
-assocs sequences splitting sorting sets debugger
-strings vectors hashtables quotations arrays byte-arrays
-math.parser calendar calendar.format present urls
+USING: accessors kernel combinators math namespaces make assocs
+sequences splitting sorting sets strings vectors hashtables
+quotations arrays byte-arrays math.parser calendar
+calendar.format present urls
 
 io io.encodings io.encodings.iana io.encodings.binary
 io.encodings.8-bit
index fd251c76db132b898cc74f25e0bdec525626b806..bde92a260d9edee86682d733616c722e2a8be299 100644 (file)
@@ -23,9 +23,3 @@ IN: io.encodings.utf16.tests
 [ { CHAR: x } ] [ { HEX: fe HEX: ff 0 CHAR: x } utf16 decode >array ] unit-test
 
 [ { HEX: ff HEX: fe 120 0 52 216 30 221 } ] [ { CHAR: x HEX: 1d11e } utf16 encode >array ] unit-test
-
-: correct-endian
-    code>> little-endian? [ utf16le = ] [ utf16be = ] if ;
-
-[ t ] [ B{ } utf16n <byte-reader> correct-endian ] unit-test
-[ t ] [ utf16n <byte-writer> correct-endian ] unit-test
diff --git a/basis/io/encodings/utf16n/utf16n-docs.factor b/basis/io/encodings/utf16n/utf16n-docs.factor
new file mode 100644 (file)
index 0000000..9ccf483
--- /dev/null
@@ -0,0 +1,6 @@
+USING: help.markup help.syntax ;
+IN: io.encodings.utf16n
+
+HELP: utf16n
+{ $class-description "The encoding descriptor for UTF-16 without a byte order mark in native endian order. This is useful mostly for FFI calls which take input of strings of the type wchar_t*" }
+{ $see-also "encodings-introduction" } ;
diff --git a/basis/io/encodings/utf16n/utf16n-tests.factor b/basis/io/encodings/utf16n/utf16n-tests.factor
new file mode 100644 (file)
index 0000000..5e7d1af
--- /dev/null
@@ -0,0 +1,9 @@
+USING: accessors alien.c-types kernel
+io.encodings.utf16 io.streams.byte-array tools.test ;
+IN: io.encodings.utf16n
+
+: correct-endian
+    code>> little-endian? [ utf16le = ] [ utf16be = ] if ;
+
+[ t ] [ B{ } utf16n <byte-reader> correct-endian ] unit-test
+[ t ] [ utf16n <byte-writer> correct-endian ] unit-test
diff --git a/basis/io/encodings/utf16n/utf16n.factor b/basis/io/encodings/utf16n/utf16n.factor
new file mode 100644 (file)
index 0000000..cc6e7e2
--- /dev/null
@@ -0,0 +1,15 @@
+! Copyright (C) 2008 Slava Pestov.
+! See http://factorcode.org/license.txt for BSD license.
+USING: alien.c-types io.encodings io.encodings.utf16 kernel ;
+IN: io.encodings.utf16n
+
+! Native-order UTF-16
+
+SINGLETON: utf16n
+
+: utf16n ( -- descriptor )
+    little-endian? utf16le utf16be ? ; foldable
+
+M: utf16n <decoder> drop utf16n <decoder> ;
+
+M: utf16n <encoder> drop utf16n <encoder> ;
diff --git a/basis/io/files/unique/backend/backend.factor b/basis/io/files/unique/backend/backend.factor
deleted file mode 100644 (file)
index 7b9809f..0000000
+++ /dev/null
@@ -1,5 +0,0 @@
-USING: io.backend ;
-IN: io.files.unique.backend
-
-HOOK: (make-unique-file) io-backend ( path -- )
-HOOK: temporary-path io-backend ( -- path )
index 825eb212f18cf2ec5a945ed04e5a236402d2ef48..bfde09dc487b02532bcf22a4f67c968f180b73f8 100644 (file)
@@ -2,12 +2,40 @@ USING: help.markup help.syntax io io.ports kernel math
 io.files.unique.private math.parser io.files ;
 IN: io.files.unique
 
+HELP: temporary-path
+{ $values
+     { "path" "a pathname string" }
+}
+{ $description "A hook that returns the path of the temporary directory in a platform-specific way. Does not guarantee that path is writable by your user." } ;
+
+HELP: touch-unique-file
+{ $values
+     { "path" "a pathname string" }
+}
+{ $description "Creates a unique file in a platform-specific way. The file is guaranteed not to exist and is openable by your user." } ;
+
+HELP: unique-length
+{ $description "A symbol storing the number of random characters inserted between the prefix and suffix of a random file name." } ;
+
+HELP: unique-retries
+{ $description "The number of times to try creating a unique file in case of a name collision. The odds of a name collision are extremely low with a sufficient " { $link unique-length } "." } ;
+
+{ unique-length unique-retries } related-words
+
 HELP: make-unique-file ( prefix suffix -- path )
 { $values { "prefix" "a string" } { "suffix" "a string" }
 { "path" "a pathname string" } }
 { $description "Creates a file that is guaranteed not to exist in a platform-specific temporary directory. The file name is composed of a prefix, a number of random digits and letters, and the suffix. Returns the full pathname." }
-{ $errors "Throws an error if a new unique file cannot be created after a number of tries. The most likely error is incorrect directory permissions on the temporary directory." }
-{ $see-also with-unique-file } ;
+{ $errors "Throws an error if a new unique file cannot be created after a number of tries. The most likely error is incorrect directory permissions on the temporary directory." } ;
+
+HELP: make-unique-file*
+{ $values
+     { "prefix" null } { "suffix" null }
+     { "path" "a pathname string" }
+}
+{ $description "Creates a file that is guaranteed not to exist in the directory in the " { $link current-directory } " variable. The file name is composed of a prefix, a number of random digits and letters, and the suffix. Returns the full pathname." } ;
+
+{ make-unique-file make-unique-file* with-unique-file } related-words
 
 HELP: with-unique-file ( prefix suffix quot: ( path -- ) -- )
 { $values { "prefix" "a string" } { "suffix" "a string" }
@@ -18,8 +46,7 @@ HELP: with-unique-file ( prefix suffix quot: ( path -- ) -- )
 HELP: make-unique-directory ( -- path )
 { $values { "path" "a pathname string" } }
 { $description "Creates a directory that is guaranteed not to exist in a platform-specific temporary directory and returns the full pathname." }
-{ $errors "Throws an error if the directory cannot be created after a number of tries. The most likely error is incorrect directory permissions on the temporary directory." }
-{ $see-also with-unique-directory } ;
+{ $errors "Throws an error if the directory cannot be created after a number of tries. The most likely error is incorrect directory permissions on the temporary directory." } ;
 
 HELP: with-unique-directory ( quot -- )
 { $values { "quot" "a quotation" } }
@@ -30,6 +57,7 @@ ARTICLE: "io.files.unique" "Temporary files"
 "The " { $vocab-link "io.files.unique" } " vocabulary implements cross-platform temporary file creation in a high-level and secure way." $nl
 "Files:"
 { $subsection make-unique-file }
+{ $subsection make-unique-file* }
 { $subsection with-unique-file }
 "Directories:"
 { $subsection make-unique-directory }
index ec89517bbc707cd749aa91169f4e33dbdc1ce513..66540fb48ed24c71e6264b9b8b5164f6b0818b64 100644 (file)
@@ -1,11 +1,13 @@
 ! Copyright (C) 2008 Doug Coleman.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: kernel math math.bitwise math.parser
-random sequences continuations namespaces
-io.files io arrays io.files.unique.backend system
-combinators vocabs.loader fry ;
+USING: kernel math math.bitwise math.parser random sequences
+continuations namespaces io.files io arrays system
+combinators vocabs.loader fry io.backend ;
 IN: io.files.unique
 
+HOOK: touch-unique-file io-backend ( path -- )
+HOOK: temporary-path io-backend ( -- path )
+
 SYMBOL: unique-length
 SYMBOL: unique-retries
 
@@ -26,12 +28,17 @@ SYMBOL: unique-retries
 
 PRIVATE>
 
+: (make-unique-file) ( path prefix suffix -- path )
+    '[
+        _ _ _ unique-length get random-name glue append-path
+        dup touch-unique-file
+    ] unique-retries get retry ;
+
 : make-unique-file ( prefix suffix -- path )
-    temporary-path -rot
-    [
-        unique-length get random-name glue append-path
-        dup (make-unique-file)
-    ] 3curry unique-retries get retry ;
+    [ temporary-path ] 2dip (make-unique-file) ;
+
+: make-unique-file* ( prefix suffix -- path )
+    [ current-directory get ] 2dip (make-unique-file) ;
 
 : with-unique-file ( prefix suffix quot: ( path -- ) -- )
     [ make-unique-file ] dip [ delete-file ] bi ; inline
diff --git a/basis/io/paths/authors.txt b/basis/io/paths/authors.txt
new file mode 100755 (executable)
index 0000000..7c1b2f2
--- /dev/null
@@ -0,0 +1 @@
+Doug Coleman
diff --git a/basis/io/paths/paths-tests.factor b/basis/io/paths/paths-tests.factor
new file mode 100644 (file)
index 0000000..01763ce
--- /dev/null
@@ -0,0 +1,11 @@
+USING: io.paths kernel tools.test io.files.unique sequences
+io.files namespaces sorting ;
+IN: io.paths.tests
+
+[ t ] [
+    [
+        10 [ "io.paths.test" "gogogo" make-unique-file* ] replicate
+        current-directory get t [ ] find-all-files
+    ] with-unique-directory
+    [ natural-sort ] bi@ =
+] unit-test
diff --git a/basis/io/paths/paths.factor b/basis/io/paths/paths.factor
new file mode 100755 (executable)
index 0000000..212ba9e
--- /dev/null
@@ -0,0 +1,58 @@
+! Copyright (C) 2008 Doug Coleman.
+! See http://factorcode.org/license.txt for BSD license.
+USING: accessors arrays deques dlists io.files
+kernel sequences system vocabs.loader fry continuations ;
+IN: io.paths
+
+TUPLE: directory-iterator path bfs queue ;
+
+<PRIVATE
+
+: qualified-directory ( path -- seq )
+    dup directory-files [ append-path ] with map ;
+
+: push-directory ( path iter -- )
+    [ qualified-directory ] dip [
+        dup queue>> swap bfs>>
+        [ push-front ] [ push-back ] if
+    ] curry each ;
+
+: <directory-iterator> ( path bfs? -- iterator )
+    <dlist> directory-iterator boa
+    dup path>> over push-directory ;
+
+: next-file ( iter -- file/f )
+    dup queue>> deque-empty? [ drop f ] [
+        dup queue>> pop-back dup link-info directory?
+        [ over push-directory next-file ] [ nip ] if
+    ] if ;
+
+: iterate-directory ( iter quot: ( obj -- ? ) -- obj )
+    over next-file [
+        over call
+        [ 2nip ] [ iterate-directory ] if*
+    ] [
+        2drop f
+    ] if* ; inline recursive
+
+PRIVATE>
+
+: find-file ( path bfs? quot: ( obj -- ? ) -- path/f )
+    [ <directory-iterator> ] dip
+    [ keep and ] curry iterate-directory ; inline
+
+: each-file ( path bfs? quot: ( obj -- ? ) -- )
+    [ <directory-iterator> ] dip
+    [ f ] compose iterate-directory drop ; inline
+
+: find-all-files ( path bfs? quot: ( obj -- ? ) -- paths )
+    [ <directory-iterator> ] dip
+    pusher [ [ f ] compose iterate-directory drop ] dip ; inline
+
+: recursive-directory ( path bfs? -- paths )
+    [ ] accumulator [ each-file ] dip ;
+
+: find-in-directories ( directories bfs? quot -- path' )
+    '[ _ _ find-file ] attempt-all ; inline
+
+os windows? [ "io.paths.windows" require ] when
diff --git a/basis/io/paths/windows/authors.txt b/basis/io/paths/windows/authors.txt
new file mode 100644 (file)
index 0000000..7c1b2f2
--- /dev/null
@@ -0,0 +1 @@
+Doug Coleman
diff --git a/basis/io/paths/windows/tags.txt b/basis/io/paths/windows/tags.txt
new file mode 100644 (file)
index 0000000..6bf6830
--- /dev/null
@@ -0,0 +1 @@
+unportable
diff --git a/basis/io/paths/windows/windows.factor b/basis/io/paths/windows/windows.factor
new file mode 100644 (file)
index 0000000..b4858aa
--- /dev/null
@@ -0,0 +1,13 @@
+! Copyright (C) 2008 Doug Coleman.
+! See http://factorcode.org/license.txt for BSD license.
+USING: arrays continuations fry io.files io.paths
+kernel windows.shell32 sequences ;
+IN: io.paths.windows
+
+: program-files-directories ( -- array )
+    program-files program-files-x86 2array ; inline
+
+: find-in-program-files ( base-directory bfs? quot -- path )
+    [
+        [ program-files-directories ] dip '[ _ append-path ] map
+    ] 2dip find-in-directories ; inline
index 0432fe4a396c6090b25c4584a698c957d789624b..6eb61a24a7e829f8b751677e5e01006f3772cf5f 100644 (file)
@@ -2,7 +2,7 @@
 ! See http://factorcode.org/license.txt for BSD license.
 USING: math kernel io sequences io.buffers io.timeouts generic
 byte-vectors system io.encodings math.order io.backend
-continuations debugger classes byte-arrays namespaces splitting
+continuations classes byte-arrays namespaces splitting
 grouping dlists assocs io.encodings.binary summary accessors
 destructors combinators ;
 IN: io.ports
index 2d990e64835bab80f8b667ac7be2cb49fb79b6ef..bc909152138e753b1fe0806b7b56f2d22d8ae35d 100644 (file)
@@ -1,7 +1,7 @@
 ! Copyright (C) 2003, 2008 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
 USING: continuations destructors kernel math math.parser
-namespaces parser sequences strings prettyprint debugger
+namespaces parser sequences strings prettyprint
 quotations combinators logging calendar assocs present
 fry accessors arrays io io.sockets io.encodings.ascii
 io.sockets.secure io.files io.streams.duplex io.timeouts
index ec45337fb1a4760351b75eddc73f974f0006d46e..60402c37ea0073923bcd09735eb480cbdf2b0b9a 100644 (file)
@@ -1,8 +1,8 @@
 ! Copyright (C) 2007, 2008, Slava Pestov, Elie CHAFTARI.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: accessors byte-arrays kernel debugger sequences
+USING: accessors byte-arrays kernel sequences
 namespaces math math.order combinators init alien alien.c-types
-alien.strings libc continuations destructors debugger summary
+alien.strings libc continuations destructors summary
 splitting assocs random math.parser locals unicode.case openssl
 openssl.libcrypto openssl.libssl io.backend io.ports io.files
 io.encodings.8-bit io.timeouts io.sockets.secure ;
index fbfae333c08b91eae2569caefcff96c3d999ab90..597aa61138903251a11dd084f58c72d4d809bf17 100644 (file)
@@ -4,7 +4,7 @@
 USING: generic kernel io.backend namespaces continuations
 sequences arrays io.encodings io.ports io.streams.duplex
 io.encodings.ascii alien.strings io.binary accessors destructors
-classes debugger byte-arrays system combinators parser
+classes byte-arrays system combinators parser
 alien.c-types math.parser splitting grouping math assocs summary
 system vocabs.loader combinators present fry ;
 IN: io.sockets
diff --git a/basis/io/streams/byte-array/byte-array-docs.factor b/basis/io/streams/byte-array/byte-array-docs.factor
new file mode 100644 (file)
index 0000000..7b27621
--- /dev/null
@@ -0,0 +1,34 @@
+USING: help.syntax help.markup io byte-arrays quotations ;
+IN: io.streams.byte-array
+
+ABOUT: "io.streams.byte-array"
+
+ARTICLE: "io.streams.byte-array" "Byte-array streams"
+"Byte array streams:"
+{ $subsection <byte-reader> }
+{ $subsection <byte-writer> }
+"Utility combinators:"
+{ $subsection with-byte-reader }
+{ $subsection with-byte-writer } ;
+
+HELP: <byte-reader>
+{ $values { "byte-array" byte-array }
+    { "encoding" "an encoding descriptor" }
+    { "stream" "a new byte reader" } }
+{ $description "Creates an input stream reading from a byte array using an encoding." } ;
+
+HELP: <byte-writer>
+{ $values { "encoding" "an encoding descriptor" }
+    { "stream" "a new byte writer" } }
+{ $description "Creates an output stream writing data to a byte array using an encoding." } ;
+
+HELP: with-byte-reader
+{ $values { "encoding" "an encoding descriptor" }
+    { "quot" quotation } { "byte-array" byte-array } }
+{ $description "Calls the quotation in a new dynamic scope with " { $link input-stream } " rebound to an input stream for reading from a byte array using an encoding." } ;
+
+HELP: with-byte-writer
+{ $values  { "encoding" "an encoding descriptor" }
+    { "quot" quotation }
+    { "byte-array" byte-array } }
+{ $description "Calls the quotation in a new dynamic scope with " { $link output-stream } " rebound to an output stream writing data to a byte array using an encoding." } ;
diff --git a/basis/io/streams/byte-array/byte-array-tests.factor b/basis/io/streams/byte-array/byte-array-tests.factor
new file mode 100644 (file)
index 0000000..77a9126
--- /dev/null
@@ -0,0 +1,9 @@
+USING: tools.test io.streams.byte-array io.encodings.binary
+io.encodings.utf8 io kernel arrays strings ;
+
+[ B{ 1 2 3 } ] [ binary [ { 1 2 3 } write ] with-byte-writer ] unit-test
+[ B{ 1 2 3 } ] [ { 1 2 3 } binary [ 3 read ] with-byte-reader ] unit-test
+
+[ B{ BIN: 11110101 BIN: 10111111 BIN: 10000000 BIN: 10111111 BIN: 11101111 BIN: 10000000 BIN: 10111111 BIN: 11011111 BIN: 10000000 CHAR: x } ]
+[ { BIN: 101111111000000111111 BIN: 1111000000111111 BIN: 11111000000 CHAR: x } utf8 [ write ] with-byte-writer ] unit-test
+[ { BIN: 101111111000000111111 } t ] [ { BIN: 11110101 BIN: 10111111 BIN: 10000000 BIN: 10111111 } utf8 <byte-reader> contents dup >array swap string? ] unit-test
diff --git a/basis/io/streams/byte-array/byte-array.factor b/basis/io/streams/byte-array/byte-array.factor
new file mode 100644 (file)
index 0000000..9d89c3d
--- /dev/null
@@ -0,0 +1,16 @@
+USING: byte-arrays byte-vectors kernel io.encodings io.streams.string
+sequences io namespaces io.encodings.private accessors ;
+IN: io.streams.byte-array
+
+: <byte-writer> ( encoding -- stream )
+    512 <byte-vector> swap <encoder> ;
+
+: with-byte-writer ( encoding quot -- byte-array )
+    [ <byte-writer> ] dip [ output-stream get ] compose with-output-stream*
+    dup encoder? [ stream>> ] when >byte-array ; inline
+
+: <byte-reader> ( byte-array encoding -- stream )
+    [ >byte-vector dup reverse-here ] dip <decoder> ;
+
+: with-byte-reader ( byte-array encoding quot -- )
+    [ <byte-reader> ] dip with-input-stream* ; inline
index 9bf637432f1a6326e929f76604b66173230d8883..53d554e766933fb12e95be23c9b78d26691e8937 100644 (file)
@@ -1,8 +1,8 @@
 ! Copyright (C) 2005, 2008 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
 USING: kernel continuations destructors io io.encodings
-io.encodings.private io.timeouts io.ports debugger summary
-listener accessors delegate delegate.protocols ;
+io.encodings.private io.timeouts io.ports summary
+accessors delegate delegate.protocols ;
 IN: io.streams.duplex
 
 TUPLE: duplex-stream in out ;
index e89b31a8848852527939036f6d28532bcbf96d48..ecc49923de5c0319cad2608acea178dde19c6d26 100644 (file)
@@ -1,7 +1,7 @@
 ! Copyright (C) 2008 Slava Pestov
 ! See http://factorcode.org/license.txt for BSD license.
 USING: kernel math io io.encodings destructors accessors
-sequences namespaces ;
+sequences namespaces byte-vectors ;
 IN: io.streams.limited
 
 TUPLE: limited-stream stream count limit ;
index c9ba8f66dfe0a82ff6c5d5fedd8e2635aa596f12..e07753c64076990032f20991523f05ac79f12cdc 100644 (file)
@@ -1,6 +1,7 @@
 ! Copyright (C) 2005, 2008 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: hashtables io colors ;
+USING: hashtables io colors summary make accessors splitting
+kernel ;
 IN: io.styles
 
 SYMBOL: plain
@@ -43,4 +44,11 @@ TUPLE: input string ;
 
 C: <input> input
 
+M: input summary
+    [
+        "Input: " %
+        string>> "\n" split1 swap %
+        "..." "" ? %
+    ] "" make ;
+
 : write-object ( str obj -- ) presented associate format ;
index 85363c8404c7274acd79f05f5b641ae9c7753593..1666d60c83fee70f2678fc02e37efe6f9b0d7e60 100644 (file)
@@ -64,10 +64,10 @@ M: mx remove-output-callbacks writes>> delete-at* drop ;
 GENERIC: wait-for-events ( ms mx -- )
 
 : input-available ( fd mx -- )
-    remove-input-callbacks [ resume ] each ;
+    reads>> delete-at* drop [ resume ] each ;
 
 : output-available ( fd mx -- )
-    remove-output-callbacks [ resume ] each ;
+    writes>> delete-at* drop [ resume ] each ;
 
 M: fd cancel-operation ( fd -- )
     dup disposed>> [ drop ] [
index 05a9bcfa8d04e3a16263672ad0153c8121ebedfb..e8d33787f38b295f27d5fe90f6ff5550c7ac89a8 100644 (file)
@@ -1,8 +1,8 @@
 ! Copyright (C) 2008 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: alien.c-types kernel io.ports io.unix.backend
-bit-arrays sequences assocs unix unix.linux.epoll math
-namespaces unix.time ;
+USING: accessors alien.c-types kernel io.ports io.unix.backend
+bit-arrays sequences assocs struct-arrays math namespaces locals
+fry unix unix.linux.epoll unix.time ;
 IN: io.unix.epoll
 
 TUPLE: epoll-mx < mx events ;
@@ -14,47 +14,50 @@ TUPLE: epoll-mx < mx events ;
 
 : <epoll-mx> ( -- mx )
     epoll-mx new-mx
-    max-events epoll_create dup io-error over set-mx-fd
-    max-events "epoll-event" <c-array> over set-epoll-mx-events ;
+        max-events epoll_create dup io-error >>fd
+        max-events "epoll-event" <struct-array> >>events ;
 
-GENERIC: io-task-events ( task -- n )
-
-M: input-task io-task-events drop EPOLLIN ;
+: make-event ( fd events -- event )
+    "epoll-event" <c-object>
+    [ set-epoll-event-events ] keep
+    [ set-epoll-event-fd ] keep ;
 
-M: output-task io-task-events drop EPOLLOUT ;
+:: do-epoll-ctl ( fd mx what events -- )
+    mx fd>> what fd fd events make-event epoll_ctl io-error ;
 
-: make-event ( task -- event )
-    "epoll-event" <c-object>
-    over io-task-events over set-epoll-event-events
-    swap io-task-fd over set-epoll-event-fd ;
+: do-epoll-add ( fd mx events -- )
+    EPOLL_CTL_ADD swap EPOLLONESHOT bitor do-epoll-ctl ;
 
-: do-epoll-ctl ( task mx what -- )
-    >r mx-fd r> rot dup io-task-fd swap make-event
-    epoll_ctl io-error ;
+: do-epoll-del ( fd mx events -- )
+    EPOLL_CTL_DEL swap do-epoll-ctl ;
 
-M: epoll-mx register-io-task ( task mx -- )
-    [ EPOLL_CTL_ADD do-epoll-ctl ] [ call-next-method ] 2bi ;
+M: epoll-mx add-input-callback ( thread fd mx -- )
+    [ EPOLLIN do-epoll-add ] [ call-next-method ] 2bi ;
 
-M: epoll-mx unregister-io-task ( task mx -- )
-    [ call-next-method ] [ EPOLL_CTL_DEL do-epoll-ctl ] 2bi ;
+M: epoll-mx add-output-callback ( thread fd mx -- )
+    [ EPOLLOUT do-epoll-add ] [ call-next-method ] 2bi ;
 
-: wait-event ( mx timeout -- n )
-    >r { mx-fd epoll-mx-events } get-slots max-events
-    r> epoll_wait dup multiplexer-error ;
+M: epoll-mx remove-input-callbacks ( fd mx -- seq )
+    2dup reads>> key? [
+        [ call-next-method ] [ EPOLLIN do-epoll-del ] 2bi
+    ] [ 2drop f ] if ;
 
-: epoll-read-task ( mx fd -- )
-    over mx-reads at* [ perform-io-task ] [ 2drop ] if ;
+M: epoll-mx remove-output-callbacks ( fd mx -- seq )
+    2dup writes>> key? [
+        [ EPOLLOUT do-epoll-del ] [ call-next-method ] 2bi
+    ] [ 2drop f ] if ;
 
-: epoll-write-task ( mx fd -- )
-    over mx-writes at* [ perform-io-task ] [ 2drop ] if ;
+: wait-event ( mx us -- n )
+    [ [ fd>> ] [ events>> ] bi [ underlying>> ] [ length ] bi ] [ 1000 /i ] bi*
+    epoll_wait dup multiplexer-error ;
 
-: handle-event ( mx kevent -- )
-    epoll-event-fd 2dup epoll-read-task epoll-write-task ;
+: handle-event ( event mx -- )
+    [ epoll-event-fd ] dip
+    [ EPOLLIN EPOLLOUT bitor do-epoll-del ]
+    [ input-available ] [ output-available ] 2tri ;
 
 : handle-events ( mx n -- )
-    [
-        over epoll-mx-events epoll-event-nth handle-event
-    ] with each ;
+    [ dup events>> ] dip head-slice swap '[ _ handle-event ] each ;
 
-M: epoll-mx wait-for-events ( ms mx -- )
-    dup rot wait-event handle-events ;
+M: epoll-mx wait-for-events ( us mx -- )
+    swap 60000000 or dupd wait-event handle-events ;
index 322358ba14129e86f517af4e15b7d4058a3d44f7..397145c9ae21d33ff2f348d9a58461bf379d8b10 100644 (file)
@@ -2,7 +2,7 @@
 ! See http://factorcode.org/license.txt for BSD license.
 USING: accessors alien.c-types alien.strings combinators
 grouping io.encodings.utf8 io.files kernel math sequences
-system unix io.unix.files
+system unix io.unix.files specialized-arrays.direct.uint arrays
 unix.statfs.macosx unix.statvfs.macosx unix.getfsstat.macosx ;
 IN: io.unix.files.macosx
 
@@ -33,7 +33,7 @@ M: macosx statfs>file-system-info ( file-system-info byte-array -- file-system-i
         [ statfs64-f_bavail >>blocks-available ]
         [ statfs64-f_files >>files ]
         [ statfs64-f_ffree >>files-free ]
-        [ statfs64-f_fsid >>id ]
+        [ statfs64-f_fsid 2 <direct-uint-array> >array >>id ]
         [ statfs64-f_owner >>owner ]
         [ statfs64-f_type >>type-id ]
         [ statfs64-f_flags >>flags ]
index e47ac6a2e3f71ebc752368dd798006696358da84..24dcdcb65a82472141620c1d26e8a66d092267eb 100644 (file)
@@ -1,13 +1,13 @@
 ! Copyright (C) 2008 Doug Coleman.
 ! See http://factorcode.org/license.txt for BSD license.
 USING: kernel io.ports io.unix.backend math.bitwise
-unix io.files.unique.backend system ;
+unix system io.files.unique ;
 IN: io.unix.files.unique
 
 : open-unique-flags ( -- flags )
     { O_RDWR O_CREAT O_EXCL } flags ;
 
-M: unix (make-unique-file) ( path -- )
+M: unix touch-unique-file ( path -- )
     open-unique-flags file-mode open-file close-file ;
 
 M: unix temporary-path ( -- path ) "/tmp" ;
index 6b687a8afb06a7eb9e8e9c7933d81df254e756c9..b4e2b7af6fb017be664c9285806415d5561cfd4a 100644 (file)
@@ -2,10 +2,10 @@
 ! See http://factorcode.org/license.txt for BSD license.
 USING: accessors alien.c-types combinators io.unix.backend
 kernel math.bitwise sequences struct-arrays unix unix.kqueue
-unix.time ;
+unix.time assocs ;
 IN: io.unix.kqueue
 
-TUPLE: kqueue-mx < mx events monitors ;
+TUPLE: kqueue-mx < mx events ;
 
 : max-events ( -- n )
     #! We read up to 256 events at a time. This is an arbitrary
@@ -14,7 +14,6 @@ TUPLE: kqueue-mx < mx events monitors ;
 
 : <kqueue-mx> ( -- mx )
     kqueue-mx new-mx
-        H{ } clone >>monitors
         kqueue dup io-error >>fd
         max-events "kevent" <struct-array> >>events ;
 
@@ -35,30 +34,25 @@ M: kqueue-mx add-input-callback ( thread fd mx -- )
 
 M: kqueue-mx add-output-callback ( thread fd mx -- )
     [ call-next-method ] [
-        [ EVFILT_WRITE EV_DELETE make-kevent ] dip
+        [ EVFILT_WRITE { EV_ADD EV_ONESHOT } flags make-kevent ] dip
         register-kevent
     ] 2bi ;
 
-: cancel-input-callbacks ( fd mx -- seq )
-    [
-        [ EVFILT_READ EV_DELETE make-kevent ] dip
-        register-kevent
-    ] [ remove-input-callbacks ] 2bi ;
-
-: cancel-output-callbacks ( fd mx -- seq )
-    [
-        [ EVFILT_WRITE EV_DELETE make-kevent ] dip
-        register-kevent
-    ] [ remove-output-callbacks ] 2bi ;
+M: kqueue-mx remove-input-callbacks ( fd mx -- seq )
+    2dup reads>> key? [
+        [ call-next-method ] [
+            [ EVFILT_READ EV_DELETE make-kevent ] dip
+            register-kevent
+        ] 2bi
+    ] [ 2drop f ] if ;
 
-M: fd cancel-operation ( fd -- )
-    dup disposed>> [ drop ] [
-        fd>>
-        mx get-global
-        [ cancel-input-callbacks [ t swap resume-with ] each ]
-        [ cancel-output-callbacks [ t swap resume-with ] each ]
-        2bi
-    ] if ;
+M: kqueue-mx remove-output-callbacks ( fd mx -- seq )
+    2dup writes>> key? [
+        [
+            [ EVFILT_WRITE EV_DELETE make-kevent ] dip
+            register-kevent
+        ] [ call-next-method ] 2bi
+    ] [ 2drop f ] if ;
 
 : wait-kevent ( mx timespec -- n )
     [
index c81da60e121667dd9726327ac5dd0af9dc412129..e80a372aefc475475cbbb7efed349be164437b4a 100644 (file)
@@ -1,6 +1,6 @@
 ! Copyright (C) 2007, 2008 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: kernel namespaces math system sequences debugger
+USING: kernel namespaces math system sequences
 continuations arrays assocs combinators alien.c-types strings
 threads accessors environment
 io io.backend io.launcher io.ports io.files
@@ -36,9 +36,6 @@ USE: unix
 : redirect-fd ( oldfd fd -- )
     2dup = [ 2drop ] [ dup2 io-error ] if ;
 
-: redirect-inherit ( obj mode fd -- )
-    3drop ;
-
 : redirect-file ( obj mode fd -- )
     [ [ normalize-path ] dip file-mode open-file ] dip redirect-fd ;
 
@@ -50,7 +47,7 @@ USE: unix
 
 : redirect ( obj mode fd -- )
     {
-        { [ pick not ] [ redirect-inherit ] }
+        { [ pick not ] [ 3drop ] }
         { [ pick string? ] [ redirect-file ] }
         { [ pick appender? ] [ redirect-file-append ] }
         { [ pick +closed+ eq? ] [ redirect-closed ] }
index e75f4c5f6b9b3a08ba2285a1a20902b367daadeb..be5b83f1b06e33e72762249fb09a873fafbb3d7a 100644 (file)
@@ -1,10 +1,10 @@
 ! Copyright (C) 2008 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
 USING: kernel io.backend io.monitors io.unix.backend
-io.unix.select io.unix.linux.monitors system namespaces ;
+io.unix.epoll io.unix.linux.monitors system namespaces ;
 IN: io.unix.linux
 
 M: linux init-io ( -- )
-    <select-mx> mx set-global ;
+    <epoll-mx> mx set-global ;
 
 linux set-io-backend
index 77140b81c95725e89490040d95233012e555cb27..ef52b676fb60d53070c9c0a80e034f53dc59cc83 100644 (file)
@@ -1,6 +1,10 @@
 ! Copyright (C) 2008 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
 IN: io.unix.macosx
-USING: io.unix.bsd io.backend system ;
+USING: io.unix.backend io.unix.bsd io.unix.kqueue io.backend
+namespaces system ;
+
+M: macosx init-io ( -- )
+    <kqueue-mx> mx set-global ;
 
 macosx set-io-backend
index a096380b74b8ca9adc6008e60f44481223697c19..106b6569ede35aab8c395a614d3efe8d5dc962ae 100644 (file)
@@ -1,6 +1,6 @@
 ! Copyright (C) 2007, 2008, Slava Pestov, Elie CHAFTARI.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: accessors unix byte-arrays kernel debugger sequences
+USING: accessors unix byte-arrays kernel sequences
 namespaces math math.order combinators init alien alien.c-types
 alien.strings libc continuations destructors openssl
 openssl.libcrypto openssl.libssl io io.files io.ports
index 83954e045bbe31ce8f1a2e365d8ffdbaded118bd..664727dbdb2b818769f30896c183cc5d219685e0 100755 (executable)
@@ -1,11 +1,11 @@
 ! Copyright (C) 2008 Doug Coleman.
 ! See http://factorcode.org/license.txt for BSD license.
 USING: alien.c-types io.binary io.backend io.files io.buffers
-io.windows kernel math splitting fry alien.strings
-windows windows.kernel32 windows.time calendar combinators
-math.functions sequences namespaces make words symbols system
-io.ports destructors accessors math.bitwise continuations
-windows.errors arrays byte-arrays ;
+io.encodings.utf16n io.ports io.windows kernel math splitting
+fry alien.strings windows windows.kernel32 windows.time calendar
+combinators math.functions sequences namespaces make words
+symbols system destructors accessors math.bitwise continuations
+windows.errors arrays byte-arrays generalizations ;
 IN: io.windows.files
 
 : open-file ( path access-mode create-mode flags -- handle )
@@ -117,7 +117,7 @@ M: windows delete-directory ( path -- )
 : find-first-file ( path -- WIN32_FIND_DATA handle )
     "WIN32_FIND_DATA" <c-object> tuck
     FindFirstFile
-    [ INVALID_HANDLE_VALUE = [ win32-error ] when ] keep ;
+    [ INVALID_HANDLE_VALUE = [ win32-error-string throw ] when ] keep ;
 
 : find-next-file ( path -- WIN32_FIND_DATA/f )
     "WIN32_FIND_DATA" <c-object> tuck
@@ -257,13 +257,15 @@ M: winnt link-info ( path -- info )
 
 HOOK: root-directory os ( string -- string' )
 
-: file-system-type ( normalized-path -- str )
-    MAX_PATH 1+ <byte-array>
-    MAX_PATH 1+
-    "DWORD" <c-object> "DWORD" <c-object> "DWORD" <c-object>
-    MAX_PATH 1+ <byte-array>
-    MAX_PATH 1+
-    [ GetVolumeInformation win32-error=0/f ] 2keep drop
+: volume-information ( normalized-path -- volume-name volume-serial max-component flags type )
+    MAX_PATH 1+ [ <byte-array> ] keep
+    "DWORD" <c-object>
+    "DWORD" <c-object>
+    "DWORD" <c-object>
+    MAX_PATH 1+ [ <byte-array> ] keep
+    [ GetVolumeInformation win32-error=0/f ] 7 nkeep
+    drop 5 nrot drop
+    [ utf16n alien>string ] 4 ndip
     utf16n alien>string ;
 
 : file-system-space ( normalized-path -- available-space total-space free-space )
@@ -278,14 +280,20 @@ HOOK: root-directory os ( string -- string' )
         [ ]
     } cleave ;
 
+TUPLE: win32-file-system-info < file-system-info max-component flags device-serial ;
+
 M: winnt file-system-info ( path -- file-system-info )
     normalize-path root-directory
-    dup [ file-system-type ] [ file-system-space ] bi
-    \ file-system-info new
+    dup [ volume-information ] [ file-system-space ] bi
+    \ win32-file-system-info new
         swap *ulonglong >>free-space
         swap *ulonglong >>total-space
         swap *ulonglong >>available-space
         swap >>type
+        swap *uint >>flags
+        swap *uint >>max-component
+        swap *uint >>device-serial
+        swap >>device-name
         swap >>mount-point
     calculate-file-system-info ;
 
@@ -299,16 +307,16 @@ M: winnt file-system-info ( path -- file-system-info )
     ] if ;
 
 : find-first-volume ( -- string handle )
-    MAX_PATH 1+ <byte-array> dup length
+    MAX_PATH 1+ [ <byte-array> ] keep
     dupd
     FindFirstVolume dup win32-error=0/f
     [ utf16n alien>string ] dip ;
 
 : find-next-volume ( handle -- string/f )
-    MAX_PATH 1+ <byte-array> dup length
-    over [ FindNextVolume ] dip swap 0 = [
+    MAX_PATH 1+ [ <byte-array> tuck ] keep
+    FindNextVolume 0 = [
         GetLastError ERROR_NO_MORE_FILES =
-        [ drop f ] [ win32-error ] if
+        [ drop f ] [ win32-error-string throw ] if
     ] [
         utf16n alien>string
     ] if ;
index b1bf2bdc1c7be50a0dcdc43a50338843b7f6fb07..ab99bf2cac9e5823161a383e87c98ac9b47b6560 100644 (file)
@@ -1,9 +1,9 @@
-USING: kernel system io.files.unique.backend
-windows.kernel32 io.windows io.windows.files io.ports windows
-destructors environment ;
+USING: kernel system windows.kernel32 io.windows
+io.windows.files io.ports windows destructors environment
+io.files.unique ;
 IN: io.windows.files.unique
 
-M: windows (make-unique-file) ( path -- )
+M: windows touch-unique-file ( path -- )
     GENERIC_WRITE CREATE_NEW 0 open-file dispose ;
 
 M: windows temporary-path ( -- path )
old mode 100644 (file)
new mode 100755 (executable)
index 9f25eb5..892a5c4
@@ -1,10 +1,10 @@
 USING: continuations destructors io.buffers io.files io.backend
-io.timeouts io.ports io.windows io.windows.files
-io.windows.nt.backend windows windows.kernel32
-kernel libc math threads system environment
-alien.c-types alien.arrays alien.strings sequences combinators
-combinators.short-circuit ascii splitting alien strings
-assocs namespaces make io.files.private accessors tr ;
+io.timeouts io.ports io.files.private io.windows
+io.windows.files io.windows.nt.backend io.encodings.utf16n
+windows windows.kernel32 kernel libc math threads system
+environment alien.c-types alien.arrays alien.strings sequences
+combinators combinators.short-circuit ascii splitting alien
+strings assocs namespaces make accessors tr ;
 IN: io.windows.nt.files
 
 M: winnt cwd
index 30345c8c69e6e18fa1487ffe57260b80a5640e22..a2b7c4fa2db2805e62466171d562cfc366388e76 100755 (executable)
@@ -5,8 +5,8 @@ kernel math assocs namespaces make continuations sequences
 hashtables sorting arrays combinators math.bitwise strings
 system accessors threads splitting io.backend io.windows
 io.windows.nt.backend io.windows.nt.files io.monitors io.ports
-io.buffers io.files io.timeouts io.encodings.string io
-windows windows.kernel32 windows.types ;
+io.buffers io.files io.timeouts io.encodings.string
+io.encodings.utf16n io windows windows.kernel32 windows.types ;
 IN: io.windows.nt.monitors
 
 : open-directory ( path -- handle )
index 95ad2640002031a72a556f472fb305677d7fa2a6..f60403055e563cbad7ee910f30e0a447b972c963 100644 (file)
@@ -82,7 +82,6 @@ t display-stacks? set-global
 : stacks. ( -- )
     display-stacks? get [
         datastack [ nl "--- Data stack:" title. stack. ] unless-empty
-        retainstack [ nl "--- Retain stack:" title. stack. ] unless-empty
     ] when ;
 
 : prompt. ( -- )
diff --git a/basis/locals/definitions/definitions.factor b/basis/locals/definitions/definitions.factor
new file mode 100644 (file)
index 0000000..99f9d0b
--- /dev/null
@@ -0,0 +1,57 @@
+! Copyright (C) 2007, 2008 Slava Pestov, Eduardo Cavazos.
+! See http://factorcode.org/license.txt for BSD license.
+USING: accessors definitions effects generic kernel locals
+macros memoize prettyprint prettyprint.backend words ;
+IN: locals.definitions
+
+PREDICATE: lambda-word < word "lambda" word-prop >boolean ;
+
+M: lambda-word definer drop \ :: \ ; ;
+
+M: lambda-word definition
+    "lambda" word-prop body>> ;
+
+M: lambda-word reset-word
+    [ call-next-method ] [ f "lambda" set-word-prop ] bi ;
+
+INTERSECTION: lambda-macro macro lambda-word ;
+
+M: lambda-macro definer drop \ MACRO:: \ ; ;
+
+M: lambda-macro definition
+    "lambda" word-prop body>> ;
+
+M: lambda-macro reset-word
+    [ call-next-method ] [ f "lambda" set-word-prop ] bi ;
+
+INTERSECTION: lambda-method method-body lambda-word ;
+
+M: lambda-method definer drop \ M:: \ ; ;
+
+M: lambda-method definition
+    "lambda" word-prop body>> ;
+
+M: lambda-method reset-word
+    [ call-next-method ] [ f "lambda" set-word-prop ] bi ;
+
+INTERSECTION: lambda-memoized memoized lambda-word ;
+
+M: lambda-memoized definer drop \ MEMO:: \ ; ;
+
+M: lambda-memoized definition
+    "lambda" word-prop body>> ;
+
+M: lambda-memoized reset-word
+    [ call-next-method ] [ f "lambda" set-word-prop ] bi ;
+
+: method-stack-effect ( method -- effect )
+    dup "lambda" word-prop vars>>
+    swap "method-generic" word-prop stack-effect
+    dup [ out>> ] when
+    <effect> ;
+
+M: lambda-method synopsis*
+    dup dup dup definer.
+    "method-class" word-prop pprint-word
+    "method-generic" word-prop pprint-word
+    method-stack-effect effect>string comment. ;
diff --git a/basis/locals/errors/errors.factor b/basis/locals/errors/errors.factor
new file mode 100644 (file)
index 0000000..95c8357
--- /dev/null
@@ -0,0 +1,40 @@
+! Copyright (C) 2007, 2008 Slava Pestov, Eduardo Cavazos.
+! See http://factorcode.org/license.txt for BSD license.
+USING: kernel summary ;
+IN: locals.errors
+
+ERROR: >r/r>-in-lambda-error ;
+
+M: >r/r>-in-lambda-error summary
+    drop
+    "Explicit retain stack manipulation is not permitted in lambda bodies" ;
+
+ERROR: binding-form-in-literal-error ;
+
+M: binding-form-in-literal-error summary
+    drop "[let, [let* and [wlet not permitted inside literals" ;
+
+ERROR: local-writer-in-literal-error ;
+
+M: local-writer-in-literal-error summary
+    drop "Local writer words not permitted inside literals" ;
+
+ERROR: local-word-in-literal-error ;
+
+M: local-word-in-literal-error summary
+    drop "Local words not permitted inside literals" ;
+
+ERROR: :>-outside-lambda-error ;
+
+M: :>-outside-lambda-error summary
+    drop ":> cannot be used outside of lambda expressions" ;
+
+ERROR: bad-lambda-rewrite output ;
+
+M: bad-lambda-rewrite summary
+    drop "You have found a bug in locals. Please report." ;
+
+ERROR: bad-local args obj ;
+
+M: bad-local summary
+    drop "You have bound a bug in locals. Please report." ;
diff --git a/basis/locals/fry/fry.factor b/basis/locals/fry/fry.factor
new file mode 100644 (file)
index 0000000..9dc9243
--- /dev/null
@@ -0,0 +1,18 @@
+! Copyright (C) 2007, 2008 Slava Pestov, Eduardo Cavazos.
+! See http://factorcode.org/license.txt for BSD license.
+USING: accessors fry fry.private generalizations kernel
+locals.types make sequences ;
+IN: locals.fry
+
+! Support for mixing locals with fry
+
+M: binding-form count-inputs body>> count-inputs ;
+
+M: lambda count-inputs body>> count-inputs ;
+
+M: lambda deep-fry
+    clone [ shallow-fry swap ] change-body
+    [ [ vars>> length ] keep '[ _ _ mnswap @ ] , ] [ drop [ncurry] % ] 2bi ;
+
+M: binding-form deep-fry
+    clone [ fry '[ @ call ] ] change-body , ;
index 89314aadc512e42a5e6248c031c88eef07d24359..77b87d1b49f2969d944f7a9cfad37f8614112782 100644 (file)
@@ -63,6 +63,35 @@ HELP: [wlet
     }
 } ;
 
+HELP: :>
+{ $syntax ":> binding" }
+{ $description "Introduces a new binding, lexically scoped to the enclosing quotation or definition." }
+{ $notes
+    "This word can only be used inside a lambda word, lambda quotation or let binding form."
+    $nl
+    "Lambda and let forms are really just syntax sugar for " { $link POSTPONE: :> } "."
+    $nl
+    "Lambdas desugar as follows:"
+    { $code
+        "[| a b | a b + b / ]"
+        "[ :> b :> a a b + b / ]"
+    }
+    "Let forms desugar as follows:"
+    { $code
+        "[|let | x [ 10 random ] | { x x } ]"
+        "10 random :> x { x x }"
+    }
+}
+{ $examples
+    { $code
+        "USING: locals math kernel ;"
+        "IN: scratchpad"
+        ":: quadratic ( a b c -- x y )"
+        "    b sq 4 a c * * - sqrt :> disc"
+        "    b neg disc [ + ] [ - ] 2bi [ 2 a * / ] bi@ ;"
+    }
+} ;
+
 HELP: ::
 { $syntax ":: word ( bindings... -- outputs... ) body... ;" }
 { $description "Defines a word with named inputs; it reads stack values into bindings from left to right, then executes the body with those bindings in lexical scope." }
@@ -209,6 +238,8 @@ $nl
 { $subsection POSTPONE: [wlet }
 "Lambda abstractions:"
 { $subsection POSTPONE: [| }
+"Lightweight binding form:"
+{ $subsection POSTPONE: :> }
 "Additional topics:"
 { $subsection "locals-literals" }
 { $subsection "locals-mutable" }
index f13c1d57fa30c00e82d836ded7e78d2d13e210d4..b5c201a5d9887860052c952f05178babca06e715 100644 (file)
@@ -441,6 +441,16 @@ M:: integer lambda-method-forget-test ( a -- b ) ;
 
 [ "USE: locals [| | [wlet | a [ 0 ] | { a } ] ]" eval ] must-fail
 
+[ "USE: locals [| | { :> a } ]" eval ] must-fail
+
+[ "USE: locals 3 :> a" eval ] must-fail
+
+[ 3 ] [ 3 [| | :> a a ] call ] unit-test
+
+[ 3 ] [ 3 [| | :> a! a ] call ] unit-test
+
+[ 3 ] [ 2 [| | :> a! a 1+ a! a ] call ] unit-test
+
 :: wlet-&&-test ( a -- ? )
     [wlet | is-integer? [ a integer? ]
             is-even? [ a even? ]
index b78b95bc245bd05142ce5bd540770c21f84e36e4..f745f6243f49fc0ad5986233d15f0e3e8143ed61 100644 (file)
 ! Copyright (C) 2007, 2008 Slava Pestov, Eduardo Cavazos.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: kernel namespaces make sequences sequences.private assocs
-math vectors strings classes.tuple generalizations parser words
-quotations debugger macros arrays macros splitting combinators
-prettyprint.backend definitions prettyprint hashtables
-prettyprint.sections sets sequences.private effects
-effects.parser generic generic.parser compiler.units accessors
-locals.backend memoize macros.expander lexer classes summary fry
-fry.private ;
+USING: lexer macros memoize parser sequences vocabs
+vocabs.loader words kernel namespaces locals.parser locals.types
+locals.errors ;
 IN: locals
 
-ERROR: >r/r>-in-lambda-error ;
-
-M: >r/r>-in-lambda-error summary
-    drop
-    "Explicit retain stack manipulation is not permitted in lambda bodies" ;
-
-ERROR: binding-form-in-literal-error ;
-
-M: binding-form-in-literal-error summary
-    drop "[let, [let* and [wlet not permitted inside literals" ;
-
-ERROR: local-writer-in-literal-error ;
-
-M: local-writer-in-literal-error summary
-    drop "Local writer words not permitted inside literals" ;
-
-ERROR: local-word-in-literal-error ;
-
-M: local-word-in-literal-error summary
-    drop "Local words not permitted inside literals" ;
-
-ERROR: bad-lambda-rewrite output ;
-
-M: bad-lambda-rewrite summary
-    drop "You have found a bug in locals. Please report." ;
-
-<PRIVATE
-
-TUPLE: lambda vars body ;
-
-C: <lambda> lambda
-
-TUPLE: binding-form bindings body ;
-
-TUPLE: let < binding-form ;
-
-C: <let> let
-
-TUPLE: let* < binding-form ;
-
-C: <let*> let*
-
-TUPLE: wlet < binding-form ;
-
-C: <wlet> wlet
-
-M: lambda expand-macros clone [ expand-macros ] change-body ;
-
-M: lambda expand-macros* expand-macros literal ;
-
-M: binding-form expand-macros
-    clone
-        [ [ expand-macros ] assoc-map ] change-bindings
-        [ expand-macros ] change-body ;
-
-M: binding-form expand-macros* expand-macros literal ;
-
-PREDICATE: local < word "local?" word-prop ;
-
-: <local> ( name -- word )
-    #! Create a local variable identifier
-    f <word>
-    dup t "local?" set-word-prop ;
-
-PREDICATE: local-word < word "local-word?" word-prop ;
-
-: <local-word> ( name -- word )
-    f <word> dup t "local-word?" set-word-prop ;
-
-PREDICATE: local-reader < word "local-reader?" word-prop ;
-
-: <local-reader> ( name -- word )
-    f <word>
-    dup t "local-reader?" set-word-prop ;
-
-PREDICATE: local-writer < word "local-writer?" word-prop ;
-
-: <local-writer> ( reader -- word )
-    dup name>> "!" append f <word> {
-        [ nip t "local-writer?" set-word-prop ]
-        [ swap "local-reader" set-word-prop ]
-        [ "local-writer" set-word-prop ]
-        [ nip ]
-    } 2cleave ;
-
-TUPLE: quote local ;
-
-C: <quote> quote
-
-: local-index ( obj args -- n )
-    [ dup quote? [ local>> ] when eq? ] with find drop ;
-
-: read-local-quot ( obj args -- quot )
-    local-index neg [ get-local ] curry ;
-
-GENERIC# localize 1 ( obj args -- quot )
-
-M: local localize read-local-quot ;
-
-M: quote localize [ local>> ] dip read-local-quot ;
-
-M: local-word localize read-local-quot [ call ] append ;
-
-M: local-reader localize read-local-quot [ local-value ] append ;
-
-M: local-writer localize
-    [ "local-reader" word-prop ] dip
-    read-local-quot [ set-local-value ] append ;
-
-M: object localize drop 1quotation ;
-
-UNION: special local quote local-word local-reader local-writer ;
-
-: load-locals-quot ( args -- quot )
-    [ [ ] ] [
-        dup [ local-reader? ] contains? [
-            dup [ local-reader? [ 1array ] [ ] ? ] map spread>quot
-        ] [ [ ] ] if swap length [ load-locals ] curry append
-    ] if-empty ;
-
-: drop-locals-quot ( args -- quot )
-    [ [ ] ] [ length [ drop-locals ] curry ] if-empty ;
-
-: point-free-body ( quot args -- newquot )
-    [ but-last-slice ] dip '[ _ localize ] map concat ;
-
-: point-free-end ( quot args -- newquot )
-    over peek special?
-    [ dup drop-locals-quot [ [ peek ] dip localize ] dip append ]
-    [ drop-locals-quot swap peek suffix ]
-    if ;
-
-: (point-free) ( quot args -- newquot )
-    [ nip load-locals-quot ]
-    [ reverse point-free-body ]
-    [ reverse point-free-end ]
-    2tri [ ] 3append-as ;
-
-: point-free ( quot args -- newquot )
-    over empty? [ nip length '[ _ ndrop ] ] [ (point-free) ] if ;
-
-UNION: lexical local local-reader local-writer local-word ;
-
-GENERIC: free-vars* ( form -- )
-
-: free-vars ( form -- vars )
-    [ free-vars* ] { } make prune ;
-
-M: local-writer free-vars* "local-reader" word-prop , ;
-
-M: lexical free-vars* , ;
-
-M: quote free-vars* , ;
-
-M: object free-vars* drop ;
-
-M: quotation free-vars* [ free-vars* ] each ;
-
-M: lambda free-vars* [ vars>> ] [ body>> ] bi free-vars swap diff % ;
-
-GENERIC: lambda-rewrite* ( obj -- )
-
-GENERIC: local-rewrite* ( obj -- )
-
-: lambda-rewrite ( form -- form' )
-    expand-macros
-    [ local-rewrite* ] [ ] make
-    [ [ lambda-rewrite* ] each ] [ ] make ;
-
-UNION: block callable lambda ;
-
-GENERIC: block-vars ( block -- seq )
-
-GENERIC: block-body ( block -- quot )
-
-M: callable block-vars drop { } ;
-
-M: callable block-body ;
-
-M: callable local-rewrite*
-    [ [ local-rewrite* ] each ] [ ] make , ;
-
-M: lambda block-vars vars>> ;
-
-M: lambda block-body body>> ;
-
-M: lambda local-rewrite*
-    [ vars>> ] [ body>> ] bi
-    [ [ local-rewrite* ] each ] [ ] make <lambda> , ;
-
-M: block lambda-rewrite*
-    #! Turn free variables into bound variables, curry them
-    #! onto the body
-    dup free-vars [ <quote> ] map dup % [
-        over block-vars prepend
-        swap block-body [ [ lambda-rewrite* ] each ] [ ] make
-        swap point-free ,
-    ] keep length \ curry <repetition> % ;
-
-GENERIC: rewrite-literal? ( obj -- ? )
-
-M: special rewrite-literal? drop t ;
-
-M: array rewrite-literal? [ rewrite-literal? ] contains? ;
-
-M: quotation rewrite-literal? [ rewrite-literal? ] contains? ;
-
-M: wrapper rewrite-literal? drop t ;
-
-M: hashtable rewrite-literal? drop t ;
-
-M: vector rewrite-literal? drop t ;
-
-M: tuple rewrite-literal? drop t ;
-
-M: object rewrite-literal? drop f ;
-
-GENERIC: rewrite-element ( obj -- )
-
-: rewrite-elements ( seq -- )
-    [ rewrite-element ] each ;
-
-: rewrite-sequence ( seq -- )
-    [ rewrite-elements ] [ length , ] [ 0 head , ] tri \ nsequence , ;
-
-M: array rewrite-element
-    dup rewrite-literal? [ rewrite-sequence ] [ , ] if ;
-
-M: vector rewrite-element rewrite-sequence ;
-
-M: hashtable rewrite-element >alist rewrite-sequence \ >hashtable , ;
-
-M: tuple rewrite-element
-    [ tuple-slots rewrite-elements ] [ class literalize , ] bi \ boa , ;
-
-M: quotation rewrite-element local-rewrite* ;
-
-M: lambda rewrite-element local-rewrite* ;
-
-M: binding-form rewrite-element binding-form-in-literal-error ;
-
-M: local rewrite-element , ;
-
-M: local-reader rewrite-element , ;
-
-M: local-writer rewrite-element
-    local-writer-in-literal-error ;
-
-M: local-word rewrite-element
-    local-word-in-literal-error ;
-
-M: word rewrite-element literalize , ;
-
-M: wrapper rewrite-element
-    dup rewrite-literal? [ wrapped>> rewrite-element ] [ , ] if ;
-
-M: object rewrite-element , ;
-
-M: array local-rewrite* rewrite-element ;
-
-M: vector local-rewrite* rewrite-element ;
-
-M: tuple local-rewrite* rewrite-element ;
-
-M: hashtable local-rewrite* rewrite-element ;
-
-M: wrapper local-rewrite* rewrite-element ;
-
-M: word local-rewrite*
-    dup { >r r> load-locals get-local drop-locals } memq?
-    [ >r/r>-in-lambda-error ] [ call-next-method ] if ;
-
-M: object lambda-rewrite* , ;
-
-M: object local-rewrite* , ;
-
-: make-local ( name -- word )
-    "!" ?tail [
-        <local-reader>
-        dup <local-writer> dup name>> set
-    ] [ <local> ] if
-    dup dup name>> set ;
-
-: make-locals ( seq -- words assoc )
-    [ [ make-local ] map ] H{ } make-assoc ;
-
-: make-local-word ( name def -- word )
-    [ <local-word> [ dup name>> set ] [ ] [ ] tri ] dip
-    "local-word-def" set-word-prop ;
-
-: push-locals ( assoc -- )
-    use get push ;
-
-: pop-locals ( assoc -- )
-    use get delete ;
-
-SYMBOL: in-lambda?
-
-: (parse-lambda) ( assoc end -- quot )
-    t in-lambda? [ parse-until ] with-variable
-    >quotation swap pop-locals ;
-
-: parse-lambda ( -- lambda )
-    "|" parse-tokens make-locals dup push-locals
-    \ ] (parse-lambda) <lambda> ;
-
-: parse-binding ( end -- pair/f )
-    scan {
-        { [ dup not ] [ unexpected-eof ] }
-        { [ 2dup = ] [ 2drop f ] }
-        [ nip scan-object 2array ]
-    } cond ;
-
-: (parse-bindings) ( end -- )
-    dup parse-binding dup [
-        first2 [ make-local ] dip 2array ,
-        (parse-bindings)
-    ] [ 2drop ] if ;
-
-: parse-bindings ( end -- bindings vars )
-    [
-        [ (parse-bindings) ] H{ } make-assoc
-        dup push-locals
-    ] { } make swap ;
-
-: parse-bindings* ( end -- words assoc )
-    [
-        [
-            namespace push-locals
-
-            (parse-bindings)
-        ] { } make-assoc
-    ] { } make swap ;
-
-: (parse-wbindings) ( end -- )
-    dup parse-binding dup [
-        first2 [ make-local-word ] keep 2array ,
-        (parse-wbindings)
-    ] [ 2drop ] if ;
-
-: parse-wbindings ( end -- bindings vars )
-    [
-        [ (parse-wbindings) ] H{ } make-assoc
-        dup push-locals
-    ] { } make swap ;
-
-: let-rewrite ( body bindings -- )
-    <reversed> [
-        [ 1array ] dip spin <lambda> '[ @ @ ]
-    ] assoc-each local-rewrite* \ call , ;
-
-M: let local-rewrite*
-    [ body>> ] [ bindings>> ] bi let-rewrite ;
-
-M: let* local-rewrite*
-    [ body>> ] [ bindings>> ] bi let-rewrite ;
-
-M: wlet local-rewrite*
-    [ body>> ] [ bindings>> ] bi
-    [ '[ _ ] ] assoc-map
-    let-rewrite ;
-
-: parse-locals ( -- vars assoc )
-    "(" expect ")" parse-effect
-    word [ over "declared-effect" set-word-prop ] when*
-    in>> [ dup pair? [ first ] when ] map make-locals dup push-locals ;
-
-: parse-locals-definition ( word -- word quot )
-    parse-locals \ ; (parse-lambda) <lambda>
-    2dup "lambda" set-word-prop
-    lambda-rewrite dup length 1 = [ first ] [ bad-lambda-rewrite ] if ;
-
-: (::) ( -- word def ) CREATE-WORD parse-locals-definition ;
-
-: (M::) ( -- word def )
-    CREATE-METHOD
-    [ parse-locals-definition ] with-method-definition ;
-
-: parsed-lambda ( accum form -- accum )
-    in-lambda? get [ parsed ] [ lambda-rewrite over push-all ] if ;
-
-PRIVATE>
+: :>
+    scan locals get [ :>-outside-lambda-error ] unless*
+    [ make-local ] bind <def> parsed ; parsing
 
 : [| parse-lambda parsed-lambda ; parsing
 
@@ -415,110 +31,12 @@ PRIVATE>
 
 : MEMO:: (::) define-memoized ; parsing
 
-<PRIVATE
-
-! Pretty-printing locals
-SYMBOL: |
-
-: pprint-var ( var -- )
-    #! Prettyprint a read/write local as its writer, just like
-    #! in the input syntax: [| x! | ... x 3 + x! ]
-    dup local-reader? [
-        "local-writer" word-prop
-    ] when pprint-word ;
-
-: pprint-vars ( vars -- ) [ pprint-var ] each ;
-
-M: lambda pprint*
-    <flow
-    \ [| pprint-word
-    dup vars>> pprint-vars
-    \ | pprint-word
-    f <inset body>> pprint-elements block>
-    \ ] pprint-word
-    block> ;
-
-: pprint-let ( let word -- )
-    pprint-word
-    [ body>> ] [ bindings>> ] bi
-    \ | pprint-word
-    t <inset
-    <block
-    [ <block [ pprint-var ] dip pprint* block> ] assoc-each
-    block>
-    \ | pprint-word
-    <block pprint-elements block>
-    block>
-    \ ] pprint-word ;
-
-M: let pprint* \ [let pprint-let ;
-
-M: wlet pprint* \ [wlet pprint-let ;
-
-M: let* pprint* \ [let* pprint-let ;
-
-PREDICATE: lambda-word < word "lambda" word-prop >boolean ;
-
-M: lambda-word definer drop \ :: \ ; ;
-
-M: lambda-word definition
-    "lambda" word-prop body>> ;
-
-M: lambda-word reset-word
-    [ call-next-method ] [ f "lambda" set-word-prop ] bi ;
-
-INTERSECTION: lambda-macro macro lambda-word ;
-
-M: lambda-macro definer drop \ MACRO:: \ ; ;
-
-M: lambda-macro definition
-    "lambda" word-prop body>> ;
-
-M: lambda-macro reset-word
-    [ call-next-method ] [ f "lambda" set-word-prop ] bi ;
-
-INTERSECTION: lambda-method method-body lambda-word ;
-
-M: lambda-method definer drop \ M:: \ ; ;
-
-M: lambda-method definition
-    "lambda" word-prop body>> ;
-
-M: lambda-method reset-word
-    [ call-next-method ] [ f "lambda" set-word-prop ] bi ;
-
-INTERSECTION: lambda-memoized memoized lambda-word ;
-
-M: lambda-memoized definer drop \ MEMO:: \ ; ;
-
-M: lambda-memoized definition
-    "lambda" word-prop body>> ;
-
-M: lambda-memoized reset-word
-    [ call-next-method ] [ f "lambda" set-word-prop ] bi ;
-
-: method-stack-effect ( method -- effect )
-    dup "lambda" word-prop vars>>
-    swap "method-generic" word-prop stack-effect
-    dup [ out>> ] when
-    <effect> ;
-
-M: lambda-method synopsis*
-    dup dup dup definer.
-    "method-class" word-prop pprint-word
-    "method-generic" word-prop pprint-word
-    method-stack-effect effect>string comment. ;
-
-PRIVATE>
-
-! Locals and fry
-M: binding-form count-inputs body>> count-inputs ;
-
-M: lambda count-inputs body>> count-inputs ;
-
-M: lambda deep-fry
-    clone [ shallow-fry swap ] change-body
-    [ [ vars>> length ] keep '[ _ _ mnswap @ ] , ] [ drop [ncurry] % ] 2bi ;
+{
+    "locals.macros"
+    "locals.fry"
+} [ require ] each
 
-M: binding-form deep-fry
-    clone [ fry '[ @ call ] ] change-body , ;
+"prettyprint" vocab [
+    "locals.definitions" require
+    "locals.prettyprint" require
+] when
diff --git a/basis/locals/macros/macros.factor b/basis/locals/macros/macros.factor
new file mode 100644 (file)
index 0000000..7bde67a
--- /dev/null
@@ -0,0 +1,16 @@
+! Copyright (C) 2007, 2008 Slava Pestov, Eduardo Cavazos.
+! See http://factorcode.org/license.txt for BSD license.
+USING: accessors assocs kernel locals.types macros.expander ;
+IN: locals.macros
+
+M: lambda expand-macros clone [ expand-macros ] change-body ;
+
+M: lambda expand-macros* expand-macros literal ;
+
+M: binding-form expand-macros
+    clone
+        [ [ expand-macros ] assoc-map ] change-bindings
+        [ expand-macros ] change-body ;
+
+M: binding-form expand-macros* expand-macros literal ;
+
diff --git a/basis/locals/parser/parser.factor b/basis/locals/parser/parser.factor
new file mode 100644 (file)
index 0000000..e6ab6c0
--- /dev/null
@@ -0,0 +1,101 @@
+! Copyright (C) 2007, 2008 Slava Pestov, Eduardo Cavazos.
+! See http://factorcode.org/license.txt for BSD license.
+USING: accessors arrays combinators effects.parser
+generic.parser kernel lexer locals.errors
+locals.rewrite.closures locals.types make namespaces parser
+quotations sequences splitting words ;
+IN: locals.parser
+
+: make-local ( name -- word )
+    "!" ?tail [
+        <local-reader>
+        dup <local-writer> dup name>> set
+    ] [ <local> ] if
+    dup dup name>> set ;
+
+: make-locals ( seq -- words assoc )
+    [ [ make-local ] map ] H{ } make-assoc ;
+
+: make-local-word ( name def -- word )
+    [ <local-word> [ dup name>> set ] [ ] [ ] tri ] dip
+    "local-word-def" set-word-prop ;
+
+SYMBOL: locals
+
+: push-locals ( assoc -- )
+    use get push ;
+
+: pop-locals ( assoc -- )
+    use get delete ;
+
+SYMBOL: in-lambda?
+
+: (parse-lambda) ( assoc end -- quot )
+    [
+        in-lambda? on
+        over locals set
+        over push-locals
+        parse-until >quotation
+        swap pop-locals
+    ] with-scope ;
+
+: parse-lambda ( -- lambda )
+    "|" parse-tokens make-locals
+    \ ] (parse-lambda) <lambda> ;
+
+: parse-binding ( end -- pair/f )
+    scan {
+        { [ dup not ] [ unexpected-eof ] }
+        { [ 2dup = ] [ 2drop f ] }
+        [ nip scan-object 2array ]
+    } cond ;
+
+: (parse-bindings) ( end -- )
+    dup parse-binding dup [
+        first2 [ make-local ] dip 2array ,
+        (parse-bindings)
+    ] [ 2drop ] if ;
+
+: parse-bindings ( end -- bindings vars )
+    [
+        [ (parse-bindings) ] H{ } make-assoc
+    ] { } make swap ;
+
+: parse-bindings* ( end -- words assoc )
+    [
+        [
+            namespace push-locals
+            (parse-bindings)
+            namespace pop-locals
+        ] { } make-assoc
+    ] { } make swap ;
+
+: (parse-wbindings) ( end -- )
+    dup parse-binding dup [
+        first2 [ make-local-word ] keep 2array ,
+        (parse-wbindings)
+    ] [ 2drop ] if ;
+
+: parse-wbindings ( end -- bindings vars )
+    [
+        [ (parse-wbindings) ] H{ } make-assoc
+    ] { } make swap ;
+
+: parse-locals ( -- vars assoc )
+    "(" expect ")" parse-effect
+    word [ over "declared-effect" set-word-prop ] when*
+    in>> [ dup pair? [ first ] when ] map make-locals ;
+
+: parse-locals-definition ( word -- word quot )
+    parse-locals \ ; (parse-lambda) <lambda>
+    2dup "lambda" set-word-prop
+    rewrite-closures dup length 1 = [ first ] [ bad-lambda-rewrite ] if ;
+
+: (::) ( -- word def ) CREATE-WORD parse-locals-definition ;
+
+: (M::) ( -- word def )
+    CREATE-METHOD
+    [ parse-locals-definition ] with-method-definition ;
+
+: parsed-lambda ( accum form -- accum )
+    in-lambda? get [ parsed ] [ rewrite-closures over push-all ] if ;
diff --git a/basis/locals/prettyprint/prettyprint.factor b/basis/locals/prettyprint/prettyprint.factor
new file mode 100644 (file)
index 0000000..187b663
--- /dev/null
@@ -0,0 +1,48 @@
+! Copyright (C) 2007, 2008 Slava Pestov, Eduardo Cavazos.
+! See http://factorcode.org/license.txt for BSD license.
+USING: accessors assocs kernel locals locals.types
+prettyprint.backend prettyprint.sections prettyprint.custom
+sequences words ;
+IN: locals.prettyprint
+
+SYMBOL: |
+
+: pprint-var ( var -- )
+    #! Prettyprint a read/write local as its writer, just like
+    #! in the input syntax: [| x! | ... x 3 + x! ]
+    dup local-reader? [
+        "local-writer" word-prop
+    ] when pprint-word ;
+
+: pprint-vars ( vars -- ) [ pprint-var ] each ;
+
+M: lambda pprint*
+    <flow
+    \ [| pprint-word
+    dup vars>> pprint-vars
+    \ | pprint-word
+    f <inset body>> pprint-elements block>
+    \ ] pprint-word
+    block> ;
+
+: pprint-let ( let word -- )
+    pprint-word
+    [ body>> ] [ bindings>> ] bi
+    \ | pprint-word
+    t <inset
+    <block
+    [ <block [ pprint-var ] dip pprint* block> ] assoc-each
+    block>
+    \ | pprint-word
+    <block pprint-elements block>
+    block>
+    \ ] pprint-word ;
+
+M: let pprint* \ [let pprint-let ;
+
+M: wlet pprint* \ [wlet pprint-let ;
+
+M: let* pprint* \ [let* pprint-let ;
+
+M: def pprint*
+    <block \ :> pprint-word local>> pprint-word block> ;
diff --git a/basis/locals/rewrite/closures/closures.factor b/basis/locals/rewrite/closures/closures.factor
new file mode 100644 (file)
index 0000000..d85155d
--- /dev/null
@@ -0,0 +1,55 @@
+! Copyright (C) 2007, 2008 Slava Pestov, Eduardo Cavazos.
+! See http://factorcode.org/license.txt for BSD license.
+USING: accessors kernel locals.rewrite.point-free
+locals.rewrite.sugar locals.types macros.expander make
+quotations sequences sets words ;
+IN: locals.rewrite.closures
+
+! Step 2: identify free variables and make them into explicit
+! parameters of lambdas which are curried on
+
+GENERIC: rewrite-closures* ( obj -- )
+
+: (rewrite-closures) ( form -- form' )
+    [ [ rewrite-closures* ] each ] [ ] make ;
+
+: rewrite-closures ( form -- form' )
+    expand-macros (rewrite-sugar) (rewrite-closures) point-free ;
+
+GENERIC: defs-vars* ( seq form -- seq' )
+
+: defs-vars ( form -- vars ) { } [ defs-vars* ] reduce prune ;
+
+M: def defs-vars* local>> unquote suffix ;
+
+M: quotation defs-vars* [ defs-vars* ] each ;
+
+M: object defs-vars* drop ;
+
+GENERIC: uses-vars* ( seq form -- seq' )
+
+: uses-vars ( form -- vars ) { } [ uses-vars* ] reduce prune ;
+
+M: local-writer uses-vars* "local-reader" word-prop suffix ;
+
+M: lexical uses-vars* suffix ;
+
+M: quote uses-vars* local>> uses-vars* ;
+
+M: object uses-vars* drop ;
+
+M: quotation uses-vars* [ uses-vars* ] each ;
+
+: free-vars ( form -- seq )
+    [ uses-vars ] [ defs-vars ] bi diff ;
+
+M: callable rewrite-closures*
+    #! Turn free variables into bound variables, curry them
+    #! onto the body
+    dup free-vars [ <quote> ] map
+    [ % ]
+    [ var-defs prepend (rewrite-closures) point-free , ]
+    [ length \ curry <repetition> % ]
+    tri ;
+
+M: object rewrite-closures* , ;
diff --git a/basis/locals/rewrite/point-free/point-free.factor b/basis/locals/rewrite/point-free/point-free.factor
new file mode 100644 (file)
index 0000000..bd322bf
--- /dev/null
@@ -0,0 +1,75 @@
+! Copyright (C) 2007, 2008 Slava Pestov, Eduardo Cavazos.
+! See http://factorcode.org/license.txt for BSD license.
+USING: accessors arrays fry kernel math quotations sequences
+words combinators make locals.backend locals.types
+locals.errors ;
+IN: locals.rewrite.point-free
+
+! Step 3: rewrite locals usage within a single quotation into
+! retain stack manipulation
+
+: local-index ( args obj -- n )
+    2dup '[ unquote _ eq? ] find drop
+    dup [ 2nip ] [ drop bad-local ] if ;
+
+: read-local-quot ( args obj -- quot )
+    local-index neg [ get-local ] curry ;
+
+GENERIC: localize ( args obj -- args quot )
+
+M: local localize dupd read-local-quot ;
+
+M: quote localize dupd local>> read-local-quot ;
+
+M: local-word localize dupd read-local-quot [ call ] append ;
+
+M: local-reader localize dupd read-local-quot [ local-value ] append ;
+
+M: local-writer localize
+    dupd "local-reader" word-prop
+    read-local-quot [ set-local-value ] append ;
+
+M: def localize
+    local>> [ prefix ] [ local-reader? [ 1array >r ] [ >r ] ? ] bi ;
+
+M: object localize 1quotation ;
+
+! We special-case all the :> at the start of a quotation
+: load-locals-quot ( args -- quot )
+    [ [ ] ] [
+        dup [ local-reader? ] contains? [
+            dup [ local-reader? [ 1array ] [ ] ? ] map
+            spread>quot
+        ] [ [ ] ] if swap length [ load-locals ] curry append
+    ] if-empty ;
+
+: load-locals-index ( quot -- n )
+    [ [ dup def? [ local>> local-reader? ] [ drop t ] if ] find drop ]
+    [ length ] bi or ;
+
+: point-free-start ( quot -- args rest )
+    dup load-locals-index
+    cut [ [ local>> ] map dup <reversed> load-locals-quot % ] dip ;
+
+: point-free-body ( args quot -- args )
+    [ localize % ] each ;
+
+: drop-locals-quot ( args -- )
+    [ length , [ drop-locals ] % ] unless-empty ;
+
+: point-free-end ( args obj -- )
+    dup special?
+    [ localize % drop-locals-quot ]
+    [ [ drop-locals-quot ] [ , ] bi* ]
+    if ;
+
+: point-free ( quot -- newquot )
+    [
+        point-free-start
+        [ drop-locals-quot ] [
+            unclip-last
+            [ point-free-body ]
+            [ point-free-end ]
+            bi*
+        ] if-empty
+    ] [ ] make ;
diff --git a/basis/locals/rewrite/sugar/sugar.factor b/basis/locals/rewrite/sugar/sugar.factor
new file mode 100644 (file)
index 0000000..05b1e23
--- /dev/null
@@ -0,0 +1,122 @@
+! Copyright (C) 2007, 2008 Slava Pestov, Eduardo Cavazos.
+! See http://factorcode.org/license.txt for BSD license.
+USING: accessors arrays assocs classes classes.tuple fry
+generalizations hashtables kernel locals locals.backend
+locals.errors locals.types make quotations sequences vectors
+words ;
+IN: locals.rewrite.sugar
+
+! Step 1: rewrite [| [let [let* [wlet into :> forms, turn
+! literals with locals in them into code which constructs
+! the literal after pushing locals on the stack
+
+GENERIC: rewrite-sugar* ( obj -- )
+
+: (rewrite-sugar) ( form -- form' )
+    [ rewrite-sugar* ] [ ] make ;
+
+GENERIC: quotation-rewrite ( form -- form' )
+
+M: callable quotation-rewrite [ [ rewrite-sugar* ] each ] [ ] make ;
+
+: var-defs ( vars -- defs ) <reversed> [ <def> ] [ ] map-as ;
+
+M: lambda quotation-rewrite
+    [ body>> ] [ vars>> var-defs ] bi
+    prepend quotation-rewrite ;
+
+M: callable rewrite-sugar* quotation-rewrite , ;
+
+M: lambda rewrite-sugar* quotation-rewrite , ;
+
+GENERIC: rewrite-literal? ( obj -- ? )
+
+M: special rewrite-literal? drop t ;
+
+M: array rewrite-literal? [ rewrite-literal? ] contains? ;
+
+M: quotation rewrite-literal? [ rewrite-literal? ] contains? ;
+
+M: wrapper rewrite-literal? drop t ;
+
+M: hashtable rewrite-literal? drop t ;
+
+M: vector rewrite-literal? drop t ;
+
+M: tuple rewrite-literal? drop t ;
+
+M: object rewrite-literal? drop f ;
+
+GENERIC: rewrite-element ( obj -- )
+
+: rewrite-elements ( seq -- )
+    [ rewrite-element ] each ;
+
+: rewrite-sequence ( seq -- )
+    [ rewrite-elements ] [ length , ] [ 0 head , ] tri \ nsequence , ;
+
+M: array rewrite-element
+    dup rewrite-literal? [ rewrite-sequence ] [ , ] if ;
+
+M: vector rewrite-element rewrite-sequence ;
+
+M: hashtable rewrite-element >alist rewrite-sequence \ >hashtable , ;
+
+M: tuple rewrite-element
+    [ tuple-slots rewrite-elements ] [ class literalize , ] bi \ boa , ;
+
+M: quotation rewrite-element rewrite-sugar* ;
+
+M: lambda rewrite-element rewrite-sugar* ;
+
+M: binding-form rewrite-element binding-form-in-literal-error ;
+
+M: local rewrite-element , ;
+
+M: local-reader rewrite-element , ;
+
+M: local-writer rewrite-element
+    local-writer-in-literal-error ;
+
+M: local-word rewrite-element
+    local-word-in-literal-error ;
+
+M: word rewrite-element literalize , ;
+
+M: wrapper rewrite-element
+    dup rewrite-literal? [ wrapped>> rewrite-element ] [ , ] if ;
+
+M: object rewrite-element , ;
+
+M: array rewrite-sugar* rewrite-element ;
+
+M: vector rewrite-sugar* rewrite-element ;
+
+M: tuple rewrite-sugar* rewrite-element ;
+
+M: def rewrite-sugar* , ;
+
+M: hashtable rewrite-sugar* rewrite-element ;
+
+M: wrapper rewrite-sugar* rewrite-element ;
+
+M: word rewrite-sugar*
+    dup { >r r> load-locals get-local drop-locals } memq?
+    [ >r/r>-in-lambda-error ] [ call-next-method ] if ;
+
+M: object rewrite-sugar* , ;
+
+: let-rewrite ( body bindings -- )
+    [ quotation-rewrite % <def> , ] assoc-each
+    quotation-rewrite % ;
+
+M: let rewrite-sugar*
+    [ body>> ] [ bindings>> ] bi let-rewrite ;
+
+M: let* rewrite-sugar*
+    [ body>> ] [ bindings>> ] bi let-rewrite ;
+
+M: wlet rewrite-sugar*
+    [ body>> ] [ bindings>> ] bi
+    [ '[ _ ] ] assoc-map
+    let-rewrite ;
diff --git a/basis/locals/types/types.factor b/basis/locals/types/types.factor
new file mode 100644 (file)
index 0000000..7a8dac1
--- /dev/null
@@ -0,0 +1,63 @@
+! Copyright (C) 2007, 2008 Slava Pestov, Eduardo Cavazos.
+! See http://factorcode.org/license.txt for BSD license.
+USING: accessors combinators kernel sequences words ;
+IN: locals.types
+
+TUPLE: lambda vars body ;
+
+C: <lambda> lambda
+
+TUPLE: binding-form bindings body ;
+
+TUPLE: let < binding-form ;
+
+C: <let> let
+
+TUPLE: let* < binding-form ;
+
+C: <let*> let*
+
+TUPLE: wlet < binding-form ;
+
+C: <wlet> wlet
+
+TUPLE: quote local ;
+
+C: <quote> quote
+
+: unquote ( quote -- local ) dup quote? [ local>> ] when ; inline
+
+TUPLE: def local ;
+
+C: <def> def
+
+PREDICATE: local < word "local?" word-prop ;
+
+: <local> ( name -- word )
+    #! Create a local variable identifier
+    f <word>
+    dup t "local?" set-word-prop ;
+
+PREDICATE: local-word < word "local-word?" word-prop ;
+
+: <local-word> ( name -- word )
+    f <word> dup t "local-word?" set-word-prop ;
+
+PREDICATE: local-reader < word "local-reader?" word-prop ;
+
+: <local-reader> ( name -- word )
+    f <word>
+    dup t "local-reader?" set-word-prop ;
+
+PREDICATE: local-writer < word "local-writer?" word-prop ;
+
+: <local-writer> ( reader -- word )
+    dup name>> "!" append f <word> {
+        [ nip t "local-writer?" set-word-prop ]
+        [ swap "local-reader" set-word-prop ]
+        [ "local-writer" set-word-prop ]
+        [ nip ]
+    } 2cleave ;
+
+UNION: lexical local local-reader local-writer local-word ;
+UNION: special lexical quote def ;
index d84e49f784cb63781bcf1c18e414e9ae1fde1d2b..24810a6c3e0a574b73ce0886e80b64d2acd24c56 100644 (file)
@@ -13,10 +13,10 @@ SYMBOL: message-histogram
 \r
 : analyze-entry ( entry -- )\r
     dup level>> { ERROR CRITICAL } memq? [ dup errors get push ] when\r
-    1 over word-name>> word-histogram get at+\r
+    dup word-name>> word-histogram get inc-at\r
     dup word-name>> word-names get member? [\r
-        1 over [ level>> ] [ word-name>> ] [ message>> ] tri 3array\r
-        message-histogram get at+\r
+        dup [ level>> ] [ word-name>> ] [ message>> ] tri 3array\r
+        message-histogram get inc-at\r
     ] when\r
     drop ;\r
 \r
index c228684e321f1ae61ef091af4bf16793aee5abdd..90713cd40fe7aa07102c40a0e39424561a553483 100644 (file)
@@ -1,8 +1,8 @@
 ! Copyright (C) 2006, 2008 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
 USING: accessors kernel kernel.private math math.private
-math.libm math.functions prettyprint.backend arrays
-math.functions.private sequences parser ;
+math.libm math.functions arrays math.functions.private sequences
+parser ;
 IN: math.complex.private
 
 M: real real-part ;
@@ -47,7 +47,3 @@ M: complex sqrt >polar [ fsqrt ] [ 2.0 / ] bi* polar> ;
 IN: syntax
 
 : C{ \ } [ first2 rect> ] parse-literal ; parsing
-
-M: complex pprint-delims drop \ C{ \ } ;
-M: complex >pprint-sequence >rect 2array ;
-M: complex pprint* pprint-object ;
diff --git a/basis/math/complex/prettyprint/prettyprint.factor b/basis/math/complex/prettyprint/prettyprint.factor
new file mode 100644 (file)
index 0000000..09eeb80
--- /dev/null
@@ -0,0 +1,8 @@
+! Copyright (C) 2008 Slava Pestov.
+! See http://factorcode.org/license.txt for BSD license.
+USING: math math.functions arrays prettyprint.custom kernel ;
+IN: math.complex.prettyprint
+
+M: complex pprint* pprint-object ;
+M: complex pprint-delims drop \ C{ \ } ;
+M: complex >pprint-sequence >rect 2array ;
index c753d0fb78589c9662188f479a0b3b29d00d5982..82643bef154a72488ca922931ef95acb344eeb05 100644 (file)
@@ -1,7 +1,7 @@
 ! Copyright (C) 2008 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
 USING: math kernel sequences sequences.private byte-arrays
-alien.c-types prettyprint.backend parser accessors ;
+alien.c-types prettyprint.custom parser accessors ;
 IN: nibble-arrays
 
 TUPLE: nibble-array
diff --git a/basis/peg/debugger/debugger.factor b/basis/peg/debugger/debugger.factor
new file mode 100644 (file)
index 0000000..7e751b5
--- /dev/null
@@ -0,0 +1,12 @@
+USING: io kernel accessors math.parser sequences prettyprint
+debugger peg ;
+IN: peg.debugger
+
+M: parse-error error.
+  "Peg parsing error at character position " write dup position>> number>string write 
+  "." print "Expected " write messages>> [ " or " write ] [ write ] interleave nl ;
+
+M: parse-failed error.
+  "The " write dup word>> pprint " word could not parse the following input:" print nl
+  input>> . ;
+
index ccae0fec930aff5a9bfe746adcc95ea06aca77cf..ca978862353cddd32fd420868e649e529652f1b4 100644 (file)
@@ -5,7 +5,7 @@ sequences quotations vectors namespaces make math assocs
 continuations peg peg.parsers unicode.categories multiline\r
 splitting accessors effects sequences.deep peg.search\r
 combinators.short-circuit lexer io.streams.string stack-checker\r
-io prettyprint combinators parser ;\r
+io combinators parser ;\r
 IN: peg.ebnf\r
 \r
 : rule ( name word -- parser )\r
@@ -458,16 +458,13 @@ M: ebnf-var build-locals ( code ast -- )
 M: object build-locals ( code ast -- )\r
   drop ;\r
    \r
+ERROR: bad-effect quot effect ;\r
+\r
 : check-action-effect ( quot -- quot )\r
   dup infer {\r
     { [ dup (( a -- b )) effect<= ] [ drop ] }\r
     { [ dup (( -- b )) effect<= ] [ drop [ drop ] prepose ] }\r
-    [\r
-      [ \r
-        "Bad effect: " write effect>string write \r
-        " for quotation " write pprint\r
-      ] with-string-writer throw\r
-    ]\r
+    [ bad-effect ]\r
   } cond ;\r
  \r
 M: ebnf-action (transform) ( ast -- parser )\r
index 8a62365f533ef68e1c2183a278a2af0e8a802853..3fc6fec8edc060d75b6647d239ed635f64368bf5 100644 (file)
@@ -1,14 +1,12 @@
 ! Copyright (C) 2007, 2008 Chris Double.
 ! See http://factorcode.org/license.txt for BSD license.
 USING: kernel sequences strings fry namespaces make math assocs
-debugger io vectors arrays math.parser math.order
-vectors combinators classes sets unicode.categories
-compiler.units parser words quotations effects memoize accessors
-locals effects splitting combinators.short-circuit generalizations ;
+io vectors arrays math.parser math.order vectors combinators
+classes sets unicode.categories compiler.units parser words
+quotations effects memoize accessors locals effects splitting
+combinators.short-circuit generalizations ;
 IN: peg
 
-USE: prettyprint
-
 TUPLE: parse-result remaining ast ;
 TUPLE: parse-error position messages ; 
 TUPLE: parser peg compiled id ;
@@ -19,10 +17,6 @@ M: parser hashcode* id>> hashcode* ;
 C: <parse-result> parse-result
 C: <parse-error>  parse-error
 
-M: parse-error error.
-  "Peg parsing error at character position " write dup position>> number>string write 
-  "." print "Expected " write messages>> [ " or " write ] [ write ] interleave nl ;
-
 SYMBOL: error-stack
 
 : (merge-errors) ( a b -- c )
@@ -238,8 +232,6 @@ TUPLE: peg-head rule-id involved-set eval-set ;
     nip
   ] if ; 
 
-USE: prettyprint
-
 : apply-rule ( r p -- ast )
 !   2dup [ rule-id ] dip 2array "apply-rule: " write .
    2dup recall [
@@ -624,10 +616,6 @@ PRIVATE>
 
 ERROR: parse-failed input word ;
 
-M: parse-failed error.
-  "The " write dup word>> pprint " word could not parse the following input:" print nl
-  input>> . ;
-
 : PEG:
   (:)
   [let | def [ ] word [ ] |
@@ -643,3 +631,9 @@ M: parse-failed error.
       ] with-compilation-unit
     ] over push-all
   ] ; parsing
+
+USING: vocabs vocabs.loader ;
+
+"debugger" vocab [
+    "peg.debugger" require
+] when
index e50fd52c1051eb52391929295546f852deb2475b..8c80782a2e5da3d8dfcda6d3e91ee63aa798848f 100644 (file)
@@ -1,7 +1,7 @@
 ! Based on Clojure's PersistentHashMap by Rich Hickey.
 
 USING: kernel math accessors assocs fry combinators parser
-prettyprint.backend make
+prettyprint.custom make
 persistent.assocs
 persistent.hashtables.nodes
 persistent.hashtables.nodes.empty
index 92b3f82a54c00d08ddc49e8624d2b54db5e284b6..cd8e7c49e0b29c090c3e9b9f8fc6868e907522a1 100644 (file)
@@ -1,7 +1,7 @@
 ! Based on Clojure's PersistentVector by Rich Hickey.
 
 USING: math accessors kernel sequences.private sequences arrays
-combinators combinators.short-circuit parser prettyprint.backend
+combinators combinators.short-circuit parser prettyprint.custom
 persistent.sequences ;
 IN: persistent.vectors
 
index 519e995fe579806067dab0954d1b39990636b6e6..fe7025d559a05987a993b6c04f3c8680185dc834 100644 (file)
@@ -1,15 +1,12 @@
 ! Copyright (C) 2008 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: accessors math math.parser calendar calendar.format
-strings words kernel effects ;
+USING: accessors math math.parser strings words kernel effects ;
 IN: present
 
 GENERIC: present ( object -- string )
 
 M: real present number>string ;
 
-M: timestamp present timestamp>string ;
-
 M: string present ;
 
 M: word present name>> ;
index 64e1fd45ff1b3c51532aa01d0707185d005deec5..165621887fd77a5c496bf9b795dfa31edcd94060 100644 (file)
@@ -1,14 +1,10 @@
 USING: help.markup help.syntax io kernel
-prettyprint.config prettyprint.sections words strings ;
+prettyprint.config prettyprint.sections prettyprint.custom
+words strings ;
 IN: prettyprint.backend
 
 ABOUT: "prettyprint-extension"
 
-HELP: pprint*
-{ $values { "obj" "an object" } }
-{ $contract "Adds sections to the current block corresponding to the prettyprinted representation of the object." }
-$prettyprinting-note ;
-
 HELP: pprint-word
 { $values { "word" "a word" } }
 { $description "Adds a text section for the word. Unlike the " { $link word } " method of " { $link pprint* } ", this does not add a " { $link POSTPONE: POSTPONE: } " prefix to parsing words." }
index 76c3918f639f987560afa808ee2892b442c5ea96..92d039a15df894293dc23138870352ac9302820a 100644 (file)
@@ -1,15 +1,13 @@
 ! Copyright (C) 2003, 2008 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: accessors arrays byte-arrays byte-vectors generic
-hashtables io assocs kernel math namespaces make sequences
-strings sbufs io.styles vectors words prettyprint.config
+USING: accessors arrays byte-arrays generic hashtables io assocs
+kernel math namespaces make sequences strings sbufs io.styles
+vectors words prettyprint.config prettyprint.custom
 prettyprint.sections quotations io io.files math.parser effects
 classes.tuple math.order classes.tuple.private classes
 combinators colors ;
 IN: prettyprint.backend
 
-GENERIC: pprint* ( obj -- )
-
 M: effect pprint* effect>string "(" ")" surround text ;
 
 : ?effect-height ( word -- n )
@@ -161,26 +159,19 @@ M: tuple pprint*
     [ [ pprint* ] each ] dip
     [ "~" swap number>string " more~" 3append text ] when* ;
 
-GENERIC: pprint-delims ( obj -- start end )
-
 M: quotation pprint-delims drop \ [ \ ] ;
 M: curry pprint-delims drop \ [ \ ] ;
 M: compose pprint-delims drop \ [ \ ] ;
 M: array pprint-delims drop \ { \ } ;
 M: byte-array pprint-delims drop \ B{ \ } ;
-M: byte-vector pprint-delims drop \ BV{ \ } ;
 M: vector pprint-delims drop \ V{ \ } ;
 M: hashtable pprint-delims drop \ H{ \ } ;
 M: tuple pprint-delims drop \ T{ \ } ;
 M: wrapper pprint-delims drop \ W{ \ } ;
 M: callstack pprint-delims drop \ CS{ \ } ;
 
-GENERIC: >pprint-sequence ( obj -- seq )
-
 M: object >pprint-sequence ;
-
 M: vector >pprint-sequence ;
-M: byte-vector >pprint-sequence ;
 M: curry >pprint-sequence ;
 M: compose >pprint-sequence ;
 M: hashtable >pprint-sequence >alist ;
@@ -191,16 +182,13 @@ M: tuple >pprint-sequence
     [ class ] [ tuple-slots ] bi
     [ 1array ] [ [ f 2array ] dip append ] if-empty ;
 
-GENERIC: pprint-narrow? ( obj -- ? )
-
 M: object pprint-narrow? drop f ;
-
 M: array pprint-narrow? drop t ;
 M: vector pprint-narrow? drop t ;
 M: hashtable pprint-narrow? drop t ;
 M: tuple pprint-narrow? drop t ;
 
-: pprint-object ( obj -- )
+M: object pprint-object ( obj -- )
     [
         <flow
         dup pprint-delims [
@@ -213,7 +201,6 @@ M: tuple pprint-narrow? drop t ;
 
 M: object pprint* pprint-object ;
 M: vector pprint* pprint-object ;
-M: byte-vector pprint* pprint-object ;
 M: hashtable pprint* pprint-object ;
 M: curry pprint* pprint-object ;
 M: compose pprint* pprint-object ;
diff --git a/basis/prettyprint/custom/custom-docs.factor b/basis/prettyprint/custom/custom-docs.factor
new file mode 100644 (file)
index 0000000..60557e6
--- /dev/null
@@ -0,0 +1,9 @@
+! Copyright (C) 2008 Slava Pestov.
+! See http://factorcode.org/license.txt for BSD license.
+USING: kernel help.markup help.syntax ;
+IN: prettyprint.custom
+
+HELP: pprint*
+{ $values { "obj" object } }
+{ $contract "Adds sections to the current block corresponding to the prettyprinted representation of the object." }
+$prettyprinting-note ;
diff --git a/basis/prettyprint/custom/custom.factor b/basis/prettyprint/custom/custom.factor
new file mode 100644 (file)
index 0000000..9fd940c
--- /dev/null
@@ -0,0 +1,9 @@
+! Copyright (C) 2008 Slava Pestov.
+! See http://factorcode.org/license.txt for BSD license.
+IN: prettyprint.custom
+
+GENERIC: pprint* ( obj -- )
+GENERIC: pprint-object ( obj -- )
+GENERIC: pprint-delims ( obj -- start end )
+GENERIC: >pprint-sequence ( obj -- seq )
+GENERIC: pprint-narrow? ( obj -- ? )
index 3c004e5b305c6837955f0025903d0ef1cb845e79..46d4e6e5ff5dbcd31ac4b78864effb8b585a41c2 100644 (file)
@@ -1,4 +1,4 @@
-USING: prettyprint.backend prettyprint.config
+USING: prettyprint.backend prettyprint.config prettyprint.custom
 prettyprint.sections prettyprint.private help.markup help.syntax
 io kernel words definitions quotations strings generic classes ;
 IN: prettyprint
index 7c4de1e973764081efc51b1f15cb6d23e88085f8..9d5af9e6a5afaeb47499a88cd248460d884d16d2 100644 (file)
@@ -2,12 +2,13 @@
 ! See http://factorcode.org/license.txt for BSD license.
 USING: arrays generic generic.standard assocs io kernel math
 namespaces make sequences strings io.styles io.streams.string
-vectors words prettyprint.backend prettyprint.sections
-prettyprint.config sorting splitting grouping math.parser vocabs
-definitions effects classes.builtin classes.tuple io.files
-classes continuations hashtables classes.mixin classes.union
-classes.intersection classes.predicate classes.singleton
-combinators quotations sets accessors colors parser ;
+vectors words prettyprint.backend prettyprint.custom
+prettyprint.sections prettyprint.config sorting splitting
+grouping math.parser vocabs definitions effects classes.builtin
+classes.tuple io.files classes continuations hashtables
+classes.mixin classes.union classes.intersection
+classes.predicate classes.singleton combinators quotations sets
+accessors colors parser summary ;
 IN: prettyprint
 
 : make-pprint ( obj quot -- block in use )
@@ -231,6 +232,8 @@ M: pathname synopsis* pprint* ;
         [ synopsis* ] with-in
     ] with-string-writer ;
 
+M: word summary synopsis ;
+
 : synopsis-alist ( definitions -- alist )
     [ dup synopsis swap ] { } map>assoc ;
 
index 25d04ed929efaf7d62c1606c89dadc4f1bd6729e..2cd64e90bf99f1ded6984031203f4766618059eb 100644 (file)
@@ -1,7 +1,7 @@
 ! Copyright (C) 2007, 2008 Daniel Ehrenberg.
 ! See http://factorcode.org/license.txt for BSD license.
 USING: kernel sequences assocs hashtables parser lexer
-vocabs words namespaces vocabs.loader debugger sets fry ;
+vocabs words namespaces vocabs.loader sets fry ;
 IN: qualified
 
 : define-qualified ( vocab-name prefix-name -- )
index b41e4d271e8f22d4074356240da8551231b0a0eb..c615719cc4da86e7cb3792965a63702c990274a4 100644 (file)
@@ -1,10 +1,10 @@
 ! Copyright (C) 2008 Doug Coleman.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: accessors combinators kernel math sequences strings
-sets assocs prettyprint.backend make lexer namespaces parser
-arrays fry regexp.backend regexp.utils regexp.parser regexp.nfa
-regexp.dfa regexp.traversal regexp.transition-tables splitting
-sorting ;
+USING: accessors combinators kernel math sequences strings sets
+assocs prettyprint.backend prettyprint.custom make lexer
+namespaces parser arrays fry regexp.backend regexp.utils
+regexp.parser regexp.nfa regexp.dfa regexp.traversal
+regexp.transition-tables splitting sorting ;
 IN: regexp
 
 : default-regexp ( string -- regexp )
index 0501458532e1faff6c55142422fefa4c9617a9f6..02e47ca140c00da8bb4fbcd32a637b7487957f25 100644 (file)
@@ -9,6 +9,8 @@ USING: hints math.vectors arrays kernel math accessors sequences ;
 
 HINTS: <double-array> { 2 } { 3 } ;
 
+HINTS: (double-array) { 2 } { 3 } ;
+
 HINTS: vneg { array } { double-array } ;
 HINTS: v*n { array object } { double-array float } ;
 HINTS: n*v { array object } { float double-array } ;
index 52977dc22ad8d767fb33540c99903661eb3d8305..579da5b84a4dd783b2d7cc0523d2127e553b4325 100644 (file)
@@ -1,6 +1,6 @@
 ! Copyright (C) 2008 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: functors sequences sequences.private prettyprint.backend
+USING: functors sequences sequences.private prettyprint.custom
 kernel words classes math parser alien.c-types byte-arrays
 accessors summary ;
 IN: specialized-arrays.functor
@@ -10,10 +10,14 @@ ERROR: bad-byte-array-length byte-array type ;
 M: bad-byte-array-length summary
     drop "Byte array length doesn't divide type width" ;
 
+: (c-array) ( n c-type -- array )
+    heap-size * (byte-array) ; inline
+
 FUNCTOR: define-array ( T -- )
 
 A            DEFINES ${T}-array
 <A>          DEFINES <${A}>
+(A)          DEFINES (${A})
 >A           DEFINES >${A}
 byte-array>A DEFINES byte-array>${A}
 A{           DEFINES ${A}{
@@ -29,6 +33,8 @@ TUPLE: A
 
 : <A> ( n -- specialized-array ) dup T <c-array> A boa ; inline
 
+: (A) ( n -- specialized-array ) dup T (c-array) A boa ; inline
+
 : byte-array>A ( byte-array -- specialized-array )
     dup length T heap-size /mod 0 = [ drop T bad-byte-array-length ] unless
     swap A boa ; inline
@@ -45,7 +51,7 @@ M: A set-nth-unsafe underlying>> SET-NTH call ;
 
 M: A like drop dup A instance? [ >A execute ] unless ;
 
-M: A new-sequence drop <A> execute ;
+M: A new-sequence drop (A) execute ;
 
 M: A equal? over A instance? [ sequence= ] [ 2drop f ] if ;
 
index 0628f8b48465c5364afdeee85033b5572a294e4b..8ba5354dc40c79f17783dc0493d630029de12f58 100644 (file)
@@ -1,7 +1,7 @@
 ! Copyright (C) 2008 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
 USING: functors sequences sequences.private growable
-prettyprint.backend kernel words classes math parser ;
+prettyprint.custom kernel words classes math parser ;
 IN: specialized-vectors.functor
 
 FUNCTOR: define-vector ( T -- )
index 7f8c920b199878fd95a06fbf200aa4065b9ea2b3..147749864d23d2daf5ef41923fb8ec8f72fb34b6 100644 (file)
@@ -1,12 +1,12 @@
 ! Copyright (C) 2004, 2008 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
 USING: fry arrays generic io io.streams.string kernel math
-namespaces parser prettyprint sequences strings vectors words
-quotations effects classes continuations debugger assocs
-combinators compiler.errors accessors math.order definitions
-sets generic.standard.engines.tuple hints stack-checker.state
-stack-checker.visitor stack-checker.errors
-stack-checker.values stack-checker.recursive-state ;
+namespaces parser sequences strings vectors words quotations
+effects classes continuations assocs combinators
+compiler.errors accessors math.order definitions sets
+generic.standard.engines.tuple hints stack-checker.state
+stack-checker.visitor stack-checker.errors stack-checker.values
+stack-checker.recursive-state ;
 IN: stack-checker.backend
 
 : push-d ( obj -- ) meta-d push ;
index 5b6b3c089379446056f197d84137f6776f22d492..58944e7bc42bbcdd744800527c50440780f71466 100644 (file)
@@ -1,8 +1,7 @@
 ! Copyright (C) 2006, 2008 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: kernel generic sequences prettyprint io words arrays
-summary effects debugger assocs accessors namespaces
-compiler.errors stack-checker.values
+USING: kernel generic sequences io words arrays summary effects
+assocs accessors namespaces compiler.errors stack-checker.values
 stack-checker.recursive-state ;
 IN: stack-checker.errors
 
@@ -10,8 +9,6 @@ TUPLE: inference-error error type word ;
 
 M: inference-error compiler-error-type type>> ;
 
-M: inference-error error-help error>> error-help ;
-
 : (inference-error) ( ... class type -- * )
     [ boa ] dip
     recursive-state get word>>
@@ -23,14 +20,8 @@ M: inference-error error-help error>> error-help ;
 : inference-warning ( ... class -- * )
     +warning+ (inference-error) ; inline
 
-M: inference-error error.
-    [ word>> [ "In word: " write . ] when* ] [ error>> error. ] bi ;
-
 TUPLE: literal-expected ;
 
-M: literal-expected summary
-    drop "Literal value expected" ;
-
 M: object (literal) \ literal-expected inference-warning ;
 
 TUPLE: unbalanced-branches-error branches quots ;
@@ -38,79 +29,25 @@ TUPLE: unbalanced-branches-error branches quots ;
 : unbalanced-branches-error ( branches quots -- * )
     \ unbalanced-branches-error inference-error ;
 
-M: unbalanced-branches-error error.
-    "Unbalanced branches:" print
-    [ quots>> ] [ branches>> [ length <effect> ] { } assoc>map ] bi zip
-    [ [ first pprint-short bl ] [ second effect>string print ] bi ] each ;
-
 TUPLE: too-many->r ;
 
-M: too-many->r summary
-    drop
-    "Quotation pushes elements on retain stack without popping them" ;
-
 TUPLE: too-many-r> ;
 
-M: too-many-r> summary
-    drop
-    "Quotation pops retain stack elements which it did not push" ;
-
 TUPLE: missing-effect word ;
 
-M: missing-effect error.
-    "The word " write
-    word>> pprint
-    " must declare a stack effect" print ;
-
 TUPLE: effect-error word inferred declared ;
 
 : effect-error ( word inferred declared -- * )
     \ effect-error inference-error ;
 
-M: effect-error error.
-    "Stack effects of the word " write
-    [ word>> pprint " do not match." print ]
-    [ "Inferred: " write inferred>> . ]
-    [ "Declared: " write declared>> . ] tri ;
-
 TUPLE: recursive-quotation-error quot ;
 
-M: recursive-quotation-error error.
-    "The quotation " write
-    quot>> pprint
-    " calls itself." print
-    "Stack effect inference is undecidable when quotation-level recursion is permitted." print ;
-
 TUPLE: undeclared-recursion-error word ;
 
-M: undeclared-recursion-error error.
-    "The inline recursive word " write
-    word>> pprint
-    " must be declared recursive" print ;
-
 TUPLE: diverging-recursion-error word ;
 
-M: diverging-recursion-error error.
-    "The recursive word " write
-    word>> pprint
-    " digs arbitrarily deep into the stack" print ;
-
 TUPLE: unbalanced-recursion-error word height ;
 
-M: unbalanced-recursion-error error.
-    "The recursive word " write
-    word>> pprint
-    " leaves with the stack having the wrong height" print ;
-
 TUPLE: inconsistent-recursive-call-error word ;
 
-M: inconsistent-recursive-call-error error.
-    "The recursive word " write
-    word>> pprint
-    " calls itself with a different set of quotation parameters than were input" print ;
-
 TUPLE: unknown-primitive-error ;
-
-M: unknown-primitive-error error.
-    drop
-    "Cannot determine stack effect statically" print ;
diff --git a/basis/stack-checker/errors/prettyprint/prettyprint.factor b/basis/stack-checker/errors/prettyprint/prettyprint.factor
new file mode 100644 (file)
index 0000000..21c6d64
--- /dev/null
@@ -0,0 +1,67 @@
+! Copyright (C) 2008 Slava Pestov.
+! See http://factorcode.org/license.txt for BSD license.
+USING: accessors kernel prettyprint io debugger
+sequences assocs stack-checker.errors summary effects ;
+IN: stack-checker.errors.prettyprint
+
+M: inference-error error-help error>> error-help ;
+
+M: inference-error error.
+    [ word>> [ "In word: " write . ] when* ] [ error>> error. ] bi ;
+
+M: literal-expected summary
+    drop "Literal value expected" ;
+
+M: unbalanced-branches-error error.
+    "Unbalanced branches:" print
+    [ quots>> ] [ branches>> [ length <effect> ] { } assoc>map ] bi zip
+    [ [ first pprint-short bl ] [ second effect>string print ] bi ] each ;
+
+M: too-many->r summary
+    drop
+    "Quotation pushes elements on retain stack without popping them" ;
+
+M: too-many-r> summary
+    drop
+    "Quotation pops retain stack elements which it did not push" ;
+
+M: missing-effect error.
+    "The word " write
+    word>> pprint
+    " must declare a stack effect" print ;
+
+M: effect-error error.
+    "Stack effects of the word " write
+    [ word>> pprint " do not match." print ]
+    [ "Inferred: " write inferred>> . ]
+    [ "Declared: " write declared>> . ] tri ;
+
+M: recursive-quotation-error error.
+    "The quotation " write
+    quot>> pprint
+    " calls itself." print
+    "Stack effect inference is undecidable when quotation-level recursion is permitted." print ;
+
+M: undeclared-recursion-error error.
+    "The inline recursive word " write
+    word>> pprint
+    " must be declared recursive" print ;
+
+M: diverging-recursion-error error.
+    "The recursive word " write
+    word>> pprint
+    " digs arbitrarily deep into the stack" print ;
+
+M: unbalanced-recursion-error error.
+    "The recursive word " write
+    word>> pprint
+    " leaves with the stack having the wrong height" print ;
+
+M: inconsistent-recursive-call-error error.
+    "The recursive word " write
+    word>> pprint
+    " calls itself with a different set of quotation parameters than were input" print ;
+
+M: unknown-primitive-error error.
+    drop
+    "Cannot determine stack effect statically" print ;
index 28634f2d44e8fd0c9986d0dac2a605930ae61ba7..bce42f1456e325546fb781dec7333198dda1749e 100644 (file)
@@ -5,12 +5,12 @@ classes sequences.private continuations.private effects generic
 hashtables hashtables.private io io.backend io.files
 io.files.private io.streams.c kernel kernel.private math
 math.private memory namespaces namespaces.private parser
-prettyprint quotations quotations.private sbufs sbufs.private
+quotations quotations.private sbufs sbufs.private
 sequences sequences.private slots.private strings
 strings.private system threads.private classes.tuple
 classes.tuple.private vectors vectors.private words definitions
 words.private assocs summary compiler.units system.private
-combinators locals locals.backend locals.private words.private
+combinators locals locals.backend locals.types words.private
 quotations.private stack-checker.values
 stack-checker.alien
 stack-checker.state
@@ -480,6 +480,9 @@ M: object infer-call*
 \ <byte-array> { integer } { byte-array } define-primitive
 \ <byte-array> make-flushable
 
+\ (byte-array) { integer } { byte-array } define-primitive
+\ (byte-array) make-flushable
+
 \ <displaced-alien> { integer c-ptr } { c-ptr } define-primitive
 \ <displaced-alien> make-flushable
 
index ea2c19fd6df6198746803128a5a0e9b3c3d434c2..44e5374dc52d7a6cd53f2ebddc25aaa4ca1eb899 100644 (file)
@@ -1,7 +1,7 @@
 ! Copyright (C) 2008 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: accessors classes sequences splitting kernel namespaces
-make words math math.parser io.styles prettyprint assocs ;
+USING: accessors classes sequences kernel namespaces
+make words math math.parser assocs ;
 IN: summary
 
 GENERIC: summary ( object -- string )
@@ -11,15 +11,6 @@ GENERIC: summary ( object -- string )
 
 M: object summary object-summary ;
 
-M: input summary
-    [
-        "Input: " %
-        string>> "\n" split1 swap %
-        "..." "" ? %
-    ] "" make ;
-
-M: word summary synopsis ;
-
 M: sequence summary
     [
         dup class name>> %
diff --git a/basis/tools/cocoa/cocoa.factor b/basis/tools/cocoa/cocoa.factor
new file mode 100644 (file)
index 0000000..a8cdf6f
--- /dev/null
@@ -0,0 +1,16 @@
+! Copyright (C) 2008 Slava Pestov.
+! See http://factorcode.org/license.txt for BSD license.
+USING: arrays cocoa.messages cocoa.runtime combinators
+prettyprint ;
+IN: tools.cocoa
+
+: method. ( method -- )
+    {
+        [ method_getName sel_getName ]
+        [ method-return-type ]
+        [ method-arg-types ]
+        [ method_getImplementation ]
+    } cleave 4array . ;
+
+: methods. ( class -- )
+    [ method. ] each-method-in-class ;
diff --git a/basis/tools/cocoa/tags.txt b/basis/tools/cocoa/tags.txt
new file mode 100644 (file)
index 0000000..6bf6830
--- /dev/null
@@ -0,0 +1 @@
+unportable
index 18713c7b0c12c9a8ba685f57a8f73141fff91f2f..ee8615ac5a8119cd99a8c8b6ed816122d52d934d 100644 (file)
@@ -5,8 +5,8 @@ assocs kernel vocabs words sequences memory io system arrays
 continuations math definitions mirrors splitting parser classes
 summary layouts vocabs.loader prettyprint.config prettyprint
 debugger io.streams.c io.files io.backend quotations io.launcher
-words.private tools.deploy.config bootstrap.image
-io.encodings.utf8 destructors accessors ;
+words.private tools.deploy.config tools.deploy.config.editor
+bootstrap.image io.encodings.utf8 destructors accessors ;
 IN: tools.deploy.backend
 
 : copy-vm ( executable bundle-name extension -- vm )
@@ -88,6 +88,11 @@ DEFER: ?make-staging-image
     dup staging-image-name exists?
     [ drop ] [ make-staging-image ] if ;
 
+: make-deploy-config ( vocab -- file )
+    [ deploy-config unparse-use ]
+    [ "deploy-config-" prepend temp-file ] bi
+    [ utf8 set-file-contents ] keep ;
+
 : deploy-command-line ( image vocab config -- flags )
     [
         bootstrap-profile ?make-staging-image
@@ -99,7 +104,8 @@ DEFER: ?make-staging-image
 
             "-run=tools.deploy.shaker" ,
 
-            "-deploy-vocab=" prepend ,
+            [ "-deploy-vocab=" prepend , ]
+            [ make-deploy-config "-deploy-config=" prepend , ] bi
 
             "-output-image=" prepend ,
 
index e8dcd2b90efea45d68af2f582c77df2dead7c1af..c8249e4e41c89522eedd5473fc38bc8b4e5bd805 100644 (file)
@@ -2,16 +2,6 @@ USING: help.markup help.syntax words alien.c-types assocs
 kernel math ;
 IN: tools.deploy.config
 
-ARTICLE: "deploy-config" "Deployment configuration"
-"The deployment configuration is a key/value mapping stored in the " { $snippet "deploy.factor" } " file in the vocabulary's directory. If this file does not exist, the default deployment configuration is used:"
-{ $subsection default-config }
-"The deployment configuration can be read and written with a pair of words:"
-{ $subsection deploy-config }
-{ $subsection set-deploy-config }
-"A utility word is provided to load the configuration, change a flag, and store it back to disk:"
-{ $subsection set-deploy-flag }
-"The " { $link "ui.tools.deploy" } " provides a graphical way of editing the configuration." ;
-
 ARTICLE: "deploy-flags" "Deployment flags"
 "There are two sets of deployment flags. The first set controls the major subsystems which are to be included in the deployment image:"
 { $subsection deploy-math?     }
@@ -25,12 +15,7 @@ ARTICLE: "deploy-flags" "Deployment flags"
 { $subsection deploy-word-props? }
 { $subsection deploy-c-types?    } ;
 
-ARTICLE: "prepare-deploy" "Preparing to deploy an application"
-"In order to deploy an application as a stand-alone image, the application's vocabulary must first be given a " { $link POSTPONE: MAIN: } " hook. Then, a " { $emphasis "deployment configuration" } " must be created."
-{ $subsection "deploy-config" }
-{ $subsection "deploy-flags" } ;
-
-ABOUT: "prepare-deploy"
+ABOUT: "deploy-flags"
 
 HELP: deploy-name
 { $description "Deploy setting. The name of the executable."
@@ -114,15 +99,3 @@ HELP: deploy-reflection
 HELP: default-config
 { $values { "vocab" "a vocabulary specifier" } { "assoc" assoc } }
 { $description "Outputs the default deployment configuration for a vocabulary." } ;
-
-HELP: deploy-config
-{ $values { "vocab" "a vocabulary specifier" } { "assoc" assoc } }
-{ $description "Loads a vocabulary's deployment configuration from the " { $snippet "deploy.factor" } " file in the vocabulary's directory. If the file does not exist, the " { $link default-config } " is output." } ;
-
-HELP: set-deploy-config
-{ $values { "assoc" assoc } { "vocab" "a vocabulary specifier" } }
-{ $description "Stores a vocabulary's deployment configuration to the " { $snippet "deploy.factor" } " file in the vocabulary's directory." } ;
-
-HELP: set-deploy-flag
-{ $values { "value" object } { "key" object } { "vocab" "a vocabulary specifier" } }
-{ $description "Modifies an entry in a vocabulary's deployment configuration on disk." } ;
index 84bfab682be2dc4457fa4db93123d45442b1a24b..1d9761e885c9582dde124d0545fa0eacb121a09f 100644 (file)
@@ -1,8 +1,7 @@
 ! Copyright (C) 2007, 2008 Slava Pestov.
 ! 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.vocabs ;
+USING: io.files io kernel sequences assocs splitting parser
+namespaces math vocabs hashtables ;
 IN: tools.deploy.config
 
 SYMBOL: deploy-name
@@ -66,18 +65,3 @@ SYMBOL: deploy-image
         ! default value for deploy.macosx
         { "stop-after-last-window?" t }
     } assoc-union ;
-
-: deploy-config-path ( vocab -- string )
-    vocab-dir "deploy.factor" append-path ;
-
-: deploy-config ( vocab -- assoc )
-    dup default-config swap
-    dup deploy-config-path vocab-file-contents
-    parse-fresh [ first assoc-union ] unless-empty ;
-
-: set-deploy-config ( assoc vocab -- )
-    [ unparse-use string-lines ] dip
-    dup deploy-config-path set-vocab-file-contents ;
-
-: set-deploy-flag ( value key vocab -- )
-    [ deploy-config [ set-at ] keep ] keep set-deploy-config ;
diff --git a/basis/tools/deploy/config/editor/editor-docs.factor b/basis/tools/deploy/config/editor/editor-docs.factor
new file mode 100644 (file)
index 0000000..b677d37
--- /dev/null
@@ -0,0 +1,27 @@
+USING: assocs help.markup help.syntax kernel
+tools.deploy.config ;
+IN: tools.deploy.config.editor
+
+ARTICLE: "deploy-config" "Deployment configuration"
+"The deployment configuration is a key/value mapping stored in the " { $snippet "deploy.factor" } " file in the vocabulary's directory. If this file does not exist, the default deployment configuration is used:"
+{ $subsection default-config }
+"The deployment configuration can be read and written with a pair of words:"
+{ $subsection deploy-config }
+{ $subsection set-deploy-config }
+"A utility word is provided to load the configuration, change a flag, and store it back to disk:"
+{ $subsection set-deploy-flag }
+"The " { $link "ui.tools.deploy" } " provides a graphical way of editing the configuration." ;
+
+HELP: deploy-config
+{ $values { "vocab" "a vocabulary specifier" } { "assoc" assoc } }
+{ $description "Loads a vocabulary's deployment configuration from the " { $snippet "deploy.factor" } " file in the vocabulary's directory. If the file does not exist, the " { $link default-config } " is output." } ;
+
+HELP: set-deploy-config
+{ $values { "assoc" assoc } { "vocab" "a vocabulary specifier" } }
+{ $description "Stores a vocabulary's deployment configuration to the " { $snippet "deploy.factor" } " file in the vocabulary's directory." } ;
+
+HELP: set-deploy-flag
+{ $values { "value" object } { "key" object } { "vocab" "a vocabulary specifier" } }
+{ $description "Modifies an entry in a vocabulary's deployment configuration on disk." } ;
+
+ABOUT: "deploy-config"
diff --git a/basis/tools/deploy/config/editor/editor.factor b/basis/tools/deploy/config/editor/editor.factor
new file mode 100644 (file)
index 0000000..2b5788a
--- /dev/null
@@ -0,0 +1,20 @@
+! Copyright (C) 2008 Slava Pestov.
+! See http://factorcode.org/license.txt for BSD license.
+USING: assocs io.files kernel parser prettyprint sequences
+splitting tools.deploy.config tools.vocabs vocabs.loader ;
+IN: tools.deploy.config.editor
+
+: deploy-config-path ( vocab -- string )
+    vocab-dir "deploy.factor" append-path ;
+
+: deploy-config ( vocab -- assoc )
+    dup default-config swap
+    dup deploy-config-path vocab-file-contents
+    parse-fresh [ first assoc-union ] unless-empty ;
+
+: set-deploy-config ( assoc vocab -- )
+    [ unparse-use string-lines ] dip
+    dup deploy-config-path set-vocab-file-contents ;
+
+: set-deploy-flag ( value key vocab -- )
+    [ deploy-config [ set-at ] keep ] keep set-deploy-config ;
index eccb3982c7c3342399b7797c6a179b89a67294da..00e747cf0076aaf298890f16ad09d26228d8519f 100644 (file)
@@ -2,6 +2,11 @@ USING: help.markup help.syntax words alien.c-types assocs
 kernel ;
 IN: tools.deploy
 
+ARTICLE: "prepare-deploy" "Preparing to deploy an application"
+"In order to deploy an application as a stand-alone image, the application's vocabulary must first be given a " { $link POSTPONE: MAIN: } " hook. Then, a " { $emphasis "deployment configuration" } " must be created."
+{ $subsection "deploy-config" }
+{ $subsection "deploy-flags" } ;
+
 ARTICLE: "tools.deploy" "Application deployment"
 "The stand-alone application deployment tool compiles a vocabulary down to a native executable which runs the vocabulary's " { $link POSTPONE: MAIN: } " hook. Deployed executables do not depend on Factor being installed, and do not expose any source code, and thus are suitable for delivering commercial end-user applications."
 $nl
index 9cc48972fab1754385aba254462982adc31793e9..71dc746fb51e938d68495e8ca8a2366f67d770b3 100644 (file)
@@ -1,8 +1,8 @@
 IN: tools.deploy.tests\r
 USING: tools.test system io.files kernel tools.deploy.config\r
-tools.deploy.backend math sequences io.launcher arrays\r
-namespaces continuations layouts accessors io.encodings.ascii\r
-urls math.parser ;\r
+tools.deploy.config.editor tools.deploy.backend math sequences\r
+io.launcher arrays namespaces continuations layouts accessors\r
+io.encodings.ascii urls math.parser ;\r
 \r
 : shake-and-bake ( vocab -- )\r
     [ "test.image" temp-file delete-file ] ignore-errors\r
@@ -31,6 +31,10 @@ urls math.parser ;
 \r
 [ t ] [ "bunny" shake-and-bake 2500000 small-enough? ] unit-test\r
 \r
+os macosx? [\r
+    [ t ] [ "webkit-demo" shake-and-bake 500000 small-enough? ] unit-test\r
+] when\r
+\r
 : run-temp-image ( -- )\r
     vm\r
     "-i=" "test.image" temp-file append\r
index d3464993e162309dbb3626bca47461ae20c49758..1f0e4824414f756134eb1cae2549a0a276c6ff10 100644 (file)
@@ -1,10 +1,11 @@
 ! Copyright (C) 2007, 2008 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: io io.files kernel namespaces make sequences
-system tools.deploy.backend tools.deploy.config assocs
-hashtables prettyprint io.unix.backend cocoa io.encodings.utf8
-io.backend cocoa.application cocoa.classes cocoa.plists
-qualified combinators ;
+USING: io io.files kernel namespaces make sequences system
+tools.deploy.backend tools.deploy.config
+tools.deploy.config.editor assocs hashtables prettyprint
+io.unix.backend cocoa io.encodings.utf8 io.backend
+cocoa.application cocoa.classes cocoa.plists qualified
+combinators ;
 IN: tools.deploy.macosx
 
 : bundle-dir ( -- dir )
index 15fd2a37d792588c06adda429643746d291f7481..3d4944841d2ee642683f65db27c287d13aa21965 100755 (executable)
@@ -1,11 +1,11 @@
 ! Copyright (C) 2007, 2008 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
 USING: accessors qualified io.backend io.streams.c init fry
-namespaces make assocs kernel parser lexer strings.parser
-tools.deploy.config vocabs sequences words words.private memory
-kernel.private continuations io prettyprint vocabs.loader
-debugger system strings sets vectors quotations byte-arrays
-sorting compiler.units definitions generic generic.standard ;
+namespaces make assocs kernel parser lexer strings.parser vocabs
+sequences words words.private memory kernel.private
+continuations io vocabs.loader system strings sets
+vectors quotations byte-arrays sorting compiler.units
+definitions generic generic.standard tools.deploy.config ;
 QUALIFIED: bootstrap.stage2
 QUALIFIED: classes
 QUALIFIED: command-line
@@ -14,7 +14,6 @@ QUALIFIED: continuations
 QUALIFIED: definitions
 QUALIFIED: init
 QUALIFIED: layouts
-QUALIFIED: prettyprint.config
 QUALIFIED: source-files
 QUALIFIED: vocabs
 IN: tools.deploy.shaker
@@ -41,7 +40,7 @@ IN: tools.deploy.shaker
     ] when ;
 
 : strip-debugger ( -- )
-    strip-debugger? [
+    strip-debugger? "debugger" vocab and [
         "Stripping debugger" show
         "resource:basis/tools/deploy/shaker/strip-debugger.factor"
         run-file
@@ -81,14 +80,11 @@ IN: tools.deploy.shaker
                 >alist f like
             ] change-props drop
         ] each
-    ] [
-        "Remaining word properties:\n" show
-        [ props>> keys ] gather unparse show
     ] [
         H{ } clone '[
             [ [ _ [ ] cache ] map ] change-props drop
         ] each
-    ] tri ;
+    ] bi ;
 
 : stripped-word-props ( -- seq )
     [
@@ -189,6 +185,19 @@ IN: tools.deploy.shaker
     strip-word-names? [ dup strip-word-names ] when
     2drop ;
 
+: strip-default-methods ( -- )
+    strip-debugger? [
+        "Stripping default methods" show
+        [
+            [ generic? ] instances
+            [ "No method" throw ] define-temp
+            dup t "default" set-word-prop
+            '[
+                [ _ "default-method" set-word-prop ] [ make-generic ] bi
+            ] each
+        ] with-compilation-unit
+    ] when ;
+
 : strip-vocab-globals ( except names -- words )
     [ child-vocabs [ words ] map concat ] map concat swap diff ;
 
@@ -275,12 +284,7 @@ IN: tools.deploy.shaker
         ] when
 
         strip-prettyprint? [
-            {
-                prettyprint.config:margin
-                prettyprint.config:string-limit?
-                prettyprint.config:boa-tuples?
-                prettyprint.config:tab-size
-            } %
+            { } { "prettyprint.config" } strip-vocab-globals %
         ] when
 
         strip-debugger? [
@@ -308,7 +312,6 @@ IN: tools.deploy.shaker
         '[ drop _ member? not ] assoc-filter
         [ drop string? not ] assoc-filter ! strip CLI args
         sift-assoc
-        dup keys unparse show
         21 setenv
     ] [ drop ] if ;
 
@@ -362,7 +365,7 @@ SYMBOL: deploy-vocab
         init-hooks get values concat %
         ,
         strip-io? [ \ flush , ] unless
-    ] [ ] make "Boot quotation: " show dup unparse show
+    ] [ ] make
     set-boot-quot ;
 
 : init-stripper ( -- )
@@ -380,6 +383,7 @@ SYMBOL: deploy-vocab
 
 : strip ( -- )
     init-stripper
+    strip-default-methods
     strip-libc
     strip-cocoa
     strip-debugger
@@ -390,11 +394,11 @@ SYMBOL: deploy-vocab
     deploy-vocab get vocab-main set-boot-quot*
     stripped-word-props
     stripped-globals strip-globals
-    strip-words
     compress-byte-arrays
     compress-quotations
     compress-strings
-    compress-wrappers ;
+    compress-wrappers
+    strip-words ;
 
 : (deploy) ( final-image vocab config -- )
     #! Does the actual work of a deployment in the slave
@@ -405,16 +409,14 @@ SYMBOL: deploy-vocab
             deploy-vocab get require
             strip
             finish-deploy
-        ] [
-            print-error flush 1 exit
-        ] recover
+        ] [ error-continuation get call>> callstack>array die 1 exit ] recover
     ] bind ;
 
 : do-deploy ( -- )
     "output-image" get
     "deploy-vocab" get
     "Deploying " write dup write "..." print
-    dup deploy-config dup .
+    "deploy-config" get parse-file first
     (deploy) ;
 
 MAIN: do-deploy
index d5249dc20c076cd165d01739bb82c742a80e9bb1..773b2d0f3b5bae9ec439a536b0ea538a3bcf8013 100644 (file)
@@ -25,11 +25,6 @@ H{ } clone \ pool [
     global [
         "stop-after-last-window?" "ui" lookup set
 
-        "ui.cocoa" vocab [
-            [ "MiniFactor.nib" load-nib ]
-            "cocoa-init-hook" "ui.cocoa" lookup set-global
-        ] when
-
         ! Only keeps those methods that we actually call
         sent-messages get super-sent-messages get assoc-union
         objc-methods [ assoc-intersect pool-values ] change
index 5e1d0be7fb5a9471b6112422b134f9069c0810cd..bd49155e8442f4d7d48f33aeae815a54e0d06647 100644 (file)
@@ -1,8 +1,8 @@
 ! Copyright (C) 2008 James Cash
 ! See http://factorcode.org/license.txt for BSD license.
 USING: io io.files io.backend kernel namespaces make sequences
-system tools.deploy.backend tools.deploy.config assocs
-hashtables prettyprint ;
+system tools.deploy.backend tools.deploy.config
+tools.deploy.config.editor assocs hashtables prettyprint ;
 IN: tools.deploy.unix
 
 : create-app-dir ( vocab bundle-name -- vm )
index ec1259c777775ad54d2c0d81d42291b782e5ecac..6188e78b0eb37e410c58841fa6d7b6a806044523 100755 (executable)
@@ -1,8 +1,9 @@
 ! Copyright (C) 2007, 2008 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
 USING: io io.files kernel namespaces sequences system
-tools.deploy.backend tools.deploy.config assocs hashtables
-prettyprint combinators windows.shell32 windows.user32 ;
+tools.deploy.backend tools.deploy.config
+tools.deploy.config.editor assocs hashtables prettyprint
+combinators windows.shell32 windows.user32 ;
 IN: tools.deploy.windows
 
 : copy-dll ( bundle-name -- )
index 782f244c6874d9560755f5b0787461a45dc6738a..96f5a043788c83f6113bfeddbb347c513aabf709 100644 (file)
@@ -1,6 +1,6 @@
 IN: tools.disassembler.tests\r
-USING: math classes.tuple prettyprint.backend tools.disassembler\r
-tools.test strings ;\r
+USING: math classes.tuple prettyprint.custom \r
+tools.disassembler tools.test strings ;\r
 \r
 [ ] [ \ + disassemble ] unit-test\r
 [ ] [ { string pprint* } disassemble ] unit-test\r
index 6aa68d81270c9f84d9b9bfbf21a70a9b3ca46b99..6cbc7d192c5898c7cae4a5069810515797ce4dc0 100644 (file)
@@ -6,3 +6,5 @@ IN: tools.files.tests
 \ directory. must-infer
 
 [ ] [ "" directory. ] unit-test
+
+[ ] [ file-systems. ] unit-test
index 18baedae0a98200ccce9428a85ff006a05b36eff..b4295af2050b08ee28cfdc237f751b441f7084db 100755 (executable)
@@ -44,12 +44,13 @@ percent-used percent-free ;
         { device-name [ device-name>> ] }
         { mount-point [ mount-point>> ] }
         { type [ type>> ] }
-        { available-space [ available-space>> ] }
-        { free-space [ free-space>> ] }
-        { used-space [ used-space>> ] }
-        { total-space [ total-space>> ] }
+        { available-space [ available-space>> [ 0 ] unless* ] }
+        { free-space [ free-space>> [ 0 ] unless* ] }
+        { used-space [ used-space>> [ 0 ] unless* ] }
+        { total-space [ total-space>> [ 0 ] unless* ] }
         { percent-used [
-            [ used-space>> ] [ total-space>> ] bi dup 0 =
+            [ used-space>> ] [ total-space>> ] bi
+            [ [ 0 ] unless* ] bi@ dup 0 =
             [ 2drop 0 ] [ / percent ] if
         ] }
     } case ;
@@ -57,13 +58,15 @@ percent-used percent-free ;
 : file-systems-info ( spec -- seq )
     file-systems swap '[ _ [ file-system-spec ] with map ] map ;
 
-: file-systems. ( spec -- )
+: print-file-systems ( spec -- )
     [ file-systems-info ]
     [ [ unparse ] map ] bi prefix simple-table. ;
 
+: file-systems. ( -- )
+    { device-name free-space used-space total-space percent-used mount-point }
+    print-file-systems ;
+
 {
     { [ os unix? ] [ "tools.files.unix" ] }
     { [ os windows? ] [ "tools.files.windows" ] }
 } cond require
-
-! { device-name free-space used-space total-space percent-used } file-systems.
index 8c35ae25a84e506eae48ace6e116d0340b99a290..2ad16a4d8d6d34cff4886ff4e64c133b4a81e638 100644 (file)
@@ -53,7 +53,7 @@ IN: tools.memory
 
 : heap-stat-step ( obj counts sizes -- )
     [ over ] dip
-    [ [ [ drop 1 ] [ class ] bi ] dip at+ ]
+    [ [ class ] dip inc-at ]
     [ [ [ size ] [ class ] bi ] dip at+ ] 2bi* ;
 
 PRIVATE>
index 953291cc59d75ebc8871b0aca519a83298bcf80d..8915d2d611bb19b3690b7248dd530fa80652b60d 100644 (file)
@@ -4,7 +4,7 @@ USING: threads kernel namespaces continuations combinators
 sequences math namespaces.private continuations.private
 concurrency.messaging quotations kernel.private words
 sequences.private assocs models models.filter arrays accessors
-generic generic.standard definitions make ;
+generic generic.standard definitions make sbufs ;
 IN: tools.walker
 
 SYMBOL: show-walker-hook ! ( status continuation thread -- )
@@ -147,6 +147,7 @@ SYMBOL: +stopped+
     { (call-next-method) [ (step-into-call-next-method) ] }
 } [ "step-into" set-word-prop ] assoc-each
 
+! Never step into these words
 {
     >n ndrop >c c>
     continue continue-with
@@ -236,7 +237,7 @@ SYMBOL: +stopped+
 
 : walker-loop ( -- )
     +running+ set-status
-    [ status +stopped+ eq? not ] [
+    [ status +stopped+ eq? ] [
         [
             {
                 ! ignore these commands while the thread is
@@ -255,7 +256,7 @@ SYMBOL: +stopped+
                 [ walker-suspended ]
             } case
         ] handle-synchronous
-    ] [ ] while ;
+    ] [ ] until ;
 
 : associate-thread ( walker -- )
     walker-thread tset
old mode 100644 (file)
new mode 100755 (executable)
index 6e19f3f..1338983
@@ -3,7 +3,7 @@
 USING: accessors math arrays assocs cocoa cocoa.application
 command-line kernel memory namespaces cocoa.messages
 cocoa.runtime cocoa.subclassing cocoa.pasteboard cocoa.types
-cocoa.windows cocoa.classes cocoa.application sequences system
+cocoa.windows cocoa.classes sequences system
 ui ui.backend ui.clipboards ui.gadgets ui.gadgets.worlds
 ui.cocoa.views core-foundation threads math.geometry.rect fry
 libc generalizations alien.c-types cocoa.views combinators ;
@@ -143,7 +143,9 @@ CLASS: {
 
 SYMBOL: cocoa-init-hook
 
-cocoa-init-hook global [ [ install-app-delegate ] or ] change-at
+cocoa-init-hook global [
+    [ "MiniFactor.nib" load-nib install-app-delegate ] or
+] change-at
 
 M: cocoa-ui-backend ui
     "UI" assert.app [
index 6c0eaaa9ac4839e107050c582d7ef22004c02552..22a4f1722db1f3f5a8ab6c89d854b668c1a48bf1 100644 (file)
@@ -1,7 +1,7 @@
 ! Copyright (C) 2005, 2008 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
 USING: alien alien.accessors alien.c-types arrays io kernel libc
-math math.vectors namespaces opengl opengl.gl prettyprint assocs
+math math.vectors namespaces opengl opengl.gl assocs
 sequences io.files io.styles continuations freetype
 ui.gadgets.worlds ui.render ui.backend byte-arrays accessors
 locals specialized-arrays.direct.uchar ;
index 108c5ae461d1b3a25c38647383f02f96eb5fa4ed..636e25cea5967bbdd18dcbef55cdced281784efa 100644 (file)
@@ -3,7 +3,7 @@
 USING: arrays ui.gadgets.buttons ui.gadgets.borders
 ui.gadgets.labels ui.gadgets.panes ui.gadgets.scrollers
 ui.gadgets.tracks ui.gadgets.theme ui.gadgets.frames
-ui.gadgets.grids io kernel math models namespaces prettyprint
+ui.gadgets.grids io kernel math models namespaces
 sequences sequences words classes.tuple ui.gadgets ui.render
 colors accessors ;
 IN: ui.gadgets.labelled
index 33ef3bbe3afbbc007feef35d98557987fdfe5a27..61a55e926bb44e5525b9e2ae2e5ebb41f8c00749 100644 (file)
@@ -1,7 +1,7 @@
 ! Copyright (C) 2005, 2008 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
 USING: arrays accessors definitions hashtables io kernel
-prettyprint sequences strings io.styles words help math models
+sequences strings io.styles words help math models
 namespaces quotations
 ui.gadgets ui.gadgets.borders ui.gadgets.buttons
 ui.gadgets.labels ui.gadgets.menus ui.gadgets.worlds
index d442e16ac4fe75efab545c72cffa9fff1741c77c..9290af1f6426b012bc77d4a23f4888a60e97342e 100644 (file)
@@ -3,7 +3,7 @@
 USING: accessors arrays assocs continuations kernel math models
 namespaces opengl sequences io combinators fry math.vectors
 ui.gadgets ui.gestures ui.render ui.backend ui.gadgets.tracks
-debugger math.geometry.rect ;
+math.geometry.rect ;
 IN: ui.gadgets.worlds
 
 TUPLE: world < track
@@ -83,7 +83,7 @@ C: <world-error> world-error
 SYMBOL: ui-error-hook
 
 : ui-error ( error -- )
-    ui-error-hook get [ call ] [ print-error ] if* ;
+    ui-error-hook get [ call ] [ die ] if* ;
 
 ui-error-hook global [ [ rethrow ] or ] change-at
 
index f023b0959ab703fd88547d5e42b807a6ad6ec8c5..f233c9f162891882de8588405fb2804ce2790325 100644 (file)
@@ -1,11 +1,11 @@
-! Copyright (C) 2007 Slava Pestov.
+! Copyright (C) 2007, 2008 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
 USING: ui.gadgets colors kernel ui.render namespaces models
 models.mapping sequences ui.gadgets.buttons ui.gadgets.packs
-ui.gadgets.labels tools.deploy.config namespaces
-ui.gadgets.editors ui.gadgets.borders ui.gestures ui.commands
-assocs ui.gadgets.tracks ui ui.tools.listener tools.deploy
-vocabs ui.tools.workspace system accessors fry ;
+ui.gadgets.labels tools.deploy.config tools.deploy.config.editor
+namespaces ui.gadgets.editors ui.gadgets.borders ui.gestures
+ui.commands assocs ui.gadgets.tracks ui ui.tools.listener
+tools.deploy vocabs ui.tools.workspace system accessors fry ;
 IN: ui.tools.deploy
 
 TUPLE: deploy-gadget < pack vocab settings ;
index cf2a6574395b0929bd106470e5220a77bbf92af9..e3401cdb332bf340fd1284532030fb22bfb6d3cc 100644 (file)
@@ -1,10 +1,10 @@
 ! Copyright (C) 2006, 2008 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
 USING: arrays assocs io kernel math models namespaces make
-prettyprint dlists deques sequences threads sequences words
-debugger ui.gadgets ui.gadgets.worlds ui.gadgets.tracks
-ui.gestures ui.backend ui.render continuations init combinators
-hashtables concurrency.flags sets accessors calendar ;
+dlists deques sequences threads sequences words ui.gadgets
+ui.gadgets.worlds ui.gadgets.tracks ui.gestures ui.backend
+ui.render continuations init combinators hashtables
+concurrency.flags sets accessors calendar ;
 IN: ui
 
 ! Assoc mapping aliens to gadgets
index e696c3fa6f74a00948becc3445f65d4797cf8f1c..ab895c10dd442ba68b070458f1ae94254ab8cc50 100755 (executable)
@@ -9,7 +9,8 @@ windows.user32 windows.opengl32 windows.messages windows.types
 windows.nt windows threads libc combinators
 combinators.short-circuit continuations command-line shuffle
 opengl ui.render ascii math.bitwise locals symbols accessors
-math.geometry.rect math.order ascii calendar ;
+math.geometry.rect math.order ascii calendar
+io.encodings.utf16n ;
 IN: ui.windows
 
 SINGLETON: windows-ui-backend
index 6d6243449b68f67e519a2c92a9f73e68e98cdf24..e5a3a8306b6572f4c10c6a17e0c0ee216e17a9a4 100755 (executable)
@@ -5,7 +5,7 @@ ui.gestures ui.backend ui.clipboards ui.gadgets.worlds ui.render
 assocs kernel math namespaces opengl sequences strings x11.xlib
 x11.events x11.xim x11.glx x11.clipboard x11.constants
 x11.windows io.encodings.string io.encodings.ascii
-io.encodings.utf8 combinators debugger command-line qualified
+io.encodings.utf8 combinators command-line qualified
 math.vectors classes.tuple opengl.gl threads math.geometry.rect
 environment ascii ;
 IN: ui.x11
index bf4610ab0da69b5e161f87234137c65d70f69051..b7ac022d0e1cc7cc49261d3a7340ff5a3ec40caf 100644 (file)
@@ -2,7 +2,7 @@
 ! See http://factorcode.org/license.txt for BSD license.
 USING: unicode.data kernel math sequences parser lexer
 bit-arrays namespaces make sequences.private arrays quotations
-assocs classes.predicate math.order eval ;
+assocs classes.predicate math.order strings.parser ;
 IN: unicode.syntax
 
 ! Character classes (categories)
@@ -26,7 +26,7 @@ IN: unicode.syntax
     categories [ swap member? ] with map >bit-array ;
 
 : as-string ( strings -- bit-array )
-    concat "\"" tuck 3append eval ;
+    concat unescape-string ;
 
 : [category] ( categories -- quot )
     [
diff --git a/basis/unix/debugger/debugger.factor b/basis/unix/debugger/debugger.factor
new file mode 100644 (file)
index 0000000..ea32657
--- /dev/null
@@ -0,0 +1,18 @@
+! Copyright (C) 2008 Slava Pestov.
+! See http://factorcode.org/license.txt for BSD license.
+USING: debugger prettyprint accessors unix io kernel ;
+IN: unix.debugger
+
+M: unix-error error.
+    "Unix system call failed:" print
+    nl
+    dup message>> write " (" write errno>> pprint ")" print ;
+
+M: unix-system-call-error error.
+    "Unix system call ``" write dup word>> pprint "'' failed:" print
+    nl
+    dup message>> write " (" write dup errno>> pprint ")" print
+    nl
+    "It was called with the following arguments:" print
+    nl
+    args>> stack. ;
diff --git a/basis/unix/debugger/tags.txt b/basis/unix/debugger/tags.txt
new file mode 100644 (file)
index 0000000..6bf6830
--- /dev/null
@@ -0,0 +1 @@
+unportable
index 83c3bb5232c50cdbb76b3c3a61daf30baf670601..d7623df8be0954b85446de497a84fb144f04101e 100644 (file)
@@ -1,6 +1,7 @@
 ! Copyright (C) 2008 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: alien.syntax system sequences vocabs.loader words ;
+USING: alien.syntax system sequences vocabs.loader words
+accessors ;
 IN: unix.kqueue
 
 << "unix.kqueue." os name>> append require >>
index c18fa2ee6ce68de3ec0e49d32aef5515f52a1429..72935807c320c5e52747fa32912c9ac55156607a 100644 (file)
@@ -18,14 +18,15 @@ FUNCTION: int epoll_wait ( int epfd, epoll_event* events, int maxevents, int tim
 : EPOLL_CTL_DEL 2 ; inline ! Remove a file decriptor from the interface.
 : EPOLL_CTL_MOD 3 ; inline ! Change file decriptor epoll_event structure.
 
-: EPOLLIN     HEX: 001 ; inline
-: EPOLLPRI    HEX: 002 ; inline
-: EPOLLOUT    HEX: 004 ; inline
-: EPOLLRDNORM HEX: 040 ; inline
-: EPOLLRDBAND HEX: 080 ; inline
-: EPOLLWRNORM HEX: 100 ; inline
-: EPOLLWRBAND HEX: 200 ; inline
-: EPOLLMSG    HEX: 400 ; inline
-: EPOLLERR    HEX: 008 ; inline
-: EPOLLHUP    HEX: 010 ; inline
-: EPOLLET     31 2^    ; inline
+: EPOLLIN      HEX: 001 ; inline
+: EPOLLPRI     HEX: 002 ; inline
+: EPOLLOUT     HEX: 004 ; inline
+: EPOLLRDNORM  HEX: 040 ; inline
+: EPOLLRDBAND  HEX: 080 ; inline
+: EPOLLWRNORM  HEX: 100 ; inline
+: EPOLLWRBAND  HEX: 200 ; inline
+: EPOLLMSG     HEX: 400 ; inline
+: EPOLLERR     HEX: 008 ; inline
+: EPOLLHUP     HEX: 010 ; inline
+: EPOLLONESHOT 30 2^    ; inline
+: EPOLLET      31 2^    ; inline
index d917425bf9cebb415042811d3e9fcc7d000e5a2b..555f8e2c7da552c2cd79a53653b3bf1e30de8ea8 100644 (file)
@@ -1,10 +1,10 @@
-! Copyright (C) 2005, 2007 Slava Pestov.
+! Copyright (C) 2005, 2008 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
 USING: alien alien.c-types alien.syntax kernel libc
 sequences continuations byte-arrays strings math namespaces
 system combinators vocabs.loader qualified accessors
 stack-checker macros locals generalizations unix.types
-debugger io prettyprint io.files ;
+io io.files vocabs vocabs.loader ;
 IN: unix
 
 : PROT_NONE   0 ; inline
@@ -60,26 +60,12 @@ FUNCTION: char* strerror ( int errno ) ;
 
 ERROR: unix-error errno message ;
 
-M: unix-error error.
-    "Unix system call failed:" print
-    nl
-    dup message>> write " (" write errno>> pprint ")" print ;
-
 : (io-error) ( -- * ) err_no dup strerror unix-error ;
 
 : io-error ( n -- ) 0 < [ (io-error) ] when ;
 
 ERROR: unix-system-call-error args errno message word ;
 
-M: unix-system-call-error error.
-    "Unix system call ``" write dup word>> pprint "'' failed:" print
-    nl
-    dup message>> write " (" write dup errno>> pprint ")" print
-    nl
-    "It was called with the following arguments:" print
-    nl
-    args>> stack. ;
-
 MACRO:: unix-system-call ( quot -- )
     [let | n [ quot infer in>> ]
            word [ quot first ] |
@@ -236,3 +222,7 @@ FUNCTION: ssize_t write ( int fd, void* buf, size_t nbytes ) ;
     { [ os bsd? ] [ "unix.bsd" require ] }
     { [ os solaris? ] [ "unix.solaris" require ] }
 } cond
+
+"debugger" vocab [
+    "unix.debugger" require
+] when
diff --git a/basis/urls/prettyprint/prettyprint.factor b/basis/urls/prettyprint/prettyprint.factor
new file mode 100644 (file)
index 0000000..59fb79e
--- /dev/null
@@ -0,0 +1,6 @@
+! Copyright (C) 2008 Slava Pestov.
+! See http://factorcode.org/license.txt for BSD license.
+USING: kernel present prettyprint.custom prettyprint.backend urls ;
+IN: urls.prettyprint
+
+M: url pprint* dup present "URL\" " "\"" pprint-string ;
index c0fb1695c3358603e6abbd3fa1bcdb5a32358a81..d71ce4ef7b992a3791f76975e8fe4edee36c67ba 100644 (file)
@@ -2,10 +2,9 @@
 ! See http://factorcode.org/license.txt for BSD license.
 USING: kernel ascii combinators combinators.short-circuit
 sequences splitting fry namespaces make assocs arrays strings
-io.sockets io.encodings.string
-io.encodings.utf8 math math.parser accessors parser
-strings.parser lexer prettyprint.backend hashtables present
-peg.ebnf urls.encoding ;
+io.sockets io.encodings.string io.encodings.utf8 math
+math.parser accessors parser strings.parser lexer
+hashtables present peg.ebnf urls.encoding ;
 IN: urls
 
 TUPLE: url protocol username password host port path query anchor ;
@@ -182,4 +181,8 @@ PRIVATE>
 ! Literal syntax
 : URL" lexer get skip-blank parse-string >url parsed ; parsing
 
-M: url pprint* dup present "URL\" " "\"" pprint-string ;
+USING: vocabs vocabs.loader ;
+
+"prettyprint" vocab [
+    "urls.prettyprint" require
+] when
index e0f7e555541e28bfd87e40afedc64a095c44978d..ea40594964760773e50c6efe0ccb165abd5d80f8 100644 (file)
@@ -2,7 +2,7 @@
 ! See http://factorcode.org/license.txt for BSD license.
 USING: arrays accessors sequences sequences.private
 persistent.sequences assocs persistent.assocs kernel math
-vectors parser prettyprint.backend ;
+vectors parser prettyprint.custom ;
 IN: vlists
 
 TUPLE: vlist
index b071bee72a4898c8b452e4e6ae0c627974c49e78..eae796ac0876e3fe769c47e5c5ddffddc0758c21 100644 (file)
@@ -1,6 +1,6 @@
 USING: alien alien.c-types alien.strings alien.syntax combinators
 kernel windows windows.user32 windows.ole32
-windows.com windows.com.syntax io.files ;
+windows.com windows.com.syntax io.files io.encodings.utf16n ;
 IN: windows.shell32
 
 : CSIDL_DESKTOP HEX: 00 ; inline
index 2fc1dbf12207a86d857c20c27046d94a93f01b62..d2250d6f7e06024ad0135600fa08657565b4d597 100644 (file)
@@ -2,7 +2,8 @@
 ! See http://factorcode.org/license.txt for BSD license.
 USING: alien alien.syntax alien.c-types alien.strings arrays
 combinators kernel math namespaces parser prettyprint sequences
-windows.errors windows.types windows.kernel32 words ;
+windows.errors windows.types windows.kernel32 words
+io.encodings.utf16n ;
 IN: windows
 
 : lo-word ( wparam -- lo ) <short> *short ; inline
index 4ca07ce85088e19baef7fc23ac68085f15c8ec97..5d450897e22120d14379ba442a478314f0c11954 100644 (file)
@@ -2,7 +2,7 @@
 ! See http://factorcode.org/license.txt for BSD license.
 USING: alien alien.c-types alien.strings alien.syntax arrays
 byte-arrays kernel math sequences windows.types windows.kernel32
-windows.errors windows math.bitwise alias ;
+windows.errors windows math.bitwise alias io.encodings.utf16n ;
 IN: windows.winsock
 
 USE: libc
index 71b0b5f13378a90ea8c55741ed954b598e2aba99..862ec3355a18243c83ad934146ee880fb42927b1 100644 (file)
@@ -3,7 +3,7 @@
 USING: alien alien.c-types alien.strings arrays byte-arrays
 hashtables io io.encodings.string kernel math namespaces
 sequences strings continuations x11.xlib specialized-arrays.uint
-accessors ;
+accessors io.encodings.utf16n ;
 IN: x11.xim
 
 SYMBOL: xim
index b02e0189b2f2d2c792880e05ec6b02a110f7fce0..2f486cd948786180506a079eda810bb2a12c0a8c 100644 (file)
@@ -90,6 +90,7 @@ ARTICLE: "assocs-mutation" "Storing keys and values in assocs"
 { $subsection rename-at }
 { $subsection change-at }
 { $subsection at+ }
+{ $subsection inc-at }
 { $see-also set-at delete-at clear-assoc push-at } ;
 
 ARTICLE: "assocs-conversions" "Associative mapping conversions"
@@ -214,7 +215,7 @@ HELP: assoc-map
 { $examples
     { $unchecked-example
         ": discount ( prices n -- newprices )"
-        "    [ - ] curry assoc-each ;"
+        "    [ - ] curry assoc-map ;"
         "H{ { \"bananas\" 5 } { \"apples\" 42 } { \"pears\" 17 } }"
         "2 discount ."
         "H{ { \"bananas\" 3 } { \"apples\" 39 } { \"pears\" 15 } }"
@@ -349,6 +350,11 @@ HELP: at+
 { $description "Adds " { $snippet "n" } " to the value associated with " { $snippet "key" } "; if there is no value, stores " { $snippet "n" } ", thus behaving as if the value was 0." }
 { $side-effects "assoc" } ;
 
+HELP: inc-at
+{ $values { "key" object } { "assoc" assoc } }
+{ $description "Adds 1 to the value associated with " { $snippet "key" } "; if there is no value, stores 1." }
+{ $side-effects "assoc" } ;
+
 HELP: >alist
 { $values { "assoc" assoc } { "newassoc" "an array of key/value pairs" } }
 { $contract "Converts an associative structure into an association list." }
index 76745cc0151f99055c778d87e5861ddf2f85be4e..320e370ec980bad11cc5363e10104cdcc05d70e3 100644 (file)
@@ -141,8 +141,9 @@ M: assoc assoc-clone-like ( assoc exemplar -- newassoc )
 : change-at ( key assoc quot -- )
     [ [ at ] dip call ] 3keep drop set-at ; inline
 
-: at+ ( n key assoc -- )
-    [ 0 or + ] change-at ;
+: at+ ( n key assoc -- ) [ 0 or + ] change-at ; inline
+
+: inc-at ( key assoc -- ) [ 1 ] 2dip at+ ; inline
 
 : map>assoc ( seq quot exemplar -- assoc )
     [ [ 2array ] compose { } map-as ] dip assoc-like ; inline
index f90ba23999994607ae6bcac9ff3f38af23ed512f..6cc97531a4a790db5efb4eb24d289feaed8d37b6 100644 (file)
@@ -68,7 +68,6 @@ bootstrapping? on
     "alien.accessors"
     "arrays"
     "byte-arrays"
-    "byte-vectors"
     "classes.private"
     "classes.tuple"
     "classes.tuple.private"
@@ -190,7 +189,7 @@ define-union-class
 define-predicate-class
 
 "array-capacity" "sequences.private" lookup
-[ >fixnum ] bootstrap-max-array-capacity [ fixnum-bitand ] curry append
+[ >fixnum ] bootstrap-max-array-capacity <fake-bignum> [ fixnum-bitand ] curry append
 "coercer" set-word-prop
 
 ! Catch-all class for providing a default method.
@@ -469,6 +468,7 @@ tuple
     { "dlsym" "alien" }
     { "dlclose" "alien" }
     { "<byte-array>" "byte-arrays" }
+    { "(byte-array)" "byte-arrays" }
     { "<displaced-alien>" "alien" }
     { "alien-signed-cell" "alien.accessors" }
     { "set-alien-signed-cell" "alien.accessors" }
index 26a27ecefb76fc465a28334cb7478f2f87effaad..874a9dd0d215dd418ebc04263b125ed981d29c64 100644 (file)
@@ -31,7 +31,7 @@ load-help? off
     "math.integers" require
     "math.floats" require
     "memory" require
-
+    
     "io.streams.c" require
     "vocabs.loader" require
     
index e7dd333ed8e90e03592d5c520d5237904b0fb963..badc1f5218165ab1686ad9b8f7883e07f06c043f 100644 (file)
@@ -16,7 +16,6 @@ IN: bootstrap.syntax
     "<PRIVATE"
     "BIN:"
     "B{"
-    "BV{"
     "C:"
     "CHAR:"
     "DEFER:"
index f981e758d79e3bd3c76613a74405033c9df3ca8b..f0d188ce4a705855a356eb3b07c3e332a55e090a 100644 (file)
@@ -9,7 +9,7 @@ M: byte-array length length>> ;
 M: byte-array nth-unsafe swap >fixnum alien-unsigned-1 ;
 M: byte-array set-nth-unsafe swap >fixnum set-alien-unsigned-1 ;
 : >byte-array ( seq -- byte-array ) B{ } clone-like ; inline
-M: byte-array new-sequence drop <byte-array> ;
+M: byte-array new-sequence drop (byte-array) ;
 
 M: byte-array equal?
     over byte-array? [ sequence= ] [ 2drop f ] if ;
diff --git a/core/byte-vectors/byte-vectors-docs.factor b/core/byte-vectors/byte-vectors-docs.factor
deleted file mode 100644 (file)
index 3873f73..0000000
+++ /dev/null
@@ -1,37 +0,0 @@
-USING: arrays byte-arrays help.markup help.syntax kernel\r
-byte-vectors.private combinators ;\r
-IN: byte-vectors\r
-\r
-ARTICLE: "byte-vectors" "Byte vectors"\r
-"A byte vector is a resizable mutable sequence of unsigned bytes. Byte vector words are found in the " { $vocab-link "byte-vectors" } " vocabulary."\r
-$nl\r
-"Byte vectors form a class:"\r
-{ $subsection byte-vector }\r
-{ $subsection byte-vector? }\r
-"Creating byte vectors:"\r
-{ $subsection >byte-vector }\r
-{ $subsection <byte-vector> }\r
-"Literal syntax:"\r
-{ $subsection POSTPONE: BV{ }\r
-"If you don't care about initial capacity, a more elegant way to create a new byte vector is to write:"\r
-{ $code "BV{ } clone" } ;\r
-\r
-ABOUT: "byte-vectors"\r
-\r
-HELP: byte-vector\r
-{ $description "The class of resizable byte vectors. See " { $link "byte-vectors" } " for information." } ;\r
-\r
-HELP: <byte-vector>\r
-{ $values { "n" "a positive integer specifying initial capacity" } { "byte-vector" byte-vector } }\r
-{ $description "Creates a new byte vector that can hold " { $snippet "n" } " bytes before resizing." } ;\r
-\r
-HELP: >byte-vector\r
-{ $values { "seq" "a sequence" } { "byte-vector" byte-vector } }\r
-{ $description "Outputs a freshly-allocated byte vector with the same elements as a given sequence." }\r
-{ $errors "Throws an error if the sequence contains elements other than integers." } ;\r
-\r
-HELP: BV{\r
-{ $syntax "BV{ elements... }" }\r
-{ $values { "elements" "a list of bytes" } }\r
-{ $description "Marks the beginning of a literal byte vector. Literal byte vectors are terminated by " { $link POSTPONE: } } "." } \r
-{ $examples { $code "BV{ 1 2 3 12 }" } } ;\r
diff --git a/core/byte-vectors/byte-vectors-tests.factor b/core/byte-vectors/byte-vectors-tests.factor
deleted file mode 100644 (file)
index 9a100d9..0000000
+++ /dev/null
@@ -1,17 +0,0 @@
-IN: byte-vectors.tests\r
-USING: tools.test byte-vectors vectors sequences kernel\r
-prettyprint ;\r
-\r
-[ 0 ] [ 123 <byte-vector> length ] unit-test\r
-\r
-: do-it\r
-    123 [ over push ] each ;\r
-\r
-[ t ] [\r
-    3 <byte-vector> do-it\r
-    3 <vector> do-it sequence=\r
-] unit-test\r
-\r
-[ t ] [ BV{ } byte-vector? ] unit-test\r
-\r
-[ "BV{ }" ] [ BV{ } unparse ] unit-test\r
diff --git a/core/byte-vectors/byte-vectors.factor b/core/byte-vectors/byte-vectors.factor
deleted file mode 100644 (file)
index 6938d02..0000000
+++ /dev/null
@@ -1,44 +0,0 @@
-! Copyright (C) 2008 Slava Pestov.\r
-! See http://factorcode.org/license.txt for BSD license.\r
-USING: arrays kernel kernel.private math sequences\r
-sequences.private growable byte-arrays accessors ;\r
-IN: byte-vectors\r
-\r
-TUPLE: byte-vector\r
-{ underlying byte-array }\r
-{ length array-capacity } ;\r
-\r
-: <byte-vector> ( n -- byte-vector )\r
-    <byte-array> 0 byte-vector boa ; inline\r
-\r
-: >byte-vector ( seq -- byte-vector )\r
-    T{ byte-vector f B{ } 0 } clone-like ;\r
-\r
-M: byte-vector like\r
-    drop dup byte-vector? [\r
-        dup byte-array?\r
-        [ dup length byte-vector boa ] [ >byte-vector ] if\r
-    ] unless ;\r
-\r
-M: byte-vector new-sequence\r
-    drop [ <byte-array> ] [ >fixnum ] bi byte-vector boa ;\r
-\r
-M: byte-vector equal?\r
-    over byte-vector? [ sequence= ] [ 2drop f ] if ;\r
-\r
-M: byte-array like\r
-    #! If we have an byte-array, we're done.\r
-    #! If we have a byte-vector, and it's at full capacity,\r
-    #! we're done. Otherwise, call resize-byte-array, which is a\r
-    #! relatively fast primitive.\r
-    drop dup byte-array? [\r
-        dup byte-vector? [\r
-            [ length ] [ underlying>> ] bi\r
-            2dup length eq?\r
-            [ nip ] [ resize-byte-array ] if\r
-        ] [ >byte-array ] if\r
-    ] unless ;\r
-\r
-M: byte-array new-resizable drop <byte-vector> ;\r
-\r
-INSTANCE: byte-vector growable\r
diff --git a/core/byte-vectors/summary.txt b/core/byte-vectors/summary.txt
deleted file mode 100644 (file)
index e914ebb..0000000
+++ /dev/null
@@ -1 +0,0 @@
-Growable byte arrays
diff --git a/core/byte-vectors/tags.txt b/core/byte-vectors/tags.txt
deleted file mode 100644 (file)
index 42d711b..0000000
+++ /dev/null
@@ -1 +0,0 @@
-collections
index 4b0d9e5072658b35e4f976801a4e313b866bb6da..699d93b8b4f994a9fbaa186b3ab03e74ae4f9b07 100644 (file)
@@ -1,7 +1,7 @@
 ! Copyright (c) 2008 Slava Pestov
 ! See http://factorcode.org/license.txt for BSD license.
-USING: sequences math.parser io io.streams.byte-array
-io.encodings.binary io.files kernel ;
+USING: sequences math.parser io io.encodings.binary io.files
+kernel ;
 IN: checksums
 
 MIXIN: checksum
@@ -12,9 +12,6 @@ GENERIC: checksum-stream ( stream checksum -- value )
 
 GENERIC: checksum-lines ( lines checksum -- value )
 
-M: checksum checksum-bytes
-    [ binary <byte-reader> ] dip checksum-stream ;
-
 M: checksum checksum-stream
     [ contents ] dip checksum-bytes ;
 
index 810bdbe10fc23ae0c4eb26e0b5880182403e188f..2730e4683bc06b8215270c9ac51bd6845854311a 100644 (file)
@@ -4,6 +4,7 @@ IN: classes.algebra
 \r
 ARTICLE: "class-operations" "Class operations"\r
 "Set-theoretic operations on classes:"\r
+{ $subsection class= }\r
 { $subsection class< }\r
 { $subsection class<= }\r
 { $subsection class-and }\r
index 3bac6c87b3aa6e429ee07db66c667f4dbcfbee0b..5b1844b78b63cbb7af071f61a4340acb972d8ed9 100644 (file)
@@ -197,7 +197,7 @@ ARTICLE: "tuple-introspection" "Tuple introspection"
 
 ARTICLE: "tuple-examples" "Tuple examples"
 "An example:"
-{ $code "TUPLE: employee name salary position ;" }
+{ $code "TUPLE: employee name position salary ;" }
 "This defines a class word named " { $snippet "employee" } ", a predicate " { $snippet "employee?" } ", and the following slot accessors:"
 { $table
     { "Reader" "Writer" "Setter" "Changer" }
@@ -237,7 +237,7 @@ ARTICLE: "tuple-examples" "Tuple examples"
     "    checks counter check boa ;"
     ""
     ": biweekly-paycheck ( employee -- check )"
-    "    dup name>> swap salary>> 26 / <check> ;"
+    "    [ name>> ] [ salary>> 26 / ] bi <check> ;"
 }
 "An example of using a changer:"
 { $code
index 9d748d665d9ae927c1dea776feed91c57efea654..d9464399a94ee4a7a9253a501f7f80779ecbf304 100644 (file)
@@ -252,7 +252,7 @@ M: tuple-class update-class
 
 : tuple-class-unchanged? ( class superclass slots -- ? )
     [ over ] dip
-    [ [ superclass ] dip = ]
+    [ [ superclass ] [ bootstrap-word ] bi* = ]
     [ [ "slots" word-prop ] dip = ] 2bi* and ;
 
 : valid-superclass? ( class -- ? )
index 8d1d9f0d2af040be7d2ada809cdf131fbf4e53ff..a26c2fbe5d1db84517d0a4af7ab758ef0c782274 100644 (file)
@@ -12,8 +12,6 @@ ARTICLE: "combinators-quot" "Quotation construction utilities"
 ARTICLE: "combinators" "Additional combinators"
 "The " { $vocab-link "combinators" } " vocabulary provides a few useful combinators."
 $nl
-"A looping combinator:"
-{ $subsection while }
 "Generalization of " { $link bi } " and " { $link tri } ":"
 { $subsection cleave }
 "Generalization of " { $link 2bi } " and " { $link 2tri } ":"
index 9f950aa36c9fc3a938b268d82cd2a8e6d3107c55..e1ab50cdcd8b340f09ed4d9dec29b0cb4f5fa696 100644 (file)
@@ -14,7 +14,7 @@ $nl
 }
 "The underlying sequence must implement a generic word:"
 { $subsection resize }
-{ $link "vectors" } ", " { $link "byte-vectors" } " and " { $link "sbufs" } " are implemented using the resizable sequence facility." ;
+{ $link "vectors" } " and " { $link "sbufs" } " are implemented using the resizable sequence facility." ;
 
 ABOUT: "growable"
 
diff --git a/core/io/streams/byte-array/byte-array-docs.factor b/core/io/streams/byte-array/byte-array-docs.factor
deleted file mode 100644 (file)
index 7b27621..0000000
+++ /dev/null
@@ -1,34 +0,0 @@
-USING: help.syntax help.markup io byte-arrays quotations ;
-IN: io.streams.byte-array
-
-ABOUT: "io.streams.byte-array"
-
-ARTICLE: "io.streams.byte-array" "Byte-array streams"
-"Byte array streams:"
-{ $subsection <byte-reader> }
-{ $subsection <byte-writer> }
-"Utility combinators:"
-{ $subsection with-byte-reader }
-{ $subsection with-byte-writer } ;
-
-HELP: <byte-reader>
-{ $values { "byte-array" byte-array }
-    { "encoding" "an encoding descriptor" }
-    { "stream" "a new byte reader" } }
-{ $description "Creates an input stream reading from a byte array using an encoding." } ;
-
-HELP: <byte-writer>
-{ $values { "encoding" "an encoding descriptor" }
-    { "stream" "a new byte writer" } }
-{ $description "Creates an output stream writing data to a byte array using an encoding." } ;
-
-HELP: with-byte-reader
-{ $values { "encoding" "an encoding descriptor" }
-    { "quot" quotation } { "byte-array" byte-array } }
-{ $description "Calls the quotation in a new dynamic scope with " { $link input-stream } " rebound to an input stream for reading from a byte array using an encoding." } ;
-
-HELP: with-byte-writer
-{ $values  { "encoding" "an encoding descriptor" }
-    { "quot" quotation }
-    { "byte-array" byte-array } }
-{ $description "Calls the quotation in a new dynamic scope with " { $link output-stream } " rebound to an output stream writing data to a byte array using an encoding." } ;
diff --git a/core/io/streams/byte-array/byte-array-tests.factor b/core/io/streams/byte-array/byte-array-tests.factor
deleted file mode 100644 (file)
index 77a9126..0000000
+++ /dev/null
@@ -1,9 +0,0 @@
-USING: tools.test io.streams.byte-array io.encodings.binary
-io.encodings.utf8 io kernel arrays strings ;
-
-[ B{ 1 2 3 } ] [ binary [ { 1 2 3 } write ] with-byte-writer ] unit-test
-[ B{ 1 2 3 } ] [ { 1 2 3 } binary [ 3 read ] with-byte-reader ] unit-test
-
-[ B{ BIN: 11110101 BIN: 10111111 BIN: 10000000 BIN: 10111111 BIN: 11101111 BIN: 10000000 BIN: 10111111 BIN: 11011111 BIN: 10000000 CHAR: x } ]
-[ { BIN: 101111111000000111111 BIN: 1111000000111111 BIN: 11111000000 CHAR: x } utf8 [ write ] with-byte-writer ] unit-test
-[ { BIN: 101111111000000111111 } t ] [ { BIN: 11110101 BIN: 10111111 BIN: 10000000 BIN: 10111111 } utf8 <byte-reader> contents dup >array swap string? ] unit-test
diff --git a/core/io/streams/byte-array/byte-array.factor b/core/io/streams/byte-array/byte-array.factor
deleted file mode 100644 (file)
index 9d89c3d..0000000
+++ /dev/null
@@ -1,16 +0,0 @@
-USING: byte-arrays byte-vectors kernel io.encodings io.streams.string
-sequences io namespaces io.encodings.private accessors ;
-IN: io.streams.byte-array
-
-: <byte-writer> ( encoding -- stream )
-    512 <byte-vector> swap <encoder> ;
-
-: with-byte-writer ( encoding quot -- byte-array )
-    [ <byte-writer> ] dip [ output-stream get ] compose with-output-stream*
-    dup encoder? [ stream>> ] when >byte-array ; inline
-
-: <byte-reader> ( byte-array encoding -- stream )
-    [ >byte-vector dup reverse-here ] dip <decoder> ;
-
-: with-byte-reader ( byte-array encoding quot -- )
-    [ <byte-reader> ] dip with-input-stream* ; inline
index 01ef8d480da6071fdcd162ac79fbefa561519d94..1404491d10e405566d0133f247882492975f2321 100644 (file)
@@ -603,15 +603,15 @@ HELP: 3dip
 
 HELP: while
 { $values { "pred" { $quotation "( -- ? )" } } { "body" "a quotation" } { "tail" "a quotation" } }
-{ $description "Repeatedly calls " { $snippet "pred" } ". If it yields " { $link f } ", iteration stops, otherwise " { $snippet "body" } " is called. After iteration stops, " { $snippet "tail" } " is called." }
-{ $notes "In most cases, tail recursion should be used, because it is simpler both in terms of implementation and conceptually. However in some cases this combinator expresses intent better and should be used."
-$nl
-"Strictly speaking, the " { $snippet "tail" } " is not necessary, since the following are equivalent:"
-{ $code
-    "[ P ] [ Q ] [ T ] while"
-    "[ P ] [ Q ] [ ] while T"
-}
-"However, depending on the stack effects of " { $snippet "pred" } " and " { $snippet "quot" } ", the " { $snippet "tail" } " quotation might need to be non-empty in order to balance out the stack effect of branches for stack effect inference." } ;
+{ $description "Calls " { $snippet "body" } " until " { $snippet "pred" } " returns " { $link f } "." } ;
+
+HELP: until
+{ $values { "pred" { $quotation "( -- ? )" } } { "body" "a quotation" } { "tail" "a quotation" } }
+{ $description "Calls " { $snippet "body" } " until " { $snippet "pred" } " returns " { $link t } "." } ;
+
+HELP: do
+{ $values { "pred" { $quotation "( -- ? )" } } { "body" "a quotation" } { "tail" "a quotation" } }
+{ $description "Executes one iteration of a " { $link while } " or " { $link until } " loop." } ;
 
 HELP: loop
 { $values
@@ -627,6 +627,26 @@ HELP: loop
     "3\n10\n6\n2\n9\n5\n1\n8\n4\n0\n7" }
 } ;
 
+ARTICLE: "looping-combinators" "Looping combinators"
+"In most cases, loops should be written using high-level combinators (such as " { $link "sequences-combinators" } ") or tail recursion. However, sometimes, the best way to express intent is with a loop."
+{ $subsection while }
+{ $subsection until }
+"The above two combinators take a " { $snippet "tail" } " quotation. Strictly speaking, the " { $snippet "tail" } " is not necessary, since the following are equivalent:"
+{ $code
+    "[ P ] [ Q ] [ T ] while"
+    "[ P ] [ Q ] [ ] while T"
+}
+"However, depending on the stack effects of " { $snippet "pred" } " and " { $snippet "quot" } ", the " { $snippet "tail" } " quotation might need to be non-empty in order to balance out the stack effect of branches for stack effect inference."
+$nl
+"To execute one iteration of a loop, use the following word:"
+{ $subsection do }
+"This word is intended as a modifier. The normal " { $link while } " loop never executes the body if the predicate returns first on the first iteration. To ensure the body executes at least once, use " { $link do } ":"
+{ $code
+    "[ P ] [ Q ] [ T ] do while"
+}
+"A simpler looping combinator which executes a single quotation until it returns " { $link f } ":"
+{ $subsection loop } ;
+
 HELP: assert
 { $values { "got" "the obtained value" } { "expect" "the expected value" } }
 { $description "Throws an " { $link assert } " error." }
@@ -899,13 +919,20 @@ ARTICLE: "dataflow" "Data and control flow"
 { $subsection "booleans" }
 { $subsection "shuffle-words" }
 "A central concept in Factor is that of a " { $emphasis "combinator" } ", which is a word taking code as input."
+$nl
+"Data flow combinators:"
 { $subsection "slip-keep-combinators" }
 { $subsection "cleave-combinators" }
 { $subsection "spread-combinators" }
 { $subsection "apply-combinators" }
+"Control flow combinators:"
 { $subsection "conditionals" }
+{ $subsection "looping-combinators" }
+"Additional combinators:"
 { $subsection "compositional-combinators" }
 { $subsection "combinators" }
+"More combinators are defined for working on data structures, such as " { $link "sequences-combinators" } " and " { $link "assocs-combinators" } "."
+$nl
 "Advanced topics:"
 { $subsection "assertions" }
 { $subsection "implementing-combinators" }
index 564600d322bab63c3dd16fb3f62fdd56db3d6b75..d4df6fa407deb01166afa4811575391aa03beaae 100644 (file)
@@ -129,14 +129,6 @@ DEFER: if
 : 2bi@ ( w x y z quot -- )
     dup 2bi* ; inline
 
-: loop ( pred: ( -- ? ) -- )
-    dup slip swap [ loop ] [ drop ] if ; inline recursive
-
-: while ( pred: ( -- ? ) body: ( -- ) tail: ( -- ) -- )
-    [ dup slip ] 2dip roll
-    [ [ tuck 2slip ] dip while ]
-    [ 2nip call ] if ; inline recursive
-
 ! Object protocol
 GENERIC: hashcode* ( depth obj -- code )
 
@@ -202,6 +194,19 @@ GENERIC: boa ( ... class -- tuple )
 : most ( x y quot -- z )
     [ 2dup ] dip call [ drop ] [ nip ] if ; inline
 
+! Loops
+: loop ( pred: ( -- ? ) -- )
+    dup slip swap [ loop ] [ drop ] if ; inline recursive
+
+: do ( pred body tail -- pred body tail )
+    over 3dip ; inline
+
+: while ( pred: ( -- ? ) body: ( -- ) tail: ( -- ) -- )
+    [ pick 3dip [ do while ] 3curry ] keep if ; inline recursive
+
+: until ( pred: ( -- ? ) body: ( -- ) tail: ( -- ) -- )
+    [ [ not ] compose ] 2dip while ; inline
+
 ! Error handling -- defined early so that other files can
 ! throw errors before continuations are loaded
 : throw ( error -- * ) 5 getenv [ die ] or 1 (throw) ;
index 30903e32693c6f2b2b5a313b04e33588b449c0c4..6ed945216ecb23da817e59f4798181e3f3605c74 100644 (file)
@@ -41,7 +41,7 @@ M: fixnum bitnot fixnum-bitnot ;
 M: fixnum bit? neg shift 1 bitand 0 > ;
 
 : fixnum-log2 ( x -- n )
-    0 swap [ dup 1 number= not ] [ [ 1+ ] [ 2/ ] bi* ] [ ] while drop ;
+    0 swap [ dup 1 eq? ] [ [ 1+ ] [ 2/ ] bi* ] [ ] until drop ;
 
 M: fixnum (log2) fixnum-log2 ;
 
index 1c23e700ca0c661a89615faff135c41335bb15ab..6794825897e540e9b8547d92ebfe55c17f4b961b 100644 (file)
@@ -1,8 +1,16 @@
 USING: generic kernel kernel.private math memory prettyprint io
 sequences tools.test words namespaces layouts classes
-classes.builtin arrays quotations ;
+classes.builtin arrays quotations io.launcher system ;
 IN: memory.tests
 
+! LOL
+[ ] [
+    vm
+    "-generations=2"
+    "-e=USING: memory io prettyprint system ; input-stream gc . 0 exit"
+    3array try-process
+] unit-test
+
 [ [ ] instances ] must-infer
 
 ! Code GC wasn't kicking in when needed
index 42527371f2ffa9957d2e71415e71a0126df851a0..b67f7c94e838e8f16ef13ed24fe09bea7868865e 100644 (file)
@@ -4,7 +4,9 @@ USING: kernel continuations sequences vectors arrays system math ;
 IN: memory
 
 : (each-object) ( quot: ( obj -- ) -- )
-    [ next-object dup ] swap [ drop ] while ; inline
+    next-object dup [
+        swap [ call ] keep (each-object)
+    ] [ 2drop ] if ; inline recursive
 
 : each-object ( quot -- )
     begin-scan [ (each-object) ] [ end-scan ] [ ] cleanup ; inline
index 0b3e0003ac90ec40ca9897a05a2e48185731d36c..7354759bb6a834c91ef1ce6fa776777e1a42c526 100644 (file)
@@ -1,6 +1,6 @@
 USING: arrays help.markup help.syntax math
 sequences.private vectors strings kernel math.order layouts
-quotations ;
+quotations generic.standard ;
 IN: sequences
 
 HELP: sequence
@@ -14,8 +14,8 @@ HELP: length
 
 HELP: set-length
 { $values { "n" "a non-negative integer" } { "seq" "a resizable sequence" } }
-{ $contract "Resizes the sequence. Not all sequences are resizable." }
-{ $errors "Throws a " { $link bounds-error } " if the new length is negative." }
+{ $contract "Resizes a sequence. The initial contents of the new area is undefined." }
+{ $errors "Throws a " { $link no-method  } " error if the sequence is not resizable, and a " { $link bounds-error } " if the new length is negative." }
 { $side-effects "seq" } ;
 
 HELP: lengthen
@@ -59,7 +59,7 @@ HELP: immutable
 
 HELP: new-sequence
 { $values { "len" "a non-negative integer" } { "seq" sequence } { "newseq" "a mutable sequence" } }
-{ $contract "Outputs a mutable sequence of length " { $snippet "n" } " which can hold the elements of " { $snippet "seq" } "." } ;
+{ $contract "Outputs a mutable sequence of length " { $snippet "n" } " which can hold the elements of " { $snippet "seq" } ". The initial contents of the sequence are undefined." } ;
 
 HELP: new-resizable
 { $values { "len" "a non-negative integer" } { "seq" sequence } { "newseq" "a resizable mutable sequence" } }
index 187db02c5cb2e0dc8d6d845f9f60ac5723d6e032..438e604e789c433f8d0c9de28139b4ac0f601e7e 100644 (file)
@@ -199,7 +199,7 @@ M: array make-slot
         swap
         peel-off-name
         peel-off-class
-        [ dup empty? not ] [ peel-off-attributes ] [ ] while drop
+        [ dup empty? ] [ peel-off-attributes ] [ ] until drop
     check-initial-value ;
 
 M: slot-spec make-slot
index 767c2a1f79ec4c216392a72eb510c833a4fb73ae..3ae50a9a150fa768b1087a175a9faa368617c20e 100644 (file)
@@ -78,7 +78,7 @@ M: pathname forget*
 
 SYMBOL: file
 
-TUPLE: source-file-error file error ;
+TUPLE: source-file-error error file ;
 
 : <source-file-error> ( msg -- error )
     \ source-file-error new
diff --git a/core/strings/parser/parser-tests.factor b/core/strings/parser/parser-tests.factor
new file mode 100644 (file)
index 0000000..80f649c
--- /dev/null
@@ -0,0 +1,4 @@
+IN: strings.parser.tests
+USING: strings.parser tools.test ;
+
+[ "Hello\n\rworld" ] [ "Hello\\n\\rworld" unescape-string ] unit-test
index cfe5d1a90ac9acf822c3fca4fc8ab3bfa3805915..4062e16e3d807a4859e85d03a4b36b0eb0b42066 100644 (file)
@@ -58,3 +58,15 @@ name>char-hook global [
     lexer get [
         [ swap tail-slice (parse-string) ] "" make swap
     ] change-lexer-column ;
+
+: (unescape-string) ( str -- str' )
+    dup [ CHAR: \\ = ] find [
+        cut-slice [ % ] dip rest-slice
+        next-escape [ , ] dip
+        (unescape-string)
+    ] [
+        drop %
+    ] if ;
+
+: unescape-string ( str -- str' )
+    [ (unescape-string) ] "" make ;
index c951750b342a6cc09f9316bd2840f3ceaa0cc428..0b7d9d008f0bce0138e14ebb66957e0b8871c6eb 100644 (file)
@@ -1,14 +1,13 @@
 ! Copyright (C) 2004, 2008 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: accessors alien arrays byte-arrays byte-vectors
-definitions generic hashtables kernel math namespaces parser
-lexer sequences strings strings.parser sbufs vectors
-words quotations io assocs splitting classes.tuple
-generic.standard generic.math generic.parser classes io.files
-vocabs classes.parser classes.union
-classes.intersection classes.mixin classes.predicate
-classes.singleton classes.tuple.parser compiler.units
-combinators effects.parser slots ;
+USING: accessors alien arrays byte-arrays definitions generic
+hashtables kernel math namespaces parser lexer sequences strings
+strings.parser sbufs vectors words quotations io assocs
+splitting classes.tuple generic.standard generic.math
+generic.parser classes io.files vocabs classes.parser
+classes.union classes.intersection classes.mixin
+classes.predicate classes.singleton classes.tuple.parser
+compiler.units combinators effects.parser slots ;
 IN: bootstrap.syntax
 
 ! These words are defined as a top-level form, instead of with
@@ -81,7 +80,6 @@ IN: bootstrap.syntax
     "{" [ \ } [ >array ] parse-literal ] define-syntax
     "V{" [ \ } [ >vector ] parse-literal ] define-syntax
     "B{" [ \ } [ >byte-array ] parse-literal ] define-syntax
-    "BV{" [ \ } [ >byte-vector ] parse-literal ] define-syntax
     "H{" [ \ } [ >hashtable ] parse-literal ] define-syntax
     "T{" [ parse-tuple-literal parsed ] define-syntax
     "W{" [ \ } [ first <wrapper> ] parse-literal ] define-syntax
index e5bd74a98169b2d28bbe8d50bdf100e377e7a67d..533bea76fcd4a35b9831cc64e8d0f670db2190b1 100644 (file)
@@ -171,3 +171,11 @@ forget-junk
 ] with-compilation-unit
 
 [ ] [ "vocabs.loader.test.h" require ] unit-test
+
+
+[
+    "vocabs.loader.test.j" forget-vocab
+    "vocabs.loader.test.k" forget-vocab
+] with-compilation-unit
+
+[ ] [ [ "vocabs.loader.test.j" require ] [ drop :1 ] recover ] unit-test
index 6fb0d088118b74fb9c388d1a9f6adcd9bc54bad3..97fbfe8a0762a6026976ec501034bcde88620074 100644 (file)
@@ -65,6 +65,7 @@ ERROR: circular-dependency name ;
     [
         +parsing+ >>source-loaded?
         dup vocab-source-path [ parse-file ] [ [ ] ] if*
+        [ +parsing+ >>source-loaded? ] dip
         [ % ] [ assert-depth ] if-bootstrapping
         +done+ >>source-loaded? drop
     ] [ ] [ f >>source-loaded? ] cleanup ;
diff --git a/core/vocabs/loader/test/j/j.factor b/core/vocabs/loader/test/j/j.factor
new file mode 100644 (file)
index 0000000..6d54548
--- /dev/null
@@ -0,0 +1,2 @@
+IN: vocabs.loader.test.j
+"vocabs.loader.test.k" require
diff --git a/core/vocabs/loader/test/j/tags.txt b/core/vocabs/loader/test/j/tags.txt
new file mode 100644 (file)
index 0000000..6bf6830
--- /dev/null
@@ -0,0 +1 @@
+unportable
diff --git a/core/vocabs/loader/test/k/k.factor b/core/vocabs/loader/test/k/k.factor
new file mode 100644 (file)
index 0000000..603b48b
--- /dev/null
@@ -0,0 +1,2 @@
+IN: vocabs.loader.test.k
+USE: vocabs.loader.test.j
diff --git a/core/vocabs/loader/test/k/tags.txt b/core/vocabs/loader/test/k/tags.txt
new file mode 100644 (file)
index 0000000..6bf6830
--- /dev/null
@@ -0,0 +1 @@
+unportable
index ab6ff190941723ea029305f7037d7787cee774b0..78c797df9b9a92b21d8f26c210e0086dda0a92d9 100644 (file)
@@ -1,5 +1,5 @@
 
-USING: kernel parser lexer locals.private ;
+USING: kernel parser lexer locals.parser locals.types ;
 
 IN: bind-in
 
index 01163f730f6347439b60213fbebdb036e0ed415c..13dae69dce0303b055feb4712c12756a92adc8ca 100644 (file)
@@ -1,4 +1,4 @@
-! Copyright (C) 2008 DoDoug Coleman.
+! Copyright (C) 2008 Doug Coleman.
 ! See http://factorcode.org/license.txt for BSD license.
 USING: crypto.barrett kernel math namespaces tools.test ;
 IN: crypto.barrett.tests
index d02983d7fd7cda5f4f382d6792002d7729d3037f..b1fdf2463e5b183eb6e2ab713d3eee47dc7e1263 100755 (executable)
@@ -1,5 +1,5 @@
-USING: words kernel sequences locals\r
-locals.private accessors parser namespaces continuations\r
+USING: words kernel sequences locals locals.parser\r
+locals.definitions accessors parser namespaces continuations\r
 summary definitions generalizations arrays ;\r
 IN: descriptive\r
 \r
index d8a363ca715e25d97f87103ce7f22f93ee1f1980..d9db83b5e35df51e365e48683a87e4d33589d020 100644 (file)
@@ -1,50 +1,70 @@
 ! Copyright (C) 2008 Jose Antonio Ortega Ruiz.
 ! See http://factorcode.org/license.txt for BSD license.
 
-USING: accessors arrays classes.tuple compiler.units continuations debugger
-definitions eval io io.files io.streams.string kernel listener listener.private
-make math namespaces parser prettyprint quotations sequences strings
-vectors vocabs.loader ;
+USING: accessors arrays classes classes.tuple compiler.units
+combinators continuations debugger definitions eval help
+io io.files io.streams.string kernel lexer listener listener.private
+make math namespaces parser prettyprint prettyprint.config
+quotations sequences strings source-files vectors vocabs.loader ;
 
 IN: fuel
 
-! <PRIVATE
+! Evaluation status:
 
-TUPLE: fuel-status in use ds? ;
+TUPLE: fuel-status in use ds? restarts ;
 
 SYMBOL: fuel-status-stack
 V{ } clone fuel-status-stack set-global
 
+SYMBOL: fuel-eval-result
+f clone fuel-eval-result set-global
+
+SYMBOL: fuel-eval-output
+f clone fuel-eval-result set-global
+
+SYMBOL: fuel-eval-res-flag
+t clone fuel-eval-res-flag set-global
+
+: fuel-eval-restartable? ( -- ? )
+    fuel-eval-res-flag get-global ; inline
+
+: fuel-eval-restartable ( -- )
+    t fuel-eval-res-flag set-global ; inline
+
+: fuel-eval-non-restartable ( -- )
+    f fuel-eval-res-flag set-global ; inline
+
 : push-fuel-status ( -- )
-    in get use get clone display-stacks? get
+    in get use get clone display-stacks? get restarts get-global clone
     fuel-status boa
     fuel-status-stack get push ;
 
 : pop-fuel-status ( -- )
     fuel-status-stack get empty? [
-        fuel-status-stack get pop
-        [ in>> in set ]
-        [ use>> clone use set ]
-        [ ds?>> display-stacks? swap [ on ] [ off ] if ] tri
+        fuel-status-stack get pop {
+            [ in>> in set ]
+            [ use>> clone use set ]
+            [ ds?>> display-stacks? swap [ on ] [ off ] if ]
+            [
+                restarts>> fuel-eval-restartable? [ drop ] [
+                    clone restarts set-global
+                ] if
+            ]
+        } cleave
     ] unless ;
 
-SYMBOL: fuel-eval-result
-f clone fuel-eval-result set-global
 
-SYMBOL: fuel-eval-output
-f clone fuel-eval-result set-global
-
-! PRIVATE>
+! Lispy pretty printing
 
 GENERIC: fuel-pprint ( obj -- )
 
-M: object fuel-pprint pprint ;
+M: object fuel-pprint pprint ; inline
 
-M: f fuel-pprint drop "nil" write ;
+M: f fuel-pprint drop "nil" write ; inline
 
-M: integer fuel-pprint pprint ;
+M: integer fuel-pprint pprint ; inline
 
-M: string fuel-pprint pprint ;
+M: string fuel-pprint pprint ; inline
 
 M: sequence fuel-pprint
     dup empty? [ drop f fuel-pprint ] [
@@ -53,12 +73,30 @@ M: sequence fuel-pprint
         ")" write
     ] if ;
 
-M: tuple fuel-pprint tuple>array fuel-pprint ;
+M: tuple fuel-pprint tuple>array fuel-pprint ; inline
+
+M: continuation fuel-pprint drop ":continuation" write ; inline
+
+M: restart fuel-pprint name>> fuel-pprint ; inline
+
+SYMBOL: :restarts
 
-M: continuation fuel-pprint drop "~continuation~" write ;
+: fuel-restarts ( obj -- seq )
+    compute-restarts :restarts prefix ; inline
+
+M: condition fuel-pprint
+    [ error>> ] [ fuel-restarts ] bi 2array condition prefix fuel-pprint ;
+
+M: source-file-error fuel-pprint
+    [ file>> ] [ error>> ] bi 2array source-file-error prefix
+    fuel-pprint ;
+
+M: source-file fuel-pprint path>> fuel-pprint ;
+
+! Evaluation vocabulary
 
 : fuel-eval-set-result ( obj -- )
-    clone fuel-eval-result set-global ;
+    clone fuel-eval-result set-global ; inline
 
 : fuel-retort ( -- )
     error get
@@ -66,33 +104,34 @@ M: continuation fuel-pprint drop "~continuation~" write ;
     fuel-eval-output get-global
     3array fuel-pprint ;
 
-: fuel-forget-error ( -- )
-    f error set-global ;
+: fuel-forget-error ( -- ) f error set-global ; inline
+: fuel-forget-result ( -- ) f fuel-eval-result set-global ; inline
+: fuel-forget-output ( -- ) f fuel-eval-output set-global ; inline
 
 : (fuel-begin-eval) ( -- )
     push-fuel-status
     display-stacks? off
     fuel-forget-error
-    f fuel-eval-result set-global
-    f fuel-eval-output set-global ;
+    fuel-forget-result
+    fuel-forget-output ;
 
 : (fuel-end-eval) ( quot -- )
     with-string-writer fuel-eval-output set-global
-    fuel-retort
-    pop-fuel-status ;
+    fuel-retort pop-fuel-status ; inline
 
 : (fuel-eval) ( lines -- )
-    [ [ parse-lines ] with-compilation-unit call ] curry [ drop ] recover ;
+    [ [ parse-lines ] with-compilation-unit call ] curry
+    [ print-error ] recover ; inline
 
 : (fuel-eval-each) ( lines -- )
-    [ 1vector (fuel-eval) ] each ;
+    [ 1vector (fuel-eval) ] each ; inline
 
 : (fuel-eval-usings) ( usings -- )
     [ "USING: " prepend " ;" append ] map
-    (fuel-eval-each) fuel-forget-error ;
+    (fuel-eval-each) fuel-forget-error fuel-forget-output ;
 
 : (fuel-eval-in) ( in -- )
-    [ dup "IN: " prepend 1vector (fuel-eval) in set ] when* ;
+    [ dup "IN: " prepend 1vector (fuel-eval) in set ] when* ; inline
 
 : fuel-eval-in-context ( lines in usings -- )
     (fuel-begin-eval) [
@@ -107,15 +146,15 @@ M: continuation fuel-pprint drop "~continuation~" write ;
     fuel-retort ;
 
 : fuel-eval ( lines -- )
-    (fuel-begin-eval) [ (fuel-eval) ] (fuel-end-eval) ;
+    (fuel-begin-eval) [ (fuel-eval) ] (fuel-end-eval) ; inline
 
-: fuel-end-eval ( -- )
-    [ ] (fuel-end-eval) ;
+: fuel-end-eval ( -- ) [ ] (fuel-end-eval) ; inline
 
 : fuel-get-edit-location ( defspec -- )
     where [ first2 [ (normalize-path) ] dip 2array fuel-eval-set-result ] when* ;
 
-: fuel-startup ( -- )
-    "listener" run ;
+: fuel-run-file ( path -- ) run-file ; inline
+
+: fuel-startup ( -- ) "listener" run ; inline
 
 MAIN: fuel-startup
index 116faf60cd9d00f607cc87db993796a5eb2f5478..b66a722258074c64dd2c4018c559fc6aa7ec1d33 100755 (executable)
@@ -1,10 +1,11 @@
-USING: windows.dinput windows.dinput.constants parser
-symbols alien.c-types windows.ole32 namespaces assocs kernel
-arrays vectors windows.kernel32 windows.com windows.dinput
-shuffle windows.user32 windows.messages sequences combinators
+USING: windows.dinput windows.dinput.constants parser symbols
+alien.c-types windows.ole32 namespaces assocs kernel arrays
+vectors windows.kernel32 windows.com windows.dinput shuffle
+windows.user32 windows.messages sequences combinators
 math.geometry.rect ui.windows accessors math windows alien
-alien.strings io.encodings.utf16 continuations byte-arrays
-locals game-input.backend.dinput.keys-array ;
+alien.strings io.encodings.utf16 io.encodings.utf16n
+continuations byte-arrays locals
+game-input.backend.dinput.keys-array ;
 << "game-input" (use+) >>
 IN: game-input.backend.dinput
 
index 64ea481b030f0485346abfa0c59d2dbd96a7a8c6..48c14f7cbafd7cb091160ff1465008c43102e93c 100755 (executable)
@@ -1,14 +1,15 @@
 USING: tools.deploy.config ;
 H{
-    { deploy-unicode? f }
-    { deploy-reflection 1 }
-    { deploy-word-props? f }
-    { deploy-math? f }
     { deploy-name "Hello world (console)" }
-    { deploy-word-defs? f }
-    { "stop-after-last-window?" t }
+    { deploy-c-types? f }
+    { deploy-word-props? f }
     { deploy-ui? f }
+    { deploy-reflection 1 }
     { deploy-compiler? f }
+    { deploy-unicode? f }
     { deploy-io 2 }
-    { deploy-c-types? f }
+    { deploy-word-defs? f }
+    { deploy-threads? f }
+    { "stop-after-last-window?" t }
+    { deploy-math? f }
 }
diff --git a/extra/io/paths/authors.txt b/extra/io/paths/authors.txt
deleted file mode 100755 (executable)
index 7c1b2f2..0000000
+++ /dev/null
@@ -1 +0,0 @@
-Doug Coleman
diff --git a/extra/io/paths/paths.factor b/extra/io/paths/paths.factor
deleted file mode 100755 (executable)
index 75d08b6..0000000
+++ /dev/null
@@ -1,58 +0,0 @@
-! Copyright (C) 2008 Doug Coleman.
-! See http://factorcode.org/license.txt for BSD license.
-USING: accessors arrays deques dlists io.files io.paths.private
-kernel sequences system vocabs.loader fry continuations ;
-IN: io.paths
-
-TUPLE: directory-iterator path bfs queue ;
-
-<PRIVATE
-
-: qualified-directory ( path -- seq )
-    dup directory-files [ append-path ] with map ;
-
-: push-directory ( path iter -- )
-    [ qualified-directory ] dip [
-        dup queue>> swap bfs>>
-        [ push-front ] [ push-back ] if
-    ] curry each ;
-
-: <directory-iterator> ( path bfs? -- iterator )
-    <dlist> directory-iterator boa
-    dup path>> over push-directory ;
-
-: next-file ( iter -- file/f )
-    dup queue>> deque-empty? [ drop f ] [
-        dup queue>> pop-back dup link-info directory?
-        [ over push-directory next-file ] [ nip ] if
-    ] if ;
-
-: iterate-directory ( iter quot: ( obj -- ? ) -- obj )
-    over next-file [
-        over call
-        [ 2nip ] [ iterate-directory ] if*
-    ] [
-        2drop f
-    ] if* ; inline recursive
-
-PRIVATE>
-
-: find-file ( path bfs? quot: ( obj -- ? ) -- path/f )
-    [ <directory-iterator> ] dip
-    [ keep and ] curry iterate-directory ; inline
-
-: each-file ( path bfs? quot: ( obj -- ? ) -- )
-    [ <directory-iterator> ] dip
-    [ f ] compose iterate-directory drop ; inline
-
-: find-all-files ( path bfs? quot: ( obj -- ? ) -- paths )
-    [ <directory-iterator> ] dip
-    pusher [ [ f ] compose iterate-directory drop ] dip ; inline
-
-: recursive-directory ( path bfs? -- paths )
-    [ ] accumulator [ each-file ] dip ;
-
-: find-in-directories ( directories bfs? quot -- path' )
-    '[ _ _ find-file ] attempt-all ; inline
-
-os windows? [ "io.paths.windows" require ] when
diff --git a/extra/io/paths/windows/authors.txt b/extra/io/paths/windows/authors.txt
deleted file mode 100644 (file)
index 7c1b2f2..0000000
+++ /dev/null
@@ -1 +0,0 @@
-Doug Coleman
diff --git a/extra/io/paths/windows/tags.txt b/extra/io/paths/windows/tags.txt
deleted file mode 100644 (file)
index 6bf6830..0000000
+++ /dev/null
@@ -1 +0,0 @@
-unportable
diff --git a/extra/io/paths/windows/windows.factor b/extra/io/paths/windows/windows.factor
deleted file mode 100644 (file)
index b4858aa..0000000
+++ /dev/null
@@ -1,13 +0,0 @@
-! Copyright (C) 2008 Doug Coleman.
-! See http://factorcode.org/license.txt for BSD license.
-USING: arrays continuations fry io.files io.paths
-kernel windows.shell32 sequences ;
-IN: io.paths.windows
-
-: program-files-directories ( -- array )
-    program-files program-files-x86 2array ; inline
-
-: find-in-program-files ( base-directory bfs? quot -- path )
-    [
-        [ program-files-directories ] dip '[ _ append-path ] map
-    ] 2dip find-in-directories ; inline
diff --git a/extra/math/binpack/authors.txt b/extra/math/binpack/authors.txt
new file mode 100644 (file)
index 0000000..e091bb8
--- /dev/null
@@ -0,0 +1 @@
+John Benediktsson
diff --git a/extra/math/binpack/binpack-docs.factor b/extra/math/binpack/binpack-docs.factor
new file mode 100644 (file)
index 0000000..36a29c7
--- /dev/null
@@ -0,0 +1,19 @@
+! Copyright (C) 2008 John Benediktsson
+! See http://factorcode.org/license.txt for BSD license
+
+USING: help.syntax help.markup kernel assocs sequences quotations ;
+
+IN: math.binpack 
+
+HELP: binpack
+{ $values { "assoc" assoc } { "n" "number of bins" } { "bins" "packed bins" } }
+{ $description "Packs the (key, value) pairs into the specified number of bins, using the value as a weight." } ;
+
+HELP: binpack*
+{ $values { "items" sequence } { "n" "number of bins" } { "bins" "packed bins" } } 
+{ $description "Packs a sequence of numbers into the specified number of bins." } ;
+
+HELP: binpack!
+{ $values { "items" sequence } { "quot" quotation } { "n" "number of bins" } { "bins" "packed bins" } } 
+{ $description "Packs a sequence of items into the specified number of bins, using the quotatino to determine the weight." } ;
+
diff --git a/extra/math/binpack/binpack-tests.factor b/extra/math/binpack/binpack-tests.factor
new file mode 100644 (file)
index 0000000..d0d4630
--- /dev/null
@@ -0,0 +1,13 @@
+! Copyright (C) 2008 John Benediktsson
+! See http://factorcode.org/license.txt for BSD license
+
+USING: kernel tools.test math.binpack ;
+
+[ t ] [ { V{ } } { } 1 binpack = ] unit-test
+
+[ t ] [ { { 3 } { 2 1 } } { 1 2 3 } 2 binpack* = ] unit-test
+
+[ t ] [ { { 1000 } { 100 60 30 7 } { 70 60 40 23 3 } } 
+        { 100 23 40 60 1000 30 60 07 70 03 } 3 binpack* = ] unit-test
+
+
diff --git a/extra/math/binpack/binpack.factor b/extra/math/binpack/binpack.factor
new file mode 100644 (file)
index 0000000..e3a009f
--- /dev/null
@@ -0,0 +1,22 @@
+! Copyright (C) 2008 John Benediktsson
+! See http://factorcode.org/license.txt for BSD license
+
+USING: sequences kernel arrays vectors accessors assocs sorting math math.functions ;
+
+IN: math.binpack 
+
+: (binpack) ( bins item -- )
+    [ [ values sum ] map ] keep
+    zip sort-keys values first push ;
+
+: binpack ( assoc n -- bins )
+    [ sort-values <reversed> dup length ] dip
+    tuck / ceiling <array> [ <vector> ] map
+    tuck [ (binpack) ] curry each ;
+
+: binpack* ( items n -- bins )
+    [ dup zip ] dip binpack [ keys ] map ;
+
+: binpack! ( items quot n -- bins ) 
+    [ dupd map zip ] dip binpack [ keys ] map ;
+
diff --git a/extra/math/binpack/summary.txt b/extra/math/binpack/summary.txt
new file mode 100644 (file)
index 0000000..c8b9196
--- /dev/null
@@ -0,0 +1 @@
+Bin-packing algorithms.
index d0014b5abe7ca38c26df52199f9cb70dbf2ce82d..44234bc4bc538242503e11d55e3664c9439630d2 100644 (file)
@@ -1,4 +1,4 @@
-USING: tools.test monads math kernel sequences lists promises ;
+USING: tools.test math kernel sequences lists promises monads ;
 IN: monads.tests
 
 [ 5 ] [ 1 identity-monad return [ 4 + ] fmap run-identity ] unit-test
index 14062b15db683157dfb214d5cc036da4904023ae..cfdc28bb3d607160194a9b6ec0342a3c944ff9bc 100755 (executable)
@@ -2,9 +2,10 @@
 ! See http://factorcode.org/license.txt for BSD license.
 USING: kernel math sequences vectors classes classes.algebra
 combinators arrays words assocs parser namespaces make
-definitions prettyprint prettyprint.backend quotations
-generalizations debugger io compiler.units kernel.private
-effects accessors hashtables sorting shuffle math.order sets ;
+definitions prettyprint prettyprint.backend prettyprint.custom
+quotations generalizations debugger io compiler.units
+kernel.private effects accessors hashtables sorting shuffle
+math.order sets ;
 IN: multi-methods
 
 ! PART I: Converting hook specializers
index b13321d9917a8d6a83e3127ecaca0fc9289d8d8a..7c23dcce0b2e31eecee52595e3e82967f8b52ca2 100755 (executable)
@@ -1,8 +1,9 @@
 USING: arrays combinators kernel lists math math.parser
-namespaces parser lexer parser-combinators parser-combinators.simple
-promises quotations sequences strings math.order
-assocs prettyprint.backend memoize unicode.case unicode.categories
-combinators.short-circuit accessors make io ;
+namespaces parser lexer parser-combinators
+parser-combinators.simple promises quotations sequences strings
+math.order assocs prettyprint.backend prettyprint.custom memoize
+unicode.case unicode.categories combinators.short-circuit
+accessors make io ;
 IN: parser-combinators.regexp
 
 <PRIVATE
diff --git a/extra/processing/gallery/trails/trails.factor b/extra/processing/gallery/trails/trails.factor
deleted file mode 100644 (file)
index a5b2b7b..0000000
+++ /dev/null
@@ -1,47 +0,0 @@
-
-USING: kernel arrays sequences math math.order qualified
-       sequences.lib circular processing ui newfx processing.shapes ;
-
-IN: processing.gallery.trails
-
-! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-
-! Example 33-15 from the Processing book
-
-! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-
-: point-list ( n -- seq ) [ drop 0 0 2array ] map <circular> ;
-
-! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-
-: dot ( pos percent -- ) 1 swap - 25 * 5 max circle ;
-
-: step ( seq -- )
-
-  no-stroke
-  { 1 0.4 } fill
-
-  0 background
-
-  mouse push-circular
-    [ dot ]
-  each-percent ;
-
-! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-
-: go* ( -- )
-
-  500 500 size*
-
-  [
-    100 point-list
-      [ step ]
-    curry
-      draw
-  ] setup
-
-  run ;
-
-: go ( -- ) [ go* ] with-ui ;
-
-MAIN: go
index 78ede328013cd382dd1333ba2652d8c427c7107f..6a547ead24a3a1c9569c663794c45c65f7dc5ee6 100755 (executable)
@@ -2,8 +2,9 @@
 ! See http://factorcode.org/license.txt for BSD license.\r
 USING: accessors assocs math kernel shuffle generalizations\r
 words quotations arrays combinators sequences math.vectors\r
-io.styles prettyprint vocabs sorting io generic locals.private\r
-math.statistics math.order combinators.lib ;\r
+io.styles prettyprint vocabs sorting io generic\r
+math.statistics math.order combinators.lib locals.types\r
+locals.definitions ;\r
 IN: reports.noise\r
 \r
 : badness ( word -- n )\r
diff --git a/extra/time/authors.txt b/extra/time/authors.txt
new file mode 100644 (file)
index 0000000..e091bb8
--- /dev/null
@@ -0,0 +1 @@
+John Benediktsson
diff --git a/extra/time/time-docs.factor b/extra/time/time-docs.factor
new file mode 100644 (file)
index 0000000..8fbc59e
--- /dev/null
@@ -0,0 +1,43 @@
+
+USING: help.syntax help.markup kernel prettyprint sequences strings ;
+
+IN: time
+
+HELP: strftime
+{ $values { "format-string" string } }
+{ $description "Writes the timestamp (specified on the stack) formatted according to the format string." } 
+;
+
+ARTICLE: "strftime" "Formatted timestamps"
+"The " { $vocab-link "time" } " vocabulary is used for formatted timestamps.\n"
+{ $subsection strftime }
+"\n"
+"Several format specifications exist for handling arguments of different types, and specifying attributes for the result string, including such things as maximum width, padding, and decimals.\n"
+{ $table
+    { "%a"     "Abbreviated weekday name." }
+    { "%A"     "Full weekday name." }
+    { "%b"     "Abbreviated month name." }
+    { "%B"     "Full month name." }
+    { "%c"     "Date and time representation." }
+    { "%d"     "Day of the month as a decimal number [01,31]." }
+    { "%H"     "Hour (24-hour clock) as a decimal number [00,23]." }
+    { "%I"     "Hour (12-hour clock) as a decimal number [01,12]." }
+    { "%j"     "Day of the year as a decimal number [001,366]." }
+    { "%m"     "Month as a decimal number [01,12]." }
+    { "%M"     "Minute as a decimal number [00,59]." }
+    { "%p"     "Either AM or PM." }
+    { "%S"     "Second as a decimal number [00,59]." }
+    { "%U"     "Week number of the year (Sunday as the first day of the week) as a decimal number [00,53]." }
+    { "%w"     "Weekday as a decimal number [0(Sunday),6]." }
+    { "%W"     "Week number of the year (Monday as the first day of the week) as a decimal number [00,53]." }
+    { "%x"     "Date representation." }
+    { "%X"     "Time representation." }
+    { "%y"     "Year without century as a decimal number [00,99]." }
+    { "%Y"     "Year with century as a decimal number." }
+    { "%Z"     "Time zone name (no characters if no time zone exists)." }
+    { "%%"     "A literal '%' character." }
+} ;
+
+ABOUT: "strftime"
+
+
diff --git a/extra/time/time-tests.factor b/extra/time/time-tests.factor
new file mode 100644 (file)
index 0000000..0b0602b
--- /dev/null
@@ -0,0 +1,24 @@
+! Copyright (C) 2008 John Benediktsson
+! See http://factorcode.org/license.txt for BSD license
+
+USING: kernel time tools.test calendar ;
+
+IN: time.tests
+
+[ "%H:%M:%S" strftime ] must-infer 
+
+: testtime ( -- timestamp )
+    2008 10 9 12 3 15 instant <timestamp> ;
+
+[ t ] [ "12:03:15" testtime "%H:%M:%S" strftime = ] unit-test
+[ t ] [ "12:03:15" testtime "%X" strftime = ] unit-test
+
+[ t ] [ "10/09/2008" testtime "%m/%d/%Y" strftime = ] unit-test
+[ t ] [ "10/09/2008" testtime "%x" strftime = ] unit-test
+
+[ t ] [ "Thu" testtime "%a" strftime = ] unit-test
+[ t ] [ "Thursday" testtime "%A" strftime = ] unit-test
+
+[ t ] [ "Oct" testtime "%b" strftime = ] unit-test
+[ t ] [ "October" testtime "%B" strftime = ] unit-test
+
diff --git a/extra/time/time.factor b/extra/time/time.factor
new file mode 100644 (file)
index 0000000..be19fb0
--- /dev/null
@@ -0,0 +1,72 @@
+! Copyright (C) 2008 John Benediktsson
+! See http://factorcode.org/license.txt for BSD license
+
+USING: accessors arrays calendar io kernel fry macros math
+math.functions math.parser peg.ebnf sequences strings vectors ;
+
+IN: time
+
+: >timestring ( timestamp -- string ) 
+    [ hour>> ] keep [ minute>> ] keep second>> 3array
+    [ number>string 2 CHAR: 0 pad-left ] map ":" join ; inline
+
+: >datestring ( timestamp -- string )
+    [ month>> ] keep [ day>> ] keep year>> 3array
+    [ number>string 2 CHAR: 0 pad-left ] map "/" join ; inline
+
+: (week-of-year) ( timestamp day -- n )
+    [ dup clone 1 >>month 1 >>day day-of-week dup ] dip > [ 7 swap - ] when
+    [ day-of-year ] dip 2dup < [ 0 2nip ] [ - 7 / 1+ >fixnum ] if ;
+
+: week-of-year-sunday ( timestamp -- n ) 0 (week-of-year) ; inline
+
+: week-of-year-monday ( timestamp -- n ) 1 (week-of-year) ; inline
+
+
+<PRIVATE
+
+EBNF: parse-format-string
+
+fmt-%     = "%"                  => [[ [ "%" ] ]]
+fmt-a     = "a"                  => [[ [ dup day-of-week day-abbreviation3 ] ]]
+fmt-A     = "A"                  => [[ [ dup day-of-week day-name ] ]] 
+fmt-b     = "b"                  => [[ [ dup month>> month-abbreviation ] ]]
+fmt-B     = "B"                  => [[ [ dup month>> month-name ] ]] 
+fmt-c     = "c"                  => [[ [ "Not yet implemented" throw ] ]]
+fmt-d     = "d"                  => [[ [ dup day>> number>string 2 CHAR: 0 pad-left ] ]] 
+fmt-H     = "H"                  => [[ [ dup hour>> number>string 2 CHAR: 0 pad-left ] ]]
+fmt-I     = "I"                  => [[ [ dup hour>> 12 > [ 12 - ] when number>string 2 CHAR: 0 pad-left ] ]] 
+fmt-j     = "j"                  => [[ [ dup day-of-year number>string ] ]] 
+fmt-m     = "m"                  => [[ [ dup month>> number>string 2 CHAR: 0 pad-left ] ]] 
+fmt-M     = "M"                  => [[ [ dup minute>> number>string 2 CHAR: 0 pad-left ] ]] 
+fmt-p     = "p"                  => [[ [ dup hour>> 12 < [ "AM" ] [ "PM" ] ? ] ]] 
+fmt-S     = "S"                  => [[ [ dup second>> round number>string 2 CHAR: 0 pad-left ] ]] 
+fmt-U     = "U"                  => [[ [ dup week-of-year-sunday ] ]] 
+fmt-w     = "w"                  => [[ [ dup day-of-week number>string ] ]] 
+fmt-W     = "W"                  => [[ [ dup week-of-year-monday ] ]] 
+fmt-x     = "x"                  => [[ [ dup >datestring ] ]] 
+fmt-X     = "X"                  => [[ [ dup >timestring ] ]] 
+fmt-y     = "y"                  => [[ [ dup year>> 100 mod number>string ] ]] 
+fmt-Y     = "Y"                  => [[ [ dup year>> number>string ] ]] 
+fmt-Z     = "Z"                  => [[ [ "Not yet implemented" throw ] ]] 
+unknown   = (.)*                 => [[ "Unknown directive" throw ]]
+
+formats_  = fmt-%|fmt-a|fmt-A|fmt-b|fmt-B|fmt-c|fmt-d|fmt-H|fmt-I|
+            fmt-j|fmt-m|fmt-M|fmt-p|fmt-S|fmt-U|fmt-w|fmt-W|fmt-x|
+            fmt-X|fmt-y|fmt-Y|fmt-Z|unknown
+
+formats   = "%" (formats_)       => [[ second '[ _ dip ] ]]
+
+plain-text = (!("%").)+          => [[ >string '[ _ swap ] ]]
+
+text      = (formats|plain-text)* => [[ reverse [ [ [ push ] keep ] append ] map ]]
+
+;EBNF
+
+PRIVATE>
+
+MACRO: strftime ( format-string -- )
+    parse-format-string [ length ] keep [ ] join 
+    '[ _ <vector> @ reverse concat nip ] ;
+
+
diff --git a/extra/trails/trails.factor b/extra/trails/trails.factor
new file mode 100644 (file)
index 0000000..cea5ece
--- /dev/null
@@ -0,0 +1,96 @@
+
+USING: kernel accessors locals namespaces sequences sequences.lib threads
+       math math.order math.vectors
+       calendar
+       colors opengl ui ui.gadgets ui.gestures ui.render
+       circular
+       processing.shapes ;
+
+IN: trails
+
+! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+
+! Example 33-15 from the Processing book
+
+! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+
+! Return the mouse location relative to the current gadget
+
+: mouse ( -- point ) hand-loc get  hand-gadget get screen-loc  v- ;
+
+! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+
+: point-list ( n -- seq ) [ drop { 0 0 } ] map <circular> ;
+
+! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+
+: percent->radius ( percent -- radius ) neg 1 + 25 * 5 max ;
+
+: dot ( pos percent -- ) percent->radius circle ;
+
+! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+
+TUPLE: <trails-gadget> < gadget paused points ;
+
+! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+
+:: iterate-system ( GADGET -- )
+
+  ! Add a valid point if the mouse is in the gadget
+  ! Otherwise, add an "invisible" point
+  
+  hand-gadget get GADGET =
+    [ mouse       GADGET points>> push-circular ]
+    [ { -10 -10 } GADGET points>> push-circular ]
+  if ;
+
+! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+
+:: start-trails-thread ( GADGET -- )
+  GADGET f >>paused drop
+  [
+    [
+      GADGET paused>>
+        [ f ]
+        [ GADGET iterate-system GADGET relayout-1 1 milliseconds sleep t ]
+      if
+    ]
+    loop
+  ]
+  in-thread ;
+
+! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+
+M: <trails-gadget> pref-dim* ( <trails-gadget> -- dim ) drop { 500 500 } ;
+
+! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+
+M:: <trails-gadget> draw-gadget* ( GADGET -- )
+  origin get
+  [
+    T{ rgba f 1 1 1 0.4 } \ fill-color set   ! White, with some transparency
+    T{ rgba f 0 0 0 0   } \ stroke-color set ! no stroke
+    
+    black gl-clear
+
+    GADGET points>> [ dot ] each-percent
+  ]
+  with-translation ;
+
+! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+
+: trails-gadget ( -- <trails-gadget> )
+
+  <trails-gadget> new-gadget
+
+    300 point-list >>points
+
+    t >>clipped?
+
+  dup start-trails-thread ;
+
+: trails-window ( -- ) [ trails-gadget "Trails" open-window ] with-ui ;
+
+! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+
+MAIN: trails-window
\ No newline at end of file
old mode 100644 (file)
new mode 100755 (executable)
index 9fe8577..779ecc0
@@ -25,7 +25,7 @@ M: offscreen-world ungraft*
 : offscreen-world>bitmap ( world -- bitmap )
     [ handle>> offscreen-pixels ] [ dim>> first2 neg ] bi
     bgra>bitmap ;
-    
+
 : do-offscreen ( gadget quot: ( offscreen-world -- ) -- )
     [ open-offscreen ] dip
     over [ slip ] [ close-offscreen ] [ ] cleanup ;
index 078490abfdfc0ec5f4ff8f120d3598f9658a219c..18f6fa1e94e271c3867ca7fab38183f5b6b8fa58 100644 (file)
@@ -47,18 +47,29 @@ M-x customize-group fuel will show you how many.
 Quick key reference
 -------------------
 
+(Chords ending in a single letter <x> accept also C-<x> (e.g. C-cC-z is
+the same as C-cz)).
+
+* In factor files:
+
  - C-cz : switch to listener
  - C-co : cycle between code, tests and docs factor files
 
- - M-. : edit word at point in Emacs
+ - M-. : edit word at point in Emacs (also in listener)
 
  - C-cr, C-cC-er : eval region
  - C-M-r, C-cC-ee : eval region, extending it to definition boundaries
  - C-M-x, C-cC-ex : eval definition around point
+ - C-ck, C-cC-ek : compile file
 
  - C-cC-da : toggle autodoc mode
  - C-cC-dd : help for word at point
  - C-cC-ds : short help word at point
 
-Chords ending in a single letter <x> accept also C-<x> (e.g. C-cC-z is
-the same as C-cz).
+* In the debugger (it pops up upon eval/compilation errors):
+
+ - g : go to error
+ - <digit> : invoke nth restart
+ - q : bury buffer
+
+
index d79930bb226b22e7ac5fe4388770b1d5812e1657..b3952074f5376fe7b7efed2428a3e63336f185ae 100644 (file)
@@ -59,6 +59,23 @@ code in the buffer."
   :type 'hook
   :group 'factor-mode)
 
+\f
+;;; Faces:
+
+(fuel-font-lock--define-faces
+ factor-font-lock font-lock factor-mode
+ ((comment comment "comments")
+  (constructor type  "constructors (<foo>)")
+  (declaration keyword "declaration words")
+  (parsing-word keyword  "parsing words")
+  (setter-word function-name "setter words (>>foo)")
+  (stack-effect comment "stack effect specifications")
+  (string string "strings")
+  (symbol variable-name "name of symbol being defined")
+  (type-name type "type names")
+  (vocabulary-name constant "vocabulary names")
+  (word function-name "word, generic or method being defined")))
+
 \f
 ;;; Syntax table:
 
diff --git a/misc/fuel/fuel-debug.el b/misc/fuel/fuel-debug.el
new file mode 100644 (file)
index 0000000..b3aad7f
--- /dev/null
@@ -0,0 +1,266 @@
+;;; fuel-debug.el -- debugging factor code
+
+;; Copyright (C) 2008 Jose Antonio Ortega Ruiz
+;; See http://factorcode.org/license.txt for BSD license.
+
+;; Author: Jose Antonio Ortega Ruiz <jao@gnu.org>
+;; Keywords: languages, fuel, factor
+;; Start date: Sun Dec 07, 2008 04:16
+
+;;; Comentary:
+
+;; A mode for displaying the results of run-file and evaluation, with
+;; support for restarts.
+
+;;; Code:
+
+(require 'fuel-base)
+(require 'fuel-eval)
+(require 'fuel-font-lock)
+
+\f
+;;; Customization:
+
+(defgroup fuel-debug nil
+  "Major mode for interaction with the Factor debugger"
+  :group 'fuel)
+
+(defcustom fuel-debug-mode-hook nil
+  "Hook run after `fuel-debug-mode' activates"
+  :group 'fuel-debug
+  :type 'hook)
+
+(defcustom fuel-debug-show-short-help t
+  "Whether to show short help on available keys in debugger"
+  :group 'fuel-debug
+  :type 'boolean)
+
+(fuel-font-lock--define-faces
+ fuel-debug-font-lock font-lock fuel-debug
+ ((error warning "highlighting errors")
+  (line variable-name "line numbers in errors/warnings")
+  (column variable-name "column numbers in errors/warnings")
+  (info comment "information headers")
+  (restart-number warning "restart numbers")
+  (restart-name function-name "restart names")))
+
+\f
+;;; Font lock and other pattern matching:
+
+(defconst fuel-debug--compiler-info-alist
+  '((":warnings" . ?w) (":errors" . ?e) (":linkage" . ?l)))
+
+(defconst fuel-debug--error-file-regex "^P\" \\([^\"]+\\)\"")
+(defconst fuel-debug--error-line-regex "\\([0-9]+\\):")
+(defconst fuel-debug--error-cont-regex "^ +\\(\\^\\)$")
+
+(defconst fuel-debug--error-regex
+  (format "%s\n%s"
+          fuel-debug--error-file-regex
+          fuel-debug--error-line-regex))
+
+(defconst fuel-debug--compiler-info-regex
+  (format "^\\(%s\\) "
+          (regexp-opt (mapcar 'car fuel-debug--compiler-info-alist))))
+
+(defconst fuel-debug--restart-regex "^:\\([0-9]+\\) \\(.+\\)")
+
+(defconst fuel-debug--font-lock-keywords
+  `((,fuel-debug--error-file-regex . 'fuel-debug-font-lock-error)
+    (,fuel-debug--error-line-regex 1 'fuel-debug-font-lock-line)
+    (,fuel-debug--error-cont-regex 1 'fuel-debug-font-lock-column)
+    (,fuel-debug--restart-regex (1 'fuel-debug-font-lock-restart-number)
+                                (2 'fuel-debug-font-lock-restart-name))
+    (,fuel-debug--compiler-info-regex 1 'fuel-debug-font-lock-restart-number)
+    ("^\\(Restarts?\\|Loading\\) .+$" . 'fuel-debug-font-lock-info)
+    ("^Error: " . 'fuel-debug-font-lock-error)))
+
+(defun fuel-debug--font-lock-setup ()
+  (set (make-local-variable 'font-lock-defaults)
+       '(fuel-debug--font-lock-keywords t nil nil nil)))
+
+\f
+;;; Debug buffer:
+
+(defvar fuel-debug--buffer nil)
+
+(make-variable-buffer-local
+ (defvar fuel-debug--last-ret nil))
+
+(make-variable-buffer-local
+ (defvar fuel-debug--file nil))
+
+(defun fuel-debug--buffer ()
+  (or (and (buffer-live-p fuel-debug--buffer) fuel-debug--buffer)
+      (with-current-buffer
+          (setq fuel-debug--buffer (get-buffer-create "*fuel dbg*"))
+        (fuel-debug-mode)
+        (current-buffer))))
+
+(defun fuel-debug--display-retort (ret &optional success-msg no-pop file)
+  (let ((err (fuel-eval--retort-error ret))
+        (inhibit-read-only t))
+    (with-current-buffer (fuel-debug--buffer)
+      (erase-buffer)
+      (fuel-debug--display-output ret)
+      (delete-blank-lines)
+      (newline)
+      (when (and (not err) success-msg)
+        (message "%s" success-msg)
+        (insert "\n" success-msg "\n"))
+      (when err
+        (fuel-debug--display-restarts err)
+        (delete-blank-lines)
+        (newline)
+        (let ((hstr (fuel-debug--help-string err file)))
+          (if fuel-debug-show-short-help
+              (insert "-----------\n" hstr "\n")
+            (message "%s" hstr))))
+      (setq fuel-debug--last-ret ret)
+      (setq fuel-debug--file file)
+      (goto-char (point-max))
+      (when (and err (not no-pop)) (pop-to-buffer fuel-debug--buffer))
+      (not err))))
+
+(defun fuel-debug--display-output (ret)
+  (let* ((last (fuel-eval--retort-output fuel-debug--last-ret))
+         (current (fuel-eval--retort-output ret))
+         (llen (length last))
+         (clen (length current))
+         (trail (and last (substring-no-properties last (/ llen 2))))
+         (err (fuel-eval--retort-error ret))
+         (p (point)))
+    (save-excursion (insert current))
+    (when (and (> clen llen) (> llen 0) (search-forward trail nil t))
+      (delete-region p (point)))
+    (goto-char (point-max))
+    (when err
+      (insert (format "\nError: %S\n\n" (fuel-eval--error-name err))))))
+
+(defun fuel-debug--display-restarts (err)
+  (let* ((rs (fuel-eval--error-restarts err))
+         (rsn (length rs)))
+    (when rs
+      (insert "Restarts:\n\n")
+      (dotimes (n rsn)
+        (insert (format ":%s %s\n" (1+ n) (nth n rs))))
+      (newline))))
+
+(defun fuel-debug--help-string (err &optional file)
+  (format "Press %s%s%sq bury buffer"
+          (if (or file (fuel-eval--error-file err)) "g go to file, " "")
+          (let ((rsn (length (fuel-eval--error-restarts err))))
+            (cond ((zerop rsn) "")
+                  ((= 1 rsn) "1 invoke restart, ")
+                  (t (format "1-%s invoke restarts, " rsn))))
+          (let ((str ""))
+            (dolist (ci fuel-debug--compiler-info-alist str)
+              (save-excursion
+                (goto-char (point-min))
+                (when (search-forward (car ci) nil t)
+                  (setq str (format "%c %s, %s" (cdr ci) (car ci) str))))))))
+
+(defun fuel-debug--buffer-file ()
+  (with-current-buffer (fuel-debug--buffer)
+    (or fuel-debug--file
+        (and fuel-debug--last-ret
+             (fuel-eval--error-file
+              (fuel-eval--retort-error fuel-debug--last-ret))))))
+
+(defsubst fuel-debug--buffer-error ()
+  (fuel-eval--retort-error fuel-debug--last-ret))
+
+(defsubst fuel-debug--buffer-restarts ()
+  (fuel-eval--error-restarts (fuel-debug--buffer-error)))
+
+\f
+;;; Buffer navigation:
+
+(defun fuel-debug-goto-error ()
+  (interactive)
+  (let* ((err (or (fuel-debug--buffer-error)
+                  (error "No errors reported")))
+         (file (or (fuel-debug--buffer-file)
+                   (error "No file associated with error")))
+         (l/c (fuel-eval--error-line/column err))
+         (line (or (car l/c) 1))
+         (col (or (cdr l/c) 0)))
+    (find-file-other-window file)
+    (goto-line line)
+    (forward-char col)))
+
+(defun fuel-debug--read-restart-no ()
+  (let ((rs (fuel-debug--buffer-restarts)))
+    (unless rs (error "No restarts available"))
+    (let* ((rsn (length rs))
+           (prompt (format "Restart number? (1-%s): " rsn))
+           (no 0))
+      (while (or (> (setq no (read-number prompt)) rsn)
+                 (< no 1)))
+      no)))
+
+(defun fuel-debug-exec-restart (&optional n confirm)
+  (interactive (list (fuel-debug--read-restart-no)))
+  (let ((n (or n 1))
+        (rs (fuel-debug--buffer-restarts)))
+    (when (zerop (length rs))
+      (error "No restarts available"))
+    (when (or (< n 1) (> n (length rs)))
+      (error "Restart %s not available" n))
+    (when (or (not confirm)
+              (y-or-n-p (format "Invoke restart %s? " n)))
+      (message "Invoking restart %s" n)
+      (let* ((file (fuel-debug--buffer-file))
+             (buffer (if file (find-file-noselect file) (current-buffer))))
+        (with-current-buffer buffer
+          (fuel-debug--display-retort
+           (fuel-eval--eval-string/context (format ":%s" n))
+           (format "Restart %s (%s) successful" n (nth (1- n) rs))))))))
+
+(defun fuel-debug-show--compiler-info (info)
+  (save-excursion
+    (goto-char (point-min))
+    (unless (re-search-forward (format "^%s" info) nil t)
+      (error "%s information not available" info))
+    (message "Retrieving %s info ..." info)
+    (unless (fuel-debug--display-retort
+             (fuel-eval--eval-string info) "" (fuel-debug--buffer-file))
+      (error "Sorry, no %s info available" info))))
+
+\f
+;;; Fuel Debug mode:
+
+(defvar fuel-debug-mode-map
+  (let ((map (make-keymap)))
+    (suppress-keymap map)
+    (define-key map "g" 'fuel-debug-goto-error)
+    (define-key map "\C-c\C-c" 'fuel-debug-goto-error)
+    (define-key map "n" 'next-line)
+    (define-key map "p" 'previous-line)
+    (define-key map "q" 'bury-buffer)
+    (dotimes (n 9)
+      (define-key map (vector (+ ?1 n))
+        `(lambda () (interactive) (fuel-debug-exec-restart ,(1+ n) t))))
+    (dolist (ci fuel-debug--compiler-info-alist)
+      (define-key map (vector (cdr ci))
+        `(lambda () (interactive) (fuel-debug-show--compiler-info ,(car ci)))))
+    map))
+
+(defun fuel-debug-mode ()
+  "A major mode for displaying Factor's compilation results and
+invoking restarts as needed.
+\\{fuel-debug-mode-map}"
+  (interactive)
+  (kill-all-local-variables)
+  (setq major-mode 'factor-mode)
+  (setq mode-name "Fuel Debug")
+  (use-local-map fuel-debug-mode-map)
+  (fuel-debug--font-lock-setup)
+  (setq fuel-debug--file nil)
+  (setq fuel-debug--last-ret nil)
+  (toggle-read-only 1)
+  (run-hooks 'fuel-debug-mode-hook))
+
+\f
+(provide 'fuel-debug)
+;;; fuel-debug.el ends here
index bef7171f6fb308a477dce1bd96f2c97406e36bff..62001cc48c2785f6228a196275a2f4c8e7bd96d7 100644 (file)
@@ -38,7 +38,8 @@
         (when (and (> fuel-eval-log-max-length 0)
                    (> (point) fuel-eval-log-max-length))
           (erase-buffer))
-        (when fuel-eval--log (insert "\n>> " (fuel--shorten-str str 256) "\n"))
+        (when fuel-eval--log (insert "\n>> " (fuel--shorten-str str 256)))
+        (newline)
         (let ((beg (point)))
           (comint-redirect-send-command-to-process str (current-buffer) proc nil t)
           (with-current-buffer (process-buffer proc)
@@ -58,8 +59,6 @@
 
 (defsubst fuel-eval--retort-p (ret) (listp ret))
 
-(defsubst fuel-eval--error-name (err) (car err))
-
 (defsubst fuel-eval--make-parse-error-retort (str)
   (fuel-eval--retort-make 'parse-retort-error nil str))
 
 (defsubst fuel-eval--factor-array (strs)
   (format "V{ %S }" (mapconcat 'identity strs " ")))
 
-(defsubst fuel-eval--eval-strings (strs)
-  (let ((str (format "%s fuel-eval" (fuel-eval--factor-array strs))))
+(defsubst fuel-eval--eval-strings (strs &optional no-restart)
+  (let ((str (format "fuel-eval-%s %s fuel-eval"
+                     (if no-restart "non-restartable" "restartable")
+                     (fuel-eval--factor-array strs))))
     (fuel-eval--send/retort str)))
 
-(defsubst fuel-eval--eval-string (str)
-  (fuel-eval--eval-strings (list str)))
+(defsubst fuel-eval--eval-string (str &optional no-restart)
+  (fuel-eval--eval-strings (list str) no-restart))
 
-(defun fuel-eval--eval-strings/context (strs)
+(defun fuel-eval--eval-strings/context (strs &optional no-restart)
   (let ((usings (fuel-syntax--usings-update)))
     (fuel-eval--send/retort
-     (format "%s %S %s fuel-eval-in-context"
+     (format "fuel-eval-%s %s %S %s fuel-eval-in-context"
+             (if no-restart "non-restartable" "restartable")
              (fuel-eval--factor-array strs)
              (or fuel-syntax--current-vocab "f")
              (if usings (fuel-eval--factor-array usings) "f")))))
 
-(defsubst fuel-eval--eval-string/context (str)
-  (fuel-eval--eval-strings/context (list str)))
+(defsubst fuel-eval--eval-string/context (str &optional no-restart)
+  (fuel-eval--eval-strings/context (list str) no-restart))
 
-(defun fuel-eval--eval-region/context (begin end)
+(defun fuel-eval--eval-region/context (begin end &optional no-restart)
   (let ((lines (split-string (buffer-substring-no-properties begin end)
                              "[\f\n\r\v]+" t)))
     (when (> (length lines) 0)
-      (fuel-eval--eval-strings/context lines))))
+      (fuel-eval--eval-strings/context lines no-restart))))
+
+\f
+;;; Error parsing
+
+(defsubst fuel-eval--error-name (err) (car err))
+
+(defsubst fuel-eval--error-restarts (err)
+  (cdr (assoc :restarts (fuel-eval--error-name-p err 'condition))))
+
+(defun fuel-eval--error-name-p (err name)
+  (unless (null err)
+    (or (and (eq (fuel-eval--error-name err) name) err)
+        (assoc name err))))
+
+(defsubst fuel-eval--error-file (err)
+  (nth 1 (fuel-eval--error-name-p err 'source-file-error)))
+
+(defsubst fuel-eval--error-lexer-p (err)
+  (or (fuel-eval--error-name-p err 'lexer-error)
+      (fuel-eval--error-name-p (fuel-eval--error-name-p err 'source-file-error)
+                               'lexer-error)))
+
+(defsubst fuel-eval--error-line/column (err)
+  (let ((err (fuel-eval--error-lexer-p err)))
+    (cons (nth 1 err) (nth 2 err))))
+
+(defsubst fuel-eval--error-line-text (err)
+  (nth 3 (fuel-eval--error-lexer-p err)))
 
 \f
 (provide 'fuel-eval)
index c8673f742bddf9dbca5f4b1cbe8aa9a08c36d020..4c710635ba56d4b8b4f33f3fc7fef84eab9c312d 100644 (file)
 \f
 ;;; Faces:
 
-(defmacro fuel-font-lock--face (face def doc)
-  (let ((face (intern (format "factor-font-lock-%s" (symbol-name face))))
-        (def (intern (format "font-lock-%s-face" (symbol-name def)))))
+(defmacro fuel-font-lock--make-face (prefix def-prefix group face def doc)
+  (let ((face (intern (format "%s-%s" prefix face)))
+        (def (intern (format "%s-%s-face" def-prefix def))))
     `(defface ,face (face-default-spec ,def)
        ,(format "Face for %s." doc)
-       :group 'factor-mode
+       :group ',group
        :group 'faces)))
 
-(defmacro fuel-font-lock--faces-setup ()
-  (cons 'progn
-        (mapcar (lambda (f) (cons 'fuel-font-lock--face f))
-                '((comment comment "comments")
-                  (constructor type  "constructors (<foo>)")
-                  (declaration keyword "declaration words")
-                  (parsing-word keyword  "parsing words")
-                  (setter-word function-name "setter words (>>foo)")
-                  (stack-effect comment "stack effect specifications")
-                  (string string "strings")
-                  (symbol variable-name "name of symbol being defined")
-                  (type-name type "type names")
-                  (vocabulary-name constant "vocabulary names")
-                  (word function-name "word, generic or method being defined")))))
-
-(fuel-font-lock--faces-setup)
+(defmacro fuel-font-lock--define-faces (prefix def-prefix group faces)
+  (let ((setup (make-symbol (format "%s--faces-setup" prefix))))
+  `(progn
+     (defmacro ,setup ()
+       (cons 'progn
+             (mapcar (lambda (f) (append '(fuel-font-lock--make-face
+                                      ,prefix ,def-prefix ,group) f))
+                     ',faces)))
+     (,setup))))
 
 \f
 ;;; Font lock:
index dcf17d27168be4ff2b0d91f7fecba5abcda25b0c..1db9b25d69787b9c30c8db57292f96ec8dfefde5 100644 (file)
 
 (defun fuel-help--word-synopsis (&optional word)
   (let ((word (or word (fuel-syntax-symbol-at-point)))
-        (fuel-eval--log nil))
+        (fuel-eval--log t))
     (when word
       (let ((ret (fuel-eval--eval-string/context
-                  (format "\\ %s synopsis fuel-eval-set-result" word))))
+                  (format "\\ %s synopsis fuel-eval-set-result" word)
+                  t)))
         (when (not (fuel-eval--retort-error ret))
           (if fuel-help-minibuffer-font-lock
               (fuel-help--font-lock-str (fuel-eval--retort-result ret))
@@ -170,7 +171,7 @@ displayed in the minibuffer."
          (def (if ask (read-string prompt nil 'fuel-help--history def) def))
          (cmd (format "\\ %s %s" def (if see "see" "help")))
          (fuel-eval--log nil)
-         (ret (fuel-eval--eval-string/context cmd))
+         (ret (fuel-eval--eval-string/context cmd t))
          (out (fuel-eval--retort-output ret)))
     (if (or (fuel-eval--retort-error ret) (empty-string-p out))
         (message "No help for '%s'" def)
index c741a77a5d2797b7a2b5f86553f3f280cd9b93e6..9fa330993c2015a6201b70ed18558014480ff5f5 100644 (file)
@@ -59,10 +59,15 @@ buffer."
       (error "Could not run factor: %s is not executable" factor))
     (unless (file-readable-p image)
       (error "Could not run factor: image file %s not readable" image))
-    (setq fuel-listener-buffer
-          (make-comint "fuel listener" factor nil "-run=fuel" (format "-i=%s" image)))
+    (setq fuel-listener-buffer (get-buffer-create "*fuel listener*"))
     (with-current-buffer fuel-listener-buffer
-      (fuel-listener-mode))))
+      (fuel-listener-mode)
+      (message "Starting FUEL listener ...")
+      (comint-exec fuel-listener-buffer "factor"
+                   factor nil `("-run=fuel" ,(format "-i=%s" image)))
+      (fuel-listener--wait-for-prompt 20)
+      (fuel-eval--send-string "USE: fuel")
+      (message "FUEL listener up and running!"))))
 
 (defun fuel-listener--process (&optional start)
   (or (and (buffer-live-p fuel-listener-buffer)
@@ -74,6 +79,23 @@ buffer."
 
 (setq fuel-eval--default-proc-function 'fuel-listener--process)
 
+\f
+;;; Prompt chasing
+
+(defun fuel-listener--wait-for-prompt (&optional timeout)
+    (let ((proc (get-buffer-process fuel-listener-buffer))
+          (seen))
+      (with-current-buffer fuel-listener-buffer
+        (while (progn (goto-char comint-last-input-end)
+                      (not (or seen
+                               (setq seen
+                                     (re-search-forward comint-prompt-regexp nil t))
+                               (not (accept-process-output proc timeout))))))
+        (goto-char (point-max)))
+      (unless seen
+        (pop-to-buffer fuel-listener-buffer)
+        (error "No prompt found!"))))
+
 \f
 ;;; Interface: starting fuel listener
 
@@ -94,30 +116,17 @@ buffer."
 
 (defconst fuel-listener--prompt-regex "( [^)]* ) ")
 
-(defun fuel-listener--wait-for-prompt (&optional timeout)
-  (let ((proc (fuel-listener--process)))
-    (with-current-buffer fuel-listener-buffer
-      (goto-char comint-last-input-end)
-      (while (not (or (re-search-forward comint-prompt-regexp nil t)
-                      (not (accept-process-output proc timeout))))
-        (goto-char comint-last-input-end))
-      (goto-char (point-max)))))
-
-(defun fuel-listener--startup ()
-  (fuel-listener--wait-for-prompt)
-  (fuel-eval--send-string "USE: fuel")
-  (message "FUEL listener up and running!"))
-
 (define-derived-mode fuel-listener-mode comint-mode "Fuel Listener"
   "Major mode for interacting with an inferior Factor listener process.
 \\{fuel-listener-mode-map}"
   (set (make-local-variable 'comint-prompt-regexp)
        fuel-listener--prompt-regex)
   (set (make-local-variable 'comint-prompt-read-only) t)
-  (fuel-listener--startup))
+  (setq fuel-listener--compilation-begin nil))
 
-;; (define-key fuel-listener-mode-map "\C-w" 'comint-kill-region)
-;; (define-key fuel-listener-mode-map "\C-k" 'comint-kill-whole-line)
+(define-key fuel-listener-mode-map "\C-ch" 'fuel-help)
+(define-key fuel-listener-mode-map "\M-." 'fuel-edit-word-at-point)
+(define-key fuel-listener-mode-map "\C-ck" 'fuel-run-file)
 
 \f
 (provide 'fuel-listener)
index bd9b127c7dd2a44a0d61dcf24ef6bbee7a3511c4..ea1d4b93ed0c196ddcebd387eaff22f6f4c89d81 100644 (file)
@@ -18,6 +18,7 @@
 (require 'fuel-base)
 (require 'fuel-syntax)
 (require 'fuel-font-lock)
+(require 'fuel-debug)
 (require 'fuel-help)
 (require 'fuel-eval)
 (require 'fuel-listener)
 \f
 ;;; User commands
 
+(defun fuel-run-file (&optional arg)
+  "Sends the current file to Factor for compilation.
+With prefix argument, ask for the file to run."
+  (interactive "P")
+  (let* ((file (or (and arg (read-file-name "File: " nil (buffer-file-name) t))
+                   (buffer-file-name)))
+         (file (expand-file-name file))
+         (buffer (find-file-noselect file))
+         (cmd (format "%S fuel-run-file" file)))
+    (when buffer
+      (with-current-buffer buffer
+        (message "Compiling %s ..." file)
+        (let ((r (fuel-debug--display-retort (fuel-eval--eval-string/context cmd)
+                                             (format "%s successfully compiled" file)
+                                             nil
+                                             file)))
+          (if r (message "Compiling %s ... OK!" file) (message "")))))))
+
 (defun fuel-eval-region (begin end &optional arg)
   "Sends region to Fuel's listener for evaluation.
-With prefix, switchs to the listener's buffer afterwards."
+Unless called with a prefix, switchs to the compilation results
+buffer in case of errors."
   (interactive "r\nP")
-  (let* ((ret (fuel-eval--eval-region/context begin end))
-         (err (fuel-eval--retort-error ret)))
-    (message "%s" (or err (fuel--shorten-region begin end 70))))
-  (when arg (pop-to-buffer fuel-listener-buffer)))
+  (fuel-debug--display-retort
+   (fuel-eval--eval-region/context begin end)
+   (format "%s%s"
+           (if fuel-syntax--current-vocab
+               (format "IN: %s " fuel-syntax--current-vocab)
+             "")
+           (fuel--shorten-region begin end 70))
+   arg
+   (buffer-file-name)))
 
 (defun fuel-eval-extended-region (begin end &optional arg)
   "Sends region extended outwards to nearest definitions,
-to Fuel's listener for evaluation. With prefix, switchs to the
-listener's buffer afterwards."
+to Fuel's listener for evaluation.
+Unless called with a prefix, switchs to the compilation results
+buffer in case of errors."
   (interactive "r\nP")
   (fuel-eval-region (save-excursion (goto-char begin) (mark-defun) (point))
-                    (save-excursion (goto-char end) (mark-defun) (mark))))
+                    (save-excursion (goto-char end) (mark-defun) (mark))
+                    arg))
 
 (defun fuel-eval-definition (&optional arg)
   "Sends definition around point to Fuel's listener for evaluation.
-With prefix, switchs to the listener's buffer afterwards."
+Unless called with a prefix, switchs to the compilation results
+buffer in case of errors."
   (interactive "P")
   (save-excursion
     (mark-defun)
     (let* ((begin (point))
            (end (mark)))
       (unless (< begin end) (error "No evaluable definition around point"))
-      (fuel-eval-region begin end))))
+      (fuel-eval-region begin end arg))))
 
 (defun fuel-edit-word-at-point (&optional arg)
   "Opens a new window visiting the definition of the word at point.
@@ -128,6 +156,9 @@ interacting with a factor listener is at your disposal.
 
 (fuel-mode--key-1 ?z 'run-factor)
 
+(fuel-mode--key-1 ?k 'fuel-run-file)
+(fuel-mode--key ?e ?k 'fuel-run-file)
+
 (define-key fuel-mode-map "\C-\M-x" 'fuel-eval-definition)
 (fuel-mode--key ?e ?x 'fuel-eval-definition)
 
index 6ed5ea43095574c53287202c81cecf174bd3f0e2..9a1c45c7df9e90c287f96ea56ba70c9757331b92 100755 (executable)
@@ -147,6 +147,8 @@ void apply_relocation(CELL class, CELL offset, F_FIXNUM absolute_value)
 /* Perform all fixups on a code block */
 void relocate_code_block(F_COMPILED *compiled, CELL code_start, CELL literals_start)
 {
+       compiled->last_scan = NURSERY;
+
        if(compiled->relocation != F)
        {
                F_BYTE_ARRAY *relocation = untag_object(compiled->relocation);
index 513a7c429c258c458003aec40d5a8792899454e5..2122f930f0569e4f4be826812d3f1dd498f09f84 100755 (executable)
@@ -32,9 +32,7 @@ F_DATA_HEAP *alloc_data_heap(CELL gens,
        data_heap->gen_count = gens;
 
        CELL total_size;
-       if(data_heap->gen_count == 1)
-               total_size = 2 * tenured_size;
-       else if(data_heap->gen_count == 2)
+       if(data_heap->gen_count == 2)
                total_size = young_size + 2 * tenured_size;
        else if(data_heap->gen_count == 3)
                total_size = young_size + 2 * aging_size + 2 * tenured_size;
@@ -985,7 +983,8 @@ void primitive_become(void)
        }
 
        gc();
-       iterate_code_heap(relocate_code_block);
+
+       compile_all_words();
 }
 
 CELL find_all_words(void)
index 4ec3fdd5f2be752ed84bb41924ad756b3ee4acc7..6d367a25fda9fc3cef1314194507fe68678abc4e 100755 (executable)
@@ -137,6 +137,7 @@ void collect_cards(void);
 /* the oldest generation */
 #define TENURED (data_heap->gen_count-1)
 
+#define MIN_GEN_COUNT 1
 #define MAX_GEN_COUNT 3
 
 /* used during garbage collection only */
index f198370ebe9d944626d4972c69fa10696834df0e..2f78a797d4ee032fab85733997208385f46f5cad 100755 (executable)
@@ -44,25 +44,7 @@ void do_stage1_init(void)
        print_string("*** Stage 2 early init... ");
        fflush(stdout);
 
-       CELL words = find_all_words();
-
-       REGISTER_ROOT(words);
-
-       CELL i;
-       CELL length = array_capacity(untag_object(words));
-       for(i = 0; i < length; i++)
-       {
-               F_WORD *word = untag_word(array_nth(untag_array(words),i));
-               REGISTER_UNTAGGED(word);
-               default_word_code(word,false);
-               UNREGISTER_UNTAGGED(word);
-               update_word_xt(word);
-       }
-
-       UNREGISTER_ROOT(words);
-
-       iterate_code_heap(relocate_code_block);
-
+       compile_all_words();
        userenv[STAGE2_ENV] = T;
 
        print_string("done\n");
index a01a8653b7879a6af41d873b1ab0fd1506fe3c6e..dcf082d40d86304406c684cd4d75137c1ff1b88b 100755 (executable)
@@ -74,6 +74,7 @@ void *primitives[] = {
        primitive_dlsym,
        primitive_dlclose,
        primitive_byte_array,
+       primitive_uninitialized_byte_array,
        primitive_displaced_alien,
        primitive_alien_signed_cell,
        primitive_set_alien_signed_cell,
index a187fecbbb51ad5cebe7af040b98be9ba2444ad5..86952a32e8eb74c7950ab720fa5b969c7fd76e52 100755 (executable)
@@ -522,3 +522,26 @@ void primitive_quotation_xt(void)
        F_QUOTATION *quot = untag_quotation(dpeek());
        drepl(allot_cell((CELL)quot->xt));
 }
+
+void compile_all_words(void)
+{
+       CELL words = find_all_words();
+
+       REGISTER_ROOT(words);
+
+       CELL i;
+       CELL length = array_capacity(untag_object(words));
+       for(i = 0; i < length; i++)
+       {
+               F_WORD *word = untag_word(array_nth(untag_array(words),i));
+               REGISTER_UNTAGGED(word);
+               if(word->compiledp == F)
+                       default_word_code(word,false);
+               UNREGISTER_UNTAGGED(word);
+               update_word_xt(word);
+       }
+
+       UNREGISTER_ROOT(words);
+
+       iterate_code_heap(relocate_code_block);
+}
index ff84977fd9dd935bad786dfe9ab6ba2e178a7acc..4c2c17bbb60f1ff3b90f303a7bde05c451bfd843 100755 (executable)
@@ -5,3 +5,4 @@ F_FIXNUM quot_code_offset_to_scan(CELL quot, F_FIXNUM offset);
 void primitive_array_to_quotation(void);
 void primitive_quotation_xt(void);
 void primitive_jit_compile(void);
+void compile_all_words(void);
index 1afbcd3a4062fb2ef7597851fad0274a658b599c..c9e657f8ee3ba2693b9c8ac52c5ecbcad20dc80f 100755 (executable)
@@ -243,6 +243,12 @@ void primitive_byte_array(void)
        dpush(tag_object(allot_byte_array(size)));
 }
 
+void primitive_uninitialized_byte_array(void)
+{
+       CELL size = unbox_array_size();
+       dpush(tag_object(allot_byte_array_internal(size)));
+}
+
 F_BYTE_ARRAY *reallot_byte_array(F_BYTE_ARRAY *array, CELL capacity)
 {
        CELL to_copy = array_capacity(array);
@@ -250,7 +256,7 @@ F_BYTE_ARRAY *reallot_byte_array(F_BYTE_ARRAY *array, CELL capacity)
                to_copy = capacity;
 
        REGISTER_UNTAGGED(array);
-       F_BYTE_ARRAY *new_array = allot_byte_array(capacity);
+       F_BYTE_ARRAY *new_array = allot_byte_array_internal(capacity);
        UNREGISTER_UNTAGGED(array);
 
        memcpy(new_array + 1,array + 1,to_copy);
index ba8d9689fe8b810c5c02ddc25944b2cebc44fba2..5850489a4c1ae5bb07c3a17ff88b09443a51530a 100755 (executable)
@@ -116,6 +116,7 @@ void primitive_tuple(void);
 void primitive_tuple_boa(void);
 void primitive_tuple_layout(void);
 void primitive_byte_array(void);
+void primitive_uninitialized_byte_array(void);
 void primitive_clone(void);
 
 F_ARRAY *reallot_array(F_ARRAY* array, CELL capacity);
@@ -125,6 +126,7 @@ void primitive_resize_byte_array(void);
 
 F_STRING* allot_string_internal(CELL capacity);
 F_STRING* allot_string(CELL capacity, CELL fill);
+void primitive_uninitialized_string(void);
 void primitive_string(void);
 F_STRING *reallot_string(F_STRING *string, CELL capacity);
 void primitive_resize_string(void);