mirror of
				https://github.com/KevinMidboe/linguist.git
				synced 2025-10-29 17:50:22 +00:00 
			
		
		
		
	Compare commits
	
		
			602 Commits
		
	
	
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
|  | ec2e3428ec | ||
|  | f8601dd663 | ||
|  | df5faa0f21 | ||
|  | 8341992a38 | ||
|  | 6a8d54e983 | ||
|  | a18155da49 | ||
|  | 2a1e850924 | ||
|  | 528adc1a04 | ||
|  | 9e7b1bf3cb | ||
|  | a517de8168 | ||
|  | a4ab7555e2 | ||
|  | b666123f8e | ||
|  | 8e36ddbafe | ||
|  | abd0c47838 | ||
|  | 8625f91b1b | ||
|  | 6c6b07fc68 | ||
|  | f5a6f20af0 | ||
|  | 76ee294c29 | ||
|  | 77bff8fd6a | ||
|  | 40b2e19310 | ||
|  | aaf281ec0e | ||
|  | 82bc320843 | ||
|  | 1f38db61df | ||
|  | db20462481 | ||
|  | 79be60bf8f | ||
|  | d57ff3abd6 | ||
|  | cd6c315fc8 | ||
|  | 60bc772d48 | ||
|  | 7ad99baf32 | ||
|  | 252ae63854 | ||
|  | 7e3a9434ef | ||
|  | f388daab39 | ||
|  | 89f4885b62 | ||
|  | 23a1ae5085 | ||
|  | 9cd6d6f001 | ||
|  | a15ed48377 | ||
|  | f5e8671481 | ||
|  | 614f4f31ed | ||
|  | 95c8405e0c | ||
|  | e6baa1d690 | ||
|  | 928409a355 | ||
|  | 86c9c9f6f3 | ||
|  | 49f29a53c0 | ||
|  | 40c04c8f6f | ||
|  | 800d26cdad | ||
|  | 016f9852d6 | ||
|  | fbcad41813 | ||
|  | cdf6fb4a22 | ||
|  | 9dc7329601 | ||
|  | bd4204b89e | ||
|  | bbf0e65c74 | ||
|  | b7e2f7cff9 | ||
|  | f9e50f4826 | ||
|  | 184095cc02 | ||
|  | 6a78ac61a7 | ||
|  | b498d51889 | ||
|  | 7fb16b7abe | ||
|  | 7bfdd4086e | ||
|  | dd27ddda17 | ||
|  | b5181488a0 | ||
|  | 001068ec75 | ||
|  | e660442e2e | ||
|  | f7b7a89709 | ||
|  | f46a895ae3 | ||
|  | da396d4c28 | ||
|  | 93556449c9 | ||
|  | 813c150918 | ||
|  | 3ced5ec784 | ||
|  | cdde9096da | ||
|  | 2cb2194686 | ||
|  | 6ae12cd0be | ||
|  | a3e1420476 | ||
|  | 66a2d5fa2e | ||
|  | 582daf273a | ||
|  | 310a804507 | ||
|  | 5e4b860fb7 | ||
|  | 86f78792c4 | ||
|  | 064c62b587 | ||
|  | 7f34de90c6 | ||
|  | 7fb389fda3 | ||
|  | 85e4c58aeb | ||
|  | de47a28ca0 | ||
|  | 0f42d35f29 | ||
|  | d51df2aef3 | ||
|  | 0c02bd18db | ||
|  | 75276c8380 | ||
|  | 442aa4ed33 | ||
|  | 1ab8c8da53 | ||
|  | f03201209f | ||
|  | d79d535182 | ||
|  | 01dc7e2294 | ||
|  | b2d1917fa0 | ||
|  | ca9ca29cc9 | ||
|  | 1ea21fbb8d | ||
|  | 46274496d6 | ||
|  | 16f1f87a8e | ||
|  | 7847e17735 | ||
|  | 8cacd10210 | ||
|  | 9a6446bae3 | ||
|  | f6034b85fb | ||
|  | 55c24a30df | ||
|  | 88afdac5d2 | ||
|  | c5e9023762 | ||
|  | b7d23efc1b | ||
|  | 300d47b36b | ||
|  | e4d381d81c | ||
|  | 3ece15b398 | ||
|  | c8761d39d7 | ||
|  | 51195290b8 | ||
|  | 11be3f3f08 | ||
|  | 91dd8d4950 | ||
|  | 9c26488f29 | ||
|  | b2a5c30a44 | ||
|  | e3d520dba8 | ||
|  | 715680bc36 | ||
|  | b5df71950d | ||
|  | ed6bcfddef | ||
|  | a633dd8c79 | ||
|  | 0974586d5c | ||
|  | 774f658f67 | ||
|  | 37ef402a1f | ||
|  | 99ad32511e | ||
|  | a282b56f46 | ||
|  | 9845eba9df | ||
|  | a49303c93f | ||
|  | 4adbbc3fcc | ||
|  | 03cadf22fa | ||
|  | 89c8d1e64c | ||
|  | 56ebfae598 | ||
|  | b1bb1a7345 | ||
|  | 4510bf1007 | ||
|  | dd8b368f76 | ||
|  | 17d0b1e02f | ||
|  | 0626def699 | ||
|  | b3c6c85387 | ||
|  | 455266f27d | ||
|  | 567408bc5e | ||
|  | 0c668ee179 | ||
|  | 8c9ba2214a | ||
|  | 8ba773127c | ||
|  | c598c9717d | ||
|  | ef41a1ac67 | ||
|  | 3bc17e822d | ||
|  | 6bd97c7fc7 | ||
|  | f6c4e39dbc | ||
|  | 7c636c4f65 | ||
|  | 6a8de63d2d | ||
|  | 107fee8859 | ||
|  | 1cb1705f8e | ||
|  | e0c1a84821 | ||
|  | b7249b671f | ||
|  | f5e86bc691 | ||
|  | 109841ceb1 | ||
|  | 1b96f87888 | ||
|  | 4d40cab954 | ||
|  | 4533b9baaa | ||
|  | 5b35f92bfe | ||
|  | 17d54d61b4 | ||
|  | 2a867c9c7f | ||
|  | 5a4bbf42c1 | ||
|  | 087ce10f12 | ||
|  | 27092191a8 | ||
|  | bc93a99864 | ||
|  | 2e4fbe3430 | ||
|  | 64f77293e8 | ||
|  | 9a42628577 | ||
|  | fc9bc8b9e1 | ||
|  | 2180c11dc6 | ||
|  | 11207283c8 | ||
|  | 8552ec35b3 | ||
|  | 5fdc2e12bf | ||
|  | 37c8a94369 | ||
|  | 7d17d69c1b | ||
|  | ee519aeb4b | ||
|  | a825a013d6 | ||
|  | b4906fc3b8 | ||
|  | fafeead5dc | ||
|  | 5c602d0a4e | ||
|  | 96084fa59a | ||
|  | c8eeda6c8a | ||
|  | 2315cdb993 | ||
|  | 2245174d28 | ||
|  | c089b3f28f | ||
|  | 7e178cc416 | ||
|  | 8603760ebe | ||
|  | 5bbffb00f5 | ||
|  | 4476a23f5a | ||
|  | 834f37810b | ||
|  | 7e9bc26796 | ||
|  | f83f226edc | ||
|  | a04b9dd7cd | ||
|  | f1ffc9e581 | ||
|  | de636f1c0b | ||
|  | ec6ef033a1 | ||
|  | a375a063d5 | ||
|  | d66147a277 | ||
|  | 283cc3a975 | ||
|  | 23af754194 | ||
|  | 50f4050444 | ||
|  | bf11900bc9 | ||
|  | 61b8a8969f | ||
|  | 0fb7017add | ||
|  | 86329a0758 | ||
|  | 4a5165ad7f | ||
|  | 017c6fd3f2 | ||
|  | 3887acd915 | ||
|  | a80bf9e024 | ||
|  | 27c9774d1b | ||
|  | 10cadb8725 | ||
|  | 9a5d52e460 | ||
|  | a8ae3d3ae5 | ||
|  | 9bf1b5867a | ||
|  | f64a589e98 | ||
|  | 72026d3a3d | ||
|  | 53f29344f8 | ||
|  | 0436973fb7 | ||
|  | 3a8651e31f | ||
|  | 953768641c | ||
|  | b59d80b00c | ||
|  | 56dec42c70 | ||
|  | c88585cffb | ||
|  | 46779da3b5 | ||
|  | 654050a459 | ||
|  | c2ca9f40ac | ||
|  | fe9f186b13 | ||
|  | 01616ef54e | ||
|  | 9fd802a208 | ||
|  | 86e0b94700 | ||
|  | 6e4e5e78ad | ||
|  | 183c280263 | ||
|  | cb0b3a688f | ||
|  | 4f656c200b | ||
|  | 791d9eed41 | ||
|  | 74775b2e0a | ||
|  | 04c78c8c33 | ||
|  | 762b389721 | ||
|  | 32e10d2c37 | ||
|  | d7baf4ed7b | ||
|  | 5bef198e6d | ||
|  | c03e310422 | ||
|  | 43723ba5ef | ||
|  | 25954c8992 | ||
|  | 12f01e9e94 | ||
|  | 41f7589d4e | ||
|  | d93edf0897 | ||
|  | 7a6202a8c3 | ||
|  | 240f6a63f4 | ||
|  | f0558769f2 | ||
|  | 12086b69ac | ||
|  | e47b312866 | ||
|  | eb5f1468d2 | ||
|  | 77c7ee6d2e | ||
|  | 4f547d79a9 | ||
|  | 8a5b26536e | ||
|  | 355ac3d81a | ||
|  | 8b8123a3c1 | ||
|  | fc44af9343 | ||
|  | 4654553d07 | ||
|  | 940df300e8 | ||
|  | 72b8e1c76f | ||
|  | 92282e3677 | ||
|  | 9e9cbb144e | ||
|  | 8c5f1e201e | ||
|  | ab20c033fe | ||
|  | fd9c657ed4 | ||
|  | fea07d025d | ||
|  | 41a570818d | ||
|  | c1e38425d0 | ||
|  | 6fb4e6836c | ||
|  | a2f9150f50 | ||
|  | 2dcee1e43c | ||
|  | 867a4d96fe | ||
|  | b8c7b71ca5 | ||
|  | 70396ab636 | ||
|  | 67b5b51c47 | ||
|  | 7b443fcdde | ||
|  | d86f8ba12f | ||
|  | 856ee4724c | ||
|  | e635af4ef9 | ||
|  | b30163444f | ||
|  | 051bedefab | ||
|  | 1d7f63e38b | ||
|  | d96657a48b | ||
|  | 8bdd6ea510 | ||
|  | 9f65e702fc | ||
|  | a500dee94e | ||
|  | 1a11a6ab48 | ||
|  | c5f1317b47 | ||
|  | 5e03ff961b | ||
|  | a0c06eb6b9 | ||
|  | 7f9142a41d | ||
|  | 94b3ea3df5 | ||
|  | 6d7eae5011 | ||
|  | 3bbeea3682 | ||
|  | 562ec13696 | ||
|  | a5c3bd7c13 | ||
|  | 6ae6882e1a | ||
|  | c4ad830931 | ||
|  | 5d417b4669 | ||
|  | 02a264fad8 | ||
|  | 31c3c43f64 | ||
|  | 5197ea2488 | ||
|  | 66167de1f9 | ||
|  | 9482c2b822 | ||
|  | 012a9c0e05 | ||
|  | 881201a2c6 | ||
|  | d656988258 | ||
|  | 89f7f8a00b | ||
|  | e4ec48fe8d | ||
|  | 1a4f890d04 | ||
|  | 71633871f3 | ||
|  | f523561e66 | ||
|  | f3007215b1 | ||
|  | 1847b237c9 | ||
|  | 07169db217 | ||
|  | 4b4b368356 | ||
|  | 09ef0cd3e1 | ||
|  | 0f6bca7a3d | ||
|  | 5e3d811902 | ||
|  | 12c655a48a | ||
|  | fdddffe041 | ||
|  | c3aab69b11 | ||
|  | 3f1161d713 | ||
|  | cf14c5fa4f | ||
|  | 8aac009b00 | ||
|  | 05bb8b10fd | ||
|  | ecacbc937b | ||
|  | 86d0f0a84a | ||
|  | 34218d9a5c | ||
|  | de7ca0d954 | ||
|  | 81176f8dfa | ||
|  | 6ee999617e | ||
|  | 88442094f9 | ||
|  | 5037dd5add | ||
|  | aa41c87158 | ||
|  | 569eac2222 | ||
|  | 2de23046cc | ||
|  | ca8b27ff15 | ||
|  | 0f17ba0fcf | ||
|  | d5002ef06a | ||
|  | ce443e73f1 | ||
|  | 89b5e9f5e6 | ||
|  | c6c5e79ccf | ||
|  | 2bac3af299 | ||
|  | 5411c5457d | ||
|  | 92595cffa3 | ||
|  | ad77279bbf | ||
|  | e7d8b99ca2 | ||
|  | 971d848eec | ||
|  | f353fa3890 | ||
|  | 64ce62a804 | ||
|  | bb9537c5b4 | ||
|  | 9f00b5478d | ||
|  | 086b565488 | ||
|  | 27566d93e2 | ||
|  | 7b1c78b848 | ||
|  | 4ec9145700 | ||
|  | 922fe46f56 | ||
|  | d4628cf5db | ||
|  | cb9c3732f2 | ||
|  | ce6a8aa671 | ||
|  | bda61ec3d2 | ||
|  | 3ea0d479fc | ||
|  | 9ff1a9a54c | ||
|  | 024005d912 | ||
|  | 4d7cd834be | ||
|  | 281e7456d5 | ||
|  | f41c79066b | ||
|  | 063ba50952 | ||
|  | 70bc0b3b77 | ||
|  | 057ea80582 | ||
|  | a046e1c380 | ||
|  | e3c2a5e510 | ||
|  | a00967ddc4 | ||
|  | 599e1e2a51 | ||
|  | 44638e1c6b | ||
|  | cabd4fb4c5 | ||
|  | 086845f189 | ||
|  | 413c881af8 | ||
|  | 74eb60a354 | ||
|  | 85e54e9af2 | ||
|  | 245521db22 | ||
|  | 5b8ad31d75 | ||
|  | 80321272b1 | ||
|  | 02500d3830 | ||
|  | 921ceaa221 | ||
|  | 5232a45d1f | ||
|  | fdf000ec62 | ||
|  | c7933537b1 | ||
|  | e194d7238e | ||
|  | 33d777a6ff | ||
|  | 1b90dfedf9 | ||
|  | b0b7d75bcd | ||
|  | 74ba0f9c39 | ||
|  | 8465961e72 | ||
|  | f5cb6e035d | ||
|  | 7946de7116 | ||
|  | 9e65eb35e7 | ||
|  | 76a1369932 | ||
|  | 12e92f127b | ||
|  | 50f3b2e398 | ||
|  | a716151c83 | ||
|  | 3c70fffb67 | ||
|  | a0a879a3a3 | ||
|  | 5d35d18634 | ||
|  | a3a6c2f8b3 | ||
|  | 8eef1c33b8 | ||
|  | 6182b0fbc2 | ||
|  | 4e4f3c6e17 | ||
|  | 800f445b22 | ||
|  | a9db25cc5b | ||
|  | b5e1bda3e4 | ||
|  | f06167eaca | ||
|  | 687e82307e | ||
|  | d9358d8af3 | ||
|  | fb3e59c6f5 | ||
|  | b3fbd42786 | ||
|  | 590ed26f7b | ||
|  | 12093ee1f0 | ||
|  | c0c0252bab | ||
|  | 02953ac3ef | ||
|  | ee840321d1 | ||
|  | 0cbc44677c | ||
|  | a9b944ac36 | ||
|  | 759860d866 | ||
|  | c4b21f51e4 | ||
|  | fdccffddfc | ||
|  | e610789d38 | ||
|  | 3bd8ed45e4 | ||
|  | 42311e1bf3 | ||
|  | 9e9aae1d83 | ||
|  | 229ab3a268 | ||
|  | 85840aadc2 | ||
|  | 32b7b3e1b1 | ||
|  | 5e7eeae98e | ||
|  | de8c4daa45 | ||
|  | 64990a00b8 | ||
|  | 33434f08f4 | ||
|  | d5730f6fd1 | ||
|  | 2305496f94 | ||
|  | d031392507 | ||
|  | 7e251d7345 | ||
|  | e33e76a1a7 | ||
|  | 9064369517 | ||
|  | a9c86d5453 | ||
|  | 4b0c975426 | ||
|  | 6ec22a1674 | ||
|  | 71b48eaf55 | ||
|  | 694f51d09e | ||
|  | 79040d00c7 | ||
|  | 7dfc1644ce | ||
|  | 777f1d27d1 | ||
|  | c4a90bbbcd | ||
|  | ac0920a11b | ||
|  | a4bdca6d6b | ||
|  | f9bfcceba9 | ||
|  | e0ceccc0c6 | ||
|  | cd3e88fe8b | ||
|  | 254b6de1d3 | ||
|  | a93e9493e2 | ||
|  | 53b356deee | ||
|  | 9dca6fa9cc | ||
|  | 7226aa18de | ||
|  | ce97865bd2 | ||
|  | 424fa0f56b | ||
|  | 007fc9ebd0 | ||
|  | e0104c8d12 | ||
|  | 1a98a1f938 | ||
|  | e005893d4c | ||
|  | 6c74d854ec | ||
|  | 06b185f725 | ||
|  | 64ec42cf4a | ||
|  | c4b24d9ae1 | ||
|  | e6f38cbf45 | ||
|  | 1764674a13 | ||
|  | 4741a47d21 | ||
|  | 432bffe3ec | ||
|  | 090216df2a | ||
|  | 7b2fec88d1 | ||
|  | 76128ccb37 | ||
|  | f5ede0d0f9 | ||
|  | 70d1649b45 | ||
|  | de706a2eb9 | ||
|  | 33ebee0f6a | ||
|  | 51a989d5f1 | ||
|  | 3fc208b4ce | ||
|  | 0fa54a85d8 | ||
|  | 96e8a5d2cc | ||
|  | 838fbc5626 | ||
|  | 486af800b5 | ||
|  | f0b9b3a35a | ||
|  | 80780ab042 | ||
|  | bd19f6ed17 | ||
|  | 2ae76842a0 | ||
|  | 750804876e | ||
|  | 1d8da964e2 | ||
|  | d21d0f281a | ||
|  | a8e337e0eb | ||
|  | 37429d91a0 | ||
|  | 4b9c6fdf62 | ||
|  | 4130825a43 | ||
|  | 8c42e61271 | ||
|  | 6d95590861 | ||
|  | dbc36a5e63 | ||
|  | 32a106cedd | ||
|  | 78ed103f90 | ||
|  | 3e26b2a0a7 | ||
|  | 4fb910533f | ||
|  | b71cab6add | ||
|  | 394fb528cc | ||
|  | d2f4eec397 | ||
|  | 5f29bf3bb4 | ||
|  | 5a9d35917f | ||
|  | 0029183078 | ||
|  | 0978258f57 | ||
|  | 772a9a582c | ||
|  | e633d565a9 | ||
|  | 7d6ee108c4 | ||
|  | dd64c3b545 | ||
|  | b462e29e1d | ||
|  | 43f4f5bd32 | ||
|  | 904e86d901 | ||
|  | 374164a299 | ||
|  | f73f309595 | ||
|  | f23110a98d | ||
|  | 3193fc90f9 | ||
|  | cc04519520 | ||
|  | f51c5e3159 | ||
|  | a75d918b93 | ||
|  | c439ca5f97 | ||
|  | 4d45f13783 | ||
|  | 2a56719378 | ||
|  | 23289d8901 | ||
|  | 7d594b55e4 | ||
|  | 5268a93fa4 | ||
|  | ae44530a66 | ||
|  | 285216a258 | ||
|  | 4d3720745e | ||
|  | a681a252d4 | ||
|  | 22de40f5f6 | ||
|  | 7fbfe0a4b4 | ||
|  | 29f5ea591f | ||
|  | 438c0a4ec1 | ||
|  | 887933c86a | ||
|  | 53340ddd4c | ||
|  | 72b70a11bc | ||
|  | d853864edb | ||
|  | 62ad763933 | ||
|  | 6a15ae47ee | ||
|  | 1bebb50482 | ||
|  | d351d6091d | ||
|  | fae8f83f64 | ||
|  | d3d62726ae | ||
|  | cf15832504 | ||
|  | fdc81d8818 | ||
|  | 764df07450 | ||
|  | 68dfff60b5 | ||
|  | 479871f019 | ||
|  | 10ec56e667 | ||
|  | 1e958a18f8 | ||
|  | 9fa0f6cd6f | ||
|  | 4e339db911 | ||
|  | c1469b25a1 | ||
|  | ef6abed81a | ||
|  | 96473849e0 | ||
|  | b14e09af6b | ||
|  | 42050c4d12 | ||
|  | 1af71c8945 | ||
|  | acc1a56da4 | ||
|  | fab34da3e7 | ||
|  | a9a28ce58d | ||
|  | f2b80a239f | ||
|  | c6d38ab647 | ||
|  | 420594874a | ||
|  | 407c40f7d3 | ||
|  | 89bc82d9df | ||
|  | 30aa3fd5d6 | ||
|  | 22cdb9ee90 | ||
|  | df448c0761 | ||
|  | 1e93e98d30 | ||
|  | d0034b4fb9 | ||
|  | 3b79cf3cf2 | ||
|  | 5b06a46451 | ||
|  | 15a746650c | ||
|  | e408b5fbaa | ||
|  | e26bf5a0d2 | ||
|  | 465d60ba86 | ||
|  | d5c3978a6e | ||
|  | d4312c05bf | ||
|  | 7efad57176 | ||
|  | ec786b73bc | ||
|  | 14d363b942 | ||
|  | f8c6277946 | ||
|  | 8254bcc3ac | ||
|  | a8b2b0a86b | ||
|  | fc8d2f641c | ||
|  | 9a5f9a5e9b | ||
|  | 806369ce7f | ||
|  | 4398cda9a5 | ||
|  | 0479f72a93 | ||
|  | 0f006af583 | ||
|  | 2bbf92d5f8 | 
| @@ -1,8 +1,12 @@ | |||||||
| before_install: sudo apt-get install libicu-dev -y | before_install:  | ||||||
|  |   - sudo apt-get install libicu-dev -y | ||||||
|  |   # Short-term fix addressing https://github.com/bundler/bundler/issues/2784 | ||||||
|  |   - gem update --system 2.1.11 | ||||||
| rvm: | rvm: | ||||||
|   - 1.8.7 |   - 1.8.7 | ||||||
|   - 1.9.2 |   - 1.9.2 | ||||||
|   - 1.9.3 |   - 1.9.3 | ||||||
|  |   - 2.0.0 | ||||||
|   - ree |   - ree | ||||||
| notifications: | notifications: | ||||||
|   disabled: true |   disabled: true | ||||||
|   | |||||||
							
								
								
									
										5
									
								
								Gemfile
									
									
									
									
									
								
							
							
						
						
									
										5
									
								
								Gemfile
									
									
									
									
									
								
							| @@ -1,2 +1,7 @@ | |||||||
| source 'https://rubygems.org' | source 'https://rubygems.org' | ||||||
| gemspec | gemspec | ||||||
|  |  | ||||||
|  | if RUBY_VERSION < "1.9.3" | ||||||
|  |   # escape_utils 1.0.0 requires 1.9.3 and above | ||||||
|  |   gem "escape_utils", "0.3.2" | ||||||
|  | end | ||||||
|   | |||||||
							
								
								
									
										2
									
								
								LICENSE
									
									
									
									
									
								
							
							
						
						
									
										2
									
								
								LICENSE
									
									
									
									
									
								
							| @@ -1,4 +1,4 @@ | |||||||
| Copyright (c) 2011 GitHub, Inc. | Copyright (c) 2011-2014 GitHub, Inc. | ||||||
|  |  | ||||||
| Permission is hereby granted, free of charge, to any person | Permission is hereby granted, free of charge, to any person | ||||||
| obtaining a copy of this software and associated documentation | obtaining a copy of this software and associated documentation | ||||||
|   | |||||||
							
								
								
									
										51
									
								
								README.md
									
									
									
									
									
								
							
							
						
						
									
										51
									
								
								README.md
									
									
									
									
									
								
							| @@ -1,18 +1,20 @@ | |||||||
| # Linguist | # Linguist | ||||||
|  |  | ||||||
| We use this library at GitHub to detect blob languages, highlight code, ignore binary files, suppress generated files in diffs and generate language breakdown graphs. | We use this library at GitHub to detect blob languages, highlight code, ignore binary files, suppress generated files in diffs, and generate language breakdown graphs. | ||||||
|  |  | ||||||
| ## Features | ## Features | ||||||
|  |  | ||||||
| ### Language detection | ### Language detection | ||||||
|  |  | ||||||
| Linguist defines the list of all languages known to GitHub in a [yaml file](https://github.com/github/linguist/blob/master/lib/linguist/languages.yml). In order for a file to be highlighted, a language and lexer must be defined there. | Linguist defines a list of all languages known to GitHub in a [yaml file](https://github.com/github/linguist/blob/master/lib/linguist/languages.yml). In order for a file to be highlighted, a language and lexer must be defined there. | ||||||
|  |  | ||||||
| Most languages are detected by their file extension. This is the fastest and most common situation. | Most languages are detected by their file extension. This is the fastest and most common situation. | ||||||
|  |  | ||||||
| For disambiguating between files with common extensions, we use a [Bayesian classifier](https://github.com/github/linguist/blob/master/lib/linguist/classifier.rb). For an example, this helps us tell the difference between `.h` files which could be either C, C++, or Obj-C. | For disambiguating between files with common extensions, we first apply | ||||||
|  | some common-sense heuristics to pick out obvious languages. After that, we use a | ||||||
| In the actual GitHub app we deal with `Grit::Blob` objects. For testing, there is a simple `FileBlob` API. | [statistical | ||||||
|  | classifier](https://github.com/github/linguist/blob/master/lib/linguist/classifier.rb). | ||||||
|  | This process can help us tell the difference between, for example, `.h` files which could be either C, C++, or Obj-C. | ||||||
|  |  | ||||||
| ```ruby | ```ruby | ||||||
|  |  | ||||||
| @@ -27,13 +29,11 @@ See [lib/linguist/language.rb](https://github.com/github/linguist/blob/master/li | |||||||
|  |  | ||||||
| The actual syntax highlighting is handled by our Pygments wrapper, [pygments.rb](https://github.com/tmm1/pygments.rb). It also provides a [Lexer abstraction](https://github.com/tmm1/pygments.rb/blob/master/lib/pygments/lexer.rb) that determines which highlighter should be used on a file. | The actual syntax highlighting is handled by our Pygments wrapper, [pygments.rb](https://github.com/tmm1/pygments.rb). It also provides a [Lexer abstraction](https://github.com/tmm1/pygments.rb/blob/master/lib/pygments/lexer.rb) that determines which highlighter should be used on a file. | ||||||
|  |  | ||||||
| We typically run on a pre-release version of Pygments, [pygments.rb](https://github.com/tmm1/pygments.rb), to get early access to new lexers. The [languages.yml](https://github.com/github/linguist/blob/master/lib/linguist/languages.yml) file is a dump of the lexers we have available on our server. |  | ||||||
|  |  | ||||||
| ### Stats | ### Stats | ||||||
|  |  | ||||||
| The Language Graph you see on every repository is built by aggregating the languages of all repo's blobs. The top language in the graph determines the project's primary language. Collectively, these stats make up the [Top Languages](https://github.com/languages) page. | The Language stats bar that you see on every repository is built by aggregating the languages of each file in that repository. The top language in the graph determines the project's primary language. Collectively, these stats make up the [Top Languages](https://github.com/languages) page. | ||||||
|  |  | ||||||
| The repository stats API can be used on a directory: | The repository stats API, accessed through `#languages`, can be used on a directory: | ||||||
|  |  | ||||||
| ```ruby | ```ruby | ||||||
| project = Linguist::Repository.from_directory(".") | project = Linguist::Repository.from_directory(".") | ||||||
| @@ -41,10 +41,27 @@ project.language.name  #=> "Ruby" | |||||||
| project.languages      #=> { "Ruby" => 0.98, "Shell" => 0.02 } | project.languages      #=> { "Ruby" => 0.98, "Shell" => 0.02 } | ||||||
| ``` | ``` | ||||||
|  |  | ||||||
| These stats are also printed out by the binary. Try running `linguist` on itself: | These stats are also printed out by the `linguist` binary. You can use the | ||||||
|  | `--breakdown` flag, and the binary will also output the breakdown of files by language. | ||||||
|  |  | ||||||
|     $ bundle exec linguist lib/ | You can try running `linguist` on the `lib/` directory in this repository itself: | ||||||
|     100%  Ruby |  | ||||||
|  |     $ bundle exec linguist lib/ --breakdown | ||||||
|  |  | ||||||
|  |     100.00% Ruby | ||||||
|  |  | ||||||
|  |     Ruby: | ||||||
|  |     linguist/blob_helper.rb | ||||||
|  |     linguist/classifier.rb | ||||||
|  |     linguist/file_blob.rb | ||||||
|  |     linguist/generated.rb | ||||||
|  |     linguist/heuristics.rb | ||||||
|  |     linguist/language.rb | ||||||
|  |     linguist/md5.rb | ||||||
|  |     linguist/repository.rb | ||||||
|  |     linguist/samples.rb | ||||||
|  |     linguist/tokenizer.rb | ||||||
|  |     linguist.rb | ||||||
|  |  | ||||||
| #### Ignore vendored files | #### Ignore vendored files | ||||||
|  |  | ||||||
| @@ -82,14 +99,18 @@ To run the tests: | |||||||
|  |  | ||||||
| ## Contributing | ## Contributing | ||||||
|  |  | ||||||
| The majority of patches won't need to touch any Ruby code at all. The [master language list](https://github.com/github/linguist/blob/master/lib/linguist/languages.yml) is just a configuration file. | The majority of contributions won't need to touch any Ruby code at all. The [master language list](https://github.com/github/linguist/blob/master/lib/linguist/languages.yml) is just a YAML configuration file. | ||||||
|  |  | ||||||
| We try to only add languages once they have a some usage on GitHub, so please note in-the-wild usage examples in your pull request. | We try to only add languages once they have some usage on GitHub, so please note in-the-wild usage examples in your pull request. | ||||||
|  |  | ||||||
| Almost all bug fixes or new language additions should come with some additional code samples. Just drop them under [`samples/`](https://github.com/github/linguist/tree/master/samples) in the correct subdirectory and our test suite will automatically test them. In most cases you shouldn't need to add any new assertions. | Almost all bug fixes or new language additions should come with some additional code samples. Just drop them under [`samples/`](https://github.com/github/linguist/tree/master/samples) in the correct subdirectory and our test suite will automatically test them. In most cases you shouldn't need to add any new assertions. | ||||||
|  |  | ||||||
|  | To update the `samples.json` after adding new files to [`samples/`](https://github.com/github/linguist/tree/master/samples): | ||||||
|  |  | ||||||
|  |     bundle exec rake samples | ||||||
|  |  | ||||||
| ### Testing | ### Testing | ||||||
|  |  | ||||||
| Sometimes getting the tests running can be too much work, especially if you don't have much Ruby experience. It's okay, be lazy and let our build bot [Travis](http://travis-ci.org/#!/github/linguist) run the tests for you. Just open a pull request and the bot will start cranking away. | Sometimes getting the tests running can be too much work, especially if you don't have much Ruby experience. It's okay: be lazy and let our build bot [Travis](http://travis-ci.org/#!/github/linguist) run the tests for you. Just open a pull request and the bot will start cranking away. | ||||||
|  |  | ||||||
| Here's our current build status, which is hopefully green: [](http://travis-ci.org/github/linguist) | Here's our current build status, which is hopefully green: [](http://travis-ci.org/github/linguist) | ||||||
|   | |||||||
							
								
								
									
										9
									
								
								Rakefile
									
									
									
									
									
								
							
							
						
						
									
										9
									
								
								Rakefile
									
									
									
									
									
								
							| @@ -1,5 +1,7 @@ | |||||||
|  | require 'json' | ||||||
| require 'rake/clean' | require 'rake/clean' | ||||||
| require 'rake/testtask' | require 'rake/testtask' | ||||||
|  | require 'yaml' | ||||||
|  |  | ||||||
| task :default => :test | task :default => :test | ||||||
|  |  | ||||||
| @@ -13,6 +15,13 @@ task :samples do | |||||||
|   File.open('lib/linguist/samples.json', 'w') { |io| io.write json } |   File.open('lib/linguist/samples.json', 'w') { |io| io.write json } | ||||||
| end | end | ||||||
|  |  | ||||||
|  | task :build_gem do | ||||||
|  |   languages = YAML.load_file("lib/linguist/languages.yml") | ||||||
|  |   File.write("lib/linguist/languages.json", JSON.dump(languages)) | ||||||
|  |   `gem build github-linguist.gemspec` | ||||||
|  |   File.delete("lib/linguist/languages.json") | ||||||
|  | end | ||||||
|  |  | ||||||
| namespace :classifier do | namespace :classifier do | ||||||
|   LIMIT = 1_000 |   LIMIT = 1_000 | ||||||
|  |  | ||||||
|   | |||||||
							
								
								
									
										28
									
								
								bin/linguist
									
									
									
									
									
								
							
							
						
						
									
										28
									
								
								bin/linguist
									
									
									
									
									
								
							| @@ -1,15 +1,39 @@ | |||||||
| #!/usr/bin/env ruby | #!/usr/bin/env ruby | ||||||
|  |  | ||||||
|  | # linguist — detect language type for a file, or, given a directory, determine language breakdown | ||||||
|  | #     usage: linguist <path> [<--breakdown>] | ||||||
|  |  | ||||||
| require 'linguist/file_blob' | require 'linguist/file_blob' | ||||||
| require 'linguist/repository' | require 'linguist/repository' | ||||||
|  |  | ||||||
| path = ARGV[0] || Dir.pwd | path = ARGV[0] || Dir.pwd | ||||||
|  |  | ||||||
|  | # special case if not given a directory but still given the --breakdown option | ||||||
|  | if path == "--breakdown" | ||||||
|  |   path = Dir.pwd | ||||||
|  |   breakdown = true | ||||||
|  | end | ||||||
|  |  | ||||||
|  | ARGV.shift | ||||||
|  | breakdown = true if ARGV[0] == "--breakdown" | ||||||
|  |  | ||||||
| if File.directory?(path) | if File.directory?(path) | ||||||
|   repo = Linguist::Repository.from_directory(path) |   repo = Linguist::Repository.from_directory(path) | ||||||
|   repo.languages.sort_by { |_, size| size }.reverse.each do |language, size| |   repo.languages.sort_by { |_, size| size }.reverse.each do |language, size| | ||||||
|     percentage = ((size / repo.size.to_f) * 100).round |     percentage = ((size / repo.size.to_f) * 100) | ||||||
|     puts "%-4s %s" % ["#{percentage}%", language] |     percentage = sprintf '%.2f' % percentage | ||||||
|  |     puts "%-7s %s" % ["#{percentage}%", language] | ||||||
|  |   end | ||||||
|  |   if breakdown | ||||||
|  |     puts | ||||||
|  |     file_breakdown = repo.breakdown_by_file | ||||||
|  |     file_breakdown.each do |lang, files| | ||||||
|  |       puts "#{lang}:"  | ||||||
|  |       files.each do |file| | ||||||
|  |         puts file | ||||||
|  |       end | ||||||
|  |       puts | ||||||
|  |     end | ||||||
|   end |   end | ||||||
| elsif File.file?(path) | elsif File.file?(path) | ||||||
|   blob = Linguist::FileBlob.new(path, Dir.pwd) |   blob = Linguist::FileBlob.new(path, Dir.pwd) | ||||||
|   | |||||||
| @@ -1,20 +1,23 @@ | |||||||
| Gem::Specification.new do |s| | Gem::Specification.new do |s| | ||||||
|   s.name    = 'github-linguist' |   s.name    = 'github-linguist' | ||||||
|   s.version = '2.7.0' |   s.version = '2.10.11' | ||||||
|   s.summary = "GitHub Language detection" |   s.summary = "GitHub Language detection" | ||||||
|  |   s.description = 'We use this library at GitHub to detect blob languages, highlight code, ignore binary files, suppress generated files in diffs, and generate language breakdown graphs.' | ||||||
|  |  | ||||||
|   s.authors  = "GitHub" |   s.authors  = "GitHub" | ||||||
|   s.homepage = "https://github.com/github/linguist" |   s.homepage = "https://github.com/github/linguist" | ||||||
|  |   s.license  = "MIT" | ||||||
|  |  | ||||||
|   s.files = Dir['lib/**/*'] |   s.files = Dir['lib/**/*'] | ||||||
|   s.executables << 'linguist' |   s.executables << 'linguist' | ||||||
|  |  | ||||||
|   s.add_dependency 'charlock_holmes', '~> 0.6.6' |   s.add_dependency 'charlock_holmes', '~> 0.6.6' | ||||||
|   s.add_dependency 'escape_utils',    '~> 0.3.1' |   s.add_dependency 'escape_utils',    '>= 0.3.1' | ||||||
|   s.add_dependency 'mime-types',      '~> 1.19' |   s.add_dependency 'mime-types',      '~> 1.19' | ||||||
|   s.add_dependency 'pygments.rb',     '~> 0.4.2' |   s.add_dependency 'pygments.rb',     '~> 0.5.4' | ||||||
|   s.add_development_dependency 'mocha' |  | ||||||
|   s.add_development_dependency 'json' |   s.add_development_dependency 'json' | ||||||
|  |   s.add_development_dependency 'mocha' | ||||||
|   s.add_development_dependency 'rake' |   s.add_development_dependency 'rake' | ||||||
|   s.add_development_dependency 'yajl-ruby' |   s.add_development_dependency 'yajl-ruby' | ||||||
| end | end | ||||||
|   | |||||||
| @@ -1,5 +1,6 @@ | |||||||
| require 'linguist/blob_helper' | require 'linguist/blob_helper' | ||||||
| require 'linguist/generated' | require 'linguist/generated' | ||||||
|  | require 'linguist/heuristics' | ||||||
| require 'linguist/language' | require 'linguist/language' | ||||||
| require 'linguist/repository' | require 'linguist/repository' | ||||||
| require 'linguist/samples' | require 'linguist/samples' | ||||||
|   | |||||||
| @@ -189,10 +189,9 @@ module Linguist | |||||||
|  |  | ||||||
|     # Public: Is the blob safe to colorize? |     # Public: Is the blob safe to colorize? | ||||||
|     # |     # | ||||||
|     # We use Pygments.rb for syntax highlighting blobs, which |     # We use Pygments for syntax highlighting blobs. Pygments | ||||||
|     # has some quirks and also is essentially 'un-killable' via |     # can be too slow for very large blobs or for certain | ||||||
|     # normal timeout.  To workaround this we try to |     # corner-case blobs. | ||||||
|     # carefully handling Pygments.rb anything it can't handle. |  | ||||||
|     # |     # | ||||||
|     # Return true or false |     # Return true or false | ||||||
|     def safe_to_colorize? |     def safe_to_colorize? | ||||||
|   | |||||||
| @@ -15,8 +15,8 @@ module Linguist | |||||||
|     # |     # | ||||||
|     # Returns nothing. |     # Returns nothing. | ||||||
|     # |     # | ||||||
|     # Set LINGUIST_DEBUG=1 or =2 to see probabilities per-token, |     # Set LINGUIST_DEBUG=1 or =2 to see probabilities per-token or | ||||||
|     # per-language.  See also dump_all_tokens, below. |     # per-language.  See also #dump_all_tokens, below. | ||||||
|     def self.train!(db, language, data) |     def self.train!(db, language, data) | ||||||
|       tokens = Tokenizer.tokenize(data) |       tokens = Tokenizer.tokenize(data) | ||||||
|  |  | ||||||
| @@ -78,18 +78,13 @@ module Linguist | |||||||
|     def classify(tokens, languages) |     def classify(tokens, languages) | ||||||
|       return [] if tokens.nil? |       return [] if tokens.nil? | ||||||
|       tokens = Tokenizer.tokenize(tokens) if tokens.is_a?(String) |       tokens = Tokenizer.tokenize(tokens) if tokens.is_a?(String) | ||||||
|  |  | ||||||
|       scores = {} |       scores = {} | ||||||
|       if verbosity >= 2 |  | ||||||
|         dump_all_tokens(tokens, languages) |       debug_dump_all_tokens(tokens, languages) if verbosity >= 2 | ||||||
|       end |  | ||||||
|       languages.each do |language| |       languages.each do |language| | ||||||
|         scores[language] = tokens_probability(tokens, language) + |         scores[language] = tokens_probability(tokens, language) + language_probability(language) | ||||||
|                                    language_probability(language) |         debug_dump_probabilities(tokens, language, scores[language]) if verbosity >= 1 | ||||||
|         if verbosity >= 1 |  | ||||||
|           printf "%10s = %10.3f + %7.3f = %10.3f\n", |  | ||||||
|             language, tokens_probability(tokens, language), language_probability(language), scores[language] |  | ||||||
|         end |  | ||||||
|       end |       end | ||||||
|  |  | ||||||
|       scores.sort { |a, b| b[1] <=> a[1] }.map { |score| [score[0], score[1]] } |       scores.sort { |a, b| b[1] <=> a[1] }.map { |score| [score[0], score[1]] } | ||||||
| @@ -135,6 +130,11 @@ module Linguist | |||||||
|         @verbosity ||= (ENV['LINGUIST_DEBUG'] || 0).to_i |         @verbosity ||= (ENV['LINGUIST_DEBUG'] || 0).to_i | ||||||
|       end |       end | ||||||
|  |  | ||||||
|  |       def debug_dump_probabilities(tokens, language, score) | ||||||
|  |         printf("%10s = %10.3f + %7.3f = %10.3f\n", | ||||||
|  |             language, tokens_probability(tokens, language), language_probability(language), score) | ||||||
|  |       end | ||||||
|  |  | ||||||
|       # Internal: show a table of probabilities for each <token,language> pair. |       # Internal: show a table of probabilities for each <token,language> pair. | ||||||
|       # |       # | ||||||
|       # The number in each table entry is the number of "points" that each |       # The number in each table entry is the number of "points" that each | ||||||
| @@ -145,18 +145,22 @@ module Linguist | |||||||
|       # how much more likely (log of probability ratio) that token is to |       # how much more likely (log of probability ratio) that token is to | ||||||
|       # appear in one language vs. the least-likely language.  Dashes |       # appear in one language vs. the least-likely language.  Dashes | ||||||
|       # indicate the least-likely language (and zero points) for each token. |       # indicate the least-likely language (and zero points) for each token. | ||||||
|       def dump_all_tokens(tokens, languages) |       def debug_dump_all_tokens(tokens, languages) | ||||||
|         maxlen = tokens.map { |tok| tok.size }.max |         maxlen = tokens.map { |tok| tok.size }.max | ||||||
|  |  | ||||||
|         printf "%#{maxlen}s", "" |         printf "%#{maxlen}s", "" | ||||||
|         puts "    #" + languages.map { |lang| sprintf("%10s", lang) }.join |         puts "    #" + languages.map { |lang| sprintf("%10s", lang) }.join | ||||||
|         tokmap = Hash.new(0) |  | ||||||
|         tokens.each { |tok| tokmap[tok] += 1 } |         token_map = Hash.new(0) | ||||||
|         tokmap.sort.each { |tok, count| |         tokens.each { |tok| token_map[tok] += 1 } | ||||||
|  |  | ||||||
|  |         token_map.sort.each { |tok, count| | ||||||
|           arr = languages.map { |lang| [lang, token_probability(tok, lang)] } |           arr = languages.map { |lang| [lang, token_probability(tok, lang)] } | ||||||
|           min = arr.map { |a,b| b }.min |           min = arr.map { |a,b| b }.min | ||||||
|           minlog = Math.log(min) |           minlog = Math.log(min) | ||||||
|           if !arr.inject(true) { |result, n| result && n[1] == arr[0][1] } |           if !arr.inject(true) { |result, n| result && n[1] == arr[0][1] } | ||||||
|             printf "%#{maxlen}s%5d", tok, count |             printf "%#{maxlen}s%5d", tok, count | ||||||
|  |  | ||||||
|             puts arr.map { |ent| |             puts arr.map { |ent| | ||||||
|               ent[1] == min ? "         -" : sprintf("%10.3f", count * (Math.log(ent[1]) - minlog)) |               ent[1] == min ? "         -" : sprintf("%10.3f", count * (Math.log(ent[1]) - minlog)) | ||||||
|             }.join |             }.join | ||||||
|   | |||||||
| @@ -52,12 +52,17 @@ module Linguist | |||||||
|     # Return true or false |     # Return true or false | ||||||
|     def generated? |     def generated? | ||||||
|       name == 'Gemfile.lock' || |       name == 'Gemfile.lock' || | ||||||
|         minified_javascript? || |         minified_files? || | ||||||
|         compiled_coffeescript? || |         compiled_coffeescript? || | ||||||
|         xcode_project_file? || |         xcode_project_file? || | ||||||
|         generated_net_docfile? || |  | ||||||
|         generated_parser? || |         generated_parser? || | ||||||
|         generated_protocol_buffer? |         generated_net_docfile? || | ||||||
|  |         generated_net_designer_file? || | ||||||
|  |         generated_postscript? || | ||||||
|  |         generated_protocol_buffer? || | ||||||
|  |         generated_jni_header? || | ||||||
|  |         composer_lock? || | ||||||
|  |         node_modules? | ||||||
|     end |     end | ||||||
|  |  | ||||||
|     # Internal: Is the blob an XCode project file? |     # Internal: Is the blob an XCode project file? | ||||||
| @@ -70,16 +75,18 @@ module Linguist | |||||||
|       ['.xib', '.nib', '.storyboard', '.pbxproj', '.xcworkspacedata', '.xcuserstate'].include?(extname) |       ['.xib', '.nib', '.storyboard', '.pbxproj', '.xcworkspacedata', '.xcuserstate'].include?(extname) | ||||||
|     end |     end | ||||||
|  |  | ||||||
|     # Internal: Is the blob minified JS? |     # Internal: Is the blob minified files? | ||||||
|     # |     # | ||||||
|     # Consider JS minified if the average line length is |     # Consider a file minified if the average line length is | ||||||
|     # greater then 100c. |     # greater then 110c. | ||||||
|  |     # | ||||||
|  |     # Currently, only JS and CSS files are detected by this method. | ||||||
|     # |     # | ||||||
|     # Returns true or false. |     # Returns true or false. | ||||||
|     def minified_javascript? |     def minified_files? | ||||||
|       return unless extname == '.js' |       return unless ['.js', '.css'].include? extname | ||||||
|       if lines.any? |       if lines.any? | ||||||
|         (lines.inject(0) { |n, l| n += l.length } / lines.length) > 100 |         (lines.inject(0) { |n, l| n += l.length } / lines.length) > 110 | ||||||
|       else |       else | ||||||
|         false |         false | ||||||
|       end |       end | ||||||
| @@ -143,6 +150,16 @@ module Linguist | |||||||
|         lines[-2].include?("</doc>") |         lines[-2].include?("</doc>") | ||||||
|     end |     end | ||||||
|  |  | ||||||
|  |     # Internal: Is this a codegen file for a .NET project? | ||||||
|  |     # | ||||||
|  |     # Visual Studio often uses code generation to generate partial classes, and | ||||||
|  |     # these files can be quite unwieldy. Let's hide them. | ||||||
|  |     # | ||||||
|  |     # Returns true or false | ||||||
|  |     def generated_net_designer_file? | ||||||
|  |       name.downcase =~ /\.designer\.cs$/ | ||||||
|  |     end | ||||||
|  |  | ||||||
|     # Internal: Is the blob of JS a parser generated by PEG.js? |     # Internal: Is the blob of JS a parser generated by PEG.js? | ||||||
|     # |     # | ||||||
|     # PEG.js-generated parsers are not meant to be consumed by humans. |     # PEG.js-generated parsers are not meant to be consumed by humans. | ||||||
| @@ -160,6 +177,29 @@ module Linguist | |||||||
|       false |       false | ||||||
|     end |     end | ||||||
|  |  | ||||||
|  |     # Internal: Is the blob of PostScript generated? | ||||||
|  |     # | ||||||
|  |     # PostScript files are often generated by other programs. If they tell us so, | ||||||
|  |     # we can detect them. | ||||||
|  |     # | ||||||
|  |     # Returns true or false. | ||||||
|  |     def generated_postscript? | ||||||
|  |       return false unless ['.ps', '.eps'].include? extname | ||||||
|  |  | ||||||
|  |       # We analyze the "%%Creator:" comment, which contains the author/generator | ||||||
|  |       # of the file. If there is one, it should be in one of the first few lines. | ||||||
|  |       creator = lines[0..9].find {|line| line =~ /^%%Creator: /} | ||||||
|  |       return false if creator.nil? | ||||||
|  |  | ||||||
|  |       # Most generators write their version number, while human authors' or companies' | ||||||
|  |       # names don't contain numbers. So look if the line contains digits. Also | ||||||
|  |       # look for some special cases without version numbers. | ||||||
|  |       return creator =~ /[0-9]/ || | ||||||
|  |         creator.include?("mpage") || | ||||||
|  |         creator.include?("draw") || | ||||||
|  |         creator.include?("ImageMagick") | ||||||
|  |     end | ||||||
|  |  | ||||||
|     # Internal: Is the blob a C++, Java or Python source file generated by the |     # Internal: Is the blob a C++, Java or Python source file generated by the | ||||||
|     # Protocol Buffer compiler? |     # Protocol Buffer compiler? | ||||||
|     # |     # | ||||||
| @@ -170,5 +210,30 @@ module Linguist | |||||||
|  |  | ||||||
|       return lines[0].include?("Generated by the protocol buffer compiler.  DO NOT EDIT!") |       return lines[0].include?("Generated by the protocol buffer compiler.  DO NOT EDIT!") | ||||||
|     end |     end | ||||||
|  |  | ||||||
|  |     # Internal: Is the blob a C/C++ header generated by the Java JNI tool javah? | ||||||
|  |     # | ||||||
|  |     # Returns true of false. | ||||||
|  |     def generated_jni_header? | ||||||
|  |       return false unless extname == '.h' | ||||||
|  |       return false unless lines.count > 2 | ||||||
|  |  | ||||||
|  |       return lines[0].include?("/* DO NOT EDIT THIS FILE - it is machine generated */") && | ||||||
|  |                lines[1].include?("#include <jni.h>") | ||||||
|  |     end | ||||||
|  |  | ||||||
|  |     # Internal: Is the blob part of node_modules/, which are not meant for humans in pull requests. | ||||||
|  |     # | ||||||
|  |     # Returns true or false. | ||||||
|  |     def node_modules? | ||||||
|  |       !!name.match(/node_modules\//) | ||||||
|  |     end | ||||||
|  |  | ||||||
|  |     # Internal: Is the blob a generated php composer lock file? | ||||||
|  |     # | ||||||
|  |     # Returns true or false. | ||||||
|  |     def composer_lock? | ||||||
|  |       !!name.match(/composer.lock/) | ||||||
|  |     end | ||||||
|   end |   end | ||||||
| end | end | ||||||
|   | |||||||
							
								
								
									
										60
									
								
								lib/linguist/heuristics.rb
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										60
									
								
								lib/linguist/heuristics.rb
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,60 @@ | |||||||
|  | module Linguist | ||||||
|  |   # A collection of simple heuristics that can be used to better analyze languages. | ||||||
|  |   class Heuristics | ||||||
|  |     ACTIVE = false | ||||||
|  |  | ||||||
|  |     # Public: Given an array of String language names, | ||||||
|  |     # apply heuristics against the given data and return an array | ||||||
|  |     # of matching languages, or nil. | ||||||
|  |     # | ||||||
|  |     # data      - Array of tokens or String data to analyze. | ||||||
|  |     # languages - Array of language name Strings to restrict to. | ||||||
|  |     # | ||||||
|  |     # Returns an array of Languages or [] | ||||||
|  |     def self.find_by_heuristics(data, languages) | ||||||
|  |       if active? | ||||||
|  |         if languages.all? { |l| ["Objective-C", "C++"].include?(l) } | ||||||
|  |           disambiguate_c(data, languages) | ||||||
|  |         end | ||||||
|  |         if languages.all? { |l| ["Perl", "Prolog"].include?(l) } | ||||||
|  |           disambiguate_pl(data, languages) | ||||||
|  |         end | ||||||
|  |         if languages.all? { |l| ["TypeScript", "XML"].include?(l) } | ||||||
|  |           disambiguate_ts(data, languages) | ||||||
|  |         end | ||||||
|  |       end | ||||||
|  |     end | ||||||
|  |  | ||||||
|  |     # .h extensions are ambigious 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, languages) | ||||||
|  |       matches = [] | ||||||
|  |       matches << Language["Objective-C"] if data.include?("@interface") | ||||||
|  |       matches << Language["C++"] if data.include?("#include <cstdint>") | ||||||
|  |       matches | ||||||
|  |     end | ||||||
|  |  | ||||||
|  |     def self.disambiguate_pl(data, languages) | ||||||
|  |       matches = [] | ||||||
|  |       matches << Language["Prolog"] if data.include?(":-") | ||||||
|  |       matches << Language["Perl"] if data.include?("use strict") | ||||||
|  |       matches | ||||||
|  |     end | ||||||
|  |  | ||||||
|  |     def self.disambiguate_ts(data, languages) | ||||||
|  |       matches = [] | ||||||
|  |       if (data.include?("</translation>")) | ||||||
|  |         matches << Language["XML"] | ||||||
|  |       else | ||||||
|  |         matches << Language["TypeScript"] | ||||||
|  |       end | ||||||
|  |       matches | ||||||
|  |     end | ||||||
|  |  | ||||||
|  |     def self.active? | ||||||
|  |       !!ACTIVE | ||||||
|  |     end | ||||||
|  |   end | ||||||
|  | end | ||||||
| @@ -1,8 +1,13 @@ | |||||||
| require 'escape_utils' | require 'escape_utils' | ||||||
| require 'pygments' | require 'pygments' | ||||||
| require 'yaml' | require 'yaml' | ||||||
|  | begin | ||||||
|  |   require 'json' | ||||||
|  | rescue LoadError | ||||||
|  | end | ||||||
|  |  | ||||||
| require 'linguist/classifier' | require 'linguist/classifier' | ||||||
|  | require 'linguist/heuristics' | ||||||
| require 'linguist/samples' | require 'linguist/samples' | ||||||
|  |  | ||||||
| module Linguist | module Linguist | ||||||
| @@ -15,11 +20,30 @@ module Linguist | |||||||
|     @index           = {} |     @index           = {} | ||||||
|     @name_index      = {} |     @name_index      = {} | ||||||
|     @alias_index     = {} |     @alias_index     = {} | ||||||
|     @extension_index = Hash.new { |h,k| h[k] = [] } |  | ||||||
|     @filename_index  = Hash.new { |h,k| h[k] = [] } |     @extension_index          = Hash.new { |h,k| h[k] = [] } | ||||||
|  |     @interpreter_index        = Hash.new { |h,k| h[k] = [] } | ||||||
|  |     @filename_index           = Hash.new { |h,k| h[k] = [] } | ||||||
|  |     @primary_extension_index  = {} | ||||||
|  |  | ||||||
|     # Valid Languages types |     # Valid Languages types | ||||||
|     TYPES = [:data, :markup, :programming] |     TYPES = [:data, :markup, :programming, :prose] | ||||||
|  |  | ||||||
|  |     # Names of non-programming languages that we will still detect | ||||||
|  |     # | ||||||
|  |     # Returns an array | ||||||
|  |     def self.detectable_markup | ||||||
|  |       ["CSS", "Less", "Sass", "SCSS", "Stylus", "TeX"] | ||||||
|  |     end | ||||||
|  |  | ||||||
|  |     # Detect languages by a specific type | ||||||
|  |     # | ||||||
|  |     # type - A symbol that exists within TYPES | ||||||
|  |     # | ||||||
|  |     # Returns an array | ||||||
|  |     def self.by_type(type) | ||||||
|  |       all.select { |h| h.type == type } | ||||||
|  |     end | ||||||
|  |  | ||||||
|     # Internal: Create a new Language object |     # Internal: Create a new Language object | ||||||
|     # |     # | ||||||
| @@ -56,6 +80,16 @@ module Linguist | |||||||
|         @extension_index[extension] << language |         @extension_index[extension] << language | ||||||
|       end |       end | ||||||
|  |  | ||||||
|  |       if @primary_extension_index.key?(language.primary_extension) | ||||||
|  |         raise ArgumentError, "Duplicate primary extension: #{language.primary_extension}" | ||||||
|  |       end | ||||||
|  |  | ||||||
|  |       @primary_extension_index[language.primary_extension] = language | ||||||
|  |  | ||||||
|  |       language.interpreters.each do |interpreter| | ||||||
|  |         @interpreter_index[interpreter] << language | ||||||
|  |       end | ||||||
|  |  | ||||||
|       language.filenames.each do |filename| |       language.filenames.each do |filename| | ||||||
|         @filename_index[filename] << language |         @filename_index[filename] << language | ||||||
|       end |       end | ||||||
| @@ -80,16 +114,32 @@ module Linguist | |||||||
|         name += ".script!" |         name += ".script!" | ||||||
|       end |       end | ||||||
|  |  | ||||||
|  |       # First try to find languages that match based on filename. | ||||||
|       possible_languages = find_by_filename(name) |       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 |       if possible_languages.length > 1 | ||||||
|         data = data.call() if data.respond_to?(:call) |         data = data.call() if data.respond_to?(:call) | ||||||
|  |         possible_language_names = possible_languages.map(&:name) | ||||||
|  |  | ||||||
|  |         # Don't bother with emptiness | ||||||
|         if data.nil? || data == "" |         if data.nil? || data == "" | ||||||
|           nil |           nil | ||||||
|         elsif result = Classifier.classify(Samples::DATA, data, possible_languages.map(&:name)).first |         # Check if there's a shebang line and use that as authoritative | ||||||
|           Language[result[0]] |         elsif (result = find_by_shebang(data)) && !result.empty? | ||||||
|  |           result.first | ||||||
|  |         # No shebang. Still more work to do. Try to find it with our heuristics. | ||||||
|  |         elsif (determined = Heuristics.find_by_heuristics(data, possible_language_names)) && !determined.empty? | ||||||
|  |           determined.first | ||||||
|  |         # Lastly, fall back to the probablistic classifier. | ||||||
|  |         elsif classified = Classifier.classify(Samples::DATA, 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 |         end | ||||||
|       else |       else | ||||||
|  |         # Simplest and most common case, we can just return the one match based on extension | ||||||
|         possible_languages.first |         possible_languages.first | ||||||
|       end |       end | ||||||
|     end |     end | ||||||
| @@ -141,7 +191,24 @@ module Linguist | |||||||
|     # Returns all matching Languages or [] if none were found. |     # Returns all matching Languages or [] if none were found. | ||||||
|     def self.find_by_filename(filename) |     def self.find_by_filename(filename) | ||||||
|       basename, extname = File.basename(filename), File.extname(filename) |       basename, extname = File.basename(filename), File.extname(filename) | ||||||
|       @filename_index[basename] + @extension_index[extname] |       langs = [@primary_extension_index[extname]] + | ||||||
|  |               @filename_index[basename] + | ||||||
|  |               @extension_index[extname] | ||||||
|  |       langs.compact.uniq | ||||||
|  |     end | ||||||
|  |  | ||||||
|  |     # Public: Look up Languages by shebang line. | ||||||
|  |     # | ||||||
|  |     # data - Array of tokens or String data to analyze. | ||||||
|  |     # | ||||||
|  |     # Examples | ||||||
|  |     # | ||||||
|  |     #   Language.find_by_shebang("#!/bin/bash\ndate;") | ||||||
|  |     #   # => [#<Language name="Bash">] | ||||||
|  |     # | ||||||
|  |     # Returns the matching Language | ||||||
|  |     def self.find_by_shebang(data) | ||||||
|  |       @interpreter_index[Linguist.interpreter_from_shebang(data)] | ||||||
|     end |     end | ||||||
|  |  | ||||||
|     # Public: Look up Language by its name or lexer. |     # Public: Look up Language by its name or lexer. | ||||||
| @@ -229,6 +296,7 @@ module Linguist | |||||||
|  |  | ||||||
|       # Set extensions or default to []. |       # Set extensions or default to []. | ||||||
|       @extensions = attributes[:extensions] || [] |       @extensions = attributes[:extensions] || [] | ||||||
|  |       @interpreters = attributes[:interpreters]   || [] | ||||||
|       @filenames  = attributes[:filenames]  || [] |       @filenames  = attributes[:filenames]  || [] | ||||||
|  |  | ||||||
|       unless @primary_extension = attributes[:primary_extension] |       unless @primary_extension = attributes[:primary_extension] | ||||||
| @@ -341,6 +409,15 @@ module Linguist | |||||||
|     # Returns the extension String. |     # Returns the extension String. | ||||||
|     attr_reader :primary_extension |     attr_reader :primary_extension | ||||||
|  |  | ||||||
|  |     # Public: Get interpreters | ||||||
|  |     # | ||||||
|  |     # Examples | ||||||
|  |     # | ||||||
|  |     #   # => ['awk', 'gawk', 'mawk' ...] | ||||||
|  |     # | ||||||
|  |     # Returns the interpreters Array | ||||||
|  |     attr_reader :interpreters | ||||||
|  |  | ||||||
|     # Public: Get filenames |     # Public: Get filenames | ||||||
|     # |     # | ||||||
|     # Examples |     # Examples | ||||||
| @@ -434,19 +511,40 @@ module Linguist | |||||||
|   end |   end | ||||||
|  |  | ||||||
|   extensions = Samples::DATA['extnames'] |   extensions = Samples::DATA['extnames'] | ||||||
|  |   interpreters = Samples::DATA['interpreters'] | ||||||
|   filenames = Samples::DATA['filenames'] |   filenames = Samples::DATA['filenames'] | ||||||
|   popular = YAML.load_file(File.expand_path("../popular.yml", __FILE__)) |   popular = YAML.load_file(File.expand_path("../popular.yml", __FILE__)) | ||||||
|  |  | ||||||
|   YAML.load_file(File.expand_path("../languages.yml", __FILE__)).each do |name, options| |   languages_yml = File.expand_path("../languages.yml", __FILE__) | ||||||
|  |   languages_json = File.expand_path("../languages.json", __FILE__) | ||||||
|  |  | ||||||
|  |   if File.exist?(languages_json) && defined?(JSON) | ||||||
|  |     languages = JSON.load(File.read(languages_json)) | ||||||
|  |   else | ||||||
|  |     languages = YAML.load_file(languages_yml) | ||||||
|  |   end | ||||||
|  |  | ||||||
|  |   languages.each do |name, options| | ||||||
|     options['extensions'] ||= [] |     options['extensions'] ||= [] | ||||||
|  |     options['interpreters'] ||= [] | ||||||
|     options['filenames'] ||= [] |     options['filenames'] ||= [] | ||||||
|  |  | ||||||
|     if extnames = extensions[name] |     if extnames = extensions[name] | ||||||
|       extnames.each do |extname| |       extnames.each do |extname| | ||||||
|         if !options['extensions'].include?(extname) |         if !options['extensions'].include?(extname) | ||||||
|           options['extensions'] << extname |           options['extensions'] << extname | ||||||
|         else |         end | ||||||
|           warn "#{name} #{extname.inspect} is already defined in samples/. Remove from languages.yml." |       end | ||||||
|  |     end | ||||||
|  |  | ||||||
|  |     if interpreters == nil | ||||||
|  |       interpreters = {} | ||||||
|  |     end | ||||||
|  |  | ||||||
|  |     if interpreter_names = interpreters[name] | ||||||
|  |       interpreter_names.each do |interpreter| | ||||||
|  |         if !options['interpreters'].include?(interpreter) | ||||||
|  |           options['interpreters'] << interpreter | ||||||
|         end |         end | ||||||
|       end |       end | ||||||
|     end |     end | ||||||
| @@ -455,8 +553,6 @@ module Linguist | |||||||
|       fns.each do |filename| |       fns.each do |filename| | ||||||
|         if !options['filenames'].include?(filename) |         if !options['filenames'].include?(filename) | ||||||
|           options['filenames'] << filename |           options['filenames'] << filename | ||||||
|         else |  | ||||||
|           warn "#{name} #{filename.inspect} is already defined in samples/. Remove from languages.yml." |  | ||||||
|         end |         end | ||||||
|       end |       end | ||||||
|     end |     end | ||||||
| @@ -473,6 +569,7 @@ module Linguist | |||||||
|       :searchable        => options.key?('searchable') ? options['searchable'] : true, |       :searchable        => options.key?('searchable') ? options['searchable'] : true, | ||||||
|       :search_term       => options['search_term'], |       :search_term       => options['search_term'], | ||||||
|       :extensions        => options['extensions'].sort, |       :extensions        => options['extensions'].sort, | ||||||
|  |       :interpreters      => options['interpreters'].sort, | ||||||
|       :primary_extension => options['primary_extension'], |       :primary_extension => options['primary_extension'], | ||||||
|       :filenames         => options['filenames'], |       :filenames         => options['filenames'], | ||||||
|       :popular           => popular.include?(name) |       :popular           => popular.include?(name) | ||||||
|   | |||||||
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							| @@ -29,6 +29,7 @@ module Linguist | |||||||
|       @computed_stats = false |       @computed_stats = false | ||||||
|       @language = @size = nil |       @language = @size = nil | ||||||
|       @sizes = Hash.new { 0 } |       @sizes = Hash.new { 0 } | ||||||
|  |       @file_breakdown = Hash.new { |h,k| h[k] = Array.new } | ||||||
|     end |     end | ||||||
|  |  | ||||||
|     # Public: Returns a breakdown of language stats. |     # Public: Returns a breakdown of language stats. | ||||||
| @@ -60,6 +61,12 @@ module Linguist | |||||||
|       @size |       @size | ||||||
|     end |     end | ||||||
|  |  | ||||||
|  |     # Public: Return the language breakdown of this repository by file | ||||||
|  |     def breakdown_by_file | ||||||
|  |       compute_stats | ||||||
|  |       @file_breakdown | ||||||
|  |     end | ||||||
|  |  | ||||||
|     # Internal: Compute language breakdown for each blob in the Repository. |     # Internal: Compute language breakdown for each blob in the Repository. | ||||||
|     # |     # | ||||||
|     # Returns nothing |     # Returns nothing | ||||||
| @@ -73,8 +80,12 @@ module Linguist | |||||||
|         # Skip vendored or generated blobs |         # Skip vendored or generated blobs | ||||||
|         next if blob.vendored? || blob.generated? || blob.language.nil? |         next if blob.vendored? || blob.generated? || blob.language.nil? | ||||||
|  |  | ||||||
|         # Only include programming languages |         # Only include programming languages and acceptable markup languages | ||||||
|         if blob.language.type == :programming |         if blob.language.type == :programming || Language.detectable_markup.include?(blob.language.name) | ||||||
|  |  | ||||||
|  |           # Build up the per-file breakdown stats | ||||||
|  |           @file_breakdown[blob.language.group.name] << blob.name | ||||||
|  |  | ||||||
|           @sizes[blob.language.group] += blob.size |           @sizes[blob.language.group] += blob.size | ||||||
|         end |         end | ||||||
|       end |       end | ||||||
|   | |||||||
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							| @@ -1,4 +1,8 @@ | |||||||
| require 'yaml' | begin | ||||||
|  |   require 'json' | ||||||
|  | rescue LoadError | ||||||
|  |   require 'yaml' | ||||||
|  | end | ||||||
|  |  | ||||||
| require 'linguist/md5' | require 'linguist/md5' | ||||||
| require 'linguist/classifier' | require 'linguist/classifier' | ||||||
| @@ -14,7 +18,8 @@ module Linguist | |||||||
|  |  | ||||||
|     # Hash of serialized samples object |     # Hash of serialized samples object | ||||||
|     if File.exist?(PATH) |     if File.exist?(PATH) | ||||||
|       DATA = YAML.load_file(PATH) |       serializer = defined?(JSON) ? JSON : YAML | ||||||
|  |       DATA = serializer.load(File.read(PATH)) | ||||||
|     end |     end | ||||||
|  |  | ||||||
|     # Public: Iterate over each sample. |     # Public: Iterate over each sample. | ||||||
| @@ -52,6 +57,7 @@ module Linguist | |||||||
|             yield({ |             yield({ | ||||||
|               :path     => File.join(dirname, filename), |               :path     => File.join(dirname, filename), | ||||||
|               :language => category, |               :language => category, | ||||||
|  |               :interpreter => File.exist?(filename) ? Linguist.interpreter_from_shebang(File.read(filename)) : nil, | ||||||
|               :extname  => File.extname(filename) |               :extname  => File.extname(filename) | ||||||
|             }) |             }) | ||||||
|           end |           end | ||||||
| @@ -67,6 +73,7 @@ module Linguist | |||||||
|     def self.data |     def self.data | ||||||
|       db = {} |       db = {} | ||||||
|       db['extnames'] = {} |       db['extnames'] = {} | ||||||
|  |       db['interpreters'] = {} | ||||||
|       db['filenames'] = {} |       db['filenames'] = {} | ||||||
|  |  | ||||||
|       each do |sample| |       each do |sample| | ||||||
| @@ -80,6 +87,14 @@ module Linguist | |||||||
|           end |           end | ||||||
|         end |         end | ||||||
|  |  | ||||||
|  |         if sample[:interpreter] | ||||||
|  |           db['interpreters'][language_name] ||= [] | ||||||
|  |           if !db['interpreters'][language_name].include?(sample[:interpreter]) | ||||||
|  |             db['interpreters'][language_name] << sample[:interpreter] | ||||||
|  |             db['interpreters'][language_name].sort! | ||||||
|  |           end | ||||||
|  |         end | ||||||
|  |  | ||||||
|         if sample[:filename] |         if sample[:filename] | ||||||
|           db['filenames'][language_name] ||= [] |           db['filenames'][language_name] ||= [] | ||||||
|           db['filenames'][language_name] << sample[:filename] |           db['filenames'][language_name] << sample[:filename] | ||||||
| @@ -95,4 +110,40 @@ module Linguist | |||||||
|       db |       db | ||||||
|     end |     end | ||||||
|   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 | end | ||||||
|   | |||||||
| @@ -12,6 +12,9 @@ | |||||||
| # Caches | # Caches | ||||||
| - cache/ | - cache/ | ||||||
|  |  | ||||||
|  | # Dependencies | ||||||
|  | - ^[Dd]ependencies/ | ||||||
|  |  | ||||||
| # C deps | # C deps | ||||||
| #  https://github.com/joyent/node | #  https://github.com/joyent/node | ||||||
| - ^deps/ | - ^deps/ | ||||||
| @@ -24,8 +27,22 @@ | |||||||
| # Node dependencies | # Node dependencies | ||||||
| - node_modules/ | - node_modules/ | ||||||
|  |  | ||||||
|  | # Bower Components | ||||||
|  | - bower_components/ | ||||||
|  |  | ||||||
|  | # Erlang bundles | ||||||
|  | - ^rebar$ | ||||||
|  |  | ||||||
|  | # Bootstrap minified css and js | ||||||
|  | - (^|/)bootstrap([^.]*)(\.min)?\.(js|css)$ | ||||||
|  |  | ||||||
|  | # Foundation css | ||||||
|  | - foundation.min.css | ||||||
|  | - foundation.css | ||||||
|  |  | ||||||
| # Vendored dependencies | # Vendored dependencies | ||||||
| - vendor/ | - thirdparty/ | ||||||
|  | - vendors?/ | ||||||
|  |  | ||||||
| # Debian packaging | # Debian packaging | ||||||
| - ^debian/ | - ^debian/ | ||||||
| @@ -34,7 +51,11 @@ | |||||||
|  |  | ||||||
| # jQuery | # jQuery | ||||||
| - (^|/)jquery([^.]*)(\.min)?\.js$ | - (^|/)jquery([^.]*)(\.min)?\.js$ | ||||||
| - (^|/)jquery\-\d\.\d(\.\d)?(\.min)?\.js$ | - (^|/)jquery\-\d\.\d+(\.\d+)?(\.min)?\.js$ | ||||||
|  |  | ||||||
|  | # jQuery UI | ||||||
|  | - (^|/)jquery\-ui(\-\d\.\d+(\.\d+)?)?(\.\w+)?(\.min)?\.(js|css)$ | ||||||
|  | - (^|/)jquery\.(ui|effects)\.([^.]*)(\.min)?\.(js|css)$ | ||||||
|  |  | ||||||
| # Prototype | # Prototype | ||||||
| - (^|/)prototype(.*)\.js$ | - (^|/)prototype(.*)\.js$ | ||||||
| @@ -55,10 +76,6 @@ | |||||||
| - (^|/)yahoo-([^.]*)\.js$ | - (^|/)yahoo-([^.]*)\.js$ | ||||||
| - (^|/)yui([^.]*)\.js$ | - (^|/)yui([^.]*)\.js$ | ||||||
|  |  | ||||||
| # LESS css |  | ||||||
| - (^|/)less([^.]*)(\.min)?\.js$ |  | ||||||
| - (^|/)less\-\d+\.\d+\.\d+(\.min)?\.js$ |  | ||||||
|  |  | ||||||
| # WYS editors | # WYS editors | ||||||
| - (^|/)ckeditor\.js$ | - (^|/)ckeditor\.js$ | ||||||
| - (^|/)tiny_mce([^.]*)\.js$ | - (^|/)tiny_mce([^.]*)\.js$ | ||||||
| @@ -72,6 +89,9 @@ | |||||||
| - (^|/)shCore\.js$ | - (^|/)shCore\.js$ | ||||||
| - (^|/)shLegacy\.js$ | - (^|/)shLegacy\.js$ | ||||||
|  |  | ||||||
|  | # AngularJS | ||||||
|  | - (^|/)angular([^.]*)(\.min)?\.js$ | ||||||
|  |  | ||||||
| ## Python ## | ## Python ## | ||||||
|  |  | ||||||
| # django | # django | ||||||
| @@ -83,6 +103,8 @@ | |||||||
| # WAF | # WAF | ||||||
| - ^waf$ | - ^waf$ | ||||||
|  |  | ||||||
|  | # .osx | ||||||
|  | - ^.osx$ | ||||||
|  |  | ||||||
| ## Obj-C ## | ## Obj-C ## | ||||||
|  |  | ||||||
| @@ -95,7 +117,8 @@ | |||||||
| - -vsdoc\.js$ | - -vsdoc\.js$ | ||||||
|  |  | ||||||
| # jQuery validation plugin (MS bundles this with asp.net mvc) | # jQuery validation plugin (MS bundles this with asp.net mvc) | ||||||
| - (^|/)jquery([^.]*)\.validate(\.min)?\.js$ | - (^|/)jquery([^.]*)\.validate(\.unobtrusive)?(\.min)?\.js$ | ||||||
|  | - (^|/)jquery([^.]*)\.unobtrusive\-ajax(\.min)?\.js$ | ||||||
|  |  | ||||||
| # Microsoft Ajax | # Microsoft Ajax | ||||||
| - (^|/)[Mm]icrosoft([Mm]vc)?([Aa]jax|[Vv]alidation)(\.debug)?\.js$ | - (^|/)[Mm]icrosoft([Mm]vc)?([Aa]jax|[Vv]alidation)(\.debug)?\.js$ | ||||||
| @@ -104,10 +127,45 @@ | |||||||
| - ^[Pp]ackages/ | - ^[Pp]ackages/ | ||||||
|  |  | ||||||
| # ExtJS | # ExtJS | ||||||
| - (^|/)extjs/ | - (^|/)extjs/.*?\.js$ | ||||||
|  | - (^|/)extjs/.*?\.xml$ | ||||||
|  | - (^|/)extjs/.*?\.txt$ | ||||||
|  | - (^|/)extjs/.*?\.html$ | ||||||
|  | - (^|/)extjs/.*?\.properties$ | ||||||
|  | - (^|/)extjs/.sencha/ | ||||||
|  | - (^|/)extjs/docs/ | ||||||
|  | - (^|/)extjs/builds/ | ||||||
|  | - (^|/)extjs/cmd/ | ||||||
|  | - (^|/)extjs/examples/ | ||||||
|  | - (^|/)extjs/locale/ | ||||||
|  | - (^|/)extjs/packages/ | ||||||
|  | - (^|/)extjs/plugins/ | ||||||
|  | - (^|/)extjs/resources/ | ||||||
|  | - (^|/)extjs/src/ | ||||||
|  | - (^|/)extjs/welcome/ | ||||||
|  |  | ||||||
| # Samples folders | # Samples folders | ||||||
| - ^[Ss]amples/ | - ^[Ss]amples/ | ||||||
|  |  | ||||||
|  | # LICENSE, README, git config files | ||||||
|  | - ^COPYING$ | ||||||
|  | - LICENSE$ | ||||||
|  | - License$ | ||||||
|  | - gitattributes$ | ||||||
|  | - gitignore$ | ||||||
|  | - gitmodules$ | ||||||
|  | - ^README$ | ||||||
|  | - ^readme$ | ||||||
|  |  | ||||||
| # Test fixtures | # Test fixtures | ||||||
| - ^[Tt]est/fixtures/ | - ^[Tt]est/fixtures/ | ||||||
|  |  | ||||||
|  | # PhoneGap/Cordova | ||||||
|  | - (^|/)cordova([^.]*)(\.min)?\.js$ | ||||||
|  | - (^|/)cordova\-\d\.\d(\.\d)?(\.min)?\.js$ | ||||||
|  |  | ||||||
|  | # Vagrant | ||||||
|  | - ^Vagrantfile$ | ||||||
|  |  | ||||||
|  | # .DS_Store's | ||||||
|  | - .[Dd][Ss]_[Ss]tore$ | ||||||
|   | |||||||
							
								
								
									
										39
									
								
								samples/Agda/NatCat.agda
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										39
									
								
								samples/Agda/NatCat.agda
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,39 @@ | |||||||
|  | module NatCat where | ||||||
|  |  | ||||||
|  | open import Relation.Binary.PropositionalEquality | ||||||
|  |  | ||||||
|  | -- If you can show that a relation only ever has one inhabitant | ||||||
|  | -- you get the category laws for free | ||||||
|  | module | ||||||
|  |   EasyCategory | ||||||
|  |   (obj : Set) | ||||||
|  |   (_⟶_ : obj → obj → Set) | ||||||
|  |   (_∘_ : ∀ {x y z} → x ⟶ y → y ⟶ z → x ⟶ z) | ||||||
|  |   (id : ∀ x → x ⟶ x) | ||||||
|  |   (single-inhabitant : (x y : obj) (r s : x ⟶ y) → r ≡ s) | ||||||
|  |   where | ||||||
|  |  | ||||||
|  |   idʳ : ∀ x y (r : x ⟶ y) → r ∘ id y ≡ r | ||||||
|  |   idʳ x y r = single-inhabitant x y (r ∘ id y) r  | ||||||
|  |  | ||||||
|  |   idˡ : ∀ x y (r : x ⟶ y) → id x ∘ r ≡ r | ||||||
|  |   idˡ x y r = single-inhabitant x y (id x ∘ r) r | ||||||
|  |  | ||||||
|  |   ∘-assoc : ∀ w x y z (r : w ⟶ x) (s : x ⟶ y) (t : y ⟶ z) → (r ∘ s) ∘ t ≡ r ∘ (s ∘ t) | ||||||
|  |   ∘-assoc w x y z r s t = single-inhabitant w z ((r ∘ s) ∘ t) (r ∘ (s ∘ t)) | ||||||
|  |  | ||||||
|  | open import Data.Nat | ||||||
|  |  | ||||||
|  | same : (x y : ℕ) (r s : x ≤ y) → r ≡ s | ||||||
|  | same .0 y z≤n z≤n = refl | ||||||
|  | same .(suc m) .(suc n) (s≤s {m} {n} r) (s≤s s) = cong s≤s (same m n r s) | ||||||
|  |  | ||||||
|  | ≤-trans : ∀ x y z → x ≤ y → y ≤ z → x ≤ z | ||||||
|  | ≤-trans .0 y z z≤n s = z≤n | ||||||
|  | ≤-trans .(suc m) .(suc n) .(suc n₁) (s≤s {m} {n} r) (s≤s {.n} {n₁} s) = s≤s (≤-trans m n n₁ r s) | ||||||
|  |  | ||||||
|  | ≤-refl : ∀ x → x ≤ x | ||||||
|  | ≤-refl zero = z≤n | ||||||
|  | ≤-refl (suc x) = s≤s (≤-refl x) | ||||||
|  |  | ||||||
|  | module Nat-EasyCategory = EasyCategory ℕ _≤_ (λ {x}{y}{z} → ≤-trans x y z) ≤-refl same | ||||||
							
								
								
									
										13
									
								
								samples/AsciiDoc/encoding.asciidoc
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										13
									
								
								samples/AsciiDoc/encoding.asciidoc
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,13 @@ | |||||||
|  | Gregory Romé has written an AsciiDoc plugin for the Redmine project management application. | ||||||
|  |  | ||||||
|  | https://github.com/foo-users/foo | ||||||
|  | へと `vicmd` キーマップを足してみている試み、 | ||||||
|  | アニメーションgifです。 | ||||||
|  |  | ||||||
|  | tag::romé[] | ||||||
|  | Gregory Romé has written an AsciiDoc plugin for the Redmine project management application. | ||||||
|  | end::romé[] | ||||||
|  |  | ||||||
|  | == Überschrift | ||||||
|  |  | ||||||
|  | * Codierungen sind verrückt auf älteren Versionen von Ruby | ||||||
							
								
								
									
										10
									
								
								samples/AsciiDoc/list.asc
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										10
									
								
								samples/AsciiDoc/list.asc
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,10 @@ | |||||||
|  | AsciiDoc Home Page | ||||||
|  | ================== | ||||||
|  |  | ||||||
|  | Example Articles | ||||||
|  | ~~~~~~~~~~~~~~~~ | ||||||
|  | - Item 1 | ||||||
|  |  | ||||||
|  | - Item 2 | ||||||
|  |  | ||||||
|  | - Item 3 | ||||||
							
								
								
									
										25
									
								
								samples/AsciiDoc/sample.adoc
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										25
									
								
								samples/AsciiDoc/sample.adoc
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,25 @@ | |||||||
|  | Document Title | ||||||
|  | ============== | ||||||
|  | Doc Writer <thedoc@asciidoctor.org> | ||||||
|  | :idprefix: id_ | ||||||
|  |  | ||||||
|  | Preamble paragraph. | ||||||
|  |  | ||||||
|  | NOTE: This is test, only a test. | ||||||
|  |  | ||||||
|  | == Section A | ||||||
|  |  | ||||||
|  | *Section A* paragraph. | ||||||
|  |  | ||||||
|  | === Section A Subsection | ||||||
|  |  | ||||||
|  | *Section A* 'subsection' paragraph. | ||||||
|  |  | ||||||
|  | == Section B | ||||||
|  |  | ||||||
|  | *Section B* paragraph. | ||||||
|  |  | ||||||
|  | .Section B list | ||||||
|  | * Item 1 | ||||||
|  | * Item 2 | ||||||
|  | * Item 3 | ||||||
							
								
								
									
										147
									
								
								samples/BlitzBasic/HalfAndDouble.bb
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										147
									
								
								samples/BlitzBasic/HalfAndDouble.bb
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,147 @@ | |||||||
|  |  | ||||||
|  | Local bk = CreateBank(8) | ||||||
|  | PokeFloat bk, 0, -1 | ||||||
|  | Print Bin(PeekInt(bk, 0)) | ||||||
|  | Print %1000000000000000 | ||||||
|  | Print Bin(1 Shl 31) | ||||||
|  | Print $1f | ||||||
|  | Print $ff | ||||||
|  | Print $1f + (127 - 15) | ||||||
|  | Print Hex(%01111111100000000000000000000000) | ||||||
|  | Print Hex(~%11111111100000000000000000000000) | ||||||
|  |  | ||||||
|  | Print Bin(FloatToHalf(-2.5)) | ||||||
|  | Print HalfToFloat(FloatToHalf(-200000000000.0)) | ||||||
|  |  | ||||||
|  | Print Bin(FToI(-2.5)) | ||||||
|  |  | ||||||
|  | WaitKey | ||||||
|  | End | ||||||
|  |  | ||||||
|  |  | ||||||
|  | ; Half-precision (16-bit) arithmetic library | ||||||
|  | ;============================================ | ||||||
|  |  | ||||||
|  | Global Half_CBank_ | ||||||
|  |  | ||||||
|  | Function FToI(f#) | ||||||
|  | 	If Half_CBank_ = 0 Then Half_CBank_ = CreateBank(4) | ||||||
|  | 	PokeFloat Half_CBank_, 0, f | ||||||
|  | 	Return PeekInt(Half_CBank_, 0) | ||||||
|  | End Function | ||||||
|  |  | ||||||
|  | Function HalfToFloat#(h) | ||||||
|  | 	Local signBit, exponent, fraction, fBits | ||||||
|  | 	 | ||||||
|  | 	signBit = (h And 32768) <> 0 | ||||||
|  | 	exponent = (h And %0111110000000000) Shr 10 | ||||||
|  | 	fraction = (h And %0000001111111111) | ||||||
|  | 	 | ||||||
|  | 	If exponent = $1F Then exponent = $FF : ElseIf exponent Then exponent = (exponent - 15) + 127 | ||||||
|  | 	fBits = (signBit Shl 31) Or (exponent Shl 23) Or (fraction Shl 13) | ||||||
|  | 	 | ||||||
|  | 	If Half_CBank_ = 0 Then Half_CBank_ = CreateBank(4) | ||||||
|  | 	PokeInt Half_CBank_, 0, fBits | ||||||
|  | 	Return PeekFloat(Half_CBank_, 0) | ||||||
|  | End Function | ||||||
|  |  | ||||||
|  | Function FloatToHalf(f#) | ||||||
|  | 	Local signBit, exponent, fraction, fBits | ||||||
|  | 	 | ||||||
|  | 	If Half_CBank_ = 0 Then Half_CBank_ = CreateBank(4) | ||||||
|  | 	PokeFloat Half_CBank_, 0, f | ||||||
|  | 	fBits = PeekInt(Half_CBank_, 0) | ||||||
|  | 	 | ||||||
|  | 	signBit = (fBits And (1 Shl 31)) <> 0 | ||||||
|  | 	exponent = (fBits And $7F800000) Shr 23 | ||||||
|  | 	fraction = fBits And $007FFFFF | ||||||
|  | 	 | ||||||
|  | 	If exponent | ||||||
|  | 		exponent = exponent - 127 | ||||||
|  | 		If Abs(exponent) > $1F | ||||||
|  | 			If exponent <> ($FF - 127) Then fraction = 0 | ||||||
|  | 			exponent = $1F * Sgn(exponent) | ||||||
|  | 		Else | ||||||
|  | 			exponent = exponent + 15 | ||||||
|  | 		EndIf | ||||||
|  | 		exponent = exponent And %11111 | ||||||
|  | 	EndIf | ||||||
|  | 	fraction = fraction Shr 13 | ||||||
|  | 	 | ||||||
|  | 	Return (signBit Shl 15) Or (exponent Shl 10) Or fraction | ||||||
|  | End Function | ||||||
|  |  | ||||||
|  | Function HalfAdd(l, r) | ||||||
|  | 	 | ||||||
|  | End Function | ||||||
|  |  | ||||||
|  | Function HalfSub(l, r) | ||||||
|  | 	 | ||||||
|  | End Function | ||||||
|  |  | ||||||
|  | Function HalfMul(l, r) | ||||||
|  | 	 | ||||||
|  | End Function | ||||||
|  |  | ||||||
|  | Function HalfDiv(l, r) | ||||||
|  | 	 | ||||||
|  | End Function | ||||||
|  |  | ||||||
|  | Function HalfLT(l, r) | ||||||
|  | 	 | ||||||
|  | End Function | ||||||
|  |  | ||||||
|  | Function HalfGT(l, r) | ||||||
|  | 	 | ||||||
|  | End Function | ||||||
|  |  | ||||||
|  |  | ||||||
|  | ; Double-precision (64-bit) arithmetic library) | ||||||
|  | ;=============================================== | ||||||
|  |  | ||||||
|  | Global DoubleOut[1], Double_CBank_ | ||||||
|  |  | ||||||
|  | Function DoubleToFloat#(d[1]) | ||||||
|  | 	 | ||||||
|  | End Function | ||||||
|  |  | ||||||
|  | Function FloatToDouble(f#) | ||||||
|  | 	 | ||||||
|  | End Function | ||||||
|  |  | ||||||
|  | Function IntToDouble(i) | ||||||
|  | 	 | ||||||
|  | End Function | ||||||
|  |  | ||||||
|  | Function SefToDouble(s, e, f) | ||||||
|  | 	 | ||||||
|  | End Function | ||||||
|  |  | ||||||
|  | Function DoubleAdd(l, r) | ||||||
|  | 	 | ||||||
|  | End Function | ||||||
|  |  | ||||||
|  | Function DoubleSub(l, r) | ||||||
|  | 	 | ||||||
|  | End Function | ||||||
|  |  | ||||||
|  | Function DoubleMul(l, r) | ||||||
|  | 	 | ||||||
|  | End Function | ||||||
|  |  | ||||||
|  | Function DoubleDiv(l, r) | ||||||
|  | 	 | ||||||
|  | End Function | ||||||
|  |  | ||||||
|  | Function DoubleLT(l, r) | ||||||
|  | 	 | ||||||
|  | End Function | ||||||
|  |  | ||||||
|  | Function DoubleGT(l, r) | ||||||
|  | 	 | ||||||
|  | End Function | ||||||
|  |  | ||||||
|  |  | ||||||
|  | ;~IDEal Editor Parameters: | ||||||
|  | ;~F#1A#20#2F | ||||||
|  | ;~C#Blitz3D | ||||||
							
								
								
									
										369
									
								
								samples/BlitzBasic/LList.bb
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										369
									
								
								samples/BlitzBasic/LList.bb
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,369 @@ | |||||||
|  |  | ||||||
|  | ; Double-linked list container class | ||||||
|  | ;==================================== | ||||||
|  |  | ||||||
|  | ; with thanks to MusicianKool, for concept and issue fixes | ||||||
|  |  | ||||||
|  |  | ||||||
|  | Type LList | ||||||
|  | 	Field head_.ListNode | ||||||
|  | 	Field tail_.ListNode | ||||||
|  | End Type | ||||||
|  |  | ||||||
|  | Type ListNode | ||||||
|  | 	Field pv_.ListNode | ||||||
|  | 	Field nx_.ListNode | ||||||
|  | 	Field Value | ||||||
|  | End Type | ||||||
|  |  | ||||||
|  | Type Iterator | ||||||
|  | 	Field Value | ||||||
|  | 	Field l_.LList | ||||||
|  | 	Field cn_.ListNode, cni_ | ||||||
|  | End Type | ||||||
|  |  | ||||||
|  |  | ||||||
|  | ;Create a new LList object | ||||||
|  | Function CreateList.LList() | ||||||
|  | 	Local l.LList = New LList | ||||||
|  | 	 | ||||||
|  | 	l\head_ = New ListNode | ||||||
|  | 	l\tail_ = New ListNode | ||||||
|  | 	 | ||||||
|  | 	l\head_\nx_ = l\tail_		;End caps | ||||||
|  | 	l\head_\pv_ = l\head_		;These make it more or less safe to iterate freely | ||||||
|  | 	l\head_\Value = 0 | ||||||
|  | 	 | ||||||
|  | 	l\tail_\nx_ = l\tail_ | ||||||
|  | 	l\tail_\pv_ = l\head_ | ||||||
|  | 	l\tail_\Value = 0 | ||||||
|  | 	 | ||||||
|  | 	Return l | ||||||
|  | End Function | ||||||
|  |  | ||||||
|  | ;Free a list and all elements (not any values) | ||||||
|  | Function FreeList(l.LList) | ||||||
|  | 	ClearList l | ||||||
|  | 	Delete l\head_ | ||||||
|  | 	Delete l\tail_ | ||||||
|  | 	Delete l | ||||||
|  | End Function | ||||||
|  |  | ||||||
|  | ;Remove all the elements from a list (does not free values) | ||||||
|  | Function ClearList(l.LList) | ||||||
|  | 	Local n.ListNode = l\head_\nx_ | ||||||
|  | 	While n <> l\tail_ | ||||||
|  | 		Local nx.ListNode = n\nx_ | ||||||
|  | 		Delete n | ||||||
|  | 		n = nx | ||||||
|  | 	Wend | ||||||
|  | 	l\head_\nx_ = l\tail_ | ||||||
|  | 	l\tail_\pv_ = l\head_ | ||||||
|  | End Function | ||||||
|  |  | ||||||
|  | ;Count the number of elements in a list (slow) | ||||||
|  | Function ListLength(l.LList) | ||||||
|  | 	Local i.Iterator = GetIterator(l), elems | ||||||
|  | 	While EachIn(i) | ||||||
|  | 		elems = elems + 1 | ||||||
|  | 	Wend | ||||||
|  | 	Return elems | ||||||
|  | End Function | ||||||
|  |  | ||||||
|  | ;Return True if a list contains a given value | ||||||
|  | Function ListContains(l.LList, Value) | ||||||
|  | 	Return (ListFindNode(l, Value) <> Null) | ||||||
|  | End Function | ||||||
|  |  | ||||||
|  | ;Create a linked list from the intvalues in a bank (slow) | ||||||
|  | Function ListFromBank.LList(bank) | ||||||
|  | 	Local l.LList = CreateList() | ||||||
|  | 	Local size = BankSize(bank), p | ||||||
|  | 	 | ||||||
|  | 	For p = 0 To size - 4 Step 4 | ||||||
|  | 		ListAddLast l, PeekInt(bank, p) | ||||||
|  | 	Next | ||||||
|  | 	 | ||||||
|  | 	Return l | ||||||
|  | End Function | ||||||
|  |  | ||||||
|  | ;Create a bank containing all the values in a list (slow) | ||||||
|  | Function ListToBank(l.LList) | ||||||
|  | 	Local size = ListLength(l) * 4 | ||||||
|  | 	Local bank = CreateBank(size) | ||||||
|  | 	 | ||||||
|  | 	Local i.Iterator = GetIterator(l), p = 0 | ||||||
|  | 	While EachIn(i) | ||||||
|  | 		PokeInt bank, p, i\Value | ||||||
|  | 		p = p + 4 | ||||||
|  | 	Wend | ||||||
|  | 	 | ||||||
|  | 	Return bank | ||||||
|  | End Function | ||||||
|  |  | ||||||
|  | ;Swap the contents of two list objects | ||||||
|  | Function SwapLists(l1.LList, l2.LList) | ||||||
|  | 	Local tempH.ListNode = l1\head_, tempT.ListNode = l1\tail_ | ||||||
|  | 	l1\head_ = l2\head_ | ||||||
|  | 	l1\tail_ = l2\tail_ | ||||||
|  | 	l2\head_ = tempH | ||||||
|  | 	l2\tail_ = tempT | ||||||
|  | End Function | ||||||
|  |  | ||||||
|  | ;Create a new list containing the same values as the first | ||||||
|  | Function CopyList.LList(lo.LList) | ||||||
|  | 	Local ln.LList = CreateList() | ||||||
|  | 	Local i.Iterator = GetIterator(lo) : While EachIn(i) | ||||||
|  | 		ListAddLast ln, i\Value | ||||||
|  | 	Wend | ||||||
|  | 	Return ln | ||||||
|  | End Function | ||||||
|  |  | ||||||
|  | ;Reverse the order of elements of a list | ||||||
|  | Function ReverseList(l.LList) | ||||||
|  | 	Local n1.ListNode, n2.ListNode, tmp.ListNode | ||||||
|  | 	 | ||||||
|  | 	n1 = l\head_ | ||||||
|  | 	n2 = l\head_\nx_ | ||||||
|  | 	 | ||||||
|  | 	While n1 <> l\tail_ | ||||||
|  | 		n1\pv_ = n2 | ||||||
|  | 		tmp = n2\nx_ | ||||||
|  | 		n2\nx_ = n1 | ||||||
|  | 		n1 = n2 | ||||||
|  | 		n2 = tmp | ||||||
|  | 	Wend | ||||||
|  | 	 | ||||||
|  | 	tmp = l\head_ | ||||||
|  | 	l\head_ = l\tail_ | ||||||
|  | 	l\tail_ = tmp | ||||||
|  | 	 | ||||||
|  | 	l\head_\pv_ = l\head_ | ||||||
|  | 	l\tail_\nx_ = l\tail_ | ||||||
|  | End Function | ||||||
|  |  | ||||||
|  | ;Search a list to retrieve the first node with the given value | ||||||
|  | Function ListFindNode.ListNode(l.LList, Value) | ||||||
|  | 	Local n.ListNode = l\head_\nx_ | ||||||
|  | 	 | ||||||
|  | 	While n <> l\tail_ | ||||||
|  | 		If n\Value = Value Then Return n | ||||||
|  | 		n = n\nx_ | ||||||
|  | 	Wend | ||||||
|  | 	 | ||||||
|  | 	Return Null | ||||||
|  | End Function | ||||||
|  |  | ||||||
|  | ;Append a value to the end of a list (fast) and return the node | ||||||
|  | Function ListAddLast.ListNode(l.LList, Value) | ||||||
|  | 	Local n.ListNode = New ListNode | ||||||
|  | 	 | ||||||
|  | 	n\pv_ = l\tail_\pv_ | ||||||
|  | 	n\nx_ = l\tail_ | ||||||
|  | 	n\Value = Value | ||||||
|  | 	 | ||||||
|  | 	l\tail_\pv_ = n | ||||||
|  | 	n\pv_\nx_ = n | ||||||
|  | 	 | ||||||
|  | 	Return n | ||||||
|  | End Function | ||||||
|  |  | ||||||
|  | ;Attach a value to the start of a list (fast) and return the node | ||||||
|  | Function ListAddFirst.ListNode(l.LList, Value) | ||||||
|  | 	Local n.ListNode = New ListNode | ||||||
|  | 	 | ||||||
|  | 	n\pv_ = l\head_ | ||||||
|  | 	n\nx_ = l\head_\nx_ | ||||||
|  | 	n\Value = Value | ||||||
|  | 	 | ||||||
|  | 	l\head_\nx_ = n | ||||||
|  | 	n\nx_\pv_ = n | ||||||
|  | 	 | ||||||
|  | 	Return n | ||||||
|  | End Function | ||||||
|  |  | ||||||
|  | ;Remove the first occurence of the given value from a list | ||||||
|  | Function ListRemove(l.LList, Value) | ||||||
|  | 	Local n.ListNode = ListFindNode(l, Value) | ||||||
|  | 	If n <> Null Then RemoveListNode n | ||||||
|  | End Function | ||||||
|  |  | ||||||
|  | ;Remove a node from a list | ||||||
|  | Function RemoveListNode(n.ListNode) | ||||||
|  | 	n\pv_\nx_ = n\nx_ | ||||||
|  | 	n\nx_\pv_ = n\pv_ | ||||||
|  | 	Delete n | ||||||
|  | End Function | ||||||
|  |  | ||||||
|  | ;Return the value of the element at the given position from the start of the list, | ||||||
|  | ;or backwards from the end of the list for a negative index | ||||||
|  | Function ValueAtIndex(l.LList, index) | ||||||
|  | 	Local n.ListNode = ListNodeAtIndex(l, index) | ||||||
|  | 	If n <> Null Then Return n\Value : Else Return 0 | ||||||
|  | End Function | ||||||
|  |  | ||||||
|  | ;Return the ListNode at the given position from the start of the list, or backwards | ||||||
|  | ;from the end of the list for a negative index, or Null if invalid | ||||||
|  | Function ListNodeAtIndex.ListNode(l.LList, index) | ||||||
|  | 	Local e, n.ListNode | ||||||
|  | 	 | ||||||
|  | 	If index >= 0 | ||||||
|  | 		n = l\head_ | ||||||
|  | 		For e = 0 To index | ||||||
|  | 			n = n\nx_ | ||||||
|  | 		Next | ||||||
|  | 		If n = l\tail_ Then n = Null	;Beyond the end of the list - not valid | ||||||
|  | 		 | ||||||
|  | 	Else	;Negative index - count backward | ||||||
|  | 		n = l\tail_ | ||||||
|  | 		For e = 0 To index Step -1 | ||||||
|  | 			n = n\pv_ | ||||||
|  | 		Next | ||||||
|  | 		If n = l\head_ Then n = Null	;Before the start of the list - not valid | ||||||
|  | 		 | ||||||
|  | 	EndIf | ||||||
|  | 	 | ||||||
|  | 	Return n | ||||||
|  | End Function | ||||||
|  |  | ||||||
|  | ;Replace a value at the given position (added by MusicianKool) | ||||||
|  | Function ReplaceValueAtIndex(l.LList,index,value) | ||||||
|  | 	Local n.ListNode = ListNodeAtIndex(l,index) | ||||||
|  | 	If n <> Null Then n\Value = value:Else Return 0 | ||||||
|  | End Function | ||||||
|  |  | ||||||
|  | ;Remove and return a value at the given position (added by MusicianKool) | ||||||
|  | Function RemoveNodeAtIndex(l.LList,index) | ||||||
|  | 	Local n.ListNode = ListNodeAtIndex(l,index),tval | ||||||
|  | 	If n <> Null Then tval = n\Value:RemoveListNode(n):Return tval:Else Return 0 | ||||||
|  | End Function | ||||||
|  |  | ||||||
|  | ;Retrieve the first value from a list | ||||||
|  | Function ListFirst(l.LList) | ||||||
|  | 	If l\head_\nx_ <> l\tail_ Then Return l\head_\nx_\Value | ||||||
|  | End Function | ||||||
|  |  | ||||||
|  | ;Retrieve the last value from a list | ||||||
|  | Function ListLast(l.LList) | ||||||
|  | 	If l\tail_\pv_ <> l\head_ Then Return l\tail_\pv_\Value | ||||||
|  | End Function | ||||||
|  |  | ||||||
|  | ;Remove the first element from a list, and return its value | ||||||
|  | Function ListRemoveFirst(l.LList) | ||||||
|  | 	Local val | ||||||
|  | 	If l\head_\nx_ <> l\tail_ | ||||||
|  | 		val = l\head_\nx_\Value | ||||||
|  | 		RemoveListNode l\head_\nx_ | ||||||
|  | 	EndIf | ||||||
|  | 	Return val | ||||||
|  | End Function | ||||||
|  |  | ||||||
|  | ;Remove the last element from a list, and return its value | ||||||
|  | Function ListRemoveLast(l.LList) | ||||||
|  | 	Local val | ||||||
|  | 	If l\tail_\pv_ <> l\head_ | ||||||
|  | 		val = l\tail_\pv_\Value | ||||||
|  | 		RemoveListNode l\tail_\pv_ | ||||||
|  | 	EndIf | ||||||
|  | 	Return val | ||||||
|  | End Function | ||||||
|  |  | ||||||
|  | ;Insert a value into a list before the specified node, and return the new node | ||||||
|  | Function InsertBeforeNode.ListNode(Value, n.ListNode) | ||||||
|  | 	Local bef.ListNode = New ListNode | ||||||
|  | 	 | ||||||
|  | 	bef\pv_ = n\pv_ | ||||||
|  | 	bef\nx_ = n | ||||||
|  | 	bef\Value = Value | ||||||
|  | 	 | ||||||
|  | 	n\pv_ = bef | ||||||
|  | 	bef\pv_\nx_ = bef | ||||||
|  | 	 | ||||||
|  | 	Return bef | ||||||
|  | End Function | ||||||
|  |  | ||||||
|  | ;Insert a value into a list after the specified node, and return then new node | ||||||
|  | Function InsertAfterNode.ListNode(Value, n.ListNode) | ||||||
|  | 	Local aft.ListNode = New ListNode | ||||||
|  | 	 | ||||||
|  | 	aft\nx_ = n\nx_ | ||||||
|  | 	aft\pv_ = n | ||||||
|  | 	aft\Value = Value | ||||||
|  | 	 | ||||||
|  | 	n\nx_ = aft | ||||||
|  | 	aft\nx_\pv_ = aft | ||||||
|  | 	 | ||||||
|  | 	Return aft | ||||||
|  | End Function | ||||||
|  |  | ||||||
|  | ;Get an iterator object to use with a loop | ||||||
|  | ;This function means that most programs won't have to think about deleting iterators manually | ||||||
|  | ;(in general only a small, constant number will be created) | ||||||
|  | Function GetIterator.Iterator(l.LList) | ||||||
|  | 	Local i.Iterator | ||||||
|  | 	 | ||||||
|  | 	If l = Null Then RuntimeError "Cannot create Iterator for Null" | ||||||
|  | 	 | ||||||
|  | 	For i = Each Iterator		;See if there's an available iterator at the moment | ||||||
|  | 		If i\l_ = Null Then Exit | ||||||
|  | 	Next | ||||||
|  | 	 | ||||||
|  | 	If i = Null Then i = New Iterator	;If there wasn't, create one | ||||||
|  | 	 | ||||||
|  | 	i\l_ = l | ||||||
|  | 	i\cn_ = l\head_ | ||||||
|  | 	i\cni_ = -1 | ||||||
|  | 	i\Value = 0		;No especial reason why this has to be anything, but meh | ||||||
|  | 	 | ||||||
|  | 	Return i | ||||||
|  | End Function | ||||||
|  |  | ||||||
|  | ;Use as the argument to While to iterate over the members of a list | ||||||
|  | Function EachIn(i.Iterator) | ||||||
|  | 	 | ||||||
|  | 	i\cn_ = i\cn_\nx_ | ||||||
|  | 	 | ||||||
|  | 	If i\cn_ <> i\l_\tail_		;Still items in the list | ||||||
|  | 		i\Value = i\cn_\Value | ||||||
|  | 		i\cni_ = i\cni_ + 1 | ||||||
|  | 		Return True | ||||||
|  | 		 | ||||||
|  | 	Else | ||||||
|  | 		i\l_ = Null		;Disconnect from the list, having reached the end | ||||||
|  | 		i\cn_ = Null | ||||||
|  | 		i\cni_ = -1 | ||||||
|  | 		Return False | ||||||
|  | 		 | ||||||
|  | 	EndIf | ||||||
|  | End Function | ||||||
|  |  | ||||||
|  | ;Remove from the containing list the element currently pointed to by an iterator | ||||||
|  | Function IteratorRemove(i.Iterator) | ||||||
|  | 	If (i\cn_ <> i\l_\head_) And (i\cn_ <> i\l_\tail_) | ||||||
|  | 		Local temp.ListNode = i\cn_ | ||||||
|  | 		 | ||||||
|  | 		i\cn_ = i\cn_\pv_ | ||||||
|  | 		i\cni_ = i\cni_ - 1 | ||||||
|  | 		i\Value = 0 | ||||||
|  | 		 | ||||||
|  | 		RemoveListNode temp | ||||||
|  | 		 | ||||||
|  | 		Return True | ||||||
|  | 	Else | ||||||
|  | 		Return False | ||||||
|  | 	EndIf | ||||||
|  | End Function | ||||||
|  |  | ||||||
|  | ;Call this before breaking out of an EachIn loop, to disconnect the iterator from the list | ||||||
|  | Function IteratorBreak(i.Iterator) | ||||||
|  | 	i\l_ = Null | ||||||
|  | 	i\cn_ = Null | ||||||
|  | 	i\cni_ = -1 | ||||||
|  | 	i\Value = 0 | ||||||
|  | End Function | ||||||
|  |  | ||||||
|  |  | ||||||
|  | ;~IDEal Editor Parameters: | ||||||
|  | ;~F#5#A#10#18#2A#32#3E#47#4C#58#66#6F#78#8F#9B#A9#B7#BD#C5#CC | ||||||
|  | ;~F#E3#E9#EF#F4#F9#103#10D#11B#12B#13F#152#163 | ||||||
|  | ;~C#Blitz3D | ||||||
							
								
								
									
										66
									
								
								samples/BlitzBasic/PObj.bb
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										66
									
								
								samples/BlitzBasic/PObj.bb
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,66 @@ | |||||||
|  |  | ||||||
|  | Local i, start, result | ||||||
|  |  | ||||||
|  | Local s.Sum3Obj = New Sum3Obj | ||||||
|  |  | ||||||
|  | For i = 1 To 100000 | ||||||
|  | 	s = New Sum3Obj | ||||||
|  | 	result = Handle Before s | ||||||
|  | 	Delete s | ||||||
|  | Next | ||||||
|  |  | ||||||
|  | start = MilliSecs() | ||||||
|  | For i = 1 To 1000000 | ||||||
|  | 	result = Sum3_(MakeSum3Obj(i, i, i)) | ||||||
|  | Next | ||||||
|  | start = MilliSecs() - start | ||||||
|  | Print start | ||||||
|  |  | ||||||
|  | start = MilliSecs() | ||||||
|  | For i = 1 To 1000000 | ||||||
|  | 	result = Sum3(i, i, i) | ||||||
|  | Next | ||||||
|  | start = MilliSecs() - start | ||||||
|  | Print start | ||||||
|  |  | ||||||
|  | WaitKey | ||||||
|  | End | ||||||
|  |  | ||||||
|  |  | ||||||
|  | Function Sum3(a, b, c) | ||||||
|  | 	Return a + b + c | ||||||
|  | End Function | ||||||
|  |  | ||||||
|  |  | ||||||
|  | Type Sum3Obj | ||||||
|  | 	Field isActive | ||||||
|  | 	Field a, b, c | ||||||
|  | End Type | ||||||
|  |  | ||||||
|  | Function MakeSum3Obj(a, b, c) | ||||||
|  | 	Local s.Sum3Obj = Last Sum3Obj | ||||||
|  | 	If s\isActive Then s = New Sum3Obj | ||||||
|  | 	s\isActive = True | ||||||
|  | 	s\a = a | ||||||
|  | 	s\b = b | ||||||
|  | 	s\c = c | ||||||
|  | 	 | ||||||
|  | 	Restore label | ||||||
|  | 	Read foo | ||||||
|  | 	 | ||||||
|  | 	Return Handle(s) | ||||||
|  | End Function | ||||||
|  |  | ||||||
|  | .label | ||||||
|  | Data (10 + 2), 12, 14 | ||||||
|  | : | ||||||
|  | Function Sum3_(a_) | ||||||
|  | 	Local a.Sum3Obj = Object.Sum3Obj a_ | ||||||
|  | 	Local return_ =  a\a + a\b + a\c | ||||||
|  | 	Insert a Before First Sum3Obj :: a\isActive = False | ||||||
|  | 	Return return_ | ||||||
|  | End Function | ||||||
|  |  | ||||||
|  |  | ||||||
|  | ;~IDEal Editor Parameters: | ||||||
|  | ;~C#Blitz3D | ||||||
							
								
								
									
										167
									
								
								samples/Bluespec/TL.bsv
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										167
									
								
								samples/Bluespec/TL.bsv
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,167 @@ | |||||||
|  | package TL; | ||||||
|  |  | ||||||
|  | interface TL; | ||||||
|  |    method Action ped_button_push(); | ||||||
|  |  | ||||||
|  |          (* always_enabled *) | ||||||
|  |          method Action set_car_state_N(Bool x); | ||||||
|  |          (* always_enabled *) | ||||||
|  |          method Action set_car_state_S(Bool x); | ||||||
|  |          (* always_enabled *) | ||||||
|  |          method Action set_car_state_E(Bool x); | ||||||
|  |          (* always_enabled *) | ||||||
|  |          method Action set_car_state_W(Bool x); | ||||||
|  |  | ||||||
|  |    method Bool lampRedNS(); | ||||||
|  |    method Bool lampAmberNS(); | ||||||
|  |    method Bool lampGreenNS(); | ||||||
|  |  | ||||||
|  |    method Bool lampRedE(); | ||||||
|  |    method Bool lampAmberE(); | ||||||
|  |    method Bool lampGreenE(); | ||||||
|  |  | ||||||
|  |    method Bool lampRedW(); | ||||||
|  |    method Bool lampAmberW(); | ||||||
|  |    method Bool lampGreenW(); | ||||||
|  |  | ||||||
|  |    method Bool lampRedPed(); | ||||||
|  |    method Bool lampAmberPed(); | ||||||
|  |    method Bool lampGreenPed(); | ||||||
|  | endinterface: TL | ||||||
|  |  | ||||||
|  | typedef enum { | ||||||
|  |          AllRed, | ||||||
|  |          GreenNS, AmberNS, | ||||||
|  |          GreenE, AmberE, | ||||||
|  |          GreenW, AmberW, | ||||||
|  |          GreenPed, AmberPed} TLstates deriving (Eq, Bits); | ||||||
|  |  | ||||||
|  | typedef UInt#(5) Time32; | ||||||
|  | typedef UInt#(20) CtrSize; | ||||||
|  |  | ||||||
|  | (* synthesize *) | ||||||
|  | module sysTL(TL); | ||||||
|  |    Time32 allRedDelay = 2; | ||||||
|  |    Time32 amberDelay = 4; | ||||||
|  |    Time32 nsGreenDelay = 20; | ||||||
|  |    Time32 ewGreenDelay = 10; | ||||||
|  |    Time32 pedGreenDelay = 10; | ||||||
|  |    Time32 pedAmberDelay = 6; | ||||||
|  |  | ||||||
|  |    CtrSize clocks_per_sec = 100; | ||||||
|  |  | ||||||
|  |    Reg#(TLstates) state <- mkReg(AllRed); | ||||||
|  |    Reg#(TLstates) next_green <- mkReg(GreenNS); | ||||||
|  |    Reg#(Time32) secs <- mkReg(0); | ||||||
|  |    Reg#(Bool) ped_button_pushed <- mkReg(False); | ||||||
|  |          Reg#(Bool) car_present_N <- mkReg(True); | ||||||
|  |    Reg#(Bool) car_present_S <- mkReg(True); | ||||||
|  |    Reg#(Bool) car_present_E <- mkReg(True); | ||||||
|  |    Reg#(Bool) car_present_W <- mkReg(True); | ||||||
|  |          Bool car_present_NS = car_present_N || car_present_S; | ||||||
|  |    Reg#(CtrSize) cycle_ctr <- mkReg(0); | ||||||
|  |  | ||||||
|  |    rule dec_cycle_ctr (cycle_ctr != 0); | ||||||
|  |       cycle_ctr <= cycle_ctr - 1; | ||||||
|  |    endrule | ||||||
|  |  | ||||||
|  |    Rules low_priority_rule = (rules | ||||||
|  |                         rule inc_sec (cycle_ctr == 0); | ||||||
|  |                                  secs <= secs + 1; | ||||||
|  |                                  cycle_ctr <= clocks_per_sec; | ||||||
|  |                         endrule endrules); | ||||||
|  |  | ||||||
|  |    function Action next_state(TLstates ns); | ||||||
|  |          action | ||||||
|  |                                  state <= ns; | ||||||
|  |                                  secs <= 0; | ||||||
|  |       endaction | ||||||
|  |    endfunction: next_state | ||||||
|  |  | ||||||
|  |    function TLstates green_seq(TLstates x); | ||||||
|  |       case (x) | ||||||
|  |                                  GreenNS: return (GreenE); | ||||||
|  |                                  GreenE:  return (GreenW); | ||||||
|  |                                  GreenW:  return (GreenNS); | ||||||
|  |       endcase | ||||||
|  |    endfunction | ||||||
|  |  | ||||||
|  |    function Bool car_present(TLstates x); | ||||||
|  |       case (x) | ||||||
|  |                                  GreenNS: return (car_present_NS); | ||||||
|  |                                  GreenE:  return (car_present_E); | ||||||
|  |                                  GreenW:  return (car_present_W); | ||||||
|  |       endcase | ||||||
|  |    endfunction | ||||||
|  |  | ||||||
|  |    function Rules make_from_green_rule(TLstates green_state, Time32 delay, Bool car_is_present, TLstates ns); | ||||||
|  |                         return (rules | ||||||
|  |                                  rule from_green (state == green_state && (secs >= delay || !car_is_present)); | ||||||
|  |                                                 next_state(ns); | ||||||
|  |                                  endrule endrules); | ||||||
|  |    endfunction: make_from_green_rule | ||||||
|  |  | ||||||
|  |    function Rules make_from_amber_rule(TLstates amber_state, TLstates ng); | ||||||
|  |       return (rules | ||||||
|  |                                  rule from_amber (state == amber_state && secs >= amberDelay); | ||||||
|  |                                                 next_state(AllRed); | ||||||
|  |                                                 next_green <= ng; | ||||||
|  |                                  endrule endrules); | ||||||
|  |    endfunction: make_from_amber_rule | ||||||
|  |  | ||||||
|  |    Rules hprs[7]; | ||||||
|  |  | ||||||
|  |    hprs[1] = make_from_green_rule(GreenNS, nsGreenDelay, car_present_NS, AmberNS); | ||||||
|  |    hprs[2] = make_from_amber_rule(AmberNS, GreenE); | ||||||
|  |    hprs[3] = make_from_green_rule(GreenE, ewGreenDelay, car_present_E, AmberE); | ||||||
|  |    hprs[4] = make_from_amber_rule(AmberE, GreenW); | ||||||
|  |    hprs[5] = make_from_green_rule(GreenW, ewGreenDelay, car_present_W, AmberW); | ||||||
|  |    hprs[6] = make_from_amber_rule(AmberW, GreenNS); | ||||||
|  |  | ||||||
|  |          hprs[0] = (rules | ||||||
|  |                         rule fromAllRed (state == AllRed && secs >= allRedDelay); | ||||||
|  |                                  if (ped_button_pushed) action | ||||||
|  |                                                 ped_button_pushed <= False; | ||||||
|  |                                                 next_state(GreenPed); | ||||||
|  |                                  endaction else if (car_present(next_green)) | ||||||
|  |                               next_state(next_green); | ||||||
|  |                            else if (car_present(green_seq(next_green))) | ||||||
|  |                                     next_state(green_seq(next_green)); | ||||||
|  |          else if (car_present(green_seq(green_seq(next_green)))) | ||||||
|  |                                     next_state(green_seq(green_seq(next_green))); | ||||||
|  |          else | ||||||
|  |                                     noAction; | ||||||
|  |                         endrule: fromAllRed endrules); | ||||||
|  |  | ||||||
|  |          Rules high_priority_rules = hprs[0]; | ||||||
|  |    for (Integer i = 1; i<7; i=i+1) | ||||||
|  |       high_priority_rules = rJoin(hprs[i], high_priority_rules); | ||||||
|  |  | ||||||
|  |          addRules(preempts(high_priority_rules, low_priority_rule)); | ||||||
|  |  | ||||||
|  |    method Action ped_button_push(); | ||||||
|  |       ped_button_pushed <= True; | ||||||
|  |    endmethod: ped_button_push | ||||||
|  |  | ||||||
|  |    method Action set_car_state_N(b) ; car_present_N <= b; endmethod | ||||||
|  |    method Action set_car_state_S(b) ; car_present_S <= b; endmethod | ||||||
|  |    method Action set_car_state_E(b) ; car_present_E <= b; endmethod | ||||||
|  |    method Action set_car_state_W(b) ; car_present_W <= b; endmethod | ||||||
|  |  | ||||||
|  |    method lampRedNS() = (!(state == GreenNS || state == AmberNS)); | ||||||
|  |    method lampAmberNS() = (state == AmberNS); | ||||||
|  |    method lampGreenNS() = (state == GreenNS); | ||||||
|  |    method lampRedE() = (!(state == GreenE || state == AmberE)); | ||||||
|  |    method lampAmberE() = (state == AmberE); | ||||||
|  |    method lampGreenE() = (state == GreenE); | ||||||
|  |    method lampRedW() = (!(state == GreenW || state == AmberW)); | ||||||
|  |    method lampAmberW() = (state == AmberW); | ||||||
|  |    method lampGreenW() = (state == GreenW); | ||||||
|  |  | ||||||
|  |    method lampRedPed() = (!(state == GreenPed || state == AmberPed)); | ||||||
|  |    method lampAmberPed() = (state == AmberPed); | ||||||
|  |    method lampGreenPed() = (state == GreenPed); | ||||||
|  |  | ||||||
|  | endmodule: sysTL | ||||||
|  |  | ||||||
|  | endpackage: TL | ||||||
							
								
								
									
										109
									
								
								samples/Bluespec/TbTL.bsv
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										109
									
								
								samples/Bluespec/TbTL.bsv
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,109 @@ | |||||||
|  | package TbTL; | ||||||
|  |  | ||||||
|  | import TL::*; | ||||||
|  |  | ||||||
|  | interface Lamp; | ||||||
|  |    method Bool changed; | ||||||
|  |    method Action show_offs; | ||||||
|  |    method Action show_ons; | ||||||
|  |    method Action reset; | ||||||
|  | endinterface | ||||||
|  |  | ||||||
|  | module mkLamp#(String name, Bool lamp)(Lamp); | ||||||
|  |    Reg#(Bool) prev <- mkReg(False); | ||||||
|  |  | ||||||
|  |    method changed = (prev != lamp); | ||||||
|  |  | ||||||
|  |    method Action show_offs; | ||||||
|  |       if (prev && !lamp) | ||||||
|  |       $write (name + " off, "); | ||||||
|  |    endmethod | ||||||
|  |  | ||||||
|  |    method Action show_ons; | ||||||
|  |       if (!prev && lamp) | ||||||
|  |       $write (name + " on, "); | ||||||
|  |    endmethod | ||||||
|  |  | ||||||
|  |    method Action reset; | ||||||
|  |       prev <= lamp; | ||||||
|  |    endmethod | ||||||
|  | endmodule | ||||||
|  |  | ||||||
|  |  | ||||||
|  | (* synthesize *) | ||||||
|  | module mkTest(); | ||||||
|  |    let dut <- sysTL; | ||||||
|  |  | ||||||
|  |    Reg#(Bit#(16)) ctr <- mkReg(0); | ||||||
|  |  | ||||||
|  |    Reg#(Bool) carN <- mkReg(False); | ||||||
|  |    Reg#(Bool) carS <- mkReg(False); | ||||||
|  |    Reg#(Bool) carE <- mkReg(False); | ||||||
|  |    Reg#(Bool) carW <- mkReg(False); | ||||||
|  |  | ||||||
|  |    Lamp lamps[12]; | ||||||
|  |  | ||||||
|  |    lamps[0] <- mkLamp("0:  NS  red  ", dut.lampRedNS); | ||||||
|  |    lamps[1] <- mkLamp("1:  NS  amber", dut.lampAmberNS); | ||||||
|  |    lamps[2] <- mkLamp("2:  NS  green", dut.lampGreenNS); | ||||||
|  |    lamps[3] <- mkLamp("3:  E   red  ", dut.lampRedE); | ||||||
|  |    lamps[4] <- mkLamp("4:  E   amber", dut.lampAmberE); | ||||||
|  |    lamps[5] <- mkLamp("5:  E   green", dut.lampGreenE); | ||||||
|  |    lamps[6] <- mkLamp("6:  W   red  ", dut.lampRedW); | ||||||
|  |    lamps[7] <- mkLamp("7:  W   amber", dut.lampAmberW); | ||||||
|  |    lamps[8] <- mkLamp("8:  W   green", dut.lampGreenW); | ||||||
|  |  | ||||||
|  |    lamps[9]  <- mkLamp("9:  Ped red  ", dut.lampRedPed); | ||||||
|  |    lamps[10] <- mkLamp("10: Ped amber", dut.lampAmberPed); | ||||||
|  |    lamps[11] <- mkLamp("11: Ped green", dut.lampGreenPed); | ||||||
|  |  | ||||||
|  |    rule start (ctr == 0); | ||||||
|  |       $dumpvars; | ||||||
|  |    endrule | ||||||
|  |  | ||||||
|  |    rule detect_cars; | ||||||
|  |       dut.set_car_state_N(carN); | ||||||
|  |       dut.set_car_state_S(carS); | ||||||
|  |       dut.set_car_state_E(carE); | ||||||
|  |       dut.set_car_state_W(carW); | ||||||
|  |    endrule | ||||||
|  |  | ||||||
|  |    rule go; | ||||||
|  |       ctr <= ctr + 1; | ||||||
|  |       if (ctr == 5000) carN <= True; | ||||||
|  |       if (ctr == 6500) carN <= False; | ||||||
|  |       if (ctr == 12_000) dut.ped_button_push; | ||||||
|  |    endrule | ||||||
|  |  | ||||||
|  |    rule stop (ctr > 32768); | ||||||
|  |       $display("TESTS FINISHED"); | ||||||
|  |       $finish(0); | ||||||
|  |    endrule | ||||||
|  |  | ||||||
|  |    function do_offs(l) = l.show_offs; | ||||||
|  |       function do_ons(l) = l.show_ons; | ||||||
|  |       function do_reset(l) = l.reset; | ||||||
|  |  | ||||||
|  |       function do_it(f); | ||||||
|  |          action | ||||||
|  |          for (Integer i=0; i<12; i=i+1) | ||||||
|  |             f(lamps[i]); | ||||||
|  |          endaction | ||||||
|  |       endfunction | ||||||
|  |  | ||||||
|  |       function any_changes(); | ||||||
|  |          Bool b = False; | ||||||
|  |          for (Integer i=0; i<12; i=i+1) | ||||||
|  |              b = b || lamps[i].changed; | ||||||
|  |          return b; | ||||||
|  |       endfunction | ||||||
|  |  | ||||||
|  |       rule show (any_changes()); | ||||||
|  |       do_it(do_offs); | ||||||
|  |       do_it(do_ons); | ||||||
|  |       do_it(do_reset); | ||||||
|  |       $display("(at time %d)", $time); | ||||||
|  |    endrule | ||||||
|  | endmodule | ||||||
|  |  | ||||||
|  | endpackage | ||||||
							
								
								
									
										305
									
								
								samples/Brightscript/SimpleGrid.brs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										305
									
								
								samples/Brightscript/SimpleGrid.brs
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,305 @@ | |||||||
|  | ' ********************************************************* | ||||||
|  | ' **  Simple Grid Screen Demonstration App | ||||||
|  | ' **  Jun 2010 | ||||||
|  | ' **  Copyright (c) 2010 Roku Inc. All Rights Reserved. | ||||||
|  | ' ********************************************************* | ||||||
|  |  | ||||||
|  | '************************************************************ | ||||||
|  | '** Application startup | ||||||
|  | '************************************************************ | ||||||
|  | Sub Main() | ||||||
|  |  | ||||||
|  |     'initialize theme attributes like titles, logos and overhang color | ||||||
|  |     initTheme() | ||||||
|  |    | ||||||
|  |     gridstyle = "Flat-Movie" | ||||||
|  |  | ||||||
|  |     'set to go, time to get started | ||||||
|  |     while gridstyle <> "" | ||||||
|  |         print "starting grid style= ";gridstyle | ||||||
|  |         screen=preShowGridScreen(gridstyle) | ||||||
|  |         gridstyle = showGridScreen(screen, gridstyle) | ||||||
|  |     end while | ||||||
|  |  | ||||||
|  | End Sub | ||||||
|  |  | ||||||
|  |  | ||||||
|  | '************************************************************* | ||||||
|  | '** Set the configurable theme attributes for the application | ||||||
|  | '**  | ||||||
|  | '** Configure the custom overhang and Logo attributes | ||||||
|  | '** These attributes affect the branding of the application | ||||||
|  | '** and are artwork, colors and offsets specific to the app | ||||||
|  | '************************************************************* | ||||||
|  |  | ||||||
|  | Sub initTheme() | ||||||
|  |     app = CreateObject("roAppManager") | ||||||
|  |     app.SetTheme(CreateDefaultTheme()) | ||||||
|  | End Sub | ||||||
|  |  | ||||||
|  | '****************************************************** | ||||||
|  | '** @return The default application theme. | ||||||
|  | '** Screens can make slight adjustments to the default | ||||||
|  | '** theme by getting it from here and then overriding | ||||||
|  | '** individual theme attributes. | ||||||
|  | '****************************************************** | ||||||
|  | Function CreateDefaultTheme() as Object | ||||||
|  |     theme = CreateObject("roAssociativeArray") | ||||||
|  |  | ||||||
|  |     theme.ThemeType = "generic-dark" | ||||||
|  |  | ||||||
|  |     ' All these are greyscales | ||||||
|  |     theme.GridScreenBackgroundColor = "#363636" | ||||||
|  |     theme.GridScreenMessageColor    = "#808080" | ||||||
|  |     theme.GridScreenRetrievingColor = "#CCCCCC" | ||||||
|  |     theme.GridScreenListNameColor   = "#FFFFFF" | ||||||
|  |  | ||||||
|  |     ' Color values work here | ||||||
|  |     theme.GridScreenDescriptionTitleColor    = "#001090" | ||||||
|  |     theme.GridScreenDescriptionDateColor     = "#FF005B" | ||||||
|  |     theme.GridScreenDescriptionRuntimeColor  = "#5B005B" | ||||||
|  |     theme.GridScreenDescriptionSynopsisColor = "#606000" | ||||||
|  |      | ||||||
|  |     'used in the Grid Screen | ||||||
|  |     theme.CounterTextLeft           = "#FF0000" | ||||||
|  |     theme.CounterSeparator          = "#00FF00" | ||||||
|  |     theme.CounterTextRight          = "#0000FF" | ||||||
|  |      | ||||||
|  |     theme.GridScreenLogoHD          = "pkg:/images/Overhang_Test_HD.png" | ||||||
|  |  | ||||||
|  |     theme.GridScreenLogoOffsetHD_X  = "0" | ||||||
|  |     theme.GridScreenLogoOffsetHD_Y  = "0" | ||||||
|  |     theme.GridScreenOverhangHeightHD = "99" | ||||||
|  |  | ||||||
|  |     theme.GridScreenLogoSD          = "pkg:/images/Overhang_Test_SD43.png" | ||||||
|  |     theme.GridScreenOverhangHeightSD = "66" | ||||||
|  |     theme.GridScreenLogoOffsetSD_X  = "0" | ||||||
|  |     theme.GridScreenLogoOffsetSD_Y  = "0" | ||||||
|  |      | ||||||
|  |     ' to use your own focus ring artwork  | ||||||
|  |     'theme.GridScreenFocusBorderSD        = "pkg:/images/GridCenter_Border_Movies_SD43.png" | ||||||
|  |     'theme.GridScreenBorderOffsetSD  = "(-26,-25)" | ||||||
|  |     'theme.GridScreenFocusBorderHD        = "pkg:/images/GridCenter_Border_Movies_HD.png" | ||||||
|  |     'theme.GridScreenBorderOffsetHD  = "(-28,-20)" | ||||||
|  |      | ||||||
|  |     ' to use your own description background artwork | ||||||
|  |     'theme.GridScreenDescriptionImageSD  = "pkg:/images/Grid_Description_Background_SD43.png" | ||||||
|  |     'theme.GridScreenDescriptionOffsetSD = "(125,170)" | ||||||
|  |     'theme.GridScreenDescriptionImageHD  = "pkg:/images/Grid_Description_Background_HD.png" | ||||||
|  |     'theme.GridScreenDescriptionOffsetHD = "(190,255)" | ||||||
|  |      | ||||||
|  |  | ||||||
|  |     return theme | ||||||
|  | End Function | ||||||
|  |  | ||||||
|  | '****************************************************** | ||||||
|  | '** Perform any startup/initialization stuff prior to  | ||||||
|  | '** initially showing the screen.   | ||||||
|  | '****************************************************** | ||||||
|  | Function preShowGridScreen(style as string) As Object | ||||||
|  |  | ||||||
|  |     m.port=CreateObject("roMessagePort") | ||||||
|  |     screen = CreateObject("roGridScreen") | ||||||
|  |     screen.SetMessagePort(m.port) | ||||||
|  | '    screen.SetDisplayMode("best-fit") | ||||||
|  |     screen.SetDisplayMode("scale-to-fill") | ||||||
|  |  | ||||||
|  |     screen.SetGridStyle(style) | ||||||
|  |     return screen | ||||||
|  |  | ||||||
|  | End Function | ||||||
|  |  | ||||||
|  |  | ||||||
|  | '****************************************************** | ||||||
|  | '** Display the gird screen and wait for events from  | ||||||
|  | '** the screen. The screen will show retreiving while | ||||||
|  | '** we fetch and parse the feeds for the show posters | ||||||
|  | '****************************************************** | ||||||
|  | Function showGridScreen(screen As Object, gridstyle as string) As string | ||||||
|  |  | ||||||
|  |     print "enter showGridScreen" | ||||||
|  |  | ||||||
|  |     categoryList = getCategoryList() | ||||||
|  |     categoryList[0] = "GridStyle: " + gridstyle | ||||||
|  |     screen.setupLists(categoryList.count()) | ||||||
|  |     screen.SetListNames(categoryList) | ||||||
|  |     StyleButtons = getGridControlButtons() | ||||||
|  |     screen.SetContentList(0, StyleButtons) | ||||||
|  |     for i = 1 to categoryList.count()-1 | ||||||
|  |         screen.SetContentList(i, getShowsForCategoryItem(categoryList[i])) | ||||||
|  |     end for | ||||||
|  |     screen.Show() | ||||||
|  |  | ||||||
|  |     while true | ||||||
|  |         print "Waiting for message" | ||||||
|  |         msg = wait(0, m.port) | ||||||
|  |         'msg = wait(0, screen.GetMessagePort())     ' getmessageport does not work on gridscreen | ||||||
|  |         print "Got Message:";type(msg) | ||||||
|  |         if type(msg) = "roGridScreenEvent" then | ||||||
|  |             print "msg= "; msg.GetMessage() " , index= "; msg.GetIndex(); " data= "; msg.getData() | ||||||
|  |             if msg.isListItemFocused() then | ||||||
|  |                 print"list item focused | current show = "; msg.GetIndex() | ||||||
|  |             else if msg.isListItemSelected() then | ||||||
|  |                 row = msg.GetIndex() | ||||||
|  |                 selection = msg.getData() | ||||||
|  |                 print "list item selected row= "; row; " selection= "; selection | ||||||
|  |  | ||||||
|  |                 ' Did we get a selection from the gridstyle selection row? | ||||||
|  |                 if (row = 0) | ||||||
|  |                     ' yes, return so we can come back with new style | ||||||
|  |                     return StyleButtons[selection].Title | ||||||
|  |                 endif | ||||||
|  |  | ||||||
|  |                 'm.curShow = displayShowDetailScreen(showList[msg.GetIndex()]) | ||||||
|  |             else if msg.isScreenClosed() then | ||||||
|  |                 return "" | ||||||
|  |             end if | ||||||
|  |         end If | ||||||
|  |     end while | ||||||
|  |  | ||||||
|  |  | ||||||
|  | End Function | ||||||
|  |  | ||||||
|  | '********************************************************** | ||||||
|  | '** When a poster on the home screen is selected, we call | ||||||
|  | '** this function passing an roAssociativeArray with the  | ||||||
|  | '** ContentMetaData for the selected show.  This data should  | ||||||
|  | '** be sufficient for the springboard to display | ||||||
|  | '********************************************************** | ||||||
|  | Function displayShowDetailScreen(category as Object, showIndex as Integer) As Integer | ||||||
|  |  | ||||||
|  |     'add code to create springboard, for now we do nothing | ||||||
|  |     return 1 | ||||||
|  |  | ||||||
|  | End Function | ||||||
|  |  | ||||||
|  |  | ||||||
|  | '************************************************************** | ||||||
|  | '** Return the list of categories to display in the filter | ||||||
|  | '** banner. The result is an roArray containing the names of  | ||||||
|  | '** all of the categories. All just static data for the example. | ||||||
|  | '*************************************************************** | ||||||
|  | Function getCategoryList() As Object | ||||||
|  |  | ||||||
|  |     categoryList = [ "GridStyle", "Reality", "History", "News", "Comedy", "Drama"] | ||||||
|  |     return categoryList | ||||||
|  |  | ||||||
|  | End Function | ||||||
|  |  | ||||||
|  |  | ||||||
|  | '******************************************************************** | ||||||
|  | '** Given the category from the filter banner, return an array  | ||||||
|  | '** of ContentMetaData objects (roAssociativeArray's) representing  | ||||||
|  | '** the shows for the category. For this example, we just cheat and | ||||||
|  | '** create and return a static array with just the minimal items | ||||||
|  | '** set, but ideally, you'd go to a feed service, fetch and parse | ||||||
|  | '** this data dynamically, so content for each category is dynamic | ||||||
|  | '******************************************************************** | ||||||
|  | Function getShowsForCategoryItem(category As Object) As Object | ||||||
|  |  | ||||||
|  |     print "getting shows for category "; category | ||||||
|  |  | ||||||
|  |     showList = [ | ||||||
|  |         { | ||||||
|  |             Title: category + ": Header", | ||||||
|  |             releaseDate: "1976", | ||||||
|  |             length: 3600-600, | ||||||
|  |             Description:"This row is category " + category, | ||||||
|  |             hdBranded: true, | ||||||
|  |             HDPosterUrl:"http://upload.wikimedia.org/wikipedia/commons/4/43/Gold_star_on_blue.gif", | ||||||
|  |             SDPosterUrl:"http://upload.wikimedia.org/wikipedia/commons/4/43/Gold_star_on_blue.gif", | ||||||
|  |             Description:"Short Synopsis #1", | ||||||
|  |             Synopsis:"Length", | ||||||
|  |             StarRating:10, | ||||||
|  |         } | ||||||
|  |         { | ||||||
|  |             Title: category + ": Beverly Hillbillies", | ||||||
|  |             releaseDate: "1969", | ||||||
|  |             rating: "PG", | ||||||
|  |             Description:"Come and listen to a story about a man named Jed: Poor mountaineer, barely kept his family fed. Then one day he was shootin at some food, and up through the ground came a bubblin crude. Oil that is, black gold, Texas tea.", | ||||||
|  |             numEpisodes:42, | ||||||
|  |             contentType:"season", | ||||||
|  |             HDPosterUrl:"http://upload.wikimedia.org/wikipedia/en/4/4e/The_Beverly_Hillbillies.jpg", | ||||||
|  |             SDPosterUrl:"http://upload.wikimedia.org/wikipedia/en/4/4e/The_Beverly_Hillbillies.jpg", | ||||||
|  |             StarRating:80, | ||||||
|  |             UserStarRating:40 | ||||||
|  |         } | ||||||
|  |         { | ||||||
|  |             Title: category + ": Babylon 5", | ||||||
|  |             releaseDate: "1996", | ||||||
|  |             rating: "PG", | ||||||
|  |             Description:"The show centers on the Babylon 5 space station: a focal point for politics, diplomacy, and conflict during the years 2257-2262.", | ||||||
|  |             numEpisodes:102, | ||||||
|  |             contentType:"season", | ||||||
|  |             HDPosterUrl:"http://upload.wikimedia.org/wikipedia/en/9/9d/Smb5-s4.jpg", | ||||||
|  |             SDPosterUrl:"http://upload.wikimedia.org/wikipedia/en/9/9d/Smb5-s4.jpg", | ||||||
|  |             StarRating:80, | ||||||
|  |             UserStarRating:40 | ||||||
|  |         } | ||||||
|  |         { | ||||||
|  |             Title: category + ": John F. Kennedy", | ||||||
|  |             releaseDate: "1961", | ||||||
|  |             rating: "PG", | ||||||
|  |             Description:"My fellow citizens of the world: ask not what America will do for you, but what together we can do for the freedom of man.", | ||||||
|  |             HDPosterUrl:"http://upload.wikimedia.org/wikipedia/en/5/52/Jfk_happy_birthday_1.jpg", | ||||||
|  |             SDPosterUrl:"http://upload.wikimedia.org/wikipedia/en/5/52/Jfk_happy_birthday_1.jpg", | ||||||
|  |             StarRating:100 | ||||||
|  |         } | ||||||
|  |         { | ||||||
|  |             Title: category + ": Man on the Moon", | ||||||
|  |             releaseDate: "1969", | ||||||
|  |             rating: "PG", | ||||||
|  |             Description:"That's one small step for a man, one giant leap for mankind.", | ||||||
|  |             HDPosterUrl:"http://upload.wikimedia.org/wikipedia/commons/1/1e/Apollo_11_first_step.jpg", | ||||||
|  |             SDPosterUrl:"http://upload.wikimedia.org/wikipedia/commons/1/1e/Apollo_11_first_step.jpg", | ||||||
|  |             StarRating:100 | ||||||
|  |         } | ||||||
|  |         { | ||||||
|  |             Title: category + ": I have a Dream", | ||||||
|  |             releaseDate: "1963", | ||||||
|  |             rating: "PG", | ||||||
|  |             Description:"I have a dream that my four little children will one day live in a nation where they will not be judged by the color of their skin, but by the content of their character.", | ||||||
|  |             HDPosterUrl:"http://upload.wikimedia.org/wikipedia/commons/8/81/Martin_Luther_King_-_March_on_Washington.jpg", | ||||||
|  |             SDPosterUrl:"http://upload.wikimedia.org/wikipedia/commons/8/81/Martin_Luther_King_-_March_on_Washington.jpg", | ||||||
|  |             StarRating:100 | ||||||
|  |         } | ||||||
|  |     ] | ||||||
|  |  | ||||||
|  |     return showList | ||||||
|  | End Function | ||||||
|  |      | ||||||
|  | function getGridControlButtons() as object | ||||||
|  |         buttons = [ | ||||||
|  |             { Title: "Flat-Movie" | ||||||
|  |               ReleaseDate: "HD:5x2 SD:5x2" | ||||||
|  |               Description: "Flat-Movie (Netflix) style" | ||||||
|  |               HDPosterUrl:"http://upload.wikimedia.org/wikipedia/commons/4/43/Gold_star_on_blue.gif" | ||||||
|  |               SDPosterUrl:"http://upload.wikimedia.org/wikipedia/commons/4/43/Gold_star_on_blue.gif" | ||||||
|  |             } | ||||||
|  |             { Title: "Flat-Landscape" | ||||||
|  |               ReleaseDate: "HD:5x3 SD:4x3" | ||||||
|  |               Description: "Channel Store" | ||||||
|  |               HDPosterUrl:"http://upload.wikimedia.org/wikipedia/commons/thumb/9/96/Dunkery_Hill.jpg/800px-Dunkery_Hill.jpg", | ||||||
|  |               SDPosterUrl:"http://upload.wikimedia.org/wikipedia/commons/thumb/9/96/Dunkery_Hill.jpg/800px-Dunkery_Hill.jpg", | ||||||
|  |             } | ||||||
|  |             { Title: "Flat-Portrait" | ||||||
|  |               ReleaseDate: "HD:5x2 SD:5x2" | ||||||
|  |               Description: "3x4 style posters" | ||||||
|  |               HDPosterUrl:"http://upload.wikimedia.org/wikipedia/commons/9/9f/Kane_George_Gurnett.jpg", | ||||||
|  |               SDPosterUrl:"http://upload.wikimedia.org/wikipedia/commons/9/9f/Kane_George_Gurnett.jpg", | ||||||
|  |             } | ||||||
|  |             { Title: "Flat-Square" | ||||||
|  |               ReleaseDate: "HD:7x3 SD:6x3" | ||||||
|  |               Description: "1x1 style posters" | ||||||
|  |               HDPosterUrl:"http://upload.wikimedia.org/wikipedia/commons/thumb/d/de/SQUARE_SHAPE.svg/536px-SQUARE_SHAPE.svg.png", | ||||||
|  |               SDPosterUrl:"http://upload.wikimedia.org/wikipedia/commons/thumb/d/de/SQUARE_SHAPE.svg/536px-SQUARE_SHAPE.svg.png", | ||||||
|  |             } | ||||||
|  |             { Title: "Flat-16x9" | ||||||
|  |               ReleaseDate: "HD:5x3 SD:4x3" | ||||||
|  |               Description: "HD style posters" | ||||||
|  |               HDPosterUrl:"http://upload.wikimedia.org/wikipedia/commons/thumb/2/22/%C3%89cran_TV_plat.svg/200px-%C3%89cran_TV_plat.svg.png", | ||||||
|  |               SDPosterUrl:"http://upload.wikimedia.org/wikipedia/commons/thumb/2/22/%C3%89cran_TV_plat.svg/200px-%C3%89cran_TV_plat.svg.png", | ||||||
|  |             } | ||||||
|  |        ] | ||||||
|  |        return buttons | ||||||
|  | End Function | ||||||
							
								
								
									
										45
									
								
								samples/C#/Index.cshtml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										45
									
								
								samples/C#/Index.cshtml
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,45 @@ | |||||||
|  | @{ | ||||||
|  |     ViewBag.Title = "Home Page"; | ||||||
|  | } | ||||||
|  | @section featured { | ||||||
|  |     <section class="featured"> | ||||||
|  |         <div class="content-wrapper"> | ||||||
|  |             <hgroup class="title"> | ||||||
|  |                 <h1>@ViewBag.Title.</h1> | ||||||
|  |                 <h2>@ViewBag.Message</h2> | ||||||
|  |             </hgroup> | ||||||
|  |             <p> | ||||||
|  |                 To learn more about ASP.NET MVC visit | ||||||
|  |                 <a href="http://asp.net/mvc" title="ASP.NET MVC Website">http://asp.net/mvc</a>. | ||||||
|  |                 The page features <mark>videos, tutorials, and samples</mark> to help you get the most from ASP.NET MVC. | ||||||
|  |                 If you have any questions about ASP.NET MVC visit | ||||||
|  |                 <a href="http://forums.asp.net/1146.aspx/1?MVC" title="ASP.NET MVC Forum">our forums</a>. | ||||||
|  |             </p> | ||||||
|  |         </div> | ||||||
|  |     </section> | ||||||
|  | } | ||||||
|  | <h3>We suggest the following:</h3> | ||||||
|  | <ol class="round"> | ||||||
|  |     <li class="one"> | ||||||
|  |         <h5>Getting Started</h5> | ||||||
|  |         ASP.NET MVC gives you a powerful, patterns-based way to build dynamic websites that | ||||||
|  |         enables a clean separation of concerns and that gives you full control over markup | ||||||
|  |         for enjoyable, agile development. ASP.NET MVC includes many features that enable | ||||||
|  |         fast, TDD-friendly development for creating sophisticated applications that use | ||||||
|  |         the latest web standards. | ||||||
|  |         <a href="http://go.microsoft.com/fwlink/?LinkId=245151">Learn more…</a> | ||||||
|  |     </li> | ||||||
|  |  | ||||||
|  |     <li class="two"> | ||||||
|  |         <h5>Add NuGet packages and jump-start your coding</h5> | ||||||
|  |         NuGet makes it easy to install and update free libraries and tools. | ||||||
|  |         <a href="http://go.microsoft.com/fwlink/?LinkId=245153">Learn more…</a> | ||||||
|  |     </li> | ||||||
|  |  | ||||||
|  |     <li class="three"> | ||||||
|  |         <h5>Find Web Hosting</h5> | ||||||
|  |         You can easily find a web hosting company that offers the right mix of features | ||||||
|  |         and price for your applications. | ||||||
|  |         <a href="http://go.microsoft.com/fwlink/?LinkId=245157">Learn more…</a> | ||||||
|  |     </li> | ||||||
|  | </ol> | ||||||
							
								
								
									
										21
									
								
								samples/C#/Program.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										21
									
								
								samples/C#/Program.cs
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,21 @@ | |||||||
|  | using System; | ||||||
|  | using System.Collections.Generic; | ||||||
|  | using System.Linq; | ||||||
|  | using System.Text; | ||||||
|  | using System.Threading.Tasks; | ||||||
|  |  | ||||||
|  | namespace LittleSampleApp | ||||||
|  | { | ||||||
|  |   /// <summary> | ||||||
|  |   /// Just what it says on the tin. A little sample application for Linguist to try out. | ||||||
|  |   ///  | ||||||
|  |   /// </summary> | ||||||
|  |   class Program | ||||||
|  |   { | ||||||
|  |     static void Main(string[] args) | ||||||
|  |     { | ||||||
|  |       Console.WriteLine("Hello, I am a little sample application to test GitHub's Linguist module."); | ||||||
|  |       Console.WriteLine("I also include a Razor MVC file just to prove it handles cshtml files now."); | ||||||
|  |     } | ||||||
|  |   } | ||||||
|  | } | ||||||
							
								
								
									
										42
									
								
								samples/C++/CsvStreamer.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										42
									
								
								samples/C++/CsvStreamer.h
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,42 @@ | |||||||
|  | #pragma once | ||||||
|  | #include <string> | ||||||
|  | #include <vector> | ||||||
|  | #include <fstream> | ||||||
|  | #include "util.h" | ||||||
|  |  | ||||||
|  | using namespace std; | ||||||
|  |  | ||||||
|  |  | ||||||
|  | #define DEFAULT_DELIMITER	',' | ||||||
|  |  | ||||||
|  |  | ||||||
|  | class CsvStreamer | ||||||
|  | { | ||||||
|  | 	private: | ||||||
|  | 		ofstream file;				// File output stream | ||||||
|  | 		vector<string> row_buffer;	// Buffer which stores a row's data before being flushed/written | ||||||
|  | 		int fields;					// Number of fields (columns) | ||||||
|  | 		long rows;					// Number of rows (records) including header row | ||||||
|  | 		char delimiter;				// Delimiter character; comma by default | ||||||
|  | 		string sanitize(string);	// Returns a string ready for output into the file | ||||||
|  | 		 | ||||||
|  | 	public: | ||||||
|  | 		CsvStreamer();				// Empty CSV streamer... be sure to open the file before writing! | ||||||
|  | 		CsvStreamer(string, char);	// Same as open(string, char)... | ||||||
|  | 		CsvStreamer(string);		// Opens an output CSV file given a file path/name | ||||||
|  | 		~CsvStreamer();				// Ensures the output file is closed and saved | ||||||
|  | 		void open(string);			// Opens an output CSV file given a file path/name (default delimiter) | ||||||
|  | 		void open(string, char);	// Opens an output CSV file given a file path/name and a delimiting character (default comma) | ||||||
|  | 		void add_field(string);		// If still on first line, adds a new field to the header row | ||||||
|  | 		void save_fields();			// Call this to save the header row; all new writes should be through append() | ||||||
|  | 		void append(string);		// Appends the current row with this data for the next field; quoted only if needed (leading/trailing spaces are trimmed) | ||||||
|  | 		void append(string, bool);	// Like append(string) but can specify whether to trim spaces at either end of the data (false to keep spaces) | ||||||
|  | 		void append(float);			// Appends the current row with this number | ||||||
|  | 		void append(double);		// Appends the current row with this number | ||||||
|  | 		void append(long);			// Appends the current row with this number | ||||||
|  | 		void append(int);			// Appends the current row with this number | ||||||
|  | 		void writeln();				// Flushes what was in the row buffer into the file (writes the row) | ||||||
|  | 		void close();				// Saves and closes the file | ||||||
|  | 		int field_count();			// Gets the number of fields (columns) | ||||||
|  | 		long row_count();			// Gets the number of records (rows) -- NOT including the header row | ||||||
|  | }; | ||||||
							
								
								
									
										32
									
								
								samples/C++/Field.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										32
									
								
								samples/C++/Field.h
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,32 @@ | |||||||
|  | /***************************************************************************** | ||||||
|  | * Dwarf Mine - The 13-11 Benchmark | ||||||
|  | * | ||||||
|  | * Copyright (c) 2013 Bünger, Thomas; Kieschnick, Christian; Kusber, | ||||||
|  | * Michael; Lohse, Henning; Wuttke, Nikolai; Xylander, Oliver; Yao, Gary; | ||||||
|  | * Zimmermann, Florian | ||||||
|  | * | ||||||
|  | * 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. | ||||||
|  | *****************************************************************************/ | ||||||
|  |  | ||||||
|  | #pragma once | ||||||
|  |  | ||||||
|  | enum Field { Free, Black, White, Illegal }; | ||||||
|  |  | ||||||
|  | typedef Field Player; | ||||||
							
								
								
									
										32
									
								
								samples/C++/Types.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										32
									
								
								samples/C++/Types.h
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,32 @@ | |||||||
|  | /***************************************************************************** | ||||||
|  | * Dwarf Mine - The 13-11 Benchmark | ||||||
|  | * | ||||||
|  | * Copyright (c) 2013 Bünger, Thomas; Kieschnick, Christian; Kusber, | ||||||
|  | * Michael; Lohse, Henning; Wuttke, Nikolai; Xylander, Oliver; Yao, Gary; | ||||||
|  | * Zimmermann, Florian | ||||||
|  | * | ||||||
|  | * 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. | ||||||
|  | *****************************************************************************/ | ||||||
|  |  | ||||||
|  | #pragma once | ||||||
|  |  | ||||||
|  | #include <cstdint> | ||||||
|  |  | ||||||
|  | typedef uint32_t smallPrime_t; | ||||||
							
								
								
									
										1129
									
								
								samples/C++/bcm2835.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										1129
									
								
								samples/C++/bcm2835.h
									
									
									
									
									
										Normal file
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							| @@ -1,39 +0,0 @@ | |||||||
| void foo() |  | ||||||
| { |  | ||||||
|   cudaArray* cu_array; |  | ||||||
|   texture<float, 2, cudaReadModeElementType> tex; |  | ||||||
|  |  | ||||||
|   // Allocate array |  | ||||||
|   cudaChannelFormatDesc description = cudaCreateChannelDesc<float>(); |  | ||||||
|   cudaMallocArray(&cu_array, &description, width, height); |  | ||||||
|  |  | ||||||
|   // Copy image data to array |  | ||||||
|   cudaMemcpyToArray(cu_array, image, width*height*sizeof(float), cudaMemcpyHostToDevice); |  | ||||||
|  |  | ||||||
|   // Set texture parameters (default) |  | ||||||
|   tex.addressMode[0] = cudaAddressModeClamp; |  | ||||||
|   tex.addressMode[1] = cudaAddressModeClamp; |  | ||||||
|   tex.filterMode = cudaFilterModePoint; |  | ||||||
|   tex.normalized = false; // do not normalize coordinates |  | ||||||
|  |  | ||||||
|   // Bind the array to the texture |  | ||||||
|   cudaBindTextureToArray(tex, cu_array); |  | ||||||
|  |  | ||||||
|   // Run kernel |  | ||||||
|   dim3 blockDim(16, 16, 1); |  | ||||||
|   dim3 gridDim((width + blockDim.x - 1)/ blockDim.x, (height + blockDim.y - 1) / blockDim.y, 1); |  | ||||||
|   kernel<<< gridDim, blockDim, 0 >>>(d_data, height, width); |  | ||||||
|  |  | ||||||
|   // Unbind the array from the texture |  | ||||||
|   cudaUnbindTexture(tex); |  | ||||||
| } //end foo() |  | ||||||
|  |  | ||||||
| __global__ void kernel(float* odata, int height, int width) |  | ||||||
| { |  | ||||||
|    unsigned int x = blockIdx.x*blockDim.x + threadIdx.x; |  | ||||||
|    unsigned int y = blockIdx.y*blockDim.y + threadIdx.y; |  | ||||||
|    if (x < width && y < height) { |  | ||||||
|       float c = tex2D(tex, x, y); |  | ||||||
|       odata[y*width+x] = c; |  | ||||||
|    } |  | ||||||
| } |  | ||||||
							
								
								
									
										138
									
								
								samples/C++/libcanister.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										138
									
								
								samples/C++/libcanister.h
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,138 @@ | |||||||
|  | #ifndef LIBCANIH | ||||||
|  | #define LIBCANIH | ||||||
|  | #include <iostream> | ||||||
|  | #include <fstream> | ||||||
|  | #include <stdlib.h> | ||||||
|  | #include <cstring> | ||||||
|  |  | ||||||
|  | #define int64 unsigned long long | ||||||
|  | //#define DEBUG | ||||||
|  |  | ||||||
|  | #ifdef DEBUG | ||||||
|  | #define dout cout | ||||||
|  | #else | ||||||
|  | #define dout if (0) cerr | ||||||
|  | #endif | ||||||
|  |  | ||||||
|  | using namespace std; | ||||||
|  |  | ||||||
|  | namespace libcanister | ||||||
|  | { | ||||||
|  |  | ||||||
|  |     //the canmem object is a generic memory container used commonly | ||||||
|  |     //throughout the canister framework to hold memory of uncertain | ||||||
|  |     //length which may or may not contain null bytes.  | ||||||
|  |     class canmem | ||||||
|  |     { | ||||||
|  |     public: | ||||||
|  |         char* data; //the raw memory block | ||||||
|  |         int size; //the absolute length of the block | ||||||
|  |         canmem(); //creates an unallocated canmem | ||||||
|  |         canmem(int allocsize); //creates an allocated, blank canmem of size | ||||||
|  |         canmem(char* strdata); //automates the creation of zero-limited canmems | ||||||
|  |         ~canmem(); //cleans up the canmem | ||||||
|  |         void zeromem(); //overwrites this canmem | ||||||
|  |         void fragmem(); //overwrites this canmem with fragment notation | ||||||
|  |         void countlen(); //counts length of zero-limited strings and stores it in size | ||||||
|  |         void trim(); //removes any nulls from the end of the string | ||||||
|  |         static canmem null(); //returns a singleton null canmem | ||||||
|  |          | ||||||
|  |     }; | ||||||
|  |      | ||||||
|  |     //contains information about the canister | ||||||
|  |     class caninfo | ||||||
|  |     { | ||||||
|  |     public: | ||||||
|  |         canmem path; //physical path | ||||||
|  |         canmem internalname; //a name for the canister | ||||||
|  |         int numfiles; //the number of files in the canister | ||||||
|  |     }; | ||||||
|  |      | ||||||
|  |     //necessary for the use of this class as a type in canfile | ||||||
|  |     class canister; | ||||||
|  |      | ||||||
|  |     //this object holds the definition of a 'file' within the | ||||||
|  |     //canister 'filesystem.' | ||||||
|  |     class canfile | ||||||
|  |     { | ||||||
|  |     public: | ||||||
|  |         libcanister::canister* parent; //the canister that holds this file | ||||||
|  |         canmem path; //internal path ('filename') | ||||||
|  |         canmem data; //the file's decompressed contents | ||||||
|  |         int isfrag; //0 = probably not fragment, 1 = definitely a fragment (ignore) | ||||||
|  |         int cfid; //'canfile id' -- a unique ID for this file | ||||||
|  |         int64 dsize; //ondisk size (compressed form size) | ||||||
|  |         int cachestate; //0 = not in memory, 1 = in memory, 2 = in memory and needs flush | ||||||
|  |                         //-1 = error, check the data for the message | ||||||
|  |         void cache(); //pull the file from disk and cache it in memory | ||||||
|  |         void cachedump(); //deletes the contents of this file from the memory cache after assuring the on disk copy is up to date | ||||||
|  |         void cachedumpfinal(fstream& infile); //same as cachedump, but more efficient during closing procedures | ||||||
|  |         void flush(); //updates the on disk copy, but retains the memory cache | ||||||
|  |     }; | ||||||
|  |  | ||||||
|  |     //the primary class | ||||||
|  |     //this defines and controls a single canister | ||||||
|  |     class canister | ||||||
|  |     { | ||||||
|  |         //table of contents | ||||||
|  |         //absolutely worthless to the control code in the canister | ||||||
|  |         //but quite useful to programs using the API, as they may | ||||||
|  |         //desire to enumerate the files in a canister for a user's | ||||||
|  |         //use or for their own. | ||||||
|  |         //contains a newline-delimited list of files in the container. | ||||||
|  |         canfile TOC; | ||||||
|  |     public: | ||||||
|  |         caninfo info; //the general info about this canister | ||||||
|  |  | ||||||
|  |         //the raw canfiles -- recommended that programs do not modify | ||||||
|  |         //these files directly, but not enforced. | ||||||
|  |         canfile* files; | ||||||
|  |         bool readonly; //if true then no write routines will do anything | ||||||
|  |          | ||||||
|  |         //maximum number of files to have in memory at any given | ||||||
|  |         //time, change this to whatever suits your application. | ||||||
|  |         int cachemax; | ||||||
|  |         int cachecnt; //number of files in the cache (should not be modified) | ||||||
|  |  | ||||||
|  |         //both initialize the canister from a physical location | ||||||
|  |         canister (canmem fspath); | ||||||
|  |         canister (char* fspath); | ||||||
|  |  | ||||||
|  |         //destroys the canister (after flushing the modded buffers, of course) | ||||||
|  |         ~canister(); | ||||||
|  |          | ||||||
|  |         //open the fspath | ||||||
|  |         //does it exist? | ||||||
|  |         // | --- yes --- opening it (return 1) | ||||||
|  |         // | --- yes --- file is corrupted, halting (return -1) | ||||||
|  |         // | --- no  --- making a new one (return 0) | ||||||
|  |         int open(); | ||||||
|  |          | ||||||
|  |         //close the canister, flush all buffers, clean up | ||||||
|  |         int close(); | ||||||
|  |          | ||||||
|  |         //deletes the file at path inside this canister | ||||||
|  |         int delFile(canmem path); | ||||||
|  |          | ||||||
|  |         //pulls the contents of the file from disk or memory and returns it as a file | ||||||
|  |         canfile getFile(canmem path); | ||||||
|  |          | ||||||
|  |         //creates a file if it does not exist, otherwise overwrites | ||||||
|  |         //returns whether operation succeeded | ||||||
|  |         bool writeFile(canmem path, canmem data); | ||||||
|  |         bool writeFile(canfile file); | ||||||
|  |          | ||||||
|  |         //get the 'table of contents', a file containing a newline delimited | ||||||
|  |         //list of the file paths in the container which have contents | ||||||
|  |         canfile getTOC(); | ||||||
|  |   | ||||||
|  |         //brings the cache back within the cachemax limit | ||||||
|  |         //important: sCFID is the safe CFID | ||||||
|  |         //(the CFID of the file we want to avoid uncaching) | ||||||
|  |         //really just used internally, but it can't do any harm. | ||||||
|  |         void cacheclean(int sCFID, bool dFlush = false); | ||||||
|  |     }; | ||||||
|  |  | ||||||
|  | } | ||||||
|  |  | ||||||
|  | #endif | ||||||
							
								
								
									
										92
									
								
								samples/C++/metrics.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										92
									
								
								samples/C++/metrics.h
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,92 @@ | |||||||
|  | // Copyright 2011 Google Inc. All Rights Reserved. | ||||||
|  | // | ||||||
|  | // 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. | ||||||
|  |  | ||||||
|  | #ifndef NINJA_METRICS_H_ | ||||||
|  | #define NINJA_METRICS_H_ | ||||||
|  |  | ||||||
|  | #include <string> | ||||||
|  | #include <vector> | ||||||
|  | using namespace std; | ||||||
|  |  | ||||||
|  | #include "util.h"  // For int64_t. | ||||||
|  |  | ||||||
|  | /// The Metrics module is used for the debug mode that dumps timing stats of | ||||||
|  | /// various actions.  To use, see METRIC_RECORD below. | ||||||
|  |  | ||||||
|  | /// A single metrics we're tracking, like "depfile load time". | ||||||
|  | struct Metric { | ||||||
|  |   string name; | ||||||
|  |   /// Number of times we've hit the code path. | ||||||
|  |   int count; | ||||||
|  |   /// Total time (in micros) we've spent on the code path. | ||||||
|  |   int64_t sum; | ||||||
|  | }; | ||||||
|  |  | ||||||
|  |  | ||||||
|  | /// A scoped object for recording a metric across the body of a function. | ||||||
|  | /// Used by the METRIC_RECORD macro. | ||||||
|  | struct ScopedMetric { | ||||||
|  |   explicit ScopedMetric(Metric* metric); | ||||||
|  |   ~ScopedMetric(); | ||||||
|  |  | ||||||
|  | private: | ||||||
|  |   Metric* metric_; | ||||||
|  |   /// Timestamp when the measurement started. | ||||||
|  |   /// Value is platform-dependent. | ||||||
|  |   int64_t start_; | ||||||
|  | }; | ||||||
|  |  | ||||||
|  | /// The singleton that stores metrics and prints the report. | ||||||
|  | struct Metrics { | ||||||
|  |   Metric* NewMetric(const string& name); | ||||||
|  |  | ||||||
|  |   /// Print a summary report to stdout. | ||||||
|  |   void Report(); | ||||||
|  |  | ||||||
|  | private: | ||||||
|  |   vector<Metric*> metrics_; | ||||||
|  | }; | ||||||
|  |  | ||||||
|  | /// Get the current time as relative to some epoch. | ||||||
|  | /// Epoch varies between platforms; only useful for measuring elapsed time. | ||||||
|  | int64_t GetTimeMillis(); | ||||||
|  |  | ||||||
|  | /// A simple stopwatch which returns the time | ||||||
|  | /// in seconds since Restart() was called. | ||||||
|  | struct Stopwatch { | ||||||
|  |  public: | ||||||
|  |   Stopwatch() : started_(0) {} | ||||||
|  |  | ||||||
|  |   /// Seconds since Restart() call. | ||||||
|  |   double Elapsed() const { | ||||||
|  |     return 1e-6 * static_cast<double>(Now() - started_); | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |   void Restart() { started_ = Now(); } | ||||||
|  |  | ||||||
|  |  private: | ||||||
|  |   uint64_t started_; | ||||||
|  |   uint64_t Now() const; | ||||||
|  | }; | ||||||
|  |  | ||||||
|  | /// The primary interface to metrics.  Use METRIC_RECORD("foobar") at the top | ||||||
|  | /// of a function to get timing stats recorded for each call of the function. | ||||||
|  | #define METRIC_RECORD(name)                                             \ | ||||||
|  |   static Metric* metrics_h_metric =                                     \ | ||||||
|  |       g_metrics ? g_metrics->NewMetric(name) : NULL;                    \ | ||||||
|  |   ScopedMetric metrics_h_scoped(metrics_h_metric); | ||||||
|  |  | ||||||
|  | extern Metrics* g_metrics; | ||||||
|  |  | ||||||
|  | #endif // NINJA_METRICS_H_ | ||||||
							
								
								
									
										6
									
								
								samples/C++/render_adapter.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										6
									
								
								samples/C++/render_adapter.cpp
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,6 @@ | |||||||
|  | #include <cstdint> | ||||||
|  |  | ||||||
|  | namespace Gui | ||||||
|  | { | ||||||
|  |  | ||||||
|  | } | ||||||
							
								
								
									
										26
									
								
								samples/C++/rpc.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										26
									
								
								samples/C++/rpc.h
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,26 @@ | |||||||
|  | // Copyright (C) 2013 Simon Que | ||||||
|  | // | ||||||
|  | // This file is part of DuinoCube. | ||||||
|  | // | ||||||
|  | // DuinoCube 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. | ||||||
|  | // | ||||||
|  | // DuinoCube 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 DuinoCube.  If not, see <http://www.gnu.org/licenses/>. | ||||||
|  |  | ||||||
|  | // DuinoCube remote procedure call functions. | ||||||
|  |  | ||||||
|  | #include <stdint.h> | ||||||
|  |  | ||||||
|  | // Initializes RPC system. | ||||||
|  | void rpc_init(); | ||||||
|  |  | ||||||
|  | // Runs the RPC server loop forever. | ||||||
|  | void rpc_server_loop(); | ||||||
							
								
								
									
										102
									
								
								samples/C/bootstrap.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										102
									
								
								samples/C/bootstrap.h
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,102 @@ | |||||||
|  | #ifndef BOOTSTRAP_H | ||||||
|  | #define BOOTSTRAP_H | ||||||
|  |  | ||||||
|  | #include <stdio.h> | ||||||
|  | #include "cxrs.h" | ||||||
|  |  | ||||||
|  | /* If we're not using GNU C, elide __attribute__ */ | ||||||
|  | #ifndef __GNUC__ | ||||||
|  | #  define  __attribute__(x)  /*NOTHING*/ | ||||||
|  | #endif | ||||||
|  |  | ||||||
|  | typedef struct object object; | ||||||
|  |  | ||||||
|  | object *true; | ||||||
|  | object *false; | ||||||
|  | object *eof; | ||||||
|  | object *empty_list; | ||||||
|  | object *global_enviroment; | ||||||
|  |  | ||||||
|  | enum obj_type { | ||||||
|  |         scm_bool, | ||||||
|  |         scm_empty_list, | ||||||
|  |         scm_eof, | ||||||
|  |         scm_char, | ||||||
|  |         scm_int, | ||||||
|  |         scm_pair, | ||||||
|  |         scm_symbol, | ||||||
|  |         scm_prim_fun, | ||||||
|  |         scm_lambda, | ||||||
|  |         scm_str, | ||||||
|  |         scm_file | ||||||
|  | }; | ||||||
|  |  | ||||||
|  | typedef object *(*prim_proc)(object *args); | ||||||
|  |  | ||||||
|  | object *read(FILE *in); | ||||||
|  | object *eval(object *code, object *env); | ||||||
|  | void print(FILE *out, object *obj, int display); | ||||||
|  |  | ||||||
|  | int check_type(enum obj_type type, object *obj, int err_on_false); | ||||||
|  |  | ||||||
|  | static inline int is_true(object *obj) | ||||||
|  | { | ||||||
|  |         return obj != false; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | object *make_int(int value); | ||||||
|  | int obj2int(object *i); | ||||||
|  |  | ||||||
|  | object *make_bool(int value); | ||||||
|  | int obj2bool(object *b); | ||||||
|  |  | ||||||
|  | object *make_char(char c); | ||||||
|  | char obj2char(object *ch); | ||||||
|  |  | ||||||
|  | object *make_str(char *str); | ||||||
|  | char *obj2str(object *str); | ||||||
|  |  | ||||||
|  | object *cons(object *car, object *cdr); | ||||||
|  | object *car(object *pair); | ||||||
|  | object *cdr(object *pair); | ||||||
|  | void set_car(object *pair, object *new); | ||||||
|  | void set_cdr(object *pair, object *new); | ||||||
|  |  | ||||||
|  | object *make_symbol(char *name); | ||||||
|  | char *sym2str(object *sym); | ||||||
|  | object *get_symbol(char *name) __attribute__((pure)); | ||||||
|  |  | ||||||
|  | object *make_prim_fun(prim_proc fun); | ||||||
|  | prim_proc obj2prim_proc(object *proc); | ||||||
|  |  | ||||||
|  | object *make_lambda(object *args, object *code, object *env); | ||||||
|  | object *lambda_code(object *lambda); | ||||||
|  | object *lambda_args(object *lambda); | ||||||
|  |  | ||||||
|  | object *make_port(FILE *handle, int direction); | ||||||
|  | int port_direction(object *port); | ||||||
|  | FILE *port_handle(object *port); | ||||||
|  | void set_port_handle_to_null(object *port); | ||||||
|  |  | ||||||
|  | /*both of these should never be called*/ | ||||||
|  | object *apply_proc(object *); | ||||||
|  | object *eval_proc(object *); | ||||||
|  |  | ||||||
|  |  | ||||||
|  | object *maybe_add_begin(object *code); | ||||||
|  |  | ||||||
|  | void init_enviroment(object *env); | ||||||
|  |  | ||||||
|  |  | ||||||
|  | void eval_err(char *msg, object *code) __attribute__((noreturn)); | ||||||
|  |  | ||||||
|  | void define_var(object *var, object *val, object *env); | ||||||
|  | void set_var(object *var, object *val, object *env); | ||||||
|  | object *get_var(object *var, object *env); | ||||||
|  |  | ||||||
|  | object *cond2nested_if(object *cond); | ||||||
|  | object *let2lambda(object *let); | ||||||
|  | object *and2nested_if(object *and); | ||||||
|  | object *or2nested_if(object *or); | ||||||
|  |  | ||||||
|  | #endif /*include guard*/ | ||||||
							
								
								
									
										61
									
								
								samples/C/jni_layer.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										61
									
								
								samples/C/jni_layer.h
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,61 @@ | |||||||
|  | /* DO NOT EDIT THIS FILE - it is machine generated */ | ||||||
|  | #include <jni.h> | ||||||
|  | /* Header for class jni_JniLayer */ | ||||||
|  |  | ||||||
|  | #ifndef _Included_jni_JniLayer | ||||||
|  | #define _Included_jni_JniLayer | ||||||
|  | #ifdef __cplusplus | ||||||
|  | extern "C" { | ||||||
|  | #endif | ||||||
|  | /* | ||||||
|  |  * Class:     jni_JniLayer | ||||||
|  |  * Method:    jni_layer_initialize | ||||||
|  |  * Signature: ([II)J | ||||||
|  |  */ | ||||||
|  | JNIEXPORT jlong JNICALL Java_jni_JniLayer_jni_1layer_1initialize | ||||||
|  |   (JNIEnv *, jobject, jintArray, jint, jint); | ||||||
|  |  | ||||||
|  | /* | ||||||
|  |  * Class:     jni_JniLayer | ||||||
|  |  * Method:    jni_layer_mainloop | ||||||
|  |  * Signature: (J)V | ||||||
|  |  */ | ||||||
|  | JNIEXPORT void JNICALL Java_jni_JniLayer_jni_1layer_1mainloop | ||||||
|  |   (JNIEnv *, jobject, jlong); | ||||||
|  |  | ||||||
|  | /* | ||||||
|  |  * Class:     jni_JniLayer | ||||||
|  |  * Method:    jni_layer_set_button | ||||||
|  |  * Signature: (JII)V | ||||||
|  |  */ | ||||||
|  | JNIEXPORT void JNICALL Java_jni_JniLayer_jni_1layer_1set_1button | ||||||
|  |   (JNIEnv *, jobject, jlong, jint, jint); | ||||||
|  |  | ||||||
|  | /* | ||||||
|  |  * Class:     jni_JniLayer | ||||||
|  |  * Method:    jni_layer_set_analog | ||||||
|  |  * Signature: (JIIF)V | ||||||
|  |  */ | ||||||
|  | JNIEXPORT void JNICALL Java_jni_JniLayer_jni_1layer_1set_1analog | ||||||
|  |   (JNIEnv *, jobject, jlong, jint, jint, jfloat); | ||||||
|  |  | ||||||
|  | /* | ||||||
|  |  * Class:     jni_JniLayer | ||||||
|  |  * Method:    jni_layer_report_analog_chg | ||||||
|  |  * Signature: (JI)V | ||||||
|  |  */ | ||||||
|  | JNIEXPORT void JNICALL Java_jni_JniLayer_jni_1layer_1report_1analog_1chg | ||||||
|  |   (JNIEnv *, jobject, jlong, jint); | ||||||
|  |  | ||||||
|  | /* | ||||||
|  |  * Class:     jni_JniLayer | ||||||
|  |  * Method:    jni_layer_kill | ||||||
|  |  * Signature: (J)V | ||||||
|  |  */ | ||||||
|  | JNIEXPORT void JNICALL Java_jni_JniLayer_jni_1layer_1kill | ||||||
|  |   (JNIEnv *, jobject, jlong); | ||||||
|  |  | ||||||
|  | #ifdef __cplusplus | ||||||
|  | } | ||||||
|  | #endif | ||||||
|  | #endif | ||||||
							
								
								
									
										5
									
								
								samples/C/syscalldefs.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										5
									
								
								samples/C/syscalldefs.h
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,5 @@ | |||||||
|  | static const syscalldef syscalldefs[] = { | ||||||
|  |         [SYSCALL_OR_NUM(0, SYS_restart_syscall)]        = MAKE_UINT16(0, 1), | ||||||
|  |         [SYSCALL_OR_NUM(1, SYS_exit)]         = MAKE_UINT16(1, 17), | ||||||
|  |         [SYSCALL_OR_NUM(2, SYS_fork)]         = MAKE_UINT16(0, 22), | ||||||
|  | }; | ||||||
							
								
								
									
										5
									
								
								samples/COBOL/hello_world.cbl
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										5
									
								
								samples/COBOL/hello_world.cbl
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,5 @@ | |||||||
|  |         program-id. hello. | ||||||
|  |         procedure division. | ||||||
|  |         display "Hello, World!". | ||||||
|  |         stop run. | ||||||
|  |  | ||||||
							
								
								
									
										6
									
								
								samples/COBOL/hello_world.ccp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										6
									
								
								samples/COBOL/hello_world.ccp
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,6 @@ | |||||||
|  |       IDENTIFICATION DIVISION. | ||||||
|  |       PROGRAM-ID. hello. | ||||||
|  |       PROCEDURE DIVISION. | ||||||
|  |       DISPLAY "Hello World, yet again.". | ||||||
|  |       STOP RUN. | ||||||
|  |  | ||||||
							
								
								
									
										6
									
								
								samples/COBOL/hello_world.cob
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										6
									
								
								samples/COBOL/hello_world.cob
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,6 @@ | |||||||
|  |       IDENTIFICATION DIVISION. | ||||||
|  |       PROGRAM-ID. hello. | ||||||
|  |       PROCEDURE DIVISION. | ||||||
|  |       DISPLAY "Hello World!". | ||||||
|  |       STOP RUN. | ||||||
|  |  | ||||||
							
								
								
									
										7
									
								
								samples/COBOL/simple.cpy
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										7
									
								
								samples/COBOL/simple.cpy
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,7 @@ | |||||||
|  | 01 COBOL-TEST-RECORD. | ||||||
|  |   05 COBOL-TEST-USAGES. | ||||||
|  |     10 COBOL-4-COMP PIC S9(4) COMP. | ||||||
|  |     10 COBOL-8-COMP PIC S9(8) COMP. | ||||||
|  |     10 COBOL-9-COMP PIC S9(9) COMP. | ||||||
|  |     10 COBOL-4-COMP2 PIC S9(4) COMP-2. | ||||||
|  |     10 COBOL-7-COMP2 PIC 9(7) COMP-2. | ||||||
							
								
								
									
										6307
									
								
								samples/CSS/bootstrap.css
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										6307
									
								
								samples/CSS/bootstrap.css
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							
							
								
								
									
										873
									
								
								samples/CSS/bootstrap.min.css
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										873
									
								
								samples/CSS/bootstrap.min.css
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
										
											
												File diff suppressed because one or more lines are too long
											
										
									
								
							
							
								
								
									
										17
									
								
								samples/Clojure/for.clj
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										17
									
								
								samples/Clojure/for.clj
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,17 @@ | |||||||
|  | (defn prime? [n] | ||||||
|  |    (not-any? zero? (map #(rem n %) (range 2 n)))) | ||||||
|  |  | ||||||
|  | (range 3 33 2) | ||||||
|  | '(3 5 7 9 11 13 15 17 19 21 23 25 27 29 31) | ||||||
|  |  | ||||||
|  | ;; :when continues through the collection even if some have the | ||||||
|  | ;; condition evaluate to false, like filter | ||||||
|  | (for [x (range 3 33 2) :when (prime? x)] | ||||||
|  |    x) | ||||||
|  | '(3 5 7 11 13 17 19 23 29 31) | ||||||
|  |  | ||||||
|  | ;; :while stops at the first collection element that evaluates to | ||||||
|  | ;; false, like take-while | ||||||
|  | (for [x (range 3 33 2) :while (prime? x)] | ||||||
|  |    x) | ||||||
|  | '(3 5 7) | ||||||
							
								
								
									
										8
									
								
								samples/Clojure/hiccup.hic
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										8
									
								
								samples/Clojure/hiccup.hic
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,8 @@ | |||||||
|  | [:html | ||||||
|  |  [:head | ||||||
|  |   [:meta {:charset "utf-8"}] | ||||||
|  |   [:link {:rel "stylesheet" :href "css/bootstrap.min.css"}] | ||||||
|  |   [:script {:src "app.js"}]] | ||||||
|  |  [:body | ||||||
|  |   [:div.nav | ||||||
|  |    [:p "Hello world!"]]]] | ||||||
							
								
								
									
										13
									
								
								samples/Clojure/into-array.cljc
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										13
									
								
								samples/Clojure/into-array.cljc
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,13 @@ | |||||||
|  | (defn into-array | ||||||
|  |   ([aseq] | ||||||
|  |      (into-array nil aseq)) | ||||||
|  |   ([type aseq] | ||||||
|  |      (let [n (count aseq) | ||||||
|  |            a (make-array n)] | ||||||
|  |        (loop [aseq (seq aseq) | ||||||
|  |               i 0] | ||||||
|  |          (if (< i n) | ||||||
|  |            (do | ||||||
|  |              (aset a i (first aseq)) | ||||||
|  |              (recur (next aseq) (inc i))) | ||||||
|  |            a))))) | ||||||
							
								
								
									
										15
									
								
								samples/Clojure/protocol.cljs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										15
									
								
								samples/Clojure/protocol.cljs
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,15 @@ | |||||||
|  | (defprotocol ISound (sound [])) | ||||||
|  |   | ||||||
|  | (deftype Cat [] | ||||||
|  |   ISound | ||||||
|  |   (sound [_] "Meow!")) | ||||||
|  |   | ||||||
|  | (deftype Dog [] | ||||||
|  |   ISound | ||||||
|  |   (sound [_] "Woof!")) | ||||||
|  |   | ||||||
|  | (extend-type default | ||||||
|  |   ISound | ||||||
|  |   (sound [_] "... silence ...")) | ||||||
|  |   | ||||||
|  | (sound 1) ;; => "... silence ..." | ||||||
							
								
								
									
										5
									
								
								samples/Clojure/rand.cljscm
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										5
									
								
								samples/Clojure/rand.cljscm
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,5 @@ | |||||||
|  | (defn rand | ||||||
|  |   "Returns a random floating point number between 0 (inclusive) and | ||||||
|  |   n (default 1) (exclusive)." | ||||||
|  |   ([] (scm* [n] (random-real))) | ||||||
|  |   ([n] (* (rand) n))) | ||||||
							
								
								
									
										20
									
								
								samples/Clojure/svg.cljx
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										20
									
								
								samples/Clojure/svg.cljx
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,20 @@ | |||||||
|  | ^:clj (ns c2.svg | ||||||
|  |         (:use [c2.core :only [unify]] | ||||||
|  |               [c2.maths :only [Pi Tau radians-per-degree | ||||||
|  |                                sin cos mean]])) | ||||||
|  |  | ||||||
|  | ^:cljs (ns c2.svg | ||||||
|  |          (:use [c2.core :only [unify]] | ||||||
|  |                [c2.maths :only [Pi Tau radians-per-degree | ||||||
|  |                                 sin cos mean]]) | ||||||
|  |          (:require [c2.dom :as dom])) | ||||||
|  |  | ||||||
|  | ;;Stub for float fn, which does not exist on cljs runtime | ||||||
|  | ^:cljs (def float identity) | ||||||
|  |  | ||||||
|  | (defn ->xy | ||||||
|  |   "Convert coordinates (potentially map of `{:x :y}`) to 2-vector." | ||||||
|  |   [coordinates] | ||||||
|  |   (cond | ||||||
|  |    (and (vector? coordinates) (= 2 (count coordinates))) coordinates | ||||||
|  |    (map? coordinates) [(:x coordinates) (:y coordinates)])) | ||||||
							
								
								
									
										20
									
								
								samples/Clojure/unit-test.cl2
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										20
									
								
								samples/Clojure/unit-test.cl2
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,20 @@ | |||||||
|  | (deftest function-tests | ||||||
|  |   (is (= 3 | ||||||
|  |          (count [1 2 3]))) | ||||||
|  |   (is (= false | ||||||
|  |          (not true))) | ||||||
|  |   (is (= true | ||||||
|  |          (contains? {:foo 1 :bar 2} :foo))) | ||||||
|  |  | ||||||
|  |   (is (= {"foo" 1, "baz" 3} | ||||||
|  |          (select-keys {:foo 1 :bar 2 :baz 3} [:foo :baz]))) | ||||||
|  |  | ||||||
|  |   (is (= [1 2 3] | ||||||
|  |          (vals {:foo 1 :bar 2 :baz 3}))) | ||||||
|  |  | ||||||
|  |   (is (= ["foo" "bar" "baz"] | ||||||
|  |          (keys {:foo 1 :bar 2 :baz 3}))) | ||||||
|  |  | ||||||
|  |   (is (= [2 4 6] | ||||||
|  |          (filter (fn [x] (=== (rem x 2) 0)) [1 2 3 4 5 6])))) | ||||||
|  |  | ||||||
							
								
								
									
										21
									
								
								samples/Common Lisp/sample.lisp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										21
									
								
								samples/Common Lisp/sample.lisp
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,21 @@ | |||||||
|  | ;;;; -*- lisp -*- | ||||||
|  |  | ||||||
|  | (in-package :foo) | ||||||
|  |  | ||||||
|  | ;;; Header comment. | ||||||
|  | (defvar *foo*) | ||||||
|  |  | ||||||
|  | (eval-when (:execute :compile-toplevel :load-toplevel) | ||||||
|  |   (defun add (x &optional y &key z) | ||||||
|  |     (declare (ignore z)) | ||||||
|  |     ;; Inline comment. | ||||||
|  |     (+ x (or y 1)))) | ||||||
|  |  | ||||||
|  | #| | ||||||
|  | Multi-line comment. | ||||||
|  | |# | ||||||
|  |  | ||||||
|  | (defmacro foo (x &body b) | ||||||
|  |   (if x | ||||||
|  |       `(1+ ,x)   ;After-line comment. | ||||||
|  |       42)) | ||||||
							
								
								
									
										47
									
								
								samples/Creole/creole.creole
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										47
									
								
								samples/Creole/creole.creole
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,47 @@ | |||||||
|  | = Creole | ||||||
|  |  | ||||||
|  | Creole is a Creole-to-HTML converter for Creole, the lightweight markup | ||||||
|  | language (http://wikicreole.org/). Github uses this converter to render *.creole files. | ||||||
|  |  | ||||||
|  | Project page on github: | ||||||
|  |  | ||||||
|  | * http://github.com/minad/creole | ||||||
|  |  | ||||||
|  | Travis-CI: | ||||||
|  |  | ||||||
|  | * https://travis-ci.org/minad/creole | ||||||
|  |  | ||||||
|  | RDOC: | ||||||
|  |  | ||||||
|  | * http://rdoc.info/projects/minad/creole | ||||||
|  |  | ||||||
|  | == INSTALLATION | ||||||
|  |  | ||||||
|  | {{{ | ||||||
|  | gem install creole | ||||||
|  | }}} | ||||||
|  |  | ||||||
|  | == SYNOPSIS | ||||||
|  |  | ||||||
|  | {{{ | ||||||
|  | require 'creole' | ||||||
|  | html = Creole.creolize('== Creole text') | ||||||
|  | }}} | ||||||
|  |  | ||||||
|  | == BUGS | ||||||
|  |  | ||||||
|  | If you found a bug, please report it at the Creole project's tracker | ||||||
|  | on GitHub: | ||||||
|  |  | ||||||
|  | http://github.com/minad/creole/issues | ||||||
|  |  | ||||||
|  | == AUTHORS | ||||||
|  |  | ||||||
|  | * Lars Christensen (larsch) | ||||||
|  | * Daniel Mendler (minad) | ||||||
|  |  | ||||||
|  | == LICENSE | ||||||
|  |  | ||||||
|  | Creole is Copyright (c) 2008 - 2013 Lars Christensen, Daniel Mendler. It is free software, and | ||||||
|  | may be redistributed under the terms specified in the README file of | ||||||
|  | the Ruby distribution. | ||||||
							
								
								
									
										52
									
								
								samples/Cuda/scalarProd_kernel.cuh
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										52
									
								
								samples/Cuda/scalarProd_kernel.cuh
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,52 @@ | |||||||
|  | __global__ void scalarProdGPU( | ||||||
|  |     float *d_C, | ||||||
|  |     float *d_A, | ||||||
|  |     float *d_B, | ||||||
|  |     int vectorN, | ||||||
|  |     int elementN | ||||||
|  | ) | ||||||
|  | { | ||||||
|  |     //Accumulators cache | ||||||
|  |     __shared__ float accumResult[ACCUM_N]; | ||||||
|  |  | ||||||
|  |     //////////////////////////////////////////////////////////////////////////// | ||||||
|  |     // Cycle through every pair of vectors, | ||||||
|  |     // taking into account that vector counts can be different | ||||||
|  |     // from total number of thread blocks | ||||||
|  |     //////////////////////////////////////////////////////////////////////////// | ||||||
|  |     for (int vec = blockIdx.x; vec < vectorN; vec += gridDim.x) | ||||||
|  |     { | ||||||
|  |         int vectorBase = IMUL(elementN, vec); | ||||||
|  |         int vectorEnd  = vectorBase + elementN; | ||||||
|  |  | ||||||
|  |         //////////////////////////////////////////////////////////////////////// | ||||||
|  |         // Each accumulator cycles through vectors with | ||||||
|  |         // stride equal to number of total number of accumulators ACCUM_N | ||||||
|  |         // At this stage ACCUM_N is only preferred be a multiple of warp size | ||||||
|  |         // to meet memory coalescing alignment constraints. | ||||||
|  |         //////////////////////////////////////////////////////////////////////// | ||||||
|  |         for (int iAccum = threadIdx.x; iAccum < ACCUM_N; iAccum += blockDim.x) | ||||||
|  |         { | ||||||
|  |             float sum = 0; | ||||||
|  |  | ||||||
|  |             for (int pos = vectorBase + iAccum; pos < vectorEnd; pos += ACCUM_N) | ||||||
|  |                 sum += d_A[pos] * d_B[pos]; | ||||||
|  |  | ||||||
|  |             accumResult[iAccum] = sum; | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         //////////////////////////////////////////////////////////////////////// | ||||||
|  |         // Perform tree-like reduction of accumulators' results. | ||||||
|  |         // ACCUM_N has to be power of two at this stage | ||||||
|  |         //////////////////////////////////////////////////////////////////////// | ||||||
|  |         for (int stride = ACCUM_N / 2; stride > 0; stride >>= 1) | ||||||
|  |         { | ||||||
|  |             __syncthreads(); | ||||||
|  |  | ||||||
|  |             for (int iAccum = threadIdx.x; iAccum < stride; iAccum += blockDim.x) | ||||||
|  |                 accumResult[iAccum] += accumResult[stride + iAccum]; | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         if (threadIdx.x == 0) d_C[vec] = accumResult[0]; | ||||||
|  |     } | ||||||
|  | } | ||||||
							
								
								
									
										46
									
								
								samples/Cuda/vectorAdd.cu
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										46
									
								
								samples/Cuda/vectorAdd.cu
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,46 @@ | |||||||
|  | #include <stdio.h> | ||||||
|  | #include <cuda_runtime.h> | ||||||
|  |  | ||||||
|  | /** | ||||||
|  |  * CUDA Kernel Device code | ||||||
|  |  * | ||||||
|  |  * Computes the vector addition of A and B into C. The 3 vectors have the same | ||||||
|  |  * number of elements numElements. | ||||||
|  |  */ | ||||||
|  | __global__ void | ||||||
|  | vectorAdd(const float *A, const float *B, float *C, int numElements) | ||||||
|  | { | ||||||
|  |     int i = blockDim.x * blockIdx.x + threadIdx.x; | ||||||
|  |  | ||||||
|  |     if (i < numElements) | ||||||
|  |     { | ||||||
|  |         C[i] = A[i] + B[i]; | ||||||
|  |     } | ||||||
|  | } | ||||||
|  |  | ||||||
|  | /** | ||||||
|  |  * Host main routine | ||||||
|  |  */ | ||||||
|  | int | ||||||
|  | main(void) | ||||||
|  | { | ||||||
|  |     // Error code to check return values for CUDA calls | ||||||
|  |     cudaError_t err = cudaSuccess; | ||||||
|  |  | ||||||
|  |     // Launch the Vector Add CUDA Kernel | ||||||
|  |     int threadsPerBlock = 256; | ||||||
|  |     int blocksPerGrid =(numElements + threadsPerBlock - 1) / threadsPerBlock; | ||||||
|  |     vectorAdd<<<blocksPerGrid, threadsPerBlock>>>(d_A, d_B, d_C, numElements); | ||||||
|  |     err = cudaGetLastError(); | ||||||
|  |  | ||||||
|  |     if (err != cudaSuccess) | ||||||
|  |     { | ||||||
|  |         fprintf(stderr, "Failed to launch vectorAdd kernel (error code %s)!\n", cudaGetErrorString(err)); | ||||||
|  |         exit(EXIT_FAILURE); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     // Reset the device and exit | ||||||
|  |     err = cudaDeviceReset(); | ||||||
|  |  | ||||||
|  |     return 0; | ||||||
|  | } | ||||||
							
								
								
									
										87
									
								
								samples/DM/example.dm
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										87
									
								
								samples/DM/example.dm
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,87 @@ | |||||||
|  | // This is a single line comment. | ||||||
|  | /* | ||||||
|  | 	This is a multi-line comment | ||||||
|  | */ | ||||||
|  |  | ||||||
|  | // Pre-processor keywords | ||||||
|  |  | ||||||
|  | #define PI 3.1415 | ||||||
|  |  | ||||||
|  | #if PI == 4 | ||||||
|  |  | ||||||
|  | #define G 5 | ||||||
|  |  | ||||||
|  | #elif PI == 3 | ||||||
|  |  | ||||||
|  | #define I 6 | ||||||
|  |  | ||||||
|  | #else | ||||||
|  |  | ||||||
|  | #define K 7 | ||||||
|  |  | ||||||
|  | #endif | ||||||
|  |  | ||||||
|  |  | ||||||
|  | var/GlobalCounter = 0 | ||||||
|  | var/const/CONST_VARIABLE = 2 | ||||||
|  | var/list/MyList = list("anything", 1, new /datum/entity) | ||||||
|  | var/list/EmptyList[99] // creates a list of 99 null entries | ||||||
|  | var/list/NullList = null | ||||||
|  |  | ||||||
|  | /* | ||||||
|  | 	Entity Class | ||||||
|  | */ | ||||||
|  |  | ||||||
|  | /datum/entity | ||||||
|  | 	var/name = "Entity" | ||||||
|  | 	var/number = 0 | ||||||
|  |  | ||||||
|  | /datum/entity/proc/myFunction() | ||||||
|  | 	world.log << "Entity has called myFunction" | ||||||
|  |  | ||||||
|  | /datum/entity/New() | ||||||
|  | 	number = GlobalCounter++ | ||||||
|  |  | ||||||
|  | /* | ||||||
|  | 	Unit Class, Extends from Entity | ||||||
|  | */ | ||||||
|  |  | ||||||
|  | /datum/entity/unit | ||||||
|  | 	name = "Unit" | ||||||
|  |  | ||||||
|  | /datum/entity/unit/New() | ||||||
|  | 	..() // calls the parent's proc; equal to super() and base() in other languages | ||||||
|  | 	number = rand(1, 99) | ||||||
|  |  | ||||||
|  | /datum/entity/unit/myFunction() | ||||||
|  | 	world.log << "Unit has overriden and called myFunction" | ||||||
|  |  | ||||||
|  | // Global Function | ||||||
|  | /proc/ReverseList(var/list/input) | ||||||
|  | 	var/list/output = list() | ||||||
|  | 	for(var/i = input.len; i >= 1; i--) // IMPORTANT: List Arrays count from 1. | ||||||
|  | 		output += input[i] // "+= x" is ".Add(x)" | ||||||
|  | 	return output | ||||||
|  |  | ||||||
|  | // Bitflags | ||||||
|  | /proc/DoStuff() | ||||||
|  | 	var/bitflag = 0 | ||||||
|  | 	bitflag |= 8 | ||||||
|  | 	return bitflag | ||||||
|  |  | ||||||
|  | /proc/DoOtherStuff() | ||||||
|  | 	var/bitflag = 65535 // 16 bits is the maximum amount | ||||||
|  | 	bitflag &= ~8 | ||||||
|  | 	return bitflag | ||||||
|  |  | ||||||
|  | // Logic | ||||||
|  | /proc/DoNothing() | ||||||
|  | 	var/pi = PI | ||||||
|  | 	if(pi == 4) | ||||||
|  | 		world.log << "PI is 4" | ||||||
|  | 	else if(pi == CONST_VARIABLE) | ||||||
|  | 		world.log << "PI is [CONST_VARIABLE]!" | ||||||
|  | 	else | ||||||
|  | 		world.log << "PI is approximety [pi]" | ||||||
|  |  | ||||||
|  | #undef PI // Undefine PI | ||||||
| @@ -1,15 +1,19 @@ | |||||||
|  | import 'dart:math' as math; | ||||||
|  |  | ||||||
| class Point { | class Point { | ||||||
|  |   num x, y; | ||||||
|  |  | ||||||
|   Point(this.x, this.y); |   Point(this.x, this.y); | ||||||
|   distanceTo(Point other) { |  | ||||||
|  |   num distanceTo(Point other) { | ||||||
|     var dx = x - other.x; |     var dx = x - other.x; | ||||||
|     var dy = y - other.y; |     var dy = y - other.y; | ||||||
|     return Math.sqrt(dx * dx + dy * dy); |     return math.sqrt(dx * dx + dy * dy); | ||||||
|   } |   } | ||||||
|   var x, y; |  | ||||||
| } | } | ||||||
|  |  | ||||||
| main() { | void main() { | ||||||
|   Point p = new Point(2, 3); |   var p = new Point(2, 3); | ||||||
|   Point q = new Point(3, 4); |   var q = new Point(3, 4); | ||||||
|   print('distance from p to q = ${p.distanceTo(q)}'); |   print('distance from p to q = ${p.distanceTo(q)}'); | ||||||
| } | } | ||||||
|   | |||||||
							
								
								
									
										122
									
								
								samples/Erlang/release.script!
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										122
									
								
								samples/Erlang/release.script!
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,122 @@ | |||||||
|  | #!/usr/bin/env escript | ||||||
|  | %%! | ||||||
|  | %-*-Mode:erlang;coding:utf-8;tab-width:4;c-basic-offset:4;indent-tabs-mode:()-*- | ||||||
|  | % ex: set ft=erlang fenc=utf-8 sts=4 ts=4 sw=4 et: | ||||||
|  | %%% | ||||||
|  | %%%------------------------------------------------------------------------ | ||||||
|  | %%% BSD LICENSE | ||||||
|  | %%% | ||||||
|  | %%% Copyright (c) 2013, Michael Truog <mjtruog at gmail dot com> | ||||||
|  | %%% All rights reserved. | ||||||
|  | %%% | ||||||
|  | %%% Redistribution and use in source and binary forms, with or without | ||||||
|  | %%% modification, are permitted provided that the following conditions are met: | ||||||
|  | %%% | ||||||
|  | %%%     * Redistributions of source code must retain the above copyright | ||||||
|  | %%%       notice, this list of conditions and the following disclaimer. | ||||||
|  | %%%     * Redistributions in binary form must reproduce the above copyright | ||||||
|  | %%%       notice, this list of conditions and the following disclaimer in | ||||||
|  | %%%       the documentation and/or other materials provided with the | ||||||
|  | %%%       distribution. | ||||||
|  | %%%     * All advertising materials mentioning features or use of this | ||||||
|  | %%%       software must display the following acknowledgment: | ||||||
|  | %%%         This product includes software developed by Michael Truog | ||||||
|  | %%%     * The name of the author may not be used to endorse or promote | ||||||
|  | %%%       products derived from this software without specific prior | ||||||
|  | %%%       written permission | ||||||
|  | %%% | ||||||
|  | %%% THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND | ||||||
|  | %%% CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, | ||||||
|  | %%% INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | ||||||
|  | %%% OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||||||
|  | %%% DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR | ||||||
|  | %%% CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||||||
|  | %%% SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, | ||||||
|  | %%% BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | ||||||
|  | %%% SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||||||
|  | %%% INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, | ||||||
|  | %%% WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | ||||||
|  | %%% NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||||||
|  | %%% OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH | ||||||
|  | %%% DAMAGE. | ||||||
|  | %%%------------------------------------------------------------------------ | ||||||
|  |  | ||||||
|  | -author('mjtruog [at] gmail (dot) com'). | ||||||
|  |  | ||||||
|  | -mode(compile). | ||||||
|  |  | ||||||
|  | main(_) -> | ||||||
|  |     {ok, | ||||||
|  |      [{sys, _} = RelToolConfig, | ||||||
|  |       {target_dir, TargetDir}, | ||||||
|  |       {overlay, OverlayConfig}]} = file:consult("reltool.config"), | ||||||
|  |     {ok, Spec} = reltool:get_target_spec([RelToolConfig]), | ||||||
|  |     case file:make_dir(TargetDir) of | ||||||
|  |         ok -> | ||||||
|  |             ok; | ||||||
|  |         {error, eexist} -> | ||||||
|  |             io:format("release already exists? (~p)~n", [TargetDir]), | ||||||
|  |             exit_code(1) | ||||||
|  |     end, | ||||||
|  |     ok = reltool:eval_target_spec(Spec, code:root_dir(), TargetDir), | ||||||
|  |     ok = process_overlay(RelToolConfig, TargetDir, OverlayConfig), | ||||||
|  |     exit_code(0). | ||||||
|  |  | ||||||
|  | shell(Command, Arguments) -> | ||||||
|  |     CommandSuffix = " && echo 0 || echo 1", | ||||||
|  |     case lists:reverse(os:cmd(lists:flatten( | ||||||
|  |         io_lib:format(Command ++ CommandSuffix, Arguments)))) of | ||||||
|  |         [_, $0 | _] -> | ||||||
|  |             ok; | ||||||
|  |         [_, $1 | _] -> | ||||||
|  |             io:format("\"~s\" failed!~n", [io_lib:format(Command, Arguments)]), | ||||||
|  |             error | ||||||
|  |     end. | ||||||
|  |  | ||||||
|  | boot_rel_vsn({sys, Config} = _RelToolConfig) -> | ||||||
|  |     {rel, _Name, Ver, _} = proplists:lookup(rel, Config), | ||||||
|  |     Ver. | ||||||
|  |  | ||||||
|  | %% minimal parsing for handling mustache syntax | ||||||
|  | mustache(Body, Context) -> | ||||||
|  |     mustache(Body, "", Context). | ||||||
|  | mustache([], Result, _Context) -> | ||||||
|  |     lists:reverse(Result); | ||||||
|  | mustache([${, ${ | KeyStr], Result, Context) -> | ||||||
|  |     mustache_key(KeyStr, "", Result, Context); | ||||||
|  | mustache([C | Rest], Result, Context) -> | ||||||
|  |     mustache(Rest, [C | Result], Context). | ||||||
|  | mustache_key([$}, $} | Rest], KeyStr, Result, Context) -> | ||||||
|  |     Key = erlang:list_to_existing_atom(lists:reverse(KeyStr)), | ||||||
|  |     {ok, Value} = dict:find(Key, Context), | ||||||
|  |     mustache(Rest, lists:reverse(Value) ++ Result, Context); | ||||||
|  | mustache_key([C | Rest], KeyStr, Result, Context) -> | ||||||
|  |     mustache_key(Rest, [C | KeyStr], Result, Context). | ||||||
|  |  | ||||||
|  | %% support minimal overlay based on rebar overlays | ||||||
|  | process_overlay(RelToolConfig, TargetDir, OverlayConfig) -> | ||||||
|  |     BootRelVsn = boot_rel_vsn(RelToolConfig), | ||||||
|  |     OverlayVars = | ||||||
|  |         dict:from_list([{erts_vsn, "erts-" ++ erlang:system_info(version)}, | ||||||
|  |                         {rel_vsn, BootRelVsn}, | ||||||
|  |                         {target_dir, TargetDir}, | ||||||
|  |                         {hostname, net_adm:localhost()}]), | ||||||
|  |     {ok, BaseDir} = file:get_cwd(), | ||||||
|  |     execute_overlay(OverlayConfig, OverlayVars, BaseDir, TargetDir). | ||||||
|  |  | ||||||
|  | execute_overlay([], _Vars, _BaseDir, _TargetDir) -> | ||||||
|  |     ok; | ||||||
|  | execute_overlay([{mkdir, Out} | Rest], Vars, BaseDir, TargetDir) -> | ||||||
|  |     OutDir = mustache(filename:join(TargetDir, Out), Vars), | ||||||
|  |     ok = shell("mkdir -p ~s", [OutDir]), | ||||||
|  |     execute_overlay(Rest, Vars, BaseDir, TargetDir); | ||||||
|  | execute_overlay([{copy, In, Out} | Rest], Vars, BaseDir, TargetDir) -> | ||||||
|  |     InFile = mustache(filename:join(BaseDir, In), Vars), | ||||||
|  |     OutFile = mustache(filename:join(TargetDir, Out), Vars), | ||||||
|  |     true = filelib:is_file(InFile), | ||||||
|  |     ok = shell("cp -R ~s ~s", [InFile, OutFile]), | ||||||
|  |     execute_overlay(Rest, Vars, BaseDir, TargetDir). | ||||||
|  |  | ||||||
|  | exit_code(ExitCode) -> | ||||||
|  |     erlang:halt(ExitCode, [{flush, true}]). | ||||||
|  |  | ||||||
							
								
								
									
										161
									
								
								samples/GLSL/SyLens.glsl
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										161
									
								
								samples/GLSL/SyLens.glsl
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,161 @@ | |||||||
|  | #version 120 | ||||||
|  |  | ||||||
|  | /* | ||||||
|  |   Original Lens Distortion Algorithm from SSontech (Syntheyes) | ||||||
|  |   http://www.ssontech.com/content/lensalg.htm | ||||||
|  |    | ||||||
|  |   r2 is radius squared. | ||||||
|  |    | ||||||
|  |   r2 = image_aspect*image_aspect*u*u + v*v | ||||||
|  |   f = 1 + r2*(k + kcube*sqrt(r2)) | ||||||
|  |   u' = f*u | ||||||
|  |   v' = f*v | ||||||
|  |  | ||||||
|  | */ | ||||||
|  |  | ||||||
|  | // Controls | ||||||
|  | uniform float kCoeff, kCube, uShift, vShift; | ||||||
|  | uniform float chroma_red, chroma_green, chroma_blue; | ||||||
|  | uniform bool apply_disto; | ||||||
|  |  | ||||||
|  | // Uniform inputs | ||||||
|  | uniform sampler2D input1; | ||||||
|  | uniform float adsk_input1_w, adsk_input1_h, adsk_input1_aspect, adsk_input1_frameratio; | ||||||
|  | uniform float adsk_result_w, adsk_result_h; | ||||||
|  |  | ||||||
|  | float distortion_f(float r) { | ||||||
|  |     float f = 1 + (r*r)*(kCoeff + kCube * r); | ||||||
|  |     return f; | ||||||
|  | } | ||||||
|  |  | ||||||
|  |  | ||||||
|  | float inverse_f(float r) | ||||||
|  | { | ||||||
|  |      | ||||||
|  |     // Build a lookup table on the radius, as a fixed-size table. | ||||||
|  |     // We will use a vec3 since we will store the multipled number in the Z coordinate. | ||||||
|  |     // So to recap: x will be the radius, y will be the f(x) distortion, and Z will be x * y; | ||||||
|  |     vec3[48] lut; | ||||||
|  |      | ||||||
|  |     // Since out LUT is shader-global check if it's been computed alrite | ||||||
|  |     // Flame has no overflow bbox so we can safely max out at the image edge, plus some cushion | ||||||
|  |     float max_r = sqrt((adsk_input1_frameratio * adsk_input1_frameratio) + 1) + 0.1; | ||||||
|  |     float incr = max_r / 48; | ||||||
|  |     float lut_r = 0; | ||||||
|  |     float f; | ||||||
|  |     for(int i=0; i < 48; i++) { | ||||||
|  |         f = distortion_f(lut_r); | ||||||
|  |         lut[i] = vec3(lut_r, f, lut_r * f); | ||||||
|  |         lut_r += incr; | ||||||
|  |     } | ||||||
|  |      | ||||||
|  |     float t; | ||||||
|  |     // Now find the nehgbouring elements | ||||||
|  |     // only iterate to 46 since we will need | ||||||
|  |     // 47 as i+1 | ||||||
|  |     for(int i=0; i < 47; i++) { | ||||||
|  |         if(lut[i].z < r && lut[i+1].z > r) { | ||||||
|  |             // BAM! our value is between these two segments | ||||||
|  |             // get the T interpolant and mix | ||||||
|  |             t = (r - lut[i].z) / (lut[i+1].z - lut[i]).z; | ||||||
|  |             return mix(lut[i].y, lut[i+1].y, t ); | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | } | ||||||
|  |  | ||||||
|  | float aberrate(float f, float chroma) | ||||||
|  | { | ||||||
|  |    return f + (f * chroma); | ||||||
|  | } | ||||||
|  |  | ||||||
|  | vec3 chromaticize_and_invert(float f) | ||||||
|  | { | ||||||
|  |    vec3 rgb_f = vec3(aberrate(f, chroma_red), aberrate(f, chroma_green), aberrate(f, chroma_blue)); | ||||||
|  |    // We need to DIVIDE by F when we redistort, and x / y == x * (1 / y) | ||||||
|  |    if(apply_disto) { | ||||||
|  |       rgb_f = 1 / rgb_f; | ||||||
|  |    } | ||||||
|  |    return rgb_f; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | void main(void) | ||||||
|  | { | ||||||
|  |    vec2 px, uv; | ||||||
|  |    float f = 1; | ||||||
|  |    float r = 1; | ||||||
|  |     | ||||||
|  |    px = gl_FragCoord.xy; | ||||||
|  |     | ||||||
|  |    // Make sure we are still centered | ||||||
|  |    px.x -= (adsk_result_w - adsk_input1_w) / 2; | ||||||
|  |    px.y -= (adsk_result_h - adsk_input1_h) / 2; | ||||||
|  |     | ||||||
|  |    // Push the destination coordinates into the [0..1] range | ||||||
|  |    uv.x = px.x / adsk_input1_w; | ||||||
|  |    uv.y = px.y / adsk_input1_h; | ||||||
|  |     | ||||||
|  |         | ||||||
|  |    // And to Syntheyes UV which are [1..-1] on both X and Y | ||||||
|  |    uv.x = (uv.x *2 ) - 1; | ||||||
|  |    uv.y = (uv.y *2 ) - 1; | ||||||
|  |     | ||||||
|  |    // Add UV shifts | ||||||
|  |    uv.x += uShift; | ||||||
|  |    uv.y += vShift; | ||||||
|  |     | ||||||
|  |    // Make the X value the aspect value, so that the X coordinates go to [-aspect..aspect] | ||||||
|  |    uv.x = uv.x * adsk_input1_frameratio; | ||||||
|  |     | ||||||
|  |    // Compute the radius | ||||||
|  |    r = sqrt(uv.x*uv.x + uv.y*uv.y); | ||||||
|  |     | ||||||
|  |    // If we are redistorting, account for the oversize plate in the input, assume that | ||||||
|  |    // the input aspect is the same | ||||||
|  |    if(apply_disto) { | ||||||
|  |        r = r / (float(adsk_input1_w) / float(adsk_result_w)); | ||||||
|  |    } | ||||||
|  |     | ||||||
|  |    // Apply or remove disto, per channel honoring chromatic aberration | ||||||
|  |    if(apply_disto) { | ||||||
|  |       f = inverse_f(r); | ||||||
|  |    } else { | ||||||
|  |       f = distortion_f(r); | ||||||
|  |    } | ||||||
|  |     | ||||||
|  |    vec2[3] rgb_uvs = vec2[](uv, uv, uv); | ||||||
|  |     | ||||||
|  |    // Compute distortions per component | ||||||
|  |    vec3 rgb_f = chromaticize_and_invert(f); | ||||||
|  |     | ||||||
|  |    // Apply the disto coefficients, per component | ||||||
|  |    rgb_uvs[0] = rgb_uvs[0] * rgb_f.rr; | ||||||
|  |    rgb_uvs[1] = rgb_uvs[1] * rgb_f.gg; | ||||||
|  |    rgb_uvs[2] = rgb_uvs[2] * rgb_f.bb; | ||||||
|  |     | ||||||
|  |    // Convert all the UVs back to the texture space, per color component | ||||||
|  |    for(int i=0; i < 3; i++) { | ||||||
|  |        uv = rgb_uvs[i]; | ||||||
|  |         | ||||||
|  |        // Back from [-aspect..aspect] to [-1..1] | ||||||
|  |        uv.x = uv.x / adsk_input1_frameratio; | ||||||
|  |         | ||||||
|  |        // Remove UV shifts | ||||||
|  |        uv.x -= uShift; | ||||||
|  |        uv.y -= vShift; | ||||||
|  |         | ||||||
|  |        // Back to OGL UV | ||||||
|  |        uv.x = (uv.x + 1) / 2; | ||||||
|  |        uv.y = (uv.y + 1) / 2; | ||||||
|  |         | ||||||
|  |        rgb_uvs[i] = uv; | ||||||
|  |    } | ||||||
|  |     | ||||||
|  |    // Sample the input plate, per component | ||||||
|  |    vec4 sampled; | ||||||
|  |    sampled.r = texture2D(input1, rgb_uvs[0]).r; | ||||||
|  |    sampled.g = texture2D(input1, rgb_uvs[1]).g; | ||||||
|  |    sampled.b = texture2D(input1, rgb_uvs[2]).b; | ||||||
|  |     | ||||||
|  |    // and assign to the output | ||||||
|  |    gl_FragColor.rgba = vec4(sampled.rgb, 1.0 ); | ||||||
|  | } | ||||||
							
								
								
									
										630
									
								
								samples/GLSL/islandScene.glsl
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										630
									
								
								samples/GLSL/islandScene.glsl
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,630 @@ | |||||||
|  | //// High quality (Some browsers may freeze or crash) | ||||||
|  | //#define HIGHQUALITY | ||||||
|  |  | ||||||
|  | //// Medium quality (Should be fine on all systems, works on Intel HD2000 on Win7 but quite slow) | ||||||
|  | //#define MEDIUMQUALITY | ||||||
|  |  | ||||||
|  | //// Defaults | ||||||
|  | //#define REFLECTIONS | ||||||
|  | #define SHADOWS | ||||||
|  | //#define GRASS | ||||||
|  | //#define SMALL_WAVES | ||||||
|  | #define RAGGED_LEAVES | ||||||
|  | //#define DETAILED_NOISE | ||||||
|  | //#define LIGHT_AA // 2 sample SSAA | ||||||
|  | //#define HEAVY_AA // 2x2 RG SSAA | ||||||
|  | //#define TONEMAP | ||||||
|  |  | ||||||
|  | //// Configurations | ||||||
|  | #ifdef MEDIUMQUALITY | ||||||
|  | 	#define SHADOWS | ||||||
|  | 	#define SMALL_WAVES | ||||||
|  | 	#define RAGGED_LEAVES | ||||||
|  | 	#define TONEMAP | ||||||
|  | #endif | ||||||
|  |  | ||||||
|  | #ifdef HIGHQUALITY | ||||||
|  | 	#define REFLECTIONS | ||||||
|  | 	#define SHADOWS | ||||||
|  | 	//#define GRASS | ||||||
|  | 	#define SMALL_WAVES | ||||||
|  | 	#define RAGGED_LEAVES | ||||||
|  | 	#define DETAILED_NOISE | ||||||
|  | 	#define LIGHT_AA | ||||||
|  | 	#define TONEMAP | ||||||
|  | #endif | ||||||
|  |  | ||||||
|  | // Constants | ||||||
|  | const float eps = 1e-5; | ||||||
|  | const float PI = 3.14159265359; | ||||||
|  |  | ||||||
|  | const vec3 sunDir = vec3(0.79057,-0.47434, 0.0); | ||||||
|  | const vec3 skyCol = vec3(0.3, 0.5, 0.8); | ||||||
|  | const vec3 sandCol = vec3(0.9, 0.8, 0.5); | ||||||
|  | const vec3 treeCol = vec3(0.8, 0.65, 0.3); | ||||||
|  | const vec3 grassCol = vec3(0.4, 0.5, 0.18); | ||||||
|  | const vec3 leavesCol = vec3(0.3, 0.6, 0.2); | ||||||
|  | const vec3 leavesPos = vec3(-5.1,13.4, 0.0); | ||||||
|  |  | ||||||
|  | #ifdef TONEMAP | ||||||
|  | const vec3 sunCol = vec3(1.8, 1.7, 1.6); | ||||||
|  | #else | ||||||
|  | const vec3 sunCol = vec3(0.9, 0.85, 0.8); | ||||||
|  | #endif | ||||||
|  |  | ||||||
|  | const float exposure = 1.1; // Only used when tonemapping | ||||||
|  |  | ||||||
|  | // Description : Array and textureless GLSL 2D/3D/4D simplex | ||||||
|  | // noise functions. | ||||||
|  | // Author : Ian McEwan, Ashima Arts. | ||||||
|  | // License : Copyright (C) 2011 Ashima Arts. All rights reserved. | ||||||
|  | // Distributed under the MIT License. See LICENSE file. | ||||||
|  | // https://github.com/ashima/webgl-noise | ||||||
|  | vec3 mod289(vec3 x) { | ||||||
|  |   return x - floor(x * (1.0 / 289.0)) * 289.0; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | vec4 mod289(vec4 x) { | ||||||
|  |   return x - floor(x * (1.0 / 289.0)) * 289.0; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | vec4 permute(vec4 x) { | ||||||
|  |      return mod289(((x*34.0)+1.0)*x); | ||||||
|  | } | ||||||
|  |  | ||||||
|  | vec4 taylorInvSqrt(vec4 r) { | ||||||
|  |   return 1.79284291400159 - 0.85373472095314 * r; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | float snoise(vec3 v) { | ||||||
|  |   const vec2 C = vec2(1.0/6.0, 1.0/3.0) ; | ||||||
|  |   const vec4 D = vec4(0.0, 0.5, 1.0, 2.0); | ||||||
|  |  | ||||||
|  | // First corner | ||||||
|  |   vec3 i = floor(v + dot(v, C.yyy) ); | ||||||
|  |   vec3 x0 = v - i + dot(i, C.xxx) ; | ||||||
|  |  | ||||||
|  | // Other corners | ||||||
|  |   vec3 g = step(x0.yzx, x0.xyz); | ||||||
|  |   vec3 l = 1.0 - g; | ||||||
|  |   vec3 i1 = min( g.xyz, l.zxy ); | ||||||
|  |   vec3 i2 = max( g.xyz, l.zxy ); | ||||||
|  |  | ||||||
|  |   // x0 = x0 - 0.0 + 0.0 * C.xxx; | ||||||
|  |   // x1 = x0 - i1 + 1.0 * C.xxx; | ||||||
|  |   // x2 = x0 - i2 + 2.0 * C.xxx; | ||||||
|  |   // x3 = x0 - 1.0 + 3.0 * C.xxx; | ||||||
|  |   vec3 x1 = x0 - i1 + C.xxx; | ||||||
|  |   vec3 x2 = x0 - i2 + C.yyy; // 2.0*C.x = 1/3 = C.y | ||||||
|  |   vec3 x3 = x0 - D.yyy; // -1.0+3.0*C.x = -0.5 = -D.y | ||||||
|  |  | ||||||
|  | // Permutations | ||||||
|  |   i = mod289(i); | ||||||
|  |   vec4 p = permute( permute( permute( | ||||||
|  |              i.z + vec4(0.0, i1.z, i2.z, 1.0 )) | ||||||
|  |            + i.y + vec4(0.0, i1.y, i2.y, 1.0 )) | ||||||
|  |            + i.x + vec4(0.0, i1.x, i2.x, 1.0 )); | ||||||
|  |  | ||||||
|  | // Gradients: 7x7 points over a square, mapped onto an octahedron. | ||||||
|  | // The ring size 17*17 = 289 is close to a multiple of 49 (49*6 = 294) | ||||||
|  |   float n_ = 0.142857142857; // 1.0/7.0 | ||||||
|  |   vec3 ns = n_ * D.wyz - D.xzx; | ||||||
|  |  | ||||||
|  |   vec4 j = p - 49.0 * floor(p * ns.z * ns.z); // mod(p,7*7) | ||||||
|  |  | ||||||
|  |   vec4 x_ = floor(j * ns.z); | ||||||
|  |   vec4 y_ = floor(j - 7.0 * x_ ); // mod(j,N) | ||||||
|  |  | ||||||
|  |   vec4 x = x_ *ns.x + ns.yyyy; | ||||||
|  |   vec4 y = y_ *ns.x + ns.yyyy; | ||||||
|  |   vec4 h = 1.0 - abs(x) - abs(y); | ||||||
|  |  | ||||||
|  |   vec4 b0 = vec4( x.xy, y.xy ); | ||||||
|  |   vec4 b1 = vec4( x.zw, y.zw ); | ||||||
|  |  | ||||||
|  |   //vec4 s0 = vec4(lessThan(b0,0.0))*2.0 - 1.0; | ||||||
|  |   //vec4 s1 = vec4(lessThan(b1,0.0))*2.0 - 1.0; | ||||||
|  |   vec4 s0 = floor(b0)*2.0 + 1.0; | ||||||
|  |   vec4 s1 = floor(b1)*2.0 + 1.0; | ||||||
|  |   vec4 sh = -step(h, vec4(0.0)); | ||||||
|  |  | ||||||
|  |   vec4 a0 = b0.xzyw + s0.xzyw*sh.xxyy ; | ||||||
|  |   vec4 a1 = b1.xzyw + s1.xzyw*sh.zzww ; | ||||||
|  |  | ||||||
|  |   vec3 p0 = vec3(a0.xy,h.x); | ||||||
|  |   vec3 p1 = vec3(a0.zw,h.y); | ||||||
|  |   vec3 p2 = vec3(a1.xy,h.z); | ||||||
|  |   vec3 p3 = vec3(a1.zw,h.w); | ||||||
|  |  | ||||||
|  | //Normalise gradients | ||||||
|  |   vec4 norm = taylorInvSqrt(vec4(dot(p0,p0), dot(p1,p1), dot(p2, p2), dot(p3,p3))); | ||||||
|  |   p0 *= norm.x; | ||||||
|  |   p1 *= norm.y; | ||||||
|  |   p2 *= norm.z; | ||||||
|  |   p3 *= norm.w; | ||||||
|  |  | ||||||
|  | // Mix final noise value | ||||||
|  |   vec4 m = max(0.6 - vec4(dot(x0,x0), dot(x1,x1), dot(x2,x2), dot(x3,x3)), 0.0); | ||||||
|  |   m = m * m; | ||||||
|  |   return 42.0 * dot( m*m, vec4( dot(p0,x0), dot(p1,x1), | ||||||
|  |                                 dot(p2,x2), dot(p3,x3) ) ); | ||||||
|  | } | ||||||
|  |  | ||||||
|  |  | ||||||
|  |  | ||||||
|  | // Main | ||||||
|  | float fbm(vec3 p) | ||||||
|  | { | ||||||
|  | 	float final = snoise(p);  | ||||||
|  | 	p *= 1.94; final += snoise(p) * 0.5; | ||||||
|  | 	#ifdef DETAILED_NOISE | ||||||
|  | 	p *= 3.75; final += snoise(p) * 0.25; | ||||||
|  | 	return final / 1.75; | ||||||
|  | 	#else | ||||||
|  | 	return final / 1.5; | ||||||
|  | 	#endif | ||||||
|  | } | ||||||
|  |  | ||||||
|  | float waterHeight(vec3 p) | ||||||
|  | { | ||||||
|  | 	float d = length(p.xz); | ||||||
|  | 	float h = sin(d * 1.5 + iGlobalTime * 3.0) * 12.0 / d; // Island waves | ||||||
|  | 	#ifdef SMALL_WAVES | ||||||
|  | 	h += fbm(p*0.5); // Other waves | ||||||
|  | 	#endif | ||||||
|  | 	return h; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | vec3 bump(vec3 pos, vec3 rayDir) | ||||||
|  | { | ||||||
|  | 	float s = 2.0; | ||||||
|  | 	 | ||||||
|  | 	// Fade out waves to reduce aliasing | ||||||
|  | 	float dist = dot(pos, rayDir); | ||||||
|  | 	s *= dist < 2.0 ? 1.0 : 1.4142 / sqrt(dist); | ||||||
|  | 	 | ||||||
|  | 	// Calculate normal from heightmap | ||||||
|  | 	vec2 e = vec2(1e-2, 0.0); | ||||||
|  | 	vec3 p = vec3(pos.x, iGlobalTime*0.5, pos.z)*0.7; | ||||||
|  | 	float m = waterHeight(p)*s; | ||||||
|  | 	return normalize(vec3( | ||||||
|  | 		waterHeight(p+e.xyy)*s-m, | ||||||
|  | 		1.0, | ||||||
|  | 		waterHeight(p+e.yxy)*s-m | ||||||
|  | 	)); | ||||||
|  | } | ||||||
|  |  | ||||||
|  | // Ray intersections | ||||||
|  | vec4 intersectSphere(vec3 rpos, vec3 rdir, vec3 pos, float rad) | ||||||
|  | { | ||||||
|  | 	vec3 op = pos - rpos; | ||||||
|  | 	float b = dot(op, rdir);  | ||||||
|  | 	float det = b*b - dot(op, op) + rad*rad;  | ||||||
|  | 		 | ||||||
|  | 	if (det > 0.0) | ||||||
|  | 	{ | ||||||
|  | 		det = sqrt(det); | ||||||
|  | 		float t = b - det; | ||||||
|  | 		if (t > eps) | ||||||
|  | 			return vec4(-normalize(rpos+rdir*t-pos), t); | ||||||
|  | 	} | ||||||
|  | 	 | ||||||
|  | 	return vec4(0.0); | ||||||
|  | } | ||||||
|  |  | ||||||
|  | vec4 intersectCylinder(vec3 rpos, vec3 rdir, vec3 pos, float rad) | ||||||
|  | { | ||||||
|  | 	vec3 op = pos - rpos; | ||||||
|  | 	vec2 rdir2 = normalize(rdir.yz); | ||||||
|  | 	float b = dot(op.yz, rdir2); | ||||||
|  | 	float det = b*b - dot(op.yz, op.yz) + rad*rad;  | ||||||
|  | 	 | ||||||
|  | 	if (det > 0.0) | ||||||
|  | 	{ | ||||||
|  | 		det = sqrt(det); | ||||||
|  | 		float t = b - det; | ||||||
|  | 		if (t > eps) | ||||||
|  | 			return vec4(-normalize(rpos.yz+rdir2*t-pos.yz), 0.0, t); | ||||||
|  | 		t = b + det; | ||||||
|  | 		if (t > eps) | ||||||
|  | 			return vec4(-normalize(rpos.yz+rdir2*t-pos.yz), 0.0, t); | ||||||
|  | 	} | ||||||
|  | 	 | ||||||
|  | 	return vec4(0.0); | ||||||
|  | } | ||||||
|  |  | ||||||
|  | vec4 intersectPlane(vec3 rayPos, vec3 rayDir, vec3 n, float d) | ||||||
|  | { | ||||||
|  | 	float t = -(dot(rayPos, n) + d) / dot(rayDir, n); | ||||||
|  | 	return vec4(n * sign(dot(rayDir, n)), t); | ||||||
|  | } | ||||||
|  |  | ||||||
|  | // Helper functions | ||||||
|  | vec3 rotate(vec3 p, float theta) | ||||||
|  | { | ||||||
|  | 	float c = cos(theta), s = sin(theta); | ||||||
|  | 	return vec3(p.x * c + p.z * s, p.y, | ||||||
|  | 				p.z * c - p.x * s); | ||||||
|  | } | ||||||
|  |  | ||||||
|  | float impulse(float k, float x) // by iq | ||||||
|  | { | ||||||
|  |     float h = k*x; | ||||||
|  |     return h * exp(1.0 - h); | ||||||
|  | } | ||||||
|  |  | ||||||
|  | // Raymarched parts of scene | ||||||
|  | float grass(vec3 pos) | ||||||
|  | { | ||||||
|  | 	float h = length(pos - vec3(0.0, -7.0, 0.0)) - 8.0; | ||||||
|  | 	 | ||||||
|  | 	if (h > 2.0) return h; // Optimization (Avoid noise if too far away) | ||||||
|  | 	 | ||||||
|  | 	return h + snoise(pos * 3.0) * 0.1 + pos.y * 0.9; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | float tree(vec3 pos) | ||||||
|  | { | ||||||
|  | 	pos.y -= 0.5; | ||||||
|  | 	float s = sin(pos.y*0.03); | ||||||
|  | 	float c = cos(pos.y*0.03); | ||||||
|  | 	mat2 m = mat2(c, -s, s, c); | ||||||
|  | 	vec3 p = vec3(m*pos.xy, pos.z); | ||||||
|  | 	 | ||||||
|  | 	float width = 1.0 - pos.y * 0.02 - clamp(sin(pos.y * 8.0) * 0.1, 0.05, 0.1); | ||||||
|  | 	 | ||||||
|  | 	return max(length(p.xz) - width, pos.y - 12.5); | ||||||
|  | } | ||||||
|  |  | ||||||
|  | vec2 scene(vec3 pos) | ||||||
|  | { | ||||||
|  | 	float vtree = tree(pos); | ||||||
|  | 	#ifdef GRASS | ||||||
|  | 	float vgrass = grass(pos); | ||||||
|  | 	float v = min(vtree, vgrass); | ||||||
|  | 	#else | ||||||
|  | 	float v = vtree; | ||||||
|  | 	#endif | ||||||
|  | 	return vec2(v, v == vtree ? 2.0 : 1.0); | ||||||
|  | } | ||||||
|  |  | ||||||
|  | vec3 normal(vec3 pos) | ||||||
|  | { | ||||||
|  | 	vec2 eps = vec2(1e-3, 0.0); | ||||||
|  | 	float h = scene(pos).x; | ||||||
|  | 	return normalize(vec3( | ||||||
|  | 		scene(pos-eps.xyy).x-h, | ||||||
|  | 		scene(pos-eps.yxy).x-h, | ||||||
|  | 		scene(pos-eps.yyx).x-h | ||||||
|  | 	)); | ||||||
|  | } | ||||||
|  |  | ||||||
|  | float plantsShadow(vec3 rayPos, vec3 rayDir) | ||||||
|  | { | ||||||
|  | 	// Soft shadow taken from iq | ||||||
|  | 	float k = 6.0; | ||||||
|  | 	float t = 0.0; | ||||||
|  | 	float s = 1.0;	 | ||||||
|  | 	for (int i = 0; i < 30; i++) | ||||||
|  | 	{ | ||||||
|  | 		vec3 pos = rayPos+rayDir*t;	 | ||||||
|  | 		vec2 res = scene(pos);		 | ||||||
|  | 		if (res.x < 0.001) return 0.0; | ||||||
|  | 		s = min(s, k*res.x/t);  | ||||||
|  | 		t += max(res.x, 0.01); | ||||||
|  | 	} | ||||||
|  | 	 | ||||||
|  | 	return s*s*(3.0 - 2.0*s); | ||||||
|  | } | ||||||
|  |  | ||||||
|  | // Ray-traced parts of scene | ||||||
|  | vec4 intersectWater(vec3 rayPos, vec3 rayDir) | ||||||
|  | { | ||||||
|  | 	float h = sin(20.5 + iGlobalTime * 2.0) * 0.03; | ||||||
|  | 	float t = -(rayPos.y + 2.5 + h) / rayDir.y; | ||||||
|  | 	return vec4(0.0, 1.0, 0.0, t); | ||||||
|  | } | ||||||
|  |  | ||||||
|  | vec4 intersectSand(vec3 rayPos, vec3 rayDir) | ||||||
|  | { | ||||||
|  | 	return intersectSphere(rayPos, rayDir, vec3(0.0,-24.1,0.0), 24.1); | ||||||
|  | } | ||||||
|  |  | ||||||
|  | vec4 intersectTreasure(vec3 rayPos, vec3 rayDir) | ||||||
|  | { | ||||||
|  | 	return vec4(0.0); | ||||||
|  | } | ||||||
|  |  | ||||||
|  | vec4 intersectLeaf(vec3 rayPos, vec3 rayDir, float openAmount) | ||||||
|  | {	 | ||||||
|  | 	vec3 dir = normalize(vec3(0.0, 1.0, openAmount)); | ||||||
|  | 	float offset = 0.0; | ||||||
|  | 			 | ||||||
|  | 	vec4 res = intersectPlane(rayPos, rayDir, dir, 0.0); | ||||||
|  | 	vec3 pos = rayPos+rayDir*res.w; | ||||||
|  | 	#ifdef RAGGED_LEAVES | ||||||
|  | 	offset = snoise(pos*0.8) * 0.3; | ||||||
|  | 	#endif | ||||||
|  | 	if (pos.y > 0.0 || length(pos * vec3(0.9, 2.0, 1.0)) > 4.0 - offset) res.w = 0.0; | ||||||
|  | 	 | ||||||
|  | 	vec4 res2 = intersectPlane(rayPos, rayDir, vec3(dir.xy, -dir.z), 0.0); | ||||||
|  | 	pos = rayPos+rayDir*res2.w; | ||||||
|  | 	#ifdef RAGGED_LEAVES | ||||||
|  | 	offset = snoise(pos*0.8) * 0.3; | ||||||
|  | 	#endif | ||||||
|  | 	if (pos.y > 0.0 || length(pos * vec3(0.9, 2.0, 1.0)) > 4.0 - offset) res2.w = 0.0; | ||||||
|  | 	 | ||||||
|  | 	if (res2.w > 0.0 && res2.w < res.w || res.w <= 0.0) | ||||||
|  | 		res = res2; | ||||||
|  | 		 | ||||||
|  | 	return res; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | vec4 leaves(vec3 rayPos, vec3 rayDir) | ||||||
|  | { | ||||||
|  | 	float t = 1e20; | ||||||
|  | 	vec3 n = vec3(0.0); | ||||||
|  | 	 | ||||||
|  | 	rayPos -= leavesPos; | ||||||
|  | 	 | ||||||
|  | 	float sway = impulse(15.0, fract(iGlobalTime / PI * 0.125)); | ||||||
|  | 	float upDownSway = sway * -sin(iGlobalTime) * 0.06; | ||||||
|  | 	float openAmount = sway * max(-cos(iGlobalTime) * 0.4, 0.0); | ||||||
|  | 	 | ||||||
|  | 	float angleOffset = -0.1;	 | ||||||
|  | 	for (float k = 0.0; k < 6.2; k += 0.75) | ||||||
|  | 	{ | ||||||
|  | 		// Left-right | ||||||
|  | 		float alpha = k + (k - PI) * sway * 0.015; | ||||||
|  | 		vec3 p = rotate(rayPos, alpha); | ||||||
|  | 		vec3 d = rotate(rayDir, alpha); | ||||||
|  | 		 | ||||||
|  | 		// Up-down | ||||||
|  | 		angleOffset *= -1.0; | ||||||
|  | 		float theta = -0.4 +  | ||||||
|  | 			angleOffset +  | ||||||
|  | 			cos(k) * 0.35 +  | ||||||
|  | 			upDownSway +  | ||||||
|  | 			sin(iGlobalTime+k*10.0) * 0.03 * (sway + 0.2); | ||||||
|  | 		 | ||||||
|  | 		p = rotate(p.xzy, theta).xzy; | ||||||
|  | 		d = rotate(d.xzy, theta).xzy; | ||||||
|  | 	 | ||||||
|  | 		// Shift | ||||||
|  | 		p -= vec3(5.4, 0.0, 0.0); | ||||||
|  | 		 | ||||||
|  | 		// Intersect individual leaf | ||||||
|  | 		vec4 res = intersectLeaf(p, d, 1.0+openAmount); | ||||||
|  | 		if (res.w > 0.0 && res.w < t) | ||||||
|  | 		{ | ||||||
|  | 			t = res.w; | ||||||
|  | 			n = res.xyz; | ||||||
|  | 		} | ||||||
|  | 	} | ||||||
|  | 	 | ||||||
|  | 	return vec4(n, t); | ||||||
|  | } | ||||||
|  |  | ||||||
|  | // Lighting | ||||||
|  | float shadow(vec3 rayPos, vec3 rayDir) | ||||||
|  | {	 | ||||||
|  | 	float s = 1.0; | ||||||
|  | 	 | ||||||
|  | 	// Intersect sand | ||||||
|  | 	//vec4 resSand = intersectSand(rayPos, rayDir); | ||||||
|  | 	//if (resSand.w > 0.0) return 0.0; | ||||||
|  | 	 | ||||||
|  | 	// Intersect plants | ||||||
|  | 	s = min(s, plantsShadow(rayPos, rayDir)); | ||||||
|  | 	if (s < 0.0001) return 0.0; | ||||||
|  | 	 | ||||||
|  | 	// Intersect leaves | ||||||
|  | 	vec4 resLeaves = leaves(rayPos, rayDir); | ||||||
|  | 	if (resLeaves.w > 0.0 && resLeaves.w < 1e7) return 0.0; | ||||||
|  | 	 | ||||||
|  | 	return s; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | vec3 light(vec3 p, vec3 n) | ||||||
|  | { | ||||||
|  | 	float s = 1.0; | ||||||
|  | 	 | ||||||
|  | 	#ifdef SHADOWS | ||||||
|  | 	s = shadow(p-sunDir*0.01, -sunDir); | ||||||
|  | 	#endif | ||||||
|  | 	 | ||||||
|  | 	vec3 col = sunCol * min(max(dot(n, sunDir), 0.0), s); | ||||||
|  | 	col += skyCol * (-n.y * 0.5 + 0.5) * 0.3; | ||||||
|  | 	return col; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | vec3 lightLeaves(vec3 p, vec3 n) | ||||||
|  | { | ||||||
|  | 	float s = 1.0; | ||||||
|  | 	 | ||||||
|  | 	#ifdef SHADOWS | ||||||
|  | 	s = shadow(p-sunDir*0.01, -sunDir); | ||||||
|  | 	#endif | ||||||
|  | 	 | ||||||
|  | 	float ao = min(length(p - leavesPos) * 0.1, 1.0); | ||||||
|  | 	 | ||||||
|  | 	float ns = dot(n, sunDir); | ||||||
|  | 	float d = sqrt(max(ns, 0.0)); | ||||||
|  | 	vec3 col = sunCol * min(d, s); | ||||||
|  | 	col += sunCol * max(-ns, 0.0) * vec3(0.3, 0.3, 0.1) * ao; | ||||||
|  | 	col += skyCol * (-n.y * 0.5 + 0.5) * 0.3 * ao; | ||||||
|  | 	return col; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | vec3 sky(vec3 n) | ||||||
|  | { | ||||||
|  | 	return skyCol * (1.0 - n.y * 0.8); | ||||||
|  | } | ||||||
|  |  | ||||||
|  | // Ray-marching | ||||||
|  | vec4 plants(vec3 rayPos, vec3 rayDir) | ||||||
|  | { | ||||||
|  | 	float t = 0.0; | ||||||
|  | 	 | ||||||
|  | 	for (int i = 0; i < 40; i++) | ||||||
|  | 	{ | ||||||
|  | 		vec3 pos = rayPos+rayDir*t;	 | ||||||
|  | 		vec2 res = scene(pos); | ||||||
|  | 		float h = res.x; | ||||||
|  | 		 | ||||||
|  | 		if (h < 0.001) | ||||||
|  | 		{ | ||||||
|  | 			vec3 col = res.y == 2.0 ? treeCol : grassCol; | ||||||
|  | 			float uvFact = res.y == 2.0 ? 1.0 : 10.0; | ||||||
|  | 			 | ||||||
|  | 			vec3 n = normal(pos); | ||||||
|  | 			vec2 uv = vec2(n.x, pos.y * 0.5) * 0.2 * uvFact; | ||||||
|  | 			vec3 tex = texture2D(iChannel0, uv).rgb * 0.6 + 0.4; | ||||||
|  | 			float ao = min(length(pos - leavesPos) * 0.1, 1.0); | ||||||
|  | 			return vec4(col * light(pos, n) * ao * tex, t); | ||||||
|  | 		} | ||||||
|  | 		 | ||||||
|  | 		t += h; | ||||||
|  | 	} | ||||||
|  | 	 | ||||||
|  | 	return vec4(sky(rayDir), 1e8); | ||||||
|  | } | ||||||
|  |  | ||||||
|  | // Final combination | ||||||
|  | vec3 traceReflection(vec3 rayPos, vec3 rayDir) | ||||||
|  | { | ||||||
|  | 	vec3 col = vec3(0.0); | ||||||
|  | 	float t = 1e20; | ||||||
|  | 			 | ||||||
|  | 	// Intersect plants | ||||||
|  | 	vec4 resPlants = plants(rayPos, rayDir); | ||||||
|  | 	if (resPlants.w > 0.0 && resPlants.w < t) | ||||||
|  | 	{ | ||||||
|  | 		t = resPlants.w; | ||||||
|  | 		col = resPlants.xyz; | ||||||
|  | 	} | ||||||
|  | 	 | ||||||
|  | 	// Intersect leaves | ||||||
|  | 	vec4 resLeaves = leaves(rayPos, rayDir); | ||||||
|  | 	if (resLeaves.w > 0.0 && resLeaves.w < t) | ||||||
|  | 	{ | ||||||
|  | 		vec3 pos = rayPos + rayDir * resLeaves.w; | ||||||
|  | 		vec2 uv = (pos.xz - leavesPos.xz) * 0.3; | ||||||
|  | 		float tex = texture2D(iChannel0, uv).r * 0.6 + 0.5; | ||||||
|  | 		 | ||||||
|  | 		t = resLeaves.w; | ||||||
|  | 		col = leavesCol * lightLeaves(pos, resLeaves.xyz) * tex; | ||||||
|  | 	} | ||||||
|  | 		 | ||||||
|  | 	if (t > 1e7) return sky(rayDir); | ||||||
|  | 	 | ||||||
|  | 	return col; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | vec3 trace(vec3 rayPos, vec3 rayDir) | ||||||
|  | { | ||||||
|  | 	vec3 col = vec3(0.0); | ||||||
|  | 	float t = 1e20; | ||||||
|  | 	 | ||||||
|  | 	// Intersect sand | ||||||
|  | 	vec4 resSand = intersectSand(rayPos, rayDir); | ||||||
|  | 	if (resSand.w > 0.0) | ||||||
|  | 	{ | ||||||
|  | 		vec3 pos = rayPos + rayDir * resSand.w; | ||||||
|  | 		t = resSand.w; | ||||||
|  |  | ||||||
|  | 		col = sandCol * light(pos, resSand.xyz); | ||||||
|  | 	} | ||||||
|  | 	 | ||||||
|  | 	// Intersect treasure chest | ||||||
|  | 	vec4 resTreasure = intersectTreasure(rayPos, rayDir); | ||||||
|  | 	if (resTreasure.w > 0.0 && resTreasure.w < t) | ||||||
|  | 	{ | ||||||
|  | 		vec3 pos = rayPos + rayDir * resTreasure.w; | ||||||
|  | 		t = resTreasure.w; | ||||||
|  | 		col = leavesCol * light(pos, resTreasure.xyz); | ||||||
|  | 	} | ||||||
|  | 	 | ||||||
|  | 	// Intersect leaves | ||||||
|  | 	vec4 resLeaves = leaves(rayPos, rayDir); | ||||||
|  | 	if (resLeaves.w > 0.0 && resLeaves.w < t) | ||||||
|  | 	{ | ||||||
|  | 		vec3 pos = rayPos + rayDir * resLeaves.w; | ||||||
|  | 		vec2 uv = (pos.xz - leavesPos.xz) * 0.3; | ||||||
|  | 		float tex = texture2D(iChannel0, uv).r * 0.6 + 0.5; | ||||||
|  | 		 | ||||||
|  | 		t = resLeaves.w; | ||||||
|  | 		col = leavesCol * lightLeaves(pos, resLeaves.xyz) * tex; | ||||||
|  | 	} | ||||||
|  | 	 | ||||||
|  | 	// Intersect plants | ||||||
|  | 	vec4 resPlants = plants(rayPos, rayDir); | ||||||
|  | 	if (resPlants.w > 0.0 && resPlants.w < t) | ||||||
|  | 	{ | ||||||
|  | 		t = resPlants.w; | ||||||
|  | 		col = resPlants.xyz; | ||||||
|  | 	} | ||||||
|  | 		 | ||||||
|  | 	// Intersect water	 | ||||||
|  | 	vec4 resWater = intersectWater(rayPos, rayDir); | ||||||
|  | 	if (resWater.w > 0.0 && resWater.w < t) | ||||||
|  | 	{ | ||||||
|  | 		vec3 pos = rayPos + rayDir * resWater.w; | ||||||
|  | 		float dist = t - resWater.w; | ||||||
|  | 		vec3 n = bump(pos, rayDir); | ||||||
|  | 		 | ||||||
|  | 		float ct = -min(dot(n,rayDir), 0.0); | ||||||
|  | 		float fresnel = 0.9 - 0.9 * pow(1.0 - ct, 5.0); | ||||||
|  | 		 | ||||||
|  | 		vec3 trans = col * exp(-dist * vec3(1.0, 0.7, 0.4) * 3.0); | ||||||
|  | 		vec3 reflDir = normalize(reflect(rayDir, n)); | ||||||
|  | 		vec3 refl = sky(reflDir); | ||||||
|  | 		 | ||||||
|  | 		#ifdef REFLECTIONS | ||||||
|  | 		if (dot(pos, rayDir) < -2.0) | ||||||
|  | 			refl = traceReflection(pos, reflDir).rgb; | ||||||
|  | 		#endif | ||||||
|  | 				 | ||||||
|  | 		t = resWater.t; | ||||||
|  | 		col = mix(refl, trans, fresnel); | ||||||
|  | 	} | ||||||
|  | 	 | ||||||
|  | 	if (t > 1e7) return sky(rayDir); | ||||||
|  | 	 | ||||||
|  | 	return col; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | // Ray-generation | ||||||
|  | vec3 camera(vec2 px) | ||||||
|  | { | ||||||
|  | 	vec2 rd = (px / iResolution.yy - vec2(iResolution.x/iResolution.y*0.5-0.5, 0.0)) * 2.0 - 1.0; | ||||||
|  | 	float t = sin(iGlobalTime * 0.1) * 0.2; | ||||||
|  | 	vec3 rayDir = normalize(vec3(rd.x, rd.y, 1.0)); | ||||||
|  | 	vec3 rayPos = vec3(0.0, 3.0, -18.0); | ||||||
|  | 	return trace(rayPos, rayDir); | ||||||
|  | } | ||||||
|  |  | ||||||
|  | void main(void) | ||||||
|  | { | ||||||
|  | 	#ifdef HEAVY_AA | ||||||
|  | 		vec3 col = camera(gl_FragCoord.xy+vec2(0.0,0.5))*0.25; | ||||||
|  | 		col += camera(gl_FragCoord.xy+vec2(0.25,0.0))*0.25; | ||||||
|  | 		col += camera(gl_FragCoord.xy+vec2(0.5,0.75))*0.25; | ||||||
|  | 		col += camera(gl_FragCoord.xy+vec2(0.75,0.25))*0.25; | ||||||
|  | 	#else | ||||||
|  | 		vec3 col = camera(gl_FragCoord.xy); | ||||||
|  | 		#ifdef LIGHT_AA | ||||||
|  | 			col = col * 0.5 + camera(gl_FragCoord.xy+vec2(0.5,0.5))*0.5; | ||||||
|  | 		#endif | ||||||
|  | 	#endif | ||||||
|  | 	 | ||||||
|  | 	#ifdef TONEMAP | ||||||
|  | 	// Optimized Haarm-Peter Duiker’s curve | ||||||
|  | 	vec3 x = max(vec3(0.0),col*exposure-0.004); | ||||||
|  | 	col = (x*(6.2*x+.5))/(x*(6.2*x+1.7)+0.06); | ||||||
|  | 	#else | ||||||
|  | 	col = pow(col, vec3(0.4545)); | ||||||
|  | 	#endif | ||||||
|  | 	 | ||||||
|  | 	gl_FragColor = vec4(col, 1.0); | ||||||
|  | } | ||||||
							
								
								
									
										68
									
								
								samples/GLSL/shader.fp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										68
									
								
								samples/GLSL/shader.fp
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,68 @@ | |||||||
|  | /* | ||||||
|  |  * Copyright (C) 2010 Josh A. Beam | ||||||
|  |  * All rights reserved. | ||||||
|  |  * | ||||||
|  |  * Redistribution and use in source and binary forms, with or without | ||||||
|  |  * modification, are permitted provided that the following conditions | ||||||
|  |  * are met: | ||||||
|  |  *   1. Redistributions of source code must retain the above copyright | ||||||
|  |  *      notice, this list of conditions and the following disclaimer. | ||||||
|  |  *   2. Redistributions in binary form must reproduce the above copyright | ||||||
|  |  *      notice, this list of conditions and the following disclaimer in the | ||||||
|  |  *      documentation and/or other materials provided with the distribution. | ||||||
|  |  * | ||||||
|  |  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR | ||||||
|  |  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | ||||||
|  |  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. | ||||||
|  |  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||||||
|  |  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | ||||||
|  |  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; | ||||||
|  |  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, | ||||||
|  |  * WHETHER IN CONTACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR | ||||||
|  |  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF | ||||||
|  |  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||||||
|  |  */ | ||||||
|  |  | ||||||
|  | const int NUM_LIGHTS = 3; | ||||||
|  | const vec3 AMBIENT = vec3(0.1, 0.1, 0.1); | ||||||
|  | const float MAX_DIST = 2.5; | ||||||
|  | const float MAX_DIST_SQUARED = MAX_DIST * MAX_DIST; | ||||||
|  |  | ||||||
|  | uniform vec3 lightColor[NUM_LIGHTS]; | ||||||
|  |  | ||||||
|  | varying vec3 fragmentNormal; | ||||||
|  | varying vec3 cameraVector; | ||||||
|  | varying vec3 lightVector[NUM_LIGHTS]; | ||||||
|  |  | ||||||
|  | void | ||||||
|  | main() | ||||||
|  | { | ||||||
|  | 	// initialize diffuse/specular lighting | ||||||
|  | 	vec3 diffuse = vec3(0.0, 0.0, 0.0); | ||||||
|  | 	vec3 specular = vec3(0.0, 0.0, 0.0); | ||||||
|  |  | ||||||
|  | 	// normalize the fragment normal and camera direction | ||||||
|  | 	vec3 normal = normalize(fragmentNormal); | ||||||
|  | 	vec3 cameraDir = normalize(cameraVector); | ||||||
|  |  | ||||||
|  | 	// loop through each light | ||||||
|  | 	for(int i = 0; i < NUM_LIGHTS; ++i) { | ||||||
|  | 		// calculate distance between 0.0 and 1.0 | ||||||
|  | 		float dist = min(dot(lightVector[i], lightVector[i]), MAX_DIST_SQUARED) / MAX_DIST_SQUARED; | ||||||
|  | 		float distFactor = 1.0 - dist; | ||||||
|  |  | ||||||
|  | 		// diffuse | ||||||
|  | 		vec3 lightDir = normalize(lightVector[i]); | ||||||
|  | 		float diffuseDot = dot(normal, lightDir); | ||||||
|  | 		diffuse += lightColor[i] * clamp(diffuseDot, 0.0, 1.0) * distFactor; | ||||||
|  |  | ||||||
|  | 		// specular | ||||||
|  | 		vec3 halfAngle = normalize(cameraDir + lightDir); | ||||||
|  | 		vec3 specularColor = min(lightColor[i] + 0.5, 1.0); | ||||||
|  | 		float specularDot = dot(normal, halfAngle); | ||||||
|  | 		specular += specularColor * pow(clamp(specularDot, 0.0, 1.0), 16.0) * distFactor; | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	vec4 sample = vec4(1.0, 1.0, 1.0, 1.0); | ||||||
|  | 	gl_FragColor = vec4(clamp(sample.rgb * (diffuse + AMBIENT) + specular, 0.0, 1.0), sample.a); | ||||||
|  | } | ||||||
| @@ -1 +0,0 @@ | |||||||
| print("hello") |  | ||||||
							
								
								
									
										9
									
								
								samples/Hy/fibonacci.hy
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										9
									
								
								samples/Hy/fibonacci.hy
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,9 @@ | |||||||
|  | ;; Fibonacci example in Hy. | ||||||
|  |  | ||||||
|  | (defn fib [n] | ||||||
|  |   (if (<= n 2) n | ||||||
|  |       (+ (fib (- n 1)) (fib (- n 2))))) | ||||||
|  |  | ||||||
|  | (if (= __name__ "__main__") | ||||||
|  |   (for [x [1 2 3 4 5 6 7 8]] | ||||||
|  |     (print (fib x)))) | ||||||
							
								
								
									
										13
									
								
								samples/Hy/hello-world.hy
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										13
									
								
								samples/Hy/hello-world.hy
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,13 @@ | |||||||
|  | ;; The concurrent.futures example in Hy. | ||||||
|  |  | ||||||
|  | (import [concurrent.futures [ThreadPoolExecutor as-completed]] | ||||||
|  |         [random [randint]] | ||||||
|  |         [sh [sleep]]) | ||||||
|  |  | ||||||
|  | (defn task-to-do [] | ||||||
|  |   (sleep (randint 1 5))) | ||||||
|  |  | ||||||
|  | (with-as (ThreadPoolExecutor 10) executor | ||||||
|  |   (setv jobs (list-comp (.submit executor task-to-do) (x (range 0 10)))) | ||||||
|  |   (for (future (as-completed jobs)) | ||||||
|  |     (.result future))) | ||||||
							
								
								
									
										29
									
								
								samples/IDL/mg_acosh.pro
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										29
									
								
								samples/IDL/mg_acosh.pro
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,29 @@ | |||||||
|  | ; docformat = 'rst' | ||||||
|  |  | ||||||
|  | ;+ | ||||||
|  | ; Inverse hyperbolic cosine. Uses the formula: | ||||||
|  | ;  | ||||||
|  | ; $$\text{acosh}(z) = \ln(z + \sqrt{z + 1} \sqrt{z - 1})$$ | ||||||
|  | ; | ||||||
|  | ; :Examples: | ||||||
|  | ;    The arc hyperbolic sine function looks like:: | ||||||
|  | ; | ||||||
|  | ;       IDL> x = 2.5 * findgen(1000) / 999. + 1. | ||||||
|  | ;       IDL> plot, x, mg_acosh(x), xstyle=1 | ||||||
|  | ; | ||||||
|  | ;    This should look like: | ||||||
|  | ; | ||||||
|  | ;    .. image:: acosh.png | ||||||
|  | ; | ||||||
|  | ; :Returns: | ||||||
|  | ;    float, double, complex, or double complex depending on the input | ||||||
|  | ; | ||||||
|  | ; :Params: | ||||||
|  | ;    z : in, required, type=numeric | ||||||
|  | ;       input | ||||||
|  | ;- | ||||||
|  | function mg_acosh, z | ||||||
|  |   compile_opt strictarr | ||||||
|  |    | ||||||
|  |   return, alog(z + sqrt(z + 1) * sqrt(z - 1)) | ||||||
|  | end | ||||||
							
								
								
									
										9
									
								
								samples/IDL/mg_analysis.dlm
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										9
									
								
								samples/IDL/mg_analysis.dlm
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,9 @@ | |||||||
|  | MODULE mg_analysis | ||||||
|  | DESCRIPTION Tools for analysis | ||||||
|  | VERSION 1.0 | ||||||
|  | SOURCE mgalloy | ||||||
|  | BUILD_DATE January 18, 2011 | ||||||
|  |  | ||||||
|  | FUNCTION MG_ARRAY_EQUAL      2 2 KEYWORDS | ||||||
|  | FUNCTION MG_TOTAL            1 1 | ||||||
|  |  | ||||||
							
								
								
									
										35
									
								
								samples/IDL/mg_gcd.pro
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										35
									
								
								samples/IDL/mg_gcd.pro
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,35 @@ | |||||||
|  | ; docformat = 'rst' | ||||||
|  |  | ||||||
|  | ;+ | ||||||
|  | ; Find the greatest common denominator (GCD) for two positive integers. | ||||||
|  | ;  | ||||||
|  | ; :Returns: | ||||||
|  | ;    integer | ||||||
|  | ; | ||||||
|  | ; :Params: | ||||||
|  | ;    a : in, required, type=integer | ||||||
|  | ;       first integer | ||||||
|  | ;    b : in, required, type=integer | ||||||
|  | ;       second integer | ||||||
|  | ;- | ||||||
|  | function mg_gcd, a, b | ||||||
|  |   compile_opt strictarr | ||||||
|  |   on_error, 2 | ||||||
|  |    | ||||||
|  |   if (n_params() ne 2) then message, 'incorrect number of arguments' | ||||||
|  |   if (~mg_isinteger(a) || ~mg_isinteger(b)) then begin | ||||||
|  |     message, 'integer arguments required' | ||||||
|  |   endif | ||||||
|  |    | ||||||
|  |   _a = abs(a) | ||||||
|  |   _b = abs(b) | ||||||
|  |   minArg = _a < _b | ||||||
|  |   maxArg = _a > _b | ||||||
|  |    | ||||||
|  |   if (minArg eq 0) then return, maxArg | ||||||
|  |    | ||||||
|  |   remainder = maxArg mod minArg | ||||||
|  |   if (remainder eq 0) then return, minArg | ||||||
|  |    | ||||||
|  |   return, mg_gcd(minArg, remainder) | ||||||
|  | end | ||||||
							
								
								
									
										42
									
								
								samples/IDL/mg_trunc.pro
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										42
									
								
								samples/IDL/mg_trunc.pro
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,42 @@ | |||||||
|  | ; docformat = 'rst' | ||||||
|  |  | ||||||
|  | ;+ | ||||||
|  | ; Truncate argument towards 0.0, i.e., takes the `FLOOR` of positive values | ||||||
|  | ; and the `CEIL` of negative values. | ||||||
|  | ; | ||||||
|  | ; :Examples: | ||||||
|  | ;   Try the main-level program at the end of this file. It does:: | ||||||
|  | ; | ||||||
|  | ;      IDL> print, mg_trunc([1.2, -1.2, 0.0]) | ||||||
|  | ;                 1          -1           0 | ||||||
|  | ;      IDL> print, floor([1.2, -1.2, 0.0]) | ||||||
|  | ;                 1          -2           0 | ||||||
|  | ;      IDL> print, ceil([1.2, -1.2, 0.0]) | ||||||
|  | ;                 2          -1           0 | ||||||
|  | ; | ||||||
|  | ; :Returns: | ||||||
|  | ;    array of same type as argument | ||||||
|  | ; | ||||||
|  | ; :Params: | ||||||
|  | ;    x : in, required, type=float/double | ||||||
|  | ;       array containing values to truncate | ||||||
|  | ;- | ||||||
|  | function mg_trunc, x | ||||||
|  |   compile_opt strictarr | ||||||
|  |    | ||||||
|  |   result = ceil(x) | ||||||
|  |   posInd = where(x gt 0, nposInd) | ||||||
|  |    | ||||||
|  |   if (nposInd gt 0L) then begin | ||||||
|  |     result[posInd] = floor(x[posInd]) | ||||||
|  |   endif | ||||||
|  |    | ||||||
|  |   return, result | ||||||
|  | end | ||||||
|  |  | ||||||
|  |  | ||||||
|  | ; main-level example program | ||||||
|  |  | ||||||
|  | print, mg_trunc([1.2, -1.2, 0.0]) | ||||||
|  |  | ||||||
|  | end | ||||||
							
								
								
									
										42
									
								
								samples/Idris/Chars.idr
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										42
									
								
								samples/Idris/Chars.idr
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,42 @@ | |||||||
|  | module Prelude.Char | ||||||
|  |  | ||||||
|  | import Builtins | ||||||
|  |  | ||||||
|  | isUpper : Char -> Bool | ||||||
|  | isUpper x = x >= 'A' && x <= 'Z' | ||||||
|  |  | ||||||
|  | isLower : Char -> Bool | ||||||
|  | isLower x = x >= 'a' && x <= 'z' | ||||||
|  |  | ||||||
|  | isAlpha : Char -> Bool | ||||||
|  | isAlpha x = isUpper x || isLower x | ||||||
|  |  | ||||||
|  | isDigit : Char -> Bool | ||||||
|  | isDigit x = (x >= '0' && x <= '9') | ||||||
|  |  | ||||||
|  | isAlphaNum : Char -> Bool | ||||||
|  | isAlphaNum x = isDigit x || isAlpha x | ||||||
|  |  | ||||||
|  | isSpace : Char -> Bool | ||||||
|  | isSpace x = x == ' '  || x == '\t' || x == '\r' || | ||||||
|  |             x == '\n' || x == '\f' || x == '\v' || | ||||||
|  |             x == '\xa0' | ||||||
|  |  | ||||||
|  | isNL : Char -> Bool | ||||||
|  | isNL x = x == '\r' || x == '\n' | ||||||
|  |  | ||||||
|  | toUpper : Char -> Char | ||||||
|  | toUpper x = if (isLower x) | ||||||
|  |                then (prim__intToChar (prim__charToInt x - 32)) | ||||||
|  |                else x | ||||||
|  |  | ||||||
|  | toLower : Char -> Char | ||||||
|  | toLower x = if (isUpper x) | ||||||
|  |                then (prim__intToChar (prim__charToInt x + 32)) | ||||||
|  |                else x | ||||||
|  |  | ||||||
|  | isHexDigit : Char -> Bool | ||||||
|  | isHexDigit x = elem (toUpper x) hexChars where | ||||||
|  |   hexChars : List Char | ||||||
|  |   hexChars = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', | ||||||
|  |               'A', 'B', 'C', 'D', 'E', 'F'] | ||||||
							
								
								
									
										267
									
								
								samples/JSON/composer.lock
									
									
									
										generated
									
									
									
										Normal file
									
								
							
							
						
						
									
										267
									
								
								samples/JSON/composer.lock
									
									
									
										generated
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,267 @@ | |||||||
|  | { | ||||||
|  |     "_readme": [ | ||||||
|  |         "This file locks the dependencies of your project to a known state", | ||||||
|  |         "Read more about it at http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file" | ||||||
|  |     ], | ||||||
|  |     "hash": "d8ff8fcb71824f5199f3499bf71862f1", | ||||||
|  |     "packages": [ | ||||||
|  |         { | ||||||
|  |             "name": "arbit/system-process", | ||||||
|  |             "version": "1.0", | ||||||
|  |             "source": { | ||||||
|  |                 "type": "git", | ||||||
|  |                 "url": "https://github.com/Arbitracker/system-process.git", | ||||||
|  |                 "reference": "1.0" | ||||||
|  |             }, | ||||||
|  |             "dist": { | ||||||
|  |                 "type": "zip", | ||||||
|  |                 "url": "https://api.github.com/repos/Arbitracker/system-process/zipball/1.0", | ||||||
|  |                 "reference": "1.0", | ||||||
|  |                 "shasum": "" | ||||||
|  |             }, | ||||||
|  |             "type": "library", | ||||||
|  |             "autoload": { | ||||||
|  |                 "psr-0": { | ||||||
|  |                     "SystemProcess": "src/main/php/" | ||||||
|  |                 } | ||||||
|  |             }, | ||||||
|  |             "notification-url": "http://packagist.org/downloads/", | ||||||
|  |             "description": "System process execution library", | ||||||
|  |             "time": "2013-03-31 12:42:56" | ||||||
|  |         }, | ||||||
|  |         { | ||||||
|  |             "name": "pdepend/staticReflection", | ||||||
|  |             "version": "0.1", | ||||||
|  |             "source": { | ||||||
|  |                 "type": "git", | ||||||
|  |                 "url": "https://github.com/manuelpichler/staticReflection.git", | ||||||
|  |                 "reference": "origin/master" | ||||||
|  |             }, | ||||||
|  |             "type": "library" | ||||||
|  |         }, | ||||||
|  |         { | ||||||
|  |             "name": "qafoo/rmf", | ||||||
|  |             "version": "dev-master", | ||||||
|  |             "source": { | ||||||
|  |                 "type": "git", | ||||||
|  |                 "url": "https://github.com/Qafoo/REST-Micro-Framework.git", | ||||||
|  |                 "reference": "5f43983f15a8aa12be42ad6068675d4008bfb9ed" | ||||||
|  |             }, | ||||||
|  |             "dist": { | ||||||
|  |                 "type": "zip", | ||||||
|  |                 "url": "https://api.github.com/repos/Qafoo/REST-Micro-Framework/zipball/5f43983f15a8aa12be42ad6068675d4008bfb9ed", | ||||||
|  |                 "reference": "5f43983f15a8aa12be42ad6068675d4008bfb9ed", | ||||||
|  |                 "shasum": "" | ||||||
|  |             }, | ||||||
|  |             "type": "library", | ||||||
|  |             "autoload": { | ||||||
|  |                 "psr-0": { | ||||||
|  |                     "Qafoo\\RMF": "src/main/" | ||||||
|  |                 } | ||||||
|  |             }, | ||||||
|  |             "description": "Very simple VC framework which makes it easy to build HTTP applications / REST webservices", | ||||||
|  |             "support": { | ||||||
|  |                 "source": "https://github.com/Qafoo/REST-Micro-Framework/tree/master", | ||||||
|  |                 "issues": "https://github.com/Qafoo/REST-Micro-Framework/issues" | ||||||
|  |             }, | ||||||
|  |             "time": "2012-12-07 13:33:01" | ||||||
|  |         }, | ||||||
|  |         { | ||||||
|  |             "name": "twig/twig", | ||||||
|  |             "version": "1.6.0", | ||||||
|  |             "source": { | ||||||
|  |                 "type": "git", | ||||||
|  |                 "url": "git://github.com/fabpot/Twig.git", | ||||||
|  |                 "reference": "v1.6.0" | ||||||
|  |             }, | ||||||
|  |             "dist": { | ||||||
|  |                 "type": "zip", | ||||||
|  |                 "url": "https://github.com/fabpot/Twig/zipball/v1.6.0", | ||||||
|  |                 "reference": "v1.6.0", | ||||||
|  |                 "shasum": "" | ||||||
|  |             }, | ||||||
|  |             "require": { | ||||||
|  |                 "php": ">=5.2.4" | ||||||
|  |             }, | ||||||
|  |             "type": "library", | ||||||
|  |             "autoload": { | ||||||
|  |                 "psr-0": { | ||||||
|  |                     "Twig_": "lib/" | ||||||
|  |                 } | ||||||
|  |             }, | ||||||
|  |             "license": [ | ||||||
|  |                 "BSD" | ||||||
|  |             ], | ||||||
|  |             "authors": [ | ||||||
|  |                 { | ||||||
|  |                     "name": "Fabien Potencier", | ||||||
|  |                     "email": "fabien@symfony.com" | ||||||
|  |                 }, | ||||||
|  |                 { | ||||||
|  |                     "name": "Armin Ronacher", | ||||||
|  |                     "email": "armin.ronacher@active-4.com" | ||||||
|  |                 } | ||||||
|  |             ], | ||||||
|  |             "description": "Twig, the flexible, fast, and secure template language for PHP", | ||||||
|  |             "homepage": "http://twig.sensiolabs.org", | ||||||
|  |             "keywords": [ | ||||||
|  |                 "templating" | ||||||
|  |             ], | ||||||
|  |             "time": "2012-02-03 23:34:52" | ||||||
|  |         }, | ||||||
|  |         { | ||||||
|  |             "name": "twitter/bootstrap", | ||||||
|  |             "version": "0.1", | ||||||
|  |             "source": { | ||||||
|  |                 "type": "git", | ||||||
|  |                 "url": "https://github.com/twitter/bootstrap/", | ||||||
|  |                 "reference": "origin/master" | ||||||
|  |             }, | ||||||
|  |             "type": "library" | ||||||
|  |         }, | ||||||
|  |         { | ||||||
|  |             "name": "zetacomponents/base", | ||||||
|  |             "version": "1.8", | ||||||
|  |             "source": { | ||||||
|  |                 "type": "git", | ||||||
|  |                 "url": "https://github.com/zetacomponents/Base.git", | ||||||
|  |                 "reference": "1.8" | ||||||
|  |             }, | ||||||
|  |             "dist": { | ||||||
|  |                 "type": "zip", | ||||||
|  |                 "url": "https://github.com/zetacomponents/Base/zipball/1.8", | ||||||
|  |                 "reference": "1.8", | ||||||
|  |                 "shasum": "" | ||||||
|  |             }, | ||||||
|  |             "type": "library", | ||||||
|  |             "autoload": { | ||||||
|  |                 "classmap": [ | ||||||
|  |                     "src" | ||||||
|  |                 ] | ||||||
|  |             }, | ||||||
|  |             "license": [ | ||||||
|  |                 "apache2" | ||||||
|  |             ], | ||||||
|  |             "authors": [ | ||||||
|  |                 { | ||||||
|  |                     "name": "Sergey Alexeev" | ||||||
|  |                 }, | ||||||
|  |                 { | ||||||
|  |                     "name": "Sebastian Bergmann" | ||||||
|  |                 }, | ||||||
|  |                 { | ||||||
|  |                     "name": "Jan Borsodi" | ||||||
|  |                 }, | ||||||
|  |                 { | ||||||
|  |                     "name": "Raymond Bosman" | ||||||
|  |                 }, | ||||||
|  |                 { | ||||||
|  |                     "name": "Frederik Holljen" | ||||||
|  |                 }, | ||||||
|  |                 { | ||||||
|  |                     "name": "Kore Nordmann" | ||||||
|  |                 }, | ||||||
|  |                 { | ||||||
|  |                     "name": "Derick Rethans" | ||||||
|  |                 }, | ||||||
|  |                 { | ||||||
|  |                     "name": "Vadym Savchuk" | ||||||
|  |                 }, | ||||||
|  |                 { | ||||||
|  |                     "name": "Tobias Schlitt" | ||||||
|  |                 }, | ||||||
|  |                 { | ||||||
|  |                     "name": "Alexandru Stanoi" | ||||||
|  |                 } | ||||||
|  |             ], | ||||||
|  |             "description": "The Base package provides the basic infrastructure that all packages rely on. Therefore every component relies on this package.", | ||||||
|  |             "homepage": "https://github.com/zetacomponents", | ||||||
|  |             "time": "2009-12-21 04:14:16" | ||||||
|  |         }, | ||||||
|  |         { | ||||||
|  |             "name": "zetacomponents/graph", | ||||||
|  |             "version": "1.5", | ||||||
|  |             "source": { | ||||||
|  |                 "type": "git", | ||||||
|  |                 "url": "https://github.com/zetacomponents/Graph.git", | ||||||
|  |                 "reference": "1.5" | ||||||
|  |             }, | ||||||
|  |             "dist": { | ||||||
|  |                 "type": "zip", | ||||||
|  |                 "url": "https://github.com/zetacomponents/Graph/zipball/1.5", | ||||||
|  |                 "reference": "1.5", | ||||||
|  |                 "shasum": "" | ||||||
|  |             }, | ||||||
|  |             "type": "library", | ||||||
|  |             "autoload": { | ||||||
|  |                 "classmap": [ | ||||||
|  |                     "src" | ||||||
|  |                 ] | ||||||
|  |             }, | ||||||
|  |             "license": [ | ||||||
|  |                 "apache2" | ||||||
|  |             ], | ||||||
|  |             "authors": [ | ||||||
|  |                 { | ||||||
|  |                     "name": "Sergey Alexeev" | ||||||
|  |                 }, | ||||||
|  |                 { | ||||||
|  |                     "name": "Sebastian Bergmann" | ||||||
|  |                 }, | ||||||
|  |                 { | ||||||
|  |                     "name": "Jan Borsodi" | ||||||
|  |                 }, | ||||||
|  |                 { | ||||||
|  |                     "name": "Raymond Bosman" | ||||||
|  |                 }, | ||||||
|  |                 { | ||||||
|  |                     "name": "Frederik Holljen" | ||||||
|  |                 }, | ||||||
|  |                 { | ||||||
|  |                     "name": "Kore Nordmann" | ||||||
|  |                 }, | ||||||
|  |                 { | ||||||
|  |                     "name": "Derick Rethans" | ||||||
|  |                 }, | ||||||
|  |                 { | ||||||
|  |                     "name": "Vadym Savchuk" | ||||||
|  |                 }, | ||||||
|  |                 { | ||||||
|  |                     "name": "Tobias Schlitt" | ||||||
|  |                 }, | ||||||
|  |                 { | ||||||
|  |                     "name": "Alexandru Stanoi" | ||||||
|  |                 }, | ||||||
|  |                 { | ||||||
|  |                     "name": "Lars Jankowski" | ||||||
|  |                 }, | ||||||
|  |                 { | ||||||
|  |                     "name": "Elger Thiele" | ||||||
|  |                 }, | ||||||
|  |                 { | ||||||
|  |                     "name": "Michael Maclean" | ||||||
|  |                 } | ||||||
|  |             ], | ||||||
|  |             "description": "A component for creating pie charts, line graphs and other kinds of diagrams.", | ||||||
|  |             "homepage": "https://github.com/zetacomponents", | ||||||
|  |             "time": "2009-12-21 04:26:17" | ||||||
|  |         } | ||||||
|  |     ], | ||||||
|  |     "packages-dev": [ | ||||||
|  |  | ||||||
|  |     ], | ||||||
|  |     "aliases": [ | ||||||
|  |  | ||||||
|  |     ], | ||||||
|  |     "minimum-stability": "stable", | ||||||
|  |     "stability-flags": { | ||||||
|  |         "qafoo/rmf": 20, | ||||||
|  |         "arbit/system-process": 0 | ||||||
|  |     }, | ||||||
|  |     "platform": [ | ||||||
|  |  | ||||||
|  |     ], | ||||||
|  |     "platform-dev": [ | ||||||
|  |  | ||||||
|  |     ] | ||||||
|  | } | ||||||
							
								
								
									
										29
									
								
								samples/JSON5/example.json5
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										29
									
								
								samples/JSON5/example.json5
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,29 @@ | |||||||
|  | /* | ||||||
|  |  * The following is a contrived example, but it illustrates most of the features: | ||||||
|  |  */ | ||||||
|  |  | ||||||
|  | { | ||||||
|  |     foo: 'bar', | ||||||
|  |     while: true, | ||||||
|  |  | ||||||
|  |     this: 'is a \ | ||||||
|  | multi-line string', | ||||||
|  |  | ||||||
|  |     // this is an inline comment | ||||||
|  |     here: 'is another', // inline comment | ||||||
|  |  | ||||||
|  |     /* this is a block comment | ||||||
|  |        that continues on another line */ | ||||||
|  |  | ||||||
|  |     hex: 0xDEADbeef, | ||||||
|  |     half: .5, | ||||||
|  |     delta: +10, | ||||||
|  |     to: Infinity,   // and beyond! | ||||||
|  |  | ||||||
|  |     finally: 'a trailing comma', | ||||||
|  |     oh: [ | ||||||
|  |         "we shouldn't forget", | ||||||
|  |         'arrays can have', | ||||||
|  |         'trailing commas too', | ||||||
|  |     ], | ||||||
|  | } | ||||||
							
								
								
									
										28
									
								
								samples/JSON5/package.json5
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										28
									
								
								samples/JSON5/package.json5
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,28 @@ | |||||||
|  | // This file is written in JSON5 syntax, naturally, but npm needs a regular | ||||||
|  | // JSON file, so compile via `npm run build`. Be sure to keep both in sync! | ||||||
|  |  | ||||||
|  | { | ||||||
|  |     name: 'json5', | ||||||
|  |     version: '0.2.0', | ||||||
|  |     description: 'JSON for the ES5 era.', | ||||||
|  |     keywords: ['json', 'es5'], | ||||||
|  |     author: 'Aseem Kishore <aseem.kishore@gmail.com>', | ||||||
|  |     contributors: [ | ||||||
|  |         'Max Nanasy <max.nanasy@gmail.com>', | ||||||
|  |     ], | ||||||
|  |     main: 'lib/json5.js', | ||||||
|  |     bin: 'lib/cli.js', | ||||||
|  |     dependencies: {}, | ||||||
|  |     devDependencies: { | ||||||
|  |         mocha: '~1.0.3', | ||||||
|  |     }, | ||||||
|  |     scripts: { | ||||||
|  |         build: './lib/cli.js -c package.json5', | ||||||
|  |         test: 'mocha --ui exports --reporter spec', | ||||||
|  |     }, | ||||||
|  |     homepage: 'http://json5.org/', | ||||||
|  |     repository: { | ||||||
|  |         type: 'git', | ||||||
|  |         url: 'https://github.com/aseemk/json5.git', | ||||||
|  |     }, | ||||||
|  | } | ||||||
							
								
								
									
										3
									
								
								samples/Jade/hello.jade
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										3
									
								
								samples/Jade/hello.jade
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,3 @@ | |||||||
|  | p. | ||||||
|  |   Hello, | ||||||
|  |   World! | ||||||
							
								
								
									
										15
									
								
								samples/KRL/helloworld.krl
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										15
									
								
								samples/KRL/helloworld.krl
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,15 @@ | |||||||
|  | ruleset sample { | ||||||
|  |   meta { | ||||||
|  |     name "Hello World" | ||||||
|  |     description << | ||||||
|  | Hello world | ||||||
|  | >> | ||||||
|  |     author "Phil Windley" | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |   // just one rule | ||||||
|  |   rule hello { | ||||||
|  |     select when web pageview | ||||||
|  |     notify("Hello world!", "Just a note to say hello"); | ||||||
|  |   } | ||||||
|  | } | ||||||
							
								
								
									
										111
									
								
								samples/LFE/church.lfe
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										111
									
								
								samples/LFE/church.lfe
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,111 @@ | |||||||
|  | ;; Copyright (c) 2013 Duncan McGreggor <oubiwann@cogitat.io> | ||||||
|  | ;; | ||||||
|  | ;; 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. | ||||||
|  |  | ||||||
|  | ;; File    : church.lfe | ||||||
|  | ;; Author  : Duncan McGreggor | ||||||
|  | ;; Purpose : Demonstrating church numerals from the lambda calculus | ||||||
|  |  | ||||||
|  | ;; The code below was used to create the section of the user guide here: | ||||||
|  | ;;    http://lfe.github.io/user-guide/recursion/5.html | ||||||
|  | ;; | ||||||
|  | ;; Here is some example usage: | ||||||
|  | ;; | ||||||
|  | ;; > (slurp '"church.lfe") | ||||||
|  | ;; #(ok church) | ||||||
|  | ;; > (zero) | ||||||
|  | ;; #Fun<lfe_eval.10.53503600> | ||||||
|  | ;; > (church->int1 (zero)) | ||||||
|  | ;; 0 | ||||||
|  | ;; > (church->int1 (three)) | ||||||
|  | ;; 3 | ||||||
|  | ;; > (church->int1 (five)) | ||||||
|  | ;; 5 | ||||||
|  | ;; > (church->int2 #'five/0) | ||||||
|  | ;; 5 | ||||||
|  | ;; > (church->int2 (lambda () (get-church 25))) | ||||||
|  | ;; 25 | ||||||
|  |  | ||||||
|  | (defmodule church | ||||||
|  |   (export all)) | ||||||
|  |  | ||||||
|  | (defun zero () | ||||||
|  |   (lambda (s) | ||||||
|  |     (lambda (x) x))) | ||||||
|  |  | ||||||
|  | (defun one () | ||||||
|  |   (lambda (s) | ||||||
|  |     (lambda (x) | ||||||
|  |       (funcall s x)))) | ||||||
|  |  | ||||||
|  | (defun two () | ||||||
|  |   (lambda (s) | ||||||
|  |     (lambda (x) | ||||||
|  |       (funcall s | ||||||
|  |         (funcall s x))))) | ||||||
|  |  | ||||||
|  | (defun three () | ||||||
|  |   (lambda (s) | ||||||
|  |     (lambda (x) | ||||||
|  |       (funcall s | ||||||
|  |         (funcall s | ||||||
|  |           (funcall s x)))))) | ||||||
|  |  | ||||||
|  | (defun four () | ||||||
|  |   (lambda (s) | ||||||
|  |     (lambda (x) | ||||||
|  |       (funcall s | ||||||
|  |         (funcall s | ||||||
|  |           (funcall s | ||||||
|  |             (funcall s x))))))) | ||||||
|  |  | ||||||
|  | (defun five () | ||||||
|  |   (get-church 5)) | ||||||
|  |  | ||||||
|  | (defun int-successor (n) | ||||||
|  |   (+ n 1)) | ||||||
|  |  | ||||||
|  | (defun church->int1 (church-numeral) | ||||||
|  |   " | ||||||
|  |   Converts a called church numeral to an integer, e.g.: | ||||||
|  |   > (church->int1 (five)) | ||||||
|  |   " | ||||||
|  |   (funcall | ||||||
|  |     (funcall church-numeral #'int-successor/1) 0)) | ||||||
|  |  | ||||||
|  | (defun church->int2 (church-numeral) | ||||||
|  |   " | ||||||
|  |   Converts a non-called church numeral to an integer, e.g.: | ||||||
|  |   > (church->int2 #'five/0) | ||||||
|  |   " | ||||||
|  |   (funcall | ||||||
|  |     (funcall | ||||||
|  |       (funcall church-numeral) #'int-successor/1) 0)) | ||||||
|  |  | ||||||
|  | (defun church-successor (church-numeral) | ||||||
|  |   (lambda (s) | ||||||
|  |     (lambda (x) | ||||||
|  |       (funcall s | ||||||
|  |         (funcall | ||||||
|  |           (funcall church-numeral s) x))))) | ||||||
|  |  | ||||||
|  | (defun get-church (church-numeral count limit) | ||||||
|  |   (cond ((== count limit) church-numeral) | ||||||
|  |         ((/= count limit) | ||||||
|  |          (get-church | ||||||
|  |            (church-successor church-numeral) | ||||||
|  |            (+ 1 count) | ||||||
|  |            limit)))) | ||||||
|  |  | ||||||
|  | (defun get-church (integer) | ||||||
|  |   (get-church (zero) 0 integer)) | ||||||
							
								
								
									
										104
									
								
								samples/LFE/gps1.lfe
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										104
									
								
								samples/LFE/gps1.lfe
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,104 @@ | |||||||
|  | ;;; -*- Mode: LFE; -*- | ||||||
|  | ;;; Code from Paradigms of Artificial Intelligence Programming | ||||||
|  | ;;; Copyright (c) 1991 Peter Norvig | ||||||
|  |  | ||||||
|  | ;;;; File gps1.lisp: First version of GPS (General Problem Solver) | ||||||
|  |  | ||||||
|  | ;;;; Converted to LFE by Robert Virding | ||||||
|  |  | ||||||
|  | ;; Define macros for global variable access. This is a hack and very naughty! | ||||||
|  | (defsyntax defvar | ||||||
|  |   ([name val] (let ((v val)) (put 'name v) v))) | ||||||
|  |  | ||||||
|  | (defsyntax setvar | ||||||
|  |   ([name val] (let ((v val)) (put 'name v) v))) | ||||||
|  |  | ||||||
|  | (defsyntax getvar | ||||||
|  |   ([name] (get 'name))) | ||||||
|  |  | ||||||
|  | ;; Module definition. | ||||||
|  |  | ||||||
|  | (defmodule gps1 | ||||||
|  |   (export (gps 2) (gps 3) (school-ops 0)) | ||||||
|  |   (import (from lists (member 2) (all 2) (any 2)) | ||||||
|  |       ;; Rename lists functions to be more CL like. | ||||||
|  |       (rename lists ((all 2) every) ((any 2) some) ((filter 2) find-all)))) | ||||||
|  |  | ||||||
|  | ;; An operation. | ||||||
|  | (defrecord op | ||||||
|  |   action preconds add-list del-list) | ||||||
|  |  | ||||||
|  | ;; General Problem Solver: achieve all goals using *ops*. | ||||||
|  | (defun gps (state goals ops) | ||||||
|  |   ;; Set global variables | ||||||
|  |   (defvar *state* state)    ;The current state: a list of conditions. | ||||||
|  |   (defvar *ops* ops)        ;A list of available operators. | ||||||
|  |   (if (every (fun achieve 1) goals) 'solved)) | ||||||
|  |  | ||||||
|  | (defun gps (state goals) | ||||||
|  |   ;; Set global variables, but use existing *ops* | ||||||
|  |   (defvar *state* state)    ;The current state: a list of conditions. | ||||||
|  |   (if (every (fun achieve 1) goals) 'solved)) | ||||||
|  |  | ||||||
|  | ;; A goal is achieved if it already holds or if there is an | ||||||
|  | ;; appropriate op for it that is applicable." | ||||||
|  | (defun achieve (goal) | ||||||
|  |   (orelse (member goal (getvar *state*)) | ||||||
|  |       (some (fun apply-op 1) | ||||||
|  |         (find-all (lambda (op) (appropriate-p goal op)) | ||||||
|  |               (getvar *ops*))))) | ||||||
|  |  | ||||||
|  | ;; An op is appropriate to a goal if it is in its add list. | ||||||
|  | (defun appropriate-p (goal op) | ||||||
|  |   (member goal (op-add-list op))) | ||||||
|  |  | ||||||
|  | ;; Print a message and update *state* if op is applicable. | ||||||
|  | (defun apply-op (op) | ||||||
|  |   (if (every (fun achieve 1) (op-preconds op)) | ||||||
|  |     (progn | ||||||
|  |       (: io fwrite '"executing ~p\n" (list (op-action op))) | ||||||
|  |       (setvar *state* (set-difference (getvar *state*) (op-del-list op))) | ||||||
|  |       (setvar *state* (union (getvar *state*) (op-add-list op))) | ||||||
|  |       'true))) | ||||||
|  |  | ||||||
|  | ;; Define the set functions to work on list, a listsets module really. | ||||||
|  | (defun set-difference | ||||||
|  |   ([(cons e es) s2] | ||||||
|  |    (if (member e s2) | ||||||
|  |      (set-difference es s2) | ||||||
|  |      (cons e (set-difference es s2)))) | ||||||
|  |   ([() s2] ())) | ||||||
|  |  | ||||||
|  | (defun union | ||||||
|  |   ([(cons e es) s2] | ||||||
|  |    (if (member e s2) (union es s2) (cons e (union es s2)))) | ||||||
|  |   ([() s2] ())) | ||||||
|  |  | ||||||
|  | ;;; ============================== | ||||||
|  |  | ||||||
|  | (defun school-ops () | ||||||
|  |   (list | ||||||
|  |     (make-op action 'drive-son-to-school | ||||||
|  |          preconds '(son-at-home car-works) | ||||||
|  |          add-list '(son-at-school) | ||||||
|  |          del-list '(son-at-home)) | ||||||
|  |     (make-op action 'shop-installs-battery | ||||||
|  |          preconds '(car-needs-battery shop-knows-problem shop-has-money) | ||||||
|  |          add-list '(car-works) | ||||||
|  |          del-list ()) | ||||||
|  |     (make-op action 'tell-shop-problem | ||||||
|  |          preconds '(in-communication-with-shop) | ||||||
|  |          add-list '(shop-knows-problem) | ||||||
|  |          del-list ()) | ||||||
|  |     (make-op action 'telephone-shop | ||||||
|  |          preconds '(know-phone-number) | ||||||
|  |          add-list '(in-communication-with-shop) | ||||||
|  |          del-list ()) | ||||||
|  |     (make-op action 'look-up-number | ||||||
|  |          preconds '(have-phone-book) | ||||||
|  |          add-list '(know-phone-number) | ||||||
|  |          del-list ()) | ||||||
|  |     (make-op action 'give-shop-money | ||||||
|  |          preconds '(have-money) | ||||||
|  |          add-list '(shop-has-money) | ||||||
|  |          del-list '(have-money)))) | ||||||
							
								
								
									
										83
									
								
								samples/LFE/mnesia_demo.lfe
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										83
									
								
								samples/LFE/mnesia_demo.lfe
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,83 @@ | |||||||
|  | ;; Copyright (c) 2008-2013 Robert Virding | ||||||
|  | ;; | ||||||
|  | ;; 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. | ||||||
|  |  | ||||||
|  | ;; File    : mnesia_demo.lfe | ||||||
|  | ;; Author  : Robert Virding | ||||||
|  | ;; Purpose : A simple Mnesia demo file for LFE. | ||||||
|  |  | ||||||
|  | ;; This file contains a simple demo of using LFE to access Mnesia | ||||||
|  | ;; tables.  It shows how to use the emp-XXXX macro (ETS match pattern) | ||||||
|  | ;; together with mnesia:match_object, match specifications with | ||||||
|  | ;; mnesia:select and Query List Comprehensions. | ||||||
|  |  | ||||||
|  | (defmodule mnesia_demo | ||||||
|  |   (export (new 0) (by_place 1) (by_place_ms 1) (by_place_qlc 1))) | ||||||
|  |  | ||||||
|  | (defrecord person name place job) | ||||||
|  |  | ||||||
|  | (defun new () | ||||||
|  |   ;; Start mnesia and create a table, we will get an in memory only schema. | ||||||
|  |   (: mnesia start) | ||||||
|  |   (: mnesia create_table 'person '(#(attributes (name place job)))) | ||||||
|  |   ;; Initialise the table. | ||||||
|  |   (let ((people '( | ||||||
|  |           ;; First some people in London. | ||||||
|  |           #(fred london waiter) | ||||||
|  |           #(bert london waiter) | ||||||
|  |           #(john london painter) | ||||||
|  |           #(paul london driver) | ||||||
|  |           ;; Now some in Paris. | ||||||
|  |           #(jean paris waiter) | ||||||
|  |           #(gerard paris driver) | ||||||
|  |           #(claude paris painter) | ||||||
|  |           #(yves paris waiter) | ||||||
|  |           ;; And some in Rome. | ||||||
|  |           #(roberto rome waiter) | ||||||
|  |           #(guiseppe rome driver) | ||||||
|  |           #(paulo rome painter) | ||||||
|  |           ;; And some in Berlin. | ||||||
|  |           #(fritz berlin painter) | ||||||
|  |           #(kurt berlin driver) | ||||||
|  |           #(hans berlin waiter) | ||||||
|  |           #(franz berlin waiter) | ||||||
|  |           ))) | ||||||
|  |     (: lists foreach (match-lambda | ||||||
|  |                ([(tuple n p j)] | ||||||
|  |             (: mnesia transaction | ||||||
|  |               (lambda () | ||||||
|  |                 (let ((new (make-person name n place p job j))) | ||||||
|  |                   (: mnesia write new)))))) | ||||||
|  |        people))) | ||||||
|  |  | ||||||
|  | ;; Match records by place using match_object and the emp-XXXX macro. | ||||||
|  | (defun by_place (place) | ||||||
|  |   (: mnesia transaction | ||||||
|  |     (lambda () (: mnesia match_object (emp-person place place))))) | ||||||
|  |  | ||||||
|  | ;; Use match specifications to match records | ||||||
|  | (defun by_place_ms (place) | ||||||
|  |   (let ((f (lambda () (: mnesia select 'person | ||||||
|  |              (match-spec ([(match-person name n place p job j)] | ||||||
|  |                       (when (=:= p place)) | ||||||
|  |                       (tuple n j))))))) | ||||||
|  |     (: mnesia transaction f))) | ||||||
|  |  | ||||||
|  | ;; Use Query List Comprehensions to match records | ||||||
|  | (defun by_place_qlc (place) | ||||||
|  |   (let ((f (lambda () | ||||||
|  |          (let ((q (qlc (lc ((<- person (: mnesia table 'person)) | ||||||
|  |                 (=:= (person-place person) place)) | ||||||
|  |                  person)))) | ||||||
|  |            (: qlc e q))))) | ||||||
|  |     (: mnesia transaction f))) | ||||||
							
								
								
									
										169
									
								
								samples/LFE/object.lfe
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										169
									
								
								samples/LFE/object.lfe
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,169 @@ | |||||||
|  | ;; Copyright (c) 2013 Duncan McGreggor <oubiwann@cogitat.io> | ||||||
|  | ;; | ||||||
|  | ;; 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. | ||||||
|  |  | ||||||
|  | ;; File    : object.lfe | ||||||
|  | ;; Author  : Duncan McGreggor | ||||||
|  | ;; Purpose : Demonstrating simple OOP with closures | ||||||
|  |  | ||||||
|  | ;; The simple object system demonstrated below shows how to do the following: | ||||||
|  | ;;  * create objects | ||||||
|  | ;;  * call methods on those objects | ||||||
|  | ;;  * have methods which can call other methods | ||||||
|  | ;;  * update the state of an instance variable | ||||||
|  | ;; | ||||||
|  | ;; Note, however, that his example does not demonstrate inheritance. | ||||||
|  | ;; | ||||||
|  | ;; To use the code below in LFE, do the following: | ||||||
|  | ;; | ||||||
|  | ;;  $ cd examples | ||||||
|  | ;;  $ ../bin/lfe -pa ../ebin | ||||||
|  | ;; | ||||||
|  | ;; Load the file and create a fish-class instance: | ||||||
|  | ;; | ||||||
|  | ;; > (slurp '"object.lfe") | ||||||
|  | ;; #(ok object) | ||||||
|  | ;; > (set mommy-fish (fish-class '"Carp")) | ||||||
|  | ;; #Fun<lfe_eval.10.91765564> | ||||||
|  | ;; | ||||||
|  | ;; Execute some of the basic methods: | ||||||
|  | ;; | ||||||
|  | ;; > (get-species mommy-fish) | ||||||
|  | ;; "Carp" | ||||||
|  | ;; > (move mommy-fish 17) | ||||||
|  | ;; The Carp swam 17 feet! | ||||||
|  | ;; ok | ||||||
|  | ;; > (get-id mommy-fish) | ||||||
|  | ;; "47eebe91a648f042fc3fb278df663de5" | ||||||
|  | ;; | ||||||
|  | ;; Now let's look at "modifying" state data (e.g., children counts): | ||||||
|  | ;; | ||||||
|  | ;; > (get-children mommy-fish) | ||||||
|  | ;; () | ||||||
|  | ;; > (get-children-count mommy-fish) | ||||||
|  | ;; 0 | ||||||
|  | ;; > (set (mommy-fish baby-fish-1) (reproduce mommy-fish)) | ||||||
|  | ;; (#Fun<lfe_eval.10.91765564> #Fun<lfe_eval.10.91765564>) | ||||||
|  | ;; > (get-id mommy-fish) | ||||||
|  | ;; "47eebe91a648f042fc3fb278df663de5" | ||||||
|  | ;; > (get-id baby-fish-1) | ||||||
|  | ;; "fdcf35983bb496650e558a82e34c9935" | ||||||
|  | ;; > (get-children-count mommy-fish) | ||||||
|  | ;; 1 | ||||||
|  | ;; > (set (mommy-fish baby-fish-2) (reproduce mommy-fish)) | ||||||
|  | ;; (#Fun<lfe_eval.10.91765564> #Fun<lfe_eval.10.91765564>) | ||||||
|  | ;; > (get-id mommy-fish) | ||||||
|  | ;; "47eebe91a648f042fc3fb278df663de5" | ||||||
|  | ;; > (get-id baby-fish-2) | ||||||
|  | ;; "3e64e5c20fb742dd88dac1032749c2fd" | ||||||
|  | ;; > (get-children-count mommy-fish) | ||||||
|  | ;; 2 | ||||||
|  | ;; > (get-info mommy-fish) | ||||||
|  | ;; id: "47eebe91a648f042fc3fb278df663de5" | ||||||
|  | ;; species: "Carp" | ||||||
|  | ;; children: ["fdcf35983bb496650e558a82e34c9935", | ||||||
|  | ;;            "3e64e5c20fb742dd88dac1032749c2fd"] | ||||||
|  | ;; ok | ||||||
|  |  | ||||||
|  | (defmodule object | ||||||
|  |  (export all)) | ||||||
|  |  | ||||||
|  | (defun fish-class (species) | ||||||
|  |   " | ||||||
|  |   This is the constructor that will be used most often, only requiring that | ||||||
|  |   one pass a 'species' string. | ||||||
|  |  | ||||||
|  |   When the children are not defined, simply use an empty list. | ||||||
|  |   " | ||||||
|  |   (fish-class species ())) | ||||||
|  |  | ||||||
|  | (defun fish-class (species children) | ||||||
|  |   " | ||||||
|  |   This contructor is mostly useful as a way of abstracting out the id | ||||||
|  |   generation from the larger constructor. Nothing else uses fish-class/2 | ||||||
|  |   besides fish-class/1, so it's not strictly necessary. | ||||||
|  |  | ||||||
|  |   When the id isn't know, generate one." | ||||||
|  |   (let* (((binary (id (size 128))) (: crypto rand_bytes 16)) | ||||||
|  |          (formatted-id (car | ||||||
|  |                          (: io_lib format | ||||||
|  |                            '"~32.16.0b" (list id))))) | ||||||
|  |     (fish-class species children formatted-id))) | ||||||
|  |  | ||||||
|  | (defun fish-class (species children id) | ||||||
|  |   " | ||||||
|  |   This is the constructor used internally, once the children and fish id are | ||||||
|  |   known. | ||||||
|  |   " | ||||||
|  |   (let ((move-verb '"swam")) | ||||||
|  |     (lambda (method-name) | ||||||
|  |       (case method-name | ||||||
|  |         ('id | ||||||
|  |           (lambda (self) id)) | ||||||
|  |         ('species | ||||||
|  |           (lambda (self) species)) | ||||||
|  |         ('children | ||||||
|  |           (lambda (self) children)) | ||||||
|  |         ('info | ||||||
|  |           (lambda (self) | ||||||
|  |             (: io format | ||||||
|  |               '"id: ~p~nspecies: ~p~nchildren: ~p~n" | ||||||
|  |               (list (get-id self) | ||||||
|  |                     (get-species self) | ||||||
|  |                     (get-children self))))) | ||||||
|  |         ('move | ||||||
|  |           (lambda (self distance) | ||||||
|  |             (: io format | ||||||
|  |               '"The ~s ~s ~p feet!~n" | ||||||
|  |               (list species move-verb distance)))) | ||||||
|  |         ('reproduce | ||||||
|  |           (lambda (self) | ||||||
|  |             (let* ((child (fish-class species)) | ||||||
|  |                    (child-id (get-id child)) | ||||||
|  |                    (children-ids (: lists append | ||||||
|  |                                    (list children (list child-id)))) | ||||||
|  |                    (parent-id (get-id self)) | ||||||
|  |                    (parent (fish-class species children-ids parent-id))) | ||||||
|  |               (list parent child)))) | ||||||
|  |         ('children-count | ||||||
|  |           (lambda (self) | ||||||
|  |             (: erlang length children))))))) | ||||||
|  |  | ||||||
|  | (defun get-method (object method-name) | ||||||
|  |   " | ||||||
|  |   This is a generic function, used to call into the given object (class | ||||||
|  |   instance). | ||||||
|  |   " | ||||||
|  |   (funcall object method-name)) | ||||||
|  |  | ||||||
|  | ; define object methods | ||||||
|  | (defun get-id (object) | ||||||
|  |   (funcall (get-method object 'id) object)) | ||||||
|  |  | ||||||
|  | (defun get-species (object) | ||||||
|  |   (funcall (get-method object 'species) object)) | ||||||
|  |  | ||||||
|  | (defun get-info (object) | ||||||
|  |   (funcall (get-method object 'info) object)) | ||||||
|  |  | ||||||
|  | (defun move (object distance) | ||||||
|  |   (funcall (get-method object 'move) object distance)) | ||||||
|  |  | ||||||
|  | (defun reproduce (object) | ||||||
|  |   (funcall (get-method object 'reproduce) object)) | ||||||
|  |  | ||||||
|  | (defun get-children (object) | ||||||
|  |   (funcall (get-method object 'children) object)) | ||||||
|  |  | ||||||
|  | (defun get-children-count (object) | ||||||
|  |   (funcall (get-method object 'children-count) object)) | ||||||
							
								
								
									
										82
									
								
								samples/Literate Agda/NatCat.lagda
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										82
									
								
								samples/Literate Agda/NatCat.lagda
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,82 @@ | |||||||
|  | \documentclass{article} | ||||||
|  |  | ||||||
|  |  % The following packages are needed because unicode | ||||||
|  |  % is translated (using the next set of packages) to | ||||||
|  |  % latex commands. You may need more packages if you | ||||||
|  |  % use more unicode characters: | ||||||
|  |  | ||||||
|  |  \usepackage{amssymb} | ||||||
|  |  \usepackage{bbm} | ||||||
|  |  \usepackage[greek,english]{babel} | ||||||
|  |  | ||||||
|  |  % This handles the translation of unicode to latex: | ||||||
|  |  | ||||||
|  |  \usepackage{ucs} | ||||||
|  |  \usepackage[utf8x]{inputenc} | ||||||
|  |  \usepackage{autofe} | ||||||
|  |  | ||||||
|  |  % Some characters that are not automatically defined | ||||||
|  |  % (you figure out by the latex compilation errors you get), | ||||||
|  |  % and you need to define: | ||||||
|  |  | ||||||
|  |  \DeclareUnicodeCharacter{8988}{\ensuremath{\ulcorner}} | ||||||
|  |  \DeclareUnicodeCharacter{8989}{\ensuremath{\urcorner}} | ||||||
|  |  \DeclareUnicodeCharacter{8803}{\ensuremath{\overline{\equiv}}} | ||||||
|  |  | ||||||
|  |  % Add more as you need them (shouldn’t happen often). | ||||||
|  |  | ||||||
|  |  % Using “\newenvironment” to redefine verbatim to | ||||||
|  |  % be called “code” doesn’t always work properly.  | ||||||
|  |  % You can more reliably use: | ||||||
|  |  | ||||||
|  |  \usepackage{fancyvrb} | ||||||
|  |  | ||||||
|  |  \DefineVerbatimEnvironment | ||||||
|  |    {code}{Verbatim} | ||||||
|  |    {} % Add fancy options here if you like. | ||||||
|  |  | ||||||
|  |  \begin{document} | ||||||
|  |  | ||||||
|  |  \begin{code} | ||||||
|  | module NatCat where | ||||||
|  |  | ||||||
|  | open import Relation.Binary.PropositionalEquality | ||||||
|  |  | ||||||
|  | -- If you can show that a relation only ever has one inhabitant | ||||||
|  | -- you get the category laws for free | ||||||
|  | module | ||||||
|  |   EasyCategory | ||||||
|  |   (obj : Set) | ||||||
|  |   (_⟶_ : obj → obj → Set) | ||||||
|  |   (_∘_ : ∀ {x y z} → x ⟶ y → y ⟶ z → x ⟶ z) | ||||||
|  |   (id : ∀ x → x ⟶ x) | ||||||
|  |   (single-inhabitant : (x y : obj) (r s : x ⟶ y) → r ≡ s) | ||||||
|  |   where | ||||||
|  |  | ||||||
|  |   idʳ : ∀ x y (r : x ⟶ y) → r ∘ id y ≡ r | ||||||
|  |   idʳ x y r = single-inhabitant x y (r ∘ id y) r  | ||||||
|  |  | ||||||
|  |   idˡ : ∀ x y (r : x ⟶ y) → id x ∘ r ≡ r | ||||||
|  |   idˡ x y r = single-inhabitant x y (id x ∘ r) r | ||||||
|  |  | ||||||
|  |   ∘-assoc : ∀ w x y z (r : w ⟶ x) (s : x ⟶ y) (t : y ⟶ z) → (r ∘ s) ∘ t ≡ r ∘ (s ∘ t) | ||||||
|  |   ∘-assoc w x y z r s t = single-inhabitant w z ((r ∘ s) ∘ t) (r ∘ (s ∘ t)) | ||||||
|  |  | ||||||
|  | open import Data.Nat | ||||||
|  |  | ||||||
|  | same : (x y : ℕ) (r s : x ≤ y) → r ≡ s | ||||||
|  | same .0 y z≤n z≤n = refl | ||||||
|  | same .(suc m) .(suc n) (s≤s {m} {n} r) (s≤s s) = cong s≤s (same m n r s) | ||||||
|  |  | ||||||
|  | ≤-trans : ∀ x y z → x ≤ y → y ≤ z → x ≤ z | ||||||
|  | ≤-trans .0 y z z≤n s = z≤n | ||||||
|  | ≤-trans .(suc m) .(suc n) .(suc n₁) (s≤s {m} {n} r) (s≤s {.n} {n₁} s) = s≤s (≤-trans m n n₁ r s) | ||||||
|  |  | ||||||
|  | ≤-refl : ∀ x → x ≤ x | ||||||
|  | ≤-refl zero = z≤n | ||||||
|  | ≤-refl (suc x) = s≤s (≤-refl x) | ||||||
|  |  | ||||||
|  | module Nat-EasyCategory = EasyCategory ℕ _≤_ (λ {x}{y}{z} → ≤-trans x y z) ≤-refl same | ||||||
|  |  \end{code} | ||||||
|  |  | ||||||
|  |  \end{document}  | ||||||
							
								
								
									
										16
									
								
								samples/Makefile/filenames/Makefile
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										16
									
								
								samples/Makefile/filenames/Makefile
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,16 @@ | |||||||
|  | all: hello | ||||||
|  |  | ||||||
|  | hello: main.o factorial.o hello.o | ||||||
|  | 	g++ main.o factorial.o hello.o -o hello | ||||||
|  |  | ||||||
|  | main.o: main.cpp | ||||||
|  | 	g++ -c main.cpp | ||||||
|  |  | ||||||
|  | factorial.o: factorial.cpp | ||||||
|  | 	g++ -c factorial.cpp | ||||||
|  |  | ||||||
|  | hello.o: hello.cpp | ||||||
|  | 	g++ -c hello.cpp | ||||||
|  |  | ||||||
|  | clean: | ||||||
|  | 	rm -rf *o hello | ||||||
							
								
								
									
										3
									
								
								samples/Makefile/makefile.script!
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										3
									
								
								samples/Makefile/makefile.script!
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,3 @@ | |||||||
|  | #!/usr/bin/make -f | ||||||
|  | %: | ||||||
|  | 	ls -l | ||||||
							
								
								
									
										31
									
								
								samples/Matlab/cross_validation.m
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										31
									
								
								samples/Matlab/cross_validation.m
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,31 @@ | |||||||
|  | function [ error ] = cross_validation(x,y,hyper_parameter) | ||||||
|  |      | ||||||
|  |     num_data = size(x,1); | ||||||
|  |  | ||||||
|  |     K = 10; | ||||||
|  |     indices = crossvalind('Kfold', num_data, K); | ||||||
|  |  | ||||||
|  |     errors = zeros(K,1); | ||||||
|  |     for i = 1:K | ||||||
|  |         % get indices | ||||||
|  |         test_idx = (indices == i); | ||||||
|  |         train_idx = ~test_idx; | ||||||
|  |  | ||||||
|  |         % get training data | ||||||
|  |         x_train = x(train_idx,:); | ||||||
|  |         y_train = y(train_idx,:); | ||||||
|  |  | ||||||
|  |         % train | ||||||
|  |         w = train(x_train, y_train, hyper_parameter); | ||||||
|  |  | ||||||
|  |         % get test data | ||||||
|  |         x_test = x(test_idx,:); | ||||||
|  |         y_test = y(test_idx,:); | ||||||
|  |          | ||||||
|  |         % calculate error | ||||||
|  |         errors(i) = calc_cost(x_test, y_test, w, hyper_parameter); %calc_error | ||||||
|  |         %errors(i) = calc_error(x_test, y_test, w); | ||||||
|  |     end | ||||||
|  |      | ||||||
|  |     error = mean(errors); | ||||||
|  | end | ||||||
							
								
								
									
										6
									
								
								samples/Matlab/normalize.m
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										6
									
								
								samples/Matlab/normalize.m
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,6 @@ | |||||||
|  | function [ d, d_mean, d_std ] = normalize( d ) | ||||||
|  |     d_mean = mean(d); | ||||||
|  |     d = d - repmat(d_mean, size(d,1), 1); | ||||||
|  |     d_std = std(d); | ||||||
|  |     d = d./ repmat(d_std, size(d,1), 1); | ||||||
|  | end | ||||||
							
								
								
									
										90
									
								
								samples/MediaWiki/mediawiki.mediawiki
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										90
									
								
								samples/MediaWiki/mediawiki.mediawiki
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,90 @@ | |||||||
|  |  | ||||||
|  | = Overview = | ||||||
|  |  | ||||||
|  | The GDB Tracepoint Analysis feature is an extension to the Tracing and Monitoring Framework that allows the visualization and analysis of C/C++ tracepoint data collected by GDB and stored to a log file. | ||||||
|  |  | ||||||
|  | = Getting Started = | ||||||
|  |  | ||||||
|  | The feature can be installed from the Eclipse update site by selecting '''Linux Tools''' > '''GDB Tracepoint Analysis'''. | ||||||
|  |  | ||||||
|  | The feature requires GDB version 7.2 or later to be installed on the local host. The executable program 'gdb' must be found in the path. | ||||||
|  |  | ||||||
|  | = GDB Trace Perspective = | ||||||
|  |  | ||||||
|  | To open the perspective, select '''Window''' > '''Open Perspective''' > '''Other...''' > '''GDB Trace'''. | ||||||
|  |  | ||||||
|  | The perspective includes the following views by default: | ||||||
|  |  | ||||||
|  | * '''Project Explorer''': This view shows the projects in the workspace and is used to create and manage Tracing projects. | ||||||
|  | * '''Debug''': This view shows the running C/C++ Postmortem Debugger instances and displays the thread and stack trace associated with a tracepoint. | ||||||
|  | * '''Trace Control''': This view shows the status of the debugger and allows navigation of trace records. | ||||||
|  | * '''Console''': This view displays console output of the C/C++ Postmortem Debugger. | ||||||
|  |  | ||||||
|  | The editor area contains the '''Events''' and '''C/C++''' editors when a GDB Trace is opened. | ||||||
|  |  | ||||||
|  | [[Image:images/GDBTracePerspective.png]] | ||||||
|  |  | ||||||
|  | = Collecting Tracepoint Data = | ||||||
|  |  | ||||||
|  | Collecting the C/C++ tracepoint data is outside the scope of this feature. It can be done from the GDB command line or by using the CDT debug component within Eclipse. See the CDT FAQ entry in the [[#References | References]] section. | ||||||
|  |  | ||||||
|  | = Importing Tracepoint Data = | ||||||
|  |  | ||||||
|  | Some information in this section is redundant with the LTTng User Guide. For further details, see the LTTng User Guide entry in the [[#References | References]] section. | ||||||
|  |  | ||||||
|  | == Creating a Tracing Project == | ||||||
|  |  | ||||||
|  | In the '''Project Explorer''' view, right-click and select '''New''' > '''Project...''' from the context menu. In the '''New Project''' dialog, select '''Tracing''' > '''Tracing Project''', click '''Next''', name your project and click '''Finish'''. | ||||||
|  |  | ||||||
|  | == Importing a GDB Trace == | ||||||
|  |  | ||||||
|  | In your tracing project, right-click on the '''Traces''' folder and select '''Import...'''. Browse to, or enter, a source directory. Select the trace file in the tree. Optionally set the trace type to '''GDB : GDB Trace'''. Click '''Finish'''. | ||||||
|  |  | ||||||
|  | Alternatively, the trace can be drag & dropped to the '''Traces''' folder from any external file manager. | ||||||
|  |  | ||||||
|  | == Selecting the GDB Trace Type == | ||||||
|  |  | ||||||
|  | Right-click the imported trace in the '''Traces''' folder and choose '''Select Trace Type...''' > '''GDB''' > '''GDB Trace''' from the context menu. This step can be omitted if the trace type was selected at import. | ||||||
|  |  | ||||||
|  | The trace will be updated with the GDB icon [[Image:images/gdb_icon16.png]]. | ||||||
|  |  | ||||||
|  | == Selecting the Trace Executable == | ||||||
|  |  | ||||||
|  | The executable file that created the tracepoint data must be identified so that the C/C++ Postmortem Debugger can be launched properly. | ||||||
|  |  | ||||||
|  | Right-click the GDB trace in the '''Traces''' folder and choose '''Select Trace Executable...''' from the context menu. Browse to, or enter, the path of the executable file and press '''OK'''. | ||||||
|  |  | ||||||
|  | The selected file must be recognized by GDB as an executable. | ||||||
|  |  | ||||||
|  | = Visualizing Tracepoint Data = | ||||||
|  |  | ||||||
|  | == Opening a GDB Trace == | ||||||
|  |  | ||||||
|  | In the '''Traces''' folder, double-click the GDB trace or right-click it and select '''Open''' from the context menu. | ||||||
|  |  | ||||||
|  | The tracepoint data will be opened in an Events editor, and a C/C++ Postmortem Debugger instance will be launched. | ||||||
|  |  | ||||||
|  | If available in the workspace, the source code corresponding to the first trace record will also be opened in a C/C++ editor. | ||||||
|  |  | ||||||
|  | At this point it is recommended to relocate the Events editor outside of the default editor area, so that it is not hidden by the C/C++ editor. | ||||||
|  |  | ||||||
|  | == Viewing Trace Data == | ||||||
|  |  | ||||||
|  | In the Events editor, a table is shown with one row for each trace record. The '''Trace Frame''' column shows the sequential trace record number. The '''Tracepoint''' column shows the number assigned by GDB at collection time for this tracepoint. The '''File''' column shows the file name, line number and method where the tracepoint was set. The '''Content''' column shows the data collected at run-time by the tracepoint. | ||||||
|  |  | ||||||
|  | Searching and filtering can be done on any column by entering a regular expression in the column header. | ||||||
|  |  | ||||||
|  | == Navigating the GDB Trace == | ||||||
|  |  | ||||||
|  | Trace records can be selected in the Events editor using the keyboard or mouse. The C/C++ Postmortem Debugger in the '''Debug''' view will be updated to show the stack trace of the current trace record. | ||||||
|  |  | ||||||
|  | The trace can also be navigated from the '''Trace Control''' view by clicking the '''Next Trace Record''' or '''Previous Trace Record''' buttons. The Events editor and '''Debug''' views will be updated. | ||||||
|  |  | ||||||
|  | = References = | ||||||
|  |  | ||||||
|  | * [http://wiki.eclipse.org/index.php/Linux_Tools_Project/LTTng2/User_Guide LTTng User Guide] | ||||||
|  | * [http://wiki.eclipse.org/CDT/User/FAQ#How_can_I_trace_my_application_using_C.2FC.2B.2B_Tracepoints.3F CDT FAQ - How can I trace my application using C/C++ Tracepoints?] | ||||||
|  |  | ||||||
|  | = Updating This Document = | ||||||
|  |  | ||||||
|  | This document is maintained in a collaborative wiki.  If you wish to update or modify this document please visit [http://wiki.eclipse.org/index.php/Linux_Tools_Project/GDB_Tracepoint_Analysis/User_Guide http://wiki.eclipse.org/Linux_Tools_Project/GDB_Tracepoint_Analysis/User_Guide] | ||||||
							
								
								
									
										55
									
								
								samples/NetLogo/Life.nlogo
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										55
									
								
								samples/NetLogo/Life.nlogo
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,55 @@ | |||||||
|  | patches-own [ | ||||||
|  |   living?         ;; indicates if the cell is living | ||||||
|  |   live-neighbors  ;; counts how many neighboring cells are alive | ||||||
|  | ] | ||||||
|  |  | ||||||
|  | to setup-blank | ||||||
|  |   clear-all | ||||||
|  |   ask patches [ cell-death ] | ||||||
|  |   reset-ticks | ||||||
|  | end | ||||||
|  |  | ||||||
|  | to setup-random | ||||||
|  |   clear-all | ||||||
|  |   ask patches | ||||||
|  |     [ ifelse random-float 100.0 < initial-density | ||||||
|  |       [ cell-birth ] | ||||||
|  |       [ cell-death ] ] | ||||||
|  |   reset-ticks | ||||||
|  | end | ||||||
|  |  | ||||||
|  | to cell-birth | ||||||
|  |   set living? true | ||||||
|  |   set pcolor fgcolor | ||||||
|  | end | ||||||
|  |  | ||||||
|  | to cell-death | ||||||
|  |   set living? false | ||||||
|  |   set pcolor bgcolor | ||||||
|  | end | ||||||
|  |  | ||||||
|  | to go | ||||||
|  |   ask patches | ||||||
|  |     [ set live-neighbors count neighbors with [living?] ] | ||||||
|  |   ;; Starting a new "ask patches" here ensures that all the patches | ||||||
|  |   ;; finish executing the first ask before any of them start executing | ||||||
|  |   ;; the second ask.  This keeps all the patches in synch with each other, | ||||||
|  |   ;; so the births and deaths at each generation all happen in lockstep. | ||||||
|  |   ask patches | ||||||
|  |     [ ifelse live-neighbors = 3 | ||||||
|  |       [ cell-birth ] | ||||||
|  |       [ if live-neighbors != 2 | ||||||
|  |         [ cell-death ] ] ] | ||||||
|  |   tick | ||||||
|  | end | ||||||
|  |  | ||||||
|  | to draw-cells | ||||||
|  |   let erasing? [living?] of patch mouse-xcor mouse-ycor | ||||||
|  |   while [mouse-down?] | ||||||
|  |     [ ask patch mouse-xcor mouse-ycor | ||||||
|  |       [ ifelse erasing? | ||||||
|  |         [ cell-death ] | ||||||
|  |         [ cell-birth ] ] | ||||||
|  |       display ] | ||||||
|  | end | ||||||
|  |  | ||||||
							
								
								
									
										23
									
								
								samples/OpenCL/sample.cl
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										23
									
								
								samples/OpenCL/sample.cl
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,23 @@ | |||||||
|  | /* Old-style comment. */ | ||||||
|  |  | ||||||
|  | // New-style comment. | ||||||
|  |  | ||||||
|  | typedef float foo_t; | ||||||
|  |  | ||||||
|  | #ifndef ZERO | ||||||
|  | #define ZERO (0.0) | ||||||
|  | #endif | ||||||
|  |  | ||||||
|  | #define FOO(x) ((x) + \ | ||||||
|  |   ZERO) | ||||||
|  |  | ||||||
|  | __kernel | ||||||
|  | void foo(__global const foo_t * x, __local foo_t y, const uint n) | ||||||
|  | { | ||||||
|  |   barrier(CLK_LOCAL_MEM_FENCE); | ||||||
|  |  | ||||||
|  |   if (n > 42) { | ||||||
|  |     *x += y; | ||||||
|  |   } | ||||||
|  | } | ||||||
|  |  | ||||||
							
								
								
									
										164
									
								
								samples/Org/org.org
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										164
									
								
								samples/Org/org.org
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,164 @@ | |||||||
|  | #+OPTIONS:    H:3 num:nil toc:nil \n:nil @:t ::t |:t ^:t -:t f:t *:t TeX:t LaTeX:t skip:nil d:(HIDE) tags:not-in-toc | ||||||
|  | #+STARTUP:    align fold nodlcheck hidestars oddeven lognotestate | ||||||
|  | #+SEQ_TODO:   TODO(t) INPROGRESS(i) WAITING(w@) | DONE(d) CANCELED(c@) | ||||||
|  | #+TAGS:       Write(w) Update(u) Fix(f) Check(c) | ||||||
|  | #+TITLE:      org-ruby | ||||||
|  | #+AUTHOR:     Brian Dewey | ||||||
|  | #+EMAIL:      bdewey@gmail.com | ||||||
|  | #+LANGUAGE:   en | ||||||
|  | #+PRIORITIES: A C B | ||||||
|  | #+CATEGORY:   worg | ||||||
|  |  | ||||||
|  | {Back to Worg's index} | ||||||
|  |  | ||||||
|  | * Motivation | ||||||
|  |  | ||||||
|  |   The dominant simple plain-text markup languages for the web are | ||||||
|  |   Textile and Markdown. A factor for the popularity of those markup | ||||||
|  |   formats is the widespread availability of simple, free packages for | ||||||
|  |   converting the formats to HTML. For example, the world of | ||||||
|  |   Ruby-powered websites has settled on RedCloth for converting Textile | ||||||
|  |   to HTML. | ||||||
|  |  | ||||||
|  |   The default way to convert org-mode files to HTML is the powerful | ||||||
|  |   publishing functionality provided by =emacs=. However, =emacs= does | ||||||
|  |   not easiliy integrate into many existing website frameworks. | ||||||
|  |  | ||||||
|  |   =Org-ruby= tries to make it easier to use org-mode files in both | ||||||
|  |   dyanmic and static website generation tools written in | ||||||
|  |   Ruby. =Org-ruby= is a simple Ruby gem to convert org-mode files to | ||||||
|  |   HTML. | ||||||
|  |  | ||||||
|  | * Using Org-ruby | ||||||
|  |  | ||||||
|  |   =Org-ruby= follows the same model as other Ruby markup | ||||||
|  |   libraries. You install the gem: | ||||||
|  |  | ||||||
|  |   #+BEGIN_EXAMPLE | ||||||
|  |   sudo gem install org-ruby | ||||||
|  |   #+END_EXAMPLE | ||||||
|  |  | ||||||
|  |   Then, to convert an org-file to HTML in your Ruby code: | ||||||
|  |  | ||||||
|  |   #+BEGIN_EXAMPLE | ||||||
|  |   require 'rubygems' | ||||||
|  |   require 'org-ruby' | ||||||
|  |  | ||||||
|  |   data = IO.read(filename) | ||||||
|  |   puts Orgmode::Parser.new(data).to_html | ||||||
|  |   #+END_EXAMPLE | ||||||
|  |  | ||||||
|  | * Walkthrough: Using org-ruby with Webby | ||||||
|  |  | ||||||
|  |   Here is an example of how to integrate =org-ruby= into Webby, a | ||||||
|  |   static website generation tool written in Ruby. | ||||||
|  |  | ||||||
|  |   Webby follows a similar pattern to other static site generation | ||||||
|  |   tools (like nanoc, Jekyll, and webgen): | ||||||
|  |  | ||||||
|  |   - You author website content in text with simple markup | ||||||
|  |   - Each page is fed through one or more /filters/ to produce HTML | ||||||
|  |   - The HTML is mixed in with layouts to produce the final pages | ||||||
|  |  | ||||||
|  |   For a Webby site, a the source for a page may look like this: | ||||||
|  |  | ||||||
|  |   #+BEGIN_EXAMPLE | ||||||
|  |   --- | ||||||
|  |   title:           Special Directories | ||||||
|  |   created_at:      2009-12-17 | ||||||
|  |   status:          Complete | ||||||
|  |   filter: | ||||||
|  |     - erb | ||||||
|  |     - maruku | ||||||
|  |   tags: | ||||||
|  |     - powershell | ||||||
|  |   --- | ||||||
|  |   <%= @page.title %> | ||||||
|  |   ================== | ||||||
|  |  | ||||||
|  |   Special Directories are a set of directories, each of which has a | ||||||
|  |   function that will navigate you to the appropriate directory using | ||||||
|  |   the push-location cmdlet. For example, the function `home` might | ||||||
|  |   navigate to `c:\users\bdewey.` | ||||||
|  |  | ||||||
|  |   Install | ||||||
|  |   ------- | ||||||
|  |  | ||||||
|  |   Copy the module to somewhere in `ENV:PSModulePath`. Then, | ||||||
|  |  | ||||||
|  |       InstallModule SpecialDirectories | ||||||
|  |   #+END_EXAMPLE | ||||||
|  |  | ||||||
|  |   In the above example, the text is written in Markdown. At the top of | ||||||
|  |   the file, metadata informs Webby to pass the text through two | ||||||
|  |   /filters/ to produce HTML. The first filter, =erb=, handles embedded | ||||||
|  |   Ruby. In this case, it will replace ~<%= @page.title %>~ with the | ||||||
|  |   page title (=Special Directories=). The second filter uses Maruku to | ||||||
|  |   translate Markdown into HTML. | ||||||
|  |  | ||||||
|  |   You can use the exact same pattern to include org-mode files in a | ||||||
|  |   Webby site. For this walkthrough, I assume you already have Webby | ||||||
|  |   installed, and that you've already created a site. | ||||||
|  |  | ||||||
|  |   1. Make sure you have =org-ruby= installed: =sudo gem install | ||||||
|  |      org-ruby=. | ||||||
|  |   2. You need to register a new Webby filter to handle org-mode | ||||||
|  |      content. Webby makes this easy. In the =lib/= folder of your | ||||||
|  |      site, create a file =orgmode.rb=: | ||||||
|  |  | ||||||
|  |      #+BEGIN_EXAMPLE | ||||||
|  |      require 'org-ruby' | ||||||
|  |  | ||||||
|  |      Webby::Filters.register :org do |input| | ||||||
|  |        Orgmode::Parser.new(input).to_html | ||||||
|  |      end | ||||||
|  |      #+END_EXAMPLE | ||||||
|  |  | ||||||
|  |      This code creates a new filter, =org=, that will use the | ||||||
|  |      =org-ruby= parser to translate org-mode input into HTML. | ||||||
|  |   3. Create your content. For example: | ||||||
|  |  | ||||||
|  |      #+BEGIN_EXAMPLE | ||||||
|  | --- | ||||||
|  | title:              Orgmode Parser | ||||||
|  | created_at:         2009-12-21 | ||||||
|  | status:             Under development | ||||||
|  | filter: | ||||||
|  |   - erb | ||||||
|  |   - org | ||||||
|  | tags: | ||||||
|  |   - orgmode | ||||||
|  |   - ruby | ||||||
|  | --- | ||||||
|  | <%= @page.title %> | ||||||
|  |  | ||||||
|  |   Status: <%= @page.status %> | ||||||
|  |  | ||||||
|  | * Description | ||||||
|  |  | ||||||
|  |   Helpful Ruby routines for parsing orgmode files. The most | ||||||
|  |   significant thing this library does today is convert orgmode files | ||||||
|  |   to textile. Currently, you cannot do much to customize the | ||||||
|  |   conversion. The supplied textile conversion is optimized for | ||||||
|  |   extracting "content" from the orgfile as opposed to "metadata." | ||||||
|  |  | ||||||
|  |  | ||||||
|  | * History | ||||||
|  |  | ||||||
|  | ** 2009-12-29: Version 0.4 | ||||||
|  |  | ||||||
|  |    - The first thing output in HTML gets the class "title" | ||||||
|  |    - HTML output is now indented | ||||||
|  |    - Proper support for multi-paragraph list items. | ||||||
|  |  | ||||||
|  |      See? This paragraph is part of the last bullet. | ||||||
|  |  | ||||||
|  |    - Fixed bugs: | ||||||
|  |      - "rake spec" wouldn't work on Linux. Needed "require 'rubygems'". | ||||||
|  |        #+END_EXAMPLE | ||||||
|  |  | ||||||
|  |      This file will go through the =erb= and =org= filters; as defined | ||||||
|  |      in the previous step, the =org= filter will use =org-ruby= to | ||||||
|  |      generate HTML. | ||||||
|  |  | ||||||
|  |   That's all there is to it! | ||||||
							
								
								
									
										55
									
								
								samples/Oxygene/Loops.oxygene
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										55
									
								
								samples/Oxygene/Loops.oxygene
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,55 @@ | |||||||
|  | <Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||||||
|  |   <PropertyGroup> | ||||||
|  |     <RootNamespace>Loops</RootNamespace> | ||||||
|  |     <OutputType>exe</OutputType> | ||||||
|  |     <AssemblyName>Loops</AssemblyName> | ||||||
|  |     <AllowGlobals>False</AllowGlobals> | ||||||
|  |     <AllowLegacyOutParams>False</AllowLegacyOutParams> | ||||||
|  |     <AllowLegacyCreate>False</AllowLegacyCreate> | ||||||
|  |     <ApplicationIcon>Properties\App.ico</ApplicationIcon> | ||||||
|  |     <Configuration Condition="'$(Configuration)' == ''">Release</Configuration> | ||||||
|  |     <ProjectGuid>{916BD89C-B610-4CEE-9CAF-C515D88E2C94}</ProjectGuid> | ||||||
|  |   </PropertyGroup> | ||||||
|  |   <PropertyGroup Condition=" '$(Configuration)' == 'Debug' "> | ||||||
|  |     <DefineConstants>DEBUG;TRACE;</DefineConstants> | ||||||
|  |     <OutputPath>.\bin\Debug</OutputPath> | ||||||
|  |     <GeneratePDB>True</GeneratePDB> | ||||||
|  |     <GenerateMDB>True</GenerateMDB> | ||||||
|  |   </PropertyGroup> | ||||||
|  |   <PropertyGroup Condition=" '$(Configuration)' == 'Release' "> | ||||||
|  |     <OutputPath>.\bin\Release</OutputPath> | ||||||
|  |     <EnableAsserts>False</EnableAsserts> | ||||||
|  |   </PropertyGroup> | ||||||
|  |   <Import Project="$(MSBuildExtensionsPath)\RemObjects Software\Oxygene\RemObjects.Oxygene.targets" /> | ||||||
|  |   <ItemGroup> | ||||||
|  |     <Reference Include="mscorlib"> | ||||||
|  |       <HintPath>$(Framework)\mscorlib.dll</HintPath> | ||||||
|  |     </Reference> | ||||||
|  |     <Reference Include="System"> | ||||||
|  |       <HintPath>$(Framework)\System.dll</HintPath> | ||||||
|  |     </Reference> | ||||||
|  |     <Reference Include="System.Core"> | ||||||
|  |       <HintPath>$(ProgramFiles)\Reference Assemblies\Microsoft\Framework\v3.5\System.Core.dll</HintPath> | ||||||
|  |       <Private>True</Private> | ||||||
|  |     </Reference> | ||||||
|  |     <Reference Include="System.Data"> | ||||||
|  |       <HintPath>$(Framework)\System.Data.dll</HintPath> | ||||||
|  |     </Reference> | ||||||
|  |     <Reference Include="System.Xml"> | ||||||
|  |       <HintPath>$(Framework)\System.Xml.dll</HintPath> | ||||||
|  |     </Reference> | ||||||
|  |   </ItemGroup> | ||||||
|  |   <ItemGroup> | ||||||
|  |     <Compile Include="Program.pas" /> | ||||||
|  |     <Content Include="Properties\App.ico" /> | ||||||
|  |     <Compile Include="Properties\AssemblyInfo.pas" /> | ||||||
|  |     <EmbeddResource Include="Properties\Resources.resx"> | ||||||
|  |       <Generator>ResXFileCodeGenerator</Generator> | ||||||
|  |     </EmbeddResource> | ||||||
|  |     <Compile Include="Properties\Resources.Designer.pas" /> | ||||||
|  |     <None Include="Properties\Settings.settings"> | ||||||
|  |       <Generator>SettingsSingleFileGenerator</Generator> | ||||||
|  |     </None> | ||||||
|  |     <Compile Include="Properties\Settings.Designer.pas" /> | ||||||
|  |   </ItemGroup> | ||||||
|  | </Project> | ||||||
							
								
								
									
										520
									
								
								samples/PAWN/grandlarc.pwn
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										520
									
								
								samples/PAWN/grandlarc.pwn
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,520 @@ | |||||||
|  | //---------------------------------------------------------- | ||||||
|  | // | ||||||
|  | // GRAND LARCENY 1.0 | ||||||
|  | // A freeroam gamemode for SA-MP 0.3 | ||||||
|  | // | ||||||
|  | //---------------------------------------------------------- | ||||||
|  |  | ||||||
|  | #include <a_samp> | ||||||
|  | #include <core> | ||||||
|  | #include <float> | ||||||
|  | #include "../include/gl_common.inc" | ||||||
|  | #include "../include/gl_spawns.inc" | ||||||
|  |  | ||||||
|  | #pragma tabsize 0 | ||||||
|  |  | ||||||
|  | //---------------------------------------------------------- | ||||||
|  |  | ||||||
|  | #define COLOR_WHITE                 0xFFFFFFFF | ||||||
|  | #define COLOR_NORMAL_PLAYER 0xFFBB7777 | ||||||
|  |  | ||||||
|  | #define CITY_LOS_SANTOS         0 | ||||||
|  | #define CITY_SAN_FIERRO         1 | ||||||
|  | #define CITY_LAS_VENTURAS         2 | ||||||
|  |  | ||||||
|  | new total_vehicles_from_files=0; | ||||||
|  |  | ||||||
|  | // Class selection globals | ||||||
|  | new gPlayerCitySelection[MAX_PLAYERS]; | ||||||
|  | new gPlayerHasCitySelected[MAX_PLAYERS]; | ||||||
|  | new gPlayerLastCitySelectionTick[MAX_PLAYERS]; | ||||||
|  |  | ||||||
|  | new Text:txtClassSelHelper; | ||||||
|  | new Text:txtLosSantos; | ||||||
|  | new Text:txtSanFierro; | ||||||
|  | new Text:txtLasVenturas; | ||||||
|  |  | ||||||
|  | new thisanimid=0; | ||||||
|  | new lastanimid=0; | ||||||
|  |  | ||||||
|  | //---------------------------------------------------------- | ||||||
|  |  | ||||||
|  | main() | ||||||
|  | { | ||||||
|  |         print("\n---------------------------------------"); | ||||||
|  |         print("Running Grand Larceny - by the SA-MP team\n"); | ||||||
|  |         print("---------------------------------------\n"); | ||||||
|  | } | ||||||
|  |  | ||||||
|  | //---------------------------------------------------------- | ||||||
|  |  | ||||||
|  | public OnPlayerConnect(playerid) | ||||||
|  | { | ||||||
|  |         GameTextForPlayer(playerid,"~w~Grand Larceny",3000,4); | ||||||
|  |           SendClientMessage(playerid,COLOR_WHITE,"Welcome to {88AA88}G{FFFFFF}rand {88AA88}L{FFFFFF}arceny"); | ||||||
|  |            | ||||||
|  |           // class selection init vars | ||||||
|  |           gPlayerCitySelection[playerid] = -1; | ||||||
|  |         gPlayerHasCitySelected[playerid] = 0; | ||||||
|  |         gPlayerLastCitySelectionTick[playerid] = GetTickCount(); | ||||||
|  |  | ||||||
|  |         //SetPlayerColor(playerid,COLOR_NORMAL_PLAYER); | ||||||
|  |  | ||||||
|  |         //Kick(playerid); | ||||||
|  |          | ||||||
|  |         /* | ||||||
|  |         Removes vending machines | ||||||
|  |         RemoveBuildingForPlayer(playerid, 1302, 0.0, 0.0, 0.0, 6000.0); | ||||||
|  |         RemoveBuildingForPlayer(playerid, 1209, 0.0, 0.0, 0.0, 6000.0); | ||||||
|  |         RemoveBuildingForPlayer(playerid, 955, 0.0, 0.0, 0.0, 6000.0); | ||||||
|  |         RemoveBuildingForPlayer(playerid, 1775, 0.0, 0.0, 0.0, 6000.0); | ||||||
|  |         RemoveBuildingForPlayer(playerid, 1776, 0.0, 0.0, 0.0, 6000.0); | ||||||
|  |         */ | ||||||
|  |          | ||||||
|  |         /* | ||||||
|  |         new ClientVersion[32]; | ||||||
|  |         GetPlayerVersion(playerid, ClientVersion, 32); | ||||||
|  |         printf("Player %d reports client version: %s", playerid, ClientVersion);*/ | ||||||
|  |  | ||||||
|  |          return 1; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | //---------------------------------------------------------- | ||||||
|  |  | ||||||
|  | public OnPlayerSpawn(playerid) | ||||||
|  | { | ||||||
|  |         if(IsPlayerNPC(playerid)) return 1; | ||||||
|  |          | ||||||
|  |         new randSpawn = 0; | ||||||
|  |          | ||||||
|  |         SetPlayerInterior(playerid,0); | ||||||
|  |         TogglePlayerClock(playerid,0); | ||||||
|  |          ResetPlayerMoney(playerid); | ||||||
|  |         GivePlayerMoney(playerid, 30000); | ||||||
|  |  | ||||||
|  |         if(CITY_LOS_SANTOS == gPlayerCitySelection[playerid]) { | ||||||
|  |           randSpawn = random(sizeof(gRandomSpawns_LosSantos)); | ||||||
|  |           SetPlayerPos(playerid, | ||||||
|  |                  gRandomSpawns_LosSantos[randSpawn][0], | ||||||
|  |                  gRandomSpawns_LosSantos[randSpawn][1], | ||||||
|  |                  gRandomSpawns_LosSantos[randSpawn][2]); | ||||||
|  |                 SetPlayerFacingAngle(playerid,gRandomSpawns_LosSantos[randSpawn][3]); | ||||||
|  |         } | ||||||
|  |         else if(CITY_SAN_FIERRO == gPlayerCitySelection[playerid]) { | ||||||
|  |           randSpawn = random(sizeof(gRandomSpawns_SanFierro)); | ||||||
|  |           SetPlayerPos(playerid, | ||||||
|  |                  gRandomSpawns_SanFierro[randSpawn][0], | ||||||
|  |                  gRandomSpawns_SanFierro[randSpawn][1], | ||||||
|  |                  gRandomSpawns_SanFierro[randSpawn][2]); | ||||||
|  |                 SetPlayerFacingAngle(playerid,gRandomSpawns_SanFierro[randSpawn][3]); | ||||||
|  |         } | ||||||
|  |         else if(CITY_LAS_VENTURAS == gPlayerCitySelection[playerid]) { | ||||||
|  |           randSpawn = random(sizeof(gRandomSpawns_LasVenturas)); | ||||||
|  |           SetPlayerPos(playerid, | ||||||
|  |                  gRandomSpawns_LasVenturas[randSpawn][0], | ||||||
|  |                  gRandomSpawns_LasVenturas[randSpawn][1], | ||||||
|  |                  gRandomSpawns_LasVenturas[randSpawn][2]); | ||||||
|  |                 SetPlayerFacingAngle(playerid,gRandomSpawns_LasVenturas[randSpawn][3]); | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         //SetPlayerColor(playerid,COLOR_NORMAL_PLAYER); | ||||||
|  |          | ||||||
|  |         SetPlayerSkillLevel(playerid,WEAPONSKILL_PISTOL,200); | ||||||
|  |     SetPlayerSkillLevel(playerid,WEAPONSKILL_PISTOL_SILENCED,200); | ||||||
|  |     SetPlayerSkillLevel(playerid,WEAPONSKILL_DESERT_EAGLE,200); | ||||||
|  |     SetPlayerSkillLevel(playerid,WEAPONSKILL_SHOTGUN,200); | ||||||
|  |     SetPlayerSkillLevel(playerid,WEAPONSKILL_SAWNOFF_SHOTGUN,200); | ||||||
|  |     SetPlayerSkillLevel(playerid,WEAPONSKILL_SPAS12_SHOTGUN,200); | ||||||
|  |     SetPlayerSkillLevel(playerid,WEAPONSKILL_MICRO_UZI,200); | ||||||
|  |     SetPlayerSkillLevel(playerid,WEAPONSKILL_MP5,200); | ||||||
|  |     SetPlayerSkillLevel(playerid,WEAPONSKILL_AK47,200); | ||||||
|  |     SetPlayerSkillLevel(playerid,WEAPONSKILL_M4,200); | ||||||
|  |     SetPlayerSkillLevel(playerid,WEAPONSKILL_SNIPERRIFLE,200); | ||||||
|  |      | ||||||
|  |     GivePlayerWeapon(playerid,WEAPON_COLT45,100); | ||||||
|  |         //GivePlayerWeapon(playerid,WEAPON_MP5,100); | ||||||
|  |         TogglePlayerClock(playerid, 0); | ||||||
|  |  | ||||||
|  |         return 1; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | //---------------------------------------------------------- | ||||||
|  |  | ||||||
|  | public OnPlayerDeath(playerid, killerid, reason) | ||||||
|  | { | ||||||
|  |     new playercash; | ||||||
|  |      | ||||||
|  |     // if they ever return to class selection make them city | ||||||
|  |         // select again first | ||||||
|  |         gPlayerHasCitySelected[playerid] = 0; | ||||||
|  |      | ||||||
|  |         if(killerid == INVALID_PLAYER_ID) { | ||||||
|  |         ResetPlayerMoney(playerid); | ||||||
|  |         } else { | ||||||
|  |                 playercash = GetPlayerMoney(playerid); | ||||||
|  |                 if(playercash > 0) { | ||||||
|  |                         GivePlayerMoney(killerid, playercash); | ||||||
|  |                         ResetPlayerMoney(playerid); | ||||||
|  |                 } | ||||||
|  |         } | ||||||
|  |            return 1; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | //---------------------------------------------------------- | ||||||
|  |  | ||||||
|  | ClassSel_SetupCharSelection(playerid) | ||||||
|  | { | ||||||
|  |            if(gPlayerCitySelection[playerid] == CITY_LOS_SANTOS) { | ||||||
|  |                 SetPlayerInterior(playerid,11); | ||||||
|  |                 SetPlayerPos(playerid,508.7362,-87.4335,998.9609); | ||||||
|  |                 SetPlayerFacingAngle(playerid,0.0); | ||||||
|  |             SetPlayerCameraPos(playerid,508.7362,-83.4335,998.9609); | ||||||
|  |                 SetPlayerCameraLookAt(playerid,508.7362,-87.4335,998.9609); | ||||||
|  |         } | ||||||
|  |         else if(gPlayerCitySelection[playerid] == CITY_SAN_FIERRO) { | ||||||
|  |                 SetPlayerInterior(playerid,3); | ||||||
|  |                 SetPlayerPos(playerid,-2673.8381,1399.7424,918.3516); | ||||||
|  |                 SetPlayerFacingAngle(playerid,181.0); | ||||||
|  |             SetPlayerCameraPos(playerid,-2673.2776,1394.3859,918.3516); | ||||||
|  |                 SetPlayerCameraLookAt(playerid,-2673.8381,1399.7424,918.3516); | ||||||
|  |         } | ||||||
|  |         else if(gPlayerCitySelection[playerid] == CITY_LAS_VENTURAS) { | ||||||
|  |                 SetPlayerInterior(playerid,3); | ||||||
|  |                 SetPlayerPos(playerid,349.0453,193.2271,1014.1797); | ||||||
|  |                 SetPlayerFacingAngle(playerid,286.25); | ||||||
|  |             SetPlayerCameraPos(playerid,352.9164,194.5702,1014.1875); | ||||||
|  |                 SetPlayerCameraLookAt(playerid,349.0453,193.2271,1014.1797); | ||||||
|  |         } | ||||||
|  |          | ||||||
|  | } | ||||||
|  |  | ||||||
|  | //---------------------------------------------------------- | ||||||
|  | // Used to init textdraws of city names | ||||||
|  |  | ||||||
|  | ClassSel_InitCityNameText(Text:txtInit) | ||||||
|  | { | ||||||
|  |           TextDrawUseBox(txtInit, 0); | ||||||
|  |         TextDrawLetterSize(txtInit,1.25,3.0); | ||||||
|  |         TextDrawFont(txtInit, 0); | ||||||
|  |         TextDrawSetShadow(txtInit,0); | ||||||
|  |     TextDrawSetOutline(txtInit,1); | ||||||
|  |     TextDrawColor(txtInit,0xEEEEEEFF); | ||||||
|  |     TextDrawBackgroundColor(txtClassSelHelper,0x000000FF); | ||||||
|  | } | ||||||
|  |  | ||||||
|  | //---------------------------------------------------------- | ||||||
|  |  | ||||||
|  | ClassSel_InitTextDraws() | ||||||
|  | { | ||||||
|  |     // Init our observer helper text display | ||||||
|  |         txtLosSantos = TextDrawCreate(10.0, 380.0, "Los Santos"); | ||||||
|  |         ClassSel_InitCityNameText(txtLosSantos); | ||||||
|  |         txtSanFierro = TextDrawCreate(10.0, 380.0, "San Fierro"); | ||||||
|  |         ClassSel_InitCityNameText(txtSanFierro); | ||||||
|  |         txtLasVenturas = TextDrawCreate(10.0, 380.0, "Las Venturas"); | ||||||
|  |         ClassSel_InitCityNameText(txtLasVenturas); | ||||||
|  |  | ||||||
|  |     // Init our observer helper text display | ||||||
|  |         txtClassSelHelper = TextDrawCreate(10.0, 415.0, | ||||||
|  |          " Press ~b~~k~~GO_LEFT~ ~w~or ~b~~k~~GO_RIGHT~ ~w~to switch cities.~n~ Press ~r~~k~~PED_FIREWEAPON~ ~w~to select."); | ||||||
|  |         TextDrawUseBox(txtClassSelHelper, 1); | ||||||
|  |         TextDrawBoxColor(txtClassSelHelper,0x222222BB); | ||||||
|  |         TextDrawLetterSize(txtClassSelHelper,0.3,1.0); | ||||||
|  |         TextDrawTextSize(txtClassSelHelper,400.0,40.0); | ||||||
|  |         TextDrawFont(txtClassSelHelper, 2); | ||||||
|  |         TextDrawSetShadow(txtClassSelHelper,0); | ||||||
|  |     TextDrawSetOutline(txtClassSelHelper,1); | ||||||
|  |     TextDrawBackgroundColor(txtClassSelHelper,0x000000FF); | ||||||
|  |     TextDrawColor(txtClassSelHelper,0xFFFFFFFF); | ||||||
|  | } | ||||||
|  |  | ||||||
|  | //---------------------------------------------------------- | ||||||
|  |  | ||||||
|  | ClassSel_SetupSelectedCity(playerid) | ||||||
|  | { | ||||||
|  |         if(gPlayerCitySelection[playerid] == -1) { | ||||||
|  |                 gPlayerCitySelection[playerid] = CITY_LOS_SANTOS; | ||||||
|  |         } | ||||||
|  |          | ||||||
|  |         if(gPlayerCitySelection[playerid] == CITY_LOS_SANTOS) { | ||||||
|  |                 SetPlayerInterior(playerid,0); | ||||||
|  |                    SetPlayerCameraPos(playerid,1630.6136,-2286.0298,110.0); | ||||||
|  |                 SetPlayerCameraLookAt(playerid,1887.6034,-1682.1442,47.6167); | ||||||
|  |                  | ||||||
|  |                 TextDrawShowForPlayer(playerid,txtLosSantos); | ||||||
|  |                 TextDrawHideForPlayer(playerid,txtSanFierro); | ||||||
|  |                 TextDrawHideForPlayer(playerid,txtLasVenturas); | ||||||
|  |         } | ||||||
|  |         else if(gPlayerCitySelection[playerid] == CITY_SAN_FIERRO) { | ||||||
|  |                 SetPlayerInterior(playerid,0); | ||||||
|  |                    SetPlayerCameraPos(playerid,-1300.8754,68.0546,129.4823); | ||||||
|  |                 SetPlayerCameraLookAt(playerid,-1817.9412,769.3878,132.6589); | ||||||
|  |                  | ||||||
|  |                 TextDrawHideForPlayer(playerid,txtLosSantos); | ||||||
|  |                 TextDrawShowForPlayer(playerid,txtSanFierro); | ||||||
|  |                 TextDrawHideForPlayer(playerid,txtLasVenturas); | ||||||
|  |         } | ||||||
|  |         else if(gPlayerCitySelection[playerid] == CITY_LAS_VENTURAS) { | ||||||
|  |                 SetPlayerInterior(playerid,0); | ||||||
|  |                    SetPlayerCameraPos(playerid,1310.6155,1675.9182,110.7390); | ||||||
|  |                 SetPlayerCameraLookAt(playerid,2285.2944,1919.3756,68.2275); | ||||||
|  |                  | ||||||
|  |                 TextDrawHideForPlayer(playerid,txtLosSantos); | ||||||
|  |                 TextDrawHideForPlayer(playerid,txtSanFierro); | ||||||
|  |                 TextDrawShowForPlayer(playerid,txtLasVenturas); | ||||||
|  |         } | ||||||
|  | } | ||||||
|  |  | ||||||
|  | //---------------------------------------------------------- | ||||||
|  |  | ||||||
|  | ClassSel_SwitchToNextCity(playerid) | ||||||
|  | { | ||||||
|  |     gPlayerCitySelection[playerid]++; | ||||||
|  |         if(gPlayerCitySelection[playerid] > CITY_LAS_VENTURAS) { | ||||||
|  |          gPlayerCitySelection[playerid] = CITY_LOS_SANTOS; | ||||||
|  |         } | ||||||
|  |         PlayerPlaySound(playerid,1052,0.0,0.0,0.0); | ||||||
|  |         gPlayerLastCitySelectionTick[playerid] = GetTickCount(); | ||||||
|  |         ClassSel_SetupSelectedCity(playerid); | ||||||
|  | } | ||||||
|  |  | ||||||
|  | //---------------------------------------------------------- | ||||||
|  |  | ||||||
|  | ClassSel_SwitchToPreviousCity(playerid) | ||||||
|  | { | ||||||
|  |     gPlayerCitySelection[playerid]--; | ||||||
|  |         if(gPlayerCitySelection[playerid] < CITY_LOS_SANTOS) { | ||||||
|  |          gPlayerCitySelection[playerid] = CITY_LAS_VENTURAS; | ||||||
|  |         } | ||||||
|  |         PlayerPlaySound(playerid,1053,0.0,0.0,0.0); | ||||||
|  |         gPlayerLastCitySelectionTick[playerid] = GetTickCount(); | ||||||
|  |         ClassSel_SetupSelectedCity(playerid); | ||||||
|  | } | ||||||
|  |  | ||||||
|  | //---------------------------------------------------------- | ||||||
|  |  | ||||||
|  | ClassSel_HandleCitySelection(playerid) | ||||||
|  | { | ||||||
|  |         new Keys,ud,lr; | ||||||
|  |     GetPlayerKeys(playerid,Keys,ud,lr); | ||||||
|  |      | ||||||
|  |     if(gPlayerCitySelection[playerid] == -1) { | ||||||
|  |                 ClassSel_SwitchToNextCity(playerid); | ||||||
|  |                 return; | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         // only allow new selection every ~500 ms | ||||||
|  |         if( (GetTickCount() - gPlayerLastCitySelectionTick[playerid]) < 500 ) return; | ||||||
|  |          | ||||||
|  |         if(Keys & KEY_FIRE) { | ||||||
|  |          gPlayerHasCitySelected[playerid] = 1; | ||||||
|  |          TextDrawHideForPlayer(playerid,txtClassSelHelper); | ||||||
|  |                 TextDrawHideForPlayer(playerid,txtLosSantos); | ||||||
|  |                 TextDrawHideForPlayer(playerid,txtSanFierro); | ||||||
|  |                 TextDrawHideForPlayer(playerid,txtLasVenturas); | ||||||
|  |          TogglePlayerSpectating(playerid,0); | ||||||
|  |          return; | ||||||
|  |         } | ||||||
|  |          | ||||||
|  |         if(lr > 0) { | ||||||
|  |          ClassSel_SwitchToNextCity(playerid); | ||||||
|  |         } | ||||||
|  |         else if(lr < 0) { | ||||||
|  |          ClassSel_SwitchToPreviousCity(playerid); | ||||||
|  |         } | ||||||
|  | } | ||||||
|  |  | ||||||
|  | //---------------------------------------------------------- | ||||||
|  |  | ||||||
|  | public OnPlayerRequestClass(playerid, classid) | ||||||
|  | { | ||||||
|  |         if(IsPlayerNPC(playerid)) return 1; | ||||||
|  |  | ||||||
|  |         if(gPlayerHasCitySelected[playerid]) { | ||||||
|  |                 ClassSel_SetupCharSelection(playerid); | ||||||
|  |                 return 1; | ||||||
|  |         } else { | ||||||
|  |                 if(GetPlayerState(playerid) != PLAYER_STATE_SPECTATING) { | ||||||
|  |                         TogglePlayerSpectating(playerid,1); | ||||||
|  |                     TextDrawShowForPlayer(playerid, txtClassSelHelper); | ||||||
|  |                     gPlayerCitySelection[playerid] = -1; | ||||||
|  |                 } | ||||||
|  |           } | ||||||
|  |      | ||||||
|  |         return 0; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | //---------------------------------------------------------- | ||||||
|  |  | ||||||
|  | public OnGameModeInit() | ||||||
|  | { | ||||||
|  |         SetGameModeText("Grand Larceny"); | ||||||
|  |         ShowPlayerMarkers(PLAYER_MARKERS_MODE_GLOBAL); | ||||||
|  |         ShowNameTags(1); | ||||||
|  |         SetNameTagDrawDistance(40.0); | ||||||
|  |         EnableStuntBonusForAll(0); | ||||||
|  |         DisableInteriorEnterExits(); | ||||||
|  |         SetWeather(2); | ||||||
|  |         SetWorldTime(11); | ||||||
|  |  | ||||||
|  |         //UsePlayerPedAnims(); | ||||||
|  |         //ManualVehicleEngineAndLights(); | ||||||
|  |         //LimitGlobalChatRadius(300.0); | ||||||
|  |          | ||||||
|  |         ClassSel_InitTextDraws(); | ||||||
|  |  | ||||||
|  |         // Player Class | ||||||
|  |         AddPlayerClass(281,1759.0189,-1898.1260,13.5622,266.4503,-1,-1,-1,-1,-1,-1); | ||||||
|  |         AddPlayerClass(282,1759.0189,-1898.1260,13.5622,266.4503,-1,-1,-1,-1,-1,-1); | ||||||
|  |         AddPlayerClass(283,1759.0189,-1898.1260,13.5622,266.4503,-1,-1,-1,-1,-1,-1); | ||||||
|  |         AddPlayerClass(284,1759.0189,-1898.1260,13.5622,266.4503,-1,-1,-1,-1,-1,-1); | ||||||
|  |         AddPlayerClass(285,1759.0189,-1898.1260,13.5622,266.4503,-1,-1,-1,-1,-1,-1); | ||||||
|  |         AddPlayerClass(286,1759.0189,-1898.1260,13.5622,266.4503,-1,-1,-1,-1,-1,-1); | ||||||
|  |         AddPlayerClass(287,1759.0189,-1898.1260,13.5622,266.4503,-1,-1,-1,-1,-1,-1); | ||||||
|  |         AddPlayerClass(288,1759.0189,-1898.1260,13.5622,266.4503,-1,-1,-1,-1,-1,-1); | ||||||
|  |         AddPlayerClass(289,1759.0189,-1898.1260,13.5622,266.4503,-1,-1,-1,-1,-1,-1); | ||||||
|  |         AddPlayerClass(265,1759.0189,-1898.1260,13.5622,266.4503,-1,-1,-1,-1,-1,-1); | ||||||
|  |         AddPlayerClass(266,1759.0189,-1898.1260,13.5622,266.4503,-1,-1,-1,-1,-1,-1); | ||||||
|  |         AddPlayerClass(267,1759.0189,-1898.1260,13.5622,266.4503,-1,-1,-1,-1,-1,-1); | ||||||
|  |         AddPlayerClass(268,1759.0189,-1898.1260,13.5622,266.4503,-1,-1,-1,-1,-1,-1); | ||||||
|  |         AddPlayerClass(269,1759.0189,-1898.1260,13.5622,266.4503,-1,-1,-1,-1,-1,-1); | ||||||
|  |         AddPlayerClass(270,1759.0189,-1898.1260,13.5622,266.4503,-1,-1,-1,-1,-1,-1); | ||||||
|  |         AddPlayerClass(1,1759.0189,-1898.1260,13.5622,266.4503,-1,-1,-1,-1,-1,-1); | ||||||
|  |         AddPlayerClass(2,1759.0189,-1898.1260,13.5622,266.4503,-1,-1,-1,-1,-1,-1); | ||||||
|  |         AddPlayerClass(3,1759.0189,-1898.1260,13.5622,266.4503,-1,-1,-1,-1,-1,-1); | ||||||
|  |         AddPlayerClass(4,1759.0189,-1898.1260,13.5622,266.4503,-1,-1,-1,-1,-1,-1); | ||||||
|  |         AddPlayerClass(5,1759.0189,-1898.1260,13.5622,266.4503,-1,-1,-1,-1,-1,-1); | ||||||
|  |         AddPlayerClass(6,1759.0189,-1898.1260,13.5622,266.4503,-1,-1,-1,-1,-1,-1); | ||||||
|  |         AddPlayerClass(8,1759.0189,-1898.1260,13.5622,266.4503,-1,-1,-1,-1,-1,-1); | ||||||
|  |         AddPlayerClass(42,1759.0189,-1898.1260,13.5622,266.4503,-1,-1,-1,-1,-1,-1); | ||||||
|  |         AddPlayerClass(65,1759.0189,-1898.1260,13.5622,266.4503,-1,-1,-1,-1,-1,-1); | ||||||
|  |         //AddPlayerClass(74,1759.0189,-1898.1260,13.5622,266.4503,-1,-1,-1,-1,-1,-1); | ||||||
|  |         AddPlayerClass(86,1759.0189,-1898.1260,13.5622,266.4503,-1,-1,-1,-1,-1,-1); | ||||||
|  |         AddPlayerClass(119,1759.0189,-1898.1260,13.5622,266.4503,-1,-1,-1,-1,-1,-1); | ||||||
|  |          AddPlayerClass(149,1759.0189,-1898.1260,13.5622,266.4503,-1,-1,-1,-1,-1,-1); | ||||||
|  |         AddPlayerClass(208,1759.0189,-1898.1260,13.5622,266.4503,-1,-1,-1,-1,-1,-1); | ||||||
|  |         AddPlayerClass(273,1759.0189,-1898.1260,13.5622,266.4503,-1,-1,-1,-1,-1,-1); | ||||||
|  |         AddPlayerClass(289,1759.0189,-1898.1260,13.5622,266.4503,-1,-1,-1,-1,-1,-1); | ||||||
|  |          | ||||||
|  |         AddPlayerClass(47,1759.0189,-1898.1260,13.5622,266.4503,-1,-1,-1,-1,-1,-1); | ||||||
|  |         AddPlayerClass(48,1759.0189,-1898.1260,13.5622,266.4503,-1,-1,-1,-1,-1,-1); | ||||||
|  |         AddPlayerClass(49,1759.0189,-1898.1260,13.5622,266.4503,-1,-1,-1,-1,-1,-1); | ||||||
|  |         AddPlayerClass(50,1759.0189,-1898.1260,13.5622,266.4503,-1,-1,-1,-1,-1,-1); | ||||||
|  |         AddPlayerClass(51,1759.0189,-1898.1260,13.5622,266.4503,-1,-1,-1,-1,-1,-1); | ||||||
|  |         AddPlayerClass(52,1759.0189,-1898.1260,13.5622,266.4503,-1,-1,-1,-1,-1,-1); | ||||||
|  |         AddPlayerClass(53,1759.0189,-1898.1260,13.5622,266.4503,-1,-1,-1,-1,-1,-1); | ||||||
|  |         AddPlayerClass(54,1759.0189,-1898.1260,13.5622,266.4503,-1,-1,-1,-1,-1,-1); | ||||||
|  |         AddPlayerClass(55,1759.0189,-1898.1260,13.5622,266.4503,-1,-1,-1,-1,-1,-1); | ||||||
|  |         AddPlayerClass(56,1759.0189,-1898.1260,13.5622,266.4503,-1,-1,-1,-1,-1,-1); | ||||||
|  |         AddPlayerClass(57,1759.0189,-1898.1260,13.5622,266.4503,-1,-1,-1,-1,-1,-1); | ||||||
|  |         AddPlayerClass(58,1759.0189,-1898.1260,13.5622,266.4503,-1,-1,-1,-1,-1,-1); | ||||||
|  |            AddPlayerClass(68,1759.0189,-1898.1260,13.5622,266.4503,-1,-1,-1,-1,-1,-1); | ||||||
|  |         AddPlayerClass(69,1759.0189,-1898.1260,13.5622,266.4503,-1,-1,-1,-1,-1,-1); | ||||||
|  |         AddPlayerClass(70,1759.0189,-1898.1260,13.5622,266.4503,-1,-1,-1,-1,-1,-1); | ||||||
|  |         AddPlayerClass(71,1759.0189,-1898.1260,13.5622,266.4503,-1,-1,-1,-1,-1,-1); | ||||||
|  |         AddPlayerClass(72,1759.0189,-1898.1260,13.5622,266.4503,-1,-1,-1,-1,-1,-1); | ||||||
|  |         AddPlayerClass(73,1759.0189,-1898.1260,13.5622,266.4503,-1,-1,-1,-1,-1,-1); | ||||||
|  |         AddPlayerClass(75,1759.0189,-1898.1260,13.5622,266.4503,-1,-1,-1,-1,-1,-1); | ||||||
|  |         AddPlayerClass(76,1759.0189,-1898.1260,13.5622,266.4503,-1,-1,-1,-1,-1,-1); | ||||||
|  |         AddPlayerClass(78,1759.0189,-1898.1260,13.5622,266.4503,-1,-1,-1,-1,-1,-1); | ||||||
|  |         AddPlayerClass(79,1759.0189,-1898.1260,13.5622,266.4503,-1,-1,-1,-1,-1,-1); | ||||||
|  |         AddPlayerClass(80,1759.0189,-1898.1260,13.5622,266.4503,-1,-1,-1,-1,-1,-1); | ||||||
|  |         AddPlayerClass(81,1759.0189,-1898.1260,13.5622,266.4503,-1,-1,-1,-1,-1,-1); | ||||||
|  |         AddPlayerClass(82,1759.0189,-1898.1260,13.5622,266.4503,-1,-1,-1,-1,-1,-1); | ||||||
|  |         AddPlayerClass(83,1759.0189,-1898.1260,13.5622,266.4503,-1,-1,-1,-1,-1,-1); | ||||||
|  |         AddPlayerClass(84,1759.0189,-1898.1260,13.5622,266.4503,-1,-1,-1,-1,-1,-1); | ||||||
|  |         AddPlayerClass(85,1759.0189,-1898.1260,13.5622,266.4503,-1,-1,-1,-1,-1,-1); | ||||||
|  |         AddPlayerClass(87,1759.0189,-1898.1260,13.5622,266.4503,-1,-1,-1,-1,-1,-1); | ||||||
|  |         AddPlayerClass(88,1759.0189,-1898.1260,13.5622,266.4503,-1,-1,-1,-1,-1,-1); | ||||||
|  |         AddPlayerClass(89,1759.0189,-1898.1260,13.5622,266.4503,-1,-1,-1,-1,-1,-1); | ||||||
|  |         AddPlayerClass(91,1759.0189,-1898.1260,13.5622,266.4503,-1,-1,-1,-1,-1,-1); | ||||||
|  |         AddPlayerClass(92,1759.0189,-1898.1260,13.5622,266.4503,-1,-1,-1,-1,-1,-1); | ||||||
|  |         AddPlayerClass(93,1759.0189,-1898.1260,13.5622,266.4503,-1,-1,-1,-1,-1,-1); | ||||||
|  |         AddPlayerClass(95,1759.0189,-1898.1260,13.5622,266.4503,-1,-1,-1,-1,-1,-1); | ||||||
|  |         AddPlayerClass(96,1759.0189,-1898.1260,13.5622,266.4503,-1,-1,-1,-1,-1,-1); | ||||||
|  |         AddPlayerClass(97,1759.0189,-1898.1260,13.5622,266.4503,-1,-1,-1,-1,-1,-1); | ||||||
|  |         AddPlayerClass(98,1759.0189,-1898.1260,13.5622,266.4503,-1,-1,-1,-1,-1,-1); | ||||||
|  |         AddPlayerClass(99,1759.0189,-1898.1260,13.5622,266.4503,-1,-1,-1,-1,-1,-1); | ||||||
|  |  | ||||||
|  |         // SPECIAL | ||||||
|  |         total_vehicles_from_files += LoadStaticVehiclesFromFile("vehicles/trains.txt"); | ||||||
|  |         total_vehicles_from_files += LoadStaticVehiclesFromFile("vehicles/pilots.txt"); | ||||||
|  |  | ||||||
|  |            // LAS VENTURAS | ||||||
|  |      total_vehicles_from_files += LoadStaticVehiclesFromFile("vehicles/lv_law.txt"); | ||||||
|  |     total_vehicles_from_files += LoadStaticVehiclesFromFile("vehicles/lv_airport.txt"); | ||||||
|  |     total_vehicles_from_files += LoadStaticVehiclesFromFile("vehicles/lv_gen.txt"); | ||||||
|  |      | ||||||
|  |     // SAN FIERRO | ||||||
|  |     total_vehicles_from_files += LoadStaticVehiclesFromFile("vehicles/sf_law.txt"); | ||||||
|  |     total_vehicles_from_files += LoadStaticVehiclesFromFile("vehicles/sf_airport.txt"); | ||||||
|  |     total_vehicles_from_files += LoadStaticVehiclesFromFile("vehicles/sf_gen.txt"); | ||||||
|  |      | ||||||
|  |     // LOS SANTOS | ||||||
|  |     total_vehicles_from_files += LoadStaticVehiclesFromFile("vehicles/ls_law.txt"); | ||||||
|  |     total_vehicles_from_files += LoadStaticVehiclesFromFile("vehicles/ls_airport.txt"); | ||||||
|  |     total_vehicles_from_files += LoadStaticVehiclesFromFile("vehicles/ls_gen_inner.txt"); | ||||||
|  |     total_vehicles_from_files += LoadStaticVehiclesFromFile("vehicles/ls_gen_outer.txt"); | ||||||
|  |      | ||||||
|  |     // OTHER AREAS | ||||||
|  |     total_vehicles_from_files += LoadStaticVehiclesFromFile("vehicles/whetstone.txt"); | ||||||
|  |     total_vehicles_from_files += LoadStaticVehiclesFromFile("vehicles/bone.txt"); | ||||||
|  |     total_vehicles_from_files += LoadStaticVehiclesFromFile("vehicles/flint.txt"); | ||||||
|  |     total_vehicles_from_files += LoadStaticVehiclesFromFile("vehicles/tierra.txt"); | ||||||
|  |     total_vehicles_from_files += LoadStaticVehiclesFromFile("vehicles/red_county.txt"); | ||||||
|  |  | ||||||
|  |     printf("Total vehicles from files: %d",total_vehicles_from_files); | ||||||
|  |  | ||||||
|  |         return 1; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | //---------------------------------------------------------- | ||||||
|  |  | ||||||
|  | public OnPlayerUpdate(playerid) | ||||||
|  | { | ||||||
|  |         if(!IsPlayerConnected(playerid)) return 0; | ||||||
|  |         if(IsPlayerNPC(playerid)) return 1; | ||||||
|  |  | ||||||
|  |         // changing cities by inputs | ||||||
|  |         if( !gPlayerHasCitySelected[playerid] && | ||||||
|  |          GetPlayerState(playerid) == PLAYER_STATE_SPECTATING ) { | ||||||
|  |          ClassSel_HandleCitySelection(playerid); | ||||||
|  |          return 1; | ||||||
|  |         } | ||||||
|  |          | ||||||
|  |         // No weapons in interiors | ||||||
|  |         if(GetPlayerInterior(playerid) != 0 && GetPlayerWeapon(playerid) != 0) { | ||||||
|  |          SetPlayerArmedWeapon(playerid,0); // fists | ||||||
|  |          return 0; // no syncing until they change their weapon | ||||||
|  |         } | ||||||
|  |          | ||||||
|  |         // Don't allow minigun | ||||||
|  |         if(GetPlayerWeapon(playerid) == WEAPON_MINIGUN) { | ||||||
|  |          Kick(playerid); | ||||||
|  |          return 0; | ||||||
|  |         } | ||||||
|  |          | ||||||
|  |         /* No jetpacks allowed | ||||||
|  |         if(GetPlayerSpecialAction(playerid) == SPECIAL_ACTION_USEJETPACK) { | ||||||
|  |          Kick(playerid); | ||||||
|  |          return 0; | ||||||
|  |         }*/ | ||||||
|  |  | ||||||
|  |         /* For testing animations | ||||||
|  |     new msg[128+1]; | ||||||
|  |         new animlib[32+1]; | ||||||
|  |         new animname[32+1]; | ||||||
|  |  | ||||||
|  |         thisanimid = GetPlayerAnimationIndex(playerid); | ||||||
|  |         if(lastanimid != thisanimid) | ||||||
|  |         { | ||||||
|  |                 GetAnimationName(thisanimid,animlib,32,animname,32); | ||||||
|  |                 format(msg, 128, "anim(%d,%d): %s %s", lastanimid, thisanimid, animlib, animname); | ||||||
|  |                 lastanimid = thisanimid; | ||||||
|  |                 SendClientMessage(playerid, 0xFFFFFFFF, msg); | ||||||
|  |         }*/ | ||||||
|  |  | ||||||
|  |         return 1; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | //---------------------------------------------------------- | ||||||
							
								
								
									
										22
									
								
								samples/PHP/php2.script!
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										22
									
								
								samples/PHP/php2.script!
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,22 @@ | |||||||
|  | #!/usr/bin/env php | ||||||
|  | <?php | ||||||
|  | /** | ||||||
|  |  * Yii console bootstrap file. | ||||||
|  |  * | ||||||
|  |  * @link http://www.yiiframework.com/ | ||||||
|  |  * @copyright Copyright (c) 2008 Yii Software LLC | ||||||
|  |  * @license http://www.yiiframework.com/license/ | ||||||
|  |  */ | ||||||
|  |  | ||||||
|  | defined('YII_DEBUG') or define('YII_DEBUG', true); | ||||||
|  |  | ||||||
|  | // fcgi doesn't have STDIN defined by default | ||||||
|  | defined('STDIN') or define('STDIN', fopen('php://stdin', 'r')); | ||||||
|  |  | ||||||
|  | require(__DIR__ . '/vendor/yiisoft/yii2/yii/Yii.php'); | ||||||
|  | require(__DIR__ . '/vendor/autoload.php'); | ||||||
|  |  | ||||||
|  | $config = require(__DIR__ . '/config/console.php'); | ||||||
|  |  | ||||||
|  | $application = new yii\console\Application($config); | ||||||
|  | $application->run(); | ||||||
							
								
								
									
										102
									
								
								samples/Perl/index.fcgi
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										102
									
								
								samples/Perl/index.fcgi
									
									
									
									
									
										Executable file
									
								
							| @@ -0,0 +1,102 @@ | |||||||
|  | #!/usr/bin/perl | ||||||
|  |  | ||||||
|  | use strict; | ||||||
|  | use warnings; | ||||||
|  |  | ||||||
|  | use CGI::Fast; | ||||||
|  | use XML::Hash::XS; | ||||||
|  | use File::Spec; | ||||||
|  | use FindBin qw($Bin); | ||||||
|  |  | ||||||
|  | #use lib File::Spec->catdir($Bin, qw(.. lib)); | ||||||
|  |  | ||||||
|  | my $_stop = 0; | ||||||
|  | my $request; | ||||||
|  | $SIG{'PIPE'} = 'IGNORE'; | ||||||
|  |  | ||||||
|  | $SIG{'INT'} = $SIG{'TERM'} = sub { | ||||||
|  | 	$_stop = 1; | ||||||
|  |  | ||||||
|  | 	exit(0) unless defined($request); | ||||||
|  | }; | ||||||
|  |  | ||||||
|  | unless ($ENV{'SERVER_SOFTWARE'}) { # for nginx external fcgi | ||||||
|  | 	$CGI::Fast::Ext_Request = FCGI::Request( | ||||||
|  | 		\*STDIN, \*STDOUT, \*STDERR, | ||||||
|  | 		\%ENV, int($ARGV[0] || 0), 1 | ||||||
|  | 	); | ||||||
|  | } | ||||||
|  |  | ||||||
|  | my $conv = XML::Hash::XS->new( | ||||||
|  | 	use_attr => 1, | ||||||
|  | 	indent   => 2, | ||||||
|  | 	output   => \*STDOUT, | ||||||
|  | 	xml_decl => 1 | ||||||
|  | ); | ||||||
|  |  | ||||||
|  | my $tmpl_path = File::Spec->catdir($Bin, qw|.. tmpl|); | ||||||
|  |  | ||||||
|  |  | ||||||
|  | my $data = { | ||||||
|  | 	name => { | ||||||
|  | 		nick => 'cono' | ||||||
|  | 	}, | ||||||
|  | 	tree => { | ||||||
|  | 		example => [ | ||||||
|  | 			{ name => 'Encyclopaedia', parent => 0, id => 1 }, | ||||||
|  | 			{ name => 'Science',       parent => 1, id => 2 }, | ||||||
|  | 			{ name => 'Culture',       parent => 1, id => 3 }, | ||||||
|  | 			{ name => 'Art',           parent => 3, id => 4 }, | ||||||
|  | 			{ name => 'Craft',         parent => 3, id => 5 } | ||||||
|  | 		], | ||||||
|  | 	}, | ||||||
|  | 	third_party => { | ||||||
|  | 		results => [ | ||||||
|  | 			{ artist_name => 'Madonna', venue => 'Kitchen',      event => 'cooking',      date => '2013-04-21' }, | ||||||
|  | 			{ artist_name => 'cono',    venue => 'Provectus-IT', event => 'presentation', date => '2013-04-20' }, | ||||||
|  | 		] | ||||||
|  | 	} | ||||||
|  | }; | ||||||
|  |  | ||||||
|  | while (1) { | ||||||
|  | 	eval { | ||||||
|  | 		$request = CGI::Fast->new(); | ||||||
|  | 		unless ($request) { | ||||||
|  | 			$_stop = 1; | ||||||
|  |  | ||||||
|  | 			return; | ||||||
|  | 		} | ||||||
|  |  | ||||||
|  | 		my ($tmpl, $output) = ('nick'); | ||||||
|  | 		if ($ENV{'REQUEST_URI'} =~ m|/([a-zA-Z0-9_]+)|) { | ||||||
|  | 			$tmpl = $1; | ||||||
|  | 			$output = $data->{$tmpl} if exists $data->{$tmpl}; | ||||||
|  | 		} | ||||||
|  |  | ||||||
|  | 		die "Bad request" unless $output; | ||||||
|  |  | ||||||
|  | 		if (-e File::Spec->catfile($tmpl_path, "$tmpl.xslt")) { | ||||||
|  | 			print "X-Xslt-Stylesheet: /$tmpl.xslt\r\n"; | ||||||
|  | 		} | ||||||
|  |  | ||||||
|  | 		print qq(Content-type:application/xml;charset=utf-8\r\n\r\n); | ||||||
|  | 		$conv->hash2xml($output); | ||||||
|  |  | ||||||
|  | 	}; | ||||||
|  |  | ||||||
|  | 	if ($@) { | ||||||
|  | 		print qq(Content-type:text/html;charset=utf-8\r\n\r\nError: $@); | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	$request = undef; | ||||||
|  | 	last if $_stop; | ||||||
|  |  | ||||||
|  | 	if (-M $0 < 0) { | ||||||
|  | 		unless ($ENV{'SERVER_SOFTWARE'}) { # for nginx external fcgi | ||||||
|  | 			system("$0 ". int($ARGV[0] || 0).' &'); | ||||||
|  | 		} | ||||||
|  | 		last; | ||||||
|  | 	} | ||||||
|  | } | ||||||
|  |  | ||||||
|  | exit(0); | ||||||
							
								
								
									
										23
									
								
								samples/Perl6/RoleQ.pm6
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										23
									
								
								samples/Perl6/RoleQ.pm6
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,23 @@ | |||||||
|  | role q { | ||||||
|  |     token stopper { \' } | ||||||
|  |  | ||||||
|  |     token escape:sym<\\> { <sym> <item=.backslash> } | ||||||
|  |  | ||||||
|  |     token backslash:sym<qq> { <?before 'q'> <quote=.LANG('MAIN','quote')> } | ||||||
|  |     token backslash:sym<\\> { <text=.sym> } | ||||||
|  |     token backslash:sym<stopper> { <text=.stopper> } | ||||||
|  |  | ||||||
|  |     token backslash:sym<miscq> { {} . } | ||||||
|  |  | ||||||
|  |     method tweak_q($v) { self.panic("Too late for :q") } | ||||||
|  |     method tweak_qq($v) { self.panic("Too late for :qq") } | ||||||
|  | } | ||||||
|  |  | ||||||
|  | role qq does b1 does c1 does s1 does a1 does h1 does f1 { | ||||||
|  |     token stopper { \" } | ||||||
|  |     token backslash:sym<unrec> { {} (\w) { self.throw_unrecog_backslash_seq: $/[0].Str } } | ||||||
|  |     token backslash:sym<misc> { \W } | ||||||
|  |  | ||||||
|  |     method tweak_q($v) { self.panic("Too late for :q") } | ||||||
|  |     method tweak_qq($v) { self.panic("Too late for :qq") } | ||||||
|  | } | ||||||
Some files were not shown because too many files have changed in this diff Show More
		Reference in New Issue
	
	Block a user