Merge branch 'master' of git://factorcode.org/git/factor
commit
1d320f4270
|
@ -56,7 +56,6 @@ $nl
|
||||||
{ $subsections
|
{ $subsections
|
||||||
malloc-object
|
malloc-object
|
||||||
malloc-byte-array
|
malloc-byte-array
|
||||||
malloc-file-contents
|
|
||||||
}
|
}
|
||||||
"The " { $vocab-link "libc" } " vocabulary defines several words which directly call C standard library memory management functions:"
|
"The " { $vocab-link "libc" } " vocabulary defines several words which directly call C standard library memory management functions:"
|
||||||
{ $subsections
|
{ $subsections
|
||||||
|
|
|
@ -56,9 +56,6 @@ M: word <c-direct-array>
|
||||||
: malloc-string ( string encoding -- alien )
|
: malloc-string ( string encoding -- alien )
|
||||||
string>alien malloc-byte-array ;
|
string>alien malloc-byte-array ;
|
||||||
|
|
||||||
: malloc-file-contents ( path -- alien len )
|
|
||||||
binary file-contents [ malloc-byte-array ] [ length ] bi ;
|
|
||||||
|
|
||||||
M: memory-stream stream-read
|
M: memory-stream stream-read
|
||||||
[
|
[
|
||||||
[ index>> ] [ alien>> ] bi <displaced-alien>
|
[ index>> ] [ alien>> ] bi <displaced-alien>
|
||||||
|
@ -81,3 +78,4 @@ M: value-type c-type-setter ( type -- quot )
|
||||||
[ c-type-getter ] [ c-type-unboxer-quot ] [ heap-size ] tri
|
[ c-type-getter ] [ c-type-unboxer-quot ] [ heap-size ] tri
|
||||||
'[ @ swap @ _ memcpy ] ;
|
'[ @ swap @ _ memcpy ] ;
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -303,6 +303,12 @@ HELP: ntuck
|
||||||
}
|
}
|
||||||
{ $description "A generalization of " { $link tuck } " that can work for any stack depth. The top item will be copied and placed " { $snippet "n" } " items down on the stack." } ;
|
{ $description "A generalization of " { $link tuck } " that can work for any stack depth. The top item will be copied and placed " { $snippet "n" } " items down on the stack." } ;
|
||||||
|
|
||||||
|
HELP: nspin
|
||||||
|
{ $values
|
||||||
|
{ "n" integer }
|
||||||
|
}
|
||||||
|
{ $description "A generalization of " { $link spin } " that can work for any stack depth. The top " { $snippet "n" } " items will be reversed in order." } ;
|
||||||
|
|
||||||
ARTICLE: "sequence-generalizations" "Generalized sequence operations"
|
ARTICLE: "sequence-generalizations" "Generalized sequence operations"
|
||||||
{ $subsections
|
{ $subsections
|
||||||
narray
|
narray
|
||||||
|
@ -321,6 +327,7 @@ ARTICLE: "shuffle-generalizations" "Generalized shuffle words"
|
||||||
nnip
|
nnip
|
||||||
ndrop
|
ndrop
|
||||||
ntuck
|
ntuck
|
||||||
|
nspin
|
||||||
mnswap
|
mnswap
|
||||||
nweave
|
nweave
|
||||||
} ;
|
} ;
|
||||||
|
|
|
@ -26,6 +26,8 @@ IN: generalizations.tests
|
||||||
{ 0 } [ 0 1 2 3 4 4 ndrop ] unit-test
|
{ 0 } [ 0 1 2 3 4 4 ndrop ] unit-test
|
||||||
[ [ 1 ] 5 ndip ] must-infer
|
[ [ 1 ] 5 ndip ] must-infer
|
||||||
[ 1 2 3 4 ] [ 2 3 4 [ 1 ] 3 ndip ] unit-test
|
[ 1 2 3 4 ] [ 2 3 4 [ 1 ] 3 ndip ] unit-test
|
||||||
|
[ 5 nspin ] must-infer
|
||||||
|
[ 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 [ drop drop drop drop drop 2 ] 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 [ drop drop drop drop drop 2 ] 5 nkeep ] unit-test
|
||||||
|
|
|
@ -104,3 +104,6 @@ MACRO: nbi-curry ( n -- )
|
||||||
[ narray concat ] dip like ; inline
|
[ narray concat ] dip like ; inline
|
||||||
|
|
||||||
: nappend ( n -- seq ) narray concat ; inline
|
: nappend ( n -- seq ) narray concat ; inline
|
||||||
|
|
||||||
|
MACRO: nspin ( n -- )
|
||||||
|
[ [ ] ] swap [ swap [ ] curry compose ] n*quot [ call ] 3append ;
|
||||||
|
|
|
@ -39,32 +39,45 @@ ERROR: bad-vconvert-input value expected-type ;
|
||||||
} cond
|
} cond
|
||||||
[ from-type check-vconvert-type ] prepose ;
|
[ from-type check-vconvert-type ] prepose ;
|
||||||
|
|
||||||
:: [vpack] ( from-element to-element from-size to-size from-type to-type -- quot )
|
:: check-vpack ( from-element to-element from-type to-type steps -- )
|
||||||
from-size to-size /i log2 :> steps
|
|
||||||
|
|
||||||
{
|
{
|
||||||
[ steps 1 = not ]
|
[ steps 1 = not ]
|
||||||
[ from-element to-element [ float-type? ] bi@ xor ]
|
[ from-element to-element [ float-type? ] bi@ xor ]
|
||||||
[ from-element unsigned-type? to-element unsigned-type? not and ]
|
[ from-element unsigned-type? to-element unsigned-type? not and ]
|
||||||
} 0|| [ from-type to-type bad-vconvert ] when
|
} 0|| [ from-type to-type bad-vconvert ] when ;
|
||||||
|
|
||||||
to-element unsigned-type? [ to-type (vpack-unsigned) ] [ to-type (vpack-signed) ] ?
|
:: [[vpack-unsigned]] ( from-type to-type -- quot )
|
||||||
[ [ from-type check-vconvert-type ] bi@ ] prepose ;
|
[ [ from-type check-vconvert-type ] bi@ to-type (vpack-unsigned) ] ;
|
||||||
|
|
||||||
:: [vunpack] ( from-element to-element from-size to-size from-type to-type -- quot )
|
:: [[vpack-signed]] ( from-type to-type -- quot )
|
||||||
to-size from-size /i log2 :> steps
|
[ [ from-type check-vconvert-type ] bi@ to-type (vpack-signed) ] ;
|
||||||
|
|
||||||
|
:: [vpack] ( from-element to-element from-size to-size from-type to-type -- quot )
|
||||||
|
from-size to-size /i log2 :> steps
|
||||||
|
|
||||||
|
from-element to-element from-type to-type steps check-vpack
|
||||||
|
|
||||||
|
from-type to-type to-element unsigned-type?
|
||||||
|
[ [[vpack-unsigned]] ] [ [[vpack-signed]] ] if ;
|
||||||
|
|
||||||
|
:: check-vunpack ( from-element to-element from-type to-type steps -- )
|
||||||
{
|
{
|
||||||
[ steps 1 = not ]
|
[ steps 1 = not ]
|
||||||
[ from-element to-element [ float-type? ] bi@ xor ]
|
[ from-element to-element [ float-type? ] bi@ xor ]
|
||||||
[ from-element unsigned-type? not to-element unsigned-type? and ]
|
[ from-element unsigned-type? not to-element unsigned-type? and ]
|
||||||
} 0|| [ from-type to-type bad-vconvert ] when
|
} 0|| [ from-type to-type bad-vconvert ] when ;
|
||||||
|
|
||||||
|
:: [[vunpack]] ( from-type to-type -- quot )
|
||||||
[
|
[
|
||||||
from-type check-vconvert-type
|
from-type check-vconvert-type
|
||||||
[ to-type (vunpack-head) ] [ to-type (vunpack-tail) ] bi
|
[ to-type (vunpack-head) ] [ to-type (vunpack-tail) ] bi
|
||||||
] ;
|
] ;
|
||||||
|
|
||||||
|
:: [vunpack] ( from-element to-element from-size to-size from-type to-type -- quot )
|
||||||
|
to-size from-size /i log2 :> steps
|
||||||
|
from-element to-element from-type to-type steps check-vunpack
|
||||||
|
from-type to-type [[vunpack]] ;
|
||||||
|
|
||||||
PRIVATE>
|
PRIVATE>
|
||||||
|
|
||||||
MACRO:: vconvert ( from-type to-type -- )
|
MACRO:: vconvert ( from-type to-type -- )
|
||||||
|
|
Loading…
Reference in New Issue