diff --git a/basis/alarms/alarms.factor b/basis/alarms/alarms.factor index ad1838b3df..9cc05b4159 100644 --- a/basis/alarms/alarms.factor +++ b/basis/alarms/alarms.factor @@ -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 diff --git a/basis/alien/prettyprint/prettyprint.factor b/basis/alien/prettyprint/prettyprint.factor new file mode 100644 index 0000000000..0794ab7789 --- /dev/null +++ b/basis/alien/prettyprint/prettyprint.factor @@ -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 ; diff --git a/basis/alien/strings/strings-docs.factor b/basis/alien/strings/strings-docs.factor index 3dc358336c..19c29e613e 100644 --- a/basis/alien/strings/strings-docs.factor +++ b/basis/alien/strings/strings-docs.factor @@ -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 diff --git a/basis/alien/strings/strings-tests.factor b/basis/alien/strings/strings-tests.factor index c1a509041e..263453ba1c 100644 --- a/basis/alien/strings/strings-tests.factor +++ b/basis/alien/strings/strings-tests.factor @@ -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" ] diff --git a/basis/alien/strings/strings.factor b/basis/alien/strings/strings.factor index d482634772..e9053cd5c1 100644 --- a/basis/alien/strings/strings.factor +++ b/basis/alien/strings/strings.factor @@ -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 drop utf16n ; - -M: utf16n drop utf16n ; - -: 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 index 0000000000..a7b1467344 --- /dev/null +++ b/basis/alien/strings/unix/unix.factor @@ -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 index 0000000000..55c69246de --- /dev/null +++ b/basis/alien/strings/windows/windows.factor @@ -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 diff --git a/basis/alien/syntax/syntax.factor b/basis/alien/syntax/syntax.factor index d10c97cd3d..b0ba10a316 100644 --- a/basis/alien/syntax/syntax.factor +++ b/basis/alien/syntax/syntax.factor @@ -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 ; diff --git a/basis/bit-arrays/bit-arrays.factor b/basis/bit-arrays/bit-arrays.factor index 4cb2032f4f..d407f0b84d 100644 --- a/basis/bit-arrays/bit-arrays.factor +++ b/basis/bit-arrays/bit-arrays.factor @@ -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 ] [ [let | out [ n log2 1+ ] 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 ; diff --git a/basis/bit-vectors/bit-vectors.factor b/basis/bit-vectors/bit-vectors.factor index 404b26829b..85bea80b2d 100644 --- a/basis/bit-vectors/bit-vectors.factor +++ b/basis/bit-vectors/bit-vectors.factor @@ -1,7 +1,7 @@ ! Copyright (C) 2008 Slava Pestov. ! See http://factorcode.org/license.txt for BSD license. USING: arrays kernel kernel.private math sequences -sequences.private growable bit-arrays prettyprint.backend +sequences.private growable bit-arrays prettyprint.custom parser accessors ; IN: bit-vectors diff --git a/basis/bootstrap/bootstrap-error.factor b/basis/bootstrap/bootstrap-error.factor new file mode 100644 index 0000000000..01eb002e44 --- /dev/null +++ b/basis/bootstrap/bootstrap-error.factor @@ -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 diff --git a/basis/bootstrap/compiler/compiler.factor b/basis/bootstrap/compiler/compiler.factor index 9968af4330..f0d9e8e131 100644 --- a/basis/bootstrap/compiler/compiler.factor +++ b/basis/bootstrap/compiler/compiler.factor @@ -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 index 0000000000..133b64acaa --- /dev/null +++ b/basis/bootstrap/finish-bootstrap.factor @@ -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 index 0000000000..a60ce04e15 --- /dev/null +++ b/basis/bootstrap/finish-staging.factor @@ -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 diff --git a/basis/bootstrap/math/math.factor b/basis/bootstrap/math/math.factor index a293efd33e..347969af0d 100644 --- a/basis/bootstrap/math/math.factor +++ b/basis/bootstrap/math/math.factor @@ -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 diff --git a/basis/bootstrap/stage2.factor b/basis/bootstrap/stage2.factor index 4ab36ec94e..78355a4670 100644 --- a/basis/bootstrap/stage2.factor +++ b/basis/bootstrap/stage2.factor @@ -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,18 @@ 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 -] recover +] [ drop "resource:basis/bootstrap/bootstrap-error.factor" run-file ] recover diff --git a/basis/bootstrap/threads/threads.factor b/basis/bootstrap/threads/threads.factor index 6c30489bb4..8b751f8458 100644 --- a/basis/bootstrap/threads/threads.factor +++ b/basis/bootstrap/threads/threads.factor @@ -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/core/byte-vectors/byte-vectors-docs.factor b/basis/byte-vectors/byte-vectors-docs.factor similarity index 100% rename from core/byte-vectors/byte-vectors-docs.factor rename to basis/byte-vectors/byte-vectors-docs.factor diff --git a/core/byte-vectors/byte-vectors-tests.factor b/basis/byte-vectors/byte-vectors-tests.factor similarity index 100% rename from core/byte-vectors/byte-vectors-tests.factor rename to basis/byte-vectors/byte-vectors-tests.factor diff --git a/core/byte-vectors/byte-vectors.factor b/basis/byte-vectors/byte-vectors.factor similarity index 80% rename from core/byte-vectors/byte-vectors.factor rename to basis/byte-vectors/byte-vectors.factor index 6938d02b2f..e24c808bbc 100644 --- a/core/byte-vectors/byte-vectors.factor +++ b/basis/byte-vectors/byte-vectors.factor @@ -1,7 +1,8 @@ ! Copyright (C) 2008 Slava Pestov. ! See http://factorcode.org/license.txt for BSD license. USING: arrays kernel kernel.private math sequences -sequences.private growable byte-arrays accessors ; +sequences.private growable byte-arrays accessors parser +prettyprint.custom ; IN: byte-vectors TUPLE: byte-vector @@ -41,4 +42,10 @@ M: byte-array like M: byte-array new-resizable drop ; +: BV{ \ } [ >byte-vector ] parse-literal ; parsing + +M: byte-vector pprint* pprint-object ; +M: byte-vector pprint-delims drop \ BV{ \ } ; +M: byte-vector >pprint-sequence ; + INSTANCE: byte-vector growable diff --git a/core/byte-vectors/summary.txt b/basis/byte-vectors/summary.txt similarity index 100% rename from core/byte-vectors/summary.txt rename to basis/byte-vectors/summary.txt diff --git a/core/byte-vectors/tags.txt b/basis/byte-vectors/tags.txt similarity index 100% rename from core/byte-vectors/tags.txt rename to basis/byte-vectors/tags.txt diff --git a/basis/calendar/format/format.factor b/basis/calendar/format/format.factor index 8d34e8a3a4..a7c4410aa5 100644 --- a/basis/calendar/format/format.factor +++ b/basis/calendar/format/format.factor @@ -1,7 +1,8 @@ -USING: math math.order math.parser math.functions kernel sequences io -accessors arrays io.streams.string splitting -combinators accessors debugger -calendar calendar.format.macros ; +! Copyright (C) 2008 Slava Pestov. +! See http://factorcode.org/license.txt for BSD license. +USING: math math.order math.parser math.functions kernel +sequences io accessors arrays io.streams.string splitting +combinators accessors calendar calendar.format.macros present ; IN: calendar.format : pad-00 ( n -- str ) number>string 2 CHAR: 0 pad-left ; @@ -288,3 +289,5 @@ ERROR: invalid-timestamp-format ; ] } formatted ] with-string-writer ; + +M: timestamp present timestamp>string ; diff --git a/basis/checksums/md5/md5.factor b/basis/checksums/md5/md5.factor index 257fd930c4..d919b0e313 100644 --- a/basis/checksums/md5/md5.factor +++ b/basis/checksums/md5/md5.factor @@ -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 ; diff --git a/basis/checksums/openssl/openssl.factor b/basis/checksums/openssl/openssl.factor index 821cbe2f3a..4bc7a7964a 100644 --- a/basis/checksums/openssl/openssl.factor +++ b/basis/checksums/openssl/openssl.factor @@ -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 diff --git a/basis/checksums/sha1/sha1.factor b/basis/checksums/sha1/sha1.factor index 3767af7c55..6cdc9270aa 100644 --- a/basis/checksums/sha1/sha1.factor +++ b/basis/checksums/sha1/sha1.factor @@ -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 index 0000000000..e753467323 --- /dev/null +++ b/basis/checksums/stream/stream.factor @@ -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 ] dip checksum-stream ; + +INSTANCE: stream-checksum checksum diff --git a/basis/cocoa/application/application.factor b/basis/cocoa/application/application.factor index ab12a93a31..e2c853ea77 100644 --- a/basis/cocoa/application/application.factor +++ b/basis/cocoa/application/application.factor @@ -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 : ( str -- alien ) -> autorelease ; diff --git a/basis/cocoa/messages/messages.factor b/basis/cocoa/messages/messages.factor index e33217a691..ebe98a2df1 100644 --- a/basis/cocoa/messages/messages.factor +++ b/basis/cocoa/messages/messages.factor @@ -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 dup ] 2keep + [ "( sender-stub )" f 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 ; diff --git a/basis/cocoa/subclassing/subclassing.factor b/basis/cocoa/subclassing/subclassing.factor index b49d55a30b..be53364185 100644 --- a/basis/cocoa/subclassing/subclassing.factor +++ b/basis/cocoa/subclassing/subclassing.factor @@ -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 -- ) diff --git a/basis/command-line/command-line.factor b/basis/command-line/command-line.factor index 1b58053b64..7d5a041951 100644 --- a/basis/command-line/command-line.factor +++ b/basis/command-line/command-line.factor @@ -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 ; - - : 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 diff --git a/basis/compiler/cfg/alias-analysis/alias-analysis-tests.factor b/basis/compiler/cfg/alias-analysis/alias-analysis-tests.factor index c7094c8c36..d8bad5ec41 100644 --- a/basis/compiler/cfg/alias-analysis/alias-analysis-tests.factor +++ b/basis/compiler/cfg/alias-analysis/alias-analysis-tests.factor @@ -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 [ ] [ diff --git a/basis/compiler/cfg/dead-code/dead-code-tests.factor b/basis/compiler/cfg/dead-code/dead-code-tests.factor index b9c3af5215..ee7d8d2a43 100644 --- a/basis/compiler/cfg/dead-code/dead-code-tests.factor +++ b/basis/compiler/cfg/dead-code/dead-code-tests.factor @@ -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 [ { } ] [ diff --git a/basis/compiler/cfg/debugger/debugger.factor b/basis/compiler/cfg/debugger/debugger.factor index 7b1b9100c4..ba58e60a4a 100644 --- a/basis/compiler/cfg/debugger/debugger.factor +++ b/basis/compiler/cfg/debugger/debugger.factor @@ -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* + > pprint* ] [ n>> pprint* ] bi + block> ; + +: pprint-loc ( loc word -- ) > pprint* block> ; + +M: ds-loc pprint* \ D pprint-loc ; + +M: rs-loc pprint* \ R pprint-loc ; diff --git a/basis/compiler/cfg/registers/registers.factor b/basis/compiler/cfg/registers/registers.factor index 21572ec615..2b9d3df6f6 100644 --- a/basis/compiler/cfg/registers/registers.factor +++ b/basis/compiler/cfg/registers/registers.factor @@ -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 TUPLE: rs-loc < loc ; C: rs-loc -! Prettyprinting : V scan-word scan-word vreg boa parsed ; parsing - -M: vreg pprint* - > pprint* ] [ n>> pprint* ] bi - block> ; - -: pprint-loc ( loc word -- ) > pprint* block> ; - : D scan-word parsed ; parsing - -M: ds-loc pprint* \ D pprint-loc ; - : R scan-word parsed ; parsing - -M: rs-loc pprint* \ R pprint-loc ; diff --git a/basis/compiler/cfg/value-numbering/value-numbering-tests.factor b/basis/compiler/cfg/value-numbering/value-numbering-tests.factor index 8adeaa21f4..641ccceb5d 100644 --- a/basis/compiler/cfg/value-numbering/value-numbering-tests.factor +++ b/basis/compiler/cfg/value-numbering/value-numbering-tests.factor @@ -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 ) [ diff --git a/basis/compiler/cfg/write-barrier/write-barrier-tests.factor b/basis/compiler/cfg/write-barrier/write-barrier-tests.factor index 7a4b1c488f..73748dbc37 100644 --- a/basis/compiler/cfg/write-barrier/write-barrier-tests.factor +++ b/basis/compiler/cfg/write-barrier/write-barrier-tests.factor @@ -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 [ diff --git a/basis/compiler/codegen/fixup/fixup.factor b/basis/compiler/codegen/fixup/fixup.factor index a56ae04a7b..e0f391deb5 100755 --- a/basis/compiler/codegen/fixup/fixup.factor +++ b/basis/compiler/codegen/fixup/fixup.factor @@ -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 -- ) diff --git a/basis/compiler/compiler.factor b/basis/compiler/compiler.factor index e5cbd888d9..0d24daef71 100644 --- a/basis/compiler/compiler.factor +++ b/basis/compiler/compiler.factor @@ -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 ; diff --git a/basis/compiler/tree/dead-code/recursive/recursive.factor b/basis/compiler/tree/dead-code/recursive/recursive.factor index 02dc42f058..71830d07e7 100644 --- a/basis/compiler/tree/dead-code/recursive/recursive.factor +++ b/basis/compiler/tree/dead-code/recursive/recursive.factor @@ -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* ; diff --git a/basis/compiler/tree/debugger/debugger.factor b/basis/compiler/tree/debugger/debugger.factor index 8d764a2833..8a2823010d 100644 --- a/basis/compiler/tree/debugger/debugger.factor +++ b/basis/compiler/tree/debugger/debugger.factor @@ -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 diff --git a/basis/compiler/tree/propagation/inlining/inlining.factor b/basis/compiler/tree/propagation/inlining/inlining.factor index fcc3b01dc0..e35eb02604 100644 --- a/basis/compiler/tree/propagation/inlining/inlining.factor +++ b/basis/compiler/tree/propagation/inlining/inlining.factor @@ -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>> ] [ [ dispatch# ] keep ] bi* - [ swap nth value-info class>> dup ] dip - specific-method ; + dup "methods" word-prop assoc-empty? [ 2drop f f ] [ + [ in-d>> ] [ [ dispatch# ] keep ] bi* + [ swap nth value-info class>> dup ] dip + specific-method + ] if ; : inline-standard-method ( #call word -- ? ) dupd inlining-standard-method eliminate-dispatch ; diff --git a/basis/concurrency/combinators/combinators.factor b/basis/concurrency/combinators/combinators.factor index 4608faf79b..932605fc36 100644 --- a/basis/concurrency/combinators/combinators.factor +++ b/basis/concurrency/combinators/combinators.factor @@ -22,7 +22,7 @@ PRIVATE> ] (parallel-each) ; inline : parallel-filter ( seq quot -- newseq ) - over [ pusher [ each ] dip ] dip like ; inline + over [ pusher [ parallel-each ] dip ] dip like ; inline CFRelease ] unit-test +[ "Hello" ] [ "Hello" [ CF>string ] [ CFRelease ] bi ] unit-test +[ "Hello\u003456" ] [ "Hello\u003456" [ CF>string ] [ CFRelease ] bi ] unit-test +[ "Hello\u013456" ] [ "Hello\u013456" [ CF>string ] [ CFRelease ] bi ] unit-test diff --git a/basis/core-foundation/core-foundation.factor b/basis/core-foundation/core-foundation.factor index d63a66dbe7..48d7b7e483 100644 --- a/basis/core-foundation/core-foundation.factor +++ b/basis/core-foundation/core-foundation.factor @@ -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 ; : ( 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" [ - [ 0 over CFStringGetLength ] dip CFStringGetCharacters - ] keep utf16n alien>string ; + dup CFStringGetLength 4 * 1 + [ + dup length + kCFStringEncodingUTF8 + CFStringGetCString + [ "CFStringGetCString failed" throw ] unless + ] keep utf8 alien>string ; : CF>string-array ( alien -- seq ) CF>array [ CF>string ] map ; diff --git a/basis/core-foundation/run-loop/run-loop.factor b/basis/core-foundation/run-loop/run-loop.factor index c334297122..39f4101301 100644 --- a/basis/core-foundation/run-loop/run-loop.factor +++ b/basis/core-foundation/run-loop/run-loop.factor @@ -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" 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 ; diff --git a/basis/core-foundation/run-loop/thread/thread.factor b/basis/core-foundation/run-loop/thread/thread.factor index 326226ec0e..aeeff312cb 100644 --- a/basis/core-foundation/run-loop/thread/thread.factor +++ b/basis/core-foundation/run-loop/thread/thread.factor @@ -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 diff --git a/basis/cpu/x86/assembler/assembler.factor b/basis/cpu/x86/assembler/assembler.factor index 2bea887295..3a98d47416 100644 --- a/basis/cpu/x86/assembler/assembler.factor +++ b/basis/cpu/x86/assembler/assembler.factor @@ -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 diff --git a/basis/debugger/debugger.factor b/basis/debugger/debugger.factor index 35b09713d3..4e0c4e8840 100644 --- a/basis/debugger/debugger.factor +++ b/basis/debugger/debugger.factor @@ -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. diff --git a/basis/delegate/delegate.factor b/basis/delegate/delegate.factor index e7ea370b8d..57f9b35c96 100644 --- a/basis/delegate/delegate.factor +++ b/basis/delegate/delegate.factor @@ -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 ; diff --git a/basis/delegate/protocols/protocols.factor b/basis/delegate/protocols/protocols.factor index 81310c16c0..c21f33ec8e 100644 --- a/basis/delegate/protocols/protocols.factor +++ b/basis/delegate/protocols/protocols.factor @@ -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 diff --git a/basis/environment/winnt/winnt.factor b/basis/environment/winnt/winnt.factor index 33cf6a698b..2ad3393aec 100644 --- a/basis/environment/winnt/winnt.factor +++ b/basis/environment/winnt/winnt.factor @@ -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 ; diff --git a/basis/functors/functors.factor b/basis/functors/functors.factor index 7126806c3d..2029c0cf25 100644 --- a/basis/functors/functors.factor +++ b/basis/functors/functors.factor @@ -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-rewrite first ; + rewrite-closures first ; : FUNCTOR: (FUNCTOR:) define ; parsing diff --git a/basis/generalizations/generalizations-docs.factor b/basis/generalizations/generalizations-docs.factor index 2380f5614d..3979e0518a 100644 --- a/basis/generalizations/generalizations-docs.factor +++ b/basis/generalizations/generalizations-docs.factor @@ -1,5 +1,5 @@ USING: help.syntax help.markup kernel sequences quotations -math arrays ; +math arrays combinators ; IN: generalizations HELP: nsequence @@ -234,6 +234,18 @@ HELP: napply } } ; +HELP: ncleave +{ $values { "quots" "a sequence of quotations" } { "n" integer } } +{ $description "A generalization of " { $link cleave } " and " { $link 2cleave } " that can work for any quotation arity." +} +{ $examples + "Some core words expressed in terms of " { $link ncleave } ":" + { $table + { { $link cleave } { $snippet "1 ncleave" } } + { { $link 2cleave } { $snippet "2 ncleave" } } + } +} ; + HELP: mnswap { $values { "m" integer } { "n" integer } } { $description "Swaps the top " { $snippet "m" } " stack elements with the " { $snippet "n" } " elements directly underneath." } @@ -269,6 +281,7 @@ $nl { $subsection nslip } { $subsection nkeep } { $subsection napply } +{ $subsection ncleave } "Generalized quotation construction:" { $subsection ncurry } { $subsection nwith } ; diff --git a/basis/generalizations/generalizations.factor b/basis/generalizations/generalizations.factor index 3c24d20c8a..ae7437b346 100644 --- a/basis/generalizations/generalizations.factor +++ b/basis/generalizations/generalizations.factor @@ -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 ] ] diff --git a/basis/help/definitions/definitions.factor b/basis/help/definitions/definitions.factor index e5202e1306..3e4066d8b7 100644 --- a/basis/help/definitions/definitions.factor +++ b/basis/help/definitions/definitions.factor @@ -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 diff --git a/basis/help/handbook/handbook.factor b/basis/help/handbook/handbook.factor index 2ed86a0a19..cc36e9faab 100644 --- a/basis/help/handbook/handbook.factor +++ b/basis/help/handbook/handbook.factor @@ -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 diff --git a/basis/help/lint/lint.factor b/basis/help/lint/lint.factor index 0a392733ac..fbebc7f0f6 100644 --- a/basis/help/lint/lint.factor +++ b/basis/help/lint/lint.factor @@ -150,7 +150,7 @@ M: help-error error. ] [ [ swap vocab-heading. - [ error. nl ] each + [ print-error nl ] each ] assoc-each ] if-empty ; diff --git a/basis/http/client/client.factor b/basis/http/client/client.factor index 9260f15a7b..119fa23567 100644 --- a/basis/http/client/client.factor +++ b/basis/http/client/client.factor @@ -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 ; - 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 ) 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 index 0000000000..413ae7bd85 --- /dev/null +++ b/basis/http/client/debugger/debugger.factor @@ -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>> . ; diff --git a/basis/http/http.factor b/basis/http/http.factor index d006c86462..bbb0335ae4 100644 --- a/basis/http/http.factor +++ b/basis/http/http.factor @@ -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 diff --git a/basis/io/encodings/utf16/utf16-tests.factor b/basis/io/encodings/utf16/utf16-tests.factor index fd251c76db..bde92a260d 100644 --- a/basis/io/encodings/utf16/utf16-tests.factor +++ b/basis/io/encodings/utf16/utf16-tests.factor @@ -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 correct-endian ] unit-test -[ t ] [ utf16n 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 index 0000000000..9ccf4834d4 --- /dev/null +++ b/basis/io/encodings/utf16n/utf16n-docs.factor @@ -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 index 0000000000..5e7d1af8f5 --- /dev/null +++ b/basis/io/encodings/utf16n/utf16n-tests.factor @@ -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 correct-endian ] unit-test +[ t ] [ utf16n correct-endian ] unit-test diff --git a/basis/io/encodings/utf16n/utf16n.factor b/basis/io/encodings/utf16n/utf16n.factor new file mode 100644 index 0000000000..cc6e7e2baa --- /dev/null +++ b/basis/io/encodings/utf16n/utf16n.factor @@ -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 drop utf16n ; + +M: utf16n drop utf16n ; diff --git a/basis/io/files/unique/backend/backend.factor b/basis/io/files/unique/backend/backend.factor deleted file mode 100644 index 7b9809fa28..0000000000 --- a/basis/io/files/unique/backend/backend.factor +++ /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 ) diff --git a/basis/io/files/unique/unique-docs.factor b/basis/io/files/unique/unique-docs.factor index 825eb212f1..bfde09dc48 100644 --- a/basis/io/files/unique/unique-docs.factor +++ b/basis/io/files/unique/unique-docs.factor @@ -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 } diff --git a/basis/io/files/unique/unique.factor b/basis/io/files/unique/unique.factor index ec89517bbc..66540fb48e 100644 --- a/basis/io/files/unique/unique.factor +++ b/basis/io/files/unique/unique.factor @@ -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/extra/io/paths/authors.txt b/basis/io/paths/authors.txt similarity index 100% rename from extra/io/paths/authors.txt rename to basis/io/paths/authors.txt diff --git a/basis/io/paths/paths-tests.factor b/basis/io/paths/paths-tests.factor new file mode 100644 index 0000000000..01763ce5c0 --- /dev/null +++ b/basis/io/paths/paths-tests.factor @@ -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/extra/io/paths/paths.factor b/basis/io/paths/paths.factor similarity index 96% rename from extra/io/paths/paths.factor rename to basis/io/paths/paths.factor index 75d08b60f8..212ba9e396 100755 --- a/extra/io/paths/paths.factor +++ b/basis/io/paths/paths.factor @@ -1,6 +1,6 @@ ! Copyright (C) 2008 Doug Coleman. ! See http://factorcode.org/license.txt for BSD license. -USING: accessors arrays deques dlists io.files io.paths.private +USING: accessors arrays deques dlists io.files kernel sequences system vocabs.loader fry continuations ; IN: io.paths diff --git a/extra/io/paths/windows/authors.txt b/basis/io/paths/windows/authors.txt similarity index 100% rename from extra/io/paths/windows/authors.txt rename to basis/io/paths/windows/authors.txt diff --git a/extra/io/paths/windows/tags.txt b/basis/io/paths/windows/tags.txt similarity index 100% rename from extra/io/paths/windows/tags.txt rename to basis/io/paths/windows/tags.txt diff --git a/extra/io/paths/windows/windows.factor b/basis/io/paths/windows/windows.factor similarity index 100% rename from extra/io/paths/windows/windows.factor rename to basis/io/paths/windows/windows.factor diff --git a/basis/io/ports/ports.factor b/basis/io/ports/ports.factor index 0432fe4a39..6eb61a24a7 100644 --- a/basis/io/ports/ports.factor +++ b/basis/io/ports/ports.factor @@ -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 diff --git a/basis/io/servers/connection/connection.factor b/basis/io/servers/connection/connection.factor index 2d990e6483..bc90915213 100644 --- a/basis/io/servers/connection/connection.factor +++ b/basis/io/servers/connection/connection.factor @@ -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 diff --git a/basis/io/sockets/secure/openssl/openssl.factor b/basis/io/sockets/secure/openssl/openssl.factor index ec45337fb1..60402c37ea 100644 --- a/basis/io/sockets/secure/openssl/openssl.factor +++ b/basis/io/sockets/secure/openssl/openssl.factor @@ -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 ; diff --git a/basis/io/sockets/sockets.factor b/basis/io/sockets/sockets.factor index fbfae333c0..597aa61138 100644 --- a/basis/io/sockets/sockets.factor +++ b/basis/io/sockets/sockets.factor @@ -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/core/io/streams/byte-array/byte-array-docs.factor b/basis/io/streams/byte-array/byte-array-docs.factor similarity index 100% rename from core/io/streams/byte-array/byte-array-docs.factor rename to basis/io/streams/byte-array/byte-array-docs.factor diff --git a/core/io/streams/byte-array/byte-array-tests.factor b/basis/io/streams/byte-array/byte-array-tests.factor similarity index 100% rename from core/io/streams/byte-array/byte-array-tests.factor rename to basis/io/streams/byte-array/byte-array-tests.factor diff --git a/core/io/streams/byte-array/byte-array.factor b/basis/io/streams/byte-array/byte-array.factor similarity index 100% rename from core/io/streams/byte-array/byte-array.factor rename to basis/io/streams/byte-array/byte-array.factor diff --git a/basis/io/streams/duplex/duplex.factor b/basis/io/streams/duplex/duplex.factor index 9bf637432f..53d554e766 100644 --- a/basis/io/streams/duplex/duplex.factor +++ b/basis/io/streams/duplex/duplex.factor @@ -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 ; diff --git a/basis/io/streams/limited/limited.factor b/basis/io/streams/limited/limited.factor index e89b31a884..ecc49923de 100644 --- a/basis/io/streams/limited/limited.factor +++ b/basis/io/streams/limited/limited.factor @@ -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 ; diff --git a/basis/io/styles/styles.factor b/basis/io/styles/styles.factor index c9ba8f66df..e07753c640 100644 --- a/basis/io/styles/styles.factor +++ b/basis/io/styles/styles.factor @@ -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 +M: input summary + [ + "Input: " % + string>> "\n" split1 swap % + "..." "" ? % + ] "" make ; + : write-object ( str obj -- ) presented associate format ; diff --git a/basis/io/unix/files/unique/unique.factor b/basis/io/unix/files/unique/unique.factor index e47ac6a2e3..24dcdcb65a 100644 --- a/basis/io/unix/files/unique/unique.factor +++ b/basis/io/unix/files/unique/unique.factor @@ -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" ; diff --git a/basis/io/unix/launcher/launcher.factor b/basis/io/unix/launcher/launcher.factor index c81da60e12..e80a372aef 100644 --- a/basis/io/unix/launcher/launcher.factor +++ b/basis/io/unix/launcher/launcher.factor @@ -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 ] } diff --git a/basis/io/unix/sockets/secure/secure.factor b/basis/io/unix/sockets/secure/secure.factor index a096380b74..106b6569ed 100644 --- a/basis/io/unix/sockets/secure/secure.factor +++ b/basis/io/unix/sockets/secure/secure.factor @@ -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 diff --git a/basis/io/windows/files/files.factor b/basis/io/windows/files/files.factor index 83954e045b..894ddc83c6 100755 --- a/basis/io/windows/files/files.factor +++ b/basis/io/windows/files/files.factor @@ -1,10 +1,10 @@ ! 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 +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 ; IN: io.windows.files diff --git a/basis/io/windows/files/unique/unique.factor b/basis/io/windows/files/unique/unique.factor index b1bf2bdc1c..ab99bf2cac 100644 --- a/basis/io/windows/files/unique/unique.factor +++ b/basis/io/windows/files/unique/unique.factor @@ -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 ) diff --git a/basis/io/windows/nt/files/files.factor b/basis/io/windows/nt/files/files.factor old mode 100644 new mode 100755 index 9f25eb5eb1..892a5c4d31 --- a/basis/io/windows/nt/files/files.factor +++ b/basis/io/windows/nt/files/files.factor @@ -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 diff --git a/basis/io/windows/nt/monitors/monitors.factor b/basis/io/windows/nt/monitors/monitors.factor index 30345c8c69..a2b7c4fa2d 100755 --- a/basis/io/windows/nt/monitors/monitors.factor +++ b/basis/io/windows/nt/monitors/monitors.factor @@ -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 ) diff --git a/basis/locals/definitions/definitions.factor b/basis/locals/definitions/definitions.factor new file mode 100644 index 0000000000..99f9d0bd22 --- /dev/null +++ b/basis/locals/definitions/definitions.factor @@ -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 + ; + +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 index 0000000000..95c8357939 --- /dev/null +++ b/basis/locals/errors/errors.factor @@ -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 index 0000000000..9dc924334c --- /dev/null +++ b/basis/locals/fry/fry.factor @@ -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 , ; diff --git a/basis/locals/locals-docs.factor b/basis/locals/locals-docs.factor index 89314aadc5..e9e1bfa16a 100644 --- a/basis/locals/locals-docs.factor +++ b/basis/locals/locals-docs.factor @@ -63,6 +63,33 @@ HELP: [wlet } } ; +HELP: :> +{ $syntax ":> binding" } +{ $description "Introduces a new binding, lexically scoped to the enclosing quotation or definition." } +{ $notes + "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 +236,8 @@ $nl { $subsection POSTPONE: [wlet } "Lambda abstractions:" { $subsection POSTPONE: [| } +"Lightweight binding form:" +{ $subsection POSTPONE: :> } "Additional topics:" { $subsection "locals-literals" } { $subsection "locals-mutable" } diff --git a/basis/locals/locals-tests.factor b/basis/locals/locals-tests.factor index f13c1d57fa..b5c201a5d9 100644 --- a/basis/locals/locals-tests.factor +++ b/basis/locals/locals-tests.factor @@ -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? ] diff --git a/basis/locals/locals.factor b/basis/locals/locals.factor index b78b95bc24..f745f6243f 100644 --- a/basis/locals/locals.factor +++ b/basis/locals/locals.factor @@ -1,397 +1,13 @@ ! 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." ; - - lambda - -TUPLE: binding-form bindings body ; - -TUPLE: let < binding-form ; - -C: let - -TUPLE: let* < binding-form ; - -C: let* - -TUPLE: wlet < binding-form ; - -C: 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 ; - -: ( name -- word ) - #! Create a local variable identifier - f - dup t "local?" set-word-prop ; - -PREDICATE: local-word < word "local-word?" word-prop ; - -: ( name -- word ) - f dup t "local-word?" set-word-prop ; - -PREDICATE: local-reader < word "local-reader?" word-prop ; - -: ( name -- word ) - f - dup t "local-reader?" set-word-prop ; - -PREDICATE: local-writer < word "local-writer?" word-prop ; - -: ( reader -- word ) - dup name>> "!" append f { - [ 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 - -: 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 , ; - -M: block lambda-rewrite* - #! Turn free variables into bound variables, curry them - #! onto the body - dup free-vars [ ] map dup % [ - over block-vars prepend - swap block-body [ [ lambda-rewrite* ] each ] [ ] make - swap point-free , - ] keep length \ curry % ; - -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 [ - - dup dup name>> set - ] [ ] if - dup dup name>> set ; - -: make-locals ( seq -- words assoc ) - [ [ make-local ] map ] H{ } make-assoc ; - -: make-local-word ( name def -- 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) ; - -: 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 -- ) - [ - [ 1array ] dip spin '[ @ @ ] - ] 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) - 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 parsed ; parsing : [| parse-lambda parsed-lambda ; parsing @@ -415,110 +31,12 @@ PRIVATE> : MEMO:: (::) define-memoized ; parsing -> pprint-vars - \ | pprint-word - f > pprint-elements block> - \ ] pprint-word - block> ; - -: pprint-let ( let word -- ) - pprint-word - [ body>> ] [ bindings>> ] bi - \ | pprint-word - t ] assoc-each - block> - \ | pprint-word - - 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 - ; - -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 ; - -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 index 0000000000..7bde67a792 --- /dev/null +++ b/basis/locals/macros/macros.factor @@ -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 index 0000000000..e6ab6c003c --- /dev/null +++ b/basis/locals/parser/parser.factor @@ -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 [ + + dup dup name>> set + ] [ ] if + dup dup name>> set ; + +: make-locals ( seq -- words assoc ) + [ [ make-local ] map ] H{ } make-assoc ; + +: make-local-word ( name def -- 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) ; + +: 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) + 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 index 0000000000..187b663c3c --- /dev/null +++ b/basis/locals/prettyprint/prettyprint.factor @@ -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* + > pprint-vars + \ | pprint-word + f > pprint-elements block> + \ ] pprint-word + block> ; + +: pprint-let ( let word -- ) + pprint-word + [ body>> ] [ bindings>> ] bi + \ | pprint-word + t ] assoc-each + block> + \ | pprint-word + + block> + \ ] pprint-word ; + +M: let pprint* \ [let pprint-let ; + +M: wlet pprint* \ [wlet pprint-let ; + +M: let* pprint* \ [let* pprint-let ; + +M: def pprint* + 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 index 0000000000..d85155daad --- /dev/null +++ b/basis/locals/rewrite/closures/closures.factor @@ -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 [ ] map + [ % ] + [ var-defs prepend (rewrite-closures) point-free , ] + [ length \ curry % ] + 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 index 0000000000..bd322bfff3 --- /dev/null +++ b/basis/locals/rewrite/point-free/point-free.factor @@ -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 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 index 0000000000..05b1e2345e --- /dev/null +++ b/basis/locals/rewrite/sugar/sugar.factor @@ -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 ) [ ] [ ] 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 % , ] 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 index 0000000000..7a8dac1947 --- /dev/null +++ b/basis/locals/types/types.factor @@ -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 + +TUPLE: binding-form bindings body ; + +TUPLE: let < binding-form ; + +C: let + +TUPLE: let* < binding-form ; + +C: let* + +TUPLE: wlet < binding-form ; + +C: wlet + +TUPLE: quote local ; + +C: quote + +: unquote ( quote -- local ) dup quote? [ local>> ] when ; inline + +TUPLE: def local ; + +C: def + +PREDICATE: local < word "local?" word-prop ; + +: ( name -- word ) + #! Create a local variable identifier + f + dup t "local?" set-word-prop ; + +PREDICATE: local-word < word "local-word?" word-prop ; + +: ( name -- word ) + f dup t "local-word?" set-word-prop ; + +PREDICATE: local-reader < word "local-reader?" word-prop ; + +: ( name -- word ) + f + dup t "local-reader?" set-word-prop ; + +PREDICATE: local-writer < word "local-writer?" word-prop ; + +: ( reader -- word ) + dup name>> "!" append f { + [ 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 ; diff --git a/basis/math/complex/complex.factor b/basis/math/complex/complex.factor index c228684e32..90713cd40f 100644 --- a/basis/math/complex/complex.factor +++ b/basis/math/complex/complex.factor @@ -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 index 0000000000..09eeb8045c --- /dev/null +++ b/basis/math/complex/prettyprint/prettyprint.factor @@ -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 ; diff --git a/basis/nibble-arrays/nibble-arrays.factor b/basis/nibble-arrays/nibble-arrays.factor index c753d0fb78..82643bef15 100644 --- a/basis/nibble-arrays/nibble-arrays.factor +++ b/basis/nibble-arrays/nibble-arrays.factor @@ -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 index 0000000000..7e751b5110 --- /dev/null +++ b/basis/peg/debugger/debugger.factor @@ -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>> . ; + diff --git a/basis/peg/ebnf/ebnf.factor b/basis/peg/ebnf/ebnf.factor index ccae0fec93..ca97886235 100644 --- a/basis/peg/ebnf/ebnf.factor +++ b/basis/peg/ebnf/ebnf.factor @@ -5,7 +5,7 @@ sequences quotations vectors namespaces make math assocs continuations peg peg.parsers unicode.categories multiline splitting accessors effects sequences.deep peg.search combinators.short-circuit lexer io.streams.string stack-checker -io prettyprint combinators parser ; +io combinators parser ; IN: peg.ebnf : rule ( name word -- parser ) @@ -458,16 +458,13 @@ M: ebnf-var build-locals ( code ast -- ) M: object build-locals ( code ast -- ) drop ; +ERROR: bad-effect quot effect ; + : check-action-effect ( quot -- quot ) dup infer { { [ dup (( a -- b )) effect<= ] [ drop ] } { [ dup (( -- b )) effect<= ] [ drop [ drop ] prepose ] } - [ - [ - "Bad effect: " write effect>string write - " for quotation " write pprint - ] with-string-writer throw - ] + [ bad-effect ] } cond ; M: ebnf-action (transform) ( ast -- parser ) diff --git a/basis/peg/peg.factor b/basis/peg/peg.factor index 8a62365f53..3fc6fec8ed 100644 --- a/basis/peg/peg.factor +++ b/basis/peg/peg.factor @@ -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 C: 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 diff --git a/basis/persistent/hashtables/hashtables.factor b/basis/persistent/hashtables/hashtables.factor index e50fd52c10..8c80782a2e 100644 --- a/basis/persistent/hashtables/hashtables.factor +++ b/basis/persistent/hashtables/hashtables.factor @@ -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 diff --git a/basis/persistent/vectors/vectors.factor b/basis/persistent/vectors/vectors.factor index 92b3f82a54..cd8e7c49e0 100644 --- a/basis/persistent/vectors/vectors.factor +++ b/basis/persistent/vectors/vectors.factor @@ -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 diff --git a/basis/present/present.factor b/basis/present/present.factor index 519e995fe5..fe7025d559 100644 --- a/basis/present/present.factor +++ b/basis/present/present.factor @@ -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>> ; diff --git a/basis/prettyprint/backend/backend-docs.factor b/basis/prettyprint/backend/backend-docs.factor index 64e1fd45ff..165621887f 100644 --- a/basis/prettyprint/backend/backend-docs.factor +++ b/basis/prettyprint/backend/backend-docs.factor @@ -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." } diff --git a/basis/prettyprint/backend/backend.factor b/basis/prettyprint/backend/backend.factor index 76c3918f63..92d039a15d 100644 --- a/basis/prettyprint/backend/backend.factor +++ b/basis/prettyprint/backend/backend.factor @@ -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 -- ) [ pprint-sequence ( obj -- seq ) +GENERIC: pprint-narrow? ( obj -- ? ) diff --git a/basis/prettyprint/prettyprint-docs.factor b/basis/prettyprint/prettyprint-docs.factor index 3c004e5b30..46d4e6e5ff 100644 --- a/basis/prettyprint/prettyprint-docs.factor +++ b/basis/prettyprint/prettyprint-docs.factor @@ -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 diff --git a/basis/prettyprint/prettyprint.factor b/basis/prettyprint/prettyprint.factor index 7c4de1e973..9d5af9e6a5 100644 --- a/basis/prettyprint/prettyprint.factor +++ b/basis/prettyprint/prettyprint.factor @@ -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 ; diff --git a/basis/qualified/qualified.factor b/basis/qualified/qualified.factor index 25d04ed929..2cd64e90bf 100644 --- a/basis/qualified/qualified.factor +++ b/basis/qualified/qualified.factor @@ -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 -- ) diff --git a/basis/regexp/regexp.factor b/basis/regexp/regexp.factor index b41e4d271e..c615719cc4 100644 --- a/basis/regexp/regexp.factor +++ b/basis/regexp/regexp.factor @@ -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 ) diff --git a/basis/specialized-arrays/functor/functor.factor b/basis/specialized-arrays/functor/functor.factor index 52977dc22a..2894649428 100644 --- a/basis/specialized-arrays/functor/functor.factor +++ b/basis/specialized-arrays/functor/functor.factor @@ -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 diff --git a/basis/specialized-vectors/functor/functor.factor b/basis/specialized-vectors/functor/functor.factor index 0628f8b484..8ba5354dc4 100644 --- a/basis/specialized-vectors/functor/functor.factor +++ b/basis/specialized-vectors/functor/functor.factor @@ -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 -- ) diff --git a/basis/stack-checker/backend/backend.factor b/basis/stack-checker/backend/backend.factor index 7f8c920b19..147749864d 100644 --- a/basis/stack-checker/backend/backend.factor +++ b/basis/stack-checker/backend/backend.factor @@ -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 ; diff --git a/basis/stack-checker/errors/errors.factor b/basis/stack-checker/errors/errors.factor index 5b6b3c0893..58944e7bc4 100644 --- a/basis/stack-checker/errors/errors.factor +++ b/basis/stack-checker/errors/errors.factor @@ -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 ] { } 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 index 0000000000..21c6d64402 --- /dev/null +++ b/basis/stack-checker/errors/prettyprint/prettyprint.factor @@ -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 ] { } 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 ; diff --git a/basis/stack-checker/known-words/known-words.factor b/basis/stack-checker/known-words/known-words.factor index 28634f2d44..a998e5394b 100644 --- a/basis/stack-checker/known-words/known-words.factor +++ b/basis/stack-checker/known-words/known-words.factor @@ -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 diff --git a/basis/summary/summary.factor b/basis/summary/summary.factor index ea2c19fd6d..44e5374dc5 100644 --- a/basis/summary/summary.factor +++ b/basis/summary/summary.factor @@ -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 index 0000000000..a8cdf6f41c --- /dev/null +++ b/basis/tools/cocoa/cocoa.factor @@ -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 index 0000000000..6bf68304bb --- /dev/null +++ b/basis/tools/cocoa/tags.txt @@ -0,0 +1 @@ +unportable diff --git a/basis/tools/deploy/backend/backend.factor b/basis/tools/deploy/backend/backend.factor index 18713c7b0c..ee8615ac5a 100644 --- a/basis/tools/deploy/backend/backend.factor +++ b/basis/tools/deploy/backend/backend.factor @@ -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 , diff --git a/basis/tools/deploy/config/config-docs.factor b/basis/tools/deploy/config/config-docs.factor index e8dcd2b90e..c8249e4e41 100644 --- a/basis/tools/deploy/config/config-docs.factor +++ b/basis/tools/deploy/config/config-docs.factor @@ -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." } ; diff --git a/basis/tools/deploy/config/config.factor b/basis/tools/deploy/config/config.factor index 84bfab682b..1d9761e885 100644 --- a/basis/tools/deploy/config/config.factor +++ b/basis/tools/deploy/config/config.factor @@ -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 index 0000000000..b677d37f95 --- /dev/null +++ b/basis/tools/deploy/config/editor/editor-docs.factor @@ -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 index 0000000000..2b5788adfc --- /dev/null +++ b/basis/tools/deploy/config/editor/editor.factor @@ -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 ; diff --git a/basis/tools/deploy/deploy-docs.factor b/basis/tools/deploy/deploy-docs.factor index eccb3982c7..00e747cf00 100644 --- a/basis/tools/deploy/deploy-docs.factor +++ b/basis/tools/deploy/deploy-docs.factor @@ -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 diff --git a/basis/tools/deploy/deploy-tests.factor b/basis/tools/deploy/deploy-tests.factor index 9cc48972fa..71dc746fb5 100644 --- a/basis/tools/deploy/deploy-tests.factor +++ b/basis/tools/deploy/deploy-tests.factor @@ -1,8 +1,8 @@ IN: tools.deploy.tests USING: tools.test system io.files kernel tools.deploy.config -tools.deploy.backend math sequences io.launcher arrays -namespaces continuations layouts accessors io.encodings.ascii -urls math.parser ; +tools.deploy.config.editor tools.deploy.backend math sequences +io.launcher arrays namespaces continuations layouts accessors +io.encodings.ascii urls math.parser ; : shake-and-bake ( vocab -- ) [ "test.image" temp-file delete-file ] ignore-errors @@ -31,6 +31,10 @@ urls math.parser ; [ t ] [ "bunny" shake-and-bake 2500000 small-enough? ] unit-test +os macosx? [ + [ t ] [ "webkit-demo" shake-and-bake 500000 small-enough? ] unit-test +] when + : run-temp-image ( -- ) vm "-i=" "test.image" temp-file append diff --git a/basis/tools/deploy/macosx/macosx.factor b/basis/tools/deploy/macosx/macosx.factor index d3464993e1..1f0e482441 100644 --- a/basis/tools/deploy/macosx/macosx.factor +++ b/basis/tools/deploy/macosx/macosx.factor @@ -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 ) diff --git a/basis/tools/deploy/shaker/shaker.factor b/basis/tools/deploy/shaker/shaker.factor index 15fd2a37d7..3d4944841d 100755 --- a/basis/tools/deploy/shaker/shaker.factor +++ b/basis/tools/deploy/shaker/shaker.factor @@ -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 diff --git a/basis/tools/deploy/shaker/strip-cocoa.factor b/basis/tools/deploy/shaker/strip-cocoa.factor index d5249dc20c..773b2d0f3b 100644 --- a/basis/tools/deploy/shaker/strip-cocoa.factor +++ b/basis/tools/deploy/shaker/strip-cocoa.factor @@ -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 diff --git a/basis/tools/deploy/unix/unix.factor b/basis/tools/deploy/unix/unix.factor index 5e1d0be7fb..bd49155e84 100644 --- a/basis/tools/deploy/unix/unix.factor +++ b/basis/tools/deploy/unix/unix.factor @@ -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 ) diff --git a/basis/tools/deploy/windows/windows.factor b/basis/tools/deploy/windows/windows.factor index ec1259c777..6188e78b0e 100755 --- a/basis/tools/deploy/windows/windows.factor +++ b/basis/tools/deploy/windows/windows.factor @@ -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 -- ) diff --git a/basis/tools/disassembler/disassembler-tests.factor b/basis/tools/disassembler/disassembler-tests.factor index 782f244c68..96f5a04378 100644 --- a/basis/tools/disassembler/disassembler-tests.factor +++ b/basis/tools/disassembler/disassembler-tests.factor @@ -1,6 +1,6 @@ IN: tools.disassembler.tests -USING: math classes.tuple prettyprint.backend tools.disassembler -tools.test strings ; +USING: math classes.tuple prettyprint.custom +tools.disassembler tools.test strings ; [ ] [ \ + disassemble ] unit-test [ ] [ { string pprint* } disassemble ] unit-test diff --git a/basis/tools/files/files-tests.factor b/basis/tools/files/files-tests.factor index 6aa68d8127..4dc4ef23f0 100644 --- a/basis/tools/files/files-tests.factor +++ b/basis/tools/files/files-tests.factor @@ -6,3 +6,6 @@ IN: tools.files.tests \ directory. must-infer [ ] [ "" directory. ] unit-test + +[ ] +[ { device-name free-space used-space total-space percent-used } file-systems. ] unit-test diff --git a/basis/tools/files/files.factor b/basis/tools/files/files.factor index 18baedae0a..a8ce9c9554 100755 --- a/basis/tools/files/files.factor +++ b/basis/tools/files/files.factor @@ -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 ; @@ -65,5 +66,3 @@ percent-used percent-free ; { [ os unix? ] [ "tools.files.unix" ] } { [ os windows? ] [ "tools.files.windows" ] } } cond require - -! { device-name free-space used-space total-space percent-used } file-systems. diff --git a/basis/tools/walker/walker.factor b/basis/tools/walker/walker.factor index 953291cc59..27358b53fc 100644 --- a/basis/tools/walker/walker.factor +++ b/basis/tools/walker/walker.factor @@ -236,7 +236,7 @@ SYMBOL: +stopped+ : walker-loop ( -- ) +running+ set-status - [ status +stopped+ eq? not ] [ + [ status +stopped+ eq? ] [ [ { ! ignore these commands while the thread is @@ -255,7 +255,7 @@ SYMBOL: +stopped+ [ walker-suspended ] } case ] handle-synchronous - ] [ ] while ; + ] [ ] until ; : associate-thread ( walker -- ) walker-thread tset diff --git a/basis/ui/cocoa/cocoa.factor b/basis/ui/cocoa/cocoa.factor index 42063fbf73..b90f4d34fe 100644 --- a/basis/ui/cocoa/cocoa.factor +++ b/basis/ui/cocoa/cocoa.factor @@ -3,9 +3,10 @@ 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 -ui ui.backend ui.clipboards ui.gadgets ui.gadgets.worlds -ui.cocoa.views core-foundation threads math.geometry.rect fry ; +cocoa.windows cocoa.classes cocoa.application cocoa.nibs +sequences system ui ui.backend ui.clipboards ui.gadgets +ui.gadgets.worlds ui.cocoa.views core-foundation threads +math.geometry.rect fry ; IN: ui.cocoa TUPLE: handle view window ; @@ -110,7 +111,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 [ diff --git a/basis/ui/freetype/freetype.factor b/basis/ui/freetype/freetype.factor index 6c0eaaa9ac..22a4f1722d 100644 --- a/basis/ui/freetype/freetype.factor +++ b/basis/ui/freetype/freetype.factor @@ -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 ; diff --git a/basis/ui/gadgets/labelled/labelled.factor b/basis/ui/gadgets/labelled/labelled.factor index 108c5ae461..636e25cea5 100644 --- a/basis/ui/gadgets/labelled/labelled.factor +++ b/basis/ui/gadgets/labelled/labelled.factor @@ -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 diff --git a/basis/ui/gadgets/presentations/presentations.factor b/basis/ui/gadgets/presentations/presentations.factor index 33ef3bbe3a..61a55e926b 100644 --- a/basis/ui/gadgets/presentations/presentations.factor +++ b/basis/ui/gadgets/presentations/presentations.factor @@ -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 diff --git a/basis/ui/gadgets/worlds/worlds.factor b/basis/ui/gadgets/worlds/worlds.factor index 68a2a18210..3b9b2fa1f3 100644 --- a/basis/ui/gadgets/worlds/worlds.factor +++ b/basis/ui/gadgets/worlds/worlds.factor @@ -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 @@ -76,7 +76,7 @@ C: 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 diff --git a/basis/ui/tools/deploy/deploy.factor b/basis/ui/tools/deploy/deploy.factor index f023b0959a..f233c9f162 100644 --- a/basis/ui/tools/deploy/deploy.factor +++ b/basis/ui/tools/deploy/deploy.factor @@ -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 ; diff --git a/basis/ui/ui.factor b/basis/ui/ui.factor index de2eb71307..88f0a353b9 100644 --- a/basis/ui/ui.factor +++ b/basis/ui/ui.factor @@ -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 diff --git a/basis/ui/windows/windows.factor b/basis/ui/windows/windows.factor index 1481287e95..0510e21f17 100755 --- a/basis/ui/windows/windows.factor +++ b/basis/ui/windows/windows.factor @@ -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 diff --git a/basis/ui/x11/x11.factor b/basis/ui/x11/x11.factor index b65236d1f9..a532a13b69 100755 --- a/basis/ui/x11/x11.factor +++ b/basis/ui/x11/x11.factor @@ -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 diff --git a/basis/unicode/syntax/syntax.factor b/basis/unicode/syntax/syntax.factor index bf4610ab0d..b7ac022d0e 100644 --- a/basis/unicode/syntax/syntax.factor +++ b/basis/unicode/syntax/syntax.factor @@ -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 index 0000000000..ea32657057 --- /dev/null +++ b/basis/unix/debugger/debugger.factor @@ -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 index 0000000000..6bf68304bb --- /dev/null +++ b/basis/unix/debugger/tags.txt @@ -0,0 +1 @@ +unportable diff --git a/basis/unix/unix.factor b/basis/unix/unix.factor index d917425bf9..555f8e2c7d 100644 --- a/basis/unix/unix.factor +++ b/basis/unix/unix.factor @@ -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 index 0000000000..59fb79e8d3 --- /dev/null +++ b/basis/urls/prettyprint/prettyprint.factor @@ -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 ; diff --git a/basis/urls/urls.factor b/basis/urls/urls.factor index c0fb1695c3..d71ce4ef7b 100644 --- a/basis/urls/urls.factor +++ b/basis/urls/urls.factor @@ -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 diff --git a/basis/vlists/vlists.factor b/basis/vlists/vlists.factor index e0f7e55554..ea40594964 100644 --- a/basis/vlists/vlists.factor +++ b/basis/vlists/vlists.factor @@ -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 diff --git a/basis/windows/shell32/shell32.factor b/basis/windows/shell32/shell32.factor index b071bee72a..eae796ac08 100644 --- a/basis/windows/shell32/shell32.factor +++ b/basis/windows/shell32/shell32.factor @@ -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 diff --git a/basis/windows/windows.factor b/basis/windows/windows.factor index 2fc1dbf122..d2250d6f7e 100644 --- a/basis/windows/windows.factor +++ b/basis/windows/windows.factor @@ -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 ; inline diff --git a/basis/windows/winsock/winsock.factor b/basis/windows/winsock/winsock.factor index 4ca07ce850..5d450897e2 100644 --- a/basis/windows/winsock/winsock.factor +++ b/basis/windows/winsock/winsock.factor @@ -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 diff --git a/basis/x11/xim/xim.factor b/basis/x11/xim/xim.factor index 71b0b5f133..862ec3355a 100644 --- a/basis/x11/xim/xim.factor +++ b/basis/x11/xim/xim.factor @@ -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 diff --git a/core/bootstrap/primitives.factor b/core/bootstrap/primitives.factor index f90ba23999..cc05efc46e 100644 --- a/core/bootstrap/primitives.factor +++ b/core/bootstrap/primitives.factor @@ -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 [ fixnum-bitand ] curry append "coercer" set-word-prop ! Catch-all class for providing a default method. diff --git a/core/bootstrap/stage1.factor b/core/bootstrap/stage1.factor index 26a27ecefb..874a9dd0d2 100644 --- a/core/bootstrap/stage1.factor +++ b/core/bootstrap/stage1.factor @@ -31,7 +31,7 @@ load-help? off "math.integers" require "math.floats" require "memory" require - + "io.streams.c" require "vocabs.loader" require diff --git a/core/bootstrap/syntax.factor b/core/bootstrap/syntax.factor index e7dd333ed8..badc1f5218 100644 --- a/core/bootstrap/syntax.factor +++ b/core/bootstrap/syntax.factor @@ -16,7 +16,6 @@ IN: bootstrap.syntax " ] dip checksum-stream ; - M: checksum checksum-stream [ contents ] dip checksum-bytes ; diff --git a/core/classes/algebra/algebra-docs.factor b/core/classes/algebra/algebra-docs.factor index 810bdbe10f..2730e4683b 100644 --- a/core/classes/algebra/algebra-docs.factor +++ b/core/classes/algebra/algebra-docs.factor @@ -4,6 +4,7 @@ IN: classes.algebra ARTICLE: "class-operations" "Class operations" "Set-theoretic operations on classes:" +{ $subsection class= } { $subsection class< } { $subsection class<= } { $subsection class-and } diff --git a/core/classes/tuple/tuple.factor b/core/classes/tuple/tuple.factor index 9d748d665d..d9464399a9 100644 --- a/core/classes/tuple/tuple.factor +++ b/core/classes/tuple/tuple.factor @@ -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 -- ? ) diff --git a/core/combinators/combinators-docs.factor b/core/combinators/combinators-docs.factor index 8d1d9f0d2a..a26c2fbe5d 100644 --- a/core/combinators/combinators-docs.factor +++ b/core/combinators/combinators-docs.factor @@ -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 } ":" diff --git a/core/growable/growable-docs.factor b/core/growable/growable-docs.factor index 9f950aa36c..e1ab50cdcd 100644 --- a/core/growable/growable-docs.factor +++ b/core/growable/growable-docs.factor @@ -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/kernel/kernel-docs.factor b/core/kernel/kernel-docs.factor index 01ef8d480d..1404491d10 100644 --- a/core/kernel/kernel-docs.factor +++ b/core/kernel/kernel-docs.factor @@ -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" } diff --git a/core/kernel/kernel.factor b/core/kernel/kernel.factor index 564600d322..d4df6fa407 100644 --- a/core/kernel/kernel.factor +++ b/core/kernel/kernel.factor @@ -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) ; diff --git a/core/math/integers/integers.factor b/core/math/integers/integers.factor index 30903e3269..6ed945216e 100644 --- a/core/math/integers/integers.factor +++ b/core/math/integers/integers.factor @@ -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 ; diff --git a/core/memory/memory.factor b/core/memory/memory.factor index 42527371f2..b67f7c94e8 100644 --- a/core/memory/memory.factor +++ b/core/memory/memory.factor @@ -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 diff --git a/core/slots/slots.factor b/core/slots/slots.factor index 187db02c5c..438e604e78 100644 --- a/core/slots/slots.factor +++ b/core/slots/slots.factor @@ -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 diff --git a/core/source-files/source-files.factor b/core/source-files/source-files.factor index 767c2a1f79..3ae50a9a15 100644 --- a/core/source-files/source-files.factor +++ b/core/source-files/source-files.factor @@ -78,7 +78,7 @@ M: pathname forget* SYMBOL: file -TUPLE: source-file-error file error ; +TUPLE: source-file-error error file ; : ( 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 index 0000000000..80f649c204 --- /dev/null +++ b/core/strings/parser/parser-tests.factor @@ -0,0 +1,4 @@ +IN: strings.parser.tests +USING: strings.parser tools.test ; + +[ "Hello\n\rworld" ] [ "Hello\\n\\rworld" unescape-string ] unit-test diff --git a/core/strings/parser/parser.factor b/core/strings/parser/parser.factor index cfe5d1a90a..4062e16e3d 100644 --- a/core/strings/parser/parser.factor +++ b/core/strings/parser/parser.factor @@ -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 ; diff --git a/core/syntax/syntax.factor b/core/syntax/syntax.factor index c951750b34..0b7d9d008f 100644 --- a/core/syntax/syntax.factor +++ b/core/syntax/syntax.factor @@ -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 ] parse-literal ] define-syntax diff --git a/core/vocabs/loader/loader-tests.factor b/core/vocabs/loader/loader-tests.factor index e5bd74a981..533bea76fc 100644 --- a/core/vocabs/loader/loader-tests.factor +++ b/core/vocabs/loader/loader-tests.factor @@ -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 diff --git a/core/vocabs/loader/loader.factor b/core/vocabs/loader/loader.factor index 6fb0d08811..97fbfe8a07 100644 --- a/core/vocabs/loader/loader.factor +++ b/core/vocabs/loader/loader.factor @@ -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 index 0000000000..6d545483a3 --- /dev/null +++ b/core/vocabs/loader/test/j/j.factor @@ -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 index 0000000000..6bf68304bb --- /dev/null +++ b/core/vocabs/loader/test/j/tags.txt @@ -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 index 0000000000..603b48b374 --- /dev/null +++ b/core/vocabs/loader/test/k/k.factor @@ -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 index 0000000000..6bf68304bb --- /dev/null +++ b/core/vocabs/loader/test/k/tags.txt @@ -0,0 +1 @@ +unportable diff --git a/extra/bind-in/bind-in.factor b/extra/bind-in/bind-in.factor index ab6ff19094..78c797df9b 100644 --- a/extra/bind-in/bind-in.factor +++ b/extra/bind-in/bind-in.factor @@ -1,5 +1,5 @@ -USING: kernel parser lexer locals.private ; +USING: kernel parser lexer locals.parser locals.types ; IN: bind-in diff --git a/extra/descriptive/descriptive.factor b/extra/descriptive/descriptive.factor index d02983d7fd..b1fdf2463e 100755 --- a/extra/descriptive/descriptive.factor +++ b/extra/descriptive/descriptive.factor @@ -1,5 +1,5 @@ -USING: words kernel sequences locals -locals.private accessors parser namespaces continuations +USING: words kernel sequences locals locals.parser +locals.definitions accessors parser namespaces continuations summary definitions generalizations arrays ; IN: descriptive diff --git a/extra/game-input/backend/dinput/dinput.factor b/extra/game-input/backend/dinput/dinput.factor index 116faf60cd..b66a722258 100755 --- a/extra/game-input/backend/dinput/dinput.factor +++ b/extra/game-input/backend/dinput/dinput.factor @@ -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 diff --git a/extra/hello-world/deploy.factor b/extra/hello-world/deploy.factor index 64ea481b03..48c14f7cba 100755 --- a/extra/hello-world/deploy.factor +++ b/extra/hello-world/deploy.factor @@ -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-ui? f } - { deploy-compiler? f } - { deploy-io 2 } { deploy-c-types? f } + { deploy-word-props? f } + { deploy-ui? f } + { deploy-reflection 1 } + { deploy-compiler? f } + { deploy-unicode? f } + { deploy-io 2 } + { deploy-word-defs? f } + { deploy-threads? f } + { "stop-after-last-window?" t } + { deploy-math? f } } diff --git a/extra/monads/monads-tests.factor b/extra/monads/monads-tests.factor index d0014b5abe..44234bc4bc 100644 --- a/extra/monads/monads-tests.factor +++ b/extra/monads/monads-tests.factor @@ -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 diff --git a/extra/multi-methods/multi-methods.factor b/extra/multi-methods/multi-methods.factor index 14062b15db..cfdc28bb3d 100755 --- a/extra/multi-methods/multi-methods.factor +++ b/extra/multi-methods/multi-methods.factor @@ -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 diff --git a/extra/parser-combinators/regexp/regexp.factor b/extra/parser-combinators/regexp/regexp.factor index b13321d991..7c23dcce0b 100755 --- a/extra/parser-combinators/regexp/regexp.factor +++ b/extra/parser-combinators/regexp/regexp.factor @@ -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 ; - -! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! - -: 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 diff --git a/extra/reports/noise/noise.factor b/extra/reports/noise/noise.factor index 78ede32801..6a547ead24 100755 --- a/extra/reports/noise/noise.factor +++ b/extra/reports/noise/noise.factor @@ -2,8 +2,9 @@ ! See http://factorcode.org/license.txt for BSD license. USING: accessors assocs math kernel shuffle generalizations words quotations arrays combinators sequences math.vectors -io.styles prettyprint vocabs sorting io generic locals.private -math.statistics math.order combinators.lib ; +io.styles prettyprint vocabs sorting io generic +math.statistics math.order combinators.lib locals.types +locals.definitions ; IN: reports.noise : badness ( word -- n ) diff --git a/extra/trails/trails.factor b/extra/trails/trails.factor new file mode 100644 index 0000000000..cea5ece9f7 --- /dev/null +++ b/extra/trails/trails.factor @@ -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 ; + +! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +: percent->radius ( percent -- radius ) neg 1 + 25 * 5 max ; + +: dot ( pos percent -- ) percent->radius circle ; + +! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +TUPLE: < 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: pref-dim* ( -- dim ) drop { 500 500 } ; + +! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +M:: 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 ( -- ) + + 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 diff --git a/vm/data_gc.c b/vm/data_gc.c index 513a7c429c..6e15718b2d 100755 --- a/vm/data_gc.c +++ b/vm/data_gc.c @@ -985,7 +985,8 @@ void primitive_become(void) } gc(); - iterate_code_heap(relocate_code_block); + + compile_all_words(); } CELL find_all_words(void) diff --git a/vm/factor.c b/vm/factor.c index f198370ebe..2f78a797d4 100755 --- a/vm/factor.c +++ b/vm/factor.c @@ -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"); diff --git a/vm/quotations.c b/vm/quotations.c index a187fecbbb..86952a32e8 100755 --- a/vm/quotations.c +++ b/vm/quotations.c @@ -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); +} diff --git a/vm/quotations.h b/vm/quotations.h index ff84977fd9..4c2c17bbb6 100755 --- a/vm/quotations.h +++ b/vm/quotations.h @@ -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);