gitlab-pygments.rb 0.3.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +6 -0
- data/Gemfile +2 -0
- data/README.md +91 -0
- data/Rakefile +78 -0
- data/bench.rb +22 -0
- data/cache-lexers.rb +8 -0
- data/lexers +0 -0
- data/lib/pygments/lexer.rb +148 -0
- data/lib/pygments/mentos.py +344 -0
- data/lib/pygments/popen.rb +389 -0
- data/lib/pygments/version.rb +3 -0
- data/lib/pygments.rb +8 -0
- data/pygments.rb.gemspec +24 -0
- data/test/test_data.c +2581 -0
- data/test/test_data.py +514 -0
- data/test/test_data_generated +2582 -0
- data/test/test_pygments.rb +276 -0
- data/vendor/custom_formatters/gitlab.py +171 -0
- data/vendor/custom_lexers/github.py +362 -0
- data/vendor/pygments-main/AUTHORS +115 -0
- data/vendor/pygments-main/CHANGES +762 -0
- data/vendor/pygments-main/LICENSE +25 -0
- data/vendor/pygments-main/MANIFEST.in +6 -0
- data/vendor/pygments-main/Makefile +59 -0
- data/vendor/pygments-main/REVISION +1 -0
- data/vendor/pygments-main/TODO +15 -0
- data/vendor/pygments-main/docs/generate.py +472 -0
- data/vendor/pygments-main/docs/pygmentize.1 +94 -0
- data/vendor/pygments-main/docs/src/api.txt +270 -0
- data/vendor/pygments-main/docs/src/authors.txt +5 -0
- data/vendor/pygments-main/docs/src/changelog.txt +5 -0
- data/vendor/pygments-main/docs/src/cmdline.txt +147 -0
- data/vendor/pygments-main/docs/src/filterdevelopment.txt +70 -0
- data/vendor/pygments-main/docs/src/filters.txt +42 -0
- data/vendor/pygments-main/docs/src/formatterdevelopment.txt +169 -0
- data/vendor/pygments-main/docs/src/formatters.txt +48 -0
- data/vendor/pygments-main/docs/src/index.txt +69 -0
- data/vendor/pygments-main/docs/src/installation.txt +71 -0
- data/vendor/pygments-main/docs/src/integrate.txt +43 -0
- data/vendor/pygments-main/docs/src/lexerdevelopment.txt +551 -0
- data/vendor/pygments-main/docs/src/lexers.txt +67 -0
- data/vendor/pygments-main/docs/src/moinmoin.txt +39 -0
- data/vendor/pygments-main/docs/src/plugins.txt +93 -0
- data/vendor/pygments-main/docs/src/quickstart.txt +202 -0
- data/vendor/pygments-main/docs/src/rstdirective.txt +22 -0
- data/vendor/pygments-main/docs/src/styles.txt +143 -0
- data/vendor/pygments-main/docs/src/tokens.txt +349 -0
- data/vendor/pygments-main/docs/src/unicode.txt +49 -0
- data/vendor/pygments-main/external/markdown-processor.py +67 -0
- data/vendor/pygments-main/external/moin-parser.py +112 -0
- data/vendor/pygments-main/external/pygments.bashcomp +38 -0
- data/vendor/pygments-main/external/rst-directive-old.py +77 -0
- data/vendor/pygments-main/external/rst-directive.py +83 -0
- data/vendor/pygments-main/ez_setup.py +276 -0
- data/vendor/pygments-main/pygmentize +7 -0
- data/vendor/pygments-main/pygments/__init__.py +91 -0
- data/vendor/pygments-main/pygments/cmdline.py +433 -0
- data/vendor/pygments-main/pygments/console.py +74 -0
- data/vendor/pygments-main/pygments/filter.py +74 -0
- data/vendor/pygments-main/pygments/filters/__init__.py +357 -0
- data/vendor/pygments-main/pygments/formatter.py +92 -0
- data/vendor/pygments-main/pygments/formatters/__init__.py +68 -0
- data/vendor/pygments-main/pygments/formatters/_mapping.py +94 -0
- data/vendor/pygments-main/pygments/formatters/bbcode.py +109 -0
- data/vendor/pygments-main/pygments/formatters/gitlab.py +171 -0
- data/vendor/pygments-main/pygments/formatters/html.py +750 -0
- data/vendor/pygments-main/pygments/formatters/img.py +553 -0
- data/vendor/pygments-main/pygments/formatters/latex.py +378 -0
- data/vendor/pygments-main/pygments/formatters/other.py +117 -0
- data/vendor/pygments-main/pygments/formatters/rtf.py +136 -0
- data/vendor/pygments-main/pygments/formatters/svg.py +154 -0
- data/vendor/pygments-main/pygments/formatters/terminal.py +112 -0
- data/vendor/pygments-main/pygments/formatters/terminal256.py +222 -0
- data/vendor/pygments-main/pygments/lexer.py +697 -0
- data/vendor/pygments-main/pygments/lexers/__init__.py +229 -0
- data/vendor/pygments-main/pygments/lexers/_asybuiltins.py +1645 -0
- data/vendor/pygments-main/pygments/lexers/_clbuiltins.py +232 -0
- data/vendor/pygments-main/pygments/lexers/_luabuiltins.py +249 -0
- data/vendor/pygments-main/pygments/lexers/_mapping.py +298 -0
- data/vendor/pygments-main/pygments/lexers/_phpbuiltins.py +3787 -0
- data/vendor/pygments-main/pygments/lexers/_postgres_builtins.py +232 -0
- data/vendor/pygments-main/pygments/lexers/_scilab_builtins.py +29 -0
- data/vendor/pygments-main/pygments/lexers/_vimbuiltins.py +3 -0
- data/vendor/pygments-main/pygments/lexers/agile.py +1803 -0
- data/vendor/pygments-main/pygments/lexers/asm.py +360 -0
- data/vendor/pygments-main/pygments/lexers/compiled.py +2891 -0
- data/vendor/pygments-main/pygments/lexers/dotnet.py +636 -0
- data/vendor/pygments-main/pygments/lexers/functional.py +1832 -0
- data/vendor/pygments-main/pygments/lexers/github.py +362 -0
- data/vendor/pygments-main/pygments/lexers/hdl.py +356 -0
- data/vendor/pygments-main/pygments/lexers/jvm.py +847 -0
- data/vendor/pygments-main/pygments/lexers/math.py +1072 -0
- data/vendor/pygments-main/pygments/lexers/other.py +3339 -0
- data/vendor/pygments-main/pygments/lexers/parsers.py +695 -0
- data/vendor/pygments-main/pygments/lexers/shell.py +361 -0
- data/vendor/pygments-main/pygments/lexers/special.py +100 -0
- data/vendor/pygments-main/pygments/lexers/sql.py +559 -0
- data/vendor/pygments-main/pygments/lexers/templates.py +1631 -0
- data/vendor/pygments-main/pygments/lexers/text.py +1753 -0
- data/vendor/pygments-main/pygments/lexers/web.py +2864 -0
- data/vendor/pygments-main/pygments/plugin.py +74 -0
- data/vendor/pygments-main/pygments/scanner.py +104 -0
- data/vendor/pygments-main/pygments/style.py +117 -0
- data/vendor/pygments-main/pygments/styles/__init__.py +70 -0
- data/vendor/pygments-main/pygments/styles/autumn.py +65 -0
- data/vendor/pygments-main/pygments/styles/borland.py +51 -0
- data/vendor/pygments-main/pygments/styles/bw.py +49 -0
- data/vendor/pygments-main/pygments/styles/colorful.py +81 -0
- data/vendor/pygments-main/pygments/styles/default.py +73 -0
- data/vendor/pygments-main/pygments/styles/emacs.py +72 -0
- data/vendor/pygments-main/pygments/styles/friendly.py +72 -0
- data/vendor/pygments-main/pygments/styles/fruity.py +42 -0
- data/vendor/pygments-main/pygments/styles/manni.py +75 -0
- data/vendor/pygments-main/pygments/styles/monokai.py +106 -0
- data/vendor/pygments-main/pygments/styles/murphy.py +80 -0
- data/vendor/pygments-main/pygments/styles/native.py +65 -0
- data/vendor/pygments-main/pygments/styles/pastie.py +75 -0
- data/vendor/pygments-main/pygments/styles/perldoc.py +69 -0
- data/vendor/pygments-main/pygments/styles/rrt.py +33 -0
- data/vendor/pygments-main/pygments/styles/tango.py +141 -0
- data/vendor/pygments-main/pygments/styles/trac.py +63 -0
- data/vendor/pygments-main/pygments/styles/vim.py +63 -0
- data/vendor/pygments-main/pygments/styles/vs.py +38 -0
- data/vendor/pygments-main/pygments/token.py +195 -0
- data/vendor/pygments-main/pygments/unistring.py +130 -0
- data/vendor/pygments-main/pygments/util.py +232 -0
- data/vendor/pygments-main/scripts/check_sources.py +242 -0
- data/vendor/pygments-main/scripts/detect_missing_analyse_text.py +30 -0
- data/vendor/pygments-main/scripts/epydoc.css +280 -0
- data/vendor/pygments-main/scripts/find_codetags.py +205 -0
- data/vendor/pygments-main/scripts/find_error.py +171 -0
- data/vendor/pygments-main/scripts/get_vimkw.py +43 -0
- data/vendor/pygments-main/scripts/pylintrc +301 -0
- data/vendor/pygments-main/scripts/reindent.py +291 -0
- data/vendor/pygments-main/scripts/vim2pygments.py +933 -0
- data/vendor/pygments-main/setup.cfg +6 -0
- data/vendor/pygments-main/setup.py +88 -0
- data/vendor/pygments-main/tests/dtds/HTML4-f.dtd +37 -0
- data/vendor/pygments-main/tests/dtds/HTML4-s.dtd +869 -0
- data/vendor/pygments-main/tests/dtds/HTML4.dcl +88 -0
- data/vendor/pygments-main/tests/dtds/HTML4.dtd +1092 -0
- data/vendor/pygments-main/tests/dtds/HTML4.soc +9 -0
- data/vendor/pygments-main/tests/dtds/HTMLlat1.ent +195 -0
- data/vendor/pygments-main/tests/dtds/HTMLspec.ent +77 -0
- data/vendor/pygments-main/tests/dtds/HTMLsym.ent +241 -0
- data/vendor/pygments-main/tests/examplefiles/ANTLRv3.g +608 -0
- data/vendor/pygments-main/tests/examplefiles/AcidStateAdvanced.hs +209 -0
- data/vendor/pygments-main/tests/examplefiles/AlternatingGroup.mu +102 -0
- data/vendor/pygments-main/tests/examplefiles/CPDictionary.j +611 -0
- data/vendor/pygments-main/tests/examplefiles/Constants.mo +158 -0
- data/vendor/pygments-main/tests/examplefiles/DancingSudoku.lhs +411 -0
- data/vendor/pygments-main/tests/examplefiles/Errors.scala +18 -0
- data/vendor/pygments-main/tests/examplefiles/File.hy +174 -0
- data/vendor/pygments-main/tests/examplefiles/Intro.java +1660 -0
- data/vendor/pygments-main/tests/examplefiles/Makefile +1131 -0
- data/vendor/pygments-main/tests/examplefiles/Object.st +4394 -0
- data/vendor/pygments-main/tests/examplefiles/OrderedMap.hx +584 -0
- data/vendor/pygments-main/tests/examplefiles/SmallCheck.hs +378 -0
- data/vendor/pygments-main/tests/examplefiles/Sorting.mod +470 -0
- data/vendor/pygments-main/tests/examplefiles/Sudoku.lhs +382 -0
- data/vendor/pygments-main/tests/examplefiles/addressbook.proto +30 -0
- data/vendor/pygments-main/tests/examplefiles/antlr_throws +1 -0
- data/vendor/pygments-main/tests/examplefiles/apache2.conf +393 -0
- data/vendor/pygments-main/tests/examplefiles/as3_test.as +143 -0
- data/vendor/pygments-main/tests/examplefiles/as3_test2.as +46 -0
- data/vendor/pygments-main/tests/examplefiles/as3_test3.as +3 -0
- data/vendor/pygments-main/tests/examplefiles/aspx-cs_example +27 -0
- data/vendor/pygments-main/tests/examplefiles/badcase.java +2 -0
- data/vendor/pygments-main/tests/examplefiles/batchfile.bat +49 -0
- data/vendor/pygments-main/tests/examplefiles/boot-9.scm +1557 -0
- data/vendor/pygments-main/tests/examplefiles/cells.ps +515 -0
- data/vendor/pygments-main/tests/examplefiles/ceval.c +2604 -0
- data/vendor/pygments-main/tests/examplefiles/cheetah_example.html +13 -0
- data/vendor/pygments-main/tests/examplefiles/classes.dylan +40 -0
- data/vendor/pygments-main/tests/examplefiles/condensed_ruby.rb +10 -0
- data/vendor/pygments-main/tests/examplefiles/coq_RelationClasses +447 -0
- data/vendor/pygments-main/tests/examplefiles/database.pytb +20 -0
- data/vendor/pygments-main/tests/examplefiles/de.MoinMoin.po +2461 -0
- data/vendor/pygments-main/tests/examplefiles/demo.ahk +181 -0
- data/vendor/pygments-main/tests/examplefiles/demo.cfm +38 -0
- data/vendor/pygments-main/tests/examplefiles/django_sample.html+django +68 -0
- data/vendor/pygments-main/tests/examplefiles/dwarf.cw +17 -0
- data/vendor/pygments-main/tests/examplefiles/erl_session +10 -0
- data/vendor/pygments-main/tests/examplefiles/escape_semicolon.clj +1 -0
- data/vendor/pygments-main/tests/examplefiles/evil_regex.js +48 -0
- data/vendor/pygments-main/tests/examplefiles/example.c +2080 -0
- data/vendor/pygments-main/tests/examplefiles/example.cls +15 -0
- data/vendor/pygments-main/tests/examplefiles/example.cpp +2363 -0
- data/vendor/pygments-main/tests/examplefiles/example.gs +106 -0
- data/vendor/pygments-main/tests/examplefiles/example.gst +7 -0
- data/vendor/pygments-main/tests/examplefiles/example.kt +47 -0
- data/vendor/pygments-main/tests/examplefiles/example.lua +250 -0
- data/vendor/pygments-main/tests/examplefiles/example.moo +26 -0
- data/vendor/pygments-main/tests/examplefiles/example.moon +629 -0
- data/vendor/pygments-main/tests/examplefiles/example.nim +1010 -0
- data/vendor/pygments-main/tests/examplefiles/example.ns2 +69 -0
- data/vendor/pygments-main/tests/examplefiles/example.p +34 -0
- data/vendor/pygments-main/tests/examplefiles/example.pas +2708 -0
- data/vendor/pygments-main/tests/examplefiles/example.rb +1852 -0
- data/vendor/pygments-main/tests/examplefiles/example.rhtml +561 -0
- data/vendor/pygments-main/tests/examplefiles/example.sh-session +19 -0
- data/vendor/pygments-main/tests/examplefiles/example.sml +156 -0
- data/vendor/pygments-main/tests/examplefiles/example.snobol +15 -0
- data/vendor/pygments-main/tests/examplefiles/example.tea +34 -0
- data/vendor/pygments-main/tests/examplefiles/example.u +548 -0
- data/vendor/pygments-main/tests/examplefiles/example.weechatlog +9 -0
- data/vendor/pygments-main/tests/examplefiles/example.xhtml +376 -0
- data/vendor/pygments-main/tests/examplefiles/example.yaml +302 -0
- data/vendor/pygments-main/tests/examplefiles/example2.aspx +29 -0
- data/vendor/pygments-main/tests/examplefiles/example_elixir.ex +363 -0
- data/vendor/pygments-main/tests/examplefiles/example_file.fy +128 -0
- data/vendor/pygments-main/tests/examplefiles/firefox.mak +586 -0
- data/vendor/pygments-main/tests/examplefiles/flipflop.sv +19 -0
- data/vendor/pygments-main/tests/examplefiles/foo.sce +6 -0
- data/vendor/pygments-main/tests/examplefiles/format.ml +1213 -0
- data/vendor/pygments-main/tests/examplefiles/fucked_up.rb +77 -0
- data/vendor/pygments-main/tests/examplefiles/function.mu +1 -0
- data/vendor/pygments-main/tests/examplefiles/functional.rst +1472 -0
- data/vendor/pygments-main/tests/examplefiles/genclass.clj +510 -0
- data/vendor/pygments-main/tests/examplefiles/genshi_example.xml+genshi +193 -0
- data/vendor/pygments-main/tests/examplefiles/genshitext_example.genshitext +33 -0
- data/vendor/pygments-main/tests/examplefiles/glsl.frag +7 -0
- data/vendor/pygments-main/tests/examplefiles/glsl.vert +13 -0
- data/vendor/pygments-main/tests/examplefiles/html+php_faulty.php +1 -0
- data/vendor/pygments-main/tests/examplefiles/http_request_example +14 -0
- data/vendor/pygments-main/tests/examplefiles/http_response_example +27 -0
- data/vendor/pygments-main/tests/examplefiles/import.hs +4 -0
- data/vendor/pygments-main/tests/examplefiles/intro.ik +24 -0
- data/vendor/pygments-main/tests/examplefiles/ints.php +10 -0
- data/vendor/pygments-main/tests/examplefiles/intsyn.fun +675 -0
- data/vendor/pygments-main/tests/examplefiles/intsyn.sig +286 -0
- data/vendor/pygments-main/tests/examplefiles/irb_heredoc +8 -0
- data/vendor/pygments-main/tests/examplefiles/irc.lsp +214 -0
- data/vendor/pygments-main/tests/examplefiles/java.properties +16 -0
- data/vendor/pygments-main/tests/examplefiles/jbst_example1.jbst +28 -0
- data/vendor/pygments-main/tests/examplefiles/jbst_example2.jbst +45 -0
- data/vendor/pygments-main/tests/examplefiles/jinjadesignerdoc.rst +713 -0
- data/vendor/pygments-main/tests/examplefiles/lighttpd_config.conf +13 -0
- data/vendor/pygments-main/tests/examplefiles/linecontinuation.py +47 -0
- data/vendor/pygments-main/tests/examplefiles/ltmain.sh +2849 -0
- data/vendor/pygments-main/tests/examplefiles/main.cmake +42 -0
- data/vendor/pygments-main/tests/examplefiles/markdown.lsp +679 -0
- data/vendor/pygments-main/tests/examplefiles/matlab_noreturn +3 -0
- data/vendor/pygments-main/tests/examplefiles/matlab_sample +27 -0
- data/vendor/pygments-main/tests/examplefiles/matlabsession_sample.txt +37 -0
- data/vendor/pygments-main/tests/examplefiles/minimal.ns2 +4 -0
- data/vendor/pygments-main/tests/examplefiles/moin_SyntaxReference.txt +340 -0
- data/vendor/pygments-main/tests/examplefiles/multiline_regexes.rb +38 -0
- data/vendor/pygments-main/tests/examplefiles/nasm_aoutso.asm +96 -0
- data/vendor/pygments-main/tests/examplefiles/nasm_objexe.asm +30 -0
- data/vendor/pygments-main/tests/examplefiles/nemerle_sample.n +87 -0
- data/vendor/pygments-main/tests/examplefiles/nginx_nginx.conf +118 -0
- data/vendor/pygments-main/tests/examplefiles/numbers.c +12 -0
- data/vendor/pygments-main/tests/examplefiles/objc_example.m +25 -0
- data/vendor/pygments-main/tests/examplefiles/objc_example2.m +24 -0
- data/vendor/pygments-main/tests/examplefiles/perl_misc +62 -0
- data/vendor/pygments-main/tests/examplefiles/perl_perl5db +998 -0
- data/vendor/pygments-main/tests/examplefiles/perl_regex-delims +120 -0
- data/vendor/pygments-main/tests/examplefiles/perlfunc.1 +856 -0
- data/vendor/pygments-main/tests/examplefiles/phpcomplete.vim +567 -0
- data/vendor/pygments-main/tests/examplefiles/pleac.in.rb +1223 -0
- data/vendor/pygments-main/tests/examplefiles/postgresql_test.txt +47 -0
- data/vendor/pygments-main/tests/examplefiles/pppoe.applescript +10 -0
- data/vendor/pygments-main/tests/examplefiles/psql_session.txt +122 -0
- data/vendor/pygments-main/tests/examplefiles/py3_test.txt +2 -0
- data/vendor/pygments-main/tests/examplefiles/pycon_test.pycon +14 -0
- data/vendor/pygments-main/tests/examplefiles/pytb_test2.pytb +2 -0
- data/vendor/pygments-main/tests/examplefiles/python25-bsd.mak +234 -0
- data/vendor/pygments-main/tests/examplefiles/qsort.prolog +13 -0
- data/vendor/pygments-main/tests/examplefiles/r-console-transcript.Rout +38 -0
- data/vendor/pygments-main/tests/examplefiles/ragel-cpp_rlscan +280 -0
- data/vendor/pygments-main/tests/examplefiles/ragel-cpp_snippet +2 -0
- data/vendor/pygments-main/tests/examplefiles/regex.js +22 -0
- data/vendor/pygments-main/tests/examplefiles/reversi.lsp +427 -0
- data/vendor/pygments-main/tests/examplefiles/ruby_func_def.rb +11 -0
- data/vendor/pygments-main/tests/examplefiles/scilab.sci +30 -0
- data/vendor/pygments-main/tests/examplefiles/sibling.prolog +19 -0
- data/vendor/pygments-main/tests/examplefiles/simple.md +747 -0
- data/vendor/pygments-main/tests/examplefiles/smarty_example.html +209 -0
- data/vendor/pygments-main/tests/examplefiles/source.lgt +343 -0
- data/vendor/pygments-main/tests/examplefiles/sources.list +62 -0
- data/vendor/pygments-main/tests/examplefiles/sphere.pov +18 -0
- data/vendor/pygments-main/tests/examplefiles/sqlite3.sqlite3-console +27 -0
- data/vendor/pygments-main/tests/examplefiles/squid.conf +30 -0
- data/vendor/pygments-main/tests/examplefiles/string.jl +1031 -0
- data/vendor/pygments-main/tests/examplefiles/string_delimiters.d +21 -0
- data/vendor/pygments-main/tests/examplefiles/stripheredoc.sh +3 -0
- data/vendor/pygments-main/tests/examplefiles/test.R +119 -0
- data/vendor/pygments-main/tests/examplefiles/test.adb +211 -0
- data/vendor/pygments-main/tests/examplefiles/test.asy +131 -0
- data/vendor/pygments-main/tests/examplefiles/test.awk +121 -0
- data/vendor/pygments-main/tests/examplefiles/test.bas +29 -0
- data/vendor/pygments-main/tests/examplefiles/test.bmx +145 -0
- data/vendor/pygments-main/tests/examplefiles/test.boo +39 -0
- data/vendor/pygments-main/tests/examplefiles/test.bro +250 -0
- data/vendor/pygments-main/tests/examplefiles/test.cs +374 -0
- data/vendor/pygments-main/tests/examplefiles/test.css +54 -0
- data/vendor/pygments-main/tests/examplefiles/test.d +135 -0
- data/vendor/pygments-main/tests/examplefiles/test.dart +23 -0
- data/vendor/pygments-main/tests/examplefiles/test.dtd +89 -0
- data/vendor/pygments-main/tests/examplefiles/test.ec +605 -0
- data/vendor/pygments-main/tests/examplefiles/test.ecl +58 -0
- data/vendor/pygments-main/tests/examplefiles/test.eh +315 -0
- data/vendor/pygments-main/tests/examplefiles/test.erl +169 -0
- data/vendor/pygments-main/tests/examplefiles/test.evoque +33 -0
- data/vendor/pygments-main/tests/examplefiles/test.fan +818 -0
- data/vendor/pygments-main/tests/examplefiles/test.flx +57 -0
- data/vendor/pygments-main/tests/examplefiles/test.gdc +13 -0
- data/vendor/pygments-main/tests/examplefiles/test.groovy +97 -0
- data/vendor/pygments-main/tests/examplefiles/test.html +339 -0
- data/vendor/pygments-main/tests/examplefiles/test.ini +10 -0
- data/vendor/pygments-main/tests/examplefiles/test.java +653 -0
- data/vendor/pygments-main/tests/examplefiles/test.jsp +24 -0
- data/vendor/pygments-main/tests/examplefiles/test.maql +45 -0
- data/vendor/pygments-main/tests/examplefiles/test.mod +374 -0
- data/vendor/pygments-main/tests/examplefiles/test.moo +51 -0
- data/vendor/pygments-main/tests/examplefiles/test.myt +166 -0
- data/vendor/pygments-main/tests/examplefiles/test.nim +93 -0
- data/vendor/pygments-main/tests/examplefiles/test.pas +743 -0
- data/vendor/pygments-main/tests/examplefiles/test.php +505 -0
- data/vendor/pygments-main/tests/examplefiles/test.plot +333 -0
- data/vendor/pygments-main/tests/examplefiles/test.ps1 +108 -0
- data/vendor/pygments-main/tests/examplefiles/test.pypylog +1839 -0
- data/vendor/pygments-main/tests/examplefiles/test.r3 +94 -0
- data/vendor/pygments-main/tests/examplefiles/test.rb +177 -0
- data/vendor/pygments-main/tests/examplefiles/test.rhtml +43 -0
- data/vendor/pygments-main/tests/examplefiles/test.scaml +8 -0
- data/vendor/pygments-main/tests/examplefiles/test.ssp +12 -0
- data/vendor/pygments-main/tests/examplefiles/test.tcsh +830 -0
- data/vendor/pygments-main/tests/examplefiles/test.vb +407 -0
- data/vendor/pygments-main/tests/examplefiles/test.vhdl +161 -0
- data/vendor/pygments-main/tests/examplefiles/test.xqy +138 -0
- data/vendor/pygments-main/tests/examplefiles/test.xsl +23 -0
- data/vendor/pygments-main/tests/examplefiles/truncated.pytb +15 -0
- data/vendor/pygments-main/tests/examplefiles/type.lisp +1202 -0
- data/vendor/pygments-main/tests/examplefiles/underscore.coffee +603 -0
- data/vendor/pygments-main/tests/examplefiles/unicode.applescript +5 -0
- data/vendor/pygments-main/tests/examplefiles/unicodedoc.py +11 -0
- data/vendor/pygments-main/tests/examplefiles/webkit-transition.css +3 -0
- data/vendor/pygments-main/tests/examplefiles/while.pov +13 -0
- data/vendor/pygments-main/tests/examplefiles/wiki.factor +384 -0
- data/vendor/pygments-main/tests/examplefiles/xml_example +1897 -0
- data/vendor/pygments-main/tests/examplefiles/zmlrpc.f90 +798 -0
- data/vendor/pygments-main/tests/old_run.py +138 -0
- data/vendor/pygments-main/tests/run.py +48 -0
- data/vendor/pygments-main/tests/support.py +15 -0
- data/vendor/pygments-main/tests/test_basic_api.py +294 -0
- data/vendor/pygments-main/tests/test_clexer.py +31 -0
- data/vendor/pygments-main/tests/test_cmdline.py +105 -0
- data/vendor/pygments-main/tests/test_examplefiles.py +97 -0
- data/vendor/pygments-main/tests/test_html_formatter.py +162 -0
- data/vendor/pygments-main/tests/test_latex_formatter.py +55 -0
- data/vendor/pygments-main/tests/test_perllexer.py +137 -0
- data/vendor/pygments-main/tests/test_regexlexer.py +47 -0
- data/vendor/pygments-main/tests/test_token.py +46 -0
- data/vendor/pygments-main/tests/test_using_api.py +40 -0
- data/vendor/pygments-main/tests/test_util.py +116 -0
- data/vendor/simplejson/.gitignore +10 -0
- data/vendor/simplejson/.travis.yml +5 -0
- data/vendor/simplejson/CHANGES.txt +291 -0
- data/vendor/simplejson/LICENSE.txt +19 -0
- data/vendor/simplejson/MANIFEST.in +5 -0
- data/vendor/simplejson/README.rst +19 -0
- data/vendor/simplejson/conf.py +179 -0
- data/vendor/simplejson/index.rst +628 -0
- data/vendor/simplejson/scripts/make_docs.py +18 -0
- data/vendor/simplejson/setup.py +104 -0
- data/vendor/simplejson/simplejson/__init__.py +510 -0
- data/vendor/simplejson/simplejson/_speedups.c +2745 -0
- data/vendor/simplejson/simplejson/decoder.py +425 -0
- data/vendor/simplejson/simplejson/encoder.py +567 -0
- data/vendor/simplejson/simplejson/ordered_dict.py +119 -0
- data/vendor/simplejson/simplejson/scanner.py +77 -0
- data/vendor/simplejson/simplejson/tests/__init__.py +67 -0
- data/vendor/simplejson/simplejson/tests/test_bigint_as_string.py +55 -0
- data/vendor/simplejson/simplejson/tests/test_check_circular.py +30 -0
- data/vendor/simplejson/simplejson/tests/test_decimal.py +66 -0
- data/vendor/simplejson/simplejson/tests/test_decode.py +83 -0
- data/vendor/simplejson/simplejson/tests/test_default.py +9 -0
- data/vendor/simplejson/simplejson/tests/test_dump.py +67 -0
- data/vendor/simplejson/simplejson/tests/test_encode_basestring_ascii.py +46 -0
- data/vendor/simplejson/simplejson/tests/test_encode_for_html.py +32 -0
- data/vendor/simplejson/simplejson/tests/test_errors.py +34 -0
- data/vendor/simplejson/simplejson/tests/test_fail.py +91 -0
- data/vendor/simplejson/simplejson/tests/test_float.py +19 -0
- data/vendor/simplejson/simplejson/tests/test_indent.py +86 -0
- data/vendor/simplejson/simplejson/tests/test_item_sort_key.py +20 -0
- data/vendor/simplejson/simplejson/tests/test_namedtuple.py +121 -0
- data/vendor/simplejson/simplejson/tests/test_pass1.py +76 -0
- data/vendor/simplejson/simplejson/tests/test_pass2.py +14 -0
- data/vendor/simplejson/simplejson/tests/test_pass3.py +20 -0
- data/vendor/simplejson/simplejson/tests/test_recursion.py +67 -0
- data/vendor/simplejson/simplejson/tests/test_scanstring.py +117 -0
- data/vendor/simplejson/simplejson/tests/test_separators.py +42 -0
- data/vendor/simplejson/simplejson/tests/test_speedups.py +20 -0
- data/vendor/simplejson/simplejson/tests/test_tuple.py +49 -0
- data/vendor/simplejson/simplejson/tests/test_unicode.py +109 -0
- data/vendor/simplejson/simplejson/tool.py +39 -0
- metadata +492 -0
@@ -0,0 +1,510 @@
|
|
1
|
+
; Copyright (c) Rich Hickey. All rights reserved.
|
2
|
+
; The use and distribution terms for this software are covered by the
|
3
|
+
; Common Public License 1.0 (http://opensource.org/licenses/cpl.php)
|
4
|
+
; which can be found in the file CPL.TXT at the root of this distribution.
|
5
|
+
; By using this software in any fashion, you are agreeing to be bound by
|
6
|
+
; the terms of this license.
|
7
|
+
; You must not remove this notice, or any other, from this software.
|
8
|
+
|
9
|
+
(in-ns 'clojure)
|
10
|
+
|
11
|
+
(import '(java.lang.reflect Modifier Constructor)
|
12
|
+
'(clojure.asm ClassWriter ClassVisitor Opcodes Type)
|
13
|
+
'(clojure.asm.commons Method GeneratorAdapter)
|
14
|
+
'(clojure.lang IPersistentMap))
|
15
|
+
|
16
|
+
;(defn method-sig [#^java.lang.reflect.Method meth]
|
17
|
+
; [(. meth (getName)) (seq (. meth (getParameterTypes)))])
|
18
|
+
|
19
|
+
(defn- non-private-methods [#^Class c]
|
20
|
+
(loop [mm {}
|
21
|
+
considered #{}
|
22
|
+
c c]
|
23
|
+
(if c
|
24
|
+
(let [[mm considered]
|
25
|
+
(loop [mm mm
|
26
|
+
considered considered
|
27
|
+
meths (concat
|
28
|
+
(seq (. c (getDeclaredMethods)))
|
29
|
+
(seq (. c (getMethods))))]
|
30
|
+
(if meths
|
31
|
+
(let [#^Method meth (first meths)
|
32
|
+
mods (. meth (getModifiers))
|
33
|
+
mk (method-sig meth)]
|
34
|
+
(if (or (considered mk)
|
35
|
+
(. Modifier (isPrivate mods))
|
36
|
+
(. Modifier (isStatic mods))
|
37
|
+
(. Modifier (isFinal mods)))
|
38
|
+
(recur mm (conj considered mk) (rest meths))
|
39
|
+
(recur (assoc mm mk meth) (conj considered mk) (rest meths))))
|
40
|
+
[mm considered]))]
|
41
|
+
(recur mm considered (. c (getSuperclass))))
|
42
|
+
mm)))
|
43
|
+
|
44
|
+
(defn- ctor-sigs [super]
|
45
|
+
(for [#^Constructor ctor (. super (getDeclaredConstructors))
|
46
|
+
:when (not (. Modifier (isPrivate (. ctor (getModifiers)))))]
|
47
|
+
(apply vector (. ctor (getParameterTypes)))))
|
48
|
+
|
49
|
+
(defn- escape-class-name [c]
|
50
|
+
(.. (.getSimpleName c)
|
51
|
+
(replace "[]" "<>")))
|
52
|
+
|
53
|
+
(defn- overload-name [mname pclasses]
|
54
|
+
(if (seq pclasses)
|
55
|
+
(apply str mname (interleave (repeat \-)
|
56
|
+
(map escape-class-name pclasses)))
|
57
|
+
(str mname "-void")))
|
58
|
+
|
59
|
+
;(distinct (map first(keys (mapcat non-private-methods [Object IPersistentMap]))))
|
60
|
+
|
61
|
+
(defn gen-class
|
62
|
+
"Generates compiled bytecode for a class with the given
|
63
|
+
package-qualified cname (which, as all names in these parameters, can
|
64
|
+
be a string or symbol). The gen-class construct contains no
|
65
|
+
implementation, as the implementation will be dynamically sought by
|
66
|
+
the generated class in functions in a corresponding Clojure
|
67
|
+
namespace. Given a generated class org.mydomain.MyClass, methods
|
68
|
+
will be implemented that look for same-named functions in a Clojure
|
69
|
+
namespace called org.domain.MyClass. The init and main
|
70
|
+
functions (see below) will be found similarly. The static
|
71
|
+
initializer for the generated class will attempt to load the Clojure
|
72
|
+
support code for the class as a resource from the claspath, e.g. in
|
73
|
+
the example case, org/mydomain/MyClass.clj
|
74
|
+
|
75
|
+
Returns a map containing :name and :bytecode. Most uses will be
|
76
|
+
satisfied by the higher-level gen-and-load-class and
|
77
|
+
gen-and-store-class functions, which generate and immediately load,
|
78
|
+
or generate and store to disk, respectively.
|
79
|
+
|
80
|
+
Options should be a set of key/value pairs, all of which are optional:
|
81
|
+
|
82
|
+
:extends aclass
|
83
|
+
|
84
|
+
Specifies the superclass, the non-private methods of which will be
|
85
|
+
overridden by the class. If not provided, defaults to Object.
|
86
|
+
|
87
|
+
:implements [interface ...]
|
88
|
+
|
89
|
+
One or more interfaces, the methods of which will be implemented by the class.
|
90
|
+
|
91
|
+
:init name
|
92
|
+
|
93
|
+
If supplied, names a function that will be called with the arguments
|
94
|
+
to the constructor. Must return [[superclass-constructor-args] state]
|
95
|
+
If not supplied, the constructor args are passed directly to
|
96
|
+
the superclass constructor and the state will be nil
|
97
|
+
|
98
|
+
:constructors {[param-types] [super-param-types], ...}
|
99
|
+
|
100
|
+
By default, constructors are created for the generated class which
|
101
|
+
match the signature(s) of the constructors for the superclass. This
|
102
|
+
parameter may be used to explicitly specify constructors, each entry
|
103
|
+
providing a mapping from a constructor signature to a superclass
|
104
|
+
constructor signature. When you supply this, you must supply an :init
|
105
|
+
specifier.
|
106
|
+
|
107
|
+
:methods [[name [param-types] return-type], ...]
|
108
|
+
|
109
|
+
The generated class automatically defines all of the non-private
|
110
|
+
methods of its superclasses/interfaces. This parameter can be used
|
111
|
+
to specify the signatures of additional methods of the generated
|
112
|
+
class. Do not repeat superclass/interface signatures here.
|
113
|
+
|
114
|
+
:main boolean
|
115
|
+
|
116
|
+
If supplied and true, a static public main function will be
|
117
|
+
generated. It will pass each string of the String[] argument as a
|
118
|
+
separate argument to a function called 'main.
|
119
|
+
|
120
|
+
:factory name
|
121
|
+
|
122
|
+
If supplied, a (set of) public static factory function(s) will be
|
123
|
+
created with the given name, and the same signature(s) as the
|
124
|
+
constructor(s).
|
125
|
+
|
126
|
+
:state name
|
127
|
+
|
128
|
+
If supplied, a public final instance field with the given name will be
|
129
|
+
created. You must supply an :init function in order to provide a
|
130
|
+
value for the state. Note that, though final, the state can be a ref
|
131
|
+
or agent, supporting the creation of Java objects with transactional
|
132
|
+
or asynchronous mutation semantics.
|
133
|
+
|
134
|
+
:exposes {protected-field-name {:get name :set name}, ...}
|
135
|
+
|
136
|
+
Since the implementations of the methods of the generated class
|
137
|
+
occur in Clojure functions, they have no access to the inherited
|
138
|
+
protected fields of the superclass. This parameter can be used to
|
139
|
+
generate public getter/setter methods exposing the protected field(s)
|
140
|
+
for use in the implementation."
|
141
|
+
|
142
|
+
[cname & options]
|
143
|
+
(let [name (str cname)
|
144
|
+
{:keys [extends implements constructors methods main factory state init exposes]} (apply hash-map options)
|
145
|
+
super (or extends Object)
|
146
|
+
interfaces implements
|
147
|
+
supers (cons super (seq interfaces))
|
148
|
+
ctor-sig-map (or constructors (zipmap (ctor-sigs super) (ctor-sigs super)))
|
149
|
+
cv (new ClassWriter (. ClassWriter COMPUTE_MAXS))
|
150
|
+
cname (. name (replace "." "/"))
|
151
|
+
ctype (. Type (getObjectType cname))
|
152
|
+
iname (fn [c] (.. Type (getType c) (getInternalName)))
|
153
|
+
totype (fn [c] (. Type (getType c)))
|
154
|
+
to-types (fn [cs] (if (pos? (count cs))
|
155
|
+
(into-array (map totype cs))
|
156
|
+
(make-array Type 0)))
|
157
|
+
obj-type (totype Object)
|
158
|
+
arg-types (fn [n] (if (pos? n)
|
159
|
+
(into-array (replicate n obj-type))
|
160
|
+
(make-array Type 0)))
|
161
|
+
super-type (totype super)
|
162
|
+
init-name (str init)
|
163
|
+
factory-name (str factory)
|
164
|
+
state-name (str state)
|
165
|
+
main-name "main"
|
166
|
+
var-name (fn [s] (str s "__var"))
|
167
|
+
rt-type (totype clojure.lang.RT)
|
168
|
+
var-type (totype clojure.lang.Var)
|
169
|
+
ifn-type (totype clojure.lang.IFn)
|
170
|
+
iseq-type (totype clojure.lang.ISeq)
|
171
|
+
ex-type (totype java.lang.UnsupportedOperationException)
|
172
|
+
all-sigs (distinct (concat (map #(let[[m p] (key %)] {m [p]}) (mapcat non-private-methods supers))
|
173
|
+
(map (fn [[m p]] {(str m) [p]}) methods)))
|
174
|
+
sigs-by-name (apply merge-with concat {} all-sigs)
|
175
|
+
overloads (into {} (filter (fn [[m s]] (rest s)) sigs-by-name))
|
176
|
+
var-fields (concat (and init [init-name])
|
177
|
+
(and main [main-name])
|
178
|
+
(distinct (concat (keys sigs-by-name)
|
179
|
+
(mapcat (fn [[m s]] (map #(overload-name m %) s)) overloads)
|
180
|
+
(mapcat (comp (partial map str) vals val) exposes))))
|
181
|
+
emit-get-var (fn [gen v]
|
182
|
+
(let [false-label (. gen newLabel)
|
183
|
+
end-label (. gen newLabel)]
|
184
|
+
(. gen getStatic ctype (var-name v) var-type)
|
185
|
+
(. gen dup)
|
186
|
+
(. gen invokeVirtual var-type (. Method (getMethod "boolean isBound()")))
|
187
|
+
(. gen ifZCmp (. GeneratorAdapter EQ) false-label)
|
188
|
+
(. gen invokeVirtual var-type (. Method (getMethod "Object get()")))
|
189
|
+
(. gen goTo end-label)
|
190
|
+
(. gen mark false-label)
|
191
|
+
(. gen pop)
|
192
|
+
(. gen visitInsn (. Opcodes ACONST_NULL))
|
193
|
+
(. gen mark end-label)))
|
194
|
+
emit-forwarding-method
|
195
|
+
(fn [mname pclasses rclass else-gen]
|
196
|
+
(let [ptypes (to-types pclasses)
|
197
|
+
rtype (totype rclass)
|
198
|
+
m (new Method mname rtype ptypes)
|
199
|
+
is-overload (overloads mname)
|
200
|
+
gen (new GeneratorAdapter (. Opcodes ACC_PUBLIC) m nil nil cv)
|
201
|
+
found-label (. gen (newLabel))
|
202
|
+
else-label (. gen (newLabel))
|
203
|
+
end-label (. gen (newLabel))]
|
204
|
+
(. gen (visitCode))
|
205
|
+
(when is-overload
|
206
|
+
(emit-get-var gen (overload-name mname pclasses))
|
207
|
+
(. gen (dup))
|
208
|
+
(. gen (ifNonNull found-label))
|
209
|
+
(. gen (pop)))
|
210
|
+
(emit-get-var gen mname)
|
211
|
+
(. gen (dup))
|
212
|
+
(. gen (ifNull else-label))
|
213
|
+
(when is-overload
|
214
|
+
(. gen (mark found-label)))
|
215
|
+
;if found
|
216
|
+
(. gen (loadThis))
|
217
|
+
;box args
|
218
|
+
(dotimes i (count ptypes)
|
219
|
+
(. gen (loadArg i))
|
220
|
+
(. clojure.lang.Compiler$HostExpr (emitBoxReturn nil gen (nth pclasses i))))
|
221
|
+
;call fn
|
222
|
+
(. gen (invokeInterface ifn-type (new Method "invoke" obj-type
|
223
|
+
(into-array (cons obj-type
|
224
|
+
(replicate (count ptypes) obj-type))))))
|
225
|
+
;unbox return
|
226
|
+
(. gen (unbox rtype))
|
227
|
+
(when (= (. rtype (getSort)) (. Type VOID))
|
228
|
+
(. gen (pop)))
|
229
|
+
(. gen (goTo end-label))
|
230
|
+
|
231
|
+
;else call supplied alternative generator
|
232
|
+
(. gen (mark else-label))
|
233
|
+
(. gen (pop))
|
234
|
+
|
235
|
+
(else-gen gen m)
|
236
|
+
|
237
|
+
(. gen (mark end-label))
|
238
|
+
(. gen (returnValue))
|
239
|
+
(. gen (endMethod))))
|
240
|
+
]
|
241
|
+
;start class definition
|
242
|
+
(. cv (visit (. Opcodes V1_5) (. Opcodes ACC_PUBLIC)
|
243
|
+
cname nil (iname super)
|
244
|
+
(when interfaces
|
245
|
+
(into-array (map iname interfaces)))))
|
246
|
+
|
247
|
+
;static fields for vars
|
248
|
+
(doseq v var-fields
|
249
|
+
(. cv (visitField (+ (. Opcodes ACC_PUBLIC) (. Opcodes ACC_FINAL) (. Opcodes ACC_STATIC))
|
250
|
+
(var-name v)
|
251
|
+
(. var-type getDescriptor)
|
252
|
+
nil nil)))
|
253
|
+
|
254
|
+
;instance field for state
|
255
|
+
(when state
|
256
|
+
(. cv (visitField (+ (. Opcodes ACC_PUBLIC) (. Opcodes ACC_FINAL))
|
257
|
+
state-name
|
258
|
+
(. obj-type getDescriptor)
|
259
|
+
nil nil)))
|
260
|
+
|
261
|
+
;static init to set up var fields and load clj
|
262
|
+
(let [gen (new GeneratorAdapter (+ (. Opcodes ACC_PUBLIC) (. Opcodes ACC_STATIC))
|
263
|
+
(. Method getMethod "void <clinit> ()")
|
264
|
+
nil nil cv)]
|
265
|
+
(. gen (visitCode))
|
266
|
+
(doseq v var-fields
|
267
|
+
(. gen push name)
|
268
|
+
(. gen push v)
|
269
|
+
(. gen (invokeStatic rt-type (. Method (getMethod "clojure.lang.Var var(String,String)"))))
|
270
|
+
(. gen putStatic ctype (var-name v) var-type))
|
271
|
+
|
272
|
+
(. gen push ctype)
|
273
|
+
(. gen push (str (. name replace \. (. java.io.File separatorChar)) ".clj"))
|
274
|
+
(. gen (invokeStatic rt-type (. Method (getMethod "void loadResourceScript(Class,String)"))))
|
275
|
+
|
276
|
+
(. gen (returnValue))
|
277
|
+
(. gen (endMethod)))
|
278
|
+
|
279
|
+
;ctors
|
280
|
+
(doseq [pclasses super-pclasses] ctor-sig-map
|
281
|
+
(let [ptypes (to-types pclasses)
|
282
|
+
super-ptypes (to-types super-pclasses)
|
283
|
+
m (new Method "<init>" (. Type VOID_TYPE) ptypes)
|
284
|
+
super-m (new Method "<init>" (. Type VOID_TYPE) super-ptypes)
|
285
|
+
gen (new GeneratorAdapter (. Opcodes ACC_PUBLIC) m nil nil cv)
|
286
|
+
no-init-label (. gen newLabel)
|
287
|
+
end-label (. gen newLabel)
|
288
|
+
nth-method (. Method (getMethod "Object nth(Object,int)"))
|
289
|
+
local (. gen newLocal obj-type)]
|
290
|
+
(. gen (visitCode))
|
291
|
+
|
292
|
+
(if init
|
293
|
+
(do
|
294
|
+
(emit-get-var gen init-name)
|
295
|
+
(. gen dup)
|
296
|
+
(. gen ifNull no-init-label)
|
297
|
+
;box init args
|
298
|
+
(dotimes i (count pclasses)
|
299
|
+
(. gen (loadArg i))
|
300
|
+
(. clojure.lang.Compiler$HostExpr (emitBoxReturn nil gen (nth pclasses i))))
|
301
|
+
;call init fn
|
302
|
+
(. gen (invokeInterface ifn-type (new Method "invoke" obj-type
|
303
|
+
(arg-types (count ptypes)))))
|
304
|
+
;expecting [[super-ctor-args] state] returned
|
305
|
+
(. gen dup)
|
306
|
+
(. gen push 0)
|
307
|
+
(. gen (invokeStatic rt-type nth-method))
|
308
|
+
(. gen storeLocal local)
|
309
|
+
|
310
|
+
(. gen (loadThis))
|
311
|
+
(. gen dupX1)
|
312
|
+
(dotimes i (count super-pclasses)
|
313
|
+
(. gen loadLocal local)
|
314
|
+
(. gen push i)
|
315
|
+
(. gen (invokeStatic rt-type nth-method))
|
316
|
+
(. clojure.lang.Compiler$HostExpr (emitUnboxArg nil gen (nth super-pclasses i))))
|
317
|
+
(. gen (invokeConstructor super-type super-m))
|
318
|
+
|
319
|
+
(if state
|
320
|
+
(do
|
321
|
+
(. gen push 1)
|
322
|
+
(. gen (invokeStatic rt-type nth-method))
|
323
|
+
(. gen (putField ctype state-name obj-type)))
|
324
|
+
(. gen pop))
|
325
|
+
|
326
|
+
(. gen goTo end-label)
|
327
|
+
;no init found
|
328
|
+
(. gen mark no-init-label)
|
329
|
+
(. gen (throwException ex-type (str init-name " not defined")))
|
330
|
+
(. gen mark end-label))
|
331
|
+
(if (= pclasses super-pclasses)
|
332
|
+
(do
|
333
|
+
(. gen (loadThis))
|
334
|
+
(. gen (loadArgs))
|
335
|
+
(. gen (invokeConstructor super-type super-m)))
|
336
|
+
(throw (new Exception ":init not specified, but ctor and super ctor args differ"))))
|
337
|
+
|
338
|
+
(. gen (returnValue))
|
339
|
+
(. gen (endMethod))
|
340
|
+
;factory
|
341
|
+
(when factory
|
342
|
+
(let [fm (new Method factory-name ctype ptypes)
|
343
|
+
gen (new GeneratorAdapter (+ (. Opcodes ACC_PUBLIC) (. Opcodes ACC_STATIC))
|
344
|
+
fm nil nil cv)]
|
345
|
+
(. gen (visitCode))
|
346
|
+
(. gen newInstance ctype)
|
347
|
+
(. gen dup)
|
348
|
+
(. gen (loadArgs))
|
349
|
+
(. gen (invokeConstructor ctype m))
|
350
|
+
(. gen (returnValue))
|
351
|
+
(. gen (endMethod))))))
|
352
|
+
|
353
|
+
;add methods matching supers', if no fn -> call super
|
354
|
+
(let [mm (non-private-methods super)]
|
355
|
+
(doseq #^java.lang.reflect.Method meth (vals mm)
|
356
|
+
(emit-forwarding-method (.getName meth) (.getParameterTypes meth) (.getReturnType meth)
|
357
|
+
(fn [gen m]
|
358
|
+
(. gen (loadThis))
|
359
|
+
;push args
|
360
|
+
(. gen (loadArgs))
|
361
|
+
;call super
|
362
|
+
(. gen (visitMethodInsn (. Opcodes INVOKESPECIAL)
|
363
|
+
(. super-type (getInternalName))
|
364
|
+
(. m (getName))
|
365
|
+
(. m (getDescriptor)))))))
|
366
|
+
;add methods matching interfaces', if no fn -> throw
|
367
|
+
(doseq #^Class iface interfaces
|
368
|
+
(doseq #^java.lang.reflect.Method meth (. iface (getMethods))
|
369
|
+
(when-not (contains? mm (method-sig meth))
|
370
|
+
(emit-forwarding-method (.getName meth) (.getParameterTypes meth) (.getReturnType meth)
|
371
|
+
(fn [gen m]
|
372
|
+
(. gen (throwException ex-type (. m (getName)))))))))
|
373
|
+
;extra methods
|
374
|
+
(doseq [mname pclasses rclass :as msig] methods
|
375
|
+
(emit-forwarding-method (str mname) pclasses rclass
|
376
|
+
(fn [gen m]
|
377
|
+
(. gen (throwException ex-type (. m (getName))))))))
|
378
|
+
|
379
|
+
;main
|
380
|
+
(when main
|
381
|
+
(let [m (. Method getMethod "void main (String[])")
|
382
|
+
gen (new GeneratorAdapter (+ (. Opcodes ACC_PUBLIC) (. Opcodes ACC_STATIC))
|
383
|
+
m nil nil cv)
|
384
|
+
no-main-label (. gen newLabel)
|
385
|
+
end-label (. gen newLabel)]
|
386
|
+
(. gen (visitCode))
|
387
|
+
|
388
|
+
(emit-get-var gen main-name)
|
389
|
+
(. gen dup)
|
390
|
+
(. gen ifNull no-main-label)
|
391
|
+
(. gen loadArgs)
|
392
|
+
(. gen (invokeStatic rt-type (. Method (getMethod "clojure.lang.ISeq seq(Object)"))))
|
393
|
+
(. gen (invokeInterface ifn-type (new Method "applyTo" obj-type
|
394
|
+
(into-array [iseq-type]))))
|
395
|
+
(. gen pop)
|
396
|
+
(. gen goTo end-label)
|
397
|
+
;no main found
|
398
|
+
(. gen mark no-main-label)
|
399
|
+
(. gen (throwException ex-type (str main-name " not defined")))
|
400
|
+
(. gen mark end-label)
|
401
|
+
(. gen (returnValue))
|
402
|
+
(. gen (endMethod))))
|
403
|
+
;field exposers
|
404
|
+
(doseq [f {getter :get setter :set}] exposes
|
405
|
+
(let [fld (.getField super (str f))
|
406
|
+
ftype (totype (.getType fld))]
|
407
|
+
(when getter
|
408
|
+
(let [m (new Method (str getter) ftype (to-types []))
|
409
|
+
gen (new GeneratorAdapter (. Opcodes ACC_PUBLIC) m nil nil cv)]
|
410
|
+
(. gen (visitCode))
|
411
|
+
(. gen loadThis)
|
412
|
+
(. gen getField ctype (str f) ftype)
|
413
|
+
(. gen (returnValue))
|
414
|
+
(. gen (endMethod))))
|
415
|
+
(when setter
|
416
|
+
(let [m (new Method (str setter) (. Type VOID_TYPE) (into-array [ftype]))
|
417
|
+
gen (new GeneratorAdapter (. Opcodes ACC_PUBLIC) m nil nil cv)]
|
418
|
+
(. gen (visitCode))
|
419
|
+
(. gen loadThis)
|
420
|
+
(. gen loadArgs)
|
421
|
+
(. gen putField ctype (str f) ftype)
|
422
|
+
(. gen (returnValue))
|
423
|
+
(. gen (endMethod))))))
|
424
|
+
;finish class def
|
425
|
+
(. cv (visitEnd))
|
426
|
+
{:name name :bytecode (. cv (toByteArray))}))
|
427
|
+
|
428
|
+
(defn gen-and-load-class
|
429
|
+
"Generates and immediately loads the bytecode for the specified
|
430
|
+
class. Note that a class generated this way can be loaded only once
|
431
|
+
- the JVM supports only one class with a given name per
|
432
|
+
classloader. Subsequent to generation you can import it into any
|
433
|
+
desired namespaces just like any other class. See gen-class for a
|
434
|
+
description of the options."
|
435
|
+
|
436
|
+
[name & options]
|
437
|
+
(let [{:keys [name bytecode]}
|
438
|
+
(apply gen-class (str name) options)]
|
439
|
+
(.. clojure.lang.RT ROOT_CLASSLOADER (defineClass (str name) bytecode))))
|
440
|
+
|
441
|
+
(defn gen-and-save-class
|
442
|
+
"Generates the bytecode for the named class and stores in a .class
|
443
|
+
file in a subpath of the supplied path, the directories for which
|
444
|
+
must already exist. See gen-class for a description of the options"
|
445
|
+
|
446
|
+
[path name & options]
|
447
|
+
(let [{:keys [name bytecode]} (apply gen-class (str name) options)
|
448
|
+
file (java.io.File. path (str (. name replace \. (. java.io.File separatorChar)) ".class"))]
|
449
|
+
(.createNewFile file)
|
450
|
+
(with-open f (java.io.FileOutputStream. file)
|
451
|
+
(.write f bytecode))))
|
452
|
+
|
453
|
+
(comment
|
454
|
+
;usage
|
455
|
+
(gen-class
|
456
|
+
package-qualified-name
|
457
|
+
;all below are optional
|
458
|
+
:extends aclass
|
459
|
+
:implements [interface ...]
|
460
|
+
:constructors {[param-types] [super-param-types], }
|
461
|
+
:methods [[name [param-types] return-type], ]
|
462
|
+
:main boolean
|
463
|
+
:factory name
|
464
|
+
:state name
|
465
|
+
:init name
|
466
|
+
:exposes {protected-field {:get name :set name}, })
|
467
|
+
|
468
|
+
;(gen-and-load-class
|
469
|
+
(clojure/gen-and-save-class
|
470
|
+
"/Users/rich/Downloads"
|
471
|
+
'fred.lucy.Ethel
|
472
|
+
:extends clojure.lang.Box ;APersistentMap
|
473
|
+
:implements [clojure.lang.IPersistentMap]
|
474
|
+
:state 'state
|
475
|
+
;:constructors {[Object] [Object]}
|
476
|
+
;:init 'init
|
477
|
+
:main true
|
478
|
+
:factory 'create
|
479
|
+
:methods [['foo [Object] Object]
|
480
|
+
['foo [] Object]]
|
481
|
+
:exposes {'val {:get 'getVal :set 'setVal}})
|
482
|
+
|
483
|
+
(in-ns 'fred.lucy.Ethel__2276)
|
484
|
+
(clojure/refer 'clojure :exclude '(assoc seq count cons))
|
485
|
+
(defn init [n] [[] n])
|
486
|
+
(defn foo
|
487
|
+
([this] :foo)
|
488
|
+
([this x] x))
|
489
|
+
(defn main [x y] (println x y))
|
490
|
+
(in-ns 'user)
|
491
|
+
(def ethel (new fred.lucy.Ethel__2276 42))
|
492
|
+
(def ethel (fred.lucy.Ethel__2276.create 21))
|
493
|
+
(fred.lucy.Ethel__2276.main (into-array ["lucy" "ricky"]))
|
494
|
+
(.state ethel)
|
495
|
+
(.foo ethel 7)
|
496
|
+
(.foo ethel)
|
497
|
+
(.getVal ethel)
|
498
|
+
(.setVal ethel 12)
|
499
|
+
|
500
|
+
(gen-class org.clojure.MyComparator :implements [Comparator])
|
501
|
+
(in-ns 'org.clojure.MyComparator)
|
502
|
+
(defn compare [this x y] ...)
|
503
|
+
|
504
|
+
(load-file "/Users/rich/dev/clojure/src/genclass.clj")
|
505
|
+
|
506
|
+
(clojure/gen-and-save-class "/Users/rich/dev/clojure/gen/"
|
507
|
+
'org.clojure.ClojureServlet
|
508
|
+
:extends javax.servlet.http.HttpServlet)
|
509
|
+
|
510
|
+
)
|