Compare commits
510 Commits
master
...
modern-har
Author | SHA1 | Date |
---|---|---|
|
ee67a4d8d2 | |
|
3a430c4dae | |
|
b644ec6818 | |
|
2321fe8c9a | |
|
94a1a8a2af | |
|
c14ffd4d0f | |
|
dfb3ebf509 | |
|
516a5d9004 | |
|
7838405c1b | |
|
9c7c8cd9dd | |
|
f5c75922ec | |
|
05b48364c6 | |
|
d3d9c1ffcf | |
|
b6e518e4bb | |
|
e2baa121f4 | |
|
1268a9e1c6 | |
|
a076fe99cf | |
|
f23fda04c0 | |
|
00c85b6cdc | |
|
82f9cea1c1 | |
|
cf689792d6 | |
|
c3dbfbbd69 | |
|
b5c8155383 | |
|
e1b83e4a21 | |
|
7d9bda3c26 | |
|
aaee11ad9e | |
|
ed43639994 | |
|
ae15ed674e | |
|
94dbc90f0f | |
|
3149deefb8 | |
|
de57b00d2f | |
|
c3c61e74d7 | |
|
0b6c3f6f8e | |
|
d934114fb7 | |
|
360b769ccf | |
|
a4208887b1 | |
|
a4a9500be1 | |
|
3f9448bc18 | |
|
67fc3e1171 | |
|
104ac614d0 | |
|
a85163aef0 | |
|
64ffbc149a | |
|
64f1cfa0fb | |
|
7528812d38 | |
|
8dd5fdda0f | |
|
cb8499373d | |
|
9e4a999f7b | |
|
5a9f0752c8 | |
|
355c52390d | |
|
bea7852d60 | |
|
73f2838c87 | |
|
618d41251e | |
|
319a8a4941 | |
|
b552ab5f28 | |
|
1cf3e1161d | |
|
c9684dbd14 | |
|
e00f639cf6 | |
|
39796039b0 | |
|
f67acc5b6a | |
|
9139752b49 | |
|
317cec5dce | |
|
6a4a7cc9d1 | |
|
8b7ab6c140 | |
|
3f79f14af2 | |
|
2b8204aabc | |
|
2be635823e | |
|
0ad47550e0 | |
|
107f435779 | |
|
e83100b759 | |
|
721ce58b4c | |
|
321ec1ee06 | |
|
3a164fb648 | |
|
c279cf6a70 | |
|
b049b0919c | |
|
c3bd9c3b4e | |
|
a4623177b6 | |
|
e4229ef5f9 | |
|
422078e01e | |
|
a654c7b879 | |
|
05686c44a3 | |
|
dc85cb9dcc | |
|
1eee4d0f34 | |
|
46b0e8d44f | |
|
dc1cb5b7d1 | |
|
6e1c2ecc6c | |
|
5618440e2b | |
|
ce06202d1a | |
|
6c5e1e3910 | |
|
9415b3399e | |
|
14ac7742ff | |
|
68ae992f40 | |
|
7cd98c796f | |
|
bf79c1abd1 | |
|
6956a90dba | |
|
be6bc61830 | |
|
a8df2132f6 | |
|
11b0bfc038 | |
|
ff594f4313 | |
|
25a8cedcb8 | |
|
8a46a16530 | |
|
953e6511ee | |
|
aa47ba1df7 | |
|
c4cd8991be | |
|
980840d360 | |
|
d2621d0da6 | |
|
5def4de6f3 | |
|
4ef0a41d05 | |
|
2c6d958030 | |
|
155171b828 | |
|
721d0c3ea9 | |
|
680cac56c1 | |
|
1c4bdd74a6 | |
|
1e4723ad2d | |
|
013ed4f2ab | |
|
d1466f2aea | |
|
58aacc34bf | |
|
810ba323c9 | |
|
1724ae15a9 | |
|
8033cb02f3 | |
|
ea8f29706a | |
|
4a86d45c17 | |
|
8d3dec2034 | |
|
8b4998aa4d | |
|
511ecb4e84 | |
|
7e46618316 | |
|
e973293309 | |
|
d635604026 | |
|
fbf7c73e99 | |
|
d5d552eb40 | |
|
5963f3a520 | |
|
1ce3b72760 | |
|
fdf13141bc | |
|
3eda5056c7 | |
|
e7c10e22b7 | |
|
502f4e7fd8 | |
|
add6234fd1 | |
|
24704095b7 | |
|
87b8641eab | |
|
9e48ebefaa | |
|
ce397fb345 | |
|
08a09f70ff | |
|
118dcd5870 | |
|
83401103a7 | |
|
b612b5be8c | |
|
bcb0bf8a53 | |
|
d222f6681c | |
|
9cff14ca01 | |
|
bedbfe512a | |
|
6507b01190 | |
|
841b0528fd | |
|
d69f75f373 | |
|
7ffb86eb67 | |
|
bd0e67beee | |
|
81d7e86494 | |
|
e1d48ba12f | |
|
56b8e74789 | |
|
438e69b233 | |
|
d5b153596d | |
|
3ac71a1317 | |
|
434879a802 | |
|
da56804031 | |
|
ee2f198fe8 | |
|
033e136590 | |
|
65fcf8208e | |
|
29b549563b | |
|
d21af6e975 | |
|
47b38345d0 | |
|
4b10899bc8 | |
|
d37ca71375 | |
|
fdb5383f19 | |
|
de903b4ee2 | |
|
b98ace932b | |
|
a526fd0011 | |
|
518e936813 | |
|
cbfdf2cfa8 | |
|
4bcae2590c | |
|
24d266c1f1 | |
|
9c7fdc3a34 | |
|
9df90f9c87 | |
|
3f0f387cbe | |
|
8c3df2ede4 | |
|
f05c7e8cd8 | |
|
e06eb4ad3e | |
|
bd329c7497 | |
|
59f406b64e | |
|
7b48017cd1 | |
|
1355c94f33 | |
|
f09eade430 | |
|
8eea6188bd | |
|
f52694159f | |
|
c00487b3ee | |
|
6b1318885d | |
|
1b8b366444 | |
|
c3f12c945d | |
|
00fb574a8d | |
|
8bb69eadf9 | |
|
227e9d6672 | |
|
8ff702c069 | |
|
66889b9552 | |
|
d40d360616 | |
|
e6715f41a5 | |
|
24929aadf1 | |
|
0ae3ac3e8a | |
|
3944515af3 | |
|
1f2d755c0f | |
|
73644eda85 | |
|
60f66bfb42 | |
|
947793673a | |
|
46e930874a | |
|
0a77f6c679 | |
|
343674189c | |
|
c715b0d505 | |
|
1a57f8180a | |
|
acc5dc6add | |
|
924b434336 | |
|
ac58033aff | |
|
a1ad3385b9 | |
|
7730fc5c64 | |
|
69c000088d | |
|
53b1a81049 | |
|
ca5e76ef1e | |
|
62ff48da56 | |
|
cbf77f34cc | |
|
2c7a579ecd | |
|
25bf216bf4 | |
|
4c164b1ae6 | |
|
6bed1364f2 | |
|
da19b780b1 | |
|
5d66a88b0d | |
|
df20fb9ddb | |
|
ddfe23ccca | |
|
e7cd3e3635 | |
|
c7f12617a6 | |
|
64ccdc40a0 | |
|
c041cc69f0 | |
|
c53892a128 | |
|
a2e8fb9050 | |
|
6338e5308d | |
|
5c3f6a2a8d | |
|
6614e8b414 | |
|
50a768f6e2 | |
|
a19c2b0c33 | |
|
1b5afce9f8 | |
|
ab9d9bfe04 | |
|
ddcd6b2af0 | |
|
804f605680 | |
|
be5f77a319 | |
|
de247bf0fa | |
|
81d713f6e6 | |
|
d2d8f02d50 | |
|
144da45241 | |
|
5ef60f2f21 | |
|
06dd84bc69 | |
|
5d8b912216 | |
|
f5853bda82 | |
|
3cbe0a1598 | |
|
daa7be5b7f | |
|
a52d513883 | |
|
72833e950a | |
|
14216fd486 | |
|
f9991cd248 | |
|
825891c7ef | |
|
957733a147 | |
|
63837139cd | |
|
9de4592de5 | |
|
ef7fafd07e | |
|
354f1cbd34 | |
|
30905e9aa8 | |
|
ef0fe3f61a | |
|
2de1c21781 | |
|
b535707035 | |
|
d096d6b740 | |
|
92f7613545 | |
|
10d59ade55 | |
|
a40fef851a | |
|
41859c47e7 | |
|
bb07cd3d48 | |
|
b095c40e73 | |
|
048f86f366 | |
|
b6dcb71a1a | |
|
c84805146d | |
|
9c5804777b | |
|
efa9b2d01d | |
|
5c18a4514d | |
|
f7d9b7d50d | |
|
887184e0e5 | |
|
f24a2e8ef7 | |
|
233c3dcebd | |
|
7ccaf78071 | |
|
032e819f3c | |
|
d8a947b53d | |
|
43bc6c08d6 | |
|
79ae918e29 | |
|
d835fd8b82 | |
|
1e9b407037 | |
|
1ca1a9b6b3 | |
|
7b62d963c7 | |
|
38e93e9308 | |
|
d6c834cea9 | |
|
a9b437c5f4 | |
|
f27c35a7dd | |
|
0134a5fc3f | |
|
fbeb5a7b1a | |
|
f1926d3423 | |
|
deef6a0744 | |
|
a35dd209c3 | |
|
b865681a39 | |
|
4b58fb57a6 | |
|
ed43df35fb | |
|
7785fea284 | |
|
3d83bb9f06 | |
|
c79b4f2e61 | |
|
588c591424 | |
|
b14955365c | |
|
57872a8a17 | |
|
527fa59fc6 | |
|
8a07105d9d | |
|
650bff4793 | |
|
3a95591005 | |
|
7f51295293 | |
|
06e40a39bc | |
|
411c2376c7 | |
|
76ce988587 | |
|
49981c22db | |
|
dbfeeebe38 | |
|
8e8b5f59f5 | |
|
3964553ed5 | |
|
56d437a1e7 | |
|
7616f6e95d | |
|
b45af1dcd6 | |
|
036bc70a47 | |
|
1950722e04 | |
|
78eea5071b | |
|
43e0ce4977 | |
|
ec05bf7be9 | |
|
384ffc1025 | |
|
f8c54fd2bf | |
|
bc285f7072 | |
|
43628c8340 | |
|
085dbe716f | |
|
05387aa750 | |
|
9eecd977c9 | |
|
c73541919c | |
|
1a1e407939 | |
|
f79a135a77 | |
|
b19b521b9c | |
|
bf82be86b1 | |
|
8c14132c9b | |
|
ce38445abc | |
|
b9e2b14cf0 | |
|
8b2e42300f | |
|
1fda1f7525 | |
|
0319ff7920 | |
|
815591e10c | |
|
5e1295f89e | |
|
083d08878a | |
|
b3bd9b1215 | |
|
d7c12986c6 | |
|
e9ad224752 | |
|
9a7406d98d | |
|
ccaad8b3be | |
|
4b35f2e0d9 | |
|
cada003d7f | |
|
8e14c52dd1 | |
|
a450350854 | |
|
57e668d704 | |
|
6fe38fde00 | |
|
2ce052c981 | |
|
f0e121051d | |
|
affbc492d7 | |
|
5a8f9284ab | |
|
577d4618ca | |
|
5582ea1b02 | |
|
86c086bafc | |
|
a1fe918276 | |
|
8e4fe207f1 | |
|
516a6909ac | |
|
f7ddfb44b7 | |
|
341f2c3307 | |
|
c3e137c08a | |
|
e8a72b0268 | |
|
b8a502d7e2 | |
|
c1bdb4b11e | |
|
f5657ac469 | |
|
4c017a7f76 | |
|
03db55e15b | |
|
e42fcb812e | |
|
4b065d4790 | |
|
9ef9cae60f | |
|
722a335b68 | |
|
aeebe0bbbe | |
|
6939b2ca5f | |
|
3c8da3722d | |
|
f32b6a171c | |
|
76a6235940 | |
|
4d3bc90e9d | |
|
70076fa7cd | |
|
153f5372d3 | |
|
122a73b5ac | |
|
0a7b50f208 | |
|
a09cc13a17 | |
|
00c4069640 | |
|
953ddc566f | |
|
1b138a74ec | |
|
3dc8f5e039 | |
|
fbbf2eb550 | |
|
51d5ca0695 | |
|
160632c3e6 | |
|
233d29d8de | |
|
ea429d347d | |
|
c24680b93d | |
|
7ff2b9c345 | |
|
994485a90c | |
|
6dc30e953e | |
|
b8f9b6f8db | |
|
ff93f58304 | |
|
eb1bcf642c | |
|
5d7c397b00 | |
|
93a358038d | |
|
e846674a2f | |
|
5dd6256550 | |
|
200b5192ed | |
|
f5f7770d30 | |
|
50602dc1a4 | |
|
17f3281844 | |
|
d4612f2140 | |
|
060a98a01a | |
|
646b627854 | |
|
3e77867cd2 | |
|
0e1eb52c4c | |
|
d8d7c0cd3c | |
|
d3497b9f6b | |
|
2773cbf889 | |
|
9a983d611f | |
|
2e89f86d16 | |
|
26f74e9d83 | |
|
7cdede9a5f | |
|
1626d19711 | |
|
29708329ab | |
|
199e710597 | |
|
14139f8fad | |
|
1316cdee79 | |
|
4b61c0b776 | |
|
3fec06f36e | |
|
fb6defd60f | |
|
e4f64e80bf | |
|
1a4d1ce24e | |
|
e6ea0392e3 | |
|
2e68e170fc | |
|
b826b9bacc | |
|
1771fbb909 | |
|
c9d2ed1458 | |
|
6ef39d8b6e | |
|
ce4c3f2f43 | |
|
c0cad4ed80 | |
|
b0858e48b8 | |
|
fbaa172732 | |
|
5fb483099f | |
|
8d2d8f99e9 | |
|
4ede4769e2 | |
|
5bb1c2b520 | |
|
55eb8f3c21 | |
|
baa6af4831 | |
|
13d9a78ec6 | |
|
55df44923f | |
|
dccba5f9c3 | |
|
3aa096e2e5 | |
|
4cba08aa8c | |
|
2551028f98 | |
|
5a5776068c | |
|
22e59d7838 | |
|
15a7484b6f | |
|
2114b7efc5 | |
|
5507c2b676 | |
|
28ffd303cb | |
|
88e772ef17 | |
|
9fc62092a4 | |
|
4a2fffe2f3 | |
|
5a119fa9f7 | |
|
3861e85d09 | |
|
54ef674a99 | |
|
f561911211 | |
|
147ae66ab5 | |
|
7ca280aee6 | |
|
39a9b21e98 | |
|
161a50c0b8 | |
|
fbb5f871c4 | |
|
a2eb7b854d | |
|
15fe8c3844 | |
|
c436f6dbad | |
|
9a94118c9d | |
|
4f5837b41c | |
|
bb6ffbd9e2 | |
|
6c5bc17c58 | |
|
eb173e2caa | |
|
7cf91e005d | |
|
84e40810cd | |
|
f049487021 | |
|
acfb3a8992 | |
|
2d77edf9a2 | |
|
317c74193d | |
|
3892047d2d | |
|
58e09f4a58 | |
|
137384cdea | |
|
c06f0eb5f7 | |
|
530ebd49ee | |
|
e7a5101366 | |
|
69d5125b87 | |
|
f04c919e79 | |
|
218530209f |
|
@ -1,12 +1,12 @@
|
|||
! Copyright (C) 2009 Slava Pestov.
|
||||
! See http://factorcode.org/license.txt for BSD license.
|
||||
USING: accessors alien.c-types alien.complex.functor kernel
|
||||
sequences ;
|
||||
USING: accessors alien alien.c-types alien.complex.functor
|
||||
classes.struct kernel math quotations ;
|
||||
FROM: alien.c-types => float double ;
|
||||
IN: alien.complex
|
||||
|
||||
<<
|
||||
{ "float" "double" } [ dup "complex-" prepend define-complex-type ] each
|
||||
>>
|
||||
COMPLEX-TYPE: float complex-float
|
||||
COMPLEX-TYPE: double complex-double
|
||||
|
||||
<<
|
||||
! This overrides the fact that small structures are never returned
|
||||
|
|
|
@ -1,32 +1,27 @@
|
|||
! Copyright (C) 2009 Slava Pestov.
|
||||
! See http://factorcode.org/license.txt for BSD license.
|
||||
USING: accessors alien alien.c-types classes.struct functors
|
||||
kernel math math.functions quotations ;
|
||||
USING: functors2 ;
|
||||
IN: alien.complex.functor
|
||||
|
||||
<FUNCTOR: define-complex-type ( N T -- )
|
||||
INLINE-FUNCTOR: complex-type ( n: existing-word t: name -- ) [[
|
||||
USING: alien alien.c-types classes.struct kernel quotations ;
|
||||
QUALIFIED: math
|
||||
|
||||
N-type IS ${N}
|
||||
<<
|
||||
STRUCT: ${t} { real ${n} } { imaginary ${n} } ;
|
||||
|
||||
T-class DEFINES-CLASS ${T}
|
||||
: <${t}> ( z -- alien )
|
||||
math:>rect ${t} <struct-boa> >c-ptr ;
|
||||
|
||||
<T> DEFINES <${T}>
|
||||
*T DEFINES *${T}
|
||||
: *${t} ( alien -- z )
|
||||
${t} memory>struct [ real>> ] [ imaginary>> ] bi math:rect> ; inline
|
||||
|
||||
WHERE
|
||||
>>
|
||||
|
||||
STRUCT: T-class { real N-type } { imaginary N-type } ;
|
||||
\ ${t} lookup-c-type
|
||||
[ <${t}> ] >>unboxer-quot
|
||||
[ *${t} ] >>boxer-quot
|
||||
complex >>boxed-class
|
||||
drop
|
||||
|
||||
: <T> ( z -- alien )
|
||||
>rect T-class <struct-boa> >c-ptr ;
|
||||
|
||||
: *T ( alien -- z )
|
||||
T-class memory>struct [ real>> ] [ imaginary>> ] bi rect> ; inline
|
||||
|
||||
T-class lookup-c-type
|
||||
<T> 1quotation >>unboxer-quot
|
||||
*T 1quotation >>boxer-quot
|
||||
complex >>boxed-class
|
||||
drop
|
||||
|
||||
;FUNCTOR>
|
||||
]]
|
||||
|
|
|
@ -30,7 +30,7 @@ HELP: <c-array>
|
|||
}
|
||||
} ;
|
||||
|
||||
HELP: c-array{
|
||||
HELP: \c-array{
|
||||
{ $description "Literal syntax, consists of a C-type followed by a series of values terminated by " { $snippet "}" } }
|
||||
{ $notes "The appropriate specialized array vocabulary must be loaded; otherwise, an error will be thrown. See the " { $vocab-link "specialized-arrays" } " vocabulary for details on the underlying sequence type constructed." }
|
||||
{ $errors "Throws an error if the type does not exist, the necessary specialized array vocabulary is not loaded, or the requested size is negative." } ;
|
||||
|
@ -182,7 +182,7 @@ $nl
|
|||
{ $subsections "alien.enums" }
|
||||
"A utility for defining " { $link "destructors" } " for deallocating memory:"
|
||||
{ $subsections "alien.destructors" }
|
||||
"C struct and union types can be defined with " { $link POSTPONE: STRUCT: } " and " { $link POSTPONE: UNION-STRUCT: } ". See " { $link "classes.struct" } " for details. For passing arrays to and from C, use the " { $link "specialized-arrays" } " vocabulary." ;
|
||||
"C struct and union types can be defined with " { $link postpone: \STRUCT: } " and " { $link postpone: \UNION-STRUCT: } ". See " { $link "classes.struct" } " for details. For passing arrays to and from C, use the " { $link "specialized-arrays" } " vocabulary." ;
|
||||
|
||||
HELP: malloc-string
|
||||
{ $values { "string" string } { "encoding" "an encoding descriptor" } { "alien" c-ptr } }
|
||||
|
@ -202,7 +202,7 @@ HELP: <c-direct-array>
|
|||
{ $notes "The appropriate specialized array vocabulary must be loaded; otherwise, an error will be thrown. See the " { $vocab-link "specialized-arrays" } " vocabulary for details on the underlying sequence type constructed." } ;
|
||||
|
||||
ARTICLE: "c-strings" "C strings"
|
||||
"C string types are arrays with shape " { $snippet "{ c-string encoding }" } ", where " { $snippet "encoding" } " is an encoding descriptor. The type " { $link c-string } " is an alias for " { $snippet "{ c-string utf8 }" } ". See " { $link "encodings-descriptors" } " for information about encoding descriptors. In " { $link POSTPONE: TYPEDEF: } ", " { $link POSTPONE: FUNCTION: } ", " { $link POSTPONE: CALLBACK: } ", and " { $link POSTPONE: STRUCT: } " definitions, the shorthand syntax " { $snippet "c-string[encoding]" } " can be used to specify the string encoding."
|
||||
"C string types are arrays with shape " { $snippet "{ c-string encoding }" } ", where " { $snippet "encoding" } " is an encoding descriptor. The type " { $link c-string } " is an alias for " { $snippet "{ c-string utf8 }" } ". See " { $link "encodings-descriptors" } " for information about encoding descriptors. In " { $link postpone: \TYPEDEF: } ", " { $link postpone: \FUNCTION: } ", " { $link postpone: \CALLBACK: } ", and " { $link postpone: \STRUCT: } " definitions, the shorthand syntax " { $snippet "c-string[encoding]" } " can be used to specify the string encoding."
|
||||
$nl
|
||||
"Using C string types triggers automatic conversions:"
|
||||
{ $list
|
||||
|
@ -211,7 +211,7 @@ $nl
|
|||
"Passing an already encoded " { $link byte-array } " also works and performs no conversion."
|
||||
}
|
||||
{ "Returning a C string from a C function allocates a Factor string in the Factor heap; the memory pointed to by the returned pointer is then decoded with the requested encoding into the Factor string." }
|
||||
{ "Reading " { $link c-string } " slots of " { $link POSTPONE: STRUCT: } " or " { $link POSTPONE: UNION-STRUCT: } " returns Factor strings." }
|
||||
{ "Reading " { $link c-string } " slots of " { $link postpone: \STRUCT: } " or " { $link postpone: \UNION-STRUCT: } " returns Factor strings." }
|
||||
}
|
||||
$nl
|
||||
"Care must be taken if the C function expects a pointer to a string with its length represented by another parameter rather than a null terminator. Passing the result of calling " { $link length } " on the string object will not suffice. This is because a Factor string of " { $emphasis "n" } " characters will not necessarily encode to " { $emphasis "n" } " bytes. The correct idiom for C functions which take a string with a length is to first encode the string using " { $link encode } ", and then pass the resulting byte array together with the length of this byte array."
|
||||
|
|
|
@ -46,7 +46,7 @@ SPECIALIZED-ARRAY: foo
|
|||
{ f } [ B{ } binary-zero? ] unit-test
|
||||
{ t } [ S{ foo f 0 f f } binary-zero? ] unit-test
|
||||
{ f } [ S{ foo f 1 f f } binary-zero? ] unit-test
|
||||
{ f } [ S{ foo f 0 ALIEN: 8 f } binary-zero? ] unit-test
|
||||
{ f } [ S{ foo f 0 alien: 8 f } binary-zero? ] unit-test
|
||||
{ f } [ S{ foo f 0 f t } binary-zero? ] unit-test
|
||||
{ t t f } [
|
||||
foo-array{
|
||||
|
|
|
@ -66,7 +66,7 @@ M: word <c-direct-array>
|
|||
M: pointer <c-direct-array>
|
||||
drop void* <c-direct-array> ;
|
||||
|
||||
SYNTAX: c-array{ \ } [ unclip >c-array ] parse-literal ;
|
||||
SYNTAX: \c-array{ \ \} [ unclip >c-array ] parse-literal ;
|
||||
|
||||
SYNTAX: c-array@
|
||||
scan-object [ scan-object scan-object ] dip
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
IN: alien.destructors
|
||||
USING: help.markup help.syntax alien destructors ;
|
||||
|
||||
HELP: DESTRUCTOR:
|
||||
HELP: \DESTRUCTOR:
|
||||
{ $syntax "DESTRUCTOR: word" }
|
||||
{ $description "Defines four things:"
|
||||
{ $list
|
||||
|
@ -25,6 +25,6 @@ HELP: DESTRUCTOR:
|
|||
|
||||
ARTICLE: "alien.destructors" "Alien destructors"
|
||||
"The " { $vocab-link "alien.destructors" } " vocabulary defines a utility parsing word for defining new disposable classes."
|
||||
{ $subsections POSTPONE: DESTRUCTOR: } ;
|
||||
{ $subsections postpone: \DESTRUCTOR: } ;
|
||||
|
||||
ABOUT: "alien.destructors"
|
||||
|
|
|
@ -1,32 +1,22 @@
|
|||
! Copyright (C) 2009 Slava Pestov.
|
||||
! See http://factorcode.org/license.txt for BSD license.
|
||||
USING: accessors destructors effects functors generalizations
|
||||
kernel parser sequences ;
|
||||
USING: functors2 ;
|
||||
IN: alien.destructors
|
||||
|
||||
TUPLE: alien-destructor alien ;
|
||||
|
||||
<FUNCTOR: define-destructor ( F -- )
|
||||
INLINE-FUNCTOR: destructor ( f: existing-word -- ) [[
|
||||
USING: accessors alien.destructors effects generalizations
|
||||
destructors kernel literals sequences ;
|
||||
|
||||
F-destructor DEFINES-CLASS ${F}-destructor
|
||||
<F-destructor> DEFINES <${F}-destructor>
|
||||
&F DEFINES &${F}
|
||||
|F DEFINES |${F}
|
||||
N [ F stack-effect out>> length ]
|
||||
TUPLE: ${f}-destructor < alien-destructor ;
|
||||
|
||||
WHERE
|
||||
: <${f}-destructor> ( alien -- destructor )
|
||||
${f}-destructor boa ; inline
|
||||
|
||||
TUPLE: F-destructor < alien-destructor ;
|
||||
: &${f} ( alien -- alien ) dup <${f}-destructor> &dispose drop ; inline
|
||||
|
||||
: <F-destructor> ( alien -- destructor )
|
||||
F-destructor boa ; inline
|
||||
: |${f} ( alien -- alien ) dup <${f}-destructor> |dispose drop ; inline
|
||||
|
||||
M: F-destructor dispose alien>> F N ndrop ;
|
||||
|
||||
: &F ( alien -- alien ) dup <F-destructor> &dispose drop ; inline
|
||||
|
||||
: |F ( alien -- alien ) dup <F-destructor> |dispose drop ; inline
|
||||
|
||||
;FUNCTOR>
|
||||
|
||||
SYNTAX: DESTRUCTOR: scan-word define-destructor ;
|
||||
M: ${f}-destructor dispose alien>> ${f} $[ \ ${f} stack-effect out>> length ] ndrop ;
|
||||
]]
|
||||
|
|
|
@ -4,7 +4,7 @@ USING: help.markup help.syntax kernel math quotations
|
|||
classes.struct ;
|
||||
IN: alien.endian
|
||||
|
||||
HELP: BE-PACKED-STRUCT:
|
||||
HELP: \BE-PACKED-STRUCT:
|
||||
{ $description "Defines a packed " { $link struct } " where endian-unaware types become big-endian types. Note that endian-aware types will override the big-endianness of this " { $link struct } " declaration; little-endian types will stay little-endian. On big-endian platforms, the endian-unaware types will not change since they are the correct endianness already." }
|
||||
{ $unchecked-example
|
||||
"! When run on a big-endian platform, this struct should prettyprint the same as defined"
|
||||
|
@ -17,7 +17,7 @@ IN: scratchpad
|
|||
STRUCT: s1 { a char[7] } { b be32 initial: 0 } ;"
|
||||
} ;
|
||||
|
||||
HELP: BE-STRUCT:
|
||||
HELP: \BE-STRUCT:
|
||||
{ $description "Defines a " { $link struct } " where endian-unaware types become big-endian types. Note that endian-aware types will override the big-endianness of this " { $link struct } " declaration; little-endian types will stay little-endian. On big-endian platforms, the endian-unaware types will not change since they are the correct endianness already." }
|
||||
{ $unchecked-example
|
||||
"! When run on a big-endian platform, this struct should prettyprint the same as defined"
|
||||
|
@ -30,7 +30,7 @@ IN: scratchpad
|
|||
STRUCT: s1 { a be32 initial: 0 } { b le32 initial: 0 } ;"
|
||||
} ;
|
||||
|
||||
HELP: LE-PACKED-STRUCT:
|
||||
HELP: \LE-PACKED-STRUCT:
|
||||
{ $description "Defines a packed " { $link struct } " where endian-unaware types become little-endian types. Note that endian-aware types will override the little-endianness of this " { $link struct } " declaration; big-endian types will stay big-endian. On little-endian platforms, the endian-unaware types will not change since they are the correct endianness already." }
|
||||
{ $unchecked-example
|
||||
"! When run on a little-endian platform, this struct should prettyprint the same as defined"
|
||||
|
@ -43,7 +43,7 @@ IN: scratchpad
|
|||
STRUCT: s1 { a char[7] } { b int initial: 0 } ;"
|
||||
} ;
|
||||
|
||||
HELP: LE-STRUCT:
|
||||
HELP: \LE-STRUCT:
|
||||
{ $description "Defines a " { $link struct } " where endian-unaware types become little-endian types. Note that endian-aware types will override the little-endianness of this " { $link struct } " declaration; big-endian types will stay big-endian. On little-endian platforms, the endian-unaware types will not change since they are the correct endianness already." }
|
||||
{ $unchecked-example
|
||||
"! When run on a little-endian platform, this struct should prettyprint the same as defined"
|
||||
|
@ -141,10 +141,10 @@ ARTICLE: "alien.endian" "Alien endian-aware types"
|
|||
}
|
||||
"Syntax for making endian-aware structs out of native types:"
|
||||
{ $subsections
|
||||
POSTPONE: LE-STRUCT:
|
||||
POSTPONE: BE-STRUCT:
|
||||
POSTPONE: LE-PACKED-STRUCT:
|
||||
POSTPONE: BE-PACKED-STRUCT:
|
||||
postpone: \LE-STRUCT:
|
||||
postpone: \BE-STRUCT:
|
||||
postpone: \LE-PACKED-STRUCT:
|
||||
postpone: \BE-PACKED-STRUCT:
|
||||
} ;
|
||||
|
||||
ABOUT: "alien.endian"
|
||||
|
|
|
@ -147,18 +147,18 @@ ERROR: unsupported-endian-type endian slot ;
|
|||
[ compute-struct-offsets ] [ drop 1 ]
|
||||
(define-struct-class) ;
|
||||
|
||||
SYNTAX: LE-STRUCT:
|
||||
SYNTAX: \LE-STRUCT:
|
||||
parse-struct-definition
|
||||
little-endian define-endian-struct-class ;
|
||||
|
||||
SYNTAX: BE-STRUCT:
|
||||
SYNTAX: \BE-STRUCT:
|
||||
parse-struct-definition
|
||||
big-endian define-endian-struct-class ;
|
||||
|
||||
SYNTAX: LE-PACKED-STRUCT:
|
||||
SYNTAX: \LE-PACKED-STRUCT:
|
||||
parse-struct-definition
|
||||
little-endian define-endian-packed-struct-class ;
|
||||
|
||||
SYNTAX: BE-PACKED-STRUCT:
|
||||
SYNTAX: \BE-PACKED-STRUCT:
|
||||
parse-struct-definition
|
||||
big-endian define-endian-packed-struct-class ;
|
||||
|
|
|
@ -7,7 +7,7 @@ HELP: define-enum
|
|||
{ $values
|
||||
{ "word" word } { "base-type" c-type } { "members" "sequence of word and value pairs" }
|
||||
}
|
||||
{ $description "Defines an enum. This is the run-time equivalent of " { $link POSTPONE: ENUM: } "." } ;
|
||||
{ $description "Defines an enum. This is the run-time equivalent of " { $link postpone: \ENUM: } "." } ;
|
||||
|
||||
HELP: enum>number
|
||||
{ $values
|
||||
|
@ -23,6 +23,6 @@ HELP: number>enum
|
|||
}
|
||||
{ $description "Convert a number to an enum." } ;
|
||||
|
||||
{ POSTPONE: ENUM: define-enum enum>number number>enum } related-words
|
||||
{ postpone: \ENUM: define-enum enum>number number>enum } related-words
|
||||
|
||||
ABOUT: "alien.enums"
|
||||
|
|
|
@ -1,24 +0,0 @@
|
|||
USING: accessors alien.libraries kernel sequences system vocabs
|
||||
;
|
||||
IN: alien.libraries.finder
|
||||
|
||||
HOOK: find-library* os ( name -- path/f )
|
||||
|
||||
: find-library ( name -- path/library-not-found )
|
||||
dup find-library* [ nip ] when* ;
|
||||
|
||||
: ?update-library ( name path abi -- )
|
||||
pick lookup-library [ dll>> dll-valid? ] [ f ] if* [
|
||||
3drop
|
||||
] [
|
||||
[ find-library ] [ update-library ] bi*
|
||||
] if ;
|
||||
|
||||
! Try to find the library from a list, but if it's not found,
|
||||
! try to open a library that is the first name in that list anyway
|
||||
! or "library_not_found" as a last resort for better debugging.
|
||||
: find-library-from-list ( seq -- path/f )
|
||||
dup [ find-library* ] map-find drop
|
||||
[ ] [ ?first "library_not_found" or ] ?if ;
|
||||
|
||||
"alien.libraries.finder." os name>> append require
|
|
@ -1,5 +0,0 @@
|
|||
USING: alien.libraries.finder sequences tools.test ;
|
||||
IN: alien.libraries.finder.linux.tests
|
||||
|
||||
{ t } [ "libm.so" "m" find-library subseq? ] unit-test
|
||||
{ t } [ "libc.so" "c" find-library subseq? ] unit-test
|
|
@ -1,47 +0,0 @@
|
|||
! Copyright (C) 2013 Björn Lindqvist, Doug Coleman.
|
||||
! See http://factorcode.org/license.txt for BSD license
|
||||
USING: alien.libraries.finder arrays assocs
|
||||
combinators.short-circuit io io.encodings.utf8 io.files
|
||||
io.files.info io.launcher kernel sequences sets splitting system
|
||||
unicode ;
|
||||
IN: alien.libraries.finder.linux
|
||||
|
||||
<PRIVATE
|
||||
|
||||
CONSTANT: mach-map {
|
||||
{ ppc.64 { "libc6" "64bit" } }
|
||||
{ x86.32 { "libc6" "x32" } }
|
||||
{ x86.64 { "libc6" "x86-64" } }
|
||||
}
|
||||
|
||||
: parse-ldconfig-lines ( string -- triple )
|
||||
[
|
||||
"=>" split1 [ [ blank? ] trim ] bi@
|
||||
[
|
||||
" " split1 [ "()" in? ] trim "," split
|
||||
[ [ blank? ] trim ] map
|
||||
[ ": Linux" swap subseq? ] reject
|
||||
] dip 3array
|
||||
] map ;
|
||||
|
||||
: load-ldconfig-cache ( -- seq )
|
||||
"/sbin/ldconfig -p" utf8 [ lines ] with-process-reader
|
||||
rest parse-ldconfig-lines ;
|
||||
|
||||
: ldconfig-arch ( -- str )
|
||||
mach-map cpu of { "libc6" } or ;
|
||||
|
||||
: name-matches? ( lib triple -- ? )
|
||||
first swap ?head [ ?first CHAR: . = ] [ drop f ] if ;
|
||||
|
||||
: arch-matches? ( lib triple -- ? )
|
||||
[ drop ldconfig-arch ] [ second swap subset? ] bi* ;
|
||||
|
||||
: ldconfig-matches? ( lib triple -- ? )
|
||||
{ [ name-matches? ] [ arch-matches? ] } 2&& ;
|
||||
|
||||
PRIVATE>
|
||||
|
||||
M: linux find-library*
|
||||
"lib" prepend load-ldconfig-cache
|
||||
[ ldconfig-matches? ] with find nip ?first ;
|
|
@ -1 +0,0 @@
|
|||
linux
|
|
@ -1,50 +0,0 @@
|
|||
|
||||
USING: alien.libraries.finder
|
||||
alien.libraries.finder.macosx.private sequences tools.test ;
|
||||
|
||||
IN: alien.libraries.finder.macosx
|
||||
|
||||
{
|
||||
{
|
||||
f
|
||||
f
|
||||
f
|
||||
f
|
||||
T{ framework-info f "Location" "Name.framework/Name" "Name" f f }
|
||||
T{ framework-info f "Location" "Name.framework/Name_suffix" "Name" f "suffix" }
|
||||
f
|
||||
f
|
||||
T{ framework-info f "Location" "Name.framework/Versions/A/Name" "Name" "A" f }
|
||||
T{ framework-info f "Location" "Name.framework/Versions/A/Name_suffix" "Name" "A" "suffix" }
|
||||
}
|
||||
} [
|
||||
{
|
||||
"broken/path"
|
||||
"broken/path/_suffix"
|
||||
"Location/Name.framework"
|
||||
"Location/Name.framework/_suffix"
|
||||
"Location/Name.framework/Name"
|
||||
"Location/Name.framework/Name_suffix"
|
||||
"Location/Name.framework/Versions"
|
||||
"Location/Name.framework/Versions/A"
|
||||
"Location/Name.framework/Versions/A/Name"
|
||||
"Location/Name.framework/Versions/A/Name_suffix"
|
||||
} [ make-framework-info ] map
|
||||
] unit-test
|
||||
|
||||
{
|
||||
{
|
||||
"/usr/lib/libSystem.dylib"
|
||||
"/System/Library/Frameworks/System.framework/System"
|
||||
}
|
||||
} [
|
||||
{
|
||||
"libSystem.dylib"
|
||||
"System.framework/System"
|
||||
} [ dyld-find ] map
|
||||
] unit-test
|
||||
|
||||
{ t } [ "libm.dylib" "m" find-library subseq? ] unit-test
|
||||
{ t } [ "libc.dylib" "c" find-library subseq? ] unit-test
|
||||
{ t } [ "libbz2.dylib" "bz2" find-library subseq? ] unit-test
|
||||
{ t } [ "AGL.framework" "AGL" find-library subseq? ] unit-test
|
|
@ -1 +0,0 @@
|
|||
macosx
|
|
@ -1,34 +0,0 @@
|
|||
! Copyright (C) 2013 Björn Lindqvist, John Benediktsson
|
||||
! See http://factorcode.org/license.txt for BSD license
|
||||
|
||||
USING: alien.libraries.finder arrays combinators.short-circuit
|
||||
environment io.backend io.files io.files.info io.pathnames kernel
|
||||
sequences splitting system system-info.windows ;
|
||||
|
||||
IN: alien.libraries.finder.windows
|
||||
|
||||
<PRIVATE
|
||||
|
||||
: search-paths ( -- seq )
|
||||
"resource:" normalize-path
|
||||
system-directory
|
||||
windows-directory 3array
|
||||
"PATH" os-env [ ";" split ] [ f ] if* append ;
|
||||
|
||||
: candidate-paths ( name -- seq )
|
||||
search-paths over ".dll" tail? [
|
||||
[ prepend-path ] with map
|
||||
] [
|
||||
[
|
||||
[ prepend-path ]
|
||||
[ [ ".dll" append ] [ prepend-path ] bi* ] 2bi
|
||||
2array
|
||||
] with map concat
|
||||
] if ;
|
||||
|
||||
PRIVATE>
|
||||
|
||||
M: windows find-library*
|
||||
candidate-paths [
|
||||
{ [ exists? ] [ file-info regular-file? ] } 1&&
|
||||
] find nip ;
|
|
@ -1 +0,0 @@
|
|||
windows
|
|
@ -1,9 +0,0 @@
|
|||
USING: alien.libraries io.pathnames system windows.errors
|
||||
windows.kernel32 ;
|
||||
IN: alien.libraries.windows
|
||||
|
||||
M: windows >deployed-library-path
|
||||
file-name ;
|
||||
|
||||
M: windows dlerror ( -- message )
|
||||
GetLastError n>win32-error-string ;
|
|
@ -122,6 +122,7 @@ TYPEDEF: int alien-parser-test-int ! reasonably unique name...
|
|||
] unit-test
|
||||
|
||||
! Redefinitions
|
||||
{ } [
|
||||
[ C-TYPE: hi TYPEDEF: void* hi ] with-compilation-unit
|
||||
] unit-test
|
||||
<<
|
||||
C-TYPE: hi
|
||||
TYPEDEF: void* hi
|
||||
>>
|
||||
|
|
|
@ -21,7 +21,7 @@ ERROR: bad-array-type ;
|
|||
: (parse-c-type) ( string -- type )
|
||||
{
|
||||
{ [ "*" ?tail ] [ (parse-c-type) <pointer> ] }
|
||||
{ [ CHAR: ] over member? ] [ parse-array-type ] }
|
||||
{ [ char: \] over member? ] [ parse-array-type ] }
|
||||
{ [ dup search ] [ parse-word ] }
|
||||
[ parse-word ]
|
||||
} cond ;
|
||||
|
@ -37,7 +37,7 @@ ERROR: bad-array-type ;
|
|||
|
||||
: scan-c-type ( -- c-type )
|
||||
scan-token {
|
||||
{ [ dup "{" = ] [ drop \ } parse-until >array ] }
|
||||
{ [ dup "{" = ] [ drop \ \} parse-until >array ] }
|
||||
{ [ dup "pointer:" = ] [ drop scan-c-type <pointer> ] }
|
||||
[ parse-c-type ]
|
||||
} cond ;
|
||||
|
|
|
@ -11,12 +11,12 @@ M: alien pprint*
|
|||
{
|
||||
{ [ dup expired? ] [ drop \ BAD-ALIEN pprint-word ] }
|
||||
{ [ dup pinned-c-ptr? not ] [ drop "( displaced alien )" text ] }
|
||||
[ \ ALIEN: [ alien-address >hex text ] pprint-prefix ]
|
||||
[ \ \alien: [ alien-address >hex text ] pprint-prefix ]
|
||||
} cond ;
|
||||
|
||||
M: dll pprint* dll-path dup "DLL\" " "\"" pprint-string ;
|
||||
|
||||
M: c-type-word definer drop \ C-TYPE: f ;
|
||||
M: c-type-word definer drop \ \C-TYPE: f ;
|
||||
M: c-type-word definition drop f ;
|
||||
M: c-type-word declarations. drop ;
|
||||
|
||||
|
@ -37,9 +37,9 @@ PRIVATE>
|
|||
[ record-c-type ] [ c-type-string ] [ ] tri present-text ;
|
||||
|
||||
M: pointer pprint*
|
||||
<flow \ pointer: pprint-word to>> pprint* block> ;
|
||||
<flow \ \pointer: pprint-word to>> pprint* block> ;
|
||||
|
||||
M: typedef-word definer drop \ TYPEDEF: f ;
|
||||
M: typedef-word definer drop \ \TYPEDEF: f ;
|
||||
|
||||
M: typedef-word synopsis*
|
||||
{
|
||||
|
@ -60,7 +60,7 @@ M: typedef-word synopsis*
|
|||
] if-empty ;
|
||||
|
||||
: pprint-library ( library -- )
|
||||
[ \ LIBRARY: [ text ] pprint-prefix ] when* ;
|
||||
[ \ \LIBRARY: [ text ] pprint-prefix ] when* ;
|
||||
|
||||
: pprint-function ( word quot -- )
|
||||
[ def>> first pprint-c-type ]
|
||||
|
@ -79,7 +79,7 @@ PREDICATE: alien-function-alias-word < word
|
|||
} 1&& ;
|
||||
|
||||
M: alien-function-alias-word definer
|
||||
drop \ FUNCTION-ALIAS: f ;
|
||||
drop \ \FUNCTION-ALIAS: f ;
|
||||
M: alien-function-alias-word definition drop f ;
|
||||
M: alien-function-alias-word synopsis*
|
||||
{
|
||||
|
@ -95,7 +95,7 @@ PREDICATE: alien-function-word < alien-function-alias-word
|
|||
[ def>> third ] [ name>> ] bi = ;
|
||||
|
||||
M: alien-function-word definer
|
||||
drop \ FUNCTION: f ;
|
||||
drop \ \FUNCTION: f ;
|
||||
M: alien-function-word synopsis*
|
||||
{
|
||||
[ seeing-word ]
|
||||
|
@ -108,7 +108,7 @@ PREDICATE: alien-callback-type-word < typedef-word
|
|||
"callback-effect" word-prop >boolean ;
|
||||
|
||||
M: alien-callback-type-word definer
|
||||
drop \ CALLBACK: f ;
|
||||
drop \ \CALLBACK: f ;
|
||||
M: alien-callback-type-word definition drop f ;
|
||||
M: alien-callback-type-word synopsis*
|
||||
{
|
||||
|
@ -126,7 +126,7 @@ M: alien-callback-type-word synopsis*
|
|||
} cleave ;
|
||||
|
||||
M: enum-c-type-word definer
|
||||
drop \ ENUM: \ ; ;
|
||||
drop \ \ENUM: \ \; ;
|
||||
M: enum-c-type-word synopsis*
|
||||
{
|
||||
[ seeing-word ]
|
||||
|
|
|
@ -16,7 +16,7 @@ IN: alien.remote-control.tests
|
|||
image-path :> image
|
||||
|
||||
[
|
||||
[I
|
||||
I[[
|
||||
#include <vm/master.h>
|
||||
#include <stdio.h>
|
||||
#include <stdbool.h>
|
||||
|
@ -32,7 +32,7 @@ int main(int argc, char **argv)
|
|||
printf("Done.\n");
|
||||
return 0;
|
||||
}
|
||||
I]
|
||||
]]
|
||||
] with-string-writer
|
||||
[ compile-file ] with-temp-directory
|
||||
[ run-test ] with-temp-directory ;
|
||||
|
|
|
@ -2,33 +2,33 @@ IN: alien.syntax
|
|||
USING: alien alien.c-types alien.enums alien.libraries classes.struct
|
||||
help.markup help.syntax see ;
|
||||
|
||||
HELP: DLL"
|
||||
HELP: \DLL"
|
||||
{ $syntax "DLL\" path\"" }
|
||||
{ $values { "path" "a pathname string" } }
|
||||
{ $description "Constructs a DLL handle at parse time." } ;
|
||||
|
||||
HELP: ALIEN:
|
||||
{ $syntax "ALIEN: address" }
|
||||
HELP: \alien:
|
||||
{ $syntax "alien: address" }
|
||||
{ $values { "address" "a non-negative hexadecimal integer" } }
|
||||
{ $description "Creates an alien object at parse time." }
|
||||
{ $notes "Alien objects are invalidated between image saves and loads, and hence source files should not contain alien literals; this word is for interactive use only. See " { $link "alien-expiry" } " for details." } ;
|
||||
|
||||
ARTICLE: "syntax-aliens" "Alien object literal syntax"
|
||||
{ $subsections
|
||||
POSTPONE: ALIEN:
|
||||
POSTPONE: DLL"
|
||||
postpone: \alien:
|
||||
postpone: \DLL"
|
||||
} ;
|
||||
|
||||
HELP: LIBRARY:
|
||||
HELP: \LIBRARY:
|
||||
{ $syntax "LIBRARY: name" }
|
||||
{ $values { "name" "a logical library name" } }
|
||||
{ $description "Sets the logical library for consequent " { $link POSTPONE: FUNCTION: } ", " { $link POSTPONE: C-GLOBAL: } " and " { $link POSTPONE: CALLBACK: } " definitions, as well as " { $link POSTPONE: &: } " forms." }
|
||||
{ $description "Sets the logical library for consequent " { $link postpone: \FUNCTION: } ", " { $link postpone: \C-GLOBAL: } " and " { $link postpone: \CALLBACK: } " definitions, as well as " { $link postpone: \&: } " forms." }
|
||||
{ $notes "Logical library names are defined with the " { $link add-library } " word." } ;
|
||||
|
||||
HELP: FUNCTION:
|
||||
HELP: \FUNCTION:
|
||||
{ $syntax "FUNCTION: return name ( parameters )" }
|
||||
{ $values { "return" "a C return type" } { "name" "a C function name" } { "parameters" "a comma-separated sequence of type/name pairs; " { $snippet "type1 arg1, type2 arg2, ..." } } }
|
||||
{ $description "Defines a new word " { $snippet "name" } " which calls the C library function with the same " { $snippet "name" } " in the logical library given by the most recent " { $link POSTPONE: LIBRARY: } " declaration."
|
||||
{ $description "Defines a new word " { $snippet "name" } " which calls the C library function with the same " { $snippet "name" } " in the logical library given by the most recent " { $link postpone: \LIBRARY: } " declaration."
|
||||
$nl
|
||||
"The new word must be compiled before being executed." }
|
||||
{ $examples
|
||||
|
@ -45,26 +45,26 @@ $nl
|
|||
"The answer to the question is 42."
|
||||
} }
|
||||
"Using the " { $link c-string } " type instead of " { $snippet "char*" } " causes the FFI to automatically convert Factor strings to C strings. See " { $link "c-strings" } " for more information on using strings with the FFI."
|
||||
{ $notes "To make a Factor word with a name different from the C function, use " { $link POSTPONE: FUNCTION-ALIAS: } "." } ;
|
||||
{ $notes "To make a Factor word with a name different from the C function, use " { $link postpone: \FUNCTION-ALIAS: } "." } ;
|
||||
|
||||
HELP: FUNCTION-ALIAS:
|
||||
HELP: \FUNCTION-ALIAS:
|
||||
{ $syntax "FUNCTION-ALIAS: factor-name
|
||||
return c_name ( parameters ) ;" }
|
||||
{ $values { "factor-name" "a Factor word name" } { "return" "a C return type" } { "name" "a C function name" } { "parameters" "a comma-separated sequence of type/name pairs; " { $snippet "type1 arg1, type2 arg2, ..." } } }
|
||||
{ $description "Defines a new word " { $snippet "factor-name" } " which calls the C library function named " { $snippet "c_name" } " in the logical library given by the most recent " { $link POSTPONE: LIBRARY: } " declaration."
|
||||
{ $description "Defines a new word " { $snippet "factor-name" } " which calls the C library function named " { $snippet "c_name" } " in the logical library given by the most recent " { $link postpone: \LIBRARY: } " declaration."
|
||||
$nl
|
||||
"The new word must be compiled before being executed." }
|
||||
{ $notes "Note that the parentheses and commas are only syntax sugar and can be omitted. They serve no purpose other than to make the declaration easier to read." } ;
|
||||
|
||||
{ POSTPONE: FUNCTION: POSTPONE: FUNCTION-ALIAS: } related-words
|
||||
{ postpone: \FUNCTION: postpone: \FUNCTION-ALIAS: } related-words
|
||||
|
||||
HELP: TYPEDEF:
|
||||
HELP: \TYPEDEF:
|
||||
{ $syntax "TYPEDEF: old new" }
|
||||
{ $values { "old" "a C type" } { "new" "a C type" } }
|
||||
{ $description "Aliases the C type " { $snippet "old" } " under the name " { $snippet "new" } "." }
|
||||
{ $notes "This word differs from " { $link typedef } " in that it runs at parse time, to ensure correct ordering of operations when loading source files. Words defined in source files are compiled before top-level forms are run, so if a source file defines C binding words and uses " { $link typedef } ", the type alias won't be available at compile time." } ;
|
||||
|
||||
HELP: ENUM:
|
||||
HELP: \ENUM:
|
||||
{ $syntax "ENUM: type words... ;" "ENUM: type < base-type words..." }
|
||||
{ $values { "type" { $maybe "a name to typedef to int" } } { "words" "a sequence of word names" } }
|
||||
{ $description "Creates a c-type that boxes and unboxes integer values to symbols. A symbol is defined for each member word. The base c-type can optionally be specified and defaults to " { $link int } ". A constructor word " { $snippet "<type>" } " is defined for converting from integers to singletons. The generic word " { $link enum>number } " converts from singletons to integers. Enum-typed values are automatically prettyprinted as their singleton words. Unrecognizing enum numbers are kept as numbers." }
|
||||
|
@ -81,25 +81,25 @@ HELP: ENUM:
|
|||
{ $code "ENUM: tv_peripherals_4 < uint\n{ appletv 1 } { chromecast 2 } { roku 4 } ;" }
|
||||
} ;
|
||||
|
||||
HELP: C-TYPE:
|
||||
HELP: \C-TYPE:
|
||||
{ $syntax "C-TYPE: type" }
|
||||
{ $values { "type" "a new C type" } }
|
||||
{ $description "Defines a new, opaque C type. Since it is opaque, " { $snippet "type" } " will not be directly usable as a parameter or return type of a " { $link POSTPONE: FUNCTION: } " or as a slot of a " { $link POSTPONE: STRUCT: } ". However, it can be used as the type of a " { $link pointer } "." $nl
|
||||
{ $description "Defines a new, opaque C type. Since it is opaque, " { $snippet "type" } " will not be directly usable as a parameter or return type of a " { $link postpone: \FUNCTION: } " or as a slot of a " { $link postpone: \STRUCT: } ". However, it can be used as the type of a " { $link pointer } "." $nl
|
||||
{ $snippet "C-TYPE:" } " can also be used to forward declare C types, allowing circular dependencies to occur between types. For example:"
|
||||
{ $code "C-TYPE: forward
|
||||
STRUCT: backward { x forward* } ;
|
||||
STRUCT: forward { x backward* } ;" } }
|
||||
{ $notes "Primitive C types are displayed using " { $snippet "C-TYPE:" } " syntax when they are " { $link see } "n." } ;
|
||||
|
||||
HELP: CALLBACK:
|
||||
HELP: \CALLBACK:
|
||||
{ $syntax "CALLBACK: return type ( parameters )" }
|
||||
{ $values { "return" "a C return type" } { "type" "a type name" } { "parameters" "a comma-separated sequence of type/name pairs; " { $snippet "type1 arg1, type2 arg2, ..." } } }
|
||||
{ $description "Defines a new function pointer C type word " { $snippet "type" } ". The newly defined word works both as a C type and as a wrapper for " { $link alien-callback } " for callbacks that accept the given return type and parameters. The ABI of the callback is decided from the ABI of the active " { $link POSTPONE: LIBRARY: } " declaration." }
|
||||
{ $description "Defines a new function pointer C type word " { $snippet "type" } ". The newly defined word works both as a C type and as a wrapper for " { $link alien-callback } " for callbacks that accept the given return type and parameters. The ABI of the callback is decided from the ABI of the active " { $link postpone: \LIBRARY: } " declaration." }
|
||||
{ $examples
|
||||
{ $code
|
||||
"CALLBACK: bool FakeCallback ( int message, void* payload )"
|
||||
": MyFakeCallback ( -- alien )"
|
||||
" [| message payload |"
|
||||
" |[ message payload |"
|
||||
" \"message #\" write"
|
||||
" message number>string write"
|
||||
" \" received\" write nl"
|
||||
|
@ -108,28 +108,28 @@ HELP: CALLBACK:
|
|||
}
|
||||
} ;
|
||||
|
||||
HELP: &:
|
||||
HELP: \&:
|
||||
{ $syntax "&: symbol" }
|
||||
{ $values { "symbol" "A C global variable name" } }
|
||||
{ $description "Pushes the address of a symbol named " { $snippet "symbol" } " from the current library, set with " { $link POSTPONE: LIBRARY: } "." } ;
|
||||
{ $description "Pushes the address of a symbol named " { $snippet "symbol" } " from the current library, set with " { $link postpone: \LIBRARY: } "." } ;
|
||||
|
||||
HELP: typedef
|
||||
{ $values { "old" "a C type" } { "new" "a C type" } }
|
||||
{ $description "Aliases the C type " { $snippet "old" } " under the name " { $snippet "new" } "." }
|
||||
{ $notes "Using this word in the same source file which defines C bindings can cause problems, because words are compiled before top-level forms are run. Use the " { $link POSTPONE: TYPEDEF: } " word instead." } ;
|
||||
{ $notes "Using this word in the same source file which defines C bindings can cause problems, because words are compiled before top-level forms are run. Use the " { $link postpone: \TYPEDEF: } " word instead." } ;
|
||||
|
||||
{ POSTPONE: TYPEDEF: typedef } related-words
|
||||
{ postpone: \TYPEDEF: typedef } related-words
|
||||
|
||||
HELP: C-GLOBAL:
|
||||
HELP: \C-GLOBAL:
|
||||
{ $syntax "C-GLOBAL: type name" }
|
||||
{ $values { "type" "a C type" } { "name" "a C global variable name" } }
|
||||
{ $description "Defines a getter " { $snippet "name" } " and setter " { $snippet "set-name" } " for the global value in the current library, set with " { $link POSTPONE: LIBRARY: } "." } ;
|
||||
{ $description "Defines a getter " { $snippet "name" } " and setter " { $snippet "set-name" } " for the global value in the current library, set with " { $link postpone: \LIBRARY: } "." } ;
|
||||
|
||||
ARTICLE: "alien.enums" "Enumeration types"
|
||||
"The " { $vocab-link "alien.enums" } " vocab contains the implementation for " { $link POSTPONE: ENUM: } " C types, and provides words for converting between enum singletons and integers. It is possible to dispatch off of members of an enum."
|
||||
"The " { $vocab-link "alien.enums" } " vocab contains the implementation for " { $link postpone: \ENUM: } " C types, and provides words for converting between enum singletons and integers. It is possible to dispatch off of members of an enum."
|
||||
$nl
|
||||
"Defining enums:"
|
||||
{ $subsection POSTPONE: ENUM: }
|
||||
{ $subsection postpone: \ENUM: }
|
||||
"Defining enums at run-time:"
|
||||
{ $subsection define-enum }
|
||||
"Conversions between enums and integers:"
|
||||
|
|
|
@ -6,37 +6,37 @@ strings.parser vocabs words ;
|
|||
<< "alien.arrays" require >> ! needed for bootstrap
|
||||
IN: alien.syntax
|
||||
|
||||
SYNTAX: DLL" lexer get skip-blank parse-string dlopen suffix! ;
|
||||
SYNTAX: \DLL" lexer get skip-blank parse-string dlopen suffix! ;
|
||||
|
||||
SYNTAX: ALIEN: 16 scan-base <alien> suffix! ;
|
||||
SYNTAX: \alien: 16 scan-base <alien> suffix! ;
|
||||
|
||||
SYNTAX: BAD-ALIEN <bad-alien> suffix! ;
|
||||
SYNTAX: \BAD-ALIEN <bad-alien> suffix! ;
|
||||
|
||||
SYNTAX: LIBRARY: scan-token current-library set ;
|
||||
SYNTAX: \LIBRARY: scan-token current-library set ;
|
||||
|
||||
SYNTAX: FUNCTION:
|
||||
SYNTAX: \FUNCTION:
|
||||
(FUNCTION:) make-function define-inline ;
|
||||
|
||||
SYNTAX: FUNCTION-ALIAS:
|
||||
SYNTAX: \FUNCTION-ALIAS:
|
||||
scan-token create-function
|
||||
(FUNCTION:) (make-function) define-inline ;
|
||||
|
||||
SYNTAX: CALLBACK:
|
||||
SYNTAX: \CALLBACK:
|
||||
(CALLBACK:) define-inline ;
|
||||
|
||||
SYNTAX: TYPEDEF:
|
||||
SYNTAX: \TYPEDEF:
|
||||
scan-c-type CREATE-C-TYPE dup save-location typedef ;
|
||||
|
||||
SYNTAX: ENUM:
|
||||
SYNTAX: \ENUM:
|
||||
parse-enum (define-enum) ;
|
||||
|
||||
SYNTAX: C-TYPE:
|
||||
SYNTAX: \C-TYPE:
|
||||
void CREATE-C-TYPE typedef ;
|
||||
|
||||
SYNTAX: &:
|
||||
SYNTAX: \&:
|
||||
scan-token current-library get '[ _ _ address-of ] append! ;
|
||||
|
||||
SYNTAX: C-GLOBAL: scan-c-type scan-new-word define-global ;
|
||||
SYNTAX: \C-GLOBAL: scan-c-type scan-new-word define-global ;
|
||||
|
||||
SYNTAX: pointer:
|
||||
SYNTAX: \pointer:
|
||||
scan-c-type <pointer> suffix! ;
|
||||
|
|
|
@ -26,7 +26,7 @@ CONSTANT: alphabet $[
|
|||
alphabet nth ; inline
|
||||
|
||||
: base64>ch ( ch -- ch )
|
||||
$[ alphabet alphabet-inverse 0 CHAR: = pick set-nth ] nth
|
||||
$[ alphabet alphabet-inverse 0 char: = pick set-nth ] nth
|
||||
[ malformed-base64 ] unless* { fixnum } declare ; inline
|
||||
|
||||
: encode3 ( x y z -- a b c d )
|
||||
|
@ -41,7 +41,7 @@ CONSTANT: alphabet $[
|
|||
[
|
||||
stream stream-write1 1 + dup 76 = [
|
||||
drop 0
|
||||
B{ CHAR: \r CHAR: \n } stream stream-write
|
||||
B{ char: \r char: \n } stream stream-write
|
||||
] when
|
||||
] each
|
||||
] [
|
||||
|
@ -61,9 +61,9 @@ CONSTANT: alphabet $[
|
|||
input stream-read1
|
||||
[ [ 0 or ] bi@ encode3 ] 2keep [ 0 1 ? ] bi@ + {
|
||||
{ 0 [ ] }
|
||||
{ 1 [ drop CHAR: = ] }
|
||||
{ 2 [ 2drop CHAR: = CHAR: = ] }
|
||||
} case data (4sequence) output stream-write-lines
|
||||
{ 1 [ drop char: = ] }
|
||||
{ 2 [ 2drop char: = char: = ] }
|
||||
} case data [ (4sequence) ] keep output stream-write-lines
|
||||
] while 2drop ; inline
|
||||
|
||||
PRIVATE>
|
||||
|
@ -95,12 +95,12 @@ PRIVATE>
|
|||
|
||||
:: (decode-base64) ( input output -- )
|
||||
3 <byte-array> :> data
|
||||
[ B{ CHAR: \n CHAR: \r } input read1-ignoring dup ] [
|
||||
B{ CHAR: \n CHAR: \r } input read1-ignoring CHAR: = or
|
||||
B{ CHAR: \n CHAR: \r } input read1-ignoring CHAR: = or
|
||||
B{ CHAR: \n CHAR: \r } input read1-ignoring CHAR: = or
|
||||
[ decode4 data (3sequence) ] 3keep
|
||||
[ CHAR: = eq? 1 0 ? ] tri@ + +
|
||||
[ B{ char: \n char: \r } input read1-ignoring dup ] [
|
||||
B{ char: \n char: \r } input read1-ignoring char: = or
|
||||
B{ char: \n char: \r } input read1-ignoring char: = or
|
||||
B{ char: \n char: \r } input read1-ignoring char: = or
|
||||
[ decode4 data [ (3sequence) ] keep ] 3keep
|
||||
[ char: = eq? 1 0 ? ] tri@ + +
|
||||
[ head-slice* ] unless-zero
|
||||
output stream-write
|
||||
] while drop ;
|
||||
|
@ -142,18 +142,18 @@ PRIVATE>
|
|||
|
||||
: >urlsafe-base64 ( seq -- base64 )
|
||||
>base64 H{
|
||||
{ CHAR: + CHAR: - }
|
||||
{ CHAR: / CHAR: _ }
|
||||
{ char: + char: - }
|
||||
{ char: / char: _ }
|
||||
} substitute ;
|
||||
|
||||
: urlsafe-base64> ( base64 -- seq )
|
||||
H{
|
||||
{ CHAR: - CHAR: + }
|
||||
{ CHAR: _ CHAR: / }
|
||||
{ char: - char: + }
|
||||
{ char: _ char: / }
|
||||
} substitute base64> ;
|
||||
|
||||
: >urlsafe-base64-lines ( seq -- base64 )
|
||||
>base64-lines H{
|
||||
{ CHAR: + CHAR: - }
|
||||
{ CHAR: / CHAR: _ }
|
||||
{ char: + char: - }
|
||||
{ char: / char: _ }
|
||||
} substitute ;
|
||||
|
|
|
@ -29,14 +29,14 @@ $nl
|
|||
bit-array>integer
|
||||
}
|
||||
"Bit array literal syntax:"
|
||||
{ $subsections POSTPONE: ?{ } ;
|
||||
{ $subsections postpone: \?{ } ;
|
||||
|
||||
ABOUT: "bit-arrays"
|
||||
|
||||
HELP: ?{
|
||||
HELP: \?{
|
||||
{ $syntax "?{ elements... }" }
|
||||
{ $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 }" } } ;
|
||||
|
||||
HELP: bit-array
|
||||
|
|
|
@ -86,7 +86,7 @@ M: bit-array resize
|
|||
|
||||
M: bit-array byte-length length bits>bytes ; inline
|
||||
|
||||
SYNTAX: ?{ \ } [ >bit-array ] parse-literal ;
|
||||
SYNTAX: \?{ \ \} [ >bit-array ] parse-literal ;
|
||||
|
||||
: integer>bit-array ( n -- bit-array )
|
||||
dup 0 =
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
USING: bit-arrays kernel prettyprint.custom ;
|
||||
IN: bit-arrays.prettyprint
|
||||
|
||||
M: bit-array pprint-delims drop \ ?{ \ } ;
|
||||
M: bit-array pprint-delims drop \ \?{ \ \} ;
|
||||
M: bit-array >pprint-sequence ;
|
||||
M: bit-array pprint* pprint-object ;
|
||||
|
|
|
@ -15,7 +15,7 @@ $nl
|
|||
<bit-vector>
|
||||
}
|
||||
"Literal syntax:"
|
||||
{ $subsections POSTPONE: ?V{ }
|
||||
{ $subsections postpone: \?V{ }
|
||||
"If you don't care about initial capacity, a more elegant way to create a new bit vector is to write:"
|
||||
{ $code "?V{ } clone" } ;
|
||||
|
||||
|
@ -32,8 +32,8 @@ HELP: >bit-vector
|
|||
{ $values { "seq" sequence } { "vector" bit-vector } }
|
||||
{ $description "Outputs a freshly-allocated bit vector with the same elements as a given sequence." } ;
|
||||
|
||||
HELP: ?V{
|
||||
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: } } "." }
|
||||
{ $description "Marks the beginning of a literal bit vector. Literal bit vectors are terminated by " { $link postpone: \} } "." }
|
||||
{ $examples { $code "?V{ t f t }" } } ;
|
||||
|
|
|
@ -1,12 +1,13 @@
|
|||
! Copyright (C) 2008, 2009 Slava Pestov.
|
||||
! See http://factorcode.org/license.txt for BSD license.
|
||||
USING: bit-arrays classes.parser growable kernel parser
|
||||
vectors.functor vocabs.loader ;
|
||||
USING: bit-arrays classes growable kernel math parser
|
||||
prettyprint.custom sequences sequences.private vectors.functor
|
||||
vocabs.loader ;
|
||||
IN: bit-vectors
|
||||
|
||||
<< "bit-vector" create-class-in \ bit-array \ <bit-array> define-vector >>
|
||||
VECTORIZED: bit bit-array <bit-array>
|
||||
|
||||
SYNTAX: ?V{ \ } [ >bit-vector ] parse-literal ;
|
||||
SYNTAX: \?V{ \ \} [ >bit-vector ] parse-literal ;
|
||||
|
||||
M: bit-vector contract 2drop ;
|
||||
|
||||
|
|
|
@ -2,6 +2,5 @@ USING: bit-vectors kernel prettyprint.custom ;
|
|||
IN: bit-vectors.prettyprint
|
||||
|
||||
M: bit-vector >pprint-sequence ;
|
||||
M: bit-vector pprint-delims drop \ ?V{ \ } ;
|
||||
M: bit-vector pprint-delims drop \ \?V{ \ \} ;
|
||||
M: bit-vector pprint* pprint-object ;
|
||||
|
||||
|
|
|
@ -7,11 +7,11 @@ IN: bitstreams
|
|||
|
||||
TUPLE: widthed
|
||||
{ bits integer read-only }
|
||||
{ #bits integer read-only } ;
|
||||
{ n-bits integer read-only } ;
|
||||
|
||||
ERROR: invalid-widthed bits #bits ;
|
||||
ERROR: invalid-widthed bits n-bits ;
|
||||
|
||||
: check-widthed ( bits #bits -- bits #bits )
|
||||
: check-widthed ( bits n-bits -- bits n-bits )
|
||||
2dup {
|
||||
[ nip 0 < ]
|
||||
[ { [ nip 0 = ] [ drop 0 = not ] } 2&& ]
|
||||
|
@ -22,7 +22,7 @@ ERROR: invalid-widthed bits #bits ;
|
|||
]
|
||||
} 2|| [ invalid-widthed ] when ;
|
||||
|
||||
: <widthed> ( bits #bits -- widthed )
|
||||
: <widthed> ( bits n-bits -- widthed )
|
||||
check-widthed
|
||||
widthed boa ;
|
||||
|
||||
|
@ -88,20 +88,20 @@ GENERIC: poke ( value n bitstream -- )
|
|||
ERROR: not-enough-widthed-bits widthed n ;
|
||||
|
||||
: check-widthed-bits ( widthed n -- widthed n )
|
||||
2dup { [ nip 0 < ] [ [ #bits>> ] dip < ] } 2||
|
||||
2dup { [ nip 0 < ] [ [ n-bits>> ] dip < ] } 2||
|
||||
[ not-enough-widthed-bits ] when ;
|
||||
|
||||
: widthed-bits ( widthed n -- bits )
|
||||
check-widthed-bits
|
||||
[ [ bits>> ] [ #bits>> ] bi ] dip
|
||||
[ [ bits>> ] [ n-bits>> ] bi ] dip
|
||||
[ - neg shift ] keep <widthed> ;
|
||||
|
||||
: split-widthed ( widthed n -- widthed1 widthed2 )
|
||||
2dup [ #bits>> ] dip < [
|
||||
2dup [ n-bits>> ] dip < [
|
||||
drop zero-widthed
|
||||
] [
|
||||
[ widthed-bits ]
|
||||
[ [ [ bits>> ] [ #bits>> ] bi ] dip - [ bits ] keep <widthed> ] 2bi
|
||||
[ [ [ bits>> ] [ n-bits>> ] bi ] dip - [ bits ] keep <widthed> ] 2bi
|
||||
] if ;
|
||||
|
||||
: widthed>bytes ( widthed -- bytes widthed )
|
||||
|
@ -110,20 +110,20 @@ ERROR: not-enough-widthed-bits widthed n ;
|
|||
|
||||
:: |widthed ( widthed1 widthed2 -- widthed3 )
|
||||
widthed1 bits>> :> bits1
|
||||
widthed1 #bits>> :> #bits1
|
||||
widthed1 n-bits>> :> n-bits1
|
||||
widthed2 bits>> :> bits2
|
||||
widthed2 #bits>> :> #bits2
|
||||
bits1 #bits2 shift bits2 bitor
|
||||
#bits1 #bits2 + <widthed> ;
|
||||
widthed2 n-bits>> :> n-bits2
|
||||
bits1 n-bits2 shift bits2 bitor
|
||||
n-bits1 n-bits2 + <widthed> ;
|
||||
|
||||
PRIVATE>
|
||||
|
||||
M:: lsb0-bit-writer poke ( value n bs -- )
|
||||
value n <widthed> :> widthed
|
||||
widthed
|
||||
bs widthed>> #bits>> 8 swap - split-widthed :> ( byte remainder )
|
||||
bs widthed>> n-bits>> 8 swap - split-widthed :> ( byte remainder )
|
||||
byte bs widthed>> |widthed :> new-byte
|
||||
new-byte #bits>> 8 = [
|
||||
new-byte n-bits>> 8 = [
|
||||
new-byte bits>> bs bytes>> push
|
||||
zero-widthed bs widthed<<
|
||||
remainder widthed>bytes
|
||||
|
@ -139,7 +139,7 @@ M:: lsb0-bit-writer poke ( value n bs -- )
|
|||
|
||||
ERROR: not-enough-bits n bit-reader ;
|
||||
|
||||
: #bits>#bytes ( #bits -- #bytes )
|
||||
: n-bits>n-bytes ( n-bits -- n-bytes )
|
||||
8 /mod 0 = [ 1 + ] unless ; inline
|
||||
|
||||
:: subseq>bits-le ( bignum n bs -- bits )
|
||||
|
@ -151,9 +151,9 @@ ERROR: not-enough-bits n bit-reader ;
|
|||
neg shift n bits ;
|
||||
|
||||
:: adjust-bits ( n bs -- )
|
||||
n 8 /mod :> ( #bytes #bits )
|
||||
bs [ #bytes + ] change-byte-pos
|
||||
bit-pos>> #bits + dup 8 >= [
|
||||
n 8 /mod :> ( n-bytes n-bits )
|
||||
bs [ n-bytes + ] change-byte-pos
|
||||
bit-pos>> n-bits + dup 8 >= [
|
||||
8 - bs bit-pos<<
|
||||
bs [ 1 + ] change-byte-pos drop
|
||||
] [
|
||||
|
@ -162,7 +162,7 @@ ERROR: not-enough-bits n bit-reader ;
|
|||
|
||||
:: (peek) ( n bs endian> subseq-endian -- bits )
|
||||
n bs enough-bits? [ n bs not-enough-bits ] unless
|
||||
bs [ byte-pos>> ] [ bit-pos>> n + ] bi #bits>#bytes dupd +
|
||||
bs [ byte-pos>> ] [ bit-pos>> n + ] bi n-bits>n-bytes dupd +
|
||||
bs bytes>> subseq endian> execute( seq -- x )
|
||||
n bs subseq-endian execute( bignum n bs -- bits ) ;
|
||||
|
||||
|
@ -173,7 +173,7 @@ M: msb0-bit-reader peek ( n bs -- bits )
|
|||
\ be> \ subseq>bits-be (peek) ;
|
||||
|
||||
:: bit-writer-bytes ( writer -- bytes )
|
||||
writer widthed>> #bits>> :> n
|
||||
writer widthed>> n-bits>> :> n
|
||||
n 0 = [
|
||||
writer widthed>> bits>> 8 n - shift
|
||||
writer bytes>> push
|
||||
|
|
|
@ -4,7 +4,7 @@ USING: assocs bootstrap.image checksums checksums.md5
|
|||
http.client io.files kernel math.parser splitting urls ;
|
||||
IN: bootstrap.image.download
|
||||
|
||||
CONSTANT: url URL" http://downloads.factorcode.org/images/master/"
|
||||
CONSTANT: url url"http://downloads.factorcode.org/images/master/"
|
||||
|
||||
: download-checksums ( -- alist )
|
||||
url "checksums.txt" >url derive-url http-get nip
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
USING: accessors combinators namespaces sequences system vocabs
|
||||
;
|
||||
USING: accessors combinators namespaces sequences system vocabs ;
|
||||
IN: bootstrap.io
|
||||
|
||||
"bootstrap.compiler" require
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
! Copyright (C) 2004, 2008 Slava Pestov.
|
||||
! See http://factorcode.org/license.txt for BSD license.
|
||||
USING: command-line compiler.units continuations definitions io
|
||||
USING: combinators command-line compiler.units continuations definitions io
|
||||
io.pathnames kernel math math.parser memory namespaces parser
|
||||
parser.notes sequences sets splitting system
|
||||
vocabs vocabs.loader ;
|
||||
|
@ -13,8 +13,8 @@ SYMBOL: bootstrap-time
|
|||
: strip-encodings ( -- )
|
||||
os unix? [
|
||||
[
|
||||
P" resource:core/io/encodings/utf16/utf16.factor"
|
||||
P" resource:core/io/encodings/utf16n/utf16n.factor" [ forget ] bi@
|
||||
path"resource:core/io/encodings/utf16/utf16.factor"
|
||||
path"resource:core/io/encodings/utf16n/utf16n.factor" [ forget ] bi@
|
||||
"io.encodings.utf16"
|
||||
"io.encodings.utf16n" [ loaded-child-vocab-names [ forget-vocab ] each ] bi@
|
||||
] with-compilation-unit
|
||||
|
@ -75,6 +75,30 @@ CONSTANT: default-components
|
|||
|
||||
(command-line) parse-command-line
|
||||
|
||||
{
|
||||
{ [ os windows? ] [ "alien.libraries.windows" ] }
|
||||
{ [ os unix? ] [ "alien.libraries.unix" ] }
|
||||
} cond require
|
||||
|
||||
! { "hashtables.identity" "prettyprint" } "hashtables.identity.prettyprint" require-when
|
||||
! { "hashtables.identity" "mirrors" } "hashtables.identity.mirrors" require-when
|
||||
! { "hashtables.wrapped" "prettyprint" } "hashtables.wrapped.prettyprint" require-when
|
||||
|
||||
! { "typed" "prettyprint" } "typed.prettyprint" require-when
|
||||
! { "typed" "compiler.cfg.debugger" } "typed.debugger" require-when
|
||||
|
||||
{ "hashtables.identity" "prettyprint" } "hashtables.identity.prettyprint" require-when
|
||||
{ "hashtables.identity" "mirrors" } "hashtables.identity.mirrors" require-when
|
||||
{ "hashtables.wrapped" "prettyprint" } "hashtables.wrapped.prettyprint" require-when
|
||||
"summary" require
|
||||
"eval" require
|
||||
! "deques" require
|
||||
! "command-line.startup" require
|
||||
{ "locals" "prettyprint" } "locals.prettyprint" require-when
|
||||
{ "typed" "prettyprint" } "typed.prettyprint" require-when
|
||||
{ "typed" "compiler.cfg.debugger" } "typed.debugger" require-when
|
||||
"stack-checker.row-polymorphism" reload
|
||||
|
||||
! Set dll paths
|
||||
os windows? [ "windows" require ] when
|
||||
|
||||
|
|
|
@ -405,6 +405,9 @@ M: timestamp days-in-year year>> days-in-year ;
|
|||
: today ( -- timestamp )
|
||||
now midnight ; inline
|
||||
|
||||
: today? ( timestamp -- ? )
|
||||
now same-day? ; inline
|
||||
|
||||
: tomorrow ( -- timestamp )
|
||||
1 days hence midnight ; inline
|
||||
|
||||
|
@ -509,14 +512,14 @@ M: timestamp december clone 12 >>month ;
|
|||
: beginning-of-week ( timestamp -- new-timestamp )
|
||||
midnight sunday ;
|
||||
|
||||
: o'clock ( timestamp n -- new-timestamp )
|
||||
: o-clock ( timestamp n -- new-timestamp )
|
||||
[ midnight ] dip >>hour ;
|
||||
|
||||
: am ( timestamp n -- new-timestamp )
|
||||
0 12 [a,b] check-interval o'clock ;
|
||||
0 12 [a,b] check-interval o-clock ;
|
||||
|
||||
: pm ( timestamp n -- new-timestamp )
|
||||
0 12 [a,b] check-interval 12 + o'clock ;
|
||||
0 12 [a,b] check-interval 12 + o-clock ;
|
||||
|
||||
GENERIC: beginning-of-year ( object -- new-timestamp )
|
||||
M: timestamp beginning-of-year beginning-of-month 1 >>month ;
|
||||
|
|
|
@ -15,14 +15,14 @@ MACRO: formatted ( spec -- quot )
|
|||
} cond
|
||||
] map [ cleave ] curry ;
|
||||
|
||||
: pad-00 ( n -- str ) number>string 2 char: 0 pad-head ;
|
||||
|
||||
: formatted>string ( spec -- string )
|
||||
'[ _ formatted ] with-string-writer ; inline
|
||||
|
||||
: pad-00 ( n -- str ) number>string 2 CHAR: 0 pad-head ;
|
||||
: pad-0000 ( n -- str ) number>string 4 char: 0 pad-head ;
|
||||
|
||||
: pad-0000 ( n -- str ) number>string 4 CHAR: 0 pad-head ;
|
||||
|
||||
: pad-00000 ( n -- str ) number>string 5 CHAR: 0 pad-head ;
|
||||
: pad-00000 ( n -- str ) number>string 5 char: 0 pad-head ;
|
||||
|
||||
: write-00 ( n -- ) pad-00 write ;
|
||||
|
||||
|
|
|
@ -28,16 +28,16 @@ ERROR: invalid-timestamp-format ;
|
|||
: read-sp ( -- token ) " " read-token ;
|
||||
|
||||
: signed-gmt-offset ( dt ch -- dt' )
|
||||
{ { CHAR: + [ 1 ] } { CHAR: - [ -1 ] } } case time* ;
|
||||
{ { char: + [ 1 ] } { char: - [ -1 ] } } case time* ;
|
||||
|
||||
: read-rfc3339-gmt-offset ( ch -- dt )
|
||||
{
|
||||
{ f [ instant ] }
|
||||
{ CHAR: Z [ instant ] }
|
||||
{ char: Z [ instant ] }
|
||||
[
|
||||
[
|
||||
read-00 hours
|
||||
read1 { { CHAR: : [ read-00 ] } { f [ 0 ] } } case minutes
|
||||
read1 { { char: \: [ read-00 ] } { f [ 0 ] } } case minutes
|
||||
time+
|
||||
] dip signed-gmt-offset
|
||||
]
|
||||
|
@ -58,7 +58,7 @@ ERROR: invalid-timestamp-format ;
|
|||
read-ymd
|
||||
"Tt \t" expect
|
||||
read-hms
|
||||
read1 { { CHAR: . [ read-rfc3339-seconds ] } [ ] } case
|
||||
read1 { { char: . [ read-rfc3339-seconds ] } [ ] } case
|
||||
read-rfc3339-gmt-offset
|
||||
<timestamp> ;
|
||||
|
||||
|
@ -66,7 +66,7 @@ ERROR: invalid-timestamp-format ;
|
|||
[ (rfc3339>timestamp) ] with-string-reader ;
|
||||
|
||||
: parse-rfc822-military-offset ( string -- dt )
|
||||
first CHAR: A - {
|
||||
first char: A - {
|
||||
-1 -2 -3 -4 -5 -6 -7 -8 -9 f -10 -11 -12
|
||||
1 2 3 4 5 6 7 8 9 10 11 12 0
|
||||
} nth hours ;
|
||||
|
@ -94,18 +94,18 @@ CONSTANT: rfc822-named-zones H{
|
|||
]
|
||||
} cond ;
|
||||
|
||||
: read-hh:mm:ss ( -- hh mm ss )
|
||||
: read-hh-mm-ss ( -- hh mm ss )
|
||||
":" read-token checked-number
|
||||
":" read-token checked-number
|
||||
read-sp checked-number ;
|
||||
|
||||
: (rfc822>timestamp) ( -- timestamp )
|
||||
"," read-token day-abbreviations3 member? check-timestamp drop
|
||||
read1 CHAR: \s assert=
|
||||
read1 char: \s assert=
|
||||
read-sp checked-number
|
||||
read-sp month-abbreviations index 1 + check-timestamp
|
||||
read-sp checked-number spin
|
||||
read-hh:mm:ss
|
||||
read-hh-mm-ss
|
||||
" " read-until drop parse-rfc822-gmt-offset <timestamp> ;
|
||||
|
||||
: rfc822>timestamp ( str -- timestamp )
|
||||
|
@ -117,11 +117,11 @@ CONSTANT: rfc822-named-zones H{
|
|||
|
||||
: (cookie-string>timestamp-1) ( -- timestamp )
|
||||
"," read-token check-day-name
|
||||
read1 CHAR: \s assert=
|
||||
read1 char: \s assert=
|
||||
"-" read-token checked-number
|
||||
"-" read-token month-abbreviations index 1 + check-timestamp
|
||||
read-sp checked-number spin
|
||||
read-hh:mm:ss
|
||||
read-hh-mm-ss
|
||||
" " read-until drop parse-rfc822-gmt-offset <timestamp> ;
|
||||
|
||||
: cookie-string>timestamp-1 ( str -- timestamp )
|
||||
|
@ -131,7 +131,7 @@ CONSTANT: rfc822-named-zones H{
|
|||
read-sp check-day-name
|
||||
read-sp month-abbreviations index 1 + check-timestamp
|
||||
read-sp checked-number
|
||||
read-hh:mm:ss
|
||||
read-hh-mm-ss
|
||||
[ read-sp checked-number ] 5 ndip
|
||||
" " read-until drop parse-rfc822-gmt-offset <timestamp> ;
|
||||
|
||||
|
|
|
@ -18,7 +18,7 @@ IN: calendar.windows
|
|||
]
|
||||
} cleave \ SYSTEMTIME <struct-boa> ;
|
||||
|
||||
: SYSTEMTIME>timestamp ( SYSTEMTIME -- timestamp )
|
||||
: \SYSTEMTIME>timestamp ( SYSTEMTIME -- timestamp )
|
||||
{
|
||||
[ wYear>> ]
|
||||
[ wMonth>> ]
|
||||
|
@ -31,11 +31,11 @@ IN: calendar.windows
|
|||
M: windows gmt-offset
|
||||
TIME_ZONE_INFORMATION <struct>
|
||||
dup GetTimeZoneInformation {
|
||||
{ TIME_ZONE_ID_INVALID [ win32-error ] }
|
||||
{ TIME_ZONE_ID_INVALID [ win32-error-string throw ] }
|
||||
{ TIME_ZONE_ID_UNKNOWN [ Bias>> ] }
|
||||
{ TIME_ZONE_ID_STANDARD [ Bias>> ] }
|
||||
{ TIME_ZONE_ID_DAYLIGHT [ [ Bias>> ] [ DaylightBias>> ] bi + ] }
|
||||
} case neg 60 /mod 0 ;
|
||||
|
||||
M: windows gmt
|
||||
SYSTEMTIME <struct> [ GetSystemTime ] keep SYSTEMTIME>timestamp ;
|
||||
SYSTEMTIME <struct> [ GetSystemTime ] keep \SYSTEMTIME>timestamp ;
|
||||
|
|
|
@ -58,7 +58,6 @@ $nl
|
|||
$nl
|
||||
"Given the id from the snippet above, a remote node can put items in the channel (where 123456 is the id):"
|
||||
$nl
|
||||
{ $snippet "\"myhost.com\" 9001 <node> 123456 <remote-channel>\n\"hello\" over to" }
|
||||
;
|
||||
{ $snippet "\"myhost.com\" 9001 <node> 123456 <remote-channel>\n\"hello\" over to" } ;
|
||||
|
||||
ABOUT: "channels.remote"
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
USING: checksums checksums.adler-32 strings tools.test ;
|
||||
|
||||
{ 300286872 } [ "Wikipedia" adler-32 checksum-bytes ] unit-test
|
||||
{ 2679885283 } [ 10000 CHAR: a <string> adler-32 checksum-bytes ] unit-test
|
||||
{ 2679885283 } [ 10000 char: a <string> adler-32 checksum-bytes ] unit-test
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
USING: checksums checksums.bsd strings tools.test ;
|
||||
|
||||
{ 15816 } [ "Wikipedia" bsd checksum-bytes ] unit-test
|
||||
{ 47937 } [ 10000 CHAR: a <string> bsd checksum-bytes ] unit-test
|
||||
{ 47937 } [ 10000 char: a <string> bsd checksum-bytes ] unit-test
|
||||
|
|
|
@ -36,5 +36,5 @@ M: crc16 checksum-bytes
|
|||
|
||||
M: crc16 checksum-lines
|
||||
init-crc16
|
||||
[ [ (crc16) ] each CHAR: \n (crc16) ] each
|
||||
[ [ (crc16) ] each char: \n (crc16) ] each
|
||||
finish-crc16 ; inline
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
! Copyright (C) 2013 John Benediktsson
|
||||
! See http://factorcode.org/license.txt for BSD license
|
||||
|
||||
USING: checksums grouping io.binary kernel locals math sequences
|
||||
;
|
||||
USING: checksums grouping io.binary kernel locals math sequences ;
|
||||
|
||||
IN: checksums.fletcher
|
||||
|
||||
|
|
|
@ -64,7 +64,4 @@ USING: checksums checksums.ripemd strings tools.test ;
|
|||
0x69 0x7b 0xdb 0xe1 0x6d
|
||||
0x37 0xf9 0x7f 0x68 0xf0
|
||||
0x83 0x25 0xdc 0x15 0x28
|
||||
} } [ 1000000 CHAR: a <string> ripemd-160 checksum-bytes ] unit-test
|
||||
|
||||
|
||||
|
||||
} } [ 1000000 char: a <string> ripemd-160 checksum-bytes ] unit-test
|
||||
|
|
|
@ -5,7 +5,7 @@ IN: checksums.sha.tests
|
|||
|
||||
{ "a9993e364706816aba3e25717850c26c9cd0d89d" } [ "abc" sha1 checksum-bytes bytes>hex-string ] unit-test
|
||||
{ "84983e441c3bd26ebaae4aa1f95129e5e54670f1" } [ "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq" sha1 checksum-bytes bytes>hex-string ] unit-test
|
||||
! [ "34aa973cd4c4daa4f61eeb2bdbad27316534016f" ] [ 1000000 CHAR: a fill string>sha1str ] unit-test ! takes a long time...
|
||||
! [ "34aa973cd4c4daa4f61eeb2bdbad27316534016f" ] [ 1000000 char: a fill string>sha1str ] unit-test ! takes a long time...
|
||||
{ "dea356a2cddd90c7a7ecedc5ebb563934f460452" } [ "0123456701234567012345670123456701234567012345670123456701234567"
|
||||
10 swap <array> concat sha1 checksum-bytes bytes>hex-string ] unit-test
|
||||
|
||||
|
|
|
@ -7,10 +7,10 @@ IN: circular.tests
|
|||
{ 0 } [ { 0 1 2 3 4 } <circular> 0 swap virtual@ drop ] unit-test
|
||||
{ 2 } [ { 0 1 2 3 4 } <circular> 2 swap virtual@ drop ] unit-test
|
||||
|
||||
{ CHAR: t } [ "test" <circular> 0 swap nth ] unit-test
|
||||
{ char: t } [ "test" <circular> 0 swap nth ] unit-test
|
||||
{ "test" } [ "test" <circular> >string ] unit-test
|
||||
|
||||
{ CHAR: e } [ "test" <circular> 5 swap nth-unsafe ] unit-test
|
||||
{ char: e } [ "test" <circular> 5 swap nth-unsafe ] unit-test
|
||||
|
||||
{ [ 1 2 3 ] } [ { 1 2 3 } <circular> [ ] like ] unit-test
|
||||
{ [ 2 3 1 ] } [ { 1 2 3 } <circular> [ rotate-circular ] keep [ ] like ] unit-test
|
||||
|
@ -19,9 +19,9 @@ IN: circular.tests
|
|||
{ [ 3 1 2 ] } [ { 1 2 3 } <circular> 1 over change-circular-start 1 over change-circular-start [ ] like ] unit-test
|
||||
{ [ 3 1 2 ] } [ { 1 2 3 } <circular> -100 over change-circular-start [ ] like ] unit-test
|
||||
|
||||
{ "fob" } [ "foo" <circular> CHAR: b 2 pick set-nth >string ] unit-test
|
||||
{ "boo" } [ "foo" <circular> CHAR: b 3 pick set-nth-unsafe >string ] unit-test
|
||||
{ "ornact" } [ "factor" <circular> 4 over change-circular-start CHAR: n 2 pick set-nth >string ] unit-test
|
||||
{ "fob" } [ "foo" <circular> char: b 2 pick set-nth >string ] unit-test
|
||||
{ "boo" } [ "foo" <circular> char: b 3 pick set-nth-unsafe >string ] unit-test
|
||||
{ "ornact" } [ "factor" <circular> 4 over change-circular-start char: n 2 pick set-nth >string ] unit-test
|
||||
|
||||
{ "bcd" } [ 3 <circular-string> "abcd" [ over circular-push ] each >string ] unit-test
|
||||
|
||||
|
@ -29,7 +29,7 @@ IN: circular.tests
|
|||
|
||||
! This no longer fails
|
||||
! [ "test" <circular> 5 swap nth ] must-fail
|
||||
! [ "foo" <circular> CHAR: b 3 rot set-nth ] must-fail
|
||||
! [ "foo" <circular> char: b 3 rot set-nth ] must-fail
|
||||
|
||||
{ { } } [ 3 <growing-circular> >array ] unit-test
|
||||
{ { 1 2 } } [
|
||||
|
|
|
@ -13,36 +13,36 @@ IN: classes.struct.prettyprint
|
|||
: struct-definer-word ( class -- word )
|
||||
struct-slots
|
||||
{
|
||||
{ [ dup [ packed?>> ] all? ] [ drop \ PACKED-STRUCT: ] }
|
||||
{ [ dup length 1 <= ] [ drop \ STRUCT: ] }
|
||||
{ [ dup [ offset>> 0 = ] all? ] [ drop \ UNION-STRUCT: ] }
|
||||
[ drop \ STRUCT: ]
|
||||
{ [ dup [ packed?>> ] all? ] [ drop \ \PACKED-STRUCT: ] }
|
||||
{ [ dup length 1 <= ] [ drop \ \STRUCT: ] }
|
||||
{ [ dup [ offset>> 0 = ] all? ] [ drop \ \UNION-STRUCT: ] }
|
||||
[ drop \ \STRUCT: ]
|
||||
} cond ;
|
||||
|
||||
: struct>assoc ( struct -- assoc )
|
||||
[ class-of struct-slots ] [ struct-slot-values ] bi zip ;
|
||||
|
||||
: pprint-struct-slot ( slot -- )
|
||||
<flow \ { pprint-word
|
||||
<flow \ \{ pprint-word
|
||||
f <inset {
|
||||
[ name>> text ]
|
||||
[ type>> pprint-c-type ]
|
||||
[ read-only>> [ \ read-only pprint-word ] when ]
|
||||
[ initial>> [ \ initial: pprint-word pprint* ] when* ]
|
||||
[ initial>> [ \ \initial: pprint-word pprint* ] when* ]
|
||||
[
|
||||
dup struct-bit-slot-spec?
|
||||
[ \ bits: pprint-word bits>> pprint* ]
|
||||
[ \ \bits: pprint-word bits>> pprint* ]
|
||||
[ drop ] if
|
||||
]
|
||||
} cleave block>
|
||||
\ } pprint-word block> ;
|
||||
\ \} pprint-word block> ;
|
||||
|
||||
: pprint-struct ( struct -- )
|
||||
[
|
||||
[ \ S{ ] dip
|
||||
[ \ \S{ ] dip
|
||||
[ class-of ]
|
||||
[ struct>assoc [ [ name>> ] dip ] assoc-map ] bi
|
||||
\ } (pprint-tuple)
|
||||
\ \} (pprint-tuple)
|
||||
] ?pprint-tuple ;
|
||||
|
||||
: pprint-struct-pointer ( struct -- )
|
||||
|
@ -53,10 +53,10 @@ PRIVATE>
|
|||
M: struct-class see-class*
|
||||
<colon dup struct-definer-word pprint-word dup pprint-word
|
||||
<block struct-slots [ pprint-struct-slot ] each
|
||||
block> pprint-; block> ;
|
||||
block> pprint-semi block> ;
|
||||
|
||||
M: struct pprint-delims
|
||||
drop \ S{ \ } ;
|
||||
drop \ \S{ \ \} ;
|
||||
|
||||
M: struct >pprint-sequence
|
||||
[ class-of ] [ struct-slot-values ] bi class-slot-sequence ;
|
||||
|
|
|
@ -28,10 +28,10 @@ HELP: <struct>
|
|||
|
||||
{ <struct> <struct-boa> malloc-struct memory>struct } related-words
|
||||
|
||||
HELP: STRUCT:
|
||||
HELP: \STRUCT:
|
||||
{ $syntax "STRUCT: class { slot type } { slot type } ... ;" }
|
||||
{ $values { "class" "a new " { $link struct } " class to define" } { "slots" "a list of slot specifiers" } }
|
||||
{ $description "Defines a new " { $link struct } " type. The syntax is nearly identical to " { $link POSTPONE: TUPLE: } "; however, there are some additional restrictions on struct types:"
|
||||
{ $description "Defines a new " { $link struct } " type. The syntax is nearly identical to " { $link postpone: \TUPLE: } "; however, there are some additional restrictions on struct types:"
|
||||
{ $list
|
||||
{ "Struct classes cannot have a superclass defined." }
|
||||
{ "The slots of a struct must all have a type declared. The type must be a C type." }
|
||||
|
@ -39,45 +39,45 @@ HELP: STRUCT:
|
|||
}
|
||||
"Additionally, structs may use bit fields. A slot specifier may use the syntax " { $snippet "bits: n" } " to specify that the bit width of the slot is " { $snippet "n" } ". Bit width may be specified on signed or unsigned integer slots. The layout of bit fields is not guaranteed to match that of any particular C compiler." } ;
|
||||
|
||||
HELP: S{
|
||||
HELP: \S{
|
||||
{ $syntax "S{ class slots... }" }
|
||||
{ $values { "class" "a " { $link struct } " class word" } { "slots" "slot values" } }
|
||||
{ $description "Marks the beginning of a literal struct. The syntax is identical to tuple literal syntax with " { $link POSTPONE: T{ } { $snippet " }" } "; either the assoc syntax (that is, " { $snippet "S{ class { slot value } { slot value } ... }" } ") or the simple syntax (" { $snippet "S{ class f value value ... }" } ") can be used." } ;
|
||||
{ $description "Marks the beginning of a literal struct. The syntax is identical to tuple literal syntax with " { $link postpone: \T{ } { $snippet " }" } "; either the assoc syntax (that is, " { $snippet "S{ class { slot value } { slot value } ... }" } ") or the simple syntax (" { $snippet "S{ class f value value ... }" } ") can be used." } ;
|
||||
|
||||
HELP: S@
|
||||
{ $syntax "S@ class alien" }
|
||||
{ $values { "class" "a " { $link struct } " class word" } { "alien" "a literal alien" } }
|
||||
{ $description "Marks the beginning of a literal struct at a specific C address. The prettyprinter uses this syntax when the memory backing a struct object is invalid. This syntax should not generally be used in source code." } ;
|
||||
|
||||
{ POSTPONE: S{ POSTPONE: S@ } related-words
|
||||
{ postpone: \S{ postpone: S@ } related-words
|
||||
|
||||
HELP: UNION-STRUCT:
|
||||
HELP: \UNION-STRUCT:
|
||||
{ $syntax "UNION-STRUCT: class { slot type } { slot type } ... ;" }
|
||||
{ $values { "class" "a new " { $link struct } " class to define" } { "slots" "a list of slot specifiers" } }
|
||||
{ $description "Defines a new " { $link struct } " type where all of the slots share the same storage. See " { $link POSTPONE: STRUCT: } " for details on the syntax." } ;
|
||||
{ $description "Defines a new " { $link struct } " type where all of the slots share the same storage. See " { $link postpone: \STRUCT: } " for details on the syntax." } ;
|
||||
|
||||
HELP: PACKED-STRUCT:
|
||||
HELP: \PACKED-STRUCT:
|
||||
{ $syntax "PACKED-STRUCT: class { slot type } { slot type } ... ;" }
|
||||
{ $values { "class" "a new " { $link struct } " class to define" } { "slots" "a list of slot specifiers" } }
|
||||
{ $description "Defines a new " { $link struct } " type with no alignment padding between slots or at the end. In all other respects, behaves like " { $link POSTPONE: STRUCT: } "." } ;
|
||||
{ $description "Defines a new " { $link struct } " type with no alignment padding between slots or at the end. In all other respects, behaves like " { $link postpone: \STRUCT: } "." } ;
|
||||
|
||||
HELP: define-struct-class
|
||||
{ $values
|
||||
{ "class" class } { "slots" "a sequence of " { $link struct-slot-spec } "s" }
|
||||
}
|
||||
{ $description "Defines a new " { $link struct } " class. This is the runtime equivalent of the " { $link POSTPONE: STRUCT: } " syntax." } ;
|
||||
{ $description "Defines a new " { $link struct } " class. This is the runtime equivalent of the " { $link postpone: \STRUCT: } " syntax." } ;
|
||||
|
||||
HELP: define-packed-struct-class
|
||||
{ $values
|
||||
{ "class" class } { "slots" "a sequence of " { $link struct-slot-spec } "s" }
|
||||
}
|
||||
{ $description "Defines a new " { $link struct } " class. This is the runtime equivalent of the " { $link POSTPONE: PACKED-STRUCT: } " syntax." } ;
|
||||
{ $description "Defines a new " { $link struct } " class. This is the runtime equivalent of the " { $link postpone: \PACKED-STRUCT: } " syntax." } ;
|
||||
|
||||
HELP: define-union-struct-class
|
||||
{ $values
|
||||
{ "class" class } { "slots" "a sequence of " { $link struct-slot-spec } "s" }
|
||||
}
|
||||
{ $description "Defines a new " { $link struct } " class where all of the slots share the same storage. This is the runtime equivalent of the " { $link POSTPONE: UNION-STRUCT: } " syntax." } ;
|
||||
{ $description "Defines a new " { $link struct } " class where all of the slots share the same storage. This is the runtime equivalent of the " { $link postpone: \UNION-STRUCT: } " syntax." } ;
|
||||
|
||||
HELP: malloc-struct
|
||||
{ $values
|
||||
|
@ -111,7 +111,7 @@ HELP: read-struct
|
|||
HELP: struct
|
||||
{ $class-description "The parent class of all struct types." } ;
|
||||
|
||||
{ struct POSTPONE: STRUCT: POSTPONE: UNION-STRUCT: } related-words
|
||||
{ struct postpone: \STRUCT: postpone: \UNION-STRUCT: } related-words
|
||||
|
||||
HELP: struct-class
|
||||
{ $class-description "The metaclass of all " { $link struct } " classes." } ;
|
||||
|
@ -145,10 +145,10 @@ ARTICLE: "classes.struct.examples" "Struct class examples"
|
|||
} ;
|
||||
|
||||
ARTICLE: "classes.struct.define" "Defining struct classes"
|
||||
"Struct classes are defined using a syntax similar to the " { $link POSTPONE: TUPLE: } " syntax for defining tuple classes:"
|
||||
{ $subsections POSTPONE: STRUCT: POSTPONE: PACKED-STRUCT: }
|
||||
"Struct classes are defined using a syntax similar to the " { $link postpone: \TUPLE: } " syntax for defining tuple classes:"
|
||||
{ $subsections postpone: \STRUCT: postpone: \PACKED-STRUCT: }
|
||||
"Union structs are also supported, which behave like structs but share the same memory for all the slots."
|
||||
{ $subsections POSTPONE: UNION-STRUCT: } ;
|
||||
{ $subsections postpone: \UNION-STRUCT: } ;
|
||||
|
||||
ARTICLE: "classes.struct.create" "Creating instances of structs"
|
||||
"Structs can be allocated with " { $link new } "- and " { $link boa } "-like constructor words. Additional words are provided for building structs from C memory and from existing buffers:"
|
||||
|
@ -163,8 +163,8 @@ ARTICLE: "classes.struct.create" "Creating instances of structs"
|
|||
(struct)
|
||||
(malloc-struct)
|
||||
}
|
||||
"Structs have literal syntax, similar to " { $link POSTPONE: T{ } " for tuples:"
|
||||
{ $subsections POSTPONE: S{ } ;
|
||||
"Structs have literal syntax, similar to " { $link postpone: \T{ } " for tuples:"
|
||||
{ $subsections postpone: \S{ } ;
|
||||
|
||||
ARTICLE: "classes.struct.c" "Passing structs to C functions"
|
||||
"Structs can be passed and returned by value, or by reference."
|
||||
|
|
|
@ -133,7 +133,7 @@ STRUCT: struct-test-bar
|
|||
[ make-mirror clear-assoc ] keep
|
||||
] unit-test
|
||||
|
||||
{ POSTPONE: STRUCT: }
|
||||
{ postpone: \STRUCT: }
|
||||
[ struct-test-foo struct-definer-word ] unit-test
|
||||
|
||||
UNION-STRUCT: struct-test-float-and-bits
|
||||
|
@ -145,7 +145,7 @@ UNION-STRUCT: struct-test-float-and-bits
|
|||
|
||||
{ 123 } [ [ struct-test-foo malloc-struct &free y>> ] with-destructors ] unit-test
|
||||
|
||||
{ POSTPONE: UNION-STRUCT: }
|
||||
{ postpone: \UNION-STRUCT: }
|
||||
[ struct-test-float-and-bits struct-definer-word ] unit-test
|
||||
|
||||
STRUCT: struct-test-string-ptr
|
||||
|
@ -325,11 +325,11 @@ STRUCT: clone-test-struct { x int } { y char[3] } ;
|
|||
] with-destructors
|
||||
] unit-test
|
||||
|
||||
STRUCT: struct-that's-a-word { x int } ;
|
||||
STRUCT: struct-that-is-a-word { x int } ;
|
||||
|
||||
: struct-that's-a-word ( -- ) "OOPS" throw ;
|
||||
: struct-that-is-a-word ( -- ) "OOPS" throw ;
|
||||
|
||||
{ -77 } [ S{ struct-that's-a-word { x -77 } } clone x>> ] unit-test
|
||||
{ -77 } [ S{ struct-that-is-a-word { x -77 } } clone x>> ] unit-test
|
||||
|
||||
! Interactive parsing of struct slot definitions
|
||||
[
|
||||
|
@ -492,7 +492,7 @@ PACKED-STRUCT: packed-struct-test
|
|||
{ 10 } [ "g" packed-struct-test offset-of ] unit-test
|
||||
{ 11 } [ "h" packed-struct-test offset-of ] unit-test
|
||||
|
||||
{ POSTPONE: PACKED-STRUCT: }
|
||||
{ postpone: \PACKED-STRUCT: }
|
||||
[ packed-struct-test struct-definer-word ] unit-test
|
||||
|
||||
STRUCT: struct-1 { a c:int } ;
|
||||
|
|
|
@ -144,7 +144,7 @@ M: struct-class initial-value* <struct> t ; inline
|
|||
GENERIC: struct-slot-values ( struct -- sequence )
|
||||
|
||||
M: struct-class reader-quot
|
||||
dup type>> array? [ dup type>> first define-array-vocab drop ] when
|
||||
dup type>> array? [ dup type>> first underlying-type define-specialized-array ] when
|
||||
nip '[ _ read-struct-slot ] ;
|
||||
|
||||
M: struct-class writer-quot
|
||||
|
@ -330,7 +330,7 @@ M: struct-class reset-class
|
|||
[ call-next-method ]
|
||||
} cleave ;
|
||||
|
||||
SYMBOL: bits:
|
||||
SYMBOL: \bits:
|
||||
|
||||
<PRIVATE
|
||||
|
||||
|
@ -364,7 +364,7 @@ PRIVATE>
|
|||
|
||||
<PRIVATE
|
||||
: parse-struct-slot ( -- slot )
|
||||
scan-token scan-c-type \ } parse-until <struct-slot-spec> ;
|
||||
scan-token scan-c-type \ \} parse-until <struct-slot-spec> ;
|
||||
|
||||
: parse-struct-slots ( slots -- slots' more? )
|
||||
scan-token {
|
||||
|
@ -378,16 +378,16 @@ PRIVATE>
|
|||
dup [ name>> ] map check-duplicate-slots ;
|
||||
PRIVATE>
|
||||
|
||||
SYNTAX: STRUCT:
|
||||
SYNTAX: \STRUCT:
|
||||
parse-struct-definition define-struct-class ;
|
||||
|
||||
SYNTAX: PACKED-STRUCT:
|
||||
SYNTAX: \PACKED-STRUCT:
|
||||
parse-struct-definition define-packed-struct-class ;
|
||||
|
||||
SYNTAX: UNION-STRUCT:
|
||||
SYNTAX: \UNION-STRUCT:
|
||||
parse-struct-definition define-union-struct-class ;
|
||||
|
||||
SYNTAX: S{
|
||||
SYNTAX: \S{
|
||||
scan-word dup struct-slots parse-tuple-literal-slots suffix! ;
|
||||
|
||||
SYNTAX: S@
|
||||
|
@ -397,10 +397,10 @@ SYNTAX: S@
|
|||
|
||||
<PRIVATE
|
||||
: scan-c-type* ( -- c-type/param )
|
||||
scan-token dup "{" = [ drop \ } parse-until >array ] [ search ] if ;
|
||||
scan-token dup "{" = [ drop \ \} parse-until >array ] [ search ] if ;
|
||||
|
||||
: parse-struct-slot* ( accum -- accum )
|
||||
scan-string-param scan-c-type* \ } parse-until
|
||||
scan-string-param scan-c-type* \ \} parse-until
|
||||
[ <struct-slot-spec> suffix! ] 3curry append! ;
|
||||
|
||||
: parse-struct-slots* ( accum -- accum more? )
|
||||
|
@ -412,7 +412,7 @@ SYNTAX: S@
|
|||
|
||||
PRIVATE>
|
||||
|
||||
FUNCTOR-SYNTAX: STRUCT:
|
||||
FUNCTOR-SYNTAX: \STRUCT:
|
||||
scan-param suffix!
|
||||
[ 8 <vector> ] append!
|
||||
[ parse-struct-slots* ] [ ] while
|
||||
|
|
|
@ -7,7 +7,7 @@ HELP: run-apple-script
|
|||
{ $description "Runs the provided uncompiled AppleScript code." }
|
||||
{ $notes "Currently, return values are unsupported." } ;
|
||||
|
||||
HELP: APPLESCRIPT:
|
||||
HELP: \APPLESCRIPT:
|
||||
{ $syntax "APPLESCRIPT: word [[ ...applescript string... ]] " }
|
||||
{ $values { "word" "a new word to define" } { "...applescript string..." "AppleScript source text" } }
|
||||
{ $description "Defines a word that when called will run the provided uncompiled AppleScript. The word has stack effect " { $snippet "( -- )" } " due to return values being currently unsupported." } ;
|
||||
|
|
|
@ -7,10 +7,10 @@ multiline words ;
|
|||
IN: cocoa.apple-script
|
||||
|
||||
: run-apple-script ( str -- )
|
||||
[ NSAppleScript -> alloc ] dip
|
||||
<NSString> -> initWithSource: -> autorelease
|
||||
f -> executeAndReturnError: drop ;
|
||||
[ NSAppleScript send: alloc ] dip
|
||||
<NSString> send: \initWithSource: send: autorelease
|
||||
f send: \executeAndReturnError: drop ;
|
||||
|
||||
SYNTAX: APPLESCRIPT:
|
||||
SYNTAX: \APPLESCRIPT:
|
||||
scan-new-word scan-object
|
||||
[ run-apple-script ] curry ( -- ) define-declared ;
|
||||
|
|
|
@ -6,7 +6,7 @@ HELP: <NSString>
|
|||
{ $values { "str" string } { "alien" alien } }
|
||||
{ $description "Allocates an autoreleased " { $snippet "CFString" } "." } ;
|
||||
|
||||
{ <NSString> <CFString> CF>string } related-words
|
||||
{ <NSString> <CFString> CFString>string } related-words
|
||||
|
||||
HELP: with-autorelease-pool
|
||||
{ $values { "quot" quotation } }
|
||||
|
|
|
@ -4,16 +4,16 @@ USING: alien.c-types alien.syntax cocoa cocoa.classes
|
|||
cocoa.runtime core-foundation.strings kernel sequences ;
|
||||
IN: cocoa.application
|
||||
|
||||
: <NSString> ( str -- alien ) <CFString> -> autorelease ;
|
||||
: <NSString> ( str -- alien ) <CFString> send: autorelease ;
|
||||
|
||||
CONSTANT: NSApplicationDelegateReplySuccess 0
|
||||
CONSTANT: NSApplicationDelegateReplyCancel 1
|
||||
CONSTANT: NSApplicationDelegateReplyFailure 2
|
||||
|
||||
: with-autorelease-pool ( quot -- )
|
||||
NSAutoreleasePool -> new [ call ] [ -> release ] bi* ; inline
|
||||
NSAutoreleasePool send: new [ call ] [ send: release ] bi* ; inline
|
||||
|
||||
: NSApp ( -- app ) NSApplication -> sharedApplication ;
|
||||
: NSApp ( -- app ) NSApplication send: sharedApplication ;
|
||||
|
||||
CONSTANT: NSAnyEventMask 0xffffffff
|
||||
|
||||
|
@ -24,24 +24,24 @@ FUNCTION: void NSBeep ( )
|
|||
|
||||
: add-observer ( observer selector name object -- )
|
||||
[
|
||||
[ NSNotificationCenter -> defaultCenter ] 2dip
|
||||
[ NSNotificationCenter send: defaultCenter ] 2dip
|
||||
sel_registerName
|
||||
] 2dip -> addObserver:selector:name:object: ;
|
||||
] 2dip send: \addObserver:selector:name:object: ;
|
||||
|
||||
: remove-observer ( observer -- )
|
||||
[ NSNotificationCenter -> defaultCenter ] dip
|
||||
-> removeObserver: ;
|
||||
[ NSNotificationCenter send: defaultCenter ] dip
|
||||
send: \removeObserver: ;
|
||||
|
||||
: cocoa-app ( quot -- )
|
||||
[ call NSApp -> run ] with-cocoa ; inline
|
||||
[ call NSApp send: run ] with-cocoa ; inline
|
||||
|
||||
: install-delegate ( receiver delegate -- )
|
||||
-> alloc -> init -> setDelegate: ;
|
||||
send: alloc send: init send: \setDelegate: ;
|
||||
|
||||
: running.app? ( -- ? )
|
||||
! Test if we're running a .app.
|
||||
".app"
|
||||
NSBundle -> mainBundle -> bundlePath CF>string
|
||||
NSBundle send: mainBundle send: bundlePath CFString>string
|
||||
subseq? ;
|
||||
|
||||
: assert.app ( message -- )
|
||||
|
|
|
@ -2,36 +2,36 @@ USING: cocoa.messages help.markup help.syntax strings
|
|||
alien core-foundation ;
|
||||
IN: cocoa
|
||||
|
||||
HELP: ->
|
||||
{ $syntax "-> selector" }
|
||||
HELP: \send:
|
||||
{ $syntax "send: selector" }
|
||||
{ $values { "selector" "an Objective C method name" } }
|
||||
{ $description "A sugared form of the following:" }
|
||||
{ $code "\"selector\" send" } ;
|
||||
|
||||
HELP: SUPER->
|
||||
{ $syntax "-> selector" }
|
||||
HELP: \super:
|
||||
{ $syntax "super: selector" }
|
||||
{ $values { "selector" "an Objective C method name" } }
|
||||
{ $description "A sugared form of the following:" }
|
||||
{ $code "\"selector\" send-super" } ;
|
||||
|
||||
{ send super-send POSTPONE: -> POSTPONE: SUPER-> } related-words
|
||||
{ send super-send postpone: \send: postpone: \super: } related-words
|
||||
|
||||
HELP: IMPORT:
|
||||
HELP: \IMPORT:
|
||||
{ $syntax "IMPORT: name" }
|
||||
{ $description "Makes an Objective C class available for use." }
|
||||
{ $examples
|
||||
{ $code "IMPORT: QTMovie" "QTMovie \"My Movie.mov\" <NSString> f -> movieWithFile:error:" }
|
||||
{ $code "IMPORT: QTMovie" "QTMovie \"My Movie.mov\" <NSString> f send: \\movieWithFile:error:" }
|
||||
} ;
|
||||
|
||||
ARTICLE: "objc-calling" "Calling Objective C code"
|
||||
"Before an Objective C class can be used, it must be imported; by default, a small set of common classes are imported automatically, but additional classes can be imported as needed."
|
||||
{ $subsections POSTPONE: IMPORT: }
|
||||
{ $subsections postpone: \IMPORT: }
|
||||
"Every imported Objective C class has as corresponding class word in the " { $vocab-link "cocoa.classes" } " vocabulary. Class words push the class object in the stack, allowing class methods to be invoked."
|
||||
$nl
|
||||
"Messages can be sent to classes and instances using a pair of parsing words:"
|
||||
{ $subsections
|
||||
POSTPONE: ->
|
||||
POSTPONE: SUPER->
|
||||
postpone: \send:
|
||||
postpone: \super:
|
||||
}
|
||||
"These parsing words are actually syntax sugar for a pair of ordinary words; they can be used instead of the parsing words if the selector name is dynamically computed:"
|
||||
{ $subsections
|
||||
|
|
|
@ -4,15 +4,15 @@ namespaces tools.test ;
|
|||
IN: cocoa.tests
|
||||
|
||||
<CLASS: Foo < NSObject
|
||||
METHOD: void foo: NSRect rect [
|
||||
COCOA-METHOD: void foo: NSRect rect [
|
||||
gc rect "x" set
|
||||
] ;
|
||||
;CLASS>
|
||||
|
||||
: test-foo ( -- )
|
||||
Foo -> alloc -> init
|
||||
dup 1.0 2.0 101.0 102.0 <CGRect> -> foo:
|
||||
-> release ;
|
||||
Foo send: alloc send: init
|
||||
dup 1.0 2.0 101.0 102.0 <CGRect> send: \foo:
|
||||
send: release ;
|
||||
|
||||
{ } [ test-foo ] unit-test
|
||||
|
||||
|
@ -22,14 +22,14 @@ IN: cocoa.tests
|
|||
{ 102.0 } [ "x" get CGRect-h ] unit-test
|
||||
|
||||
<CLASS: Bar < NSObject
|
||||
METHOD: NSRect bar [ test-foo "x" get ] ;
|
||||
COCOA-METHOD: NSRect bar [ test-foo "x" get ] ;
|
||||
;CLASS>
|
||||
|
||||
{ } [
|
||||
Bar [
|
||||
-> alloc -> init
|
||||
dup -> bar "x" set
|
||||
-> release
|
||||
send: alloc send: init
|
||||
dup send: bar "x" set
|
||||
send: release
|
||||
] compile-call
|
||||
] unit-test
|
||||
|
||||
|
@ -40,15 +40,15 @@ IN: cocoa.tests
|
|||
|
||||
! Make sure that we can add methods
|
||||
<CLASS: Bar < NSObject
|
||||
METHOD: NSRect bar [ test-foo "x" get ] ;
|
||||
COCOA-METHOD: NSRect bar [ test-foo "x" get ] ;
|
||||
|
||||
METHOD: int babb: int x [ x sq ] ;
|
||||
COCOA-METHOD: int babb: int x [ x sq ] ;
|
||||
;CLASS>
|
||||
|
||||
{ 144 } [
|
||||
Bar [
|
||||
-> alloc -> init
|
||||
dup 12 -> babb:
|
||||
swap -> release
|
||||
send: alloc send: init
|
||||
dup 12 send: \babb:
|
||||
swap send: release
|
||||
] compile-call
|
||||
] unit-test
|
||||
|
|
|
@ -4,46 +4,41 @@ USING: assocs cocoa.messages compiler.units core-foundation.bundles
|
|||
hashtables init io kernel lexer namespaces sequences vocabs ;
|
||||
IN: cocoa
|
||||
|
||||
SYMBOL: sent-messages
|
||||
|
||||
sent-messages [ H{ } clone ] initialize
|
||||
INITIALIZED-SYMBOL: sent-messages [ H{ } clone ]
|
||||
|
||||
: remember-send ( selector -- )
|
||||
dup sent-messages get set-at ;
|
||||
|
||||
SYNTAX: ->
|
||||
scan-token dup remember-send
|
||||
SYNTAX: \send:
|
||||
scan-token unescape-token dup remember-send
|
||||
[ lookup-method suffix! ] [ suffix! ] bi \ send suffix! ;
|
||||
|
||||
SYNTAX: ?->
|
||||
SYNTAX: \?send:
|
||||
dup last cache-stubs
|
||||
scan-token dup remember-send
|
||||
scan-token unescape-token dup remember-send
|
||||
suffix! \ send suffix! ;
|
||||
|
||||
SYNTAX: SEL:
|
||||
scan-token dup remember-send
|
||||
<selector> suffix! \ cocoa.messages:selector suffix! ;
|
||||
SYNTAX: \selector:
|
||||
scan-token unescape-token
|
||||
[ remember-send ]
|
||||
[ <selector> suffix! \ cocoa.messages:selector suffix! ] bi ;
|
||||
|
||||
SYMBOL: super-sent-messages
|
||||
|
||||
super-sent-messages [ H{ } clone ] initialize
|
||||
INITIALIZED-SYMBOL: super-sent-messages [ H{ } clone ]
|
||||
|
||||
: remember-super-send ( selector -- )
|
||||
dup super-sent-messages get set-at ;
|
||||
|
||||
SYNTAX: SUPER->
|
||||
scan-token dup remember-super-send
|
||||
SYNTAX: \super:
|
||||
scan-token unescape-token dup remember-super-send
|
||||
[ lookup-method suffix! ] [ suffix! ] bi \ super-send suffix! ;
|
||||
|
||||
SYMBOL: frameworks
|
||||
|
||||
frameworks [ V{ } clone ] initialize
|
||||
INITIALIZED-SYMBOL: frameworks [ V{ } clone ]
|
||||
|
||||
[ frameworks get [ load-framework ] each ] "cocoa" add-startup-hook
|
||||
|
||||
SYNTAX: FRAMEWORK: scan-token [ load-framework ] [ frameworks get push ] bi ;
|
||||
SYNTAX: \FRAMEWORK: scan-token [ load-framework ] [ frameworks get push ] bi ;
|
||||
|
||||
SYNTAX: IMPORT: scan-token [ ] import-objc-class ;
|
||||
SYNTAX: \IMPORT: scan-token [ ] import-objc-class ;
|
||||
|
||||
"Importing Cocoa classes..." print
|
||||
|
||||
|
|
|
@ -5,27 +5,27 @@ core-foundation.strings kernel splitting ;
|
|||
IN: cocoa.dialogs
|
||||
|
||||
: <NSOpenPanel> ( -- panel )
|
||||
NSOpenPanel -> openPanel
|
||||
dup 1 -> setCanChooseFiles:
|
||||
dup 0 -> setCanChooseDirectories:
|
||||
dup 1 -> setResolvesAliases:
|
||||
dup 1 -> setAllowsMultipleSelection: ;
|
||||
NSOpenPanel send: openPanel
|
||||
dup 1 send: \setCanChooseFiles:
|
||||
dup 0 send: \setCanChooseDirectories:
|
||||
dup 1 send: \setResolvesAliases:
|
||||
dup 1 send: \setAllowsMultipleSelection: ;
|
||||
|
||||
: <NSDirPanel> ( -- panel ) <NSOpenPanel>
|
||||
dup 1 -> setCanChooseDirectories: ;
|
||||
dup 1 send: \setCanChooseDirectories: ;
|
||||
|
||||
: <NSSavePanel> ( -- panel )
|
||||
NSSavePanel -> savePanel
|
||||
dup 1 -> setCanChooseFiles:
|
||||
dup 0 -> setCanChooseDirectories:
|
||||
dup 0 -> setAllowsMultipleSelection: ;
|
||||
NSSavePanel send: savePanel
|
||||
dup 1 send: \setCanChooseFiles:
|
||||
dup 0 send: \setCanChooseDirectories:
|
||||
dup 0 send: \setAllowsMultipleSelection: ;
|
||||
|
||||
CONSTANT: NSOKButton 1
|
||||
CONSTANT: NSCancelButton 0
|
||||
|
||||
: (open-panel) ( panel -- paths )
|
||||
dup -> runModal NSOKButton =
|
||||
[ -> filenames CF>string-array ] [ drop f ] if ;
|
||||
dup send: runModal NSOKButton =
|
||||
[ send: filenames CFString>string-array ] [ drop f ] if ;
|
||||
|
||||
: open-panel ( -- paths ) <NSOpenPanel> (open-panel) ;
|
||||
|
||||
|
@ -36,5 +36,5 @@ CONSTANT: NSCancelButton 0
|
|||
|
||||
: save-panel ( path -- path/f )
|
||||
[ <NSSavePanel> dup ] dip
|
||||
split-path -> runModalForDirectory:file: NSOKButton =
|
||||
[ -> filename CF>string ] [ drop f ] if ;
|
||||
split-path send: \runModalForDirectory:file: NSOKButton =
|
||||
[ send: filename CFString>string ] [ drop f ] if ;
|
||||
|
|
|
@ -17,7 +17,7 @@ CONSTANT: NS-EACH-BUFFER-SIZE 16
|
|||
] with-destructors ; inline
|
||||
|
||||
:: (NSFastEnumeration-each) ( ... object quot: ( ... elt -- ) state stackbuf count -- ... )
|
||||
object state stackbuf count -> countByEnumeratingWithState:objects:count: :> items-count
|
||||
object state stackbuf count send: \countByEnumeratingWithState:objects:count: :> items-count
|
||||
items-count 0 = [
|
||||
state itemsPtr>> [ items-count id <c-direct-array> ] [ stackbuf ] if* :> items
|
||||
items-count <iota> [ items nth quot call ] each
|
||||
|
|
|
@ -14,7 +14,7 @@ HELP: super-send
|
|||
HELP: objc-class
|
||||
{ $values { "string" string } { "class" alien } }
|
||||
{ $description "Outputs the Objective C class named by " { $snippet "string" } ". This class can then be used as the receiver in message sends calling class methods, for example:"
|
||||
{ $code "NSMutableArray -> alloc" } }
|
||||
{ $code "NSMutableArray send: alloc" } }
|
||||
{ $errors "Throws an error if there is no class named by " { $snippet "string" } "." } ;
|
||||
|
||||
HELP: objc-meta-class
|
||||
|
|
|
@ -24,11 +24,8 @@ SPECIALIZED-ARRAY: void*
|
|||
over first large-struct? [ "_stret" append ] when
|
||||
make-sender dup infer define-declared ;
|
||||
|
||||
SYMBOL: message-senders
|
||||
SYMBOL: super-message-senders
|
||||
|
||||
message-senders [ H{ } clone ] initialize
|
||||
super-message-senders [ H{ } clone ] initialize
|
||||
INITIALIZED-SYMBOL: message-senders [ H{ } clone ]
|
||||
INITIALIZED-SYMBOL: super-message-senders [ H{ } clone ]
|
||||
|
||||
:: cache-stub ( signature function assoc -- )
|
||||
signature assoc [ function sender-stub ] cache drop ;
|
||||
|
@ -45,7 +42,7 @@ super-message-senders [ H{ } clone ] initialize
|
|||
TUPLE: selector-tuple name object ;
|
||||
|
||||
: selector-name ( name -- name' )
|
||||
CHAR: . over index [ 0 > [ "." split1 nip ] when ] when* ;
|
||||
char: . over index [ 0 > [ "." split1 nip ] when ] when* ;
|
||||
|
||||
MEMO: <selector> ( name -- sel )
|
||||
selector-name f selector-tuple boa ;
|
||||
|
@ -188,7 +185,7 @@ cell {
|
|||
assoc-union alien>objc-types set-global
|
||||
|
||||
: objc-struct-type ( i string -- ctype )
|
||||
[ CHAR: = ] 2keep index-from swap subseq
|
||||
[ char: = ] 2keep index-from swap subseq
|
||||
objc>struct-types get at* [ drop void* ] unless ;
|
||||
|
||||
ERROR: no-objc-type name ;
|
||||
|
@ -200,9 +197,9 @@ ERROR: no-objc-type name ;
|
|||
: (parse-objc-type) ( i string -- ctype )
|
||||
[ [ 1 + ] dip ] [ nth ] 2bi {
|
||||
{ [ dup "rnNoORV" member? ] [ drop (parse-objc-type) ] }
|
||||
{ [ dup CHAR: ^ = ] [ 3drop void* ] }
|
||||
{ [ dup CHAR: { = ] [ drop objc-struct-type ] }
|
||||
{ [ dup CHAR: [ = ] [ 3drop void* ] }
|
||||
{ [ dup char: ^ = ] [ 3drop void* ] }
|
||||
{ [ dup char: \{ = ] [ drop objc-struct-type ] }
|
||||
{ [ dup char: \[ = ] [ 3drop void* ] }
|
||||
[ 2nip decode-type ]
|
||||
} cond ;
|
||||
|
||||
|
@ -238,7 +235,7 @@ ERROR: no-objc-type name ;
|
|||
|
||||
: method-collisions ( -- collisions )
|
||||
objc-methods get >alist
|
||||
[ first CHAR: . swap member? ] filter
|
||||
[ first char: . swap member? ] filter
|
||||
[ first "." split1 nip ] collect-by
|
||||
[ nip values members length 1 > ] assoc-filter ;
|
||||
|
||||
|
|
|
@ -6,15 +6,15 @@ IN: cocoa.nibs
|
|||
|
||||
: load-nib ( name -- )
|
||||
NSBundle
|
||||
swap <NSString> NSApp -> loadNibNamed:owner:
|
||||
swap <NSString> NSApp send: \loadNibNamed:owner:
|
||||
drop ;
|
||||
|
||||
: nib-named ( nib-name -- anNSNib )
|
||||
<NSString> NSNib -> alloc swap f -> initWithNibNamed:bundle:
|
||||
dup [ -> autorelease ] when ;
|
||||
<NSString> NSNib send: alloc swap f send: \initWithNibNamed:bundle:
|
||||
dup [ send: autorelease ] when ;
|
||||
|
||||
: nib-objects ( anNSNib -- objects/f )
|
||||
f
|
||||
{ void* } [ -> instantiateNibWithOwner:topLevelObjects: ]
|
||||
{ void* } [ send: \instantiateNibWithOwner:topLevelObjects: ]
|
||||
with-out-parameters
|
||||
swap [ CF>array ] [ drop f ] if ;
|
||||
swap [ CFArray>array ] [ drop f ] if ;
|
||||
|
|
|
@ -1,26 +1,25 @@
|
|||
! Copyright (C) 2006, 2009 Slava Pestov.
|
||||
! See http://factorcode.org/license.txt for BSD license.
|
||||
USING: alien.accessors arrays cocoa cocoa.application
|
||||
core-foundation.arrays core-foundation.strings kernel sequences
|
||||
;
|
||||
core-foundation.arrays core-foundation.strings kernel sequences ;
|
||||
IN: cocoa.pasteboard
|
||||
|
||||
CONSTANT: NSStringPboardType "NSStringPboardType"
|
||||
|
||||
: pasteboard-string? ( pasteboard -- ? )
|
||||
NSStringPboardType swap -> types CF>string-array member? ;
|
||||
NSStringPboardType swap send: types CFString>string-array member? ;
|
||||
|
||||
: pasteboard-string ( pasteboard -- str )
|
||||
NSStringPboardType <NSString> -> stringForType:
|
||||
dup [ CF>string ] when ;
|
||||
NSStringPboardType <NSString> send: \stringForType:
|
||||
dup [ CFString>string ] when ;
|
||||
|
||||
: set-pasteboard-types ( seq pasteboard -- )
|
||||
swap <CFArray> -> autorelease f -> declareTypes:owner: drop ;
|
||||
swap <CFArray> send: autorelease f send: \declareTypes:owner: drop ;
|
||||
|
||||
: set-pasteboard-string ( str pasteboard -- )
|
||||
NSStringPboardType <NSString>
|
||||
dup 1array pick set-pasteboard-types
|
||||
[ swap <NSString> ] dip -> setString:forType: drop ;
|
||||
[ swap <NSString> ] dip send: \setString:forType: drop ;
|
||||
|
||||
: pasteboard-error ( error -- f )
|
||||
"Pasteboard does not hold a string" <NSString>
|
||||
|
|
|
@ -8,10 +8,10 @@ core-foundation.utilities fry io.backend kernel macros math
|
|||
quotations sequences ;
|
||||
IN: cocoa.plists
|
||||
|
||||
: >plist ( value -- plist ) >cf -> autorelease ;
|
||||
: >plist ( value -- plist ) >cf send: autorelease ;
|
||||
|
||||
: write-plist ( assoc path -- )
|
||||
[ >plist ] [ normalize-path <NSString> ] bi* 0 -> writeToFile:atomically:
|
||||
[ >plist ] [ normalize-path <NSString> ] bi* 0 send: \writeToFile:atomically:
|
||||
[ "write-plist failed" throw ] unless ;
|
||||
|
||||
DEFER: plist>
|
||||
|
@ -19,30 +19,30 @@ DEFER: plist>
|
|||
<PRIVATE
|
||||
|
||||
: (plist-NSNumber>) ( NSNumber -- number )
|
||||
dup -> doubleValue dup >integer =
|
||||
[ -> longLongValue ] [ -> doubleValue ] if ;
|
||||
dup send: doubleValue dup >integer =
|
||||
[ send: longLongValue ] [ send: doubleValue ] if ;
|
||||
|
||||
: (plist-NSData>) ( NSData -- byte-array )
|
||||
dup -> length <byte-array> [ -> getBytes: ] keep ;
|
||||
dup send: length <byte-array> [ send: \getBytes: ] keep ;
|
||||
|
||||
: (plist-NSArray>) ( NSArray -- vector )
|
||||
[ plist> ] NSFastEnumeration-map ;
|
||||
|
||||
: (plist-NSDictionary>) ( NSDictionary -- hashtable )
|
||||
dup [ [ nip ] [ -> valueForKey: ] 2bi [ plist> ] bi@ ] with
|
||||
dup [ [ nip ] [ send: \valueForKey: ] 2bi [ plist> ] bi@ ] with
|
||||
NSFastEnumeration>hashtable ;
|
||||
|
||||
: (read-plist) ( NSData -- id )
|
||||
NSPropertyListSerialization swap kCFPropertyListImmutable f
|
||||
{ void* }
|
||||
[ -> propertyListFromData:mutabilityOption:format:errorDescription: ]
|
||||
[ send: \propertyListFromData:mutabilityOption:format:errorDescription: ]
|
||||
with-out-parameters
|
||||
[ -> release "read-plist failed" throw ] when* ;
|
||||
[ send: release "read-plist failed" throw ] when* ;
|
||||
|
||||
MACRO: objc-class-case ( alist -- quot )
|
||||
[
|
||||
dup callable?
|
||||
[ first2 [ '[ dup _ execute -> isKindOfClass: c-bool> ] ] dip 2array ]
|
||||
[ first2 [ '[ dup _ execute send: \isKindOfClass: c-bool> ] ] dip 2array ]
|
||||
unless
|
||||
] map '[ _ cond ] ;
|
||||
|
||||
|
@ -52,7 +52,7 @@ ERROR: invalid-plist-object object ;
|
|||
|
||||
: plist> ( plist -- value )
|
||||
{
|
||||
{ NSString [ CF>string ] }
|
||||
{ NSString [ CFString>string ] }
|
||||
{ NSNumber [ (plist-NSNumber>) ] }
|
||||
{ NSData [ (plist-NSData>) ] }
|
||||
{ NSArray [ (plist-NSArray>) ] }
|
||||
|
@ -63,5 +63,5 @@ ERROR: invalid-plist-object object ;
|
|||
|
||||
: read-plist ( path -- assoc )
|
||||
normalize-path <NSString>
|
||||
NSData swap -> dataWithContentsOfFile:
|
||||
NSData swap send: \dataWithContentsOfFile:
|
||||
[ (read-plist) plist> ] [ "read-plist failed" throw ] if* ;
|
||||
|
|
|
@ -1,23 +1,23 @@
|
|||
USING: help.markup help.syntax strings alien hashtables ;
|
||||
IN: cocoa.subclassing
|
||||
|
||||
HELP: <CLASS:
|
||||
HELP: \<CLASS:
|
||||
{ $syntax "<CLASS: name < superclass protocols... imeth... ;CLASS>" }
|
||||
{ $values { "name" "a new class name" } { "superclass" "a superclass name" } { "protocols" "zero or more protocol names" } { "imeth" "instance method definitions using " { $link POSTPONE: METHOD: } } }
|
||||
{ $description "Defines a new Objective C class. Instance methods are defined with the " { $link POSTPONE: METHOD: } " parsing word."
|
||||
{ $values { "name" "a new class name" } { "superclass" "a superclass name" } { "protocols" "zero or more protocol names" } { "imeth" "instance method definitions using " { $link postpone: \COCOA-METHOD: } } }
|
||||
{ $description "Defines a new Objective C class. Instance methods are defined with the " { $link postpone: \COCOA-METHOD: } " parsing word."
|
||||
$nl
|
||||
"This word is preferred to calling " { $link define-objc-class } ", because it creates a class word in the " { $vocab-link "cocoa.classes" } " vocabulary at parse time, allowing code to refer to the class word in the same source file where the class is defined." } ;
|
||||
|
||||
{ define-objc-class POSTPONE: <CLASS: POSTPONE: METHOD: } related-words
|
||||
{ define-objc-class postpone: \<CLASS: postpone: \COCOA-METHOD: } related-words
|
||||
|
||||
HELP: METHOD:
|
||||
{ $syntax "METHOD: return foo: type1 arg1 bar: type2 arg2 baz: ... [ body ] ;" }
|
||||
HELP: \COCOA-METHOD:
|
||||
{ $syntax "COCOA-METHOD: return foo: type1 arg1 bar: type2 arg2 baz: ... [ body ] ;" }
|
||||
{ $values { "return" "a C type name" } { "type1" "a C type name" } { "arg1" "a local variable name" } { "body" "arbitrary code" } }
|
||||
{ $description "Defines a method inside of a " { $link POSTPONE: <CLASS: } " form." } ;
|
||||
{ $description "Defines a method inside of a " { $link postpone: \<CLASS: } " form." } ;
|
||||
|
||||
ARTICLE: "objc-subclassing" "Subclassing Objective C classes"
|
||||
"Objective C classes can be subclassed, with new methods defined in Factor, using parsing words:"
|
||||
{ $subsections POSTPONE: <CLASS: POSTPONE: METHOD: }
|
||||
{ $subsections postpone: \<CLASS: postpone: \COCOA-METHOD: }
|
||||
"Objective C class definitions are saved in the image. If the image is saved and Factor is restarted with the saved image, custom class definitions are made available to the Objective C runtime when they are first accessed from within Factor." ;
|
||||
|
||||
ABOUT: "objc-subclassing"
|
||||
|
|
|
@ -71,12 +71,12 @@ IN: cocoa.subclassing
|
|||
TUPLE: cocoa-protocol name ;
|
||||
C: <cocoa-protocol> cocoa-protocol
|
||||
|
||||
SYNTAX: COCOA-PROTOCOL:
|
||||
SYNTAX: \COCOA-PROTOCOL:
|
||||
scan-token <cocoa-protocol> suffix! ;
|
||||
|
||||
SYMBOL: ;CLASS>
|
||||
SYMBOL: \;CLASS>
|
||||
|
||||
SYNTAX: <CLASS:
|
||||
SYNTAX: \<CLASS:
|
||||
scan-token
|
||||
"<" expect
|
||||
scan-token
|
||||
|
@ -101,7 +101,7 @@ SYNTAX: <CLASS:
|
|||
[ [ make-local ] map ] H{ } make
|
||||
(parse-lambda) <lambda> ?rewrite-closures first ;
|
||||
|
||||
SYNTAX: METHOD:
|
||||
SYNTAX: \COCOA-METHOD:
|
||||
scan-c-type
|
||||
parse-selector
|
||||
parse-method-body [ swap ] 2dip 4array ";" expect
|
||||
|
|
|
@ -1,23 +1,22 @@
|
|||
! Copyright (C) 2017 Doug Coleman.
|
||||
! See http://factorcode.org/license.txt for BSD license.
|
||||
USING: alien.c-types cocoa cocoa.classes cocoa.messages
|
||||
cocoa.runtime combinators core-foundation.strings kernel locals
|
||||
;
|
||||
cocoa.runtime combinators core-foundation.strings kernel locals ;
|
||||
IN: cocoa.touchbar
|
||||
|
||||
: make-touchbar ( seq self -- touchbar )
|
||||
[ NSTouchBar -> alloc -> init dup ] dip -> setDelegate: {
|
||||
[ swap <CFStringArray> { void { id SEL id } } ?-> setDefaultItemIdentifiers: ]
|
||||
[ swap <CFStringArray> { void { id SEL id } } ?-> setCustomizationAllowedItemIdentifiers: ]
|
||||
[ NSTouchBar send: alloc send: init dup ] dip send: setDelegate: {
|
||||
[ swap <CFStringArray> send: \setDefaultItemIdentifiers: ]
|
||||
[ swap <CFStringArray> send: \setCustomizationAllowedItemIdentifiers: ]
|
||||
[ nip ]
|
||||
} 2cleave ;
|
||||
|
||||
:: make-NSTouchBar-button ( self identifier label-string action-string -- button )
|
||||
NSCustomTouchBarItem -> alloc
|
||||
identifier <CFString> { id { id SEL id } } ?-> initWithIdentifier: :> item
|
||||
NSCustomTouchBarItem send: alloc
|
||||
identifier <CFString> send: \initWithIdentifier: :> item
|
||||
NSButton
|
||||
label-string <CFString>
|
||||
self
|
||||
action-string lookup-selector { id { id SEL id id SEL } } ?-> buttonWithTitle:target:action: :> button
|
||||
item button -> setView:
|
||||
action-string lookup-selector send: \buttonWithTitle:target:action: :> button
|
||||
item button send: \setView:
|
||||
item ;
|
||||
|
|
|
@ -59,21 +59,21 @@ CONSTANT: NSOpenGLProfileVersion3_2Core 0x3200
|
|||
CONSTANT: NSOpenGLProfileVersion4_1Core 0x4100
|
||||
|
||||
: <GLView> ( class dim pixel-format -- view )
|
||||
[ -> alloc ]
|
||||
[ send: alloc ]
|
||||
[ [ 0 0 ] dip first2 <CGRect> ]
|
||||
[ handle>> ] tri*
|
||||
-> initWithFrame:pixelFormat:
|
||||
dup 1 -> setPostsBoundsChangedNotifications:
|
||||
dup 1 -> setPostsFrameChangedNotifications: ;
|
||||
send: \initWithFrame:pixelFormat:
|
||||
dup 1 send: \setPostsBoundsChangedNotifications:
|
||||
dup 1 send: \setPostsFrameChangedNotifications: ;
|
||||
|
||||
: view-dim ( view -- dim )
|
||||
-> bounds
|
||||
send: bounds
|
||||
[ CGRect-w >fixnum ] [ CGRect-h >fixnum ] bi
|
||||
2array ;
|
||||
|
||||
: mouse-location ( view event -- loc )
|
||||
[
|
||||
-> locationInWindow f -> convertPoint:fromView:
|
||||
send: locationInWindow f send: \convertPoint:fromView:
|
||||
[ x>> ] [ y>> ] bi
|
||||
] [ drop -> frame CGRect-h ] 2bi
|
||||
] [ drop send: frame CGRect-h ] 2bi
|
||||
swap - [ >integer ] bi@ 2array ;
|
||||
|
|
|
@ -22,19 +22,19 @@ CONSTANT: NSBackingStoreNonretained 1
|
|||
CONSTANT: NSBackingStoreBuffered 2
|
||||
|
||||
: <NSWindow> ( rect style class -- window )
|
||||
[ -> alloc ] curry 2dip NSBackingStoreBuffered 1
|
||||
-> initWithContentRect:styleMask:backing:defer: ;
|
||||
[ send: alloc ] curry 2dip NSBackingStoreBuffered 1
|
||||
send: \initWithContentRect:styleMask:backing:defer: ;
|
||||
|
||||
: class-for-style ( style -- NSWindow/NSPanel )
|
||||
0x1ef0 bitand zero? NSWindow NSPanel ? ;
|
||||
|
||||
: <ViewWindow> ( view rect style -- window )
|
||||
dup class-for-style <NSWindow> [ swap -> setContentView: ] keep
|
||||
dup dup -> contentView -> setInitialFirstResponder:
|
||||
dup 1 -> setAcceptsMouseMovedEvents:
|
||||
dup 0 -> setReleasedWhenClosed: ;
|
||||
dup class-for-style <NSWindow> [ swap send: \setContentView: ] keep
|
||||
dup dup send: contentView send: \setInitialFirstResponder:
|
||||
dup 1 send: \setAcceptsMouseMovedEvents:
|
||||
dup 0 send: \setReleasedWhenClosed: ;
|
||||
|
||||
: window-content-rect ( window -- rect )
|
||||
dup -> class swap
|
||||
[ -> frame ] [ -> styleMask ] bi
|
||||
-> contentRectForFrameRect:styleMask: ;
|
||||
dup send: class swap
|
||||
[ send: frame ] [ send: styleMask ] bi
|
||||
send: \contentRectForFrameRect:styleMask: ;
|
||||
|
|
|
@ -5,9 +5,9 @@ USING: arrays colors colors.cmyk kernel locals math.functions
|
|||
math.ranges sequences tools.test ;
|
||||
|
||||
{ t } [
|
||||
0.0 1.0 0.1 <range> [| r |
|
||||
0.0 1.0 0.1 <range> [| g |
|
||||
0.0 1.0 0.1 <range> [| b |
|
||||
0.0 1.0 0.1 <range> |[ r |
|
||||
0.0 1.0 0.1 <range> |[ g |
|
||||
0.0 1.0 0.1 <range> |[ b |
|
||||
r g b 1.0 <rgba> dup >cmyka >rgba
|
||||
[ >rgba-components 4array ] bi@
|
||||
[ 0.00000001 ~ ] 2all?
|
||||
|
|
|
@ -4,21 +4,21 @@ USING: help.markup help.syntax strings colors ;
|
|||
HELP: named-color
|
||||
{ $values { "name" string } { "color" color } }
|
||||
{ $description "Outputs a named color from the color database." }
|
||||
{ $notes "In most cases, " { $link POSTPONE: COLOR: } " should be used instead." }
|
||||
{ $notes "In most cases, " { $link postpone: \color: } " should be used instead." }
|
||||
{ $errors "Throws an error if the color is not listed in " { $snippet "rgb.txt" } ", " { $snippet "factor-colors.txt" } " or " { $snippet "solarized-colors.txt" } "." } ;
|
||||
|
||||
HELP: named-colors
|
||||
{ $values { "keys" "a sequence of strings" } }
|
||||
{ $description "Outputs a sequence of all colors in the " { $snippet "rgb.txt" } " database." } ;
|
||||
|
||||
HELP: COLOR:
|
||||
{ $syntax "COLOR: name" }
|
||||
HELP: \color:
|
||||
{ $syntax "color: name" }
|
||||
{ $description "Parses as a " { $link color } " object with the given name." }
|
||||
{ $errors "Throws an error if the color is not listed in " { $snippet "rgb.txt" } "." }
|
||||
{ $examples
|
||||
{ $code
|
||||
"USING: colors.constants io.styles ;"
|
||||
"\"Hello!\" { { foreground COLOR: cyan } } format nl"
|
||||
"\"Hello!\" { { foreground color: cyan } } format nl"
|
||||
}
|
||||
} ;
|
||||
|
||||
|
@ -27,7 +27,7 @@ ARTICLE: "colors.constants" "Standard color database"
|
|||
{ $subsections
|
||||
named-color
|
||||
named-colors
|
||||
POSTPONE: COLOR:
|
||||
postpone: \color:
|
||||
} ;
|
||||
|
||||
ABOUT: "colors.constants"
|
||||
|
|
|
@ -2,4 +2,4 @@
|
|||
! See http://factorcode.org/license.txt for BSD license.
|
||||
USING: colors colors.constants tools.test ;
|
||||
|
||||
{ t } [ COLOR: light-green rgba? ] unit-test
|
||||
{ t } [ color: light-green rgba? ] unit-test
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
! Copyright (C) 2009 Slava Pestov.
|
||||
! See http://factorcode.org/license.txt for BSD license.
|
||||
USING: kernel assocs math math.parser memoize io.encodings.utf8
|
||||
io.files lexer parser colors sequences splitting ascii ;
|
||||
USING: ascii assocs colors io.encodings.utf8 io.files kernel
|
||||
lexer math math.parser sequences splitting ;
|
||||
IN: colors.constants
|
||||
|
||||
<PRIVATE
|
||||
|
@ -9,7 +9,7 @@ IN: colors.constants
|
|||
: parse-color ( line -- name color )
|
||||
first4
|
||||
[ [ string>number 255 /f ] tri@ 1.0 <rgba> ] dip
|
||||
[ blank? ] trim-head H{ { CHAR: \s CHAR: - } } substitute swap ;
|
||||
[ blank? ] trim-head H{ { char: \s char: - } } substitute swap ;
|
||||
|
||||
: parse-colors ( lines -- assoc )
|
||||
[ "!" head? ] reject
|
||||
|
@ -31,4 +31,4 @@ ERROR: no-such-color name ;
|
|||
: named-color ( name -- color )
|
||||
dup colors at [ ] [ no-such-color ] ?if ;
|
||||
|
||||
SYNTAX: COLOR: scan-token named-color suffix! ;
|
||||
SYNTAX: \color: scan-token named-color suffix! ;
|
||||
|
|
|
@ -7,21 +7,19 @@ IN: colors.hex
|
|||
|
||||
HELP: hex>rgba
|
||||
{ $values { "hex" string } { "rgba" color } }
|
||||
{ $description "Converts a hexadecimal string value into a " { $link color } "." }
|
||||
;
|
||||
{ $description "Converts a hexadecimal string value into a " { $link color } "." } ;
|
||||
|
||||
HELP: rgba>hex
|
||||
{ $values { "rgba" color } { "hex" string } }
|
||||
{ $description "Converts a " { $link color } " into a hexadecimal string value." }
|
||||
;
|
||||
{ $description "Converts a " { $link color } " into a hexadecimal string value." } ;
|
||||
|
||||
HELP: HEXCOLOR:
|
||||
{ $syntax "HEXCOLOR: value" }
|
||||
HELP: \hexcolor:
|
||||
{ $syntax "hexcolor: value" }
|
||||
{ $description "Parses as a " { $link color } " object with the given hexadecimal value." }
|
||||
{ $examples
|
||||
{ $code
|
||||
"USING: colors.hex io.styles ;"
|
||||
"\"Hello!\" { { foreground HEXCOLOR: 336699 } } format nl"
|
||||
"\"Hello!\" { { foreground hexcolor: 336699 } } format nl"
|
||||
}
|
||||
} ;
|
||||
|
||||
|
@ -31,7 +29,7 @@ ARTICLE: "colors.hex" "HEX colors"
|
|||
{ $subsections
|
||||
hex>rgba
|
||||
rgba>hex
|
||||
POSTPONE: HEXCOLOR:
|
||||
postpone: \hexcolor:
|
||||
}
|
||||
{ $see-also "colors" } ;
|
||||
|
||||
|
|
|
@ -2,18 +2,18 @@
|
|||
! See http://factorcode.org/license.txt for BSD license
|
||||
USING: colors colors.hex tools.test ;
|
||||
|
||||
{ HEXCOLOR: 000000 } [ 0.0 0.0 0.0 1.0 <rgba> ] unit-test
|
||||
{ HEXCOLOR: FFFFFF } [ 1.0 1.0 1.0 1.0 <rgba> ] unit-test
|
||||
{ HEXCOLOR: abcdef } [ "abcdef" hex>rgba ] unit-test
|
||||
{ HEXCOLOR: abcdef } [ "ABCDEF" hex>rgba ] unit-test
|
||||
{ "ABCDEF" } [ HEXCOLOR: abcdef rgba>hex ] unit-test
|
||||
{ hexcolor: 000000 } [ 0.0 0.0 0.0 1.0 <rgba> ] unit-test
|
||||
{ hexcolor: FFFFFF } [ 1.0 1.0 1.0 1.0 <rgba> ] unit-test
|
||||
{ hexcolor: abcdef } [ "abcdef" hex>rgba ] unit-test
|
||||
{ hexcolor: abcdef } [ "ABCDEF" hex>rgba ] unit-test
|
||||
{ "ABCDEF" } [ hexcolor: abcdef rgba>hex ] unit-test
|
||||
|
||||
{ HEXCOLOR: 00000000 } [ 0.0 0.0 0.0 0.0 <rgba> ] unit-test
|
||||
{ HEXCOLOR: FF000000 } [ 1.0 0.0 0.0 0.0 <rgba> ] unit-test
|
||||
{ HEXCOLOR: FFFF0000 } [ 1.0 1.0 0.0 0.0 <rgba> ] unit-test
|
||||
{ HEXCOLOR: FFFFFF00 } [ 1.0 1.0 1.0 0.0 <rgba> ] unit-test
|
||||
{ HEXCOLOR: FFFFFFFF } [ 1.0 1.0 1.0 1.0 <rgba> ] unit-test
|
||||
{ hexcolor: 00000000 } [ 0.0 0.0 0.0 0.0 <rgba> ] unit-test
|
||||
{ hexcolor: FF000000 } [ 1.0 0.0 0.0 0.0 <rgba> ] unit-test
|
||||
{ hexcolor: FFFF0000 } [ 1.0 1.0 0.0 0.0 <rgba> ] unit-test
|
||||
{ hexcolor: FFFFFF00 } [ 1.0 1.0 1.0 0.0 <rgba> ] unit-test
|
||||
{ hexcolor: FFFFFFFF } [ 1.0 1.0 1.0 1.0 <rgba> ] unit-test
|
||||
|
||||
{ HEXCOLOR: cafebabe } [ "cafebabe" hex>rgba ] unit-test
|
||||
{ HEXCOLOR: 112233 } [ "123" hex>rgba ] unit-test
|
||||
{ HEXCOLOR: 11223344 } [ "1234" hex>rgba ] unit-test
|
||||
{ hexcolor: cafebabe } [ "cafebabe" hex>rgba ] unit-test
|
||||
{ hexcolor: 112233 } [ "123" hex>rgba ] unit-test
|
||||
{ hexcolor: 11223344 } [ "1234" hex>rgba ] unit-test
|
||||
|
|
|
@ -18,4 +18,4 @@ IN: colors.hex
|
|||
[ red>> ] [ green>> ] [ blue>> ] tri
|
||||
[ 255 * >integer ] tri@ "%02X%02X%02X" sprintf ;
|
||||
|
||||
SYNTAX: HEXCOLOR: scan-token hex>rgba suffix! ;
|
||||
SYNTAX: \hexcolor: scan-token hex>rgba suffix! ;
|
||||
|
|
|
@ -5,9 +5,9 @@ USING: arrays colors colors.hsl kernel locals math.functions
|
|||
math.ranges sequences tools.test ;
|
||||
|
||||
{ t } [
|
||||
0.0 1.0 0.1 <range> [| r |
|
||||
0.0 1.0 0.1 <range> [| g |
|
||||
0.0 1.0 0.1 <range> [| b |
|
||||
0.0 1.0 0.1 <range> |[ r |
|
||||
0.0 1.0 0.1 <range> |[ g |
|
||||
0.0 1.0 0.1 <range> |[ b |
|
||||
r g b 1.0 <rgba> dup >hsla >rgba
|
||||
[ >rgba-components 4array ] bi@
|
||||
[ 0.00000001 ~ ] 2all?
|
||||
|
|
|
@ -31,7 +31,7 @@ PRIVATE>
|
|||
M: hsla >rgba
|
||||
{
|
||||
[ hue>> ] [ saturation>> ] [ lightness>> ] [ alpha>> ]
|
||||
} cleave [| h s l |
|
||||
} cleave |[ h s l |
|
||||
s zero? [
|
||||
l l l
|
||||
] [
|
||||
|
@ -50,7 +50,7 @@ M: object >hsla >rgba >hsla ;
|
|||
M: hsla >hsla ; inline
|
||||
|
||||
M: rgba >hsla
|
||||
>rgba-components [| r g b |
|
||||
>rgba-components |[ r g b |
|
||||
r g b min min :> min-c
|
||||
r g b max max :> max-c
|
||||
min-c max-c + 2 / :> l
|
||||
|
|
|
@ -5,9 +5,9 @@ USING: arrays colors colors.lab kernel locals math.functions
|
|||
math.ranges sequences tools.test ;
|
||||
|
||||
{ t } [
|
||||
0.0 1.0 0.1 <range> [| r |
|
||||
0.0 1.0 0.1 <range> [| g |
|
||||
0.0 1.0 0.1 <range> [| b |
|
||||
0.0 1.0 0.1 <range> |[ r |
|
||||
0.0 1.0 0.1 <range> |[ g |
|
||||
0.0 1.0 0.1 <range> |[ b |
|
||||
r g b 1.0 <rgba> dup >laba >rgba
|
||||
[ >rgba-components 4array ] bi@
|
||||
[ 0.00001 ~ ] 2all?
|
||||
|
|
|
@ -14,7 +14,7 @@ M: laba >rgba >xyza >rgba ;
|
|||
|
||||
M: laba >xyza
|
||||
[
|
||||
[let
|
||||
let[
|
||||
[ l>> ] [ a>> ] [ b>> ] tri :> ( l a b )
|
||||
l 16 + 116 / :> fy
|
||||
a 500 / fy + :> fx
|
||||
|
@ -53,7 +53,7 @@ M: rgba >laba >xyza >laba ;
|
|||
|
||||
M: xyza >laba
|
||||
[
|
||||
[let
|
||||
let[
|
||||
[ x>> wp_x / ] [ y>> wp_y / ] [ z>> wp_z / ] tri
|
||||
[
|
||||
dup xyz_epsilon >
|
||||
|
|
|
@ -5,9 +5,9 @@ USING: arrays colors colors.lch kernel locals math.functions
|
|||
math.ranges sequences tools.test ;
|
||||
|
||||
{ t } [
|
||||
0.0 1.0 0.1 <range> [| r |
|
||||
0.0 1.0 0.1 <range> [| g |
|
||||
0.0 1.0 0.1 <range> [| b |
|
||||
0.0 1.0 0.1 <range> |[ r |
|
||||
0.0 1.0 0.1 <range> |[ g |
|
||||
0.0 1.0 0.1 <range> |[ b |
|
||||
r g b 1.0 <rgba> dup >LCHuv >rgba
|
||||
[ >rgba-components 4array ] bi@
|
||||
[ 0.00001 ~ ] 2all?
|
||||
|
@ -17,9 +17,9 @@ math.ranges sequences tools.test ;
|
|||
] unit-test
|
||||
|
||||
{ t } [
|
||||
0.0 1.0 0.1 <range> [| r |
|
||||
0.0 1.0 0.1 <range> [| g |
|
||||
0.0 1.0 0.1 <range> [| b |
|
||||
0.0 1.0 0.1 <range> |[ r |
|
||||
0.0 1.0 0.1 <range> |[ g |
|
||||
0.0 1.0 0.1 <range> |[ b |
|
||||
r g b 1.0 <rgba> dup >LCHab >rgba
|
||||
[ >rgba-components 4array ] bi@
|
||||
[ 0.00001 ~ ] 2all?
|
||||
|
|
|
@ -16,7 +16,7 @@ M: LCHuv >xyza >luva >xyza ;
|
|||
|
||||
M: LCHuv >luva
|
||||
[
|
||||
[let
|
||||
let[
|
||||
[ l>> ] [ c>> ] [ h>> ] tri :> ( l c h )
|
||||
h deg>rad :> hr
|
||||
|
||||
|
@ -34,7 +34,7 @@ M: LCHuv >LCHuv ; inline
|
|||
|
||||
M: luva >LCHuv
|
||||
[
|
||||
[let
|
||||
let[
|
||||
[ l>> ] [ u>> ] [ v>> ] tri :> ( l u v )
|
||||
v u fatan2 rad>deg
|
||||
[ dup 360 > ] [ 360 - ] while
|
||||
|
@ -54,7 +54,7 @@ M: LCHab >rgba >laba >rgba ;
|
|||
|
||||
M: LCHab >laba
|
||||
[
|
||||
[let
|
||||
let[
|
||||
[ l>> ] [ c>> ] [ h>> ] tri :> ( l c h )
|
||||
h deg>rad :> hr
|
||||
|
||||
|
@ -72,7 +72,7 @@ M: LCHab >LCHab ; inline
|
|||
|
||||
M: laba >LCHab
|
||||
[
|
||||
[let
|
||||
let[
|
||||
[ l>> ] [ a>> ] [ b>> ] tri :> ( l a b )
|
||||
b a fatan2 rad>deg
|
||||
[ dup 360 > ] [ 360 - ] while
|
||||
|
|
|
@ -5,9 +5,9 @@ USING: arrays colors colors.luv kernel locals math.functions
|
|||
math.ranges sequences tools.test ;
|
||||
|
||||
{ t } [
|
||||
0.0 1.0 0.1 <range> [| r |
|
||||
0.0 1.0 0.1 <range> [| g |
|
||||
0.0 1.0 0.1 <range> [| b |
|
||||
0.0 1.0 0.1 <range> |[ r |
|
||||
0.0 1.0 0.1 <range> |[ g |
|
||||
0.0 1.0 0.1 <range> |[ b |
|
||||
r g b 1.0 <rgba> dup >luva >rgba
|
||||
[ >rgba-components 4array ] bi@
|
||||
[ 0.00001 ~ ] 2all?
|
||||
|
|
|
@ -23,7 +23,7 @@ M: luva >rgba >xyza >rgba ;
|
|||
|
||||
M: luva >xyza
|
||||
[
|
||||
[let
|
||||
let[
|
||||
wp_x wp_y wp_z xyz-to-uv :> ( u_wp v_wp )
|
||||
[ l>> ] [ u>> ] [ v>> ] tri :> ( l u v )
|
||||
|
||||
|
@ -52,7 +52,7 @@ M: luva >luva ; inline
|
|||
|
||||
M: xyza >luva
|
||||
[
|
||||
[let
|
||||
let[
|
||||
wp_x wp_y wp_z xyz-to-uv :> ( u_wp v_wp )
|
||||
[ x>> ] [ y>> ] [ z>> ] tri :> ( x_ y_ z_ )
|
||||
x_ y_ z_ xyz-to-uv :> ( u_ v_ )
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
USING: colors.constants colors.mix kernel tools.test ;
|
||||
|
||||
{ COLOR: blue } [ COLOR: blue COLOR: red 0.0 linear-gradient ] unit-test
|
||||
{ COLOR: red } [ COLOR: blue COLOR: red 1.0 linear-gradient ] unit-test
|
||||
{ color: blue } [ color: blue color: red 0.0 linear-gradient ] unit-test
|
||||
{ color: red } [ color: blue color: red 1.0 linear-gradient ] unit-test
|
||||
|
||||
{ COLOR: blue } [ { COLOR: blue COLOR: red COLOR: green } 0.0 sample-linear-gradient ] unit-test
|
||||
{ COLOR: red } [ { COLOR: blue COLOR: red COLOR: green } 0.5 sample-linear-gradient ] unit-test
|
||||
{ COLOR: green } [ { COLOR: blue COLOR: red COLOR: green } 1.0 sample-linear-gradient ] unit-test
|
||||
{ color: blue } [ { color: blue color: red color: green } 0.0 sample-linear-gradient ] unit-test
|
||||
{ color: red } [ { color: blue color: red color: green } 0.5 sample-linear-gradient ] unit-test
|
||||
{ color: green } [ { color: blue color: red color: green } 1.0 sample-linear-gradient ] unit-test
|
||||
|
||||
{ t } [
|
||||
{ COLOR: blue COLOR: red } 0.5 sample-linear-gradient
|
||||
COLOR: blue COLOR: red 0.5 linear-gradient =
|
||||
{ color: blue color: red } 0.5 sample-linear-gradient
|
||||
color: blue color: red 0.5 linear-gradient =
|
||||
] unit-test
|
||||
|
|
|
@ -5,9 +5,9 @@ USING: arrays colors colors.ryb kernel locals math.functions
|
|||
math.ranges sequences tools.test ;
|
||||
|
||||
{ t } [
|
||||
0.0 1.0 0.1 <range> [| r |
|
||||
0.0 1.0 0.1 <range> [| g |
|
||||
0.0 1.0 0.1 <range> [| b |
|
||||
0.0 1.0 0.1 <range> |[ r |
|
||||
0.0 1.0 0.1 <range> |[ g |
|
||||
0.0 1.0 0.1 <range> |[ b |
|
||||
r g b 1.0 <rgba> dup >ryba >rgba
|
||||
[ >rgba-components 4array ] bi@
|
||||
[ 0.00000001 ~ ] 2all?
|
||||
|
|
|
@ -5,9 +5,9 @@ USING: arrays colors colors.xyy kernel locals math.functions
|
|||
math.ranges sequences tools.test ;
|
||||
|
||||
{ t } [
|
||||
0.0 1.0 0.1 <range> [| r |
|
||||
0.0 1.0 0.1 <range> [| g |
|
||||
0.0 1.0 0.1 <range> [| b |
|
||||
0.0 1.0 0.1 <range> |[ r |
|
||||
0.0 1.0 0.1 <range> |[ g |
|
||||
0.0 1.0 0.1 <range> |[ b |
|
||||
r g b 1.0 <rgba> dup >xyYa >rgba
|
||||
[ >rgba-components 4array ] bi@
|
||||
[ 0.00001 ~ ] 2all?
|
||||
|
|
|
@ -14,7 +14,7 @@ M: xyYa >rgba
|
|||
|
||||
M: xyYa >xyza
|
||||
[
|
||||
[let
|
||||
let[
|
||||
[ x>> ] [ y>> ] [ Y>> ] tri :> ( x y Y )
|
||||
x y / Y *
|
||||
Y
|
||||
|
@ -30,7 +30,7 @@ M: xyYa >xyYa ; inline
|
|||
|
||||
M: xyza >xyYa
|
||||
[
|
||||
[let
|
||||
let[
|
||||
[ x>> ] [ y>> ] [ z>> ] tri :> ( x y z )
|
||||
x y z + +
|
||||
[ x swap / ]
|
||||
|
|
|
@ -5,9 +5,9 @@ USING: arrays colors colors.xyz kernel locals math.functions
|
|||
math.ranges sequences tools.test ;
|
||||
|
||||
{ t } [
|
||||
0.0 1.0 0.1 <range> [| r |
|
||||
0.0 1.0 0.1 <range> [| g |
|
||||
0.0 1.0 0.1 <range> [| b |
|
||||
0.0 1.0 0.1 <range> |[ r |
|
||||
0.0 1.0 0.1 <range> |[ g |
|
||||
0.0 1.0 0.1 <range> |[ b |
|
||||
r g b 1.0 <rgba> dup >xyza >rgba
|
||||
[ >rgba-components 4array ] bi@
|
||||
[ 0.00001 ~ ] 2all?
|
||||
|
|
|
@ -26,7 +26,7 @@ PRIVATE>
|
|||
|
||||
M: xyza >rgba
|
||||
[
|
||||
[let
|
||||
let[
|
||||
[ x>> ] [ y>> ] [ z>> ] tri :> ( x y z )
|
||||
x 3.2404542 * y -1.5371385 * z -0.4985314 * + +
|
||||
x -0.9692660 * y 1.8760108 * z 0.0415560 * + +
|
||||
|
@ -50,7 +50,7 @@ PRIVATE>
|
|||
|
||||
M: rgba >xyza
|
||||
[
|
||||
[let
|
||||
let[
|
||||
[ red>> ] [ green>> ] [ blue>> ] tri
|
||||
[ invert-rgb-compand ] tri@ :> ( r g b )
|
||||
r 0.4124564 * g 0.3575761 * b 0.1804375 * + +
|
||||
|
|
|
@ -5,9 +5,9 @@ USING: arrays colors colors.yiq kernel locals math.functions
|
|||
math.ranges sequences tools.test ;
|
||||
|
||||
{ t } [
|
||||
0.0 1.0 0.1 <range> [| r |
|
||||
0.0 1.0 0.1 <range> [| g |
|
||||
0.0 1.0 0.1 <range> [| b |
|
||||
0.0 1.0 0.1 <range> |[ r |
|
||||
0.0 1.0 0.1 <range> |[ g |
|
||||
0.0 1.0 0.1 <range> |[ b |
|
||||
r g b 1.0 <rgba> dup >yiqa >rgba
|
||||
[ >rgba-components 4array ] bi@
|
||||
[ 0.00000001 ~ ] 2all?
|
||||
|
|
|
@ -5,9 +5,9 @@ USING: arrays colors colors.yuv kernel locals math.functions
|
|||
math.ranges sequences tools.test ;
|
||||
|
||||
{ t } [
|
||||
0.0 1.0 0.1 <range> [| r |
|
||||
0.0 1.0 0.1 <range> [| g |
|
||||
0.0 1.0 0.1 <range> [| b |
|
||||
0.0 1.0 0.1 <range> |[ r |
|
||||
0.0 1.0 0.1 <range> |[ g |
|
||||
0.0 1.0 0.1 <range> |[ b |
|
||||
r g b 1.0 <rgba> dup >yuva >rgba
|
||||
[ >rgba-components 4array ] bi@
|
||||
[ 0.00000001 ~ ] 2all?
|
||||
|
|
|
@ -26,7 +26,7 @@ PRIVATE>
|
|||
|
||||
M: yuva >rgba
|
||||
{ [ y>> ] [ u>> ] [ v>> ] [ alpha>> ] } cleave
|
||||
[| y u v |
|
||||
|[ y u v |
|
||||
y 1 Wr - Vmax / v * +
|
||||
|
||||
y
|
||||
|
|
|
@ -3,7 +3,7 @@ IN: compiler.cfg.alias-analysis
|
|||
|
||||
HELP: useless-compare?
|
||||
{ $values
|
||||
{ "insn" "a " { $link ##compare } " instruction" }
|
||||
{ "insn" "a " { $link compare## } " instruction" }
|
||||
{ "?" boolean }
|
||||
}
|
||||
{ $description "Checks if the comparison instruction is required." } ;
|
||||
|
|
|
@ -12,168 +12,168 @@ IN: compiler.cfg.alias-analysis.tests
|
|||
! Redundant load elimination
|
||||
{
|
||||
V{
|
||||
T{ ##peek f 0 D: 0 }
|
||||
T{ ##slot-imm f 1 0 1 0 }
|
||||
T{ ##copy f 2 1 any-rep }
|
||||
T{ peek## f 0 d: 0 }
|
||||
T{ slot-imm## f 1 0 1 0 }
|
||||
T{ copy## f 2 1 any-rep }
|
||||
}
|
||||
} [
|
||||
V{
|
||||
T{ ##peek f 0 D: 0 }
|
||||
T{ ##slot-imm f 1 0 1 0 }
|
||||
T{ ##slot-imm f 2 0 1 0 }
|
||||
T{ peek## f 0 d: 0 }
|
||||
T{ slot-imm## f 1 0 1 0 }
|
||||
T{ slot-imm## f 2 0 1 0 }
|
||||
} test-alias-analysis
|
||||
] unit-test
|
||||
|
||||
! Store-load forwarding
|
||||
{
|
||||
V{
|
||||
T{ ##peek f 0 D: 0 }
|
||||
T{ ##peek f 1 D: 1 }
|
||||
T{ ##set-slot-imm f 1 0 1 0 }
|
||||
T{ ##copy f 2 1 any-rep }
|
||||
T{ peek## f 0 d: 0 }
|
||||
T{ peek## f 1 d: 1 }
|
||||
T{ set-slot-imm## f 1 0 1 0 }
|
||||
T{ copy## f 2 1 any-rep }
|
||||
}
|
||||
} [
|
||||
V{
|
||||
T{ ##peek f 0 D: 0 }
|
||||
T{ ##peek f 1 D: 1 }
|
||||
T{ ##set-slot-imm f 1 0 1 0 }
|
||||
T{ ##slot-imm f 2 0 1 0 }
|
||||
T{ peek## f 0 d: 0 }
|
||||
T{ peek## f 1 d: 1 }
|
||||
T{ set-slot-imm## f 1 0 1 0 }
|
||||
T{ slot-imm## f 2 0 1 0 }
|
||||
} test-alias-analysis
|
||||
] unit-test
|
||||
|
||||
! Dead store elimination
|
||||
{
|
||||
V{
|
||||
T{ ##peek f 0 D: 0 }
|
||||
T{ ##peek f 1 D: 1 }
|
||||
T{ ##peek f 2 D: 2 }
|
||||
T{ ##set-slot-imm f 2 0 1 0 }
|
||||
T{ peek## f 0 d: 0 }
|
||||
T{ peek## f 1 d: 1 }
|
||||
T{ peek## f 2 d: 2 }
|
||||
T{ set-slot-imm## f 2 0 1 0 }
|
||||
}
|
||||
} [
|
||||
V{
|
||||
T{ ##peek f 0 D: 0 }
|
||||
T{ ##peek f 1 D: 1 }
|
||||
T{ ##peek f 2 D: 2 }
|
||||
T{ ##set-slot-imm f 1 0 1 0 }
|
||||
T{ ##set-slot-imm f 2 0 1 0 }
|
||||
T{ peek## f 0 d: 0 }
|
||||
T{ peek## f 1 d: 1 }
|
||||
T{ peek## f 2 d: 2 }
|
||||
T{ set-slot-imm## f 1 0 1 0 }
|
||||
T{ set-slot-imm## f 2 0 1 0 }
|
||||
} test-alias-analysis
|
||||
] unit-test
|
||||
|
||||
{
|
||||
V{
|
||||
T{ ##peek f 0 D: 0 }
|
||||
T{ ##peek f 1 D: 1 }
|
||||
T{ ##peek f 2 D: 2 }
|
||||
T{ ##peek f 3 D: 3 }
|
||||
T{ ##set-slot-imm f 3 0 1 0 }
|
||||
T{ peek## f 0 d: 0 }
|
||||
T{ peek## f 1 d: 1 }
|
||||
T{ peek## f 2 d: 2 }
|
||||
T{ peek## f 3 d: 3 }
|
||||
T{ set-slot-imm## f 3 0 1 0 }
|
||||
}
|
||||
} [
|
||||
V{
|
||||
T{ ##peek f 0 D: 0 }
|
||||
T{ ##peek f 1 D: 1 }
|
||||
T{ ##peek f 2 D: 2 }
|
||||
T{ ##peek f 3 D: 3 }
|
||||
T{ ##set-slot-imm f 1 0 1 0 }
|
||||
T{ ##set-slot-imm f 2 0 1 0 }
|
||||
T{ ##set-slot-imm f 3 0 1 0 }
|
||||
T{ peek## f 0 d: 0 }
|
||||
T{ peek## f 1 d: 1 }
|
||||
T{ peek## f 2 d: 2 }
|
||||
T{ peek## f 3 d: 3 }
|
||||
T{ set-slot-imm## f 1 0 1 0 }
|
||||
T{ set-slot-imm## f 2 0 1 0 }
|
||||
T{ set-slot-imm## f 3 0 1 0 }
|
||||
} test-alias-analysis
|
||||
] unit-test
|
||||
|
||||
! Redundant store elimination
|
||||
{
|
||||
V{
|
||||
T{ ##peek f 0 D: 0 }
|
||||
T{ ##slot-imm f 1 0 1 0 }
|
||||
T{ peek## f 0 d: 0 }
|
||||
T{ slot-imm## f 1 0 1 0 }
|
||||
}
|
||||
} [
|
||||
V{
|
||||
T{ ##peek f 0 D: 0 }
|
||||
T{ ##slot-imm f 1 0 1 0 }
|
||||
T{ ##set-slot-imm f 1 0 1 0 }
|
||||
T{ peek## f 0 d: 0 }
|
||||
T{ slot-imm## f 1 0 1 0 }
|
||||
T{ set-slot-imm## f 1 0 1 0 }
|
||||
} test-alias-analysis
|
||||
] unit-test
|
||||
|
||||
{
|
||||
V{
|
||||
T{ ##peek f 0 D: 0 }
|
||||
T{ ##slot-imm f 1 0 1 0 }
|
||||
T{ ##copy f 2 1 any-rep }
|
||||
T{ peek## f 0 d: 0 }
|
||||
T{ slot-imm## f 1 0 1 0 }
|
||||
T{ copy## f 2 1 any-rep }
|
||||
}
|
||||
} [
|
||||
V{
|
||||
T{ ##peek f 0 D: 0 }
|
||||
T{ ##slot-imm f 1 0 1 0 }
|
||||
T{ ##copy f 2 1 any-rep }
|
||||
T{ ##set-slot-imm f 2 0 1 0 }
|
||||
T{ peek## f 0 d: 0 }
|
||||
T{ slot-imm## f 1 0 1 0 }
|
||||
T{ copy## f 2 1 any-rep }
|
||||
T{ set-slot-imm## f 2 0 1 0 }
|
||||
} test-alias-analysis
|
||||
] unit-test
|
||||
|
||||
! Not a redundant load
|
||||
{
|
||||
V{
|
||||
T{ ##peek f 0 D: 0 }
|
||||
T{ ##peek f 1 D: 1 }
|
||||
T{ ##slot-imm f 1 0 1 0 }
|
||||
T{ ##set-slot-imm f 0 1 1 0 }
|
||||
T{ ##slot-imm f 2 0 1 0 }
|
||||
T{ peek## f 0 d: 0 }
|
||||
T{ peek## f 1 d: 1 }
|
||||
T{ slot-imm## f 1 0 1 0 }
|
||||
T{ set-slot-imm## f 0 1 1 0 }
|
||||
T{ slot-imm## f 2 0 1 0 }
|
||||
}
|
||||
} [
|
||||
V{
|
||||
T{ ##peek f 0 D: 0 }
|
||||
T{ ##peek f 1 D: 1 }
|
||||
T{ ##slot-imm f 1 0 1 0 }
|
||||
T{ ##set-slot-imm f 0 1 1 0 }
|
||||
T{ ##slot-imm f 2 0 1 0 }
|
||||
T{ peek## f 0 d: 0 }
|
||||
T{ peek## f 1 d: 1 }
|
||||
T{ slot-imm## f 1 0 1 0 }
|
||||
T{ set-slot-imm## f 0 1 1 0 }
|
||||
T{ slot-imm## f 2 0 1 0 }
|
||||
} test-alias-analysis
|
||||
] unit-test
|
||||
|
||||
! Not a redundant store
|
||||
{
|
||||
V{
|
||||
T{ ##peek f 0 D: 0 }
|
||||
T{ ##peek f 1 D: 1 }
|
||||
T{ ##peek f 2 D: 2 }
|
||||
T{ ##peek f 3 D: 3 }
|
||||
T{ ##set-slot-imm f 2 1 1 0 }
|
||||
T{ ##slot-imm f 4 0 1 0 }
|
||||
T{ ##set-slot-imm f 3 1 1 0 }
|
||||
T{ peek## f 0 d: 0 }
|
||||
T{ peek## f 1 d: 1 }
|
||||
T{ peek## f 2 d: 2 }
|
||||
T{ peek## f 3 d: 3 }
|
||||
T{ set-slot-imm## f 2 1 1 0 }
|
||||
T{ slot-imm## f 4 0 1 0 }
|
||||
T{ set-slot-imm## f 3 1 1 0 }
|
||||
}
|
||||
} [
|
||||
V{
|
||||
T{ ##peek f 0 D: 0 }
|
||||
T{ ##peek f 1 D: 1 }
|
||||
T{ ##peek f 2 D: 2 }
|
||||
T{ ##peek f 3 D: 3 }
|
||||
T{ ##set-slot-imm f 2 1 1 0 }
|
||||
T{ ##slot-imm f 4 0 1 0 }
|
||||
T{ ##set-slot-imm f 3 1 1 0 }
|
||||
T{ peek## f 0 d: 0 }
|
||||
T{ peek## f 1 d: 1 }
|
||||
T{ peek## f 2 d: 2 }
|
||||
T{ peek## f 3 d: 3 }
|
||||
T{ set-slot-imm## f 2 1 1 0 }
|
||||
T{ slot-imm## f 4 0 1 0 }
|
||||
T{ set-slot-imm## f 3 1 1 0 }
|
||||
} test-alias-analysis
|
||||
] unit-test
|
||||
|
||||
! There's a redundant load, but not a redundant store
|
||||
{
|
||||
V{
|
||||
T{ ##peek f 0 D: 0 }
|
||||
T{ ##peek f 1 D: 1 }
|
||||
T{ ##peek f 2 D: 2 }
|
||||
T{ ##peek f 3 D: 3 }
|
||||
T{ ##slot-imm f 4 0 1 0 }
|
||||
T{ ##set-slot-imm f 2 0 1 0 }
|
||||
T{ ##slot f 5 0 3 0 0 }
|
||||
T{ ##set-slot-imm f 3 0 1 0 }
|
||||
T{ ##copy f 6 3 any-rep }
|
||||
T{ peek## f 0 d: 0 }
|
||||
T{ peek## f 1 d: 1 }
|
||||
T{ peek## f 2 d: 2 }
|
||||
T{ peek## f 3 d: 3 }
|
||||
T{ slot-imm## f 4 0 1 0 }
|
||||
T{ set-slot-imm## f 2 0 1 0 }
|
||||
T{ slot## f 5 0 3 0 0 }
|
||||
T{ set-slot-imm## f 3 0 1 0 }
|
||||
T{ copy## f 6 3 any-rep }
|
||||
}
|
||||
} [
|
||||
V{
|
||||
T{ ##peek f 0 D: 0 }
|
||||
T{ ##peek f 1 D: 1 }
|
||||
T{ ##peek f 2 D: 2 }
|
||||
T{ ##peek f 3 D: 3 }
|
||||
T{ ##slot-imm f 4 0 1 0 }
|
||||
T{ ##set-slot-imm f 2 0 1 0 }
|
||||
T{ ##slot f 5 0 3 0 0 }
|
||||
T{ ##set-slot-imm f 3 0 1 0 }
|
||||
T{ ##slot-imm f 6 0 1 0 }
|
||||
T{ peek## f 0 d: 0 }
|
||||
T{ peek## f 1 d: 1 }
|
||||
T{ peek## f 2 d: 2 }
|
||||
T{ peek## f 3 d: 3 }
|
||||
T{ slot-imm## f 4 0 1 0 }
|
||||
T{ set-slot-imm## f 2 0 1 0 }
|
||||
T{ slot## f 5 0 3 0 0 }
|
||||
T{ set-slot-imm## f 3 0 1 0 }
|
||||
T{ slot-imm## f 6 0 1 0 }
|
||||
} test-alias-analysis
|
||||
] unit-test
|
||||
|
||||
|
@ -182,45 +182,45 @@ IN: compiler.cfg.alias-analysis.tests
|
|||
! Redundant load elimination
|
||||
{
|
||||
V{
|
||||
T{ ##peek f 1 D: 1 }
|
||||
T{ ##peek f 2 D: 2 }
|
||||
T{ ##peek f 3 D: 3 }
|
||||
T{ ##allot f 4 16 array }
|
||||
T{ ##set-slot-imm f 3 4 1 0 }
|
||||
T{ ##set-slot-imm f 2 1 1 0 }
|
||||
T{ ##copy f 5 3 any-rep }
|
||||
T{ peek## f 1 d: 1 }
|
||||
T{ peek## f 2 d: 2 }
|
||||
T{ peek## f 3 d: 3 }
|
||||
T{ allot## f 4 16 array }
|
||||
T{ set-slot-imm## f 3 4 1 0 }
|
||||
T{ set-slot-imm## f 2 1 1 0 }
|
||||
T{ copy## f 5 3 any-rep }
|
||||
}
|
||||
} [
|
||||
V{
|
||||
T{ ##peek f 1 D: 1 }
|
||||
T{ ##peek f 2 D: 2 }
|
||||
T{ ##peek f 3 D: 3 }
|
||||
T{ ##allot f 4 16 array }
|
||||
T{ ##set-slot-imm f 3 4 1 0 }
|
||||
T{ ##set-slot-imm f 2 1 1 0 }
|
||||
T{ ##slot-imm f 5 4 1 0 }
|
||||
T{ peek## f 1 d: 1 }
|
||||
T{ peek## f 2 d: 2 }
|
||||
T{ peek## f 3 d: 3 }
|
||||
T{ allot## f 4 16 array }
|
||||
T{ set-slot-imm## f 3 4 1 0 }
|
||||
T{ set-slot-imm## f 2 1 1 0 }
|
||||
T{ slot-imm## f 5 4 1 0 }
|
||||
} test-alias-analysis
|
||||
] unit-test
|
||||
|
||||
! Redundant store elimination
|
||||
{
|
||||
V{
|
||||
T{ ##peek f 1 D: 1 }
|
||||
T{ ##peek f 2 D: 2 }
|
||||
T{ ##peek f 3 D: 3 }
|
||||
T{ ##allot f 4 16 array }
|
||||
T{ ##slot-imm f 5 1 1 0 }
|
||||
T{ ##set-slot-imm f 3 4 1 0 }
|
||||
T{ peek## f 1 d: 1 }
|
||||
T{ peek## f 2 d: 2 }
|
||||
T{ peek## f 3 d: 3 }
|
||||
T{ allot## f 4 16 array }
|
||||
T{ slot-imm## f 5 1 1 0 }
|
||||
T{ set-slot-imm## f 3 4 1 0 }
|
||||
}
|
||||
} [
|
||||
V{
|
||||
T{ ##peek f 1 D: 1 }
|
||||
T{ ##peek f 2 D: 2 }
|
||||
T{ ##peek f 3 D: 3 }
|
||||
T{ ##allot f 4 16 array }
|
||||
T{ ##set-slot-imm f 1 4 1 0 }
|
||||
T{ ##slot-imm f 5 1 1 0 }
|
||||
T{ ##set-slot-imm f 3 4 1 0 }
|
||||
T{ peek## f 1 d: 1 }
|
||||
T{ peek## f 2 d: 2 }
|
||||
T{ peek## f 3 d: 3 }
|
||||
T{ allot## f 4 16 array }
|
||||
T{ set-slot-imm## f 1 4 1 0 }
|
||||
T{ slot-imm## f 5 1 1 0 }
|
||||
T{ set-slot-imm## f 3 4 1 0 }
|
||||
} test-alias-analysis
|
||||
] unit-test
|
||||
|
||||
|
@ -228,63 +228,63 @@ IN: compiler.cfg.alias-analysis.tests
|
|||
! can now alias the new ac
|
||||
{
|
||||
V{
|
||||
T{ ##peek f 0 D: 0 }
|
||||
T{ ##peek f 1 D: 1 }
|
||||
T{ ##peek f 2 D: 2 }
|
||||
T{ ##peek f 3 D: 3 }
|
||||
T{ ##allot f 4 16 array }
|
||||
T{ ##set-slot-imm f 0 4 1 0 }
|
||||
T{ ##set-slot-imm f 4 2 1 0 }
|
||||
T{ ##slot-imm f 5 3 1 0 }
|
||||
T{ ##set-slot-imm f 1 5 1 0 }
|
||||
T{ ##slot-imm f 6 4 1 0 }
|
||||
T{ peek## f 0 d: 0 }
|
||||
T{ peek## f 1 d: 1 }
|
||||
T{ peek## f 2 d: 2 }
|
||||
T{ peek## f 3 d: 3 }
|
||||
T{ allot## f 4 16 array }
|
||||
T{ set-slot-imm## f 0 4 1 0 }
|
||||
T{ set-slot-imm## f 4 2 1 0 }
|
||||
T{ slot-imm## f 5 3 1 0 }
|
||||
T{ set-slot-imm## f 1 5 1 0 }
|
||||
T{ slot-imm## f 6 4 1 0 }
|
||||
}
|
||||
} [
|
||||
V{
|
||||
T{ ##peek f 0 D: 0 }
|
||||
T{ ##peek f 1 D: 1 }
|
||||
T{ ##peek f 2 D: 2 }
|
||||
T{ ##peek f 3 D: 3 }
|
||||
T{ ##allot f 4 16 array }
|
||||
T{ ##set-slot-imm f 0 4 1 0 }
|
||||
T{ ##set-slot-imm f 4 2 1 0 }
|
||||
T{ ##slot-imm f 5 3 1 0 }
|
||||
T{ ##set-slot-imm f 1 5 1 0 }
|
||||
T{ ##slot-imm f 6 4 1 0 }
|
||||
T{ peek## f 0 d: 0 }
|
||||
T{ peek## f 1 d: 1 }
|
||||
T{ peek## f 2 d: 2 }
|
||||
T{ peek## f 3 d: 3 }
|
||||
T{ allot## f 4 16 array }
|
||||
T{ set-slot-imm## f 0 4 1 0 }
|
||||
T{ set-slot-imm## f 4 2 1 0 }
|
||||
T{ slot-imm## f 5 3 1 0 }
|
||||
T{ set-slot-imm## f 1 5 1 0 }
|
||||
T{ slot-imm## f 6 4 1 0 }
|
||||
} test-alias-analysis
|
||||
] unit-test
|
||||
|
||||
! Compares between objects which cannot alias are eliminated
|
||||
{
|
||||
V{
|
||||
T{ ##peek f 0 D: 0 }
|
||||
T{ ##allot f 1 16 array }
|
||||
T{ ##load-reference f 2 f }
|
||||
T{ peek## f 0 d: 0 }
|
||||
T{ allot## f 1 16 array }
|
||||
T{ load-reference## f 2 f }
|
||||
}
|
||||
} [
|
||||
V{
|
||||
T{ ##peek f 0 D: 0 }
|
||||
T{ ##allot f 1 16 array }
|
||||
T{ ##compare f 2 0 1 cc= }
|
||||
T{ peek## f 0 d: 0 }
|
||||
T{ allot## f 1 16 array }
|
||||
T{ compare## f 2 0 1 cc= }
|
||||
} test-alias-analysis
|
||||
] unit-test
|
||||
|
||||
! Make sure that input to ##box-displaced-alien becomes heap-ac
|
||||
! Make sure that input to box-displaced-alien## becomes heap-ac
|
||||
{
|
||||
V{
|
||||
T{ ##allot f 1 16 byte-array }
|
||||
T{ ##load-reference f 2 10 }
|
||||
T{ ##box-displaced-alien f 3 2 1 4 byte-array }
|
||||
T{ ##slot-imm f 5 3 1 $[ alien type-number ] }
|
||||
T{ ##compare f 6 5 1 cc= }
|
||||
T{ allot## f 1 16 byte-array }
|
||||
T{ load-reference## f 2 10 }
|
||||
T{ box-displaced-alien## f 3 2 1 4 byte-array }
|
||||
T{ slot-imm## f 5 3 1 $[ alien type-number ] }
|
||||
T{ compare## f 6 5 1 cc= }
|
||||
}
|
||||
} [
|
||||
V{
|
||||
T{ ##allot f 1 16 byte-array }
|
||||
T{ ##load-reference f 2 10 }
|
||||
T{ ##box-displaced-alien f 3 2 1 4 byte-array }
|
||||
T{ ##slot-imm f 5 3 1 $[ alien type-number ] }
|
||||
T{ ##compare f 6 5 1 cc= }
|
||||
T{ allot## f 1 16 byte-array }
|
||||
T{ load-reference## f 2 10 }
|
||||
T{ box-displaced-alien## f 3 2 1 4 byte-array }
|
||||
T{ slot-imm## f 5 3 1 $[ alien type-number ] }
|
||||
T{ compare## f 6 5 1 cc= }
|
||||
} test-alias-analysis
|
||||
] unit-test
|
||||
|
||||
|
@ -292,71 +292,71 @@ IN: compiler.cfg.alias-analysis.tests
|
|||
! instructions which can call back into Factor code
|
||||
{
|
||||
V{
|
||||
T{ ##peek f 0 D: 0 }
|
||||
T{ ##slot-imm f 1 0 1 0 }
|
||||
T{ ##alien-invoke f { } { } { } { } 0 0 "free" }
|
||||
T{ ##slot-imm f 2 0 1 0 }
|
||||
T{ peek## f 0 d: 0 }
|
||||
T{ slot-imm## f 1 0 1 0 }
|
||||
T{ alien-invoke## f { } { } { } { } 0 0 "free" }
|
||||
T{ slot-imm## f 2 0 1 0 }
|
||||
}
|
||||
} [
|
||||
V{
|
||||
T{ ##peek f 0 D: 0 }
|
||||
T{ ##slot-imm f 1 0 1 0 }
|
||||
T{ ##alien-invoke f { } { } { } { } 0 0 "free" }
|
||||
T{ ##slot-imm f 2 0 1 0 }
|
||||
T{ peek## f 0 d: 0 }
|
||||
T{ slot-imm## f 1 0 1 0 }
|
||||
T{ alien-invoke## f { } { } { } { } 0 0 "free" }
|
||||
T{ slot-imm## f 2 0 1 0 }
|
||||
} test-alias-analysis
|
||||
] unit-test
|
||||
|
||||
{
|
||||
V{
|
||||
T{ ##peek f 0 D: 0 }
|
||||
T{ ##peek f 1 D: 1 }
|
||||
T{ ##set-slot-imm f 1 0 1 0 }
|
||||
T{ ##alien-invoke f { } { } { } { } 0 0 "free" }
|
||||
T{ ##slot-imm f 2 0 1 0 }
|
||||
T{ peek## f 0 d: 0 }
|
||||
T{ peek## f 1 d: 1 }
|
||||
T{ set-slot-imm## f 1 0 1 0 }
|
||||
T{ alien-invoke## f { } { } { } { } 0 0 "free" }
|
||||
T{ slot-imm## f 2 0 1 0 }
|
||||
}
|
||||
} [
|
||||
V{
|
||||
T{ ##peek f 0 D: 0 }
|
||||
T{ ##peek f 1 D: 1 }
|
||||
T{ ##set-slot-imm f 1 0 1 0 }
|
||||
T{ ##alien-invoke f { } { } { } { } 0 0 "free" }
|
||||
T{ ##slot-imm f 2 0 1 0 }
|
||||
T{ peek## f 0 d: 0 }
|
||||
T{ peek## f 1 d: 1 }
|
||||
T{ set-slot-imm## f 1 0 1 0 }
|
||||
T{ alien-invoke## f { } { } { } { } 0 0 "free" }
|
||||
T{ slot-imm## f 2 0 1 0 }
|
||||
} test-alias-analysis
|
||||
] unit-test
|
||||
|
||||
{
|
||||
V{
|
||||
T{ ##peek f 0 D: 0 }
|
||||
T{ ##peek f 1 D: 1 }
|
||||
T{ ##peek f 2 D: 2 }
|
||||
T{ ##set-slot-imm f 1 0 1 0 }
|
||||
T{ ##alien-invoke f { } { } { } { } 0 0 "free" }
|
||||
T{ ##set-slot-imm f 2 0 1 0 }
|
||||
T{ peek## f 0 d: 0 }
|
||||
T{ peek## f 1 d: 1 }
|
||||
T{ peek## f 2 d: 2 }
|
||||
T{ set-slot-imm## f 1 0 1 0 }
|
||||
T{ alien-invoke## f { } { } { } { } 0 0 "free" }
|
||||
T{ set-slot-imm## f 2 0 1 0 }
|
||||
}
|
||||
} [
|
||||
V{
|
||||
T{ ##peek f 0 D: 0 }
|
||||
T{ ##peek f 1 D: 1 }
|
||||
T{ ##peek f 2 D: 2 }
|
||||
T{ ##set-slot-imm f 1 0 1 0 }
|
||||
T{ ##alien-invoke f { } { } { } { } 0 0 "free" }
|
||||
T{ ##set-slot-imm f 2 0 1 0 }
|
||||
T{ peek## f 0 d: 0 }
|
||||
T{ peek## f 1 d: 1 }
|
||||
T{ peek## f 2 d: 2 }
|
||||
T{ set-slot-imm## f 1 0 1 0 }
|
||||
T{ alien-invoke## f { } { } { } { } 0 0 "free" }
|
||||
T{ set-slot-imm## f 2 0 1 0 }
|
||||
} test-alias-analysis
|
||||
] unit-test
|
||||
|
||||
{
|
||||
V{
|
||||
T{ ##peek f 0 D: 0 }
|
||||
T{ ##slot-imm f 1 0 1 0 }
|
||||
T{ ##alien-invoke f { } { } { } { } 0 0 "free" }
|
||||
T{ ##set-slot-imm f 1 0 1 0 }
|
||||
T{ peek## f 0 d: 0 }
|
||||
T{ slot-imm## f 1 0 1 0 }
|
||||
T{ alien-invoke## f { } { } { } { } 0 0 "free" }
|
||||
T{ set-slot-imm## f 1 0 1 0 }
|
||||
}
|
||||
} [
|
||||
V{
|
||||
T{ ##peek f 0 D: 0 }
|
||||
T{ ##slot-imm f 1 0 1 0 }
|
||||
T{ ##alien-invoke f { } { } { } { } 0 0 "free" }
|
||||
T{ ##set-slot-imm f 1 0 1 0 }
|
||||
T{ peek## f 0 d: 0 }
|
||||
T{ slot-imm## f 1 0 1 0 }
|
||||
T{ alien-invoke## f { } { } { } { } 0 0 "free" }
|
||||
T{ set-slot-imm## f 1 0 1 0 }
|
||||
} test-alias-analysis
|
||||
] unit-test
|
||||
|
||||
|
@ -364,70 +364,70 @@ IN: compiler.cfg.alias-analysis.tests
|
|||
! instruction
|
||||
{
|
||||
V{
|
||||
T{ ##allot f 0 }
|
||||
T{ ##slot-imm f 1 0 1 0 }
|
||||
T{ ##alien-invoke f { } { } { } { } 0 0 "free" }
|
||||
T{ ##copy f 2 1 any-rep }
|
||||
T{ allot## f 0 }
|
||||
T{ slot-imm## f 1 0 1 0 }
|
||||
T{ alien-invoke## f { } { } { } { } 0 0 "free" }
|
||||
T{ copy## f 2 1 any-rep }
|
||||
}
|
||||
} [
|
||||
V{
|
||||
T{ ##allot f 0 }
|
||||
T{ ##slot-imm f 1 0 1 0 }
|
||||
T{ ##alien-invoke f { } { } { } { } 0 0 "free" }
|
||||
T{ ##slot-imm f 2 0 1 0 }
|
||||
T{ allot## f 0 }
|
||||
T{ slot-imm## f 1 0 1 0 }
|
||||
T{ alien-invoke## f { } { } { } { } 0 0 "free" }
|
||||
T{ slot-imm## f 2 0 1 0 }
|
||||
} test-alias-analysis
|
||||
] unit-test
|
||||
|
||||
{
|
||||
V{
|
||||
T{ ##allot f 0 }
|
||||
T{ ##peek f 1 D: 1 }
|
||||
T{ ##set-slot-imm f 1 0 1 0 }
|
||||
T{ ##alien-invoke f { } { } { } { } 0 0 "free" }
|
||||
T{ ##copy f 2 1 any-rep }
|
||||
T{ allot## f 0 }
|
||||
T{ peek## f 1 d: 1 }
|
||||
T{ set-slot-imm## f 1 0 1 0 }
|
||||
T{ alien-invoke## f { } { } { } { } 0 0 "free" }
|
||||
T{ copy## f 2 1 any-rep }
|
||||
}
|
||||
} [
|
||||
V{
|
||||
T{ ##allot f 0 }
|
||||
T{ ##peek f 1 D: 1 }
|
||||
T{ ##set-slot-imm f 1 0 1 0 }
|
||||
T{ ##alien-invoke f { } { } { } { } 0 0 "free" }
|
||||
T{ ##slot-imm f 2 0 1 0 }
|
||||
T{ allot## f 0 }
|
||||
T{ peek## f 1 d: 1 }
|
||||
T{ set-slot-imm## f 1 0 1 0 }
|
||||
T{ alien-invoke## f { } { } { } { } 0 0 "free" }
|
||||
T{ slot-imm## f 2 0 1 0 }
|
||||
} test-alias-analysis
|
||||
] unit-test
|
||||
|
||||
{
|
||||
V{
|
||||
T{ ##allot f 0 }
|
||||
T{ ##peek f 1 D: 1 }
|
||||
T{ ##peek f 2 D: 2 }
|
||||
T{ ##set-slot-imm f 1 0 1 0 }
|
||||
T{ ##alien-invoke f { } { } { } { } 0 0 "free" }
|
||||
T{ ##set-slot-imm f 2 0 1 0 }
|
||||
T{ allot## f 0 }
|
||||
T{ peek## f 1 d: 1 }
|
||||
T{ peek## f 2 d: 2 }
|
||||
T{ set-slot-imm## f 1 0 1 0 }
|
||||
T{ alien-invoke## f { } { } { } { } 0 0 "free" }
|
||||
T{ set-slot-imm## f 2 0 1 0 }
|
||||
}
|
||||
} [
|
||||
V{
|
||||
T{ ##allot f 0 }
|
||||
T{ ##peek f 1 D: 1 }
|
||||
T{ ##peek f 2 D: 2 }
|
||||
T{ ##set-slot-imm f 1 0 1 0 }
|
||||
T{ ##alien-invoke f { } { } { } { } 0 0 "free" }
|
||||
T{ ##set-slot-imm f 2 0 1 0 }
|
||||
T{ allot## f 0 }
|
||||
T{ peek## f 1 d: 1 }
|
||||
T{ peek## f 2 d: 2 }
|
||||
T{ set-slot-imm## f 1 0 1 0 }
|
||||
T{ alien-invoke## f { } { } { } { } 0 0 "free" }
|
||||
T{ set-slot-imm## f 2 0 1 0 }
|
||||
} test-alias-analysis
|
||||
] unit-test
|
||||
|
||||
{
|
||||
V{
|
||||
T{ ##allot f 0 }
|
||||
T{ ##slot-imm f 1 0 1 0 }
|
||||
T{ ##alien-invoke f { } { } { } { } 0 0 "free" }
|
||||
T{ allot## f 0 }
|
||||
T{ slot-imm## f 1 0 1 0 }
|
||||
T{ alien-invoke## f { } { } { } { } 0 0 "free" }
|
||||
}
|
||||
} [
|
||||
V{
|
||||
T{ ##allot f 0 }
|
||||
T{ ##slot-imm f 1 0 1 0 }
|
||||
T{ ##alien-invoke f { } { } { } { } 0 0 "free" }
|
||||
T{ ##set-slot-imm f 1 0 1 0 }
|
||||
T{ allot## f 0 }
|
||||
T{ slot-imm## f 1 0 1 0 }
|
||||
T{ alien-invoke## f { } { } { } { } 0 0 "free" }
|
||||
T{ set-slot-imm## f 1 0 1 0 }
|
||||
} test-alias-analysis
|
||||
] unit-test
|
||||
|
||||
|
@ -435,14 +435,14 @@ IN: compiler.cfg.alias-analysis.tests
|
|||
! handled properly
|
||||
{
|
||||
V{
|
||||
T{ ##allot f 0 }
|
||||
T{ ##alien-indirect f f { } { } { { 2 double-rep 0 } } { } 0 0 "free" }
|
||||
T{ ##set-slot-imm f 2 0 1 0 }
|
||||
T{ allot## f 0 }
|
||||
T{ alien-indirect## f f { } { } { { 2 double-rep 0 } } { } 0 0 "free" }
|
||||
T{ set-slot-imm## f 2 0 1 0 }
|
||||
}
|
||||
} [
|
||||
V{
|
||||
T{ ##allot f 0 }
|
||||
T{ ##alien-indirect f f { } { } { { 2 double-rep 0 } } { } 0 0 "free" }
|
||||
T{ ##set-slot-imm f 2 0 1 0 }
|
||||
T{ allot## f 0 }
|
||||
T{ alien-indirect## f f { } { } { { 2 double-rep 0 } } { } 0 0 "free" }
|
||||
T{ set-slot-imm## f 2 0 1 0 }
|
||||
} test-alias-analysis
|
||||
] unit-test
|
||||
|
|
|
@ -12,7 +12,7 @@ SYMBOL: copies
|
|||
|
||||
: resolve ( vreg -- vreg ) copies get ?at drop ;
|
||||
|
||||
: record-copy ( ##copy -- )
|
||||
: record-copy ( copy## -- )
|
||||
[ src>> resolve ] [ dst>> ] bi copies get set-at ; inline
|
||||
|
||||
! Map vregs -> alias classes
|
||||
|
@ -30,8 +30,8 @@ SYMBOL: heap-ac
|
|||
acs>vregs get [ drop V{ } clone ] cache ;
|
||||
|
||||
: vreg>ac ( vreg -- ac )
|
||||
! Only vregs produced by ##allot, ##peek and ##slot can
|
||||
! ever be used as valid inputs to ##slot and ##set-slot,
|
||||
! Only vregs produced by allot##, peek## and slot## can
|
||||
! ever be used as valid inputs to slot## and set-slot##,
|
||||
! so we assert this fact by not giving alias classes to
|
||||
! other vregs.
|
||||
vregs>acs get [ heap-ac get [ ac>vregs push ] keep ] cache ;
|
||||
|
@ -58,7 +58,7 @@ SYMBOL: live-slots
|
|||
! Maps vreg -> slot# -> insn# of last store or f
|
||||
SYMBOL: recent-stores
|
||||
|
||||
! A set of insn#s of dead stores
|
||||
! A set of insns# of dead stores
|
||||
SYMBOL: dead-stores
|
||||
|
||||
: dead-store ( insn# -- ) dead-stores get adjoin ;
|
||||
|
@ -136,21 +136,21 @@ SYMBOL: ac-counter
|
|||
GENERIC: insn-slot# ( insn -- slot#/f )
|
||||
GENERIC: insn-object ( insn -- vreg )
|
||||
|
||||
M: ##slot insn-slot# drop f ;
|
||||
M: ##slot-imm insn-slot# slot>> ;
|
||||
M: ##set-slot insn-slot# drop f ;
|
||||
M: ##set-slot-imm insn-slot# slot>> ;
|
||||
M: ##alien-global insn-slot# [ library>> ] [ symbol>> ] bi 2array ;
|
||||
M: ##vm-field insn-slot# offset>> ;
|
||||
M: ##set-vm-field insn-slot# offset>> ;
|
||||
M: slot## insn-slot# drop f ;
|
||||
M: slot-imm## insn-slot# slot>> ;
|
||||
M: set-slot## insn-slot# drop f ;
|
||||
M: set-slot-imm## insn-slot# slot>> ;
|
||||
M: alien-global## insn-slot# [ library>> ] [ symbol>> ] bi 2array ;
|
||||
M: vm-field## insn-slot# offset>> ;
|
||||
M: set-vm-field## insn-slot# offset>> ;
|
||||
|
||||
M: ##slot insn-object obj>> resolve ;
|
||||
M: ##slot-imm insn-object obj>> resolve ;
|
||||
M: ##set-slot insn-object obj>> resolve ;
|
||||
M: ##set-slot-imm insn-object obj>> resolve ;
|
||||
M: ##alien-global insn-object drop ##alien-global ;
|
||||
M: ##vm-field insn-object drop ##vm-field ;
|
||||
M: ##set-vm-field insn-object drop ##vm-field ;
|
||||
M: slot## insn-object obj>> resolve ;
|
||||
M: slot-imm## insn-object obj>> resolve ;
|
||||
M: set-slot## insn-object obj>> resolve ;
|
||||
M: set-slot-imm## insn-object obj>> resolve ;
|
||||
M: alien-global## insn-object drop alien-global## ;
|
||||
M: vm-field## insn-object drop vm-field## ;
|
||||
M: set-vm-field## insn-object drop vm-field## ;
|
||||
|
||||
GENERIC: analyze-aliases ( insn -- insn' )
|
||||
|
||||
|
@ -175,7 +175,7 @@ M: allocation-insn analyze-aliases
|
|||
! object.
|
||||
dup dst>> set-new-ac ;
|
||||
|
||||
M: ##box-displaced-alien analyze-aliases
|
||||
M: box-displaced-alien## analyze-aliases
|
||||
[ call-next-method ]
|
||||
[ base>> heap-ac get merge-acs ] bi ;
|
||||
|
||||
|
@ -206,7 +206,7 @@ M:: write-insn analyze-aliases ( insn -- insn )
|
|||
|
||||
insn ;
|
||||
|
||||
M: ##copy analyze-aliases
|
||||
M: copy## analyze-aliases
|
||||
! The output vreg gets the same alias class as the input
|
||||
! vreg, since they both contain the same value.
|
||||
dup record-copy ;
|
||||
|
@ -217,10 +217,10 @@ M: ##copy analyze-aliases
|
|||
[ [ src1>> ] [ src2>> ] bi [ resolve vreg>ac ] same? not ]
|
||||
} 1&& ; inline
|
||||
|
||||
M: ##compare analyze-aliases
|
||||
M: compare## analyze-aliases
|
||||
call-next-method
|
||||
dup useless-compare? [
|
||||
dst>> f ##load-reference new-insn
|
||||
dst>> f load-reference## new-insn
|
||||
analyze-aliases
|
||||
] when ;
|
||||
|
||||
|
@ -242,7 +242,7 @@ M: alien-call-insn analyze-aliases
|
|||
|
||||
GENERIC: eliminate-dead-stores ( insn -- ? )
|
||||
|
||||
M: ##set-slot-imm eliminate-dead-stores
|
||||
M: set-slot-imm## eliminate-dead-stores
|
||||
insn#>> dead-stores get in? not ;
|
||||
|
||||
M: insn eliminate-dead-stores drop t ;
|
||||
|
@ -256,8 +256,8 @@ M: insn eliminate-dead-stores drop t ;
|
|||
dead-stores get clear-set
|
||||
|
||||
next-ac heap-ac namespaces:set
|
||||
##vm-field set-new-ac
|
||||
##alien-global set-new-ac ;
|
||||
vm-field## set-new-ac
|
||||
alien-global## set-new-ac ;
|
||||
|
||||
: alias-analysis-step ( insns -- insns' )
|
||||
reset-alias-analysis
|
||||
|
|
|
@ -16,6 +16,6 @@ HELP: join-blocks
|
|||
{ $description "A compiler pass when optimizing the cfg." } ;
|
||||
|
||||
ARTICLE: "compiler.cfg.block-joining" "Block Joining"
|
||||
"Joining blocks that are not calls and are connected by a single CFG edge. This pass does not update " { $link ##phi } " nodes and should therefore only run before stack analysis or after ##phi node elimination." ;
|
||||
"Joining blocks that are not calls and are connected by a single CFG edge. This pass does not update " { $link phi## } " nodes and should therefore only run before stack analysis or after phi## node elimination." ;
|
||||
|
||||
ABOUT: "compiler.cfg.block-joining"
|
||||
|
|
|
@ -17,31 +17,31 @@ IN: compiler.cfg.branch-splitting.tests
|
|||
: test-branch-splitting ( -- )
|
||||
0 get block>cfg check-branch-splitting ;
|
||||
|
||||
V{ T{ ##branch } } 0 test-bb
|
||||
V{ T{ branch## } } 0 test-bb
|
||||
|
||||
V{ T{ ##branch } } 1 test-bb
|
||||
V{ T{ branch## } } 1 test-bb
|
||||
|
||||
V{ T{ ##branch } } 2 test-bb
|
||||
V{ T{ branch## } } 2 test-bb
|
||||
|
||||
V{ T{ ##branch } } 3 test-bb
|
||||
V{ T{ branch## } } 3 test-bb
|
||||
|
||||
V{ T{ ##branch } } 4 test-bb
|
||||
V{ T{ branch## } } 4 test-bb
|
||||
|
||||
test-diamond
|
||||
|
||||
{ } [ test-branch-splitting ] unit-test
|
||||
|
||||
V{ T{ ##branch } } 0 test-bb
|
||||
V{ T{ branch## } } 0 test-bb
|
||||
|
||||
V{ T{ ##branch } } 1 test-bb
|
||||
V{ T{ branch## } } 1 test-bb
|
||||
|
||||
V{ T{ ##branch } } 2 test-bb
|
||||
V{ T{ branch## } } 2 test-bb
|
||||
|
||||
V{ T{ ##branch } } 3 test-bb
|
||||
V{ T{ branch## } } 3 test-bb
|
||||
|
||||
V{ T{ ##branch } } 4 test-bb
|
||||
V{ T{ branch## } } 4 test-bb
|
||||
|
||||
V{ T{ ##branch } } 5 test-bb
|
||||
V{ T{ branch## } } 5 test-bb
|
||||
|
||||
0 { 1 2 } edges
|
||||
|
||||
|
@ -51,15 +51,15 @@ V{ T{ ##branch } } 5 test-bb
|
|||
|
||||
{ } [ test-branch-splitting ] unit-test
|
||||
|
||||
V{ T{ ##branch } } 0 test-bb
|
||||
V{ T{ branch## } } 0 test-bb
|
||||
|
||||
V{ T{ ##branch } } 1 test-bb
|
||||
V{ T{ branch## } } 1 test-bb
|
||||
|
||||
V{ T{ ##branch } } 2 test-bb
|
||||
V{ T{ branch## } } 2 test-bb
|
||||
|
||||
V{ T{ ##branch } } 3 test-bb
|
||||
V{ T{ branch## } } 3 test-bb
|
||||
|
||||
V{ T{ ##branch } } 4 test-bb
|
||||
V{ T{ branch## } } 4 test-bb
|
||||
|
||||
0 { 1 2 } edges
|
||||
|
||||
|
@ -69,11 +69,11 @@ V{ T{ ##branch } } 4 test-bb
|
|||
|
||||
{ } [ test-branch-splitting ] unit-test
|
||||
|
||||
V{ T{ ##branch } } 0 test-bb
|
||||
V{ T{ branch## } } 0 test-bb
|
||||
|
||||
V{ T{ ##branch } } 1 test-bb
|
||||
V{ T{ branch## } } 1 test-bb
|
||||
|
||||
V{ T{ ##branch } } 2 test-bb
|
||||
V{ T{ branch## } } 2 test-bb
|
||||
|
||||
0 { 1 2 } edges
|
||||
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue