Merge branch 'master' of git://factorcode.org/git/factor

db4
Slava Pestov 2009-10-15 22:12:00 -05:00
commit f212549a5f
19 changed files with 306 additions and 43 deletions

View File

@ -172,7 +172,7 @@ HELP: ndip
} ;
HELP: nkeep
{ $values { "quot" quotation } { "n" integer } }
{ $values { "n" integer } }
{ $description "A generalization of " { $link keep } " that can work "
"for any stack depth. The first " { $snippet "n" } " items after the quotation will be "
"saved, the quotation called, and the items restored."

View File

@ -30,7 +30,9 @@ IN: generalizations.tests
[ 1 5 4 3 2 ] [ 1 2 3 4 5 4 nspin ] unit-test
[ 1 2 3 4 5 [ drop drop drop drop drop 2 ] 5 nkeep ] must-infer
[ 1 2 3 4 5 2 '[ drop drop drop drop drop _ ] 5 nkeep ] must-infer
{ 2 1 2 3 4 5 } [ 1 2 3 4 5 [ drop drop drop drop drop 2 ] 5 nkeep ] unit-test
{ 2 1 2 3 4 5 } [ 1 2 3 4 5 2 '[ drop drop drop drop drop _ ] 5 nkeep ] unit-test
[ [ 1 2 3 + ] ] [ 1 2 3 [ + ] 3 ncurry ] unit-test
[ "HELLO" ] [ "hello" [ >upper ] 1 napply ] unit-test

View File

@ -77,8 +77,8 @@ MACRO: ntuck ( n -- )
MACRO: ndip ( n -- )
[ [ dip ] curry ] n*quot [ call ] compose ;
MACRO: nkeep ( quot n -- )
tuck '[ _ ndup _ _ ndip ] ;
MACRO: nkeep ( n -- )
dup '[ [ _ ndup ] dip _ ndip ] ;
MACRO: ncurry ( n -- )
[ curry ] n*quot ;

View File

@ -1,16 +1,16 @@
! Copyright (C) 2008 Doug Coleman.
! See http://factorcode.org/license.txt for BSD license.
USING: accessors arrays continuations deques dlists fry
io.directories io.files io.files.info io.pathnames kernel
sequences system vocabs.loader locals math namespaces
sorting assocs calendar threads io math.parser unicode.case ;
USING: accessors arrays assocs continuations deques dlists fry
io.backend io.directories io.files.info io.pathnames kernel
locals math sequences sorting system unicode.case vocabs.loader ;
IN: io.directories.search
: qualified-directory-entries ( path -- seq )
dup directory-entries
[ [ append-path ] change-name ] with map ;
(normalize-path)
dup directory-entries [ [ append-path ] change-name ] with map ;
: qualified-directory-files ( path -- seq )
(normalize-path)
dup directory-files [ append-path ] with map ;
: with-qualified-directory-files ( path quot -- )

View File

@ -54,6 +54,13 @@ HELP: with-unique-directory
}
{ $description "Creates a directory with " { $link unique-directory } " and calls the quotation with the pathname on the stack using the " { $link with-temporary-directory } " combinator. The quotation can access the " { $link current-temporary-directory } " symbol for the name of the temporary directory. Subsequent unique files will be created in this unique directory until the combinator returns." } ;
HELP: move-file-unique
{ $values
{ "path" "a pathname string" } { "directory" "a directory" }
{ "path'" "a pathname string" }
}
{ $description "Moves " { $snippet "path" } " to " { $snippet "directory" } " by creating a unique file in this directory. Returns the new path." } ;
HELP: current-temporary-directory
{ $values
{ "value" "a path" }
@ -90,6 +97,8 @@ ARTICLE: "io.files.unique" "Unique files"
cleanup-unique-directory
}
"Default temporary directory:"
{ $subsections default-temporary-directory } ;
{ $subsections default-temporary-directory }
"Moving files into a directory safely:"
{ $subsections move-file-unique } ;
ABOUT: "io.files.unique"

View File

@ -70,6 +70,11 @@ PRIVATE>
: unique-file ( prefix -- path )
"" make-unique-file ;
: move-file-unique ( path directory -- path' )
[
"" unique-file [ move-file ] keep
] with-temporary-directory ;
{
{ [ os unix? ] [ "io.files.unique.unix" ] }
{ [ os windows? ] [ "io.files.unique.windows" ] }

View File

@ -14,4 +14,5 @@ USING: alien sequences alien.libraries ;
{ "glu" "glu32.dll" "stdcall" }
{ "ole32" "ole32.dll" "stdcall" }
{ "usp10" "usp10.dll" "stdcall" }
{ "psapi" "psapi.dll" "stdcall" }
} [ first3 add-library ] each

View File

@ -0,0 +1 @@
Doug Coleman

View File

@ -0,0 +1,12 @@
! Copyright (C) 2009 Doug Coleman.
! See http://factorcode.org/license.txt for BSD license.
USING: alien.syntax windows.types ;
IN: windows.psapi
LIBRARY: psapi
FUNCTION: BOOL EnumDeviceDrivers ( LPVOID* lpImageBase, DWORD cb, LPDWORD lpcbNeeded ) ;
FUNCTION: DWORD GetDeviceDriverBaseNameW ( LPVOID ImageBase, LPTSTR lpBaseName, DWORD nSize ) ;
ALIAS: GetDeviceDriverBaseName GetDeviceDriverBaseNameW

View File

@ -1,6 +1,6 @@
! (c)Joe Groff bsd license
USING: alien.data.map generalizations kernel math.vectors
math.vectors.conversion math.vectors.simd
USING: alien.data.map fry generalizations kernel locals math.vectors
math.vectors.conversion math math.vectors.simd
specialized-arrays tools.test ;
FROM: alien.c-types => uchar short int float ;
SIMDS: float int short uchar ;
@ -19,6 +19,23 @@ IN: alien.data.map.tests
[ dup ] data-map!( int -- float[2] )
] unit-test
:: float-pixels>byte-pixels-locals ( floats scale bias -- bytes )
floats [
[ scale 255.0 * v*n bias 255.0 * v+n float-4 int-4 vconvert ] 4 napply
[ int-4 short-8 vconvert ] 2bi@
short-8 uchar-16 vconvert
] data-map( float-4[4] -- uchar-16 ) ; inline
: float-pixels>byte-pixels* ( floats scale bias -- bytes )
'[
[ _ 255.0 * v*n _ 255.0 * v+n float-4 int-4 vconvert ] 4 napply
[ int-4 short-8 vconvert ] 2bi@
short-8 uchar-16 vconvert
] data-map( float-4[4] -- uchar-16 ) ; inline
: float-pixels>byte-pixels ( floats -- bytes )
1.0 0.0 float-pixels>byte-pixels* ;
[
B{
127 191 255 63
@ -32,11 +49,23 @@ IN: alien.data.map.tests
1.0 0.1 0.2 0.3
0.3 0.2 0.9 0.5
0.1 1.0 1.5 2.0
} [
[ 255.0 v*n float-4 int-4 vconvert ] 4 napply
[ int-4 short-8 vconvert ] 2bi@
short-8 uchar-16 vconvert
] data-map( float-4[4] -- uchar-16 )
} 1.0 0.0 float-pixels>byte-pixels-locals
] unit-test
[
B{
127 191 255 63
255 25 51 76
76 51 229 127
25 255 255 255
}
] [
float-array{
0.5 0.75 1.0 0.25
1.0 0.1 0.2 0.3
0.3 0.2 0.9 0.5
0.1 1.0 1.5 2.0
} float-pixels>byte-pixels
] unit-test
[
@ -63,6 +92,10 @@ IN: alien.data.map.tests
: vmerge-transpose ( a b c d -- ac bd ac bd )
[ (vmerge) ] bi-curry@ bi* ; inline
: fold-rgba-planes ( r g b a -- rgba )
[ vmerge-transpose vmerge-transpose ]
data-map( uchar-16 uchar-16 uchar-16 uchar-16 -- uchar-16[4] ) ;
[
B{
1 10 11 15
@ -87,6 +120,5 @@ IN: alien.data.map.tests
B{ 10 20 30 40 50 60 70 80 90 100 110 120 130 140 150 160 }
B{ 11 22 33 44 55 66 77 88 99 110 121 132 143 154 165 176 }
B{ 15 25 35 45 55 65 75 85 95 105 115 125 135 145 155 165 }
[ vmerge-transpose vmerge-transpose ]
data-map( uchar-16 uchar-16 uchar-16 uchar-16 -- uchar-16[4] )
fold-rgba-planes
] unit-test

View File

@ -1,7 +1,7 @@
! (c)Joe Groff bsd license
USING: accessors alien alien.c-types alien.data alien.parser arrays
byte-arrays combinators effects.parser fry generalizations kernel
lexer locals macros math math.ranges parser sequences sequences.private ;
lexer locals macros make math math.ranges parser sequences sequences.private ;
IN: alien.data.map
ERROR: bad-data-map-input-length byte-length iter-size remainder ;
@ -39,27 +39,23 @@ INSTANCE: data-map-param immutable-sequence
dup array? [ unclip swap product >fixnum ] [ 1 ] if
2dup swap heap-size * >fixnum ; inline
MACRO:: >param ( in -- quot: ( array -- param ) )
in c-type-count :> iter-length :> count :> c-type
[
[ c-type count ] dip
MACRO: >param ( in -- quot: ( array -- param ) )
c-type-count '[
[ _ _ ] dip
[ ]
[ >c-ptr ]
[ byte-length ] tri
iter-length
_
2dup /i
data-map-param boa
] ;
MACRO:: alloc-param ( out -- quot: ( len -- param ) )
out c-type-count :> iter-length :> count :> c-type
[
[ c-type count ] dip
MACRO: alloc-param ( out -- quot: ( len -- param ) )
c-type-count dup '[
[ _ _ ] dip
[
iter-length * >fixnum [ (byte-array) dup ] keep
iter-length
_ * >fixnum [ (byte-array) dup ] keep
_
] keep
data-map-param boa
] ;
@ -76,14 +72,17 @@ MACRO: pack-params ( outs -- )
outs length :> #outs
#ins #outs + :> #params
[| quot |
param-quot call
[
param-quot %
[
[ [ ins unpack-params quot call ] #outs ndip outs pack-params ]
#params neach
] #outs nkeep
[ orig>> ] #outs napply
] ;
[
[ ins , \ unpack-params , \ @ , ] [ ] make ,
#outs , \ ndip , outs , \ pack-params ,
] [ ] make ,
#params , \ neach ,
] [ ] make , #outs , \ nkeep ,
[ orig>> ] , #outs , \ napply ,
] [ ] make fry \ call suffix ;
MACRO: data-map ( ins outs -- )
2dup

View File

@ -0,0 +1 @@
Joe Groff

View File

@ -0,0 +1 @@
Derive a tuple of specialized arrays from a struct class

View File

@ -0,0 +1,73 @@
! (c)2009 Joe Groff bsd license
USING: accessors alien.c-types classes.struct classes.struct.vectored
kernel sequences specialized-arrays tools.test ;
SPECIALIZED-ARRAYS: int ushort float ;
IN: classes.struct.vectored.tests
STRUCT: foo
{ x int }
{ y float }
{ z ushort }
{ w ushort } ;
SPECIALIZED-ARRAY: foo
VECTORED-STRUCT: foo
[
T{ vectored-foo
{ x int-array{ 0 1 0 0 } }
{ y float-array{ 0.0 2.0 0.0 0.0 } }
{ z ushort-array{ 0 3 0 0 } }
{ w ushort-array{ 0 4 0 0 } }
}
] [ S{ foo f 1 2.0 3 4 } 4 <vectored-foo> [ set-second ] keep ] unit-test
[
T{ vectored-foo
{ x int-array{ 0 1 2 3 } }
{ y float-array{ 0.0 0.5 1.0 1.5 } }
{ z ushort-array{ 10 20 30 40 } }
{ w ushort-array{ 15 25 35 45 } }
}
] [
foo-array{
S{ foo { x 0 } { y 0.0 } { z 10 } { w 15 } }
S{ foo { x 1 } { y 0.5 } { z 20 } { w 25 } }
S{ foo { x 2 } { y 1.0 } { z 30 } { w 35 } }
S{ foo { x 3 } { y 1.5 } { z 40 } { w 45 } }
} struct-transpose
] unit-test
[
foo-array{
S{ foo { x 0 } { y 0.0 } { z 10 } { w 15 } }
S{ foo { x 1 } { y 0.5 } { z 20 } { w 25 } }
S{ foo { x 2 } { y 1.0 } { z 30 } { w 35 } }
S{ foo { x 3 } { y 1.5 } { z 40 } { w 45 } }
}
] [
T{ vectored-foo
{ x int-array{ 0 1 2 3 } }
{ y float-array{ 0.0 0.5 1.0 1.5 } }
{ z ushort-array{ 10 20 30 40 } }
{ w ushort-array{ 15 25 35 45 } }
} struct-transpose
] unit-test
[ 30 ] [
T{ vectored-foo
{ x int-array{ 0 1 2 3 } }
{ y float-array{ 0.0 0.5 1.0 1.5 } }
{ z ushort-array{ 10 20 30 40 } }
{ w ushort-array{ 15 25 35 45 } }
} third z>>
] unit-test
[ S{ foo { x 2 } { y 1.0 } { z 30 } { w 35 } } ] [
T{ vectored-foo
{ x int-array{ 0 1 2 3 } }
{ y float-array{ 0.0 0.5 1.0 1.5 } }
{ z ushort-array{ 10 20 30 40 } }
{ w ushort-array{ 15 25 35 45 } }
} third vectored-element>
] unit-test

View File

@ -0,0 +1,117 @@
! (c)2009 Joe Groff bsd license
USING: accessors classes.struct classes.tuple combinators fry
functors kernel locals macros math parser quotations sequences
sequences.private slots specialized-arrays words ;
IN: classes.struct.vectored
<PRIVATE
: array-class-of ( type -- array-type )
[ define-array-vocab ] [ name>> "-array" append swap lookup ] bi ;
: <array-class>-of ( type -- array-type )
[ define-array-vocab ] [ name>> "<" "-array>" surround swap lookup ] bi ;
: (array-class)-of ( type -- array-type )
[ define-array-vocab ] [ name>> "(" "-array)" surround swap lookup ] bi ;
: >vectored-slot ( struct-slot offset -- tuple-slot )
{
[ drop name>> ]
[ nip ]
[ drop type>> array-class-of dup initial-value ]
[ 2drop t ]
} 2cleave slot-spec boa ;
MACRO: first-slot ( struct-class -- quot: ( struct -- value ) )
struct-slots first name>> reader-word 1quotation ;
MACRO: set-vectored-nth ( struct-class -- quot: ( value i vector -- ) )
struct-slots [
name>> reader-word 1quotation dup
'[ _ [ ] _ tri* set-nth-unsafe ]
] map '[ _ 3cleave ] ;
MACRO: <vectored-slots> ( struct-class -- quot: ( n -- slots... ) )
struct-slots [ type>> <array-class>-of 1quotation ] map
'[ _ cleave ] ;
MACRO: (vectored-slots) ( struct-class -- quot: ( n -- slots... ) )
struct-slots [ type>> (array-class)-of 1quotation ] map
'[ _ cleave ] ;
MACRO: (vectored-element>) ( struct-class -- quot: ( elt -- struct ) )
[ struct-slots [ name>> reader-word 1quotation ] map ] keep
'[ _ cleave _ <struct-boa> ] ;
SLOT: (n)
SLOT: (vectored)
FUNCTOR: define-vectored-accessors ( S>> (>>S) T -- )
WHERE
M: T S>>
[ (n)>> ] [ (vectored)>> S>> ] bi nth-unsafe ; inline
M: T (>>S)
[ (n)>> ] [ (vectored)>> S>> ] bi set-nth-unsafe ; inline
;FUNCTOR
PRIVATE>
GENERIC: struct-transpose ( structstruct -- ssttrruucctt )
GENERIC: vectored-element> ( elt -- struct )
FUNCTOR: define-vectored-struct ( T -- )
T-array [ T array-class-of ]
vectored-T DEFINES-CLASS vectored-${T}
vectored-T-element DEFINES-CLASS vectored-${T}-element
<vectored-T> DEFINES <vectored-${T}>
(vectored-T) DEFINES (vectored-${T})
WHERE
vectored-T tuple T struct-slots [ >vectored-slot ] map-index define-tuple-class
TUPLE: vectored-T-element
{ (n) fixnum read-only }
{ (vectored) vectored-T read-only } ;
T struct-slots [
name>> [ reader-word ] [ writer-word ] bi
vectored-T-element define-vectored-accessors
] each
M: vectored-T-element vectored-element>
T (vectored-element>) ; inline
M: vectored-T nth-unsafe
vectored-T-element boa ; inline
M: vectored-T length
T first-slot length ; inline
M: vectored-T set-nth-unsafe
T set-vectored-nth ; inline
INSTANCE: vectored-T sequence
: <vectored-T> ( n -- vectored-T )
T <vectored-slots> vectored-T boa ; inline
: (vectored-T) ( n -- vectored-T )
T (vectored-slots) vectored-T boa ; inline
M: vectored-T struct-transpose
[ vectored-element> ] T-array new map-as ; inline
M: T-array struct-transpose
dup length [ nip iota ] [ drop ] [ nip (vectored-T) ] 2tri
[ [ [ nth ] [ set-nth ] bi-curry* bi ] 2curry each ] keep ; inline
;FUNCTOR
SYNTAX: VECTORED-STRUCT:
scan-word define-vectored-struct ;

View File

@ -229,3 +229,13 @@ IN: math.matrices.simd.tests
float-4{ 2.0 2.0 0.0 0.0 } 1.0 5.0
frustum-matrix4
] unit-test
[ float-4{ 3.0 4.0 5.0 1.0 } ]
[ float-4{ 1.0 1.0 1.0 1.0 } translation-matrix4 float-4{ 2.0 3.0 4.0 1.0 } m4.v ] unit-test
[ float-4{ 2.0 2.5 3.0 1.0 } ]
[
float-4{ 1.0 1.0 1.0 1.0 } translation-matrix4
float-4{ 0.5 0.5 0.5 1.0 } scale-matrix4 m4.
float-4{ 2.0 3.0 4.0 1.0 } m4.v
] unit-test

View File

@ -211,7 +211,7 @@ void factor_vm::dump_memory(cell from, cell to)
dump_cell(from);
}
void factor_vm::dump_zone(char *name, zone *z)
void factor_vm::dump_zone(const char *name, zone *z)
{
print_string(name); print_string(": ");
print_string("Start="); print_cell(z->start);

View File

@ -68,7 +68,7 @@ cell old_space::next_object_after(factor_vm *myvm, cell scan)
if(scan + size < here)
return scan + size;
else
return NULL;
return 0;
}
}

View File

@ -301,7 +301,7 @@ struct factor_vm
void print_callstack();
void dump_cell(cell x);
void dump_memory(cell from, cell to);
void dump_zone(char *name, zone *z);
void dump_zone(const char *name, zone *z);
void dump_generations();
void dump_objects(cell type);
void find_data_references_step(cell *scan);