pygments.rb-jruby 0.5.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (473) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +6 -0
  3. data/CHANGELOG.md +71 -0
  4. data/Gemfile +2 -0
  5. data/LICENSE +17 -0
  6. data/README.md +118 -0
  7. data/Rakefile +66 -0
  8. data/bench.rb +22 -0
  9. data/cache-lexers.rb +8 -0
  10. data/lexers +0 -0
  11. data/lib/pygments.rb +8 -0
  12. data/lib/pygments/lexer.rb +148 -0
  13. data/lib/pygments/mentos.py +351 -0
  14. data/lib/pygments/popen.rb +404 -0
  15. data/lib/pygments/version.rb +3 -0
  16. data/pygments.rb.gemspec +24 -0
  17. data/test/test_data.c +2581 -0
  18. data/test/test_data.py +514 -0
  19. data/test/test_data_generated +2582 -0
  20. data/test/test_pygments.rb +287 -0
  21. data/vendor/custom_lexers/github.py +565 -0
  22. data/vendor/pygments-main/AUTHORS +153 -0
  23. data/vendor/pygments-main/CHANGES +889 -0
  24. data/vendor/pygments-main/LICENSE +25 -0
  25. data/vendor/pygments-main/MANIFEST.in +6 -0
  26. data/vendor/pygments-main/Makefile +59 -0
  27. data/vendor/pygments-main/REVISION +1 -0
  28. data/vendor/pygments-main/TODO +15 -0
  29. data/vendor/pygments-main/docs/generate.py +472 -0
  30. data/vendor/pygments-main/docs/pygmentize.1 +94 -0
  31. data/vendor/pygments-main/docs/src/api.txt +270 -0
  32. data/vendor/pygments-main/docs/src/authors.txt +5 -0
  33. data/vendor/pygments-main/docs/src/changelog.txt +5 -0
  34. data/vendor/pygments-main/docs/src/cmdline.txt +147 -0
  35. data/vendor/pygments-main/docs/src/filterdevelopment.txt +70 -0
  36. data/vendor/pygments-main/docs/src/filters.txt +42 -0
  37. data/vendor/pygments-main/docs/src/formatterdevelopment.txt +169 -0
  38. data/vendor/pygments-main/docs/src/formatters.txt +48 -0
  39. data/vendor/pygments-main/docs/src/index.txt +69 -0
  40. data/vendor/pygments-main/docs/src/installation.txt +71 -0
  41. data/vendor/pygments-main/docs/src/integrate.txt +48 -0
  42. data/vendor/pygments-main/docs/src/java.txt +70 -0
  43. data/vendor/pygments-main/docs/src/lexerdevelopment.txt +603 -0
  44. data/vendor/pygments-main/docs/src/lexers.txt +67 -0
  45. data/vendor/pygments-main/docs/src/moinmoin.txt +39 -0
  46. data/vendor/pygments-main/docs/src/plugins.txt +93 -0
  47. data/vendor/pygments-main/docs/src/quickstart.txt +202 -0
  48. data/vendor/pygments-main/docs/src/rstdirective.txt +22 -0
  49. data/vendor/pygments-main/docs/src/styles.txt +143 -0
  50. data/vendor/pygments-main/docs/src/tokens.txt +349 -0
  51. data/vendor/pygments-main/docs/src/unicode.txt +49 -0
  52. data/vendor/pygments-main/external/autopygmentize +64 -0
  53. data/vendor/pygments-main/external/lasso-builtins-generator-9.lasso +144 -0
  54. data/vendor/pygments-main/external/markdown-processor.py +67 -0
  55. data/vendor/pygments-main/external/moin-parser.py +112 -0
  56. data/vendor/pygments-main/external/pygments.bashcomp +38 -0
  57. data/vendor/pygments-main/external/rst-directive-old.py +77 -0
  58. data/vendor/pygments-main/external/rst-directive.py +83 -0
  59. data/vendor/pygments-main/ez_setup.py +276 -0
  60. data/vendor/pygments-main/pygmentize +7 -0
  61. data/vendor/pygments-main/pygments/__init__.py +91 -0
  62. data/vendor/pygments-main/pygments/cmdline.py +441 -0
  63. data/vendor/pygments-main/pygments/console.py +74 -0
  64. data/vendor/pygments-main/pygments/filter.py +74 -0
  65. data/vendor/pygments-main/pygments/filters/__init__.py +356 -0
  66. data/vendor/pygments-main/pygments/formatter.py +95 -0
  67. data/vendor/pygments-main/pygments/formatters/__init__.py +68 -0
  68. data/vendor/pygments-main/pygments/formatters/_mapping.py +92 -0
  69. data/vendor/pygments-main/pygments/formatters/bbcode.py +109 -0
  70. data/vendor/pygments-main/pygments/formatters/html.py +821 -0
  71. data/vendor/pygments-main/pygments/formatters/img.py +553 -0
  72. data/vendor/pygments-main/pygments/formatters/latex.py +378 -0
  73. data/vendor/pygments-main/pygments/formatters/other.py +115 -0
  74. data/vendor/pygments-main/pygments/formatters/rtf.py +136 -0
  75. data/vendor/pygments-main/pygments/formatters/svg.py +154 -0
  76. data/vendor/pygments-main/pygments/formatters/terminal.py +112 -0
  77. data/vendor/pygments-main/pygments/formatters/terminal256.py +222 -0
  78. data/vendor/pygments-main/pygments/lexer.py +765 -0
  79. data/vendor/pygments-main/pygments/lexers/__init__.py +240 -0
  80. data/vendor/pygments-main/pygments/lexers/_asybuiltins.py +1645 -0
  81. data/vendor/pygments-main/pygments/lexers/_clbuiltins.py +232 -0
  82. data/vendor/pygments-main/pygments/lexers/_lassobuiltins.py +5172 -0
  83. data/vendor/pygments-main/pygments/lexers/_luabuiltins.py +249 -0
  84. data/vendor/pygments-main/pygments/lexers/_mapping.py +354 -0
  85. data/vendor/pygments-main/pygments/lexers/_openedgebuiltins.py +562 -0
  86. data/vendor/pygments-main/pygments/lexers/_phpbuiltins.py +3787 -0
  87. data/vendor/pygments-main/pygments/lexers/_postgres_builtins.py +233 -0
  88. data/vendor/pygments-main/pygments/lexers/_robotframeworklexer.py +557 -0
  89. data/vendor/pygments-main/pygments/lexers/_scilab_builtins.py +40 -0
  90. data/vendor/pygments-main/pygments/lexers/_sourcemodbuiltins.py +1072 -0
  91. data/vendor/pygments-main/pygments/lexers/_stan_builtins.py +360 -0
  92. data/vendor/pygments-main/pygments/lexers/_vimbuiltins.py +13 -0
  93. data/vendor/pygments-main/pygments/lexers/agile.py +2290 -0
  94. data/vendor/pygments-main/pygments/lexers/asm.py +398 -0
  95. data/vendor/pygments-main/pygments/lexers/compiled.py +3723 -0
  96. data/vendor/pygments-main/pygments/lexers/dalvik.py +104 -0
  97. data/vendor/pygments-main/pygments/lexers/dotnet.py +671 -0
  98. data/vendor/pygments-main/pygments/lexers/foxpro.py +428 -0
  99. data/vendor/pygments-main/pygments/lexers/functional.py +2731 -0
  100. data/vendor/pygments-main/pygments/lexers/github.py +565 -0
  101. data/vendor/pygments-main/pygments/lexers/hdl.py +356 -0
  102. data/vendor/pygments-main/pygments/lexers/jvm.py +1112 -0
  103. data/vendor/pygments-main/pygments/lexers/math.py +1918 -0
  104. data/vendor/pygments-main/pygments/lexers/other.py +3778 -0
  105. data/vendor/pygments-main/pygments/lexers/parsers.py +778 -0
  106. data/vendor/pygments-main/pygments/lexers/shell.py +424 -0
  107. data/vendor/pygments-main/pygments/lexers/special.py +100 -0
  108. data/vendor/pygments-main/pygments/lexers/sql.py +559 -0
  109. data/vendor/pygments-main/pygments/lexers/templates.py +1742 -0
  110. data/vendor/pygments-main/pygments/lexers/text.py +1893 -0
  111. data/vendor/pygments-main/pygments/lexers/web.py +4045 -0
  112. data/vendor/pygments-main/pygments/modeline.py +40 -0
  113. data/vendor/pygments-main/pygments/plugin.py +74 -0
  114. data/vendor/pygments-main/pygments/scanner.py +104 -0
  115. data/vendor/pygments-main/pygments/style.py +117 -0
  116. data/vendor/pygments-main/pygments/styles/__init__.py +70 -0
  117. data/vendor/pygments-main/pygments/styles/autumn.py +65 -0
  118. data/vendor/pygments-main/pygments/styles/borland.py +51 -0
  119. data/vendor/pygments-main/pygments/styles/bw.py +49 -0
  120. data/vendor/pygments-main/pygments/styles/colorful.py +81 -0
  121. data/vendor/pygments-main/pygments/styles/default.py +73 -0
  122. data/vendor/pygments-main/pygments/styles/emacs.py +72 -0
  123. data/vendor/pygments-main/pygments/styles/friendly.py +72 -0
  124. data/vendor/pygments-main/pygments/styles/fruity.py +42 -0
  125. data/vendor/pygments-main/pygments/styles/manni.py +75 -0
  126. data/vendor/pygments-main/pygments/styles/monokai.py +106 -0
  127. data/vendor/pygments-main/pygments/styles/murphy.py +80 -0
  128. data/vendor/pygments-main/pygments/styles/native.py +65 -0
  129. data/vendor/pygments-main/pygments/styles/pastie.py +75 -0
  130. data/vendor/pygments-main/pygments/styles/perldoc.py +69 -0
  131. data/vendor/pygments-main/pygments/styles/rrt.py +33 -0
  132. data/vendor/pygments-main/pygments/styles/tango.py +141 -0
  133. data/vendor/pygments-main/pygments/styles/trac.py +63 -0
  134. data/vendor/pygments-main/pygments/styles/vim.py +63 -0
  135. data/vendor/pygments-main/pygments/styles/vs.py +38 -0
  136. data/vendor/pygments-main/pygments/token.py +195 -0
  137. data/vendor/pygments-main/pygments/unistring.py +140 -0
  138. data/vendor/pygments-main/pygments/util.py +277 -0
  139. data/vendor/pygments-main/scripts/check_sources.py +242 -0
  140. data/vendor/pygments-main/scripts/detect_missing_analyse_text.py +32 -0
  141. data/vendor/pygments-main/scripts/epydoc.css +280 -0
  142. data/vendor/pygments-main/scripts/find_codetags.py +205 -0
  143. data/vendor/pygments-main/scripts/find_error.py +170 -0
  144. data/vendor/pygments-main/scripts/get_vimkw.py +43 -0
  145. data/vendor/pygments-main/scripts/pylintrc +301 -0
  146. data/vendor/pygments-main/scripts/reindent.py +291 -0
  147. data/vendor/pygments-main/scripts/vim2pygments.py +933 -0
  148. data/vendor/pygments-main/setup.cfg +7 -0
  149. data/vendor/pygments-main/setup.py +90 -0
  150. data/vendor/pygments-main/tests/dtds/HTML4-f.dtd +37 -0
  151. data/vendor/pygments-main/tests/dtds/HTML4-s.dtd +869 -0
  152. data/vendor/pygments-main/tests/dtds/HTML4.dcl +88 -0
  153. data/vendor/pygments-main/tests/dtds/HTML4.dtd +1092 -0
  154. data/vendor/pygments-main/tests/dtds/HTML4.soc +9 -0
  155. data/vendor/pygments-main/tests/dtds/HTMLlat1.ent +195 -0
  156. data/vendor/pygments-main/tests/dtds/HTMLspec.ent +77 -0
  157. data/vendor/pygments-main/tests/dtds/HTMLsym.ent +241 -0
  158. data/vendor/pygments-main/tests/examplefiles/ANTLRv3.g +608 -0
  159. data/vendor/pygments-main/tests/examplefiles/AcidStateAdvanced.hs +209 -0
  160. data/vendor/pygments-main/tests/examplefiles/AlternatingGroup.mu +102 -0
  161. data/vendor/pygments-main/tests/examplefiles/BOM.js +1 -0
  162. data/vendor/pygments-main/tests/examplefiles/CPDictionary.j +611 -0
  163. data/vendor/pygments-main/tests/examplefiles/Config.in.cache +1973 -0
  164. data/vendor/pygments-main/tests/examplefiles/Constants.mo +158 -0
  165. data/vendor/pygments-main/tests/examplefiles/DancingSudoku.lhs +411 -0
  166. data/vendor/pygments-main/tests/examplefiles/Deflate.fs +578 -0
  167. data/vendor/pygments-main/tests/examplefiles/Errors.scala +18 -0
  168. data/vendor/pygments-main/tests/examplefiles/File.hy +174 -0
  169. data/vendor/pygments-main/tests/examplefiles/Get-CommandDefinitionHtml.ps1 +66 -0
  170. data/vendor/pygments-main/tests/examplefiles/IPDispatchC.nc +104 -0
  171. data/vendor/pygments-main/tests/examplefiles/IPDispatchP.nc +671 -0
  172. data/vendor/pygments-main/tests/examplefiles/Intro.java +1660 -0
  173. data/vendor/pygments-main/tests/examplefiles/Makefile +1131 -0
  174. data/vendor/pygments-main/tests/examplefiles/Object.st +4394 -0
  175. data/vendor/pygments-main/tests/examplefiles/OrderedMap.hx +584 -0
  176. data/vendor/pygments-main/tests/examplefiles/RoleQ.pm6 +23 -0
  177. data/vendor/pygments-main/tests/examplefiles/SmallCheck.hs +378 -0
  178. data/vendor/pygments-main/tests/examplefiles/Sorting.mod +470 -0
  179. data/vendor/pygments-main/tests/examplefiles/Sudoku.lhs +382 -0
  180. data/vendor/pygments-main/tests/examplefiles/addressbook.proto +30 -0
  181. data/vendor/pygments-main/tests/examplefiles/antlr_throws +1 -0
  182. data/vendor/pygments-main/tests/examplefiles/apache2.conf +393 -0
  183. data/vendor/pygments-main/tests/examplefiles/as3_test.as +143 -0
  184. data/vendor/pygments-main/tests/examplefiles/as3_test2.as +46 -0
  185. data/vendor/pygments-main/tests/examplefiles/as3_test3.as +3 -0
  186. data/vendor/pygments-main/tests/examplefiles/aspx-cs_example +27 -0
  187. data/vendor/pygments-main/tests/examplefiles/autoit_submit.au3 +25 -0
  188. data/vendor/pygments-main/tests/examplefiles/badcase.java +2 -0
  189. data/vendor/pygments-main/tests/examplefiles/batchfile.bat +49 -0
  190. data/vendor/pygments-main/tests/examplefiles/bigtest.nsi +308 -0
  191. data/vendor/pygments-main/tests/examplefiles/boot-9.scm +1557 -0
  192. data/vendor/pygments-main/tests/examplefiles/ca65_example +284 -0
  193. data/vendor/pygments-main/tests/examplefiles/cbmbas_example +9 -0
  194. data/vendor/pygments-main/tests/examplefiles/cells.ps +515 -0
  195. data/vendor/pygments-main/tests/examplefiles/ceval.c +2604 -0
  196. data/vendor/pygments-main/tests/examplefiles/cheetah_example.html +13 -0
  197. data/vendor/pygments-main/tests/examplefiles/classes.dylan +125 -0
  198. data/vendor/pygments-main/tests/examplefiles/condensed_ruby.rb +10 -0
  199. data/vendor/pygments-main/tests/examplefiles/coq_RelationClasses +447 -0
  200. data/vendor/pygments-main/tests/examplefiles/database.pytb +20 -0
  201. data/vendor/pygments-main/tests/examplefiles/de.MoinMoin.po +2461 -0
  202. data/vendor/pygments-main/tests/examplefiles/demo.ahk +181 -0
  203. data/vendor/pygments-main/tests/examplefiles/demo.cfm +38 -0
  204. data/vendor/pygments-main/tests/examplefiles/django_sample.html+django +68 -0
  205. data/vendor/pygments-main/tests/examplefiles/dwarf.cw +17 -0
  206. data/vendor/pygments-main/tests/examplefiles/erl_session +10 -0
  207. data/vendor/pygments-main/tests/examplefiles/escape_semicolon.clj +1 -0
  208. data/vendor/pygments-main/tests/examplefiles/evil_regex.js +48 -0
  209. data/vendor/pygments-main/tests/examplefiles/example.Rd +78 -0
  210. data/vendor/pygments-main/tests/examplefiles/example.bug +54 -0
  211. data/vendor/pygments-main/tests/examplefiles/example.c +2080 -0
  212. data/vendor/pygments-main/tests/examplefiles/example.ceylon +52 -0
  213. data/vendor/pygments-main/tests/examplefiles/example.clay +33 -0
  214. data/vendor/pygments-main/tests/examplefiles/example.cls +15 -0
  215. data/vendor/pygments-main/tests/examplefiles/example.cob +3556 -0
  216. data/vendor/pygments-main/tests/examplefiles/example.cpp +2363 -0
  217. data/vendor/pygments-main/tests/examplefiles/example.gs +106 -0
  218. data/vendor/pygments-main/tests/examplefiles/example.gst +7 -0
  219. data/vendor/pygments-main/tests/examplefiles/example.hx +142 -0
  220. data/vendor/pygments-main/tests/examplefiles/example.jag +48 -0
  221. data/vendor/pygments-main/tests/examplefiles/example.kt +47 -0
  222. data/vendor/pygments-main/tests/examplefiles/example.lagda +19 -0
  223. data/vendor/pygments-main/tests/examplefiles/example.lua +250 -0
  224. data/vendor/pygments-main/tests/examplefiles/example.monkey +152 -0
  225. data/vendor/pygments-main/tests/examplefiles/example.moo +26 -0
  226. data/vendor/pygments-main/tests/examplefiles/example.moon +629 -0
  227. data/vendor/pygments-main/tests/examplefiles/example.msc +43 -0
  228. data/vendor/pygments-main/tests/examplefiles/example.nim +1010 -0
  229. data/vendor/pygments-main/tests/examplefiles/example.ns2 +69 -0
  230. data/vendor/pygments-main/tests/examplefiles/example.p +34 -0
  231. data/vendor/pygments-main/tests/examplefiles/example.pas +2708 -0
  232. data/vendor/pygments-main/tests/examplefiles/example.prg +161 -0
  233. data/vendor/pygments-main/tests/examplefiles/example.rb +1852 -0
  234. data/vendor/pygments-main/tests/examplefiles/example.reg +19 -0
  235. data/vendor/pygments-main/tests/examplefiles/example.rexx +50 -0
  236. data/vendor/pygments-main/tests/examplefiles/example.rhtml +561 -0
  237. data/vendor/pygments-main/tests/examplefiles/example.rkt +95 -0
  238. data/vendor/pygments-main/tests/examplefiles/example.rpf +4 -0
  239. data/vendor/pygments-main/tests/examplefiles/example.sh-session +19 -0
  240. data/vendor/pygments-main/tests/examplefiles/example.shell-session +45 -0
  241. data/vendor/pygments-main/tests/examplefiles/example.sml +156 -0
  242. data/vendor/pygments-main/tests/examplefiles/example.snobol +15 -0
  243. data/vendor/pygments-main/tests/examplefiles/example.stan +108 -0
  244. data/vendor/pygments-main/tests/examplefiles/example.tea +34 -0
  245. data/vendor/pygments-main/tests/examplefiles/example.ts +28 -0
  246. data/vendor/pygments-main/tests/examplefiles/example.u +548 -0
  247. data/vendor/pygments-main/tests/examplefiles/example.weechatlog +9 -0
  248. data/vendor/pygments-main/tests/examplefiles/example.xhtml +376 -0
  249. data/vendor/pygments-main/tests/examplefiles/example.xtend +34 -0
  250. data/vendor/pygments-main/tests/examplefiles/example.yaml +302 -0
  251. data/vendor/pygments-main/tests/examplefiles/example2.aspx +29 -0
  252. data/vendor/pygments-main/tests/examplefiles/example2.msc +79 -0
  253. data/vendor/pygments-main/tests/examplefiles/example_elixir.ex +363 -0
  254. data/vendor/pygments-main/tests/examplefiles/example_file.fy +128 -0
  255. data/vendor/pygments-main/tests/examplefiles/firefox.mak +586 -0
  256. data/vendor/pygments-main/tests/examplefiles/flipflop.sv +19 -0
  257. data/vendor/pygments-main/tests/examplefiles/foo.sce +6 -0
  258. data/vendor/pygments-main/tests/examplefiles/format.ml +1213 -0
  259. data/vendor/pygments-main/tests/examplefiles/fucked_up.rb +77 -0
  260. data/vendor/pygments-main/tests/examplefiles/function.mu +1 -0
  261. data/vendor/pygments-main/tests/examplefiles/functional.rst +1472 -0
  262. data/vendor/pygments-main/tests/examplefiles/garcia-wachs.kk +133 -0
  263. data/vendor/pygments-main/tests/examplefiles/genclass.clj +510 -0
  264. data/vendor/pygments-main/tests/examplefiles/genshi_example.xml+genshi +193 -0
  265. data/vendor/pygments-main/tests/examplefiles/genshitext_example.genshitext +33 -0
  266. data/vendor/pygments-main/tests/examplefiles/glsl.frag +7 -0
  267. data/vendor/pygments-main/tests/examplefiles/glsl.vert +13 -0
  268. data/vendor/pygments-main/tests/examplefiles/grammar-test.p6 +22 -0
  269. data/vendor/pygments-main/tests/examplefiles/hello.smali +40 -0
  270. data/vendor/pygments-main/tests/examplefiles/hello.sp +9 -0
  271. data/vendor/pygments-main/tests/examplefiles/html+php_faulty.php +1 -0
  272. data/vendor/pygments-main/tests/examplefiles/http_request_example +15 -0
  273. data/vendor/pygments-main/tests/examplefiles/http_response_example +29 -0
  274. data/vendor/pygments-main/tests/examplefiles/import.hs +4 -0
  275. data/vendor/pygments-main/tests/examplefiles/inet_pton6.dg +71 -0
  276. data/vendor/pygments-main/tests/examplefiles/intro.ik +24 -0
  277. data/vendor/pygments-main/tests/examplefiles/ints.php +10 -0
  278. data/vendor/pygments-main/tests/examplefiles/intsyn.fun +675 -0
  279. data/vendor/pygments-main/tests/examplefiles/intsyn.sig +286 -0
  280. data/vendor/pygments-main/tests/examplefiles/irb_heredoc +8 -0
  281. data/vendor/pygments-main/tests/examplefiles/irc.lsp +214 -0
  282. data/vendor/pygments-main/tests/examplefiles/java.properties +16 -0
  283. data/vendor/pygments-main/tests/examplefiles/jbst_example1.jbst +28 -0
  284. data/vendor/pygments-main/tests/examplefiles/jbst_example2.jbst +45 -0
  285. data/vendor/pygments-main/tests/examplefiles/jinjadesignerdoc.rst +713 -0
  286. data/vendor/pygments-main/tests/examplefiles/json.lasso +301 -0
  287. data/vendor/pygments-main/tests/examplefiles/json.lasso9 +213 -0
  288. data/vendor/pygments-main/tests/examplefiles/lighttpd_config.conf +13 -0
  289. data/vendor/pygments-main/tests/examplefiles/linecontinuation.py +47 -0
  290. data/vendor/pygments-main/tests/examplefiles/livescript-demo.ls +41 -0
  291. data/vendor/pygments-main/tests/examplefiles/logos_example.xm +28 -0
  292. data/vendor/pygments-main/tests/examplefiles/ltmain.sh +2849 -0
  293. data/vendor/pygments-main/tests/examplefiles/main.cmake +42 -0
  294. data/vendor/pygments-main/tests/examplefiles/markdown.lsp +679 -0
  295. data/vendor/pygments-main/tests/examplefiles/matlab_noreturn +3 -0
  296. data/vendor/pygments-main/tests/examplefiles/matlab_sample +30 -0
  297. data/vendor/pygments-main/tests/examplefiles/matlabsession_sample.txt +37 -0
  298. data/vendor/pygments-main/tests/examplefiles/metagrammar.treetop +455 -0
  299. data/vendor/pygments-main/tests/examplefiles/mg_sample.pro +73 -0
  300. data/vendor/pygments-main/tests/examplefiles/minehunt.qml +112 -0
  301. data/vendor/pygments-main/tests/examplefiles/minimal.ns2 +4 -0
  302. data/vendor/pygments-main/tests/examplefiles/moin_SyntaxReference.txt +340 -0
  303. data/vendor/pygments-main/tests/examplefiles/multiline_regexes.rb +38 -0
  304. data/vendor/pygments-main/tests/examplefiles/nanomsg.intr +95 -0
  305. data/vendor/pygments-main/tests/examplefiles/nasm_aoutso.asm +96 -0
  306. data/vendor/pygments-main/tests/examplefiles/nasm_objexe.asm +30 -0
  307. data/vendor/pygments-main/tests/examplefiles/nemerle_sample.n +87 -0
  308. data/vendor/pygments-main/tests/examplefiles/nginx_nginx.conf +118 -0
  309. data/vendor/pygments-main/tests/examplefiles/numbers.c +12 -0
  310. data/vendor/pygments-main/tests/examplefiles/objc_example.m +32 -0
  311. data/vendor/pygments-main/tests/examplefiles/objc_example2.m +24 -0
  312. data/vendor/pygments-main/tests/examplefiles/perl_misc +62 -0
  313. data/vendor/pygments-main/tests/examplefiles/perl_perl5db +998 -0
  314. data/vendor/pygments-main/tests/examplefiles/perl_regex-delims +120 -0
  315. data/vendor/pygments-main/tests/examplefiles/perlfunc.1 +856 -0
  316. data/vendor/pygments-main/tests/examplefiles/phpMyAdmin.spec +163 -0
  317. data/vendor/pygments-main/tests/examplefiles/phpcomplete.vim +567 -0
  318. data/vendor/pygments-main/tests/examplefiles/pleac.in.rb +1223 -0
  319. data/vendor/pygments-main/tests/examplefiles/postgresql_test.txt +47 -0
  320. data/vendor/pygments-main/tests/examplefiles/pppoe.applescript +10 -0
  321. data/vendor/pygments-main/tests/examplefiles/psql_session.txt +122 -0
  322. data/vendor/pygments-main/tests/examplefiles/py3_test.txt +2 -0
  323. data/vendor/pygments-main/tests/examplefiles/py3tb_test.py3tb +4 -0
  324. data/vendor/pygments-main/tests/examplefiles/pycon_test.pycon +14 -0
  325. data/vendor/pygments-main/tests/examplefiles/pytb_test2.pytb +2 -0
  326. data/vendor/pygments-main/tests/examplefiles/pytb_test3.pytb +4 -0
  327. data/vendor/pygments-main/tests/examplefiles/python25-bsd.mak +234 -0
  328. data/vendor/pygments-main/tests/examplefiles/qsort.prolog +13 -0
  329. data/vendor/pygments-main/tests/examplefiles/r-console-transcript.Rout +38 -0
  330. data/vendor/pygments-main/tests/examplefiles/ragel-cpp_rlscan +280 -0
  331. data/vendor/pygments-main/tests/examplefiles/ragel-cpp_snippet +2 -0
  332. data/vendor/pygments-main/tests/examplefiles/regex.js +22 -0
  333. data/vendor/pygments-main/tests/examplefiles/reversi.lsp +427 -0
  334. data/vendor/pygments-main/tests/examplefiles/robotframework.txt +39 -0
  335. data/vendor/pygments-main/tests/examplefiles/ruby_func_def.rb +11 -0
  336. data/vendor/pygments-main/tests/examplefiles/rust_example.rs +233 -0
  337. data/vendor/pygments-main/tests/examplefiles/scilab.sci +30 -0
  338. data/vendor/pygments-main/tests/examplefiles/session.dylan-console +9 -0
  339. data/vendor/pygments-main/tests/examplefiles/sibling.prolog +19 -0
  340. data/vendor/pygments-main/tests/examplefiles/simple.md +747 -0
  341. data/vendor/pygments-main/tests/examplefiles/smarty_example.html +209 -0
  342. data/vendor/pygments-main/tests/examplefiles/source.lgt +343 -0
  343. data/vendor/pygments-main/tests/examplefiles/sources.list +62 -0
  344. data/vendor/pygments-main/tests/examplefiles/sphere.pov +18 -0
  345. data/vendor/pygments-main/tests/examplefiles/sqlite3.sqlite3-console +27 -0
  346. data/vendor/pygments-main/tests/examplefiles/squid.conf +30 -0
  347. data/vendor/pygments-main/tests/examplefiles/string.jl +1031 -0
  348. data/vendor/pygments-main/tests/examplefiles/string_delimiters.d +21 -0
  349. data/vendor/pygments-main/tests/examplefiles/stripheredoc.sh +3 -0
  350. data/vendor/pygments-main/tests/examplefiles/swig_java.swg +1329 -0
  351. data/vendor/pygments-main/tests/examplefiles/swig_std_vector.i +225 -0
  352. data/vendor/pygments-main/tests/examplefiles/test.R +153 -0
  353. data/vendor/pygments-main/tests/examplefiles/test.adb +211 -0
  354. data/vendor/pygments-main/tests/examplefiles/test.agda +102 -0
  355. data/vendor/pygments-main/tests/examplefiles/test.asy +131 -0
  356. data/vendor/pygments-main/tests/examplefiles/test.awk +121 -0
  357. data/vendor/pygments-main/tests/examplefiles/test.bas +29 -0
  358. data/vendor/pygments-main/tests/examplefiles/test.bb +95 -0
  359. data/vendor/pygments-main/tests/examplefiles/test.bmx +145 -0
  360. data/vendor/pygments-main/tests/examplefiles/test.boo +39 -0
  361. data/vendor/pygments-main/tests/examplefiles/test.bro +250 -0
  362. data/vendor/pygments-main/tests/examplefiles/test.cs +374 -0
  363. data/vendor/pygments-main/tests/examplefiles/test.css +54 -0
  364. data/vendor/pygments-main/tests/examplefiles/test.cu +36 -0
  365. data/vendor/pygments-main/tests/examplefiles/test.d +135 -0
  366. data/vendor/pygments-main/tests/examplefiles/test.dart +23 -0
  367. data/vendor/pygments-main/tests/examplefiles/test.dtd +89 -0
  368. data/vendor/pygments-main/tests/examplefiles/test.ebnf +31 -0
  369. data/vendor/pygments-main/tests/examplefiles/test.ec +605 -0
  370. data/vendor/pygments-main/tests/examplefiles/test.ecl +58 -0
  371. data/vendor/pygments-main/tests/examplefiles/test.eh +315 -0
  372. data/vendor/pygments-main/tests/examplefiles/test.erl +169 -0
  373. data/vendor/pygments-main/tests/examplefiles/test.evoque +33 -0
  374. data/vendor/pygments-main/tests/examplefiles/test.fan +818 -0
  375. data/vendor/pygments-main/tests/examplefiles/test.flx +57 -0
  376. data/vendor/pygments-main/tests/examplefiles/test.gdc +13 -0
  377. data/vendor/pygments-main/tests/examplefiles/test.groovy +97 -0
  378. data/vendor/pygments-main/tests/examplefiles/test.html +339 -0
  379. data/vendor/pygments-main/tests/examplefiles/test.ini +10 -0
  380. data/vendor/pygments-main/tests/examplefiles/test.java +653 -0
  381. data/vendor/pygments-main/tests/examplefiles/test.jsp +24 -0
  382. data/vendor/pygments-main/tests/examplefiles/test.maql +45 -0
  383. data/vendor/pygments-main/tests/examplefiles/test.mod +374 -0
  384. data/vendor/pygments-main/tests/examplefiles/test.moo +51 -0
  385. data/vendor/pygments-main/tests/examplefiles/test.myt +166 -0
  386. data/vendor/pygments-main/tests/examplefiles/test.nim +93 -0
  387. data/vendor/pygments-main/tests/examplefiles/test.opa +10 -0
  388. data/vendor/pygments-main/tests/examplefiles/test.p6 +252 -0
  389. data/vendor/pygments-main/tests/examplefiles/test.pas +743 -0
  390. data/vendor/pygments-main/tests/examplefiles/test.php +505 -0
  391. data/vendor/pygments-main/tests/examplefiles/test.plot +333 -0
  392. data/vendor/pygments-main/tests/examplefiles/test.ps1 +108 -0
  393. data/vendor/pygments-main/tests/examplefiles/test.pypylog +1839 -0
  394. data/vendor/pygments-main/tests/examplefiles/test.r3 +94 -0
  395. data/vendor/pygments-main/tests/examplefiles/test.rb +177 -0
  396. data/vendor/pygments-main/tests/examplefiles/test.rhtml +43 -0
  397. data/vendor/pygments-main/tests/examplefiles/test.scaml +8 -0
  398. data/vendor/pygments-main/tests/examplefiles/test.ssp +12 -0
  399. data/vendor/pygments-main/tests/examplefiles/test.tcsh +830 -0
  400. data/vendor/pygments-main/tests/examplefiles/test.vb +407 -0
  401. data/vendor/pygments-main/tests/examplefiles/test.vhdl +161 -0
  402. data/vendor/pygments-main/tests/examplefiles/test.xqy +138 -0
  403. data/vendor/pygments-main/tests/examplefiles/test.xsl +23 -0
  404. data/vendor/pygments-main/tests/examplefiles/test2.pypylog +120 -0
  405. data/vendor/pygments-main/tests/examplefiles/truncated.pytb +15 -0
  406. data/vendor/pygments-main/tests/examplefiles/type.lisp +1218 -0
  407. data/vendor/pygments-main/tests/examplefiles/underscore.coffee +603 -0
  408. data/vendor/pygments-main/tests/examplefiles/unicode.applescript +5 -0
  409. data/vendor/pygments-main/tests/examplefiles/unicodedoc.py +11 -0
  410. data/vendor/pygments-main/tests/examplefiles/unix-io.lid +37 -0
  411. data/vendor/pygments-main/tests/examplefiles/webkit-transition.css +3 -0
  412. data/vendor/pygments-main/tests/examplefiles/while.pov +13 -0
  413. data/vendor/pygments-main/tests/examplefiles/wiki.factor +384 -0
  414. data/vendor/pygments-main/tests/examplefiles/xml_example +1897 -0
  415. data/vendor/pygments-main/tests/examplefiles/zmlrpc.f90 +798 -0
  416. data/vendor/pygments-main/tests/old_run.py +138 -0
  417. data/vendor/pygments-main/tests/run.py +49 -0
  418. data/vendor/pygments-main/tests/support.py +15 -0
  419. data/vendor/pygments-main/tests/support/tags +36 -0
  420. data/vendor/pygments-main/tests/test_basic_api.py +295 -0
  421. data/vendor/pygments-main/tests/test_clexer.py +31 -0
  422. data/vendor/pygments-main/tests/test_cmdline.py +105 -0
  423. data/vendor/pygments-main/tests/test_examplefiles.py +99 -0
  424. data/vendor/pygments-main/tests/test_html_formatter.py +178 -0
  425. data/vendor/pygments-main/tests/test_latex_formatter.py +55 -0
  426. data/vendor/pygments-main/tests/test_lexers_other.py +68 -0
  427. data/vendor/pygments-main/tests/test_perllexer.py +137 -0
  428. data/vendor/pygments-main/tests/test_regexlexer.py +47 -0
  429. data/vendor/pygments-main/tests/test_token.py +46 -0
  430. data/vendor/pygments-main/tests/test_using_api.py +40 -0
  431. data/vendor/pygments-main/tests/test_util.py +135 -0
  432. data/vendor/simplejson/.gitignore +10 -0
  433. data/vendor/simplejson/.travis.yml +5 -0
  434. data/vendor/simplejson/CHANGES.txt +291 -0
  435. data/vendor/simplejson/LICENSE.txt +19 -0
  436. data/vendor/simplejson/MANIFEST.in +5 -0
  437. data/vendor/simplejson/README.rst +19 -0
  438. data/vendor/simplejson/conf.py +179 -0
  439. data/vendor/simplejson/index.rst +628 -0
  440. data/vendor/simplejson/scripts/make_docs.py +18 -0
  441. data/vendor/simplejson/setup.py +104 -0
  442. data/vendor/simplejson/simplejson/__init__.py +510 -0
  443. data/vendor/simplejson/simplejson/_speedups.c +2745 -0
  444. data/vendor/simplejson/simplejson/decoder.py +425 -0
  445. data/vendor/simplejson/simplejson/encoder.py +567 -0
  446. data/vendor/simplejson/simplejson/ordered_dict.py +119 -0
  447. data/vendor/simplejson/simplejson/scanner.py +77 -0
  448. data/vendor/simplejson/simplejson/tests/__init__.py +67 -0
  449. data/vendor/simplejson/simplejson/tests/test_bigint_as_string.py +55 -0
  450. data/vendor/simplejson/simplejson/tests/test_check_circular.py +30 -0
  451. data/vendor/simplejson/simplejson/tests/test_decimal.py +66 -0
  452. data/vendor/simplejson/simplejson/tests/test_decode.py +83 -0
  453. data/vendor/simplejson/simplejson/tests/test_default.py +9 -0
  454. data/vendor/simplejson/simplejson/tests/test_dump.py +67 -0
  455. data/vendor/simplejson/simplejson/tests/test_encode_basestring_ascii.py +46 -0
  456. data/vendor/simplejson/simplejson/tests/test_encode_for_html.py +32 -0
  457. data/vendor/simplejson/simplejson/tests/test_errors.py +34 -0
  458. data/vendor/simplejson/simplejson/tests/test_fail.py +91 -0
  459. data/vendor/simplejson/simplejson/tests/test_float.py +19 -0
  460. data/vendor/simplejson/simplejson/tests/test_indent.py +86 -0
  461. data/vendor/simplejson/simplejson/tests/test_item_sort_key.py +20 -0
  462. data/vendor/simplejson/simplejson/tests/test_namedtuple.py +121 -0
  463. data/vendor/simplejson/simplejson/tests/test_pass1.py +76 -0
  464. data/vendor/simplejson/simplejson/tests/test_pass2.py +14 -0
  465. data/vendor/simplejson/simplejson/tests/test_pass3.py +20 -0
  466. data/vendor/simplejson/simplejson/tests/test_recursion.py +67 -0
  467. data/vendor/simplejson/simplejson/tests/test_scanstring.py +117 -0
  468. data/vendor/simplejson/simplejson/tests/test_separators.py +42 -0
  469. data/vendor/simplejson/simplejson/tests/test_speedups.py +20 -0
  470. data/vendor/simplejson/simplejson/tests/test_tuple.py +49 -0
  471. data/vendor/simplejson/simplejson/tests/test_unicode.py +109 -0
  472. data/vendor/simplejson/simplejson/tool.py +39 -0
  473. metadata +557 -0
@@ -0,0 +1,1557 @@
1
+ ;;; installed-scm-file
2
+
3
+ ;;;; Copyright (C) 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004 Free Software Foundation, Inc.
4
+ ;;;;
5
+ ;;;; This program is free software; you can redistribute it and/or modify
6
+ ;;;; it under the terms of the GNU General Public License as published by
7
+ ;;;; the Free Software Foundation; either version 2, or (at your option)
8
+ ;;;; any later version.
9
+ ;;;;
10
+ ;;;; This program is distributed in the hope that it will be useful,
11
+ ;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ ;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ ;;;; GNU General Public License for more details.
14
+ ;;;;
15
+ ;;;; You should have received a copy of the GNU General Public License
16
+ ;;;; along with this software; see the file COPYING. If not, write to
17
+ ;;;; the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
18
+ ;;;; Boston, MA 02111-1307 USA
19
+ ;;;;
20
+ ;;;; As a special exception, the Free Software Foundation gives permission
21
+ ;;;; for additional uses of the text contained in its release of GUILE.
22
+ ;;;;
23
+ ;;;; The exception is that, if you link the GUILE library with other files
24
+ ;;;; to produce an executable, this does not by itself cause the
25
+ ;;;; resulting executable to be covered by the GNU General Public License.
26
+ ;;;; Your use of that executable is in no way restricted on account of
27
+ ;;;; linking the GUILE library code into it.
28
+ ;;;;
29
+ ;;;; This exception does not however invalidate any other reasons why
30
+ ;;;; the executable file might be covered by the GNU General Public License.
31
+ ;;;;
32
+ ;;;; This exception applies only to the code released by the
33
+ ;;;; Free Software Foundation under the name GUILE. If you copy
34
+ ;;;; code from other Free Software Foundation releases into a copy of
35
+ ;;;; GUILE, as the General Public License permits, the exception does
36
+ ;;;; not apply to the code that you add in this way. To avoid misleading
37
+ ;;;; anyone as to the status of such modified files, you must delete
38
+ ;;;; this exception notice from them.
39
+ ;;;;
40
+ ;;;; If you write modifications of your own for GUILE, it is your choice
41
+ ;;;; whether to permit this exception to apply to your modifications.
42
+ ;;;; If you do not wish that, delete this exception notice.
43
+ ;;;;
44
+
45
+
46
+ ;;; Commentary:
47
+
48
+ ;;; This file is the first thing loaded into Guile. It adds many mundane
49
+ ;;; definitions and a few that are interesting.
50
+ ;;;
51
+ ;;; The module system (hence the hierarchical namespace) are defined in this
52
+ ;;; file.
53
+ ;;;
54
+
55
+ ;;; Code:
56
+
57
+
58
+ ;;; {Deprecation}
59
+ ;;;
60
+
61
+ ;; We don't have macros here, but we do want to define
62
+ ;; `begin-deprecated' early.
63
+
64
+ (define begin-deprecated
65
+ (procedure->memoizing-macro
66
+ (lambda (exp env)
67
+ (if (include-deprecated-features)
68
+ `(begin ,@(cdr exp))
69
+ `#f))))
70
+
71
+
72
+ ;;; {Features}
73
+ ;;
74
+
75
+ (define (provide sym)
76
+ (if (not (memq sym *features*))
77
+ (set! *features* (cons sym *features*))))
78
+
79
+ ;;; Return #t iff FEATURE is available to this Guile interpreter.
80
+ ;;; In SLIB, provided? also checks to see if the module is available.
81
+ ;;; We should do that too, but don't.
82
+ (define (provided? feature)
83
+ (and (memq feature *features*) #t))
84
+
85
+ (begin-deprecated
86
+ (define (feature? sym)
87
+ (issue-deprecation-warning
88
+ "`feature?' is deprecated. Use `provided?' instead.")
89
+ (provided? sym)))
90
+
91
+ ;;; let format alias simple-format until the more complete version is loaded
92
+ (define format simple-format)
93
+
94
+
95
+ ;;; {R4RS compliance}
96
+
97
+ (primitive-load-path "ice-9/r4rs.scm")
98
+
99
+
100
+ ;;; {Simple Debugging Tools}
101
+ ;;
102
+
103
+
104
+ ;; peek takes any number of arguments, writes them to the
105
+ ;; current ouput port, and returns the last argument.
106
+ ;; It is handy to wrap around an expression to look at
107
+ ;; a value each time is evaluated, e.g.:
108
+ ;;
109
+ ;; (+ 10 (troublesome-fn))
110
+ ;; => (+ 10 (pk 'troublesome-fn-returned (troublesome-fn)))
111
+ ;;
112
+
113
+ (define (peek . stuff)
114
+ (newline)
115
+ (display ";;; ")
116
+ (write stuff)
117
+ (newline)
118
+ (car (last-pair stuff)))
119
+
120
+ (define pk peek)
121
+
122
+ (define (warn . stuff)
123
+ (with-output-to-port (current-error-port)
124
+ (lambda ()
125
+ (newline)
126
+ (display ";;; WARNING ")
127
+ (display stuff)
128
+ (newline)
129
+ (car (last-pair stuff)))))
130
+
131
+
132
+ ;;; {Trivial Functions}
133
+ ;;;
134
+
135
+ (define (identity x) x)
136
+ (define (1+ n) (+ n 1))
137
+ (define (1- n) (+ n -1))
138
+ (define (and=> value procedure) (and value (procedure value)))
139
+ (define (make-hash-table k) (make-vector k '()))
140
+
141
+ (begin-deprecated
142
+ (define (id x)
143
+ (issue-deprecation-warning "`id' is deprecated. Use `identity' instead.")
144
+ (identity x))
145
+ (define (-1+ n)
146
+ (issue-deprecation-warning "`-1+' is deprecated. Use `1-' instead.")
147
+ (1- n))
148
+ (define (return-it . args)
149
+ (issue-deprecation-warning "`return-it' is deprecated. Use `noop' instead.")
150
+ (apply noop args)))
151
+
152
+ ;;; apply-to-args is functionally redundant with apply and, worse,
153
+ ;;; is less general than apply since it only takes two arguments.
154
+ ;;;
155
+ ;;; On the other hand, apply-to-args is a syntacticly convenient way to
156
+ ;;; perform binding in many circumstances when the "let" family of
157
+ ;;; of forms don't cut it. E.g.:
158
+ ;;;
159
+ ;;; (apply-to-args (return-3d-mouse-coords)
160
+ ;;; (lambda (x y z)
161
+ ;;; ...))
162
+ ;;;
163
+
164
+ (define (apply-to-args args fn) (apply fn args))
165
+
166
+
167
+
168
+ ;;; {Integer Math}
169
+ ;;;
170
+
171
+ (define (ipow-by-squaring x k acc proc)
172
+ (cond ((zero? k) acc)
173
+ ((= 1 k) (proc acc x))
174
+ (else (ipow-by-squaring (proc x x)
175
+ (quotient k 2)
176
+ (if (even? k) acc (proc acc x))
177
+ proc))))
178
+
179
+ (begin-deprecated
180
+ (define (string-character-length s)
181
+ (issue-deprecation-warning "`string-character-length' is deprecated. Use `string-length' instead.")
182
+ (string-length s))
183
+ (define (flags . args)
184
+ (issue-deprecation-warning "`flags' is deprecated. Use `logior' instead.")
185
+ (apply logior args)))
186
+
187
+
188
+ ;;; {Symbol Properties}
189
+ ;;;
190
+
191
+ (define (symbol-property sym prop)
192
+ (let ((pair (assoc prop (symbol-pref sym))))
193
+ (and pair (cdr pair))))
194
+
195
+ (define (set-symbol-property! sym prop val)
196
+ (let ((pair (assoc prop (symbol-pref sym))))
197
+ (if pair
198
+ (set-cdr! pair val)
199
+ (symbol-pset! sym (acons prop val (symbol-pref sym))))))
200
+
201
+ (define (symbol-property-remove! sym prop)
202
+ (let ((pair (assoc prop (symbol-pref sym))))
203
+ (if pair
204
+ (symbol-pset! sym (delq! pair (symbol-pref sym))))))
205
+
206
+ ;;; {General Properties}
207
+ ;;;
208
+
209
+ ;; This is a more modern interface to properties. It will replace all
210
+ ;; other property-like things eventually.
211
+
212
+ (define (make-object-property)
213
+ (let ((prop (primitive-make-property #f)))
214
+ (make-procedure-with-setter
215
+ (lambda (obj) (primitive-property-ref prop obj))
216
+ (lambda (obj val) (primitive-property-set! prop obj val)))))
217
+
218
+
219
+
220
+ ;;; {Arrays}
221
+ ;;;
222
+
223
+ (if (provided? 'array)
224
+ (primitive-load-path "ice-9/arrays.scm"))
225
+
226
+
227
+ ;;; {Keywords}
228
+ ;;;
229
+
230
+ (define (symbol->keyword symbol)
231
+ (make-keyword-from-dash-symbol (symbol-append '- symbol)))
232
+
233
+ (define (keyword->symbol kw)
234
+ (let ((sym (symbol->string (keyword-dash-symbol kw))))
235
+ (string->symbol (substring sym 1 (string-length sym)))))
236
+
237
+ (define (kw-arg-ref args kw)
238
+ (let ((rem (member kw args)))
239
+ (and rem (pair? (cdr rem)) (cadr rem))))
240
+
241
+
242
+
243
+ ;;; {Structs}
244
+
245
+ (define (struct-layout s)
246
+ (struct-ref (struct-vtable s) vtable-index-layout))
247
+
248
+
249
+
250
+ ;;; Environments
251
+
252
+ (define the-environment
253
+ (procedure->syntax
254
+ (lambda (x e)
255
+ e)))
256
+
257
+ (define the-root-environment (the-environment))
258
+
259
+ (define (environment-module env)
260
+ (let ((closure (and (pair? env) (car (last-pair env)))))
261
+ (and closure (procedure-property closure 'module))))
262
+
263
+
264
+ ;;; {Records}
265
+ ;;;
266
+
267
+ ;; Printing records: by default, records are printed as
268
+ ;;
269
+ ;; #<type-name field1: val1 field2: val2 ...>
270
+ ;;
271
+ ;; You can change that by giving a custom printing function to
272
+ ;; MAKE-RECORD-TYPE (after the list of field symbols). This function
273
+ ;; will be called like
274
+ ;;
275
+ ;; (<printer> object port)
276
+ ;;
277
+ ;; It should print OBJECT to PORT.
278
+
279
+ (define (inherit-print-state old-port new-port)
280
+ (if (get-print-state old-port)
281
+ (port-with-print-state new-port (get-print-state old-port))
282
+ new-port))
283
+
284
+ ;; 0: type-name, 1: fields
285
+ (define record-type-vtable
286
+ (make-vtable-vtable "prpr" 0
287
+ (lambda (s p)
288
+ (cond ((eq? s record-type-vtable)
289
+ (display "#<record-type-vtable>" p))
290
+ (else
291
+ (display "#<record-type " p)
292
+ (display (record-type-name s) p)
293
+ (display ">" p))))))
294
+
295
+ (define (record-type? obj)
296
+ (and (struct? obj) (eq? record-type-vtable (struct-vtable obj))))
297
+
298
+ (define (make-record-type type-name fields . opt)
299
+ (let ((printer-fn (and (pair? opt) (car opt))))
300
+ (let ((struct (make-struct record-type-vtable 0
301
+ (make-struct-layout
302
+ (apply string-append
303
+ (map (lambda (f) "pw") fields)))
304
+ (or printer-fn
305
+ (lambda (s p)
306
+ (display "#<" p)
307
+ (display type-name p)
308
+ (let loop ((fields fields)
309
+ (off 0))
310
+ (cond
311
+ ((not (null? fields))
312
+ (display " " p)
313
+ (display (car fields) p)
314
+ (display ": " p)
315
+ (display (struct-ref s off) p)
316
+ (loop (cdr fields) (+ 1 off)))))
317
+ (display ">" p)))
318
+ type-name
319
+ (copy-tree fields))))
320
+ ;; Temporary solution: Associate a name to the record type descriptor
321
+ ;; so that the object system can create a wrapper class for it.
322
+ (set-struct-vtable-name! struct (if (symbol? type-name)
323
+ type-name
324
+ (string->symbol type-name)))
325
+ struct)))
326
+
327
+ (define (record-type-name obj)
328
+ (if (record-type? obj)
329
+ (struct-ref obj vtable-offset-user)
330
+ (error 'not-a-record-type obj)))
331
+
332
+ (define (record-type-fields obj)
333
+ (if (record-type? obj)
334
+ (struct-ref obj (+ 1 vtable-offset-user))
335
+ (error 'not-a-record-type obj)))
336
+
337
+ (define (record-constructor rtd . opt)
338
+ (let ((field-names (if (pair? opt) (car opt) (record-type-fields rtd))))
339
+ (local-eval `(lambda ,field-names
340
+ (make-struct ',rtd 0 ,@(map (lambda (f)
341
+ (if (memq f field-names)
342
+ f
343
+ #f))
344
+ (record-type-fields rtd))))
345
+ the-root-environment)))
346
+
347
+ (define (record-predicate rtd)
348
+ (lambda (obj) (and (struct? obj) (eq? rtd (struct-vtable obj)))))
349
+
350
+ (define (record-accessor rtd field-name)
351
+ (let* ((pos (list-index (record-type-fields rtd) field-name)))
352
+ (if (not pos)
353
+ (error 'no-such-field field-name))
354
+ (local-eval `(lambda (obj)
355
+ (and (eq? ',rtd (record-type-descriptor obj))
356
+ (struct-ref obj ,pos)))
357
+ the-root-environment)))
358
+
359
+ (define (record-modifier rtd field-name)
360
+ (let* ((pos (list-index (record-type-fields rtd) field-name)))
361
+ (if (not pos)
362
+ (error 'no-such-field field-name))
363
+ (local-eval `(lambda (obj val)
364
+ (and (eq? ',rtd (record-type-descriptor obj))
365
+ (struct-set! obj ,pos val)))
366
+ the-root-environment)))
367
+
368
+
369
+ (define (record? obj)
370
+ (and (struct? obj) (record-type? (struct-vtable obj))))
371
+
372
+ (define (record-type-descriptor obj)
373
+ (if (struct? obj)
374
+ (struct-vtable obj)
375
+ (error 'not-a-record obj)))
376
+
377
+ (provide 'record)
378
+
379
+
380
+ ;;; {Booleans}
381
+ ;;;
382
+
383
+ (define (->bool x) (not (not x)))
384
+
385
+
386
+ ;;; {Symbols}
387
+ ;;;
388
+
389
+ (define (symbol-append . args)
390
+ (string->symbol (apply string-append (map symbol->string args))))
391
+
392
+ (define (list->symbol . args)
393
+ (string->symbol (apply list->string args)))
394
+
395
+ (define (symbol . args)
396
+ (string->symbol (apply string args)))
397
+
398
+
399
+ ;;; {Lists}
400
+ ;;;
401
+
402
+ (define (list-index l k)
403
+ (let loop ((n 0)
404
+ (l l))
405
+ (and (not (null? l))
406
+ (if (eq? (car l) k)
407
+ n
408
+ (loop (+ n 1) (cdr l))))))
409
+
410
+ (define (make-list n . init)
411
+ (if (pair? init) (set! init (car init)))
412
+ (let loop ((answer '())
413
+ (n n))
414
+ (if (<= n 0)
415
+ answer
416
+ (loop (cons init answer) (- n 1)))))
417
+
418
+
419
+ ;;; {and-map and or-map}
420
+ ;;;
421
+ ;;; (and-map fn lst) is like (and (fn (car lst)) (fn (cadr lst)) (fn...) ...)
422
+ ;;; (or-map fn lst) is like (or (fn (car lst)) (fn (cadr lst)) (fn...) ...)
423
+ ;;;
424
+
425
+ ;; and-map f l
426
+ ;;
427
+ ;; Apply f to successive elements of l until exhaustion or f returns #f.
428
+ ;; If returning early, return #f. Otherwise, return the last value returned
429
+ ;; by f. If f has never been called because l is empty, return #t.
430
+ ;;
431
+ (define (and-map f lst)
432
+ (let loop ((result #t)
433
+ (l lst))
434
+ (and result
435
+ (or (and (null? l)
436
+ result)
437
+ (loop (f (car l)) (cdr l))))))
438
+
439
+ ;; or-map f l
440
+ ;;
441
+ ;; Apply f to successive elements of l until exhaustion or while f returns #f.
442
+ ;; If returning early, return the return value of f.
443
+ ;;
444
+ (define (or-map f lst)
445
+ (let loop ((result #f)
446
+ (l lst))
447
+ (or result
448
+ (and (not (null? l))
449
+ (loop (f (car l)) (cdr l))))))
450
+
451
+
452
+
453
+ (if (provided? 'posix)
454
+ (primitive-load-path "ice-9/posix.scm"))
455
+
456
+ (if (provided? 'socket)
457
+ (primitive-load-path "ice-9/networking.scm"))
458
+
459
+ (define file-exists?
460
+ (if (provided? 'posix)
461
+ (lambda (str)
462
+ (->bool (false-if-exception (stat str))))
463
+ (lambda (str)
464
+ (let ((port (catch 'system-error (lambda () (open-file str OPEN_READ))
465
+ (lambda args #f))))
466
+ (if port (begin (close-port port) #t)
467
+ #f)))))
468
+
469
+ (define file-is-directory?
470
+ (if (provided? 'posix)
471
+ (lambda (str)
472
+ (eq? (stat:type (stat str)) 'directory))
473
+ (lambda (str)
474
+ (let ((port (catch 'system-error
475
+ (lambda () (open-file (string-append str "/.")
476
+ OPEN_READ))
477
+ (lambda args #f))))
478
+ (if port (begin (close-port port) #t)
479
+ #f)))))
480
+
481
+ (define (has-suffix? str suffix)
482
+ (let ((sufl (string-length suffix))
483
+ (sl (string-length str)))
484
+ (and (> sl sufl)
485
+ (string=? (substring str (- sl sufl) sl) suffix))))
486
+
487
+ (define (system-error-errno args)
488
+ (if (eq? (car args) 'system-error)
489
+ (car (list-ref args 4))
490
+ #f))
491
+
492
+
493
+ ;;; {Error Handling}
494
+ ;;;
495
+
496
+ (define (error . args)
497
+ (save-stack)
498
+ (if (null? args)
499
+ (scm-error 'misc-error #f "?" #f #f)
500
+ (let loop ((msg "~A")
501
+ (rest (cdr args)))
502
+ (if (not (null? rest))
503
+ (loop (string-append msg " ~S")
504
+ (cdr rest))
505
+ (scm-error 'misc-error #f msg args #f)))))
506
+
507
+ ;; bad-throw is the hook that is called upon a throw to a an unhandled
508
+ ;; key (unless the throw has four arguments, in which case
509
+ ;; it's usually interpreted as an error throw.)
510
+ ;; If the key has a default handler (a throw-handler-default property),
511
+ ;; it is applied to the throw.
512
+ ;;
513
+ (define (bad-throw key . args)
514
+ (let ((default (symbol-property key 'throw-handler-default)))
515
+ (or (and default (apply default key args))
516
+ (apply error "unhandled-exception:" key args))))
517
+
518
+
519
+
520
+ (define (tm:sec obj) (vector-ref obj 0))
521
+ (define (tm:min obj) (vector-ref obj 1))
522
+ (define (tm:hour obj) (vector-ref obj 2))
523
+ (define (tm:mday obj) (vector-ref obj 3))
524
+ (define (tm:mon obj) (vector-ref obj 4))
525
+ (define (tm:year obj) (vector-ref obj 5))
526
+ (define (tm:wday obj) (vector-ref obj 6))
527
+ (define (tm:yday obj) (vector-ref obj 7))
528
+ (define (tm:isdst obj) (vector-ref obj 8))
529
+ (define (tm:gmtoff obj) (vector-ref obj 9))
530
+ (define (tm:zone obj) (vector-ref obj 10))
531
+
532
+ (define (set-tm:sec obj val) (vector-set! obj 0 val))
533
+ (define (set-tm:min obj val) (vector-set! obj 1 val))
534
+ (define (set-tm:hour obj val) (vector-set! obj 2 val))
535
+ (define (set-tm:mday obj val) (vector-set! obj 3 val))
536
+ (define (set-tm:mon obj val) (vector-set! obj 4 val))
537
+ (define (set-tm:year obj val) (vector-set! obj 5 val))
538
+ (define (set-tm:wday obj val) (vector-set! obj 6 val))
539
+ (define (set-tm:yday obj val) (vector-set! obj 7 val))
540
+ (define (set-tm:isdst obj val) (vector-set! obj 8 val))
541
+ (define (set-tm:gmtoff obj val) (vector-set! obj 9 val))
542
+ (define (set-tm:zone obj val) (vector-set! obj 10 val))
543
+
544
+ (define (tms:clock obj) (vector-ref obj 0))
545
+ (define (tms:utime obj) (vector-ref obj 1))
546
+ (define (tms:stime obj) (vector-ref obj 2))
547
+ (define (tms:cutime obj) (vector-ref obj 3))
548
+ (define (tms:cstime obj) (vector-ref obj 4))
549
+
550
+ (define file-position ftell)
551
+ (define (file-set-position port offset . whence)
552
+ (let ((whence (if (eq? whence '()) SEEK_SET (car whence))))
553
+ (seek port offset whence)))
554
+
555
+ (define (move->fdes fd/port fd)
556
+ (cond ((integer? fd/port)
557
+ (dup->fdes fd/port fd)
558
+ (close fd/port)
559
+ fd)
560
+ (else
561
+ (primitive-move->fdes fd/port fd)
562
+ (set-port-revealed! fd/port 1)
563
+ fd/port)))
564
+
565
+ (define (release-port-handle port)
566
+ (let ((revealed (port-revealed port)))
567
+ (if (> revealed 0)
568
+ (set-port-revealed! port (- revealed 1)))))
569
+
570
+ (define (dup->port port/fd mode . maybe-fd)
571
+ (let ((port (fdopen (apply dup->fdes port/fd maybe-fd)
572
+ mode)))
573
+ (if (pair? maybe-fd)
574
+ (set-port-revealed! port 1))
575
+ port))
576
+
577
+ (define (dup->inport port/fd . maybe-fd)
578
+ (apply dup->port port/fd "r" maybe-fd))
579
+
580
+ (define (dup->outport port/fd . maybe-fd)
581
+ (apply dup->port port/fd "w" maybe-fd))
582
+
583
+ (define (dup port/fd . maybe-fd)
584
+ (if (integer? port/fd)
585
+ (apply dup->fdes port/fd maybe-fd)
586
+ (apply dup->port port/fd (port-mode port/fd) maybe-fd)))
587
+
588
+ (define (duplicate-port port modes)
589
+ (dup->port port modes))
590
+
591
+ (define (fdes->inport fdes)
592
+ (let loop ((rest-ports (fdes->ports fdes)))
593
+ (cond ((null? rest-ports)
594
+ (let ((result (fdopen fdes "r")))
595
+ (set-port-revealed! result 1)
596
+ result))
597
+ ((input-port? (car rest-ports))
598
+ (set-port-revealed! (car rest-ports)
599
+ (+ (port-revealed (car rest-ports)) 1))
600
+ (car rest-ports))
601
+ (else
602
+ (loop (cdr rest-ports))))))
603
+
604
+ (define (fdes->outport fdes)
605
+ (let loop ((rest-ports (fdes->ports fdes)))
606
+ (cond ((null? rest-ports)
607
+ (let ((result (fdopen fdes "w")))
608
+ (set-port-revealed! result 1)
609
+ result))
610
+ ((output-port? (car rest-ports))
611
+ (set-port-revealed! (car rest-ports)
612
+ (+ (port-revealed (car rest-ports)) 1))
613
+ (car rest-ports))
614
+ (else
615
+ (loop (cdr rest-ports))))))
616
+
617
+ (define (port->fdes port)
618
+ (set-port-revealed! port (+ (port-revealed port) 1))
619
+ (fileno port))
620
+
621
+ (define (setenv name value)
622
+ (if value
623
+ (putenv (string-append name "=" value))
624
+ (putenv name)))
625
+
626
+
627
+ ;;; {Load Paths}
628
+ ;;;
629
+
630
+ ;;; Here for backward compatability
631
+ ;;
632
+ (define scheme-file-suffix (lambda () ".scm"))
633
+
634
+ (define (in-vicinity vicinity file)
635
+ (let ((tail (let ((len (string-length vicinity)))
636
+ (if (zero? len)
637
+ #f
638
+ (string-ref vicinity (- len 1))))))
639
+ (string-append vicinity
640
+ (if (or (not tail)
641
+ (eq? tail #\/))
642
+ ""
643
+ "/")
644
+ file)))
645
+
646
+
647
+ ;;; {Help for scm_shell}
648
+ ;;; The argument-processing code used by Guile-based shells generates
649
+ ;;; Scheme code based on the argument list. This page contains help
650
+ ;;; functions for the code it generates.
651
+
652
+ (define (command-line) (program-arguments))
653
+
654
+ ;; This is mostly for the internal use of the code generated by
655
+ ;; scm_compile_shell_switches.
656
+ (define (load-user-init)
657
+ (let* ((home (or (getenv "HOME")
658
+ (false-if-exception (passwd:dir (getpwuid (getuid))))
659
+ "/")) ;; fallback for cygwin etc.
660
+ (init-file (in-vicinity home ".guile")))
661
+ (if (file-exists? init-file)
662
+ (primitive-load init-file))))
663
+
664
+
665
+ ;;; {Loading by paths}
666
+
667
+ ;;; Load a Scheme source file named NAME, searching for it in the
668
+ ;;; directories listed in %load-path, and applying each of the file
669
+ ;;; name extensions listed in %load-extensions.
670
+ (define (load-from-path name)
671
+ (start-stack 'load-stack
672
+ (primitive-load-path name)))
673
+
674
+
675
+
676
+ ;;; {Transcendental Functions}
677
+ ;;;
678
+ ;;; Derived from "Transcen.scm", Complex trancendental functions for SCM.
679
+ ;;; Written by Jerry D. Hedden, (C) FSF.
680
+ ;;; See the file `COPYING' for terms applying to this program.
681
+ ;;;
682
+
683
+ (define (exp z)
684
+ (if (real? z) ($exp z)
685
+ (make-polar ($exp (real-part z)) (imag-part z))))
686
+
687
+ (define (log z)
688
+ (if (and (real? z) (>= z 0))
689
+ ($log z)
690
+ (make-rectangular ($log (magnitude z)) (angle z))))
691
+
692
+ (define (sqrt z)
693
+ (if (real? z)
694
+ (if (negative? z) (make-rectangular 0 ($sqrt (- z)))
695
+ ($sqrt z))
696
+ (make-polar ($sqrt (magnitude z)) (/ (angle z) 2))))
697
+
698
+ (define expt
699
+ (let ((integer-expt integer-expt))
700
+ (lambda (z1 z2)
701
+ (cond ((integer? z2)
702
+ (if (negative? z2)
703
+ (/ 1 (integer-expt z1 (- z2)))
704
+ (integer-expt z1 z2)))
705
+ ((and (real? z2) (real? z1) (>= z1 0))
706
+ ($expt z1 z2))
707
+ (else
708
+ (exp (* z2 (log z1))))))))
709
+
710
+ (define (sinh z)
711
+ (if (real? z) ($sinh z)
712
+ (let ((x (real-part z)) (y (imag-part z)))
713
+ (make-rectangular (* ($sinh x) ($cos y))
714
+ (* ($cosh x) ($sin y))))))
715
+ (define (cosh z)
716
+ (if (real? z) ($cosh z)
717
+ (let ((x (real-part z)) (y (imag-part z)))
718
+ (make-rectangular (* ($cosh x) ($cos y))
719
+ (* ($sinh x) ($sin y))))))
720
+ (define (tanh z)
721
+ (if (real? z) ($tanh z)
722
+ (let* ((x (* 2 (real-part z)))
723
+ (y (* 2 (imag-part z)))
724
+ (w (+ ($cosh x) ($cos y))))
725
+ (make-rectangular (/ ($sinh x) w) (/ ($sin y) w)))))
726
+
727
+ (define (asinh z)
728
+ (if (real? z) ($asinh z)
729
+ (log (+ z (sqrt (+ (* z z) 1))))))
730
+
731
+ (define (acosh z)
732
+ (if (and (real? z) (>= z 1))
733
+ ($acosh z)
734
+ (log (+ z (sqrt (- (* z z) 1))))))
735
+
736
+ (define (atanh z)
737
+ (if (and (real? z) (> z -1) (< z 1))
738
+ ($atanh z)
739
+ (/ (log (/ (+ 1 z) (- 1 z))) 2)))
740
+
741
+ (define (sin z)
742
+ (if (real? z) ($sin z)
743
+ (let ((x (real-part z)) (y (imag-part z)))
744
+ (make-rectangular (* ($sin x) ($cosh y))
745
+ (* ($cos x) ($sinh y))))))
746
+ (define (cos z)
747
+ (if (real? z) ($cos z)
748
+ (let ((x (real-part z)) (y (imag-part z)))
749
+ (make-rectangular (* ($cos x) ($cosh y))
750
+ (- (* ($sin x) ($sinh y)))))))
751
+ (define (tan z)
752
+ (if (real? z) ($tan z)
753
+ (let* ((x (* 2 (real-part z)))
754
+ (y (* 2 (imag-part z)))
755
+ (w (+ ($cos x) ($cosh y))))
756
+ (make-rectangular (/ ($sin x) w) (/ ($sinh y) w)))))
757
+
758
+ (define (asin z)
759
+ (if (and (real? z) (>= z -1) (<= z 1))
760
+ ($asin z)
761
+ (* -i (asinh (* +i z)))))
762
+
763
+ (define (acos z)
764
+ (if (and (real? z) (>= z -1) (<= z 1))
765
+ ($acos z)
766
+ (+ (/ (angle -1) 2) (* +i (asinh (* +i z))))))
767
+
768
+ (define (atan z . y)
769
+ (if (null? y)
770
+ (if (real? z) ($atan z)
771
+ (/ (log (/ (- +i z) (+ +i z))) +2i))
772
+ ($atan2 z (car y))))
773
+
774
+ (define (log10 arg)
775
+ (/ (log arg) (log 10)))
776
+
777
+
778
+
779
+ ;;; {Reader Extensions}
780
+ ;;;
781
+
782
+ ;;; Reader code for various "#c" forms.
783
+ ;;;
784
+
785
+ (read-hash-extend #\' (lambda (c port)
786
+ (read port)))
787
+
788
+ (define read-eval? (make-fluid))
789
+ (fluid-set! read-eval? #f)
790
+ (read-hash-extend #\.
791
+ (lambda (c port)
792
+ (if (fluid-ref read-eval?)
793
+ (eval (read port) (interaction-environment))
794
+ (error
795
+ "#. read expansion found and read-eval? is #f."))))
796
+
797
+
798
+ ;;; {Command Line Options}
799
+ ;;;
800
+
801
+ (define (get-option argv kw-opts kw-args return)
802
+ (cond
803
+ ((null? argv)
804
+ (return #f #f argv))
805
+
806
+ ((or (not (eq? #\- (string-ref (car argv) 0)))
807
+ (eq? (string-length (car argv)) 1))
808
+ (return 'normal-arg (car argv) (cdr argv)))
809
+
810
+ ((eq? #\- (string-ref (car argv) 1))
811
+ (let* ((kw-arg-pos (or (string-index (car argv) #\=)
812
+ (string-length (car argv))))
813
+ (kw (symbol->keyword (substring (car argv) 2 kw-arg-pos)))
814
+ (kw-opt? (member kw kw-opts))
815
+ (kw-arg? (member kw kw-args))
816
+ (arg (or (and (not (eq? kw-arg-pos (string-length (car argv))))
817
+ (substring (car argv)
818
+ (+ kw-arg-pos 1)
819
+ (string-length (car argv))))
820
+ (and kw-arg?
821
+ (begin (set! argv (cdr argv)) (car argv))))))
822
+ (if (or kw-opt? kw-arg?)
823
+ (return kw arg (cdr argv))
824
+ (return 'usage-error kw (cdr argv)))))
825
+
826
+ (else
827
+ (let* ((char (substring (car argv) 1 2))
828
+ (kw (symbol->keyword char)))
829
+ (cond
830
+
831
+ ((member kw kw-opts)
832
+ (let* ((rest-car (substring (car argv) 2 (string-length (car argv))))
833
+ (new-argv (if (= 0 (string-length rest-car))
834
+ (cdr argv)
835
+ (cons (string-append "-" rest-car) (cdr argv)))))
836
+ (return kw #f new-argv)))
837
+
838
+ ((member kw kw-args)
839
+ (let* ((rest-car (substring (car argv) 2 (string-length (car argv))))
840
+ (arg (if (= 0 (string-length rest-car))
841
+ (cadr argv)
842
+ rest-car))
843
+ (new-argv (if (= 0 (string-length rest-car))
844
+ (cddr argv)
845
+ (cdr argv))))
846
+ (return kw arg new-argv)))
847
+
848
+ (else (return 'usage-error kw argv)))))))
849
+
850
+ (define (for-next-option proc argv kw-opts kw-args)
851
+ (let loop ((argv argv))
852
+ (get-option argv kw-opts kw-args
853
+ (lambda (opt opt-arg argv)
854
+ (and opt (proc opt opt-arg argv loop))))))
855
+
856
+ (define (display-usage-report kw-desc)
857
+ (for-each
858
+ (lambda (kw)
859
+ (or (eq? (car kw) #t)
860
+ (eq? (car kw) 'else)
861
+ (let* ((opt-desc kw)
862
+ (help (cadr opt-desc))
863
+ (opts (car opt-desc))
864
+ (opts-proper (if (string? (car opts)) (cdr opts) opts))
865
+ (arg-name (if (string? (car opts))
866
+ (string-append "<" (car opts) ">")
867
+ ""))
868
+ (left-part (string-append
869
+ (with-output-to-string
870
+ (lambda ()
871
+ (map (lambda (x) (display (keyword->symbol x)) (display " "))
872
+ opts-proper)))
873
+ arg-name))
874
+ (middle-part (if (and (< (string-length left-part) 30)
875
+ (< (string-length help) 40))
876
+ (make-string (- 30 (string-length left-part)) #\ )
877
+ "\n\t")))
878
+ (display left-part)
879
+ (display middle-part)
880
+ (display help)
881
+ (newline))))
882
+ kw-desc))
883
+
884
+
885
+
886
+ (define (transform-usage-lambda cases)
887
+ (let* ((raw-usage (delq! 'else (map car cases)))
888
+ (usage-sans-specials (map (lambda (x)
889
+ (or (and (not (list? x)) x)
890
+ (and (symbol? (car x)) #t)
891
+ (and (boolean? (car x)) #t)
892
+ x))
893
+ raw-usage))
894
+ (usage-desc (delq! #t usage-sans-specials))
895
+ (kw-desc (map car usage-desc))
896
+ (kw-opts (apply append (map (lambda (x) (and (not (string? (car x))) x)) kw-desc)))
897
+ (kw-args (apply append (map (lambda (x) (and (string? (car x)) (cdr x))) kw-desc)))
898
+ (transmogrified-cases (map (lambda (case)
899
+ (cons (let ((opts (car case)))
900
+ (if (or (boolean? opts) (eq? 'else opts))
901
+ opts
902
+ (cond
903
+ ((symbol? (car opts)) opts)
904
+ ((boolean? (car opts)) opts)
905
+ ((string? (caar opts)) (cdar opts))
906
+ (else (car opts)))))
907
+ (cdr case)))
908
+ cases)))
909
+ `(let ((%display-usage (lambda () (display-usage-report ',usage-desc))))
910
+ (lambda (%argv)
911
+ (let %next-arg ((%argv %argv))
912
+ (get-option %argv
913
+ ',kw-opts
914
+ ',kw-args
915
+ (lambda (%opt %arg %new-argv)
916
+ (case %opt
917
+ ,@ transmogrified-cases))))))))
918
+
919
+
920
+
921
+
922
+ ;;; {Low Level Modules}
923
+ ;;;
924
+ ;;; These are the low level data structures for modules.
925
+ ;;;
926
+ ;;; !!! warning: The interface to lazy binder procedures is going
927
+ ;;; to be changed in an incompatible way to permit all the basic
928
+ ;;; module ops to be virtualized.
929
+ ;;;
930
+ ;;; (make-module size use-list lazy-binding-proc) => module
931
+ ;;; module-{obarray,uses,binder}[|-set!]
932
+ ;;; (module? obj) => [#t|#f]
933
+ ;;; (module-locally-bound? module symbol) => [#t|#f]
934
+ ;;; (module-bound? module symbol) => [#t|#f]
935
+ ;;; (module-symbol-locally-interned? module symbol) => [#t|#f]
936
+ ;;; (module-symbol-interned? module symbol) => [#t|#f]
937
+ ;;; (module-local-variable module symbol) => [#<variable ...> | #f]
938
+ ;;; (module-variable module symbol) => [#<variable ...> | #f]
939
+ ;;; (module-symbol-binding module symbol opt-value)
940
+ ;;; => [ <obj> | opt-value | an error occurs ]
941
+ ;;; (module-make-local-var! module symbol) => #<variable...>
942
+ ;;; (module-add! module symbol var) => unspecified
943
+ ;;; (module-remove! module symbol) => unspecified
944
+ ;;; (module-for-each proc module) => unspecified
945
+ ;;; (make-scm-module) => module ; a lazy copy of the symhash module
946
+ ;;; (set-current-module module) => unspecified
947
+ ;;; (current-module) => #<module...>
948
+ ;;;
949
+ ;;;
950
+
951
+
952
+ ;;; {Printing Modules}
953
+ ;; This is how modules are printed. You can re-define it.
954
+ ;; (Redefining is actually more complicated than simply redefining
955
+ ;; %print-module because that would only change the binding and not
956
+ ;; the value stored in the vtable that determines how record are
957
+ ;; printed. Sigh.)
958
+
959
+ (define (%print-module mod port) ; unused args: depth length style table)
960
+ (display "#<" port)
961
+ (display (or (module-kind mod) "module") port)
962
+ (let ((name (module-name mod)))
963
+ (if name
964
+ (begin
965
+ (display " " port)
966
+ (display name port))))
967
+ (display " " port)
968
+ (display (number->string (object-address mod) 16) port)
969
+ (display ">" port))
970
+
971
+ ;; module-type
972
+ ;;
973
+ ;; A module is characterized by an obarray in which local symbols
974
+ ;; are interned, a list of modules, "uses", from which non-local
975
+ ;; bindings can be inherited, and an optional lazy-binder which
976
+ ;; is a (CLOSURE module symbol) which, as a last resort, can provide
977
+ ;; bindings that would otherwise not be found locally in the module.
978
+ ;;
979
+ ;; NOTE: If you change here, you also need to change libguile/modules.h.
980
+ ;;
981
+ (define module-type
982
+ (make-record-type 'module
983
+ '(obarray uses binder eval-closure transformer name kind
984
+ observers weak-observers observer-id)
985
+ %print-module))
986
+
987
+ ;; make-module &opt size uses binder
988
+ ;;
989
+ ;; Create a new module, perhaps with a particular size of obarray,
990
+ ;; initial uses list, or binding procedure.
991
+ ;;
992
+ (define make-module
993
+ (lambda args
994
+
995
+ (define (parse-arg index default)
996
+ (if (> (length args) index)
997
+ (list-ref args index)
998
+ default))
999
+
1000
+ (if (> (length args) 3)
1001
+ (error "Too many args to make-module." args))
1002
+
1003
+ (let ((size (parse-arg 0 1021))
1004
+ (uses (parse-arg 1 '()))
1005
+ (binder (parse-arg 2 #f)))
1006
+
1007
+ (if (not (integer? size))
1008
+ (error "Illegal size to make-module." size))
1009
+ (if (not (and (list? uses)
1010
+ (and-map module? uses)))
1011
+ (error "Incorrect use list." uses))
1012
+ (if (and binder (not (procedure? binder)))
1013
+ (error
1014
+ "Lazy-binder expected to be a procedure or #f." binder))
1015
+
1016
+ (let ((module (module-constructor (make-vector size '())
1017
+ uses binder #f #f #f #f
1018
+ '()
1019
+ (make-weak-value-hash-table 31)
1020
+ 0)))
1021
+
1022
+ ;; We can't pass this as an argument to module-constructor,
1023
+ ;; because we need it to close over a pointer to the module
1024
+ ;; itself.
1025
+ (set-module-eval-closure! module (standard-eval-closure module))
1026
+
1027
+ module))))
1028
+
1029
+ (define module-constructor (record-constructor module-type))
1030
+ (define module-obarray (record-accessor module-type 'obarray))
1031
+ (define set-module-obarray! (record-modifier module-type 'obarray))
1032
+ (define module-uses (record-accessor module-type 'uses))
1033
+ (define set-module-uses! (record-modifier module-type 'uses))
1034
+ (define module-binder (record-accessor module-type 'binder))
1035
+ (define set-module-binder! (record-modifier module-type 'binder))
1036
+
1037
+ ;; NOTE: This binding is used in libguile/modules.c.
1038
+ (define module-eval-closure (record-accessor module-type 'eval-closure))
1039
+
1040
+ (define module-transformer (record-accessor module-type 'transformer))
1041
+ (define set-module-transformer! (record-modifier module-type 'transformer))
1042
+ (define module-name (record-accessor module-type 'name))
1043
+ (define set-module-name! (record-modifier module-type 'name))
1044
+ (define module-kind (record-accessor module-type 'kind))
1045
+ (define set-module-kind! (record-modifier module-type 'kind))
1046
+ (define module-observers (record-accessor module-type 'observers))
1047
+ (define set-module-observers! (record-modifier module-type 'observers))
1048
+ (define module-weak-observers (record-accessor module-type 'weak-observers))
1049
+ (define module-observer-id (record-accessor module-type 'observer-id))
1050
+ (define set-module-observer-id! (record-modifier module-type 'observer-id))
1051
+ (define module? (record-predicate module-type))
1052
+
1053
+ (define set-module-eval-closure!
1054
+ (let ((setter (record-modifier module-type 'eval-closure)))
1055
+ (lambda (module closure)
1056
+ (setter module closure)
1057
+ ;; Make it possible to lookup the module from the environment.
1058
+ ;; This implementation is correct since an eval closure can belong
1059
+ ;; to maximally one module.
1060
+ (set-procedure-property! closure 'module module))))
1061
+
1062
+ (begin-deprecated
1063
+ (define (eval-in-module exp mod)
1064
+ (issue-deprecation-warning
1065
+ "`eval-in-module' is deprecated. Use `eval' instead.")
1066
+ (eval exp mod)))
1067
+
1068
+
1069
+ ;;; {Observer protocol}
1070
+ ;;;
1071
+
1072
+ (define (module-observe module proc)
1073
+ (set-module-observers! module (cons proc (module-observers module)))
1074
+ (cons module proc))
1075
+
1076
+ (define (module-observe-weak module proc)
1077
+ (let ((id (module-observer-id module)))
1078
+ (hash-set! (module-weak-observers module) id proc)
1079
+ (set-module-observer-id! module (+ 1 id))
1080
+ (cons module id)))
1081
+
1082
+ (define (module-unobserve token)
1083
+ (let ((module (car token))
1084
+ (id (cdr token)))
1085
+ (if (integer? id)
1086
+ (hash-remove! (module-weak-observers module) id)
1087
+ (set-module-observers! module (delq1! id (module-observers module)))))
1088
+ *unspecified*)
1089
+
1090
+ (define (module-modified m)
1091
+ (for-each (lambda (proc) (proc m)) (module-observers m))
1092
+ (hash-fold (lambda (id proc res) (proc m)) #f (module-weak-observers m)))
1093
+
1094
+
1095
+ ;;; {Module Searching in General}
1096
+ ;;;
1097
+ ;;; We sometimes want to look for properties of a symbol
1098
+ ;;; just within the obarray of one module. If the property
1099
+ ;;; holds, then it is said to hold ``locally'' as in, ``The symbol
1100
+ ;;; DISPLAY is locally rebound in the module `safe-guile'.''
1101
+ ;;;
1102
+ ;;;
1103
+ ;;; Other times, we want to test for a symbol property in the obarray
1104
+ ;;; of M and, if it is not found there, try each of the modules in the
1105
+ ;;; uses list of M. This is the normal way of testing for some
1106
+ ;;; property, so we state these properties without qualification as
1107
+ ;;; in: ``The symbol 'fnord is interned in module M because it is
1108
+ ;;; interned locally in module M2 which is a member of the uses list
1109
+ ;;; of M.''
1110
+ ;;;
1111
+
1112
+ ;; module-search fn m
1113
+ ;;
1114
+ ;; return the first non-#f result of FN applied to M and then to
1115
+ ;; the modules in the uses of m, and so on recursively. If all applications
1116
+ ;; return #f, then so does this function.
1117
+ ;;
1118
+ (define (module-search fn m v)
1119
+ (define (loop pos)
1120
+ (and (pair? pos)
1121
+ (or (module-search fn (car pos) v)
1122
+ (loop (cdr pos)))))
1123
+ (or (fn m v)
1124
+ (loop (module-uses m))))
1125
+
1126
+
1127
+ ;;; {Is a symbol bound in a module?}
1128
+ ;;;
1129
+ ;;; Symbol S in Module M is bound if S is interned in M and if the binding
1130
+ ;;; of S in M has been set to some well-defined value.
1131
+ ;;;
1132
+
1133
+ ;; module-locally-bound? module symbol
1134
+ ;;
1135
+ ;; Is a symbol bound (interned and defined) locally in a given module?
1136
+ ;;
1137
+ (define (module-locally-bound? m v)
1138
+ (let ((var (module-local-variable m v)))
1139
+ (and var
1140
+ (variable-bound? var))))
1141
+
1142
+ ;; module-bound? module symbol
1143
+ ;;
1144
+ ;; Is a symbol bound (interned and defined) anywhere in a given module
1145
+ ;; or its uses?
1146
+ ;;
1147
+ (define (module-bound? m v)
1148
+ (module-search module-locally-bound? m v))
1149
+
1150
+ ;;; {Is a symbol interned in a module?}
1151
+ ;;;
1152
+ ;;; Symbol S in Module M is interned if S occurs in
1153
+ ;;; of S in M has been set to some well-defined value.
1154
+ ;;;
1155
+ ;;; It is possible to intern a symbol in a module without providing
1156
+ ;;; an initial binding for the corresponding variable. This is done
1157
+ ;;; with:
1158
+ ;;; (module-add! module symbol (make-undefined-variable))
1159
+ ;;;
1160
+ ;;; In that case, the symbol is interned in the module, but not
1161
+ ;;; bound there. The unbound symbol shadows any binding for that
1162
+ ;;; symbol that might otherwise be inherited from a member of the uses list.
1163
+ ;;;
1164
+
1165
+ (define (module-obarray-get-handle ob key)
1166
+ ((if (symbol? key) hashq-get-handle hash-get-handle) ob key))
1167
+
1168
+ (define (module-obarray-ref ob key)
1169
+ ((if (symbol? key) hashq-ref hash-ref) ob key))
1170
+
1171
+ (define (module-obarray-set! ob key val)
1172
+ ((if (symbol? key) hashq-set! hash-set!) ob key val))
1173
+
1174
+ (define (module-obarray-remove! ob key)
1175
+ ((if (symbol? key) hashq-remove! hash-remove!) ob key))
1176
+
1177
+ ;; module-symbol-locally-interned? module symbol
1178
+ ;;
1179
+ ;; is a symbol interned (not neccessarily defined) locally in a given module
1180
+ ;; or its uses? Interned symbols shadow inherited bindings even if
1181
+ ;; they are not themselves bound to a defined value.
1182
+ ;;
1183
+ (define (module-symbol-locally-interned? m v)
1184
+ (not (not (module-obarray-get-handle (module-obarray m) v))))
1185
+
1186
+ ;; module-symbol-interned? module symbol
1187
+ ;;
1188
+ ;; is a symbol interned (not neccessarily defined) anywhere in a given module
1189
+ ;; or its uses? Interned symbols shadow inherited bindings even if
1190
+ ;; they are not themselves bound to a defined value.
1191
+ ;;
1192
+ (define (module-symbol-interned? m v)
1193
+ (module-search module-symbol-locally-interned? m v))
1194
+
1195
+
1196
+ ;;; {Mapping modules x symbols --> variables}
1197
+ ;;;
1198
+
1199
+ ;; module-local-variable module symbol
1200
+ ;; return the local variable associated with a MODULE and SYMBOL.
1201
+ ;;
1202
+ ;;; This function is very important. It is the only function that can
1203
+ ;;; return a variable from a module other than the mutators that store
1204
+ ;;; new variables in modules. Therefore, this function is the location
1205
+ ;;; of the "lazy binder" hack.
1206
+ ;;;
1207
+ ;;; If symbol is defined in MODULE, and if the definition binds symbol
1208
+ ;;; to a variable, return that variable object.
1209
+ ;;;
1210
+ ;;; If the symbols is not found at first, but the module has a lazy binder,
1211
+ ;;; then try the binder.
1212
+ ;;;
1213
+ ;;; If the symbol is not found at all, return #f.
1214
+ ;;;
1215
+ (define (module-local-variable m v)
1216
+ ; (caddr
1217
+ ; (list m v
1218
+ (let ((b (module-obarray-ref (module-obarray m) v)))
1219
+ (or (and (variable? b) b)
1220
+ (and (module-binder m)
1221
+ ((module-binder m) m v #f)))))
1222
+ ;))
1223
+
1224
+ ;; module-variable module symbol
1225
+ ;;
1226
+ ;; like module-local-variable, except search the uses in the
1227
+ ;; case V is not found in M.
1228
+ ;;
1229
+ ;; NOTE: This function is superseded with C code (see modules.c)
1230
+ ;;; when using the standard eval closure.
1231
+ ;;
1232
+ (define (module-variable m v)
1233
+ (module-search module-local-variable m v))
1234
+
1235
+
1236
+ ;;; {Mapping modules x symbols --> bindings}
1237
+ ;;;
1238
+ ;;; These are similar to the mapping to variables, except that the
1239
+ ;;; variable is dereferenced.
1240
+ ;;;
1241
+
1242
+ ;; module-symbol-binding module symbol opt-value
1243
+ ;;
1244
+ ;; return the binding of a variable specified by name within
1245
+ ;; a given module, signalling an error if the variable is unbound.
1246
+ ;; If the OPT-VALUE is passed, then instead of signalling an error,
1247
+ ;; return OPT-VALUE.
1248
+ ;;
1249
+ (define (module-symbol-local-binding m v . opt-val)
1250
+ (let ((var (module-local-variable m v)))
1251
+ (if var
1252
+ (variable-ref var)
1253
+ (if (not (null? opt-val))
1254
+ (car opt-val)
1255
+ (error "Locally unbound variable." v)))))
1256
+
1257
+ ;; module-symbol-binding module symbol opt-value
1258
+ ;;
1259
+ ;; return the binding of a variable specified by name within
1260
+ ;; a given module, signalling an error if the variable is unbound.
1261
+ ;; If the OPT-VALUE is passed, then instead of signalling an error,
1262
+ ;; return OPT-VALUE.
1263
+ ;;
1264
+ (define (module-symbol-binding m v . opt-val)
1265
+ (let ((var (module-variable m v)))
1266
+ (if var
1267
+ (variable-ref var)
1268
+ (if (not (null? opt-val))
1269
+ (car opt-val)
1270
+ (error "Unbound variable." v)))))
1271
+
1272
+
1273
+
1274
+ ;;; {Adding Variables to Modules}
1275
+ ;;;
1276
+ ;;;
1277
+
1278
+
1279
+ ;; module-make-local-var! module symbol
1280
+ ;;
1281
+ ;; ensure a variable for V in the local namespace of M.
1282
+ ;; If no variable was already there, then create a new and uninitialzied
1283
+ ;; variable.
1284
+ ;;
1285
+ (define (module-make-local-var! m v)
1286
+ (or (let ((b (module-obarray-ref (module-obarray m) v)))
1287
+ (and (variable? b)
1288
+ (begin
1289
+ (module-modified m)
1290
+ b)))
1291
+ (and (module-binder m)
1292
+ ((module-binder m) m v #t))
1293
+ (begin
1294
+ (let ((answer (make-undefined-variable)))
1295
+ (variable-set-name-hint! answer v)
1296
+ (module-obarray-set! (module-obarray m) v answer)
1297
+ (module-modified m)
1298
+ answer))))
1299
+
1300
+ ;; module-ensure-local-variable! module symbol
1301
+ ;;
1302
+ ;; Ensure that there is a local variable in MODULE for SYMBOL. If
1303
+ ;; there is no binding for SYMBOL, create a new uninitialized
1304
+ ;; variable. Return the local variable.
1305
+ ;;
1306
+ (define (module-ensure-local-variable! module symbol)
1307
+ (or (module-local-variable module symbol)
1308
+ (let ((var (make-undefined-variable)))
1309
+ (variable-set-name-hint! var symbol)
1310
+ (module-add! module symbol var)
1311
+ var)))
1312
+
1313
+ ;; module-add! module symbol var
1314
+ ;;
1315
+ ;; ensure a particular variable for V in the local namespace of M.
1316
+ ;;
1317
+ (define (module-add! m v var)
1318
+ (if (not (variable? var))
1319
+ (error "Bad variable to module-add!" var))
1320
+ (module-obarray-set! (module-obarray m) v var)
1321
+ (module-modified m))
1322
+
1323
+ ;; module-remove!
1324
+ ;;
1325
+ ;; make sure that a symbol is undefined in the local namespace of M.
1326
+ ;;
1327
+ (define (module-remove! m v)
1328
+ (module-obarray-remove! (module-obarray m) v)
1329
+ (module-modified m))
1330
+
1331
+ (define (module-clear! m)
1332
+ (vector-fill! (module-obarray m) '())
1333
+ (module-modified m))
1334
+
1335
+ ;; MODULE-FOR-EACH -- exported
1336
+ ;;
1337
+ ;; Call PROC on each symbol in MODULE, with arguments of (SYMBOL VARIABLE).
1338
+ ;;
1339
+ (define (module-for-each proc module)
1340
+ (let ((obarray (module-obarray module)))
1341
+ (do ((index 0 (+ index 1))
1342
+ (end (vector-length obarray)))
1343
+ ((= index end))
1344
+ (for-each
1345
+ (lambda (bucket)
1346
+ (proc (car bucket) (cdr bucket)))
1347
+ (vector-ref obarray index)))))
1348
+
1349
+
1350
+ (define (module-map proc module)
1351
+ (let* ((obarray (module-obarray module))
1352
+ (end (vector-length obarray)))
1353
+
1354
+ (let loop ((i 0)
1355
+ (answer '()))
1356
+ (if (= i end)
1357
+ answer
1358
+ (loop (+ 1 i)
1359
+ (append!
1360
+ (map (lambda (bucket)
1361
+ (proc (car bucket) (cdr bucket)))
1362
+ (vector-ref obarray i))
1363
+ answer))))))
1364
+
1365
+
1366
+ ;;; {Low Level Bootstrapping}
1367
+ ;;;
1368
+
1369
+ ;; make-root-module
1370
+
1371
+ ;; A root module uses the pre-modules-obarray as its obarray. This
1372
+ ;; special obarray accumulates all bindings that have been established
1373
+ ;; before the module system is fully booted.
1374
+ ;;
1375
+ ;; (The obarray continues to be used by code that has been closed over
1376
+ ;; before the module system has been booted.)
1377
+
1378
+ (define (make-root-module)
1379
+ (let ((m (make-module 0)))
1380
+ (set-module-obarray! m (%get-pre-modules-obarray))
1381
+ m))
1382
+
1383
+ ;; make-scm-module
1384
+
1385
+ ;; The root interface is a module that uses the same obarray as the
1386
+ ;; root module. It does not allow new definitions, tho.
1387
+
1388
+ (define (make-scm-module)
1389
+ (let ((m (make-module 0)))
1390
+ (set-module-obarray! m (%get-pre-modules-obarray))
1391
+ (set-module-eval-closure! m (standard-interface-eval-closure m))
1392
+ m))
1393
+
1394
+
1395
+
1396
+ ;;; {Module-based Loading}
1397
+ ;;;
1398
+
1399
+ (define (save-module-excursion thunk)
1400
+ (let ((inner-module (current-module))
1401
+ (outer-module #f))
1402
+ (dynamic-wind (lambda ()
1403
+ (set! outer-module (current-module))
1404
+ (set-current-module inner-module)
1405
+ (set! inner-module #f))
1406
+ thunk
1407
+ (lambda ()
1408
+ (set! inner-module (current-module))
1409
+ (set-current-module outer-module)
1410
+ (set! outer-module #f)))))
1411
+
1412
+ (define basic-load load)
1413
+
1414
+ (define (load-module filename)
1415
+ (save-module-excursion
1416
+ (lambda ()
1417
+ (let ((oldname (and (current-load-port)
1418
+ (port-filename (current-load-port)))))
1419
+ (basic-load (if (and oldname
1420
+ (> (string-length filename) 0)
1421
+ (not (char=? (string-ref filename 0) #\/))
1422
+ (not (string=? (dirname oldname) ".")))
1423
+ (string-append (dirname oldname) "/" filename)
1424
+ filename))))))
1425
+
1426
+
1427
+
1428
+ ;;; {MODULE-REF -- exported}
1429
+ ;;
1430
+ ;; Returns the value of a variable called NAME in MODULE or any of its
1431
+ ;; used modules. If there is no such variable, then if the optional third
1432
+ ;; argument DEFAULT is present, it is returned; otherwise an error is signaled.
1433
+ ;;
1434
+ (define (module-ref module name . rest)
1435
+ (let ((variable (module-variable module name)))
1436
+ (if (and variable (variable-bound? variable))
1437
+ (variable-ref variable)
1438
+ (if (null? rest)
1439
+ (error "No variable named" name 'in module)
1440
+ (car rest) ; default value
1441
+ ))))
1442
+
1443
+ ;; MODULE-SET! -- exported
1444
+ ;;
1445
+ ;; Sets the variable called NAME in MODULE (or in a module that MODULE uses)
1446
+ ;; to VALUE; if there is no such variable, an error is signaled.
1447
+ ;;
1448
+ (define (module-set! module name value)
1449
+ (let ((variable (module-variable module name)))
1450
+ (if variable
1451
+ (variable-set! variable value)
1452
+ (error "No variable named" name 'in module))))
1453
+
1454
+ ;; MODULE-DEFINE! -- exported
1455
+ ;;
1456
+ ;; Sets the variable called NAME in MODULE to VALUE; if there is no such
1457
+ ;; variable, it is added first.
1458
+ ;;
1459
+ (define (module-define! module name value)
1460
+ (let ((variable (module-local-variable module name)))
1461
+ (if variable
1462
+ (begin
1463
+ (variable-set! variable value)
1464
+ (module-modified module))
1465
+ (let ((variable (make-variable value)))
1466
+ (variable-set-name-hint! variable name)
1467
+ (module-add! module name variable)))))
1468
+
1469
+ ;; MODULE-DEFINED? -- exported
1470
+ ;;
1471
+ ;; Return #t iff NAME is defined in MODULE (or in a module that MODULE
1472
+ ;; uses)
1473
+ ;;
1474
+ (define (module-defined? module name)
1475
+ (let ((variable (module-variable module name)))
1476
+ (and variable (variable-bound? variable))))
1477
+
1478
+ ;; MODULE-USE! module interface
1479
+ ;;
1480
+ ;; Add INTERFACE to the list of interfaces used by MODULE.
1481
+ ;;
1482
+ (define (module-use! module interface)
1483
+ (set-module-uses! module
1484
+ (cons interface (delq! interface (module-uses module))))
1485
+ (module-modified module))
1486
+
1487
+
1488
+ ;;; {Recursive Namespaces}
1489
+ ;;;
1490
+ ;;;
1491
+ ;;; A hierarchical namespace emerges if we consider some module to be
1492
+ ;;; root, and variables bound to modules as nested namespaces.
1493
+ ;;;
1494
+ ;;; The routines in this file manage variable names in hierarchical namespace.
1495
+ ;;; Each variable name is a list of elements, looked up in successively nested
1496
+ ;;; modules.
1497
+ ;;;
1498
+ ;;; (nested-ref some-root-module '(foo bar baz))
1499
+ ;;; => <value of a variable named baz in the module bound to bar in
1500
+ ;;; the module bound to foo in some-root-module>
1501
+ ;;;
1502
+ ;;;
1503
+ ;;; There are:
1504
+ ;;;
1505
+ ;;; ;; a-root is a module
1506
+ ;;; ;; name is a list of symbols
1507
+ ;;;
1508
+ ;;; nested-ref a-root name
1509
+ ;;; nested-set! a-root name val
1510
+ ;;; nested-define! a-root name val
1511
+ ;;; nested-remove! a-root name
1512
+ ;;;
1513
+ ;;;
1514
+ ;;; (current-module) is a natural choice for a-root so for convenience there are
1515
+ ;;; also:
1516
+ ;;;
1517
+ ;;; local-ref name == nested-ref (current-module) name
1518
+ ;;; local-set! name val == nested-set! (current-module) name val
1519
+ ;;; local-define! name val == nested-define! (current-module) name val
1520
+ ;;; local-remove! name == nested-remove! (current-module) name
1521
+ ;;;
1522
+
1523
+
1524
+ (define (nested-ref root names)
1525
+ (let loop ((cur root)
1526
+ (elts names))
1527
+ (cond
1528
+ ((null? elts) cur)
1529
+ ((not (module? cur)) #f)
1530
+ (else (loop (module-ref cur (car elts) #f) (cdr elts))))))
1531
+
1532
+ (define (nested-set! root names val)
1533
+ (let loop ((cur root)
1534
+ (elts names))
1535
+ (if (null? (cdr elts))
1536
+ (module-set! cur (car elts) val)
1537
+ (loop (module-ref cur (car elts)) (cdr elts)))))
1538
+
1539
+ (define (nested-define! root names val)
1540
+ (let loop ((cur root)
1541
+ (elts names))
1542
+ (if (null? (cdr elts))
1543
+ (module-define! cur (car elts) val)
1544
+ (loop (module-ref cur (car elts)) (cdr elts)))))
1545
+
1546
+ (define (nested-remove! root names)
1547
+ (let loop ((cur root)
1548
+ (elts names))
1549
+ (if (null? (cdr elts))
1550
+ (module-remove! cur (car elts))
1551
+ (loop (module-ref cur (car elts)) (cdr elts)))))
1552
+
1553
+ (define (local-ref names) (nested-ref (current-module) names))
1554
+ (define (local-set! names val) (nested-set! (current-module) names val))
1555
+ (define (local-define names val) (nested-define! (current-module) names val))
1556
+ (define (local-remove names) (nested-remove! (current-module) names))
1557
+ ;;; boot-9.scm ends here