diff --git a/Makefile b/Makefile old mode 100644 new mode 100755 index c19d83e58e..33d42217a2 --- a/Makefile +++ b/Makefile @@ -9,11 +9,10 @@ VERSION = 0.92 BUNDLE = Factor.app LIBPATH = -L/usr/X11R6/lib -CFLAGS = -Wall -FFI_TEST_CFLAGS = -fPIC +CFLAGS = -Wall -Werror ifdef DEBUG - CFLAGS += -g + CFLAGS += -g -DFACTOR_DEBUG else CFLAGS += -O3 endif @@ -28,7 +27,10 @@ endif DLL_OBJS = $(PLAF_DLL_OBJS) \ vm/alien.o \ + vm/arrays.o \ vm/bignum.o \ + vm/booleans.o \ + vm/byte_arrays.o \ vm/callstack.o \ vm/code_block.o \ vm/code_gc.o \ @@ -36,17 +38,22 @@ DLL_OBJS = $(PLAF_DLL_OBJS) \ vm/data_gc.o \ vm/data_heap.o \ vm/debug.o \ + vm/dispatch.o \ vm/errors.o \ vm/factor.o \ vm/image.o \ + vm/inline_cache.o \ vm/io.o \ + vm/jit.o \ vm/math.o \ vm/primitives.o \ vm/profiler.o \ vm/quotations.o \ vm/run.o \ - vm/types.o \ - vm/utilities.o + vm/strings.o \ + vm/tuples.o \ + vm/utilities.o \ + vm/words.o EXE_OBJS = $(PLAF_EXE_OBJS) @@ -183,5 +190,5 @@ vm/ffi_test.o: vm/ffi_test.c .m.o: $(CC) -c $(CFLAGS) -o $@ $< - + .PHONY: factor diff --git a/basis/alarms/alarms.factor b/basis/alarms/alarms.factor index 9cc05b4159..f9fdce806f 100644 --- a/basis/alarms/alarms.factor +++ b/basis/alarms/alarms.factor @@ -71,7 +71,7 @@ ERROR: bad-alarm-frequency frequency ; ] when* ; : init-alarms ( -- ) - alarms global [ cancel-alarms ] change-at + alarms [ cancel-alarms ] change-global [ alarm-thread-loop t ] "Alarms" spawn-server alarm-thread set-global ; diff --git a/basis/alien/libraries/libraries-docs.factor b/basis/alien/libraries/libraries-docs.factor old mode 100644 new mode 100755 index c555061e58..eac7655c38 --- a/basis/alien/libraries/libraries-docs.factor +++ b/basis/alien/libraries/libraries-docs.factor @@ -15,7 +15,7 @@ HELP: libraries { $description "A global hashtable that keeps a list of open libraries. Use the " { $link add-library } " word to construct a library and add it with a single call." } ; HELP: library -{ $values { "name" "a string" } { "library" "a hashtable" } } +{ $values { "name" "a string" } { "library" assoc } } { $description "Looks up a library by its logical name. The library object is a hashtable with the following keys:" { $list { { $snippet "name" } " - the full path of the C library binary" } diff --git a/basis/alien/remote-control/remote-control.factor b/basis/alien/remote-control/remote-control.factor index 4da06ec4c9..b72c79e478 100644 --- a/basis/alien/remote-control/remote-control.factor +++ b/basis/alien/remote-control/remote-control.factor @@ -15,7 +15,7 @@ IN: alien.remote-control "void" { "long" } "cdecl" [ sleep ] alien-callback ; : ?callback ( word -- alien ) - dup optimized>> [ execute ] [ drop f ] if ; inline + dup optimized? [ execute ] [ drop f ] if ; inline : init-remote-control ( -- ) \ eval-callback ?callback 16 setenv diff --git a/basis/bootstrap/compiler/compiler.factor b/basis/bootstrap/compiler/compiler.factor index 89a0ed86fe..7940703140 100644 --- a/basis/bootstrap/compiler/compiler.factor +++ b/basis/bootstrap/compiler/compiler.factor @@ -5,7 +5,7 @@ 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 libc splitting math.parser +io.encodings.string libc splitting math.parser memory compiler.units math.order compiler.tree.builder compiler.tree.optimizer compiler.cfg.optimizer ; IN: bootstrap.compiler @@ -23,10 +23,13 @@ IN: bootstrap.compiler "cpu." cpu name>> append require -enable-compiler +enable-optimizer + +! Push all tuple layouts to tenured space to improve method caching +gc : compile-unoptimized ( words -- ) - [ optimized>> not ] filter compile ; + [ optimized? not ] filter compile ; nl "Compiling..." write flush diff --git a/basis/bootstrap/image/image.factor b/basis/bootstrap/image/image.factor index 504afae018..cad40b6384 100644 --- a/basis/bootstrap/image/image.factor +++ b/basis/bootstrap/image/image.factor @@ -3,14 +3,13 @@ USING: alien arrays byte-arrays generic assocs hashtables assocs hashtables.private io io.binary io.files io.encodings.binary io.pathnames kernel kernel.private math namespaces make parser -prettyprint sequences sequences.private strings sbufs -vectors words quotations assocs system layouts splitting -grouping growable classes classes.builtin classes.tuple -classes.tuple.private words.private vocabs -vocabs.loader source-files definitions debugger -quotations.private sequences.private combinators -math.order math.private accessors -slots.private compiler.units fry ; +prettyprint sequences sequences.private strings sbufs vectors words +quotations assocs system layouts splitting grouping growable classes +classes.builtin classes.tuple classes.tuple.private vocabs +vocabs.loader source-files definitions debugger quotations.private +sequences.private combinators math.order math.private accessors +slots.private generic.single.private compiler.units compiler.constants +fry ; IN: bootstrap.image : arch ( os cpu -- arch ) @@ -94,13 +93,30 @@ CONSTANT: -1-offset 9 SYMBOL: sub-primitives -: make-jit ( quot rc rt offset -- quad ) - [ [ call( -- ) ] { } make ] 3dip 4array ; +SYMBOL: jit-define-rc +SYMBOL: jit-define-rt +SYMBOL: jit-define-offset -: jit-define ( quot rc rt offset name -- ) +: compute-offset ( -- offset ) + building get length jit-define-rc get rc-absolute-cell = bootstrap-cell 4 ? - ; + +: jit-rel ( rc rt -- ) + jit-define-rt set + jit-define-rc set + compute-offset jit-define-offset set ; + +: make-jit ( quot -- quad ) + [ + call( -- ) + jit-define-rc get + jit-define-rt get + jit-define-offset get 3array + ] B{ } make prefix ; + +: jit-define ( quot name -- ) [ make-jit ] dip set ; -: define-sub-primitive ( quot rc rt offset word -- ) +: define-sub-primitive ( quot word -- ) [ make-jit ] dip sub-primitives get set-at ; ! The image being constructed; a vector of word-size integers @@ -119,7 +135,6 @@ SYMBOL: bootstrap-global SYMBOL: bootstrap-boot-quot ! JIT parameters -SYMBOL: jit-code-format SYMBOL: jit-prolog SYMBOL: jit-primitive-word SYMBOL: jit-primitive @@ -129,20 +144,36 @@ SYMBOL: jit-push-immediate SYMBOL: jit-if-word SYMBOL: jit-if-1 SYMBOL: jit-if-2 -SYMBOL: jit-dispatch-word -SYMBOL: jit-dispatch SYMBOL: jit-dip-word SYMBOL: jit-dip SYMBOL: jit-2dip-word SYMBOL: jit-2dip SYMBOL: jit-3dip-word SYMBOL: jit-3dip +SYMBOL: jit-execute-word +SYMBOL: jit-execute-jump +SYMBOL: jit-execute-call SYMBOL: jit-epilog SYMBOL: jit-return SYMBOL: jit-profiling -SYMBOL: jit-declare-word SYMBOL: jit-save-stack +! PIC stubs +SYMBOL: pic-load +SYMBOL: pic-tag +SYMBOL: pic-hi-tag +SYMBOL: pic-tuple +SYMBOL: pic-hi-tag-tuple +SYMBOL: pic-check-tag +SYMBOL: pic-check +SYMBOL: pic-hit +SYMBOL: pic-miss-word + +! Megamorphic dispatch +SYMBOL: mega-lookup +SYMBOL: mega-lookup-word +SYMBOL: mega-miss-word + ! Default definition for undefined words SYMBOL: undefined-quot @@ -150,7 +181,6 @@ SYMBOL: undefined-quot H{ { bootstrap-boot-quot 20 } { bootstrap-global 21 } - { jit-code-format 22 } { jit-prolog 23 } { jit-primitive-word 24 } { jit-primitive 25 } @@ -159,20 +189,32 @@ SYMBOL: undefined-quot { jit-if-word 28 } { jit-if-1 29 } { jit-if-2 30 } - { jit-dispatch-word 31 } - { jit-dispatch 32 } { jit-epilog 33 } { jit-return 34 } { jit-profiling 35 } { jit-push-immediate 36 } - { jit-declare-word 42 } - { jit-save-stack 43 } - { jit-dip-word 44 } - { jit-dip 45 } - { jit-2dip-word 46 } - { jit-2dip 47 } - { jit-3dip-word 48 } - { jit-3dip 49 } + { jit-save-stack 38 } + { jit-dip-word 39 } + { jit-dip 40 } + { jit-2dip-word 41 } + { jit-2dip 42 } + { jit-3dip-word 43 } + { jit-3dip 44 } + { jit-execute-word 45 } + { jit-execute-jump 46 } + { jit-execute-call 47 } + { pic-load 48 } + { pic-tag 49 } + { pic-hi-tag 50 } + { pic-tuple 51 } + { pic-hi-tag-tuple 52 } + { pic-check-tag 53 } + { pic-check 54 } + { pic-hit 55 } + { pic-miss-word 56 } + { mega-lookup 57 } + { mega-lookup-word 58 } + { mega-miss-word 59 } { undefined-quot 60 } } ; inline @@ -205,8 +247,8 @@ SYMBOL: undefined-quot : emit-fixnum ( n -- ) tag-fixnum emit ; -: emit-object ( header tag quot -- addr ) - swap here-as [ swap tag-fixnum emit call align-here ] dip ; +: emit-object ( class quot -- addr ) + over tag-number here-as [ swap type-number tag-fixnum emit call align-here ] dip ; inline ! Write an object to the image. @@ -251,7 +293,7 @@ GENERIC: ' ( obj -- ptr ) M: bignum ' [ - bignum tag-number dup [ emit-bignum ] emit-object + bignum [ emit-bignum ] emit-object ] cache-object ; ! Fixnums @@ -274,7 +316,7 @@ M: fake-bignum ' n>> tag-fixnum ; M: float ' [ - float tag-number dup [ + float [ align-here double>bits emit-64 ] emit-object ] cache-object ; @@ -309,7 +351,7 @@ M: f ' [ vocabulary>> , ] [ def>> , ] [ props>> , ] - [ drop f , ] + [ direct-entry-def>> , ] ! direct-entry-def [ drop 0 , ] ! count [ word-sub-primitive , ] [ drop 0 , ] ! xt @@ -318,8 +360,7 @@ M: f ' } cleave ] { } make [ ' ] map ] bi - \ word type-number object tag-number - [ emit-seq ] emit-object + \ word [ emit-seq ] emit-object ] keep put-object ; : word-error ( word msg -- * ) @@ -340,8 +381,7 @@ M: word ' ; ! Wrappers M: wrapper ' - wrapped>> ' wrapper type-number object tag-number - [ emit ] emit-object ; + wrapped>> ' wrapper [ emit ] emit-object ; ! Strings : native> ( object -- object ) @@ -370,7 +410,7 @@ M: wrapper ' : emit-string ( string -- ptr ) [ length ] [ extended-part ' ] [ ] tri - string type-number object tag-number [ + string [ [ emit-fixnum ] [ emit ] [ f ' emit ascii-part pad-bytes emit-bytes ] @@ -387,12 +427,11 @@ M: string ' : emit-dummy-array ( obj type -- ptr ) [ assert-empty ] [ - type-number object tag-number [ 0 emit-fixnum ] emit-object ] bi* ; M: byte-array ' - byte-array type-number object tag-number [ + byte-array [ dup length emit-fixnum pad-bytes emit-bytes ] emit-object ; @@ -406,7 +445,7 @@ ERROR: tuple-removed class ; : (emit-tuple) ( tuple -- pointer ) [ tuple-slots ] [ class transfer-word require-tuple-layout ] bi prefix [ ' ] map - tuple type-number dup [ emit-seq ] emit-object ; + tuple [ emit-seq ] emit-object ; : emit-tuple ( tuple -- pointer ) dup class name>> "tombstone" = @@ -421,8 +460,7 @@ M: tombstone ' ! Arrays : emit-array ( array -- offset ) - [ ' ] map array type-number object tag-number - [ [ length emit-fixnum ] [ emit-seq ] bi ] emit-object ; + [ ' ] map array [ [ length emit-fixnum ] [ emit-seq ] bi ] emit-object ; M: array ' emit-array ; @@ -448,7 +486,7 @@ M: tuple-layout-array ' M: quotation ' [ array>> ' - quotation type-number object tag-number [ + quotation [ emit ! array f ' emit ! compiled f ' emit ! cached-effect @@ -480,15 +518,16 @@ M: quotation ' : emit-jit-data ( -- ) \ if jit-if-word set - \ dispatch jit-dispatch-word set \ do-primitive jit-primitive-word set - \ declare jit-declare-word set \ dip jit-dip-word set \ 2dip jit-2dip-word set \ 3dip jit-3dip-word set + \ (execute) jit-execute-word set + \ inline-cache-miss \ pic-miss-word set + \ mega-cache-lookup \ mega-lookup-word set + \ mega-cache-miss \ mega-miss-word set [ undefined ] undefined-quot set { - jit-code-format jit-prolog jit-primitive-word jit-primitive @@ -498,19 +537,31 @@ M: quotation ' jit-if-word jit-if-1 jit-if-2 - jit-dispatch-word - jit-dispatch jit-dip-word jit-dip jit-2dip-word jit-2dip jit-3dip-word jit-3dip + jit-execute-word + jit-execute-jump + jit-execute-call jit-epilog jit-return jit-profiling - jit-declare-word jit-save-stack + pic-load + pic-tag + pic-hi-tag + pic-tuple + pic-hi-tag-tuple + pic-check-tag + pic-check + pic-hit + pic-miss-word + mega-lookup + mega-lookup-word + mega-miss-word undefined-quot } [ emit-userenv ] each ; diff --git a/basis/bootstrap/stage2.factor b/basis/bootstrap/stage2.factor index cc853e4842..14c08c070a 100644 --- a/basis/bootstrap/stage2.factor +++ b/basis/bootstrap/stage2.factor @@ -35,10 +35,6 @@ SYMBOL: bootstrap-time "Core bootstrap completed in " write core-bootstrap-time get print-time "Bootstrap completed in " write bootstrap-time get print-time - [ optimized>> ] count-words " compiled words" print - [ symbol? ] count-words " symbol words" print - [ ] count-words " words total" print - "Bootstrapping is complete." print "Now, you can run Factor:" print vm write " -i=" write "output-image" get print flush ; diff --git a/basis/calendar/windows/windows.factor b/basis/calendar/windows/windows.factor index 508cbb0a49..caab530a23 100644 --- a/basis/calendar/windows/windows.factor +++ b/basis/calendar/windows/windows.factor @@ -1,5 +1,5 @@ -USING: calendar namespaces alien.c-types system windows -windows.kernel32 kernel math combinators ; +USING: calendar namespaces alien.c-types system +windows.kernel32 kernel math combinators windows.errors ; IN: calendar.windows M: windows gmt-offset ( -- hours minutes seconds ) diff --git a/basis/cocoa/cocoa.factor b/basis/cocoa/cocoa.factor index 69d698f9b1..3e933e6643 100644 --- a/basis/cocoa/cocoa.factor +++ b/basis/cocoa/cocoa.factor @@ -7,7 +7,7 @@ compiler.units lexer init ; IN: cocoa : (remember-send) ( selector variable -- ) - global [ dupd ?set-at ] change-at ; + [ dupd ?set-at ] change-global ; SYMBOL: sent-messages diff --git a/basis/cocoa/dialogs/dialogs.factor b/basis/cocoa/dialogs/dialogs.factor index 84a1ad46a3..7761286127 100644 --- a/basis/cocoa/dialogs/dialogs.factor +++ b/basis/cocoa/dialogs/dialogs.factor @@ -12,6 +12,9 @@ IN: cocoa.dialogs dup 1 -> setResolvesAliases: dup 1 -> setAllowsMultipleSelection: ; +: ( -- panel ) + dup 1 -> setCanChooseDirectories: ; + : ( -- panel ) NSSavePanel -> savePanel dup 1 -> setCanChooseFiles: @@ -21,10 +24,12 @@ IN: cocoa.dialogs CONSTANT: NSOKButton 1 CONSTANT: NSCancelButton 0 -: open-panel ( -- paths ) - +: (open-panel) ( panel -- paths ) dup -> runModal NSOKButton = [ -> filenames CF>string-array ] [ drop f ] if ; + +: open-panel ( -- paths ) (open-panel) ; +: open-dir-panel ( -- paths ) (open-panel) ; : split-path ( path -- dir file ) "/" split1-last [ ] bi@ ; diff --git a/basis/command-line/command-line-docs.factor b/basis/command-line/command-line-docs.factor index 3d06bd97b7..5aeb49d6f2 100644 --- a/basis/command-line/command-line-docs.factor +++ b/basis/command-line/command-line-docs.factor @@ -1,5 +1,4 @@ -USING: help.markup help.syntax parser vocabs.loader strings -command-line.private ; +USING: help.markup help.syntax parser vocabs.loader strings ; IN: command-line HELP: run-bootstrap-init @@ -53,6 +52,7 @@ ARTICLE: "runtime-cli-args" "Command line switches for the VM" { { $snippet "-aging=" { $emphasis "n" } } "Size of aging generation (1), megabytes" } { { $snippet "-tenured=" { $emphasis "n" } } "Size of oldest generation (2), megabytes" } { { $snippet "-codeheap=" { $emphasis "n" } } "Code heap size, megabytes" } + { { $snippet "-pic=" { $emphasis "n" } } "Maximum inline cache size. Setting of 0 disables inline caching, > 1 enables polymorphic inline caching" } { { $snippet "-securegc" } "If specified, unused portions of the data heap will be zeroed out after every garbage collection" } } "If an " { $snippet "-i=" } " switch is not present, the default image file is used, which is usually a file named " { $snippet "factor.image" } " in the same directory as the runtime executable (on Windows and Mac OS X) or the current directory (on Unix)." ; diff --git a/basis/compiler/cfg/intrinsics/allot/allot.factor b/basis/compiler/cfg/intrinsics/allot/allot.factor index 3a4c702bc5..938dbbccbf 100644 --- a/basis/compiler/cfg/intrinsics/allot/allot.factor +++ b/basis/compiler/cfg/intrinsics/allot/allot.factor @@ -27,11 +27,11 @@ IN: compiler.cfg.intrinsics.allot [ tuple ##set-slots ] [ ds-push drop ] 2bi ] [ drop emit-primitive ] if ; -: store-length ( len reg -- ) - [ ^^load-literal ] dip 1 object tag-number ##set-slot-imm ; +: store-length ( len reg class -- ) + [ [ ^^load-literal ] dip 1 ] dip tag-number ##set-slot-imm ; -: store-initial-element ( elt reg len -- ) - [ 2 + object tag-number ##set-slot-imm ] with with each ; +:: store-initial-element ( len reg elt class -- ) + len [ [ elt reg ] dip 2 + class tag-number ##set-slot-imm ] each ; : expand-? ( obj -- ? ) dup integer? [ 0 8 between? ] [ drop f ] if ; @@ -42,8 +42,8 @@ IN: compiler.cfg.intrinsics.allot [let | elt [ ds-pop ] reg [ len ^^allot-array ] | ds-drop - len reg store-length - elt reg len store-initial-element + len reg array store-length + len reg elt array store-initial-element reg ds-push ] ] [ node emit-primitive ] if @@ -57,16 +57,16 @@ IN: compiler.cfg.intrinsics.allot : emit-allot-byte-array ( len -- dst ) ds-drop dup ^^allot-byte-array - [ store-length ] [ ds-push ] [ ] tri ; + [ byte-array store-length ] [ ds-push ] [ ] tri ; : emit-(byte-array) ( node -- ) dup node-input-infos first literal>> dup expand-? [ nip emit-allot-byte-array drop ] [ drop emit-primitive ] if ; -: emit- ( node -- ) - dup node-input-infos first literal>> dup expand-? [ - nip - [ 0 ^^load-literal ] dip - [ emit-allot-byte-array ] keep - bytes>cells store-initial-element - ] [ drop emit-primitive ] if ; +:: emit- ( node -- ) + node node-input-infos first literal>> dup expand-? [ + :> len + 0 ^^load-literal :> elt + len emit-allot-byte-array :> reg + len reg elt byte-array store-initial-element + ] [ drop node emit-primitive ] if ; diff --git a/basis/compiler/cfg/intrinsics/intrinsics.factor b/basis/compiler/cfg/intrinsics/intrinsics.factor index 3d0a7bec9c..ec819f9440 100644 --- a/basis/compiler/cfg/intrinsics/intrinsics.factor +++ b/basis/compiler/cfg/intrinsics/intrinsics.factor @@ -52,8 +52,6 @@ IN: compiler.cfg.intrinsics arrays: byte-arrays: byte-arrays:(byte-array) - math.private: - math.private: kernel: alien.accessors:alien-unsigned-1 alien.accessors:set-alien-unsigned-1 @@ -140,8 +138,6 @@ IN: compiler.cfg.intrinsics { \ arrays: [ emit- iterate-next ] } { \ byte-arrays: [ emit- iterate-next ] } { \ byte-arrays:(byte-array) [ emit-(byte-array) iterate-next ] } - { \ math.private: [ emit-simple-allot iterate-next ] } - { \ math.private: [ emit-simple-allot iterate-next ] } { \ kernel: [ emit-simple-allot iterate-next ] } { \ alien.accessors:alien-unsigned-1 [ 1 emit-alien-unsigned-getter iterate-next ] } { \ alien.accessors:set-alien-unsigned-1 [ 1 emit-alien-integer-setter iterate-next ] } diff --git a/basis/compiler/cfg/value-numbering/value-numbering-tests.factor b/basis/compiler/cfg/value-numbering/value-numbering-tests.factor index ac9603522e..abd2720817 100644 --- a/basis/compiler/cfg/value-numbering/value-numbering-tests.factor +++ b/basis/compiler/cfg/value-numbering/value-numbering-tests.factor @@ -92,7 +92,7 @@ sequences ; T{ ##load-reference f V int-regs 1 + } T{ ##peek f V int-regs 2 D 0 } T{ ##compare f V int-regs 4 V int-regs 2 V int-regs 1 cc> } - T{ ##compare-imm f V int-regs 6 V int-regs 4 7 cc/= } + T{ ##compare-imm f V int-regs 6 V int-regs 4 5 cc/= } T{ ##replace f V int-regs 6 D 0 } } value-numbering trim-temps ] unit-test @@ -110,7 +110,7 @@ sequences ; T{ ##load-reference f V int-regs 1 + } T{ ##peek f V int-regs 2 D 0 } T{ ##compare f V int-regs 4 V int-regs 2 V int-regs 1 cc<= } - T{ ##compare-imm f V int-regs 6 V int-regs 4 7 cc= } + T{ ##compare-imm f V int-regs 6 V int-regs 4 5 cc= } T{ ##replace f V int-regs 6 D 0 } } value-numbering trim-temps ] unit-test @@ -132,7 +132,7 @@ sequences ; T{ ##unbox-float f V double-float-regs 10 V int-regs 8 } T{ ##unbox-float f V double-float-regs 11 V int-regs 9 } T{ ##compare-float f V int-regs 12 V double-float-regs 10 V double-float-regs 11 cc< } - T{ ##compare-imm f V int-regs 14 V int-regs 12 7 cc= } + T{ ##compare-imm f V int-regs 14 V int-regs 12 5 cc= } T{ ##replace f V int-regs 14 D 0 } } value-numbering trim-temps ] unit-test @@ -149,6 +149,6 @@ sequences ; T{ ##peek f V int-regs 29 D -1 } T{ ##peek f V int-regs 30 D -2 } T{ ##compare f V int-regs 33 V int-regs 29 V int-regs 30 cc<= } - T{ ##compare-imm-branch f V int-regs 33 7 cc/= } + T{ ##compare-imm-branch f V int-regs 33 5 cc/= } } value-numbering trim-temps ] unit-test diff --git a/basis/compiler/codegen/codegen.factor b/basis/compiler/codegen/codegen.factor index 2a0456e3b7..c19707a694 100755 --- a/basis/compiler/codegen/codegen.factor +++ b/basis/compiler/codegen/codegen.factor @@ -44,7 +44,7 @@ SYMBOL: calls SYMBOL: compiling-word -: compiled-stack-traces? ( -- ? ) 59 getenv ; +: compiled-stack-traces? ( -- ? ) 67 getenv ; ! Mapping _label IDs to label instances SYMBOL: labels diff --git a/basis/compiler/codegen/fixup/fixup.factor b/basis/compiler/codegen/fixup/fixup.factor index 3a047a8d39..99f258d93c 100755 --- a/basis/compiler/codegen/fixup/fixup.factor +++ b/basis/compiler/codegen/fixup/fixup.factor @@ -3,15 +3,13 @@ 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 +system combinators math.bitwise math.order accessors growable cpu.architecture compiler.constants ; IN: compiler.codegen.fixup GENERIC: fixup* ( obj -- ) -: code-format ( -- n ) 22 getenv ; - -: compiled-offset ( -- n ) building get length code-format * ; +: compiled-offset ( -- n ) building get length ; SYMBOL: relocation-table SYMBOL: label-table @@ -25,7 +23,7 @@ TUPLE: label-fixup label class ; M: label-fixup fixup* dup class>> rc-absolute? [ "Absolute labels not supported" throw ] when - [ label>> ] [ class>> ] bi compiled-offset 4 - rot + [ class>> ] [ label>> ] bi compiled-offset 4 - swap 3array label-table get push ; TUPLE: rel-fixup class type ; @@ -58,6 +56,9 @@ SYMBOL: literal-table : rel-word ( word class -- ) [ add-literal ] dip rt-xt rel-fixup ; +: rel-word-direct ( word class -- ) + [ add-literal ] dip rt-xt-direct rel-fixup ; + : rel-primitive ( word class -- ) [ def>> first add-literal ] dip rt-primitive rel-fixup ; @@ -88,4 +89,4 @@ SYMBOL: literal-table literal-table get >array relocation-table get >byte-array label-table get resolve-labels - ] { } make 4array ; + ] B{ } make 4array ; diff --git a/basis/compiler/compiler-docs.factor b/basis/compiler/compiler-docs.factor index b96d5e573a..306ab515a8 100644 --- a/basis/compiler/compiler-docs.factor +++ b/basis/compiler/compiler-docs.factor @@ -1,19 +1,19 @@ USING: assocs compiler.cfg.builder compiler.cfg.optimizer compiler.errors compiler.tree.builder compiler.tree.optimizer compiler.units help.markup help.syntax io parser quotations -sequences words words.private ; +sequences words ; IN: compiler -HELP: enable-compiler +HELP: enable-optimizer { $description "Enables the optimizing compiler." } ; -HELP: disable-compiler +HELP: disable-optimizer { $description "Disable the optimizing compiler." } ; ARTICLE: "compiler-usage" "Calling the optimizing compiler" "Normally, new word definitions are recompiled automatically. This can be changed:" -{ $subsection disable-compiler } -{ $subsection enable-compiler } +{ $subsection disable-optimizer } +{ $subsection enable-optimizer } "Removing a word's optimized definition:" { $subsection decompile } "Compiling a single quotation:" diff --git a/basis/compiler/compiler.factor b/basis/compiler/compiler.factor index ee91d04b3d..e418f0ef60 100644 --- a/basis/compiler/compiler.factor +++ b/basis/compiler/compiler.factor @@ -2,19 +2,20 @@ ! See http://factorcode.org/license.txt for BSD license. USING: accessors kernel namespaces arrays sequences io words fry continuations vocabs assocs dlists definitions math graphs generic -combinators deques search-deques macros io source-files.errors -stack-checker stack-checker.state stack-checker.inlining -stack-checker.errors combinators.short-circuit 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 compiler.utilities ; +generic.single combinators deques search-deques macros io +source-files.errors stack-checker stack-checker.state +stack-checker.inlining stack-checker.errors combinators.short-circuit +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 +compiler.utilities ; IN: compiler SYMBOL: compile-queue SYMBOL: compiled -: queue-compile? ( word -- ? ) +: compile? ( word -- ? ) #! Don't attempt to compile certain words. { [ "forgotten" word-prop ] @@ -24,7 +25,7 @@ SYMBOL: compiled } 1|| not ; : queue-compile ( word -- ) - dup queue-compile? [ compile-queue get push-front ] [ drop ] if ; + dup compile? [ compile-queue get push-front ] [ drop ] if ; : recompile-callers? ( word -- ? ) changed-effects get key? ; @@ -41,6 +42,14 @@ SYMBOL: compiled H{ } clone generic-dependencies set clear-compiler-error ; +GENERIC: no-compile? ( word -- ? ) + +M: word no-compile? "no-compile" word-prop ; + +M: method-body no-compile? "method-generic" word-prop no-compile? ; + +M: predicate-engine-word no-compile? "owner-generic" word-prop no-compile? ; + : ignore-error? ( word error -- ? ) #! Ignore some errors on inline combinators, macros, and special #! words such as 'call'. @@ -48,8 +57,8 @@ SYMBOL: compiled { [ macro? ] [ inline? ] + [ no-compile? ] [ "special" word-prop ] - [ "no-compile" word-prop ] } 1|| ] [ { @@ -80,32 +89,46 @@ SYMBOL: compiled : not-compiled-def ( word error -- def ) '[ _ _ not-compiled ] [ ] like ; +: ignore-error ( word error -- * ) + drop + [ clear-compiler-error ] + [ dup def>> deoptimize-with ] + bi ; + +: remember-error ( word error -- * ) + [ swap compiler-error ] + [ [ drop ] [ not-compiled-def ] 2bi deoptimize-with ] + 2bi ; + : deoptimize ( word error -- * ) #! If the error is ignorable, compile the word with the #! non-optimizing compiler, using its definition. Otherwise, #! if the compiler error is not ignorable, use a dummy #! definition from 'not-compiled-def' which throws an error. - 2dup ignore-error? [ - drop - [ dup def>> deoptimize-with ] - [ clear-compiler-error ] - bi - ] [ - [ swap compiler-error ] - [ [ drop ] [ not-compiled-def ] 2bi deoptimize-with ] - 2bi - ] if ; + { + { [ dup inference-error? not ] [ rethrow ] } + { [ 2dup ignore-error? ] [ ignore-error ] } + [ remember-error ] + } cond ; + +: optimize? ( word -- ? ) + { + [ predicate-engine-word? ] + [ contains-breakpoints? ] + [ single-generic? ] + } 1|| not ; : frontend ( word -- nodes ) #! If the word contains breakpoints, don't optimize it, since #! the walker does not support this. - dup contains-breakpoints? [ dup def>> deoptimize-with ] [ - [ build-tree ] [ deoptimize ] recover optimize-tree - ] if ; + dup optimize? + [ [ build-tree ] [ deoptimize ] recover optimize-tree ] + [ dup def>> deoptimize-with ] + if ; : compile-dependency ( word -- ) #! If a word calls an unoptimized word, try to compile the callee. - dup optimized>> [ drop ] [ queue-compile ] if ; + dup optimized? [ drop ] [ queue-compile ] if ; ! Only switch this off for debugging. SYMBOL: compile-dependencies? @@ -161,15 +184,21 @@ M: optimizing-compiler recompile ( words -- alist ) [ compile-queue set H{ } clone compiled set - [ queue-compile ] each + [ + [ queue-compile ] + [ subwords [ compile-dependency ] each ] bi + ] each compile-queue get compile-loop compiled get >alist ] with-scope ; -: enable-compiler ( -- ) +: with-optimizer ( quot -- ) + [ optimizing-compiler compiler-impl ] dip with-variable ; inline + +: enable-optimizer ( -- ) optimizing-compiler compiler-impl set-global ; -: disable-compiler ( -- ) +: disable-optimizer ( -- ) f compiler-impl set-global ; : recompile-all ( -- ) diff --git a/basis/compiler/constants/constants.factor b/basis/compiler/constants/constants.factor index b3757bf008..2f0494b58a 100644 --- a/basis/compiler/constants/constants.factor +++ b/basis/compiler/constants/constants.factor @@ -1,6 +1,7 @@ -! Copyright (C) 2008 Slava Pestov. +! Copyright (C) 2008, 2009 Slava Pestov. ! See http://factorcode.org/license.txt for BSD license. -USING: math kernel layouts system strings ; +USING: math kernel layouts system strings words quotations byte-arrays +alien arrays ; IN: compiler.constants ! These constants must match vm/memory.h @@ -11,18 +12,17 @@ CONSTANT: deck-bits 18 ! These constants must match vm/layouts.h : header-offset ( -- n ) object tag-number neg ; inline : float-offset ( -- n ) 8 float tag-number - ; inline -: string-offset ( -- n ) 4 bootstrap-cells object tag-number - ; inline +: string-offset ( -- n ) 4 bootstrap-cells string tag-number - ; inline : string-aux-offset ( -- n ) 2 bootstrap-cells string tag-number - ; inline -: profile-count-offset ( -- n ) 7 bootstrap-cells object tag-number - ; inline -: byte-array-offset ( -- n ) 2 bootstrap-cells object tag-number - ; inline -: alien-offset ( -- n ) 3 bootstrap-cells object tag-number - ; inline -: underlying-alien-offset ( -- n ) bootstrap-cell object tag-number - ; inline +: profile-count-offset ( -- n ) 7 bootstrap-cells \ word tag-number - ; inline +: byte-array-offset ( -- n ) 2 bootstrap-cells byte-array tag-number - ; inline +: alien-offset ( -- n ) 3 bootstrap-cells alien tag-number - ; inline +: underlying-alien-offset ( -- n ) bootstrap-cell alien tag-number - ; inline : tuple-class-offset ( -- n ) bootstrap-cell tuple tag-number - ; inline -: class-hash-offset ( -- n ) bootstrap-cell object tag-number - ; inline -: word-xt-offset ( -- n ) 9 bootstrap-cells object tag-number - ; inline -: quot-xt-offset ( -- n ) 5 bootstrap-cells object tag-number - ; inline -: word-code-offset ( -- n ) 10 bootstrap-cells object tag-number - ; inline -: array-start-offset ( -- n ) 2 bootstrap-cells object tag-number - ; inline +: word-xt-offset ( -- n ) 9 bootstrap-cells \ word tag-number - ; inline +: quot-xt-offset ( -- n ) 5 bootstrap-cells quotation tag-number - ; inline +: word-code-offset ( -- n ) 10 bootstrap-cells \ word tag-number - ; inline +: array-start-offset ( -- n ) 2 bootstrap-cells array tag-number - ; inline : compiled-header-size ( -- n ) 5 bootstrap-cells ; inline ! Relocation classes @@ -41,10 +41,12 @@ CONSTANT: rt-primitive 0 CONSTANT: rt-dlsym 1 CONSTANT: rt-dispatch 2 CONSTANT: rt-xt 3 -CONSTANT: rt-here 4 -CONSTANT: rt-this 5 -CONSTANT: rt-immediate 6 -CONSTANT: rt-stack-chain 7 +CONSTANT: rt-xt-direct 4 +CONSTANT: rt-here 5 +CONSTANT: rt-this 6 +CONSTANT: rt-immediate 7 +CONSTANT: rt-stack-chain 8 +CONSTANT: rt-untagged 9 : rc-absolute? ( n -- ? ) [ rc-absolute-ppc-2/2 = ] diff --git a/basis/compiler/tests/call-effect.factor b/basis/compiler/tests/call-effect.factor new file mode 100644 index 0000000000..a9fd313d64 --- /dev/null +++ b/basis/compiler/tests/call-effect.factor @@ -0,0 +1,14 @@ +IN: compiler.tests.call-effect +USING: tools.test combinators generic.single sequences kernel ; + +: execute-ic-test ( a b -- c ) execute( a -- c ) ; + +! VM type check error +[ 1 f execute-ic-test ] [ second 3 = ] must-fail-with + +: call-test ( q -- ) call( -- ) ; + +[ ] [ [ ] call-test ] unit-test +[ ] [ f [ drop ] curry call-test ] unit-test +[ ] [ [ ] [ ] compose call-test ] unit-test +[ [ 1 2 3 ] call-test ] [ wrong-values? ] must-fail-with \ No newline at end of file diff --git a/basis/compiler/tests/codegen.factor b/basis/compiler/tests/codegen.factor index c746fdfb45..8fbe13ce51 100644 --- a/basis/compiler/tests/codegen.factor +++ b/basis/compiler/tests/codegen.factor @@ -26,7 +26,7 @@ IN: compiler.tests.codegen [ 2 3 4 ] [ 3 [ 2 swap 4 ] compile-call ] unit-test -[ { 1 2 3 } { 1 4 3 } 3 3 ] +[ { 1 2 3 } { 1 4 3 } 2 2 ] [ { 1 2 3 } { 1 4 3 } [ over tag over tag ] compile-call ] unit-test @@ -37,7 +37,7 @@ unit-test : foo ( -- ) ; -[ 5 5 ] +[ 3 3 ] [ 1.2 [ tag [ foo ] keep ] compile-call ] unit-test @@ -211,7 +211,7 @@ TUPLE: my-tuple ; { tuple vector } 3 slot { word } declare dup 1 slot 0 fixnum-bitand { [ ] } dispatch ; -[ t ] [ \ dispatch-alignment-regression optimized>> ] unit-test +[ t ] [ \ dispatch-alignment-regression optimized? ] unit-test [ vector ] [ dispatch-alignment-regression ] unit-test diff --git a/basis/compiler/tests/float.factor b/basis/compiler/tests/float.factor index 1a604dbd8e..7074b73845 100644 --- a/basis/compiler/tests/float.factor +++ b/basis/compiler/tests/float.factor @@ -9,7 +9,7 @@ math.private tools.test math.floats.private ; [ 3.0 1 2 3 ] [ 1.0 2.0 [ float+ 1 2 3 ] compile-call ] unit-test -[ 5 ] [ 1.0 [ 2.0 float+ tag ] compile-call ] unit-test +[ 3 ] [ 1.0 [ 2.0 float+ tag ] compile-call ] unit-test [ 3.0 ] [ 1.0 [ 2.0 float+ ] compile-call ] unit-test [ 3.0 ] [ 1.0 [ 2.0 swap float+ ] compile-call ] unit-test diff --git a/basis/compiler/tests/generic.factor b/basis/compiler/tests/generic.factor new file mode 100644 index 0000000000..6b0ef2d439 --- /dev/null +++ b/basis/compiler/tests/generic.factor @@ -0,0 +1,11 @@ +IN: compiler.tests.generic +USING: tools.test math kernel compiler.units definitions ; + +GENERIC: bad ( -- ) +M: integer bad ; +M: object bad ; + +[ 0 bad ] must-fail +[ "" bad ] must-fail + +[ ] [ [ \ bad forget ] with-compilation-unit ] unit-test \ No newline at end of file diff --git a/basis/compiler/tests/intrinsics.factor b/basis/compiler/tests/intrinsics.factor index a6e827ea33..5ca0f3f109 100644 --- a/basis/compiler/tests/intrinsics.factor +++ b/basis/compiler/tests/intrinsics.factor @@ -342,12 +342,12 @@ cell 8 = [ ] unit-test [ 1 2 ] [ - 1 2 [ ] compile-call + 1 2 [ complex boa ] compile-call dup real-part swap imaginary-part ] unit-test [ 1 2 ] [ - 1 2 [ ] compile-call dup numerator swap denominator + 1 2 [ ratio boa ] compile-call dup numerator swap denominator ] unit-test [ \ + ] [ \ + [ ] compile-call ] unit-test diff --git a/basis/compiler/tests/optimizer.factor b/basis/compiler/tests/optimizer.factor index bd7008f909..f19a950711 100644 --- a/basis/compiler/tests/optimizer.factor +++ b/basis/compiler/tests/optimizer.factor @@ -4,13 +4,13 @@ sbufs strings tools.test vectors words sequences.private quotations classes classes.algebra classes.tuple.private continuations growable namespaces hints alien.accessors compiler.tree.builder compiler.tree.optimizer sequences.deep -compiler ; +compiler definitions ; IN: compiler.tests.optimizer GENERIC: xyz ( obj -- obj ) M: array xyz xyz ; -[ t ] [ \ xyz optimized>> ] unit-test +[ t ] [ M\ array xyz optimized? ] unit-test ! Test predicate inlining : pred-test-1 ( a -- b c ) @@ -95,7 +95,7 @@ TUPLE: pred-test ; ! regression GENERIC: void-generic ( obj -- * ) : breakage ( -- * ) "hi" void-generic ; -[ t ] [ \ breakage optimized>> ] unit-test +[ t ] [ \ breakage optimized? ] unit-test [ breakage ] must-fail ! regression @@ -120,7 +120,7 @@ GENERIC: void-generic ( obj -- * ) ! compiling with a non-literal class failed : -regression ( class -- tuple ) ; -[ t ] [ \ -regression optimized>> ] unit-test +[ t ] [ \ -regression optimized? ] unit-test GENERIC: foozul ( a -- b ) M: reversed foozul ; @@ -229,7 +229,7 @@ USE: binary-search.private : node-successor-f-bug ( x -- * ) [ 3 throw ] [ empty-compound ] compose [ 3 throw ] if ; -[ t ] [ \ node-successor-f-bug optimized>> ] unit-test +[ t ] [ \ node-successor-f-bug optimized? ] unit-test [ ] [ [ new ] build-tree optimize-tree drop ] unit-test @@ -243,7 +243,7 @@ USE: binary-search.private ] if ] if ; -[ t ] [ \ lift-throw-tail-regression optimized>> ] unit-test +[ t ] [ \ lift-throw-tail-regression optimized? ] unit-test [ 3 "an integer" ] [ 3 lift-throw-tail-regression ] unit-test [ "hi" "a string" ] [ "hi" lift-throw-tail-regression ] unit-test @@ -274,7 +274,7 @@ HINTS: recursive-inline-hang array ; : recursive-inline-hang-1 ( -- a ) { } recursive-inline-hang ; -[ t ] [ \ recursive-inline-hang-1 optimized>> ] unit-test +[ t ] [ \ recursive-inline-hang-1 optimized? ] unit-test DEFER: recursive-inline-hang-3 @@ -325,7 +325,7 @@ PREDICATE: list < improper-list dup "a" get { array-capacity } declare >= [ dup "b" get { array-capacity } declare >= [ 3 ] [ 4 ] if ] [ 5 ] if ; -[ t ] [ \ interval-inference-bug optimized>> ] unit-test +[ t ] [ \ interval-inference-bug optimized? ] unit-test [ ] [ 1 "a" set 2 "b" set ] unit-test [ 2 3 ] [ 2 interval-inference-bug ] unit-test @@ -384,3 +384,9 @@ DEFER: loop-bbb 1 >bignum 2 >bignum [ { bignum integer } declare [ shift ] keep 1+ ] compile-call ] unit-test + +: broken-declaration ( -- ) \ + declare ; + +[ f ] [ \ broken-declaration optimized? ] unit-test + +[ ] [ [ \ broken-declaration forget ] with-compilation-unit ] unit-test \ No newline at end of file diff --git a/basis/compiler/tests/peg-regression.factor b/basis/compiler/tests/peg-regression.factor index e107135305..95d454fed1 100644 --- a/basis/compiler/tests/peg-regression.factor +++ b/basis/compiler/tests/peg-regression.factor @@ -4,7 +4,7 @@ ! optimization, which would batch generic word updates at the ! end of a compilation unit. -USING: kernel accessors peg.ebnf ; +USING: kernel accessors peg.ebnf words ; IN: compiler.tests.peg-regression TUPLE: pipeline-expr background ; @@ -22,5 +22,5 @@ pipeline = "hello" => [[ ast>pipeline-expr ]] USE: tools.test -[ t ] [ \ expr optimized>> ] unit-test -[ t ] [ \ ast>pipeline-expr optimized>> ] unit-test +[ t ] [ \ expr optimized? ] unit-test +[ t ] [ \ ast>pipeline-expr optimized? ] unit-test diff --git a/basis/compiler/tests/pic-problem-1.factor b/basis/compiler/tests/pic-problem-1.factor new file mode 100644 index 0000000000..4adf0b36b9 --- /dev/null +++ b/basis/compiler/tests/pic-problem-1.factor @@ -0,0 +1,14 @@ +IN: compiler.tests.pic-problem-1 +USING: kernel sequences prettyprint memory tools.test ; + +TUPLE: x ; + +M: x length drop 0 ; + +INSTANCE: x sequence + +<< gc >> + +CONSTANT: blah T{ x } + +[ T{ x } ] [ blah ] unit-test \ No newline at end of file diff --git a/basis/compiler/tests/redefine14.factor b/basis/compiler/tests/redefine14.factor index 807f3ed2c7..a72db4833c 100644 --- a/basis/compiler/tests/redefine14.factor +++ b/basis/compiler/tests/redefine14.factor @@ -1,8 +1,8 @@ USING: compiler.units definitions tools.test sequences ; IN: compiler.tests.redefine14 -! TUPLE: bad ; -! -! M: bad length 1 2 3 ; -! -! [ ] [ [ { bad length } forget ] with-compilation-unit ] unit-test +TUPLE: bad ; + +M: bad length 1 2 3 ; + +[ ] [ [ M\ bad length forget ] with-compilation-unit ] unit-test diff --git a/basis/compiler/tests/redefine17.factor b/basis/compiler/tests/redefine17.factor new file mode 100644 index 0000000000..4ed3e36f4d --- /dev/null +++ b/basis/compiler/tests/redefine17.factor @@ -0,0 +1,49 @@ +IN: compiler.tests.redefine17 +USING: tools.test classes.mixin compiler.units arrays kernel.private +strings sequences vocabs definitions kernel ; + +<< "compiler.tests.redefine17" words forget-all >> + +GENERIC: bong ( a -- b ) + +M: array bong ; + +M: string bong length ; + +MIXIN: mixin + +INSTANCE: array mixin + +: blah ( a -- b ) { mixin } declare bong ; + +[ { } ] [ { } blah ] unit-test + +[ ] [ [ \ array \ mixin remove-mixin-instance ] with-compilation-unit ] unit-test + +[ ] [ [ \ string \ mixin add-mixin-instance ] with-compilation-unit ] unit-test + +[ 0 ] [ "" blah ] unit-test + +MIXIN: mixin1 + +INSTANCE: string mixin1 + +MIXIN: mixin2 + +GENERIC: billy ( a -- b ) + +M: mixin2 billy ; + +M: array billy drop "BILLY" ; + +INSTANCE: string mixin2 + +: bully ( a -- b ) { mixin1 } declare billy ; + +[ "" ] [ "" bully ] unit-test + +[ ] [ [ \ string \ mixin1 remove-mixin-instance ] with-compilation-unit ] unit-test + +[ ] [ [ \ array \ mixin1 add-mixin-instance ] with-compilation-unit ] unit-test + +[ "BILLY" ] [ { } bully ] unit-test diff --git a/basis/compiler/tests/redefine3.factor b/basis/compiler/tests/redefine3.factor index 51ce33c1bd..0a5eb84579 100644 --- a/basis/compiler/tests/redefine3.factor +++ b/basis/compiler/tests/redefine3.factor @@ -14,7 +14,7 @@ M: empty-mixin sheeple drop "wake up" ; : sheeple-test ( -- string ) { } sheeple ; [ "sheeple" ] [ sheeple-test ] unit-test -[ t ] [ \ sheeple-test optimized>> ] unit-test +[ t ] [ \ sheeple-test optimized? ] unit-test [ t ] [ object \ sheeple method \ sheeple-test "compiled-uses" word-prop key? ] unit-test [ f ] [ empty-mixin \ sheeple method \ sheeple-test "compiled-uses" word-prop key? ] unit-test @@ -27,6 +27,6 @@ M: empty-mixin sheeple drop "wake up" ; [ ] [ [ array empty-mixin remove-mixin-instance ] with-compilation-unit ] unit-test [ "sheeple" ] [ sheeple-test ] unit-test -[ t ] [ \ sheeple-test optimized>> ] unit-test +[ t ] [ \ sheeple-test optimized? ] unit-test [ t ] [ object \ sheeple method \ sheeple-test "compiled-uses" word-prop key? ] unit-test [ f ] [ empty-mixin \ sheeple method \ sheeple-test "compiled-uses" word-prop key? ] unit-test diff --git a/basis/compiler/tests/simple.factor b/basis/compiler/tests/simple.factor index 82cc97e0f6..88dc9a53b1 100644 --- a/basis/compiler/tests/simple.factor +++ b/basis/compiler/tests/simple.factor @@ -235,6 +235,6 @@ M: f single-combination-test-2 single-combination-test-4 ; 10 [ [ "compiler.tests.foo" forget-vocab ] with-compilation-unit [ t ] [ - "USING: prettyprint words accessors ; IN: compiler.tests.foo : (recursive) ( -- ) (recursive) (recursive) ; inline recursive : recursive ( -- ) (recursive) ; \\ (recursive) optimized>>" eval( -- obj ) + "USING: prettyprint words accessors ; IN: compiler.tests.foo : (recursive) ( -- ) (recursive) (recursive) ; inline recursive : recursive ( -- ) (recursive) ; \\ (recursive) optimized?" eval( -- obj ) ] unit-test ] times diff --git a/basis/compiler/tests/spilling.factor b/basis/compiler/tests/spilling.factor index 2ec6fbde95..e518ff8df2 100644 --- a/basis/compiler/tests/spilling.factor +++ b/basis/compiler/tests/spilling.factor @@ -1,5 +1,5 @@ USING: math.private kernel combinators accessors arrays -generalizations tools.test ; +generalizations tools.test words ; IN: compiler.tests.spilling : float-spill-bug ( a -- b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b ) @@ -47,7 +47,7 @@ IN: compiler.tests.spilling [ 2.0 2.0 2.0 2.0 2.0 2.0 2.0 2.0 2.0 2.0 2.0 2.0 2.0 2.0 2.0 2.0 2.0 2.0 2.0 2.0 2.0 2.0 2.0 2.0 2.0 2.0 2.0 2.0 2.0 2.0 2.0 2.0 2.0 2.0 2.0 2.0 2.0 2.0 ] [ 1.0 float-spill-bug ] unit-test -[ t ] [ \ float-spill-bug optimized>> ] unit-test +[ t ] [ \ float-spill-bug optimized? ] unit-test : float-fixnum-spill-bug ( object -- object object object object object object object object object object object object object object object object object object object object object object object object object object object object object object object object object object object object object object object object object object object object object object object object object object object object object object object object object object object object object object object object object object object object object object object object object object object object ) { @@ -132,7 +132,7 @@ IN: compiler.tests.spilling [ 2.0 2 2.0 2 2.0 2 2.0 2 2.0 2 2.0 2 2.0 2 2.0 2 2.0 2 2.0 2 2.0 2 2.0 2 2.0 2 2.0 2 2.0 2 2.0 2 2.0 2 2.0 2 2.0 2 2.0 2 2.0 2 2.0 2 2.0 2 2.0 2 2.0 2 2.0 2 2.0 2 2.0 2 2.0 2 2.0 2 2.0 2 2.0 2 2.0 2 2.0 2 2.0 2 2.0 2 2.0 2 2.0 2 ] [ 1.0 float-fixnum-spill-bug ] unit-test -[ t ] [ \ float-fixnum-spill-bug optimized>> ] unit-test +[ t ] [ \ float-fixnum-spill-bug optimized? ] unit-test : resolve-spill-bug ( a b -- c ) [ 1 fixnum+fast ] bi@ dup 10 fixnum< [ @@ -159,7 +159,7 @@ IN: compiler.tests.spilling 16 narray ] if ; -[ t ] [ \ resolve-spill-bug optimized>> ] unit-test +[ t ] [ \ resolve-spill-bug optimized? ] unit-test [ 4 ] [ 1 1 resolve-spill-bug ] unit-test diff --git a/basis/compiler/tree/debugger/debugger.factor b/basis/compiler/tree/debugger/debugger.factor index b1dc04082e..60cab92843 100644 --- a/basis/compiler/tree/debugger/debugger.factor +++ b/basis/compiler/tree/debugger/debugger.factor @@ -153,7 +153,7 @@ SYMBOL: node-count [ 1+ ] dip dup #call? [ word>> { - { [ dup "intrinsics" word-prop over "if-intrinsics" word-prop or ] [ intrinsics-called ] } + { [ dup "intrinsic" word-prop ] [ intrinsics-called ] } { [ dup generic? ] [ generics-called ] } { [ dup method-body? ] [ methods-called ] } [ words-called ] diff --git a/basis/compiler/tree/escape-analysis/check/check.factor b/basis/compiler/tree/escape-analysis/check/check.factor index 333b3fa636..ed253ad89b 100644 --- a/basis/compiler/tree/escape-analysis/check/check.factor +++ b/basis/compiler/tree/escape-analysis/check/check.factor @@ -12,7 +12,6 @@ M: #push run-escape-analysis* M: #call run-escape-analysis* { - { [ dup word>> \ eq? ] [ t ] } { [ dup immutable-tuple-boa? ] [ t ] } [ f ] } cond nip ; diff --git a/basis/compiler/tree/escape-analysis/escape-analysis-tests.factor b/basis/compiler/tree/escape-analysis/escape-analysis-tests.factor index bcb8b2f80a..5f89372ebe 100644 --- a/basis/compiler/tree/escape-analysis/escape-analysis-tests.factor +++ b/basis/compiler/tree/escape-analysis/escape-analysis-tests.factor @@ -17,7 +17,7 @@ GENERIC: count-unboxed-allocations* ( m node -- n ) out-d>> first escaping-allocation? [ 1+ ] unless ; M: #call count-unboxed-allocations* - dup [ immutable-tuple-boa? ] [ word>> \ eq? ] bi or + dup immutable-tuple-boa? [ (count-unboxed-allocations) ] [ drop ] if ; M: #push count-unboxed-allocations* @@ -291,7 +291,7 @@ C: ro-box [ 0 ] [ [ bad-tuple-fib-3 i>> ] count-unboxed-allocations ] unit-test -[ 1 ] [ [ >rect ] count-unboxed-allocations ] unit-test +[ 1 ] [ [ complex boa >rect ] count-unboxed-allocations ] unit-test [ 0 ] [ [ 1 cons boa 2 cons boa ] count-unboxed-allocations ] unit-test diff --git a/basis/compiler/tree/escape-analysis/simple/simple.factor b/basis/compiler/tree/escape-analysis/simple/simple.factor index fe1e60dbc2..729d6a0490 100644 --- a/basis/compiler/tree/escape-analysis/simple/simple.factor +++ b/basis/compiler/tree/escape-analysis/simple/simple.factor @@ -47,9 +47,6 @@ M: #push escape-analysis* [ record-unknown-allocation ] if ; -: record-complex-allocation ( #call -- ) - [ in-d>> ] [ out-d>> first ] bi record-allocation ; - : slot-offset ( #call -- n/f ) dup in-d>> [ first node-value-info class>> ] @@ -71,7 +68,6 @@ M: #push escape-analysis* M: #call escape-analysis* dup word>> { { \ [ record-tuple-allocation ] } - { \ [ record-complex-allocation ] } { \ slot [ record-slot-call ] } [ drop record-unknown-allocation ] } case ; diff --git a/basis/compiler/tree/propagation/info/info.factor b/basis/compiler/tree/propagation/info/info.factor index a22b7aa172..4d4b22218d 100644 --- a/basis/compiler/tree/propagation/info/info.factor +++ b/basis/compiler/tree/propagation/info/info.factor @@ -59,29 +59,18 @@ CONSTANT: object-info T{ value-info f object full-interval } : ( -- info ) \ value-info new ; -: read-only-slots ( values class -- slots ) - all-slots - [ read-only>> [ drop f ] unless ] 2map - f prefix ; - DEFER: +: tuple-slot-infos ( tuple -- slots ) + [ tuple-slots ] [ class all-slots ] bi + [ read-only>> [ ] [ drop f ] if ] 2map + f prefix ; + : init-literal-info ( info -- info ) dup literal>> class >>class dup literal>> dup real? [ [a,a] >>interval ] [ [ [-inf,inf] >>interval ] dip - { - { [ dup complex? ] [ - [ real-part ] - [ imaginary-part ] bi - 2array >>slots - ] } - { [ dup tuple? ] [ - [ tuple-slots [ ] map ] [ class ] bi - read-only-slots >>slots - ] } - [ drop ] - } cond + dup tuple? [ tuple-slot-infos >>slots ] [ drop ] if ] if ; inline : init-value-info ( info -- info ) diff --git a/basis/compiler/tree/propagation/inlining/inlining.factor b/basis/compiler/tree/propagation/inlining/inlining.factor index aa66b2f6d7..2a7d431314 100755 --- a/basis/compiler/tree/propagation/inlining/inlining.factor +++ b/basis/compiler/tree/propagation/inlining/inlining.factor @@ -1,7 +1,7 @@ ! Copyright (C) 2008, 2009 Slava Pestov. ! See http://factorcode.org/license.txt for BSD license. USING: accessors kernel arrays sequences math math.order -math.partial-dispatch generic generic.standard generic.math +math.partial-dispatch generic generic.standard generic.single generic.math classes.algebra classes.union sets quotations assocs combinators words namespaces continuations classes fry combinators.smart hints locals @@ -188,9 +188,7 @@ SYMBOL: history { curry compose } memq? ; : never-inline-word? ( word -- ? ) - [ deferred? ] - [ "default" word-prop ] - [ { call execute } memq? ] tri or or ; + [ deferred? ] [ "default" word-prop ] [ \ call eq? ] tri or or ; : custom-inlining? ( word -- ? ) "custom-inlining" word-prop ; diff --git a/basis/compiler/tree/propagation/propagation-tests.factor b/basis/compiler/tree/propagation/propagation-tests.factor index f6308ac40a..eba41dbfdf 100644 --- a/basis/compiler/tree/propagation/propagation-tests.factor +++ b/basis/compiler/tree/propagation/propagation-tests.factor @@ -9,7 +9,7 @@ compiler.tree.propagation.info compiler.tree.def-use compiler.tree.debugger compiler.tree.checker slots.private words hashtables classes assocs locals specialized-arrays.double system sorting math.libm -math.intervals ; +math.intervals quotations ; IN: compiler.tree.propagation.tests [ V{ } ] [ [ ] final-classes ] unit-test @@ -357,7 +357,7 @@ TUPLE: immutable-prop-test-tuple { x sequence read-only } ; ] unit-test [ V{ complex } ] [ - [ ] final-classes + [ complex boa ] final-classes ] unit-test [ V{ complex } ] [ @@ -375,7 +375,7 @@ TUPLE: immutable-prop-test-tuple { x sequence read-only } ; [ V{ complex } ] [ [ { float float object } declare - [ "Oops" throw ] [ ] if + [ "Oops" throw ] [ complex boa ] if ] final-classes ] unit-test @@ -590,7 +590,7 @@ MIXIN: empty-mixin [ V{ float } ] [ [ - [ { float float } declare ] + [ { float float } declare complex boa ] [ 2drop C{ 0.0 0.0 } ] if real-part ] final-classes @@ -686,3 +686,8 @@ TUPLE: littledan-2 { from read-only } { to read-only } ; [ V{ 0 } ] [ [ { } length ] final-literals ] unit-test [ V{ 1 } ] [ [ { } length 1+ f length ] final-literals ] unit-test + +! Mutable tuples with circularity should not cause problems +TUPLE: circle me ; + +[ ] [ circle new dup >>me 1quotation final-info drop ] unit-test \ No newline at end of file diff --git a/basis/compiler/tree/propagation/simple/simple.factor b/basis/compiler/tree/propagation/simple/simple.factor index 9937c6b9c4..5837d59ef9 100644 --- a/basis/compiler/tree/propagation/simple/simple.factor +++ b/basis/compiler/tree/propagation/simple/simple.factor @@ -109,7 +109,7 @@ M: #declare propagate-before : output-value-infos ( #call word -- infos ) { - { [ dup tuple-constructor? ] [ propagate-tuple-constructor ] } + { [ dup \ eq? ] [ drop propagate- ] } { [ dup sequence-constructor? ] [ propagate-sequence-constructor ] } { [ dup predicate? ] [ propagate-predicate ] } { [ dup "outputs" word-prop ] [ call-outputs-quot ] } diff --git a/basis/compiler/tree/propagation/slots/slots.factor b/basis/compiler/tree/propagation/slots/slots.factor index 8192b1c520..86114772f7 100644 --- a/basis/compiler/tree/propagation/slots/slots.factor +++ b/basis/compiler/tree/propagation/slots/slots.factor @@ -1,4 +1,4 @@ -! Copyright (C) 2008 Slava Pestov. +! Copyright (C) 2008, 2009 Slava Pestov. ! See http://factorcode.org/license.txt for BSD license. USING: fry assocs arrays byte-arrays strings accessors sequences kernel slots classes.algebra classes.tuple classes.tuple.private @@ -8,9 +8,6 @@ IN: compiler.tree.propagation.slots ! Propagation of immutable slots and array lengths -! Revisit this code when delegation is removed and when complex -! numbers become tuples. - UNION: fixed-length-sequence array byte-array string ; : sequence-constructor? ( word -- ? ) @@ -29,33 +26,26 @@ UNION: fixed-length-sequence array byte-array string ; [ constructor-output-class ] bi* value-info-intersect 1array ; -: tuple-constructor? ( word -- ? ) - { } memq? ; - : fold- ( values class -- info ) [ [ literal>> ] map ] dip prefix >tuple ; +: read-only-slots ( values class -- slots ) + all-slots + [ read-only>> [ value-info ] [ drop f ] if ] 2map + f prefix ; + : (propagate-tuple-constructor) ( values class -- info ) - [ [ value-info ] map ] dip [ read-only-slots ] keep + [ read-only-slots ] keep over rest-slice [ dup [ literal?>> ] when ] all? [ [ rest-slice ] dip fold- ] [ ] if ; -: propagate- ( #call -- info ) +: propagate- ( #call -- infos ) in-d>> unclip-last - value-info literal>> first (propagate-tuple-constructor) ; - -: propagate- ( #call -- info ) - in-d>> [ value-info ] map complex ; - -: propagate-tuple-constructor ( #call word -- infos ) - { - { \ [ propagate- ] } - { \ [ propagate- ] } - } case 1array ; + value-info literal>> first (propagate-tuple-constructor) 1array ; : read-only-slot? ( n class -- ? ) all-slots [ offset>> = ] with find nip diff --git a/basis/compiler/tree/tuple-unboxing/tuple-unboxing-tests.factor b/basis/compiler/tree/tuple-unboxing/tuple-unboxing-tests.factor index 8654a6f983..70670648b1 100644 --- a/basis/compiler/tree/tuple-unboxing/tuple-unboxing-tests.factor +++ b/basis/compiler/tree/tuple-unboxing/tuple-unboxing-tests.factor @@ -32,7 +32,6 @@ TUPLE: empty-tuple ; [ dup [ drop f ] [ "A" throw ] if ] [ [ ] [ ] curry curry dup 2 slot swap 3 slot dup 2 slot swap 3 slot drop ] [ [ ] [ ] curry curry call ] - [ dup 1 slot drop 2 slot drop ] [ 1 cons boa over [ "A" throw ] when car>> ] [ [ <=> ] sort ] [ [ <=> ] with search ] diff --git a/basis/compiler/tree/tuple-unboxing/tuple-unboxing.factor b/basis/compiler/tree/tuple-unboxing/tuple-unboxing.factor index 1e00efa835..107ea59902 100755 --- a/basis/compiler/tree/tuple-unboxing/tuple-unboxing.factor +++ b/basis/compiler/tree/tuple-unboxing/tuple-unboxing.factor @@ -36,9 +36,6 @@ M: #push unbox-tuples* ( #push -- nodes ) : unbox- ( #call -- nodes ) dup unbox-output? [ in-d>> 1 tail* #drop ] when ; -: unbox- ( #call -- nodes ) - dup unbox-output? [ drop { } ] when ; - : (flatten-values) ( values accum -- ) dup '[ dup unboxed-allocation @@ -70,7 +67,6 @@ M: #push unbox-tuples* ( #push -- nodes ) M: #call unbox-tuples* dup word>> { { \ [ unbox- ] } - { \ [ unbox- ] } { \ slot [ unbox-slot-access ] } [ drop ] } case ; diff --git a/basis/core-foundation/fsevents/fsevents.factor b/basis/core-foundation/fsevents/fsevents.factor index 46f6639ab8..1956cd9c20 100644 --- a/basis/core-foundation/fsevents/fsevents.factor +++ b/basis/core-foundation/fsevents/fsevents.factor @@ -151,8 +151,8 @@ SYMBOL: event-stream-callbacks \ event-stream-counter counter ; [ - event-stream-callbacks global - [ [ drop expired? not ] assoc-filter H{ } assoc-like ] change-at + event-stream-callbacks + [ [ drop expired? not ] assoc-filter H{ } assoc-like ] change-global ] "core-foundation" add-init-hook : add-event-source-callback ( quot -- id ) diff --git a/basis/cpu/ppc/bootstrap.factor b/basis/cpu/ppc/bootstrap.factor index 1431d471c1..7278fd2092 100644 --- a/basis/cpu/ppc/bootstrap.factor +++ b/basis/cpu/ppc/bootstrap.factor @@ -2,15 +2,13 @@ ! See http://factorcode.org/license.txt for BSD license. USING: bootstrap.image.private kernel kernel.private namespaces system cpu.ppc.assembler compiler.codegen.fixup compiler.units -compiler.constants math math.private layouts words words.private +compiler.constants math math.private layouts words vocabs slots.private locals.backend ; IN: bootstrap.ppc 4 \ cell set big-endian on -4 jit-code-format set - CONSTANT: ds-reg 29 CONSTANT: rs-reg 30 @@ -23,7 +21,7 @@ CONSTANT: rs-reg 30 : xt-save ( -- n ) stack-frame 2 bootstrap-cells - ; [ - 0 6 LOAD32 + 0 6 LOAD32 rc-absolute-ppc-2/2 rt-immediate jit-rel 11 6 profile-count-offset LWZ 11 11 1 tag-fixnum ADDI 11 6 profile-count-offset STW @@ -31,65 +29,50 @@ CONSTANT: rs-reg 30 11 11 compiled-header-size ADDI 11 MTCTR BCTR -] rc-absolute-ppc-2/2 rt-immediate 1 jit-profiling jit-define +] jit-profiling jit-define [ - 0 6 LOAD32 + 0 6 LOAD32 rc-absolute-ppc-2/2 rt-this jit-rel 0 MFLR 1 1 stack-frame SUBI 6 1 xt-save STW stack-frame 6 LI 6 1 next-save STW 0 1 lr-save stack-frame + STW -] rc-absolute-ppc-2/2 rt-this 1 jit-prolog jit-define +] jit-prolog jit-define [ - 0 6 LOAD32 + 0 6 LOAD32 rc-absolute-ppc-2/2 rt-immediate jit-rel 6 ds-reg 4 STWU -] rc-absolute-ppc-2/2 rt-immediate 1 jit-push-immediate jit-define +] jit-push-immediate jit-define [ - 0 6 LOAD32 + 0 6 LOAD32 rc-absolute-ppc-2/2 rt-stack-chain jit-rel 7 6 0 LWZ 1 7 0 STW -] rc-absolute-ppc-2/2 rt-stack-chain 1 jit-save-stack jit-define +] jit-save-stack jit-define [ - 0 6 LOAD32 + 0 6 LOAD32 rc-absolute-ppc-2/2 rt-primitive jit-rel 6 MTCTR BCTR -] rc-absolute-ppc-2/2 rt-primitive 1 jit-primitive jit-define +] jit-primitive jit-define -[ 0 BL ] rc-relative-ppc-3 rt-xt 0 jit-word-call jit-define +[ 0 BL rc-relative-ppc-3 rt-xt-direct jit-rel ] jit-word-call jit-define -[ 0 B ] rc-relative-ppc-3 rt-xt 0 jit-word-jump jit-define +[ 0 B rc-relative-ppc-3 rt-xt jit-rel ] jit-word-jump jit-define [ 3 ds-reg 0 LWZ ds-reg dup 4 SUBI 0 3 \ f tag-number CMPI 2 BEQ - 0 B -] rc-relative-ppc-3 rt-xt 4 jit-if-1 jit-define + 0 B rc-relative-ppc-3 rt-xt jit-rel +] jit-if-1 jit-define [ - 0 B -] rc-relative-ppc-3 rt-xt 0 jit-if-2 jit-define - -: jit-jump-quot ( -- ) - 4 3 quot-xt-offset LWZ - 4 MTCTR - BCTR ; - -[ - 0 3 LOAD32 - 6 ds-reg 0 LWZ - 6 6 1 SRAWI - 3 3 6 ADD - 3 3 array-start-offset LWZ - ds-reg dup 4 SUBI - jit-jump-quot -] rc-absolute-ppc-2/2 rt-immediate 1 jit-dispatch jit-define + 0 B rc-relative-ppc-3 rt-xt jit-rel +] jit-if-2 jit-define : jit->r ( -- ) 4 ds-reg 0 LWZ @@ -139,29 +122,29 @@ CONSTANT: rs-reg 30 [ jit->r - 0 BL + 0 BL rc-relative-ppc-3 rt-xt jit-rel jit-r> -] rc-relative-ppc-3 rt-xt 3 jit-dip jit-define +] jit-dip jit-define [ jit-2>r - 0 BL + 0 BL rc-relative-ppc-3 rt-xt jit-rel jit-2r> -] rc-relative-ppc-3 rt-xt 6 jit-2dip jit-define +] jit-2dip jit-define [ jit-3>r - 0 BL + 0 BL rc-relative-ppc-3 rt-xt jit-rel jit-3r> -] rc-relative-ppc-3 rt-xt 8 jit-3dip jit-define +] jit-3dip jit-define [ 0 1 lr-save stack-frame + LWZ 1 1 stack-frame ADDI 0 MTLR -] f f f jit-epilog jit-define +] jit-epilog jit-define -[ BLR ] f f f jit-return jit-define +[ BLR ] jit-return jit-define ! Sub-primitives @@ -169,8 +152,10 @@ CONSTANT: rs-reg 30 [ 3 ds-reg 0 LWZ ds-reg dup 4 SUBI - jit-jump-quot -] f f f \ (call) define-sub-primitive + 4 3 quot-xt-offset LWZ + 4 MTCTR + BCTR +] \ (call) define-sub-primitive [ 3 ds-reg 0 LWZ @@ -178,7 +163,7 @@ CONSTANT: rs-reg 30 4 3 word-xt-offset LWZ 4 MTCTR BCTR -] f f f \ (execute) define-sub-primitive +] \ (execute) define-sub-primitive ! Objects [ @@ -186,7 +171,7 @@ CONSTANT: rs-reg 30 3 3 tag-mask get ANDI 3 3 tag-bits get SLWI 3 ds-reg 0 STW -] f f f \ tag define-sub-primitive +] \ tag define-sub-primitive [ 3 ds-reg 0 LWZ @@ -195,25 +180,25 @@ CONSTANT: rs-reg 30 4 4 0 0 31 tag-bits get - RLWINM 4 3 3 LWZX 3 ds-reg 0 STW -] f f f \ slot define-sub-primitive +] \ slot define-sub-primitive ! Shufflers [ ds-reg dup 4 SUBI -] f f f \ drop define-sub-primitive +] \ drop define-sub-primitive [ ds-reg dup 8 SUBI -] f f f \ 2drop define-sub-primitive +] \ 2drop define-sub-primitive [ ds-reg dup 12 SUBI -] f f f \ 3drop define-sub-primitive +] \ 3drop define-sub-primitive [ 3 ds-reg 0 LWZ 3 ds-reg 4 STWU -] f f f \ dup define-sub-primitive +] \ dup define-sub-primitive [ 3 ds-reg 0 LWZ @@ -221,7 +206,7 @@ CONSTANT: rs-reg 30 ds-reg dup 8 ADDI 3 ds-reg 0 STW 4 ds-reg -4 STW -] f f f \ 2dup define-sub-primitive +] \ 2dup define-sub-primitive [ 3 ds-reg 0 LWZ @@ -231,36 +216,36 @@ CONSTANT: rs-reg 30 3 ds-reg 0 STW 4 ds-reg -4 STW 5 ds-reg -8 STW -] f f f \ 3dup define-sub-primitive +] \ 3dup define-sub-primitive [ 3 ds-reg 0 LWZ ds-reg dup 4 SUBI 3 ds-reg 0 STW -] f f f \ nip define-sub-primitive +] \ nip define-sub-primitive [ 3 ds-reg 0 LWZ ds-reg dup 8 SUBI 3 ds-reg 0 STW -] f f f \ 2nip define-sub-primitive +] \ 2nip define-sub-primitive [ 3 ds-reg -4 LWZ 3 ds-reg 4 STWU -] f f f \ over define-sub-primitive +] \ over define-sub-primitive [ 3 ds-reg -8 LWZ 3 ds-reg 4 STWU -] f f f \ pick define-sub-primitive +] \ pick define-sub-primitive [ 3 ds-reg 0 LWZ 4 ds-reg -4 LWZ 4 ds-reg 0 STW 3 ds-reg 4 STWU -] f f f \ dupd define-sub-primitive +] \ dupd define-sub-primitive [ 3 ds-reg 0 LWZ @@ -268,21 +253,21 @@ CONSTANT: rs-reg 30 3 ds-reg 4 STWU 4 ds-reg -4 STW 3 ds-reg -8 STW -] f f f \ tuck define-sub-primitive +] \ tuck define-sub-primitive [ 3 ds-reg 0 LWZ 4 ds-reg -4 LWZ 3 ds-reg -4 STW 4 ds-reg 0 STW -] f f f \ swap define-sub-primitive +] \ swap define-sub-primitive [ 3 ds-reg -4 LWZ 4 ds-reg -8 LWZ 3 ds-reg -8 STW 4 ds-reg -4 STW -] f f f \ swapd define-sub-primitive +] \ swapd define-sub-primitive [ 3 ds-reg 0 LWZ @@ -291,7 +276,7 @@ CONSTANT: rs-reg 30 4 ds-reg -8 STW 3 ds-reg -4 STW 5 ds-reg 0 STW -] f f f \ rot define-sub-primitive +] \ rot define-sub-primitive [ 3 ds-reg 0 LWZ @@ -300,13 +285,13 @@ CONSTANT: rs-reg 30 3 ds-reg -8 STW 5 ds-reg -4 STW 4 ds-reg 0 STW -] f f f \ -rot define-sub-primitive +] \ -rot define-sub-primitive -[ jit->r ] f f f \ load-local define-sub-primitive +[ jit->r ] \ load-local define-sub-primitive ! Comparisons : jit-compare ( insn -- ) - 0 3 LOAD32 + 0 3 LOAD32 rc-absolute-ppc-2/2 rt-immediate jit-rel 4 ds-reg 0 LWZ 5 ds-reg -4 LWZU 5 0 4 CMP @@ -315,8 +300,7 @@ CONSTANT: rs-reg 30 3 ds-reg 0 STW ; : define-jit-compare ( insn word -- ) - [ [ jit-compare ] curry rc-absolute-ppc-2/2 rt-immediate 1 ] dip - define-sub-primitive ; + [ [ jit-compare ] curry ] dip define-sub-primitive ; \ BEQ \ eq? define-jit-compare \ BGE \ fixnum>= define-jit-compare @@ -336,7 +320,7 @@ CONSTANT: rs-reg 30 2 BNE 1 tag-fixnum 4 LI 4 ds-reg 0 STW -] f f f \ both-fixnums? define-sub-primitive +] \ both-fixnums? define-sub-primitive : jit-math ( insn -- ) 3 ds-reg 0 LWZ @@ -344,9 +328,9 @@ CONSTANT: rs-reg 30 [ 5 3 4 ] dip execute( dst src1 src2 -- ) 5 ds-reg 0 STW ; -[ \ ADD jit-math ] f f f \ fixnum+fast define-sub-primitive +[ \ ADD jit-math ] \ fixnum+fast define-sub-primitive -[ \ SUBF jit-math ] f f f \ fixnum-fast define-sub-primitive +[ \ SUBF jit-math ] \ fixnum-fast define-sub-primitive [ 3 ds-reg 0 LWZ @@ -354,20 +338,20 @@ CONSTANT: rs-reg 30 4 4 tag-bits get SRAWI 5 3 4 MULLW 5 ds-reg 0 STW -] f f f \ fixnum*fast define-sub-primitive +] \ fixnum*fast define-sub-primitive -[ \ AND jit-math ] f f f \ fixnum-bitand define-sub-primitive +[ \ AND jit-math ] \ fixnum-bitand define-sub-primitive -[ \ OR jit-math ] f f f \ fixnum-bitor define-sub-primitive +[ \ OR jit-math ] \ fixnum-bitor define-sub-primitive -[ \ XOR jit-math ] f f f \ fixnum-bitxor define-sub-primitive +[ \ XOR jit-math ] \ fixnum-bitxor define-sub-primitive [ 3 ds-reg 0 LWZ 3 3 NOT 3 3 tag-mask get XORI 3 ds-reg 0 STW -] f f f \ fixnum-bitnot define-sub-primitive +] \ fixnum-bitnot define-sub-primitive [ 3 ds-reg 0 LWZ @@ -382,7 +366,7 @@ CONSTANT: rs-reg 30 2 BGT 5 7 MR 5 ds-reg 0 STW -] f f f \ fixnum-shift-fast define-sub-primitive +] \ fixnum-shift-fast define-sub-primitive [ 3 ds-reg 0 LWZ @@ -392,7 +376,7 @@ CONSTANT: rs-reg 30 6 5 3 MULLW 7 6 4 SUBF 7 ds-reg 0 STW -] f f f \ fixnum-mod define-sub-primitive +] \ fixnum-mod define-sub-primitive [ 3 ds-reg 0 LWZ @@ -401,7 +385,7 @@ CONSTANT: rs-reg 30 5 4 3 DIVW 5 5 tag-bits get SLWI 5 ds-reg 0 STW -] f f f \ fixnum/i-fast define-sub-primitive +] \ fixnum/i-fast define-sub-primitive [ 3 ds-reg 0 LWZ @@ -412,20 +396,20 @@ CONSTANT: rs-reg 30 5 5 tag-bits get SLWI 5 ds-reg -4 STW 7 ds-reg 0 STW -] f f f \ fixnum/mod-fast define-sub-primitive +] \ fixnum/mod-fast define-sub-primitive [ 3 ds-reg 0 LWZ 3 3 1 SRAWI rs-reg 3 3 LWZX 3 ds-reg 0 STW -] f f f \ get-local define-sub-primitive +] \ get-local define-sub-primitive [ 3 ds-reg 0 LWZ ds-reg ds-reg 4 SUBI 3 3 1 SRAWI rs-reg 3 rs-reg SUBF -] f f f \ drop-locals define-sub-primitive +] \ drop-locals define-sub-primitive [ "bootstrap.ppc" forget-vocab ] with-compilation-unit diff --git a/basis/cpu/x86/32/32.factor b/basis/cpu/x86/32/32.factor index b280afc01e..10cd9c8657 100755 --- a/basis/cpu/x86/32/32.factor +++ b/basis/cpu/x86/32/32.factor @@ -309,7 +309,7 @@ FUNCTION: bool check_sse2 ( ) ; check_sse2 ; "-no-sse2" (command-line) member? [ - optimizing-compiler compiler-impl [ { check_sse2 } compile ] with-variable + [ { check_sse2 } compile ] with-optimizer "Checking if your CPU supports SSE2..." print flush sse2? [ diff --git a/basis/cpu/x86/32/bootstrap.factor b/basis/cpu/x86/32/bootstrap.factor index 5d88f699b8..be21344815 100644 --- a/basis/cpu/x86/32/bootstrap.factor +++ b/basis/cpu/x86/32/bootstrap.factor @@ -22,13 +22,15 @@ IN: bootstrap.x86 : rex-length ( -- n ) 0 ; [ - temp0 0 [] MOV ! load stack_chain - temp0 [] stack-reg MOV ! save stack pointer -] rc-absolute-cell rt-stack-chain 2 jit-save-stack jit-define + ! load stack_chain + temp0 0 [] MOV rc-absolute-cell rt-stack-chain jit-rel + ! save stack pointer + temp0 [] stack-reg MOV +] jit-save-stack jit-define [ - (JMP) drop -] rc-relative rt-primitive 1 jit-primitive jit-define + (JMP) drop rc-relative rt-primitive jit-rel +] jit-primitive jit-define << "vocab:cpu/x86/bootstrap.factor" parse-file parsed >> call diff --git a/basis/cpu/x86/64/bootstrap.factor b/basis/cpu/x86/64/bootstrap.factor index ddf5791009..8d1ed086e7 100644 --- a/basis/cpu/x86/64/bootstrap.factor +++ b/basis/cpu/x86/64/bootstrap.factor @@ -20,15 +20,19 @@ IN: bootstrap.x86 : rex-length ( -- n ) 1 ; [ - temp0 0 MOV ! load stack_chain + ! load stack_chain + temp0 0 MOV rc-absolute-cell rt-stack-chain jit-rel temp0 temp0 [] MOV - temp0 [] stack-reg MOV ! save stack pointer -] rc-absolute-cell rt-stack-chain 1 rex-length + jit-save-stack jit-define + ! save stack pointer + temp0 [] stack-reg MOV +] jit-save-stack jit-define [ - temp1 0 MOV ! load XT - temp1 JMP ! go -] rc-absolute-cell rt-primitive 1 rex-length + jit-primitive jit-define + ! load XT + temp1 0 MOV rc-absolute-cell rt-primitive jit-rel + ! go + temp1 JMP +] jit-primitive jit-define << "vocab:cpu/x86/bootstrap.factor" parse-file parsed >> call diff --git a/basis/cpu/x86/assembler/assembler-tests.factor b/basis/cpu/x86/assembler/assembler-tests.factor index 49b0961819..203edf956e 100644 --- a/basis/cpu/x86/assembler/assembler-tests.factor +++ b/basis/cpu/x86/assembler/assembler-tests.factor @@ -62,3 +62,5 @@ IN: cpu.x86.assembler.tests [ { HEX: 48 HEX: d3 HEX: e1 } ] [ [ RCX CL SHL ] { } make ] unit-test [ { HEX: 48 HEX: d3 HEX: e8 } ] [ [ RAX CL SHR ] { } make ] unit-test [ { HEX: 48 HEX: d3 HEX: e9 } ] [ [ RCX CL SHR ] { } make ] unit-test + +[ { HEX: f7 HEX: c1 HEX: d2 HEX: 04 HEX: 00 HEX: 00 } ] [ [ ECX 1234 TEST ] { } make ] unit-test diff --git a/basis/cpu/x86/assembler/assembler.factor b/basis/cpu/x86/assembler/assembler.factor index 3a98d47416..5560d17a1e 100644 --- a/basis/cpu/x86/assembler/assembler.factor +++ b/basis/cpu/x86/assembler/assembler.factor @@ -316,15 +316,16 @@ M: operand JMP { BIN: 100 t HEX: ff } 1-operand ; GENERIC: CALL ( op -- ) : (CALL) ( -- rel-class ) HEX: e8 , 0 4, rc-relative ; M: f CALL (CALL) 2drop ; -M: callable CALL (CALL) rel-word ; +M: callable CALL (CALL) rel-word-direct ; M: label CALL (CALL) label-fixup ; M: operand CALL { BIN: 010 t HEX: ff } 1-operand ; GENERIC# JUMPcc 1 ( addr opcode -- ) -: (JUMPcc) ( n -- rel-class ) extended-opcode, 0 4, rc-relative ; -M: f JUMPcc nip (JUMPcc) drop ; -M: callable JUMPcc (JUMPcc) rel-word ; -M: label JUMPcc (JUMPcc) label-fixup ; +: (JUMPcc) ( addr n -- rel-class ) extended-opcode, 4, rc-relative ; +M: f JUMPcc [ 0 ] dip (JUMPcc) 2drop ; +M: integer JUMPcc (JUMPcc) drop ; +M: callable JUMPcc [ 0 ] dip (JUMPcc) rel-word ; +M: label JUMPcc [ 0 ] dip (JUMPcc) label-fixup ; : JO ( dst -- ) HEX: 80 JUMPcc ; : JNO ( dst -- ) HEX: 81 JUMPcc ; @@ -382,6 +383,10 @@ GENERIC: CMP ( dst src -- ) M: immediate CMP swap { BIN: 111 t HEX: 80 } immediate-1/4 ; M: operand CMP OCT: 070 2-operand ; +GENERIC: TEST ( dst src -- ) +M: immediate TEST swap { BIN: 0 t HEX: f7 } immediate-4 ; +M: operand TEST OCT: 204 2-operand ; + : XCHG ( dst src -- ) OCT: 207 2-operand ; : BSR ( dst src -- ) swap { HEX: 0f HEX: bd } (2-operand) ; diff --git a/basis/cpu/x86/bootstrap.factor b/basis/cpu/x86/bootstrap.factor index b63d31364b..4fe5e5cd33 100644 --- a/basis/cpu/x86/bootstrap.factor +++ b/basis/cpu/x86/bootstrap.factor @@ -1,18 +1,16 @@ -! Copyright (C) 2007, 2008 Slava Pestov. +! Copyright (C) 2007, 2009 Slava Pestov. ! See http://factorcode.org/license.txt for BSD license. USING: bootstrap.image.private kernel kernel.private namespaces system cpu.x86.assembler layouts compiler.units math math.private compiler.constants vocabs slots.private words -words.private locals.backend ; +locals.backend make sequences combinators arrays ; IN: bootstrap.x86 big-endian off -1 jit-code-format set - [ ! Load word - temp0 0 MOV + temp0 0 MOV rc-absolute-cell rt-immediate jit-rel ! Bump profiling counter temp0 profile-count-offset [+] 1 tag-fixnum ADD ! Load word->code @@ -21,35 +19,35 @@ big-endian off temp0 compiled-header-size ADD ! Jump to XT temp0 JMP -] rc-absolute-cell rt-immediate 1 rex-length + jit-profiling jit-define +] jit-profiling jit-define [ ! load XT - temp0 0 MOV + temp0 0 MOV rc-absolute-cell rt-this jit-rel ! save stack frame size stack-frame-size PUSH ! push XT temp0 PUSH ! alignment stack-reg stack-frame-size 3 bootstrap-cells - SUB -] rc-absolute-cell rt-this 1 rex-length + jit-prolog jit-define +] jit-prolog jit-define [ ! load literal - temp0 0 MOV + temp0 0 MOV rc-absolute-cell rt-immediate jit-rel ! increment datastack pointer ds-reg bootstrap-cell ADD ! store literal on datastack ds-reg [] temp0 MOV -] rc-absolute-cell rt-immediate 1 rex-length + jit-push-immediate jit-define +] jit-push-immediate jit-define [ - f JMP -] rc-relative rt-xt 1 jit-word-jump jit-define + f JMP rc-relative rt-xt jit-rel +] jit-word-jump jit-define [ - f CALL -] rc-relative rt-xt 1 jit-word-call jit-define + f CALL rc-relative rt-xt-direct jit-rel +] jit-word-call jit-define [ ! load boolean @@ -59,31 +57,13 @@ big-endian off ! compare boolean with f temp0 \ f tag-number CMP ! jump to true branch if not equal - f JNE -] rc-relative rt-xt 10 rex-length 3 * + jit-if-1 jit-define + f JNE rc-relative rt-xt jit-rel +] jit-if-1 jit-define [ ! jump to false branch if equal - f JMP -] rc-relative rt-xt 1 jit-if-2 jit-define - -[ - ! load dispatch table - temp1 0 MOV - ! load index - temp0 ds-reg [] MOV - ! turn it into an array offset - fixnum>slot@ - ! pop index - ds-reg bootstrap-cell SUB - ! compute quotation location - temp0 temp1 ADD - ! load quotation - arg temp0 array-start-offset [+] MOV - ! execute branch. the quot must be in arg, since it might - ! not be compiled yet - arg quot-xt-offset [+] JMP -] rc-absolute-cell rt-immediate 1 rex-length + jit-dispatch jit-define + f JMP rc-relative rt-xt jit-rel +] jit-if-2 jit-define : jit->r ( -- ) rs-reg bootstrap-cell ADD @@ -135,30 +115,133 @@ big-endian off [ jit->r - f CALL + f CALL rc-relative rt-xt jit-rel jit-r> -] rc-relative rt-xt 11 rex-length 4 * + jit-dip jit-define +] jit-dip jit-define [ jit-2>r - f CALL + f CALL rc-relative rt-xt jit-rel jit-2r> -] rc-relative rt-xt 17 rex-length 6 * + jit-2dip jit-define +] jit-2dip jit-define [ jit-3>r - f CALL + f CALL rc-relative rt-xt jit-rel jit-3r> -] rc-relative rt-xt 23 rex-length 8 * + jit-3dip jit-define +] jit-3dip jit-define + +: prepare-(execute) ( -- operand ) + ! load from stack + temp0 ds-reg [] MOV + ! pop stack + ds-reg bootstrap-cell SUB + ! execute word + temp0 word-xt-offset [+] ; + +[ prepare-(execute) JMP ] jit-execute-jump jit-define + +[ prepare-(execute) CALL ] jit-execute-call jit-define [ ! unwind stack frame stack-reg stack-frame-size bootstrap-cell - ADD -] f f f jit-epilog jit-define +] jit-epilog jit-define -[ 0 RET ] f f f jit-return jit-define +[ 0 RET ] jit-return jit-define -! Sub-primitives +! ! ! Polymorphic inline caches + +! temp0 contains the object being dispatched on +! temp1 contains its class + +! Load a value from a stack position +[ + temp1 ds-reg HEX: ffffffff [+] MOV rc-absolute rt-untagged jit-rel +] pic-load jit-define + +! Tag +: load-tag ( -- ) + temp1 tag-mask get AND + temp1 tag-bits get SHL ; + +[ load-tag ] pic-tag jit-define + +! The 'make' trick lets us compute the jump distance for the +! conditional branches there + +! Hi-tag +[ + temp0 temp1 MOV + load-tag + temp1 object tag-number tag-fixnum CMP + [ temp1 temp0 object tag-number neg [+] MOV ] { } make + [ length JNE ] [ % ] bi +] pic-hi-tag jit-define + +! Tuple +[ + temp0 temp1 MOV + load-tag + temp1 tuple tag-number tag-fixnum CMP + [ temp1 temp0 tuple tag-number neg bootstrap-cell + [+] MOV ] { } make + [ length JNE ] [ % ] bi +] pic-tuple jit-define + +! Hi-tag and tuple +[ + temp0 temp1 MOV + load-tag + ! If bits 2 and 3 are set, the tag is either 6 (object) or 7 (tuple) + temp1 BIN: 110 tag-fixnum CMP + [ + ! Untag temp0 + temp0 tag-mask get bitnot AND + ! Set temp1 to 0 for objects, and 8 for tuples + temp1 1 tag-fixnum AND + bootstrap-cell 4 = [ temp1 1 SHR ] when + ! Load header cell or tuple layout cell + temp1 temp0 temp1 [+] MOV + ] [ ] make [ length JL ] [ % ] bi +] pic-hi-tag-tuple jit-define + +[ + temp1 HEX: ffffffff CMP rc-absolute rt-immediate jit-rel +] pic-check-tag jit-define + +[ + temp2 HEX: ffffffff MOV rc-absolute-cell rt-immediate jit-rel + temp1 temp2 CMP +] pic-check jit-define + +[ f JE rc-relative rt-xt jit-rel ] pic-hit jit-define + +! ! ! Megamorphic caches + +[ + ! cache = ... + temp0 0 MOV rc-absolute-cell rt-immediate jit-rel + ! key = class + temp2 temp1 MOV + bootstrap-cell 8 = [ temp2 1 SHL ] when + ! key &= cache.length - 1 + temp2 mega-cache-size get 1- bootstrap-cell * AND + ! cache += array-start-offset + temp0 array-start-offset ADD + ! cache += key + temp0 temp2 ADD + ! if(get(cache) == class) + temp0 [] temp1 CMP + ! ... goto get(cache + bootstrap-cell) + [ + temp0 temp0 bootstrap-cell [+] MOV + temp0 word-xt-offset [+] JMP + ] [ ] make + [ length JNE ] [ % ] bi + ! fall-through on miss +] mega-lookup jit-define + +! ! ! Sub-primitives ! Quotations and words [ @@ -168,16 +251,7 @@ big-endian off ds-reg bootstrap-cell SUB ! call quotation arg quot-xt-offset [+] JMP -] f f f \ (call) define-sub-primitive - -[ - ! load from stack - temp0 ds-reg [] MOV - ! pop stack - ds-reg bootstrap-cell SUB - ! execute word - temp0 word-xt-offset [+] JMP -] f f f \ (execute) define-sub-primitive +] \ (call) define-sub-primitive ! Objects [ @@ -189,7 +263,7 @@ big-endian off temp0 tag-bits get SHL ! push to stack ds-reg [] temp0 MOV -] f f f \ tag define-sub-primitive +] \ tag define-sub-primitive [ ! load slot number @@ -207,26 +281,26 @@ big-endian off temp0 temp1 temp0 [+] MOV ! push to stack ds-reg [] temp0 MOV -] f f f \ slot define-sub-primitive +] \ slot define-sub-primitive ! Shufflers [ ds-reg bootstrap-cell SUB -] f f f \ drop define-sub-primitive +] \ drop define-sub-primitive [ ds-reg 2 bootstrap-cells SUB -] f f f \ 2drop define-sub-primitive +] \ 2drop define-sub-primitive [ ds-reg 3 bootstrap-cells SUB -] f f f \ 3drop define-sub-primitive +] \ 3drop define-sub-primitive [ temp0 ds-reg [] MOV ds-reg bootstrap-cell ADD ds-reg [] temp0 MOV -] f f f \ dup define-sub-primitive +] \ dup define-sub-primitive [ temp0 ds-reg [] MOV @@ -234,7 +308,7 @@ big-endian off ds-reg 2 bootstrap-cells ADD ds-reg [] temp0 MOV ds-reg bootstrap-cell neg [+] temp1 MOV -] f f f \ 2dup define-sub-primitive +] \ 2dup define-sub-primitive [ temp0 ds-reg [] MOV @@ -244,31 +318,31 @@ big-endian off ds-reg [] temp0 MOV ds-reg -1 bootstrap-cells [+] temp1 MOV ds-reg -2 bootstrap-cells [+] temp3 MOV -] f f f \ 3dup define-sub-primitive +] \ 3dup define-sub-primitive [ temp0 ds-reg [] MOV ds-reg bootstrap-cell SUB ds-reg [] temp0 MOV -] f f f \ nip define-sub-primitive +] \ nip define-sub-primitive [ temp0 ds-reg [] MOV ds-reg 2 bootstrap-cells SUB ds-reg [] temp0 MOV -] f f f \ 2nip define-sub-primitive +] \ 2nip define-sub-primitive [ temp0 ds-reg -1 bootstrap-cells [+] MOV ds-reg bootstrap-cell ADD ds-reg [] temp0 MOV -] f f f \ over define-sub-primitive +] \ over define-sub-primitive [ temp0 ds-reg -2 bootstrap-cells [+] MOV ds-reg bootstrap-cell ADD ds-reg [] temp0 MOV -] f f f \ pick define-sub-primitive +] \ pick define-sub-primitive [ temp0 ds-reg [] MOV @@ -276,7 +350,7 @@ big-endian off ds-reg [] temp1 MOV ds-reg bootstrap-cell ADD ds-reg [] temp0 MOV -] f f f \ dupd define-sub-primitive +] \ dupd define-sub-primitive [ temp0 ds-reg [] MOV @@ -285,21 +359,21 @@ big-endian off ds-reg [] temp0 MOV ds-reg -1 bootstrap-cells [+] temp1 MOV ds-reg -2 bootstrap-cells [+] temp0 MOV -] f f f \ tuck define-sub-primitive +] \ tuck define-sub-primitive [ temp0 ds-reg [] MOV temp1 ds-reg bootstrap-cell neg [+] MOV ds-reg bootstrap-cell neg [+] temp0 MOV ds-reg [] temp1 MOV -] f f f \ swap define-sub-primitive +] \ swap define-sub-primitive [ temp0 ds-reg -1 bootstrap-cells [+] MOV temp1 ds-reg -2 bootstrap-cells [+] MOV ds-reg -2 bootstrap-cells [+] temp0 MOV ds-reg -1 bootstrap-cells [+] temp1 MOV -] f f f \ swapd define-sub-primitive +] \ swapd define-sub-primitive [ temp0 ds-reg [] MOV @@ -308,7 +382,7 @@ big-endian off ds-reg -2 bootstrap-cells [+] temp1 MOV ds-reg -1 bootstrap-cells [+] temp0 MOV ds-reg [] temp3 MOV -] f f f \ rot define-sub-primitive +] \ rot define-sub-primitive [ temp0 ds-reg [] MOV @@ -317,14 +391,14 @@ big-endian off ds-reg -2 bootstrap-cells [+] temp0 MOV ds-reg -1 bootstrap-cells [+] temp3 MOV ds-reg [] temp1 MOV -] f f f \ -rot define-sub-primitive +] \ -rot define-sub-primitive -[ jit->r ] f f f \ load-local define-sub-primitive +[ jit->r ] \ load-local define-sub-primitive ! Comparisons : jit-compare ( insn -- ) ! load t - temp3 0 MOV + temp3 0 MOV rc-absolute-cell rt-immediate jit-rel ! load f temp1 \ f tag-number MOV ! load first value @@ -339,8 +413,7 @@ big-endian off ds-reg [] temp1 MOV ; : define-jit-compare ( insn word -- ) - [ [ jit-compare ] curry rc-absolute-cell rt-immediate 1 rex-length + ] dip - define-sub-primitive ; + [ [ jit-compare ] curry ] dip define-sub-primitive ; \ CMOVE \ eq? define-jit-compare \ CMOVGE \ fixnum>= define-jit-compare @@ -357,9 +430,9 @@ big-endian off ! compute result [ ds-reg [] temp0 ] dip execute( dst src -- ) ; -[ \ ADD jit-math ] f f f \ fixnum+fast define-sub-primitive +[ \ ADD jit-math ] \ fixnum+fast define-sub-primitive -[ \ SUB jit-math ] f f f \ fixnum-fast define-sub-primitive +[ \ SUB jit-math ] \ fixnum-fast define-sub-primitive [ ! load second input @@ -374,20 +447,20 @@ big-endian off temp0 temp1 IMUL2 ! push result ds-reg [] temp1 MOV -] f f f \ fixnum*fast define-sub-primitive +] \ fixnum*fast define-sub-primitive -[ \ AND jit-math ] f f f \ fixnum-bitand define-sub-primitive +[ \ AND jit-math ] \ fixnum-bitand define-sub-primitive -[ \ OR jit-math ] f f f \ fixnum-bitor define-sub-primitive +[ \ OR jit-math ] \ fixnum-bitor define-sub-primitive -[ \ XOR jit-math ] f f f \ fixnum-bitxor define-sub-primitive +[ \ XOR jit-math ] \ fixnum-bitxor define-sub-primitive [ ! complement ds-reg [] NOT ! clear tag bits ds-reg [] tag-mask get XOR -] f f f \ fixnum-bitnot define-sub-primitive +] \ fixnum-bitnot define-sub-primitive [ ! load shift count @@ -411,7 +484,7 @@ big-endian off temp1 temp3 CMOVGE ! push to stack ds-reg [] temp1 MOV -] f f f \ fixnum-shift-fast define-sub-primitive +] \ fixnum-shift-fast define-sub-primitive : jit-fixnum-/mod ( -- ) ! load second parameter @@ -431,7 +504,7 @@ big-endian off ds-reg bootstrap-cell SUB ! push to stack ds-reg [] mod-arg MOV -] f f f \ fixnum-mod define-sub-primitive +] \ fixnum-mod define-sub-primitive [ jit-fixnum-/mod @@ -441,7 +514,7 @@ big-endian off div-arg tag-bits get SHL ! push to stack ds-reg [] div-arg MOV -] f f f \ fixnum/i-fast define-sub-primitive +] \ fixnum/i-fast define-sub-primitive [ jit-fixnum-/mod @@ -450,7 +523,7 @@ big-endian off ! push to stack ds-reg [] mod-arg MOV ds-reg bootstrap-cell neg [+] div-arg MOV -] f f f \ fixnum/mod-fast define-sub-primitive +] \ fixnum/mod-fast define-sub-primitive [ temp0 ds-reg [] MOV @@ -461,7 +534,7 @@ big-endian off temp1 1 tag-fixnum MOV temp0 temp1 CMOVE ds-reg [] temp0 MOV -] f f f \ both-fixnums? define-sub-primitive +] \ both-fixnums? define-sub-primitive [ ! load local number @@ -472,7 +545,7 @@ big-endian off temp0 rs-reg temp0 [+] MOV ! push to stack ds-reg [] temp0 MOV -] f f f \ get-local define-sub-primitive +] \ get-local define-sub-primitive [ ! load local count @@ -483,6 +556,6 @@ big-endian off fixnum>slot@ ! decrement retain stack pointer rs-reg temp0 SUB -] f f f \ drop-locals define-sub-primitive +] \ drop-locals define-sub-primitive [ "bootstrap.x86" forget-vocab ] with-compilation-unit diff --git a/basis/debugger/debugger-docs.factor b/basis/debugger/debugger-docs.factor index ff5869efab..ff9986432c 100644 --- a/basis/debugger/debugger-docs.factor +++ b/basis/debugger/debugger-docs.factor @@ -1,6 +1,6 @@ USING: alien arrays generic generic.math help.markup help.syntax kernel math memory strings sbufs vectors io io.files classes -help generic.standard continuations io.files.private listener +help generic.single continuations io.files.private listener alien.libraries ; IN: debugger diff --git a/basis/debugger/debugger.factor b/basis/debugger/debugger.factor index d8ebd5bbf9..2091a26133 100644 --- a/basis/debugger/debugger.factor +++ b/basis/debugger/debugger.factor @@ -6,7 +6,7 @@ sequences assocs sequences.private strings io.styles io.pathnames vectors words system splitting math.parser classes.mixin classes.tuple continuations continuations.private combinators generic.math classes.builtin classes compiler.units -generic.standard vocabs init kernel.private io.encodings +generic.standard generic.single vocabs init kernel.private io.encodings accessors math.order destructors source-files parser classes.tuple.parser effects.parser lexer generic.parser strings.parser vocabs.loader vocabs.parser see diff --git a/basis/delegate/delegate-tests.factor b/basis/delegate/delegate-tests.factor index f6a40d8dc8..9f9aca8702 100644 --- a/basis/delegate/delegate-tests.factor +++ b/basis/delegate/delegate-tests.factor @@ -1,6 +1,6 @@ USING: delegate kernel arrays tools.test words math definitions compiler.units parser generic prettyprint io.streams.string -accessors eval multiline generic.standard delegate.protocols +accessors eval multiline generic.single delegate.protocols delegate.private assocs see ; IN: delegate.tests diff --git a/basis/documents/elements/elements.factor b/basis/documents/elements/elements.factor index f485f1bec1..0776f8f158 100644 --- a/basis/documents/elements/elements.factor +++ b/basis/documents/elements/elements.factor @@ -79,6 +79,13 @@ M: one-word-elt next-elt drop [ f next-word ] modify-col ; +SINGLETON: word-start-elt + +M: word-start-elt prev-elt + drop one-word-elt prev-elt ; + +M: word-start-elt next-elt 2drop ; + SINGLETON: word-elt M: word-elt prev-elt diff --git a/basis/ftp/client/client.factor b/basis/ftp/client/client.factor index 14877110d3..9d51ba259e 100644 --- a/basis/ftp/client/client.factor +++ b/basis/ftp/client/client.factor @@ -66,7 +66,7 @@ ERROR: ftp-error got expected ; : list ( url -- ftp-response ) utf8 open-passive-client ftp-list - lines + stream-lines swap >>strings read-response 226 ftp-assert parse-list ; diff --git a/basis/hints/hints.factor b/basis/hints/hints.factor index d445bf72ad..db04033275 100644 --- a/basis/hints/hints.factor +++ b/basis/hints/hints.factor @@ -1,9 +1,9 @@ -! Copyright (C) 2008 Slava Pestov. +! Copyright (C) 2008, 2009 Slava Pestov. ! See http://factorcode.org/license.txt for BSD license. USING: parser words definitions kernel sequences assocs arrays kernel.private fry combinators accessors vectors strings sbufs byte-arrays byte-vectors io.binary io.streams.string splitting math -math.parser generic generic.standard generic.standard.engines classes +math.parser generic generic.single generic.standard classes hashtables namespaces ; IN: hints @@ -42,13 +42,13 @@ SYMBOL: specialize-method? t specialize-method? set-global +: method-declaration ( method -- quot ) + [ "method-generic" word-prop dispatch# object ] + [ "method-class" word-prop ] + bi prefix [ declare ] curry [ ] like ; + : specialize-method ( quot method -- quot' ) - [ - specialize-method? get [ - [ "method-class" word-prop ] [ "method-generic" word-prop ] bi - method-declaration prepend - ] [ drop ] if - ] + [ specialize-method? get [ method-declaration prepend ] [ drop ] if ] [ "method-generic" word-prop "specializer" word-prop ] bi [ specialize-quot ] when* ; @@ -71,7 +71,7 @@ t specialize-method? set-global SYNTAX: HINTS: scan-object [ changed-definition ] - [ parse-definition "specializer" set-word-prop ] bi ; + [ parse-definition { } like "specializer" set-word-prop ] bi ; ! Default specializers { first first2 first3 first4 } diff --git a/basis/http/client/client-docs.factor b/basis/http/client/client-docs.factor index 0d7f7851e2..e00f8e2263 100644 --- a/basis/http/client/client-docs.factor +++ b/basis/http/client/client-docs.factor @@ -1,6 +1,7 @@ USING: http help.markup help.syntax io.pathnames io.streams.string io.encodings.8-bit io.encodings.binary kernel strings urls -urls.encoding byte-arrays strings assocs sequences destructors ; +urls.encoding byte-arrays strings assocs sequences destructors +http.client.post-data.private ; IN: http.client HELP: download-failed @@ -71,7 +72,7 @@ ARTICLE: "http.client.get" "GET requests with the HTTP client" { $subsection with-http-get } { $subsection with-http-request } ; -ARTICLE: "http.client.post-data" "HTTP client submission data" +ARTICLE: "http.client.post-data" "HTTP client post data" "HTTP POST and PUT request words take a post data parameter, which can be one of the following:" { $list { "a " { $link byte-array } ": the data is sent the server without further encoding" } @@ -85,7 +86,9 @@ ARTICLE: "http.client.post-data" "HTTP client submission data" { $code "\"my-large-post-request.txt\" ascii " "[ URL\" http://www.my-company.com/web-service\" http-post ] with-disposal" -} ; +} +"An internal word used to convert objects to " { $link post-data } " instances:" +{ $subsection >post-data } ; ARTICLE: "http.client.post" "POST requests with the HTTP client" "Basic usage involves passing post data and a " { $link url } ", and getting a " { $link response } " and data back:" diff --git a/basis/http/client/post-data/post-data-docs.factor b/basis/http/client/post-data/post-data-docs.factor new file mode 100644 index 0000000000..24325e9ebd --- /dev/null +++ b/basis/http/client/post-data/post-data-docs.factor @@ -0,0 +1,6 @@ +IN: http.client.post-data +USING: http http.client.post-data.private help.markup help.syntax kernel ; + +HELP: >post-data +{ $values { "object" object } { "post-data" { $maybe post-data } } } +{ $description "Converts an object into a " { $link post-data } " tuple instance." } ; diff --git a/basis/io/backend/windows/nt/nt.factor b/basis/io/backend/windows/nt/nt.factor index 6f283ac1bb..4dfe02d651 100755 --- a/basis/io/backend/windows/nt/nt.factor +++ b/basis/io/backend/windows/nt/nt.factor @@ -46,7 +46,7 @@ M: winnt add-completion ( win32-handle -- ) { [ dup integer? ] [ ] } { [ dup array? ] [ first dup eof? - [ drop 0 ] [ (win32-error-string) throw ] if + [ drop 0 ] [ n>win32-error-string throw ] if ] } } cond ] with-timeout ; @@ -105,7 +105,7 @@ M: winnt seek-handle ( n seek-type handle -- ) GetLastError { { [ dup expected-io-error? ] [ drop f ] } { [ dup eof? ] [ drop t ] } - [ (win32-error-string) throw ] + [ n>win32-error-string throw ] } cond ] [ f ] if ; diff --git a/basis/io/backend/windows/nt/privileges/privileges.factor b/basis/io/backend/windows/nt/privileges/privileges.factor index 64218f75b0..33577a9394 100755 --- a/basis/io/backend/windows/nt/privileges/privileges.factor +++ b/basis/io/backend/windows/nt/privileges/privileges.factor @@ -2,7 +2,7 @@ USING: alien alien.c-types alien.syntax arrays continuations destructors generic io.mmap io.ports io.backend.windows io.files.windows kernel libc math math.bitwise namespaces quotations sequences windows windows.advapi32 windows.kernel32 io.backend system accessors -io.backend.windows.privileges ; +io.backend.windows.privileges windows.errors ; IN: io.backend.windows.nt.privileges TYPEDEF: TOKEN_PRIVILEGES* PTOKEN_PRIVILEGES diff --git a/basis/io/backend/windows/windows.factor b/basis/io/backend/windows/windows.factor index 6ecbc49f2a..9f5c00cc5f 100755 --- a/basis/io/backend/windows/windows.factor +++ b/basis/io/backend/windows/windows.factor @@ -1,10 +1,10 @@ ! Copyright (C) 2004, 2008 Mackenzie Straight, Doug Coleman. ! See http://factorcode.org/license.txt for BSD license. USING: alien alien.c-types arrays destructors io io.backend -io.buffers io.files io.ports io.binary io.timeouts -windows.errors strings kernel math namespaces sequences windows -windows.kernel32 windows.shell32 windows.types windows.winsock -splitting continuations math.bitwise system accessors ; +io.buffers io.files io.ports io.binary io.timeouts system +windows.errors strings kernel math namespaces sequences +windows.errors windows.kernel32 windows.shell32 windows.types +windows.winsock splitting continuations math.bitwise accessors ; IN: io.backend.windows : set-inherit ( handle ? -- ) @@ -51,4 +51,4 @@ HOOK: add-completion io-backend ( port -- ) : default-security-attributes ( -- obj ) "SECURITY_ATTRIBUTES" "SECURITY_ATTRIBUTES" heap-size - over set-SECURITY_ATTRIBUTES-nLength ; \ No newline at end of file + over set-SECURITY_ATTRIBUTES-nLength ; diff --git a/basis/io/encodings/string/string.factor b/basis/io/encodings/string/string.factor index 5e57a943a9..3659939fb0 100644 --- a/basis/io/encodings/string/string.factor +++ b/basis/io/encodings/string/string.factor @@ -4,7 +4,7 @@ USING: io io.streams.byte-array ; IN: io.encodings.string : decode ( byte-array encoding -- string ) - contents ; + stream-contents ; : encode ( string encoding -- byte-array ) [ write ] with-byte-writer ; diff --git a/basis/io/files/links/links-docs.factor b/basis/io/files/links/links-docs.factor index 8419399c92..bf1bedaa08 100644 --- a/basis/io/files/links/links-docs.factor +++ b/basis/io/files/links/links-docs.factor @@ -5,6 +5,10 @@ HELP: make-link { $values { "target" "a path to the symbolic link's target" } { "symlink" "a path to new symbolic link" } } { $description "Creates a symbolic link." } ; +HELP: make-hard-link +{ $values { "target" "a path to the hard link's target" } { "link" "a path to new symbolic link" } } +{ $description "Creates a hard link." } ; + HELP: read-link { $values { "symlink" "a path to an existing symbolic link" } { "path" "the path pointed to by the symbolic link" } } { $description "Reads the symbolic link and returns its target path." } ; diff --git a/basis/io/files/links/links.factor b/basis/io/files/links/links.factor index 1212d579db..7aec916c72 100644 --- a/basis/io/files/links/links.factor +++ b/basis/io/files/links/links.factor @@ -6,6 +6,8 @@ IN: io.files.links HOOK: make-link os ( target symlink -- ) +HOOK: make-hard-link os ( target link -- ) + HOOK: read-link os ( symlink -- path ) : copy-link ( target symlink -- ) diff --git a/basis/io/files/links/unix/unix.factor b/basis/io/files/links/unix/unix.factor index 7d2a6ee4f3..c9a651b484 100644 --- a/basis/io/files/links/unix/unix.factor +++ b/basis/io/files/links/unix/unix.factor @@ -7,6 +7,9 @@ IN: io.files.links.unix M: unix make-link ( path1 path2 -- ) normalize-path symlink io-error ; +M: unix make-hard-link ( path1 path2 -- ) + normalize-path link io-error ; + M: unix read-link ( path -- path' ) normalize-path read-symbolic-link ; diff --git a/basis/io/files/windows/nt/nt.factor b/basis/io/files/windows/nt/nt.factor index afc81c784c..32424a37a3 100755 --- a/basis/io/files/windows/nt/nt.factor +++ b/basis/io/files/windows/nt/nt.factor @@ -4,7 +4,8 @@ io.backend.windows io.files.windows 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 windows.time windows.shell32 ; +namespaces make accessors tr windows.time windows.shell32 +windows.errors ; IN: io.files.windows.nt M: winnt cwd diff --git a/basis/io/launcher/launcher.factor b/basis/io/launcher/launcher.factor index f5809223fc..838c09c657 100755 --- a/basis/io/launcher/launcher.factor +++ b/basis/io/launcher/launcher.factor @@ -3,9 +3,9 @@ USING: system kernel namespaces strings hashtables sequences assocs combinators vocabs.loader init threads continuations math accessors concurrency.flags destructors environment -io io.backend io.timeouts io.pipes io.pipes.private io.encodings -io.streams.duplex io.ports debugger prettyprint summary -calendar ; +io io.encodings.ascii io.backend io.timeouts io.pipes +io.pipes.private io.encodings io.streams.duplex io.ports +debugger prettyprint summary calendar ; IN: io.launcher TUPLE: process < identity-tuple @@ -265,3 +265,5 @@ M: object run-pipeline-element { [ os winnt? ] [ "io.launcher.windows.nt" require ] } [ ] } cond + +: run-desc ( desc -- result ) ascii f swap stream-read-until drop ; diff --git a/basis/io/launcher/unix/unix-tests.factor b/basis/io/launcher/unix/unix-tests.factor index f375bb41e8..99d45e4fd7 100644 --- a/basis/io/launcher/unix/unix-tests.factor +++ b/basis/io/launcher/unix/unix-tests.factor @@ -33,7 +33,7 @@ concurrency.promises threads unix.process ; "cat" "launcher-test-1" temp-file 2array - ascii contents + ascii stream-contents ] unit-test [ ] [ @@ -52,7 +52,7 @@ concurrency.promises threads unix.process ; "cat" "launcher-test-1" temp-file 2array - ascii contents + ascii stream-contents ] unit-test [ ] [ @@ -70,14 +70,14 @@ concurrency.promises threads unix.process ; "cat" "launcher-test-1" temp-file 2array - ascii contents + ascii stream-contents ] unit-test [ t ] [ "env" >>command { { "A" "B" } } >>environment - ascii lines + ascii stream-lines "A=B" swap member? ] unit-test @@ -86,7 +86,7 @@ concurrency.promises threads unix.process ; "env" >>command { { "A" "B" } } >>environment +replace-environment+ >>environment-mode - ascii lines + ascii stream-lines ] unit-test [ "hi\n" ] [ @@ -113,13 +113,13 @@ concurrency.promises threads unix.process ; "append-test" temp-file utf8 file-contents ] unit-test -[ t ] [ "ls" utf8 contents >boolean ] unit-test +[ t ] [ "ls" utf8 stream-contents >boolean ] unit-test [ "Hello world.\n" ] [ "cat" utf8 [ "Hello world.\n" write output-stream get dispose - input-stream get contents + input-stream get stream-contents ] with-stream ] unit-test diff --git a/basis/io/mmap/windows/windows.factor b/basis/io/mmap/windows/windows.factor index ebd8109d14..8fdc7fefd9 100644 --- a/basis/io/mmap/windows/windows.factor +++ b/basis/io/mmap/windows/windows.factor @@ -2,7 +2,7 @@ USING: alien alien.c-types arrays destructors generic io.mmap io.ports io.backend.windows io.files.windows io.backend.windows.privileges kernel libc math math.bitwise namespaces quotations sequences windows windows.advapi32 windows.kernel32 io.backend system -accessors locals ; +accessors locals windows.errors ; IN: io.mmap.windows : create-file-mapping ( hFile lpAttributes flProtect dwMaximumSizeHigh dwMaximumSizeLow lpName -- HANDLE ) @@ -12,8 +12,8 @@ IN: io.mmap.windows MapViewOfFile [ win32-error=0/f ] keep ; :: mmap-open ( path length access-mode create-mode protect access -- handle handle address ) - [let | lo [ length HEX: ffffffff bitand ] - hi [ length -32 shift HEX: ffffffff bitand ] | + [let | lo [ length 32 bits ] + hi [ length -32 shift 32 bits ] | { "SeCreateGlobalPrivilege" "SeLockMemoryPrivilege" } [ path access-mode create-mode 0 open-file |dispose dup handle>> f protect hi lo f create-file-mapping |dispose diff --git a/basis/io/monitors/windows/nt/nt.factor b/basis/io/monitors/windows/nt/nt.factor index d2408a3dd1..bec249c04c 100755 --- a/basis/io/monitors/windows/nt/nt.factor +++ b/basis/io/monitors/windows/nt/nt.factor @@ -6,7 +6,7 @@ hashtables sorting arrays combinators math.bitwise strings system accessors threads splitting io.backend io.backend.windows io.backend.windows.nt io.files.windows.nt io.monitors io.ports io.buffers io.files io.timeouts io.encodings.string -io.encodings.utf16n io windows windows.kernel32 windows.types +io.encodings.utf16n io windows.errors windows.kernel32 windows.types io.pathnames ; IN: io.monitors.windows.nt diff --git a/basis/io/servers/connection/connection-tests.factor b/basis/io/servers/connection/connection-tests.factor index ae79290f0a..ab99531eb4 100644 --- a/basis/io/servers/connection/connection-tests.factor +++ b/basis/io/servers/connection/connection-tests.factor @@ -35,4 +35,4 @@ concurrency.promises io.encodings.ascii io threads calendar ; dup start-server* sockets>> first addr>> port>> "port" set ] unit-test -[ "Hello world." ] [ "localhost" "port" get ascii drop contents ] unit-test +[ "Hello world." ] [ "localhost" "port" get ascii drop stream-contents ] unit-test diff --git a/basis/io/sockets/secure/unix/unix-tests.factor b/basis/io/sockets/secure/unix/unix-tests.factor index 7c4dcc17d1..f87ad93fbd 100644 --- a/basis/io/sockets/secure/unix/unix-tests.factor +++ b/basis/io/sockets/secure/unix/unix-tests.factor @@ -23,7 +23,7 @@ io.sockets.secure.unix.debug ; : client-test ( -- string ) [ - "127.0.0.1" "port" get ?promise ascii drop contents + "127.0.0.1" "port" get ?promise ascii drop stream-contents ] with-secure-context ; [ ] [ [ class name>> write ] server-test ] unit-test diff --git a/basis/io/streams/byte-array/byte-array-tests.factor b/basis/io/streams/byte-array/byte-array-tests.factor index 3cf52c6a78..0cd35dfa21 100644 --- a/basis/io/streams/byte-array/byte-array-tests.factor +++ b/basis/io/streams/byte-array/byte-array-tests.factor @@ -6,7 +6,7 @@ io.encodings.utf8 io kernel arrays strings namespaces ; [ B{ BIN: 11110101 BIN: 10111111 BIN: 10000000 BIN: 10111111 BIN: 11101111 BIN: 10000000 BIN: 10111111 BIN: 11011111 BIN: 10000000 CHAR: x } ] [ { BIN: 101111111000000111111 BIN: 1111000000111111 BIN: 11111000000 CHAR: x } >string utf8 [ write ] with-byte-writer ] unit-test -[ { BIN: 101111111000000111111 } t ] [ { BIN: 11110101 BIN: 10111111 BIN: 10000000 BIN: 10111111 } utf8 contents dup >array swap string? ] unit-test +[ { BIN: 101111111000000111111 } t ] [ { BIN: 11110101 BIN: 10111111 BIN: 10000000 BIN: 10111111 } utf8 stream-contents dup >array swap string? ] unit-test [ B{ 121 120 } 0 ] [ B{ 0 121 120 0 0 0 0 0 0 } binary @@ -26,4 +26,4 @@ io.encodings.utf8 io kernel arrays strings namespaces ; 0 seek-end input-stream get stream-seek read1 ] with-byte-reader -] unit-test \ No newline at end of file +] unit-test diff --git a/basis/io/styles/styles-docs.factor b/basis/io/styles/styles-docs.factor old mode 100644 new mode 100755 index 6148394c57..8fcf12aae9 --- a/basis/io/styles/styles-docs.factor +++ b/basis/io/styles/styles-docs.factor @@ -1,17 +1,17 @@ USING: help.markup help.syntax io.streams.plain io strings -hashtables kernel quotations colors ; +hashtables kernel quotations colors assocs ; IN: io.styles HELP: stream-format -{ $values { "str" string } { "style" "a hashtable" } { "stream" "an output stream" } } +{ $values { "str" string } { "style" assoc } { "stream" "an output stream" } } { $contract "Writes formatted text to the stream. If the stream does buffering, output may not be performed immediately; use " { $link stream-flush } " to force output." $nl -"The " { $snippet "style" } " hashtable holds character style information. See " { $link "character-styles" } "." } +"The " { $snippet "style" } " assoc holds character style information. See " { $link "character-styles" } "." } { $notes "Most code only works on one stream at a time and should instead use " { $link format } "; see " { $link "stdio" } "." } $io-error ; HELP: make-block-stream -{ $values { "style" "a hashtable" } { "stream" "an output stream" } { "stream'" "an output stream" } } +{ $values { "style" assoc } { "stream" "an output stream" } { "stream'" "an output stream" } } { $contract "Creates an output stream which wraps " { $snippet "stream" } " and adds " { $snippet "style" } " on calls to " { $link stream-write } " and " { $link stream-format } "." $nl "Unlike " { $link make-span-stream } ", this creates a new paragraph block in the output." @@ -21,7 +21,7 @@ $nl $io-error ; HELP: stream-write-table -{ $values { "table-cells" "a sequence of sequences of table cells" } { "style" "a hashtable" } { "stream" "an output stream" } } +{ $values { "table-cells" "a sequence of sequences of table cells" } { "style" assoc } { "stream" "an output stream" } } { $contract "Prints a table of cells produced by " { $link with-cell } "." $nl "The " { $snippet "style" } " hashtable holds table style information. See " { $link "table-styles" } "." } @@ -29,13 +29,13 @@ $nl $io-error ; HELP: make-cell-stream -{ $values { "style" hashtable } { "stream" "an output stream" } { "stream'" object } } +{ $values { "style" assoc } { "stream" "an output stream" } { "stream'" object } } { $contract "Creates an output stream which writes to a table cell object." } { $notes "Most code only works on one stream at a time and should instead use " { $link with-cell } "; see " { $link "stdio" } "." } $io-error ; HELP: make-span-stream -{ $values { "style" "a hashtable" } { "stream" "an output stream" } { "stream'" "an output stream" } } +{ $values { "style" assoc } { "stream" "an output stream" } { "stream'" "an output stream" } } { $contract "Creates an output stream which wraps " { $snippet "stream" } " and adds " { $snippet "style" } " on calls to " { $link stream-write } " and " { $link stream-format } "." $nl "Unlike " { $link make-block-stream } ", the stream output is inline, and not nested in a paragraph block." } @@ -43,19 +43,19 @@ $nl $io-error ; HELP: format -{ $values { "str" string } { "style" "a hashtable" } } +{ $values { "str" string } { "style" assoc } } { $description "Writes formatted text to " { $link output-stream } ". If the stream does buffering, output may not be performed immediately; use " { $link flush } " to force output." } { $notes "Details are in the documentation for " { $link stream-format } "." } $io-error ; HELP: with-nesting -{ $values { "style" "a hashtable" } { "quot" quotation } } +{ $values { "style" assoc } { "quot" quotation } } { $description "Calls the quotation in a new dynamic scope with " { $link output-stream } " rebound to a nested paragraph stream, with formatting information applied." } { $notes "Details are in the documentation for " { $link make-block-stream } "." } $io-error ; HELP: tabular-output -{ $values { "style" "a hashtable" } { "quot" quotation } } +{ $values { "style" assoc } { "quot" quotation } } { $description "Calls a quotation which emits a series of equal-length table rows using " { $link with-row } ". The results are laid out in a tabular fashion on " { $link output-stream } "." $nl "The " { $snippet "style" } " hashtable holds table style information. See " { $link "table-styles" } "." } @@ -85,7 +85,7 @@ HELP: write-cell $io-error ; HELP: with-style -{ $values { "style" "a hashtable" } { "quot" quotation } } +{ $values { "style" assoc } { "quot" quotation } } { $description "Calls the quotation in a new dynamic scope where calls to " { $link write } ", " { $link format } " and other stream output words automatically inherit style settings from " { $snippet "style" } "." } { $notes "Details are in the documentation for " { $link make-span-stream } "." } $io-error ; diff --git a/basis/io/styles/styles.factor b/basis/io/styles/styles.factor index c3bf5d2f28..2d25016919 100644 --- a/basis/io/styles/styles.factor +++ b/basis/io/styles/styles.factor @@ -99,7 +99,11 @@ M: plain-writer make-block-stream nip ; M: plain-writer stream-write-table - [ drop format-table [ nl ] [ write ] interleave ] with-output-stream* ; + [ + drop + [ [ >string ] map ] map format-table + [ nl ] [ write ] interleave + ] with-output-stream* ; M: plain-writer make-cell-stream 2drop ; diff --git a/basis/locals/locals-tests.factor b/basis/locals/locals-tests.factor index 68fa8dbda0..1549a77663 100644 --- a/basis/locals/locals-tests.factor +++ b/basis/locals/locals-tests.factor @@ -585,4 +585,4 @@ M: integer ed's-bug neg ; :: ed's-test-case ( a -- b ) { [ a ed's-bug ] } && ; -[ t ] [ \ ed's-test-case optimized>> ] unit-test +[ t ] [ \ ed's-test-case optimized? ] unit-test diff --git a/basis/macros/macros-docs.factor b/basis/macros/macros-docs.factor old mode 100644 new mode 100755 index acd2c3383f..6a4672bea0 --- a/basis/macros/macros-docs.factor +++ b/basis/macros/macros-docs.factor @@ -49,6 +49,7 @@ $nl { $subsection POSTPONE: MACRO: } "A slightly lower-level facility, " { $emphasis "compiler transforms" } ", allows an ordinary word definition to co-exist with a version that performs compile-time expansion." { $subsection define-transform } -"An example is the " { $link member? } " word. If the input sequence is a literal, the compile transform kicks in and converts the " { $link member? } " call into a series of conditionals. Otherwise, if the input sequence is not literal, a call to the definition of " { $link member? } " is generated." ; +"An example is the " { $link member? } " word. If the input sequence is a literal, the compile transform kicks in and converts the " { $link member? } " call into a series of conditionals. Otherwise, if the input sequence is not literal, a call to the definition of " { $link member? } " is generated." +{ $see-also "generalizations" "fry" } ; ABOUT: "macros" diff --git a/basis/math/complex/complex-docs.factor b/basis/math/complex/complex-docs.factor index 6b6f5c95bd..a51b86ff0b 100644 --- a/basis/math/complex/complex-docs.factor +++ b/basis/math/complex/complex-docs.factor @@ -25,7 +25,3 @@ HELP: complex { $class-description "The class of complex numbers with non-zero imaginary part." } ; ABOUT: "complex-numbers" - -HELP: ( x y -- z ) -{ $values { "x" "a real number" } { "y" "a real number" } { "z" "a complex number" } } -{ $description "Low-level complex number constructor. User code should call " { $link rect> } " instead." } ; diff --git a/basis/math/complex/complex.factor b/basis/math/complex/complex.factor index c41faaf558..832a9e64ba 100644 --- a/basis/math/complex/complex.factor +++ b/basis/math/complex/complex.factor @@ -15,14 +15,14 @@ M: complex hashcode* nip >rect [ hashcode ] bi@ bitxor ; : complex= ( x y quot -- ? ) componentwise and ; inline M: complex equal? over complex? [ [ = ] complex= ] [ 2drop f ] if ; M: complex number= [ number= ] complex= ; -: complex-op ( x y quot -- z ) componentwise (rect>) ; inline +: complex-op ( x y quot -- z ) componentwise rect> ; inline M: complex + [ + ] complex-op ; M: complex - [ - ] complex-op ; : *re ( x y -- xr*yr xi*yi ) [ >rect ] bi@ [ * ] bi-curry@ bi* ; inline : *im ( x y -- xi*yr xr*yi ) swap [ >rect ] bi@ swap [ * ] bi-curry@ bi* ; inline -M: complex * [ *re - ] [ *im + ] 2bi (rect>) ; +M: complex * [ *re - ] [ *im + ] 2bi rect> ; : (complex/) ( x y -- r i m ) [ [ *re + ] [ *im - ] 2bi ] keep absq ; inline -: complex/ ( x y quot -- z ) [ (complex/) ] dip curry bi@ (rect>) ; inline +: complex/ ( x y quot -- z ) [ (complex/) ] dip curry bi@ rect> ; inline M: complex / [ / ] complex/ ; M: complex /f [ /f ] complex/ ; M: complex /i [ /i ] complex/ ; diff --git a/basis/math/functions/functions-docs.factor b/basis/math/functions/functions-docs.factor index f7d0d5a941..48da8aa6ec 100644 --- a/basis/math/functions/functions-docs.factor +++ b/basis/math/functions/functions-docs.factor @@ -100,11 +100,6 @@ ARTICLE: "math-functions" "Mathematical functions" ABOUT: "math-functions" -HELP: (rect>) -{ $values { "x" real } { "y" real } { "z" number } } -{ $description "Creates a complex number from real and imaginary components." } -{ $warning "This word does not check that the arguments are real numbers, which can have undefined consequences. Use the " { $link rect> } " word instead." } ; - HELP: rect> { $values { "x" real } { "y" real } { "z" number } } { $description "Creates a complex number from real and imaginary components. If " { $snippet "z" } " is an integer zero, this will simply output " { $snippet "x" } "." } ; diff --git a/basis/math/functions/functions.factor b/basis/math/functions/functions.factor index a6beb87345..c21053317e 100644 --- a/basis/math/functions/functions.factor +++ b/basis/math/functions/functions.factor @@ -7,19 +7,8 @@ IN: math.functions : >fraction ( a/b -- a b ) [ numerator ] [ denominator ] bi ; inline -) ( x y -- z ) - dup 0 = [ drop ] [ ] if ; inline - -PRIVATE> - : rect> ( x y -- z ) - 2dup [ real? ] both? [ - (rect>) - ] [ - "Complex number must have real components" throw - ] if ; inline + dup 0 = [ drop ] [ complex boa ] if ; inline GENERIC: sqrt ( x -- y ) foldable diff --git a/basis/math/ratios/ratios-docs.factor b/basis/math/ratios/ratios-docs.factor index 7b6393dabe..2e51fa1870 100644 --- a/basis/math/ratios/ratios-docs.factor +++ b/basis/math/ratios/ratios-docs.factor @@ -47,6 +47,3 @@ HELP: 2>fraction { $values { "a/b" rational } { "c/d" rational } { "a" integer } { "c" integer } { "b" "a positive integer" } { "d" "a positive integer" } } { $description "Extracts the numerator and denominator of two rational numbers at once." } ; -HELP: ( a b -- a/b ) -{ $values { "a" integer } { "b" integer } { "a/b" "a ratio" } } -{ $description "Primitive ratio constructor. User code should call " { $link / } " to create ratios instead." } ; diff --git a/basis/math/ratios/ratios.factor b/basis/math/ratios/ratios.factor index 54e4bee1a8..d4f457180e 100644 --- a/basis/math/ratios/ratios.factor +++ b/basis/math/ratios/ratios.factor @@ -9,7 +9,7 @@ IN: math.ratios ( a b -- a/b ) - dup 1 number= [ drop ] [ ] if ; inline + dup 1 number= [ drop ] [ ratio boa ] if ; inline : scale ( a/b c/d -- a*d b*c ) 2>fraction [ * swap ] dip * swap ; inline diff --git a/basis/peg/peg-tests.factor b/basis/peg/peg-tests.factor index 683fa328d8..cae1e05dc8 100644 --- a/basis/peg/peg-tests.factor +++ b/basis/peg/peg-tests.factor @@ -199,10 +199,10 @@ IN: peg.tests USE: compiler -[ ] [ disable-compiler ] unit-test +[ ] [ disable-optimizer ] unit-test [ ] [ "" epsilon parse drop ] unit-test -[ ] [ enable-compiler ] unit-test +[ ] [ enable-optimizer ] unit-test [ [ ] ] [ "" epsilon [ drop [ [ ] ] call ] action parse ] unit-test diff --git a/basis/random/windows/windows.factor b/basis/random/windows/windows.factor index a4cf74e1df..488deef41f 100644 --- a/basis/random/windows/windows.factor +++ b/basis/random/windows/windows.factor @@ -1,6 +1,6 @@ USING: accessors alien.c-types byte-arrays continuations -kernel windows windows.advapi32 init namespaces random -destructors locals ; +kernel windows.advapi32 init namespaces random destructors +locals windows.errors ; IN: random.windows TUPLE: windows-rng provider type ; diff --git a/basis/refs/refs-docs.factor b/basis/refs/refs-docs.factor old mode 100644 new mode 100755 index 9c10641c4c..9971a1d4fa --- a/basis/refs/refs-docs.factor +++ b/basis/refs/refs-docs.factor @@ -1,14 +1,18 @@ ! Copyright (C) 2007 Slava Pestov, 2009 Alex Chapman ! See http://factorcode.org/license.txt for BSD license. -USING: boxes help.markup help.syntax kernel math namespaces ; +USING: boxes help.markup help.syntax kernel math namespaces assocs ; IN: refs ARTICLE: "refs" "References" -"References provide a uniform way of accessing and changing values. Some examples of referenced values are variables, tuple slots, and keys or values of assocs. References can be read, written, and deleted. References are defined in the " { $vocab-link "refs" } " vocabulary, and new reference types can be made by implementing the " { $link "refs-protocol" } "." -{ $subsection get-ref } -{ $subsection set-ref } -{ $subsection set-ref* } -{ $subsection delete-ref } +"References provide a uniform way of accessing and changing values. Some examples of referenced values are variables, tuple slots, and keys or values of assocs. References can be read, written, and deleted. References are defined in the " { $vocab-link "refs" } " vocabulary, and new reference types can be made by implementing a protocol." +{ $subsection "refs-protocol" } +{ $subsection "refs-impls" } +{ $subsection "refs-utils" } +"References are used by the " { $link "ui-inspector" } "." ; + +ABOUT: "refs" + +ARTICLE: "refs-impls" "Reference implementations" "References to objects:" { $subsection obj-ref } { $subsection } @@ -27,20 +31,24 @@ ARTICLE: "refs" "References" { $subsection slot-ref } { $subsection } "Using boxes as references:" -{ $subsection "box-refs" } -"References are used by the UI inspector." ; +{ $subsection "box-refs" } ; -ABOUT: "refs" +ARTICLE: "refs-utils" "Reference utilities" +{ $subsection ref-on } +{ $subsection ref-off } +{ $subsection ref-inc } +{ $subsection ref-dec } +{ $subsection set-ref* } ; -ARTICLE: "refs-protocol" "Reference Protocol" +ARTICLE: "refs-protocol" "Reference protocol" "To use a class of objects as references you must implement the reference protocol for that class, and mark your class as an instance of the " { $link ref } " mixin class. All references must implement these two words:" { $subsection get-ref } { $subsection set-ref } "References may also implement:" { $subsection delete-ref } ; -ARTICLE: "box-refs" "Using Boxes as References" -"Boxes are elements of the " { $link ref } " mixin class, so any box may be used as a reference. Bear in mind that boxes will still throw an error if you call " { $link get-ref } " on an empty box." ; +ARTICLE: "box-refs" "Boxes as references" +{ $link "boxes" } " are elements of the " { $link ref } " mixin class, so any box may be used as a reference. Bear in mind that boxes will still throw an error if you call " { $link get-ref } " on an empty box." ; HELP: ref { $class-description "A mixin class whose instances encapsulate a value which can be read, written, and deleted. Instantiable members of this class include:" { $link obj-ref } ", " { $link var-ref } ", " { $link global-var-ref } ", " { $link slot-ref } ", " { $link box } ", " { $link key-ref } ", and " { $link value-ref } "." } ; @@ -89,14 +97,14 @@ HELP: key-ref { $class-description "Instances of this class identify a key in an associative structure. New key references are created by calling " { $link } "." } ; HELP: -{ $values { "assoc" "an assoc" } { "key" object } { "key-ref" key-ref } } +{ $values { "assoc" assoc } { "key" object } { "key-ref" key-ref } } { $description "Creates a reference to a key stored in an assoc." } ; HELP: value-ref { $class-description "Instances of this class identify a value associated to a key in an associative structure. New value references are created by calling " { $link } "." } ; HELP: -{ $values { "assoc" "an assoc" } { "key" object } { "value-ref" value-ref } } +{ $values { "assoc" assoc } { "key" object } { "value-ref" value-ref } } { $description "Creates a reference to the value associated with " { $snippet "key" } " in " { $snippet "assoc" } "." } ; { get-ref set-ref delete-ref set-ref* } related-words diff --git a/basis/see/see.factor b/basis/see/see.factor index 2494c72fa4..37153b5229 100644 --- a/basis/see/see.factor +++ b/basis/see/see.factor @@ -1,13 +1,13 @@ ! Copyright (C) 2009 Slava Pestov. ! See http://factorcode.org/license.txt for BSD license. USING: accessors arrays assocs classes classes.builtin -classes.intersection classes.mixin classes.predicate -classes.singleton classes.tuple classes.union combinators -definitions effects generic generic.standard io io.pathnames +classes.intersection classes.mixin classes.predicate classes.singleton +classes.tuple classes.union combinators definitions effects generic +generic.single generic.standard generic.hook io io.pathnames io.streams.string io.styles kernel make namespaces prettyprint prettyprint.backend prettyprint.config prettyprint.custom -prettyprint.sections sequences sets sorting strings summary -words words.symbol words.constant words.alias ; +prettyprint.sections sequences sets sorting strings summary words +words.symbol words.constant words.alias ; IN: see GENERIC: synopsis* ( defspec -- ) diff --git a/basis/stack-checker/backend/backend.factor b/basis/stack-checker/backend/backend.factor index 4fb5bab96f..338b052316 100755 --- a/basis/stack-checker/backend/backend.factor +++ b/basis/stack-checker/backend/backend.factor @@ -1,10 +1,9 @@ ! Copyright (C) 2004, 2009 Slava Pestov. ! See http://factorcode.org/license.txt for BSD license. -USING: fry arrays generic io io.streams.string kernel math -namespaces parser sequences strings vectors words quotations -effects classes continuations assocs combinators -compiler.errors accessors math.order definitions sets -generic.standard.engines.tuple hints macros stack-checker.state +USING: fry arrays generic io io.streams.string kernel math namespaces +parser sequences strings vectors words quotations effects classes +continuations assocs combinators compiler.errors accessors math.order +definitions sets hints macros stack-checker.state stack-checker.visitor stack-checker.errors stack-checker.values stack-checker.recursive-state ; IN: stack-checker.backend diff --git a/basis/stack-checker/call-effect/call-effect-tests.factor b/basis/stack-checker/call-effect/call-effect-tests.factor index e5c0f23b30..b222cbbcf7 100644 --- a/basis/stack-checker/call-effect/call-effect-tests.factor +++ b/basis/stack-checker/call-effect/call-effect-tests.factor @@ -1,7 +1,16 @@ -USING: stack-checker.call-effect tools.test math kernel ; +USING: stack-checker.call-effect tools.test math kernel math effects ; IN: stack-checker.call-effect.tests [ t ] [ \ + (( a b -- c )) execute-effect-unsafe? ] unit-test [ t ] [ \ + (( a b c -- d e )) execute-effect-unsafe? ] unit-test [ f ] [ \ + (( a b c -- d )) execute-effect-unsafe? ] unit-test -[ f ] [ \ call (( x -- )) execute-effect-unsafe? ] unit-test \ No newline at end of file +[ f ] [ \ call (( x -- )) execute-effect-unsafe? ] unit-test + +[ t ] [ [ + ] cached-effect (( a b -- c )) effect= ] unit-test +[ t ] [ 5 [ + ] curry cached-effect (( a -- c )) effect= ] unit-test +[ t ] [ 5 [ ] curry cached-effect (( -- c )) effect= ] unit-test +[ t ] [ [ dup ] [ drop ] compose cached-effect (( a -- b )) effect= ] unit-test +[ t ] [ [ drop ] [ dup ] compose cached-effect (( a b -- c d )) effect= ] unit-test +[ t ] [ [ 2drop ] [ dup ] compose cached-effect (( a b c -- d e )) effect= ] unit-test +[ t ] [ [ 1 2 3 ] [ 2drop ] compose cached-effect (( -- a )) effect= ] unit-test +[ t ] [ [ 1 2 ] [ 3drop ] compose cached-effect (( a -- )) effect= ] unit-test \ No newline at end of file diff --git a/basis/stack-checker/call-effect/call-effect.factor b/basis/stack-checker/call-effect/call-effect.factor index 100088f174..b3b678d93d 100644 --- a/basis/stack-checker/call-effect/call-effect.factor +++ b/basis/stack-checker/call-effect/call-effect.factor @@ -2,7 +2,7 @@ ! See http://factorcode.org/license.txt for BSD license. USING: accessors combinators combinators.private effects fry kernel kernel.private make sequences continuations quotations -stack-checker stack-checker.transforms words ; +stack-checker stack-checker.transforms words math ; IN: stack-checker.call-effect ! call( and execute( have complex expansions. @@ -18,14 +18,36 @@ IN: stack-checker.call-effect TUPLE: inline-cache value ; -: cache-hit? ( word/quot ic -- ? ) value>> eq? ; inline +: cache-hit? ( word/quot ic -- ? ) + [ value>> eq? ] [ value>> ] bi and ; inline -SYMBOL: +unknown+ +SINGLETON: +unknown+ GENERIC: cached-effect ( quot -- effect ) M: object cached-effect drop +unknown+ ; +GENERIC: curry-effect ( effect -- effect' ) + +M: +unknown+ curry-effect ; + +M: effect curry-effect + [ in>> length ] [ out>> length ] [ terminated?>> ] tri + pick 0 = [ [ 1+ ] dip ] [ [ 1- ] 2dip ] if + effect boa ; + +M: curry cached-effect + quot>> cached-effect curry-effect ; + +: compose-effects* ( effect1 effect2 -- effect' ) + { + { [ 2dup [ effect? ] both? ] [ compose-effects ] } + { [ 2dup [ +unknown+ eq? ] either? ] [ 2drop +unknown+ ] } + } cond ; + +M: compose cached-effect + [ first>> ] [ second>> ] bi [ cached-effect ] bi@ compose-effects* ; + M: quotation cached-effect dup cached-effect>> [ ] [ @@ -79,7 +101,7 @@ M: quotation cached-effect [ '[ _ execute ] ] dip call-effect-slow ; inline : execute-effect-unsafe? ( word effect -- ? ) - over optimized>> [ [ stack-effect ] dip effect<= ] [ 2drop f ] if ; inline + over optimized? [ [ stack-effect ] dip effect<= ] [ 2drop f ] if ; inline : execute-effect-fast ( word effect inline-cache -- ) 2over execute-effect-unsafe? diff --git a/basis/stack-checker/errors/errors-docs.factor b/basis/stack-checker/errors/errors-docs.factor old mode 100644 new mode 100755 index 7a87ab988d..6a67b815cd --- a/basis/stack-checker/errors/errors-docs.factor +++ b/basis/stack-checker/errors/errors-docs.factor @@ -84,8 +84,11 @@ HELP: inconsistent-recursive-call-error } ; ARTICLE: "inference-errors" "Stack checker errors" -"These conditions are thrown by " { $link "inference" } ", as well as the " { $link "compiler" } "." -$nl +"These " { $link "inference" } " failure conditions are reported in one of two ways:" +{ $list + { { $link "tools.inference" } " throws them as errors" } + { "The " { $link "compiler" } " reports them via " { $link "tools.errors" } } +} "Error thrown when insufficient information is available to calculate the stack effect of a combinator call (see " { $link "inference-combinators" } "):" { $subsection literal-expected } "Error thrown when a word's stack effect declaration does not match the composition of the stack effects of its factors:" diff --git a/basis/stack-checker/errors/errors.factor b/basis/stack-checker/errors/errors.factor index e036d4d81b..b1071df708 100644 --- a/basis/stack-checker/errors/errors.factor +++ b/basis/stack-checker/errors/errors.factor @@ -33,4 +33,6 @@ ERROR: unknown-primitive-error < inference-error ; ERROR: transform-expansion-error < inference-error word error ; +ERROR: bad-declaration-error < inference-error declaration ; + M: object (literal) "literal value" literal-expected ; \ No newline at end of file diff --git a/basis/stack-checker/known-words/known-words.factor b/basis/stack-checker/known-words/known-words.factor index eade33e52b..4a9ff93179 100644 --- a/basis/stack-checker/known-words/known-words.factor +++ b/basis/stack-checker/known-words/known-words.factor @@ -9,9 +9,10 @@ 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.types words.private +assocs summary compiler.units system.private +combinators combinators.short-circuit locals locals.backend locals.types quotations.private combinators.private stack-checker.values +generic.single generic.single.private alien.libraries stack-checker.alien stack-checker.state @@ -57,8 +58,12 @@ IN: stack-checker.known-words : infer-shuffle-word ( word -- ) "shuffle" word-prop infer-shuffle ; +: check-declaration ( declaration -- declaration ) + dup { [ array? ] [ [ class? ] all? ] } 1&& + [ bad-declaration-error ] unless ; + : infer-declare ( -- ) - pop-literal nip + pop-literal nip check-declaration [ length ensure-d ] keep zip #declare, ; @@ -142,7 +147,7 @@ M: object infer-call* apply-word/effect ; : infer-execute-effect-unsafe ( -- ) - \ execute infer-effect-unsafe ; + \ (execute) infer-effect-unsafe ; : infer-call-effect-unsafe ( -- ) \ call infer-effect-unsafe ; @@ -227,14 +232,7 @@ M: object infer-call* ! More words not to compile \ call t "no-compile" set-word-prop -\ call subwords [ t "no-compile" set-word-prop ] each - \ execute t "no-compile" set-word-prop -\ execute subwords [ t "no-compile" set-word-prop ] each - -\ effective-method t "no-compile" set-word-prop -\ effective-method subwords [ t "no-compile" set-word-prop ] each - \ clear t "no-compile" set-word-prop : non-inline-word ( word -- ) @@ -292,9 +290,6 @@ M: object infer-call* \ bignum>float { bignum } { float } define-primitive \ bignum>float make-foldable -\ { integer integer } { ratio } define-primitive -\ make-foldable - \ string>float { string } { float } define-primitive \ string>float make-foldable @@ -313,9 +308,6 @@ M: object infer-call* \ bits>double { integer } { float } define-primitive \ bits>double make-foldable -\ { real real } { complex } define-primitive -\ make-foldable - \ both-fixnums? { object object } { object } define-primitive \ fixnum+ { fixnum fixnum } { integer } define-primitive @@ -676,3 +668,12 @@ M: object infer-call* \ gc-stats { } { array } define-primitive \ jit-compile { quotation } { } define-primitive + +\ lookup-method { object array } { word } define-primitive + +\ reset-dispatch-stats { } { } define-primitive +\ dispatch-stats { } { array } define-primitive +\ reset-inline-cache-stats { } { } define-primitive +\ inline-cache-stats { } { array } define-primitive + +\ optimized? { word } { object } define-primitive \ No newline at end of file diff --git a/basis/stack-checker/stack-checker-docs.factor b/basis/stack-checker/stack-checker-docs.factor index 243221ccf0..7d18482bff 100644 --- a/basis/stack-checker/stack-checker-docs.factor +++ b/basis/stack-checker/stack-checker-docs.factor @@ -102,6 +102,7 @@ ARTICLE: "tools.inference" "Stack effect tools" "Comparing effects:" { $subsection effect-height } { $subsection effect<= } +{ $subsection effect= } "The class of stack effects:" { $subsection effect } { $subsection effect? } ; diff --git a/basis/stack-checker/transforms/transforms.factor b/basis/stack-checker/transforms/transforms.factor index cd8a57bf2e..8113a662d6 100755 --- a/basis/stack-checker/transforms/transforms.factor +++ b/basis/stack-checker/transforms/transforms.factor @@ -19,7 +19,6 @@ IN: stack-checker.transforms rstate recursive-state [ word stack quot call-transformer ] with-variable [ - word inlined-dependency depends-on values [ length meta-d shorten-by ] [ #drop, ] bi rstate infer-quot ] [ word infer-word ] if* ; @@ -108,7 +107,6 @@ IN: stack-checker.transforms ] 1 define-transform \ boa t "no-compile" set-word-prop -M\ tuple-class boa t "no-compile" set-word-prop \ new [ dup tuple-class? [ diff --git a/basis/strings/tables/tables-tests.factor b/basis/strings/tables/tables-tests.factor index a77312897a..9429772f4a 100644 --- a/basis/strings/tables/tables-tests.factor +++ b/basis/strings/tables/tables-tests.factor @@ -2,3 +2,7 @@ ! See http://factorcode.org/license.txt for BSD license. USING: tools.test strings.tables ; IN: strings.tables.tests + +[ { "A BB" "CC D" } ] [ { { "A" "BB" } { "CC" "D" } } format-table ] unit-test + +[ { "A C" "B " "D E" } ] [ { { "A\nB" "C" } { "D" "E" } } format-table ] unit-test \ No newline at end of file diff --git a/basis/strings/tables/tables.factor b/basis/strings/tables/tables.factor index c6ccba5a78..51032264c7 100644 --- a/basis/strings/tables/tables.factor +++ b/basis/strings/tables/tables.factor @@ -1,21 +1,30 @@ ! Copyright (C) 2009 Slava Pestov. ! See http://factorcode.org/license.txt for BSD license. -USING: kernel sequences fry math.order ; +USING: kernel sequences fry math.order splitting ; IN: strings.tables ] dip '[ 0 = @ ] 2map ; inline +: max-length ( seq -- n ) + [ length ] [ max ] map-reduce ; + +: format-row ( seq ? -- seq ) + [ + dup max-length + '[ _ "" pad-tail ] map + ] unless ; + +: format-column ( seq ? -- seq ) + [ + dup max-length + '[ _ CHAR: \s pad-tail ] map + ] unless ; + PRIVATE> : format-table ( table -- seq ) - flip [ format-column ] map-last - flip [ " " join ] map ; \ No newline at end of file + [ [ [ string-lines ] map ] dip format-row flip ] map-last concat + flip [ format-column ] map-last flip [ " " join ] map ; \ No newline at end of file diff --git a/basis/tools/continuations/continuations.factor b/basis/tools/continuations/continuations.factor index 1ac4557ec4..8c572f4ae3 100644 --- a/basis/tools/continuations/continuations.factor +++ b/basis/tools/continuations/continuations.factor @@ -4,7 +4,7 @@ USING: threads kernel namespaces continuations combinators sequences math namespaces.private continuations.private concurrency.messaging quotations kernel.private words sequences.private assocs models models.arrow arrays accessors -generic generic.standard definitions make sbufs tools.crossref ; +generic generic.single definitions make sbufs tools.crossref ; IN: tools.continuations > (step-into-quot) ] diff --git a/basis/tools/crossref/crossref.factor b/basis/tools/crossref/crossref.factor index c5cd246f2e..6082933bcb 100644 --- a/basis/tools/crossref/crossref.factor +++ b/basis/tools/crossref/crossref.factor @@ -3,8 +3,7 @@ USING: words assocs definitions io io.pathnames io.styles kernel prettyprint sorting see sets sequences arrays hashtables help.crossref help.topics help.markup quotations accessors source-files namespaces -graphs vocabs generic generic.standard.engines.tuple threads -compiler.units init ; +graphs vocabs generic generic.single threads compiler.units init ; IN: tools.crossref SYMBOL: crossref @@ -82,7 +81,7 @@ M: object irrelevant? drop f ; M: default-method irrelevant? drop t ; -M: engine-word irrelevant? drop t ; +M: predicate-engine irrelevant? drop t ; PRIVATE> diff --git a/basis/tools/deploy/backend/backend.factor b/basis/tools/deploy/backend/backend.factor index 6ca54ca36b..b74548a65f 100755 --- a/basis/tools/deploy/backend/backend.factor +++ b/basis/tools/deploy/backend/backend.factor @@ -3,12 +3,11 @@ USING: namespaces make continuations.private kernel.private init 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.files.temp io.pathnames -io.directories io.directories.hierarchy io.backend quotations -io.launcher words.private tools.deploy.config -tools.deploy.config.editor bootstrap.image io.encodings.utf8 -destructors accessors hashtables ; +summary layouts vocabs.loader prettyprint.config prettyprint debugger +io.streams.c io.files io.files.temp io.pathnames io.directories +io.directories.hierarchy io.backend quotations io.launcher +tools.deploy.config tools.deploy.config.editor bootstrap.image +io.encodings.utf8 destructors accessors hashtables ; IN: tools.deploy.backend : copy-vm ( executable bundle-name -- vm ) diff --git a/basis/tools/deploy/shaker/shaker.factor b/basis/tools/deploy/shaker/shaker.factor index e23e1b092d..9b02d3208f 100755 --- a/basis/tools/deploy/shaker/shaker.factor +++ b/basis/tools/deploy/shaker/shaker.factor @@ -2,7 +2,7 @@ ! See http://factorcode.org/license.txt for BSD license. USING: accessors io.backend io.streams.c init fry namespaces make assocs kernel parser lexer strings.parser vocabs -sequences words words.private memory kernel.private +sequences words memory kernel.private continuations io vocabs.loader system strings sets vectors quotations byte-arrays sorting compiler.units definitions generic generic.standard tools.deploy.config ; @@ -103,6 +103,7 @@ IN: tools.deploy.shaker "compiled-uses" "constraints" "custom-inlining" + "decision-tree" "declared-effect" "default" "default-method" @@ -112,14 +113,12 @@ IN: tools.deploy.shaker "engines" "forgotten" "identities" - "if-intrinsics" - "infer" "inline" "inlined-block" "input-classes" "instances" "interval" - "intrinsics" + "intrinsic" "lambda" "loc" "local-reader" @@ -136,7 +135,7 @@ IN: tools.deploy.shaker "method-generic" "modular-arithmetic" "no-compile" - "optimizer-hooks" + "owner-generic" "outputs" "participants" "predicate" @@ -149,17 +148,13 @@ IN: tools.deploy.shaker "register" "register-size" "shuffle" - "slot-names" "slots" "special" "specializer" - "step-into" - "step-into?" ! UI needs this ! "superclass" "transform-n" "transform-quot" - "tuple-dispatch-generic" "type" "writer" "writing" diff --git a/basis/tools/deploy/test/test.factor b/basis/tools/deploy/test/test.factor index eb780e40cc..f997a6eb3a 100644 --- a/basis/tools/deploy/test/test.factor +++ b/basis/tools/deploy/test/test.factor @@ -16,4 +16,5 @@ IN: tools.deploy.test : run-temp-image ( -- ) vm "-i=" "test.image" temp-file append - 2array try-process ; \ No newline at end of file + 2array + swap >>command +closed+ >>stdin try-process ; \ No newline at end of file diff --git a/basis/tools/disassembler/disassembler-tests.factor b/basis/tools/disassembler/disassembler-tests.factor index 49cfb054a1..89ca265bf6 100644 --- a/basis/tools/disassembler/disassembler-tests.factor +++ b/basis/tools/disassembler/disassembler-tests.factor @@ -1,6 +1,4 @@ IN: tools.disassembler.tests -USING: math classes.tuple prettyprint.custom -tools.disassembler tools.test strings ; +USING: kernel fry vocabs tools.disassembler tools.test sequences ; -[ ] [ \ + disassemble ] unit-test -[ ] [ M\ string pprint* disassemble ] unit-test +"math" words [ [ [ ] ] dip '[ _ disassemble ] unit-test ] each \ No newline at end of file diff --git a/basis/tools/disassembler/udis/udis.factor b/basis/tools/disassembler/udis/udis.factor index 51e399c1c3..cd9dd9cf4b 100755 --- a/basis/tools/disassembler/udis/udis.factor +++ b/basis/tools/disassembler/udis/udis.factor @@ -3,7 +3,7 @@ USING: tools.disassembler namespaces combinators alien alien.syntax alien.c-types lexer parser kernel sequences layouts math math.order alien.libraries -math.parser system make fry arrays ; +math.parser system make fry arrays libc destructors ; IN: tools.disassembler.udis << @@ -47,11 +47,14 @@ FUNCTION: uint ud_insn_len ( ud* u ) ; FUNCTION: char* ud_lookup_mnemonic ( int c ) ; : ( -- ud ) - "ud" + "ud" malloc-object &free dup ud_init dup cell-bits ud_set_mode dup UD_SYN_INTEL ud_set_syntax ; +: with-ud ( quot: ( ud -- ) -- ) + [ [ ] dip call ] with-destructors ; inline + SINGLETON: udis-disassembler : buf/len ( from to -- buf len ) [ drop ] [ swap - ] 2bi ; @@ -82,10 +85,12 @@ SINGLETON: udis-disassembler ] { } make ; M: udis-disassembler disassemble* ( from to -- buffer ) - [ ] 2dip { + '[ + _ _ [ drop ud_set_pc ] [ buf/len ud_set_input_buffer ] [ 2drop (disassemble) format-disassembly ] - } 3cleave ; + 3tri + ] with-ud ; udis-disassembler disassembler-backend set-global diff --git a/basis/tools/scaffold/scaffold.factor b/basis/tools/scaffold/scaffold.factor index f35da24266..5c8b868483 100755 --- a/basis/tools/scaffold/scaffold.factor +++ b/basis/tools/scaffold/scaffold.factor @@ -6,7 +6,7 @@ vocabs.loader io combinators calendar accessors math.parser io.streams.string ui.tools.operations quotations strings arrays prettyprint words vocabs sorting sets classes math alien urls splitting ascii combinators.short-circuit alarms words.symbol -system ; +system summary ; IN: tools.scaffold SYMBOL: developer-name @@ -16,6 +16,10 @@ ERROR: not-a-vocab-root string ; ERROR: vocab-name-contains-separator path ; ERROR: vocab-name-contains-dot path ; ERROR: no-vocab vocab ; +ERROR: bad-developer-name name ; + +M: bad-developer-name summary + drop "Developer name must be a string." ; path scaffolding? [ - [ developer-name get ] dip utf8 set-file-contents + developer-name get [ + "authors.txt" vocab-root/vocab/file>path scaffolding? [ + developer-name get swap utf8 set-file-contents + ] [ + drop + ] if ] [ - drop + 2drop ] if ; : lookup-type ( string -- object/string ? ) @@ -298,9 +306,12 @@ SYMBOL: examples-flag "}" print ] with-variable ; +: touch. ( path -- ) + [ touch-file ] + [ "Click to edit: " write . ] bi ; + : scaffold-rc ( path -- ) - [ home ] dip append-path - [ touch-file ] [ "Click to edit: " write . ] bi ; + [ home ] dip append-path touch. ; : scaffold-factor-boot-rc ( -- ) os windows? "factor-boot-rc" ".factor-boot-rc" ? scaffold-rc ; @@ -308,4 +319,7 @@ SYMBOL: examples-flag : scaffold-factor-rc ( -- ) os windows? "factor-rc" ".factor-rc" ? scaffold-rc ; -: scaffold-emacs ( -- ) ".emacs" scaffold-rc ; + +HOOK: scaffold-emacs os ( -- ) + +M: unix scaffold-emacs ( -- ) ".emacs" scaffold-rc ; diff --git a/basis/tools/scaffold/windows/authors.txt b/basis/tools/scaffold/windows/authors.txt new file mode 100755 index 0000000000..7c1b2f2279 --- /dev/null +++ b/basis/tools/scaffold/windows/authors.txt @@ -0,0 +1 @@ +Doug Coleman diff --git a/basis/tools/scaffold/windows/tags.txt b/basis/tools/scaffold/windows/tags.txt new file mode 100644 index 0000000000..6bf68304bb --- /dev/null +++ b/basis/tools/scaffold/windows/tags.txt @@ -0,0 +1 @@ +unportable diff --git a/basis/tools/scaffold/windows/windows.factor b/basis/tools/scaffold/windows/windows.factor new file mode 100755 index 0000000000..fef6121717 --- /dev/null +++ b/basis/tools/scaffold/windows/windows.factor @@ -0,0 +1,7 @@ +! Copyright (C) 2009 Doug Coleman. +! See http://factorcode.org/license.txt for BSD license. +USING: io.pathnames system tools.scaffold windows.shell32 ; +IN: tools.scaffold.windows + +M: windows scaffold-emacs ( -- ) + application-data ".emacs" append-path touch. ; diff --git a/basis/tools/time/time.factor b/basis/tools/time/time.factor index 0d1d9f6fa1..65e87f976f 100644 --- a/basis/tools/time/time.factor +++ b/basis/tools/time/time.factor @@ -1,24 +1,27 @@ ! Copyright (C) 2003, 2008 Slava Pestov. ! See http://factorcode.org/license.txt for BSD license. USING: kernel math math.vectors memory io io.styles prettyprint -namespaces system sequences splitting grouping assocs strings ; +namespaces system sequences splitting grouping assocs strings +generic.single combinators ; IN: tools.time : benchmark ( quot -- runtime ) micros [ call micros ] dip - ; inline -: time. ( data -- ) - unclip - "==== RUNNING TIME" print nl 1000000 /f pprint " seconds" print nl +: time. ( time -- ) + "== Running time ==" print nl 1000000 /f pprint " seconds" print ; + +: gc-stats. ( stats -- ) 5 cut* - "==== GARBAGE COLLECTION" print nl + "== Garbage collection ==" print nl + "Times are in microseconds." print nl [ 6 group { "GC count:" - "Cumulative GC time (us):" - "Longest GC pause (us):" - "Average GC pause (us):" + "Total GC time:" + "Longest GC pause:" + "Average GC pause:" "Objects copied:" "Bytes copied:" } prefix @@ -29,13 +32,43 @@ IN: tools.time [ nl { - "Total GC time (us):" + "Total GC time:" "Cards scanned:" "Decks scanned:" - "Card scan time (us):" + "Card scan time:" "Code heap literal scans:" } swap zip simple-table. ] bi* ; +: dispatch-stats. ( stats -- ) + "== Megamorphic caches ==" print nl + { "Hits" "Misses" } swap zip simple-table. ; + +: inline-cache-stats. ( stats -- ) + nl "== Polymorphic inline caches ==" print nl + 3 cut + [ + "Transitions:" print + { "Cold to monomorphic" "Mono to polymorphic" "Poly to megamorphic" } swap zip + simple-table. nl + ] [ + "Type check stubs:" print + { "Tag only" "Hi-tag" "Tuple" "Hi-tag and tuple" } swap zip + simple-table. + ] bi* ; + : time ( quot -- ) - gc-reset micros [ call gc-stats micros ] dip - prefix time. ; inline + gc-reset + reset-dispatch-stats + reset-inline-cache-stats + benchmark gc-stats dispatch-stats inline-cache-stats + H{ { table-gap { 20 20 } } } [ + [ + [ [ time. ] 3dip ] with-cell + [ ] with-cell + ] with-row + [ + [ [ gc-stats. ] 2dip ] with-cell + [ [ dispatch-stats. ] [ inline-cache-stats. ] bi* ] with-cell + ] with-row + ] tabular-output nl ; inline diff --git a/basis/tools/vocabs/vocabs.factor b/basis/tools/vocabs/vocabs.factor index ba99a41eba..4b9a72a443 100644 --- a/basis/tools/vocabs/vocabs.factor +++ b/basis/tools/vocabs/vocabs.factor @@ -74,8 +74,6 @@ SYMBOL: failures SYMBOL: changed-vocabs -[ f changed-vocabs set-global ] "tools.vocabs" add-init-hook - : changed-vocab ( vocab -- ) dup vocab changed-vocabs get and [ dup changed-vocabs get set-at ] [ drop ] if ; @@ -287,3 +285,12 @@ MEMO: all-authors ( -- seq ) \ all-vocabs-seq reset-memoized \ all-authors reset-memoized \ all-tags reset-memoized ; + +SINGLETON: cache-observer + +M: cache-observer vocabs-changed drop reset-cache ; + +[ + f changed-vocabs set-global + cache-observer add-vocab-observer +] "tools.vocabs" add-init-hook \ No newline at end of file diff --git a/basis/tools/walker/walker-tests.factor b/basis/tools/walker/walker-tests.factor index 6dabb73e30..6f87792faa 100644 --- a/basis/tools/walker/walker-tests.factor +++ b/basis/tools/walker/walker-tests.factor @@ -1,7 +1,7 @@ USING: tools.walker io io.streams.string kernel math math.private namespaces prettyprint sequences tools.test continuations math.parser threads arrays tools.walker.debug -generic.standard sequences.private kernel.private +generic.single sequences.private kernel.private tools.continuations accessors words ; IN: tools.walker.tests @@ -118,7 +118,7 @@ IN: tools.walker.tests \ breakpoint-test don't-step-into -[ f ] [ \ breakpoint-test optimized>> ] unit-test +[ f ] [ \ breakpoint-test optimized? ] unit-test [ { 3 } ] [ [ breakpoint-test ] test-walker ] unit-test diff --git a/basis/tuple-arrays/summary.txt b/basis/tuple-arrays/summary.txt new file mode 100755 index 0000000000..6f5c8b7244 --- /dev/null +++ b/basis/tuple-arrays/summary.txt @@ -0,0 +1 @@ +Efficient arrays of tuples with value semantics for elements diff --git a/basis/tuple-arrays/tags.txt b/basis/tuple-arrays/tags.txt new file mode 100755 index 0000000000..42d711b32b --- /dev/null +++ b/basis/tuple-arrays/tags.txt @@ -0,0 +1 @@ +collections diff --git a/basis/ui/backend/windows/windows.factor b/basis/ui/backend/windows/windows.factor index e405efb540..76c0dc4e01 100755 --- a/basis/ui/backend/windows/windows.factor +++ b/basis/ui/backend/windows/windows.factor @@ -6,15 +6,19 @@ ui.gadgets ui.gadgets.private ui.backend ui.clipboards ui.gadgets.worlds ui.gestures ui.event-loop io kernel math math.vectors namespaces make sequences strings vectors words windows.kernel32 windows.gdi32 windows.user32 windows.opengl32 -windows.messages windows.types windows.offscreen windows.nt windows +windows.messages windows.types windows.offscreen windows.nt threads libc combinators fry combinators.short-circuit continuations command-line shuffle opengl ui.render ascii math.bitwise locals accessors math.rectangles math.order ascii calendar -io.encodings.utf16n ; +io.encodings.utf16n windows.errors ; IN: ui.backend.windows SINGLETON: windows-ui-backend +: lo-word ( wparam -- lo ) *short ; inline +: hi-word ( wparam -- hi ) -16 shift lo-word ; inline +: >lo-hi ( WORD -- array ) [ lo-word ] [ hi-word ] bi 2array ; + : crlf>lf ( str -- str' ) CHAR: \r swap remove ; @@ -286,8 +290,6 @@ SYMBOL: nc-buttons message>button nc-buttons get swap [ push ] [ delete ] if ; -: >lo-hi ( WORD -- array ) [ lo-word ] [ hi-word ] bi 2array ; - : mouse-wheel ( wParam -- array ) >lo-hi [ sgn neg ] map ; : mouse-event>gesture ( uMsg -- button ) @@ -553,6 +555,54 @@ M: windows-ui-backend (with-ui) M: windows-ui-backend beep ( -- ) 0 MessageBeep drop ; +: fullscreen-RECT ( hwnd -- RECT ) + MONITOR_DEFAULTTONEAREST MonitorFromWindow + "MONITORINFOEX" dup length over set-MONITORINFOEX-cbSize + [ GetMonitorInfo win32-error=0/f ] keep MONITORINFOEX-rcMonitor ; + +: hwnd>RECT ( hwnd -- RECT ) + "RECT" [ GetWindowRect win32-error=0/f ] keep ; + +: fullscreen-flags ( -- n ) + { WS_CAPTION WS_BORDER WS_THICKFRAME } flags ; inline + +: enter-fullscreen ( world -- ) + handle>> hWnd>> + { + [ + GWL_STYLE GetWindowLong + fullscreen-flags unmask + ] + [ GWL_STYLE rot SetWindowLong win32-error=0/f ] + [ + HWND_TOP + over hwnd>RECT get-RECT-dimensions + SWP_FRAMECHANGED + SetWindowPos win32-error=0/f + ] + [ SW_MAXIMIZE ShowWindow win32-error=0/f ] + } cleave ; + +: exit-fullscreen ( world -- ) + handle>> hWnd>> + { + [ + GWL_STYLE GetWindowLong + fullscreen-flags bitor + ] + [ GWL_STYLE rot SetWindowLong win32-error=0/f ] + [ + f + over hwnd>RECT get-RECT-dimensions + { SWP_NOMOVE SWP_NOSIZE SWP_NOZORDER SWP_FRAMECHANGED } flags + SetWindowPos win32-error=0/f + ] + [ SW_RESTORE ShowWindow win32-error=0/f ] + } cleave ; + +M: windows-ui-backend set-fullscreen* ( ? world -- ) + swap [ enter-fullscreen ] [ exit-fullscreen ] if ; + windows-ui-backend ui-backend set-global [ "ui.tools" ] main-vocab-hook set-global diff --git a/basis/ui/gadgets/sliders/sliders.factor b/basis/ui/gadgets/sliders/sliders.factor index 6cfb83a49a..80829d7b66 100644 --- a/basis/ui/gadgets/sliders/sliders.factor +++ b/basis/ui/gadgets/sliders/sliders.factor @@ -53,8 +53,8 @@ CONSTANT: min-thumb-dim 30 [ slider-max* 1 max ] bi / ; -: slider>screen ( m slider -- n ) slider-scale * elevator-padding + ; -: screen>slider ( m slider -- n ) [ elevator-padding - ] dip slider-scale / ; +: slider>screen ( m slider -- n ) slider-scale * ; +: screen>slider ( m slider -- n ) slider-scale / ; M: slider model-changed nip elevator>> relayout-1 ; @@ -133,7 +133,7 @@ elevator H{ swap >>orientation ; : thumb-loc ( slider -- loc ) - [ slider-value ] keep slider>screen ; + [ slider-value ] keep slider>screen elevator-padding + ; : layout-thumb-loc ( thumb slider -- ) [ thumb-loc ] [ orientation>> ] bi n*v diff --git a/basis/ui/gadgets/tables/tables.factor b/basis/ui/gadgets/tables/tables.factor index d390b1e49b..ba3b5a2f78 100644 --- a/basis/ui/gadgets/tables/tables.factor +++ b/basis/ui/gadgets/tables/tables.factor @@ -46,14 +46,16 @@ mouse-index { takes-focus? initial: t } focused? ; -: ( rows renderer -- table ) - table new-line-gadget +: new-table ( rows renderer class -- table ) + new-line-gadget swap >>renderer swap >>model f >>selected-value sans-serif-font >>font focus-border-color >>focus-border-color - transparent >>column-line-color ; + transparent >>column-line-color ; inline + +:
( rows renderer -- table ) table new-table ; string os ( keysym -- string ) M: macosx keysym>string >upper ; -M: object keysym>string ; +M: object keysym>string dup length 1 = [ >lower ] when ; M: key-down gesture>string [ mods>> ] [ sym>> ] bi { { [ dup { [ length 1 = ] [ first LETTER? ] } 1&& ] [ [ S+ prefix ] dip ] } { [ dup " " = ] [ drop "SPACE" ] } - [ keysym>string ] + [ ] } cond - [ modifiers>string ] dip append ; + [ modifiers>string ] [ keysym>string ] bi* append ; M: button-up gesture>string [ diff --git a/basis/ui/tools/browser/browser.factor b/basis/ui/tools/browser/browser.factor index a493d5d7d2..1b8af1dd03 100644 --- a/basis/ui/tools/browser/browser.factor +++ b/basis/ui/tools/browser/browser.factor @@ -25,7 +25,10 @@ M: browser-gadget set-history-value : show-help ( link browser-gadget -- ) [ >link ] dip - [ [ add-recent ] [ history>> add-history ] bi* ] + [ + 2dup model>> value>> = + [ 2drop ] [ [ add-recent ] [ history>> add-history ] bi* ] if + ] [ model>> set-model ] 2bi ; diff --git a/basis/ui/tools/common/common.factor b/basis/ui/tools/common/common.factor index e581e72e24..95af20ec72 100644 --- a/basis/ui/tools/common/common.factor +++ b/basis/ui/tools/common/common.factor @@ -7,7 +7,7 @@ IN: ui.tools.common SYMBOL: tool-dims -tool-dims global [ H{ } clone or ] change-at +tool-dims [ H{ } clone ] initialize TUPLE: tool < track ; diff --git a/basis/ui/tools/error-list/error-list.factor b/basis/ui/tools/error-list/error-list.factor index aa23a8ebe1..704ae112e5 100644 --- a/basis/ui/tools/error-list/error-list.factor +++ b/basis/ui/tools/error-list/error-list.factor @@ -10,7 +10,7 @@ ui.gadgets.tables ui.gadgets.labeled ui.gadgets.tracks ui.gestures ui.operations ui.tools.browser ui.tools.common ui.gadgets.scrollers ui.tools.inspector ui.gadgets.status-bar ui.operations ui.gadgets.buttons ui.gadgets.borders ui.gadgets.packs -ui.gadgets.labels ui.baseline-alignment ui.images ui.tools.listener +ui.gadgets.labels ui.baseline-alignment ui.images compiler.errors tools.errors tools.errors.model ; IN: ui.tools.error-list diff --git a/basis/ui/tools/listener/completion/completion.factor b/basis/ui/tools/listener/completion/completion.factor index ba66121bc2..fdba400c3d 100644 --- a/basis/ui/tools/listener/completion/completion.factor +++ b/basis/ui/tools/listener/completion/completion.factor @@ -3,11 +3,10 @@ USING: accessors arrays assocs calendar colors colors.constants documents documents.elements fry kernel words sets splitting math math.vectors models.delay models.arrow combinators.short-circuit -parser present sequences tools.completion help.vocabs generic -generic.standard.engines.tuple fonts definitions.icons ui.images -ui.commands ui.operations ui.gadgets ui.gadgets.editors -ui.gadgets.glass ui.gadgets.scrollers ui.gadgets.tables -ui.gadgets.tracks ui.gadgets.labeled +parser present sequences tools.completion help.vocabs generic fonts +definitions.icons ui.images ui.commands ui.operations ui.gadgets +ui.gadgets.editors ui.gadgets.glass ui.gadgets.scrollers +ui.gadgets.tables ui.gadgets.tracks ui.gadgets.labeled ui.gadgets.worlds ui.gadgets.wrappers ui.gestures ui.pens.solid ui.tools.listener.history combinators vocabs ui.tools.listener.popups ; IN: ui.tools.listener.completion @@ -40,7 +39,7 @@ M: history-completion completion-quot drop '[ drop _ history-list ] ; GENERIC: completion-element ( completion-mode -- element ) -M: object completion-element drop one-word-elt ; +M: object completion-element drop word-start-elt ; M: history-completion completion-element drop one-line-elt ; GENERIC: completion-banner ( completion-mode -- string ) @@ -73,13 +72,13 @@ M: vocab-completion row-color drop vocab? COLOR: black COLOR: dark-gray ? ; : complete-IN:/USE:? ( tokens -- ? ) - 2 short tail* { "IN:" "USE:" } intersects? ; + 1 short head* 2 short tail* { "IN:" "USE:" } intersects? ; : chop-; ( seq -- seq' ) { ";" } split1-last [ ] [ ] ?if ; : complete-USING:? ( tokens -- ? ) - chop-; { "USING:" } intersects? ; + chop-; 1 short head* { "USING:" } intersects? ; : complete-CHAR:? ( tokens -- ? ) 2 short tail* "CHAR:" swap member? ; @@ -120,8 +119,6 @@ M: object completion-string present ; M: method-body completion-string method-completion-string ; -M: engine-word completion-string method-completion-string ; - GENERIC# accept-completion-hook 1 ( item popup -- ) : insert-completion ( item popup -- ) diff --git a/basis/ui/tools/listener/listener-tests.factor b/basis/ui/tools/listener/listener-tests.factor index 45b94344a6..e06e17374f 100644 --- a/basis/ui/tools/listener/listener-tests.factor +++ b/basis/ui/tools/listener/listener-tests.factor @@ -75,7 +75,7 @@ CONSTANT: text "Hello world.\nThis is a test." [ ] [ [ "interactor" get register-self - "interactor" get contents "promise" get fulfill + "interactor" get stream-contents "promise" get fulfill ] in-thread ] unit-test @@ -150,4 +150,4 @@ CONSTANT: text "Hello world.\nThis is a test." [ ] [ "l" set ] unit-test [ ] [ "l" get com-scroll-up ] unit-test -[ ] [ "l" get com-scroll-down ] unit-test \ No newline at end of file +[ ] [ "l" get com-scroll-down ] unit-test diff --git a/basis/ui/ui.factor b/basis/ui/ui.factor index 8be486cb1a..09403cb2d2 100644 --- a/basis/ui/ui.factor +++ b/basis/ui/ui.factor @@ -28,7 +28,7 @@ SYMBOL: windows [ [ length 1- dup 1- ] keep exchange ] [ drop ] if ; : unregister-window ( handle -- ) - windows global [ [ first = not ] with filter ] change-at ; + windows [ [ first = not ] with filter ] change-global ; : raised-window ( world -- ) windows get-global diff --git a/basis/unix/unix.factor b/basis/unix/unix.factor index a6a0147504..10fb2ad64f 100644 --- a/basis/unix/unix.factor +++ b/basis/unix/unix.factor @@ -194,6 +194,7 @@ FUNCTION: int setsockopt ( int s, int level, int optname, void* optval, socklen_ FUNCTION: int setuid ( uid_t uid ) ; FUNCTION: int socket ( int domain, int type, int protocol ) ; FUNCTION: int symlink ( char* path1, char* path2 ) ; +FUNCTION: int link ( char* path1, char* path2 ) ; FUNCTION: int system ( char* command ) ; FUNCTION: int unlink ( char* path ) ; diff --git a/basis/windows/advapi32/advapi32.factor b/basis/windows/advapi32/advapi32.factor index 5b62f54795..fd037cb2a0 100644 --- a/basis/windows/advapi32/advapi32.factor +++ b/basis/windows/advapi32/advapi32.factor @@ -350,35 +350,46 @@ CONSTANT: TOKEN_ADJUST_DEFAULT HEX: 0080 TOKEN_ADJUST_DEFAULT } flags ; foldable -CONSTANT: HKEY_CLASSES_ROOT 1 -CONSTANT: HKEY_CURRENT_CONFIG 2 -CONSTANT: HKEY_CURRENT_USER 3 -CONSTANT: HKEY_LOCAL_MACHINE 4 -CONSTANT: HKEY_USERS 5 +CONSTANT: HKEY_CLASSES_ROOT HEX: 80000000 +CONSTANT: HKEY_CURRENT_USER HEX: 80000001 +CONSTANT: HKEY_LOCAL_MACHINE HEX: 80000002 +CONSTANT: HKEY_USERS HEX: 80000003 +CONSTANT: HKEY_PERFORMANCE_DATA HEX: 80000004 +CONSTANT: HKEY_CURRENT_CONFIG HEX: 80000005 +CONSTANT: HKEY_DYN_DATA HEX: 80000006 +CONSTANT: HKEY_PERFORMANCE_TEXT HEX: 80000050 +CONSTANT: HKEY_PERFORMANCE_NLSTEXT HEX: 80000060 -CONSTANT: KEY_ALL_ACCESS HEX: 0001 -CONSTANT: KEY_CREATE_LINK HEX: 0002 +CONSTANT: KEY_QUERY_VALUE HEX: 0001 +CONSTANT: KEY_SET_VALUE HEX: 0002 CONSTANT: KEY_CREATE_SUB_KEY HEX: 0004 CONSTANT: KEY_ENUMERATE_SUB_KEYS HEX: 0008 -CONSTANT: KEY_EXECUTE HEX: 0010 -CONSTANT: KEY_NOTIFY HEX: 0020 -CONSTANT: KEY_QUERY_VALUE HEX: 0040 -CONSTANT: KEY_READ HEX: 0080 -CONSTANT: KEY_SET_VALUE HEX: 0100 -CONSTANT: KEY_WOW64_64KEY HEX: 0200 -CONSTANT: KEY_WOW64_32KEY HEX: 0400 -CONSTANT: KEY_WRITE HEX: 0800 +CONSTANT: KEY_NOTIFY HEX: 0010 +CONSTANT: KEY_CREATE_LINK HEX: 0020 +CONSTANT: KEY_READ HEX: 20019 +CONSTANT: KEY_WOW64_32KEY HEX: 0200 +CONSTANT: KEY_WOW64_64KEY HEX: 0100 +CONSTANT: KEY_WRITE HEX: 20006 +CONSTANT: KEY_EXECUTE KEY_READ +CONSTANT: KEY_ALL_ACCESS HEX: F003F -CONSTANT: REG_BINARY 1 -CONSTANT: REG_DWORD 2 -CONSTANT: REG_EXPAND_SZ 3 -CONSTANT: REG_MULTI_SZ 4 -CONSTANT: REG_QWORD 5 -CONSTANT: REG_SZ 6 +CONSTANT: REG_NONE 0 +CONSTANT: REG_SZ 1 +CONSTANT: REG_EXPAND_SZ 2 +CONSTANT: REG_BINARY 3 +CONSTANT: REG_DWORD 4 +CONSTANT: REG_DWORD_LITTLE_ENDIAN 4 +CONSTANT: REG_DWORD_BIG_ENDIAN 5 +CONSTANT: REG_LINK 6 +CONSTANT: REG_MULTI_SZ 7 +CONSTANT: REG_RESOURCE_LIST 8 +CONSTANT: REG_FULL_RESOURCE_DESCRIPTOR 9 +CONSTANT: REG_RESOURCE_REQUIREMENTS_LIST 10 +CONSTANT: REG_QWORD 11 +CONSTANT: REG_QWORD_LITTLE_ENDIAN 11 TYPEDEF: DWORD REGSAM - ! : I_ScGetCurrentGroupStateW ; ! : A_SHAFinal ; ! : A_SHAInit ; @@ -874,7 +885,7 @@ FUNCTION: BOOL OpenThreadToken ( HANDLE ThreadHandle, DWORD DesiredAccess, BOOL ! : ReadEncryptedFileRaw ; ! : ReadEventLogA ; ! : ReadEventLogW ; -! : RegCloseKey ; +FUNCTION: LONG RegCloseKey ( HKEY hKey ) ; ! : RegConnectRegistryA ; ! : RegConnectRegistryW ; ! : RegCreateKeyA ; @@ -883,15 +894,52 @@ FUNCTION: LONG RegCreateKeyExW ( HKEY hKey, LPCTSTR lpSubKey, DWORD Reserved, LP ! : RegCreateKeyW ! : RegDeleteKeyA ; ! : RegDeleteKeyW ; + +FUNCTION: LONG RegDeleteKeyExW ( + HKEY hKey, + LPCTSTR lpSubKey, + DWORD Reserved, + LPTSTR lpClass, + DWORD dwOptions, + REGSAM samDesired, + LPSECURITY_ATTRIBUTES lpSecurityAttributes, + PHKEY phkResult, + LPDWORD lpdwDisposition + ) ; + +ALIAS: RegDeleteKeyEx RegDeleteKeyExW + ! : RegDeleteValueA ; ! : RegDeleteValueW ; ! : RegDisablePredefinedCache ; ! : RegEnumKeyA ; ! : RegEnumKeyExA ; -! : RegEnumKeyExW ; +FUNCTION: LONG RegEnumKeyExW ( + HKEY hKey, + DWORD dwIndex, + LPTSTR lpName, + LPDWORD lpcName, + LPDWORD lpReserved, + LPTSTR lpClass, + LPDWORD lpcClass, + PFILETIME lpftLastWriteTime + ) ; ! : RegEnumKeyW ; ! : RegEnumValueA ; -! : RegEnumValueW ; + +FUNCTION: LONG RegEnumValueW ( + HKEY hKey, + DWORD dwIndex, + LPTSTR lpValueName, + LPDWORD lpcchValueName, + LPDWORD lpReserved, + LPDWORD lpType, + LPBYTE lpData, + LPDWORD lpcbData + ) ; + +ALIAS: RegEnumValue RegEnumValueW + ! : RegFlushKey ; ! : RegGetKeySecurity ; ! : RegLoadKeyA ; @@ -900,17 +948,33 @@ FUNCTION: LONG RegCreateKeyExW ( HKEY hKey, LPCTSTR lpSubKey, DWORD Reserved, LP FUNCTION: LONG RegOpenCurrentUser ( REGSAM samDesired, PHKEY phkResult ) ; ! : RegOpenKeyA ; ! : RegOpenKeyExA ; -! : RegOpenKeyExW ; +FUNCTION: LONG RegOpenKeyExW ( HKEY hKey, LPCTSTR lpSubKey, DWORD ulOptions, REGSAM samDesired, PHKEY phkResult ) ; +ALIAS: RegOpenKeyEx RegOpenKeyExW ! : RegOpenKeyW ; ! : RegOpenUserClassesRoot ; ! : RegOverridePredefKey ; ! : RegQueryInfoKeyA ; -! : RegQueryInfoKeyW ; +FUNCTION: LONG RegQueryInfoKeyW ( + HKEY hKey, + LPTSTR lpClass, + LPDWORD lpcClass, + LPDWORD lpReserved, + LPDWORD lpcSubKeys, + LPDWORD lpcMaxSubKeyLen, + LPDWORD lpcMaxClassLen, + LPDWORD lpcValues, + LPDWORD lpcMaxValueNameLen, + LPDWORD lpcMaxValueLen, + LPDWORD lpcbSecurityDescriptor, + PFILETIME lpftLastWriteTime + ) ; +ALIAS: RegQueryInfoKey RegQueryInfoKeyW ! : RegQueryMultipleValuesA ; ! : RegQueryMultipleValuesW ; ! : RegQueryValueA ; ! : RegQueryValueExA ; -FUNCTION: LONG RegQueryValueExW ( HKEY hKey, LPCTSTR lpValueName, LPWORD lpReserved, LPDWORD lpType, LPBYTE lpData, LPDWORD lpcbData ) ; +FUNCTION: LONG RegQueryValueExW ( HKEY hKey, LPCTSTR lpValueName, LPDWORD lpReserved, LPDWORD lpType, LPBYTE lpData, LPDWORD lpcbData ) ; +ALIAS: RegQueryValueEx RegQueryValueExW ! : RegQueryValueW ; ! : RegReplaceKeyA ; ! : RegReplaceKeyW ; diff --git a/basis/windows/dinput/constants/constants.factor b/basis/windows/dinput/constants/constants.factor index 0f95c6d683..74238abed2 100755 --- a/basis/windows/dinput/constants/constants.factor +++ b/basis/windows/dinput/constants/constants.factor @@ -842,7 +842,7 @@ SYMBOLS: [ define-constants ] "windows.dinput.constants" add-init-hook : uninitialize ( variable quot -- ) - [ global ] dip '[ _ when* f ] change-at ; inline + '[ _ when* f ] change-global ; inline : free-dinput-constants ( -- ) { diff --git a/basis/windows/errors/errors-tests.factor b/basis/windows/errors/errors-tests.factor new file mode 100755 index 0000000000..96edb8a379 --- /dev/null +++ b/basis/windows/errors/errors-tests.factor @@ -0,0 +1,6 @@ +! Copyright (C) 2009 Doug Coleman. +! See http://factorcode.org/license.txt for BSD license. +USING: tools.test windows.errors strings ; +IN: windows.errors.tests + +[ t ] [ 0 n>win32-error-string string? ] unit-test diff --git a/basis/windows/errors/errors.factor b/basis/windows/errors/errors.factor index 56bba768de..e08704d469 100644 --- a/basis/windows/errors/errors.factor +++ b/basis/windows/errors/errors.factor @@ -1,9 +1,752 @@ -IN: windows.errors +USING: alien.c-types kernel locals math math.bitwise +windows.kernel32 sequences byte-arrays unicode.categories +io.encodings.string io.encodings.utf16n alien.strings +arrays ; +IN: windows.errors -CONSTANT: ERROR_SUCCESS 0 -CONSTANT: ERROR_NO_MORE_FILES 18 -CONSTANT: ERROR_HANDLE_EOF 38 -CONSTANT: ERROR_BROKEN_PIPE 109 -CONSTANT: ERROR_ENVVAR_NOT_FOUND 203 -CONSTANT: ERROR_IO_INCOMPLETE 996 -CONSTANT: ERROR_IO_PENDING 997 +CONSTANT: ERROR_SUCCESS 0 +CONSTANT: ERROR_INVALID_FUNCTION 1 +CONSTANT: ERROR_FILE_NOT_FOUND 2 +CONSTANT: ERROR_PATH_NOT_FOUND 3 +CONSTANT: ERROR_TOO_MANY_OPEN_FILES 4 +CONSTANT: ERROR_ACCESS_DENIED 5 +CONSTANT: ERROR_INVALID_HANDLE 6 +CONSTANT: ERROR_ARENA_TRASHED 7 +CONSTANT: ERROR_NOT_ENOUGH_MEMORY 8 +CONSTANT: ERROR_INVALID_BLOCK 9 +CONSTANT: ERROR_BAD_ENVIRONMENT 10 +CONSTANT: ERROR_BAD_FORMAT 11 +CONSTANT: ERROR_INVALID_ACCESS 12 +CONSTANT: ERROR_INVALID_DATA 13 +CONSTANT: ERROR_OUTOFMEMORY 14 +CONSTANT: ERROR_INVALID_DRIVE 15 +CONSTANT: ERROR_CURRENT_DIRECTORY 16 +CONSTANT: ERROR_NOT_SAME_DEVICE 17 +CONSTANT: ERROR_NO_MORE_FILES 18 +CONSTANT: ERROR_WRITE_PROTECT 19 +CONSTANT: ERROR_BAD_UNIT 20 +CONSTANT: ERROR_NOT_READY 21 +CONSTANT: ERROR_BAD_COMMAND 22 +CONSTANT: ERROR_CRC 23 +CONSTANT: ERROR_BAD_LENGTH 24 +CONSTANT: ERROR_SEEK 25 +CONSTANT: ERROR_NOT_DOS_DISK 26 +CONSTANT: ERROR_SECTOR_NOT_FOUND 27 +CONSTANT: ERROR_OUT_OF_PAPER 28 +CONSTANT: ERROR_WRITE_FAULT 29 +CONSTANT: ERROR_READ_FAULT 30 +CONSTANT: ERROR_GEN_FAILURE 31 +CONSTANT: ERROR_SHARING_VIOLATION 32 +CONSTANT: ERROR_LOCK_VIOLATION 33 +CONSTANT: ERROR_WRONG_DISK 34 +CONSTANT: ERROR_SHARING_BUFFER_EXCEEDED 36 +CONSTANT: ERROR_HANDLE_EOF 38 +CONSTANT: ERROR_HANDLE_DISK_FULL 39 +CONSTANT: ERROR_NOT_SUPPORTED 50 +CONSTANT: ERROR_REM_NOT_LIST 51 +CONSTANT: ERROR_DUP_NAME 52 +CONSTANT: ERROR_BAD_NETPATH 53 +CONSTANT: ERROR_NETWORK_BUSY 54 +CONSTANT: ERROR_DEV_NOT_EXIST 55 +CONSTANT: ERROR_TOO_MANY_CMDS 56 +CONSTANT: ERROR_ADAP_HDW_ERR 57 +CONSTANT: ERROR_BAD_NET_RESP 58 +CONSTANT: ERROR_UNEXP_NET_ERR 59 +CONSTANT: ERROR_BAD_REM_ADAP 60 +CONSTANT: ERROR_PRINTQ_FULL 61 +CONSTANT: ERROR_NO_SPOOL_SPACE 62 +CONSTANT: ERROR_PRINT_CANCELLED 63 +CONSTANT: ERROR_NETNAME_DELETED 64 +CONSTANT: ERROR_NETWORK_ACCESS_DENIED 65 +CONSTANT: ERROR_BAD_DEV_TYPE 66 +CONSTANT: ERROR_BAD_NET_NAME 67 +CONSTANT: ERROR_TOO_MANY_NAMES 68 +CONSTANT: ERROR_TOO_MANY_SESS 69 +CONSTANT: ERROR_SHARING_PAUSED 70 +CONSTANT: ERROR_REQ_NOT_ACCEP 71 +CONSTANT: ERROR_REDIR_PAUSED 72 +CONSTANT: ERROR_FILE_EXISTS 80 +CONSTANT: ERROR_CANNOT_MAKE 82 +CONSTANT: ERROR_FAIL_I24 83 +CONSTANT: ERROR_OUT_OF_STRUCTURES 84 +CONSTANT: ERROR_ALREADY_ASSIGNED 85 +CONSTANT: ERROR_INVALID_PASSWORD 86 +CONSTANT: ERROR_INVALID_PARAMETER 87 +CONSTANT: ERROR_NET_WRITE_FAULT 88 +CONSTANT: ERROR_NO_PROC_SLOTS 89 +CONSTANT: ERROR_TOO_MANY_SEMAPHORES 100 +CONSTANT: ERROR_EXCL_SEM_ALREADY_OWNED 101 +CONSTANT: ERROR_SEM_IS_SET 102 +CONSTANT: ERROR_TOO_MANY_SEM_REQUESTS 103 +CONSTANT: ERROR_INVALID_AT_INTERRUPT_TIME 104 +CONSTANT: ERROR_SEM_OWNER_DIED 105 +CONSTANT: ERROR_SEM_USER_LIMIT 106 +CONSTANT: ERROR_DISK_CHANGE 107 +CONSTANT: ERROR_DRIVE_LOCKED 108 +CONSTANT: ERROR_BROKEN_PIPE 109 +CONSTANT: ERROR_OPEN_FAILED 110 +CONSTANT: ERROR_BUFFER_OVERFLOW 111 +CONSTANT: ERROR_DISK_FULL 112 +CONSTANT: ERROR_NO_MORE_SEARCH_HANDLES 113 +CONSTANT: ERROR_INVALID_TARGET_HANDLE 114 +CONSTANT: ERROR_INVALID_CATEGORY 117 +CONSTANT: ERROR_INVALID_VERIFY_SWITCH 118 +CONSTANT: ERROR_BAD_DRIVER_LEVEL 119 +CONSTANT: ERROR_CALL_NOT_IMPLEMENTED 120 +CONSTANT: ERROR_SEM_TIMEOUT 121 +CONSTANT: ERROR_INSUFFICIENT_BUFFER 122 +CONSTANT: ERROR_INVALID_NAME 123 +CONSTANT: ERROR_INVALID_LEVEL 124 +CONSTANT: ERROR_NO_VOLUME_LABEL 125 +CONSTANT: ERROR_MOD_NOT_FOUND 126 +CONSTANT: ERROR_PROC_NOT_FOUND 127 +CONSTANT: ERROR_WAIT_NO_CHILDREN 128 +CONSTANT: ERROR_CHILD_NOT_COMPLETE 129 +CONSTANT: ERROR_DIRECT_ACCESS_HANDLE 130 +CONSTANT: ERROR_NEGATIVE_SEEK 131 +CONSTANT: ERROR_SEEK_ON_DEVICE 132 +CONSTANT: ERROR_IS_JOIN_TARGET 133 +CONSTANT: ERROR_IS_JOINED 134 +CONSTANT: ERROR_IS_SUBSTED 135 +CONSTANT: ERROR_NOT_JOINED 136 +CONSTANT: ERROR_NOT_SUBSTED 137 +CONSTANT: ERROR_JOIN_TO_JOIN 138 +CONSTANT: ERROR_SUBST_TO_SUBST 139 +CONSTANT: ERROR_JOIN_TO_SUBST 140 +CONSTANT: ERROR_SUBST_TO_JOIN 141 +CONSTANT: ERROR_BUSY_DRIVE 142 +CONSTANT: ERROR_SAME_DRIVE 143 +CONSTANT: ERROR_DIR_NOT_ROOT 144 +CONSTANT: ERROR_DIR_NOT_EMPTY 145 +CONSTANT: ERROR_IS_SUBST_PATH 146 +CONSTANT: ERROR_IS_JOIN_PATH 147 +CONSTANT: ERROR_PATH_BUSY 148 +CONSTANT: ERROR_IS_SUBST_TARGET 149 +CONSTANT: ERROR_SYSTEM_TRACE 150 +CONSTANT: ERROR_INVALID_EVENT_COUNT 151 +CONSTANT: ERROR_TOO_MANY_MUXWAITERS 152 +CONSTANT: ERROR_INVALID_LIST_FORMAT 153 +CONSTANT: ERROR_LABEL_TOO_LONG 154 +CONSTANT: ERROR_TOO_MANY_TCBS 155 +CONSTANT: ERROR_SIGNAL_REFUSED 156 +CONSTANT: ERROR_DISCARDED 157 +CONSTANT: ERROR_NOT_LOCKED 158 +CONSTANT: ERROR_BAD_THREADID_ADDR 159 +CONSTANT: ERROR_BAD_ARGUMENTS 160 +CONSTANT: ERROR_BAD_PATHNAME 161 +CONSTANT: ERROR_SIGNAL_PENDING 162 +CONSTANT: ERROR_MAX_THRDS_REACHED 164 +CONSTANT: ERROR_LOCK_FAILED 167 +CONSTANT: ERROR_BUSY 170 +CONSTANT: ERROR_CANCEL_VIOLATION 173 +CONSTANT: ERROR_ATOMIC_LOCKS_NOT_SUPPORTED 174 +CONSTANT: ERROR_INVALID_SEGMENT_NUMBER 180 +CONSTANT: ERROR_INVALID_ORDINAL 182 +CONSTANT: ERROR_ALREADY_EXISTS 183 +CONSTANT: ERROR_INVALID_FLAG_NUMBER 186 +CONSTANT: ERROR_SEM_NOT_FOUND 187 +CONSTANT: ERROR_INVALID_STARTING_CODESEG 188 +CONSTANT: ERROR_INVALID_STACKSEG 189 +CONSTANT: ERROR_INVALID_MODULETYPE 190 +CONSTANT: ERROR_INVALID_EXE_SIGNATURE 191 +CONSTANT: ERROR_EXE_MARKED_INVALID 192 +CONSTANT: ERROR_BAD_EXE_FORMAT 193 +CONSTANT: ERROR_ITERATED_DATA_EXCEEDS_64k 194 +CONSTANT: ERROR_INVALID_MINALLOCSIZE 195 +CONSTANT: ERROR_DYNLINK_FROM_INVALID_RING 196 +CONSTANT: ERROR_IOPL_NOT_ENABLED 197 +CONSTANT: ERROR_INVALID_SEGDPL 198 +CONSTANT: ERROR_AUTODATASEG_EXCEEDS_64k 199 +CONSTANT: ERROR_RING2SEG_MUST_BE_MOVABLE 200 +CONSTANT: ERROR_RELOC_CHAIN_XEEDS_SEGLIM 201 +CONSTANT: ERROR_INFLOOP_IN_RELOC_CHAIN 202 +CONSTANT: ERROR_ENVVAR_NOT_FOUND 203 +CONSTANT: ERROR_NO_SIGNAL_SENT 205 +CONSTANT: ERROR_FILENAME_EXCED_RANGE 206 +CONSTANT: ERROR_RING2_STACK_IN_USE 207 +CONSTANT: ERROR_META_EXPANSION_TOO_LONG 208 +CONSTANT: ERROR_INVALID_SIGNAL_NUMBER 209 +CONSTANT: ERROR_THREAD_1_INACTIVE 210 +CONSTANT: ERROR_LOCKED 212 +CONSTANT: ERROR_TOO_MANY_MODULES 214 +CONSTANT: ERROR_NESTING_NOT_ALLOWED 215 +CONSTANT: ERROR_EXE_MACHINE_TYPE_MISMATCH 216 +CONSTANT: ERROR_BAD_PIPE 230 +CONSTANT: ERROR_PIPE_BUSY 231 +CONSTANT: ERROR_NO_DATA 232 +CONSTANT: ERROR_PIPE_NOT_CONNECTED 233 +CONSTANT: ERROR_MORE_DATA 234 +CONSTANT: ERROR_VC_DISCONNECTED 240 +CONSTANT: ERROR_INVALID_EA_NAME 254 +CONSTANT: ERROR_EA_LIST_INCONSISTENT 255 +CONSTANT: ERROR_NO_MORE_ITEMS 259 +CONSTANT: ERROR_CANNOT_COPY 266 +CONSTANT: ERROR_DIRECTORY 267 +CONSTANT: ERROR_EAS_DIDNT_FIT 275 +CONSTANT: ERROR_EA_FILE_CORRUPT 276 +CONSTANT: ERROR_EA_TABLE_FULL 277 +CONSTANT: ERROR_INVALID_EA_HANDLE 278 +CONSTANT: ERROR_EAS_NOT_SUPPORTED 282 +CONSTANT: ERROR_NOT_OWNER 288 +CONSTANT: ERROR_TOO_MANY_POSTS 298 +CONSTANT: ERROR_PARTIAL_COPY 299 +CONSTANT: ERROR_MR_MID_NOT_FOUND 317 +CONSTANT: ERROR_INVALID_ADDRESS 487 +CONSTANT: ERROR_ARITHMETIC_OVERFLOW 534 +CONSTANT: ERROR_PIPE_CONNECTED 535 +CONSTANT: ERROR_PIPE_LISTENING 536 +CONSTANT: ERROR_EA_ACCESS_DENIED 994 +CONSTANT: ERROR_OPERATION_ABORTED 995 +CONSTANT: ERROR_IO_INCOMPLETE 996 +CONSTANT: ERROR_IO_PENDING 997 +CONSTANT: ERROR_NOACCESS 998 +CONSTANT: ERROR_SWAPERROR 999 +CONSTANT: ERROR_STACK_OVERFLOW 1001 +CONSTANT: ERROR_INVALID_MESSAGE 1002 +CONSTANT: ERROR_CAN_NOT_COMPLETE 1003 +CONSTANT: ERROR_INVALID_FLAGS 1004 +CONSTANT: ERROR_UNRECOGNIZED_VOLUME 1005 +CONSTANT: ERROR_FILE_INVALID 1006 +CONSTANT: ERROR_FULLSCREEN_MODE 1007 +CONSTANT: ERROR_NO_TOKEN 1008 +CONSTANT: ERROR_BADDB 1009 +CONSTANT: ERROR_BADKEY 1010 +CONSTANT: ERROR_CANTOPEN 1011 +CONSTANT: ERROR_CANTREAD 1012 +CONSTANT: ERROR_CANTWRITE 1013 +CONSTANT: ERROR_REGISTRY_RECOVERED 1014 +CONSTANT: ERROR_REGISTRY_CORRUPT 1015 +CONSTANT: ERROR_REGISTRY_IO_FAILED 1016 +CONSTANT: ERROR_NOT_REGISTRY_FILE 1017 +CONSTANT: ERROR_KEY_DELETED 1018 +CONSTANT: ERROR_NO_LOG_SPACE 1019 +CONSTANT: ERROR_KEY_HAS_CHILDREN 1020 +CONSTANT: ERROR_CHILD_MUST_BE_VOLATILE 1021 +CONSTANT: ERROR_NOTIFY_ENUM_DIR 1022 +CONSTANT: ERROR_DEPENDENT_SERVICES_RUNNING 1051 +CONSTANT: ERROR_INVALID_SERVICE_CONTROL 1052 +CONSTANT: ERROR_SERVICE_REQUEST_TIMEOUT 1053 +CONSTANT: ERROR_SERVICE_NO_THREAD 1054 +CONSTANT: ERROR_SERVICE_DATABASE_LOCKED 1055 +CONSTANT: ERROR_SERVICE_ALREADY_RUNNING 1056 +CONSTANT: ERROR_INVALID_SERVICE_ACCOUNT 1057 +CONSTANT: ERROR_SERVICE_DISABLED 1058 +CONSTANT: ERROR_CIRCULAR_DEPENDENCY 1059 +CONSTANT: ERROR_SERVICE_DOES_NOT_EXIST 1060 +CONSTANT: ERROR_SERVICE_CANNOT_ACCEPT_CTRL 1061 +CONSTANT: ERROR_SERVICE_NOT_ACTIVE 1062 +CONSTANT: ERROR_FAILED_SERVICE_CONTROLLER_CONNECT 1063 +CONSTANT: ERROR_EXCEPTION_IN_SERVICE 1064 +CONSTANT: ERROR_DATABASE_DOES_NOT_EXIST 1065 +CONSTANT: ERROR_SERVICE_SPECIFIC_ERROR 1066 +CONSTANT: ERROR_PROCESS_ABORTED 1067 +CONSTANT: ERROR_SERVICE_DEPENDENCY_FAIL 1068 +CONSTANT: ERROR_SERVICE_LOGON_FAILED 1069 +CONSTANT: ERROR_SERVICE_START_HANG 1070 +CONSTANT: ERROR_INVALID_SERVICE_LOCK 1071 +CONSTANT: ERROR_SERVICE_MARKED_FOR_DELETE 1072 +CONSTANT: ERROR_SERVICE_EXISTS 1073 +CONSTANT: ERROR_ALREADY_RUNNING_LKG 1074 +CONSTANT: ERROR_SERVICE_DEPENDENCY_DELETED 1075 +CONSTANT: ERROR_BOOT_ALREADY_ACCEPTED 1076 +CONSTANT: ERROR_SERVICE_NEVER_STARTED 1077 +CONSTANT: ERROR_DUPLICATE_SERVICE_NAME 1078 +CONSTANT: ERROR_DIFFERENT_SERVICE_ACCOUNT 1079 +CONSTANT: ERROR_END_OF_MEDIA 1100 +CONSTANT: ERROR_FILEMARK_DETECTED 1101 +CONSTANT: ERROR_BEGINNING_OF_MEDIA 1102 +CONSTANT: ERROR_SETMARK_DETECTED 1103 +CONSTANT: ERROR_NO_DATA_DETECTED 1104 +CONSTANT: ERROR_PARTITION_FAILURE 1105 +CONSTANT: ERROR_INVALID_BLOCK_LENGTH 1106 +CONSTANT: ERROR_DEVICE_NOT_PARTITIONED 1107 +CONSTANT: ERROR_UNABLE_TO_LOCK_MEDIA 1108 +CONSTANT: ERROR_UNABLE_TO_UNLOAD_MEDIA 1109 +CONSTANT: ERROR_MEDIA_CHANGED 1110 +CONSTANT: ERROR_BUS_RESET 1111 +CONSTANT: ERROR_NO_MEDIA_IN_DRIVE 1112 +CONSTANT: ERROR_NO_UNICODE_TRANSLATION 1113 +CONSTANT: ERROR_DLL_INIT_FAILED 1114 +CONSTANT: ERROR_SHUTDOWN_IN_PROGRESS 1115 +CONSTANT: ERROR_NO_SHUTDOWN_IN_PROGRESS 1116 +CONSTANT: ERROR_IO_DEVICE 1117 +CONSTANT: ERROR_SERIAL_NO_DEVICE 1118 +CONSTANT: ERROR_IRQ_BUSY 1119 +CONSTANT: ERROR_MORE_WRITES 1120 +CONSTANT: ERROR_COUNTER_TIMEOUT 1121 +CONSTANT: ERROR_FLOPPY_ID_MARK_NOT_FOUND 1122 +CONSTANT: ERROR_FLOPPY_WRONG_CYLINDER 1123 +CONSTANT: ERROR_FLOPPY_UNKNOWN_ERROR 1124 +CONSTANT: ERROR_FLOPPY_BAD_REGISTERS 1125 +CONSTANT: ERROR_DISK_RECALIBRATE_FAILED 1126 +CONSTANT: ERROR_DISK_OPERATION_FAILED 1127 +CONSTANT: ERROR_DISK_RESET_FAILED 1128 +CONSTANT: ERROR_EOM_OVERFLOW 1129 +CONSTANT: ERROR_NOT_ENOUGH_SERVER_MEMORY 1130 +CONSTANT: ERROR_POSSIBLE_DEADLOCK 1131 +CONSTANT: ERROR_MAPPED_ALIGNMENT 1132 +CONSTANT: ERROR_SET_POWER_STATE_VETOED 1140 +CONSTANT: ERROR_SET_POWER_STATE_FAILED 1141 +CONSTANT: ERROR_TOO_MANY_LINKS 1142 +CONSTANT: ERROR_OLD_WIN_VERSION 1150 +CONSTANT: ERROR_APP_WRONG_OS 1151 +CONSTANT: ERROR_SINGLE_INSTANCE_APP 1152 +CONSTANT: ERROR_RMODE_APP 1153 +CONSTANT: ERROR_INVALID_DLL 1154 +CONSTANT: ERROR_NO_ASSOCIATION 1155 +CONSTANT: ERROR_DDE_FAIL 1156 +CONSTANT: ERROR_DLL_NOT_FOUND 1157 +CONSTANT: ERROR_BAD_DEVICE 1200 +CONSTANT: ERROR_CONNECTION_UNAVAIL 1201 +CONSTANT: ERROR_DEVICE_ALREADY_REMEMBERED 1202 +CONSTANT: ERROR_NO_NET_OR_BAD_PATH 1203 +CONSTANT: ERROR_BAD_PROVIDER 1204 +CONSTANT: ERROR_CANNOT_OPEN_PROFILE 1205 +CONSTANT: ERROR_BAD_PROFILE 1206 +CONSTANT: ERROR_NOT_CONTAINER 1207 +CONSTANT: ERROR_EXTENDED_ERROR 1208 +CONSTANT: ERROR_INVALID_GROUPNAME 1209 +CONSTANT: ERROR_INVALID_COMPUTERNAME 1210 +CONSTANT: ERROR_INVALID_EVENTNAME 1211 +CONSTANT: ERROR_INVALID_DOMAINNAME 1212 +CONSTANT: ERROR_INVALID_SERVICENAME 1213 +CONSTANT: ERROR_INVALID_NETNAME 1214 +CONSTANT: ERROR_INVALID_SHARENAME 1215 +CONSTANT: ERROR_INVALID_PASSWORDNAME 1216 +CONSTANT: ERROR_INVALID_MESSAGENAME 1217 +CONSTANT: ERROR_INVALID_MESSAGEDEST 1218 +CONSTANT: ERROR_SESSION_CREDENTIAL_CONFLICT 1219 +CONSTANT: ERROR_REMOTE_SESSION_LIMIT_EXCEEDED 1220 +CONSTANT: ERROR_DUP_DOMAINNAME 1221 +CONSTANT: ERROR_NO_NETWORK 1222 +CONSTANT: ERROR_CANCELLED 1223 +CONSTANT: ERROR_USER_MAPPED_FILE 1224 +CONSTANT: ERROR_CONNECTION_REFUSED 1225 +CONSTANT: ERROR_GRACEFUL_DISCONNECT 1226 +CONSTANT: ERROR_ADDRESS_ALREADY_ASSOCIATED 1227 +CONSTANT: ERROR_ADDRESS_NOT_ASSOCIATED 1228 +CONSTANT: ERROR_CONNECTION_INVALID 1229 +CONSTANT: ERROR_CONNECTION_ACTIVE 1230 +CONSTANT: ERROR_NETWORK_UNREACHABLE 1231 +CONSTANT: ERROR_HOST_UNREACHABLE 1232 +CONSTANT: ERROR_PROTOCOL_UNREACHABLE 1233 +CONSTANT: ERROR_PORT_UNREACHABLE 1234 +CONSTANT: ERROR_REQUEST_ABORTED 1235 +CONSTANT: ERROR_CONNECTION_ABORTED 1236 +CONSTANT: ERROR_RETRY 1237 +CONSTANT: ERROR_CONNECTION_COUNT_LIMIT 1238 +CONSTANT: ERROR_LOGIN_TIME_RESTRICTION 1239 +CONSTANT: ERROR_LOGIN_WKSTA_RESTRICTION 1240 +CONSTANT: ERROR_INCORRECT_ADDRESS 1241 +CONSTANT: ERROR_ALREADY_REGISTERED 1242 +CONSTANT: ERROR_SERVICE_NOT_FOUND 1243 +CONSTANT: ERROR_NOT_AUTHENTICATED 1244 +CONSTANT: ERROR_NOT_LOGGED_ON 1245 +CONSTANT: ERROR_CONTINUE 1246 +CONSTANT: ERROR_ALREADY_INITIALIZED 1247 +CONSTANT: ERROR_NO_MORE_DEVICES 1248 +CONSTANT: ERROR_NOT_ALL_ASSIGNED 1300 +CONSTANT: ERROR_SOME_NOT_MAPPED 1301 +CONSTANT: ERROR_NO_QUOTAS_FOR_ACCOUNT 1302 +CONSTANT: ERROR_LOCAL_USER_SESSION_KEY 1303 +CONSTANT: ERROR_NULL_LM_PASSWORD 1304 +CONSTANT: ERROR_UNKNOWN_REVISION 1305 +CONSTANT: ERROR_REVISION_MISMATCH 1306 +CONSTANT: ERROR_INVALID_OWNER 1307 +CONSTANT: ERROR_INVALID_PRIMARY_GROUP 1308 +CONSTANT: ERROR_NO_IMPERSONATION_TOKEN 1309 +CONSTANT: ERROR_CANT_DISABLE_MANDATORY 1310 +CONSTANT: ERROR_NO_LOGON_SERVERS 1311 +CONSTANT: ERROR_NO_SUCH_LOGON_SESSION 1312 +CONSTANT: ERROR_NO_SUCH_PRIVILEGE 1313 +CONSTANT: ERROR_PRIVILEGE_NOT_HELD 1314 +CONSTANT: ERROR_INVALID_ACCOUNT_NAME 1315 +CONSTANT: ERROR_USER_EXISTS 1316 +CONSTANT: ERROR_NO_SUCH_USER 1317 +CONSTANT: ERROR_GROUP_EXISTS 1318 +CONSTANT: ERROR_NO_SUCH_GROUP 1319 +CONSTANT: ERROR_MEMBER_IN_GROUP 1320 +CONSTANT: ERROR_MEMBER_NOT_IN_GROUP 1321 +CONSTANT: ERROR_LAST_ADMIN 1322 +CONSTANT: ERROR_WRONG_PASSWORD 1323 +CONSTANT: ERROR_ILL_FORMED_PASSWORD 1324 +CONSTANT: ERROR_PASSWORD_RESTRICTION 1325 +CONSTANT: ERROR_LOGON_FAILURE 1326 +CONSTANT: ERROR_ACCOUNT_RESTRICTION 1327 +CONSTANT: ERROR_INVALID_LOGON_HOURS 1328 +CONSTANT: ERROR_INVALID_WORKSTATION 1329 +CONSTANT: ERROR_PASSWORD_EXPIRED 1330 +CONSTANT: ERROR_ACCOUNT_DISABLED 1331 +CONSTANT: ERROR_NONE_MAPPED 1332 +CONSTANT: ERROR_TOO_MANY_LUIDS_REQUESTED 1333 +CONSTANT: ERROR_LUIDS_EXHAUSTED 1334 +CONSTANT: ERROR_INVALID_SUB_AUTHORITY 1335 +CONSTANT: ERROR_INVALID_ACL 1336 +CONSTANT: ERROR_INVALID_SID 1337 +CONSTANT: ERROR_INVALID_SECURITY_DESCR 1338 +CONSTANT: ERROR_BAD_INHERITANCE_ACL 1340 +CONSTANT: ERROR_SERVER_DISABLED 1341 +CONSTANT: ERROR_SERVER_NOT_DISABLED 1342 +CONSTANT: ERROR_INVALID_ID_AUTHORITY 1343 +CONSTANT: ERROR_ALLOTTED_SPACE_EXCEEDED 1344 +CONSTANT: ERROR_INVALID_GROUP_ATTRIBUTES 1345 +CONSTANT: ERROR_BAD_IMPERSONATION_LEVEL 1346 +CONSTANT: ERROR_CANT_OPEN_ANONYMOUS 1347 +CONSTANT: ERROR_BAD_VALIDATION_CLASS 1348 +CONSTANT: ERROR_BAD_TOKEN_TYPE 1349 +CONSTANT: ERROR_NO_SECURITY_ON_OBJECT 1350 +CONSTANT: ERROR_CANT_ACCESS_DOMAIN_INFO 1351 +CONSTANT: ERROR_INVALID_SERVER_STATE 1352 +CONSTANT: ERROR_INVALID_DOMAIN_STATE 1353 +CONSTANT: ERROR_INVALID_DOMAIN_ROLE 1354 +CONSTANT: ERROR_NO_SUCH_DOMAIN 1355 +CONSTANT: ERROR_DOMAIN_EXISTS 1356 +CONSTANT: ERROR_DOMAIN_LIMIT_EXCEEDED 1357 +CONSTANT: ERROR_INTERNAL_DB_CORRUPTION 1358 +CONSTANT: ERROR_INTERNAL_ERROR 1359 +CONSTANT: ERROR_GENERIC_NOT_MAPPED 1360 +CONSTANT: ERROR_BAD_DESCRIPTOR_FORMAT 1361 +CONSTANT: ERROR_NOT_LOGON_PROCESS 1362 +CONSTANT: ERROR_LOGON_SESSION_EXISTS 1363 +CONSTANT: ERROR_NO_SUCH_PACKAGE 1364 +CONSTANT: ERROR_BAD_LOGON_SESSION_STATE 1365 +CONSTANT: ERROR_LOGON_SESSION_COLLISION 1366 +CONSTANT: ERROR_INVALID_LOGON_TYPE 1367 +CONSTANT: ERROR_CANNOT_IMPERSONATE 1368 +CONSTANT: ERROR_RXACT_INVALID_STATE 1369 +CONSTANT: ERROR_RXACT_COMMIT_FAILURE 1370 +CONSTANT: ERROR_SPECIAL_ACCOUNT 1371 +CONSTANT: ERROR_SPECIAL_GROUP 1372 +CONSTANT: ERROR_SPECIAL_USER 1373 +CONSTANT: ERROR_MEMBERS_PRIMARY_GROUP 1374 +CONSTANT: ERROR_TOKEN_ALREADY_IN_USE 1375 +CONSTANT: ERROR_NO_SUCH_ALIAS 1376 +CONSTANT: ERROR_MEMBER_NOT_IN_ALIAS 1377 +CONSTANT: ERROR_MEMBER_IN_ALIAS 1378 +CONSTANT: ERROR_ALIAS_EXISTS 1379 +CONSTANT: ERROR_LOGON_NOT_GRANTED 1380 +CONSTANT: ERROR_TOO_MANY_SECRETS 1381 +CONSTANT: ERROR_SECRET_TOO_LONG 1382 +CONSTANT: ERROR_INTERNAL_DB_ERROR 1383 +CONSTANT: ERROR_TOO_MANY_CONTEXT_IDS 1384 +CONSTANT: ERROR_LOGON_TYPE_NOT_GRANTED 1385 +CONSTANT: ERROR_NT_CROSS_ENCRYPTION_REQUIRED 1386 +CONSTANT: ERROR_NO_SUCH_MEMBER 1387 +CONSTANT: ERROR_INVALID_MEMBER 1388 +CONSTANT: ERROR_TOO_MANY_SIDS 1389 +CONSTANT: ERROR_LM_CROSS_ENCRYPTION_REQUIRED 1390 +CONSTANT: ERROR_NO_INHERITANCE 1391 +CONSTANT: ERROR_FILE_CORRUPT 1392 +CONSTANT: ERROR_DISK_CORRUPT 1393 +CONSTANT: ERROR_NO_USER_SESSION_KEY 1394 +CONSTANT: ERROR_LICENSE_QUOTA_EXCEEDED 1395 +CONSTANT: ERROR_INVALID_WINDOW_HANDLE 1400 +CONSTANT: ERROR_INVALID_MENU_HANDLE 1401 +CONSTANT: ERROR_INVALID_CURSOR_HANDLE 1402 +CONSTANT: ERROR_INVALID_ACCEL_HANDLE 1403 +CONSTANT: ERROR_INVALID_HOOK_HANDLE 1404 +CONSTANT: ERROR_INVALID_DWP_HANDLE 1405 +CONSTANT: ERROR_TLW_WITH_WSCHILD 1406 +CONSTANT: ERROR_CANNOT_FIND_WND_CLASS 1407 +CONSTANT: ERROR_WINDOW_OF_OTHER_THREAD 1408 +CONSTANT: ERROR_HOTKEY_ALREADY_REGISTERED 1409 +CONSTANT: ERROR_CLASS_ALREADY_EXISTS 1410 +CONSTANT: ERROR_CLASS_DOES_NOT_EXIST 1411 +CONSTANT: ERROR_CLASS_HAS_WINDOWS 1412 +CONSTANT: ERROR_INVALID_INDEX 1413 +CONSTANT: ERROR_INVALID_ICON_HANDLE 1414 +CONSTANT: ERROR_PRIVATE_DIALOG_INDEX 1415 +CONSTANT: ERROR_LISTBOX_ID_NOT_FOUND 1416 +CONSTANT: ERROR_NO_WILDCARD_CHARACTERS 1417 +CONSTANT: ERROR_CLIPBOARD_NOT_OPEN 1418 +CONSTANT: ERROR_HOTKEY_NOT_REGISTERED 1419 +CONSTANT: ERROR_WINDOW_NOT_DIALOG 1420 +CONSTANT: ERROR_CONTROL_ID_NOT_FOUND 1421 +CONSTANT: ERROR_INVALID_COMBOBOX_MESSAGE 1422 +CONSTANT: ERROR_WINDOW_NOT_COMBOBOX 1423 +CONSTANT: ERROR_INVALID_EDIT_HEIGHT 1424 +CONSTANT: ERROR_DC_NOT_FOUND 1425 +CONSTANT: ERROR_INVALID_HOOK_FILTER 1426 +CONSTANT: ERROR_INVALID_FILTER_PROC 1427 +CONSTANT: ERROR_HOOK_NEEDS_HMOD 1428 +CONSTANT: ERROR_GLOBAL_ONLY_HOOK 1429 +CONSTANT: ERROR_JOURNAL_HOOK_SET 1430 +CONSTANT: ERROR_HOOK_NOT_INSTALLED 1431 +CONSTANT: ERROR_INVALID_LB_MESSAGE 1432 +CONSTANT: ERROR_LB_WITHOUT_TABSTOPS 1434 +CONSTANT: ERROR_DESTROY_OBJECT_OF_OTHER_THREAD 1435 +CONSTANT: ERROR_CHILD_WINDOW_MENU 1436 +CONSTANT: ERROR_NO_SYSTEM_MENU 1437 +CONSTANT: ERROR_INVALID_MSGBOX_STYLE 1438 +CONSTANT: ERROR_INVALID_SPI_VALUE 1439 +CONSTANT: ERROR_SCREEN_ALREADY_LOCKED 1440 +CONSTANT: ERROR_HWNDS_HAVE_DIFF_PARENT 1441 +CONSTANT: ERROR_NOT_CHILD_WINDOW 1442 +CONSTANT: ERROR_INVALID_GW_COMMAND 1443 +CONSTANT: ERROR_INVALID_THREAD_ID 1444 +CONSTANT: ERROR_NON_MDICHILD_WINDOW 1445 +CONSTANT: ERROR_POPUP_ALREADY_ACTIVE 1446 +CONSTANT: ERROR_NO_SCROLLBARS 1447 +CONSTANT: ERROR_INVALID_SCROLLBAR_RANGE 1448 +CONSTANT: ERROR_INVALID_SHOWWIN_COMMAND 1449 +CONSTANT: ERROR_NO_SYSTEM_RESOURCES 1450 +CONSTANT: ERROR_NONPAGED_SYSTEM_RESOURCES 1451 +CONSTANT: ERROR_PAGED_SYSTEM_RESOURCES 1452 +CONSTANT: ERROR_WORKING_SET_QUOTA 1453 +CONSTANT: ERROR_PAGEFILE_QUOTA 1454 +CONSTANT: ERROR_COMMITMENT_LIMIT 1455 +CONSTANT: ERROR_MENU_ITEM_NOT_FOUND 1456 +CONSTANT: ERROR_INVALID_KEYBOARD_HANDLE 1457 +CONSTANT: ERROR_HOOK_TYPE_NOT_ALLOWED 1458 +CONSTANT: ERROR_REQUIRES_INTERACTIVE_WINDOWSTATION 1459 +CONSTANT: ERROR_TIMEOUT 1460 +CONSTANT: ERROR_EVENTLOG_FILE_CORRUPT 1500 +CONSTANT: ERROR_EVENTLOG_CANT_START 1501 +CONSTANT: ERROR_LOG_FILE_FULL 1502 +CONSTANT: ERROR_EVENTLOG_FILE_CHANGED 1503 +CONSTANT: RPC_S_INVALID_STRING_BINDING 1700 +CONSTANT: RPC_S_WRONG_KIND_OF_BINDING 1701 +CONSTANT: RPC_S_INVALID_BINDING 1702 +CONSTANT: RPC_S_PROTSEQ_NOT_SUPPORTED 1703 +CONSTANT: RPC_S_INVALID_RPC_PROTSEQ 1704 +CONSTANT: RPC_S_INVALID_STRING_UUID 1705 +CONSTANT: RPC_S_INVALID_ENDPOINT_FORMAT 1706 +CONSTANT: RPC_S_INVALID_NET_ADDR 1707 +CONSTANT: RPC_S_NO_ENDPOINT_FOUND 1708 +CONSTANT: RPC_S_INVALID_TIMEOUT 1709 +CONSTANT: RPC_S_OBJECT_NOT_FOUND 1710 +CONSTANT: RPC_S_ALREADY_REGISTERED 1711 +CONSTANT: RPC_S_TYPE_ALREADY_REGISTERED 1712 +CONSTANT: RPC_S_ALREADY_LISTENING 1713 +CONSTANT: RPC_S_NO_PROTSEQS_REGISTERED 1714 +CONSTANT: RPC_S_NOT_LISTENING 1715 +CONSTANT: RPC_S_UNKNOWN_MGR_TYPE 1716 +CONSTANT: RPC_S_UNKNOWN_IF 1717 +CONSTANT: RPC_S_NO_BINDINGS 1718 +CONSTANT: RPC_S_NO_PROTSEQS 1719 +CONSTANT: RPC_S_CANT_CREATE_ENDPOINT 1720 +CONSTANT: RPC_S_OUT_OF_RESOURCES 1721 +CONSTANT: RPC_S_SERVER_UNAVAILABLE 1722 +CONSTANT: RPC_S_SERVER_TOO_BUSY 1723 +CONSTANT: RPC_S_INVALID_NETWORK_OPTIONS 1724 +CONSTANT: RPC_S_NO_CALL_ACTIVE 1725 +CONSTANT: RPC_S_CALL_FAILED 1726 +CONSTANT: RPC_S_CALL_FAILED_DNE 1727 +CONSTANT: RPC_S_PROTOCOL_ERROR 1728 +CONSTANT: RPC_S_UNSUPPORTED_TRANS_SYN 1730 +CONSTANT: RPC_S_UNSUPPORTED_TYPE 1732 +CONSTANT: RPC_S_INVALID_TAG 1733 +CONSTANT: RPC_S_INVALID_BOUND 1734 +CONSTANT: RPC_S_NO_ENTRY_NAME 1735 +CONSTANT: RPC_S_INVALID_NAME_SYNTAX 1736 +CONSTANT: RPC_S_UNSUPPORTED_NAME_SYNTAX 1737 +CONSTANT: RPC_S_UUID_NO_ADDRESS 1739 +CONSTANT: RPC_S_DUPLICATE_ENDPOINT 1740 +CONSTANT: RPC_S_UNKNOWN_AUTHN_TYPE 1741 +CONSTANT: RPC_S_MAX_CALLS_TOO_SMALL 1742 +CONSTANT: RPC_S_STRING_TOO_LONG 1743 +CONSTANT: RPC_S_PROTSEQ_NOT_FOUND 1744 +CONSTANT: RPC_S_PROCNUM_OUT_OF_RANGE 1745 +CONSTANT: RPC_S_BINDING_HAS_NO_AUTH 1746 +CONSTANT: RPC_S_UNKNOWN_AUTHN_SERVICE 1747 +CONSTANT: RPC_S_UNKNOWN_AUTHN_LEVEL 1748 +CONSTANT: RPC_S_INVALID_AUTH_IDENTITY 1749 +CONSTANT: RPC_S_UNKNOWN_AUTHZ_SERVICE 1750 +CONSTANT: EPT_S_INVALID_ENTRY 1751 +CONSTANT: EPT_S_CANT_PERFORM_OP 1752 +CONSTANT: EPT_S_NOT_REGISTERED 1753 +CONSTANT: RPC_S_NOTHING_TO_EXPORT 1754 +CONSTANT: RPC_S_INCOMPLETE_NAME 1755 +CONSTANT: RPC_S_INVALID_VERS_OPTION 1756 +CONSTANT: RPC_S_NO_MORE_MEMBERS 1757 +CONSTANT: RPC_S_NOT_ALL_OBJS_UNEXPORTED 1758 +CONSTANT: RPC_S_INTERFACE_NOT_FOUND 1759 +CONSTANT: RPC_S_ENTRY_ALREADY_EXISTS 1760 +CONSTANT: RPC_S_ENTRY_NOT_FOUND 1761 +CONSTANT: RPC_S_NAME_SERVICE_UNAVAILABLE 1762 +CONSTANT: RPC_S_INVALID_NAF_ID 1763 +CONSTANT: RPC_S_CANNOT_SUPPORT 1764 +CONSTANT: RPC_S_NO_CONTEXT_AVAILABLE 1765 +CONSTANT: RPC_S_INTERNAL_ERROR 1766 +CONSTANT: RPC_S_ZERO_DIVIDE 1767 +CONSTANT: RPC_S_ADDRESS_ERROR 1768 +CONSTANT: RPC_S_FP_DIV_ZERO 1769 +CONSTANT: RPC_S_FP_UNDERFLOW 1770 +CONSTANT: RPC_S_FP_OVERFLOW 1771 +CONSTANT: RPC_X_NO_MORE_ENTRIES 1772 +CONSTANT: RPC_X_SS_CHAR_TRANS_OPEN_FAIL 1773 +CONSTANT: RPC_X_SS_CHAR_TRANS_SHORT_FILE 1774 +CONSTANT: RPC_X_SS_IN_NULL_CONTEXT 1775 +CONSTANT: RPC_X_SS_CONTEXT_DAMAGED 1777 +CONSTANT: RPC_X_SS_HANDLES_MISMATCH 1778 +CONSTANT: RPC_X_SS_CANNOT_GET_CALL_HANDLE 1779 +CONSTANT: RPC_X_NULL_REF_POINTER 1780 +CONSTANT: RPC_X_ENUM_VALUE_OUT_OF_RANGE 1781 +CONSTANT: RPC_X_BYTE_COUNT_TOO_SMALL 1782 +CONSTANT: RPC_X_BAD_STUB_DATA 1783 +CONSTANT: ERROR_INVALID_USER_BUFFER 1784 +CONSTANT: ERROR_UNRECOGNIZED_MEDIA 1785 +CONSTANT: ERROR_NO_TRUST_LSA_SECRET 1786 +CONSTANT: ERROR_NO_TRUST_SAM_ACCOUNT 1787 +CONSTANT: ERROR_TRUSTED_DOMAIN_FAILURE 1788 +CONSTANT: ERROR_TRUSTED_RELATIONSHIP_FAILURE 1789 +CONSTANT: ERROR_TRUST_FAILURE 1790 +CONSTANT: RPC_S_CALL_IN_PROGRESS 1791 +CONSTANT: ERROR_NETLOGON_NOT_STARTED 1792 +CONSTANT: ERROR_ACCOUNT_EXPIRED 1793 +CONSTANT: ERROR_REDIRECTOR_HAS_OPEN_HANDLES 1794 +CONSTANT: ERROR_PRINTER_DRIVER_ALREADY_INSTALLED 1795 +CONSTANT: ERROR_UNKNOWN_PORT 1796 +CONSTANT: ERROR_UNKNOWN_PRINTER_DRIVER 1797 +CONSTANT: ERROR_UNKNOWN_PRINTPROCESSOR 1798 +CONSTANT: ERROR_INVALID_SEPARATOR_FILE 1799 +CONSTANT: ERROR_INVALID_PRIORITY 1800 +CONSTANT: ERROR_INVALID_PRINTER_NAME 1801 +CONSTANT: ERROR_PRINTER_ALREADY_EXISTS 1802 +CONSTANT: ERROR_INVALID_PRINTER_COMMAND 1803 +CONSTANT: ERROR_INVALID_DATATYPE 1804 +CONSTANT: ERROR_INVALID_ENVIRONMENT 1805 +CONSTANT: RPC_S_NO_MORE_BINDINGS 1806 +CONSTANT: ERROR_NOLOGON_INTERDOMAIN_TRUST_ACCOUNT 1807 +CONSTANT: ERROR_NOLOGON_WORKSTATION_TRUST_ACCOUNT 1808 +CONSTANT: ERROR_NOLOGON_SERVER_TRUST_ACCOUNT 1809 +CONSTANT: ERROR_DOMAIN_TRUST_INCONSISTENT 1810 +CONSTANT: ERROR_SERVER_HAS_OPEN_HANDLES 1811 +CONSTANT: ERROR_RESOURCE_DATA_NOT_FOUND 1812 +CONSTANT: ERROR_RESOURCE_TYPE_NOT_FOUND 1813 +CONSTANT: ERROR_RESOURCE_NAME_NOT_FOUND 1814 +CONSTANT: ERROR_RESOURCE_LANG_NOT_FOUND 1815 +CONSTANT: ERROR_NOT_ENOUGH_QUOTA 1816 +CONSTANT: RPC_S_NO_INTERFACES 1817 +CONSTANT: RPC_S_CALL_CANCELLED 1818 +CONSTANT: RPC_S_BINDING_INCOMPLETE 1819 +CONSTANT: RPC_S_COMM_FAILURE 1820 +CONSTANT: RPC_S_UNSUPPORTED_AUTHN_LEVEL 1821 +CONSTANT: RPC_S_NO_PRINC_NAME 1822 +CONSTANT: RPC_S_NOT_RPC_ERROR 1823 +CONSTANT: RPC_S_UUID_LOCAL_ONLY 1824 +CONSTANT: RPC_S_SEC_PKG_ERROR 1825 +CONSTANT: RPC_S_NOT_CANCELLED 1826 +CONSTANT: RPC_X_INVALID_ES_ACTION 1827 +CONSTANT: RPC_X_WRONG_ES_VERSION 1828 +CONSTANT: RPC_X_WRONG_STUB_VERSION 1829 +CONSTANT: RPC_X_INVALID_PIPE_OBJECT 1830 +CONSTANT: RPC_X_INVALID_PIPE_OPERATION 1831 +CONSTANT: RPC_X_WRONG_PIPE_VERSION 1832 +CONSTANT: RPC_S_GROUP_MEMBER_NOT_FOUND 1898 +CONSTANT: EPT_S_CANT_CREATE 1899 +CONSTANT: RPC_S_INVALID_OBJECT 1900 +CONSTANT: ERROR_INVALID_TIME 1901 +CONSTANT: ERROR_INVALID_FORM_NAME 1902 +CONSTANT: ERROR_INVALID_FORM_SIZE 1903 +CONSTANT: ERROR_ALREADY_WAITING 1904 +CONSTANT: ERROR_PRINTER_DELETED 1905 +CONSTANT: ERROR_INVALID_PRINTER_STATE 1906 +CONSTANT: ERROR_PASSWORD_MUST_CHANGE 1907 +CONSTANT: ERROR_DOMAIN_CONTROLLER_NOT_FOUND 1908 +CONSTANT: ERROR_ACCOUNT_LOCKED_OUT 1909 +CONSTANT: OR_INVALID_OXID 1910 +CONSTANT: OR_INVALID_OID 1911 +CONSTANT: OR_INVALID_SET 1912 +CONSTANT: RPC_S_SEND_INCOMPLETE 1913 +CONSTANT: ERROR_INVALID_PIXEL_FORMAT 2000 +CONSTANT: ERROR_BAD_DRIVER 2001 +CONSTANT: ERROR_INVALID_WINDOW_STYLE 2002 +CONSTANT: ERROR_METAFILE_NOT_SUPPORTED 2003 +CONSTANT: ERROR_TRANSFORM_NOT_SUPPORTED 2004 +CONSTANT: ERROR_CLIPPING_NOT_SUPPORTED 2005 +CONSTANT: ERROR_BAD_USERNAME 2202 +CONSTANT: ERROR_NOT_CONNECTED 2250 +CONSTANT: ERROR_OPEN_FILES 2401 +CONSTANT: ERROR_ACTIVE_CONNECTIONS 2402 +CONSTANT: ERROR_DEVICE_IN_USE 2404 +CONSTANT: ERROR_UNKNOWN_PRINT_MONITOR 3000 +CONSTANT: ERROR_PRINTER_DRIVER_IN_USE 3001 +CONSTANT: ERROR_SPOOL_FILE_NOT_FOUND 3002 +CONSTANT: ERROR_SPL_NO_STARTDOC 3003 +CONSTANT: ERROR_SPL_NO_ADDJOB 3004 +CONSTANT: ERROR_PRINT_PROCESSOR_ALREADY_INSTALLED 3005 +CONSTANT: ERROR_PRINT_MONITOR_ALREADY_INSTALLED 3006 +CONSTANT: ERROR_INVALID_PRINT_MONITOR 3007 +CONSTANT: ERROR_PRINT_MONITOR_IN_USE 3008 +CONSTANT: ERROR_PRINTER_HAS_JOBS_QUEUED 3009 +CONSTANT: ERROR_SUCCESS_REBOOT_REQUIRED 3010 +CONSTANT: ERROR_SUCCESS_RESTART_REQUIRED 3011 +CONSTANT: ERROR_WINS_INTERNAL 4000 +CONSTANT: ERROR_CAN_NOT_DEL_LOCAL_WINS 4001 +CONSTANT: ERROR_STATIC_INIT 4002 +CONSTANT: ERROR_INC_BACKUP 4003 +CONSTANT: ERROR_FULL_BACKUP 4004 +CONSTANT: ERROR_REC_NON_EXISTENT 4005 +CONSTANT: ERROR_RPL_NOT_ALLOWED 4006 +CONSTANT: ERROR_NO_BROWSER_SERVERS_FOUND 6118 + +CONSTANT: SUBLANG_NEUTRAL 0 +CONSTANT: LANG_NEUTRAL 0 +CONSTANT: SUBLANG_DEFAULT 1 + +CONSTANT: FORMAT_MESSAGE_ALLOCATE_BUFFER HEX: 00000100 +CONSTANT: FORMAT_MESSAGE_IGNORE_INSERTS HEX: 00000200 +CONSTANT: FORMAT_MESSAGE_FROM_STRING HEX: 00000400 +CONSTANT: FORMAT_MESSAGE_FROM_HMODULE HEX: 00000800 +CONSTANT: FORMAT_MESSAGE_FROM_SYSTEM HEX: 00001000 +CONSTANT: FORMAT_MESSAGE_ARGUMENT_ARRAY HEX: 00002000 +CONSTANT: FORMAT_MESSAGE_MAX_WIDTH_MASK HEX: 000000FF + +: make-lang-id ( lang1 lang2 -- n ) + 10 shift bitor ; inline + +ERROR: error-message-failed id ; +:: n>win32-error-string ( id -- string ) + { + FORMAT_MESSAGE_FROM_SYSTEM + FORMAT_MESSAGE_ARGUMENT_ARRAY + } flags + f + id + LANG_NEUTRAL SUBLANG_DEFAULT make-lang-id + 32768 [ "TCHAR" ] keep + f pick [ FormatMessage 0 = [ id error-message-failed ] when ] dip + utf16n alien>string [ blank? ] trim ; + +: win32-error-string ( -- str ) + GetLastError n>win32-error-string ; + +: (win32-error) ( n -- ) + dup zero? [ + drop + ] [ + win32-error-string throw + ] if ; + +: win32-error ( -- ) + GetLastError (win32-error) ; + +: win32-error=0/f ( n -- ) { 0 f } member? [ win32-error ] when ; +: win32-error>0 ( n -- ) 0 > [ win32-error ] when ; +: win32-error<0 ( n -- ) 0 < [ win32-error ] when ; +: win32-error<>0 ( n -- ) zero? [ win32-error ] unless ; + +: invalid-handle? ( handle -- ) + INVALID_HANDLE_VALUE = [ + win32-error-string throw + ] when ; + +: expected-io-errors ( -- seq ) + ERROR_SUCCESS + ERROR_IO_INCOMPLETE + ERROR_IO_PENDING + WAIT_TIMEOUT 4array ; foldable + +: expected-io-error? ( error-code -- ? ) + expected-io-errors member? ; + +: expected-io-error ( error-code -- ) + dup expected-io-error? [ + drop + ] [ + win32-error-string throw + ] if ; + +: io-error ( return-value -- ) + { 0 f } member? [ GetLastError expected-io-error ] when ; diff --git a/basis/windows/fonts/fonts.factor b/basis/windows/fonts/fonts.factor index a034856b34..1753ff1ce1 100755 --- a/basis/windows/fonts/fonts.factor +++ b/basis/windows/fonts/fonts.factor @@ -1,5 +1,5 @@ USING: assocs memoize locals kernel accessors init fonts math -combinators windows windows.types windows.gdi32 ; +combinators windows.errors windows.types windows.gdi32 ; IN: windows.fonts : windows-font-name ( string -- string' ) diff --git a/basis/windows/fonts/tags.txt b/basis/windows/fonts/tags.txt new file mode 100644 index 0000000000..6bf68304bb --- /dev/null +++ b/basis/windows/fonts/tags.txt @@ -0,0 +1 @@ +unportable diff --git a/basis/windows/kernel32/kernel32.factor b/basis/windows/kernel32/kernel32.factor index 1a513df186..e654b68bdc 100755 --- a/basis/windows/kernel32/kernel32.factor +++ b/basis/windows/kernel32/kernel32.factor @@ -1110,7 +1110,19 @@ FUNCTION: BOOL FindVolumeMountPointClose ( HANDLE hFindVolumeMountPoint ) ; ! FUNCTION: FoldStringA ! FUNCTION: FoldStringW ! FUNCTION: FormatMessageA -! FUNCTION: FormatMessageW +FUNCTION: DWORD FormatMessageW ( + DWORD dwFlags, + LPCVOID lpSource, + DWORD dwMessageId, + DWORD dwLanguageId, + LPTSTR lpBuffer, + DWORD nSize, + void* Arguments + ) ; + +ALIAS: FormatMessage FormatMessageW + + FUNCTION: BOOL FreeConsole ( ) ; ! FUNCTION: FreeEnvironmentStringsA FUNCTION: BOOL FreeEnvironmentStringsW ( LPTCH lpszEnvironmentBlock ) ; diff --git a/basis/windows/ole32/ole32.factor b/basis/windows/ole32/ole32.factor index e69a9213b0..864700cb0f 100755 --- a/basis/windows/ole32/ole32.factor +++ b/basis/windows/ole32/ole32.factor @@ -1,6 +1,6 @@ USING: alien alien.syntax alien.c-types alien.strings math -kernel sequences windows windows.types debugger io accessors -math.order namespaces make math.parser windows.kernel32 +kernel sequences windows.errors windows.types debugger io +accessors math.order namespaces make math.parser windows.kernel32 combinators locals specialized-arrays.direct.uchar ; IN: windows.ole32 @@ -120,7 +120,7 @@ TUPLE: ole32-error error-code ; C: ole32-error M: ole32-error error. - "COM method failed: " print error-code>> (win32-error-string) print ; + "COM method failed: " print error-code>> n>win32-error-string print ; : ole32-error ( hresult -- ) dup succeeded? [ drop ] [ throw ] if ; diff --git a/basis/windows/shell32/shell32.factor b/basis/windows/shell32/shell32.factor index 7802ceb297..016f5ab149 100644 --- a/basis/windows/shell32/shell32.factor +++ b/basis/windows/shell32/shell32.factor @@ -2,8 +2,8 @@ ! See http://factorcode.org/license.txt for BSD license. USING: alien alien.c-types alien.strings alien.syntax combinators io.encodings.utf16n io.files io.pathnames kernel -windows windows.com windows.com.syntax windows.user32 -windows.ole32 ; +windows.errors windows.com windows.com.syntax windows.user32 +windows.ole32 windows ; IN: windows.shell32 CONSTANT: CSIDL_DESKTOP HEX: 00 diff --git a/basis/windows/time/time.factor b/basis/windows/time/time.factor index e63834d369..71726a554a 100644 --- a/basis/windows/time/time.factor +++ b/basis/windows/time/time.factor @@ -1,11 +1,11 @@ ! Copyright (C) 2007 Doug Coleman. ! See http://factorcode.org/license.txt for BSD license. -USING: alien alien.c-types kernel math windows windows.kernel32 -namespaces calendar math.bitwise ; +USING: alien alien.c-types kernel math windows.errors +windows.kernel32 namespaces calendar math.bitwise ; IN: windows.time : >64bit ( lo hi -- n ) - 32 shift bitor ; + 32 shift bitor ; inline : windows-1601 ( -- timestamp ) 1601 1 1 0 0 0 instant ; diff --git a/basis/windows/types/types.factor b/basis/windows/types/types.factor index 20bae06f30..062196c3f8 100755 --- a/basis/windows/types/types.factor +++ b/basis/windows/types/types.factor @@ -100,7 +100,7 @@ TYPEDEF: HANDLE HGDIOBJ TYPEDEF: HANDLE HGLOBAL TYPEDEF: HANDLE HHOOK TYPEDEF: HANDLE HINSTANCE -TYPEDEF: HANDLE HKEY +TYPEDEF: DWORD HKEY TYPEDEF: HANDLE HKL TYPEDEF: HANDLE HLOCAL TYPEDEF: HANDLE HMENU diff --git a/basis/windows/uniscribe/uniscribe.factor b/basis/windows/uniscribe/uniscribe.factor index fb0c134b9a..feb0bef7a8 100755 --- a/basis/windows/uniscribe/uniscribe.factor +++ b/basis/windows/uniscribe/uniscribe.factor @@ -2,9 +2,9 @@ ! See http://factorcode.org/license.txt for BSD license. USING: kernel assocs math sequences fry io.encodings.string io.encodings.utf16n accessors arrays combinators destructors -cache namespaces init fonts alien.c-types windows windows.usp10 +cache namespaces init fonts alien.c-types windows.usp10 windows.offscreen windows.gdi32 windows.ole32 windows.types -windows.fonts opengl.textures locals ; +windows.fonts opengl.textures locals windows.errors ; IN: windows.uniscribe TUPLE: script-string font string metrics ssa size image disposed ; diff --git a/basis/windows/user32/user32.factor b/basis/windows/user32/user32.factor index f3bc1becb2..1e694bcbe4 100644 --- a/basis/windows/user32/user32.factor +++ b/basis/windows/user32/user32.factor @@ -542,12 +542,46 @@ C-STRUCT: DEV_BROADCAST_HDR { "DWORD" "dbch_size" } { "DWORD" "dbch_devicetype" } { "DWORD" "dbch_reserved" } ; + C-STRUCT: DEV_BROADCAST_DEVICEW { "DWORD" "dbcc_size" } { "DWORD" "dbcc_devicetype" } { "DWORD" "dbcc_reserved" } { "GUID" "dbcc_classguid" } - { "WCHAR[1]" "dbcc_name" } ; + { { "WCHAR" 1 } "dbcc_name" } ; + +CONSTANT: CCHDEVICENAME 32 + +C-STRUCT: MONITORINFOEX + { "DWORD" "cbSize" } + { "RECT" "rcMonitor" } + { "RECT" "rcWork" } + { "DWORD" "dwFlags" } + { { "TCHAR" CCHDEVICENAME } "szDevice" } ; + +TYPEDEF: MONITORINFOEX* LPMONITORINFOEX +TYPEDEF: MONITORINFOEX* LPMONITORINFO + +CONSTANT: MONITOR_DEFAULTTONULL 0 +CONSTANT: MONITOR_DEFAULTTOPRIMARY 1 +CONSTANT: MONITOR_DEFAULTTONEAREST 2 +CONSTANT: MONITORINFOF_PRIMARY 1 +CONSTANT: SWP_NOSIZE 1 +CONSTANT: SWP_NOMOVE 2 +CONSTANT: SWP_NOZORDER 4 +CONSTANT: SWP_NOREDRAW 8 +CONSTANT: SWP_NOACTIVATE 16 +CONSTANT: SWP_FRAMECHANGED 32 +CONSTANT: SWP_SHOWWINDOW 64 +CONSTANT: SWP_HIDEWINDOW 128 +CONSTANT: SWP_NOCOPYBITS 256 +CONSTANT: SWP_NOOWNERZORDER 512 +CONSTANT: SWP_NOSENDCHANGING 1024 +CONSTANT: SWP_DRAWFRAME SWP_FRAMECHANGED +CONSTANT: SWP_NOREPOSITION SWP_NOOWNERZORDER +CONSTANT: SWP_DEFERERASE 8192 +CONSTANT: SWP_ASYNCWINDOWPOS 16384 + LIBRARY: user32 @@ -910,7 +944,10 @@ ALIAS: GetMessage GetMessageW ! FUNCTION: GetMessagePos ! FUNCTION: GetMessageTime ! FUNCTION: GetMonitorInfoA -! FUNCTION: GetMonitorInfoW + +FUNCTION: BOOL GetMonitorInfoW ( HMONITOR hMonitor, LPMONITORINFO lpmi ) ; +ALIAS: GetMonitorInfo GetMonitorInfoW + ! FUNCTION: GetMouseMovePointsEx ! FUNCTION: GetNextDlgGroupItem ! FUNCTION: GetNextDlgTabItem @@ -961,6 +998,8 @@ FUNCTION: HWND GetWindow ( HWND hWnd, UINT uCmd ) ; ! FUNCTION: GetWindowInfo ! FUNCTION: GetWindowLongA ! FUNCTION: GetWindowLongW +FUNCTION: LONG_PTR GetWindowLongW ( HANDLE hWnd, int index ) ; +ALIAS: GetWindowLong GetWindowLongW ! FUNCTION: GetWindowModuleFileName ! FUNCTION: GetWindowModuleFileNameA ! FUNCTION: GetWindowModuleFileNameW @@ -1127,7 +1166,7 @@ ALIAS: MessageBoxEx MessageBoxExW ! FUNCTION: ModifyMenuW ! FUNCTION: MonitorFromPoint ! FUNCTION: MonitorFromRect -! FUNCTION: MonitorFromWindow +FUNCTION: HMONITOR MonitorFromWindow ( HWND hWnd, DWORD dwFlags ) ; ! FUNCTION: mouse_event @@ -1303,12 +1342,14 @@ FUNCTION: void SetLastErrorEx ( DWORD dwErrCode, DWORD dwType ) ; ! FUNCTION: SetWindowContextHelpId ! FUNCTION: SetWindowLongA ! FUNCTION: SetWindowLongW +FUNCTION: LONG_PTR SetWindowLongW ( HANDLE hWnd, int index, LONG_PTR dwNewLong ) ; +ALIAS: SetWindowLong SetWindowLongW ! FUNCTION: SetWindowPlacement FUNCTION: BOOL SetWindowPos ( HWND hWnd, HWND hWndInsertAfter, int X, int Y, int cx, int cy, UINT uFlags ) ; : HWND_BOTTOM ( -- alien ) 1 ; : HWND_NOTOPMOST ( -- alien ) -2 ; -: HWND_TOP ( -- alien ) 0 ; +CONSTANT: HWND_TOP f : HWND_TOPMOST ( -- alien ) -1 ; ! FUNCTION: SetWindowRgn diff --git a/basis/windows/windows.factor b/basis/windows/windows.factor index 902b1bec8d..92ba8b638a 100755 --- a/basis/windows/windows.factor +++ b/basis/windows/windows.factor @@ -1,61 +1,5 @@ ! Copyright (C) 2005, 2006 Doug Coleman. ! See http://factorcode.org/license.txt for BSD license. -USING: alien alien.syntax alien.c-types alien.strings arrays -combinators kernel math namespaces parser sequences -windows.errors windows.types windows.kernel32 words -io.encodings.utf16n ; IN: windows -: lo-word ( wparam -- lo ) *short ; inline -: hi-word ( wparam -- hi ) -16 shift lo-word ; inline CONSTANT: MAX_UNICODE_PATH 32768 - -! You must LocalFree the return value! -FUNCTION: void* error_message ( DWORD id ) ; - -: (win32-error-string) ( n -- string ) - error_message - dup utf16n alien>string - swap LocalFree drop ; - -: win32-error-string ( -- str ) - GetLastError (win32-error-string) ; - -: (win32-error) ( n -- ) - dup zero? [ - drop - ] [ - win32-error-string throw - ] if ; - -: win32-error ( -- ) - GetLastError (win32-error) ; - -: win32-error=0/f ( n -- ) { 0 f } member? [ win32-error ] when ; -: win32-error>0 ( n -- ) 0 > [ win32-error ] when ; -: win32-error<0 ( n -- ) 0 < [ win32-error ] when ; -: win32-error<>0 ( n -- ) zero? [ win32-error ] unless ; - -: invalid-handle? ( handle -- ) - INVALID_HANDLE_VALUE = [ - win32-error-string throw - ] when ; - -: expected-io-errors ( -- seq ) - ERROR_SUCCESS - ERROR_IO_INCOMPLETE - ERROR_IO_PENDING - WAIT_TIMEOUT 4array ; foldable - -: expected-io-error? ( error-code -- ? ) - expected-io-errors member? ; - -: expected-io-error ( error-code -- ) - dup expected-io-error? [ - drop - ] [ - (win32-error-string) throw - ] if ; - -: io-error ( return-value -- ) - { 0 f } member? [ GetLastError expected-io-error ] when ; diff --git a/basis/windows/winsock/winsock.factor b/basis/windows/winsock/winsock.factor index 06df74cd4c..f0d32588f5 100755 --- 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 io.encodings.utf16n ; +windows.errors math.bitwise io.encodings.utf16n ; IN: windows.winsock USE: libc @@ -403,7 +403,7 @@ CONSTANT: SIO_GET_EXTENSION_FUNCTION_POINTER -939524090 : (winsock-error-string) ( n -- str ) ! #! WSAStartup returns the error code 'n' directly dup winsock-expected-error? - [ drop f ] [ error_message utf16n alien>string ] if ; + [ drop f ] [ n>win32-error-string ] if ; : winsock-error-string ( -- string/f ) WSAGetLastError (winsock-error-string) ; diff --git a/basis/xmode/code2html/code2html.factor b/basis/xmode/code2html/code2html.factor index 3fb5a532c9..b5141f6cc4 100644 --- a/basis/xmode/code2html/code2html.factor +++ b/basis/xmode/code2html/code2html.factor @@ -24,7 +24,7 @@ IN: xmode.code2html [XML XML] ; :: htmlize-stream ( path stream -- xml ) - stream lines + stream stream-lines [ "" ] [ path over first find-mode htmlize-lines ] if-empty :> input default-stylesheet :> stylesheet diff --git a/build-support/factor.sh b/build-support/factor.sh index 3ece72306a..ba5815cfc1 100755 --- a/build-support/factor.sh +++ b/build-support/factor.sh @@ -205,7 +205,7 @@ find_architecture() { write_test_program() { echo "#include " > $C_WORD.c - echo "int main(){printf(\"%ld\", 8*sizeof(void*)); return 0; }" >> $C_WORD.c + echo "int main(){printf(\"%ld\", (long)(8*sizeof(void*))); return 0; }" >> $C_WORD.c } c_find_word_size() { diff --git a/core/bootstrap/layouts/layouts.factor b/core/bootstrap/layouts/layouts.factor index 26100277a8..5ed92b7776 100644 --- a/core/bootstrap/layouts/layouts.factor +++ b/core/bootstrap/layouts/layouts.factor @@ -1,4 +1,4 @@ -! Copyright (C) 2007, 2008 Slava Pestov. +! Copyright (C) 2007, 2009 Slava Pestov. ! See http://factorcode.org/license.txt for BSD license. USING: namespaces math words kernel alien byte-arrays hashtables vectors strings sbufs arrays @@ -9,28 +9,28 @@ BIN: 111 tag-mask set 8 num-tags set 3 tag-bits set -17 num-types set +15 num-types set + +32 mega-cache-size set H{ { fixnum BIN: 000 } { bignum BIN: 001 } - { tuple BIN: 010 } - { object BIN: 011 } - { hi-tag BIN: 011 } - { ratio BIN: 100 } - { float BIN: 101 } - { complex BIN: 110 } - { POSTPONE: f BIN: 111 } + { array BIN: 010 } + { float BIN: 011 } + { quotation BIN: 100 } + { POSTPONE: f BIN: 101 } + { object BIN: 110 } + { hi-tag BIN: 110 } + { tuple BIN: 111 } } tag-numbers set tag-numbers get H{ - { array 8 } - { wrapper 9 } - { byte-array 10 } - { callstack 11 } - { string 12 } - { word 13 } - { quotation 14 } - { dll 15 } - { alien 16 } + { wrapper 8 } + { byte-array 9 } + { callstack 10 } + { string 11 } + { word 12 } + { dll 13 } + { alien 14 } } assoc-union type-numbers set diff --git a/core/bootstrap/primitives.factor b/core/bootstrap/primitives.factor index 1258da8a4d..c0d51477ca 100644 --- a/core/bootstrap/primitives.factor +++ b/core/bootstrap/primitives.factor @@ -1,4 +1,4 @@ -! Copyright (C) 2004, 2008 Slava Pestov. +! Copyright (C) 2004, 2009 Slava Pestov. ! See http://factorcode.org/license.txt for BSD license. USING: alien arrays byte-arrays generic hashtables hashtables.private io kernel math math.private math.order @@ -69,6 +69,8 @@ bootstrapping? on "classes.predicate" "compiler.units" "continuations.private" + "generic.single" + "generic.single.private" "growable" "hashtables" "hashtables.private" @@ -97,7 +99,6 @@ bootstrapping? on "threads.private" "tools.profiler.private" "words" - "words.private" "vectors" "vectors.private" } [ create-vocab drop ] each @@ -125,9 +126,7 @@ bootstrapping? on "fixnum" "math" create register-builtin "bignum" "math" create register-builtin "tuple" "kernel" create register-builtin -"ratio" "math" create register-builtin "float" "math" create register-builtin -"complex" "math" create register-builtin "f" "syntax" lookup register-builtin "array" "arrays" create register-builtin "wrapper" "kernel" create register-builtin @@ -146,24 +145,6 @@ bootstrapping? on "f?" "syntax" vocab-words delete-at ! Some unions -"integer" "math" create -"fixnum" "math" lookup -"bignum" "math" lookup -2array -define-union-class - -"rational" "math" create -"integer" "math" lookup -"ratio" "math" lookup -2array -define-union-class - -"real" "math" create -"rational" "math" lookup -"float" "math" lookup -2array -define-union-class - "c-ptr" "alien" create [ "alien" "alien" lookup , "f" "syntax" lookup , @@ -210,19 +191,9 @@ bi "bignum" "math" create { } define-builtin "bignum" "math" create ">bignum" "math" create 1quotation "coercer" set-word-prop -"ratio" "math" create { - { "numerator" { "integer" "math" } read-only } - { "denominator" { "integer" "math" } read-only } -} define-builtin - "float" "math" create { } define-builtin "float" "math" create ">float" "math" create 1quotation "coercer" set-word-prop -"complex" "math" create { - { "real" { "real" "math" } read-only } - { "imaginary" { "real" "math" } read-only } -} define-builtin - "array" "arrays" create { { "length" { "array-capacity" "sequences.private" } read-only } } define-builtin @@ -258,7 +229,7 @@ bi "vocabulary" { "def" { "quotation" "quotations" } initial: [ ] } "props" - { "optimized" read-only } + { "direct-entry-def" } { "counter" { "fixnum" "math" } } { "sub-primitive" read-only } } define-builtin @@ -338,7 +309,7 @@ tuple [ create dup 1quotation ] dip define-declared ; { - { "(execute)" "words.private" (( word -- )) } + { "(execute)" "kernel.private" (( word -- )) } { "(call)" "kernel.private" (( quot -- )) } { "both-fixnums?" "math.private" (( x y -- ? )) } { "fixnum+fast" "math.private" (( x y -- z )) } @@ -378,6 +349,7 @@ tuple { "get-local" "locals.backend" (( n -- obj )) } { "load-local" "locals.backend" (( obj -- )) } { "drop-locals" "locals.backend" (( n -- )) } + { "mega-cache-lookup" "generic.single.private" (( methods index cache -- )) } } [ first3 make-sub-primitive ] each ! Primitive words @@ -394,14 +366,12 @@ tuple { "float>bignum" "math.private" (( x -- y )) } { "fixnum>float" "math.private" (( x -- y )) } { "bignum>float" "math.private" (( x -- y )) } - { "" "math.private" (( a b -- a/b )) } { "string>float" "math.private" (( str -- n/f )) } { "float>string" "math.private" (( n -- str )) } { "float>bits" "math" (( x -- n )) } { "double>bits" "math" (( x -- n )) } { "bits>float" "math" (( n -- x )) } { "bits>double" "math" (( n -- x )) } - { "" "math.private" (( x y -- z )) } { "fixnum+" "math.private" (( x y -- z )) } { "fixnum-" "math.private" (( x y -- z )) } { "fixnum*" "math.private" (( x y -- z )) } @@ -532,6 +502,14 @@ tuple { "jit-compile" "quotations" (( quot -- )) } { "load-locals" "locals.backend" (( ... n -- )) } { "check-datastack" "kernel.private" (( array in# out# -- ? )) } + { "inline-cache-miss" "generic.single.private" (( generic methods index cache -- )) } + { "mega-cache-miss" "generic.single.private" (( methods index cache -- method )) } + { "lookup-method" "generic.single.private" (( object methods -- method )) } + { "reset-dispatch-stats" "generic.single" (( -- )) } + { "dispatch-stats" "generic.single" (( -- stats )) } + { "reset-inline-cache-stats" "generic.single" (( -- )) } + { "inline-cache-stats" "generic.single" (( -- stats )) } + { "optimized?" "words" (( word -- ? )) } } [ [ first3 ] dip swap make-primitive ] each-index ! Bump build number diff --git a/core/checksums/checksums.factor b/core/checksums/checksums.factor index 98d36b21c3..82918b6f81 100644 --- a/core/checksums/checksums.factor +++ b/core/checksums/checksums.factor @@ -13,7 +13,7 @@ GENERIC: checksum-stream ( stream checksum -- value ) GENERIC: checksum-lines ( lines checksum -- value ) M: checksum checksum-stream - [ contents ] dip checksum-bytes ; + [ stream-contents ] dip checksum-bytes ; M: checksum checksum-lines [ B{ CHAR: \n } join ] dip checksum-bytes ; diff --git a/core/classes/builtin/builtin.factor b/core/classes/builtin/builtin.factor index f95d66fd05..32f7af8113 100644 --- a/core/classes/builtin/builtin.factor +++ b/core/classes/builtin/builtin.factor @@ -33,13 +33,13 @@ M: lo-tag-class define-builtin-predicate M: hi-tag-class define-builtin-predicate dup class>type [ eq? ] curry [ hi-tag ] prepend 1quotation - [ dup tag 3 eq? ] [ [ drop f ] if ] surround + [ dup tag 6 eq? ] [ [ drop f ] if ] surround define-predicate ; M: lo-tag-class instance? [ tag ] [ class>type ] bi* eq? ; M: hi-tag-class instance? - over tag 3 eq? [ [ hi-tag ] [ class>type ] bi* eq? ] [ 2drop f ] if ; + over tag 6 eq? [ [ hi-tag ] [ class>type ] bi* eq? ] [ 2drop f ] if ; M: builtin-class (flatten-class) dup set ; diff --git a/core/classes/mixin/mixin-tests.factor b/core/classes/mixin/mixin-tests.factor index cd11591d6c..f44642fdd5 100644 --- a/core/classes/mixin/mixin-tests.factor +++ b/core/classes/mixin/mixin-tests.factor @@ -119,3 +119,13 @@ MIXIN: move-instance-declaration-mixin [ ] [ "IN: classes.mixin.tests.a" "move-mixin-test-1" parse-stream drop ] unit-test [ { string } ] [ move-instance-declaration-mixin members ] unit-test + +MIXIN: silly-mixin +SYMBOL: not-a-class + +[ [ \ not-a-class \ silly-mixin add-mixin-instance ] with-compilation-unit ] must-fail + +SYMBOL: not-a-mixin +TUPLE: a-class ; + +[ [ \ a-class \ not-a-mixin add-mixin-instance ] with-compilation-unit ] must-fail diff --git a/core/classes/mixin/mixin.factor b/core/classes/mixin/mixin.factor index 4bdb893d9a..6cf95716be 100644 --- a/core/classes/mixin/mixin.factor +++ b/core/classes/mixin/mixin.factor @@ -50,7 +50,9 @@ TUPLE: check-mixin-class class ; [ [ f ] 2dip "instances" word-prop set-at ] 2bi ; -: add-mixin-instance ( class mixin -- ) +GENERIC# add-mixin-instance 1 ( class mixin -- ) + +M: class add-mixin-instance #! Note: we call update-classes on the new member, not the #! mixin. This ensures that we only have to update the #! methods whose specializer intersects the new member, not diff --git a/core/classes/tuple/tuple-tests.factor b/core/classes/tuple/tuple-tests.factor index c180807b0c..466b221877 100644 --- a/core/classes/tuple/tuple-tests.factor +++ b/core/classes/tuple/tuple-tests.factor @@ -1,11 +1,11 @@ -USING: definitions generic kernel kernel.private math -math.constants parser sequences tools.test words assocs -namespaces quotations sequences.private classes continuations -generic.standard effects classes.tuple classes.tuple.private -arrays vectors strings compiler.units accessors classes.algebra -calendar prettyprint io.streams.string splitting summary -columns math.order classes.private slots slots.private eval see -words.symbol compiler.errors ; +USING: definitions generic kernel kernel.private math math.constants +parser sequences tools.test words assocs namespaces quotations +sequences.private classes continuations generic.single +generic.standard effects classes.tuple classes.tuple.private arrays +vectors strings compiler.units accessors classes.algebra calendar +prettyprint io.streams.string splitting summary columns math.order +classes.private slots slots.private eval see words.symbol +compiler.errors ; IN: classes.tuple.tests TUPLE: rect x y w h ; diff --git a/core/combinators/combinators-docs.factor b/core/combinators/combinators-docs.factor old mode 100644 new mode 100755 index cbef25ac38..8b301affbd --- a/core/combinators/combinators-docs.factor +++ b/core/combinators/combinators-docs.factor @@ -290,7 +290,6 @@ $nl "The above are syntax sugar. The underlying words are a bit more verbose but allow non-constant effects to be passed in:" { $subsection call-effect } { $subsection execute-effect } -{ $subsection "call-unsafe" } "The combinator variants that do not take an effect declaration can only be used if the compiler is able to infer the stack effect by other means. See " { $link "inference-combinators" } "." { $subsection "call-unsafe" } { $see-also "effects" "inference" } ; @@ -306,6 +305,7 @@ ARTICLE: "combinators" "Combinators" { $subsection "combinators.smart" } "More combinators are defined for working on data structures, such as " { $link "sequences-combinators" } " and " { $link "assocs-combinators" } "." { $subsection "combinators-quot" } +{ $subsection "generalizations" } { $see-also "quotations" } ; ABOUT: "combinators" diff --git a/core/combinators/combinators-tests.factor b/core/combinators/combinators-tests.factor old mode 100644 new mode 100755 index dd5fa06031..aae6618ee8 --- a/core/combinators/combinators-tests.factor +++ b/core/combinators/combinators-tests.factor @@ -16,12 +16,12 @@ IN: combinators.tests : compile-execute(-test-1 ( a b -- c ) \ + execute( a b -- c ) ; -[ t ] [ \ compile-execute(-test-1 optimized>> ] unit-test +[ t ] [ \ compile-execute(-test-1 optimized? ] unit-test [ 4 ] [ 1 3 compile-execute(-test-1 ] unit-test : compile-execute(-test-2 ( a b w -- c ) execute( a b -- c ) ; -[ t ] [ \ compile-execute(-test-2 optimized>> ] unit-test +[ t ] [ \ compile-execute(-test-2 optimized? ] unit-test [ 4 ] [ 1 3 \ + compile-execute(-test-2 ] unit-test [ 5 ] [ 1 4 \ + compile-execute(-test-2 ] unit-test [ -3 ] [ 1 4 \ - compile-execute(-test-2 ] unit-test @@ -29,7 +29,7 @@ IN: combinators.tests : compile-call(-test-1 ( a b q -- c ) call( a b -- c ) ; -[ t ] [ \ compile-call(-test-1 optimized>> ] unit-test +[ t ] [ \ compile-call(-test-1 optimized? ] unit-test [ 4 ] [ 1 3 [ + ] compile-call(-test-1 ] unit-test [ 7 ] [ 1 3 2 [ * + ] curry compile-call(-test-1 ] unit-test [ 7 ] [ 1 3 [ 2 * ] [ + ] compose compile-call(-test-1 ] unit-test @@ -352,7 +352,7 @@ DEFER: corner-case-1 << \ corner-case-1 2 [ + ] curry 1array [ case ] curry (( a -- b )) define-declared >> -[ t ] [ \ corner-case-1 optimized>> ] unit-test +[ t ] [ \ corner-case-1 optimized? ] unit-test [ 4 ] [ 2 corner-case-1 ] unit-test [ 4 ] [ 2 2 [ + ] curry 1array case ] unit-test diff --git a/core/compiler/units/units-tests.factor b/core/compiler/units/units-tests.factor index da2dce128f..8dce12f411 100644 --- a/core/compiler/units/units-tests.factor +++ b/core/compiler/units/units-tests.factor @@ -19,7 +19,7 @@ IN: compiler.units.tests ] unit-test [ "A" "B" ] [ - disable-compiler + disable-optimizer gensym "a" set gensym "b" set @@ -33,7 +33,7 @@ IN: compiler.units.tests ] with-compilation-unit "b" get execute - enable-compiler + enable-optimizer ] unit-test ! Check that we notify observers diff --git a/core/compiler/units/units.factor b/core/compiler/units/units.factor index c4a137b2ba..f1f9131f08 100644 --- a/core/compiler/units/units.factor +++ b/core/compiler/units/units.factor @@ -43,6 +43,9 @@ HOOK: recompile compiler-impl ( words -- alist ) ! Non-optimizing compiler M: f recompile [ dup def>> ] { } map>assoc ; +: without-optimizer ( quot -- ) + [ f compiler-impl ] dip with-variable ; inline + ! Trivial compiler. We don't want to touch the code heap ! during stage1 bootstrap, it would just waste time. SINGLETON: dummy-compiler @@ -58,6 +61,10 @@ GENERIC: definitions-changed ( assoc obj -- ) [ V{ } clone definition-observers set-global ] "compiler.units" add-init-hook +! This goes here because vocabs cannot depend on init +[ V{ } clone vocab-observers set-global ] +"vocabs" add-init-hook + : add-definition-observer ( obj -- ) definition-observers get push ; diff --git a/core/effects/effects-docs.factor b/core/effects/effects-docs.factor index 495aeb39c1..38b8ab4dad 100644 --- a/core/effects/effects-docs.factor +++ b/core/effects/effects-docs.factor @@ -42,8 +42,15 @@ HELP: effect-height { $description "Outputs the number of objects added to the data stack by the stack effect. This will be negative if the stack effect only removes objects from the stack." } ; HELP: effect<= -{ $values { "eff1" effect } { "eff2" effect } { "?" "a boolean" } } -{ $description "Tests if " { $snippet "eff1" } " is substitutable for " { $snippet "eff2" } ". What this means is that both stack effects change the stack height by the same amount, the first takes a smaller or equal number of inputs as the second, and either both or neither one terminate execution by throwing an error." } ; +{ $values { "effect1" effect } { "effect2" effect } { "?" "a boolean" } } +{ $description "Tests if " { $snippet "effect1" } " is substitutable for " { $snippet "effect2" } ". What this means is that both stack effects change the stack height by the same amount, the first takes a smaller or equal number of inputs as the second, and either both or neither one terminate execution by throwing an error." } ; + +HELP: effect= +{ $values { "effect1" effect } { "effect2" effect } { "?" "a boolean" } } +{ $description "Tests if " { $snippet "effect1" } " and " { $snippet "effect2" } " represent the same stack transformation, without looking parameter names." } +{ $examples + { $example "USING: effects prettyprint ;" "(( a -- b )) (( x -- y )) effect= ." "t" } +} ; HELP: effect>string { $values { "obj" object } { "str" string } } diff --git a/core/effects/effects-tests.factor b/core/effects/effects-tests.factor index 316add54c0..3eb9273859 100644 --- a/core/effects/effects-tests.factor +++ b/core/effects/effects-tests.factor @@ -18,4 +18,8 @@ USING: effects tools.test prettyprint accessors sequences ; [ { "x" "y" } ] [ { "y" "x" } (( a b -- b a )) shuffle ] unit-test [ { "y" "x" "y" } ] [ { "y" "x" } (( a b -- a b a )) shuffle ] unit-test -[ { } ] [ { "y" "x" } (( a b -- )) shuffle ] unit-test \ No newline at end of file +[ { } ] [ { "y" "x" } (( a b -- )) shuffle ] unit-test + +[ t ] [ (( -- )) (( -- )) compose-effects (( -- )) effect= ] unit-test +[ t ] [ (( -- * )) (( -- )) compose-effects (( -- * )) effect= ] unit-test +[ t ] [ (( -- )) (( -- * )) compose-effects (( -- * )) effect= ] unit-test \ No newline at end of file diff --git a/core/effects/effects.factor b/core/effects/effects.factor index 142b9120a8..cab1e531b7 100644 --- a/core/effects/effects.factor +++ b/core/effects/effects.factor @@ -1,6 +1,6 @@ ! Copyright (C) 2006, 2009 Slava Pestov. ! See http://factorcode.org/license.txt for BSD license. -USING: kernel math math.parser namespaces make sequences strings +USING: kernel math math.parser math.order namespaces make sequences strings words assocs combinators accessors arrays ; IN: effects @@ -13,7 +13,7 @@ TUPLE: effect { in read-only } { out read-only } { terminated? read-only } ; : effect-height ( effect -- n ) [ out>> length ] [ in>> length ] bi - ; inline -: effect<= ( eff1 eff2 -- ? ) +: effect<= ( effect1 effect2 -- ? ) { { [ over terminated?>> ] [ t ] } { [ dup terminated?>> ] [ f ] } @@ -22,6 +22,12 @@ TUPLE: effect { in read-only } { out read-only } { terminated? read-only } ; [ t ] } cond 2nip ; inline +: effect= ( effect1 effect2 -- ? ) + [ [ in>> length ] bi@ = ] + [ [ out>> length ] bi@ = ] + [ [ terminated?>> ] bi@ = ] + 2tri and and ; + GENERIC: effect>string ( obj -- str ) M: string effect>string ; M: object effect>string drop "object" ; @@ -66,3 +72,13 @@ M: effect clone : add-effect-input ( effect -- effect' ) [ in>> "obj" suffix ] [ out>> ] [ terminated?>> ] tri effect boa ; + +: compose-effects ( effect1 effect2 -- effect' ) + over terminated?>> [ + drop + ] [ + [ [ [ in>> length ] [ out>> length ] bi ] [ in>> length ] bi* swap [-] + ] + [ [ out>> length ] [ [ in>> length ] [ out>> length ] bi ] bi* [ [-] ] dip + ] + [ nip terminated?>> ] 2tri + effect boa + ] if ; inline diff --git a/core/generic/generic-docs.factor b/core/generic/generic-docs.factor index e8b5e6d69c..73002a5d89 100644 --- a/core/generic/generic-docs.factor +++ b/core/generic/generic-docs.factor @@ -1,6 +1,7 @@ USING: help.markup help.syntax words classes classes.algebra definitions kernel alien sequences math quotations -generic.standard generic.math combinators prettyprint effects ; +generic.single generic.standard generic.hook generic.math +combinators prettyprint effects ; IN: generic ARTICLE: "method-order" "Method precedence" diff --git a/core/generic/generic-tests.factor b/core/generic/generic-tests.factor index e7ae583aa6..a63cab1c5c 100755 --- a/core/generic/generic-tests.factor +++ b/core/generic/generic-tests.factor @@ -96,15 +96,6 @@ M: shit big-generic-test "shit" ; [ t ] [ \ + math-generic? ] unit-test -! Test math-combination -[ [ [ >float ] dip ] ] [ \ real \ float math-upgrade ] unit-test -[ [ >float ] ] [ \ float \ real math-upgrade ] unit-test -[ [ [ >bignum ] dip ] ] [ \ fixnum \ bignum math-upgrade ] unit-test -[ [ >float ] ] [ \ float \ integer math-upgrade ] unit-test -[ number ] [ \ number \ float math-class-max ] unit-test -[ float ] [ \ real \ float math-class-max ] unit-test -[ fixnum ] [ \ fixnum \ null math-class-max ] unit-test - ! Regression TUPLE: first-one ; TUPLE: second-one ; diff --git a/core/generic/generic.factor b/core/generic/generic.factor index 965be91642..4b398f6532 100644 --- a/core/generic/generic.factor +++ b/core/generic/generic.factor @@ -164,8 +164,8 @@ M: sequence update-methods ( class seq -- ) drop 2dup [ "combination" word-prop ] dip = [ 2drop ] [ { + [ drop reset-generic ] [ "combination" set-word-prop ] - [ drop "methods" word-prop values forget-all ] [ drop H{ } clone "methods" set-word-prop ] [ define-default-method ] } diff --git a/core/generic/hook/authors.txt b/core/generic/hook/authors.txt new file mode 100644 index 0000000000..d4f5d6b3ae --- /dev/null +++ b/core/generic/hook/authors.txt @@ -0,0 +1 @@ +Slava Pestov \ No newline at end of file diff --git a/core/generic/hook/hook-docs.factor b/core/generic/hook/hook-docs.factor new file mode 100644 index 0000000000..9b57d941c0 --- /dev/null +++ b/core/generic/hook/hook-docs.factor @@ -0,0 +1,10 @@ +USING: generic generic.single generic.standard help.markup help.syntax sequences math +math.parser effects ; +IN: generic.hook + +HELP: hook-combination +{ $class-description + "Performs hook method combination . See " { $link POSTPONE: HOOK: } "." +} ; + +{ standard-combination hook-combination } related-words \ No newline at end of file diff --git a/core/generic/hook/hook.factor b/core/generic/hook/hook.factor new file mode 100644 index 0000000000..fe5b62f6c0 --- /dev/null +++ b/core/generic/hook/hook.factor @@ -0,0 +1,28 @@ +! Copyright (C) 2009 Slava Pestov. +! See http://factorcode.org/license.txt for BSD license. +USING: accessors definitions generic generic.single +generic.single.private kernel namespaces words kernel.private +quotations sequences ; +IN: generic.hook + +TUPLE: hook-combination < single-combination var ; + +C: hook-combination + +PREDICATE: hook-generic < generic + "combination" word-prop hook-combination? ; + +M: hook-combination picker + combination get var>> [ get ] curry ; + +M: hook-combination dispatch# drop 0 ; + +M: hook-combination inline-cache-quot 2drop f ; + +M: hook-combination mega-cache-quot + 1quotation picker [ lookup-method (execute) ] surround ; + +M: hook-generic definer drop \ HOOK: f ; + +M: hook-generic effective-method + [ "combination" word-prop var>> get ] keep (effective-method) ; \ No newline at end of file diff --git a/core/generic/math/math-docs.factor b/core/generic/math/math-docs.factor index 60fa745339..7d7d6e725b 100644 --- a/core/generic/math/math-docs.factor +++ b/core/generic/math/math-docs.factor @@ -1,5 +1,5 @@ USING: kernel generic help.markup help.syntax math classes -sequences quotations ; +sequences quotations generic.math.private ; IN: generic.math HELP: math-upgrade diff --git a/core/generic/math/math-tests.factor b/core/generic/math/math-tests.factor new file mode 100644 index 0000000000..51e122431c --- /dev/null +++ b/core/generic/math/math-tests.factor @@ -0,0 +1,21 @@ +IN: generic.math.tests +USING: generic.math math tools.test kernel ; + +! Test math-combination +[ [ [ >float ] dip ] ] [ \ real \ float math-upgrade ] unit-test +[ [ >float ] ] [ \ float \ real math-upgrade ] unit-test +[ [ [ >bignum ] dip ] ] [ \ fixnum \ bignum math-upgrade ] unit-test +[ [ >float ] ] [ \ float \ integer math-upgrade ] unit-test + +[ number ] [ number float math-class-max ] unit-test +[ number ] [ float number math-class-max ] unit-test +[ float ] [ real float math-class-max ] unit-test +[ float ] [ float real math-class-max ] unit-test +[ fixnum ] [ fixnum null math-class-max ] unit-test +[ fixnum ] [ null fixnum math-class-max ] unit-test +[ bignum ] [ fixnum bignum math-class-max ] unit-test +[ bignum ] [ bignum fixnum math-class-max ] unit-test +[ number ] [ fixnum number math-class-max ] unit-test +[ number ] [ number fixnum math-class-max ] unit-test + + diff --git a/core/generic/math/math.factor b/core/generic/math/math.factor index 8d4610dabe..c96050ad03 100644 --- a/core/generic/math/math.factor +++ b/core/generic/math/math.factor @@ -1,9 +1,9 @@ -! Copyright (C) 2005, 2008 Slava Pestov. +! Copyright (C) 2005, 2009 Slava Pestov. ! See http://factorcode.org/license.txt for BSD license. USING: arrays generic hashtables kernel kernel.private math -namespaces make sequences words quotations layouts combinators +namespaces sequences words quotations layouts combinators sequences.private classes classes.builtin classes.algebra -definitions math.order math.private ; +definitions math.order math.private assocs ; IN: generic.math PREDICATE: math-class < class @@ -13,24 +13,30 @@ PREDICATE: math-class < class number bootstrap-word class<= ] if ; + ( class1 class2 -- class ) - [ math-precedence ] compare +gt+ eq? ; +: bootstrap-words ( classes -- classes' ) + [ bootstrap-word ] map ; -: math-class-max ( class1 class2 -- class ) - [ math-class<=> ] most ; +: math-precedence ( class -- pair ) + [ + { fixnum integer rational real number object } bootstrap-words + swap [ swap class<= ] curry find drop -1 or + ] [ + { fixnum bignum ratio float complex object } bootstrap-words + swap [ class<= ] curry find drop -1 or + ] bi 2array ; : (math-upgrade) ( max class -- quot ) dupd = [ drop [ ] ] [ "coercer" word-prop [ ] or ] if ; +PRIVATE> + +: math-class-max ( class1 class2 -- class ) + [ [ math-precedence ] bi@ after? ] most ; + : math-upgrade ( class1 class2 -- quot ) [ math-class-max ] 2keep [ @@ -44,33 +50,57 @@ ERROR: no-math-method left right generic ; : default-math-method ( generic -- quot ) [ no-math-method ] curry [ ] like ; + + : object-method ( generic -- quot ) object bootstrap-word applicable-method ; : math-method ( word class1 class2 -- quot ) 2dup and [ - [ - 2dup 2array , \ declare , - 2dup math-upgrade % - math-class-max over order min-class applicable-method % - ] [ ] make + [ 2array [ declare ] curry nip ] + [ math-upgrade nip ] + [ math-class-max over order min-class applicable-method ] + 3tri 3append ] [ 2drop object-method ] if ; -SYMBOL: picker +class ] prepose map , ] bi* - \ dispatch , - ] [ ] make ; inline +SYMBOL: generic-word + +: make-math-method-table ( classes quot: ( class -- quot ) -- alist ) + [ bootstrap-words ] dip + [ [ drop ] [ call ] 2bi ] curry { } map>assoc ; inline + +: math-alist>quot ( alist -- quot ) + [ generic-word get object-method ] dip alist>quot ; + +: tag-dispatch-entry ( tag picker -- quot ) + [ "type" word-prop 1quotation [ tag ] [ eq? ] surround ] dip prepend ; + +: tag-dispatch ( picker alist -- alist' ) + swap [ [ tag-dispatch-entry ] curry dip ] curry assoc-map math-alist>quot ; + +: tuple-dispatch-entry ( class picker -- quot ) + [ 1quotation [ { tuple } declare class ] [ eq? ] surround ] dip prepend ; + +: tuple-dispatch ( picker alist -- alist' ) + swap [ [ tuple-dispatch-entry ] curry dip ] curry assoc-map math-alist>quot ; + +: math-dispatch-step ( picker quot: ( class -- quot ) -- quot ) + [ [ { bignum float fixnum } ] dip make-math-method-table ] + [ [ { ratio complex } ] dip make-math-method-table tuple-dispatch ] 2bi + tuple swap 2array prefix tag-dispatch ; inline + +PRIVATE> SINGLETON: math-combination @@ -78,20 +108,21 @@ M: math-combination make-default-method drop default-math-method ; M: math-combination perform-combination - drop - dup - [ - [ 2dup both-fixnums? ] % - dup fixnum bootstrap-word dup math-method , - \ over [ - dup math-class? [ - \ dup [ [ 2dup ] dip math-method ] math-vtable - ] [ - over object-method - ] if nip - ] math-vtable nip , - \ if , - ] [ ] make define ; + drop dup generic-word [ + dup + [ fixnum bootstrap-word dup math-method ] + [ + [ over ] [ + dup math-class? [ + [ dup ] [ math-method ] with with math-dispatch-step + ] [ + drop object-method + ] if + ] with math-dispatch-step + ] bi + [ if ] 2curry [ 2dup both-fixnums? ] prepend + define + ] with-variable ; PREDICATE: math-generic < generic ( word -- ? ) "combination" word-prop math-combination? ; diff --git a/core/generic/single/authors.txt b/core/generic/single/authors.txt new file mode 100644 index 0000000000..d4f5d6b3ae --- /dev/null +++ b/core/generic/single/authors.txt @@ -0,0 +1 @@ +Slava Pestov \ No newline at end of file diff --git a/core/generic/single/single-docs.factor b/core/generic/single/single-docs.factor new file mode 100644 index 0000000000..8f81be762c --- /dev/null +++ b/core/generic/single/single-docs.factor @@ -0,0 +1,27 @@ +USING: generic help.markup help.syntax sequences math +math.parser effects ; +IN: generic.single + +HELP: no-method +{ $values { "object" "an object" } { "generic" "a generic word" } } +{ $description "Throws a " { $link no-method } " error." } +{ $error-description "Thrown by the " { $snippet "generic" } " word to indicate it does not have a method for the class of " { $snippet "object" } "." } ; + +HELP: inconsistent-next-method +{ $error-description "Thrown by " { $link POSTPONE: call-next-method } " if the values on the stack are not compatible with the current method." } +{ $examples + "The following code throws this error:" + { $code + "GENERIC: error-test ( object -- )" + "" + "M: string error-test print ;" + "" + "M: integer error-test number>string call-next-method ;" + "" + "123 error-test" + } + "This results in the method on " { $link integer } " being called, which then passes a string to " { $link POSTPONE: call-next-method } ". However, this fails because the string is not compatible with the current method." + $nl + "This usually indicates programmer error; if the intention above was to call the string method on the result of " { $link number>string } ", the code should be rewritten as follows:" + { $code "M: integer error-test number>string error-test ;" } +} ; \ No newline at end of file diff --git a/core/generic/standard/standard-tests.factor b/core/generic/single/single-tests.factor similarity index 88% rename from core/generic/standard/standard-tests.factor rename to core/generic/single/single-tests.factor index 58007f795f..c8cab970fd 100644 --- a/core/generic/standard/standard-tests.factor +++ b/core/generic/single/single-tests.factor @@ -1,11 +1,10 @@ -IN: generic.standard.tests -USING: tools.test math math.functions math.constants -generic.standard strings sequences arrays kernel accessors words -specialized-arrays.double byte-arrays bit-arrays parser -namespaces make quotations stack-checker vectors growable -hashtables sbufs prettyprint byte-vectors bit-vectors -specialized-vectors.double definitions generic sets graphs assocs -grouping see ; +IN: generic.single.tests +USING: tools.test math math.functions math.constants generic.standard +generic.single strings sequences arrays kernel accessors words +specialized-arrays.double byte-arrays bit-arrays parser namespaces +make quotations stack-checker vectors growable hashtables sbufs +prettyprint byte-vectors bit-vectors specialized-vectors.double +definitions generic sets graphs assocs grouping see eval ; GENERIC: lo-tag-test ( obj -- obj' ) @@ -249,23 +248,6 @@ M: string my-hook "a string" ; [ "a string" ] [ my-hook my-var set my-hook ] unit-test [ 1.0 my-var set my-hook ] [ T{ no-method f 1.0 my-hook } = ] must-fail-with -HOOK: my-tuple-hook my-var ( -- x ) - -M: sequence my-tuple-hook my-hook ; - -TUPLE: m-t-h-a ; - -M: m-t-h-a my-tuple-hook "foo" ; - -TUPLE: m-t-h-b < m-t-h-a ; - -M: m-t-h-b my-tuple-hook "bar" ; - -[ f ] [ - \ my-tuple-hook [ "engines" word-prop ] keep prefix - [ 1quotation infer ] map all-equal? -] unit-test - HOOK: call-next-hooker my-var ( -- x ) M: sequence call-next-hooker "sequence" ; @@ -281,9 +263,15 @@ M: growable call-next-hooker call-next-method "growable " prepend ; ] unit-test [ t ] [ - { } \ nth effective-method nip \ sequence \ nth method eq? + { } \ nth effective-method nip M\ sequence nth eq? ] unit-test [ t ] [ \ + \ nth effective-method nip dup \ nth "default-method" word-prop eq? and ] unit-test + +[ ] [ "IN: generic.single.tests GENERIC: xyz ( a -- b )" eval( -- ) ] unit-test +[ ] [ "IN: generic.single.tests MATH: xyz ( a b -- c )" eval( -- ) ] unit-test + +[ f ] [ "xyz" "generic.single.tests" lookup direct-entry-def>> ] unit-test +[ f ] [ "xyz" "generic.single.tests" lookup "decision-tree" word-prop ] unit-test \ No newline at end of file diff --git a/core/generic/single/single.factor b/core/generic/single/single.factor new file mode 100644 index 0000000000..4fe9ce5a36 --- /dev/null +++ b/core/generic/single/single.factor @@ -0,0 +1,256 @@ +! Copyright (C) 2009 Slava Pestov. +! See http://factorcode.org/license.txt for BSD license. +USING: accessors arrays assocs classes classes.algebra +combinators definitions generic hashtables kernel +kernel.private layouts math namespaces quotations +sequences words generic.single.private effects make ; +IN: generic.single + +ERROR: no-method object generic ; + +ERROR: inconsistent-next-method class generic ; + +TUPLE: single-combination ; + +PREDICATE: single-generic < generic + "combination" word-prop single-combination? ; + +GENERIC: dispatch# ( word -- n ) + +M: generic dispatch# "combination" word-prop dispatch# ; + +SYMBOL: assumed +SYMBOL: default +SYMBOL: generic-word +SYMBOL: combination + +: with-combination ( combination quot -- ) + [ combination ] dip with-variable ; inline + +HOOK: picker combination ( -- quot ) + +M: single-combination next-method-quot* ( class generic combination -- quot ) + [ + 2dup next-method dup [ + [ + pick "predicate" word-prop % + 1quotation , + [ inconsistent-next-method ] 2curry , + \ if , + ] [ ] make picker prepend + ] [ 3drop f ] if + ] with-combination ; + +: (effective-method) ( obj word -- method ) + [ [ order [ instance? ] with find-last nip ] keep method ] + [ "default-method" word-prop ] + bi or ; + +M: single-combination make-default-method + [ [ picker ] dip [ no-method ] curry append ] with-combination ; + +! ! ! Build an engine ! ! ! + +: find-default ( methods -- default ) + #! Side-effects methods. + [ object bootstrap-word ] dip delete-at* [ + drop generic-word get "default-method" word-prop + ] unless ; + +! 1. Flatten methods +TUPLE: predicate-engine methods ; + +: ( methods -- engine ) predicate-engine boa ; + +: push-method ( method specializer atomic assoc -- ) + [ + [ H{ } clone ] unless* + [ methods>> set-at ] keep + ] change-at ; + +: flatten-method ( class method assoc -- ) + [ [ flatten-class keys ] keep ] 2dip [ + [ spin ] dip push-method + ] 3curry each ; + +: flatten-methods ( assoc -- assoc' ) + H{ } clone [ [ flatten-method ] curry assoc-each ] keep ; + +! 2. Convert methods +: split-methods ( assoc class -- first second ) + [ [ nip class<= not ] curry assoc-filter ] + [ [ nip class<= ] curry assoc-filter ] 2bi ; + +: convert-methods ( assoc class word -- assoc' ) + over [ split-methods ] 2dip pick assoc-empty? + [ 3drop ] [ [ execute ] dip pick set-at ] if ; inline + +! 2.1 Convert tuple methods +TUPLE: echelon-dispatch-engine n methods ; + +C: echelon-dispatch-engine + +TUPLE: tuple-dispatch-engine echelons ; + +: push-echelon ( class method assoc -- ) + [ swap dup "layout" word-prop third ] dip + [ ?set-at ] change-at ; + +: echelon-sort ( assoc -- assoc' ) + #! Convert an assoc mapping classes to methods into an + #! assoc mapping echelons to assocs. The first echelon + #! is always there + H{ { 0 f } } clone [ [ push-echelon ] curry assoc-each ] keep ; + +: ( methods -- engine ) + echelon-sort + [ dupd ] assoc-map + \ tuple-dispatch-engine boa ; + +: convert-tuple-methods ( assoc -- assoc' ) + tuple bootstrap-word + \ convert-methods ; + +! 2.2 Convert hi-tag methods +TUPLE: hi-tag-dispatch-engine methods ; + +C: hi-tag-dispatch-engine + +: convert-hi-tag-methods ( assoc -- assoc' ) + \ hi-tag bootstrap-word + \ convert-methods ; + +! 3 Tag methods +TUPLE: tag-dispatch-engine methods ; + +C: tag-dispatch-engine + +: ( assoc -- engine ) + flatten-methods + convert-tuple-methods + convert-hi-tag-methods + ; + +! ! ! Compile engine ! ! ! +GENERIC: compile-engine ( engine -- obj ) + +: compile-engines ( assoc -- assoc' ) + [ compile-engine ] assoc-map ; + +: compile-engines* ( assoc -- assoc' ) + [ over assumed [ compile-engine ] with-variable ] assoc-map ; + +: direct-dispatch-table ( assoc n -- table ) + default get [ swap update ] keep ; + +: lo-tag-number ( class -- n ) + "type" word-prop dup num-tags get member? + [ drop object tag-number ] unless ; + +M: tag-dispatch-engine compile-engine + methods>> compile-engines* + [ [ lo-tag-number ] dip ] assoc-map + num-tags get direct-dispatch-table ; + +: num-hi-tags ( -- n ) num-types get num-tags get - ; + +: hi-tag-number ( class -- n ) "type" word-prop ; + +M: hi-tag-dispatch-engine compile-engine + methods>> compile-engines* + [ [ hi-tag-number num-tags get - ] dip ] assoc-map + num-hi-tags direct-dispatch-table ; + +: build-fast-hash ( methods -- buckets ) + >alist V{ } clone [ hashcode 1array ] distribute-buckets + [ compile-engines* >alist >array ] map ; + +M: echelon-dispatch-engine compile-engine + dup n>> 0 = [ + methods>> dup assoc-size { + { 0 [ drop default get ] } + { 1 [ >alist first second compile-engine ] } + } case + ] [ + methods>> compile-engines* build-fast-hash + ] if ; + +M: tuple-dispatch-engine compile-engine + tuple assumed [ + echelons>> compile-engines + dup keys supremum 1+ f + [ swap update ] keep + ] with-variable ; + +: sort-methods ( assoc -- assoc' ) + >alist [ keys sort-classes ] keep extract-keys ; + +: quote-methods ( assoc -- assoc' ) + [ 1quotation \ drop prefix ] assoc-map ; + +: methods-with-default ( engine -- assoc ) + methods>> clone default get object bootstrap-word pick set-at ; + +: keep-going? ( assoc -- ? ) + assumed get swap second first class<= ; + +: prune-redundant-predicates ( assoc -- default assoc' ) + { + { [ dup empty? ] [ drop [ "Unreachable" throw ] { } ] } + { [ dup length 1 = ] [ first second { } ] } + { [ dup keep-going? ] [ rest-slice prune-redundant-predicates ] } + [ [ first second ] [ rest-slice ] bi ] + } cond ; + +: class-predicates ( assoc -- assoc ) + [ [ "predicate" word-prop [ dup ] prepend ] dip ] assoc-map ; + +PREDICATE: predicate-engine-word < word "owner-generic" word-prop ; + +: ( -- word ) + generic-word get name>> "/predicate-engine" append f + dup generic-word get "owner-generic" set-word-prop ; + +M: predicate-engine-word stack-effect "owner-generic" word-prop stack-effect ; + +: define-predicate-engine ( alist -- word ) + [ ] dip + [ define ] [ drop generic-word get "engines" word-prop push ] [ drop ] 2tri ; + +M: predicate-engine compile-engine + methods-with-default + sort-methods + quote-methods + prune-redundant-predicates + class-predicates + [ peek ] [ alist>quot picker prepend define-predicate-engine ] if-empty ; + +M: word compile-engine ; + +M: f compile-engine ; + +: build-decision-tree ( generic -- methods ) + [ "engines" word-prop forget-all ] + [ V{ } clone "engines" set-word-prop ] + [ + "methods" word-prop clone + [ find-default default set ] + [ compile-engine ] bi + ] tri ; + +HOOK: inline-cache-quot combination ( word methods -- quot/f ) + +: define-inline-cache-quot ( word methods -- ) + [ drop ] [ inline-cache-quot ] 2bi >>direct-entry-def drop ; + +HOOK: mega-cache-quot combination ( methods -- quot/f ) + +M: single-combination perform-combination + [ + dup generic-word set + dup build-decision-tree + [ "decision-tree" set-word-prop ] + [ mega-cache-quot define ] + [ define-inline-cache-quot ] + 2tri + ] with-combination ; \ No newline at end of file diff --git a/core/generic/standard/authors.txt b/core/generic/standard/authors.txt index 1901f27a24..d4f5d6b3ae 100644 --- a/core/generic/standard/authors.txt +++ b/core/generic/standard/authors.txt @@ -1 +1 @@ -Slava Pestov +Slava Pestov \ No newline at end of file diff --git a/core/generic/standard/engines/engines.factor b/core/generic/standard/engines/engines.factor deleted file mode 100644 index b6cb9fc9f7..0000000000 --- a/core/generic/standard/engines/engines.factor +++ /dev/null @@ -1,53 +0,0 @@ -! Copyright (C) 2008 Slava Pestov. -! See http://factorcode.org/license.txt for BSD license. -USING: assocs kernel kernel.private namespaces quotations -generic math sequences combinators words classes.algebra arrays -; -IN: generic.standard.engines - -SYMBOL: default -SYMBOL: assumed -SYMBOL: (dispatch#) - -GENERIC: engine>quot ( engine -- quot ) - -: engines>quots ( assoc -- assoc' ) - [ engine>quot ] assoc-map ; - -: engines>quots* ( assoc -- assoc' ) - [ over assumed [ engine>quot ] with-variable ] assoc-map ; - -: if-small? ( assoc true false -- ) - [ dup assoc-size 4 <= ] 2dip if ; inline - -: linear-dispatch-quot ( alist -- quot ) - default get [ drop ] prepend swap - [ - [ [ dup ] swap [ eq? ] curry compose ] - [ [ drop ] prepose ] - bi* [ ] like - ] assoc-map - alist>quot ; - -: split-methods ( assoc class -- first second ) - [ [ nip class<= not ] curry assoc-filter ] - [ [ nip class<= ] curry assoc-filter ] 2bi ; - -: convert-methods ( assoc class word -- assoc' ) - over [ split-methods ] 2dip pick assoc-empty? [ - 3drop - ] [ - [ execute ] dip pick set-at - ] if ; inline - -: (picker) ( n -- quot ) - { - { 0 [ [ dup ] ] } - { 1 [ [ over ] ] } - { 2 [ [ pick ] ] } - [ 1- (picker) [ dip swap ] curry ] - } case ; - -: picker ( -- quot ) \ (dispatch#) get (picker) ; - -GENERIC: extra-values ( generic -- n ) diff --git a/core/generic/standard/engines/predicate/predicate.factor b/core/generic/standard/engines/predicate/predicate.factor deleted file mode 100644 index 152b112c2a..0000000000 --- a/core/generic/standard/engines/predicate/predicate.factor +++ /dev/null @@ -1,38 +0,0 @@ -! Copyright (C) 2008 Slava Pestov. -! See http://factorcode.org/license.txt for BSD license. -USING: generic.standard.engines generic namespaces kernel -kernel.private sequences classes.algebra accessors words -combinators assocs arrays ; -IN: generic.standard.engines.predicate - -TUPLE: predicate-dispatch-engine methods ; - -C: predicate-dispatch-engine - -: class-predicates ( assoc -- assoc ) - [ [ "predicate" word-prop picker prepend ] dip ] assoc-map ; - -: keep-going? ( assoc -- ? ) - assumed get swap second first class<= ; - -: prune-redundant-predicates ( assoc -- default assoc' ) - { - { [ dup empty? ] [ drop [ "Unreachable" throw ] { } ] } - { [ dup length 1 = ] [ first second { } ] } - { [ dup keep-going? ] [ rest-slice prune-redundant-predicates ] } - [ [ first second ] [ rest-slice ] bi ] - } cond ; - -: sort-methods ( assoc -- assoc' ) - >alist [ keys sort-classes ] keep extract-keys ; - -: methods-with-default ( engine -- assoc ) - methods>> clone default get object bootstrap-word pick set-at ; - -M: predicate-dispatch-engine engine>quot - methods-with-default - engines>quots - sort-methods - prune-redundant-predicates - class-predicates - alist>quot ; diff --git a/core/generic/standard/engines/predicate/summary.txt b/core/generic/standard/engines/predicate/summary.txt deleted file mode 100644 index 47fee09ee5..0000000000 --- a/core/generic/standard/engines/predicate/summary.txt +++ /dev/null @@ -1 +0,0 @@ -Chained-conditional dispatch strategy diff --git a/core/generic/standard/engines/summary.txt b/core/generic/standard/engines/summary.txt deleted file mode 100644 index 209190799b..0000000000 --- a/core/generic/standard/engines/summary.txt +++ /dev/null @@ -1 +0,0 @@ -Generic word dispatch strategy implementation diff --git a/core/generic/standard/engines/tag/summary.txt b/core/generic/standard/engines/tag/summary.txt deleted file mode 100644 index 3eea4b11cf..0000000000 --- a/core/generic/standard/engines/tag/summary.txt +++ /dev/null @@ -1 +0,0 @@ -Jump table keyed by pointer tag dispatch strategy diff --git a/core/generic/standard/engines/tag/tag.factor b/core/generic/standard/engines/tag/tag.factor deleted file mode 100644 index 5ed33009c0..0000000000 --- a/core/generic/standard/engines/tag/tag.factor +++ /dev/null @@ -1,71 +0,0 @@ -! Copyright (C) 2008 Slava Pestov. -! See http://factorcode.org/license.txt for BSD license. -USING: classes.private generic.standard.engines namespaces make -arrays assocs sequences.private quotations kernel.private -math slots.private math.private kernel accessors words -layouts sorting sequences combinators ; -IN: generic.standard.engines.tag - -TUPLE: lo-tag-dispatch-engine methods ; - -C: lo-tag-dispatch-engine - -: direct-dispatch-quot ( alist n -- quot ) - default get - [ swap update ] keep - [ dispatch ] curry >quotation ; - -: lo-tag-number ( class -- n ) - dup \ hi-tag bootstrap-word eq? [ - drop \ hi-tag tag-number - ] [ - "type" word-prop - ] if ; - -: sort-tags ( assoc -- alist ) >alist sort-keys reverse ; - -: tag-dispatch-test ( tag# -- quot ) - picker [ tag ] append swap [ eq? ] curry append ; - -: tag-dispatch-quot ( alist -- quot ) - [ default get ] dip - [ [ tag-dispatch-test ] dip ] assoc-map - alist>quot ; - -M: lo-tag-dispatch-engine engine>quot - methods>> engines>quots* - [ [ lo-tag-number ] dip ] assoc-map - [ - [ sort-tags tag-dispatch-quot ] - [ picker % [ tag ] % num-tags get direct-dispatch-quot ] - if-small? % - ] [ ] make ; - -TUPLE: hi-tag-dispatch-engine methods ; - -C: hi-tag-dispatch-engine - -: convert-hi-tag-methods ( assoc -- assoc' ) - \ hi-tag bootstrap-word - \ convert-methods ; - -: num-hi-tags ( -- n ) num-types get num-tags get - ; - -: hi-tag-number ( class -- n ) - "type" word-prop ; - -: hi-tag-quot ( -- quot ) - \ hi-tag def>> ; - -M: hi-tag-dispatch-engine engine>quot - methods>> engines>quots* - [ [ hi-tag-number ] dip ] assoc-map - [ - picker % hi-tag-quot % [ - sort-tags linear-dispatch-quot - ] [ - num-tags get , \ fixnum-fast , - [ [ num-tags get - ] dip ] assoc-map - num-hi-tags direct-dispatch-quot - ] if-small? % - ] [ ] make ; diff --git a/core/generic/standard/engines/tuple/summary.txt b/core/generic/standard/engines/tuple/summary.txt deleted file mode 100644 index cb18ac5c78..0000000000 --- a/core/generic/standard/engines/tuple/summary.txt +++ /dev/null @@ -1 +0,0 @@ -Tuple class dispatch strategy diff --git a/core/generic/standard/engines/tuple/tuple.factor b/core/generic/standard/engines/tuple/tuple.factor deleted file mode 100644 index a0711af095..0000000000 --- a/core/generic/standard/engines/tuple/tuple.factor +++ /dev/null @@ -1,167 +0,0 @@ -! Copyright (c) 2008 Slava Pestov -! See http://factorcode.org/license.txt for BSD license. -USING: kernel classes.tuple.private hashtables assocs sorting -accessors combinators sequences slots.private math.parser words -effects namespaces make generic generic.standard.engines -classes.algebra math math.private kernel.private -quotations arrays definitions ; -IN: generic.standard.engines.tuple - -: nth-superclass% ( n -- ) 2 * 5 + , \ slot , ; inline - -: nth-hashcode% ( n -- ) 2 * 6 + , \ slot , ; inline - -: tuple-layout% ( -- ) - [ { tuple } declare 1 slot { array } declare ] % ; inline - -: tuple-layout-echelon% ( -- ) - [ 4 slot ] % ; inline - -TUPLE: echelon-dispatch-engine n methods ; - -C: echelon-dispatch-engine - -TUPLE: trivial-tuple-dispatch-engine n methods ; - -C: trivial-tuple-dispatch-engine - -TUPLE: tuple-dispatch-engine echelons ; - -: push-echelon ( class method assoc -- ) - [ swap dup "layout" word-prop third ] dip - [ ?set-at ] change-at ; - -: echelon-sort ( assoc -- assoc' ) - V{ } clone [ - [ - push-echelon - ] curry assoc-each - ] keep sort-keys ; - -: ( methods -- engine ) - echelon-sort - [ dupd ] assoc-map - \ tuple-dispatch-engine boa ; - -: convert-tuple-methods ( assoc -- assoc' ) - tuple bootstrap-word - \ convert-methods ; - -M: trivial-tuple-dispatch-engine engine>quot - [ n>> ] [ methods>> ] bi dup assoc-empty? [ - 2drop default get [ drop ] prepend - ] [ - [ - [ nth-superclass% ] - [ engines>quots* linear-dispatch-quot % ] bi* - ] [ ] make - ] if ; - -: hash-methods ( n methods -- buckets ) - >alist V{ } clone [ hashcode 1array ] distribute-buckets - [ ] with map ; - -: class-hash-dispatch-quot ( n methods -- quot ) - [ - \ dup , - [ drop nth-hashcode% ] - [ hash-methods [ engine>quot ] map hash-dispatch-quot % ] 2bi - ] [ ] make ; - -: engine-word-name ( -- string ) - generic get name>> "/tuple-dispatch-engine" append ; - -PREDICATE: engine-word < word - "tuple-dispatch-generic" word-prop generic? ; - -M: engine-word stack-effect - "tuple-dispatch-generic" word-prop - [ extra-values ] [ stack-effect ] bi - dup [ - [ in>> length + ] [ out>> ] [ terminated?>> ] tri - effect boa - ] [ 2drop f ] if ; - -M: engine-word where "tuple-dispatch-generic" word-prop where ; - -M: engine-word crossref? "forgotten" word-prop not ; - -: remember-engine ( word -- ) - generic get "engines" word-prop push ; - -: ( -- word ) - engine-word-name f - dup generic get "tuple-dispatch-generic" set-word-prop ; - -: define-engine-word ( quot -- word ) - [ dup ] dip define ; - -: tuple-dispatch-engine-body ( engine -- quot ) - [ - picker % - tuple-layout% - [ n>> ] [ methods>> ] bi - [ engine>quot ] - [ class-hash-dispatch-quot ] - if-small? % - ] [ ] make ; - -M: echelon-dispatch-engine engine>quot - dup n>> zero? [ - methods>> dup assoc-empty? - [ drop default get ] [ values first engine>quot ] if - ] [ - tuple-dispatch-engine-body - ] if ; - -: >=-case-quot ( default alist -- quot ) - [ [ drop ] prepend ] dip - [ - [ [ dup ] swap [ fixnum>= ] curry compose ] - [ [ drop ] prepose ] - bi* [ ] like - ] assoc-map - alist>quot ; - -: simplify-echelon-alist ( default alist -- default' alist' ) - dup empty? [ - dup first first 1 <= [ - nip unclip second swap - simplify-echelon-alist - ] when - ] unless ; - -: echelon-case-quot ( alist -- quot ) - #! We don't have to test for echelon 1 since all tuple - #! classes are at least at depth 1 in the inheritance - #! hierarchy. - default get swap simplify-echelon-alist - [ - [ - picker % - tuple-layout% - tuple-layout-echelon% - >=-case-quot % - ] [ ] make - ] unless-empty ; - -M: tuple-dispatch-engine engine>quot - [ - [ - tuple assumed set - echelons>> unclip-last - [ - [ - engine>quot - over 0 = [ - define-engine-word - [ remember-engine ] [ 1quotation ] bi - ] unless - dup default set - ] assoc-map - ] - [ first2 engine>quot 2array ] bi* - suffix - ] with-scope - echelon-case-quot % - ] [ ] make ; diff --git a/core/generic/standard/standard-docs.factor b/core/generic/standard/standard-docs.factor index 6e788eb947..33da0037b3 100644 --- a/core/generic/standard/standard-docs.factor +++ b/core/generic/standard/standard-docs.factor @@ -1,12 +1,7 @@ -USING: generic help.markup help.syntax sequences math +USING: generic generic.single help.markup help.syntax sequences math math.parser effects ; IN: generic.standard -HELP: no-method -{ $values { "object" "an object" } { "generic" "a generic word" } } -{ $description "Throws a " { $link no-method } " error." } -{ $error-description "Thrown by the " { $snippet "generic" } " word to indicate it does not have a method for the class of " { $snippet "object" } "." } ; - HELP: standard-combination { $class-description "Performs standard method combination." @@ -22,32 +17,6 @@ HELP: standard-combination } } ; -HELP: hook-combination -{ $class-description - "Performs hook method combination . See " { $link POSTPONE: HOOK: } "." -} ; - HELP: define-simple-generic { $values { "word" "a word" } { "effect" effect } } -{ $description "Defines a generic word with the " { $link standard-combination } " method combination and a dispatch position of 0." } ; - -{ standard-combination hook-combination } related-words - -HELP: inconsistent-next-method -{ $error-description "Thrown by " { $link POSTPONE: call-next-method } " if the values on the stack are not compatible with the current method." } -{ $examples - "The following code throws this error:" - { $code - "GENERIC: error-test ( object -- )" - "" - "M: string error-test print ;" - "" - "M: integer error-test number>string call-next-method ;" - "" - "123 error-test" - } - "This results in the method on " { $link integer } " being called, which then passes a string to " { $link POSTPONE: call-next-method } ". However, this fails because the string is not compatible with the current method." - $nl - "This usually indicates programmer error; if the intention above was to call the string method on the result of " { $link number>string } ", the code should be rewritten as follows:" - { $code "M: integer error-test number>string error-test ;" } -} ; +{ $description "Defines a generic word with the " { $link standard-combination } " method combination and a dispatch position of 0." } ; \ No newline at end of file diff --git a/core/generic/standard/standard.factor b/core/generic/standard/standard.factor index 5dbc0d17a1..96c273e3f8 100644 --- a/core/generic/standard/standard.factor +++ b/core/generic/standard/standard.factor @@ -1,180 +1,57 @@ -! Copyright (C) 2005, 2008 Slava Pestov. +! Copyright (C) 2009 Slava Pestov. ! See http://factorcode.org/license.txt for BSD license. -USING: arrays assocs kernel kernel.private slots.private math -namespaces make sequences vectors words quotations definitions -hashtables layouts combinators sequences.private generic -classes classes.algebra classes.private generic.standard.engines -generic.standard.engines.tag generic.standard.engines.predicate -generic.standard.engines.tuple accessors ; +USING: accessors definitions generic generic.single kernel +namespaces words math math.order combinators sequences +generic.single.private quotations kernel.private +assocs arrays layouts ; IN: generic.standard -GENERIC: dispatch# ( word -- n ) +TUPLE: standard-combination < single-combination # ; -M: generic dispatch# - "combination" word-prop dispatch# ; - -GENERIC: method-declaration ( class generic -- quot ) - -M: generic method-declaration - "combination" word-prop method-declaration ; - -M: quotation engine>quot - assumed get generic get method-declaration prepend ; - -ERROR: no-method object generic ; - -: error-method ( word -- quot ) - [ picker ] dip [ no-method ] curry append ; - -: push-method ( method specializer atomic assoc -- ) - [ - [ H{ } clone ] unless* - [ methods>> set-at ] keep - ] change-at ; - -: flatten-method ( class method assoc -- ) - [ [ flatten-class keys ] keep ] 2dip [ - [ spin ] dip push-method - ] 3curry each ; - -: flatten-methods ( assoc -- assoc' ) - H{ } clone [ - [ - flatten-method - ] curry assoc-each - ] keep ; - -: ( assoc -- engine ) - flatten-methods - convert-tuple-methods - convert-hi-tag-methods - ; - -: mangle-method ( method -- quot ) - 1quotation generic get extra-values \ drop - prepend [ ] like ; - -: find-default ( methods -- quot ) - #! Side-effects methods. - [ object bootstrap-word ] dip delete-at* [ - drop generic get "default-method" word-prop mangle-method - ] unless ; - -: ( word -- engine ) - object bootstrap-word assumed set { - [ generic set ] - [ "engines" word-prop forget-all ] - [ V{ } clone "engines" set-word-prop ] - [ - "methods" word-prop - [ mangle-method ] assoc-map - [ find-default default set ] - [ ] - bi - ] - } cleave ; - -: single-combination ( word -- quot ) - [ engine>quot ] with-scope ; - -ERROR: inconsistent-next-method class generic ; - -: single-next-method-quot ( class generic -- quot/f ) - 2dup next-method dup [ - [ - pick "predicate" word-prop % - 1quotation , - [ inconsistent-next-method ] 2curry , - \ if , - ] [ ] make - ] [ 3drop f ] if ; - -: single-effective-method ( obj word -- method ) - [ [ order [ instance? ] with find-last nip ] keep method ] - [ "default-method" word-prop ] - bi or ; - -TUPLE: standard-combination # ; - -C: standard-combination +: ( n -- standard-combination ) + dup 0 2 between? [ "Bad dispatch position" throw ] unless + standard-combination boa ; PREDICATE: standard-generic < generic "combination" word-prop standard-combination? ; PREDICATE: simple-generic < standard-generic - "combination" word-prop #>> zero? ; + "combination" word-prop #>> 0 = ; CONSTANT: simple-combination T{ standard-combination f 0 } : define-simple-generic ( word effect -- ) [ simple-combination ] dip define-generic ; -: with-standard ( combination quot -- quot' ) - [ #>> (dispatch#) ] dip with-variable ; inline +: (picker) ( n -- quot ) + { + { 0 [ [ dup ] ] } + { 1 [ [ over ] ] } + { 2 [ [ pick ] ] } + [ 1- (picker) [ dip swap ] curry ] + } case ; -M: standard-generic extra-values drop 0 ; - -M: standard-combination make-default-method - [ error-method ] with-standard ; - -M: standard-combination perform-combination - [ drop ] [ [ single-combination ] with-standard ] 2bi define ; +M: standard-combination picker + combination get #>> (picker) ; M: standard-combination dispatch# #>> ; -M: standard-combination method-declaration - dispatch# object swap prefix [ declare ] curry [ ] like ; - -M: standard-combination next-method-quot* - [ - single-next-method-quot - dup [ picker prepend ] when - ] with-standard ; - M: standard-generic effective-method - [ dispatch# (picker) call ] keep single-effective-method ; + [ datastack ] dip [ "combination" word-prop #>> swap nth ] keep + (effective-method) ; -TUPLE: hook-combination var ; +M: standard-combination inline-cache-quot ( word methods -- ) + #! Direct calls to the generic word (not tail calls or indirect calls) + #! will jump to the inline cache entry point instead of the megamorphic + #! dispatch entry point. + combination get #>> [ f inline-cache-miss ] 3curry [ ] like ; -C: hook-combination +: make-empty-cache ( -- array ) + mega-cache-size get f ; -PREDICATE: hook-generic < generic - "combination" word-prop hook-combination? ; - -: with-hook ( combination quot -- quot' ) - 0 (dispatch#) [ - [ hook-combination ] dip with-variable - ] with-variable ; inline - -: prepend-hook-var ( quot -- quot' ) - hook-combination get var>> [ get ] curry prepend ; - -M: hook-combination dispatch# drop 0 ; - -M: hook-combination method-declaration 2drop [ ] ; - -M: hook-generic extra-values drop 1 ; - -M: hook-generic effective-method - [ "combination" word-prop var>> get ] keep - single-effective-method ; - -M: hook-combination make-default-method - [ error-method prepend-hook-var ] with-hook ; - -M: hook-combination perform-combination - [ drop ] [ - [ single-combination prepend-hook-var ] with-hook - ] 2bi define ; - -M: hook-combination next-method-quot* - [ - single-next-method-quot - dup [ prepend-hook-var ] when - ] with-hook ; - -M: simple-generic definer drop \ GENERIC: f ; +M: standard-combination mega-cache-quot + combination get #>> make-empty-cache [ mega-cache-lookup ] 3curry [ ] like ; M: standard-generic definer drop \ GENERIC# f ; -M: hook-generic definer drop \ HOOK: f ; +M: simple-generic definer drop \ GENERIC: f ; diff --git a/core/generic/standard/summary.txt b/core/generic/standard/summary.txt deleted file mode 100644 index 5e731c6f15..0000000000 --- a/core/generic/standard/summary.txt +++ /dev/null @@ -1 +0,0 @@ -Standard method combination used for most generic words diff --git a/core/hashtables/hashtables-docs.factor b/core/hashtables/hashtables-docs.factor old mode 100644 new mode 100755 index 5a19cce351..0619e798dc --- a/core/hashtables/hashtables-docs.factor +++ b/core/hashtables/hashtables-docs.factor @@ -116,7 +116,7 @@ HELP: ?set-at { $description "If the third input is an assoc, stores the key/value pair into that assoc, or else creates a new hashtable with the key/value pair as its only entry." } ; HELP: >hashtable -{ $values { "assoc" "an assoc" } { "hashtable" "a hashtable" } } +{ $values { "assoc" assoc } { "hashtable" hashtable } } { $description "Constructs a hashtable from any assoc." } ; HELP: rehash diff --git a/core/init/init.factor b/core/init/init.factor index 5d8e88b85f..0140fcc0e8 100644 --- a/core/init/init.factor +++ b/core/init/init.factor @@ -1,7 +1,8 @@ ! Copyright (C) 2004, 2009 Slava Pestov. ! See http://factorcode.org/license.txt for BSD license. USING: continuations continuations.private kernel -kernel.private sequences assocs namespaces namespaces.private ; +kernel.private sequences assocs namespaces namespaces.private +continuations continuations.private ; IN: init SYMBOL: init-hooks diff --git a/core/io/files/files-tests.factor b/core/io/files/files-tests.factor index 8f0fb9e97a..f57dafbdc6 100644 --- a/core/io/files/files-tests.factor +++ b/core/io/files/files-tests.factor @@ -1,7 +1,7 @@ USING: arrays debugger.threads destructors io io.directories io.encodings.8-bit io.encodings.ascii io.encodings.binary io.files io.files.private io.files.temp io.files.unique kernel -make math sequences system threads tools.test generic.standard ; +make math sequences system threads tools.test generic.single ; IN: io.files.tests [ ] [ "append-test" temp-file dup exists? [ delete-file ] [ drop ] if ] unit-test diff --git a/core/io/files/files.factor b/core/io/files/files.factor index 1bc282e956..0f3041e670 100644 --- a/core/io/files/files.factor +++ b/core/io/files/files.factor @@ -20,13 +20,13 @@ HOOK: (file-appender) io-backend ( path -- stream ) swap normalize-path (file-appender) swap ; : file-lines ( path encoding -- seq ) - lines ; + stream-lines ; : with-file-reader ( path encoding quot -- ) [ ] dip with-input-stream ; inline : file-contents ( path encoding -- seq ) - contents ; + stream-contents ; : with-file-writer ( path encoding quot -- ) [ ] dip with-output-stream ; inline diff --git a/core/io/io-docs.factor b/core/io/io-docs.factor index 740152f294..3469a81064 100644 --- a/core/io/io-docs.factor +++ b/core/io/io-docs.factor @@ -221,10 +221,14 @@ HELP: bl { $description "Outputs a space character (" { $snippet "\" \"" } ") to " { $link output-stream } "." } $io-error ; -HELP: lines +HELP: stream-lines { $values { "stream" "an input stream" } { "seq" "a sequence of strings" } } { $description "Reads lines of text until the stream is exhausted, collecting them in a sequence of strings." } ; +HELP: lines +{ $values { "seq" "a sequence of strings" } } +{ $description "Reads lines of text until from the " { $link input-stream } " until it is exhausted, collecting them in a sequence of strings." } ; + HELP: each-line { $values { "quot" { $quotation "( str -- )" } } } { $description "Calls the quotation with successive lines of text, until the current " { $link input-stream } " is exhausted." } ; @@ -233,9 +237,14 @@ HELP: each-block { $values { "quot" { $quotation "( block -- )" } } } { $description "Calls the quotation with successive blocks of data, until the current " { $link input-stream } " is exhausted." } ; -HELP: contents +HELP: stream-contents { $values { "stream" "an input stream" } { "seq" "a string, byte array or " { $link f } } } -{ $description "Reads the entire contents of a stream. If the stream is empty, outputs" { $link f } "." } +{ $description "Reads the entire contents of a stream. If the stream is empty, outputs " { $link f } "." } +$io-error ; + +HELP: contents +{ $values { "seq" "a string, byte array or " { $link f } } } +{ $description "Reads the entire contents of a the stream stored in " { $link input-stream } ". If the stream is empty, outputs " { $link f } "." } $io-error ; ARTICLE: "stream-protocol" "Stream protocol" @@ -347,9 +356,11 @@ $nl "First, a simple composition of " { $link stream-write } " and " { $link stream-nl } ":" { $subsection stream-print } "Processing lines one by one:" +{ $subsection stream-lines } { $subsection lines } { $subsection each-line } "Processing blocks of data:" +{ $subsection stream-contents } { $subsection contents } { $subsection each-block } "Copying the contents of one stream to another:" diff --git a/core/io/io.factor b/core/io/io.factor index 74bba7769e..b43098bcd4 100644 --- a/core/io/io.factor +++ b/core/io/io.factor @@ -68,9 +68,12 @@ SYMBOL: error-stream : bl ( -- ) " " write ; -: lines ( stream -- seq ) +: stream-lines ( stream -- seq ) [ [ readln dup ] [ ] produce nip ] with-input-stream ; +: lines ( -- seq ) + input-stream get stream-lines ; + : each-line ( quot -- ) [ readln ] each-morsel ; inline -: contents ( stream -- seq ) +: stream-contents ( stream -- seq ) [ [ 65536 read-partial dup ] [ ] produce nip concat f like ] with-input-stream ; +: contents ( -- seq ) + input-stream get stream-contents ; + : each-block ( quot: ( block -- ) -- ) [ 8192 read-partial ] each-morsel ; inline diff --git a/core/io/streams/c/c-tests.factor b/core/io/streams/c/c-tests.factor index 3dde9152d0..6a82d6d545 100644 --- a/core/io/streams/c/c-tests.factor +++ b/core/io/streams/c/c-tests.factor @@ -5,6 +5,6 @@ IN: io.streams.c.tests [ "hello world" ] [ "hello world" "test.txt" temp-file ascii set-file-contents - "test.txt" temp-file "rb" fopen contents + "test.txt" temp-file "rb" fopen stream-contents >string ] unit-test diff --git a/core/kernel/kernel-docs.factor b/core/kernel/kernel-docs.factor index 1d8c09a9b2..e67e2bc0dd 100644 --- a/core/kernel/kernel-docs.factor +++ b/core/kernel/kernel-docs.factor @@ -183,6 +183,20 @@ HELP: either? { $example "USING: kernel math prettyprint ;" "5 7 [ even? ] either? ." "f" } } ; +HELP: execute +{ $values { "word" word } } +{ $description "Executes a word. Words which " { $link execute } " an input parameter must be declared " { $link POSTPONE: inline } " so that a caller which passes in a literal word can have a static stack effect." } +{ $examples + { $example "USING: kernel io words ;" "IN: scratchpad" ": twice ( word -- ) dup execute execute ; inline\n: hello ( -- ) \"Hello\" print ;\n\\ hello twice" "Hello\nHello" } +} ; + +{ execute POSTPONE: execute( } related-words + +HELP: (execute) +{ $values { "word" word } } +{ $description "Executes a word without checking if it is a word first." } +{ $warning "This word is in the " { $vocab-link "kernel.private" } " vocabulary because it is unsafe. Calling with a parameter that is not a word will crash Factor. Use " { $link execute } " instead." } ; + HELP: call { $values { "callable" callable } } { $description "Calls a quotation. Words which " { $link call } " an input parameter must be declared " { $link POSTPONE: inline } " so that a caller which passes in a literal quotation can have a static stack effect." } diff --git a/core/layouts/layouts.factor b/core/layouts/layouts.factor index 5a32ca2dce..00b9500211 100644 --- a/core/layouts/layouts.factor +++ b/core/layouts/layouts.factor @@ -1,4 +1,4 @@ -! Copyright (C) 2007, 2008 Slava Pestov. +! Copyright (C) 2007, 2009 Slava Pestov. ! See http://factorcode.org/license.txt for BSD license. USING: namespaces math words kernel assocs classes math.order kernel.private ; @@ -16,12 +16,14 @@ SYMBOL: tag-numbers SYMBOL: type-numbers -: tag-number ( class -- n ) - tag-numbers get at [ object tag-number ] unless* ; +SYMBOL: mega-cache-size : type-number ( class -- n ) type-numbers get at ; +: tag-number ( class -- n ) + type-number dup num-tags get >= [ drop object tag-number ] when ; + : tag-fixnum ( n -- tagged ) tag-bits get shift ; diff --git a/core/math/math.factor b/core/math/math.factor index 42786ffc9d..993d8d0e76 100755 --- a/core/math/math.factor +++ b/core/math/math.factor @@ -1,4 +1,4 @@ -! Copyright (C) 2003, 2008 Slava Pestov. +! Copyright (C) 2003, 2009 Slava Pestov. ! See http://factorcode.org/license.txt for BSD license. USING: kernel math.private ; IN: math @@ -63,23 +63,22 @@ PRIVATE> : neg ( x -- -x ) 0 swap - ; inline : recip ( x -- y ) 1 swap / ; inline : sgn ( x -- n ) dup 0 < [ drop -1 ] [ 0 > 1 0 ? ] if ; inline - : ?1+ ( x -- y ) [ 1+ ] [ 0 ] if* ; inline - : rem ( x y -- z ) abs [ mod ] [ + ] [ mod ] tri ; foldable - : 2^ ( n -- 2^n ) 1 swap shift ; inline - : even? ( n -- ? ) 1 bitand zero? ; - : odd? ( n -- ? ) 1 bitand 1 number= ; UNION: integer fixnum bignum ; +TUPLE: ratio { numerator integer read-only } { denominator integer read-only } ; + UNION: rational integer ratio ; UNION: real rational float ; +TUPLE: complex { real real read-only } { imaginary real read-only } ; + UNION: number real complex ; GENERIC: fp-nan? ( x -- ? ) diff --git a/core/namespaces/namespaces-docs.factor b/core/namespaces/namespaces-docs.factor old mode 100644 new mode 100755 index 74d7c58963..cd66e781d2 --- a/core/namespaces/namespaces-docs.factor +++ b/core/namespaces/namespaces-docs.factor @@ -1,6 +1,6 @@ USING: help.markup help.syntax kernel kernel.private sequences words namespaces.private quotations vectors -math.parser math words.symbol ; +math.parser math words.symbol assocs ; IN: namespaces ARTICLE: "namespaces-combinators" "Namespace combinators" @@ -14,7 +14,8 @@ ARTICLE: "namespaces-change" "Changing variable values" { $subsection off } { $subsection inc } { $subsection dec } -{ $subsection change } ; +{ $subsection change } +{ $subsection change-global } ; ARTICLE: "namespaces-global" "Global variables" { $subsection namespace } @@ -73,6 +74,11 @@ HELP: change { $description "Applies the quotation to the old value of the variable, and assigns the resulting value to the variable." } { $side-effects "variable" } ; +HELP: change-global +{ $values { "variable" "a variable, by convention a symbol" } { "quot" { $quotation "( old -- new )" } } } +{ $description "Applies the quotation to the old value of the global variable, and assigns the resulting value to the global variable." } +{ $side-effects "variable" } ; + HELP: +@ { $values { "n" "a number" } { "variable" "a variable, by convention a symbol" } } { $description "Adds " { $snippet "n" } " to the value of the variable. A variable value of " { $link f } " is interpreted as being zero." } @@ -113,19 +119,19 @@ HELP: with-variable } ; HELP: make-assoc -{ $values { "quot" quotation } { "exemplar" "an assoc" } { "hash" "a new hashtable" } } +{ $values { "quot" quotation } { "exemplar" assoc } { "hash" "a new assoc" } } { $description "Calls the quotation in a new namespace of the same type as " { $snippet "exemplar" } ", and outputs this namespace when the quotation returns. Useful for quickly building assocs." } ; HELP: bind -{ $values { "ns" "a hashtable" } { "quot" quotation } } +{ $values { "ns" assoc } { "quot" quotation } } { $description "Calls the quotation in the dynamic scope of " { $snippet "ns" } ". When variables are looked up by the quotation, " { $snippet "ns" } " is checked first, and setting variables in the quotation stores them in " { $snippet "ns" } "." } ; HELP: namespace -{ $values { "namespace" "an assoc" } } +{ $values { "namespace" assoc } } { $description "Outputs the current namespace. Calls to " { $link set } " modify this namespace." } ; HELP: global -{ $values { "g" "an assoc" } } +{ $values { "g" assoc } } { $description "Outputs the global namespace. The global namespace is always checked last when looking up variable values." } ; HELP: get-global @@ -150,7 +156,7 @@ HELP: set-namestack { $description "Replaces the name stack with a copy of the given vector." } ; HELP: >n -{ $values { "namespace" "an assoc" } } +{ $values { "namespace" assoc } } { $description "Pushes a namespace on the name stack." } ; HELP: ndrop diff --git a/core/namespaces/namespaces.factor b/core/namespaces/namespaces.factor index b0e764c94d..310816cbf7 100644 --- a/core/namespaces/namespaces.factor +++ b/core/namespaces/namespaces.factor @@ -24,12 +24,13 @@ PRIVATE> : get-global ( variable -- value ) global at ; : set-global ( value variable -- ) global set-at ; : change ( variable quot -- ) [ [ get ] keep ] dip dip set ; inline +: change-global ( variable quot -- ) [ global ] dip change-at ; inline : +@ ( n variable -- ) [ 0 or + ] change ; : inc ( variable -- ) 1 swap +@ ; inline : dec ( variable -- ) -1 swap +@ ; inline : bind ( ns quot -- ) swap >n call ndrop ; inline -: counter ( variable -- n ) global [ 0 or 1+ dup ] change-at ; +: counter ( variable -- n ) [ 0 or 1+ dup ] change-global ; : make-assoc ( quot exemplar -- hash ) 20 swap new-assoc [ swap bind ] keep ; inline : with-scope ( quot -- ) 5 swap bind ; inline : with-variable ( value key quot -- ) [ associate ] dip bind ; inline -: initialize ( variable quot -- ) [ global ] dip [ unless* ] curry change-at ; inline \ No newline at end of file +: initialize ( variable quot -- ) [ unless* ] curry change-global ; inline \ No newline at end of file diff --git a/core/parser/parser.factor b/core/parser/parser.factor index 7908f40cbe..7915dc69e0 100644 --- a/core/parser/parser.factor +++ b/core/parser/parser.factor @@ -272,7 +272,7 @@ print-use-hook [ [ ] ] initialize : parse-stream ( stream name -- quot ) [ [ - lines dup parse-fresh + stream-lines dup parse-fresh [ nip ] [ finish-parsing ] 2bi forget-smudged ] with-source-file diff --git a/core/sequences/sequences-docs.factor b/core/sequences/sequences-docs.factor index 556e41249e..cfd96789b4 100755 --- a/core/sequences/sequences-docs.factor +++ b/core/sequences/sequences-docs.factor @@ -1,6 +1,6 @@ USING: arrays help.markup help.syntax math sequences.private vectors strings kernel math.order layouts -quotations generic.standard ; +quotations generic.single ; IN: sequences HELP: sequence @@ -1466,8 +1466,8 @@ ARTICLE: "sequences-combinators" "Sequence combinators" { $subsection produce } { $subsection produce-as } "Filtering:" -{ $subsection push-if } { $subsection filter } +{ $subsection partition } "Testing if a sequence contains elements satisfying a predicate:" { $subsection any? } { $subsection all? } diff --git a/core/sets/sets-docs.factor b/core/sets/sets-docs.factor index a122aa1240..3670b10d3c 100755 --- a/core/sets/sets-docs.factor +++ b/core/sets/sets-docs.factor @@ -1,4 +1,4 @@ -USING: kernel help.markup help.syntax sequences quotations ; +USING: kernel help.markup help.syntax sequences quotations assocs ; IN: sets ARTICLE: "sets" "Set-theoretic operations on sequences" @@ -42,7 +42,7 @@ HELP: adjoin { $side-effects "seq" } ; HELP: conjoin -{ $values { "elt" object } { "assoc" "an assoc" } } +{ $values { "elt" object } { "assoc" assoc } } { $description "Stores a key/value pair, both equal to " { $snippet "elt" } ", into the assoc." } { $examples { $example @@ -54,7 +54,7 @@ HELP: conjoin { $side-effects "assoc" } ; HELP: unique -{ $values { "seq" "a sequence" } { "assoc" "an assoc" } } +{ $values { "seq" "a sequence" } { "assoc" assoc } } { $description "Outputs a new assoc where the keys and values are equal." } { $examples { $example "USING: sets prettyprint ;" "{ 1 1 2 2 3 3 } unique ." "H{ { 1 1 } { 2 2 } { 3 3 } }" } diff --git a/core/slots/slots-tests.factor b/core/slots/slots-tests.factor index 7ac8446842..1365e81524 100644 --- a/core/slots/slots-tests.factor +++ b/core/slots/slots-tests.factor @@ -1,5 +1,5 @@ IN: slots.tests -USING: math accessors slots strings generic.standard kernel +USING: math accessors slots strings generic.single kernel tools.test generic words parser eval math.functions ; TUPLE: r/w-test foo ; diff --git a/core/strings/strings-tests.factor b/core/strings/strings-tests.factor index 5b71b13552..22bf7bb821 100644 --- a/core/strings/strings-tests.factor +++ b/core/strings/strings-tests.factor @@ -58,7 +58,7 @@ unit-test [ "\u001234bc\0\0\0" ] [ 6 "\u001234bc" resize-string ] unit-test ! Random tester found this -[ 2 -7 resize-string ] [ { "kernel-error" 3 12 -7 } = ] must-fail-with +[ 2 -7 resize-string ] [ { "kernel-error" 3 11 -7 } = ] must-fail-with ! Make sure 24-bit strings work "hello world" "s" set diff --git a/core/syntax/syntax-docs.factor b/core/syntax/syntax-docs.factor index 7ab287fd20..e8f86faa9d 100644 --- a/core/syntax/syntax-docs.factor +++ b/core/syntax/syntax-docs.factor @@ -1,7 +1,7 @@ USING: generic help.syntax help.markup kernel math parser words effects classes generic.standard classes.tuple generic.math -generic.standard arrays io.pathnames vocabs.loader io sequences -assocs words.symbol words.alias words.constant combinators ; +generic.standard generic.single arrays io.pathnames vocabs.loader io +sequences assocs words.symbol words.alias words.constant combinators ; IN: syntax ARTICLE: "parser-algorithm" "Parser algorithm" diff --git a/core/syntax/syntax.factor b/core/syntax/syntax.factor index 2e072f72d8..3512b92e4c 100644 --- a/core/syntax/syntax.factor +++ b/core/syntax/syntax.factor @@ -4,7 +4,7 @@ USING: accessors alien arrays byte-arrays definitions generic hashtables kernel math namespaces parser lexer sequences strings strings.parser sbufs vectors words words.symbol words.constant words.alias quotations io assocs splitting classes.tuple -generic.standard generic.math generic.parser classes +generic.standard generic.hook generic.math generic.parser classes io.pathnames vocabs vocabs.parser classes.parser classes.union classes.intersection classes.mixin classes.predicate classes.singleton classes.tuple.parser compiler.units diff --git a/core/vocabs/vocabs.factor b/core/vocabs/vocabs.factor index 2b978e8666..6c12b7b325 100644 --- a/core/vocabs/vocabs.factor +++ b/core/vocabs/vocabs.factor @@ -65,8 +65,22 @@ M: object vocab-main vocab vocab-main ; M: f vocab-main ; +SYMBOL: vocab-observers + +GENERIC: vocabs-changed ( obj -- ) + +: add-vocab-observer ( obj -- ) + vocab-observers get push ; + +: remove-vocab-observer ( obj -- ) + vocab-observers get delq ; + +: notify-vocab-observers ( -- ) + vocab-observers get [ vocabs-changed ] each ; + : create-vocab ( name -- vocab ) - dictionary get [ ] cache ; + dictionary get [ ] cache + notify-vocab-observers ; ERROR: no-vocab name ; @@ -99,7 +113,8 @@ M: string >vocab-link dup vocab [ ] [ ] ?if ; : forget-vocab ( vocab -- ) dup words forget-all - vocab-name dictionary get delete-at ; + vocab-name dictionary get delete-at + notify-vocab-observers ; M: vocab-spec forget* forget-vocab ; diff --git a/core/words/words-docs.factor b/core/words/words-docs.factor index 94609a06e5..3725086f70 100644 --- a/core/words/words-docs.factor +++ b/core/words/words-docs.factor @@ -1,5 +1,5 @@ USING: definitions help.markup help.syntax kernel parser -kernel.private words.private vocabs classes quotations +kernel.private vocabs classes quotations strings effects compiler.units ; IN: words @@ -163,15 +163,6 @@ $nl ABOUT: "words" -HELP: execute ( word -- ) -{ $values { "word" word } } -{ $description "Executes a word. Words which " { $link execute } " an input parameter must be declared " { $link POSTPONE: inline } " so that a caller which passes in a literal word can have a static stack effect." } -{ $examples - { $example "USING: kernel io words ;" "IN: scratchpad" ": twice ( word -- ) dup execute execute ; inline\n: hello ( -- ) \"Hello\" print ;\n\\ hello twice" "Hello\nHello" } -} ; - -{ execute POSTPONE: execute( } related-words - HELP: deferred { $class-description "The class of deferred words created by " { $link POSTPONE: DEFER: } "." } ; diff --git a/core/words/words.factor b/core/words/words.factor index eb0599db78..1976c1e4cd 100755 --- a/core/words/words.factor +++ b/core/words/words.factor @@ -1,9 +1,9 @@ ! Copyright (C) 2004, 2009 Slava Pestov. ! See http://factorcode.org/license.txt for BSD license. USING: accessors arrays definitions graphs assocs kernel -kernel.private slots.private math namespaces sequences strings -vectors sbufs quotations assocs hashtables sorting words.private -vocabs math.order sets ; +kernel.private kernel.private slots.private math namespaces sequences +strings vectors sbufs quotations assocs hashtables sorting vocabs +math.order sets ; IN: words : word ( -- word ) \ word get-global ; @@ -154,8 +154,16 @@ M: word reset-word : reset-generic ( word -- ) [ subwords forget-all ] [ reset-word ] - [ { "methods" "combination" "default-method" } reset-props ] - tri ; + [ + f >>direct-entry-def + { + "methods" + "combination" + "default-method" + "engines" + "decision-tree" + } reset-props + ] tri ; : gensym ( -- word ) "( gensym )" f ; diff --git a/extra/audio/audio.factor b/extra/audio/audio.factor new file mode 100644 index 0000000000..04df36ebd6 --- /dev/null +++ b/extra/audio/audio.factor @@ -0,0 +1,23 @@ +USING: accessors alien arrays combinators kernel math openal ; +IN: audio + +TUPLE: audio + { channels integer } + { sample-bits integer } + { sample-rate integer } + { size integer } + { data c-ptr } ; + +C: