mirror of
https://github.com/KevinMidboe/linguist.git
synced 2025-10-29 17:50:22 +00:00
Compare commits
460 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
470419d732 | ||
|
|
5b05653881 | ||
|
|
899dc07883 | ||
|
|
83dfd408e9 | ||
|
|
417171cfe1 | ||
|
|
e8e82a1ca3 | ||
|
|
6843aa7cc8 | ||
|
|
952acc983d | ||
|
|
650f267be7 | ||
|
|
3ace4c57f7 | ||
|
|
ab1b603c78 | ||
|
|
8430f694e5 | ||
|
|
71f0cafc78 | ||
|
|
4614287a55 | ||
|
|
f477f811df | ||
|
|
95bb5a1ae4 | ||
|
|
70699037ae | ||
|
|
7edddec920 | ||
|
|
8f3779c94c | ||
|
|
917bc48348 | ||
|
|
581dc36c47 | ||
|
|
a4286ba950 | ||
|
|
5fa85f268f | ||
|
|
ada6f6882a | ||
|
|
78a0030d46 | ||
|
|
e2d6aecd81 | ||
|
|
a2e99e8ddb | ||
|
|
b499a074cf | ||
|
|
188e579df7 | ||
|
|
d82e4801ff | ||
|
|
d258d146b8 | ||
|
|
ae6b0f0d40 | ||
|
|
2c2c4740a8 | ||
|
|
4428e62b99 | ||
|
|
575ad0d8a2 | ||
|
|
ec01672f6c | ||
|
|
be6b1bb3ee | ||
|
|
6f4557a103 | ||
|
|
55132f2955 | ||
|
|
ebdd2d4a23 | ||
|
|
4c63827517 | ||
|
|
8e6609c192 | ||
|
|
1f1ffcbfa6 | ||
|
|
065dd713c1 | ||
|
|
71132d48ff | ||
|
|
d77e0c62c1 | ||
|
|
e853c36039 | ||
|
|
2be3220824 | ||
|
|
6ae39e50ae | ||
|
|
c783acc973 | ||
|
|
e5210b5137 | ||
|
|
41f0950c04 | ||
|
|
9f439cd7fb | ||
|
|
c911c5c045 | ||
|
|
27a7873e08 | ||
|
|
5fe233384e | ||
|
|
d42ad45423 | ||
|
|
84235478ef | ||
|
|
509b35a19f | ||
|
|
65296e86a3 | ||
|
|
c9b7bb73b9 | ||
|
|
795f42cbaa | ||
|
|
d540ec0cb8 | ||
|
|
202cba1a14 | ||
|
|
20d5b81085 | ||
|
|
d8b806592d | ||
|
|
84f9b83fc2 | ||
|
|
7cb5106656 | ||
|
|
6f21df7624 | ||
|
|
4c7dc565e7 | ||
|
|
3c60fba430 | ||
|
|
224eef9ffa | ||
|
|
42beadcf34 | ||
|
|
80ed2d6d30 | ||
|
|
c2bf6fe7f5 | ||
|
|
6f014f8638 | ||
|
|
66ca5aca89 | ||
|
|
33afa30c30 | ||
|
|
1634d787ec | ||
|
|
df7b529e23 | ||
|
|
56d90bedd0 | ||
|
|
8369d253f8 | ||
|
|
516d3e226c | ||
|
|
47b785a8fd | ||
|
|
6a2bf3fd2f | ||
|
|
ff678642e6 | ||
|
|
e3eb1b90c5 | ||
|
|
49125f077c | ||
|
|
324031cb68 | ||
|
|
f2ab426d38 | ||
|
|
587ab35d65 | ||
|
|
16a6dda3dd | ||
|
|
15191b068d | ||
|
|
ee9cc24e52 | ||
|
|
0584fbf42b | ||
|
|
f5f9ccee7f | ||
|
|
0d183e2e89 | ||
|
|
b9eacfefc8 | ||
|
|
0239127db4 | ||
|
|
281d1ea91c | ||
|
|
df92ecaa55 | ||
|
|
60d40c8ad8 | ||
|
|
f428c561c9 | ||
|
|
8fbb7a1d93 | ||
|
|
e98223b2b3 | ||
|
|
410fe2843d | ||
|
|
dc8d69e0f4 | ||
|
|
a056765e38 | ||
|
|
4e7da98bfa | ||
|
|
0a56f5282d | ||
|
|
04b9ca2fd4 | ||
|
|
ddbe3df6de | ||
|
|
ab5c88a7f3 | ||
|
|
4046a0efe9 | ||
|
|
5aefc7cdff | ||
|
|
70eb779ce5 | ||
|
|
39f5d28348 | ||
|
|
e70407f16b | ||
|
|
c25475296d | ||
|
|
e97b7454e9 | ||
|
|
735caa03b1 | ||
|
|
f577aece08 | ||
|
|
b7f1bfdb92 | ||
|
|
b5301e280b | ||
|
|
741816db52 | ||
|
|
546a6e2a68 | ||
|
|
1be5e8c63e | ||
|
|
917a25317a | ||
|
|
949167e6ad | ||
|
|
a359905a06 | ||
|
|
4ce606306d | ||
|
|
707fcd29ea | ||
|
|
970cbe35b8 | ||
|
|
fa9e8aa5c0 | ||
|
|
a5e6d37049 | ||
|
|
dacac135fb | ||
|
|
0ddf0d5d0d | ||
|
|
90a5251fa7 | ||
|
|
a97c69e06f | ||
|
|
a323eb43ed | ||
|
|
79243b77fd | ||
|
|
5ab2720ddc | ||
|
|
c72a49b77f | ||
|
|
a0d92b80df | ||
|
|
1a32a6252b | ||
|
|
6df7cbaf6e | ||
|
|
0a90cd3a0a | ||
|
|
c529939481 | ||
|
|
db70630eaa | ||
|
|
24862d9759 | ||
|
|
cb5f2685cd | ||
|
|
baa298873a | ||
|
|
a8f57d37bf | ||
|
|
d97ee52f4e | ||
|
|
1cfdb6decd | ||
|
|
f93272f0bd | ||
|
|
e783e953d9 | ||
|
|
39cac919c7 | ||
|
|
fec82173d9 | ||
|
|
35efed73d4 | ||
|
|
21b8e16afc | ||
|
|
6efee51101 | ||
|
|
1490425ecb | ||
|
|
afac6a918d | ||
|
|
bf0e488c06 | ||
|
|
37c2bee3ae | ||
|
|
4debcabb88 | ||
|
|
5a0c637ad0 | ||
|
|
d91215680a | ||
|
|
0cbcbd4614 | ||
|
|
19135f08c3 | ||
|
|
855cc52f0f | ||
|
|
4e5da23474 | ||
|
|
3cca4ec0ac | ||
|
|
e393f7feb4 | ||
|
|
b76ac7bab0 | ||
|
|
a3c842ba18 | ||
|
|
1640370c9d | ||
|
|
b6427fa05a | ||
|
|
2a04d854cc | ||
|
|
6d190d7d7c | ||
|
|
b8a2bd595a | ||
|
|
8b7d5546f7 | ||
|
|
299a9c7bc9 | ||
|
|
37f8d5b5e1 | ||
|
|
2a6a59c047 | ||
|
|
583392d179 | ||
|
|
1488796779 | ||
|
|
7458a2f9ff | ||
|
|
348dab4b9f | ||
|
|
5c824e0771 | ||
|
|
b9c88a758c | ||
|
|
a51d637e58 | ||
|
|
d002dfa70c | ||
|
|
d118017d27 | ||
|
|
d10d328eb1 | ||
|
|
e472d7b8b1 | ||
|
|
a54d6f3a8a | ||
|
|
67ccb24b41 | ||
|
|
42ff3f58d9 | ||
|
|
ad778571a2 | ||
|
|
bb12b86445 | ||
|
|
ab61b06c34 | ||
|
|
de6b2f3307 | ||
|
|
5fd56c75d5 | ||
|
|
6aa70a3e93 | ||
|
|
93186947c2 | ||
|
|
77444284e3 | ||
|
|
6950b028df | ||
|
|
565767ef42 | ||
|
|
a1f26d64d5 | ||
|
|
be30e1c658 | ||
|
|
3aec4dd2ea | ||
|
|
ed34caa565 | ||
|
|
81b8c57bae | ||
|
|
0780b7239a | ||
|
|
1d626f7378 | ||
|
|
ff3438b810 | ||
|
|
1762c2cefd | ||
|
|
7aaf99c9b1 | ||
|
|
07cd9aa994 | ||
|
|
6ae4aa50e2 | ||
|
|
22fbcc244b | ||
|
|
1a3177409c | ||
|
|
de4b538d82 | ||
|
|
70b1ec97db | ||
|
|
a97e328484 | ||
|
|
e446b86b90 | ||
|
|
901e8da911 | ||
|
|
e9036d675e | ||
|
|
351e348ac0 | ||
|
|
feea9bfd30 | ||
|
|
f1282b857d | ||
|
|
70e0ce1d73 | ||
|
|
a5673e7fb6 | ||
|
|
d06529fd14 | ||
|
|
a02f19f5a3 | ||
|
|
a9a62fff15 | ||
|
|
7625c92307 | ||
|
|
7dd318ca76 | ||
|
|
e5bc2845cd | ||
|
|
4ddd8d9d2b | ||
|
|
37ffdb9020 | ||
|
|
39037d5bfb | ||
|
|
31d882b07e | ||
|
|
fd9275b213 | ||
|
|
cfa63cff35 | ||
|
|
5e6fd11cc2 | ||
|
|
62a8b52df4 | ||
|
|
783670095c | ||
|
|
23cfa86f93 | ||
|
|
dce00d01d9 | ||
|
|
768ec76ff0 | ||
|
|
211cb9567a | ||
|
|
1e68a45515 | ||
|
|
72c00f869c | ||
|
|
c76137efc0 | ||
|
|
88f196e4d4 | ||
|
|
4fe5980065 | ||
|
|
7c7b1fb9c4 | ||
|
|
ed3d38cf05 | ||
|
|
837e9a6325 | ||
|
|
1364e9be51 | ||
|
|
2fbfaf448d | ||
|
|
bf82caccfc | ||
|
|
325dbc8e16 | ||
|
|
bd2fb0af51 | ||
|
|
3c904dff61 | ||
|
|
9b22b2973f | ||
|
|
025bb35ac7 | ||
|
|
7fb5d0cadd | ||
|
|
8157c6f56b | ||
|
|
0154c21c3d | ||
|
|
8c841903a5 | ||
|
|
648596dbb2 | ||
|
|
212c74d8a3 | ||
|
|
4495e15fa7 | ||
|
|
da96e11b37 | ||
|
|
b7a9843770 | ||
|
|
55432774c7 | ||
|
|
ca76802ee4 | ||
|
|
cec54837bc | ||
|
|
e0c35b0665 | ||
|
|
865980b8f7 | ||
|
|
9367a4797f | ||
|
|
4ed58c743d | ||
|
|
cfd95360cb | ||
|
|
22144e79d3 | ||
|
|
3acbf06beb | ||
|
|
7b41346db8 | ||
|
|
878b321b89 | ||
|
|
a903123cb8 | ||
|
|
577fb95384 | ||
|
|
770a1d4553 | ||
|
|
c038b51941 | ||
|
|
4bebcef6ef | ||
|
|
d4888098e5 | ||
|
|
a349daeaeb | ||
|
|
b8685103d0 | ||
|
|
26d789612b | ||
|
|
7a57a0b594 | ||
|
|
66eabd8bdc | ||
|
|
be82b55408 | ||
|
|
526ca1761a | ||
|
|
10de952ed6 | ||
|
|
2517650ecb | ||
|
|
47b739527a | ||
|
|
8655d966ad | ||
|
|
3fb4973aab | ||
|
|
1d4149168d | ||
|
|
26ab33754f | ||
|
|
88f08803ee | ||
|
|
c05717d15c | ||
|
|
bc66f558b9 | ||
|
|
71e1bd9af2 | ||
|
|
57b0739219 | ||
|
|
d60241cc86 | ||
|
|
d725e8e385 | ||
|
|
034cb25099 | ||
|
|
fbc0947420 | ||
|
|
9020d7c044 | ||
|
|
ffe2ccf1f6 | ||
|
|
434ab9f2c0 | ||
|
|
cd3defda42 | ||
|
|
fd85f7f112 | ||
|
|
e42ccf0d82 | ||
|
|
bf4baff363 | ||
|
|
c1a9737313 | ||
|
|
a4081498f8 | ||
|
|
9efd923382 | ||
|
|
b16149d641 | ||
|
|
2d940e72c2 | ||
|
|
9f103abfb5 | ||
|
|
689a209ed9 | ||
|
|
d91a451fc7 | ||
|
|
1ae4672230 | ||
|
|
3edf5fd770 | ||
|
|
412af86cb8 | ||
|
|
5b41ab4774 | ||
|
|
06c0cb916b | ||
|
|
b3a49ce627 | ||
|
|
0651568bfb | ||
|
|
ce31e23006 | ||
|
|
7ccd8caf71 | ||
|
|
598a7028ea | ||
|
|
4ed1efe9ce | ||
|
|
6a4bf3fa65 | ||
|
|
5b2b3a2b53 | ||
|
|
596cd9368f | ||
|
|
f8d50faedb | ||
|
|
ccc9c197ae | ||
|
|
ed2dcc35e8 | ||
|
|
208a3ff480 | ||
|
|
6739a1471b | ||
|
|
230d91ecd8 | ||
|
|
8de2cd15ed | ||
|
|
4603f3b2e7 | ||
|
|
9d6b8b4715 | ||
|
|
7cbc4bc144 | ||
|
|
d239e71826 | ||
|
|
ecaa2a41c9 | ||
|
|
fc71805489 | ||
|
|
74d94781cb | ||
|
|
897c2c5ab6 | ||
|
|
b556425037 | ||
|
|
6131d17c02 | ||
|
|
875b3157bf | ||
|
|
4ce9048f8d | ||
|
|
04f1b1df48 | ||
|
|
f9c36345c3 | ||
|
|
ec3967d080 | ||
|
|
05a88b5b7e | ||
|
|
b6b2cf04a7 | ||
|
|
49247e9ec2 | ||
|
|
6629b75aa6 | ||
|
|
e702b453ec | ||
|
|
38190d92fc | ||
|
|
109ca5735b | ||
|
|
4dde499f51 | ||
|
|
5fd18a215e | ||
|
|
b283548c0f | ||
|
|
2352ce77c9 | ||
|
|
2054afc741 | ||
|
|
9d3b9964b5 | ||
|
|
79c1d21a0f | ||
|
|
1d69228872 | ||
|
|
f5953a09da | ||
|
|
a17f6c8ae1 | ||
|
|
9823af0cb4 | ||
|
|
45384bd498 | ||
|
|
56bfde998b | ||
|
|
870feb8592 | ||
|
|
2670e2b035 | ||
|
|
eccea65641 | ||
|
|
231ad86176 | ||
|
|
9658b02502 | ||
|
|
30c6b6e5a1 | ||
|
|
b44e58dd7f | ||
|
|
245a1a92cf | ||
|
|
aa7ab2065b | ||
|
|
1356d4e579 | ||
|
|
6c106b88c0 | ||
|
|
c46667581d | ||
|
|
3ca872cea8 | ||
|
|
9c64f72f35 | ||
|
|
95777055d1 | ||
|
|
42e9131b4f | ||
|
|
74fa4b9b75 | ||
|
|
815337299a | ||
|
|
fd32938cd8 | ||
|
|
8d7b4f81b4 | ||
|
|
2bc546eadf | ||
|
|
9e50e188a8 | ||
|
|
0c05a6c3ac | ||
|
|
d4d6ef314d | ||
|
|
322b21e0d0 | ||
|
|
32de8a4d19 | ||
|
|
cf9998f3e4 | ||
|
|
89320b1ca4 | ||
|
|
f3d654a965 | ||
|
|
2e6aae0256 | ||
|
|
12b78c5357 | ||
|
|
e70cd33323 | ||
|
|
302af86363 | ||
|
|
44eebde394 | ||
|
|
498c102414 | ||
|
|
79cd77454b | ||
|
|
410aace222 | ||
|
|
bde19a76cc | ||
|
|
49ebf4b303 | ||
|
|
0017310dd1 | ||
|
|
dad4b974b7 | ||
|
|
f1cb16648f | ||
|
|
1276f10b67 | ||
|
|
c3da262bd0 | ||
|
|
35355b157c | ||
|
|
2143699aab | ||
|
|
b1c2820299 | ||
|
|
624fd74f83 | ||
|
|
cd878522d9 | ||
|
|
10fed43c27 | ||
|
|
1d50adf87a | ||
|
|
614a61b0b0 | ||
|
|
bd380f44cc | ||
|
|
8a546d2a7a | ||
|
|
1148a9746a | ||
|
|
913cd6c309 | ||
|
|
81d9c682da | ||
|
|
492aa12cad | ||
|
|
e79e45a74e | ||
|
|
e661470bbb | ||
|
|
af30a80702 | ||
|
|
bab7ee4fcb | ||
|
|
6524ac3588 | ||
|
|
c432cd67fc | ||
|
|
5c071a2e07 | ||
|
|
cb10c53dee | ||
|
|
dfba2a31a5 | ||
|
|
667f3de26b | ||
|
|
fd585beb07 |
2
.gitignore
vendored
2
.gitignore
vendored
@@ -4,3 +4,5 @@ benchmark/
|
||||
lib/linguist/samples.json
|
||||
/grammars
|
||||
/node_modules
|
||||
test/fixtures/ace_modes.json
|
||||
/vendor/gems/
|
||||
|
||||
536
.gitmodules
vendored
Normal file
536
.gitmodules
vendored
Normal file
@@ -0,0 +1,536 @@
|
||||
[submodule "vendor/grammars/go-tmbundle"]
|
||||
path = vendor/grammars/go-tmbundle
|
||||
url = https://github.com/AlanQuatermain/go-tmbundle
|
||||
[submodule "vendor/grammars/PHP-Twig.tmbundle"]
|
||||
path = vendor/grammars/PHP-Twig.tmbundle
|
||||
url = https://github.com/Anomareh/PHP-Twig.tmbundle
|
||||
[submodule "vendor/grammars/sublime-cirru"]
|
||||
path = vendor/grammars/sublime-cirru
|
||||
url = https://github.com/Cirru/sublime-cirru
|
||||
[submodule "vendor/grammars/Sublime-Logos"]
|
||||
path = vendor/grammars/Sublime-Logos
|
||||
url = https://github.com/Cykey/Sublime-Logos
|
||||
[submodule "vendor/grammars/SublimeBrainfuck"]
|
||||
path = vendor/grammars/SublimeBrainfuck
|
||||
url = https://github.com/Drako/SublimeBrainfuck
|
||||
[submodule "vendor/grammars/awk-sublime"]
|
||||
path = vendor/grammars/awk-sublime
|
||||
url = https://github.com/JohnNilsson/awk-sublime
|
||||
[submodule "vendor/grammars/Sublime-SQF-Language"]
|
||||
path = vendor/grammars/Sublime-SQF-Language
|
||||
url = https://github.com/JonBons/Sublime-SQF-Language
|
||||
[submodule "vendor/grammars/SCSS.tmbundle"]
|
||||
path = vendor/grammars/SCSS.tmbundle
|
||||
url = https://github.com/MarioRicalde/SCSS.tmbundle
|
||||
[submodule "vendor/grammars/Sublime-REBOL"]
|
||||
path = vendor/grammars/Sublime-REBOL
|
||||
url = https://github.com/Oldes/Sublime-REBOL
|
||||
[submodule "vendor/grammars/Sublime-Inform"]
|
||||
path = vendor/grammars/Sublime-Inform
|
||||
url = https://github.com/PogiNate/Sublime-Inform
|
||||
[submodule "vendor/grammars/autoitv3-tmbundle"]
|
||||
path = vendor/grammars/autoitv3-tmbundle
|
||||
url = https://github.com/Red-Nova-Technologies/autoitv3-tmbundle
|
||||
[submodule "vendor/grammars/Sublime-VimL"]
|
||||
path = vendor/grammars/Sublime-VimL
|
||||
url = https://github.com/SalGnt/Sublime-VimL
|
||||
[submodule "vendor/grammars/boo-sublime"]
|
||||
path = vendor/grammars/boo-sublime
|
||||
url = https://github.com/Shammah/boo-sublime
|
||||
[submodule "vendor/grammars/ColdFusion"]
|
||||
path = vendor/grammars/ColdFusion
|
||||
url = https://github.com/SublimeText/ColdFusion
|
||||
[submodule "vendor/grammars/NSIS"]
|
||||
path = vendor/grammars/NSIS
|
||||
url = https://github.com/SublimeText/NSIS
|
||||
[submodule "vendor/grammars/NimLime"]
|
||||
path = vendor/grammars/NimLime
|
||||
url = https://github.com/Varriount/NimLime
|
||||
[submodule "vendor/grammars/gradle.tmbundle"]
|
||||
path = vendor/grammars/gradle.tmbundle
|
||||
url = https://github.com/alkemist/gradle.tmbundle
|
||||
[submodule "vendor/grammars/Sublime-Loom"]
|
||||
path = vendor/grammars/Sublime-Loom
|
||||
url = https://github.com/ambethia/Sublime-Loom
|
||||
[submodule "vendor/grammars/VBDotNetSyntax"]
|
||||
path = vendor/grammars/VBDotNetSyntax
|
||||
url = https://github.com/angryant0007/VBDotNetSyntax
|
||||
[submodule "vendor/grammars/cool-tmbundle"]
|
||||
path = vendor/grammars/cool-tmbundle
|
||||
url = https://github.com/anunayk/cool-tmbundle
|
||||
[submodule "vendor/grammars/Docker.tmbundle"]
|
||||
path = vendor/grammars/Docker.tmbundle
|
||||
url = https://github.com/asbjornenge/Docker.tmbundle
|
||||
[submodule "vendor/grammars/jasmin-sublime"]
|
||||
path = vendor/grammars/jasmin-sublime
|
||||
url = https://github.com/atmarksharp/jasmin-sublime
|
||||
[submodule "vendor/grammars/language-clojure"]
|
||||
path = vendor/grammars/language-clojure
|
||||
url = https://github.com/atom/language-clojure
|
||||
[submodule "vendor/grammars/language-coffee-script"]
|
||||
path = vendor/grammars/language-coffee-script
|
||||
url = https://github.com/atom/language-coffee-script
|
||||
[submodule "vendor/grammars/language-csharp"]
|
||||
path = vendor/grammars/language-csharp
|
||||
url = https://github.com/atom/language-csharp
|
||||
[submodule "vendor/grammars/language-gfm"]
|
||||
path = vendor/grammars/language-gfm
|
||||
url = https://github.com/atom/language-gfm
|
||||
[submodule "vendor/grammars/language-javascript"]
|
||||
path = vendor/grammars/language-javascript
|
||||
url = https://github.com/atom/language-javascript
|
||||
[submodule "vendor/grammars/language-python"]
|
||||
path = vendor/grammars/language-python
|
||||
url = https://github.com/atom/language-python
|
||||
[submodule "vendor/grammars/language-shellscript"]
|
||||
path = vendor/grammars/language-shellscript
|
||||
url = https://github.com/atom/language-shellscript
|
||||
[submodule "vendor/grammars/language-yaml"]
|
||||
path = vendor/grammars/language-yaml
|
||||
url = https://github.com/atom/language-yaml
|
||||
[submodule "vendor/grammars/sublime-sourcepawn"]
|
||||
path = vendor/grammars/sublime-sourcepawn
|
||||
url = https://github.com/austinwagner/sublime-sourcepawn
|
||||
[submodule "vendor/grammars/Sublime-Lasso"]
|
||||
path = vendor/grammars/Sublime-Lasso
|
||||
url = https://github.com/bfad/Sublime-Lasso
|
||||
[submodule "vendor/grammars/chapel-tmbundle"]
|
||||
path = vendor/grammars/chapel-tmbundle
|
||||
url = https://github.com/bholt/chapel-tmbundle
|
||||
[submodule "vendor/grammars/sublime-nginx"]
|
||||
path = vendor/grammars/sublime-nginx
|
||||
url = https://github.com/brandonwamboldt/sublime-nginx
|
||||
[submodule "vendor/grammars/bro-sublime"]
|
||||
path = vendor/grammars/bro-sublime
|
||||
url = https://github.com/bro/bro-sublime
|
||||
[submodule "vendor/grammars/sublime_man_page_support"]
|
||||
path = vendor/grammars/sublime_man_page_support
|
||||
url = https://github.com/carsonoid/sublime_man_page_support
|
||||
[submodule "vendor/grammars/sublime-MuPAD"]
|
||||
path = vendor/grammars/sublime-MuPAD
|
||||
url = https://github.com/ccreutzig/sublime-MuPAD
|
||||
[submodule "vendor/grammars/nesC.tmbundle"]
|
||||
path = vendor/grammars/nesC.tmbundle
|
||||
url = https://github.com/cdwilson/nesC.tmbundle
|
||||
[submodule "vendor/grammars/racket-tmbundle"]
|
||||
path = vendor/grammars/racket-tmbundle
|
||||
url = https://github.com/christophevg/racket-tmbundle
|
||||
[submodule "vendor/grammars/haxe-sublime-bundle"]
|
||||
path = vendor/grammars/haxe-sublime-bundle
|
||||
url = https://github.com/clemos/haxe-sublime-bundle
|
||||
[submodule "vendor/grammars/cucumber-tmbundle"]
|
||||
path = vendor/grammars/cucumber-tmbundle
|
||||
url = https://github.com/cucumber/cucumber-tmbundle
|
||||
[submodule "vendor/grammars/Handlebars"]
|
||||
path = vendor/grammars/Handlebars
|
||||
url = https://github.com/daaain/Handlebars
|
||||
[submodule "vendor/grammars/powershell.tmbundle"]
|
||||
path = vendor/grammars/powershell.tmbundle
|
||||
url = https://github.com/davidpeckham/powershell.tmbundle
|
||||
[submodule "vendor/grammars/jade-tmbundle"]
|
||||
path = vendor/grammars/jade-tmbundle
|
||||
url = https://github.com/davidrios/jade-tmbundle
|
||||
[submodule "vendor/grammars/elixir-tmbundle"]
|
||||
path = vendor/grammars/elixir-tmbundle
|
||||
url = https://github.com/elixir-lang/elixir-tmbundle
|
||||
[submodule "vendor/grammars/sublime-glsl"]
|
||||
path = vendor/grammars/sublime-glsl
|
||||
url = https://github.com/euler0/sublime-glsl
|
||||
[submodule "vendor/grammars/fancy-tmbundle"]
|
||||
path = vendor/grammars/fancy-tmbundle
|
||||
url = https://github.com/fancy-lang/fancy-tmbundle
|
||||
[submodule "vendor/grammars/fsharpbinding"]
|
||||
path = vendor/grammars/fsharpbinding
|
||||
url = https://github.com/fsharp/fsharpbinding
|
||||
[submodule "vendor/grammars/monkey.tmbundle"]
|
||||
path = vendor/grammars/monkey.tmbundle
|
||||
url = https://github.com/gingerbeardman/monkey.tmbundle
|
||||
[submodule "vendor/grammars/dart-sublime-bundle"]
|
||||
path = vendor/grammars/dart-sublime-bundle
|
||||
url = https://github.com/guillermooo/dart-sublime-bundle
|
||||
[submodule "vendor/grammars/sublimetext-cuda-cpp"]
|
||||
path = vendor/grammars/sublimetext-cuda-cpp
|
||||
url = https://github.com/harrism/sublimetext-cuda-cpp
|
||||
[submodule "vendor/grammars/pike-textmate"]
|
||||
path = vendor/grammars/pike-textmate
|
||||
url = https://github.com/hww3/pike-textmate
|
||||
[submodule "vendor/grammars/ceylon-sublimetext"]
|
||||
path = vendor/grammars/ceylon-sublimetext
|
||||
url = https://github.com/jeancharles-roger/ceylon-sublimetext
|
||||
[submodule "vendor/grammars/Sublime-Text-2-OpenEdge-ABL"]
|
||||
path = vendor/grammars/Sublime-Text-2-OpenEdge-ABL
|
||||
url = https://github.com/jfairbank/Sublime-Text-2-OpenEdge-ABL
|
||||
[submodule "vendor/grammars/sublime-rust"]
|
||||
path = vendor/grammars/sublime-rust
|
||||
url = https://github.com/jhasse/sublime-rust
|
||||
[submodule "vendor/grammars/sublime-befunge"]
|
||||
path = vendor/grammars/sublime-befunge
|
||||
url = https://github.com/johanasplund/sublime-befunge
|
||||
[submodule "vendor/grammars/RDoc.tmbundle"]
|
||||
path = vendor/grammars/RDoc.tmbundle
|
||||
url = https://github.com/joshaven/RDoc.tmbundle
|
||||
[submodule "vendor/grammars/Textmate-Gosu-Bundle"]
|
||||
path = vendor/grammars/Textmate-Gosu-Bundle
|
||||
url = https://github.com/jpcamara/Textmate-Gosu-Bundle
|
||||
[submodule "vendor/grammars/jquery-tmbundle"]
|
||||
path = vendor/grammars/jquery-tmbundle
|
||||
url = https://github.com/kswedberg/jquery-tmbundle
|
||||
[submodule "vendor/grammars/fish-tmbundle"]
|
||||
path = vendor/grammars/fish-tmbundle
|
||||
url = https://github.com/l15n/fish-tmbundle
|
||||
[submodule "vendor/grammars/sublime-idris"]
|
||||
path = vendor/grammars/sublime-idris
|
||||
url = https://github.com/laughedelic/sublime-idris
|
||||
[submodule "vendor/grammars/sublime-better-typescript"]
|
||||
path = vendor/grammars/sublime-better-typescript
|
||||
url = https://github.com/lavrton/sublime-better-typescript
|
||||
[submodule "vendor/grammars/moonscript-tmbundle"]
|
||||
path = vendor/grammars/moonscript-tmbundle
|
||||
url = https://github.com/leafo/moonscript-tmbundle
|
||||
[submodule "vendor/grammars/Isabelle.tmbundle"]
|
||||
path = vendor/grammars/Isabelle.tmbundle
|
||||
url = https://github.com/lsf37/Isabelle.tmbundle
|
||||
[submodule "vendor/grammars/x86-assembly-textmate-bundle"]
|
||||
path = vendor/grammars/x86-assembly-textmate-bundle
|
||||
url = https://github.com/lunixbochs/x86-assembly-textmate-bundle
|
||||
[submodule "vendor/grammars/Alloy.tmbundle"]
|
||||
path = vendor/grammars/Alloy.tmbundle
|
||||
url = https://github.com/macekond/Alloy.tmbundle
|
||||
[submodule "vendor/grammars/opa.tmbundle"]
|
||||
path = vendor/grammars/opa.tmbundle
|
||||
url = https://github.com/mads379/opa.tmbundle
|
||||
[submodule "vendor/grammars/scala.tmbundle"]
|
||||
path = vendor/grammars/scala.tmbundle
|
||||
url = https://github.com/mads379/scala.tmbundle
|
||||
[submodule "vendor/grammars/mako-tmbundle"]
|
||||
path = vendor/grammars/mako-tmbundle
|
||||
url = https://github.com/marconi/mako-tmbundle
|
||||
[submodule "vendor/grammars/gnuplot-tmbundle"]
|
||||
path = vendor/grammars/gnuplot-tmbundle
|
||||
url = https://github.com/mattfoster/gnuplot-tmbundle
|
||||
[submodule "vendor/grammars/idl.tmbundle"]
|
||||
path = vendor/grammars/idl.tmbundle
|
||||
url = https://github.com/mgalloy/idl.tmbundle
|
||||
[submodule "vendor/grammars/protobuf-tmbundle"]
|
||||
path = vendor/grammars/protobuf-tmbundle
|
||||
url = https://github.com/michaeledgar/protobuf-tmbundle
|
||||
[submodule "vendor/grammars/Sublime-Coq"]
|
||||
path = vendor/grammars/Sublime-Coq
|
||||
url = https://github.com/mkolosick/Sublime-Coq
|
||||
[submodule "vendor/grammars/Agda.tmbundle"]
|
||||
path = vendor/grammars/Agda.tmbundle
|
||||
url = https://github.com/mokus0/Agda.tmbundle
|
||||
[submodule "vendor/grammars/Julia.tmbundle"]
|
||||
path = vendor/grammars/Julia.tmbundle
|
||||
url = https://github.com/nanoant/Julia.tmbundle
|
||||
[submodule "vendor/grammars/assembly.tmbundle"]
|
||||
path = vendor/grammars/assembly.tmbundle
|
||||
url = https://github.com/nanoant/assembly.tmbundle
|
||||
[submodule "vendor/grammars/ooc.tmbundle"]
|
||||
path = vendor/grammars/ooc.tmbundle
|
||||
url = https://github.com/nilium/ooc.tmbundle
|
||||
[submodule "vendor/grammars/LiveScript.tmbundle"]
|
||||
path = vendor/grammars/LiveScript.tmbundle
|
||||
url = https://github.com/paulmillr/LiveScript.tmbundle
|
||||
[submodule "vendor/grammars/sublime-tea"]
|
||||
path = vendor/grammars/sublime-tea
|
||||
url = https://github.com/pferruggiaro/sublime-tea
|
||||
[submodule "vendor/grammars/puppet-textmate-bundle"]
|
||||
path = vendor/grammars/puppet-textmate-bundle
|
||||
url = https://github.com/puppet-textmate-bundle/puppet-textmate-bundle
|
||||
[submodule "vendor/grammars/abap.tmbundle"]
|
||||
path = vendor/grammars/abap.tmbundle
|
||||
url = https://github.com/pvl/abap.tmbundle
|
||||
[submodule "vendor/grammars/mercury-tmlanguage"]
|
||||
path = vendor/grammars/mercury-tmlanguage
|
||||
url = https://github.com/sebgod/mercury-tmlanguage
|
||||
[submodule "vendor/grammars/mathematica-tmbundle"]
|
||||
path = vendor/grammars/mathematica-tmbundle
|
||||
url = https://github.com/shadanan/mathematica-tmbundle
|
||||
[submodule "vendor/grammars/sublime-robot-plugin"]
|
||||
path = vendor/grammars/sublime-robot-plugin
|
||||
url = https://github.com/shellderp/sublime-robot-plugin
|
||||
[submodule "vendor/grammars/actionscript3-tmbundle"]
|
||||
path = vendor/grammars/actionscript3-tmbundle
|
||||
url = https://github.com/simongregory/actionscript3-tmbundle
|
||||
[submodule "vendor/grammars/Sublime-QML"]
|
||||
path = vendor/grammars/Sublime-QML
|
||||
url = https://github.com/skozlovf/Sublime-QML
|
||||
[submodule "vendor/grammars/Slash.tmbundle"]
|
||||
path = vendor/grammars/Slash.tmbundle
|
||||
url = https://github.com/slash-lang/Slash.tmbundle
|
||||
[submodule "vendor/grammars/factor"]
|
||||
path = vendor/grammars/factor
|
||||
url = https://github.com/slavapestov/factor
|
||||
[submodule "vendor/grammars/ruby-slim.tmbundle"]
|
||||
path = vendor/grammars/ruby-slim.tmbundle
|
||||
url = https://github.com/slim-template/ruby-slim.tmbundle
|
||||
[submodule "vendor/grammars/SublimeXtend"]
|
||||
path = vendor/grammars/SublimeXtend
|
||||
url = https://github.com/staltz/SublimeXtend
|
||||
[submodule "vendor/grammars/Stata.tmbundle"]
|
||||
path = vendor/grammars/Stata.tmbundle
|
||||
url = https://github.com/statatmbundle/Stata.tmbundle
|
||||
[submodule "vendor/grammars/Vala-TMBundle"]
|
||||
path = vendor/grammars/Vala-TMBundle
|
||||
url = https://github.com/technosophos/Vala-TMBundle
|
||||
[submodule "vendor/grammars/ant.tmbundle"]
|
||||
path = vendor/grammars/ant.tmbundle
|
||||
url = https://github.com/textmate/ant.tmbundle
|
||||
[submodule "vendor/grammars/antlr.tmbundle"]
|
||||
path = vendor/grammars/antlr.tmbundle
|
||||
url = https://github.com/textmate/antlr.tmbundle
|
||||
[submodule "vendor/grammars/apache.tmbundle"]
|
||||
path = vendor/grammars/apache.tmbundle
|
||||
url = https://github.com/textmate/apache.tmbundle
|
||||
[submodule "vendor/grammars/applescript.tmbundle"]
|
||||
path = vendor/grammars/applescript.tmbundle
|
||||
url = https://github.com/textmate/applescript.tmbundle
|
||||
[submodule "vendor/grammars/asp.tmbundle"]
|
||||
path = vendor/grammars/asp.tmbundle
|
||||
url = https://github.com/textmate/asp.tmbundle
|
||||
[submodule "vendor/grammars/bison.tmbundle"]
|
||||
path = vendor/grammars/bison.tmbundle
|
||||
url = https://github.com/textmate/bison.tmbundle
|
||||
[submodule "vendor/grammars/capnproto.tmbundle"]
|
||||
path = vendor/grammars/capnproto.tmbundle
|
||||
url = https://github.com/textmate/capnproto.tmbundle
|
||||
[submodule "vendor/grammars/cmake.tmbundle"]
|
||||
path = vendor/grammars/cmake.tmbundle
|
||||
url = https://github.com/textmate/cmake.tmbundle
|
||||
[submodule "vendor/grammars/cpp-qt.tmbundle"]
|
||||
path = vendor/grammars/cpp-qt.tmbundle
|
||||
url = https://github.com/textmate/cpp-qt.tmbundle
|
||||
[submodule "vendor/grammars/css.tmbundle"]
|
||||
path = vendor/grammars/css.tmbundle
|
||||
url = https://github.com/textmate/css.tmbundle
|
||||
[submodule "vendor/grammars/d.tmbundle"]
|
||||
path = vendor/grammars/d.tmbundle
|
||||
url = https://github.com/textmate/d.tmbundle
|
||||
[submodule "vendor/grammars/diff.tmbundle"]
|
||||
path = vendor/grammars/diff.tmbundle
|
||||
url = https://github.com/textmate/diff.tmbundle
|
||||
[submodule "vendor/grammars/dylan.tmbundle"]
|
||||
path = vendor/grammars/dylan.tmbundle
|
||||
url = https://github.com/textmate/dylan.tmbundle
|
||||
[submodule "vendor/grammars/eiffel.tmbundle"]
|
||||
path = vendor/grammars/eiffel.tmbundle
|
||||
url = https://github.com/textmate/eiffel.tmbundle
|
||||
[submodule "vendor/grammars/erlang.tmbundle"]
|
||||
path = vendor/grammars/erlang.tmbundle
|
||||
url = https://github.com/textmate/erlang.tmbundle
|
||||
[submodule "vendor/grammars/fortran.tmbundle"]
|
||||
path = vendor/grammars/fortran.tmbundle
|
||||
url = https://github.com/textmate/fortran.tmbundle
|
||||
[submodule "vendor/grammars/gettext.tmbundle"]
|
||||
path = vendor/grammars/gettext.tmbundle
|
||||
url = https://github.com/textmate/gettext.tmbundle
|
||||
[submodule "vendor/grammars/graphviz.tmbundle"]
|
||||
path = vendor/grammars/graphviz.tmbundle
|
||||
url = https://github.com/textmate/graphviz.tmbundle
|
||||
[submodule "vendor/grammars/groovy.tmbundle"]
|
||||
path = vendor/grammars/groovy.tmbundle
|
||||
url = https://github.com/textmate/groovy.tmbundle
|
||||
[submodule "vendor/grammars/haskell.tmbundle"]
|
||||
path = vendor/grammars/haskell.tmbundle
|
||||
url = https://github.com/textmate/haskell.tmbundle
|
||||
[submodule "vendor/grammars/html.tmbundle"]
|
||||
path = vendor/grammars/html.tmbundle
|
||||
url = https://github.com/textmate/html.tmbundle
|
||||
[submodule "vendor/grammars/ini.tmbundle"]
|
||||
path = vendor/grammars/ini.tmbundle
|
||||
url = https://github.com/textmate/ini.tmbundle
|
||||
[submodule "vendor/grammars/io.tmbundle"]
|
||||
path = vendor/grammars/io.tmbundle
|
||||
url = https://github.com/textmate/io.tmbundle
|
||||
[submodule "vendor/grammars/java.tmbundle"]
|
||||
path = vendor/grammars/java.tmbundle
|
||||
url = https://github.com/textmate/java.tmbundle
|
||||
[submodule "vendor/grammars/javadoc.tmbundle"]
|
||||
path = vendor/grammars/javadoc.tmbundle
|
||||
url = https://github.com/textmate/javadoc.tmbundle
|
||||
[submodule "vendor/grammars/javascript-objective-j.tmbundle"]
|
||||
path = vendor/grammars/javascript-objective-j.tmbundle
|
||||
url = https://github.com/textmate/javascript-objective-j.tmbundle
|
||||
[submodule "vendor/grammars/json.tmbundle"]
|
||||
path = vendor/grammars/json.tmbundle
|
||||
url = https://github.com/textmate/json.tmbundle
|
||||
[submodule "vendor/grammars/latex.tmbundle"]
|
||||
path = vendor/grammars/latex.tmbundle
|
||||
url = https://github.com/textmate/latex.tmbundle
|
||||
[submodule "vendor/grammars/less.tmbundle"]
|
||||
path = vendor/grammars/less.tmbundle
|
||||
url = https://github.com/textmate/less.tmbundle
|
||||
[submodule "vendor/grammars/lilypond.tmbundle"]
|
||||
path = vendor/grammars/lilypond.tmbundle
|
||||
url = https://github.com/textmate/lilypond.tmbundle
|
||||
[submodule "vendor/grammars/lisp.tmbundle"]
|
||||
path = vendor/grammars/lisp.tmbundle
|
||||
url = https://github.com/textmate/lisp.tmbundle
|
||||
[submodule "vendor/grammars/logtalk.tmbundle"]
|
||||
path = vendor/grammars/logtalk.tmbundle
|
||||
url = https://github.com/textmate/logtalk.tmbundle
|
||||
[submodule "vendor/grammars/lua.tmbundle"]
|
||||
path = vendor/grammars/lua.tmbundle
|
||||
url = https://github.com/textmate/lua.tmbundle
|
||||
[submodule "vendor/grammars/make.tmbundle"]
|
||||
path = vendor/grammars/make.tmbundle
|
||||
url = https://github.com/textmate/make.tmbundle
|
||||
[submodule "vendor/grammars/matlab.tmbundle"]
|
||||
path = vendor/grammars/matlab.tmbundle
|
||||
url = https://github.com/textmate/matlab.tmbundle
|
||||
[submodule "vendor/grammars/maven.tmbundle"]
|
||||
path = vendor/grammars/maven.tmbundle
|
||||
url = https://github.com/textmate/maven.tmbundle
|
||||
[submodule "vendor/grammars/nemerle.tmbundle"]
|
||||
path = vendor/grammars/nemerle.tmbundle
|
||||
url = https://github.com/textmate/nemerle.tmbundle
|
||||
[submodule "vendor/grammars/ninja.tmbundle"]
|
||||
path = vendor/grammars/ninja.tmbundle
|
||||
url = https://github.com/textmate/ninja.tmbundle
|
||||
[submodule "vendor/grammars/objective-c.tmbundle"]
|
||||
path = vendor/grammars/objective-c.tmbundle
|
||||
url = https://github.com/textmate/objective-c.tmbundle
|
||||
[submodule "vendor/grammars/ocaml.tmbundle"]
|
||||
path = vendor/grammars/ocaml.tmbundle
|
||||
url = https://github.com/textmate/ocaml.tmbundle
|
||||
[submodule "vendor/grammars/pascal.tmbundle"]
|
||||
path = vendor/grammars/pascal.tmbundle
|
||||
url = https://github.com/textmate/pascal.tmbundle
|
||||
[submodule "vendor/grammars/perl.tmbundle"]
|
||||
path = vendor/grammars/perl.tmbundle
|
||||
url = https://github.com/textmate/perl.tmbundle
|
||||
[submodule "vendor/grammars/php-smarty.tmbundle"]
|
||||
path = vendor/grammars/php-smarty.tmbundle
|
||||
url = https://github.com/textmate/php-smarty.tmbundle
|
||||
[submodule "vendor/grammars/php.tmbundle"]
|
||||
path = vendor/grammars/php.tmbundle
|
||||
url = https://github.com/textmate/php.tmbundle
|
||||
[submodule "vendor/grammars/postscript.tmbundle"]
|
||||
path = vendor/grammars/postscript.tmbundle
|
||||
url = https://github.com/textmate/postscript.tmbundle
|
||||
[submodule "vendor/grammars/processing.tmbundle"]
|
||||
path = vendor/grammars/processing.tmbundle
|
||||
url = https://github.com/textmate/processing.tmbundle
|
||||
[submodule "vendor/grammars/prolog.tmbundle"]
|
||||
path = vendor/grammars/prolog.tmbundle
|
||||
url = https://github.com/textmate/prolog.tmbundle
|
||||
[submodule "vendor/grammars/python-django.tmbundle"]
|
||||
path = vendor/grammars/python-django.tmbundle
|
||||
url = https://github.com/textmate/python-django.tmbundle
|
||||
[submodule "vendor/grammars/r.tmbundle"]
|
||||
path = vendor/grammars/r.tmbundle
|
||||
url = https://github.com/textmate/r.tmbundle
|
||||
[submodule "vendor/grammars/restructuredtext.tmbundle"]
|
||||
path = vendor/grammars/restructuredtext.tmbundle
|
||||
url = https://github.com/textmate/restructuredtext.tmbundle
|
||||
[submodule "vendor/grammars/ruby-haml.tmbundle"]
|
||||
path = vendor/grammars/ruby-haml.tmbundle
|
||||
url = https://github.com/textmate/ruby-haml.tmbundle
|
||||
[submodule "vendor/grammars/ruby-on-rails-tmbundle"]
|
||||
path = vendor/grammars/ruby-on-rails-tmbundle
|
||||
url = https://github.com/textmate/ruby-on-rails-tmbundle
|
||||
[submodule "vendor/grammars/scheme.tmbundle"]
|
||||
path = vendor/grammars/scheme.tmbundle
|
||||
url = https://github.com/textmate/scheme.tmbundle
|
||||
[submodule "vendor/grammars/scilab.tmbundle"]
|
||||
path = vendor/grammars/scilab.tmbundle
|
||||
url = https://github.com/textmate/scilab.tmbundle
|
||||
[submodule "vendor/grammars/sql.tmbundle"]
|
||||
path = vendor/grammars/sql.tmbundle
|
||||
url = https://github.com/textmate/sql.tmbundle
|
||||
[submodule "vendor/grammars/standard-ml.tmbundle"]
|
||||
path = vendor/grammars/standard-ml.tmbundle
|
||||
url = https://github.com/textmate/standard-ml.tmbundle
|
||||
[submodule "vendor/grammars/swift.tmbundle"]
|
||||
path = vendor/grammars/swift.tmbundle
|
||||
url = https://github.com/textmate/swift.tmbundle
|
||||
[submodule "vendor/grammars/tcl.tmbundle"]
|
||||
path = vendor/grammars/tcl.tmbundle
|
||||
url = https://github.com/textmate/tcl.tmbundle
|
||||
[submodule "vendor/grammars/text.tmbundle"]
|
||||
path = vendor/grammars/text.tmbundle
|
||||
url = https://github.com/textmate/text.tmbundle
|
||||
[submodule "vendor/grammars/textile.tmbundle"]
|
||||
path = vendor/grammars/textile.tmbundle
|
||||
url = https://github.com/textmate/textile.tmbundle
|
||||
[submodule "vendor/grammars/textmate.tmbundle"]
|
||||
path = vendor/grammars/textmate.tmbundle
|
||||
url = https://github.com/textmate/textmate.tmbundle
|
||||
[submodule "vendor/grammars/thrift.tmbundle"]
|
||||
path = vendor/grammars/thrift.tmbundle
|
||||
url = https://github.com/textmate/thrift.tmbundle
|
||||
[submodule "vendor/grammars/toml.tmbundle"]
|
||||
path = vendor/grammars/toml.tmbundle
|
||||
url = https://github.com/textmate/toml.tmbundle
|
||||
[submodule "vendor/grammars/verilog.tmbundle"]
|
||||
path = vendor/grammars/verilog.tmbundle
|
||||
url = https://github.com/textmate/verilog.tmbundle
|
||||
[submodule "vendor/grammars/xml.tmbundle"]
|
||||
path = vendor/grammars/xml.tmbundle
|
||||
url = https://github.com/textmate/xml.tmbundle
|
||||
[submodule "vendor/grammars/smalltalk-tmbundle"]
|
||||
path = vendor/grammars/smalltalk-tmbundle
|
||||
url = https://github.com/tomas-stefano/smalltalk-tmbundle
|
||||
[submodule "vendor/grammars/ioke-outdated"]
|
||||
path = vendor/grammars/ioke-outdated
|
||||
url = https://github.com/vic/ioke-outdated
|
||||
[submodule "vendor/grammars/kotlin-sublime-package"]
|
||||
path = vendor/grammars/kotlin-sublime-package
|
||||
url = https://github.com/vkostyukov/kotlin-sublime-package
|
||||
[submodule "vendor/grammars/c.tmbundle"]
|
||||
path = vendor/grammars/c.tmbundle
|
||||
url = https://github.com/textmate/c.tmbundle
|
||||
[submodule "vendor/grammars/zephir-sublime"]
|
||||
path = vendor/grammars/zephir-sublime
|
||||
url = https://github.com/vmg/zephir-sublime
|
||||
[submodule "vendor/grammars/llvm.tmbundle"]
|
||||
path = vendor/grammars/llvm.tmbundle
|
||||
url = https://github.com/whitequark/llvm.tmbundle
|
||||
[submodule "vendor/grammars/sublime-nix"]
|
||||
path = vendor/grammars/sublime-nix
|
||||
url = https://github.com/wmertens/sublime-nix
|
||||
[submodule "vendor/grammars/ada.tmbundle"]
|
||||
path = vendor/grammars/ada.tmbundle
|
||||
url = https://github.com/aroben/ada.tmbundle
|
||||
branch = better-with-highlighting
|
||||
[submodule "vendor/grammars/oz-tmbundle"]
|
||||
path = vendor/grammars/oz-tmbundle
|
||||
url = https://github.com/eregon/oz-tmbundle
|
||||
[submodule "vendor/grammars/ebundles"]
|
||||
path = vendor/grammars/ebundles
|
||||
url = https://github.com/ericzou/ebundles
|
||||
[submodule "vendor/grammars/sublime-mask"]
|
||||
path = vendor/grammars/sublime-mask
|
||||
url = https://github.com/tenbits/sublime-mask
|
||||
[submodule "vendor/grammars/sublime_cobol"]
|
||||
path = vendor/grammars/sublime_cobol
|
||||
url = https://bitbucket.org/bitlang/sublime_cobol
|
||||
[submodule "vendor/grammars/ruby.tmbundle"]
|
||||
path = vendor/grammars/ruby.tmbundle
|
||||
url = https://github.com/aroben/ruby.tmbundle
|
||||
branch = pl
|
||||
[submodule "vendor/grammars/IDL-Syntax"]
|
||||
path = vendor/grammars/IDL-Syntax
|
||||
url = https://github.com/andik/IDL-Syntax
|
||||
[submodule "vendor/grammars/sas.tmbundle"]
|
||||
path = vendor/grammars/sas.tmbundle
|
||||
url = https://github.com/rpardee/sas.tmbundle
|
||||
[submodule "vendor/grammars/atom-salt"]
|
||||
path = vendor/grammars/atom-salt
|
||||
url = https://github.com/saltstack/atom-salt
|
||||
[submodule "vendor/grammars/Scalate.tmbundle"]
|
||||
path = vendor/grammars/Scalate.tmbundle
|
||||
url = https://github.com/scalate/Scalate.tmbundle
|
||||
[submodule "vendor/grammars/Elm.tmLanguage"]
|
||||
path = vendor/grammars/Elm.tmLanguage
|
||||
url = https://github.com/deadfoxygrandpa/Elm.tmLanguage
|
||||
[submodule "vendor/grammars/sublime-bsv"]
|
||||
path = vendor/grammars/sublime-bsv
|
||||
url = https://github.com/thotypous/sublime-bsv
|
||||
[submodule "vendor/grammars/sass-textmate-bundle"]
|
||||
path = vendor/grammars/sass-textmate-bundle
|
||||
url = https://github.com/nathos/sass-textmate-bundle
|
||||
[submodule "vendor/grammars/carto-atom"]
|
||||
path = vendor/grammars/carto-atom
|
||||
url = https://github.com/yohanboniface/carto-atom
|
||||
10
.travis.yml
10
.travis.yml
@@ -1,8 +1,5 @@
|
||||
before_install:
|
||||
- git fetch origin master:master
|
||||
- git fetch origin v2.0.0:v2.0.0
|
||||
- git fetch origin test/attributes:test/attributes
|
||||
- sudo apt-get install libicu-dev -y
|
||||
sudo: false
|
||||
before_install: script/travis/before_install
|
||||
rvm:
|
||||
- 1.9.3
|
||||
- 2.0.0
|
||||
@@ -10,3 +7,6 @@ rvm:
|
||||
- 2.2
|
||||
notifications:
|
||||
disabled: true
|
||||
git:
|
||||
submodules: false
|
||||
cache: bundler
|
||||
|
||||
@@ -10,9 +10,9 @@ This can usually be solved either by adding a new filename or file name extensio
|
||||
|
||||
### Syntax highlighting looks wrong
|
||||
|
||||
Assuming your code is being detected as the right language (see above), in most cases this is due to a bug in the language grammar rather than a bug in Linguist. [`grammars.yml`][grammars] lists all the grammars we use for syntax highlighting on github.com. Find the one corresponding to your code's programming language and submit a bug report upstream.
|
||||
Assuming your code is being detected as the right language (see above), in most cases this is due to a bug in the language grammar rather than a bug in Linguist. [`grammars.yml`][grammars] lists all the grammars we use for syntax highlighting on github.com. Find the one corresponding to your code's programming language and submit a bug report upstream. If you can, try to reproduce the highlighting problem in the text editor that the grammar is designed for (TextMate, Sublime Text, or Atom) and include that information in your bug report.
|
||||
|
||||
You can also try to fix the bug yourself and submit a Pull Request. [This piece from TextMate's documentation](http://manual.macromates.com/en/language_grammars) offers a good introduction on how to work with TextMate-compatible grammars.
|
||||
You can also try to fix the bug yourself and submit a Pull Request. [This piece from TextMate's documentation](http://manual.macromates.com/en/language_grammars) offers a good introduction on how to work with TextMate-compatible grammars. You can test grammars using [Lightshow](https://lightshow.githubapp.com).
|
||||
|
||||
Once the bug has been fixed upstream, please let us know and we'll pick it up for GitHub.
|
||||
|
||||
@@ -21,9 +21,19 @@ Once the bug has been fixed upstream, please let us know and we'll pick it up fo
|
||||
Great! You'll need to:
|
||||
|
||||
0. Add an entry for your language to [`languages.yml`][languages].
|
||||
0. Add a grammar for your language to [`grammars.yml`][grammars] by running `script/download-grammars --add URL`. Please only add grammars that have a license that permits redistribution.
|
||||
0. Add a grammar for your language. Please only add grammars that have a license that permits redistribution.
|
||||
0. Add your grammar as a submodule: `git submodule add https://github.com/JaneSmith/MyGrammar vendor/grammars/MyGrammar`.
|
||||
0. Add your grammar to [`grammars.yml`][grammars] by running `script/convert-grammars --add vendor/grammars/MyGrammar`.
|
||||
0. Add samples for your language to the [samples directory][samples].
|
||||
|
||||
In addition, if your new language defines an extension that's already listed in [`languages.yml`][languages] (such as `.foo`) then sometimes a few more steps will need to be taken:
|
||||
|
||||
0. Make sure that example `.foo` files are present in the [samples directory][samples] for each language that uses `.foo`.
|
||||
0. Test the performance of the Bayesian classifier with a relatively large number (1000s) of sample `.foo` files. (ping @arfon or @bkeepers to help with this) to ensure we're not misclassifying files.
|
||||
0. If the Bayesian classifier does a bad job with the sample `.foo` files then a [heuristic](https://github.com/github/linguist/blob/master/lib/linguist/heuristics.rb) may need to be written to help.
|
||||
|
||||
Remember, the goal here is to try and avoid false positives!
|
||||
|
||||
We try only to add languages once they have some usage on GitHub, so please note in-the-wild usage examples in your pull request. In most cases we prefer that languages already be in use in hundreds of repositories before supporting them in Linguist.
|
||||
|
||||
[grammars]: /grammars.yml
|
||||
|
||||
2
Gemfile
2
Gemfile
@@ -1,4 +1,4 @@
|
||||
source 'https://rubygems.org'
|
||||
gemspec :name => "github-linguist"
|
||||
gemspec :name => "github-linguist-grammars"
|
||||
gem 'test-unit', require: false if RUBY_VERSION >= '2.2'
|
||||
gem 'byebug' if RUBY_VERSION >= '2.0'
|
||||
|
||||
@@ -141,7 +141,7 @@ But for development you are going to want to checkout out the source. To get it,
|
||||
|
||||
git clone https://github.com/github/linguist.git
|
||||
cd linguist/
|
||||
bundle install
|
||||
script/bootstrap
|
||||
|
||||
To run the tests:
|
||||
|
||||
@@ -181,7 +181,7 @@ Here's our current build status, which is hopefully green: [.
|
||||
|
||||
21
Rakefile
21
Rakefile
@@ -3,13 +3,14 @@ require 'rake/clean'
|
||||
require 'rake/testtask'
|
||||
require 'yaml'
|
||||
require 'yajl'
|
||||
require 'open-uri'
|
||||
|
||||
task :default => :test
|
||||
|
||||
Rake::TestTask.new
|
||||
|
||||
# Extend test task to check for samples
|
||||
task :test => :check_samples
|
||||
# Extend test task to check for samples and fetch latest Ace modes
|
||||
task :test => [:check_samples, :fetch_ace_modes]
|
||||
|
||||
desc "Check that we have samples.json generated"
|
||||
task :check_samples do
|
||||
@@ -18,6 +19,20 @@ task :check_samples do
|
||||
end
|
||||
end
|
||||
|
||||
desc "Fetch the latest Ace modes from its GitHub repository"
|
||||
task :fetch_ace_modes do
|
||||
ACE_FIXTURE_PATH = File.join('test', 'fixtures', 'ace_modes.json')
|
||||
|
||||
File.delete(ACE_FIXTURE_PATH) if File.exist?(ACE_FIXTURE_PATH)
|
||||
|
||||
begin
|
||||
ace_github_modes = open("https://api.github.com/repos/ajaxorg/ace/contents/lib/ace/mode").read
|
||||
File.write(ACE_FIXTURE_PATH, ace_github_modes)
|
||||
rescue OpenURI::HTTPError, SocketError
|
||||
# no internet? no problem.
|
||||
end
|
||||
end
|
||||
|
||||
task :samples do
|
||||
require 'linguist/samples'
|
||||
json = Yajl.dump(Linguist::Samples.data, :pretty => true)
|
||||
@@ -33,7 +48,7 @@ end
|
||||
|
||||
task :build_grammars_gem do
|
||||
rm_rf "grammars"
|
||||
sh "script/download-grammars"
|
||||
sh "script/convert-grammars"
|
||||
sh "gem", "build", "github-linguist-grammars.gemspec"
|
||||
end
|
||||
|
||||
|
||||
@@ -16,8 +16,9 @@ Gem::Specification.new do |s|
|
||||
s.add_dependency 'charlock_holmes', '~> 0.7.3'
|
||||
s.add_dependency 'escape_utils', '~> 1.0.1'
|
||||
s.add_dependency 'mime-types', '>= 1.19'
|
||||
s.add_dependency 'rugged', '~> 0.22.0b1'
|
||||
s.add_dependency 'rugged', '~> 0.22.0b4'
|
||||
|
||||
s.add_development_dependency 'minitest', '>= 5.0'
|
||||
s.add_development_dependency 'mocha'
|
||||
s.add_development_dependency 'pry'
|
||||
s.add_development_dependency 'rake'
|
||||
|
||||
650
grammars.yml
650
grammars.yml
@@ -5,14 +5,10 @@ http://svn.textmate.org/trunk/Review/Bundles/BlitzMax.tmbundle:
|
||||
- source.blitzmax
|
||||
http://svn.textmate.org/trunk/Review/Bundles/Cython.tmbundle:
|
||||
- source.cython
|
||||
http://svn.textmate.org/trunk/Review/Bundles/F%20Sharp.tmbundle:
|
||||
- source.fsharp
|
||||
http://svn.textmate.org/trunk/Review/Bundles/Forth.tmbundle:
|
||||
- source.forth
|
||||
http://svn.textmate.org/trunk/Review/Bundles/Parrot.tmbundle:
|
||||
- source.parrot.pir
|
||||
http://svn.textmate.org/trunk/Review/Bundles/Ruby%20Sass.tmbundle:
|
||||
- source.sass
|
||||
http://svn.textmate.org/trunk/Review/Bundles/SecondLife%20LSL.tmbundle:
|
||||
- source.lsl
|
||||
http://svn.textmate.org/trunk/Review/Bundles/VHDL.tmbundle:
|
||||
@@ -22,388 +18,438 @@ http://svn.textmate.org/trunk/Review/Bundles/XQuery.tmbundle:
|
||||
https://bitbucket.org/Clams/sublimesystemverilog/get/default.tar.gz:
|
||||
- source.systemverilog
|
||||
- source.ucfconstraints
|
||||
https://bitbucket.org/bitlang/sublime_cobol/raw/b0e9c44ac5f7a2fb553421aa986b35854cbfda4a/COBOL.tmLanguage:
|
||||
- source.cobol
|
||||
https://fan.googlecode.com/hg-history/Build%201.0.55/adm/tools/textmate/Fan.tmbundle/Syntaxes/Fan.tmLanguage:
|
||||
- source.fan
|
||||
https://github.com/AlanQuatermain/go-tmbundle:
|
||||
- source.go
|
||||
https://github.com/Anomareh/PHP-Twig.tmbundle:
|
||||
- text.html.twig
|
||||
https://github.com/Cirru/sublime-cirru/raw/master/Cirru.tmLanguage:
|
||||
- source.cirru
|
||||
https://github.com/Cykey/Sublime-Logos:
|
||||
- source.logos
|
||||
https://github.com/Drako/SublimeBrainfuck/raw/master/Brainfuck.tmLanguage:
|
||||
- source.bf
|
||||
https://github.com/JohnNilsson/awk-sublime/raw/master/AWK.tmLanguage:
|
||||
- source.awk
|
||||
https://github.com/MarioRicalde/SCSS.tmbundle:
|
||||
- source.scss
|
||||
https://github.com/Oldes/Sublime-REBOL:
|
||||
- source.rebol
|
||||
https://github.com/PogiNate/Sublime-Inform:
|
||||
- source.Inform7
|
||||
https://github.com/Red-Nova-Technologies/autoitv3-tmbundle:
|
||||
- source.autoit.3
|
||||
https://github.com/SalGnt/Sublime-VimL:
|
||||
- source.viml
|
||||
https://github.com/Shammah/boo-sublime/raw/master/Boo.tmLanguage:
|
||||
- source.boo
|
||||
https://github.com/SublimeText/ColdFusion:
|
||||
vendor/grammars/Agda.tmbundle:
|
||||
- source.agda
|
||||
vendor/grammars/Alloy.tmbundle:
|
||||
- source.alloy
|
||||
vendor/grammars/ColdFusion:
|
||||
- source.cfscript
|
||||
- source.cfscript.cfc
|
||||
- text.cfml.basic
|
||||
- text.html.cfm
|
||||
https://github.com/SublimeText/NSIS:
|
||||
- source.nsis
|
||||
https://github.com/Varriount/NimLime:
|
||||
- source.nimrod
|
||||
- source.nimrod_filter
|
||||
- source.nimrodcfg
|
||||
https://github.com/angryant0007/VBDotNetSyntax:
|
||||
- source.vbnet
|
||||
https://github.com/aroben/ada.tmbundle/raw/c45eed4d5f98fe3bcbbffbb9e436601ab5bbde4b/Syntaxes/Ada.plist:
|
||||
- source.ada
|
||||
https://github.com/aroben/ruby.tmbundle@4636a3023153c3034eb6ffc613899ba9cf33b41f:
|
||||
- source.ruby
|
||||
- text.html.erb
|
||||
https://github.com/asbjornenge/Docker.tmbundle:
|
||||
vendor/grammars/Docker.tmbundle:
|
||||
- source.dockerfile
|
||||
https://github.com/atom/language-clojure:
|
||||
- source.clojure
|
||||
https://github.com/atom/language-coffee-script:
|
||||
- source.coffee
|
||||
- source.litcoffee
|
||||
https://github.com/atom/language-csharp:
|
||||
- source.cs
|
||||
- source.csx
|
||||
- source.nant-build
|
||||
https://github.com/atom/language-javascript:
|
||||
- source.js
|
||||
- source.js.regexp
|
||||
https://github.com/atom/language-python:
|
||||
- source.python
|
||||
- source.regexp.python
|
||||
- text.python.traceback
|
||||
https://github.com/atom/language-shellscript:
|
||||
- source.shell
|
||||
- text.shell-session
|
||||
https://github.com/austinwagner/sublime-sourcepawn:
|
||||
- source.sp
|
||||
https://github.com/bfad/Sublime-Lasso:
|
||||
vendor/grammars/Elm.tmLanguage:
|
||||
- source.elm
|
||||
vendor/grammars/Handlebars:
|
||||
- text.html.handlebars
|
||||
vendor/grammars/IDL-Syntax:
|
||||
- source.webidl
|
||||
vendor/grammars/Isabelle.tmbundle:
|
||||
- source.isabelle.root
|
||||
- source.isabelle.theory
|
||||
vendor/grammars/Julia.tmbundle:
|
||||
- source.julia
|
||||
vendor/grammars/LiveScript.tmbundle:
|
||||
- source.livescript
|
||||
vendor/grammars/NSIS:
|
||||
- source.nsis
|
||||
vendor/grammars/NimLime:
|
||||
- source.nim
|
||||
- source.nim_filter
|
||||
- source.nimcfg
|
||||
vendor/grammars/PHP-Twig.tmbundle:
|
||||
- text.html.twig
|
||||
vendor/grammars/RDoc.tmbundle:
|
||||
- text.rdoc
|
||||
vendor/grammars/SCSS.tmbundle:
|
||||
- source.scss
|
||||
vendor/grammars/Scalate.tmbundle:
|
||||
- source.scaml
|
||||
- text.html.ssp
|
||||
vendor/grammars/Slash.tmbundle:
|
||||
- text.html.slash
|
||||
vendor/grammars/Stata.tmbundle:
|
||||
- source.mata
|
||||
- source.stata
|
||||
vendor/grammars/Sublime-Coq:
|
||||
- source.coq
|
||||
vendor/grammars/Sublime-Inform:
|
||||
- source.Inform7
|
||||
vendor/grammars/Sublime-Lasso:
|
||||
- file.lasso
|
||||
https://github.com/bholt/chapel-tmbundle:
|
||||
vendor/grammars/Sublime-Logos:
|
||||
- source.logos
|
||||
vendor/grammars/Sublime-Loom:
|
||||
- source.loomscript
|
||||
vendor/grammars/Sublime-QML:
|
||||
- source.qml
|
||||
vendor/grammars/Sublime-REBOL:
|
||||
- source.rebol
|
||||
vendor/grammars/Sublime-SQF-Language:
|
||||
- source.sqf
|
||||
vendor/grammars/Sublime-Text-2-OpenEdge-ABL:
|
||||
- source.abl
|
||||
vendor/grammars/Sublime-VimL:
|
||||
- source.viml
|
||||
vendor/grammars/SublimeBrainfuck:
|
||||
- source.bf
|
||||
vendor/grammars/SublimeXtend:
|
||||
- source.xtend
|
||||
vendor/grammars/Textmate-Gosu-Bundle:
|
||||
- source.gosu.2
|
||||
vendor/grammars/VBDotNetSyntax:
|
||||
- source.vbnet
|
||||
vendor/grammars/Vala-TMBundle:
|
||||
- source.vala
|
||||
vendor/grammars/abap.tmbundle:
|
||||
- source.abap
|
||||
vendor/grammars/actionscript3-tmbundle:
|
||||
- source.actionscript.3
|
||||
- text.html.asdoc
|
||||
- text.xml.flex-config
|
||||
vendor/grammars/ada.tmbundle:
|
||||
- source.ada
|
||||
vendor/grammars/ant.tmbundle:
|
||||
- text.xml.ant
|
||||
vendor/grammars/antlr.tmbundle:
|
||||
- source.antlr
|
||||
vendor/grammars/apache.tmbundle:
|
||||
- source.apache-config
|
||||
- source.apache-config.mod_perl
|
||||
vendor/grammars/applescript.tmbundle:
|
||||
- source.applescript
|
||||
vendor/grammars/asp.tmbundle:
|
||||
- source.asp
|
||||
- text.html.asp
|
||||
vendor/grammars/assembly.tmbundle:
|
||||
- objdump.x86asm
|
||||
- source.x86asm
|
||||
vendor/grammars/atom-salt:
|
||||
- source.python.salt
|
||||
- source.yaml.salt
|
||||
vendor/grammars/autoitv3-tmbundle:
|
||||
- source.autoit.3
|
||||
vendor/grammars/awk-sublime:
|
||||
- source.awk
|
||||
vendor/grammars/bison.tmbundle:
|
||||
- source.bison
|
||||
vendor/grammars/boo-sublime:
|
||||
- source.boo
|
||||
vendor/grammars/bro-sublime:
|
||||
- source.bro
|
||||
vendor/grammars/c.tmbundle:
|
||||
- source.c
|
||||
- source.c++
|
||||
- source.c.platform
|
||||
vendor/grammars/capnproto.tmbundle:
|
||||
- source.capnp
|
||||
vendor/grammars/carto-atom:
|
||||
- source.css.mss
|
||||
vendor/grammars/ceylon-sublimetext:
|
||||
- module.ceylon
|
||||
- source.ceylon
|
||||
vendor/grammars/chapel-tmbundle:
|
||||
- source.chapel
|
||||
https://github.com/brandonwamboldt/sublime-nginx:
|
||||
- source.nginx
|
||||
https://github.com/carsonoid/sublime_man_page_support/raw/master/man-groff.tmLanguage:
|
||||
- text.groff
|
||||
https://github.com/ccreutzig/sublime-MuPAD:
|
||||
- source.mupad
|
||||
https://github.com/cdwilson/nesC.tmbundle:
|
||||
- source.nesc
|
||||
https://github.com/christophevg/racket-tmbundle:
|
||||
- source.racket
|
||||
https://github.com/clemos/haxe-sublime-bundle:
|
||||
vendor/grammars/cmake.tmbundle:
|
||||
- source.cache.cmake
|
||||
- source.cmake
|
||||
vendor/grammars/cool-tmbundle:
|
||||
- source.cool
|
||||
vendor/grammars/cpp-qt.tmbundle:
|
||||
- source.c++.qt
|
||||
- source.qmake
|
||||
vendor/grammars/css.tmbundle:
|
||||
- source.css
|
||||
vendor/grammars/cucumber-tmbundle:
|
||||
- source.ruby.rspec.cucumber.steps
|
||||
- text.gherkin.feature
|
||||
vendor/grammars/d.tmbundle:
|
||||
- source.d
|
||||
vendor/grammars/dart-sublime-bundle:
|
||||
- source.dart
|
||||
- source.pubspec
|
||||
- text.dart-doccomments
|
||||
vendor/grammars/diff.tmbundle:
|
||||
- source.diff
|
||||
vendor/grammars/dylan.tmbundle:
|
||||
- source.dylan
|
||||
- source.lid
|
||||
- source.makegen
|
||||
vendor/grammars/ebundles/Bundles/MSDOS batch file.tmbundle:
|
||||
- source.dosbatch
|
||||
vendor/grammars/eiffel.tmbundle:
|
||||
- source.eiffel
|
||||
vendor/grammars/elixir-tmbundle:
|
||||
- source.elixir
|
||||
- text.elixir
|
||||
- text.html.elixir
|
||||
vendor/grammars/erlang.tmbundle:
|
||||
- source.erlang
|
||||
- text.html.erlang.yaws
|
||||
vendor/grammars/factor:
|
||||
- source.factor
|
||||
- text.html.factor
|
||||
vendor/grammars/fancy-tmbundle:
|
||||
- source.fancy
|
||||
vendor/grammars/fish-tmbundle:
|
||||
- source.fish
|
||||
vendor/grammars/fortran.tmbundle:
|
||||
- source.fortran
|
||||
- source.fortran.modern
|
||||
vendor/grammars/fsharpbinding:
|
||||
- source.fsharp
|
||||
vendor/grammars/gettext.tmbundle:
|
||||
- source.po
|
||||
vendor/grammars/gnuplot-tmbundle:
|
||||
- source.gnuplot
|
||||
vendor/grammars/go-tmbundle:
|
||||
- source.go
|
||||
vendor/grammars/gradle.tmbundle:
|
||||
- source.groovy.gradle
|
||||
vendor/grammars/graphviz.tmbundle:
|
||||
- source.dot
|
||||
vendor/grammars/groovy.tmbundle:
|
||||
- source.groovy
|
||||
vendor/grammars/haskell.tmbundle:
|
||||
- source.haskell
|
||||
- text.tex.latex.haskell
|
||||
vendor/grammars/haxe-sublime-bundle:
|
||||
- source.erazor
|
||||
- source.haxe.2
|
||||
- source.hss.1
|
||||
- source.hxml
|
||||
- source.nmml
|
||||
https://github.com/cucumber/cucumber-tmbundle:
|
||||
- source.ruby.rspec.cucumber.steps
|
||||
- text.gherkin.feature
|
||||
https://github.com/daaain/Handlebars/raw/master/Handlebars.tmLanguage:
|
||||
- text.html.handlebars
|
||||
https://github.com/davidpeckham/powershell.tmbundle:
|
||||
- source.powershell
|
||||
https://github.com/davidrios/jade-tmbundle:
|
||||
- source.jade
|
||||
- source.pyjade
|
||||
https://github.com/elixir-lang/elixir-tmbundle:
|
||||
- source.elixir
|
||||
- text.elixir
|
||||
- text.html.elixir
|
||||
https://github.com/ericzou/ebundles/raw/master/Bundles/MSDOS%20batch%20file.tmbundle/Syntaxes/MSDOS%20batch%20file.tmLanguage:
|
||||
- source.dosbatch
|
||||
https://github.com/euler0/sublime-glsl/raw/master/GLSL.tmLanguage:
|
||||
- source.glsl
|
||||
https://github.com/fancy-lang/fancy-tmbundle:
|
||||
- source.fancy
|
||||
https://github.com/gingerbeardman/monkey.tmbundle:
|
||||
- source.monkey
|
||||
https://github.com/guillermooo/dart-sublime-bundle/raw/master/Dart.tmLanguage:
|
||||
- source.dart
|
||||
https://github.com/harrism/sublimetext-cuda-cpp/raw/master/cuda-c%2B%2B.tmLanguage:
|
||||
- source.cuda-c++
|
||||
https://github.com/hww3/pike-textmate:
|
||||
- source.pike
|
||||
https://github.com/jeancharles-roger/ceylon-sublimetext/raw/master/Ceylon.tmLanguage:
|
||||
- source.ceylon
|
||||
https://github.com/jfairbank/Sublime-Text-2-OpenEdge-ABL:
|
||||
- source.abl
|
||||
https://github.com/jhasse/sublime-rust:
|
||||
- source.rust
|
||||
https://github.com/johanasplund/sublime-befunge/raw/master/Befunge-93.tmLanguage:
|
||||
- source.befunge
|
||||
https://github.com/joshaven/RDoc.tmbundle:
|
||||
- text.rdoc
|
||||
https://github.com/jpcamara/Textmate-Gosu-Bundle/raw/master/Gosu.tmbundle/Syntaxes/Gosu.tmLanguage:
|
||||
- source.gosu.2
|
||||
https://github.com/kswedberg/jquery-tmbundle:
|
||||
- source.js.jquery
|
||||
https://github.com/laughedelic/sublime-idris/raw/master/Idris.tmLanguage:
|
||||
- source.idris
|
||||
https://github.com/lavrton/sublime-better-typescript:
|
||||
- source.ts
|
||||
https://github.com/leafo/moonscript-tmbundle:
|
||||
- source.moonscript
|
||||
https://github.com/lunixbochs/x86-assembly-textmate-bundle:
|
||||
- source.asm.x86
|
||||
https://github.com/macekond/Alloy.tmbundle:
|
||||
- source.alloy
|
||||
https://github.com/mads379/opa.tmbundle:
|
||||
- source.opa
|
||||
https://github.com/mads379/scala.tmbundle:
|
||||
- source.sbt
|
||||
- source.scala
|
||||
https://github.com/marconi/mako-tmbundle:
|
||||
- text.html.mako
|
||||
https://github.com/mattfoster/gnuplot-tmbundle:
|
||||
- source.gnuplot
|
||||
https://github.com/mgalloy/idl.tmbundle:
|
||||
vendor/grammars/html.tmbundle:
|
||||
- text.html.basic
|
||||
vendor/grammars/idl.tmbundle:
|
||||
- source.idl
|
||||
- source.idl-dlm
|
||||
- text.idl-idldoc
|
||||
https://github.com/michaeledgar/protobuf-tmbundle:
|
||||
- source.protobuf
|
||||
https://github.com/mkolosick/Sublime-Coq/raw/master/Coq.tmLanguage:
|
||||
- source.coq
|
||||
https://github.com/mokus0/Agda.tmbundle:
|
||||
- source.agda
|
||||
https://github.com/nanoant/Julia.tmbundle:
|
||||
- source.julia
|
||||
https://github.com/nanoant/assembly.tmbundle/raw/master/Syntaxes/objdump%20C%2B%2B.tmLanguage:
|
||||
- objdump.x86asm
|
||||
https://github.com/nilium/ooc.tmbundle:
|
||||
- source.ooc
|
||||
https://github.com/paulmillr/LiveScript.tmbundle:
|
||||
- source.livescript
|
||||
https://github.com/pferruggiaro/sublime-tea:
|
||||
- source.tea
|
||||
https://github.com/puppet-textmate-bundle/puppet-textmate-bundle:
|
||||
- source.puppet
|
||||
https://github.com/pvl/abap.tmbundle:
|
||||
- source.abap
|
||||
https://github.com/scalate/Scalate.tmbundle:
|
||||
- source.scaml
|
||||
- text.html.ssp
|
||||
https://github.com/shadanan/mathematica-tmbundle:
|
||||
- source.mathematica
|
||||
https://github.com/shellderp/sublime-robot-plugin:
|
||||
- text.robot
|
||||
https://github.com/simongregory/actionscript3-tmbundle:
|
||||
- source.actionscript.3
|
||||
- text.html.asdoc
|
||||
- text.xml.flex-config
|
||||
https://github.com/skozlovf/Sublime-QML:
|
||||
- source.qml
|
||||
https://github.com/slash-lang/Slash.tmbundle:
|
||||
- text.html.slash
|
||||
https://github.com/slavapestov/factor/raw/master/misc/Factor.tmbundle/Syntaxes/Factor.tmLanguage:
|
||||
- source.factor
|
||||
https://github.com/slim-template/ruby-slim.tmbundle:
|
||||
- text.slim
|
||||
https://github.com/smiledawgg/Bro.tmbundle:
|
||||
- source.bro
|
||||
- source.bro.sig
|
||||
https://github.com/staltz/SublimeXtend:
|
||||
- source.xtend
|
||||
https://github.com/statatmbundle/Stata.tmbundle:
|
||||
- source.mata
|
||||
- source.stata
|
||||
https://github.com/technosophos/Vala-TMBundle:
|
||||
- source.vala
|
||||
https://github.com/textmate/ant.tmbundle:
|
||||
- text.xml.ant
|
||||
https://github.com/textmate/antlr.tmbundle:
|
||||
- source.antlr
|
||||
https://github.com/textmate/apache.tmbundle:
|
||||
- source.apache-config
|
||||
- source.apache-config.mod_perl
|
||||
https://github.com/textmate/applescript.tmbundle:
|
||||
- source.applescript
|
||||
https://github.com/textmate/asp.tmbundle:
|
||||
- source.asp
|
||||
- text.html.asp
|
||||
https://github.com/textmate/bison.tmbundle:
|
||||
- source.bison
|
||||
https://github.com/textmate/c.tmbundle:
|
||||
- source.c
|
||||
- source.c++
|
||||
- source.c.platform
|
||||
https://github.com/textmate/capnproto.tmbundle:
|
||||
- source.capnp
|
||||
https://github.com/textmate/cmake.tmbundle:
|
||||
- source.cache.cmake
|
||||
- source.cmake
|
||||
https://github.com/textmate/cpp-qt.tmbundle:
|
||||
- source.c++.qt
|
||||
- source.qmake
|
||||
https://github.com/textmate/css.tmbundle:
|
||||
- source.css
|
||||
https://github.com/textmate/d.tmbundle:
|
||||
- source.d
|
||||
https://github.com/textmate/diff.tmbundle:
|
||||
- source.diff
|
||||
https://github.com/textmate/dylan.tmbundle:
|
||||
- source.dylan
|
||||
- source.lid
|
||||
- source.makegen
|
||||
https://github.com/textmate/eiffel.tmbundle:
|
||||
- source.eiffel
|
||||
https://github.com/textmate/erlang.tmbundle:
|
||||
- source.erlang
|
||||
- text.html.erlang.yaws
|
||||
https://github.com/textmate/fortran.tmbundle:
|
||||
- source.fortran
|
||||
- source.fortran.modern
|
||||
https://github.com/textmate/gettext.tmbundle:
|
||||
- source.po
|
||||
https://github.com/textmate/graphviz.tmbundle:
|
||||
- source.dot
|
||||
https://github.com/textmate/groovy.tmbundle:
|
||||
- source.groovy
|
||||
https://github.com/textmate/haskell.tmbundle:
|
||||
- source.haskell
|
||||
- text.tex.latex.haskell
|
||||
https://github.com/textmate/html.tmbundle:
|
||||
- text.html.basic
|
||||
https://github.com/textmate/ini.tmbundle:
|
||||
vendor/grammars/ini.tmbundle:
|
||||
- source.ini
|
||||
https://github.com/textmate/io.tmbundle:
|
||||
vendor/grammars/io.tmbundle:
|
||||
- source.io
|
||||
https://github.com/textmate/java.tmbundle:
|
||||
vendor/grammars/ioke-outdated:
|
||||
- source.ioke
|
||||
vendor/grammars/jade-tmbundle:
|
||||
- source.jade
|
||||
- source.pyjade
|
||||
vendor/grammars/jasmin-sublime:
|
||||
- source.jasmin
|
||||
vendor/grammars/java.tmbundle:
|
||||
- source.java
|
||||
- source.java-properties
|
||||
- text.html.jsp
|
||||
- text.junit-test-report
|
||||
https://github.com/textmate/javadoc.tmbundle:
|
||||
vendor/grammars/javadoc.tmbundle:
|
||||
- text.html.javadoc
|
||||
https://github.com/textmate/javascript-objective-j.tmbundle:
|
||||
vendor/grammars/javascript-objective-j.tmbundle:
|
||||
- source.js.objj
|
||||
https://github.com/textmate/json.tmbundle:
|
||||
vendor/grammars/jquery-tmbundle:
|
||||
- source.js.jquery
|
||||
vendor/grammars/json.tmbundle:
|
||||
- source.json
|
||||
https://github.com/textmate/latex.tmbundle:
|
||||
vendor/grammars/kotlin-sublime-package:
|
||||
- source.Kotlin
|
||||
vendor/grammars/language-clojure:
|
||||
- source.clojure
|
||||
vendor/grammars/language-coffee-script:
|
||||
- source.coffee
|
||||
- source.litcoffee
|
||||
vendor/grammars/language-csharp:
|
||||
- source.cs
|
||||
- source.csx
|
||||
- source.nant-build
|
||||
vendor/grammars/language-gfm:
|
||||
- source.gfm
|
||||
vendor/grammars/language-javascript:
|
||||
- source.js
|
||||
- source.js.regexp
|
||||
vendor/grammars/language-python:
|
||||
- source.python
|
||||
- source.regexp.python
|
||||
- text.python.console
|
||||
- text.python.traceback
|
||||
vendor/grammars/language-shellscript:
|
||||
- source.shell
|
||||
- text.shell-session
|
||||
vendor/grammars/language-yaml:
|
||||
- source.yaml
|
||||
vendor/grammars/latex.tmbundle:
|
||||
- text.bibtex
|
||||
- text.log.latex
|
||||
- text.tex
|
||||
- text.tex.latex
|
||||
- text.tex.latex.beamer
|
||||
- text.tex.latex.memoir
|
||||
https://github.com/textmate/less.tmbundle:
|
||||
vendor/grammars/less.tmbundle:
|
||||
- source.css.less
|
||||
https://github.com/textmate/lilypond.tmbundle:
|
||||
vendor/grammars/lilypond.tmbundle:
|
||||
- source.lilypond
|
||||
https://github.com/textmate/lisp.tmbundle:
|
||||
vendor/grammars/lisp.tmbundle:
|
||||
- source.lisp
|
||||
https://github.com/textmate/logtalk.tmbundle:
|
||||
vendor/grammars/llvm.tmbundle:
|
||||
- source.llvm
|
||||
vendor/grammars/logtalk.tmbundle:
|
||||
- source.logtalk
|
||||
https://github.com/textmate/lua.tmbundle:
|
||||
vendor/grammars/lua.tmbundle:
|
||||
- source.lua
|
||||
https://github.com/textmate/make.tmbundle:
|
||||
vendor/grammars/make.tmbundle:
|
||||
- source.makefile
|
||||
https://github.com/textmate/markdown.tmbundle:
|
||||
- text.html.markdown
|
||||
https://github.com/textmate/matlab.tmbundle:
|
||||
vendor/grammars/mako-tmbundle:
|
||||
- text.html.mako
|
||||
vendor/grammars/mathematica-tmbundle:
|
||||
- source.mathematica
|
||||
vendor/grammars/matlab.tmbundle:
|
||||
- source.matlab
|
||||
- source.octave
|
||||
https://github.com/textmate/maven.tmbundle:
|
||||
vendor/grammars/maven.tmbundle:
|
||||
- text.xml.pom
|
||||
https://github.com/textmate/nemerle.tmbundle:
|
||||
vendor/grammars/mercury-tmlanguage:
|
||||
- source.mercury
|
||||
vendor/grammars/monkey.tmbundle:
|
||||
- source.monkey
|
||||
vendor/grammars/moonscript-tmbundle:
|
||||
- source.moonscript
|
||||
vendor/grammars/nemerle.tmbundle:
|
||||
- source.nemerle
|
||||
https://github.com/textmate/ninja.tmbundle:
|
||||
vendor/grammars/nesC.tmbundle:
|
||||
- source.nesc
|
||||
vendor/grammars/ninja.tmbundle:
|
||||
- source.ninja
|
||||
https://github.com/textmate/objective-c.tmbundle:
|
||||
vendor/grammars/objective-c.tmbundle:
|
||||
- source.objc
|
||||
- source.objc++
|
||||
- source.objc.platform
|
||||
- source.strings
|
||||
https://github.com/textmate/ocaml.tmbundle:
|
||||
vendor/grammars/ocaml.tmbundle:
|
||||
- source.camlp4.ocaml
|
||||
- source.ocaml
|
||||
- source.ocamllex
|
||||
- source.ocamlyacc
|
||||
https://github.com/textmate/pascal.tmbundle:
|
||||
vendor/grammars/ooc.tmbundle:
|
||||
- source.ooc
|
||||
vendor/grammars/opa.tmbundle:
|
||||
- source.opa
|
||||
vendor/grammars/oz-tmbundle/Syntaxes/Oz.tmLanguage:
|
||||
- source.oz
|
||||
vendor/grammars/pascal.tmbundle:
|
||||
- source.pascal
|
||||
https://github.com/textmate/perl.tmbundle:
|
||||
vendor/grammars/perl.tmbundle:
|
||||
- source.perl
|
||||
https://github.com/textmate/php-smarty.tmbundle:
|
||||
vendor/grammars/php-smarty.tmbundle:
|
||||
- source.smarty
|
||||
https://github.com/textmate/php.tmbundle:
|
||||
vendor/grammars/php.tmbundle:
|
||||
- text.html.php
|
||||
https://github.com/textmate/postscript.tmbundle:
|
||||
vendor/grammars/pike-textmate:
|
||||
- source.pike
|
||||
vendor/grammars/postscript.tmbundle:
|
||||
- source.postscript
|
||||
https://github.com/textmate/processing.tmbundle:
|
||||
vendor/grammars/powershell.tmbundle:
|
||||
- source.powershell
|
||||
vendor/grammars/processing.tmbundle:
|
||||
- source.processing
|
||||
https://github.com/textmate/prolog.tmbundle:
|
||||
vendor/grammars/prolog.tmbundle:
|
||||
- source.prolog
|
||||
https://github.com/textmate/python-django.tmbundle:
|
||||
vendor/grammars/protobuf-tmbundle:
|
||||
- source.protobuf
|
||||
vendor/grammars/puppet-textmate-bundle:
|
||||
- source.puppet
|
||||
vendor/grammars/python-django.tmbundle:
|
||||
- source.python.django
|
||||
- text.html.django
|
||||
https://github.com/textmate/r.tmbundle:
|
||||
vendor/grammars/r.tmbundle:
|
||||
- source.r
|
||||
- text.tex.latex.rd
|
||||
https://github.com/textmate/restructuredtext.tmbundle:
|
||||
vendor/grammars/racket-tmbundle:
|
||||
- source.racket
|
||||
vendor/grammars/restructuredtext.tmbundle:
|
||||
- text.restructuredtext
|
||||
https://github.com/textmate/ruby-haml.tmbundle:
|
||||
vendor/grammars/ruby-haml.tmbundle:
|
||||
- text.haml
|
||||
https://github.com/textmate/ruby-on-rails-tmbundle:
|
||||
vendor/grammars/ruby-on-rails-tmbundle:
|
||||
- source.js.erb.rails
|
||||
- source.ruby.rails
|
||||
- source.ruby.rails.rjs
|
||||
- source.sql.ruby
|
||||
- text.html.erb.rails
|
||||
https://github.com/textmate/scheme.tmbundle:
|
||||
vendor/grammars/ruby-slim.tmbundle:
|
||||
- text.slim
|
||||
vendor/grammars/ruby.tmbundle:
|
||||
- source.ruby
|
||||
- text.html.erb
|
||||
vendor/grammars/sas.tmbundle:
|
||||
- source.SASLog
|
||||
- source.sas
|
||||
vendor/grammars/sass-textmate-bundle:
|
||||
- source.sass
|
||||
vendor/grammars/scala.tmbundle:
|
||||
- source.sbt
|
||||
- source.scala
|
||||
vendor/grammars/scheme.tmbundle:
|
||||
- source.scheme
|
||||
https://github.com/textmate/scilab.tmbundle:
|
||||
vendor/grammars/scilab.tmbundle:
|
||||
- source.scilab
|
||||
https://github.com/textmate/sql.tmbundle:
|
||||
vendor/grammars/smalltalk-tmbundle:
|
||||
- source.smalltalk
|
||||
vendor/grammars/sql.tmbundle:
|
||||
- source.sql
|
||||
https://github.com/textmate/standard-ml.tmbundle:
|
||||
vendor/grammars/standard-ml.tmbundle:
|
||||
- source.cm
|
||||
- source.ml
|
||||
https://github.com/textmate/swift.tmbundle:
|
||||
vendor/grammars/sublime-MuPAD:
|
||||
- source.mupad
|
||||
vendor/grammars/sublime-befunge:
|
||||
- source.befunge
|
||||
vendor/grammars/sublime-better-typescript:
|
||||
- source.ts
|
||||
vendor/grammars/sublime-bsv:
|
||||
- source.bsv
|
||||
vendor/grammars/sublime-cirru:
|
||||
- source.cirru
|
||||
vendor/grammars/sublime-glsl:
|
||||
- source.essl
|
||||
- source.glsl
|
||||
vendor/grammars/sublime-idris:
|
||||
- source.idris
|
||||
vendor/grammars/sublime-mask:
|
||||
- source.mask
|
||||
vendor/grammars/sublime-nginx:
|
||||
- source.nginx
|
||||
vendor/grammars/sublime-nix:
|
||||
- source.nix
|
||||
vendor/grammars/sublime-robot-plugin:
|
||||
- text.robot
|
||||
vendor/grammars/sublime-rust:
|
||||
- source.rust
|
||||
vendor/grammars/sublime-sourcepawn:
|
||||
- source.sp
|
||||
vendor/grammars/sublime-tea:
|
||||
- source.tea
|
||||
vendor/grammars/sublime_cobol:
|
||||
- source.acucobol
|
||||
- source.cobol
|
||||
- source.opencobol
|
||||
vendor/grammars/sublime_man_page_support:
|
||||
- source.man
|
||||
- text.groff
|
||||
vendor/grammars/sublimetext-cuda-cpp:
|
||||
- source.cuda-c++
|
||||
vendor/grammars/swift.tmbundle:
|
||||
- source.swift
|
||||
https://github.com/textmate/tcl.tmbundle:
|
||||
vendor/grammars/tcl.tmbundle:
|
||||
- source.tcl
|
||||
- text.html.tcl
|
||||
https://github.com/textmate/text.tmbundle:
|
||||
vendor/grammars/text.tmbundle:
|
||||
- text.plain
|
||||
https://github.com/textmate/textile.tmbundle:
|
||||
vendor/grammars/textile.tmbundle:
|
||||
- text.html.textile
|
||||
https://github.com/textmate/textmate.tmbundle:
|
||||
vendor/grammars/textmate.tmbundle:
|
||||
- source.regexp.oniguruma
|
||||
- source.tm-properties
|
||||
https://github.com/textmate/thrift.tmbundle:
|
||||
vendor/grammars/thrift.tmbundle:
|
||||
- source.thrift
|
||||
https://github.com/textmate/toml.tmbundle:
|
||||
vendor/grammars/toml.tmbundle:
|
||||
- source.toml
|
||||
https://github.com/textmate/verilog.tmbundle:
|
||||
vendor/grammars/verilog.tmbundle:
|
||||
- source.verilog
|
||||
https://github.com/textmate/xml.tmbundle:
|
||||
vendor/grammars/x86-assembly-textmate-bundle:
|
||||
- source.asm.x86
|
||||
vendor/grammars/xml.tmbundle:
|
||||
- text.xml
|
||||
- text.xml.xsl
|
||||
https://github.com/textmate/yaml.tmbundle:
|
||||
- source.yaml
|
||||
https://github.com/tomas-stefano/smalltalk-tmbundle:
|
||||
- source.smalltalk
|
||||
https://github.com/vic/ioke-outdated/raw/master/share/TextMate/Ioke.tmbundle/Syntaxes/Ioke.tmLanguage:
|
||||
- source.ioke
|
||||
https://github.com/vkostyukov/kotlin-sublime-package:
|
||||
- source.Kotlin
|
||||
https://github.com/vmg/zephir-sublime:
|
||||
vendor/grammars/zephir-sublime:
|
||||
- source.php.zephir
|
||||
https://github.com/whitequark/llvm.tmbundle:
|
||||
- source.llvm
|
||||
|
||||
@@ -4,4 +4,5 @@ require 'linguist/heuristics'
|
||||
require 'linguist/language'
|
||||
require 'linguist/repository'
|
||||
require 'linguist/samples'
|
||||
require 'linguist/shebang'
|
||||
require 'linguist/version'
|
||||
|
||||
@@ -3,6 +3,25 @@ require 'linguist/tokenizer'
|
||||
module Linguist
|
||||
# Language bayesian classifier.
|
||||
class Classifier
|
||||
# Public: Use the classifier to detect language of the blob.
|
||||
#
|
||||
# blob - An object that quacks like a blob.
|
||||
# possible_languages - Array of Language objects
|
||||
#
|
||||
# Examples
|
||||
#
|
||||
# Classifier.call(FileBlob.new("path/to/file"), [
|
||||
# Language["Ruby"], Language["Python"]
|
||||
# ])
|
||||
#
|
||||
# Returns an Array of Language objects, most probable first.
|
||||
def self.call(blob, possible_languages)
|
||||
language_names = possible_languages.map(&:name)
|
||||
classify(Samples.cache, blob.data, language_names).map do |name, _|
|
||||
Language[name] # Return the actual Language objects
|
||||
end
|
||||
end
|
||||
|
||||
# Public: Train classifier that data is a certain language.
|
||||
#
|
||||
# db - Hash classifier database object
|
||||
|
||||
@@ -57,14 +57,20 @@ module Linguist
|
||||
#
|
||||
# Returns a String.
|
||||
def extension
|
||||
# File.extname returns nil if the filename is an extension.
|
||||
extension = File.extname(name)
|
||||
basename = File.basename(name)
|
||||
# Checks if the filename is an extension.
|
||||
if extension.empty? && basename[0] == "."
|
||||
basename
|
||||
else
|
||||
extension
|
||||
extensions.last || ""
|
||||
end
|
||||
|
||||
# Public: Return an array of the file extensions
|
||||
#
|
||||
# >> Linguist::FileBlob.new("app/views/things/index.html.erb").extensions
|
||||
# => [".html.erb", ".erb"]
|
||||
#
|
||||
# Returns an Array
|
||||
def extensions
|
||||
basename, *segments = File.basename(name).split(".")
|
||||
|
||||
segments.map.with_index do |segment, index|
|
||||
"." + segments[index..-1].join(".")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -51,20 +51,20 @@ module Linguist
|
||||
#
|
||||
# Return true or false
|
||||
def generated?
|
||||
minified_files? ||
|
||||
compiled_coffeescript? ||
|
||||
xcode_file? ||
|
||||
generated_parser? ||
|
||||
generated_net_docfile? ||
|
||||
generated_net_designer_file? ||
|
||||
generated_postscript? ||
|
||||
generated_protocol_buffer? ||
|
||||
generated_jni_header? ||
|
||||
composer_lock? ||
|
||||
node_modules? ||
|
||||
godeps? ||
|
||||
vcr_cassette? ||
|
||||
generated_by_zephir?
|
||||
generated_by_zephir? ||
|
||||
minified_files? ||
|
||||
compiled_coffeescript? ||
|
||||
generated_parser? ||
|
||||
generated_net_docfile? ||
|
||||
generated_postscript? ||
|
||||
generated_protocol_buffer? ||
|
||||
generated_jni_header? ||
|
||||
vcr_cassette?
|
||||
end
|
||||
|
||||
# Internal: Is the blob an Xcode file?
|
||||
|
||||
@@ -1,158 +1,185 @@
|
||||
module Linguist
|
||||
# A collection of simple heuristics that can be used to better analyze languages.
|
||||
class Heuristics
|
||||
ACTIVE = true
|
||||
|
||||
# Public: Given an array of String language names,
|
||||
# apply heuristics against the given data and return an array
|
||||
# of matching languages, or nil.
|
||||
# Public: Use heuristics to detect language of the blob.
|
||||
#
|
||||
# data - Array of tokens or String data to analyze.
|
||||
# languages - Array of language name Strings to restrict to.
|
||||
# blob - An object that quacks like a blob.
|
||||
# possible_languages - Array of Language objects
|
||||
#
|
||||
# Returns an array of Languages or []
|
||||
def self.find_by_heuristics(data, languages)
|
||||
if active?
|
||||
result = []
|
||||
# Examples
|
||||
#
|
||||
# Heuristics.call(FileBlob.new("path/to/file"), [
|
||||
# Language["Ruby"], Language["Python"]
|
||||
# ])
|
||||
#
|
||||
# Returns an Array of languages, or empty if none matched or were inconclusive.
|
||||
def self.call(blob, languages)
|
||||
data = blob.data
|
||||
|
||||
if languages.all? { |l| ["Perl", "Prolog"].include?(l) }
|
||||
result = disambiguate_pl(data)
|
||||
end
|
||||
if languages.all? { |l| ["ECL", "Prolog"].include?(l) }
|
||||
result = disambiguate_ecl(data)
|
||||
end
|
||||
if languages.all? { |l| ["IDL", "Prolog"].include?(l) }
|
||||
result = disambiguate_pro(data)
|
||||
end
|
||||
if languages.all? { |l| ["Common Lisp", "OpenCL"].include?(l) }
|
||||
result = disambiguate_cl(data)
|
||||
end
|
||||
if languages.all? { |l| ["Hack", "PHP"].include?(l) }
|
||||
result = disambiguate_hack(data)
|
||||
end
|
||||
if languages.all? { |l| ["Scala", "SuperCollider"].include?(l) }
|
||||
result = disambiguate_sc(data)
|
||||
end
|
||||
if languages.all? { |l| ["AsciiDoc", "AGS Script"].include?(l) }
|
||||
result = disambiguate_asc(data)
|
||||
end
|
||||
if languages.all? { |l| ["FORTRAN", "Forth"].include?(l) }
|
||||
result = disambiguate_f(data)
|
||||
end
|
||||
return result
|
||||
@heuristics.each do |heuristic|
|
||||
return Array(heuristic.call(data)) if heuristic.matches?(languages)
|
||||
end
|
||||
|
||||
[] # No heuristics matched
|
||||
end
|
||||
|
||||
# Internal: Define a new heuristic.
|
||||
#
|
||||
# languages - String names of languages to disambiguate.
|
||||
# heuristic - Block which takes data as an argument and returns a Language or nil.
|
||||
#
|
||||
# Examples
|
||||
#
|
||||
# disambiguate "Perl", "Prolog" do |data|
|
||||
# if data.include?("use strict")
|
||||
# Language["Perl"]
|
||||
# elsif data.include?(":-")
|
||||
# Language["Prolog"]
|
||||
# end
|
||||
# end
|
||||
#
|
||||
def self.disambiguate(*languages, &heuristic)
|
||||
@heuristics << new(languages, &heuristic)
|
||||
end
|
||||
|
||||
# Internal: Array of defined heuristics
|
||||
@heuristics = []
|
||||
|
||||
# Internal
|
||||
def initialize(languages, &heuristic)
|
||||
@languages = languages
|
||||
@heuristic = heuristic
|
||||
end
|
||||
|
||||
# Internal: Check if this heuristic matches the candidate languages.
|
||||
def matches?(candidates)
|
||||
candidates.any? && candidates.all? { |l| @languages.include?(l.name) }
|
||||
end
|
||||
|
||||
# Internal: Perform the heuristic
|
||||
def call(data)
|
||||
@heuristic.call(data)
|
||||
end
|
||||
|
||||
disambiguate "BitBake", "BlitzBasic" do |data|
|
||||
if /^\s*; /.match(data) || data.include?("End Function")
|
||||
Language["BlitzBasic"]
|
||||
elsif /^\s*(# |include|require)\b/.match(data)
|
||||
Language["BitBake"]
|
||||
end
|
||||
end
|
||||
|
||||
# .h extensions are ambiguous between C, C++, and Objective-C.
|
||||
# We want to shortcut look for Objective-C _and_ now C++ too!
|
||||
#
|
||||
# Returns an array of Languages or []
|
||||
def self.disambiguate_c(data)
|
||||
matches = []
|
||||
if data.include?("@interface")
|
||||
matches << Language["Objective-C"]
|
||||
elsif data.include?("#include <cstdint>")
|
||||
matches << Language["C++"]
|
||||
disambiguate "Objective-C", "C++", "C" do |data|
|
||||
if (/^[ \t]*@(interface|class|protocol|property|end|synchronised|selector|implementation)\b/.match(data))
|
||||
Language["Objective-C"]
|
||||
elsif (/^\s*#\s*include <(cstdint|string|vector|map|list|array|bitset|queue|stack|forward_list|unordered_map|unordered_set|(i|o|io)stream)>/.match(data) ||
|
||||
/^\s*template\s*</.match(data) || /^[ \t]*try/.match(data) || /^[ \t]*catch\s*\(/.match(data) || /^[ \t]*(class|(using[ \t]+)?namespace)\s+\w+/.match(data) || /^[ \t]*(private|public|protected):$/.match(data) || /std::\w+/.match(data))
|
||||
Language["C++"]
|
||||
end
|
||||
matches
|
||||
end
|
||||
|
||||
def self.disambiguate_pl(data)
|
||||
matches = []
|
||||
if data.include?("use strict")
|
||||
matches << Language["Perl"]
|
||||
disambiguate "Perl", "Perl6", "Prolog" do |data|
|
||||
if data.include?("use v6")
|
||||
Language["Perl6"]
|
||||
elsif data.include?("use strict")
|
||||
Language["Perl"]
|
||||
elsif data.include?(":-")
|
||||
matches << Language["Prolog"]
|
||||
Language["Prolog"]
|
||||
end
|
||||
matches
|
||||
end
|
||||
|
||||
def self.disambiguate_ecl(data)
|
||||
matches = []
|
||||
disambiguate "ECL", "Prolog" do |data|
|
||||
if data.include?(":-")
|
||||
matches << Language["Prolog"]
|
||||
Language["Prolog"]
|
||||
elsif data.include?(":=")
|
||||
matches << Language["ECL"]
|
||||
Language["ECL"]
|
||||
end
|
||||
matches
|
||||
end
|
||||
|
||||
def self.disambiguate_pro(data)
|
||||
matches = []
|
||||
if (data.include?(":-"))
|
||||
matches << Language["Prolog"]
|
||||
disambiguate "IDL", "Prolog" do |data|
|
||||
if data.include?(":-")
|
||||
Language["Prolog"]
|
||||
else
|
||||
matches << Language["IDL"]
|
||||
Language["IDL"]
|
||||
end
|
||||
matches
|
||||
end
|
||||
|
||||
def self.disambiguate_ts(data)
|
||||
matches = []
|
||||
if (data.include?("</translation>"))
|
||||
matches << Language["XML"]
|
||||
else
|
||||
matches << Language["TypeScript"]
|
||||
end
|
||||
matches
|
||||
end
|
||||
|
||||
def self.disambiguate_cl(data)
|
||||
matches = []
|
||||
disambiguate "Common Lisp", "OpenCL", "Cool" do |data|
|
||||
if data.include?("(defun ")
|
||||
matches << Language["Common Lisp"]
|
||||
Language["Common Lisp"]
|
||||
elsif /^class/x.match(data)
|
||||
Language["Cool"]
|
||||
elsif /\/\* |\/\/ |^\}/.match(data)
|
||||
matches << Language["OpenCL"]
|
||||
Language["OpenCL"]
|
||||
end
|
||||
matches
|
||||
end
|
||||
|
||||
def self.disambiguate_r(data)
|
||||
matches = []
|
||||
matches << Language["Rebol"] if /\bRebol\b/i.match(data)
|
||||
matches << Language["R"] if data.include?("<-")
|
||||
matches
|
||||
end
|
||||
|
||||
def self.disambiguate_hack(data)
|
||||
matches = []
|
||||
disambiguate "Hack", "PHP" do |data|
|
||||
if data.include?("<?hh")
|
||||
matches << Language["Hack"]
|
||||
Language["Hack"]
|
||||
elsif /<?[^h]/.match(data)
|
||||
matches << Language["PHP"]
|
||||
Language["PHP"]
|
||||
end
|
||||
matches
|
||||
end
|
||||
|
||||
def self.disambiguate_sc(data)
|
||||
matches = []
|
||||
if (/\^(this|super)\./.match(data) || /^\s*(\+|\*)\s*\w+\s*{/.match(data) || /^\s*~\w+\s*=\./.match(data))
|
||||
matches << Language["SuperCollider"]
|
||||
disambiguate "Scala", "SuperCollider" do |data|
|
||||
if /\^(this|super)\./.match(data) || /^\s*(\+|\*)\s*\w+\s*{/.match(data) || /^\s*~\w+\s*=\./.match(data)
|
||||
Language["SuperCollider"]
|
||||
elsif /^\s*import (scala|java)\./.match(data) || /^\s*val\s+\w+\s*=/.match(data) || /^\s*class\b/.match(data)
|
||||
Language["Scala"]
|
||||
end
|
||||
if (/^\s*import (scala|java)\./.match(data) || /^\s*val\s+\w+\s*=/.match(data) || /^\s*class\b/.match(data))
|
||||
matches << Language["Scala"]
|
||||
end
|
||||
matches
|
||||
end
|
||||
|
||||
def self.disambiguate_asc(data)
|
||||
matches = []
|
||||
matches << Language["AsciiDoc"] if /^=+(\s|\n)/.match(data)
|
||||
matches
|
||||
disambiguate "AsciiDoc", "AGS Script" do |data|
|
||||
Language["AsciiDoc"] if /^=+(\s|\n)/.match(data)
|
||||
end
|
||||
|
||||
def self.disambiguate_f(data)
|
||||
matches = []
|
||||
disambiguate "FORTRAN", "Forth" do |data|
|
||||
if /^: /.match(data)
|
||||
matches << Language["Forth"]
|
||||
elsif /^([c*][^a-z]| subroutine\s)/i.match(data)
|
||||
matches << Language["FORTRAN"]
|
||||
Language["Forth"]
|
||||
elsif /^([c*][^a-z]| (subroutine|program)\s|!)/i.match(data)
|
||||
Language["FORTRAN"]
|
||||
end
|
||||
matches
|
||||
end
|
||||
|
||||
def self.active?
|
||||
!!ACTIVE
|
||||
disambiguate "F#", "Forth", "GLSL" do |data|
|
||||
if /^(: |new-device)/.match(data)
|
||||
Language["Forth"]
|
||||
elsif /^\s*(#light|import|let|module|namespace|open|type)/.match(data)
|
||||
Language["F#"]
|
||||
elsif /^\s*(#include|#pragma|precision|uniform|varying|void)/.match(data)
|
||||
Language["GLSL"]
|
||||
end
|
||||
end
|
||||
|
||||
disambiguate "Gosu", "JavaScript" do |data|
|
||||
Language["Gosu"] if /^uses java\./.match(data)
|
||||
end
|
||||
|
||||
disambiguate "LoomScript", "LiveScript" do |data|
|
||||
if /^\s*package\s*[\w\.\/\*\s]*\s*{/.match(data)
|
||||
Language["LoomScript"]
|
||||
else
|
||||
Language["LiveScript"]
|
||||
end
|
||||
end
|
||||
|
||||
disambiguate "TypeScript", "XML" do |data|
|
||||
if data.include?("<TS ")
|
||||
Language["XML"]
|
||||
else
|
||||
Language["TypeScript"]
|
||||
end
|
||||
end
|
||||
|
||||
disambiguate "Frege", "Forth", "Text" do |data|
|
||||
if /^(: |also |new-device|previous )/.match(data)
|
||||
Language["Forth"]
|
||||
elsif /\s*(import|module|package|data|type) /.match(data)
|
||||
Language["Frege"]
|
||||
else
|
||||
Language["Text"]
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -10,6 +10,8 @@ require 'linguist/heuristics'
|
||||
require 'linguist/samples'
|
||||
require 'linguist/file_blob'
|
||||
require 'linguist/blob_helper'
|
||||
require 'linguist/strategy/filename'
|
||||
require 'linguist/shebang'
|
||||
|
||||
module Linguist
|
||||
# Language names that are recognizable by GitHub. Defined languages
|
||||
@@ -91,6 +93,13 @@ module Linguist
|
||||
language
|
||||
end
|
||||
|
||||
STRATEGIES = [
|
||||
Linguist::Strategy::Filename,
|
||||
Linguist::Shebang,
|
||||
Linguist::Heuristics,
|
||||
Linguist::Classifier
|
||||
]
|
||||
|
||||
# Public: Detects the Language of the blob.
|
||||
#
|
||||
# blob - an object that includes the Linguist `BlobHelper` interface;
|
||||
@@ -98,49 +107,22 @@ module Linguist
|
||||
#
|
||||
# Returns Language or nil.
|
||||
def self.detect(blob)
|
||||
name = blob.name.to_s
|
||||
|
||||
# Bail early if the blob is binary or empty.
|
||||
return nil if blob.likely_binary? || blob.binary? || blob.empty?
|
||||
|
||||
# A bit of an elegant hack. If the file is executable but extensionless,
|
||||
# append a "magic" extension so it can be classified with other
|
||||
# languages that have shebang scripts.
|
||||
extension = FileBlob.new(name).extension
|
||||
if extension.empty? && blob.mode && (blob.mode.to_i(8) & 05) == 05
|
||||
name += ".script!"
|
||||
end
|
||||
|
||||
# First try to find languages that match based on filename.
|
||||
possible_languages = find_by_filename(name)
|
||||
|
||||
# If there is more than one possible language with that extension (or no
|
||||
# extension at all, in the case of extensionless scripts), we need to continue
|
||||
# our detection work
|
||||
if possible_languages.length > 1
|
||||
data = blob.data
|
||||
possible_language_names = possible_languages.map(&:name)
|
||||
heuristic_languages = Heuristics.find_by_heuristics(data, possible_language_names)
|
||||
|
||||
if heuristic_languages.size > 1
|
||||
possible_language_names = heuristic_languages.map(&:name)
|
||||
# Call each strategy until one candidate is returned.
|
||||
STRATEGIES.reduce([]) do |languages, strategy|
|
||||
candidates = strategy.call(blob, languages)
|
||||
if candidates.size == 1
|
||||
return candidates.first
|
||||
elsif candidates.size > 1
|
||||
# More than one candidate was found, pass them to the next strategy.
|
||||
candidates
|
||||
else
|
||||
# No candiates were found, pass on languages from the previous strategy.
|
||||
languages
|
||||
end
|
||||
|
||||
# Check if there's a shebang line and use that as authoritative
|
||||
if (result = find_by_shebang(data)) && !result.empty?
|
||||
result.first
|
||||
# No shebang. Still more work to do. Try to find it with our heuristics.
|
||||
elsif heuristic_languages.size == 1
|
||||
heuristic_languages.first
|
||||
# Lastly, fall back to the probabilistic classifier.
|
||||
elsif classified = Classifier.classify(Samples.cache, data, possible_language_names).first
|
||||
# Return the actual Language object based of the string language name (i.e., first element of `#classify`)
|
||||
Language[classified[0]]
|
||||
end
|
||||
else
|
||||
# Simplest and most common case, we can just return the one match based on extension
|
||||
possible_languages.first
|
||||
end
|
||||
end.first
|
||||
end
|
||||
|
||||
# Public: Get all Languages
|
||||
@@ -190,8 +172,13 @@ module Linguist
|
||||
# Returns all matching Languages or [] if none were found.
|
||||
def self.find_by_filename(filename)
|
||||
basename = File.basename(filename)
|
||||
extname = FileBlob.new(filename).extension
|
||||
(@filename_index[basename] + find_by_extension(extname)).compact.uniq
|
||||
|
||||
# find the first extension with language definitions
|
||||
extname = FileBlob.new(filename).extensions.detect do |e|
|
||||
!@extension_index[e].empty?
|
||||
end
|
||||
|
||||
(@filename_index[basename] + @extension_index[extname]).compact.uniq
|
||||
end
|
||||
|
||||
# Public: Look up Languages by file extension.
|
||||
@@ -212,20 +199,26 @@ module Linguist
|
||||
@extension_index[extname]
|
||||
end
|
||||
|
||||
# Public: Look up Languages by shebang line.
|
||||
# DEPRECATED
|
||||
def self.find_by_shebang(data)
|
||||
@interpreter_index[Shebang.interpreter(data)]
|
||||
end
|
||||
|
||||
# Public: Look up Languages by interpreter.
|
||||
#
|
||||
# data - Array of tokens or String data to analyze.
|
||||
# interpreter - String of interpreter name
|
||||
#
|
||||
# Examples
|
||||
#
|
||||
# Language.find_by_shebang("#!/bin/bash\ndate;")
|
||||
# Language.find_by_interpreter("bash")
|
||||
# # => [#<Language name="Bash">]
|
||||
#
|
||||
# Returns the matching Language
|
||||
def self.find_by_shebang(data)
|
||||
@interpreter_index[Linguist.interpreter_from_shebang(data)]
|
||||
def self.find_by_interpreter(interpreter)
|
||||
@interpreter_index[interpreter]
|
||||
end
|
||||
|
||||
|
||||
# Public: Look up Language by its name or lexer.
|
||||
#
|
||||
# name - The String name of the Language
|
||||
@@ -276,8 +269,12 @@ module Linguist
|
||||
|
||||
# Public: A List of languages compatible with Ace.
|
||||
#
|
||||
# TODO: Remove this method in a 5.x release. Every language now needs an ace_mode
|
||||
# key, so this function isn't doing anything unique anymore.
|
||||
#
|
||||
# Returns an Array of Languages.
|
||||
def self.ace_modes
|
||||
warn "This method will be deprecated in a future 5.x release. Every language now has an `ace_mode` set."
|
||||
@ace_modes ||= all.select(&:ace_mode).sort_by { |lang| lang.name.downcase }
|
||||
end
|
||||
|
||||
@@ -551,7 +548,7 @@ module Linguist
|
||||
|
||||
if extnames = extensions[name]
|
||||
extnames.each do |extname|
|
||||
if !options['extensions'].include?(extname)
|
||||
if !options['extensions'].index { |x| x.end_with? extname }
|
||||
warn "#{name} has a sample with extension (#{extname}) that isn't explicitly defined in languages.yml" unless extname == '.script!'
|
||||
options['extensions'] << extname
|
||||
end
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -3,7 +3,6 @@
|
||||
# This file should only be edited by GitHub staff
|
||||
|
||||
- ActionScript
|
||||
- Bash
|
||||
- C
|
||||
- C#
|
||||
- C++
|
||||
@@ -27,3 +26,4 @@
|
||||
- SQL
|
||||
- Scala
|
||||
- Scheme
|
||||
- Shell
|
||||
|
||||
@@ -6,6 +6,7 @@ end
|
||||
|
||||
require 'linguist/md5'
|
||||
require 'linguist/classifier'
|
||||
require 'linguist/shebang'
|
||||
|
||||
module Linguist
|
||||
# Model for accessing classifier training data.
|
||||
@@ -33,10 +34,6 @@ module Linguist
|
||||
Dir.entries(ROOT).sort!.each do |category|
|
||||
next if category == '.' || category == '..'
|
||||
|
||||
# Skip text and binary for now
|
||||
# Possibly reconsider this later
|
||||
next if category == 'Text' || category == 'Binary'
|
||||
|
||||
dirname = File.join(ROOT, category)
|
||||
Dir.entries(dirname).each do |filename|
|
||||
next if filename == '.' || filename == '..'
|
||||
@@ -52,14 +49,16 @@ module Linguist
|
||||
})
|
||||
end
|
||||
else
|
||||
path = File.join(dirname, filename)
|
||||
|
||||
if File.extname(filename) == ""
|
||||
raise "#{File.join(dirname, filename)} is missing an extension, maybe it belongs in filenames/ subdir"
|
||||
raise "#{path} is missing an extension, maybe it belongs in filenames/ subdir"
|
||||
end
|
||||
|
||||
yield({
|
||||
:path => File.join(dirname, filename),
|
||||
:path => path,
|
||||
:language => category,
|
||||
:interpreter => File.exist?(filename) ? Linguist.interpreter_from_shebang(File.read(filename)) : nil,
|
||||
:interpreter => Shebang.interpreter(File.read(path)),
|
||||
:extname => File.extname(filename)
|
||||
})
|
||||
end
|
||||
@@ -112,40 +111,4 @@ module Linguist
|
||||
db
|
||||
end
|
||||
end
|
||||
|
||||
# Used to retrieve the interpreter from the shebang line of a file's
|
||||
# data.
|
||||
def self.interpreter_from_shebang(data)
|
||||
lines = data.lines.to_a
|
||||
|
||||
if lines.any? && (match = lines[0].match(/(.+)\n?/)) && (bang = match[0]) =~ /^#!/
|
||||
bang.sub!(/^#! /, '#!')
|
||||
tokens = bang.split(' ')
|
||||
pieces = tokens.first.split('/')
|
||||
|
||||
if pieces.size > 1
|
||||
script = pieces.last
|
||||
else
|
||||
script = pieces.first.sub('#!', '')
|
||||
end
|
||||
|
||||
script = script == 'env' ? tokens[1] : script
|
||||
|
||||
# "python2.6" -> "python"
|
||||
if script =~ /((?:\d+\.?)+)/
|
||||
script.sub! $1, ''
|
||||
end
|
||||
|
||||
# Check for multiline shebang hacks that call `exec`
|
||||
if script == 'sh' &&
|
||||
lines[0...5].any? { |l| l.match(/exec (\w+).+\$0.+\$@/) }
|
||||
script = $1
|
||||
end
|
||||
|
||||
script
|
||||
else
|
||||
nil
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
53
lib/linguist/shebang.rb
Normal file
53
lib/linguist/shebang.rb
Normal file
@@ -0,0 +1,53 @@
|
||||
module Linguist
|
||||
class Shebang
|
||||
# Public: Use shebang to detect language of the blob.
|
||||
#
|
||||
# blob - An object that quacks like a blob.
|
||||
#
|
||||
# Examples
|
||||
#
|
||||
# Shebang.call(FileBlob.new("path/to/file"))
|
||||
#
|
||||
# Returns an Array with one Language if the blob has a shebang with a valid
|
||||
# interpreter, or empty if there is no shebang.
|
||||
def self.call(blob, _ = nil)
|
||||
Language.find_by_interpreter interpreter(blob.data)
|
||||
end
|
||||
|
||||
# Public: Get the interpreter from the shebang
|
||||
#
|
||||
# Returns a String or nil
|
||||
def self.interpreter(data)
|
||||
shebang = data.lines.first
|
||||
|
||||
# First line must start with #!
|
||||
return unless shebang && shebang.start_with?("#!")
|
||||
|
||||
# Get the parts of the shebang without the #!
|
||||
tokens = shebang.sub(/^#!\s*/, '').strip.split(' ')
|
||||
|
||||
# There was nothing after the #!
|
||||
return if tokens.empty?
|
||||
|
||||
# Get the name of the interpreter
|
||||
script = File.basename(tokens.first)
|
||||
|
||||
# Get next argument if interpreter was /usr/bin/env
|
||||
script = tokens[1] if script == 'env'
|
||||
|
||||
# Interpreter was /usr/bin/env with no arguments
|
||||
return unless script
|
||||
|
||||
# "python2.6" -> "python2"
|
||||
script.sub! /(\.\d+)$/, ''
|
||||
|
||||
# Check for multiline shebang hacks that call `exec`
|
||||
if script == 'sh' &&
|
||||
data.lines.first(5).any? { |l| l.match(/exec (\w+).+\$0.+\$@/) }
|
||||
script = $1
|
||||
end
|
||||
|
||||
File.basename(script)
|
||||
end
|
||||
end
|
||||
end
|
||||
20
lib/linguist/strategy/filename.rb
Normal file
20
lib/linguist/strategy/filename.rb
Normal file
@@ -0,0 +1,20 @@
|
||||
module Linguist
|
||||
module Strategy
|
||||
# Detects language based on filename and/or extension
|
||||
class Filename
|
||||
def self.call(blob, _)
|
||||
name = blob.name.to_s
|
||||
|
||||
# A bit of an elegant hack. If the file is executable but extensionless,
|
||||
# append a "magic" extension so it can be classified with other
|
||||
# languages that have shebang scripts.
|
||||
extensions = FileBlob.new(name).extensions
|
||||
if extensions.empty? && blob.mode && (blob.mode.to_i(8) & 05) == 05
|
||||
name += ".script!"
|
||||
end
|
||||
|
||||
Language.find_by_filename(name)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -32,6 +32,7 @@
|
||||
|
||||
# Erlang bundles
|
||||
- ^rebar$
|
||||
- erlang.mk
|
||||
|
||||
# Go dependencies
|
||||
- Godeps/_workspace/
|
||||
@@ -110,6 +111,9 @@
|
||||
# MathJax
|
||||
- (^|/)MathJax/
|
||||
|
||||
# Chart.js
|
||||
- (^|/)Chart\.js$
|
||||
|
||||
# Codemirror
|
||||
- (^|/)[Cc]ode[Mm]irror/(lib|mode|theme|addon|keymap)
|
||||
|
||||
@@ -229,9 +233,6 @@
|
||||
# .DS_Store's
|
||||
- .[Dd][Ss]_[Ss]tore$
|
||||
|
||||
# Mercury --use-subdirs
|
||||
- Mercury/
|
||||
|
||||
# R packages
|
||||
- ^vignettes/
|
||||
- ^inst/extdata/
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
module Linguist
|
||||
VERSION = "4.0.2"
|
||||
VERSION = "4.2.6"
|
||||
end
|
||||
|
||||
25
samples/BitBake/gstreamer-libav.bb
Normal file
25
samples/BitBake/gstreamer-libav.bb
Normal file
@@ -0,0 +1,25 @@
|
||||
include gstreamer1.0-libav.inc
|
||||
|
||||
LIC_FILES_CHKSUM = "file://COPYING;md5=b234ee4d69f5fce4486a80fdaf4a4263 \
|
||||
file://COPYING.LIB;md5=6762ed442b3822387a51c92d928ead0d \
|
||||
file://ext/libav/gstav.h;beginline=1;endline=18;md5=a752c35267d8276fd9ca3db6994fca9c \
|
||||
file://gst-libs/ext/libav/LICENSE;md5=23a54f59b82572c203a559346e89ed57 \
|
||||
file://gst-libs/ext/libav/COPYING.GPLv2;md5=b234ee4d69f5fce4486a80fdaf4a4263 \
|
||||
file://gst-libs/ext/libav/COPYING.GPLv3;md5=d32239bcb673463ab874e80d47fae504 \
|
||||
file://gst-libs/ext/libav/COPYING.LGPLv2.1;md5=bd7a443320af8c812e4c18d1b79df004 \
|
||||
file://gst-libs/ext/libav/COPYING.LGPLv3;md5=e6a600fd5e1d9cbde2d983680233ad02"
|
||||
|
||||
SRC_URI = " \
|
||||
http://gstreamer.freedesktop.org/src/gst-libav/gst-libav-${PV}.tar.xz \
|
||||
file://0001-Disable-yasm-for-libav-when-disable-yasm.patch \
|
||||
"
|
||||
SRC_URI[md5sum] = "86540dee14d31daf976eb2713f2294f3"
|
||||
SRC_URI[sha256sum] = "585eb7971006100ad771a852e07bd2f3e23bcc6eb0b1253a40b5a0e40e4e7418"
|
||||
|
||||
LIBAV_EXTRA_CONFIGURE_COMMON_ARG = "--target-os=linux \
|
||||
--cc='${CC}' --as='${CC}' --ld='${CC}' --nm='${NM}' --ar='${AR}' \
|
||||
--ranlib='${RANLIB}' \
|
||||
${GSTREAMER_1_0_DEBUG}"
|
||||
|
||||
S = "${WORKDIR}/gst-libav-${PV}"
|
||||
|
||||
13
samples/BitBake/qtbase-native.bb
Normal file
13
samples/BitBake/qtbase-native.bb
Normal file
@@ -0,0 +1,13 @@
|
||||
require qt5-git.inc
|
||||
require ${PN}.inc
|
||||
|
||||
do_install_append() {
|
||||
# for modules which are still using syncqt and call qtPrepareTool(QMAKE_SYNCQT, syncqt)
|
||||
# e.g. qt3d, qtwayland
|
||||
ln -sf syncqt.pl ${D}${OE_QMAKE_PATH_QT_BINS}/syncqt
|
||||
}
|
||||
|
||||
QT_MODULE_BRANCH = "release"
|
||||
# v5.2.1 + 168 commits
|
||||
SRCREV = "08cbbde61778276ccdda73d89fd64d02c623779f"
|
||||
|
||||
26
samples/C#/AssemblyInfo.cs
Normal file
26
samples/C#/AssemblyInfo.cs
Normal file
@@ -0,0 +1,26 @@
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
// Information about this assembly is defined by the following attributes.
|
||||
// Change them to the values specific to your project.
|
||||
|
||||
[assembly: AssemblyTitle("Simple")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("")]
|
||||
[assembly: AssemblyCopyright("")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
// The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}".
|
||||
// The form "{Major}.{Minor}.*" will automatically update the build and revision,
|
||||
// and "{Major}.{Minor}.{Build}.*" will update just the revision.
|
||||
|
||||
[assembly: AssemblyVersion("1.0.*")]
|
||||
|
||||
// The following attributes are used to specify the signing key for the assembly,
|
||||
// if desired. See the Mono documentation for more information about signing.
|
||||
|
||||
//[assembly: AssemblyDelaySign(false)]
|
||||
//[assembly: AssemblyKeyFile("")]
|
||||
20
samples/C#/BsonPropertyValue.cs
Normal file
20
samples/C#/BsonPropertyValue.cs
Normal file
@@ -0,0 +1,20 @@
|
||||
using System;
|
||||
|
||||
namespace MongoDB.Serialization.Descriptors
|
||||
{
|
||||
internal class BsonPropertyValue
|
||||
{
|
||||
public bool IsDictionary { get; private set; }
|
||||
|
||||
public Type Type { get; private set; }
|
||||
|
||||
public object Value { get; private set; }
|
||||
|
||||
public BsonPropertyValue(Type type, object value, bool isDictionary)
|
||||
{
|
||||
Type = type;
|
||||
Value = value;
|
||||
IsDictionary = isDictionary;
|
||||
}
|
||||
}
|
||||
}
|
||||
153
samples/C#/MongoExpressionVisitor.cs
Normal file
153
samples/C#/MongoExpressionVisitor.cs
Normal file
@@ -0,0 +1,153 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
|
||||
namespace MongoDB.Linq.Expressions
|
||||
{
|
||||
internal class MongoExpressionVisitor : ExpressionVisitor
|
||||
{
|
||||
protected override Expression Visit(Expression exp)
|
||||
{
|
||||
if (exp == null)
|
||||
return null;
|
||||
switch ((MongoExpressionType)exp.NodeType)
|
||||
{
|
||||
case MongoExpressionType.Collection:
|
||||
return VisitCollection((CollectionExpression)exp);
|
||||
case MongoExpressionType.Field:
|
||||
return VisitField((FieldExpression)exp);
|
||||
case MongoExpressionType.Projection:
|
||||
return VisitProjection((ProjectionExpression)exp);
|
||||
case MongoExpressionType.Select:
|
||||
return VisitSelect((SelectExpression)exp);
|
||||
case MongoExpressionType.Aggregate:
|
||||
return VisitAggregate((AggregateExpression)exp);
|
||||
case MongoExpressionType.AggregateSubquery:
|
||||
return VisitAggregateSubquery((AggregateSubqueryExpression)exp);
|
||||
case MongoExpressionType.Scalar:
|
||||
return VisitScalar((ScalarExpression)exp);
|
||||
default:
|
||||
return base.Visit(exp);
|
||||
}
|
||||
}
|
||||
|
||||
protected virtual Expression VisitAggregate(AggregateExpression aggregate)
|
||||
{
|
||||
var exp = Visit(aggregate.Argument);
|
||||
if (exp != aggregate.Argument)
|
||||
return new AggregateExpression(aggregate.Type, aggregate.AggregateType, exp, aggregate.Distinct);
|
||||
|
||||
return aggregate;
|
||||
}
|
||||
|
||||
protected virtual Expression VisitAggregateSubquery(AggregateSubqueryExpression aggregateSubquery)
|
||||
{
|
||||
Expression e = Visit(aggregateSubquery.AggregateAsSubquery);
|
||||
ScalarExpression subquery = (ScalarExpression)e;
|
||||
if (subquery != aggregateSubquery.AggregateAsSubquery)
|
||||
return new AggregateSubqueryExpression(aggregateSubquery.GroupByAlias, aggregateSubquery.AggregateInGroupSelect, subquery);
|
||||
return aggregateSubquery;
|
||||
}
|
||||
|
||||
protected virtual Expression VisitCollection(CollectionExpression collection)
|
||||
{
|
||||
return collection;
|
||||
}
|
||||
|
||||
protected virtual Expression VisitField(FieldExpression field)
|
||||
{
|
||||
var e = Visit(field.Expression);
|
||||
if (field.Expression != e)
|
||||
field = new FieldExpression(e, field.Alias, field.Name);
|
||||
|
||||
return field;
|
||||
}
|
||||
|
||||
protected virtual Expression VisitProjection(ProjectionExpression projection)
|
||||
{
|
||||
var source = (SelectExpression)Visit(projection.Source);
|
||||
var projector = Visit(projection.Projector);
|
||||
if (source != projection.Source || projector != projection.Projector)
|
||||
return new ProjectionExpression(source, projector, projection.Aggregator);
|
||||
return projection;
|
||||
}
|
||||
|
||||
protected ReadOnlyCollection<OrderExpression> VisitOrderBy(ReadOnlyCollection<OrderExpression> orderBys)
|
||||
{
|
||||
if (orderBys != null)
|
||||
{
|
||||
List<OrderExpression> alternate = null;
|
||||
for (int i = 0, n = orderBys.Count; i < n; i++)
|
||||
{
|
||||
OrderExpression expr = orderBys[i];
|
||||
Expression e = this.Visit(expr.Expression);
|
||||
if (alternate == null && e != expr.Expression)
|
||||
alternate = orderBys.Take(i).ToList();
|
||||
if (alternate != null)
|
||||
alternate.Add(new OrderExpression(expr.OrderType, e));
|
||||
}
|
||||
if (alternate != null)
|
||||
return alternate.AsReadOnly();
|
||||
}
|
||||
return orderBys;
|
||||
}
|
||||
|
||||
protected virtual Expression VisitScalar(ScalarExpression scalar)
|
||||
{
|
||||
SelectExpression select = (SelectExpression)Visit(scalar.Select);
|
||||
if (select != scalar.Select)
|
||||
return new ScalarExpression(scalar.Type, select);
|
||||
return scalar;
|
||||
}
|
||||
|
||||
protected virtual Expression VisitSelect(SelectExpression select)
|
||||
{
|
||||
var from = VisitSource(select.From);
|
||||
var where = Visit(select.Where);
|
||||
var groupBy = Visit(select.GroupBy);
|
||||
var orderBy = VisitOrderBy(select.OrderBy);
|
||||
var skip = Visit(select.Skip);
|
||||
var take = Visit(select.Take);
|
||||
var fields = VisitFieldDeclarationList(select.Fields);
|
||||
if (from != select.From || where != select.Where || orderBy != select.OrderBy || groupBy != select.GroupBy || skip != select.Skip || take != select.Take || fields != select.Fields)
|
||||
return new SelectExpression(select.Alias, fields, from, where, orderBy, groupBy, select.IsDistinct, skip, take);
|
||||
return select;
|
||||
}
|
||||
|
||||
protected virtual Expression VisitSource(Expression source)
|
||||
{
|
||||
return Visit(source);
|
||||
}
|
||||
|
||||
protected virtual Expression VisitSubquery(SubqueryExpression subquery)
|
||||
{
|
||||
switch ((MongoExpressionType)subquery.NodeType)
|
||||
{
|
||||
case MongoExpressionType.Scalar:
|
||||
return VisitScalar((ScalarExpression)subquery);
|
||||
}
|
||||
return subquery;
|
||||
}
|
||||
|
||||
protected virtual ReadOnlyCollection<FieldDeclaration> VisitFieldDeclarationList(ReadOnlyCollection<FieldDeclaration> fields)
|
||||
{
|
||||
if (fields == null)
|
||||
return fields;
|
||||
|
||||
List<FieldDeclaration> alternate = null;
|
||||
for (int i = 0, n = fields.Count; i < n; i++)
|
||||
{
|
||||
var f = fields[i];
|
||||
var e = Visit(f.Expression);
|
||||
if (f.Expression != e && alternate == null)
|
||||
alternate = fields.Take(i).ToList();
|
||||
if (alternate != null)
|
||||
alternate.Add(new FieldDeclaration(f.Name, e));
|
||||
}
|
||||
if (alternate != null)
|
||||
return alternate.AsReadOnly();
|
||||
return fields;
|
||||
}
|
||||
}
|
||||
}
|
||||
86
samples/C++/16F88.h
Normal file
86
samples/C++/16F88.h
Normal file
@@ -0,0 +1,86 @@
|
||||
/*
|
||||
* This file is part of PIC
|
||||
* Copyright © 2012 Rachel Mant (dx-mon@users.sourceforge.net)
|
||||
*
|
||||
* PIC is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* PIC is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
enum PIC16F88Instruction
|
||||
{
|
||||
ADDWF,
|
||||
ANDWF,
|
||||
CLRF,
|
||||
CLRW,
|
||||
COMF,
|
||||
DECF,
|
||||
DECFSZ,
|
||||
INCF,
|
||||
INCFSZ,
|
||||
IORWF,
|
||||
MOVF,
|
||||
MOVWF,
|
||||
NOP,
|
||||
RLF,
|
||||
RRF,
|
||||
SUBWF,
|
||||
SWAPF,
|
||||
XORWF,
|
||||
BCF,
|
||||
BSF,
|
||||
BTFSC,
|
||||
BTFSS,
|
||||
ADDLW,
|
||||
ANDLW,
|
||||
CALL,
|
||||
CLRWDT,
|
||||
GOTO,
|
||||
IORLW,
|
||||
MOVLW,
|
||||
RETFIE,
|
||||
RETLW,
|
||||
RETURN,
|
||||
SLEEP,
|
||||
SUBLW,
|
||||
XORLW
|
||||
};
|
||||
|
||||
class PIC16F88
|
||||
{
|
||||
public:
|
||||
PIC16F88(ROM *ProgramMemory);
|
||||
void Step();
|
||||
|
||||
private:
|
||||
uint8_t q;
|
||||
bool nextIsNop, trapped;
|
||||
Memory *memory;
|
||||
ROM *program;
|
||||
Stack<uint16_t, 8> *CallStack;
|
||||
Register<uint16_t> *PC;
|
||||
Register<> *WREG, *PCL, *STATUS, *PCLATCH;
|
||||
PIC16F88Instruction inst;
|
||||
uint16_t instrWord;
|
||||
|
||||
private:
|
||||
void DecodeInstruction();
|
||||
void ProcessInstruction();
|
||||
|
||||
uint8_t GetBank();
|
||||
uint8_t GetMemoryContents(uint8_t partialAddress);
|
||||
void SetMemoryContents(uint8_t partialAddress, uint8_t newVal);
|
||||
void CheckZero(uint8_t value);
|
||||
void StoreValue(uint8_t value, bool updateZero);
|
||||
uint8_t SetCarry(bool val);
|
||||
uint16_t GetPCHFinalBits();
|
||||
};
|
||||
98
samples/C++/Entity.h
Normal file
98
samples/C++/Entity.h
Normal file
@@ -0,0 +1,98 @@
|
||||
/**
|
||||
* @file Entity.h
|
||||
* @page EntityPage Entity
|
||||
* @brief represent an entity in the game
|
||||
* @author vinz243
|
||||
* @version 0.1.0
|
||||
* This file represents an Entity in the game system
|
||||
* This parent type is a static entity which is shown and loaded into the Physics engine but never updated
|
||||
*/
|
||||
|
||||
#ifndef ENTITY_H
|
||||
#define ENTITY_H
|
||||
|
||||
#include "base.h"
|
||||
/// @namespace Whitedrop
|
||||
namespace Whitedrop {
|
||||
/** @class Entity
|
||||
* This parent type is a static entity which is shown and loaded into the Physics engine but never updated
|
||||
*/
|
||||
class Entity {
|
||||
public:
|
||||
/**
|
||||
* @brief Create static entity
|
||||
* @details creates a static entity instance according to the mesh and the id, the position
|
||||
* This needs to be attached to a World after!
|
||||
* The material name is not the file name but the material name!
|
||||
* @ref WorldPage
|
||||
* @param mesh the name of the mesh for the object, file must be in media/meshes
|
||||
* @param id an unique identifier for the object, shortest as possible
|
||||
* @param dimensions an Ogre::Vector3 which contains the dimensions in meter
|
||||
* @param position the Vector3 which contains it position
|
||||
* @param material the material name
|
||||
*/
|
||||
Entity(std::string mesh, std::string id, Ogre::Vector3 dimensions, Ogre::Vector3 position, std::string material);
|
||||
/**
|
||||
* @brief The copy constructor
|
||||
* @details A copy constr
|
||||
*
|
||||
* @param ref the Entity to be copied from
|
||||
*/
|
||||
Entity(const Entity &ref);
|
||||
|
||||
/**
|
||||
* @brief The assignement operator
|
||||
* @details
|
||||
*
|
||||
* @param ent the entity to be copied
|
||||
*/
|
||||
Entity& operator=(const Entity ent);
|
||||
|
||||
/**
|
||||
* @brief destrctor
|
||||
* @details
|
||||
*/
|
||||
virtual ~Entity(void);
|
||||
|
||||
/**
|
||||
* @brief a constance type of the entity
|
||||
* @details depends of the class.
|
||||
* May contain STATIC, DYNAMIC or ETHERAL
|
||||
*/
|
||||
const std::string type = "STATIC";
|
||||
|
||||
/**
|
||||
* @brief Attach the entity to specified sceneManager
|
||||
* @details This creates the OgreEntity using sceneMgr,
|
||||
* set material, create a Node with name as `<id>_n`,
|
||||
* scale it to match dimensions and translate the node to pos
|
||||
* @param sceneMgr the scene manager to use
|
||||
*/
|
||||
virtual void setup(Ogre::SceneManager* sceneMgr);
|
||||
|
||||
/**
|
||||
* @brief the update method
|
||||
* @details this method should be called on each world update.
|
||||
* Even though the method is necessary declared, the main impl of
|
||||
* a static entity should be empty since it is not updated by physics
|
||||
* However, a Dynamic entity should implement this function in order to:
|
||||
* 1) Get from the physics engine the actor position in the physic world
|
||||
* 2) Update the OgreEntity position and rotation from the previous actor
|
||||
* @return whether it was successful or not, if falsey engine should stop
|
||||
*/
|
||||
virtual bool update(void);
|
||||
|
||||
protected:
|
||||
std::string mMesh = "cube.mesh";
|
||||
std::string mId;
|
||||
std::string mMaterial;
|
||||
Ogre::Vector3 mDimensions;
|
||||
Ogre::Vector3 mPosition;
|
||||
Ogre::Entity* mEntity;
|
||||
Ogre::SceneNode* mNode;
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
32
samples/C++/Memory16F88.h
Normal file
32
samples/C++/Memory16F88.h
Normal file
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* This file is part of PIC
|
||||
* Copyright © 2012 Rachel Mant (dx-mon@users.sourceforge.net)
|
||||
*
|
||||
* PIC is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* PIC is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "Memory.h"
|
||||
|
||||
class Memory16F88 : public Memory
|
||||
{
|
||||
private:
|
||||
uint8_t memory[512];
|
||||
std::map<uint32_t, MemoryLocation *> memoryMap;
|
||||
|
||||
public:
|
||||
Memory16F88();
|
||||
uint8_t Dereference(uint8_t bank, uint8_t partialAddress);
|
||||
uint8_t *Reference(uint8_t bank, uint8_t partialAddress);
|
||||
uint8_t *operator [](uint32_t ref);
|
||||
};
|
||||
76
samples/C++/ThreadedQueue.h
Normal file
76
samples/C++/ThreadedQueue.h
Normal file
@@ -0,0 +1,76 @@
|
||||
/*
|
||||
* This file is part of IRCBot
|
||||
* Copyright © 2014 Rachel Mant (dx-mon@users.sourceforge.net)
|
||||
*
|
||||
* IRCBot is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* IRCBot is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef __THREADED_QUEUE_H__
|
||||
#define __THREADED_QUEUE_H__
|
||||
|
||||
#include <pthread.h>
|
||||
#include <queue>
|
||||
|
||||
template<class T>
|
||||
class ThreadedQueue : public std::queue<T>
|
||||
{
|
||||
private:
|
||||
pthread_mutex_t queueMutex;
|
||||
pthread_cond_t queueCond;
|
||||
|
||||
public:
|
||||
ThreadedQueue()
|
||||
{
|
||||
pthread_mutexattr_t mutexAttrs;
|
||||
pthread_condattr_t condAttrs;
|
||||
|
||||
pthread_mutexattr_init(&mutexAttrs);
|
||||
pthread_mutexattr_settype(&mutexAttrs, PTHREAD_MUTEX_ERRORCHECK);
|
||||
pthread_mutex_init(&queueMutex, &mutexAttrs);
|
||||
pthread_mutexattr_destroy(&mutexAttrs);
|
||||
|
||||
pthread_condattr_init(&condAttrs);
|
||||
pthread_condattr_setpshared(&condAttrs, PTHREAD_PROCESS_PRIVATE);
|
||||
pthread_cond_init(&queueCond, &condAttrs);
|
||||
pthread_condattr_destroy(&condAttrs);
|
||||
}
|
||||
|
||||
~ThreadedQueue()
|
||||
{
|
||||
pthread_cond_destroy(&queueCond);
|
||||
pthread_mutex_destroy(&queueMutex);
|
||||
}
|
||||
|
||||
void waitItems()
|
||||
{
|
||||
pthread_mutex_lock(&queueMutex);
|
||||
pthread_cond_wait(&queueCond, &queueMutex);
|
||||
pthread_mutex_unlock(&queueMutex);
|
||||
}
|
||||
|
||||
void signalItems()
|
||||
{
|
||||
pthread_mutex_lock(&queueMutex);
|
||||
pthread_cond_broadcast(&queueCond);
|
||||
pthread_mutex_unlock(&queueMutex);
|
||||
}
|
||||
|
||||
void push(T item)
|
||||
{
|
||||
std::queue<T>::push(item);
|
||||
signalItems();
|
||||
}
|
||||
};
|
||||
|
||||
#endif /*__THREADED_QUEUE_H__*/
|
||||
145
samples/C/2D.C
Normal file
145
samples/C/2D.C
Normal file
@@ -0,0 +1,145 @@
|
||||
#include "2D.h"
|
||||
#include <math.h>
|
||||
|
||||
void set_vgabasemem(void)
|
||||
{
|
||||
ULONG vgabase;
|
||||
SELECTOR tmp;
|
||||
asm mov [tmp], ds
|
||||
dpmi_get_sel_base(&vgabase, tmp);
|
||||
vgabasemem = (char *)(-vgabase + 0xa0000);
|
||||
}
|
||||
|
||||
void drw_chdis(int mode) // change the display!
|
||||
{
|
||||
regs.b.ah = 0x00; // seet theh display moode
|
||||
regs.b.al = mode; // change it to the mode like innit
|
||||
regs.h.flags = 0x72;// Set the dingoes kidneys out of FLAGS eh?
|
||||
regs.h.ss = 0; // Like, totally set the stack segment
|
||||
regs.h.sp = 0; // Set tha stack pointaaaaahhhhh!!!
|
||||
dpmi_simulate_real_interrupt(0x10, ®s);
|
||||
}
|
||||
|
||||
void drw_pix(int x, int y, enum COLORS col)
|
||||
{
|
||||
*VGAPIX(x, y) = col;
|
||||
}
|
||||
|
||||
void drw_line(int x0, int y0, int x1, int y1, enum COLORS col)
|
||||
{
|
||||
// Going for the optimized version of bresenham's line algo.
|
||||
int stp = (abs(y0 - y1) > abs(x0 - x1));
|
||||
int tmp, dx, dy, err, yi, i, j; // yi = y excrement
|
||||
if (stp) {
|
||||
// swappity swap
|
||||
tmp = y0;
|
||||
y0 = x0;
|
||||
x0 = tmp;
|
||||
|
||||
tmp = y1;
|
||||
y1 = x1;
|
||||
x1 = tmp;
|
||||
}
|
||||
// AAAAND NOW WE MUST DO ZEES AGAIN :(
|
||||
// I'm sure there was a func somewhere that does this? :P
|
||||
if (x0 > x1) {
|
||||
tmp = x0;
|
||||
x0 = x1;
|
||||
x1 = tmp;
|
||||
|
||||
tmp = y0;
|
||||
y0 = y1;
|
||||
y1 = tmp;
|
||||
}
|
||||
dx = (x1 - x0);
|
||||
dy = (abs(y1 - y0));
|
||||
err = (dx / 2);
|
||||
|
||||
if (y0 < y1)
|
||||
yi = 1;
|
||||
else
|
||||
yi = -1;
|
||||
j = y0;
|
||||
for (i = x0; i < x1; i++)
|
||||
{
|
||||
if (stp)
|
||||
*VGAPIX(j, i) = col;
|
||||
else
|
||||
*VGAPIX(i, j) = col;
|
||||
|
||||
err -= dy;
|
||||
if (err < 0) {
|
||||
j += yi;
|
||||
err += dx;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void drw_rectl(int x, int y, int w, int h, enum COLORS col)
|
||||
{
|
||||
drw_line(x, y, x+w, y, col);
|
||||
drw_line(x+w, y, x+w, y+h, col);
|
||||
|
||||
drw_line(x, y, x, y+h, col);
|
||||
drw_line(x, y+h, x+w+1, y+h, col);
|
||||
}
|
||||
|
||||
void drw_rectf(int x, int y, int w, int h, enum COLORS col)
|
||||
{
|
||||
int i, j;
|
||||
for (j = y; j < x+h; j++) {
|
||||
for (i = x; i < y+w; i++) {
|
||||
*VGAPIX(i, j) = col;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void drw_circl(int x, int y, int rad, enum COLORS col)
|
||||
{
|
||||
int mang, i; // max angle, haha
|
||||
int px, py;
|
||||
mang = 360; // Yeah yeah I'll switch to rad later
|
||||
for (i = 0; i <= mang; i++)
|
||||
{
|
||||
px = cos(i)*rad + x; // + px; // causes some really cools effects! :D
|
||||
py = sin(i)*rad + y; // + py;
|
||||
*VGAPIX(px, py) = col;
|
||||
}
|
||||
}
|
||||
|
||||
void drw_tex(int x, int y, int w, int h, enum COLORS tex[])
|
||||
{ // i*w+j
|
||||
int i, j;
|
||||
for (i = 0; i < w; i++)
|
||||
{
|
||||
for (j = 0; j < h; j++)
|
||||
{
|
||||
*VGAPIX(x+i, y+j) = tex[j*w+i];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void 2D_init(void)
|
||||
{
|
||||
set_vgabasemem();
|
||||
drw_chdis(0x13);
|
||||
}
|
||||
|
||||
void 2D_exit(void)
|
||||
{
|
||||
drw_chdis(3);
|
||||
}
|
||||
/*
|
||||
int main()
|
||||
{
|
||||
set_vgabasemem();
|
||||
drw_chdis(0x13);
|
||||
|
||||
while(!kbhit()) {
|
||||
if ((getch()) == 0x1b) // escape
|
||||
break;
|
||||
}
|
||||
drw_chdis(3);
|
||||
return 0;
|
||||
}
|
||||
*/
|
||||
29
samples/C/2D.H
Normal file
29
samples/C/2D.H
Normal file
@@ -0,0 +1,29 @@
|
||||
#ifndef __2DGFX
|
||||
#define __2DGFX
|
||||
// Includes
|
||||
#include <stdio.h>
|
||||
#include <math.h>
|
||||
#include <conio.h>
|
||||
#include <dpmi.h>
|
||||
|
||||
// Defines
|
||||
#define VGAPIX(x,y) (vgabasemem + (x) + (y) * 320)
|
||||
|
||||
// Variables
|
||||
char * vgabasemem;
|
||||
DPMI_REGS regs;
|
||||
|
||||
// Drawing functions:
|
||||
//void setvgabasemem(void);
|
||||
void drw_chdis(int mode); // draw_func_change_display
|
||||
void drw_pix(int x, int y, enum COLORS col);
|
||||
void drw_line(int x0, int y0, int x1, int y1, enum COLORS col);
|
||||
void drw_rectl(int x, int y, int w, int h, enum COLORS col);
|
||||
void drw_rectf(int x, int y, int w, int h, enum COLORS col);
|
||||
void drw_cirl(int x, int y, int rad, enum COLORS col);
|
||||
void drw_tex(int x, int y, int w, int h, enum COLORS tex[]);
|
||||
void 2D_init(void);
|
||||
void 2D_exit(void);
|
||||
|
||||
|
||||
#endif
|
||||
93
samples/C/ArrowLeft.h
Normal file
93
samples/C/ArrowLeft.h
Normal file
@@ -0,0 +1,93 @@
|
||||
/*
|
||||
* This file is part of GTK++ (libGTK++)
|
||||
* Copyright © 2012 Rachel Mant (dx-mon@users.sourceforge.net)
|
||||
*
|
||||
* GTK++ is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* GTK++ is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/* GdkPixbuf RGBA C-Source image dump */
|
||||
|
||||
#ifdef __SUNPRO_C
|
||||
#pragma align 4 (ArrowLeft)
|
||||
#endif
|
||||
#ifdef __GNUC__
|
||||
static const uint8_t ArrowLeft[] __attribute__ ((__aligned__ (4))) =
|
||||
#else
|
||||
static const uint8_t ArrowLeft[] =
|
||||
#endif
|
||||
{ ""
|
||||
/* Pixbuf magic (0x47646b50) */
|
||||
"GdkP"
|
||||
/* length: header (24) + pixel_data (1600) */
|
||||
"\0\0\6X"
|
||||
/* pixdata_type (0x1010002) */
|
||||
"\1\1\0\2"
|
||||
/* rowstride (80) */
|
||||
"\0\0\0P"
|
||||
/* width (20) */
|
||||
"\0\0\0\24"
|
||||
/* height (20) */
|
||||
"\0\0\0\24"
|
||||
/* pixel_data: */
|
||||
"\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
|
||||
"\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
|
||||
"\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
|
||||
"\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
|
||||
"\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
|
||||
"\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
|
||||
"\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
|
||||
"\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
|
||||
"\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
|
||||
"\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
|
||||
"\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\377\0\0\0\0\0"
|
||||
"\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
|
||||
"\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
|
||||
"\0\0\377\0\0\0\377\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
|
||||
"\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
|
||||
"\0\0\0\0\0\0\0\0\0\0\0\0\377\0\0\0\377\0\0\0\377\0\0\0\0\0\0\0\0\0\0"
|
||||
"\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
|
||||
"\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\377\0\0\0\377\0\0\0\377"
|
||||
"\0\0\0\377\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
|
||||
"\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
|
||||
"\377\0\0\0\377\0\0\0\377\0\0\0\377\0\0\0\377\0\0\0\0\0\0\0\0\0\0\0\0"
|
||||
"\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
|
||||
"\0\0\0\0\0\0\0\0\0\0\0\0\0\377\0\0\0\377\0\0\0\377\0\0\0\377\0\0\0\377"
|
||||
"\0\0\0\377\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
|
||||
"\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
|
||||
"\377\0\0\0\377\0\0\0\377\0\0\0\377\0\0\0\377\0\0\0\0\0\0\0\0\0\0\0\0"
|
||||
"\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
|
||||
"\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\377\0\0\0\377\0\0\0\377\0"
|
||||
"\0\0\377\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
|
||||
"\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
|
||||
"\0\0\0\0\0\0\0\377\0\0\0\377\0\0\0\377\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
|
||||
"\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
|
||||
"\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\377\0\0\0\377\0"
|
||||
"\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
|
||||
"\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
|
||||
"\0\0\0\0\0\0\0\0\0\0\377\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
|
||||
"\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
|
||||
"\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
|
||||
"\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
|
||||
"\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
|
||||
"\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
|
||||
"\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
|
||||
"\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
|
||||
"\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
|
||||
"\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
|
||||
"\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
|
||||
"\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
|
||||
"\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
|
||||
"\0\0"};
|
||||
|
||||
|
||||
903
samples/C/GLKMatrix4.h
Normal file
903
samples/C/GLKMatrix4.h
Normal file
@@ -0,0 +1,903 @@
|
||||
//
|
||||
// GLKMatrix4.h
|
||||
// GLKit
|
||||
//
|
||||
// Copyright (c) 2011, Apple Inc. All rights reserved.
|
||||
//
|
||||
|
||||
#ifndef __GLK_MATRIX_4_H
|
||||
#define __GLK_MATRIX_4_H
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdbool.h>
|
||||
#include <math.h>
|
||||
|
||||
#if defined(__ARM_NEON__)
|
||||
#include <arm_neon.h>
|
||||
#endif
|
||||
|
||||
#include <GLKit/GLKMathTypes.h>
|
||||
#include <GLKit/GLKVector3.h>
|
||||
#include <GLKit/GLKVector4.h>
|
||||
#include <GLKit/GLKQuaternion.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#pragma mark -
|
||||
#pragma mark Prototypes
|
||||
#pragma mark -
|
||||
|
||||
extern const GLKMatrix4 GLKMatrix4Identity;
|
||||
|
||||
/*
|
||||
m30, m31, and m32 correspond to the translation values tx, ty, tz, respectively.
|
||||
*/
|
||||
static __inline__ GLKMatrix4 GLKMatrix4Make(float m00, float m01, float m02, float m03,
|
||||
float m10, float m11, float m12, float m13,
|
||||
float m20, float m21, float m22, float m23,
|
||||
float m30, float m31, float m32, float m33);
|
||||
|
||||
/*
|
||||
m03, m13, and m23 correspond to the translation values tx, ty, tz, respectively.
|
||||
*/
|
||||
static __inline__ GLKMatrix4 GLKMatrix4MakeAndTranspose(float m00, float m01, float m02, float m03,
|
||||
float m10, float m11, float m12, float m13,
|
||||
float m20, float m21, float m22, float m23,
|
||||
float m30, float m31, float m32, float m33);
|
||||
|
||||
/*
|
||||
m[12], m[13], and m[14] correspond to the translation values tx, ty, and tz, respectively.
|
||||
*/
|
||||
static __inline__ GLKMatrix4 GLKMatrix4MakeWithArray(float values[16]);
|
||||
|
||||
/*
|
||||
m[3], m[7], and m[11] correspond to the translation values tx, ty, and tz, respectively.
|
||||
*/
|
||||
static __inline__ GLKMatrix4 GLKMatrix4MakeWithArrayAndTranspose(float values[16]);
|
||||
|
||||
/*
|
||||
row0, row1, and row2's last component should correspond to the translation values tx, ty, and tz, respectively.
|
||||
*/
|
||||
static __inline__ GLKMatrix4 GLKMatrix4MakeWithRows(GLKVector4 row0,
|
||||
GLKVector4 row1,
|
||||
GLKVector4 row2,
|
||||
GLKVector4 row3);
|
||||
|
||||
/*
|
||||
column3's first three components should correspond to the translation values tx, ty, and tz.
|
||||
*/
|
||||
static __inline__ GLKMatrix4 GLKMatrix4MakeWithColumns(GLKVector4 column0,
|
||||
GLKVector4 column1,
|
||||
GLKVector4 column2,
|
||||
GLKVector4 column3);
|
||||
|
||||
/*
|
||||
The quaternion will be normalized before conversion.
|
||||
*/
|
||||
static __inline__ GLKMatrix4 GLKMatrix4MakeWithQuaternion(GLKQuaternion quaternion);
|
||||
|
||||
static __inline__ GLKMatrix4 GLKMatrix4MakeTranslation(float tx, float ty, float tz);
|
||||
static __inline__ GLKMatrix4 GLKMatrix4MakeScale(float sx, float sy, float sz);
|
||||
static __inline__ GLKMatrix4 GLKMatrix4MakeRotation(float radians, float x, float y, float z);
|
||||
|
||||
static __inline__ GLKMatrix4 GLKMatrix4MakeXRotation(float radians);
|
||||
static __inline__ GLKMatrix4 GLKMatrix4MakeYRotation(float radians);
|
||||
static __inline__ GLKMatrix4 GLKMatrix4MakeZRotation(float radians);
|
||||
|
||||
/*
|
||||
Equivalent to gluPerspective.
|
||||
*/
|
||||
static __inline__ GLKMatrix4 GLKMatrix4MakePerspective(float fovyRadians, float aspect, float nearZ, float farZ);
|
||||
|
||||
/*
|
||||
Equivalent to glFrustum.
|
||||
*/
|
||||
static __inline__ GLKMatrix4 GLKMatrix4MakeFrustum(float left, float right,
|
||||
float bottom, float top,
|
||||
float nearZ, float farZ);
|
||||
|
||||
/*
|
||||
Equivalent to glOrtho.
|
||||
*/
|
||||
static __inline__ GLKMatrix4 GLKMatrix4MakeOrtho(float left, float right,
|
||||
float bottom, float top,
|
||||
float nearZ, float farZ);
|
||||
|
||||
/*
|
||||
Equivalent to gluLookAt.
|
||||
*/
|
||||
static __inline__ GLKMatrix4 GLKMatrix4MakeLookAt(float eyeX, float eyeY, float eyeZ,
|
||||
float centerX, float centerY, float centerZ,
|
||||
float upX, float upY, float upZ);
|
||||
|
||||
/*
|
||||
Returns the upper left 3x3 portion of the 4x4 matrix.
|
||||
*/
|
||||
static __inline__ GLKMatrix3 GLKMatrix4GetMatrix3(GLKMatrix4 matrix);
|
||||
/*
|
||||
Returns the upper left 2x2 portion of the 4x4 matrix.
|
||||
*/
|
||||
static __inline__ GLKMatrix2 GLKMatrix4GetMatrix2(GLKMatrix4 matrix);
|
||||
|
||||
/*
|
||||
GLKMatrix4GetRow returns vectors for rows 0, 1, and 2 whose last component will be the translation value tx, ty, and tz, respectively.
|
||||
Valid row values range from 0 to 3, inclusive.
|
||||
*/
|
||||
static __inline__ GLKVector4 GLKMatrix4GetRow(GLKMatrix4 matrix, int row);
|
||||
/*
|
||||
GLKMatrix4GetColumn returns a vector for column 3 whose first three components will be the translation values tx, ty, and tz.
|
||||
Valid column values range from 0 to 3, inclusive.
|
||||
*/
|
||||
static __inline__ GLKVector4 GLKMatrix4GetColumn(GLKMatrix4 matrix, int column);
|
||||
|
||||
/*
|
||||
GLKMatrix4SetRow expects that the vector for row 0, 1, and 2 will have a translation value as its last component.
|
||||
Valid row values range from 0 to 3, inclusive.
|
||||
*/
|
||||
static __inline__ GLKMatrix4 GLKMatrix4SetRow(GLKMatrix4 matrix, int row, GLKVector4 vector);
|
||||
/*
|
||||
GLKMatrix4SetColumn expects that the vector for column 3 will contain the translation values tx, ty, and tz as its first three components, respectively.
|
||||
Valid column values range from 0 to 3, inclusive.
|
||||
*/
|
||||
static __inline__ GLKMatrix4 GLKMatrix4SetColumn(GLKMatrix4 matrix, int column, GLKVector4 vector);
|
||||
|
||||
static __inline__ GLKMatrix4 GLKMatrix4Transpose(GLKMatrix4 matrix);
|
||||
|
||||
GLKMatrix4 GLKMatrix4Invert(GLKMatrix4 matrix, bool *isInvertible);
|
||||
GLKMatrix4 GLKMatrix4InvertAndTranspose(GLKMatrix4 matrix, bool *isInvertible);
|
||||
|
||||
static __inline__ GLKMatrix4 GLKMatrix4Multiply(GLKMatrix4 matrixLeft, GLKMatrix4 matrixRight);
|
||||
|
||||
static __inline__ GLKMatrix4 GLKMatrix4Add(GLKMatrix4 matrixLeft, GLKMatrix4 matrixRight);
|
||||
static __inline__ GLKMatrix4 GLKMatrix4Subtract(GLKMatrix4 matrixLeft, GLKMatrix4 matrixRight);
|
||||
|
||||
static __inline__ GLKMatrix4 GLKMatrix4Translate(GLKMatrix4 matrix, float tx, float ty, float tz);
|
||||
static __inline__ GLKMatrix4 GLKMatrix4TranslateWithVector3(GLKMatrix4 matrix, GLKVector3 translationVector);
|
||||
/*
|
||||
The last component of the GLKVector4, translationVector, is ignored.
|
||||
*/
|
||||
static __inline__ GLKMatrix4 GLKMatrix4TranslateWithVector4(GLKMatrix4 matrix, GLKVector4 translationVector);
|
||||
|
||||
static __inline__ GLKMatrix4 GLKMatrix4Scale(GLKMatrix4 matrix, float sx, float sy, float sz);
|
||||
static __inline__ GLKMatrix4 GLKMatrix4ScaleWithVector3(GLKMatrix4 matrix, GLKVector3 scaleVector);
|
||||
/*
|
||||
The last component of the GLKVector4, scaleVector, is ignored.
|
||||
*/
|
||||
static __inline__ GLKMatrix4 GLKMatrix4ScaleWithVector4(GLKMatrix4 matrix, GLKVector4 scaleVector);
|
||||
|
||||
static __inline__ GLKMatrix4 GLKMatrix4Rotate(GLKMatrix4 matrix, float radians, float x, float y, float z);
|
||||
static __inline__ GLKMatrix4 GLKMatrix4RotateWithVector3(GLKMatrix4 matrix, float radians, GLKVector3 axisVector);
|
||||
/*
|
||||
The last component of the GLKVector4, axisVector, is ignored.
|
||||
*/
|
||||
static __inline__ GLKMatrix4 GLKMatrix4RotateWithVector4(GLKMatrix4 matrix, float radians, GLKVector4 axisVector);
|
||||
|
||||
static __inline__ GLKMatrix4 GLKMatrix4RotateX(GLKMatrix4 matrix, float radians);
|
||||
static __inline__ GLKMatrix4 GLKMatrix4RotateY(GLKMatrix4 matrix, float radians);
|
||||
static __inline__ GLKMatrix4 GLKMatrix4RotateZ(GLKMatrix4 matrix, float radians);
|
||||
|
||||
/*
|
||||
Assumes 0 in the w component.
|
||||
*/
|
||||
static __inline__ GLKVector3 GLKMatrix4MultiplyVector3(GLKMatrix4 matrixLeft, GLKVector3 vectorRight);
|
||||
/*
|
||||
Assumes 1 in the w component.
|
||||
*/
|
||||
static __inline__ GLKVector3 GLKMatrix4MultiplyVector3WithTranslation(GLKMatrix4 matrixLeft, GLKVector3 vectorRight);
|
||||
/*
|
||||
Assumes 1 in the w component and divides the resulting vector by w before returning.
|
||||
*/
|
||||
static __inline__ GLKVector3 GLKMatrix4MultiplyAndProjectVector3(GLKMatrix4 matrixLeft, GLKVector3 vectorRight);
|
||||
|
||||
/*
|
||||
Assumes 0 in the w component.
|
||||
*/
|
||||
static __inline__ void GLKMatrix4MultiplyVector3Array(GLKMatrix4 matrix, GLKVector3 *vectors, size_t vectorCount);
|
||||
/*
|
||||
Assumes 1 in the w component.
|
||||
*/
|
||||
static __inline__ void GLKMatrix4MultiplyVector3ArrayWithTranslation(GLKMatrix4 matrix, GLKVector3 *vectors, size_t vectorCount);
|
||||
/*
|
||||
Assumes 1 in the w component and divides the resulting vector by w before returning.
|
||||
*/
|
||||
static __inline__ void GLKMatrix4MultiplyAndProjectVector3Array(GLKMatrix4 matrix, GLKVector3 *vectors, size_t vectorCount);
|
||||
|
||||
static __inline__ GLKVector4 GLKMatrix4MultiplyVector4(GLKMatrix4 matrixLeft, GLKVector4 vectorRight);
|
||||
|
||||
static __inline__ void GLKMatrix4MultiplyVector4Array(GLKMatrix4 matrix, GLKVector4 *vectors, size_t vectorCount);
|
||||
|
||||
#pragma mark -
|
||||
#pragma mark Implementations
|
||||
#pragma mark -
|
||||
|
||||
static __inline__ GLKMatrix4 GLKMatrix4Make(float m00, float m01, float m02, float m03,
|
||||
float m10, float m11, float m12, float m13,
|
||||
float m20, float m21, float m22, float m23,
|
||||
float m30, float m31, float m32, float m33)
|
||||
{
|
||||
GLKMatrix4 m = { m00, m01, m02, m03,
|
||||
m10, m11, m12, m13,
|
||||
m20, m21, m22, m23,
|
||||
m30, m31, m32, m33 };
|
||||
return m;
|
||||
}
|
||||
|
||||
static __inline__ GLKMatrix4 GLKMatrix4MakeAndTranspose(float m00, float m01, float m02, float m03,
|
||||
float m10, float m11, float m12, float m13,
|
||||
float m20, float m21, float m22, float m23,
|
||||
float m30, float m31, float m32, float m33)
|
||||
{
|
||||
GLKMatrix4 m = { m00, m10, m20, m30,
|
||||
m01, m11, m21, m31,
|
||||
m02, m12, m22, m32,
|
||||
m03, m13, m23, m33 };
|
||||
return m;
|
||||
}
|
||||
|
||||
static __inline__ GLKMatrix4 GLKMatrix4MakeWithArray(float values[16])
|
||||
{
|
||||
GLKMatrix4 m = { values[0], values[1], values[2], values[3],
|
||||
values[4], values[5], values[6], values[7],
|
||||
values[8], values[9], values[10], values[11],
|
||||
values[12], values[13], values[14], values[15] };
|
||||
return m;
|
||||
}
|
||||
|
||||
static __inline__ GLKMatrix4 GLKMatrix4MakeWithArrayAndTranspose(float values[16])
|
||||
{
|
||||
#if defined(__ARM_NEON__)
|
||||
float32x4x4_t m = vld4q_f32(values);
|
||||
return *(GLKMatrix4 *)&m;
|
||||
#else
|
||||
GLKMatrix4 m = { values[0], values[4], values[8], values[12],
|
||||
values[1], values[5], values[9], values[13],
|
||||
values[2], values[6], values[10], values[14],
|
||||
values[3], values[7], values[11], values[15] };
|
||||
return m;
|
||||
#endif
|
||||
}
|
||||
|
||||
static __inline__ GLKMatrix4 GLKMatrix4MakeWithRows(GLKVector4 row0,
|
||||
GLKVector4 row1,
|
||||
GLKVector4 row2,
|
||||
GLKVector4 row3)
|
||||
{
|
||||
GLKMatrix4 m = { row0.v[0], row1.v[0], row2.v[0], row3.v[0],
|
||||
row0.v[1], row1.v[1], row2.v[1], row3.v[1],
|
||||
row0.v[2], row1.v[2], row2.v[2], row3.v[2],
|
||||
row0.v[3], row1.v[3], row2.v[3], row3.v[3] };
|
||||
return m;
|
||||
}
|
||||
|
||||
static __inline__ GLKMatrix4 GLKMatrix4MakeWithColumns(GLKVector4 column0,
|
||||
GLKVector4 column1,
|
||||
GLKVector4 column2,
|
||||
GLKVector4 column3)
|
||||
{
|
||||
#if defined(__ARM_NEON__)
|
||||
float32x4x4_t m;
|
||||
m.val[0] = vld1q_f32(column0.v);
|
||||
m.val[1] = vld1q_f32(column1.v);
|
||||
m.val[2] = vld1q_f32(column2.v);
|
||||
m.val[3] = vld1q_f32(column3.v);
|
||||
return *(GLKMatrix4 *)&m;
|
||||
#else
|
||||
GLKMatrix4 m = { column0.v[0], column0.v[1], column0.v[2], column0.v[3],
|
||||
column1.v[0], column1.v[1], column1.v[2], column1.v[3],
|
||||
column2.v[0], column2.v[1], column2.v[2], column2.v[3],
|
||||
column3.v[0], column3.v[1], column3.v[2], column3.v[3] };
|
||||
return m;
|
||||
#endif
|
||||
}
|
||||
|
||||
static __inline__ GLKMatrix4 GLKMatrix4MakeWithQuaternion(GLKQuaternion quaternion)
|
||||
{
|
||||
quaternion = GLKQuaternionNormalize(quaternion);
|
||||
|
||||
float x = quaternion.q[0];
|
||||
float y = quaternion.q[1];
|
||||
float z = quaternion.q[2];
|
||||
float w = quaternion.q[3];
|
||||
|
||||
float _2x = x + x;
|
||||
float _2y = y + y;
|
||||
float _2z = z + z;
|
||||
float _2w = w + w;
|
||||
|
||||
GLKMatrix4 m = { 1.0f - _2y * y - _2z * z,
|
||||
_2x * y + _2w * z,
|
||||
_2x * z - _2w * y,
|
||||
0.0f,
|
||||
_2x * y - _2w * z,
|
||||
1.0f - _2x * x - _2z * z,
|
||||
_2y * z + _2w * x,
|
||||
0.0f,
|
||||
_2x * z + _2w * y,
|
||||
_2y * z - _2w * x,
|
||||
1.0f - _2x * x - _2y * y,
|
||||
0.0f,
|
||||
0.0f,
|
||||
0.0f,
|
||||
0.0f,
|
||||
1.0f };
|
||||
|
||||
return m;
|
||||
}
|
||||
|
||||
static __inline__ GLKMatrix4 GLKMatrix4MakeTranslation(float tx, float ty, float tz)
|
||||
{
|
||||
GLKMatrix4 m = GLKMatrix4Identity;
|
||||
m.m[12] = tx;
|
||||
m.m[13] = ty;
|
||||
m.m[14] = tz;
|
||||
return m;
|
||||
}
|
||||
|
||||
static __inline__ GLKMatrix4 GLKMatrix4MakeScale(float sx, float sy, float sz)
|
||||
{
|
||||
GLKMatrix4 m = GLKMatrix4Identity;
|
||||
m.m[0] = sx;
|
||||
m.m[5] = sy;
|
||||
m.m[10] = sz;
|
||||
return m;
|
||||
}
|
||||
|
||||
static __inline__ GLKMatrix4 GLKMatrix4MakeRotation(float radians, float x, float y, float z)
|
||||
{
|
||||
GLKVector3 v = GLKVector3Normalize(GLKVector3Make(x, y, z));
|
||||
float cos = cosf(radians);
|
||||
float cosp = 1.0f - cos;
|
||||
float sin = sinf(radians);
|
||||
|
||||
GLKMatrix4 m = { cos + cosp * v.v[0] * v.v[0],
|
||||
cosp * v.v[0] * v.v[1] + v.v[2] * sin,
|
||||
cosp * v.v[0] * v.v[2] - v.v[1] * sin,
|
||||
0.0f,
|
||||
cosp * v.v[0] * v.v[1] - v.v[2] * sin,
|
||||
cos + cosp * v.v[1] * v.v[1],
|
||||
cosp * v.v[1] * v.v[2] + v.v[0] * sin,
|
||||
0.0f,
|
||||
cosp * v.v[0] * v.v[2] + v.v[1] * sin,
|
||||
cosp * v.v[1] * v.v[2] - v.v[0] * sin,
|
||||
cos + cosp * v.v[2] * v.v[2],
|
||||
0.0f,
|
||||
0.0f,
|
||||
0.0f,
|
||||
0.0f,
|
||||
1.0f };
|
||||
|
||||
return m;
|
||||
}
|
||||
|
||||
static __inline__ GLKMatrix4 GLKMatrix4MakeXRotation(float radians)
|
||||
{
|
||||
float cos = cosf(radians);
|
||||
float sin = sinf(radians);
|
||||
|
||||
GLKMatrix4 m = { 1.0f, 0.0f, 0.0f, 0.0f,
|
||||
0.0f, cos, sin, 0.0f,
|
||||
0.0f, -sin, cos, 0.0f,
|
||||
0.0f, 0.0f, 0.0f, 1.0f };
|
||||
|
||||
return m;
|
||||
}
|
||||
|
||||
static __inline__ GLKMatrix4 GLKMatrix4MakeYRotation(float radians)
|
||||
{
|
||||
float cos = cosf(radians);
|
||||
float sin = sinf(radians);
|
||||
|
||||
GLKMatrix4 m = { cos, 0.0f, -sin, 0.0f,
|
||||
0.0f, 1.0f, 0.0f, 0.0f,
|
||||
sin, 0.0f, cos, 0.0f,
|
||||
0.0f, 0.0f, 0.0f, 1.0f };
|
||||
|
||||
return m;
|
||||
}
|
||||
|
||||
static __inline__ GLKMatrix4 GLKMatrix4MakeZRotation(float radians)
|
||||
{
|
||||
float cos = cosf(radians);
|
||||
float sin = sinf(radians);
|
||||
|
||||
GLKMatrix4 m = { cos, sin, 0.0f, 0.0f,
|
||||
-sin, cos, 0.0f, 0.0f,
|
||||
0.0f, 0.0f, 1.0f, 0.0f,
|
||||
0.0f, 0.0f, 0.0f, 1.0f };
|
||||
|
||||
return m;
|
||||
}
|
||||
|
||||
static __inline__ GLKMatrix4 GLKMatrix4MakePerspective(float fovyRadians, float aspect, float nearZ, float farZ)
|
||||
{
|
||||
float cotan = 1.0f / tanf(fovyRadians / 2.0f);
|
||||
|
||||
GLKMatrix4 m = { cotan / aspect, 0.0f, 0.0f, 0.0f,
|
||||
0.0f, cotan, 0.0f, 0.0f,
|
||||
0.0f, 0.0f, (farZ + nearZ) / (nearZ - farZ), -1.0f,
|
||||
0.0f, 0.0f, (2.0f * farZ * nearZ) / (nearZ - farZ), 0.0f };
|
||||
|
||||
return m;
|
||||
}
|
||||
|
||||
static __inline__ GLKMatrix4 GLKMatrix4MakeFrustum(float left, float right,
|
||||
float bottom, float top,
|
||||
float nearZ, float farZ)
|
||||
{
|
||||
float ral = right + left;
|
||||
float rsl = right - left;
|
||||
float tsb = top - bottom;
|
||||
float tab = top + bottom;
|
||||
float fan = farZ + nearZ;
|
||||
float fsn = farZ - nearZ;
|
||||
|
||||
GLKMatrix4 m = { 2.0f * nearZ / rsl, 0.0f, 0.0f, 0.0f,
|
||||
0.0f, 2.0f * nearZ / tsb, 0.0f, 0.0f,
|
||||
ral / rsl, tab / tsb, -fan / fsn, -1.0f,
|
||||
0.0f, 0.0f, (-2.0f * farZ * nearZ) / fsn, 0.0f };
|
||||
|
||||
return m;
|
||||
}
|
||||
|
||||
static __inline__ GLKMatrix4 GLKMatrix4MakeOrtho(float left, float right,
|
||||
float bottom, float top,
|
||||
float nearZ, float farZ)
|
||||
{
|
||||
float ral = right + left;
|
||||
float rsl = right - left;
|
||||
float tab = top + bottom;
|
||||
float tsb = top - bottom;
|
||||
float fan = farZ + nearZ;
|
||||
float fsn = farZ - nearZ;
|
||||
|
||||
GLKMatrix4 m = { 2.0f / rsl, 0.0f, 0.0f, 0.0f,
|
||||
0.0f, 2.0f / tsb, 0.0f, 0.0f,
|
||||
0.0f, 0.0f, -2.0f / fsn, 0.0f,
|
||||
-ral / rsl, -tab / tsb, -fan / fsn, 1.0f };
|
||||
|
||||
return m;
|
||||
}
|
||||
|
||||
static __inline__ GLKMatrix4 GLKMatrix4MakeLookAt(float eyeX, float eyeY, float eyeZ,
|
||||
float centerX, float centerY, float centerZ,
|
||||
float upX, float upY, float upZ)
|
||||
{
|
||||
GLKVector3 ev = { eyeX, eyeY, eyeZ };
|
||||
GLKVector3 cv = { centerX, centerY, centerZ };
|
||||
GLKVector3 uv = { upX, upY, upZ };
|
||||
GLKVector3 n = GLKVector3Normalize(GLKVector3Add(ev, GLKVector3Negate(cv)));
|
||||
GLKVector3 u = GLKVector3Normalize(GLKVector3CrossProduct(uv, n));
|
||||
GLKVector3 v = GLKVector3CrossProduct(n, u);
|
||||
|
||||
GLKMatrix4 m = { u.v[0], v.v[0], n.v[0], 0.0f,
|
||||
u.v[1], v.v[1], n.v[1], 0.0f,
|
||||
u.v[2], v.v[2], n.v[2], 0.0f,
|
||||
GLKVector3DotProduct(GLKVector3Negate(u), ev),
|
||||
GLKVector3DotProduct(GLKVector3Negate(v), ev),
|
||||
GLKVector3DotProduct(GLKVector3Negate(n), ev),
|
||||
1.0f };
|
||||
|
||||
return m;
|
||||
}
|
||||
|
||||
static __inline__ GLKMatrix3 GLKMatrix4GetMatrix3(GLKMatrix4 matrix)
|
||||
{
|
||||
GLKMatrix3 m = { matrix.m[0], matrix.m[1], matrix.m[2],
|
||||
matrix.m[4], matrix.m[5], matrix.m[6],
|
||||
matrix.m[8], matrix.m[9], matrix.m[10] };
|
||||
return m;
|
||||
}
|
||||
|
||||
static __inline__ GLKMatrix2 GLKMatrix4GetMatrix2(GLKMatrix4 matrix)
|
||||
{
|
||||
GLKMatrix2 m = { matrix.m[0], matrix.m[1],
|
||||
matrix.m[4], matrix.m[5] };
|
||||
return m;
|
||||
}
|
||||
|
||||
static __inline__ GLKVector4 GLKMatrix4GetRow(GLKMatrix4 matrix, int row)
|
||||
{
|
||||
GLKVector4 v = { matrix.m[row], matrix.m[4 + row], matrix.m[8 + row], matrix.m[12 + row] };
|
||||
return v;
|
||||
}
|
||||
|
||||
static __inline__ GLKVector4 GLKMatrix4GetColumn(GLKMatrix4 matrix, int column)
|
||||
{
|
||||
#if defined(__ARM_NEON__)
|
||||
float32x4_t v = vld1q_f32(&(matrix.m[column * 4]));
|
||||
return *(GLKVector4 *)&v;
|
||||
#else
|
||||
GLKVector4 v = { matrix.m[column * 4 + 0], matrix.m[column * 4 + 1], matrix.m[column * 4 + 2], matrix.m[column * 4 + 3] };
|
||||
return v;
|
||||
#endif
|
||||
}
|
||||
|
||||
static __inline__ GLKMatrix4 GLKMatrix4SetRow(GLKMatrix4 matrix, int row, GLKVector4 vector)
|
||||
{
|
||||
matrix.m[row] = vector.v[0];
|
||||
matrix.m[row + 4] = vector.v[1];
|
||||
matrix.m[row + 8] = vector.v[2];
|
||||
matrix.m[row + 12] = vector.v[3];
|
||||
|
||||
return matrix;
|
||||
}
|
||||
|
||||
static __inline__ GLKMatrix4 GLKMatrix4SetColumn(GLKMatrix4 matrix, int column, GLKVector4 vector)
|
||||
{
|
||||
#if defined(__ARM_NEON__)
|
||||
float *dst = &(matrix.m[column * 4]);
|
||||
vst1q_f32(dst, vld1q_f32(vector.v));
|
||||
return matrix;
|
||||
#else
|
||||
matrix.m[column * 4 + 0] = vector.v[0];
|
||||
matrix.m[column * 4 + 1] = vector.v[1];
|
||||
matrix.m[column * 4 + 2] = vector.v[2];
|
||||
matrix.m[column * 4 + 3] = vector.v[3];
|
||||
|
||||
return matrix;
|
||||
#endif
|
||||
}
|
||||
|
||||
static __inline__ GLKMatrix4 GLKMatrix4Transpose(GLKMatrix4 matrix)
|
||||
{
|
||||
#if defined(__ARM_NEON__)
|
||||
float32x4x4_t m = vld4q_f32(matrix.m);
|
||||
return *(GLKMatrix4 *)&m;
|
||||
#else
|
||||
GLKMatrix4 m = { matrix.m[0], matrix.m[4], matrix.m[8], matrix.m[12],
|
||||
matrix.m[1], matrix.m[5], matrix.m[9], matrix.m[13],
|
||||
matrix.m[2], matrix.m[6], matrix.m[10], matrix.m[14],
|
||||
matrix.m[3], matrix.m[7], matrix.m[11], matrix.m[15] };
|
||||
return m;
|
||||
#endif
|
||||
}
|
||||
|
||||
static __inline__ GLKMatrix4 GLKMatrix4Multiply(GLKMatrix4 matrixLeft, GLKMatrix4 matrixRight)
|
||||
{
|
||||
#if defined(__ARM_NEON__)
|
||||
float32x4x4_t iMatrixLeft = *(float32x4x4_t *)&matrixLeft;
|
||||
float32x4x4_t iMatrixRight = *(float32x4x4_t *)&matrixRight;
|
||||
float32x4x4_t m;
|
||||
|
||||
m.val[0] = vmulq_n_f32(iMatrixLeft.val[0], vgetq_lane_f32(iMatrixRight.val[0], 0));
|
||||
m.val[1] = vmulq_n_f32(iMatrixLeft.val[0], vgetq_lane_f32(iMatrixRight.val[1], 0));
|
||||
m.val[2] = vmulq_n_f32(iMatrixLeft.val[0], vgetq_lane_f32(iMatrixRight.val[2], 0));
|
||||
m.val[3] = vmulq_n_f32(iMatrixLeft.val[0], vgetq_lane_f32(iMatrixRight.val[3], 0));
|
||||
|
||||
m.val[0] = vmlaq_n_f32(m.val[0], iMatrixLeft.val[1], vgetq_lane_f32(iMatrixRight.val[0], 1));
|
||||
m.val[1] = vmlaq_n_f32(m.val[1], iMatrixLeft.val[1], vgetq_lane_f32(iMatrixRight.val[1], 1));
|
||||
m.val[2] = vmlaq_n_f32(m.val[2], iMatrixLeft.val[1], vgetq_lane_f32(iMatrixRight.val[2], 1));
|
||||
m.val[3] = vmlaq_n_f32(m.val[3], iMatrixLeft.val[1], vgetq_lane_f32(iMatrixRight.val[3], 1));
|
||||
|
||||
m.val[0] = vmlaq_n_f32(m.val[0], iMatrixLeft.val[2], vgetq_lane_f32(iMatrixRight.val[0], 2));
|
||||
m.val[1] = vmlaq_n_f32(m.val[1], iMatrixLeft.val[2], vgetq_lane_f32(iMatrixRight.val[1], 2));
|
||||
m.val[2] = vmlaq_n_f32(m.val[2], iMatrixLeft.val[2], vgetq_lane_f32(iMatrixRight.val[2], 2));
|
||||
m.val[3] = vmlaq_n_f32(m.val[3], iMatrixLeft.val[2], vgetq_lane_f32(iMatrixRight.val[3], 2));
|
||||
|
||||
m.val[0] = vmlaq_n_f32(m.val[0], iMatrixLeft.val[3], vgetq_lane_f32(iMatrixRight.val[0], 3));
|
||||
m.val[1] = vmlaq_n_f32(m.val[1], iMatrixLeft.val[3], vgetq_lane_f32(iMatrixRight.val[1], 3));
|
||||
m.val[2] = vmlaq_n_f32(m.val[2], iMatrixLeft.val[3], vgetq_lane_f32(iMatrixRight.val[2], 3));
|
||||
m.val[3] = vmlaq_n_f32(m.val[3], iMatrixLeft.val[3], vgetq_lane_f32(iMatrixRight.val[3], 3));
|
||||
|
||||
return *(GLKMatrix4 *)&m;
|
||||
#else
|
||||
GLKMatrix4 m;
|
||||
|
||||
m.m[0] = matrixLeft.m[0] * matrixRight.m[0] + matrixLeft.m[4] * matrixRight.m[1] + matrixLeft.m[8] * matrixRight.m[2] + matrixLeft.m[12] * matrixRight.m[3];
|
||||
m.m[4] = matrixLeft.m[0] * matrixRight.m[4] + matrixLeft.m[4] * matrixRight.m[5] + matrixLeft.m[8] * matrixRight.m[6] + matrixLeft.m[12] * matrixRight.m[7];
|
||||
m.m[8] = matrixLeft.m[0] * matrixRight.m[8] + matrixLeft.m[4] * matrixRight.m[9] + matrixLeft.m[8] * matrixRight.m[10] + matrixLeft.m[12] * matrixRight.m[11];
|
||||
m.m[12] = matrixLeft.m[0] * matrixRight.m[12] + matrixLeft.m[4] * matrixRight.m[13] + matrixLeft.m[8] * matrixRight.m[14] + matrixLeft.m[12] * matrixRight.m[15];
|
||||
|
||||
m.m[1] = matrixLeft.m[1] * matrixRight.m[0] + matrixLeft.m[5] * matrixRight.m[1] + matrixLeft.m[9] * matrixRight.m[2] + matrixLeft.m[13] * matrixRight.m[3];
|
||||
m.m[5] = matrixLeft.m[1] * matrixRight.m[4] + matrixLeft.m[5] * matrixRight.m[5] + matrixLeft.m[9] * matrixRight.m[6] + matrixLeft.m[13] * matrixRight.m[7];
|
||||
m.m[9] = matrixLeft.m[1] * matrixRight.m[8] + matrixLeft.m[5] * matrixRight.m[9] + matrixLeft.m[9] * matrixRight.m[10] + matrixLeft.m[13] * matrixRight.m[11];
|
||||
m.m[13] = matrixLeft.m[1] * matrixRight.m[12] + matrixLeft.m[5] * matrixRight.m[13] + matrixLeft.m[9] * matrixRight.m[14] + matrixLeft.m[13] * matrixRight.m[15];
|
||||
|
||||
m.m[2] = matrixLeft.m[2] * matrixRight.m[0] + matrixLeft.m[6] * matrixRight.m[1] + matrixLeft.m[10] * matrixRight.m[2] + matrixLeft.m[14] * matrixRight.m[3];
|
||||
m.m[6] = matrixLeft.m[2] * matrixRight.m[4] + matrixLeft.m[6] * matrixRight.m[5] + matrixLeft.m[10] * matrixRight.m[6] + matrixLeft.m[14] * matrixRight.m[7];
|
||||
m.m[10] = matrixLeft.m[2] * matrixRight.m[8] + matrixLeft.m[6] * matrixRight.m[9] + matrixLeft.m[10] * matrixRight.m[10] + matrixLeft.m[14] * matrixRight.m[11];
|
||||
m.m[14] = matrixLeft.m[2] * matrixRight.m[12] + matrixLeft.m[6] * matrixRight.m[13] + matrixLeft.m[10] * matrixRight.m[14] + matrixLeft.m[14] * matrixRight.m[15];
|
||||
|
||||
m.m[3] = matrixLeft.m[3] * matrixRight.m[0] + matrixLeft.m[7] * matrixRight.m[1] + matrixLeft.m[11] * matrixRight.m[2] + matrixLeft.m[15] * matrixRight.m[3];
|
||||
m.m[7] = matrixLeft.m[3] * matrixRight.m[4] + matrixLeft.m[7] * matrixRight.m[5] + matrixLeft.m[11] * matrixRight.m[6] + matrixLeft.m[15] * matrixRight.m[7];
|
||||
m.m[11] = matrixLeft.m[3] * matrixRight.m[8] + matrixLeft.m[7] * matrixRight.m[9] + matrixLeft.m[11] * matrixRight.m[10] + matrixLeft.m[15] * matrixRight.m[11];
|
||||
m.m[15] = matrixLeft.m[3] * matrixRight.m[12] + matrixLeft.m[7] * matrixRight.m[13] + matrixLeft.m[11] * matrixRight.m[14] + matrixLeft.m[15] * matrixRight.m[15];
|
||||
|
||||
return m;
|
||||
#endif
|
||||
}
|
||||
|
||||
static __inline__ GLKMatrix4 GLKMatrix4Add(GLKMatrix4 matrixLeft, GLKMatrix4 matrixRight)
|
||||
{
|
||||
#if defined(__ARM_NEON__)
|
||||
float32x4x4_t iMatrixLeft = *(float32x4x4_t *)&matrixLeft;
|
||||
float32x4x4_t iMatrixRight = *(float32x4x4_t *)&matrixRight;
|
||||
float32x4x4_t m;
|
||||
|
||||
m.val[0] = vaddq_f32(iMatrixLeft.val[0], iMatrixRight.val[0]);
|
||||
m.val[1] = vaddq_f32(iMatrixLeft.val[1], iMatrixRight.val[1]);
|
||||
m.val[2] = vaddq_f32(iMatrixLeft.val[2], iMatrixRight.val[2]);
|
||||
m.val[3] = vaddq_f32(iMatrixLeft.val[3], iMatrixRight.val[3]);
|
||||
|
||||
return *(GLKMatrix4 *)&m;
|
||||
#else
|
||||
GLKMatrix4 m;
|
||||
|
||||
m.m[0] = matrixLeft.m[0] + matrixRight.m[0];
|
||||
m.m[1] = matrixLeft.m[1] + matrixRight.m[1];
|
||||
m.m[2] = matrixLeft.m[2] + matrixRight.m[2];
|
||||
m.m[3] = matrixLeft.m[3] + matrixRight.m[3];
|
||||
|
||||
m.m[4] = matrixLeft.m[4] + matrixRight.m[4];
|
||||
m.m[5] = matrixLeft.m[5] + matrixRight.m[5];
|
||||
m.m[6] = matrixLeft.m[6] + matrixRight.m[6];
|
||||
m.m[7] = matrixLeft.m[7] + matrixRight.m[7];
|
||||
|
||||
m.m[8] = matrixLeft.m[8] + matrixRight.m[8];
|
||||
m.m[9] = matrixLeft.m[9] + matrixRight.m[9];
|
||||
m.m[10] = matrixLeft.m[10] + matrixRight.m[10];
|
||||
m.m[11] = matrixLeft.m[11] + matrixRight.m[11];
|
||||
|
||||
m.m[12] = matrixLeft.m[12] + matrixRight.m[12];
|
||||
m.m[13] = matrixLeft.m[13] + matrixRight.m[13];
|
||||
m.m[14] = matrixLeft.m[14] + matrixRight.m[14];
|
||||
m.m[15] = matrixLeft.m[15] + matrixRight.m[15];
|
||||
|
||||
return m;
|
||||
#endif
|
||||
}
|
||||
|
||||
static __inline__ GLKMatrix4 GLKMatrix4Subtract(GLKMatrix4 matrixLeft, GLKMatrix4 matrixRight)
|
||||
{
|
||||
#if defined(__ARM_NEON__)
|
||||
float32x4x4_t iMatrixLeft = *(float32x4x4_t *)&matrixLeft;
|
||||
float32x4x4_t iMatrixRight = *(float32x4x4_t *)&matrixRight;
|
||||
float32x4x4_t m;
|
||||
|
||||
m.val[0] = vsubq_f32(iMatrixLeft.val[0], iMatrixRight.val[0]);
|
||||
m.val[1] = vsubq_f32(iMatrixLeft.val[1], iMatrixRight.val[1]);
|
||||
m.val[2] = vsubq_f32(iMatrixLeft.val[2], iMatrixRight.val[2]);
|
||||
m.val[3] = vsubq_f32(iMatrixLeft.val[3], iMatrixRight.val[3]);
|
||||
|
||||
return *(GLKMatrix4 *)&m;
|
||||
#else
|
||||
GLKMatrix4 m;
|
||||
|
||||
m.m[0] = matrixLeft.m[0] - matrixRight.m[0];
|
||||
m.m[1] = matrixLeft.m[1] - matrixRight.m[1];
|
||||
m.m[2] = matrixLeft.m[2] - matrixRight.m[2];
|
||||
m.m[3] = matrixLeft.m[3] - matrixRight.m[3];
|
||||
|
||||
m.m[4] = matrixLeft.m[4] - matrixRight.m[4];
|
||||
m.m[5] = matrixLeft.m[5] - matrixRight.m[5];
|
||||
m.m[6] = matrixLeft.m[6] - matrixRight.m[6];
|
||||
m.m[7] = matrixLeft.m[7] - matrixRight.m[7];
|
||||
|
||||
m.m[8] = matrixLeft.m[8] - matrixRight.m[8];
|
||||
m.m[9] = matrixLeft.m[9] - matrixRight.m[9];
|
||||
m.m[10] = matrixLeft.m[10] - matrixRight.m[10];
|
||||
m.m[11] = matrixLeft.m[11] - matrixRight.m[11];
|
||||
|
||||
m.m[12] = matrixLeft.m[12] - matrixRight.m[12];
|
||||
m.m[13] = matrixLeft.m[13] - matrixRight.m[13];
|
||||
m.m[14] = matrixLeft.m[14] - matrixRight.m[14];
|
||||
m.m[15] = matrixLeft.m[15] - matrixRight.m[15];
|
||||
|
||||
return m;
|
||||
#endif
|
||||
}
|
||||
|
||||
static __inline__ GLKMatrix4 GLKMatrix4Translate(GLKMatrix4 matrix, float tx, float ty, float tz)
|
||||
{
|
||||
GLKMatrix4 m = { matrix.m[0], matrix.m[1], matrix.m[2], matrix.m[3],
|
||||
matrix.m[4], matrix.m[5], matrix.m[6], matrix.m[7],
|
||||
matrix.m[8], matrix.m[9], matrix.m[10], matrix.m[11],
|
||||
matrix.m[0] * tx + matrix.m[4] * ty + matrix.m[8] * tz + matrix.m[12],
|
||||
matrix.m[1] * tx + matrix.m[5] * ty + matrix.m[9] * tz + matrix.m[13],
|
||||
matrix.m[2] * tx + matrix.m[6] * ty + matrix.m[10] * tz + matrix.m[14],
|
||||
matrix.m[15] };
|
||||
return m;
|
||||
}
|
||||
|
||||
static __inline__ GLKMatrix4 GLKMatrix4TranslateWithVector3(GLKMatrix4 matrix, GLKVector3 translationVector)
|
||||
{
|
||||
GLKMatrix4 m = { matrix.m[0], matrix.m[1], matrix.m[2], matrix.m[3],
|
||||
matrix.m[4], matrix.m[5], matrix.m[6], matrix.m[7],
|
||||
matrix.m[8], matrix.m[9], matrix.m[10], matrix.m[11],
|
||||
matrix.m[0] * translationVector.v[0] + matrix.m[4] * translationVector.v[1] + matrix.m[8] * translationVector.v[2] + matrix.m[12],
|
||||
matrix.m[1] * translationVector.v[0] + matrix.m[5] * translationVector.v[1] + matrix.m[9] * translationVector.v[2] + matrix.m[13],
|
||||
matrix.m[2] * translationVector.v[0] + matrix.m[6] * translationVector.v[1] + matrix.m[10] * translationVector.v[2] + matrix.m[14],
|
||||
matrix.m[15] };
|
||||
return m;
|
||||
}
|
||||
|
||||
static __inline__ GLKMatrix4 GLKMatrix4TranslateWithVector4(GLKMatrix4 matrix, GLKVector4 translationVector)
|
||||
{
|
||||
GLKMatrix4 m = { matrix.m[0], matrix.m[1], matrix.m[2], matrix.m[3],
|
||||
matrix.m[4], matrix.m[5], matrix.m[6], matrix.m[7],
|
||||
matrix.m[8], matrix.m[9], matrix.m[10], matrix.m[11],
|
||||
matrix.m[0] * translationVector.v[0] + matrix.m[4] * translationVector.v[1] + matrix.m[8] * translationVector.v[2] + matrix.m[12],
|
||||
matrix.m[1] * translationVector.v[0] + matrix.m[5] * translationVector.v[1] + matrix.m[9] * translationVector.v[2] + matrix.m[13],
|
||||
matrix.m[2] * translationVector.v[0] + matrix.m[6] * translationVector.v[1] + matrix.m[10] * translationVector.v[2] + matrix.m[14],
|
||||
matrix.m[15] };
|
||||
return m;
|
||||
}
|
||||
|
||||
static __inline__ GLKMatrix4 GLKMatrix4Scale(GLKMatrix4 matrix, float sx, float sy, float sz)
|
||||
{
|
||||
#if defined(__ARM_NEON__)
|
||||
float32x4x4_t iMatrix = *(float32x4x4_t *)&matrix;
|
||||
float32x4x4_t m;
|
||||
|
||||
m.val[0] = vmulq_n_f32(iMatrix.val[0], (float32_t)sx);
|
||||
m.val[1] = vmulq_n_f32(iMatrix.val[1], (float32_t)sy);
|
||||
m.val[2] = vmulq_n_f32(iMatrix.val[2], (float32_t)sz);
|
||||
m.val[3] = iMatrix.val[3];
|
||||
|
||||
return *(GLKMatrix4 *)&m;
|
||||
#else
|
||||
GLKMatrix4 m = { matrix.m[0] * sx, matrix.m[1] * sx, matrix.m[2] * sx, matrix.m[3] * sx,
|
||||
matrix.m[4] * sy, matrix.m[5] * sy, matrix.m[6] * sy, matrix.m[7] * sy,
|
||||
matrix.m[8] * sz, matrix.m[9] * sz, matrix.m[10] * sz, matrix.m[11] * sz,
|
||||
matrix.m[12], matrix.m[13], matrix.m[14], matrix.m[15] };
|
||||
return m;
|
||||
#endif
|
||||
}
|
||||
|
||||
static __inline__ GLKMatrix4 GLKMatrix4ScaleWithVector3(GLKMatrix4 matrix, GLKVector3 scaleVector)
|
||||
{
|
||||
#if defined(__ARM_NEON__)
|
||||
float32x4x4_t iMatrix = *(float32x4x4_t *)&matrix;
|
||||
float32x4x4_t m;
|
||||
|
||||
m.val[0] = vmulq_n_f32(iMatrix.val[0], (float32_t)scaleVector.v[0]);
|
||||
m.val[1] = vmulq_n_f32(iMatrix.val[1], (float32_t)scaleVector.v[1]);
|
||||
m.val[2] = vmulq_n_f32(iMatrix.val[2], (float32_t)scaleVector.v[2]);
|
||||
m.val[3] = iMatrix.val[3];
|
||||
|
||||
return *(GLKMatrix4 *)&m;
|
||||
#else
|
||||
GLKMatrix4 m = { matrix.m[0] * scaleVector.v[0], matrix.m[1] * scaleVector.v[0], matrix.m[2] * scaleVector.v[0], matrix.m[3] * scaleVector.v[0],
|
||||
matrix.m[4] * scaleVector.v[1], matrix.m[5] * scaleVector.v[1], matrix.m[6] * scaleVector.v[1], matrix.m[7] * scaleVector.v[1],
|
||||
matrix.m[8] * scaleVector.v[2], matrix.m[9] * scaleVector.v[2], matrix.m[10] * scaleVector.v[2], matrix.m[11] * scaleVector.v[2],
|
||||
matrix.m[12], matrix.m[13], matrix.m[14], matrix.m[15] };
|
||||
return m;
|
||||
#endif
|
||||
}
|
||||
|
||||
static __inline__ GLKMatrix4 GLKMatrix4ScaleWithVector4(GLKMatrix4 matrix, GLKVector4 scaleVector)
|
||||
{
|
||||
#if defined(__ARM_NEON__)
|
||||
float32x4x4_t iMatrix = *(float32x4x4_t *)&matrix;
|
||||
float32x4x4_t m;
|
||||
|
||||
m.val[0] = vmulq_n_f32(iMatrix.val[0], (float32_t)scaleVector.v[0]);
|
||||
m.val[1] = vmulq_n_f32(iMatrix.val[1], (float32_t)scaleVector.v[1]);
|
||||
m.val[2] = vmulq_n_f32(iMatrix.val[2], (float32_t)scaleVector.v[2]);
|
||||
m.val[3] = iMatrix.val[3];
|
||||
|
||||
return *(GLKMatrix4 *)&m;
|
||||
#else
|
||||
GLKMatrix4 m = { matrix.m[0] * scaleVector.v[0], matrix.m[1] * scaleVector.v[0], matrix.m[2] * scaleVector.v[0], matrix.m[3] * scaleVector.v[0],
|
||||
matrix.m[4] * scaleVector.v[1], matrix.m[5] * scaleVector.v[1], matrix.m[6] * scaleVector.v[1], matrix.m[7] * scaleVector.v[1],
|
||||
matrix.m[8] * scaleVector.v[2], matrix.m[9] * scaleVector.v[2], matrix.m[10] * scaleVector.v[2], matrix.m[11] * scaleVector.v[2],
|
||||
matrix.m[12], matrix.m[13], matrix.m[14], matrix.m[15] };
|
||||
return m;
|
||||
#endif
|
||||
}
|
||||
|
||||
static __inline__ GLKMatrix4 GLKMatrix4Rotate(GLKMatrix4 matrix, float radians, float x, float y, float z)
|
||||
{
|
||||
GLKMatrix4 rm = GLKMatrix4MakeRotation(radians, x, y, z);
|
||||
return GLKMatrix4Multiply(matrix, rm);
|
||||
}
|
||||
|
||||
static __inline__ GLKMatrix4 GLKMatrix4RotateWithVector3(GLKMatrix4 matrix, float radians, GLKVector3 axisVector)
|
||||
{
|
||||
GLKMatrix4 rm = GLKMatrix4MakeRotation(radians, axisVector.v[0], axisVector.v[1], axisVector.v[2]);
|
||||
return GLKMatrix4Multiply(matrix, rm);
|
||||
}
|
||||
|
||||
static __inline__ GLKMatrix4 GLKMatrix4RotateWithVector4(GLKMatrix4 matrix, float radians, GLKVector4 axisVector)
|
||||
{
|
||||
GLKMatrix4 rm = GLKMatrix4MakeRotation(radians, axisVector.v[0], axisVector.v[1], axisVector.v[2]);
|
||||
return GLKMatrix4Multiply(matrix, rm);
|
||||
}
|
||||
|
||||
static __inline__ GLKMatrix4 GLKMatrix4RotateX(GLKMatrix4 matrix, float radians)
|
||||
{
|
||||
GLKMatrix4 rm = GLKMatrix4MakeXRotation(radians);
|
||||
return GLKMatrix4Multiply(matrix, rm);
|
||||
}
|
||||
|
||||
static __inline__ GLKMatrix4 GLKMatrix4RotateY(GLKMatrix4 matrix, float radians)
|
||||
{
|
||||
GLKMatrix4 rm = GLKMatrix4MakeYRotation(radians);
|
||||
return GLKMatrix4Multiply(matrix, rm);
|
||||
}
|
||||
|
||||
static __inline__ GLKMatrix4 GLKMatrix4RotateZ(GLKMatrix4 matrix, float radians)
|
||||
{
|
||||
GLKMatrix4 rm = GLKMatrix4MakeZRotation(radians);
|
||||
return GLKMatrix4Multiply(matrix, rm);
|
||||
}
|
||||
|
||||
static __inline__ GLKVector3 GLKMatrix4MultiplyVector3(GLKMatrix4 matrixLeft, GLKVector3 vectorRight)
|
||||
{
|
||||
GLKVector4 v4 = GLKMatrix4MultiplyVector4(matrixLeft, GLKVector4Make(vectorRight.v[0], vectorRight.v[1], vectorRight.v[2], 0.0f));
|
||||
return GLKVector3Make(v4.v[0], v4.v[1], v4.v[2]);
|
||||
}
|
||||
|
||||
static __inline__ GLKVector3 GLKMatrix4MultiplyVector3WithTranslation(GLKMatrix4 matrixLeft, GLKVector3 vectorRight)
|
||||
{
|
||||
GLKVector4 v4 = GLKMatrix4MultiplyVector4(matrixLeft, GLKVector4Make(vectorRight.v[0], vectorRight.v[1], vectorRight.v[2], 1.0f));
|
||||
return GLKVector3Make(v4.v[0], v4.v[1], v4.v[2]);
|
||||
}
|
||||
|
||||
static __inline__ GLKVector3 GLKMatrix4MultiplyAndProjectVector3(GLKMatrix4 matrixLeft, GLKVector3 vectorRight)
|
||||
{
|
||||
GLKVector4 v4 = GLKMatrix4MultiplyVector4(matrixLeft, GLKVector4Make(vectorRight.v[0], vectorRight.v[1], vectorRight.v[2], 1.0f));
|
||||
return GLKVector3MultiplyScalar(GLKVector3Make(v4.v[0], v4.v[1], v4.v[2]), 1.0f / v4.v[3]);
|
||||
}
|
||||
|
||||
static __inline__ void GLKMatrix4MultiplyVector3Array(GLKMatrix4 matrix, GLKVector3 *vectors, size_t vectorCount)
|
||||
{
|
||||
size_t i;
|
||||
for (i=0; i < vectorCount; i++)
|
||||
vectors[i] = GLKMatrix4MultiplyVector3(matrix, vectors[i]);
|
||||
}
|
||||
|
||||
static __inline__ void GLKMatrix4MultiplyVector3ArrayWithTranslation(GLKMatrix4 matrix, GLKVector3 *vectors, size_t vectorCount)
|
||||
{
|
||||
size_t i;
|
||||
for (i=0; i < vectorCount; i++)
|
||||
vectors[i] = GLKMatrix4MultiplyVector3WithTranslation(matrix, vectors[i]);
|
||||
}
|
||||
|
||||
static __inline__ void GLKMatrix4MultiplyAndProjectVector3Array(GLKMatrix4 matrix, GLKVector3 *vectors, size_t vectorCount)
|
||||
{
|
||||
size_t i;
|
||||
for (i=0; i < vectorCount; i++)
|
||||
vectors[i] = GLKMatrix4MultiplyAndProjectVector3(matrix, vectors[i]);
|
||||
}
|
||||
|
||||
static __inline__ GLKVector4 GLKMatrix4MultiplyVector4(GLKMatrix4 matrixLeft, GLKVector4 vectorRight)
|
||||
{
|
||||
#if defined(__ARM_NEON__)
|
||||
float32x4x4_t iMatrix = *(float32x4x4_t *)&matrixLeft;
|
||||
float32x4_t v;
|
||||
|
||||
iMatrix.val[0] = vmulq_n_f32(iMatrix.val[0], (float32_t)vectorRight.v[0]);
|
||||
iMatrix.val[1] = vmulq_n_f32(iMatrix.val[1], (float32_t)vectorRight.v[1]);
|
||||
iMatrix.val[2] = vmulq_n_f32(iMatrix.val[2], (float32_t)vectorRight.v[2]);
|
||||
iMatrix.val[3] = vmulq_n_f32(iMatrix.val[3], (float32_t)vectorRight.v[3]);
|
||||
|
||||
iMatrix.val[0] = vaddq_f32(iMatrix.val[0], iMatrix.val[1]);
|
||||
iMatrix.val[2] = vaddq_f32(iMatrix.val[2], iMatrix.val[3]);
|
||||
|
||||
v = vaddq_f32(iMatrix.val[0], iMatrix.val[2]);
|
||||
|
||||
return *(GLKVector4 *)&v;
|
||||
#else
|
||||
GLKVector4 v = { matrixLeft.m[0] * vectorRight.v[0] + matrixLeft.m[4] * vectorRight.v[1] + matrixLeft.m[8] * vectorRight.v[2] + matrixLeft.m[12] * vectorRight.v[3],
|
||||
matrixLeft.m[1] * vectorRight.v[0] + matrixLeft.m[5] * vectorRight.v[1] + matrixLeft.m[9] * vectorRight.v[2] + matrixLeft.m[13] * vectorRight.v[3],
|
||||
matrixLeft.m[2] * vectorRight.v[0] + matrixLeft.m[6] * vectorRight.v[1] + matrixLeft.m[10] * vectorRight.v[2] + matrixLeft.m[14] * vectorRight.v[3],
|
||||
matrixLeft.m[3] * vectorRight.v[0] + matrixLeft.m[7] * vectorRight.v[1] + matrixLeft.m[11] * vectorRight.v[2] + matrixLeft.m[15] * vectorRight.v[3] };
|
||||
return v;
|
||||
#endif
|
||||
}
|
||||
|
||||
static __inline__ void GLKMatrix4MultiplyVector4Array(GLKMatrix4 matrix, GLKVector4 *vectors, size_t vectorCount)
|
||||
{
|
||||
size_t i;
|
||||
for (i=0; i < vectorCount; i++)
|
||||
vectors[i] = GLKMatrix4MultiplyVector4(matrix, vectors[i]);
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __GLK_MATRIX_4_H */
|
||||
99
samples/C/NWMan.h
Normal file
99
samples/C/NWMan.h
Normal file
@@ -0,0 +1,99 @@
|
||||
#ifndef _NME_WMAN_H
|
||||
#define _NME_WMAN_H
|
||||
|
||||
// Internal window manager API
|
||||
|
||||
#include "NCompat.h"
|
||||
|
||||
START_HEAD
|
||||
|
||||
#include "NPos.h"
|
||||
#include "NUtil.h"
|
||||
#include "NTypes.h"
|
||||
|
||||
NTS(NWMan_event);
|
||||
|
||||
NSTRUCT(NWMan, {
|
||||
// Init stuff
|
||||
bool (*init)();
|
||||
bool (*destroy)();
|
||||
|
||||
// Window stuff
|
||||
bool (*create_window)();
|
||||
bool (*destroy_window)();
|
||||
|
||||
void (*swap_buffers)();
|
||||
|
||||
// Event stuff
|
||||
bool (*next_event)(NWMan_event* event);
|
||||
|
||||
// Time stuff
|
||||
uint (*get_millis)();
|
||||
void (*sleep)(uint millis);
|
||||
|
||||
// Info
|
||||
int rshift_key;
|
||||
int lshift_key;
|
||||
int left_key;
|
||||
int right_key;
|
||||
});
|
||||
|
||||
NENUM(NWMan_event_type, {
|
||||
N_WMAN_MOUSE_MOVE = 0,
|
||||
N_WMAN_MOUSE_BUTTON = 1,
|
||||
N_WMAN_MOUSE_WHEEL = 2,
|
||||
|
||||
N_WMAN_KEYBOARD = 10,
|
||||
|
||||
N_WMAN_QUIT = 20,
|
||||
N_WMAN_RESIZE = 21,
|
||||
N_WMAN_FOCUS = 22
|
||||
});
|
||||
|
||||
#define N_WMAN_MOUSE_LEFT 0
|
||||
#define N_WMAN_MOUSE_RIGHT 1
|
||||
#define N_WMAN_MOUSE_MIDDLE 2
|
||||
|
||||
NSTRUCT(NWMan_event, {
|
||||
NWMan_event_type type;
|
||||
|
||||
union {
|
||||
// Mouse
|
||||
|
||||
NPos2i mouse_pos;
|
||||
|
||||
struct {
|
||||
short id;
|
||||
bool state;
|
||||
} mouse_button;
|
||||
|
||||
signed char mouse_wheel; // 1 if up, -1 if down
|
||||
|
||||
// Keyboard
|
||||
|
||||
struct {
|
||||
int key;
|
||||
bool state;
|
||||
} keyboard;
|
||||
|
||||
// Window
|
||||
|
||||
bool window_quit; // Will always be true if WM_QUIT
|
||||
|
||||
NPos2i window_size;
|
||||
|
||||
bool window_focus;
|
||||
};
|
||||
});
|
||||
|
||||
NWMan_event NWMan_event_new(NWMan_event_type type);
|
||||
|
||||
|
||||
bool NWMan_init();
|
||||
bool NWMan_destroy();
|
||||
|
||||
extern NWMan N_WMan;
|
||||
|
||||
END_HEAD
|
||||
|
||||
#endif
|
||||
27
samples/C/Nightmare.h
Normal file
27
samples/C/Nightmare.h
Normal file
@@ -0,0 +1,27 @@
|
||||
#ifndef _NMEX_NIGHTMARE_H
|
||||
#define _NMEX_NIGHTMARE_H
|
||||
|
||||
//#define NMEX
|
||||
|
||||
#include "../src/NCompat.h"
|
||||
|
||||
START_HEAD
|
||||
|
||||
#include "../src/NTypes.h"
|
||||
#include "../src/NUtil.h"
|
||||
#include "../src/NPorting.h"
|
||||
#include "../src/NGlobals.h"
|
||||
#include "../src/NLog.h"
|
||||
#include "../src/NWMan.h"
|
||||
#include "../src/NRsc.h"
|
||||
#include "../src/NShader.h"
|
||||
#include "../src/NSquare.h"
|
||||
#include "../src/NImage.h"
|
||||
#include "../src/NSprite.h"
|
||||
#include "../src/NSpritesheet.h"
|
||||
#include "../src/NEntity.h"
|
||||
#include "../src/Game.h"
|
||||
|
||||
END_HEAD
|
||||
|
||||
#endif
|
||||
47
samples/C/bitmap.h
Normal file
47
samples/C/bitmap.h
Normal file
@@ -0,0 +1,47 @@
|
||||
#pragma once
|
||||
|
||||
/* Copyright © 2010 Christoph Sünderhauf
|
||||
*
|
||||
* This file is part of Xelix.
|
||||
*
|
||||
* Xelix is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Xelix is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Xelix. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "generic.h"
|
||||
|
||||
typedef struct {
|
||||
uint32_t numbits;
|
||||
/* an array large enough for numbits to fit in. Might
|
||||
* (if numbits%8!=0) have some spare bits at the end
|
||||
*/
|
||||
uint32_t* bits;
|
||||
} bitmap_t;
|
||||
|
||||
|
||||
// creates a new bitmap.
|
||||
// CONTENT IS RANDOM! - use bitmap_clearall() to clear the bitmap.
|
||||
bitmap_t bitmap_init(uint32_t numbits);
|
||||
|
||||
// returns 1 or 0
|
||||
uint8_t bitmap_get(bitmap_t bitmap, uint32_t bitnum);
|
||||
// sets a bit (to 1)
|
||||
void bitmap_set(bitmap_t bitmap, uint32_t bitnum);
|
||||
// clears a bit (to 0)
|
||||
void bitmap_clear(bitmap_t bitmap, uint32_t bitnum);
|
||||
|
||||
// clears every bit to 0
|
||||
void bitmap_clearAll(bitmap_t bitmap);
|
||||
|
||||
// finds the first bit set to 0 returns 0 if no cleared bit found (0 is also returned if the first bit is cleared)
|
||||
uint32_t bitmap_findFirstClear(bitmap_t bitmap);
|
||||
44
samples/C/color.h
Normal file
44
samples/C/color.h
Normal file
@@ -0,0 +1,44 @@
|
||||
#pragma once
|
||||
|
||||
/* Copyright © 2011 Fritz Grimpen
|
||||
*
|
||||
* This file is part of Xelix.
|
||||
*
|
||||
* Xelix is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Xelix is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Xelix. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <lib/generic.h>
|
||||
|
||||
typedef struct {
|
||||
uint32_t background;
|
||||
uint32_t foreground;
|
||||
} console_color_t;
|
||||
|
||||
#define CONSOLE_COLOR_BLACK 0x0
|
||||
#define CONSOLE_COLOR_BLUE 0x1
|
||||
#define CONSOLE_COLOR_GREEN 0x2
|
||||
#define CONSOLE_COLOR_CYAN 0x3
|
||||
#define CONSOLE_COLOR_RED 0x4
|
||||
#define CONSOLE_COLOR_MAGENTA 0x5
|
||||
#define CONSOLE_COLOR_BROWN 0x6
|
||||
#define CONSOLE_COLOR_LGREY 0x7
|
||||
#define CONSOLE_COLOR_DGREY 0x8
|
||||
#define CONSOLE_COLOR_LBLUE 0x9
|
||||
#define CONSOLE_COLOR_LGREEN 0xa
|
||||
#define CONSOLE_COLOR_LCYAN 0xb
|
||||
#define CONSOLE_COLOR_LRED 0xc
|
||||
#define CONSOLE_COLOR_LMAGENTA 0xd
|
||||
#define CONSOLE_COLOR_YELLOW 0xe
|
||||
#define CONSOLE_COLOR_WHITE 0xf
|
||||
|
||||
52
samples/C/driver.h
Normal file
52
samples/C/driver.h
Normal file
@@ -0,0 +1,52 @@
|
||||
#pragma once
|
||||
|
||||
/* Copyright © 2011 Fritz Grimpen
|
||||
*
|
||||
* This file is part of Xelix.
|
||||
*
|
||||
* Xelix is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Xelix is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Xelix. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <lib/generic.h>
|
||||
#include <console/info.h>
|
||||
|
||||
#define CONSOLE_DRV_CAP_CLEAR 0x01
|
||||
#define CONSOLE_DRV_CAP_SCROLL 0x02
|
||||
#define CONSOLE_DRV_CAP_SET_CURSOR 0x04
|
||||
|
||||
// Input modifier keys
|
||||
typedef struct {
|
||||
bool shift_left:1;
|
||||
bool shift_right:1;
|
||||
bool control_left:1;
|
||||
bool control_right:1;
|
||||
bool alt:1;
|
||||
bool super:1;
|
||||
} console_modifiers_t;
|
||||
|
||||
typedef struct {
|
||||
char character;
|
||||
console_modifiers_t* modifiers;
|
||||
} console_read_t;
|
||||
|
||||
typedef struct {
|
||||
int (*write)(console_info_t*, char);
|
||||
console_read_t* (*read)(console_info_t*);
|
||||
|
||||
int capabilities;
|
||||
|
||||
int (*_clear)(console_info_t*);
|
||||
int (*scroll)(console_info_t*, int32_t);
|
||||
void (*setCursor)(console_info_t*, uint32_t, uint32_t);
|
||||
} console_driver_t;
|
||||
70
samples/C/elf.h
Normal file
70
samples/C/elf.h
Normal file
@@ -0,0 +1,70 @@
|
||||
#pragma once
|
||||
|
||||
/* Copyright © 2011 Lukas Martini
|
||||
*
|
||||
* This file is part of Xelix.
|
||||
*
|
||||
* Xelix is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Xelix is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Xelix. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <lib/generic.h>
|
||||
#include <tasks/scheduler.h>
|
||||
|
||||
#define ELF_TYPE_NONE 0
|
||||
#define ELF_TYPE_REL 1
|
||||
#define ELF_TYPE_EXEC 2
|
||||
#define ELF_TYPE_DYN 3
|
||||
#define ELF_TYPE_CORE 4
|
||||
|
||||
#define ELF_ARCH_NONE 0
|
||||
#define ELF_ARCH_386 3
|
||||
|
||||
#define ELF_VERSION_CURRENT 1
|
||||
|
||||
typedef struct {
|
||||
unsigned char magic[4];
|
||||
/* Note: There _is_ other stuff in here, but we don't need it */
|
||||
unsigned char pad[12];
|
||||
} __attribute__((packed)) elf_ident_t;
|
||||
|
||||
typedef struct {
|
||||
uint32_t type;
|
||||
uint32_t offset;
|
||||
void* virtaddr;
|
||||
void* physaddr;
|
||||
uint32_t filesize;
|
||||
uint32_t memsize;
|
||||
uint32_t flags;
|
||||
uint32_t alignment;
|
||||
} __attribute__((packed)) elf_program_t;
|
||||
|
||||
typedef struct {
|
||||
elf_ident_t ident;
|
||||
uint16_t type; /* Object file type */
|
||||
uint16_t machine; /* Architecture */
|
||||
uint32_t version; /* Object file version */
|
||||
void* entry; /* Entry point virtual address */
|
||||
uint32_t phoff; /* Program header table file offset */
|
||||
uint32_t shoff; /* Section header table file offset */
|
||||
uint32_t flags; /* Processor-specific flags */
|
||||
uint16_t ehsize; /* ELF header size in bytes */
|
||||
uint16_t phentsize; /* Program header table entry size */
|
||||
uint16_t phnum; /* Program header table entry count */
|
||||
uint16_t shentsize; /* Section header table entry size */
|
||||
uint16_t shnum; /* Section header table entry count */
|
||||
uint16_t shstrndx; /* Section header string table index */
|
||||
} __attribute__((packed)) elf_t;
|
||||
|
||||
task_t* elf_load(elf_t* bin, char* name, char** environ, char** argv, int argc);
|
||||
task_t* elf_load_file(char* path, char** environ, char** argv, int argc);
|
||||
45
samples/C/filter.h
Normal file
45
samples/C/filter.h
Normal file
@@ -0,0 +1,45 @@
|
||||
#pragma once
|
||||
|
||||
/* Copyright © 2011 Fritz Grimpen
|
||||
*
|
||||
* This file is part of Xelix.
|
||||
*
|
||||
* Xelix is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Xelix is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Xelix. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <lib/generic.h>
|
||||
#include <console/info.h>
|
||||
#include <console/driver.h>
|
||||
|
||||
struct console_filter {
|
||||
// General callback for all actions etc.
|
||||
// Preferred prototype:
|
||||
// char <name>(char c, console_info_t *info, console_driver_t *input, console_driver_t *output);
|
||||
char (*callback)(char, console_info_t*, console_driver_t*, console_driver_t*);
|
||||
|
||||
// Specific callbacks for read and write
|
||||
// Preferred prototype:
|
||||
// char <name>(char c, console_info_t *info, console_driver_t *input);
|
||||
char (*read_callback)(char, console_info_t*, console_driver_t*);
|
||||
|
||||
// Preferred prototype:
|
||||
// char <name>(char c, console_info_t *info, console_driver_t *output);
|
||||
char (*write_callback)(char, console_info_t*, console_driver_t*);
|
||||
|
||||
// The next filter in the filter chain
|
||||
struct console_filter* next;
|
||||
};
|
||||
|
||||
typedef struct console_filter console_filter_t;
|
||||
|
||||
44
samples/C/info.h
Normal file
44
samples/C/info.h
Normal file
@@ -0,0 +1,44 @@
|
||||
#pragma once
|
||||
|
||||
/* Copyright © 2011 Fritz Grimpen
|
||||
*
|
||||
* This file is part of Xelix.
|
||||
*
|
||||
* Xelix is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Xelix is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Xelix. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <lib/generic.h>
|
||||
#include <console/color.h>
|
||||
|
||||
typedef struct {
|
||||
uint32_t cursor_x;
|
||||
uint32_t cursor_y;
|
||||
|
||||
uint32_t rows;
|
||||
uint32_t columns;
|
||||
|
||||
uint32_t tabstop;
|
||||
|
||||
console_color_t default_color;
|
||||
console_color_t current_color;
|
||||
|
||||
uint8_t nonblocking;
|
||||
uint8_t reverse_video;
|
||||
uint8_t bold;
|
||||
uint8_t blink;
|
||||
uint8_t underline;
|
||||
uint8_t newline_mode;
|
||||
uint8_t auto_echo;
|
||||
uint8_t handle_backspace;
|
||||
} console_info_t;
|
||||
47
samples/C/interface.h
Normal file
47
samples/C/interface.h
Normal file
@@ -0,0 +1,47 @@
|
||||
#pragma once
|
||||
|
||||
/* Copyright © 2011 Fritz Grimpen
|
||||
*
|
||||
* This file is part of Xelix.
|
||||
*
|
||||
* Xelix is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Xelix is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Xelix. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <lib/generic.h>
|
||||
#include <console/info.h>
|
||||
#include <console/filter.h>
|
||||
#include <console/driver.h>
|
||||
|
||||
typedef struct {
|
||||
console_info_t info;
|
||||
|
||||
console_filter_t* input_filter;
|
||||
console_filter_t* output_filter;
|
||||
|
||||
console_driver_t* input_driver;
|
||||
console_driver_t* output_driver;
|
||||
} console_t;
|
||||
|
||||
console_t* default_console;
|
||||
|
||||
// Generate raw console, connected to the Display, Keyboard and the
|
||||
// ECMA-48-Filter
|
||||
void console_init();
|
||||
|
||||
size_t console_write(console_t* console, const char* buffer, int32_t length);
|
||||
#define console_write2(console, buffer) console_write(console, buffer, strlen(buffer))
|
||||
size_t console_read(console_t* console, char* buffer, size_t length);
|
||||
size_t console_scroll(console_t* console, int32_t pages);
|
||||
|
||||
void console_clear(console_t* console);
|
||||
50
samples/C/ip4.h
Normal file
50
samples/C/ip4.h
Normal file
@@ -0,0 +1,50 @@
|
||||
#pragma once
|
||||
|
||||
/* Copyright © 2011 Lukas Martini
|
||||
*
|
||||
* This file is part of Xelix.
|
||||
*
|
||||
* Xelix is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Xelix is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Xelix. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <lib/generic.h>
|
||||
#include <net/net.h>
|
||||
|
||||
#define IP4_TOS_ICMP 0
|
||||
|
||||
typedef uint32_t ip4_addr_t;
|
||||
|
||||
typedef struct {
|
||||
unsigned int hl:4; /* both fields are 4 bits */
|
||||
unsigned int version:4;
|
||||
uint8_t tos;
|
||||
uint16_t len;
|
||||
uint16_t id;
|
||||
uint16_t off;
|
||||
uint8_t ttl;
|
||||
uint8_t p;
|
||||
uint16_t checksum;
|
||||
ip4_addr_t src;
|
||||
ip4_addr_t dst;
|
||||
} ip4_header_t;
|
||||
|
||||
typedef struct {
|
||||
uint8_t type;
|
||||
uint8_t code;
|
||||
uint16_t checksum;
|
||||
uint16_t id;
|
||||
uint16_t sequence;
|
||||
} ip4_icmp_header_t;
|
||||
|
||||
void ip4_receive(net_device_t* origin, net_l2proto_t proto, size_t size, void* raw);
|
||||
110
samples/C/multiboot.h
Normal file
110
samples/C/multiboot.h
Normal file
@@ -0,0 +1,110 @@
|
||||
#pragma once
|
||||
|
||||
/* Copyright © 2010, 2011 Lukas Martini
|
||||
*
|
||||
* This file is part of Xelix.
|
||||
*
|
||||
* Xelix is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Xelix is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Xelix. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <lib/generic.h>
|
||||
|
||||
#define MULTIBOOT_KERNELMAGIC 0x2BADB002
|
||||
|
||||
#define MULTIBOOT_FLAG_MEM 0x001
|
||||
#define MULTIBOOT_FLAG_DEVICE 0x002
|
||||
#define MULTIBOOT_FLAG_CMDLINE 0x004
|
||||
#define MULTIBOOT_FLAG_MODS 0x008
|
||||
#define MULTIBOOT_FLAG_AOUT 0x010
|
||||
#define MULTIBOOT_FLAG_ELF 0x020
|
||||
#define MULTIBOOT_FLAG_MMAP 0x040
|
||||
#define MULTIBOOT_FLAG_CONFIG 0x080
|
||||
#define MULTIBOOT_FLAG_LOADER 0x100
|
||||
#define MULTIBOOT_FLAG_APM 0x200
|
||||
#define MULTIBOOT_FLAG_VBE 0x400
|
||||
|
||||
// The symbol table for a.out.
|
||||
typedef struct
|
||||
{
|
||||
uint32_t tabSize;
|
||||
uint32_t strSize;
|
||||
uint32_t addr;
|
||||
uint32_t reserved;
|
||||
} __attribute__((packed)) multiboot_aoutSymbolTable_t;
|
||||
|
||||
// The section header table for ELF.
|
||||
typedef struct
|
||||
{
|
||||
uint32_t num;
|
||||
uint32_t size;
|
||||
uint32_t addr;
|
||||
uint32_t shndx;
|
||||
} __attribute__((packed)) multiboot_elfSectionHeaderTable_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint32_t size;
|
||||
uint64_t addr;
|
||||
uint64_t length;
|
||||
uint32_t type;
|
||||
} __attribute__((packed)) multiboot_memoryMap_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint32_t start;
|
||||
uint32_t end;
|
||||
char* cmdLine;
|
||||
uint32_t reserved;
|
||||
} __attribute__((packed)) multiboot_module_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint32_t flags;
|
||||
uint32_t memLower;
|
||||
uint32_t memUpper;
|
||||
uint32_t bootDevice;
|
||||
char* cmdLine;
|
||||
uint32_t modsCount;
|
||||
multiboot_module_t* modsAddr;
|
||||
|
||||
union
|
||||
{
|
||||
multiboot_aoutSymbolTable_t aoutSym;
|
||||
multiboot_elfSectionHeaderTable_t elfSec;
|
||||
} u;
|
||||
|
||||
uint32_t mmapLength;
|
||||
uint32_t mmapAddr;
|
||||
|
||||
uint32_t drivesLength;
|
||||
uint32_t drivesAddr;
|
||||
|
||||
// ROM configuration table
|
||||
uint32_t configTable;
|
||||
|
||||
char* bootLoaderName;
|
||||
uint32_t apmTable;
|
||||
|
||||
// Video
|
||||
uint32_t vbeControlInfo;
|
||||
uint32_t vbeModeInfo;
|
||||
uint16_t vbeMode;
|
||||
uint16_t vbeInterfaceSeg;
|
||||
uint16_t vbeInterfaceOff;
|
||||
uint16_t vbeInterfaceLen;
|
||||
} __attribute__((packed)) multiboot_info_t;
|
||||
|
||||
multiboot_info_t* multiboot_info;
|
||||
|
||||
void arch_multiboot_printInfo();
|
||||
89
samples/C/ntru_encrypt.h
Normal file
89
samples/C/ntru_encrypt.h
Normal file
@@ -0,0 +1,89 @@
|
||||
/*
|
||||
* Copyright (C) 2014 FH Bielefeld
|
||||
*
|
||||
* This file is part of a FH Bielefeld project.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
* MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file ntru_encrypt.h
|
||||
* Header for the internal API of ntru_encrypt.c.
|
||||
* @brief header for encrypt.c
|
||||
*/
|
||||
|
||||
#ifndef PQC_ENCRYPT_H
|
||||
#define PQC_ENCRYPT_H
|
||||
|
||||
|
||||
#include "ntru_params.h"
|
||||
#include "ntru_poly.h"
|
||||
#include "ntru_string.h"
|
||||
|
||||
#include <fmpz_poly.h>
|
||||
#include <fmpz.h>
|
||||
|
||||
|
||||
/**
|
||||
* encrypt the msg, using the math:
|
||||
* e = (h ∗ r) + m (mod q)
|
||||
*
|
||||
* e = the encrypted poly
|
||||
*
|
||||
* h = the public key
|
||||
*
|
||||
* r = the random poly
|
||||
*
|
||||
* m = the message poly
|
||||
*
|
||||
* q = large mod
|
||||
*
|
||||
* @param msg_tern the message to encrypt, in ternary format
|
||||
* @param pub_key the public key
|
||||
* @param rnd the random poly (should have relatively small
|
||||
* coefficients, but not restricted to {-1, 0, 1})
|
||||
* @param out the output poly which is in the range {0, q-1}
|
||||
* (not ternary!) [out]
|
||||
* @param params ntru_params the ntru context
|
||||
*/
|
||||
void
|
||||
ntru_encrypt_poly(
|
||||
const fmpz_poly_t msg_tern,
|
||||
const fmpz_poly_t pub_key,
|
||||
const fmpz_poly_t rnd,
|
||||
fmpz_poly_t out,
|
||||
const ntru_params *params);
|
||||
|
||||
/**
|
||||
* Encrypt a message in the form of a null-terminated char array and
|
||||
* return a string.
|
||||
*
|
||||
* @param msg the message
|
||||
* @param pub_key the public key
|
||||
* @param rnd the random poly (should have relatively small
|
||||
* coefficients, but not restricted to {-1, 0, 1})
|
||||
* @param params ntru_params the ntru context
|
||||
* @return the newly allocated encrypted string
|
||||
*/
|
||||
string *
|
||||
ntru_encrypt_string(
|
||||
const string *msg,
|
||||
const fmpz_poly_t pub_key,
|
||||
const fmpz_poly_t rnd,
|
||||
const ntru_params *params);
|
||||
|
||||
|
||||
#endif /* PQC_ENCRYPT_H */
|
||||
43
samples/C/portio.h
Normal file
43
samples/C/portio.h
Normal file
@@ -0,0 +1,43 @@
|
||||
#pragma once
|
||||
|
||||
/* Copyright © 2011 Lukas Martini
|
||||
*
|
||||
* This file is part of Xelix.
|
||||
*
|
||||
* Xelix is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Xelix is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Xelix. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <lib/generic.h>
|
||||
#include <lib/stdint.h>
|
||||
|
||||
// Legacy
|
||||
#define outb(args...) portio_out8(args)
|
||||
#define outw(args...) portio_out16(args)
|
||||
#define outl(args...) portio_out32(args)
|
||||
#define outq(args...) portio_out64(args)
|
||||
|
||||
#define inb(args...) portio_in8(args)
|
||||
#define inw(args...) portio_in16(args)
|
||||
#define inl(args...) portio_in32(args)
|
||||
#define inq(args...) portio_in64(args)
|
||||
|
||||
void portio_out8(uint16_t port, uint8_t value);
|
||||
void portio_out16(uint16_t port, uint16_t value);
|
||||
void portio_out32(uint16_t port, uint32_t value);
|
||||
void portio_out64(uint16_t port, uint64_t value);
|
||||
|
||||
uint8_t portio_in8(uint16_t port);
|
||||
uint16_t portio_in16(uint16_t port);
|
||||
uint32_t portio_in32(uint16_t port);
|
||||
uint64_t portio_in64(uint16_t port);
|
||||
69
samples/C/scheduler.h
Normal file
69
samples/C/scheduler.h
Normal file
@@ -0,0 +1,69 @@
|
||||
#pragma once
|
||||
|
||||
/* Copyright © 2011 Lukas Martini
|
||||
*
|
||||
* This file is part of Xelix.
|
||||
*
|
||||
* Xelix is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Xelix is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Xelix. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <lib/generic.h>
|
||||
#include <hw/cpu.h>
|
||||
#include <memory/vmem.h>
|
||||
|
||||
#define SCHEDULER_MAXNAME 256
|
||||
#define SCHEDULER_TASK_PATH_MAX 256
|
||||
|
||||
// Single linked list
|
||||
typedef struct task {
|
||||
uint32_t pid;
|
||||
char name[SCHEDULER_MAXNAME];
|
||||
struct task *parent;
|
||||
cpu_state_t* state;
|
||||
struct task* next;
|
||||
struct task* previous;
|
||||
|
||||
void* stack;
|
||||
void* entry;
|
||||
struct vmem_context *memory_context;
|
||||
|
||||
// Current task state
|
||||
enum {
|
||||
TASK_STATE_KILLED,
|
||||
TASK_STATE_TERMINATED,
|
||||
TASK_STATE_BLOCKING,
|
||||
TASK_STATE_STOPPED,
|
||||
TASK_STATE_RUNNING
|
||||
} task_state;
|
||||
|
||||
char** environ;
|
||||
char** argv;
|
||||
int argc;
|
||||
|
||||
// TODO Is this actually the same as PATH_MAX in our toolchain?
|
||||
char cwd[SCHEDULER_TASK_PATH_MAX + 1];
|
||||
} task_t;
|
||||
|
||||
int scheduler_state;
|
||||
|
||||
task_t* scheduler_new(void* entry, task_t* parent, char name[SCHEDULER_MAXNAME],
|
||||
char** environ, char** argv, int argc, struct vmem_context* memory_context, bool map_structs);
|
||||
void scheduler_add(task_t *task);
|
||||
void scheduler_terminate_current();
|
||||
task_t* scheduler_get_current();
|
||||
task_t* scheduler_select(cpu_state_t* lastRegs);
|
||||
void scheduler_init();
|
||||
void scheduler_yield();
|
||||
void scheduler_remove(task_t *t);
|
||||
task_t* scheduler_fork(task_t* to_fork, cpu_state_t* state);
|
||||
95
samples/C/syscalls.h
Normal file
95
samples/C/syscalls.h
Normal file
@@ -0,0 +1,95 @@
|
||||
#pragma once
|
||||
|
||||
/* Copyright © 2011 Fritz Grimpen
|
||||
*
|
||||
* This file is part of Xelix.
|
||||
*
|
||||
* Xelix is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Xelix is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Xelix. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <lib/generic.h>
|
||||
#include <tasks/syscall.h>
|
||||
|
||||
#include "syscalls/write.h"
|
||||
#include "syscalls/exit.h"
|
||||
#include "syscalls/getpid.h"
|
||||
#include "syscalls/getppid.h"
|
||||
#include "syscalls/read.h"
|
||||
#include "syscalls/brk.h"
|
||||
#include "syscalls/mmap.h"
|
||||
#include "syscalls/munmap.h"
|
||||
#include "syscalls/test.h"
|
||||
#include "syscalls/hostname.h"
|
||||
#include "syscalls/uname.h"
|
||||
#include "syscalls/open.h"
|
||||
#include "syscalls/execve.h"
|
||||
#include "syscalls/seek.h"
|
||||
#include "syscalls/opendir.h"
|
||||
#include "syscalls/readdir.h"
|
||||
#include "syscalls/kill.h"
|
||||
#include "syscalls/getexecdata.h"
|
||||
#include "syscalls/cwd.h"
|
||||
#include "syscalls/fork.h"
|
||||
|
||||
syscall_t syscall_table[] = {
|
||||
NULL,
|
||||
sys_exit, // 1
|
||||
sys_read, // 2
|
||||
sys_write, // 3
|
||||
sys_getpid, // 4
|
||||
sys_brk, // 5
|
||||
sys_getppid, // 6
|
||||
sys_mmap, // 7
|
||||
sys_munmap, // 8
|
||||
sys_test, // 9
|
||||
sys_get_hostname, // 10
|
||||
sys_set_hostname, // 11
|
||||
sys_uname, // 12
|
||||
sys_open, // 13
|
||||
sys_execve, // 14
|
||||
sys_seek, // 15
|
||||
sys_opendir, // 16
|
||||
sys_readdir, // 17
|
||||
sys_kill, // 18
|
||||
sys_getexecdata, // 19
|
||||
sys_chdir, // 20
|
||||
sys_getcwd, // 21
|
||||
sys_fork, // 22
|
||||
};
|
||||
|
||||
char* syscall_name_table[] = {
|
||||
NULL,
|
||||
"exit", // 1
|
||||
"read", // 2
|
||||
"write", // 3
|
||||
"getpid", // 4
|
||||
"brk", // 5
|
||||
"getppid", // 6
|
||||
"mmap", // 7
|
||||
"munmap", // 8
|
||||
"test", // 9
|
||||
"get_hostname", // 10
|
||||
"set_hostname", // 11
|
||||
"uname", // 12
|
||||
"open", // 13
|
||||
"execve", // 14
|
||||
"seek", // 15
|
||||
"opendir", // 16
|
||||
"readdir", // 17
|
||||
"kill", // 18
|
||||
"getexecdata", // 19
|
||||
"chdir", // 20
|
||||
"getcwd", // 21
|
||||
"fork", // 22
|
||||
};
|
||||
56
samples/C/vfs.h
Normal file
56
samples/C/vfs.h
Normal file
@@ -0,0 +1,56 @@
|
||||
#pragma once
|
||||
|
||||
/* Copyright © 2010, 2011 Lukas Martini
|
||||
*
|
||||
* This file is part of Xelix.
|
||||
*
|
||||
* Xelix is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Xelix is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Xelix. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <lib/generic.h>
|
||||
|
||||
#define VFS_SEEK_SET 0
|
||||
#define VFS_SEEK_CUR 1
|
||||
#define VFS_SEEK_END 2
|
||||
|
||||
typedef struct {
|
||||
uint64_t num;
|
||||
char path[512];
|
||||
char mount_path[512];
|
||||
uint32_t offset;
|
||||
uint32_t mountpoint;
|
||||
} vfs_file_t;
|
||||
|
||||
typedef struct {
|
||||
uint64_t num;
|
||||
char path[512];
|
||||
char mount_path[512];
|
||||
uint32_t mountpoint;
|
||||
} vfs_dir_t;
|
||||
|
||||
typedef void* (*vfs_read_callback_t)(char* path, uint32_t offset, uint32_t size);
|
||||
typedef char* (*vfs_read_dir_callback_t)(char* path, uint32_t offset);
|
||||
|
||||
|
||||
// Used to always store the last read/write attempt (used for kernel panic debugging)
|
||||
char vfs_last_read_attempt[512];
|
||||
|
||||
vfs_file_t* vfs_get_from_id(uint32_t id);
|
||||
vfs_dir_t* vfs_get_dir_from_id(uint32_t id);
|
||||
void* vfs_read(vfs_file_t* fp, uint32_t size);
|
||||
char* vfs_dir_read(vfs_dir_t* dir, uint32_t offset);
|
||||
void vfs_seek(vfs_file_t* fp, uint32_t offset, int origin);
|
||||
vfs_file_t* vfs_open(char* path);
|
||||
vfs_dir_t* vfs_dir_open(char* path);
|
||||
int vfs_mount(char* path, vfs_read_callback_t read_callback, vfs_read_dir_callback_t read_dir_callback);
|
||||
94
samples/C/vmem.h
Normal file
94
samples/C/vmem.h
Normal file
@@ -0,0 +1,94 @@
|
||||
#pragma once
|
||||
|
||||
/* Copyright © 2011 Fritz Grimpen
|
||||
* Copyright © 2013 Lukas Martini
|
||||
*
|
||||
* This file is part of Xelix.
|
||||
*
|
||||
* Xelix is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Xelix is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Xelix. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <lib/generic.h>
|
||||
|
||||
struct vmem_context;
|
||||
|
||||
struct vmem_page
|
||||
{
|
||||
enum
|
||||
{
|
||||
VMEM_SECTION_STACK, /* Initial stack */
|
||||
VMEM_SECTION_CODE, /* Contains program code and is read-only */
|
||||
VMEM_SECTION_DATA, /* Contains static data */
|
||||
VMEM_SECTION_HEAP, /* Allocated by brk(2) at runtime */
|
||||
VMEM_SECTION_MMAP, /* Allocated by mmap(2) at runtime */
|
||||
VMEM_SECTION_KERNEL, /* Contains kernel-internal data */
|
||||
VMEM_SECTION_UNMAPPED /* Unmapped */
|
||||
} section;
|
||||
|
||||
bool readonly:1;
|
||||
bool cow:1; /* Copy-on-Write mechanism */
|
||||
bool allocated:1;
|
||||
|
||||
void *cow_src_addr;
|
||||
void *virt_addr;
|
||||
void *phys_addr;
|
||||
};
|
||||
|
||||
typedef void (*vmem_iterator_t)(struct vmem_context *, struct vmem_page *, uint32_t);
|
||||
|
||||
/* Initialize vmem_kernelContext for paging_init() */
|
||||
void vmem_init();
|
||||
struct vmem_context *vmem_kernelContext;
|
||||
struct vmem_context *vmem_currentContext;
|
||||
struct vmem_context *vmem_processContext;
|
||||
void *vmem_faultAddress;
|
||||
|
||||
/* Some callbacks for magic functions */
|
||||
void (*vmem_applyPage)(struct vmem_context *, struct vmem_page *);
|
||||
|
||||
/* Generate new page context */
|
||||
struct vmem_context *vmem_new();
|
||||
struct vmem_page *vmem_new_page();
|
||||
|
||||
int vmem_add_page(struct vmem_context *ctx, struct vmem_page *pg);
|
||||
|
||||
struct vmem_page *vmem_get_page_phys(struct vmem_context *ctx, void *phys_addr);
|
||||
struct vmem_page *vmem_get_page_virt(struct vmem_context *ctx, void *virt_addr);
|
||||
struct vmem_page *vmem_get_page(struct vmem_context *ctx, uint32_t offset);
|
||||
|
||||
/* Remove pages in a specific context by physical or virtual address */
|
||||
struct vmem_page *vmem_rm_page_phys(struct vmem_context *ctx, void *phys_addr);
|
||||
struct vmem_page *vmem_rm_page_virt(struct vmem_context *ctx, void *virt_addr);
|
||||
|
||||
/* Iterator */
|
||||
int vmem_iterate(struct vmem_context *ctx, vmem_iterator_t callback);
|
||||
|
||||
uint32_t vmem_count_pages(struct vmem_context *ctx);
|
||||
void vmem_dump_page(struct vmem_page *pg);
|
||||
void vmem_dump(struct vmem_context *ctx);
|
||||
void vmem_handle_fault(uint32_t code, void *addr, void *instruction);
|
||||
|
||||
/* Get/Set cached paging context */
|
||||
void vmem_set_cache(struct vmem_context *ctx, void *cache);
|
||||
void *vmem_get_cache(struct vmem_context *ctx);
|
||||
|
||||
#ifdef __i386__
|
||||
#define PAGE_SIZE 4096
|
||||
#define VMEM_ALIGN(x) (typeof(x))(((intptr_t)(x) & 0xFFFFF000) + 0x1000)
|
||||
#define VMEM_ALIGN_DOWN(x) (typeof(x))( \
|
||||
((intptr_t)(x) - ((intptr_t)(x) % PAGE_SIZE)))
|
||||
#else
|
||||
#define PAGE_SIZE 0
|
||||
#define VMEM_ALIGN(x) (x)
|
||||
#endif
|
||||
12
samples/CMake/filenames/CMakeLists.txt
Normal file
12
samples/CMake/filenames/CMakeLists.txt
Normal file
@@ -0,0 +1,12 @@
|
||||
cmake_minimum_required(VERSION 2.8)
|
||||
|
||||
project(Foo)
|
||||
|
||||
set(CMAKE_SKIP_RPATH TRUE)
|
||||
set(CMAKE_INSTALL_PREFIX "/usr/local")
|
||||
|
||||
add_subdirectory(bar)
|
||||
|
||||
add_executable(foo foo.c)
|
||||
target_link_libraries(foo pthread)
|
||||
install(TARGETS foo DESTINATION bin)
|
||||
1879
samples/CartoCSS/amenity-points.mss
Normal file
1879
samples/CartoCSS/amenity-points.mss
Normal file
File diff suppressed because it is too large
Load Diff
40
samples/CoffeeScript/example.cjsx
Normal file
40
samples/CoffeeScript/example.cjsx
Normal file
@@ -0,0 +1,40 @@
|
||||
###* @cjsx React.DOM ###
|
||||
define 'myProject.ReactExampleComponent', [
|
||||
'React'
|
||||
'myProject.ExampleStore'
|
||||
'myProject.ExampleActions'
|
||||
'myProject.ReactExampleTable'
|
||||
], (React, ExampleStore, ExampleActions, ReactExampleTable ) ->
|
||||
|
||||
ReactExampleComponent = React.createClass
|
||||
mixins: [ListenMixin]
|
||||
|
||||
getInitialState: ->
|
||||
rows: ExampleStore.getRows()
|
||||
meta: ExampleStore.getMeta()
|
||||
|
||||
componentWillMount: ->
|
||||
@listenTo ExampleStore
|
||||
|
||||
componentDidMount: ->
|
||||
ExampleActions.getExampleData()
|
||||
|
||||
onStoreChange: ->
|
||||
if this.isMounted()
|
||||
@setState
|
||||
rows: ExampleStore.getRows()
|
||||
meta: ExampleStore.getMeta()
|
||||
|
||||
componentWillUnmount: ->
|
||||
@stopListening ExampleStore
|
||||
|
||||
render: ->
|
||||
<div className="page-wrap">
|
||||
<header>
|
||||
<strong> {@state.title} </strong>
|
||||
<header>
|
||||
<ReactExampleTable
|
||||
rows={@state.rows},
|
||||
meta={@state.meta}
|
||||
/>
|
||||
</div>
|
||||
26
samples/Cool/list.cl
Normal file
26
samples/Cool/list.cl
Normal file
@@ -0,0 +1,26 @@
|
||||
(* This simple example of a list class is adapted from an example in the
|
||||
Cool distribution. *)
|
||||
|
||||
class List {
|
||||
isNil() : Bool { true };
|
||||
head() : Int { { abort(); 0; } };
|
||||
tail() : List { { abort(); self; } };
|
||||
cons(i : Int) : List {
|
||||
(new Cons).init(i, self)
|
||||
};
|
||||
};
|
||||
|
||||
class Cons inherits List {
|
||||
car : Int; -- The element in this list cell
|
||||
cdr : List; -- The rest of the list
|
||||
isNil() : Bool { false };
|
||||
head() : Int { car };
|
||||
tail() : List { cdr };
|
||||
init(i : Int, rest : List) : List {
|
||||
{
|
||||
car <- i;
|
||||
cdr <- rest;
|
||||
self;
|
||||
}
|
||||
};
|
||||
};
|
||||
71
samples/Cool/sample.cl
Normal file
71
samples/Cool/sample.cl
Normal file
@@ -0,0 +1,71 @@
|
||||
(* Refer to Alex Aiken, "The Cool Reference Manual":
|
||||
http://theory.stanford.edu/~aiken/software/cool/cool-manual.pdf
|
||||
for language specification.
|
||||
*)
|
||||
|
||||
-- Exhibit various language constructs
|
||||
class Sample {
|
||||
testCondition(x: Int): Bool {
|
||||
if x = 0
|
||||
then false
|
||||
else
|
||||
if x < (1 + 2) * 3
|
||||
then true
|
||||
else false
|
||||
fi
|
||||
fi
|
||||
};
|
||||
|
||||
testLoop(y: Int): Bool {
|
||||
while y > 0 loop
|
||||
{
|
||||
if not condition(y)
|
||||
then y <- y / 2
|
||||
else y <- y - 1;
|
||||
}
|
||||
pool
|
||||
};
|
||||
|
||||
testAssign(z: Int): Bool {
|
||||
i : Int;
|
||||
i <- ~z;
|
||||
};
|
||||
|
||||
testCase(var: Sample): SELF_TYPE {
|
||||
io : IO <- new IO;
|
||||
case var of
|
||||
a : A => io.out_string("Class type is A\n");
|
||||
b : B => io.out_string("Class type is B\n");
|
||||
s : Sample => io.out_string("Class type is Sample\n");
|
||||
o : Object => io.out_string("Class type is object\n");
|
||||
esac
|
||||
};
|
||||
|
||||
testLet(i: Int): Int {
|
||||
let (a: Int in
|
||||
let(b: Int <- 3, c: Int <- 4 in
|
||||
{
|
||||
a <- 2;
|
||||
a * b * 2 / c;
|
||||
}
|
||||
)
|
||||
)
|
||||
};
|
||||
};
|
||||
|
||||
-- Used to test subclasses
|
||||
class A inherits Sample {};
|
||||
class B inherits A {};
|
||||
|
||||
class C {
|
||||
main() : Int {
|
||||
(new Sample).testLet(1)
|
||||
};
|
||||
};
|
||||
|
||||
-- "Hello, world" example
|
||||
class Main inherits IO {
|
||||
main(): SELF_TYPE {
|
||||
out_string("Hello, World.\n")
|
||||
};
|
||||
};
|
||||
49
samples/F#/Combinators.fs
Normal file
49
samples/F#/Combinators.fs
Normal file
@@ -0,0 +1,49 @@
|
||||
namespace Nessos.FsPickler.Combinators
|
||||
|
||||
open Nessos.FsPickler
|
||||
open Nessos.FsPickler.Json
|
||||
|
||||
/// Json pickling methods
|
||||
[<RequireQualifiedAccess>]
|
||||
module Json =
|
||||
|
||||
let private jsonSerializer = lazy(FsPickler.CreateJson(omitHeader = true))
|
||||
|
||||
/// <summary>
|
||||
/// Pickles a value to Json.
|
||||
/// </summary>
|
||||
/// <param name="pickler">utilized pickler.</param>
|
||||
/// <param name="value">input value.</param>
|
||||
let pickle (pickler : Pickler<'T>) (value : 'T) : string =
|
||||
jsonSerializer.Value.PickleToString (pickler, value)
|
||||
|
||||
/// <summary>
|
||||
/// Unpickles a value from Json.
|
||||
/// </summary>
|
||||
/// <param name="pickler">utilized pickler.</param>
|
||||
/// <param name="pickle">input pickle.</param>
|
||||
let unpickle (pickler : Pickler<'T>) (pickle : string) : 'T =
|
||||
jsonSerializer.Value.UnPickleOfString (pickler, pickle)
|
||||
|
||||
|
||||
/// Bson pickling methods
|
||||
[<RequireQualifiedAccess>]
|
||||
module Bson =
|
||||
|
||||
let private bsonPickler = lazy(FsPickler.CreateBson())
|
||||
|
||||
/// <summary>
|
||||
/// Pickles a value to Bson.
|
||||
/// </summary>
|
||||
/// <param name="pickler">utilized pickler.</param>
|
||||
/// <param name="value">input value.</param>
|
||||
let pickle (pickler : Pickler<'T>) (value : 'T) : byte [] =
|
||||
bsonPickler.Value.Pickle (pickler, value)
|
||||
|
||||
/// <summary>
|
||||
/// Unpickles a value from bson.
|
||||
/// </summary>
|
||||
/// <param name="pickler">utilized pickler.</param>
|
||||
/// <param name="pickle">input pickle.</param>
|
||||
let unpickle (pickler : Pickler<'T>) (pickle : byte []) : 'T =
|
||||
bsonPickler.Value.UnPickle (pickler, pickle)
|
||||
65
samples/F#/JsonFormat.fs
Normal file
65
samples/F#/JsonFormat.fs
Normal file
@@ -0,0 +1,65 @@
|
||||
namespace Nessos.FsPickler.Json
|
||||
|
||||
open System
|
||||
open System.IO
|
||||
open System.Text
|
||||
|
||||
open Newtonsoft.Json
|
||||
|
||||
open Nessos.FsPickler
|
||||
|
||||
/// <summary>
|
||||
/// Factory methods for the Json serialization format.
|
||||
/// </summary>
|
||||
type JsonPickleFormatProvider internal (indent, omitHeader) as self =
|
||||
|
||||
let isCustomSeq isTopLevelSequence =
|
||||
isTopLevelSequence && self.OmitHeader && self.UseCustomTopLevelSequenceSeparator
|
||||
|
||||
let mutable sequenceSeparator = " "
|
||||
|
||||
member val Indent = indent with get,set
|
||||
member val OmitHeader = omitHeader with get,set
|
||||
member val UseCustomTopLevelSequenceSeparator = false with get,set
|
||||
|
||||
member __.SequenceSeparator
|
||||
with get () = sequenceSeparator
|
||||
and set sep =
|
||||
if sep <> null && String.IsNullOrWhiteSpace sep then
|
||||
sequenceSeparator <- sep
|
||||
else
|
||||
invalidArg "SequenceSeparator" "should be non-null whitespace."
|
||||
|
||||
interface ITextPickleFormatProvider with
|
||||
member __.Name = "Json"
|
||||
|
||||
// see discussion : https://github.com/nessos/FsPickler/issues/17
|
||||
member __.DefaultEncoding = new UTF8Encoding(false) :> Encoding
|
||||
|
||||
member __.CreateWriter (stream, encoding, isTopLevelSequence, leaveOpen) =
|
||||
#if NET40
|
||||
if leaveOpen then raise <| new NotSupportedException("'leaveOpen' not supported in .NET 40.")
|
||||
let sw = new StreamWriter(stream, encoding)
|
||||
#else
|
||||
let sw = new StreamWriter(stream, encoding, 1024, leaveOpen)
|
||||
#endif
|
||||
let jw = new JsonTextWriter(sw)
|
||||
new JsonPickleWriter(jw, __.OmitHeader, __.Indent, isCustomSeq isTopLevelSequence, sequenceSeparator, leaveOpen) :> _
|
||||
|
||||
member __.CreateReader (stream, encoding, isTopLevelSequence, leaveOpen) =
|
||||
#if NET40
|
||||
if leaveOpen then raise <| new NotSupportedException("'leaveOpen' not supported in .NET 40.")
|
||||
let sr = new StreamReader(stream, encoding)
|
||||
#else
|
||||
let sr = new StreamReader(stream, encoding, true, 1024, leaveOpen)
|
||||
#endif
|
||||
let jr = new JsonTextReader(sr)
|
||||
new JsonPickleReader(jr, __.OmitHeader, isCustomSeq isTopLevelSequence, leaveOpen) :> _
|
||||
|
||||
member __.CreateWriter (textWriter, isTopLevelSequence, leaveOpen) =
|
||||
let jw = new JsonTextWriter(textWriter)
|
||||
new JsonPickleWriter(jw, __.OmitHeader, __.Indent, isCustomSeq isTopLevelSequence, sequenceSeparator, leaveOpen) :> _
|
||||
|
||||
member __.CreateReader (textReader, isTopLevelSequence, leaveOpen) =
|
||||
let jr = new JsonTextReader(textReader)
|
||||
new JsonPickleReader(jr, __.OmitHeader, isCustomSeq isTopLevelSequence, leaveOpen) :> _
|
||||
202
samples/F#/JsonReader.fs
Normal file
202
samples/F#/JsonReader.fs
Normal file
@@ -0,0 +1,202 @@
|
||||
namespace Nessos.FsPickler.Json
|
||||
|
||||
open System
|
||||
open System.Collections.Generic
|
||||
open System.Globalization
|
||||
open System.IO
|
||||
open System.Numerics
|
||||
open System.Text
|
||||
|
||||
open Newtonsoft.Json
|
||||
|
||||
open Nessos.FsPickler
|
||||
|
||||
/// <summary>
|
||||
/// Json format deserializer
|
||||
/// </summary>
|
||||
type internal JsonPickleReader (jsonReader : JsonReader, omitHeader, isTopLevelSequence, leaveOpen) =
|
||||
|
||||
do
|
||||
jsonReader.CloseInput <- not leaveOpen
|
||||
jsonReader.SupportMultipleContent <- isTopLevelSequence
|
||||
|
||||
let isBsonReader = match jsonReader with :? Bson.BsonReader -> true | _ -> false
|
||||
|
||||
let mutable depth = 0
|
||||
let arrayStack = new Stack<int> ()
|
||||
do arrayStack.Push Int32.MinValue
|
||||
|
||||
// do not write tag if omitting header or array element
|
||||
let omitTag () = (omitHeader && depth = 0) || arrayStack.Peek() = depth - 1
|
||||
|
||||
interface IPickleFormatReader with
|
||||
|
||||
member __.BeginReadRoot (tag : string) =
|
||||
do jsonReader.Read() |> ignore
|
||||
|
||||
if omitHeader then () else
|
||||
|
||||
if jsonReader.TokenType <> JsonToken.StartObject then raise <| new FormatException("invalid json root object.")
|
||||
else
|
||||
do jsonReader.MoveNext()
|
||||
let version = jsonReader.ReadPrimitiveAs<string> false "FsPickler"
|
||||
if version <> jsonFormatVersion then
|
||||
let v = Version(version)
|
||||
raise <| new FormatException(sprintf "Invalid FsPickler format version %O." version)
|
||||
|
||||
let sTag = jsonReader.ReadPrimitiveAs<string> false "type"
|
||||
if tag <> sTag then
|
||||
raise <| new InvalidPickleTypeException(tag, sTag)
|
||||
|
||||
member __.EndReadRoot () =
|
||||
if not omitHeader then jsonReader.Read() |> ignore
|
||||
|
||||
member __.BeginReadObject (tag : string) =
|
||||
|
||||
if not <| omitTag () then
|
||||
jsonReader.ReadProperty tag
|
||||
jsonReader.MoveNext ()
|
||||
|
||||
if isTopLevelSequence && depth = 0 then
|
||||
arrayStack.Push depth
|
||||
depth <- depth + 1
|
||||
ObjectFlags.IsSequenceHeader
|
||||
|
||||
else
|
||||
match jsonReader.TokenType with
|
||||
| JsonToken.Null -> ObjectFlags.IsNull
|
||||
| JsonToken.StartArray ->
|
||||
jsonReader.MoveNext()
|
||||
arrayStack.Push depth
|
||||
depth <- depth + 1
|
||||
ObjectFlags.IsSequenceHeader
|
||||
|
||||
| JsonToken.StartObject ->
|
||||
do jsonReader.MoveNext()
|
||||
depth <- depth + 1
|
||||
|
||||
if jsonReader.ValueAs<string> () = "_flags" then
|
||||
jsonReader.MoveNext()
|
||||
let csvFlags = jsonReader.ValueAs<string>()
|
||||
jsonReader.MoveNext()
|
||||
parseFlagCsv csvFlags
|
||||
else
|
||||
ObjectFlags.None
|
||||
|
||||
| token -> raise <| new FormatException(sprintf "expected start of Json object but was '%O'." token)
|
||||
|
||||
|
||||
member __.EndReadObject () =
|
||||
if isTopLevelSequence && depth = 1 then
|
||||
arrayStack.Pop () |> ignore
|
||||
depth <- depth - 1
|
||||
jsonReader.Read() |> ignore
|
||||
else
|
||||
match jsonReader.TokenType with
|
||||
| JsonToken.Null -> ()
|
||||
| JsonToken.EndObject -> depth <- depth - 1
|
||||
| JsonToken.EndArray ->
|
||||
arrayStack.Pop() |> ignore
|
||||
depth <- depth - 1
|
||||
|
||||
| token -> raise <| new FormatException(sprintf "expected end of Json object but was '%O'." token)
|
||||
|
||||
if omitHeader && depth = 0 then ()
|
||||
else jsonReader.Read() |> ignore
|
||||
|
||||
member __.SerializeUnionCaseNames = true
|
||||
|
||||
member __.PreferLengthPrefixInSequences = false
|
||||
member __.ReadNextSequenceElement () =
|
||||
if isTopLevelSequence && depth = 1 then
|
||||
jsonReader.TokenType <> JsonToken.None
|
||||
else
|
||||
jsonReader.TokenType <> JsonToken.EndArray
|
||||
|
||||
member __.ReadCachedObjectId () = jsonReader.ReadPrimitiveAs<int64> false "id"
|
||||
|
||||
member __.ReadBoolean tag = jsonReader.ReadPrimitiveAs<bool> (omitTag ()) tag
|
||||
member __.ReadByte tag = jsonReader.ReadPrimitiveAs<int64> (omitTag ()) tag |> byte
|
||||
member __.ReadSByte tag = jsonReader.ReadPrimitiveAs<int64> (omitTag ()) tag |> sbyte
|
||||
|
||||
member __.ReadInt16 tag = jsonReader.ReadPrimitiveAs<int64> (omitTag ()) tag |> int16
|
||||
member __.ReadInt32 tag = jsonReader.ReadPrimitiveAs<int64> (omitTag ()) tag |> int
|
||||
member __.ReadInt64 tag = jsonReader.ReadPrimitiveAs<int64> (omitTag ()) tag
|
||||
|
||||
member __.ReadUInt16 tag = jsonReader.ReadPrimitiveAs<int64> (omitTag ()) tag |> uint16
|
||||
member __.ReadUInt32 tag = jsonReader.ReadPrimitiveAs<int64> (omitTag ()) tag |> uint32
|
||||
member __.ReadUInt64 tag = jsonReader.ReadPrimitiveAs<int64> (omitTag ()) tag |> uint64
|
||||
|
||||
member __.ReadSingle tag =
|
||||
if not <| omitTag () then
|
||||
jsonReader.ReadProperty tag
|
||||
jsonReader.MoveNext()
|
||||
|
||||
let value =
|
||||
match jsonReader.TokenType with
|
||||
| JsonToken.Float -> jsonReader.ValueAs<double> () |> single
|
||||
| JsonToken.String -> Single.Parse(jsonReader.ValueAs<string>(), CultureInfo.InvariantCulture)
|
||||
| _ -> raise <| new FormatException("not a float.")
|
||||
|
||||
jsonReader.Read() |> ignore
|
||||
value
|
||||
|
||||
member __.ReadDouble tag =
|
||||
if not <| omitTag () then
|
||||
jsonReader.ReadProperty tag
|
||||
jsonReader.MoveNext()
|
||||
|
||||
let value =
|
||||
match jsonReader.TokenType with
|
||||
| JsonToken.Float -> jsonReader.ValueAs<double> ()
|
||||
| JsonToken.String -> Double.Parse(jsonReader.ValueAs<string>(), CultureInfo.InvariantCulture)
|
||||
| _ -> raise <| new FormatException("not a float.")
|
||||
|
||||
jsonReader.Read() |> ignore
|
||||
value
|
||||
|
||||
member __.ReadChar tag = let value = jsonReader.ReadPrimitiveAs<string> (omitTag ()) tag in value.[0]
|
||||
member __.ReadString tag = jsonReader.ReadPrimitiveAs<string> (omitTag ()) tag
|
||||
member __.ReadBigInteger tag = jsonReader.ReadPrimitiveAs<string> (omitTag ()) tag |> BigInteger.Parse
|
||||
|
||||
member __.ReadGuid tag =
|
||||
if isBsonReader then
|
||||
jsonReader.ReadPrimitiveAs<Guid> (omitTag ()) tag
|
||||
else
|
||||
jsonReader.ReadPrimitiveAs<string> (omitTag ()) tag |> Guid.Parse
|
||||
|
||||
member __.ReadTimeSpan tag = jsonReader.ReadPrimitiveAs<string> (omitTag ()) tag |> TimeSpan.Parse
|
||||
member __.ReadDecimal tag = jsonReader.ReadPrimitiveAs<string> (omitTag ()) tag |> decimal
|
||||
|
||||
// BSON spec mandates the use of Unix time;
|
||||
// this has millisecond precision which results in loss of accuracy w.r.t. ticks
|
||||
// since the goal of FsPickler is to offer faithful representations of .NET objects
|
||||
// we choose to override the spec and serialize ticks outright.
|
||||
// see also https://json.codeplex.com/discussions/212067
|
||||
member __.ReadDate tag =
|
||||
if isBsonReader then
|
||||
let ticks = jsonReader.ReadPrimitiveAs<int64> (omitTag ()) tag
|
||||
DateTime(ticks)
|
||||
else
|
||||
jsonReader.ReadPrimitiveAs<DateTime> (omitTag ()) tag
|
||||
|
||||
member __.ReadBytes tag =
|
||||
if not <| omitTag () then
|
||||
jsonReader.ReadProperty tag
|
||||
jsonReader.Read() |> ignore
|
||||
|
||||
let bytes =
|
||||
if jsonReader.TokenType = JsonToken.Null then null
|
||||
elif isBsonReader then jsonReader.ValueAs<byte []> ()
|
||||
else
|
||||
let base64 = jsonReader.ValueAs<string> ()
|
||||
Convert.FromBase64String base64
|
||||
|
||||
jsonReader.Read() |> ignore
|
||||
|
||||
bytes
|
||||
|
||||
member __.IsPrimitiveArraySerializationSupported = false
|
||||
member __.ReadPrimitiveArray _ _ = raise <| new NotImplementedException()
|
||||
|
||||
member __.Dispose () = (jsonReader :> IDisposable).Dispose()
|
||||
85
samples/F#/JsonSerializer.fs
Normal file
85
samples/F#/JsonSerializer.fs
Normal file
@@ -0,0 +1,85 @@
|
||||
namespace Nessos.FsPickler.Json
|
||||
|
||||
open System
|
||||
|
||||
open Nessos.FsPickler
|
||||
|
||||
type internal OAttribute = System.Runtime.InteropServices.OptionalAttribute
|
||||
type internal DAttribute = System.Runtime.InteropServices.DefaultParameterValueAttribute
|
||||
|
||||
/// <summary>
|
||||
/// Json pickler instance.
|
||||
/// </summary>
|
||||
type JsonSerializer =
|
||||
inherit FsPicklerTextSerializer
|
||||
|
||||
val private format : JsonPickleFormatProvider
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new Json pickler instance.
|
||||
/// </summary>
|
||||
/// <param name="indent">indent out Json pickles.</param>
|
||||
/// <param name="omitHeader">omit FsPickler header in Json pickles.</param>
|
||||
/// <param name="typeConverter">specify a custom type name converter.</param>
|
||||
new ([<O;D(null)>] ?indent, [<O;D(null)>] ?omitHeader, [<O;D(null)>] ?typeConverter) =
|
||||
let indent = defaultArg indent false
|
||||
let omitHeader = defaultArg omitHeader false
|
||||
let json = new JsonPickleFormatProvider(indent, omitHeader)
|
||||
{
|
||||
inherit FsPicklerTextSerializer(json, ?typeConverter = typeConverter)
|
||||
format = json
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets whether Json output should be indented.
|
||||
/// </summary>
|
||||
member x.Indent
|
||||
with get () = x.format.Indent
|
||||
and set b = x.format.Indent <- b
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets whether FsPickler headers should be ignored in pickle format.
|
||||
/// </summary>
|
||||
member x.OmitHeader
|
||||
with get () = x.format.OmitHeader
|
||||
and set b = x.format.OmitHeader <- b
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a non-null whitespace string that serves as a custom, top-level sequence separator.
|
||||
/// </summary>
|
||||
member x.SequenceSeparator
|
||||
with get () = x.format.SequenceSeparator
|
||||
and set sep = x.format.SequenceSeparator <- sep
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets whether top-level sequences should be serialized using the custom separator.
|
||||
/// </summary>
|
||||
member x.UseCustomTopLevelSequenceSeparator
|
||||
with get () = x.format.UseCustomTopLevelSequenceSeparator
|
||||
and set e = x.format.UseCustomTopLevelSequenceSeparator <- e
|
||||
|
||||
/// <summary>
|
||||
/// BSON pickler instance.
|
||||
/// </summary>
|
||||
type BsonSerializer([<O;D(null)>] ?typeConverter) =
|
||||
inherit FsPicklerSerializer(new BsonPickleFormatProvider(), ?typeConverter = typeConverter)
|
||||
|
||||
|
||||
/// FsPickler static methods.
|
||||
type FsPickler =
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new Json pickler instance.
|
||||
/// </summary>
|
||||
/// <param name="indent">indent out Json pickles.</param>
|
||||
/// <param name="omitHeader">omit FsPickler header in Json pickles.</param>
|
||||
/// <param name="typeConverter">specify a custom type name converter.</param>
|
||||
static member CreateJson([<O;D(null)>] ?indent, [<O;D(null)>] ?omitHeader, [<O;D(null)>] ?typeConverter) =
|
||||
new JsonSerializer(?indent = indent, ?omitHeader = omitHeader, ?typeConverter = typeConverter)
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new Bson pickler instance.
|
||||
/// </summary>
|
||||
/// <param name="typeConverter">specify a custom type name converter.</param>
|
||||
static member CreateBson([<O;D(null)>] ?typeConverter) =
|
||||
new BsonSerializer(?typeConverter = typeConverter)
|
||||
142
samples/F#/JsonWriter.fs
Normal file
142
samples/F#/JsonWriter.fs
Normal file
@@ -0,0 +1,142 @@
|
||||
namespace Nessos.FsPickler.Json
|
||||
|
||||
open System
|
||||
open System.IO
|
||||
open System.Collections.Generic
|
||||
|
||||
open Newtonsoft.Json
|
||||
|
||||
open Nessos.FsPickler
|
||||
|
||||
/// <summary>
|
||||
/// Json format serializer.
|
||||
/// </summary>
|
||||
type internal JsonPickleWriter (jsonWriter : JsonWriter, omitHeader, indented, isTopLevelSequence, separator, leaveOpen) =
|
||||
|
||||
do
|
||||
jsonWriter.Formatting <- if indented then Formatting.Indented else Formatting.None
|
||||
jsonWriter.CloseOutput <- not leaveOpen
|
||||
|
||||
let isBsonWriter = match jsonWriter with :? Bson.BsonWriter -> true | _ -> false
|
||||
|
||||
let mutable depth = 0
|
||||
let mutable isTopLevelSequenceHead = false
|
||||
let mutable currentValueIsNull = false
|
||||
|
||||
let arrayStack = new Stack<int> ()
|
||||
do arrayStack.Push Int32.MinValue
|
||||
|
||||
// do not write tag if omitting header or array element
|
||||
let omitTag () = (omitHeader && depth = 0) || arrayStack.Peek() = depth - 1
|
||||
|
||||
interface IPickleFormatWriter with
|
||||
|
||||
member __.BeginWriteRoot (tag : string) =
|
||||
if omitHeader then () else
|
||||
|
||||
jsonWriter.WriteStartObject()
|
||||
writePrimitive jsonWriter false "FsPickler" jsonFormatVersion
|
||||
writePrimitive jsonWriter false "type" tag
|
||||
|
||||
member __.EndWriteRoot () =
|
||||
if not omitHeader then jsonWriter.WriteEnd()
|
||||
|
||||
member __.BeginWriteObject (tag : string) (flags : ObjectFlags) =
|
||||
|
||||
if not <| omitTag () then
|
||||
jsonWriter.WritePropertyName tag
|
||||
|
||||
if flags.HasFlag ObjectFlags.IsNull then
|
||||
currentValueIsNull <- true
|
||||
jsonWriter.WriteNull()
|
||||
|
||||
elif flags.HasFlag ObjectFlags.IsSequenceHeader then
|
||||
if isTopLevelSequence && depth = 0 then
|
||||
isTopLevelSequenceHead <- true
|
||||
else
|
||||
jsonWriter.WriteStartArray()
|
||||
|
||||
arrayStack.Push depth
|
||||
depth <- depth + 1
|
||||
else
|
||||
jsonWriter.WriteStartObject()
|
||||
depth <- depth + 1
|
||||
|
||||
if flags = ObjectFlags.None then ()
|
||||
else
|
||||
let flagCsv = mkFlagCsv flags
|
||||
writePrimitive jsonWriter false "_flags" flagCsv
|
||||
|
||||
member __.EndWriteObject () =
|
||||
if currentValueIsNull then
|
||||
currentValueIsNull <- false
|
||||
else
|
||||
depth <- depth - 1
|
||||
if arrayStack.Peek () = depth then
|
||||
if isTopLevelSequence && depth = 0 then ()
|
||||
else
|
||||
jsonWriter.WriteEndArray()
|
||||
|
||||
arrayStack.Pop () |> ignore
|
||||
else
|
||||
jsonWriter.WriteEndObject()
|
||||
|
||||
member __.SerializeUnionCaseNames = true
|
||||
|
||||
member __.PreferLengthPrefixInSequences = false
|
||||
member __.WriteNextSequenceElement hasNext =
|
||||
if isTopLevelSequence && depth = 1 then
|
||||
if isTopLevelSequenceHead then
|
||||
isTopLevelSequenceHead <- false
|
||||
else
|
||||
jsonWriter.WriteWhitespace separator
|
||||
|
||||
member __.WriteCachedObjectId id = writePrimitive jsonWriter false "id" id
|
||||
|
||||
member __.WriteBoolean (tag : string) value = writePrimitive jsonWriter (omitTag ()) tag value
|
||||
member __.WriteByte (tag : string) value = writePrimitive jsonWriter (omitTag ()) tag value
|
||||
member __.WriteSByte (tag : string) value = writePrimitive jsonWriter (omitTag ()) tag value
|
||||
|
||||
member __.WriteInt16 (tag : string) value = writePrimitive jsonWriter (omitTag ()) tag value
|
||||
member __.WriteInt32 (tag : string) value = writePrimitive jsonWriter (omitTag ()) tag value
|
||||
member __.WriteInt64 (tag : string) value = writePrimitive jsonWriter (omitTag ()) tag value
|
||||
|
||||
member __.WriteUInt16 (tag : string) value = writePrimitive jsonWriter (omitTag ()) tag value
|
||||
member __.WriteUInt32 (tag : string) value = writePrimitive jsonWriter (omitTag ()) tag value
|
||||
member __.WriteUInt64 (tag : string) value = writePrimitive jsonWriter (omitTag ()) tag value
|
||||
|
||||
member __.WriteSingle (tag : string) value = writePrimitive jsonWriter (omitTag ()) tag value
|
||||
member __.WriteDouble (tag : string) value = writePrimitive jsonWriter (omitTag ()) tag value
|
||||
member __.WriteDecimal (tag : string) value = writePrimitive jsonWriter (omitTag ()) tag (string value)
|
||||
|
||||
member __.WriteChar (tag : string) value = writePrimitive jsonWriter (omitTag ()) tag value
|
||||
member __.WriteString (tag : string) value = writePrimitive jsonWriter (omitTag ()) tag value
|
||||
member __.WriteBigInteger (tag : string) value = writePrimitive jsonWriter (omitTag ()) tag (string value)
|
||||
|
||||
member __.WriteGuid (tag : string) value = writePrimitive jsonWriter (omitTag ()) tag value
|
||||
member __.WriteTimeSpan (tag : string) value = writePrimitive jsonWriter (omitTag ()) tag (string value)
|
||||
|
||||
// BSON spec mandates the use of Unix time;
|
||||
// this has millisecond precision which results in loss of accuracy w.r.t. ticks
|
||||
// since the goal of FsPickler is to offer faithful representations of .NET objects
|
||||
// we choose to override the spec and serialize ticks outright.
|
||||
// see also https://json.codeplex.com/discussions/212067
|
||||
member __.WriteDate (tag : string) value =
|
||||
if isBsonWriter then
|
||||
writePrimitive jsonWriter (omitTag ()) tag value.Ticks
|
||||
else
|
||||
writePrimitive jsonWriter (omitTag ()) tag value
|
||||
|
||||
member __.WriteBytes (tag : string) (value : byte []) =
|
||||
if not <| omitTag () then
|
||||
jsonWriter.WritePropertyName tag
|
||||
|
||||
if obj.ReferenceEquals(value, null) then
|
||||
jsonWriter.WriteNull()
|
||||
else
|
||||
jsonWriter.WriteValue value
|
||||
|
||||
member __.IsPrimitiveArraySerializationSupported = false
|
||||
member __.WritePrimitiveArray _ _ = raise <| NotSupportedException()
|
||||
|
||||
member __.Dispose () = jsonWriter.Flush()
|
||||
68
samples/F#/PerformanceTesters.fs
Normal file
68
samples/F#/PerformanceTesters.fs
Normal file
@@ -0,0 +1,68 @@
|
||||
namespace Nessos.FsPickler.Tests
|
||||
|
||||
open PerfUtil
|
||||
open PerfUtil.NUnit
|
||||
|
||||
open NUnit.Framework
|
||||
|
||||
open Nessos.FsPickler
|
||||
open Nessos.FsPickler.Json
|
||||
|
||||
[<AbstractClass>]
|
||||
type PerfTester () =
|
||||
inherit NUnitPerf<Serializer> ()
|
||||
|
||||
let tests = PerfTest.OfModuleMarker<PerformanceTests.Marker> ()
|
||||
|
||||
override __.PerfTests = tests
|
||||
|
||||
|
||||
type ``Serializer Comparison`` () =
|
||||
inherit PerfTester()
|
||||
|
||||
let fsp = FsPickler.initBinary()
|
||||
let bfs = new BinaryFormatterSerializer() :> Serializer
|
||||
let ndc = new NetDataContractSerializer() :> Serializer
|
||||
let jdn = new JsonDotNetSerializer() :> Serializer
|
||||
let bdn = new JsonDotNetBsonSerializer () :> Serializer
|
||||
let pbn = new ProtoBufSerializer() :> Serializer
|
||||
let ssj = new ServiceStackJsonSerializer() :> Serializer
|
||||
let sst = new ServiceStackTypeSerializer() :> Serializer
|
||||
|
||||
let comparer = new WeightedComparer(spaceFactor = 0.2, leastAcceptableImprovementFactor = 1.)
|
||||
let tester = new ImplementationComparer<_>(fsp, [bfs;ndc;jdn;bdn;pbn;ssj;sst], throwOnError = true, warmup = true, comparer = comparer)
|
||||
|
||||
override __.PerfTester = tester :> _
|
||||
|
||||
|
||||
type ``FsPickler Formats Comparison`` () =
|
||||
inherit PerfTester ()
|
||||
|
||||
let binary = FsPickler.initBinary()
|
||||
let json = FsPickler.initJson()
|
||||
let bson = FsPickler.initBson()
|
||||
let xml = FsPickler.initXml()
|
||||
|
||||
let tester = new ImplementationComparer<_>(binary, [json ; bson; xml], warmup = true, throwOnError = false)
|
||||
|
||||
override __.PerfTester = tester :> _
|
||||
|
||||
|
||||
type ``Past FsPickler Versions Comparison`` () =
|
||||
inherit PerfTester ()
|
||||
|
||||
let persistResults = true
|
||||
let persistenceFile = "fspPerf.xml"
|
||||
|
||||
let fsp = FsPickler.initBinary()
|
||||
let version = typeof<FsPickler>.Assembly.GetName().Version
|
||||
let comparer = new WeightedComparer(spaceFactor = 0.2, leastAcceptableImprovementFactor = 0.8)
|
||||
let tester =
|
||||
new PastImplementationComparer<Serializer>(
|
||||
fsp, version, historyFile = persistenceFile, throwOnError = true, warmup = true, comparer = comparer)
|
||||
|
||||
override __.PerfTester = tester :> _
|
||||
|
||||
[<TestFixtureTearDown>]
|
||||
member __.Persist() =
|
||||
if persistResults then tester.PersistCurrentResults ()
|
||||
207
samples/F#/PerformanceTests.fs
Normal file
207
samples/F#/PerformanceTests.fs
Normal file
@@ -0,0 +1,207 @@
|
||||
namespace Nessos.FsPickler.Tests
|
||||
|
||||
open System
|
||||
open System.Collections.Generic
|
||||
|
||||
open PerfUtil
|
||||
|
||||
open Nessos.FsPickler
|
||||
open Nessos.FsPickler.Tests.Serializer
|
||||
open Nessos.FsPickler.Tests.TestTypes
|
||||
|
||||
module PerformanceTests =
|
||||
|
||||
type Marker = class end
|
||||
|
||||
let guid = Guid.NewGuid()
|
||||
|
||||
[<PerfTest(1000)>]
|
||||
let ``Value: Guid`` s = roundtrip guid s
|
||||
|
||||
let date = DateTime.Now
|
||||
|
||||
[<PerfTest(1000)>]
|
||||
let ``Value: DateTime`` s = roundtrip date s
|
||||
|
||||
[<PerfTest(10000)>]
|
||||
let ``Value: String`` s = roundtrip stringValue s
|
||||
|
||||
|
||||
let boxed = box ([| 1 .. 1000 |], "lorem ipsum")
|
||||
|
||||
[<PerfTest(1000)>]
|
||||
let ``Boxed Object`` s = roundtrip boxed s
|
||||
|
||||
let fsClass = new Class(42, stringValue)
|
||||
|
||||
[<PerfTest(10000)>]
|
||||
let ``Class: Simple F# Class`` s = roundtrip fsClass s
|
||||
|
||||
let serializableClass = new SerializableClass<_>(42, stringValue, [|1..1000|])
|
||||
|
||||
[<PerfTest(10000)>]
|
||||
let ``Class: ISerializable`` s = roundtrip serializableClass s
|
||||
|
||||
let boxedClass = box(Some 42)
|
||||
|
||||
[<PerfTest(10000)>]
|
||||
let ``Subtype Resolution`` s = roundtrip boxedClass s
|
||||
|
||||
let floatArray = Array.init 100000 (fun i -> float i)
|
||||
|
||||
[<PerfTest(10)>]
|
||||
let ``Array: Float`` s = roundtrip floatArray s
|
||||
|
||||
let intArray = Array.init 100000 id
|
||||
|
||||
[<PerfTest(10)>]
|
||||
let ``Array: Int`` s = roundtrip intArray s
|
||||
|
||||
let stringArray = Array.init 10000 (fun i -> stringValue + string i)
|
||||
|
||||
[<PerfTest(100)>]
|
||||
let ``Array: String`` s = roundtrip stringArray s
|
||||
|
||||
let kvarr = [|1..10000|] |> Array.map (fun i -> i, string i)
|
||||
|
||||
[<PerfTest(100)>]
|
||||
let ``Array: Key-Value Pairs`` s = roundtrip kvarr s
|
||||
|
||||
let duArray = [| for i in 1 .. 10000 -> (Something ("asdasdasdas", i)) |]
|
||||
|
||||
[<PerfTest(100)>]
|
||||
let ``Array: Discriminated Unions`` s = roundtrip duArray s
|
||||
|
||||
let objArray =
|
||||
[|
|
||||
box 2; box 3; box "hello" ; box <| Some 3; box(2,3) ;
|
||||
box <| new Class(2, stringValue) ; box <| new SerializableClass<int option>(2, stringValue, Some 12);
|
||||
box stringValue
|
||||
|]
|
||||
|
||||
[<PerfTest(1000)>]
|
||||
let ``Array: Objects`` s = roundtrip objArray s
|
||||
|
||||
|
||||
let array3D = Array3D.init 100 100 100 (fun i j k -> float (i * j + k))
|
||||
|
||||
[<PerfTest(10)>]
|
||||
let ``Array: Rank-3 Float`` s = roundtrip array3D s
|
||||
|
||||
let bclDict = dict [ for i in 1 .. 1000 -> (string i, i)]
|
||||
|
||||
[<PerfTest(100)>]
|
||||
let ``.NET Dictionary`` s = roundtrip bclDict s
|
||||
|
||||
let bclStack = new Stack<string>([for i in 1 .. 1000 -> string i])
|
||||
|
||||
[<PerfTest(100)>]
|
||||
let ``.NET Stack`` s = roundtrip bclStack s
|
||||
|
||||
let bclList = new List<string * int>([for i in 1 .. 1000 -> string i, i])
|
||||
|
||||
[<PerfTest(100)>]
|
||||
let ``.NET List`` s = roundtrip bclList s
|
||||
|
||||
let bclSet = new SortedSet<_>([for i in 1 .. 1000 -> string i])
|
||||
|
||||
[<PerfTest(100)>]
|
||||
let ``.NET Set`` s = roundtrip bclSet s
|
||||
|
||||
let smallTuple = (1, DateTime.Now,"hello")
|
||||
|
||||
[<PerfTest(10000)>]
|
||||
let ``FSharp: Tuple Small`` s = roundtrip smallTuple s
|
||||
|
||||
let largeTuple = (stringValue, 1, 2, 3, true, "", Some(3.14, [2]), 3, 2, 1, stringValue)
|
||||
|
||||
[<PerfTest(10000)>]
|
||||
let ``FSharp: Tuple Large`` s =
|
||||
roundtrip largeTuple s
|
||||
|
||||
let intList = [1..1000]
|
||||
|
||||
[<PerfTest(1000)>]
|
||||
let ``FSharp: List Int`` s = roundtrip intList s
|
||||
|
||||
let stringList = [ for i in 1 .. 1000 -> stringValue + string i ]
|
||||
|
||||
[<PerfTest(1000)>]
|
||||
let ``FSharp: List String`` s = roundtrip stringList s
|
||||
|
||||
let pairList = [ for i in 1 .. 1000 -> (string i, i) ]
|
||||
|
||||
[<PerfTest(1000)>]
|
||||
let ``FSharp: List Key-Value`` s = roundtrip pairList s
|
||||
|
||||
let nestedLst = let n = [1..1000] in [for _ in 1 .. 100 -> n]
|
||||
|
||||
[<PerfTest(1000)>]
|
||||
let ``FSharp: List Nested`` s = roundtrip nestedLst s
|
||||
|
||||
let union = SomethingElse(stringValue, 42, box (Some 42))
|
||||
|
||||
[<PerfTest(10000)>]
|
||||
let ``FSharp: Union`` s = roundtrip union s
|
||||
|
||||
let record = { Int = 42 ; String = stringValue ; Tuple = (13, "") }
|
||||
|
||||
[<PerfTest(10000)>]
|
||||
let ``FSharp: Record`` s = roundtrip record s
|
||||
|
||||
let peano = int2Peano 100
|
||||
|
||||
[<PerfTest(100)>]
|
||||
let ``FSharp: Peano Rectype`` s = roundtrip peano s
|
||||
|
||||
let closure = (@) [ Some([1..100], Set.ofList [1..100]) ]
|
||||
|
||||
[<PerfTest(1000)>]
|
||||
let ``FSharp: Curried Function`` s = roundtrip closure s
|
||||
|
||||
let binTree = mkTree 10
|
||||
|
||||
[<PerfTest(100)>]
|
||||
let ``FSharp: Binary Tree`` s = roundtrip binTree s
|
||||
|
||||
let intSet = [1..1000] |> List.map string |> set
|
||||
|
||||
[<PerfTest(1000)>]
|
||||
let ``FSharp: Set`` s = roundtrip intSet s
|
||||
|
||||
let fsMap = [1..1000] |> Seq.map (fun i -> (string i,i)) |> Map.ofSeq
|
||||
|
||||
[<PerfTest(1000)>]
|
||||
let ``FSharp: Map`` s = roundtrip fsMap s
|
||||
|
||||
let testType = typeof<int * string option * Map<int * string [], string ref option>>
|
||||
|
||||
[<PerfTest(1000)>]
|
||||
let ``Reflection: Type`` s = roundtrip testType s
|
||||
|
||||
let quotationSmall = <@ fun x -> pown 2 x @>
|
||||
|
||||
let quotationLarge =
|
||||
<@
|
||||
async {
|
||||
let rec fibAsync n =
|
||||
async {
|
||||
match n with
|
||||
| _ when n < 0 -> return invalidArg "negative" "n"
|
||||
| _ when n < 2 -> return n
|
||||
| n ->
|
||||
let! fn = fibAsync (n-1)
|
||||
let! fnn = fibAsync (n-2)
|
||||
return fn + fnn
|
||||
}
|
||||
|
||||
let! values = [1..100] |> Seq.map fibAsync |> Async.Parallel
|
||||
return Seq.sum values
|
||||
}
|
||||
@>
|
||||
|
||||
[<PerfTest(10000)>]
|
||||
let ``FSharp: Quotation Small`` s = roundtrip quotationSmall s
|
||||
|
||||
[<PerfTest(1000)>]
|
||||
let ``FSharp: Quotation Large`` s = roundtrip quotationLarge s
|
||||
15
samples/F#/sample.fs
Normal file
15
samples/F#/sample.fs
Normal file
@@ -0,0 +1,15 @@
|
||||
module Sample
|
||||
|
||||
open System
|
||||
|
||||
type Foo =
|
||||
{
|
||||
Bar : string
|
||||
}
|
||||
|
||||
type Baz = interface end
|
||||
|
||||
let Sample1(xs : int list) : string =
|
||||
xs
|
||||
|> List.map (fun x -> string x)
|
||||
|> String.concat ","
|
||||
244
samples/Forth/asm.fr
Normal file
244
samples/Forth/asm.fr
Normal file
@@ -0,0 +1,244 @@
|
||||
\ Copyright 2013-2014 Lars Brinkhoff
|
||||
|
||||
\ Assembler for x86.
|
||||
|
||||
\ Adds to FORTH vocabulary: ASSEMBLER CODE ;CODE.
|
||||
\ Creates ASSEMBLER vocabulary with: END-CODE and x86 opcodes.
|
||||
|
||||
\ Conventional prefix syntax: "<source> <destination> <opcode>,".
|
||||
\ Addressing modes:
|
||||
\ - immediate: "n #"
|
||||
\ - direct: n
|
||||
\ - register: <reg>
|
||||
\ - indirect: "<reg> )"
|
||||
\ - indirect with displacement: "n <reg> )#"
|
||||
\ - indexed: not supported yet
|
||||
|
||||
require lib/common.fth
|
||||
require search.fth
|
||||
|
||||
vocabulary assembler
|
||||
also assembler definitions
|
||||
|
||||
\ Access to the target image.
|
||||
' header, defer header, is header,
|
||||
' cell defer cell is cell
|
||||
' dp defer dp is dp
|
||||
0 value delta
|
||||
|
||||
: aligned cell + 1 - cell negate nand invert ;
|
||||
: align dp @ aligned dp ! ;
|
||||
: allot dp +! ;
|
||||
: here dp @ ;
|
||||
: cells cell * ;
|
||||
: c! delta + c! ;
|
||||
: c, here c! 1 allot ;
|
||||
: h, dup c, 8 rshift c, ;
|
||||
: , dup h, 16 rshift h, ;
|
||||
|
||||
base @ hex
|
||||
|
||||
\ This constant signals that an operand is not a direct address.
|
||||
deadbeef constant -addr
|
||||
|
||||
\ Assembler state.
|
||||
variable opcode
|
||||
variable d
|
||||
variable s
|
||||
variable dir?
|
||||
variable mrrm defer ?mrrm,
|
||||
variable sib defer ?sib,
|
||||
variable disp defer ?disp,
|
||||
variable imm defer ?imm,
|
||||
defer imm,
|
||||
defer immediate-opcode
|
||||
defer reg
|
||||
defer ?opsize
|
||||
|
||||
\ Set opcode. And destination: register or memory.
|
||||
: opcode! 3@ is immediate-opcode >r opcode ! ;
|
||||
: !reg dir? @ if 2 d ! then dir? off ;
|
||||
: !mem dir? off ;
|
||||
|
||||
\ Set bits in mod/reg/rm byte.
|
||||
: -mrrm ['] nop is ?mrrm, ;
|
||||
: mod! mrrm c0 !bits ;
|
||||
: reg@ mrrm 38 @bits ;
|
||||
: reg! mrrm 38 !bits ;
|
||||
: rm@ mrrm 7 @bits ;
|
||||
: rm! rm@ 3 lshift reg! mrrm 7 !bits ;
|
||||
: reg>opcode rm@ opcode 07 !bits ;
|
||||
: opcode>reg opcode @ dup 3 rshift rm! 8 rshift opcode ! ;
|
||||
|
||||
\ Write parts of instruction to memory.
|
||||
: ds d @ s @ + ;
|
||||
: ?twobyte dup FF > if dup 8 rshift c, then ;
|
||||
: opcode, opcode @ ?twobyte ds + c, ;
|
||||
: mrrm, mrrm @ c, ;
|
||||
: sib, sib @ c, ;
|
||||
: imm8, imm @ c, ;
|
||||
: imm16, imm @ h, ;
|
||||
: imm32, imm @ , ;
|
||||
: disp8, disp @ c, ;
|
||||
: disp32, disp @ , ;
|
||||
|
||||
\ Set operand size.
|
||||
: -opsize 2drop r> drop ;
|
||||
: opsize! is imm, s ! ['] -opsize is ?opsize ;
|
||||
: !op8 0 ['] imm8, ?opsize ;
|
||||
: !op32 1 ['] imm32, ?opsize ;
|
||||
: !op16 1 ['] imm16, ?opsize 66 c, ;
|
||||
|
||||
\ Set SIB byte.
|
||||
: !sib ['] sib, is ?sib, ;
|
||||
: sib! 3 lshift + sib ! !sib ;
|
||||
|
||||
\ Set displacement.
|
||||
: byte? -80 80 within ;
|
||||
: disp! is ?disp, disp ! ;
|
||||
: !disp8 ['] disp8, disp! ;
|
||||
: !disp32 ['] disp32, disp! ;
|
||||
: !disp ( a -- u ) dup byte? if !disp8 40 else !disp32 80 then ;
|
||||
: -pc here 5 + negate ;
|
||||
: relative -pc disp +! ;
|
||||
|
||||
\ Set immediate operand.
|
||||
: imm! imm ! ['] imm, is ?imm, ;
|
||||
|
||||
\ Implements addressing modes: register, indirect, indexed, and direct.
|
||||
: reg1 rm! !reg ;
|
||||
: reg2 3 lshift reg! ;
|
||||
: !reg2 ['] reg2 is reg ;
|
||||
: ind dup mod! rm! !mem !reg2 ;
|
||||
: ind# swap !disp + ind ;
|
||||
: idx 04 ind sib! ;
|
||||
: idx# rot !disp 04 + ind sib! ;
|
||||
: addr !disp32 05 ind ;
|
||||
|
||||
\ Reset assembler state.
|
||||
: 0opsize ['] opsize! is ?opsize ;
|
||||
: 0ds d off s off ;
|
||||
: 0reg ['] reg1 is reg ;
|
||||
: 0mrrm c0 mrrm ! ['] mrrm, is ?mrrm, ;
|
||||
: 0sib ['] nop is ?sib, ;
|
||||
: 0disp ['] nop is ?disp, ;
|
||||
: 0imm imm off ['] nop is ?imm, 0 is imm, ;
|
||||
: 0asm 0imm 0disp 0reg 0ds 0mrrm 0sib 0opsize dir? on ;
|
||||
|
||||
\ Enter and exit assembler mode.
|
||||
: start-code also assembler 0asm ;
|
||||
: end-code align previous ;
|
||||
|
||||
\ Implements addressing mode: immediate.
|
||||
: imm8? imm @ byte? ;
|
||||
: ?sign-extend d off imm8? if 2 d ! ['] imm8, is ?imm, then ;
|
||||
: alu# opcode @ reg! 80 opcode ! ?sign-extend ;
|
||||
: mov# B0 s @ 3 lshift + rm@ + opcode ! 0ds -mrrm ;
|
||||
: push# imm8? if ['] imm8, 6A else ['] imm32, 68 then dup opcode ! rm! is ?imm, ;
|
||||
: test# F6 opcode ! ;
|
||||
: imm-op imm! immediate-opcode ;
|
||||
|
||||
\ Process one operand. All operands except a direct address
|
||||
\ have the stack picture ( n*x xt -addr ).
|
||||
: addr? dup -addr <> ;
|
||||
: op addr? if addr else drop execute then ;
|
||||
|
||||
\ Define instruction formats.
|
||||
: instruction, opcode! opcode, ?mrrm, ?sib, ?disp, ?imm, 0asm ;
|
||||
: mnemonic ( u a "name" -- ) create ['] nop 3, does> instruction, ;
|
||||
: format: create ] !csp does> mnemonic ;
|
||||
: immediate: ' latestxt >body ! ;
|
||||
|
||||
\ Instruction formats.
|
||||
format: 0op -mrrm ;
|
||||
format: 1reg op reg>opcode 0ds -mrrm ;
|
||||
format: 1op opcode>reg op d off ;
|
||||
format: 2op op op ;
|
||||
format: 2op-d op op d off ;
|
||||
format: 2op-ds op op 0ds ;
|
||||
format: 1addr op relative -mrrm ;
|
||||
format: 1imm8 !op8 op -mrrm ;
|
||||
|
||||
\ Instruction mnemonics.
|
||||
00 2op add, immediate: alu#
|
||||
08 2op or, immediate: alu#
|
||||
0F44 2op-ds cmove, \ Todo: other condition codes.
|
||||
0FB6 2op-ds movzx,
|
||||
0FBE 2op-ds movsx,
|
||||
10 2op adc, immediate: alu#
|
||||
18 2op sbb, immediate: alu#
|
||||
20 2op and, immediate: alu#
|
||||
26 0op es,
|
||||
28 2op sub, immediate: alu#
|
||||
2E 0op cs,
|
||||
30 2op xor, immediate: alu#
|
||||
36 0op ss,
|
||||
38 2op cmp, immediate: alu#
|
||||
3E 0op ds,
|
||||
50 1reg push, immediate: push#
|
||||
58 1reg pop,
|
||||
64 0op fs,
|
||||
65 0op gs,
|
||||
\ 70 jcc
|
||||
84 2op-d test, immediate: test#
|
||||
86 2op-d xchg,
|
||||
88 2op mov, immediate: mov#
|
||||
8D 2op-ds lea,
|
||||
\ 8F/0 pop, rm
|
||||
90 0op nop,
|
||||
C3 0op ret,
|
||||
\ C6/0 immediate mov to r/m
|
||||
\ C7/0 immediate mov to r/m
|
||||
CD 1imm8 int,
|
||||
E8 1addr call,
|
||||
E9 1addr jmp,
|
||||
\ EB jmp rel8
|
||||
F0 0op lock,
|
||||
F2 0op rep,
|
||||
F3 0op repz,
|
||||
F4 0op hlt,
|
||||
F5 0op cmc,
|
||||
F610 1op not,
|
||||
F618 1op neg,
|
||||
F8 0op clc,
|
||||
F9 0op stc,
|
||||
FA 0op cli,
|
||||
FB 0op sti,
|
||||
FC 0op cld,
|
||||
FD 0op std,
|
||||
\ FE 0 inc rm
|
||||
\ FF 1 dec rm
|
||||
\ FF 2 call rm
|
||||
\ FF 4 jmp rm
|
||||
\ FF 6 push rm
|
||||
|
||||
: sp? dup 4 = ;
|
||||
|
||||
\ Addressing mode syntax: immediate, indirect, and displaced indirect.
|
||||
: # ['] imm-op -addr ;
|
||||
: ) 2drop sp? if 4 ['] idx else ['] ind then -addr 0reg 0opsize ;
|
||||
: )# 2drop sp? if 4 ['] idx# else ['] ind# then -addr 0reg 0opsize ;
|
||||
|
||||
\ Define registers.
|
||||
: reg8 create , does> @ ['] reg -addr !op8 ;
|
||||
: reg16 create , does> @ ['] reg -addr !op16 ;
|
||||
: reg32 create , does> @ ['] reg -addr !op32 ;
|
||||
: reg: dup reg8 dup reg16 dup reg32 1+ ;
|
||||
|
||||
\ Register names.
|
||||
0
|
||||
reg: al ax eax reg: cl cx ecx reg: dl dx edx reg: bl bx ebx
|
||||
reg: ah sp esp reg: ch bp ebp reg: dh si esi reg: bh di edi
|
||||
drop
|
||||
|
||||
\ Runtime for ;CODE. CODE! is defined elsewhere.
|
||||
: (;code) r> code! ;
|
||||
|
||||
base ! only forth definitions also assembler
|
||||
|
||||
\ Standard assembler entry points.
|
||||
: code parse-name header, ?code, start-code ;
|
||||
: ;code postpone (;code) reveal postpone [ ?csp start-code ; immediate
|
||||
|
||||
0asm
|
||||
previous
|
||||
252
samples/Forth/core.fs
Normal file
252
samples/Forth/core.fs
Normal file
@@ -0,0 +1,252 @@
|
||||
: immediate lastxt @ dup c@ negate swap c! ;
|
||||
|
||||
: \ source nip >in ! ; immediate \ Copyright 2004, 2012 Lars Brinkhoff
|
||||
|
||||
: char \ ( "word" -- char )
|
||||
bl-word here 1+ c@ ;
|
||||
|
||||
: ahead here 0 , ;
|
||||
|
||||
: resolve here swap ! ;
|
||||
|
||||
: ' bl-word here find 0branch [ ahead ] exit [ resolve ] 0 ;
|
||||
|
||||
: postpone-nonimmediate [ ' literal , ' compile, ] literal , ;
|
||||
|
||||
: create dovariable_code header, reveal ;
|
||||
|
||||
create postponers
|
||||
' postpone-nonimmediate ,
|
||||
' abort ,
|
||||
' , ,
|
||||
|
||||
: word \ ( char "<chars>string<char>" -- caddr )
|
||||
drop bl-word here ;
|
||||
|
||||
: postpone \ ( C: "word" -- )
|
||||
bl word find 1+ cells postponers + @ execute ; immediate
|
||||
|
||||
: unresolved \ ( C: "word" -- orig )
|
||||
postpone postpone postpone ahead ; immediate
|
||||
|
||||
: chars \ ( n1 -- n2 )
|
||||
;
|
||||
|
||||
: else \ ( -- ) ( C: orig1 -- orig2 )
|
||||
unresolved branch swap resolve ; immediate
|
||||
|
||||
: if \ ( flag -- ) ( C: -- orig )
|
||||
unresolved 0branch ; immediate
|
||||
|
||||
: then \ ( -- ) ( C: orig -- )
|
||||
resolve ; immediate
|
||||
|
||||
: [char] \ ( "word" -- )
|
||||
char postpone literal ; immediate
|
||||
|
||||
: (does>) lastxt @ dodoes_code over >code ! r> swap >does ! ;
|
||||
|
||||
: does> postpone (does>) ; immediate
|
||||
|
||||
: begin \ ( -- ) ( C: -- dest )
|
||||
here ; immediate
|
||||
|
||||
: while \ ( x -- ) ( C: dest -- orig dest )
|
||||
unresolved 0branch swap ; immediate
|
||||
|
||||
: repeat \ ( -- ) ( C: orig dest -- )
|
||||
postpone branch , resolve ; immediate
|
||||
|
||||
: until \ ( x -- ) ( C: dest -- )
|
||||
postpone 0branch , ; immediate
|
||||
|
||||
: recurse lastxt @ compile, ; immediate
|
||||
|
||||
: pad \ ( -- addr )
|
||||
here 1024 + ;
|
||||
|
||||
: parse \ ( char "string<char>" -- addr n )
|
||||
pad >r begin
|
||||
source? if <source 2dup <> else 0 0 then
|
||||
while
|
||||
r@ c! r> 1+ >r
|
||||
repeat 2drop pad r> over - ;
|
||||
|
||||
: ( \ ( "string<paren>" -- )
|
||||
[ char ) ] literal parse 2drop ; immediate
|
||||
\ TODO: If necessary, refill and keep parsing.
|
||||
|
||||
: string, ( addr n -- )
|
||||
here over allot align swap cmove ;
|
||||
|
||||
: (s") ( -- addr n ) ( R: ret1 -- ret2 )
|
||||
r> dup @ swap cell+ 2dup + aligned >r swap ;
|
||||
|
||||
create squote 128 allot
|
||||
|
||||
: s" ( "string<quote>" -- addr n )
|
||||
state @ if
|
||||
postpone (s") [char] " parse dup , string,
|
||||
else
|
||||
[char] " parse >r squote r@ cmove squote r>
|
||||
then ; immediate
|
||||
|
||||
: (abort") ( ... addr n -- ) ( R: ... -- )
|
||||
cr type cr abort ;
|
||||
|
||||
: abort" ( ... x "string<quote>" -- ) ( R: ... -- )
|
||||
postpone if postpone s" postpone (abort") postpone then ; immediate
|
||||
|
||||
\ ----------------------------------------------------------------------
|
||||
|
||||
( Core words. )
|
||||
|
||||
\ TODO: #
|
||||
\ TODO: #>
|
||||
\ TODO: #s
|
||||
|
||||
: and ( x y -- x&y ) nand invert ;
|
||||
|
||||
: * 1 2>r 0 swap begin r@ while
|
||||
r> r> swap 2dup dup + 2>r and if swap over + swap then dup +
|
||||
repeat r> r> 2drop drop ;
|
||||
|
||||
\ TODO: */mod
|
||||
|
||||
: +loop ( -- ) ( C: nest-sys -- )
|
||||
postpone (+loop) postpone 0branch , postpone unloop ; immediate
|
||||
|
||||
: space bl emit ;
|
||||
|
||||
: ?.- dup 0 < if [char] - emit negate then ;
|
||||
|
||||
: digit [char] 0 + emit ;
|
||||
|
||||
: (.) base @ /mod ?dup if recurse then digit ;
|
||||
|
||||
: ." ( "string<quote>" -- ) postpone s" postpone type ; immediate
|
||||
|
||||
: . ( x -- ) ?.- (.) space ;
|
||||
|
||||
: postpone-number ( caddr -- )
|
||||
0 0 rot count >number dup 0= if
|
||||
2drop nip
|
||||
postpone (literal) postpone (literal) postpone ,
|
||||
postpone literal postpone ,
|
||||
else
|
||||
." Undefined: " type cr abort
|
||||
then ;
|
||||
|
||||
' postpone-number postponers cell+ !
|
||||
|
||||
: / ( x y -- x/y ) /mod nip ;
|
||||
|
||||
: 0< ( n -- flag ) 0 < ;
|
||||
|
||||
: 1- ( n -- n-1 ) -1 + ;
|
||||
|
||||
: 2! ( x1 x2 addr -- ) swap over ! cell+ ! ;
|
||||
|
||||
: 2* ( n -- 2n ) dup + ;
|
||||
|
||||
\ Kernel: 2/
|
||||
|
||||
: 2@ ( addr -- x1 x2 ) dup cell+ @ swap @ ;
|
||||
|
||||
\ Kernel: 2drop
|
||||
\ Kernel: 2dup
|
||||
|
||||
\ TODO: 2over ( x1 x2 x3 x4 -- x1 x2 x3 x4 x1 x2 )
|
||||
\ 3 pick 3 pick ;
|
||||
|
||||
\ TODO: 2swap
|
||||
|
||||
\ TODO: <#
|
||||
|
||||
: abs ( n -- |n| )
|
||||
dup 0< if negate then ;
|
||||
|
||||
\ TODO: accept
|
||||
|
||||
: c, ( n -- )
|
||||
here c! 1 chars allot ;
|
||||
|
||||
: char+ ( n1 -- n2 )
|
||||
1+ ;
|
||||
|
||||
: constant create , does> @ ;
|
||||
|
||||
: decimal ( -- )
|
||||
10 base ! ;
|
||||
|
||||
: depth ( -- n )
|
||||
data_stack 100 cells + 'SP @ - /cell / 2 - ;
|
||||
|
||||
: do ( n1 n2 -- ) ( R: -- loop-sys ) ( C: -- do-sys )
|
||||
postpone 2>r here ; immediate
|
||||
|
||||
\ TODO: environment?
|
||||
\ TODO: evaluate
|
||||
\ TODO: fill
|
||||
\ TODO: fm/mod )
|
||||
\ TODO: hold
|
||||
|
||||
: j ( -- x1 ) ( R: x1 x2 x3 -- x1 x2 x3 )
|
||||
'RP @ 3 cells + @ ;
|
||||
|
||||
\ TODO: leave
|
||||
|
||||
: loop ( -- ) ( C: nest-sys -- )
|
||||
postpone 1 postpone (+loop)
|
||||
postpone 0branch ,
|
||||
postpone unloop ; immediate
|
||||
|
||||
: lshift begin ?dup while 1- swap dup + swap repeat ;
|
||||
|
||||
: rshift 1 begin over while dup + swap 1- swap repeat nip
|
||||
2>r 0 1 begin r@ while
|
||||
r> r> 2dup swap dup + 2>r and if swap over + swap then dup +
|
||||
repeat r> r> 2drop drop ;
|
||||
|
||||
: max ( x y -- max[x,y] )
|
||||
2dup > if drop else nip then ;
|
||||
|
||||
\ Kernel: min
|
||||
\ TODO: mod
|
||||
\ TODO: move
|
||||
|
||||
: (quit) ( R: ... -- )
|
||||
return_stack 100 cells + 'RP !
|
||||
0 'source-id ! tib ''source ! #tib ''#source !
|
||||
postpone [
|
||||
begin
|
||||
refill
|
||||
while
|
||||
interpret state @ 0= if ." ok" cr then
|
||||
repeat
|
||||
bye ;
|
||||
|
||||
' (quit) ' quit >body cell+ !
|
||||
|
||||
\ TODO: s>d
|
||||
\ TODO: sign
|
||||
\ TODO: sm/rem
|
||||
|
||||
: spaces ( n -- )
|
||||
0 do space loop ;
|
||||
|
||||
\ TODO: u.
|
||||
|
||||
: signbit ( -- n ) -1 1 rshift invert ;
|
||||
|
||||
: xor ( x y -- x^y ) 2dup nand >r r@ nand swap r> nand nand ;
|
||||
|
||||
: u< ( x y -- flag ) signbit xor swap signbit xor > ;
|
||||
|
||||
\ TODO: um/mod
|
||||
|
||||
: variable ( "word" -- )
|
||||
create /cell allot ;
|
||||
|
||||
: ['] \ ( C: "word" -- )
|
||||
' postpone literal ; immediate
|
||||
48
samples/GLSL/recurse1.fs
Normal file
48
samples/GLSL/recurse1.fs
Normal file
@@ -0,0 +1,48 @@
|
||||
#version 330 core
|
||||
|
||||
// cross-unit recursion
|
||||
|
||||
void main() {}
|
||||
|
||||
// two-level recursion
|
||||
|
||||
float cbar(int);
|
||||
|
||||
void cfoo(float)
|
||||
{
|
||||
cbar(2);
|
||||
}
|
||||
|
||||
// four-level, out of order
|
||||
|
||||
void CB();
|
||||
void CD();
|
||||
void CA() { CB(); }
|
||||
void CC() { CD(); }
|
||||
|
||||
// high degree
|
||||
|
||||
void CBT();
|
||||
void CDT();
|
||||
void CAT() { CBT(); CBT(); CBT(); }
|
||||
void CCT() { CDT(); CDT(); CBT(); }
|
||||
|
||||
// not recursive
|
||||
|
||||
void norA() {}
|
||||
void norB() { norA(); }
|
||||
void norC() { norA(); }
|
||||
void norD() { norA(); }
|
||||
void norE() { norB(); }
|
||||
void norF() { norB(); }
|
||||
void norG() { norE(); }
|
||||
void norH() { norE(); }
|
||||
void norI() { norE(); }
|
||||
|
||||
// not recursive, but with a call leading into a cycle if ignoring direction
|
||||
|
||||
void norcA() { }
|
||||
void norcB() { norcA(); }
|
||||
void norcC() { norcB(); }
|
||||
void norcD() { norcC(); norcB(); } // head of cycle
|
||||
void norcE() { norcD(); } // lead into cycle
|
||||
238
samples/Gosu/Ronin.gs
Normal file
238
samples/Gosu/Ronin.gs
Normal file
@@ -0,0 +1,238 @@
|
||||
/**
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
|
||||
*/
|
||||
|
||||
package ronin
|
||||
|
||||
uses gw.util.concurrent.LockingLazyVar
|
||||
uses gw.lang.reflect.*
|
||||
uses java.lang.*
|
||||
uses java.io.*
|
||||
uses ronin.config.*
|
||||
uses org.slf4j.*
|
||||
|
||||
/**
|
||||
* The central location for Ronin utility methods. Controllers and templates should generally access the
|
||||
* methods and properties they inherit from {@link ronin.IRoninUtils} instead of using the methods and
|
||||
* properties here.
|
||||
*/
|
||||
class Ronin {
|
||||
|
||||
// One static field to rule the all...
|
||||
static var _CONFIG : IRoninConfig as Config
|
||||
|
||||
// And one thread local to bind them
|
||||
static var _CURRENT_REQUEST = new ThreadLocal<RoninRequest>();
|
||||
|
||||
// That's inconstructable
|
||||
private construct() {}
|
||||
|
||||
internal static function init(servlet : RoninServlet, m : ApplicationMode, src : File) {
|
||||
if(_CONFIG != null) {
|
||||
throw "Cannot initialize a Ronin application multiple times!"
|
||||
}
|
||||
var cfg = TypeSystem.getByFullNameIfValid("config.RoninConfig")
|
||||
var defaultWarning = false
|
||||
if(cfg != null) {
|
||||
var ctor = cfg.TypeInfo.getConstructor({ronin.config.ApplicationMode, ronin.RoninServlet})
|
||||
if(ctor == null) {
|
||||
throw "config.RoninConfig must have a constructor with the same signature as ronin.config.RoninConfig"
|
||||
}
|
||||
_CONFIG = ctor.Constructor.newInstance({m, servlet}) as IRoninConfig
|
||||
} else {
|
||||
_CONFIG = new DefaultRoninConfig(m, servlet)
|
||||
defaultWarning = true
|
||||
}
|
||||
var roninLogger = TypeSystem.getByFullNameIfValid("ronin.RoninLoggerFactory")
|
||||
if(roninLogger != null) {
|
||||
roninLogger.TypeInfo.getMethod("init", {ronin.config.LogLevel}).CallHandler.handleCall(null, {LogLevel})
|
||||
}
|
||||
if(defaultWarning) {
|
||||
log("No configuration was found at config.RoninConfig, using the default configuration...", :level=WARN)
|
||||
}
|
||||
Quartz.maybeStart()
|
||||
ReloadManager.setSourceRoot(src)
|
||||
}
|
||||
|
||||
internal static property set CurrentRequest(req : RoninRequest) {
|
||||
_CURRENT_REQUEST.set(req)
|
||||
}
|
||||
|
||||
//============================================
|
||||
// Public API
|
||||
//============================================
|
||||
|
||||
/**
|
||||
* The trace handler for the current request.
|
||||
*/
|
||||
static property get CurrentTrace() : Trace {
|
||||
return CurrentRequest?.Trace
|
||||
}
|
||||
|
||||
/**
|
||||
* Ronin's representation of the current request.
|
||||
*/
|
||||
static property get CurrentRequest() : RoninRequest {
|
||||
return _CURRENT_REQUEST.get()
|
||||
}
|
||||
|
||||
/**
|
||||
* The mode in which this application is running.
|
||||
*/
|
||||
static property get Mode() : ApplicationMode {
|
||||
return _CONFIG?.Mode ?: TESTING
|
||||
}
|
||||
|
||||
/**
|
||||
* The log level at and above which log messages should be displayed.
|
||||
*/
|
||||
static property get LogLevel() : LogLevel {
|
||||
return _CONFIG?.LogLevel ?: DEBUG
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether or not to display detailed trace information on each request.
|
||||
*/
|
||||
static property get TraceEnabled() : boolean {
|
||||
return _CONFIG != null ? _CONFIG.TraceEnabled : true
|
||||
}
|
||||
|
||||
/**
|
||||
* The default controller method to call when no method name is present in the request URL.
|
||||
*/
|
||||
static property get DefaultAction() : String {
|
||||
return _CONFIG?.DefaultAction
|
||||
}
|
||||
|
||||
/**
|
||||
* The default controller to call when no controller name is present in the request URL.
|
||||
*/
|
||||
static property get DefaultController() : Type {
|
||||
return _CONFIG?.DefaultController
|
||||
}
|
||||
|
||||
/**
|
||||
* The servlet responsible for handling Ronin requests.
|
||||
*/
|
||||
static property get RoninServlet() : RoninServlet {
|
||||
return _CONFIG?.RoninServlet
|
||||
}
|
||||
|
||||
/**
|
||||
* The handler for request processing errors.
|
||||
*/
|
||||
static property get ErrorHandler() : IErrorHandler {
|
||||
return _CONFIG?.ErrorHandler
|
||||
}
|
||||
|
||||
/**
|
||||
* The custom handler for logging messages.
|
||||
*/
|
||||
static property get LogHandler() : ILogHandler {
|
||||
return _CONFIG?.LogHandler
|
||||
}
|
||||
|
||||
/**
|
||||
* Logs a message using the configured log handler.
|
||||
* @param msg The text of the message to log, or a block which returns said text.
|
||||
* @param level (Optional) The level at which to log the message.
|
||||
* @param component (Optional) The logical component from whence the message originated.
|
||||
* @param exception (Optional) An exception to associate with the message.
|
||||
*/
|
||||
static function log(msg : Object, level : LogLevel = null, component : String = null, exception : java.lang.Throwable = null) {
|
||||
if(level == null) {
|
||||
level = INFO
|
||||
}
|
||||
if(LogLevel <= level) {
|
||||
var msgStr : String
|
||||
if(msg typeis block():String) {
|
||||
msgStr = (msg as block():String)()
|
||||
} else {
|
||||
msgStr = msg as String
|
||||
}
|
||||
if(_CONFIG?.LogHandler != null) {
|
||||
_CONFIG.LogHandler.log(msgStr, level, component, exception)
|
||||
} else {
|
||||
switch(level) {
|
||||
case TRACE:
|
||||
LoggerFactory.getLogger(component?:Logger.ROOT_LOGGER_NAME).trace(msgStr, exception)
|
||||
break
|
||||
case DEBUG:
|
||||
LoggerFactory.getLogger(component?:Logger.ROOT_LOGGER_NAME).debug(msgStr, exception)
|
||||
break
|
||||
case INFO:
|
||||
LoggerFactory.getLogger(component?:Logger.ROOT_LOGGER_NAME).info(msgStr, exception)
|
||||
break
|
||||
case WARN:
|
||||
LoggerFactory.getLogger(component?:Logger.ROOT_LOGGER_NAME).warn(msgStr, exception)
|
||||
break
|
||||
case ERROR:
|
||||
case FATAL:
|
||||
LoggerFactory.getLogger(component?:Logger.ROOT_LOGGER_NAME).error(msgStr, exception)
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The caches known to Ronin.
|
||||
*/
|
||||
static enum CacheStore {
|
||||
REQUEST,
|
||||
SESSION,
|
||||
APPLICATION
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves a value from a cache, or computes and stores it if it is not in the cache.
|
||||
* @param value A block which will compute the desired value.
|
||||
* @param name (Optional) A unique identifier for the value. Default is null, which means one will be
|
||||
* generated from the type of the value.
|
||||
* @param store (Optional) The cache store used to retrieve or store the value. Default is the request cache.
|
||||
* @return The retrieved or computed value.
|
||||
*/
|
||||
static function cache<T>(value : block():T, name : String = null, store : CacheStore = null) : T {
|
||||
if(store == null or store == REQUEST) {
|
||||
return _CONFIG.RequestCache.getValue(value, name)
|
||||
} else if (store == SESSION) {
|
||||
return _CONFIG.SessionCache.getValue(value, name)
|
||||
} else if (store == APPLICATION) {
|
||||
return _CONFIG.ApplicationCache.getValue(value, name)
|
||||
} else {
|
||||
throw "Don't know about CacheStore ${store}"
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Invalidates a cached value in a cache.
|
||||
* @param name The unique identifier for the value.
|
||||
* @param store The cache store in which to invalidate the value.
|
||||
*/
|
||||
static function invalidate<T>(name : String, store : CacheStore) {
|
||||
if(store == null or store == REQUEST) {
|
||||
_CONFIG.RequestCache.invalidate(name)
|
||||
} else if (store == SESSION) {
|
||||
_CONFIG.SessionCache.invalidate(name)
|
||||
} else if (store == APPLICATION) {
|
||||
_CONFIG.ApplicationCache.invalidate(name)
|
||||
} else {
|
||||
throw "Don't know about CacheStore ${store}"
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Detects changes made to resources in the Ronin application and
|
||||
* reloads them. This function should only be called when Ronin is
|
||||
* in development mode.
|
||||
*/
|
||||
static function loadChanges() {
|
||||
ReloadManager.detectAndReloadChangedResources()
|
||||
}
|
||||
|
||||
}
|
||||
18
samples/Gradle/build.gradle
Normal file
18
samples/Gradle/build.gradle
Normal file
@@ -0,0 +1,18 @@
|
||||
apply plugin: GreetingPlugin
|
||||
|
||||
greeting.message = 'Hi from Gradle'
|
||||
|
||||
class GreetingPlugin implements Plugin<Project> {
|
||||
void apply(Project project) {
|
||||
// Add the 'greeting' extension object
|
||||
project.extensions.create("greeting", GreetingPluginExtension)
|
||||
// Add a task that uses the configuration
|
||||
project.task('hello') << {
|
||||
println project.greeting.message
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class GreetingPluginExtension {
|
||||
def String message = 'Hello from GreetingPlugin'
|
||||
}
|
||||
20
samples/Gradle/builder.gradle
Normal file
20
samples/Gradle/builder.gradle
Normal file
@@ -0,0 +1,20 @@
|
||||
apply plugin: GreetingPlugin
|
||||
|
||||
greeting {
|
||||
message = 'Hi'
|
||||
greeter = 'Gradle'
|
||||
}
|
||||
|
||||
class GreetingPlugin implements Plugin<Project> {
|
||||
void apply(Project project) {
|
||||
project.extensions.create("greeting", GreetingPluginExtension)
|
||||
project.task('hello') << {
|
||||
println "${project.greeting.message} from ${project.greeting.greeter}"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class GreetingPluginExtension {
|
||||
String message
|
||||
String greeter
|
||||
}
|
||||
17
samples/HTML/example.xht
Normal file
17
samples/HTML/example.xht
Normal file
@@ -0,0 +1,17 @@
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||
<head>
|
||||
<title>This is a XHTML sample file</title>
|
||||
<style type="text/css"><![CDATA[
|
||||
#example {
|
||||
background-color: yellow;
|
||||
}
|
||||
]]></style>
|
||||
</head>
|
||||
<body>
|
||||
<div id="example">
|
||||
Just a simple <strong>XHTML</strong> test page.
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
56
samples/Jasmin/if1.j
Normal file
56
samples/Jasmin/if1.j
Normal file
@@ -0,0 +1,56 @@
|
||||
.class public if1
|
||||
.super java/lang/Object
|
||||
;
|
||||
; standard initializer (calls java.lang.Object's initializer)
|
||||
;
|
||||
.method public <init>()V
|
||||
aload_0
|
||||
invokenonvirtual java/lang/Object/<init>()V
|
||||
return
|
||||
.end method
|
||||
|
||||
.method public static main([Ljava/lang/String;)V
|
||||
|
||||
.limit locals 1
|
||||
.limit stack 5
|
||||
BeginGlobal:
|
||||
.line 2
|
||||
ldc 0x1
|
||||
ldc 0x1
|
||||
if_icmpeq If556261059
|
||||
goto IfElse556261059
|
||||
If556261059:
|
||||
.line 3
|
||||
.line 3
|
||||
getstatic java/lang/System/out Ljava/io/PrintStream;
|
||||
ldc 0x1
|
||||
invokevirtual java/io/PrintStream/print(I)V
|
||||
goto IfDone556261059
|
||||
IfElse556261059:
|
||||
.line 5
|
||||
.line 5
|
||||
getstatic java/lang/System/out Ljava/io/PrintStream;
|
||||
ldc 0x2
|
||||
invokevirtual java/io/PrintStream/print(I)V
|
||||
IfDone556261059:
|
||||
|
||||
.line 6
|
||||
getstatic java/lang/System/out Ljava/io/PrintStream;
|
||||
ldc 0x3
|
||||
invokevirtual java/io/PrintStream/print(I)V
|
||||
|
||||
.line 7
|
||||
ldc 0x1
|
||||
ldc 0x1
|
||||
if_icmpne IfNot-920218690
|
||||
.line 8
|
||||
.line 8
|
||||
getstatic java/lang/System/out Ljava/io/PrintStream;
|
||||
ldc 0x4
|
||||
invokevirtual java/io/PrintStream/print(I)V
|
||||
IfNot-920218690:
|
||||
|
||||
EndGlobal:
|
||||
return
|
||||
.end method
|
||||
|
||||
167
samples/Jasmin/if2.j
Normal file
167
samples/Jasmin/if2.j
Normal file
@@ -0,0 +1,167 @@
|
||||
.class public if2
|
||||
.super java/lang/Object
|
||||
;
|
||||
; standard initializer (calls java.lang.Object's initializer)
|
||||
;
|
||||
.method public <init>()V
|
||||
aload_0
|
||||
invokenonvirtual java/lang/Object/<init>()V
|
||||
return
|
||||
.end method
|
||||
|
||||
.method public static main([Ljava/lang/String;)V
|
||||
|
||||
.limit locals 1
|
||||
.limit stack 5
|
||||
BeginGlobal:
|
||||
.line 2
|
||||
ldc 0x1
|
||||
ldc 0x1
|
||||
if_icmpeq Cmp1893841232
|
||||
ldc 0x0
|
||||
goto CmpDone1893841232
|
||||
Cmp1893841232:
|
||||
ldc 0x1
|
||||
CmpDone1893841232:
|
||||
ldc 0x1
|
||||
if_icmpeq If-1736765035
|
||||
goto IfElse-1736765035
|
||||
If-1736765035:
|
||||
.line 2
|
||||
.line 3
|
||||
getstatic java/lang/System/out Ljava/io/PrintStream;
|
||||
ldc 0x1
|
||||
invokevirtual java/io/PrintStream/print(I)V
|
||||
goto IfDone-1736765035
|
||||
IfElse-1736765035:
|
||||
.line 4
|
||||
.line 4
|
||||
ldc 0x2
|
||||
ldc 0x1
|
||||
if_icmpeq Cmp-1460884369
|
||||
ldc 0x0
|
||||
goto CmpDone-1460884369
|
||||
Cmp-1460884369:
|
||||
ldc 0x1
|
||||
CmpDone-1460884369:
|
||||
ldc 0x1
|
||||
if_icmpeq If-247349760
|
||||
goto IfElse-247349760
|
||||
If-247349760:
|
||||
.line 4
|
||||
.line 5
|
||||
getstatic java/lang/System/out Ljava/io/PrintStream;
|
||||
ldc 0x2
|
||||
invokevirtual java/io/PrintStream/print(I)V
|
||||
goto IfDone-247349760
|
||||
IfElse-247349760:
|
||||
.line 6
|
||||
.line 7
|
||||
getstatic java/lang/System/out Ljava/io/PrintStream;
|
||||
ldc 0x3
|
||||
invokevirtual java/io/PrintStream/print(I)V
|
||||
IfDone-247349760:
|
||||
IfDone-1736765035:
|
||||
|
||||
.line 10
|
||||
ldc 0x1
|
||||
ldc 0x2
|
||||
if_icmpeq Cmp933554851
|
||||
ldc 0x0
|
||||
goto CmpDone933554851
|
||||
Cmp933554851:
|
||||
ldc 0x1
|
||||
CmpDone933554851:
|
||||
ldc 0x1
|
||||
if_icmpeq If1623625546
|
||||
goto IfElse1623625546
|
||||
If1623625546:
|
||||
.line 10
|
||||
.line 11
|
||||
getstatic java/lang/System/out Ljava/io/PrintStream;
|
||||
ldc 0x1
|
||||
invokevirtual java/io/PrintStream/print(I)V
|
||||
goto IfDone1623625546
|
||||
IfElse1623625546:
|
||||
.line 12
|
||||
.line 12
|
||||
ldc 0x2
|
||||
ldc 0x2
|
||||
if_icmpeq Cmp1572138409
|
||||
ldc 0x0
|
||||
goto CmpDone1572138409
|
||||
Cmp1572138409:
|
||||
ldc 0x1
|
||||
CmpDone1572138409:
|
||||
ldc 0x1
|
||||
if_icmpeq If126354425
|
||||
goto IfElse126354425
|
||||
If126354425:
|
||||
.line 12
|
||||
.line 13
|
||||
getstatic java/lang/System/out Ljava/io/PrintStream;
|
||||
ldc 0x2
|
||||
invokevirtual java/io/PrintStream/print(I)V
|
||||
goto IfDone126354425
|
||||
IfElse126354425:
|
||||
.line 14
|
||||
.line 15
|
||||
getstatic java/lang/System/out Ljava/io/PrintStream;
|
||||
ldc 0x3
|
||||
invokevirtual java/io/PrintStream/print(I)V
|
||||
IfDone126354425:
|
||||
IfDone1623625546:
|
||||
|
||||
.line 18
|
||||
ldc 0x1
|
||||
ldc 0x2
|
||||
if_icmpeq Cmp126493150
|
||||
ldc 0x0
|
||||
goto CmpDone126493150
|
||||
Cmp126493150:
|
||||
ldc 0x1
|
||||
CmpDone126493150:
|
||||
ldc 0x1
|
||||
if_icmpeq If1522284422
|
||||
goto IfElse1522284422
|
||||
If1522284422:
|
||||
.line 18
|
||||
.line 19
|
||||
getstatic java/lang/System/out Ljava/io/PrintStream;
|
||||
ldc 0x1
|
||||
invokevirtual java/io/PrintStream/print(I)V
|
||||
goto IfDone1522284422
|
||||
IfElse1522284422:
|
||||
.line 20
|
||||
.line 20
|
||||
ldc 0x2
|
||||
ldc 0x1
|
||||
if_icmpeq Cmp-906666545
|
||||
ldc 0x0
|
||||
goto CmpDone-906666545
|
||||
Cmp-906666545:
|
||||
ldc 0x1
|
||||
CmpDone-906666545:
|
||||
ldc 0x1
|
||||
if_icmpeq If1083939031
|
||||
goto IfElse1083939031
|
||||
If1083939031:
|
||||
.line 20
|
||||
.line 21
|
||||
getstatic java/lang/System/out Ljava/io/PrintStream;
|
||||
ldc 0x2
|
||||
invokevirtual java/io/PrintStream/print(I)V
|
||||
goto IfDone1083939031
|
||||
IfElse1083939031:
|
||||
.line 22
|
||||
.line 23
|
||||
getstatic java/lang/System/out Ljava/io/PrintStream;
|
||||
ldc 0x3
|
||||
invokevirtual java/io/PrintStream/print(I)V
|
||||
IfDone1083939031:
|
||||
IfDone1522284422:
|
||||
|
||||
EndGlobal:
|
||||
return
|
||||
.end method
|
||||
|
||||
55
samples/Jasmin/if3.j
Normal file
55
samples/Jasmin/if3.j
Normal file
@@ -0,0 +1,55 @@
|
||||
.class public if3
|
||||
.super java/lang/Object
|
||||
;
|
||||
; standard initializer (calls java.lang.Object's initializer)
|
||||
;
|
||||
.method public <init>()V
|
||||
aload_0
|
||||
invokenonvirtual java/lang/Object/<init>()V
|
||||
return
|
||||
.end method
|
||||
|
||||
.method public static main([Ljava/lang/String;)V
|
||||
|
||||
.limit locals 1
|
||||
.limit stack 5
|
||||
BeginGlobal:
|
||||
.line 2
|
||||
ldc 0x1
|
||||
ldc 0x1
|
||||
if_icmpeq If-811796083
|
||||
goto IfElse-811796083
|
||||
If-811796083:
|
||||
.line 3
|
||||
.line 3
|
||||
ldc 0x0
|
||||
ldc 0x1
|
||||
if_icmpeq If-1001319390
|
||||
goto IfElse-1001319390
|
||||
If-1001319390:
|
||||
.line 4
|
||||
.line 4
|
||||
getstatic java/lang/System/out Ljava/io/PrintStream;
|
||||
ldc 0x1
|
||||
invokevirtual java/io/PrintStream/print(I)V
|
||||
goto IfDone-1001319390
|
||||
IfElse-1001319390:
|
||||
.line 6
|
||||
.line 6
|
||||
getstatic java/lang/System/out Ljava/io/PrintStream;
|
||||
ldc 0x2
|
||||
invokevirtual java/io/PrintStream/print(I)V
|
||||
IfDone-1001319390:
|
||||
goto IfDone-811796083
|
||||
IfElse-811796083:
|
||||
.line 8
|
||||
.line 8
|
||||
getstatic java/lang/System/out Ljava/io/PrintStream;
|
||||
ldc 0x3
|
||||
invokevirtual java/io/PrintStream/print(I)V
|
||||
IfDone-811796083:
|
||||
|
||||
EndGlobal:
|
||||
return
|
||||
.end method
|
||||
|
||||
37
samples/Jasmin/if4.j
Normal file
37
samples/Jasmin/if4.j
Normal file
@@ -0,0 +1,37 @@
|
||||
.class public if4
|
||||
.super java/lang/Object
|
||||
;
|
||||
; standard initializer (calls java.lang.Object's initializer)
|
||||
;
|
||||
.method public <init>()V
|
||||
aload_0
|
||||
invokenonvirtual java/lang/Object/<init>()V
|
||||
return
|
||||
.end method
|
||||
|
||||
.method public static main([Ljava/lang/String;)V
|
||||
|
||||
.limit locals 1
|
||||
.limit stack 5
|
||||
BeginGlobal:
|
||||
.line 2
|
||||
ldc 0x1
|
||||
ldc 0x1
|
||||
if_icmpne IfNot1919266740
|
||||
.line 2
|
||||
.line 2
|
||||
ldc 0x1
|
||||
ldc 0x1
|
||||
if_icmpne IfNot613368541
|
||||
.line 2
|
||||
.line 2
|
||||
getstatic java/lang/System/out Ljava/io/PrintStream;
|
||||
ldc 0x1
|
||||
invokevirtual java/io/PrintStream/print(I)V
|
||||
IfNot613368541:
|
||||
IfNot1919266740:
|
||||
|
||||
EndGlobal:
|
||||
return
|
||||
.end method
|
||||
|
||||
54
samples/Jasmin/op1.j
Normal file
54
samples/Jasmin/op1.j
Normal file
@@ -0,0 +1,54 @@
|
||||
.class public op1
|
||||
.super java/lang/Object
|
||||
;
|
||||
; standard initializer (calls java.lang.Object's initializer)
|
||||
;
|
||||
.method public <init>()V
|
||||
aload_0
|
||||
invokenonvirtual java/lang/Object/<init>()V
|
||||
return
|
||||
.end method
|
||||
|
||||
.method public static main([Ljava/lang/String;)V
|
||||
|
||||
.limit locals 1
|
||||
.limit stack 5
|
||||
BeginGlobal:
|
||||
.line 2
|
||||
getstatic java/lang/System/out Ljava/io/PrintStream;
|
||||
ldc 0x1
|
||||
ldc 0x1
|
||||
iadd
|
||||
invokevirtual java/io/PrintStream/println(I)V
|
||||
|
||||
.line 3
|
||||
getstatic java/lang/System/out Ljava/io/PrintStream;
|
||||
ldc 0xa
|
||||
ldc 0x5
|
||||
isub
|
||||
invokevirtual java/io/PrintStream/println(I)V
|
||||
|
||||
.line 4
|
||||
getstatic java/lang/System/out Ljava/io/PrintStream;
|
||||
ldc 0x15
|
||||
ldc 0x3
|
||||
idiv
|
||||
invokevirtual java/io/PrintStream/println(I)V
|
||||
|
||||
.line 5
|
||||
getstatic java/lang/System/out Ljava/io/PrintStream;
|
||||
ldc 0x159
|
||||
ldc 0x38
|
||||
imul
|
||||
invokevirtual java/io/PrintStream/println(I)V
|
||||
|
||||
.line 6
|
||||
getstatic java/lang/System/out Ljava/io/PrintStream;
|
||||
ldc 0x52
|
||||
ldc 0x9
|
||||
irem
|
||||
invokevirtual java/io/PrintStream/println(I)V
|
||||
|
||||
EndGlobal:
|
||||
return
|
||||
.end method
|
||||
34
samples/Jasmin/op2.j
Normal file
34
samples/Jasmin/op2.j
Normal file
@@ -0,0 +1,34 @@
|
||||
.class public op2
|
||||
.super java/lang/Object
|
||||
;
|
||||
; standard initializer (calls java.lang.Object's initializer)
|
||||
;
|
||||
.method public <init>()V
|
||||
aload_0
|
||||
invokenonvirtual java/lang/Object/<init>()V
|
||||
return
|
||||
.end method
|
||||
|
||||
.method public static main([Ljava/lang/String;)V
|
||||
|
||||
.limit locals 1
|
||||
.limit stack 5
|
||||
BeginGlobal:
|
||||
.line 2
|
||||
getstatic java/lang/System/out Ljava/io/PrintStream;
|
||||
ldc 0x1
|
||||
ldc 0x0
|
||||
iand
|
||||
invokevirtual java/io/PrintStream/println(Z)V
|
||||
|
||||
.line 3
|
||||
getstatic java/lang/System/out Ljava/io/PrintStream;
|
||||
ldc 0x1
|
||||
ldc 0x0
|
||||
ior
|
||||
invokevirtual java/io/PrintStream/println(Z)V
|
||||
|
||||
EndGlobal:
|
||||
return
|
||||
.end method
|
||||
|
||||
68
samples/Jasmin/op3.j
Normal file
68
samples/Jasmin/op3.j
Normal file
@@ -0,0 +1,68 @@
|
||||
.class public op3
|
||||
.super java/lang/Object
|
||||
;
|
||||
; standard initializer (calls java.lang.Object's initializer)
|
||||
;
|
||||
.method public <init>()V
|
||||
aload_0
|
||||
invokenonvirtual java/lang/Object/<init>()V
|
||||
return
|
||||
.end method
|
||||
|
||||
.method public static main([Ljava/lang/String;)V
|
||||
|
||||
.limit locals 1
|
||||
.limit stack 5
|
||||
BeginGlobal:
|
||||
.line 2
|
||||
getstatic java/lang/System/out Ljava/io/PrintStream;
|
||||
ldc 0x0
|
||||
ldc 0x1
|
||||
if_icmpeq Cmp-1307183590
|
||||
ldc 0x0
|
||||
goto CmpDone-1307183590
|
||||
Cmp-1307183590:
|
||||
ldc 0x1
|
||||
CmpDone-1307183590:
|
||||
invokevirtual java/io/PrintStream/println(Z)V
|
||||
|
||||
.line 3
|
||||
getstatic java/lang/System/out Ljava/io/PrintStream;
|
||||
ldc 0x0
|
||||
ldc 0x0
|
||||
if_icmpeq Cmp-1443270821
|
||||
ldc 0x0
|
||||
goto CmpDone-1443270821
|
||||
Cmp-1443270821:
|
||||
ldc 0x1
|
||||
CmpDone-1443270821:
|
||||
invokevirtual java/io/PrintStream/println(Z)V
|
||||
|
||||
.line 4
|
||||
getstatic java/lang/System/out Ljava/io/PrintStream;
|
||||
ldc 0x1
|
||||
ldc 0x1
|
||||
if_icmpeq Cmp1759327329
|
||||
ldc 0x0
|
||||
goto CmpDone1759327329
|
||||
Cmp1759327329:
|
||||
ldc 0x1
|
||||
CmpDone1759327329:
|
||||
invokevirtual java/io/PrintStream/println(Z)V
|
||||
|
||||
.line 5
|
||||
getstatic java/lang/System/out Ljava/io/PrintStream;
|
||||
ldc 0x1
|
||||
ldc 0x0
|
||||
if_icmpeq Cmp-678570146
|
||||
ldc 0x0
|
||||
goto CmpDone-678570146
|
||||
Cmp-678570146:
|
||||
ldc 0x1
|
||||
CmpDone-678570146:
|
||||
invokevirtual java/io/PrintStream/println(Z)V
|
||||
|
||||
EndGlobal:
|
||||
return
|
||||
.end method
|
||||
|
||||
68
samples/Jasmin/op4.j
Normal file
68
samples/Jasmin/op4.j
Normal file
@@ -0,0 +1,68 @@
|
||||
.class public op4
|
||||
.super java/lang/Object
|
||||
;
|
||||
; standard initializer (calls java.lang.Object's initializer)
|
||||
;
|
||||
.method public <init>()V
|
||||
aload_0
|
||||
invokenonvirtual java/lang/Object/<init>()V
|
||||
return
|
||||
.end method
|
||||
|
||||
.method public static main([Ljava/lang/String;)V
|
||||
|
||||
.limit locals 1
|
||||
.limit stack 5
|
||||
BeginGlobal:
|
||||
.line 2
|
||||
getstatic java/lang/System/out Ljava/io/PrintStream;
|
||||
ldc 0x0
|
||||
ldc 0x1
|
||||
if_icmpne Cmp-191731100
|
||||
ldc 0x0
|
||||
goto CmpDone-191731100
|
||||
Cmp-191731100:
|
||||
ldc 0x1
|
||||
CmpDone-191731100:
|
||||
invokevirtual java/io/PrintStream/println(Z)V
|
||||
|
||||
.line 3
|
||||
getstatic java/lang/System/out Ljava/io/PrintStream;
|
||||
ldc 0x0
|
||||
ldc 0x0
|
||||
if_icmpne Cmp-901585603
|
||||
ldc 0x0
|
||||
goto CmpDone-901585603
|
||||
Cmp-901585603:
|
||||
ldc 0x1
|
||||
CmpDone-901585603:
|
||||
invokevirtual java/io/PrintStream/println(Z)V
|
||||
|
||||
.line 4
|
||||
getstatic java/lang/System/out Ljava/io/PrintStream;
|
||||
ldc 0x1
|
||||
ldc 0x1
|
||||
if_icmpne Cmp1522577937
|
||||
ldc 0x0
|
||||
goto CmpDone1522577937
|
||||
Cmp1522577937:
|
||||
ldc 0x1
|
||||
CmpDone1522577937:
|
||||
invokevirtual java/io/PrintStream/println(Z)V
|
||||
|
||||
.line 5
|
||||
getstatic java/lang/System/out Ljava/io/PrintStream;
|
||||
ldc 0x1
|
||||
ldc 0x0
|
||||
if_icmpne Cmp-1653028684
|
||||
ldc 0x0
|
||||
goto CmpDone-1653028684
|
||||
Cmp-1653028684:
|
||||
ldc 0x1
|
||||
CmpDone-1653028684:
|
||||
invokevirtual java/io/PrintStream/println(Z)V
|
||||
|
||||
EndGlobal:
|
||||
return
|
||||
.end method
|
||||
|
||||
78
samples/JavaScript/chart_composers.gs
Normal file
78
samples/JavaScript/chart_composers.gs
Normal file
@@ -0,0 +1,78 @@
|
||||
/*
|
||||
License
|
||||
Copyright [2013] [Farruco Sanjurjo Arcay]
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
|
||||
*/
|
||||
|
||||
var TagsTotalPerMonth;
|
||||
|
||||
TagsTotalPerMonth = (function(){
|
||||
function TagsTotalPerMonth(){};
|
||||
|
||||
TagsTotalPerMonth.getDatasource = function (category, months, values){
|
||||
return new CategoryMonthlyExpenseBarChartDataSource(category, months, values);
|
||||
};
|
||||
|
||||
TagsTotalPerMonth.getType = function (){ return Charts.ChartType.COLUMN};
|
||||
|
||||
return TagsTotalPerMonth;
|
||||
})();
|
||||
|
||||
|
||||
var TagsTotalPerMonthWithMean;
|
||||
|
||||
TagsTotalPerMonthWithMean = (function(){
|
||||
function TagsTotalPerMonthWithMean(){};
|
||||
|
||||
TagsTotalPerMonthWithMean.getDatasource = function (category, months, values){
|
||||
return new CategoryMonthlyWithMeanExpenseDataSource(category, months, values);
|
||||
};
|
||||
|
||||
TagsTotalPerMonthWithMean.getType = function (){ return Charts.ChartType.LINE};
|
||||
|
||||
return TagsTotalPerMonthWithMean;
|
||||
})();
|
||||
|
||||
|
||||
var TagsAccumulatedPerMonth;
|
||||
|
||||
TagsAccumulatedPerMonth = (function(){
|
||||
function TagsAccumulatedPerMonth(){};
|
||||
|
||||
TagsAccumulatedPerMonth.getDatasource = function (category, months, values){
|
||||
return new CategoryMonthlyAccumulated(category, months, values);
|
||||
};
|
||||
|
||||
TagsAccumulatedPerMonth.getType = function (){ return Charts.ChartType.AREA};
|
||||
|
||||
return TagsAccumulatedPerMonth;
|
||||
})();
|
||||
|
||||
var MonthTotalsPerTags;
|
||||
|
||||
MonthTotalsPerTags = (function(){
|
||||
function MonthTotalsPerTags(){};
|
||||
|
||||
MonthTotalsPerTags.getDatasource = function (month, tags, values){
|
||||
return new CategoryExpenseDataSource(tags, month, values);
|
||||
};
|
||||
|
||||
MonthTotalsPerTags.getType = function (){ return Charts.ChartType.PIE; };
|
||||
|
||||
return MonthTotalsPerTags;
|
||||
})();
|
||||
|
||||
var SavingsFlowChartComposer = (function(){
|
||||
function SavingsFlowChartComposer(){};
|
||||
|
||||
SavingsFlowChartComposer.getDatasource = function(months, values){
|
||||
return new SavingsFlowDataSource(months, values);
|
||||
};
|
||||
|
||||
SavingsFlowChartComposer.getType = function(){ return Charts.ChartType.COLUMN; };
|
||||
|
||||
return SavingsFlowChartComposer;
|
||||
})();
|
||||
150
samples/JavaScript/itau.gs
Normal file
150
samples/JavaScript/itau.gs
Normal file
@@ -0,0 +1,150 @@
|
||||
/*
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2014 Thiago Brandão Damasceno
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
// based on http://ctrlq.org/code/19053-send-to-google-drive
|
||||
function sendToGoogleDrive() {
|
||||
|
||||
var gmailLabels = 'inbox';
|
||||
var driveFolder = 'Itaú Notifications';
|
||||
var spreadsheetName = 'itau';
|
||||
var archiveLabel = 'itau.processed';
|
||||
var itauNotificationEmail = 'comunicacaodigital@itau-unibanco.com.br';
|
||||
var filter = "from: " +
|
||||
itauNotificationEmail +
|
||||
" -label:" +
|
||||
archiveLabel +
|
||||
" label:" +
|
||||
gmailLabels;
|
||||
|
||||
// Create label for 'itau.processed' if it doesn't exist
|
||||
var moveToLabel = GmailApp.getUserLabelByName(archiveLabel);
|
||||
|
||||
if (!moveToLabel) {
|
||||
moveToLabel = GmailApp.createLabel(archiveLabel);
|
||||
}
|
||||
|
||||
// Create folder 'Itaú Notifications' if it doesn't exist
|
||||
var folders = DriveApp.getFoldersByName(driveFolder);
|
||||
var folder;
|
||||
|
||||
if (folders.hasNext()) {
|
||||
folder = folders.next();
|
||||
} else {
|
||||
folder = DriveApp.createFolder(driveFolder);
|
||||
}
|
||||
|
||||
// Create spreadsheet file 'itau' if it doesn't exist
|
||||
var files = folder.getFilesByName(spreadsheetName);
|
||||
|
||||
// File is in DriveApp
|
||||
// Doc is in SpreadsheetApp
|
||||
// They are not interchangeable
|
||||
var file, doc;
|
||||
|
||||
// Confusing :\
|
||||
// As per: https://code.google.com/p/google-apps-script-issues/issues/detail?id=3578
|
||||
if (files.hasNext()){
|
||||
file = files.next();
|
||||
doc = SpreadsheetApp.openById(file.getId());
|
||||
} else {
|
||||
doc = SpreadsheetApp.create(spreadsheetName);
|
||||
file = DriveApp.getFileById(doc.getId());
|
||||
folder.addFile(file);
|
||||
DriveApp.removeFile(file);
|
||||
}
|
||||
|
||||
var sheet = doc.getSheets()[0];
|
||||
|
||||
// Append header if first line
|
||||
if(sheet.getLastRow() == 0){
|
||||
sheet.appendRow(['Conta', 'Operação', 'Valor', 'Data', 'Hora', 'Email ID']);
|
||||
}
|
||||
|
||||
var message, messages, account, operation, value, date, hour, emailID, plainBody;
|
||||
var accountRegex = /Conta: (XXX[0-9\-]+)/;
|
||||
var operationRegex = /Tipo de operação: ([A-Z]+)/;
|
||||
var paymentRegex = /Pagamento de ([0-9A-Za-z\-]+)\ ?([0-9]+)?/;
|
||||
var valueRegex = /Valor: R\$ ([0-9\,\.]+)/;
|
||||
var dateRegex = /Data: ([0-9\/]+)/;
|
||||
var hourRegex = /Hora: ([0-9\:]+)/;
|
||||
var emailIDRegex = /E-mail nº ([0-9]+)/;
|
||||
|
||||
var threads = GmailApp.search(filter, 0, 100);
|
||||
|
||||
for (var x = 0; x < threads.length; x++) {
|
||||
messages = threads[x].getMessages();
|
||||
|
||||
for (var i = 0; i < messages.length; i++) {
|
||||
account, operation, value, date, hour, emailID = [];
|
||||
|
||||
message = messages[i];
|
||||
|
||||
plainBody = message.getPlainBody();
|
||||
|
||||
if(accountRegex.test(plainBody)) {
|
||||
account = RegExp.$1;
|
||||
}
|
||||
|
||||
if(operationRegex.test(plainBody)) {
|
||||
operation = RegExp.$1;
|
||||
}
|
||||
|
||||
if(valueRegex.test(plainBody)) {
|
||||
value = RegExp.$1;
|
||||
}
|
||||
|
||||
if(dateRegex.test(plainBody)) {
|
||||
date = RegExp.$1;
|
||||
}
|
||||
|
||||
if(hourRegex.test(plainBody)) {
|
||||
hour = RegExp.$1;
|
||||
}
|
||||
|
||||
if(emailIDRegex.test(plainBody)){
|
||||
emailID = RegExp.$1;
|
||||
}
|
||||
|
||||
if(paymentRegex.test(plainBody)){
|
||||
operation = RegExp.$1;
|
||||
if(RegExp.$2){
|
||||
operation += ' ' + RegExp.$2
|
||||
}
|
||||
date = hour = ' - ';
|
||||
}
|
||||
|
||||
if(account && operation && value && date && hour){
|
||||
sheet.appendRow([account, operation, value, date, hour, emailID]);
|
||||
}
|
||||
|
||||
// Logger.log(account);
|
||||
// Logger.log(operation);
|
||||
// Logger.log(value);
|
||||
// Logger.log(date);
|
||||
// Logger.log(hour);
|
||||
}
|
||||
|
||||
threads[x].addLabel(moveToLabel);
|
||||
}
|
||||
}
|
||||
93
samples/JavaScript/namespace.js
Normal file
93
samples/JavaScript/namespace.js
Normal file
@@ -0,0 +1,93 @@
|
||||
(function(root, factory) {
|
||||
if (typeof define === 'function' && define.amd) {
|
||||
define(['lodash'], factory);
|
||||
} else if (typeof exports !== 'undefined') {
|
||||
module.exports = factory(require('lodash'));
|
||||
} else {
|
||||
root.Namespace = factory(root._);
|
||||
}
|
||||
})(this, function(_) {
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* @module namespace
|
||||
* @class namespace
|
||||
*/
|
||||
function Namespace() {}
|
||||
|
||||
/**
|
||||
* Regex for splitting keypaths into arrays.
|
||||
*
|
||||
* @private
|
||||
* @const {RegExp}
|
||||
* @type
|
||||
*/
|
||||
var KEYPATH_SPLITTER = /\./g;
|
||||
|
||||
/**
|
||||
* An internal cache to avoid calculating a keypath more than once.
|
||||
*
|
||||
* @private
|
||||
* @type {Object}
|
||||
*/
|
||||
var _keypaths = {};
|
||||
|
||||
_.extend(Namespace.prototype, {
|
||||
|
||||
/**
|
||||
* Adds a definition to the namespace object.
|
||||
*
|
||||
* @public
|
||||
* @instance
|
||||
* @method add
|
||||
* @param {String} keypath - The keypath for the definition to be added at.
|
||||
* @param {Function|Object} definition - The definition to be added.
|
||||
* @return {Function|Object} - The definition.
|
||||
*/
|
||||
add: function(keypath, definition) {
|
||||
return this._walk(keypath, function(memo, name, index, keypath) {
|
||||
if (index + 1 === keypath.length) {
|
||||
memo[name] = _.extend(definition, memo[name]);
|
||||
}
|
||||
return memo[name] || (memo[name] = {});
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
* Retrieves a definition from the namespace safely.
|
||||
*
|
||||
* @public
|
||||
* @instance
|
||||
* @method get
|
||||
* @param {String} keypath - The keypath to lookup a definition for.
|
||||
* @returns {Function|Object|undefined} - The definition if it exists, otherwise `undefined`.
|
||||
*/
|
||||
get: function(keypath) {
|
||||
return this._walk(keypath);
|
||||
},
|
||||
|
||||
/**
|
||||
* An internal function for walking a keypath.
|
||||
*
|
||||
* @private
|
||||
* @instance
|
||||
* @method _walk
|
||||
* @param {String} keypath - The keypath to walk through.
|
||||
* @param {Function} [callback] - An optional callback to be called at each item in the path.
|
||||
* @returns {function|Object|undefined} - The reduced keypath.
|
||||
*/
|
||||
_walk: function(keypath, callback) {
|
||||
return _.reduce(
|
||||
_keypaths[keypath] || (_keypaths[keypath] = keypath.split(KEYPATH_SPLITTER)),
|
||||
callback || function(memo, name) {
|
||||
return memo && memo[name];
|
||||
},
|
||||
this
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
return Namespace;
|
||||
});
|
||||
|
||||
//# sourceMappingURL=namespace.js.map
|
||||
38
samples/LoomScript/HelloWorld.ls
Normal file
38
samples/LoomScript/HelloWorld.ls
Normal file
@@ -0,0 +1,38 @@
|
||||
package
|
||||
{
|
||||
import loom.Application;
|
||||
import loom2d.display.StageScaleMode;
|
||||
import loom2d.ui.SimpleLabel;
|
||||
|
||||
/**
|
||||
The HelloWorld app renders a label with its name on it,
|
||||
and traces 'hello' to the log.
|
||||
*/
|
||||
public class HelloWorld extends Application
|
||||
{
|
||||
|
||||
override public function run():void
|
||||
{
|
||||
stage.scaleMode = StageScaleMode.LETTERBOX;
|
||||
centeredMessage(simpleLabel, this.getFullTypeName());
|
||||
|
||||
trace("hello");
|
||||
}
|
||||
|
||||
// a convenience getter that generates a label and adds it to the stage
|
||||
private function get simpleLabel():SimpleLabel
|
||||
{
|
||||
return stage.addChild(new SimpleLabel("assets/Curse-hd.fnt")) as SimpleLabel;
|
||||
}
|
||||
|
||||
// a utility to set the label's text and then center it on the stage
|
||||
private function centeredMessage(label:SimpleLabel, msg:String):void
|
||||
{
|
||||
label.text = msg;
|
||||
label.center();
|
||||
label.x = stage.stageWidth / 2;
|
||||
label.y = (stage.stageHeight / 2) - (label.height / 2);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
137
samples/LoomScript/SyntaxExercise.ls
Normal file
137
samples/LoomScript/SyntaxExercise.ls
Normal file
@@ -0,0 +1,137 @@
|
||||
package
|
||||
{
|
||||
import loom.Application;
|
||||
|
||||
public interface I {}
|
||||
public class C {}
|
||||
public class B extends C implements I {}
|
||||
final public class A extends B {}
|
||||
|
||||
delegate ToCompute(s:String, o:Object):Number;
|
||||
|
||||
public enum Enumeration
|
||||
{
|
||||
foo,
|
||||
baz,
|
||||
cat,
|
||||
}
|
||||
|
||||
struct P {
|
||||
public var x:Number = 0;
|
||||
public var y:Number = 0;
|
||||
public static operator function =(a:P, b:P):P
|
||||
{
|
||||
a.x = b.x;
|
||||
a.y = b.y;
|
||||
|
||||
return a;
|
||||
}
|
||||
}
|
||||
|
||||
// single-line comment
|
||||
|
||||
/*
|
||||
Multi-line comment
|
||||
*/
|
||||
|
||||
/**
|
||||
Doc comment
|
||||
*/
|
||||
public class SyntaxExercise extends Application
|
||||
{
|
||||
static public var classVar:String = 'class variable';
|
||||
public const CONST:String = 'constant';
|
||||
private var _a:A = new A();
|
||||
public var _d:ToCompute;
|
||||
|
||||
override public function run():void
|
||||
{
|
||||
trace("hello");
|
||||
}
|
||||
|
||||
private function get a():A { return _a; }
|
||||
private function set a(value:A):void { _a = value; }
|
||||
|
||||
private function variousTypes(defaultValue:String = ''):void
|
||||
{
|
||||
var nil:Object = null;
|
||||
var b1:Boolean = true;
|
||||
var b2:Boolean = false;
|
||||
var n1:Number = 0.123;
|
||||
var n2:Number = 12345;
|
||||
var n3:Number = 0xfed;
|
||||
var s1:String = 'single-quotes with "quotes" inside';
|
||||
var s2:String = "double-quotes with 'quotes' inside";
|
||||
var f1:Function = function (life:String, universe:Object, ...everything):Number { return 42; };
|
||||
var v1:Vector.<Number> = [1, 2];
|
||||
var d1:Dictionary.<String, Number> = { 'three': 3, 'four': 4 };
|
||||
|
||||
_d += f1;
|
||||
_d -= f1;
|
||||
}
|
||||
|
||||
private function variousOps():void
|
||||
{
|
||||
var a = ((100 + 200 - 0) / 300) % 2;
|
||||
var b = 100 * 30;
|
||||
var d = true && (b > 301);
|
||||
var e = 0x10 | 0x01;
|
||||
|
||||
b++; b--;
|
||||
a += 300; a -= 5; a *= 4; a /= 2; a %= 7;
|
||||
|
||||
var castable1:Boolean = (a is B);
|
||||
var castable2:Boolean = (a as B) != null;
|
||||
var cast:String = B(a).toString();
|
||||
var instanced:Boolean = (_a instanceof A);
|
||||
}
|
||||
|
||||
private function variousFlow():void
|
||||
{
|
||||
var n:Number = Math.random();
|
||||
if (n > 0.6)
|
||||
trace('top 40!');
|
||||
else if(n > 0.3)
|
||||
trace('mid 30!');
|
||||
else
|
||||
trace('bottom 30');
|
||||
|
||||
var flip:String = (Math.random() > 0.5) ? 'heads' : 'tails';
|
||||
|
||||
for (var i = 0; i < 100; i++)
|
||||
trace(i);
|
||||
|
||||
var v:Vector.<String> = ['a', 'b', 'c'];
|
||||
for each (var s:String in v)
|
||||
trace(s);
|
||||
|
||||
var d:Dictionary.<String, Number> = { 'one': 1 };
|
||||
for (var key1:String in d)
|
||||
trace(key1);
|
||||
|
||||
for (var key2:Number in v)
|
||||
trace(key2);
|
||||
|
||||
while (i > 0)
|
||||
{
|
||||
i--;
|
||||
if (i == 13) continue;
|
||||
trace(i);
|
||||
}
|
||||
|
||||
do
|
||||
{
|
||||
i++;
|
||||
}
|
||||
while (i < 10);
|
||||
|
||||
switch (Math.floor(Math.random()) * 3 + 1)
|
||||
{
|
||||
case 1 : trace('rock'); break;
|
||||
case 2 : trace('paper'); break;
|
||||
default: trace('scissors'); break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
434
samples/Objective-J/AppController.j
Normal file
434
samples/Objective-J/AppController.j
Normal file
@@ -0,0 +1,434 @@
|
||||
//
|
||||
// AppController.j
|
||||
// FlickrPhoto
|
||||
//
|
||||
// Created by Ross Boucher.
|
||||
// Copyright 2008 - 2010, 280 North, Inc. All rights reserved.
|
||||
|
||||
@import <Foundation/Foundation.j>
|
||||
@import <AppKit/AppKit.j>
|
||||
|
||||
var SliderToolbarItemIdentifier = "SliderToolbarItemIdentifier",
|
||||
AddToolbarItemIdentifier = "AddToolbarItemIdentifier",
|
||||
RemoveToolbarItemIdentifier = "RemoveToolbarItemIdentifier";
|
||||
|
||||
/*
|
||||
Important note about CPJSONPConnection: CPJSONPConnection is ONLY for JSONP APIs.
|
||||
If aren't sure you NEED JSONP (see http://ajaxian.com/archives/jsonp-json-with-padding ),
|
||||
you most likely don't want to use CPJSONPConnection, but rather the more standard
|
||||
CPURLConnection. CPJSONPConnection is designed for cross-domain
|
||||
connections, and if you are making requests to the same domain (as most web
|
||||
applications do), you do not need it.
|
||||
*/
|
||||
|
||||
@implementation AppController : CPObject
|
||||
{
|
||||
CPString lastIdentifier;
|
||||
CPDictionary photosets;
|
||||
|
||||
CPCollectionView listCollectionView;
|
||||
CPCollectionView photosCollectionView;
|
||||
}
|
||||
|
||||
- (void)applicationDidFinishLaunching:(CPNotification)aNotification
|
||||
{
|
||||
//the first thing we need to do is create a window to take up the full screen
|
||||
//we'll also create a toolbar to go with it, and grab its size for future reference
|
||||
|
||||
var theWindow = [[CPWindow alloc] initWithContentRect:CGRectMakeZero() styleMask:CPBorderlessBridgeWindowMask],
|
||||
contentView = [theWindow contentView],
|
||||
toolbar = [[CPToolbar alloc] initWithIdentifier:"Photos"],
|
||||
bounds = [contentView bounds];
|
||||
|
||||
//we tell the toolbar that we want to be its delegate and attach it to theWindow
|
||||
[toolbar setDelegate:self];
|
||||
[toolbar setVisible:true];
|
||||
[theWindow setToolbar:toolbar];
|
||||
|
||||
photosets = [CPDictionary dictionary]; //storage for our sets of photos return from Flickr
|
||||
|
||||
//now we create a scroll view to contain the list of collections of photos (photosets)
|
||||
//inside the scroll view, we'll place our collection view, which manages a collection of "cells"
|
||||
//each cell will represent one photo collection, and choosing cells will select that collection
|
||||
|
||||
var listScrollView = [[CPScrollView alloc] initWithFrame:CGRectMake(0, 0, 200, CGRectGetHeight(bounds) - 58)];
|
||||
[listScrollView setAutohidesScrollers:YES];
|
||||
[listScrollView setAutoresizingMask:CPViewHeightSizable];
|
||||
[[listScrollView contentView] setBackgroundColor:[CPColor colorWithRed:213.0 / 255.0 green:221.0 / 255.0 blue:230.0 / 255.0 alpha:1.0]];
|
||||
|
||||
//we create the collection view cells by creating a single prototype (CPCollectionViewItem) and setting its view.
|
||||
//the CPCollectionView class will then duplicate this item as many times as it needs
|
||||
|
||||
var photosListItem = [[CPCollectionViewItem alloc] init];
|
||||
[photosListItem setView:[[PhotosListCell alloc] initWithFrame:CGRectMakeZero()]];
|
||||
|
||||
listCollectionView = [[CPCollectionView alloc] initWithFrame:CGRectMake(0, 0, 200, 0)];
|
||||
|
||||
[listCollectionView setDelegate:self]; //we want delegate methods
|
||||
[listCollectionView setItemPrototype:photosListItem]; //set the item prototype
|
||||
|
||||
[listCollectionView setMinItemSize:CGSizeMake(20.0, 45.0)];
|
||||
[listCollectionView setMaxItemSize:CGSizeMake(1000.0, 45.0)];
|
||||
[listCollectionView setMaxNumberOfColumns:1]; //setting a single column will make this appear as a vertical list
|
||||
|
||||
[listCollectionView setVerticalMargin:0.0];
|
||||
[listCollectionView setAutoresizingMask:CPViewWidthSizable];
|
||||
|
||||
//finally, we put our collection view inside the scroll view as it's document view, so it can be scrolled
|
||||
[listScrollView setDocumentView:listCollectionView];
|
||||
|
||||
//and we add it to the window's content view, so it will show up on the screen
|
||||
[contentView addSubview:listScrollView];
|
||||
|
||||
//repeat the process with another collection view for the actual photos
|
||||
//this time we'll use a different view for the prototype (PhotoCell)
|
||||
|
||||
var photoItem = [[CPCollectionViewItem alloc] init];
|
||||
[photoItem setView:[[PhotoCell alloc] initWithFrame:CGRectMake(0, 0, 150, 150)]];
|
||||
|
||||
var scrollView = [[CPScrollView alloc] initWithFrame:CGRectMake(200, 0, CGRectGetWidth(bounds) - 200, CGRectGetHeight(bounds) - 58)];
|
||||
|
||||
photosCollectionView = [[CPCollectionView alloc] initWithFrame:CGRectMake(0, 0, CGRectGetWidth(bounds) - 200, 0)];
|
||||
|
||||
[photosCollectionView setDelegate:self];
|
||||
[photosCollectionView setItemPrototype:photoItem];
|
||||
|
||||
[photosCollectionView setMinItemSize:CGSizeMake(150, 150)];
|
||||
[photosCollectionView setMaxItemSize:CGSizeMake(150, 150)];
|
||||
[photosCollectionView setAutoresizingMask:CPViewWidthSizable];
|
||||
|
||||
[scrollView setAutoresizingMask:CPViewHeightSizable | CPViewWidthSizable];
|
||||
[scrollView setDocumentView:photosCollectionView];
|
||||
[scrollView setAutohidesScrollers:YES];
|
||||
|
||||
[[scrollView contentView] setBackgroundColor:[CPColor colorWithCalibratedWhite:0.25 alpha:1.0]];
|
||||
|
||||
[contentView addSubview:scrollView];
|
||||
|
||||
//bring forward the window to display it
|
||||
[theWindow orderFront:self];
|
||||
|
||||
//get the most interesting photos on flickr
|
||||
var request = [CPURLRequest requestWithURL:"http://www.flickr.com/services/rest/?method=flickr.interestingness.getList&per_page=20&format=json&api_key=ca4dd89d3dfaeaf075144c3fdec76756"];
|
||||
|
||||
// see important note about CPJSONPConnection above
|
||||
var connection = [CPJSONPConnection sendRequest:request callback:"jsoncallback" delegate:self];
|
||||
|
||||
lastIdentifier = "Interesting Photos";
|
||||
}
|
||||
|
||||
- (void)add:(id)sender
|
||||
{
|
||||
var string = prompt("Enter a tag to search Flickr for photos.");
|
||||
|
||||
if (string)
|
||||
{
|
||||
//create a new request for the photos with the tag returned from the javascript prompt
|
||||
var request = [CPURLRequest requestWithURL:"http://www.flickr.com/services/rest/?"+
|
||||
"method=flickr.photos.search&tags="+encodeURIComponent(string)+
|
||||
"&media=photos&machine_tag_mode=any&per_page=20&format=json&api_key=ca4dd89d3dfaeaf075144c3fdec76756"];
|
||||
|
||||
// see important note about CPJSONPConnection above
|
||||
[CPJSONPConnection sendRequest:request callback:"jsoncallback" delegate:self];
|
||||
|
||||
lastIdentifier = string;
|
||||
}
|
||||
}
|
||||
|
||||
- (void)remove:(id)sender
|
||||
{
|
||||
//remove this photo
|
||||
[self removeImageListWithIdentifier:[[photosets allKeys] objectAtIndex:[[listCollectionView selectionIndexes] firstIndex]]];
|
||||
}
|
||||
|
||||
- (void)addImageList:(CPArray)images withIdentifier:(CPString)aString
|
||||
{
|
||||
[photosets setObject:images forKey:aString];
|
||||
|
||||
[listCollectionView setContent:[[photosets allKeys] copy]];
|
||||
[listCollectionView setSelectionIndexes:[CPIndexSet indexSetWithIndex:[[photosets allKeys] indexOfObject:aString]]];
|
||||
}
|
||||
|
||||
- (void)removeImageListWithIdentifier:(CPString)aString
|
||||
{
|
||||
var nextIndex = MAX([[listCollectionView content] indexOfObject:aString] - 1, 0);
|
||||
|
||||
[photosets removeObjectForKey:aString];
|
||||
|
||||
[listCollectionView setContent:[[photosets allKeys] copy]];
|
||||
[listCollectionView setSelectionIndexes:[CPIndexSet indexSetWithIndex:nextIndex]];
|
||||
}
|
||||
|
||||
- (void)adjustImageSize:(id)sender
|
||||
{
|
||||
var newSize = [sender value];
|
||||
|
||||
[photosCollectionView setMinItemSize:CGSizeMake(newSize, newSize)];
|
||||
[photosCollectionView setMaxItemSize:CGSizeMake(newSize, newSize)];
|
||||
}
|
||||
|
||||
- (void)collectionViewDidChangeSelection:(CPCollectionView)aCollectionView
|
||||
{
|
||||
if (aCollectionView == listCollectionView)
|
||||
{
|
||||
var listIndex = [[listCollectionView selectionIndexes] firstIndex];
|
||||
|
||||
if (listIndex === CPNotFound)
|
||||
return;
|
||||
|
||||
var key = [listCollectionView content][listIndex];
|
||||
|
||||
[photosCollectionView setContent:[photosets objectForKey:key]];
|
||||
[photosCollectionView setSelectionIndexes:[CPIndexSet indexSet]];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)connection:(CPJSONPConnection)aConnection didReceiveData:(CPString)data
|
||||
{
|
||||
//this method is called when the network request returns. the data is the returned
|
||||
//information from flickr. we set the array of photo urls as the data to our collection view
|
||||
|
||||
[self addImageList:data.photos.photo withIdentifier:lastIdentifier];
|
||||
}
|
||||
|
||||
- (void)connection:(CPJSONPConnection)aConnection didFailWithError:(CPString)error
|
||||
{
|
||||
alert(error); //a network error occurred
|
||||
}
|
||||
|
||||
//these two methods are the toolbar delegate methods, and tell the toolbar what it should display to the user
|
||||
|
||||
- (CPArray)toolbarAllowedItemIdentifiers:(CPToolbar)aToolbar
|
||||
{
|
||||
return [self toolbarDefaultItemIdentifiers:aToolbar];
|
||||
}
|
||||
|
||||
- (CPArray)toolbarDefaultItemIdentifiers:(CPToolbar)aToolbar
|
||||
{
|
||||
return [AddToolbarItemIdentifier, RemoveToolbarItemIdentifier, CPToolbarFlexibleSpaceItemIdentifier, SliderToolbarItemIdentifier];
|
||||
}
|
||||
|
||||
//this delegate method returns the actual toolbar item for the given identifier
|
||||
|
||||
- (CPToolbarItem)toolbar:(CPToolbar)aToolbar itemForItemIdentifier:(CPString)anItemIdentifier willBeInsertedIntoToolbar:(BOOL)aFlag
|
||||
{
|
||||
var toolbarItem = [[CPToolbarItem alloc] initWithItemIdentifier:anItemIdentifier];
|
||||
|
||||
if (anItemIdentifier == SliderToolbarItemIdentifier)
|
||||
{
|
||||
[toolbarItem setView:[[PhotoResizeView alloc] initWithFrame:CGRectMake(0, 0, 180, 32)]];
|
||||
[toolbarItem setMinSize:CGSizeMake(180, 32)];
|
||||
[toolbarItem setMaxSize:CGSizeMake(180, 32)];
|
||||
[toolbarItem setLabel:"Scale"];
|
||||
}
|
||||
else if (anItemIdentifier == AddToolbarItemIdentifier)
|
||||
{
|
||||
var image = [[CPImage alloc] initWithContentsOfFile:[[CPBundle mainBundle] pathForResource:"add.png"] size:CPSizeMake(30, 25)],
|
||||
highlighted = [[CPImage alloc] initWithContentsOfFile:[[CPBundle mainBundle] pathForResource:"addHighlighted.png"] size:CPSizeMake(30, 25)];
|
||||
|
||||
[toolbarItem setImage:image];
|
||||
[toolbarItem setAlternateImage:highlighted];
|
||||
|
||||
[toolbarItem setTarget:self];
|
||||
[toolbarItem setAction:@selector(add:)];
|
||||
[toolbarItem setLabel:"Add Photo List"];
|
||||
|
||||
[toolbarItem setMinSize:CGSizeMake(32, 32)];
|
||||
[toolbarItem setMaxSize:CGSizeMake(32, 32)];
|
||||
}
|
||||
else if (anItemIdentifier == RemoveToolbarItemIdentifier)
|
||||
{
|
||||
var image = [[CPImage alloc] initWithContentsOfFile:[[CPBundle mainBundle] pathForResource:"remove.png"] size:CPSizeMake(30, 25)],
|
||||
highlighted = [[CPImage alloc] initWithContentsOfFile:[[CPBundle mainBundle] pathForResource:"removeHighlighted.png"] size:CPSizeMake(30, 25)];
|
||||
|
||||
[toolbarItem setImage:image];
|
||||
[toolbarItem setAlternateImage:highlighted];
|
||||
|
||||
[toolbarItem setTarget:self];
|
||||
[toolbarItem setAction:@selector(remove:)];
|
||||
[toolbarItem setLabel:"Remove Photo List"];
|
||||
|
||||
[toolbarItem setMinSize:CGSizeMake(32, 32)];
|
||||
[toolbarItem setMaxSize:CGSizeMake(32, 32)];
|
||||
}
|
||||
|
||||
return toolbarItem;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
/*
|
||||
This code demonstrates how to add a category to an existing class.
|
||||
In this case, we are adding the class method +flickr_labelWithText: to
|
||||
the CPTextField class. Later on, we can call [CPTextField flickr_labelWithText:"foo"]
|
||||
to return a new text field with the string foo.
|
||||
Best practices suggest prefixing category methods with your unique prefix, to prevent collisions.
|
||||
*/
|
||||
|
||||
@implementation CPTextField (CreateLabel)
|
||||
|
||||
+ (CPTextField)flickr_labelWithText:(CPString)aString
|
||||
{
|
||||
var label = [[CPTextField alloc] initWithFrame:CGRectMakeZero()];
|
||||
|
||||
[label setStringValue:aString];
|
||||
[label sizeToFit];
|
||||
[label setTextShadowColor:[CPColor whiteColor]];
|
||||
[label setTextShadowOffset:CGSizeMake(0, 1)];
|
||||
|
||||
return label;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
// This class wraps our slider + labels combo
|
||||
|
||||
@implementation PhotoResizeView : CPView
|
||||
{
|
||||
}
|
||||
|
||||
- (id)initWithFrame:(CGRect)aFrame
|
||||
{
|
||||
self = [super initWithFrame:aFrame];
|
||||
|
||||
var slider = [[CPSlider alloc] initWithFrame:CGRectMake(30, CGRectGetHeight(aFrame) / 2.0 - 8, CGRectGetWidth(aFrame) - 65, 24)];
|
||||
|
||||
[slider setMinValue:50.0];
|
||||
[slider setMaxValue:250.0];
|
||||
[slider setIntValue:150.0];
|
||||
[slider setAction:@selector(adjustImageSize:)];
|
||||
|
||||
[self addSubview:slider];
|
||||
|
||||
var label = [CPTextField flickr_labelWithText:"50"];
|
||||
[label setFrameOrigin:CGPointMake(0, CGRectGetHeight(aFrame) / 2.0 - 4.0)];
|
||||
[self addSubview:label];
|
||||
|
||||
label = [CPTextField flickr_labelWithText:"250"];
|
||||
[label setFrameOrigin:CGPointMake(CGRectGetWidth(aFrame) - CGRectGetWidth([label frame]), CGRectGetHeight(aFrame) / 2.0 - 4.0)];
|
||||
[self addSubview:label];
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
// This class displays a single photo collection inside our list of photo collecitions
|
||||
|
||||
@implementation PhotosListCell : CPView
|
||||
{
|
||||
CPTextField label;
|
||||
CPView highlightView;
|
||||
}
|
||||
|
||||
- (void)setRepresentedObject:(JSObject)anObject
|
||||
{
|
||||
if (!label)
|
||||
{
|
||||
label = [[CPTextField alloc] initWithFrame:CGRectInset([self bounds], 4, 4)];
|
||||
|
||||
[label setFont:[CPFont systemFontOfSize:16.0]];
|
||||
[label setTextShadowColor:[CPColor whiteColor]];
|
||||
[label setTextShadowOffset:CGSizeMake(0, 1)];
|
||||
|
||||
[self addSubview:label];
|
||||
}
|
||||
|
||||
[label setStringValue:anObject];
|
||||
[label sizeToFit];
|
||||
|
||||
[label setFrameOrigin:CGPointMake(10,CGRectGetHeight([label bounds]) / 2.0)];
|
||||
}
|
||||
|
||||
- (void)setSelected:(BOOL)flag
|
||||
{
|
||||
if (!highlightView)
|
||||
{
|
||||
highlightView = [[CPView alloc] initWithFrame:CGRectCreateCopy([self bounds])];
|
||||
[highlightView setBackgroundColor:[CPColor blueColor]];
|
||||
}
|
||||
|
||||
if (flag)
|
||||
{
|
||||
[self addSubview:highlightView positioned:CPWindowBelow relativeTo:label];
|
||||
[label setTextColor:[CPColor whiteColor]];
|
||||
[label setTextShadowColor:[CPColor blackColor]];
|
||||
}
|
||||
else
|
||||
{
|
||||
[highlightView removeFromSuperview];
|
||||
[label setTextColor:[CPColor blackColor]];
|
||||
[label setTextShadowColor:[CPColor whiteColor]];
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
// This class displays a single photo from our collection
|
||||
|
||||
@implementation PhotoCell : CPView
|
||||
{
|
||||
CPImage image;
|
||||
CPImageView imageView;
|
||||
CPView highlightView;
|
||||
}
|
||||
|
||||
- (void)setRepresentedObject:(JSObject)anObject
|
||||
{
|
||||
if (!imageView)
|
||||
{
|
||||
imageView = [[CPImageView alloc] initWithFrame:CGRectMakeCopy([self bounds])];
|
||||
[imageView setAutoresizingMask:CPViewWidthSizable | CPViewHeightSizable];
|
||||
[imageView setImageScaling:CPScaleProportionally];
|
||||
[imageView setHasShadow:YES];
|
||||
[self addSubview:imageView];
|
||||
}
|
||||
|
||||
[image setDelegate:nil];
|
||||
|
||||
image = [[CPImage alloc] initWithContentsOfFile:thumbForFlickrPhoto(anObject)];
|
||||
|
||||
[image setDelegate:self];
|
||||
|
||||
if ([image loadStatus] == CPImageLoadStatusCompleted)
|
||||
[imageView setImage:image];
|
||||
else
|
||||
[imageView setImage:nil];
|
||||
}
|
||||
|
||||
- (void)imageDidLoad:(CPImage)anImage
|
||||
{
|
||||
[imageView setImage:anImage];
|
||||
}
|
||||
|
||||
- (void)setSelected:(BOOL)flag
|
||||
{
|
||||
if (!highlightView)
|
||||
{
|
||||
highlightView = [[CPView alloc] initWithFrame:[self bounds]];
|
||||
[highlightView setBackgroundColor:[CPColor colorWithCalibratedWhite:0.8 alpha:0.6]];
|
||||
[highlightView setAutoresizingMask:CPViewWidthSizable | CPViewHeightSizable];
|
||||
}
|
||||
|
||||
if (flag)
|
||||
{
|
||||
[highlightView setFrame:[self bounds]];
|
||||
[self addSubview:highlightView positioned:CPWindowBelow relativeTo:imageView];
|
||||
}
|
||||
else
|
||||
[highlightView removeFromSuperview];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
// helper javascript functions for turning a Flickr photo object into a URL for getting the image
|
||||
|
||||
function urlForFlickrPhoto(photo)
|
||||
{
|
||||
return "http://farm" + photo.farm + ".static.flickr.com/" + photo.server + "/" + photo.id+"_" + photo.secret + ".jpg";
|
||||
}
|
||||
|
||||
function thumbForFlickrPhoto(photo)
|
||||
{
|
||||
return "http://farm" + photo.farm + ".static.flickr.com/" + photo.server + "/" + photo.id + "_" + photo.secret + "_m.jpg";
|
||||
}
|
||||
88
samples/Objective-J/LightsOff.j
Normal file
88
samples/Objective-J/LightsOff.j
Normal file
@@ -0,0 +1,88 @@
|
||||
@import <Foundation/CPObject.j>
|
||||
@import <AppKit/CPView.j>
|
||||
@import <AppKit/CPButton.j>
|
||||
@import <AppKit/CPWebView.j>
|
||||
@import "LOBoard.j"
|
||||
|
||||
@implementation LOInfoView : CPView
|
||||
{
|
||||
}
|
||||
|
||||
- (void)drawRect:(CGRect)r
|
||||
{
|
||||
[[CPColor whiteColor] setFill]
|
||||
var path = [CPBezierPath bezierPath];
|
||||
[path appendBezierPathWithRoundedRect:CGRectMake(5, 0, CGRectGetWidth([self bounds]) - 10.0, CGRectGetHeight([self bounds])) xRadius:10 yRadius:10];
|
||||
[path fill];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation AppController : CPObject
|
||||
{
|
||||
}
|
||||
|
||||
- (CPPanel)initInfoWindow
|
||||
{
|
||||
var infoWindow = [[CPPanel alloc] initWithContentRect:CGRectMake(400, 50, 320, 480) styleMask:CPHUDBackgroundWindowMask | CPResizableWindowMask];
|
||||
[infoWindow setFloatingPanel:YES];
|
||||
|
||||
var _infoContent = [infoWindow contentView],
|
||||
_iconImage = [[CPImage alloc] initWithContentsOfFile:"Resources/icon.png" size:CPSizeMake(59, 60)],
|
||||
_iconView = [[CPImageView alloc] initWithFrame:CGRectMake(125, 0, 59, 60)];
|
||||
|
||||
[_iconView setImage:_iconImage];
|
||||
[_infoContent addSubview:_iconView];
|
||||
|
||||
var _infoView = [[LOInfoView alloc] initWithFrame:CGRectMake(0, 65, 320, 395)],
|
||||
_webView = [[CPWebView alloc] initWithFrame:CGRectMake(20, 0, 270, 370)];
|
||||
|
||||
[_webView loadHTMLString:@"<center><h3>Lights Off</h3></center> <p>Lights Off is a fantastic game exclusively for iPhone and iPod touch and inspired by Tiger Electronic's 'Lights Out'.</p> <p>The goal of the game is simply to switch all of the lights off, but it's harder than it looks! Give the first few levels a try in the playable demo to the left.</p><center><img src='Resources/avail_on_app_store.png'></center>"];
|
||||
|
||||
[_infoView addSubview:_webView];
|
||||
|
||||
[_infoContent addSubview:_infoView];
|
||||
|
||||
return infoWindow;
|
||||
}
|
||||
|
||||
- (void)applicationDidFinishLaunching:(CPNotification)aNotification
|
||||
{
|
||||
/* Enable Logging (DEBUG) */
|
||||
// CPLogRegister(CPLogPopup);
|
||||
|
||||
var rootWindow = [[CPWindow alloc] initWithContentRect:CGRectMakeZero() styleMask:CPBorderlessBridgeWindowMask];
|
||||
[rootWindow setBackgroundColor:[CPColor grayColor]];
|
||||
[rootWindow orderFront:self];
|
||||
|
||||
var infoWindow = [self initInfoWindow],
|
||||
gameWindow = [[CPPanel alloc] initWithContentRect:CGRectMake(50, 50, 324, 482) styleMask:CPHUDBackgroundWindowMask];
|
||||
[gameWindow setFloatingPanel:YES];
|
||||
[gameWindow setTitle:@"Lights Off"];
|
||||
|
||||
contentView = [gameWindow contentView];
|
||||
|
||||
var _board = [[LOBoard alloc] initWithFrame:CGRectMake(2, 0, 320, 480)],
|
||||
_bgImage = [[CPImage alloc] initWithContentsOfFile:"Resources/lo-background.png" size:CPSizeMake(320, 480)];
|
||||
[_board setImage:_bgImage];
|
||||
[_board resetBoard];
|
||||
|
||||
var _buttonImage = [[CPImage alloc] initWithContentsOfFile:"Resources/button-reset.png" size:CPSizeMake(90, 28)],
|
||||
_buttonPressImage = [[CPImage alloc] initWithContentsOfFile:"Resources/button-reset-press.png" size:CPSizeMake(90, 28)],
|
||||
_resetButton = [[CPButton alloc] initWithFrame:CGRectMake(195, 422, 90, 28)];
|
||||
|
||||
[_resetButton setImage:_buttonImage];
|
||||
[_resetButton setAlternateImage:_buttonPressImage];
|
||||
[_resetButton setBordered:NO];
|
||||
|
||||
[contentView addSubview:_board];
|
||||
[contentView addSubview:_resetButton];
|
||||
|
||||
[_resetButton setTarget:_board];
|
||||
[_resetButton setAction:@selector(resetBoard)];
|
||||
|
||||
[gameWindow orderFront:self];
|
||||
[infoWindow orderFront:self];
|
||||
}
|
||||
|
||||
@end
|
||||
47
samples/Objective-J/iTunesLayout.j
Normal file
47
samples/Objective-J/iTunesLayout.j
Normal file
@@ -0,0 +1,47 @@
|
||||
|
||||
@import <Foundation/CPObject.j>
|
||||
|
||||
|
||||
@implementation AppController : CPObject
|
||||
{
|
||||
}
|
||||
|
||||
- (void)applicationDidFinishLaunching:(CPNotification)aNotification
|
||||
{
|
||||
// The end result of this layout will be the kind of master/detail/auxilliary view
|
||||
// found in iTunes, Mail, and many other apps.
|
||||
|
||||
var theWindow = [[CPWindow alloc] initWithContentRect:CGRectMakeZero() styleMask:CPBorderlessBridgeWindowMask],
|
||||
contentView = [theWindow contentView];
|
||||
|
||||
var navigationArea = [[CPView alloc] initWithFrame:CGRectMake(0.0, 0.0, 150.0, CGRectGetHeight([contentView bounds]) - 150.0)];
|
||||
|
||||
[navigationArea setBackgroundColor:[CPColor redColor]];
|
||||
|
||||
// This view will grow in height, but stay fixed width attached to the left side of the screen.
|
||||
[navigationArea setAutoresizingMask:CPViewHeightSizable | CPViewMaxXMargin];
|
||||
|
||||
[contentView addSubview:navigationArea];
|
||||
|
||||
var metaDataArea = [[CPView alloc] initWithFrame:CGRectMake(0.0, CGRectGetMaxY([navigationArea frame]), 150.0, 150.0)];
|
||||
|
||||
[metaDataArea setBackgroundColor:[CPColor greenColor]];
|
||||
|
||||
// This view will stay the same size in both directions, and fixed to the lower left corner.
|
||||
[metaDataArea setAutoresizingMask:CPViewMinYMargin | CPViewMaxXMargin];
|
||||
|
||||
[contentView addSubview:metaDataArea];
|
||||
|
||||
var contentArea = [[CPView alloc] initWithFrame:CGRectMake(150.0, 0.0, CGRectGetWidth([contentView bounds]) - 150.0, CGRectGetHeight([contentView bounds]))];
|
||||
|
||||
[contentArea setBackgroundColor:[CPColor blueColor]];
|
||||
|
||||
// This view will grow in both height an width.
|
||||
[contentArea setAutoresizingMask:CPViewWidthSizable | CPViewHeightSizable];
|
||||
|
||||
[contentView addSubview:contentArea];
|
||||
|
||||
[theWindow orderFront:self];
|
||||
}
|
||||
|
||||
@end
|
||||
52
samples/Oz/example.oz
Normal file
52
samples/Oz/example.oz
Normal file
@@ -0,0 +1,52 @@
|
||||
% You can get a lot of information about Oz by following theses links :
|
||||
% - http://mozart.github.io/
|
||||
% - http://en.wikipedia.org/wiki/Oz_(programming_language)
|
||||
% There is also a well known book that uses Oz for pedagogical reason :
|
||||
% - http://mitpress.mit.edu/books/concepts-techniques-and-models-computer-programming
|
||||
% And there are two courses on edX about 'Paradigms of Computer Programming' that also uses Oz for pedagogical reason :
|
||||
% - https://www.edx.org/node/2751#.VHijtfl5OSo
|
||||
% - https://www.edx.org/node/4436#.VHijzfl5OSo
|
||||
%
|
||||
% Here is an example of some code written with Oz.
|
||||
|
||||
declare
|
||||
% Computes the sum of square of the N first integers.
|
||||
fun {Sum N}
|
||||
local SumAux in
|
||||
fun {SumAux N Acc}
|
||||
if N==0 then Acc
|
||||
else
|
||||
{Sum N-1 Acc}
|
||||
end
|
||||
end
|
||||
{SumAux N 0}
|
||||
end
|
||||
end
|
||||
|
||||
% Returns true if N is a prime and false otherwize
|
||||
fun {Prime N}
|
||||
local PrimeAcc in
|
||||
fun {PrimeAcc N Acc}
|
||||
if(N == 1) then false
|
||||
elseif(Acc == 1) then true
|
||||
else
|
||||
if (N mod Acc) == 0 then false
|
||||
else
|
||||
{PrimeAcc N Acc-1}
|
||||
end
|
||||
end
|
||||
end
|
||||
{PrimeAcc N (N div 2)}
|
||||
end
|
||||
end
|
||||
|
||||
% Reverse a list using cells and for loop (instead of recursivity)
|
||||
fun {Reverse L}
|
||||
local RevList in
|
||||
RevList = {NewCell nil}
|
||||
for E in L do
|
||||
RevList := E|@RevList
|
||||
end
|
||||
@RevList
|
||||
end
|
||||
end
|
||||
97
samples/Perl6/01-dash-uppercase-i.t
Normal file
97
samples/Perl6/01-dash-uppercase-i.t
Normal file
@@ -0,0 +1,97 @@
|
||||
use v6;
|
||||
|
||||
use Test;
|
||||
|
||||
=begin pod
|
||||
|
||||
Test handling of -I.
|
||||
|
||||
Multiple C<-I> switches are supposed to
|
||||
prepend left-to-right:
|
||||
|
||||
-Ifoo -Ibar
|
||||
|
||||
should make C<@*INC> look like:
|
||||
|
||||
foo
|
||||
bar
|
||||
...
|
||||
|
||||
Duplication of directories on the command line is mirrored
|
||||
in the C<@*INC> variable, so C<pugs -Ilib -Ilib> will have B<two>
|
||||
entries C<lib/> in C<@*INC>.
|
||||
|
||||
=end pod
|
||||
|
||||
# L<S19/Reference/"Prepend directories to">
|
||||
|
||||
my $fragment = '-e "@*INC.perl.say"';
|
||||
|
||||
my @tests = (
|
||||
'foo',
|
||||
'foo$bar',
|
||||
'foo bar$baz',
|
||||
'foo$foo',
|
||||
);
|
||||
|
||||
plan @tests*2;
|
||||
|
||||
diag "Running under $*OS";
|
||||
|
||||
my ($pugs,$redir) = ($*EXECUTABLE_NAME, ">");
|
||||
|
||||
if $*OS eq any <MSWin32 mingw msys cygwin> {
|
||||
$pugs = 'pugs.exe';
|
||||
$redir = '>';
|
||||
};
|
||||
|
||||
sub nonce () { return (".{$*PID}." ~ (1..1000).pick) }
|
||||
|
||||
sub run_pugs ($c) {
|
||||
my $tempfile = "temp-ex-output" ~ nonce;
|
||||
my $command = "$pugs $c $redir $tempfile";
|
||||
diag $command;
|
||||
run $command;
|
||||
my $res = slurp $tempfile;
|
||||
unlink $tempfile;
|
||||
return $res;
|
||||
}
|
||||
|
||||
for @tests -> $t {
|
||||
my @dirs = split('$',$t);
|
||||
my $command;
|
||||
# This should be smarter about quoting
|
||||
# (currently, this should work for WinNT and Unix shells)
|
||||
$command = join " ", map { qq["-I$_"] }, @dirs;
|
||||
my $got = run_pugs( $command ~ " $fragment" );
|
||||
$got .= chomp;
|
||||
|
||||
if (substr($got,0,1) ~~ "[") {
|
||||
# Convert from arrayref to array
|
||||
$got = substr($got, 1, -1);
|
||||
};
|
||||
|
||||
my @got = EVAL $got;
|
||||
@got = @got[ 0..@dirs-1 ];
|
||||
my @expected = @dirs;
|
||||
|
||||
is @got, @expected, "'" ~ @dirs ~ "' works";
|
||||
|
||||
$command = join " ", map { qq[-I "$_"] }, @dirs;
|
||||
$got = run_pugs( $command ~ " $fragment" );
|
||||
|
||||
$got .= chomp;
|
||||
if (substr($got,0,1) ~~ "[") {
|
||||
# Convert from arrayref to array
|
||||
$got = substr($got, 1, -1);
|
||||
};
|
||||
|
||||
@got = EVAL $got;
|
||||
@got = @got[ 0..@dirs-1 ];
|
||||
@expected = @dirs;
|
||||
|
||||
is @got, @expected, "'" ~ @dirs ~ "' works (with a space delimiting -I)";
|
||||
}
|
||||
|
||||
|
||||
# vim: ft=perl6
|
||||
223
samples/Perl6/01-parse.t
Normal file
223
samples/Perl6/01-parse.t
Normal file
@@ -0,0 +1,223 @@
|
||||
use v6;
|
||||
BEGIN { @*INC.push('lib') };
|
||||
|
||||
use JSON::Tiny::Grammar;
|
||||
use Test;
|
||||
|
||||
my @t =
|
||||
'{}',
|
||||
'{ }',
|
||||
' { } ',
|
||||
'{ "a" : "b" }',
|
||||
'{ "a" : null }',
|
||||
'{ "a" : true }',
|
||||
'{ "a" : false }',
|
||||
'{ "a" : { } }',
|
||||
'[]',
|
||||
'[ ]',
|
||||
' [ ] ',
|
||||
# stolen from JSON::XS, 18_json_checker.t, and adapted a bit
|
||||
Q<<[
|
||||
"JSON Test Pattern pass1",
|
||||
{"object with 1 member":["array with 1 element"]},
|
||||
{},
|
||||
[]
|
||||
]>>,
|
||||
Q<<[1]>>,
|
||||
Q<<[true]>>,
|
||||
Q<<[-42]>>,
|
||||
Q<<[-42,true,false,null]>>,
|
||||
Q<<{ "integer": 1234567890 }>>,
|
||||
Q<<{ "real": -9876.543210 }>>,
|
||||
Q<<{ "e": 0.123456789e-12 }>>,
|
||||
Q<<{ "E": 1.234567890E+34 }>>,
|
||||
Q<<{ "": 23456789012E66 }>>,
|
||||
Q<<{ "zero": 0 }>>,
|
||||
Q<<{ "one": 1 }>>,
|
||||
Q<<{ "space": " " }>>,
|
||||
Q<<{ "quote": "\""}>>,
|
||||
Q<<{ "backslash": "\\"}>>,
|
||||
Q<<{ "controls": "\b\f\n\r\t"}>>,
|
||||
Q<<{ "slash": "/ & \/"}>>,
|
||||
Q<<{ "alpha": "abcdefghijklmnopqrstuvwyz"}>>,
|
||||
Q<<{ "ALPHA": "ABCDEFGHIJKLMNOPQRSTUVWYZ"}>>,
|
||||
Q<<{ "digit": "0123456789"}>>,
|
||||
Q<<{ "0123456789": "digit"}>>,
|
||||
Q<<{"special": "`1~!@#$%^&*()_+-={':[,]}|;.</>?"}>>,
|
||||
Q<<{"hex": "\u0123\u4567\u89AB\uCDEF\uabcd\uef4A"}>>,
|
||||
Q<<{"true": true}>>,
|
||||
Q<<{"false": false}>>,
|
||||
Q<<{"null": null}>>,
|
||||
Q<<{"array":[ ]}>>,
|
||||
Q<<{"object":{ }}>>,
|
||||
Q<<{"address": "50 St. James Street"}>>,
|
||||
Q<<{"url": "http://www.JSON.org/"}>>,
|
||||
Q<<{"comment": "// /* <!-- --"}>>,
|
||||
Q<<{"# -- --> */": " "}>>,
|
||||
Q<<{ " s p a c e d " :[1,2 , 3
|
||||
|
||||
,
|
||||
|
||||
4 , 5 , 6 ,7 ],"compact":[1,2,3,4,5,6,7]}>>,
|
||||
|
||||
Q<<{"jsontext": "{\"object with 1 member\":[\"array with 1 element\"]}"}>>,
|
||||
Q<<{"quotes": "" \u0022 %22 0x22 034 ""}>>,
|
||||
Q<<{ "\/\\\"\uCAFE\uBABE\uAB98\uFCDE\ubcda\uef4A\b\f\n\r\t`1~!@#$%^&*()_+-=[]{}|;:',./<>?"
|
||||
: "A key can be any string"
|
||||
}>>,
|
||||
Q<<[ 0.5 ,98.6
|
||||
,
|
||||
99.44
|
||||
,
|
||||
|
||||
1066,
|
||||
1e1,
|
||||
0.1e1
|
||||
]>>,
|
||||
Q<<[1e-1]>>,
|
||||
Q<<[1e00,2e+00,2e-00,"rosebud"]>>,
|
||||
Q<<[[[[[[[[[[[[[[[[[[["Not too deep"]]]]]]]]]]]]]]]]]]]>>,
|
||||
Q<<{
|
||||
"JSON Test Pattern pass3": {
|
||||
"The outermost value": "must be an object or array.",
|
||||
"In this test": "It is an object."
|
||||
}
|
||||
}
|
||||
>>,
|
||||
# from http://www.json.org/example.html
|
||||
Q<<{
|
||||
"glossary": {
|
||||
"title": "example glossary",
|
||||
"GlossDiv": {
|
||||
"title": "S",
|
||||
"GlossList": {
|
||||
"GlossEntry": {
|
||||
"ID": "SGML",
|
||||
"SortAs": "SGML",
|
||||
"GlossTerm": "Standard Generalized Markup Language",
|
||||
"Acronym": "SGML",
|
||||
"Abbrev": "ISO 8879:1986",
|
||||
"GlossDef": {
|
||||
"para": "A meta-markup language, used to create markup languages such as DocBook.",
|
||||
"GlossSeeAlso": ["GML", "XML"]
|
||||
},
|
||||
"GlossSee": "markup"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
>>,
|
||||
Q<<{"menu": {
|
||||
"id": "file",
|
||||
"value": "File",
|
||||
"popup": {
|
||||
"menuitem": [
|
||||
{"value": "New", "onclick": "CreateNewDoc()"},
|
||||
{"value": "Open", "onclick": "OpenDoc()"},
|
||||
{"value": "Close", "onclick": "CloseDoc()"}
|
||||
]
|
||||
}
|
||||
}}>>,
|
||||
Q<<{"widget": {
|
||||
"debug": "on",
|
||||
"window": {
|
||||
"title": "Sample Konfabulator Widget",
|
||||
"name": "main_window",
|
||||
"width": 500,
|
||||
"height": 500
|
||||
},
|
||||
"image": {
|
||||
"src": "Images/Sun.png",
|
||||
"name": "sun1",
|
||||
"hOffset": 250,
|
||||
"vOffset": 250,
|
||||
"alignment": "center"
|
||||
},
|
||||
"text": {
|
||||
"data": "Click Here",
|
||||
"size": 36,
|
||||
"style": "bold",
|
||||
"name": "text1",
|
||||
"hOffset": 250,
|
||||
"vOffset": 100,
|
||||
"alignment": "center",
|
||||
"onMouseUp": "sun1.opacity = (sun1.opacity / 100) * 90;"
|
||||
}
|
||||
}}>>,
|
||||
;
|
||||
|
||||
my @n =
|
||||
'{ ',
|
||||
'{ 3 : 4 }',
|
||||
'{ 3 : tru }', # not quite true
|
||||
'{ "a : false }', # missing quote
|
||||
# stolen from JSON::XS, 18_json_checker.t
|
||||
Q<<"A JSON payload should be an object or array, not a string.">>,
|
||||
Q<<{"Extra value after close": true} "misplaced quoted value">>,
|
||||
Q<<{"Illegal expression": 1 + 2}>>,
|
||||
Q<<{"Illegal invocation": alert()}>>,
|
||||
Q<<{"Numbers cannot have leading zeroes": 013}>>,
|
||||
Q<<{"Numbers cannot be hex": 0x14}>>,
|
||||
Q<<["Illegal backslash escape: \x15"]>>,
|
||||
Q<<[\naked]>>,
|
||||
Q<<["Illegal backslash escape: \017"]>>,
|
||||
# skipped: wo don't implement no stinkin' aritifical limits.
|
||||
# Q<<[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[["Too deep"]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]>>,
|
||||
Q<<{"Missing colon" null}>>,
|
||||
Q<<["Unclosed array">>,
|
||||
Q<<{"Double colon":: null}>>,
|
||||
Q<<{"Comma instead of colon", null}>>,
|
||||
Q<<["Colon instead of comma": false]>>,
|
||||
Q<<["Bad value", truth]>>,
|
||||
Q<<['single quote']>>,
|
||||
qq<["\ttab\tcharacter in string "]>,
|
||||
Q<<["line
|
||||
break"]>>,
|
||||
Q<<["line\
|
||||
break"]>>,
|
||||
Q<<[0e]>>,
|
||||
Q<<{unquoted_key: "keys must be quoted"}>>,
|
||||
Q<<[0e+]>>,
|
||||
Q<<[0e+-1]>>,
|
||||
Q<<{"Comma instead if closing brace": true,>>,
|
||||
Q<<["mismatch"}>>,
|
||||
Q<<["extra comma",]>>,
|
||||
Q<<["double extra comma",,]>>,
|
||||
Q<<[ , "<-- missing value"]>>,
|
||||
Q<<["Comma after the close"],>>,
|
||||
Q<<["Extra close"]]>>,
|
||||
Q<<{"Extra comma": true,}>>,
|
||||
;
|
||||
|
||||
plan (+@t) + (+@n);
|
||||
|
||||
my $i = 0;
|
||||
for @t -> $t {
|
||||
my $desc = $t;
|
||||
if $desc ~~ m/\n/ {
|
||||
$desc .= subst(/\n.*$/, "\\n...[$i]");
|
||||
}
|
||||
my $parsed = 0;
|
||||
try {
|
||||
JSON::Tiny::Grammar.parse($t)
|
||||
and $parsed = 1;
|
||||
}
|
||||
ok $parsed, "JSON string «$desc» parsed";
|
||||
$i++;
|
||||
}
|
||||
|
||||
for @n -> $t {
|
||||
my $desc = $t;
|
||||
if $desc ~~ m/\n/ {
|
||||
$desc .= subst(/\n.*$/, "\\n...[$i]");
|
||||
}
|
||||
my $parsed = 0;
|
||||
try { JSON::Tiny::Grammar.parse($t) and $parsed = 1 };
|
||||
nok $parsed, "NOT parsed «$desc»";
|
||||
$i++;
|
||||
}
|
||||
|
||||
|
||||
# vim: ft=perl6
|
||||
|
||||
9
samples/Perl6/A.pm
Normal file
9
samples/Perl6/A.pm
Normal file
@@ -0,0 +1,9 @@
|
||||
# used in t/spec/S11-modules/nested.t
|
||||
|
||||
BEGIN { @*INC.push('t/spec/packages') };
|
||||
|
||||
module A::A {
|
||||
use A::B;
|
||||
}
|
||||
|
||||
# vim: ft=perl6
|
||||
148
samples/Perl6/ANSIColor.pm
Normal file
148
samples/Perl6/ANSIColor.pm
Normal file
@@ -0,0 +1,148 @@
|
||||
use v6;
|
||||
|
||||
module Term::ANSIColor;
|
||||
|
||||
# these will be macros one day, yet macros can't be exported so far
|
||||
sub RESET is export { "\e[0m" }
|
||||
sub BOLD is export { "\e[1m" }
|
||||
sub UNDERLINE is export { "\e[4m" }
|
||||
sub INVERSE is export { "\e[7m" }
|
||||
sub BOLD_OFF is export { "\e[22m" }
|
||||
sub UNDERLINE_OFF is export { "\e[24m" }
|
||||
sub INVERSE_OFF is export { "\e[27m" }
|
||||
|
||||
my %attrs =
|
||||
reset => "0",
|
||||
bold => "1",
|
||||
underline => "4",
|
||||
inverse => "7",
|
||||
black => "30",
|
||||
red => "31",
|
||||
green => "32",
|
||||
yellow => "33",
|
||||
blue => "34",
|
||||
magenta => "35",
|
||||
cyan => "36",
|
||||
white => "37",
|
||||
default => "39",
|
||||
on_black => "40",
|
||||
on_red => "41",
|
||||
on_green => "42",
|
||||
on_yellow => "43",
|
||||
on_blue => "44",
|
||||
on_magenta => "45",
|
||||
on_cyan => "46",
|
||||
on_white => "47",
|
||||
on_default => "49";
|
||||
|
||||
sub color (Str $what) is export {
|
||||
my @res;
|
||||
my @a = $what.split(' ');
|
||||
for @a -> $attr {
|
||||
if %attrs.exists($attr) {
|
||||
@res.push: %attrs{$attr}
|
||||
} else {
|
||||
die("Invalid attribute name '$attr'")
|
||||
}
|
||||
}
|
||||
return "\e[" ~ @res.join(';') ~ "m";
|
||||
}
|
||||
|
||||
sub colored (Str $what, Str $how) is export {
|
||||
color($how) ~ $what ~ color('reset');
|
||||
}
|
||||
|
||||
sub colorvalid (*@a) is export {
|
||||
for @a -> $el {
|
||||
return False unless %attrs.exists($el)
|
||||
}
|
||||
return True;
|
||||
}
|
||||
|
||||
sub colorstrip (*@a) is export {
|
||||
my @res;
|
||||
for @a -> $str {
|
||||
@res.push: $str.subst(/\e\[ <[0..9;]>+ m/, '', :g);
|
||||
}
|
||||
return @res.join;
|
||||
}
|
||||
|
||||
sub uncolor (Str $what) is export {
|
||||
my @res;
|
||||
my @list = $what.comb(/\d+/);
|
||||
for @list -> $elem {
|
||||
if %attrs.reverse.exists($elem) {
|
||||
@res.push: %attrs.reverse{$elem}
|
||||
} else {
|
||||
die("Bad escape sequence: {'\e[' ~ $elem ~ 'm'}")
|
||||
}
|
||||
}
|
||||
return @res.join(' ');
|
||||
}
|
||||
|
||||
=begin pod
|
||||
|
||||
=head1 NAME
|
||||
|
||||
Term::ANSIColor - Color screen output using ANSI escape sequences
|
||||
|
||||
=head1 SYNOPSIS
|
||||
|
||||
use Term::ANSIColor;
|
||||
say color('bold'), "this is in bold", color('reset');
|
||||
say colored('underline red on_green', 'what a lovely colours!');
|
||||
say BOLD, 'good to be fat!', BOLD_OFF;
|
||||
say 'ok' if colorvalid('magenta', 'on_black', 'inverse');
|
||||
say '\e[36m is ', uncolor('\e36m');
|
||||
say colorstrip("\e[1mThis is bold\e[0m");
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
Term::ANSIColor provides an interface for using colored output
|
||||
in terminals. The following functions are available:
|
||||
|
||||
=head2 C<color()>
|
||||
|
||||
Given a string with color names, the output produced by C<color()>
|
||||
sets the terminal output so the text printed after it will be colored
|
||||
as specified. The following color names are recognised:
|
||||
|
||||
reset bold underline inverse black red green yellow blue
|
||||
magenta cyan white default on_black on_red on_green on_yellow
|
||||
on_blue on_magenta on_cyan on_white on_default
|
||||
|
||||
The on_* family of colors correspond to the background colors.
|
||||
|
||||
=head2 C<colored()>
|
||||
|
||||
C<colored()> is similar to C<color()>. It takes two Str arguments,
|
||||
where the first is the colors to be used, and the second is the string
|
||||
to be colored. The C<reset> sequence is automagically placed after
|
||||
the string.
|
||||
|
||||
=head2 C<colorvalid()>
|
||||
|
||||
C<colorvalid()> gets an array of color specifications (like those
|
||||
passed to C<color()>) and returns true if all of them are valid,
|
||||
false otherwise.
|
||||
|
||||
=head2 C<colorstrip()>
|
||||
|
||||
C<colorstrip>, given a string, removes all the escape sequences
|
||||
in it, leaving the plain text without effects.
|
||||
|
||||
=head2 C<uncolor()>
|
||||
|
||||
Given escape sequences, C<uncolor()> returns a string with readable
|
||||
color names. E.g. passing "\e[36;44m" will result in "cyan on_blue".
|
||||
|
||||
=head1 Constants
|
||||
|
||||
C<Term::ANSIColor> provides constants which are just strings of
|
||||
appropriate escape sequences. The following constants are available:
|
||||
|
||||
RESET BOLD UNDERLINE INVERSE BOLD_OFF UNDERLINE_OFF INVERSE_OFF
|
||||
|
||||
=end pod
|
||||
|
||||
# vim: ft=perl6
|
||||
102
samples/Perl6/Bailador.pm
Normal file
102
samples/Perl6/Bailador.pm
Normal file
@@ -0,0 +1,102 @@
|
||||
use Bailador::App;
|
||||
use Bailador::Request;
|
||||
use Bailador::Response;
|
||||
use Bailador::Context;
|
||||
use HTTP::Easy::PSGI;
|
||||
|
||||
module Bailador;
|
||||
|
||||
my $app = Bailador::App.current;
|
||||
|
||||
our sub import {
|
||||
my $file = callframe(1).file;
|
||||
my $slash = $file.rindex('/');
|
||||
if $slash {
|
||||
$app.location = $file.substr(0, $file.rindex('/'));
|
||||
} else {
|
||||
$app.location = '.';
|
||||
}
|
||||
}
|
||||
|
||||
sub route_to_regex($route) {
|
||||
$route.split('/').map({
|
||||
my $r = $_;
|
||||
if $_.substr(0, 1) eq ':' {
|
||||
$r = q{(<-[\/\.]>+)};
|
||||
}
|
||||
$r
|
||||
}).join("'/'");
|
||||
}
|
||||
|
||||
multi parse_route(Str $route) {
|
||||
my $r = route_to_regex($route);
|
||||
return "/ ^ $r \$ /".eval;
|
||||
}
|
||||
|
||||
multi parse_route($route) {
|
||||
# do nothing
|
||||
$route
|
||||
}
|
||||
|
||||
sub get(Pair $x) is export {
|
||||
my $p = parse_route($x.key) => $x.value;
|
||||
$app.add_route: 'GET', $p;
|
||||
return $x;
|
||||
}
|
||||
|
||||
sub post(Pair $x) is export {
|
||||
my $p = parse_route($x.key) => $x.value;
|
||||
$app.add_route: 'POST', $p;
|
||||
return $x;
|
||||
}
|
||||
|
||||
sub request is export { $app.context.request }
|
||||
|
||||
sub content_type(Str $type) is export {
|
||||
$app.response.headers<Content-Type> = $type;
|
||||
}
|
||||
|
||||
sub header(Str $name, Cool $value) is export {
|
||||
$app.response.headers{$name} = ~$value;
|
||||
}
|
||||
|
||||
sub status(Int $code) is export {
|
||||
$app.response.code = $code;
|
||||
}
|
||||
|
||||
sub template(Str $tmpl, *@params) is export {
|
||||
$app.template($tmpl, @params);
|
||||
}
|
||||
|
||||
our sub dispatch_request(Bailador::Request $r) {
|
||||
return dispatch($r.env);
|
||||
}
|
||||
|
||||
sub dispatch($env) {
|
||||
$app.context.env = $env;
|
||||
|
||||
my ($r, $match) = $app.find_route($env);
|
||||
|
||||
if $r {
|
||||
status 200;
|
||||
if $match {
|
||||
$app.response.content = $r.value.(|$match.list);
|
||||
} else {
|
||||
$app.response.content = $r.value.();
|
||||
}
|
||||
}
|
||||
|
||||
return $app.response;
|
||||
}
|
||||
|
||||
sub dispatch-psgi($env) {
|
||||
return dispatch($env).psgi;
|
||||
}
|
||||
|
||||
sub baile is export {
|
||||
given HTTP::Easy::PSGI.new(port => 3000) {
|
||||
.app(&dispatch-psgi);
|
||||
say "Entering the development dance floor: http://0.0.0.0:3000";
|
||||
.run;
|
||||
}
|
||||
}
|
||||
7
samples/Perl6/ContainsUnicode.pm
Normal file
7
samples/Perl6/ContainsUnicode.pm
Normal file
@@ -0,0 +1,7 @@
|
||||
module ContainsUnicode {
|
||||
sub uc-and-join(*@things, :$separator = ', ') is export {
|
||||
@things».uc.join($separator)
|
||||
}
|
||||
}
|
||||
|
||||
# vim: ft=perl6
|
||||
1431
samples/Perl6/Exception.pm
Normal file
1431
samples/Perl6/Exception.pm
Normal file
File diff suppressed because it is too large
Load Diff
146
samples/Perl6/Model.pm
Normal file
146
samples/Perl6/Model.pm
Normal file
@@ -0,0 +1,146 @@
|
||||
use v6;
|
||||
|
||||
class Math::Model;
|
||||
|
||||
use Math::RungeKutta;
|
||||
# TODO: only load when needed
|
||||
use SVG;
|
||||
use SVG::Plot;
|
||||
|
||||
has %.derivatives;
|
||||
has %.variables;
|
||||
has %.initials;
|
||||
has @.captures is rw;
|
||||
|
||||
has %!inv = %!derivatives.invert;
|
||||
# in Math::Model all variables are accessible by name
|
||||
# in contrast Math::RungeKutta uses vectors, so we need
|
||||
# to define an (arbitrary) ordering
|
||||
# @!deriv-names holds the names of the derivatives in a fixed
|
||||
# order, sod @!deriv-names[$number] turns the number into a name
|
||||
# %!deriv-keying{$name} translates a name into the corresponding index
|
||||
has @!deriv-names = %!inv.keys;
|
||||
has %!deriv-keying = @!deriv-names Z=> 0..Inf;
|
||||
|
||||
# snapshot of all variables in the current model
|
||||
has %!current-values;
|
||||
|
||||
has %.results;
|
||||
has @.time;
|
||||
|
||||
has $.numeric-error is rw = 0.0001;
|
||||
|
||||
my sub param-names(&c) {
|
||||
&c.signature.params».name».substr(1).grep({ $_ ne '_'});
|
||||
}
|
||||
|
||||
method !params-for(&c) {
|
||||
param-names(&c).map( {; $_ => %!current-values{$_} } ).hash;
|
||||
}
|
||||
|
||||
method topo-sort(*@vars) {
|
||||
my %seen;
|
||||
my @order;
|
||||
sub topo(*@a) {
|
||||
for @a {
|
||||
next if %!inv.exists($_) || %seen{$_} || $_ eq 'time';
|
||||
die "Undeclared variable '$_' used in model"
|
||||
unless %.variables.exists($_);
|
||||
topo(param-names(%.variables{$_}));
|
||||
@order.push: $_;
|
||||
%seen{$_}++;
|
||||
}
|
||||
}
|
||||
topo(@vars);
|
||||
# say @order.perl;
|
||||
@order;
|
||||
}
|
||||
|
||||
|
||||
method integrate(:$from = 0, :$to = 10, :$min-resolution = ($to - $from) / 20, :$verbose) {
|
||||
for %.derivatives -> $d {
|
||||
die "There must be a variable defined for each derivative, missing for '$d.key()'"
|
||||
unless %.variables.exists($d.key) || %!inv.exists($d.key);
|
||||
die "There must be an initial value defined for each derivative target, missing for '$d.value()'"
|
||||
unless %.initials.exists($d.value);
|
||||
}
|
||||
|
||||
%!current-values = %.initials;
|
||||
%!current-values<time> = $from;
|
||||
|
||||
my @vars-topo = self.topo-sort(%.variables.keys);
|
||||
sub update-current-values($time, @values) {
|
||||
%!current-values<time> = $time;
|
||||
%!current-values{@!deriv-names} = @values;
|
||||
for @vars-topo {
|
||||
my $c = %.variables{$_};
|
||||
%!current-values{$_} = $c.(|self!params-for($c));
|
||||
}
|
||||
}
|
||||
|
||||
my @initial = %.initials{@!deriv-names};
|
||||
|
||||
sub derivatives($time, @values) {
|
||||
update-current-values($time, @values);
|
||||
my @r;
|
||||
for %!inv{@!deriv-names} {
|
||||
my $v = %.variables{$_};
|
||||
@r.push: $v.defined
|
||||
?? $v(|self!params-for($v))
|
||||
!! %!current-values{$_};
|
||||
}
|
||||
@r;
|
||||
}
|
||||
|
||||
@!time = ();
|
||||
for @.captures {
|
||||
%!results{$_} = [];
|
||||
}
|
||||
|
||||
sub record($time, @values) {
|
||||
update-current-values($time, @values);
|
||||
@!time.push: $time;
|
||||
say $time if $verbose;
|
||||
|
||||
for @.captures {
|
||||
%!results{$_}.push: %!current-values{$_};;
|
||||
}
|
||||
}
|
||||
|
||||
record($from, %.initials{@!deriv-names});
|
||||
|
||||
adaptive-rk-integrate(
|
||||
:$from,
|
||||
:$to,
|
||||
:@initial,
|
||||
:derivative(&derivatives),
|
||||
:max-stepsize($min-resolution),
|
||||
:do(&record),
|
||||
:epsilon($.numeric-error),
|
||||
);
|
||||
%!results;
|
||||
}
|
||||
|
||||
method render-svg(
|
||||
$filename,
|
||||
:$x-axis = 'time',
|
||||
:$width = 800,
|
||||
:$height = 600,
|
||||
:$title = 'Model output') {
|
||||
my $f = open $filename, :w
|
||||
or die "Can't open file '$filename' for writing: $!";
|
||||
my @values = map { %!results{$_} }, @.captures.grep({ $_ ne $x-axis});
|
||||
my @x = $x-axis eq 'time' ?? @!time !! %!results{$x-axis}.flat;
|
||||
my $svg = SVG::Plot.new(
|
||||
:$width,
|
||||
:$height,
|
||||
:@x,
|
||||
:@values,
|
||||
:$title,
|
||||
).plot(:xy-lines);
|
||||
$f.say(SVG.serialize($svg));
|
||||
$f.close;
|
||||
say "Wrote ouput to '$filename'";
|
||||
}
|
||||
|
||||
# vim: ft=perl6
|
||||
317
samples/Perl6/Simple.pm
Normal file
317
samples/Perl6/Simple.pm
Normal file
@@ -0,0 +1,317 @@
|
||||
# ----------------------
|
||||
# LWP::Simple for Perl 6
|
||||
# ----------------------
|
||||
use v6;
|
||||
use MIME::Base64;
|
||||
use URI;
|
||||
|
||||
class LWP::Simple:auth<cosimo>:ver<0.085>;
|
||||
|
||||
our $VERSION = '0.085';
|
||||
|
||||
enum RequestType <GET POST>;
|
||||
|
||||
has Str $.default_encoding = 'utf-8';
|
||||
our $.class_default_encoding = 'utf-8';
|
||||
|
||||
# these were intended to be constant but that hit pre-compilation issue
|
||||
my Buf $crlf = Buf.new(13, 10);
|
||||
my Buf $http_header_end_marker = Buf.new(13, 10, 13, 10);
|
||||
my Int constant $default_stream_read_len = 2 * 1024;
|
||||
|
||||
method base64encode ($user, $pass) {
|
||||
my MIME::Base64 $mime .= new();
|
||||
my $encoded = $mime.encode_base64($user ~ ':' ~ $pass);
|
||||
return $encoded;
|
||||
}
|
||||
|
||||
method get (Str $url) {
|
||||
self.request_shell(RequestType::GET, $url)
|
||||
}
|
||||
|
||||
method post (Str $url, %headers = {}, Any $content?) {
|
||||
self.request_shell(RequestType::POST, $url, %headers, $content)
|
||||
}
|
||||
|
||||
method request_shell (RequestType $rt, Str $url, %headers = {}, Any $content?) {
|
||||
|
||||
return unless $url;
|
||||
|
||||
my ($scheme, $hostname, $port, $path, $auth) = self.parse_url($url);
|
||||
|
||||
%headers{'Connection'} = 'close';
|
||||
%headers{'User-Agent'} //= "LWP::Simple/$VERSION Perl6/$*PERL<compiler><name>";
|
||||
|
||||
if $auth {
|
||||
$hostname = $auth<host>;
|
||||
my $user = $auth<user>;
|
||||
my $pass = $auth<password>;
|
||||
my $base64enc = self.base64encode($user, $pass);
|
||||
%headers<Authorization> = "Basic $base64enc";
|
||||
}
|
||||
|
||||
%headers<Host> = $hostname;
|
||||
|
||||
if ($rt ~~ RequestType::POST && $content.defined) {
|
||||
# Attach Content-Length header
|
||||
# as recommended in RFC2616 section 14.3.
|
||||
# Note: Empty content is also a content,
|
||||
# header value equals to zero is valid.
|
||||
%headers{'Content-Length'} = $content.encode.bytes;
|
||||
}
|
||||
|
||||
my ($status, $resp_headers, $resp_content) =
|
||||
self.make_request($rt, $hostname, $port, $path, %headers, $content);
|
||||
|
||||
given $status {
|
||||
|
||||
when / 30 <[12]> / {
|
||||
my %resp_headers = $resp_headers.hash;
|
||||
my $new_url = %resp_headers<Location>;
|
||||
if ! $new_url {
|
||||
die "Redirect $status without a new URL?";
|
||||
}
|
||||
|
||||
# Watch out for too many redirects.
|
||||
# Need to find a way to store a class member
|
||||
#if $redirects++ > 10 {
|
||||
# say "Too many redirects!";
|
||||
# return;
|
||||
#}
|
||||
|
||||
return self.request_shell($rt, $new_url, %headers, $content);
|
||||
}
|
||||
|
||||
when /200/ {
|
||||
# should be fancier about charset decoding application - someday
|
||||
if $resp_headers<Content-Type> &&
|
||||
$resp_headers<Content-Type> ~~
|
||||
/ $<media-type>=[<-[/;]>+]
|
||||
[ <[/]> $<media-subtype>=[<-[;]>+] ]? / &&
|
||||
( $<media-type> eq 'text' ||
|
||||
( $<media-type> eq 'application' &&
|
||||
$<media-subtype> ~~ /[ ecma | java ]script | json/
|
||||
)
|
||||
)
|
||||
{
|
||||
my $charset =
|
||||
($resp_headers<Content-Type> ~~ /charset\=(<-[;]>*)/)[0];
|
||||
$charset = $charset ?? $charset.Str !!
|
||||
self ?? $.default_encoding !! $.class_default_encoding;
|
||||
return $resp_content.decode($charset);
|
||||
}
|
||||
else {
|
||||
return $resp_content;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
# Response failed
|
||||
default {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
method parse_chunks(Blob $b is rw, IO::Socket::INET $sock) {
|
||||
my Int ($line_end_pos, $chunk_len, $chunk_start) = (0) xx 3;
|
||||
my Blob $content = Blob.new();
|
||||
|
||||
# smallest valid chunked line is 0CRLFCRLF (ascii or other 8bit like EBCDIC)
|
||||
while ($line_end_pos + 5 <= $b.bytes) {
|
||||
while ( $line_end_pos +4 <= $b.bytes &&
|
||||
$b.subbuf($line_end_pos, 2) ne $crlf
|
||||
) {
|
||||
$line_end_pos++
|
||||
}
|
||||
# say "got here x0x pos ", $line_end_pos, ' bytes ', $b.bytes, ' start ', $chunk_start, ' some data ', $b.subbuf($chunk_start, $line_end_pos +2 - $chunk_start).decode('ascii');
|
||||
if $line_end_pos +4 <= $b.bytes &&
|
||||
$b.subbuf(
|
||||
$chunk_start, $line_end_pos + 2 - $chunk_start
|
||||
).decode('ascii') ~~ /^(<.xdigit>+)[";"|"\r\n"]/
|
||||
{
|
||||
|
||||
# deal with case of chunk_len is 0
|
||||
|
||||
$chunk_len = :16($/[0].Str);
|
||||
# say 'got chunk len ', $/[0].Str;
|
||||
|
||||
# test if at end of buf??
|
||||
if $chunk_len == 0 {
|
||||
# this is a "normal" exit from the routine
|
||||
return True, $content;
|
||||
}
|
||||
|
||||
# think 1CRLFxCRLF
|
||||
if $line_end_pos + $chunk_len + 4 <= $b.bytes {
|
||||
# say 'inner chunk';
|
||||
$content ~= $b.subbuf($line_end_pos +2, $chunk_len);
|
||||
$line_end_pos = $chunk_start = $line_end_pos + $chunk_len +4;
|
||||
}
|
||||
else {
|
||||
# say 'last chunk';
|
||||
# remaining chunk part len is chunk_len with CRLF
|
||||
# minus the length of the chunk piece at end of buffer
|
||||
my $last_chunk_end_len =
|
||||
$chunk_len +2 - ($b.bytes - $line_end_pos -2);
|
||||
$content ~= $b.subbuf($line_end_pos +2);
|
||||
if $last_chunk_end_len > 2 {
|
||||
$content ~= $sock.read($last_chunk_end_len -2);
|
||||
}
|
||||
# clean up CRLF after chunk
|
||||
$sock.read(min($last_chunk_end_len, 2));
|
||||
|
||||
# this is a` "normal" exit from the routine
|
||||
return False, $content;
|
||||
}
|
||||
}
|
||||
else {
|
||||
# say 'extend bytes ', $b.bytes, ' start ', $chunk_start, ' data ', $b.subbuf($chunk_start).decode('ascii');
|
||||
# maybe odd case of buffer has just part of header at end
|
||||
$b ~= $sock.read(20);
|
||||
}
|
||||
}
|
||||
|
||||
# say join ' ', $b[0 .. 100];
|
||||
# say $b.subbuf(0, 100).decode('utf-8');
|
||||
die "Could not parse chunk header";
|
||||
}
|
||||
|
||||
method make_request (
|
||||
RequestType $rt, $host, $port as Int, $path, %headers, $content?
|
||||
) {
|
||||
|
||||
my $headers = self.stringify_headers(%headers);
|
||||
|
||||
my IO::Socket::INET $sock .= new(:$host, :$port);
|
||||
my Str $req_str = $rt.Stringy ~ " {$path} HTTP/1.1\r\n"
|
||||
~ $headers
|
||||
~ "\r\n";
|
||||
|
||||
# attach $content if given
|
||||
# (string context is forced by concatenation)
|
||||
$req_str ~= $content if $content.defined;
|
||||
|
||||
$sock.send($req_str);
|
||||
|
||||
my Blob $resp = $sock.read($default_stream_read_len);
|
||||
|
||||
my ($status, $resp_headers, $resp_content) = self.parse_response($resp);
|
||||
|
||||
|
||||
if (($resp_headers<Transfer-Encoding> || '') eq 'chunked') {
|
||||
my Bool $is_last_chunk;
|
||||
my Blob $resp_content_chunk;
|
||||
|
||||
($is_last_chunk, $resp_content) =
|
||||
self.parse_chunks($resp_content, $sock);
|
||||
while (not $is_last_chunk) {
|
||||
($is_last_chunk, $resp_content_chunk) =
|
||||
self.parse_chunks(
|
||||
my Blob $next_chunk_start = $sock.read(1024),
|
||||
$sock
|
||||
);
|
||||
$resp_content ~= $resp_content_chunk;
|
||||
}
|
||||
}
|
||||
elsif ( $resp_headers<Content-Length> &&
|
||||
$resp_content.bytes < $resp_headers<Content-Length>
|
||||
) {
|
||||
$resp_content ~= $sock.read(
|
||||
$resp_headers<Content-Length> - $resp_content.bytes
|
||||
);
|
||||
}
|
||||
else { # a bit hacky for now but should be ok
|
||||
while ($resp.bytes > 0) {
|
||||
$resp = $sock.read($default_stream_read_len);
|
||||
$resp_content ~= $resp;
|
||||
}
|
||||
}
|
||||
|
||||
$sock.close();
|
||||
|
||||
return ($status, $resp_headers, $resp_content);
|
||||
}
|
||||
|
||||
method parse_response (Blob $resp) {
|
||||
|
||||
my %header;
|
||||
|
||||
my Int $header_end_pos = 0;
|
||||
while ( $header_end_pos < $resp.bytes &&
|
||||
$http_header_end_marker ne $resp.subbuf($header_end_pos, 4) ) {
|
||||
$header_end_pos++;
|
||||
}
|
||||
|
||||
if ($header_end_pos < $resp.bytes) {
|
||||
my @header_lines = $resp.subbuf(
|
||||
0, $header_end_pos
|
||||
).decode('ascii').split(/\r\n/);
|
||||
my Str $status_line = @header_lines.shift;
|
||||
|
||||
for @header_lines {
|
||||
my ($name, $value) = .split(': ');
|
||||
%header{$name} = $value;
|
||||
}
|
||||
return $status_line, %header.item, $resp.subbuf($header_end_pos +4).item;
|
||||
}
|
||||
|
||||
die "could not parse headers";
|
||||
# if %header.exists('Transfer-Encoding') && %header<Transfer-Encoding> ~~ m/:i chunked/ {
|
||||
# @content = self.decode_chunked(@content);
|
||||
# }
|
||||
|
||||
}
|
||||
|
||||
method getprint (Str $url) {
|
||||
my $out = self.get($url);
|
||||
if $out ~~ Buf { $*OUT.write($out) } else { say $out }
|
||||
}
|
||||
|
||||
method getstore (Str $url, Str $filename) {
|
||||
return unless defined $url;
|
||||
|
||||
my $content = self.get($url);
|
||||
if ! $content {
|
||||
return
|
||||
}
|
||||
|
||||
my $fh = open($filename, :bin, :w);
|
||||
if $content ~~ Buf {
|
||||
$fh.write($content)
|
||||
}
|
||||
else {
|
||||
$fh.print($content)
|
||||
}
|
||||
|
||||
$fh.close;
|
||||
}
|
||||
|
||||
method parse_url (Str $url) {
|
||||
my URI $u .= new($url);
|
||||
my $path = $u.path_query;
|
||||
|
||||
my $user_info = $u.grammar.parse_result<URI_reference><URI><hier_part><authority><userinfo>;
|
||||
|
||||
return (
|
||||
$u.scheme,
|
||||
$user_info ?? "{$user_info}@{$u.host}" !! $u.host,
|
||||
$u.port,
|
||||
$path eq '' ?? '/' !! $path,
|
||||
$user_info ?? {
|
||||
host => $u.host,
|
||||
user => ~ $user_info<likely_userinfo_component>[0],
|
||||
password => ~ $user_info<likely_userinfo_component>[1]
|
||||
} !! Nil
|
||||
);
|
||||
}
|
||||
|
||||
method stringify_headers (%headers) {
|
||||
my Str $str = '';
|
||||
for sort %headers.keys {
|
||||
$str ~= $_ ~ ': ' ~ %headers{$_} ~ "\r\n";
|
||||
}
|
||||
return $str;
|
||||
}
|
||||
|
||||
207
samples/Perl6/Win32.pm
Normal file
207
samples/Perl6/Win32.pm
Normal file
@@ -0,0 +1,207 @@
|
||||
my class IO::Spec::Win32 is IO::Spec::Unix {
|
||||
|
||||
# Some regexes we use for path splitting
|
||||
my $slash = regex { <[\/ \\]> }
|
||||
my $notslash = regex { <-[\/ \\]> }
|
||||
my $driveletter = regex { <[A..Z a..z]> ':' }
|
||||
my $UNCpath = regex { [<$slash> ** 2] <$notslash>+ <$slash> [<$notslash>+ | $] }
|
||||
my $volume_rx = regex { <$driveletter> | <$UNCpath> }
|
||||
|
||||
method canonpath ($path, :$parent) {
|
||||
$path eq '' ?? '' !! self!canon-cat($path, :$parent);
|
||||
}
|
||||
|
||||
method catdir(*@dirs) {
|
||||
return "" unless @dirs;
|
||||
return self!canon-cat( "\\", |@dirs ) if @dirs[0] eq "";
|
||||
self!canon-cat(|@dirs);
|
||||
}
|
||||
|
||||
method splitdir($dir) { $dir.split($slash) }
|
||||
method catfile(|c) { self.catdir(|c) }
|
||||
method devnull { 'nul' }
|
||||
method rootdir { '\\' }
|
||||
|
||||
method tmpdir {
|
||||
first( { .defined && .IO.d && .IO.w },
|
||||
%*ENV<TMPDIR>,
|
||||
%*ENV<TEMP>,
|
||||
%*ENV<TMP>,
|
||||
'SYS:/temp',
|
||||
'C:\system\temp',
|
||||
'C:/temp',
|
||||
'/tmp',
|
||||
'/')
|
||||
|| self.curdir;
|
||||
}
|
||||
|
||||
method path {
|
||||
my @path = split(';', %*ENV<PATH>);
|
||||
@path».=subst(:global, q/"/, '');
|
||||
@path = grep *.chars, @path;
|
||||
unshift @path, ".";
|
||||
return @path;
|
||||
}
|
||||
|
||||
method is-absolute ($path) {
|
||||
# As of right now, this returns 2 if the path is absolute with a
|
||||
# volume, 1 if it's absolute with no volume, 0 otherwise.
|
||||
given $path {
|
||||
when /^ [<$driveletter> <$slash> | <$UNCpath>]/ { 2 }
|
||||
when /^ <$slash> / { 1 }
|
||||
default { 0 }
|
||||
} #/
|
||||
}
|
||||
|
||||
method split ($path as Str is copy) {
|
||||
$path ~~ s[ <$slash>+ $] = '' #=
|
||||
unless $path ~~ /^ <$driveletter>? <$slash>+ $/;
|
||||
|
||||
$path ~~
|
||||
m/^ ( <$volume_rx> ? )
|
||||
( [ .* <$slash> ]? )
|
||||
(.*)
|
||||
/;
|
||||
my ($volume, $directory, $basename) = (~$0, ~$1, ~$2);
|
||||
$directory ~~ s/ <?after .> <$slash>+ $//;
|
||||
|
||||
|
||||
if all($directory, $basename) eq '' && $volume ne '' {
|
||||
$directory = $volume ~~ /^<$driveletter>/
|
||||
?? '.' !! '\\';
|
||||
}
|
||||
$basename = '\\' if $directory eq any('/', '\\') && $basename eq '';
|
||||
$directory = '.' if $directory eq '' && $basename ne '';
|
||||
|
||||
return (:$volume, :$directory, :$basename);
|
||||
}
|
||||
|
||||
method join ($volume, $directory is copy, $file is copy) {
|
||||
$directory = '' if $directory eq '.' && $file.chars;
|
||||
if $directory.match( /^<$slash>$/ ) && $file.match( /^<$slash>$/ ) {
|
||||
$file = '';
|
||||
$directory = '' if $volume.chars > 2; #i.e. UNC path
|
||||
}
|
||||
self.catpath($volume, $directory, $file);
|
||||
}
|
||||
|
||||
method splitpath($path as Str, :$nofile = False) {
|
||||
|
||||
my ($volume,$directory,$file) = ('','','');
|
||||
if ( $nofile ) {
|
||||
$path ~~
|
||||
/^ (<$volume_rx>?) (.*) /;
|
||||
$volume = ~$0;
|
||||
$directory = ~$1;
|
||||
}
|
||||
else {
|
||||
$path ~~
|
||||
m/^ ( <$volume_rx> ? )
|
||||
( [ .* <$slash> [ '.' ** 1..2 $]? ]? )
|
||||
(.*)
|
||||
/;
|
||||
$volume = ~$0;
|
||||
$directory = ~$1;
|
||||
$file = ~$2;
|
||||
}
|
||||
|
||||
return ($volume,$directory,$file);
|
||||
}
|
||||
|
||||
method catpath($volume is copy, $directory, $file) {
|
||||
|
||||
# Make sure the glue separator is present
|
||||
# unless it's a relative path like A:foo.txt
|
||||
if $volume.chars and $directory.chars
|
||||
and $volume !~~ /^<$driveletter>/
|
||||
and $volume !~~ /<$slash> $/
|
||||
and $directory !~~ /^ <$slash>/
|
||||
{ $volume ~= '\\' }
|
||||
if $file.chars and $directory.chars
|
||||
and $directory !~~ /<$slash> $/
|
||||
{ $volume ~ $directory ~ '\\' ~ $file; }
|
||||
else { $volume ~ $directory ~ $file; }
|
||||
}
|
||||
|
||||
method rel2abs ($path is copy, $base? is copy) {
|
||||
|
||||
my $is_abs = self.is-absolute($path);
|
||||
|
||||
# Check for volume (should probably document the '2' thing...)
|
||||
return self.canonpath( $path ) if $is_abs == 2;
|
||||
|
||||
if $is_abs {
|
||||
# It's missing a volume, add one
|
||||
my $vol;
|
||||
$vol = self.splitpath($base)[0] if $base.defined;
|
||||
$vol ||= self.splitpath($*CWD)[0];
|
||||
return self.canonpath( $vol ~ $path );
|
||||
}
|
||||
|
||||
if not defined $base {
|
||||
# TODO: implement _getdcwd call ( Windows maintains separate CWD for each volume )
|
||||
# See: http://msdn.microsoft.com/en-us/library/1e5zwe0c%28v=vs.80%29.aspx
|
||||
#$base = Cwd::getdcwd( (self.splitpath: $path)[0] ) if defined &Cwd::getdcwd ;
|
||||
#$base //= $*CWD ;
|
||||
$base = $*CWD;
|
||||
}
|
||||
elsif ( !self.is-absolute( $base ) ) {
|
||||
$base = self.rel2abs( $base );
|
||||
}
|
||||
else {
|
||||
$base = self.canonpath( $base );
|
||||
}
|
||||
|
||||
my ($path_directories, $path_file) = self.splitpath( $path )[1..2] ;
|
||||
|
||||
my ($base_volume, $base_directories) = self.splitpath( $base, :nofile ) ;
|
||||
|
||||
$path = self.catpath(
|
||||
$base_volume,
|
||||
self.catdir( $base_directories, $path_directories ),
|
||||
$path_file
|
||||
) ;
|
||||
|
||||
return self.canonpath( $path ) ;
|
||||
}
|
||||
|
||||
|
||||
method !canon-cat ( $first, *@rest, :$parent --> Str) {
|
||||
|
||||
$first ~~ /^ ([ <$driveletter> <$slash>?
|
||||
| <$UNCpath>
|
||||
| [<$slash> ** 2] <$notslash>+
|
||||
| <$slash> ]?)
|
||||
(.*)
|
||||
/;
|
||||
my Str ($volume, $path) = ~$0, ~$1;
|
||||
|
||||
$volume.=subst(:g, '/', '\\');
|
||||
if $volume ~~ /^<$driveletter>/ {
|
||||
$volume.=uc;
|
||||
}
|
||||
elsif $volume.chars && $volume !~~ / '\\' $/ {
|
||||
$volume ~= '\\';
|
||||
}
|
||||
|
||||
$path = join "\\", $path, @rest.flat;
|
||||
$path ~~ s:g/ <$slash>+ /\\/; # /xx\\yy --> \xx\yy
|
||||
$path ~~ s:g/[ ^ | '\\'] '.' '\\.'* [ '\\' | $ ]/\\/; # xx/././yy --> xx/yy
|
||||
if $parent {
|
||||
while $path ~~ s:g { [^ | <?after '\\'>] <!before '..\\'> <-[\\]>+ '\\..' ['\\' | $ ] } = '' { };
|
||||
}
|
||||
$path ~~ s/^ '\\'+ //; # \xx --> xx NOTE: this is *not* root
|
||||
$path ~~ s/ '\\'+ $//; # xx\ --> xx
|
||||
if $volume ~~ / '\\' $ / { # <vol>\.. --> <vol>\
|
||||
$path ~~ s/ ^ '..' '\\..'* [ '\\' | $ ] //;
|
||||
}
|
||||
|
||||
if $path eq '' { # \\HOST\SHARE\ --> \\HOST\SHARE
|
||||
$volume ~~ s/<?after '\\\\' .*> '\\' $ //;
|
||||
$volume || '.';
|
||||
}
|
||||
else {
|
||||
$volume ~ $path;
|
||||
}
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user