Compare commits

..

460 Commits

Author SHA1 Message Date
Adam Roben
470419d732 Merge pull request #1962 from github/bump-4.2.6
Bump to v4.2.6
2015-01-07 10:57:29 -05:00
Adam Roben
5b05653881 Bump to v4.2.6 2015-01-07 10:30:51 -05:00
Adam Roben
899dc07883 Merge pull request #1938 from floscher/carto-grammar
Add grammar for CartoCSS
2015-01-07 09:31:34 -05:00
Florian M. Schäfer
83dfd408e9 Update carto-grammar to current version (2ec5a89) 2015-01-07 15:27:40 +01:00
Florian M. Schäfer
417171cfe1 Don't pass JSON-files through csonc 2015-01-07 15:27:40 +01:00
Florian Schäfer
e8e82a1ca3 Add grammar for CartoCSS 2015-01-07 15:27:40 +01:00
Florian Schäfer
6843aa7cc8 Enable file extension .json for grammar files 2015-01-07 15:27:40 +01:00
Adam Roben
952acc983d Merge pull request #1958 from floscher/fix-convert-script
Fixes script/convert-grammars: require thread-gem and solve problem with visibility of variable p
2015-01-07 08:58:34 -05:00
Adam Roben
650f267be7 Merge pull request #1959 from floscher/licence
Allow British-English spelled LICENCE-files
2015-01-07 08:56:20 -05:00
Florian M. Schäfer
3ace4c57f7 Allow British-English LICENCE-files 2015-01-06 22:51:08 +01:00
Florian M. Schäfer
ab1b603c78 Require thread-gem and solve problem with visibility of variable p in convert-grammars
* The `thread`-gem is required for the script, because otherwise Ruby throws an error that `Queue` in line 259 is an uninitialized constant
* The variable `p` was previously in the same method with the status message saying `OK ‹path› ‹converted scopes›`. But `p` is now defined in load_grammars() and thus not visible when showing the OK-message in install_grammars(). This was solved by adding a path-parameter to install_grammars().
2015-01-06 22:06:55 +01:00
Adam Roben
8430f694e5 Merge pull request #1954 from github/test-grammar-licenses
Test that all grammar submodules have an appropriate license
2015-01-06 13:59:52 -05:00
Adam Roben
71f0cafc78 Update all submodules
This was done via `git submodule update --remote`.

Since Scalate.tmbundle now has a license we can remove it from the
whitelist.

* vendor/grammars/NimLime 9cef4b6...a7067c6 (1):
  > Added 'nim' to tmpl sublimetext highlighting

* vendor/grammars/Scalate.tmbundle 4f85314...0307535 (1):
  > Merge pull request #3 from aroben/patch-1

* vendor/grammars/fsharpbinding d097476...99d2e9a (2):
  > Merge pull request #917 from 7sharp9/CleanMacProjects
  > Merge pull request #916 from 7sharp9/ToolTipsLessBlocky

* vendor/grammars/language-clojure d649d9f...bae6eee (2):
  > Prepare 0.10.0 release
  > Rename scoped-properties/ to settings/

* vendor/grammars/language-coffee-script c6e8d33...d86c896 (2):
  > Prepare 0.39.0 release
  > Rename scoped-properties/ to settings/

* vendor/grammars/language-gfm 7b62290...6af44a0 (2):
  > Remove unneeded newline
  > Merge pull request #65 from braver/line-break

* vendor/grammars/language-javascript 6690feb...5157519 (2):
  > Prepare 0.53.0 release
  > Rename scoped-properties/ to settings/

* vendor/grammars/language-python f518e49...46072e3 (2):
  > Prepare 0.29.0 release
  > Rename scoped-properties/ to settings/

* vendor/grammars/language-shellscript cbec163...9839719 (2):
  > Prepare 0.12.0 release
  > Rename scoped-properties/ to settings/

* vendor/grammars/language-yaml eddd079...ce8b441 (2):
  > Prepare 0.22.0 release
  > Rename scoped-properties/ to settings/
2015-01-06 13:46:04 -05:00
Adam Roben
4614287a55 Test that all grammar submodules have an appropriate license
We require all grammars to have a license that permits redistribution. A
few existing grammars have been grandfathered in without a license (and
we're working to remedy that), but no new grammars should be added
without a license.
2015-01-06 13:44:11 -05:00
Adam Roben
f477f811df Extract TestGrammars#submodule_paths method 2015-01-06 13:43:50 -05:00
Adam Roben
95bb5a1ae4 Switch to the master branch of tenbits/sublime-mask
The master branch contains a license while the release branch does not.
Other than that they're nearly identical.
2015-01-06 13:43:37 -05:00
Adam Roben
70699037ae Merge pull request #1909 from github/scopes-test
Test that grammars.yml lists the right scopes for each submodule
2015-01-06 13:41:44 -05:00
Adam Roben
7edddec920 Make convert-grammars a little quieter
No need to say "Done" at the end. We're obviously done; the script is
exiting.
2015-01-06 13:39:18 -05:00
Adam Roben
8f3779c94c Update grammars.yml to match submodules
I should have done this in 2c2c4740a8.
2015-01-06 13:36:51 -05:00
Adam Roben
917bc48348 Use File.directory? to test for local directories
Some of our submodules end in ".tmLanguage", which we used to think
meant it was a file rather than a directory.
2015-01-06 13:31:26 -05:00
Adam Roben
581dc36c47 Ruby 1.9 compatibility for convert-grammars 2015-01-06 13:28:26 -05:00
Adam Roben
a4286ba950 Show stderr output when running convert-grammars
This will let us see why it's failing.
2015-01-06 13:28:26 -05:00
Adam Roben
5fa85f268f Ruby 1.9 compatibility 2015-01-06 13:28:26 -05:00
Adam Roben
ada6f6882a Test that grammars.yml lists the right scopes for each submodule
convert-grammars now supports a few flags that we can use to make it
dump out the YAML just for the local grammar submodules. We can then
compare this to the YAML that's actually in grammars.yml to check that
they're the same. If they aren't, grammars.yml needs to be updated.
This will help catch mistakes like using the wrong scope name.
2015-01-06 13:28:25 -05:00
Adam Roben
78a0030d46 download-grammars -> convert-grammars
Downloading is only a small part of what this script does. The main
thing it does is convert grammars to JSON.
2015-01-06 13:28:25 -05:00
Adam Roben
e2d6aecd81 Merge pull request #1956 from github/new-sass-grammar
Switch Sass grammar to nathos/sass-textmate-bundle
2015-01-06 13:26:09 -05:00
Patrik Affentranger
a2e99e8ddb Switch Sass grammar to nathos/sass-textmate-bundle
This provides better highlighting in many cases than the previous
grammar. See https://github.com/github/linguist/pull/1852.
2015-01-06 13:18:30 -05:00
Adam Roben
b499a074cf Merge pull request #1931 from github/travis-container
Opt in to container-based Travis CI builds
2015-01-06 13:02:53 -05:00
Adam Roben
188e579df7 Use a single git fetch invocation in CI 2015-01-06 12:56:08 -05:00
Adam Roben
d82e4801ff Use --with-icu-dir everywhere but Ruby 2.0
--with-icu-dir is broken on Ruby 2.0 due to
https://bugs.ruby-lang.org/issues/8074. Specifying
--with-icu-include/--with-icu-lib is broken on Ruby 2.1 and newer due to
https://github.com/bundler/bundler/pull/3338. So now we use
--with-icu-dir everywhere but Ruby 2.0.
2015-01-06 12:44:39 -05:00
Adam Roben
d258d146b8 Move before_install steps to a separate script 2015-01-06 12:44:14 -05:00
Adam Roben
ae6b0f0d40 Merge pull request #1953 from github/update-grammars
Update all grammar submodules
2015-01-06 10:18:52 -05:00
Adam Roben
2c2c4740a8 Update all grammar submodules
This was performed via `git submodule update --remote`.

* vendor/grammars/Agda.tmbundle 784f435...68a218c (1):
  > Merge pull request #1 from aroben/patch-1

* vendor/grammars/IDL-Syntax 9473b7f...3baeaea (1):
  > Merge pull request #3 from aroben/patch-1

* vendor/grammars/NimLime 7a2fb4e...9cef4b6 (4):
  > Updated command names
  > Updated generated documentation
  > renamed more from nimrod to nim
  > Renamed several files

* vendor/grammars/SCSS.tmbundle d6188e5...4147502 (1):
  > Merge pull request #181 from redgluten/master

* vendor/grammars/Sublime-VimL 6ab7e19...366fdc6 (1):
  > Merge pull request #2 from yous/fix-single-quoted-string

* vendor/grammars/factor 2dc5590...2453a78 (38):
  > json.writer: make sure we make hex values two digits zero padded.
  > json.writer: support escaping unicode > 0x10000.  Thanks @jonenst!
  > mason.git: fix status check.
  > compiler.cfg.*: new unit test vocabs
  > compiler.cfg.*: more docs
  > compiler.cfg.*: refactoring away the compute-global-sets word
  > compiler.cfg.*: docs and more tests
  > compiler.cfg.stacks.local: refactoring making stack-changes and height-changes take and return stuff instead of using variables and the make building
  > compiler.cfg.parallel-copy: docs
  > compiler.cfg.stacks.height: these words are unused
  > compiler.cfg.*: more compiler docs
  > compiler.cfg.stacks.finalize: initial docs
  > io.launcher: fix stack effects.
  > io.launcher: fix docs for with-process-reader and with-process-writer.
  > io.launcher: add versions of with-process that preserve process and status.
  > mason.git: fix use.
  > mason.git: fix for rename.
  > io.launcher: cleanup public interface, make some things private or internal.
  > gopher: set 1 minute timeout by default.
  > brainfuck: cleanup tests.
  > json.writer: don't escape spaces, thats weird.
  > unix: some using cleanups.
  > python: rename startup/shutdown hooks.
  > math.extras: adding the Möbius function.
  > alien.c-types: move definitions of stdint.h from unix.types.
  > gopher: use contents now that it works.
  > io.ports: Make buffered-port not have a length because of Linux virtual files and TCP sockets. Related to issues #1256 and #1259.
  > tools.deploy.backend: add word for deleting cached staging images.
  > command-line: save the executable in a variable so that people don't use (command-line) directly if possible.
  > bootstrap: fix this use of (command-line).
  > tools.deploy.shaker: set the rest of the args to preserve current behavior.
  > vm: store full command-line including executable first argument.
  > gopher: fix bug where empty lines weren't printed properly in menus.
  > gopher: simplify.
  > gopher: change gopher-text to use split1.
  > io.encodings.detect: simplify prolog-tag.
  > gopher: add way to get result without converting to objects.
  > tools.disassembler: allow disassemble of compose and curry.

* vendor/grammars/fsharpbinding af755c8...d097476 (24):
  > Merge pull request #909 from cbowdon/issue877-vim-73-support
  > Merge pull request #913 from 7sharp9/Move_GetColourizations_toBg
  > Merge pull request #912 from 7sharp9/TryFind_opt
  > Merge pull request #911 from 7sharp9/FoldingParser
  > Merge pull request #908 from 7sharp9/TooltipOverhaul_AutoParamFix
  > Merge pull request #907 from 7sharp9/Movegetdefinestomodule
  > Merge pull request #906 from 7sharp9/tooltipfixforclosures
  > Merge pull request #905 from 7sharp9/ResolverProvider_singletimeout
  > Merge pull request #904 from fsharp/revert-903-ResolverProvider_singletimeout
  > Merge pull request #903 from 7sharp9/ResolverProvider_singletimeout
  > Merge pull request #902 from 7sharp9/ParameterCompletion_gatherTimeout
  > Merge pull request #901 from 7sharp9/Changed_invalidate_project
  > Merge pull request #900 from 7sharp9/Syntaxmode_removeextraoperation
  > Merge pull request #899 from 7sharp9/tooltips_ensureTimout
  > Merge pull request #898 from 7sharp9/pathextension_useAddRange
  > Merge pull request #897 from 7sharp9/resolverprovider_ensuretimout
  > Merge pull request #896 from 7sharp9/completion_ensuretimout
  > Merge pull request #895 from cbowdon/894-Vim-fix-for-no-completions-stacktrace
  > Merge pull request #890 from wangzq/gotodecl
  > Merge pull request #893 from 7sharp9/fixfortooltipvaltypes
  > Merge pull request #892 from 7sharp9/fixforprojecttypechecking
  > Added correct indentation
  > Merge pull request #891 from 7sharp9/ImproveImplementInterface
  > Merge pull request #888 from VincentDondain/master

* vendor/grammars/haxe-sublime-bundle 58cad47...e2613bb (4):
  > fixed goto definition / find type
  > clean
  > adaptations for toplevel completion
  > first test

* vendor/grammars/language-gfm c6df027...7b62290 (7):
  > Prepare 0.59.0 release
  > scoped-properties -> settings
  > Prepare 0.58.0 release
  > Merge pull request #67 from davidcelis/master
  > Prepare 0.57.0 release
  > Prepare 0.56.0 release
  > Merge pull request #64 from atom/mb-new-cpp-scope-name

* vendor/grammars/language-javascript 15dc5d1...6690feb (5):
  > Prepare 0.52.0 release
  > Merge pull request #82 from Hurtak/feature/snippets-for
  > Merge pull request #80 from Hurtak/feature/snippets-querySelector
  > Merge pull request #79 from Hurtak/feature/snippets-switch-indentation-fix
  > Merge pull request #81 from Hurtak/feature/snippets-iife

* vendor/grammars/language-python 476a353...f518e49 (5):
  > Prepare 0.28.0 release
  > Use trailing scope name
  > Merge pull request #48 from msabramo/patch-1
  > Prepare 0.27.0 release
  > Add pattern for nonlocal keyword

* vendor/grammars/language-sass 064a8b5...33efa33 (2):
  > Prepare 0.29.0 release
  > Allow + and - in selector argument

* vendor/grammars/language-shellscript e2d62af...cbec163 (2):
  > Prepare 0.11.0 release
  > Merge pull request #4 from hd-deman/patch-1

* vendor/grammars/latex.tmbundle 682c4b7...52b2251 (42):
  > Replaced `python` with `python2.7` in shebangs
  > Make the preferences compatible with Python 3
  > Handle manual spacing in “Reformat” (Table)
  > Fix: Reformatting of table containing empty cells
  > Use more descriptive variable names in `format`
  > Add documentation to `reformat`
  > Fix doctest in `refresh_viewer`
  > Add tests for `reformat`
  > Ignore “exit discard” status in `cramtests`
  > Remove print statements from `reformat` function
  > Fix: Close log window option ignored
  > Automatically scroll to bottom in “HTML Output”
  > Handle “\” signs in the notification window
  > Fix missing logname in default error message
  > Extend list of auxiliary files
  > Remove unused code from `latex_watch`
  > Display default message in notification window
  > Sort error messages by line number
  > Do not store duplicate error messages anymore
  > Close notification window on cleanup
  > Improve reopening of closed notification windows
  > Improve rewrap code in `texparser`
  > Improve readability of verbose log output
  > Only parse log file if there were changes
  > Remove unnecessary function call in “LaTeX Watch”
  > Properly close file in `guess_tex_engine`
  > Handle log messages containing double quotes
  > Left justify severity in notification window
  > Handle manual closing of notification window
  > Add additional information to notification window
  > Remove unused code from `texparser`
  > Close notification when typesetting succeeds
  > Add support for notifications to “LaTeX Watch”
  > Update bundle preference values instantly
  > Make “Reformat” (Table) compatible with Ruby 2
  > Ignore escaped ampersand `\&` in “Format” (Table)
  > Remove warnings reported by `RuboCop`
  > Format code for “Reformat” (Table)
  > Move code for “Reformat” into separate script
  > Save “Reformat” command with TextMate 2
  > Remove unused import
  > Use explicit import in “Itemize Lines In Selection”

* vendor/grammars/mercury-tmlanguage b5a4fd6...eaef0b0 (8):
  > Add require_* and some, all keywords
  > Highlight %f format specifiers, `` as op
  > Correct implementation of '''', """" and 0'<char>
  > README.md: Mention GitHub grammar compatability
  > README.md: add resources and demonstration
  > reformatted whitespace; added foreign mods; missing keywords
  > Highlight variables, determ decls, more pragmas
  > no highlighting of variables, function names, type names, inst's, etc.

* vendor/grammars/sublime-mask 2f59519...632ff3c (4):
  > v0.8.7
  > v0.8.7
  > + expression in component nodes
  < v0.8.6

* vendor/grammars/swift.tmbundle 81a0164...3c7eac5 (9):
  > Use constant scope for booleans
  > Use storage scope instead of keyword
  > Correct typo in include
  > Revamp string literal matching
  > Improve punctuation scopes
  > Allow for functions without a body
  > Add simple folding markers for swift
  > Improved matching of capture specifiers
  > Add Support for UInt, Int[8|16|32|64] & Float80
2015-01-06 10:09:53 -05:00
Adam Roben
4428e62b99 Merge pull request #1950 from github/upstream-c-bundle
Switch back to textmate/c.tmbundle
2015-01-05 15:24:42 -05:00
Adam Roben
575ad0d8a2 Switch back to textmate/c.tmbundle
We were using a fork to get the fix for
https://github.com/textmate/c.tmbundle/pull/24 before it was merged
upstream. Now it's been merged so we can go back to the upstream
repository.
2015-01-05 15:07:28 -05:00
Arfon Smith
ec01672f6c Merge pull request #1866 from github/cpp-c-improvements
Better C++ regex
2015-01-03 11:23:20 -06:00
Arfon Smith
be6b1bb3ee Merge branch 'master' into cpp-c-improvements 2015-01-03 11:12:55 -06:00
Arfon Smith
6f4557a103 Updating Objective-C matchers and adding a sample C++ file 2015-01-03 11:10:24 -06:00
Arfon Smith
55132f2955 Merge pull request #1945 from thotypous/bluespec
Add Bluespec SystemVerilog grammar
2015-01-02 21:14:52 -06:00
Paulo Matias
ebdd2d4a23 Add Bluespec SystemVerilog Sublime Text grammar 2015-01-03 00:55:19 -02:00
Arfon Smith
4c63827517 Merge pull request #1942 from pchaigno/xml.dist
Add .xml.dist as a XML file extension
2015-01-02 17:07:32 -06:00
Paul Chaignon
8e6609c192 .xml.dist as an XML file extension 2015-01-02 22:29:44 +01:00
Adam Roben
1f1ffcbfa6 Merge pull request #1930 from github/minitest
Switch to Minitest::Test instead of Test::Unit::TestCase
2015-01-02 16:27:43 -05:00
Adam Roben
065dd713c1 Assert that generated files are detected correctly 2015-01-02 16:15:55 -05:00
Arfon Smith
71132d48ff Merge pull request #1922 from Mailaender/patch-2
Added support for Mono .dll.config XML files
2015-01-02 11:10:46 -06:00
Matthias Mailänder
d77e0c62c1 add a DllMap example file
www.mono-project.com/docs/advanced/pinvoke/dllmap/#example
2015-01-02 17:28:37 +01:00
Matthias Mailänder
e853c36039 Update languages.yml
add support for Mono .dll.config XML files
2015-01-02 17:28:36 +01:00
Brandon Keepers
2be3220824 Merge pull request #1940 from github/fix-multiple-extensions
Fix for extensions with multiple segments
2015-01-02 10:59:30 -05:00
Lars Brinkhoff
6ae39e50ae Fix #1731 to allow samples with multiple file extension segments. 2015-01-02 10:41:22 -05:00
Arfon Smith
c783acc973 Merge pull request #1937 from github/hack-highlighting
Update languages.yml for Hack syntax-highlighting
2015-01-02 07:38:24 -06:00
Arfon Smith
e5210b5137 Update languages.yml 2015-01-02 06:53:58 -06:00
Arfon Smith
41f0950c04 Merge pull request #1933 from floscher/patch-1
Added CartoCSS to languages.yml
2015-01-01 13:46:22 -06:00
Florian Schäfer
9f439cd7fb Added support for CartoCSS
Code sample was taken from https://github.com/gravitystorm
/openstreetmap-carto/blob/ae990905790a26ae8af107441ce9e85b60ea1266
/amenity-points.mss
2015-01-01 17:15:22 +01:00
Arfon Smith
c911c5c045 Merge pull request #1932 from deadfoxygrandpa/elm
Update Elm support by adding its own syntax highlighting
2015-01-01 09:16:29 -06:00
Alex Neslusan
27a7873e08 Add color to Elm language definition 2015-01-01 20:41:05 +08:00
Alex Neslusan
5fe233384e Update Elm support 2015-01-01 20:24:13 +08:00
Adam Roben
d42ad45423 Turn on the bundler cache
This should allow us to skip installing gems in most builds, shaving off
~40 seconds.
2014-12-31 15:42:34 -05:00
Adam Roben
84235478ef Download and install libicu-dev without using sudo
We tell apt-get to download it to vendor/apt and then install it into a
vendor/icu directory.

We should be able to just specify --with-icu-dir, but apparently Ruby
2.0 (but not 1.9 or 2.1 or 2.2) has a bug that requires us to use
--with-icu-include/--with-icu-lib instead. Otherwise it can't find the
ICU libraries.
2014-12-31 15:42:34 -05:00
Adam Roben
509b35a19f Opt in to container-based Travis CI builds
This should speed up our builds by providing lower latency, better
caching, and more resources on the build machine. See
http://docs.travis-ci.com/user/workers/container-based-infrastructure/.
2014-12-31 15:42:34 -05:00
Adam Roben
65296e86a3 Switch to Minitest::Test instead of Test::Unit::TestCase
This gives us a consistent test framework across all Ruby versions which
should help avoid errors that are only found when CI runs the tests on
different Rubies. (And this fixes an immediate bug where there's no
`skip` method in the version of test-unit we're currently using only on
Ruby 2.2.)
2014-12-31 15:26:26 -05:00
Adam Roben
c9b7bb73b9 Use test/helper.rb in test_file_blob.rb 2014-12-31 15:19:56 -05:00
Adam Roben
795f42cbaa Merge pull request #1832 from pchaigno/optimize-generated
Optimization of generated?
2014-12-31 15:19:43 -05:00
Arfon Smith
d540ec0cb8 Merge pull request #1928 from github/contributing-update
Update including explicit steps to resolve conflicts.
2014-12-31 11:38:48 -06:00
Arfon Smith
202cba1a14 Update CONTRIBUTING.md 2014-12-31 11:38:03 -06:00
Arfon Smith
20d5b81085 Merge pull request #1929 from github/1304-local
Take 2: Add support for .sls YAML files (SaltStack states)
2014-12-31 09:45:14 -06:00
Arfon Smith
d8b806592d Removing trailing slash 2014-12-31 08:27:40 -06:00
Arfon Smith
84f9b83fc2 Fixing up grammars 2014-12-31 08:25:56 -06:00
Arfon Smith
7cb5106656 Adding atom-salt gitsubmodule 2014-12-31 07:48:48 -06:00
Arfon Smith
6f21df7624 Merge branch 'master' into 1304-local
Conflicts:
	grammars.yml
2014-12-30 22:15:55 -06:00
Arfon Smith
4c7dc565e7 Update including explicit steps to resolve conflicts. 2014-12-30 20:52:48 -06:00
Adam Roben
3c60fba430 Merge pull request #1926 from github/sas-grammar
Added support for SAS syntax.
2014-12-30 07:26:32 -05:00
Roy Pardee
224eef9ffa Added support for SAS syntax. 2014-12-30 06:34:37 -05:00
Paul Chaignon
42beadcf34 Use an exception for tests on Generated.generated? 2014-12-28 17:00:13 +01:00
Brandon Keepers
80ed2d6d30 Merge pull request #1920 from pchaigno/webidl-grammar
Grammar for WebIDL
2014-12-27 14:55:47 -05:00
Paul Chaignon
c2bf6fe7f5 Grammar for WebIDL 2014-12-27 16:54:41 +01:00
Adam Roben
6f014f8638 Merge pull request #1896 from github/grammar-submodules
Move all grammars that use Git repos to submodules
2014-12-22 17:17:40 -05:00
Adam Roben
66ca5aca89 Init submodules in CI 2014-12-22 17:07:37 -05:00
Adam Roben
33afa30c30 Don't use question marks in struct fields
Apparently it doesn't work in Ruby 1.9.
2014-12-22 17:06:49 -05:00
Adam Roben
1634d787ec Use fast-submodule-update in CI
Hopefully this will speed up CI builds.
2014-12-22 16:58:59 -05:00
Adam Roben
df7b529e23 Set tracking branches for submodules that aren't tracking master
This will let us use `git submodule update --remote` to update the
submodules to the latest commit from the relevant branch.
2014-12-22 16:41:22 -05:00
Adam Roben
56d90bedd0 Sort grammars.yml 2014-12-22 16:36:35 -05:00
Brandon Keepers
8369d253f8 Move grammar sources to vendor/grammars 2014-12-22 16:28:58 -05:00
Adam Roben
516d3e226c Suggest adding/removing submodules from the repo 2014-12-22 15:50:33 -05:00
Adam Roben
47b785a8fd Initialize submodules before updating them
Initialization cannot happen in parallel because every submodule has to
get written to .git/config.
2014-12-19 16:05:17 -05:00
Adam Roben
6a2bf3fd2f Update submodules in parallel to speed up bootstrap
This runs 8 `git submodule update` processes in parallel, speeding up
bootstrap from 2 minutes to 30 seconds for me. (Obviously this is
dependent on bandwidth.)
2014-12-19 16:05:17 -05:00
Adam Roben
ff678642e6 Suggest running script/bootstrap before building gems
This ensures all our submodules are up to date as well.
2014-12-19 16:05:17 -05:00
Adam Roben
e3eb1b90c5 Test that grammars.yml agrees with the list of submodules
If any submodules are missing from grammars.yml, or are listed in
grammars.yml but missing from the repo, the test will fail.

Eventually it would be good to test that the scopes for each submodule
are accurate, but that will take some more work.
2014-12-19 16:05:17 -05:00
Adam Roben
49125f077c Update grammars.yml
This is just the result of running script/download-grammars.
2014-12-19 15:39:02 -05:00
Adam Roben
324031cb68 Sort grammars.yml 2014-12-19 15:39:02 -05:00
Adam Roben
f2ab426d38 Move all grammars that use Git repos to submodules
This makes it so we don't have to redownload all the grammars every time
we build the grammars gem. It will also let us verify that grammars.yml
is accurate in the future by checking it against the submodules on disk.

script/bootstrap now updates the submodules.
2014-12-19 15:39:02 -05:00
Brandon Keepers
587ab35d65 Merge pull request #1904 from github/remove-cached-gems
Remove cached gems
2014-12-19 11:27:10 -05:00
Brandon Keepers
16a6dda3dd Remove cached gems 2014-12-19 10:52:29 -05:00
Arfon Smith
15191b068d Merge pull request #1890 from github/cut-release-v4.2.4
Updating Linguist version for v4.2.4
2014-12-18 14:31:21 -08:00
Arfon Smith
ee9cc24e52 Longer timeout 2014-12-18 14:28:33 -08:00
Arfon Smith
0584fbf42b 4.2.5 2014-12-18 14:17:36 -08:00
Adam Roben
f5f9ccee7f Merge pull request #1895 from github/bootstrap-script
Add script/bootstrap
2014-12-18 12:20:26 -05:00
Adam Roben
0d183e2e89 Ignore vendor/gems
This is where script/bootstrap places the bundle.
2014-12-18 12:14:45 -05:00
Adam Roben
b9eacfefc8 Add script/bootstrap
This just runs Bundler with the right options. Maybe it will do more in
the future, like update submodules.
2014-12-18 12:13:32 -05:00
Arfon Smith
0239127db4 4.2.5b1 2014-12-18 08:02:24 -08:00
Arfon Smith
281d1ea91c Merge branch 'master' into cut-release-v4.2.4 2014-12-17 15:37:46 -08:00
Arfon Smith
df92ecaa55 Merge pull request #1891 from github/fix-grammars
Fix some bugs in grammars.yml
2014-12-17 15:35:30 -08:00
Adam Roben
60d40c8ad8 Update grammars.yml
I just ran script/download-grammars and these are the changes it made.
The most notable one is that we had the wrong scope listed for Markdown.
2014-12-17 16:39:03 -05:00
Adam Roben
f428c561c9 Remove the WebIDL grammar
This grammar uses the same scope name (source.idl) as our existing IDL
grammar. The wrong scope name was listed in grammars.yml which masked
this problem. https://github.com/andik/IDL-Syntax/pull/2 tracks getting
the grammar to use a different scope name; in the meantime we just won't
highlight these files.
2014-12-17 16:39:03 -05:00
Adam Roben
8fbb7a1d93 Sort grammars.yml 2014-12-17 16:39:03 -05:00
Adam Roben
e98223b2b3 Use raw links as little as possible
It's much cleaner and more robust to specify the repo URL instead of a
URL to an individual file. If the file gets moved we'll still be able to
find it if we're using the repo URL.

Where we do need raw links, we now use github.com/owner/repo/raw/*
because it looks a bit nicer and sorts better with non-raw links.
2014-12-17 16:39:03 -05:00
Adam Roben
410fe2843d Add some tests for grammars.yml
It must be sorted, because it will get re-sorted when
script/download-grammars is next run and that would clutter up diffs.
And it must not contain any duplicate scopes.
2014-12-17 16:39:02 -05:00
Arfon Smith
dc8d69e0f4 Updating Linguist version for v4.2.4 2014-12-17 10:31:51 -08:00
Arfon Smith
a056765e38 Merge pull request #1886 from Dadido3/patch-1
Add PureBasic
2014-12-17 10:28:46 -08:00
Adam Roben
4e7da98bfa Merge pull request #1875 from arctic5/patch-1
change ace mode of game maker language to c++
2014-12-17 08:59:21 -05:00
David Vogel
0a56f5282d Create Example_Sine.pb 2014-12-17 12:00:16 +01:00
Arfon Smith
04b9ca2fd4 Merge pull request #1797 from github/cs-smalltalk
Cs smalltalk
2014-12-17 04:47:37 -06:00
Arfon Smith
ddbe3df6de Merge pull request #1876 from Mailaender/patch-2
Added support for StyleCop XML configuration files
2014-12-16 21:29:55 -06:00
Arfon Smith
ab5c88a7f3 Merge pull request #1881 from hawkw/master
Add support for Jasmin JVM assembly
2014-12-16 21:29:19 -06:00
Arfon Smith
4046a0efe9 Merge pull request #1877 from sebgod/change-mercury-grammar
Added a more suitable grammar for Mercury
2014-12-16 21:27:10 -06:00
Arfon Smith
5aefc7cdff Merge pull request #1885 from github/gjtorikian-patch-1
Use atom/language-atom for the YAML grammar
2014-12-16 21:25:02 -06:00
David Vogel
70eb779ce5 Reduced PureBasic to .pb and .pbi 2014-12-16 22:19:56 +01:00
David Vogel
39f5d28348 Added PureBasic example 2014-12-16 21:12:13 +01:00
David Vogel
e70407f16b Added PureBasic 2014-12-16 20:34:32 +01:00
Garen Torikian
c25475296d Use atom/language-atom for the YAML grammar 2014-12-16 08:17:07 -08:00
Vicent Marti
e97b7454e9 grammars: Temporarily use vmg's fork for C.tmbundle 2014-12-16 17:02:09 +01:00
Hawk Weisman
735caa03b1 Fix empty sample file. 2014-12-15 22:47:11 -05:00
Hawk Weisman
f577aece08 Add Objective-J samples 2014-12-15 22:40:02 -05:00
Hawk Weisman
b7f1bfdb92 Put Jasmin entry in the right place. 2014-12-15 22:37:17 -05:00
Hawk Weisman
b5301e280b Add some samples of Jasmin assembly 2014-12-15 21:35:14 -05:00
Hawk Weisman
741816db52 Add Jasmin to languages.yml 2014-12-15 21:29:26 -05:00
Hawk Weisman
546a6e2a68 Add Jasmin textmate language 2014-12-15 21:27:06 -05:00
Sebastian Godelet
1be5e8c63e Added a more suitable grammar for Mercury 2014-12-15 10:31:50 +08:00
Matthias Mailänder
917a25317a sort alphabetically 2014-12-14 15:27:39 +01:00
Matthias Mailänder
949167e6ad add support for StyleCop XML configuration files 2014-12-14 13:04:31 +01:00
arctic
a359905a06 change ace mode of game maker language to c++ 2014-12-13 23:41:31 -08:00
Arfon Smith
4ce606306d Merge pull request #1871 from github/fish
Fish
2014-12-12 11:24:40 -06:00
Arfon Smith
707fcd29ea Merge branch 'master' into fish
Conflicts:
	grammars.yml
	lib/linguist/languages.yml
2014-12-12 11:22:24 -06:00
Arfon Smith
970cbe35b8 :blank: -> \t 2014-12-12 08:23:17 -06:00
Arfon Smith
fa9e8aa5c0 Merge branch 'master' into cpp-c-improvements 2014-12-12 08:21:32 -06:00
Brandon Keepers
a5e6d37049 Merge pull request #1859 from pchaigno/rc-interpreter
rc as a Shell interpreter for Plan 9
2014-12-11 22:49:27 -05:00
Arfon Smith
dacac135fb Merge pull request #1868 from github/no-language
No language
2014-12-11 21:23:02 -06:00
Arfon Smith
0ddf0d5d0d Merge branch 'master' into no-language
Conflicts:
	lib/linguist/heuristics.rb
2014-12-11 21:17:38 -06:00
Arfon Smith
90a5251fa7 Merge branch 'master' into cpp-c-improvements 2014-12-11 21:11:32 -06:00
Arfon Smith
a97c69e06f BitBake ace_mode 2014-12-11 21:10:57 -06:00
Arfon Smith
a323eb43ed Better C++ regex 2014-12-11 21:06:35 -06:00
Arfon Smith
79243b77fd Merge pull request #1129 from pchaigno/bitbake
Support of the BitBake language
2014-12-11 20:58:06 -06:00
Arfon Smith
5ab2720ddc Merge pull request #1865 from github/webidl
Webidl
2014-12-11 20:56:05 -06:00
Arfon Smith
c72a49b77f Whitespace 2014-12-11 20:52:44 -06:00
Arfon Smith
a0d92b80df Merge branch 'master' into webidl
Conflicts:
	grammars.yml
2014-12-11 20:52:17 -06:00
Arfon Smith
1a32a6252b Merge pull request #1861 from github/aroben-patch-1
Suggest reproducing highlighting errors in text editors
2014-12-11 20:45:33 -06:00
Arfon Smith
6df7cbaf6e Merge pull request #1864 from github/robrix-patch-1
Use atom/language-gfm’s Markdown grammar.
2014-12-11 20:44:37 -06:00
Rob Rix
0a90cd3a0a Remove the accidental “m”. 2014-12-11 16:38:10 -05:00
Rob Rix
c529939481 Use atom/language-gfm’s Markdown grammar.
We render [GitHub Flavoured Markdown](https://help.github.com/articles/github-flavored-markdown/) on the site. We can use Atom’s grammar to ensure that syntax highlighting uses the same dialect.
2014-12-11 16:29:36 -05:00
Paul Chaignon
db70630eaa Renamed text in Text 2014-12-11 12:51:09 -05:00
Adam Roben
24862d9759 Merge pull request #1863 from github/popular-integrity
Test that all popular languages exist
2014-12-11 12:31:08 -05:00
Adam Roben
cb5f2685cd Test that all popular languages exist
popular.yml listed "Bash" but should have been listing "Shell" instead.
There is no "Bash" language. Now CI will fail if this happens again.
2014-12-11 11:47:52 -05:00
Brandon Keepers
baa298873a Merge pull request #1854 from github/more-shebang-fixes
More shebang fixes
2014-12-11 10:40:11 -05:00
Adam Roben
a8f57d37bf Merge pull request #1860 from github/atom-sass-grammar
Use atom/language-sass's Sass grammar
2014-12-11 09:52:14 -05:00
Adam Roben
d97ee52f4e Suggest reproducing highlighting errors in text editors
This will make for more useful upstream bug reports.
2014-12-11 09:39:24 -05:00
Adam Roben
1cfdb6decd Use atom/language-sass's Sass grammar
This works better than the old Ruby Sass.tmbundle we were pulling from
svn.textmate.org.

atom/language-sass also contains an SCSS grammar, but I didn't switch to
using that grammar because it isn't obviously better than our current
one and I'm not an SCSS expert.
2014-12-11 09:35:33 -05:00
Paul Chaignon
f93272f0bd Move text files from fixtures to samples when possible 2014-12-10 20:09:14 -05:00
Paul Chaignon
e783e953d9 Merge branch 'master' into data-fixture-folder 2014-12-10 19:15:41 -05:00
Paul Chaignon
39cac919c7 rc as a Shell interpreter for Plan 9 2014-12-10 19:12:28 -05:00
Arfon Smith
fec82173d9 Merge pull request #1856 from lutoma/xelix-c-samples
Add a bunch of C header samples for the Bayesian classifier
2014-12-10 15:29:18 -06:00
Lukas Martini
35efed73d4 Add a bunch of C header samples for the Bayesian classifier 2014-12-10 20:28:20 +01:00
Brandon Keepers
21b8e16afc Use #start_with? for clarity 2014-12-10 12:05:37 -05:00
Brandon Keepers
6efee51101 Add missing test cases 2014-12-10 11:00:46 -05:00
Brandon Keepers
1490425ecb document shebang code 2014-12-10 11:00:41 -05:00
Brandon Keepers
afac6a918d Handle empty shebang with whitespace 2014-12-10 11:00:32 -05:00
Brandon Keepers
bf0e488c06 Test case for case causing error 2014-12-10 10:58:14 -05:00
othree
37c2bee3ae Follow #1831, change WebIDL ace_mode to 'text' 2014-12-10 14:18:25 +08:00
othree
4debcabb88 Add syntax define for WebIDL 2014-12-10 12:03:59 +08:00
Garen Torikian
5a0c637ad0 Merge pull request #1831 from github/return-nil-on-no-ace-mode
Set "missing" ace modes to `text`
2014-12-09 10:53:47 -08:00
othree
d91215680a Add WebIDL support and two sample file 2014-12-10 01:28:23 +08:00
Garen Torikian
0cbcbd4614 Set Public Key ace_mode to text 2014-12-09 09:16:51 -08:00
Garen Torikian
19135f08c3 Merge branch 'master' into return-nil-on-no-ace-mode 2014-12-09 09:13:02 -08:00
Brandon Keepers
855cc52f0f Merge pull request #1844 from pchaigno/pgp
Public Key as a language with .asc and .pub extensions
2014-12-09 11:24:18 -05:00
Garen Torikian
4e5da23474 Add warn message indicating deprecation 2014-12-09 08:20:15 -08:00
Arfon Smith
3cca4ec0ac Merge pull request #1848 from larsbrinkhoff/again_with_the_fortran
Improve FORTRAN heuristic.
2014-12-08 16:02:58 -06:00
Lars Brinkhoff
e393f7feb4 Improve FORTRAN heuristic. 2014-12-08 13:53:19 +01:00
Arfon Smith
b76ac7bab0 Merge pull request #1845 from lostcolony/patch-1
Adding 'erlang.mk' to vendor.yml exclusion list.
2014-12-07 17:45:48 -06:00
lostcolony
a3c842ba18 Adding erlang.mk to exclusion list.
Adding 'erlang.mk' to list of erlang bundles; it's seeing some adoption in the Erlang community for building Erlang apps, and at 1k lines of code at present can dominate an initial check-in, project skeleton, or small library.

See https://github.com/ninenines/erlang.mk for further details.
2014-12-07 16:41:56 -05:00
Paul Chaignon
1640370c9d Add Public Key as a language with .asc and .pub extensions 2014-12-07 10:37:25 -05:00
Garen Torikian
b6427fa05a Set text's ace_mode to text 2014-12-07 14:48:36 +02:00
Garen Torikian
2a04d854cc Merge branch 'master' into return-nil-on-no-ace-mode 2014-12-07 14:45:27 +02:00
Jorge Bucaran
6d190d7d7c Add Fish. (Fix* ace_mode: none) 2014-12-07 16:24:16 +09:00
Jorge Bucaran
b8a2bd595a Add Fish. (Update) 2014-12-07 15:57:46 +09:00
Paul Chaignon
8b7d5546f7 Merge branch 'master' into newlisp 2014-12-06 20:04:18 -05:00
Arfon Smith
299a9c7bc9 Merge pull request #1835 from tenbits/master
MaskLang: Use proper tm scope
2014-12-06 17:14:06 -06:00
Arfon Smith
37f8d5b5e1 Merge pull request #1834 from karel-brinda/master
Python syntax highlighting for Snakemake files
2014-12-06 17:11:51 -06:00
Arfon Smith
2a6a59c047 Merge pull request #1842 from pchaigno/ts
Add .ts as a XML extension for Qt translation files
2014-12-06 17:06:09 -06:00
Paul Chaignon
583392d179 Heuristic for .ts (TypeScript, XML) 2014-12-06 16:31:14 -05:00
Paul Chaignon
1488796779 .ts as a XML extension for Qt translation files 2014-12-06 15:41:13 -05:00
Paul Chaignon
7458a2f9ff Heuristic for .bb (BitBake, BlitzBasic) 2014-12-06 15:26:30 -05:00
Garen Torikian
348dab4b9f Update test to account for using text 2014-12-06 11:59:31 +02:00
Paul Chaignon
5c824e0771 Ace mode and grammar to none for BitBake after merge with master 2014-12-05 21:20:55 -05:00
Paul Chaignon
b9c88a758c Merge branch 'master' into bitbake 2014-12-05 19:35:48 -05:00
Paul Chaignon
a51d637e58 Error messages for tests on Generated 2014-12-05 17:53:19 -05:00
Karel Brinda
d002dfa70c Snakemake => Snakefile (Snakemake ... program, Snakefile ... file) 2014-12-05 23:46:37 +01:00
Karel Brinda
d118017d27 Correction of alphabet sorting of filenames 2014-12-05 23:36:25 +01:00
Alex Kit
d10d328eb1 MaskLang: Use proper tm scope 2014-12-05 23:13:01 +01:00
Karel Brinda
e472d7b8b1 Python syntax highlighting for Snakemake files 2014-12-05 20:00:52 +01:00
Brandon Keepers
a54d6f3a8a Merge pull request #1779 from larsbrinkhoff/fr
Disambiguate .fr between Frege, Forth, and plain text files
2014-12-05 08:18:24 -08:00
Paul Chaignon
67ccb24b41 Require test helper in generated test 2014-12-05 10:29:19 -05:00
Paul Chaignon
42ff3f58d9 Tests for Generated.generated? optimization 2014-12-05 11:38:03 -05:00
Garen Torikian
ad778571a2 This reject is no longer necessary 2014-12-05 16:57:55 +02:00
Garen Torikian
bb12b86445 Set missing ace_mode values to text
This makes it much easier to deal with when iterating over all the
languages, since `text` is a valid, non-highlighting lexer.
2014-12-05 16:56:55 +02:00
Garen Torikian
ab61b06c34 Reject Ace modes that are lacking a mode 2014-12-05 16:25:14 +02:00
Lars Brinkhoff
de6b2f3307 Add 'text' language with samples, and heuristics for .fr. 2014-12-05 12:19:36 +01:00
Lars Brinkhoff
5fd56c75d5 Add Forth extension .fr; and a sample. 2014-12-05 11:52:00 +01:00
Paul Chaignon
6aa70a3e93 Reorganize the methods called in generated? to only load the data in last resort 2014-12-05 01:22:38 -05:00
Paul Chaignon
93186947c2 Move binaries and text files from samples folder to fixtures 2014-12-04 23:48:05 -05:00
Paul Chaignon
77444284e3 Data folder in fixtures for files with no language 2014-12-04 19:14:44 -05:00
Paul Chaignon
6950b028df Ace mode for SaltStack 2014-12-04 15:06:35 -05:00
Paul Chaignon
565767ef42 Merge branch 'master' into saltstack-states 2014-12-04 15:05:52 -05:00
Garen Torikian
a1f26d64d5 Merge pull request #1762 from github/add-missing-ace-modes-for-popular-languages
Add missing `ace_mode` values wherever necessary
2014-12-04 21:46:58 +02:00
Paul Chaignon
be30e1c658 Grammar for .sls SaltStack files 2014-12-04 14:42:24 -05:00
Garen Torikian
3aec4dd2ea Adjust to ignore generated 2014-12-04 21:27:07 +02:00
Paul Chaignon
ed34caa565 Merge branch 'master' into saltstack-states 2014-12-04 14:14:05 -05:00
Garen Torikian
81b8c57bae Add Loomscript exclusion 2014-12-04 21:10:28 +02:00
Garen Torikian
0780b7239a Merge branch 'master' into add-missing-ace-modes-for-popular-languages 2014-12-04 21:09:46 +02:00
Arfon Smith
1d626f7378 Merge pull request #1821 from github/cut-release-v4.2.3
v4.2.3
2014-12-03 15:09:42 -06:00
Arfon Smith
ff3438b810 v4.2.3 2014-12-03 13:52:45 -06:00
Arfon Smith
1762c2cefd Merge pull request #1816 from github/FS-samples
Adding more F# .fs samples. Fixes #1814
2014-12-03 13:47:18 -06:00
Arfon Smith
7aaf99c9b1 Merge branch 'FS-samples' of github.com:github/linguist into FS-samples 2014-12-03 13:09:00 -06:00
Arfon Smith
07cd9aa994 Merge branch 'master' into FS-samples 2014-12-03 13:08:41 -06:00
Arfon Smith
6ae4aa50e2 Merge pull request #1817 from pchaigno/fix-fs-heuristic
Fix .fs heuristic
2014-12-03 13:08:08 -06:00
Brandon Keepers
22fbcc244b Merge pull request #1820 from github/cut-release-v4.2.2
v4.2.2
2014-12-03 10:55:09 -08:00
Garen Torikian
1a3177409c Merge master 2014-12-03 20:15:55 +02:00
Garen Torikian
de4b538d82 Update comment at the top of the file 2014-12-03 20:14:20 +02:00
Brandon Keepers
70b1ec97db Clean before running janky build 2014-12-03 10:07:59 -08:00
Brandon Keepers
a97e328484 v4.2.2 2014-12-03 09:58:08 -08:00
Brandon Keepers
e446b86b90 Merge pull request #1813 from github/invalid-shebang
Fix detection for invalid shebang
2014-12-03 09:48:48 -08:00
Arfon Smith
901e8da911 Merge pull request #1818 from github/remove-scss-from-sass
SCSS isnt SASS
2014-12-03 10:13:32 -06:00
Arfon Smith
e9036d675e SCSS isnt SASS 2014-12-03 10:12:58 -06:00
Paul Chaignon
351e348ac0 New F# sample to test fix for .fs heuristics 2014-12-03 10:07:54 -05:00
Paul Chaignon
feea9bfd30 Fix heuristic for .fs 2014-12-03 09:48:54 -05:00
Arfon Smith
f1282b857d Better output for failing test 2014-12-03 08:46:45 -06:00
Arfon Smith
70e0ce1d73 Adding more F# .fs samples. Fixes #1814 2014-12-03 08:36:58 -06:00
Brandon Keepers
a5673e7fb6 Fix detection for invalid shebang 2014-12-02 21:03:39 -06:00
Arfon Smith
d06529fd14 Merge pull request #1812 from github/cut-release-v4.2.1
Bumping linguist version
2014-12-02 20:30:30 -06:00
Arfon Smith
a02f19f5a3 Bumping linguist version 2014-12-02 20:06:36 -06:00
Arfon Smith
a9a62fff15 Merge pull request #1809 from pchaigno/fix-matches-heuristics
Fix error when matching languages against heuristics
2014-12-02 20:05:22 -06:00
Paul Chaignon
7625c92307 Remove .module extension for PHP 2014-12-02 20:37:09 -05:00
Paul Chaignon
7dd318ca76 Use namespace.js for the heuristic test with no match 2014-12-02 20:36:18 -05:00
Paul Chaignon
e5bc2845cd Fix for fixture tests: fixture files were not tested at all 2014-12-02 20:26:15 -05:00
Paul Chaignon
4ddd8d9d2b Unit test for fix #1809 on heuristics 2014-12-02 20:06:12 -05:00
Paul Chaignon
37ffdb9020 Fix error when matching languages against heuristics: if no language, no heuristic rule should be used 2014-12-02 16:41:39 -05:00
Arfon Smith
39037d5bfb Merge pull request #1803 from github/cut-release-v4.2.0
Bumping to v4.2.0
2014-12-02 12:36:05 -06:00
Arfon Smith
31d882b07e Merge branch 'master' into cut-release-v4.2.0
Conflicts:
	grammars.yml
2014-12-02 10:57:53 -06:00
Arfon Smith
fd9275b213 Merge pull request #1702 from ellemenno/loomscript-support
add language declaration and samples for LoomScript
2014-12-02 10:54:36 -06:00
Arfon Smith
cfa63cff35 Merge pull request #900 from hoelzro/master
Update Perl 6 samples
2014-12-02 10:52:45 -06:00
Arfon Smith
5e6fd11cc2 Updating Oz tmbundle 2014-12-01 15:08:22 -06:00
Arfon Smith
62a8b52df4 Bumping to v4.2.0 2014-12-01 14:19:08 -06:00
Adam Roben
783670095c Merge pull request #1802 from wmertens/master
Add grammar for Nix
2014-12-01 13:05:24 -05:00
Wout Mertens
23cfa86f93 Add grammar for Nix 2014-12-01 18:50:56 +01:00
Garen Torikian
dce00d01d9 Add missing ace_mode values 2014-12-01 15:54:33 +02:00
Garen Torikian
768ec76ff0 Merge master 2014-12-01 15:52:37 +02:00
ellemenno
211cb9567a refactor heuristic tests to use new helper 2014-12-01 01:37:55 -05:00
ellemenno
1e68a45515 add test of ls disambiguation 2014-12-01 01:30:14 -05:00
ellemenno
72c00f869c add textmate scope for loomscript 2014-12-01 01:30:14 -05:00
ellemenno
c76137efc0 improve regex for loomscript 2014-12-01 01:30:13 -05:00
ellemenno
88f196e4d4 add a heuristic to disambiguate LiveScript from LoomScript
Keying off of `package {`, since LoomScript code must be enclosed in a
package definition, whereas that would be invalid LiveScript
2014-12-01 01:28:33 -05:00
ellemenno
4fe5980065 add language declaration and samples for LoomScript
LoomScript is the scripting language for the Loom SDK.
It has an ActionScript3-like syntax with added C#-esque capabilities.

Loom SDK: https://github.com/LoomSDK/LoomSDK
2014-12-01 01:03:03 -05:00
Rob Hoelz
7c7b1fb9c4 Reorder extensions for Perl 6 2014-11-30 22:35:52 -06:00
Rob Hoelz
ed3d38cf05 Create Perl6 heuristic 2014-11-30 22:35:52 -06:00
Rob Hoelz
837e9a6325 Add a bunch of Perl 6 sample files 2014-11-30 22:28:06 -06:00
Rob Hoelz
1364e9be51 Add .t as a valid Perl/Perl6 file extension 2014-11-30 22:28:06 -06:00
Arfon Smith
2fbfaf448d Merge pull request #1800 from github/isabelle-grammar
Isabelle grammar
2014-11-30 21:58:08 -06:00
Arfon Smith
bf82caccfc Merge branch 'master' into isabelle-grammar
Conflicts:
	grammars.yml
2014-11-30 21:53:02 -06:00
Arfon Smith
325dbc8e16 Merge pull request #1698 from sebgod/add-mercury-interpreter
languages.yml: added an interpreter entry to Mercury section
2014-11-30 21:28:04 -06:00
Arfon Smith
bd2fb0af51 Merge pull request #1790 from pchaigno/gradle
Support for gradle files
2014-11-30 21:24:30 -06:00
Arfon Smith
3c904dff61 Merge pull request #1798 from github/google-apps
Google apps
2014-11-30 21:16:50 -06:00
Arfon Smith
9b22b2973f Merge branch 'master' into google-apps
Conflicts:
	lib/linguist/heuristics.rb
	lib/linguist/samples.json
2014-11-30 21:11:59 -06:00
Arfon Smith
025bb35ac7 Merge pull request #1673 from blakeembrey/support-raml
Add spport for RAML language
2014-11-30 21:05:10 -06:00
Arfon Smith
7fb5d0cadd Merge pull request #1782 from anpar/master
Add Oz to recognized languages
2014-11-30 20:57:55 -06:00
Arfon Smith
8157c6f56b Merge pull request #1796 from github/cool
Cool
2014-11-30 20:49:26 -06:00
Arfon Smith
0154c21c3d Adding Cool grammar 2014-11-30 20:45:24 -06:00
Arfon Smith
8c841903a5 Merge branch 'master' into cs-smalltalk
Conflicts:
	lib/linguist/languages.yml
	lib/linguist/samples.json
2014-11-30 15:35:16 -06:00
Arfon Smith
648596dbb2 Be explicit about tm_scope 2014-11-30 15:24:33 -06:00
Arfon Smith
212c74d8a3 Merge branch 'master' into cool
Conflicts:
	lib/linguist/heuristics.rb
	lib/linguist/languages.yml
	lib/linguist/samples.json
2014-11-30 15:23:09 -06:00
Antoine Paris
4495e15fa7 Misspelling correction 2014-11-30 22:07:55 +01:00
Antoine Paris
da96e11b37 Add grammar for Oz 2014-11-30 22:01:39 +01:00
Antoine Paris
b7a9843770 Corrections by @pchaigno 2014-11-30 21:18:23 +01:00
Arfon Smith
55432774c7 Merge pull request #1795 from github/mercury-vendor
Removing Mercury directory from vendor.yml
2014-11-30 08:00:36 -06:00
Arfon Smith
ca76802ee4 Removing Mercury directory from vendor.yml 2014-11-30 07:55:55 -06:00
Gerwin Klein
cec54837bc add language grammar for Isabelle theorem prover 2014-11-30 17:17:13 +11:00
Arfon Smith
e0c35b0665 Merge pull request #1706 from pchaigno/mm-xml
Add .mm as an XML extension with heuristic rule
2014-11-29 23:07:58 -06:00
Brandon Keepers
865980b8f7 Merge pull request #1791 from pchaigno/remove-old-heuristic
Remove old test forgotten in #1788
2014-11-29 12:32:28 -06:00
Paul Chaignon
9367a4797f Remove old test forgotten in #1788 2014-11-28 23:14:17 -05:00
Paul Chaignon
4ed58c743d Support for gradle files 2014-11-28 23:00:35 -05:00
Arfon Smith
cfd95360cb Merge pull request #1627 from github/1036-local
Disambiguate C, C++, Objective-C
2014-11-28 18:05:16 -06:00
Brandon Keepers
22144e79d3 Merge pull request #1787 from github/move-shebang
Move shebang (updated)
2014-11-28 18:02:04 -06:00
Brandon Keepers
3acbf06beb Merge pull request #1788 from github/refactor-heuristics
Refactor heuristics (updated)
2014-11-28 17:59:43 -06:00
Brandon Keepers
7b41346db8 Merge branch 'refactor-heuristics' into 1036-local
* refactor-heuristics: (43 commits)
  update docs
  Clean up heuristic logic
  Allow disambiguate to return an Array
  Rename .create to .disambiguate
  docs
  Remove inactive heuristics
  Refactor heuristics
  Not going back
  docs
  Move call method into existing Classifier class
  Try strategies until one language is returned
  Remove unneded empty blob check
  Add F# and GLSL samples.  Add Forth and GLSL extension .fs. Add heuristic to disambiguate between F#, Forth, and GLSL.
  byebug requires ruby 2.0
  Remove test for removed extension
  Fix typo in test
  add rake interpreter
  add python3 interpreter
  Remove old wrong_shebang.rb sample
  Add byebug
  ...

Conflicts:
	lib/linguist/heuristics.rb
	test/test_heuristics.rb
2014-11-28 17:58:00 -06:00
Brandon Keepers
878b321b89 Merge remote-tracking branch 'origin/master' into move-shebang
* origin/master:
  Tweak docs
2014-11-28 17:41:10 -06:00
Brandon Keepers
a903123cb8 Merge pull request #1663 from github/strategies
Refactor detection into strategies
2014-11-28 17:40:12 -06:00
Brandon Keepers
577fb95384 Tweak docs 2014-11-28 17:36:14 -06:00
Brandon Keepers
770a1d4553 update docs 2014-11-28 17:07:15 -06:00
Brandon Keepers
c038b51941 Clean up heuristic logic 2014-11-28 17:03:01 -06:00
Brandon Keepers
4bebcef6ef Allow disambiguate to return an Array 2014-11-28 16:55:00 -06:00
Jorge Bucaran
d4888098e5 Add source.fish scope reference. 2014-11-29 07:39:19 +09:00
Jorge Bucaran
a349daeaeb Add fish tmBundle source. 2014-11-29 07:38:00 +09:00
Brandon Keepers
b8685103d0 Rename .create to .disambiguate 2014-11-28 14:41:52 -06:00
Brandon Keepers
26d789612b docs 2014-11-28 14:40:02 -06:00
Garen Torikian
7a57a0b594 What is this, Lisp? 2014-11-28 12:35:42 -08:00
Garen Torikian
66eabd8bdc Prefer Yajl.load 2014-11-28 12:34:02 -08:00
Garen Torikian
be82b55408 Simplify rescue catching 2014-11-28 12:33:43 -08:00
Garen Torikian
526ca1761a This require is no longer used 2014-11-28 12:33:37 -08:00
Brandon Keepers
10de952ed6 Remove Linguist.interpreter_from_shebang 2014-11-28 14:14:40 -06:00
Brandon Keepers
2517650ecb Fix shebang without path 2014-11-28 14:14:10 -06:00
Brandon Keepers
47b739527a Treat lines as enumerator and not array 2014-11-28 13:55:55 -06:00
Garen Torikian
8655d966ad Make corrections from a bade merge resolution 2014-11-28 11:50:46 -08:00
Garen Torikian
3fb4973aab Add missing ace_modes (introduced from master) 2014-11-28 11:48:39 -08:00
Garen Torikian
1d4149168d Add Rake task to fetch ace_modes, and skip test if there's no internet 2014-11-28 11:48:26 -08:00
Garen Torikian
26ab33754f Merge master 2014-11-28 11:04:53 -08:00
Brandon Keepers
88f08803ee require shebang when building samples 2014-11-28 12:34:41 -06:00
Brandon Keepers
c05717d15c docs 2014-11-28 12:27:48 -06:00
Brandon Keepers
bc66f558b9 Remove inactive heuristics
We can add these back when we’re ready to enable them.
2014-11-28 12:17:52 -06:00
Antoine Paris
71e1bd9af2 Misspelling correction 2014-11-28 17:42:54 +01:00
Antoine Paris
57b0739219 Add some examples for Oz 2014-11-28 17:40:49 +01:00
Antoine Paris
d60241cc86 Add grammar for Oz 2014-11-28 17:28:22 +01:00
Antoine Paris
d725e8e385 Add Oz to languages.yml 2014-11-28 17:16:32 +01:00
Brandon Keepers
034cb25099 Refactor heuristics 2014-11-28 09:43:59 -06:00
Brandon Keepers
fbc0947420 Not going back 2014-11-28 08:14:30 -06:00
Brandon Keepers
9020d7c044 Deprecate find_by_shebang
This class doesn’t need to know about shebangs.
2014-11-27 13:18:51 -05:00
Brandon Keepers
ffe2ccf1f6 Don't bother creating an instance 2014-11-27 13:17:28 -05:00
Brandon Keepers
434ab9f2c0 Add tests for shebangs 2014-11-27 13:09:05 -05:00
Brandon Keepers
cd3defda42 Simplify shebang detection 2014-11-27 12:44:55 -05:00
Brandon Keepers
fd85f7f112 consolidate shebang logic 2014-11-27 12:18:23 -05:00
Brandon Keepers
e42ccf0d82 docs 2014-11-27 11:40:48 -05:00
Brandon Keepers
bf4baff363 Move call method into existing Classifier class 2014-11-27 11:29:38 -05:00
Brandon Keepers
c1a9737313 Try strategies until one language is returned 2014-11-27 11:12:47 -05:00
Brandon Keepers
a4081498f8 Remove unneded empty blob check 2014-11-27 10:55:03 -05:00
Brandon Keepers
9efd923382 Merge remote-tracking branch 'origin/master' into strategies
* origin/master: (165 commits)
  Add F# and GLSL samples.  Add Forth and GLSL extension .fs. Add heuristic to disambiguate between F#, Forth, and GLSL.
  byebug requires ruby 2.0
  Remove test for removed extension
  Fix typo in test
  add rake interpreter
  add python3 interpreter
  Remove old wrong_shebang.rb sample
  Add byebug
  Link to Lightshow in CONTRIBUTING.md
  Switch to a better F# grammar
  Bump Rugged again
  Checkout the master for testing
  Rugged 0.22.0b3
  Reordering
  Bump version to 4.0.3
  Add some docs for tm_scope
  Change NONE to none
  Checking other case for Chart.jS
  Test that all languages have grammars
  Fix RHTML's tm_scope
  ...

Conflicts:
	lib/linguist/language.rb
2014-11-27 10:52:44 -05:00
Arfon Smith
b16149d641 Merge pull request #1758 from larsbrinkhoff/fsharp-glsl
Disambiguate .fs between F#, Forth, and GLSL
2014-11-27 07:41:14 -06:00
Lars Brinkhoff
2d940e72c2 Add F# and GLSL samples. Add Forth and GLSL extension .fs.
Add heuristic to disambiguate between F#, Forth, and GLSL.
2014-11-27 06:56:26 +01:00
Brandon Keepers
9f103abfb5 Merge pull request #1750 from github/interpreters-in-samples
Fix for interpreters from samples
2014-11-26 16:51:08 -05:00
Brandon Keepers
689a209ed9 Merge remote-tracking branch 'origin/master' into interpreters-in-samples
* origin/master:
  byebug requires ruby 2.0
  Remove test for removed extension
  Merge branch 'master' into 1233-local
  Removing pry runtime dependency
  Moving to fixtures
  Language detection test for non-sample files
  Refactoring of Language.detect
  Try shebang detection if the extension is unknown
  Change unknown extension of PHP sample file
2014-11-26 16:25:15 -05:00
Brandon Keepers
d91a451fc7 Merge pull request #1776 from github/fix-failures
Fix failure from #1731
2014-11-26 16:24:25 -05:00
Brandon Keepers
1ae4672230 byebug requires ruby 2.0 2014-11-26 16:12:43 -05:00
Brandon Keepers
3edf5fd770 Remove test for removed extension
This existed when the test was written, but was removed in https://github.com/github/linguist/pull/1734 and the test got lost in a merge somewhere.
2014-11-26 15:59:16 -05:00
Arfon Smith
412af86cb8 Merge pull request #1538 from github/1233-local
Detection based on the shebang (updated)
2014-11-26 14:47:12 -06:00
Brandon Keepers
5b41ab4774 Fix typo in test 2014-11-26 15:40:51 -05:00
Brandon Keepers
06c0cb916b add rake interpreter 2014-11-26 15:40:40 -05:00
Brandon Keepers
b3a49ce627 add python3 interpreter 2014-11-26 15:40:33 -05:00
Brandon Keepers
0651568bfb Remove old wrong_shebang.rb sample
This was added in a69118bd17, but that test has since been removed.
2014-11-26 15:34:03 -05:00
Brandon Keepers
ce31e23006 Merge remote-tracking branch 'origin/master' into interpreters-in-samples
* origin/master: (30 commits)
  Add byebug
  Link to Lightshow in CONTRIBUTING.md
  Switch to a better F# grammar
  Bump Rugged again
  Checkout the master for testing
  Rugged 0.22.0b3
  Reordering
  Bump version to 4.0.3
  Add some docs for tm_scope
  Change NONE to none
  Checking other case for Chart.jS
  Test that all languages have grammars
  Fix RHTML's tm_scope
  Chart JS is vendored
  Switch to a better grammar for Bro
  reorder again…
  put cjsx at the top
  Use a SQF grammar for SQF files
  move cjsx before iced
  move cjsx before iced
  ...

Conflicts:
	lib/linguist/languages.yml
2014-11-26 15:17:08 -05:00
Brandon Keepers
7ccd8caf71 Merge pull request #1774 from github/byebug
Add byebug
2014-11-26 15:16:06 -05:00
Brandon Keepers
598a7028ea Add byebug 2014-11-26 15:12:55 -05:00
Brandon Keepers
4ed1efe9ce Merge pull request #1741 from github/test-helper
Add test helper to make test env consistent
2014-11-26 15:10:24 -05:00
Brandon Keepers
6a4bf3fa65 Merge pull request #1731 from github/multiple-ext-segments
Support for multiple file extension segments
2014-11-26 15:09:15 -05:00
Brandon Keepers
5b2b3a2b53 Merge remote-tracking branch 'origin/master' into test-helper
* origin/master: (31 commits)
  Link to Lightshow in CONTRIBUTING.md
  Switch to a better F# grammar
  Bump Rugged again
  Checkout the master for testing
  Rugged 0.22.0b3
  Reordering
  Bump version to 4.0.3
  Add some docs for tm_scope
  Change NONE to none
  Checking other case for Chart.jS
  Test that all languages have grammars
  Fix RHTML's tm_scope
  Chart JS is vendored
  Switch to a better grammar for Bro
  reorder again…
  put cjsx at the top
  Use a SQF grammar for SQF files
  move cjsx before iced
  move cjsx before iced
  change component name
  ...

Conflicts:
	test/test_language.rb
2014-11-26 15:07:27 -05:00
Adam Roben
596cd9368f Merge pull request #1773 from github/introduce-lightshow
Link to Lightshow in CONTRIBUTING.md
2014-11-26 11:44:05 -05:00
Adam Roben
f8d50faedb Link to Lightshow in CONTRIBUTING.md
This is a tool for testing grammars with GitHub's syntax highlighter.
2014-11-26 11:21:05 -05:00
Adam Roben
ccc9c197ae Merge pull request #1771 from github/better-fsharp-grammar
Switch to a better F# grammar
2014-11-26 09:35:55 -05:00
Adam Roben
ed2dcc35e8 Switch to a better F# grammar
This fixes many bugs with F# highlighting, and the grammar is being
actively developed and maintained by the fsharp organization on GitHub.
2014-11-26 08:56:02 -05:00
Arfon Smith
208a3ff480 Merge branch 'master' into 1233-local
Conflicts:
	lib/linguist/language.rb
2014-11-25 17:04:43 -06:00
Paul Chaignon
6739a1471b Remove samples.json following merge with master 2014-11-25 15:46:51 -05:00
Paul Chaignon
230d91ecd8 Merge branch 'master' into saltstack-states 2014-11-25 15:41:25 -05:00
Arfon Smith
8de2cd15ed Merge branch 'master' into 1036-local
Conflicts:
	lib/linguist/heuristics.rb
	lib/linguist/languages.yml
	test/test_heuristics.rb
2014-11-25 13:06:11 -06:00
Garen Torikian
4603f3b2e7 Update languages.yml to always include ace_mode 2014-11-24 11:38:51 -08:00
Garen Torikian
9d6b8b4715 Add test for catching missing ace_mode values 2014-11-24 10:58:13 -08:00
Brandon Keepers
7cbc4bc144 Merge pull request #1751 from roodboi/master
add .cjsx extension for Facebook’s JSX in coffescript
2014-11-24 11:30:04 -05:00
Vicent Marti
d239e71826 Merge pull request #1765 from github/vmg/rugged-22b3
Rugged 0.22.0b3
2014-11-24 13:37:09 +01:00
Vicent Marti
ecaa2a41c9 Bump Rugged again 2014-11-24 13:32:37 +01:00
Vicent Marti
fc71805489 Checkout the master for testing 2014-11-24 13:25:49 +01:00
Vicent Marti
74d94781cb Rugged 0.22.0b3 2014-11-24 13:05:42 +01:00
Garen Torikian
897c2c5ab6 Add missing ace_mode values wherever necessary 2014-11-23 21:16:21 -08:00
Arfon Smith
b556425037 Reordering 2014-11-21 13:10:45 -06:00
Arfon Smith
6131d17c02 Merge pull request #1748 from mrego/xht-extension
Add support for .xht extension which is used in some XHTML files
2014-11-21 12:48:58 -06:00
Adam Roben
875b3157bf Merge pull request #1757 from github/cut-release-v4.0.3
Bump version to 4.0.3
2014-11-21 12:06:38 -05:00
Adam Roben
4ce9048f8d Bump version to 4.0.3 2014-11-21 11:56:17 -05:00
Adam Roben
04f1b1df48 Merge pull request #1756 from github/test-for-grammars
Test that all languages have grammars
2014-11-21 11:54:46 -05:00
Adam Roben
f9c36345c3 Add some docs for tm_scope 2014-11-21 11:53:52 -05:00
Adam Roben
ec3967d080 Change NONE to none
NONE is a little shouty.
2014-11-21 11:52:29 -05:00
Arfon Smith
05a88b5b7e Merge pull request #1754 from github/chart-js
Chart js
2014-11-21 09:30:20 -06:00
Arfon Smith
b6b2cf04a7 Checking other case for Chart.jS 2014-11-21 09:29:28 -06:00
Adam Roben
49247e9ec2 Test that all languages have grammars
This will make CI fail if someone adds a new language but neglects to
add a new grammar for it. This should make it easier for people to
review PRs, as CI will help them to make sure a new grammar gets added.

However, we currently support some languages that have no grammars, and
we may support more in the future. So you can explicitly mark the
language as having no grammar by setting `tm_scope: NONE` in
languages.yml.
2014-11-21 09:48:52 -05:00
Adam Roben
6629b75aa6 Merge pull request #1755 from github/fix-rhtml-scope
Fix RHTML's tm_scope
2014-11-21 09:31:07 -05:00
Adam Roben
e702b453ec Fix RHTML's tm_scope
I missed this back in 9595e2ba7e.
2014-11-21 09:29:06 -05:00
Arfon Smith
38190d92fc Chart JS is vendored 2014-11-21 08:24:33 -06:00
Adam Roben
109ca5735b Merge pull request #1753 from github/better-bro-grammar
Switch to a better grammar for Bro
2014-11-21 09:23:28 -05:00
Adam Roben
4dde499f51 Switch to a better grammar for Bro
This grammar seems to be replacing the other ones out there and is
maintained by the Bro organization.
2014-11-21 09:17:19 -05:00
Vicent Marti
5fd18a215e Merge pull request #1752 from github/sqf-grammar
Use a SQF grammar for SQF files
2014-11-21 11:31:50 +01:00
Dimitri Kennedy
b283548c0f reorder again… 2014-11-20 18:36:08 -05:00
Dimitri Kennedy
2352ce77c9 put cjsx at the top 2014-11-20 17:38:38 -05:00
Adam Roben
2054afc741 Use a SQF grammar for SQF files
This produces better highlighting than using the C++ grammar.

The grammar is licensed under the Apache 2.0 license.
2014-11-20 17:22:55 -05:00
Dimitri Kennedy
9d3b9964b5 move cjsx before iced 2014-11-20 17:08:21 -05:00
Dimitri Kennedy
79c1d21a0f move cjsx before iced 2014-11-20 17:08:10 -05:00
Dimitri Kennedy
1d69228872 change component name 2014-11-20 16:49:48 -05:00
Dimitri Kennedy
f5953a09da add example cjsx file 2014-11-20 16:48:22 -05:00
Dimitri Kennedy
a17f6c8ae1 add .cjsx extension for Facebook’s JSX in coffescript 2014-11-20 14:56:09 -05:00
Brandon Keepers
9823af0cb4 Fix for shebang with relative bin
`#!/usr/bin/env bin/linguist` is a valid shebang
2014-11-20 12:50:35 -05:00
Brandon Keepers
45384bd498 More missing interpreters 2014-11-20 12:29:16 -05:00
Brandon Keepers
56bfde998b Only strip minor version off of interpreters
This used to turn `python2.4` into `python`, which causes trouble with
`perl6`, which is a different language definition.
2014-11-20 12:28:30 -05:00
Brandon Keepers
870feb8592 Add missing interpreters 2014-11-20 11:27:54 -05:00
Brandon Keepers
2670e2b035 Test that interpreters are defined in languages.yml 2014-11-20 11:21:52 -05:00
Brandon Keepers
eccea65641 Fix for interpreters not getting add to samples.json 2014-11-20 11:14:05 -05:00
Brandon Keepers
231ad86176 sync cached gems 2014-11-20 08:51:56 -05:00
Florian Kaiser
9658b02502 add Chart.js as vendor
http://www.chartjs.org
2014-11-20 10:02:45 +01:00
Manuel Rego Casasnovas
30c6b6e5a1 Add XHTML example file 2014-11-20 00:30:21 +01:00
Manuel Rego Casasnovas
b44e58dd7f Add support for .xht extension which is used in some XHTML files 2014-11-19 23:08:51 +01:00
Brandon Keepers
245a1a92cf Merge remote-tracking branch 'origin/master' into test-helper
* origin/master:
  Add Gemfile.lock sample
  Remove deprecated method
  #all_extensions already includes primary extension
  typo
  remove unused assertion
  Symlink ant.xml to build.xml
  Avoid shadowing variable name
  Update comment
  Make missing sample failure message similar
  Remove blank extensions property
  Fix sample tests
  Add Forth extensions .f and .for; add heuristics for Forth and FORTRAN.
  Add FORTRAN and Forth samples.
  Extensions aren't actually required
  Fix errors from pedantic test
  Make pedantic test actually pedantic
  Removing extensions when they should be filenames
  Adding sample pom.xml files
  Link to contributing docs
  require samples if filename matches multiple languages

Conflicts:
	test/test_pedantic.rb
2014-11-18 16:48:26 -05:00
Brandon Keepers
aa7ab2065b Add test helper to make test env consistent 2014-11-18 16:46:09 -05:00
Paul Chaignon
1356d4e579 Remove heuristic rules for .mm files 2014-11-17 19:20:45 -05:00
Brandon Keepers
6c106b88c0 Avoid using singular #extension 2014-11-17 15:47:21 -05:00
Brandon Keepers
c46667581d Use the first extension with languages defined 2014-11-17 15:15:39 -05:00
Brandon Keepers
3ca872cea8 Support for multiple file extension segments 2014-11-17 14:54:22 -05:00
Paul Chaignon
9c64f72f35 Add .mm as an XML extension with heuristic rule 2014-11-12 19:38:54 -05:00
Sebastian Godelet
95777055d1 languages.yml: added an interpreter entry to Mercury section 2014-11-11 23:28:07 +08:00
Blake Embrey
42e9131b4f Add RAML support 2014-11-06 11:47:00 -06:00
Brandon Keepers
74fa4b9b75 docs 2014-11-03 08:54:11 -05:00
Brandon Keepers
815337299a Extract empty blob strategy 2014-11-03 08:21:46 -05:00
Brandon Keepers
fd32938cd8 Extract strategies for detecting the language 2014-11-03 08:17:02 -05:00
Brandon Keepers
8d7b4f81b4 Extract filename strategy 2014-11-02 22:15:52 -05:00
Arfon Smith
2bc546eadf Merge branch 'master' into 1233-local
Conflicts:
	lib/linguist/language.rb
2014-11-01 10:05:45 -05:00
Arfon Smith
9e50e188a8 Merge branch 'master' into 1233-local
Conflicts:
	lib/linguist/language.rb
	lib/linguist/languages.yml
	lib/linguist/samples.json
2014-11-01 10:04:22 -05:00
Arfon Smith
0c05a6c3ac Merge branch 'master' into 1036-local 2014-10-29 20:06:40 -05:00
Arfon Smith
d4d6ef314d Merge branch 'master' into 1036-local 2014-10-28 19:14:43 -05:00
Arfon Smith
322b21e0d0 Updating regexes 2014-10-28 19:14:32 -05:00
Arfon Smith
32de8a4d19 Only exact matches 2014-10-23 13:59:36 +01:00
Arfon Smith
cf9998f3e4 Merge branch 'master' into 1036-local 2014-10-23 12:16:51 +01:00
Arfon Smith
89320b1ca4 Merge branch 'master' into 1036-local
Conflicts:
	lib/linguist/heuristics.rb
	lib/linguist/samples.json
2014-10-23 12:05:18 +01:00
Paul Chaignon
f3d654a965 Merge branch 'master' into bitbake 2014-09-25 10:38:47 -04:00
Paul Chaignon
2e6aae0256 Merge branch 'master' into saltstack-states 2014-09-25 10:26:57 -04:00
Arfon Smith
12b78c5357 Removing pry runtime dependency 2014-09-18 13:22:02 -05:00
Arfon Smith
e70cd33323 Moving to fixtures 2014-09-17 08:37:00 -05:00
Arfon Smith
302af86363 Merge branch 'master' into 1233-local
Conflicts:
	lib/linguist/language.rb
	lib/linguist/samples.json
2014-09-16 16:36:10 -05:00
Rachel Mant
44eebde394 Added @property and @end as an Obj-C heuristic for issue #1344 2014-09-03 18:33:24 +01:00
DX-MON
498c102414 Fixed the tests that broke, but this may have re-broken a couple of repositories - I can't yet tell 2014-09-03 18:14:15 +01:00
DX-MON
79cd77454b Merge remote-tracking branch 'source/master' 2014-09-03 18:09:52 +01:00
Michael Johnson
410aace222 Adding Google Apps Script (.gs) as a JavaScript extension. 2014-08-24 17:00:37 -04:00
Damien Pollet
bde19a76cc Re-generate samples.json 2014-08-07 15:24:57 +02:00
Damien Pollet
49ebf4b303 C# samples to disambiguate from Smalltalk 2014-08-07 14:43:35 +02:00
Damien Pollet
0017310dd1 Declare .cs as Smalltalk changeset 2014-08-06 22:27:30 +02:00
dx-mon
dad4b974b7 Merge branch 'master' of https://github.com/github/linguist 2014-07-14 22:08:16 +01:00
DX-MON
f1cb16648f Added samples for .C and .H files to fix the pedantic tests for sample presense 2014-06-27 12:49:11 +01:00
DX-MON
1276f10b67 Fixed languages.yml so the pedantic test on extension ordering passes 2014-06-26 23:04:10 +01:00
DX-MON
c3da262bd0 Merge branch 'master' of https://github.com/github/linguist 2014-06-26 22:57:07 +01:00
Paul Chaignon
35355b157c Add support for .sls YAML files (SaltStack states) 2014-06-22 15:28:49 +02:00
Paul Chaignon
2143699aab Language detection test for non-sample files 2014-06-14 11:53:45 +02:00
Paul Chaignon
b1c2820299 Merge conflicts from master fixed 2014-06-13 18:50:32 +02:00
DX-MON
624fd74f83 Added C header samples from https://github.com/MiJyn/nightmare/ to fix the misclassifications as C++ that were occuring 2014-06-10 18:54:10 +01:00
DX-MON
cd878522d9 Added the GLKit GLKMatrix4 header as a C sample as this fixes 5 misclassifications - 4 as Obj-C and one as C++ 2014-06-10 18:51:29 +01:00
DX-MON
10fed43c27 Added .H and .C as C file extensions as well as them already being C++ ones. This fixes #1054 2014-06-10 11:59:11 +01:00
DX-MON
1d50adf87a Added a sample that fixes comment two on issue #1264. 2014-06-10 10:41:00 +01:00
Rachel Mant
614a61b0b0 Update heuristics.rb
Added the iostream headers and std:: to the C++ heuristics. This covers issues 1250.
2014-06-05 10:37:23 +01:00
Paul Chaignon
bd380f44cc Refactoring of Language.detect 2014-06-03 09:52:24 +02:00
Paul Chaignon
8a546d2a7a Try shebang detection if the extension is unknown 2014-06-01 20:00:49 +02:00
Paul Chaignon
1148a9746a Change unknown extension of PHP sample file 2014-06-01 19:59:57 +02:00
Trey Deitch
913cd6c309 Add support for Cool
This change includes a brief (non-sensical) sample program I wrote to
illustrate many of Cool's language constructs, as well as a simple rule
to distinguish Cool files from Common Lisp or OpenCL (it has a line that
starts with the word 'class'). Further, it includes a second example
program adapted from an example contained in the Cool distribution
(list.cl), which contains a few further language constructs and captures
the style of a Cool program.
2014-05-08 13:27:22 -07:00
Paul Chaignon
81d9c682da Support of the BitBake language 2014-05-05 11:29:00 +02:00
DX-MON
492aa12cad Updated the samples database file as recommended 2014-04-03 11:18:36 +01:00
DX-MON
e79e45a74e Removed the matches variable from find_by_heuristics without re-breaking anything 2014-04-02 22:22:22 +01:00
dx-mon
e661470bbb Merge branch 'master' of github.com:DX-MON/linguist 2014-04-02 21:41:13 +01:00
DX-MON
af30a80702 Added two new heuristics tests for the new C/C++/Obj-C heuristics 2014-04-02 21:41:02 +01:00
Rachel Mant
bab7ee4fcb Found my new heuristic was still not being used because heuristics had been switched off 2014-04-02 20:17:33 +01:00
DX-MON
6524ac3588 Fixed the C++ class matching regex that was breaking the test for C/jni_layer.h 2014-04-02 20:08:47 +01:00
DX-MON
c432cd67fc Found out that nothing was ever getting returned from the heuristic function "find_by_heuristics", and that headers matching C, Obj-C and C++ were never getting checked heuristically 2014-04-02 19:55:24 +01:00
DX-MON
5c071a2e07 More regex goodness to improve the detection of C++ vs C 2014-04-02 19:48:44 +01:00
DX-MON
cb10c53dee Fixed the failing patten for detecting C++-only headers 2014-04-02 17:57:58 +01:00
Rachel Mant
dfba2a31a5 Added the end statements for the two new if statmeents
Did not know ends were required on one-liner ifs. Fixed.
2014-04-02 13:44:17 +01:00
Rachel Mant
667f3de26b Improved the Obj-C heuristic with a Regex matching multiple unique keywords
Also improved the C++ heuristic by checking for class without an @ on the front.
2014-04-02 13:09:17 +01:00
Rachel Mant
fd585beb07 Improved the C++ heuristic for detecting based on included headers 2014-04-02 12:55:29 +01:00
374 changed files with 18232 additions and 1708 deletions

2
.gitignore vendored
View File

@@ -4,3 +4,5 @@ benchmark/
lib/linguist/samples.json
/grammars
/node_modules
test/fixtures/ace_modes.json
/vendor/gems/

536
.gitmodules vendored Normal file
View File

@@ -0,0 +1,536 @@
[submodule "vendor/grammars/go-tmbundle"]
path = vendor/grammars/go-tmbundle
url = https://github.com/AlanQuatermain/go-tmbundle
[submodule "vendor/grammars/PHP-Twig.tmbundle"]
path = vendor/grammars/PHP-Twig.tmbundle
url = https://github.com/Anomareh/PHP-Twig.tmbundle
[submodule "vendor/grammars/sublime-cirru"]
path = vendor/grammars/sublime-cirru
url = https://github.com/Cirru/sublime-cirru
[submodule "vendor/grammars/Sublime-Logos"]
path = vendor/grammars/Sublime-Logos
url = https://github.com/Cykey/Sublime-Logos
[submodule "vendor/grammars/SublimeBrainfuck"]
path = vendor/grammars/SublimeBrainfuck
url = https://github.com/Drako/SublimeBrainfuck
[submodule "vendor/grammars/awk-sublime"]
path = vendor/grammars/awk-sublime
url = https://github.com/JohnNilsson/awk-sublime
[submodule "vendor/grammars/Sublime-SQF-Language"]
path = vendor/grammars/Sublime-SQF-Language
url = https://github.com/JonBons/Sublime-SQF-Language
[submodule "vendor/grammars/SCSS.tmbundle"]
path = vendor/grammars/SCSS.tmbundle
url = https://github.com/MarioRicalde/SCSS.tmbundle
[submodule "vendor/grammars/Sublime-REBOL"]
path = vendor/grammars/Sublime-REBOL
url = https://github.com/Oldes/Sublime-REBOL
[submodule "vendor/grammars/Sublime-Inform"]
path = vendor/grammars/Sublime-Inform
url = https://github.com/PogiNate/Sublime-Inform
[submodule "vendor/grammars/autoitv3-tmbundle"]
path = vendor/grammars/autoitv3-tmbundle
url = https://github.com/Red-Nova-Technologies/autoitv3-tmbundle
[submodule "vendor/grammars/Sublime-VimL"]
path = vendor/grammars/Sublime-VimL
url = https://github.com/SalGnt/Sublime-VimL
[submodule "vendor/grammars/boo-sublime"]
path = vendor/grammars/boo-sublime
url = https://github.com/Shammah/boo-sublime
[submodule "vendor/grammars/ColdFusion"]
path = vendor/grammars/ColdFusion
url = https://github.com/SublimeText/ColdFusion
[submodule "vendor/grammars/NSIS"]
path = vendor/grammars/NSIS
url = https://github.com/SublimeText/NSIS
[submodule "vendor/grammars/NimLime"]
path = vendor/grammars/NimLime
url = https://github.com/Varriount/NimLime
[submodule "vendor/grammars/gradle.tmbundle"]
path = vendor/grammars/gradle.tmbundle
url = https://github.com/alkemist/gradle.tmbundle
[submodule "vendor/grammars/Sublime-Loom"]
path = vendor/grammars/Sublime-Loom
url = https://github.com/ambethia/Sublime-Loom
[submodule "vendor/grammars/VBDotNetSyntax"]
path = vendor/grammars/VBDotNetSyntax
url = https://github.com/angryant0007/VBDotNetSyntax
[submodule "vendor/grammars/cool-tmbundle"]
path = vendor/grammars/cool-tmbundle
url = https://github.com/anunayk/cool-tmbundle
[submodule "vendor/grammars/Docker.tmbundle"]
path = vendor/grammars/Docker.tmbundle
url = https://github.com/asbjornenge/Docker.tmbundle
[submodule "vendor/grammars/jasmin-sublime"]
path = vendor/grammars/jasmin-sublime
url = https://github.com/atmarksharp/jasmin-sublime
[submodule "vendor/grammars/language-clojure"]
path = vendor/grammars/language-clojure
url = https://github.com/atom/language-clojure
[submodule "vendor/grammars/language-coffee-script"]
path = vendor/grammars/language-coffee-script
url = https://github.com/atom/language-coffee-script
[submodule "vendor/grammars/language-csharp"]
path = vendor/grammars/language-csharp
url = https://github.com/atom/language-csharp
[submodule "vendor/grammars/language-gfm"]
path = vendor/grammars/language-gfm
url = https://github.com/atom/language-gfm
[submodule "vendor/grammars/language-javascript"]
path = vendor/grammars/language-javascript
url = https://github.com/atom/language-javascript
[submodule "vendor/grammars/language-python"]
path = vendor/grammars/language-python
url = https://github.com/atom/language-python
[submodule "vendor/grammars/language-shellscript"]
path = vendor/grammars/language-shellscript
url = https://github.com/atom/language-shellscript
[submodule "vendor/grammars/language-yaml"]
path = vendor/grammars/language-yaml
url = https://github.com/atom/language-yaml
[submodule "vendor/grammars/sublime-sourcepawn"]
path = vendor/grammars/sublime-sourcepawn
url = https://github.com/austinwagner/sublime-sourcepawn
[submodule "vendor/grammars/Sublime-Lasso"]
path = vendor/grammars/Sublime-Lasso
url = https://github.com/bfad/Sublime-Lasso
[submodule "vendor/grammars/chapel-tmbundle"]
path = vendor/grammars/chapel-tmbundle
url = https://github.com/bholt/chapel-tmbundle
[submodule "vendor/grammars/sublime-nginx"]
path = vendor/grammars/sublime-nginx
url = https://github.com/brandonwamboldt/sublime-nginx
[submodule "vendor/grammars/bro-sublime"]
path = vendor/grammars/bro-sublime
url = https://github.com/bro/bro-sublime
[submodule "vendor/grammars/sublime_man_page_support"]
path = vendor/grammars/sublime_man_page_support
url = https://github.com/carsonoid/sublime_man_page_support
[submodule "vendor/grammars/sublime-MuPAD"]
path = vendor/grammars/sublime-MuPAD
url = https://github.com/ccreutzig/sublime-MuPAD
[submodule "vendor/grammars/nesC.tmbundle"]
path = vendor/grammars/nesC.tmbundle
url = https://github.com/cdwilson/nesC.tmbundle
[submodule "vendor/grammars/racket-tmbundle"]
path = vendor/grammars/racket-tmbundle
url = https://github.com/christophevg/racket-tmbundle
[submodule "vendor/grammars/haxe-sublime-bundle"]
path = vendor/grammars/haxe-sublime-bundle
url = https://github.com/clemos/haxe-sublime-bundle
[submodule "vendor/grammars/cucumber-tmbundle"]
path = vendor/grammars/cucumber-tmbundle
url = https://github.com/cucumber/cucumber-tmbundle
[submodule "vendor/grammars/Handlebars"]
path = vendor/grammars/Handlebars
url = https://github.com/daaain/Handlebars
[submodule "vendor/grammars/powershell.tmbundle"]
path = vendor/grammars/powershell.tmbundle
url = https://github.com/davidpeckham/powershell.tmbundle
[submodule "vendor/grammars/jade-tmbundle"]
path = vendor/grammars/jade-tmbundle
url = https://github.com/davidrios/jade-tmbundle
[submodule "vendor/grammars/elixir-tmbundle"]
path = vendor/grammars/elixir-tmbundle
url = https://github.com/elixir-lang/elixir-tmbundle
[submodule "vendor/grammars/sublime-glsl"]
path = vendor/grammars/sublime-glsl
url = https://github.com/euler0/sublime-glsl
[submodule "vendor/grammars/fancy-tmbundle"]
path = vendor/grammars/fancy-tmbundle
url = https://github.com/fancy-lang/fancy-tmbundle
[submodule "vendor/grammars/fsharpbinding"]
path = vendor/grammars/fsharpbinding
url = https://github.com/fsharp/fsharpbinding
[submodule "vendor/grammars/monkey.tmbundle"]
path = vendor/grammars/monkey.tmbundle
url = https://github.com/gingerbeardman/monkey.tmbundle
[submodule "vendor/grammars/dart-sublime-bundle"]
path = vendor/grammars/dart-sublime-bundle
url = https://github.com/guillermooo/dart-sublime-bundle
[submodule "vendor/grammars/sublimetext-cuda-cpp"]
path = vendor/grammars/sublimetext-cuda-cpp
url = https://github.com/harrism/sublimetext-cuda-cpp
[submodule "vendor/grammars/pike-textmate"]
path = vendor/grammars/pike-textmate
url = https://github.com/hww3/pike-textmate
[submodule "vendor/grammars/ceylon-sublimetext"]
path = vendor/grammars/ceylon-sublimetext
url = https://github.com/jeancharles-roger/ceylon-sublimetext
[submodule "vendor/grammars/Sublime-Text-2-OpenEdge-ABL"]
path = vendor/grammars/Sublime-Text-2-OpenEdge-ABL
url = https://github.com/jfairbank/Sublime-Text-2-OpenEdge-ABL
[submodule "vendor/grammars/sublime-rust"]
path = vendor/grammars/sublime-rust
url = https://github.com/jhasse/sublime-rust
[submodule "vendor/grammars/sublime-befunge"]
path = vendor/grammars/sublime-befunge
url = https://github.com/johanasplund/sublime-befunge
[submodule "vendor/grammars/RDoc.tmbundle"]
path = vendor/grammars/RDoc.tmbundle
url = https://github.com/joshaven/RDoc.tmbundle
[submodule "vendor/grammars/Textmate-Gosu-Bundle"]
path = vendor/grammars/Textmate-Gosu-Bundle
url = https://github.com/jpcamara/Textmate-Gosu-Bundle
[submodule "vendor/grammars/jquery-tmbundle"]
path = vendor/grammars/jquery-tmbundle
url = https://github.com/kswedberg/jquery-tmbundle
[submodule "vendor/grammars/fish-tmbundle"]
path = vendor/grammars/fish-tmbundle
url = https://github.com/l15n/fish-tmbundle
[submodule "vendor/grammars/sublime-idris"]
path = vendor/grammars/sublime-idris
url = https://github.com/laughedelic/sublime-idris
[submodule "vendor/grammars/sublime-better-typescript"]
path = vendor/grammars/sublime-better-typescript
url = https://github.com/lavrton/sublime-better-typescript
[submodule "vendor/grammars/moonscript-tmbundle"]
path = vendor/grammars/moonscript-tmbundle
url = https://github.com/leafo/moonscript-tmbundle
[submodule "vendor/grammars/Isabelle.tmbundle"]
path = vendor/grammars/Isabelle.tmbundle
url = https://github.com/lsf37/Isabelle.tmbundle
[submodule "vendor/grammars/x86-assembly-textmate-bundle"]
path = vendor/grammars/x86-assembly-textmate-bundle
url = https://github.com/lunixbochs/x86-assembly-textmate-bundle
[submodule "vendor/grammars/Alloy.tmbundle"]
path = vendor/grammars/Alloy.tmbundle
url = https://github.com/macekond/Alloy.tmbundle
[submodule "vendor/grammars/opa.tmbundle"]
path = vendor/grammars/opa.tmbundle
url = https://github.com/mads379/opa.tmbundle
[submodule "vendor/grammars/scala.tmbundle"]
path = vendor/grammars/scala.tmbundle
url = https://github.com/mads379/scala.tmbundle
[submodule "vendor/grammars/mako-tmbundle"]
path = vendor/grammars/mako-tmbundle
url = https://github.com/marconi/mako-tmbundle
[submodule "vendor/grammars/gnuplot-tmbundle"]
path = vendor/grammars/gnuplot-tmbundle
url = https://github.com/mattfoster/gnuplot-tmbundle
[submodule "vendor/grammars/idl.tmbundle"]
path = vendor/grammars/idl.tmbundle
url = https://github.com/mgalloy/idl.tmbundle
[submodule "vendor/grammars/protobuf-tmbundle"]
path = vendor/grammars/protobuf-tmbundle
url = https://github.com/michaeledgar/protobuf-tmbundle
[submodule "vendor/grammars/Sublime-Coq"]
path = vendor/grammars/Sublime-Coq
url = https://github.com/mkolosick/Sublime-Coq
[submodule "vendor/grammars/Agda.tmbundle"]
path = vendor/grammars/Agda.tmbundle
url = https://github.com/mokus0/Agda.tmbundle
[submodule "vendor/grammars/Julia.tmbundle"]
path = vendor/grammars/Julia.tmbundle
url = https://github.com/nanoant/Julia.tmbundle
[submodule "vendor/grammars/assembly.tmbundle"]
path = vendor/grammars/assembly.tmbundle
url = https://github.com/nanoant/assembly.tmbundle
[submodule "vendor/grammars/ooc.tmbundle"]
path = vendor/grammars/ooc.tmbundle
url = https://github.com/nilium/ooc.tmbundle
[submodule "vendor/grammars/LiveScript.tmbundle"]
path = vendor/grammars/LiveScript.tmbundle
url = https://github.com/paulmillr/LiveScript.tmbundle
[submodule "vendor/grammars/sublime-tea"]
path = vendor/grammars/sublime-tea
url = https://github.com/pferruggiaro/sublime-tea
[submodule "vendor/grammars/puppet-textmate-bundle"]
path = vendor/grammars/puppet-textmate-bundle
url = https://github.com/puppet-textmate-bundle/puppet-textmate-bundle
[submodule "vendor/grammars/abap.tmbundle"]
path = vendor/grammars/abap.tmbundle
url = https://github.com/pvl/abap.tmbundle
[submodule "vendor/grammars/mercury-tmlanguage"]
path = vendor/grammars/mercury-tmlanguage
url = https://github.com/sebgod/mercury-tmlanguage
[submodule "vendor/grammars/mathematica-tmbundle"]
path = vendor/grammars/mathematica-tmbundle
url = https://github.com/shadanan/mathematica-tmbundle
[submodule "vendor/grammars/sublime-robot-plugin"]
path = vendor/grammars/sublime-robot-plugin
url = https://github.com/shellderp/sublime-robot-plugin
[submodule "vendor/grammars/actionscript3-tmbundle"]
path = vendor/grammars/actionscript3-tmbundle
url = https://github.com/simongregory/actionscript3-tmbundle
[submodule "vendor/grammars/Sublime-QML"]
path = vendor/grammars/Sublime-QML
url = https://github.com/skozlovf/Sublime-QML
[submodule "vendor/grammars/Slash.tmbundle"]
path = vendor/grammars/Slash.tmbundle
url = https://github.com/slash-lang/Slash.tmbundle
[submodule "vendor/grammars/factor"]
path = vendor/grammars/factor
url = https://github.com/slavapestov/factor
[submodule "vendor/grammars/ruby-slim.tmbundle"]
path = vendor/grammars/ruby-slim.tmbundle
url = https://github.com/slim-template/ruby-slim.tmbundle
[submodule "vendor/grammars/SublimeXtend"]
path = vendor/grammars/SublimeXtend
url = https://github.com/staltz/SublimeXtend
[submodule "vendor/grammars/Stata.tmbundle"]
path = vendor/grammars/Stata.tmbundle
url = https://github.com/statatmbundle/Stata.tmbundle
[submodule "vendor/grammars/Vala-TMBundle"]
path = vendor/grammars/Vala-TMBundle
url = https://github.com/technosophos/Vala-TMBundle
[submodule "vendor/grammars/ant.tmbundle"]
path = vendor/grammars/ant.tmbundle
url = https://github.com/textmate/ant.tmbundle
[submodule "vendor/grammars/antlr.tmbundle"]
path = vendor/grammars/antlr.tmbundle
url = https://github.com/textmate/antlr.tmbundle
[submodule "vendor/grammars/apache.tmbundle"]
path = vendor/grammars/apache.tmbundle
url = https://github.com/textmate/apache.tmbundle
[submodule "vendor/grammars/applescript.tmbundle"]
path = vendor/grammars/applescript.tmbundle
url = https://github.com/textmate/applescript.tmbundle
[submodule "vendor/grammars/asp.tmbundle"]
path = vendor/grammars/asp.tmbundle
url = https://github.com/textmate/asp.tmbundle
[submodule "vendor/grammars/bison.tmbundle"]
path = vendor/grammars/bison.tmbundle
url = https://github.com/textmate/bison.tmbundle
[submodule "vendor/grammars/capnproto.tmbundle"]
path = vendor/grammars/capnproto.tmbundle
url = https://github.com/textmate/capnproto.tmbundle
[submodule "vendor/grammars/cmake.tmbundle"]
path = vendor/grammars/cmake.tmbundle
url = https://github.com/textmate/cmake.tmbundle
[submodule "vendor/grammars/cpp-qt.tmbundle"]
path = vendor/grammars/cpp-qt.tmbundle
url = https://github.com/textmate/cpp-qt.tmbundle
[submodule "vendor/grammars/css.tmbundle"]
path = vendor/grammars/css.tmbundle
url = https://github.com/textmate/css.tmbundle
[submodule "vendor/grammars/d.tmbundle"]
path = vendor/grammars/d.tmbundle
url = https://github.com/textmate/d.tmbundle
[submodule "vendor/grammars/diff.tmbundle"]
path = vendor/grammars/diff.tmbundle
url = https://github.com/textmate/diff.tmbundle
[submodule "vendor/grammars/dylan.tmbundle"]
path = vendor/grammars/dylan.tmbundle
url = https://github.com/textmate/dylan.tmbundle
[submodule "vendor/grammars/eiffel.tmbundle"]
path = vendor/grammars/eiffel.tmbundle
url = https://github.com/textmate/eiffel.tmbundle
[submodule "vendor/grammars/erlang.tmbundle"]
path = vendor/grammars/erlang.tmbundle
url = https://github.com/textmate/erlang.tmbundle
[submodule "vendor/grammars/fortran.tmbundle"]
path = vendor/grammars/fortran.tmbundle
url = https://github.com/textmate/fortran.tmbundle
[submodule "vendor/grammars/gettext.tmbundle"]
path = vendor/grammars/gettext.tmbundle
url = https://github.com/textmate/gettext.tmbundle
[submodule "vendor/grammars/graphviz.tmbundle"]
path = vendor/grammars/graphviz.tmbundle
url = https://github.com/textmate/graphviz.tmbundle
[submodule "vendor/grammars/groovy.tmbundle"]
path = vendor/grammars/groovy.tmbundle
url = https://github.com/textmate/groovy.tmbundle
[submodule "vendor/grammars/haskell.tmbundle"]
path = vendor/grammars/haskell.tmbundle
url = https://github.com/textmate/haskell.tmbundle
[submodule "vendor/grammars/html.tmbundle"]
path = vendor/grammars/html.tmbundle
url = https://github.com/textmate/html.tmbundle
[submodule "vendor/grammars/ini.tmbundle"]
path = vendor/grammars/ini.tmbundle
url = https://github.com/textmate/ini.tmbundle
[submodule "vendor/grammars/io.tmbundle"]
path = vendor/grammars/io.tmbundle
url = https://github.com/textmate/io.tmbundle
[submodule "vendor/grammars/java.tmbundle"]
path = vendor/grammars/java.tmbundle
url = https://github.com/textmate/java.tmbundle
[submodule "vendor/grammars/javadoc.tmbundle"]
path = vendor/grammars/javadoc.tmbundle
url = https://github.com/textmate/javadoc.tmbundle
[submodule "vendor/grammars/javascript-objective-j.tmbundle"]
path = vendor/grammars/javascript-objective-j.tmbundle
url = https://github.com/textmate/javascript-objective-j.tmbundle
[submodule "vendor/grammars/json.tmbundle"]
path = vendor/grammars/json.tmbundle
url = https://github.com/textmate/json.tmbundle
[submodule "vendor/grammars/latex.tmbundle"]
path = vendor/grammars/latex.tmbundle
url = https://github.com/textmate/latex.tmbundle
[submodule "vendor/grammars/less.tmbundle"]
path = vendor/grammars/less.tmbundle
url = https://github.com/textmate/less.tmbundle
[submodule "vendor/grammars/lilypond.tmbundle"]
path = vendor/grammars/lilypond.tmbundle
url = https://github.com/textmate/lilypond.tmbundle
[submodule "vendor/grammars/lisp.tmbundle"]
path = vendor/grammars/lisp.tmbundle
url = https://github.com/textmate/lisp.tmbundle
[submodule "vendor/grammars/logtalk.tmbundle"]
path = vendor/grammars/logtalk.tmbundle
url = https://github.com/textmate/logtalk.tmbundle
[submodule "vendor/grammars/lua.tmbundle"]
path = vendor/grammars/lua.tmbundle
url = https://github.com/textmate/lua.tmbundle
[submodule "vendor/grammars/make.tmbundle"]
path = vendor/grammars/make.tmbundle
url = https://github.com/textmate/make.tmbundle
[submodule "vendor/grammars/matlab.tmbundle"]
path = vendor/grammars/matlab.tmbundle
url = https://github.com/textmate/matlab.tmbundle
[submodule "vendor/grammars/maven.tmbundle"]
path = vendor/grammars/maven.tmbundle
url = https://github.com/textmate/maven.tmbundle
[submodule "vendor/grammars/nemerle.tmbundle"]
path = vendor/grammars/nemerle.tmbundle
url = https://github.com/textmate/nemerle.tmbundle
[submodule "vendor/grammars/ninja.tmbundle"]
path = vendor/grammars/ninja.tmbundle
url = https://github.com/textmate/ninja.tmbundle
[submodule "vendor/grammars/objective-c.tmbundle"]
path = vendor/grammars/objective-c.tmbundle
url = https://github.com/textmate/objective-c.tmbundle
[submodule "vendor/grammars/ocaml.tmbundle"]
path = vendor/grammars/ocaml.tmbundle
url = https://github.com/textmate/ocaml.tmbundle
[submodule "vendor/grammars/pascal.tmbundle"]
path = vendor/grammars/pascal.tmbundle
url = https://github.com/textmate/pascal.tmbundle
[submodule "vendor/grammars/perl.tmbundle"]
path = vendor/grammars/perl.tmbundle
url = https://github.com/textmate/perl.tmbundle
[submodule "vendor/grammars/php-smarty.tmbundle"]
path = vendor/grammars/php-smarty.tmbundle
url = https://github.com/textmate/php-smarty.tmbundle
[submodule "vendor/grammars/php.tmbundle"]
path = vendor/grammars/php.tmbundle
url = https://github.com/textmate/php.tmbundle
[submodule "vendor/grammars/postscript.tmbundle"]
path = vendor/grammars/postscript.tmbundle
url = https://github.com/textmate/postscript.tmbundle
[submodule "vendor/grammars/processing.tmbundle"]
path = vendor/grammars/processing.tmbundle
url = https://github.com/textmate/processing.tmbundle
[submodule "vendor/grammars/prolog.tmbundle"]
path = vendor/grammars/prolog.tmbundle
url = https://github.com/textmate/prolog.tmbundle
[submodule "vendor/grammars/python-django.tmbundle"]
path = vendor/grammars/python-django.tmbundle
url = https://github.com/textmate/python-django.tmbundle
[submodule "vendor/grammars/r.tmbundle"]
path = vendor/grammars/r.tmbundle
url = https://github.com/textmate/r.tmbundle
[submodule "vendor/grammars/restructuredtext.tmbundle"]
path = vendor/grammars/restructuredtext.tmbundle
url = https://github.com/textmate/restructuredtext.tmbundle
[submodule "vendor/grammars/ruby-haml.tmbundle"]
path = vendor/grammars/ruby-haml.tmbundle
url = https://github.com/textmate/ruby-haml.tmbundle
[submodule "vendor/grammars/ruby-on-rails-tmbundle"]
path = vendor/grammars/ruby-on-rails-tmbundle
url = https://github.com/textmate/ruby-on-rails-tmbundle
[submodule "vendor/grammars/scheme.tmbundle"]
path = vendor/grammars/scheme.tmbundle
url = https://github.com/textmate/scheme.tmbundle
[submodule "vendor/grammars/scilab.tmbundle"]
path = vendor/grammars/scilab.tmbundle
url = https://github.com/textmate/scilab.tmbundle
[submodule "vendor/grammars/sql.tmbundle"]
path = vendor/grammars/sql.tmbundle
url = https://github.com/textmate/sql.tmbundle
[submodule "vendor/grammars/standard-ml.tmbundle"]
path = vendor/grammars/standard-ml.tmbundle
url = https://github.com/textmate/standard-ml.tmbundle
[submodule "vendor/grammars/swift.tmbundle"]
path = vendor/grammars/swift.tmbundle
url = https://github.com/textmate/swift.tmbundle
[submodule "vendor/grammars/tcl.tmbundle"]
path = vendor/grammars/tcl.tmbundle
url = https://github.com/textmate/tcl.tmbundle
[submodule "vendor/grammars/text.tmbundle"]
path = vendor/grammars/text.tmbundle
url = https://github.com/textmate/text.tmbundle
[submodule "vendor/grammars/textile.tmbundle"]
path = vendor/grammars/textile.tmbundle
url = https://github.com/textmate/textile.tmbundle
[submodule "vendor/grammars/textmate.tmbundle"]
path = vendor/grammars/textmate.tmbundle
url = https://github.com/textmate/textmate.tmbundle
[submodule "vendor/grammars/thrift.tmbundle"]
path = vendor/grammars/thrift.tmbundle
url = https://github.com/textmate/thrift.tmbundle
[submodule "vendor/grammars/toml.tmbundle"]
path = vendor/grammars/toml.tmbundle
url = https://github.com/textmate/toml.tmbundle
[submodule "vendor/grammars/verilog.tmbundle"]
path = vendor/grammars/verilog.tmbundle
url = https://github.com/textmate/verilog.tmbundle
[submodule "vendor/grammars/xml.tmbundle"]
path = vendor/grammars/xml.tmbundle
url = https://github.com/textmate/xml.tmbundle
[submodule "vendor/grammars/smalltalk-tmbundle"]
path = vendor/grammars/smalltalk-tmbundle
url = https://github.com/tomas-stefano/smalltalk-tmbundle
[submodule "vendor/grammars/ioke-outdated"]
path = vendor/grammars/ioke-outdated
url = https://github.com/vic/ioke-outdated
[submodule "vendor/grammars/kotlin-sublime-package"]
path = vendor/grammars/kotlin-sublime-package
url = https://github.com/vkostyukov/kotlin-sublime-package
[submodule "vendor/grammars/c.tmbundle"]
path = vendor/grammars/c.tmbundle
url = https://github.com/textmate/c.tmbundle
[submodule "vendor/grammars/zephir-sublime"]
path = vendor/grammars/zephir-sublime
url = https://github.com/vmg/zephir-sublime
[submodule "vendor/grammars/llvm.tmbundle"]
path = vendor/grammars/llvm.tmbundle
url = https://github.com/whitequark/llvm.tmbundle
[submodule "vendor/grammars/sublime-nix"]
path = vendor/grammars/sublime-nix
url = https://github.com/wmertens/sublime-nix
[submodule "vendor/grammars/ada.tmbundle"]
path = vendor/grammars/ada.tmbundle
url = https://github.com/aroben/ada.tmbundle
branch = better-with-highlighting
[submodule "vendor/grammars/oz-tmbundle"]
path = vendor/grammars/oz-tmbundle
url = https://github.com/eregon/oz-tmbundle
[submodule "vendor/grammars/ebundles"]
path = vendor/grammars/ebundles
url = https://github.com/ericzou/ebundles
[submodule "vendor/grammars/sublime-mask"]
path = vendor/grammars/sublime-mask
url = https://github.com/tenbits/sublime-mask
[submodule "vendor/grammars/sublime_cobol"]
path = vendor/grammars/sublime_cobol
url = https://bitbucket.org/bitlang/sublime_cobol
[submodule "vendor/grammars/ruby.tmbundle"]
path = vendor/grammars/ruby.tmbundle
url = https://github.com/aroben/ruby.tmbundle
branch = pl
[submodule "vendor/grammars/IDL-Syntax"]
path = vendor/grammars/IDL-Syntax
url = https://github.com/andik/IDL-Syntax
[submodule "vendor/grammars/sas.tmbundle"]
path = vendor/grammars/sas.tmbundle
url = https://github.com/rpardee/sas.tmbundle
[submodule "vendor/grammars/atom-salt"]
path = vendor/grammars/atom-salt
url = https://github.com/saltstack/atom-salt
[submodule "vendor/grammars/Scalate.tmbundle"]
path = vendor/grammars/Scalate.tmbundle
url = https://github.com/scalate/Scalate.tmbundle
[submodule "vendor/grammars/Elm.tmLanguage"]
path = vendor/grammars/Elm.tmLanguage
url = https://github.com/deadfoxygrandpa/Elm.tmLanguage
[submodule "vendor/grammars/sublime-bsv"]
path = vendor/grammars/sublime-bsv
url = https://github.com/thotypous/sublime-bsv
[submodule "vendor/grammars/sass-textmate-bundle"]
path = vendor/grammars/sass-textmate-bundle
url = https://github.com/nathos/sass-textmate-bundle
[submodule "vendor/grammars/carto-atom"]
path = vendor/grammars/carto-atom
url = https://github.com/yohanboniface/carto-atom

View File

@@ -1,8 +1,5 @@
before_install:
- git fetch origin master:master
- git fetch origin v2.0.0:v2.0.0
- git fetch origin test/attributes:test/attributes
- sudo apt-get install libicu-dev -y
sudo: false
before_install: script/travis/before_install
rvm:
- 1.9.3
- 2.0.0
@@ -10,3 +7,6 @@ rvm:
- 2.2
notifications:
disabled: true
git:
submodules: false
cache: bundler

View File

@@ -10,9 +10,9 @@ This can usually be solved either by adding a new filename or file name extensio
### Syntax highlighting looks wrong
Assuming your code is being detected as the right language (see above), in most cases this is due to a bug in the language grammar rather than a bug in Linguist. [`grammars.yml`][grammars] lists all the grammars we use for syntax highlighting on github.com. Find the one corresponding to your code's programming language and submit a bug report upstream.
Assuming your code is being detected as the right language (see above), in most cases this is due to a bug in the language grammar rather than a bug in Linguist. [`grammars.yml`][grammars] lists all the grammars we use for syntax highlighting on github.com. Find the one corresponding to your code's programming language and submit a bug report upstream. If you can, try to reproduce the highlighting problem in the text editor that the grammar is designed for (TextMate, Sublime Text, or Atom) and include that information in your bug report.
You can also try to fix the bug yourself and submit a Pull Request. [This piece from TextMate's documentation](http://manual.macromates.com/en/language_grammars) offers a good introduction on how to work with TextMate-compatible grammars.
You can also try to fix the bug yourself and submit a Pull Request. [This piece from TextMate's documentation](http://manual.macromates.com/en/language_grammars) offers a good introduction on how to work with TextMate-compatible grammars. You can test grammars using [Lightshow](https://lightshow.githubapp.com).
Once the bug has been fixed upstream, please let us know and we'll pick it up for GitHub.
@@ -21,9 +21,19 @@ Once the bug has been fixed upstream, please let us know and we'll pick it up fo
Great! You'll need to:
0. Add an entry for your language to [`languages.yml`][languages].
0. Add a grammar for your language to [`grammars.yml`][grammars] by running `script/download-grammars --add URL`. Please only add grammars that have a license that permits redistribution.
0. Add a grammar for your language. Please only add grammars that have a license that permits redistribution.
0. Add your grammar as a submodule: `git submodule add https://github.com/JaneSmith/MyGrammar vendor/grammars/MyGrammar`.
0. Add your grammar to [`grammars.yml`][grammars] by running `script/convert-grammars --add vendor/grammars/MyGrammar`.
0. Add samples for your language to the [samples directory][samples].
In addition, if your new language defines an extension that's already listed in [`languages.yml`][languages] (such as `.foo`) then sometimes a few more steps will need to be taken:
0. Make sure that example `.foo` files are present in the [samples directory][samples] for each language that uses `.foo`.
0. Test the performance of the Bayesian classifier with a relatively large number (1000s) of sample `.foo` files. (ping @arfon or @bkeepers to help with this) to ensure we're not misclassifying files.
0. If the Bayesian classifier does a bad job with the sample `.foo` files then a [heuristic](https://github.com/github/linguist/blob/master/lib/linguist/heuristics.rb) may need to be written to help.
Remember, the goal here is to try and avoid false positives!
We try only to add languages once they have some usage on GitHub, so please note in-the-wild usage examples in your pull request. In most cases we prefer that languages already be in use in hundreds of repositories before supporting them in Linguist.
[grammars]: /grammars.yml

View File

@@ -1,4 +1,4 @@
source 'https://rubygems.org'
gemspec :name => "github-linguist"
gemspec :name => "github-linguist-grammars"
gem 'test-unit', require: false if RUBY_VERSION >= '2.2'
gem 'byebug' if RUBY_VERSION >= '2.0'

View File

@@ -141,7 +141,7 @@ But for development you are going to want to checkout out the source. To get it,
git clone https://github.com/github/linguist.git
cd linguist/
bundle install
script/bootstrap
To run the tests:
@@ -181,7 +181,7 @@ Here's our current build status, which is hopefully green: [![Build Status](http
If you are the current maintainer of this gem:
0. Create a branch for the release: `git checkout -b cut-release-vxx.xx.xx`
0. Make sure your local dependencies are up to date: `bundle install`
0. Make sure your local dependencies are up to date: `script/bootstrap`
0. Ensure that samples are updated: `bundle exec rake samples`
0. Ensure that tests are green: `bundle exec rake test`
0. Bump gem version in `lib/linguist/version.rb`. For example, [like this](https://github.com/github/linguist/commit/8d2ea90a5ba3b2fe6e1508b7155aa4632eea2985).

View File

@@ -3,13 +3,14 @@ require 'rake/clean'
require 'rake/testtask'
require 'yaml'
require 'yajl'
require 'open-uri'
task :default => :test
Rake::TestTask.new
# Extend test task to check for samples
task :test => :check_samples
# Extend test task to check for samples and fetch latest Ace modes
task :test => [:check_samples, :fetch_ace_modes]
desc "Check that we have samples.json generated"
task :check_samples do
@@ -18,6 +19,20 @@ task :check_samples do
end
end
desc "Fetch the latest Ace modes from its GitHub repository"
task :fetch_ace_modes do
ACE_FIXTURE_PATH = File.join('test', 'fixtures', 'ace_modes.json')
File.delete(ACE_FIXTURE_PATH) if File.exist?(ACE_FIXTURE_PATH)
begin
ace_github_modes = open("https://api.github.com/repos/ajaxorg/ace/contents/lib/ace/mode").read
File.write(ACE_FIXTURE_PATH, ace_github_modes)
rescue OpenURI::HTTPError, SocketError
# no internet? no problem.
end
end
task :samples do
require 'linguist/samples'
json = Yajl.dump(Linguist::Samples.data, :pretty => true)
@@ -33,7 +48,7 @@ end
task :build_grammars_gem do
rm_rf "grammars"
sh "script/download-grammars"
sh "script/convert-grammars"
sh "gem", "build", "github-linguist-grammars.gemspec"
end

View File

@@ -16,8 +16,9 @@ Gem::Specification.new do |s|
s.add_dependency 'charlock_holmes', '~> 0.7.3'
s.add_dependency 'escape_utils', '~> 1.0.1'
s.add_dependency 'mime-types', '>= 1.19'
s.add_dependency 'rugged', '~> 0.22.0b1'
s.add_dependency 'rugged', '~> 0.22.0b4'
s.add_development_dependency 'minitest', '>= 5.0'
s.add_development_dependency 'mocha'
s.add_development_dependency 'pry'
s.add_development_dependency 'rake'

View File

@@ -5,14 +5,10 @@ http://svn.textmate.org/trunk/Review/Bundles/BlitzMax.tmbundle:
- source.blitzmax
http://svn.textmate.org/trunk/Review/Bundles/Cython.tmbundle:
- source.cython
http://svn.textmate.org/trunk/Review/Bundles/F%20Sharp.tmbundle:
- source.fsharp
http://svn.textmate.org/trunk/Review/Bundles/Forth.tmbundle:
- source.forth
http://svn.textmate.org/trunk/Review/Bundles/Parrot.tmbundle:
- source.parrot.pir
http://svn.textmate.org/trunk/Review/Bundles/Ruby%20Sass.tmbundle:
- source.sass
http://svn.textmate.org/trunk/Review/Bundles/SecondLife%20LSL.tmbundle:
- source.lsl
http://svn.textmate.org/trunk/Review/Bundles/VHDL.tmbundle:
@@ -22,388 +18,438 @@ http://svn.textmate.org/trunk/Review/Bundles/XQuery.tmbundle:
https://bitbucket.org/Clams/sublimesystemverilog/get/default.tar.gz:
- source.systemverilog
- source.ucfconstraints
https://bitbucket.org/bitlang/sublime_cobol/raw/b0e9c44ac5f7a2fb553421aa986b35854cbfda4a/COBOL.tmLanguage:
- source.cobol
https://fan.googlecode.com/hg-history/Build%201.0.55/adm/tools/textmate/Fan.tmbundle/Syntaxes/Fan.tmLanguage:
- source.fan
https://github.com/AlanQuatermain/go-tmbundle:
- source.go
https://github.com/Anomareh/PHP-Twig.tmbundle:
- text.html.twig
https://github.com/Cirru/sublime-cirru/raw/master/Cirru.tmLanguage:
- source.cirru
https://github.com/Cykey/Sublime-Logos:
- source.logos
https://github.com/Drako/SublimeBrainfuck/raw/master/Brainfuck.tmLanguage:
- source.bf
https://github.com/JohnNilsson/awk-sublime/raw/master/AWK.tmLanguage:
- source.awk
https://github.com/MarioRicalde/SCSS.tmbundle:
- source.scss
https://github.com/Oldes/Sublime-REBOL:
- source.rebol
https://github.com/PogiNate/Sublime-Inform:
- source.Inform7
https://github.com/Red-Nova-Technologies/autoitv3-tmbundle:
- source.autoit.3
https://github.com/SalGnt/Sublime-VimL:
- source.viml
https://github.com/Shammah/boo-sublime/raw/master/Boo.tmLanguage:
- source.boo
https://github.com/SublimeText/ColdFusion:
vendor/grammars/Agda.tmbundle:
- source.agda
vendor/grammars/Alloy.tmbundle:
- source.alloy
vendor/grammars/ColdFusion:
- source.cfscript
- source.cfscript.cfc
- text.cfml.basic
- text.html.cfm
https://github.com/SublimeText/NSIS:
- source.nsis
https://github.com/Varriount/NimLime:
- source.nimrod
- source.nimrod_filter
- source.nimrodcfg
https://github.com/angryant0007/VBDotNetSyntax:
- source.vbnet
https://github.com/aroben/ada.tmbundle/raw/c45eed4d5f98fe3bcbbffbb9e436601ab5bbde4b/Syntaxes/Ada.plist:
- source.ada
https://github.com/aroben/ruby.tmbundle@4636a3023153c3034eb6ffc613899ba9cf33b41f:
- source.ruby
- text.html.erb
https://github.com/asbjornenge/Docker.tmbundle:
vendor/grammars/Docker.tmbundle:
- source.dockerfile
https://github.com/atom/language-clojure:
- source.clojure
https://github.com/atom/language-coffee-script:
- source.coffee
- source.litcoffee
https://github.com/atom/language-csharp:
- source.cs
- source.csx
- source.nant-build
https://github.com/atom/language-javascript:
- source.js
- source.js.regexp
https://github.com/atom/language-python:
- source.python
- source.regexp.python
- text.python.traceback
https://github.com/atom/language-shellscript:
- source.shell
- text.shell-session
https://github.com/austinwagner/sublime-sourcepawn:
- source.sp
https://github.com/bfad/Sublime-Lasso:
vendor/grammars/Elm.tmLanguage:
- source.elm
vendor/grammars/Handlebars:
- text.html.handlebars
vendor/grammars/IDL-Syntax:
- source.webidl
vendor/grammars/Isabelle.tmbundle:
- source.isabelle.root
- source.isabelle.theory
vendor/grammars/Julia.tmbundle:
- source.julia
vendor/grammars/LiveScript.tmbundle:
- source.livescript
vendor/grammars/NSIS:
- source.nsis
vendor/grammars/NimLime:
- source.nim
- source.nim_filter
- source.nimcfg
vendor/grammars/PHP-Twig.tmbundle:
- text.html.twig
vendor/grammars/RDoc.tmbundle:
- text.rdoc
vendor/grammars/SCSS.tmbundle:
- source.scss
vendor/grammars/Scalate.tmbundle:
- source.scaml
- text.html.ssp
vendor/grammars/Slash.tmbundle:
- text.html.slash
vendor/grammars/Stata.tmbundle:
- source.mata
- source.stata
vendor/grammars/Sublime-Coq:
- source.coq
vendor/grammars/Sublime-Inform:
- source.Inform7
vendor/grammars/Sublime-Lasso:
- file.lasso
https://github.com/bholt/chapel-tmbundle:
vendor/grammars/Sublime-Logos:
- source.logos
vendor/grammars/Sublime-Loom:
- source.loomscript
vendor/grammars/Sublime-QML:
- source.qml
vendor/grammars/Sublime-REBOL:
- source.rebol
vendor/grammars/Sublime-SQF-Language:
- source.sqf
vendor/grammars/Sublime-Text-2-OpenEdge-ABL:
- source.abl
vendor/grammars/Sublime-VimL:
- source.viml
vendor/grammars/SublimeBrainfuck:
- source.bf
vendor/grammars/SublimeXtend:
- source.xtend
vendor/grammars/Textmate-Gosu-Bundle:
- source.gosu.2
vendor/grammars/VBDotNetSyntax:
- source.vbnet
vendor/grammars/Vala-TMBundle:
- source.vala
vendor/grammars/abap.tmbundle:
- source.abap
vendor/grammars/actionscript3-tmbundle:
- source.actionscript.3
- text.html.asdoc
- text.xml.flex-config
vendor/grammars/ada.tmbundle:
- source.ada
vendor/grammars/ant.tmbundle:
- text.xml.ant
vendor/grammars/antlr.tmbundle:
- source.antlr
vendor/grammars/apache.tmbundle:
- source.apache-config
- source.apache-config.mod_perl
vendor/grammars/applescript.tmbundle:
- source.applescript
vendor/grammars/asp.tmbundle:
- source.asp
- text.html.asp
vendor/grammars/assembly.tmbundle:
- objdump.x86asm
- source.x86asm
vendor/grammars/atom-salt:
- source.python.salt
- source.yaml.salt
vendor/grammars/autoitv3-tmbundle:
- source.autoit.3
vendor/grammars/awk-sublime:
- source.awk
vendor/grammars/bison.tmbundle:
- source.bison
vendor/grammars/boo-sublime:
- source.boo
vendor/grammars/bro-sublime:
- source.bro
vendor/grammars/c.tmbundle:
- source.c
- source.c++
- source.c.platform
vendor/grammars/capnproto.tmbundle:
- source.capnp
vendor/grammars/carto-atom:
- source.css.mss
vendor/grammars/ceylon-sublimetext:
- module.ceylon
- source.ceylon
vendor/grammars/chapel-tmbundle:
- source.chapel
https://github.com/brandonwamboldt/sublime-nginx:
- source.nginx
https://github.com/carsonoid/sublime_man_page_support/raw/master/man-groff.tmLanguage:
- text.groff
https://github.com/ccreutzig/sublime-MuPAD:
- source.mupad
https://github.com/cdwilson/nesC.tmbundle:
- source.nesc
https://github.com/christophevg/racket-tmbundle:
- source.racket
https://github.com/clemos/haxe-sublime-bundle:
vendor/grammars/cmake.tmbundle:
- source.cache.cmake
- source.cmake
vendor/grammars/cool-tmbundle:
- source.cool
vendor/grammars/cpp-qt.tmbundle:
- source.c++.qt
- source.qmake
vendor/grammars/css.tmbundle:
- source.css
vendor/grammars/cucumber-tmbundle:
- source.ruby.rspec.cucumber.steps
- text.gherkin.feature
vendor/grammars/d.tmbundle:
- source.d
vendor/grammars/dart-sublime-bundle:
- source.dart
- source.pubspec
- text.dart-doccomments
vendor/grammars/diff.tmbundle:
- source.diff
vendor/grammars/dylan.tmbundle:
- source.dylan
- source.lid
- source.makegen
vendor/grammars/ebundles/Bundles/MSDOS batch file.tmbundle:
- source.dosbatch
vendor/grammars/eiffel.tmbundle:
- source.eiffel
vendor/grammars/elixir-tmbundle:
- source.elixir
- text.elixir
- text.html.elixir
vendor/grammars/erlang.tmbundle:
- source.erlang
- text.html.erlang.yaws
vendor/grammars/factor:
- source.factor
- text.html.factor
vendor/grammars/fancy-tmbundle:
- source.fancy
vendor/grammars/fish-tmbundle:
- source.fish
vendor/grammars/fortran.tmbundle:
- source.fortran
- source.fortran.modern
vendor/grammars/fsharpbinding:
- source.fsharp
vendor/grammars/gettext.tmbundle:
- source.po
vendor/grammars/gnuplot-tmbundle:
- source.gnuplot
vendor/grammars/go-tmbundle:
- source.go
vendor/grammars/gradle.tmbundle:
- source.groovy.gradle
vendor/grammars/graphviz.tmbundle:
- source.dot
vendor/grammars/groovy.tmbundle:
- source.groovy
vendor/grammars/haskell.tmbundle:
- source.haskell
- text.tex.latex.haskell
vendor/grammars/haxe-sublime-bundle:
- source.erazor
- source.haxe.2
- source.hss.1
- source.hxml
- source.nmml
https://github.com/cucumber/cucumber-tmbundle:
- source.ruby.rspec.cucumber.steps
- text.gherkin.feature
https://github.com/daaain/Handlebars/raw/master/Handlebars.tmLanguage:
- text.html.handlebars
https://github.com/davidpeckham/powershell.tmbundle:
- source.powershell
https://github.com/davidrios/jade-tmbundle:
- source.jade
- source.pyjade
https://github.com/elixir-lang/elixir-tmbundle:
- source.elixir
- text.elixir
- text.html.elixir
https://github.com/ericzou/ebundles/raw/master/Bundles/MSDOS%20batch%20file.tmbundle/Syntaxes/MSDOS%20batch%20file.tmLanguage:
- source.dosbatch
https://github.com/euler0/sublime-glsl/raw/master/GLSL.tmLanguage:
- source.glsl
https://github.com/fancy-lang/fancy-tmbundle:
- source.fancy
https://github.com/gingerbeardman/monkey.tmbundle:
- source.monkey
https://github.com/guillermooo/dart-sublime-bundle/raw/master/Dart.tmLanguage:
- source.dart
https://github.com/harrism/sublimetext-cuda-cpp/raw/master/cuda-c%2B%2B.tmLanguage:
- source.cuda-c++
https://github.com/hww3/pike-textmate:
- source.pike
https://github.com/jeancharles-roger/ceylon-sublimetext/raw/master/Ceylon.tmLanguage:
- source.ceylon
https://github.com/jfairbank/Sublime-Text-2-OpenEdge-ABL:
- source.abl
https://github.com/jhasse/sublime-rust:
- source.rust
https://github.com/johanasplund/sublime-befunge/raw/master/Befunge-93.tmLanguage:
- source.befunge
https://github.com/joshaven/RDoc.tmbundle:
- text.rdoc
https://github.com/jpcamara/Textmate-Gosu-Bundle/raw/master/Gosu.tmbundle/Syntaxes/Gosu.tmLanguage:
- source.gosu.2
https://github.com/kswedberg/jquery-tmbundle:
- source.js.jquery
https://github.com/laughedelic/sublime-idris/raw/master/Idris.tmLanguage:
- source.idris
https://github.com/lavrton/sublime-better-typescript:
- source.ts
https://github.com/leafo/moonscript-tmbundle:
- source.moonscript
https://github.com/lunixbochs/x86-assembly-textmate-bundle:
- source.asm.x86
https://github.com/macekond/Alloy.tmbundle:
- source.alloy
https://github.com/mads379/opa.tmbundle:
- source.opa
https://github.com/mads379/scala.tmbundle:
- source.sbt
- source.scala
https://github.com/marconi/mako-tmbundle:
- text.html.mako
https://github.com/mattfoster/gnuplot-tmbundle:
- source.gnuplot
https://github.com/mgalloy/idl.tmbundle:
vendor/grammars/html.tmbundle:
- text.html.basic
vendor/grammars/idl.tmbundle:
- source.idl
- source.idl-dlm
- text.idl-idldoc
https://github.com/michaeledgar/protobuf-tmbundle:
- source.protobuf
https://github.com/mkolosick/Sublime-Coq/raw/master/Coq.tmLanguage:
- source.coq
https://github.com/mokus0/Agda.tmbundle:
- source.agda
https://github.com/nanoant/Julia.tmbundle:
- source.julia
https://github.com/nanoant/assembly.tmbundle/raw/master/Syntaxes/objdump%20C%2B%2B.tmLanguage:
- objdump.x86asm
https://github.com/nilium/ooc.tmbundle:
- source.ooc
https://github.com/paulmillr/LiveScript.tmbundle:
- source.livescript
https://github.com/pferruggiaro/sublime-tea:
- source.tea
https://github.com/puppet-textmate-bundle/puppet-textmate-bundle:
- source.puppet
https://github.com/pvl/abap.tmbundle:
- source.abap
https://github.com/scalate/Scalate.tmbundle:
- source.scaml
- text.html.ssp
https://github.com/shadanan/mathematica-tmbundle:
- source.mathematica
https://github.com/shellderp/sublime-robot-plugin:
- text.robot
https://github.com/simongregory/actionscript3-tmbundle:
- source.actionscript.3
- text.html.asdoc
- text.xml.flex-config
https://github.com/skozlovf/Sublime-QML:
- source.qml
https://github.com/slash-lang/Slash.tmbundle:
- text.html.slash
https://github.com/slavapestov/factor/raw/master/misc/Factor.tmbundle/Syntaxes/Factor.tmLanguage:
- source.factor
https://github.com/slim-template/ruby-slim.tmbundle:
- text.slim
https://github.com/smiledawgg/Bro.tmbundle:
- source.bro
- source.bro.sig
https://github.com/staltz/SublimeXtend:
- source.xtend
https://github.com/statatmbundle/Stata.tmbundle:
- source.mata
- source.stata
https://github.com/technosophos/Vala-TMBundle:
- source.vala
https://github.com/textmate/ant.tmbundle:
- text.xml.ant
https://github.com/textmate/antlr.tmbundle:
- source.antlr
https://github.com/textmate/apache.tmbundle:
- source.apache-config
- source.apache-config.mod_perl
https://github.com/textmate/applescript.tmbundle:
- source.applescript
https://github.com/textmate/asp.tmbundle:
- source.asp
- text.html.asp
https://github.com/textmate/bison.tmbundle:
- source.bison
https://github.com/textmate/c.tmbundle:
- source.c
- source.c++
- source.c.platform
https://github.com/textmate/capnproto.tmbundle:
- source.capnp
https://github.com/textmate/cmake.tmbundle:
- source.cache.cmake
- source.cmake
https://github.com/textmate/cpp-qt.tmbundle:
- source.c++.qt
- source.qmake
https://github.com/textmate/css.tmbundle:
- source.css
https://github.com/textmate/d.tmbundle:
- source.d
https://github.com/textmate/diff.tmbundle:
- source.diff
https://github.com/textmate/dylan.tmbundle:
- source.dylan
- source.lid
- source.makegen
https://github.com/textmate/eiffel.tmbundle:
- source.eiffel
https://github.com/textmate/erlang.tmbundle:
- source.erlang
- text.html.erlang.yaws
https://github.com/textmate/fortran.tmbundle:
- source.fortran
- source.fortran.modern
https://github.com/textmate/gettext.tmbundle:
- source.po
https://github.com/textmate/graphviz.tmbundle:
- source.dot
https://github.com/textmate/groovy.tmbundle:
- source.groovy
https://github.com/textmate/haskell.tmbundle:
- source.haskell
- text.tex.latex.haskell
https://github.com/textmate/html.tmbundle:
- text.html.basic
https://github.com/textmate/ini.tmbundle:
vendor/grammars/ini.tmbundle:
- source.ini
https://github.com/textmate/io.tmbundle:
vendor/grammars/io.tmbundle:
- source.io
https://github.com/textmate/java.tmbundle:
vendor/grammars/ioke-outdated:
- source.ioke
vendor/grammars/jade-tmbundle:
- source.jade
- source.pyjade
vendor/grammars/jasmin-sublime:
- source.jasmin
vendor/grammars/java.tmbundle:
- source.java
- source.java-properties
- text.html.jsp
- text.junit-test-report
https://github.com/textmate/javadoc.tmbundle:
vendor/grammars/javadoc.tmbundle:
- text.html.javadoc
https://github.com/textmate/javascript-objective-j.tmbundle:
vendor/grammars/javascript-objective-j.tmbundle:
- source.js.objj
https://github.com/textmate/json.tmbundle:
vendor/grammars/jquery-tmbundle:
- source.js.jquery
vendor/grammars/json.tmbundle:
- source.json
https://github.com/textmate/latex.tmbundle:
vendor/grammars/kotlin-sublime-package:
- source.Kotlin
vendor/grammars/language-clojure:
- source.clojure
vendor/grammars/language-coffee-script:
- source.coffee
- source.litcoffee
vendor/grammars/language-csharp:
- source.cs
- source.csx
- source.nant-build
vendor/grammars/language-gfm:
- source.gfm
vendor/grammars/language-javascript:
- source.js
- source.js.regexp
vendor/grammars/language-python:
- source.python
- source.regexp.python
- text.python.console
- text.python.traceback
vendor/grammars/language-shellscript:
- source.shell
- text.shell-session
vendor/grammars/language-yaml:
- source.yaml
vendor/grammars/latex.tmbundle:
- text.bibtex
- text.log.latex
- text.tex
- text.tex.latex
- text.tex.latex.beamer
- text.tex.latex.memoir
https://github.com/textmate/less.tmbundle:
vendor/grammars/less.tmbundle:
- source.css.less
https://github.com/textmate/lilypond.tmbundle:
vendor/grammars/lilypond.tmbundle:
- source.lilypond
https://github.com/textmate/lisp.tmbundle:
vendor/grammars/lisp.tmbundle:
- source.lisp
https://github.com/textmate/logtalk.tmbundle:
vendor/grammars/llvm.tmbundle:
- source.llvm
vendor/grammars/logtalk.tmbundle:
- source.logtalk
https://github.com/textmate/lua.tmbundle:
vendor/grammars/lua.tmbundle:
- source.lua
https://github.com/textmate/make.tmbundle:
vendor/grammars/make.tmbundle:
- source.makefile
https://github.com/textmate/markdown.tmbundle:
- text.html.markdown
https://github.com/textmate/matlab.tmbundle:
vendor/grammars/mako-tmbundle:
- text.html.mako
vendor/grammars/mathematica-tmbundle:
- source.mathematica
vendor/grammars/matlab.tmbundle:
- source.matlab
- source.octave
https://github.com/textmate/maven.tmbundle:
vendor/grammars/maven.tmbundle:
- text.xml.pom
https://github.com/textmate/nemerle.tmbundle:
vendor/grammars/mercury-tmlanguage:
- source.mercury
vendor/grammars/monkey.tmbundle:
- source.monkey
vendor/grammars/moonscript-tmbundle:
- source.moonscript
vendor/grammars/nemerle.tmbundle:
- source.nemerle
https://github.com/textmate/ninja.tmbundle:
vendor/grammars/nesC.tmbundle:
- source.nesc
vendor/grammars/ninja.tmbundle:
- source.ninja
https://github.com/textmate/objective-c.tmbundle:
vendor/grammars/objective-c.tmbundle:
- source.objc
- source.objc++
- source.objc.platform
- source.strings
https://github.com/textmate/ocaml.tmbundle:
vendor/grammars/ocaml.tmbundle:
- source.camlp4.ocaml
- source.ocaml
- source.ocamllex
- source.ocamlyacc
https://github.com/textmate/pascal.tmbundle:
vendor/grammars/ooc.tmbundle:
- source.ooc
vendor/grammars/opa.tmbundle:
- source.opa
vendor/grammars/oz-tmbundle/Syntaxes/Oz.tmLanguage:
- source.oz
vendor/grammars/pascal.tmbundle:
- source.pascal
https://github.com/textmate/perl.tmbundle:
vendor/grammars/perl.tmbundle:
- source.perl
https://github.com/textmate/php-smarty.tmbundle:
vendor/grammars/php-smarty.tmbundle:
- source.smarty
https://github.com/textmate/php.tmbundle:
vendor/grammars/php.tmbundle:
- text.html.php
https://github.com/textmate/postscript.tmbundle:
vendor/grammars/pike-textmate:
- source.pike
vendor/grammars/postscript.tmbundle:
- source.postscript
https://github.com/textmate/processing.tmbundle:
vendor/grammars/powershell.tmbundle:
- source.powershell
vendor/grammars/processing.tmbundle:
- source.processing
https://github.com/textmate/prolog.tmbundle:
vendor/grammars/prolog.tmbundle:
- source.prolog
https://github.com/textmate/python-django.tmbundle:
vendor/grammars/protobuf-tmbundle:
- source.protobuf
vendor/grammars/puppet-textmate-bundle:
- source.puppet
vendor/grammars/python-django.tmbundle:
- source.python.django
- text.html.django
https://github.com/textmate/r.tmbundle:
vendor/grammars/r.tmbundle:
- source.r
- text.tex.latex.rd
https://github.com/textmate/restructuredtext.tmbundle:
vendor/grammars/racket-tmbundle:
- source.racket
vendor/grammars/restructuredtext.tmbundle:
- text.restructuredtext
https://github.com/textmate/ruby-haml.tmbundle:
vendor/grammars/ruby-haml.tmbundle:
- text.haml
https://github.com/textmate/ruby-on-rails-tmbundle:
vendor/grammars/ruby-on-rails-tmbundle:
- source.js.erb.rails
- source.ruby.rails
- source.ruby.rails.rjs
- source.sql.ruby
- text.html.erb.rails
https://github.com/textmate/scheme.tmbundle:
vendor/grammars/ruby-slim.tmbundle:
- text.slim
vendor/grammars/ruby.tmbundle:
- source.ruby
- text.html.erb
vendor/grammars/sas.tmbundle:
- source.SASLog
- source.sas
vendor/grammars/sass-textmate-bundle:
- source.sass
vendor/grammars/scala.tmbundle:
- source.sbt
- source.scala
vendor/grammars/scheme.tmbundle:
- source.scheme
https://github.com/textmate/scilab.tmbundle:
vendor/grammars/scilab.tmbundle:
- source.scilab
https://github.com/textmate/sql.tmbundle:
vendor/grammars/smalltalk-tmbundle:
- source.smalltalk
vendor/grammars/sql.tmbundle:
- source.sql
https://github.com/textmate/standard-ml.tmbundle:
vendor/grammars/standard-ml.tmbundle:
- source.cm
- source.ml
https://github.com/textmate/swift.tmbundle:
vendor/grammars/sublime-MuPAD:
- source.mupad
vendor/grammars/sublime-befunge:
- source.befunge
vendor/grammars/sublime-better-typescript:
- source.ts
vendor/grammars/sublime-bsv:
- source.bsv
vendor/grammars/sublime-cirru:
- source.cirru
vendor/grammars/sublime-glsl:
- source.essl
- source.glsl
vendor/grammars/sublime-idris:
- source.idris
vendor/grammars/sublime-mask:
- source.mask
vendor/grammars/sublime-nginx:
- source.nginx
vendor/grammars/sublime-nix:
- source.nix
vendor/grammars/sublime-robot-plugin:
- text.robot
vendor/grammars/sublime-rust:
- source.rust
vendor/grammars/sublime-sourcepawn:
- source.sp
vendor/grammars/sublime-tea:
- source.tea
vendor/grammars/sublime_cobol:
- source.acucobol
- source.cobol
- source.opencobol
vendor/grammars/sublime_man_page_support:
- source.man
- text.groff
vendor/grammars/sublimetext-cuda-cpp:
- source.cuda-c++
vendor/grammars/swift.tmbundle:
- source.swift
https://github.com/textmate/tcl.tmbundle:
vendor/grammars/tcl.tmbundle:
- source.tcl
- text.html.tcl
https://github.com/textmate/text.tmbundle:
vendor/grammars/text.tmbundle:
- text.plain
https://github.com/textmate/textile.tmbundle:
vendor/grammars/textile.tmbundle:
- text.html.textile
https://github.com/textmate/textmate.tmbundle:
vendor/grammars/textmate.tmbundle:
- source.regexp.oniguruma
- source.tm-properties
https://github.com/textmate/thrift.tmbundle:
vendor/grammars/thrift.tmbundle:
- source.thrift
https://github.com/textmate/toml.tmbundle:
vendor/grammars/toml.tmbundle:
- source.toml
https://github.com/textmate/verilog.tmbundle:
vendor/grammars/verilog.tmbundle:
- source.verilog
https://github.com/textmate/xml.tmbundle:
vendor/grammars/x86-assembly-textmate-bundle:
- source.asm.x86
vendor/grammars/xml.tmbundle:
- text.xml
- text.xml.xsl
https://github.com/textmate/yaml.tmbundle:
- source.yaml
https://github.com/tomas-stefano/smalltalk-tmbundle:
- source.smalltalk
https://github.com/vic/ioke-outdated/raw/master/share/TextMate/Ioke.tmbundle/Syntaxes/Ioke.tmLanguage:
- source.ioke
https://github.com/vkostyukov/kotlin-sublime-package:
- source.Kotlin
https://github.com/vmg/zephir-sublime:
vendor/grammars/zephir-sublime:
- source.php.zephir
https://github.com/whitequark/llvm.tmbundle:
- source.llvm

View File

@@ -4,4 +4,5 @@ require 'linguist/heuristics'
require 'linguist/language'
require 'linguist/repository'
require 'linguist/samples'
require 'linguist/shebang'
require 'linguist/version'

View File

@@ -3,6 +3,25 @@ require 'linguist/tokenizer'
module Linguist
# Language bayesian classifier.
class Classifier
# Public: Use the classifier to detect language of the blob.
#
# blob - An object that quacks like a blob.
# possible_languages - Array of Language objects
#
# Examples
#
# Classifier.call(FileBlob.new("path/to/file"), [
# Language["Ruby"], Language["Python"]
# ])
#
# Returns an Array of Language objects, most probable first.
def self.call(blob, possible_languages)
language_names = possible_languages.map(&:name)
classify(Samples.cache, blob.data, language_names).map do |name, _|
Language[name] # Return the actual Language objects
end
end
# Public: Train classifier that data is a certain language.
#
# db - Hash classifier database object

View File

@@ -57,14 +57,20 @@ module Linguist
#
# Returns a String.
def extension
# File.extname returns nil if the filename is an extension.
extension = File.extname(name)
basename = File.basename(name)
# Checks if the filename is an extension.
if extension.empty? && basename[0] == "."
basename
else
extension
extensions.last || ""
end
# Public: Return an array of the file extensions
#
# >> Linguist::FileBlob.new("app/views/things/index.html.erb").extensions
# => [".html.erb", ".erb"]
#
# Returns an Array
def extensions
basename, *segments = File.basename(name).split(".")
segments.map.with_index do |segment, index|
"." + segments[index..-1].join(".")
end
end
end

View File

@@ -51,20 +51,20 @@ module Linguist
#
# Return true or false
def generated?
minified_files? ||
compiled_coffeescript? ||
xcode_file? ||
generated_parser? ||
generated_net_docfile? ||
generated_net_designer_file? ||
generated_postscript? ||
generated_protocol_buffer? ||
generated_jni_header? ||
composer_lock? ||
node_modules? ||
godeps? ||
vcr_cassette? ||
generated_by_zephir?
generated_by_zephir? ||
minified_files? ||
compiled_coffeescript? ||
generated_parser? ||
generated_net_docfile? ||
generated_postscript? ||
generated_protocol_buffer? ||
generated_jni_header? ||
vcr_cassette?
end
# Internal: Is the blob an Xcode file?

View File

@@ -1,158 +1,185 @@
module Linguist
# A collection of simple heuristics that can be used to better analyze languages.
class Heuristics
ACTIVE = true
# Public: Given an array of String language names,
# apply heuristics against the given data and return an array
# of matching languages, or nil.
# Public: Use heuristics to detect language of the blob.
#
# data - Array of tokens or String data to analyze.
# languages - Array of language name Strings to restrict to.
# blob - An object that quacks like a blob.
# possible_languages - Array of Language objects
#
# Returns an array of Languages or []
def self.find_by_heuristics(data, languages)
if active?
result = []
# Examples
#
# Heuristics.call(FileBlob.new("path/to/file"), [
# Language["Ruby"], Language["Python"]
# ])
#
# Returns an Array of languages, or empty if none matched or were inconclusive.
def self.call(blob, languages)
data = blob.data
if languages.all? { |l| ["Perl", "Prolog"].include?(l) }
result = disambiguate_pl(data)
end
if languages.all? { |l| ["ECL", "Prolog"].include?(l) }
result = disambiguate_ecl(data)
end
if languages.all? { |l| ["IDL", "Prolog"].include?(l) }
result = disambiguate_pro(data)
end
if languages.all? { |l| ["Common Lisp", "OpenCL"].include?(l) }
result = disambiguate_cl(data)
end
if languages.all? { |l| ["Hack", "PHP"].include?(l) }
result = disambiguate_hack(data)
end
if languages.all? { |l| ["Scala", "SuperCollider"].include?(l) }
result = disambiguate_sc(data)
end
if languages.all? { |l| ["AsciiDoc", "AGS Script"].include?(l) }
result = disambiguate_asc(data)
end
if languages.all? { |l| ["FORTRAN", "Forth"].include?(l) }
result = disambiguate_f(data)
end
return result
@heuristics.each do |heuristic|
return Array(heuristic.call(data)) if heuristic.matches?(languages)
end
[] # No heuristics matched
end
# Internal: Define a new heuristic.
#
# languages - String names of languages to disambiguate.
# heuristic - Block which takes data as an argument and returns a Language or nil.
#
# Examples
#
# disambiguate "Perl", "Prolog" do |data|
# if data.include?("use strict")
# Language["Perl"]
# elsif data.include?(":-")
# Language["Prolog"]
# end
# end
#
def self.disambiguate(*languages, &heuristic)
@heuristics << new(languages, &heuristic)
end
# Internal: Array of defined heuristics
@heuristics = []
# Internal
def initialize(languages, &heuristic)
@languages = languages
@heuristic = heuristic
end
# Internal: Check if this heuristic matches the candidate languages.
def matches?(candidates)
candidates.any? && candidates.all? { |l| @languages.include?(l.name) }
end
# Internal: Perform the heuristic
def call(data)
@heuristic.call(data)
end
disambiguate "BitBake", "BlitzBasic" do |data|
if /^\s*; /.match(data) || data.include?("End Function")
Language["BlitzBasic"]
elsif /^\s*(# |include|require)\b/.match(data)
Language["BitBake"]
end
end
# .h extensions are ambiguous between C, C++, and Objective-C.
# We want to shortcut look for Objective-C _and_ now C++ too!
#
# Returns an array of Languages or []
def self.disambiguate_c(data)
matches = []
if data.include?("@interface")
matches << Language["Objective-C"]
elsif data.include?("#include <cstdint>")
matches << Language["C++"]
disambiguate "Objective-C", "C++", "C" do |data|
if (/^[ \t]*@(interface|class|protocol|property|end|synchronised|selector|implementation)\b/.match(data))
Language["Objective-C"]
elsif (/^\s*#\s*include <(cstdint|string|vector|map|list|array|bitset|queue|stack|forward_list|unordered_map|unordered_set|(i|o|io)stream)>/.match(data) ||
/^\s*template\s*</.match(data) || /^[ \t]*try/.match(data) || /^[ \t]*catch\s*\(/.match(data) || /^[ \t]*(class|(using[ \t]+)?namespace)\s+\w+/.match(data) || /^[ \t]*(private|public|protected):$/.match(data) || /std::\w+/.match(data))
Language["C++"]
end
matches
end
def self.disambiguate_pl(data)
matches = []
if data.include?("use strict")
matches << Language["Perl"]
disambiguate "Perl", "Perl6", "Prolog" do |data|
if data.include?("use v6")
Language["Perl6"]
elsif data.include?("use strict")
Language["Perl"]
elsif data.include?(":-")
matches << Language["Prolog"]
Language["Prolog"]
end
matches
end
def self.disambiguate_ecl(data)
matches = []
disambiguate "ECL", "Prolog" do |data|
if data.include?(":-")
matches << Language["Prolog"]
Language["Prolog"]
elsif data.include?(":=")
matches << Language["ECL"]
Language["ECL"]
end
matches
end
def self.disambiguate_pro(data)
matches = []
if (data.include?(":-"))
matches << Language["Prolog"]
disambiguate "IDL", "Prolog" do |data|
if data.include?(":-")
Language["Prolog"]
else
matches << Language["IDL"]
Language["IDL"]
end
matches
end
def self.disambiguate_ts(data)
matches = []
if (data.include?("</translation>"))
matches << Language["XML"]
else
matches << Language["TypeScript"]
end
matches
end
def self.disambiguate_cl(data)
matches = []
disambiguate "Common Lisp", "OpenCL", "Cool" do |data|
if data.include?("(defun ")
matches << Language["Common Lisp"]
Language["Common Lisp"]
elsif /^class/x.match(data)
Language["Cool"]
elsif /\/\* |\/\/ |^\}/.match(data)
matches << Language["OpenCL"]
Language["OpenCL"]
end
matches
end
def self.disambiguate_r(data)
matches = []
matches << Language["Rebol"] if /\bRebol\b/i.match(data)
matches << Language["R"] if data.include?("<-")
matches
end
def self.disambiguate_hack(data)
matches = []
disambiguate "Hack", "PHP" do |data|
if data.include?("<?hh")
matches << Language["Hack"]
Language["Hack"]
elsif /<?[^h]/.match(data)
matches << Language["PHP"]
Language["PHP"]
end
matches
end
def self.disambiguate_sc(data)
matches = []
if (/\^(this|super)\./.match(data) || /^\s*(\+|\*)\s*\w+\s*{/.match(data) || /^\s*~\w+\s*=\./.match(data))
matches << Language["SuperCollider"]
disambiguate "Scala", "SuperCollider" do |data|
if /\^(this|super)\./.match(data) || /^\s*(\+|\*)\s*\w+\s*{/.match(data) || /^\s*~\w+\s*=\./.match(data)
Language["SuperCollider"]
elsif /^\s*import (scala|java)\./.match(data) || /^\s*val\s+\w+\s*=/.match(data) || /^\s*class\b/.match(data)
Language["Scala"]
end
if (/^\s*import (scala|java)\./.match(data) || /^\s*val\s+\w+\s*=/.match(data) || /^\s*class\b/.match(data))
matches << Language["Scala"]
end
matches
end
def self.disambiguate_asc(data)
matches = []
matches << Language["AsciiDoc"] if /^=+(\s|\n)/.match(data)
matches
disambiguate "AsciiDoc", "AGS Script" do |data|
Language["AsciiDoc"] if /^=+(\s|\n)/.match(data)
end
def self.disambiguate_f(data)
matches = []
disambiguate "FORTRAN", "Forth" do |data|
if /^: /.match(data)
matches << Language["Forth"]
elsif /^([c*][^a-z]| subroutine\s)/i.match(data)
matches << Language["FORTRAN"]
Language["Forth"]
elsif /^([c*][^a-z]| (subroutine|program)\s|!)/i.match(data)
Language["FORTRAN"]
end
matches
end
def self.active?
!!ACTIVE
disambiguate "F#", "Forth", "GLSL" do |data|
if /^(: |new-device)/.match(data)
Language["Forth"]
elsif /^\s*(#light|import|let|module|namespace|open|type)/.match(data)
Language["F#"]
elsif /^\s*(#include|#pragma|precision|uniform|varying|void)/.match(data)
Language["GLSL"]
end
end
disambiguate "Gosu", "JavaScript" do |data|
Language["Gosu"] if /^uses java\./.match(data)
end
disambiguate "LoomScript", "LiveScript" do |data|
if /^\s*package\s*[\w\.\/\*\s]*\s*{/.match(data)
Language["LoomScript"]
else
Language["LiveScript"]
end
end
disambiguate "TypeScript", "XML" do |data|
if data.include?("<TS ")
Language["XML"]
else
Language["TypeScript"]
end
end
disambiguate "Frege", "Forth", "Text" do |data|
if /^(: |also |new-device|previous )/.match(data)
Language["Forth"]
elsif /\s*(import|module|package|data|type) /.match(data)
Language["Frege"]
else
Language["Text"]
end
end
end
end

View File

@@ -10,6 +10,8 @@ require 'linguist/heuristics'
require 'linguist/samples'
require 'linguist/file_blob'
require 'linguist/blob_helper'
require 'linguist/strategy/filename'
require 'linguist/shebang'
module Linguist
# Language names that are recognizable by GitHub. Defined languages
@@ -91,6 +93,13 @@ module Linguist
language
end
STRATEGIES = [
Linguist::Strategy::Filename,
Linguist::Shebang,
Linguist::Heuristics,
Linguist::Classifier
]
# Public: Detects the Language of the blob.
#
# blob - an object that includes the Linguist `BlobHelper` interface;
@@ -98,49 +107,22 @@ module Linguist
#
# Returns Language or nil.
def self.detect(blob)
name = blob.name.to_s
# Bail early if the blob is binary or empty.
return nil if blob.likely_binary? || blob.binary? || blob.empty?
# A bit of an elegant hack. If the file is executable but extensionless,
# append a "magic" extension so it can be classified with other
# languages that have shebang scripts.
extension = FileBlob.new(name).extension
if extension.empty? && blob.mode && (blob.mode.to_i(8) & 05) == 05
name += ".script!"
end
# First try to find languages that match based on filename.
possible_languages = find_by_filename(name)
# If there is more than one possible language with that extension (or no
# extension at all, in the case of extensionless scripts), we need to continue
# our detection work
if possible_languages.length > 1
data = blob.data
possible_language_names = possible_languages.map(&:name)
heuristic_languages = Heuristics.find_by_heuristics(data, possible_language_names)
if heuristic_languages.size > 1
possible_language_names = heuristic_languages.map(&:name)
# Call each strategy until one candidate is returned.
STRATEGIES.reduce([]) do |languages, strategy|
candidates = strategy.call(blob, languages)
if candidates.size == 1
return candidates.first
elsif candidates.size > 1
# More than one candidate was found, pass them to the next strategy.
candidates
else
# No candiates were found, pass on languages from the previous strategy.
languages
end
# Check if there's a shebang line and use that as authoritative
if (result = find_by_shebang(data)) && !result.empty?
result.first
# No shebang. Still more work to do. Try to find it with our heuristics.
elsif heuristic_languages.size == 1
heuristic_languages.first
# Lastly, fall back to the probabilistic classifier.
elsif classified = Classifier.classify(Samples.cache, data, possible_language_names).first
# Return the actual Language object based of the string language name (i.e., first element of `#classify`)
Language[classified[0]]
end
else
# Simplest and most common case, we can just return the one match based on extension
possible_languages.first
end
end.first
end
# Public: Get all Languages
@@ -190,8 +172,13 @@ module Linguist
# Returns all matching Languages or [] if none were found.
def self.find_by_filename(filename)
basename = File.basename(filename)
extname = FileBlob.new(filename).extension
(@filename_index[basename] + find_by_extension(extname)).compact.uniq
# find the first extension with language definitions
extname = FileBlob.new(filename).extensions.detect do |e|
!@extension_index[e].empty?
end
(@filename_index[basename] + @extension_index[extname]).compact.uniq
end
# Public: Look up Languages by file extension.
@@ -212,20 +199,26 @@ module Linguist
@extension_index[extname]
end
# Public: Look up Languages by shebang line.
# DEPRECATED
def self.find_by_shebang(data)
@interpreter_index[Shebang.interpreter(data)]
end
# Public: Look up Languages by interpreter.
#
# data - Array of tokens or String data to analyze.
# interpreter - String of interpreter name
#
# Examples
#
# Language.find_by_shebang("#!/bin/bash\ndate;")
# Language.find_by_interpreter("bash")
# # => [#<Language name="Bash">]
#
# Returns the matching Language
def self.find_by_shebang(data)
@interpreter_index[Linguist.interpreter_from_shebang(data)]
def self.find_by_interpreter(interpreter)
@interpreter_index[interpreter]
end
# Public: Look up Language by its name or lexer.
#
# name - The String name of the Language
@@ -276,8 +269,12 @@ module Linguist
# Public: A List of languages compatible with Ace.
#
# TODO: Remove this method in a 5.x release. Every language now needs an ace_mode
# key, so this function isn't doing anything unique anymore.
#
# Returns an Array of Languages.
def self.ace_modes
warn "This method will be deprecated in a future 5.x release. Every language now has an `ace_mode` set."
@ace_modes ||= all.select(&:ace_mode).sort_by { |lang| lang.name.downcase }
end
@@ -551,7 +548,7 @@ module Linguist
if extnames = extensions[name]
extnames.each do |extname|
if !options['extensions'].include?(extname)
if !options['extensions'].index { |x| x.end_with? extname }
warn "#{name} has a sample with extension (#{extname}) that isn't explicitly defined in languages.yml" unless extname == '.script!'
options['extensions'] << extname
end

File diff suppressed because it is too large Load Diff

View File

@@ -3,7 +3,6 @@
# This file should only be edited by GitHub staff
- ActionScript
- Bash
- C
- C#
- C++
@@ -27,3 +26,4 @@
- SQL
- Scala
- Scheme
- Shell

View File

@@ -6,6 +6,7 @@ end
require 'linguist/md5'
require 'linguist/classifier'
require 'linguist/shebang'
module Linguist
# Model for accessing classifier training data.
@@ -33,10 +34,6 @@ module Linguist
Dir.entries(ROOT).sort!.each do |category|
next if category == '.' || category == '..'
# Skip text and binary for now
# Possibly reconsider this later
next if category == 'Text' || category == 'Binary'
dirname = File.join(ROOT, category)
Dir.entries(dirname).each do |filename|
next if filename == '.' || filename == '..'
@@ -52,14 +49,16 @@ module Linguist
})
end
else
path = File.join(dirname, filename)
if File.extname(filename) == ""
raise "#{File.join(dirname, filename)} is missing an extension, maybe it belongs in filenames/ subdir"
raise "#{path} is missing an extension, maybe it belongs in filenames/ subdir"
end
yield({
:path => File.join(dirname, filename),
:path => path,
:language => category,
:interpreter => File.exist?(filename) ? Linguist.interpreter_from_shebang(File.read(filename)) : nil,
:interpreter => Shebang.interpreter(File.read(path)),
:extname => File.extname(filename)
})
end
@@ -112,40 +111,4 @@ module Linguist
db
end
end
# Used to retrieve the interpreter from the shebang line of a file's
# data.
def self.interpreter_from_shebang(data)
lines = data.lines.to_a
if lines.any? && (match = lines[0].match(/(.+)\n?/)) && (bang = match[0]) =~ /^#!/
bang.sub!(/^#! /, '#!')
tokens = bang.split(' ')
pieces = tokens.first.split('/')
if pieces.size > 1
script = pieces.last
else
script = pieces.first.sub('#!', '')
end
script = script == 'env' ? tokens[1] : script
# "python2.6" -> "python"
if script =~ /((?:\d+\.?)+)/
script.sub! $1, ''
end
# Check for multiline shebang hacks that call `exec`
if script == 'sh' &&
lines[0...5].any? { |l| l.match(/exec (\w+).+\$0.+\$@/) }
script = $1
end
script
else
nil
end
end
end

53
lib/linguist/shebang.rb Normal file
View File

@@ -0,0 +1,53 @@
module Linguist
class Shebang
# Public: Use shebang to detect language of the blob.
#
# blob - An object that quacks like a blob.
#
# Examples
#
# Shebang.call(FileBlob.new("path/to/file"))
#
# Returns an Array with one Language if the blob has a shebang with a valid
# interpreter, or empty if there is no shebang.
def self.call(blob, _ = nil)
Language.find_by_interpreter interpreter(blob.data)
end
# Public: Get the interpreter from the shebang
#
# Returns a String or nil
def self.interpreter(data)
shebang = data.lines.first
# First line must start with #!
return unless shebang && shebang.start_with?("#!")
# Get the parts of the shebang without the #!
tokens = shebang.sub(/^#!\s*/, '').strip.split(' ')
# There was nothing after the #!
return if tokens.empty?
# Get the name of the interpreter
script = File.basename(tokens.first)
# Get next argument if interpreter was /usr/bin/env
script = tokens[1] if script == 'env'
# Interpreter was /usr/bin/env with no arguments
return unless script
# "python2.6" -> "python2"
script.sub! /(\.\d+)$/, ''
# Check for multiline shebang hacks that call `exec`
if script == 'sh' &&
data.lines.first(5).any? { |l| l.match(/exec (\w+).+\$0.+\$@/) }
script = $1
end
File.basename(script)
end
end
end

View File

@@ -0,0 +1,20 @@
module Linguist
module Strategy
# Detects language based on filename and/or extension
class Filename
def self.call(blob, _)
name = blob.name.to_s
# A bit of an elegant hack. If the file is executable but extensionless,
# append a "magic" extension so it can be classified with other
# languages that have shebang scripts.
extensions = FileBlob.new(name).extensions
if extensions.empty? && blob.mode && (blob.mode.to_i(8) & 05) == 05
name += ".script!"
end
Language.find_by_filename(name)
end
end
end
end

View File

@@ -32,6 +32,7 @@
# Erlang bundles
- ^rebar$
- erlang.mk
# Go dependencies
- Godeps/_workspace/
@@ -110,6 +111,9 @@
# MathJax
- (^|/)MathJax/
# Chart.js
- (^|/)Chart\.js$
# Codemirror
- (^|/)[Cc]ode[Mm]irror/(lib|mode|theme|addon|keymap)
@@ -229,9 +233,6 @@
# .DS_Store's
- .[Dd][Ss]_[Ss]tore$
# Mercury --use-subdirs
- Mercury/
# R packages
- ^vignettes/
- ^inst/extdata/

View File

@@ -1,3 +1,3 @@
module Linguist
VERSION = "4.0.2"
VERSION = "4.2.6"
end

View File

@@ -0,0 +1,25 @@
include gstreamer1.0-libav.inc
LIC_FILES_CHKSUM = "file://COPYING;md5=b234ee4d69f5fce4486a80fdaf4a4263 \
file://COPYING.LIB;md5=6762ed442b3822387a51c92d928ead0d \
file://ext/libav/gstav.h;beginline=1;endline=18;md5=a752c35267d8276fd9ca3db6994fca9c \
file://gst-libs/ext/libav/LICENSE;md5=23a54f59b82572c203a559346e89ed57 \
file://gst-libs/ext/libav/COPYING.GPLv2;md5=b234ee4d69f5fce4486a80fdaf4a4263 \
file://gst-libs/ext/libav/COPYING.GPLv3;md5=d32239bcb673463ab874e80d47fae504 \
file://gst-libs/ext/libav/COPYING.LGPLv2.1;md5=bd7a443320af8c812e4c18d1b79df004 \
file://gst-libs/ext/libav/COPYING.LGPLv3;md5=e6a600fd5e1d9cbde2d983680233ad02"
SRC_URI = " \
http://gstreamer.freedesktop.org/src/gst-libav/gst-libav-${PV}.tar.xz \
file://0001-Disable-yasm-for-libav-when-disable-yasm.patch \
"
SRC_URI[md5sum] = "86540dee14d31daf976eb2713f2294f3"
SRC_URI[sha256sum] = "585eb7971006100ad771a852e07bd2f3e23bcc6eb0b1253a40b5a0e40e4e7418"
LIBAV_EXTRA_CONFIGURE_COMMON_ARG = "--target-os=linux \
--cc='${CC}' --as='${CC}' --ld='${CC}' --nm='${NM}' --ar='${AR}' \
--ranlib='${RANLIB}' \
${GSTREAMER_1_0_DEBUG}"
S = "${WORKDIR}/gst-libav-${PV}"

View File

@@ -0,0 +1,13 @@
require qt5-git.inc
require ${PN}.inc
do_install_append() {
# for modules which are still using syncqt and call qtPrepareTool(QMAKE_SYNCQT, syncqt)
# e.g. qt3d, qtwayland
ln -sf syncqt.pl ${D}${OE_QMAKE_PATH_QT_BINS}/syncqt
}
QT_MODULE_BRANCH = "release"
# v5.2.1 + 168 commits
SRCREV = "08cbbde61778276ccdda73d89fd64d02c623779f"

View File

@@ -0,0 +1,26 @@
using System.Reflection;
using System.Runtime.CompilerServices;
// Information about this assembly is defined by the following attributes.
// Change them to the values specific to your project.
[assembly: AssemblyTitle("Simple")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("")]
[assembly: AssemblyCopyright("")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}".
// The form "{Major}.{Minor}.*" will automatically update the build and revision,
// and "{Major}.{Minor}.{Build}.*" will update just the revision.
[assembly: AssemblyVersion("1.0.*")]
// The following attributes are used to specify the signing key for the assembly,
// if desired. See the Mono documentation for more information about signing.
//[assembly: AssemblyDelaySign(false)]
//[assembly: AssemblyKeyFile("")]

View File

@@ -0,0 +1,20 @@
using System;
namespace MongoDB.Serialization.Descriptors
{
internal class BsonPropertyValue
{
public bool IsDictionary { get; private set; }
public Type Type { get; private set; }
public object Value { get; private set; }
public BsonPropertyValue(Type type, object value, bool isDictionary)
{
Type = type;
Value = value;
IsDictionary = isDictionary;
}
}
}

View File

@@ -0,0 +1,153 @@
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Linq.Expressions;
namespace MongoDB.Linq.Expressions
{
internal class MongoExpressionVisitor : ExpressionVisitor
{
protected override Expression Visit(Expression exp)
{
if (exp == null)
return null;
switch ((MongoExpressionType)exp.NodeType)
{
case MongoExpressionType.Collection:
return VisitCollection((CollectionExpression)exp);
case MongoExpressionType.Field:
return VisitField((FieldExpression)exp);
case MongoExpressionType.Projection:
return VisitProjection((ProjectionExpression)exp);
case MongoExpressionType.Select:
return VisitSelect((SelectExpression)exp);
case MongoExpressionType.Aggregate:
return VisitAggregate((AggregateExpression)exp);
case MongoExpressionType.AggregateSubquery:
return VisitAggregateSubquery((AggregateSubqueryExpression)exp);
case MongoExpressionType.Scalar:
return VisitScalar((ScalarExpression)exp);
default:
return base.Visit(exp);
}
}
protected virtual Expression VisitAggregate(AggregateExpression aggregate)
{
var exp = Visit(aggregate.Argument);
if (exp != aggregate.Argument)
return new AggregateExpression(aggregate.Type, aggregate.AggregateType, exp, aggregate.Distinct);
return aggregate;
}
protected virtual Expression VisitAggregateSubquery(AggregateSubqueryExpression aggregateSubquery)
{
Expression e = Visit(aggregateSubquery.AggregateAsSubquery);
ScalarExpression subquery = (ScalarExpression)e;
if (subquery != aggregateSubquery.AggregateAsSubquery)
return new AggregateSubqueryExpression(aggregateSubquery.GroupByAlias, aggregateSubquery.AggregateInGroupSelect, subquery);
return aggregateSubquery;
}
protected virtual Expression VisitCollection(CollectionExpression collection)
{
return collection;
}
protected virtual Expression VisitField(FieldExpression field)
{
var e = Visit(field.Expression);
if (field.Expression != e)
field = new FieldExpression(e, field.Alias, field.Name);
return field;
}
protected virtual Expression VisitProjection(ProjectionExpression projection)
{
var source = (SelectExpression)Visit(projection.Source);
var projector = Visit(projection.Projector);
if (source != projection.Source || projector != projection.Projector)
return new ProjectionExpression(source, projector, projection.Aggregator);
return projection;
}
protected ReadOnlyCollection<OrderExpression> VisitOrderBy(ReadOnlyCollection<OrderExpression> orderBys)
{
if (orderBys != null)
{
List<OrderExpression> alternate = null;
for (int i = 0, n = orderBys.Count; i < n; i++)
{
OrderExpression expr = orderBys[i];
Expression e = this.Visit(expr.Expression);
if (alternate == null && e != expr.Expression)
alternate = orderBys.Take(i).ToList();
if (alternate != null)
alternate.Add(new OrderExpression(expr.OrderType, e));
}
if (alternate != null)
return alternate.AsReadOnly();
}
return orderBys;
}
protected virtual Expression VisitScalar(ScalarExpression scalar)
{
SelectExpression select = (SelectExpression)Visit(scalar.Select);
if (select != scalar.Select)
return new ScalarExpression(scalar.Type, select);
return scalar;
}
protected virtual Expression VisitSelect(SelectExpression select)
{
var from = VisitSource(select.From);
var where = Visit(select.Where);
var groupBy = Visit(select.GroupBy);
var orderBy = VisitOrderBy(select.OrderBy);
var skip = Visit(select.Skip);
var take = Visit(select.Take);
var fields = VisitFieldDeclarationList(select.Fields);
if (from != select.From || where != select.Where || orderBy != select.OrderBy || groupBy != select.GroupBy || skip != select.Skip || take != select.Take || fields != select.Fields)
return new SelectExpression(select.Alias, fields, from, where, orderBy, groupBy, select.IsDistinct, skip, take);
return select;
}
protected virtual Expression VisitSource(Expression source)
{
return Visit(source);
}
protected virtual Expression VisitSubquery(SubqueryExpression subquery)
{
switch ((MongoExpressionType)subquery.NodeType)
{
case MongoExpressionType.Scalar:
return VisitScalar((ScalarExpression)subquery);
}
return subquery;
}
protected virtual ReadOnlyCollection<FieldDeclaration> VisitFieldDeclarationList(ReadOnlyCollection<FieldDeclaration> fields)
{
if (fields == null)
return fields;
List<FieldDeclaration> alternate = null;
for (int i = 0, n = fields.Count; i < n; i++)
{
var f = fields[i];
var e = Visit(f.Expression);
if (f.Expression != e && alternate == null)
alternate = fields.Take(i).ToList();
if (alternate != null)
alternate.Add(new FieldDeclaration(f.Name, e));
}
if (alternate != null)
return alternate.AsReadOnly();
return fields;
}
}
}

86
samples/C++/16F88.h Normal file
View File

@@ -0,0 +1,86 @@
/*
* This file is part of PIC
* Copyright © 2012 Rachel Mant (dx-mon@users.sourceforge.net)
*
* PIC is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* PIC is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
enum PIC16F88Instruction
{
ADDWF,
ANDWF,
CLRF,
CLRW,
COMF,
DECF,
DECFSZ,
INCF,
INCFSZ,
IORWF,
MOVF,
MOVWF,
NOP,
RLF,
RRF,
SUBWF,
SWAPF,
XORWF,
BCF,
BSF,
BTFSC,
BTFSS,
ADDLW,
ANDLW,
CALL,
CLRWDT,
GOTO,
IORLW,
MOVLW,
RETFIE,
RETLW,
RETURN,
SLEEP,
SUBLW,
XORLW
};
class PIC16F88
{
public:
PIC16F88(ROM *ProgramMemory);
void Step();
private:
uint8_t q;
bool nextIsNop, trapped;
Memory *memory;
ROM *program;
Stack<uint16_t, 8> *CallStack;
Register<uint16_t> *PC;
Register<> *WREG, *PCL, *STATUS, *PCLATCH;
PIC16F88Instruction inst;
uint16_t instrWord;
private:
void DecodeInstruction();
void ProcessInstruction();
uint8_t GetBank();
uint8_t GetMemoryContents(uint8_t partialAddress);
void SetMemoryContents(uint8_t partialAddress, uint8_t newVal);
void CheckZero(uint8_t value);
void StoreValue(uint8_t value, bool updateZero);
uint8_t SetCarry(bool val);
uint16_t GetPCHFinalBits();
};

98
samples/C++/Entity.h Normal file
View File

@@ -0,0 +1,98 @@
/**
* @file Entity.h
* @page EntityPage Entity
* @brief represent an entity in the game
* @author vinz243
* @version 0.1.0
* This file represents an Entity in the game system
* This parent type is a static entity which is shown and loaded into the Physics engine but never updated
*/
#ifndef ENTITY_H
#define ENTITY_H
#include "base.h"
/// @namespace Whitedrop
namespace Whitedrop {
/** @class Entity
* This parent type is a static entity which is shown and loaded into the Physics engine but never updated
*/
class Entity {
public:
/**
* @brief Create static entity
* @details creates a static entity instance according to the mesh and the id, the position
* This needs to be attached to a World after!
* The material name is not the file name but the material name!
* @ref WorldPage
* @param mesh the name of the mesh for the object, file must be in media/meshes
* @param id an unique identifier for the object, shortest as possible
* @param dimensions an Ogre::Vector3 which contains the dimensions in meter
* @param position the Vector3 which contains it position
* @param material the material name
*/
Entity(std::string mesh, std::string id, Ogre::Vector3 dimensions, Ogre::Vector3 position, std::string material);
/**
* @brief The copy constructor
* @details A copy constr
*
* @param ref the Entity to be copied from
*/
Entity(const Entity &ref);
/**
* @brief The assignement operator
* @details
*
* @param ent the entity to be copied
*/
Entity& operator=(const Entity ent);
/**
* @brief destrctor
* @details
*/
virtual ~Entity(void);
/**
* @brief a constance type of the entity
* @details depends of the class.
* May contain STATIC, DYNAMIC or ETHERAL
*/
const std::string type = "STATIC";
/**
* @brief Attach the entity to specified sceneManager
* @details This creates the OgreEntity using sceneMgr,
* set material, create a Node with name as `<id>_n`,
* scale it to match dimensions and translate the node to pos
* @param sceneMgr the scene manager to use
*/
virtual void setup(Ogre::SceneManager* sceneMgr);
/**
* @brief the update method
* @details this method should be called on each world update.
* Even though the method is necessary declared, the main impl of
* a static entity should be empty since it is not updated by physics
* However, a Dynamic entity should implement this function in order to:
* 1) Get from the physics engine the actor position in the physic world
* 2) Update the OgreEntity position and rotation from the previous actor
* @return whether it was successful or not, if falsey engine should stop
*/
virtual bool update(void);
protected:
std::string mMesh = "cube.mesh";
std::string mId;
std::string mMaterial;
Ogre::Vector3 mDimensions;
Ogre::Vector3 mPosition;
Ogre::Entity* mEntity;
Ogre::SceneNode* mNode;
};
}
#endif

32
samples/C++/Memory16F88.h Normal file
View File

@@ -0,0 +1,32 @@
/*
* This file is part of PIC
* Copyright © 2012 Rachel Mant (dx-mon@users.sourceforge.net)
*
* PIC is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* PIC is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "Memory.h"
class Memory16F88 : public Memory
{
private:
uint8_t memory[512];
std::map<uint32_t, MemoryLocation *> memoryMap;
public:
Memory16F88();
uint8_t Dereference(uint8_t bank, uint8_t partialAddress);
uint8_t *Reference(uint8_t bank, uint8_t partialAddress);
uint8_t *operator [](uint32_t ref);
};

View File

@@ -0,0 +1,76 @@
/*
* This file is part of IRCBot
* Copyright © 2014 Rachel Mant (dx-mon@users.sourceforge.net)
*
* IRCBot is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* IRCBot is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __THREADED_QUEUE_H__
#define __THREADED_QUEUE_H__
#include <pthread.h>
#include <queue>
template<class T>
class ThreadedQueue : public std::queue<T>
{
private:
pthread_mutex_t queueMutex;
pthread_cond_t queueCond;
public:
ThreadedQueue()
{
pthread_mutexattr_t mutexAttrs;
pthread_condattr_t condAttrs;
pthread_mutexattr_init(&mutexAttrs);
pthread_mutexattr_settype(&mutexAttrs, PTHREAD_MUTEX_ERRORCHECK);
pthread_mutex_init(&queueMutex, &mutexAttrs);
pthread_mutexattr_destroy(&mutexAttrs);
pthread_condattr_init(&condAttrs);
pthread_condattr_setpshared(&condAttrs, PTHREAD_PROCESS_PRIVATE);
pthread_cond_init(&queueCond, &condAttrs);
pthread_condattr_destroy(&condAttrs);
}
~ThreadedQueue()
{
pthread_cond_destroy(&queueCond);
pthread_mutex_destroy(&queueMutex);
}
void waitItems()
{
pthread_mutex_lock(&queueMutex);
pthread_cond_wait(&queueCond, &queueMutex);
pthread_mutex_unlock(&queueMutex);
}
void signalItems()
{
pthread_mutex_lock(&queueMutex);
pthread_cond_broadcast(&queueCond);
pthread_mutex_unlock(&queueMutex);
}
void push(T item)
{
std::queue<T>::push(item);
signalItems();
}
};
#endif /*__THREADED_QUEUE_H__*/

145
samples/C/2D.C Normal file
View File

@@ -0,0 +1,145 @@
#include "2D.h"
#include <math.h>
void set_vgabasemem(void)
{
ULONG vgabase;
SELECTOR tmp;
asm mov [tmp], ds
dpmi_get_sel_base(&vgabase, tmp);
vgabasemem = (char *)(-vgabase + 0xa0000);
}
void drw_chdis(int mode) // change the display!
{
regs.b.ah = 0x00; // seet theh display moode
regs.b.al = mode; // change it to the mode like innit
regs.h.flags = 0x72;// Set the dingoes kidneys out of FLAGS eh?
regs.h.ss = 0; // Like, totally set the stack segment
regs.h.sp = 0; // Set tha stack pointaaaaahhhhh!!!
dpmi_simulate_real_interrupt(0x10, &regs);
}
void drw_pix(int x, int y, enum COLORS col)
{
*VGAPIX(x, y) = col;
}
void drw_line(int x0, int y0, int x1, int y1, enum COLORS col)
{
// Going for the optimized version of bresenham's line algo.
int stp = (abs(y0 - y1) > abs(x0 - x1));
int tmp, dx, dy, err, yi, i, j; // yi = y excrement
if (stp) {
// swappity swap
tmp = y0;
y0 = x0;
x0 = tmp;
tmp = y1;
y1 = x1;
x1 = tmp;
}
// AAAAND NOW WE MUST DO ZEES AGAIN :(
// I'm sure there was a func somewhere that does this? :P
if (x0 > x1) {
tmp = x0;
x0 = x1;
x1 = tmp;
tmp = y0;
y0 = y1;
y1 = tmp;
}
dx = (x1 - x0);
dy = (abs(y1 - y0));
err = (dx / 2);
if (y0 < y1)
yi = 1;
else
yi = -1;
j = y0;
for (i = x0; i < x1; i++)
{
if (stp)
*VGAPIX(j, i) = col;
else
*VGAPIX(i, j) = col;
err -= dy;
if (err < 0) {
j += yi;
err += dx;
}
}
}
void drw_rectl(int x, int y, int w, int h, enum COLORS col)
{
drw_line(x, y, x+w, y, col);
drw_line(x+w, y, x+w, y+h, col);
drw_line(x, y, x, y+h, col);
drw_line(x, y+h, x+w+1, y+h, col);
}
void drw_rectf(int x, int y, int w, int h, enum COLORS col)
{
int i, j;
for (j = y; j < x+h; j++) {
for (i = x; i < y+w; i++) {
*VGAPIX(i, j) = col;
}
}
}
void drw_circl(int x, int y, int rad, enum COLORS col)
{
int mang, i; // max angle, haha
int px, py;
mang = 360; // Yeah yeah I'll switch to rad later
for (i = 0; i <= mang; i++)
{
px = cos(i)*rad + x; // + px; // causes some really cools effects! :D
py = sin(i)*rad + y; // + py;
*VGAPIX(px, py) = col;
}
}
void drw_tex(int x, int y, int w, int h, enum COLORS tex[])
{ // i*w+j
int i, j;
for (i = 0; i < w; i++)
{
for (j = 0; j < h; j++)
{
*VGAPIX(x+i, y+j) = tex[j*w+i];
}
}
}
void 2D_init(void)
{
set_vgabasemem();
drw_chdis(0x13);
}
void 2D_exit(void)
{
drw_chdis(3);
}
/*
int main()
{
set_vgabasemem();
drw_chdis(0x13);
while(!kbhit()) {
if ((getch()) == 0x1b) // escape
break;
}
drw_chdis(3);
return 0;
}
*/

29
samples/C/2D.H Normal file
View File

@@ -0,0 +1,29 @@
#ifndef __2DGFX
#define __2DGFX
// Includes
#include <stdio.h>
#include <math.h>
#include <conio.h>
#include <dpmi.h>
// Defines
#define VGAPIX(x,y) (vgabasemem + (x) + (y) * 320)
// Variables
char * vgabasemem;
DPMI_REGS regs;
// Drawing functions:
//void setvgabasemem(void);
void drw_chdis(int mode); // draw_func_change_display
void drw_pix(int x, int y, enum COLORS col);
void drw_line(int x0, int y0, int x1, int y1, enum COLORS col);
void drw_rectl(int x, int y, int w, int h, enum COLORS col);
void drw_rectf(int x, int y, int w, int h, enum COLORS col);
void drw_cirl(int x, int y, int rad, enum COLORS col);
void drw_tex(int x, int y, int w, int h, enum COLORS tex[]);
void 2D_init(void);
void 2D_exit(void);
#endif

93
samples/C/ArrowLeft.h Normal file
View File

@@ -0,0 +1,93 @@
/*
* This file is part of GTK++ (libGTK++)
* Copyright © 2012 Rachel Mant (dx-mon@users.sourceforge.net)
*
* GTK++ is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* GTK++ is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/* GdkPixbuf RGBA C-Source image dump */
#ifdef __SUNPRO_C
#pragma align 4 (ArrowLeft)
#endif
#ifdef __GNUC__
static const uint8_t ArrowLeft[] __attribute__ ((__aligned__ (4))) =
#else
static const uint8_t ArrowLeft[] =
#endif
{ ""
/* Pixbuf magic (0x47646b50) */
"GdkP"
/* length: header (24) + pixel_data (1600) */
"\0\0\6X"
/* pixdata_type (0x1010002) */
"\1\1\0\2"
/* rowstride (80) */
"\0\0\0P"
/* width (20) */
"\0\0\0\24"
/* height (20) */
"\0\0\0\24"
/* pixel_data: */
"\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
"\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
"\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
"\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
"\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
"\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
"\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
"\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
"\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
"\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
"\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\377\0\0\0\0\0"
"\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
"\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
"\0\0\377\0\0\0\377\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
"\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
"\0\0\0\0\0\0\0\0\0\0\0\0\377\0\0\0\377\0\0\0\377\0\0\0\0\0\0\0\0\0\0"
"\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
"\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\377\0\0\0\377\0\0\0\377"
"\0\0\0\377\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
"\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
"\377\0\0\0\377\0\0\0\377\0\0\0\377\0\0\0\377\0\0\0\0\0\0\0\0\0\0\0\0"
"\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
"\0\0\0\0\0\0\0\0\0\0\0\0\0\377\0\0\0\377\0\0\0\377\0\0\0\377\0\0\0\377"
"\0\0\0\377\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
"\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
"\377\0\0\0\377\0\0\0\377\0\0\0\377\0\0\0\377\0\0\0\0\0\0\0\0\0\0\0\0"
"\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
"\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\377\0\0\0\377\0\0\0\377\0"
"\0\0\377\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
"\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
"\0\0\0\0\0\0\0\377\0\0\0\377\0\0\0\377\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
"\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
"\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\377\0\0\0\377\0"
"\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
"\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
"\0\0\0\0\0\0\0\0\0\0\377\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
"\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
"\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
"\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
"\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
"\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
"\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
"\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
"\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
"\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
"\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
"\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
"\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
"\0\0"};

903
samples/C/GLKMatrix4.h Normal file
View File

@@ -0,0 +1,903 @@
//
// GLKMatrix4.h
// GLKit
//
// Copyright (c) 2011, Apple Inc. All rights reserved.
//
#ifndef __GLK_MATRIX_4_H
#define __GLK_MATRIX_4_H
#include <stddef.h>
#include <stdbool.h>
#include <math.h>
#if defined(__ARM_NEON__)
#include <arm_neon.h>
#endif
#include <GLKit/GLKMathTypes.h>
#include <GLKit/GLKVector3.h>
#include <GLKit/GLKVector4.h>
#include <GLKit/GLKQuaternion.h>
#ifdef __cplusplus
extern "C" {
#endif
#pragma mark -
#pragma mark Prototypes
#pragma mark -
extern const GLKMatrix4 GLKMatrix4Identity;
/*
m30, m31, and m32 correspond to the translation values tx, ty, tz, respectively.
*/
static __inline__ GLKMatrix4 GLKMatrix4Make(float m00, float m01, float m02, float m03,
float m10, float m11, float m12, float m13,
float m20, float m21, float m22, float m23,
float m30, float m31, float m32, float m33);
/*
m03, m13, and m23 correspond to the translation values tx, ty, tz, respectively.
*/
static __inline__ GLKMatrix4 GLKMatrix4MakeAndTranspose(float m00, float m01, float m02, float m03,
float m10, float m11, float m12, float m13,
float m20, float m21, float m22, float m23,
float m30, float m31, float m32, float m33);
/*
m[12], m[13], and m[14] correspond to the translation values tx, ty, and tz, respectively.
*/
static __inline__ GLKMatrix4 GLKMatrix4MakeWithArray(float values[16]);
/*
m[3], m[7], and m[11] correspond to the translation values tx, ty, and tz, respectively.
*/
static __inline__ GLKMatrix4 GLKMatrix4MakeWithArrayAndTranspose(float values[16]);
/*
row0, row1, and row2's last component should correspond to the translation values tx, ty, and tz, respectively.
*/
static __inline__ GLKMatrix4 GLKMatrix4MakeWithRows(GLKVector4 row0,
GLKVector4 row1,
GLKVector4 row2,
GLKVector4 row3);
/*
column3's first three components should correspond to the translation values tx, ty, and tz.
*/
static __inline__ GLKMatrix4 GLKMatrix4MakeWithColumns(GLKVector4 column0,
GLKVector4 column1,
GLKVector4 column2,
GLKVector4 column3);
/*
The quaternion will be normalized before conversion.
*/
static __inline__ GLKMatrix4 GLKMatrix4MakeWithQuaternion(GLKQuaternion quaternion);
static __inline__ GLKMatrix4 GLKMatrix4MakeTranslation(float tx, float ty, float tz);
static __inline__ GLKMatrix4 GLKMatrix4MakeScale(float sx, float sy, float sz);
static __inline__ GLKMatrix4 GLKMatrix4MakeRotation(float radians, float x, float y, float z);
static __inline__ GLKMatrix4 GLKMatrix4MakeXRotation(float radians);
static __inline__ GLKMatrix4 GLKMatrix4MakeYRotation(float radians);
static __inline__ GLKMatrix4 GLKMatrix4MakeZRotation(float radians);
/*
Equivalent to gluPerspective.
*/
static __inline__ GLKMatrix4 GLKMatrix4MakePerspective(float fovyRadians, float aspect, float nearZ, float farZ);
/*
Equivalent to glFrustum.
*/
static __inline__ GLKMatrix4 GLKMatrix4MakeFrustum(float left, float right,
float bottom, float top,
float nearZ, float farZ);
/*
Equivalent to glOrtho.
*/
static __inline__ GLKMatrix4 GLKMatrix4MakeOrtho(float left, float right,
float bottom, float top,
float nearZ, float farZ);
/*
Equivalent to gluLookAt.
*/
static __inline__ GLKMatrix4 GLKMatrix4MakeLookAt(float eyeX, float eyeY, float eyeZ,
float centerX, float centerY, float centerZ,
float upX, float upY, float upZ);
/*
Returns the upper left 3x3 portion of the 4x4 matrix.
*/
static __inline__ GLKMatrix3 GLKMatrix4GetMatrix3(GLKMatrix4 matrix);
/*
Returns the upper left 2x2 portion of the 4x4 matrix.
*/
static __inline__ GLKMatrix2 GLKMatrix4GetMatrix2(GLKMatrix4 matrix);
/*
GLKMatrix4GetRow returns vectors for rows 0, 1, and 2 whose last component will be the translation value tx, ty, and tz, respectively.
Valid row values range from 0 to 3, inclusive.
*/
static __inline__ GLKVector4 GLKMatrix4GetRow(GLKMatrix4 matrix, int row);
/*
GLKMatrix4GetColumn returns a vector for column 3 whose first three components will be the translation values tx, ty, and tz.
Valid column values range from 0 to 3, inclusive.
*/
static __inline__ GLKVector4 GLKMatrix4GetColumn(GLKMatrix4 matrix, int column);
/*
GLKMatrix4SetRow expects that the vector for row 0, 1, and 2 will have a translation value as its last component.
Valid row values range from 0 to 3, inclusive.
*/
static __inline__ GLKMatrix4 GLKMatrix4SetRow(GLKMatrix4 matrix, int row, GLKVector4 vector);
/*
GLKMatrix4SetColumn expects that the vector for column 3 will contain the translation values tx, ty, and tz as its first three components, respectively.
Valid column values range from 0 to 3, inclusive.
*/
static __inline__ GLKMatrix4 GLKMatrix4SetColumn(GLKMatrix4 matrix, int column, GLKVector4 vector);
static __inline__ GLKMatrix4 GLKMatrix4Transpose(GLKMatrix4 matrix);
GLKMatrix4 GLKMatrix4Invert(GLKMatrix4 matrix, bool *isInvertible);
GLKMatrix4 GLKMatrix4InvertAndTranspose(GLKMatrix4 matrix, bool *isInvertible);
static __inline__ GLKMatrix4 GLKMatrix4Multiply(GLKMatrix4 matrixLeft, GLKMatrix4 matrixRight);
static __inline__ GLKMatrix4 GLKMatrix4Add(GLKMatrix4 matrixLeft, GLKMatrix4 matrixRight);
static __inline__ GLKMatrix4 GLKMatrix4Subtract(GLKMatrix4 matrixLeft, GLKMatrix4 matrixRight);
static __inline__ GLKMatrix4 GLKMatrix4Translate(GLKMatrix4 matrix, float tx, float ty, float tz);
static __inline__ GLKMatrix4 GLKMatrix4TranslateWithVector3(GLKMatrix4 matrix, GLKVector3 translationVector);
/*
The last component of the GLKVector4, translationVector, is ignored.
*/
static __inline__ GLKMatrix4 GLKMatrix4TranslateWithVector4(GLKMatrix4 matrix, GLKVector4 translationVector);
static __inline__ GLKMatrix4 GLKMatrix4Scale(GLKMatrix4 matrix, float sx, float sy, float sz);
static __inline__ GLKMatrix4 GLKMatrix4ScaleWithVector3(GLKMatrix4 matrix, GLKVector3 scaleVector);
/*
The last component of the GLKVector4, scaleVector, is ignored.
*/
static __inline__ GLKMatrix4 GLKMatrix4ScaleWithVector4(GLKMatrix4 matrix, GLKVector4 scaleVector);
static __inline__ GLKMatrix4 GLKMatrix4Rotate(GLKMatrix4 matrix, float radians, float x, float y, float z);
static __inline__ GLKMatrix4 GLKMatrix4RotateWithVector3(GLKMatrix4 matrix, float radians, GLKVector3 axisVector);
/*
The last component of the GLKVector4, axisVector, is ignored.
*/
static __inline__ GLKMatrix4 GLKMatrix4RotateWithVector4(GLKMatrix4 matrix, float radians, GLKVector4 axisVector);
static __inline__ GLKMatrix4 GLKMatrix4RotateX(GLKMatrix4 matrix, float radians);
static __inline__ GLKMatrix4 GLKMatrix4RotateY(GLKMatrix4 matrix, float radians);
static __inline__ GLKMatrix4 GLKMatrix4RotateZ(GLKMatrix4 matrix, float radians);
/*
Assumes 0 in the w component.
*/
static __inline__ GLKVector3 GLKMatrix4MultiplyVector3(GLKMatrix4 matrixLeft, GLKVector3 vectorRight);
/*
Assumes 1 in the w component.
*/
static __inline__ GLKVector3 GLKMatrix4MultiplyVector3WithTranslation(GLKMatrix4 matrixLeft, GLKVector3 vectorRight);
/*
Assumes 1 in the w component and divides the resulting vector by w before returning.
*/
static __inline__ GLKVector3 GLKMatrix4MultiplyAndProjectVector3(GLKMatrix4 matrixLeft, GLKVector3 vectorRight);
/*
Assumes 0 in the w component.
*/
static __inline__ void GLKMatrix4MultiplyVector3Array(GLKMatrix4 matrix, GLKVector3 *vectors, size_t vectorCount);
/*
Assumes 1 in the w component.
*/
static __inline__ void GLKMatrix4MultiplyVector3ArrayWithTranslation(GLKMatrix4 matrix, GLKVector3 *vectors, size_t vectorCount);
/*
Assumes 1 in the w component and divides the resulting vector by w before returning.
*/
static __inline__ void GLKMatrix4MultiplyAndProjectVector3Array(GLKMatrix4 matrix, GLKVector3 *vectors, size_t vectorCount);
static __inline__ GLKVector4 GLKMatrix4MultiplyVector4(GLKMatrix4 matrixLeft, GLKVector4 vectorRight);
static __inline__ void GLKMatrix4MultiplyVector4Array(GLKMatrix4 matrix, GLKVector4 *vectors, size_t vectorCount);
#pragma mark -
#pragma mark Implementations
#pragma mark -
static __inline__ GLKMatrix4 GLKMatrix4Make(float m00, float m01, float m02, float m03,
float m10, float m11, float m12, float m13,
float m20, float m21, float m22, float m23,
float m30, float m31, float m32, float m33)
{
GLKMatrix4 m = { m00, m01, m02, m03,
m10, m11, m12, m13,
m20, m21, m22, m23,
m30, m31, m32, m33 };
return m;
}
static __inline__ GLKMatrix4 GLKMatrix4MakeAndTranspose(float m00, float m01, float m02, float m03,
float m10, float m11, float m12, float m13,
float m20, float m21, float m22, float m23,
float m30, float m31, float m32, float m33)
{
GLKMatrix4 m = { m00, m10, m20, m30,
m01, m11, m21, m31,
m02, m12, m22, m32,
m03, m13, m23, m33 };
return m;
}
static __inline__ GLKMatrix4 GLKMatrix4MakeWithArray(float values[16])
{
GLKMatrix4 m = { values[0], values[1], values[2], values[3],
values[4], values[5], values[6], values[7],
values[8], values[9], values[10], values[11],
values[12], values[13], values[14], values[15] };
return m;
}
static __inline__ GLKMatrix4 GLKMatrix4MakeWithArrayAndTranspose(float values[16])
{
#if defined(__ARM_NEON__)
float32x4x4_t m = vld4q_f32(values);
return *(GLKMatrix4 *)&m;
#else
GLKMatrix4 m = { values[0], values[4], values[8], values[12],
values[1], values[5], values[9], values[13],
values[2], values[6], values[10], values[14],
values[3], values[7], values[11], values[15] };
return m;
#endif
}
static __inline__ GLKMatrix4 GLKMatrix4MakeWithRows(GLKVector4 row0,
GLKVector4 row1,
GLKVector4 row2,
GLKVector4 row3)
{
GLKMatrix4 m = { row0.v[0], row1.v[0], row2.v[0], row3.v[0],
row0.v[1], row1.v[1], row2.v[1], row3.v[1],
row0.v[2], row1.v[2], row2.v[2], row3.v[2],
row0.v[3], row1.v[3], row2.v[3], row3.v[3] };
return m;
}
static __inline__ GLKMatrix4 GLKMatrix4MakeWithColumns(GLKVector4 column0,
GLKVector4 column1,
GLKVector4 column2,
GLKVector4 column3)
{
#if defined(__ARM_NEON__)
float32x4x4_t m;
m.val[0] = vld1q_f32(column0.v);
m.val[1] = vld1q_f32(column1.v);
m.val[2] = vld1q_f32(column2.v);
m.val[3] = vld1q_f32(column3.v);
return *(GLKMatrix4 *)&m;
#else
GLKMatrix4 m = { column0.v[0], column0.v[1], column0.v[2], column0.v[3],
column1.v[0], column1.v[1], column1.v[2], column1.v[3],
column2.v[0], column2.v[1], column2.v[2], column2.v[3],
column3.v[0], column3.v[1], column3.v[2], column3.v[3] };
return m;
#endif
}
static __inline__ GLKMatrix4 GLKMatrix4MakeWithQuaternion(GLKQuaternion quaternion)
{
quaternion = GLKQuaternionNormalize(quaternion);
float x = quaternion.q[0];
float y = quaternion.q[1];
float z = quaternion.q[2];
float w = quaternion.q[3];
float _2x = x + x;
float _2y = y + y;
float _2z = z + z;
float _2w = w + w;
GLKMatrix4 m = { 1.0f - _2y * y - _2z * z,
_2x * y + _2w * z,
_2x * z - _2w * y,
0.0f,
_2x * y - _2w * z,
1.0f - _2x * x - _2z * z,
_2y * z + _2w * x,
0.0f,
_2x * z + _2w * y,
_2y * z - _2w * x,
1.0f - _2x * x - _2y * y,
0.0f,
0.0f,
0.0f,
0.0f,
1.0f };
return m;
}
static __inline__ GLKMatrix4 GLKMatrix4MakeTranslation(float tx, float ty, float tz)
{
GLKMatrix4 m = GLKMatrix4Identity;
m.m[12] = tx;
m.m[13] = ty;
m.m[14] = tz;
return m;
}
static __inline__ GLKMatrix4 GLKMatrix4MakeScale(float sx, float sy, float sz)
{
GLKMatrix4 m = GLKMatrix4Identity;
m.m[0] = sx;
m.m[5] = sy;
m.m[10] = sz;
return m;
}
static __inline__ GLKMatrix4 GLKMatrix4MakeRotation(float radians, float x, float y, float z)
{
GLKVector3 v = GLKVector3Normalize(GLKVector3Make(x, y, z));
float cos = cosf(radians);
float cosp = 1.0f - cos;
float sin = sinf(radians);
GLKMatrix4 m = { cos + cosp * v.v[0] * v.v[0],
cosp * v.v[0] * v.v[1] + v.v[2] * sin,
cosp * v.v[0] * v.v[2] - v.v[1] * sin,
0.0f,
cosp * v.v[0] * v.v[1] - v.v[2] * sin,
cos + cosp * v.v[1] * v.v[1],
cosp * v.v[1] * v.v[2] + v.v[0] * sin,
0.0f,
cosp * v.v[0] * v.v[2] + v.v[1] * sin,
cosp * v.v[1] * v.v[2] - v.v[0] * sin,
cos + cosp * v.v[2] * v.v[2],
0.0f,
0.0f,
0.0f,
0.0f,
1.0f };
return m;
}
static __inline__ GLKMatrix4 GLKMatrix4MakeXRotation(float radians)
{
float cos = cosf(radians);
float sin = sinf(radians);
GLKMatrix4 m = { 1.0f, 0.0f, 0.0f, 0.0f,
0.0f, cos, sin, 0.0f,
0.0f, -sin, cos, 0.0f,
0.0f, 0.0f, 0.0f, 1.0f };
return m;
}
static __inline__ GLKMatrix4 GLKMatrix4MakeYRotation(float radians)
{
float cos = cosf(radians);
float sin = sinf(radians);
GLKMatrix4 m = { cos, 0.0f, -sin, 0.0f,
0.0f, 1.0f, 0.0f, 0.0f,
sin, 0.0f, cos, 0.0f,
0.0f, 0.0f, 0.0f, 1.0f };
return m;
}
static __inline__ GLKMatrix4 GLKMatrix4MakeZRotation(float radians)
{
float cos = cosf(radians);
float sin = sinf(radians);
GLKMatrix4 m = { cos, sin, 0.0f, 0.0f,
-sin, cos, 0.0f, 0.0f,
0.0f, 0.0f, 1.0f, 0.0f,
0.0f, 0.0f, 0.0f, 1.0f };
return m;
}
static __inline__ GLKMatrix4 GLKMatrix4MakePerspective(float fovyRadians, float aspect, float nearZ, float farZ)
{
float cotan = 1.0f / tanf(fovyRadians / 2.0f);
GLKMatrix4 m = { cotan / aspect, 0.0f, 0.0f, 0.0f,
0.0f, cotan, 0.0f, 0.0f,
0.0f, 0.0f, (farZ + nearZ) / (nearZ - farZ), -1.0f,
0.0f, 0.0f, (2.0f * farZ * nearZ) / (nearZ - farZ), 0.0f };
return m;
}
static __inline__ GLKMatrix4 GLKMatrix4MakeFrustum(float left, float right,
float bottom, float top,
float nearZ, float farZ)
{
float ral = right + left;
float rsl = right - left;
float tsb = top - bottom;
float tab = top + bottom;
float fan = farZ + nearZ;
float fsn = farZ - nearZ;
GLKMatrix4 m = { 2.0f * nearZ / rsl, 0.0f, 0.0f, 0.0f,
0.0f, 2.0f * nearZ / tsb, 0.0f, 0.0f,
ral / rsl, tab / tsb, -fan / fsn, -1.0f,
0.0f, 0.0f, (-2.0f * farZ * nearZ) / fsn, 0.0f };
return m;
}
static __inline__ GLKMatrix4 GLKMatrix4MakeOrtho(float left, float right,
float bottom, float top,
float nearZ, float farZ)
{
float ral = right + left;
float rsl = right - left;
float tab = top + bottom;
float tsb = top - bottom;
float fan = farZ + nearZ;
float fsn = farZ - nearZ;
GLKMatrix4 m = { 2.0f / rsl, 0.0f, 0.0f, 0.0f,
0.0f, 2.0f / tsb, 0.0f, 0.0f,
0.0f, 0.0f, -2.0f / fsn, 0.0f,
-ral / rsl, -tab / tsb, -fan / fsn, 1.0f };
return m;
}
static __inline__ GLKMatrix4 GLKMatrix4MakeLookAt(float eyeX, float eyeY, float eyeZ,
float centerX, float centerY, float centerZ,
float upX, float upY, float upZ)
{
GLKVector3 ev = { eyeX, eyeY, eyeZ };
GLKVector3 cv = { centerX, centerY, centerZ };
GLKVector3 uv = { upX, upY, upZ };
GLKVector3 n = GLKVector3Normalize(GLKVector3Add(ev, GLKVector3Negate(cv)));
GLKVector3 u = GLKVector3Normalize(GLKVector3CrossProduct(uv, n));
GLKVector3 v = GLKVector3CrossProduct(n, u);
GLKMatrix4 m = { u.v[0], v.v[0], n.v[0], 0.0f,
u.v[1], v.v[1], n.v[1], 0.0f,
u.v[2], v.v[2], n.v[2], 0.0f,
GLKVector3DotProduct(GLKVector3Negate(u), ev),
GLKVector3DotProduct(GLKVector3Negate(v), ev),
GLKVector3DotProduct(GLKVector3Negate(n), ev),
1.0f };
return m;
}
static __inline__ GLKMatrix3 GLKMatrix4GetMatrix3(GLKMatrix4 matrix)
{
GLKMatrix3 m = { matrix.m[0], matrix.m[1], matrix.m[2],
matrix.m[4], matrix.m[5], matrix.m[6],
matrix.m[8], matrix.m[9], matrix.m[10] };
return m;
}
static __inline__ GLKMatrix2 GLKMatrix4GetMatrix2(GLKMatrix4 matrix)
{
GLKMatrix2 m = { matrix.m[0], matrix.m[1],
matrix.m[4], matrix.m[5] };
return m;
}
static __inline__ GLKVector4 GLKMatrix4GetRow(GLKMatrix4 matrix, int row)
{
GLKVector4 v = { matrix.m[row], matrix.m[4 + row], matrix.m[8 + row], matrix.m[12 + row] };
return v;
}
static __inline__ GLKVector4 GLKMatrix4GetColumn(GLKMatrix4 matrix, int column)
{
#if defined(__ARM_NEON__)
float32x4_t v = vld1q_f32(&(matrix.m[column * 4]));
return *(GLKVector4 *)&v;
#else
GLKVector4 v = { matrix.m[column * 4 + 0], matrix.m[column * 4 + 1], matrix.m[column * 4 + 2], matrix.m[column * 4 + 3] };
return v;
#endif
}
static __inline__ GLKMatrix4 GLKMatrix4SetRow(GLKMatrix4 matrix, int row, GLKVector4 vector)
{
matrix.m[row] = vector.v[0];
matrix.m[row + 4] = vector.v[1];
matrix.m[row + 8] = vector.v[2];
matrix.m[row + 12] = vector.v[3];
return matrix;
}
static __inline__ GLKMatrix4 GLKMatrix4SetColumn(GLKMatrix4 matrix, int column, GLKVector4 vector)
{
#if defined(__ARM_NEON__)
float *dst = &(matrix.m[column * 4]);
vst1q_f32(dst, vld1q_f32(vector.v));
return matrix;
#else
matrix.m[column * 4 + 0] = vector.v[0];
matrix.m[column * 4 + 1] = vector.v[1];
matrix.m[column * 4 + 2] = vector.v[2];
matrix.m[column * 4 + 3] = vector.v[3];
return matrix;
#endif
}
static __inline__ GLKMatrix4 GLKMatrix4Transpose(GLKMatrix4 matrix)
{
#if defined(__ARM_NEON__)
float32x4x4_t m = vld4q_f32(matrix.m);
return *(GLKMatrix4 *)&m;
#else
GLKMatrix4 m = { matrix.m[0], matrix.m[4], matrix.m[8], matrix.m[12],
matrix.m[1], matrix.m[5], matrix.m[9], matrix.m[13],
matrix.m[2], matrix.m[6], matrix.m[10], matrix.m[14],
matrix.m[3], matrix.m[7], matrix.m[11], matrix.m[15] };
return m;
#endif
}
static __inline__ GLKMatrix4 GLKMatrix4Multiply(GLKMatrix4 matrixLeft, GLKMatrix4 matrixRight)
{
#if defined(__ARM_NEON__)
float32x4x4_t iMatrixLeft = *(float32x4x4_t *)&matrixLeft;
float32x4x4_t iMatrixRight = *(float32x4x4_t *)&matrixRight;
float32x4x4_t m;
m.val[0] = vmulq_n_f32(iMatrixLeft.val[0], vgetq_lane_f32(iMatrixRight.val[0], 0));
m.val[1] = vmulq_n_f32(iMatrixLeft.val[0], vgetq_lane_f32(iMatrixRight.val[1], 0));
m.val[2] = vmulq_n_f32(iMatrixLeft.val[0], vgetq_lane_f32(iMatrixRight.val[2], 0));
m.val[3] = vmulq_n_f32(iMatrixLeft.val[0], vgetq_lane_f32(iMatrixRight.val[3], 0));
m.val[0] = vmlaq_n_f32(m.val[0], iMatrixLeft.val[1], vgetq_lane_f32(iMatrixRight.val[0], 1));
m.val[1] = vmlaq_n_f32(m.val[1], iMatrixLeft.val[1], vgetq_lane_f32(iMatrixRight.val[1], 1));
m.val[2] = vmlaq_n_f32(m.val[2], iMatrixLeft.val[1], vgetq_lane_f32(iMatrixRight.val[2], 1));
m.val[3] = vmlaq_n_f32(m.val[3], iMatrixLeft.val[1], vgetq_lane_f32(iMatrixRight.val[3], 1));
m.val[0] = vmlaq_n_f32(m.val[0], iMatrixLeft.val[2], vgetq_lane_f32(iMatrixRight.val[0], 2));
m.val[1] = vmlaq_n_f32(m.val[1], iMatrixLeft.val[2], vgetq_lane_f32(iMatrixRight.val[1], 2));
m.val[2] = vmlaq_n_f32(m.val[2], iMatrixLeft.val[2], vgetq_lane_f32(iMatrixRight.val[2], 2));
m.val[3] = vmlaq_n_f32(m.val[3], iMatrixLeft.val[2], vgetq_lane_f32(iMatrixRight.val[3], 2));
m.val[0] = vmlaq_n_f32(m.val[0], iMatrixLeft.val[3], vgetq_lane_f32(iMatrixRight.val[0], 3));
m.val[1] = vmlaq_n_f32(m.val[1], iMatrixLeft.val[3], vgetq_lane_f32(iMatrixRight.val[1], 3));
m.val[2] = vmlaq_n_f32(m.val[2], iMatrixLeft.val[3], vgetq_lane_f32(iMatrixRight.val[2], 3));
m.val[3] = vmlaq_n_f32(m.val[3], iMatrixLeft.val[3], vgetq_lane_f32(iMatrixRight.val[3], 3));
return *(GLKMatrix4 *)&m;
#else
GLKMatrix4 m;
m.m[0] = matrixLeft.m[0] * matrixRight.m[0] + matrixLeft.m[4] * matrixRight.m[1] + matrixLeft.m[8] * matrixRight.m[2] + matrixLeft.m[12] * matrixRight.m[3];
m.m[4] = matrixLeft.m[0] * matrixRight.m[4] + matrixLeft.m[4] * matrixRight.m[5] + matrixLeft.m[8] * matrixRight.m[6] + matrixLeft.m[12] * matrixRight.m[7];
m.m[8] = matrixLeft.m[0] * matrixRight.m[8] + matrixLeft.m[4] * matrixRight.m[9] + matrixLeft.m[8] * matrixRight.m[10] + matrixLeft.m[12] * matrixRight.m[11];
m.m[12] = matrixLeft.m[0] * matrixRight.m[12] + matrixLeft.m[4] * matrixRight.m[13] + matrixLeft.m[8] * matrixRight.m[14] + matrixLeft.m[12] * matrixRight.m[15];
m.m[1] = matrixLeft.m[1] * matrixRight.m[0] + matrixLeft.m[5] * matrixRight.m[1] + matrixLeft.m[9] * matrixRight.m[2] + matrixLeft.m[13] * matrixRight.m[3];
m.m[5] = matrixLeft.m[1] * matrixRight.m[4] + matrixLeft.m[5] * matrixRight.m[5] + matrixLeft.m[9] * matrixRight.m[6] + matrixLeft.m[13] * matrixRight.m[7];
m.m[9] = matrixLeft.m[1] * matrixRight.m[8] + matrixLeft.m[5] * matrixRight.m[9] + matrixLeft.m[9] * matrixRight.m[10] + matrixLeft.m[13] * matrixRight.m[11];
m.m[13] = matrixLeft.m[1] * matrixRight.m[12] + matrixLeft.m[5] * matrixRight.m[13] + matrixLeft.m[9] * matrixRight.m[14] + matrixLeft.m[13] * matrixRight.m[15];
m.m[2] = matrixLeft.m[2] * matrixRight.m[0] + matrixLeft.m[6] * matrixRight.m[1] + matrixLeft.m[10] * matrixRight.m[2] + matrixLeft.m[14] * matrixRight.m[3];
m.m[6] = matrixLeft.m[2] * matrixRight.m[4] + matrixLeft.m[6] * matrixRight.m[5] + matrixLeft.m[10] * matrixRight.m[6] + matrixLeft.m[14] * matrixRight.m[7];
m.m[10] = matrixLeft.m[2] * matrixRight.m[8] + matrixLeft.m[6] * matrixRight.m[9] + matrixLeft.m[10] * matrixRight.m[10] + matrixLeft.m[14] * matrixRight.m[11];
m.m[14] = matrixLeft.m[2] * matrixRight.m[12] + matrixLeft.m[6] * matrixRight.m[13] + matrixLeft.m[10] * matrixRight.m[14] + matrixLeft.m[14] * matrixRight.m[15];
m.m[3] = matrixLeft.m[3] * matrixRight.m[0] + matrixLeft.m[7] * matrixRight.m[1] + matrixLeft.m[11] * matrixRight.m[2] + matrixLeft.m[15] * matrixRight.m[3];
m.m[7] = matrixLeft.m[3] * matrixRight.m[4] + matrixLeft.m[7] * matrixRight.m[5] + matrixLeft.m[11] * matrixRight.m[6] + matrixLeft.m[15] * matrixRight.m[7];
m.m[11] = matrixLeft.m[3] * matrixRight.m[8] + matrixLeft.m[7] * matrixRight.m[9] + matrixLeft.m[11] * matrixRight.m[10] + matrixLeft.m[15] * matrixRight.m[11];
m.m[15] = matrixLeft.m[3] * matrixRight.m[12] + matrixLeft.m[7] * matrixRight.m[13] + matrixLeft.m[11] * matrixRight.m[14] + matrixLeft.m[15] * matrixRight.m[15];
return m;
#endif
}
static __inline__ GLKMatrix4 GLKMatrix4Add(GLKMatrix4 matrixLeft, GLKMatrix4 matrixRight)
{
#if defined(__ARM_NEON__)
float32x4x4_t iMatrixLeft = *(float32x4x4_t *)&matrixLeft;
float32x4x4_t iMatrixRight = *(float32x4x4_t *)&matrixRight;
float32x4x4_t m;
m.val[0] = vaddq_f32(iMatrixLeft.val[0], iMatrixRight.val[0]);
m.val[1] = vaddq_f32(iMatrixLeft.val[1], iMatrixRight.val[1]);
m.val[2] = vaddq_f32(iMatrixLeft.val[2], iMatrixRight.val[2]);
m.val[3] = vaddq_f32(iMatrixLeft.val[3], iMatrixRight.val[3]);
return *(GLKMatrix4 *)&m;
#else
GLKMatrix4 m;
m.m[0] = matrixLeft.m[0] + matrixRight.m[0];
m.m[1] = matrixLeft.m[1] + matrixRight.m[1];
m.m[2] = matrixLeft.m[2] + matrixRight.m[2];
m.m[3] = matrixLeft.m[3] + matrixRight.m[3];
m.m[4] = matrixLeft.m[4] + matrixRight.m[4];
m.m[5] = matrixLeft.m[5] + matrixRight.m[5];
m.m[6] = matrixLeft.m[6] + matrixRight.m[6];
m.m[7] = matrixLeft.m[7] + matrixRight.m[7];
m.m[8] = matrixLeft.m[8] + matrixRight.m[8];
m.m[9] = matrixLeft.m[9] + matrixRight.m[9];
m.m[10] = matrixLeft.m[10] + matrixRight.m[10];
m.m[11] = matrixLeft.m[11] + matrixRight.m[11];
m.m[12] = matrixLeft.m[12] + matrixRight.m[12];
m.m[13] = matrixLeft.m[13] + matrixRight.m[13];
m.m[14] = matrixLeft.m[14] + matrixRight.m[14];
m.m[15] = matrixLeft.m[15] + matrixRight.m[15];
return m;
#endif
}
static __inline__ GLKMatrix4 GLKMatrix4Subtract(GLKMatrix4 matrixLeft, GLKMatrix4 matrixRight)
{
#if defined(__ARM_NEON__)
float32x4x4_t iMatrixLeft = *(float32x4x4_t *)&matrixLeft;
float32x4x4_t iMatrixRight = *(float32x4x4_t *)&matrixRight;
float32x4x4_t m;
m.val[0] = vsubq_f32(iMatrixLeft.val[0], iMatrixRight.val[0]);
m.val[1] = vsubq_f32(iMatrixLeft.val[1], iMatrixRight.val[1]);
m.val[2] = vsubq_f32(iMatrixLeft.val[2], iMatrixRight.val[2]);
m.val[3] = vsubq_f32(iMatrixLeft.val[3], iMatrixRight.val[3]);
return *(GLKMatrix4 *)&m;
#else
GLKMatrix4 m;
m.m[0] = matrixLeft.m[0] - matrixRight.m[0];
m.m[1] = matrixLeft.m[1] - matrixRight.m[1];
m.m[2] = matrixLeft.m[2] - matrixRight.m[2];
m.m[3] = matrixLeft.m[3] - matrixRight.m[3];
m.m[4] = matrixLeft.m[4] - matrixRight.m[4];
m.m[5] = matrixLeft.m[5] - matrixRight.m[5];
m.m[6] = matrixLeft.m[6] - matrixRight.m[6];
m.m[7] = matrixLeft.m[7] - matrixRight.m[7];
m.m[8] = matrixLeft.m[8] - matrixRight.m[8];
m.m[9] = matrixLeft.m[9] - matrixRight.m[9];
m.m[10] = matrixLeft.m[10] - matrixRight.m[10];
m.m[11] = matrixLeft.m[11] - matrixRight.m[11];
m.m[12] = matrixLeft.m[12] - matrixRight.m[12];
m.m[13] = matrixLeft.m[13] - matrixRight.m[13];
m.m[14] = matrixLeft.m[14] - matrixRight.m[14];
m.m[15] = matrixLeft.m[15] - matrixRight.m[15];
return m;
#endif
}
static __inline__ GLKMatrix4 GLKMatrix4Translate(GLKMatrix4 matrix, float tx, float ty, float tz)
{
GLKMatrix4 m = { matrix.m[0], matrix.m[1], matrix.m[2], matrix.m[3],
matrix.m[4], matrix.m[5], matrix.m[6], matrix.m[7],
matrix.m[8], matrix.m[9], matrix.m[10], matrix.m[11],
matrix.m[0] * tx + matrix.m[4] * ty + matrix.m[8] * tz + matrix.m[12],
matrix.m[1] * tx + matrix.m[5] * ty + matrix.m[9] * tz + matrix.m[13],
matrix.m[2] * tx + matrix.m[6] * ty + matrix.m[10] * tz + matrix.m[14],
matrix.m[15] };
return m;
}
static __inline__ GLKMatrix4 GLKMatrix4TranslateWithVector3(GLKMatrix4 matrix, GLKVector3 translationVector)
{
GLKMatrix4 m = { matrix.m[0], matrix.m[1], matrix.m[2], matrix.m[3],
matrix.m[4], matrix.m[5], matrix.m[6], matrix.m[7],
matrix.m[8], matrix.m[9], matrix.m[10], matrix.m[11],
matrix.m[0] * translationVector.v[0] + matrix.m[4] * translationVector.v[1] + matrix.m[8] * translationVector.v[2] + matrix.m[12],
matrix.m[1] * translationVector.v[0] + matrix.m[5] * translationVector.v[1] + matrix.m[9] * translationVector.v[2] + matrix.m[13],
matrix.m[2] * translationVector.v[0] + matrix.m[6] * translationVector.v[1] + matrix.m[10] * translationVector.v[2] + matrix.m[14],
matrix.m[15] };
return m;
}
static __inline__ GLKMatrix4 GLKMatrix4TranslateWithVector4(GLKMatrix4 matrix, GLKVector4 translationVector)
{
GLKMatrix4 m = { matrix.m[0], matrix.m[1], matrix.m[2], matrix.m[3],
matrix.m[4], matrix.m[5], matrix.m[6], matrix.m[7],
matrix.m[8], matrix.m[9], matrix.m[10], matrix.m[11],
matrix.m[0] * translationVector.v[0] + matrix.m[4] * translationVector.v[1] + matrix.m[8] * translationVector.v[2] + matrix.m[12],
matrix.m[1] * translationVector.v[0] + matrix.m[5] * translationVector.v[1] + matrix.m[9] * translationVector.v[2] + matrix.m[13],
matrix.m[2] * translationVector.v[0] + matrix.m[6] * translationVector.v[1] + matrix.m[10] * translationVector.v[2] + matrix.m[14],
matrix.m[15] };
return m;
}
static __inline__ GLKMatrix4 GLKMatrix4Scale(GLKMatrix4 matrix, float sx, float sy, float sz)
{
#if defined(__ARM_NEON__)
float32x4x4_t iMatrix = *(float32x4x4_t *)&matrix;
float32x4x4_t m;
m.val[0] = vmulq_n_f32(iMatrix.val[0], (float32_t)sx);
m.val[1] = vmulq_n_f32(iMatrix.val[1], (float32_t)sy);
m.val[2] = vmulq_n_f32(iMatrix.val[2], (float32_t)sz);
m.val[3] = iMatrix.val[3];
return *(GLKMatrix4 *)&m;
#else
GLKMatrix4 m = { matrix.m[0] * sx, matrix.m[1] * sx, matrix.m[2] * sx, matrix.m[3] * sx,
matrix.m[4] * sy, matrix.m[5] * sy, matrix.m[6] * sy, matrix.m[7] * sy,
matrix.m[8] * sz, matrix.m[9] * sz, matrix.m[10] * sz, matrix.m[11] * sz,
matrix.m[12], matrix.m[13], matrix.m[14], matrix.m[15] };
return m;
#endif
}
static __inline__ GLKMatrix4 GLKMatrix4ScaleWithVector3(GLKMatrix4 matrix, GLKVector3 scaleVector)
{
#if defined(__ARM_NEON__)
float32x4x4_t iMatrix = *(float32x4x4_t *)&matrix;
float32x4x4_t m;
m.val[0] = vmulq_n_f32(iMatrix.val[0], (float32_t)scaleVector.v[0]);
m.val[1] = vmulq_n_f32(iMatrix.val[1], (float32_t)scaleVector.v[1]);
m.val[2] = vmulq_n_f32(iMatrix.val[2], (float32_t)scaleVector.v[2]);
m.val[3] = iMatrix.val[3];
return *(GLKMatrix4 *)&m;
#else
GLKMatrix4 m = { matrix.m[0] * scaleVector.v[0], matrix.m[1] * scaleVector.v[0], matrix.m[2] * scaleVector.v[0], matrix.m[3] * scaleVector.v[0],
matrix.m[4] * scaleVector.v[1], matrix.m[5] * scaleVector.v[1], matrix.m[6] * scaleVector.v[1], matrix.m[7] * scaleVector.v[1],
matrix.m[8] * scaleVector.v[2], matrix.m[9] * scaleVector.v[2], matrix.m[10] * scaleVector.v[2], matrix.m[11] * scaleVector.v[2],
matrix.m[12], matrix.m[13], matrix.m[14], matrix.m[15] };
return m;
#endif
}
static __inline__ GLKMatrix4 GLKMatrix4ScaleWithVector4(GLKMatrix4 matrix, GLKVector4 scaleVector)
{
#if defined(__ARM_NEON__)
float32x4x4_t iMatrix = *(float32x4x4_t *)&matrix;
float32x4x4_t m;
m.val[0] = vmulq_n_f32(iMatrix.val[0], (float32_t)scaleVector.v[0]);
m.val[1] = vmulq_n_f32(iMatrix.val[1], (float32_t)scaleVector.v[1]);
m.val[2] = vmulq_n_f32(iMatrix.val[2], (float32_t)scaleVector.v[2]);
m.val[3] = iMatrix.val[3];
return *(GLKMatrix4 *)&m;
#else
GLKMatrix4 m = { matrix.m[0] * scaleVector.v[0], matrix.m[1] * scaleVector.v[0], matrix.m[2] * scaleVector.v[0], matrix.m[3] * scaleVector.v[0],
matrix.m[4] * scaleVector.v[1], matrix.m[5] * scaleVector.v[1], matrix.m[6] * scaleVector.v[1], matrix.m[7] * scaleVector.v[1],
matrix.m[8] * scaleVector.v[2], matrix.m[9] * scaleVector.v[2], matrix.m[10] * scaleVector.v[2], matrix.m[11] * scaleVector.v[2],
matrix.m[12], matrix.m[13], matrix.m[14], matrix.m[15] };
return m;
#endif
}
static __inline__ GLKMatrix4 GLKMatrix4Rotate(GLKMatrix4 matrix, float radians, float x, float y, float z)
{
GLKMatrix4 rm = GLKMatrix4MakeRotation(radians, x, y, z);
return GLKMatrix4Multiply(matrix, rm);
}
static __inline__ GLKMatrix4 GLKMatrix4RotateWithVector3(GLKMatrix4 matrix, float radians, GLKVector3 axisVector)
{
GLKMatrix4 rm = GLKMatrix4MakeRotation(radians, axisVector.v[0], axisVector.v[1], axisVector.v[2]);
return GLKMatrix4Multiply(matrix, rm);
}
static __inline__ GLKMatrix4 GLKMatrix4RotateWithVector4(GLKMatrix4 matrix, float radians, GLKVector4 axisVector)
{
GLKMatrix4 rm = GLKMatrix4MakeRotation(radians, axisVector.v[0], axisVector.v[1], axisVector.v[2]);
return GLKMatrix4Multiply(matrix, rm);
}
static __inline__ GLKMatrix4 GLKMatrix4RotateX(GLKMatrix4 matrix, float radians)
{
GLKMatrix4 rm = GLKMatrix4MakeXRotation(radians);
return GLKMatrix4Multiply(matrix, rm);
}
static __inline__ GLKMatrix4 GLKMatrix4RotateY(GLKMatrix4 matrix, float radians)
{
GLKMatrix4 rm = GLKMatrix4MakeYRotation(radians);
return GLKMatrix4Multiply(matrix, rm);
}
static __inline__ GLKMatrix4 GLKMatrix4RotateZ(GLKMatrix4 matrix, float radians)
{
GLKMatrix4 rm = GLKMatrix4MakeZRotation(radians);
return GLKMatrix4Multiply(matrix, rm);
}
static __inline__ GLKVector3 GLKMatrix4MultiplyVector3(GLKMatrix4 matrixLeft, GLKVector3 vectorRight)
{
GLKVector4 v4 = GLKMatrix4MultiplyVector4(matrixLeft, GLKVector4Make(vectorRight.v[0], vectorRight.v[1], vectorRight.v[2], 0.0f));
return GLKVector3Make(v4.v[0], v4.v[1], v4.v[2]);
}
static __inline__ GLKVector3 GLKMatrix4MultiplyVector3WithTranslation(GLKMatrix4 matrixLeft, GLKVector3 vectorRight)
{
GLKVector4 v4 = GLKMatrix4MultiplyVector4(matrixLeft, GLKVector4Make(vectorRight.v[0], vectorRight.v[1], vectorRight.v[2], 1.0f));
return GLKVector3Make(v4.v[0], v4.v[1], v4.v[2]);
}
static __inline__ GLKVector3 GLKMatrix4MultiplyAndProjectVector3(GLKMatrix4 matrixLeft, GLKVector3 vectorRight)
{
GLKVector4 v4 = GLKMatrix4MultiplyVector4(matrixLeft, GLKVector4Make(vectorRight.v[0], vectorRight.v[1], vectorRight.v[2], 1.0f));
return GLKVector3MultiplyScalar(GLKVector3Make(v4.v[0], v4.v[1], v4.v[2]), 1.0f / v4.v[3]);
}
static __inline__ void GLKMatrix4MultiplyVector3Array(GLKMatrix4 matrix, GLKVector3 *vectors, size_t vectorCount)
{
size_t i;
for (i=0; i < vectorCount; i++)
vectors[i] = GLKMatrix4MultiplyVector3(matrix, vectors[i]);
}
static __inline__ void GLKMatrix4MultiplyVector3ArrayWithTranslation(GLKMatrix4 matrix, GLKVector3 *vectors, size_t vectorCount)
{
size_t i;
for (i=0; i < vectorCount; i++)
vectors[i] = GLKMatrix4MultiplyVector3WithTranslation(matrix, vectors[i]);
}
static __inline__ void GLKMatrix4MultiplyAndProjectVector3Array(GLKMatrix4 matrix, GLKVector3 *vectors, size_t vectorCount)
{
size_t i;
for (i=0; i < vectorCount; i++)
vectors[i] = GLKMatrix4MultiplyAndProjectVector3(matrix, vectors[i]);
}
static __inline__ GLKVector4 GLKMatrix4MultiplyVector4(GLKMatrix4 matrixLeft, GLKVector4 vectorRight)
{
#if defined(__ARM_NEON__)
float32x4x4_t iMatrix = *(float32x4x4_t *)&matrixLeft;
float32x4_t v;
iMatrix.val[0] = vmulq_n_f32(iMatrix.val[0], (float32_t)vectorRight.v[0]);
iMatrix.val[1] = vmulq_n_f32(iMatrix.val[1], (float32_t)vectorRight.v[1]);
iMatrix.val[2] = vmulq_n_f32(iMatrix.val[2], (float32_t)vectorRight.v[2]);
iMatrix.val[3] = vmulq_n_f32(iMatrix.val[3], (float32_t)vectorRight.v[3]);
iMatrix.val[0] = vaddq_f32(iMatrix.val[0], iMatrix.val[1]);
iMatrix.val[2] = vaddq_f32(iMatrix.val[2], iMatrix.val[3]);
v = vaddq_f32(iMatrix.val[0], iMatrix.val[2]);
return *(GLKVector4 *)&v;
#else
GLKVector4 v = { matrixLeft.m[0] * vectorRight.v[0] + matrixLeft.m[4] * vectorRight.v[1] + matrixLeft.m[8] * vectorRight.v[2] + matrixLeft.m[12] * vectorRight.v[3],
matrixLeft.m[1] * vectorRight.v[0] + matrixLeft.m[5] * vectorRight.v[1] + matrixLeft.m[9] * vectorRight.v[2] + matrixLeft.m[13] * vectorRight.v[3],
matrixLeft.m[2] * vectorRight.v[0] + matrixLeft.m[6] * vectorRight.v[1] + matrixLeft.m[10] * vectorRight.v[2] + matrixLeft.m[14] * vectorRight.v[3],
matrixLeft.m[3] * vectorRight.v[0] + matrixLeft.m[7] * vectorRight.v[1] + matrixLeft.m[11] * vectorRight.v[2] + matrixLeft.m[15] * vectorRight.v[3] };
return v;
#endif
}
static __inline__ void GLKMatrix4MultiplyVector4Array(GLKMatrix4 matrix, GLKVector4 *vectors, size_t vectorCount)
{
size_t i;
for (i=0; i < vectorCount; i++)
vectors[i] = GLKMatrix4MultiplyVector4(matrix, vectors[i]);
}
#ifdef __cplusplus
}
#endif
#endif /* __GLK_MATRIX_4_H */

99
samples/C/NWMan.h Normal file
View File

@@ -0,0 +1,99 @@
#ifndef _NME_WMAN_H
#define _NME_WMAN_H
// Internal window manager API
#include "NCompat.h"
START_HEAD
#include "NPos.h"
#include "NUtil.h"
#include "NTypes.h"
NTS(NWMan_event);
NSTRUCT(NWMan, {
// Init stuff
bool (*init)();
bool (*destroy)();
// Window stuff
bool (*create_window)();
bool (*destroy_window)();
void (*swap_buffers)();
// Event stuff
bool (*next_event)(NWMan_event* event);
// Time stuff
uint (*get_millis)();
void (*sleep)(uint millis);
// Info
int rshift_key;
int lshift_key;
int left_key;
int right_key;
});
NENUM(NWMan_event_type, {
N_WMAN_MOUSE_MOVE = 0,
N_WMAN_MOUSE_BUTTON = 1,
N_WMAN_MOUSE_WHEEL = 2,
N_WMAN_KEYBOARD = 10,
N_WMAN_QUIT = 20,
N_WMAN_RESIZE = 21,
N_WMAN_FOCUS = 22
});
#define N_WMAN_MOUSE_LEFT 0
#define N_WMAN_MOUSE_RIGHT 1
#define N_WMAN_MOUSE_MIDDLE 2
NSTRUCT(NWMan_event, {
NWMan_event_type type;
union {
// Mouse
NPos2i mouse_pos;
struct {
short id;
bool state;
} mouse_button;
signed char mouse_wheel; // 1 if up, -1 if down
// Keyboard
struct {
int key;
bool state;
} keyboard;
// Window
bool window_quit; // Will always be true if WM_QUIT
NPos2i window_size;
bool window_focus;
};
});
NWMan_event NWMan_event_new(NWMan_event_type type);
bool NWMan_init();
bool NWMan_destroy();
extern NWMan N_WMan;
END_HEAD
#endif

27
samples/C/Nightmare.h Normal file
View File

@@ -0,0 +1,27 @@
#ifndef _NMEX_NIGHTMARE_H
#define _NMEX_NIGHTMARE_H
//#define NMEX
#include "../src/NCompat.h"
START_HEAD
#include "../src/NTypes.h"
#include "../src/NUtil.h"
#include "../src/NPorting.h"
#include "../src/NGlobals.h"
#include "../src/NLog.h"
#include "../src/NWMan.h"
#include "../src/NRsc.h"
#include "../src/NShader.h"
#include "../src/NSquare.h"
#include "../src/NImage.h"
#include "../src/NSprite.h"
#include "../src/NSpritesheet.h"
#include "../src/NEntity.h"
#include "../src/Game.h"
END_HEAD
#endif

47
samples/C/bitmap.h Normal file
View File

@@ -0,0 +1,47 @@
#pragma once
/* Copyright © 2010 Christoph Sünderhauf
*
* This file is part of Xelix.
*
* Xelix is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Xelix is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Xelix. If not, see <http://www.gnu.org/licenses/>.
*/
#include "generic.h"
typedef struct {
uint32_t numbits;
/* an array large enough for numbits to fit in. Might
* (if numbits%8!=0) have some spare bits at the end
*/
uint32_t* bits;
} bitmap_t;
// creates a new bitmap.
// CONTENT IS RANDOM! - use bitmap_clearall() to clear the bitmap.
bitmap_t bitmap_init(uint32_t numbits);
// returns 1 or 0
uint8_t bitmap_get(bitmap_t bitmap, uint32_t bitnum);
// sets a bit (to 1)
void bitmap_set(bitmap_t bitmap, uint32_t bitnum);
// clears a bit (to 0)
void bitmap_clear(bitmap_t bitmap, uint32_t bitnum);
// clears every bit to 0
void bitmap_clearAll(bitmap_t bitmap);
// finds the first bit set to 0 returns 0 if no cleared bit found (0 is also returned if the first bit is cleared)
uint32_t bitmap_findFirstClear(bitmap_t bitmap);

44
samples/C/color.h Normal file
View File

@@ -0,0 +1,44 @@
#pragma once
/* Copyright © 2011 Fritz Grimpen
*
* This file is part of Xelix.
*
* Xelix is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Xelix is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Xelix. If not, see <http://www.gnu.org/licenses/>.
*/
#include <lib/generic.h>
typedef struct {
uint32_t background;
uint32_t foreground;
} console_color_t;
#define CONSOLE_COLOR_BLACK 0x0
#define CONSOLE_COLOR_BLUE 0x1
#define CONSOLE_COLOR_GREEN 0x2
#define CONSOLE_COLOR_CYAN 0x3
#define CONSOLE_COLOR_RED 0x4
#define CONSOLE_COLOR_MAGENTA 0x5
#define CONSOLE_COLOR_BROWN 0x6
#define CONSOLE_COLOR_LGREY 0x7
#define CONSOLE_COLOR_DGREY 0x8
#define CONSOLE_COLOR_LBLUE 0x9
#define CONSOLE_COLOR_LGREEN 0xa
#define CONSOLE_COLOR_LCYAN 0xb
#define CONSOLE_COLOR_LRED 0xc
#define CONSOLE_COLOR_LMAGENTA 0xd
#define CONSOLE_COLOR_YELLOW 0xe
#define CONSOLE_COLOR_WHITE 0xf

52
samples/C/driver.h Normal file
View File

@@ -0,0 +1,52 @@
#pragma once
/* Copyright © 2011 Fritz Grimpen
*
* This file is part of Xelix.
*
* Xelix is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Xelix is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Xelix. If not, see <http://www.gnu.org/licenses/>.
*/
#include <lib/generic.h>
#include <console/info.h>
#define CONSOLE_DRV_CAP_CLEAR 0x01
#define CONSOLE_DRV_CAP_SCROLL 0x02
#define CONSOLE_DRV_CAP_SET_CURSOR 0x04
// Input modifier keys
typedef struct {
bool shift_left:1;
bool shift_right:1;
bool control_left:1;
bool control_right:1;
bool alt:1;
bool super:1;
} console_modifiers_t;
typedef struct {
char character;
console_modifiers_t* modifiers;
} console_read_t;
typedef struct {
int (*write)(console_info_t*, char);
console_read_t* (*read)(console_info_t*);
int capabilities;
int (*_clear)(console_info_t*);
int (*scroll)(console_info_t*, int32_t);
void (*setCursor)(console_info_t*, uint32_t, uint32_t);
} console_driver_t;

70
samples/C/elf.h Normal file
View File

@@ -0,0 +1,70 @@
#pragma once
/* Copyright © 2011 Lukas Martini
*
* This file is part of Xelix.
*
* Xelix is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Xelix is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Xelix. If not, see <http://www.gnu.org/licenses/>.
*/
#include <lib/generic.h>
#include <tasks/scheduler.h>
#define ELF_TYPE_NONE 0
#define ELF_TYPE_REL 1
#define ELF_TYPE_EXEC 2
#define ELF_TYPE_DYN 3
#define ELF_TYPE_CORE 4
#define ELF_ARCH_NONE 0
#define ELF_ARCH_386 3
#define ELF_VERSION_CURRENT 1
typedef struct {
unsigned char magic[4];
/* Note: There _is_ other stuff in here, but we don't need it */
unsigned char pad[12];
} __attribute__((packed)) elf_ident_t;
typedef struct {
uint32_t type;
uint32_t offset;
void* virtaddr;
void* physaddr;
uint32_t filesize;
uint32_t memsize;
uint32_t flags;
uint32_t alignment;
} __attribute__((packed)) elf_program_t;
typedef struct {
elf_ident_t ident;
uint16_t type; /* Object file type */
uint16_t machine; /* Architecture */
uint32_t version; /* Object file version */
void* entry; /* Entry point virtual address */
uint32_t phoff; /* Program header table file offset */
uint32_t shoff; /* Section header table file offset */
uint32_t flags; /* Processor-specific flags */
uint16_t ehsize; /* ELF header size in bytes */
uint16_t phentsize; /* Program header table entry size */
uint16_t phnum; /* Program header table entry count */
uint16_t shentsize; /* Section header table entry size */
uint16_t shnum; /* Section header table entry count */
uint16_t shstrndx; /* Section header string table index */
} __attribute__((packed)) elf_t;
task_t* elf_load(elf_t* bin, char* name, char** environ, char** argv, int argc);
task_t* elf_load_file(char* path, char** environ, char** argv, int argc);

45
samples/C/filter.h Normal file
View File

@@ -0,0 +1,45 @@
#pragma once
/* Copyright © 2011 Fritz Grimpen
*
* This file is part of Xelix.
*
* Xelix is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Xelix is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Xelix. If not, see <http://www.gnu.org/licenses/>.
*/
#include <lib/generic.h>
#include <console/info.h>
#include <console/driver.h>
struct console_filter {
// General callback for all actions etc.
// Preferred prototype:
// char <name>(char c, console_info_t *info, console_driver_t *input, console_driver_t *output);
char (*callback)(char, console_info_t*, console_driver_t*, console_driver_t*);
// Specific callbacks for read and write
// Preferred prototype:
// char <name>(char c, console_info_t *info, console_driver_t *input);
char (*read_callback)(char, console_info_t*, console_driver_t*);
// Preferred prototype:
// char <name>(char c, console_info_t *info, console_driver_t *output);
char (*write_callback)(char, console_info_t*, console_driver_t*);
// The next filter in the filter chain
struct console_filter* next;
};
typedef struct console_filter console_filter_t;

44
samples/C/info.h Normal file
View File

@@ -0,0 +1,44 @@
#pragma once
/* Copyright © 2011 Fritz Grimpen
*
* This file is part of Xelix.
*
* Xelix is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Xelix is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Xelix. If not, see <http://www.gnu.org/licenses/>.
*/
#include <lib/generic.h>
#include <console/color.h>
typedef struct {
uint32_t cursor_x;
uint32_t cursor_y;
uint32_t rows;
uint32_t columns;
uint32_t tabstop;
console_color_t default_color;
console_color_t current_color;
uint8_t nonblocking;
uint8_t reverse_video;
uint8_t bold;
uint8_t blink;
uint8_t underline;
uint8_t newline_mode;
uint8_t auto_echo;
uint8_t handle_backspace;
} console_info_t;

47
samples/C/interface.h Normal file
View File

@@ -0,0 +1,47 @@
#pragma once
/* Copyright © 2011 Fritz Grimpen
*
* This file is part of Xelix.
*
* Xelix is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Xelix is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Xelix. If not, see <http://www.gnu.org/licenses/>.
*/
#include <lib/generic.h>
#include <console/info.h>
#include <console/filter.h>
#include <console/driver.h>
typedef struct {
console_info_t info;
console_filter_t* input_filter;
console_filter_t* output_filter;
console_driver_t* input_driver;
console_driver_t* output_driver;
} console_t;
console_t* default_console;
// Generate raw console, connected to the Display, Keyboard and the
// ECMA-48-Filter
void console_init();
size_t console_write(console_t* console, const char* buffer, int32_t length);
#define console_write2(console, buffer) console_write(console, buffer, strlen(buffer))
size_t console_read(console_t* console, char* buffer, size_t length);
size_t console_scroll(console_t* console, int32_t pages);
void console_clear(console_t* console);

50
samples/C/ip4.h Normal file
View File

@@ -0,0 +1,50 @@
#pragma once
/* Copyright © 2011 Lukas Martini
*
* This file is part of Xelix.
*
* Xelix is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Xelix is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Xelix. If not, see <http://www.gnu.org/licenses/>.
*/
#include <lib/generic.h>
#include <net/net.h>
#define IP4_TOS_ICMP 0
typedef uint32_t ip4_addr_t;
typedef struct {
unsigned int hl:4; /* both fields are 4 bits */
unsigned int version:4;
uint8_t tos;
uint16_t len;
uint16_t id;
uint16_t off;
uint8_t ttl;
uint8_t p;
uint16_t checksum;
ip4_addr_t src;
ip4_addr_t dst;
} ip4_header_t;
typedef struct {
uint8_t type;
uint8_t code;
uint16_t checksum;
uint16_t id;
uint16_t sequence;
} ip4_icmp_header_t;
void ip4_receive(net_device_t* origin, net_l2proto_t proto, size_t size, void* raw);

110
samples/C/multiboot.h Normal file
View File

@@ -0,0 +1,110 @@
#pragma once
/* Copyright © 2010, 2011 Lukas Martini
*
* This file is part of Xelix.
*
* Xelix is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Xelix is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Xelix. If not, see <http://www.gnu.org/licenses/>.
*/
#include <lib/generic.h>
#define MULTIBOOT_KERNELMAGIC 0x2BADB002
#define MULTIBOOT_FLAG_MEM 0x001
#define MULTIBOOT_FLAG_DEVICE 0x002
#define MULTIBOOT_FLAG_CMDLINE 0x004
#define MULTIBOOT_FLAG_MODS 0x008
#define MULTIBOOT_FLAG_AOUT 0x010
#define MULTIBOOT_FLAG_ELF 0x020
#define MULTIBOOT_FLAG_MMAP 0x040
#define MULTIBOOT_FLAG_CONFIG 0x080
#define MULTIBOOT_FLAG_LOADER 0x100
#define MULTIBOOT_FLAG_APM 0x200
#define MULTIBOOT_FLAG_VBE 0x400
// The symbol table for a.out.
typedef struct
{
uint32_t tabSize;
uint32_t strSize;
uint32_t addr;
uint32_t reserved;
} __attribute__((packed)) multiboot_aoutSymbolTable_t;
// The section header table for ELF.
typedef struct
{
uint32_t num;
uint32_t size;
uint32_t addr;
uint32_t shndx;
} __attribute__((packed)) multiboot_elfSectionHeaderTable_t;
typedef struct
{
uint32_t size;
uint64_t addr;
uint64_t length;
uint32_t type;
} __attribute__((packed)) multiboot_memoryMap_t;
typedef struct
{
uint32_t start;
uint32_t end;
char* cmdLine;
uint32_t reserved;
} __attribute__((packed)) multiboot_module_t;
typedef struct
{
uint32_t flags;
uint32_t memLower;
uint32_t memUpper;
uint32_t bootDevice;
char* cmdLine;
uint32_t modsCount;
multiboot_module_t* modsAddr;
union
{
multiboot_aoutSymbolTable_t aoutSym;
multiboot_elfSectionHeaderTable_t elfSec;
} u;
uint32_t mmapLength;
uint32_t mmapAddr;
uint32_t drivesLength;
uint32_t drivesAddr;
// ROM configuration table
uint32_t configTable;
char* bootLoaderName;
uint32_t apmTable;
// Video
uint32_t vbeControlInfo;
uint32_t vbeModeInfo;
uint16_t vbeMode;
uint16_t vbeInterfaceSeg;
uint16_t vbeInterfaceOff;
uint16_t vbeInterfaceLen;
} __attribute__((packed)) multiboot_info_t;
multiboot_info_t* multiboot_info;
void arch_multiboot_printInfo();

89
samples/C/ntru_encrypt.h Normal file
View File

@@ -0,0 +1,89 @@
/*
* Copyright (C) 2014 FH Bielefeld
*
* This file is part of a FH Bielefeld project.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301 USA
*/
/**
* @file ntru_encrypt.h
* Header for the internal API of ntru_encrypt.c.
* @brief header for encrypt.c
*/
#ifndef PQC_ENCRYPT_H
#define PQC_ENCRYPT_H
#include "ntru_params.h"
#include "ntru_poly.h"
#include "ntru_string.h"
#include <fmpz_poly.h>
#include <fmpz.h>
/**
* encrypt the msg, using the math:
* e = (h r) + m (mod q)
*
* e = the encrypted poly
*
* h = the public key
*
* r = the random poly
*
* m = the message poly
*
* q = large mod
*
* @param msg_tern the message to encrypt, in ternary format
* @param pub_key the public key
* @param rnd the random poly (should have relatively small
* coefficients, but not restricted to {-1, 0, 1})
* @param out the output poly which is in the range {0, q-1}
* (not ternary!) [out]
* @param params ntru_params the ntru context
*/
void
ntru_encrypt_poly(
const fmpz_poly_t msg_tern,
const fmpz_poly_t pub_key,
const fmpz_poly_t rnd,
fmpz_poly_t out,
const ntru_params *params);
/**
* Encrypt a message in the form of a null-terminated char array and
* return a string.
*
* @param msg the message
* @param pub_key the public key
* @param rnd the random poly (should have relatively small
* coefficients, but not restricted to {-1, 0, 1})
* @param params ntru_params the ntru context
* @return the newly allocated encrypted string
*/
string *
ntru_encrypt_string(
const string *msg,
const fmpz_poly_t pub_key,
const fmpz_poly_t rnd,
const ntru_params *params);
#endif /* PQC_ENCRYPT_H */

43
samples/C/portio.h Normal file
View File

@@ -0,0 +1,43 @@
#pragma once
/* Copyright © 2011 Lukas Martini
*
* This file is part of Xelix.
*
* Xelix is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Xelix is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Xelix. If not, see <http://www.gnu.org/licenses/>.
*/
#include <lib/generic.h>
#include <lib/stdint.h>
// Legacy
#define outb(args...) portio_out8(args)
#define outw(args...) portio_out16(args)
#define outl(args...) portio_out32(args)
#define outq(args...) portio_out64(args)
#define inb(args...) portio_in8(args)
#define inw(args...) portio_in16(args)
#define inl(args...) portio_in32(args)
#define inq(args...) portio_in64(args)
void portio_out8(uint16_t port, uint8_t value);
void portio_out16(uint16_t port, uint16_t value);
void portio_out32(uint16_t port, uint32_t value);
void portio_out64(uint16_t port, uint64_t value);
uint8_t portio_in8(uint16_t port);
uint16_t portio_in16(uint16_t port);
uint32_t portio_in32(uint16_t port);
uint64_t portio_in64(uint16_t port);

69
samples/C/scheduler.h Normal file
View File

@@ -0,0 +1,69 @@
#pragma once
/* Copyright © 2011 Lukas Martini
*
* This file is part of Xelix.
*
* Xelix is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Xelix is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Xelix. If not, see <http://www.gnu.org/licenses/>.
*/
#include <lib/generic.h>
#include <hw/cpu.h>
#include <memory/vmem.h>
#define SCHEDULER_MAXNAME 256
#define SCHEDULER_TASK_PATH_MAX 256
// Single linked list
typedef struct task {
uint32_t pid;
char name[SCHEDULER_MAXNAME];
struct task *parent;
cpu_state_t* state;
struct task* next;
struct task* previous;
void* stack;
void* entry;
struct vmem_context *memory_context;
// Current task state
enum {
TASK_STATE_KILLED,
TASK_STATE_TERMINATED,
TASK_STATE_BLOCKING,
TASK_STATE_STOPPED,
TASK_STATE_RUNNING
} task_state;
char** environ;
char** argv;
int argc;
// TODO Is this actually the same as PATH_MAX in our toolchain?
char cwd[SCHEDULER_TASK_PATH_MAX + 1];
} task_t;
int scheduler_state;
task_t* scheduler_new(void* entry, task_t* parent, char name[SCHEDULER_MAXNAME],
char** environ, char** argv, int argc, struct vmem_context* memory_context, bool map_structs);
void scheduler_add(task_t *task);
void scheduler_terminate_current();
task_t* scheduler_get_current();
task_t* scheduler_select(cpu_state_t* lastRegs);
void scheduler_init();
void scheduler_yield();
void scheduler_remove(task_t *t);
task_t* scheduler_fork(task_t* to_fork, cpu_state_t* state);

95
samples/C/syscalls.h Normal file
View File

@@ -0,0 +1,95 @@
#pragma once
/* Copyright © 2011 Fritz Grimpen
*
* This file is part of Xelix.
*
* Xelix is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Xelix is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Xelix. If not, see <http://www.gnu.org/licenses/>.
*/
#include <lib/generic.h>
#include <tasks/syscall.h>
#include "syscalls/write.h"
#include "syscalls/exit.h"
#include "syscalls/getpid.h"
#include "syscalls/getppid.h"
#include "syscalls/read.h"
#include "syscalls/brk.h"
#include "syscalls/mmap.h"
#include "syscalls/munmap.h"
#include "syscalls/test.h"
#include "syscalls/hostname.h"
#include "syscalls/uname.h"
#include "syscalls/open.h"
#include "syscalls/execve.h"
#include "syscalls/seek.h"
#include "syscalls/opendir.h"
#include "syscalls/readdir.h"
#include "syscalls/kill.h"
#include "syscalls/getexecdata.h"
#include "syscalls/cwd.h"
#include "syscalls/fork.h"
syscall_t syscall_table[] = {
NULL,
sys_exit, // 1
sys_read, // 2
sys_write, // 3
sys_getpid, // 4
sys_brk, // 5
sys_getppid, // 6
sys_mmap, // 7
sys_munmap, // 8
sys_test, // 9
sys_get_hostname, // 10
sys_set_hostname, // 11
sys_uname, // 12
sys_open, // 13
sys_execve, // 14
sys_seek, // 15
sys_opendir, // 16
sys_readdir, // 17
sys_kill, // 18
sys_getexecdata, // 19
sys_chdir, // 20
sys_getcwd, // 21
sys_fork, // 22
};
char* syscall_name_table[] = {
NULL,
"exit", // 1
"read", // 2
"write", // 3
"getpid", // 4
"brk", // 5
"getppid", // 6
"mmap", // 7
"munmap", // 8
"test", // 9
"get_hostname", // 10
"set_hostname", // 11
"uname", // 12
"open", // 13
"execve", // 14
"seek", // 15
"opendir", // 16
"readdir", // 17
"kill", // 18
"getexecdata", // 19
"chdir", // 20
"getcwd", // 21
"fork", // 22
};

56
samples/C/vfs.h Normal file
View File

@@ -0,0 +1,56 @@
#pragma once
/* Copyright © 2010, 2011 Lukas Martini
*
* This file is part of Xelix.
*
* Xelix is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Xelix is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Xelix. If not, see <http://www.gnu.org/licenses/>.
*/
#include <lib/generic.h>
#define VFS_SEEK_SET 0
#define VFS_SEEK_CUR 1
#define VFS_SEEK_END 2
typedef struct {
uint64_t num;
char path[512];
char mount_path[512];
uint32_t offset;
uint32_t mountpoint;
} vfs_file_t;
typedef struct {
uint64_t num;
char path[512];
char mount_path[512];
uint32_t mountpoint;
} vfs_dir_t;
typedef void* (*vfs_read_callback_t)(char* path, uint32_t offset, uint32_t size);
typedef char* (*vfs_read_dir_callback_t)(char* path, uint32_t offset);
// Used to always store the last read/write attempt (used for kernel panic debugging)
char vfs_last_read_attempt[512];
vfs_file_t* vfs_get_from_id(uint32_t id);
vfs_dir_t* vfs_get_dir_from_id(uint32_t id);
void* vfs_read(vfs_file_t* fp, uint32_t size);
char* vfs_dir_read(vfs_dir_t* dir, uint32_t offset);
void vfs_seek(vfs_file_t* fp, uint32_t offset, int origin);
vfs_file_t* vfs_open(char* path);
vfs_dir_t* vfs_dir_open(char* path);
int vfs_mount(char* path, vfs_read_callback_t read_callback, vfs_read_dir_callback_t read_dir_callback);

94
samples/C/vmem.h Normal file
View File

@@ -0,0 +1,94 @@
#pragma once
/* Copyright © 2011 Fritz Grimpen
* Copyright © 2013 Lukas Martini
*
* This file is part of Xelix.
*
* Xelix is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Xelix is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Xelix. If not, see <http://www.gnu.org/licenses/>.
*/
#include <lib/generic.h>
struct vmem_context;
struct vmem_page
{
enum
{
VMEM_SECTION_STACK, /* Initial stack */
VMEM_SECTION_CODE, /* Contains program code and is read-only */
VMEM_SECTION_DATA, /* Contains static data */
VMEM_SECTION_HEAP, /* Allocated by brk(2) at runtime */
VMEM_SECTION_MMAP, /* Allocated by mmap(2) at runtime */
VMEM_SECTION_KERNEL, /* Contains kernel-internal data */
VMEM_SECTION_UNMAPPED /* Unmapped */
} section;
bool readonly:1;
bool cow:1; /* Copy-on-Write mechanism */
bool allocated:1;
void *cow_src_addr;
void *virt_addr;
void *phys_addr;
};
typedef void (*vmem_iterator_t)(struct vmem_context *, struct vmem_page *, uint32_t);
/* Initialize vmem_kernelContext for paging_init() */
void vmem_init();
struct vmem_context *vmem_kernelContext;
struct vmem_context *vmem_currentContext;
struct vmem_context *vmem_processContext;
void *vmem_faultAddress;
/* Some callbacks for magic functions */
void (*vmem_applyPage)(struct vmem_context *, struct vmem_page *);
/* Generate new page context */
struct vmem_context *vmem_new();
struct vmem_page *vmem_new_page();
int vmem_add_page(struct vmem_context *ctx, struct vmem_page *pg);
struct vmem_page *vmem_get_page_phys(struct vmem_context *ctx, void *phys_addr);
struct vmem_page *vmem_get_page_virt(struct vmem_context *ctx, void *virt_addr);
struct vmem_page *vmem_get_page(struct vmem_context *ctx, uint32_t offset);
/* Remove pages in a specific context by physical or virtual address */
struct vmem_page *vmem_rm_page_phys(struct vmem_context *ctx, void *phys_addr);
struct vmem_page *vmem_rm_page_virt(struct vmem_context *ctx, void *virt_addr);
/* Iterator */
int vmem_iterate(struct vmem_context *ctx, vmem_iterator_t callback);
uint32_t vmem_count_pages(struct vmem_context *ctx);
void vmem_dump_page(struct vmem_page *pg);
void vmem_dump(struct vmem_context *ctx);
void vmem_handle_fault(uint32_t code, void *addr, void *instruction);
/* Get/Set cached paging context */
void vmem_set_cache(struct vmem_context *ctx, void *cache);
void *vmem_get_cache(struct vmem_context *ctx);
#ifdef __i386__
#define PAGE_SIZE 4096
#define VMEM_ALIGN(x) (typeof(x))(((intptr_t)(x) & 0xFFFFF000) + 0x1000)
#define VMEM_ALIGN_DOWN(x) (typeof(x))( \
((intptr_t)(x) - ((intptr_t)(x) % PAGE_SIZE)))
#else
#define PAGE_SIZE 0
#define VMEM_ALIGN(x) (x)
#endif

View File

@@ -0,0 +1,12 @@
cmake_minimum_required(VERSION 2.8)
project(Foo)
set(CMAKE_SKIP_RPATH TRUE)
set(CMAKE_INSTALL_PREFIX "/usr/local")
add_subdirectory(bar)
add_executable(foo foo.c)
target_link_libraries(foo pthread)
install(TARGETS foo DESTINATION bin)

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,40 @@
###* @cjsx React.DOM ###
define 'myProject.ReactExampleComponent', [
'React'
'myProject.ExampleStore'
'myProject.ExampleActions'
'myProject.ReactExampleTable'
], (React, ExampleStore, ExampleActions, ReactExampleTable ) ->
ReactExampleComponent = React.createClass
mixins: [ListenMixin]
getInitialState: ->
rows: ExampleStore.getRows()
meta: ExampleStore.getMeta()
componentWillMount: ->
@listenTo ExampleStore
componentDidMount: ->
ExampleActions.getExampleData()
onStoreChange: ->
if this.isMounted()
@setState
rows: ExampleStore.getRows()
meta: ExampleStore.getMeta()
componentWillUnmount: ->
@stopListening ExampleStore
render: ->
<div className="page-wrap">
<header>
<strong> {@state.title} </strong>
<header>
<ReactExampleTable
rows={@state.rows},
meta={@state.meta}
/>
</div>

26
samples/Cool/list.cl Normal file
View File

@@ -0,0 +1,26 @@
(* This simple example of a list class is adapted from an example in the
Cool distribution. *)
class List {
isNil() : Bool { true };
head() : Int { { abort(); 0; } };
tail() : List { { abort(); self; } };
cons(i : Int) : List {
(new Cons).init(i, self)
};
};
class Cons inherits List {
car : Int; -- The element in this list cell
cdr : List; -- The rest of the list
isNil() : Bool { false };
head() : Int { car };
tail() : List { cdr };
init(i : Int, rest : List) : List {
{
car <- i;
cdr <- rest;
self;
}
};
};

71
samples/Cool/sample.cl Normal file
View File

@@ -0,0 +1,71 @@
(* Refer to Alex Aiken, "The Cool Reference Manual":
http://theory.stanford.edu/~aiken/software/cool/cool-manual.pdf
for language specification.
*)
-- Exhibit various language constructs
class Sample {
testCondition(x: Int): Bool {
if x = 0
then false
else
if x < (1 + 2) * 3
then true
else false
fi
fi
};
testLoop(y: Int): Bool {
while y > 0 loop
{
if not condition(y)
then y <- y / 2
else y <- y - 1;
}
pool
};
testAssign(z: Int): Bool {
i : Int;
i <- ~z;
};
testCase(var: Sample): SELF_TYPE {
io : IO <- new IO;
case var of
a : A => io.out_string("Class type is A\n");
b : B => io.out_string("Class type is B\n");
s : Sample => io.out_string("Class type is Sample\n");
o : Object => io.out_string("Class type is object\n");
esac
};
testLet(i: Int): Int {
let (a: Int in
let(b: Int <- 3, c: Int <- 4 in
{
a <- 2;
a * b * 2 / c;
}
)
)
};
};
-- Used to test subclasses
class A inherits Sample {};
class B inherits A {};
class C {
main() : Int {
(new Sample).testLet(1)
};
};
-- "Hello, world" example
class Main inherits IO {
main(): SELF_TYPE {
out_string("Hello, World.\n")
};
};

49
samples/F#/Combinators.fs Normal file
View File

@@ -0,0 +1,49 @@
namespace Nessos.FsPickler.Combinators
open Nessos.FsPickler
open Nessos.FsPickler.Json
/// Json pickling methods
[<RequireQualifiedAccess>]
module Json =
let private jsonSerializer = lazy(FsPickler.CreateJson(omitHeader = true))
/// <summary>
/// Pickles a value to Json.
/// </summary>
/// <param name="pickler">utilized pickler.</param>
/// <param name="value">input value.</param>
let pickle (pickler : Pickler<'T>) (value : 'T) : string =
jsonSerializer.Value.PickleToString (pickler, value)
/// <summary>
/// Unpickles a value from Json.
/// </summary>
/// <param name="pickler">utilized pickler.</param>
/// <param name="pickle">input pickle.</param>
let unpickle (pickler : Pickler<'T>) (pickle : string) : 'T =
jsonSerializer.Value.UnPickleOfString (pickler, pickle)
/// Bson pickling methods
[<RequireQualifiedAccess>]
module Bson =
let private bsonPickler = lazy(FsPickler.CreateBson())
/// <summary>
/// Pickles a value to Bson.
/// </summary>
/// <param name="pickler">utilized pickler.</param>
/// <param name="value">input value.</param>
let pickle (pickler : Pickler<'T>) (value : 'T) : byte [] =
bsonPickler.Value.Pickle (pickler, value)
/// <summary>
/// Unpickles a value from bson.
/// </summary>
/// <param name="pickler">utilized pickler.</param>
/// <param name="pickle">input pickle.</param>
let unpickle (pickler : Pickler<'T>) (pickle : byte []) : 'T =
bsonPickler.Value.UnPickle (pickler, pickle)

65
samples/F#/JsonFormat.fs Normal file
View File

@@ -0,0 +1,65 @@
namespace Nessos.FsPickler.Json
open System
open System.IO
open System.Text
open Newtonsoft.Json
open Nessos.FsPickler
/// <summary>
/// Factory methods for the Json serialization format.
/// </summary>
type JsonPickleFormatProvider internal (indent, omitHeader) as self =
let isCustomSeq isTopLevelSequence =
isTopLevelSequence && self.OmitHeader && self.UseCustomTopLevelSequenceSeparator
let mutable sequenceSeparator = " "
member val Indent = indent with get,set
member val OmitHeader = omitHeader with get,set
member val UseCustomTopLevelSequenceSeparator = false with get,set
member __.SequenceSeparator
with get () = sequenceSeparator
and set sep =
if sep <> null && String.IsNullOrWhiteSpace sep then
sequenceSeparator <- sep
else
invalidArg "SequenceSeparator" "should be non-null whitespace."
interface ITextPickleFormatProvider with
member __.Name = "Json"
// see discussion : https://github.com/nessos/FsPickler/issues/17
member __.DefaultEncoding = new UTF8Encoding(false) :> Encoding
member __.CreateWriter (stream, encoding, isTopLevelSequence, leaveOpen) =
#if NET40
if leaveOpen then raise <| new NotSupportedException("'leaveOpen' not supported in .NET 40.")
let sw = new StreamWriter(stream, encoding)
#else
let sw = new StreamWriter(stream, encoding, 1024, leaveOpen)
#endif
let jw = new JsonTextWriter(sw)
new JsonPickleWriter(jw, __.OmitHeader, __.Indent, isCustomSeq isTopLevelSequence, sequenceSeparator, leaveOpen) :> _
member __.CreateReader (stream, encoding, isTopLevelSequence, leaveOpen) =
#if NET40
if leaveOpen then raise <| new NotSupportedException("'leaveOpen' not supported in .NET 40.")
let sr = new StreamReader(stream, encoding)
#else
let sr = new StreamReader(stream, encoding, true, 1024, leaveOpen)
#endif
let jr = new JsonTextReader(sr)
new JsonPickleReader(jr, __.OmitHeader, isCustomSeq isTopLevelSequence, leaveOpen) :> _
member __.CreateWriter (textWriter, isTopLevelSequence, leaveOpen) =
let jw = new JsonTextWriter(textWriter)
new JsonPickleWriter(jw, __.OmitHeader, __.Indent, isCustomSeq isTopLevelSequence, sequenceSeparator, leaveOpen) :> _
member __.CreateReader (textReader, isTopLevelSequence, leaveOpen) =
let jr = new JsonTextReader(textReader)
new JsonPickleReader(jr, __.OmitHeader, isCustomSeq isTopLevelSequence, leaveOpen) :> _

202
samples/F#/JsonReader.fs Normal file
View File

@@ -0,0 +1,202 @@
namespace Nessos.FsPickler.Json
open System
open System.Collections.Generic
open System.Globalization
open System.IO
open System.Numerics
open System.Text
open Newtonsoft.Json
open Nessos.FsPickler
/// <summary>
/// Json format deserializer
/// </summary>
type internal JsonPickleReader (jsonReader : JsonReader, omitHeader, isTopLevelSequence, leaveOpen) =
do
jsonReader.CloseInput <- not leaveOpen
jsonReader.SupportMultipleContent <- isTopLevelSequence
let isBsonReader = match jsonReader with :? Bson.BsonReader -> true | _ -> false
let mutable depth = 0
let arrayStack = new Stack<int> ()
do arrayStack.Push Int32.MinValue
// do not write tag if omitting header or array element
let omitTag () = (omitHeader && depth = 0) || arrayStack.Peek() = depth - 1
interface IPickleFormatReader with
member __.BeginReadRoot (tag : string) =
do jsonReader.Read() |> ignore
if omitHeader then () else
if jsonReader.TokenType <> JsonToken.StartObject then raise <| new FormatException("invalid json root object.")
else
do jsonReader.MoveNext()
let version = jsonReader.ReadPrimitiveAs<string> false "FsPickler"
if version <> jsonFormatVersion then
let v = Version(version)
raise <| new FormatException(sprintf "Invalid FsPickler format version %O." version)
let sTag = jsonReader.ReadPrimitiveAs<string> false "type"
if tag <> sTag then
raise <| new InvalidPickleTypeException(tag, sTag)
member __.EndReadRoot () =
if not omitHeader then jsonReader.Read() |> ignore
member __.BeginReadObject (tag : string) =
if not <| omitTag () then
jsonReader.ReadProperty tag
jsonReader.MoveNext ()
if isTopLevelSequence && depth = 0 then
arrayStack.Push depth
depth <- depth + 1
ObjectFlags.IsSequenceHeader
else
match jsonReader.TokenType with
| JsonToken.Null -> ObjectFlags.IsNull
| JsonToken.StartArray ->
jsonReader.MoveNext()
arrayStack.Push depth
depth <- depth + 1
ObjectFlags.IsSequenceHeader
| JsonToken.StartObject ->
do jsonReader.MoveNext()
depth <- depth + 1
if jsonReader.ValueAs<string> () = "_flags" then
jsonReader.MoveNext()
let csvFlags = jsonReader.ValueAs<string>()
jsonReader.MoveNext()
parseFlagCsv csvFlags
else
ObjectFlags.None
| token -> raise <| new FormatException(sprintf "expected start of Json object but was '%O'." token)
member __.EndReadObject () =
if isTopLevelSequence && depth = 1 then
arrayStack.Pop () |> ignore
depth <- depth - 1
jsonReader.Read() |> ignore
else
match jsonReader.TokenType with
| JsonToken.Null -> ()
| JsonToken.EndObject -> depth <- depth - 1
| JsonToken.EndArray ->
arrayStack.Pop() |> ignore
depth <- depth - 1
| token -> raise <| new FormatException(sprintf "expected end of Json object but was '%O'." token)
if omitHeader && depth = 0 then ()
else jsonReader.Read() |> ignore
member __.SerializeUnionCaseNames = true
member __.PreferLengthPrefixInSequences = false
member __.ReadNextSequenceElement () =
if isTopLevelSequence && depth = 1 then
jsonReader.TokenType <> JsonToken.None
else
jsonReader.TokenType <> JsonToken.EndArray
member __.ReadCachedObjectId () = jsonReader.ReadPrimitiveAs<int64> false "id"
member __.ReadBoolean tag = jsonReader.ReadPrimitiveAs<bool> (omitTag ()) tag
member __.ReadByte tag = jsonReader.ReadPrimitiveAs<int64> (omitTag ()) tag |> byte
member __.ReadSByte tag = jsonReader.ReadPrimitiveAs<int64> (omitTag ()) tag |> sbyte
member __.ReadInt16 tag = jsonReader.ReadPrimitiveAs<int64> (omitTag ()) tag |> int16
member __.ReadInt32 tag = jsonReader.ReadPrimitiveAs<int64> (omitTag ()) tag |> int
member __.ReadInt64 tag = jsonReader.ReadPrimitiveAs<int64> (omitTag ()) tag
member __.ReadUInt16 tag = jsonReader.ReadPrimitiveAs<int64> (omitTag ()) tag |> uint16
member __.ReadUInt32 tag = jsonReader.ReadPrimitiveAs<int64> (omitTag ()) tag |> uint32
member __.ReadUInt64 tag = jsonReader.ReadPrimitiveAs<int64> (omitTag ()) tag |> uint64
member __.ReadSingle tag =
if not <| omitTag () then
jsonReader.ReadProperty tag
jsonReader.MoveNext()
let value =
match jsonReader.TokenType with
| JsonToken.Float -> jsonReader.ValueAs<double> () |> single
| JsonToken.String -> Single.Parse(jsonReader.ValueAs<string>(), CultureInfo.InvariantCulture)
| _ -> raise <| new FormatException("not a float.")
jsonReader.Read() |> ignore
value
member __.ReadDouble tag =
if not <| omitTag () then
jsonReader.ReadProperty tag
jsonReader.MoveNext()
let value =
match jsonReader.TokenType with
| JsonToken.Float -> jsonReader.ValueAs<double> ()
| JsonToken.String -> Double.Parse(jsonReader.ValueAs<string>(), CultureInfo.InvariantCulture)
| _ -> raise <| new FormatException("not a float.")
jsonReader.Read() |> ignore
value
member __.ReadChar tag = let value = jsonReader.ReadPrimitiveAs<string> (omitTag ()) tag in value.[0]
member __.ReadString tag = jsonReader.ReadPrimitiveAs<string> (omitTag ()) tag
member __.ReadBigInteger tag = jsonReader.ReadPrimitiveAs<string> (omitTag ()) tag |> BigInteger.Parse
member __.ReadGuid tag =
if isBsonReader then
jsonReader.ReadPrimitiveAs<Guid> (omitTag ()) tag
else
jsonReader.ReadPrimitiveAs<string> (omitTag ()) tag |> Guid.Parse
member __.ReadTimeSpan tag = jsonReader.ReadPrimitiveAs<string> (omitTag ()) tag |> TimeSpan.Parse
member __.ReadDecimal tag = jsonReader.ReadPrimitiveAs<string> (omitTag ()) tag |> decimal
// BSON spec mandates the use of Unix time;
// this has millisecond precision which results in loss of accuracy w.r.t. ticks
// since the goal of FsPickler is to offer faithful representations of .NET objects
// we choose to override the spec and serialize ticks outright.
// see also https://json.codeplex.com/discussions/212067
member __.ReadDate tag =
if isBsonReader then
let ticks = jsonReader.ReadPrimitiveAs<int64> (omitTag ()) tag
DateTime(ticks)
else
jsonReader.ReadPrimitiveAs<DateTime> (omitTag ()) tag
member __.ReadBytes tag =
if not <| omitTag () then
jsonReader.ReadProperty tag
jsonReader.Read() |> ignore
let bytes =
if jsonReader.TokenType = JsonToken.Null then null
elif isBsonReader then jsonReader.ValueAs<byte []> ()
else
let base64 = jsonReader.ValueAs<string> ()
Convert.FromBase64String base64
jsonReader.Read() |> ignore
bytes
member __.IsPrimitiveArraySerializationSupported = false
member __.ReadPrimitiveArray _ _ = raise <| new NotImplementedException()
member __.Dispose () = (jsonReader :> IDisposable).Dispose()

View File

@@ -0,0 +1,85 @@
namespace Nessos.FsPickler.Json
open System
open Nessos.FsPickler
type internal OAttribute = System.Runtime.InteropServices.OptionalAttribute
type internal DAttribute = System.Runtime.InteropServices.DefaultParameterValueAttribute
/// <summary>
/// Json pickler instance.
/// </summary>
type JsonSerializer =
inherit FsPicklerTextSerializer
val private format : JsonPickleFormatProvider
/// <summary>
/// Initializes a new Json pickler instance.
/// </summary>
/// <param name="indent">indent out Json pickles.</param>
/// <param name="omitHeader">omit FsPickler header in Json pickles.</param>
/// <param name="typeConverter">specify a custom type name converter.</param>
new ([<O;D(null)>] ?indent, [<O;D(null)>] ?omitHeader, [<O;D(null)>] ?typeConverter) =
let indent = defaultArg indent false
let omitHeader = defaultArg omitHeader false
let json = new JsonPickleFormatProvider(indent, omitHeader)
{
inherit FsPicklerTextSerializer(json, ?typeConverter = typeConverter)
format = json
}
/// <summary>
/// Gets or sets whether Json output should be indented.
/// </summary>
member x.Indent
with get () = x.format.Indent
and set b = x.format.Indent <- b
/// <summary>
/// Gets or sets whether FsPickler headers should be ignored in pickle format.
/// </summary>
member x.OmitHeader
with get () = x.format.OmitHeader
and set b = x.format.OmitHeader <- b
/// <summary>
/// Gets or sets a non-null whitespace string that serves as a custom, top-level sequence separator.
/// </summary>
member x.SequenceSeparator
with get () = x.format.SequenceSeparator
and set sep = x.format.SequenceSeparator <- sep
/// <summary>
/// Gets or sets whether top-level sequences should be serialized using the custom separator.
/// </summary>
member x.UseCustomTopLevelSequenceSeparator
with get () = x.format.UseCustomTopLevelSequenceSeparator
and set e = x.format.UseCustomTopLevelSequenceSeparator <- e
/// <summary>
/// BSON pickler instance.
/// </summary>
type BsonSerializer([<O;D(null)>] ?typeConverter) =
inherit FsPicklerSerializer(new BsonPickleFormatProvider(), ?typeConverter = typeConverter)
/// FsPickler static methods.
type FsPickler =
/// <summary>
/// Initializes a new Json pickler instance.
/// </summary>
/// <param name="indent">indent out Json pickles.</param>
/// <param name="omitHeader">omit FsPickler header in Json pickles.</param>
/// <param name="typeConverter">specify a custom type name converter.</param>
static member CreateJson([<O;D(null)>] ?indent, [<O;D(null)>] ?omitHeader, [<O;D(null)>] ?typeConverter) =
new JsonSerializer(?indent = indent, ?omitHeader = omitHeader, ?typeConverter = typeConverter)
/// <summary>
/// Initializes a new Bson pickler instance.
/// </summary>
/// <param name="typeConverter">specify a custom type name converter.</param>
static member CreateBson([<O;D(null)>] ?typeConverter) =
new BsonSerializer(?typeConverter = typeConverter)

142
samples/F#/JsonWriter.fs Normal file
View File

@@ -0,0 +1,142 @@
namespace Nessos.FsPickler.Json
open System
open System.IO
open System.Collections.Generic
open Newtonsoft.Json
open Nessos.FsPickler
/// <summary>
/// Json format serializer.
/// </summary>
type internal JsonPickleWriter (jsonWriter : JsonWriter, omitHeader, indented, isTopLevelSequence, separator, leaveOpen) =
do
jsonWriter.Formatting <- if indented then Formatting.Indented else Formatting.None
jsonWriter.CloseOutput <- not leaveOpen
let isBsonWriter = match jsonWriter with :? Bson.BsonWriter -> true | _ -> false
let mutable depth = 0
let mutable isTopLevelSequenceHead = false
let mutable currentValueIsNull = false
let arrayStack = new Stack<int> ()
do arrayStack.Push Int32.MinValue
// do not write tag if omitting header or array element
let omitTag () = (omitHeader && depth = 0) || arrayStack.Peek() = depth - 1
interface IPickleFormatWriter with
member __.BeginWriteRoot (tag : string) =
if omitHeader then () else
jsonWriter.WriteStartObject()
writePrimitive jsonWriter false "FsPickler" jsonFormatVersion
writePrimitive jsonWriter false "type" tag
member __.EndWriteRoot () =
if not omitHeader then jsonWriter.WriteEnd()
member __.BeginWriteObject (tag : string) (flags : ObjectFlags) =
if not <| omitTag () then
jsonWriter.WritePropertyName tag
if flags.HasFlag ObjectFlags.IsNull then
currentValueIsNull <- true
jsonWriter.WriteNull()
elif flags.HasFlag ObjectFlags.IsSequenceHeader then
if isTopLevelSequence && depth = 0 then
isTopLevelSequenceHead <- true
else
jsonWriter.WriteStartArray()
arrayStack.Push depth
depth <- depth + 1
else
jsonWriter.WriteStartObject()
depth <- depth + 1
if flags = ObjectFlags.None then ()
else
let flagCsv = mkFlagCsv flags
writePrimitive jsonWriter false "_flags" flagCsv
member __.EndWriteObject () =
if currentValueIsNull then
currentValueIsNull <- false
else
depth <- depth - 1
if arrayStack.Peek () = depth then
if isTopLevelSequence && depth = 0 then ()
else
jsonWriter.WriteEndArray()
arrayStack.Pop () |> ignore
else
jsonWriter.WriteEndObject()
member __.SerializeUnionCaseNames = true
member __.PreferLengthPrefixInSequences = false
member __.WriteNextSequenceElement hasNext =
if isTopLevelSequence && depth = 1 then
if isTopLevelSequenceHead then
isTopLevelSequenceHead <- false
else
jsonWriter.WriteWhitespace separator
member __.WriteCachedObjectId id = writePrimitive jsonWriter false "id" id
member __.WriteBoolean (tag : string) value = writePrimitive jsonWriter (omitTag ()) tag value
member __.WriteByte (tag : string) value = writePrimitive jsonWriter (omitTag ()) tag value
member __.WriteSByte (tag : string) value = writePrimitive jsonWriter (omitTag ()) tag value
member __.WriteInt16 (tag : string) value = writePrimitive jsonWriter (omitTag ()) tag value
member __.WriteInt32 (tag : string) value = writePrimitive jsonWriter (omitTag ()) tag value
member __.WriteInt64 (tag : string) value = writePrimitive jsonWriter (omitTag ()) tag value
member __.WriteUInt16 (tag : string) value = writePrimitive jsonWriter (omitTag ()) tag value
member __.WriteUInt32 (tag : string) value = writePrimitive jsonWriter (omitTag ()) tag value
member __.WriteUInt64 (tag : string) value = writePrimitive jsonWriter (omitTag ()) tag value
member __.WriteSingle (tag : string) value = writePrimitive jsonWriter (omitTag ()) tag value
member __.WriteDouble (tag : string) value = writePrimitive jsonWriter (omitTag ()) tag value
member __.WriteDecimal (tag : string) value = writePrimitive jsonWriter (omitTag ()) tag (string value)
member __.WriteChar (tag : string) value = writePrimitive jsonWriter (omitTag ()) tag value
member __.WriteString (tag : string) value = writePrimitive jsonWriter (omitTag ()) tag value
member __.WriteBigInteger (tag : string) value = writePrimitive jsonWriter (omitTag ()) tag (string value)
member __.WriteGuid (tag : string) value = writePrimitive jsonWriter (omitTag ()) tag value
member __.WriteTimeSpan (tag : string) value = writePrimitive jsonWriter (omitTag ()) tag (string value)
// BSON spec mandates the use of Unix time;
// this has millisecond precision which results in loss of accuracy w.r.t. ticks
// since the goal of FsPickler is to offer faithful representations of .NET objects
// we choose to override the spec and serialize ticks outright.
// see also https://json.codeplex.com/discussions/212067
member __.WriteDate (tag : string) value =
if isBsonWriter then
writePrimitive jsonWriter (omitTag ()) tag value.Ticks
else
writePrimitive jsonWriter (omitTag ()) tag value
member __.WriteBytes (tag : string) (value : byte []) =
if not <| omitTag () then
jsonWriter.WritePropertyName tag
if obj.ReferenceEquals(value, null) then
jsonWriter.WriteNull()
else
jsonWriter.WriteValue value
member __.IsPrimitiveArraySerializationSupported = false
member __.WritePrimitiveArray _ _ = raise <| NotSupportedException()
member __.Dispose () = jsonWriter.Flush()

View File

@@ -0,0 +1,68 @@
namespace Nessos.FsPickler.Tests
open PerfUtil
open PerfUtil.NUnit
open NUnit.Framework
open Nessos.FsPickler
open Nessos.FsPickler.Json
[<AbstractClass>]
type PerfTester () =
inherit NUnitPerf<Serializer> ()
let tests = PerfTest.OfModuleMarker<PerformanceTests.Marker> ()
override __.PerfTests = tests
type ``Serializer Comparison`` () =
inherit PerfTester()
let fsp = FsPickler.initBinary()
let bfs = new BinaryFormatterSerializer() :> Serializer
let ndc = new NetDataContractSerializer() :> Serializer
let jdn = new JsonDotNetSerializer() :> Serializer
let bdn = new JsonDotNetBsonSerializer () :> Serializer
let pbn = new ProtoBufSerializer() :> Serializer
let ssj = new ServiceStackJsonSerializer() :> Serializer
let sst = new ServiceStackTypeSerializer() :> Serializer
let comparer = new WeightedComparer(spaceFactor = 0.2, leastAcceptableImprovementFactor = 1.)
let tester = new ImplementationComparer<_>(fsp, [bfs;ndc;jdn;bdn;pbn;ssj;sst], throwOnError = true, warmup = true, comparer = comparer)
override __.PerfTester = tester :> _
type ``FsPickler Formats Comparison`` () =
inherit PerfTester ()
let binary = FsPickler.initBinary()
let json = FsPickler.initJson()
let bson = FsPickler.initBson()
let xml = FsPickler.initXml()
let tester = new ImplementationComparer<_>(binary, [json ; bson; xml], warmup = true, throwOnError = false)
override __.PerfTester = tester :> _
type ``Past FsPickler Versions Comparison`` () =
inherit PerfTester ()
let persistResults = true
let persistenceFile = "fspPerf.xml"
let fsp = FsPickler.initBinary()
let version = typeof<FsPickler>.Assembly.GetName().Version
let comparer = new WeightedComparer(spaceFactor = 0.2, leastAcceptableImprovementFactor = 0.8)
let tester =
new PastImplementationComparer<Serializer>(
fsp, version, historyFile = persistenceFile, throwOnError = true, warmup = true, comparer = comparer)
override __.PerfTester = tester :> _
[<TestFixtureTearDown>]
member __.Persist() =
if persistResults then tester.PersistCurrentResults ()

View File

@@ -0,0 +1,207 @@
namespace Nessos.FsPickler.Tests
open System
open System.Collections.Generic
open PerfUtil
open Nessos.FsPickler
open Nessos.FsPickler.Tests.Serializer
open Nessos.FsPickler.Tests.TestTypes
module PerformanceTests =
type Marker = class end
let guid = Guid.NewGuid()
[<PerfTest(1000)>]
let ``Value: Guid`` s = roundtrip guid s
let date = DateTime.Now
[<PerfTest(1000)>]
let ``Value: DateTime`` s = roundtrip date s
[<PerfTest(10000)>]
let ``Value: String`` s = roundtrip stringValue s
let boxed = box ([| 1 .. 1000 |], "lorem ipsum")
[<PerfTest(1000)>]
let ``Boxed Object`` s = roundtrip boxed s
let fsClass = new Class(42, stringValue)
[<PerfTest(10000)>]
let ``Class: Simple F# Class`` s = roundtrip fsClass s
let serializableClass = new SerializableClass<_>(42, stringValue, [|1..1000|])
[<PerfTest(10000)>]
let ``Class: ISerializable`` s = roundtrip serializableClass s
let boxedClass = box(Some 42)
[<PerfTest(10000)>]
let ``Subtype Resolution`` s = roundtrip boxedClass s
let floatArray = Array.init 100000 (fun i -> float i)
[<PerfTest(10)>]
let ``Array: Float`` s = roundtrip floatArray s
let intArray = Array.init 100000 id
[<PerfTest(10)>]
let ``Array: Int`` s = roundtrip intArray s
let stringArray = Array.init 10000 (fun i -> stringValue + string i)
[<PerfTest(100)>]
let ``Array: String`` s = roundtrip stringArray s
let kvarr = [|1..10000|] |> Array.map (fun i -> i, string i)
[<PerfTest(100)>]
let ``Array: Key-Value Pairs`` s = roundtrip kvarr s
let duArray = [| for i in 1 .. 10000 -> (Something ("asdasdasdas", i)) |]
[<PerfTest(100)>]
let ``Array: Discriminated Unions`` s = roundtrip duArray s
let objArray =
[|
box 2; box 3; box "hello" ; box <| Some 3; box(2,3) ;
box <| new Class(2, stringValue) ; box <| new SerializableClass<int option>(2, stringValue, Some 12);
box stringValue
|]
[<PerfTest(1000)>]
let ``Array: Objects`` s = roundtrip objArray s
let array3D = Array3D.init 100 100 100 (fun i j k -> float (i * j + k))
[<PerfTest(10)>]
let ``Array: Rank-3 Float`` s = roundtrip array3D s
let bclDict = dict [ for i in 1 .. 1000 -> (string i, i)]
[<PerfTest(100)>]
let ``.NET Dictionary`` s = roundtrip bclDict s
let bclStack = new Stack<string>([for i in 1 .. 1000 -> string i])
[<PerfTest(100)>]
let ``.NET Stack`` s = roundtrip bclStack s
let bclList = new List<string * int>([for i in 1 .. 1000 -> string i, i])
[<PerfTest(100)>]
let ``.NET List`` s = roundtrip bclList s
let bclSet = new SortedSet<_>([for i in 1 .. 1000 -> string i])
[<PerfTest(100)>]
let ``.NET Set`` s = roundtrip bclSet s
let smallTuple = (1, DateTime.Now,"hello")
[<PerfTest(10000)>]
let ``FSharp: Tuple Small`` s = roundtrip smallTuple s
let largeTuple = (stringValue, 1, 2, 3, true, "", Some(3.14, [2]), 3, 2, 1, stringValue)
[<PerfTest(10000)>]
let ``FSharp: Tuple Large`` s =
roundtrip largeTuple s
let intList = [1..1000]
[<PerfTest(1000)>]
let ``FSharp: List Int`` s = roundtrip intList s
let stringList = [ for i in 1 .. 1000 -> stringValue + string i ]
[<PerfTest(1000)>]
let ``FSharp: List String`` s = roundtrip stringList s
let pairList = [ for i in 1 .. 1000 -> (string i, i) ]
[<PerfTest(1000)>]
let ``FSharp: List Key-Value`` s = roundtrip pairList s
let nestedLst = let n = [1..1000] in [for _ in 1 .. 100 -> n]
[<PerfTest(1000)>]
let ``FSharp: List Nested`` s = roundtrip nestedLst s
let union = SomethingElse(stringValue, 42, box (Some 42))
[<PerfTest(10000)>]
let ``FSharp: Union`` s = roundtrip union s
let record = { Int = 42 ; String = stringValue ; Tuple = (13, "") }
[<PerfTest(10000)>]
let ``FSharp: Record`` s = roundtrip record s
let peano = int2Peano 100
[<PerfTest(100)>]
let ``FSharp: Peano Rectype`` s = roundtrip peano s
let closure = (@) [ Some([1..100], Set.ofList [1..100]) ]
[<PerfTest(1000)>]
let ``FSharp: Curried Function`` s = roundtrip closure s
let binTree = mkTree 10
[<PerfTest(100)>]
let ``FSharp: Binary Tree`` s = roundtrip binTree s
let intSet = [1..1000] |> List.map string |> set
[<PerfTest(1000)>]
let ``FSharp: Set`` s = roundtrip intSet s
let fsMap = [1..1000] |> Seq.map (fun i -> (string i,i)) |> Map.ofSeq
[<PerfTest(1000)>]
let ``FSharp: Map`` s = roundtrip fsMap s
let testType = typeof<int * string option * Map<int * string [], string ref option>>
[<PerfTest(1000)>]
let ``Reflection: Type`` s = roundtrip testType s
let quotationSmall = <@ fun x -> pown 2 x @>
let quotationLarge =
<@
async {
let rec fibAsync n =
async {
match n with
| _ when n < 0 -> return invalidArg "negative" "n"
| _ when n < 2 -> return n
| n ->
let! fn = fibAsync (n-1)
let! fnn = fibAsync (n-2)
return fn + fnn
}
let! values = [1..100] |> Seq.map fibAsync |> Async.Parallel
return Seq.sum values
}
@>
[<PerfTest(10000)>]
let ``FSharp: Quotation Small`` s = roundtrip quotationSmall s
[<PerfTest(1000)>]
let ``FSharp: Quotation Large`` s = roundtrip quotationLarge s

15
samples/F#/sample.fs Normal file
View File

@@ -0,0 +1,15 @@
module Sample
open System
type Foo =
{
Bar : string
}
type Baz = interface end
let Sample1(xs : int list) : string =
xs
|> List.map (fun x -> string x)
|> String.concat ","

244
samples/Forth/asm.fr Normal file
View File

@@ -0,0 +1,244 @@
\ Copyright 2013-2014 Lars Brinkhoff
\ Assembler for x86.
\ Adds to FORTH vocabulary: ASSEMBLER CODE ;CODE.
\ Creates ASSEMBLER vocabulary with: END-CODE and x86 opcodes.
\ Conventional prefix syntax: "<source> <destination> <opcode>,".
\ Addressing modes:
\ - immediate: "n #"
\ - direct: n
\ - register: <reg>
\ - indirect: "<reg> )"
\ - indirect with displacement: "n <reg> )#"
\ - indexed: not supported yet
require lib/common.fth
require search.fth
vocabulary assembler
also assembler definitions
\ Access to the target image.
' header, defer header, is header,
' cell defer cell is cell
' dp defer dp is dp
0 value delta
: aligned cell + 1 - cell negate nand invert ;
: align dp @ aligned dp ! ;
: allot dp +! ;
: here dp @ ;
: cells cell * ;
: c! delta + c! ;
: c, here c! 1 allot ;
: h, dup c, 8 rshift c, ;
: , dup h, 16 rshift h, ;
base @ hex
\ This constant signals that an operand is not a direct address.
deadbeef constant -addr
\ Assembler state.
variable opcode
variable d
variable s
variable dir?
variable mrrm defer ?mrrm,
variable sib defer ?sib,
variable disp defer ?disp,
variable imm defer ?imm,
defer imm,
defer immediate-opcode
defer reg
defer ?opsize
\ Set opcode. And destination: register or memory.
: opcode! 3@ is immediate-opcode >r opcode ! ;
: !reg dir? @ if 2 d ! then dir? off ;
: !mem dir? off ;
\ Set bits in mod/reg/rm byte.
: -mrrm ['] nop is ?mrrm, ;
: mod! mrrm c0 !bits ;
: reg@ mrrm 38 @bits ;
: reg! mrrm 38 !bits ;
: rm@ mrrm 7 @bits ;
: rm! rm@ 3 lshift reg! mrrm 7 !bits ;
: reg>opcode rm@ opcode 07 !bits ;
: opcode>reg opcode @ dup 3 rshift rm! 8 rshift opcode ! ;
\ Write parts of instruction to memory.
: ds d @ s @ + ;
: ?twobyte dup FF > if dup 8 rshift c, then ;
: opcode, opcode @ ?twobyte ds + c, ;
: mrrm, mrrm @ c, ;
: sib, sib @ c, ;
: imm8, imm @ c, ;
: imm16, imm @ h, ;
: imm32, imm @ , ;
: disp8, disp @ c, ;
: disp32, disp @ , ;
\ Set operand size.
: -opsize 2drop r> drop ;
: opsize! is imm, s ! ['] -opsize is ?opsize ;
: !op8 0 ['] imm8, ?opsize ;
: !op32 1 ['] imm32, ?opsize ;
: !op16 1 ['] imm16, ?opsize 66 c, ;
\ Set SIB byte.
: !sib ['] sib, is ?sib, ;
: sib! 3 lshift + sib ! !sib ;
\ Set displacement.
: byte? -80 80 within ;
: disp! is ?disp, disp ! ;
: !disp8 ['] disp8, disp! ;
: !disp32 ['] disp32, disp! ;
: !disp ( a -- u ) dup byte? if !disp8 40 else !disp32 80 then ;
: -pc here 5 + negate ;
: relative -pc disp +! ;
\ Set immediate operand.
: imm! imm ! ['] imm, is ?imm, ;
\ Implements addressing modes: register, indirect, indexed, and direct.
: reg1 rm! !reg ;
: reg2 3 lshift reg! ;
: !reg2 ['] reg2 is reg ;
: ind dup mod! rm! !mem !reg2 ;
: ind# swap !disp + ind ;
: idx 04 ind sib! ;
: idx# rot !disp 04 + ind sib! ;
: addr !disp32 05 ind ;
\ Reset assembler state.
: 0opsize ['] opsize! is ?opsize ;
: 0ds d off s off ;
: 0reg ['] reg1 is reg ;
: 0mrrm c0 mrrm ! ['] mrrm, is ?mrrm, ;
: 0sib ['] nop is ?sib, ;
: 0disp ['] nop is ?disp, ;
: 0imm imm off ['] nop is ?imm, 0 is imm, ;
: 0asm 0imm 0disp 0reg 0ds 0mrrm 0sib 0opsize dir? on ;
\ Enter and exit assembler mode.
: start-code also assembler 0asm ;
: end-code align previous ;
\ Implements addressing mode: immediate.
: imm8? imm @ byte? ;
: ?sign-extend d off imm8? if 2 d ! ['] imm8, is ?imm, then ;
: alu# opcode @ reg! 80 opcode ! ?sign-extend ;
: mov# B0 s @ 3 lshift + rm@ + opcode ! 0ds -mrrm ;
: push# imm8? if ['] imm8, 6A else ['] imm32, 68 then dup opcode ! rm! is ?imm, ;
: test# F6 opcode ! ;
: imm-op imm! immediate-opcode ;
\ Process one operand. All operands except a direct address
\ have the stack picture ( n*x xt -addr ).
: addr? dup -addr <> ;
: op addr? if addr else drop execute then ;
\ Define instruction formats.
: instruction, opcode! opcode, ?mrrm, ?sib, ?disp, ?imm, 0asm ;
: mnemonic ( u a "name" -- ) create ['] nop 3, does> instruction, ;
: format: create ] !csp does> mnemonic ;
: immediate: ' latestxt >body ! ;
\ Instruction formats.
format: 0op -mrrm ;
format: 1reg op reg>opcode 0ds -mrrm ;
format: 1op opcode>reg op d off ;
format: 2op op op ;
format: 2op-d op op d off ;
format: 2op-ds op op 0ds ;
format: 1addr op relative -mrrm ;
format: 1imm8 !op8 op -mrrm ;
\ Instruction mnemonics.
00 2op add, immediate: alu#
08 2op or, immediate: alu#
0F44 2op-ds cmove, \ Todo: other condition codes.
0FB6 2op-ds movzx,
0FBE 2op-ds movsx,
10 2op adc, immediate: alu#
18 2op sbb, immediate: alu#
20 2op and, immediate: alu#
26 0op es,
28 2op sub, immediate: alu#
2E 0op cs,
30 2op xor, immediate: alu#
36 0op ss,
38 2op cmp, immediate: alu#
3E 0op ds,
50 1reg push, immediate: push#
58 1reg pop,
64 0op fs,
65 0op gs,
\ 70 jcc
84 2op-d test, immediate: test#
86 2op-d xchg,
88 2op mov, immediate: mov#
8D 2op-ds lea,
\ 8F/0 pop, rm
90 0op nop,
C3 0op ret,
\ C6/0 immediate mov to r/m
\ C7/0 immediate mov to r/m
CD 1imm8 int,
E8 1addr call,
E9 1addr jmp,
\ EB jmp rel8
F0 0op lock,
F2 0op rep,
F3 0op repz,
F4 0op hlt,
F5 0op cmc,
F610 1op not,
F618 1op neg,
F8 0op clc,
F9 0op stc,
FA 0op cli,
FB 0op sti,
FC 0op cld,
FD 0op std,
\ FE 0 inc rm
\ FF 1 dec rm
\ FF 2 call rm
\ FF 4 jmp rm
\ FF 6 push rm
: sp? dup 4 = ;
\ Addressing mode syntax: immediate, indirect, and displaced indirect.
: # ['] imm-op -addr ;
: ) 2drop sp? if 4 ['] idx else ['] ind then -addr 0reg 0opsize ;
: )# 2drop sp? if 4 ['] idx# else ['] ind# then -addr 0reg 0opsize ;
\ Define registers.
: reg8 create , does> @ ['] reg -addr !op8 ;
: reg16 create , does> @ ['] reg -addr !op16 ;
: reg32 create , does> @ ['] reg -addr !op32 ;
: reg: dup reg8 dup reg16 dup reg32 1+ ;
\ Register names.
0
reg: al ax eax reg: cl cx ecx reg: dl dx edx reg: bl bx ebx
reg: ah sp esp reg: ch bp ebp reg: dh si esi reg: bh di edi
drop
\ Runtime for ;CODE. CODE! is defined elsewhere.
: (;code) r> code! ;
base ! only forth definitions also assembler
\ Standard assembler entry points.
: code parse-name header, ?code, start-code ;
: ;code postpone (;code) reveal postpone [ ?csp start-code ; immediate
0asm
previous

252
samples/Forth/core.fs Normal file
View File

@@ -0,0 +1,252 @@
: immediate lastxt @ dup c@ negate swap c! ;
: \ source nip >in ! ; immediate \ Copyright 2004, 2012 Lars Brinkhoff
: char \ ( "word" -- char )
bl-word here 1+ c@ ;
: ahead here 0 , ;
: resolve here swap ! ;
: ' bl-word here find 0branch [ ahead ] exit [ resolve ] 0 ;
: postpone-nonimmediate [ ' literal , ' compile, ] literal , ;
: create dovariable_code header, reveal ;
create postponers
' postpone-nonimmediate ,
' abort ,
' , ,
: word \ ( char "<chars>string<char>" -- caddr )
drop bl-word here ;
: postpone \ ( C: "word" -- )
bl word find 1+ cells postponers + @ execute ; immediate
: unresolved \ ( C: "word" -- orig )
postpone postpone postpone ahead ; immediate
: chars \ ( n1 -- n2 )
;
: else \ ( -- ) ( C: orig1 -- orig2 )
unresolved branch swap resolve ; immediate
: if \ ( flag -- ) ( C: -- orig )
unresolved 0branch ; immediate
: then \ ( -- ) ( C: orig -- )
resolve ; immediate
: [char] \ ( "word" -- )
char postpone literal ; immediate
: (does>) lastxt @ dodoes_code over >code ! r> swap >does ! ;
: does> postpone (does>) ; immediate
: begin \ ( -- ) ( C: -- dest )
here ; immediate
: while \ ( x -- ) ( C: dest -- orig dest )
unresolved 0branch swap ; immediate
: repeat \ ( -- ) ( C: orig dest -- )
postpone branch , resolve ; immediate
: until \ ( x -- ) ( C: dest -- )
postpone 0branch , ; immediate
: recurse lastxt @ compile, ; immediate
: pad \ ( -- addr )
here 1024 + ;
: parse \ ( char "string<char>" -- addr n )
pad >r begin
source? if <source 2dup <> else 0 0 then
while
r@ c! r> 1+ >r
repeat 2drop pad r> over - ;
: ( \ ( "string<paren>" -- )
[ char ) ] literal parse 2drop ; immediate
\ TODO: If necessary, refill and keep parsing.
: string, ( addr n -- )
here over allot align swap cmove ;
: (s") ( -- addr n ) ( R: ret1 -- ret2 )
r> dup @ swap cell+ 2dup + aligned >r swap ;
create squote 128 allot
: s" ( "string<quote>" -- addr n )
state @ if
postpone (s") [char] " parse dup , string,
else
[char] " parse >r squote r@ cmove squote r>
then ; immediate
: (abort") ( ... addr n -- ) ( R: ... -- )
cr type cr abort ;
: abort" ( ... x "string<quote>" -- ) ( R: ... -- )
postpone if postpone s" postpone (abort") postpone then ; immediate
\ ----------------------------------------------------------------------
( Core words. )
\ TODO: #
\ TODO: #>
\ TODO: #s
: and ( x y -- x&y ) nand invert ;
: * 1 2>r 0 swap begin r@ while
r> r> swap 2dup dup + 2>r and if swap over + swap then dup +
repeat r> r> 2drop drop ;
\ TODO: */mod
: +loop ( -- ) ( C: nest-sys -- )
postpone (+loop) postpone 0branch , postpone unloop ; immediate
: space bl emit ;
: ?.- dup 0 < if [char] - emit negate then ;
: digit [char] 0 + emit ;
: (.) base @ /mod ?dup if recurse then digit ;
: ." ( "string<quote>" -- ) postpone s" postpone type ; immediate
: . ( x -- ) ?.- (.) space ;
: postpone-number ( caddr -- )
0 0 rot count >number dup 0= if
2drop nip
postpone (literal) postpone (literal) postpone ,
postpone literal postpone ,
else
." Undefined: " type cr abort
then ;
' postpone-number postponers cell+ !
: / ( x y -- x/y ) /mod nip ;
: 0< ( n -- flag ) 0 < ;
: 1- ( n -- n-1 ) -1 + ;
: 2! ( x1 x2 addr -- ) swap over ! cell+ ! ;
: 2* ( n -- 2n ) dup + ;
\ Kernel: 2/
: 2@ ( addr -- x1 x2 ) dup cell+ @ swap @ ;
\ Kernel: 2drop
\ Kernel: 2dup
\ TODO: 2over ( x1 x2 x3 x4 -- x1 x2 x3 x4 x1 x2 )
\ 3 pick 3 pick ;
\ TODO: 2swap
\ TODO: <#
: abs ( n -- |n| )
dup 0< if negate then ;
\ TODO: accept
: c, ( n -- )
here c! 1 chars allot ;
: char+ ( n1 -- n2 )
1+ ;
: constant create , does> @ ;
: decimal ( -- )
10 base ! ;
: depth ( -- n )
data_stack 100 cells + 'SP @ - /cell / 2 - ;
: do ( n1 n2 -- ) ( R: -- loop-sys ) ( C: -- do-sys )
postpone 2>r here ; immediate
\ TODO: environment?
\ TODO: evaluate
\ TODO: fill
\ TODO: fm/mod )
\ TODO: hold
: j ( -- x1 ) ( R: x1 x2 x3 -- x1 x2 x3 )
'RP @ 3 cells + @ ;
\ TODO: leave
: loop ( -- ) ( C: nest-sys -- )
postpone 1 postpone (+loop)
postpone 0branch ,
postpone unloop ; immediate
: lshift begin ?dup while 1- swap dup + swap repeat ;
: rshift 1 begin over while dup + swap 1- swap repeat nip
2>r 0 1 begin r@ while
r> r> 2dup swap dup + 2>r and if swap over + swap then dup +
repeat r> r> 2drop drop ;
: max ( x y -- max[x,y] )
2dup > if drop else nip then ;
\ Kernel: min
\ TODO: mod
\ TODO: move
: (quit) ( R: ... -- )
return_stack 100 cells + 'RP !
0 'source-id ! tib ''source ! #tib ''#source !
postpone [
begin
refill
while
interpret state @ 0= if ." ok" cr then
repeat
bye ;
' (quit) ' quit >body cell+ !
\ TODO: s>d
\ TODO: sign
\ TODO: sm/rem
: spaces ( n -- )
0 do space loop ;
\ TODO: u.
: signbit ( -- n ) -1 1 rshift invert ;
: xor ( x y -- x^y ) 2dup nand >r r@ nand swap r> nand nand ;
: u< ( x y -- flag ) signbit xor swap signbit xor > ;
\ TODO: um/mod
: variable ( "word" -- )
create /cell allot ;
: ['] \ ( C: "word" -- )
' postpone literal ; immediate

48
samples/GLSL/recurse1.fs Normal file
View File

@@ -0,0 +1,48 @@
#version 330 core
// cross-unit recursion
void main() {}
// two-level recursion
float cbar(int);
void cfoo(float)
{
cbar(2);
}
// four-level, out of order
void CB();
void CD();
void CA() { CB(); }
void CC() { CD(); }
// high degree
void CBT();
void CDT();
void CAT() { CBT(); CBT(); CBT(); }
void CCT() { CDT(); CDT(); CBT(); }
// not recursive
void norA() {}
void norB() { norA(); }
void norC() { norA(); }
void norD() { norA(); }
void norE() { norB(); }
void norF() { norB(); }
void norG() { norE(); }
void norH() { norE(); }
void norI() { norE(); }
// not recursive, but with a call leading into a cycle if ignoring direction
void norcA() { }
void norcB() { norcA(); }
void norcC() { norcB(); }
void norcD() { norcC(); norcB(); } // head of cycle
void norcE() { norcD(); } // lead into cycle

238
samples/Gosu/Ronin.gs Normal file
View File

@@ -0,0 +1,238 @@
/**
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
*/
package ronin
uses gw.util.concurrent.LockingLazyVar
uses gw.lang.reflect.*
uses java.lang.*
uses java.io.*
uses ronin.config.*
uses org.slf4j.*
/**
* The central location for Ronin utility methods. Controllers and templates should generally access the
* methods and properties they inherit from {@link ronin.IRoninUtils} instead of using the methods and
* properties here.
*/
class Ronin {
// One static field to rule the all...
static var _CONFIG : IRoninConfig as Config
// And one thread local to bind them
static var _CURRENT_REQUEST = new ThreadLocal<RoninRequest>();
// That's inconstructable
private construct() {}
internal static function init(servlet : RoninServlet, m : ApplicationMode, src : File) {
if(_CONFIG != null) {
throw "Cannot initialize a Ronin application multiple times!"
}
var cfg = TypeSystem.getByFullNameIfValid("config.RoninConfig")
var defaultWarning = false
if(cfg != null) {
var ctor = cfg.TypeInfo.getConstructor({ronin.config.ApplicationMode, ronin.RoninServlet})
if(ctor == null) {
throw "config.RoninConfig must have a constructor with the same signature as ronin.config.RoninConfig"
}
_CONFIG = ctor.Constructor.newInstance({m, servlet}) as IRoninConfig
} else {
_CONFIG = new DefaultRoninConfig(m, servlet)
defaultWarning = true
}
var roninLogger = TypeSystem.getByFullNameIfValid("ronin.RoninLoggerFactory")
if(roninLogger != null) {
roninLogger.TypeInfo.getMethod("init", {ronin.config.LogLevel}).CallHandler.handleCall(null, {LogLevel})
}
if(defaultWarning) {
log("No configuration was found at config.RoninConfig, using the default configuration...", :level=WARN)
}
Quartz.maybeStart()
ReloadManager.setSourceRoot(src)
}
internal static property set CurrentRequest(req : RoninRequest) {
_CURRENT_REQUEST.set(req)
}
//============================================
// Public API
//============================================
/**
* The trace handler for the current request.
*/
static property get CurrentTrace() : Trace {
return CurrentRequest?.Trace
}
/**
* Ronin's representation of the current request.
*/
static property get CurrentRequest() : RoninRequest {
return _CURRENT_REQUEST.get()
}
/**
* The mode in which this application is running.
*/
static property get Mode() : ApplicationMode {
return _CONFIG?.Mode ?: TESTING
}
/**
* The log level at and above which log messages should be displayed.
*/
static property get LogLevel() : LogLevel {
return _CONFIG?.LogLevel ?: DEBUG
}
/**
* Whether or not to display detailed trace information on each request.
*/
static property get TraceEnabled() : boolean {
return _CONFIG != null ? _CONFIG.TraceEnabled : true
}
/**
* The default controller method to call when no method name is present in the request URL.
*/
static property get DefaultAction() : String {
return _CONFIG?.DefaultAction
}
/**
* The default controller to call when no controller name is present in the request URL.
*/
static property get DefaultController() : Type {
return _CONFIG?.DefaultController
}
/**
* The servlet responsible for handling Ronin requests.
*/
static property get RoninServlet() : RoninServlet {
return _CONFIG?.RoninServlet
}
/**
* The handler for request processing errors.
*/
static property get ErrorHandler() : IErrorHandler {
return _CONFIG?.ErrorHandler
}
/**
* The custom handler for logging messages.
*/
static property get LogHandler() : ILogHandler {
return _CONFIG?.LogHandler
}
/**
* Logs a message using the configured log handler.
* @param msg The text of the message to log, or a block which returns said text.
* @param level (Optional) The level at which to log the message.
* @param component (Optional) The logical component from whence the message originated.
* @param exception (Optional) An exception to associate with the message.
*/
static function log(msg : Object, level : LogLevel = null, component : String = null, exception : java.lang.Throwable = null) {
if(level == null) {
level = INFO
}
if(LogLevel <= level) {
var msgStr : String
if(msg typeis block():String) {
msgStr = (msg as block():String)()
} else {
msgStr = msg as String
}
if(_CONFIG?.LogHandler != null) {
_CONFIG.LogHandler.log(msgStr, level, component, exception)
} else {
switch(level) {
case TRACE:
LoggerFactory.getLogger(component?:Logger.ROOT_LOGGER_NAME).trace(msgStr, exception)
break
case DEBUG:
LoggerFactory.getLogger(component?:Logger.ROOT_LOGGER_NAME).debug(msgStr, exception)
break
case INFO:
LoggerFactory.getLogger(component?:Logger.ROOT_LOGGER_NAME).info(msgStr, exception)
break
case WARN:
LoggerFactory.getLogger(component?:Logger.ROOT_LOGGER_NAME).warn(msgStr, exception)
break
case ERROR:
case FATAL:
LoggerFactory.getLogger(component?:Logger.ROOT_LOGGER_NAME).error(msgStr, exception)
break
}
}
}
}
/**
* The caches known to Ronin.
*/
static enum CacheStore {
REQUEST,
SESSION,
APPLICATION
}
/**
* Retrieves a value from a cache, or computes and stores it if it is not in the cache.
* @param value A block which will compute the desired value.
* @param name (Optional) A unique identifier for the value. Default is null, which means one will be
* generated from the type of the value.
* @param store (Optional) The cache store used to retrieve or store the value. Default is the request cache.
* @return The retrieved or computed value.
*/
static function cache<T>(value : block():T, name : String = null, store : CacheStore = null) : T {
if(store == null or store == REQUEST) {
return _CONFIG.RequestCache.getValue(value, name)
} else if (store == SESSION) {
return _CONFIG.SessionCache.getValue(value, name)
} else if (store == APPLICATION) {
return _CONFIG.ApplicationCache.getValue(value, name)
} else {
throw "Don't know about CacheStore ${store}"
}
}
/**
* Invalidates a cached value in a cache.
* @param name The unique identifier for the value.
* @param store The cache store in which to invalidate the value.
*/
static function invalidate<T>(name : String, store : CacheStore) {
if(store == null or store == REQUEST) {
_CONFIG.RequestCache.invalidate(name)
} else if (store == SESSION) {
_CONFIG.SessionCache.invalidate(name)
} else if (store == APPLICATION) {
_CONFIG.ApplicationCache.invalidate(name)
} else {
throw "Don't know about CacheStore ${store}"
}
}
/**
* Detects changes made to resources in the Ronin application and
* reloads them. This function should only be called when Ronin is
* in development mode.
*/
static function loadChanges() {
ReloadManager.detectAndReloadChangedResources()
}
}

View File

@@ -0,0 +1,18 @@
apply plugin: GreetingPlugin
greeting.message = 'Hi from Gradle'
class GreetingPlugin implements Plugin<Project> {
void apply(Project project) {
// Add the 'greeting' extension object
project.extensions.create("greeting", GreetingPluginExtension)
// Add a task that uses the configuration
project.task('hello') << {
println project.greeting.message
}
}
}
class GreetingPluginExtension {
def String message = 'Hello from GreetingPlugin'
}

View File

@@ -0,0 +1,20 @@
apply plugin: GreetingPlugin
greeting {
message = 'Hi'
greeter = 'Gradle'
}
class GreetingPlugin implements Plugin<Project> {
void apply(Project project) {
project.extensions.create("greeting", GreetingPluginExtension)
project.task('hello') << {
println "${project.greeting.message} from ${project.greeting.greeter}"
}
}
}
class GreetingPluginExtension {
String message
String greeter
}

17
samples/HTML/example.xht Normal file
View File

@@ -0,0 +1,17 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>This is a XHTML sample file</title>
<style type="text/css"><![CDATA[
#example {
background-color: yellow;
}
]]></style>
</head>
<body>
<div id="example">
Just a simple <strong>XHTML</strong> test page.
</div>
</body>
</html>

56
samples/Jasmin/if1.j Normal file
View File

@@ -0,0 +1,56 @@
.class public if1
.super java/lang/Object
;
; standard initializer (calls java.lang.Object's initializer)
;
.method public <init>()V
aload_0
invokenonvirtual java/lang/Object/<init>()V
return
.end method
.method public static main([Ljava/lang/String;)V
.limit locals 1
.limit stack 5
BeginGlobal:
.line 2
ldc 0x1
ldc 0x1
if_icmpeq If556261059
goto IfElse556261059
If556261059:
.line 3
.line 3
getstatic java/lang/System/out Ljava/io/PrintStream;
ldc 0x1
invokevirtual java/io/PrintStream/print(I)V
goto IfDone556261059
IfElse556261059:
.line 5
.line 5
getstatic java/lang/System/out Ljava/io/PrintStream;
ldc 0x2
invokevirtual java/io/PrintStream/print(I)V
IfDone556261059:
.line 6
getstatic java/lang/System/out Ljava/io/PrintStream;
ldc 0x3
invokevirtual java/io/PrintStream/print(I)V
.line 7
ldc 0x1
ldc 0x1
if_icmpne IfNot-920218690
.line 8
.line 8
getstatic java/lang/System/out Ljava/io/PrintStream;
ldc 0x4
invokevirtual java/io/PrintStream/print(I)V
IfNot-920218690:
EndGlobal:
return
.end method

167
samples/Jasmin/if2.j Normal file
View File

@@ -0,0 +1,167 @@
.class public if2
.super java/lang/Object
;
; standard initializer (calls java.lang.Object's initializer)
;
.method public <init>()V
aload_0
invokenonvirtual java/lang/Object/<init>()V
return
.end method
.method public static main([Ljava/lang/String;)V
.limit locals 1
.limit stack 5
BeginGlobal:
.line 2
ldc 0x1
ldc 0x1
if_icmpeq Cmp1893841232
ldc 0x0
goto CmpDone1893841232
Cmp1893841232:
ldc 0x1
CmpDone1893841232:
ldc 0x1
if_icmpeq If-1736765035
goto IfElse-1736765035
If-1736765035:
.line 2
.line 3
getstatic java/lang/System/out Ljava/io/PrintStream;
ldc 0x1
invokevirtual java/io/PrintStream/print(I)V
goto IfDone-1736765035
IfElse-1736765035:
.line 4
.line 4
ldc 0x2
ldc 0x1
if_icmpeq Cmp-1460884369
ldc 0x0
goto CmpDone-1460884369
Cmp-1460884369:
ldc 0x1
CmpDone-1460884369:
ldc 0x1
if_icmpeq If-247349760
goto IfElse-247349760
If-247349760:
.line 4
.line 5
getstatic java/lang/System/out Ljava/io/PrintStream;
ldc 0x2
invokevirtual java/io/PrintStream/print(I)V
goto IfDone-247349760
IfElse-247349760:
.line 6
.line 7
getstatic java/lang/System/out Ljava/io/PrintStream;
ldc 0x3
invokevirtual java/io/PrintStream/print(I)V
IfDone-247349760:
IfDone-1736765035:
.line 10
ldc 0x1
ldc 0x2
if_icmpeq Cmp933554851
ldc 0x0
goto CmpDone933554851
Cmp933554851:
ldc 0x1
CmpDone933554851:
ldc 0x1
if_icmpeq If1623625546
goto IfElse1623625546
If1623625546:
.line 10
.line 11
getstatic java/lang/System/out Ljava/io/PrintStream;
ldc 0x1
invokevirtual java/io/PrintStream/print(I)V
goto IfDone1623625546
IfElse1623625546:
.line 12
.line 12
ldc 0x2
ldc 0x2
if_icmpeq Cmp1572138409
ldc 0x0
goto CmpDone1572138409
Cmp1572138409:
ldc 0x1
CmpDone1572138409:
ldc 0x1
if_icmpeq If126354425
goto IfElse126354425
If126354425:
.line 12
.line 13
getstatic java/lang/System/out Ljava/io/PrintStream;
ldc 0x2
invokevirtual java/io/PrintStream/print(I)V
goto IfDone126354425
IfElse126354425:
.line 14
.line 15
getstatic java/lang/System/out Ljava/io/PrintStream;
ldc 0x3
invokevirtual java/io/PrintStream/print(I)V
IfDone126354425:
IfDone1623625546:
.line 18
ldc 0x1
ldc 0x2
if_icmpeq Cmp126493150
ldc 0x0
goto CmpDone126493150
Cmp126493150:
ldc 0x1
CmpDone126493150:
ldc 0x1
if_icmpeq If1522284422
goto IfElse1522284422
If1522284422:
.line 18
.line 19
getstatic java/lang/System/out Ljava/io/PrintStream;
ldc 0x1
invokevirtual java/io/PrintStream/print(I)V
goto IfDone1522284422
IfElse1522284422:
.line 20
.line 20
ldc 0x2
ldc 0x1
if_icmpeq Cmp-906666545
ldc 0x0
goto CmpDone-906666545
Cmp-906666545:
ldc 0x1
CmpDone-906666545:
ldc 0x1
if_icmpeq If1083939031
goto IfElse1083939031
If1083939031:
.line 20
.line 21
getstatic java/lang/System/out Ljava/io/PrintStream;
ldc 0x2
invokevirtual java/io/PrintStream/print(I)V
goto IfDone1083939031
IfElse1083939031:
.line 22
.line 23
getstatic java/lang/System/out Ljava/io/PrintStream;
ldc 0x3
invokevirtual java/io/PrintStream/print(I)V
IfDone1083939031:
IfDone1522284422:
EndGlobal:
return
.end method

55
samples/Jasmin/if3.j Normal file
View File

@@ -0,0 +1,55 @@
.class public if3
.super java/lang/Object
;
; standard initializer (calls java.lang.Object's initializer)
;
.method public <init>()V
aload_0
invokenonvirtual java/lang/Object/<init>()V
return
.end method
.method public static main([Ljava/lang/String;)V
.limit locals 1
.limit stack 5
BeginGlobal:
.line 2
ldc 0x1
ldc 0x1
if_icmpeq If-811796083
goto IfElse-811796083
If-811796083:
.line 3
.line 3
ldc 0x0
ldc 0x1
if_icmpeq If-1001319390
goto IfElse-1001319390
If-1001319390:
.line 4
.line 4
getstatic java/lang/System/out Ljava/io/PrintStream;
ldc 0x1
invokevirtual java/io/PrintStream/print(I)V
goto IfDone-1001319390
IfElse-1001319390:
.line 6
.line 6
getstatic java/lang/System/out Ljava/io/PrintStream;
ldc 0x2
invokevirtual java/io/PrintStream/print(I)V
IfDone-1001319390:
goto IfDone-811796083
IfElse-811796083:
.line 8
.line 8
getstatic java/lang/System/out Ljava/io/PrintStream;
ldc 0x3
invokevirtual java/io/PrintStream/print(I)V
IfDone-811796083:
EndGlobal:
return
.end method

37
samples/Jasmin/if4.j Normal file
View File

@@ -0,0 +1,37 @@
.class public if4
.super java/lang/Object
;
; standard initializer (calls java.lang.Object's initializer)
;
.method public <init>()V
aload_0
invokenonvirtual java/lang/Object/<init>()V
return
.end method
.method public static main([Ljava/lang/String;)V
.limit locals 1
.limit stack 5
BeginGlobal:
.line 2
ldc 0x1
ldc 0x1
if_icmpne IfNot1919266740
.line 2
.line 2
ldc 0x1
ldc 0x1
if_icmpne IfNot613368541
.line 2
.line 2
getstatic java/lang/System/out Ljava/io/PrintStream;
ldc 0x1
invokevirtual java/io/PrintStream/print(I)V
IfNot613368541:
IfNot1919266740:
EndGlobal:
return
.end method

54
samples/Jasmin/op1.j Normal file
View File

@@ -0,0 +1,54 @@
.class public op1
.super java/lang/Object
;
; standard initializer (calls java.lang.Object's initializer)
;
.method public <init>()V
aload_0
invokenonvirtual java/lang/Object/<init>()V
return
.end method
.method public static main([Ljava/lang/String;)V
.limit locals 1
.limit stack 5
BeginGlobal:
.line 2
getstatic java/lang/System/out Ljava/io/PrintStream;
ldc 0x1
ldc 0x1
iadd
invokevirtual java/io/PrintStream/println(I)V
.line 3
getstatic java/lang/System/out Ljava/io/PrintStream;
ldc 0xa
ldc 0x5
isub
invokevirtual java/io/PrintStream/println(I)V
.line 4
getstatic java/lang/System/out Ljava/io/PrintStream;
ldc 0x15
ldc 0x3
idiv
invokevirtual java/io/PrintStream/println(I)V
.line 5
getstatic java/lang/System/out Ljava/io/PrintStream;
ldc 0x159
ldc 0x38
imul
invokevirtual java/io/PrintStream/println(I)V
.line 6
getstatic java/lang/System/out Ljava/io/PrintStream;
ldc 0x52
ldc 0x9
irem
invokevirtual java/io/PrintStream/println(I)V
EndGlobal:
return
.end method

34
samples/Jasmin/op2.j Normal file
View File

@@ -0,0 +1,34 @@
.class public op2
.super java/lang/Object
;
; standard initializer (calls java.lang.Object's initializer)
;
.method public <init>()V
aload_0
invokenonvirtual java/lang/Object/<init>()V
return
.end method
.method public static main([Ljava/lang/String;)V
.limit locals 1
.limit stack 5
BeginGlobal:
.line 2
getstatic java/lang/System/out Ljava/io/PrintStream;
ldc 0x1
ldc 0x0
iand
invokevirtual java/io/PrintStream/println(Z)V
.line 3
getstatic java/lang/System/out Ljava/io/PrintStream;
ldc 0x1
ldc 0x0
ior
invokevirtual java/io/PrintStream/println(Z)V
EndGlobal:
return
.end method

68
samples/Jasmin/op3.j Normal file
View File

@@ -0,0 +1,68 @@
.class public op3
.super java/lang/Object
;
; standard initializer (calls java.lang.Object's initializer)
;
.method public <init>()V
aload_0
invokenonvirtual java/lang/Object/<init>()V
return
.end method
.method public static main([Ljava/lang/String;)V
.limit locals 1
.limit stack 5
BeginGlobal:
.line 2
getstatic java/lang/System/out Ljava/io/PrintStream;
ldc 0x0
ldc 0x1
if_icmpeq Cmp-1307183590
ldc 0x0
goto CmpDone-1307183590
Cmp-1307183590:
ldc 0x1
CmpDone-1307183590:
invokevirtual java/io/PrintStream/println(Z)V
.line 3
getstatic java/lang/System/out Ljava/io/PrintStream;
ldc 0x0
ldc 0x0
if_icmpeq Cmp-1443270821
ldc 0x0
goto CmpDone-1443270821
Cmp-1443270821:
ldc 0x1
CmpDone-1443270821:
invokevirtual java/io/PrintStream/println(Z)V
.line 4
getstatic java/lang/System/out Ljava/io/PrintStream;
ldc 0x1
ldc 0x1
if_icmpeq Cmp1759327329
ldc 0x0
goto CmpDone1759327329
Cmp1759327329:
ldc 0x1
CmpDone1759327329:
invokevirtual java/io/PrintStream/println(Z)V
.line 5
getstatic java/lang/System/out Ljava/io/PrintStream;
ldc 0x1
ldc 0x0
if_icmpeq Cmp-678570146
ldc 0x0
goto CmpDone-678570146
Cmp-678570146:
ldc 0x1
CmpDone-678570146:
invokevirtual java/io/PrintStream/println(Z)V
EndGlobal:
return
.end method

68
samples/Jasmin/op4.j Normal file
View File

@@ -0,0 +1,68 @@
.class public op4
.super java/lang/Object
;
; standard initializer (calls java.lang.Object's initializer)
;
.method public <init>()V
aload_0
invokenonvirtual java/lang/Object/<init>()V
return
.end method
.method public static main([Ljava/lang/String;)V
.limit locals 1
.limit stack 5
BeginGlobal:
.line 2
getstatic java/lang/System/out Ljava/io/PrintStream;
ldc 0x0
ldc 0x1
if_icmpne Cmp-191731100
ldc 0x0
goto CmpDone-191731100
Cmp-191731100:
ldc 0x1
CmpDone-191731100:
invokevirtual java/io/PrintStream/println(Z)V
.line 3
getstatic java/lang/System/out Ljava/io/PrintStream;
ldc 0x0
ldc 0x0
if_icmpne Cmp-901585603
ldc 0x0
goto CmpDone-901585603
Cmp-901585603:
ldc 0x1
CmpDone-901585603:
invokevirtual java/io/PrintStream/println(Z)V
.line 4
getstatic java/lang/System/out Ljava/io/PrintStream;
ldc 0x1
ldc 0x1
if_icmpne Cmp1522577937
ldc 0x0
goto CmpDone1522577937
Cmp1522577937:
ldc 0x1
CmpDone1522577937:
invokevirtual java/io/PrintStream/println(Z)V
.line 5
getstatic java/lang/System/out Ljava/io/PrintStream;
ldc 0x1
ldc 0x0
if_icmpne Cmp-1653028684
ldc 0x0
goto CmpDone-1653028684
Cmp-1653028684:
ldc 0x1
CmpDone-1653028684:
invokevirtual java/io/PrintStream/println(Z)V
EndGlobal:
return
.end method

View File

@@ -0,0 +1,78 @@
/*
License
Copyright [2013] [Farruco Sanjurjo Arcay]
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
*/
var TagsTotalPerMonth;
TagsTotalPerMonth = (function(){
function TagsTotalPerMonth(){};
TagsTotalPerMonth.getDatasource = function (category, months, values){
return new CategoryMonthlyExpenseBarChartDataSource(category, months, values);
};
TagsTotalPerMonth.getType = function (){ return Charts.ChartType.COLUMN};
return TagsTotalPerMonth;
})();
var TagsTotalPerMonthWithMean;
TagsTotalPerMonthWithMean = (function(){
function TagsTotalPerMonthWithMean(){};
TagsTotalPerMonthWithMean.getDatasource = function (category, months, values){
return new CategoryMonthlyWithMeanExpenseDataSource(category, months, values);
};
TagsTotalPerMonthWithMean.getType = function (){ return Charts.ChartType.LINE};
return TagsTotalPerMonthWithMean;
})();
var TagsAccumulatedPerMonth;
TagsAccumulatedPerMonth = (function(){
function TagsAccumulatedPerMonth(){};
TagsAccumulatedPerMonth.getDatasource = function (category, months, values){
return new CategoryMonthlyAccumulated(category, months, values);
};
TagsAccumulatedPerMonth.getType = function (){ return Charts.ChartType.AREA};
return TagsAccumulatedPerMonth;
})();
var MonthTotalsPerTags;
MonthTotalsPerTags = (function(){
function MonthTotalsPerTags(){};
MonthTotalsPerTags.getDatasource = function (month, tags, values){
return new CategoryExpenseDataSource(tags, month, values);
};
MonthTotalsPerTags.getType = function (){ return Charts.ChartType.PIE; };
return MonthTotalsPerTags;
})();
var SavingsFlowChartComposer = (function(){
function SavingsFlowChartComposer(){};
SavingsFlowChartComposer.getDatasource = function(months, values){
return new SavingsFlowDataSource(months, values);
};
SavingsFlowChartComposer.getType = function(){ return Charts.ChartType.COLUMN; };
return SavingsFlowChartComposer;
})();

150
samples/JavaScript/itau.gs Normal file
View File

@@ -0,0 +1,150 @@
/*
The MIT License (MIT)
Copyright (c) 2014 Thiago Brandão Damasceno
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
// based on http://ctrlq.org/code/19053-send-to-google-drive
function sendToGoogleDrive() {
var gmailLabels = 'inbox';
var driveFolder = 'Itaú Notifications';
var spreadsheetName = 'itau';
var archiveLabel = 'itau.processed';
var itauNotificationEmail = 'comunicacaodigital@itau-unibanco.com.br';
var filter = "from: " +
itauNotificationEmail +
" -label:" +
archiveLabel +
" label:" +
gmailLabels;
// Create label for 'itau.processed' if it doesn't exist
var moveToLabel = GmailApp.getUserLabelByName(archiveLabel);
if (!moveToLabel) {
moveToLabel = GmailApp.createLabel(archiveLabel);
}
// Create folder 'Itaú Notifications' if it doesn't exist
var folders = DriveApp.getFoldersByName(driveFolder);
var folder;
if (folders.hasNext()) {
folder = folders.next();
} else {
folder = DriveApp.createFolder(driveFolder);
}
// Create spreadsheet file 'itau' if it doesn't exist
var files = folder.getFilesByName(spreadsheetName);
// File is in DriveApp
// Doc is in SpreadsheetApp
// They are not interchangeable
var file, doc;
// Confusing :\
// As per: https://code.google.com/p/google-apps-script-issues/issues/detail?id=3578
if (files.hasNext()){
file = files.next();
doc = SpreadsheetApp.openById(file.getId());
} else {
doc = SpreadsheetApp.create(spreadsheetName);
file = DriveApp.getFileById(doc.getId());
folder.addFile(file);
DriveApp.removeFile(file);
}
var sheet = doc.getSheets()[0];
// Append header if first line
if(sheet.getLastRow() == 0){
sheet.appendRow(['Conta', 'Operação', 'Valor', 'Data', 'Hora', 'Email ID']);
}
var message, messages, account, operation, value, date, hour, emailID, plainBody;
var accountRegex = /Conta: (XXX[0-9\-]+)/;
var operationRegex = /Tipo de operação: ([A-Z]+)/;
var paymentRegex = /Pagamento de ([0-9A-Za-z\-]+)\ ?([0-9]+)?/;
var valueRegex = /Valor: R\$ ([0-9\,\.]+)/;
var dateRegex = /Data: ([0-9\/]+)/;
var hourRegex = /Hora: ([0-9\:]+)/;
var emailIDRegex = /E-mail nº ([0-9]+)/;
var threads = GmailApp.search(filter, 0, 100);
for (var x = 0; x < threads.length; x++) {
messages = threads[x].getMessages();
for (var i = 0; i < messages.length; i++) {
account, operation, value, date, hour, emailID = [];
message = messages[i];
plainBody = message.getPlainBody();
if(accountRegex.test(plainBody)) {
account = RegExp.$1;
}
if(operationRegex.test(plainBody)) {
operation = RegExp.$1;
}
if(valueRegex.test(plainBody)) {
value = RegExp.$1;
}
if(dateRegex.test(plainBody)) {
date = RegExp.$1;
}
if(hourRegex.test(plainBody)) {
hour = RegExp.$1;
}
if(emailIDRegex.test(plainBody)){
emailID = RegExp.$1;
}
if(paymentRegex.test(plainBody)){
operation = RegExp.$1;
if(RegExp.$2){
operation += ' ' + RegExp.$2
}
date = hour = ' - ';
}
if(account && operation && value && date && hour){
sheet.appendRow([account, operation, value, date, hour, emailID]);
}
// Logger.log(account);
// Logger.log(operation);
// Logger.log(value);
// Logger.log(date);
// Logger.log(hour);
}
threads[x].addLabel(moveToLabel);
}
}

View File

@@ -0,0 +1,93 @@
(function(root, factory) {
if (typeof define === 'function' && define.amd) {
define(['lodash'], factory);
} else if (typeof exports !== 'undefined') {
module.exports = factory(require('lodash'));
} else {
root.Namespace = factory(root._);
}
})(this, function(_) {
'use strict';
/**
* @module namespace
* @class namespace
*/
function Namespace() {}
/**
* Regex for splitting keypaths into arrays.
*
* @private
* @const {RegExp}
* @type
*/
var KEYPATH_SPLITTER = /\./g;
/**
* An internal cache to avoid calculating a keypath more than once.
*
* @private
* @type {Object}
*/
var _keypaths = {};
_.extend(Namespace.prototype, {
/**
* Adds a definition to the namespace object.
*
* @public
* @instance
* @method add
* @param {String} keypath - The keypath for the definition to be added at.
* @param {Function|Object} definition - The definition to be added.
* @return {Function|Object} - The definition.
*/
add: function(keypath, definition) {
return this._walk(keypath, function(memo, name, index, keypath) {
if (index + 1 === keypath.length) {
memo[name] = _.extend(definition, memo[name]);
}
return memo[name] || (memo[name] = {});
});
},
/**
* Retrieves a definition from the namespace safely.
*
* @public
* @instance
* @method get
* @param {String} keypath - The keypath to lookup a definition for.
* @returns {Function|Object|undefined} - The definition if it exists, otherwise `undefined`.
*/
get: function(keypath) {
return this._walk(keypath);
},
/**
* An internal function for walking a keypath.
*
* @private
* @instance
* @method _walk
* @param {String} keypath - The keypath to walk through.
* @param {Function} [callback] - An optional callback to be called at each item in the path.
* @returns {function|Object|undefined} - The reduced keypath.
*/
_walk: function(keypath, callback) {
return _.reduce(
_keypaths[keypath] || (_keypaths[keypath] = keypath.split(KEYPATH_SPLITTER)),
callback || function(memo, name) {
return memo && memo[name];
},
this
);
}
});
return Namespace;
});
//# sourceMappingURL=namespace.js.map

View File

@@ -0,0 +1,38 @@
package
{
import loom.Application;
import loom2d.display.StageScaleMode;
import loom2d.ui.SimpleLabel;
/**
The HelloWorld app renders a label with its name on it,
and traces 'hello' to the log.
*/
public class HelloWorld extends Application
{
override public function run():void
{
stage.scaleMode = StageScaleMode.LETTERBOX;
centeredMessage(simpleLabel, this.getFullTypeName());
trace("hello");
}
// a convenience getter that generates a label and adds it to the stage
private function get simpleLabel():SimpleLabel
{
return stage.addChild(new SimpleLabel("assets/Curse-hd.fnt")) as SimpleLabel;
}
// a utility to set the label's text and then center it on the stage
private function centeredMessage(label:SimpleLabel, msg:String):void
{
label.text = msg;
label.center();
label.x = stage.stageWidth / 2;
label.y = (stage.stageHeight / 2) - (label.height / 2);
}
}
}

View File

@@ -0,0 +1,137 @@
package
{
import loom.Application;
public interface I {}
public class C {}
public class B extends C implements I {}
final public class A extends B {}
delegate ToCompute(s:String, o:Object):Number;
public enum Enumeration
{
foo,
baz,
cat,
}
struct P {
public var x:Number = 0;
public var y:Number = 0;
public static operator function =(a:P, b:P):P
{
a.x = b.x;
a.y = b.y;
return a;
}
}
// single-line comment
/*
Multi-line comment
*/
/**
Doc comment
*/
public class SyntaxExercise extends Application
{
static public var classVar:String = 'class variable';
public const CONST:String = 'constant';
private var _a:A = new A();
public var _d:ToCompute;
override public function run():void
{
trace("hello");
}
private function get a():A { return _a; }
private function set a(value:A):void { _a = value; }
private function variousTypes(defaultValue:String = ''):void
{
var nil:Object = null;
var b1:Boolean = true;
var b2:Boolean = false;
var n1:Number = 0.123;
var n2:Number = 12345;
var n3:Number = 0xfed;
var s1:String = 'single-quotes with "quotes" inside';
var s2:String = "double-quotes with 'quotes' inside";
var f1:Function = function (life:String, universe:Object, ...everything):Number { return 42; };
var v1:Vector.<Number> = [1, 2];
var d1:Dictionary.<String, Number> = { 'three': 3, 'four': 4 };
_d += f1;
_d -= f1;
}
private function variousOps():void
{
var a = ((100 + 200 - 0) / 300) % 2;
var b = 100 * 30;
var d = true && (b > 301);
var e = 0x10 | 0x01;
b++; b--;
a += 300; a -= 5; a *= 4; a /= 2; a %= 7;
var castable1:Boolean = (a is B);
var castable2:Boolean = (a as B) != null;
var cast:String = B(a).toString();
var instanced:Boolean = (_a instanceof A);
}
private function variousFlow():void
{
var n:Number = Math.random();
if (n > 0.6)
trace('top 40!');
else if(n > 0.3)
trace('mid 30!');
else
trace('bottom 30');
var flip:String = (Math.random() > 0.5) ? 'heads' : 'tails';
for (var i = 0; i < 100; i++)
trace(i);
var v:Vector.<String> = ['a', 'b', 'c'];
for each (var s:String in v)
trace(s);
var d:Dictionary.<String, Number> = { 'one': 1 };
for (var key1:String in d)
trace(key1);
for (var key2:Number in v)
trace(key2);
while (i > 0)
{
i--;
if (i == 13) continue;
trace(i);
}
do
{
i++;
}
while (i < 10);
switch (Math.floor(Math.random()) * 3 + 1)
{
case 1 : trace('rock'); break;
case 2 : trace('paper'); break;
default: trace('scissors'); break;
}
}
}
}

View File

@@ -0,0 +1,434 @@
//
// AppController.j
// FlickrPhoto
//
// Created by Ross Boucher.
// Copyright 2008 - 2010, 280 North, Inc. All rights reserved.
@import <Foundation/Foundation.j>
@import <AppKit/AppKit.j>
var SliderToolbarItemIdentifier = "SliderToolbarItemIdentifier",
AddToolbarItemIdentifier = "AddToolbarItemIdentifier",
RemoveToolbarItemIdentifier = "RemoveToolbarItemIdentifier";
/*
Important note about CPJSONPConnection: CPJSONPConnection is ONLY for JSONP APIs.
If aren't sure you NEED JSONP (see http://ajaxian.com/archives/jsonp-json-with-padding ),
you most likely don't want to use CPJSONPConnection, but rather the more standard
CPURLConnection. CPJSONPConnection is designed for cross-domain
connections, and if you are making requests to the same domain (as most web
applications do), you do not need it.
*/
@implementation AppController : CPObject
{
CPString lastIdentifier;
CPDictionary photosets;
CPCollectionView listCollectionView;
CPCollectionView photosCollectionView;
}
- (void)applicationDidFinishLaunching:(CPNotification)aNotification
{
//the first thing we need to do is create a window to take up the full screen
//we'll also create a toolbar to go with it, and grab its size for future reference
var theWindow = [[CPWindow alloc] initWithContentRect:CGRectMakeZero() styleMask:CPBorderlessBridgeWindowMask],
contentView = [theWindow contentView],
toolbar = [[CPToolbar alloc] initWithIdentifier:"Photos"],
bounds = [contentView bounds];
//we tell the toolbar that we want to be its delegate and attach it to theWindow
[toolbar setDelegate:self];
[toolbar setVisible:true];
[theWindow setToolbar:toolbar];
photosets = [CPDictionary dictionary]; //storage for our sets of photos return from Flickr
//now we create a scroll view to contain the list of collections of photos (photosets)
//inside the scroll view, we'll place our collection view, which manages a collection of "cells"
//each cell will represent one photo collection, and choosing cells will select that collection
var listScrollView = [[CPScrollView alloc] initWithFrame:CGRectMake(0, 0, 200, CGRectGetHeight(bounds) - 58)];
[listScrollView setAutohidesScrollers:YES];
[listScrollView setAutoresizingMask:CPViewHeightSizable];
[[listScrollView contentView] setBackgroundColor:[CPColor colorWithRed:213.0 / 255.0 green:221.0 / 255.0 blue:230.0 / 255.0 alpha:1.0]];
//we create the collection view cells by creating a single prototype (CPCollectionViewItem) and setting its view.
//the CPCollectionView class will then duplicate this item as many times as it needs
var photosListItem = [[CPCollectionViewItem alloc] init];
[photosListItem setView:[[PhotosListCell alloc] initWithFrame:CGRectMakeZero()]];
listCollectionView = [[CPCollectionView alloc] initWithFrame:CGRectMake(0, 0, 200, 0)];
[listCollectionView setDelegate:self]; //we want delegate methods
[listCollectionView setItemPrototype:photosListItem]; //set the item prototype
[listCollectionView setMinItemSize:CGSizeMake(20.0, 45.0)];
[listCollectionView setMaxItemSize:CGSizeMake(1000.0, 45.0)];
[listCollectionView setMaxNumberOfColumns:1]; //setting a single column will make this appear as a vertical list
[listCollectionView setVerticalMargin:0.0];
[listCollectionView setAutoresizingMask:CPViewWidthSizable];
//finally, we put our collection view inside the scroll view as it's document view, so it can be scrolled
[listScrollView setDocumentView:listCollectionView];
//and we add it to the window's content view, so it will show up on the screen
[contentView addSubview:listScrollView];
//repeat the process with another collection view for the actual photos
//this time we'll use a different view for the prototype (PhotoCell)
var photoItem = [[CPCollectionViewItem alloc] init];
[photoItem setView:[[PhotoCell alloc] initWithFrame:CGRectMake(0, 0, 150, 150)]];
var scrollView = [[CPScrollView alloc] initWithFrame:CGRectMake(200, 0, CGRectGetWidth(bounds) - 200, CGRectGetHeight(bounds) - 58)];
photosCollectionView = [[CPCollectionView alloc] initWithFrame:CGRectMake(0, 0, CGRectGetWidth(bounds) - 200, 0)];
[photosCollectionView setDelegate:self];
[photosCollectionView setItemPrototype:photoItem];
[photosCollectionView setMinItemSize:CGSizeMake(150, 150)];
[photosCollectionView setMaxItemSize:CGSizeMake(150, 150)];
[photosCollectionView setAutoresizingMask:CPViewWidthSizable];
[scrollView setAutoresizingMask:CPViewHeightSizable | CPViewWidthSizable];
[scrollView setDocumentView:photosCollectionView];
[scrollView setAutohidesScrollers:YES];
[[scrollView contentView] setBackgroundColor:[CPColor colorWithCalibratedWhite:0.25 alpha:1.0]];
[contentView addSubview:scrollView];
//bring forward the window to display it
[theWindow orderFront:self];
//get the most interesting photos on flickr
var request = [CPURLRequest requestWithURL:"http://www.flickr.com/services/rest/?method=flickr.interestingness.getList&per_page=20&format=json&api_key=ca4dd89d3dfaeaf075144c3fdec76756"];
// see important note about CPJSONPConnection above
var connection = [CPJSONPConnection sendRequest:request callback:"jsoncallback" delegate:self];
lastIdentifier = "Interesting Photos";
}
- (void)add:(id)sender
{
var string = prompt("Enter a tag to search Flickr for photos.");
if (string)
{
//create a new request for the photos with the tag returned from the javascript prompt
var request = [CPURLRequest requestWithURL:"http://www.flickr.com/services/rest/?"+
"method=flickr.photos.search&tags="+encodeURIComponent(string)+
"&media=photos&machine_tag_mode=any&per_page=20&format=json&api_key=ca4dd89d3dfaeaf075144c3fdec76756"];
// see important note about CPJSONPConnection above
[CPJSONPConnection sendRequest:request callback:"jsoncallback" delegate:self];
lastIdentifier = string;
}
}
- (void)remove:(id)sender
{
//remove this photo
[self removeImageListWithIdentifier:[[photosets allKeys] objectAtIndex:[[listCollectionView selectionIndexes] firstIndex]]];
}
- (void)addImageList:(CPArray)images withIdentifier:(CPString)aString
{
[photosets setObject:images forKey:aString];
[listCollectionView setContent:[[photosets allKeys] copy]];
[listCollectionView setSelectionIndexes:[CPIndexSet indexSetWithIndex:[[photosets allKeys] indexOfObject:aString]]];
}
- (void)removeImageListWithIdentifier:(CPString)aString
{
var nextIndex = MAX([[listCollectionView content] indexOfObject:aString] - 1, 0);
[photosets removeObjectForKey:aString];
[listCollectionView setContent:[[photosets allKeys] copy]];
[listCollectionView setSelectionIndexes:[CPIndexSet indexSetWithIndex:nextIndex]];
}
- (void)adjustImageSize:(id)sender
{
var newSize = [sender value];
[photosCollectionView setMinItemSize:CGSizeMake(newSize, newSize)];
[photosCollectionView setMaxItemSize:CGSizeMake(newSize, newSize)];
}
- (void)collectionViewDidChangeSelection:(CPCollectionView)aCollectionView
{
if (aCollectionView == listCollectionView)
{
var listIndex = [[listCollectionView selectionIndexes] firstIndex];
if (listIndex === CPNotFound)
return;
var key = [listCollectionView content][listIndex];
[photosCollectionView setContent:[photosets objectForKey:key]];
[photosCollectionView setSelectionIndexes:[CPIndexSet indexSet]];
}
}
- (void)connection:(CPJSONPConnection)aConnection didReceiveData:(CPString)data
{
//this method is called when the network request returns. the data is the returned
//information from flickr. we set the array of photo urls as the data to our collection view
[self addImageList:data.photos.photo withIdentifier:lastIdentifier];
}
- (void)connection:(CPJSONPConnection)aConnection didFailWithError:(CPString)error
{
alert(error); //a network error occurred
}
//these two methods are the toolbar delegate methods, and tell the toolbar what it should display to the user
- (CPArray)toolbarAllowedItemIdentifiers:(CPToolbar)aToolbar
{
return [self toolbarDefaultItemIdentifiers:aToolbar];
}
- (CPArray)toolbarDefaultItemIdentifiers:(CPToolbar)aToolbar
{
return [AddToolbarItemIdentifier, RemoveToolbarItemIdentifier, CPToolbarFlexibleSpaceItemIdentifier, SliderToolbarItemIdentifier];
}
//this delegate method returns the actual toolbar item for the given identifier
- (CPToolbarItem)toolbar:(CPToolbar)aToolbar itemForItemIdentifier:(CPString)anItemIdentifier willBeInsertedIntoToolbar:(BOOL)aFlag
{
var toolbarItem = [[CPToolbarItem alloc] initWithItemIdentifier:anItemIdentifier];
if (anItemIdentifier == SliderToolbarItemIdentifier)
{
[toolbarItem setView:[[PhotoResizeView alloc] initWithFrame:CGRectMake(0, 0, 180, 32)]];
[toolbarItem setMinSize:CGSizeMake(180, 32)];
[toolbarItem setMaxSize:CGSizeMake(180, 32)];
[toolbarItem setLabel:"Scale"];
}
else if (anItemIdentifier == AddToolbarItemIdentifier)
{
var image = [[CPImage alloc] initWithContentsOfFile:[[CPBundle mainBundle] pathForResource:"add.png"] size:CPSizeMake(30, 25)],
highlighted = [[CPImage alloc] initWithContentsOfFile:[[CPBundle mainBundle] pathForResource:"addHighlighted.png"] size:CPSizeMake(30, 25)];
[toolbarItem setImage:image];
[toolbarItem setAlternateImage:highlighted];
[toolbarItem setTarget:self];
[toolbarItem setAction:@selector(add:)];
[toolbarItem setLabel:"Add Photo List"];
[toolbarItem setMinSize:CGSizeMake(32, 32)];
[toolbarItem setMaxSize:CGSizeMake(32, 32)];
}
else if (anItemIdentifier == RemoveToolbarItemIdentifier)
{
var image = [[CPImage alloc] initWithContentsOfFile:[[CPBundle mainBundle] pathForResource:"remove.png"] size:CPSizeMake(30, 25)],
highlighted = [[CPImage alloc] initWithContentsOfFile:[[CPBundle mainBundle] pathForResource:"removeHighlighted.png"] size:CPSizeMake(30, 25)];
[toolbarItem setImage:image];
[toolbarItem setAlternateImage:highlighted];
[toolbarItem setTarget:self];
[toolbarItem setAction:@selector(remove:)];
[toolbarItem setLabel:"Remove Photo List"];
[toolbarItem setMinSize:CGSizeMake(32, 32)];
[toolbarItem setMaxSize:CGSizeMake(32, 32)];
}
return toolbarItem;
}
@end
/*
This code demonstrates how to add a category to an existing class.
In this case, we are adding the class method +flickr_labelWithText: to
the CPTextField class. Later on, we can call [CPTextField flickr_labelWithText:"foo"]
to return a new text field with the string foo.
Best practices suggest prefixing category methods with your unique prefix, to prevent collisions.
*/
@implementation CPTextField (CreateLabel)
+ (CPTextField)flickr_labelWithText:(CPString)aString
{
var label = [[CPTextField alloc] initWithFrame:CGRectMakeZero()];
[label setStringValue:aString];
[label sizeToFit];
[label setTextShadowColor:[CPColor whiteColor]];
[label setTextShadowOffset:CGSizeMake(0, 1)];
return label;
}
@end
// This class wraps our slider + labels combo
@implementation PhotoResizeView : CPView
{
}
- (id)initWithFrame:(CGRect)aFrame
{
self = [super initWithFrame:aFrame];
var slider = [[CPSlider alloc] initWithFrame:CGRectMake(30, CGRectGetHeight(aFrame) / 2.0 - 8, CGRectGetWidth(aFrame) - 65, 24)];
[slider setMinValue:50.0];
[slider setMaxValue:250.0];
[slider setIntValue:150.0];
[slider setAction:@selector(adjustImageSize:)];
[self addSubview:slider];
var label = [CPTextField flickr_labelWithText:"50"];
[label setFrameOrigin:CGPointMake(0, CGRectGetHeight(aFrame) / 2.0 - 4.0)];
[self addSubview:label];
label = [CPTextField flickr_labelWithText:"250"];
[label setFrameOrigin:CGPointMake(CGRectGetWidth(aFrame) - CGRectGetWidth([label frame]), CGRectGetHeight(aFrame) / 2.0 - 4.0)];
[self addSubview:label];
return self;
}
@end
// This class displays a single photo collection inside our list of photo collecitions
@implementation PhotosListCell : CPView
{
CPTextField label;
CPView highlightView;
}
- (void)setRepresentedObject:(JSObject)anObject
{
if (!label)
{
label = [[CPTextField alloc] initWithFrame:CGRectInset([self bounds], 4, 4)];
[label setFont:[CPFont systemFontOfSize:16.0]];
[label setTextShadowColor:[CPColor whiteColor]];
[label setTextShadowOffset:CGSizeMake(0, 1)];
[self addSubview:label];
}
[label setStringValue:anObject];
[label sizeToFit];
[label setFrameOrigin:CGPointMake(10,CGRectGetHeight([label bounds]) / 2.0)];
}
- (void)setSelected:(BOOL)flag
{
if (!highlightView)
{
highlightView = [[CPView alloc] initWithFrame:CGRectCreateCopy([self bounds])];
[highlightView setBackgroundColor:[CPColor blueColor]];
}
if (flag)
{
[self addSubview:highlightView positioned:CPWindowBelow relativeTo:label];
[label setTextColor:[CPColor whiteColor]];
[label setTextShadowColor:[CPColor blackColor]];
}
else
{
[highlightView removeFromSuperview];
[label setTextColor:[CPColor blackColor]];
[label setTextShadowColor:[CPColor whiteColor]];
}
}
@end
// This class displays a single photo from our collection
@implementation PhotoCell : CPView
{
CPImage image;
CPImageView imageView;
CPView highlightView;
}
- (void)setRepresentedObject:(JSObject)anObject
{
if (!imageView)
{
imageView = [[CPImageView alloc] initWithFrame:CGRectMakeCopy([self bounds])];
[imageView setAutoresizingMask:CPViewWidthSizable | CPViewHeightSizable];
[imageView setImageScaling:CPScaleProportionally];
[imageView setHasShadow:YES];
[self addSubview:imageView];
}
[image setDelegate:nil];
image = [[CPImage alloc] initWithContentsOfFile:thumbForFlickrPhoto(anObject)];
[image setDelegate:self];
if ([image loadStatus] == CPImageLoadStatusCompleted)
[imageView setImage:image];
else
[imageView setImage:nil];
}
- (void)imageDidLoad:(CPImage)anImage
{
[imageView setImage:anImage];
}
- (void)setSelected:(BOOL)flag
{
if (!highlightView)
{
highlightView = [[CPView alloc] initWithFrame:[self bounds]];
[highlightView setBackgroundColor:[CPColor colorWithCalibratedWhite:0.8 alpha:0.6]];
[highlightView setAutoresizingMask:CPViewWidthSizable | CPViewHeightSizable];
}
if (flag)
{
[highlightView setFrame:[self bounds]];
[self addSubview:highlightView positioned:CPWindowBelow relativeTo:imageView];
}
else
[highlightView removeFromSuperview];
}
@end
// helper javascript functions for turning a Flickr photo object into a URL for getting the image
function urlForFlickrPhoto(photo)
{
return "http://farm" + photo.farm + ".static.flickr.com/" + photo.server + "/" + photo.id+"_" + photo.secret + ".jpg";
}
function thumbForFlickrPhoto(photo)
{
return "http://farm" + photo.farm + ".static.flickr.com/" + photo.server + "/" + photo.id + "_" + photo.secret + "_m.jpg";
}

View File

@@ -0,0 +1,88 @@
@import <Foundation/CPObject.j>
@import <AppKit/CPView.j>
@import <AppKit/CPButton.j>
@import <AppKit/CPWebView.j>
@import "LOBoard.j"
@implementation LOInfoView : CPView
{
}
- (void)drawRect:(CGRect)r
{
[[CPColor whiteColor] setFill]
var path = [CPBezierPath bezierPath];
[path appendBezierPathWithRoundedRect:CGRectMake(5, 0, CGRectGetWidth([self bounds]) - 10.0, CGRectGetHeight([self bounds])) xRadius:10 yRadius:10];
[path fill];
}
@end
@implementation AppController : CPObject
{
}
- (CPPanel)initInfoWindow
{
var infoWindow = [[CPPanel alloc] initWithContentRect:CGRectMake(400, 50, 320, 480) styleMask:CPHUDBackgroundWindowMask | CPResizableWindowMask];
[infoWindow setFloatingPanel:YES];
var _infoContent = [infoWindow contentView],
_iconImage = [[CPImage alloc] initWithContentsOfFile:"Resources/icon.png" size:CPSizeMake(59, 60)],
_iconView = [[CPImageView alloc] initWithFrame:CGRectMake(125, 0, 59, 60)];
[_iconView setImage:_iconImage];
[_infoContent addSubview:_iconView];
var _infoView = [[LOInfoView alloc] initWithFrame:CGRectMake(0, 65, 320, 395)],
_webView = [[CPWebView alloc] initWithFrame:CGRectMake(20, 0, 270, 370)];
[_webView loadHTMLString:@"<center><h3>Lights Off</h3></center> <p>Lights Off is a fantastic game exclusively for iPhone and iPod touch and inspired by Tiger Electronic's 'Lights Out'.</p> <p>The goal of the game is simply to switch all of the lights off, but it's harder than it looks! Give the first few levels a try in the playable demo to the left.</p><center><img src='Resources/avail_on_app_store.png'></center>"];
[_infoView addSubview:_webView];
[_infoContent addSubview:_infoView];
return infoWindow;
}
- (void)applicationDidFinishLaunching:(CPNotification)aNotification
{
/* Enable Logging (DEBUG) */
// CPLogRegister(CPLogPopup);
var rootWindow = [[CPWindow alloc] initWithContentRect:CGRectMakeZero() styleMask:CPBorderlessBridgeWindowMask];
[rootWindow setBackgroundColor:[CPColor grayColor]];
[rootWindow orderFront:self];
var infoWindow = [self initInfoWindow],
gameWindow = [[CPPanel alloc] initWithContentRect:CGRectMake(50, 50, 324, 482) styleMask:CPHUDBackgroundWindowMask];
[gameWindow setFloatingPanel:YES];
[gameWindow setTitle:@"Lights Off"];
contentView = [gameWindow contentView];
var _board = [[LOBoard alloc] initWithFrame:CGRectMake(2, 0, 320, 480)],
_bgImage = [[CPImage alloc] initWithContentsOfFile:"Resources/lo-background.png" size:CPSizeMake(320, 480)];
[_board setImage:_bgImage];
[_board resetBoard];
var _buttonImage = [[CPImage alloc] initWithContentsOfFile:"Resources/button-reset.png" size:CPSizeMake(90, 28)],
_buttonPressImage = [[CPImage alloc] initWithContentsOfFile:"Resources/button-reset-press.png" size:CPSizeMake(90, 28)],
_resetButton = [[CPButton alloc] initWithFrame:CGRectMake(195, 422, 90, 28)];
[_resetButton setImage:_buttonImage];
[_resetButton setAlternateImage:_buttonPressImage];
[_resetButton setBordered:NO];
[contentView addSubview:_board];
[contentView addSubview:_resetButton];
[_resetButton setTarget:_board];
[_resetButton setAction:@selector(resetBoard)];
[gameWindow orderFront:self];
[infoWindow orderFront:self];
}
@end

View File

@@ -0,0 +1,47 @@
@import <Foundation/CPObject.j>
@implementation AppController : CPObject
{
}
- (void)applicationDidFinishLaunching:(CPNotification)aNotification
{
// The end result of this layout will be the kind of master/detail/auxilliary view
// found in iTunes, Mail, and many other apps.
var theWindow = [[CPWindow alloc] initWithContentRect:CGRectMakeZero() styleMask:CPBorderlessBridgeWindowMask],
contentView = [theWindow contentView];
var navigationArea = [[CPView alloc] initWithFrame:CGRectMake(0.0, 0.0, 150.0, CGRectGetHeight([contentView bounds]) - 150.0)];
[navigationArea setBackgroundColor:[CPColor redColor]];
// This view will grow in height, but stay fixed width attached to the left side of the screen.
[navigationArea setAutoresizingMask:CPViewHeightSizable | CPViewMaxXMargin];
[contentView addSubview:navigationArea];
var metaDataArea = [[CPView alloc] initWithFrame:CGRectMake(0.0, CGRectGetMaxY([navigationArea frame]), 150.0, 150.0)];
[metaDataArea setBackgroundColor:[CPColor greenColor]];
// This view will stay the same size in both directions, and fixed to the lower left corner.
[metaDataArea setAutoresizingMask:CPViewMinYMargin | CPViewMaxXMargin];
[contentView addSubview:metaDataArea];
var contentArea = [[CPView alloc] initWithFrame:CGRectMake(150.0, 0.0, CGRectGetWidth([contentView bounds]) - 150.0, CGRectGetHeight([contentView bounds]))];
[contentArea setBackgroundColor:[CPColor blueColor]];
// This view will grow in both height an width.
[contentArea setAutoresizingMask:CPViewWidthSizable | CPViewHeightSizable];
[contentView addSubview:contentArea];
[theWindow orderFront:self];
}
@end

52
samples/Oz/example.oz Normal file
View File

@@ -0,0 +1,52 @@
% You can get a lot of information about Oz by following theses links :
% - http://mozart.github.io/
% - http://en.wikipedia.org/wiki/Oz_(programming_language)
% There is also a well known book that uses Oz for pedagogical reason :
% - http://mitpress.mit.edu/books/concepts-techniques-and-models-computer-programming
% And there are two courses on edX about 'Paradigms of Computer Programming' that also uses Oz for pedagogical reason :
% - https://www.edx.org/node/2751#.VHijtfl5OSo
% - https://www.edx.org/node/4436#.VHijzfl5OSo
%
% Here is an example of some code written with Oz.
declare
% Computes the sum of square of the N first integers.
fun {Sum N}
local SumAux in
fun {SumAux N Acc}
if N==0 then Acc
else
{Sum N-1 Acc}
end
end
{SumAux N 0}
end
end
% Returns true if N is a prime and false otherwize
fun {Prime N}
local PrimeAcc in
fun {PrimeAcc N Acc}
if(N == 1) then false
elseif(Acc == 1) then true
else
if (N mod Acc) == 0 then false
else
{PrimeAcc N Acc-1}
end
end
end
{PrimeAcc N (N div 2)}
end
end
% Reverse a list using cells and for loop (instead of recursivity)
fun {Reverse L}
local RevList in
RevList = {NewCell nil}
for E in L do
RevList := E|@RevList
end
@RevList
end
end

View File

@@ -0,0 +1,97 @@
use v6;
use Test;
=begin pod
Test handling of -I.
Multiple C<-I> switches are supposed to
prepend left-to-right:
-Ifoo -Ibar
should make C<@*INC> look like:
foo
bar
...
Duplication of directories on the command line is mirrored
in the C<@*INC> variable, so C<pugs -Ilib -Ilib> will have B<two>
entries C<lib/> in C<@*INC>.
=end pod
# L<S19/Reference/"Prepend directories to">
my $fragment = '-e "@*INC.perl.say"';
my @tests = (
'foo',
'foo$bar',
'foo bar$baz',
'foo$foo',
);
plan @tests*2;
diag "Running under $*OS";
my ($pugs,$redir) = ($*EXECUTABLE_NAME, ">");
if $*OS eq any <MSWin32 mingw msys cygwin> {
$pugs = 'pugs.exe';
$redir = '>';
};
sub nonce () { return (".{$*PID}." ~ (1..1000).pick) }
sub run_pugs ($c) {
my $tempfile = "temp-ex-output" ~ nonce;
my $command = "$pugs $c $redir $tempfile";
diag $command;
run $command;
my $res = slurp $tempfile;
unlink $tempfile;
return $res;
}
for @tests -> $t {
my @dirs = split('$',$t);
my $command;
# This should be smarter about quoting
# (currently, this should work for WinNT and Unix shells)
$command = join " ", map { qq["-I$_"] }, @dirs;
my $got = run_pugs( $command ~ " $fragment" );
$got .= chomp;
if (substr($got,0,1) ~~ "[") {
# Convert from arrayref to array
$got = substr($got, 1, -1);
};
my @got = EVAL $got;
@got = @got[ 0..@dirs-1 ];
my @expected = @dirs;
is @got, @expected, "'" ~ @dirs ~ "' works";
$command = join " ", map { qq[-I "$_"] }, @dirs;
$got = run_pugs( $command ~ " $fragment" );
$got .= chomp;
if (substr($got,0,1) ~~ "[") {
# Convert from arrayref to array
$got = substr($got, 1, -1);
};
@got = EVAL $got;
@got = @got[ 0..@dirs-1 ];
@expected = @dirs;
is @got, @expected, "'" ~ @dirs ~ "' works (with a space delimiting -I)";
}
# vim: ft=perl6

223
samples/Perl6/01-parse.t Normal file
View File

@@ -0,0 +1,223 @@
use v6;
BEGIN { @*INC.push('lib') };
use JSON::Tiny::Grammar;
use Test;
my @t =
'{}',
'{ }',
' { } ',
'{ "a" : "b" }',
'{ "a" : null }',
'{ "a" : true }',
'{ "a" : false }',
'{ "a" : { } }',
'[]',
'[ ]',
' [ ] ',
# stolen from JSON::XS, 18_json_checker.t, and adapted a bit
Q<<[
"JSON Test Pattern pass1",
{"object with 1 member":["array with 1 element"]},
{},
[]
]>>,
Q<<[1]>>,
Q<<[true]>>,
Q<<[-42]>>,
Q<<[-42,true,false,null]>>,
Q<<{ "integer": 1234567890 }>>,
Q<<{ "real": -9876.543210 }>>,
Q<<{ "e": 0.123456789e-12 }>>,
Q<<{ "E": 1.234567890E+34 }>>,
Q<<{ "": 23456789012E66 }>>,
Q<<{ "zero": 0 }>>,
Q<<{ "one": 1 }>>,
Q<<{ "space": " " }>>,
Q<<{ "quote": "\""}>>,
Q<<{ "backslash": "\\"}>>,
Q<<{ "controls": "\b\f\n\r\t"}>>,
Q<<{ "slash": "/ & \/"}>>,
Q<<{ "alpha": "abcdefghijklmnopqrstuvwyz"}>>,
Q<<{ "ALPHA": "ABCDEFGHIJKLMNOPQRSTUVWYZ"}>>,
Q<<{ "digit": "0123456789"}>>,
Q<<{ "0123456789": "digit"}>>,
Q<<{"special": "`1~!@#$%^&*()_+-={':[,]}|;.</>?"}>>,
Q<<{"hex": "\u0123\u4567\u89AB\uCDEF\uabcd\uef4A"}>>,
Q<<{"true": true}>>,
Q<<{"false": false}>>,
Q<<{"null": null}>>,
Q<<{"array":[ ]}>>,
Q<<{"object":{ }}>>,
Q<<{"address": "50 St. James Street"}>>,
Q<<{"url": "http://www.JSON.org/"}>>,
Q<<{"comment": "// /* <!-- --"}>>,
Q<<{"# -- --> */": " "}>>,
Q<<{ " s p a c e d " :[1,2 , 3
,
4 , 5 , 6 ,7 ],"compact":[1,2,3,4,5,6,7]}>>,
Q<<{"jsontext": "{\"object with 1 member\":[\"array with 1 element\"]}"}>>,
Q<<{"quotes": "&#34; \u0022 %22 0x22 034 &#x22;"}>>,
Q<<{ "\/\\\"\uCAFE\uBABE\uAB98\uFCDE\ubcda\uef4A\b\f\n\r\t`1~!@#$%^&*()_+-=[]{}|;:',./<>?"
: "A key can be any string"
}>>,
Q<<[ 0.5 ,98.6
,
99.44
,
1066,
1e1,
0.1e1
]>>,
Q<<[1e-1]>>,
Q<<[1e00,2e+00,2e-00,"rosebud"]>>,
Q<<[[[[[[[[[[[[[[[[[[["Not too deep"]]]]]]]]]]]]]]]]]]]>>,
Q<<{
"JSON Test Pattern pass3": {
"The outermost value": "must be an object or array.",
"In this test": "It is an object."
}
}
>>,
# from http://www.json.org/example.html
Q<<{
"glossary": {
"title": "example glossary",
"GlossDiv": {
"title": "S",
"GlossList": {
"GlossEntry": {
"ID": "SGML",
"SortAs": "SGML",
"GlossTerm": "Standard Generalized Markup Language",
"Acronym": "SGML",
"Abbrev": "ISO 8879:1986",
"GlossDef": {
"para": "A meta-markup language, used to create markup languages such as DocBook.",
"GlossSeeAlso": ["GML", "XML"]
},
"GlossSee": "markup"
}
}
}
}
}
>>,
Q<<{"menu": {
"id": "file",
"value": "File",
"popup": {
"menuitem": [
{"value": "New", "onclick": "CreateNewDoc()"},
{"value": "Open", "onclick": "OpenDoc()"},
{"value": "Close", "onclick": "CloseDoc()"}
]
}
}}>>,
Q<<{"widget": {
"debug": "on",
"window": {
"title": "Sample Konfabulator Widget",
"name": "main_window",
"width": 500,
"height": 500
},
"image": {
"src": "Images/Sun.png",
"name": "sun1",
"hOffset": 250,
"vOffset": 250,
"alignment": "center"
},
"text": {
"data": "Click Here",
"size": 36,
"style": "bold",
"name": "text1",
"hOffset": 250,
"vOffset": 100,
"alignment": "center",
"onMouseUp": "sun1.opacity = (sun1.opacity / 100) * 90;"
}
}}>>,
;
my @n =
'{ ',
'{ 3 : 4 }',
'{ 3 : tru }', # not quite true
'{ "a : false }', # missing quote
# stolen from JSON::XS, 18_json_checker.t
Q<<"A JSON payload should be an object or array, not a string.">>,
Q<<{"Extra value after close": true} "misplaced quoted value">>,
Q<<{"Illegal expression": 1 + 2}>>,
Q<<{"Illegal invocation": alert()}>>,
Q<<{"Numbers cannot have leading zeroes": 013}>>,
Q<<{"Numbers cannot be hex": 0x14}>>,
Q<<["Illegal backslash escape: \x15"]>>,
Q<<[\naked]>>,
Q<<["Illegal backslash escape: \017"]>>,
# skipped: wo don't implement no stinkin' aritifical limits.
# Q<<[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[["Too deep"]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]>>,
Q<<{"Missing colon" null}>>,
Q<<["Unclosed array">>,
Q<<{"Double colon":: null}>>,
Q<<{"Comma instead of colon", null}>>,
Q<<["Colon instead of comma": false]>>,
Q<<["Bad value", truth]>>,
Q<<['single quote']>>,
qq<["\ttab\tcharacter in string "]>,
Q<<["line
break"]>>,
Q<<["line\
break"]>>,
Q<<[0e]>>,
Q<<{unquoted_key: "keys must be quoted"}>>,
Q<<[0e+]>>,
Q<<[0e+-1]>>,
Q<<{"Comma instead if closing brace": true,>>,
Q<<["mismatch"}>>,
Q<<["extra comma",]>>,
Q<<["double extra comma",,]>>,
Q<<[ , "<-- missing value"]>>,
Q<<["Comma after the close"],>>,
Q<<["Extra close"]]>>,
Q<<{"Extra comma": true,}>>,
;
plan (+@t) + (+@n);
my $i = 0;
for @t -> $t {
my $desc = $t;
if $desc ~~ m/\n/ {
$desc .= subst(/\n.*$/, "\\n...[$i]");
}
my $parsed = 0;
try {
JSON::Tiny::Grammar.parse($t)
and $parsed = 1;
}
ok $parsed, "JSON string «$desc» parsed";
$i++;
}
for @n -> $t {
my $desc = $t;
if $desc ~~ m/\n/ {
$desc .= subst(/\n.*$/, "\\n...[$i]");
}
my $parsed = 0;
try { JSON::Tiny::Grammar.parse($t) and $parsed = 1 };
nok $parsed, "NOT parsed «$desc»";
$i++;
}
# vim: ft=perl6

9
samples/Perl6/A.pm Normal file
View File

@@ -0,0 +1,9 @@
# used in t/spec/S11-modules/nested.t
BEGIN { @*INC.push('t/spec/packages') };
module A::A {
use A::B;
}
# vim: ft=perl6

148
samples/Perl6/ANSIColor.pm Normal file
View File

@@ -0,0 +1,148 @@
use v6;
module Term::ANSIColor;
# these will be macros one day, yet macros can't be exported so far
sub RESET is export { "\e[0m" }
sub BOLD is export { "\e[1m" }
sub UNDERLINE is export { "\e[4m" }
sub INVERSE is export { "\e[7m" }
sub BOLD_OFF is export { "\e[22m" }
sub UNDERLINE_OFF is export { "\e[24m" }
sub INVERSE_OFF is export { "\e[27m" }
my %attrs =
reset => "0",
bold => "1",
underline => "4",
inverse => "7",
black => "30",
red => "31",
green => "32",
yellow => "33",
blue => "34",
magenta => "35",
cyan => "36",
white => "37",
default => "39",
on_black => "40",
on_red => "41",
on_green => "42",
on_yellow => "43",
on_blue => "44",
on_magenta => "45",
on_cyan => "46",
on_white => "47",
on_default => "49";
sub color (Str $what) is export {
my @res;
my @a = $what.split(' ');
for @a -> $attr {
if %attrs.exists($attr) {
@res.push: %attrs{$attr}
} else {
die("Invalid attribute name '$attr'")
}
}
return "\e[" ~ @res.join(';') ~ "m";
}
sub colored (Str $what, Str $how) is export {
color($how) ~ $what ~ color('reset');
}
sub colorvalid (*@a) is export {
for @a -> $el {
return False unless %attrs.exists($el)
}
return True;
}
sub colorstrip (*@a) is export {
my @res;
for @a -> $str {
@res.push: $str.subst(/\e\[ <[0..9;]>+ m/, '', :g);
}
return @res.join;
}
sub uncolor (Str $what) is export {
my @res;
my @list = $what.comb(/\d+/);
for @list -> $elem {
if %attrs.reverse.exists($elem) {
@res.push: %attrs.reverse{$elem}
} else {
die("Bad escape sequence: {'\e[' ~ $elem ~ 'm'}")
}
}
return @res.join(' ');
}
=begin pod
=head1 NAME
Term::ANSIColor - Color screen output using ANSI escape sequences
=head1 SYNOPSIS
use Term::ANSIColor;
say color('bold'), "this is in bold", color('reset');
say colored('underline red on_green', 'what a lovely colours!');
say BOLD, 'good to be fat!', BOLD_OFF;
say 'ok' if colorvalid('magenta', 'on_black', 'inverse');
say '\e[36m is ', uncolor('\e36m');
say colorstrip("\e[1mThis is bold\e[0m");
=head1 DESCRIPTION
Term::ANSIColor provides an interface for using colored output
in terminals. The following functions are available:
=head2 C<color()>
Given a string with color names, the output produced by C<color()>
sets the terminal output so the text printed after it will be colored
as specified. The following color names are recognised:
reset bold underline inverse black red green yellow blue
magenta cyan white default on_black on_red on_green on_yellow
on_blue on_magenta on_cyan on_white on_default
The on_* family of colors correspond to the background colors.
=head2 C<colored()>
C<colored()> is similar to C<color()>. It takes two Str arguments,
where the first is the colors to be used, and the second is the string
to be colored. The C<reset> sequence is automagically placed after
the string.
=head2 C<colorvalid()>
C<colorvalid()> gets an array of color specifications (like those
passed to C<color()>) and returns true if all of them are valid,
false otherwise.
=head2 C<colorstrip()>
C<colorstrip>, given a string, removes all the escape sequences
in it, leaving the plain text without effects.
=head2 C<uncolor()>
Given escape sequences, C<uncolor()> returns a string with readable
color names. E.g. passing "\e[36;44m" will result in "cyan on_blue".
=head1 Constants
C<Term::ANSIColor> provides constants which are just strings of
appropriate escape sequences. The following constants are available:
RESET BOLD UNDERLINE INVERSE BOLD_OFF UNDERLINE_OFF INVERSE_OFF
=end pod
# vim: ft=perl6

102
samples/Perl6/Bailador.pm Normal file
View File

@@ -0,0 +1,102 @@
use Bailador::App;
use Bailador::Request;
use Bailador::Response;
use Bailador::Context;
use HTTP::Easy::PSGI;
module Bailador;
my $app = Bailador::App.current;
our sub import {
my $file = callframe(1).file;
my $slash = $file.rindex('/');
if $slash {
$app.location = $file.substr(0, $file.rindex('/'));
} else {
$app.location = '.';
}
}
sub route_to_regex($route) {
$route.split('/').map({
my $r = $_;
if $_.substr(0, 1) eq ':' {
$r = q{(<-[\/\.]>+)};
}
$r
}).join("'/'");
}
multi parse_route(Str $route) {
my $r = route_to_regex($route);
return "/ ^ $r \$ /".eval;
}
multi parse_route($route) {
# do nothing
$route
}
sub get(Pair $x) is export {
my $p = parse_route($x.key) => $x.value;
$app.add_route: 'GET', $p;
return $x;
}
sub post(Pair $x) is export {
my $p = parse_route($x.key) => $x.value;
$app.add_route: 'POST', $p;
return $x;
}
sub request is export { $app.context.request }
sub content_type(Str $type) is export {
$app.response.headers<Content-Type> = $type;
}
sub header(Str $name, Cool $value) is export {
$app.response.headers{$name} = ~$value;
}
sub status(Int $code) is export {
$app.response.code = $code;
}
sub template(Str $tmpl, *@params) is export {
$app.template($tmpl, @params);
}
our sub dispatch_request(Bailador::Request $r) {
return dispatch($r.env);
}
sub dispatch($env) {
$app.context.env = $env;
my ($r, $match) = $app.find_route($env);
if $r {
status 200;
if $match {
$app.response.content = $r.value.(|$match.list);
} else {
$app.response.content = $r.value.();
}
}
return $app.response;
}
sub dispatch-psgi($env) {
return dispatch($env).psgi;
}
sub baile is export {
given HTTP::Easy::PSGI.new(port => 3000) {
.app(&dispatch-psgi);
say "Entering the development dance floor: http://0.0.0.0:3000";
.run;
}
}

View File

@@ -0,0 +1,7 @@
module ContainsUnicode {
sub uc-and-join(*@things, :$separator = ', ') is export {
@things».uc.join($separator)
}
}
# vim: ft=perl6

1431
samples/Perl6/Exception.pm Normal file

File diff suppressed because it is too large Load Diff

146
samples/Perl6/Model.pm Normal file
View File

@@ -0,0 +1,146 @@
use v6;
class Math::Model;
use Math::RungeKutta;
# TODO: only load when needed
use SVG;
use SVG::Plot;
has %.derivatives;
has %.variables;
has %.initials;
has @.captures is rw;
has %!inv = %!derivatives.invert;
# in Math::Model all variables are accessible by name
# in contrast Math::RungeKutta uses vectors, so we need
# to define an (arbitrary) ordering
# @!deriv-names holds the names of the derivatives in a fixed
# order, sod @!deriv-names[$number] turns the number into a name
# %!deriv-keying{$name} translates a name into the corresponding index
has @!deriv-names = %!inv.keys;
has %!deriv-keying = @!deriv-names Z=> 0..Inf;
# snapshot of all variables in the current model
has %!current-values;
has %.results;
has @.time;
has $.numeric-error is rw = 0.0001;
my sub param-names(&c) {
&c.signature.params».name».substr(1).grep({ $_ ne '_'});
}
method !params-for(&c) {
param-names(&c).map( {; $_ => %!current-values{$_} } ).hash;
}
method topo-sort(*@vars) {
my %seen;
my @order;
sub topo(*@a) {
for @a {
next if %!inv.exists($_) || %seen{$_} || $_ eq 'time';
die "Undeclared variable '$_' used in model"
unless %.variables.exists($_);
topo(param-names(%.variables{$_}));
@order.push: $_;
%seen{$_}++;
}
}
topo(@vars);
# say @order.perl;
@order;
}
method integrate(:$from = 0, :$to = 10, :$min-resolution = ($to - $from) / 20, :$verbose) {
for %.derivatives -> $d {
die "There must be a variable defined for each derivative, missing for '$d.key()'"
unless %.variables.exists($d.key) || %!inv.exists($d.key);
die "There must be an initial value defined for each derivative target, missing for '$d.value()'"
unless %.initials.exists($d.value);
}
%!current-values = %.initials;
%!current-values<time> = $from;
my @vars-topo = self.topo-sort(%.variables.keys);
sub update-current-values($time, @values) {
%!current-values<time> = $time;
%!current-values{@!deriv-names} = @values;
for @vars-topo {
my $c = %.variables{$_};
%!current-values{$_} = $c.(|self!params-for($c));
}
}
my @initial = %.initials{@!deriv-names};
sub derivatives($time, @values) {
update-current-values($time, @values);
my @r;
for %!inv{@!deriv-names} {
my $v = %.variables{$_};
@r.push: $v.defined
?? $v(|self!params-for($v))
!! %!current-values{$_};
}
@r;
}
@!time = ();
for @.captures {
%!results{$_} = [];
}
sub record($time, @values) {
update-current-values($time, @values);
@!time.push: $time;
say $time if $verbose;
for @.captures {
%!results{$_}.push: %!current-values{$_};;
}
}
record($from, %.initials{@!deriv-names});
adaptive-rk-integrate(
:$from,
:$to,
:@initial,
:derivative(&derivatives),
:max-stepsize($min-resolution),
:do(&record),
:epsilon($.numeric-error),
);
%!results;
}
method render-svg(
$filename,
:$x-axis = 'time',
:$width = 800,
:$height = 600,
:$title = 'Model output') {
my $f = open $filename, :w
or die "Can't open file '$filename' for writing: $!";
my @values = map { %!results{$_} }, @.captures.grep({ $_ ne $x-axis});
my @x = $x-axis eq 'time' ?? @!time !! %!results{$x-axis}.flat;
my $svg = SVG::Plot.new(
:$width,
:$height,
:@x,
:@values,
:$title,
).plot(:xy-lines);
$f.say(SVG.serialize($svg));
$f.close;
say "Wrote ouput to '$filename'";
}
# vim: ft=perl6

317
samples/Perl6/Simple.pm Normal file
View File

@@ -0,0 +1,317 @@
# ----------------------
# LWP::Simple for Perl 6
# ----------------------
use v6;
use MIME::Base64;
use URI;
class LWP::Simple:auth<cosimo>:ver<0.085>;
our $VERSION = '0.085';
enum RequestType <GET POST>;
has Str $.default_encoding = 'utf-8';
our $.class_default_encoding = 'utf-8';
# these were intended to be constant but that hit pre-compilation issue
my Buf $crlf = Buf.new(13, 10);
my Buf $http_header_end_marker = Buf.new(13, 10, 13, 10);
my Int constant $default_stream_read_len = 2 * 1024;
method base64encode ($user, $pass) {
my MIME::Base64 $mime .= new();
my $encoded = $mime.encode_base64($user ~ ':' ~ $pass);
return $encoded;
}
method get (Str $url) {
self.request_shell(RequestType::GET, $url)
}
method post (Str $url, %headers = {}, Any $content?) {
self.request_shell(RequestType::POST, $url, %headers, $content)
}
method request_shell (RequestType $rt, Str $url, %headers = {}, Any $content?) {
return unless $url;
my ($scheme, $hostname, $port, $path, $auth) = self.parse_url($url);
%headers{'Connection'} = 'close';
%headers{'User-Agent'} //= "LWP::Simple/$VERSION Perl6/$*PERL<compiler><name>";
if $auth {
$hostname = $auth<host>;
my $user = $auth<user>;
my $pass = $auth<password>;
my $base64enc = self.base64encode($user, $pass);
%headers<Authorization> = "Basic $base64enc";
}
%headers<Host> = $hostname;
if ($rt ~~ RequestType::POST && $content.defined) {
# Attach Content-Length header
# as recommended in RFC2616 section 14.3.
# Note: Empty content is also a content,
# header value equals to zero is valid.
%headers{'Content-Length'} = $content.encode.bytes;
}
my ($status, $resp_headers, $resp_content) =
self.make_request($rt, $hostname, $port, $path, %headers, $content);
given $status {
when / 30 <[12]> / {
my %resp_headers = $resp_headers.hash;
my $new_url = %resp_headers<Location>;
if ! $new_url {
die "Redirect $status without a new URL?";
}
# Watch out for too many redirects.
# Need to find a way to store a class member
#if $redirects++ > 10 {
# say "Too many redirects!";
# return;
#}
return self.request_shell($rt, $new_url, %headers, $content);
}
when /200/ {
# should be fancier about charset decoding application - someday
if $resp_headers<Content-Type> &&
$resp_headers<Content-Type> ~~
/ $<media-type>=[<-[/;]>+]
[ <[/]> $<media-subtype>=[<-[;]>+] ]? / &&
( $<media-type> eq 'text' ||
( $<media-type> eq 'application' &&
$<media-subtype> ~~ /[ ecma | java ]script | json/
)
)
{
my $charset =
($resp_headers<Content-Type> ~~ /charset\=(<-[;]>*)/)[0];
$charset = $charset ?? $charset.Str !!
self ?? $.default_encoding !! $.class_default_encoding;
return $resp_content.decode($charset);
}
else {
return $resp_content;
}
}
# Response failed
default {
return;
}
}
}
method parse_chunks(Blob $b is rw, IO::Socket::INET $sock) {
my Int ($line_end_pos, $chunk_len, $chunk_start) = (0) xx 3;
my Blob $content = Blob.new();
# smallest valid chunked line is 0CRLFCRLF (ascii or other 8bit like EBCDIC)
while ($line_end_pos + 5 <= $b.bytes) {
while ( $line_end_pos +4 <= $b.bytes &&
$b.subbuf($line_end_pos, 2) ne $crlf
) {
$line_end_pos++
}
# say "got here x0x pos ", $line_end_pos, ' bytes ', $b.bytes, ' start ', $chunk_start, ' some data ', $b.subbuf($chunk_start, $line_end_pos +2 - $chunk_start).decode('ascii');
if $line_end_pos +4 <= $b.bytes &&
$b.subbuf(
$chunk_start, $line_end_pos + 2 - $chunk_start
).decode('ascii') ~~ /^(<.xdigit>+)[";"|"\r\n"]/
{
# deal with case of chunk_len is 0
$chunk_len = :16($/[0].Str);
# say 'got chunk len ', $/[0].Str;
# test if at end of buf??
if $chunk_len == 0 {
# this is a "normal" exit from the routine
return True, $content;
}
# think 1CRLFxCRLF
if $line_end_pos + $chunk_len + 4 <= $b.bytes {
# say 'inner chunk';
$content ~= $b.subbuf($line_end_pos +2, $chunk_len);
$line_end_pos = $chunk_start = $line_end_pos + $chunk_len +4;
}
else {
# say 'last chunk';
# remaining chunk part len is chunk_len with CRLF
# minus the length of the chunk piece at end of buffer
my $last_chunk_end_len =
$chunk_len +2 - ($b.bytes - $line_end_pos -2);
$content ~= $b.subbuf($line_end_pos +2);
if $last_chunk_end_len > 2 {
$content ~= $sock.read($last_chunk_end_len -2);
}
# clean up CRLF after chunk
$sock.read(min($last_chunk_end_len, 2));
# this is a` "normal" exit from the routine
return False, $content;
}
}
else {
# say 'extend bytes ', $b.bytes, ' start ', $chunk_start, ' data ', $b.subbuf($chunk_start).decode('ascii');
# maybe odd case of buffer has just part of header at end
$b ~= $sock.read(20);
}
}
# say join ' ', $b[0 .. 100];
# say $b.subbuf(0, 100).decode('utf-8');
die "Could not parse chunk header";
}
method make_request (
RequestType $rt, $host, $port as Int, $path, %headers, $content?
) {
my $headers = self.stringify_headers(%headers);
my IO::Socket::INET $sock .= new(:$host, :$port);
my Str $req_str = $rt.Stringy ~ " {$path} HTTP/1.1\r\n"
~ $headers
~ "\r\n";
# attach $content if given
# (string context is forced by concatenation)
$req_str ~= $content if $content.defined;
$sock.send($req_str);
my Blob $resp = $sock.read($default_stream_read_len);
my ($status, $resp_headers, $resp_content) = self.parse_response($resp);
if (($resp_headers<Transfer-Encoding> || '') eq 'chunked') {
my Bool $is_last_chunk;
my Blob $resp_content_chunk;
($is_last_chunk, $resp_content) =
self.parse_chunks($resp_content, $sock);
while (not $is_last_chunk) {
($is_last_chunk, $resp_content_chunk) =
self.parse_chunks(
my Blob $next_chunk_start = $sock.read(1024),
$sock
);
$resp_content ~= $resp_content_chunk;
}
}
elsif ( $resp_headers<Content-Length> &&
$resp_content.bytes < $resp_headers<Content-Length>
) {
$resp_content ~= $sock.read(
$resp_headers<Content-Length> - $resp_content.bytes
);
}
else { # a bit hacky for now but should be ok
while ($resp.bytes > 0) {
$resp = $sock.read($default_stream_read_len);
$resp_content ~= $resp;
}
}
$sock.close();
return ($status, $resp_headers, $resp_content);
}
method parse_response (Blob $resp) {
my %header;
my Int $header_end_pos = 0;
while ( $header_end_pos < $resp.bytes &&
$http_header_end_marker ne $resp.subbuf($header_end_pos, 4) ) {
$header_end_pos++;
}
if ($header_end_pos < $resp.bytes) {
my @header_lines = $resp.subbuf(
0, $header_end_pos
).decode('ascii').split(/\r\n/);
my Str $status_line = @header_lines.shift;
for @header_lines {
my ($name, $value) = .split(': ');
%header{$name} = $value;
}
return $status_line, %header.item, $resp.subbuf($header_end_pos +4).item;
}
die "could not parse headers";
# if %header.exists('Transfer-Encoding') && %header<Transfer-Encoding> ~~ m/:i chunked/ {
# @content = self.decode_chunked(@content);
# }
}
method getprint (Str $url) {
my $out = self.get($url);
if $out ~~ Buf { $*OUT.write($out) } else { say $out }
}
method getstore (Str $url, Str $filename) {
return unless defined $url;
my $content = self.get($url);
if ! $content {
return
}
my $fh = open($filename, :bin, :w);
if $content ~~ Buf {
$fh.write($content)
}
else {
$fh.print($content)
}
$fh.close;
}
method parse_url (Str $url) {
my URI $u .= new($url);
my $path = $u.path_query;
my $user_info = $u.grammar.parse_result<URI_reference><URI><hier_part><authority><userinfo>;
return (
$u.scheme,
$user_info ?? "{$user_info}@{$u.host}" !! $u.host,
$u.port,
$path eq '' ?? '/' !! $path,
$user_info ?? {
host => $u.host,
user => ~ $user_info<likely_userinfo_component>[0],
password => ~ $user_info<likely_userinfo_component>[1]
} !! Nil
);
}
method stringify_headers (%headers) {
my Str $str = '';
for sort %headers.keys {
$str ~= $_ ~ ': ' ~ %headers{$_} ~ "\r\n";
}
return $str;
}

207
samples/Perl6/Win32.pm Normal file
View File

@@ -0,0 +1,207 @@
my class IO::Spec::Win32 is IO::Spec::Unix {
# Some regexes we use for path splitting
my $slash = regex { <[\/ \\]> }
my $notslash = regex { <-[\/ \\]> }
my $driveletter = regex { <[A..Z a..z]> ':' }
my $UNCpath = regex { [<$slash> ** 2] <$notslash>+ <$slash> [<$notslash>+ | $] }
my $volume_rx = regex { <$driveletter> | <$UNCpath> }
method canonpath ($path, :$parent) {
$path eq '' ?? '' !! self!canon-cat($path, :$parent);
}
method catdir(*@dirs) {
return "" unless @dirs;
return self!canon-cat( "\\", |@dirs ) if @dirs[0] eq "";
self!canon-cat(|@dirs);
}
method splitdir($dir) { $dir.split($slash) }
method catfile(|c) { self.catdir(|c) }
method devnull { 'nul' }
method rootdir { '\\' }
method tmpdir {
first( { .defined && .IO.d && .IO.w },
%*ENV<TMPDIR>,
%*ENV<TEMP>,
%*ENV<TMP>,
'SYS:/temp',
'C:\system\temp',
'C:/temp',
'/tmp',
'/')
|| self.curdir;
}
method path {
my @path = split(';', %*ENV<PATH>);
@path».=subst(:global, q/"/, '');
@path = grep *.chars, @path;
unshift @path, ".";
return @path;
}
method is-absolute ($path) {
# As of right now, this returns 2 if the path is absolute with a
# volume, 1 if it's absolute with no volume, 0 otherwise.
given $path {
when /^ [<$driveletter> <$slash> | <$UNCpath>]/ { 2 }
when /^ <$slash> / { 1 }
default { 0 }
} #/
}
method split ($path as Str is copy) {
$path ~~ s[ <$slash>+ $] = '' #=
unless $path ~~ /^ <$driveletter>? <$slash>+ $/;
$path ~~
m/^ ( <$volume_rx> ? )
( [ .* <$slash> ]? )
(.*)
/;
my ($volume, $directory, $basename) = (~$0, ~$1, ~$2);
$directory ~~ s/ <?after .> <$slash>+ $//;
if all($directory, $basename) eq '' && $volume ne '' {
$directory = $volume ~~ /^<$driveletter>/
?? '.' !! '\\';
}
$basename = '\\' if $directory eq any('/', '\\') && $basename eq '';
$directory = '.' if $directory eq '' && $basename ne '';
return (:$volume, :$directory, :$basename);
}
method join ($volume, $directory is copy, $file is copy) {
$directory = '' if $directory eq '.' && $file.chars;
if $directory.match( /^<$slash>$/ ) && $file.match( /^<$slash>$/ ) {
$file = '';
$directory = '' if $volume.chars > 2; #i.e. UNC path
}
self.catpath($volume, $directory, $file);
}
method splitpath($path as Str, :$nofile = False) {
my ($volume,$directory,$file) = ('','','');
if ( $nofile ) {
$path ~~
/^ (<$volume_rx>?) (.*) /;
$volume = ~$0;
$directory = ~$1;
}
else {
$path ~~
m/^ ( <$volume_rx> ? )
( [ .* <$slash> [ '.' ** 1..2 $]? ]? )
(.*)
/;
$volume = ~$0;
$directory = ~$1;
$file = ~$2;
}
return ($volume,$directory,$file);
}
method catpath($volume is copy, $directory, $file) {
# Make sure the glue separator is present
# unless it's a relative path like A:foo.txt
if $volume.chars and $directory.chars
and $volume !~~ /^<$driveletter>/
and $volume !~~ /<$slash> $/
and $directory !~~ /^ <$slash>/
{ $volume ~= '\\' }
if $file.chars and $directory.chars
and $directory !~~ /<$slash> $/
{ $volume ~ $directory ~ '\\' ~ $file; }
else { $volume ~ $directory ~ $file; }
}
method rel2abs ($path is copy, $base? is copy) {
my $is_abs = self.is-absolute($path);
# Check for volume (should probably document the '2' thing...)
return self.canonpath( $path ) if $is_abs == 2;
if $is_abs {
# It's missing a volume, add one
my $vol;
$vol = self.splitpath($base)[0] if $base.defined;
$vol ||= self.splitpath($*CWD)[0];
return self.canonpath( $vol ~ $path );
}
if not defined $base {
# TODO: implement _getdcwd call ( Windows maintains separate CWD for each volume )
# See: http://msdn.microsoft.com/en-us/library/1e5zwe0c%28v=vs.80%29.aspx
#$base = Cwd::getdcwd( (self.splitpath: $path)[0] ) if defined &Cwd::getdcwd ;
#$base //= $*CWD ;
$base = $*CWD;
}
elsif ( !self.is-absolute( $base ) ) {
$base = self.rel2abs( $base );
}
else {
$base = self.canonpath( $base );
}
my ($path_directories, $path_file) = self.splitpath( $path )[1..2] ;
my ($base_volume, $base_directories) = self.splitpath( $base, :nofile ) ;
$path = self.catpath(
$base_volume,
self.catdir( $base_directories, $path_directories ),
$path_file
) ;
return self.canonpath( $path ) ;
}
method !canon-cat ( $first, *@rest, :$parent --> Str) {
$first ~~ /^ ([ <$driveletter> <$slash>?
| <$UNCpath>
| [<$slash> ** 2] <$notslash>+
| <$slash> ]?)
(.*)
/;
my Str ($volume, $path) = ~$0, ~$1;
$volume.=subst(:g, '/', '\\');
if $volume ~~ /^<$driveletter>/ {
$volume.=uc;
}
elsif $volume.chars && $volume !~~ / '\\' $/ {
$volume ~= '\\';
}
$path = join "\\", $path, @rest.flat;
$path ~~ s:g/ <$slash>+ /\\/; # /xx\\yy --> \xx\yy
$path ~~ s:g/[ ^ | '\\'] '.' '\\.'* [ '\\' | $ ]/\\/; # xx/././yy --> xx/yy
if $parent {
while $path ~~ s:g { [^ | <?after '\\'>] <!before '..\\'> <-[\\]>+ '\\..' ['\\' | $ ] } = '' { };
}
$path ~~ s/^ '\\'+ //; # \xx --> xx NOTE: this is *not* root
$path ~~ s/ '\\'+ $//; # xx\ --> xx
if $volume ~~ / '\\' $ / { # <vol>\.. --> <vol>\
$path ~~ s/ ^ '..' '\\..'* [ '\\' | $ ] //;
}
if $path eq '' { # \\HOST\SHARE\ --> \\HOST\SHARE
$volume ~~ s/<?after '\\\\' .*> '\\' $ //;
$volume || '.';
}
else {
$volume ~ $path;
}
}
}

Some files were not shown because too many files have changed in this diff Show More