]> gitweb.factorcode.org Git - factor.git/commitdiff
Merge branch 'master' of git://projects.elasticdog.com/git/factor
authorSlava Pestov <slava@slava-pestovs-macbook-pro.local>
Thu, 6 Nov 2008 08:00:08 +0000 (02:00 -0600)
committerSlava Pestov <slava@slava-pestovs-macbook-pro.local>
Thu, 6 Nov 2008 08:00:08 +0000 (02:00 -0600)
75 files changed:
basis/bootstrap/compiler/compiler.factor
basis/bootstrap/image/image.factor
basis/bootstrap/random/random.factor [deleted file]
basis/bootstrap/stage2.factor
basis/compiler/cfg/def-use/def-use.factor
basis/compiler/cfg/hats/hats.factor
basis/compiler/cfg/instructions/instructions.factor
basis/compiler/cfg/intrinsics/allot/allot.factor
basis/compiler/cfg/intrinsics/intrinsics.factor
basis/compiler/cfg/intrinsics/slots/slots.factor
basis/compiler/cfg/value-numbering/propagate/propagate.factor
basis/compiler/codegen/codegen.factor
basis/compiler/tree/propagation/info/info.factor
basis/compiler/tree/propagation/inlining/inlining.factor
basis/compiler/tree/propagation/known-words/known-words.factor
basis/compiler/tree/propagation/propagation-tests.factor
basis/compiler/tree/propagation/slots/slots.factor
basis/concurrency/mailboxes/mailboxes.factor
basis/concurrency/messaging/messaging.factor
basis/cpu/architecture/architecture.factor
basis/cpu/x86/x86.factor
basis/help/handbook/handbook.factor
basis/hints/hints.factor
basis/io/buffers/buffers.factor
basis/io/encodings/ascii/ascii.factor
basis/io/ports/ports.factor
basis/prettyprint/backend/backend.factor
basis/random/mersenne-twister/mersenne-twister.factor
basis/random/random.factor
basis/stack-checker/known-words/known-words.factor
basis/tools/deploy/backend/backend.factor
basis/tools/deploy/config/config-docs.factor
basis/tools/deploy/config/config.factor
basis/tools/deploy/test/1/deploy.factor
basis/tools/deploy/test/2/deploy.factor
basis/tools/deploy/test/3/deploy.factor
basis/tools/deploy/test/4/deploy.factor
basis/tools/deploy/test/5/deploy.factor
basis/tools/deploy/test/6/deploy.factor
basis/ui/tools/deploy/deploy.factor
core/bootstrap/layouts/layouts.factor
core/bootstrap/primitives.factor
core/bootstrap/stage1.factor
core/classes/tuple/tuple-docs.factor
core/classes/tuple/tuple-tests.factor
core/classes/tuple/tuple.factor
core/generic/standard/engines/tag/tag.factor
core/generic/standard/engines/tuple/tuple.factor
core/generic/standard/standard.factor
core/io/encodings/encodings.factor
extra/advice/advice-docs.factor [new file with mode: 0644]
extra/advice/advice-tests.factor [new file with mode: 0644]
extra/advice/advice.factor [new file with mode: 0644]
extra/advice/authors.txt [new file with mode: 0644]
extra/advice/summary.txt [new file with mode: 0644]
extra/advice/tags.txt [new file with mode: 0644]
extra/bunny/deploy.factor
extra/hello-ui/deploy.factor [changed mode: 0755->0644]
extra/hello-world/deploy.factor
extra/joystick-demo/deploy.factor
extra/lisp/lisp-docs.factor
extra/lisp/lisp-tests.factor
extra/lisp/lisp.factor
extra/lisp/parser/parser-tests.factor
extra/lisp/parser/parser.factor
extra/maze/deploy.factor
extra/spheres/deploy.factor
extra/sudoku/deploy.factor
extra/tetris/deploy.factor
extra/webkit-demo/deploy.factor
vm/data_gc.c
vm/debug.c
vm/layouts.h
vm/primitives.c
vm/types.c

index cbd2f0f41ec6da404529f35aae42575bf5805e49..dabdeea74148d28d25b54d7e9802d6b44bb6c12a 100644 (file)
@@ -89,14 +89,24 @@ nl
     . malloc calloc free memcpy
 } compile-uncompiled
 
+"." write flush
+
 { build-tree } compile-uncompiled
 
+"." write flush
+
 { optimize-tree } compile-uncompiled
 
+"." write flush
+
 { optimize-cfg } compile-uncompiled
 
+"." write flush
+
 { (compile) } compile-uncompiled
 
+"." write flush
+
 vocabs [ words compile-uncompiled "." write flush ] each
 
 " done" print flush
index 643899102eb970cecb317498f8c7ea8e3b1d4442..3816b930e0fbe6c9715887eb4f63de834ecec70b 100644 (file)
@@ -368,31 +368,35 @@ M: byte-array '
 
 M: tuple ' emit-tuple ;
 
