Merge branch 'master' of git://factorcode.org/git/factor
commit
4bd309dd07
8
Makefile
8
Makefile
|
@ -56,6 +56,8 @@ default:
|
||||||
@echo "linux-arm"
|
@echo "linux-arm"
|
||||||
@echo "openbsd-x86-32"
|
@echo "openbsd-x86-32"
|
||||||
@echo "openbsd-x86-64"
|
@echo "openbsd-x86-64"
|
||||||
|
@echo "netbsd-x86-32"
|
||||||
|
@echo "netbsd-x86-64"
|
||||||
@echo "macosx-x86-32"
|
@echo "macosx-x86-32"
|
||||||
@echo "macosx-x86-64"
|
@echo "macosx-x86-64"
|
||||||
@echo "macosx-ppc"
|
@echo "macosx-ppc"
|
||||||
|
@ -83,6 +85,12 @@ freebsd-x86-32:
|
||||||
freebsd-x86-64:
|
freebsd-x86-64:
|
||||||
$(MAKE) $(EXECUTABLE) CONFIG=vm/Config.freebsd.x86.64
|
$(MAKE) $(EXECUTABLE) CONFIG=vm/Config.freebsd.x86.64
|
||||||
|
|
||||||
|
netbsd-x86-32:
|
||||||
|
$(MAKE) $(EXECUTABLE) CONFIG=vm/Config.netbsd.x86.32
|
||||||
|
|
||||||
|
netbsd-x86-64:
|
||||||
|
$(MAKE) $(EXECUTABLE) CONFIG=vm/Config.netbsd.x86.64
|
||||||
|
|
||||||
macosx-freetype:
|
macosx-freetype:
|
||||||
ln -sf libfreetype.6.dylib \
|
ln -sf libfreetype.6.dylib \
|
||||||
Factor.app/Contents/Frameworks/libfreetype.dylib
|
Factor.app/Contents/Frameworks/libfreetype.dylib
|
||||||
|
|
|
@ -46,3 +46,9 @@ IN: temporary
|
||||||
[ ?{ f } ] [
|
[ ?{ f } ] [
|
||||||
1 2 { t f t f } <slice> >bit-array
|
1 2 { t f t f } <slice> >bit-array
|
||||||
] unit-test
|
] unit-test
|
||||||
|
|
||||||
|
[ ?{ t f t f f f } ] [ 6 ?{ t f t } resize-bit-array ] unit-test
|
||||||
|
|
||||||
|
[ ?{ t t } ] [ 2 ?{ t t f t f t f t t t f t } resize-bit-array ] unit-test
|
||||||
|
|
||||||
|
[ -10 ?{ } resize-bit-array ] unit-test-fails
|
||||||
|
|
|
@ -48,6 +48,9 @@ M: bit-array new drop <bit-array> ;
|
||||||
M: bit-array equal?
|
M: bit-array equal?
|
||||||
over bit-array? [ sequence= ] [ 2drop f ] if ;
|
over bit-array? [ sequence= ] [ 2drop f ] if ;
|
||||||
|
|
||||||
|
M: bit-array resize
|
||||||
|
resize-bit-array ;
|
||||||
|
|
||||||
INSTANCE: bit-array sequence
|
INSTANCE: bit-array sequence
|
||||||
INSTANCE: bit-array simple-c-ptr
|
INSTANCE: bit-array simple-c-ptr
|
||||||
INSTANCE: bit-array c-ptr
|
INSTANCE: bit-array c-ptr
|
||||||
|
|
|
@ -0,0 +1,33 @@
|
||||||
|
USING: arrays bit-arrays help.markup help.syntax kernel
|
||||||
|
bit-vectors.private combinators ;
|
||||||
|
IN: bit-vectors
|
||||||
|
|
||||||
|
ARTICLE: "bit-vectors" "Bit vectors"
|
||||||
|
"A bit vector is a resizable mutable sequence of bits. The literal syntax is covered in " { $link "syntax-bit-vectors" } ". Bit vector words are found in the " { $vocab-link "bit-vectors" } " vocabulary."
|
||||||
|
$nl
|
||||||
|
"Bit vectors form a class:"
|
||||||
|
{ $subsection bit-vector }
|
||||||
|
{ $subsection bit-vector? }
|
||||||
|
"Creating bit vectors:"
|
||||||
|
{ $subsection >bit-vector }
|
||||||
|
{ $subsection <bit-vector> }
|
||||||
|
"If you don't care about initial capacity, a more elegant way to create a new bit vector is to write:"
|
||||||
|
{ $code "?V{ } clone" } ;
|
||||||
|
|
||||||
|
ABOUT: "bit-vectors"
|
||||||
|
|
||||||
|
HELP: bit-vector
|
||||||
|
{ $description "The class of resizable bit vectors. See " { $link "syntax-bit-vectors" } " for syntax and " { $link "bit-vectors" } " for general information." } ;
|
||||||
|
|
||||||
|
HELP: <bit-vector>
|
||||||
|
{ $values { "n" "a positive integer specifying initial capacity" } { "bit-vector" bit-vector } }
|
||||||
|
{ $description "Creates a new bit vector that can hold " { $snippet "n" } " bits before resizing." } ;
|
||||||
|
|
||||||
|
HELP: >bit-vector
|
||||||
|
{ $values { "seq" "a sequence" } { "bit-vector" bit-vector } }
|
||||||
|
{ $description "Outputs a freshly-allocated bit vector with the same elements as a given sequence." } ;
|
||||||
|
|
||||||
|
HELP: bit-array>vector
|
||||||
|
{ $values { "bit-array" "an array" } { "length" "a non-negative integer" } { "bit-vector" bit-vector } }
|
||||||
|
{ $description "Creates a new bit vector using the array for underlying storage with the specified initial length." }
|
||||||
|
{ $warning "This word is in the " { $vocab-link "bit-vectors.private" } " vocabulary because it does not perform type or bounds checks. User code should call " { $link >bit-vector } " instead." } ;
|
|
@ -0,0 +1,14 @@
|
||||||
|
IN: temporary
|
||||||
|
USING: tools.test bit-vectors vectors sequences kernel math ;
|
||||||
|
|
||||||
|
[ 0 ] [ 123 <bit-vector> length ] unit-test
|
||||||
|
|
||||||
|
: do-it
|
||||||
|
1234 swap [ >r even? r> push ] curry each ;
|
||||||
|
|
||||||
|
[ t ] [
|
||||||
|
3 <bit-vector> dup do-it
|
||||||
|
3 <vector> dup do-it sequence=
|
||||||
|
] unit-test
|
||||||
|
|
||||||
|
[ t ] [ ?V{ } bit-vector? ] unit-test
|
|
@ -0,0 +1,33 @@
|
||||||
|
! Copyright (C) 2008 Slava Pestov.
|
||||||
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
|
USING: arrays kernel kernel.private math sequences
|
||||||
|
sequences.private growable bit-arrays ;
|
||||||
|
IN: bit-vectors
|
||||||
|
|
||||||
|
<PRIVATE
|
||||||
|
|
||||||
|
: bit-array>vector ( bit-array length -- bit-vector )
|
||||||
|
bit-vector construct-boa ; inline
|
||||||
|
|
||||||
|
PRIVATE>
|
||||||
|
|
||||||
|
: <bit-vector> ( n -- bit-vector )
|
||||||
|
<bit-array> 0 bit-array>vector ; inline
|
||||||
|
|
||||||
|
: >bit-vector ( seq -- bit-vector ) ?V{ } clone-like ;
|
||||||
|
|
||||||
|
M: bit-vector like
|
||||||
|
drop dup bit-vector? [
|
||||||
|
dup bit-array?
|
||||||
|
[ dup length bit-array>vector ] [ >bit-vector ] if
|
||||||
|
] unless ;
|
||||||
|
|
||||||
|
M: bit-vector new
|
||||||
|
drop [ <bit-array> ] keep >fixnum bit-array>vector ;
|
||||||
|
|
||||||
|
M: bit-vector equal?
|
||||||
|
over bit-vector? [ sequence= ] [ 2drop f ] if ;
|
||||||
|
|
||||||
|
M: bit-array new-resizable drop <bit-vector> ;
|
||||||
|
|
||||||
|
INSTANCE: bit-vector growable
|
|
@ -320,24 +320,33 @@ M: quotation '
|
||||||
! Vectors and sbufs
|
! Vectors and sbufs
|
||||||
|
|
||||||
M: vector '
|
M: vector '
|
||||||
dup underlying ' swap length
|
dup length swap underlying '
|
||||||
vector type-number object tag-number [
|
tuple type-number tuple tag-number [
|
||||||
emit-fixnum ! length
|
4 emit-fixnum
|
||||||
|
vector ' emit
|
||||||
|
f ' emit
|
||||||
emit ! array ptr
|
emit ! array ptr
|
||||||
|
emit-fixnum ! length
|
||||||
] emit-object ;
|
] emit-object ;
|
||||||
|
|
||||||
M: sbuf '
|
M: sbuf '
|
||||||
dup underlying ' swap length
|
dup length swap underlying '
|
||||||
sbuf type-number object tag-number [
|
tuple type-number tuple tag-number [
|
||||||
emit-fixnum ! length
|
4 emit-fixnum
|
||||||
|
sbuf ' emit
|
||||||
|
f ' emit
|
||||||
emit ! array ptr
|
emit ! array ptr
|
||||||
|
emit-fixnum ! length
|
||||||
] emit-object ;
|
] emit-object ;
|
||||||
|
|
||||||
! Hashes
|
! Hashes
|
||||||
|
|
||||||
M: hashtable '
|
M: hashtable '
|
||||||
[ hash-array ' ] keep
|
[ hash-array ' ] keep
|
||||||
hashtable type-number object tag-number [
|
tuple type-number tuple tag-number [
|
||||||
|
5 emit-fixnum
|
||||||
|
hashtable ' emit
|
||||||
|
f ' emit
|
||||||
dup hash-count emit-fixnum
|
dup hash-count emit-fixnum
|
||||||
hash-deleted emit-fixnum
|
hash-deleted emit-fixnum
|
||||||
emit ! array ptr
|
emit ! array ptr
|
||||||
|
|
|
@ -8,7 +8,7 @@ BIN: 111 tag-mask set
|
||||||
8 num-tags set
|
8 num-tags set
|
||||||
3 tag-bits set
|
3 tag-bits set
|
||||||
|
|
||||||
23 num-types set
|
20 num-types set
|
||||||
|
|
||||||
H{
|
H{
|
||||||
{ fixnum BIN: 000 }
|
{ fixnum BIN: 000 }
|
||||||
|
@ -24,17 +24,14 @@ H{
|
||||||
tag-numbers get H{
|
tag-numbers get H{
|
||||||
{ array 8 }
|
{ array 8 }
|
||||||
{ wrapper 9 }
|
{ wrapper 9 }
|
||||||
{ hashtable 10 }
|
{ float-array 10 }
|
||||||
{ vector 11 }
|
{ callstack 11 }
|
||||||
{ string 12 }
|
{ string 12 }
|
||||||
{ sbuf 13 }
|
{ curry 13 }
|
||||||
{ quotation 14 }
|
{ quotation 14 }
|
||||||
{ dll 15 }
|
{ dll 15 }
|
||||||
{ alien 16 }
|
{ alien 16 }
|
||||||
{ word 17 }
|
{ word 17 }
|
||||||
{ byte-array 18 }
|
{ byte-array 18 }
|
||||||
{ bit-array 19 }
|
{ bit-array 19 }
|
||||||
{ float-array 20 }
|
|
||||||
{ curry 21 }
|
|
||||||
{ callstack 22 }
|
|
||||||
} union type-numbers set
|
} union type-numbers set
|
||||||
|
|
|
@ -22,7 +22,9 @@ crossref off
|
||||||
{ "arm" "arm" }
|
{ "arm" "arm" }
|
||||||
} at "/bootstrap.factor" 3append parse-file
|
} at "/bootstrap.factor" 3append parse-file
|
||||||
|
|
||||||
! Now we have ( syntax-quot arch-quot ) on the stack
|
"resource:core/bootstrap/layouts/layouts.factor" parse-file
|
||||||
|
|
||||||
|
! Now we have ( syntax-quot arch-quot layouts-quot ) on the stack
|
||||||
|
|
||||||
! Bring up a bare cross-compiling vocabulary.
|
! Bring up a bare cross-compiling vocabulary.
|
||||||
"syntax" vocab vocab-words bootstrap-syntax set
|
"syntax" vocab vocab-words bootstrap-syntax set
|
||||||
|
@ -30,6 +32,7 @@ H{ } clone dictionary set
|
||||||
H{ } clone changed-words set
|
H{ } clone changed-words set
|
||||||
[ drop ] recompile-hook set
|
[ drop ] recompile-hook set
|
||||||
|
|
||||||
|
call
|
||||||
call
|
call
|
||||||
call
|
call
|
||||||
|
|
||||||
|
@ -39,11 +42,14 @@ call
|
||||||
"alien"
|
"alien"
|
||||||
"arrays"
|
"arrays"
|
||||||
"bit-arrays"
|
"bit-arrays"
|
||||||
|
"bit-vectors"
|
||||||
"byte-arrays"
|
"byte-arrays"
|
||||||
|
"byte-vectors"
|
||||||
"classes.private"
|
"classes.private"
|
||||||
"compiler.units"
|
"compiler.units"
|
||||||
"continuations.private"
|
"continuations.private"
|
||||||
"float-arrays"
|
"float-arrays"
|
||||||
|
"float-vectors"
|
||||||
"generator"
|
"generator"
|
||||||
"growable"
|
"growable"
|
||||||
"hashtables"
|
"hashtables"
|
||||||
|
@ -96,12 +102,6 @@ H{ } clone update-map set
|
||||||
: register-builtin ( class -- )
|
: register-builtin ( class -- )
|
||||||
dup "type" word-prop builtins get set-nth ;
|
dup "type" word-prop builtins get set-nth ;
|
||||||
|
|
||||||
: intern-slots ( spec -- spec )
|
|
||||||
[
|
|
||||||
[ dup array? [ first2 create ] when ] map
|
|
||||||
{ slot-spec f } swap append >tuple
|
|
||||||
] map ;
|
|
||||||
|
|
||||||
: lookup-type-number ( word -- n )
|
: lookup-type-number ( word -- n )
|
||||||
global [ target-word ] bind type-number ;
|
global [ target-word ] bind type-number ;
|
||||||
|
|
||||||
|
@ -110,8 +110,8 @@ H{ } clone update-map set
|
||||||
dup dup lookup-type-number "type" set-word-prop
|
dup dup lookup-type-number "type" set-word-prop
|
||||||
dup f f builtin-class define-class
|
dup f f builtin-class define-class
|
||||||
dup r> builtin-predicate
|
dup r> builtin-predicate
|
||||||
dup r> intern-slots 2dup "slots" set-word-prop
|
dup r> 1 simple-slots 2dup "slots" set-word-prop
|
||||||
define-slots
|
dupd define-slots
|
||||||
register-builtin ;
|
register-builtin ;
|
||||||
|
|
||||||
H{ } clone typemap set
|
H{ } clone typemap set
|
||||||
|
@ -137,14 +137,12 @@ num-types get f <array> builtins set
|
||||||
{
|
{
|
||||||
{ "integer" "math" }
|
{ "integer" "math" }
|
||||||
"numerator"
|
"numerator"
|
||||||
1
|
|
||||||
{ "numerator" "math" }
|
{ "numerator" "math" }
|
||||||
f
|
f
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
{ "integer" "math" }
|
{ "integer" "math" }
|
||||||
"denominator"
|
"denominator"
|
||||||
2
|
|
||||||
{ "denominator" "math" }
|
{ "denominator" "math" }
|
||||||
f
|
f
|
||||||
}
|
}
|
||||||
|
@ -158,14 +156,12 @@ num-types get f <array> builtins set
|
||||||
{
|
{
|
||||||
{ "real" "math" }
|
{ "real" "math" }
|
||||||
"real-part"
|
"real-part"
|
||||||
1
|
|
||||||
{ "real-part" "math" }
|
{ "real-part" "math" }
|
||||||
f
|
f
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
{ "real" "math" }
|
{ "real" "math" }
|
||||||
"imaginary-part"
|
"imaginary-part"
|
||||||
2
|
|
||||||
{ "imaginary-part" "math" }
|
{ "imaginary-part" "math" }
|
||||||
f
|
f
|
||||||
}
|
}
|
||||||
|
@ -182,94 +178,32 @@ num-types get f <array> builtins set
|
||||||
{
|
{
|
||||||
{ "object" "kernel" }
|
{ "object" "kernel" }
|
||||||
"wrapped"
|
"wrapped"
|
||||||
1
|
|
||||||
{ "wrapped" "kernel" }
|
{ "wrapped" "kernel" }
|
||||||
f
|
f
|
||||||
}
|
}
|
||||||
} define-builtin
|
} define-builtin
|
||||||
|
|
||||||
"hashtable" "hashtables" create "hashtable?" "hashtables" create
|
|
||||||
{
|
|
||||||
{
|
|
||||||
{ "array-capacity" "sequences.private" }
|
|
||||||
"count"
|
|
||||||
1
|
|
||||||
{ "hash-count" "hashtables.private" }
|
|
||||||
{ "set-hash-count" "hashtables.private" }
|
|
||||||
} {
|
|
||||||
{ "array-capacity" "sequences.private" }
|
|
||||||
"deleted"
|
|
||||||
2
|
|
||||||
{ "hash-deleted" "hashtables.private" }
|
|
||||||
{ "set-hash-deleted" "hashtables.private" }
|
|
||||||
} {
|
|
||||||
{ "array" "arrays" }
|
|
||||||
"array"
|
|
||||||
3
|
|
||||||
{ "hash-array" "hashtables.private" }
|
|
||||||
{ "set-hash-array" "hashtables.private" }
|
|
||||||
}
|
|
||||||
} define-builtin
|
|
||||||
|
|
||||||
"vector" "vectors" create "vector?" "vectors" create
|
|
||||||
{
|
|
||||||
{
|
|
||||||
{ "array-capacity" "sequences.private" }
|
|
||||||
"fill"
|
|
||||||
1
|
|
||||||
{ "length" "sequences" }
|
|
||||||
{ "set-fill" "growable" }
|
|
||||||
} {
|
|
||||||
{ "array" "arrays" }
|
|
||||||
"underlying"
|
|
||||||
2
|
|
||||||
{ "underlying" "growable" }
|
|
||||||
{ "set-underlying" "growable" }
|
|
||||||
}
|
|
||||||
} define-builtin
|
|
||||||
|
|
||||||
"string" "strings" create "string?" "strings" create
|
"string" "strings" create "string?" "strings" create
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
{ "array-capacity" "sequences.private" }
|
{ "array-capacity" "sequences.private" }
|
||||||
"length"
|
"length"
|
||||||
1
|
|
||||||
{ "length" "sequences" }
|
{ "length" "sequences" }
|
||||||
f
|
f
|
||||||
}
|
}
|
||||||
} define-builtin
|
} define-builtin
|
||||||
|
|
||||||
"sbuf" "sbufs" create "sbuf?" "sbufs" create
|
|
||||||
{
|
|
||||||
{
|
|
||||||
{ "array-capacity" "sequences.private" }
|
|
||||||
"length"
|
|
||||||
1
|
|
||||||
{ "length" "sequences" }
|
|
||||||
{ "set-fill" "growable" }
|
|
||||||
}
|
|
||||||
{
|
|
||||||
{ "string" "strings" }
|
|
||||||
"underlying"
|
|
||||||
2
|
|
||||||
{ "underlying" "growable" }
|
|
||||||
{ "set-underlying" "growable" }
|
|
||||||
}
|
|
||||||
} define-builtin
|
|
||||||
|
|
||||||
"quotation" "quotations" create "quotation?" "quotations" create
|
"quotation" "quotations" create "quotation?" "quotations" create
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
{ "object" "kernel" }
|
{ "object" "kernel" }
|
||||||
"array"
|
"array"
|
||||||
1
|
|
||||||
{ "quotation-array" "quotations.private" }
|
{ "quotation-array" "quotations.private" }
|
||||||
f
|
f
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
{ "object" "kernel" }
|
{ "object" "kernel" }
|
||||||
"compiled?"
|
"compiled?"
|
||||||
2
|
|
||||||
{ "quotation-compiled?" "quotations" }
|
{ "quotation-compiled?" "quotations" }
|
||||||
f
|
f
|
||||||
}
|
}
|
||||||
|
@ -280,7 +214,6 @@ num-types get f <array> builtins set
|
||||||
{
|
{
|
||||||
{ "byte-array" "byte-arrays" }
|
{ "byte-array" "byte-arrays" }
|
||||||
"path"
|
"path"
|
||||||
1
|
|
||||||
{ "(dll-path)" "alien" }
|
{ "(dll-path)" "alien" }
|
||||||
f
|
f
|
||||||
}
|
}
|
||||||
|
@ -292,13 +225,11 @@ define-builtin
|
||||||
{
|
{
|
||||||
{ "c-ptr" "alien" }
|
{ "c-ptr" "alien" }
|
||||||
"alien"
|
"alien"
|
||||||
1
|
|
||||||
{ "underlying-alien" "alien" }
|
{ "underlying-alien" "alien" }
|
||||||
f
|
f
|
||||||
} {
|
} {
|
||||||
{ "object" "kernel" }
|
{ "object" "kernel" }
|
||||||
"expired?"
|
"expired?"
|
||||||
2
|
|
||||||
{ "expired?" "alien" }
|
{ "expired?" "alien" }
|
||||||
f
|
f
|
||||||
}
|
}
|
||||||
|
@ -307,45 +238,40 @@ define-builtin
|
||||||
|
|
||||||
"word" "words" create "word?" "words" create
|
"word" "words" create "word?" "words" create
|
||||||
{
|
{
|
||||||
|
f
|
||||||
{
|
{
|
||||||
{ "object" "kernel" }
|
{ "object" "kernel" }
|
||||||
"name"
|
"name"
|
||||||
2
|
|
||||||
{ "word-name" "words" }
|
{ "word-name" "words" }
|
||||||
{ "set-word-name" "words" }
|
{ "set-word-name" "words" }
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
{ "object" "kernel" }
|
{ "object" "kernel" }
|
||||||
"vocabulary"
|
"vocabulary"
|
||||||
3
|
|
||||||
{ "word-vocabulary" "words" }
|
{ "word-vocabulary" "words" }
|
||||||
{ "set-word-vocabulary" "words" }
|
{ "set-word-vocabulary" "words" }
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
{ "quotation" "quotations" }
|
{ "quotation" "quotations" }
|
||||||
"def"
|
"def"
|
||||||
4
|
|
||||||
{ "word-def" "words" }
|
{ "word-def" "words" }
|
||||||
{ "set-word-def" "words.private" }
|
{ "set-word-def" "words.private" }
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
{ "object" "kernel" }
|
{ "object" "kernel" }
|
||||||
"props"
|
"props"
|
||||||
5
|
|
||||||
{ "word-props" "words" }
|
{ "word-props" "words" }
|
||||||
{ "set-word-props" "words" }
|
{ "set-word-props" "words" }
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
{ "object" "kernel" }
|
{ "object" "kernel" }
|
||||||
"?"
|
"?"
|
||||||
6
|
|
||||||
{ "compiled?" "words" }
|
{ "compiled?" "words" }
|
||||||
f
|
f
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
{ "fixnum" "math" }
|
{ "fixnum" "math" }
|
||||||
"counter"
|
"counter"
|
||||||
7
|
|
||||||
{ "profile-counter" "tools.profiler.private" }
|
{ "profile-counter" "tools.profiler.private" }
|
||||||
{ "set-profile-counter" "tools.profiler.private" }
|
{ "set-profile-counter" "tools.profiler.private" }
|
||||||
}
|
}
|
||||||
|
@ -369,14 +295,12 @@ define-builtin
|
||||||
{
|
{
|
||||||
{ "object" "kernel" }
|
{ "object" "kernel" }
|
||||||
"obj"
|
"obj"
|
||||||
1
|
|
||||||
{ "curry-obj" "kernel" }
|
{ "curry-obj" "kernel" }
|
||||||
f
|
f
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
{ "object" "kernel" }
|
{ "object" "kernel" }
|
||||||
"obj"
|
"obj"
|
||||||
2
|
|
||||||
{ "curry-quot" "kernel" }
|
{ "curry-quot" "kernel" }
|
||||||
f
|
f
|
||||||
}
|
}
|
||||||
|
@ -414,6 +338,102 @@ builtins get num-tags get tail f union-class define-class
|
||||||
"tombstone" "hashtables.private" lookup t
|
"tombstone" "hashtables.private" lookup t
|
||||||
2array >tuple 1quotation define-inline
|
2array >tuple 1quotation define-inline
|
||||||
|
|
||||||
|
! Some tuple classes
|
||||||
|
"hashtable" "hashtables" create
|
||||||
|
{
|
||||||
|
{
|
||||||
|
{ "array-capacity" "sequences.private" }
|
||||||
|
"count"
|
||||||
|
{ "hash-count" "hashtables.private" }
|
||||||
|
{ "set-hash-count" "hashtables.private" }
|
||||||
|
} {
|
||||||
|
{ "array-capacity" "sequences.private" }
|
||||||
|
"deleted"
|
||||||
|
{ "hash-deleted" "hashtables.private" }
|
||||||
|
{ "set-hash-deleted" "hashtables.private" }
|
||||||
|
} {
|
||||||
|
{ "array" "arrays" }
|
||||||
|
"array"
|
||||||
|
{ "hash-array" "hashtables.private" }
|
||||||
|
{ "set-hash-array" "hashtables.private" }
|
||||||
|
}
|
||||||
|
} define-tuple-class
|
||||||
|
|
||||||
|
"sbuf" "sbufs" create
|
||||||
|
{
|
||||||
|
{
|
||||||
|
{ "string" "strings" }
|
||||||
|
"underlying"
|
||||||
|
{ "underlying" "growable" }
|
||||||
|
{ "set-underlying" "growable" }
|
||||||
|
} {
|
||||||
|
{ "array-capacity" "sequences.private" }
|
||||||
|
"length"
|
||||||
|
{ "length" "sequences" }
|
||||||
|
{ "set-fill" "growable" }
|
||||||
|
}
|
||||||
|
} define-tuple-class
|
||||||
|
|
||||||
|
"vector" "vectors" create
|
||||||
|
{
|
||||||
|
{
|
||||||
|
{ "array" "arrays" }
|
||||||
|
"underlying"
|
||||||
|
{ "underlying" "growable" }
|
||||||
|
{ "set-underlying" "growable" }
|
||||||
|
} {
|
||||||
|
{ "array-capacity" "sequences.private" }
|
||||||
|
"fill"
|
||||||
|
{ "length" "sequences" }
|
||||||
|
{ "set-fill" "growable" }
|
||||||
|
}
|
||||||
|
} define-tuple-class
|
||||||
|
|
||||||
|
"byte-vector" "byte-vectors" create
|
||||||
|
{
|
||||||
|
{
|
||||||
|
{ "byte-array" "byte-arrays" }
|
||||||
|
"underlying"
|
||||||
|
{ "underlying" "growable" }
|
||||||
|
{ "set-underlying" "growable" }
|
||||||
|
} {
|
||||||
|
{ "array-capacity" "sequences.private" }
|
||||||
|
"fill"
|
||||||
|
{ "length" "sequences" }
|
||||||
|
{ "set-fill" "growable" }
|
||||||
|
}
|
||||||
|
} define-tuple-class
|
||||||
|
|
||||||
|
"bit-vector" "bit-vectors" create
|
||||||
|
{
|
||||||
|
{
|
||||||
|
{ "bit-array" "bit-arrays" }
|
||||||
|
"underlying"
|
||||||
|
{ "underlying" "growable" }
|
||||||
|
{ "set-underlying" "growable" }
|
||||||
|
} {
|
||||||
|
{ "array-capacity" "sequences.private" }
|
||||||
|
"fill"
|
||||||
|
{ "length" "sequences" }
|
||||||
|
{ "set-fill" "growable" }
|
||||||
|
}
|
||||||
|
} define-tuple-class
|
||||||
|
|
||||||
|
"float-vector" "float-vectors" create
|
||||||
|
{
|
||||||
|
{
|
||||||
|
{ "float-array" "float-arrays" }
|
||||||
|
"underlying"
|
||||||
|
{ "underlying" "growable" }
|
||||||
|
{ "set-underlying" "growable" }
|
||||||
|
} {
|
||||||
|
{ "array-capacity" "sequences.private" }
|
||||||
|
"fill"
|
||||||
|
{ "length" "sequences" }
|
||||||
|
{ "set-fill" "growable" }
|
||||||
|
}
|
||||||
|
} define-tuple-class
|
||||||
|
|
||||||
! Primitive words
|
! Primitive words
|
||||||
: make-primitive ( word vocab n -- )
|
: make-primitive ( word vocab n -- )
|
||||||
>r create dup reset-word r> [ do-primitive ] curry [ ] like define ;
|
>r create dup reset-word r> [ do-primitive ] curry [ ] like define ;
|
||||||
|
@ -422,7 +442,6 @@ builtins get num-tags get tail f union-class define-class
|
||||||
{ "(execute)" "words.private" }
|
{ "(execute)" "words.private" }
|
||||||
{ "(call)" "kernel.private" }
|
{ "(call)" "kernel.private" }
|
||||||
{ "uncurry" "kernel.private" }
|
{ "uncurry" "kernel.private" }
|
||||||
{ "string>sbuf" "sbufs.private" }
|
|
||||||
{ "bignum>fixnum" "math.private" }
|
{ "bignum>fixnum" "math.private" }
|
||||||
{ "float>fixnum" "math.private" }
|
{ "float>fixnum" "math.private" }
|
||||||
{ "fixnum>bignum" "math.private" }
|
{ "fixnum>bignum" "math.private" }
|
||||||
|
@ -575,7 +594,6 @@ builtins get num-tags get tail f union-class define-class
|
||||||
{ "set-char-slot" "strings.private" }
|
{ "set-char-slot" "strings.private" }
|
||||||
{ "resize-array" "arrays" }
|
{ "resize-array" "arrays" }
|
||||||
{ "resize-string" "strings" }
|
{ "resize-string" "strings" }
|
||||||
{ "(hashtable)" "hashtables.private" }
|
|
||||||
{ "<array>" "arrays" }
|
{ "<array>" "arrays" }
|
||||||
{ "begin-scan" "memory" }
|
{ "begin-scan" "memory" }
|
||||||
{ "next-object" "memory" }
|
{ "next-object" "memory" }
|
||||||
|
@ -590,7 +608,6 @@ builtins get num-tags get tail f union-class define-class
|
||||||
{ "fclose" "io.streams.c" }
|
{ "fclose" "io.streams.c" }
|
||||||
{ "<wrapper>" "kernel" }
|
{ "<wrapper>" "kernel" }
|
||||||
{ "(clone)" "kernel" }
|
{ "(clone)" "kernel" }
|
||||||
{ "array>vector" "vectors.private" }
|
|
||||||
{ "<string>" "strings" }
|
{ "<string>" "strings" }
|
||||||
{ "(>tuple)" "tuples.private" }
|
{ "(>tuple)" "tuples.private" }
|
||||||
{ "array>quotation" "quotations.private" }
|
{ "array>quotation" "quotations.private" }
|
||||||
|
@ -610,6 +627,9 @@ builtins get num-tags get tail f union-class define-class
|
||||||
{ "set-innermost-frame-quot" "kernel.private" }
|
{ "set-innermost-frame-quot" "kernel.private" }
|
||||||
{ "call-clear" "kernel" }
|
{ "call-clear" "kernel" }
|
||||||
{ "(os-envs)" "system" }
|
{ "(os-envs)" "system" }
|
||||||
|
{ "resize-byte-array" "byte-arrays" }
|
||||||
|
{ "resize-bit-array" "bit-arrays" }
|
||||||
|
{ "resize-float-array" "float-arrays" }
|
||||||
}
|
}
|
||||||
dup length [ >r first2 r> make-primitive ] 2each
|
dup length [ >r first2 r> make-primitive ] 2each
|
||||||
|
|
||||||
|
|
|
@ -87,5 +87,5 @@ IN: bootstrap.stage2
|
||||||
"output-image" get resource-path save-image-and-exit
|
"output-image" get resource-path save-image-and-exit
|
||||||
] if
|
] if
|
||||||
] [
|
] [
|
||||||
error. :c "listener" vocab-main execute
|
print-error :c "listener" vocab-main execute
|
||||||
] recover
|
] recover
|
||||||
|
|
|
@ -16,12 +16,15 @@ f swap set-vocab-source-loaded?
|
||||||
";"
|
";"
|
||||||
"<PRIVATE"
|
"<PRIVATE"
|
||||||
"?{"
|
"?{"
|
||||||
|
"?V{"
|
||||||
"BIN:"
|
"BIN:"
|
||||||
"B{"
|
"B{"
|
||||||
|
"BV{"
|
||||||
"C:"
|
"C:"
|
||||||
"CHAR:"
|
"CHAR:"
|
||||||
"DEFER:"
|
"DEFER:"
|
||||||
"F{"
|
"F{"
|
||||||
|
"FV{"
|
||||||
"FORGET:"
|
"FORGET:"
|
||||||
"GENERIC#"
|
"GENERIC#"
|
||||||
"GENERIC:"
|
"GENERIC:"
|
||||||
|
|
|
@ -0,0 +1,8 @@
|
||||||
|
IN: temporary
|
||||||
|
USING: tools.test byte-arrays ;
|
||||||
|
|
||||||
|
[ B{ 1 2 3 0 0 0 } ] [ 6 B{ 1 2 3 } resize-byte-array ] unit-test
|
||||||
|
|
||||||
|
[ B{ 1 2 } ] [ 2 B{ 1 2 3 4 5 6 7 8 9 } resize-byte-array ] unit-test
|
||||||
|
|
||||||
|
[ -10 B{ } resize-byte-array ] unit-test-fails
|
|
@ -15,6 +15,9 @@ M: byte-array new drop <byte-array> ;
|
||||||
M: byte-array equal?
|
M: byte-array equal?
|
||||||
over byte-array? [ sequence= ] [ 2drop f ] if ;
|
over byte-array? [ sequence= ] [ 2drop f ] if ;
|
||||||
|
|
||||||
|
M: byte-array resize
|
||||||
|
resize-byte-array ;
|
||||||
|
|
||||||
INSTANCE: byte-array sequence
|
INSTANCE: byte-array sequence
|
||||||
INSTANCE: byte-array simple-c-ptr
|
INSTANCE: byte-array simple-c-ptr
|
||||||
INSTANCE: byte-array c-ptr
|
INSTANCE: byte-array c-ptr
|
||||||
|
|
|
@ -0,0 +1,34 @@
|
||||||
|
USING: arrays byte-arrays help.markup help.syntax kernel
|
||||||
|
byte-vectors.private combinators ;
|
||||||
|
IN: byte-vectors
|
||||||
|
|
||||||
|
ARTICLE: "byte-vectors" "Byte vectors"
|
||||||
|
"A byte vector is a resizable mutable sequence of unsigned bytes. The literal syntax is covered in " { $link "syntax-byte-vectors" } ". Byte vector words are found in the " { $vocab-link "byte-vectors" } " vocabulary."
|
||||||
|
$nl
|
||||||
|
"Byte vectors form a class:"
|
||||||
|
{ $subsection byte-vector }
|
||||||
|
{ $subsection byte-vector? }
|
||||||
|
"Creating byte vectors:"
|
||||||
|
{ $subsection >byte-vector }
|
||||||
|
{ $subsection <byte-vector> }
|
||||||
|
"If you don't care about initial capacity, a more elegant way to create a new byte vector is to write:"
|
||||||
|
{ $code "BV{ } clone" } ;
|
||||||
|
|
||||||
|
ABOUT: "byte-vectors"
|
||||||
|
|
||||||
|
HELP: byte-vector
|
||||||
|
{ $description "The class of resizable byte vectors. See " { $link "syntax-byte-vectors" } " for syntax and " { $link "byte-vectors" } " for general information." } ;
|
||||||
|
|
||||||
|
HELP: <byte-vector>
|
||||||
|
{ $values { "n" "a positive integer specifying initial capacity" } { "byte-vector" byte-vector } }
|
||||||
|
{ $description "Creates a new byte vector that can hold " { $snippet "n" } " bytes before resizing." } ;
|
||||||
|
|
||||||
|
HELP: >byte-vector
|
||||||
|
{ $values { "seq" "a sequence" } { "byte-vector" byte-vector } }
|
||||||
|
{ $description "Outputs a freshly-allocated byte vector with the same elements as a given sequence." }
|
||||||
|
{ $errors "Throws an error if the sequence contains elements other than integers." } ;
|
||||||
|
|
||||||
|
HELP: byte-array>vector
|
||||||
|
{ $values { "byte-array" "an array" } { "length" "a non-negative integer" } { "byte-vector" byte-vector } }
|
||||||
|
{ $description "Creates a new byte vector using the array for underlying storage with the specified initial length." }
|
||||||
|
{ $warning "This word is in the " { $vocab-link "byte-vectors.private" } " vocabulary because it does not perform type or bounds checks. User code should call " { $link >byte-vector } " instead." } ;
|
|
@ -0,0 +1,14 @@
|
||||||
|
IN: temporary
|
||||||
|
USING: tools.test byte-vectors vectors sequences kernel ;
|
||||||
|
|
||||||
|
[ 0 ] [ 123 <byte-vector> length ] unit-test
|
||||||
|
|
||||||
|
: do-it
|
||||||
|
123 [ over push ] each ;
|
||||||
|
|
||||||
|
[ t ] [
|
||||||
|
3 <byte-vector> do-it
|
||||||
|
3 <vector> do-it sequence=
|
||||||
|
] unit-test
|
||||||
|
|
||||||
|
[ t ] [ BV{ } byte-vector? ] unit-test
|
|
@ -0,0 +1,33 @@
|
||||||
|
! Copyright (C) 2008 Slava Pestov.
|
||||||
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
|
USING: arrays kernel kernel.private math sequences
|
||||||
|
sequences.private growable byte-arrays ;
|
||||||
|
IN: byte-vectors
|
||||||
|
|
||||||
|
<PRIVATE
|
||||||
|
|
||||||
|
: byte-array>vector ( byte-array capacity -- byte-vector )
|
||||||
|
byte-vector construct-boa ; inline
|
||||||
|
|
||||||
|
PRIVATE>
|
||||||
|
|
||||||
|
: <byte-vector> ( n -- byte-vector )
|
||||||
|
<byte-array> 0 byte-array>vector ; inline
|
||||||
|
|
||||||
|
: >byte-vector ( seq -- byte-vector ) BV{ } clone-like ;
|
||||||
|
|
||||||
|
M: byte-vector like
|
||||||
|
drop dup byte-vector? [
|
||||||
|
dup byte-array?
|
||||||
|
[ dup length byte-array>vector ] [ >byte-vector ] if
|
||||||
|
] unless ;
|
||||||
|
|
||||||
|
M: byte-vector new
|
||||||
|
drop [ <byte-array> ] keep >fixnum byte-array>vector ;
|
||||||
|
|
||||||
|
M: byte-vector equal?
|
||||||
|
over byte-vector? [ sequence= ] [ 2drop f ] if ;
|
||||||
|
|
||||||
|
M: byte-array new-resizable drop <byte-vector> ;
|
||||||
|
|
||||||
|
INSTANCE: byte-vector growable
|
|
@ -255,7 +255,14 @@ PRIVATE>
|
||||||
>r dup word-props r> union over set-word-props
|
>r dup word-props r> union over set-word-props
|
||||||
t "class" set-word-prop ;
|
t "class" set-word-prop ;
|
||||||
|
|
||||||
GENERIC: update-methods ( class -- )
|
GENERIC: update-predicate ( class -- )
|
||||||
|
|
||||||
|
M: class update-predicate drop ;
|
||||||
|
|
||||||
|
: update-predicates ( assoc -- )
|
||||||
|
[ drop update-predicate ] assoc-each ;
|
||||||
|
|
||||||
|
GENERIC: update-methods ( assoc -- )
|
||||||
|
|
||||||
: define-class ( word members superclass metaclass -- )
|
: define-class ( word members superclass metaclass -- )
|
||||||
#! If it was already a class, update methods after.
|
#! If it was already a class, update methods after.
|
||||||
|
@ -264,8 +271,9 @@ GENERIC: update-methods ( class -- )
|
||||||
over class-usages [
|
over class-usages [
|
||||||
uncache-classes
|
uncache-classes
|
||||||
dupd (define-class)
|
dupd (define-class)
|
||||||
] keep cache-classes
|
] keep cache-classes r>
|
||||||
r> [ update-methods ] [ drop ] if ;
|
[ class-usages dup update-predicates update-methods ]
|
||||||
|
[ drop ] if ;
|
||||||
|
|
||||||
GENERIC: class ( object -- class ) inline
|
GENERIC: class ( object -- class ) inline
|
||||||
|
|
||||||
|
|
|
@ -20,6 +20,8 @@ PREDICATE: class union-class
|
||||||
over members union-predicate-quot
|
over members union-predicate-quot
|
||||||
define-predicate ;
|
define-predicate ;
|
||||||
|
|
||||||
|
M: union-class update-predicate define-union-predicate ;
|
||||||
|
|
||||||
: define-union-class ( class members -- )
|
: define-union-class ( class members -- )
|
||||||
dupd f union-class define-class define-union-predicate ;
|
dupd f union-class define-class define-union-predicate ;
|
||||||
|
|
||||||
|
|
|
@ -334,10 +334,6 @@ cell 8 = [
|
||||||
|
|
||||||
[ \ + ] [ \ + [ <wrapper> ] compile-call ] unit-test
|
[ \ + ] [ \ + [ <wrapper> ] compile-call ] unit-test
|
||||||
|
|
||||||
[ H{ } ] [
|
|
||||||
100 [ (hashtable) ] compile-call [ reset-hash ] keep
|
|
||||||
] unit-test
|
|
||||||
|
|
||||||
[ B{ 0 0 0 0 0 } ] [
|
[ B{ 0 0 0 0 0 } ] [
|
||||||
[ 5 <byte-array> ] compile-call
|
[ 5 <byte-array> ] compile-call
|
||||||
] unit-test
|
] unit-test
|
||||||
|
|
|
@ -68,6 +68,15 @@ $nl
|
||||||
|
|
||||||
ABOUT: "continuations"
|
ABOUT: "continuations"
|
||||||
|
|
||||||
|
HELP: dispose
|
||||||
|
{ $values { "object" "a disposable object" } }
|
||||||
|
{ $contract "Releases operating system resources associated with a disposable object. No further operations can be performed on a disposable object after this call. Disposable objects include streams, memory mapped files, and so on." }
|
||||||
|
{ $notes "You must close disposable objects after you are finished working with them, to avoid leaking operating system resources. A convenient way to automate this is by using the " { $link with-disposal } " word." } ;
|
||||||
|
|
||||||
|
HELP: with-disposal
|
||||||
|
{ $values { "object" "a disposable object" } { "quot" "a quotation with stack effect " { $snippet "( object -- )" } } }
|
||||||
|
{ $description "Calls the quotation, disposing the object with " { $link dispose } " after the quotation returns or if it throws an error." } ;
|
||||||
|
|
||||||
HELP: catchstack*
|
HELP: catchstack*
|
||||||
{ $values { "catchstack" "a vector of continuations" } }
|
{ $values { "catchstack" "a vector of continuations" } }
|
||||||
{ $description "Outputs the current catchstack." } ;
|
{ $description "Outputs the current catchstack." } ;
|
||||||
|
|
|
@ -135,6 +135,11 @@ PRIVATE>
|
||||||
[ [ , f ] compose [ , drop t ] recover ] curry all?
|
[ [ , f ] compose [ , drop t ] recover ] curry all?
|
||||||
] { } make peek swap [ rethrow ] when ; inline
|
] { } make peek swap [ rethrow ] when ; inline
|
||||||
|
|
||||||
|
GENERIC: dispose ( object -- )
|
||||||
|
|
||||||
|
: with-disposal ( object quot -- )
|
||||||
|
over [ dispose ] curry [ ] cleanup ; inline
|
||||||
|
|
||||||
TUPLE: condition restarts continuation ;
|
TUPLE: condition restarts continuation ;
|
||||||
|
|
||||||
: <condition> ( error restarts cc -- condition )
|
: <condition> ( error restarts cc -- condition )
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
compiler
|
|
@ -383,41 +383,6 @@ IN: cpu.arm.intrinsics
|
||||||
{ +output+ { "out" } }
|
{ +output+ { "out" } }
|
||||||
} define-intrinsic
|
} define-intrinsic
|
||||||
|
|
||||||
\ (hashtable) [
|
|
||||||
hashtable 4 cells %allot
|
|
||||||
R12 f v>operand MOV
|
|
||||||
R12 1 %set-slot
|
|
||||||
R12 2 %set-slot
|
|
||||||
R12 3 %set-slot
|
|
||||||
! Store tagged ptr in reg
|
|
||||||
"out" get object %store-tagged
|
|
||||||
] H{
|
|
||||||
{ +scratch+ { { f "out" } } }
|
|
||||||
{ +output+ { "out" } }
|
|
||||||
} define-intrinsic
|
|
||||||
|
|
||||||
\ string>sbuf [
|
|
||||||
sbuf 3 cells %allot
|
|
||||||
"length" operand 1 %set-slot
|
|
||||||
"string" operand 2 %set-slot
|
|
||||||
"out" get object %store-tagged
|
|
||||||
] H{
|
|
||||||
{ +input+ { { f "string" } { f "length" } } }
|
|
||||||
{ +scratch+ { { f "out" } } }
|
|
||||||
{ +output+ { "out" } }
|
|
||||||
} define-intrinsic
|
|
||||||
|
|
||||||
\ array>vector [
|
|
||||||
vector 3 cells %allot
|
|
||||||
"length" operand 1 %set-slot
|
|
||||||
"array" operand 2 %set-slot
|
|
||||||
"out" get object %store-tagged
|
|
||||||
] H{
|
|
||||||
{ +input+ { { f "array" } { f "length" } } }
|
|
||||||
{ +scratch+ { { f "out" } } }
|
|
||||||
{ +output+ { "out" } }
|
|
||||||
} define-intrinsic
|
|
||||||
|
|
||||||
! Alien intrinsics
|
! Alien intrinsics
|
||||||
: %alien-accessor ( quot -- )
|
: %alien-accessor ( quot -- )
|
||||||
"offset" operand dup %untag-fixnum
|
"offset" operand dup %untag-fixnum
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
compiler
|
|
@ -586,43 +586,6 @@ IN: cpu.ppc.intrinsics
|
||||||
{ +output+ { "wrapper" } }
|
{ +output+ { "wrapper" } }
|
||||||
} define-intrinsic
|
} define-intrinsic
|
||||||
|
|
||||||
\ (hashtable) [
|
|
||||||
hashtable 4 cells %allot
|
|
||||||
f v>operand 12 LI
|
|
||||||
12 11 1 cells STW
|
|
||||||
12 11 2 cells STW
|
|
||||||
12 11 3 cells STW
|
|
||||||
! Store tagged ptr in reg
|
|
||||||
"hashtable" get object %store-tagged
|
|
||||||
] H{
|
|
||||||
{ +scratch+ { { f "hashtable" } } }
|
|
||||||
{ +output+ { "hashtable" } }
|
|
||||||
} define-intrinsic
|
|
||||||
|
|
||||||
\ string>sbuf [
|
|
||||||
sbuf 3 cells %allot
|
|
||||||
"length" operand 11 1 cells STW
|
|
||||||
"string" operand 11 2 cells STW
|
|
||||||
! Store tagged ptr in reg
|
|
||||||
"sbuf" get object %store-tagged
|
|
||||||
] H{
|
|
||||||
{ +input+ { { f "string" } { f "length" } } }
|
|
||||||
{ +scratch+ { { f "sbuf" } } }
|
|
||||||
{ +output+ { "sbuf" } }
|
|
||||||
} define-intrinsic
|
|
||||||
|
|
||||||
\ array>vector [
|
|
||||||
vector 3 cells %allot
|
|
||||||
"length" operand 11 1 cells STW
|
|
||||||
"array" operand 11 2 cells STW
|
|
||||||
! Store tagged ptr in reg
|
|
||||||
"vector" get object %store-tagged
|
|
||||||
] H{
|
|
||||||
{ +input+ { { f "array" } { f "length" } } }
|
|
||||||
{ +scratch+ { { f "vector" } } }
|
|
||||||
{ +output+ { "vector" } }
|
|
||||||
} define-intrinsic
|
|
||||||
|
|
||||||
! Alien intrinsics
|
! Alien intrinsics
|
||||||
: %alien-accessor ( quot -- )
|
: %alien-accessor ( quot -- )
|
||||||
"offset" operand dup %untag-fixnum
|
"offset" operand dup %untag-fixnum
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
compiler
|
|
@ -0,0 +1 @@
|
||||||
|
compiler
|
|
@ -0,0 +1 @@
|
||||||
|
compiler
|
|
@ -447,45 +447,6 @@ IN: cpu.x86.intrinsics
|
||||||
{ +output+ { "wrapper" } }
|
{ +output+ { "wrapper" } }
|
||||||
} define-intrinsic
|
} define-intrinsic
|
||||||
|
|
||||||
\ (hashtable) [
|
|
||||||
hashtable 4 cells [
|
|
||||||
1 object@ f v>operand MOV
|
|
||||||
2 object@ f v>operand MOV
|
|
||||||
3 object@ f v>operand MOV
|
|
||||||
! Store tagged ptr in reg
|
|
||||||
"hashtable" get object %store-tagged
|
|
||||||
] %allot
|
|
||||||
] H{
|
|
||||||
{ +scratch+ { { f "hashtable" } } }
|
|
||||||
{ +output+ { "hashtable" } }
|
|
||||||
} define-intrinsic
|
|
||||||
|
|
||||||
\ string>sbuf [
|
|
||||||
sbuf 3 cells [
|
|
||||||
1 object@ "length" operand MOV
|
|
||||||
2 object@ "string" operand MOV
|
|
||||||
! Store tagged ptr in reg
|
|
||||||
"sbuf" get object %store-tagged
|
|
||||||
] %allot
|
|
||||||
] H{
|
|
||||||
{ +input+ { { f "string" } { f "length" } } }
|
|
||||||
{ +scratch+ { { f "sbuf" } } }
|
|
||||||
{ +output+ { "sbuf" } }
|
|
||||||
} define-intrinsic
|
|
||||||
|
|
||||||
\ array>vector [
|
|
||||||
vector 3 cells [
|
|
||||||
1 object@ "length" operand MOV
|
|
||||||
2 object@ "array" operand MOV
|
|
||||||
! Store tagged ptr in reg
|
|
||||||
"vector" get object %store-tagged
|
|
||||||
] %allot
|
|
||||||
] H{
|
|
||||||
{ +input+ { { f "array" } { f "length" } } }
|
|
||||||
{ +scratch+ { { f "vector" } } }
|
|
||||||
{ +output+ { "vector" } }
|
|
||||||
} define-intrinsic
|
|
||||||
|
|
||||||
! Alien intrinsics
|
! Alien intrinsics
|
||||||
: %alien-accessor ( quot -- )
|
: %alien-accessor ( quot -- )
|
||||||
"offset" operand %untag-fixnum
|
"offset" operand %untag-fixnum
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
USING: help.markup help.syntax kernel ;
|
USING: help.markup help.syntax kernel quotations ;
|
||||||
IN: dlists
|
IN: dlists
|
||||||
|
|
||||||
ARTICLE: "dlists" "Doubly-linked lists"
|
ARTICLE: "dlists" "Doubly-linked lists"
|
||||||
|
@ -13,23 +13,31 @@ $nl
|
||||||
{ $subsection dlist? }
|
{ $subsection dlist? }
|
||||||
"Constructing a dlist:"
|
"Constructing a dlist:"
|
||||||
{ $subsection <dlist> }
|
{ $subsection <dlist> }
|
||||||
"Double-ended queue protocol:"
|
"Working with the front of the list:"
|
||||||
{ $subsection dlist-empty? }
|
|
||||||
{ $subsection push-front }
|
{ $subsection push-front }
|
||||||
|
{ $subsection push-front* }
|
||||||
|
{ $subsection peek-front }
|
||||||
{ $subsection pop-front }
|
{ $subsection pop-front }
|
||||||
{ $subsection pop-front* }
|
{ $subsection pop-front* }
|
||||||
|
"Working with the back of the list:"
|
||||||
{ $subsection push-back }
|
{ $subsection push-back }
|
||||||
|
{ $subsection push-back* }
|
||||||
|
{ $subsection peek-back }
|
||||||
{ $subsection pop-back }
|
{ $subsection pop-back }
|
||||||
{ $subsection pop-back* }
|
{ $subsection pop-back* }
|
||||||
"Finding out the length:"
|
"Finding out the length:"
|
||||||
|
{ $subsection dlist-empty? }
|
||||||
{ $subsection dlist-length }
|
{ $subsection dlist-length }
|
||||||
"Iterating over elements:"
|
"Iterating over elements:"
|
||||||
{ $subsection dlist-each }
|
{ $subsection dlist-each }
|
||||||
{ $subsection dlist-find }
|
{ $subsection dlist-find }
|
||||||
{ $subsection dlist-contains? }
|
{ $subsection dlist-contains? }
|
||||||
"Deleting a node matching a predicate:"
|
"Deleting a node:"
|
||||||
{ $subsection delete-node* }
|
|
||||||
{ $subsection delete-node }
|
{ $subsection delete-node }
|
||||||
|
{ $subsection dlist-delete }
|
||||||
|
"Deleting a node matching a predicate:"
|
||||||
|
{ $subsection delete-node-if* }
|
||||||
|
{ $subsection delete-node-if }
|
||||||
"Consuming all nodes:"
|
"Consuming all nodes:"
|
||||||
{ $subsection dlist-slurp } ;
|
{ $subsection dlist-slurp } ;
|
||||||
|
|
||||||
|
@ -77,7 +85,7 @@ HELP: pop-back*
|
||||||
{ $see-also push-front push-back pop-front pop-front* pop-back } ;
|
{ $see-also push-front push-back pop-front pop-front* pop-back } ;
|
||||||
|
|
||||||
HELP: dlist-find
|
HELP: dlist-find
|
||||||
{ $values { "quot" "a quotation" } { "dlist" { $link dlist } } { "obj/f" "an object or " { $link f } } { "?" "a boolean" } }
|
{ $values { "quot" quotation } { "dlist" { $link dlist } } { "obj/f" "an object or " { $link f } } { "?" "a boolean" } }
|
||||||
{ $description "Applies the quotation to each element of the " { $link dlist } " in turn, until it outputs a true value or the end of the " { $link dlist } " is reached. Outputs either the object it found or " { $link f } ", and a boolean which is true if an object is found." }
|
{ $description "Applies the quotation to each element of the " { $link dlist } " in turn, until it outputs a true value or the end of the " { $link dlist } " is reached. Outputs either the object it found or " { $link f } ", and a boolean which is true if an object is found." }
|
||||||
{ $notes "Returns a boolean to allow dlists to store " { $link f } "."
|
{ $notes "Returns a boolean to allow dlists to store " { $link f } "."
|
||||||
$nl
|
$nl
|
||||||
|
@ -85,20 +93,20 @@ HELP: dlist-find
|
||||||
} ;
|
} ;
|
||||||
|
|
||||||
HELP: dlist-contains?
|
HELP: dlist-contains?
|
||||||
{ $values { "quot" "a quotation" } { "dlist" { $link dlist } } { "?" "a boolean" } }
|
{ $values { "quot" quotation } { "dlist" { $link dlist } } { "?" "a boolean" } }
|
||||||
{ $description "Just like " { $link dlist-find } " except it doesn't return the object." }
|
{ $description "Just like " { $link dlist-find } " except it doesn't return the object." }
|
||||||
{ $notes "This operation is O(n)." } ;
|
{ $notes "This operation is O(n)." } ;
|
||||||
|
|
||||||
HELP: delete-node*
|
HELP: delete-node-if*
|
||||||
{ $values { "quot" "a quotation" } { "dlist" { $link dlist } } { "obj/f" "an object or " { $link f } } { "?" "a boolean" } }
|
{ $values { "quot" quotation } { "dlist" { $link dlist } } { "obj/f" "an object or " { $link f } } { "?" "a boolean" } }
|
||||||
{ $description "Calls " { $link dlist-find } " on the " { $link dlist } " and deletes the node returned, if any. Returns the value of the deleted node and a boolean to allow the deleted value to distinguished from " { $link f } ", for nothing deleted." }
|
{ $description "Calls " { $link dlist-find } " on the " { $link dlist } " and deletes the node returned, if any. Returns the value of the deleted node and a boolean to allow the deleted value to distinguished from " { $link f } ", for nothing deleted." }
|
||||||
{ $notes "This operation is O(n)." } ;
|
{ $notes "This operation is O(n)." } ;
|
||||||
|
|
||||||
HELP: delete-node
|
HELP: delete-node-if
|
||||||
{ $values { "quot" "a quotation" } { "dlist" { $link dlist } } { "obj/f" "an object or " { $link f } } }
|
{ $values { "quot" quotation } { "dlist" { $link dlist } } { "obj/f" "an object or " { $link f } } }
|
||||||
{ $description "Like " { $link delete-node* } " but cannot distinguish from deleting a node whose value is " { $link f } " or not deleting an element." }
|
{ $description "Like " { $link delete-node-if* } " but cannot distinguish from deleting a node whose value is " { $link f } " or not deleting an element." }
|
||||||
{ $notes "This operation is O(n)." } ;
|
{ $notes "This operation is O(n)." } ;
|
||||||
|
|
||||||
HELP: dlist-each
|
HELP: dlist-each
|
||||||
{ $values { "quot" "a quotation" } { "dlist" { $link dlist } } }
|
{ $values { "quot" quotation } { "dlist" { $link dlist } } }
|
||||||
{ $description "Iterate a " { $link dlist } ", calling quot on each element." } ;
|
{ $description "Iterate a " { $link dlist } ", calling quot on each element." } ;
|
||||||
|
|
|
@ -49,14 +49,14 @@ IN: temporary
|
||||||
[ f ] [ <dlist> 1 over push-back [ 2 = ] swap dlist-contains? ] unit-test
|
[ f ] [ <dlist> 1 over push-back [ 2 = ] swap dlist-contains? ] unit-test
|
||||||
[ t ] [ <dlist> 1 over push-back [ 1 = ] swap dlist-contains? ] unit-test
|
[ t ] [ <dlist> 1 over push-back [ 1 = ] swap dlist-contains? ] unit-test
|
||||||
|
|
||||||
[ 1 ] [ <dlist> 1 over push-back [ 1 = ] swap delete-node ] unit-test
|
[ 1 ] [ <dlist> 1 over push-back [ 1 = ] swap delete-node-if ] unit-test
|
||||||
[ t ] [ <dlist> 1 over push-back [ 1 = ] over delete-node drop dlist-empty? ] unit-test
|
[ t ] [ <dlist> 1 over push-back [ 1 = ] over delete-node-if drop dlist-empty? ] unit-test
|
||||||
[ t ] [ <dlist> 1 over push-back [ 1 = ] over delete-node drop dlist-empty? ] unit-test
|
[ t ] [ <dlist> 1 over push-back [ 1 = ] over delete-node-if drop dlist-empty? ] unit-test
|
||||||
[ 0 ] [ <dlist> 1 over push-back [ 1 = ] over delete-node drop dlist-length ] unit-test
|
[ 0 ] [ <dlist> 1 over push-back [ 1 = ] over delete-node-if drop dlist-length ] unit-test
|
||||||
[ 1 ] [ <dlist> 1 over push-back 2 over push-back [ 1 = ] over delete-node drop dlist-length ] unit-test
|
[ 1 ] [ <dlist> 1 over push-back 2 over push-back [ 1 = ] over delete-node-if drop dlist-length ] unit-test
|
||||||
[ 2 ] [ <dlist> 1 over push-back 2 over push-back 3 over push-back [ 1 = ] over delete-node drop dlist-length ] unit-test
|
[ 2 ] [ <dlist> 1 over push-back 2 over push-back 3 over push-back [ 1 = ] over delete-node-if drop dlist-length ] unit-test
|
||||||
[ 2 ] [ <dlist> 1 over push-back 2 over push-back 3 over push-back [ 2 = ] over delete-node drop dlist-length ] unit-test
|
[ 2 ] [ <dlist> 1 over push-back 2 over push-back 3 over push-back [ 2 = ] over delete-node-if drop dlist-length ] unit-test
|
||||||
[ 2 ] [ <dlist> 1 over push-back 2 over push-back 3 over push-back [ 3 = ] over delete-node drop dlist-length ] unit-test
|
[ 2 ] [ <dlist> 1 over push-back 2 over push-back 3 over push-back [ 3 = ] over delete-node-if drop dlist-length ] unit-test
|
||||||
|
|
||||||
[ 0 ] [ <dlist> dlist-length ] unit-test
|
[ 0 ] [ <dlist> dlist-length ] unit-test
|
||||||
[ 1 ] [ <dlist> 1 over push-front dlist-length ] unit-test
|
[ 1 ] [ <dlist> 1 over push-front dlist-length ] unit-test
|
||||||
|
|
|
@ -63,12 +63,22 @@ C: <dlist-node> dlist-node
|
||||||
>r dlist-front r> (dlist-each-node) ; inline
|
>r dlist-front r> (dlist-each-node) ; inline
|
||||||
PRIVATE>
|
PRIVATE>
|
||||||
|
|
||||||
: push-front ( obj dlist -- )
|
: push-front* ( obj dlist -- dlist-node )
|
||||||
[ dlist-front f swap <dlist-node> dup set-next-prev ] keep
|
[ dlist-front f swap <dlist-node> dup dup set-next-prev ] keep
|
||||||
[ set-dlist-front ] keep
|
[ set-dlist-front ] keep
|
||||||
[ set-back-to-front ] keep
|
[ set-back-to-front ] keep
|
||||||
inc-length ;
|
inc-length ;
|
||||||
|
|
||||||
|
: push-front ( obj dlist -- )
|
||||||
|
push-front* drop ;
|
||||||
|
|
||||||
|
: push-back* ( obj dlist -- dlist-node )
|
||||||
|
[ dlist-back f <dlist-node> ] keep
|
||||||
|
[ dlist-back set-next-when ] 2keep
|
||||||
|
[ set-dlist-back ] 2keep
|
||||||
|
[ set-front-to-back ] keep
|
||||||
|
inc-length ;
|
||||||
|
|
||||||
: push-back ( obj dlist -- )
|
: push-back ( obj dlist -- )
|
||||||
[ dlist-back f <dlist-node> ] keep
|
[ dlist-back f <dlist-node> ] keep
|
||||||
[ dlist-back set-next-when ] 2keep
|
[ dlist-back set-next-when ] 2keep
|
||||||
|
@ -76,6 +86,9 @@ PRIVATE>
|
||||||
[ set-front-to-back ] keep
|
[ set-front-to-back ] keep
|
||||||
inc-length ;
|
inc-length ;
|
||||||
|
|
||||||
|
: peek-front ( dlist -- obj )
|
||||||
|
dlist-front dlist-node-obj ;
|
||||||
|
|
||||||
: pop-front ( dlist -- obj )
|
: pop-front ( dlist -- obj )
|
||||||
dup dlist-front [
|
dup dlist-front [
|
||||||
dup dlist-node-next
|
dup dlist-node-next
|
||||||
|
@ -87,6 +100,9 @@ PRIVATE>
|
||||||
|
|
||||||
: pop-front* ( dlist -- ) pop-front drop ;
|
: pop-front* ( dlist -- ) pop-front drop ;
|
||||||
|
|
||||||
|
: peek-back ( dlist -- obj )
|
||||||
|
dlist-back dlist-node-obj ;
|
||||||
|
|
||||||
: pop-back ( dlist -- obj )
|
: pop-back ( dlist -- obj )
|
||||||
dup dlist-back [
|
dup dlist-back [
|
||||||
dup dlist-node-prev
|
dup dlist-node-prev
|
||||||
|
@ -108,25 +124,25 @@ PRIVATE>
|
||||||
dup dlist-node-prev over dlist-node-next set-prev-when
|
dup dlist-node-prev over dlist-node-next set-prev-when
|
||||||
dup dlist-node-next swap dlist-node-prev set-next-when ;
|
dup dlist-node-next swap dlist-node-prev set-next-when ;
|
||||||
|
|
||||||
: (delete-node) ( dlist dlist-node -- )
|
: delete-node ( dlist dlist-node -- )
|
||||||
{
|
{
|
||||||
{ [ over dlist-front over eq? ] [ drop pop-front* ] }
|
{ [ over dlist-front over eq? ] [ drop pop-front* ] }
|
||||||
{ [ over dlist-back over eq? ] [ drop pop-back* ] }
|
{ [ over dlist-back over eq? ] [ drop pop-back* ] }
|
||||||
{ [ t ] [ unlink-node dec-length ] }
|
{ [ t ] [ unlink-node dec-length ] }
|
||||||
} cond ;
|
} cond ;
|
||||||
|
|
||||||
: delete-node* ( quot dlist -- obj/f ? )
|
: delete-node-if* ( quot dlist -- obj/f ? )
|
||||||
tuck dlist-find-node [
|
tuck dlist-find-node [
|
||||||
[ (delete-node) ] keep [ dlist-node-obj t ] [ f f ] if*
|
[ delete-node ] keep [ dlist-node-obj t ] [ f f ] if*
|
||||||
] [
|
] [
|
||||||
2drop f f
|
2drop f f
|
||||||
] if ; inline
|
] if ; inline
|
||||||
|
|
||||||
: delete-node ( quot dlist -- obj/f )
|
: delete-node-if ( quot dlist -- obj/f )
|
||||||
delete-node* drop ; inline
|
delete-node-if* drop ; inline
|
||||||
|
|
||||||
: dlist-delete ( obj dlist -- obj/f )
|
: dlist-delete ( obj dlist -- obj/f )
|
||||||
>r [ eq? ] curry r> delete-node ;
|
>r [ eq? ] curry r> delete-node-if ;
|
||||||
|
|
||||||
: dlist-each ( dlist quot -- )
|
: dlist-each ( dlist quot -- )
|
||||||
[ dlist-node-obj ] swap compose dlist-each-node ; inline
|
[ dlist-node-obj ] swap compose dlist-each-node ; inline
|
||||||
|
|
|
@ -2,3 +2,9 @@ IN: temporary
|
||||||
USING: float-arrays tools.test ;
|
USING: float-arrays tools.test ;
|
||||||
|
|
||||||
[ F{ 1.0 1.0 1.0 } ] [ 3 1.0 <float-array> ] unit-test
|
[ F{ 1.0 1.0 1.0 } ] [ 3 1.0 <float-array> ] unit-test
|
||||||
|
|
||||||
|
[ F{ 1 2 3 0 0 0 } ] [ 6 F{ 1 2 3 } resize-float-array ] unit-test
|
||||||
|
|
||||||
|
[ F{ 1 2 } ] [ 2 F{ 1 2 3 4 5 6 7 8 9 } resize-float-array ] unit-test
|
||||||
|
|
||||||
|
[ -10 F{ } resize-float-array ] unit-test-fails
|
||||||
|
|
|
@ -29,6 +29,9 @@ M: float-array new drop 0.0 <float-array> ;
|
||||||
M: float-array equal?
|
M: float-array equal?
|
||||||
over float-array? [ sequence= ] [ 2drop f ] if ;
|
over float-array? [ sequence= ] [ 2drop f ] if ;
|
||||||
|
|
||||||
|
M: float-array resize
|
||||||
|
resize-float-array ;
|
||||||
|
|
||||||
INSTANCE: float-array sequence
|
INSTANCE: float-array sequence
|
||||||
INSTANCE: float-array simple-c-ptr
|
INSTANCE: float-array simple-c-ptr
|
||||||
INSTANCE: float-array c-ptr
|
INSTANCE: float-array c-ptr
|
||||||
|
|
|
@ -0,0 +1,34 @@
|
||||||
|
USING: arrays float-arrays help.markup help.syntax kernel
|
||||||
|
float-vectors.private combinators ;
|
||||||
|
IN: float-vectors
|
||||||
|
|
||||||
|
ARTICLE: "float-vectors" "Float vectors"
|
||||||
|
"A float vector is a resizable mutable sequence of unsigned floats. The literal syntax is covered in " { $link "syntax-float-vectors" } ". Float vector words are found in the " { $vocab-link "float-vectors" } " vocabulary."
|
||||||
|
$nl
|
||||||
|
"Float vectors form a class:"
|
||||||
|
{ $subsection float-vector }
|
||||||
|
{ $subsection float-vector? }
|
||||||
|
"Creating float vectors:"
|
||||||
|
{ $subsection >float-vector }
|
||||||
|
{ $subsection <float-vector> }
|
||||||
|
"If you don't care about initial capacity, a more elegant way to create a new float vector is to write:"
|
||||||
|
{ $code "BV{ } clone" } ;
|
||||||
|
|
||||||
|
ABOUT: "float-vectors"
|
||||||
|
|
||||||
|
HELP: float-vector
|
||||||
|
{ $description "The class of resizable float vectors. See " { $link "syntax-float-vectors" } " for syntax and " { $link "float-vectors" } " for general information." } ;
|
||||||
|
|
||||||
|
HELP: <float-vector>
|
||||||
|
{ $values { "n" "a positive integer specifying initial capacity" } { "float-vector" float-vector } }
|
||||||
|
{ $description "Creates a new float vector that can hold " { $snippet "n" } " floats before resizing." } ;
|
||||||
|
|
||||||
|
HELP: >float-vector
|
||||||
|
{ $values { "seq" "a sequence" } { "float-vector" float-vector } }
|
||||||
|
{ $description "Outputs a freshly-allocated float vector with the same elements as a given sequence." }
|
||||||
|
{ $errors "Throws an error if the sequence contains elements other than real numbers." } ;
|
||||||
|
|
||||||
|
HELP: float-array>vector
|
||||||
|
{ $values { "float-array" "an array" } { "length" "a non-negative integer" } { "float-vector" float-vector } }
|
||||||
|
{ $description "Creates a new float vector using the array for underlying storage with the specified initial length." }
|
||||||
|
{ $warning "This word is in the " { $vocab-link "float-vectors.private" } " vocabulary because it does not perform type or bounds checks. User code should call " { $link >float-vector } " instead." } ;
|
|
@ -0,0 +1,14 @@
|
||||||
|
IN: temporary
|
||||||
|
USING: tools.test float-vectors vectors sequences kernel ;
|
||||||
|
|
||||||
|
[ 0 ] [ 123 <float-vector> length ] unit-test
|
||||||
|
|
||||||
|
: do-it
|
||||||
|
12345 [ over push ] each ;
|
||||||
|
|
||||||
|
[ t ] [
|
||||||
|
3 <float-vector> do-it
|
||||||
|
3 <vector> do-it sequence=
|
||||||
|
] unit-test
|
||||||
|
|
||||||
|
[ t ] [ FV{ } float-vector? ] unit-test
|
|
@ -0,0 +1,33 @@
|
||||||
|
! Copyright (C) 2008 Slava Pestov.
|
||||||
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
|
USING: arrays kernel kernel.private math sequences
|
||||||
|
sequences.private growable float-arrays ;
|
||||||
|
IN: float-vectors
|
||||||
|
|
||||||
|
<PRIVATE
|
||||||
|
|
||||||
|
: float-array>vector ( float-array length -- float-vector )
|
||||||
|
float-vector construct-boa ; inline
|
||||||
|
|
||||||
|
PRIVATE>
|
||||||
|
|
||||||
|
: <float-vector> ( n -- float-vector )
|
||||||
|
0.0 <float-array> 0 float-array>vector ; inline
|
||||||
|
|
||||||
|
: >float-vector ( seq -- float-vector ) FV{ } clone-like ;
|
||||||
|
|
||||||
|
M: float-vector like
|
||||||
|
drop dup float-vector? [
|
||||||
|
dup float-array?
|
||||||
|
[ dup length float-array>vector ] [ >float-vector ] if
|
||||||
|
] unless ;
|
||||||
|
|
||||||
|
M: float-vector new
|
||||||
|
drop [ 0.0 <float-array> ] keep >fixnum float-array>vector ;
|
||||||
|
|
||||||
|
M: float-vector equal?
|
||||||
|
over float-vector? [ sequence= ] [ 2drop f ] if ;
|
||||||
|
|
||||||
|
M: float-array new-resizable drop <float-vector> ;
|
||||||
|
|
||||||
|
INSTANCE: float-vector growable
|
|
@ -19,8 +19,8 @@ SYMBOL: compiled
|
||||||
: queue-compile ( word -- )
|
: queue-compile ( word -- )
|
||||||
{
|
{
|
||||||
{ [ dup compiled get key? ] [ drop ] }
|
{ [ dup compiled get key? ] [ drop ] }
|
||||||
|
{ [ dup inlined-block? ] [ drop ] }
|
||||||
{ [ dup primitive? ] [ drop ] }
|
{ [ dup primitive? ] [ drop ] }
|
||||||
{ [ dup deferred? ] [ drop ] }
|
|
||||||
{ [ t ] [ dup compile-queue get set-at ] }
|
{ [ t ] [ dup compile-queue get set-at ] }
|
||||||
} cond ;
|
} cond ;
|
||||||
|
|
||||||
|
|
|
@ -107,5 +107,5 @@ M: class forget* ( class -- )
|
||||||
dup uncache-class
|
dup uncache-class
|
||||||
forget-word ;
|
forget-word ;
|
||||||
|
|
||||||
M: class update-methods ( class -- )
|
M: assoc update-methods ( assoc -- )
|
||||||
class-usages implementors* [ make-generic ] each ;
|
implementors* [ make-generic ] each ;
|
||||||
|
|
|
@ -116,10 +116,6 @@ HELP: <hashtable>
|
||||||
{ $values { "n" "a positive integer specifying hashtable capacity" } { "hash" "a new hashtable" } }
|
{ $values { "n" "a positive integer specifying hashtable capacity" } { "hash" "a new hashtable" } }
|
||||||
{ $description "Create a new hashtable capable of storing " { $snippet "n" } " key/value pairs before growing." } ;
|
{ $description "Create a new hashtable capable of storing " { $snippet "n" } " key/value pairs before growing." } ;
|
||||||
|
|
||||||
HELP: (hashtable) ( -- hash )
|
|
||||||
{ $values { "hash" "a new hashtable" } }
|
|
||||||
{ $description "Allocates a hashtable stub object without an underlying array. User code should call " { $link <hashtable> } " instead." } ;
|
|
||||||
|
|
||||||
HELP: associate
|
HELP: associate
|
||||||
{ $values { "value" "a value" } { "key" "a key" } { "hash" "a new " { $link hashtable } } }
|
{ $values { "value" "a value" } { "key" "a key" } { "hash" "a new " { $link hashtable } } }
|
||||||
{ $description "Create a new hashtable holding one key/value pair." } ;
|
{ $description "Create a new hashtable holding one key/value pair." } ;
|
||||||
|
|
|
@ -122,7 +122,7 @@ IN: hashtables
|
||||||
PRIVATE>
|
PRIVATE>
|
||||||
|
|
||||||
: <hashtable> ( n -- hash )
|
: <hashtable> ( n -- hash )
|
||||||
(hashtable) [ reset-hash ] keep ;
|
hashtable construct-empty [ reset-hash ] keep ;
|
||||||
|
|
||||||
M: hashtable at* ( key hash -- value ? )
|
M: hashtable at* ( key hash -- value ? )
|
||||||
key@ [ 3 fixnum+fast slot t ] [ 2drop f f ] if ;
|
key@ [ 3 fixnum+fast slot t ] [ 2drop f f ] if ;
|
||||||
|
|
|
@ -402,10 +402,14 @@ TUPLE: recursive-declare-error word ;
|
||||||
dup node-param #return node,
|
dup node-param #return node,
|
||||||
dataflow-graph get 1array over set-node-children ;
|
dataflow-graph get 1array over set-node-children ;
|
||||||
|
|
||||||
|
: inlined-block? "inlined-block" word-prop ;
|
||||||
|
|
||||||
|
: <inlined-block> gensym dup t "inlined-block" set-word-prop ;
|
||||||
|
|
||||||
: inline-block ( word -- node-block data )
|
: inline-block ( word -- node-block data )
|
||||||
[
|
[
|
||||||
copy-inference nest-node
|
copy-inference nest-node
|
||||||
dup word-def swap gensym
|
dup word-def swap <inlined-block>
|
||||||
[ infer-quot-recursive ] 2keep
|
[ infer-quot-recursive ] 2keep
|
||||||
#label unnest-node
|
#label unnest-node
|
||||||
] H{ } make-assoc ;
|
] H{ } make-assoc ;
|
||||||
|
|
|
@ -421,6 +421,8 @@ DEFER: bar
|
||||||
{ 2 1 } [ [ + ] [ ] [ ] cleanup ] unit-test-effect
|
{ 2 1 } [ [ + ] [ ] [ ] cleanup ] unit-test-effect
|
||||||
{ 2 1 } [ [ + ] [ 3drop 0 ] recover ] unit-test-effect
|
{ 2 1 } [ [ + ] [ 3drop 0 ] recover ] unit-test-effect
|
||||||
|
|
||||||
|
\ dispose must-infer
|
||||||
|
|
||||||
! Test stream protocol
|
! Test stream protocol
|
||||||
\ set-timeout must-infer
|
\ set-timeout must-infer
|
||||||
\ stream-read must-infer
|
\ stream-read must-infer
|
||||||
|
@ -430,7 +432,6 @@ DEFER: bar
|
||||||
\ stream-write must-infer
|
\ stream-write must-infer
|
||||||
\ stream-write1 must-infer
|
\ stream-write1 must-infer
|
||||||
\ stream-nl must-infer
|
\ stream-nl must-infer
|
||||||
\ stream-close must-infer
|
|
||||||
\ stream-format must-infer
|
\ stream-format must-infer
|
||||||
\ stream-write-table must-infer
|
\ stream-write-table must-infer
|
||||||
\ stream-flush must-infer
|
\ stream-flush must-infer
|
||||||
|
|
|
@ -167,9 +167,6 @@ t over set-effect-terminated?
|
||||||
|
|
||||||
\ rehash-string { string } { } <effect> "inferred-effect" set-word-prop
|
\ rehash-string { string } { } <effect> "inferred-effect" set-word-prop
|
||||||
|
|
||||||
\ string>sbuf { string integer } { sbuf } <effect> "inferred-effect" set-word-prop
|
|
||||||
\ string>sbuf make-flushable
|
|
||||||
|
|
||||||
\ bignum>fixnum { bignum } { fixnum } <effect> "inferred-effect" set-word-prop
|
\ bignum>fixnum { bignum } { fixnum } <effect> "inferred-effect" set-word-prop
|
||||||
\ bignum>fixnum make-foldable
|
\ bignum>fixnum make-foldable
|
||||||
|
|
||||||
|
@ -491,12 +488,18 @@ t over set-effect-terminated?
|
||||||
\ resize-array { integer array } { array } <effect> "inferred-effect" set-word-prop
|
\ resize-array { integer array } { array } <effect> "inferred-effect" set-word-prop
|
||||||
\ resize-array make-flushable
|
\ resize-array make-flushable
|
||||||
|
|
||||||
|
\ resize-byte-array { integer byte-array } { byte-array } <effect> "inferred-effect" set-word-prop
|
||||||
|
\ resize-byte-array make-flushable
|
||||||
|
|
||||||
|
\ resize-bit-array { integer bit-array } { bit-array } <effect> "inferred-effect" set-word-prop
|
||||||
|
\ resize-bit-array make-flushable
|
||||||
|
|
||||||
|
\ resize-float-array { integer float-array } { float-array } <effect> "inferred-effect" set-word-prop
|
||||||
|
\ resize-float-array make-flushable
|
||||||
|
|
||||||
\ resize-string { integer string } { string } <effect> "inferred-effect" set-word-prop
|
\ resize-string { integer string } { string } <effect> "inferred-effect" set-word-prop
|
||||||
\ resize-string make-flushable
|
\ resize-string make-flushable
|
||||||
|
|
||||||
\ (hashtable) { } { hashtable } <effect> "inferred-effect" set-word-prop
|
|
||||||
\ (hashtable) make-flushable
|
|
||||||
|
|
||||||
\ <array> { integer object } { array } <effect> "inferred-effect" set-word-prop
|
\ <array> { integer object } { array } <effect> "inferred-effect" set-word-prop
|
||||||
\ <array> make-flushable
|
\ <array> make-flushable
|
||||||
|
|
||||||
|
@ -532,9 +535,6 @@ t over set-effect-terminated?
|
||||||
\ (clone) { object } { object } <effect> "inferred-effect" set-word-prop
|
\ (clone) { object } { object } <effect> "inferred-effect" set-word-prop
|
||||||
\ (clone) make-flushable
|
\ (clone) make-flushable
|
||||||
|
|
||||||
\ array>vector { array integer } { vector } <effect> "inferred-effect" set-word-prop
|
|
||||||
\ array>vector make-flushable
|
|
||||||
|
|
||||||
\ <string> { integer integer } { string } <effect> "inferred-effect" set-word-prop
|
\ <string> { integer integer } { string } <effect> "inferred-effect" set-word-prop
|
||||||
\ <string> make-flushable
|
\ <string> make-flushable
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
IN: temporary
|
IN: temporary
|
||||||
USING: tools.test io.files io threads kernel ;
|
USING: tools.test io.files io threads kernel continuations ;
|
||||||
|
|
||||||
[ "passwd" ] [ "/etc/passwd" file-name ] unit-test
|
[ "passwd" ] [ "/etc/passwd" file-name ] unit-test
|
||||||
[ "awk/" ] [ "/usr/libexec/awk/" file-name ] unit-test
|
[ "awk/" ] [ "/usr/libexec/awk/" file-name ] unit-test
|
||||||
|
@ -41,7 +41,7 @@ USING: tools.test io.files io threads kernel ;
|
||||||
[ ] [ "test-blah" resource-path make-directory ] unit-test
|
[ ] [ "test-blah" resource-path make-directory ] unit-test
|
||||||
|
|
||||||
[ ] [
|
[ ] [
|
||||||
"test-blah/fooz" resource-path <file-writer> stream-close
|
"test-blah/fooz" resource-path <file-writer> dispose
|
||||||
] unit-test
|
] unit-test
|
||||||
|
|
||||||
[ t ] [
|
[ t ] [
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
USING: help.markup help.syntax quotations hashtables kernel
|
USING: help.markup help.syntax quotations hashtables kernel
|
||||||
classes strings ;
|
classes strings continuations ;
|
||||||
IN: io
|
IN: io
|
||||||
|
|
||||||
ARTICLE: "stream-protocol" "Stream protocol"
|
ARTICLE: "stream-protocol" "Stream protocol"
|
||||||
"The stream protocol consists of a large number of generic words, many of which are optional."
|
"The stream protocol consists of a large number of generic words, many of which are optional."
|
||||||
$nl
|
$nl
|
||||||
"A word required to be implemented for all streams:"
|
"All streams must implement the " { $link dispose } " word in addition to the stream protocol."
|
||||||
{ $subsection stream-close }
|
$nl
|
||||||
"Three words are required for input streams:"
|
"Three words are required for input streams:"
|
||||||
{ $subsection stream-read1 }
|
{ $subsection stream-read1 }
|
||||||
{ $subsection stream-read }
|
{ $subsection stream-read }
|
||||||
|
@ -73,16 +73,10 @@ ARTICLE: "streams" "Streams"
|
||||||
|
|
||||||
ABOUT: "streams"
|
ABOUT: "streams"
|
||||||
|
|
||||||
HELP: stream-close
|
|
||||||
{ $values { "stream" "a stream" } }
|
|
||||||
{ $contract "Closes the stream. This releases any external resources associated with the stream, such as file handles and network connections. No further operations can be performed on the stream after this call." }
|
|
||||||
{ $notes "You must close streams after you are finished working with them. A convenient way to automate this is by using the " { $link with-stream } " word." }
|
|
||||||
$io-error ;
|
|
||||||
|
|
||||||
HELP: set-timeout
|
HELP: set-timeout
|
||||||
{ $values { "n" "an integer" } { "stream" "a stream" } }
|
{ $values { "n" "an integer" } { "stream" "a stream" } }
|
||||||
{ $contract "Sets a timeout, in milliseconds, for closing the stream if there is no activity. Not all streams support timeouts." }
|
{ $contract "Sets a timeout, in milliseconds, for input and output operations on the stream. If a read or a write is initiated and no activity is seen before the timeout expires, an error will be thrown to the caller of the operation being performed." }
|
||||||
$io-error ;
|
{ $notes "Whether or not the stream is closed when the error is thrown is implementation-specific, and user code should take care to close the stream on all error conditions in any case." } ;
|
||||||
|
|
||||||
HELP: stream-readln
|
HELP: stream-readln
|
||||||
{ $values { "stream" "an input stream" } { "str" string } }
|
{ $values { "stream" "an input stream" } { "str" string } }
|
||||||
|
|
|
@ -4,7 +4,6 @@ USING: hashtables generic kernel math namespaces sequences strings
|
||||||
continuations assocs io.styles sbufs ;
|
continuations assocs io.styles sbufs ;
|
||||||
IN: io
|
IN: io
|
||||||
|
|
||||||
GENERIC: stream-close ( stream -- )
|
|
||||||
GENERIC: set-timeout ( n stream -- )
|
GENERIC: set-timeout ( n stream -- )
|
||||||
GENERIC: stream-readln ( stream -- str )
|
GENERIC: stream-readln ( stream -- str )
|
||||||
GENERIC: stream-read1 ( stream -- ch/f )
|
GENERIC: stream-read1 ( stream -- ch/f )
|
||||||
|
@ -29,7 +28,7 @@ GENERIC: stream-write-table ( table-cells style stream -- )
|
||||||
[ over stream-write (stream-copy) ] [ 2drop ] if* ;
|
[ over stream-write (stream-copy) ] [ 2drop ] if* ;
|
||||||
|
|
||||||
: stream-copy ( in out -- )
|
: stream-copy ( in out -- )
|
||||||
[ 2dup (stream-copy) ] [ stream-close stream-close ] [ ]
|
[ 2dup (stream-copy) ] [ dispose dispose ] [ ]
|
||||||
cleanup ;
|
cleanup ;
|
||||||
|
|
||||||
! Default stream
|
! Default stream
|
||||||
|
@ -54,9 +53,7 @@ SYMBOL: stderr
|
||||||
stdio swap with-variable ; inline
|
stdio swap with-variable ; inline
|
||||||
|
|
||||||
: with-stream ( stream quot -- )
|
: with-stream ( stream quot -- )
|
||||||
swap [
|
[ with-stream* ] curry with-disposal ; inline
|
||||||
[ stdio get stream-close ] [ ] cleanup
|
|
||||||
] with-stream* ; inline
|
|
||||||
|
|
||||||
: tabular-output ( style quot -- )
|
: tabular-output ( style quot -- )
|
||||||
swap >r { } make r> stdio get stream-write-table ; inline
|
swap >r { } make r> stdio get stream-write-table ; inline
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
! Copyright (C) 2004, 2007 Slava Pestov.
|
! Copyright (C) 2004, 2008 Slava Pestov.
|
||||||
! See http://factorcode.org/license.txt for BSD license.
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
USING: kernel kernel.private namespaces io
|
USING: kernel kernel.private namespaces io
|
||||||
strings sequences math generic threads.private classes
|
strings sequences math generic threads.private classes
|
||||||
io.backend io.streams.lines io.streams.plain io.streams.duplex
|
io.backend io.streams.lines io.streams.plain io.streams.duplex
|
||||||
io.files ;
|
io.files continuations ;
|
||||||
IN: io.streams.c
|
IN: io.streams.c
|
||||||
|
|
||||||
TUPLE: c-writer handle ;
|
TUPLE: c-writer handle ;
|
||||||
|
@ -19,7 +19,7 @@ M: c-writer stream-write
|
||||||
M: c-writer stream-flush
|
M: c-writer stream-flush
|
||||||
c-writer-handle fflush ;
|
c-writer-handle fflush ;
|
||||||
|
|
||||||
M: c-writer stream-close
|
M: c-writer dispose
|
||||||
c-writer-handle fclose ;
|
c-writer-handle fclose ;
|
||||||
|
|
||||||
TUPLE: c-reader handle ;
|
TUPLE: c-reader handle ;
|
||||||
|
@ -46,7 +46,7 @@ M: c-reader stream-read-until
|
||||||
[ swap read-until-loop ] "" make swap
|
[ swap read-until-loop ] "" make swap
|
||||||
over empty? over not and [ 2drop f f ] when ;
|
over empty? over not and [ 2drop f f ] when ;
|
||||||
|
|
||||||
M: c-reader stream-close
|
M: c-reader dispose
|
||||||
c-reader-handle fclose ;
|
c-reader-handle fclose ;
|
||||||
|
|
||||||
: <duplex-c-stream> ( in out -- stream )
|
: <duplex-c-stream> ( in out -- stream )
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
USING: help.markup help.syntax io ;
|
USING: help.markup help.syntax io continuations ;
|
||||||
IN: io.streams.duplex
|
IN: io.streams.duplex
|
||||||
|
|
||||||
ARTICLE: "io.streams.duplex" "Duplex streams"
|
ARTICLE: "io.streams.duplex" "Duplex streams"
|
||||||
|
@ -19,4 +19,4 @@ HELP: <duplex-stream>
|
||||||
HELP: check-closed
|
HELP: check-closed
|
||||||
{ $values { "stream" "a duplex stream" } }
|
{ $values { "stream" "a duplex stream" } }
|
||||||
{ $description "Throws a " { $link check-closed } " error if the stream has already been closed." }
|
{ $description "Throws a " { $link check-closed } " error if the stream has already been closed." }
|
||||||
{ $error-description "This error is thrown when performing an I/O operation on a " { $link duplex-stream } " which has been closed with " { $link stream-close } "." } ;
|
{ $error-description "This error is thrown when performing an I/O operation on a " { $link duplex-stream } " which has been closed with " { $link dispose } "." } ;
|
||||||
|
|
|
@ -6,7 +6,7 @@ TUPLE: closing-stream closed? ;
|
||||||
|
|
||||||
: <closing-stream> closing-stream construct-empty ;
|
: <closing-stream> closing-stream construct-empty ;
|
||||||
|
|
||||||
M: closing-stream stream-close
|
M: closing-stream dispose
|
||||||
dup closing-stream-closed? [
|
dup closing-stream-closed? [
|
||||||
"Closing twice!" throw
|
"Closing twice!" throw
|
||||||
] [
|
] [
|
||||||
|
@ -17,24 +17,24 @@ TUPLE: unclosable-stream ;
|
||||||
|
|
||||||
: <unclosable-stream> unclosable-stream construct-empty ;
|
: <unclosable-stream> unclosable-stream construct-empty ;
|
||||||
|
|
||||||
M: unclosable-stream stream-close
|
M: unclosable-stream dispose
|
||||||
"Can't close me!" throw ;
|
"Can't close me!" throw ;
|
||||||
|
|
||||||
[ ] [
|
[ ] [
|
||||||
<closing-stream> <closing-stream> <duplex-stream>
|
<closing-stream> <closing-stream> <duplex-stream>
|
||||||
dup stream-close stream-close
|
dup dispose dispose
|
||||||
] unit-test
|
] unit-test
|
||||||
|
|
||||||
[ t ] [
|
[ t ] [
|
||||||
<unclosable-stream> <closing-stream> [
|
<unclosable-stream> <closing-stream> [
|
||||||
<duplex-stream>
|
<duplex-stream>
|
||||||
[ dup stream-close ] catch 2drop
|
[ dup dispose ] catch 2drop
|
||||||
] keep closing-stream-closed?
|
] keep closing-stream-closed?
|
||||||
] unit-test
|
] unit-test
|
||||||
|
|
||||||
[ t ] [
|
[ t ] [
|
||||||
<closing-stream> [ <unclosable-stream>
|
<closing-stream> [ <unclosable-stream>
|
||||||
<duplex-stream>
|
<duplex-stream>
|
||||||
[ dup stream-close ] catch 2drop
|
[ dup dispose ] catch 2drop
|
||||||
] keep closing-stream-closed?
|
] keep closing-stream-closed?
|
||||||
] unit-test
|
] unit-test
|
||||||
|
|
|
@ -65,14 +65,14 @@ M: duplex-stream make-cell-stream
|
||||||
M: duplex-stream stream-write-table
|
M: duplex-stream stream-write-table
|
||||||
duplex-stream-out+ stream-write-table ;
|
duplex-stream-out+ stream-write-table ;
|
||||||
|
|
||||||
M: duplex-stream stream-close
|
M: duplex-stream dispose
|
||||||
#! The output stream is closed first, in case both streams
|
#! The output stream is closed first, in case both streams
|
||||||
#! are attached to the same file descriptor, the output
|
#! are attached to the same file descriptor, the output
|
||||||
#! buffer needs to be flushed before we close the fd.
|
#! buffer needs to be flushed before we close the fd.
|
||||||
dup duplex-stream-closed? [
|
dup duplex-stream-closed? [
|
||||||
t over set-duplex-stream-closed?
|
t over set-duplex-stream-closed?
|
||||||
[ dup duplex-stream-out stream-close ]
|
[ dup duplex-stream-out dispose ]
|
||||||
[ dup duplex-stream-in stream-close ] [ ] cleanup
|
[ dup duplex-stream-in dispose ] [ ] cleanup
|
||||||
] unless drop ;
|
] unless drop ;
|
||||||
|
|
||||||
M: duplex-stream set-timeout
|
M: duplex-stream set-timeout
|
||||||
|
|
|
@ -1,14 +1,14 @@
|
||||||
! Copyright (C) 2006, 2007 Slava Pestov.
|
! Copyright (C) 2006, 2008 Slava Pestov.
|
||||||
! See http://factorcode.org/license.txt for BSD license.
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
IN: io.streams.nested
|
IN: io.streams.nested
|
||||||
USING: arrays generic assocs kernel namespaces strings
|
USING: arrays generic assocs kernel namespaces strings
|
||||||
quotations io ;
|
quotations io continuations ;
|
||||||
|
|
||||||
TUPLE: ignore-close-stream ;
|
TUPLE: ignore-close-stream ;
|
||||||
|
|
||||||
: <ignore-close-stream> ignore-close-stream construct-delegate ;
|
: <ignore-close-stream> ignore-close-stream construct-delegate ;
|
||||||
|
|
||||||
M: ignore-close-stream stream-close drop ;
|
M: ignore-close-stream dispose drop ;
|
||||||
|
|
||||||
TUPLE: style-stream style ;
|
TUPLE: style-stream style ;
|
||||||
|
|
||||||
|
@ -44,4 +44,4 @@ TUPLE: block-stream ;
|
||||||
|
|
||||||
: <block-stream> block-stream construct-delegate ;
|
: <block-stream> block-stream construct-delegate ;
|
||||||
|
|
||||||
M: block-stream stream-close drop ;
|
M: block-stream dispose drop ;
|
||||||
|
|
|
@ -2,11 +2,13 @@
|
||||||
! See http://factorcode.org/license.txt for BSD license.
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
IN: io.streams.string
|
IN: io.streams.string
|
||||||
USING: io kernel math namespaces sequences sbufs strings
|
USING: io kernel math namespaces sequences sbufs strings
|
||||||
generic splitting io.streams.plain io.streams.lines ;
|
generic splitting io.streams.plain io.streams.lines
|
||||||
|
continuations ;
|
||||||
|
|
||||||
|
M: sbuf dispose drop ;
|
||||||
|
|
||||||
M: sbuf stream-write1 push ;
|
M: sbuf stream-write1 push ;
|
||||||
M: sbuf stream-write push-all ;
|
M: sbuf stream-write push-all ;
|
||||||
M: sbuf stream-close drop ;
|
|
||||||
M: sbuf stream-flush drop ;
|
M: sbuf stream-flush drop ;
|
||||||
|
|
||||||
: <string-writer> ( -- stream )
|
: <string-writer> ( -- stream )
|
||||||
|
|
|
@ -18,11 +18,10 @@ GENERIC: stream-read-quot ( stream -- quot/f )
|
||||||
[ parse-lines in get ] with-compilation-unit in set ;
|
[ parse-lines in get ] with-compilation-unit in set ;
|
||||||
|
|
||||||
: read-quot-step ( lines -- quot/f )
|
: read-quot-step ( lines -- quot/f )
|
||||||
[ parse-lines-interactive ] catch {
|
[ parse-lines-interactive ] [
|
||||||
{ [ dup delegate unexpected-eof? ] [ 2drop f ] }
|
dup delegate unexpected-eof?
|
||||||
{ [ dup not ] [ drop ] }
|
[ 2drop f ] [ rethrow ] if
|
||||||
{ [ t ] [ rethrow ] }
|
] recover ;
|
||||||
} cond ;
|
|
||||||
|
|
||||||
: read-quot-loop ( stream accum -- quot/f )
|
: read-quot-loop ( stream accum -- quot/f )
|
||||||
over stream-readln dup [
|
over stream-readln dup [
|
||||||
|
|
|
@ -1,9 +1,10 @@
|
||||||
! Copyright (C) 2003, 2007 Slava Pestov.
|
! Copyright (C) 2003, 2008 Slava Pestov.
|
||||||
! See http://factorcode.org/license.txt for BSD license.
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
USING: arrays byte-arrays bit-arrays generic hashtables io
|
USING: arrays byte-arrays byte-vectors bit-arrays bit-vectors
|
||||||
assocs kernel math namespaces sequences strings sbufs io.styles
|
generic hashtables io assocs kernel math namespaces sequences
|
||||||
vectors words prettyprint.config prettyprint.sections quotations
|
strings sbufs io.styles vectors words prettyprint.config
|
||||||
io io.files math.parser effects tuples classes float-arrays ;
|
prettyprint.sections quotations io io.files math.parser effects
|
||||||
|
tuples classes float-arrays float-vectors ;
|
||||||
IN: prettyprint.backend
|
IN: prettyprint.backend
|
||||||
|
|
||||||
GENERIC: pprint* ( obj -- )
|
GENERIC: pprint* ( obj -- )
|
||||||
|
@ -143,8 +144,11 @@ M: quotation pprint-delims drop \ [ \ ] ;
|
||||||
M: curry pprint-delims drop \ [ \ ] ;
|
M: curry pprint-delims drop \ [ \ ] ;
|
||||||
M: array pprint-delims drop \ { \ } ;
|
M: array pprint-delims drop \ { \ } ;
|
||||||
M: byte-array pprint-delims drop \ B{ \ } ;
|
M: byte-array pprint-delims drop \ B{ \ } ;
|
||||||
|
M: byte-vector pprint-delims drop \ BV{ \ } ;
|
||||||
M: bit-array pprint-delims drop \ ?{ \ } ;
|
M: bit-array pprint-delims drop \ ?{ \ } ;
|
||||||
|
M: bit-vector pprint-delims drop \ ?V{ \ } ;
|
||||||
M: float-array pprint-delims drop \ F{ \ } ;
|
M: float-array pprint-delims drop \ F{ \ } ;
|
||||||
|
M: float-vector pprint-delims drop \ FV{ \ } ;
|
||||||
M: vector pprint-delims drop \ V{ \ } ;
|
M: vector pprint-delims drop \ V{ \ } ;
|
||||||
M: hashtable pprint-delims drop \ H{ \ } ;
|
M: hashtable pprint-delims drop \ H{ \ } ;
|
||||||
M: tuple pprint-delims drop \ T{ \ } ;
|
M: tuple pprint-delims drop \ T{ \ } ;
|
||||||
|
@ -155,6 +159,10 @@ GENERIC: >pprint-sequence ( obj -- seq )
|
||||||
|
|
||||||
M: object >pprint-sequence ;
|
M: object >pprint-sequence ;
|
||||||
|
|
||||||
|
M: vector >pprint-sequence ;
|
||||||
|
M: bit-vector >pprint-sequence ;
|
||||||
|
M: byte-vector >pprint-sequence ;
|
||||||
|
M: float-vector >pprint-sequence ;
|
||||||
M: hashtable >pprint-sequence >alist ;
|
M: hashtable >pprint-sequence >alist ;
|
||||||
M: tuple >pprint-sequence tuple>array ;
|
M: tuple >pprint-sequence tuple>array ;
|
||||||
M: wrapper >pprint-sequence wrapped 1array ;
|
M: wrapper >pprint-sequence wrapped 1array ;
|
||||||
|
|
|
@ -1,9 +1,16 @@
|
||||||
! Copyright (C) 2004, 2007 Slava Pestov.
|
! Copyright (C) 2004, 2007 Slava Pestov.
|
||||||
! See http://factorcode.org/license.txt for BSD license.
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
USING: kernel math strings kernel.private sequences.private
|
USING: kernel math strings sequences.private sequences strings
|
||||||
sequences strings growable strings.private sbufs.private ;
|
growable strings.private ;
|
||||||
IN: sbufs
|
IN: sbufs
|
||||||
|
|
||||||
|
<PRIVATE
|
||||||
|
|
||||||
|
: string>sbuf ( string length -- sbuf )
|
||||||
|
sbuf construct-boa ; inline
|
||||||
|
|
||||||
|
PRIVATE>
|
||||||
|
|
||||||
: <sbuf> ( n -- sbuf ) 0 <string> 0 string>sbuf ; inline
|
: <sbuf> ( n -- sbuf ) 0 <string> 0 string>sbuf ; inline
|
||||||
|
|
||||||
M: sbuf set-nth-unsafe
|
M: sbuf set-nth-unsafe
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
! Copyright (C) 2005, 2007 Slava Pestov.
|
! Copyright (C) 2005, 2008 Slava Pestov.
|
||||||
! See http://factorcode.org/license.txt for BSD license.
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
USING: arrays kernel kernel.private math namespaces
|
USING: arrays kernel kernel.private math namespaces
|
||||||
sequences strings words effects generic generic.standard
|
sequences strings words effects generic generic.standard
|
||||||
classes slots.private ;
|
classes slots.private combinators ;
|
||||||
IN: slots
|
IN: slots
|
||||||
|
|
||||||
TUPLE: slot-spec type name offset reader writer ;
|
TUPLE: slot-spec type name offset reader writer ;
|
||||||
|
@ -87,14 +87,23 @@ PREDICATE: word slot-writer "writing" word-prop >boolean ;
|
||||||
: simple-writer-word ( class name -- word )
|
: simple-writer-word ( class name -- word )
|
||||||
(simple-slot-word) writer-word ;
|
(simple-slot-word) writer-word ;
|
||||||
|
|
||||||
: simple-slot ( class name # -- spec )
|
: short-slot ( class name # -- spec )
|
||||||
>r object bootstrap-word over r> f f <slot-spec>
|
>r object bootstrap-word over r> f f <slot-spec>
|
||||||
2over simple-reader-word over set-slot-spec-reader
|
2over simple-reader-word over set-slot-spec-reader
|
||||||
-rot simple-writer-word over set-slot-spec-writer ;
|
-rot simple-writer-word over set-slot-spec-writer ;
|
||||||
|
|
||||||
|
: long-slot ( spec # -- spec )
|
||||||
|
>r [ dup array? [ first2 create ] when ] map first4 r>
|
||||||
|
-rot <slot-spec> ;
|
||||||
|
|
||||||
: simple-slots ( class slots base -- specs )
|
: simple-slots ( class slots base -- specs )
|
||||||
over length [ + ] with map
|
over length [ + ] with map [
|
||||||
[ >r >r dup r> r> simple-slot ] 2map nip ;
|
{
|
||||||
|
{ [ over not ] [ 2drop f ] }
|
||||||
|
{ [ over string? ] [ >r dupd r> short-slot ] }
|
||||||
|
{ [ over array? ] [ long-slot ] }
|
||||||
|
} cond
|
||||||
|
] 2map [ ] subset nip ;
|
||||||
|
|
||||||
: slot-of-reader ( reader specs -- spec/f )
|
: slot-of-reader ( reader specs -- spec/f )
|
||||||
[ slot-spec-reader eq? ] with find nip ;
|
[ slot-spec-reader eq? ] with find nip ;
|
||||||
|
|
|
@ -68,7 +68,7 @@ uses definitions ;
|
||||||
: reset-checksums ( -- )
|
: reset-checksums ( -- )
|
||||||
source-files get [
|
source-files get [
|
||||||
swap ?resource-path dup exists?
|
swap ?resource-path dup exists?
|
||||||
[ file-lines record-checksum ] [ 2drop ] if
|
[ file-lines swap record-checksum ] [ 2drop ] if
|
||||||
] assoc-each ;
|
] assoc-each ;
|
||||||
|
|
||||||
M: pathname where pathname-string 1 2array ;
|
M: pathname where pathname-string 1 2array ;
|
||||||
|
|
|
@ -151,6 +151,18 @@ ARTICLE: "syntax-byte-arrays" "Byte array syntax"
|
||||||
{ $subsection POSTPONE: B{ }
|
{ $subsection POSTPONE: B{ }
|
||||||
"Byte arrays are documented in " { $link "byte-arrays" } "." ;
|
"Byte arrays are documented in " { $link "byte-arrays" } "." ;
|
||||||
|
|
||||||
|
ARTICLE: "syntax-bit-vectors" "Bit vector syntax"
|
||||||
|
{ $subsection POSTPONE: ?V{ }
|
||||||
|
"Bit vectors are documented in " { $link "bit-vectors" } "." ;
|
||||||
|
|
||||||
|
ARTICLE: "syntax-float-vectors" "Float vector syntax"
|
||||||
|
{ $subsection POSTPONE: FV{ }
|
||||||
|
"Float vectors are documented in " { $link "float-vectors" } "." ;
|
||||||
|
|
||||||
|
ARTICLE: "syntax-byte-vectors" "Byte vector syntax"
|
||||||
|
{ $subsection POSTPONE: BV{ }
|
||||||
|
"Byte vectors are documented in " { $link "byte-vectors" } "." ;
|
||||||
|
|
||||||
ARTICLE: "syntax-pathnames" "Pathname syntax"
|
ARTICLE: "syntax-pathnames" "Pathname syntax"
|
||||||
{ $subsection POSTPONE: P" }
|
{ $subsection POSTPONE: P" }
|
||||||
"Pathnames are documented in " { $link "file-streams" } "." ;
|
"Pathnames are documented in " { $link "file-streams" } "." ;
|
||||||
|
@ -165,11 +177,15 @@ $nl
|
||||||
{ $subsection "syntax-words" }
|
{ $subsection "syntax-words" }
|
||||||
{ $subsection "syntax-quots" }
|
{ $subsection "syntax-quots" }
|
||||||
{ $subsection "syntax-arrays" }
|
{ $subsection "syntax-arrays" }
|
||||||
{ $subsection "syntax-vectors" }
|
|
||||||
{ $subsection "syntax-strings" }
|
{ $subsection "syntax-strings" }
|
||||||
{ $subsection "syntax-sbufs" }
|
|
||||||
{ $subsection "syntax-byte-arrays" }
|
|
||||||
{ $subsection "syntax-bit-arrays" }
|
{ $subsection "syntax-bit-arrays" }
|
||||||
|
{ $subsection "syntax-byte-arrays" }
|
||||||
|
{ $subsection "syntax-float-arrays" }
|
||||||
|
{ $subsection "syntax-vectors" }
|
||||||
|
{ $subsection "syntax-sbufs" }
|
||||||
|
{ $subsection "syntax-bit-vectors" }
|
||||||
|
{ $subsection "syntax-byte-vectors" }
|
||||||
|
{ $subsection "syntax-float-vectors" }
|
||||||
{ $subsection "syntax-hashtables" }
|
{ $subsection "syntax-hashtables" }
|
||||||
{ $subsection "syntax-tuples" }
|
{ $subsection "syntax-tuples" }
|
||||||
{ $subsection "syntax-pathnames" } ;
|
{ $subsection "syntax-pathnames" } ;
|
||||||
|
@ -273,12 +289,30 @@ HELP: B{
|
||||||
{ $description "Marks the beginning of a literal byte array. Literal byte arrays are terminated by " { $link POSTPONE: } } "." }
|
{ $description "Marks the beginning of a literal byte array. Literal byte arrays are terminated by " { $link POSTPONE: } } "." }
|
||||||
{ $examples { $code "B{ 1 2 3 }" } } ;
|
{ $examples { $code "B{ 1 2 3 }" } } ;
|
||||||
|
|
||||||
|
HELP: BV{
|
||||||
|
{ $syntax "BV{ elements... }" }
|
||||||
|
{ $values { "elements" "a list of bytes" } }
|
||||||
|
{ $description "Marks the beginning of a literal byte vector. Literal byte vectors are terminated by " { $link POSTPONE: } } "." }
|
||||||
|
{ $examples { $code "BV{ 1 2 3 12 }" } } ;
|
||||||
|
|
||||||
HELP: ?{
|
HELP: ?{
|
||||||
{ $syntax "?{ elements... }" }
|
{ $syntax "?{ elements... }" }
|
||||||
{ $values { "elements" "a list of booleans" } }
|
{ $values { "elements" "a list of booleans" } }
|
||||||
{ $description "Marks the beginning of a literal bit array. Literal bit arrays are terminated by " { $link POSTPONE: } } "." }
|
{ $description "Marks the beginning of a literal bit array. Literal bit arrays are terminated by " { $link POSTPONE: } } "." }
|
||||||
{ $examples { $code "?{ t f t }" } } ;
|
{ $examples { $code "?{ t f t }" } } ;
|
||||||
|
|
||||||
|
HELP: ?V{
|
||||||
|
{ $syntax "?V{ elements... }" }
|
||||||
|
{ $values { "elements" "a list of booleans" } }
|
||||||
|
{ $description "Marks the beginning of a literal bit vector. Literal bit vectors are terminated by " { $link POSTPONE: } } "." }
|
||||||
|
{ $examples { $code "?V{ t f t }" } } ;
|
||||||
|
|
||||||
|
HELP: FV{
|
||||||
|
{ $syntax "FV{ elements... }" }
|
||||||
|
{ $values { "elements" "a list of real numbers" } }
|
||||||
|
{ $description "Marks the beginning of a literal float vector. Literal float vectors are terminated by " { $link POSTPONE: } } "." }
|
||||||
|
{ $examples { $code "FV{ 1.0 2.0 3.0 }" } } ;
|
||||||
|
|
||||||
HELP: F{
|
HELP: F{
|
||||||
{ $syntax "F{ elements... }" }
|
{ $syntax "F{ elements... }" }
|
||||||
{ $values { "elements" "a list of real numbers" } }
|
{ $values { "elements" "a list of real numbers" } }
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
! Copyright (C) 2004, 2007 Slava Pestov.
|
! Copyright (C) 2004, 2008 Slava Pestov.
|
||||||
! See http://factorcode.org/license.txt for BSD license.
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
USING: alien arrays bit-arrays byte-arrays definitions generic
|
USING: alien arrays bit-arrays bit-vectors byte-arrays
|
||||||
hashtables kernel math namespaces parser sequences strings sbufs
|
byte-vectors definitions generic hashtables kernel math
|
||||||
vectors words quotations io assocs splitting tuples
|
namespaces parser sequences strings sbufs vectors words
|
||||||
generic.standard generic.math classes io.files vocabs
|
quotations io assocs splitting tuples generic.standard
|
||||||
float-arrays classes.union classes.mixin classes.predicate
|
generic.math classes io.files vocabs float-arrays float-vectors
|
||||||
compiler.units ;
|
classes.union classes.mixin classes.predicate compiler.units ;
|
||||||
IN: bootstrap.syntax
|
IN: bootstrap.syntax
|
||||||
|
|
||||||
! These words are defined as a top-level form, instead of with
|
! These words are defined as a top-level form, instead of with
|
||||||
|
@ -71,8 +71,11 @@ IN: bootstrap.syntax
|
||||||
"{" [ \ } [ >array ] parse-literal ] define-syntax
|
"{" [ \ } [ >array ] parse-literal ] define-syntax
|
||||||
"V{" [ \ } [ >vector ] parse-literal ] define-syntax
|
"V{" [ \ } [ >vector ] parse-literal ] define-syntax
|
||||||
"B{" [ \ } [ >byte-array ] parse-literal ] define-syntax
|
"B{" [ \ } [ >byte-array ] parse-literal ] define-syntax
|
||||||
|
"BV{" [ \ } [ >byte-vector ] parse-literal ] define-syntax
|
||||||
"?{" [ \ } [ >bit-array ] parse-literal ] define-syntax
|
"?{" [ \ } [ >bit-array ] parse-literal ] define-syntax
|
||||||
|
"?V{" [ \ } [ >bit-vector ] parse-literal ] define-syntax
|
||||||
"F{" [ \ } [ >float-array ] parse-literal ] define-syntax
|
"F{" [ \ } [ >float-array ] parse-literal ] define-syntax
|
||||||
|
"FV{" [ \ } [ >float-vector ] parse-literal ] define-syntax
|
||||||
"H{" [ \ } [ >hashtable ] parse-literal ] define-syntax
|
"H{" [ \ } [ >hashtable ] parse-literal ] define-syntax
|
||||||
"T{" [ \ } [ >tuple ] parse-literal ] define-syntax
|
"T{" [ \ } [ >tuple ] parse-literal ] define-syntax
|
||||||
"W{" [ \ } [ first <wrapper> ] parse-literal ] define-syntax
|
"W{" [ \ } [ first <wrapper> ] parse-literal ] define-syntax
|
||||||
|
|
|
@ -49,6 +49,7 @@ HELP: os
|
||||||
"linux"
|
"linux"
|
||||||
"macosx"
|
"macosx"
|
||||||
"openbsd"
|
"openbsd"
|
||||||
|
"netbsd"
|
||||||
"solaris"
|
"solaris"
|
||||||
"windows"
|
"windows"
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,11 +39,11 @@ splitting assocs ;
|
||||||
|
|
||||||
: unix? ( -- ? )
|
: unix? ( -- ? )
|
||||||
os {
|
os {
|
||||||
"freebsd" "openbsd" "linux" "macosx" "solaris"
|
"freebsd" "openbsd" "netbsd" "linux" "macosx" "solaris"
|
||||||
} member? ;
|
} member? ;
|
||||||
|
|
||||||
: bsd? ( -- ? )
|
: bsd? ( -- ? )
|
||||||
os { "freebsd" "openbsd" "macosx" } member? ;
|
os { "freebsd" "openbsd" "netbsd" "macosx" } member? ;
|
||||||
|
|
||||||
: linux? ( -- ? )
|
: linux? ( -- ? )
|
||||||
os "linux" = ;
|
os "linux" = ;
|
||||||
|
|
|
@ -80,8 +80,8 @@ PRIVATE>
|
||||||
} ;
|
} ;
|
||||||
|
|
||||||
: define-tuple-slots ( class slots -- )
|
: define-tuple-slots ( class slots -- )
|
||||||
2dup "slot-names" set-word-prop
|
|
||||||
dupd 4 simple-slots
|
dupd 4 simple-slots
|
||||||
|
2dup [ slot-spec-name ] map "slot-names" set-word-prop
|
||||||
2dup delegate-slot-spec add* "slots" set-word-prop
|
2dup delegate-slot-spec add* "slots" set-word-prop
|
||||||
define-slots ;
|
define-slots ;
|
||||||
|
|
||||||
|
|
|
@ -30,10 +30,10 @@ HELP: >vector
|
||||||
{ $values { "seq" "a sequence" } { "vector" vector } }
|
{ $values { "seq" "a sequence" } { "vector" vector } }
|
||||||
{ $description "Outputs a freshly-allocated vector with the same elements as a given sequence." } ;
|
{ $description "Outputs a freshly-allocated vector with the same elements as a given sequence." } ;
|
||||||
|
|
||||||
HELP: array>vector ( array length -- vector )
|
HELP: array>vector
|
||||||
{ $values { "array" "an array" } { "length" "a non-negative integer" } { "vector" vector } }
|
{ $values { "array" "an array" } { "length" "a non-negative integer" } { "vector" vector } }
|
||||||
{ $description "Creates a new vector using the array for underlying storage with the specified initial length." }
|
{ $description "Creates a new vector using the array for underlying storage with the specified initial length." }
|
||||||
{ $warning "This word is in the " { $vocab-link "sequences.private" } " vocabulary because it does not perform type or bounds checks. User code should call " { $link >vector } " instead." } ;
|
{ $warning "This word is in the " { $vocab-link "vectors.private" } " vocabulary because it does not perform type or bounds checks. User code should call " { $link >vector } " instead." } ;
|
||||||
|
|
||||||
HELP: 1vector
|
HELP: 1vector
|
||||||
{ $values { "x" object } { "vector" vector } }
|
{ $values { "x" object } { "vector" vector } }
|
||||||
|
|
|
@ -1,10 +1,15 @@
|
||||||
! Copyright (C) 2004, 2007 Slava Pestov.
|
! Copyright (C) 2004, 2008 Slava Pestov.
|
||||||
! See http://factorcode.org/license.txt for BSD license.
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
USING: arrays kernel kernel.private math
|
USING: arrays kernel math sequences sequences.private growable ;
|
||||||
math.private sequences sequences.private vectors.private
|
|
||||||
growable ;
|
|
||||||
IN: vectors
|
IN: vectors
|
||||||
|
|
||||||
|
<PRIVATE
|
||||||
|
|
||||||
|
: array>vector ( byte-array capacity -- byte-vector )
|
||||||
|
vector construct-boa ; inline
|
||||||
|
|
||||||
|
PRIVATE>
|
||||||
|
|
||||||
: <vector> ( n -- vector ) f <array> 0 array>vector ; inline
|
: <vector> ( n -- vector ) f <array> 0 array>vector ; inline
|
||||||
|
|
||||||
: >vector ( seq -- vector ) V{ } clone-like ;
|
: >vector ( seq -- vector ) V{ } clone-like ;
|
||||||
|
|
|
@ -148,8 +148,16 @@ SYMBOL: load-help?
|
||||||
dup update-roots
|
dup update-roots
|
||||||
dup modified-sources swap modified-docs ;
|
dup modified-sources swap modified-docs ;
|
||||||
|
|
||||||
|
: require-restart { { "Ignore this vocabulary" t } } ;
|
||||||
|
|
||||||
: require-all ( seq -- )
|
: require-all ( seq -- )
|
||||||
[ [ require ] each ] with-compiler-errors ;
|
[
|
||||||
|
[
|
||||||
|
[ require ]
|
||||||
|
[ require-restart rethrow-restarts 2drop ]
|
||||||
|
recover
|
||||||
|
] each
|
||||||
|
] with-compiler-errors ;
|
||||||
|
|
||||||
: do-refresh ( modified-sources modified-docs -- )
|
: do-refresh ( modified-sources modified-docs -- )
|
||||||
2dup
|
2dup
|
||||||
|
|
|
@ -9,16 +9,12 @@ IN: assocs.lib
|
||||||
|
|
||||||
: ref-at ( table key -- value ) swap at ;
|
: ref-at ( table key -- value ) swap at ;
|
||||||
|
|
||||||
! set-at with alternative stack effects
|
|
||||||
|
|
||||||
: put-at* ( table key value -- ) swap rot set-at ;
|
: put-at* ( table key value -- ) swap rot set-at ;
|
||||||
|
|
||||||
: put-at ( table key value -- table ) swap pick set-at ;
|
: put-at ( table key value -- table ) swap pick set-at ;
|
||||||
|
|
||||||
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
|
||||||
|
|
||||||
: set-assoc-stack ( value key seq -- )
|
: set-assoc-stack ( value key seq -- )
|
||||||
dupd [ key? ] with find-last nip set-at ;
|
dupd [ key? ] with find-last nip set-at ;
|
||||||
|
|
||||||
: at-default ( key assoc -- value/key )
|
: at-default ( key assoc -- value/key )
|
||||||
dupd at [ nip ] when* ;
|
dupd at [ nip ] when* ;
|
||||||
|
|
|
@ -1,9 +1,14 @@
|
||||||
USING: tools.deploy.private io.files system
|
USING: io.files io.launcher system tools.deploy.backend
|
||||||
tools.deploy.backend ;
|
namespaces sequences kernel ;
|
||||||
IN: benchmark.bootstrap2
|
IN: benchmark.bootstrap2
|
||||||
|
|
||||||
: bootstrap-benchmark
|
: bootstrap-benchmark
|
||||||
"." resource-path cd
|
"." resource-path cd
|
||||||
vm { "-output-image=foo.image" "-no-user-init" } stage2 ;
|
[
|
||||||
|
vm ,
|
||||||
|
"-i=" boot-image-name append ,
|
||||||
|
"-output-image=foo.image" ,
|
||||||
|
"-no-user-init" ,
|
||||||
|
] { } make run-process drop ;
|
||||||
|
|
||||||
MAIN: bootstrap-benchmark
|
MAIN: bootstrap-benchmark
|
||||||
|
|
|
@ -0,0 +1,113 @@
|
||||||
|
|
||||||
|
USING: kernel io io.files io.launcher
|
||||||
|
system namespaces sequences splitting math.parser
|
||||||
|
unix prettyprint tools.time calendar bake vars ;
|
||||||
|
|
||||||
|
IN: builder
|
||||||
|
|
||||||
|
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||||
|
|
||||||
|
: datestamp ( -- string )
|
||||||
|
now `{ ,[ dup timestamp-year ]
|
||||||
|
,[ dup timestamp-month ]
|
||||||
|
,[ dup timestamp-day ]
|
||||||
|
,[ dup timestamp-hour ]
|
||||||
|
,[ timestamp-minute ] }
|
||||||
|
[ number>string 2 CHAR: 0 pad-left ] map "-" join ;
|
||||||
|
|
||||||
|
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||||
|
|
||||||
|
SYMBOL: builder-recipients
|
||||||
|
|
||||||
|
: quote ( str -- str ) "'" swap "'" 3append ;
|
||||||
|
|
||||||
|
: email-file ( subject file -- )
|
||||||
|
`{
|
||||||
|
"cat" ,
|
||||||
|
"| mutt -s" ,[ quote ]
|
||||||
|
"-x" %[ builder-recipients get ]
|
||||||
|
}
|
||||||
|
" " join system drop ;
|
||||||
|
|
||||||
|
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||||
|
|
||||||
|
: boot-image ( -- filename ) `{ "boot" ,[ cpu ] "image" } "." join ;
|
||||||
|
|
||||||
|
: target ( -- target ) `{ ,[ os ] %[ cpu "." split ] } "-" join ;
|
||||||
|
|
||||||
|
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||||
|
|
||||||
|
VAR: stamp
|
||||||
|
|
||||||
|
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||||
|
|
||||||
|
: build ( -- )
|
||||||
|
|
||||||
|
datestamp >stamp
|
||||||
|
|
||||||
|
"/builds/factor" cd
|
||||||
|
"git pull git://factorcode.org/git/factor.git" system
|
||||||
|
0 =
|
||||||
|
[ ]
|
||||||
|
[
|
||||||
|
"builder: git pull" "/dev/null" email-file
|
||||||
|
"builder: git pull" throw
|
||||||
|
]
|
||||||
|
if
|
||||||
|
|
||||||
|
"/builds/" stamp> append make-directory
|
||||||
|
"/builds/" stamp> append cd
|
||||||
|
"git clone /builds/factor" system drop
|
||||||
|
|
||||||
|
"factor" cd
|
||||||
|
|
||||||
|
{ "/usr/bin/git" "show" } <process-stream>
|
||||||
|
[ readln ] with-stream
|
||||||
|
" " split second
|
||||||
|
"../git-id" <file-writer> [ print ] with-stream
|
||||||
|
|
||||||
|
"make clean" system drop
|
||||||
|
|
||||||
|
"make " target " > ../compile-log" 3append system
|
||||||
|
0 =
|
||||||
|
[ ]
|
||||||
|
[
|
||||||
|
"builder: vm compile" "../compile-log" email-file
|
||||||
|
"builder: vm compile" throw
|
||||||
|
] if
|
||||||
|
|
||||||
|
"wget http://factorcode.org/images/latest/" boot-image append system
|
||||||
|
0 =
|
||||||
|
[ ]
|
||||||
|
[
|
||||||
|
"builder: image download" "/dev/null" email-file
|
||||||
|
"builder: image download" throw
|
||||||
|
] if
|
||||||
|
|
||||||
|
[ "./factor -i=" boot-image " -no-user-init > ../boot-log" 3append system ]
|
||||||
|
benchmark nip
|
||||||
|
"../boot-time" <file-writer> [ . ] with-stream
|
||||||
|
0 =
|
||||||
|
[ ]
|
||||||
|
[
|
||||||
|
"builder: bootstrap" "../boot-log" email-file
|
||||||
|
"builder: bootstrap" throw
|
||||||
|
] if
|
||||||
|
|
||||||
|
[
|
||||||
|
"./factor -e='USE: tools.browser load-everything' > ../load-everything-log"
|
||||||
|
system
|
||||||
|
] benchmark nip
|
||||||
|
"../load-everything-time" <file-writer> [ . ] with-stream
|
||||||
|
0 =
|
||||||
|
[ ]
|
||||||
|
[
|
||||||
|
"builder: load-everything" "../load-everything-log" email-file
|
||||||
|
"builder: load-everything" throw
|
||||||
|
] if
|
||||||
|
|
||||||
|
;
|
||||||
|
|
||||||
|
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||||
|
|
||||||
|
MAIN: build
|
|
@ -53,7 +53,7 @@ IN: bunny
|
||||||
model-path resource-path dup exists? [
|
model-path resource-path dup exists? [
|
||||||
"Downloading bunny from " write
|
"Downloading bunny from " write
|
||||||
model-url dup print flush
|
model-url dup print flush
|
||||||
over download
|
over download-to
|
||||||
] unless ;
|
] unless ;
|
||||||
|
|
||||||
: draw-triangle ( ns vs triple -- )
|
: draw-triangle ( ns vs triple -- )
|
||||||
|
|
|
@ -41,7 +41,7 @@ VARS: input user ;
|
||||||
: ((send-input)) ( other -- ) [ input> print flush ] with-stream* ;
|
: ((send-input)) ( other -- ) [ input> print flush ] with-stream* ;
|
||||||
|
|
||||||
: (send-input) ( other -- )
|
: (send-input) ( other -- )
|
||||||
[ ((send-input)) ] catch [ print dup stream-close users> delete ] when ;
|
[ ((send-input)) ] catch [ print dup dispose users> delete ] when ;
|
||||||
|
|
||||||
: send-input ( other -- )
|
: send-input ( other -- )
|
||||||
dup duplex-stream-closed? [ users> delete ] [ (send-input) ] if ;
|
dup duplex-stream-closed? [ users> delete ] [ (send-input) ] if ;
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
Doug Coleman
|
Slava Pestov
|
||||||
|
|
|
@ -333,16 +333,18 @@ M: integer year. ( n -- )
|
||||||
M: timestamp year. ( timestamp -- )
|
M: timestamp year. ( timestamp -- )
|
||||||
timestamp-year year. ;
|
timestamp-year year. ;
|
||||||
|
|
||||||
: pad-00 number>string 2 CHAR: 0 pad-left write ;
|
: pad-00 number>string 2 CHAR: 0 pad-left ;
|
||||||
|
|
||||||
|
: write-00 pad-00 write ;
|
||||||
|
|
||||||
: (timestamp>string) ( timestamp -- )
|
: (timestamp>string) ( timestamp -- )
|
||||||
dup day-of-week day-abbreviations3 nth write ", " write
|
dup day-of-week day-abbreviations3 nth write ", " write
|
||||||
dup timestamp-day number>string write bl
|
dup timestamp-day number>string write bl
|
||||||
dup timestamp-month month-abbreviations nth write bl
|
dup timestamp-month month-abbreviations nth write bl
|
||||||
dup timestamp-year number>string write bl
|
dup timestamp-year number>string write bl
|
||||||
dup timestamp-hour pad-00 ":" write
|
dup timestamp-hour write-00 ":" write
|
||||||
dup timestamp-minute pad-00 ":" write
|
dup timestamp-minute write-00 ":" write
|
||||||
timestamp-second >fixnum pad-00 ;
|
timestamp-second >fixnum write-00 ;
|
||||||
|
|
||||||
: timestamp>string ( timestamp -- str )
|
: timestamp>string ( timestamp -- str )
|
||||||
[ (timestamp>string) ] string-out ;
|
[ (timestamp>string) ] string-out ;
|
||||||
|
@ -357,11 +359,11 @@ M: timestamp year. ( timestamp -- )
|
||||||
|
|
||||||
: (timestamp>rfc3339) ( timestamp -- )
|
: (timestamp>rfc3339) ( timestamp -- )
|
||||||
dup timestamp-year number>string write CHAR: - write1
|
dup timestamp-year number>string write CHAR: - write1
|
||||||
dup timestamp-month pad-00 CHAR: - write1
|
dup timestamp-month write-00 CHAR: - write1
|
||||||
dup timestamp-day pad-00 CHAR: T write1
|
dup timestamp-day write-00 CHAR: T write1
|
||||||
dup timestamp-hour pad-00 CHAR: : write1
|
dup timestamp-hour write-00 CHAR: : write1
|
||||||
dup timestamp-minute pad-00 CHAR: : write1
|
dup timestamp-minute write-00 CHAR: : write1
|
||||||
timestamp-second >fixnum pad-00 CHAR: Z write1 ;
|
timestamp-second >fixnum write-00 CHAR: Z write1 ;
|
||||||
|
|
||||||
: timestamp>rfc3339 ( timestamp -- str )
|
: timestamp>rfc3339 ( timestamp -- str )
|
||||||
>gmt [ (timestamp>rfc3339) ] string-out ;
|
>gmt [ (timestamp>rfc3339) ] string-out ;
|
||||||
|
@ -390,8 +392,8 @@ M: timestamp year. ( timestamp -- )
|
||||||
[ timestamp-month month-abbreviations nth write ] keep bl
|
[ timestamp-month month-abbreviations nth write ] keep bl
|
||||||
[ timestamp-day number>string 2 32 pad-left write ] keep bl
|
[ timestamp-day number>string 2 32 pad-left write ] keep bl
|
||||||
dup now [ timestamp-year ] 2apply = [
|
dup now [ timestamp-year ] 2apply = [
|
||||||
[ timestamp-hour pad-00 ] keep ":" write
|
[ timestamp-hour write-00 ] keep ":" write
|
||||||
timestamp-minute pad-00
|
timestamp-minute write-00
|
||||||
] [
|
] [
|
||||||
timestamp-year number>string 5 32 pad-left write
|
timestamp-year number>string 5 32 pad-left write
|
||||||
] if
|
] if
|
||||||
|
|
|
@ -0,0 +1,15 @@
|
||||||
|
! Copyright (C) 2008 Slava Pestov
|
||||||
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
|
USING: calendar namespaces models threads init ;
|
||||||
|
IN: calendar.model
|
||||||
|
|
||||||
|
SYMBOL: time
|
||||||
|
|
||||||
|
: (time-thread) ( -- )
|
||||||
|
now time get set-model
|
||||||
|
1000 sleep (time-thread) ;
|
||||||
|
|
||||||
|
: time-thread ( -- ) [ (time-thread) ] in-thread ;
|
||||||
|
|
||||||
|
f <model> time set-global
|
||||||
|
[ time-thread ] "calendar.model" add-init-hook
|
|
@ -1 +1 @@
|
||||||
Date and time classes
|
Timestamp model updated every second
|
||||||
|
|
|
@ -1,121 +0,0 @@
|
||||||
USING: slides help.markup math arrays hashtables namespaces
|
|
||||||
sequences kernel sequences parser ;
|
|
||||||
IN: catalyst-talk
|
|
||||||
|
|
||||||
: catalyst-slides
|
|
||||||
{
|
|
||||||
{ $slide "What is Factor?"
|
|
||||||
"Originally scripting for a Java game"
|
|
||||||
"Language dev more fun than game dev"
|
|
||||||
"Start with ideas which were mostly dead"
|
|
||||||
"Throw in features from crazy languages"
|
|
||||||
"Develop practical libraries and tools"
|
|
||||||
}
|
|
||||||
{ $slide "Factor: a stack language"
|
|
||||||
"Implicit parameter passing"
|
|
||||||
{ "Each " { $emphasis "word" } " is a function call" }
|
|
||||||
{ $code ": sq dup * ;" }
|
|
||||||
{ $code "2 3 + sq ." }
|
|
||||||
"Minimal syntax and semantics = easy meta-programming"
|
|
||||||
{ "Related languages: Forth, Joy, PostScript" }
|
|
||||||
}
|
|
||||||
{ $slide "Factor: a functional language"
|
|
||||||
{ { $emphasis "Quotations" } " can be passed around, constructed..." }
|
|
||||||
{ $code "[ sq 3 + ]" }
|
|
||||||
{ { $emphasis "Combinators" } " are words which take quotations, eg " { $link if } }
|
|
||||||
{ "For FP buffs: " { $link each } ", " { $link map } ", " { $link reduce } ", " { $link accumulate } ", " { $link interleave } ", " { $link subset } }
|
|
||||||
{ $code "{ 42 69 666 } [ sq 3 + ] map ." }
|
|
||||||
}
|
|
||||||
{ $slide "Factor: an object-oriented language"
|
|
||||||
{ "Everything is an " { $emphasis "object" } }
|
|
||||||
{ "An object is an instance of a " { $emphasis "class" } }
|
|
||||||
"Methods"
|
|
||||||
"Generic words"
|
|
||||||
"For CLOS buffs: we allow custom method combination, classes are objects too, there's a MOP"
|
|
||||||
}
|
|
||||||
|
|
||||||
STRIP-TEASE:
|
|
||||||
$slide "Primary school geometry recap"
|
|
||||||
{ $code
|
|
||||||
"GENERIC: area ( shape -- meters^2 )"
|
|
||||||
"TUPLE: square dimension ;"
|
|
||||||
"M: square area square-dimension sq ;"
|
|
||||||
"TUPLE: circle radius ;"
|
|
||||||
"M: circle area circle-radius sq pi * ;"
|
|
||||||
"TUPLE: rectangle width height ;"
|
|
||||||
"M: rectangle area"
|
|
||||||
" dup rectangle-width"
|
|
||||||
" swap rectangle-height"
|
|
||||||
" * ;"
|
|
||||||
}
|
|
||||||
;
|
|
||||||
|
|
||||||
{ $slide "Geometry example"
|
|
||||||
{ $code "10 <square> area ." }
|
|
||||||
{ $code "18 <circle> area ." }
|
|
||||||
{ $code "20 40 <rectangle> area ." }
|
|
||||||
}
|
|
||||||
! { $slide "Factor: a meta language"
|
|
||||||
! "Writing code which writes code"
|
|
||||||
! "Extensible parser: define new syntax"
|
|
||||||
! "Compiler transforms"
|
|
||||||
! "Here's an inefficient word:"
|
|
||||||
! { $code
|
|
||||||
! ": fib ( x -- y )"
|
|
||||||
! " dup 1 > ["
|
|
||||||
! " 1 - dup fib swap 1 - fib +"
|
|
||||||
! " ] when ;"
|
|
||||||
! }
|
|
||||||
! }
|
|
||||||
! { $slide "Memoization"
|
|
||||||
! { { $link POSTPONE: : } " is just another word" }
|
|
||||||
! "What if we could define a word which caches its results?"
|
|
||||||
! { "The " { $vocab-link "memoize" } " library provides such a feature" }
|
|
||||||
! { "Just change " { $link POSTPONE: : } " to " { $link POSTPONE: MEMO: } }
|
|
||||||
! { $code
|
|
||||||
! "MEMO: fib ( x -- y )"
|
|
||||||
! " dup 1 > ["
|
|
||||||
! " 1 - dup fib swap 1 - fib +"
|
|
||||||
! " ] when ;"
|
|
||||||
! }
|
|
||||||
! }
|
|
||||||
{ $slide "Factor: a tool-building language"
|
|
||||||
"Tools are not monolithic, but are themselves just sets of words"
|
|
||||||
"Examples: parser, compiler, etc"
|
|
||||||
"Parser: turns strings into objects"
|
|
||||||
{ $code "\"1\" <file-reader> contents parse" }
|
|
||||||
"Prettyprinter: turns objects into strings"
|
|
||||||
{ $code "\"2\" <file-writer> [ . ] with-stream" }
|
|
||||||
}
|
|
||||||
{ $slide "Factor: an interactive language"
|
|
||||||
{ "Let's hack " { $vocab-link "tetris" } }
|
|
||||||
"Editor integration"
|
|
||||||
{ $code "\\ tetrominoes edit" }
|
|
||||||
"Inspector"
|
|
||||||
{ $code "\\ tetrominoes get inspect" }
|
|
||||||
}
|
|
||||||
{ $slide "C library interface"
|
|
||||||
"No need to write C glue code!"
|
|
||||||
"Callbacks from C to Factor"
|
|
||||||
"Factor can be embedded in C apps"
|
|
||||||
{ "Example: " { $vocab-link "ogg.vorbis" } }
|
|
||||||
{ "Other bindings: OpenGL, OpenAL, X11, Win32, Cocoa, OpenSSL, memory mapped files, ..." }
|
|
||||||
}
|
|
||||||
{ $slide "Native libraries"
|
|
||||||
"XML, HTTP, SMTP, Unicode, calendar, ..."
|
|
||||||
"Lazy lists, pattern matching, packed arrays, ..."
|
|
||||||
}
|
|
||||||
{ $slide "Factor: a fun language"
|
|
||||||
{ "Let's play "
|
|
||||||
{ $vocab-link "space-invaders" }
|
|
||||||
}
|
|
||||||
{ $url "http://factorcode.org" }
|
|
||||||
{ $url "http://factor-language.blogspot.com" }
|
|
||||||
"irc.freenode.net #concatenative"
|
|
||||||
"Have fun!"
|
|
||||||
}
|
|
||||||
} ;
|
|
||||||
|
|
||||||
: catalyst-talk catalyst-slides slides-window ;
|
|
||||||
|
|
||||||
MAIN: catalyst-talk
|
|
|
@ -1 +0,0 @@
|
||||||
Slides for a talk at Catalyst IT NZ, July 2007
|
|
|
@ -84,7 +84,7 @@ M: crypt-stream stream-write1 ( ch stream -- )
|
||||||
: check-close ( err -- )
|
: check-close ( err -- )
|
||||||
dup CRYPT_ERROR_PARAM1 = [ drop ] [ check-result ] if ;
|
dup CRYPT_ERROR_PARAM1 = [ drop ] [ check-result ] if ;
|
||||||
|
|
||||||
M: crypt-stream stream-close ( stream -- )
|
M: crypt-stream dispose ( stream -- )
|
||||||
crypt-stream-handle cryptDestroySession check-close ;
|
crypt-stream-handle cryptDestroySession check-close ;
|
||||||
|
|
||||||
: create-session ( format -- session )
|
: create-session ( format -- session )
|
||||||
|
@ -115,7 +115,7 @@ M: crypt-stream stream-close ( stream -- )
|
||||||
|
|
||||||
dup stream-readln print
|
dup stream-readln print
|
||||||
|
|
||||||
stream-close
|
dispose
|
||||||
end
|
end
|
||||||
;
|
;
|
||||||
|
|
||||||
|
@ -130,7 +130,7 @@ M: crypt-stream stream-close ( stream -- )
|
||||||
"Thanks!" over stream-print
|
"Thanks!" over stream-print
|
||||||
dup stream-flush
|
dup stream-flush
|
||||||
|
|
||||||
stream-close
|
dispose
|
||||||
end
|
end
|
||||||
;
|
;
|
||||||
|
|
||||||
|
@ -152,6 +152,6 @@ M: crypt-stream stream-close ( stream -- )
|
||||||
|
|
||||||
(rpl)
|
(rpl)
|
||||||
|
|
||||||
stream-close
|
dispose
|
||||||
end
|
end
|
||||||
;
|
;
|
|
@ -15,7 +15,7 @@ PROTOCOL: assoc-protocol
|
||||||
! everything should work, just slower (with >alist)
|
! everything should work, just slower (with >alist)
|
||||||
|
|
||||||
PROTOCOL: stream-protocol
|
PROTOCOL: stream-protocol
|
||||||
stream-close stream-read1 stream-read stream-read-until
|
stream-read1 stream-read stream-read-until
|
||||||
stream-flush stream-write1 stream-write stream-format
|
stream-flush stream-write1 stream-write stream-format
|
||||||
stream-nl make-span-stream make-block-stream stream-readln
|
stream-nl make-span-stream make-block-stream stream-readln
|
||||||
make-cell-stream stream-write-table set-timeout ;
|
make-cell-stream stream-write-table set-timeout ;
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
USING: editors.gvim io.files io.windows kernel namespaces
|
USING: editors.gvim.backend io.files io.windows kernel namespaces
|
||||||
sequences windows.shell32 ;
|
sequences windows.shell32 ;
|
||||||
IN: editors.gvim.windows
|
IN: editors.gvim.windows
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
USING: editors io.files io.launcher kernel math.parser
|
USING: editors io.files io.launcher kernel math.parser
|
||||||
namespaces windows.shell32 ;
|
namespaces sequences windows.shell32 ;
|
||||||
IN: editors.notepadpp
|
IN: editors.notepadpp
|
||||||
|
|
||||||
: notepadpp-path
|
: notepadpp-path
|
||||||
|
@ -11,6 +11,6 @@ IN: editors.notepadpp
|
||||||
[
|
[
|
||||||
notepadpp-path ,
|
notepadpp-path ,
|
||||||
"-n" swap number>string append , ,
|
"-n" swap number>string append , ,
|
||||||
] "" make run-detached drop ;
|
] { } make run-detached drop ;
|
||||||
|
|
||||||
[ notepadpp ] edit-hook set-global
|
[ notepadpp ] edit-hook set-global
|
||||||
|
|
|
@ -8,18 +8,19 @@
|
||||||
! variable to point to your executable,
|
! variable to point to your executable,
|
||||||
! if not on the path.
|
! if not on the path.
|
||||||
!
|
!
|
||||||
USING: io.launcher kernel namespaces math math.parser
|
USING: io.files io.launcher kernel namespaces math
|
||||||
editors ;
|
math.parser editors sequences windows.shell32 ;
|
||||||
IN: editors.scite
|
IN: editors.scite
|
||||||
|
|
||||||
SYMBOL: scite-path
|
: scite-path ( -- path )
|
||||||
|
\ scite-path get-global [
|
||||||
"scite" scite-path set-global
|
program-files "wscite\\SciTE.exe" path+
|
||||||
|
] unless* ;
|
||||||
|
|
||||||
: scite-command ( file line -- cmd )
|
: scite-command ( file line -- cmd )
|
||||||
swap
|
swap
|
||||||
[
|
[
|
||||||
scite-path get ,
|
scite-path ,
|
||||||
,
|
,
|
||||||
"-goto:" swap number>string append ,
|
"-goto:" swap number>string append ,
|
||||||
] { } make ;
|
] { } make ;
|
||||||
|
|
|
@ -10,7 +10,7 @@ IN: editors.ultraedit
|
||||||
|
|
||||||
: ultraedit ( file line -- )
|
: ultraedit ( file line -- )
|
||||||
[
|
[
|
||||||
ultraedit-path , [ % "/" % # "/1" % ] "" make ,
|
ultraedit-path , [ swap % "/" % # "/1" % ] "" make ,
|
||||||
] { } make run-detached drop ;
|
] { } make run-detached drop ;
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -11,4 +11,3 @@ HOOK: available-page-file os ( -- n )
|
||||||
HOOK: total-virtual-mem os ( -- n )
|
HOOK: total-virtual-mem os ( -- n )
|
||||||
HOOK: available-virtual-mem os ( -- n )
|
HOOK: available-virtual-mem os ( -- n )
|
||||||
HOOK: available-virtual-extended-mem os ( -- n )
|
HOOK: available-virtual-extended-mem os ( -- n )
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,6 @@
|
||||||
|
IN: hardware-info.windows.backend
|
||||||
|
|
||||||
|
TUPLE: wince ;
|
||||||
|
TUPLE: winnt ;
|
||||||
|
UNION: windows wince winnt ;
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
USING: alien.c-types hardware-info hardware-info.windows
|
USING: alien.c-types hardware-info kernel math namespaces
|
||||||
kernel math namespaces windows windows.kernel32
|
windows windows.kernel32 hardware-info.backend ;
|
||||||
hardware-info.backend ;
|
|
||||||
IN: hardware-info.windows.ce
|
IN: hardware-info.windows.ce
|
||||||
|
|
||||||
|
TUPLE: wince ;
|
||||||
T{ wince } os set-global
|
T{ wince } os set-global
|
||||||
|
|
||||||
: memory-status ( -- MEMORYSTATUS )
|
: memory-status ( -- MEMORYSTATUS )
|
||||||
|
@ -10,6 +10,8 @@ T{ wince } os set-global
|
||||||
"MEMORYSTATUS" heap-size over set-MEMORYSTATUS-dwLength
|
"MEMORYSTATUS" heap-size over set-MEMORYSTATUS-dwLength
|
||||||
[ GlobalMemoryStatus ] keep ;
|
[ GlobalMemoryStatus ] keep ;
|
||||||
|
|
||||||
|
M: wince cpus ( -- n ) 1 ;
|
||||||
|
|
||||||
M: wince memory-load ( -- n )
|
M: wince memory-load ( -- n )
|
||||||
memory-status MEMORYSTATUS-dwMemoryLoad ;
|
memory-status MEMORYSTATUS-dwMemoryLoad ;
|
||||||
|
|
||||||
|
|
|
@ -1,10 +1,18 @@
|
||||||
USING: alien alien.c-types hardware-info hardware-info.windows
|
USING: alien alien.c-types hardware-info.windows.backend
|
||||||
kernel libc math namespaces hardware-info.backend
|
kernel libc math namespaces hardware-info.backend
|
||||||
windows windows.advapi32 windows.kernel32 ;
|
windows windows.advapi32 windows.kernel32 ;
|
||||||
IN: hardware-info.windows.nt
|
IN: hardware-info.windows.nt
|
||||||
|
|
||||||
|
TUPLE: winnt ;
|
||||||
|
|
||||||
T{ winnt } os set-global
|
T{ winnt } os set-global
|
||||||
|
|
||||||
|
: system-info ( -- SYSTEM_INFO )
|
||||||
|
"SYSTEM_INFO" <c-object> [ GetSystemInfo ] keep ;
|
||||||
|
|
||||||
|
M: winnt cpus ( -- n )
|
||||||
|
system-info SYSTEM_INFO-dwNumberOfProcessors ;
|
||||||
|
|
||||||
: memory-status ( -- MEMORYSTATUSEX )
|
: memory-status ( -- MEMORYSTATUSEX )
|
||||||
"MEMORYSTATUSEX" <c-object>
|
"MEMORYSTATUSEX" <c-object>
|
||||||
"MEMORYSTATUSEX" heap-size over set-MEMORYSTATUSEX-dwLength
|
"MEMORYSTATUSEX" heap-size over set-MEMORYSTATUSEX-dwLength
|
||||||
|
|
|
@ -1,22 +1,15 @@
|
||||||
USING: alien alien.c-types kernel libc math namespaces
|
USING: alien alien.c-types kernel libc math namespaces
|
||||||
windows windows.kernel32 windows.advapi32
|
windows windows.kernel32 windows.advapi32
|
||||||
|
hardware-info.windows.backend
|
||||||
words combinators vocabs.loader hardware-info.backend ;
|
words combinators vocabs.loader hardware-info.backend ;
|
||||||
IN: hardware-info.windows
|
IN: hardware-info.windows
|
||||||
|
|
||||||
TUPLE: wince ;
|
|
||||||
TUPLE: winnt ;
|
|
||||||
UNION: windows wince winnt ;
|
|
||||||
USE: system
|
|
||||||
|
|
||||||
: system-info ( -- SYSTEM_INFO )
|
: system-info ( -- SYSTEM_INFO )
|
||||||
"SYSTEM_INFO" <c-object> [ GetSystemInfo ] keep ;
|
"SYSTEM_INFO" <c-object> [ GetSystemInfo ] keep ;
|
||||||
|
|
||||||
: page-size ( -- n )
|
: page-size ( -- n )
|
||||||
system-info SYSTEM_INFO-dwPageSize ;
|
system-info SYSTEM_INFO-dwPageSize ;
|
||||||
|
|
||||||
M: windows cpus ( -- n )
|
|
||||||
system-info SYSTEM_INFO-dwNumberOfProcessors ;
|
|
||||||
|
|
||||||
! 386, 486, 586, 2200 (IA64), 8664 (AMD_X8664)
|
! 386, 486, 586, 2200 (IA64), 8664 (AMD_X8664)
|
||||||
: processor-type ( -- n )
|
: processor-type ( -- n )
|
||||||
system-info SYSTEM_INFO-dwProcessorType ;
|
system-info SYSTEM_INFO-dwProcessorType ;
|
||||||
|
@ -70,8 +63,7 @@ M: windows cpus ( -- n )
|
||||||
: system-windows-directory ( -- str )
|
: system-windows-directory ( -- str )
|
||||||
\ GetSystemWindowsDirectory get-directory ;
|
\ GetSystemWindowsDirectory get-directory ;
|
||||||
|
|
||||||
<< {
|
{
|
||||||
{ [ wince? ] [ "hardware-info.windows.ce" ] }
|
{ [ wince? ] [ "hardware-info.windows.ce" ] }
|
||||||
{ [ winnt? ] [ "hardware-info.windows.nt" ] }
|
{ [ winnt? ] [ "hardware-info.windows.nt" ] }
|
||||||
{ [ t ] [ f ] }
|
} cond [ require ] when*
|
||||||
} cond [ require ] when* >>
|
|
||||||
|
|
|
@ -110,15 +110,21 @@ USE: io.buffers
|
||||||
ARTICLE: "collections" "Collections"
|
ARTICLE: "collections" "Collections"
|
||||||
{ $heading "Sequences" }
|
{ $heading "Sequences" }
|
||||||
{ $subsection "sequences" }
|
{ $subsection "sequences" }
|
||||||
"Sequence implementations:"
|
"Fixed-length sequences:"
|
||||||
{ $subsection "arrays" }
|
{ $subsection "arrays" }
|
||||||
{ $subsection "vectors" }
|
{ $subsection "quotations" }
|
||||||
|
"Fixed-length specialized sequences:"
|
||||||
|
{ $subsection "strings" }
|
||||||
{ $subsection "bit-arrays" }
|
{ $subsection "bit-arrays" }
|
||||||
{ $subsection "byte-arrays" }
|
{ $subsection "byte-arrays" }
|
||||||
{ $subsection "float-arrays" }
|
{ $subsection "float-arrays" }
|
||||||
{ $subsection "strings" }
|
"Resizable sequence:"
|
||||||
|
{ $subsection "vectors" }
|
||||||
|
"Resizable specialized sequences:"
|
||||||
{ $subsection "sbufs" }
|
{ $subsection "sbufs" }
|
||||||
{ $subsection "quotations" }
|
{ $subsection "bit-vectors" }
|
||||||
|
{ $subsection "byte-vectors" }
|
||||||
|
{ $subsection "float-vectors" }
|
||||||
{ $heading "Associative mappings" }
|
{ $heading "Associative mappings" }
|
||||||
{ $subsection "assocs" }
|
{ $subsection "assocs" }
|
||||||
{ $subsection "namespaces" }
|
{ $subsection "namespaces" }
|
||||||
|
@ -131,22 +137,25 @@ ARTICLE: "collections" "Collections"
|
||||||
{ $subsection "graphs" }
|
{ $subsection "graphs" }
|
||||||
{ $subsection "buffers" } ;
|
{ $subsection "buffers" } ;
|
||||||
|
|
||||||
USING: io.sockets io.launcher io.mmap ;
|
USING: io.sockets io.launcher io.mmap io.monitor ;
|
||||||
|
|
||||||
ARTICLE: "io" "Input and output"
|
ARTICLE: "io" "Input and output"
|
||||||
{ $subsection "streams" }
|
{ $subsection "streams" }
|
||||||
"Stream implementations:"
|
"External streams:"
|
||||||
{ $subsection "file-streams" }
|
{ $subsection "file-streams" }
|
||||||
|
{ $subsection "network-streams" }
|
||||||
|
"Wrapper streams:"
|
||||||
{ $subsection "io.streams.duplex" }
|
{ $subsection "io.streams.duplex" }
|
||||||
{ $subsection "io.streams.lines" }
|
{ $subsection "io.streams.lines" }
|
||||||
{ $subsection "io.streams.plain" }
|
{ $subsection "io.streams.plain" }
|
||||||
{ $subsection "io.streams.string" }
|
{ $subsection "io.streams.string" }
|
||||||
"Advanced features:"
|
"Stream utilities:"
|
||||||
{ $subsection "stream-binary" }
|
{ $subsection "stream-binary" }
|
||||||
{ $subsection "styles" }
|
{ $subsection "styles" }
|
||||||
{ $subsection "network-streams" }
|
"Advanced features:"
|
||||||
{ $subsection "io.launcher" }
|
{ $subsection "io.launcher" }
|
||||||
{ $subsection "io.mmap" } ;
|
{ $subsection "io.mmap" }
|
||||||
|
{ $subsection "io.monitor" } ;
|
||||||
|
|
||||||
ARTICLE: "tools" "Developer tools"
|
ARTICLE: "tools" "Developer tools"
|
||||||
{ $subsection "tools.annotations" }
|
{ $subsection "tools.annotations" }
|
||||||
|
|
|
@ -23,7 +23,7 @@ $nl
|
||||||
$nl
|
$nl
|
||||||
"Now, we tell Factor that all definitions in this source file should go into the " { $snippet "palindrome" } " vocabulary using the " { $link POSTPONE: IN: } " word:"
|
"Now, we tell Factor that all definitions in this source file should go into the " { $snippet "palindrome" } " vocabulary using the " { $link POSTPONE: IN: } " word:"
|
||||||
{ $code "IN: palindrome" }
|
{ $code "IN: palindrome" }
|
||||||
"You are now ready to go onto the nex section." ;
|
"You are now ready to go on to the next section: " { $link "first-program-logic" } "." ;
|
||||||
|
|
||||||
ARTICLE: "first-program-logic" "Writing some logic in your first program"
|
ARTICLE: "first-program-logic" "Writing some logic in your first program"
|
||||||
"Your " { $snippet "palindrome.factor" } " file should look like the following after the previous section:"
|
"Your " { $snippet "palindrome.factor" } " file should look like the following after the previous section:"
|
||||||
|
@ -56,7 +56,7 @@ $nl
|
||||||
{ $code "\\ = see" }
|
{ $code "\\ = see" }
|
||||||
"It's in the " { $vocab-link "kernel" } " vocabulary, which we've already added to the search path."
|
"It's in the " { $vocab-link "kernel" } " vocabulary, which we've already added to the search path."
|
||||||
|
|
||||||
"Now press " { $command workspace "workflow" refresh-all } " again, and the source file should reload without any errors." ;
|
"Now press " { $command workspace "workflow" refresh-all } " again, and the source file should reload without any errors. You can now go on and learn about " { $link "first-program-test" } "." ;
|
||||||
|
|
||||||
ARTICLE: "first-program-test" "Testing your first program"
|
ARTICLE: "first-program-test" "Testing your first program"
|
||||||
"Your " { $snippet "palindrome.factor" } " file should look like the following after the previous section:"
|
"Your " { $snippet "palindrome.factor" } " file should look like the following after the previous section:"
|
||||||
|
@ -92,7 +92,7 @@ $nl
|
||||||
}
|
}
|
||||||
"Now, you can run unit tests:"
|
"Now, you can run unit tests:"
|
||||||
{ $code "\"palindrome\" test" }
|
{ $code "\"palindrome\" test" }
|
||||||
"It should report that all tests have passed." ;
|
"It should report that all tests have passed. Now you can read about " { $link "first-program-extend" } "." ;
|
||||||
|
|
||||||
ARTICLE: "first-program-extend" "Extending your first program"
|
ARTICLE: "first-program-extend" "Extending your first program"
|
||||||
"Our palindrome program works well, however we'd like to extend it to ignore spaces and non-alphabetical characters in the input."
|
"Our palindrome program works well, however we'd like to extend it to ignore spaces and non-alphabetical characters in the input."
|
||||||
|
|
|
@ -105,7 +105,7 @@ TUPLE: html-sub-stream style stream ;
|
||||||
|
|
||||||
TUPLE: html-span-stream ;
|
TUPLE: html-span-stream ;
|
||||||
|
|
||||||
M: html-span-stream stream-close
|
M: html-span-stream dispose
|
||||||
end-sub-stream not-a-div format-html-span ;
|
end-sub-stream not-a-div format-html-span ;
|
||||||
|
|
||||||
: border-css, ( border -- )
|
: border-css, ( border -- )
|
||||||
|
@ -138,7 +138,7 @@ M: html-span-stream stream-close
|
||||||
|
|
||||||
TUPLE: html-block-stream ;
|
TUPLE: html-block-stream ;
|
||||||
|
|
||||||
M: html-block-stream stream-close ( quot style stream -- )
|
M: html-block-stream dispose ( quot style stream -- )
|
||||||
end-sub-stream a-div format-html-div ;
|
end-sub-stream a-div format-html-div ;
|
||||||
|
|
||||||
: border-spacing-css,
|
: border-spacing-css,
|
||||||
|
|
|
@ -7,3 +7,8 @@ USING: http.client tools.test ;
|
||||||
[ 404 ] [ "404 File not found" parse-response ] unit-test
|
[ 404 ] [ "404 File not found" parse-response ] unit-test
|
||||||
[ 200 ] [ "HTTP/1.0 200" parse-response ] unit-test
|
[ 200 ] [ "HTTP/1.0 200" parse-response ] unit-test
|
||||||
[ 200 ] [ "HTTP/1.0 200 Success" parse-response ] unit-test
|
[ 200 ] [ "HTTP/1.0 200 Success" parse-response ] unit-test
|
||||||
|
|
||||||
|
[ "foo.txt" ] [ "http://www.paulgraham.com/foo.txt" download-name ] unit-test
|
||||||
|
[ "foo.txt" ] [ "http://www.arcsucks.com/foo.txt?xxx" download-name ] unit-test
|
||||||
|
[ "foo.txt" ] [ "http://www.arcsucks.com/foo.txt/" download-name ] unit-test
|
||||||
|
[ "www.arcsucks.com" ] [ "http://www.arcsucks.com////" download-name ] unit-test
|
||||||
|
|
|
@ -44,14 +44,14 @@ DEFER: http-get-stream
|
||||||
#! Should this support Location: headers that are
|
#! Should this support Location: headers that are
|
||||||
#! relative URLs?
|
#! relative URLs?
|
||||||
pick 100 /i 3 = [
|
pick 100 /i 3 = [
|
||||||
stream-close "Location" swap at nip http-get-stream
|
dispose "Location" swap at nip http-get-stream
|
||||||
] when ;
|
] when ;
|
||||||
|
|
||||||
: http-get-stream ( url -- code headers stream )
|
: http-get-stream ( url -- code headers stream )
|
||||||
#! Opens a stream for reading from an HTTP URL.
|
#! Opens a stream for reading from an HTTP URL.
|
||||||
parse-url over parse-host <inet> <client> [
|
parse-url over parse-host <inet> <client> [
|
||||||
[ [ get-request read-response ] with-stream* ] keep
|
[ [ get-request read-response ] with-stream* ] keep
|
||||||
] [ >r stream-close r> rethrow ] recover do-redirect ;
|
] [ ] [ dispose ] cleanup do-redirect ;
|
||||||
|
|
||||||
: http-get ( url -- code headers string )
|
: http-get ( url -- code headers string )
|
||||||
#! Opens a stream for reading from an HTTP URL.
|
#! Opens a stream for reading from an HTTP URL.
|
||||||
|
@ -59,9 +59,23 @@ DEFER: http-get-stream
|
||||||
http-get-stream [ stdio get contents ] with-stream
|
http-get-stream [ stdio get contents ] with-stream
|
||||||
] with-scope ;
|
] with-scope ;
|
||||||
|
|
||||||
: download ( url file -- )
|
: download-name ( url -- name )
|
||||||
|
file-name "?" split1 drop "/" ?tail drop ;
|
||||||
|
|
||||||
|
: default-timeout 60 1000 * over set-timeout ;
|
||||||
|
|
||||||
|
: success? ( code -- ? ) 200 = ;
|
||||||
|
|
||||||
|
: download-to ( url file -- )
|
||||||
#! Downloads the contents of a URL to a file.
|
#! Downloads the contents of a URL to a file.
|
||||||
>r http-get 2nip r> <file-writer> [ write ] with-stream ;
|
>r http-get-stream nip default-timeout swap success? [
|
||||||
|
r> <file-writer> stream-copy
|
||||||
|
] [
|
||||||
|
r> drop dispose "HTTP download failed" throw
|
||||||
|
] if ;
|
||||||
|
|
||||||
|
: download ( url -- )
|
||||||
|
dup download-name download-to ;
|
||||||
|
|
||||||
: post-request ( content-type content host resource -- )
|
: post-request ( content-type content host resource -- )
|
||||||
#! Note: It is up to the caller to url encode the content if
|
#! Note: It is up to the caller to url encode the content if
|
||||||
|
|
|
@ -93,7 +93,7 @@ HELP: run-process*
|
||||||
{ $notes "User code should call " { $link run-process } " instead." } ;
|
{ $notes "User code should call " { $link run-process } " instead." } ;
|
||||||
|
|
||||||
HELP: >descriptor
|
HELP: >descriptor
|
||||||
{ $values { "obj" object } { "desc" "a launch descriptor" } }
|
{ $values { "desc" "a launch descriptor" } { "desc" "a launch descriptor" } }
|
||||||
{ $description "Creates a launch descriptor from an object, which must be one of the following:"
|
{ $description "Creates a launch descriptor from an object, which must be one of the following:"
|
||||||
{ $list
|
{ $list
|
||||||
{ "a string -- this is wrapped in a launch descriptor with a single " { $link +command+ } " key" }
|
{ "a string -- this is wrapped in a launch descriptor with a single " { $link +command+ } " key" }
|
||||||
|
@ -103,12 +103,12 @@ HELP: >descriptor
|
||||||
} ;
|
} ;
|
||||||
|
|
||||||
HELP: run-process
|
HELP: run-process
|
||||||
{ $values { "obj" object } { "process" process } }
|
{ $values { "desc" "a launch descriptor" } { "process" process } }
|
||||||
{ $description "Launches a process. The object can either be a string, a sequence of strings or a launch descriptor. See " { $link >descriptor } " for details." }
|
{ $description "Launches a process. The object can either be a string, a sequence of strings or a launch descriptor. See " { $link >descriptor } " for details." }
|
||||||
{ $notes "The output value can be passed to " { $link wait-for-process } " to get an exit code." } ;
|
{ $notes "The output value can be passed to " { $link wait-for-process } " to get an exit code." } ;
|
||||||
|
|
||||||
HELP: run-detached
|
HELP: run-detached
|
||||||
{ $values { "obj" object } { "process" process } }
|
{ $values { "desc" "a launch descriptor" } { "process" process } }
|
||||||
{ $contract "Launches a process without waiting for it to complete. The object can either be a string, a sequence of strings or a launch descriptor. See " { $link >descriptor } " for details." }
|
{ $contract "Launches a process without waiting for it to complete. The object can either be a string, a sequence of strings or a launch descriptor. See " { $link >descriptor } " for details." }
|
||||||
{ $notes
|
{ $notes
|
||||||
"This word is functionally identical to passing a launch descriptor to " { $link run-process } " having the " { $link +detached+ } " key set."
|
"This word is functionally identical to passing a launch descriptor to " { $link run-process } " having the " { $link +detached+ } " key set."
|
||||||
|
@ -127,12 +127,17 @@ HELP: process-stream
|
||||||
{ $class-description "A bidirectional stream for interacting with a running process. Instances are created by calling " { $link <process-stream> } ". The " { $link process-stream-process } " slot holds a " { $link process } " instance." } ;
|
{ $class-description "A bidirectional stream for interacting with a running process. Instances are created by calling " { $link <process-stream> } ". The " { $link process-stream-process } " slot holds a " { $link process } " instance." } ;
|
||||||
|
|
||||||
HELP: <process-stream>
|
HELP: <process-stream>
|
||||||
{ $values { "obj" object } { "stream" "a bidirectional stream" } }
|
{ $values
|
||||||
|
{ "desc" "a launch descriptor" }
|
||||||
|
{ "stream" "a bidirectional stream" } }
|
||||||
{ $description "Launches a process and redirects its input and output via a pair of pipes which may be read and written as a stream." }
|
{ $description "Launches a process and redirects its input and output via a pair of pipes which may be read and written as a stream." }
|
||||||
{ $notes "Closing the stream will block until the process exits." } ;
|
{ $notes "Closing the stream will block until the process exits." } ;
|
||||||
|
|
||||||
HELP: with-process-stream
|
HELP: with-process-stream
|
||||||
{ $values { "obj" object } { "quot" quotation } { "process" process } }
|
{ $values
|
||||||
|
{ "desc" "a launch descriptor" }
|
||||||
|
{ "quot" quotation }
|
||||||
|
{ "process" process } }
|
||||||
{ $description "Calls " { $snippet "quot" } " in a dynamic scope where " { $link stdio } " is rebound to a " { $link process-stream } ". When the quotation returns, the " { $link process } " instance is output." } ;
|
{ $description "Calls " { $snippet "quot" } " in a dynamic scope where " { $link stdio } " is rebound to a " { $link process-stream } ". When the quotation returns, the " { $link process } " instance is output." } ;
|
||||||
|
|
||||||
HELP: wait-for-process
|
HELP: wait-for-process
|
||||||
|
|
|
@ -63,7 +63,7 @@ SYMBOL: append-environment
|
||||||
{ replace-environment [ ] }
|
{ replace-environment [ ] }
|
||||||
} case ;
|
} case ;
|
||||||
|
|
||||||
GENERIC: >descriptor ( obj -- desc )
|
GENERIC: >descriptor ( desc -- desc )
|
||||||
|
|
||||||
M: string >descriptor +command+ associate ;
|
M: string >descriptor +command+ associate ;
|
||||||
M: sequence >descriptor +arguments+ associate ;
|
M: sequence >descriptor +arguments+ associate ;
|
||||||
|
@ -76,24 +76,24 @@ HOOK: run-process* io-backend ( desc -- handle )
|
||||||
dup [ processes get at push stop ] curry callcc0
|
dup [ processes get at push stop ] curry callcc0
|
||||||
] when process-status ;
|
] when process-status ;
|
||||||
|
|
||||||
: run-process ( obj -- process )
|
: run-process ( desc -- process )
|
||||||
>descriptor
|
>descriptor
|
||||||
dup run-process*
|
dup run-process*
|
||||||
+detached+ rot at [ dup wait-for-process drop ] unless ;
|
+detached+ rot at [ dup wait-for-process drop ] unless ;
|
||||||
|
|
||||||
: run-detached ( obj -- process )
|
: run-detached ( desc -- process )
|
||||||
>descriptor H{ { +detached+ t } } union run-process ;
|
>descriptor H{ { +detached+ t } } union run-process ;
|
||||||
|
|
||||||
HOOK: process-stream* io-backend ( desc -- stream process )
|
HOOK: process-stream* io-backend ( desc -- stream process )
|
||||||
|
|
||||||
TUPLE: process-stream process ;
|
TUPLE: process-stream process ;
|
||||||
|
|
||||||
: <process-stream> ( obj -- stream )
|
: <process-stream> ( desc -- stream )
|
||||||
>descriptor process-stream*
|
>descriptor process-stream*
|
||||||
{ set-delegate set-process-stream-process }
|
{ set-delegate set-process-stream-process }
|
||||||
process-stream construct ;
|
process-stream construct ;
|
||||||
|
|
||||||
: with-process-stream ( obj quot -- process )
|
: with-process-stream ( desc quot -- process )
|
||||||
swap <process-stream>
|
swap <process-stream>
|
||||||
[ swap with-stream ] keep
|
[ swap with-stream ] keep
|
||||||
process-stream-process ; inline
|
process-stream-process ; inline
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
USING: help.markup help.syntax alien math ;
|
USING: help.markup help.syntax alien math continuations ;
|
||||||
IN: io.mmap
|
IN: io.mmap
|
||||||
|
|
||||||
HELP: mapped-file
|
HELP: mapped-file
|
||||||
|
@ -15,21 +15,17 @@ HELP: <mapped-file>
|
||||||
{ $notes "You must call " { $link close-mapped-file } " when you are finished working with the returned object, to reclaim resources. The " { $link with-mapped-file } " provides an abstraction which can close the mapped file for you." }
|
{ $notes "You must call " { $link close-mapped-file } " when you are finished working with the returned object, to reclaim resources. The " { $link with-mapped-file } " provides an abstraction which can close the mapped file for you." }
|
||||||
{ $errors "Throws an error if a memory mapping could not be established." } ;
|
{ $errors "Throws an error if a memory mapping could not be established." } ;
|
||||||
|
|
||||||
HELP: (close-mapped-file)
|
|
||||||
{ $values { "mmap" mapped-file } }
|
|
||||||
{ $contract "Releases system resources associated with the mapped file. This word should not be called by user code; use " { $link close-mapped-file } " instead." }
|
|
||||||
{ $errors "Throws an error if a memory mapping could not be established." } ;
|
|
||||||
|
|
||||||
HELP: close-mapped-file
|
HELP: close-mapped-file
|
||||||
{ $values { "mmap" mapped-file } }
|
{ $values { "mmap" mapped-file } }
|
||||||
{ $description "Releases system resources associated with the mapped file." }
|
{ $contract "Releases system resources associated with the mapped file. This word should not be called by user code; use " { $link dispose } " instead." }
|
||||||
{ $errors "Throws an error if a memory mapping could not be established." } ;
|
{ $errors "Throws an error if a memory mapping could not be established." } ;
|
||||||
|
|
||||||
ARTICLE: "io.mmap" "Memory-mapped files"
|
ARTICLE: "io.mmap" "Memory-mapped files"
|
||||||
"The " { $vocab-link "io.mmap" } " vocabulary implements support for memory-mapped files."
|
"The " { $vocab-link "io.mmap" } " vocabulary implements support for memory-mapped files."
|
||||||
{ $subsection <mapped-file> }
|
{ $subsection <mapped-file> }
|
||||||
{ $subsection close-mapped-file }
|
"Memory-mapped files are disposable and can be closed with " { $link dispose } " or " { $link with-disposal } "."
|
||||||
"A combinator which wraps the above two words:"
|
$nl
|
||||||
|
"A utility combinator which wraps the above:"
|
||||||
{ $subsection with-mapped-file }
|
{ $subsection with-mapped-file }
|
||||||
"Memory mapped files implement the " { $link "sequence-protocol" } " and present themselves as a sequence of bytes. The underlying memory area can also be accessed directly:"
|
"Memory mapped files implement the " { $link "sequence-protocol" } " and present themselves as a sequence of bytes. The underlying memory area can also be accessed directly:"
|
||||||
{ $subsection mapped-file-address }
|
{ $subsection mapped-file-address }
|
||||||
|
|
|
@ -23,14 +23,12 @@ INSTANCE: mapped-file sequence
|
||||||
|
|
||||||
HOOK: <mapped-file> io-backend ( path length -- mmap )
|
HOOK: <mapped-file> io-backend ( path length -- mmap )
|
||||||
|
|
||||||
HOOK: (close-mapped-file) io-backend ( mmap -- )
|
HOOK: close-mapped-file io-backend ( mmap -- )
|
||||||
|
|
||||||
: close-mapped-file ( mmap -- )
|
M: mapped-file dispose ( mmap -- )
|
||||||
check-closed
|
check-closed
|
||||||
t over set-mapped-file-closed?
|
t over set-mapped-file-closed?
|
||||||
(close-mapped-file) ;
|
close-mapped-file ;
|
||||||
|
|
||||||
: with-mapped-file ( path length quot -- )
|
: with-mapped-file ( path length quot -- )
|
||||||
>r <mapped-file> r>
|
>r <mapped-file> r> with-disposal ; inline
|
||||||
[ keep ] curry
|
|
||||||
[ close-mapped-file ] [ ] cleanup ; inline
|
|
||||||
|
|
|
@ -0,0 +1,61 @@
|
||||||
|
IN: io.monitor
|
||||||
|
USING: help.markup help.syntax continuations ;
|
||||||
|
|
||||||
|
HELP: <monitor>
|
||||||
|
{ $values { "path" "a pathname string" } { "recursive?" "a boolean" } }
|
||||||
|
{ $description "Opens a file system change monitor which listens for changes on " { $snippet "path" } ". The boolean indicates whether changes in subdirectories should be reported."
|
||||||
|
$nl
|
||||||
|
"Not all operating systems support recursive monitors; if recursive monitoring is not available, an error is thrown and the caller must implement alternative logic for monitoring subdirectories." } ;
|
||||||
|
|
||||||
|
HELP: next-change
|
||||||
|
{ $values { "monitor" "a monitor" } { "path" "a pathname string" } { "changes" "a sequence of change descriptors" } }
|
||||||
|
{ $description "Waits for file system changes and outputs the pathname of the first changed file. The change descriptor is a sequence containing at least one change descriptor; see " { $link "io.monitor.descriptors" } "." } ;
|
||||||
|
|
||||||
|
HELP: with-monitor
|
||||||
|
{ $values { "path" "a pathname string" } { "recursive?" "a boolean" } { "quot" "a quotation with stack effect " { $snippet "( monitor -- )" } } }
|
||||||
|
{ $description "Opens a file system change monitor and passes it to the quotation. Closes the monitor after the quotation returns or throws an error." } ;
|
||||||
|
|
||||||
|
HELP: +change-file+
|
||||||
|
{ $description "Indicates that the contents of the file have changed." } ;
|
||||||
|
|
||||||
|
HELP: +change-name+
|
||||||
|
{ $description "Indicates that the file name has changed." } ;
|
||||||
|
|
||||||
|
HELP: +change-size+
|
||||||
|
{ $description "Indicates that the file size has changed." } ;
|
||||||
|
|
||||||
|
HELP: +change-attributes+
|
||||||
|
{ $description "Indicates that file attributes has changed. Attributes are operating system-specific but may include the creation time and permissions." } ;
|
||||||
|
|
||||||
|
HELP: +change-modified+
|
||||||
|
{ $description "Indicates that the last modification time of the file has changed." } ;
|
||||||
|
|
||||||
|
ARTICLE: "io.monitor.descriptors" "File system change descriptors"
|
||||||
|
"Change descriptors output by " { $link next-change } ":"
|
||||||
|
{ $subsection +change-file+ }
|
||||||
|
{ $subsection +change-name+ }
|
||||||
|
{ $subsection +change-size+ }
|
||||||
|
{ $subsection +change-attributes+ }
|
||||||
|
{ $subsection +change-modified+ } ;
|
||||||
|
|
||||||
|
ARTICLE: "io.monitor" "File system change monitors"
|
||||||
|
"File system change monitors listen for changes to file names, attributes and contents under a specified directory. They can optionally be recursive, in which case subdirectories are also monitored."
|
||||||
|
$nl
|
||||||
|
"Creating a file system change monitor and listening for changes:"
|
||||||
|
{ $subsection <monitor> }
|
||||||
|
{ $subsection next-change }
|
||||||
|
{ $subsection "io.monitor.descriptors" }
|
||||||
|
"Monitors are closed by calling " { $link dispose } " or " { $link with-disposal } "."
|
||||||
|
$nl
|
||||||
|
"A utility combinator which opens a monitor and cleans it up after:"
|
||||||
|
{ $subsection with-monitor }
|
||||||
|
"An example which watches the Factor directory for changes:"
|
||||||
|
{ $code
|
||||||
|
"USE: io.monitor"
|
||||||
|
": watch-loop ( monitor -- )"
|
||||||
|
" dup next-change . . nl nl flush watch-loop ;"
|
||||||
|
""
|
||||||
|
"\"\" resource-path f [ watch-loop ] with-monitor"
|
||||||
|
} ;
|
||||||
|
|
||||||
|
ABOUT: "io.monitor"
|
|
@ -5,8 +5,6 @@ IN: io.monitor
|
||||||
|
|
||||||
HOOK: <monitor> io-backend ( path recursive? -- monitor )
|
HOOK: <monitor> io-backend ( path recursive? -- monitor )
|
||||||
|
|
||||||
HOOK: close-monitor io-backend ( monitor -- )
|
|
||||||
|
|
||||||
HOOK: next-change io-backend ( monitor -- path changes )
|
HOOK: next-change io-backend ( monitor -- path changes )
|
||||||
|
|
||||||
SYMBOL: +change-file+
|
SYMBOL: +change-file+
|
||||||
|
@ -16,4 +14,4 @@ SYMBOL: +change-attributes+
|
||||||
SYMBOL: +change-modified+
|
SYMBOL: +change-modified+
|
||||||
|
|
||||||
: with-monitor ( path recursive? quot -- )
|
: with-monitor ( path recursive? quot -- )
|
||||||
>r <monitor> r> over [ close-monitor ] curry [ ] cleanup ;
|
>r <monitor> r> with-disposal ; inline
|
||||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue