diff --git a/.gitignore b/.gitignore index 71239be2..c0ab5df0 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,8 @@ -Gemfile.lock +/Gemfile.lock .bundle/ benchmark/ lib/linguist/samples.json +/grammars +/node_modules +test/fixtures/ace_modes.json +/vendor/gems/ diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 00000000..79209740 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,551 @@ +[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/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/AutoHotkey"] + path = vendor/grammars/AutoHotkey + url = https://github.com/robertcollier4/AutoHotkey +[submodule "vendor/grammars/Sublime-HTTP"] + path = vendor/grammars/Sublime-HTTP + url = https://github.com/httpspec/sublime-highlighting +[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 +[submodule "vendor/grammars/Sublime-Nit"] + path = vendor/grammars/Sublime-Nit + url = https://github.com/R4PaSs/Sublime-Nit +[submodule "vendor/grammars/language-hy"] + path = vendor/grammars/language-hy + url = https://github.com/rwtolbert/language-hy +[submodule "vendor/grammars/Racket"] + path = vendor/grammars/Racket + url = https://github.com/soegaard/racket-highlight-for-github +[submodule "vendor/grammars/turtle.tmbundle"] + path = vendor/grammars/turtle.tmbundle + url = https://github.com/peta/turtle.tmbundle diff --git a/.travis.yml b/.travis.yml index ac6800a7..4d0c2351 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,8 +1,5 @@ -before_install: - - git fetch origin master:master - - git fetch origin v2.0.0:v2.0.0 - - git fetch origin test/attributes:test/attributes - - sudo apt-get install libicu-dev -y +sudo: false +before_install: script/travis/before_install rvm: - 1.9.3 - 2.0.0 @@ -10,3 +7,6 @@ rvm: - 2.2 notifications: disabled: true +git: + submodules: false +cache: bundler diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 00000000..b6b682f6 --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,41 @@ +## Contributing + +The majority of contributions won't need to touch any Ruby code at all. The [master language list][languages] is just a YAML configuration file. + +Almost all bug fixes or new language additions should come with some additional code samples. Just drop them under [`samples/`][samples] in the correct subdirectory and our test suite will automatically test them. In most cases you shouldn't need to add any new assertions. + +### My code is detected as the wrong language + +This can usually be solved either by adding a new filename or file name extension to the language's entry in [`languages.yml`][languages] or adding more [samples][samples] for your language to the repository to make Linguist's classifier smarter. + +### 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. 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 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. + +### I want to add support for the `X` programming language + +Great! You'll need to: + +0. Add an entry for your language to [`languages.yml`][languages]. +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 +[languages]: /lib/linguist/languages.yml +[samples]: /samples diff --git a/Gemfile b/Gemfile index b92cab78..c5f2cc3b 100644 --- a/Gemfile +++ b/Gemfile @@ -1,3 +1,4 @@ source 'https://rubygems.org' -gemspec -gem 'test-unit', require: false if RUBY_VERSION >= '2.2' +gemspec :name => "github-linguist" +gemspec :name => "github-linguist-grammars" +gem 'byebug' if RUBY_VERSION >= '2.0' diff --git a/README.md b/README.md index 94430f4d..2bebfafe 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,14 @@ # Linguist -We use this library at GitHub to detect blob languages, highlight code, ignore binary files, suppress generated files in diffs, and generate language breakdown graphs. +We use this library at GitHub to detect blob languages, ignore binary files, suppress generated files in diffs, and generate language breakdown graphs. + +Tips for filing issues and creating pull requests can be found in [`CONTRIBUTING.md`](/CONTRIBUTING.md). ## Features ### Language detection -Linguist defines a list of all languages known to GitHub in a [yaml file](https://github.com/github/linguist/blob/master/lib/linguist/languages.yml). In order for a file to be highlighted, a language and a lexer must be defined there. +Linguist defines a list of all languages known to GitHub in a [yaml file](https://github.com/github/linguist/blob/master/lib/linguist/languages.yml). Most languages are detected by their file extension. For disambiguating between files with common extensions, we first apply some common-sense heuristics to pick out obvious languages. After that, we use a [statistical @@ -24,7 +26,9 @@ See [lib/linguist/language.rb](https://github.com/github/linguist/blob/master/li ### Syntax Highlighting -The actual syntax highlighting is handled by our Pygments wrapper, [pygments.rb](https://github.com/tmm1/pygments.rb). It also provides a [Lexer abstraction](https://github.com/tmm1/pygments.rb/blob/master/lib/pygments/lexer.rb) that determines which highlighter should be used on a file. +Syntax highlighting in GitHub is performed using TextMate-compatible grammars. These are the same grammars that TextMate, Sublime Text and Atom use. + +Every language in `languages.yml` is mapped to its corresponding TM `scope`. This scope will be used when picking up a grammar for highlighting. **When adding a new language to Linguist, please add its corresponding scope too (assuming there's an existing TextMate bundle, Sublime Text package, or Atom package) so syntax highlighting works for it**. ### Stats @@ -137,20 +141,12 @@ 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: bundle exec rake test -## Contributing - -The majority of contributions won't need to touch any Ruby code at all. The [master language list](https://github.com/github/linguist/blob/master/lib/linguist/languages.yml) is just a YAML configuration file. - -We try to only add languages once they have some usage on GitHub, so please note in-the-wild usage examples in your pull request. - -Almost all bug fixes or new language additions should come with some additional code samples. Just drop them under [`samples/`](https://github.com/github/linguist/tree/master/samples) in the correct subdirectory and our test suite will automatically test them. In most cases you shouldn't need to add any new assertions. - ### A note on language extensions Linguist has a number of methods available to it for identifying the language of a particular file. The initial lookup is based upon the extension of the file, possible file extensions are defined in an array called `extensions`. Take a look at this example for example for `Perl`: @@ -185,7 +181,8 @@ 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. If grammar submodules have not been updated recently, update them: `git submodule update --remote && git commit -a` 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). diff --git a/Rakefile b/Rakefile index 09fa0d8a..b38486c0 100644 --- a/Rakefile +++ b/Rakefile @@ -3,13 +3,14 @@ require 'rake/clean' require 'rake/testtask' require 'yaml' require 'yajl' +require 'open-uri' task :default => :test Rake::TestTask.new -# Extend test task to check for samples -task :test => :check_samples +# Extend test task to check for samples and fetch latest Ace modes +task :test => [:check_samples, :fetch_ace_modes] desc "Check that we have samples.json generated" task :check_samples do @@ -18,6 +19,20 @@ task :check_samples do end end +desc "Fetch the latest Ace modes from its GitHub repository" +task :fetch_ace_modes do + ACE_FIXTURE_PATH = File.join('test', 'fixtures', 'ace_modes.json') + + File.delete(ACE_FIXTURE_PATH) if File.exist?(ACE_FIXTURE_PATH) + + begin + ace_github_modes = open("https://api.github.com/repos/ajaxorg/ace/contents/lib/ace/mode").read + File.write(ACE_FIXTURE_PATH, ace_github_modes) + rescue OpenURI::HTTPError, SocketError + # no internet? no problem. + end +end + task :samples do require 'linguist/samples' json = Yajl.dump(Linguist::Samples.data, :pretty => true) @@ -31,6 +46,12 @@ task :build_gem => :samples do File.delete("lib/linguist/languages.json") end +task :build_grammars_gem do + rm_rf "grammars" + sh "script/convert-grammars" + sh "gem", "build", "github-linguist-grammars.gemspec" +end + namespace :benchmark do benchmark_path = "benchmark/results" diff --git a/github-linguist-grammars.gemspec b/github-linguist-grammars.gemspec new file mode 100644 index 00000000..429b3ff1 --- /dev/null +++ b/github-linguist-grammars.gemspec @@ -0,0 +1,14 @@ +require File.expand_path('../lib/linguist/version', __FILE__) + +Gem::Specification.new do |s| + s.name = 'github-linguist-grammars' + s.version = Linguist::VERSION + s.summary = "Language grammars for use with github-linguist" + + s.authors = "GitHub" + s.homepage = "https://github.com/github/linguist" + + s.files = ['lib/linguist/grammars.rb'] + Dir['grammars/*'] + + s.add_development_dependency 'plist', '~>3.1' +end diff --git a/github-linguist.gemspec b/github-linguist.gemspec index 4e918f30..983db982 100644 --- a/github-linguist.gemspec +++ b/github-linguist.gemspec @@ -10,15 +10,15 @@ Gem::Specification.new do |s| s.homepage = "https://github.com/github/linguist" s.license = "MIT" - s.files = Dir['lib/**/*'] + s.files = Dir['lib/**/*'] - ['lib/linguist/grammars.rb'] s.executables << 'linguist' 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 'pygments.rb', '~> 0.6.0' - s.add_dependency 'rugged', '~> 0.21.1b2' + s.add_dependency 'mime-types', '>= 1.19' + 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' diff --git a/grammars.yml b/grammars.yml new file mode 100644 index 00000000..c85b2de6 --- /dev/null +++ b/grammars.yml @@ -0,0 +1,466 @@ +--- +http://svn.edgewall.org/repos/genshi/contrib/textmate/Genshi.tmbundle/Syntaxes/Markup%20Template%20%28XML%29.tmLanguage: +- text.xml.genshi +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/Forth.tmbundle: +- source.forth +http://svn.textmate.org/trunk/Review/Bundles/Parrot.tmbundle: +- source.parrot.pir +http://svn.textmate.org/trunk/Review/Bundles/SecondLife%20LSL.tmbundle: +- source.lsl +http://svn.textmate.org/trunk/Review/Bundles/VHDL.tmbundle: +- source.vhdl +http://svn.textmate.org/trunk/Review/Bundles/XQuery.tmbundle: +- source.xquery +https://bitbucket.org/Clams/sublimesystemverilog/get/default.tar.gz: +- source.systemverilog +- source.ucfconstraints +https://fan.googlecode.com/hg-history/Build%201.0.55/adm/tools/textmate/Fan.tmbundle/Syntaxes/Fan.tmLanguage: +- source.fan +vendor/grammars/Agda.tmbundle: +- source.agda +vendor/grammars/Alloy.tmbundle: +- source.alloy +vendor/grammars/AutoHotkey: +- source.ahk +vendor/grammars/ColdFusion: +- source.cfscript +- source.cfscript.cfc +- text.cfml.basic +- text.html.cfm +vendor/grammars/Docker.tmbundle: +- source.dockerfile +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/Racket: +- source.racket +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-HTTP: +- source.httpspec +vendor/grammars/Sublime-Inform: +- source.Inform7 +vendor/grammars/Sublime-Lasso: +- file.lasso +vendor/grammars/Sublime-Logos: +- source.logos +vendor/grammars/Sublime-Loom: +- source.loomscript +vendor/grammars/Sublime-Nit: +- source.nit +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 +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 +vendor/grammars/html.tmbundle: +- text.html.basic +vendor/grammars/idl.tmbundle: +- source.idl +- source.idl-dlm +- text.idl-idldoc +vendor/grammars/ini.tmbundle: +- source.ini +vendor/grammars/io.tmbundle: +- source.io +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 +vendor/grammars/javadoc.tmbundle: +- text.html.javadoc +vendor/grammars/javascript-objective-j.tmbundle: +- source.js.objj +vendor/grammars/jquery-tmbundle: +- source.js.jquery +vendor/grammars/json.tmbundle: +- source.json +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-hy: +- source.hy +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 +vendor/grammars/less.tmbundle: +- source.css.less +vendor/grammars/lilypond.tmbundle: +- source.lilypond +vendor/grammars/lisp.tmbundle: +- source.lisp +vendor/grammars/llvm.tmbundle: +- source.llvm +vendor/grammars/logtalk.tmbundle: +- source.logtalk +vendor/grammars/lua.tmbundle: +- source.lua +vendor/grammars/make.tmbundle: +- source.makefile +vendor/grammars/mako-tmbundle: +- text.html.mako +vendor/grammars/mathematica-tmbundle: +- source.mathematica +vendor/grammars/matlab.tmbundle: +- source.matlab +- source.octave +vendor/grammars/maven.tmbundle: +- text.xml.pom +vendor/grammars/mercury-tmlanguage: +- source.mercury +vendor/grammars/monkey.tmbundle: +- source.monkey +vendor/grammars/moonscript-tmbundle: +- source.moonscript +vendor/grammars/nemerle.tmbundle: +- source.nemerle +vendor/grammars/nesC.tmbundle: +- source.nesc +vendor/grammars/ninja.tmbundle: +- source.ninja +vendor/grammars/objective-c.tmbundle: +- source.objc +- source.objc++ +- source.objc.platform +- source.strings +vendor/grammars/ocaml.tmbundle: +- source.camlp4.ocaml +- source.ocaml +- source.ocamllex +- source.ocamlyacc +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 +vendor/grammars/perl.tmbundle: +- source.perl +vendor/grammars/php-smarty.tmbundle: +- source.smarty +vendor/grammars/php.tmbundle: +- text.html.php +vendor/grammars/pike-textmate: +- source.pike +vendor/grammars/postscript.tmbundle: +- source.postscript +vendor/grammars/powershell.tmbundle: +- source.powershell +vendor/grammars/processing.tmbundle: +- source.processing +vendor/grammars/prolog.tmbundle: +- source.prolog +vendor/grammars/protobuf-tmbundle: +- source.protobuf +vendor/grammars/puppet-textmate-bundle: +- source.puppet +vendor/grammars/python-django.tmbundle: +- source.python.django +- text.html.django +vendor/grammars/r.tmbundle: +- source.r +- text.tex.latex.rd +vendor/grammars/restructuredtext.tmbundle: +- text.restructuredtext +vendor/grammars/ruby-haml.tmbundle: +- text.haml +vendor/grammars/ruby-on-rails-tmbundle: +- source.js.erb.rails +- source.ruby.rails +- source.ruby.rails.rjs +- source.sql.ruby +- text.html.erb.rails +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 +vendor/grammars/scilab.tmbundle: +- source.scilab +vendor/grammars/smalltalk-tmbundle: +- source.smalltalk +vendor/grammars/sql.tmbundle: +- source.sql +vendor/grammars/standard-ml.tmbundle: +- source.cm +- source.ml +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 +vendor/grammars/tcl.tmbundle: +- source.tcl +- text.html.tcl +vendor/grammars/text.tmbundle: +- text.plain +vendor/grammars/textile.tmbundle: +- text.html.textile +vendor/grammars/textmate.tmbundle: +- source.regexp.oniguruma +- source.tm-properties +vendor/grammars/thrift.tmbundle: +- source.thrift +vendor/grammars/toml.tmbundle: +- source.toml +vendor/grammars/turtle.tmbundle: +- source.sparql +- source.turtle +vendor/grammars/verilog.tmbundle: +- source.verilog +vendor/grammars/x86-assembly-textmate-bundle: +- source.asm.x86 +vendor/grammars/xml.tmbundle: +- text.xml +- text.xml.xsl +vendor/grammars/zephir-sublime: +- source.php.zephir diff --git a/lib/linguist.rb b/lib/linguist.rb index 3714b5a0..ff9fc3a2 100644 --- a/lib/linguist.rb +++ b/lib/linguist.rb @@ -4,4 +4,5 @@ require 'linguist/heuristics' require 'linguist/language' require 'linguist/repository' require 'linguist/samples' +require 'linguist/shebang' require 'linguist/version' diff --git a/lib/linguist/blob_helper.rb b/lib/linguist/blob_helper.rb index 840ca75c..c368b4d0 100644 --- a/lib/linguist/blob_helper.rb +++ b/lib/linguist/blob_helper.rb @@ -2,7 +2,6 @@ require 'linguist/generated' require 'charlock_holmes' require 'escape_utils' require 'mime/types' -require 'pygments' require 'yaml' module Linguist @@ -147,6 +146,13 @@ module Linguist end end + # Public: Is the blob empty? + # + # Return true or false + def empty? + data.nil? || data == "" + end + # Public: Is the blob text? # # Return true or false @@ -193,10 +199,6 @@ module Linguist # Public: Is the blob safe to colorize? # - # We use Pygments for syntax highlighting blobs. Pygments - # can be too slow for very large blobs or for certain - # corner-case blobs. - # # Return true or false def safe_to_colorize? !large? && text? && !high_ratio_of_long_lines? @@ -204,9 +206,6 @@ module Linguist # Internal: Does the blob have a ratio of long lines? # - # These types of files are usually going to make Pygments.rb - # angry if we try to colorize them. - # # Return true or false def high_ratio_of_long_lines? return false if loc == 0 @@ -314,28 +313,9 @@ module Linguist @language ||= Language.detect(self) end - # Internal: Get the lexer of the blob. - # - # Returns a Lexer. - def lexer - language ? language.lexer : Pygments::Lexer.find_by_name('Text only') - end - # Internal: Get the TextMate compatible scope for the blob def tm_scope language && language.tm_scope end - - # Public: Highlight syntax of blob - # - # options - A Hash of options (defaults to {}) - # - # Returns html String - def colorize(options = {}) - return unless safe_to_colorize? - options[:options] ||= {} - options[:options][:encoding] ||= encoding - lexer.highlight(data, options) - end end end diff --git a/lib/linguist/classifier.rb b/lib/linguist/classifier.rb index 5370bdd8..89a0df2f 100644 --- a/lib/linguist/classifier.rb +++ b/lib/linguist/classifier.rb @@ -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 diff --git a/lib/linguist/file_blob.rb b/lib/linguist/file_blob.rb index bc475023..04441935 100644 --- a/lib/linguist/file_blob.rb +++ b/lib/linguist/file_blob.rb @@ -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 diff --git a/lib/linguist/generated.rb b/lib/linguist/generated.rb index 0f911c45..50dbc58d 100644 --- a/lib/linguist/generated.rb +++ b/lib/linguist/generated.rb @@ -51,26 +51,25 @@ module Linguist # # Return true or false def generated? - name == 'Gemfile.lock' || - 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? + xcode_file? || + generated_net_designer_file? || + composer_lock? || + node_modules? || + godeps? || + 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? # - # Generated if the file extension is an Xcode + # Generated if the file extension is an Xcode # file extension. # # Returns true of false. @@ -265,4 +264,3 @@ module Linguist end end end - diff --git a/lib/linguist/grammars.rb b/lib/linguist/grammars.rb new file mode 100644 index 00000000..f6468280 --- /dev/null +++ b/lib/linguist/grammars.rb @@ -0,0 +1,13 @@ +# Note: This file is included in the github-linguist-grammars gem, not the +# github-linguist gem. + +module Linguist + module Grammars + # Get the path to the directory containing the language grammar JSON files. + # + # Returns a String. + def self.path + File.expand_path("../../../grammars", __FILE__) + end + end +end diff --git a/lib/linguist/heuristics.rb b/lib/linguist/heuristics.rb index 30b4fcdf..544ce023 100644 --- a/lib/linguist/heuristics.rb +++ b/lib/linguist/heuristics.rb @@ -1,107 +1,201 @@ module Linguist # A collection of simple heuristics that can be used to better analyze languages. class Heuristics - ACTIVE = true + # Public: Use heuristics to detect language of the blob. + # + # blob - An object that quacks like a blob. + # possible_languages - Array of Language objects + # + # 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 - # Public: Given an array of String language names, - # apply heuristics against the given data and return an array - # of matching languages, or nil. + @heuristics.each do |heuristic| + return Array(heuristic.call(data)) if heuristic.matches?(languages) + end + + [] # No heuristics matched + end + + # Internal: Define a new heuristic. # - # data - Array of tokens or String data to analyze. - # languages - Array of language name Strings to restrict to. + # languages - String names of languages to disambiguate. + # heuristic - Block which takes data as an argument and returns a Language or nil. # - # Returns an array of Languages or [] - def self.find_by_heuristics(data, languages) - if active? - if languages.all? { |l| ["Perl", "Prolog"].include?(l) } - result = disambiguate_pl(data, languages) - end - if languages.all? { |l| ["ECL", "Prolog"].include?(l) } - result = disambiguate_ecl(data, languages) - end - if languages.all? { |l| ["IDL", "Prolog"].include?(l) } - result = disambiguate_pro(data, languages) - end - if languages.all? { |l| ["Common Lisp", "OpenCL"].include?(l) } - result = disambiguate_cl(data, languages) - end - if languages.all? { |l| ["M", "Matlab", "Mathematica", "Mercury", "Objective-C"].include?(l) } - result = disambiguate_m(data, languages) - end - return result + # 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, languages) - matches = [] - matches << Language["Objective-C"] if data.include?("@interface") - matches << Language["C++"] if data.include?("#include ") - matches + disambiguate "C#", "Smalltalk" do |data| + if /![\w\s]+methodsFor: /.match(data) + Language["Smalltalk"] + elsif /^\s*namespace\s*[\w\.]+\s*{/.match(data) || /^\s*\/\//.match(data) + Language["C#"] + end end - def self.disambiguate_pl(data, languages) - matches = [] - matches << Language["Prolog"] if data.include?(":-") - matches << Language["Perl"] if data.include?("use strict") - matches + 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*")) - matches << Language["XML"] - else - matches << Language["TypeScript"] + disambiguate "Common Lisp", "OpenCL", "Cool" do |data| + if data.include?("(defun ") + Language["Common Lisp"] + elsif /^class/x.match(data) + Language["Cool"] + elsif /\/\* |\/\/ |^\}/.match(data) + Language["OpenCL"] end - matches end - def self.disambiguate_cl(data, languages) - matches = [] - matches << Language["Common Lisp"] if data.include?("(defun ") - matches << Language["OpenCL"] if /\/\* |\/\/ |^\}/.match(data) - matches - end - - def self.disambiguate_r(data, languages) - matches = [] - matches << Language["Rebol"] if /\bRebol\b/i.match(data) - matches << Language["R"] if data.include?("<-") - matches - end - - def self.disambiguate_m(data, languages) - matches = [] - if (/@(interface|class|protocol|property|end|synchronised|selector|implementation)\b/.match(data)) - matches << Language["Objective-C"] + disambiguate "Hack", "PHP" do |data| + if data.include?(" 1 - data = blob.data - possible_language_names = possible_languages.map(&:name) - - # Don't bother with binary contents or an empty file - if data.nil? || data == "" - nil - # Check if there's a shebang line and use that as authoritative - elsif (result = find_by_shebang(data)) && !result.empty? - result.first - # No shebang. Still more work to do. Try to find it with our heuristics. - elsif (determined = Heuristics.find_by_heuristics(data, possible_language_names)) && !determined.empty? - determined.first - # Lastly, fall back to the 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]] + # 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 - 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 @@ -164,7 +143,7 @@ module Linguist # # Returns the Language or nil if none was found. def self.find_by_name(name) - @name_index[name] + name && @name_index[name.downcase] end # Public: Look up Language by one of its aliases. @@ -178,7 +157,7 @@ module Linguist # # Returns the Lexer or nil if none was found. def self.find_by_alias(name) - @alias_index[name] + name && @alias_index[name.downcase] end # Public: Look up Languages by filename. @@ -193,26 +172,53 @@ 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 - langs = @filename_index[basename] + - @extension_index[extname] - langs.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 shebang line. + # Public: Look up Languages by file extension. # - # data - Array of tokens or String data to analyze. + # extname - The extension String. # # Examples # - # Language.find_by_shebang("#!/bin/bash\ndate;") + # Language.find_by_extension('.rb') + # # => [#] + # + # Language.find_by_extension('rb') + # # => [#] + # + # Returns all matching Languages or [] if none were found. + def self.find_by_extension(extname) + extname = ".#{extname}" unless extname.start_with?(".") + @extension_index[extname] + end + + # DEPRECATED + def self.find_by_shebang(data) + @interpreter_index[Shebang.interpreter(data)] + end + + # Public: Look up Languages by interpreter. + # + # interpreter - String of interpreter name + # + # Examples + # + # Language.find_by_interpreter("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 @@ -227,7 +233,7 @@ module Linguist # # Returns the Language or nil if none was found. def self.[](name) - @index[name] + name && @index[name.downcase] end # Public: A List of popular languages @@ -263,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 @@ -286,10 +296,7 @@ module Linguist # Set aliases @aliases = [default_alias_name] + (attributes[:aliases] || []) - # Lookup Lexer object - @lexer = Pygments::Lexer.find_by_name(attributes[:lexer] || name) || - raise(ArgumentError, "#{@name} is missing lexer") - + # Load the TextMate scope name or try to guess one @tm_scope = attributes[:tm_scope] || begin context = case @type when :data, :markup, :prose @@ -421,11 +428,6 @@ module Linguist # Returns the extensions Array attr_reader :filenames - # Public: Return all possible extensions for language - def all_extensions - (extensions + [primary_extension]).uniq - end - # Deprecated: Get primary extension # # Defaults to the first extension but can be overridden @@ -546,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 @@ -583,9 +585,9 @@ module Linguist :ace_mode => options['ace_mode'], :wrap => options['wrap'], :group_name => options['group'], - :searchable => options.key?('searchable') ? options['searchable'] : true, + :searchable => options.fetch('searchable', true), :search_term => options['search_term'], - :extensions => [options['extensions'].first] + options['extensions'][1..-1].sort, + :extensions => Array(options['extensions']), :interpreters => options['interpreters'].sort, :filenames => options['filenames'], :popular => popular.include?(name) diff --git a/lib/linguist/languages.yml b/lib/linguist/languages.yml index 858a8487..af0472c8 100644 --- a/lib/linguist/languages.yml +++ b/lib/linguist/languages.yml @@ -1,13 +1,11 @@ # Defines all Languages known to GitHub. # -# All languages have an associated lexer for syntax highlighting. It -# defaults to name.downcase, which covers most cases. -# # type - Either data, programming, markup, prose, or nil -# lexer - An explicit lexer String (defaults to name) # aliases - An Array of additional aliases (implicitly # includes name.downcase) -# ace_mode - A String name of Ace Mode (if available) +# ace_mode - A String name of the Ace Mode used for highlighting whenever +# a file is edited. This must match one of the filenames in http://git.io/3XO_Cg. +# Use "text" if a mode does not exist. # wrap - Boolean wrap to enable line wrapping (default: false) # extensions - An Array of associated extensions (the first one is # considered the primary extension) @@ -16,6 +14,10 @@ # search_term - Deprecated: Some languages maybe indexed under a # different alias. Avoid defining new exceptions. # color - CSS hex color to represent the language. +# tm_scope - The TextMate scope that represents this programming +# language. This should match one of the scopes listed in +# the grammars.yml file. Use "none" if there is no grammar +# for this language. # # Any additions or modifications (even trivial) should have corresponding # test change in `test/test_blob.rb`. @@ -24,13 +26,12 @@ ABAP: type: programming - lexer: ABAP extensions: - .abap + ace_mode: abap AGS Script: type: programming - lexer: C++ color: "#B9D9FF" aliases: - ags @@ -38,13 +39,14 @@ AGS Script: - .asc - .ash tm_scope: source.c++ + ace_mode: c_cpp ANTLR: type: programming color: "#9DC3FF" - lexer: ANTLR extensions: - .g4 + ace_mode: text APL: type: programming @@ -52,11 +54,12 @@ APL: extensions: - .apl - .dyalog + tm_scope: none + ace_mode: text ASP: type: programming color: "#6a40fd" - lexer: aspx-vb search_term: aspx-vb aliases: - aspx @@ -69,11 +72,11 @@ ASP: - .asmx - .aspx - .axd + ace_mode: text ATS: type: programming color: "#1ac620" - lexer: OCaml aliases: - ats2 extensions: @@ -82,52 +85,71 @@ ATS: - .hats - .sats tm_scope: source.ocaml + ace_mode: ocaml ActionScript: type: programming - lexer: ActionScript 3 tm_scope: source.actionscript.3 color: "#e3491a" search_term: as3 aliases: + - actionscript 3 + - actionscript3 - as3 extensions: - .as + ace_mode: actionscript Ada: type: programming color: "#02f88c" extensions: - .adb + - .ada - .ads + aliases: + - ada95ada2005 + ace_mode: ada Agda: type: programming color: "#467C91" extensions: - .agda + ace_mode: text Alloy: type: programming # 'modeling' would be more appropiate - lexer: Alloy color: "#cc5c24" extensions: - .als + ace_mode: text + +Ant Build System: + type: data + tm_scope: text.xml.ant + filenames: + - ant.xml + - build.xml + ace_mode: xml ApacheConf: type: markup aliases: + - aconf - apache extensions: - .apacheconf + - .conf tm_scope: source.apache-config + ace_mode: apache_conf Apex: type: programming - lexer: Java extensions: - .cls tm_scope: source.java + ace_mode: java AppleScript: type: programming @@ -138,64 +160,72 @@ AppleScript: - .scpt interpreters: - osascript + ace_mode: applescript Arc: type: programming color: "#ca2afe" - lexer: Text only extensions: - .arc + tm_scope: none + ace_mode: text Arduino: type: programming color: "#bd79d1" - lexer: C++ extensions: - .ino tm_scope: source.c++ + ace_mode: c_cpp AsciiDoc: type: prose - lexer: Text only ace_mode: asciidoc wrap: true extensions: - .asciidoc - .adoc - .asc + tm_scope: none AspectJ: type: programming - lexer: AspectJ color: "#1957b0" extensions: - .aj + tm_scope: none + ace_mode: text Assembly: type: programming - lexer: NASM color: "#a67219" search_term: nasm aliases: - nasm extensions: - .asm + - .ASM - .a51 tm_scope: source.asm.x86 + ace_mode: assembly_x86 Augeas: type: programming extensions: - .aug + tm_scope: none + ace_mode: text AutoHotkey: type: programming - lexer: autohotkey color: "#6594b9" aliases: - ahk extensions: - .ahk + - .ahkl + tm_scope: source.ahk + ace_mode: autohotkey AutoIt: type: programming @@ -207,10 +237,10 @@ AutoIt: extensions: - .au3 tm_scope: source.autoit.3 + ace_mode: autohotkey Awk: type: programming - lexer: Awk extensions: - .awk - .auk @@ -222,6 +252,7 @@ Awk: - gawk - mawk - nawk + ace_mode: text Batchfile: type: programming @@ -229,69 +260,102 @@ Batchfile: search_term: bat aliases: - bat + - batch + - dosbatch + - winbatch extensions: - .bat - .cmd tm_scope: source.dosbatch + ace_mode: batchfile Befunge: extensions: - .befunge + ace_mode: text + +Bison: + type: programming + tm_scope: source.bison + extensions: + - .y + ace_mode: text + +BitBake: + type: programming + tm_scope: none + extensions: + - .bb + ace_mode: text BlitzBasic: type: programming aliases: - - blitzplus + - b3d - blitz3d + - blitzplus + - bplus extensions: - .bb - .decls tm_scope: source.blitzmax + ace_mode: text BlitzMax: type: programming color: "#cd6400" extensions: - .bmx + aliases: + - bmax + ace_mode: text Bluespec: type: programming - lexer: verilog extensions: - .bsv - tm_scope: source.verilog + tm_scope: source.bsv + ace_mode: verilog Boo: type: programming color: "#d4bec1" extensions: - .boo + ace_mode: text Brainfuck: extensions: - .b - .bf tm_scope: source.bf + ace_mode: text Brightscript: type: programming - lexer: Text only extensions: - .brs + tm_scope: none + ace_mode: text Bro: type: programming extensions: - .bro + ace_mode: text C: type: programming color: "#555" extensions: - .c + - .C + - .H - .cats - .h + - .idc - .w + ace_mode: c_cpp C#: type: programming @@ -315,59 +379,62 @@ C++: - cpp extensions: - .cpp - - .C - .c++ - .cc - .cxx - - .H - .h - .h++ - .hh - .hpp - .hxx - .inl + - .ipp - .tcc - .tpp - - .ipp C-ObjDump: type: data - lexer: c-objdump extensions: - .c-objdump tm_scope: objdump.x86asm + ace_mode: assembly_x86 C2hs Haskell: type: programming - lexer: Haskell group: Haskell aliases: - c2hs extensions: - .chs tm_scope: source.haskell + ace_mode: haskell CLIPS: type: programming - lexer: Text only extensions: - .clp + tm_scope: none + ace_mode: text CMake: extensions: - .cmake - - .in + - .cmake.in filenames: - CMakeLists.txt + ace_mode: text COBOL: type: programming extensions: - .cob + - .COB + - .CPY - .cbl - .ccp - .cobol - .cpy + ace_mode: cobol CSS: ace_mode: css @@ -375,11 +442,27 @@ CSS: extensions: - .css +Cap'n Proto: + type: programming + tm_scope: source.capnp + extensions: + - .capnp + ace_mode: text + +CartoCSS: + type: programming + aliases: + - Carto + extensions: + - .mss + ace_mode: text + tm_scope: source.css.mss + Ceylon: type: programming - lexer: Ceylon extensions: - .ceylon + ace_mode: text Chapel: type: programming @@ -388,28 +471,29 @@ Chapel: - chpl extensions: - .chpl + ace_mode: text ChucK: - lexer: Java extensions: - .ck tm_scope: source.java + ace_mode: java Cirru: type: programming color: "#aaaaff" ace_mode: cirru - lexer: Cirru extensions: - .cirru Clean: type: programming color: "#3a81ad" - lexer: Text only extensions: - .icl - .dcl + tm_scope: none + ace_mode: text Clojure: type: programming @@ -420,10 +504,10 @@ Clojure: - .cl2 - .cljc - .cljs + - .cljs.hl - .cljscm - .cljx - .hic - - .hl filenames: - riemann.config @@ -438,6 +522,7 @@ CoffeeScript: extensions: - .coffee - ._coffee + - .cjsx - .cson - .iced filenames: @@ -448,21 +533,21 @@ CoffeeScript: ColdFusion: type: programming group: ColdFusion - lexer: Coldfusion HTML ace_mode: coldfusion color: "#ed2cd6" search_term: cfm aliases: - cfm - cfml + - coldfusion html extensions: - .cfm + - .cfml tm_scope: text.html.cfm ColdFusion CFC: type: programming group: ColdFusion - lexer: Coldfusion CFC ace_mode: coldfusion color: "#ed2cd6" search_term: cfc @@ -491,66 +576,86 @@ Common Lisp: - ccl - clisp - ecl + ace_mode: lisp Component Pascal: type: programming - lexer: Delphi color: "#b0ce4e" extensions: - .cp - .cps tm_scope: source.pascal + aliases: + - delphi + - objectpascal + ace_mode: pascal + +Cool: + type: programming + extensions: + - .cl + tm_scope: source.cool + ace_mode: text Coq: type: programming extensions: - .coq - .v + ace_mode: text Cpp-ObjDump: type: data - lexer: cpp-objdump extensions: - .cppobjdump + - .c++-objdump - .c++objdump + - .cpp-objdump - .cxx-objdump tm_scope: objdump.x86asm + aliases: + - c++-objdumb + ace_mode: assembly_x86 Creole: type: prose - lexer: Text only wrap: true extensions: - .creole + tm_scope: none + ace_mode: text Crystal: type: programming - lexer: Ruby extensions: - .cr ace_mode: ruby tm_scope: source.ruby + interpreters: + - crystal Cucumber: - lexer: Gherkin extensions: - .feature tm_scope: text.gherkin.feature + aliases: + - gherkin + ace_mode: text Cuda: type: programming - lexer: CUDA extensions: - .cu - .cuh tm_scope: source.cuda-c++ + ace_mode: c_cpp Cycript: type: programming - lexer: JavaScript extensions: - .cy tm_scope: source.js + ace_mode: javascript Cython: type: programming @@ -559,6 +664,9 @@ Cython: - .pyx - .pxd - .pxi + aliases: + - pyrex + ace_mode: text D: type: programming @@ -566,30 +674,24 @@ D: extensions: - .d - .di + ace_mode: d D-ObjDump: type: data - lexer: d-objdump extensions: - .d-objdump tm_scope: objdump.x86asm + ace_mode: assembly_x86 DM: type: programming color: "#075ff1" - lexer: C++ extensions: - .dm aliases: - byond tm_scope: source.c++ - -DOT: - type: data - lexer: Text only - extensions: - - .dot - - .gv + ace_mode: c_cpp Darcs Patch: search_term: dpatch @@ -598,71 +700,91 @@ Darcs Patch: extensions: - .darcspatch - .dpatch + tm_scope: none + ace_mode: text Dart: type: programming color: "#98BAD6" extensions: - .dart + ace_mode: dart Diff: extensions: - .diff - .patch + aliases: + - udiff + ace_mode: diff + +Dockerfile: + type: data + tm_scope: source.dockerfile + extensions: + - .dockerfile + filenames: + - Dockerfile + ace_mode: dockerfile Dogescript: type: programming - lexer: Text only color: "#cca760" extensions: - .djs + tm_scope: none + ace_mode: text Dylan: type: programming color: "#3ebc27" extensions: - .dylan + - .dyl - .intr - .lid + ace_mode: text E: type: programming color: "#ccce35" - lexer: Text only extensions: - .E - -Ecere Projects: - type: data - group: JavaScript - lexer: JSON - extensions: - - .epj - tm_scope: source.json + tm_scope: none + ace_mode: text ECL: type: programming color: "#8a1267" - lexer: ECL extensions: - .ecl - .eclxml + tm_scope: none + ace_mode: text Eagle: type: markup color: "#3994bc" - lexer: XML extensions: - .sch - .brd tm_scope: text.xml + ace_mode: xml + +Ecere Projects: + type: data + group: JavaScript + extensions: + - .epj + tm_scope: source.json + ace_mode: json Eiffel: type: programming - lexer: Eiffel color: "#946d57" extensions: - .e + ace_mode: eiffel Elixir: type: programming @@ -670,17 +792,18 @@ Elixir: extensions: - .ex - .exs + ace_mode: elixir Elm: type: programming - lexer: Haskell + color: "#60B5CC" extensions: - .elm - tm_scope: source.haskell + tm_scope: source.elm + ace_mode: elm Emacs Lisp: type: programming - lexer: Common Lisp tm_scope: source.lisp color: "#c065db" aliases: @@ -691,27 +814,31 @@ Emacs Lisp: extensions: - .el - .emacs + ace_mode: lisp EmberScript: type: programming color: "#f64e3e" - lexer: CoffeeScript extensions: - .em - .emberscript tm_scope: source.coffee + ace_mode: coffee Erlang: type: programming color: "#0faf8d" extensions: - .erl + - .es - .escript - .hrl + ace_mode: erlang + interpreters: + - escript F#: type: programming - lexer: FSharp color: "#b845fc" search_term: fsharp aliases: @@ -721,18 +848,19 @@ F#: - .fsi - .fsx tm_scope: source.fsharp + ace_mode: text FLUX: type: programming color: "#33CCFF" - lexer: Text only extensions: - .fx - .flux + tm_scope: none + ace_mode: text FORTRAN: type: programming - lexer: Fortran color: "#4d41b1" extensions: - .f90 @@ -751,6 +879,8 @@ FORTRAN: - .f95 - .for - .fpp + tm_scope: source.fortran.modern + ace_mode: text Factor: type: programming @@ -758,8 +888,9 @@ Factor: extensions: - .factor filenames: - - .factor-rc - .factor-boot-rc + - .factor-rc + ace_mode: text Fancy: type: programming @@ -769,6 +900,7 @@ Fancy: - .fancypack filenames: - Fakefile + ace_mode: text Fantom: type: programming @@ -776,55 +908,56 @@ Fantom: extensions: - .fan tm_scope: source.fan + ace_mode: text Forth: type: programming color: "#341708" - lexer: Text only extensions: - .fth - .4th + - .F + - .f + - .for - .forth + - .fr - .frt + - .fs + ace_mode: forth Frege: type: programming color: "#00cafe" - lexer: Haskell extensions: - .fr tm_scope: source.haskell + ace_mode: haskell G-code: type: data - lexer: Text only extensions: - .g - .gco - .gcode - -Game Maker Language: - type: programming - color: "#8ad353" - lexer: JavaScript - extensions: - - .gml - tm_scope: source.js + tm_scope: none + ace_mode: gcode GAMS: type: programming - lexer: Text only extensions: - .gms + tm_scope: none + ace_mode: text GAP: type: programming - lexer: Text only extensions: - .g - .gap - .gd - .gi + tm_scope: none + ace_mode: text GAS: type: programming @@ -832,12 +965,15 @@ GAS: extensions: - .s - .S + tm_scope: source.asm.x86 + ace_mode: assembly_x86 GDScript: type: programming - lexer: Text only extensions: - .gd + tm_scope: none + ace_mode: text GLSL: group: C @@ -847,7 +983,9 @@ GLSL: - .fp - .frag - .frg + - .fs - .fshader + - .geo - .geom - .glslv - .gshader @@ -855,25 +993,38 @@ GLSL: - .vert - .vrx - .vshader + ace_mode: glsl + +Game Maker Language: + type: programming + color: "#8ad353" + extensions: + - .gml + tm_scope: source.c++ + ace_mode: c_cpp Genshi: extensions: - .kid tm_scope: text.xml.genshi + aliases: + - xml+genshi + - xml+kid + ace_mode: xml Gentoo Ebuild: group: Shell - lexer: Bash extensions: - .ebuild tm_scope: source.shell + ace_mode: sh Gentoo Eclass: group: Shell - lexer: Bash extensions: - .eclass tm_scope: source.shell + ace_mode: sh Gettext Catalog: search_term: pot @@ -884,31 +1035,43 @@ Gettext Catalog: - .po - .pot tm_scope: source.po + ace_mode: text Glyph: type: programming color: "#e4cc98" - lexer: Tcl extensions: - .glf tm_scope: source.tcl + ace_mode: tcl Gnuplot: type: programming color: "#f0a9f0" - lexer: Gnuplot extensions: - .gp - .gnu - .gnuplot - .plot - .plt + interpreters: + - gnuplot + ace_mode: text Go: type: programming color: "#375eab" extensions: - .go + ace_mode: golang + +Golo: + type: programming + color: "#f6a51f" + extensions: + - .golo + tm_scope: none + ace_mode: text Gosu: type: programming @@ -919,16 +1082,24 @@ Gosu: - .gsx - .vark tm_scope: source.gosu.2 + ace_mode: text Grace: type: programming - lexer: Text only extensions: - .grace + tm_scope: none + ace_mode: text + +Gradle: + type: data + extensions: + - .gradle + tm_scope: source.groovy.gradle + ace_mode: text Grammatical Framework: type: programming - lexer: Haskell aliases: - gf wrap: false @@ -937,12 +1108,23 @@ Grammatical Framework: searchable: true color: "#ff0000" tm_scope: source.haskell + ace_mode: haskell Graph Modeling Language: type: data - lexer: Text only extensions: - .gml + tm_scope: none + ace_mode: text + +Graphviz (DOT): + type: data + tm_scope: source.dot + extensions: + - .dot + - .DOT + - .gv + ace_mode: text Groff: extensions: @@ -955,6 +1137,9 @@ Groff: - '.6' - '.7' tm_scope: text.groff + aliases: + - nroff + ace_mode: text Groovy: type: programming @@ -970,12 +1155,13 @@ Groovy: Groovy Server Pages: group: Groovy - lexer: Java Server Page aliases: - gsp + - java server page extensions: - .gsp tm_scope: text.html.jsp + ace_mode: jsp HTML: type: markup @@ -986,28 +1172,34 @@ HTML: extensions: - .html - .htm + - .html.hl - .st + - .xht - .xhtml HTML+Django: type: markup tm_scope: text.html.django group: HTML - lexer: HTML+Django/Jinja extensions: - .mustache - .jinja + aliases: + - html+django/jinja + - html+jinja + - htmldjango + ace_mode: django HTML+ERB: type: markup tm_scope: text.html.erb group: HTML - lexer: RHTML aliases: - erb extensions: - .erb - - .deface + - .erb.deface + ace_mode: html_ruby HTML+PHP: type: markup @@ -1015,35 +1207,48 @@ HTML+PHP: group: HTML extensions: - .phtml + ace_mode: php HTTP: type: data extensions: - .http + tm_scope: source.httpspec + ace_mode: text + +Hack: + type: programming + ace_mode: php + extensions: + - .hh + - .php + tm_scope: text.html.php Haml: group: HTML type: markup extensions: - .haml - - .deface + - .haml.deface + ace_mode: haml Handlebars: type: markup - lexer: Handlebars aliases: - hbs extensions: - .handlebars - .hbs tm_scope: text.html.handlebars + ace_mode: handlebars Harbour: type: programming - lexer: Text only color: "#0e60e3" extensions: - .hb + tm_scope: none + ace_mode: text Haskell: type: programming @@ -1051,6 +1256,7 @@ Haskell: extensions: - .hs - .hsc + ace_mode: haskell Haxe: type: programming @@ -1063,93 +1269,110 @@ Haxe: Hy: type: programming - lexer: Hy - ace_mode: clojure + ace_mode: text color: "#7891b1" extensions: - .hy + aliases: + - hylang + tm_scope: source.hy IDL: type: programming - lexer: IDL color: "#e3592c" extensions: - .pro - .dlm + ace_mode: text IGOR Pro: type: programming - lexer: Igor extensions: - .ipf + aliases: + - igor + - igorpro + tm_scope: none + ace_mode: text INI: type: data extensions: - .ini + - .cfg - .prefs - .properties tm_scope: source.ini + aliases: + - dosini + ace_mode: ini -Inno Setup: +IRC log: + search_term: irc + aliases: + - irc + - irc logs extensions: - - .iss - lexer: Text only + - .irclog + - .weechatlog + tm_scope: none + ace_mode: text Idris: type: programming - lexer: Idris extensions: - .idr - .lidr + ace_mode: text Inform 7: type: programming - lexer: Inform 7 wrap: true extensions: - .ni - .i7x - tm_scope: source.inform + tm_scope: source.Inform7 + aliases: + - i7 + - inform7 + ace_mode: text Inno Setup: extensions: - .iss - lexer: Text only - -IRC log: - lexer: IRC logs - search_term: irc - aliases: - - irc - extensions: - - .irclog - - .weechatlog + tm_scope: none + ace_mode: text Io: type: programming color: "#a9188d" extensions: - .io + ace_mode: io Ioke: type: programming color: "#078193" extensions: - .ik + interpreters: + - ioke + ace_mode: text Isabelle: type: programming - lexer: Text only color: "#fdcd00" extensions: - .thy + tm_scope: source.isabelle.theory + ace_mode: text J: type: programming - lexer: Text only extensions: - .ijs + tm_scope: none + ace_mode: text JSON: type: data @@ -1160,29 +1383,21 @@ JSON: extensions: - .json - .lock - - .sublime-keymap - - .sublime-mousemap - - .sublime-project - - .sublime-settings - - .sublime-workspace - - .sublime_metrics - - .sublime_session filenames: - .jshintrc - composer.lock JSON5: type: data - lexer: JavaScript extensions: - .json5 tm_scope: source.js + ace_mode: javascript JSONLD: type: data group: JavaScript - ace_mode: json - lexer: JavaScript + ace_mode: javascript extensions: - .jsonld tm_scope: source.js @@ -1190,7 +1405,6 @@ JSONLD: JSONiq: type: programming ace_mode: jsoniq - lexer: XQuery extensions: - .jq tm_scope: source.xquery @@ -1201,6 +1415,14 @@ Jade: extensions: - .jade tm_scope: source.jade + ace_mode: jade + +Jasmin: + type: programming + ace_mode: java + extensions: + - .j + tm_scope: source.jasmin Java: type: programming @@ -1211,13 +1433,13 @@ Java: Java Server Pages: group: Java - lexer: Java Server Page search_term: jsp aliases: - jsp extensions: - .jsp tm_scope: text.html.jsp + ace_mode: jsp JavaScript: type: programming @@ -1233,6 +1455,7 @@ JavaScript: - .bones - .es6 - .frag + - .gs - .jake - .jsb - .jsfl @@ -1243,6 +1466,19 @@ JavaScript: - .pac - .sjs - .ssjs + - .sublime-build + - .sublime-commands + - .sublime-completions + - .sublime-keymap + - .sublime-macro + - .sublime-menu + - .sublime-mousemap + - .sublime-project + - .sublime-settings + - .sublime-theme + - .sublime-workspace + - .sublime_metrics + - .sublime_session - .xsjs - .xsjslib filenames: @@ -1255,17 +1491,18 @@ Julia: extensions: - .jl color: "#a270ba" + ace_mode: julia KRL: - lexer: Text only type: programming color: "#f5c800" extensions: - .krl + tm_scope: none + ace_mode: text Kit: type: markup - lexer: HTML ace_mode: html extensions: - .kit @@ -1278,30 +1515,32 @@ Kotlin: - .ktm - .kts tm_scope: source.Kotlin + ace_mode: text LFE: type: programming extensions: - .lfe color: "#004200" - lexer: Common Lisp group: Erlang tm_scope: source.lisp + ace_mode: lisp LLVM: extensions: - .ll + ace_mode: text LOLCODE: type: programming - lexer: Text only extensions: - .lol color: "#cc9900" + tm_scope: none + ace_mode: text LSL: type: programming - lexer: LSL ace_mode: lsl extensions: - .lsl @@ -1311,61 +1550,67 @@ LSL: LabVIEW: type: programming - lexer: Text only extensions: - .lvproj + tm_scope: none + ace_mode: text Lasso: type: programming - lexer: Lasso color: "#2584c3" extensions: - .lasso - .las + - .lasso8 - .lasso9 - .ldml tm_scope: file.lasso + aliases: + - lassoscript + ace_mode: text Latte: type: markup color: "#A8FF97" group: HTML - lexer: Smarty extensions: - .latte tm_scope: source.smarty + ace_mode: smarty Less: type: markup group: CSS - lexer: CSS extensions: - .less - tm_scope: source.css + tm_scope: source.css.less + ace_mode: less LilyPond: - lexer: Text only extensions: - .ly - .ily + ace_mode: text Liquid: type: markup - lexer: Text only extensions: - .liquid + tm_scope: none + ace_mode: liquid Literate Agda: type: programming group: Agda extensions: - .lagda + tm_scope: none + ace_mode: text Literate CoffeeScript: type: programming tm_scope: source.litcoffee group: CoffeeScript - lexer: Text only ace_mode: markdown wrap: true search_term: litcoffee @@ -1373,49 +1618,63 @@ Literate CoffeeScript: - litcoffee extensions: - .litcoffee + ace_mode: text Literate Haskell: type: programming group: Haskell search_term: lhs aliases: + - lhaskell - lhs extensions: - .lhs tm_scope: text.tex.latex.haskell + ace_mode: text LiveScript: type: programming - ace_mode: ls color: "#499886" aliases: + - live-script - ls extensions: - .ls - ._ls filenames: - Slakefile + ace_mode: livescript Logos: type: programming extensions: - .xm + - .x + - .xi + ace_mode: text Logtalk: type: programming extensions: - .lgt - .logtalk + ace_mode: text LookML: type: programming - lexer: YAML ace_mode: yaml color: "#652B81" extensions: - .lookml tm_scope: source.yaml +LoomScript: + type: programming + extensions: + - .ls + tm_scope: source.loomscript + ace_mode: text + Lua: type: programming ace_mode: lua @@ -1426,49 +1685,54 @@ Lua: - .nse - .pd_lua - .rbxs + - .wlua interpreters: - lua M: type: programming - lexer: Common Lisp aliases: - mumps extensions: - .mumps - .m tm_scope: source.lisp + ace_mode: lisp MTML: type: markup - lexer: HTML color: "#0095d9" extensions: - .mtml tm_scope: text.html.basic + ace_mode: html Makefile: + type: programming aliases: + - bsdmake - make + - mf extensions: - .mak - .mk filenames: - - makefile - - Makefile - GNUmakefile + - Makefile + - makefile interpreters: - make + ace_mode: makefile Mako: extensions: - .mako - .mao tm_scope: text.html.mako + ace_mode: text Markdown: type: prose - lexer: Text only ace_mode: markdown wrap: true extensions: @@ -1478,24 +1742,28 @@ Markdown: - .mkdn - .mkdown - .ron - tm_scope: text.html.markdown + tm_scope: source.gfm Mask: type: markup - lexer: SCSS color: "#f97732" - ace_mode: scss + ace_mode: mask extensions: - .mask - tm_scope: source.scss + tm_scope: source.mask Mathematica: type: programming extensions: - .mathematica + - .cdf - .m + - .ma - .nb - lexer: Mathematica + - .nbp + aliases: + - mma + ace_mode: text Matlab: type: programming @@ -1503,11 +1771,18 @@ Matlab: extensions: - .matlab - .m + ace_mode: matlab + +Maven POM: + type: data + tm_scope: text.xml.pom + filenames: + - pom.xml + ace_mode: xml Max: type: programming color: "#ce279c" - lexer: JSON aliases: - max/msp - maxmsp @@ -1519,32 +1794,37 @@ Max: - .mxt - .pat tm_scope: source.json + ace_mode: json MediaWiki: type: prose - lexer: Text only wrap: true extensions: - .mediawiki + tm_scope: none + ace_mode: text Mercury: type: programming color: "#abcdef" - lexer: Prolog ace_mode: prolog + interpreters: + - mmi extensions: - .m - .moo - tm_scope: source.prolog + tm_scope: source.mercury + ace_mode: prolog MiniD: # Legacy searchable: false extensions: - .minid # Dummy extension + tm_scope: none + ace_mode: text Mirah: type: programming - lexer: Ruby search_term: mirah color: "#c7a938" extensions: @@ -1553,18 +1833,20 @@ Mirah: - .mir - .mirah tm_scope: source.ruby + ace_mode: ruby Monkey: type: programming - lexer: Monkey extensions: - .monkey + ace_mode: text Moocode: type: programming - lexer: MOOCode extensions: - .moo + tm_scope: none + ace_mode: text MoonScript: type: programming @@ -1572,36 +1854,43 @@ MoonScript: - .moon interpreters: - moon + ace_mode: text Myghty: extensions: - .myt + tm_scope: none + ace_mode: text NSIS: extensions: - .nsi - .nsh + ace_mode: text Nemerle: type: programming color: "#0d3c6e" extensions: - .n + ace_mode: text NetLogo: type: programming - lexer: Common Lisp color: "#ff2b2b" extensions: - .nlogo tm_scope: source.lisp + ace_mode: lisp Nginx: type: markup - lexer: Nginx configuration file extensions: - .nginxconf tm_scope: source.nginx + aliases: + - nginx configuration file + ace_mode: text Nimrod: type: programming @@ -1609,23 +1898,36 @@ Nimrod: extensions: - .nim - .nimrod + ace_mode: text + tm_scope: source.nim + +Ninja: + type: data + tm_scope: source.ninja + extensions: + - .ninja + ace_mode: text Nit: type: programming - lexer: Text only color: "#0d8921" extensions: - .nit + tm_scope: source.nit + ace_mode: text Nix: type: programming - lexer: Nix + color: "#7070ff" extensions: - .nix + aliases: + - nixos + tm_scope: source.nix + ace_mode: nix Nu: type: programming - lexer: Scheme color: "#c9df40" aliases: - nush @@ -1634,6 +1936,9 @@ Nu: filenames: - Nukefile tm_scope: source.scheme + ace_mode: scheme + interpreters: + - nush NumPy: group: Python @@ -1641,6 +1946,8 @@ NumPy: - .numpy - .numpyw - .numsc + tm_scope: none + ace_mode: text OCaml: type: programming @@ -1657,10 +1964,10 @@ OCaml: ObjDump: type: data - lexer: objdump extensions: - .objdump tm_scope: objdump.x86asm + ace_mode: assembly_x86 Objective-C: type: programming @@ -1669,9 +1976,11 @@ Objective-C: aliases: - obj-c - objc + - objectivec extensions: - .m - .h + ace_mode: objectivec Objective-C++: type: programming @@ -1680,46 +1989,54 @@ Objective-C++: aliases: - obj-c++ - objc++ + - objectivec++ extensions: - .mm + ace_mode: objectivec Objective-J: type: programming color: "#ff0c5a" aliases: - obj-j + - objectivej + - objj extensions: - .j - .sj tm_scope: source.js.objj + ace_mode: text Omgrofl: type: programming extensions: - .omgrofl color: "#cabbff" - lexer: Text only + tm_scope: none + ace_mode: text Opa: type: programming extensions: - .opa + ace_mode: text Opal: type: programming color: "#f7ede0" - lexer: Text only extensions: - .opal + tm_scope: none + ace_mode: text OpenCL: type: programming group: C - lexer: C extensions: - .cl - .opencl tm_scope: source.c + ace_mode: c_cpp OpenEdge ABL: type: programming @@ -1731,42 +2048,55 @@ OpenEdge ABL: - .p - .cls tm_scope: source.abl + ace_mode: text OpenSCAD: type: programming - lexer: Text only extensions: - .scad + tm_scope: none + ace_mode: text Org: type: prose - lexer: Text only wrap: true extensions: - .org + tm_scope: none + ace_mode: text Ox: type: programming - lexer: Text only extensions: - .ox - .oxh - .oxo + tm_scope: none + ace_mode: text Oxygene: type: programming - lexer: Text only color: "#5a63a3" extensions: - .oxygene + tm_scope: none + ace_mode: text + +Oz: + type: programming + color: "#fcaf3e" + extensions: + - .oz + tm_scope: source.oz + ace_mode: text PAWN: type: programming - lexer: C++ color: "#dbb284" extensions: - .pwn tm_scope: source.c++ + ace_mode: c_cpp PHP: type: programming @@ -1778,7 +2108,6 @@ PHP: - .aw - .ctp - .fcgi - - .module - .php3 - .php4 - .php5 @@ -1787,49 +2116,59 @@ PHP: - Phakefile interpreters: - php + aliases: + - inc Pan: type: programming - lexer: Pan color: '#cc0000' extensions: - .pan + tm_scope: none + ace_mode: text Papyrus: type: programming color: "#6600cc" - lexer: Text only extensions: - .psc + tm_scope: none + ace_mode: text Parrot: type: programming color: "#f3ca0a" - lexer: Text only extensions: - .parrot # Dummy extension - -Parrot Internal Representation: - group: Parrot - type: programming - lexer: Text only - aliases: - - pir - extensions: - - .pir + tm_scope: none + ace_mode: text Parrot Assembly: group: Parrot type: programming - lexer: Text only aliases: - pasm extensions: - .pasm + interpreters: + - parrot + tm_scope: none + ace_mode: text + +Parrot Internal Representation: + group: Parrot + tm_scope: source.parrot.pir + type: programming + aliases: + - pir + extensions: + - .pir + interpreters: + - parrot + ace_mode: text Pascal: type: programming - lexer: Delphi color: "#b0ce4e" extensions: - .pas @@ -1837,6 +2176,7 @@ Pascal: - .dpr - .lpr - .pp + ace_mode: pascal Perl: type: programming @@ -1861,44 +2201,57 @@ Perl6: type: programming color: "#0298c3" extensions: - - .p6 - .6pl - .6pm - .nqp + - .p6 - .p6l - .p6m + - .pl - .pl6 + - .pm - .pm6 + - .t + filenames: + - Rexfile + interpreters: + - perl6 + tm_scope: none + ace_mode: perl PigLatin: type: programming color: "#fcd7de" - lexer: Text only extensions: - .pig + tm_scope: none + ace_mode: text Pike: type: programming color: "#066ab2" - lexer: Pike extensions: - .pike - .pmod + interpreters: + - pike + ace_mode: text Pod: type: prose - lexer: Text only ace_mode: perl wrap: true extensions: - .pod + tm_scope: none PogoScript: type: programming color: "#d80074" - lexer: Text only extensions: - .pogo + tm_scope: none + ace_mode: text PostScript: type: markup @@ -1906,6 +2259,9 @@ PostScript: - .ps - .eps tm_scope: source.postscript + aliases: + - postscr + ace_mode: text PowerShell: type: programming @@ -1919,27 +2275,30 @@ PowerShell: Processing: type: programming - lexer: Java color: "#2779ab" extensions: - .pde + ace_mode: text Prolog: type: programming - lexer: Logtalk color: "#74283c" extensions: - .pl - .ecl - .pro - .prolog + interpreters: + - swipl + ace_mode: prolog Propeller Spin: type: programming - lexer: Text only color: "#2b446d" extensions: - .spin + tm_scope: none + ace_mode: text Protocol Buffer: type: markup @@ -1949,6 +2308,15 @@ Protocol Buffer: extensions: - .proto tm_scope: source.protobuf + ace_mode: protobuf + +Public Key: + type: data + extensions: + - .asc + - .pub + tm_scope: none + ace_mode: text Puppet: type: programming @@ -1957,21 +2325,32 @@ Puppet: - .pp filenames: - Modulefile + ace_mode: text Pure Data: type: programming color: "#91de79" - lexer: Text only extensions: - .pd + tm_scope: none + ace_mode: text + +PureBasic: + type: programming + color: "#5a6986" + extensions: + - .pb + - .pbi + tm_scope: none + ace_mode: text PureScript: type: programming color: "#bcdc53" - lexer: Haskell extensions: - .purs tm_scope: source.haskell + ace_mode: haskell Python: type: programming @@ -1987,22 +2366,28 @@ Python: - .pyp - .pyt - .pyw + - .tac - .wsgi - .xpy filenames: - - wscript - - SConstruct + - BUILD - SConscript + - SConstruct + - Snakefile + - wscript interpreters: - python + - python2 + - python3 Python traceback: type: data group: Python - lexer: Python Traceback searchable: false extensions: - .pytb + tm_scope: text.python.traceback + ace_mode: text QML: type: markup @@ -2010,20 +2395,23 @@ QML: extensions: - .qml tm_scope: source.qml + ace_mode: text QMake: - lexer: Text only extensions: - .pro - .pri + interpreters: + - qmake + ace_mode: text R: type: programming color: "#198ce7" - lexer: S aliases: - R - Rscript + - splus extensions: - .r - .R @@ -2034,10 +2422,19 @@ R: - .Rprofile interpreters: - Rscript + ace_mode: r + +RAML: + type: data + lexer: YAML + ace_mode: yaml + tm_scope: source.yaml + color: "#77d9fb" + extensions: + - .raml RDoc: type: prose - lexer: Rd ace_mode: rdoc wrap: true extensions: @@ -2046,7 +2443,6 @@ RDoc: REALbasic: type: programming - lexer: VB.net extensions: - .rbbas - .rbfrm @@ -2055,40 +2451,48 @@ REALbasic: - .rbtbar - .rbuistate tm_scope: source.vbnet + ace_mode: text RHTML: type: markup group: HTML extensions: - .rhtml - tm_scope: text.html.ruby + tm_scope: text.html.erb + aliases: + - html+ruby + ace_mode: rhtml RMarkdown: type: prose - lexer: Text only wrap: true ace_mode: markdown extensions: - .rmd - .Rmd + tm_scope: none Racket: type: programming - lexer: Racket color: "#ae17ff" extensions: - .rkt - .rktd - .rktl - .scrbl - tm_scope: source.scheme + tm_scope: source.racket + ace_mode: lisp Ragel in Ruby Host: type: programming - lexer: Ragel in Ruby Host color: "#ff9c2e" extensions: - .rl + aliases: + - ragel-rb + - ragel-ruby + tm_scope: none + ace_mode: text Raw token data: search_term: raw @@ -2096,10 +2500,11 @@ Raw token data: - raw extensions: - .raw + tm_scope: none + ace_mode: text Rebol: type: programming - lexer: REBOL color: "#358a5b" extensions: - .reb @@ -2107,18 +2512,24 @@ Rebol: - .r2 - .r3 - .rebol + ace_mode: text Red: type: programming - lexer: Text only color: "#ee0000" extensions: - .red - .reds + aliases: + - red/system + tm_scope: none + ace_mode: text Redcode: extensions: - .cw + tm_scope: none + ace_mode: text RobotFramework: type: programming @@ -2126,10 +2537,10 @@ RobotFramework: - .robot # - .txt tm_scope: text.robot + ace_mode: text Rouge: type: programming - lexer: Clojure ace_mode: clojure color: "#cc0088" extensions: @@ -2166,6 +2577,8 @@ Ruby: - .watchr interpreters: - ruby + - macruby + - rake filenames: - .pryrc - Appraisals @@ -2187,13 +2600,15 @@ Rust: color: "#dea584" extensions: - .rs + ace_mode: rust SAS: type: programming color: "#1E90FF" - lexer: Text only extensions: - .sas + tm_scope: source.sas + ace_mode: text SCSS: type: markup @@ -2203,14 +2618,22 @@ SCSS: extensions: - .scss +SPARQL: + type: data + tm_scope: source.sparql + ace_mode: text + extensions: + - .sparql + - .rq + SQF: type: programming color: "#FFCB1F" - lexer: C++ extensions: - .sqf - .hqf - tm_scope: source.c++ + tm_scope: source.sqf + ace_mode: text SQL: type: data @@ -2218,6 +2641,8 @@ SQL: ace_mode: sql extensions: - .sql + - .cql + - .ddl - .prc - .tab - .udf @@ -2226,18 +2651,30 @@ SQL: STON: type: data group: Smalltalk - lexer: JSON extensions: - .ston - tm_scope: source.json + tm_scope: source.smalltalk + ace_mode: text Sage: type: programming - lexer: Python group: Python extensions: - .sage + - .sagews tm_scope: source.python + ace_mode: python + +SaltStack: + type: data + group: YAML + aliases: + - saltstate + - salt + extensions: + - .sls + tm_scope: source.yaml.salt + ace_mode: yaml Sass: type: markup @@ -2245,7 +2682,7 @@ Sass: group: CSS extensions: - .sass - - .scss + ace_mode: sass Scala: type: programming @@ -2255,6 +2692,8 @@ Scala: - .scala - .sbt - .sc + interpreters: + - scala Scaml: group: HTML @@ -2262,6 +2701,7 @@ Scaml: extensions: - .scaml tm_scope: source.scaml + ace_mode: text Scheme: type: programming @@ -2277,6 +2717,7 @@ Scheme: - racket - bigloo - chicken + ace_mode: scheme Scilab: type: programming @@ -2284,17 +2725,18 @@ Scilab: - .sci - .sce - .tst + ace_mode: text Self: type: programming color: "#0579aa" - lexer: Text only extensions: - .self + tm_scope: none + ace_mode: text Shell: type: programming - lexer: Bash search_term: bash color: "#89e051" aliases: @@ -2308,27 +2750,33 @@ Shell: - .cgi - .command - .fcgi + - .ksh - .tmux - .zsh interpreters: - bash + - rc - sh - zsh - filenames: - - Dockerfile + ace_mode: sh ShellSession: type: programming - lexer: Bash Session extensions: - .sh-session + aliases: + - bash session + - console + tm_scope: text.shell-session + ace_mode: sh Shen: type: programming color: "#120F14" - lexer: Text only extensions: - .shen + tm_scope: none + ace_mode: text Slash: type: programming @@ -2336,24 +2784,30 @@ Slash: extensions: - .sl tm_scope: text.html.slash + ace_mode: text Slim: group: HTML type: markup - lexer: Slim color: "#ff8877" extensions: - .slim + ace_mode: text Smalltalk: type: programming color: "#596706" extensions: - .st + - .cs + aliases: + - squeak + ace_mode: text Smarty: extensions: - .tpl + ace_mode: smarty SourcePawn: type: programming @@ -2363,13 +2817,14 @@ SourcePawn: extensions: - .sp tm_scope: source.sp + ace_mode: text Squirrel: type: programming - lexer: C++ extensions: - .nut tm_scope: source.c++ + ace_mode: c_cpp Standard ML: type: programming @@ -2382,10 +2837,10 @@ Standard ML: - .sig - .sml tm_scope: source.ml + ace_mode: text Stata: type: programming - lexer: Text only extensions: - .do - .ado @@ -2394,48 +2849,54 @@ Stata: - .mata - .matah - .sthlp + ace_mode: text Stylus: type: markup group: CSS - lexer: Text only extensions: - .styl + tm_scope: none + ace_mode: stylus SuperCollider: type: programming color: "#46390b" - lexer: Text only extensions: - .scd + - .sc + tm_scope: none + ace_mode: text Swift: type: programming - lexer: Swift color: "#ffac45" extensions: - .swift + ace_mode: text SystemVerilog: type: programming color: "#343761" - lexer: systemverilog extensions: - .sv - .svh - .vh + ace_mode: verilog TOML: type: data extensions: - .toml tm_scope: source.toml + ace_mode: toml TXL: type: programming - lexer: Text only extensions: - .txl + tm_scope: none + ace_mode: text Tcl: type: programming @@ -2447,6 +2908,7 @@ Tcl: interpreters: - tclsh - wish + ace_mode: tcl Tcsh: type: programming @@ -2455,11 +2917,12 @@ Tcsh: - .tcsh - .csh tm_scope: source.shell + ace_mode: sh TeX: type: markup color: "#3D6117" - ace_mode: latex + ace_mode: tex wrap: true aliases: - latex @@ -2485,30 +2948,55 @@ Tea: extensions: - .tea tm_scope: source.tea + ace_mode: text + +Text: + type: prose + wrap: true + extensions: + - .txt + - .fr + tm_scope: none + ace_mode: text Textile: type: prose - lexer: Text only ace_mode: textile wrap: true extensions: - .textile + tm_scope: none + +Thrift: + type: programming + tm_scope: source.thrift + extensions: + - .thrift + ace_mode: text Turing: type: programming color: "#45f715" - lexer: Text only extensions: - .t - .tu + tm_scope: none + ace_mode: text + +Turtle: + type: data + extensions: + - .ttl + tm_scope: source.turtle + ace_mode: text Twig: type: markup group: PHP - lexer: HTML+Django/Jinja extensions: - .twig tm_scope: text.html.twig + ace_mode: twig TypeScript: type: programming @@ -2518,11 +3006,11 @@ TypeScript: extensions: - .ts tm_scope: source.ts + ace_mode: typescript Unified Parallel C: type: programming group: C - lexer: C ace_mode: c_cpp color: "#755223" extensions: @@ -2532,14 +3020,13 @@ Unified Parallel C: UnrealScript: type: programming color: "#a54c4d" - lexer: Java extensions: - .uc tm_scope: source.java + ace_mode: java VCL: type: programming - lexer: Perl ace_mode: perl color: "#0298c3" extensions: @@ -2548,7 +3035,6 @@ VCL: VHDL: type: programming - lexer: vhdl color: "#543978" extensions: - .vhdl @@ -2559,6 +3045,7 @@ VHDL: - .vhs - .vht - .vhw + ace_mode: vhdl Vala: type: programming @@ -2566,14 +3053,15 @@ Vala: extensions: - .vala - .vapi + ace_mode: vala Verilog: type: programming - lexer: verilog color: "#848bf3" extensions: - .v - .veo + ace_mode: verilog VimL: type: programming @@ -2586,12 +3074,12 @@ VimL: filenames: - .vimrc - _vimrc - - vimrc - gvimrc + - vimrc + ace_mode: text Visual Basic: type: programming - lexer: VB.net color: "#945db7" extensions: - .vb @@ -2603,21 +3091,40 @@ Visual Basic: - .vbhtml - .vbs tm_scope: source.vbnet + aliases: + - vb.net + - vbnet + ace_mode: text Volt: - type: programming - lexer: D - color: "#0098db" - extensions: - - .volt - tm_scope: source.d + type: programming + color: "#0098db" + extensions: + - .volt + tm_scope: source.d + ace_mode: d + +Web Ontology Language: + type: markup + color: "#3994bc" + extensions: + - .owl + tm_scope: text.xml + ace_mode: xml + +WebIDL: + type: programming + extensions: + - .webidl + tm_scope: source.webidl + ace_mode: text XC: type: programming - lexer: C extensions: - .xc tm_scope: source.c + ace_mode: c_cpp XML: type: markup @@ -2638,14 +3145,17 @@ XML: - .dita - .ditamap - .ditaval + - .dll.config - .filters - .fsproj + - .fxml - .glade - .grxml - .ivy - .jelly - .kml - .launch + - .mm - .mxml - .nproj - .nuspec @@ -2659,6 +3169,8 @@ XML: - .rss - .scxml - .srdf + - .stTheme + - .sublime-snippet - .svg - .targets - .tmCommand @@ -2667,12 +3179,14 @@ XML: - .tmSnippet - .tmTheme - .tml + - .ts - .ui - .urdf - .vbproj - .vcxproj - .vxml - .wsdl + - .wsf - .wxi - .wxl - .wxs @@ -2682,22 +3196,26 @@ XML: - .xlf - .xliff - .xmi + - .xml.dist - .xsd - .xul - .zcml filenames: - .classpath - .project - - build.xml.dist - - phpunit.xml.dist + - Settings.StyleCop + - Web.Debug.config + - Web.Release.config + - Web.config + - packages.config XProc: type: programming - lexer: XML extensions: - .xpl - .xproc tm_scope: text.xml + ace_mode: xml XQuery: type: programming @@ -2708,12 +3226,13 @@ XQuery: - .xql - .xqm - .xqy + ace_mode: xquery XS: - lexer: C extensions: - .xs tm_scope: source.c + ace_mode: c_cpp XSLT: type: programming @@ -2723,10 +3242,10 @@ XSLT: - .xslt - .xsl tm_scope: text.xml.xsl + ace_mode: xml Xojo: type: programming - lexer: VB.net extensions: - .xojo_code - .xojo_menu @@ -2735,11 +3254,13 @@ Xojo: - .xojo_toolbar - .xojo_window tm_scope: source.vbnet + ace_mode: text Xtend: type: programming extensions: - .xtend + ace_mode: text YAML: type: data @@ -2751,22 +3272,24 @@ YAML: - .reek - .rviz - .yaml + ace_mode: yaml Zephir: type: programming - lexer: PHP color: "#118f9e" extensions: - .zep - tm_scope: text.html.php + tm_scope: source.php.zephir + ace_mode: php Zimpl: type: programming - lexer: Text only extensions: - .zimpl - .zmpl - .zpl + tm_scope: none + ace_mode: text eC: type: programming @@ -2774,10 +3297,11 @@ eC: extensions: - .ec - .eh + tm_scope: none + ace_mode: text edn: type: data - lexer: Clojure ace_mode: clojure color: "#db5855" extensions: @@ -2787,28 +3311,29 @@ edn: fish: type: programming group: Shell - lexer: Text only extensions: - .fish + tm_scope: source.fish + ace_mode: text mupad: - lexer: MuPAD extensions: - .mu + ace_mode: text nesC: type: programming color: "#ffce3b" - lexer: nesC extensions: - .nc + ace_mode: text ooc: type: programming - lexer: Ooc color: "#b0b77e" extensions: - .ooc + ace_mode: text reStructuredText: type: prose @@ -2819,10 +3344,10 @@ reStructuredText: extensions: - .rst - .rest + ace_mode: text wisp: type: programming - lexer: Clojure ace_mode: clojure color: "#7582D1" extensions: @@ -2831,7 +3356,8 @@ wisp: xBase: type: programming - lexer: Text only color: "#3a4040" extensions: - .prg + tm_scope: none + ace_mode: text diff --git a/lib/linguist/popular.yml b/lib/linguist/popular.yml index 68d9d0b8..1a5cb750 100644 --- a/lib/linguist/popular.yml +++ b/lib/linguist/popular.yml @@ -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 diff --git a/lib/linguist/samples.rb b/lib/linguist/samples.rb index 82c011b1..efcba365 100644 --- a/lib/linguist/samples.rb +++ b/lib/linguist/samples.rb @@ -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 diff --git a/lib/linguist/shebang.rb b/lib/linguist/shebang.rb new file mode 100644 index 00000000..6f04e866 --- /dev/null +++ b/lib/linguist/shebang.rb @@ -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 diff --git a/lib/linguist/strategy/filename.rb b/lib/linguist/strategy/filename.rb new file mode 100644 index 00000000..e682863b --- /dev/null +++ b/lib/linguist/strategy/filename.rb @@ -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 diff --git a/lib/linguist/vendor.yml b/lib/linguist/vendor.yml index 490a910f..4ba241ca 100644 --- a/lib/linguist/vendor.yml +++ b/lib/linguist/vendor.yml @@ -32,31 +32,35 @@ # Erlang bundles - ^rebar$ +- erlang.mk # Go dependencies - Godeps/_workspace/ -# Bootstrap minified css and js -- (^|/)bootstrap([^.]*)(\.min)?\.(js|css)$ +# Minified JavaScript and CSS +- (\.|-)min\.(js|css)$ + +#Stylesheets imported from packages +- ([^\s]*)import\.(css|less|scss|styl)$ + +# Bootstrap css and js +- (^|/)bootstrap([^.]*)\.(js|css|less|scss|styl)$ +- (^|/)custom\.bootstrap([^\s]*)(js|css|less|scss|styl)$ # Font Awesome -- font-awesome.min.css -- font-awesome.css +- (^|/)font-awesome\.(css|less|scss|styl)$ # Foundation css -- foundation.min.css -- foundation.css +- (^|/)foundation\.(css|less|scss|styl)$ # Normalize.css -- normalize.css +- (^|/)normalize\.(css|less|scss|styl)$ -# Bourbon SCSS -- (^|/)[Bb]ourbon/.*\.css$ -- (^|/)[Bb]ourbon/.*\.scss$ +# Bourbon css +- (^|/)[Bb]ourbon/.*\.(css|less|scss|styl)$ # Animate.css -- animate.css -- animate.min.css +- (^|/)animate\.(css|less|scss|styl)$ # Vendored dependencies - third[-_]?party/ @@ -73,12 +77,12 @@ ## Commonly Bundled JavaScript frameworks ## # jQuery -- (^|/)jquery([^.]*)(\.min)?\.js$ -- (^|/)jquery\-\d\.\d+(\.\d+)?(\.min)?\.js$ +- (^|/)jquery([^.]*)\.js$ +- (^|/)jquery\-\d\.\d+(\.\d+)?\.js$ # jQuery UI -- (^|/)jquery\-ui(\-\d\.\d+(\.\d+)?)?(\.\w+)?(\.min)?\.(js|css)$ -- (^|/)jquery\.(ui|effects)\.([^.]*)(\.min)?\.(js|css)$ +- (^|/)jquery\-ui(\-\d\.\d+(\.\d+)?)?(\.\w+)?\.(js|css)$ +- (^|/)jquery\.(ui|effects)\.([^.]*)\.(js|css)$ # Prototype - (^|/)prototype(.*)\.js$ @@ -110,27 +114,32 @@ # MathJax - (^|/)MathJax/ +# Chart.js +- (^|/)Chart\.js$ + +# Codemirror +- (^|/)[Cc]ode[Mm]irror/(lib|mode|theme|addon|keymap) + # SyntaxHighlighter - http://alexgorbatchev.com/ - (^|/)shBrush([^.]*)\.js$ - (^|/)shCore\.js$ - (^|/)shLegacy\.js$ # AngularJS -- (^|/)angular([^.]*)(\.min)?\.js$ +- (^|/)angular([^.]*)\.js$ # D3.js -- (^|\/)d3(\.v\d+)?([^.]*)(\.min)?\.js$ +- (^|\/)d3(\.v\d+)?([^.]*)\.js$ # React -- (^|/)react(-[^.]*)?(\.min)?\.js$ +- (^|/)react(-[^.]*)?\.js$ # Modernizr -- (^|/)modernizr\-\d\.\d+(\.\d+)?(\.min)?\.js$ +- (^|/)modernizr\-\d\.\d+(\.\d+)?\.js$ - (^|/)modernizr\.custom\.\d+\.js$ # Knockout - (^|/)knockout-(\d+\.){3}(debug\.)?js$ -- knockout-min.js ## Python ## @@ -168,8 +177,8 @@ - \.intellisense\.js$ # jQuery validation plugin (MS bundles this with asp.net mvc) -- (^|/)jquery([^.]*)\.validate(\.unobtrusive)?(\.min)?\.js$ -- (^|/)jquery([^.]*)\.unobtrusive\-ajax(\.min)?\.js$ +- (^|/)jquery([^.]*)\.validate(\.unobtrusive)?\.js$ +- (^|/)jquery([^.]*)\.unobtrusive\-ajax\.js$ # Microsoft Ajax - (^|/)[Mm]icrosoft([Mm]vc)?([Aa]jax|[Vv]alidation)(\.debug)?\.js$ @@ -196,7 +205,7 @@ - (^|/)extjs/welcome/ # Html5shiv -- (^|/)html5shiv(\.min)?\.js$ +- (^|/)html5shiv\.js$ # Samples folders - ^[Ss]amples/ @@ -215,8 +224,8 @@ - ^[Tt]est/fixtures/ # PhoneGap/Cordova -- (^|/)cordova([^.]*)(\.min)?\.js$ -- (^|/)cordova\-\d\.\d(\.\d)?(\.min)?\.js$ +- (^|/)cordova([^.]*)\.js$ +- (^|/)cordova\-\d\.\d(\.\d)?\.js$ # Foundation js - foundation(\..*)?\.js$ @@ -227,16 +236,12 @@ # .DS_Store's - .[Dd][Ss]_[Ss]tore$ -# Mercury --use-subdirs -- Mercury/ - # R packages - ^vignettes/ - ^inst/extdata/ # Octicons - octicons.css -- octicons.min.css - sprockets-octicons.scss # Typesafe Activator diff --git a/lib/linguist/version.rb b/lib/linguist/version.rb index f02c0c45..73b6c63a 100644 --- a/lib/linguist/version.rb +++ b/lib/linguist/version.rb @@ -1,3 +1,3 @@ module Linguist - VERSION = "3.4.1" + VERSION = "4.2.7" end diff --git a/package.json b/package.json new file mode 100644 index 00000000..acd7cd9e --- /dev/null +++ b/package.json @@ -0,0 +1,6 @@ +{ + "repository": "https://github.com/github/linguist", + "dependencies": { + "season": "~>3.0" + } +} diff --git a/samples/Ant Build System/filenames/ant.xml b/samples/Ant Build System/filenames/ant.xml new file mode 100644 index 00000000..54e96ddc --- /dev/null +++ b/samples/Ant Build System/filenames/ant.xml @@ -0,0 +1,110 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/samples/Ant Build System/filenames/build.xml b/samples/Ant Build System/filenames/build.xml new file mode 120000 index 00000000..6c7d5cd4 --- /dev/null +++ b/samples/Ant Build System/filenames/build.xml @@ -0,0 +1 @@ +ant.xml \ No newline at end of file diff --git a/samples/BitBake/gstreamer-libav.bb b/samples/BitBake/gstreamer-libav.bb new file mode 100644 index 00000000..803bcf2f --- /dev/null +++ b/samples/BitBake/gstreamer-libav.bb @@ -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}" + diff --git a/samples/BitBake/qtbase-native.bb b/samples/BitBake/qtbase-native.bb new file mode 100644 index 00000000..5d24f48a --- /dev/null +++ b/samples/BitBake/qtbase-native.bb @@ -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" + diff --git a/samples/C#/AssemblyInfo.cs b/samples/C#/AssemblyInfo.cs new file mode 100644 index 00000000..1ef68427 --- /dev/null +++ b/samples/C#/AssemblyInfo.cs @@ -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("")] diff --git a/samples/C#/BsonPropertyValue.cs b/samples/C#/BsonPropertyValue.cs new file mode 100644 index 00000000..94d27c88 --- /dev/null +++ b/samples/C#/BsonPropertyValue.cs @@ -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; + } + } +} \ No newline at end of file diff --git a/samples/C#/MongoExpressionVisitor.cs b/samples/C#/MongoExpressionVisitor.cs new file mode 100644 index 00000000..b7a1effe --- /dev/null +++ b/samples/C#/MongoExpressionVisitor.cs @@ -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 VisitOrderBy(ReadOnlyCollection orderBys) + { + if (orderBys != null) + { + List 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 VisitFieldDeclarationList(ReadOnlyCollection fields) + { + if (fields == null) + return fields; + + List 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; + } + } +} \ No newline at end of file diff --git a/samples/C++/16F88.h b/samples/C++/16F88.h new file mode 100644 index 00000000..28f51ce4 --- /dev/null +++ b/samples/C++/16F88.h @@ -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 . + */ + +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 *CallStack; + Register *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(); +}; diff --git a/samples/C++/Entity.h b/samples/C++/Entity.h new file mode 100644 index 00000000..619fc1d1 --- /dev/null +++ b/samples/C++/Entity.h @@ -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 `_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 \ No newline at end of file diff --git a/samples/C++/Memory16F88.h b/samples/C++/Memory16F88.h new file mode 100644 index 00000000..ced2ef13 --- /dev/null +++ b/samples/C++/Memory16F88.h @@ -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 . + */ + +#include "Memory.h" + +class Memory16F88 : public Memory +{ +private: + uint8_t memory[512]; + std::map 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); +}; diff --git a/samples/C++/ThreadedQueue.h b/samples/C++/ThreadedQueue.h new file mode 100644 index 00000000..6b2fbaad --- /dev/null +++ b/samples/C++/ThreadedQueue.h @@ -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 . + */ + +#ifndef __THREADED_QUEUE_H__ +#define __THREADED_QUEUE_H__ + +#include +#include + +template +class ThreadedQueue : public std::queue +{ +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::push(item); + signalItems(); + } +}; + +#endif /*__THREADED_QUEUE_H__*/ diff --git a/samples/C++/bar.hh b/samples/C++/bar.hh new file mode 100644 index 00000000..a87343c2 --- /dev/null +++ b/samples/C++/bar.hh @@ -0,0 +1,10 @@ +class Bar +{ + protected: + + char *name; + + public: + + void hello(); +} diff --git a/samples/C/2D.C b/samples/C/2D.C new file mode 100644 index 00000000..b3d45015 --- /dev/null +++ b/samples/C/2D.C @@ -0,0 +1,145 @@ +#include "2D.h" +#include + +void set_vgabasemem(void) +{ + ULONG vgabase; + SELECTOR tmp; + asm mov [tmp], ds + dpmi_get_sel_base(&vgabase, tmp); + vgabasemem = (char *)(-vgabase + 0xa0000); +} + +void drw_chdis(int mode) // change the display! +{ + regs.b.ah = 0x00; // seet theh display moode + regs.b.al = mode; // change it to the mode like innit + regs.h.flags = 0x72;// Set the dingoes kidneys out of FLAGS eh? + regs.h.ss = 0; // Like, totally set the stack segment + regs.h.sp = 0; // Set tha stack pointaaaaahhhhh!!! + dpmi_simulate_real_interrupt(0x10, ®s); +} + +void drw_pix(int x, int y, enum COLORS col) +{ + *VGAPIX(x, y) = col; +} + +void drw_line(int x0, int y0, int x1, int y1, enum COLORS col) +{ + // Going for the optimized version of bresenham's line algo. + int stp = (abs(y0 - y1) > abs(x0 - x1)); + int tmp, dx, dy, err, yi, i, j; // yi = y excrement + if (stp) { + // swappity swap + tmp = y0; + y0 = x0; + x0 = tmp; + + tmp = y1; + y1 = x1; + x1 = tmp; + } + // AAAAND NOW WE MUST DO ZEES AGAIN :( + // I'm sure there was a func somewhere that does this? :P + if (x0 > x1) { + tmp = x0; + x0 = x1; + x1 = tmp; + + tmp = y0; + y0 = y1; + y1 = tmp; + } + dx = (x1 - x0); + dy = (abs(y1 - y0)); + err = (dx / 2); + + if (y0 < y1) + yi = 1; + else + yi = -1; + j = y0; + for (i = x0; i < x1; i++) + { + if (stp) + *VGAPIX(j, i) = col; + else + *VGAPIX(i, j) = col; + + err -= dy; + if (err < 0) { + j += yi; + err += dx; + } + } +} + +void drw_rectl(int x, int y, int w, int h, enum COLORS col) +{ + drw_line(x, y, x+w, y, col); + drw_line(x+w, y, x+w, y+h, col); + + drw_line(x, y, x, y+h, col); + drw_line(x, y+h, x+w+1, y+h, col); +} + +void drw_rectf(int x, int y, int w, int h, enum COLORS col) +{ + int i, j; + for (j = y; j < x+h; j++) { + for (i = x; i < y+w; i++) { + *VGAPIX(i, j) = col; + } + } +} + +void drw_circl(int x, int y, int rad, enum COLORS col) +{ + int mang, i; // max angle, haha + int px, py; + mang = 360; // Yeah yeah I'll switch to rad later + for (i = 0; i <= mang; i++) + { + px = cos(i)*rad + x; // + px; // causes some really cools effects! :D + py = sin(i)*rad + y; // + py; + *VGAPIX(px, py) = col; + } +} + +void drw_tex(int x, int y, int w, int h, enum COLORS tex[]) +{ // i*w+j + int i, j; + for (i = 0; i < w; i++) + { + for (j = 0; j < h; j++) + { + *VGAPIX(x+i, y+j) = tex[j*w+i]; + } + } +} + +void 2D_init(void) +{ + set_vgabasemem(); + drw_chdis(0x13); +} + +void 2D_exit(void) +{ + drw_chdis(3); +} +/* +int main() +{ + set_vgabasemem(); + drw_chdis(0x13); + + while(!kbhit()) { + if ((getch()) == 0x1b) // escape + break; + } + drw_chdis(3); + return 0; +} +*/ diff --git a/samples/C/2D.H b/samples/C/2D.H new file mode 100644 index 00000000..e3354986 --- /dev/null +++ b/samples/C/2D.H @@ -0,0 +1,29 @@ +#ifndef __2DGFX +#define __2DGFX +// Includes +#include +#include +#include +#include + +// 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 diff --git a/samples/C/ArrowLeft.h b/samples/C/ArrowLeft.h new file mode 100644 index 00000000..b3577c0e --- /dev/null +++ b/samples/C/ArrowLeft.h @@ -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 . + */ + +/* 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"}; + + diff --git a/samples/C/GLKMatrix4.h b/samples/C/GLKMatrix4.h new file mode 100644 index 00000000..41eb5afd --- /dev/null +++ b/samples/C/GLKMatrix4.h @@ -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 +#include +#include + +#if defined(__ARM_NEON__) +#include +#endif + +#include +#include +#include +#include + +#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 */ diff --git a/samples/C/NWMan.h b/samples/C/NWMan.h new file mode 100644 index 00000000..abcd2ddb --- /dev/null +++ b/samples/C/NWMan.h @@ -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 diff --git a/samples/C/Nightmare.h b/samples/C/Nightmare.h new file mode 100644 index 00000000..3b639c20 --- /dev/null +++ b/samples/C/Nightmare.h @@ -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 diff --git a/samples/C/bitmap.h b/samples/C/bitmap.h new file mode 100644 index 00000000..30ab99ea --- /dev/null +++ b/samples/C/bitmap.h @@ -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 . + */ + +#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); diff --git a/samples/C/color.h b/samples/C/color.h new file mode 100644 index 00000000..5c60b480 --- /dev/null +++ b/samples/C/color.h @@ -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 . + */ + +#include + +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 + diff --git a/samples/C/driver.h b/samples/C/driver.h new file mode 100644 index 00000000..e376c97d --- /dev/null +++ b/samples/C/driver.h @@ -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 . + */ + +#include +#include + +#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; diff --git a/samples/C/elf.h b/samples/C/elf.h new file mode 100644 index 00000000..a270eb14 --- /dev/null +++ b/samples/C/elf.h @@ -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 . + */ + +#include +#include + +#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); diff --git a/samples/Zephir/filenames/exception.zep.c b/samples/C/exception.zep.c similarity index 100% rename from samples/Zephir/filenames/exception.zep.c rename to samples/C/exception.zep.c diff --git a/samples/Zephir/filenames/exception.zep.h b/samples/C/exception.zep.h similarity index 100% rename from samples/Zephir/filenames/exception.zep.h rename to samples/C/exception.zep.h diff --git a/samples/C/filter.h b/samples/C/filter.h new file mode 100644 index 00000000..a1a13c9f --- /dev/null +++ b/samples/C/filter.h @@ -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 . + */ + +#include +#include +#include + +struct console_filter { + // General callback for all actions etc. + // Preferred prototype: + // char (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 (char c, console_info_t *info, console_driver_t *input); + char (*read_callback)(char, console_info_t*, console_driver_t*); + + // Preferred prototype: + // char (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; + diff --git a/samples/C/info.h b/samples/C/info.h new file mode 100644 index 00000000..50be7b69 --- /dev/null +++ b/samples/C/info.h @@ -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 . + */ + +#include +#include + +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; diff --git a/samples/C/interface.h b/samples/C/interface.h new file mode 100644 index 00000000..2c3bfeff --- /dev/null +++ b/samples/C/interface.h @@ -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 . + */ + +#include +#include +#include +#include + +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); diff --git a/samples/C/ip4.h b/samples/C/ip4.h new file mode 100644 index 00000000..b2c8a2a8 --- /dev/null +++ b/samples/C/ip4.h @@ -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 . + */ + +#include +#include + +#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); diff --git a/samples/C/multiboot.h b/samples/C/multiboot.h new file mode 100644 index 00000000..fcbc13e1 --- /dev/null +++ b/samples/C/multiboot.h @@ -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 . + */ + +#include + +#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(); diff --git a/samples/C/ntru_encrypt.h b/samples/C/ntru_encrypt.h new file mode 100644 index 00000000..4893f6f9 --- /dev/null +++ b/samples/C/ntru_encrypt.h @@ -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 +#include + + +/** + * 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 */ diff --git a/samples/C/portio.h b/samples/C/portio.h new file mode 100644 index 00000000..8a805680 --- /dev/null +++ b/samples/C/portio.h @@ -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 . + */ + +#include +#include + +// 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); diff --git a/samples/C/scheduler.h b/samples/C/scheduler.h new file mode 100644 index 00000000..a886003c --- /dev/null +++ b/samples/C/scheduler.h @@ -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 . + */ + +#include +#include +#include + +#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); \ No newline at end of file diff --git a/samples/C/syscalls.h b/samples/C/syscalls.h new file mode 100644 index 00000000..dc054e2b --- /dev/null +++ b/samples/C/syscalls.h @@ -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 . + */ + +#include +#include + +#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 +}; diff --git a/samples/C/vfs.h b/samples/C/vfs.h new file mode 100644 index 00000000..3502460d --- /dev/null +++ b/samples/C/vfs.h @@ -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 . + */ + +#include + +#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); diff --git a/samples/C/vmem.h b/samples/C/vmem.h new file mode 100644 index 00000000..82bd29be --- /dev/null +++ b/samples/C/vmem.h @@ -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 . + */ + +#include + +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 diff --git a/samples/CMake/filenames/CMakeLists.txt b/samples/CMake/filenames/CMakeLists.txt new file mode 100644 index 00000000..27f3b3a7 --- /dev/null +++ b/samples/CMake/filenames/CMakeLists.txt @@ -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) diff --git a/samples/CMake/sample1.cmake b/samples/CMake/sample1.cmake new file mode 100644 index 00000000..c4b23485 --- /dev/null +++ b/samples/CMake/sample1.cmake @@ -0,0 +1,15 @@ +cmake_minimum_required(VERSION 2.6) + +enable_testing() + +set(CMAKE_BUILD_TYPE debug) + +include_directories("/usr/local/include") + +find_library(ssl_LIBRARY NAMES ssl PATHS "/usr/local/lib") + +add_custom_command(OUTPUT "ver.c" "ver.h" COMMAND ./ver.sh) + +add_executable(foo foo.c bar.c baz.c ver.c) + +target_link_libraries(foo ${ssl_LIBRARY}) diff --git a/samples/CMake/sample2.cmake b/samples/CMake/sample2.cmake new file mode 100644 index 00000000..7411b5d6 --- /dev/null +++ b/samples/CMake/sample2.cmake @@ -0,0 +1,25 @@ +cmake_minimum_required(VERSION 2.8 FATAL_ERROR) + +project(PCLVisualizer) +target_link_libraries (PCLVisualizer ${PCL_LIBRARIES}) + +#it seems it's needed only on OS X 10.9 +find_package(GLEW REQUIRED) +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -I/usr/include -v") + +find_package(PCL 1.7 REQUIRED) + +include_directories(${PCL_INCLUDE_DIRS}) +link_directories(${PCL_LIBRARY_DIRS}) +add_definitions(${PCL_DEFINITIONS}) + +set(PCL_BUILD_TYPE Release) + +file(GLOB PCL_openni_viewer_SRC + "src/*.h" + "src/*.cpp" +) +add_executable(PCLVisualizer ${PCL_openni_viewer_SRC}) + +#add this line to solve probem in mac os x 10.9 +target_link_libraries(PCLVisualizer ${PCL_COMMON_LIBRARIES} ${PCL_IO_LIBRARIES} ${PCL_VISUALIZATION_LIBRARIES} ${PCL_FEATURES_LIBRARIES}) \ No newline at end of file diff --git a/samples/CMake/sample3.cmake b/samples/CMake/sample3.cmake new file mode 100644 index 00000000..7bd9ea77 --- /dev/null +++ b/samples/CMake/sample3.cmake @@ -0,0 +1,33 @@ +# Specifications for building user and development documentation. +# +# ==================================================================== +# Copyright (c) 2009 Ian Blumel. All rights reserved. +# +# This software is licensed as described in the file LICENSE, which +# you should have received as part of this distribution. +# ==================================================================== + +CMAKE_MINIMUM_REQUIRED(VERSION 2.6) + +FIND_FILE( SPHINX sphinx-build.exe) + +# If we are windows call to the make.bat file, otherwise rely on the Makefile +# to handle the processing. +IF(WIN32) + SET(SPHINX_MAKE make.bat) +ELSE(WIN32) + SET(SPHINX_MAKE make) +ENDIF(WIN32) + +ADD_CUSTOM_TARGET( + doc_usr + COMMAND ${SPHINX_MAKE} html + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/usr +) + +ADD_CUSTOM_TARGET( + doc_dev + COMMAND ${SPHINX_MAKE} html + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/dev +) + diff --git a/samples/CMake/sample4.cmake b/samples/CMake/sample4.cmake new file mode 100644 index 00000000..e3c123a0 --- /dev/null +++ b/samples/CMake/sample4.cmake @@ -0,0 +1,33 @@ +cmake_minimum_required (VERSION 2.6) + +set (CMAKE_RUNTIME_OUTPUT_DIRECTORY "bin") + +list(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake/vala) +find_package(Vala REQUIRED) +include(ValaPrecompile) +include(ValaVersion) +ensure_vala_version("0.11.0" MINIMUM) + +project (template C) + +find_package(PkgConfig) + +pkg_check_modules(GOBJECT REQUIRED gobject-2.0) +add_definitions(${GOBJECT_CFLAGS} ${GOBJECT_CFLAGS_OTHER}) +link_libraries(${GOBJECT_LIBRARIES}) +link_directories(${GOBJECT_LIBRARY_DIRS}) + + +vala_precompile(VALA_C + src/template.vala +PACKAGES +OPTIONS + --thread +CUSTOM_VAPIS +GENERATE_VAPI +GENERATE_HEADER +DIRECTORY + gen +) + +add_executable("template" ${VALA_C}) diff --git a/samples/CMake/sample5.cmake b/samples/CMake/sample5.cmake new file mode 100644 index 00000000..f87136e7 --- /dev/null +++ b/samples/CMake/sample5.cmake @@ -0,0 +1,89 @@ +# - Check if the STDCALL function exists. +# This works for non-cdecl functions (kernel32 functions, for example) +# CHECK_STDCALL_FUNCTION_EXISTS(FUNCTION FUNCTION_DUMMY_ARGS VARIABLE) +# - macro which checks if the stdcall function exists +# FUNCTION_DECLARATION - the definition of the function ( e.g.: Sleep(500) ) +# VARIABLE - variable to store the result +# +# The following variables may be set before calling this macro to +# modify the way the check is run: +# +# CMAKE_REQUIRED_FLAGS = string of compile command line flags +# CMAKE_REQUIRED_DEFINITIONS = list of macros to define (-DFOO=bar) +# CMAKE_REQUIRED_INCLUDES = list of include directories +# CMAKE_REQUIRED_LIBRARIES = list of libraries to link +# CMAKE_EXTRA_INCLUDE_FILES = list of extra includes to check in + +MACRO(CHECK_STDCALL_FUNCTION_EXISTS FUNCTION_DECLARATION VARIABLE) + IF("${VARIABLE}" MATCHES "^${VARIABLE}$") + #get includes + SET(CHECK_STDCALL_FUNCTION_PREMAIN) + FOREACH(def ${CMAKE_EXTRA_INCLUDE_FILES}) + SET(CHECK_STDCALL_FUNCTION_PREMAIN "${CHECK_STDCALL_FUNCTION_PREMAIN}#include \"${def}\"\n") + ENDFOREACH(def) + + #add some default includes + IF ( HAVE_WINDOWS_H ) + SET(CHECK_STDCALL_FUNCTION_PREMAIN "${CHECK_STDCALL_FUNCTION_PREMAIN}#include \"windows.h\"\n") + ENDIF ( HAVE_WINDOWS_H ) + IF ( HAVE_UNISTD_H ) + SET(CHECK_STDCALL_FUNCTION_PREMAIN "${CHECK_STDCALL_FUNCTION_PREMAIN}#include \"unistd.h\"\n") + ENDIF ( HAVE_UNISTD_H ) + IF ( HAVE_DIRECT_H ) + SET(CHECK_STDCALL_FUNCTION_PREMAIN "${CHECK_STDCALL_FUNCTION_PREMAIN}#include \"direct.h\"\n") + ENDIF ( HAVE_DIRECT_H ) + IF ( HAVE_IO_H ) + SET(CHECK_STDCALL_FUNCTION_PREMAIN "${CHECK_STDCALL_FUNCTION_PREMAIN}#include \"io.h\"\n") + ENDIF ( HAVE_IO_H ) + IF ( HAVE_SYS_TIMEB_H ) + SET(CHECK_STDCALL_FUNCTION_PREMAIN "${CHECK_STDCALL_FUNCTION_PREMAIN}#include \"sys/timeb.h\"\n") + ENDIF ( HAVE_SYS_TIMEB_H ) + + STRING(REGEX REPLACE "(\\(.*\\))" "" CHECK_STDCALL_FUNCTION_EXISTS_FUNCTION ${FUNCTION_DECLARATION} ) + + SET(MACRO_CHECK_STDCALL_FUNCTION_DEFINITIONS "${CMAKE_REQUIRED_FLAGS}") + MESSAGE(STATUS "Looking for ${CHECK_STDCALL_FUNCTION_EXISTS_FUNCTION}") + + IF(CMAKE_REQUIRED_LIBRARIES) + SET(CHECK_STDCALL_FUNCTION_EXISTS_ADD_LIBRARIES + "-DLINK_LIBRARIES:STRING=${CMAKE_REQUIRED_LIBRARIES}") + ELSE(CMAKE_REQUIRED_LIBRARIES) + SET(CHECK_STDCALL_FUNCTION_EXISTS_ADD_LIBRARIES) + ENDIF(CMAKE_REQUIRED_LIBRARIES) + + IF(CMAKE_REQUIRED_INCLUDES) + SET(CHECK_STDCALL_FUNCTION_EXISTS_ADD_INCLUDES + "-DINCLUDE_DIRECTORIES:STRING=${CMAKE_REQUIRED_INCLUDES}") + ELSE(CMAKE_REQUIRED_INCLUDES) + SET(CHECK_STDCALL_FUNCTION_EXISTS_ADD_INCLUDES) + ENDIF(CMAKE_REQUIRED_INCLUDES) + + SET(CHECK_STDCALL_FUNCTION_DECLARATION ${FUNCTION_DECLARATION}) + CONFIGURE_FILE("${clucene-shared_SOURCE_DIR}/cmake/CheckStdCallFunctionExists.cpp.in" + "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/CheckStdCallFunctionExists.cpp" IMMEDIATE @ONLY) + FILE(READ "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/CheckStdCallFunctionExists.cpp" + CHECK_STDCALL_FUNCTION_CONTENT) + + TRY_COMPILE(${VARIABLE} + ${CMAKE_BINARY_DIR} + "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/CheckStdCallFunctionExists.cpp" + COMPILE_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS} + CMAKE_FLAGS -DCOMPILE_DEFINITIONS:STRING=${MACRO_CHECK_STDCALL_FUNCTION_DEFINITIONS} + "${CHECK_STDCALL_FUNCTION_EXISTS_ADD_LIBRARIES}" + "${CHECK_STDCALL_FUNCTION_EXISTS_ADD_INCLUDES}" + OUTPUT_VARIABLE OUTPUT) + IF(${VARIABLE}) + SET(${VARIABLE} 1 CACHE INTERNAL "Have function ${FUNCTION_DECLARATION}") + MESSAGE(STATUS "Looking for ${FUNCTION_DECLARATION} - found") + FILE(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log + "Determining if the stdcall function ${FUNCTION_DECLARATION} exists passed with the following output:\n" + "${OUTPUT}\nCheckStdCallFunctionExists.cpp:\n${CHECK_STDCALL_FUNCTION_CONTENT}\n\n") + ELSE(${VARIABLE}) + MESSAGE(STATUS "Looking for ${FUNCTION_DECLARATION} - not found") + SET(${VARIABLE} "" CACHE INTERNAL "Have function ${FUNCTION_DECLARATION}") + FILE(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log + "Determining if the stdcall function ${FUNCTION_DECLARATION} exists failed with the following output:\n" + "${OUTPUT}\nCheckStdCallFunctionExists.cpp:\n${CHECK_STDCALL_FUNCTION_CONTENT}\n\n") + ENDIF(${VARIABLE}) + ENDIF("${VARIABLE}" MATCHES "^${VARIABLE}$") +ENDMACRO(CHECK_STDCALL_FUNCTION_EXISTS) diff --git a/samples/CMake/uninstall.cmake.in b/samples/CMake/uninstall.cmake.in new file mode 100644 index 00000000..a5b7436f --- /dev/null +++ b/samples/CMake/uninstall.cmake.in @@ -0,0 +1,22 @@ +IF (NOT EXISTS "@PROJECT_BINARY_DIR@/install_manifest.txt") + MESSAGE (FATAL_ERROR "Cannot find install manifest: \"@PROJECT_BINARY_DIR@/install_manifest.txt\"") +ENDIF (NOT EXISTS "@PROJECT_BINARY_DIR@/install_manifest.txt") + +FILE (READ "@PROJECT_BINARY_DIR@/install_manifest.txt" files) +STRING (REGEX REPLACE "\n" ";" files "${files}") +FOREACH (file ${files}) + MESSAGE (STATUS "Uninstalling \"$ENV{DESTDIR}${file}\"") + IF (EXISTS "$ENV{DESTDIR}${file}") + EXEC_PROGRAM ( + "@CMAKE_COMMAND@" ARGS "-E remove \"$ENV{DESTDIR}${file}\"" + OUTPUT_VARIABLE rm_out + RETURN_VALUE rm_retval + ) + IF (NOT "${rm_retval}" STREQUAL 0) + MESSAGE (FATAL_ERROR "Problem when removing \"$ENV{DESTDIR}${file}\"") + ENDIF (NOT "${rm_retval}" STREQUAL 0) + ELSE (EXISTS "$ENV{DESTDIR}${file}") + MESSAGE (STATUS "File \"$ENV{DESTDIR}${file}\" does not exist.") + ENDIF (EXISTS "$ENV{DESTDIR}${file}") +ENDFOREACH (file) + diff --git a/samples/CartoCSS/amenity-points.mss b/samples/CartoCSS/amenity-points.mss new file mode 100644 index 00000000..a7b94ea0 --- /dev/null +++ b/samples/CartoCSS/amenity-points.mss @@ -0,0 +1,1879 @@ +@marina-text: #576ddf; // also swimming_pool +@wetland-text: darken(#017fff, 10%); /* Also for marsh */ +@mud-text: darken(#aea397, 20%); +@shop-icon: #ac39ac; +@transportation-icon: #0092da; +@transportation-text: #0066ff; +@airtransport: #8461C4; + +@landcover-font-size: 10; +@landcover-font-size-big: 12; +@landcover-font-size-bigger: 15; +@landcover-wrap-width-size: 25; +@landcover-wrap-width-size-big: 35; +@landcover-wrap-width-size-bigger: 45; +@landcover-face-name: @oblique-fonts; + +@standard-wrap-width: 30; + +.points { + [feature = 'tourism_alpine_hut'][zoom >= 13] { + point-file: url('symbols/alpinehut.p.16.png'); + point-placement: interior; + } + + [feature = 'amenity_shelter'][zoom >= 16] { + point-file: url('symbols/shelter2.p.16.png'); + point-placement: interior; + } + + [feature = 'amenity_atm'][zoom >= 17] { + point-file: url('symbols/atm2.p.16.png'); + point-placement: interior; + } + + [feature = 'amenity_bank'][zoom >= 17] { + point-file: url('symbols/bank2.p.16.png'); + point-placement: interior; + } + + [feature = 'amenity_bar'][zoom >= 17] { + point-file: url('symbols/bar.p.20.png'); + point-placement: interior; + } + + [feature = 'amenity_bicycle_rental'][zoom >= 17] { + point-file: url('symbols/rental_bicycle.p.20.png'); + point-placement: interior; + } + + [feature = 'highway_bus_stop'] { + [zoom >= 16] { + marker-file: url('symbols/square.svg'); + marker-fill: @transportation-icon; + marker-placement: interior; + marker-width: 6; + } + [zoom >= 17] { + marker-file: url('symbols/bus_stop.p.12.png'); + marker-width: 12; + } + } + + [feature = 'amenity_bus_station'][zoom >= 16] { + point-file: url('symbols/bus_station.n.16.png'); + point-placement: interior; + } + + [feature = 'highway_traffic_signals'][zoom >= 17] { + marker-file: url('symbols/traffic_light.svg'); + marker-fill: #0a0a0a; + marker-placement: interior; + } + + [feature = 'amenity_cafe'][zoom >= 17] { + point-file: url('symbols/cafe.p.16.png'); + point-placement: interior; + } + + [feature = 'tourism_camp_site'][zoom >= 16] { + point-file: url('symbols/camping.n.16.png'); + point-placement: interior; + } + + [feature = 'highway_ford'][zoom >= 16] { + point-file: url('symbols/transport_ford.p.16.png'); + point-placement: interior; + } + + [feature = 'tourism_caravan_site'][zoom >= 16] { + point-file: url('symbols/caravan_park.p.24.png'); + point-placement: interior; + } + + [feature = 'amenity_car_sharing'][zoom >= 16] { + point-file: url('symbols/car_share.p.16.png'); + point-placement: interior; + } + + [feature = 'tourism_chalet'][zoom >= 17] { + point-file: url('symbols/chalet.p.16.png'); + point-placement: interior; + } + + [feature = 'amenity_cinema'][zoom >= 16] { + point-file: url('symbols/cinema.p.24.png'); + point-placement: interior; + } + + [feature = 'amenity_fire_station'][zoom >= 16] { + point-file: url('symbols/firestation.p.16.png'); + point-placement: interior; + } + + [feature = 'amenity_fuel'][zoom >= 17] { + point-file: url('symbols/fuel.p.16.png'); + point-placement: interior; + } + + [feature = 'tourism_guest_house'][zoom >= 17] { + point-file: url('symbols/guest_house.p.16.png'); + point-placement: interior; + } + + [feature = 'amenity_hospital'][zoom >= 15] { + point-file: url('symbols/hospital.p.16.png'); + point-placement: interior; + } + + [feature = 'tourism_hostel'][zoom >= 17] { + point-file: url('symbols/hostel.p.20.png'); + point-placement: interior; + } + + [feature = 'tourism_hotel'][zoom >= 17] { + point-file: url('symbols/hotel2.p.20.png'); + point-placement: interior; + } + + [feature = 'tourism_motel'][zoom >= 17] { + point-file: url('symbols/motel.p.20.png'); + point-placement: interior; + } + + [feature = 'tourism_information'][zoom >= 17] { + point-file: url('symbols/information.p.16.png'); + point-placement: interior; + } + + [feature = 'amenity_embassy'][zoom >= 17] { + point-file: url('symbols/embassy.png'); + point-placement: interior; + } + + [feature = 'amenity_library'][zoom >= 16] { + point-file: url('symbols/library.p.20.png'); + point-placement: interior; + } + + [feature = 'amenity_courthouse'][zoom > 16] { + point-file: url('symbols/amenity_court.p.20.png'); + point-placement: interior; + } + + [feature = 'waterway_lock'], + [feature = 'lock_yes'] { + [zoom >= 15] { + marker-fill: #969494; + marker-width: 9; + marker-line-width: 0; + marker-placement: interior; + } + } + + [feature = 'man_made_mast'][zoom >= 17] { + point-file: url('symbols/communications.p.20.png'); + point-placement: interior; + } + + [feature = 'tourism_museum'][zoom >= 16] { + point-file: url('symbols/museum.p.16.png'); + point-placement: interior; + } + + [feature = 'amenity_parking'][zoom >= 16] { + marker-file: url('symbols/parking.svg'); + marker-placement: interior; + marker-clip: false; + marker-fill: @transportation-icon; + [access != ''][access != 'public'][access != 'yes'] { + marker-opacity: 0.33; + } + } + + [feature = 'amenity_pharmacy'][zoom >= 17] { + point-file: url('symbols/pharmacy.p.16.png'); + point-placement: interior; + } + + [feature = 'amenity_place_of_worship'][zoom >= 16] { + point-file: url('symbols/place_of_worship3.p.16.png'); + point-placement: interior; + [religion = 'christian'] { + point-file: url('symbols/christian3.p.14.png'); + [denomination = 'jehovahs_witness']{ + point-file: url('symbols/place_of_worship3.p.16.png'); + } + } + [religion = 'muslim'] { + point-file: url('symbols/islamic3.p.16.png'); + } + [religion = 'sikh'] { + point-file: url('symbols/sikh3.p.16.png'); + } + [religion = 'jewish'] { + point-file: url('symbols/jewish3.p.16.png'); + } + [religion = 'hindu'] { + point-file: url('symbols/hindu.png'); + } + [religion = 'buddhist'] { + point-file: url('symbols/buddhist.png'); + } + [religion = 'shinto'] { + point-file: url('symbols/shinto.png'); + } + [religion = 'taoist'] { + point-file: url('symbols/taoist.png'); + } + } + + [feature = 'amenity_police'][zoom >= 16] { + point-file: url('symbols/police.p.16.png'); + point-placement: interior; + } + + [feature = 'amenity_post_box'][zoom >= 17] { + point-file: url('symbols/post_box.p.16.png'); + point-placement: interior; + } + + [feature = 'amenity_post_office'][zoom >= 17] { + point-file: url('symbols/post_office.p.16.png'); + point-placement: interior; + } + + [feature = 'amenity_pub'][zoom >= 17] { + point-file: url('symbols/pub.p.16.png'); + point-placement: interior; + } + + [feature = 'amenity_biergarten'][zoom >= 17] { + point-file: url('symbols/biergarten.p.16.png'); + point-placement: interior; + } + + [feature = 'amenity_recycling'][zoom >= 16] { + point-file: url('symbols/recycling.p.16.png'); + point-placement: interior; + } + + [feature = 'amenity_restaurant'][zoom >= 17] { + point-file: url('symbols/restaurant.p.16.png'); + point-placement: interior; + } + + [feature = 'amenity_fast_food'][zoom >= 17] { + point-file: url('symbols/fast_food.png'); + point-placement: interior; + } + + [feature = 'amenity_telephone'][zoom >= 17] { + point-file: url('symbols/telephone.p.16.png'); + point-placement: interior; + } + + [feature = 'amenity_emergency_phone'][zoom >= 17] { + point-file: url('symbols/sosphone.png'); + point-placement: interior; + } + + [feature = 'amenity_theatre'][zoom >= 16] { + point-file: url('symbols/theatre.p.20.png'); + point-placement: interior; + } + + [feature = 'amenity_toilets'][zoom >= 17] { + point-file: url('symbols/toilets.p.20.png'); + point-placement: interior; + } + + [feature = 'amenity_drinking_water'][zoom >= 17] { + point-file: url('symbols/food_drinkingtap.p.20.png'); + point-placement: interior; + } + + [feature = 'amenity_prison'][zoom >= 17] { + point-file: url('symbols/amenity_prison.p.20.png'); + point-placement: interior; + } + + [feature = 'tourism_viewpoint'][zoom >= 16] { + point-file: url('symbols/view_point.p.16.png'); + point-placement: interior; + } + + [feature = 'man_made_water_tower'][zoom >= 17] { + point-file: url('symbols/tower_water.p.20.png'); + point-placement: interior; + } + + [feature = 'historic_memorial'][zoom >= 17] { + point-file: url('symbols/tourist_memorial.p.20.png'); + point-placement: interior; + } + + [feature = 'historic_archaeological_site'][zoom >= 16] { + point-file: url('symbols/tourist_archaeological2.glow.24.png'); + point-placement: interior; + } + + [feature = 'shop_other'][zoom >= 17] { + marker-fill: @shop-icon; + marker-width: 6; + marker-line-width: 0; + marker-placement: interior; + marker-clip: false; + } + + [feature = 'shop_supermarket'][zoom >= 16] { + marker-file: url('symbols/shop_supermarket.svg'); + marker-placement: interior; + marker-clip: false; + marker-fill: @shop-icon; + } + + [feature = 'shop_bakery'][zoom >= 17] { + marker-file: url('symbols/shop_bakery.p.16.png'); + marker-placement: interior; + marker-clip: false; + } + + [feature = 'shop_butcher'][zoom >= 17] { + marker-file: url('symbols/shop_butcher.png'); + marker-placement: interior; + marker-clip: false; + } + + [feature = 'shop_clothes'], + [feature = 'shop_fashion'] { + [zoom >= 17] { + marker-file: url('symbols/shop_clothes.svg'); + marker-placement: interior; + marker-clip: false; + marker-fill: @shop-icon; + } + } + + [feature = 'shop_convenience'][zoom >= 17] { + marker-file: url('symbols/shop_convenience.svg'); + marker-placement: interior; + marker-clip: false; + marker-fill: @shop-icon; + } + + [feature = 'shop_department_store'][zoom >= 16] { + point-file: url('symbols/department_store.p.16.png'); + point-placement: interior; + } + + [feature = 'shop_doityourself'][zoom >= 17] { + marker-file: url('symbols/shop_diy.p.16.png'); + marker-placement: interior; + marker-clip: false; + } + + [feature = 'shop_florist'][zoom >= 17] { + marker-file: url('symbols/florist.p.16.png'); + marker-placement: interior; + marker-clip: false; + } + + [feature = 'shop_hairdresser'][zoom >= 17] { + marker-file: url('symbols/shop_hairdresser.p.16.png'); + marker-placement: interior; + marker-clip: false; + } + + [feature = 'shop_car'][zoom >= 17] { + marker-file: url('symbols/shop_car.svg'); + marker-placement: interior; + marker-clip: false; + marker-fill: @shop-icon; + } + + [feature = 'shop_car_repair'][zoom >= 17] { + marker-file: url('symbols/shopping_car_repair.p.16.png'); + marker-placement: interior; + marker-clip: false; + } + + [feature = 'shop_bicycle'][zoom >= 17] { + marker-file: url('symbols/shopping_bicycle.p.16.png'); + marker-placement: interior; + marker-clip: false; + } + + [feature = 'leisure_playground'][zoom >= 17] { + point-file: url('symbols/playground.p.20.png'); + point-placement: interior; + } + + [feature = 'tourism_picnic_site'][zoom >= 16] { + point-file: url('symbols/picnic.p.16.png'); + point-placement: interior; + } + + [feature = 'leisure_picnic_table'][zoom >= 17] { + point-file: url('symbols/picnic.p.16.png'); + point-placement: interior; + } + + [feature = 'leisure_slipway'][zoom >= 17] { + point-file: url('symbols/transport_slipway.p.20.png'); + point-placement: interior; + } + + [feature = 'aeroway_helipad'][zoom >= 16]::aeroway { + marker-file: url('symbols/helipad.svg'); + marker-clip: false; + marker-fill: @airtransport; + } + + [feature = 'aeroway_aerodrome'][zoom >= 10][zoom < 14]::aeroway { + marker-file: url('symbols/aerodrome.svg'); + marker-clip: false; + marker-fill: @airtransport; + } + + [feature = 'man_made_lighthouse'][zoom >= 15]::man_made { + point-file: url('symbols/lighthouse.p.20.png'); + point-placement: interior; + } + + [feature = 'natural_peak'][zoom >= 11]::natural { + marker-file: url('symbols/peak.svg'); + marker-fill: #d08f55; + marker-placement: interior; + } + + [feature = 'natural_volcano'][zoom >= 11]::natural { + marker-file: url('symbols/peak.svg'); + marker-fill: #d40000; + marker-placement: interior; + } + + [feature = 'natural_saddle'][zoom >= 15]::natural { + marker-file: url('symbols/saddle.svg'); + marker-fill: #d08f55; + marker-placement: interior; + } + + [feature = 'natural_cave_entrance'][zoom >= 15]::natural { + point-file: url('symbols/poi_cave.p.16.png'); + point-placement: interior; + } + + [feature = 'natural_spring'][zoom >= 14]::natural { + marker-file: url('symbols/spring.svg'); + marker-placement: interior; + } + + [feature = 'natural_tree'][zoom >= 16]::natural { + marker-placement: interior; + marker-ignore-placement: true; + marker-line-width: 0; + marker-width: 3; + marker-fill: #239c45; + [zoom >= 17] { + marker-line-width: 1; + marker-line-color: #8ef2ab; + marker-width: 4; + } + } + + [feature = 'power_generator']['generator:source' = 'wind']::power, + [feature = 'power_generator'][power_source = 'wind']::power { + [zoom >= 15] { + point-file: url('symbols/power_wind.png'); + point-placement: interior; + } + } + + [feature = 'man_made_windmill'][zoom >= 16]::man_made { + point-file: url('symbols/windmill.png'); + point-placement: interior; + } + + [feature = 'man_made_mast'][zoom >= 17]::man_made { + point-file: url('symbols/communications.p.20.png'); + point-placement: interior; + } +} + +.amenity-low-priority { + [railway = 'level_crossing'][zoom >= 14]::railway { + point-file: url('symbols/level_crossing.svg'); + point-placement: interior; + [zoom >= 16] { + point-file: url('symbols/level_crossing2.svg'); + } + } + + [highway = 'mini_roundabout'][zoom >= 16]::highway { + marker-file: url('symbols/mini_roundabout.svg'); + marker-placement: interior; + } + + [barrier = 'gate']::barrier { + [zoom >= 16] { + marker-file: url('symbols/gate.svg'); + marker-placement: interior; + } + } + + [barrier = 'lift_gate'][zoom >= 16]::barrier { + marker-file: url('symbols/liftgate.svg'); + marker-fill: #3f3f3f; + marker-placement: interior + } + + [barrier = 'bollard'], + [barrier = 'block'] { + [zoom >= 16] { + marker-width: 3; + marker-line-width: 0; + marker-fill: #7d7c7c; + marker-placement: interior; + + [zoom >= 18] { + marker-width: 4; + } + } + } +} + +.text-low-zoom[zoom < 10], +.text[zoom >= 10] { + [feature = 'place_island'][zoom >= 7][way_pixels > 3000], + [feature = 'place_island'][zoom >= 16], + [feature = 'place_islet'][zoom >= 14][way_pixels > 3000], + [feature = 'place_islet'][zoom >= 17] { + text-name: "[name]"; + text-fill: #000; + text-size: 10; + [way_pixels > 12000] { text-size: 12; } + [way_pixels > 48000] { text-size: 15; } + text-face-name: @oblique-fonts; + text-halo-radius: 1; + text-wrap-width: @standard-wrap-width; + text-placement: interior; + } + + [feature = 'amenity_pub'], + [feature = 'amenity_restaurant'], + [feature = 'amenity_cafe'], + [feature = 'amenity_fast_food'], + [feature = 'amenity_biergarten'], + [feature = 'amenity_bar'] { + [zoom >= 17] { + text-name: "[name]"; + text-fill: #734a08; + text-size: 10; + text-dy: 11; + text-face-name: @bold-fonts; + text-halo-radius: 1; + text-wrap-width: @standard-wrap-width; + text-placement: interior; + [feature = 'amenity_bar']{ + text-dy: 13; + } + } + } + + [feature = 'amenity_library'], + [feature = 'amenity_theatre'], + [feature = 'amenity_courthouse'], + [feature = 'amenity_cinema'] { + [zoom >= 17] { + text-name: "[name]"; + text-size: 10; + text-fill: #734a08; + text-dy: 13; + text-face-name: @bold-fonts; + text-halo-radius: 1; + text-wrap-width: @standard-wrap-width; + text-placement: interior; + [feature = 'amenity_cinema'] { + text-dy: 15; + } + } + } + + [feature = 'amenity_parking'][zoom >= 17] { + text-name: "[name]"; + text-size: 9; + text-fill: @transportation-text; + text-dy: 9; + text-face-name: @book-fonts; + text-halo-radius: 1; + text-wrap-width: @standard-wrap-width; + text-placement: interior; + [access != ''][access != 'public'][access != 'yes'] { + text-fill: #66ccaf; + } + } + + [feature = 'amenity_police'][zoom >= 17] { + text-name: "[name]"; + text-size: 10; + text-fill: #734a08; + text-dy: 11; + text-face-name: @book-fonts; + text-halo-radius: 1; + text-wrap-width: @standard-wrap-width; + text-placement: interior; + } + + [feature = 'amenity_fire_station'][zoom >= 17] { + text-name: "[name]"; + text-size: 10; + text-fill: #734a08; + text-dy: 11; + text-face-name: @book-fonts; + text-halo-radius: 1; + text-wrap-width: @standard-wrap-width; + text-placement: interior; + } + + [feature = 'amenity_place_of_worship'][zoom >= 17] { + text-name: "[name]"; + text-size: 10; + text-fill: #000033; + text-dy: 12; + text-face-name: @book-fonts; + text-halo-radius: 1; + text-wrap-width: @standard-wrap-width; + text-placement: interior; + } + + [feature = 'natural_wood'][is_building = 'no'] { + [zoom >= 8][way_pixels > 3000], + [zoom >= 17] { + text-name: "[name]"; + text-size: @landcover-font-size; + [way_pixels > 12000] { text-size: @landcover-font-size-big; } + [way_pixels > 48000] { text-size: @landcover-font-size-bigger; } + text-fill: darken(@wood, 40%); + text-face-name: @landcover-face-name; + text-halo-radius: 1; + text-halo-fill: rgba(255,255,255,0.6); + text-wrap-width: @landcover-wrap-width-size; + [way_pixels > 12000] {text-wrap-width: @landcover-wrap-width-size-big; } + [way_pixels > 48000] {text-wrap-width: @landcover-wrap-width-size-bigger; } + text-placement: interior; + } + } + + [feature = 'natural_peak'], + [feature = 'natural_volcano'] { + [zoom >= 13] { + text-name: "[name]"; + text-size: 10; + text-fill: brown; + text-dy: 7; + text-face-name: @book-fonts; + text-halo-radius: 1; + text-wrap-width: @standard-wrap-width; + text-placement: interior; + ele/text-name: "[ele]"; + ele/text-size: 9; + ele/text-fill: brown; + ele/text-dy: 6; + ele/text-face-name: @oblique-fonts; + ele/text-halo-radius: 1; + ele/text-placement: interior; + [name != ''] { + ele/text-dy: 19; + } + } + } + + [feature = 'natural_saddle'] { + [zoom >= 15] { + text-name: "[name]"; + text-size: 10; + text-fill: brown; + text-dy: 7; + text-face-name: @book-fonts; + text-halo-radius: 1; + text-wrap-width: @standard-wrap-width; + text-placement: interior; + ele/text-name: "[ele]"; + ele/text-size: 9; + ele/text-fill: brown; + ele/text-dy: 6; + ele/text-face-name: @oblique-fonts; + ele/text-halo-radius: 1; + ele/text-placement: interior; + [name != ''] { + ele/text-dy: 19; + } + } + } + + [feature = 'natural_cave_entrance'][zoom >= 15] { + text-name: "[name]"; + text-size: 10; + text-fill: brown; + text-dy: 11; + text-face-name: @book-fonts; + text-halo-radius: 1; + text-wrap-width: @standard-wrap-width; + text-placement: interior; + } + + [feature = 'historic_memorial'][zoom >= 17] { + text-name: "[name]"; + text-size: 9; + text-fill: brown; + text-dy: 13; + text-face-name: @book-fonts; + text-halo-radius: 1; + text-wrap-width: @standard-wrap-width; + text-placement: interior; + } + + [feature = 'historic_archaeological_site'][zoom >= 17] { + text-name: "[name]"; + text-size: 9; + text-fill: brown; + text-dy: 15; + text-face-name: @book-fonts; + text-halo-radius: 1; + text-wrap-width: @standard-wrap-width; + text-placement: interior; + } + + [feature = 'natural_water'], + [feature = 'natural_lake'], + [feature = 'landuse_reservoir'], + [feature = 'landuse_basin'] { + [way_area >= 40000000][zoom >= 10], + [way_area >= 10000000][zoom >= 11], + [way_area >= 2400000][zoom >= 12], + [way_area >= 600000][zoom >= 13], + [way_area >= 150000][zoom >= 14], + [way_area >= 80000][zoom >= 15], + [way_area >= 20000][zoom >= 16], + [zoom >= 17] { + text-name: "[name]"; + text-size: 12; + text-fill: @water-text; + text-face-name: @oblique-fonts; + text-halo-radius: 1; + text-wrap-width: @standard-wrap-width; + text-placement: interior; + } + } + + [feature = 'natural_mud'][is_building = 'no'] { + [zoom >= 10][way_pixels > 3000], + [zoom >= 17] { + text-name: "[name]"; + text-size: @landcover-font-size; + [way_pixels > 12000] { text-size: @landcover-font-size-big; } + [way_pixels > 48000] { text-size: @landcover-font-size-bigger; } + text-fill: @mud-text; + text-face-name: @landcover-face-name; + text-halo-radius: 1; + text-wrap-width: @landcover-wrap-width-size; + [way_pixels > 12000] {text-wrap-width: @landcover-wrap-width-size-big; } + [way_pixels > 48000] {text-wrap-width: @landcover-wrap-width-size-bigger; } + text-placement: interior; + } + } + + [feature = 'natural_wetland'][is_building = 'no'], + [feature = 'natural_marsh'][is_building = 'no'] { + [zoom >= 10][way_pixels > 3000], + [zoom >= 17] { + text-name: "[name]"; + text-size: @landcover-font-size; + [way_pixels > 12000] { text-size: @landcover-font-size-big; } + [way_pixels > 48000] { text-size: @landcover-font-size-bigger; } + text-fill: @wetland-text; + text-face-name: @landcover-face-name; + text-halo-radius: 1; + text-wrap-width: @landcover-wrap-width-size; + [way_pixels > 12000] {text-wrap-width: @landcover-wrap-width-size-big; } + [way_pixels > 48000] {text-wrap-width: @landcover-wrap-width-size-bigger; } + text-placement: interior; + } + } + + [feature = 'leisure_swimming_pool'][is_building = 'no'] { + [zoom >= 14][way_pixels > 3000], + [zoom >= 17] { + text-name: "[name]"; + text-size: @landcover-font-size; + [way_pixels > 12000] { text-size: @landcover-font-size-big; } + [way_pixels > 48000] { text-size: @landcover-font-size-bigger; } + text-fill: @marina-text; + text-face-name: @landcover-face-name; + text-halo-radius: 1; + text-wrap-width: @landcover-wrap-width-size; + [way_pixels > 12000] {text-wrap-width: @landcover-wrap-width-size-big; } + [way_pixels > 48000] {text-wrap-width: @landcover-wrap-width-size-bigger; } + text-placement: interior; + } + } + + [feature = 'leisure_sports_centre'][is_building = 'no'], + [feature = 'leisure_stadium'][is_building = 'no'] { + [zoom >= 10][way_pixels > 3000], + [zoom >= 17] { + text-name: "[name]"; + text-size: @landcover-font-size; + [way_pixels > 12000] { text-size: @landcover-font-size-big; } + [way_pixels > 48000] { text-size: @landcover-font-size-bigger; } + text-fill: darken(@stadium, 30%); + text-face-name: @landcover-face-name; + text-halo-radius: 1; + text-halo-fill: rgba(255,255,255,0.6); + text-wrap-width: @landcover-wrap-width-size; + [way_pixels > 12000] {text-wrap-width: @landcover-wrap-width-size-big; } + [way_pixels > 48000] {text-wrap-width: @landcover-wrap-width-size-bigger; } + text-placement: interior; + } + } + + [feature = 'leisure_track'][is_building = 'no'] { + [zoom >= 10][way_pixels > 3000], + [zoom >= 17] { + text-name: "[name]"; + text-size: @landcover-font-size; + [way_pixels > 12000] { text-size: @landcover-font-size-big; } + [way_pixels > 48000] { text-size: @landcover-font-size-bigger; } + text-fill: darken(@track, 40%); + text-face-name: @landcover-face-name; + text-halo-radius: 1; + text-wrap-width: @landcover-wrap-width-size; + [way_pixels > 12000] {text-wrap-width: @landcover-wrap-width-size-big; } + [way_pixels > 48000] {text-wrap-width: @landcover-wrap-width-size-bigger; } + text-placement: interior; + } + } + + [feature = 'leisure_pitch'][is_building = 'no'] { + [zoom >= 10][way_pixels > 3000], + [zoom >= 17] { + text-name: "[name]"; + text-size: @landcover-font-size; + [way_pixels > 12000] { text-size: @landcover-font-size-big; } + [way_pixels > 48000] { text-size: @landcover-font-size-bigger; } + text-fill: darken(@pitch, 40%); + text-face-name: @landcover-face-name; + text-halo-radius: 1; + text-halo-fill: rgba(255,255,255,0.6); + text-wrap-width: @landcover-wrap-width-size; + [way_pixels > 12000] {text-wrap-width: @landcover-wrap-width-size-big; } + [way_pixels > 48000] {text-wrap-width: @landcover-wrap-width-size-bigger; } + text-placement: interior; + } + } + + [feature = 'leisure_playground'] { + [way_area >= 150000][zoom >= 14], + [way_area >= 80000][zoom >= 15], + [way_area >= 20000][zoom >= 16], + [zoom >= 17] { + text-name: "[name]"; + text-size: 11; + text-dy: 13; + text-fill: darken(@park, 60%); + text-face-name: @book-fonts; + text-halo-radius: 1; + text-halo-fill: rgba(255,255,255,0.6); + text-wrap-width: @standard-wrap-width; + text-placement: interior; + } + } + + [feature = 'leisure_park'][is_building = 'no'], + [feature = 'leisure_recreation_ground'][is_building = 'no'], + [feature = 'landuse_recreation_ground'][is_building = 'no'], + [feature = 'landuse_conservation'][is_building = 'no'], + [feature = 'landuse_village_green'][is_building = 'no'], + [feature = 'leisure_common'][is_building = 'no'], + [feature = 'leisure_garden'][is_building = 'no'], + [feature = 'leisure_golf_course'][is_building = 'no'] { + [zoom >= 10][way_pixels > 3000], + [zoom >= 17] { + text-name: "[name]"; + text-size: @landcover-font-size; + [way_pixels > 12000] { text-size: @landcover-font-size-big; } + [way_pixels > 48000] { text-size: @landcover-font-size-bigger; } + text-fill: darken(@park, 60%); + text-face-name: @landcover-face-name; + text-halo-radius: 1; + text-halo-fill: rgba(255,255,255,0.6); + text-wrap-width: @landcover-wrap-width-size; + [way_pixels > 12000] {text-wrap-width: @landcover-wrap-width-size-big; } + [way_pixels > 48000] {text-wrap-width: @landcover-wrap-width-size-bigger; } + text-placement: interior; + } + } + + [feature = 'boundary_national_park'][is_building = 'no'], + [feature = 'leisure_nature_reserve'][is_building = 'no'] { + [zoom >= 8][way_pixels > 3000], + [zoom >= 17] { + text-name: "[name]"; + text-size: @landcover-font-size; + [way_pixels > 12000] { text-size: @landcover-font-size-big; } + [way_pixels > 48000] { text-size: @landcover-font-size-bigger; } + text-fill: darken(@park, 70%); + text-face-name: @landcover-face-name; + text-halo-radius: 1; + text-halo-fill: rgba(255,255,255,0.6); + text-wrap-width: @landcover-wrap-width-size; + [way_pixels > 12000] {text-wrap-width: @landcover-wrap-width-size-big; } + [way_pixels > 48000] {text-wrap-width: @landcover-wrap-width-size-bigger; } + text-placement: interior; + } + } + + [feature = 'landuse_quarry'][is_building = 'no'] { + [zoom >= 10][way_pixels > 3000], + [zoom >= 17] { + text-name: "[name]"; + text-size: @landcover-font-size; + [way_pixels > 12000] { text-size: @landcover-font-size-big; } + [way_pixels > 48000] { text-size: @landcover-font-size-bigger; } + text-fill: darken(@quarry, 60%); + text-face-name: @landcover-face-name; + text-halo-radius: 1; + text-halo-fill: rgba(255,255,255,0.6); + text-wrap-width: @landcover-wrap-width-size; + [way_pixels > 12000] {text-wrap-width: @landcover-wrap-width-size-big; } + [way_pixels > 48000] {text-wrap-width: @landcover-wrap-width-size-bigger; } + text-placement: interior; + } + } + + [feature = 'landuse_vineyard'][is_building = 'no'], + [feature = 'landuse_orchard'][is_building = 'no'] { + [zoom >= 10][way_pixels > 3000], + [zoom >= 17] { + text-name: "[name]"; + text-size: @landcover-font-size; + [way_pixels > 12000] { text-size: @landcover-font-size-big; } + [way_pixels > 48000] { text-size: @landcover-font-size-bigger; } + text-fill: darken(@vineyard, 50%); + text-face-name: @landcover-face-name; + text-halo-radius: 1.5; /* extra halo needed to overpower the vineyard polygon pattern */ + text-halo-fill: rgba(255,255,255,0.6); + text-wrap-width: @landcover-wrap-width-size; + [way_pixels > 12000] {text-wrap-width: @landcover-wrap-width-size-big; } + [way_pixels > 48000] {text-wrap-width: @landcover-wrap-width-size-bigger; } + text-placement: interior; + } + } + + [feature = 'landuse_cemetery'][is_building = 'no'], + [feature = 'amenity_grave_yard'][is_building = 'no'] { + [zoom >= 10][way_pixels > 3000], + [zoom >= 17] { + text-name: "[name]"; + text-size: @landcover-font-size; + [way_pixels > 12000] { text-size: @landcover-font-size-big; } + [way_pixels > 48000] { text-size: @landcover-font-size-bigger; } + text-fill: darken(@cemetery, 50%); + text-face-name: @landcover-face-name; + text-halo-radius: 1.5; /* extra halo needed to overpower the cemetery polygon pattern */ + text-halo-fill: rgba(255,255,255,0.6); + text-wrap-width: @landcover-wrap-width-size; + [way_pixels > 12000] {text-wrap-width: @landcover-wrap-width-size-big; } + [way_pixels > 48000] {text-wrap-width: @landcover-wrap-width-size-bigger; } + text-placement: interior; + } + } + + [feature = 'landuse_residential'][is_building = 'no'] { + [zoom >= 10][way_pixels > 3000], + [zoom >= 17] { + text-name: "[name]"; + text-size: @landcover-font-size; + [way_pixels > 12000] { text-size: @landcover-font-size-big; } + [way_pixels > 48000] { text-size: @landcover-font-size-bigger; } + text-fill: darken(@residential, 50%); + text-face-name: @landcover-face-name; + text-halo-radius: 1; + text-halo-fill: rgba(255,255,255,0.6); + text-wrap-width: @landcover-wrap-width-size; + [way_pixels > 12000] {text-wrap-width: @landcover-wrap-width-size-big; } + [way_pixels > 48000] {text-wrap-width: @landcover-wrap-width-size-bigger; } + text-placement: interior; + } + } + + [feature = 'landuse_garages'][is_building = 'no'] { + [zoom >= 13][way_pixels > 3000], + [zoom >= 17] { + text-name: "[name]"; + text-size: @landcover-font-size; + [way_pixels > 12000] { text-size: @landcover-font-size-big; } + [way_pixels > 48000] { text-size: @landcover-font-size-bigger; } + text-fill: darken(@garages, 50%); + text-face-name: @landcover-face-name; + text-halo-radius: 1; + text-halo-fill: rgba(255,255,255,0.6); + text-wrap-width: @landcover-wrap-width-size; + [way_pixels > 12000] {text-wrap-width: @landcover-wrap-width-size-big; } + [way_pixels > 48000] {text-wrap-width: @landcover-wrap-width-size-bigger; } + text-placement: interior; + } + } + + [feature = 'landuse_field'][is_building = 'no'] { + [zoom >= 10][way_pixels > 3000], + [zoom >= 17] { + text-name: "[name]"; + text-size: @landcover-font-size; + [way_pixels > 12000] { text-size: @landcover-font-size-big; } + [way_pixels > 48000] { text-size: @landcover-font-size-bigger; } + text-fill: darken(@field, 50%); + text-face-name: @landcover-face-name; + text-halo-radius: 1; + text-halo-fill: rgba(255,255,255,0.6); + text-wrap-width: @landcover-wrap-width-size; + [way_pixels > 12000] {text-wrap-width: @landcover-wrap-width-size-big; } + [way_pixels > 48000] {text-wrap-width: @landcover-wrap-width-size-bigger; } + text-placement: interior; + } + } + + [feature = 'landuse_meadow'][is_building = 'no'], + [feature = 'landuse_grass'][is_building = 'no'] { + [zoom >= 10][way_pixels > 3000], + [zoom >= 17] { + text-name: "[name]"; + text-size: @landcover-font-size; + [way_pixels > 12000] { text-size: @landcover-font-size-big; } + [way_pixels > 48000] { text-size: @landcover-font-size-bigger; } + text-fill: darken(@grass, 50%); + text-face-name: @landcover-face-name; + text-halo-radius: 1; + text-halo-fill: rgba(255,255,255,0.6); + text-wrap-width: @landcover-wrap-width-size; + [way_pixels > 12000] {text-wrap-width: @landcover-wrap-width-size-big; } + [way_pixels > 48000] {text-wrap-width: @landcover-wrap-width-size-bigger; } + text-placement: interior; + } + } + + [feature = 'landuse_allotments'][is_building = 'no'] { + [zoom >= 10][way_pixels > 3000], + [zoom >= 17] { + text-name: "[name]"; + text-size: @landcover-font-size; + [way_pixels > 12000] { text-size: @landcover-font-size-big; } + [way_pixels > 48000] { text-size: @landcover-font-size-bigger; } + text-fill: darken(@allotments, 50%); + text-face-name: @landcover-face-name; + text-halo-radius: 1; + text-halo-fill: rgba(255,255,255,0.6); + text-wrap-width: @landcover-wrap-width-size; + [way_pixels > 12000] {text-wrap-width: @landcover-wrap-width-size-big; } + [way_pixels > 48000] {text-wrap-width: @landcover-wrap-width-size-bigger; } + text-placement: interior; + } + } + + [feature = 'landuse_forest'][is_building = 'no'] { + [zoom >= 8][way_pixels > 3000], + [zoom >= 17] { + text-name: "[name]"; + text-size: @landcover-font-size; + [way_pixels > 12000] { text-size: @landcover-font-size-big; } + [way_pixels > 48000] { text-size: @landcover-font-size-bigger; } + text-fill: darken(@forest, 30%); + text-face-name: @landcover-face-name; + text-halo-radius: 1; + text-halo-fill: rgba(255,255,255,0.6); + text-wrap-width: @landcover-wrap-width-size; + [way_pixels > 12000] {text-wrap-width: @landcover-wrap-width-size-big; } + [way_pixels > 48000] {text-wrap-width: @landcover-wrap-width-size-bigger; } + text-placement: interior; + } + } + + [feature = 'landuse_farmyard'][is_building = 'no'] { + [zoom >= 10][way_pixels > 3000], + [zoom >= 17] { + text-name: "[name]"; + text-size: @landcover-font-size; + [way_pixels > 12000] { text-size: @landcover-font-size-big; } + [way_pixels > 48000] { text-size: @landcover-font-size-bigger; } + text-fill: darken(@farmyard, 50%); + text-face-name: @landcover-face-name; + text-halo-radius: 1; + text-halo-fill: rgba(255,255,255,0.6); + text-wrap-width: @landcover-wrap-width-size; + [way_pixels > 12000] {text-wrap-width: @landcover-wrap-width-size-big; } + [way_pixels > 48000] {text-wrap-width: @landcover-wrap-width-size-bigger; } + text-placement: interior; + } + } + [feature = 'landuse_farm'][is_building = 'no'], + [feature = 'landuse_farmland'][is_building = 'no'] { + [zoom >= 10][way_pixels > 3000], + [zoom >= 17] { + text-name: "[name]"; + text-size: @landcover-font-size; + [way_pixels > 12000] { text-size: @landcover-font-size-big; } + [way_pixels > 48000] { text-size: @landcover-font-size-bigger; } + text-fill: darken(@farmland, 50%); + text-face-name: @landcover-face-name; + text-halo-radius: 1; + text-halo-fill: rgba(255,255,255,0.6); + text-wrap-width: @landcover-wrap-width-size; + [way_pixels > 12000] {text-wrap-width: @landcover-wrap-width-size-big; } + [way_pixels > 48000] {text-wrap-width: @landcover-wrap-width-size-bigger; } + text-placement: interior; + } + } + + [feature = 'shop_mall'], + [feature = 'landuse_retail'][is_building = 'no'] { + [zoom >= 10][way_pixels > 3000], + [zoom >= 17] { + text-name: "[name]"; + text-size: @landcover-font-size; + [way_pixels > 12000] { text-size: @landcover-font-size-big; } + [way_pixels > 48000] { text-size: @landcover-font-size-bigger; } + text-fill: darken(@retail, 50%); + text-face-name: @landcover-face-name; + text-halo-radius: 1; + text-halo-fill: rgba(255,255,255,0.6); + text-wrap-width: @landcover-wrap-width-size; + [way_pixels > 12000] {text-wrap-width: @landcover-wrap-width-size-big; } + [way_pixels > 48000] {text-wrap-width: @landcover-wrap-width-size-bigger; } + text-placement: interior; + } + } + + [feature = 'landuse_industrial'][is_building = 'no'], + [feature = 'landuse_railway'][is_building = 'no'] { + [zoom >= 10][way_pixels > 3000], + [zoom >= 17] { + text-name: "[name]"; + text-size: @landcover-font-size; + [way_pixels > 12000] { text-size: @landcover-font-size-big; } + [way_pixels > 48000] { text-size: @landcover-font-size-bigger; } + text-fill: darken(@industrial, 60%); + text-face-name: @landcover-face-name; + text-halo-radius: 1; + text-halo-fill: rgba(255,255,255,0.6); + text-wrap-width: @landcover-wrap-width-size; + [way_pixels > 12000] {text-wrap-width: @landcover-wrap-width-size-big; } + [way_pixels > 48000] {text-wrap-width: @landcover-wrap-width-size-bigger; } + text-placement: interior; + } + } + + [feature = 'landuse_commercial'][is_building = 'no'] { + [zoom >= 10][way_pixels > 3000], + [zoom >= 17] { + text-name: "[name]"; + text-size: @landcover-font-size; + [way_pixels > 12000] { text-size: @landcover-font-size-big; } + [way_pixels > 48000] { text-size: @landcover-font-size-bigger; } + text-fill: darken(@commercial, 60%); + text-face-name: @landcover-face-name; + text-halo-radius: 1; + text-halo-fill: rgba(255,255,255,0.6); + text-wrap-width: @landcover-wrap-width-size; + [way_pixels > 12000] {text-wrap-width: @landcover-wrap-width-size-big; } + [way_pixels > 48000] {text-wrap-width: @landcover-wrap-width-size-bigger; } + text-placement: interior; + } + } + + [feature = 'landuse_brownfield'][is_building = 'no'], + [feature = 'landuse_landfill'][is_building = 'no'], + [feature = 'landuse_construction'][is_building = 'no'] { + [zoom >= 10][way_pixels > 3000], + [zoom >= 17] { + text-name: "[name]"; + text-size: @landcover-font-size; + [way_pixels > 12000] { text-size: @landcover-font-size-big; } + [way_pixels > 48000] { text-size: @landcover-font-size-bigger; } + text-fill: darken(@construction, 50%); + text-face-name: @landcover-face-name; + text-halo-radius: 1; + text-halo-fill: rgba(255,255,255,0.6); + text-wrap-width: @landcover-wrap-width-size; + [way_pixels > 12000] {text-wrap-width: @landcover-wrap-width-size-big; } + [way_pixels > 48000] {text-wrap-width: @landcover-wrap-width-size-bigger; } + text-placement: interior; + } + } + + [feature = 'natural_bay'][zoom >= 14] { + text-name: "[name]"; + text-size: 10; + text-fill: #6699cc; + text-face-name: @book-fonts; + text-halo-radius: 1; + text-wrap-width: @standard-wrap-width; + text-placement: interior; + } + + [feature = 'natural_spring'][zoom >= 16] { + text-name: "[name]"; + text-size: 10; + text-fill: #6699cc; + text-face-name: @book-fonts; + text-halo-radius: 1; + text-wrap-width: @standard-wrap-width; + text-placement: interior; + text-dy: 6; + } + + [feature = 'tourism_alpine_hut'][zoom >= 15] { + text-name: "[name]"; + text-size: 9; + text-fill: #6699cc; + text-dy: 11; + text-face-name: @book-fonts; + text-halo-radius: 1; + text-wrap-width: @standard-wrap-width; + text-placement: interior; + [zoom >= 16] { + ele/text-name: "[ele]"; + ele/text-size: 8; + ele/text-fill: #6699cc; + ele/text-dy: 23; + ele/text-face-name: @oblique-fonts; + ele/text-halo-radius: 1; + ele/text-placement: interior; + } + } + + [feature = 'amenity_shelter'][zoom >= 17] { + text-name: "[name]"; + text-size: 9; + text-fill: #6699cc; + text-dy: 11; + text-face-name: @book-fonts; + text-halo-radius: 1; + text-wrap-width: @standard-wrap-width; + text-placement: interior; + ele/text-name: "[ele]"; + ele/text-size: 8; + ele/text-fill: #6699cc; + ele/text-dy: 23; + ele/text-face-name: @oblique-fonts; + ele/text-halo-radius: 1; + ele/text-placement: interior; + } + + [feature = 'amenity_bank'][zoom >= 17] { + text-name: "[name]"; + text-size: 9; + text-fill: black; + text-dy: 12; + text-halo-radius: 1; + text-wrap-width: @standard-wrap-width; + text-placement: interior; + text-face-name: @book-fonts; + } + + [feature = 'tourism_hotel'], + [feature = 'tourism_motel'], + [feature = 'tourism_hostel'], + [feature = 'tourism_chalet'] { + [zoom >= 17] { + text-name: "[name]"; + text-size: 10; + text-fill: #0066ff; + text-dy: 13; + text-face-name: @book-fonts; + text-halo-radius: 1; + text-wrap-width: @standard-wrap-width; + text-placement: interior; + [feature = 'tourism_chalet'] { + text-dy: 11; + } + } + } + + [feature = 'amenity_embassy'][zoom >= 17] { + text-name: "[name]"; + text-size: 9; + text-fill: #0066ff; + text-dy: 9; + text-face-name: @book-fonts; + text-halo-radius: 1; + text-wrap-width: @standard-wrap-width; + text-placement: interior; + } + + [feature = 'tourism_guest_house'][zoom >= 17] { + text-name: "[name]"; + text-size: 8; + text-fill: #0066ff; + text-dy: 10; + text-face-name: @book-fonts; + text-halo-radius: 1; + text-wrap-width: @standard-wrap-width; + text-placement: interior; + } + + [feature = 'highway_bus_stop'], + [feature = 'amenity_fuel'], + [feature = 'amenity_bus_station'] { + [zoom >= 17] { + text-name: "[name]"; + text-size: 9; + text-fill: @transportation-text; + text-dy: 11; + text-face-name: @book-fonts; + text-halo-radius: 1; + text-wrap-width: @standard-wrap-width; + text-placement: interior; + [feature = 'highway_bus_stop'] { + text-dy: 9; + } + } + } + + [feature = 'tourism_camp_site'][zoom >= 17] { + text-name: "[name]"; + text-size: 10; + text-fill: #0066ff; + text-dy: 15; + text-face-name: @book-fonts; + text-halo-radius: 1; + text-wrap-width: @standard-wrap-width; + text-placement: interior; + } + + [feature = 'tourism_caravan_site'][is_building = 'no'] { + [zoom >= 10][way_pixels > 3000], + [zoom >= 17] { + text-name: "[name]"; + text-size: @landcover-font-size; + [way_pixels > 12000] { text-size: @landcover-font-size-big; } + [way_pixels > 48000] { text-size: @landcover-font-size-bigger; } + text-fill: darken(@campsite, 50%); + text-dy: 15; + text-face-name: @landcover-face-name; + text-halo-radius: 1; + text-halo-fill: rgba(255,255,255,0.6); + text-wrap-width: @landcover-wrap-width-size; + [way_pixels > 12000] {text-wrap-width: @landcover-wrap-width-size-big; } + [way_pixels > 48000] {text-wrap-width: @landcover-wrap-width-size-bigger; } + text-placement: interior; + } + } + + [feature = 'waterway_lock'][zoom >= 15] { + text-name: "[name]"; + text-size: 9; + text-dy: 10; + text-fill: #0066ff; + text-face-name: @book-fonts; + text-halo-radius: 1; + text-wrap-width: @standard-wrap-width; + text-placement: interior; + } + + [feature = 'leisure_marina'][zoom >= 15] { + text-name: "[name]"; + text-size: 8; + text-fill: @marina-text; + text-face-name: @book-fonts; + text-halo-radius: 1; + text-wrap-width: @standard-wrap-width; + text-placement: interior; + [zoom >= 17] { + text-size: 10; + } + } + + [feature = 'tourism_theme_park'][is_building = 'no'] { + [zoom >= 13][way_pixels > 3000], + [zoom >= 17] { + text-name: "[name]"; + text-size: @landcover-font-size; + [way_pixels > 12000] { text-size: @landcover-font-size-big; } + [way_pixels > 48000] { text-size: @landcover-font-size-bigger; } + text-fill: @theme_park; + text-face-name: @bold-fonts; /*rendered bold to improve visibility since theme parks tend to have crowded backgrounds*/ + text-halo-radius: 1; + text-halo-fill: rgba(255,255,255,0.6); + text-wrap-width: @landcover-wrap-width-size; + [way_pixels > 12000] {text-wrap-width: @landcover-wrap-width-size-big; } + [way_pixels > 48000] {text-wrap-width: @landcover-wrap-width-size-bigger; } + text-placement: interior; + } + } + + [feature = 'tourism_museum'][zoom >= 17] { + text-name: "[name]"; + text-size: 10; + text-dy: 11; + text-fill: #734a08; + text-face-name: @book-fonts; + text-halo-radius: 1; + text-wrap-width: @standard-wrap-width; + text-placement: interior; + } + + [feature = 'amenity_prison'][zoom >= 17] { + text-name: "[name]"; + text-size: 10; + text-fill: #734a08; + text-dy: 16; + text-face-name: @book-fonts; + text-halo-radius: 1; + text-wrap-width: @standard-wrap-width; + text-placement: interior; + } + + [feature = 'tourism_attraction'][is_building = 'no'] { + [zoom >= 10][way_pixels > 3000], + [zoom >= 17] { + text-name: "[name]"; + text-size: @landcover-font-size; + [way_pixels > 12000] { text-size: @landcover-font-size-big; } + [way_pixels > 48000] { text-size: @landcover-font-size-bigger; } + text-fill: #660033; + text-face-name: @book-fonts; + text-halo-radius: 2; + text-wrap-width: @landcover-wrap-width-size; + [way_pixels > 12000] {text-wrap-width: @landcover-wrap-width-size-big; } + [way_pixels > 48000] {text-wrap-width: @landcover-wrap-width-size-bigger; } + text-placement: interior; + } + } + + [feature = 'amenity_university'][is_building = 'no'] { + [zoom >= 10][way_pixels > 3000], + [zoom >= 17] { + text-name: "[name]"; + text-size: @landcover-font-size; + [way_pixels > 12000] { text-size: @landcover-font-size-big; } + [way_pixels > 48000] { text-size: @landcover-font-size-bigger; } + text-fill: darken(@school, 70%); + text-face-name: @landcover-face-name; + text-halo-radius: 1; + text-halo-fill: rgba(255,255,255,0.6); + text-wrap-width: @landcover-wrap-width-size; + [way_pixels > 12000] {text-wrap-width: @landcover-wrap-width-size-big; } + [way_pixels > 48000] {text-wrap-width: @landcover-wrap-width-size-bigger; } + text-placement: interior; + } + } + + [feature = 'amenity_school'][is_building = 'no'], + [feature = 'amenity_college'][is_building = 'no'] { + [zoom >= 10][way_pixels > 3000], + [zoom >= 17] { + text-name: "[name]"; + text-size: @landcover-font-size; + [way_pixels > 12000] { text-size: @landcover-font-size-big; } + [way_pixels > 48000] { text-size: @landcover-font-size-bigger; } + text-fill: darken(@school, 70%); + text-face-name: @landcover-face-name; + text-halo-radius: 1; + text-halo-fill: rgba(255,255,255,0.6); + text-wrap-width: @landcover-wrap-width-size; + [way_pixels > 12000] {text-wrap-width: @landcover-wrap-width-size-big; } + [way_pixels > 48000] {text-wrap-width: @landcover-wrap-width-size-bigger; } + text-placement: interior; + } + } + + [feature = 'amenity_kindergarten'][is_building = 'no'] { + [zoom >= 10][way_pixels > 3000], + [zoom >= 17] { + text-name: "[name]"; + text-size: @landcover-font-size; + [way_pixels > 12000] { text-size: @landcover-font-size-big; } + [way_pixels > 48000] { text-size: @landcover-font-size-bigger; } + text-fill: darken(@school, 65%); + text-face-name: @landcover-face-name; + text-halo-radius: 1; + text-halo-fill: rgba(255,255,255,0.6); + text-wrap-width: @landcover-wrap-width-size; + [way_pixels > 12000] {text-wrap-width: @landcover-wrap-width-size-big; } + [way_pixels > 48000] {text-wrap-width: @landcover-wrap-width-size-bigger; } + text-placement: interior; + } + } + + [feature = 'man_made_lighthouse'][zoom >= 15] { + text-name: "[name]"; + text-size: 9; + text-fill: #000033; + text-dy: 16; + text-face-name: @book-fonts; + text-halo-radius: 2; + text-wrap-width: @standard-wrap-width; + text-placement: interior; + } + + [feature = 'man_made_windmill'][zoom >= 17] { + text-name: "[name]"; + text-size: 9; + text-fill: #734a08; + text-dy: 12; + text-face-name: @book-fonts; + text-halo-radius: 1; + text-wrap-width: @standard-wrap-width; + text-placement: interior; + } + + [feature = 'amenity_hospital'][zoom >= 16] { + text-name: "[name]"; + text-fill: #da0092; + text-size: 8; + text-dy: 10; + text-face-name: @book-fonts; + text-halo-radius: 2; + text-wrap-width: @standard-wrap-width; + text-placement: interior; + } + + [feature = 'amenity_pharmacy'][zoom >= 17] { + text-name: "[name]"; + text-size: 8; + text-dy: 10; + text-fill: #da0092; + text-face-name: @book-fonts; + text-halo-radius: 1; + text-wrap-width: @standard-wrap-width; + text-placement: interior; + } + + [feature = 'shop_bakery'], + [feature = 'shop_clothes'], + [feature = 'shop_fashion'], + [feature = 'shop_convenience'], + [feature = 'shop_doityourself'], + [feature = 'shop_hairdresser'], + [feature = 'shop_butcher'], + [feature = 'shop_car'], + [feature = 'shop_car_repair'], + [feature = 'shop_bicycle'], + [feature = 'shop_florist'], + [feature = 'shop_other']{ + [zoom >= 17] { + text-name: "[name]"; + text-size: 10; + text-dy: 12; + text-fill: #939; + text-face-name: @book-fonts; + text-halo-radius: 1.5; + text-halo-fill: rgba(255, 255, 255, 0.8); + text-wrap-width: @standard-wrap-width; + text-placement: interior; + } + } + + [feature = 'shop_supermarket'], + [feature = 'shop_department_store'] { + [zoom >= 16] { + text-name: "[name]"; + text-size: 10; + text-dy: 12; + text-fill: #939; + text-face-name: @book-fonts; + text-halo-radius: 1.5; + text-halo-fill: rgba(255, 255, 255, 0.8); + text-wrap-width: @standard-wrap-width; + text-placement: interior; + } + } + + [feature = 'military_danger_area'][is_building = 'no'] { + [zoom >= 9][way_pixels > 3000], + [zoom >= 17] { + text-name: "[name]"; + text-size: @landcover-font-size; + [way_pixels > 12000] { text-size: @landcover-font-size-big; } + [way_pixels > 48000] { text-size: @landcover-font-size-bigger; } + text-fill: darken(@danger_area, 40%); + text-face-name: @bold-fonts; + text-halo-radius: 1; + text-halo-fill: rgba(255,255,255,0.6); + text-wrap-width: @landcover-wrap-width-size; + [way_pixels > 12000] {text-wrap-width: @landcover-wrap-width-size-big; } + [way_pixels > 48000] {text-wrap-width: @landcover-wrap-width-size-bigger; } + text-placement: interior; + } + } + + [feature = 'landuse_military'][is_building = 'no'] { + [zoom >= 10][way_pixels > 3000], + [zoom >= 17] { + text-name: "[name]"; + text-size: @landcover-font-size; + [way_pixels > 12000] { text-size: @landcover-font-size-big; } + [way_pixels > 48000] { text-size: @landcover-font-size-bigger; } + text-fill: darken(@military, 40%); + text-face-name: @landcover-face-name; + text-halo-radius: 1; + text-halo-fill: rgba(255,255,255,0.6); + text-wrap-width: @landcover-wrap-width-size; + [way_pixels > 12000] {text-wrap-width: @landcover-wrap-width-size-big; } + [way_pixels > 48000] {text-wrap-width: @landcover-wrap-width-size-bigger; } + text-placement: interior; + } + } + + [feature = 'aeroway_gate'][zoom >= 17] { + text-name: "[ref]"; + text-size: 10; + text-fill: #aa66cc; + text-face-name: @book-fonts; + text-halo-radius: 1; + text-wrap-width: @standard-wrap-width; + text-placement: interior; + } + + [feature = 'military_barracks'][is_building = 'no'] { + [zoom >= 10][way_pixels > 3000], + [zoom >= 17] { + text-name: "[name]"; + text-size: @landcover-font-size; + [way_pixels > 12000] { text-size: @landcover-font-size-big; } + [way_pixels > 48000] { text-size: @landcover-font-size-bigger; } + text-fill: darken(@barracks, 40%); + text-face-name: @landcover-face-name; + text-halo-radius: 1; + text-halo-fill: rgba(255,255,255,0.6); + text-wrap-width: @landcover-wrap-width-size; + [way_pixels > 12000] {text-wrap-width: @landcover-wrap-width-size-big; } + [way_pixels > 48000] {text-wrap-width: @landcover-wrap-width-size-bigger; } + text-placement: interior; + } + } + + [feature = 'tourism_zoo'][is_building = 'no'] { + [zoom >= 10][way_pixels > 3000], + [zoom >= 17] { + text-name: "[name]"; + text-size: @landcover-font-size; + [way_pixels > 12000] { text-size: @landcover-font-size-big; } + [way_pixels > 48000] { text-size: @landcover-font-size-bigger; } + text-fill: darken(@zoo, 40%); + text-face-name: @landcover-face-name; + text-halo-radius: 1; + text-halo-fill: rgba(255,255,255,0.6); + text-wrap-width: @landcover-wrap-width-size; + [way_pixels > 12000] {text-wrap-width: @landcover-wrap-width-size-big; } + [way_pixels > 48000] {text-wrap-width: @landcover-wrap-width-size-bigger; } + text-placement: interior; + } + } + + [feature = 'power_station'][is_building = 'no'][zoom >= 10], + [feature = 'power_generator'][is_building = 'no'][zoom >= 10], + [feature = 'power_sub_station'][is_building = 'no'][zoom >= 13], + [feature = 'power_substation'][is_building = 'no'][zoom >= 13]{ + [way_pixels > 3000], + [zoom >= 17] { + text-name: "[name]"; + text-size: @landcover-font-size; + [way_pixels > 12000] { text-size: @landcover-font-size-big; } + [way_pixels > 48000] { text-size: @landcover-font-size-bigger; } + text-fill: darken(@power, 40%); + text-face-name: @landcover-face-name; + text-halo-radius: 1; + text-halo-fill: rgba(255,255,255,0.6); + text-wrap-width: @landcover-wrap-width-size; + [way_pixels > 12000] {text-wrap-width: @landcover-wrap-width-size-big; } + [way_pixels > 48000] {text-wrap-width: @landcover-wrap-width-size-bigger; } + text-placement: interior; + } + } + + [feature = 'natural_desert'][is_building = 'no'] { + [zoom >= 10][way_pixels > 3000], + [zoom >= 17] { + text-name: "[name]"; + text-size: @landcover-font-size; + [way_pixels > 12000] { text-size: @landcover-font-size-big; } + [way_pixels > 48000] { text-size: @landcover-font-size-bigger; } + text-fill: darken(@desert, 40%); + text-face-name: @landcover-face-name; + text-halo-radius: 1; + text-halo-fill: rgba(255,255,255,0.6); + text-wrap-width: @landcover-wrap-width-size; + [way_pixels > 12000] {text-wrap-width: @landcover-wrap-width-size-big; } + [way_pixels > 48000] {text-wrap-width: @landcover-wrap-width-size-bigger; } + text-placement: interior; + } + } + + [feature = 'natural_sand'][is_building = 'no'] { + [zoom >= 10][way_pixels > 3000], + [zoom >= 17] { + text-name: "[name]"; + text-size: @landcover-font-size; + [way_pixels > 12000] { text-size: @landcover-font-size-big; } + [way_pixels > 48000] { text-size: @landcover-font-size-bigger; } + text-fill: darken(@sand, 50%); + text-face-name: @landcover-face-name; + text-halo-radius: 1; + text-halo-fill: rgba(255,255,255,0.6); + text-wrap-width: @landcover-wrap-width-size; + [way_pixels > 12000] {text-wrap-width: @landcover-wrap-width-size-big; } + [way_pixels > 48000] {text-wrap-width: @landcover-wrap-width-size-bigger; } + text-placement: interior; + } + } + + [feature = 'natural_heath'][is_building = 'no'] { + [zoom >= 10][way_pixels > 3000], + [zoom >= 17] { + text-name: "[name]"; + text-size: @landcover-font-size; + [way_pixels > 12000] { text-size: @landcover-font-size-big; } + [way_pixels > 48000] { text-size: @landcover-font-size-bigger; } + text-fill: darken(@heath, 40%); + text-face-name: @landcover-face-name; + text-halo-radius: 1; + text-halo-fill: rgba(255,255,255,0.6); + text-wrap-width: @landcover-wrap-width-size; + [way_pixels > 12000] {text-wrap-width: @landcover-wrap-width-size-big; } + [way_pixels > 48000] {text-wrap-width: @landcover-wrap-width-size-bigger; } + text-placement: interior; + } + } + + + [feature = 'natural_grassland'][is_building = 'no'] { + [zoom >= 10][way_pixels > 3000], + [zoom >= 17] { + text-name: "[name]"; + text-size: @landcover-font-size; + [way_pixels > 12000] { text-size: @landcover-font-size-big; } + [way_pixels > 48000] { text-size: @landcover-font-size-bigger; } + text-fill: darken(@grassland, 60%); + text-face-name: @landcover-face-name; + text-halo-radius: 1; + text-halo-fill: rgba(255,255,255,0.6); + text-wrap-width: @landcover-wrap-width-size; + [way_pixels > 12000] {text-wrap-width: @landcover-wrap-width-size-big; } + [way_pixels > 48000] {text-wrap-width: @landcover-wrap-width-size-bigger; } + text-placement: interior; + } + } + + [feature = 'natural_scrub'][is_building = 'no'] { + [zoom >= 10][way_pixels > 3000], + [zoom >= 17] { + text-name: "[name]"; + text-size: @landcover-font-size; + [way_pixels > 12000] { text-size: @landcover-font-size-big; } + [way_pixels > 48000] { text-size: @landcover-font-size-bigger; } + text-fill: darken(@scrub, 60%); + text-face-name: @landcover-face-name; + text-halo-radius: 1; + text-halo-fill: rgba(255,255,255,0.6); + text-wrap-width: @landcover-wrap-width-size; + [way_pixels > 12000] {text-wrap-width: @landcover-wrap-width-size-big; } + [way_pixels > 48000] {text-wrap-width: @landcover-wrap-width-size-bigger; } + text-placement: interior; + } + } + + [feature = 'aeroway_apron'][is_building = 'no'] { + [zoom >= 10][way_pixels > 3000], + [zoom >= 17] { + text-name: "[name]"; + text-size: @landcover-font-size; + [way_pixels > 12000] { text-size: @landcover-font-size-big; } + [way_pixels > 48000] { text-size: @landcover-font-size-bigger; } + text-fill: darken(@apron, 60%); + text-face-name: @landcover-face-name; + text-halo-radius: 1; + text-halo-fill: rgba(255,255,255,0.6); + text-wrap-width: @landcover-wrap-width-size; + [way_pixels > 12000] {text-wrap-width: @landcover-wrap-width-size-big; } + [way_pixels > 48000] {text-wrap-width: @landcover-wrap-width-size-bigger; } + text-placement: interior; + } + } + + [feature = 'natural_beach'][is_building = 'no'] { + [zoom >= 10][way_pixels > 3000], + [zoom >= 17] { + text-name: "[name]"; + text-size: @landcover-font-size; + [way_pixels > 12000] { text-size: @landcover-font-size-big; } + [way_pixels > 48000] { text-size: @landcover-font-size-bigger; } + text-fill: darken(@beach, 60%); + text-face-name: @landcover-face-name; + text-halo-radius: 1; + text-halo-fill: rgba(255,255,255,0.6); + text-wrap-width: @landcover-wrap-width-size; + [way_pixels > 12000] {text-wrap-width: @landcover-wrap-width-size-big; } + [way_pixels > 48000] {text-wrap-width: @landcover-wrap-width-size-bigger; } + text-placement: interior; + } + } + + [feature = 'highway_services'][is_building = 'no'], + [feature = 'highway_rest_area'][is_building = 'no'] { + [zoom >= 10][way_pixels > 3000], + [zoom >= 17] { + text-name: "[name]"; + text-size: @landcover-font-size; + [way_pixels > 12000] { text-size: @landcover-font-size-big; } + [way_pixels > 48000] { text-size: @landcover-font-size-bigger; } + text-fill: darken(@rest_area, 40%); + text-face-name: @landcover-face-name; + text-halo-radius: 1; + text-halo-fill: rgba(255,255,255,0.6); + text-wrap-width: @landcover-wrap-width-size; + [way_pixels > 12000] {text-wrap-width: @landcover-wrap-width-size-big; } + [way_pixels > 48000] {text-wrap-width: @landcover-wrap-width-size-bigger; } + } + } + + [feature = 'natural_glacier'][is_building = 'no'] { + [zoom >= 10][way_pixels > 3000], + [zoom >= 17] { + text-name: "[name]"; + text-size: @landcover-font-size; + [way_pixels > 12000] { text-size: @landcover-font-size-big; } + [way_pixels > 48000] { text-size: @landcover-font-size-bigger; } + text-fill: darken(@glacier, 40%); + text-face-name: @landcover-face-name; + text-halo-radius: 1; + text-halo-fill: rgba(255,255,255,0.6); + text-wrap-width: @landcover-wrap-width-size; + [way_pixels > 12000] {text-wrap-width: @landcover-wrap-width-size-big; } + [way_pixels > 48000] {text-wrap-width: @landcover-wrap-width-size-bigger; } + } + } + + [feature = 'aeroway_helipad'][zoom >= 16]::aeroway { + text-name: "[name]"; + text-size: 8; + text-fill: @airtransport; + text-dy: -10; + text-face-name: @bold-fonts; + text-halo-radius: 1; + text-placement: interior; + text-wrap-width: 30; + } + + [feature = 'aeroway_aerodrome'][zoom >= 10][zoom < 14]::aeroway { + text-name: "[name]"; + text-size: 8; + text-fill: darken(@airtransport, 15%); + text-dy: -10; + text-face-name: @oblique-fonts; + text-halo-radius: 1; + text-placement: interior; + text-wrap-width: 30; + } +} diff --git a/samples/CoffeeScript/empty.coffee b/samples/CoffeeScript/empty.coffee deleted file mode 100644 index e69de29b..00000000 diff --git a/samples/CoffeeScript/example.cjsx b/samples/CoffeeScript/example.cjsx new file mode 100644 index 00000000..def9cf2f --- /dev/null +++ b/samples/CoffeeScript/example.cjsx @@ -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: -> +
+
+ {@state.title} +
+ +
diff --git a/samples/Cool/list.cl b/samples/Cool/list.cl new file mode 100644 index 00000000..3d44813e --- /dev/null +++ b/samples/Cool/list.cl @@ -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; + } + }; +}; diff --git a/samples/Cool/sample.cl b/samples/Cool/sample.cl new file mode 100644 index 00000000..e8884990 --- /dev/null +++ b/samples/Cool/sample.cl @@ -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") + }; +}; diff --git a/samples/Shell/filenames/Dockerfile b/samples/Dockerfile/filenames/Dockerfile similarity index 100% rename from samples/Shell/filenames/Dockerfile rename to samples/Dockerfile/filenames/Dockerfile diff --git a/samples/F#/Combinators.fs b/samples/F#/Combinators.fs new file mode 100644 index 00000000..409c524d --- /dev/null +++ b/samples/F#/Combinators.fs @@ -0,0 +1,49 @@ +namespace Nessos.FsPickler.Combinators + + open Nessos.FsPickler + open Nessos.FsPickler.Json + + /// Json pickling methods + [] + module Json = + + let private jsonSerializer = lazy(FsPickler.CreateJson(omitHeader = true)) + + /// + /// Pickles a value to Json. + /// + /// utilized pickler. + /// input value. + let pickle (pickler : Pickler<'T>) (value : 'T) : string = + jsonSerializer.Value.PickleToString (pickler, value) + + /// + /// Unpickles a value from Json. + /// + /// utilized pickler. + /// input pickle. + let unpickle (pickler : Pickler<'T>) (pickle : string) : 'T = + jsonSerializer.Value.UnPickleOfString (pickler, pickle) + + + /// Bson pickling methods + [] + module Bson = + + let private bsonPickler = lazy(FsPickler.CreateBson()) + + /// + /// Pickles a value to Bson. + /// + /// utilized pickler. + /// input value. + let pickle (pickler : Pickler<'T>) (value : 'T) : byte [] = + bsonPickler.Value.Pickle (pickler, value) + + /// + /// Unpickles a value from bson. + /// + /// utilized pickler. + /// input pickle. + let unpickle (pickler : Pickler<'T>) (pickle : byte []) : 'T = + bsonPickler.Value.UnPickle (pickler, pickle) \ No newline at end of file diff --git a/samples/F#/JsonFormat.fs b/samples/F#/JsonFormat.fs new file mode 100644 index 00000000..cf6aac61 --- /dev/null +++ b/samples/F#/JsonFormat.fs @@ -0,0 +1,65 @@ +namespace Nessos.FsPickler.Json + + open System + open System.IO + open System.Text + + open Newtonsoft.Json + + open Nessos.FsPickler + + /// + /// Factory methods for the Json serialization format. + /// + 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) :> _ \ No newline at end of file diff --git a/samples/F#/JsonReader.fs b/samples/F#/JsonReader.fs new file mode 100644 index 00000000..fdd90d3c --- /dev/null +++ b/samples/F#/JsonReader.fs @@ -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 + + /// + /// Json format deserializer + /// + 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 () + 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 false "FsPickler" + if version <> jsonFormatVersion then + let v = Version(version) + raise <| new FormatException(sprintf "Invalid FsPickler format version %O." version) + + let sTag = jsonReader.ReadPrimitiveAs 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 () = "_flags" then + jsonReader.MoveNext() + let csvFlags = jsonReader.ValueAs() + 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 false "id" + + member __.ReadBoolean tag = jsonReader.ReadPrimitiveAs (omitTag ()) tag + member __.ReadByte tag = jsonReader.ReadPrimitiveAs (omitTag ()) tag |> byte + member __.ReadSByte tag = jsonReader.ReadPrimitiveAs (omitTag ()) tag |> sbyte + + member __.ReadInt16 tag = jsonReader.ReadPrimitiveAs (omitTag ()) tag |> int16 + member __.ReadInt32 tag = jsonReader.ReadPrimitiveAs (omitTag ()) tag |> int + member __.ReadInt64 tag = jsonReader.ReadPrimitiveAs (omitTag ()) tag + + member __.ReadUInt16 tag = jsonReader.ReadPrimitiveAs (omitTag ()) tag |> uint16 + member __.ReadUInt32 tag = jsonReader.ReadPrimitiveAs (omitTag ()) tag |> uint32 + member __.ReadUInt64 tag = jsonReader.ReadPrimitiveAs (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 () |> single + | JsonToken.String -> Single.Parse(jsonReader.ValueAs(), 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 () + | JsonToken.String -> Double.Parse(jsonReader.ValueAs(), CultureInfo.InvariantCulture) + | _ -> raise <| new FormatException("not a float.") + + jsonReader.Read() |> ignore + value + + member __.ReadChar tag = let value = jsonReader.ReadPrimitiveAs (omitTag ()) tag in value.[0] + member __.ReadString tag = jsonReader.ReadPrimitiveAs (omitTag ()) tag + member __.ReadBigInteger tag = jsonReader.ReadPrimitiveAs (omitTag ()) tag |> BigInteger.Parse + + member __.ReadGuid tag = + if isBsonReader then + jsonReader.ReadPrimitiveAs (omitTag ()) tag + else + jsonReader.ReadPrimitiveAs (omitTag ()) tag |> Guid.Parse + + member __.ReadTimeSpan tag = jsonReader.ReadPrimitiveAs (omitTag ()) tag |> TimeSpan.Parse + member __.ReadDecimal tag = jsonReader.ReadPrimitiveAs (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 (omitTag ()) tag + DateTime(ticks) + else + jsonReader.ReadPrimitiveAs (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 () + else + let base64 = jsonReader.ValueAs () + Convert.FromBase64String base64 + + jsonReader.Read() |> ignore + + bytes + + member __.IsPrimitiveArraySerializationSupported = false + member __.ReadPrimitiveArray _ _ = raise <| new NotImplementedException() + + member __.Dispose () = (jsonReader :> IDisposable).Dispose() \ No newline at end of file diff --git a/samples/F#/JsonSerializer.fs b/samples/F#/JsonSerializer.fs new file mode 100644 index 00000000..15f4929a --- /dev/null +++ b/samples/F#/JsonSerializer.fs @@ -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 + + /// + /// Json pickler instance. + /// + type JsonSerializer = + inherit FsPicklerTextSerializer + + val private format : JsonPickleFormatProvider + + /// + /// Initializes a new Json pickler instance. + /// + /// indent out Json pickles. + /// omit FsPickler header in Json pickles. + /// specify a custom type name converter. + new ([] ?indent, [] ?omitHeader, [] ?typeConverter) = + let indent = defaultArg indent false + let omitHeader = defaultArg omitHeader false + let json = new JsonPickleFormatProvider(indent, omitHeader) + { + inherit FsPicklerTextSerializer(json, ?typeConverter = typeConverter) + format = json + } + + /// + /// Gets or sets whether Json output should be indented. + /// + member x.Indent + with get () = x.format.Indent + and set b = x.format.Indent <- b + + /// + /// Gets or sets whether FsPickler headers should be ignored in pickle format. + /// + member x.OmitHeader + with get () = x.format.OmitHeader + and set b = x.format.OmitHeader <- b + + /// + /// Gets or sets a non-null whitespace string that serves as a custom, top-level sequence separator. + /// + member x.SequenceSeparator + with get () = x.format.SequenceSeparator + and set sep = x.format.SequenceSeparator <- sep + + /// + /// Gets or sets whether top-level sequences should be serialized using the custom separator. + /// + member x.UseCustomTopLevelSequenceSeparator + with get () = x.format.UseCustomTopLevelSequenceSeparator + and set e = x.format.UseCustomTopLevelSequenceSeparator <- e + + /// + /// BSON pickler instance. + /// + type BsonSerializer([] ?typeConverter) = + inherit FsPicklerSerializer(new BsonPickleFormatProvider(), ?typeConverter = typeConverter) + + + /// FsPickler static methods. + type FsPickler = + + /// + /// Initializes a new Json pickler instance. + /// + /// indent out Json pickles. + /// omit FsPickler header in Json pickles. + /// specify a custom type name converter. + static member CreateJson([] ?indent, [] ?omitHeader, [] ?typeConverter) = + new JsonSerializer(?indent = indent, ?omitHeader = omitHeader, ?typeConverter = typeConverter) + + /// + /// Initializes a new Bson pickler instance. + /// + /// specify a custom type name converter. + static member CreateBson([] ?typeConverter) = + new BsonSerializer(?typeConverter = typeConverter) \ No newline at end of file diff --git a/samples/F#/JsonWriter.fs b/samples/F#/JsonWriter.fs new file mode 100644 index 00000000..bbb6ff24 --- /dev/null +++ b/samples/F#/JsonWriter.fs @@ -0,0 +1,142 @@ +namespace Nessos.FsPickler.Json + + open System + open System.IO + open System.Collections.Generic + + open Newtonsoft.Json + + open Nessos.FsPickler + + /// + /// Json format serializer. + /// + 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 () + 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() \ No newline at end of file diff --git a/samples/F#/PerformanceTesters.fs b/samples/F#/PerformanceTesters.fs new file mode 100644 index 00000000..c5eb20d2 --- /dev/null +++ b/samples/F#/PerformanceTesters.fs @@ -0,0 +1,68 @@ +namespace Nessos.FsPickler.Tests + + open PerfUtil + open PerfUtil.NUnit + + open NUnit.Framework + + open Nessos.FsPickler + open Nessos.FsPickler.Json + + [] + type PerfTester () = + inherit NUnitPerf () + + let tests = PerfTest.OfModuleMarker () + + 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.Assembly.GetName().Version + let comparer = new WeightedComparer(spaceFactor = 0.2, leastAcceptableImprovementFactor = 0.8) + let tester = + new PastImplementationComparer( + fsp, version, historyFile = persistenceFile, throwOnError = true, warmup = true, comparer = comparer) + + override __.PerfTester = tester :> _ + + [] + member __.Persist() = + if persistResults then tester.PersistCurrentResults () \ No newline at end of file diff --git a/samples/F#/PerformanceTests.fs b/samples/F#/PerformanceTests.fs new file mode 100644 index 00000000..c3d01356 --- /dev/null +++ b/samples/F#/PerformanceTests.fs @@ -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() + + [] + let ``Value: Guid`` s = roundtrip guid s + + let date = DateTime.Now + + [] + let ``Value: DateTime`` s = roundtrip date s + + [] + let ``Value: String`` s = roundtrip stringValue s + + + let boxed = box ([| 1 .. 1000 |], "lorem ipsum") + + [] + let ``Boxed Object`` s = roundtrip boxed s + + let fsClass = new Class(42, stringValue) + + [] + let ``Class: Simple F# Class`` s = roundtrip fsClass s + + let serializableClass = new SerializableClass<_>(42, stringValue, [|1..1000|]) + + [] + let ``Class: ISerializable`` s = roundtrip serializableClass s + + let boxedClass = box(Some 42) + + [] + let ``Subtype Resolution`` s = roundtrip boxedClass s + + let floatArray = Array.init 100000 (fun i -> float i) + + [] + let ``Array: Float`` s = roundtrip floatArray s + + let intArray = Array.init 100000 id + + [] + let ``Array: Int`` s = roundtrip intArray s + + let stringArray = Array.init 10000 (fun i -> stringValue + string i) + + [] + let ``Array: String`` s = roundtrip stringArray s + + let kvarr = [|1..10000|] |> Array.map (fun i -> i, string i) + + [] + let ``Array: Key-Value Pairs`` s = roundtrip kvarr s + + let duArray = [| for i in 1 .. 10000 -> (Something ("asdasdasdas", i)) |] + + [] + 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(2, stringValue, Some 12); + box stringValue + |] + + [] + let ``Array: Objects`` s = roundtrip objArray s + + + let array3D = Array3D.init 100 100 100 (fun i j k -> float (i * j + k)) + + [] + let ``Array: Rank-3 Float`` s = roundtrip array3D s + + let bclDict = dict [ for i in 1 .. 1000 -> (string i, i)] + + [] + let ``.NET Dictionary`` s = roundtrip bclDict s + + let bclStack = new Stack([for i in 1 .. 1000 -> string i]) + + [] + let ``.NET Stack`` s = roundtrip bclStack s + + let bclList = new List([for i in 1 .. 1000 -> string i, i]) + + [] + let ``.NET List`` s = roundtrip bclList s + + let bclSet = new SortedSet<_>([for i in 1 .. 1000 -> string i]) + + [] + let ``.NET Set`` s = roundtrip bclSet s + + let smallTuple = (1, DateTime.Now,"hello") + + [] + let ``FSharp: Tuple Small`` s = roundtrip smallTuple s + + let largeTuple = (stringValue, 1, 2, 3, true, "", Some(3.14, [2]), 3, 2, 1, stringValue) + + [] + let ``FSharp: Tuple Large`` s = + roundtrip largeTuple s + + let intList = [1..1000] + + [] + let ``FSharp: List Int`` s = roundtrip intList s + + let stringList = [ for i in 1 .. 1000 -> stringValue + string i ] + + [] + let ``FSharp: List String`` s = roundtrip stringList s + + let pairList = [ for i in 1 .. 1000 -> (string i, i) ] + + [] + let ``FSharp: List Key-Value`` s = roundtrip pairList s + + let nestedLst = let n = [1..1000] in [for _ in 1 .. 100 -> n] + + [] + let ``FSharp: List Nested`` s = roundtrip nestedLst s + + let union = SomethingElse(stringValue, 42, box (Some 42)) + + [] + let ``FSharp: Union`` s = roundtrip union s + + let record = { Int = 42 ; String = stringValue ; Tuple = (13, "") } + + [] + let ``FSharp: Record`` s = roundtrip record s + + let peano = int2Peano 100 + + [] + let ``FSharp: Peano Rectype`` s = roundtrip peano s + + let closure = (@) [ Some([1..100], Set.ofList [1..100]) ] + + [] + let ``FSharp: Curried Function`` s = roundtrip closure s + + let binTree = mkTree 10 + + [] + let ``FSharp: Binary Tree`` s = roundtrip binTree s + + let intSet = [1..1000] |> List.map string |> set + + [] + let ``FSharp: Set`` s = roundtrip intSet s + + let fsMap = [1..1000] |> Seq.map (fun i -> (string i,i)) |> Map.ofSeq + + [] + let ``FSharp: Map`` s = roundtrip fsMap s + + let testType = typeof> + + [] + 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 + } + @> + + [] + let ``FSharp: Quotation Small`` s = roundtrip quotationSmall s + + [] + let ``FSharp: Quotation Large`` s = roundtrip quotationLarge s \ No newline at end of file diff --git a/samples/F#/sample.fs b/samples/F#/sample.fs new file mode 100644 index 00000000..2b690f10 --- /dev/null +++ b/samples/F#/sample.fs @@ -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 "," diff --git a/samples/FORTRAN/sample1.f b/samples/FORTRAN/sample1.f new file mode 100644 index 00000000..39ba97cb --- /dev/null +++ b/samples/FORTRAN/sample1.f @@ -0,0 +1,25 @@ +c comment +* comment + + program main + + end + + subroutine foo( i, x, b ) + INTEGER i + REAL x + LOGICAL b + + if( i.ne.0 ) then + call bar( -i ) + end if + + return + end + + double complex function baz() + + baz = (0.0d0,0.0d0) + + return + end diff --git a/samples/FORTRAN/sample1.for b/samples/FORTRAN/sample1.for new file mode 100644 index 00000000..39ba97cb --- /dev/null +++ b/samples/FORTRAN/sample1.for @@ -0,0 +1,25 @@ +c comment +* comment + + program main + + end + + subroutine foo( i, x, b ) + INTEGER i + REAL x + LOGICAL b + + if( i.ne.0 ) then + call bar( -i ) + end if + + return + end + + double complex function baz() + + baz = (0.0d0,0.0d0) + + return + end diff --git a/samples/FORTRAN/sample2.f b/samples/FORTRAN/sample2.f new file mode 100644 index 00000000..19538ac7 --- /dev/null +++ b/samples/FORTRAN/sample2.f @@ -0,0 +1,25 @@ + PROGRAM MAIN + + END + +C comment +* comment + + SUBROUTINE foo( i, x, b ) + INTEGER i + REAL x + LOGICAL b + + IF( i.NE.0 ) THEN + CALL bar( -i ) + END IF + + RETURN + END + + DOUBLE COMPLEX FUNCTION baz() + + baz = (0.0d0,0.0d0) + + RETURN + END diff --git a/samples/FORTRAN/sample3.F b/samples/FORTRAN/sample3.F new file mode 100644 index 00000000..39ba97cb --- /dev/null +++ b/samples/FORTRAN/sample3.F @@ -0,0 +1,25 @@ +c comment +* comment + + program main + + end + + subroutine foo( i, x, b ) + INTEGER i + REAL x + LOGICAL b + + if( i.ne.0 ) then + call bar( -i ) + end if + + return + end + + double complex function baz() + + baz = (0.0d0,0.0d0) + + return + end diff --git a/samples/Forth/asm.fr b/samples/Forth/asm.fr new file mode 100644 index 00000000..73faf776 --- /dev/null +++ b/samples/Forth/asm.fr @@ -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: " ,". +\ Addressing modes: +\ - immediate: "n #" +\ - direct: n +\ - register: +\ - indirect: " )" +\ - indirect with displacement: "n )#" +\ - 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 diff --git a/samples/Forth/core.f b/samples/Forth/core.f new file mode 100644 index 00000000..4a13e217 --- /dev/null +++ b/samples/Forth/core.f @@ -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 "string" -- 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" -- addr n ) + pad >r begin + source? if else 0 0 then + while + r@ c! r> 1+ >r + repeat 2drop pad r> over - ; + +: ( \ ( "string" -- ) + [ 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" -- 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" -- ) ( 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" -- ) 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 diff --git a/samples/Forth/core.for b/samples/Forth/core.for new file mode 100644 index 00000000..4a13e217 --- /dev/null +++ b/samples/Forth/core.for @@ -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 "string" -- 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" -- addr n ) + pad >r begin + source? if else 0 0 then + while + r@ c! r> 1+ >r + repeat 2drop pad r> over - ; + +: ( \ ( "string" -- ) + [ 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" -- 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" -- ) ( 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" -- ) 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 diff --git a/samples/Forth/core.fs b/samples/Forth/core.fs new file mode 100644 index 00000000..4a13e217 --- /dev/null +++ b/samples/Forth/core.fs @@ -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 "string" -- 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" -- addr n ) + pad >r begin + source? if else 0 0 then + while + r@ c! r> 1+ >r + repeat 2drop pad r> over - ; + +: ( \ ( "string" -- ) + [ 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" -- 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" -- ) ( 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" -- ) 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 diff --git a/samples/Forth/core1.F b/samples/Forth/core1.F new file mode 100644 index 00000000..4a13e217 --- /dev/null +++ b/samples/Forth/core1.F @@ -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 "string" -- 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" -- addr n ) + pad >r begin + source? if else 0 0 then + while + r@ c! r> 1+ >r + repeat 2drop pad r> over - ; + +: ( \ ( "string" -- ) + [ 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" -- 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" -- ) ( 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" -- ) 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 diff --git a/samples/GLSL/recurse1.fs b/samples/GLSL/recurse1.fs new file mode 100644 index 00000000..66b4c3fe --- /dev/null +++ b/samples/GLSL/recurse1.fs @@ -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 diff --git a/samples/Golo/adapters.golo b/samples/Golo/adapters.golo new file mode 100755 index 00000000..20c7d031 --- /dev/null +++ b/samples/Golo/adapters.golo @@ -0,0 +1,67 @@ +# Copyright 2012-2014 Institut National des Sciences Appliquées de Lyon (INSA-Lyon) +# +# 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. + +module samples.Adapters + +local function list_sample = |fabric| { + println(">>> list_sample()") + let carbonCopy = list[] + let conf = map[ + ["extends", "java.util.ArrayList"], + ["overrides", map[ + ["*", |super, name, args| { + if name == "add" { + if args: length() == 2 { + carbonCopy: add(args: get(1)) + } else { + carbonCopy: add(args: get(1), args: get(2)) + } + } + return super: invokeWithArguments(args) + } + ]] + ]] + let list = fabric: maker(conf): newInstance() + list: add("bar") + list: add(0, "foo") + list: add("baz") + println(" list: " + list + " " + list: getClass()) + println("carbonCopy: " + carbonCopy + " " + carbonCopy: getClass()) +} + +local function runnable_sample = |fabric| { + println(">>> runnable_sample") + let result = array[1, 2, 3] + let conf = map[ + ["interfaces", ["java.io.Serializable", "java.lang.Runnable"]], + ["implements", map[ + ["run", |this| { + for (var i = 0, i < result: length(), i = i + 1) { + result: set(i, result: get(i) + 10) + } + }] + ]] + ] + let runner = fabric: maker(conf): newInstance() + runner: run() + println(" result: " + result: toString()) + println("serializable? " + (runner oftype java.io.Serializable.class)) + println(" runnable? " + (runner oftype java.lang.Runnable.class)) +} + +function main = |args| { + let fabric = AdapterFabric() + list_sample(fabric) + runnable_sample(fabric) +} diff --git a/samples/Golo/async.golo b/samples/Golo/async.golo new file mode 100755 index 00000000..432f8c94 --- /dev/null +++ b/samples/Golo/async.golo @@ -0,0 +1,84 @@ +# Copyright 2012-2014 Institut National des Sciences Appliquées de Lyon (INSA-Lyon) +# +# 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. + +module samples.AsyncHelpers + +import gololang.Async +import java.util.concurrent.TimeUnit +import java.util.concurrent.Executors + +local function fib = |n| { + if n <= 1 { + return n + } else { + return fib(n - 1) + fib(n - 2) + } +} + +function main = |args| { + + let executor = newCachedThreadPool() + println("Let's do some useless asynchronous operations...") + + var f = executor: enqueue({ + Thread.sleep(1000_L) + return 666 + }) + f: + onSet(|v| -> println(">>> #slow -> " + v)): + onFail(|e| -> println(">>> #fail -> " + e)) + f: + cancel(true) + + f = executor: enqueue({ + Thread.sleep(1000_L) + return 666 + }) + f: + onSet(|v| -> println(">>> #ok -> " + v)): + onFail(|e| -> println(">>> #wtf? -> " + e)) + + let fib_10 = promise() + let fib_20 = promise() + let fib_30 = promise() + let fib_40 = promise() + + let futures = [ + fib_10: future(), fib_20: future(), + fib_30: future(), fib_40: future() + ] + + executor: submit(-> fib_10: set(fib(10))) + executor: submit(-> fib_20: set(fib(20))) + executor: submit(-> fib_30: set(fib(30))) + executor: submit(-> fib_40: set(fib(40))) + + all(futures): onSet(|results| -> println(">>> Fibs: " + results)) + + let truth = promise() + truth: + future(): + map(|v| -> "truth=" + v): + onSet(|v| -> executor: submit(-> println(">>> (another thread) " + v))): + onSet(|v| -> println(">>> (same thread) " + v)) + executor: submit({ + Thread.sleep(500_L) + truth: set(42) + }) + + Thread.sleep(1000_L) + executor: shutdown() + executor: awaitTermination(2_L, SECONDS()) + println("Bye!") +} diff --git a/samples/Golo/augmentations.golo b/samples/Golo/augmentations.golo new file mode 100755 index 00000000..bed289a4 --- /dev/null +++ b/samples/Golo/augmentations.golo @@ -0,0 +1,37 @@ +# Copyright 2012-2014 Institut National des Sciences Appliquées de Lyon (INSA-Lyon) +# +# 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. + +module samples.Augmentations + +import java.util.LinkedList + +augment java.util.List { + function with = |this, value| { + this: add(value) + return this + } +} + +augment java.util.Collection { + function doToEach = |this, func| { + foreach (element in this) { + func(element) + } + } +} + +function main = |args| { + let list = LinkedList(): with("foo"): with("bar"): with("baz") + list: doToEach(|value| -> println(">>> " + value)) +} diff --git a/samples/Golo/closures.golo b/samples/Golo/closures.golo new file mode 100755 index 00000000..32378017 --- /dev/null +++ b/samples/Golo/closures.golo @@ -0,0 +1,43 @@ +# Copyright 2012-2014 Institut National des Sciences Appliquées de Lyon (INSA-Lyon) +# +# 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. + +module Closures + +local function sayHello = |who| -> "Hello " + who + "!" + +function main = |args| { + let adder = |a, b| -> a + b + println(adder: invokeWithArguments(1, 2)) + println(adder(1, 2)) + + let addToTen = adder: bindTo(10) + println(addToTen: invokeWithArguments(2)) + println(addToTen(2)) + + let adding = |x| -> |y| -> adder(x, y) + let addingTen = adding(10) + println(addingTen(4)) + println(adding(2)(4)) + + println(sayHello("Julien")) + + let list = java.util.LinkedList() + let pump_it = { + list: add("I heard you say") + list: add("Hey!") + list: add("Hey!") + } + pump_it() + println(list) +} diff --git a/samples/Golo/coin-change.golo b/samples/Golo/coin-change.golo new file mode 100755 index 00000000..fe82bb04 --- /dev/null +++ b/samples/Golo/coin-change.golo @@ -0,0 +1,34 @@ +# Copyright 2012-2014 Institut National des Sciences Appliquées de Lyon (INSA-Lyon) +# +# 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. + +module CoinChange + +import java.util.LinkedList + +function change = |money, coins| -> match { + when money == 0 then 1 + when (money < 0) or (coins: isEmpty()) then 0 + otherwise change(money - coins: head(), coins) + change(money, coins: tail()) +} + +function main = |args| { + let coins = LinkedList(): append(1, 2, 5, 10, 20) + println("Coins: " + coins) + println("0: " + change(0, coins)) + println("1: " + change(1, coins)) + println("2: " + change(2, coins)) + println("10: " + change(10, coins)) + println("12: " + change(12, coins)) + println("6: " + change(6, coins)) +} diff --git a/samples/Golo/collection-literals.golo b/samples/Golo/collection-literals.golo new file mode 100755 index 00000000..ac19b35e --- /dev/null +++ b/samples/Golo/collection-literals.golo @@ -0,0 +1,55 @@ +# Copyright 2012-2014 Institut National des Sciences Appliquées de Lyon (INSA-Lyon) +# +# 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. + +module samples.CollectionLiterals + +local function play_with_tuples = { + let hello = ["Hello", "world", "!"] + foreach str in hello { + print(str + " ") + } + println("") + + println(hello: get(0) + "-" + hello: get(1) + "-" + hello: get(2)) + + println(hello: join("/")) +} + +local function play_with_literals = { + let data = [ + [1, 2, 3], + tuple[1, 2, 3], + array[1, 2, 3], + set[1, 2, 3, 3, 1], + map[ + ["a", 10], + ["b", 20] + ], + vector[1, 2, 3], + list[1, 2, 3] + ] + + data: each(|element| { + println(element: toString()) + println(" type: " + element: getClass()) + }) +} + +function main = |args| { + println(">>> Literals") + play_with_literals() + println("\n>>> Tuples") + play_with_tuples() +} + diff --git a/samples/Golo/context-decorator.golo b/samples/Golo/context-decorator.golo new file mode 100755 index 00000000..6a3bb889 --- /dev/null +++ b/samples/Golo/context-decorator.golo @@ -0,0 +1,53 @@ +# Copyright 2012-2014 Institut National des Sciences Appliquées de Lyon (INSA-Lyon) +# +# 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. + +module samples.ContextDecorator + +import gololang.Decorators + +let myContext = defaultContext(): + count(0): + define("entry", |this, args| { + this: count(this: count() + 1) + println("hello:" + this: count()) + return args + }): + define("exit", |this, result| { + require(result >= 3, "wrong value") + println("goobye") + return result + }): + define("catcher", |this, e| { + println("Caught " + e) + throw e + }): + define("finallizer", |this| {println("do some cleanup")}) + + +@withContext(myContext) +function foo = |a, b| { + println("Hard computation") + return a + b +} + +function main = |args| { + println(foo(1,2)) + println("====") + println(withContext(myContext)(|a| -> 2*a)(3)) + println("====") + try { + println(foo(1, 1)) + } catch (e) { } +} + diff --git a/samples/Golo/decorators.golo b/samples/Golo/decorators.golo new file mode 100755 index 00000000..c3acbfc4 --- /dev/null +++ b/samples/Golo/decorators.golo @@ -0,0 +1,83 @@ +# Copyright 2012-2014 Institut National des Sciences Appliquées de Lyon (INSA-Lyon) +# +# 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. + +module samples.Decorators + +import java.util.LinkedList + +function simple_decorator = |func| { + return |a,b| -> func(a+1,b+1) +} + +@simple_decorator +function simple_adder = |x,y| -> x + y + +function decorator_with_params = |param1, param2|{ + return |func| { + return |a,b| -> func(a+param1,b+param2) + } +} + +@decorator_with_params(10,2) +function parametrized_adder = |x,y| -> x + y + +function generic_decorator = |func| { + return |args...| { + println("number of params : "+args: length()) + return func: invokeWithArguments(args) + } +} + +@generic_decorator +function generic_adder0 = -> 42 + +@generic_decorator +function generic_adder1 = |x| -> x + +@generic_decorator +function generic_adder2 = |x,y| -> x + y + +@generic_decorator +function generic_adder3 = |x,y,z| -> x + y + z + +function list_sum_decorator = |func| { + return |this| -> func(this) - 8 +} + +augment java.util.List { + + @list_sum_decorator + function sum = |this| { + var acc = 0 + foreach elem in this { + acc = acc + elem + } + return acc + } +} + +function main = |args| { + println(simple_adder(10,30)) + println(parametrized_adder(10,20)) + println(generic_adder0()) + println(generic_adder1(42)) + println(generic_adder2(20,22)) + println(generic_adder3(10,12,20)) + let list = LinkedList() + list: add(5) + list: add(10) + list: add(15) + list: add(20) + println(list: sum()) +} \ No newline at end of file diff --git a/samples/Golo/dynamic-evaluation.golo b/samples/Golo/dynamic-evaluation.golo new file mode 100755 index 00000000..af5351f4 --- /dev/null +++ b/samples/Golo/dynamic-evaluation.golo @@ -0,0 +1,88 @@ +# Copyright 2012-2014 Institut National des Sciences Appliquées de Lyon (INSA-Lyon) +# +# 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. + +module samples.DynamicEvaluation + +import gololang.EvaluationEnvironment + +local function test_asModule = |env| { + let code = +""" +module foo + +function a = -> "a!" +function b = -> "b!" +""" + let mod = env: asModule(code) + let a = fun("a", mod) + let b = fun("b", mod) + println(">>> asModule()") + println(a()) + println(b()) +} + +local function test_anonymousModule = |env| { + let code = +""" +function a = -> "a." +function b = -> "b." +""" + let mod = env: anonymousModule(code) + let a = fun("a", mod) + let b = fun("b", mod) + println(">>> anonymousModule()") + println(a()) + println(b()) +} + +local function test_asFunction = |env| { + let code = "return (a + b) * 2" + let f = env: asFunction(code, "a", "b") + println(">>> asFunction") + println(f(10, 20)) +} + +local function test_def = |env| { + let code = "|a, b| -> (a + b) * 2" + let f = env: def(code) + println(">>> def") + println(f(10, 20)) +} + +local function test_run = |env| { + let code = """println(">>> run") + foreach (i in range(0, 3)) { + println("w00t") + }""" + env: run(code) +} + +local function test_run_map = |env| { + let code = """println(">>> run_map") + println(a) + println(b) + """ + let values = java.util.TreeMap(): add("a", 1): add("b", 2) + env: run(code, values) +} + +function main = |args| { + let env = EvaluationEnvironment() + test_asModule(env) + test_anonymousModule(env) + test_asFunction(env) + test_def(env) + test_run(env) + test_run_map(env) +} diff --git a/samples/Golo/dynamic-object-person.golo b/samples/Golo/dynamic-object-person.golo new file mode 100755 index 00000000..27f3ab6d --- /dev/null +++ b/samples/Golo/dynamic-object-person.golo @@ -0,0 +1,29 @@ +# Copyright 2012-2014 Institut National des Sciences Appliquées de Lyon (INSA-Lyon) +# +# 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. + +module samples.DynamicObjectPerson + +local function mrbean = -> DynamicObject(): + name("Mr Bean"): + email("mrbean@gmail.com"): + define("toString", |this| -> this: name() + " <" + this: email() + ">") + +function main = |args| { + + let bean = mrbean() + println(bean: toString()) + + bean: email("mrbean@outlook.com") + println(bean: toString()) +} diff --git a/samples/Golo/echo-args.golo b/samples/Golo/echo-args.golo new file mode 100755 index 00000000..7bf1e093 --- /dev/null +++ b/samples/Golo/echo-args.golo @@ -0,0 +1,34 @@ +# Copyright 2012-2014 Institut National des Sciences Appliquées de Lyon (INSA-Lyon) +# +# 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. + +module EchoArgs + +function main = |args| { + + println("With a for loop and an index:") + for (var i = 0, i < args: length(), i = i + 1) { + println(" #" + i + " -> " + args: get(i)) + } + + println("With a foreach loop:") + foreach arg in args { + println(" " + arg) + } + + println("With a foreach over a range:") + foreach i in range(0, args: length()) { + println(" #" + i + " -> " + args: get(i)) + } +} + diff --git a/samples/Golo/enums-thread-state.golo b/samples/Golo/enums-thread-state.golo new file mode 100755 index 00000000..4310ea26 --- /dev/null +++ b/samples/Golo/enums-thread-state.golo @@ -0,0 +1,31 @@ +# Copyright 2012-2014 Institut National des Sciences Appliquées de Lyon (INSA-Lyon) +# +# 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. + +module sample.EnumsThreadState + +import java.lang.Thread$State + +function main = |args| { + + # Call the enum entry like a function + let new = Thread$State.NEW() + println("name=" + new: name() + ", ordinal=" + new: ordinal()) + println("-----------") + + # Walk through all enum entries + foreach element in Thread$State.values() { + println("name=" + element: name() + ", ordinal=" + element: ordinal()) + } +} + diff --git a/samples/Golo/fibonacci.golo b/samples/Golo/fibonacci.golo new file mode 100755 index 00000000..53455a7d --- /dev/null +++ b/samples/Golo/fibonacci.golo @@ -0,0 +1,39 @@ +# Copyright 2012-2014 Institut National des Sciences Appliquées de Lyon (INSA-Lyon) +# +# 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. + +module samples.Fibonacci + +import java.lang.System + +function fib = |n| { + if n <= 1 { + return n + } else { + return fib(n - 1) + fib(n - 2) + } +} + +local function run = { + let start = System.currentTimeMillis() + let result = fib(40) + let duration = System.currentTimeMillis() - start + println(">>> " + result + " (took " + duration + "ms)") +} + +function main = |args| { + while true { + run() + } +} + diff --git a/samples/Golo/helloworld.golo b/samples/Golo/helloworld.golo new file mode 100755 index 00000000..4800de6d --- /dev/null +++ b/samples/Golo/helloworld.golo @@ -0,0 +1,20 @@ +# Copyright 2012-2014 Institut National des Sciences Appliquées de Lyon (INSA-Lyon) +# +# 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. + +module hello.World + +function main = |args| { + println("Hello world!") +} + diff --git a/samples/Golo/http-server.golo b/samples/Golo/http-server.golo new file mode 100755 index 00000000..ce4ff857 --- /dev/null +++ b/samples/Golo/http-server.golo @@ -0,0 +1,53 @@ +# Copyright 2012-2014 Institut National des Sciences Appliquées de Lyon (INSA-Lyon) +# +# 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. + +module samples.WebServer + +import java.lang +import java.net.InetSocketAddress +import com.sun.net.httpserver +import com.sun.net.httpserver.HttpServer + +function main = |args| { + + let server = HttpServer.create(InetSocketAddress("localhost", 8081), 0) + + server: createContext("/", |exchange| { + let headers = exchange: getResponseHeaders() + let response = StringBuilder(): + append("Requested URI: "): + append(exchange: getRequestURI()): + append("\n"): + append("Current time: "): + append(java.util.Date()): + append("\n"): + toString() + headers: set("Content-Type", "text/plain") + exchange: sendResponseHeaders(200, response: length()) + exchange: getResponseBody(): write(response: getBytes()) + exchange: close() + }) + + server: createContext("/shutdown", |exchange| { + let response = "Ok, thanks, bye!" + exchange: getResponseHeaders(): set("Content-Type", "text/plain") + exchange: sendResponseHeaders(200, response: length()) + exchange: getResponseBody(): write(response: getBytes()) + exchange: close() + server: stop(5) + }) + + server: start() + println(">>> http://localhost:8081/") +} diff --git a/samples/Golo/logdeco.golo b/samples/Golo/logdeco.golo new file mode 100755 index 00000000..ae42a133 --- /dev/null +++ b/samples/Golo/logdeco.golo @@ -0,0 +1,65 @@ + +module samples.LogDeco + +function log1 = |msg| { + return |fun| { + return |args...| { + println(msg) + return fun: invokeWithArguments(args) + } + } +} + +@log1("calling foo") +function foo = |a| { + println("foo got a " + a) +} + +@log1("I'am a bar") +function bar = |a| -> 2*a + +let sayHello = log1("Hello") + +@sayHello +function baz = -> "Goodbye" + +function log2 = |msgBefore| -> |msgAfter| -> |func| -> |args...| { + println(msgBefore) + let res = func: invokeWithArguments(args) + println(msgAfter) + return res +} + +@log2("enter foo")("exit foo") +function spam = |a| { + println("foo: " + a) +} + +function logEnterExit = |name| -> log2("# enter " + name)("# exit " + name) + +@logEnterExit("bar") +function egg = { println("doing something...") } + +function main = |args| { + + foo("bar") + + println("---") + println(bar(21)) + + println("---") + println(baz()) + + println("---") + spam("bar") + + println("---") + egg() + + println("---") + let strange_use = log2("hello")("goodbye")({println(":p")}) + strange_use() + + println("---") + log2("another")("use")(|a|{println(a)})("strange") +} diff --git a/samples/Golo/matching-operator.golo b/samples/Golo/matching-operator.golo new file mode 100755 index 00000000..380d2259 --- /dev/null +++ b/samples/Golo/matching-operator.golo @@ -0,0 +1,40 @@ +# Copyright 2012-2014 Institut National des Sciences Appliquées de Lyon (INSA-Lyon) +# +# 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. + +module Matching + +import java.util.LinkedList + +local function data = { + let list = LinkedList() + list: add("foo@bar.com") + list: add("+33.6.11.22.33") + list: add("http://golo-lang.org/") + list: add("def foo = bar(_._) with :> T") + return list +} + +local function what_it_could_be = |item| -> match { + when item: contains("@") then "an email?" + when item: startsWith("+33") then "a French phone number?" + when item: startsWith("http://") then "a website URL?" + otherwise "I have no clue, mate!" +} + +function main = |args| { + foreach item in data() { + println(item + " => " + what_it_could_be(item)) + } +} + diff --git a/samples/Golo/max-int.golo b/samples/Golo/max-int.golo new file mode 100755 index 00000000..457a5dff --- /dev/null +++ b/samples/Golo/max-int.golo @@ -0,0 +1,24 @@ +# Copyright 2012-2014 Institut National des Sciences Appliquées de Lyon (INSA-Lyon) +# +# 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. + +module samples.MaxInt + +local function max_int = { + return java.lang.Integer.MAX_VALUE() +} + +function main = |args| { + println(max_int()) +} + diff --git a/samples/Golo/memoize.golo b/samples/Golo/memoize.golo new file mode 100755 index 00000000..8fb1b455 --- /dev/null +++ b/samples/Golo/memoize.golo @@ -0,0 +1,55 @@ +# Copyright 2012-2014 Institut National des Sciences Appliquées de Lyon (INSA-Lyon) +# +# 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. + +module samples.MemoizeDecorator + +import gololang.Decorators + +import java.lang.System + +let memo = memoizer() + +@memo +function fib = |n| { + if n <= 1 { + return n + } else { + return fib(n - 1) + fib(n - 2) + } +} + +@memo +function foo = |n| -> n + +local function run = { + let start = System.currentTimeMillis() + let result = fib(40) + let duration = System.currentTimeMillis() - start + println(">>> fib(40) = " + result + " (took " + duration + "ms)") +} + +local function run2 = { + let start = System.currentTimeMillis() + let result = foo(40) + let duration = System.currentTimeMillis() - start + println(">>> foo(40) = " + result + " (took " + duration + "ms)") +} + +function main = |args| { + foreach i in range(0, 5) { + println("run " + i) + run() + run2() + } +} diff --git a/samples/Golo/null-safety.golo b/samples/Golo/null-safety.golo new file mode 100755 index 00000000..903f5309 --- /dev/null +++ b/samples/Golo/null-safety.golo @@ -0,0 +1,43 @@ +# Copyright 2012-2014 Institut National des Sciences Appliquées de Lyon (INSA-Lyon) +# +# 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. + +module DealingWithNull + +import java.util + +function main = |args| { + + # Data model + let contacts = map[ + ["mrbean", map[ + ["email", "bean@gmail.com"], + ["url", "http://mrbean.com"] + ]], + ["larry", map[ + ["email", "larry@iamricherthanyou.com"] + ]] + ] + + # MrBean and Larry + let mrbean = contacts: get("mrbean") + let larry = contacts: get("larry") + + # Illustrates orIfNull + println(mrbean: get("url") orIfNull "n/a") + println(larry: get("url") orIfNull "n/a") + + # Querying a non-existent data model because there is no 'address' entry + println(mrbean: get("address")?: street()?: number() orIfNull "n/a") +} + diff --git a/samples/Golo/prepost-decorators.golo b/samples/Golo/prepost-decorators.golo new file mode 100755 index 00000000..a7ea73ca --- /dev/null +++ b/samples/Golo/prepost-decorators.golo @@ -0,0 +1,65 @@ +# Copyright 2012-2014 Institut National des Sciences Appliquées de Lyon (INSA-Lyon) +# +# 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. + +module samples.PrepostDecorator + +import gololang.Decorators + +let isInteger = isOfType(Integer.class) + +@checkResult(isString(): andThen(lengthIs(2))) +@checkArguments(isInteger: andThen(isPositive()), isString()) +function foo = |a, b| { + return b + a +} + +let myCheck = checkArguments(isInteger: andThen(isPositive())) + +@myCheck +function inv = |v| -> 1.0 / v + +let isPositiveInt = isInteger: andThen(isPositive()) + +@checkArguments(isPositiveInt) +function mul = |v| -> 10 * v + +@checkArguments(isNumber()) +function num = |v| -> "ok" + +@checkArguments(isNotNull()) +function notnull = |v| -> "ok" + +function main = |args| { + try { println(foo(1, "b")) } catch (e) { println(e) } + try { println(foo(-1, "b")) } catch (e) { println(e) } + try { println(foo("a", 2)) } catch (e) { println(e) } + try { println(foo(1, 2)) } catch (e) { println(e) } + try { println(foo(10, "ab")) } catch (e) { println(e) } + + try { println(inv(10)) } catch (e) { println(e) } + try { println(inv(0)) } catch (e) { println(e) } + + try { println(mul(5)) } catch (e) { println(e) } + try { println(mul(0)) } catch (e) { println(e) } + + try { println(num(1)) } catch (e) { println(e) } + try { println(num(1_L)) } catch (e) { println(e) } + try { println(num(1.5)) } catch (e) { println(e) } + try { println(num(1.5_F)) } catch (e) { println(e) } + try { println(num("a")) } catch (e) { println(e) } + try { println(num('a')) } catch (e) { println(e) } + + try { println(notnull('1')) } catch (e) { println(e) } + try { println(notnull(null)) } catch (e) { println(e) } +} diff --git a/samples/Golo/structs.golo b/samples/Golo/structs.golo new file mode 100755 index 00000000..de18836a --- /dev/null +++ b/samples/Golo/structs.golo @@ -0,0 +1,69 @@ +# Copyright 2012-2014 Institut National des Sciences Appliquées de Lyon (INSA-Lyon) +# +# 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. + +module StructDemo + +struct Point = { x, y } + +augment StructDemo.types.Point { + + function move = |this, offsetX, offsetY| { + this: x(this: x() + offsetX) + this: y(this: y() + offsetY) + return this + } + + function relative = |this, offsetX, offsetY| -> Point(this: x() + offsetX, this: y() + offsetY) +} + +function main = |args| { + + let p1 = Point(1, 2) + let p2 = Point(): x(1): y(2) + let p3 = p1: frozenCopy() + let p4 = p1: frozenCopy() + + println(p1) + println("x = " + p1: x()) + println("y = " + p1: y()) + + println("p1 == p2 " + (p1 == p2)) + println("p1 == p3 " + (p1 == p3)) + println("p3 == p4 " + (p3 == p4)) + + println("#p1 " + p1: hashCode()) + println("#p2 " + p2: hashCode()) + println("#p3 " + p3: hashCode()) + println("#p4 " + p4: hashCode()) + + println("p1: members() " + p1: members()) + println("p1: values() " + p1: values()) + foreach item in p1 { + println(item: get(0) + " -> " + item: get(1)) + } + + println("p1: set(\"x\", 10) " + p1: set("x", 10)) + println("p1: move(10, 5) " + p1: move(10, 5)) + println("p1: relative(11, 6) " + p1: relative(11, 6)) + + let p5 = ImmutablePoint(10, 20) + println("p5: " + p5) + try { + p5: x(100) + } catch (expected) { + println("p5 is immutable, so... " + expected: getMessage()) + } +} + + diff --git a/samples/Golo/swing-actionlistener.golo b/samples/Golo/swing-actionlistener.golo new file mode 100755 index 00000000..61d0f7f3 --- /dev/null +++ b/samples/Golo/swing-actionlistener.golo @@ -0,0 +1,43 @@ +# Copyright 2012-2014 Institut National des Sciences Appliquées de Lyon (INSA-Lyon) +# +# 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. + +module samples.SwingActionListener + +import java.awt.event +import javax.swing +import javax.swing.WindowConstants + +local function listener = |handler| -> asInterfaceInstance(ActionListener.class, handler) + +function main = |args| { + + let frame = JFrame("Action listeners") + frame: setDefaultCloseOperation(EXIT_ON_CLOSE()) + + let button = JButton("Click me!") + button: setFont(button: getFont(): deriveFont(96.0_F)) + + # Using a helper function + button: addActionListener(listener(|event| -> println("Clicked!"))) + + # Using a standard augmentation: MethodHandle::to(Class) + button: addActionListener((|event| -> println("[click]")): to(ActionListener.class)) + + # Straight closure passing + button: addActionListener(|event| -> println("( )")) + + frame: getContentPane(): add(button) + frame: pack() + frame: setVisible(true) +} diff --git a/samples/Golo/swing-helloworld.golo b/samples/Golo/swing-helloworld.golo new file mode 100755 index 00000000..9d5e0541 --- /dev/null +++ b/samples/Golo/swing-helloworld.golo @@ -0,0 +1,31 @@ +# Copyright 2012-2014 Institut National des Sciences Appliquées de Lyon (INSA-Lyon) +# +# 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. + +module samples.SwingHelloWorld + +import javax.swing +import javax.swing.WindowConstants + +function main = |args| { + + let frame = JFrame("Hello world") + frame: setDefaultCloseOperation(EXIT_ON_CLOSE()) + + let label = JLabel("Hello world") + label: setFont(label: getFont(): deriveFont(128.0_F)) + + frame: getContentPane(): add(label) + frame: pack() + frame: setVisible(true) +} diff --git a/samples/Golo/templates-chat-webapp.golo b/samples/Golo/templates-chat-webapp.golo new file mode 100755 index 00000000..a5eab98b --- /dev/null +++ b/samples/Golo/templates-chat-webapp.golo @@ -0,0 +1,90 @@ +# Copyright 2012-2014 Institut National des Sciences Appliquées de Lyon (INSA-Lyon) +# +# 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. + +module samples.TemplatesChatWebapp + +import java.lang +import java.io +import java.net.InetSocketAddress +import com.sun.net.httpserver +import com.sun.net.httpserver.HttpServer + +local function redirect = |exchange, to| { + exchange: getResponseHeaders(): set("Location", to) + exchange: sendResponseHeaders(303, 0) + exchange: close() +} + +local function respond = |exchange, body| { + exchange: getResponseHeaders(): set("Content-Type", "text/html") + exchange: sendResponseHeaders(200, body: length()) + exchange: getResponseBody(): write(body: getBytes()) + exchange: close() +} + +# This is leaky and works with just 1 POST parameter... +local function extract_post = |exchange, posts| { + let reader = BufferedReader(InputStreamReader(exchange: getRequestBody())) + var line = reader: readLine() + while line isnt null { + if line: startsWith("msg=") { + posts: add(java.net.URLDecoder.decode(line: substring(4), "UTF-8")) + } + line = reader: readLine() + } + reader: close() +} + + +local function index = |posts, template, exchange| { + if exchange: getRequestMethod() == "POST" { + extract_post(exchange, posts) + redirect(exchange, "/") + } else { + respond(exchange, template(posts)) + } +} + +local function index_template = -> """ +<%@params posts %> + + + + Golo Chat + + +
+ + +
+
+

Last posts

+ <% foreach post in posts { %> +
+ <%= post %> +
+ <% } %> +
+ + +""" + +function main = |args| { + let index_tpl = gololang.TemplateEngine(): compile(index_template()) + let posts = java.util.concurrent.ConcurrentLinkedDeque() + let server = HttpServer.create(InetSocketAddress("localhost", 8081), 0) + server: createContext("/", ^index: bindTo(posts): bindTo(index_tpl)) + server: start() + println(">>> http://localhost:8081/") +} diff --git a/samples/Golo/util-containers.golo b/samples/Golo/util-containers.golo new file mode 100755 index 00000000..63d09b6a --- /dev/null +++ b/samples/Golo/util-containers.golo @@ -0,0 +1,51 @@ +# Copyright 2012-2014 Institut National des Sciences Appliquées de Lyon (INSA-Lyon) +# +# 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. + +module MoreCoolContainers + +function main = |args| { + + println(">>> DynamicVariable") + + let dyn = DynamicVariable("Foo") + println(dyn: value()) + + let t1 = Thread({ + dyn: withValue(666, { + println(dyn: value()) + }) + }) + + let t2 = Thread({ + dyn: withValue(69, { + println(dyn: value()) + }) + }) + + t1: start() + t2: start() + t1: join() + t2: join() + println(dyn: value()) + + println(">>> Observable") + + let foo = Observable("Foo") + foo: onChange(|v| -> println("foo = " + v)) + + let mapped = foo: map(|v| -> v + "!") + mapped: onChange(|v| -> println("mapped = " + v)) + + foo: set("69") +} diff --git a/samples/Golo/workers.golo b/samples/Golo/workers.golo new file mode 100755 index 00000000..8c08f650 --- /dev/null +++ b/samples/Golo/workers.golo @@ -0,0 +1,48 @@ +# Copyright 2012-2014 Institut National des Sciences Appliquées de Lyon (INSA-Lyon) +# +# 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. + +module Workers + +import java.lang.Thread +import java.util.concurrent +import gololang.concurrent.workers.WorkerEnvironment + +local function pusher = |queue, message| -> queue: offer(message) + +local function generator = |port, message| { + foreach i in range(0, 100) { + port: send(message) + } +} + +function main = |args| { + + let env = WorkerEnvironment.builder(): withFixedThreadPool() + let queue = ConcurrentLinkedQueue() + + let pusherPort = env: spawn(^pusher: bindTo(queue)) + let generatorPort = env: spawn(^generator: bindTo(pusherPort)) + + let finishPort = env: spawn(|any| -> env: shutdown()) + + foreach i in range(0, 10) { + generatorPort: send("[" + i + "]") + } + Thread.sleep(2000_L) + finishPort: send("Die!") + + env: awaitTermination(2000) + println(queue: reduce("", |acc, next| -> acc + " " + next)) +} + diff --git a/samples/Gosu/Ronin.gs b/samples/Gosu/Ronin.gs new file mode 100644 index 00000000..dfbdee7b --- /dev/null +++ b/samples/Gosu/Ronin.gs @@ -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(); + + // 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(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(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() + } + +} diff --git a/samples/Gradle/build.gradle b/samples/Gradle/build.gradle new file mode 100644 index 00000000..190eb3f6 --- /dev/null +++ b/samples/Gradle/build.gradle @@ -0,0 +1,18 @@ +apply plugin: GreetingPlugin + +greeting.message = 'Hi from Gradle' + +class GreetingPlugin implements Plugin { + 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' +} diff --git a/samples/Gradle/builder.gradle b/samples/Gradle/builder.gradle new file mode 100644 index 00000000..342be2fd --- /dev/null +++ b/samples/Gradle/builder.gradle @@ -0,0 +1,20 @@ +apply plugin: GreetingPlugin + +greeting { + message = 'Hi' + greeter = 'Gradle' +} + +class GreetingPlugin implements Plugin { + 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 +} diff --git a/samples/Graphviz (DOT)/annoying.DOT b/samples/Graphviz (DOT)/annoying.DOT new file mode 100644 index 00000000..fd20f4a4 --- /dev/null +++ b/samples/Graphviz (DOT)/annoying.DOT @@ -0,0 +1,50 @@ +/* + Huffman Tree DOT graph. + + DOT Reference : http://www.graphviz.org/doc/info/lang.html + http://en.wikipedia.org/wiki/DOT_language + Timestamp : 1415989074 + Phrase : 'OH GOD WHY IS LINGUIST SO ANAL ABOUT THIS STUFF' + + Generated on http://huffman.ooz.ie/ +*/ + +digraph G { + edge [label=0]; + graph [ranksep=0]; + T [shape=record, label="{{T|4}|000}"]; + S [shape=record, label="{{S|5}|001}"]; + SPACE [shape=record, label="{{SPACE|9}|01}"]; + A [shape=record, label="{{A|3}|1000}"]; + H [shape=record, label="{{H|3}|1001}"]; + U [shape=record, label="{{U|3}|1010}"]; + L [shape=record, label="{{L|2}|10110}"]; + N [shape=record, label="{{N|2}|10111}"]; + I [shape=record, label="{{I|4}|1100}"]; + O [shape=record, label="{{O|4}|1101}"]; + G [shape=record, label="{{G|2}|11100}"]; + F [shape=record, label="{{F|2}|11101}"]; + GF [label=4]; + W [shape=record, label="{{W|1}|111100}"]; + Y [shape=record, label="{{Y|1}|111101}"]; + B [shape=record, label="{{B|1}|111110}"]; + D [shape=record, label="{{D|1}|111111}"]; + BD [label=2]; + WYBD [label=4]; + GFWYBD [label=8]; + 47 -> 18 -> 9 -> T; + 29 -> 13 -> 6 -> A; + 7 -> U; + 4 -> L; + 16 -> 8 -> I; + GFWYBD -> GF -> G; + WYBD -> 2 -> W; + BD -> B;9 -> S [label=1]; + 18 -> SPACE [label=1]; + 6 -> H [label=1]; + 13 -> 7 -> 4 -> N [label=1]; + 8 -> O [label=1]; + GF -> F [label=1]; + 2 -> Y [label=1]; + 47 -> 29 -> 16 -> GFWYBD -> WYBD -> BD -> D [label=1]; +} \ No newline at end of file diff --git a/samples/Graphviz (DOT)/sample.dot b/samples/Graphviz (DOT)/sample.dot new file mode 100644 index 00000000..a55dc093 --- /dev/null +++ b/samples/Graphviz (DOT)/sample.dot @@ -0,0 +1,74 @@ +/* + Huffman Tree DOT graph. + + DOT Reference : http://www.graphviz.org/doc/info/lang.html + http://en.wikipedia.org/wiki/DOT_language + Timestamp : 1415988139 + Phrase : 'SERIAL KILLER AND SEX OFFENDER ANGUS SINCLAIR IS JAILED FOR A MINIMUM OF 37 YEARS FOR THE 1977 WORLDS END MURDERS OF HELEN SCOTT AND CHRISTINE EADIE.' + + Generated on http://huffman.ooz.ie/ +*/ + +digraph G { + edge [label=0]; + graph [ranksep=0]; + node [shape=record]; + U [label="{{U|3}|00000}"]; + G [label="{{G|1}|0000100}"]; + K [label="{{K|1}|0000101}"]; + _3 [label="{{3|1}|0000110}"]; + _9 [label="{{9|1}|0000111}"]; + _39 [label=2]; + L [label="{{L|7}|0001}"]; + O [label="{{O|7}|0010}"]; + Y [label="{{Y|1}|0011000}"]; + X [label="{{X|1}|0011001}"]; + YX [label=2]; + J [label="{{J|1}|0011010}"]; + W [label="{{W|1}|0011011}"]; + JW [label=2]; + YXJW [label=4]; + M [label="{{M|4}|00111}"]; + E [label="{{E|15}|010}"]; + D [label="{{D|8}|0110}"]; + T [label="{{T|4}|01110}"]; + DOT [label="{{DOT|1}|0111100}"]; + _1 [label="{{1|1}|0111101}"]; + DOT1 [label=2]; + _7 [label="{{7|3}|011111}"]; + A [label="{{A|9}|1000}"]; + N [label="{{N|9}|1001}"]; + S [label="{{S|10}|1010}"]; + I [label="{{I|11}|1011}"]; + R [label="{{R|11}|1100}"]; + C [label="{{C|3}|110100}"]; + H [label="{{H|3}|110101}"]; + F [label="{{F|6}|11011}"]; + SPACE [label="{{SPACE|26}|111}"]; + 149 -> 61 -> 29 -> 14 -> 7 -> U; + 4 -> 2 -> G; + _39 -> _3; + 15 -> O; + 8 -> YXJW -> YX -> Y; + JW -> J; + 32 -> E; + 17 -> D; + 9 -> T; + 5 -> DOT1 -> DOT; + 88 -> 39 -> 18 -> A; + 21 -> S; + 49 -> 23 -> R; + 12 -> 6 -> C;2 -> K [label=1]; + 7 -> 4 -> _39 -> _9 [label=1]; + 14 -> L [label=1]; + YX -> X [label=1]; + YXJW -> JW -> W [label=1]; + 29 -> 15 -> 8 -> M [label=1]; + DOT1 -> _1 [label=1]; + 61 -> 32 -> 17 -> 9 -> 5 -> _7 [label=1]; + 18 -> N [label=1]; + 39 -> 21 -> I [label=1]; + 6 -> H [label=1]; + 23 -> 12 -> F [label=1]; + 149 -> 88 -> 49 -> SPACE [label=1]; +} \ No newline at end of file diff --git a/samples/HTML/example.xht b/samples/HTML/example.xht new file mode 100644 index 00000000..a49a0a53 --- /dev/null +++ b/samples/HTML/example.xht @@ -0,0 +1,17 @@ + + + + This is a XHTML sample file + + + +
+ Just a simple XHTML test page. +
+ + + diff --git a/samples/HTML/index.html.hl b/samples/HTML/index.html.hl new file mode 100644 index 00000000..65491957 --- /dev/null +++ b/samples/HTML/index.html.hl @@ -0,0 +1,328 @@ + + + + + + + + +
+

Example 1

+ + + + + +
+ + +
+ +

~{x}

+
+
+
+
+ + +
+

Example 2

+ + + + + +
+ + +
+ +

~{x}

+
+
+
+
+ + +
+

Example 3

+ + + + + +
+ + + +
+ +

~{x}

+
+
+
+
+ + +
+

Example 4

+ + + + + +
+ + +
+
+
+ + +
+

Example 5

+ + + + + +
+ + +
+
+
+ + +
+

Example 6

+ + + + + +
+ + +
+
+ +

~{x}

+
+
+
+
+
+ + +
+

Example 7

+ + + + + +
+ + +
+
+ +

~{x}

+
+
+
+
+
+ + +
+

Example 8

+ + + + + +
+ + +
+
+ +

~{x}

+
+
+
+
+
+ + +
+

Example 9

+ + + + + +
+ + +
+
+ + +
+

Example 10

+ + + + + +
+ + + +
+
+ + diff --git a/samples/Hack/Assert.hh b/samples/Hack/Assert.hh new file mode 100644 index 00000000..c80fc87a --- /dev/null +++ b/samples/Hack/Assert.hh @@ -0,0 +1,55 @@ +( + (function(mixed): T) $fn, + mixed $x, + ): array { + if (is_array($x)) { + return array_map($fn, $x); + } + throw new AssertException('Expected an array'); + } +} diff --git a/samples/Hack/AssertRecipe.hh b/samples/Hack/AssertRecipe.hh new file mode 100644 index 00000000..e2f9eabd --- /dev/null +++ b/samples/Hack/AssertRecipe.hh @@ -0,0 +1,52 @@ +> + protected function getDescription(): ?string { + return 'When you have values with unknown types, it is useful to make '. + 'some runtime assertions and have the type checker understand. This '. + 'recipe demonstrates one approach.'; + } + + protected function getFilenames(): Vector { + return Vector { + 'Assert.php', + }; + } + + protected function getDocs(): Vector<(string, string)> { + return Vector{ + tuple ('Mixed Types', 'hack.annotations.mixedtypes'), + tuple ('Type Inference', 'hack.otherrulesandfeatures.typeinference'), + }; + } + + public function getDemoFilename(): string { + return 'demo.php'; + } + + public function getDemoResult(): string { + return assert_main(); + } + + public function getDemoXHP(): ?:xhp { + return null; + } +} diff --git a/samples/Hack/Controller.hh b/samples/Hack/Controller.hh new file mode 100644 index 00000000..a21aacb2 --- /dev/null +++ b/samples/Hack/Controller.hh @@ -0,0 +1,39 @@ +; + abstract protected function getJS(): Set; + abstract protected function getTitle(): string; + abstract protected function render(): :xhp; + + final protected function getHead(): :xhp { + $css = $this->getCSS()->toVector()->map( + ($css) ==> + ); + $js = $this->getJS()->toVector()->map( + ($js) ==>