-M: tuple-layout '
-    [
-        [
-            {
-                [ hashcode>> , ]
-                [ class>> , ]
-                [ size>> , ]
-                [ superclasses>> , ]
-                [ echelon>> , ]
-            } cleave
-        ] { } make [ ' ] map
-        \ tuple-layout type-number
-        object tag-number [ emit-seq ] emit-object
-    ] cache-object ;
-
 M: tombstone '
     state>> "((tombstone))" "((empty))" ?
     "hashtables.private" lookup def>> first
     [ emit-tuple ] cache-object ;
 
 ! Arrays
-M: array '
+: emit-array ( array -- offset )
     [ ' ] map array type-number object tag-number
     [ [ length emit-fixnum ] [ emit-seq ] bi ] emit-object ;
 
+M: array ' emit-array ;
+
+! This is a hack. We need to detect arrays which are tuple
+! layout arrays so that they can be internalized, but making
+! them a built-in type is not worth it.
+PREDICATE: tuple-layout-array < array
+    dup length 5 >= [
+        [ first tuple-class? ]
+        [ second fixnum? ]
+        [ third fixnum? ]
+        tri and and
+    ] [ drop f ] if ;
+
+M: tuple-layout-array '
+    [
+        [ dup integer? [ <fake-bignum> ] when ] map
+        emit-array
+    ] cache-object ;
+
 ! Quotations
 
 M: quotation '
diff --git a/basis/bootstrap/random/random.factor b/basis/bootstrap/random/random.factor
deleted file mode 100644 (file)
index f6527cd..0000000
+++ /dev/null
@@ -1,16 +0,0 @@
-USING: vocabs.loader sequences system
-random random.mersenne-twister combinators init
-namespaces random ;
-IN: bootstrap.random
-
-"random.mersenne-twister" require
-
-{
-    { [ os windows? ] [ "random.windows" require ] }
-    { [ os unix? ] [ "random.unix" require ] }
-} cond
-
-[
-    [ 32 random-bits ] with-system-random
-    <mersenne-twister> random-generator set-global
-] "bootstrap.random" add-init-hook
index 58ea725d1e31b5e326f343adf6bf975e876b7db8..3b6c04329c313d601ab98a29256d0ee4a2ad320c 100644 (file)
@@ -50,7 +50,7 @@ SYMBOL: bootstrap-time
 
     default-image-name "output-image" set-global
 
-    "math compiler threads help io tools ui ui.tools random unicode handbook" "include" set-global
+    "math compiler threads help io tools ui ui.tools unicode handbook" "include" set-global
     "" "exclude" set-global
 
     parse-command-line
index 2cbd7e54cbaee7f6cd5470eb9c5408563e01037c..7553407e00b8c3d3ef74498ea0fc6c2424a189ed 100644 (file)
@@ -14,6 +14,7 @@ M: ##allot defs-vregs dst/tmp-vregs ;
 M: ##dispatch defs-vregs temp>> 1array ;
 M: ##slot defs-vregs [ dst>> ] [ temp>> ] bi 2array ;
 M: ##set-slot defs-vregs temp>> 1array ;
+M: ##string-nth defs-vregs [ dst>> ] [ temp>> ] bi 2array ;
 M: insn defs-vregs drop f ;
 
 M: ##unary uses-vregs src>> 1array ;
@@ -24,6 +25,7 @@ M: ##slot uses-vregs [ obj>> ] [ slot>> ] bi 2array ;
 M: ##slot-imm uses-vregs obj>> 1array ;
 M: ##set-slot uses-vregs [ src>> ] [ obj>> ] [ slot>> ] tri 3array ;
 M: ##set-slot-imm uses-vregs [ src>> ] [ obj>> ] bi 2array ;
+M: ##string-nth uses-vregs [ obj>> ] [ index>> ] bi 2array ;
 M: ##conditional-branch uses-vregs [ src1>> ] [ src2>> ] bi 2array ;
 M: ##compare-imm-branch uses-vregs src1>> 1array ;
 M: ##dispatch uses-vregs src>> 1array ;
index 1c6480048c632129552159ad3994b475b8ee8a21..e6e05abbd5eb89c8fae414b9eb6b7e4e0a69cdc1 100644 (file)
@@ -22,6 +22,7 @@ IN: compiler.cfg.hats
 : ^^slot ( obj slot tag -- dst ) ^^i3 i ##slot ; inline
 : ^^slot-imm ( obj slot tag -- dst ) ^^i3 ##slot-imm ; inline
 : ^^set-slot ( src obj slot tag -- ) i ##set-slot ; inline
+: ^^string-nth ( obj index -- dst ) ^^i2 i ##string-nth ; inline
 : ^^add ( src1 src2 -- dst ) ^^i2 ##add ; inline
 : ^^add-imm ( src1 src2 -- dst ) ^^i2 ##add-imm ; inline
 : ^^sub ( src1 src2 -- dst ) ^^i2 ##sub ; inline
index 5ea74e97ec79fc32a8590c9dd670ddf5c402b739..c39f517671bc21912cf6dd623229a54687c4aa7c 100644 (file)
@@ -71,6 +71,9 @@ INSN: ##slot-imm < ##read { obj vreg } { slot integer } { tag integer } ;
 INSN: ##set-slot < ##write { obj vreg } { slot vreg } { tag integer } { temp vreg } ;
 INSN: ##set-slot-imm < ##write { obj vreg } { slot integer } { tag integer } ;
 
+! String element access
+INSN: ##string-nth < ##flushable { obj vreg } { index vreg } { temp vreg } ;
+
 ! Integer arithmetic
 INSN: ##add < ##commutative ;
 INSN: ##add-imm < ##commutative-imm ;
index f0796c59f0d09b736a8243bb1858be1a158730b2..ceac5e960cfb20aa82372fb43fb8cedd9b8c4cc5 100644 (file)
@@ -16,14 +16,14 @@ IN: compiler.cfg.intrinsics.allot
     [ ##set-slots ] [ [ drop ] [ ds-push ] [ drop ] tri* ] 3bi ;
 
 : tuple-slot-regs ( layout -- vregs )
-    [ size>> ds-load ] [ ^^load-literal ] bi prefix ;
+    [ second ds-load ] [ ^^load-literal ] bi prefix ;
 
 : emit-<tuple-boa> ( node -- )
     dup node-input-infos peek literal>>
-    dup tuple-layout? [
+    dup array? [
         nip
         ds-drop
-        [ tuple-slot-regs ] [ size>> ^^allot-tuple ] bi
+        [ tuple-slot-regs ] [ second ^^allot-tuple ] bi
         [ tuple ##set-slots ] [ ds-push drop ] 2bi
     ] [ drop emit-primitive ] if ;
 
index 3fd54d2e07a4b9d3c8317d3114d5298512d02c3e..ef1cde337a489fb5dc8e3abfa1be1c21c59dfef1 100644 (file)
@@ -14,6 +14,7 @@ QUALIFIED: arrays
 QUALIFIED: byte-arrays
 QUALIFIED: kernel.private
 QUALIFIED: slots.private
+QUALIFIED: strings.private
 QUALIFIED: classes.tuple.private
 QUALIFIED: math.private
 QUALIFIED: alien.accessors
@@ -38,6 +39,7 @@ IN: compiler.cfg.intrinsics
     kernel:eq?
     slots.private:slot
     slots.private:set-slot
+    strings.private:string-nth
     classes.tuple.private:<tuple-boa>
     arrays:<array>
     byte-arrays:<byte-array>
@@ -114,6 +116,7 @@ IN: compiler.cfg.intrinsics
         { \ math.private:fixnum>float [ drop emit-fixnum>float ] }
         { \ slots.private:slot [ emit-slot ] }
         { \ slots.private:set-slot [ emit-set-slot ] }
+        { \ strings.private:string-nth [ drop emit-string-nth ] }
         { \ classes.tuple.private:<tuple-boa> [ emit-<tuple-boa> ] }
         { \ arrays:<array> [ emit-<array> ] }
         { \ byte-arrays:<byte-array> [ emit-<byte-array> ] }
index cbc5d04c0b4bed2d20d21efb223b465e50425b43..22fb4e747be573eea3b3925dfb886c3f28bf0015 100644 (file)
@@ -51,3 +51,6 @@ IN: compiler.cfg.intrinsics.slots
         ] [ first class>> immediate class<= ] bi
         [ drop ] [ i i ##write-barrier ] if
     ] [ drop emit-primitive ] if ;
+
+: emit-string-nth ( -- )
+    2inputs swap ^^untag-fixnum ^^string-nth ^^tag-fixnum ds-push ;
index d08f2339951c20b00990e636389ff4fb19bdf7ed..a3c9725838fdf44de6e0b13fdf867fd0dea84d9d 100644 (file)
@@ -36,6 +36,10 @@ M: ##set-slot propagate
     [ resolve ] change-obj
     [ resolve ] change-slot ;
 
+M: ##string-nth propagate
+    [ resolve ] change-obj
+    [ resolve ] change-index ;
+
 M: ##set-slot-imm propagate
     call-next-method
     [ resolve ] change-obj ;
index 0d36a88b4526834fc2ede6e00a07ff53a663b17c..cab86dcb54220c16c02018d90d7a5a40aed97651 100644 (file)
@@ -123,6 +123,14 @@ M: ##set-slot generate-insn
 M: ##set-slot-imm generate-insn
     >set-slot< %set-slot-imm ;
 
+M: ##string-nth generate-insn
+    {
+        [ dst>> register ]
+        [ obj>> register ]
+        [ index>> register ]
+        [ temp>> register ]
+    } cleave %string-nth ;
+
 : dst/src ( insn -- dst src )
     [ dst>> register ] [ src>> register ] bi ; inline
 
index 5f8de4eb4923753484a99562a30141b3ef01bc4d..d1d8189f7a9eee76c72484f26206b4b5b1af05e1 100644 (file)
@@ -307,5 +307,5 @@ SYMBOL: value-infos
 : immutable-tuple-boa? ( #call -- ? )
     dup word>> \ <tuple-boa> eq? [
         dup in-d>> peek node-value-info
-        literal>> class>> immutable-tuple-class?
+        literal>> first immutable-tuple-class?
     ] [ drop f ] if ;
index 130b94cf6b99eead0f784a14887b2f5f3fee9c82..8397a5fdbb4d1a0bfff542f289eee0ac866c8293 100644 (file)
@@ -131,7 +131,7 @@ DEFER: (flat-length)
     ] bi* + + + + + ;
 
 : should-inline? ( #call word -- ? )
-    inlining-rank 5 >= ;
+    dup "inline" word-prop [ 2drop t ] [ inlining-rank 5 >= ] if ;
 
 SYMBOL: history
 
index a1ccaa95bd564b896c8448e19b5bfaa7ee2f2c54..3b698e000168a7a3cddeaee4644298e1372520a5 100644 (file)
@@ -281,7 +281,7 @@ generic-comparison-ops [
 
 { <tuple> <tuple-boa> } [
     [
-        literal>> dup tuple-layout? [ class>> ] [ drop tuple ] if <class-info>
+        literal>> dup array? [ first ] [ drop tuple ] if <class-info>
         [ clear ] dip
     ] "outputs" set-word-prop
 ] each
index 19ee051ac6706fff1340e2a196a78d5c90320d40..101320f92cdc88a92d66bd27ab58f86dc3452b30 100644 (file)
@@ -379,7 +379,7 @@ TUPLE: mutable-tuple-test { x sequence } ;
     [ T{ mutable-tuple-test f "hey" } x>> ] final-classes
 ] unit-test
 
-[ V{ tuple-layout } ] [
+[ V{ array } ] [
     [ T{ mutable-tuple-test f "hey" } layout-of ] final-classes
 ] unit-test
 
index 08a8520d0a376d75c97c9c7654e40cc89df315a1..83e71c336314c6201cbb2a5526ba1d633f63857b 100644 (file)
@@ -45,7 +45,7 @@ UNION: fixed-length-sequence array byte-array string ;
 
 : propagate-<tuple-boa> ( #call -- info )
     in-d>> unclip-last
-    value-info literal>> class>> (propagate-tuple-constructor) ;
+    value-info literal>> first (propagate-tuple-constructor) ;
 
 : propagate-<complex> ( #call -- info )
     in-d>> [ value-info ] map complex <tuple-info> ;
index 6de546ca6097141929196e1476a9285648a94a23..39b21e0943d3571ba49f5e5d49548193ba531798 100644 (file)
@@ -2,7 +2,7 @@
 ! See http://factorcode.org/license.txt for BSD license.\r
 IN: concurrency.mailboxes\r
 USING: dlists deques threads sequences continuations\r
-destructors namespaces random math quotations words kernel\r
+destructors namespaces math quotations words kernel\r
 arrays assocs init system concurrency.conditions accessors\r
 debugger debugger.threads locals ;\r
 \r
index 03d130452717e34eac12206d085027c3e3d5ad8f..9aeb24ed723d12f889de09e86a05005819ca2734 100644 (file)
@@ -4,7 +4,7 @@
 ! Concurrency library for Factor, based on Erlang/Termite style\r
 ! concurrency.\r
 USING: kernel threads concurrency.mailboxes continuations\r
-namespaces assocs random accessors summary ;\r
+namespaces assocs accessors summary ;\r
 IN: concurrency.messaging\r
 \r
 GENERIC: send ( message thread -- )\r
@@ -40,7 +40,7 @@ M: thread send ( message thread -- )
 TUPLE: synchronous data sender tag ;\r
 \r
 : <synchronous> ( data -- sync )\r
-    self 256 random-bits synchronous boa ;\r
+    self synchronous counter synchronous boa ;\r
 \r
 TUPLE: reply data tag ;\r
 \r
index c86f23697610c9a3f8434db82cfe193c83076b31..e4fa9419f061e97fbb3f8758cab6ba7009a89b02 100644 (file)
@@ -58,6 +58,8 @@ HOOK: %slot-imm cpu ( dst obj slot tag -- )
 HOOK: %set-slot cpu ( src obj slot tag temp -- )
 HOOK: %set-slot-imm cpu ( src obj slot tag -- )
 
+HOOK: %string-nth cpu ( dst obj index temp -- )
+
 HOOK: %add     cpu ( dst src1 src2 -- )
 HOOK: %add-imm cpu ( dst src1 src2 -- )
 HOOK: %sub     cpu ( dst src1 src2 -- )
index 83c9ee7f0d81a96c21241728f21a4d7269c30342..0e00ce60eec36afebc7d6c463c9edec963453049 100644 (file)
@@ -1,6 +1,6 @@
 ! Copyright (C) 2005, 2008 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: accessors assocs alien alien.c-types arrays
+USING: accessors assocs alien alien.c-types arrays strings
 cpu.x86.assembler cpu.x86.assembler.private cpu.architecture
 kernel kernel.private math memory namespaces make sequences
 words system layouts combinators math.order fry locals
@@ -278,27 +278,49 @@ M:: x86 %box-alien ( dst src temp -- )
 : small-regs ( -- regs ) { EAX ECX EDX EBX } ; inline
 
 : small-reg-that-isn't ( exclude -- reg' )
-    small-reg-4 small-regs [ eq? not ] with find nip ;
+    small-regs swap [ small-reg-4 ] map '[ _ memq? not ] find nip ;
 
 : with-save/restore ( reg quot -- )
     [ drop PUSH ] [ call ] [ drop POP ] 2tri ; inline
 
-:: with-small-register ( dst src quot: ( dst src -- ) -- )
+:: with-small-register ( dst exclude quot: ( new-dst -- ) -- )
     #! If the destination register overlaps a small register, we
     #! call the quot with that. Otherwise, we find a small
-    #! register that is not equal to src, and call quot, saving
+    #! register that is not in exclude, and call quot, saving
     #! and restoring the small register.
-    dst small-reg-4 small-regs memq? [ dst src quot call ] [
-        src small-reg-that-isn't
-        [| new-dst |
-            new-dst src quot call
-            dst new-dst MOV
-        ] with-save/restore
+    dst small-reg-4 small-regs memq? [ dst quot call ] [
+        exclude small-reg-that-isn't
+        [ quot call ] with-save/restore
     ] if ; inline
 
-: %alien-integer-getter ( dst src size quot -- )
-    '[ [ dup _ small-reg dup ] [ [] ] bi* MOV @ ]
-    with-small-register ; inline
+: aux-offset 2 cells string tag-number - ; inline
+
+M:: x86 %string-nth ( dst src index temp -- )
+    "end" define-label
+    dst { src index temp } [| new-dst |
+        temp src index [+] LEA
+        new-dst 1 small-reg temp string-offset [+] MOV
+        new-dst new-dst 1 small-reg MOVZX
+        temp src aux-offset [+] MOV
+        temp \ f tag-number CMP
+        "end" get JE
+        new-dst temp XCHG
+        new-dst index ADD
+        new-dst index ADD
+        new-dst 2 small-reg new-dst byte-array-offset [+] MOV
+        new-dst new-dst 2 small-reg MOVZX
+        new-dst 8 SHL
+        new-dst temp OR
+        "end" resolve-label
+        dst new-dst ?MOV
+    ] with-small-register ;
+
+:: %alien-integer-getter ( dst src size quot -- )
+    dst { src } [| new-dst |
+        new-dst dup size small-reg dup src [] MOV
+        quot call
+        dst new-dst ?MOV
+    ] with-small-register ; inline
 
 : %alien-unsigned-getter ( dst src size -- )
     [ MOVZX ] %alien-integer-getter ; inline
@@ -320,7 +342,7 @@ M: x86 %alien-float dupd [] MOVSS dup CVTSS2SD ;
 M: x86 %alien-double [] MOVSD ;
 
 :: %alien-integer-setter ( ptr value size -- )
-    value ptr [| new-value ptr |
+    value { ptr } [| new-value |
         new-value value ?MOV
         ptr [] new-value size small-reg MOV
     ] with-small-register ; inline
index 6aa19d43d58a0175a8d128fbfdab401a0668bb09..5b60102e467062b3a3cc2e7a10157fef21629a43 100644 (file)
@@ -86,14 +86,11 @@ ARTICLE: "objects" "Objects"
 { $subsection "slots" }
 { $subsection "mirrors" } ;
 
-USE: random
-
 ARTICLE: "numbers" "Numbers"
 { $subsection "arithmetic" }
 { $subsection "math-constants" }
 { $subsection "math-functions" }
 { $subsection "number-strings" }
-{ $subsection "random" }
 "Number implementations:"
 { $subsection "integers" }
 { $subsection "rationals" }
index a10588d7300a16fee81e64606245ba34c394420a..06ca209caee2e86cca04003c09df9bea62ad0166 100644 (file)
@@ -64,10 +64,12 @@ IN: hints
 { first first2 first3 first4 }
 [ { array } "specializer" set-word-prop ] each
 
-{ peek pop* pop push } [
+{ peek pop* pop } [
     { vector } "specializer" set-word-prop
 ] each
 
+\ push { { vector } { sbuf } } "specializer" set-word-prop
+
 \ push-all
 { { string sbuf } { array vector } { byte-array byte-vector } }
 "specializer" set-word-prop
index e6a0070ee0e5bc13c08d70cda15d3a279bfc8999..4df081b17de6932b8c381cf802cb131fd9aab23d 100644 (file)
@@ -36,9 +36,7 @@ M: buffer dispose* ptr>> free ;
     [ ptr>> ] [ pos>> ] bi alien-unsigned-1 ; inline
 
 : buffer-pop ( buffer -- byte )
-    [ buffer-peek ] [ 1 swap buffer-consume ] bi ;
-
-HINTS: buffer-pop buffer ;
+    [ buffer-peek ] [ 1 swap buffer-consume ] bi ; inline
 
 : buffer-length ( buffer -- n )
     [ fill>> ] [ pos>> ] bi - ; inline
@@ -69,14 +67,13 @@ HINTS: n>buffer fixnum buffer ;
 HINTS: >buffer byte-array buffer ;
 
 : byte>buffer ( byte buffer -- )
+    [ >fixnum ] dip
     [ [ ptr>> ] [ fill>> ] bi set-alien-unsigned-1 ]
     [ 1 swap n>buffer ]
-    bi ;
-
-HINTS: byte>buffer fixnum buffer ;
+    bi ; inline
 
 : search-buffer-until ( pos fill ptr separators -- n )
-    [ [ swap alien-unsigned-1 ] dip memq? ] 2curry find-from drop ;
+    [ [ swap alien-unsigned-1 ] dip memq? ] 2curry find-from drop ; inline
 
 : finish-buffer-until ( buffer n -- byte-array separator )
     [
@@ -86,7 +83,7 @@ HINTS: byte>buffer fixnum buffer ;
     ] [
         [ buffer-length ] keep
         buffer-read f
-    ] if* ;
+    ] if* ; inline
 
 : buffer-until ( separators buffer -- byte-array separator )
     swap [ { [ ] [ pos>> ] [ fill>> ] [ ptr>> ] } cleave ] dip
index 08dc8d07d91b081330f5e8a1cc109323ed831f4e..0803ba3871be14008780484d1829759e87a525a5 100644 (file)
@@ -9,7 +9,7 @@ IN: io.encodings.ascii
 
 : decode-if< ( stream encoding max -- character )
     nip swap stream-read1 dup
-    [ tuck > [ drop replacement-char ] unless ] [ 2drop f ] if ; inline
+    [ tuck > [ >fixnum ] [ drop replacement-char ] if ] [ 2drop f ] if ; inline
 PRIVATE>
 
 SINGLETON: ascii
index 909b2dcf3bfeb7d792edce4536f157fee131b3cb..6ee982fcda5ab62d30a5d60b336424b77e0f18ea 100644 (file)
@@ -100,7 +100,7 @@ TUPLE: output-port < buffered-port ;
 
 : wait-to-write ( len port -- )
     tuck buffer>> buffer-capacity <=
-    [ drop ] [ stream-flush ] if ;
+    [ drop ] [ stream-flush ] if ; inline
 
 M: output-port stream-write1
     dup check-disposed
@@ -161,4 +161,4 @@ HINTS: decoder-read-until { string input-port utf8 } { string input-port ascii }
 
 HINTS: decoder-readln { input-port utf8 } { input-port ascii } ;
 
-HINTS: decoder-write { string output-port utf8 } { string output-port ascii } ;
+HINTS: encoder-write { string output-port utf8 } { string output-port ascii } ;
index f8445c7783a8193363d5e5d8a132dc0c684457d7..b749bd63eb83b575a96293cfa44a619067fabb0c 100644 (file)
@@ -233,6 +233,3 @@ M: wrapper pprint*
     ] [
         pprint-object
     ] if ;
-
-M: tuple-layout pprint*
-    "( tuple layout )" swap present-text ;
index 0a730190c2b293eb6373e2a91a0cc7631719c376..712883e4b8e440fe7c5d4ab622a9a7351e1fc682 100644 (file)
@@ -68,3 +68,10 @@ M: mersenne-twister random-32* ( mt -- r )
     [ next-index ]
     [ seq>> nth mt-temper ]
     [ [ 1+ ] change-i drop ] tri ;
+
+USE: init
+
+[
+    [ 32 random-bits ] with-system-random
+    <mersenne-twister> random-generator set-global
+] "bootstrap.random" add-init-hook
index 845f8e004f999449f190ff2a2a6b0eff15cb295c..a0b62cf7de59aecb0729e36fc6e1191cc4501a5f 100755 (executable)
@@ -60,3 +60,12 @@ PRIVATE>
 
 : with-secure-random ( quot -- )
     secure-random-generator get swap with-random ; inline
+
+USE: vocabs.loader
+
+{
+    { [ os windows? ] [ "random.windows" require ] }
+    { [ os unix? ] [ "random.unix" require ] }
+} cond
+
+"random.mersenne-twister" require
index 2c0bae5328aaf142467d3179df297ed096e370e3..c40b94fd3ce757b2a5fb35aacceb9fc3476477b3 100644 (file)
@@ -108,7 +108,7 @@ M: object infer-call*
 
 : infer-<tuple-boa> ( -- )
     \ <tuple-boa>
-    peek-d literal value>> size>> 1+ { tuple } <effect>
+    peek-d literal value>> second 1+ { tuple } <effect>
     apply-word/effect ;
 
 : infer-(throw) ( -- )
@@ -561,9 +561,6 @@ do-primitive alien-invoke alien-indirect alien-callback
 \ <tuple> { tuple-layout } { tuple } define-primitive
 \ <tuple> make-flushable
 
-\ <tuple-layout> { word fixnum array fixnum } { tuple-layout } define-primitive
-\ <tuple-layout> make-foldable
-
 \ datastack { } { array } define-primitive
 \ datastack make-flushable
 
index a0565c6babca02ef2a4e52f434e8bdab8b8356b2..9431cb2c1982cae9d729369fce1d9e2d83ce58ed 100644 (file)
@@ -42,7 +42,7 @@ IN: tools.deploy.backend
         { "compiler" deploy-compiler? }
         { "threads"  deploy-threads?  }
         { "ui"       deploy-ui?       }
-        { "random"   deploy-random?   }
+        { "unicode"  deploy-unicode?  }
     } [ nip get ] assoc-filter keys
     native-io? [ "io" suffix ] when ;
 
index 2960cf452dd9b7afc3e6742a7e8cded76e8ca9e7..e8dcd2b90efea45d68af2f582c77df2dead7c1af 100644 (file)
@@ -16,7 +16,7 @@ ARTICLE: "deploy-flags" "Deployment flags"
 "There are two sets of deployment flags. The first set controls the major subsystems which are to be included in the deployment image:"
 { $subsection deploy-math?     }
 { $subsection deploy-compiler? }
-{ $subsection deploy-random?   }
+{ $subsection deploy-unicode?   }
 { $subsection deploy-threads?  }
 { $subsection deploy-ui?       }
 "The second set of flags controls the level of stripping to be performed on the deployment image; there is a trade-off between image size, and retaining functionality which is required by the application:"
@@ -73,10 +73,10 @@ HELP: deploy-compiler?
 $nl
 "On by default. Most programs should be compiled, not only for performance but because features which depend on the C library interface only function after compilation." } ;
 
-HELP: deploy-random?
-{ $description "Deploy flag. If set, the random number generator protocol is included, together with two implementations: a native OS-specific random number generator, and the Mersenne Twister."
+HELP: deploy-unicode?
+{ $description "Deploy flag. If set, full Unicode " { $link POSTPONE: CHAR: } " syntax is included."
 $nl
-"On by default. If your program does not generate random numbers you can disable this to save some space." } ;
+"Off by default. If your program needs to use " { $link POSTPONE: CHAR: } " with named characters, enable this flag." } ;
 
 HELP: deploy-threads?
 { $description "Deploy flag. If set, thread support will be included in the final image."
index 0ebda89b1522cf2524220a2a98ff309c2374092d..c78e0a32ba94d0d7b5fb94af9e911886ec8c7650 100644 (file)
@@ -10,7 +10,7 @@ SYMBOL: deploy-name
 SYMBOL: deploy-ui?
 SYMBOL: deploy-compiler?
 SYMBOL: deploy-math?
-SYMBOL: deploy-random?
+SYMBOL: deploy-unicode?
 SYMBOL: deploy-threads?
 
 SYMBOL: deploy-io
@@ -58,7 +58,7 @@ SYMBOL: deploy-image
         { deploy-reflection         1 }
         { deploy-compiler?          t }
         { deploy-threads?           t }
-        { deploy-random?            t }
+        { deploy-unicode?           f }
         { deploy-math?              t }
         { deploy-word-props?        f }
         { deploy-word-defs?         f }
index 6846b3b53e9509ecfdbd11ab0893f7c0d06f5d2a..6d6a1c1bd362939bf5cd5158f10698dd87b64059 100644 (file)
@@ -1,7 +1,6 @@
 USING: tools.deploy.config ;
 H{
     { deploy-threads? t }
-    { deploy-random? f }
     { deploy-c-types? f }
     { deploy-ui? f }
     { deploy-word-props? f }
index 4c34a77b66334e80327bad37bb68995106fed01a..1457769ce19a4bc44b1d1b8d0ca9a2846df148f1 100644 (file)
@@ -1,7 +1,6 @@
 USING: tools.deploy.config ;
 H{
     { deploy-threads? t }
-    { deploy-random? f }
     { deploy-c-types? f }
     { deploy-ui? f }
     { deploy-word-props? f }
index 84347164b6323b7530003294400b0346c7caef2a..b38c5da6767da39b42ee3a944b2c5318c66cb63b 100644 (file)
@@ -1,7 +1,6 @@
 USING: tools.deploy.config ;
 H{
     { deploy-threads? t }
-    { deploy-random? f }
     { deploy-c-types? f }
     { deploy-ui? f }
     { deploy-word-props? f }
index b1a6736bde603cd554cd9f3fd44698fb0e2d2e9e..981bbcf982739d4bb852a7d5ac78f0f0a8675157 100644 (file)
@@ -1,7 +1,6 @@
 USING: tools.deploy.config ;
 H{
     { deploy-threads? t }
-    { deploy-random? f }
     { deploy-c-types? f }
     { deploy-ui? f }
     { deploy-word-props? f }
index f5f8bc035291fbe5bb54cf46db0f6ce3915ebe59..22f50214975dbe99280fe29c2e5abc11c161cf14 100644 (file)
@@ -1,7 +1,6 @@
 USING: tools.deploy.config ;
 H{
     { deploy-threads? t }
-    { deploy-random? f }
     { deploy-c-types? f }
     { deploy-ui? f }
     { deploy-word-props? f }
index e7d3764d39c082d5e5d81df0571d94e2cb5020ae..c474fcdadfada8b972ebdd04ac72024dde755128 100644 (file)
@@ -5,7 +5,6 @@ H{
     { deploy-io 1 }
     { deploy-name "tools.deploy.test.6" }
     { deploy-math? t }
-    { deploy-random? f }
     { deploy-compiler? t }
     { deploy-ui? f }
     { deploy-c-types? f }
index e6180e9982f099d3040ffe273e835c9bb1b584ad..0ac89e122f6d23d1355860f54c347506fe5259ae 100644 (file)
@@ -36,7 +36,7 @@ TUPLE: deploy-gadget < pack vocab settings ;
     deploy-compiler? get "Use optimizing compiler" <checkbox> add-gadget
     deploy-math? get "Rational and complex number support" <checkbox> add-gadget
     deploy-threads? get "Threading support" <checkbox> add-gadget
-    deploy-random? get "Random number generator support" <checkbox> add-gadget
+    deploy-unicode? get "Unicode character literal support" <checkbox> add-gadget
     deploy-word-props? get "Retain all word properties" <checkbox> add-gadget
     deploy-word-defs? get "Retain all word definitions" <checkbox> add-gadget
     deploy-c-types? get "Retain all C types" <checkbox> add-gadget ;
index 08df7403058f4cc55347db47256f685e6546f178..26100277a8433c69ec039110428e5126f8f17684 100644 (file)
@@ -9,7 +9,7 @@ BIN: 111 tag-mask set
 8 num-tags set
 3 tag-bits set
 
-18 num-types set
+17 num-types set
 
 H{
     { fixnum      BIN: 000 }
@@ -29,9 +29,8 @@ tag-numbers get H{
     { byte-array 10 }
     { callstack 11 }
     { string 12 }
-    { tuple-layout 13 }
+    { word 13 }
     { quotation 14 }
     { dll 15 }
     { alien 16 }
-    { word 17 }
 } assoc-union type-numbers set
index bbc86c2e3c200e46c74ca81445b7d38c9e207a11..3accb8a9b897c53970e6df78fed4581e939e3d62 100644 (file)
@@ -147,7 +147,6 @@ bootstrapping? on
 "alien" "alien" create register-builtin
 "word" "words" create register-builtin
 "byte-array" "byte-arrays" create register-builtin
-"tuple-layout" "classes.tuple.private" create register-builtin
 
 ! For predicate classes
 "predicate-instance?" "classes.predicate" create drop
@@ -272,14 +271,6 @@ bi
 
 "callstack" "kernel" create { } define-builtin
 
-"tuple-layout" "classes.tuple.private" create {
-    { "hashcode" { "fixnum" "math" } read-only }
-    { "class" { "word" "words" } initial: t read-only }
-    { "size" { "fixnum" "math" } read-only }
-    { "superclasses" { "array" "arrays" } initial: { } read-only }
-    { "echelon" { "fixnum" "math" } read-only }
-} define-builtin
-
 "tuple" "kernel" create
 [ { } define-builtin ]
 [ define-tuple-layout ]
@@ -510,7 +501,6 @@ tuple
     { "array>quotation" "quotations.private" }
     { "quotation-xt" "quotations" }
     { "<tuple>" "classes.tuple.private" }
-    { "<tuple-layout>" "classes.tuple.private" }
     { "profiling" "tools.profiler.private" }
     { "become" "kernel.private" }
     { "(sleep)" "threads.private" }
index efa7c4b8770ea28d7d568413879ccda41d3b8a8b..26a27ecefb76fc465a28334cb7478f2f87effaad 100644 (file)
@@ -49,4 +49,5 @@ load-help? off
             1 exit
         ] if
     ] %
-] [ ] make bootstrap-boot-quot set
+] [ ] make
+bootstrap-boot-quot set
index e16be25ce4314c517caaedccfe307d13f7ea4681..4d2c537522051ea604b9b6eeba6f716471ec82c8 100644 (file)
@@ -348,7 +348,7 @@ $nl
 { $list
     { { $snippet "\"predicate\"" } " - a quotation which tests if the top of the stack is an instance of this tuple class" }
     { { $snippet "\"slots\"" } " - a sequence of " { $link slot-spec } " instances" }
-    { { $snippet "\"tuple-layout\"" } " - a " { $link tuple-layout } " instance" }
+    { { $snippet "\"tuple-layout\"" } " - an array with the tuple size and superclasses encoded in a format amneable to fast method dispatch" }
 } } ;
 
 HELP: define-tuple-predicate
@@ -405,11 +405,11 @@ HELP: tuple>array ( tuple -- array )
 { $description "Outputs an array having the tuple's slots as elements. The first element is the tuple class word and remainder are declared slots." } ;
 
 HELP: <tuple> ( layout -- tuple )
-{ $values { "layout" tuple-layout } { "tuple" tuple } }
+{ $values { "layout" "a tuple layout array" } { "tuple" tuple } }
 { $description "Low-level tuple constructor. User code should never call this directly, and instead use " { $link new } "." } ;
 
 HELP: <tuple-boa> ( ... layout -- tuple )
-{ $values { "..." "values" } { "layout" tuple-layout } { "tuple" tuple } }
+{ $values { "..." "values" } { "layout" "a tuple layout array" } { "tuple" tuple } }
 { $description "Low-level tuple constructor. User code should never call this directly, and instead use " { $link boa } "." } ;
 
 HELP: new
index 5c91bdf8dd8d1301b66654934fe50fed7440cf1f..8261e713a55228e3f091d150397cc67fd3a4ebfb 100644 (file)
@@ -94,7 +94,7 @@ TUPLE: size-test a b c d ;
 
 [ t ] [
     T{ size-test } tuple-size
-    size-test tuple-layout size>> =
+    size-test tuple-layout second =
 ] unit-test
 
 GENERIC: <yo-momma>
@@ -238,12 +238,6 @@ C: <laptop> laptop
 
 test-laptop-slot-values
 
-[ laptop ] [
-    "laptop" get 1 slot
-    dup echelon>> swap
-    superclasses>> nth
-] unit-test
-
 [ "TUPLE: laptop < computer battery ;" ] [
     [ \ laptop see ] with-string-writer string-lines second
 ] unit-test
index ef2cf616be2f5656400f8d008b41c3fefb56c26b..c2f93ead3e04f6a808dd96819380c037894fd24c 100644 (file)
@@ -10,8 +10,6 @@ IN: classes.tuple
 PREDICATE: tuple-class < class
     "metaclass" word-prop tuple-class eq? ;
 
-M: tuple class 1 slot 2 slot { word } declare ;
-
 ERROR: not-a-tuple object ;
 
 : check-tuple ( object -- tuple )
@@ -29,10 +27,12 @@ PREDICATE: immutable-tuple-class < tuple-class ( class -- ? )
     "layout" word-prop ;
 
 : layout-of ( tuple -- layout )
-    1 slot { tuple-layout } declare ; inline
+    1 slot { array } declare ; inline
+
+M: tuple class layout-of 2 slot { word } declare ;
 
 : tuple-size ( tuple -- size )
-    layout-of size>> ; inline
+    layout-of second ; inline
 
 : prepare-tuple>array ( tuple -- n tuple layout )
     check-tuple [ tuple-size ] [ ] [ layout-of ] tri ;
@@ -59,7 +59,7 @@ PRIVATE>
 : tuple>array ( tuple -- array )
     prepare-tuple>array
     >r copy-tuple-slots r>
-    class>> prefix ;
+    first prefix ;
 
 : tuple-slots ( tuple -- seq )
     prepare-tuple>array drop copy-tuple-slots ;
@@ -90,15 +90,19 @@ ERROR: bad-superclass class ;
         2drop f
     ] if ; inline
 
-: tuple-instance? ( object class echelon -- ? )
+: tuple-instance? ( object class offset -- ? )
     #! 4 slot == superclasses>>
     rot dup tuple? [
-        layout-of 4 slot { array } declare
-        2dup 1 slot fixnum< [ array-nth eq? ] [ 3drop f ] if
+        layout-of
+        2dup 1 slot fixnum<=
+        [ swap slot eq? ] [ 3drop f ] if
     ] [ 3drop f ] if ; inline
 
+: layout-class-offset ( class -- n )
+    tuple-layout third 2 * 5 + ;
+
 : define-tuple-predicate ( class -- )
-    dup dup tuple-layout echelon>>
+    dup dup layout-class-offset
     [ tuple-instance? ] 2curry define-predicate ;
 
 : class-size ( class -- n )
@@ -145,10 +149,14 @@ ERROR: bad-superclass class ;
     define-accessors ;
 
 : make-tuple-layout ( class -- layout )
-    [ ]
-    [ [ superclass class-size ] [ "slots" word-prop length ] bi + ]
-    [ superclasses dup length 1- ] tri
-    <tuple-layout> ;
+    [
+        {
+            [ , ]
+            [ [ superclass class-size ] [ "slots" word-prop length ] bi + , ]
+            [ superclasses length 1- , ]
+            [ superclasses [ [ , ] [ hashcode , ] bi ] each ]
+        } cleave
+    ] { } make ;
 
 : define-tuple-layout ( class -- )
     dup make-tuple-layout "layout" set-word-prop ;
@@ -169,13 +177,13 @@ ERROR: bad-superclass class ;
     [ first3 update-slot ] with map ;
 
 : permute-slots ( old-values layout -- new-values )
-    [ class>> all-slots ] [ outdated-tuples get at ] bi
+    [ first all-slots ] [ outdated-tuples get at ] bi
     compute-slot-permutation
     apply-slot-permutation ;
 
 : update-tuple ( tuple -- newtuple )
     [ tuple-slots ] [ layout-of ] bi
-    [ permute-slots ] [ class>> ] bi
+    [ permute-slots ] [ first ] bi
     slots>tuple ;
 
 : outdated-tuple? ( tuple assoc -- ? )
@@ -284,7 +292,7 @@ M: tuple-class reset-class
 M: tuple-class rank-class drop 0 ;
 
 M: tuple-class instance?
-    dup tuple-layout echelon>> tuple-instance? ;
+    dup layout-class-offset tuple-instance? ;
 
 M: tuple-class (flatten-class) dup set ;
 
index 2043c99741e508ed0fef635398fc3b7b831627c7..c65726260c3e88dd2fc722277efe94b73c2d9f16 100644 (file)
@@ -3,7 +3,7 @@
 USING: classes.private generic.standard.engines namespaces make
 arrays assocs sequences.private quotations kernel.private
 math slots.private math.private kernel accessors words
-layouts ;
+layouts sorting sequences ;
 IN: generic.standard.engines.tag
 
 TUPLE: lo-tag-dispatch-engine methods ;
@@ -23,9 +23,11 @@ C: <lo-tag-dispatch-engine> lo-tag-dispatch-engine
     ] if ;
 
 M: lo-tag-dispatch-engine engine>quot
-    methods>> engines>quots* [ >r lo-tag-number r> ] assoc-map
+    methods>> engines>quots*
+    [ >r lo-tag-number r> ] assoc-map
     [
         picker % [ tag ] % [
+            ! >alist sort-keys reverse
             linear-dispatch-quot
         ] [
             num-tags get direct-dispatch-quot
index 8c61aa4240584ff658dc2927d1e5400265614eca..34447fb92dcf1f7c5743954d717f920a1f944513 100644 (file)
@@ -7,18 +7,28 @@ 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> echelon-dispatch-engine
 
-TUPLE: trivial-tuple-dispatch-engine methods ;
+TUPLE: trivial-tuple-dispatch-engine methods ;
 
 C: <trivial-tuple-dispatch-engine> trivial-tuple-dispatch-engine
 
 TUPLE: tuple-dispatch-engine echelons ;
 
 : push-echelon ( class method assoc -- )
-    >r swap dup "layout" word-prop echelon>> r>
+    [ swap dup "layout" word-prop third ] dip
     [ ?set-at ] change-at ;
 
 : echelon-sort ( assoc -- assoc' )
@@ -38,19 +48,20 @@ TUPLE: tuple-dispatch-engine echelons ;
     \ <tuple-dispatch-engine> convert-methods ;
 
 M: trivial-tuple-dispatch-engine engine>quot
-    methods>> engines>quots* linear-dispatch-quot ;
+    [
+        [ n>> nth-superclass% ]
+        [ methods>> engines>quots* linear-dispatch-quot % ] bi
+    ] [ ] make ;
 
-: hash-methods ( methods -- buckets )
+: hash-methods ( methods -- buckets )
     >alist V{ } clone [ hashcode 1array ] distribute-buckets
-    [ <trivial-tuple-dispatch-engine> ] map ;
-
-: word-hashcode% ( -- ) [ 1 slot ] % ;
+    [ <trivial-tuple-dispatch-engine> ] with map ;
 
-: class-hash-dispatch-quot ( methods -- quot )
+: class-hash-dispatch-quot ( methods -- quot )
     [
         \ dup ,
-        word-hashcode%
-        hash-methods [ engine>quot ] map hash-dispatch-quot %
+        [ drop nth-hashcode% ]
+        [ hash-methods [ engine>quot ] map hash-dispatch-quot % ] 2bi
     ] [ ] make ;
 
 : engine-word-name ( -- string )
@@ -79,29 +90,16 @@ M: engine-word irrelevant? drop t ;
     dup generic get "tuple-dispatch-generic" set-word-prop ;
 
 : define-engine-word ( quot -- word )
-    >r <engine-word> dup r> define ;
-
-: array-nth% ( n -- ) 2 + , [ slot { word } declare ] % ;
-
-: tuple-layout-superclasses% ( -- )
-    [
-        { tuple } declare
-        1 slot { tuple-layout } declare
-        4 slot { array } declare
-    ] % ; inline
+    [ <engine-word> dup ] dip define ;
 
 : tuple-dispatch-engine-body ( engine -- quot )
     [
         picker %
-        tuple-layout-superclasses%
-        [ n>> array-nth% ]
-        [
-            methods>> [
-                <trivial-tuple-dispatch-engine> engine>quot
-            ] [
-                class-hash-dispatch-quot
-            ] if-small? %
-        ] bi
+        tuple-layout%
+        [ n>> ] [ methods>> ] bi
+        [ <trivial-tuple-dispatch-engine> engine>quot ]
+        [ class-hash-dispatch-quot ]
+        if-small? %
     ] [ ] make ;
 
 M: echelon-dispatch-engine engine>quot
@@ -109,22 +107,11 @@ M: echelon-dispatch-engine engine>quot
         methods>> dup assoc-empty?
         [ drop default get ] [ values first engine>quot ] if
     ] [
-        [
-            picker %
-            tuple-layout-superclasses%
-            [ n>> array-nth% ]
-            [
-                methods>> [
-                    <trivial-tuple-dispatch-engine> engine>quot
-                ] [
-                    class-hash-dispatch-quot
-                ] if-small? %
-            ] bi
-        ] [ ] make
+        tuple-dispatch-engine-body
     ] if ;
 
-: >=-case-quot ( alist -- quot )
-    default get [ drop ] prepend swap
+: >=-case-quot ( default alist -- quot )
+    [ [ drop ] prepend ] dip
     [
         [ [ dup ] swap [ fixnum>= ] curry compose ]
         [ [ drop ] prepose ]
@@ -132,31 +119,34 @@ M: echelon-dispatch-engine engine>quot
     ] assoc-map
     alist>quot ;
 
-: tuple-layout-echelon% ( -- )
+: 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.
+    dup first first 1 = [ unclip second ] [ default get ] if swap
     [
-        { tuple } declare
-        1 slot { tuple-layout } declare
-        5 slot
-    ] % ; inline
+        [
+            picker %
+            tuple-layout%
+            tuple-layout-echelon%
+            >=-case-quot %
+        ] [ ] make
+    ] unless-empty ;
 
 M: tuple-dispatch-engine engine>quot
     [
-        picker %
-        tuple-layout-echelon%
         [
             tuple assumed set
-            echelons>> dup empty? [
-                unclip-last
+            echelons>> unclip-last
+            [
                 [
-                    [
-                        engine>quot define-engine-word
-                        [ remember-engine ] [ 1quotation ] bi
-                        dup default set
-                    ] assoc-map
-                ]
-                [ first2 engine>quot 2array ] bi*
-                suffix
-            ] unless
+                    engine>quot define-engine-word
+                    [ remember-engine ] [ 1quotation ] bi
+                    dup default set
+                ] assoc-map
+            ]
+            [ first2 engine>quot 2array ] bi*
+            suffix
         ] with-scope
-        >=-case-quot %
+        echelon-case-quot %
     ] [ ] make ;
index d22d20a0fc61430189141976aa2ef65ecc6db4a1..284a58836f3ee68715a60168909ce86581e0f7ef 100644 (file)
@@ -60,21 +60,22 @@ ERROR: no-method object generic ;
     [ 1quotation ] [ extra-values \ drop <repetition> ] bi*
     prepend [ ] like ;
 
+: <standard-engine> ( word -- engine )
+    object bootstrap-word assumed set {
+        [ generic set ]
+        [ "engines" word-prop forget-all ]
+        [ V{ } clone "engines" set-word-prop ]
+        [
+            "methods" word-prop
+            [ generic get mangle-method ] assoc-map
+            [ find-default default set ]
+            [ <big-dispatch-engine> ]
+            bi
+        ]
+    } cleave ;
+
 : single-combination ( word -- quot )
-    [
-        object bootstrap-word assumed set {
-            [ generic set ]
-            [ "engines" word-prop forget-all ]
-            [ V{ } clone "engines" set-word-prop ]
-            [
-                "methods" word-prop
-                [ generic get mangle-method ] assoc-map
-                [ find-default default set ]
-                [ <big-dispatch-engine> ]
-                bi engine>quot
-            ]
-        } cleave
-    ] with-scope ;
+    [ <standard-engine> engine>quot ] with-scope ;
 
 ERROR: inconsistent-next-method class generic ;
 
index 36cec298bdf0b4e26b697198a3a577d30ce17d79..48a428d36e6c480a7b789bee4b2e4395e662b603 100644 (file)
@@ -124,11 +124,11 @@ M: object <encoder> encoder boa ;
 M: encoder stream-write1
     >encoder< encode-char ;
 
-: decoder-write ( string stream encoding -- )
+: encoder-write ( string stream encoding -- )
     [ encode-char ] 2curry each ;
 
 M: encoder stream-write
-    >encoder< decoder-write ;
+    >encoder< encoder-write ;
 
 M: encoder dispose stream>> dispose ;
 
diff --git a/extra/advice/advice-docs.factor b/extra/advice/advice-docs.factor
new file mode 100644 (file)
index 0000000..2b33378
--- /dev/null
@@ -0,0 +1,22 @@
+IN: advice
+USING: help.markup help.syntax tools.annotations words ;
+
+HELP: make-advised
+{ $values { "word" "a word to annotate in preparation of advising" } }
+{ $description "Prepares a word for being advised.  This is done by: "
+    { $list
+        { "Annotating it to call the appropriate words before, around, and after the original body " }
+        { "Adding " { $snippet "before" } ", " { $snippet "around" } ", and " { $snippet "after" } " properties, which will contain the advice" }
+        { "Adding an " { $snippet "advised" } "property, which can later be used to determine if a given word is defined (see " { $link advised? } ")" }
+    }
+}
+{ $see-also advised? annotate } ;
+
+HELP: advised?
+{ $values { "word" "a word" } { "?" "t or f, indicating if " { $snippet word } " is advised" } }
+{ $description "Determines whether or not the given word has any advice on it." } ;
+
+ARTICLE: "advice" "Advice"
+"Advice is a simple way of adding additition functionality to words by adding 'hooks' to a word, which can act before, after, or around the calling of the word." ;
+
+ABOUT: "advice"
\ No newline at end of file
diff --git a/extra/advice/advice-tests.factor b/extra/advice/advice-tests.factor
new file mode 100644 (file)
index 0000000..17b60c8
--- /dev/null
@@ -0,0 +1,40 @@
+! Copyright (C) 2008 James Cash
+! See http://factorcode.org/license.txt for BSD license.
+USING: kernel sequences math tools.test advice parser namespaces ;
+IN: advice.tests
+
+[
+: foo "foo" ; 
+\ foo make-advised
+  { "bar" "foo" } [
+     [ "bar" ] "barify" \ foo advise-before
+     foo ] unit-test
+  { "bar" "foo" "baz" } [
+      [ "baz" ] "bazify" \ foo advise-after
+      foo ] unit-test
+  { "foo" "baz" } [
+     "barify" \ foo before remove-advice
+     foo ] unit-test
+: bar ( a -- b ) 1+ ;
+\ bar make-advised
+
+  { 11 } [
+     [ 2 * ] "double" \ bar advise-before
+     5 bar
+  ] unit-test 
+
+  { 11/3 } [
+      [ 3 / ] "third" \ bar advise-after
+      5 bar
+  ] unit-test
+
+  { -2 } [
+      [ -1 * ad-do-it 3 + ] "frobnobicate" \ bar advise-around
+      5 bar
+  ] unit-test
+ ] with-scope
\ No newline at end of file
diff --git a/extra/advice/advice.factor b/extra/advice/advice.factor
new file mode 100644 (file)
index 0000000..6a7d46f
--- /dev/null
@@ -0,0 +1,49 @@
+! Copyright (C) 2008 James Cash
+! See http://factorcode.org/license.txt for BSD license.
+USING: kernel sequences symbols fry words assocs tools.annotations coroutines ;
+IN: advice
+
+SYMBOLS: before after around advised ;
+
+<PRIVATE
+: advise ( quot name word loc --  )
+    word-prop set-at ;
+PRIVATE>
+    
+: advise-before ( quot name word --  )
+    before advise ;
+    
+: advise-after ( quot name word --  )
+    after advise ;
+
+: advise-around ( quot name word --  )
+    [ \ coterminate suffix ] 2dip
+    around advise ;
+
+: get-advice ( word type -- seq )
+    word-prop values ;
+
+: call-before ( word --  )
+    before get-advice [ call ] each ;
+
+: call-after ( word --  )
+    after get-advice [ call ] each ;
+
+: call-around ( main word --  )
+    around get-advice [ cocreate ] map tuck 
+    [ [ coresume ] each ] [ call ] [ reverse [ coresume ] each ] tri* ;
+
+: remove-advice ( name word loc --  )
+    word-prop delete-at ;
+
+: ad-do-it ( input -- result )
+    coyield ;
+
+: advised? ( word -- ? )
+    advised word-prop ;
+    
+: make-advised ( word -- )
+    [ dup [ over dup '[ _ call-before _ _ call-around _ call-after ] ] annotate ]
+    [ { before after around } [ H{ } clone swap set-word-prop ] with each ] 
+    [ t advised set-word-prop ] tri ;
+    
\ No newline at end of file
diff --git a/extra/advice/authors.txt b/extra/advice/authors.txt
new file mode 100644 (file)
index 0000000..4b7af4a
--- /dev/null
@@ -0,0 +1 @@
+James Cash
diff --git a/extra/advice/summary.txt b/extra/advice/summary.txt
new file mode 100644 (file)
index 0000000..a6f9c06
--- /dev/null
@@ -0,0 +1 @@
+Implmentation of advice/aspects
diff --git a/extra/advice/tags.txt b/extra/advice/tags.txt
new file mode 100644 (file)
index 0000000..a87b65d
--- /dev/null
@@ -0,0 +1,3 @@
+advice
+aspect
+annotations
index 55ac991df197eb47b952710902dd2d5d74723a05..0954c9ad4188b9dc222172b136c43b0c4373e115 100755 (executable)
@@ -4,7 +4,6 @@ H{
     { deploy-word-defs? f }
     { deploy-reflection 1 }
     { deploy-compiler? t }
-    { deploy-random? f }
     { deploy-c-types? f }
     { deploy-name "Bunny" }
     { deploy-word-props? f }
old mode 100755 (executable)
new mode 100644 (file)
index b21fd77..28ce8f5
@@ -8,7 +8,6 @@ H{
     { deploy-io 2 }
     { deploy-ui? t }
     { "stop-after-last-window?" t }
-    { deploy-random? f }
     { deploy-word-defs? f }
     { deploy-compiler? t }
     { deploy-reflection 1 }
index c683ef6e0624eb7596a5e9d852be2aeebe7ac95a..219fe0ca05d583ac1d1d06615f208c8eb183a40d 100755 (executable)
@@ -5,7 +5,6 @@ H{
     { deploy-threads? f }
     { deploy-word-props? f }
     { deploy-reflection 2 }
-    { deploy-random? f }
     { deploy-io 2 }
     { deploy-math? f }
     { deploy-ui? f }
index 8843ae66f341cabf75d5bf411c9a01e6c7346e60..8f25662f9e06654e84423fb04fbabb0a24882244 100644 (file)
@@ -4,7 +4,6 @@ H{
     { deploy-io 2 }
     { deploy-word-defs? f }
     { deploy-c-types? t }
-    { deploy-random? t }
     { deploy-word-props? f }
     { deploy-reflection 1 }
     { deploy-threads? t }
index 149f22864e2f9ea5a56ce83379f2bee59a7e038e..c970a1e0b7b943992c9abcab428cab6862b885aa 100644 (file)
@@ -1,5 +1,12 @@
 IN: lisp
 USING: help.markup help.syntax ;
+HELP: <LISP
+{ $description "parsing word which converts the lisp code between <LISP and LISP> into factor quotations and calls it" }
+{ $see-also lisp-string>factor } ;
+
+HELP: lisp-string>factor
+{ $values { "str"  "a string of lisp code" } { "quot" "the quotation the lisp compiles into" } }
+{ $description "Turns a string of lisp into a factor quotation" } ;
 
 ARTICLE: "lisp" "Lisp in Factor"
 "This is a simple implementation of a Lisp dialect, which somewhat resembles Scheme." $nl
index 48f6419d3031c5f32958f7fc7bf1d68a5369b4a3..5f849c441689fbc2731840e860e3e7a5d93dbe1c 100644 (file)
@@ -84,4 +84,11 @@ IN: lisp.test
         <LISP ((lambda (x y) (if x (+ 1 y) (+ 2 y))) #t 3) LISP>
     ] unit-test
     
+    { { 3 3 4 } } [
+        <LISP (defun foo (x y &rest z)
+                  (cons (+ x y) z))
+              (foo 1 2 3 4)
+        LISP> cons>seq
+    ] unit-test
+    
 ] with-interactive-vocabs
index e60529caab7511587c8ef3b6ac532255145dfc3d..4a933501e8705b0f075d3de13ef3cfe41c36d348 100644 (file)
@@ -64,14 +64,9 @@ PRIVATE>
 : macro-expand ( cons -- quot )
     uncons [ list>seq >quotation ] [ lookup-macro ] bi* call call ;
 
-<PRIVATE
-: (expand-macros) ( cons -- cons )
-    [ dup list? [ (expand-macros) dup car lisp-macro? [ macro-expand ] when ] when ] lmap ;
-PRIVATE>
-
 : expand-macros ( cons -- cons )
-    dup list? [ (expand-macros) dup car lisp-macro? [ macro-expand ] when ] when ;
-
+    dup list? [ [ expand-macros ] lmap dup car lisp-macro? [ macro-expand expand-macros ] when ] when ;
+    
 : convert-begin ( cons -- quot )
     cdr [ convert-form ] [ ] lmap-as [ 1 tail* ] [ but-last ] bi
     [ '[ { } _ with-datastack drop ] ] map prepend '[ _ [ call ] each ] ;
@@ -169,15 +164,15 @@ M: no-such-var summary drop "No such variable" ;
 
    "set" "lisp" "define-lisp-var" define-primitive
     
-   "(lambda (&rest xs) xs)" lisp-string>factor first "list" lisp-define
-   "(defmacro setq (var val) (list (quote set) (list (quote quote) var) val))" lisp-eval
+   "(set 'list (lambda (&rest xs) xs))" lisp-eval
+   "(defmacro setq (var val) (list 'set (list 'quote var) val))" lisp-eval
     
    <" (defmacro defun (name vars &rest body)
-        (list (quote setq) name (list (quote lambda) vars body))) "> lisp-eval
+        (list 'setq name (cons 'lambda (cons vars body)))) "> lisp-eval
     
-   "(defmacro if (pred tr fl) (list (quote cond) (list pred tr) (list (quote #t) fl)))" lisp-eval
+   "(defmacro if (pred tr fl) (list 'cond (list pred tr) (list (quote #t) fl)))" lisp-eval
    ;
 
 : <LISP 
-    "LISP>" parse-multiline-string define-lisp-builtins
-    lisp-string>factor parsed \ call parsed ; parsing
+    "LISP>" parse-multiline-string "(begin " prepend ")" append define-lisp-builtins
+    lisp-string>factor parsed \ call parsed ; parsing
\ No newline at end of file
index d722390f9a699c39c1c1ca1e89032d44a1a5aa6b..911a8d34401030fdcbe0b20ad93bdd2cac55a293 100644 (file)
@@ -65,4 +65,16 @@ IN: lisp.parser.tests
    }
 } [
     "(1 (3 4) 2)" lisp-expr
+] unit-test
+    
+{ { T{ lisp-symbol { name "quote" } } { 1 2 3 } } } [
+    "'(1 2 3)" lisp-expr cons>seq
+] unit-test
+    
+{ { T{ lisp-symbol f "quote" } T{ lisp-symbol f "foo" } } } [
+    "'foo" lisp-expr cons>seq
+] unit-test
+    
+{ { 1 2 { T{ lisp-symbol { name "quote" } } { 3 4 } } 5 } } [
+    "(1 2 '(3 4) 5)" lisp-expr cons>seq
 ] unit-test
\ No newline at end of file
index 72344fd0dc23e96d561793c3ff86a98e84ed3758..50f58692d5833ea2541544e882a1b52105b95826 100644 (file)
@@ -35,5 +35,7 @@ atom         = number
               | identifier
               | string
 s-expression = LPAREN (list-item)* RPAREN                => [[ second seq>cons ]]
-list-item    = _ ( atom | s-expression ) _               => [[ second ]]
-;EBNF
+list-item    = _ ( atom | s-expression | quoted ) _      => [[ second ]]
+quoted       = squote list-item                          => [[ second nil cons "quote" <lisp-symbol> swap cons ]]
+expr         = list-item
+;EBNF
\ No newline at end of file
index c00d32f67628b803d59191162a3858fb1d373d66..1eda31561755d097bd30edd30836a767133a85dd 100755 (executable)
@@ -8,7 +8,6 @@ H{
     { deploy-io 2 }
     { deploy-ui? t }
     { "stop-after-last-window?" t }
-    { deploy-random? t }
     { deploy-word-defs? f }
     { deploy-compiler? t }
     { deploy-reflection 1 }
index 0eeef1e3b7d32965fa3259dce7d6ec022b5bb23c..d6591a1a26781ae73d3844d6668278e8e9b98894 100644 (file)
@@ -1,7 +1,6 @@
 USING: tools.deploy.config ;
 H{
     { deploy-reflection 1 }
-    { deploy-random? t }
     { deploy-word-defs? f }
     { deploy-word-props? f }
     { deploy-name "Spheres" }
index 3d9101b19e4ffbe9b18c74f5f057d6bb59736d89..92c4395decf31bcb76d1b4885517628355ac5674 100755 (executable)
@@ -1,7 +1,6 @@
 USING: tools.deploy.config ;
 H{
     { deploy-word-defs? f }
-    { deploy-random? f }
     { deploy-name "Sudoku" }
     { deploy-threads? f }
     { deploy-compiler? t }
index a21e592cc8eae8235fbc02a05e027d56a34e2584..03ec5d4e6405b7f975e47fa5ce3792a2be12e93e 100755 (executable)
@@ -6,7 +6,6 @@ H{
     { deploy-word-props? f }
     { deploy-reflection 1 }
     { "stop-after-last-window?" t }
-    { deploy-random? t }
     { deploy-io 2 }
     { deploy-math? t }
     { deploy-word-defs? f }
index 684bbc57b5bb141acaec41375d72165278bc94d1..8c0b1beb8323303e4eb387f4608a7d17d628e804 100644 (file)
@@ -4,7 +4,6 @@ H{
     { deploy-compiler? t }
     { deploy-c-types? f }
     { deploy-reflection 1 }
-    { deploy-random? f }
     { deploy-name "WebKit demo" }
     { deploy-io 1 }
     { deploy-math? f }
index 2e05395d19181461906e2e20427f010df9c9c9dd..9aa4f88de66d87f3c10642302b8b75f4f97d4419 100755 (executable)
@@ -244,8 +244,6 @@ CELL unaligned_object_size(CELL pointer)
        case CALLSTACK_TYPE:
                return callstack_size(
                        untag_fixnum_fast(((F_CALLSTACK *)pointer)->length));
-       case TUPLE_LAYOUT_TYPE:
-               return sizeof(F_TUPLE_LAYOUT);
        default:
                critical_error("Invalid header",pointer);
                return -1; /* can't happen */
index 0869d6a8850329c973f379cf74536fda869d8a9d..2550931c727196a8f5c94155770130862cf01a6f 100755 (executable)
@@ -1,5 +1,7 @@
 #include "master.h"
 
+static bool full_output;
+
 void print_chars(F_STRING* str)
 {
        CELL i;
@@ -39,7 +41,7 @@ void print_array(F_ARRAY* array, CELL nesting)
        CELL i;
        bool trimmed;
 
-       if(length > 10)
+       if(length > 10 && !full_output)
        {
                trimmed = true;
                length = 10;
@@ -68,7 +70,7 @@ void print_tuple(F_TUPLE* tuple, CELL nesting)
        CELL i;
        bool trimmed;
 
-       if(length > 10)
+       if(length > 10 && !full_output)
        {
                trimmed = true;
                length = 10;
@@ -88,7 +90,7 @@ void print_tuple(F_TUPLE* tuple, CELL nesting)
 
 void print_nested_obj(CELL obj, F_FIXNUM nesting)
 {
-       if(nesting <= 0)
+       if(nesting <= 0 && !full_output)
        {
                printf(" ... ");
                return;
@@ -342,6 +344,7 @@ void factorbug(void)
        printf("d <addr> <count> -- dump memory\n");
        printf("u <addr>         -- dump object at tagged <addr>\n");
        printf(". <addr>         -- print object at tagged <addr>\n");
+       printf("t                -- toggle output trimming\n");
        printf("s r              -- dump data, retain stacks\n");
        printf(".s .r .c         -- print data, retain, call stacks\n");
        printf("e                -- dump environment\n");
@@ -404,6 +407,8 @@ void factorbug(void)
                        print_obj(addr);
                        printf("\n");
                }
+               else if(strcmp(cmd,"t") == 0)
+                       full_output = !full_output;
                else if(strcmp(cmd,"s") == 0)
                        dump_memory(ds_bot,ds);
                else if(strcmp(cmd,"r") == 0)
index 7ebfe50dd4be09ea60d604d50893ab06f3983afb..6dc29efdae773ac9d44c1d9d9f68ba6b9382d3fb 100755 (executable)
@@ -52,13 +52,12 @@ typedef signed long long s64;
 #define BYTE_ARRAY_TYPE 10
 #define CALLSTACK_TYPE 11
 #define STRING_TYPE 12
-#define TUPLE_LAYOUT_TYPE 13
+#define WORD_TYPE 13
 #define QUOTATION_TYPE 14
 #define DLL_TYPE 15
 #define ALIEN_TYPE 16
-#define WORD_TYPE 17
 
-#define TYPE_COUNT 20
+#define TYPE_COUNT 17
 
 INLINE bool immediate_p(CELL obj)
 {
@@ -154,7 +153,8 @@ typedef struct {
 
 /* Assembly code makes assumptions about the layout of this struct */
 typedef struct {
-/* C sucks. */
+/* We use a union here to force the float value to be aligned on an
+8-byte boundary. */
        union {
                CELL header;
                long long padding;
@@ -222,17 +222,17 @@ typedef struct
        CELL size;
 } F_STACK_FRAME;
 
+/* These are really just arrays, but certain elements have special
+significance */
 typedef struct
 {
        CELL header;
-       /* tagged fixnum */
-       CELL hashcode;
+       /* tagged */
+       CELL capacity;
        /* tagged */
        CELL class;
        /* tagged fixnum */
        CELL size;
-       /* tagged array */
-       CELL superclasses;
        /* tagged fixnum */
        CELL echelon;
 } F_TUPLE_LAYOUT;
index 84cad12326173ce13301845d802acc9a072c1aab..69e77f81ed5529e97d2243f08d6c805352ce75aa 100755 (executable)
@@ -127,7 +127,6 @@ void *primitives[] = {
        primitive_array_to_quotation,
        primitive_quotation_xt,
        primitive_tuple,
-       primitive_tuple_layout,
        primitive_profiling,
        primitive_become,
        primitive_sleep,
index ccc7cbdba30f3b7f79d01d6bdcc6183b79164fdd..5e2ed4bed9a039ab2aa58955ee3168d48ade34c0 100755 (executable)
@@ -298,18 +298,6 @@ F_BYTE_ARRAY *growable_byte_array_append(F_BYTE_ARRAY *result, void *elts, CELL
        return result;
 }
 
-/* Tuple layouts */
-DEFINE_PRIMITIVE(tuple_layout)
-{
-       F_TUPLE_LAYOUT *layout = allot_object(TUPLE_LAYOUT_TYPE,sizeof(F_TUPLE_LAYOUT));
-       layout->echelon = dpop();
-       layout->superclasses = dpop();
-       layout->size = dpop();
-       layout->class = dpop();
-       layout->hashcode = untag_word(layout->class)->hashcode;
-       dpush(tag_object(layout));
-}
-
 /* Tuples */
 
 /* push a new tuple on the stack */
@@ -325,7 +313,7 @@ F_TUPLE *allot_tuple(F_TUPLE_LAYOUT *layout)
 DEFINE_PRIMITIVE(tuple)
 {
        F_TUPLE_LAYOUT *layout = untag_object(dpop());
-       F_FIXNUM size = to_fixnum(layout->size);
+       F_FIXNUM size = untag_fixnum_fast(layout->size);
 
        F_TUPLE *tuple = allot_tuple(layout);
        F_FIXNUM i;
@@ -339,7 +327,7 @@ DEFINE_PRIMITIVE(tuple)
 DEFINE_PRIMITIVE(tuple_boa)
 {
        F_TUPLE_LAYOUT *layout = untag_object(dpop());
-       F_FIXNUM size = to_fixnum(layout->size);
+       F_FIXNUM size = untag_fixnum_fast(layout->size);
 
        REGISTER_UNTAGGED(layout);
        F_TUPLE *tuple = allot_tuple(layout);