]> gitweb.factorcode.org Git - factor.git/commitdiff
Merge branch 'master' of git://factorcode.org/git/factor
authorJoe Groff <arcata@gmail.com>
Fri, 15 Jan 2010 22:03:46 +0000 (14:03 -0800)
committerJoe Groff <arcata@gmail.com>
Fri, 15 Jan 2010 22:03:46 +0000 (14:03 -0800)
330 files changed:
Makefile
basis/alien/remote-control/remote-control.factor
basis/base64/base64.factor
basis/binary-search/binary-search-tests.factor
basis/bit-arrays/bit-arrays-tests.factor
basis/bit-arrays/bit-arrays.factor
basis/bit-vectors/bit-vectors-tests.factor
basis/bootstrap/image/image.factor
basis/bootstrap/image/syntax/syntax.factor
basis/calendar/calendar.factor
basis/calendar/format/format.factor
basis/checksums/sha/sha.factor
basis/classes/struct/bit-accessors/bit-accessors-tests.factor
basis/cocoa/application/application.factor
basis/cocoa/messages/messages.factor
basis/columns/columns-tests.factor
basis/columns/columns.factor
basis/combinators/smart/smart.factor
basis/command-line/command-line.factor
basis/compiler/cfg/build-stack-frame/build-stack-frame.factor
basis/compiler/cfg/builder/builder.factor
basis/compiler/cfg/instructions/instructions.factor
basis/compiler/cfg/instructions/syntax/syntax.factor
basis/compiler/cfg/intrinsics/allot/allot.factor
basis/compiler/cfg/intrinsics/intrinsics.factor
basis/compiler/cfg/intrinsics/misc/misc.factor
basis/compiler/cfg/intrinsics/simd/backend/backend.factor
basis/compiler/cfg/save-contexts/save-contexts.factor
basis/compiler/cfg/stacks/stacks.factor
basis/compiler/cfg/stacks/uninitialized/uninitialized.factor
basis/compiler/codegen/codegen.factor
basis/compiler/codegen/fixup/fixup.factor
basis/compiler/constants/constants.factor
basis/compiler/tests/alien.factor
basis/compiler/tests/codegen.factor
basis/compiler/tests/float.factor
basis/compiler/tests/intrinsics.factor
basis/compiler/tests/optimizer.factor
basis/compiler/tree/checker/checker.factor
basis/compiler/tree/cleanup/cleanup-tests.factor
basis/compiler/tree/dead-code/branches/branches.factor
basis/compiler/tree/dead-code/recursive/recursive.factor
basis/compiler/tree/dead-code/simple/simple.factor
basis/compiler/tree/debugger/debugger.factor
basis/compiler/tree/escape-analysis/recursive/recursive-tests.factor
basis/compiler/tree/escape-analysis/simple/simple.factor
basis/compiler/tree/modular-arithmetic/modular-arithmetic-tests.factor
basis/compiler/tree/normalization/normalization.factor
basis/compiler/tree/propagation/call-effect/call-effect.factor
basis/compiler/tree/propagation/info/info-tests.factor
basis/compiler/tree/propagation/known-words/known-words.factor
basis/compiler/tree/propagation/propagation-tests.factor
basis/compiler/tree/propagation/simple/simple.factor
basis/compiler/tree/propagation/transforms/transforms.factor
basis/compiler/tree/tree.factor
basis/compiler/tree/tuple-unboxing/tuple-unboxing.factor
basis/compression/inflate/inflate.factor
basis/compression/zlib/zlib-tests.factor
basis/compression/zlib/zlib.factor
basis/concurrency/combinators/combinators-tests.factor
basis/cpu/architecture/architecture.factor
basis/cpu/ppc/bootstrap.factor
basis/cpu/ppc/linux/bootstrap.factor
basis/cpu/ppc/macosx/bootstrap.factor
basis/cpu/ppc/ppc.factor
basis/cpu/x86/32/32-tests.factor [new file with mode: 0644]
basis/cpu/x86/32/32.factor
basis/cpu/x86/32/bootstrap.factor
basis/cpu/x86/64/64-tests.factor [new file with mode: 0644]
basis/cpu/x86/64/64.factor
basis/cpu/x86/64/bootstrap.factor
basis/cpu/x86/assembler/assembler.factor
basis/cpu/x86/bootstrap.factor
basis/cpu/x86/features/features.factor
basis/cpu/x86/x86.factor
basis/db/db.factor
basis/db/queries/queries.factor
basis/db/tester/tester.factor
basis/farkup/farkup-tests.factor
basis/fry/fry-tests.factor
basis/generalizations/generalizations-tests.factor
basis/grouping/grouping-docs.factor
basis/heaps/heaps-tests.factor
basis/hints/hints.factor
basis/images/jpeg/jpeg.factor
basis/images/png/png.factor
basis/images/processing/processing.factor
basis/inspector/inspector.factor
basis/inverse/inverse.factor
basis/io/encodings/iso2022/iso2022.factor
basis/io/files/links/unix/unix-tests.factor
basis/io/files/unique/unique.factor
basis/lcs/diff2html/diff2html-tests.factor
basis/lcs/diff2html/diff2html.factor
basis/lcs/lcs.factor
basis/macros/expander/expander.factor
basis/math/combinatorics/combinatorics-docs.factor
basis/math/combinatorics/combinatorics-tests.factor
basis/math/combinatorics/combinatorics.factor
basis/math/complex/complex-tests.factor
basis/math/floats/env/x86/32/32.factor [new file with mode: 0644]
basis/math/floats/env/x86/32/tags.txt [new file with mode: 0644]
basis/math/floats/env/x86/64/64.factor [new file with mode: 0644]
basis/math/floats/env/x86/64/tags.txt [new file with mode: 0644]
basis/math/floats/env/x86/x86.factor
basis/math/functions/functions.factor
basis/math/intervals/intervals-tests.factor
basis/math/matrices/elimination/elimination.factor
basis/math/matrices/matrices.factor
basis/math/polynomials/polynomials.factor
basis/math/primes/miller-rabin/miller-rabin-tests.factor
basis/math/primes/miller-rabin/miller-rabin.factor
basis/math/vectors/simd/cords/cords.factor
basis/math/vectors/simd/intrinsics/intrinsics.factor
basis/math/vectors/simd/simd-tests.factor
basis/math/vectors/simd/simd.factor
basis/math/vectors/vectors.factor
basis/models/arrow/smart/smart.factor
basis/nibble-arrays/nibble-arrays-tests.factor
basis/peg/ebnf/ebnf.factor
basis/persistent/hashtables/hashtables-tests.factor
basis/persistent/vectors/vectors-tests.factor
basis/porter-stemmer/porter-stemmer.factor
basis/prettyprint/prettyprint.factor
basis/prettyprint/sections/sections.factor
basis/random/mersenne-twister/mersenne-twister-tests.factor
basis/random/mersenne-twister/mersenne-twister.factor
basis/random/random-docs.factor
basis/random/random-tests.factor
basis/random/random.factor
basis/regexp/disambiguate/disambiguate.factor
basis/roman/roman-docs.factor
basis/roman/roman.factor
basis/serialize/serialize-tests.factor
basis/serialize/serialize.factor
basis/shuffle/shuffle.factor
basis/sorting/insertion/insertion.factor
basis/sorting/slots/slots-tests.factor
basis/splitting/monotonic/monotonic.factor
basis/stack-checker/alien/alien.factor
basis/stack-checker/errors/prettyprint/prettyprint.factor
basis/stack-checker/inlining/inlining.factor
basis/stack-checker/known-words/known-words.factor
basis/stack-checker/stack-checker-docs.factor
basis/stack-checker/stack-checker-tests.factor
basis/stack-checker/stack-checker.factor
basis/stack-checker/state/state.factor
basis/stack-checker/visitor/dummy/dummy.factor
basis/stack-checker/visitor/visitor.factor
basis/strings/tables/tables.factor
basis/suffix-arrays/suffix-arrays.factor
basis/threads/threads-tests.factor
basis/threads/threads.factor
basis/tools/deploy/shaker/shaker.factor
basis/tools/deploy/shaker/strip-cocoa.factor
basis/tr/tr.factor
basis/tuple-arrays/tuple-arrays.factor
basis/ui/gadgets/gadgets-tests.factor
basis/ui/gadgets/packs/packs-tests.factor
basis/ui/gadgets/panes/panes-tests.factor
basis/ui/gadgets/scrollers/scrollers-tests.factor
basis/ui/gadgets/slots/slots-tests.factor
basis/ui/pens/gradient/gradient-tests.factor
basis/ui/pens/gradient/gradient.factor
basis/unicode/breaks/breaks-tests.factor
basis/unicode/breaks/breaks.factor
basis/unicode/collation/collation.factor
basis/unicode/data/data.factor
basis/unix/unix.factor
basis/unrolled-lists/unrolled-lists-tests.factor
basis/vm/vm.factor
basis/windows/time/time.factor
basis/xml/tests/xmltest.factor
basis/xml/tokenize/tokenize.factor
build-support/factor.sh
core/alien/alien-docs.factor
core/alien/alien.factor
core/alien/strings/strings.factor
core/assocs/assocs.factor
core/bootstrap/primitives.factor
core/byte-vectors/byte-vectors-tests.factor
core/classes/algebra/algebra-tests.factor
core/combinators/combinators.factor
core/compiler/units/units-tests.factor
core/compiler/units/units.factor
core/continuations/continuations-tests.factor
core/continuations/continuations.factor
core/effects/effects-docs.factor
core/effects/effects-tests.factor
core/effects/effects.factor
core/generic/generic-docs.factor
core/hashtables/hashtables-tests.factor
core/init/init.factor
core/io/encodings/utf8/utf8-tests.factor
core/io/files/files.factor
core/io/streams/c/c.factor
core/kernel/kernel-docs.factor
core/layouts/layouts.factor
core/math/floats/floats-tests.factor
core/math/floats/floats.factor
core/math/integers/integers-tests.factor
core/math/integers/integers.factor
core/math/math-docs.factor
core/math/order/order-docs.factor
core/math/order/order.factor
core/math/parser/parser-docs.factor
core/namespaces/namespaces.factor
core/parser/parser.factor
core/sbufs/sbufs-tests.factor
core/sequences/sequences-docs.factor
core/sequences/sequences-tests.factor
core/sequences/sequences.factor
core/sorting/sorting-tests.factor
core/source-files/errors/errors.factor
core/strings/strings-tests.factor
core/system/system.factor
core/vectors/vectors-tests.factor
extra/24-game/24-game.factor
extra/alien/data/map/map-tests.factor
extra/benchmark/base64/base64.factor
extra/benchmark/dawes/dawes.factor
extra/benchmark/dispatch2/dispatch2.factor
extra/benchmark/dispatch4/dispatch4.factor
extra/benchmark/e-decimals/e-decimals.factor
extra/benchmark/empty-loop-2/empty-loop-2.factor
extra/benchmark/fasta/fasta.factor
extra/benchmark/gc1/gc1.factor
extra/benchmark/iteration/iteration.factor
extra/benchmark/knucleotide/knucleotide.factor
extra/benchmark/partial-sums/partial-sums.factor
extra/benchmark/random/random.factor
extra/benchmark/raytracer-simd/raytracer-simd.factor
extra/benchmark/raytracer/raytracer.factor
extra/benchmark/ring/ring.factor
extra/benchmark/spectral-norm/spectral-norm.factor
extra/benchmark/tuple-arrays/tuple-arrays.factor
extra/benchmark/ui-panes/ui-panes.factor
extra/benchmark/yuv-to-rgb/yuv-to-rgb.factor
extra/bloom-filters/bloom-filters-tests.factor
extra/bloom-filters/bloom-filters.factor
extra/bson/reader/reader.factor
extra/bson/writer/writer.factor
extra/constructors/constructors.factor
extra/crypto/aes/aes.factor
extra/decimals/decimals-tests.factor
extra/furnace/mongodb/mongodb.factor [new file with mode: 0644]
extra/grid-meshes/grid-meshes-tests.factor [new file with mode: 0644]
extra/html/parser/analyzer/analyzer.factor
extra/id3/id3-tests.factor
extra/infix/infix-docs.factor
extra/jamshred/gl/gl.factor
extra/jamshred/oint/oint.factor
extra/koszul/koszul.factor
extra/mason/common/common.factor
extra/math/analysis/analysis.factor
extra/math/text/english/english.factor
extra/maze/maze.factor
extra/memory/pools/pools.factor
extra/mongodb/benchmark/benchmark.factor
extra/mongodb/driver/driver.factor
extra/mongodb/msg/msg.factor
extra/mongodb/operations/operations.factor
extra/multi-methods/multi-methods.factor
extra/noise/noise-tests.factor [new file with mode: 0644]
extra/noise/noise.factor
extra/partial-continuations/partial-continuations-tests.factor
extra/project-euler/001/001.factor
extra/project-euler/011/011.factor
extra/project-euler/014/014.factor
extra/project-euler/024/024.factor
extra/project-euler/027/027.factor
extra/project-euler/030/030.factor
extra/project-euler/032/032.factor
extra/project-euler/043/043.factor
extra/project-euler/052/052.factor
extra/project-euler/053/053.factor
extra/project-euler/055/055.factor
extra/project-euler/057/057.factor
extra/project-euler/081/081.factor
extra/project-euler/150/150.factor
extra/project-euler/151/151.factor
extra/project-euler/164/164.factor
extra/project-euler/common/common.factor
extra/slides/slides.factor
extra/smalltalk/compiler/compiler-tests.factor
extra/smalltalk/selectors/selectors.factor
extra/sudoku/sudoku-tests.factor [new file with mode: 0644]
extra/sudoku/sudoku.factor
extra/taxes/usa/fica/fica.factor
extra/tetris/board/board.factor
extra/tetris/gl/gl.factor
extra/trees/splay/splay-tests.factor
vm/Config.arm
vm/Config.windows
vm/Config.x86.32
vm/Config.x86.64
vm/asm.h [deleted file]
vm/callbacks.cpp
vm/callbacks.hpp
vm/callstack.cpp
vm/code_block_visitor.hpp
vm/code_blocks.cpp
vm/cpu-arm.S [deleted file]
vm/cpu-arm.hpp
vm/cpu-ppc.S
vm/cpu-ppc.hpp
vm/cpu-x86.32.S [deleted file]
vm/cpu-x86.64.S [deleted file]
vm/cpu-x86.S [deleted file]
vm/cpu-x86.hpp
vm/entry_points.cpp [new file with mode: 0644]
vm/entry_points.hpp [new file with mode: 0644]
vm/errors.cpp
vm/factor.cpp
vm/instruction_operands.cpp
vm/master.hpp
vm/objects.cpp
vm/objects.hpp
vm/os-genunix.cpp
vm/os-macosx.mm
vm/os-unix.hpp
vm/os-windows-nt.cpp
vm/os-windows.hpp
vm/platform.hpp
vm/primitives.cpp
vm/quotations.cpp
vm/utilities.cpp
vm/utilities.hpp
vm/vm.cpp
vm/vm.hpp

index 80621d8f0a96c2649d23efa03d204ba0c82af301..772f3f98754db42759372294788e750c3884b648 100755 (executable)
--- a/Makefile
+++ b/Makefile
@@ -47,6 +47,7 @@ DLL_OBJS = $(PLAF_DLL_OBJS) \
        vm/data_heap_checker.o \
        vm/debug.o \
        vm/dispatch.o \
+       vm/entry_points.o \
        vm/errors.o \
        vm/factor.o \
        vm/free_list.o \
index 6a5644cceb5f675f77875e4b094d5cb308924611..ae694bed9c4b8da031dc212c9e187df1d92e97ca 100644 (file)
@@ -19,8 +19,8 @@ IN: alien.remote-control
     dup optimized? [ execute ] [ drop f ] if ; inline
 
 : init-remote-control ( -- )
-    \ eval-callback ?callback 16 setenv
-    \ yield-callback ?callback 17 setenv
-    \ sleep-callback ?callback 18 setenv ;
+    \ eval-callback ?callback 16 set-special-object
+    \ yield-callback ?callback 17 set-special-object
+    \ sleep-callback ?callback 18 set-special-object ;
 
 MAIN: init-remote-control
index eb2c9193a374b35e61a33a2f510f4c2582eaf04e..1a0648cef8b92f2037438ddc2686e24617e3ade3 100644 (file)
@@ -13,7 +13,8 @@ ERROR: malformed-base64 ;
     read1 2dup swap member? [ drop read1-ignoring ] [ nip ] if ;
 
 : read-ignoring ( ignoring n -- str )
-    [ drop read1-ignoring ] with map harvest
+    [ drop read1-ignoring ] with { } map-integers
+    [ { f 0 } member? not ] filter
     [ f ] [ >string ] if-empty ;
 
 : ch>base64 ( ch -- ch )
@@ -42,7 +43,7 @@ SYMBOL: column
     [ write1-lines ] each ;
 
 : encode3 ( seq -- )
-    be> 4 <reversed> [
+    be> 4 iota <reversed> [
         -6 * shift HEX: 3f bitand ch>base64 write1-lines
     ] with each ; inline
 
index f2ea7503f4851f8a8ac6bdb371a21237053d03ce..a797219a01466894624323ce5832c0965f4cec64 100644 (file)
@@ -1,4 +1,4 @@
-USING: binary-search math.order vectors kernel tools.test ;
+USING: binary-search math.order sequences kernel tools.test ;
 IN: binary-search.tests
 
 [ f ] [ 3 { } [ <=> ] with search drop ] unit-test
@@ -7,7 +7,7 @@ IN: binary-search.tests
 [ 3 ] [ 4 { 1 2 3 4 5 6 } [ <=> ] with search drop ] unit-test
 [ 2 ] [ 3.5 { 1 2 3 4 5 6 7 8 } [ <=> ] with search drop ] unit-test
 [ 4 ] [ 5.5 { 1 2 3 4 5 6 7 8 } [ <=> ] with search drop ] unit-test
-[ 10 ] [ 10 20 >vector [ <=> ] with search drop ] unit-test
+[ 10 ] [ 10 20 iota [ <=> ] with search drop ] unit-test
 
 [ t ] [ "hello" { "alligator" "cat" "fish" "hello" "ikarus" "java" } sorted-member? ] unit-test
 [ 3 ] [ "hey" { "alligator" "cat" "fish" "hello" "ikarus" "java" } sorted-index ] unit-test
index 7397791ab5b1b05058058d87fade66942c1ccb6d..f08db68441c9484a7f17c2f3c9752abdf42719c2 100644 (file)
@@ -40,7 +40,7 @@ IN: bit-arrays.tests
     100 [
         drop 100 [ 2 random zero? ] replicate
         dup >bit-array >array =
-    ] all?
+    ] all-integers?
 ] unit-test
 
 [ ?{ f } ] [
index f5613da6b552126b3edf31b7e494179c0246a9c0..4fafc528fdcb7728633915184f4ec5e97f23cdb8 100644 (file)
@@ -1,4 +1,4 @@
-! Copyright (C) 2007, 2008 Slava Pestov.
+! Copyright (C) 2007, 2010 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
 USING: alien.c-types alien.data accessors math alien.accessors kernel
 kernel.private sequences sequences.private byte-arrays
@@ -25,7 +25,7 @@ TUPLE: bit-array
 
 : (set-bits) ( bit-array n -- )
     [ [ length bits>cells ] keep ] dip swap underlying>>
-    '[ 2 shift [ _ _ ] dip set-alien-unsigned-4 ] each ; inline
+    '[ 2 shift [ _ _ ] dip set-alien-unsigned-4 ] each-integer ; inline
 
 : clean-up ( bit-array -- )
     ! Zero bits after the end.
@@ -99,7 +99,7 @@ SYNTAX: ?{ \ } [ >bit-array ] parse-literal ;
     ] if ;
 
 : bit-array>integer ( bit-array -- n )
-    0 swap underlying>> dup length <reversed> [
+    0 swap underlying>> dup length iota <reversed> [
         alien-unsigned-1 swap 8 shift bitor
     ] with each ;
 
index 5af44b59f7f30577e24a753a74c4565fe1f03689..a8a856ffd00476e73a9bef035886d965cfa0fd92 100644 (file)
@@ -4,7 +4,7 @@ IN: bit-vectors.tests
 [ 0 ] [ 123 <bit-vector> length ] unit-test\r
 \r
 : do-it ( seq -- )\r
-    1234 swap [ [ even? ] dip push ] curry each ;\r
+    1234 swap [ [ even? ] dip push ] curry each-integer ;\r
 \r
 [ t ] [\r
     3 <bit-vector> dup do-it\r
index bf2d14e3aabde68b6c553720f82794b2ad7ab3c3..90b4c3ae6f35ebe22e6d1eab562bf23f4fb3e844 100644 (file)
@@ -1,4 +1,4 @@
-! Copyright (C) 2004, 2009 Slava Pestov.
+! Copyright (C) 2004, 2010 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
 USING: alien alien.strings arrays byte-arrays generic hashtables
 hashtables.private io io.binary io.files io.encodings.binary
@@ -93,7 +93,7 @@ CONSTANT: image-version 4
 
 CONSTANT: data-base 1024
 
-CONSTANT: userenv-size 70
+CONSTANT: special-objects-size 70
 
 CONSTANT: header-size 10
 
@@ -155,7 +155,7 @@ SYMBOL: jit-literals
 : define-sub-primitive ( quot word -- )
     [ make-jit 3array ] dip sub-primitives get set-at ;
 
-: define-sub-primitive* ( quot non-tail-quot tail-quot word -- )
+: define-combinator-primitive ( quot non-tail-quot tail-quot word -- )
     [
         [ make-jit ]
         [ make-jit 2nip ]
@@ -176,54 +176,58 @@ SYMBOL: architecture
 RESET
 
 ! Boot quotation, set in stage1.factor
-USERENV: bootstrap-startup-quot 20
+SPECIAL-OBJECT: bootstrap-startup-quot 20
 
 ! Bootstrap global namesapce
-USERENV: bootstrap-global 21
+SPECIAL-OBJECT: bootstrap-global 21
 
 ! JIT parameters
-USERENV: jit-prolog 23
-USERENV: jit-primitive-word 24
-USERENV: jit-primitive 25
-USERENV: jit-word-jump 26
-USERENV: jit-word-call 27
-USERENV: jit-if-word 28
-USERENV: jit-if 29
-USERENV: jit-epilog 30
-USERENV: jit-return 31
-USERENV: jit-profiling 32
-USERENV: jit-push 33
-USERENV: jit-dip-word 34
-USERENV: jit-dip 35
-USERENV: jit-2dip-word 36
-USERENV: jit-2dip 37
-USERENV: jit-3dip-word 38
-USERENV: jit-3dip 39
-USERENV: jit-execute 40
-USERENV: jit-declare-word 41
-
-USERENV: callback-stub 48
+SPECIAL-OBJECT: jit-prolog 23
+SPECIAL-OBJECT: jit-primitive-word 24
+SPECIAL-OBJECT: jit-primitive 25
+SPECIAL-OBJECT: jit-word-jump 26
+SPECIAL-OBJECT: jit-word-call 27
+SPECIAL-OBJECT: jit-if-word 28
+SPECIAL-OBJECT: jit-if 29
+SPECIAL-OBJECT: jit-epilog 30
+SPECIAL-OBJECT: jit-return 31
+SPECIAL-OBJECT: jit-profiling 32
+SPECIAL-OBJECT: jit-push 33
+SPECIAL-OBJECT: jit-dip-word 34
+SPECIAL-OBJECT: jit-dip 35
+SPECIAL-OBJECT: jit-2dip-word 36
+SPECIAL-OBJECT: jit-2dip 37
+SPECIAL-OBJECT: jit-3dip-word 38
+SPECIAL-OBJECT: jit-3dip 39
+SPECIAL-OBJECT: jit-execute 40
+SPECIAL-OBJECT: jit-declare-word 41
+
+SPECIAL-OBJECT: c-to-factor-word 42
+SPECIAL-OBJECT: lazy-jit-compile-word 43
+SPECIAL-OBJECT: unwind-native-frames-word 44
+
+SPECIAL-OBJECT: callback-stub 48
 
 ! PIC stubs
-USERENV: pic-load 49
-USERENV: pic-tag 50
-USERENV: pic-tuple 51
-USERENV: pic-check-tag 52
-USERENV: pic-check-tuple 53
-USERENV: pic-hit 54
-USERENV: pic-miss-word 55
-USERENV: pic-miss-tail-word 56
+SPECIAL-OBJECT: pic-load 49
+SPECIAL-OBJECT: pic-tag 50
+SPECIAL-OBJECT: pic-tuple 51
+SPECIAL-OBJECT: pic-check-tag 52
+SPECIAL-OBJECT: pic-check-tuple 53
+SPECIAL-OBJECT: pic-hit 54
+SPECIAL-OBJECT: pic-miss-word 55
+SPECIAL-OBJECT: pic-miss-tail-word 56
 
 ! Megamorphic dispatch
-USERENV: mega-lookup 57
-USERENV: mega-lookup-word 58
-USERENV: mega-miss-word 59
+SPECIAL-OBJECT: mega-lookup 57
+SPECIAL-OBJECT: mega-lookup-word 58
+SPECIAL-OBJECT: mega-miss-word 59
 
 ! Default definition for undefined words
-USERENV: undefined-quot 60
+SPECIAL-OBJECT: undefined-quot 60
 
-: userenv-offset ( symbol -- n )
-    userenvs get at header-size + ;
+: special-object-offset ( symbol -- n )
+    special-objects get at header-size + ;
 
 : emit ( cell -- ) image get push ;
 
@@ -239,7 +243,7 @@ USERENV: undefined-quot 60
 : fixup ( value offset -- ) image get set-nth ;
 
 : heap-size ( -- size )
-    image get length header-size - userenv-size -
+    image get length header-size - special-objects-size -
     bootstrap-cells ;
 
 : here ( -- size ) heap-size data-base + ;
@@ -278,10 +282,10 @@ GENERIC: ' ( obj -- ptr )
     0 emit ! pointer to bignum 0
     0 emit ! pointer to bignum 1
     0 emit ! pointer to bignum -1
-    userenv-size [ f ' emit ] times ;
+    special-objects-size [ f ' emit ] times ;
 
-: emit-userenv ( symbol -- )
-    [ get ' ] [ userenv-offset ] bi fixup ;
+: emit-special-object ( symbol -- )
+    [ get ' ] [ special-object-offset ] bi fixup ;
 
 ! Bignums
 
@@ -534,15 +538,18 @@ M: quotation '
     \ dip jit-dip-word set
     \ 2dip jit-2dip-word set
     \ 3dip jit-3dip-word set
-    \ inline-cache-miss pic-miss-word set
-    \ inline-cache-miss-tail pic-miss-tail-word set
-    \ mega-cache-lookup mega-lookup-word set
-    \ mega-cache-miss mega-miss-word set
+    \ inline-cache-miss pic-miss-word set
+    \ inline-cache-miss-tail pic-miss-tail-word set
+    \ mega-cache-lookup mega-lookup-word set
+    \ mega-cache-miss mega-miss-word set
     \ declare jit-declare-word set
+    \ c-to-factor c-to-factor-word set
+    \ lazy-jit-compile lazy-jit-compile-word set
+    \ unwind-native-frames unwind-native-frames-word set
     [ undefined ] undefined-quot set ;
 
-: emit-userenvs ( -- )
-    userenvs get keys [ emit-userenv ] each ;
+: emit-special-objects ( -- )
+    special-objects get keys [ emit-special-object ] each ;
 
 : fixup-header ( -- )
     heap-size data-heap-size-offset fixup ;
@@ -559,8 +566,8 @@ M: quotation '
     emit-jit-data
     "Serializing global namespace..." print flush
     emit-global
-    "Serializing user environment..." print flush
-    emit-userenvs
+    "Serializing special object table..." print flush
+    emit-special-objects
     "Performing word fixups..." print flush
     fixup-words
     "Performing header fixups..." print flush
index 29dc09717a605a8ed023933e68b15c235fa6fa44..7025cd61e14bbaf491b768ab88bb95395760d5a8 100644 (file)
@@ -1,14 +1,14 @@
-! Copyright (C) 2009 Slava Pestov.
+! Copyright (C) 2009, 2010 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
 USING: parser kernel namespaces assocs words.symbol ;
 IN: bootstrap.image.syntax
 
-SYMBOL: userenvs
+SYMBOL: special-objects
 
-SYNTAX: RESET H{ } clone userenvs set-global ;
+SYNTAX: RESET H{ } clone special-objects set-global ;
 
-SYNTAX: USERENV:
+SYNTAX: SPECIAL-OBJECT:
     CREATE-WORD scan-word
-    [ swap userenvs get set-at ]
+    [ swap special-objects get set-at ]
     [ drop define-symbol ]
     2bi ;
\ No newline at end of file
index 25cf35c062a57082df6ea1d7e319dbc55f55048f..3940af48563a87bbfebb3eb1cc2f1174289a051a 100644 (file)
@@ -554,7 +554,8 @@ M: integer end-of-year 12 31 <date> ;
 : unix-time>timestamp ( seconds -- timestamp )
     seconds unix-1970 time+ ;
 
-M: duration sleep duration>nanoseconds nano-count + sleep-until ;
+M: duration sleep
+    duration>nanoseconds >integer nano-count + sleep-until ;
 
 {
     { [ os unix? ] [ "calendar.unix" ] }
index d07d74722a71de9c45ad58b231d55b71acd54a3b..96d76d0ce86430c5e7b9badbd0502b7393f8aba8 100644 (file)
@@ -1,4 +1,4 @@
-! Copyright (C) 2008 Slava Pestov.\r
+! Copyright (C) 2008, 2010 Slava Pestov, Doug Coleman.\r
 ! See http://factorcode.org/license.txt for BSD license.\r
 USING: math math.order math.parser math.functions kernel\r
 sequences io accessors arrays io.streams.string splitting\r
@@ -70,7 +70,7 @@ M: array month. ( pair -- )
     [\r
         [ 1 + day. ] keep\r
         1 + + 7 mod zero? [ nl ] [ bl ] if\r
-    ] with each nl ;\r
+    ] with each-integer nl ;\r
 \r
 M: timestamp month. ( timestamp -- )\r
     [ year>> ] [ month>> ] bi 2array month. ;\r
@@ -78,7 +78,7 @@ M: timestamp month. ( timestamp -- )
 GENERIC: year. ( obj -- )\r
 \r
 M: integer year. ( n -- )\r
-    12 [ 1 + 2array month. nl ] with each ;\r
+    12 [ 1 + 2array month. nl ] with each-integer ;\r
 \r
 M: timestamp year. ( timestamp -- )\r
     year>> year. ;\r
index 35262bb0b0fb718103d9b3ef39138a598f86effd..ba85add03c63727406fb6d650b5f745b2b911e68 100644 (file)
@@ -301,7 +301,7 @@ GENERIC: pad-initial-bytes ( string sha2 -- padded-string )
         M cloned-H sha2 T1-256
         cloned-H T2-256
         cloned-H update-H
-    ] each
+    ] each-integer
     sha2 [ cloned-H [ w+ ] 2map ] change-H drop ; inline
 
 M: sha2-short checksum-block
@@ -391,7 +391,7 @@ M: sha-256 checksum-stream ( stream checksum -- byte-array )
         b H nth-unsafe 30 bitroll-32 c H set-nth-unsafe
         a H nth-unsafe b H set-nth-unsafe
         a H set-nth-unsafe
-    ] each
+    ] each-integer
     state [ H [ w+ ] 2map ] change-H drop ; inline
 
 M:: sha1-state checksum-block ( bytes state -- )
index e2ff6dbd9c5c15e834f0bcb05f28f2c43fa22e01..ecf7b68a2d89fc25a048998299451679511823b5 100644 (file)
@@ -1,6 +1,7 @@
 ! Copyright (C) 2009 Daniel Ehrenberg
 ! See http://factorcode.org/license.txt for BSD license.
-USING: classes.struct.bit-accessors tools.test effects kernel random stack-checker ;
+USING: classes.struct.bit-accessors tools.test effects kernel
+sequences random stack-checker ;
 IN: classes.struct.bit-accessors.test
 
 [ t ] [ 20 random 20 random bit-reader infer (( alien -- n )) effect= ] unit-test
index 83213b47ba005ec11c6442898a74a9b96a9d214c..df56ce5c4c43568bf9cbdcd5226d64aac3a21156 100644 (file)
@@ -49,7 +49,7 @@ TUPLE: objc-error alien reason ;
 M: objc-error summary ( error -- )
     drop "Objective C exception" ;
 
-[ [ objc-error ] 19 setenv ] "cocoa.application" add-startup-hook
+[ [ objc-error ] 19 set-special-object ] "cocoa.application" add-startup-hook
 
 : running.app? ( -- ? )
     #! Test if we're running a .app.
index 4cc9554d3c4be5b84d1be3a1f09b7ceabd02fded..02e6335c54b5f4f2a7a628721d7647df412025a2 100644 (file)
@@ -1,4 +1,4 @@
-! Copyright (C) 2006, 2009 Slava Pestov.
+! Copyright (C) 2006, 2010 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
 USING: accessors alien alien.c-types alien.strings arrays assocs
 classes.struct continuations combinators compiler compiler.alien
@@ -202,7 +202,7 @@ ERROR: no-objc-type name ;
     (free) ;
 
 : method-arg-types ( method -- args )
-    dup method_getNumberOfArguments
+    dup method_getNumberOfArguments iota
     [ method-arg-type ] with map ;
 
 : method-return-type ( method -- ctype )
index 434c2339368a24b1970dcd1a20e938f5df79e010..c0e0956709582c1421577dc4accf9af2488b62c5 100644 (file)
@@ -7,3 +7,5 @@ IN: columns.tests
 [ { 1 4 7 } ] [ "seq" get 0 <column> >array ] unit-test
 [ ] [ "seq" get 1 <column> [ sq ] map! drop ] unit-test
 [ { 4 25 64 } ] [ "seq" get 1 <column> >array ] unit-test
+
+[ { { 1 3 } { 2 4 } } ] [ { { 1 2 } { 3 4 } } <flipped> [ >array ] map ] unit-test
index 8674217655c572e0bf977279d2fd3c9dc251882d..c36505ab6d1d727f091ff83be941935005fd1c10 100644 (file)
@@ -1,4 +1,4 @@
-! Copyright (C) 2005, 2008 Slava Pestov, Daniel Ehrenberg.
+! Copyright (C) 2005, 2010 Slava Pestov, Daniel Ehrenberg.
 ! See http://factorcode.org/license.txt for BSD license.
 USING: sequences kernel accessors ;
 IN: columns
@@ -15,4 +15,4 @@ M: column length seq>> length ;
 INSTANCE: column virtual-sequence
 
 : <flipped> ( seq -- seq' )
-    dup empty? [ dup first length [ <column> ] with map ] unless ;
+    dup empty? [ dup first length [ <column> ] with { } map-integers ] unless ;
index 91987e0dfa6577f05a1d3b492ab56a6279ce33dd..cb1b309c86ebccc34cbc9bb0ef0ab9b6e75a9b52 100644 (file)
@@ -5,49 +5,49 @@ stack-checker math sequences ;
 IN: combinators.smart
 
 MACRO: drop-outputs ( quot -- quot' )
-    dup infer out>> '[ @ _ ndrop ] ;
+    dup outputs '[ @ _ ndrop ] ;
 
 MACRO: keep-inputs ( quot -- quot' )
-    dup infer in>> '[ _ _ nkeep ] ;
+    dup inputs '[ _ _ nkeep ] ;
 
 MACRO: output>sequence ( quot exemplar -- newquot )
-    [ dup infer out>> ] dip
+    [ dup outputs ] dip
     '[ @ _ _ nsequence ] ;
 
 MACRO: output>array ( quot -- newquot )
     '[ _ { } output>sequence ] ;
 
 MACRO: input<sequence ( quot -- newquot )
-    [ infer in>> ] keep
+    [ inputs ] keep
     '[ _ firstn @ ] ;
 
 MACRO: input<sequence-unsafe ( quot -- newquot )
-    [ infer in>> ] keep
+    [ inputs ] keep
     '[ _ firstn-unsafe @ ] ;
 
 MACRO: reduce-outputs ( quot operation -- newquot )
-    [ dup infer out>> 1 [-] ] dip n*quot compose ;
+    [ dup outputs 1 [-] ] dip n*quot compose ;
 
 MACRO: sum-outputs ( quot -- n )
     '[ _ [ + ] reduce-outputs ] ;
 
 MACRO: map-reduce-outputs ( quot mapper reducer -- newquot )
-    [ dup infer out>> ] 2dip
+    [ dup outputs ] 2dip
     [ swap '[ _ _ napply ] ]
     [ [ 1 [-] ] dip n*quot ] bi-curry* bi
     '[ @ @ @ ] ;
 
 MACRO: append-outputs-as ( quot exemplar -- newquot )
-    [ dup infer out>> ] dip '[ @ _ _ nappend-as ] ;
+    [ dup outputs ] dip '[ @ _ _ nappend-as ] ;
 
 MACRO: append-outputs ( quot -- seq )
     '[ _ { } append-outputs-as ] ;
 
 MACRO: preserving ( quot -- )
-    [ infer in>> length ] keep '[ _ ndup @ ] ;
+    [ inputs ] keep '[ _ ndup @ ] ;
 
 MACRO: nullary ( quot -- quot' )
-    dup infer out>> length '[ @ _ ndrop ] ;
+    dup outputs '[ @ _ ndrop ] ;
 
 MACRO: smart-if ( pred true false -- )
     '[ _ preserving _ _ if ] ; inline
index f1748d37083f7ebbaba5663eb8a238f39db590c3..939fb82f008f0da27277faef527039dea009b3cd 100644 (file)
@@ -8,7 +8,8 @@ IN: command-line
 SYMBOL: script
 SYMBOL: command-line
 
-: (command-line) ( -- args ) 10 getenv sift [ alien>native-string ] map ;
+: (command-line) ( -- args )
+    10 special-object sift [ alien>native-string ] map ;
 
 : rc-path ( name -- path )
     os windows? [ "." prepend ] unless
index 6f45a51f552a5ca93cb36cb8ebdc64a01353789d..670e34e5f9b4282b6b82e75a263781d09c103b4b 100644 (file)
@@ -1,4 +1,4 @@
-! Copyright (C) 2008, 2009 Slava Pestov.
+! Copyright (C) 2008, 2010 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
 USING: namespaces accessors math.order assocs kernel sequences
 combinators make classes words cpu.architecture layouts
@@ -17,6 +17,7 @@ GENERIC: compute-stack-frame* ( insn -- )
 UNION: stack-frame-insn
     ##alien-invoke
     ##alien-indirect
+    ##alien-assembly
     ##alien-callback ;
 
 M: stack-frame-insn compute-stack-frame*
index e67b8e3737c49e83b7a3510f9c14cb54df66d46a..529c3b5ae6540c5357b2534944d918b289d1c054 100644 (file)
@@ -236,6 +236,9 @@ M: #alien-invoke emit-node
 M: #alien-indirect emit-node
     [ ##alien-indirect ] emit-alien-node ;
 
+M: #alien-assembly emit-node
+    [ ##alien-assembly ] emit-alien-node ;
+
 M: #alien-callback emit-node
     dup params>> xt>> dup
     [
index 20008ea85efcee54d712704f177012d67be8fcf1..68a8b8ce59d6fc376e2d6251a1be2f1c9cf12d06 100644 (file)
@@ -671,6 +671,9 @@ literal: params stack-frame ;
 INSN: ##alien-indirect
 literal: params stack-frame ;
 
+INSN: ##alien-assembly
+literal: params stack-frame ;
+
 INSN: ##alien-callback
 literal: params stack-frame ;
 
index bca5e1ee64491c2c8956fd7c74e5f40bc8ca725b..cd76652d06076508be8cfaa3308093cc26c23ef8 100644 (file)
@@ -1,4 +1,4 @@
-! Copyright (C) 2008, 2009 Slava Pestov.
+! Copyright (C) 2008, 2010 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
 USING: classes.tuple classes.tuple.parser kernel words
 make fry sequences parser accessors effects namespaces
@@ -61,14 +61,14 @@ TUPLE: insn-slot-spec type name rep ;
     "pure-insn" "compiler.cfg.instructions" lookup ;
 
 : insn-effect ( word -- effect )
-    boa-effect in>> but-last f <effect> ;
+    boa-effect in>> but-last { } <effect> ;
 
 : define-insn-tuple ( class superclass specs -- )
     [ name>> ] map "insn#" suffix define-tuple-class ;
 
 : define-insn-ctor ( class specs -- )
     [ dup '[ _ ] [ f ] [ boa , ] surround ] dip
-    [ name>> ] map f <effect> define-declared ;
+    [ name>> ] map { } <effect> define-declared ;
 
 : define-insn ( class superclass specs -- )
     parse-insn-slot-specs {
index 9804244ecb939da2a2d7d5996b808f9b4b61019c..31a8a898bc1fb07837e1a88425dda876e0f27210 100644 (file)
@@ -1,4 +1,4 @@
-! Copyright (C) 2008, 2009 Slava Pestov.
+! Copyright (C) 2008, 2010 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
 USING: kernel math math.order sequences accessors arrays
 byte-arrays layouts classes.tuple.private fry locals
@@ -34,7 +34,7 @@ IN: compiler.cfg.intrinsics.allot
     [ [ ^^load-literal ] dip 1 ] dip type-number ##set-slot-imm ;
 
 :: store-initial-element ( len reg elt class -- )
-    len [ [ elt reg ] dip 2 + class type-number ##set-slot-imm ] each ;
+    len [ [ elt reg ] dip 2 + class type-number ##set-slot-imm ] each-integer ;
 
 : expand-<array>? ( obj -- ? )
     dup integer? [ 0 8 between? ] [ drop f ] if ;
index e8c93899cb71c25d64ffef1699c531cb0ae0a545..d753a4c1b496c75cbf0a329e9147bc685689ba23 100644 (file)
@@ -30,7 +30,7 @@ IN: compiler.cfg.intrinsics
 
 {
     { kernel.private:tag [ drop emit-tag ] }
-    { kernel.private:getenv [ emit-getenv ] }
+    { kernel.private:special-object [ emit-special-object ] }
     { kernel.private:(identity-hashcode) [ drop emit-identity-hashcode ] }
     { math.private:both-fixnums? [ drop emit-both-fixnums? ] }
     { math.private:fixnum+ [ drop emit-fixnum+ ] }
index a477ef4b950b1d0b9b6a6dcbf58d99edc1a6a6c6..fed5492220847bbd760935147a1995d2c94151f3 100644 (file)
@@ -9,8 +9,8 @@ IN: compiler.cfg.intrinsics.misc
 : emit-tag ( -- )
     ds-pop tag-mask get ^^and-imm ^^tag-fixnum ds-push ;
 
-: emit-getenv ( node -- )
-    "userenv" ^^vm-field-ptr
+: emit-special-object ( node -- )
+    "special-objects" ^^vm-field-ptr
     swap node-input-infos first literal>>
     [ ds-drop 0 ^^slot-imm ] [ ds-pop ^^offset>slot ^^slot ] if*
     ds-push ;
index cf61a560d240089c85760b33c0d38f4ea1a6e18c..e8b9e3c5de3bc2abfc31138d76c16991815faf1d 100644 (file)
@@ -110,7 +110,7 @@ MACRO: vvvv-vector-op ( trials -- )
     blub ;
 
 MACRO: can-has-case ( cases -- )
-    dup first second infer in>> length 1 +
+    dup first second inputs 1 +
     '[ _ ndrop f ] suffix '[ _ case ] ;
 
 GENERIC# >can-has-trial 1 ( obj #pick -- quot )
@@ -118,7 +118,7 @@ GENERIC# >can-has-trial 1 ( obj #pick -- quot )
 M: callable >can-has-trial
     drop '[ _ can-has? ] ;
 M: pair >can-has-trial
-    swap first2 dup infer in>> length
+    swap first2 dup inputs
     '[ _ npick _ instance? [ _ can-has? ] [ _ ndrop blub ] if ] ; 
 
 MACRO: can-has-vector-op ( trials #pick #dup -- )
index 4296fb54f947bd764977d2562dd76dae46946918..c7b6db06715000941bc0255c73fd769d382ab4df 100644 (file)
@@ -1,4 +1,4 @@
-! Copyright (C) 2009 Slava Pestov.
+! Copyright (C) 2009, 2010 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
 USING: accessors combinators.short-circuit
 compiler.cfg.instructions compiler.cfg.registers
@@ -14,6 +14,7 @@ IN: compiler.cfg.save-contexts
             [ ##binary-float-function? ]
             [ ##alien-invoke? ]
             [ ##alien-indirect? ]
+            [ ##alien-assembly? ]
         } 1||
     ] any? ;
 
index ce673ba5bb4da2a317347c3763ffb9bb29ec18dc..6cf362c2308a4f278c09e04db1dc48cbf63c7691 100644 (file)
@@ -1,4 +1,4 @@
-! Copyright (C) 2008, 2009 Slava Pestov.
+! Copyright (C) 2008, 2010 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
 USING: math sequences kernel namespaces accessors biassocs compiler.cfg
 compiler.cfg.instructions compiler.cfg.registers compiler.cfg.hats
@@ -33,7 +33,7 @@ IN: compiler.cfg.stacks
 : ds-load ( n -- vregs )
     dup 0 =
     [ drop f ]
-    [ [ <reversed> [ <ds-loc> peek-loc ] map ] [ neg inc-d ] bi ] if ;
+    [ [ iota <reversed> [ <ds-loc> peek-loc ] map ] [ neg inc-d ] bi ] if ;
 
 : ds-store ( vregs -- )
     [
index 0bed759e5286d615932726245ce860e5f772f123..e5fbfa6c40bcbafa674be12d46eb07044682a640 100644 (file)
@@ -1,4 +1,4 @@
-! Copyright (C) 2009 Slava Pestov.
+! Copyright (C) 2009, 2010 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
 USING: kernel sequences byte-arrays namespaces accessors classes math
 math.order fry arrays combinators compiler.cfg.registers
@@ -55,7 +55,7 @@ M: insn visit-insn drop ;
     2dup [ length ] bi@ max '[ _ 1 pad-tail ] bi@ [ bitand ] 2map ;
 
 : (uninitialized-locs) ( seq quot -- seq' )
-    [ dup length [ drop 0 = ] pusher [ 2each ] dip ] dip map ; inline
+    [ [ drop 0 = ] pusher [ each-index ] dip ] dip map ; inline
 
 PRIVATE>
 
index c67048cf0df1a9a8da491b47b03c43efe956bc58..ef6794e9fab212dd8c656d3875311df96b73b088 100644 (file)
@@ -380,7 +380,7 @@ M: c-type-name flatten-value-type c-type flatten-value-type ;
     [ [ parameter-offsets nip ] keep ] dip 2reverse-each ; inline
 
 : prepare-unbox-parameters ( parameters -- offsets types indices )
-    [ parameter-offsets nip ] [ ] [ length iota reverse ] tri ;
+    [ parameter-offsets nip ] [ ] [ length iota <reversed> ] tri ;
 
 : unbox-parameters ( offset node -- )
     parameters>> swap
@@ -436,6 +436,16 @@ M: ##alien-invoke generate-insn
     dup %cleanup
     box-return* ;
 
+M: ##alien-assembly generate-insn
+    params>>
+    ! Unbox parameters
+    dup objects>registers
+    %prepare-var-args
+    ! Generate assembly
+    dup quot>> call( -- )
+    ! Box return value
+    box-return* ;
+
 ! ##alien-indirect
 M: ##alien-indirect generate-insn
     params>>
@@ -464,7 +474,7 @@ M: ##alien-indirect generate-insn
 
 TUPLE: callback-context ;
 
-: current-callback ( -- id ) 2 getenv ;
+: current-callback ( -- id ) 2 special-object ;
 
 : wait-to-return ( token -- )
     dup current-callback eq? [
@@ -475,7 +485,7 @@ TUPLE: callback-context ;
 
 : do-callback ( quot token -- )
     init-catchstack
-    [ 2 setenv call ] keep
+    [ 2 set-special-object call ] keep
     wait-to-return ; inline
 
 : callback-return-quot ( ctype -- quot )
index dbe7c864a5a93613e378803f7fef465b8a5a1d41..efdc02cc1fa962fa0285a8f754cd0e5a551a15ca 100644 (file)
@@ -1,10 +1,10 @@
-! Copyright (C) 2007, 2009 Slava Pestov.
+! Copyright (C) 2007, 2010 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
 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 math.order generalizations
-accessors growable fry compiler.constants ;
+accessors growable fry compiler.constants memoize ;
 IN: compiler.codegen.fixup
 
 ! Owner
@@ -52,8 +52,11 @@ SYMBOL: relocation-table
 : rel-fixup ( class type -- )
     swap compiled-offset add-relocation-entry ;
 
+! Caching common symbol names reduces image size a bit
+MEMO: cached-string>symbol ( symbol -- obj ) string>symbol ;
+
 : add-dlsym-parameters ( symbol dll -- )
-    [ string>symbol add-parameter ] [ add-parameter ] bi* ;
+    [ cached-string>symbol add-parameter ] [ add-parameter ] bi* ;
 
 : rel-dlsym ( name dll class -- )
     [ add-dlsym-parameters ] dip rt-dlsym rel-fixup ;
index 83b50b61f4dc21d1743ffa317baca4abf14349aa..499a1b192fb2f3ba163816a34e84f43b171082e2 100644 (file)
@@ -25,6 +25,13 @@ CONSTANT: deck-bits 18
 : word-code-offset ( -- n ) 11 \ word type-number slot-offset ; inline
 : array-start-offset ( -- n ) 2 array type-number slot-offset ; inline
 : compiled-header-size ( -- n ) 4 bootstrap-cells ; inline
+: callstack-length-offset ( -- n ) 1 \ callstack type-number slot-offset ; inline
+: callstack-top-offset ( -- n ) 2 \ callstack type-number slot-offset ; inline
+: vm-context-offset ( -- n ) 0 bootstrap-cells ; inline
+: context-callstack-top-offset ( -- n ) 0 bootstrap-cells ; inline
+: context-callstack-bottom-offset ( -- n ) 1 bootstrap-cells ; inline
+: context-datastack-offset ( -- n ) 2 bootstrap-cells ; inline
+: context-retainstack-offset ( -- n ) 3 bootstrap-cells ; inline
 
 ! Relocation classes
 CONSTANT: rc-absolute-cell 0
index e6abab1267857dbf6ba8173cd98786a84c8fc70f..4cfbe8f6fa03bc7de20c0818cb42ad08014d10fe 100644 (file)
@@ -164,7 +164,7 @@ FUNCTION: void ffi_test_20 double x1, double x2, double x3,
     { int int int int int int int int int int int int int int int int int int int int int int int int int int int int int int int int int int int int int int int int int int }
     alien-invoke gc 3 ;
 
-[ 861 3 ] [ 42 [ ] each ffi_test_31 ] unit-test
+[ 861 3 ] [ 42 [ ] each-integer ffi_test_31 ] unit-test
 
 : ffi_test_31_point_5 ( a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a -- result )
     float
@@ -172,7 +172,7 @@ FUNCTION: void ffi_test_20 double x1, double x2, double x3,
     { float float float float float float float float float float float float float float float float float float float float float float float float float float float float float float float float float float float float float float float float float float }
     alien-invoke ;
 
-[ 861.0 ] [ 42 [ >float ] each ffi_test_31_point_5 ] unit-test
+[ 861.0 ] [ 42 [ >float ] each-integer ffi_test_31_point_5 ] unit-test
 
 FUNCTION: longlong ffi_test_21 long x long y ;
 
@@ -316,7 +316,7 @@ FUNCTION: ulonglong ffi_test_38 ( ulonglong x, ulonglong y ) ;
 
 : callback-1 ( -- callback ) void { } "cdecl" [ ] alien-callback ;
 
-[ 0 1 ] [ [ callback-1 ] infer [ in>> ] [ out>> ] bi ] unit-test
+[ 0 1 ] [ [ callback-1 ] infer [ in>> length ] [ out>> length ] bi ] unit-test
 
 [ t ] [ callback-1 alien? ] unit-test
 
@@ -377,9 +377,7 @@ FUNCTION: ulonglong ffi_test_38 ( ulonglong x, ulonglong y ) ;
 [ f ] [ namespace global eq? ] unit-test
 
 : callback-8 ( -- callback )
-    void { } "cdecl" [
-        [ continue ] callcc0
-    ] alien-callback ;
+    void { } "cdecl" [ [ ] in-thread yield ] alien-callback ;
 
 [ ] [ callback-8 callback_test_1 ] unit-test
 
@@ -591,3 +589,8 @@ FUNCTION: short ffi_test_48 ( bool-field-test x ) ;
 FUNCTION: void this_does_not_exist ( ) ;
 
 [ this_does_not_exist ] [ { "kernel-error" 9 f f } = ] must-fail-with
+
+! More alien-assembly tests are in cpu.* vocabs
+: assembly-test-1 ( -- ) void { } "cdecl" [ ] alien-assembly ;
+
+[ ] [ assembly-test-1 ] unit-test
index eba65805746b39c2b1466639b1935ff4013f8c4a..cff685eaf6e7066d059a0704561a15c1c1ed7c93 100644 (file)
@@ -116,7 +116,7 @@ unit-test
     1 1.0 2.5 try-breaking-dispatch "bye" = [ 3.5 = ] dip and ;
 
 [ t ] [
-    10000000 [ drop try-breaking-dispatch-2 ] all?
+    10000000 [ drop try-breaking-dispatch-2 ] all-integers?
 ] unit-test
 
 ! Regression
@@ -314,7 +314,7 @@ cell 4 = [
 
 ! Bug with ##return node construction
 : return-recursive-bug ( nodes -- ? )
-    { fixnum } declare [
+    { fixnum } declare iota [
         dup 3 bitand 1 = [ drop t ] [
             dup 3 bitand 2 = [
                 return-recursive-bug
index 14b347008cb3f7524850ba4c68da4b8812bca741..632a560c0df9834f7a27f854678f0115be408d73 100644 (file)
@@ -1,5 +1,5 @@
 USING: compiler.units compiler kernel kernel.private memory math
-math.private tools.test math.floats.private ;
+math.private tools.test math.floats.private math.order fry ;
 IN: compiler.tests.float
 
 [ 5.0 ] [ [ 5.0 ] compile-call gc gc gc ] unit-test
@@ -84,11 +84,6 @@ IN: compiler.tests.float
 
 [ 315 315.0 ] [ 313 [ 2 fixnum+fast dup fixnum>float ] compile-call ] unit-test
 
-[ 17.5 ] [ -11.3 17.5 [ float-max ] compile-call ] unit-test
-[ 17.5 ] [ 17.5 -11.3 [ float-max ] compile-call ] unit-test
-[ -11.3 ] [ -11.3 17.5 [ float-min ] compile-call ] unit-test
-[ -11.3 ] [ 17.5 -11.3 [ float-min ] compile-call ] unit-test
-
 [ t ] [ 0/0. 0/0. [ float-unordered? ] compile-call ] unit-test
 [ t ] [ 0/0. 1.0 [ float-unordered? ] compile-call ] unit-test
 [ t ] [ 1.0 0/0. [ float-unordered? ] compile-call ] unit-test
@@ -100,3 +95,23 @@ IN: compiler.tests.float
 [ 1 ] [ 1.0 0/0. [ float-unordered? [ 1 ] [ 2 ] if ] compile-call ] unit-test
 [ 2 ] [ 3.0 1.0 [ float-unordered? [ 1 ] [ 2 ] if ] compile-call ] unit-test
 [ 2 ] [ 1.0 3.0 [ float-unordered? [ 1 ] [ 2 ] if ] compile-call ] unit-test
+
+! Ensure that float-min and min, and float-max and max, have
+! consistent behavior with respect to NaNs
+
+: two-floats ( a b -- a b ) { float float } declare ; inline
+
+[ -11.3 ] [ -11.3 17.5 [ two-floats min ] compile-call ] unit-test
+[ -11.3 ] [ 17.5 -11.3 [ two-floats min ] compile-call ] unit-test
+[ 17.5 ] [ -11.3 17.5 [ two-floats max ] compile-call ] unit-test
+[ 17.5 ] [ 17.5 -11.3 [ two-floats max ] compile-call ] unit-test
+
+: check-compiled-binary-op ( a b word -- )
+    [ '[ [ [ two-floats _ execute ] compile-call ] call( a b -- c ) ] ]
+    [ '[ _ execute ] ]
+    bi 2bi fp-bitwise= ; inline
+
+[ t ] [ 0/0. 3.0 \ min check-compiled-binary-op ] unit-test
+[ t ] [ 3.0 0/0. \ min check-compiled-binary-op ] unit-test
+[ t ] [ 0/0. 3.0 \ max check-compiled-binary-op ] unit-test
+[ t ] [ 3.0 0/0. \ max check-compiled-binary-op ] unit-test
index 7fe5e2b60110e9ab2060093e3ad8d4d5106d29fb..1c066f26a336c866e419ddf1bfdba4a6ba0a9d40 100644 (file)
@@ -54,8 +54,8 @@ IN: compiler.tests.intrinsics
 [ HEX: 123456 ] [ 1 [ "a\u123456c" string-nth ] compile-call ] unit-test
 [ HEX: 123456 ] [ [ 1 "a\u123456c" string-nth ] compile-call ] unit-test
 
-[ ] [ [ 0 getenv ] compile-call drop ] unit-test
-[ ] [ 1 getenv [ 1 setenv ] compile-call ] unit-test
+[ ] [ [ 0 special-object ] compile-call drop ] unit-test
+[ ] [ 1 special-object [ 1 set-special-object ] compile-call ] unit-test
 
 [ ] [ 1 [ drop ] compile-call ] unit-test
 [ ] [ [ 1 drop ] compile-call ] unit-test
@@ -337,7 +337,7 @@ ERROR: bug-in-fixnum* x y a b ;
 
 [ ] [
     10000 [
-        5 random [ drop 32 random-bits ] map product >bignum
+        5 random iota [ drop 32 random-bits ] map product >bignum
         dup [ bignum>fixnum ] keep compiled-bignum>fixnum =
         [ drop ] [ "Oops" throw ] if
     ] times
index 0831d6e8ddc91b7aeb2d7c768b514237123cf5af..865cd639a356583633aa93018d5eac11356a63b2 100644 (file)
@@ -4,7 +4,7 @@ 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 definitions generic.single shuffle ;
+compiler definitions generic.single shuffle math.order ;
 IN: compiler.tests.optimizer
 
 GENERIC: xyz ( obj -- obj )
@@ -90,7 +90,7 @@ TUPLE: pred-test ;
 : double-label-2 ( a -- b )
     dup array? [ ] [ ] if 0 t double-label-1 ;
 
-[ 0 ] [ 10 double-label-2 ] unit-test
+[ 0 ] [ 10 iota double-label-2 ] unit-test
 
 ! regression
 GENERIC: void-generic ( obj -- * )
@@ -208,7 +208,7 @@ USE: binary-search.private
     ] if ; inline recursive
 
 [ 10 ] [
-    10 20 >vector <flat-slice>
+    10 20 iota <flat-slice>
     [ [ - ] swap old-binsearch ] compile-call 2nip
 ] unit-test
 
@@ -349,7 +349,7 @@ TUPLE: some-tuple x ;
 [ 5 ] [ { 1 2 { 3 { 4 5 } } } deep-find-test ] unit-test
 [ f ] [ { 1 2 { 3 { 4 } } } deep-find-test ] unit-test
 
-[ B{ 0 1 2 3 4 5 6 7 } ] [ [ 8 [ ] B{ } map-as ] compile-call ] unit-test
+[ B{ 0 1 2 3 4 5 6 7 } ] [ [ 8 iota [ ] B{ } map-as ] compile-call ] unit-test
 
 [ 0 ] [ 1234 [ { fixnum } declare -64 shift ] compile-call ] unit-test
 
@@ -445,5 +445,17 @@ M: object bad-dispatch-position-test* ;
 
 [ 1024 bignum ] [ 10 [ 1 >bignum swap >fixnum shift ] compile-call dup class ] unit-test
 
-! Not sure if I want to fix this...
-! [ t [ [ f ] [ 3 ] if >fixnum ] compile-call ] [ no-method? ] must-fail-with
+TUPLE: grid-mesh-tuple { length read-only } { step read-only } ;
+
+: grid-mesh-test-case ( -- vertices )
+    1.0 1.0 { 2 } first /f [ /i 1 + ] keep grid-mesh-tuple boa
+    1 f <array>
+    [
+        [ drop length>> >fixnum 2 min ] 2keep
+        [
+            [ step>> 1 * ] dip
+            0 swap set-nth-unsafe
+        ] 2curry times
+    ] keep ;
+
+[ { 0.5 } ] [ grid-mesh-test-case ] unit-test
index 0b3b46fe336da1463d13c1e0118fa6415a8c6a4e..b3f01c8c01b02f1764071695a791dc3a1c3bf0de 100644 (file)
@@ -185,9 +185,7 @@ M: #recursive check-stack-flow*
 
 M: #copy check-stack-flow* [ check-in-d ] [ check-out-d ] bi ;
 
-M: #alien-invoke check-stack-flow* [ check-in-d ] [ check-out-d ] bi ;
-
-M: #alien-indirect check-stack-flow* [ check-in-d ] [ check-out-d ] bi ;
+M: #alien-node check-stack-flow* [ check-in-d ] [ check-out-d ] bi ;
 
 M: #alien-callback check-stack-flow* drop ;
 
index db960863717aa28fffa3234d874ec2860f3da710..05f9092ee130fe95ee6e3f72e607fabc95beaed5 100644 (file)
@@ -339,28 +339,23 @@ cell-bits 32 = [
 ] unit-test
 
 [ t ] [
-    [ { fixnum } declare length [ drop ] each-integer ]
+    [ { fixnum } declare iota [ drop ] each ]
     { < <-integer-fixnum +-integer-fixnum + } inlined?
 ] unit-test
 
 [ t ] [
-    [ { fixnum } declare [ drop ] each ]
-    { < <-integer-fixnum +-integer-fixnum + } inlined?
-] unit-test
-
-[ t ] [
-    [ { fixnum } declare 0 [ + ] reduce ]
+    [ { fixnum } declare iota 0 [ + ] reduce ]
     { < <-integer-fixnum nth-unsafe } inlined?
 ] unit-test
 
 [ f ] [
-    [ { fixnum } declare 0 [ + ] reduce ]
+    [ { fixnum } declare iota 0 [ + ] reduce ]
     \ +-integer-fixnum inlined?
 ] unit-test
 
 [ f ] [
     [
-        { integer } declare [ ] map
+        { integer } declare iota [ ] map
     ] \ >fixnum inlined?
 ] unit-test
 
@@ -403,7 +398,7 @@ cell-bits 32 = [
 
 [ t ] [
     [
-        { integer } declare [ 0 >= ] map
+        { integer } declare iota [ 0 >= ] map
     ] { >= fixnum>= } inlined?
 ] unit-test
 
index 6cef45a9c91767ab64577697f9e6f51bf9d61c52..d1fdf6359a19322c472b5422b4c7365105487a2c 100644 (file)
@@ -1,4 +1,4 @@
-! Copyright (C) 2008 Slava Pestov.
+! Copyright (C) 2008, 2010 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
 USING: sequences namespaces kernel accessors assocs sets fry
 arrays combinators columns stack-checker.backend
@@ -36,7 +36,7 @@ M: #branch remove-dead-code*
 
 : drop-indexed-values ( values indices -- node )
     [ drop filter-live ] [ swap nths ] 2bi
-    [ make-values ] keep
+    [ length make-values ] keep
     [ drop ] [ zip ] 2bi
     #data-shuffle ;
 
index 482d370947bb626a601c217fc42689edd9ee5f8b..0c9464374a6edae178674a1494a32b523991fc83 100644 (file)
@@ -1,4 +1,4 @@
-! Copyright (C) 2008 Slava Pestov.
+! Copyright (C) 2008, 2010 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
 USING: accessors arrays assocs sequences kernel locals fry
 combinators stack-checker.backend
@@ -24,7 +24,7 @@ M: #call-recursive compute-live-values*
 
 :: drop-dead-inputs ( inputs outputs -- #shuffle )
     inputs filter-live
-    outputs inputs filter-corresponding make-values
+    outputs inputs filter-corresponding length make-values
     outputs
     inputs
     drop-values ;
@@ -39,7 +39,7 @@ M: #enter-recursive remove-dead-code*
     2bi ;
 
 :: (drop-call-recursive-outputs) ( inputs outputs -- #shuffle )
-    inputs outputs filter-corresponding make-values :> new-live-outputs
+    inputs outputs filter-corresponding length make-values :> new-live-outputs
     outputs filter-live :> live-outputs
     new-live-outputs
     live-outputs
index 67c5cfdc78a55352390da3826bfa41345f29b0ce..77523568d70f6ecc2f6838e515e392359218ef2d 100644 (file)
@@ -1,4 +1,4 @@
-! Copyright (C) 2008 Slava Pestov.
+! Copyright (C) 2008, 2010 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
 USING: kernel accessors words assocs sequences arrays namespaces
 fry locals definitions classes classes.algebra generic
@@ -28,9 +28,7 @@ M: method-body flushable? "method-generic" word-prop flushable? ;
 M: #call mark-live-values*
     dup flushable-call? [ drop ] [ look-at-inputs ] if ;
 
-M: #alien-invoke mark-live-values* look-at-inputs ;
-
-M: #alien-indirect mark-live-values* look-at-inputs ;
+M: #alien-node mark-live-values* look-at-inputs ;
 
 M: #return mark-live-values* look-at-inputs ;
 
@@ -47,9 +45,7 @@ M: #call compute-live-values* nip look-at-inputs ;
 M: #shuffle compute-live-values*
     mapping>> at look-at-value ;
 
-M: #alien-invoke compute-live-values* nip look-at-inputs ;
-
-M: #alien-indirect compute-live-values* nip look-at-inputs ;
+M: #alien-node compute-live-values* nip look-at-inputs ;
 
 : filter-mapping ( assoc -- assoc' )
     live-values get '[ drop _ key? ] assoc-filter ;
@@ -71,7 +67,7 @@ M: #alien-indirect compute-live-values* nip look-at-inputs ;
     filter-corresponding zip #data-shuffle ; inline
 
 :: drop-dead-values ( outputs -- #shuffle )
-    outputs make-values :> new-outputs
+    outputs length make-values :> new-outputs
     outputs filter-live :> live-outputs
     new-outputs
     live-outputs
@@ -127,8 +123,5 @@ M: #terminate remove-dead-code*
     [ filter-live ] change-in-d
     [ filter-live ] change-in-r ;
 
-M: #alien-invoke remove-dead-code*
-    maybe-drop-dead-outputs ;
-
-M: #alien-indirect remove-dead-code*
+M: #alien-node remove-dead-code*
     maybe-drop-dead-outputs ;
index 63f145d752a24aaf53474647f9de6e7c22a2e4f4..47ec13e809b4eb9f3084c6bb145b4dafc76f0e31 100644 (file)
@@ -1,4 +1,4 @@
-! Copyright (C) 2006, 2009 Slava Pestov.
+! Copyright (C) 2006, 2010 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
 USING: kernel assocs match fry accessors namespaces make effects
 sequences sequences.private quotations generic macros arrays
@@ -64,7 +64,7 @@ TUPLE: shuffle-node { effect effect } ;
 M: shuffle-node pprint* effect>> effect>string text ;
  
 : (shuffle-effect) ( in out #shuffle -- effect )
-    mapping>> '[ _ at ] map <effect> ;
+    mapping>> '[ _ at ] map [ >array ] bi@ <effect> ;
 
 : shuffle-effect ( #shuffle -- effect )
     [ in-d>> ] [ out-d>> ] [ ] tri (shuffle-effect) ;
@@ -126,6 +126,8 @@ M: #alien-invoke node>quot params>> , \ #alien-invoke , ;
 
 M: #alien-indirect node>quot params>> , \ #alien-indirect , ;
 
+M: #alien-assembly node>quot params>> , \ #alien-assembly , ;
+
 M: #alien-callback node>quot params>> , \ #alien-callback , ;
 
 M: node node>quot drop ;
index c26f3ddefc02a26a7f779ed1c69aea5829d04649..bb32e6e23b1a229cee60d336cacfcad359547a88 100644 (file)
@@ -1,4 +1,4 @@
-USING: kernel tools.test namespaces sequences
+USING: kernel tools.test namespaces sequences math
 compiler.tree.escape-analysis.recursive
 compiler.tree.escape-analysis.allocations ;
 IN: compiler.tree.escape-analysis.recursive.tests
@@ -6,7 +6,7 @@ IN: compiler.tree.escape-analysis.recursive.tests
 H{ } clone allocations set
 <escaping-values> escaping-values set
 
-[ ] [ 8 [ introduce-value ] each ] unit-test
+[ ] [ 8 [ introduce-value ] each-integer ] unit-test
 
 [ ] [ { 1 2 } 3 record-allocation ] unit-test
 
index c053b15f29704aaa002b4e57418c2e7fa123e385..50fa7ef0a85f18abfd824349817252eb2cba913d 100644 (file)
@@ -86,12 +86,7 @@ M: #call escape-analysis*
 M: #return escape-analysis*
     in-d>> add-escaping-values ;
 
-M: #alien-invoke escape-analysis*
-    [ in-d>> add-escaping-values ]
-    [ out-d>> unknown-allocations ]
-    bi ;
-
-M: #alien-indirect escape-analysis*
+M: #alien-node escape-analysis*
     [ in-d>> add-escaping-values ]
     [ out-d>> unknown-allocations ]
     bi ;
index 42e7f421bfc04073ae014c6abd8d45aa6e931840..7366a83ee176f34df1920eb20c02556d89b7b6ba 100644 (file)
@@ -73,7 +73,7 @@ TUPLE: declared-fixnum { x fixnum } ;
 
 [ t ] [
     [
-        { fixnum } declare 0 swap
+        { fixnum } declare iota 0 swap
         [
             drop 615949 * 797807 + 20 2^ rem dup 19 2^ -
         ] map
@@ -94,7 +94,7 @@ TUPLE: declared-fixnum { x fixnum } ;
 
 [ t ] [
     [
-        { integer } declare [ 256 mod ] map
+        { integer } declare iota [ 256 mod ] map
     ] { mod fixnum-mod } inlined?
 ] unit-test
 
index fcfa42c70ba56388420cc896a217edd4c753c897..7912fce1f68d2c59256aef72c2b963e3da829467 100644 (file)
@@ -1,4 +1,4 @@
-! Copyright (C) 2008 Slava Pestov.
+! Copyright (C) 2008, 2010 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
 USING: fry namespaces sequences math math.order accessors kernel arrays
 combinators assocs
@@ -75,10 +75,9 @@ M: #phi normalize*
     ] with-variable ;
 
 M: #recursive normalize*
-    dup label>> introductions>>
-    [ drop [ child>> first ] [ in-d>> ] bi >>in-d drop ]
-    [ make-values '[ _ (normalize) ] change-child ]
-    2bi ;
+    [ [ child>> first ] [ in-d>> ] bi >>in-d drop ]
+    [ dup label>> introductions>> make-values '[ _ (normalize) ] change-child ]
+    bi ;
 
 M: #enter-recursive normalize*
     [ introduction-stack get prepend ] change-out-d
index ff4886d1c795ad0ecc2fb7d7dbe0d246f9474871..439b428784e3cb92c3d02bbb42c6d2f506bf6434 100644 (file)
@@ -1,8 +1,8 @@
-! Copyright (C) 2009 Slava Pestov, Daniel Ehrenberg.
+! Copyright (C) 2009, 2010 Slava Pestov, Daniel Ehrenberg.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: accessors combinators combinators.private effects fry
-kernel kernel.private make sequences continuations quotations
-words math stack-checker combinators.short-circuit
+USING: accessors arrays combinators combinators.private effects
+fry kernel kernel.private make sequences continuations
+quotations words math stack-checker combinators.short-circuit
 stack-checker.transforms compiler.tree.propagation.info
 compiler.tree.propagation.inlining compiler.units ;
 IN: compiler.tree.propagation.call-effect
@@ -43,7 +43,7 @@ M: +unknown+ curry-effect ;
 M: effect curry-effect
     [ in>> length ] [ out>> length ] [ terminated?>> ] tri
     pick 0 = [ [ 1 + ] dip ] [ [ 1 - ] 2dip ] if
-    effect boa ;
+    [ [ "x" <array> ] bi@ ] dip effect boa ;
 
 M: curry cached-effect
     quot>> cached-effect curry-effect ;
index 826131ab612525013b49a2c37c14488d238bbafe..446aad89e5cf224dab4e3e95cc260841c3b19946 100644 (file)
@@ -4,13 +4,6 @@ IN: compiler.tree.propagation.info.tests
 
 [ f ] [ 0.0 -0.0 eql? ] unit-test
 
-[ t ] [
-    number <class-info>
-    sequence <class-info>
-    value-info-intersect
-    class>> integer class=
-] unit-test
-
 [ t t ] [
     0 10 [a,b] <interval-info>
     5 20 [a,b] <interval-info>
index 0fde7ffa86d1b154389be7b923f61f93c5221c6c..6aacbc57daaa4a5168f5918ad52368e6c9588f72 100644 (file)
@@ -1,4 +1,4 @@
-! Copyright (C) 2008, 2009 Slava Pestov.
+! Copyright (C) 2008, 2010 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
 USING: kernel effects accessors math math.private
 math.integers.private math.floats.private math.partial-dispatch
@@ -23,11 +23,10 @@ IN: compiler.tree.propagation.known-words
 { + - * / }
 [ { number number } "input-classes" set-word-prop ] each
 
-{ /f < > <= >= u< u> u<= u>= }
+{ /f /i mod < > <= >= u< u> u<= u>= }
 [ { real real } "input-classes" set-word-prop ] each
 
-{ /i mod /mod }
-[ { rational rational } "input-classes" set-word-prop ] each
+\ /mod { rational rational } "input-classes" set-word-prop
 
 { bitand bitor bitxor bitnot shift }
 [ { integer integer } "input-classes" set-word-prop ] each
index c7e02aef4c59fa99a6151ce368bf490e23086f9a..2c80b87e76096ec0d79143946baaba672f9fc72a 100644 (file)
@@ -1,14 +1,13 @@
 USING: kernel compiler.tree.builder compiler.tree
 compiler.tree.propagation compiler.tree.recursive
-compiler.tree.normalization tools.test math math.order
-accessors sequences arrays kernel.private vectors
-alien.accessors alien.c-types sequences.private
-byte-arrays classes.algebra classes.tuple.private
-math.functions math.private strings layouts
-compiler.tree.propagation.info compiler.tree.def-use
-compiler.tree.debugger compiler.tree.checker
-slots.private words hashtables classes assocs locals
-specialized-arrays system sorting math.libm
+compiler.tree.normalization tools.test math math.order accessors
+sequences arrays kernel.private vectors alien.accessors
+alien.c-types sequences.private byte-arrays classes.algebra
+classes.tuple.private math.functions math.private strings
+layouts compiler.tree.propagation.info compiler.tree.def-use
+compiler.tree.debugger compiler.tree.checker slots.private words
+hashtables classes assocs locals specialized-arrays system
+sorting math.libm math.floats.private math.integers.private
 math.intervals quotations effects alien alien.data ;
 FROM: math => float ;
 SPECIALIZED-ARRAY: double
@@ -91,6 +90,8 @@ IN: compiler.tree.propagation.tests
 
 [ float ] [ [ { float float } declare mod ] final-math-class ] unit-test
 
+[ V{ integer float } ] [ [ { float float } declare [ /i ] keep ] final-classes ] unit-test
+
 [ V{ fixnum } ] [ [ 255 bitand ] final-classes ] unit-test
 
 [ V{ fixnum } ] [
@@ -405,14 +406,6 @@ IN: compiler.tree.propagation.tests
     ] final-literals
 ] unit-test
 
-[ V{ 27 } ] [
-    [
-        dup number? over sequence? and [
-            dup 10 < over 8 <= not and [ 3 * ] [ "A" throw ] if
-        ] [ "B" throw ] if
-    ] final-literals
-] unit-test
-
 [ V{ string string } ] [
     [
         2dup [ dup string? [ "Oops" throw ] unless ] bi@ 2drop
@@ -680,7 +673,7 @@ M: array iterate first t ; inline
 ] unit-test
 
 [ V{ fixnum } ] [
-    [ { fixnum fixnum } declare [ nth-unsafe ] curry call ] final-classes
+    [ { fixnum fixnum } declare iota [ nth-unsafe ] curry call ] final-classes
 ] unit-test
 
 [ V{ f } ] [
@@ -942,3 +935,14 @@ M: tuple-with-read-only-slot clone
 ! Could be bignum not integer but who cares
 [ V{ integer } ] [ [ 10 >bignum bitand ] final-classes ] unit-test
 
+[ t ] [ [ { fixnum fixnum } declare min ] { min } inlined? ] unit-test
+[ f ] [ [ { fixnum fixnum } declare min ] { fixnum-min } inlined? ] unit-test
+
+[ t ] [ [ { float float } declare min ] { min } inlined? ] unit-test
+[ f ] [ [ { float float } declare min ] { float-min } inlined? ] unit-test
+
+[ t ] [ [ { fixnum fixnum } declare max ] { max } inlined? ] unit-test
+[ f ] [ [ { fixnum fixnum } declare max ] { fixnum-max } inlined? ] unit-test
+
+[ t ] [ [ { float float } declare max ] { max } inlined? ] unit-test
+[ f ] [ [ { float float } declare max ] { float-max } inlined? ] unit-test
index b4d8b95247b4e7c1966f2323e685b09b0e3ce5ea..225f10d342ef55b729d37b70cf9b0d486aed2e04 100644 (file)
@@ -80,7 +80,7 @@ M: #declare propagate-before
 : (fold-call) ( #call word -- info )
     [ [ out-d>> ] [ in-d>> [ value-info literal>> ] map ] bi ] [ '[ _ execute ] ] bi*
     '[ _ _ with-datastack [ <literal-info> ] map nip ]
-    [ drop [ object-info ] replicate ]
+    [ drop length [ object-info ] replicate ]
     recover ;
 
 : fold-call ( #call word -- )
@@ -153,8 +153,6 @@ M: #call propagate-after
     [ out-d>> ] [ params>> return>> ] bi
     [ drop ] [ c-type-class <class-info> swap first set-value-info ] if-void ;
 
-M: #alien-invoke propagate-before propagate-alien-invoke ;
-
-M: #alien-indirect propagate-before propagate-alien-invoke ;
+M: #alien-node propagate-before propagate-alien-invoke ;
 
 M: #return annotate-node dup in-d>> (annotate-node) ;
index 809b51c6ef64128acb1e0d8360acc1f568bafc16..63c0aea13ebf931dd8e197be625e6dd0c5f6f434 100644 (file)
@@ -1,4 +1,4 @@
-! Copyright (C) 2008, 2009 Slava Pestov, Daniel Ehrenberg.
+! Copyright (C) 2008, 2010 Slava Pestov, Daniel Ehrenberg.
 ! See http://factorcode.org/license.txt for BSD license.
 USING: alien.c-types kernel sequences words fry generic accessors
 classes.tuple classes classes.algebra definitions
@@ -132,26 +132,6 @@ IN: compiler.tree.propagation.transforms
     ] "custom-inlining" set-word-prop
 ] each
 
-! Integrate this with generic arithmetic optimization instead?
-: both-inputs? ( #call class -- ? )
-    [ in-d>> first2 ] dip '[ value-info class>> _ class<= ] both? ;
-
-\ min [
-    {
-        { [ dup fixnum both-inputs? ] [ [ fixnum-min ] ] }
-        { [ dup float both-inputs? ] [ [ float-min ] ] }
-        [ f ]
-    } cond nip
-] "custom-inlining" set-word-prop
-
-\ max [
-    {
-        { [ dup fixnum both-inputs? ] [ [ fixnum-max ] ] }
-        { [ dup float both-inputs? ] [ [ float-max ] ] }
-        [ f ]
-    } cond nip
-] "custom-inlining" set-word-prop
-
 ! Generate more efficient code for common idiom
 \ clone [
     in-d>> first value-info literal>> {
@@ -209,7 +189,7 @@ ERROR: bad-partial-eval quot word ;
 \ index [
     dup sequence? [
         dup length 4 >= [
-            dup length zip >hashtable '[ _ at ]
+            dup length iota zip >hashtable '[ _ at ]
         ] [ drop f ] if
     ] [ drop f ] if
 ] 1 define-partial-eval
@@ -248,7 +228,7 @@ CONSTANT: lookup-table-at-max 256
     } 1&& ;
 
 : lookup-table-seq ( assoc -- table )
-    [ keys supremum 1 + ] keep '[ _ at ] { } map-as ;
+    [ keys supremum 1 + iota ] keep '[ _ at ] { } map-as ;
 
 : lookup-table-quot ( seq -- newquot )
     lookup-table-seq
index 82b8fbb8434f7ceae30119b96a3675a42bf83eab..a1d1b4db611f57f909a3cd30e51a2b29f739bed7 100644 (file)
@@ -1,4 +1,4 @@
-! Copyright (C) 2004, 2008 Slava Pestov.
+! Copyright (C) 2004, 2010 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
 USING: fry arrays generic assocs kernel math namespaces parser
 sequences words vectors math.intervals classes
@@ -149,7 +149,12 @@ TUPLE: #alien-indirect < #alien-node in-d out-d ;
 : #alien-indirect ( params -- node )
     \ #alien-indirect new-alien-node ;
 
-TUPLE: #alien-callback < #alien-node ;
+TUPLE: #alien-assembly < #alien-node in-d out-d ;
+
+: #alien-assembly ( params -- node )
+    \ #alien-assembly new-alien-node ;
+
+TUPLE: #alien-callback < node params ;
 
 : #alien-callback ( params -- node )
     \ #alien-callback new
@@ -187,4 +192,5 @@ M: vector #recursive, #recursive node, ;
 M: vector #copy, #copy node, ;
 M: vector #alien-invoke, #alien-invoke node, ;
 M: vector #alien-indirect, #alien-indirect node, ;
+M: vector #alien-assembly, #alien-assembly node, ;
 M: vector #alien-callback, #alien-callback node, ;
index de2848ea78dffeb78041ab8708baad15cc351b60..d4ca3010cee4b428fb77c7c959d94df9789d5f1d 100644 (file)
@@ -164,9 +164,7 @@ M: #branch unbox-tuples* dup in-d>> assert-not-unboxed ;
 
 M: #return unbox-tuples* dup in-d>> assert-not-unboxed ;
 
-M: #alien-invoke unbox-tuples* dup in-d>> assert-not-unboxed ;
-
-M: #alien-indirect unbox-tuples* dup in-d>> assert-not-unboxed ;
+M: #alien-node unbox-tuples* dup in-d>> assert-not-unboxed ;
 
 M: #alien-callback unbox-tuples* ;
 
index 567c435c2e05486e97378c1d7852c149d69e58e2..d96946d53dea21ae96bad72e81a6ccbe0da7cfd6 100644 (file)
@@ -36,7 +36,7 @@ CONSTANT: clen-shuffle { 16 17 18 0 8 7 9 6 10 5 11 4 12 3 13 2 14 1 15 }
     5 bitstream bs:read 1 +
     4 bitstream bs:read 4 + clen-shuffle swap head 
 
-    dup length iota [ 3 bitstream bs:read ] replicate
+    dup length [ 3 bitstream bs:read ] replicate
     get-table
     bitstream swap <huffman-decoder>
     [ 2dup + ] dip swap :> k!
@@ -64,13 +64,13 @@ CONSTANT: clen-shuffle { 16 17 18 0 8 7 9 6 10 5 11 4 12 3 13 2 14 1 15 }
 
 MEMO: static-huffman-tables ( -- obj )
     [
-        0 143 [a,b] [ 8 ] replicate
-        144 255 [a,b] [ 9 ] replicate append
-        256 279 [a,b] [ 7 ] replicate append
-        280 287 [a,b] [ 8 ] replicate append
+        0 143 [a,b] length [ 8 ] replicate
+        144 255 [a,b] length [ 9 ] replicate append
+        256 279 [a,b] length [ 7 ] replicate append
+        280 287 [a,b] length [ 8 ] replicate append
     ] append-outputs
-    0 31 [a,b] [ 5 ] replicate 2array
-    [ [ length>> [0,b) ] [ ] bi get-table ] map ;
+    0 31 [a,b] length [ 5 ] replicate 2array
+    [ [ length>> iota ] [ ] bi get-table ] map ;
 
 CONSTANT: length-table
     {
index 1baeba73d9c8dd140d5b481678a1b50b568560c6..b9bc502d46f301e83f41c8d00506f5a8b43fe95c 100644 (file)
@@ -1,9 +1,12 @@
 ! Copyright (C) 2009 Doug Coleman.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: kernel tools.test compression.zlib classes ;
+USING: accessors kernel tools.test compression.zlib classes ;
+QUALIFIED-WITH: compression.zlib.ffi ffi
 IN: compression.zlib.tests
 
 : compress-me ( -- byte-array ) B{ 1 2 3 4 5 } ;
 
 [ t ] [ compress-me [ compress uncompress ] keep = ] unit-test
 [ t ] [ compress-me compress compressed instance? ] unit-test
+
+[ ffi:Z_DATA_ERROR zlib-error-message ] [ string>> "data error" = ] must-fail-with
index 781817349809dd7075312f18a855d38d387887f9..c662eec04970b05bcb868c0cdcd7ccd3cd697311 100644 (file)
@@ -19,7 +19,9 @@ ERROR: zlib-failed n string ;
     dup compression.zlib.ffi:Z_ERRNO = [
         drop errno "native libc error"
     ] [
-        dup {
+        dup
+        neg ! zlib error codes are negative
+        {
             "no error" "libc_error"
             "stream error" "data error"
             "memory error" "buffer error" "zlib version error"
index d3f3229171bb279522c8d01d0e6c869d62a00077..f33f6513a97330472ef301dd3cac8601419f37bf 100644 (file)
@@ -17,12 +17,12 @@ IN: concurrency.combinators.tests
 [ error>> "Even" = ] must-fail-with\r
 \r
 [ V{ 0 3 6 9 } ]\r
-[ 10 [ 3 mod zero? ] parallel-filter ] unit-test\r
+[ 10 iota [ 3 mod zero? ] parallel-filter ] unit-test\r
 \r
 [ 10 ]\r
 [\r
     V{ } clone\r
-    10 over [ push ] curry parallel-each\r
+    10 iota over [ push ] curry parallel-each\r
     length\r
 ] unit-test\r
 \r
@@ -41,7 +41,7 @@ IN: concurrency.combinators.tests
 [ 20 ]\r
 [\r
     V{ } clone\r
-    10 10 pick [ [ push ] [ push ] bi ] curry 2parallel-each\r
+    10 iota 10 iota pick [ [ push ] [ push ] bi ] curry 2parallel-each\r
     length\r
 ] unit-test\r
 \r
index 5127b56acffb369fd7898949c08c0a07a6e8f523..03090dc4b514138cb6561f6955677a899b9d34c7 100644 (file)
@@ -550,7 +550,7 @@ HOOK: %save-param-reg cpu ( stack reg rep -- )
 
 HOOK: %load-param-reg cpu ( stack reg rep -- )
 
-HOOK: %load-context cpu ( temp1 temp2 -- )
+HOOK: %restore-context cpu ( temp1 temp2 -- )
 
 HOOK: %save-context cpu ( temp1 temp2 -- )
 
index a5267b898b76a9b6b4b55c991fb41413123b291a..e3c212bd482648af6f250a1bbd405e13112a37fe 100644 (file)
@@ -1,9 +1,10 @@
-! Copyright (C) 2007, 2009 Slava Pestov.\r
+! Copyright (C) 2007, 2010 Slava Pestov.\r
 ! See http://factorcode.org/license.txt for BSD license.\r
 USING: bootstrap.image.private kernel kernel.private namespaces\r
 system cpu.ppc.assembler compiler.codegen.fixup compiler.units\r
-compiler.constants math math.private layouts words vocabs\r
-slots.private locals locals.backend generic.single.private fry ;\r
+compiler.constants math math.private math.ranges layouts words vocabs\r
+slots.private locals locals.backend generic.single.private fry\r
+sequences ;\r
 FROM: cpu.ppc.assembler => B ;\r
 IN: bootstrap.ppc\r
 \r
@@ -13,28 +14,88 @@ big-endian on
 CONSTANT: ds-reg 13\r
 CONSTANT: rs-reg 14\r
 CONSTANT: vm-reg 15\r
+CONSTANT: ctx-reg 16\r
 \r
-: factor-area-size ( -- n ) 4 bootstrap-cells ;\r
+: factor-area-size ( -- n ) 16 ;\r
 \r
 : stack-frame ( -- n )\r
-    factor-area-size c-area-size + 4 bootstrap-cells align ;\r
+    reserved-size\r
+    factor-area-size +\r
+    16 align ;\r
 \r
-: next-save ( -- n ) stack-frame bootstrap-cell - ;\r
-: xt-save ( -- n ) stack-frame 2 bootstrap-cells - ;\r
+: next-save ( -- n ) stack-frame 4 - ;\r
+: xt-save ( -- n ) stack-frame 8 - ;\r
+\r
+: param-size ( -- n ) 32 ;\r
+\r
+: save-at ( m -- n ) reserved-size + param-size + ;\r
+\r
+: save-int ( register offset -- ) [ 1 ] dip save-at STW ;\r
+: restore-int ( register offset -- ) [ 1 ] dip save-at LWZ ;\r
+\r
+: save-fp ( register offset -- ) [ 1 ] dip save-at STFD ;\r
+: restore-fp ( register offset -- ) [ 1 ] dip save-at LFD ;\r
+\r
+: save-vec ( register offset -- ) save-at 2 LI 2 1 STVXL ;\r
+: restore-vec ( register offset -- ) save-at 2 LI 2 1 LVXL ;\r
+\r
+: nv-int-regs ( -- seq ) 13 31 [a,b] ;\r
+: nv-fp-regs ( -- seq ) 14 31 [a,b] ;\r
+: nv-vec-regs ( -- seq ) 20 31 [a,b] ;\r
+\r
+: saved-int-regs-size ( -- n ) 96 ;\r
+: saved-fp-regs-size ( -- n ) 144 ;\r
+: saved-vec-regs-size ( -- n ) 208 ;\r
+\r
+: callback-frame-size ( -- n )\r
+    reserved-size\r
+    param-size +\r
+    saved-int-regs-size +\r
+    saved-fp-regs-size +\r
+    saved-vec-regs-size +\r
+    16 align ;\r
+\r
+[\r
+    0 MFLR\r
+    1 1 callback-frame-size neg STWU\r
+    0 1 callback-frame-size lr-save + STW\r
+\r
+    nv-int-regs [ 4 * save-int ] each-index\r
+    nv-fp-regs [ 8 * 80 + save-fp ] each-index\r
+    nv-vec-regs [ 16 * 224 + save-vec ] each-index\r
+\r
+    0 vm-reg LOAD32 rc-absolute-ppc-2/2 rt-vm jit-rel\r
+\r
+    0 2 LOAD32 rc-absolute-ppc-2/2 rt-xt jit-rel\r
+    2 MTLR\r
+    BLRL\r
+\r
+    nv-vec-regs [ 16 * 224 + restore-vec ] each-index\r
+    nv-fp-regs [ 8 * 80 + restore-fp ] each-index\r
+    nv-int-regs [ 4 * restore-int ] each-index\r
+\r
+    0 1 callback-frame-size lr-save + LWZ\r
+    1 1 0 LWZ\r
+    0 MTLR\r
+    BLR\r
+] callback-stub jit-define\r
 \r
 : jit-conditional* ( test-quot false-quot -- )\r
-    [ '[ bootstrap-cell /i 1 + @ ] ] dip jit-conditional ; inline\r
+    [ '[ 4 /i 1 + @ ] ] dip jit-conditional ; inline\r
+\r
+: jit-load-context ( -- )\r
+    ctx-reg vm-reg vm-context-offset LWZ ;\r
 \r
 : jit-save-context ( -- )\r
-    4 vm-reg 0 LWZ\r
-    1 4 0 STW\r
-    ds-reg 4 8 STW\r
-    rs-reg 4 12 STW ;\r
+    jit-load-context\r
+    1 ctx-reg context-callstack-top-offset STW\r
+    ds-reg ctx-reg context-datastack-offset STW\r
+    rs-reg ctx-reg context-retainstack-offset STW ;\r
 \r
 : jit-restore-context ( -- )\r
-    4 vm-reg 0 LWZ\r
-    ds-reg 4 8 LWZ\r
-    rs-reg 4 12 LWZ ;\r
+    jit-load-context\r
+    ds-reg ctx-reg context-datastack-offset LWZ\r
+    rs-reg ctx-reg context-retainstack-offset LWZ ;\r
 \r
 [\r
     0 3 LOAD32 rc-absolute-ppc-2/2 rt-literal jit-rel\r
@@ -48,12 +109,12 @@ CONSTANT: vm-reg 15
 ] jit-profiling jit-define\r
 \r
 [\r
-    0 3 LOAD32 rc-absolute-ppc-2/2 rt-this jit-rel\r
+    0 2 LOAD32 rc-absolute-ppc-2/2 rt-this jit-rel\r
     0 MFLR\r
     1 1 stack-frame SUBI\r
-    3 1 xt-save STW\r
-    stack-frame 3 LI\r
-    3 1 next-save STW\r
+    2 1 xt-save STW\r
+    stack-frame 2 LI\r
+    2 1 next-save STW\r
     0 1 lr-save stack-frame + STW\r
 ] jit-prolog jit-define\r
 \r
@@ -181,7 +242,7 @@ CONSTANT: vm-reg 15
     load-tag\r
     0 4 tuple type-number tag-fixnum CMPI\r
     [ BNE ]\r
-    [ 4 3 tuple type-number neg bootstrap-cell + LWZ ]\r
+    [ 4 3 tuple type-number neg 4 + LWZ ]\r
     jit-conditional*\r
 ] pic-tuple jit-define\r
 \r
@@ -215,12 +276,12 @@ CONSTANT: vm-reg 15
 [ jit-load-return-address jit-inline-cache-miss ]\r
 [ 3 MTLR BLRL ]\r
 [ 3 MTCTR BCTR ]\r
-\ inline-cache-miss define-sub-primitive*\r
+\ inline-cache-miss define-combinator-primitive\r
 \r
 [ jit-inline-cache-miss ]\r
 [ 3 MTLR BLRL ]\r
 [ 3 MTCTR BCTR ]\r
-\ inline-cache-miss-tail define-sub-primitive*\r
+\ inline-cache-miss-tail define-combinator-primitive\r
 \r
 ! ! ! Megamorphic caches\r
 \r
@@ -230,7 +291,7 @@ CONSTANT: vm-reg 15
     ! key = hashcode(class)\r
     5 4 1 SRAWI\r
     ! key &= cache.length - 1\r
-    5 5 mega-cache-size get 1 - bootstrap-cell * ANDI\r
+    5 5 mega-cache-size get 1 - 4 * ANDI\r
     ! cache += array-start-offset\r
     3 3 array-start-offset ADDI\r
     ! cache += key\r
@@ -245,7 +306,7 @@ CONSTANT: vm-reg 15
         5 4 0 LWZ\r
         5 5 1 ADDI\r
         5 4 0 STW\r
-        ! ... goto get(cache + bootstrap-cell)\r
+        ! ... goto get(cache + 4)\r
         3 3 4 LWZ\r
         3 3 word-xt-offset LWZ\r
         3 MTCTR\r
@@ -255,23 +316,16 @@ CONSTANT: vm-reg 15
     ! fall-through on miss\r
 ] mega-lookup jit-define\r
 \r
-[\r
-    0 2 LOAD32 rc-absolute-ppc-2/2 rt-xt jit-rel\r
-    2 MTCTR\r
-    BCTR\r
-] callback-stub jit-define\r
-\r
 ! ! ! Sub-primitives\r
 \r
 ! Quotations and words\r
 [\r
     3 ds-reg 0 LWZ\r
     ds-reg dup 4 SUBI\r
-    4 vm-reg MR\r
     5 3 quot-xt-offset LWZ\r
 ]\r
 [ 5 MTLR BLRL ]\r
-[ 5 MTCTR BCTR ] \ (call) define-sub-primitive*\r
+[ 5 MTCTR BCTR ] \ (call) define-combinator-primitive\r
 \r
 [\r
     3 ds-reg 0 LWZ\r
@@ -279,7 +333,7 @@ CONSTANT: vm-reg 15
     4 3 word-xt-offset LWZ\r
 ]\r
 [ 4 MTLR BLRL ]\r
-[ 4 MTCTR BCTR ] \ (execute) define-sub-primitive*\r
+[ 4 MTCTR BCTR ] \ (execute) define-combinator-primitive\r
 \r
 [\r
     3 ds-reg 0 LWZ\r
@@ -288,6 +342,79 @@ CONSTANT: vm-reg 15
     4 MTCTR BCTR\r
 ] jit-execute jit-define\r
 \r
+! Special primitives\r
+[\r
+    jit-restore-context\r
+    ! Save ctx->callstack_bottom\r
+    1 ctx-reg context-callstack-bottom-offset STW\r
+    ! Call quotation\r
+    5 3 quot-xt-offset LWZ\r
+    5 MTLR\r
+    BLRL\r
+    jit-save-context\r
+] \ c-to-factor define-sub-primitive\r
+\r
+[\r
+    ! Unwind stack frames\r
+    1 4 MR\r
+\r
+    ! Load VM pointer into vm-reg, since we're entering from\r
+    ! C code\r
+    0 vm-reg LOAD32 0 rc-absolute-ppc-2/2 jit-vm\r
+\r
+    ! Load ds and rs registers\r
+    jit-restore-context\r
+\r
+    ! We have changed the stack; load return address again\r
+    0 1 lr-save LWZ\r
+    0 MTLR\r
+\r
+    ! Call quotation\r
+    4 3 quot-xt-offset LWZ\r
+    4 MTCTR\r
+    BCTR\r
+] \ unwind-native-frames define-sub-primitive\r
+\r
+[\r
+    ! Load callstack object\r
+    6 ds-reg 0 LWZ\r
+    ds-reg ds-reg 4 SUBI\r
+    ! Get ctx->callstack_bottom\r
+    jit-load-context\r
+    3 ctx-reg context-callstack-bottom-offset LWZ\r
+    ! Get top of callstack object -- 'src' for memcpy\r
+    4 6 callstack-top-offset ADDI\r
+    ! Get callstack length, in bytes --- 'len' for memcpy\r
+    5 6 callstack-length-offset LWZ\r
+    5 5 tag-bits get SRAWI\r
+    ! Compute new stack pointer -- 'dst' for memcpy\r
+    3 5 3 SUBF\r
+    ! Install new stack pointer\r
+    1 3 MR\r
+    ! Call memcpy; arguments are now in the correct registers\r
+    1 1 -64 STWU\r
+    0 2 LOAD32 "factor_memcpy" f rc-absolute-ppc-2/2 jit-dlsym\r
+    2 MTLR\r
+    BLRL\r
+    1 1 0 LWZ\r
+    ! Return with new callstack\r
+    0 1 lr-save LWZ\r
+    0 MTLR\r
+    BLR\r
+] \ set-callstack define-sub-primitive\r
+\r
+[\r
+    jit-save-context\r
+    4 vm-reg MR\r
+    0 2 LOAD32 "lazy_jit_compile" f rc-absolute-ppc-2/2 jit-dlsym\r
+    2 MTLR\r
+    BLRL\r
+    5 3 quot-xt-offset LWZ\r
+]\r
+[ 5 MTLR BLRL ]\r
+[ 5 MTCTR BCTR ]\r
+\ lazy-jit-compile define-combinator-primitive\r
+\r
 ! Objects\r
 [\r
     3 ds-reg 0 LWZ\r
index a5250414ab22dbb7abd63ca75ff43e219f2d316e..2f463dea007515dbe88c014c121c8f02533fe5f5 100644 (file)
@@ -1,10 +1,10 @@
-! Copyright (C) 2007, 2008 Slava Pestov.
+! Copyright (C) 2007, 2010 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: parser layouts system kernel sequences ;
+USING: parser system kernel sequences ;
 IN: bootstrap.ppc
 
-: c-area-size ( -- n ) 10 bootstrap-cells ;
-: lr-save ( -- n ) bootstrap-cell ;
+: reserved-size ( -- n ) 24 ;
+: lr-save ( -- n ) 4 ;
 
 << "vocab:cpu/ppc/bootstrap.factor" parse-file suffix! >>
 call
index 2aa0ddc4a27f4ec8e5e392e5442add49aea30531..0960011c70163e9f7081830282de9d3a2f51170a 100644 (file)
@@ -1,10 +1,10 @@
-! Copyright (C) 2007, 2008 Slava Pestov.
+! Copyright (C) 2007, 2010 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: parser layouts system kernel sequences ;
+USING: parser system kernel sequences ;
 IN: bootstrap.ppc
 
-: c-area-size ( -- n ) 14 bootstrap-cells ;
-: lr-save ( -- n ) 2 bootstrap-cells ;
+: reserved-size ( -- n ) 24 ;
+: lr-save ( -- n ) 8 ;
 
 << "vocab:cpu/ppc/bootstrap.factor" parse-file suffix! >>
 call
index d641ed7039dd35b420b798b7c36dbcd3e1f517a6..48423279737d89141775c1344c9950b1856acd01 100644 (file)
@@ -83,8 +83,8 @@ HOOK: reserved-area-size os ( -- n )
 ! The start of the stack frame contains the size of this frame
 ! as well as the currently executing XT
 : factor-area-size ( -- n ) 2 cells ; foldable
-: next-save ( n -- i ) cell - ;
-: xt-save ( n -- i ) 2 cells - ;
+: next-save ( n -- i ) cell - ; foldable
+: xt-save ( n -- i ) 2 cells - ; foldable
 
 ! Next, we have the spill area as well as the FFI parameter area.
 ! It is safe for them to overlap, since basic blocks with FFI calls
@@ -126,7 +126,7 @@ M: ppc stack-frame-size ( stack-frame -- i )
 M: ppc %call ( word -- ) 0 BL rc-relative-ppc-3 rel-word-pic ;
 
 M: ppc %jump ( word -- )
-    0 6 LOAD32 8 rc-absolute-ppc-2/2 rel-here
+    0 6 LOAD32 4 rc-absolute-ppc-2/2 rel-here
     0 B rc-relative-ppc-3 rel-word-pic-tail ;
 
 M: ppc %jump-label ( label -- ) B ;
@@ -134,7 +134,7 @@ M: ppc %return ( -- ) BLR ;
 
 M:: ppc %dispatch ( src temp -- )
     0 temp LOAD32
-    4 cells rc-absolute-ppc-2/2 rel-here
+    3 cells rc-absolute-ppc-2/2 rel-here
     temp temp src LWZX
     temp MTCTR
     BCTR ;
@@ -564,14 +564,16 @@ M:: ppc %compare-float-unordered-branch ( label src1 src2 cc -- )
         { stack-params [ [ 0 1 ] dip LWZ [ 0 1 ] dip param@ STW ] }
     } case ;
 
-: next-param@ ( n -- x ) param@ stack-frame get total-size>> + ;
+: next-param@ ( n -- reg x )
+    2 1 stack-frame get total-size>> LWZ
+    [ 2 ] dip param@ ;
 
 : store-to-frame ( src n rep -- )
     {
         { int-rep [ [ 1 ] dip STW ] }
         { float-rep [ [ 1 ] dip STFS ] }
         { double-rep [ [ 1 ] dip STFD ] }
-        { stack-params [ [ [ 0 ] dip next-param@ LWZ 0 1 ] dip STW ] }
+        { stack-params [ [ [ 0 ] dip next-param@ LWZ 0 1 ] dip STW ] }
     } case ;
 
 M: ppc %spill ( src rep dst -- )
@@ -679,10 +681,15 @@ M: ppc %box-large-struct ( n c-type -- )
     ! Call the function
     "from_value_struct" f %alien-invoke ;
 
+M:: ppc %restore-context ( temp1 temp2 -- )
+    temp1 "ctx" %load-vm-field-addr
+    temp1 temp1 0 LWZ
+    temp2 1 stack-frame get total-size>> ADDI
+    temp2 temp1 "callstack-bottom" context-field-offset STW
+    ds-reg temp1 8 LWZ
+    rs-reg temp1 12 LWZ ;
+
 M:: ppc %save-context ( temp1 temp2 -- )
-    #! Save Factor stack pointers in case the C code calls a
-    #! callback which does a GC, which must reliably trace
-    #! all roots.
     temp1 "ctx" %load-vm-field-addr
     temp1 temp1 0 LWZ
     1 temp1 0 STW
@@ -693,13 +700,18 @@ M: ppc %alien-invoke ( symbol dll -- )
     [ 11 ] 2dip %alien-global 11 MTLR BLRL ;
 
 M: ppc %alien-callback ( quot -- )
+    3 4 %restore-context
     3 swap %load-reference
-    4 %load-vm-addr
-    "c_to_factor" f %alien-invoke ;
+    4 3 quot-xt-offset LWZ
+    4 MTLR
+    BLRL
+    3 4 %save-context ;
 
 M: ppc %prepare-alien-indirect ( -- )
-    3 %load-vm-addr
-    "from_alien" f %alien-invoke
+    3 ds-reg 0 LWZ
+    ds-reg ds-reg 4 SUBI
+    4 %load-vm-addr
+    "pinned_alien_offset" f %alien-invoke
     16 3 MR ;
 
 M: ppc %alien-indirect ( -- )
@@ -753,9 +765,7 @@ M: ppc %box-small-struct ( c-type -- )
     3 3 0 LWZ ;
 
 M: ppc %nest-stacks ( -- )
-    ! Save current frame. See comment in vm/contexts.hpp
-    3 1 stack-frame get total-size>> 2 cells - ADDI
-    4 %load-vm-addr
+    3 %load-vm-addr
     "nest_stacks" f %alien-invoke ;
 
 M: ppc %unnest-stacks ( -- )
@@ -763,7 +773,6 @@ M: ppc %unnest-stacks ( -- )
     "unnest_stacks" f %alien-invoke ;
 
 M: ppc %unbox-small-struct ( size -- )
-    #! Alien must be in EAX.
     heap-size cell align cell /i {
         { 1 [ %unbox-struct-1 ] }
         { 2 [ %unbox-struct-2 ] }
diff --git a/basis/cpu/x86/32/32-tests.factor b/basis/cpu/x86/32/32-tests.factor
new file mode 100644 (file)
index 0000000..bc07e3a
--- /dev/null
@@ -0,0 +1,7 @@
+IN: cpu.x86.32.tests
+USING: alien alien.c-types tools.test cpu.x86.assembler
+cpu.x86.assembler.operands ;
+
+: assembly-test-1 ( -- x ) int { } "cdecl" [ EAX 3 MOV ] alien-assembly ;
+
+[ 3 ] [ assembly-test-1 ] unit-test
index 8b44b6580973ad491287ac36f15be47f85424023..0f98170d66659634834a37213cfd9b284fb92c81 100644 (file)
@@ -8,7 +8,8 @@ compiler.codegen compiler.codegen.fixup
 compiler.cfg.instructions compiler.cfg.builder
 compiler.cfg.intrinsics compiler.cfg.stack-frame
 cpu.x86.assembler cpu.x86.assembler.operands cpu.x86
-cpu.architecture ;
+cpu.architecture vm ;
+FROM: layouts => cell ;
 IN: cpu.x86.32
 
 M: x86.32 machine-registers
@@ -23,6 +24,12 @@ M: x86.32 stack-reg ESP ;
 M: x86.32 frame-reg EBP ;
 M: x86.32 temp-reg ECX ;
 
+M: x86.32 %mov-vm-ptr ( reg -- )
+    0 MOV 0 rc-absolute-cell rel-vm ;
+
+M: x86.32 %vm-field-ptr ( dst field -- )
+    [ 0 MOV ] dip vm-field-offset rc-absolute-cell rel-vm ;
+
 : local@ ( n -- op )
     stack-frame get extra-stack-space dup 16 assert= + stack@ ;
 
@@ -235,9 +242,8 @@ M: x86.32 %alien-indirect ( -- )
     EBP CALL ;
 
 M: x86.32 %alien-callback ( quot -- )
-    EAX EDX %load-context
+    EAX EDX %restore-context
     EAX swap %load-reference
-    EDX %mov-vm-ptr
     EAX quot-xt-offset [+] CALL
     EAX EDX %save-context ;
 
index 580db119465c480d7ba90d646d40724a008173e5..bcab5a54ee4b93c0f52e2589d80b09d01dc301fa 100644 (file)
@@ -1,4 +1,4 @@
-! Copyright (C) 2007, 2009 Slava Pestov.
+! Copyright (C) 2007, 2010 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
 USING: bootstrap.image.private kernel kernel.private namespaces
 system cpu.x86.assembler cpu.x86.assembler.operands layouts
@@ -19,6 +19,8 @@ IN: bootstrap.x86
 : safe-reg ( -- reg ) EAX ;
 : stack-reg ( -- reg ) ESP ;
 : frame-reg ( -- reg ) EBP ;
+: vm-reg ( -- reg ) ECX ;
+: ctx-reg ( -- reg ) EBP ;
 : nv-regs ( -- seq ) { ESI EDI EBX } ;
 : ds-reg ( -- reg ) ESI ;
 : rs-reg ( -- reg ) EDI ;
@@ -35,49 +37,122 @@ IN: bootstrap.x86
 ] jit-prolog jit-define
 
 : jit-load-vm ( -- )
-    EBP 0 MOV 0 rc-absolute-cell jit-vm ;
+    vm-reg 0 MOV 0 rc-absolute-cell jit-vm ;
+
+: jit-load-context ( -- )
+    ! VM pointer must be in vm-reg already
+    ctx-reg vm-reg vm-context-offset [+] MOV ;
 
 : jit-save-context ( -- )
-    ! VM pointer must be in EBP already
-    ECX EBP [] MOV
-    ! save ctx->callstack_top
-    EAX ESP -4 [+] LEA
-    ECX [] EAX MOV
-    ! save ctx->datastack
-    ECX 8 [+] ds-reg MOV
-    ! save ctx->retainstack
-    ECX 12 [+] rs-reg MOV ;
+    EDX RSP -4 [+] LEA
+    ctx-reg context-callstack-top-offset [+] EDX MOV
+    ctx-reg context-datastack-offset [+] ds-reg MOV
+    ctx-reg context-retainstack-offset [+] rs-reg MOV ;
 
 : jit-restore-context ( -- )
-    ! VM pointer must be in EBP already
-    ECX EBP [] MOV
-    ! restore ctx->datastack
-    ds-reg ECX 8 [+] MOV
-    ! restore ctx->retainstack
-    rs-reg ECX 12 [+] MOV ;
+    ds-reg ctx-reg context-datastack-offset [+] MOV
+    rs-reg ctx-reg context-retainstack-offset [+] MOV ;
 
 [
     jit-load-vm
-    ! save ds, rs registers
+    jit-load-context
     jit-save-context
     ! call the primitive
-    ESP [] EBP MOV
+    ESP [] vm-reg MOV
     0 CALL rc-relative rt-primitive jit-rel
     ! restore ds, rs registers
     jit-restore-context
 ] jit-primitive jit-define
 
 [
-    ! load from stack
+    ! Load quotation
+    EAX EBP 8 [+] MOV
+    ! save ctx->callstack_bottom, load ds, rs registers
+    jit-load-vm
+    jit-load-context
+    jit-restore-context
+    EDX stack-reg stack-frame-size 4 - [+] LEA
+    ctx-reg context-callstack-bottom-offset [+] EDX MOV
+    ! call the quotation
+    EAX quot-xt-offset [+] CALL
+    ! save ds, rs registers
+    jit-save-context
+] \ c-to-factor define-sub-primitive
+
+[
     EAX ds-reg [] MOV
-    ! pop stack
     ds-reg bootstrap-cell SUB
-    ! load VM pointer
-    EDX 0 MOV 0 rc-absolute-cell jit-vm
 ]
 [ EAX quot-xt-offset [+] CALL ]
 [ EAX quot-xt-offset [+] JMP ]
-\ (call) define-sub-primitive*
+\ (call) define-combinator-primitive
+
+[
+    ! Clear x87 stack, but preserve rounding mode and exception flags
+    ESP 2 SUB
+    ESP [] FNSTCW
+    FNINIT
+    ESP [] FLDCW
+    ESP 2 ADD
+
+    ! Load arguments
+    EAX ESP stack-frame-size [+] MOV
+    EDX ESP stack-frame-size 4 + [+] MOV
+
+    ! Unwind stack frames
+    ESP EDX MOV
+
+    ! Load ds and rs registers
+    jit-load-vm
+    jit-load-context
+    jit-restore-context
+
+    ! Call quotation
+    EAX quot-xt-offset [+] JMP
+] \ unwind-native-frames define-sub-primitive
+
+[
+    ! Load callstack object
+    EBX ds-reg [] MOV
+    ds-reg bootstrap-cell SUB
+    ! Get ctx->callstack_bottom
+    jit-load-vm
+    jit-load-context
+    EAX ctx-reg context-callstack-bottom-offset [+] MOV
+    ! Get top of callstack object -- 'src' for memcpy
+    EBP EBX callstack-top-offset [+] LEA
+    ! Get callstack length, in bytes --- 'len' for memcpy
+    EDX EBX callstack-length-offset [+] MOV
+    EDX tag-bits get SHR
+    ! Compute new stack pointer -- 'dst' for memcpy
+    EAX EDX SUB
+    ! Install new stack pointer
+    ESP EAX MOV
+    ! Call memcpy
+    EDX PUSH
+    EBP PUSH
+    EAX PUSH
+    0 CALL "factor_memcpy" f rc-relative jit-dlsym
+    ESP 12 ADD
+    ! Return with new callstack
+    0 RET
+] \ set-callstack define-sub-primitive
+
+[
+    jit-load-vm
+    jit-load-context
+    jit-save-context
+
+    ! Store arguments
+    ESP [] EAX MOV
+    ESP 4 [+] vm-reg MOV
+
+    ! Call VM
+    0 CALL "lazy_jit_compile" f rc-relative jit-dlsym
+]
+[ EAX quot-xt-offset [+] CALL ]
+[ EAX quot-xt-offset [+] JMP ]
+\ lazy-jit-compile define-combinator-primitive
 
 ! Inline cache miss entry points
 : jit-load-return-address ( -- )
@@ -87,8 +162,9 @@ IN: bootstrap.x86
 ! frame, and the stack. The frame setup takes this into account.
 : jit-inline-cache-miss ( -- )
     jit-load-vm
+    jit-load-context
     jit-save-context
-    ESP 4 [+] EBP MOV
+    ESP 4 [+] vm-reg MOV
     ESP [] EBX MOV
     0 CALL "inline_cache_miss" f rc-relative jit-dlsym
     jit-restore-context ;
@@ -96,28 +172,29 @@ IN: bootstrap.x86
 [ jit-load-return-address jit-inline-cache-miss ]
 [ EAX CALL ]
 [ EAX JMP ]
-\ inline-cache-miss define-sub-primitive*
+\ inline-cache-miss define-combinator-primitive
 
 [ jit-inline-cache-miss ]
 [ EAX CALL ]
 [ EAX JMP ]
-\ inline-cache-miss-tail define-sub-primitive*
+\ inline-cache-miss-tail define-combinator-primitive
 
 ! Overflowing fixnum arithmetic
 : jit-overflow ( insn func -- )
     ds-reg 4 SUB
     jit-load-vm
+    jit-load-context
     jit-save-context
     EAX ds-reg [] MOV
     EDX ds-reg 4 [+] MOV
-    ECX EAX MOV
-    [ [ ECX EDX ] dip call( dst src -- ) ] dip
-    ds-reg [] ECX MOV
+    EBX EAX MOV
+    [ [ EBX EDX ] dip call( dst src -- ) ] dip
+    ds-reg [] EBX MOV
     [ JNO ]
     [
         ESP [] EAX MOV
         ESP 4 [+] EDX MOV
-        ESP 8 [+] EBP MOV
+        ESP 8 [+] vm-reg MOV
         [ 0 CALL ] dip f rc-relative jit-dlsym
     ]
     jit-conditional ;
@@ -129,19 +206,20 @@ IN: bootstrap.x86
 [
     ds-reg 4 SUB
     jit-load-vm
+    jit-load-context
     jit-save-context
-    ECX ds-reg [] MOV
-    EAX ECX MOV
-    EBX ds-reg 4 [+] MOV
-    EBX tag-bits get SAR
-    EBX IMUL
+    EBX ds-reg [] MOV
+    EAX EBX MOV
+    EBP ds-reg 4 [+] MOV
+    EBP tag-bits get SAR
+    EBP IMUL
     ds-reg [] EAX MOV
     [ JNO ]
     [
-        ECX tag-bits get SAR
-        ESP [] ECX MOV
-        ESP 4 [+] EBX MOV
-        ESP 8 [+] EBP MOV
+        EBX tag-bits get SAR
+        ESP [] EBX MOV
+        ESP 4 [+] EBP MOV
+        ESP 8 [+] vm-reg MOV
         0 CALL "overflow_fixnum_multiply" f rc-relative jit-dlsym
     ]
     jit-conditional
diff --git a/basis/cpu/x86/64/64-tests.factor b/basis/cpu/x86/64/64-tests.factor
new file mode 100644 (file)
index 0000000..6d171af
--- /dev/null
@@ -0,0 +1,15 @@
+USING: alien alien.c-types cpu.architecture cpu.x86.64
+cpu.x86.assembler cpu.x86.assembler.operands tools.test ;
+IN: cpu.x86.64.tests
+
+: assembly-test-1 ( -- x ) int { } "cdecl" [ RAX 3 MOV ] alien-assembly ;
+
+[ 3 ] [ assembly-test-1 ] unit-test
+
+: assembly-test-2 ( a b -- x )
+    int { int int } "cdecl" [
+        param-reg-0 param-reg-1 ADD
+        int-regs return-reg param-reg-0 MOV
+    ] alien-assembly ;
+
+[ 23 ] [ 17 6 assembly-test-2 ] unit-test
index 5fc6ae8c169aa64238f68a8bf77109eb27f7f690..676c96ce50787e2b0bfd6dc111e811f2bce5662c 100644 (file)
@@ -7,7 +7,8 @@ compiler.codegen compiler.codegen.fixup
 compiler.cfg.instructions compiler.cfg.builder
 compiler.cfg.intrinsics compiler.cfg.stack-frame
 cpu.x86.assembler cpu.x86.assembler.operands cpu.x86
-cpu.architecture ;
+cpu.architecture vm ;
+FROM: layouts => cell cells ;
 IN: cpu.x86.64
 
 : param-reg-0 ( -- reg ) 0 int-regs param-reg ; inline
@@ -29,13 +30,21 @@ M: x86.64 extra-stack-space drop 0 ;
 
 M: x86.64 machine-registers
     {
-        { int-regs { RAX RCX RDX RBX RBP RSI RDI R8 R9 R10 R11 R12 R13 } }
+        { int-regs { RAX RCX RDX RBX RBP RSI RDI R8 R9 R10 R11 R12 } }
         { float-regs {
             XMM0 XMM1 XMM2 XMM3 XMM4 XMM5 XMM6 XMM7
             XMM8 XMM9 XMM10 XMM11 XMM12 XMM13 XMM14 XMM15
         } }
     } ;
 
+: vm-reg ( -- reg ) R13 ; inline
+
+M: x86.64 %mov-vm-ptr ( reg -- )
+    vm-reg MOV ;
+
+M: x86.64 %vm-field-ptr ( dst field -- )
+    [ vm-reg ] dip vm-field-offset [+] LEA ;
+
 : param@ ( n -- op ) reserved-stack-space + stack@ ;
 
 M: x86.64 %prologue ( n -- )
@@ -223,9 +232,8 @@ M: x86.64 %alien-indirect ( -- )
     RBP CALL ;
 
 M: x86.64 %alien-callback ( quot -- )
-    param-reg-0 param-reg-1 %load-context
+    param-reg-0 param-reg-1 %restore-context
     param-reg-0 swap %load-reference
-    param-reg-1 %mov-vm-ptr
     param-reg-0 quot-xt-offset [+] CALL
     param-reg-0 param-reg-1 %save-context ;
 
index a1bdcbd1ff9636f4c3ebeca3ee937171fee404fd..74943a94bb99fe09b899e60a12220a7113d05528 100644 (file)
@@ -1,4 +1,4 @@
-! Copyright (C) 2007, 2009 Slava Pestov.
+! Copyright (C) 2007, 2010 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
 USING: bootstrap.image.private kernel kernel.private namespaces
 system layouts vocabs parser compiler.constants math
@@ -15,9 +15,12 @@ IN: bootstrap.x86
 : temp1 ( -- reg ) RSI ;
 : temp2 ( -- reg ) RDX ;
 : temp3 ( -- reg ) RBX ;
+: return-reg ( -- reg ) RAX ;
 : safe-reg ( -- reg ) RAX ;
 : stack-reg ( -- reg ) RSP ;
 : frame-reg ( -- reg ) RBP ;
+: ctx-reg ( -- reg ) R12 ;
+: vm-reg ( -- reg ) R13 ;
 : ds-reg ( -- reg ) R14 ;
 : rs-reg ( -- reg ) R15 ;
 : fixnum>slot@ ( -- ) temp0 1 SAR ;
@@ -25,60 +28,114 @@ IN: bootstrap.x86
 
 [
     ! load XT
-    RDI 0 MOV rc-absolute-cell rt-this jit-rel
+    safe-reg 0 MOV rc-absolute-cell rt-this jit-rel
     ! save stack frame size
     stack-frame-size PUSH
     ! push XT
-    RDI PUSH
+    safe-reg PUSH
     ! alignment
     RSP stack-frame-size 3 bootstrap-cells - SUB
 ] jit-prolog jit-define
 
-: jit-load-vm ( -- )
-    RBP 0 MOV 0 rc-absolute-cell jit-vm ;
+: jit-load-context ( -- )
+    ctx-reg vm-reg vm-context-offset [+] MOV ;
 
 : jit-save-context ( -- )
-    ! VM pointer must be in RBP already
-    RCX RBP [] MOV
-    ! save ctx->callstack_top
-    RAX RSP -8 [+] LEA
-    RCX [] RAX MOV
-    ! save ctx->datastack
-    RCX 16 [+] ds-reg MOV
-    ! save ctx->retainstack
-    RCX 24 [+] rs-reg MOV ;
+    jit-load-context
+    safe-reg RSP -8 [+] LEA
+    ctx-reg context-callstack-top-offset [+] safe-reg MOV
+    ctx-reg context-datastack-offset [+] ds-reg MOV
+    ctx-reg context-retainstack-offset [+] rs-reg MOV ;
 
 : jit-restore-context ( -- )
-    ! VM pointer must be in EBP already
-    RCX RBP [] MOV
-    ! restore ctx->datastack
-    ds-reg RCX 16 [+] MOV
-    ! restore ctx->retainstack
-    rs-reg RCX 24 [+] MOV ;
+    jit-load-context
+    ds-reg ctx-reg context-datastack-offset [+] MOV
+    rs-reg ctx-reg context-retainstack-offset [+] MOV ;
 
 [
-    jit-load-vm
-    ! save ds, rs registers
     jit-save-context
     ! call the primitive
-    arg1 RBP MOV
+    arg1 vm-reg MOV
     RAX 0 MOV rc-absolute-cell rt-primitive jit-rel
     RAX CALL
-    ! restore ds, rs registers
     jit-restore-context
 ] jit-primitive jit-define
 
 [
-    ! load from stack
+    jit-restore-context
+    ! save ctx->callstack_bottom
+    safe-reg stack-reg stack-frame-size 8 - [+] LEA
+    ctx-reg context-callstack-bottom-offset [+] safe-reg MOV
+    ! call the quotation
+    arg1 quot-xt-offset [+] CALL
+    jit-save-context
+] \ c-to-factor define-sub-primitive
+
+[
     arg1 ds-reg [] MOV
-    ! pop stack
     ds-reg bootstrap-cell SUB
-    ! load VM pointer
-    arg2 0 MOV 0 rc-absolute-cell jit-vm
 ]
 [ arg1 quot-xt-offset [+] CALL ]
 [ arg1 quot-xt-offset [+] JMP ]
-\ (call) define-sub-primitive*
+\ (call) define-combinator-primitive
+
+[
+    ! Clear x87 stack, but preserve rounding mode and exception flags
+    RSP 2 SUB
+    RSP [] FNSTCW
+    FNINIT
+    RSP [] FLDCW
+
+    ! Unwind stack frames
+    RSP arg2 MOV
+
+    ! Load VM pointer into vm-reg, since we're entering from
+    ! C code
+    vm-reg 0 MOV 0 rc-absolute-cell jit-vm
+
+    ! Load ds and rs registers
+    jit-restore-context
+
+    ! Call quotation
+    arg1 quot-xt-offset [+] JMP
+] \ unwind-native-frames define-sub-primitive
+
+[
+    ! Load callstack object
+    arg4 ds-reg [] MOV
+    ds-reg bootstrap-cell SUB
+    ! Get ctx->callstack_bottom
+    jit-load-context
+    arg1 ctx-reg context-callstack-bottom-offset [+] MOV
+    ! Get top of callstack object -- 'src' for memcpy
+    arg2 arg4 callstack-top-offset [+] LEA
+    ! Get callstack length, in bytes --- 'len' for memcpy
+    arg3 arg4 callstack-length-offset [+] MOV
+    arg3 tag-bits get SHR
+    ! Compute new stack pointer -- 'dst' for memcpy
+    arg1 arg3 SUB
+    ! Install new stack pointer
+    RSP arg1 MOV
+    ! Call memcpy; arguments are now in the correct registers
+    ! Create register shadow area for Win64
+    RSP 32 SUB
+    safe-reg 0 MOV "factor_memcpy" f rc-absolute-cell jit-dlsym
+    safe-reg CALL
+    ! Tear down register shadow area
+    RSP 32 ADD
+    ! Return with new callstack
+    0 RET
+] \ set-callstack define-sub-primitive
+
+[
+    jit-save-context
+    arg2 vm-reg MOV
+    safe-reg 0 MOV "lazy_jit_compile" f rc-absolute-cell jit-dlsym
+    safe-reg CALL
+]
+[ return-reg quot-xt-offset [+] CALL ]
+[ return-reg quot-xt-offset [+] JMP ]
+\ lazy-jit-compile define-combinator-primitive
 
 ! Inline cache miss entry points
 : jit-load-return-address ( -- )
@@ -87,10 +144,9 @@ IN: bootstrap.x86
 ! These are always in tail position with an existing stack
 ! frame, and the stack. The frame setup takes this into account.
 : jit-inline-cache-miss ( -- )
-    jit-load-vm
     jit-save-context
     arg1 RBX MOV
-    arg2 RBP MOV
+    arg2 vm-reg MOV
     RAX 0 MOV "inline_cache_miss" f rc-absolute-cell jit-dlsym
     RAX CALL
     jit-restore-context ;
@@ -98,17 +154,16 @@ IN: bootstrap.x86
 [ jit-load-return-address jit-inline-cache-miss ]
 [ RAX CALL ]
 [ RAX JMP ]
-\ inline-cache-miss define-sub-primitive*
+\ inline-cache-miss define-combinator-primitive
 
 [ jit-inline-cache-miss ]
 [ RAX CALL ]
 [ RAX JMP ]
-\ inline-cache-miss-tail define-sub-primitive*
+\ inline-cache-miss-tail define-combinator-primitive
 
 ! Overflowing fixnum arithmetic
 : jit-overflow ( insn func -- )
     ds-reg 8 SUB
-    jit-load-vm
     jit-save-context
     arg1 ds-reg [] MOV
     arg2 ds-reg 8 [+] MOV
@@ -117,7 +172,7 @@ IN: bootstrap.x86
     ds-reg [] arg3 MOV
     [ JNO ]
     [
-        arg3 RBP MOV
+        arg3 vm-reg MOV
         RAX 0 MOV f rc-absolute-cell jit-dlsym
         RAX CALL
     ]
@@ -129,7 +184,6 @@ IN: bootstrap.x86
 
 [
     ds-reg 8 SUB
-    jit-load-vm
     jit-save-context
     RCX ds-reg [] MOV
     RBX ds-reg 8 [+] MOV
@@ -142,7 +196,7 @@ IN: bootstrap.x86
         arg1 RCX MOV
         arg1 tag-bits get SAR
         arg2 RBX MOV
-        arg3 RBP MOV
+        arg3 vm-reg MOV
         RAX 0 MOV "overflow_fixnum_multiply" f rc-absolute-cell jit-dlsym
         RAX CALL
     ]
index 57738ce4bad7553057950781670998b669327e6c..b075b121a5c7c130f285af29ac3c3853c8ee1f31 100644 (file)
@@ -375,6 +375,7 @@ PRIVATE>
 : NOP ( -- ) HEX: 90 , ;
 : PAUSE ( -- ) HEX: f3 , HEX: 90 , ;
 
+: RDTSC ( -- ) HEX: 0f , HEX: 31 , ;
 : RDPMC ( -- ) HEX: 0f , HEX: 33 , ;
 
 ! x87 Floating Point Unit
@@ -385,6 +386,13 @@ PRIVATE>
 : FLDS ( operand -- ) { BIN: 000 f HEX: d9 } 1-operand ;
 : FLDL ( operand -- ) { BIN: 000 f HEX: dd } 1-operand ;
 
+: FNSTCW ( operand -- ) { BIN: 111 f HEX: d9 } 1-operand ;
+: FNSTSW ( operand -- ) { BIN: 111 f HEX: dd } 1-operand ;
+: FLDCW ( operand -- ) { BIN: 101 f HEX: d9 } 1-operand ;
+
+: FNCLEX ( -- ) HEX: db , HEX: e2 , ;
+: FNINIT ( -- ) HEX: db , HEX: e3 , ;
+
 ! SSE multimedia instructions
 
 <PRIVATE
index f0e869fe5b9c7a168a09f645117f11fa13f5fd55..96d21972d50ebb7d717a3d36b0761d71a5b087fb 100644 (file)
@@ -1,4 +1,4 @@
-! Copyright (C) 2007, 2009 Slava Pestov.
+! Copyright (C) 2007, 2010 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
 USING: bootstrap.image.private compiler.constants
 compiler.units cpu.x86.assembler cpu.x86.assembler.operands
@@ -30,6 +30,9 @@ big-endian off
     ! hurt on other platforms
     stack-reg 32 SUB
 
+    ! Load VM into vm-reg
+    vm-reg 0 MOV rc-absolute-cell rt-vm jit-rel
+
     ! Call into Factor code
     safe-reg 0 MOV rc-absolute-cell rt-xt jit-rel
     safe-reg CALL
@@ -169,7 +172,7 @@ big-endian off
 ]
 [ temp0 word-xt-offset [+] CALL ]
 [ temp0 word-xt-offset [+] JMP ]
-\ (execute) define-sub-primitive*
+\ (execute) define-combinator-primitive
 
 [
     temp0 ds-reg [] MOV
index 38364805eb90215a362676f461ff34edd8384313..30b2ce3b57accf63cd05a6aaa80bbcd16f89e275 100644 (file)
@@ -1,21 +1,78 @@
-! Copyright (C) 2009 Slava Pestov.
+! Copyright (C) 2009, 2010 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: system kernel memoize math math.order math.parser
-namespaces alien.c-types alien.syntax combinators locals init io
-compiler compiler.units accessors ;
+USING: accessors alien alien.c-types combinators compiler
+compiler.codegen.fixup compiler.units cpu.architecture
+cpu.x86.assembler cpu.x86.assembler.operands init io kernel
+locals math math.order math.parser memoize namespaces system ;
 IN: cpu.x86.features
 
 <PRIVATE
 
-FUNCTION: int sse_version ( ) ;
+: (sse-version) ( -- n )
+    int { } "cdecl" [
+        "sse-42" define-label
+        "sse-41" define-label
+        "ssse-3" define-label
+        "sse-3" define-label
+        "sse-2" define-label
+        "sse-1" define-label
+        "end" define-label
 
-FUNCTION: longlong read_timestamp_counter ( ) ;
+        int-regs return-reg 1 MOV
+
+        CPUID
+
+        ECX HEX: 100000 TEST
+        "sse-42" get JNE
+
+        ECX HEX: 80000 TEST
+        "sse-41" get JNE
+
+        ECX HEX: 200 TEST
+        "ssse-3" get JNE
+
+        ECX HEX: 1 TEST
+        "sse-3" get JNE
+
+        EDX HEX: 4000000 TEST
+        "sse-2" get JNE
+
+        EDX HEX: 2000000 TEST
+        "sse-1" get JNE
+
+        int-regs return-reg 0 MOV
+        "end" get JMP
+
+        "sse-42" resolve-label
+        int-regs return-reg 42 MOV
+        "end" get JMP
+
+        "sse-41" resolve-label
+        int-regs return-reg 41 MOV
+        "end" get JMP
+
+        "ssse-3" resolve-label
+        int-regs return-reg 33 MOV
+        "end" get JMP
+
+        "sse-3" resolve-label
+        int-regs return-reg 30 MOV
+        "end" get JMP
+
+        "sse-2" resolve-label
+        int-regs return-reg 20 MOV
+        "end" get JMP
+
+        "sse-1" resolve-label
+        int-regs return-reg 10 MOV
+
+        "end" resolve-label
+    ] alien-assembly ;
 
 PRIVATE>
 
 MEMO: sse-version ( -- n )
-    sse_version
-    "sse-version" get string>number [ min ] when* ;
+    (sse-version) "sse-version" get string>number [ min ] when* ;
 
 [ \ sse-version reset-memoized ] "cpu.x86.features" add-startup-hook
 
@@ -39,7 +96,18 @@ MEMO: sse-version ( -- n )
 
 HOOK: instruction-count cpu ( -- n )
 
-M: x86 instruction-count read_timestamp_counter ;
+M: x86.32 instruction-count
+    longlong { } "cdecl" [
+        RDTSC
+    ] alien-assembly ;
+
+M: x86.64 instruction-count
+    longlong { } "cdecl" [
+        RAX 0 MOV
+        RDTSC
+        RDX 32 SHL
+        RAX RDX OR
+    ] alien-assembly ;
 
 : count-instructions ( quot -- n )
-    instruction-count [ call ] dip instruction-count swap - ; inline
+    instruction-count [ call instruction-count ] dip - ; inline
index 69a0f39945edc538ae3eeecfb9ee9acb308f622b..f2751b1be21b23c51b488aa0308d901549d0b91b 100644 (file)
@@ -1,4 +1,4 @@
-! Copyright (C) 2005, 2009 Slava Pestov.
+! Copyright (C) 2005, 2010 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
 USING: accessors assocs alien alien.c-types arrays strings
 cpu.x86.assembler cpu.x86.assembler.private cpu.x86.assembler.operands
@@ -419,11 +419,7 @@ M: x86 %shl int-rep two-operand [ SHL ] emit-shift ;
 M: x86 %shr int-rep two-operand [ SHR ] emit-shift ;
 M: x86 %sar int-rep two-operand [ SAR ] emit-shift ;
 
-: %mov-vm-ptr ( reg -- )
-    0 MOV 0 rc-absolute-cell rel-vm ;
-
-M: x86 %vm-field-ptr ( dst field -- )
-    [ 0 MOV ] dip vm-field-offset rc-absolute-cell rel-vm ;
+HOOK: %mov-vm-ptr cpu ( reg -- )
 
 : load-allot-ptr ( nursery-ptr allot-ptr -- )
     [ drop "nursery" %vm-field-ptr ] [ swap [] MOV ] 2bi ;
@@ -1410,18 +1406,15 @@ M:: x86 %reload ( dst rep src -- ) dst src rep %copy ;
 
 M: x86 %loop-entry 16 code-alignment [ NOP ] times ;
 
-M:: x86 %load-context ( temp1 temp2 -- )
+M:: x86 %restore-context ( temp1 temp2 -- )
     #! Load Factor stack pointers on entry from C to Factor.
     #! Also save callstack bottom!
     temp1 "ctx" %vm-field-ptr
     temp1 temp1 [] MOV
-    ! callstack_bottom
     temp2 stack-reg stack-frame get total-size>> cell - [+] LEA
-    temp1 1 cells [+] temp2 MOV
-    ! datastack
-    ds-reg temp1 2 cells [+] MOV
-    ! retainstack
-    rs-reg temp1 3 cells [+] MOV ;
+    temp1 "callstack-bottom" context-field-offset [+] temp2 MOV
+    ds-reg temp1 "datastack" context-field-offset [+] MOV
+    rs-reg temp1 "retainstack" context-field-offset [+] MOV ;
 
 M:: x86 %save-context ( temp1 temp2 -- )
     #! Save Factor stack pointers in case the C code calls a
@@ -1429,13 +1422,10 @@ M:: x86 %save-context ( temp1 temp2 -- )
     #! all roots.
     temp1 "ctx" %vm-field-ptr
     temp1 temp1 [] MOV
-    ! callstack_top
     temp2 stack-reg cell neg [+] LEA
-    temp1 [] temp2 MOV
-    ! datastack
-    temp1 2 cells [+] ds-reg MOV
-    ! retainstack
-    temp1 3 cells [+] rs-reg MOV ;
+    temp1 "callstack-top" context-field-offset [+] temp2 MOV
+    temp1 "datastack" context-field-offset [+] ds-reg MOV
+    temp1 "retainstack" context-field-offset [+] rs-reg MOV ;
 
 M: x86 value-struct? drop t ;
 
@@ -1475,6 +1465,6 @@ enable-fixnum-log2
     ] when ;
 
 : check-sse ( -- )
-    [ { sse_version } compile ] with-optimizer
+    [ { (sse-version) } compile ] with-optimizer
     "Checking for multimedia extensions: " write sse-version
     [ sse-string write " detected" print ] [ enable-sse2 ] bi ;
index bd523b38e6d81a887ab9f3db2ce5e9653b50e0c3..f26729f8eae2a955293ce661752126281d87501c 100644 (file)
@@ -100,10 +100,10 @@ M: object execute-statement* ( statement type -- )
     t >>bound? drop ;
 
 : sql-row ( result-set -- seq )
-    dup #columns [ row-column ] with map ;
+    dup #columns [ row-column ] with { } map-integers ;
 
 : sql-row-typed ( result-set -- seq )
-    dup #columns [ row-column-typed ] with map ;
+    dup #columns [ row-column-typed ] with { } map-integers ;
 
 : query-each ( statement quot: ( statement -- ) -- )
     over more-rows? [
index e9aa01feb4bb9568486c4a9b37268c247664311d..3ff93f49c67f42f461159c6446fa7b6c91f36453 100644 (file)
@@ -34,7 +34,7 @@ SINGLETON: retryable
     ] 2map >>bind-params ;
     
 M: retryable execute-statement* ( statement type -- )
-    drop [ retries>> ] [
+    drop [ retries>> iota ] [
         [
             nip
             [ query-results dispose t ]
index 19140259bf1e4b913a4243f8b7abd81ab99b0254..d0ea6cbcf12eee933beefc083c1c12fa8664e67a 100644 (file)
@@ -67,7 +67,7 @@ test-2 "TEST2" {
             test-2 ensure-table
         ] with-db
     ] [
-        10 [
+        10 iota [
             drop
             10 [
                 dup [
@@ -85,7 +85,7 @@ test-2 "TEST2" {
         ] with-db
     ] [
         <db-pool> [
-            10 [
+            10 iota [
                 10 [
                     test-1-tuple insert-tuple yield
                 ] times
index 863dc522b2d694de12c3b3cc30ab095b24aa914b..7ef62bfb77eefcb955cbc304513d98c51db21dfc 100644 (file)
@@ -205,7 +205,7 @@ link-no-follow? off
     100 [
         drop random-markup
         [ convert-farkup drop t ] [ drop print f ] recover
-    ] all?
+    ] all-integers?
 ] unit-test
 
 [ "<p><a href=\"http://foo.com/~foo\">http://foo.com/~foo</a></p>" ] [ "[[http://foo.com/~foo]]" convert-farkup ] unit-test
index f33eb276a0e88f6320ff920865811e7321ac352e..b341c462be39afe739f41d64a4298a4204a8e794 100644 (file)
@@ -64,7 +64,7 @@ SYMBOLS: a b c d e f g h ;
 [ "hi" 3 ] [ "h" "i" 3 [ append ] funny-dip ] unit-test
 
 [ { 1 2 3 } ] [
-    3 1 '[ _ [ _ + ] map ] call
+    3 1 '[ _ iota [ _ + ] map ] call
 ] unit-test
 
 [ { 1 { 2 { 3 } } } ] [
index 546413447e6a28fc1b385ec1f43af84c12fccc11..0c35f157142419ed6b1e912c6fe23707a950d3b8 100644 (file)
@@ -64,7 +64,7 @@ IN: generalizations.tests
 { 3 5 } [ 2 nweave ] must-infer-as\r
 \r
 [ { 0 1 2 } { 3 5 4 } { 7 8 6 } ]\r
-[ 9 [ ] each { [ 3array ] [ swap 3array ] [ rot 3array ] } 3 nspread ] unit-test\r
+[ 9 [ ] each-integer { [ 3array ] [ swap 3array ] [ rot 3array ] } 3 nspread ] unit-test\r
 \r
 [ 1 2 3 4 1 2 3 ] [ 1 2 3 4 3 nover ] unit-test\r
 \r
index e1044b0feb0e5ef1bddff64fd1c97ab9b01dc820..2c2fee1d70e79233249c8803478f3652bcb2f97f 100644 (file)
@@ -52,7 +52,7 @@ HELP: <groups>
 { $examples
     { $example
         "USING: arrays kernel prettyprint sequences grouping ;"
-        "9 >array 3 <groups> reverse! concat >array ." "{ 6 7 8 3 4 5 0 1 2 }"
+        "9 iota >array 3 <groups> reverse! concat >array ." "{ 6 7 8 3 4 5 0 1 2 }"
     }
     { $example
         "USING: kernel prettyprint sequences grouping ;"
@@ -67,7 +67,7 @@ HELP: <sliced-groups>
 { $examples
     { $example
         "USING: arrays kernel prettyprint sequences grouping ;"
-        "9 >array 3 <sliced-groups>"
+        "9 iota >array 3 <sliced-groups>"
         "dup [ reverse! drop ] each concat >array ."
         "{ 2 1 0 5 4 3 8 7 6 }"
     }
index c1985c516f995cdee7c614985f4e9330a4b7c36e..703cf530805c06b44fbb6552847a12743c7d3d04 100644 (file)
@@ -31,7 +31,7 @@ IN: heaps.tests
     <min-heap> [ heap-push-all ] keep heap-pop-all ;
 
 : random-alist ( n -- alist )
-    [
+    iota [
         drop 32 random-bits dup number>string
     ] H{ } map>assoc ;
 
@@ -40,16 +40,16 @@ IN: heaps.tests
 
 14 [
     [ t ] swap [ 2^ test-heap-sort ] curry unit-test
-] each
+] each-integer
 
 : test-entry-indices ( n -- ? )
     random-alist
     <min-heap> [ heap-push-all ] keep
-    data>> dup length swap [ index>> ] map sequence= ;
+    data>> dup length iota swap [ index>> ] map sequence= ;
 
 14 [
     [ t ] swap [ 2^ test-entry-indices ] curry unit-test
-] each
+] each-integer
 
 : sort-entries ( entries -- entries' )
     [ key>> ] sort-with ;
@@ -66,4 +66,4 @@ IN: heaps.tests
 
 11 [
     [ t ] swap [ 2^ delete-test sequence= ] curry unit-test
-] each
+] each-integer
index 1ca5bf1bc54ff898a1fec4d11b8c5be848f463cc..e4bbb3459e53a3b6543573666bde13843b7b8046 100644 (file)
@@ -1,4 +1,4 @@
-! Copyright (C) 2008, 2009 Slava Pestov.
+! Copyright (C) 2008, 2010 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
 USING: accessors arrays assocs byte-arrays byte-vectors classes
 combinators definitions effects fry generic generic.single
@@ -24,7 +24,7 @@ M: object specializer-declaration class ;
     "specializer" word-prop ;
 
 : make-specializer ( specs -- quot )
-    dup length <reversed>
+    dup length iota <reversed>
     [ (picker) 2array ] 2map
     [ drop object eq? not ] assoc-filter
     [ [ t ] ] [
index e305c8477a18f63f2f3a80a0202d4a09018a48f7..9a67d43e7d90aa24d575225cb1f2a9a36a6828f0 100644 (file)
@@ -137,7 +137,7 @@ TUPLE: jpeg-color-info
     data>>
     binary
     [
-        read1 [0,b)
+        read1 iota
         [   drop
             read1 jpeg> color-info>> nth clone
             read1 16 /mod [ >>dc-huff-table ] [ >>ac-huff-table ] bi*
@@ -198,7 +198,7 @@ MEMO: yuv>bgr-matrix ( -- m )
     { 8 8 } coord-matrix [ { u v } [ wave ] 2map product ] map^2
     1 u v [ 0 = [ 2 sqrt / ] when ] bi@ 4 / m*n ;
 
-MEMO: dct-matrix ( -- m ) 64 [0,b) [ 8 /mod dct-vect flatten ] map ;
+MEMO: dct-matrix ( -- m ) 64 iota [ 8 /mod dct-vect flatten ] map ;
 
 : mb-dim ( component -- dim )  [ h>> ] [ v>> ] bi 2array ;
 
index 0817a59e7b20fad84fc764b67c66b03bfadccbcf..d4a9c4ab563a57b37ce0c12242d0b5b3f755ea5e 100644 (file)
@@ -120,7 +120,7 @@ ERROR: unimplemented-color-type image ;
     prev width tail-slice :> b
     curr :> a
     curr width tail-slice :> x
-    x length [0,b)
+    x length iota
     filter {
         { filter-none [ drop ] }
         { filter-sub [ [| n | n x nth n a nth + 256 wrap n x set-nth ] each ] }
index cd6754550d3a7a5d11d4dfcf273a131bc80bdb7e..b21eb50c62c8d9890a86c0c3106a6895b275760f 100644 (file)
@@ -6,7 +6,7 @@ math.ranges math.vectors sequences sequences.deep fry ;
 IN: images.processing\r
 \r
 : coord-matrix ( dim -- m )\r
-    [ [0,b) ] map first2 [ [ 2array ] with map ] curry map ;\r
+    [ iota ] map first2 [ [ 2array ] with map ] curry map ;\r
 \r
 : map^2 ( m quot -- m' ) '[ _ map ] map ; inline\r
 : each^2 ( m quot -- m' ) '[ _ each ] each ; inline\r
@@ -16,7 +16,7 @@ IN: images.processing
 : matrix>image ( m -- image )\r
     <image> over matrix-dim >>dim\r
     swap flip flatten\r
-    [ 128 * 128 + 0 max 255 min  >fixnum ] map\r
+    [ 128 * 128 + 0 255 clamp >fixnum ] map\r
     >byte-array >>bitmap L >>component-order ubyte-components >>component-type ;\r
 \r
 :: matrix-zoom ( m f -- m' )\r
@@ -30,7 +30,7 @@ IN: images.processing
 :: draw-grey ( value x,y image -- )\r
     x,y image image-offset 3 * { 0 1 2 }\r
     [\r
-        + value 128 + >fixnum 0 max 255 min swap image bitmap>> set-nth\r
+        + value 128 + >fixnum 0 255 clamp swap image bitmap>> set-nth\r
     ] with each ;\r
 \r
 :: draw-color ( value x,y color-id image -- )\r
index 82c2487f671b30bacb8af47767b6da887e2e7a7e..2aa7cd218e02b051ca1ac66b2612bbefe620b2d1 100644 (file)
@@ -1,4 +1,4 @@
-! Copyright (C) 2005, 2009 Slava Pestov.
+! Copyright (C) 2005, 2010 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
 USING: accessors arrays generic hashtables io kernel assocs math
 namespaces prettyprint prettyprint.custom prettyprint.sections
@@ -23,9 +23,7 @@ GENERIC: add-numbers ( alist -- table' )
 M: enum add-numbers ;
 
 M: assoc add-numbers
-    +number-rows+ get [
-        dup length [ prefix ] 2map
-    ] when ;
+    +number-rows+ get [ [ prefix ] map-index ] when ;
 
 TUPLE: slot-name name ;
 
index 4ecb1e12a8a133e52f4db1bcd845bbf154927f6b..d112e4e6ebd6e3b31374b0233c4ddfd3a4fa0fcd 100644 (file)
@@ -68,7 +68,7 @@ UNION: explicit-inverse normal-inverse math-inverse pop-inverse ;
 
 : enough? ( stack word -- ? )
     dup deferred? [ 2drop f ] [
-        [ [ length ] [ 1quotation infer in>> ] bi* >= ]
+        [ [ length ] [ 1quotation inputs ] bi* >= ]
         [ 3drop f ] recover
     ] if ;
 
@@ -273,10 +273,10 @@ DEFER: __
     ] recover ; inline
 
 : true-out ( quot effect -- quot' )
-    out>> '[ @ _ ndrop t ] ;
+    out>> length '[ @ _ ndrop t ] ;
 
 : false-recover ( effect -- quot )
-    in>> [ ndrop f ] curry [ recover-fail ] curry ;
+    in>> length [ ndrop f ] curry [ recover-fail ] curry ;
 
 : [matches?] ( quot -- undoes?-quot )
     [undo] dup infer [ true-out ] [ false-recover ] bi curry ;
index 17264267777486fc000ae91e6d7bd5daa0e7744b..7d4d7f1215f6fa89b43fd118c1e9d68faa238d6b 100644 (file)
@@ -18,7 +18,7 @@ VALUE: jis212
 "vocab:io/encodings/iso2022/212.txt" flat-file>biassoc to: jis212
 
 VALUE: ascii
-128 unique >biassoc to: ascii
+128 iota unique >biassoc to: ascii
 
 TUPLE: iso2022-state type ;
 
index ef7d778abe7ae439b2ce4c35e6a81bc66b92b15c..23de95f519c591a9c83147d45b6e88e811e2905b 100644 (file)
@@ -4,7 +4,7 @@ io.pathnames namespaces ;
 IN: io.files.links.unix.tests
 
 : make-test-links ( n path -- )
-    [ '[ [ 1 + ] keep [ number>string _ prepend ] bi@ make-link ] each ]
+    [ '[ [ 1 + ] keep [ number>string _ prepend ] bi@ make-link ] each-integer ]
     [ [ number>string ] dip prepend touch-file ] 2bi ; inline
 
 [ t ] [
index f167b1e99ba32f387a454e03f379fe662c71ddde..07f7b25140bdc192da95247e2ae6b589c81e75ae 100644 (file)
@@ -35,8 +35,8 @@ SYMBOL: unique-retries
 : random-name ( -- string )
     unique-length get [ random-ch ] "" replicate-as ;
 
-: retry ( quot: ( -- ? )  n -- )
-    swap [ drop ] prepose attempt-all ; inline
+: retry ( quot: ( -- ? ) n -- )
+    iota swap [ drop ] prepose attempt-all ; inline
 
 : (make-unique-file) ( path prefix suffix -- path )
     '[
index 0c2ed34f453b99958081ada4476fc5592c23d30e..2ee662c0ac5698fb2c65bcb80d4fa81cee53ee16 100644 (file)
@@ -3,4 +3,4 @@
 USING: lcs.diff2html lcs kernel tools.test strings sequences xml.writer ;
 IN: lcs.diff2html.tests
 
-[ ] [ "hello" "heyo" [ 1string ] { } map-as diff htmlize-diff xml>string drop ] unit-test
+[ ] [ "hello" "heyo" [ [ 1string ] { } map-as ] bi@ diff htmlize-diff xml>string drop ] unit-test
index ca9e48eb057623509324bba81db54a788ff0baeb..545610a0ea2a90c66bb7b521982fba57483f5811 100644 (file)
@@ -1,4 +1,4 @@
-! Copyright (C) 2008 Slava Pestov
+! Copyright (C) 2008, 2010 Slava Pestov
 ! See http://factorcode.org/license.txt for BSD license.
 USING: lcs xml.syntax xml.writer kernel strings ;
 FROM: accessors => item>> ;
index 38920f5764669daffbb2d6f07602de6dca37b27f..5861d90dc377492cff651147e6af2a8f65957aa8 100644 (file)
@@ -19,15 +19,15 @@ IN: lcs
     i 1 + j 1 + matrix nth set-nth ; inline\r
 \r
 : lcs-initialize ( |str1| |str2| -- matrix )\r
-    [ drop 0 <array> ] with map ;\r
+    iota [ drop 0 <array> ] with map ;\r
 \r
 : levenshtein-initialize ( |str1| |str2| -- matrix )\r
-    [ [ + ] curry map ] with map ;\r
+    [ iota ] bi@ [ [ + ] curry map ] with map ;\r
 \r
 :: run-lcs ( old new init step -- matrix )\r
     old length 1 + new length 1 + init call :> matrix\r
-    old length [| i |\r
-        new length\r
+    old length iota [| i |\r
+        new length iota\r
         [| j | i j matrix old new step loop-step ] each\r
     ] each matrix ; inline\r
 PRIVATE>\r
index 25f754e92af46ca874d2ed42f67f13d978cac1cf..3dab0c3cdb12a25a299b5aa0714356a178a44ca3 100644 (file)
@@ -49,7 +49,7 @@ M: wrapper expand-macros* wrapped>> literal ;
     stack get pop end
     [ [ expand-macros ] [ ] map-as '[ _ dip ] % ]
     [
-        length [ <reversed> ] keep
+        length iota [ <reversed> ] keep
         [ '[ _ ndrop _ nnip call ] [ ] like ] 2map , \ dispatch ,
     ] bi ;
 
index 10584f2004da48505c8061ff0b30cddc6bc1c218..ec3cd6ee76c9f96847106d463e918ded20e5dd24 100644 (file)
@@ -31,7 +31,7 @@ HELP: permutation
 { $notes "Permutations are 0-based and a bounds error will be thrown if " { $snippet "n" } " is larger than " { $snippet "seq length factorial 1 -" } "." }
 { $examples
     { $example "USING: math.combinatorics prettyprint ;"
-        "1 3 permutation ." "{ 0 2 1 }" }
+        "1 { 0 1 2 } permutation ." "{ 0 2 1 }" }
     { $example "USING: math.combinatorics prettyprint ;"
         "5 { \"apple\" \"banana\" \"orange\" } permutation ." "{ \"orange\" \"banana\" \"apple\" }" }
 } ;
@@ -41,7 +41,7 @@ HELP: all-permutations
 { $description "Outputs a sequence containing all permutations of " { $snippet "seq" } " in lexicographical order." }
 { $examples
     { $example "USING: math.combinatorics prettyprint ;"
-        "3 all-permutations ." "{ { 0 1 2 } { 0 2 1 } { 1 0 2 } { 1 2 0 } { 2 0 1 } { 2 1 0 } }" }
+        "{ 0 1 2 } all-permutations ." "{ { 0 1 2 } { 0 2 1 } { 1 0 2 } { 1 2 0 } { 2 0 1 } { 2 1 0 } }" }
 } ;
 
 HELP: each-permutation
index ca6ec9cb53c02d0d5722d8bf70eae70bfd3cd4b9..bbf5a1cb85bfaa08a35f581ae18faeb1288fe959 100644 (file)
@@ -56,7 +56,7 @@ IN: math.combinatorics.tests
 [ 0 ] [ 9 5 iota 3 <combo> dual-index ] unit-test
 [ 179 ] [ 72 10 iota 5 <combo> dual-index ] unit-test
 
-[ { 5 3 2 1 } ] [ 7 4 <combo> 8 combinadic ] unit-test
+[ { 5 3 2 1 } ] [ 7 iota 4 <combo> 8 combinadic ] unit-test
 [ { 4 3 2 1 0 } ] [ 10 iota 5 <combo> 0 combinadic ] unit-test
 [ { 8 6 3 1 0 } ] [ 10 iota 5 <combo> 72 combinadic ] unit-test
 [ { 9 8 7 6 5 } ] [ 10 iota 5 <combo> 251 combinadic ] unit-test
index 36b62ddcc06d0cbe53417a81d50a8a5714433af3..7c68aede094572249bf1049292b05b47ceca4a3a 100644 (file)
@@ -1,4 +1,4 @@
-! Copyright (c) 2007-2009 Slava Pestov, Doug Coleman, Aaron Schaefer.
+! Copyright (c) 2007-2010 Slava Pestov, Doug Coleman, Aaron Schaefer.
 ! See http://factorcode.org/license.txt for BSD license.
 USING: accessors assocs binary-search fry kernel locals math math.order
     math.ranges namespaces sequences sorting ;
@@ -15,7 +15,7 @@ IN: math.combinatorics
 PRIVATE>
 
 : factorial ( n -- n! )
-    1 [ 1 + * ] reduce ;
+    iota 1 [ 1 + * ] reduce ;
 
 : nPk ( n k -- nPk )
     2dup possible? [ dupd - [a,b) product ] [ 2drop 0 ] if ;
@@ -46,11 +46,11 @@ PRIVATE>
     [ permutation-indices ] keep nths ;
 
 : all-permutations ( seq -- seq )
-    [ length factorial ] keep
+    [ length factorial iota ] keep
     '[ _ permutation ] map ;
 
 : each-permutation ( seq quot -- )
-    [ [ length factorial ] keep ] dip
+    [ [ length factorial iota ] keep ] dip
     '[ _ permutation @ ] each ; inline
 
 : reduce-permutations ( seq identity quot -- result )
@@ -77,7 +77,7 @@ C: <combo> combo
     dup 0 = [
         drop 1 - nip
     ] [
-        [ [0,b) ] 2dip '[ _ nCk _ >=< ] search nip
+        [ iota ] 2dip '[ _ nCk _ >=< ] search nip
     ] if ;
 
 :: next-values ( a b x -- a' b' x' v )
@@ -104,7 +104,7 @@ C: <combo> combo
     [ combination-indices ] keep seq>> nths ;
 
 : combinations-quot ( seq k quot -- seq quot )
-    [ <combo> [ choose [0,b) ] keep ] dip
+    [ <combo> [ choose iota ] keep ] dip
     '[ _ apply-combination @ ] ; inline
 
 PRIVATE>
index 4b0481eca1eb808d514736f37d97a4ed2fce8d1c..f85ec49f81d06e79b46dec824d18b8f9da1fcfa0 100644 (file)
@@ -70,4 +70,7 @@ IN: math.complex.tests
 [ ] [ C{ 1 4 } coth drop ] unit-test
 [ ] [ C{ 1 4 } cot drop ] unit-test
 
+[ t ] [ 0.0 pi rect> exp C{ -1 0 } 1.0e-7 ~ ] unit-test
+[ t ] [ 0 pi rect> exp C{ -1 0 } 1.0e-7 ~ ] unit-test
+
 [ "C{ 1/2 2/3 }" ] [ C{ 1/2 2/3 } unparse ] unit-test
diff --git a/basis/math/floats/env/x86/32/32.factor b/basis/math/floats/env/x86/32/32.factor
new file mode 100644 (file)
index 0000000..ea3bee4
--- /dev/null
@@ -0,0 +1,29 @@
+USING: alien alien.c-types cpu.x86.assembler
+cpu.x86.assembler.operands math.floats.env.x86 system ;
+IN: math.floats.env.x86.32
+
+M: x86.32 get-sse-env
+    void { void* } "cdecl" [
+        EAX ESP [] MOV
+        EAX [] STMXCSR
+    ] alien-assembly ;
+
+M: x86.32 set-sse-env
+    void { void* } "cdecl" [
+        EAX ESP [] MOV
+        EAX [] LDMXCSR
+    ] alien-assembly ;
+
+M: x86.32 get-x87-env
+    void { void* } "cdecl" [
+        EAX ESP [] MOV
+        EAX [] FNSTSW
+        EAX 2 [+] FNSTCW
+    ] alien-assembly ;
+
+M: x86.32 set-x87-env
+    void { void* } "cdecl" [
+        EAX ESP [] MOV
+        FNCLEX
+        EAX 2 [+] FLDCW
+    ] alien-assembly ;
diff --git a/basis/math/floats/env/x86/32/tags.txt b/basis/math/floats/env/x86/32/tags.txt
new file mode 100644 (file)
index 0000000..6bf6830
--- /dev/null
@@ -0,0 +1 @@
+unportable
diff --git a/basis/math/floats/env/x86/64/64.factor b/basis/math/floats/env/x86/64/64.factor
new file mode 100644 (file)
index 0000000..b6f8ee1
--- /dev/null
@@ -0,0 +1,25 @@
+USING: alien alien.c-types cpu.architecture cpu.x86.assembler
+cpu.x86.assembler.operands math.floats.env.x86 sequences system ;
+IN: math.floats.env.x86.64
+
+M: x86.64 get-sse-env
+    void { void* } "cdecl" [
+        int-regs param-regs first [] STMXCSR
+    ] alien-assembly ;
+
+M: x86.64 set-sse-env
+    void { void* } "cdecl" [
+        int-regs param-regs first [] LDMXCSR
+    ] alien-assembly ;
+
+M: x86.64 get-x87-env
+    void { void* } "cdecl" [
+        int-regs param-regs first [] FNSTSW
+        int-regs param-regs first 2 [+] FNSTCW
+    ] alien-assembly ;
+
+M: x86.64 set-x87-env
+    void { void* } "cdecl" [
+        FNCLEX
+        int-regs param-regs first 2 [+] FLDCW
+    ] alien-assembly ;
diff --git a/basis/math/floats/env/x86/64/tags.txt b/basis/math/floats/env/x86/64/tags.txt
new file mode 100644 (file)
index 0000000..6bf6830
--- /dev/null
@@ -0,0 +1 @@
+unportable
index 2b73628b4ce064b7c6074647d2ad801cd082fa8d..89dd402378dedb9138439b45f70312b79feedd48 100644 (file)
@@ -1,7 +1,7 @@
-USING: accessors alien.c-types alien.syntax arrays assocs
-biassocs classes.struct combinators cpu.x86.features kernel
-literals math math.bitwise math.floats.env
-math.floats.env.private system ;
+USING: accessors alien.c-types arrays assocs biassocs
+classes.struct combinators cpu.x86.features kernel literals
+math math.bitwise math.floats.env math.floats.env.private
+system vocabs.loader ;
 IN: math.floats.env.x86
 
 STRUCT: sse-env
@@ -11,24 +11,23 @@ STRUCT: x87-env
     { status ushort }
     { control ushort } ;
 
-! defined in the vm, cpu-x86*.S
-FUNCTION: void get_sse_env ( sse-env* env ) ;
-FUNCTION: void set_sse_env ( sse-env* env ) ;
+HOOK: get-sse-env cpu ( sse-env -- )
+HOOK: set-sse-env cpu ( sse-env -- )
 
-FUNCTION: void get_x87_env ( x87-env* env ) ;
-FUNCTION: void set_x87_env ( x87-env* env ) ;
+HOOK: get-x87-env cpu ( x87-env -- )
+HOOK: set-x87-env cpu ( x87-env -- )
 
 : <sse-env> ( -- sse-env )
-    sse-env (struct) [ get_sse_env ] keep ;
+    sse-env (struct) [ get-sse-env ] keep ;
 
 M: sse-env (set-fp-env-register)
-    set_sse_env ;
+    set-sse-env ;
 
 : <x87-env> ( -- x87-env )
-    x87-env (struct) [ get_x87_env ] keep ;
+    x87-env (struct) [ get-x87-env ] keep ;
 
 M: x87-env (set-fp-env-register)
-    set_x87_env ;
+    set-x87-env ;
 
 M: x86 (fp-env-registers)
     sse2? [ <sse-env> <x87-env> 2array ] [ <x87-env> 1array ] if ;
@@ -128,3 +127,7 @@ M: x87-env (get-denormal-mode) ( register -- mode )
 M: x87-env (set-denormal-mode) ( register mode -- register' )
     drop ;
 
+cpu {
+    { x86.32 [ "math.floats.env.x86.32" ] }
+    { x86.64 [ "math.floats.env.x86.64" ] }
+} case require
index d91b4b6b92a0c5904d418037be7a6999e573322c..a1466dd22cb587415a694cbf31b57517c2e8d67b 100644 (file)
@@ -1,4 +1,4 @@
-! Copyright (C) 2004, 2008 Slava Pestov.
+! Copyright (C) 2004, 2010 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
 USING: math kernel math.constants math.private math.bits
 math.libm combinators math.order sequences ;
@@ -62,7 +62,7 @@ M: float exp fexp ; inline
 
 M: real exp >float exp ; inline
 
-M: complex exp >rect swap fexp swap polar> ; inline
+M: complex exp >rect swap exp swap polar> ; inline
 
 <PRIVATE
 
index a569b4af7bb39b852c752d83c85d5c83f48466b0..3fa3e97cbabedb8d9f0e0bb9d187abae3fc7869e 100644 (file)
@@ -291,7 +291,7 @@ IN: math.intervals.tests
     ] if ;
 
 unary-ops [
-    [ [ t ] ] dip '[ 8000 iota [ drop _ unary-test ] all? ] unit-test
+    [ [ t ] ] dip '[ 8000 [ drop _ unary-test ] all-integers? ] unit-test
 ] each
 
 : binary-ops ( -- alist )
index 371eb8a36c092bb4152e25eb71f3cbe84265c766..c8d5bb7338ea377811611437316fabe780872b1b 100644 (file)
@@ -1,4 +1,4 @@
-! Copyright (C) 2006, 2008 Slava Pestov.
+! Copyright (C) 2006, 2010 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
 USING: kernel locals math math.vectors math.matrices
 namespaces sequences fry sorting ;
@@ -42,7 +42,7 @@ SYMBOL: matrix
     [ [ clear-scale ] 2keep [ n*v ] dip v+ ] change-row ;
 
 : rows-from ( row# -- slice )
-    rows dup <slice> ;
+    rows dup iota <slice> ;
 
 : clear-col ( col# row# rows -- )
     [ nth-row ] dip [ [ 2dup ] dip (clear-col) ] each 2drop ;
@@ -79,9 +79,9 @@ SYMBOL: matrix
 
 : reduced ( matrix' -- matrix'' )
     [
-        rows <reversed> [
+        rows iota <reversed> [
             dup nth-row leading drop
-            dup [ swap dup clear-col ] [ 2drop ] if
+            dup [ swap dup iota clear-col ] [ 2drop ] if
         ] each
     ] with-matrix ;
 
index 75b9be5caec547429b2ff10422bf45dafa9c6e97..bf14d7ba13ccff4bcf5eb55385f561a5543c0e3b 100644 (file)
@@ -1,4 +1,4 @@
-! Copyright (C) 2005, 2009 Slava Pestov.
+! Copyright (C) 2005, 2010 Slava Pestov, Joe Groff.
 ! See http://factorcode.org/license.txt for BSD license.
 USING: accessors arrays columns kernel locals math math.bits
 math.functions math.order math.vectors sequences
@@ -11,7 +11,7 @@ IN: math.matrices
 
 : identity-matrix ( n -- matrix )
     #! Make a nxn identity matrix.
-    dup [ [ = 1 0 ? ] with map ] curry map ;
+    iota dup [ [ = 1 0 ? ] with map ] curry map ;
 
 :: rotation-matrix3 ( axis theta -- matrix )
     theta cos :> c
index 0de18b6febc38320a9acc305edcf16681daa7036..99d77d0ce2216d66d66bad92c36592b69833f293 100644 (file)
@@ -32,7 +32,7 @@ PRIVATE>
     2dup [ length ] bi@ + 1 - 2pad-tail [ >vector ] bi@ ;
 
 : p* ( p q -- r )
-    2unempty pextend-conv <reversed> dup length
+    2unempty pextend-conv <reversed> dup length iota
     [ over length pick <slice> pick [ * ] 2map sum ] map 2nip reverse ;
 
 : p-sq ( p -- p^2 )
index d201abfef8f5705dbaa25320014cf187d79da6b4..f803b7db01aebdee0ba41f1c0edf71705a908637 100644 (file)
@@ -8,4 +8,4 @@ IN: math.primes.miller-rabin.tests
 [ t ] [ 37 miller-rabin ] unit-test
 [ t ] [ 2135623355842621559 miller-rabin ] unit-test
 
-[ f ] [ 1000 [ drop 15 miller-rabin ] any? ] unit-test
+[ f ] [ 1000 iota [ drop 15 miller-rabin ] any? ] unit-test
index 04b1330cc2e0bec710355bf32b387d812a28fa5f..ac5c2df705764a6003c5d360bd4e519c3043a482 100644 (file)
@@ -10,7 +10,7 @@ IN: math.primes.miller-rabin
     n 1 - :> n-1
     n-1 factor-2s :> ( r s )
     0 :> a!
-    trials [
+    trials iota [
         drop
         2 n 2 - [a,b] random a!
         a s n ^mod 1 = [
index e099f6e830523ffc147910f61e1839a4692031e5..815b34a90d7288b816ce0cf9dc37bcba81df7a1d 100644 (file)
@@ -22,7 +22,7 @@ A-cast DEFINES       ${A}-cast
 A{     DEFINES       ${A}{
 
 N       [ A-rep rep-length ]
-BOA-EFFECT [ N 2 * "n" <repetition> >array { "v" } <effect> ]
+BOA-EFFECT [ N 2 * "n" <array> { "v" } <effect> ]
 
 WHERE
 
index 658d9b270c8eaffe1f6e3ab792ab771a2b05ab38..d80755a6a5c2cb24b37f1c6e5cf142ee0d33096d 100644 (file)
@@ -238,7 +238,7 @@ PRIVATE>
     [ >rep-array ] [ widen-vector-rep [ rep-length ] [ [>rep-array] ] bi ] bi
     [ tail-slice ] dip call( a' -- c' ) underlying>> ;
 : (simd-with)              (   n rep -- v )
-    [ rep-length iota swap '[ _ ] ] [ <rep-array> ] bi replicate-as 
+    [ rep-length swap '[ _ ] ] [ <rep-array> ] bi replicate-as 
     underlying>> ;
 : (simd-gather-2)          ( m n rep -- v ) <rep-array> [ 2 set-firstn ] keep underlying>> ;
 : (simd-gather-4)          ( m n o p rep -- v ) <rep-array> [ 4 set-firstn ] keep underlying>> ;
index aaa55078640749b3135a48489b0e075be1ab1c75..342c565dcebe16590a4ac58b76835b3dd3616ef5 100644 (file)
@@ -175,7 +175,8 @@ CONSTANT: vector-words
 "== Checking vector operations" print
 
 : random-int-vector ( class -- vec )
-    new [ drop 1,000 random ] map ;
+    new [ drop 1000 random ] map ;
+
 : random-float-vector ( class -- vec )
     new [
         drop
@@ -463,7 +464,7 @@ TUPLE: inconsistent-vector-test bool branch ;
 
 ! Test element access -- it should box bignums for int-4 on x86
 : test-accesses ( seq -- failures )
-    [ length >array ] keep
+    [ length iota >array ] keep
     '[ [ _ 1quotation ] dip '[ _ swap nth ] ] [ = ] check-optimizer ; inline
 
 [ { } ] [ float-4{ 1.0 2.0 3.0 4.0 } test-accesses ] unit-test
@@ -480,7 +481,7 @@ TUPLE: inconsistent-vector-test bool branch ;
 
 "== Checking broadcast" print
 : test-broadcast ( seq -- failures )
-    [ length >array ] keep
+    [ length iota >array ] keep
     '[ [ _ 1quotation ] dip '[ _ vbroadcast ] ] [ = ] check-optimizer ;
 
 [ { } ] [ float-4{ 1.0 2.0 3.0 4.0 } test-broadcast ] unit-test
index 905737c266c283cca9ec43534888cbde7f3931bf..acf13599c1f059552a8671ca323531e09370a7ce 100644 (file)
@@ -247,7 +247,7 @@ COERCER [ ELT c-type-class "coercer" word-prop [ ] or ]
 
 SET-NTH [ ELT dup c:c-setter c:array-accessor ]
 
-BOA-EFFECT [ N "n" <repetition> >array { "v" } <effect> ]
+BOA-EFFECT [ N "n" <array> { "v" } <effect> ]
 
 WHERE
 
index 311abf50af1d474076d23e6b589f0d9ee039812a..69d8929c651d49d90f4a67f739a887ed9cf0f9d7 100644 (file)
@@ -58,21 +58,14 @@ M: object v*hs+ [ * ] 2map (h+) ;
 GENERIC: v/ ( u v -- w )
 M: object v/ [ / ] 2map ;
 
-<PRIVATE
-
-: if-both-floats ( x y p q -- )
-    [ 2dup [ float? ] both? ] 2dip if ; inline
-
-PRIVATE>
-
 GENERIC: vavg ( u v -- w )
 M: object vavg [ + 2 / ] 2map ;
 
 GENERIC: vmax ( u v -- w )
-M: object vmax [ [ float-max ] [ max ] if-both-floats ] 2map ;
+M: object vmax [ max ] 2map ;
 
 GENERIC: vmin ( u v -- w )
-M: object vmin [ [ float-min ] [ min ] if-both-floats ] 2map ;
+M: object vmin [ min ] 2map ;
 
 GENERIC: v+- ( u v -- w )
 M: object v+-
index 257a2bb1ea059be27a418b4eb4f72d15c8493f82..7c29310a97716c9764422170e19e8f58cd37aac2 100644 (file)
@@ -1,9 +1,9 @@
-! Copyright (C) 2009 Slava Pestov.
+! Copyright (C) 2009, 2010 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
 USING: models.arrow models.product stack-checker accessors fry
-generalizations macros kernel ;
+generalizations combinators.smart macros kernel ;
 IN: models.arrow.smart
 
 MACRO: <smart-arrow> ( quot -- quot' )
-    [ infer in>> dup ] keep
+    [ inputs dup ] keep
     '[ _ narray <product> [ _ firstn @ ] <arrow> ] ;
\ No newline at end of file
index 2a0eef7227aed299377fd41e4bdd9a473db950ad..363f30678dadefff30c3522fda26915c563ce31d 100644 (file)
@@ -1,6 +1,6 @@
 USING: nibble-arrays tools.test sequences kernel math ;
 IN: nibble-arrays.tests
 
-[ t ] [ 16 dup >nibble-array sequence= ] unit-test
+[ t ] [ 16 iota dup >nibble-array sequence= ] unit-test
 [ N{ 4 2 1 3 } ] [ N{ 3 1 2 4 } reverse ] unit-test
 [ N{ 1 4 9 0 9 4 } ] [ N{ 1 2 3 4 5 6 } [ sq ] map ] unit-test
index 5ddd5f9bf08e04699ac9ce3bdf16b145553b762d..ffc4cb91ad78aa462b4abbf529ac615225179e80 100644 (file)
@@ -446,14 +446,14 @@ M: ebnf-sequence build-locals ( code ast -- code )
     ] [ \r
       [\r
         "FROM: locals => [let :> ; FROM: sequences => nth ; [let " %\r
-          dup length [\r
+          [\r
             over ebnf-var? [\r
               " " % # " over nth :> " %\r
               name>> % \r
             ] [\r
               2drop\r
             ] if\r
-          ] 2each\r
+          ] each-index\r
           " " %\r
           %  \r
           " nip ]" %     \r
index d66fdd0c089eaacd055ef5926006c17123d4267a..482367ad9cf0277bd6c27e692de3346e3e9a0969 100644 (file)
@@ -81,7 +81,8 @@ M: hash-0-b hashcode* 2drop 0 ;
 ] unit-test
 
 : random-string ( -- str )
-    1000000 random ; ! [ CHAR: a CHAR: z [a,b] random ] "" replicate-as ;
+    1000000 random ;
+    ! [ CHAR: a CHAR: z [a,b] random ] "" replicate-as ;
 
 : random-assocs ( n -- hash phash )
     [ random-string ] replicate
index 95fa70558d0d6ed4feb5d17f8354fdb71074b8cc..6d340ca78a95b6575613c26caecdc81abfe7b84a 100644 (file)
@@ -18,14 +18,14 @@ vectors math math.order ;
 ] unit-test
 
 { 100 1060 2000 10000 100000 1000000 } [
-    [ t ] swap [ dup >persistent-vector sequence= ] curry unit-test
+    [ t ] swap [ iota dup >persistent-vector sequence= ] curry unit-test
 ] each
 
 [ ] [ 10000 [ 16 random-bits ] PV{ } replicate-as "1" set ] unit-test
 [ ] [ "1" get >vector "2" set ] unit-test
 
 [ t ] [
-    3000 [
+    3000 iota [
         drop
         16 random-bits 10000 random
         [ "1" [ new-nth ] change ]
@@ -56,11 +56,11 @@ vectors math math.order ;
 ] unit-test
 
 [ t ] [
-    10000 >persistent-vector 752 [ ppop ] times dup length sequence=
+    10000 iota >persistent-vector 752 [ ppop ] times dup length iota sequence=
 ] unit-test
 
 [ t ] [
-    100 [
+    100 iota [
         drop
         100 random [
             16 random-bits [ "1" [ ppush ] change ] [ "2" get push ] bi
index 2e1a47b9512d50b75f68667c123483d1a3e84407..e3cb186bf8057f5d45f2a13faf59c4c2cd2f43af 100644 (file)
@@ -33,10 +33,10 @@ IN: porter-stemmer
     ] if ;
 
 : consonant-seq ( str -- n )
-    0 0 rot skip-consonants (consonant-seq) ;
+    [ 0 0 ] dip skip-consonants (consonant-seq) ;
 
 : stem-vowel? ( str -- ? )
-    [ length ] keep [ consonant? ] curry all? not ;
+    [ length iota ] keep [ consonant? ] curry all? not ;
 
 : double-consonant? ( i str -- ? )
     over 1 < [
index 6cff3992019b36f43cac5645b7275a3c4091c9a4..65d25f1812f5d386a121e92b8cb5ab522e1fd2dc 100644 (file)
@@ -73,8 +73,8 @@ SYMBOL: ->
 
 : remove-breakpoints ( quot pos -- quot' )
     over quotation? [
-        1 + cut [ (remove-breakpoints) ] bi@
-        [ -> ] glue 
+        1 + short cut [ (remove-breakpoints) ] bi@
+        [ -> ] glue
     ] [
         drop
     ] if ;
index 040b6d8f7c23723f365e04e8bc002d56bb364cb7..6f5f61f688ef3ae019c6524e3e4b13099ec5a462 100644 (file)
@@ -1,4 +1,4 @@
-! Copyright (C) 2003, 2009 Slava Pestov.
+! Copyright (C) 2003, 2010 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
 USING: arrays generic hashtables io kernel math assocs
 namespaces make sequences strings io.styles vectors words
@@ -309,7 +309,7 @@ SYMBOL: next
 
 : group-flow ( seq -- newseq )
     [
-        dup length [
+        dup length iota [
             2dup 1 - swap ?nth prev set
             2dup 1 + swap ?nth next set
             swap nth dup split-before dup , split-after
index b877af6f79bfd465addaaa700a269298a80faa26..ede3c92f517b60cd2acf4f2c5b2d7e3442a3c244 100644 (file)
@@ -5,7 +5,7 @@ IN: random.mersenne-twister.tests
 : check-random ( max -- ? )
     [ random 0 ] keep between? ;
 
-[ t ] [ 100 [ drop 674 check-random ] all? ] unit-test
+[ t ] [ 100 [ drop 674 check-random ] all-integers? ] unit-test
 
 : randoms ( -- seq )
     100 [ 100 random ] replicate ;
@@ -16,11 +16,11 @@ IN: random.mersenne-twister.tests
 [ f ] [ 1234 [ randoms randoms = ] test-rng ] unit-test
 
 [ 1333075495 ] [
-    0 [ 1000 [ drop random-generator get random-32* drop ] each random-generator get random-32* ] test-rng
+    0 [ 1000 [ drop random-generator get random-32* drop ] each-integer random-generator get random-32* ] test-rng
 ] unit-test
 
 [ 1575309035 ] [
-    0 [ 10000 [ drop random-generator get random-32* drop ] each random-generator get random-32* ] test-rng
+    0 [ 10000 [ drop random-generator get random-32* drop ] each-integer random-generator get random-32* ] test-rng
 ] unit-test
 
 
index 90489d30521940781ef2c29e98c5a86dd9779247..9fd82a30626a10eb6b4b0985eeca45776bc83a62 100644 (file)
@@ -30,8 +30,8 @@ CONSTANT: a uint-array{ 0 HEX: 9908b0df }
 : mt-generate ( mt -- )
     [
         seq>>
-        [ [ n m - ] dip '[ [ m ] dip _ mt[k] ] each ]
-        [ [ m 1 - ] dip '[ [ m n - ] [ n m - + ] bi* _ mt[k] ] each ]
+        [ [ n m - ] dip '[ [ m ] dip _ mt[k] ] each-integer ]
+        [ [ m 1 - ] dip '[ [ m n - ] [ n m - + ] bi* _ mt[k] ] each-integer ]
         bi
     ] [ 0 >>i drop ] bi ; inline
 
@@ -41,7 +41,7 @@ CONSTANT: a uint-array{ 0 HEX: 9908b0df }
 : init-mt-rest ( seq -- )
     n 1 - swap '[
         _ [ init-mt-formula ] [ [ 1 + ] dip set-nth ] 2bi
-    ] each ; inline
+    ] each-integer ; inline
 
 : init-mt-seq ( seed -- seq )
     32 bits n <uint-array>
index 788a6e700a45b3b92cf0a4c4d98b1027243fb4df..2bf92f64a3b51512daa3392dde72227fc97ff8d3 100644 (file)
@@ -19,9 +19,8 @@ HELP: random-bytes*
 { $description "Generates a byte-array of random bytes." } ;
 
 HELP: random
-{ $values { "seq" sequence } { "elt" "a random element" } }
-{ $description "Outputs a random element of the input sequence. Outputs " { $link f } " if the sequence is empty." }
-{ $notes "Since integers are sequences, passing an integer " { $snippet "n" } " outputs an integer in the interval " { $snippet "[0,n)" } "." }
+{ $values { "obj" object } { "elt" "a random element" } }
+{ $description "Outputs a random element of the input object, or outputs " { $link f } " if the object contains no elements." }
 { $examples
     { $unchecked-example "USING: random prettyprint ;"
         "10 random ."
index 96dc8cc783c9fdf4d48bec12a58da076f439954f..9341b96b11499c604310cefd207658936882ce1e 100644 (file)
@@ -11,8 +11,8 @@ IN: random.tests
 [ 2 ] [ V{ 10 20 30 } [ delete-random drop ] keep length ] unit-test
 [ V{ } [ delete-random drop ] keep length ] must-fail
 
-[ t ] [ 10000 [ 0 [ drop 187 random + ] reduce ] keep / 2 * 187 10 ~ ] unit-test
-[ t ] [ 10000 [ 0 [ drop 400 random + ] reduce ] keep / 2 * 400 10 ~ ] unit-test
+[ t ] [ 10000 [ iota 0 [ drop 187 random + ] reduce ] keep / 2 * 187 10 ~ ] unit-test
+[ t ] [ 10000 [ iota 0 [ drop 400 random + ] reduce ] keep / 2 * 400 10 ~ ] unit-test
 
 [ t ] [ 1000 [ 400 random ] replicate prune length 256 > ] unit-test
 
@@ -29,7 +29,7 @@ IN: random.tests
 [ { 1 2 } 3 sample ] [ too-many-samples?  ] must-fail-with
 
 [ 3 ] [ { 1 2 3 4 } 3 sample prune length ] unit-test
-[ 99 ] [ 100 99 sample prune length ] unit-test
+[ 99 ] [ 100 iota 99 sample prune length ] unit-test
 
 [ ]
 [ [ 100 random-bytes ] with-system-random drop ] unit-test
index bfd107dbb64772824b5757e79a0c796296bbdd2e..1e54c567284315b8d0a9dd921c86d9ab921eb6e0 100644 (file)
@@ -50,7 +50,11 @@ PRIVATE>
 : random-bits* ( numbits -- n )
     1 - [ random-bits ] keep set-bit ;
 
-: random ( seq -- elt )
+GENERIC: random ( obj -- elt )
+
+M: integer random [ f ] [ random-integer ] if-zero ;
+
+M: sequence random
     [ f ] [
         [ length random-integer ] keep nth
     ] if-empty ;
@@ -59,7 +63,7 @@ PRIVATE>
 
 : randomize ( seq -- seq )
     dup length [ dup 1 > ]
-    [ [ iota random ] [ 1 - ] bi [ pick exchange ] keep ]
+    [ [ random ] [ 1 - ] bi [ pick exchange ] keep ]
     while drop ;
 
 ERROR: too-many-samples seq n ;
index fcde135cf887c0fb1af245ef8332f1d634624f91..33b2ded448e53ad803265f0118ccc864c5449a79 100644 (file)
@@ -11,9 +11,7 @@ TUPLE: parts in out ;
     zip [ first ] partition [ values ] bi@ parts boa ;
 
 : powerset-partition ( sequence -- partitions )
-    [ length [ 2^ ] keep ] keep '[
-        _ <bits> _ make-partition
-    ] map rest ;
+    [ length [ 2^ iota ] keep ] keep '[ _ <bits> _ make-partition ] map rest ;
 
 : partition>class ( parts -- class )
     [ out>> [ <not-class> ] map ]
index 50a057d7f400628f856cf48210022c4905d3c0ce..c81ed0ae42898c518dcc2c94bdaa12390098a912 100644 (file)
@@ -4,7 +4,7 @@ USING: help.markup help.syntax kernel math strings ;
 IN: roman
 
 HELP: >roman
-{ $values { "n" "an integer" } { "str" "a string" } }
+{ $values { "n" integer } { "str" string } }
 { $description "Converts a number to its lower-case Roman Numeral equivalent." }
 { $notes "The range for this word is 1-3999, inclusive." }
 { $examples 
@@ -15,7 +15,7 @@ HELP: >roman
 } ;
 
 HELP: >ROMAN
-{ $values { "n" "an integer" } { "str" "a string" } }
+{ $values { "n" integer } { "str" string } }
 { $description "Converts a number to its upper-case Roman numeral equivalent." }
 { $notes "The range for this word is 1-3999, inclusive." }
 { $examples 
@@ -26,7 +26,7 @@ HELP: >ROMAN
 } ;
 
 HELP: roman>
-{ $values { "str" "a string" } { "n" "an integer" } }
+{ $values { "str" string } { "n" integer } }
 { $description "Converts a Roman numeral to an integer." }
 { $notes "The range for this word is i-mmmcmxcix, inclusive." }
 { $examples 
@@ -39,7 +39,7 @@ HELP: roman>
 { >roman >ROMAN roman> } related-words
 
 HELP: roman+
-{ $values { "string" string } { "string" string } { "string" string } }
+{ $values { "x" string } { "x" string } { "x" string } }
 { $description "Adds two Roman numerals." }
 { $examples 
     { $example "USING: io roman ;"
@@ -49,7 +49,7 @@ HELP: roman+
 } ;
 
 HELP: roman-
-{ $values { "string" string } { "string" string } { "string" string } }
+{ $values { "x" string } { "x" string } { "x" string } }
 { $description "Subtracts two Roman numerals." }
 { $examples 
     { $example "USING: io roman ;"
@@ -61,7 +61,7 @@ HELP: roman-
 { roman+ roman- } related-words
 
 HELP: roman*
-{ $values { "string" string } { "string" string } { "string" string } }
+{ $values { "x" string } { "x" string } { "x" string } }
 { $description "Multiplies two Roman numerals." }
 { $examples 
     { $example "USING: io roman ;"
@@ -71,7 +71,7 @@ HELP: roman*
 } ;
 
 HELP: roman/i
-{ $values { "string" string } { "string" string } { "string" string } }
+{ $values { "x" string } { "x" string } { "x" string } }
 { $description "Computes the integer division of two Roman numerals." }
 { $examples 
     { $example "USING: io roman ;"
@@ -81,7 +81,7 @@ HELP: roman/i
 } ;
 
 HELP: roman/mod
-{ $values { "string" string } { "string" string } { "string" string } { "string" string } }
+{ $values { "x" string } { "x" string } { "x" string } { "x" string } }
 { $description "Computes the quotient and remainder of two Roman numerals." }
 { $examples 
     { $example "USING: kernel io roman ;"
index a645898c034e9838c970e2216795ebb15c7b8b2c..a783e7973c3193f1eb120a7381a967baaa125ff6 100644 (file)
@@ -48,7 +48,7 @@ PRIVATE>
 <PRIVATE
 
 MACRO: binary-roman-op ( quot -- quot' )
-    [ infer in>> ] [ ] [ infer out>> ] tri
+    [ inputs ] [ ] [ outputs ] tri
     '[ [ roman> ] _ napply @ [ >roman ] _ napply ] ;
 
 PRIVATE>
@@ -58,8 +58,7 @@ PRIVATE>
 SYNTAX: ROMAN-OP:
     scan-word [ name>> "roman" prepend create-in ] keep
     1quotation '[ _ binary-roman-op ]
-    dup infer [ in>> ] [ out>> ] bi
-    [ "string" <repetition> ] bi@ <effect> define-declared ;
+    dup infer define-declared ;
 
 >>
 
index 6dbc76386d1c4824f9546d3203d041a88e1cdec0..036356e137975eeeec2fa147007450d2cacb2659 100644 (file)
@@ -16,12 +16,12 @@ IN: serialize.tests
 [ t ] [
     100 [
         drop
-        40 [        test-serialize-cell ] all?
-         4 [ 40 *   test-serialize-cell ] all?
-         4 [ 400 *  test-serialize-cell ] all?
-         4 [ 4000 * test-serialize-cell ] all?
+        40 [        test-serialize-cell ] all-integers?
+         4 [ 40 *   test-serialize-cell ] all-integers?
+         4 [ 400 *  test-serialize-cell ] all-integers?
+         4 [ 4000 * test-serialize-cell ] all-integers?
         and and and
-    ] all?
+    ] all-integers?
 ] unit-test
 
 TUPLE: serialize-test a b ;
index 9b4b0ac46b9651be7bd68fafe8668728d35c66bf..0840c778d7923473d6a3c434b8c7aed0cded8ad7 100644 (file)
@@ -240,7 +240,7 @@ SYMBOL: deserialized
     [ ] tri ;
 
 : copy-seq-to-tuple ( seq tuple -- )
-    [ dup length ] dip [ set-array-nth ] curry 2each ;
+    [ set-array-nth ] curry each-index ;
 
 : deserialize-tuple ( -- array )
     #! Ugly because we have to intern the tuple before reading
index 0ff41edec621ffc1b74d33f0603b722539cc0228..b826606df51f85070e4d9ddb17270b3a1e9625a4 100644 (file)
@@ -8,7 +8,7 @@ IN: shuffle
 <PRIVATE
 
 : >index-assoc ( sequence -- assoc )
-    dup length zip >hashtable ;
+    dup length iota zip >hashtable ;
 
 PRIVATE>
 
index 78b1493920cca026cde6aa54b8e9085f3e5cb462..b7fefcad635c9d04d381d34fa669a86069db073e 100644 (file)
@@ -13,4 +13,4 @@ PRIVATE>
 
 : insertion-sort ( seq quot -- )
     ! quot is a transformation on elements
-    over length [ insert ] with with each ; inline
+    over length [ insert ] with with each-integer ; inline
index 5ebd4438fe94e9ab757be475b56d4a4a2e3a8f46..08fc0e921d4a44b6881b3dff93a5dc0201cb49c4 100644 (file)
@@ -1,8 +1,7 @@
 ! Copyright (C) 2009 Doug Coleman.
 ! See http://factorcode.org/license.txt for BSD license.
 USING: accessors math.order sorting.slots tools.test
-sorting.human arrays sequences kernel assocs multiline
-sorting.functor ;
+arrays sequences kernel assocs multiline sorting.functor ;
 IN: sorting.literals.tests
 
 TUPLE: sort-test a b c tuple2 ;
@@ -42,7 +41,7 @@ TUPLE: tuple2 d ;
         T{ sort-test f 1 1 11 }
         T{ sort-test f 2 5 3 }
         T{ sort-test f 2 5 2 }
-    } { { a>> human<=> } { b>> human>=< } { c>> <=> } } sort-by
+    } { { a>> <=> } { b>> >=< } { c>> <=> } } sort-by
 ] unit-test
 
 [ { } ]
@@ -83,14 +82,14 @@ TUPLE: tuple2 d ;
     { length-test<=> <=> } sort-by
 ] unit-test
 
-[ { { 0 1 } { 1 2 } { 1 1 } { 3 2 } } ]
+[ { { { 0 } 1 } { { 1 } 2 } { { 1 } 1 } { { 3 1 } 2 } } ]
 [
-    { { 3 2 } { 1 2 } { 0 1 } { 1 1 } }
+    { { { 3 1 } 2 } { { 1 } 2 } { { 0 } 1 } { { 1 } 1 } }
     { length-test<=> <=> } sort-keys-by
 ] unit-test
 
-[ { { 0 1 } { 1 1 } { 3 2 } { 1 2 } } ]
+[ { { 0 { 1 } } { 1 { 1 } } { 3 { 2 4 } } { 1 { 2 0 0 0 } } } ]
 [
-    { { 3 2 } { 1 2 } { 0 1 } { 1 1 } }
+    { { 3 { 2 4 } } { 1 { 2 0 0 0 } } { 0 { 1 } } { 1 { 1 } } }
     { length-test<=> <=> } sort-values-by
 ] unit-test
index 3641345a3ebd2bd9179e1224d9e8df1dbf69d146..32bb8b46c6edf5ff46297dc20c70ff820202e2d8 100644 (file)
@@ -26,7 +26,7 @@ PRIVATE>
 : (monotonic-slice) ( seq quot class -- slices )
     [
         dupd '[
-            [ length ] [ ] [ <circular> 1 over change-circular-start ] tri
+            [ length iota ] [ ] [ <circular> 1 over change-circular-start ] tri
             [ @ not [ , ] [ drop ] if ] 3each
         ] { } make
         dup empty? [ over length 1 - prefix ] when -1 prefix 2 clump
index deeada373547223d2656e94f9b47eabf81986fb4..fdfda6dd9e37ba417346be7b3bf6c92b1b36b4c0 100644 (file)
@@ -12,6 +12,8 @@ TUPLE: alien-invoke-params < alien-node-params library function ;
 
 TUPLE: alien-indirect-params < alien-node-params ;
 
+TUPLE: alien-assembly-params < alien-node-params quot ;
+
 TUPLE: alien-callback-params < alien-node-params quot xt ;
 
 : param-prep-quot ( node -- quot )
@@ -58,6 +60,22 @@ TUPLE: alien-callback-params < alien-node-params quot xt ;
     ! Quotation which coerces return value to required type
     return-prep-quot infer-quot-here ;
 
+: infer-alien-assembly ( -- )
+    alien-assembly-params new
+    ! Compile-time parameters
+    pop-literal nip >>quot
+    pop-literal nip >>abi
+    pop-literal nip >>parameters
+    pop-literal nip >>return
+    ! Quotation which coerces parameters to required types
+    dup param-prep-quot infer-quot-here
+    ! Magic #: consume exactly the number of inputs
+    dup 0 alien-stack
+    ! Add node to IR
+    dup #alien-assembly,
+    ! Quotation which coerces return value to required type
+    return-prep-quot infer-quot-here ;
+
 : callback-xt ( word return-rewind -- alien )
     [ callbacks get ] dip '[ _ <callback> ] cache ;
 
index d008c4921d6519d9c092fa0cce8c404b1558995f..433c11d34c80125e165455aa2e7acf4b2d2ceda8 100644 (file)
@@ -1,6 +1,6 @@
-! Copyright (C) 2008, 2009 Slava Pestov.
+! Copyright (C) 2008, 2010 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: accessors kernel prettyprint io debugger
+USING: accessors arrays kernel prettyprint io debugger
 sequences assocs stack-checker.errors summary effects ;
 IN: stack-checker.errors.prettyprint
 
@@ -15,7 +15,7 @@ M: unbalanced-branches-error summary
 
 M: unbalanced-branches-error error.
     dup summary print
-    [ quots>> ] [ branches>> [ length <effect> ] { } assoc>map ] bi zip
+    [ quots>> ] [ branches>> [ length [ "x" <array> ] bi@ <effect> ] { } assoc>map ] bi zip
     [ [ first pprint-short bl ] [ second effect>string print ] bi ] each ;
 
 M: too-many->r summary
index 38ac2b0e719a24fb66f63e9c35f6dd928da46fab..20d61b9c3769cf829f64d519d88cb7a16fb8a931 100644 (file)
@@ -1,4 +1,4 @@
-! Copyright (C) 2008 Slava Pestov.
+! Copyright (C) 2008, 2010 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
 USING: fry namespaces assocs kernel sequences words accessors
 definitions math math.order effects classes arrays combinators
@@ -42,7 +42,7 @@ loop? ;
 : make-copies ( values effect-in -- values' )
     [ length cut* ] keep
     [ quotation-param? [ copy-value ] [ drop <value> ] if ] 2map
-    [ make-values ] dip append ;
+    [ length make-values ] dip append ;
 
 SYMBOL: enter-in
 SYMBOL: enter-out
index 316ae6ca2f086e778dc4da35bdcc3911ff6e4957..b217f4d659628781381d6dc04c386cda6adc9223 100644 (file)
@@ -1,4 +1,4 @@
-! Copyright (C) 2004, 2009 Slava Pestov, Daniel Ehrenberg.
+! Copyright (C) 2004, 2010 Slava Pestov, Daniel Ehrenberg.
 ! See http://factorcode.org/license.txt for BSD license.
 USING: fry accessors alien alien.accessors arrays byte-arrays
 classes continuations.private effects generic hashtables
@@ -153,7 +153,7 @@ M: bad-executable summary
 
 : infer-<tuple-boa> ( -- )
     \ <tuple-boa>
-    peek-d literal value>> second 1 + { tuple } <effect>
+    peek-d literal value>> second 1 + "obj" <array> { tuple } <effect>
     apply-word/effect ;
 
 \ <tuple-boa> [ infer-<tuple-boa> ] "special" set-word-prop
@@ -228,6 +228,7 @@ M: bad-executable summary
 
 \ alien-invoke [ infer-alien-invoke ] "special" set-word-prop
 \ alien-indirect [ infer-alien-indirect ] "special" set-word-prop
+\ alien-assembly [ infer-alien-assembly ] "special" set-word-prop
 \ alien-callback [ infer-alien-callback ] "special" set-word-prop
 
 : infer-special ( word -- )
@@ -488,10 +489,10 @@ M: bad-executable summary
 \ word-xt { word } { integer integer } define-primitive
 \ word-xt make-flushable
 
-\ getenv { fixnum } { object } define-primitive
-\ getenv make-flushable
+\ special-object { fixnum } { object } define-primitive
+\ special-object make-flushable
 
-\ setenv { object fixnum } { } define-primitive
+\ set-special-object { object fixnum } { } define-primitive
 
 \ (exists?) { string } { object } define-primitive
 
index cc4a688f7aea9dc510c46434dbfc7c899c74ad4f..eb25b9be57d883173b4d49d77136011c64f4835a 100644 (file)
@@ -11,14 +11,14 @@ IN: stack-checker
 ARTICLE: "inference-simple" "Straight-line stack effects"
 "The simplest case is when a piece of code does not have any branches or recursion, and just pushes literals and calls words."
 $nl
-"Pushing a literal has stack effect " { $snippet "( -- object )" } ". The stack effect of a most words is always known statically from the declaration. Stack effects of " { $link POSTPONE: inline } " words and " { $link "macros" } ", may depend on literals pushed on the stack prior to the call, and this case is discussed in " { $link "inference-combinators" } "."
+"Pushing a literal has stack effect " { $snippet "( -- x )" } ". The stack effect of a most words is always known statically from the declaration. Stack effects of " { $link POSTPONE: inline } " words and " { $link "macros" } ", may depend on literals pushed on the stack prior to the call, and this case is discussed in " { $link "inference-combinators" } "."
 $nl
 "The stack effect of each element in a code snippet is composed. The result is then the stack effect of the snippet."
 $nl
 "An example:"
-{ $example "[ 1 2 3 ] infer." "( -- object object object )" }
+{ $example "[ 1 2 3 ] infer." "( -- x x x )" }
 "Another example:"
-{ $example "[ 2 + ] infer." "( object -- object )" } ;
+{ $example "[ 2 + ] infer." "( x -- x )" } ;
 
 ARTICLE: "inference-combinators" "Combinator stack effects"
 "If a word calls a combinator, one of the following two conditions must hold for the stack checker to succeed:"
@@ -30,15 +30,15 @@ ARTICLE: "inference-combinators" "Combinator stack effects"
 { $heading "Examples" }
 { $subheading "Calling a combinator" }
 "The following usage of " { $link map } " passes the stack checker, because the quotation is the result of " { $link curry } ":"
-{ $example "USING: math sequences ;" "[ [ + ] curry map ] infer." "( object object -- object )" }
+{ $example "USING: math sequences ;" "[ [ + ] curry map ] infer." "( x x -- x )" }
 "The equivalent code using " { $vocab-link "fry" } " and " { $vocab-link "locals" } " likewise passes the stack checker:"
-{ $example "USING: fry math sequences ;" "[ '[ _ + ] map ] infer." "( object object -- object )" }
-{ $example "USING: locals math sequences ;" "[| a | [ a + ] map ] infer." "( object object -- object )" }
+{ $example "USING: fry math sequences ;" "[ '[ _ + ] map ] infer." "( x x -- x )" }
+{ $example "USING: locals math sequences ;" "[| a | [ a + ] map ] infer." "( x x -- x )" }
 { $subheading "Defining an inline combinator" }
 "The following word calls a quotation twice; the word is declared " { $link POSTPONE: inline } ", since it invokes " { $link call } " on the result of " { $link compose } " on an input parameter:"
 { $code ": twice ( value quot -- result ) dup compose call ; inline" }
 "The following code now passes the stack checker; it would fail were " { $snippet "twice" } " not declared " { $link POSTPONE: inline } ":"
-{ $unchecked-example "USE: math.functions" "[ [ sqrt ] twice ] infer." "( object -- object )" }
+{ $unchecked-example "USE: math.functions" "[ [ sqrt ] twice ] infer." "( x -- x )" }
 { $subheading "Defining a combinator for unknown quotations" }
 "In the next example, " { $link POSTPONE: call( } " must be used because the quotation the result of calling a runtime accessor, and the compiler cannot make any static assumptions about this quotation at all:"
 { $code
@@ -61,14 +61,14 @@ $nl
 }
 "To make this work, use " { $link dip } " to pass the quotation instead:"
 { $example
-  "[ [ reverse ] [ [ reverse ] map ] dip call ] infer." "( object -- object )"
+  "[ [ reverse ] [ [ reverse ] map ] dip call ] infer." "( x -- x )"
 } ;
 
 ARTICLE: "inference-branches" "Branch stack effects"
 "Conditionals such as " { $link if } " and combinators built on top have the same restrictions as " { $link POSTPONE: inline } " combinators (see " { $link "inference-combinators" } ") with the additional requirement that all branches leave the stack at the same height. If this is not the case, the stack checker throws a " { $link unbalanced-branches-error } "."
 $nl
 "If all branches leave the stack at the same height, then the stack effect of the conditional is just the maximum of the stack effect of each branch. For example,"
-{ $example "[ [ + ] [ drop ] if ] infer." "( object object object -- object )" }
+{ $example "[ [ + ] [ drop ] if ] infer." "( x x x -- x )" }
 "The call to " { $link if } " takes one value from the stack, a generalized boolean. The first branch " { $snippet "[ + ]" } " has stack effect " { $snippet "( x x -- x )" } " and the second has stack effect " { $snippet "( x -- )" } ". Since both branches decrease the height of the stack by one, we say that the stack effect of the two branches is " { $snippet "( x x -- x )" } ", and together with the boolean popped off the stack by " { $link if } ", this gives a total stack effect of " { $snippet "( x x x -- x )" } "." ;
 
 ARTICLE: "inference-recursive-combinators" "Recursive combinator stack effects"
@@ -87,7 +87,7 @@ $nl
 "An inline recursive word cannot pass a quotation on the data stack through the recursive call. For example, the following will not infer:"
 { $unchecked-example ": bad ( ? quot: ( ? -- ) -- ) 2dup [ not ] dip bad call ; inline recursive" "[ [ drop ] bad ] infer." "Cannot apply “call” to a run-time computed value\nmacro call" }
 "However a small change can be made:"
-{ $example ": good ( ? quot: ( ? -- ) -- ) [ good ] 2keep [ not ] dip call ; inline recursive" "[ [ drop ] good ] infer." "( object -- )" }
+{ $example ": good ( ? quot: ( ? -- ) -- ) [ good ] 2keep [ not ] dip call ; inline recursive" "[ [ drop ] good ] infer." "( x -- )" }
 "An inline recursive word must have a fixed stack effect in its base case. The following will not infer:"
 { $code
     ": foo ( quot ? -- ) [ f foo ] [ call ] if ; inline"
index 6af0ec64e583ebe0df9347eca44e3c5ec581051e..8a0724556e8ad95a676ff964716b17b778740a70 100644 (file)
@@ -289,21 +289,21 @@ DEFER: an-inline-word
 
 ERROR: custom-error ;
 
-[ T{ effect f 0 0 t } ] [
+[ T{ effect f { } { } t } ] [
     [ custom-error ] infer
 ] unit-test
 
 : funny-throw ( a -- * ) throw ; inline
 
-[ T{ effect f 0 0 t } ] [
+[ T{ effect f { } { } t } ] [
     [ 3 funny-throw ] infer
 ] unit-test
 
-[ T{ effect f 0 0 t } ] [
+[ T{ effect f { } { } t } ] [
     [ custom-error inference-error ] infer
 ] unit-test
 
-[ T{ effect f 1 2 t } ] [
+[ T{ effect f { "x" } { "x" "x" } t } ] [
     [ dup [ 3 throw ] dip ] infer
 ] unit-test
 
@@ -392,5 +392,5 @@ DEFER: eee'
 [ [ call-effect ] infer ] [ T{ unknown-macro-input f call-effect } = ] must-fail-with
 [ [ execute-effect ] infer ] [ T{ unknown-macro-input f execute-effect } = ] must-fail-with
 
-[ \ set-callstack def>> infer ] [ T{ unknown-primitive-error } = ] must-fail-with
-[ ] [ [ \ set-callstack def>> infer ] try ] unit-test
+[ \ set-datastack def>> infer ] [ T{ unknown-primitive-error } = ] must-fail-with
+[ ] [ [ \ set-datastack def>> infer ] try ] unit-test
index fe52357f9ef95d7e9654bd7c796daeb50a61bbc7..12e86609004c992de19e056ff95352967b4d18df 100644 (file)
@@ -1,7 +1,8 @@
-! Copyright (C) 2004, 2009 Slava Pestov.
+! Copyright (C) 2004, 2010 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: kernel io effects namespaces sequences quotations vocabs
-vocabs.loader generic words stack-checker.backend stack-checker.state
+USING: accessors kernel io effects namespaces sequences
+quotations vocabs vocabs.loader generic words
+stack-checker.backend stack-checker.state
 stack-checker.known-words stack-checker.transforms
 stack-checker.errors stack-checker.inlining
 stack-checker.visitor.dummy ;
@@ -15,3 +16,7 @@ M: callable infer ( quot -- effect )
 : infer. ( quot -- )
     #! Safe to call from inference transforms.
     infer effect>string print ;
+
+: inputs ( quot -- n ) infer in>> length ;
+
+: outputs ( quot -- n ) infer out>> length ;
index 1c527abfe49e63eb59f6ae889dd3911fb82049af..f0b595ebe5c2ebfa4f54be0a36f65fa7312ad223 100644 (file)
@@ -1,4 +1,4 @@
-! Copyright (C) 2008 Slava Pestov.
+! Copyright (C) 2008, 2010 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
 USING: assocs arrays namespaces sequences kernel definitions
 math effects accessors words fry classes.algebra
@@ -38,7 +38,9 @@ SYMBOL: literals
 : current-stack-height ( -- n ) meta-d length input-count get - ;
 
 : current-effect ( -- effect )
-    input-count get meta-d length terminated? get effect boa ;
+    input-count get "x" <array>
+    meta-d length "x" <array>
+    terminated? get effect boa ;
 
 : init-inference ( -- )
     terminated? off
index 5f05d97d1a4d1970f3eb75c736f61df467c77a28..871f79d320b949f4ea951e9ec243eb8db9ed76fa 100644 (file)
@@ -1,4 +1,4 @@
-! Copyright (C) 2008 Slava Pestov.
+! Copyright (C) 2008, 2010 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
 USING: stack-checker.visitor kernel ;
 IN: stack-checker.visitor.dummy
@@ -24,4 +24,5 @@ M: f #copy, 2drop ;
 M: f #drop, drop ;
 M: f #alien-invoke, drop ;
 M: f #alien-indirect, drop ;
+M: f #alien-assembly, drop ;
 M: f #alien-callback, drop ;
index 6093cd008af0d077157283e51eae0bb6903cfc1e..d4207caf5bb5396da2d475d7b0f3a2043df8bf0a 100644 (file)
@@ -1,4 +1,4 @@
-! Copyright (C) 2008 Slava Pestov.
+! Copyright (C) 2008, 2010 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
 USING: kernel arrays namespaces ;
 IN: stack-checker.visitor
@@ -29,4 +29,5 @@ HOOK: #recursive, stack-visitor ( label inputs visitor -- )
 HOOK: #copy, stack-visitor ( inputs outputs -- )
 HOOK: #alien-invoke, stack-visitor ( params -- )
 HOOK: #alien-indirect, stack-visitor ( params -- )
+HOOK: #alien-assembly, stack-visitor ( params -- )
 HOOK: #alien-callback, stack-visitor ( params -- )
index 51032264c7ad4c50aafdf4f50e8b02afcd6334c1..19d0051d176a6008fd92b0f955bee142a236adb2 100644 (file)
@@ -1,4 +1,4 @@
-! Copyright (C) 2009 Slava Pestov.
+! Copyright (C) 2009, 2010 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
 USING: kernel sequences fry math.order splitting ;
 IN: strings.tables
@@ -6,7 +6,7 @@ IN: strings.tables
 <PRIVATE
 
 : map-last ( seq quot -- seq )
-    [ dup length <reversed> ] dip '[ 0 = @ ] 2map ; inline
+    [ dup length iota <reversed> ] dip '[ 0 = @ ] 2map ; inline
 
 : max-length ( seq -- n )
     [ length ] [ max ] map-reduce ;
index f486adcb32e27f882289eb4a6b4b567c41706126..134c144fda07442be067257492139cfb21299452 100644 (file)
@@ -7,7 +7,7 @@ IN: suffix-arrays
 <PRIVATE
 
 : suffixes ( string -- suffixes-seq )
-    dup length [ tail-slice ] with map ;
+    dup length iota [ tail-slice ] with map ;
 
 : prefix<=> ( begin seq -- <=> )
     [ <=> ] [ swap head? ] 2bi [ drop +eq+ ] when ;
index 79aad20b856b0e875dbdf222b96b43b530b7de37..4568b7c491c76cf73b077f5ffdd3108107ed076c 100644 (file)
@@ -1,6 +1,6 @@
 USING: namespaces io tools.test threads kernel
 concurrency.combinators concurrency.promises locals math
-words ;
+words calendar sequences ;
 IN: threads.tests
 
 3 "x" set
@@ -20,7 +20,7 @@ yield
 [ f ] [ f get-global ] unit-test
 
 { { 0 3 6 9 12 15 18 21 24 27 } } [
-    10 [
+    10 iota [
         0 "i" tset
         [
             "i" [ yield 3 + ] tchange
@@ -42,3 +42,5 @@ yield
 [ t ] [ spawn-namespace-test ] unit-test
 
 [ "a" [ 1 1 + ] spawn 100 sleep ] must-fail
+
+[ ] [ 0.1 seconds sleep ] unit-test
index 9d1cd29337665b60434c6e1979965b2619a45a92..952652d801dbeeb036e200ef1337694732eb4165 100644 (file)
@@ -21,7 +21,7 @@ mailbox
 variables
 sleep-entry ;
 
-: self ( -- thread ) 63 getenv ; inline
+: self ( -- thread ) 63 special-object ; inline
 
 ! Thread-local storage
 : tnamespace ( -- assoc )
@@ -36,7 +36,7 @@ sleep-entry ;
 : tchange ( key quot -- )
     tnamespace swap change-at ; inline
 
-: threads ( -- assoc ) 64 getenv ;
+: threads ( -- assoc ) 64 special-object ;
 
 : thread ( id -- thread ) threads at ;
 
@@ -61,7 +61,7 @@ ERROR: not-running thread ;
 : unregister-thread ( thread -- )
     check-registered id>> threads delete-at ;
 
-: set-self ( thread -- ) 63 setenv ; inline
+: set-self ( thread -- ) 63 set-special-object ; inline
 
 PRIVATE>
 
@@ -75,9 +75,9 @@ PRIVATE>
 : <thread> ( quot name -- thread )
     \ thread new-thread ;
 
-: run-queue ( -- dlist ) 65 getenv ;
+: run-queue ( -- dlist ) 65 special-object ;
 
-: sleep-queue ( -- heap ) 66 getenv ;
+: sleep-queue ( -- heap ) 66 special-object ;
 
 : resume ( thread -- )
     f >>state
@@ -216,9 +216,9 @@ GENERIC: error-in-thread ( error thread -- )
 <PRIVATE
 
 : init-threads ( -- )
-    H{ } clone 64 setenv
-    <dlist> 65 setenv
-    <min-heap> 66 setenv
+    H{ } clone 64 set-special-object
+    <dlist> 65 set-special-object
+    <min-heap> 66 set-special-object
     initial-thread global
     [ drop [ ] "Initial" <thread> ] cache
     <box> >>continuation
index ea02aa03c9d6327ca0ccc683339cf12d3711aaac..06009992adaac802bb094ed15126a3cf30736b99 100644 (file)
@@ -393,7 +393,7 @@ IN: tools.deploy.shaker
         '[ drop _ member? not ] assoc-filter
         [ drop string? not ] assoc-filter ! strip CLI args
         sift-assoc
-        21 setenv
+        21 set-special-object
     ] [ drop ] if ;
 
 : strip-c-io ( -- )
@@ -518,7 +518,7 @@ SYMBOL: deploy-vocab
     strip-c-io
     strip-default-methods
     strip-compiler-classes
-    f 5 setenv ! we can't use the Factor debugger or Factor I/O anymore
+    f 5 set-special-object ! we can't use the Factor debugger or Factor I/O anymore
     deploy-vocab get vocab-main deploy-startup-quot
     find-megamorphic-caches
     stripped-word-props
index d5c5bd54da5d5692a529f8ca2da9b0249279713f..7bb2f651dc2da794c00c92814f3b3ba460365008 100644 (file)
@@ -17,7 +17,7 @@ IN: cocoa.application
 
 : objc-error ( error -- ) die ;
 
-[ [ die ] 19 setenv ] "cocoa.application" add-startup-hook
+[ [ die ] 19 set-special-object ] "cocoa.application" add-startup-hook
 
 H{ } clone \ pool [
     global [
index f75adcbf04d6944b670346f7813ef0a921b2e819..690103edf5eeb2a0ca8ee22e1c62d805188182ed 100644 (file)
@@ -1,4 +1,4 @@
-! Copyright (C) 2008 Slava Pestov.
+! Copyright (C) 2008, 2010 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
 USING: byte-arrays strings sequences sequences.private ascii
 fry kernel words parser lexer assocs math math.order summary ;
@@ -17,7 +17,7 @@ M: bad-tr summary
     [ [ ascii? ] all? ] both? [ bad-tr ] unless ;
 
 : compute-tr ( quot from to -- mapping )
-    [ 128 ] 3dip zip
+    [ 128 iota ] 3dip zip
     '[ [ _ call( x -- y ) _ at ] keep or ] B{ } map-as ; inline
 
 : tr-hints ( word -- )
index 92e7541616f3507d05075fa5a7ec5d04d38db358..1bc62705247606841eb01af36b34cc9593d375fe 100644 (file)
@@ -10,7 +10,7 @@ IN: tuple-arrays
 
 MACRO: boa-unsafe ( class -- quot ) tuple-layout '[ _ <tuple-boa> ] ;
 
-MACRO: infer-in ( class -- quot ) infer in>> '[ _ ] ;
+MACRO: infer-in ( class -- quot ) inputs '[ _ ] ;
 
 : tuple-arity ( class -- quot ) '[ _ boa ] infer-in ; inline
 
@@ -28,7 +28,7 @@ MACRO: infer-in ( class -- quot ) infer in>> '[ _ ] ;
 
 MACRO: write-tuple ( class -- quot )
     [ '[ [ _ boa ] undo ] ]
-    [ tuple-arity <reversed> [ '[ [ _ ] dip set-nth-unsafe ] ] map '[ _ cleave ] ]
+    [ tuple-arity iota <reversed> [ '[ [ _ ] dip set-nth-unsafe ] ] map '[ _ cleave ] ]
     bi '[ _ dip @ ] ;
 
 PRIVATE>
index d7f77d9e549301c9bd19ce58b763ac47165eda80..ea16abb9bae6ba80697f68042a5e483800086216 100644 (file)
@@ -123,7 +123,7 @@ M: mock-gadget ungraft*
             <mock-gadget> over <model> >>model
             "g" get over add-gadget drop
             swap 1 + number>string set
-        ] each ;
+        ] each-integer ;
 
     : status-flags ( -- seq )
         { "g" "1" "2" "3" } [ get graft-state>> ] map prune ;
index b49f46c05a9e4429533f9a0c4cc8fdcd45f9f743..7ca83ce465c1ba3e6fd8ebb24d661a53f3e15ff7 100644 (file)
@@ -1,14 +1,14 @@
 USING: ui.gadgets.packs ui.gadgets.packs.private
 ui.gadgets.labels ui.gadgets ui.gadgets.debug ui.render
 ui.baseline-alignment kernel namespaces tools.test math.parser
-sequences math.rectangles accessors ;
+sequences math.rectangles accessors math ;
 IN: ui.gadgets.packs.tests
 
 [ t ] [
     { 0 0 } { 100 100 } <rect> clip set
 
     <pile>
-        100 [ number>string <label> add-gadget ] each
+        100 [ number>string <label> add-gadget ] each-integer
     dup layout
 
     visible-children [ label? ] all?
index 01abe8b3d958c0175ee1f81b2a7be511fc65a917..847e14df8a07aba9da31061cfa505085710951ae 100644 (file)
@@ -12,7 +12,7 @@ IN: ui.gadgets.panes.tests
 [ ] [ #children "num-children" set ] unit-test
 
 [ ] [
-    "pane" get <pane-stream> [ 100 [ . ] each ] with-output-stream*
+    "pane" get <pane-stream> [ 100 [ . ] each-integer ] with-output-stream*
 ] unit-test
 
 [ t ] [ #children "num-children" get = ] unit-test
index 5f5cc91846cd1a5649a550ff03b6bd81f0910d14..c89461cd5ab01d218238199692632e35a46c6072 100644 (file)
@@ -70,7 +70,7 @@ dup layout
 "s" set
 
 [ t ] [
-    10 [
+    10 iota [
         drop
         "g2" get scroll>gadget
         "s" get layout
index e49c60a3ed21458d264e0b24abc5c5be21b6bcb3..f1b856949c05024b16b91318d67161504a96d930 100644 (file)
@@ -1,4 +1,4 @@
 IN: ui.gadgets.slots.tests
 USING: assocs ui.gadgets.slots tools.test refs ;
 
-[ t ] [ [ ] [ ] { 1 2 3 } 2 <value-ref> <slot-editor> slot-editor? ] unit-test
+[ t ] [ [ ] [ ] { { 1 1 } { 2 2 } { 3 3 } } 2 <value-ref> <slot-editor> slot-editor? ] unit-test
index 63134b3c8e6a91026031f9430b08f8ebf1a07f5a..22802d39aee565d29a34af5f8e8843fd669cc3f0 100644 (file)
@@ -1,4 +1,24 @@
-! Copyright (C) 2009 Slava Pestov.
-! See http://factorcode.org/license.txt for BSD license.
-USING: tools.test ui.pens.gradient ;
+USING: tools.test ui.pens.gradient ui.pens.gradient.private
+colors.constants specialized-arrays alien.c-types ;
+SPECIALIZED-ARRAY: float
 IN: ui.pens.gradient.tests
+
+[
+    float-array{
+        0.0
+        0.0
+        0.0
+        100.0
+        50.0
+        0.0
+        50.0
+        100.0
+        100.0
+        0.0
+        100.0
+        100.0
+    }
+] [
+    { 1 0 } { 100 100 } { COLOR: red COLOR: green COLOR: blue }
+    gradient-vertices
+] unit-test
index 7f7bd02204884598504d9fc1644108186b3adec8..fbf190a218fcf4a7e5d22495a4d906c4368e0167 100644 (file)
@@ -16,7 +16,7 @@ TUPLE: gradient < caching-pen colors last-vertices last-colors ;
 
 :: gradient-vertices ( direction dim colors -- seq )
     direction dim v* dim over v- swap
-    colors length dup 1 - v/n [ v*n ] with map
+    colors length [ iota ] [ 1 - ] bi v/n [ v*n ] with map
     swap [ over v+ 2array ] curry map
     concat concat >float-array ;
 
index bbce857681bd17540a928ce624a8eff2ffae4fd5..0311b43474860111105d812f62fe4b5eec0c9f97 100644 (file)
@@ -27,7 +27,12 @@ IN: unicode.breaks.tests
     utf8 file-lines
     [ "#" split1 drop ] map harvest [
         "÷" split
-        [ "×" split [ [ blank? ] trim hex> ] map harvest >string ] map
+        [
+            "×" split
+            [ [ blank? ] trim hex> ] map
+            [ { f 0 } member? not ] filter
+            >string
+        ] map
         harvest
     ] map ;
 
@@ -46,4 +51,4 @@ IN: unicode.breaks.tests
 grapheme-break-test parse-test-file [ >graphemes ] test
 word-break-test parse-test-file [ >words ] test
 
-[ { t f t t f t } ] [ 6 [ "as df" word-break-at? ] map ] unit-test
+[ { t f t t f t } ] [ 6 iota [ "as df" word-break-at? ] map ] unit-test
index 7c7b8a1f50771499672eb752680021570141ccd4..46651bd7de8c1f2a345c7dc742e115d3f403ce95 100644 (file)
@@ -74,14 +74,14 @@ SYMBOL: table
   
 : make-grapheme-table ( -- )
     { CR } { LF } connect
-    { Control CR LF } graphemes disconnect
-    graphemes { Control CR LF } disconnect
+    { Control CR LF } graphemes iota disconnect
+    graphemes iota { Control CR LF } disconnect
     { L } { L V LV LVT } connect
     { LV V } { V T } connect
     { LVT T } { T } connect
-    graphemes { Extend } connect
-    graphemes { SpacingMark } connect
-    { Prepend } graphemes connect ;
+    graphemes iota { Extend } connect
+    graphemes iota { SpacingMark } connect
+    { Prepend } graphemes iota connect ;
 
 VALUE: grapheme-table
 
@@ -154,8 +154,8 @@ SYMBOL: check-number-after
 
 : make-word-table ( -- )
     { wCR } { wLF } connect
-    { wNewline wCR wLF } words disconnect
-    words { wNewline wCR wLF } disconnect
+    { wNewline wCR wLF } words iota disconnect
+    words iota { wNewline wCR wLF } disconnect
     { wALetter } { wMidLetter wMidNumLet } check-letter-after set-table
     { wMidLetter wMidNumLet } { wALetter } check-letter-before set-table
     { wNumeric wALetter } { wNumeric wALetter } connect
@@ -252,7 +252,7 @@ PRIVATE>
     over tail-slice first-word + ;
 
 : last-word ( str -- i )
-    [ length ] keep '[ _ word-break-at? ] find-last drop 0 or ;
+    [ length iota ] keep '[ _ word-break-at? ] find-last drop 0 or ;
 
 : last-word-from ( end str -- i )
     swap head-slice last-word ;
index ea0487c703525e8c9b311ebdf8f7e5484e3ca269..dc3cd89b51097f5b6cfcdd50a486b444e512d1b5 100644 (file)
@@ -82,7 +82,7 @@ ducet insert-helpers
 \r
 : add ( char -- )\r
     dup blocked? [ 1string , ] [\r
-        dup possible-bases dup length\r
+        dup possible-bases dup length iota\r
         [ ?combine ] with with any?\r
         [ drop ] [ 1string , ] if\r
     ] if ;\r
index 1c6c6afdf35711473774469afc0cc9e116e0a907..24dfba6be02dab57ec4a1f89bd091c22d67b7529 100644 (file)
@@ -108,7 +108,8 @@ PRIVATE>
 
 : exclusions ( -- set )
     exclusions-file utf8 file-lines
-    [ "#" split1 drop [ blank? ] trim-tail hex> ] map harvest ;
+    [ "#" split1 drop [ blank? ] trim-tail hex> ] map
+    [ 0 = not ] filter ;
 
 : remove-exclusions ( alist -- alist )
     exclusions [ dup ] H{ } map>assoc assoc-diff ;
index a672c850d29914a8cacab1b40dc4d371e0e7b243..e9cb9d59188aca5fc0ab8a95a883df54fffe770f 100644 (file)
@@ -1,11 +1,11 @@
-! Copyright (C) 2005, 2008 Slava Pestov.
+! Copyright (C) 2005, 2010 Slava Pestov.
 ! Copyright (C) 2008 Eduardo Cavazos.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: alien alien.c-types alien.syntax kernel libc
-sequences continuations byte-arrays strings math namespaces
-system combinators vocabs.loader accessors
-stack-checker macros locals generalizations unix.types
-io vocabs classes.struct unix.time alien.libraries ;
+USING: alien alien.c-types alien.syntax kernel libc sequences
+continuations byte-arrays strings math namespaces system
+combinators combinators.smart vocabs.loader accessors
+stack-checker macros locals generalizations unix.types io vocabs
+classes.struct unix.time alien.libraries ;
 IN: unix
 
 CONSTANT: PROT_NONE   0
@@ -48,7 +48,7 @@ ERROR: unix-error errno message ;
 ERROR: unix-system-call-error args errno message word ;
 
 MACRO:: unix-system-call ( quot -- )
-    quot infer in>> :> n
+    quot inputs :> n
     quot first :> word
     [
         n ndup quot call dup 0 < [
index 89eb1cdebd48a923595818bfee3d8194d601ea93..8eadfb9cbfebff667807a7980f124ea31858522a 100644 (file)
@@ -1,5 +1,5 @@
 USING: unrolled-lists tools.test deques kernel sequences
-random prettyprint grouping ;
+random prettyprint grouping math ;
 IN: unrolled-lists.tests
 
 [ 1 ] [ <unrolled-list> 1 over push-front pop-front ] unit-test
@@ -35,14 +35,14 @@ IN: unrolled-lists.tests
 
 [ { 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 } ] [
     <unrolled-list>
-    32 [ over push-front ] each
+    32 [ over push-front ] each-integer
     32 [ dup pop-back ] replicate
     nip
 ] unit-test
 
 [ { 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 } ] [
     <unrolled-list>
-    32 [ over push-front ] each
+    32 [ over push-front ] each-integer
     32 [ dup pop-front ] replicate reverse
     nip
 ] unit-test
@@ -51,7 +51,7 @@ IN: unrolled-lists.tests
     <unrolled-list>
     1000 [ 1000 random ] replicate
     [ [ over push-front ] each ]
-    [ [ dup pop-back ] replicate ]
+    [ length [ dup pop-back ] replicate ]
     [ ]
     tri
     =
@@ -64,7 +64,7 @@ IN: unrolled-lists.tests
     [
         10 group [
             [ [ over push-front ] each ]
-            [ [ dup pop-back ] replicate ]
+            [ length [ dup pop-back ] replicate ]
             bi 
         ] map concat
     ] keep
index 278296c4d049b3b98da5429887f5af0951f0c9bb..cc4a291a8b089922fda2dd93bb77174c2e827e1d 100644 (file)
@@ -1,4 +1,4 @@
-! Copyright (C) 2009 Phil Dawes.
+! Copyright (C) 2009, 2010 Phil Dawes, Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
 USING: classes.struct alien.c-types alien.syntax ;
 IN: vm
@@ -9,7 +9,7 @@ STRUCT: context
 { callstack-top void* }
 { callstack-bottom void* }
 { datastack cell }
-{ callstack cell }
+{ retainstack cell }
 { magic-frame void* }
 { datastack-region void* }
 { retainstack-region void* }
@@ -30,7 +30,7 @@ STRUCT: vm
 { nursery zone }
 { cards-offset cell }
 { decks-offset cell }
-{ userenv cell[70] } ;
+{ special-objects cell[70] } ;
 
 : vm-field-offset ( field -- offset ) vm offset-of ; inline
 
index dfe12aaf3c21e7147e017400933ac2f33e2c4cbe..904c85200e583509959a70edf683461f5815ed8f 100644 (file)
@@ -8,8 +8,7 @@ IN: windows.time
 : >64bit ( lo hi -- n )
     32 shift bitor ; inline
 
-: windows-1601 ( -- timestamp )
-    1601 1 1 0 0 0 instant <timestamp> ;
+: windows-1601 ( -- timestamp ) 1601 <year-gmt> ;
 
 : FILETIME>windows-time ( FILETIME -- n )
     [ dwLowDateTime>> ] [ dwHighDateTime>> ] bi >64bit ;
index 55b5147abba72a48b0bbddc5bb3e719e4a0e0de1..2cbc5890b16da57b5239cb54b7918889532f6da1 100644 (file)
@@ -1,6 +1,7 @@
-USING: accessors assocs combinators continuations fry generalizations
-io.pathnames kernel macros sequences stack-checker tools.test xml
-xml.traversal xml.writer arrays xml.data ; 
+USING: accessors assocs combinators combinators.smart
+continuations fry generalizations io.pathnames kernel macros
+sequences stack-checker tools.test xml xml.traversal xml.writer
+arrays xml.data ;
 IN: xml.tests.suite
 
 TUPLE: xml-test id uri sections description type ;
@@ -19,14 +20,11 @@ TUPLE: xml-test id uri sections description type ;
 
 CONSTANT: base "vocab:xml/tests/xmltest/"
 
-MACRO: drop-output ( quot -- newquot )
-    dup infer out>> '[ @ _ ndrop ] ;
-
-MACRO: drop-input ( quot -- newquot )
-    infer in>> '[ _ ndrop ] ;
+MACRO: drop-inputs ( quot -- newquot )
+    inputs '[ _ ndrop ] ;
 
 : fails? ( quot -- ? )
-    [ drop-output f ] [ nip drop-input t ] bi-curry recover ; inline
+    [ drop-outputs f ] [ nip drop-inputs t ] bi-curry recover ; inline
 
 : well-formed? ( uri -- answer )
     [ file>xml ] fails? "not-wf" "valid" ? ;
index beb5983b5a61ce1f1158736e3bd0212b6de9f60d..ef8420d66c8012199bf001a55c9069ad63749e87 100644 (file)
@@ -95,7 +95,7 @@ HINTS: next* { spot } ;
     get-char [ missing-close ] unless next ;
 
 : expect ( string -- )
-    dup spot get '[ _ [ char>> ] keep next* ] replicate
+    dup length spot get '[ _ [ char>> ] keep next* ] "" replicate-as
     2dup = [ 2drop ] [ expected ] if ;
 
 ! Suddenly XML-specific
index d54f9d8a7752df8c93e3ce44780323e030c7b054..c2775f435afb114d67af0f1123ce340f46a7237c 100755 (executable)
@@ -11,7 +11,7 @@ ECHO=echo
 OS=
 ARCH=
 WORD=
-NO_UI=
+NO_UI=${NO_UI-}
 GIT_PROTOCOL=${GIT_PROTOCOL:="git"}
 GIT_URL=${GIT_URL:=$GIT_PROTOCOL"://factorcode.org/git/factor.git"}
 SCRIPT_ARGS="$*"
@@ -25,9 +25,9 @@ test_program_installed() {
 
 exit_script() {
     if [[ $FIND_MAKE_TARGET -eq true ]] ; then
-               echo $MAKE_TARGET;
-       fi
-       exit $1
+        echo $MAKE_TARGET;
+    fi
+    exit $1
 }
 
 ensure_program_installed() {
@@ -132,9 +132,11 @@ check_library_exists() {
 }
 
 check_X11_libraries() {
-    check_library_exists GL
-    check_library_exists X11
-    check_library_exists pango-1.0
+    if [ -z "$NO_UI" ]; then
+        check_library_exists GL
+        check_library_exists X11
+        check_library_exists pango-1.0
+    fi
 }
 
 check_libraries() {
@@ -345,8 +347,8 @@ update_script_name() {
 
 update_script() {
     update_script=`update_script_name`
-    
-    echo "#!/bin/sh" >"$update_script"
+    bash_path=`which bash`
+    echo "#!$bash_path" >"$update_script"
     echo "git pull \"$GIT_URL\" master" >>"$update_script"
     echo "if [[ \$? -eq 0 ]]; then exec \"$0\" $SCRIPT_ARGS; else echo \"git pull failed\"; exit 2; fi" \
         >>"$update_script"
@@ -431,7 +433,7 @@ make_factor() {
 update_boot_images() {
     echo "Deleting old images..."
     $DELETE checksums.txt* > /dev/null 2>&1
-       # delete boot images with one or two characters after the dot
+    # delete boot images with one or two characters after the dot
     $DELETE $BOOT_IMAGE.{?,??} > /dev/null 2>&1
     $DELETE temp/staging.*.image > /dev/null 2>&1
     if [[ -f $BOOT_IMAGE ]] ; then
index 6787d3714b4f5f34cfebc62506639e92d697e33d..98292b8728b4b6ee2a190716c5c98b81ee83f340 100644 (file)
@@ -1,7 +1,7 @@
 USING: byte-arrays arrays help.syntax help.markup
 alien.syntax compiler definitions math libc eval
 debugger parser io io.backend system alien.accessors
-alien.libraries ;
+alien.libraries alien.c-types quotations ;
 IN: alien
 
 HELP: alien
@@ -44,17 +44,26 @@ HELP: <alien>
 HELP: c-ptr
 { $class-description "Class of objects consisting of aliens, byte arrays and " { $link f } ". These objects can convert to pointer C types, which are all aliases of " { $snippet "void*" } "." } ;
 
+HELP: alien-invoke-error
+{ $error-description "Thrown if the word calling " { $link alien-invoke } " was not compiled with the optimizing compiler. This may be a result of one of several failure conditions:"
+    { $list
+        { "This can happen when experimenting with " { $link alien-invoke } " in this listener. To fix the problem, place the " { $link alien-invoke } " call in a word; word definitions are automatically compiled with the optimizing compiler." }
+        { "The return type or parameter list references an unknown C type." }
+        { "The symbol or library could not be found." }
+        { "One of the four inputs to " { $link alien-invoke } " is not a literal value. To call functions which are not known at compile-time, use " { $link alien-indirect } "." }
+    }
+} ;
+
 HELP: alien-invoke
 { $values { "..." "zero or more objects passed to the C function" } { "return" "a C return type" } { "library" "a logical library name" } { "function" "a C function name" } { "parameters" "a sequence of C parameter types" } }
-{ $description "Calls a C library function with the given name. Input parameters are taken from the data stack, and the return value is pushed on the data stack after the function returns. A return type of " { $snippet "\"void\"" } " indicates that no value is to be expected." }
+{ $description "Calls a C library function with the given name. Input parameters are taken from the data stack, and the return value is pushed on the data stack after the function returns. A return type of " { $link void } " indicates that no value is to be expected." }
 { $notes "C type names are documented in " { $link "c-types-specs" } "." }
 { $errors "Throws an " { $link alien-invoke-error } " if the word calling " { $link alien-invoke } " was not compiled with the optimizing compiler." } ;
 
 HELP: alien-indirect-error
-{ $error-description "Thrown if the word calling " { $link alien-indirect } " was not compiled with the optimizing compiler. This may be a result of one of several failure conditions:"
+{ $error-description "Thrown if the word calling " { $link alien-indirect } " was not compiled with the optimizing compiler. This may be a result of one of two failure conditions:"
     { $list
         { "This can happen when experimenting with " { $link alien-indirect } " in this listener. To fix the problem, place the " { $link alien-indirect } " call in a word; word definitions are automatically compiled with the optimizing compiler." }
-        { "The return type or parameter list references an unknown C type." }
         { "One of the three inputs to " { $link alien-indirect } " is not a literal value." }
     }
 } ;
@@ -62,22 +71,21 @@ HELP: alien-indirect-error
 HELP: alien-indirect
 { $values { "..." "zero or more objects passed to the C function" } { "funcptr" "a C function pointer" } { "return" "a C return type" } { "parameters" "a sequence of C parameter types" } { "abi" "one of " { $snippet "\"cdecl\"" } " or " { $snippet "\"stdcall\"" } } }
 { $description
-    "Invokes a C function pointer passed on the data stack. Input parameters are taken from the data stack following the function pointer, and the return value is pushed on the data stack after the function returns. A return type of " { $snippet "\"void\"" } " indicates that no value is to be expected."
+    "Invokes a C function pointer passed on the data stack. Input parameters are taken from the data stack following the function pointer, and the return value is pushed on the data stack after the function returns. A return type of " { $link void } " indicates that no value is to be expected."
 }
 { $notes "C type names are documented in " { $link "c-types-specs" } "." }
 { $errors "Throws an " { $link alien-indirect-error } " if the word calling " { $link alien-indirect } " is not compiled." } ;
 
 HELP: alien-callback-error
-{ $error-description "Thrown if the word calling " { $link alien-callback } " was not compiled with the optimizing compiler. This may be a result of one of several failure conditions:"
+{ $error-description "Thrown if the word calling " { $link alien-callback } " was not compiled with the optimizing compiler. This may be a result of one of two failure conditions:"
     { $list
         { "This can happen when experimenting with " { $link alien-callback } " in this listener. To fix the problem, place the " { $link alien-callback } " call in a word; word definitions are automatically compiled with the optimizing compiler." }
-        { "The return type or parameter list references an unknown C type." }
         { "One of the four inputs to " { $link alien-callback } " is not a literal value." }
     }
 } ;
 
 HELP: alien-callback
-{ $values { "return" "a C return type" } { "parameters" "a sequence of C parameter types" } { "abi" "one of " { $snippet "\"cdecl\"" } " or " { $snippet "\"stdcall\"" } } { "quot" "a quotation" } { "alien" alien } }
+{ $values { "return" "a C return type" } { "parameters" "a sequence of C parameter types" } { "abi" "one of " { $snippet "\"cdecl\"" } " or " { $snippet "\"stdcall\"" } } { "quot" quotation } { "alien" alien } }
 { $description
     "Defines a callback from C to Factor which accepts the given set of parameters from the C caller, pushes them on the data stack, calls the quotation, and passes a return value back to the C caller. A return type of " { $snippet "void" } " indicates that no value is to be returned."
     $nl
@@ -95,7 +103,23 @@ HELP: alien-callback
 }
 { $errors "Throws an " { $link alien-callback-error } " if the word calling " { $link alien-callback } " is not compiled." } ;
 
-{ alien-invoke alien-indirect alien-callback } related-words
+HELP: alien-assembly-error
+{ $error-description "Thrown if the word calling " { $link alien-assembly } " was not compiled with the optimizing compiler. This may be a result of one of two failure conditions:"
+    { $list
+        { "This can happen when experimenting with " { $link alien-assembly } " in this listener. To fix the problem, place the " { $link alien-assembly } " call in a word; word definitions are automatically compiled with the optimizing compiler." }
+        { "One of the four inputs to " { $link alien-assembly } " is not a literal value." }
+    }
+} ;
+
+HELP: alien-assembly
+{ $values { "..." "zero or more objects passed to the C function" } { "return" "a C return type" } { "parameters" "a sequence of C parameter types" } { "abi" "one of " { $snippet "\"cdecl\"" } " or " { $snippet "\"stdcall\"" } } { "quot" quotation } }
+{ $description
+    "Invokes arbitrary machine code, generated at compile-time by the quotation. Input parameters are taken from the data stack, and the return value is pushed on the data stack after the function returns. A return type of " { $link void } " indicates that no value is to be expected."
+}
+{ $notes "C type names are documented in " { $link "c-types-specs" } "." }
+{ $errors "Throws an " { $link alien-assembly-error } " if the word calling " { $link alien-assembly } " is not compiled." } ;
+
+{ alien-invoke alien-indirect alien-assembly alien-callback } related-words
 
 ARTICLE: "alien-expiry" "Alien expiry"
 "When an image is loaded, any alien objects which persisted from the previous session are marked as having expired. This is because the C pointers they contain are almost certainly no longer valid."
@@ -165,16 +189,6 @@ ARTICLE: "alien-invoke" "Calling C from Factor"
 { $subsections alien-indirect }
 "There are some details concerning the conversion of Factor objects to C values, and vice versa. See " { $link "c-data" } "." ;
 
-HELP: alien-invoke-error
-{ $error-description "Thrown if the word calling " { $link alien-invoke } " was not compiled with the optimizing compiler. This may be a result of one of several failure conditions:"
-    { $list
-        { "This can happen when experimenting with " { $link alien-invoke } " in this listener. To fix the problem, place the " { $link alien-invoke } " call in a word; word definitions are automatically compiled with the optimizing compiler." }
-        { "The return type or parameter list references an unknown C type." }
-        { "The symbol or library could not be found." }
-        { "One of the four inputs to " { $link alien-invoke } " is not a literal value. To call functions which are not known at compile-time, use " { $link alien-indirect } "." }
-    }
-} ;
-
 ARTICLE: "alien-callback" "Calling Factor from C"
 "Callbacks can be defined and passed to C code as function pointers; the C code can then invoke the callback and run Factor code:"
 { $subsections
@@ -191,6 +205,18 @@ ARTICLE: "alien-globals" "Accessing C global variables"
     POSTPONE: &:
 } ;
 
+ARTICLE: "alien-assembly" "Calling arbitrary assembly code"
+"It is possible to write a word whose body consists of arbitrary assembly code. The assembly receives parameters and returns values as per the platform's ABI; marshalling and unmarshalling Factor values is taken care of by the C library interface, as with " { $link alien-invoke } "."
+$nl
+"Assembler opcodes are defined in CPU-specific vocabularies:"
+{ $list
+    { $vocab-link "cpu.arm.assembler" }
+    { $vocab-link "cpu.ppc.assembler" }
+    { $vocab-link "cpu.x86.assembler" }
+}
+"The combinator for generating arbitrary assembly by calling a quotation at compile time:"
+{ $subsection alien-assembly } ;
+
 ARTICLE: "dll.private" "DLL handles"
 "DLL handles are a built-in class of objects which represent loaded native libraries. DLL handles are instances of the " { $link dll } " class, and have a literal syntax used for debugging prinouts; see " { $link "syntax-aliens" } "."
 $nl
@@ -281,6 +307,7 @@ $nl
     "c-data"
     "classes.struct"
     "alien-globals"
+    "alien-assembly"
     "dll.private"
     "embedding"
 } ;
index 91dd150e8f14f0924754fb57ae64e640734bc763..16c33fc1c33ea773b3e2c4194fd81c52299148ec 100644 (file)
@@ -1,4 +1,4 @@
-! Copyright (C) 2004, 2009 Slava Pestov.
+! Copyright (C) 2004, 2010 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
 USING: accessors assocs kernel math namespaces sequences system
 kernel.private byte-arrays arrays init ;
@@ -49,7 +49,7 @@ ERROR: alien-callback-error ;
 
 ERROR: alien-indirect-error ;
 
-: alien-indirect ( ... funcptr return parameters abi -- )
+: alien-indirect ( ... funcptr return parameters abi -- ... )
     alien-indirect-error ;
 
 ERROR: alien-invoke-error library symbol ;
@@ -57,6 +57,11 @@ ERROR: alien-invoke-error library symbol ;
 : alien-invoke ( ... return library function parameters -- ... )
     2over alien-invoke-error ;
 
+ERROR: alien-assembly-error code ;
+
+: alien-assembly ( ... return parameters abi quot -- ... )
+    dup alien-assembly-error ;
+
 ! Callbacks are registered in a global hashtable. Note that they
 ! are also pinned in a special callback area, so clearing this
 ! hashtable will not reclaim callbacks. It should only be
index 8e09fa8c2c24ea6b9563d37be834d49602c5df7f..15e0370ba081daa8f2ed53b25bf5da83e81920fb 100644 (file)
@@ -67,6 +67,6 @@ M: string string>symbol string>symbol* ;
 M: sequence string>symbol [ string>symbol* ] map ;
 
 [
-    8 getenv utf8 alien>string string>cpu \ cpu set-global
-    9 getenv utf8 alien>string string>os \ os set-global
+    8 special-object utf8 alien>string string>cpu \ cpu set-global
+    9 special-object utf8 alien>string string>os \ os set-global
 ] "alien.strings" add-startup-hook
index e441855ed1929ba011a029a72004d257dcddcf9c..7b50d7c443232d3943f0c6c7be56d8f3d6bb0e45 100644 (file)
@@ -1,4 +1,4 @@
-! Copyright (C) 2007, 2009 Daniel Ehrenberg, Slava Pestov
+! Copyright (C) 2007, 2010 Daniel Ehrenberg, Slava Pestov
 ! See http://factorcode.org/license.txt for BSD license.
 USING: kernel sequences arrays math sequences.private vectors
 accessors ;
@@ -225,7 +225,7 @@ M: enum set-at seq>> set-nth ; inline
 M: enum delete-at seq>> remove-nth! drop ; inline
 
 M: enum >alist ( enum -- alist )
-    seq>> [ length ] keep zip ; inline
+    seq>> [ length iota ] keep zip ; inline
 
 M: enum assoc-size seq>> length ; inline
 
index ac1f4fad69a6744389701c9530940f87d0b85741..2a791bf42dae9db130e23c39802c9e4423b1f2df 100644 (file)
@@ -312,27 +312,9 @@ tuple
     [ create dup 1quotation ] dip define-declared ;
 
 {
-    { "(execute)" "kernel.private" (( word -- )) }
-    { "(call)" "kernel.private" (( quot -- )) }
-    { "both-fixnums?" "math.private" (( x y -- ? )) }
-    { "fixnum+fast" "math.private" (( x y -- z )) }
-    { "fixnum-fast" "math.private" (( x y -- z )) }
-    { "fixnum*fast" "math.private" (( x y -- z )) }
-    { "fixnum-bitand" "math.private" (( x y -- z )) }
-    { "fixnum-bitor" "math.private" (( x y -- z )) }
-    { "fixnum-bitxor" "math.private" (( x y -- z )) }
-    { "fixnum-bitnot" "math.private" (( x -- y )) }
-    { "fixnum-mod" "math.private" (( x y -- z )) }
-    { "fixnum-shift-fast" "math.private" (( x y -- z )) }
-    { "fixnum/i-fast" "math.private" (( x y -- z )) }
-    { "fixnum/mod-fast" "math.private" (( x y -- z w )) }
-    { "fixnum+" "math.private" (( x y -- z )) }
-    { "fixnum-" "math.private" (( x y -- z )) }
-    { "fixnum*" "math.private" (( x y -- z )) }
-    { "fixnum<" "math.private" (( x y -- ? )) }
-    { "fixnum<=" "math.private" (( x y -- z )) }
-    { "fixnum>" "math.private" (( x y -- ? )) }
-    { "fixnum>=" "math.private" (( x y -- ? )) }
+    { "mega-cache-lookup" "generic.single.private" (( methods index cache -- )) }
+    { "inline-cache-miss" "generic.single.private" (( generic methods index cache -- )) }
+    { "inline-cache-miss-tail" "generic.single.private" (( generic methods index cache -- )) }
     { "drop" "kernel" (( x -- )) }
     { "2drop" "kernel" (( x y -- )) }
     { "3drop" "kernel" (( x y z -- )) }
@@ -350,13 +332,35 @@ tuple
     { "swap" "kernel" (( x y -- y x )) }
     { "eq?" "kernel" (( obj1 obj2 -- ? )) }
     { "tag" "kernel.private" (( object -- n )) }
+    { "(execute)" "kernel.private" (( word -- )) }
+    { "(call)" "kernel.private" (( quot -- )) }
+    { "unwind-native-frames" "kernel.private" (( -- )) }
+    { "set-callstack" "kernel.private" (( cs -- * )) }
+    { "lazy-jit-compile" "kernel.private" (( -- )) }
+    { "c-to-factor" "kernel.private" (( -- )) }
     { "slot" "slots.private" (( obj m -- value )) }
     { "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 -- )) }
-    { "inline-cache-miss" "generic.single.private" (( generic methods index cache -- )) }
-    { "inline-cache-miss-tail" "generic.single.private" (( generic methods index cache -- )) }
+    { "both-fixnums?" "math.private" (( x y -- ? )) }
+    { "fixnum+fast" "math.private" (( x y -- z )) }
+    { "fixnum-fast" "math.private" (( x y -- z )) }
+    { "fixnum*fast" "math.private" (( x y -- z )) }
+    { "fixnum-bitand" "math.private" (( x y -- z )) }
+    { "fixnum-bitor" "math.private" (( x y -- z )) }
+    { "fixnum-bitxor" "math.private" (( x y -- z )) }
+    { "fixnum-bitnot" "math.private" (( x -- y )) }
+    { "fixnum-mod" "math.private" (( x y -- z )) }
+    { "fixnum-shift-fast" "math.private" (( x y -- z )) }
+    { "fixnum/i-fast" "math.private" (( x y -- z )) }
+    { "fixnum/mod-fast" "math.private" (( x y -- z w )) }
+    { "fixnum+" "math.private" (( x y -- z )) }
+    { "fixnum-" "math.private" (( x y -- z )) }
+    { "fixnum*" "math.private" (( x y -- z )) }
+    { "fixnum<" "math.private" (( x y -- ? )) }
+    { "fixnum<=" "math.private" (( x y -- z )) }
+    { "fixnum>" "math.private" (( x y -- ? )) }
+    { "fixnum>=" "math.private" (( x y -- ? )) }
 } [ first3 make-sub-primitive ] each
 
 ! Primitive words
@@ -417,8 +421,8 @@ tuple
     { "float-u>=" "math.private" (( x y -- ? )) }
     { "(word)" "words.private" (( name vocab -- word )) }
     { "word-xt" "words" (( word -- start end )) }
-    { "getenv" "kernel.private" (( n -- obj )) }
-    { "setenv" "kernel.private" (( obj n -- )) }
+    { "special-object" "kernel.private" (( n -- obj )) }
+    { "set-special-object" "kernel.private" (( obj n -- )) }
     { "(exists?)" "io.files.private" (( path -- ? )) }
     { "minor-gc" "memory" (( -- )) }
     { "gc" "memory" (( -- )) }
@@ -428,9 +432,8 @@ tuple
     { "datastack" "kernel" (( -- ds )) }
     { "retainstack" "kernel" (( -- rs )) }
     { "callstack" "kernel" (( -- cs )) }
-    { "set-datastack" "kernel" (( ds -- )) }
-    { "set-retainstack" "kernel" (( rs -- )) }
-    { "set-callstack" "kernel" (( cs -- * )) }
+    { "set-datastack" "kernel.private" (( ds -- )) }
+    { "set-retainstack" "kernel.private" (( rs -- )) }
     { "(exit)" "system" (( n -- )) }
     { "data-room" "memory" (( -- data-room )) }
     { "code-room" "memory" (( -- code-room )) }
index fdf4ab6aca99c6c4600a20d76ae80abbf36d5b14..286b7c419e101749edc59c51ca2b838c9157aa36 100644 (file)
@@ -1,11 +1,11 @@
 USING: tools.test byte-vectors vectors sequences kernel\r
-prettyprint ;\r
+prettyprint math ;\r
 IN: byte-vectors.tests\r
 \r
 [ 0 ] [ 123 <byte-vector> length ] unit-test\r
 \r
 : do-it ( seq -- seq )\r
-    123 [ over push ] each ;\r
+    123 [ over push ] each-integer ;\r
 \r
 [ t ] [\r
     3 <byte-vector> do-it\r
index c016b0169bf22808088a86abbd700c94c738fa78..11cb11d334c4f692e1d9789ee96f4d58969c54dc 100644 (file)
@@ -206,7 +206,6 @@ INSTANCE: union-with-one-member mixin-with-one-member
 \r
 ! class<=>\r
 \r
-[ +lt+ ] [ integer sequence class<=> ] unit-test\r
 [ +lt+ ] [ sequence object class<=> ] unit-test\r
 [ +gt+ ] [ object sequence class<=> ] unit-test\r
 [ +eq+ ] [ integer integer class<=> ] unit-test\r
@@ -266,7 +265,7 @@ INSTANCE: union-with-one-member mixin-with-one-member
 10 [\r
     [ ] [\r
         20 [ random-op ] [ ] replicate-as\r
-        [ infer in>> [ random-class ] times ] keep\r
+        [ infer in>> length [ random-class ] times ] keep\r
         call\r
         drop\r
     ] unit-test\r
@@ -300,7 +299,7 @@ INSTANCE: union-with-one-member mixin-with-one-member
 20 [\r
     [ t ] [\r
         20 [ random-boolean-op ] [ ] replicate-as dup .\r
-        [ infer in>> [ random-boolean ] replicate dup . ] keep\r
+        [ infer in>> length [ random-boolean ] replicate dup . ] keep\r
         \r
         [ [ [ ] each ] dip call ] 2keep\r
         \r
index 2bef1a568a1b3dd99d6b350aa56cb56e11a56963..55cc55c3341a315882fe22884ab8f2e29f857a29 100644 (file)
@@ -11,7 +11,9 @@ IN: combinators
 
 : execute-effect-unsafe ( word effect -- ) drop execute ;
 
-M: object throw 5 getenv [ die ] or (( error -- * )) call-effect-unsafe ;
+M: object throw
+    5 special-object [ die ] or
+    (( error -- * )) call-effect-unsafe ;
 
 PRIVATE>
 
index eccc292f26b94155a9b89b87d9b31ce7efa5b2fe..48c3b6891c526bec3b5177d3eeea7859a4bfa1e4 100644 (file)
@@ -1,5 +1,5 @@
 USING: compiler definitions compiler.units tools.test arrays sequences words kernel
-accessors namespaces fry eval ;
+accessors namespaces fry eval quotations math ;
 IN: compiler.units.tests
 
 [ [ [ ] define-temp ] with-compilation-unit ] must-infer
@@ -56,3 +56,16 @@ DEFER: nesting-test
 [ ] [ "IN: compiler.units.tests << : nesting-test ( -- ) ; >>" eval( -- ) ] unit-test
 
 observer remove-definition-observer
+
+! Make sure that non-optimized calls to a generic word which
+! hasn't been compiled yet work properly
+GENERIC: uncompiled-generic-test ( a -- b )
+
+M: integer uncompiled-generic-test 1 + ;
+
+<< [ uncompiled-generic-test ] [ jit-compile ] [ suffix! ] bi >>
+"q" set
+
+[ 4 ] [ 3 "q" get call ] unit-test
+
+[ ] [ [ \ uncompiled-generic-test forget ] with-compilation-unit ] unit-test
index 996a6e9bd46b828f8b1dcef0719bde219285209d..a64080e510afce7f0a888dcc1acf196d9efe3c29 100644 (file)
@@ -100,7 +100,7 @@ GENERIC: definitions-changed ( assoc obj -- )
 ! Incremented each time stack effects potentially changed, used
 ! by compiler.tree.propagation.call-effect for call( and execute(
 ! inline caching
-: effect-counter ( -- n ) 47 getenv ; inline
+: effect-counter ( -- n ) 47 special-object ; inline
 
 GENERIC: bump-effect-counter* ( defspec -- ? )
 
@@ -132,7 +132,11 @@ M: object bump-effect-counter* drop f ;
     or ;
 
 : bump-effect-counter ( -- )
-    bump-effect-counter? [ 47 getenv 0 or 1 + 47 setenv ] when ;
+    bump-effect-counter? [
+        47 special-object 0 or
+        1 +
+        47 set-special-object
+    ] when ;
 
 : notify-observers ( -- )
     updated-definitions dup assoc-empty?
index a2617d0ebbfda4df8da27e91fde0b5f9e167a1f9..988be0dd88a6bf3c5257cec15fed13fbec127cd3 100644 (file)
@@ -22,7 +22,7 @@ IN: continuations.tests
         ] with-scope
     ] callcc0 "x" get 5 = ;
 
-[ t ] [ 10 callcc1-test 10 reverse >vector = ] unit-test
+[ t ] [ 10 callcc1-test 10 iota reverse >vector = ] unit-test
 [ t ] [ callcc-namespace-test ] unit-test
 
 [ 5 throw ] [ 5 = ] must-fail-with
index 02c129aefee0e75eaf01a2f1a39b01169c7f1200..d63acae8836213fbbef3ae6ad5431717f06e55fa 100644 (file)
@@ -13,7 +13,7 @@ SYMBOL: restarts
 <PRIVATE
 
 : catchstack* ( -- catchstack )
-    1 getenv { vector } declare ; inline
+    1 special-object { vector } declare ; inline
 
 : >c ( continuation -- ) catchstack* push ;
 
@@ -23,13 +23,13 @@ SYMBOL: restarts
 : dummy-1 ( -- obj ) f ;
 : dummy-2 ( obj -- obj ) dup drop ;
 
-: init-catchstack ( -- ) V{ } clone 1 setenv ;
+: init-catchstack ( -- ) V{ } clone 1 set-special-object ;
 
 PRIVATE>
 
 : catchstack ( -- catchstack ) catchstack* clone ; inline
 
-: set-catchstack ( catchstack -- ) >vector 1 setenv ; inline
+: set-catchstack ( catchstack -- ) >vector 1 set-special-object ; inline
 
 TUPLE: continuation data call retain name catch ;
 
@@ -71,12 +71,12 @@ PRIVATE>
 
 : continue-with ( obj continuation -- * )
     [
-        swap 4 setenv
+        swap 4 set-special-object
         >continuation<
         set-catchstack
         set-namestack
         set-retainstack
-        [ set-datastack drop 4 getenv f 4 setenv f ] dip
+        [ set-datastack drop 4 special-object f 4 set-special-object f ] dip
         set-callstack
     ] (( obj continuation -- * )) call-effect-unsafe ;
 
@@ -173,12 +173,12 @@ M: condition compute-restarts
     ! VM calls on error
     [
         ! 63 = self
-        63 getenv error-thread set-global
+        63 special-object error-thread set-global
         continuation error-continuation set-global
         rethrow
-    ] 5 setenv
+    ] 5 set-special-object
     ! VM adds this to kernel errors, so that user-space
     ! can identify them
-    "kernel-error" 6 setenv ;
+    "kernel-error" 6 set-special-object ;
 
 PRIVATE>
index 38b8ab4dad2986985777795cdb52f4dc9891e200..134faea0270bc5f10adeb087e2d828f4d2e41d8c 100644 (file)
@@ -56,7 +56,7 @@ HELP: effect>string
 { $values { "obj" object } { "str" string } }
 { $description "Turns a stack effect object into a string mnemonic." }
 { $examples
-    { $example "USING: effects io ;" "1 2 <effect> effect>string print" "( object -- object object )" }
+    { $example "USING: effects io ;" "{ \"x\" } { \"y\" \"z\" } <effect> effect>string print" "( x -- y z )" }
 } ;
 
 HELP: stack-effect
index 8adef62795081e24116fde8d3a1c4bb96b3f1f44..ffc0c9780b27daeeb35dca386d6fa3112607bd32 100644 (file)
@@ -2,11 +2,11 @@ USING: effects kernel tools.test prettyprint accessors
 quotations sequences ;
 IN: effects.tests
 
-[ t ] [ 1 1 <effect> 2 2 <effect> effect<= ] unit-test
-[ f ] [ 1 0 <effect> 2 2 <effect> effect<= ] unit-test
-[ t ] [ 2 2 <effect> 2 2 <effect> effect<= ] unit-test
-[ f ] [ 3 3 <effect> 2 2 <effect> effect<= ] unit-test
-[ f ] [ 2 3 <effect> 2 2 <effect> effect<= ] unit-test
+[ t ] [ { "a" } { "a" } <effect> { "a" "b" } { "a" "b" } <effect> effect<= ] unit-test
+[ f ] [ { "a" } { } <effect> { "a" "b" } { "a" "b" } <effect> effect<= ] unit-test
+[ t ] [ { "a" "b" } { "a" "b" } <effect> { "a" "b" } { "a" "b" } <effect> effect<= ] unit-test
+[ f ] [ { "a" "b" "c" } { "a" "b" "c" } <effect> { "a" "b" } { "a" "b" } <effect> effect<= ] unit-test
+[ f ] [ { "a" "b" } { "a" "b" "c" } <effect> { "a" "b" } { "a" "b" } <effect> effect<= ] unit-test
 [ 2 ] [ (( a b -- c )) in>> length ] unit-test
 [ 1 ] [ (( a b -- c )) out>> length ] unit-test
 
index 8c1699f8d654def0d58ae5bae2f4d2eb124e222c..1790399e04d2c47a964f98c52a8c608a98be2c99 100644 (file)
@@ -1,34 +1,33 @@
-! Copyright (C) 2006, 2009 Slava Pestov.
+! Copyright (C) 2006, 2010 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
 USING: kernel math math.parser math.order namespaces make sequences strings
 words assocs combinators accessors arrays quotations ;
 IN: effects
 
-TUPLE: effect { in read-only } { out read-only } { terminated? read-only } ;
-
-GENERIC: effect-length ( obj -- n )
-M: sequence effect-length length ;
-M: integer effect-length ;
+TUPLE: effect
+{ in array read-only }
+{ out array read-only }
+{ terminated? read-only } ;
 
 : <effect> ( in out -- effect )
-    dup { "*" } sequence= [ drop { } t ] [ f ] if
+    dup { "*" } = [ drop { } t ] [ f ] if
     effect boa ;
 
 : effect-height ( effect -- n )
-    [ out>> effect-length ] [ in>> effect-length ] bi - ; inline
+    [ out>> length ] [ in>> length ] bi - ; inline
 
 : effect<= ( effect1 effect2 -- ? )
     {
         { [ over terminated?>> ] [ t ] }
         { [ dup terminated?>> ] [ f ] }
-        { [ 2dup [ in>> effect-length ] bi@ > ] [ f ] }
+        { [ 2dup [ in>> length ] bi@ > ] [ f ] }
         { [ 2dup [ effect-height ] bi@ = not ] [ f ] }
         [ t ]
     } cond 2nip ; inline
 
 : effect= ( effect1 effect2 -- ? )
-    [ [ in>> effect-length ] bi@ = ]
-    [ [ out>> effect-length ] bi@ = ]
+    [ [ in>> length ] bi@ = ]
+    [ [ out>> length ] bi@ = ]
     [ [ terminated?>> ] bi@ = ]
     2tri and and ;
 
@@ -40,7 +39,6 @@ M: integer effect>string number>string ;
 M: pair effect>string first2 [ effect>string ] bi@ ": " glue ;
 
 : stack-picture ( seq -- string )
-    dup integer? [ "object" <repetition> ] when
     [ [ effect>string % CHAR: \s , ] each ] "" make ;
 
 M: effect effect>string ( effect -- string )
@@ -56,10 +54,14 @@ M: effect effect>string ( effect -- string )
 GENERIC: effect>type ( obj -- type )
 M: object effect>type drop object ;
 M: word effect>type ;
-! attempting to specialize on callable breaks compiling
-! M: effect effect>type drop callable ;
 M: pair effect>type second effect>type ;
 
+: effect-in-types ( effect -- input-types )
+    in>> [ effect>type ] map ;
+
+: effect-out-types ( effect -- input-types )
+    out>> [ effect>type ] map ;
+
 GENERIC: stack-effect ( word -- effect/f )
 
 M: word stack-effect "declared-effect" word-prop ;
@@ -73,7 +75,7 @@ M: effect clone
     stack-effect effect-height ;
 
 : split-shuffle ( stack shuffle -- stack1 stack2 )
-    in>> effect-length cut* ;
+    in>> length cut* ;
 
 : shuffle-mapping ( effect -- mapping )
     [ out>> ] [ in>> ] bi [ index ] curry map ;
@@ -88,14 +90,9 @@ M: effect clone
     over terminated?>> [
         drop
     ] [
-        [ [ [ in>> effect-length ] [ out>> effect-length ] bi ] [ in>> effect-length ] bi* swap [-] + ]
-        [ [ out>> effect-length ] [ [ in>> effect-length ] [ out>> effect-length ] bi ] bi* [ [-] ] dip + ]
+        [ [ [ in>> length ] [ out>> length ] bi ] [ in>> length ] bi* swap [-] + ]
+        [ [ out>> length ] [ [ in>> length ] [ out>> length ] bi ] bi* [ [-] ] dip + ]
         [ nip terminated?>> ] 2tri
-        [ [ [ "obj" ] replicate ] bi@ ] dip
+        [ [ "x" <array> ] bi@ ] dip
         effect boa
     ] if ; inline
-
-: effect-in-types ( effect -- input-types )
-    in>> [ effect>type ] map ;
-: effect-out-types ( effect -- input-types )
-    out>> [ effect>type ] map ;
index dea523538eec6384d9b51179269d4c2e22d3581b..240fdd96e0aab3c1a3a899adabe8baa3f182fed7 100644 (file)
@@ -11,15 +11,13 @@ $nl
 { $code
     "GENERIC: explain ( object -- )"
     "M: object explain drop \"an object\" print ;"
-    "M: number explain drop \"a number\" print ;"
-    "M: sequence explain drop \"a sequence\" print ;"
+    "M: generic explain drop \"a class word\" print ;"
+    "M: class explain drop \"a generic word\" print ;"
 }
 "The linear order is the following, from least-specific to most-specific:"
-{ $code "{ object sequence number }" }
-"Neither " { $link number } " nor " { $link sequence } " are subclasses of each other, yet their intersection is the non-empty " { $link integer } " class. Calling " { $snippet "explain" } " with an integer on the stack will print " { $snippet "a number" } " because " { $link number } " precedes " { $link sequence } " in the class linearization order. If this was not the desired outcome, define a method on the intersection:"
-{ $code "M: integer explain drop \"an integer\" print ;" }
-"Now, the linear order is the following, from least-specific to most-specific:"
-{ $code "{ object sequence number integer }" }
+{ $code "{ object generic class }" }
+"Neither " { $link class } " nor " { $link generic } " are subclasses of each other, and their intersection is non-empty. Calling " { $snippet "explain" } " with a word on the stack that is both a class and a generic word will print " { $snippet "a generic word" } " because " { $link class } " precedes " { $link generic } " in the class linearization order. (One example of a word which is both a class and a generic word is the class of classes, " { $link class } ", which is also a word to get the class of an object.)"
+$nl
 "The " { $link order } " word can be useful to clarify method dispatch order:"
 { $subsections order } ;
 
index 05cc27f5e8bfc0e48e61ba4336de65717e7cd81f..541f98ab9ca3ecbe00ac4c3996f84343568d0346 100644 (file)
@@ -3,14 +3,12 @@ sequences.private hashtables io prettyprint assocs
 continuations ;
 IN: hashtables.tests
 
-[ f ] [ "hi" V{ 1 2 3 } at ] unit-test
-
 [ H{ } ] [ { } [ dup ] H{ } map>assoc ] unit-test
 
-[ ] [ 1000 [ dup sq ] H{ } map>assoc "testhash" set ] unit-test
+[ ] [ 1000 iota [ dup sq ] H{ } map>assoc "testhash" set ] unit-test
 
 [ V{ } ]
-[ 1000 [ dup sq swap "testhash" get at = not ] filter ]
+[ 1000 iota [ dup sq swap "testhash" get at = not ] filter ]
 unit-test
 
 [ t ]
@@ -118,7 +116,7 @@ H{ } clone "counting" set
 
 ! Resource leak...
 H{ } "x" set
-100 [ drop "x" get clear-assoc ] each
+100 [ drop "x" get clear-assoc ] each-integer
 
 ! Crash discovered by erg
 [ t ] [ 0.75 <hashtable> dup clone = ] unit-test
@@ -173,4 +171,4 @@ H{ } "x" set
 [ 1 ] [ 2 "h" get at ] unit-test
 
 ! Random test case
-[ "A" ] [ 100 [ dup ] H{ } map>assoc 32 over delete-at "A" 32 pick set-at 32 swap at ] unit-test
+[ "A" ] [ 100 iota [ dup ] H{ } map>assoc 32 over delete-at "A" 32 pick set-at 32 swap at ] unit-test
index 40e5806fd594cdf9ccdfce2d60d17156e6cc887c..4e2d4b16a156f98b756d8c46760ff9309e8ec7d8 100644 (file)
@@ -27,12 +27,12 @@ shutdown-hooks global [ drop V{ } clone ] cache drop
 
 : boot ( -- ) init-namespaces init-catchstack init-error-handler ;
 
-: startup-quot ( -- quot ) 20 getenv ;
+: startup-quot ( -- quot ) 20 special-object ;
 
-: set-startup-quot ( quot -- ) 20 setenv ;
+: set-startup-quot ( quot -- ) 20 set-special-object ;
 
-: shutdown-quot ( -- quot ) 22 getenv ;
+: shutdown-quot ( -- quot ) 22 special-object ;
 
-: set-shutdown-quot ( quot -- ) 22 setenv ;
+: set-shutdown-quot ( quot -- ) 22 set-special-object ;
 
 [ do-shutdown-hooks ] set-shutdown-quot
index 088131acf9e0a0ba6c90a0ed2d99efc7b5509cc1..efebe7bd25431717da6a562a36012d87f3639bc0 100644 (file)
@@ -28,4 +28,4 @@ IN: io.encodings.utf8.tests
 
 [ 3 ] [ 2 "lápis" >utf8-index ] unit-test
 
-[ V{ } ] [ 100000 [ [ code-point-length ] [ 1string utf8 encode length ] bi = not ] filter ] unit-test
+[ V{ } ] [ 100000 iota [ [ code-point-length ] [ 1string utf8 encode length ] bi = not ] filter ] unit-test
index 9824fba18cdcb49c3cd1a903f12aaa44b3b38959..86d02acdd1721961de654c83bcc24a97794bb09e 100644 (file)
@@ -57,7 +57,7 @@ PRIVATE>
 
 [
     cwd current-directory set-global
-    13 getenv alien>native-string cwd prepend-path \ image set-global
-    14 getenv alien>native-string cwd prepend-path \ vm set-global
+    13 special-object alien>native-string cwd prepend-path \ image set-global
+    14 special-object alien>native-string cwd prepend-path \ vm set-global
     image parent-directory "resource-path" set-global
 ] "io.files" add-startup-hook
index cb978d5debb6589b0adaea3f65a54a56aa8ac726..d26f03aa5ee80e9279cf5a6e8334585572dd95ae 100644 (file)
@@ -61,9 +61,9 @@ M: c-reader stream-read-until
 
 M: c-io-backend init-io ;
 
-: stdin-handle ( -- alien ) 11 getenv ;
-: stdout-handle ( -- alien ) 12 getenv ;
-: stderr-handle ( -- alien ) 61 getenv ;
+: stdin-handle ( -- alien ) 11 special-object ;
+: stdout-handle ( -- alien ) 12 special-object ;
+: stderr-handle ( -- alien ) 61 special-object ;
 
 : init-c-stdio ( -- )
     stdin-handle <c-reader>
index 89ac1c9a05bd91740cca20570fc5bc60f5869f6c..7c80990d7a214d97353d53cc836329c12e6f5e4c 100644 (file)
@@ -655,13 +655,13 @@ HELP: tag ( object -- n )
 { $values { "object" object } { "n" "a tag number" } }
 { $description "Outputs an object's tag number, between zero and one less than " { $link num-types } ". This is implementation detail and user code should call " { $link class } " instead." } ;
 
-HELP: getenv ( n -- obj )
+HELP: special-object ( n -- obj )
 { $values { "n" "a non-negative integer" } { "obj" object } }
-{ $description "Reads an object from the Factor VM's environment table. User code never has to read the environment table directly; instead, use one of the callers of this word." } ;
+{ $description "Reads an object from the Factor VM's special object table. User code never has to read the special object table directly; instead, use one of the callers of this word." } ;
 
-HELP: setenv ( obj n -- )
+HELP: set-special-object ( obj n -- )
 { $values { "obj" object } { "n" "a non-negative integer" } }
-{ $description "Writes an object to the Factor VM's environment table. User code never has to write to the environment table directly; instead, use one of the callers of this word." } ;
+{ $description "Writes an object to the Factor VM's special object table. User code never has to write to the special object table directly; instead, use one of the callers of this word." } ;
 
 HELP: object
 { $class-description
index 05fe03315cc0ea603c396d384c38ed458d4555a7..5edb5d1d7271d16fc5583c6e5c94be7ad54ad8b7 100644 (file)
@@ -36,7 +36,7 @@ SYMBOL: header-bits
 ! We do this in its own compilation unit so that they can be
 ! folded below
 <<
-: cell ( -- n ) 7 getenv ; foldable
+: cell ( -- n ) 7 special-object ; foldable
 
 : (first-bignum) ( m -- n ) tag-bits get - 1 - 2^ ; foldable
 >>
index 220eb339606ae36704964dbe30e16e66c99dcbb5..84f993c5ac9a95dae1c149c22a7353909356dcdb 100644 (file)
@@ -1,4 +1,4 @@
-USING: kernel math math.constants tools.test sequences
+USING: kernel math math.constants math.order tools.test sequences
 grouping ;
 IN: math.floats.tests
 
@@ -58,7 +58,7 @@ unit-test
 
 [ 0 ] [ 1/0. >bignum ] unit-test
 
-[ t ] [ 64 [ 2^ 0.5 * ] map [ < ] monotonic? ] unit-test
+[ t ] [ 64 iota [ 2^ 0.5 * ] map [ < ] monotonic? ] unit-test
 
 [ 5 ] [ 10.5 1.9 /i ] unit-test
 
@@ -75,3 +75,6 @@ unit-test
 [ t ] [ -0.0 abs 0.0 fp-bitwise= ] unit-test
 [ 1.5 ] [ -1.5 abs ] unit-test
 [ 1.5 ] [ 1.5 abs ] unit-test
+
+[ 5.0 ] [ 3 5.0 max ] unit-test
+[ 3 ] [ 3 5.0 min ] unit-test
index bc419b94c52dde3c4ae9d3d5db0a4e9595cf30d4..97c6f7fc87659b71869eb35eb2c33c684f4b6dfe 100644 (file)
@@ -1,6 +1,6 @@
-! Copyright (C) 2004, 2009 Slava Pestov, Joe Groff.
+! Copyright (C) 2004, 2010 Slava Pestov, Joe Groff.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: kernel math math.private ;
+USING: kernel math math.private math.order ;
 IN: math.floats.private
 
 : float-unordered? ( x y -- ? ) [ fp-nan? ] bi@ or ;
@@ -29,6 +29,9 @@ M: float u<= float-u<= ; inline
 M: float u>  float-u> ; inline
 M: float u>= float-u>= ; inline
 
+M: float min over float? [ float-min ] [ call-next-method ] if ; inline
+M: float max over float? [ float-max ] [ call-next-method ] if ; inline
+
 M: float + float+ ; inline
 M: float - float- ; inline
 M: float * float* ; inline
index 30d1254082017b9fb539cc141ba8fc4daa1e062a..3f3ea7ba1bd0975df2192defafd6198556ffe5e5 100644 (file)
@@ -1,5 +1,6 @@
-USING: kernel math math.functions namespaces prettyprint
-math.private continuations tools.test sequences random ;
+USING: kernel math math.functions math.order namespaces
+prettyprint math.private continuations tools.test sequences
+random ;
 IN: math.integers.tests
 
 [ "-8" ] [ -8 unparse ] unit-test
@@ -224,9 +225,12 @@ unit-test
         random-integer
         random-integer
         [ >float / ] [ /f ] 2bi 0.1 ~
-    ] all?
+    ] all-integers?
 ] unit-test
 
 ! Ensure that /f is accurate for fixnums > 2^53 on 64-bit platforms
 [ HEX: 1.758bec11492f9p-54 ] [ 1 12345678901234567 /f ] unit-test
 [ HEX: -1.758bec11492f9p-54 ] [ 1 -12345678901234567 /f ] unit-test
+
+[ 17 ] [ 17 >bignum 5 max ] unit-test
+[ 5 ] [ 17 >bignum 5 min ] unit-test
index eb94597160c68026ab6b7e8ae204715ecea16b39..e95c6d832b4591606a6bd75c8c84a5f4260950f7 100644 (file)
@@ -1,8 +1,8 @@
-! Copyright (C) 2004, 2009 Slava Pestov.
+! Copyright (C) 2004, 2010 Slava Pestov.
 ! Copyright (C) 2008, Doug Coleman.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: kernel kernel.private sequences
-sequences.private math math.private combinators ;
+USING: kernel kernel.private sequences sequences.private math
+math.private math.order combinators ;
 IN: math.integers.private
 
 : fixnum-min ( x y -- z ) [ fixnum< ] most ; foldable
@@ -29,6 +29,9 @@ M: fixnum u<= fixnum<= ; inline
 M: fixnum u> fixnum> ; inline
 M: fixnum u>= fixnum>= ; inline
 
+M: fixnum min over fixnum? [ fixnum-min ] [ call-next-method ] if ; inline
+M: fixnum max over fixnum? [ fixnum-max ] [ call-next-method ] if ; inline
+
 M: fixnum + fixnum+ ; inline
 M: fixnum - fixnum- ; inline
 M: fixnum * fixnum* ; inline
index e56753887c3211db0960cabb9281f2d57d65e7ce..6af48d00de19270d6c53f050cfb066a769d8d752 100644 (file)
@@ -283,7 +283,7 @@ HELP: unless-zero
 { $examples "This word is equivalent to " { $link if-zero } " with an empty first quotation:"
     { $example
     "USING: sequences math prettyprint ;"
-    "3 [ ] [ sq ] if-empty ."
+    "3 [ ] [ sq ] if-zero ."
     "9"
     }
     { $example
index 5d294c1f6f9edeb321a597734dd1867810ea7192..418107fcd158f9bf23c1054d0fa48fdb152ab817 100644 (file)
@@ -44,18 +44,18 @@ HELP: compare
 } ;
 
 HELP: max
-{ $values { "x" object } { "y" object } { "z" object } }
+{ $values { "obj1" object } { "obj2" object } { "obj" object } }
 { $description "Outputs the greatest of two ordered values." }
 { $notes "If one value is a floating point positive zero and the other is a negative zero, the result is undefined." } ;
 
 HELP: min
-{ $values { "x" object } { "y" object } { "z" object } }
+{ $values { "obj1" object } { "obj2" object } { "obj" object } }
 { $description "Outputs the smallest of two ordered values." }
 { $notes "If one value is a floating point positive zero and the other is a negative zero, the result is undefined." } ;
 
 HELP: clamp
 { $values { "x" object } { "min" object } { "max" object } { "y" object } }
-{ $description "Outputs " { $snippet "x" } " if contained in the interval " { $snippet "[min,max]" } " or outputs one of the endpoints." } ;
+{ $description "Outputs " { $snippet "x" } " if contained in the interval " { $snippet "[min,max]" } " or else outputs one of the endpoints." } ;
 
 HELP: between?
 { $values { "x" object } { "y" object } { "z" real } { "?" "a boolean" } }
index fe1454d1d873fab0b7f9a621dccdc95d0df531fb..499cf06e9a6394d04d514331a88dc7f2c2949580 100644 (file)
@@ -1,4 +1,4 @@
-! Copyright (C) 2008 Slava Pestov, Doug Coleman.
+! Copyright (C) 2008, 2010 Slava Pestov, Doug Coleman.
 ! See http://factorcode.org/license.txt for BSD license.
 USING: kernel math ;
 IN: math.order
@@ -32,8 +32,12 @@ M: real after? ( obj1 obj2 -- ? ) > ; inline
 M: real before=? ( obj1 obj2 -- ? ) <= ; inline
 M: real after=? ( obj1 obj2 -- ? ) >= ; inline
 
-: min ( x y -- z ) [ before? ] most ;
-: max ( x y -- z ) [ after? ] most ;
+GENERIC: min ( obj1 obj2 -- obj )
+GENERIC: max ( obj1 obj2 -- obj )
+
+M: object min [ before? ] most ; inline
+M: object max [ after? ] most ; inline
+
 : clamp ( x min max -- y ) [ max ] dip min ; inline
 
 : between? ( x y z -- ? )
index cd0bb47bd5b39bd2a06d760c2f9d2969074eb2c8..0d039f2fe97bc2e6f5e09c0182018d237cef3af2 100644 (file)
@@ -29,12 +29,12 @@ $nl
 ABOUT: "number-strings"
 
 HELP: digits>integer
-{ $values { "seq" "a sequence of integers" } { "radix" "an integer between 2 and 36" } { "n/f" { $maybe integer } } }
+{ $values { "seq" "a sequence of integers" } { "radix" "an integer between 2 and 16" } { "n/f" { $maybe integer } } }
 { $description "Converts a sequence of digits (with most significant digit first) into an integer." }
 { $notes "This is one of the factors of " { $link string>number } "." } ;
 
 HELP: >digit
-{ $values { "n" "an integer between 0 and 35" } { "ch" "a character" } }
+{ $values { "n" "an integer between 0 and 15" } { "ch" "a character" } }
 { $description "Outputs a character representation of a digit." }
 { $notes "This is one of the factors of " { $link number>string } "." } ;
 
@@ -44,7 +44,7 @@ HELP: digit>
 { $notes "This is one of the factors of " { $link string>number } "." } ;
 
 HELP: base>
-{ $values { "str" string } { "radix" "an integer between 2 and 36" } { "n/f" "a real number or " { $link f } } }
+{ $values { "str" string } { "radix" "an integer between 2 and 16" } { "n/f" "a real number or " { $link f } } }
 { $description "Creates a real number from a string representation with the given radix. The radix is ignored for floating point literals; they are always taken to be in base 10."
 $nl
 "Outputs " { $link f } " if the string does not represent a number." } ;
@@ -84,7 +84,7 @@ $nl
 { >hex POSTPONE: HEX: hex> .h } related-words
 
 HELP: >base
-{ $values { "n" real } { "radix" "an integer between 2 and 36" } { "str" string } }
+{ $values { "n" real } { "radix" "an integer between 2 and 16" } { "str" string } }
 { $description "Converts a real number into a string representation using the given radix. If the number is a float, the radix is ignored and the output is always in base 10." } ;
 
 HELP: >bin
index 9428445d267adb1d83321d1d4c01b143085012f5..40b1db8a3f39a83fcfb1955cd85ce3aaf3ab23e8 100644 (file)
@@ -6,7 +6,7 @@ IN: namespaces
 
 <PRIVATE
 
-: namestack* ( -- namestack ) 0 getenv { vector } declare ; inline
+: namestack* ( -- namestack ) 0 special-object { vector } declare ; inline
 : >n ( namespace -- ) namestack* push ;
 : ndrop ( -- ) namestack* pop* ;
 
@@ -14,8 +14,8 @@ PRIVATE>
 
 : namespace ( -- namespace ) namestack* last ; inline
 : namestack ( -- namestack ) namestack* clone ;
-: set-namestack ( namestack -- ) >vector 0 setenv ;
-: global ( -- g ) 21 getenv { hashtable } declare ; inline
+: set-namestack ( namestack -- ) >vector 0 set-special-object ;
+: global ( -- g ) 21 special-object { hashtable } declare ; inline
 : init-namespaces ( -- ) global 1array set-namestack ;
 : get ( variable -- value ) namestack* assoc-stack ; inline
 : set ( value variable -- ) namespace set-at ;
index d920e1fc734767adfc95c518d4688a8c59478fd8..1433289f0a59fd8c02cd2e9c81ce34f32783647c 100644 (file)
@@ -55,8 +55,11 @@ ERROR: staging-violation word ;
     execute( accum -- accum ) ;
 
 : scan-object ( -- object )
-    scan-word dup parsing-word?
-    [ V{ } clone swap execute-parsing first ] when ;
+    scan-word {
+        { [ dup not ] [ unexpected-eof ] }
+        { [ dup parsing-word? ] [ V{ } clone swap execute-parsing first ] }
+        [ ]
+    } cond  ;
 
 : parse-step ( accum end -- accum ? )
     scan-word {
index ac3f565e5678784473968c1b752eedb3780a5cec..6711870f74c585a956f6aa65f65463d1688177e6 100644 (file)
@@ -21,4 +21,4 @@ IN: sbufs.tests
 
 [ fixnum ] [ 1 >bignum SBUF" " new-sequence length class ] unit-test
 
-[ fixnum ] [ 1 >bignum [ ] SBUF" " map-as length class ] unit-test
+[ fixnum ] [ 1 >bignum iota [ ] SBUF" " map-as length class ] unit-test
index aeab243a2f60adf3cb7c0145aa7e6e09a2e44381..9f570f97d5af49645c975d0b328f05c8fadbafea 100644 (file)
@@ -999,7 +999,7 @@ HELP: pusher
      { "quot" quotation } { "accum" vector } }
 { $description "Creates a new vector to accumulate the values which return true for a predicate.  Returns a new quotation which accepts an object to be tested and stored in the accumulator if the test yields true. The accumulator is left on the stack for convenience." }
 { $example "! Find all the even numbers:" "USING: prettyprint sequences math kernel ;"
-           "10 [ even? ] pusher [ each ] dip ."
+           "10 iota [ even? ] pusher [ each ] dip ."
            "V{ 0 2 4 6 8 }"
 }
 { $notes "Used to implement the " { $link filter } " word. Compare this word with " { $link accumulator } ", which is an unfiltering version." } ;
@@ -1140,9 +1140,9 @@ HELP: set-fourth
 
 HELP: replicate
 { $values
-     { "seq" sequence } { "quot" { $quotation "( -- elt )" } }
+     { "len" integer } { "quot" { $quotation "( -- elt )" } }
      { "newseq" sequence } }
-{ $description "Calls the quotation for every element of the sequence in order. However, the element is not passed to the quotation -- it is dropped, and the quotation produces an element of its own that is collected into a sequence of the same class as the input sequence." }
+     { $description "Calls the quotation " { $snippet "len" } " times, collecting results into a new array." }
 { $examples 
     { $unchecked-example "USING: kernel prettyprint random sequences ;"
         "5 [ 100 random ] replicate ."
@@ -1152,15 +1152,16 @@ HELP: replicate
 
 HELP: replicate-as
 { $values
-     { "seq" sequence } { "quot" quotation } { "exemplar" sequence }
+     { "len" integer } { "quot" quotation } { "exemplar" sequence }
      { "newseq" sequence } }
-{ $description "Calls the quotation for every element of the sequence in order. However, the element is not passed to the quotation -- it is dropped, and the quotation produces an element of its own that is collected into a sequence of the same class as the exemplar sequence." }
+ { $description "Calls the quotation " { $snippet "len" } " times, collecting results into a new sequence of the same type as the exemplar sequence." }
 { $examples 
     { $unchecked-example "USING: prettyprint kernel sequences ;"
         "5 [ 100 random ] B{ } replicate-as ."
         "B{ 44 8 2 33 18 }"
     }
 } ;
+
 { replicate replicate-as } related-words
 
 HELP: partition
@@ -1240,7 +1241,7 @@ HELP: binary-reduce
 { $description "Like " { $link reduce } ", but splits the sequence in half recursively until each sequence is small enough, and calls the quotation on these smaller sequences. If the quotation computes values that depend on the size of their input, such as bignum arithmetic, then this algorithm can be more efficient than using " { $link reduce } "." }
 { $examples "Computing factorial:"
     { $example "USING: prettyprint sequences math ;"
-    "40 rest-slice 1 [ * ] binary-reduce ."
+    "40 iota rest-slice 1 [ * ] binary-reduce ."
     "20397882081197443358640281739902897356800000000" }
 } ;
 
@@ -1408,17 +1409,20 @@ ARTICLE: "virtual-sequences" "Virtual sequences"
 "A virtual sequence is an implementation of the " { $link "sequence-protocol" } " which does not store its own elements, and instead computes them, either from scratch or by retrieving them from another sequence."
 $nl
 "Implementations include the following:"
-{ $subsections reversed slice iota }
-"Virtual sequences can be implemented with the " { $link "virtual-sequences-protocol" } ", by translating an index in the virtual sequence into an index in another sequence." ;
+{ $subsections reversed slice }
+"Virtual sequences can be implemented with the " { $link "virtual-sequences-protocol" } ", by translating an index in the virtual sequence into an index in another sequence."
+{ $see-also "sequences-integers" } ;
 
 ARTICLE: "sequences-integers" "Counted loops"
-"Integers support the sequence protocol in a trivial fashion; a non-negative integer presents its non-negative predecessors as elements. For example, the integer 3, when viewed as a sequence, contains the elements 0, 1, and 2. This is very useful for performing counted loops."
+"A virtual sequence is defined for iterating over integers from zero."
+{ $subsection iota }
+"For example, calling " { $link iota } " on the integer 3 produces a sequence containing the elements 0, 1, and 2. This is very useful for performing counted loops."
 $nl
-"For example, the " { $link each } " combinator, given an integer, simply calls a quotation that number of times, pushing a counter on each iteration that ranges from 0 up to that integer:"
-{ $example "3 [ . ] each" "0\n1\n2" }
+"This means the " { $link each } " combinator, given an integer, simply calls a quotation that number of times, pushing a counter on each iteration that ranges from 0 up to that integer:"
+{ $example "3 iota [ . ] each" "0\n1\n2" }
 "A common idiom is to iterate over a sequence, while also maintaining a loop counter. This can be done using " { $link each-index } ", " { $link map-index } " and " { $link reduce-index } "."
 $nl
-"Combinators that produce new sequences, such as " { $link map } ", will output an array if the input is an integer."
+"Combinators that produce new sequences, such as " { $link map } ", will output an array if the input is an instance of " { $link iota } "."
 $nl
 "More elaborate counted loops can be performed with " { $link "math.ranges" } "." ;
 
index c82caec3f9769772d61069f7a01fba6b122e7f23..10be0454b98f7c235cc45f01f9f16fb4f63577fc 100644 (file)
@@ -6,13 +6,13 @@ IN: sequences.tests
 [ "empty" ] [ { } [ "empty" ] [ "not empty" ] if-empty ] unit-test
 [ { 1 } "not empty" ] [ { 1 } [ "empty" ] [ "not empty" ] if-empty ] unit-test
 
-[ V{ 1 2 3 4 } ] [ 1 5 dup <slice> >vector ] unit-test
-[ 3 ] [ 1 4 dup <slice> length ] unit-test
+[ V{ 1 2 3 4 } ] [ 1 5 dup iota <slice> >vector ] unit-test
+[ 3 ] [ 1 4 dup iota <slice> length ] unit-test
 [ 2 ] [ 1 3 { 1 2 3 4 } <slice> length ] unit-test
 [ V{ 2 3 } ] [ 1 3 { 1 2 3 4 } <slice> >vector ] unit-test
 [ V{ 4 5 } ] [ { 1 2 3 4 5 } 2 tail-slice* >vector ] unit-test
-[ V{ 3 4 } ] [ 2 4 1 10 dup <slice> subseq >vector ] unit-test
-[ V{ 3 4 } ] [ 0 2 2 4 1 10 dup <slice> <slice> subseq >vector ] unit-test
+[ V{ 3 4 } ] [ 2 4 1 10 dup iota <slice> subseq >vector ] unit-test
+[ V{ 3 4 } ] [ 0 2 2 4 1 10 dup iota <slice> <slice> subseq >vector ] unit-test
 [ 0 10 "hello" <slice> ] must-fail
 [ -10 3 "hello" <slice> ] must-fail
 [ 2 1 "hello" <slice> ] must-fail
@@ -129,7 +129,7 @@ unit-test
 [ { 1 3 2 4 } ] [ { 1 2 3 4 } clone 1 2 pick exchange ] unit-test
 
 [ { "" "a" "aa" "aaa" } ]
-[ 4 [ CHAR: a <string> ] map ]
+[ 4 [ CHAR: a <string> ] { } map-integers ]
 unit-test
 
 [ V{ } ] [ "f" V{ } clone remove! ] unit-test
@@ -138,11 +138,11 @@ unit-test
 [ V{ "x" } ] [ "f" V{ "f" "x" "f" } clone remove! ] unit-test
 [ V{ "y" "x" } ] [ "f" V{ "y" "f" "x" "f" } clone remove! ] unit-test
 
-[ V{ 0 1 4 5 } ] [ 6 >vector 2 4 pick delete-slice ] unit-test
+[ V{ 0 1 4 5 } ] [ 6 iota >vector 2 4 pick delete-slice ] unit-test
 
 [ 6 >vector 2 8 pick delete-slice ] must-fail
 
-[ V{ } ] [ 6 >vector 0 6 pick delete-slice ] unit-test
+[ V{ } ] [ 6 iota >vector 0 6 pick delete-slice ] unit-test
 
 [ { 1 2 "a" "b" 5 6 7 } ] [
     { "a" "b" } 2 4 { 1 2 3 4 5 6 7 }
@@ -228,10 +228,10 @@ unit-test
 
 [ 0 ] [ f length ] unit-test
 [ f first ] must-fail
-[ 3 ] [ 3 10 nth ] unit-test
-[ 3 ] [ 3 10 nth-unsafe ] unit-test
-[ -3 10 nth ] must-fail
-[ 11 10 nth ] must-fail
+[ 3 ] [ 3 10 iota nth ] unit-test
+[ 3 ] [ 3 10 iota nth-unsafe ] unit-test
+[ -3 10 iota nth ] must-fail
+[ 11 10 iota nth ] must-fail
 
 [ -1/0. 0 remove-nth! ] must-fail
 [ "" ] [ "" [ CHAR: \s = ] trim ] unit-test
@@ -243,10 +243,10 @@ unit-test
 [ "asdf " ] [ " asdf " [ CHAR: \s = ] trim-head ] unit-test
 [ " asdf" ] [ " asdf " [ CHAR: \s = ] trim-tail ] unit-test
 
-[ 328350 ] [ 100 [ sq ] map-sum ] unit-test
+[ 328350 ] [ 100 iota [ sq ] map-sum ] unit-test
 
-[ 50 ] [ 100 [ even? ] count ] unit-test
-[ 50 ] [ 100 [ odd?  ] count ] unit-test
+[ 50 ] [ 100 iota [ even? ] count ] unit-test
+[ 50 ] [ 100 iota [ odd?  ] count ] unit-test
 
 [ { "b" "d" } ] [ { 1 3 } { "a" "b" "c" "d" } nths ] unit-test
 [ { "a" "b" "c" "d" } ] [ { 0 1 2 3 } { "a" "b" "c" "d" } nths ] unit-test
index 16949f5542da48d43daba98dfbaff786e7a655c2..7d1e45aca0ffb0db67182d67e0593b4c23dfd138 100644 (file)
@@ -1,4 +1,4 @@
-! Copyright (C) 2005, 2009 Slava Pestov, Daniel Ehrenberg.
+! Copyright (C) 2005, 2010 Slava Pestov, Daniel Ehrenberg.
 ! See http://factorcode.org/license.txt for BSD license.
 USING: accessors kernel kernel.private slots.private math
 math.private math.order ;
@@ -98,12 +98,6 @@ M: f like drop [ f ] when-empty ; inline
 
 INSTANCE: f immutable-sequence
 
-! Integers used to support the sequence protocol
-M: integer length ; inline
-M: integer nth-unsafe drop ; inline
-
-INSTANCE: integer immutable-sequence
-
 PRIVATE>
 
 ! In the future, this will replace integer sequences
@@ -426,11 +420,11 @@ PRIVATE>
 : map ( seq quot -- newseq )
     over map-as ; inline
 
-: replicate ( seq quot -- newseq )
-    [ drop ] prepose map ; inline
+: replicate-as ( len quot exemplar -- newseq )
+    [ [ drop ] prepose ] dip map-integers ; inline
 
-: replicate-as ( seq quot exemplar -- newseq )
-    [ [ drop ] prepose ] dip map-as ; inline
+: replicate ( len quot -- newseq )
+    { } replicate-as ; inline
 
 : map! ( seq quot -- seq )
     over [ map-into ] keep ; inline
@@ -466,7 +460,7 @@ PRIVATE>
     (2each) all-integers? ; inline
 
 : 3each ( seq1 seq2 seq3 quot -- )
-    (3each) each ; inline
+    (3each) each-integer ; inline
 
 : 3map-as ( seq1 seq2 seq3 quot exemplar -- newseq )
     [ (3each) ] dip map-integers ; inline
index 0bda4ba9b0be9e4324c69677d6734c4a7c1e3d3e..101cd75a5ba1f7aaf3a53bf49eba55ea584d754c 100644 (file)
@@ -5,7 +5,7 @@ IN: sorting.tests
 [ { } ] [ { } natural-sort ] unit-test
 
 [ { 270000000 270000001 } ]
-[ T{ slice f 270000000 270000002 270000002 } natural-sort ]
+[ T{ slice f 270000000 270000002 T{ iota f 270000002 } } natural-sort ]
 unit-test
 
 [ t ] [
@@ -14,7 +14,7 @@ unit-test
         100 [ 20 random [ 1000 random ] replicate ] replicate
         dup natural-sort
         [ set= ] [ nip [ before=? ] monotonic? ] 2bi and
-    ] all?
+    ] all-integers?
 ] unit-test
 
 [ ] [ { 1 2 } [ 2drop 1 ] sort drop ] unit-test
index 4f5473ce9de921869ee2e94e7245102c19d90943..b3b6daee5957174fdb8a559caa25333f6576e6e9 100644 (file)
@@ -20,7 +20,7 @@ M: source-file-error error-line [ error>> error-line ] [ line#>> ] bi or ;
 M: source-file-error compute-restarts error>> compute-restarts ;
 
 : sort-errors ( errors -- alist )
-    [ [ line#>> ] sort-with ] { } assoc-map-as sort-keys ;
+    [ [ line#>> 0 or ] sort-with ] { } assoc-map-as sort-keys ;
 
 : group-by-source-file ( errors -- assoc )
     H{ } clone [ [ push-at ] curry [ dup file>> ] prepose each ] keep ;
index 689d88be7156cc2c1b60ad09df47e4cf5456f3ce..b90d96a356e0809616fa2d87c698139d8c747307 100644 (file)
@@ -116,5 +116,5 @@ unit-test
         drop
         300 100 CHAR: \u123456
         [ <string> clone resize-string first ] keep =
-    ] all?
+    ] all-integers?
 ] unit-test
index 59f2a030ceee8fcb44a3dee3a4925f52a5a3c6fd..715564c64dcf8c91cd8bd965890fb1ec2549b09a 100644 (file)
@@ -53,6 +53,6 @@ PRIVATE>
 
 : vm ( -- path ) \ vm get-global ;
 
-: embedded? ( -- ? ) 15 getenv ;
+: embedded? ( -- ? ) 15 special-object ;
 
 : exit ( n -- ) do-shutdown-hooks (exit) ;
index 9052638e7da914b9e41c0b1e4a8d2d5b45c4388a..8f644963bf0594cc33c12144eb3a20a19256dbbf 100644 (file)
@@ -91,11 +91,11 @@ IN: vectors.tests
 [ 4 ] [ 5 V{ 1 2 3 4 5 } index ] unit-test
 
 [ t ] [
-    100 >array dup >vector <reversed> >array [ reverse ] dip =
+    100 iota >array dup >vector <reversed> >array [ reverse ] dip =
 ] unit-test
 
 [ fixnum ] [ 1 >bignum V{ } new-sequence length class ] unit-test
 
-[ fixnum ] [ 1 >bignum [ ] V{ } map-as length class ] unit-test
+[ fixnum ] [ 1 >bignum iota [ ] V{ } map-as length class ] unit-test
 
 [ V{ "lulz" } ] [ "lulz" 1vector ] unit-test
index 15c610ce7a6a5e5086ab23848730666e99097d3e..28600b6c48667452795f794d4138ee6d3892699b 100644 (file)
@@ -56,7 +56,7 @@ DEFER: check-status
         [ end-game ] 
         [ dup quit? [ quit-game ] [ repeat ] if ]
     if ;
-: build-quad ( -- array ) 4 [ 10 random ] replicate >array ;
+: build-quad ( -- array ) 4 [ 10 random ] replicate ;
 : 24-able? ( quad -- t/f ) [ makes-24? ] with-datastack first ;
 : 24-able ( -- vector ) build-quad dup 24-able? [ drop build-quad ] unless ;
 : set-commands ( -- ) { + - * / rot swap q } commands set ;
index b97a356e6ef8496113fd13fadf8d9d83c4d48878..305ae6bdf236f4b7b2d07d23bd1e58218968abad 100644 (file)
@@ -1,6 +1,6 @@
 ! (c)Joe Groff bsd license
 USING: alien.data.map fry generalizations kernel locals math.vectors
-math.vectors.conversion math math.vectors.simd sequences
+math.vectors.conversion math math.vectors.simd math.ranges sequences
 specialized-arrays tools.test ;
 FROM: alien.c-types => uchar short int float ;
 SPECIALIZED-ARRAYS: int float float-4 uchar-16 ;
@@ -145,3 +145,11 @@ CONSTANT: plane-count 4
     B{  15  25  35  45  55  65  75  85  95 105 115 125 135 145 155 165 }
     fold-rgba-planes
 ] unit-test
+
+: data-map-compiler-bug-test ( n -- byte-array )
+    [ 0.0 1.0 1.0 ] dip /f <range>
+    [ ] data-map( object -- float ) ;
+
+[ float-array{ 0.0 0.5 1.0 } ]
+[ 2 data-map-compiler-bug-test byte-array>float-array ]
+unit-test
index 350a29f8659db7b5430cd8c5ac5c521f2cdaf416..95202f35f984f75e8a51d14a34008ca52f2cdaeb 100644 (file)
@@ -4,7 +4,7 @@ USING: math sequences kernel base64 ;
 IN: benchmark.base64
 
 : base64-benchmark ( -- )
-    65535 [ 255 bitand ] "" map-as
+    65535 iota [ 255 bitand ] "" map-as
     20 [ >base64 base64> ] times
     drop ;
 
index 31c202b803716a6d1a02a088b3f93ab9e6573754..839bd89dc06792a632fdfc01b3f44e1c547d0011 100644 (file)
@@ -8,7 +8,7 @@ IN: benchmark.dawes
 : count-ones ( int-array -- n ) [ 1 = ] count ; inline
 
 : make-int-array ( -- int-array )
-    120000 [ 255 bitand ] int-array{ } map-as ; inline
+    120000 iota [ 255 bitand ] int-array{ } map-as ; inline
 
 : dawes-benchmark ( -- )
     200 make-int-array '[ _ count-ones ] replicate drop ;
index 87848cee9dfae4532333da07036f259e756e4ac7..7db583d42a397bcc6fe97c0316c3afd305739945 100644 (file)
@@ -5,8 +5,8 @@ IN: benchmark.dispatch2
 
 : sequences ( -- seq )
     [
-        1 ,
-        10 >bignum ,
+        1 iota ,
+        10 >bignum iota ,
         { 1 2 3 } ,
         "hello world" ,
         SBUF" sbuf world" ,
@@ -14,7 +14,7 @@ IN: benchmark.dispatch2
         double-array{ 1.0 2.0 3.0 } ,
         "hello world" 4 tail-slice ,
         10 f <repetition> ,
-        100 2 <sliced-groups> ,
+        100 iota 2 <sliced-groups> ,
         "hello" <reversed> ,
         { { 1 2 } { 3 4 } } 0 <column> ,
         ?{ t f t } ,
index 2f989b77231f2b82cbd064b2b8e952534c1754c0..685c92a8cc05a6a3e6277707b72293b0fcaa641e 100644 (file)
@@ -54,14 +54,14 @@ IN: benchmark.dispatch4
     20000000 [
         20 [
             foobar-1 drop
-        ] each
+        ] each-integer
     ] times ;
 
 : foobar-test-2 ( -- )
     20000000 [
         20 [
             foobar-2 drop
-        ] each
+        ] each-integer
     ] times ;
 
 MAIN: foobar-test-1
index 7ef40aa65a0db40debd1965b9db1f5887383ead6..a7d875af3fe9c12aff922bd7dc486a4e5f22656a 100644 (file)
@@ -5,7 +5,7 @@ sequences ;
 IN: benchmark.e-decimals
 
 : D-factorial ( n -- D! )
-    D: 1 [ 0 <decimal> D: 1 D+ D* ] reduce ; inline
+    iota D: 1 [ 0 <decimal> D: 1 D+ D* ] reduce ; inline
 
 :: calculate-e-decimals ( n -- e )
     n [1,b] D: 1
index f09aee6adaa47a52e334d3ea18d51bf45ee356ce..a6541856a56a05ee9ab9fa4814280910ab5cae10 100644 (file)
@@ -2,7 +2,7 @@ USING: math math.private kernel sequences ;
 IN: benchmark.empty-loop-2
 
 : empty-loop-2 ( n -- )
-    [ drop ] each ;
+    iota [ drop ] each ;
 
 : empty-loop-main ( -- )
     50000000 empty-loop-2 ;
index 5ba285dbb18343441d63a89938a359b913571ace..bd7ccafb9fa01eb7ebfbfc0ee47b374db953113a 100644 (file)
@@ -56,7 +56,7 @@ CONSTANT: homo-sapiens
     chars nth-unsafe ; inline
 
 : make-random-fasta ( seed len chars floats -- seed )
-    [ rot drop select-random ] 2curry "" map-as print ; inline
+    [ iota ] 2dip [ [ drop ] 2dip select-random ] 2curry "" map-as print ; inline
 
 : write-description ( desc id -- )
     ">" write write bl print ; inline
@@ -72,7 +72,7 @@ CONSTANT: homo-sapiens
 
 :: make-repeat-fasta ( k len alu -- k' )
     alu length :> kn
-    len [ k + kn mod alu nth-unsafe ] "" map-as print
+    len iota [ k + kn mod alu nth-unsafe ] "" map-as print
     k len + ; inline
 
 : write-repeat-fasta ( n alu desc id -- )
index 4909496d125b65874f71e69b427b5d8c8517f125..91989f204a4e1aaa774f1a4c6d08e31e46f87fc2 100644 (file)
@@ -3,6 +3,6 @@
 USING: math sequences kernel ;
 IN: benchmark.gc1
 
-: gc1 ( -- ) 600000 [ >bignum 1 + ] map drop ;
+: gc1 ( -- ) 600000 iota [ >bignum 1 + ] map drop ;
 
 MAIN: gc1
index f49d21d5a36829664733903f94b73b54af176758..51cafbe1e8596b1f602e43df9e6da15c350e3b9b 100644 (file)
@@ -2,7 +2,7 @@ IN: benchmark.iteration
 USING: sequences vectors arrays strings sbufs math math.vectors
 kernel ;
 
-: <range> ( from to -- seq ) dup <slice> ; inline
+: <range> ( from to -- seq ) dup iota <slice> ; inline
 
 : vector-iter ( -- ) 100 [ 0 100000 <range> >vector [ ] map drop ] times ;
 : array-iter ( -- ) 100 [ 0 100000 <range> >array [ ] map drop ] times ;
index a28a676b904b72957dae0aed314e03c24d747317..70fa1bb061b367cac6f1a825ef3a5efc546819fc 100644 (file)
@@ -25,7 +25,7 @@ IN: benchmark.knucleotide
 
 : small-groups ( x n -- b )
     swap
-    [ length swap - 1 + ] 2keep
+    [ length swap - 1 + iota ] 2keep
     [ [ over + ] dip subseq ] 2curry map ;
 
 : handle-table ( inputs n -- )
index 023f5de5c24d8b21ba88629225294ef6fff92a38..aa6098a43458f4a82d61a51ff80977fd61d0a94d 100644 (file)
@@ -1,11 +1,11 @@
-! Copyright (C) 2008 Slava Pestov.
+! Copyright (C) 2008, 2010 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
 USING: math math.functions kernel io io.styles prettyprint
 combinators hints fry namespaces sequences ;
 IN: benchmark.partial-sums
 
 ! Helper words
-: summing-integers ( n quot -- y ) [ 0.0 ] 2dip '[ 1 + @ + ] each ; inline
+: summing-integers ( n quot -- y ) [ 0.0 ] [ iota ] [ ] tri* '[ 1 + @ + ] each ; inline
 : summing-floats ( n quot -- y ) '[ >float @ ] summing-integers ; inline
 : cube ( x -- y ) dup dup * * ; inline
 : -1^ ( n -- -1/1 ) 2 mod 2 * 1 - ; inline
index 4eab7c16693ae6b49ceb09d1a01c70b22b9a9c0c..b5abc4f68736473cd9fb03abb02ea1617c489567 100644 (file)
@@ -1,5 +1,5 @@
 USING: io io.files io.files.temp io.encodings.ascii random
-math.parser math ;
+math.parser math sequences ;
 IN: benchmark.random
 
 : random-numbers-path ( -- path )
index 45407e5ad2676e23d30f5cd66c717633a9484e1e..dcdc911cbf676b08389f56a2b546c0b7935a159b 100644 (file)
@@ -149,7 +149,7 @@ DEFER: create ( level c r -- scene )
     [ oversampling /f ] bi@ 0.0 0.0 double-4-boa ;
 
 : ss-grid ( -- ss-grid )
-    oversampling [ oversampling [ ss-point ] with map ] map ;
+    oversampling iota [ oversampling iota [ ss-point ] with map ] map ;
 
 : ray-grid ( point ss-grid -- ray-grid )
     [
@@ -161,8 +161,8 @@ DEFER: create ( level c r -- scene )
     [ [ swap cast-ray + ] with each ] with each ;
 
 : pixel-grid ( -- grid )
-    size reverse [
-        size [
+    size iota reverse [
+        size iota [
             [ size 0.5 * - ] bi@ swap size
             0.0 double-4-boa
         ] with map
index 2413e7fd1e38991a47ccee77d20c543b542148f9..868743b46a2c2885f447fc17a7d1216b7176836e 100644 (file)
@@ -148,7 +148,7 @@ DEFER: create ( level c r -- scene )
     [ oversampling /f ] bi@ 0.0 double-array{ } 3sequence ;
 
 : ss-grid ( -- ss-grid )
-    oversampling [ oversampling [ ss-point ] with map ] map ;
+    oversampling iota [ oversampling iota [ ss-point ] with map ] map ;
 
 : ray-grid ( point ss-grid -- ray-grid )
     [
@@ -160,8 +160,8 @@ DEFER: create ( level c r -- scene )
     [ [ swap cast-ray + ] with each ] with each ;
 
 : pixel-grid ( -- grid )
-    size reverse [
-        size [
+    size iota reverse [
+        size iota [
             [ size 0.5 * - ] bi@ swap size
             double-array{ } 3sequence
         ] with map
index ae918b7ebcb9f3ccff4abd8c4319edbca97b68cf..08e8edbeff583df74523a62a9b925d4ab3f83e5a 100644 (file)
@@ -13,7 +13,7 @@ SYMBOL: done
     ] times ;
 
 : send-messages ( messages target -- )
-    dupd [ send ] curry each [ receive drop ] times ; 
+    [ dup iota ] dip [ send ] curry each [ receive drop ] times ; 
 
 : destroy-ring ( target -- )
     done swap send [ done eq? ] receive-if drop ;
index 68efffe08313b3f056c3033a796804b1ddd21db1..386ffb0ae10c6aa4498bc2515e4620c6ecc5c188 100644 (file)
@@ -7,8 +7,8 @@ SPECIALIZED-ARRAY: double
 IN: benchmark.spectral-norm
 
 :: inner-loop ( u n quot -- seq )
-    n [| i |
-        n 0.0 [| j |
+    n iota [| i |
+        n iota 0.0 [| j |
             u i j quot call +
         ] reduce
     ] double-array{ } map-as ; inline
index 38ce0087a2c209d74f61cd97848bf320c23b86ae..701db7713591de56154ca5c6a02218aa554ab84c 100644 (file)
@@ -9,7 +9,7 @@ TUPLE: point { x float } { y float } { z float } ;
 TUPLE-ARRAY: point
 
 : tuple-array-benchmark ( -- )
-    100 [
+    100 iota [
         drop 5000 <point-array> [
             [ 1 + ] change-x
             [ 1 - ] change-y
index 6fdbdaecf6d06ea5452799a56d7e68f5b75037b2..9d16f75e15d2da7b4ced9d835b34f04b01aa2ddd 100644 (file)
@@ -2,6 +2,6 @@ USING: ui.gadgets.panes prettyprint io sequences ;
 IN: benchmark.ui-panes
 
 : ui-pane-benchmark ( -- )
-    <pane> <pane-stream> [ 10000 [ . ] each ] with-output-stream* ;
+    <pane> <pane-stream> [ 10000 iota [ . ] each ] with-output-stream* ;
 
 MAIN: ui-pane-benchmark
index 024887991e9af4a12865846bd3cafecc2b994a84..b182b4f832ee703b18df1f437498400e3393ded7 100644 (file)
@@ -27,9 +27,9 @@ STRUCT: yuv_buffer
         h >>uv_height
         w >>y_stride
         w >>uv_stride
-        w h * [ dup * ] B{ } map-as malloc-byte-array &free >>y
-        w h * 2/ [ dup dup * * ] B{ } map-as malloc-byte-array &free >>u
-        w h * 2/ [ dup * dup * ] B{ } map-as malloc-byte-array &free >>v ;
+        w h * iota [ dup * ] B{ } map-as malloc-byte-array &free >>y
+        w h * 2/ iota [ dup dup * * ] B{ } map-as malloc-byte-array &free >>u
+        w h * 2/ iota [ dup * dup * ] B{ } map-as malloc-byte-array &free >>v ;
 
 : clamp ( n -- n )
     255 min 0 max ; inline
@@ -76,12 +76,12 @@ STRUCT: yuv_buffer
 
 : yuv>rgb-row ( index rgb yuv y -- index )
     over stride
-    pick y_width>>
+    pick y_width>> iota
     [ yuv>rgb-pixel ] with with with with each ; inline
 
 : yuv>rgb ( rgb yuv -- )
     [ 0 ] 2dip
-    dup y_height>>
+    dup y_height>> iota
     [ yuv>rgb-row ] with with each
     drop ;
 
index fa56aff8cc92898c8cf3c64c57054cc906c33f70..f4055ca9e06c74813889e190fd003a3996ef831f 100644 (file)
@@ -73,8 +73,8 @@ IN: bloom-filters.tests
 [ t ] [ 1000 iota [ drop most-positive-fixnum random 1000 + ] map
         full-bloom-filter
         [ bloom-filter-member? ] curry map
-        [ ] filter
+        [ ] count
         ! TODO: This should be 10, but the false positive rate is currently very
         ! high.  300 is large enough not to prevent builds from succeeding.
-        length 300 <=
+        300 <=
 ] unit-test
index ad24d74adffb00bd481869b37efaae500870009f..0f14ed1d975720323e0066f92c7ef4106c35390f 100644 (file)
@@ -4,7 +4,7 @@ USING: accessors arrays bit-arrays fry infix kernel layouts locals math
 math.functions multiline sequences ;
 IN: bloom-filters
 
-FROM: math.ranges => [1,b] [0,b) ;
+FROM: math.ranges => [1,b] ;
 FROM: math.intervals => (a,b) interval-contains? ;
 
 /*
@@ -121,7 +121,7 @@ PRIVATE>
     [infix hash0 + (index * hash1) + ((pow(index, 3) - index) / 6) infix] ;
 
 : enhanced-double-hashes ( hash0 hash1 n -- seq )
-    [0,b)
+    iota
     [ '[ _ _ enhanced-double-hash ] ] dip
     swap map ;
 
index e6ae0060b67ac9fd7a5e7a08509875b325f14691..51aa5f3817e32bba1208090fc7e256858ad58203 100644 (file)
@@ -1,6 +1,6 @@
 USING: accessors assocs bson.constants calendar fry io io.binary
 io.encodings io.encodings.utf8 kernel math math.bitwise namespaces
-sequences serialize ;
+sequences serialize locals ;
 
 FROM: kernel.private => declare ;
 FROM: io.encodings.private => (read-until) ;
@@ -62,22 +62,17 @@ GENERIC: element-binary-read ( length type -- object )
 : read-byte ( -- byte )
     read-byte-raw first ; inline
 
-: utf8-read-until ( seps stream encoding -- string/f sep/f )
-    [ { utf8 } declare decode-char dup [ dup rot member? ] [ 2drop f t ] if ]
-    3curry (read-until) ;
-
 : read-cstring ( -- string )
-    "\0" input-stream get utf8 utf8-read-until drop ; inline
+    "\0" read-until drop "" like ; inline
 
 : read-sized-string ( length -- string )
-    drop read-cstring ; inline
+    read 1 head-slice* "" like ; inline
 
 : read-element-type ( -- type )
     read-byte ; inline
 
-: push-element ( type name -- element )
-    element boa
-    [ get-state element>> push ] keep ; inline
+: push-element ( type name -- )
+    element boa get-state element>> push ; inline
 
 : pop-element ( -- element )
     get-state element>> pop ; inline
@@ -96,8 +91,7 @@ M: bson-object fix-result ( assoc type -- result )
     drop ;
 
 M: bson-array fix-result ( assoc type -- result )
-    drop
-    values ;
+    drop values ;
 
 GENERIC: end-element ( type -- )
 
@@ -108,25 +102,20 @@ M: bson-array end-element ( type -- )
     drop ;
 
 M: object end-element ( type -- )
-    drop
-    pop-element drop ;
+    pop-element 2drop ;
 
-M: bson-eoo element-read ( type -- cont? )
-    drop
-    get-state scope>> [ pop ] keep swap ! vec assoc
-    pop-element [ type>> ] keep       ! vec assoc element
-    [ fix-result ] dip
-    rot length 0 >                      ! assoc element 
-    [ name>> peek-scope set-at t ]
-    [ drop [ get-state ] dip >>result drop f ] if ;
-
-M: bson-not-eoo element-read ( type -- cont? )
-    [ peek-scope ] dip                                 ! scope type 
-    '[ _ read-cstring push-element [ name>> ] [ type>> ] bi 
-       [ element-data-read ] keep
-       end-element
-       swap
-    ] dip set-at t ;
+M:: bson-eoo element-read ( type -- cont? )
+    pop-element :> element
+    get-state scope>>
+    [ pop element type>> fix-result ] [ empty? ] bi
+    [ [ get-state ] dip >>result drop f ]
+    [ element name>> peek-scope set-at t ] if ;
+
+M:: bson-not-eoo element-read ( type -- cont? )
+    peek-scope :> scope
+    type read-cstring [ push-element ] 2keep
+    [ [ element-data-read ] [ end-element ] bi ]
+    [ scope set-at t ] bi* ;
 
 : [scope-changer] ( state -- state quot )
     dup exemplar>> '[ [ [ _ clone ] dip push ] keep ] ; inline
@@ -173,8 +162,7 @@ M: bson-regexp element-data-read ( type -- mdbregexp )
    read-cstring >>regexp read-cstring >>options ;
  
 M: bson-null element-data-read ( type -- bf  )
-    drop
-    f ;
+    drop f ;
 
 M: bson-oid element-data-read ( type -- oid )
     drop
index f9bd0eb392a45a3980c4454dfcd124776554151f..a07057994331203de6b0101b8f44cdc3539e0a10 100644 (file)
@@ -73,11 +73,9 @@ M: word bson-type? ( word -- type ) drop T_Binary ;
 M: quotation bson-type? ( quotation -- type ) drop T_Binary ; 
 M: byte-array bson-type? ( byte-array -- type ) drop T_Binary ; 
 
-: write-utf8-string ( string -- ) output-stream get '[ _ swap char>utf8 ] each ; inline
-
 : write-int32 ( int -- ) INT32-SIZE >le write ; inline
 : write-double ( real -- ) double>bits INT64-SIZE >le write ; inline
-: write-cstring ( string -- ) write-utf8-string 0 write1 ; inline
+: write-cstring ( string -- ) B{ } like write 0 write1 ; inline
 : write-longlong ( object -- ) INT64-SIZE >le write ; inline
 
 : write-eoo ( -- ) T_EOO write1 ; inline
@@ -127,9 +125,11 @@ M: sequence bson-write ( array -- )
    { $[ MDB_OID_FIELD MDB_META_FIELD ] } member? ; inline
 
 M: assoc bson-write ( assoc -- )
-    '[ _  [ write-oid ] keep
-       [ over skip-field? [ 2drop ] [ write-pair ] if ] assoc-each
-       write-eoo ] with-length-prefix ; 
+    '[
+        _  [ write-oid ] keep
+        [ over skip-field? [ 2drop ] [ write-pair ] if ] assoc-each
+        write-eoo
+    ] with-length-prefix ;
 
 : (serialize-code) ( code -- )
     object>bytes [ length write-int32 ] keep
index 3cee3999255262ac981a48b72cde8953dd53b8e7..747c8f53fc1bdc47603e915a0af07e30e652a441 100644 (file)
@@ -49,8 +49,8 @@ MACRO:: slots>constructor ( class slots -- quot )
     reverse? [ reverse ] when
     '[ @ _ [ execute( obj -- obj ) ] each ] effect define-declared ;
 
-: scan-constructor ( -- class word )
-    scan-word [ name>> "<" ">" surround create-in ] keep ;
+: scan-constructor ( -- word class )
+    scan-word [ name>> "<" ">" surround create-in dup reset-generic ] keep ;
 
 : parse-constructor ( -- class word effect def )
     scan-constructor complete-effect parse-definition ;
index a5a6709c6d61c2d555ecbf68560cc3a1ca208fd4..4891eab6902f25fd115c0c02ecb20457a4ef222e 100644 (file)
@@ -44,7 +44,7 @@ CONSTANT: AES_BLOCK_SIZE 16
 
 : inv-sbox ( -- array )
     256 0 <array>
-    dup 256 [ dup sbox nth rot set-nth ] with each ;
+    dup 256 [ dup sbox nth rot set-nth ] with each-integer ;
 
 : rcon ( -- array )
     {
@@ -72,7 +72,7 @@ CONSTANT: AES_BLOCK_SIZE 16
 
 MEMO:: t-table ( -- array )
     1024 0 <array>
-    dup 256 [ set-t ] with each ;
+    dup 256 [ set-t ] with each-integer ;
 
 :: set-d ( D i -- )
     i inv-sbox nth :> a1
@@ -91,7 +91,7 @@ MEMO:: t-table ( -- array )
     
 MEMO:: d-table ( -- array )
     1024 0 <array>
-    dup 256 [ set-d ] with each ;
+    dup 256 [ set-d ] with each-integer ;
 
 
 USE: multiline
index 29b9d98b38548e4fa8489ceeb13ddb40558d2a07..5bd0fb0fa3a3868a63045970540aa95873f2132a 100644 (file)
@@ -26,15 +26,15 @@ ERROR: decimal-test-failure D1 D2 quot ;
 : test-decimal-op ( quot1 quot2 -- ? )
     [ random-test-decimal random-test-decimal ] 2dip (test-decimal-op) ; inline
 
-[ t ] [ 1000 [ drop [ D+ ] [ + ] test-decimal-op ] all? ] unit-test
-[ t ] [ 1000 [ drop [ D- ] [ - ] test-decimal-op ] all? ] unit-test
-[ t ] [ 1000 [ drop [ D* ] [ * ] test-decimal-op ] all? ] unit-test
+[ t ] [ 1000 [ drop [ D+ ] [ + ] test-decimal-op ] all-integers? ] unit-test
+[ t ] [ 1000 [ drop [ D- ] [ - ] test-decimal-op ] all-integers? ] unit-test
+[ t ] [ 1000 [ drop [ D* ] [ * ] test-decimal-op ] all-integers? ] unit-test
 [ t ] [
     1000 [
         drop
         [ [ 100 D/ ] [ /f ] test-decimal-op ]
         [ { "kernel-error" 4 f f } = ] recover
-    ] all?
+    ] all-integers?
 ] unit-test
 
 [ t ] [ 
diff --git a/extra/furnace/mongodb/mongodb.factor b/extra/furnace/mongodb/mongodb.factor
new file mode 100644 (file)
index 0000000..a3af419
--- /dev/null
@@ -0,0 +1,12 @@
+USING: accessors http.server http.server.filters io.pools kernel
+mongodb.driver mongodb.connection namespaces unix destructors continuations ;
+
+IN: furnace.mongodb
+
+TUPLE: mdb-persistence < filter-responder pool ;
+
+: <mdb-persistence> ( responder mdb -- responder' )
+    <mdb-pool> mdb-persistence boa ;
+
+M: mdb-persistence call-responder*
+    dup pool>> [ mdb-connection set call-next-method ] with-pooled-connection ;
diff --git a/extra/grid-meshes/grid-meshes-tests.factor b/extra/grid-meshes/grid-meshes-tests.factor
new file mode 100644 (file)
index 0000000..ef71a66
--- /dev/null
@@ -0,0 +1,21 @@
+IN: grid-meshes.tests
+USING: alien.c-types grid-meshes grid-meshes.private
+specialized-arrays tools.test ;
+SPECIALIZED-ARRAY: float
+
+[
+    float-array{
+        0.0 0.0 0.0 1.0
+        0.0 0.0 0.5 1.0
+        0.5 0.0 0.0 1.0
+        0.5 0.0 0.5 1.0
+        1.0 0.0 0.0 1.0
+        1.0 0.0 0.5 1.0
+        0.0 0.0 0.5 1.0
+        0.0 0.0 1.0 1.0
+        0.5 0.0 0.5 1.0
+        0.5 0.0 1.0 1.0
+        1.0 0.0 0.5 1.0
+        1.0 0.0 1.0 1.0
+    }
+] [ { 2 2 } vertex-array byte-array>float-array ] unit-test
index 10fcd9c449ade7c150ae2cb4469fa209cc13b645..2d0b9514ffee2dab36a0c2569a32df11cb9e6dbd 100644 (file)
@@ -61,10 +61,10 @@ TUPLE: link attributes clickable ;
     ] map ;
 
 : find-by-id ( vector id -- vector' elt/f )
-    '[ attributes>> "id" at _ = ] find ;
+    '[ attributes>> "id" swap at _ = ] find ;
     
 : find-by-class ( vector id -- vector' elt/f )
-    '[ attributes>> "class" at _ = ] find ;
+    '[ attributes>> "class" swap at _ = ] find ;
 
 : find-by-name ( vector string -- vector elt/f )
     >lower '[ name>> _ = ] find ;
index 9bb755807771054a1aaf8cda2a74ec6abd8f058d..bc3a387fd0cc4aa4b5e0bee8593de40527c5788a 100644 (file)
@@ -43,4 +43,4 @@ IN: id3.tests
 
 
 [ t ]
-[ 10000 [ synchsafe>seq seq>synchsafe ] map [ < ] monotonic? ] unit-test
+[ 10000 iota [ synchsafe>seq seq>synchsafe ] map [ < ] monotonic? ] unit-test
index 917480dd3ffe89a276158b4857c4f31fcf2aaf82..9c42bf256b84138e44984a73583ccf02264a5955 100644 (file)
@@ -68,9 +68,9 @@ $nl
 "Please note: in Factor " { $emphasis "fixnums are sequences too." } " If you are not careful with sequence accesses you may introduce subtle bugs:"
 { $example
     "USING: arrays infix locals ;"
-    ":: add-2nd-element ( x y -- res )"
+    ":: add-2nd-elements ( x y -- res )"
     "    [infix x[1] + y[1] infix] ;"
-    "{ 1 2 3 } 5 add-2nd-element ."
+    "{ 1 2 3 } { 0 1 2 3 } add-2nd-elements ."
     "3"
 }
 ;
index 48bf2b693a8c463c74cdc247e5689dc2488fd1b6..9e5d248c989726c93149a44476af3196109ece06 100644 (file)
@@ -44,7 +44,7 @@ CONSTANT: wall-drawing-offset 0.15
 
 : equally-spaced-radians ( n -- seq )
     #! return a sequence of n numbers between 0 and 2pi
-    dup [ / pi 2 * * ] curry map ;
+    [ iota ] keep [ / pi 2 * * ] curry map ;
 
 : draw-segment-vertex ( segment theta -- )
     over color>> gl-color segment-vertex-and-normal
index b1644ef443a5f308963e79c2510070935350d2c2..1b1d87fbab4f0ac093419c93cd9bd0e6f3cb8f90 100644 (file)
@@ -34,7 +34,7 @@ C: <oint> oint
 
 : random-float+- ( n -- m )
     #! find a random float between -n/2 and n/2
-    dup 10000 * >fixnum random 10000 / swap 2 / - ;
+    dup 10000 * >integer random 10000 / swap 2 / - ;
 
 : random-turn ( oint theta -- )
     2 / 2dup random-float+- left-pivot random-float+- up-pivot ;
index f5b30f49da7a61dfa2659cec521e483d30195ed8..c35ba6ac8c0193922ba85c8b53879987713a6b64 100644 (file)
@@ -71,10 +71,10 @@ SYMBOL: terms
     [ natural-sort ] keep [ index ] curry map ;
 
 : (inversions) ( n seq -- n )
-    [ > ] with filter length ;
+    [ > ] with count ;
 
 : inversions ( seq -- n )
-    0 swap [ length ] keep [
+    0 swap [ length iota ] keep [
         [ nth ] 2keep swap 1 + tail-slice (inversions) +
     ] curry each ;
 
@@ -145,12 +145,12 @@ DEFER: (d)
     [ dup length pick nth push ] reduce ;
 
 : nth-basis-elt ( generators n -- elt )
-    over length [
+    over length iota [
         3dup bit? [ nth ] [ 2drop f ] if
     ] map sift 2nip ;
 
 : basis ( generators -- seq )
-    natural-sort dup length 2^ [ nth-basis-elt ] with map ;
+    natural-sort dup length 2^ iota [ nth-basis-elt ] with map ;
 
 : (tensor) ( seq1 seq2 -- seq )
     [
@@ -180,7 +180,7 @@ DEFER: (d)
     dim-im/ker-d ;
 
 : graded-ker/im-d ( graded-basis -- seq )
-    [ length ] keep [ (graded-ker/im-d) ] curry map ;
+    [ length iota ] keep [ (graded-ker/im-d) ] curry map ;
 
 : graded-betti ( generators -- seq )
     basis graded graded-ker/im-d unzip but-last 0 prefix v- ;
@@ -269,8 +269,8 @@ DEFER: (d)
     3array ;
 
 :: bigraded-triples ( grid -- triples )
-    grid length [| z |
-        grid first length [| u |
+    grid length iota [| z |
+        grid first length iota [| u |
             u z grid bigraded-triple
         ] map
     ] map ;
index e77dacaf580bc2a3a23c3a085e4ef553d79cc20a..cac4180abd53c74a44a3e904c9d13980497f531d 100644 (file)
@@ -30,6 +30,7 @@ M: windows really-delete-tree
 M: unix really-delete-tree delete-tree ;
 
 : retry ( n quot -- )
+    [ iota ] dip
     '[ drop @ f ] attempt-all drop ; inline
 
 :: upload-safely ( local username host remote -- )
index 6d01744290ab9f889308788a092e11f22c6de9b3..e4052836b4ffca8662be7df633c198233b6f3746 100644 (file)
@@ -18,7 +18,7 @@ CONSTANT: gamma-p6
     }
 
 : gamma-z ( x n -- seq )
-    [ + recip ] with map 1.0 0 pick set-nth ;
+    [ + recip ] with { } map-integers 1.0 0 pick set-nth ;
 
 : (gamma-lanczos6) ( x -- log[gamma[x+1]] )
     #! log(gamma(x+1)
index 422036d5cc39ae6c44c819f5632c926439653c17..5b2af13489fd7286b01e658fb5edbf59729904fb 100644 (file)
@@ -83,7 +83,7 @@ SYMBOL: and-needed?
         first 3digits>text
     ] [
         [ set-conjunction "" ] [ length ] [ ] tri
-        [ (recombine) ] curry each
+        [ (recombine) ] curry each-integer
     ] if ;
 
 : (number>text) ( n -- str )
index c0623d96b6a64eb6da66f3797ed8ede3c8c94780..4238dab16888c53e09277076ea8b869ff822ee49 100644 (file)
@@ -44,7 +44,7 @@ SYMBOL: visited
     line-width 2 - glLineWidth
     line-width 2 - glPointSize
     1.0 1.0 1.0 1.0 glColor4d
-    dup [ drop t <array> ] with map visited set
+    dup iota [ drop t <array> ] with map visited set
     GL_LINE_STRIP glBegin
     { 0 0 } dup vertex (draw-maze)
     glEnd ;
index 33d1fbedcbc58fb36f51b36caed11f844f306fad..a053c058537d23333999916659b15aaada4d69a6 100644 (file)
@@ -1,6 +1,6 @@
 ! (c)2009 Joe Groff bsd license
 USING: accessors arrays bit-arrays classes
-classes.tuple.private fry kernel locals parser
+classes.tuple.private fry kernel locals math parser
 sequences sequences.private vectors words ;
 IN: memory.pools
 
@@ -10,7 +10,7 @@ TUPLE: pool
 
 : <pool> ( size class -- pool )
     [ nip new ]
-    [ [ iota ] dip '[ _ new ] V{ } replicate-as ] 2bi
+    [ '[ _ new ] V{ } replicate-as ] 2bi
     pool boa ;
 
 : pool-size ( pool -- size )
@@ -20,7 +20,7 @@ TUPLE: pool
 
 :: copy-tuple ( from to -- to )
     from tuple-size :> size
-    size [| n | n from array-nth n to set-array-nth ] each
+    size [| n | n from array-nth n to set-array-nth ] each-integer
     to ; inline
 
 : (pool-new) ( pool -- object )
index ad8c5016052688153f4694ef424b4a89e4ebc316..399b5c4e8cbccf717e82c6a501dc309e0d149506 100644 (file)
@@ -224,15 +224,15 @@ CONSTANT: DOC-LARGE H{ { "base_url" "http://www.example.com/test-me" }
       [ index>> bchar ] keep
       lasterror>> bchar
       trial-size ] dip
-    1000000 / /i
-    "%-18s: {batch:%s,index:%s;errchk:%s} %10s docs/s"
+      1000000000 / [ /i ] [ result get batch>> [ [ batch-size /i ] dip ] when /i ] 2bi
+    "%-18s: {batch:%s,index:%s;errchk:%s} %10s docs/s %10s ops/s"
     sprintf print flush ; 
 
 : print-separator ( -- )
-    "----------------------------------------------------------------" print flush ; inline
+    "---------------------------------------------------------------------------------" print flush ; inline
 
 : print-separator-bold ( -- )
-    "================================================================" print flush ; inline
+    "=================================================================================" print flush ; inline
 
 : print-header ( -- )
     trial-size
index 294672523cbb6c237d2870cbcc92c4a36235cc0e..78d0b627345c162f16062c896f89ff9fb07526f7 100644 (file)
@@ -165,9 +165,7 @@ M: mdb-collection create-collection
 : fix-query-collection ( mdb-query -- mdb-query )
     [ check-collection ] change-collection ; inline
 
-GENERIC: get-more ( mdb-cursor -- mdb-cursor seq )
-
-M: mdb-cursor get-more 
+: get-more ( mdb-cursor -- mdb-cursor seq )
     [ [ query>> dup [ collection>> ] [ return#>> ] bi ]
       [ id>> ] bi <mdb-getmore-msg> swap >>query send-query ] 
     [ f f ] if* ;
@@ -177,21 +175,20 @@ PRIVATE>
 : <query> ( collection assoc -- mdb-query-msg )
     <mdb-query-msg> ; inline
 
-GENERIC# limit 1 ( mdb-query-msg limit# -- mdb-query-msg )
-
-M: mdb-query-msg limit 
+: limit ( mdb-query-msg limit# -- mdb-query-msg )
     >>return# ; inline
 
-GENERIC# skip 1 ( mdb-query-msg skip# -- mdb-query-msg )
-
-M: mdb-query-msg skip 
+: skip ( mdb-query-msg skip# -- mdb-query-msg )
     >>skip# ; inline
 
 : asc ( key -- spec ) 1 2array ; inline
 : desc ( key -- spec ) -1 2array ; inline
 
 : sort ( mdb-query-msg sort-quot -- mdb-query-msg )
-    output>array [ 1array >hashtable ] map >>orderby ; inline
+    output>array >hashtable >>orderby ; inline
+
+: filter-fields ( mdb-query-msg filterseq -- mdb-query-msg )
+    [ asc ] map >hashtable >>returnfields ; inline
 
 : key-spec ( spec-quot -- spec-assoc )
     output>array >hashtable ; inline
@@ -209,21 +206,15 @@ M: mdb-query-msg find
 M: mdb-cursor find
     get-more ;
 
-GENERIC: explain. ( mdb-query-msg -- )
-
-M: mdb-query-msg explain.
+: explain. ( mdb-query-msg -- )
     t >>explain find nip . ;
 
-GENERIC: find-one ( mdb-query-msg -- result/f )
-
-M: mdb-query-msg find-one
+: find-one ( mdb-query-msg -- result/f )
     fix-query-collection 
     1 >>return# send-query-plain objects>>
     dup empty? [ drop f ] [ first ] if ;
 
-GENERIC: count ( mdb-query-msg -- result )
-
-M: mdb-query-msg count    
+: count ( mdb-query-msg -- result )
     [ collection>> "count" H{ } clone [ set-at ] keep ] keep
     query>> [ over [ "query" ] dip set-at ] when*
     [ cmd-collection ] dip <mdb-query-msg> find-one 
@@ -251,18 +242,15 @@ M: mdb-collection validate.
 
 PRIVATE>
 
-GENERIC: save ( collection assoc -- )
-M: assoc save
+: save ( collection assoc -- )
     [ check-collection ] dip
     <mdb-insert-msg> send-message-check-error ;
 
-GENERIC: save-unsafe ( collection assoc -- )
-M: assoc save-unsafe
+: save-unsafe ( collection assoc -- )
     [ check-collection ] dip
     <mdb-insert-msg> send-message ;
 
-GENERIC: ensure-index ( index-spec -- )
-M: index-spec ensure-index
+: ensure-index ( index-spec -- )
     <linked-hash> [ [ uuid1 "_id" ] dip set-at ] keep
     [ { [ [ name>> "name" ] dip set-at ]
         [ [ ns>> index-ns "ns" ] dip set-at ]
@@ -285,24 +273,23 @@ M: index-spec ensure-index
 : >upsert ( mdb-update-msg -- mdb-update-msg )
     1 >>upsert? ; 
 
-GENERIC: update ( mdb-update-msg -- )
-M: mdb-update-msg update
+: update ( mdb-update-msg -- )
     send-message-check-error ;
 
-GENERIC: update-unsafe ( mdb-update-msg -- )
-M: mdb-update-msg update-unsafe
+: update-unsafe ( mdb-update-msg -- )
     send-message ;
  
-GENERIC: delete ( collection selector -- )
-M: assoc delete
+: delete ( collection selector -- )
     [ check-collection ] dip
     <mdb-delete-msg> send-message-check-error ;
 
-GENERIC: delete-unsafe ( collection selector -- )
-M: assoc delete-unsafe
+: delete-unsafe ( collection selector -- )
     [ check-collection ] dip
     <mdb-delete-msg> send-message ;
 
+: kill-cursor ( mdb-cursor -- )
+    id>> <mdb-killcursors-msg> send-message ;
+
 : load-index-list ( -- index-list )
     index-collection
     H{ } clone <mdb-query-msg> find nip ;
index c48634679507caa304149e9a35507b0905b70b21..ada0ab42d06dcdc18e41a1141957eaf89d0a462e 100644 (file)
@@ -29,7 +29,7 @@ TUPLE: mdb-query-msg < mdb-msg
 { return# integer initial: 0 }
 { query assoc }
 { returnfields assoc }
-{ orderby sequence }
+{ orderby assoc }
 explain hint ;
 
 TUPLE: mdb-insert-msg < mdb-msg
index 7e99c52aacf6d95085815e7ceef72565fb26f1eb..108f61094083fca6373fcde8c87ddf6dba53715f 100644 (file)
@@ -107,7 +107,7 @@ USE: tools.walker
 
 :: build-query-object ( query -- selector )
     H{ } clone :> selector
-    query { [ orderby>> [ "orderby" selector set-at ] when* ]
+    query { [ orderby>> [ "$orderby" selector set-at ] when* ]
       [ explain>> [ "$explain" selector set-at ] when* ]
       [ hint>> [ "$hint" selector set-at ] when* ] 
       [ query>> "query" selector set-at ]
index de131df3c6a84b4a3217dd7f3a37934c88318063..6bed6d5f32ee18f7dae771236ce64cd31b342770 100644 (file)
@@ -21,7 +21,7 @@ SYMBOL: total
 : canonicalize-specializer-1 ( specializer -- specializer' )
     [
         [ class? ] filter
-        [ length <reversed> [ 1 + neg ] map ] keep zip
+        [ length iota <reversed> [ 1 + neg ] map ] keep zip
         [ length args [ max ] change ] keep
     ]
     [
@@ -111,7 +111,7 @@ SYMBOL: total
     swap "predicate" word-prop append ;
 
 : multi-predicate ( classes -- quot )
-    dup length <reversed>
+    dup length iota <reversed>
     [ picker 2array ] 2map
     [ drop object eq? not ] assoc-filter
     [ [ t ] ] [
diff --git a/extra/noise/noise-tests.factor b/extra/noise/noise-tests.factor
new file mode 100644 (file)
index 0000000..e216637
--- /dev/null
@@ -0,0 +1,4 @@
+IN: noise.tests
+USING: noise tools.test sequences math ;
+
+[ t ] [ { 100 100 } perlin-noise-map-coords [ [ 100 <= ] all? ] all? ] unit-test
index a27cc186a0d58a43d31b81accae787dd8ba57587..9204fa55f124473314b2f452a7ff8e0e5fb9cd0a 100644 (file)
@@ -120,7 +120,7 @@ TYPED:: perlin-noise ( table: byte-array point: float-4 -- value: float )
     faded trilerp ;
 
 MEMO: perlin-noise-map-coords ( dim -- coords )
-    first2 [| x y | x [ y 0.0 0.0 float-4-boa ] float-4-array{ } map-as ] with map concat ; 
+    first2 iota [| x y | x iota [ y 0.0 0.0 float-4-boa ] float-4-array{ } map-as ] with map concat ;
 
 TYPED:: perlin-noise-map ( table: byte-array transform: matrix4 coords: float-4-array -- map: float-array )
     coords [| coord | table transform coord m4.v perlin-noise ] data-map( float-4 -- c:float )
index e3d8cb7fd91036be60d2c339b8c006b60142ae54..fb7f00f62912d0a69591202e782ba2fbc5e98f47 100644 (file)
@@ -6,7 +6,7 @@ SYMBOL: sum
 
 : range ( r from to -- n )
     over - 1 + rot [ 
-        '[ over + @ drop ] each drop f
+        '[ over + @ drop ] each-integer drop f
     ] bshift 2nip ; inline
 
 [ 55 ] [
index d59b9103449c5832c57fc9770bc35693764afa3e..5bf44eddc6ef1eb0ff164cec80d34f24d88593dd 100644 (file)
@@ -47,14 +47,14 @@ PRIVATE>
 
 
 : euler001b ( -- answer )
-    1000 [0,b) [ [ 5 mod ] [ 3 mod ] bi [ 0 = ] either? ] filter sum ;
+    1000 iota [ [ 5 mod ] [ 3 mod ] bi [ 0 = ] either? ] filter sum ;
 
 ! [ euler001b ] 100 ave-time
 ! 0 ms ave run time - 0.06 SD (100 trials)
 
 
 : euler001c ( -- answer )
-    1000 [0,b) [ { 3 5 } [ divisor? ] with any? ] filter sum ;
+    1000 iota [ { 3 5 } [ divisor? ] with any? ] filter sum ;
 
 ! [ euler001c ] 100 ave-time
 ! 0 ms ave run time - 0.06 SD (100 trials)
index beed787fba1504fb86708b992623b3e386fa72bb..241fc2b626355c7ff0f14387367225a3dd7164c3 100644 (file)
@@ -72,12 +72,12 @@ IN: project-euler.011
 
 : pad-front ( matrix -- matrix )
     [
-        length [ 0 <repetition> ] map
+        length iota [ 0 <repetition> ] map
     ] keep [ append ] 2map ;
 
 : pad-back ( matrix -- matrix )
     <reversed> [
-        length [ 0 <repetition> ] map
+        length iota [ 0 <repetition> ] map
     ] keep [ <reversed> append ] 2map ;
 
 : diagonal/ ( -- matrix )
index 49680177d525fb57bb69218141e32e270b1ab91c..cbf45c9e326281ab44a10276424cb421d97aa6cf 100644 (file)
@@ -47,7 +47,7 @@ PRIVATE>
     [ [ dup 1 > ] [ dup , next-collatz ] while , ] { } make ;
 
 : euler014 ( -- answer )
-    1000000 [1,b] 0 [ collatz longest ] reduce first ;
+    1000000 [1,b] { } [ collatz longest ] reduce first ;
 
 ! [ euler014 ] time
 ! 52868 ms run / 483 ms GC time
@@ -64,7 +64,7 @@ PRIVATE>
 PRIVATE>
 
 : euler014a ( -- answer )
-    500000 1000000 [a,b] 1 [
+    500000 1000000 [a,b] { 1 } [
         dup worth-calculating? [ collatz longest ] [ drop ] if
     ] reduce first ;
 
index f6b4d497c070ae45150178a0166e5b42e1c09717..71e44ccb1e925dc09570a8274a19d21a46da8eb7 100644 (file)
@@ -1,6 +1,7 @@
 ! Copyright (c) 2008 Aaron Schaefer.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: kernel math.combinatorics math.parser project-euler.common ;
+USING: kernel math.combinatorics math.parser project-euler.common
+sequences ;
 IN: project-euler.024
 
 ! http://projecteuler.net/index.php?section=problems&id=24
@@ -23,7 +24,7 @@ IN: project-euler.024
 ! --------
 
 : euler024 ( -- answer )
-    999999 10 permutation 10 digits>integer ;
+    999999 10 iota permutation 10 digits>integer ;
 
 ! [ euler024 ] 100 ave-time
 ! 0 ms ave run time - 0.27 SD (100 trials)
index f97d8e9e0ddd700dc6b2b339a817d980c0d36908..0c697236aaa63d86dc05e17d46853db172e5c23c 100644 (file)
@@ -46,7 +46,7 @@ IN: project-euler.027
 <PRIVATE
 
 : source-027 ( -- seq )
-    1000 [0,b) [ prime? ] filter [ dup [ neg ] map append ] keep
+    1000 iota [ prime? ] filter [ dup [ neg ] map append ] keep
     cartesian-product [ first2 < ] filter ;
 
 : quadratic ( b a n -- m )
index 25d78d9465f58b533dcffe60980e7cdd6151b89a..6db9707f7323385378927b03e6e727d1b20ecfc1 100644 (file)
@@ -38,7 +38,7 @@ IN: project-euler.030
 PRIVATE>
 
 : euler030 ( -- answer )
-    325537 [0,b) [ dup sum-fifth-powers = ] filter sum 1 - ;
+    325537 iota [ dup sum-fifth-powers = ] filter sum 1 - ;
 
 ! [ euler030 ] 100 ave-time
 ! 1700 ms ave run time - 64.84 SD (100 trials)
index 814f8a5a6382d92187e616db9901315fc33d8a6e..8fb7a2bfaa8c83b45d0d8d7203cb1fb6ac3b1a46 100644 (file)
@@ -28,7 +28,7 @@ IN: project-euler.032
 
 : source-032 ( -- seq )
     9 factorial iota [
-        9 permutation [ 1 + ] map 10 digits>integer
+        9 iota permutation [ 1 + ] map 10 digits>integer
     ] map ;
 
 : 1and4 ( n -- ? )
index cf4955750636a769bdb4ba2e88086991ae5109e9..4991d65a895c4f7c032ed0f68c134d774c35d23b 100644 (file)
@@ -40,13 +40,13 @@ IN: project-euler.043
 
 : interesting? ( seq -- ? )
     {
-        [ 17 8 rot subseq-divisible? ]
-        [ 13 7 rot subseq-divisible? ]
-        [ 11 6 rot subseq-divisible? ]
-        [ 7  5 rot subseq-divisible? ]
-        [ 5  4 rot subseq-divisible? ]
-        [ 3  3 rot subseq-divisible? ]
-        [ 2  2 rot subseq-divisible? ]
+        [ [ 17 8 ] dip subseq-divisible? ]
+        [ [ 13 7 ] dip subseq-divisible? ]
+        [ [ 11 6 ] dip subseq-divisible? ]
+        [ [ 7  5 ] dip subseq-divisible? ]
+        [ [ 5  4 ] dip subseq-divisible? ]
+        [ [ 3  3 ] dip subseq-divisible? ]
+        [ [ 2  2 ] dip subseq-divisible? ]
     } 1&& ;
 
 PRIVATE>
@@ -82,7 +82,7 @@ PRIVATE>
     [ unclip 1 head prefix concat ] map [ all-unique? ] filter ;
 
 : add-missing-digit ( seq -- seq )
-    dup natural-sort 10 swap diff prepend ;
+    dup natural-sort 10 iota swap diff prepend ;
 
 : interesting-pandigitals ( -- seq )
     17 candidates { 13 11 7 5 3 2 } [
index 037cc87288420e13ab0823aaaef63ba22287663d..ae603c81fd498bf4f1e96c2139bc231b476e4cfd 100644 (file)
@@ -24,7 +24,7 @@ IN: project-euler.052
 <PRIVATE
 
 : map-nx ( n x -- seq )
-    [ 1 + * ] with map ; inline
+    iota [ 1 + * ] with map ; inline
 
 : all-same-digits? ( seq -- ? )
     [ number>digits natural-sort ] map all-equal? ;
index faca6a8ad56ce5c372767e0683282937ffb4f226..2e2d31740192e3df3f9181cd66a1f5b79732de2e 100644 (file)
@@ -27,7 +27,7 @@ IN: project-euler.053
 ! --------
 
 : euler053 ( -- answer )
-    23 100 [a,b] [ dup [ nCk 1000000 > ] with count ] map-sum ;
+    23 100 [a,b] [ dup iota [ nCk 1000000 > ] with count ] map-sum ;
 
 ! [ euler053 ] 100 ave-time
 ! 52 ms ave run time - 4.44 SD (100 trials)
index 09663d241fea5b13a467e0f72fd304faa96d9e7f..1d8967ff6ce68b3961e3a602e3c4265189f0ce2c 100644 (file)
@@ -61,7 +61,7 @@ IN: project-euler.055
 PRIVATE>
 
 : euler055 ( -- answer )
-    10000 [0,b) [ lychrel? ] count ;
+    10000 iota [ lychrel? ] count ;
 
 ! [ euler055 ] 100 ave-time
 ! 478 ms ave run time - 30.63 SD (100 trials)
index 97789944fe9b74ced76c1bfa7c19f53110f55273..4e35c9da58b2358bad80ef72099adae145857489 100644 (file)
@@ -36,7 +36,7 @@ IN: project-euler.057
     >fraction [ number>string length ] bi@ > ; inline
 
 : euler057 ( -- answer )
-    0 1000 [0,b) [ drop 2 + recip dup 1 + longer-numerator? ] count nip ;
+    0 1000 iota [ drop 2 + recip dup 1 + longer-numerator? ] count nip ;
 
 ! [ euler057 ] 100 ave-time
 ! 1728 ms ave run time - 80.81 SD (100 trials)
index 35bc1f10678f184237c0f9e14dfff56a2e27b1db..cc5e93d7a86412702e52cf175c1151c1b3162273 100644 (file)
@@ -60,7 +60,7 @@ IN: project-euler.081
     3dup minimal-path-sum-to '[ _ + ] change-matrix ;
 
 : (euler081) ( matrix -- n )
-    dup first length [0,b) dup cartesian-product
+    dup first length iota dup cartesian-product
     [ first2 pick update-minimal-path-sum ] each
     last last ;
 
index e6278a1e172297e77e4b7105274340352138ddb9..6e64d6ad3080a491121c003aca5ba5bc5f28f32e 100644 (file)
@@ -55,9 +55,9 @@ IN: project-euler.150
 
 :: (euler150) ( m -- n )
     sums-triangle :> table
-    m [| x |
-        x 1 + [| y |
-            m x - [0,b) [| z |
+    m iota [| x |
+        x 1 + iota [| y |
+            m x - iota [| z |
                 x z + table nth-unsafe
                 [ y z + 1 + swap nth-unsafe ]
                 [ y        swap nth-unsafe ] bi -
index ccdb76d80e05ca679f5b464c27b6adf5bb9fd396..b8db55e886e00421e9f7a1443b99540faff6f4e5 100644 (file)
@@ -62,7 +62,7 @@ DEFER: (euler151)
         { { 0 0 1 0 } [ { 0 0 0 1 } (euler151) 1 + ] }
         { { 0 1 0 0 } [ { 0 0 1 1 } (euler151) 1 + ] }
         { { 1 0 0 0 } [ { 0 1 1 1 } (euler151) 1 + ] }
-        [ [ dup length [ pick-sheet ] with map sum ] [ sum ] bi / ]
+        [ [ dup length iota [ pick-sheet ] with map sum ] [ sum ] bi / ]
      } case ] cache ;
 
 : euler151 ( -- answer )
index af8b7e49c064d3de79794f7602ce04f4edf0dbc7..be5d40df9b92aefd9405ab47c8fa0e6a1f5003bd 100644 (file)
@@ -18,7 +18,7 @@ IN: project-euler.164
 <PRIVATE
 
 : next-keys ( key -- keys )
-    [ last ] [ 10 swap sum - ] bi [ 2array ] with map ;
+    [ last ] [ 10 swap sum - iota ] bi [ 2array ] with map ;
 
 : next-table ( assoc -- assoc )
     H{ } clone swap
index 9eb9e968ca161c60b1f679206b873d88bf2772a4..a84f4fa48b3aff39506e2713581a89bc6fa142e4 100644 (file)
@@ -39,7 +39,7 @@ IN: project-euler.common
 <PRIVATE
 
 : max-children ( seq -- seq )
-    [ dup length 1 - [ nth-pair max , ] with each ] { } make ;
+    [ dup length 1 - iota [ nth-pair max , ] with each ] { } make ;
 
 ! Propagate one row into the upper one
 : propagate ( bottom top -- newtop )
index 19b0dead484fc094396d936dae56544eac9b4747..fe552a77a1d6e9d9cc095d64b0e55e70c84e146b 100644 (file)
@@ -1,4 +1,4 @@
-! Copyright (C) 2007, 2009 Slava Pestov.
+! Copyright (C) 2007, 2010 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
 USING: arrays hashtables help.markup help.stylesheet io
 io.styles kernel math models namespaces sequences ui ui.gadgets
@@ -94,7 +94,7 @@ TUPLE: slides < book ;
     [ first3 ] dip head 3array ;
 
 : strip-tease ( data -- seq )
-    dup third length 1 - [
+    dup third length 1 - iota [
         2 + (strip-tease)
     ] with map ;
 
index 81b38f2c1450946e8794fb2f017a21b0d519575e..afbeea61108daac1f2af7943404ffef7e0593afa 100644 (file)
@@ -10,7 +10,7 @@ IN: smalltalk.compiler.tests
     ] with-compilation-unit ;
 
 : test-inference ( ast -- in# out# )
-    test-compilation infer [ in>> ] [ out>> ] bi ;
+    test-compilation infer [ in>> ] [ out>> ] bi [ length ] bi@ ;
 
 [ 2 1 ] [
     T{ ast-block f
index 2ea1e99afd1ce349fa6e1871f449c756d7a63192..609498634574e2eb834adca3f4f186f524d7e50c 100644 (file)
@@ -1,6 +1,6 @@
-! Copyright (C) 2009 Slava Pestov.
+! Copyright (C) 2009, 2010 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: combinators effects generic generic.standard
+USING: arrays combinators effects generic generic.standard
 kernel sequences words lexer ;
 IN: smalltalk.selectors
 
@@ -15,9 +15,9 @@ SYMBOLS: unary binary keyword ;
 
 : selector>effect ( selector -- effect )
     dup selector-type {
-        { unary [ drop 0 ] }
-        { binary [ drop 1 ] }
-        { keyword [ [ CHAR: : = ] count ] }
+        { unary [ drop { } ] }
+        { binary [ drop { "x" } ] }
+        { keyword [ [ CHAR: : = ] count "x" <array> ] }
     } case "receiver" suffix { "result" } <effect> ;
 
 : selector>generic ( selector -- generic )
diff --git a/extra/sudoku/sudoku-tests.factor b/extra/sudoku/sudoku-tests.factor
new file mode 100644 (file)
index 0000000..60babf0
--- /dev/null
@@ -0,0 +1,4 @@
+IN: sudoku.tests
+USING: tools.test sudoku ;
+
+[ ] [ sudoku-demo ] unit-test
index 555f1e632a580b489131907d0b7d5259a597074f..848d647fe0561a91aac8d4453cde14bb4737f671 100644 (file)
@@ -19,7 +19,7 @@ SYMBOL: board
 
 : box-any? ( n x y -- ? )
     [ 3 /i 3 * ] bi@
-    9 [ [ 3dup ] dip cell-any? ] any?
+    9 iota [ [ 3dup ] dip cell-any? ] any?
     [ 3drop ] dip ;
 
 DEFER: search
@@ -35,7 +35,7 @@ DEFER: search
         [ assume ]
     } cond ;
 
-: solve ( x y -- ) 9 [ 1 + 2over attempt ] each 2drop ;
+: solve ( x y -- ) 9 [ 1 + 2over attempt ] each-integer 2drop ;
 
 : board. ( board -- )
     standard-table-style [
@@ -52,7 +52,7 @@ DEFER: search
                 ] each
             ] with-row
         ] each
-    ] tabular-output ;
+    ] tabular-output nl ;
 
 : solution. ( -- )
     solutions inc "Solution:" print board get board. ;
index 251f60e6d7ddedab514ee9815b1da9cc37f6cecd..4541a15eca34c04cad80305d4bbb701921d049d5 100644 (file)
@@ -9,6 +9,7 @@ ERROR: fica-base-unknown ;
 
 : fica-base-rate ( year -- x )
     H{
+        { 2009 106800 }
         { 2008 102000 }
         { 2007  97500 }
     } at [ fica-base-unknown ] unless* ;
index 1f12dcabe6454a5dd02ecc0651c2d255b40f05a4..2346999bcbc822ae69686dad6b97e191470d8842 100644 (file)
@@ -6,7 +6,7 @@ IN: tetris.board
 TUPLE: board { width integer } { height integer } rows ;
 
 : make-rows ( width height -- rows )
-    [ drop f <array> ] with map ;
+    iota [ drop f <array> ] with map ;
 
 : <board> ( width height -- board )
     2dup make-rows board boa ;
@@ -24,8 +24,8 @@ TUPLE: board { width integer } { height integer } rows ;
 : block-free? ( board block -- ? ) block not ;
 
 : block-in-bounds? ( board block -- ? )
-    [ first swap width>> bounds-check? ] 2keep
-    second swap height>> bounds-check? and ;
+    [ first swap width>> iota bounds-check? ]
+    [ second swap height>> iota bounds-check? ] 2bi and ;
 
 : location-valid? ( board block -- ? )
     2dup block-in-bounds? [ block-free? ] [ 2drop f ] if ;
index 0169249e81952ffe15cf1f86394d798c8721a5b4..8326da35842d586c979dc179b37ef472be584dc9 100644 (file)
@@ -26,10 +26,10 @@ IN: tetris.gl
     [ gl-color 2array draw-block ] [ 3drop ] if ;
 
 : draw-row ( y row -- )
-    dup length -rot [ (draw-row) ] 2curry each ;
+    [ length iota swap ] keep [ (draw-row) ] 2curry each ;
 
 : draw-board ( board -- )
-    rows>> dup length swap
+    rows>> [ length iota ] keep
     [ dupd nth draw-row ] curry each ;
 
 : scale-board ( width height board -- )
index c07357fbdf7a5ba91a25fad87c6de7a962478fdb..d858a14795d9c38d4df347ea24cd524c7c54129f 100644 (file)
@@ -5,10 +5,10 @@ sequences random sets make grouping ;
 IN: trees.splay.tests
 
 : randomize-numeric-splay-tree ( splay-tree -- )
-    100 [ drop 100 random swap at drop ] with each ;
+    100 iota [ drop 100 random swap at drop ] with each ;
 
 : make-numeric-splay-tree ( n -- splay-tree )
-    <splay> [ [ conjoin ] curry each ] keep ;
+    iota <splay> [ [ conjoin ] curry each ] keep ;
 
 [ t ] [
     100 make-numeric-splay-tree dup randomize-numeric-splay-tree
index 1d7e6f9cc67600c1bcf25be756d0d2169ee655e1..8b137891791fe96927ad78e64b0aad7bded08bdc 100644 (file)
@@ -1 +1 @@
-PLAF_DLL_OBJS += vmpp/cpu-arm.o
+
index b0b1352cb244f96949d6420af3cfd597a62d3758..11df4035416f159627d33886c462dd06ec318147 100644 (file)
@@ -1,4 +1,4 @@
-CFLAGS += -DWINDOWS -mno-cygwin
+CFLAGS += -mno-cygwin
 LIBS = -lm
 PLAF_DLL_OBJS += vm/os-windows.o
 SHARED_FLAG = -shared
index b7f8bc65f0ec6ee3f3666677fc05cd1565d2780e..8b137891791fe96927ad78e64b0aad7bded08bdc 100644 (file)
@@ -1,2 +1 @@
-BOOT_ARCH = x86
-PLAF_DLL_OBJS += vm/cpu-x86.32.o
+
index 63f06d5a786337245463030ce0ee22f7f1be8d40..8b137891791fe96927ad78e64b0aad7bded08bdc 100644 (file)
@@ -1,2 +1 @@
-PLAF_DLL_OBJS += vm/cpu-x86.64.o
-CFLAGS += -DFACTOR_64
+
diff --git a/vm/asm.h b/vm/asm.h
deleted file mode 100644 (file)
index 9719ae8..0000000
--- a/vm/asm.h
+++ /dev/null
@@ -1,16 +0,0 @@
-#if defined(__APPLE__) || (defined(WINDOWS) && !defined(__arm__))
-       #define MANGLE(sym) _##sym
-#else
-       #define MANGLE(sym) sym
-#endif
-
-/* Apple's PPC assembler is out of date? */
-#if defined(__APPLE__) && defined(__ppc__)
-       #define XX @
-#else
-       #define XX ;
-#endif
-
-/* The returns and args are just for documentation */
-#define DEF(returns,symbol,args) .globl MANGLE(symbol) XX \
-MANGLE(symbol)
index 061c42927d4b47864b5c4792515855e194544f59..ebb66bae129d860cdf3fea9f2166341b0fd81e60 100644 (file)
@@ -19,13 +19,13 @@ void factor_vm::init_callbacks(cell size)
        callbacks = new callback_heap(size,this);
 }
 
-void callback_heap::update(code_block *stub)
+void callback_heap::store_callback_operand(code_block *stub, cell index, cell value)
 {
        tagged<array> code_template(parent->special_objects[CALLBACK_STUB]);
 
-       cell rel_class = untag_fixnum(array_nth(code_template.untagged(),1));
-       cell rel_type = untag_fixnum(array_nth(code_template.untagged(),2));
-       cell offset = untag_fixnum(array_nth(code_template.untagged(),3));
+       cell rel_class = untag_fixnum(array_nth(code_template.untagged(),3 * index + 1));
+       cell rel_type  = untag_fixnum(array_nth(code_template.untagged(),3 * index + 2));
+       cell offset    = untag_fixnum(array_nth(code_template.untagged(),3 * index + 3));
 
        relocation_entry rel(
                (relocation_type)rel_type,
@@ -33,8 +33,12 @@ void callback_heap::update(code_block *stub)
                offset);
 
        instruction_operand op(rel,stub,0);
-       op.store_value((cell)callback_xt(stub));
+       op.store_value(value);
+}
 
+void callback_heap::update(code_block *stub)
+{
+       store_callback_operand(stub,1,(cell)callback_xt(stub));
        stub->flush_icache();
 }
 
@@ -58,22 +62,14 @@ code_block *callback_heap::add(cell owner, cell return_rewind)
 
        memcpy(stub->xt(),insns->data<void>(),size);
 
+       /* Store VM pointer */
+       store_callback_operand(stub,0,(cell)parent);
+
        /* On x86, the RET instruction takes an argument which depends on
        the callback's calling convention */
-       if(array_capacity(code_template.untagged()) == 7)
-       {
-               cell rel_class = untag_fixnum(array_nth(code_template.untagged(),4));
-               cell rel_type = untag_fixnum(array_nth(code_template.untagged(),5));
-               cell offset = untag_fixnum(array_nth(code_template.untagged(),6));
-
-               relocation_entry rel(
-                       (relocation_type)rel_type,
-                       (relocation_class)rel_class,
-                       offset);
-
-               instruction_operand op(rel,stub,0);
-               op.store_value(return_rewind);
-       }
+#if defined(FACTOR_X86) || defined(FACTOR_AMD64)
+       store_callback_operand(stub,2,return_rewind);
+#endif
 
        update(stub);
 
index 136d9b82b4971e1ccf96534d77f0d946544f2f43..0bed3f406d3ddad3391faad268fd314150ad953d 100644 (file)
@@ -38,7 +38,10 @@ struct callback_heap {
                return w->xt;
        }
 
+       void store_callback_operand(code_block *stub, cell index, cell value);
+
        void update(code_block *stub);
+
        code_block *add(cell owner, cell return_rewind);
 
        void update();
index 714a4585c3f94c1e61aa60b511c8b4e2e188b28a..b6742534b90a31ee91df7431bd2dab1f6c08f22d 100755 (executable)
@@ -60,20 +60,6 @@ void factor_vm::primitive_callstack()
        ctx->push(tag<callstack>(stack));
 }
 
-void factor_vm::primitive_set_callstack()
-{
-       callstack *stack = untag_check<callstack>(ctx->pop());
-
-       set_callstack(this,
-               ctx->callstack_bottom,
-               stack->top(),
-               untag_fixnum(stack->length),
-               memcpy);
-
-       /* We cannot return here ... */
-       critical_error("Bug in set_callstack()",0);
-}
-
 code_block *factor_vm::frame_code(stack_frame *frame)
 {
        check_frame(frame);
index 0624adb268b5fe0545d43004f6f133f25c91b4ac..dce82843f810a434114428e64d16933ce1d98411 100644 (file)
@@ -72,8 +72,6 @@ void code_block_visitor<Visitor>::visit_object_code_block(object *obj)
                        quotation *q = (quotation *)obj;
                        if(q->code)
                                parent->set_quot_xt(q,visitor(q->code));
-                       else
-                               q->xt = (void *)lazy_jit_compile_impl;
                        break;
                }
        case CALLSTACK_TYPE:
index ec7a0e8998e74066f2bed3e4e9c6413c2522a615..d72d30cc962c18a08a2869799084c609198571f1 100755 (executable)
@@ -24,7 +24,7 @@ cell factor_vm::compute_xt_pic_address(word *w, cell tagged_quot)
        else
        {
                quotation *quot = untag<quotation>(tagged_quot);
-               if(quot->code)
+               if(quot_compiled_p(quot))
                        return (cell)quot->xt;
                else
                        return (cell)w->xt;
diff --git a/vm/cpu-arm.S b/vm/cpu-arm.S
deleted file mode 100644 (file)
index 09e3331..0000000
+++ /dev/null
@@ -1,127 +0,0 @@
-#include "asm.h"
-
-/* Note that the XT is passed to the quotation in r12 */
-#define CALL_QUOT \
-        ldr r12,[r0, #9]     /* load quotation-xt slot */ ; \
-       mov lr,pc ; \
-        mov pc,r12
-
-#define JUMP_QUOT \
-        ldr r12,[r0, #9]     /* load quotation-xt slot */ ; \
-       mov pc,r12
-
-#define SAVED_REGS_SIZE 32
-
-#define FRAME (RESERVED_SIZE + SAVED_REGS_SIZE + 8)
-
-#define LR_SAVE [sp, #-4]
-#define RESERVED_SIZE 8
-
-#define SAVE_LR str lr,LR_SAVE
-
-#define LOAD_LR ldr lr,LR_SAVE
-
-#define SAVE_AT(offset) (RESERVED_SIZE + 4 * offset)
-
-#define SAVE(register,offset) str register,[sp, #SAVE_AT(offset)]
-
-#define RESTORE(register,offset) ldr register,[sp, #SAVE_AT(offset)]
-
-#define PROLOGUE \
-       SAVE_LR ; \
-       sub sp,sp,#FRAME
-
-#define EPILOGUE \
-       add sp,sp,#FRAME ; \
-       LOAD_LR
-
-DEF(void,c_to_factor,(CELL quot)):
-        PROLOGUE
-
-       SAVE(r4,0)           /* save GPRs */
-                             /* don't save ds pointer */
-                             /* don't save rs pointer */
-        SAVE(r7,3)
-        SAVE(r8,4)
-        SAVE(r9,5)
-        SAVE(r10,6)
-        SAVE(r11,7)
-       SAVE(r0,8)           /* save quotation since we're about to mangle it */
-
-        sub r0,sp,#4         /* pass call stack pointer as an argument */
-       bl MANGLE(save_callstack_bottom)
-
-       RESTORE(r0,8)        /* restore quotation */
-        CALL_QUOT
-
-        RESTORE(r11,7)       /* restore GPRs */
-        RESTORE(r10,6)
-        RESTORE(r9,5)
-        RESTORE(r8,4)
-        RESTORE(r7,3)
-                             /* don't restore rs pointer */
-                             /* don't restore ds pointer */
-        RESTORE(r4,0)
-
-        EPILOGUE
-        mov pc,lr
-
-/* The JIT compiles an 'mov r1',sp in front of every primitive call, since a
-word which was defined as a primitive will not change its definition for the
-lifetime of the image -- adding new primitives requires a bootstrap. However,
-an undefined word can certainly become defined,
-
-DEFER: foo
-...
-: foo ... ;
-
-And calls to non-primitives do not have this one-instruction prologue, so we
-set the XT of undefined words to this symbol. */
-DEF(void,undefined,(CELL word)):
-       sub r1,sp,#4
-       b MANGLE(undefined_error)
-
-/* Here we have two entry points. The first one is taken when profiling is
-enabled */
-DEF(void,docol_profiling,(CELL word)):
-        ldr r1,[r0, #25]     /* load profile-count slot */
-        add r1,r1,#8         /* increment count */
-        str r1,[r0, #25]     /* store profile-count slot */
-DEF(void,docol,(CELL word)):
-        ldr r0,[r0, #13]     /* load word-def slot */
-        JUMP_QUOT
-
-/* We must pass the XT to the quotation in r12. */
-DEF(void,primitive_call,(void)):
-        ldr r0,[r5], #-4     /* load quotation from data stack */
-        JUMP_QUOT
-
-/* We must preserve r1 here in case we're calling a primitive */
-DEF(void,primitive_execute,(void)):
-        ldr r0,[r5], #-4     /* load word from data stack */
-        ldr pc,[r0, #29]     /* jump to word-xt */
-
-DEF(void,set_callstack,(F_STACK_FRAME *to, F_STACK_FRAME *from, CELL length)):
-        sub sp,r0,r2         /* compute new stack pointer */
-        mov r0,sp            /* start of destination of memcpy() */
-       sub sp,sp,#12        /* alignment */
-        bl MANGLE(memcpy)    /* go */
-       add sp,sp,#16        /* point SP at innermost frame */
-        ldr pc,LR_SAVE       /* return */
-
-DEF(void,throw_impl,(CELL quot, F_STACK_FRAME *rewind_to)):
-       add sp,r1,#4         /* compute new stack pointer */
-       ldr lr,LR_SAVE       /* we have rewound the stack; load return address */
-       JUMP_QUOT            /* call the quotation */
-
-DEF(void,lazy_jit_compile,(CELL quot)):
-       mov r1,sp            /* save stack pointer */
-       PROLOGUE
-       bl MANGLE(lazy_jit_compile_impl)
-       EPILOGUE
-        JUMP_QUOT            /* call the quotation */
-
-#ifdef WINCE
-       .section .drectve
-       .ascii " -export:c_to_factor"
-#endif
index b08e76382c07cd4a5dbeaecffe9845cef86b6d6a..e725c6d5962101cb2672ffc23d8dc08a2f324a49 100644 (file)
@@ -3,14 +3,6 @@ namespace factor
 
 #define FACTOR_CPU_STRING "arm"
 
-register cell ds asm("r5");
-register cell rs asm("r6");
-
 #define FRAME_RETURN_ADDRESS(frame,vm) *(XT *)(vm->frame_successor(frame) + 1)
 
-void c_to_factor(cell quot);
-void set_callstack(stack_frame *to, stack_frame *from, cell length, void *memcpy);
-void throw_impl(cell quot, stack_frame *rewind);
-void lazy_jit_compile(cell quot);
-
 }
index 772f4a24fcfe9f72a10c7543403c83166f30dba9..835ed14cc20a0a62f4cea8d2361052706da47663 100644 (file)
-/* Parts of this file were snarfed from SBCL src/runtime/ppc-assem.S, which is
-in the public domain. */
-#include "asm.h"
-
-#define DS_REG r13
-#define RS_REG r14
-#define VM_REG r15
-
-#define CALL_OR_JUMP_QUOT \
-       lwz r11,12(r3)     /* load quotation-xt slot */ XX \
-
-#define CALL_QUOT \
-       CALL_OR_JUMP_QUOT XX \
-       mtlr r11           /* prepare to call XT with quotation in r3 */ XX \
-       blrl               /* go */
-
-#define JUMP_QUOT \
-       CALL_OR_JUMP_QUOT XX \
-       mtctr r11          /* prepare to call XT with quotation in r3 */ XX \
-       bctr               /* go */
-
-#define PARAM_SIZE 32
-
-#define SAVED_INT_REGS_SIZE 96
-
-#define SAVED_FP_REGS_SIZE 144
-
-#define SAVED_V_REGS_SIZE 208
-
-#define FRAME (RESERVED_SIZE + PARAM_SIZE + SAVED_INT_REGS_SIZE + SAVED_FP_REGS_SIZE + SAVED_V_REGS_SIZE + 8)
-   
-#if defined( __APPLE__)
-       #define LR_SAVE 8
-       #define RESERVED_SIZE 24
+#if defined(__APPLE__)
+    #define MANGLE(sym) _##sym
+    #define XX @
 #else
-       #define LR_SAVE 4
-       #define RESERVED_SIZE 8
+    #define MANGLE(sym) sym
+    #define XX ;
 #endif
 
-#define SAVE_LR(reg) stw reg,(LR_SAVE + FRAME)(r1)
-
-#define LOAD_LR(reg) lwz reg,(LR_SAVE + FRAME)(r1)
-
-#define SAVE_AT(offset) (RESERVED_SIZE + PARAM_SIZE + 4 * offset)
-
-#define SAVE_INT(register,offset) stw register,SAVE_AT(offset)(r1)
-#define RESTORE_INT(register,offset) lwz register,SAVE_AT(offset)(r1)
-
-#define SAVE_FP(register,offset) stfd register,SAVE_AT(offset)(r1)
-#define RESTORE_FP(register,offset) lfd register,SAVE_AT(offset)(r1)
-
-#define SAVE_V(register,offset) \
-       li r2,SAVE_AT(offset) XX \
-       stvxl register,r2,r1
-
-#define RESTORE_V(register,offset) \
-       li r2,SAVE_AT(offset) XX \
-       lvxl register,r2,r1
-
-#define PROLOGUE \
-       mflr r0 XX         /* get caller's return address */ \
-       stwu r1,-FRAME(r1) XX /* create a stack frame to hold non-volatile registers */ \
-       SAVE_LR(r0)
-
-#define EPILOGUE \
-       LOAD_LR(r0) XX \
-       lwz r1,0(r1) XX    /* destroy the stack frame */ \
-       mtlr r0            /* get ready to return */
-
-/* We have to save and restore nonvolatile registers because
-the Factor compiler treats the entire register file as volatile. */
-DEF(void,c_to_factor,(cell quot, void *vm)):
-       PROLOGUE
-
-       SAVE_INT(r13,0)
-       SAVE_INT(r14,1)
-       SAVE_INT(VM_REG,2)
-       SAVE_INT(r16,3)
-       SAVE_INT(r17,4)
-       SAVE_INT(r18,5)
-       SAVE_INT(r19,6)
-       SAVE_INT(r20,7)
-       SAVE_INT(r21,8)
-       SAVE_INT(r22,9)
-       SAVE_INT(r23,10)
-       SAVE_INT(r24,11)
-       SAVE_INT(r25,12)
-       SAVE_INT(r26,13)
-       SAVE_INT(r27,14)
-       SAVE_INT(r28,15)
-       SAVE_INT(r29,16)
-       SAVE_INT(r30,17)
-       SAVE_INT(r31,18)
-
-       SAVE_FP(f14,20)
-       SAVE_FP(f15,22)
-       SAVE_FP(f16,24)
-       SAVE_FP(f17,26)
-       SAVE_FP(f18,28)
-       SAVE_FP(f19,30)
-       SAVE_FP(f20,32)
-       SAVE_FP(f21,34)
-       SAVE_FP(f22,36)
-       SAVE_FP(f23,38)
-       SAVE_FP(f24,40)
-       SAVE_FP(f25,42)
-       SAVE_FP(f26,44)
-       SAVE_FP(f27,46)
-       SAVE_FP(f28,48)
-       SAVE_FP(f29,50)
-       SAVE_FP(f30,52)
-       SAVE_FP(f31,54)
-
-       SAVE_V(v20,56)
-       SAVE_V(v21,60)
-       SAVE_V(v22,64)
-       SAVE_V(v23,68)
-       SAVE_V(v24,72)
-       SAVE_V(v25,76)
-       SAVE_V(v26,80)
-       SAVE_V(v27,84)
-       SAVE_V(v28,88)
-       SAVE_V(v29,92)
-       SAVE_V(v30,96)
-       SAVE_V(v31,100)
-
-       /* r4 vm ptr preserved */
-       mfvscr v0
-       li r2,SAVE_AT(104)
-       stvxl v0,r2,r1
-       addi r2,r2,0xc
-       lwzx r5,r2,r1
-       lis r6,0x1
-       andc r5,r5,r6
-       stwx r5,r2,r1
-       subi r2,r2,0xc
-       lvxl v0,r2,r1
-       mtvscr v0
-
-
-       /* Load context */
-       mr VM_REG,r4
-       lwz r16,0(VM_REG)
-
-       /* Load ctx->datastack */
-       lwz DS_REG,8(r16)
-
-       /* Load ctx->retainstack */
-       lwz RS_REG,12(r16)
-
-       /* Save ctx->callstack_bottom */
-       stw r1,4(r16)
-
-       CALL_QUOT
-
-       /* Load context */
-       lwz r16,0(VM_REG)
-
-       /* Save ctx->datastack */
-       stw DS_REG,8(r16)
-
-       /* Save ctx->retainstack */
-       stw RS_REG,12(r16)
-
-       RESTORE_V(v0,104)
-       mtvscr v0
-
-       RESTORE_V(v31,100)
-       RESTORE_V(v30,96)
-       RESTORE_V(v29,92)
-       RESTORE_V(v28,88)
-       RESTORE_V(v27,84)
-       RESTORE_V(v26,80)
-       RESTORE_V(v25,76)
-       RESTORE_V(v24,72)
-       RESTORE_V(v23,68)
-       RESTORE_V(v22,64)
-       RESTORE_V(v21,60)
-       RESTORE_V(v20,56)
-
-       RESTORE_FP(f31,54)
-       RESTORE_FP(f30,52)
-       RESTORE_FP(f29,50)
-       RESTORE_FP(f28,48)
-       RESTORE_FP(f27,46)
-       RESTORE_FP(f26,44)
-       RESTORE_FP(f25,42)
-       RESTORE_FP(f24,40)
-       RESTORE_FP(f23,38)
-       RESTORE_FP(f22,36)
-       RESTORE_FP(f21,34)
-       RESTORE_FP(f20,32)
-       RESTORE_FP(f19,30)
-       RESTORE_FP(f18,28)
-       RESTORE_FP(f17,26)
-       RESTORE_FP(f16,24)
-       RESTORE_FP(f15,22)
-       RESTORE_FP(f14,20)
-
-       RESTORE_INT(r31,18)
-       RESTORE_INT(r30,17)
-       RESTORE_INT(r29,16)
-       RESTORE_INT(r28,15)
-       RESTORE_INT(r27,14)
-       RESTORE_INT(r26,13)
-       RESTORE_INT(r25,12)
-       RESTORE_INT(r24,11)
-       RESTORE_INT(r23,10)
-       RESTORE_INT(r22,9)
-       RESTORE_INT(r21,8)
-       RESTORE_INT(r20,7)
-       RESTORE_INT(r19,6)
-       RESTORE_INT(r18,5)
-       RESTORE_INT(r17,4)
-       RESTORE_INT(r16,3)
-       RESTORE_INT(VM_REG,2)
-       RESTORE_INT(r14,1)
-       RESTORE_INT(r13,0)
-
-       EPILOGUE
-       blr
-
-DEF(void,set_callstack,(void *vm, stack_frame *to, stack_frame *from, cell length, void *memcpy)):
-       /* Save VM pointer in non-volatile register */
-       mr VM_REG,r3
-
-    /* Compute new stack pointer */
-       sub r1,r4,r6
-
-       /* Call memcpy() */
-       mr r3,r1
-       mr r4,r5
-       mr r5,r6
-       stwu r1,-64(r1)
-       mtlr r7
-       blrl
-       lwz r1,0(r1)
-
-       /* Load context */
-       lwz r16,0(VM_REG)
-
-       /* Load ctx->datastack */
-       lwz DS_REG,8(r16)
-
-       /* Load ctx->retainstack */
-       lwz RS_REG,12(r16)
-
-       /* We have changed the stack; load return address again */
-       lwz r0,LR_SAVE(r1)
-       mtlr r0
-       blr
-
-DEF(void,throw_impl,(cell quot, void *new_stack, void *vm)):
-       /* compute new stack pointer */
-       mr r1,r4
-
-       /* make vm ptr 2nd arg in case quot->xt == lazy_jit_compile */
-       mr r4,r5
-
-       /* Load context */
-       mr VM_REG,r5
-       lwz r16,0(VM_REG)
-
-       /* Load ctx->datastack */
-       lwz DS_REG,8(r16)
-
-       /* Load ctx->retainstack */
-       lwz RS_REG,12(r16)
-
-       /* We have changed the stack; load return address again */
-       lwz r0,LR_SAVE(r1)
-       mtlr r0
-
-       /* Call the quotation */
-       JUMP_QUOT
-
-DEF(void,lazy_jit_compile_impl,(cell quot, void *vm)):
-       /* Load context */
-       mr VM_REG,r4
-       lwz r16,0(VM_REG)
-
-       /* Save ctx->datastack */
-       stw DS_REG,8(r16)
-
-       /* Save ctx->retainstack */
-       stw RS_REG,12(r16)
-
-       /* Save ctx->callstack_top */
-       stw r1,0(r16)
-
-       /* Compile quotation */
-       PROLOGUE
-       bl MANGLE(lazy_jit_compile)
-       EPILOGUE
-
-       /* Call the quotation */
-       JUMP_QUOT
+/* The returns and args are just for documentation */
+#define DEF(returns,symbol,args) .globl MANGLE(symbol) XX \
+MANGLE(symbol)
 
 /* Thanks to Joshua Grams for this code.
 
 On PowerPC processors, we must flush the instruction cache manually
 after writing to the code heap. */
 
-DEF(void,flush_icache,(void *start, int len)):
-       /* compute number of cache lines to flush */
-       add r4,r4,r3
-       clrrwi r3,r3,5     /* align addr to next lower cache line boundary */
-       sub r4,r4,r3       /* then n_lines = (len + 0x1f) / 0x20 */
-       addi r4,r4,0x1f
-       srwi. r4,r4,5      /* note '.' suffix */
-       beqlr              /* if n_lines == 0, just return. */
-       mtctr r4           /* flush cache lines */
-0:     dcbf 0,r3          /* for each line... */
-       sync
-       icbi 0,r3
-       addi r3,r3,0x20
-       bdnz 0b
-       sync               /* finish up */
-       isync
-       blr
+DEF(void,flush_icache,(void*, int)):
+    /* compute number of cache lines to flush */
+    add r4,r4,r3
+    /* align addr to next lower cache line boundary */
+    clrrwi r3,r3,5
+    /* then n_lines = (len + 0x1f) / 0x20 */
+    sub r4,r4,r3
+    addi r4,r4,0x1f
+    /* note '.' suffix */
+    srwi. r4,r4,5
+    /* if n_lines == 0, just return. */
+    beqlr
+    /* flush cache lines */
+    mtctr r4
+    /* for each line... */
+0:  dcbf 0,r3
+    sync
+    icbi 0,r3
+    addi r3,r3,0x20
+    bdnz 0b
+    /* finish up */
+    sync
+    isync
+    blr
 
 DEF(void,get_ppc_fpu_env,(void*)):
-       mffs f0
-       stfd f0,0(r3)
-       blr
+    mffs f0
+    stfd f0,0(r3)
+    blr
 
 DEF(void,set_ppc_fpu_env,(const void*)):
-       lfd f0,0(r3)
-       mtfsf 0xff,f0
-       blr
+    lfd f0,0(r3)
+    mtfsf 0xff,f0
+    blr
 
 DEF(void,get_ppc_vmx_env,(void*)):
-       mfvscr v0
-       subi r4,r1,16
-       li r5,0xf
-       andc r4,r4,r5
-       stvxl v0,0,r4
-       li r5,0xc
-       lwzx r6,r5,r4
-       stw r6,0(r3)
-       blr
+    mfvscr v0
+    subi r4,r1,16
+    li r5,0xf
+    andc r4,r4,r5
+    stvxl v0,0,r4
+    li r5,0xc
+    lwzx r6,r5,r4
+    stw r6,0(r3)
+    blr
 
 DEF(void,set_ppc_vmx_env,(const void*)):
-       subi r4,r1,16
-       li r5,0xf
-       andc r4,r4,r5
-       li r5,0xc
-       lwz r6,0(r3)
-       stwx r6,r5,r4
-       lvxl v0,0,r4
-       mtvscr v0
-       blr
+    subi r4,r1,16
+    li r5,0xf
+    andc r4,r4,r5
+    li r5,0xc
+    lwz r6,0(r3)
+    stwx r6,r5,r4
+    lvxl v0,0,r4
+    mtvscr v0
+    blr
index f0f6f80ae355da0b00fbc719928ffbe0195afdeb..cd98d6a6ab553c7b90733416a89c5d43418d4969 100644 (file)
@@ -9,8 +9,8 @@ namespace factor
    B blah
 
    the offset from the immediate operand to LOAD32 to the instruction after
-   the branch is two instructions. */
-static const fixnum xt_tail_pic_offset = 4 * 2;
+   the branch is one instruction. */
+static const fixnum xt_tail_pic_offset = 4;
 
 inline static void check_call_site(cell return_address)
 {
@@ -77,16 +77,6 @@ inline static unsigned int fpu_status(unsigned int status)
 }
 
 /* Defined in assembly */
-VM_C_API void c_to_factor(cell quot, void *vm);
-VM_C_API void throw_impl(cell quot, void *new_stack, void *vm);
-VM_C_API void lazy_jit_compile_impl(cell quot, void *vm);
 VM_C_API void flush_icache(cell start, cell len);
 
-VM_C_API void set_callstack(
-       void *vm,
-       stack_frame *to,
-       stack_frame *from,
-       cell length,
-       void *(*memcpy)(void*,const void*, size_t));
-
 }
diff --git a/vm/cpu-x86.32.S b/vm/cpu-x86.32.S
deleted file mode 100644 (file)
index ee3ec25..0000000
+++ /dev/null
@@ -1,181 +0,0 @@
-#include "asm.h"
-
-#define DS_REG %esi
-#define RS_REG %edi
-#define RETURN_REG %eax
-
-#define QUOT_XT_OFFSET 12
-
-DEF(void,c_to_factor,(cell quot, void *vm)):
-       /* Load parameters */
-       mov 4(%esp),%eax
-       mov 8(%esp),%edx
-
-       /* Save non-volatile registers */
-       push %ebx
-       push %ebp
-       push %esi
-       push %edi
-
-       /* Save old stack pointer and align */
-       mov %esp,%ebx
-       and $-16,%esp
-       push %ebx
-
-       /* Set up stack frame for the call to the boot quotation */
-       sub $4,%esp
-       push %edx
-       push %eax
-
-       /* Load context */
-       mov (%edx),%ecx
-
-       /* Load ctx->datastack */
-       mov 8(%ecx),DS_REG
-
-       /* Load ctx->retainstack */
-       mov 12(%ecx),RS_REG
-
-       /* Save ctx->callstack_bottom */
-       lea -4(%esp),%ebx
-       mov %ebx,4(%ecx)
-
-       /* Call quot-xt */
-       call *QUOT_XT_OFFSET(%eax)
-
-       /* Tear down stack frame for the call to the boot quotation */
-       pop %eax
-       pop %edx
-       add $4,%esp
-
-       /* Undo stack alignment */
-       mov (%esp),%esp
-
-       /* Load context */
-       mov (%edx),%ecx
-
-       /* Save ctx->datastack */
-       mov DS_REG,8(%ecx)
-
-       /* Save ctx->retainstack */
-       mov RS_REG,12(%ecx)
-
-       /* Restore non-volatile registers */
-       pop %edi
-       pop %esi
-       pop %ebp
-       pop %ebx
-
-       ret
-
-DEF(void,set_callstack,(void *vm, stack_frame *to, stack_frame *from, cell length, void *memcpy)):
-       /* load arguments */
-       mov 4(%esp),%ebx  /* vm - to non-volatile register */
-       mov 8(%esp),%ebp  /* to */
-       mov 12(%esp),%edx /* from */
-       mov 16(%esp),%ecx /* length */
-       mov 20(%esp),%eax /* memcpy */
-
-       /* compute new stack pointer */
-       sub %ecx,%ebp
-       mov %ebp,%esp
-
-       /* call memcpy */
-       push %ecx /* pass length */
-       push %edx /* pass src */
-       push %ebp /* pass dst */
-       call *%eax
-       add $12,%esp
-
-       /* load context */
-       mov (%ebx),%ecx
-       /* load datastack */
-       mov 8(%ecx),DS_REG
-       /* load retainstack */
-       mov 12(%ecx),RS_REG
-
-       /* return with new stack */
-       ret
-
-DEF(void,throw_impl,(cell quot, void *new_stack, void *vm)):
-       /* clear x87 stack, but preserve rounding mode and exception flags */
-       sub $2,%esp
-       fnstcw (%esp)
-       fninit
-       fldcw (%esp)
-       add $2,%esp
-
-       /* load quotation and vm parameters */
-       mov 4(%esp),%eax
-       mov 12(%esp),%edx
-
-       /* load new stack pointer */
-       mov 8(%esp),%esp
-
-       /* load context */
-       mov (%edx),%ecx
-       /* load datastack */
-       mov 8(%ecx),DS_REG
-       /* load retainstack */
-       mov 12(%ecx),RS_REG
-
-       /* call the error handler */
-       jmp *QUOT_XT_OFFSET(%eax)
-
-DEF(void,lazy_jit_compile_impl,(cell quot, void *vm)):
-       /* load context */
-       mov (%edx),%ecx
-       /* save datastack */
-       mov DS_REG,8(%ecx)
-       /* save retainstack */
-       mov RS_REG,12(%ecx)
-       /* save callstack */
-       lea -4(%esp),%ebp
-       mov %ebp,(%ecx)
-
-       /* compile quotation */
-       sub $4,%esp
-       push %edx
-       push %eax
-       call MANGLE(lazy_jit_compile)
-       add $12,%esp
-
-       /* call quotation */
-       jmp *QUOT_XT_OFFSET(%eax)
-
-DEF(long long,read_timestamp_counter,(void)):
-       rdtsc
-       ret
-
-DEF(void,get_sse_env,(void*)):
-       movl 4(%esp), %eax
-       stmxcsr (%eax)
-       ret
-
-DEF(void,set_sse_env,(const void*)):
-       movl 4(%esp), %eax
-       ldmxcsr (%eax)
-       ret
-
-DEF(void,get_x87_env,(void*)):
-       movl 4(%esp), %eax
-       fnstsw (%eax)
-       fnstcw 2(%eax)
-       ret
-
-DEF(void,set_x87_env,(const void*)):
-       movl 4(%esp), %eax
-       fnclex
-       fldcw 2(%eax)
-       ret
-
-#include "cpu-x86.S"
-
-#ifdef WINDOWS
-       .section .drectve
-       .ascii " -export:read_timestamp_counter"
-       .ascii " -export:get_sse_env"
-       .ascii " -export:set_sse_env"
-       .ascii " -export:get_x87_env"
-       .ascii " -export:set_x87_env"
-#endif
diff --git a/vm/cpu-x86.64.S b/vm/cpu-x86.64.S
deleted file mode 100644 (file)
index 37a6507..0000000
+++ /dev/null
@@ -1,203 +0,0 @@
-#include "asm.h"
-
-#define DS_REG %r14
-#define RS_REG %r15
-#define RETURN_REG %rax
-
-#define QUOT_XT_OFFSET 28
-
-#ifdef WINDOWS
-
-       #define ARG0 %rcx
-       #define ARG1 %rdx
-       #define ARG2 %r8
-       #define ARG3 %r9
-
-       #define PUSH_NONVOLATILE \
-               push %r15 ; \
-               push %r14 ; \
-               push %r12 ; \
-               push %r13 ; \
-               push %rdi ; \
-               push %rsi ; \
-               push %rbx ; \
-               push %rbp
-
-       #define POP_NONVOLATILE \
-               pop %rbp ; \
-               pop %rbx ; \
-               pop %rsi ; \
-               pop %rdi ; \
-               pop %r13 ; \
-               pop %r12 ; \
-               pop %r14 ; \
-               pop %r15
-
-#else
-
-       #define ARG0 %rdi
-       #define ARG1 %rsi
-       #define ARG2 %rdx
-       #define ARG3 %rcx
-
-       #define PUSH_NONVOLATILE \
-               push %rbx ; \
-               push %rbp ; \
-               push %r12 ; \
-               push %r13 ; \
-               push %r14 ; \
-               push %r15
-
-       #define POP_NONVOLATILE \
-               pop %r15 ; \
-               pop %r14 ; \
-               pop %r13 ; \
-               pop %r12 ; \
-               pop %rbp ; \
-               pop %rbx
-
-#endif
-
-DEF(void,c_to_factor,(cell quot, void *vm)):
-       PUSH_NONVOLATILE
-
-       /* Save old stack pointer and align */
-       mov %rsp,%rbp
-       and $-16,%rsp
-       push %rbp
-
-       /* Set up stack frame for the call to the boot quotation */
-       push ARG0
-       push ARG1
-
-       /* Create register shadow area (required for Win64 only) */
-       sub $40,%rsp
-
-       /* Load context */
-       mov (ARG1),ARG2
-
-       /* Save ctx->callstack_bottom */
-       lea -8(%rsp),ARG3
-       mov ARG3,8(ARG2)
-
-       /* Load ctx->datastack */
-       mov 16(ARG2),DS_REG
-
-       /* Load ctx->retainstack */
-       mov 24(ARG2),RS_REG
-
-       /* Call quot-xt */
-       call *QUOT_XT_OFFSET(ARG0)
-
-       /* Tear down register shadow area */
-       add $40,%rsp
-
-       /* Tear down stack frame for the call to the boot quotation */
-       pop ARG1
-       pop ARG0
-
-       /* Undo stack alignment */
-       pop %rbp
-       mov %rbp,%rsp
-
-       /* Load context */
-       mov (ARG1),ARG2
-
-       /* Save ctx->datastack */
-       mov DS_REG,16(ARG2)
-
-       /* Save ctx->retainstack */
-       mov RS_REG,24(ARG2)
-
-       POP_NONVOLATILE
-       ret
-
-DEF(void,set_callstack,(void *vm, stack_frame *to, stack_frame *from, cell length)):
-       /* save VM pointer in non-volatile register */
-       mov ARG0,%rbp
-
-       /* compute new stack pointer */ 
-       sub ARG3,ARG1
-       mov ARG1,%rsp
-
-       /* call memcpy */
-       mov ARG1,ARG0
-       mov ARG2,ARG1
-       mov ARG3,ARG2
-       call MANGLE(memcpy)
-
-       /* load context */
-       mov (%rbp),ARG2
-       /* load datastack */
-       mov 16(ARG2),DS_REG
-       /* load retainstack */
-       mov 24(ARG2),RS_REG
-
-       /* return with new stack */
-       ret
-
-DEF(void,throw_impl,(cell quot, void *new_stack, void *vm)):
-       /* clear x87 stack, but preserve rounding mode and exception flags */
-       sub $2,%rsp
-       fnstcw (%rsp)
-       fninit
-       fldcw (%rsp)
-
-       /* shuffle args */
-       mov ARG1,%rsp
-       mov ARG2,ARG1
-
-       /* load context */
-       mov (ARG1),ARG2
-       /* load datastack */
-       mov 16(ARG2),DS_REG
-       /* load retainstack */
-       mov 24(ARG2),RS_REG
-
-       jmp *QUOT_XT_OFFSET(ARG0)
-
-DEF(void,lazy_jit_compile_impl,(cell quot, void *vm)):
-       /* load context */
-       mov (ARG1),ARG2
-       /* save datastack */
-       mov DS_REG,16(ARG2)
-       /* save retainstack */
-       mov RS_REG,24(ARG2)
-       /* save callstack */
-       lea -8(%rsp),%rbp
-       mov %rbp,(ARG2)
-
-       /* compile quotation */
-       sub $8,%rsp
-       call MANGLE(lazy_jit_compile)
-       add $8,%rsp
-
-       /* call quotation */
-       jmp *QUOT_XT_OFFSET(RETURN_REG)
-
-DEF(long long,read_timestamp_counter,(void)):
-       mov $0,%rax
-       rdtsc
-       shl $32,%rdx
-       or %rdx,%rax
-       ret
-
-DEF(void,get_sse_env,(void*)):
-       stmxcsr (%rdi)
-       ret
-
-DEF(void,set_sse_env,(const void*)):
-       ldmxcsr (%rdi)
-       ret
-
-DEF(void,get_x87_env,(void*)):
-       fnstsw (%rdi)
-       fnstcw 2(%rdi)
-       ret
-
-DEF(void,set_x87_env,(const void*)):
-       fnclex
-       fldcw 2(%rdi)
-       ret
-       
-#include "cpu-x86.S"
diff --git a/vm/cpu-x86.S b/vm/cpu-x86.S
deleted file mode 100644 (file)
index d59d0df..0000000
+++ /dev/null
@@ -1,42 +0,0 @@
-/* cpu.x86.features calls this */
-DEF(bool,sse_version,(void)):
-       mov $0x1,RETURN_REG
-       cpuid
-       test $0x100000,%ecx
-       jnz sse_42
-       test $0x80000,%ecx
-       jnz sse_41
-       test $0x200,%ecx
-       jnz ssse_3
-       test $0x1,%ecx
-       jnz sse_3
-       test $0x4000000,%edx
-       jnz sse_2
-       test $0x2000000,%edx
-       jnz sse_1
-       mov $0,%eax
-       ret
-sse_42:
-       mov $42,RETURN_REG
-       ret
-sse_41:
-       mov $41,RETURN_REG
-       ret
-ssse_3:
-       mov $33,RETURN_REG
-       ret
-sse_3:
-       mov $30,RETURN_REG
-       ret
-sse_2:
-       mov $20,RETURN_REG
-       ret
-sse_1:
-       mov $10,RETURN_REG
-       ret
-
-#ifdef WINDOWS
-       .section .drectve
-       .ascii " -export:sse_version"
-       .ascii " -export:c_to_factor"
-#endif
index 349548f1ca32d2881bfc7f73b5dd968d4af850ab..c96291b0d72da9be33552f2386bb4dfedd21062c 100644 (file)
@@ -73,16 +73,4 @@ inline static unsigned int fpu_status(unsigned int status)
         return r;
 }
 
-/* Defined in assembly */
-VM_C_API void c_to_factor(cell quot, void *vm);
-VM_C_API void throw_impl(cell quot, void *new_stack, void *vm);
-VM_C_API void lazy_jit_compile_impl(cell quot, void *vm);
-
-VM_C_API void set_callstack(
-       void *vm,
-       stack_frame *to,
-       stack_frame *from,
-       cell length,
-       void *(*memcpy)(void*,const void*, size_t));
-
 }
diff --git a/vm/entry_points.cpp b/vm/entry_points.cpp
new file mode 100644 (file)
index 0000000..f5f37ce
--- /dev/null
@@ -0,0 +1,29 @@
+#include "master.hpp"
+
+namespace factor
+{
+
+void factor_vm::c_to_factor(cell quot)
+{
+       /* First time this is called, wrap the c-to-factor sub-primitive inside
+       of a callback stub, which saves and restores non-volatile registers
+       as per platform ABI conventions, so that the Factor compiler can treat
+       all registers as volatile */
+       if(!c_to_factor_func)
+       {
+               tagged<word> c_to_factor_word(special_objects[C_TO_FACTOR_WORD]);
+               code_block *c_to_factor_block = callbacks->add(c_to_factor_word.value(),0);
+               c_to_factor_func = (c_to_factor_func_type)c_to_factor_block->xt();
+       }
+
+       c_to_factor_func(quot);
+}
+
+void factor_vm::unwind_native_frames(cell quot, stack_frame *to)
+{
+       tagged<word> unwind_native_frames_word(special_objects[UNWIND_NATIVE_FRAMES_WORD]);
+       unwind_native_frames_func_type unwind_native_frames_func = (unwind_native_frames_func_type)unwind_native_frames_word->xt;
+       unwind_native_frames_func(quot,to);
+}
+
+}
diff --git a/vm/entry_points.hpp b/vm/entry_points.hpp
new file mode 100644 (file)
index 0000000..873501f
--- /dev/null
@@ -0,0 +1,7 @@
+namespace factor
+{
+
+typedef void (* c_to_factor_func_type)(cell quot);
+typedef void (* unwind_native_frames_func_type)(cell quot, stack_frame *to);
+
+}
index 2292c2769369bd5cbc118f9c81967907f0a7412b..2dcb773dd1c06b81ec9528708c9e2afb47191791 100755 (executable)
@@ -31,7 +31,7 @@ void factor_vm::throw_error(cell error, stack_frame *callstack_top)
 {
        /* If the error handler is set, we rewind any C stack frames and
        pass the error to user-space. */
-       if(!current_gc && to_boolean(special_objects[OBJ_BREAK]))
+       if(!current_gc && to_boolean(special_objects[ERROR_HANDLER_QUOT]))
        {
                /* If error was thrown during heap scan, we re-enable the GC */
                gc_off = false;
@@ -56,7 +56,7 @@ void factor_vm::throw_error(cell error, stack_frame *callstack_top)
                else
                        callstack_top = ctx->callstack_top;
 
-               throw_impl(special_objects[OBJ_BREAK],callstack_top,this);
+               unwind_native_frames(special_objects[ERROR_HANDLER_QUOT],callstack_top);
        }
        /* Error was thrown in early startup before error handler is set, just
        crash. */
@@ -130,7 +130,7 @@ void factor_vm::fp_trap_error(unsigned int fpu_status, stack_frame *signal_calls
 
 void factor_vm::primitive_call_clear()
 {
-       throw_impl(ctx->pop(),ctx->callstack_bottom,this);
+       unwind_native_frames(ctx->pop(),ctx->callstack_bottom);
 }
 
 /* For testing purposes */
index d4824fdcd5fc7d7358e6c43074412bda05114126..453ec7168203f921651505db14adcde8892a0e7f 100755 (executable)
@@ -79,14 +79,15 @@ void factor_vm::init_parameters_from_args(vm_parameters *p, int argc, vm_char **
        }
 }
 
-/* Do some initialization that we do once only */
-void factor_vm::do_stage1_init()
+/* Compile code in boot image so that we can execute the startup quotation */
+void factor_vm::prepare_boot_image()
 {
        std::cout << "*** Stage 2 early init... ";
        fflush(stdout);
 
        compile_all_words();
        update_code_heap_words();
+       initialize_all_quotations();
        special_objects[OBJ_STAGE2] = true_object;
 
        std::cout << "done\n";
@@ -145,7 +146,7 @@ void factor_vm::init_factor(vm_parameters *p)
        gc_off = false;
 
        if(!to_boolean(special_objects[OBJ_STAGE2]))
-               do_stage1_init();
+               prepare_boot_image();
 }
 
 /* May allocate memory */
index e815fc96196baf585dfb83711c0d93c40ba340da..69b82b143583ffae5c91931297fafa94efd4578a 100644 (file)
@@ -38,9 +38,9 @@ fixnum instruction_operand::load_value(cell relative_to)
        case RC_ABSOLUTE_PPC_2:
                return load_value_masked(rel_absolute_ppc_2_mask,16,0);
        case RC_RELATIVE_PPC_2:
-               return load_value_masked(rel_relative_ppc_2_mask,16,0) + relative_to;
+               return load_value_masked(rel_relative_ppc_2_mask,16,0) + relative_to - sizeof(cell);
        case RC_RELATIVE_PPC_3:
-               return load_value_masked(rel_relative_ppc_3_mask,6,0) + relative_to;
+               return load_value_masked(rel_relative_ppc_3_mask,6,0) + relative_to - sizeof(cell);
        case RC_RELATIVE_ARM_3:
                return load_value_masked(rel_relative_arm_3_mask,6,2) + relative_to + sizeof(cell);
        case RC_INDIRECT_ARM:
@@ -107,10 +107,10 @@ void instruction_operand::store_value(fixnum absolute_value)
                store_value_masked(absolute_value,rel_absolute_ppc_2_mask,0);
                break;
        case RC_RELATIVE_PPC_2:
-               store_value_masked(relative_value,rel_relative_ppc_2_mask,0);
+               store_value_masked(relative_value + sizeof(cell),rel_relative_ppc_2_mask,0);
                break;
        case RC_RELATIVE_PPC_3:
-               store_value_masked(relative_value,rel_relative_ppc_3_mask,0);
+               store_value_masked(relative_value + sizeof(cell),rel_relative_ppc_3_mask,0);
                break;
        case RC_RELATIVE_ARM_3:
                store_value_masked(relative_value - sizeof(cell),rel_relative_arm_3_mask,2);
index 80c2f1050d5e71644929c1b2f1e49028491c7e78..9a920efce73b170d78a3fcb855cb5906905e2e1b 100755 (executable)
 #include <vector>
 #include <iostream>
 
+/* Detect target CPU type */
+#if defined(__arm__)
+       #define FACTOR_ARM
+#elif defined(__amd64__) || defined(__x86_64__)
+       #define FACTOR_AMD64
+       #define FACTOR_64
+#elif defined(i386) || defined(__i386) || defined(__i386__) || defined(WIN32)
+       #define FACTOR_X86
+#elif defined(__POWERPC__) || defined(__ppc__) || defined(_ARCH_PPC)
+       #define FACTOR_PPC
+#else
+       #error "Unsupported architecture"
+#endif
+
+#ifdef WIN32
+       #define WINDOWS
+#endif
+
 /* Forward-declare this since it comes up in function prototypes */
 namespace factor
 {
@@ -74,6 +92,7 @@ namespace factor
 #include "alien.hpp"
 #include "callbacks.hpp"
 #include "dispatch.hpp"
+#include "entry_points.hpp"
 #include "vm.hpp"
 #include "allot.hpp"
 #include "tagged.hpp"
index 494aca3c5b87f4215055b024b9b640c536b6f25a..21948e5e7a7b1f6070f0401ec868c9e7fc4e2470 100644 (file)
@@ -145,13 +145,6 @@ void factor_vm::primitive_become()
        all objects on a minor GC. */
        data->mark_all_cards();
        primitive_minor_gc();
-
-       /* If a word's definition quotation was in old_objects and the
-          quotation in new_objects is not compiled, we might leak memory
-          by referencing the old quotation unless we recompile all
-          unoptimized words. */
-       compile_all_words();
-       update_code_heap_words();
 }
 
 }
index 368f0f2c19d16a0e783161c43270dcfb4fd4063f..fdc5758a8d2159bb6730307c764f2bc7ff8f6202 100644 (file)
@@ -11,7 +11,7 @@ enum special_object {
        OBJ_WALKER_HOOK,           /* non-local exit hook, used by library only */
        OBJ_CALLCC_1,              /* used to pass the value in callcc1 */
 
-       OBJ_BREAK = 5,             /* quotation called by throw primitive */
+       ERROR_HANDLER_QUOT = 5,    /* quotation called when VM throws an error */
        OBJ_ERROR,                 /* a marker consed onto kernel errors */
 
        OBJ_CELL_SIZE = 7,         /* sizeof(cell) */
@@ -57,6 +57,11 @@ enum special_object {
        JIT_EXECUTE,
        JIT_DECLARE_WORD,
 
+       /* External entry points */
+       C_TO_FACTOR_WORD,
+       LAZY_JIT_COMPILE_WORD,
+       UNWIND_NATIVE_FRAMES_WORD,
+
        /* Incremented on every modify-code-heap call; invalidates call( inline
        caching */
        REDEFINITION_COUNTER = 47,
index ba23125e802c616281ef8f10be40252b530ce328..301b68fb528bb96ce302f5d3b54675a12110c4bb 100644 (file)
@@ -6,7 +6,7 @@ namespace factor
 
 void factor_vm::c_to_factor_toplevel(cell quot)
 {
-       c_to_factor(quot,this);
+       c_to_factor(quot);
 }
 
 void init_signals()
index 101169be064427843573641a9fa8817c0742e515..92694a4599a19770b1db16807189e9221c9d0901 100644 (file)
@@ -11,7 +11,7 @@ void factor_vm::c_to_factor_toplevel(cell quot)
        for(;;)
        {
 NS_DURING
-               c_to_factor(quot,this);
+               c_to_factor(quot);
                NS_VOIDRETURN;
 NS_HANDLER
                ctx->push(allot_alien(false_object,(cell)localException));
index fa9bc71417bd2f83aa8a3f2b7ed744b47070ce2c..bb784bc93c78563f2e47907e324f1f8b19025e63 100644 (file)
@@ -26,18 +26,8 @@ typedef char symbol_char;
 #define FTELL ftello
 #define FSEEK fseeko
 
-#define FIXNUM_FORMAT "%ld"
-#define CELL_FORMAT "%lu"
 #define CELL_HEX_FORMAT "%lx"
 
-#ifdef FACTOR_64
-       #define CELL_HEX_PAD_FORMAT "%016lx"
-#else
-       #define CELL_HEX_PAD_FORMAT "%08lx"
-#endif
-
-#define FIXNUM_FORMAT "%ld"
-
 #define OPEN_READ(path) fopen(path,"rb")
 #define OPEN_WRITE(path) fopen(path,"wb")
 
index f0ae9e7a6d46c418f4c825d4332be29a4f750c04..cab30b121ee287d38459d852e3d12295ca692ba7 100755 (executable)
@@ -117,16 +117,13 @@ FACTOR_STDCALL LONG exception_handler(PEXCEPTION_POINTERS pe)
        return tls_vm()->exception_handler(pe);
 }
 
-bool handler_added = 0;
-
 void factor_vm::c_to_factor_toplevel(cell quot)
 {
-       if(!handler_added){
-               if(!AddVectoredExceptionHandler(0, (PVECTORED_EXCEPTION_HANDLER)factor::exception_handler))
-                       fatal_error("AddVectoredExceptionHandler failed", 0);
-               handler_added = 1;
-       }
-       c_to_factor(quot,this);
+       if(!AddVectoredExceptionHandler(0, (PVECTORED_EXCEPTION_HANDLER)factor::exception_handler))
+               fatal_error("AddVectoredExceptionHandler failed", 0);
+
+       c_to_factor(quot);
+
        RemoveVectoredExceptionHandler((void *)factor::exception_handler);
 }
 
index eeac2a42ddff2f79348e7a17897cda15f47df062..6a280ea58031a46358936971bb629ff9fd76510f 100644 (file)
@@ -18,20 +18,13 @@ typedef wchar_t vm_char;
 #define STRCMP wcscmp
 #define STRNCMP wcsncmp
 #define STRDUP _wcsdup
-#define MIN(a,b) ((a)>(b)?(b):(a))
 #define FTELL ftello64
 #define FSEEK fseeko64
 
 #ifdef WIN64
-       #define CELL_FORMAT "%Iu"
        #define CELL_HEX_FORMAT "%Ix"
-       #define CELL_HEX_PAD_FORMAT "%016Ix"
-       #define FIXNUM_FORMAT "%Id"
 #else
-       #define CELL_FORMAT "%lu"
        #define CELL_HEX_FORMAT "%lx"
-       #define CELL_HEX_PAD_FORMAT "%08lx"
-       #define FIXNUM_FORMAT "%ld"
 #endif
 
 #define OPEN_READ(path) _wfopen(path,L"rb")
index 7b4356af56257a451e3974c4db58862f3359a6a8..96e19ad7f4b9eb71c5ef7d656c1543815e680000 100644 (file)
@@ -1,15 +1,3 @@
-#if defined(__arm__)
-       #define FACTOR_ARM
-#elif defined(__amd64__) || defined(__x86_64__)
-       #define FACTOR_AMD64
-#elif defined(i386) || defined(__i386) || defined(__i386__) || defined(WIN32)
-       #define FACTOR_X86
-#elif defined(__POWERPC__) || defined(__ppc__) || defined(_ARCH_PPC)
-       #define FACTOR_PPC
-#else
-       #error "Unsupported architecture"
-#endif
-
 #if defined(WINDOWS)
        #if defined(WINCE)
                #include "os-windows-ce.hpp"
@@ -18,6 +6,7 @@
        #endif
 
        #include "os-windows.hpp"
+
        #if defined(FACTOR_AMD64)
                #include "os-windows-nt.64.hpp"
        #elif defined(FACTOR_X86)
index 830ae7beb234455c845867a6772212e3a2a760d5..5521b26a3f9ac4b973f6217be14d9c42cef4efb8 100644 (file)
@@ -62,7 +62,6 @@ PRIMITIVE_FORWARD(retainstack)
 PRIMITIVE_FORWARD(callstack)
 PRIMITIVE_FORWARD(set_datastack)
 PRIMITIVE_FORWARD(set_retainstack)
-PRIMITIVE_FORWARD(set_callstack)
 PRIMITIVE_FORWARD(exit)
 PRIMITIVE_FORWARD(data_room)
 PRIMITIVE_FORWARD(code_room)
@@ -196,7 +195,6 @@ const primitive_type primitives[] = {
        primitive_callstack,
        primitive_set_datastack,
        primitive_set_retainstack,
-       primitive_set_callstack,
        primitive_exit,
        primitive_data_room,
        primitive_code_room,
index 5af9d95b02324daf1a5664d3eb11779bd2a8bebf..e4836fe96bfed65e3f70faeb39c253b9ea275dbf 100755 (executable)
@@ -182,10 +182,10 @@ void quotation_jit::iterate_quotation()
                        /* Primitive calls */
                        if(primitive_call_p(i,length))
                        {
-                               /* On PowerPC, the VM pointer is stored as a register; on other
-                                  platforms, the RT_VM relocation is used and it needs an offset
-                                  parameter */
-#ifndef FACTOR_PPC
+                               /* On x86-64 and PowerPC, the VM pointer is stored in
+                               a register; on other platforms, the RT_VM relocation
+                               is used and it needs an offset parameter */
+#ifdef FACTOR_X86
                                parameter(tag_fixnum(0));
 #endif
                                parameter(obj.value());
@@ -293,11 +293,11 @@ code_block *factor_vm::jit_compile_quot(cell owner_, cell quot_, bool relocating
 void factor_vm::jit_compile_quot(cell quot_, bool relocating)
 {
        data_root<quotation> quot(quot_,this);
-
-       if(quot->code) return;
-
-       code_block *compiled = jit_compile_quot(quot.value(),quot.value(),relocating);
-       set_quot_xt(quot.untagged(),compiled);
+       if(!quot_compiled_p(quot.untagged()))
+       {
+               code_block *compiled = jit_compile_quot(quot.value(),quot.value(),relocating);
+               set_quot_xt(quot.untagged(),compiled);
+       }
 }
 
 void factor_vm::primitive_jit_compile()
@@ -305,15 +305,21 @@ void factor_vm::primitive_jit_compile()
        jit_compile_quot(ctx->pop(),true);
 }
 
+code_block *factor_vm::lazy_jit_compile_block()
+{
+       return untag<word>(special_objects[LAZY_JIT_COMPILE_WORD])->code;
+}
+
 /* push a new quotation on the stack */
 void factor_vm::primitive_array_to_quotation()
 {
        quotation *quot = allot<quotation>(sizeof(quotation));
+
        quot->array = ctx->peek();
        quot->cached_effect = false_object;
        quot->cache_counter = false_object;
-       quot->xt = (void *)lazy_jit_compile_impl;
-       quot->code = NULL;
+       set_quot_xt(quot,lazy_jit_compile_block());
+
        ctx->replace(tag<quotation>(quot));
 }
 
@@ -349,11 +355,34 @@ VM_C_API cell lazy_jit_compile(cell quot, factor_vm *parent)
        return parent->lazy_jit_compile(quot);
 }
 
+bool factor_vm::quot_compiled_p(quotation *quot)
+{
+       return quot->code != NULL && quot->code != lazy_jit_compile_block();
+}
+
 void factor_vm::primitive_quot_compiled_p()
 {
        tagged<quotation> quot(ctx->pop());
        quot.untag_check(this);
-       ctx->push(tag_boolean(quot->code != NULL));
+       ctx->push(tag_boolean(quot_compiled_p(quot.untagged())));
+}
+
+cell factor_vm::find_all_quotations()
+{
+       return instances(QUOTATION_TYPE);
+}
+
+void factor_vm::initialize_all_quotations()
+{
+       data_root<array> quotations(find_all_quotations(),this);
+
+       cell length = array_capacity(quotations.untagged());
+       for(cell i = 0; i < length; i++)
+       {
+               data_root<quotation> quot(array_nth(quotations.untagged(),i),this);
+               if(!quot->code)
+                       set_quot_xt(quot.untagged(),lazy_jit_compile_block());
+       }
 }
 
 }
index 8f063a9ad4628686d3e366d007181a076a17d611..3e976d06195a23fb030c12ccbd990541a5f6dcfe 100755 (executable)
@@ -18,4 +18,11 @@ cell read_cell_hex()
        return cell;
 }
 
+/* On Windows, memcpy() is in a different DLL and the non-optimizing
+compiler can't find it */
+VM_C_API void *factor_memcpy(void *dst, void *src, size_t len)
+{
+       return memcpy(dst,src,len);
+}
+
 }
index 94b9de6f483d98cbaf9fd8a66a64e2fbae65d28c..cea70c0c372e755468ae2a5095b75a55ffa7bdb3 100755 (executable)
@@ -27,5 +27,6 @@ inline static void memset_cell(void *dst, cell pattern, size_t size)
 
 vm_char *safe_strdup(const vm_char *str);
 cell read_cell_hex();
+VM_C_API void *factor_memcpy(void *dst, void *src, size_t len);
 
 }
index d911b80227d009befe6151a84ac341cd695a0bb7..623556416ab3ece478241406fc283646a3e14137 100755 (executable)
--- a/vm/vm.cpp
+++ b/vm/vm.cpp
@@ -5,6 +5,7 @@ namespace factor
 \r
 factor_vm::factor_vm() :\r
        nursery(0,0),\r
+       c_to_factor_func(NULL),\r
        profiling_p(false),\r
        gc_off(false),\r
        current_gc(NULL),\r
index ef2d7e06444b319ce3979bd49e18cdc8b8deb5bf..92e921000b603efbaad315ae2ff0fc0ed8a4dd72 100755 (executable)
--- a/vm/vm.hpp
+++ b/vm/vm.hpp
@@ -30,6 +30,9 @@ struct factor_vm
        /* Canonical truth value. In Factor, 't' */
        cell true_object;
 
+       /* External entry points */
+       c_to_factor_func_type c_to_factor_func;
+
        /* Is call counting enabled? */
        bool profiling_p;
 
@@ -562,7 +565,6 @@ struct factor_vm
        stack_frame *fix_callstack_top(stack_frame *top, stack_frame *bottom);
        stack_frame *second_from_top_stack_frame();
        void primitive_callstack();
-       void primitive_set_callstack();
        code_block *frame_code(stack_frame *frame);
        code_block_type frame_type(stack_frame *frame);
        cell frame_executing(stack_frame *frame);
@@ -596,6 +598,7 @@ struct factor_vm
 
        //quotations
        void primitive_jit_compile();
+       code_block *lazy_jit_compile_block();
        void primitive_array_to_quotation();
        void primitive_quotation_xt();
        void set_quot_xt(quotation *quot, code_block *code);
@@ -603,7 +606,10 @@ struct factor_vm
        void jit_compile_quot(cell quot_, bool relocating);
        fixnum quot_code_offset_to_scan(cell quot_, cell offset);
        cell lazy_jit_compile(cell quot);
+       bool quot_compiled_p(quotation *quot);
        void primitive_quot_compiled_p();
+       cell find_all_quotations();
+       void initialize_all_quotations();
 
        //dispatch
        cell search_lookup_alist(cell table, cell klass);
@@ -632,11 +638,15 @@ struct factor_vm
        void update_pic_transitions(cell pic_size);
        void *inline_cache_miss(cell return_address);
 
+       //entry points
+       void c_to_factor(cell quot);
+       void unwind_native_frames(cell quot, stack_frame *to);
+
        //factor
        void default_parameters(vm_parameters *p);
-       bool factor_arg(const vm_char* str, const vm_char* arg, cell* value);
+       bool factor_arg(const vm_char *str, const vm_char *arg, cell *value);
        void init_parameters_from_args(vm_parameters *p, int argc, vm_char **argv);
-       void do_stage1_init();
+       void prepare_boot_image();
        void init_factor(vm_parameters *p);
        void pass_args_to_factor(int argc, vm_char **argv);
        void start_factor(vm_parameters *p);