sproutit-narwhal 0.1.106

Sign up to get free protection for your applications and to get access to all the features.
Files changed (291) hide show
  1. data/DISTRIBUTION.yml +15 -0
  2. data/README.md +86 -0
  3. data/Rakefile +349 -0
  4. data/VERSION.yml +7 -0
  5. data/bin/activate +50 -0
  6. data/bin/activate.bash +50 -0
  7. data/bin/activate.cmd +3 -0
  8. data/bin/js +67 -0
  9. data/bin/json +2 -0
  10. data/bin/narwhal +67 -0
  11. data/bin/narwhal.cmd +29 -0
  12. data/bin/sea +45 -0
  13. data/bin/sea.cmd +25 -0
  14. data/bin/tusk +2 -0
  15. data/bin/tusk.cmd +5 -0
  16. data/catalog.json +902 -0
  17. data/docs/available-packages.md +32 -0
  18. data/docs/browser-api-plan.md +290 -0
  19. data/docs/browser-api.md +153 -0
  20. data/docs/download.md +25 -0
  21. data/docs/engines.md +32 -0
  22. data/docs/json-tool.md +121 -0
  23. data/docs/lib/binary.wiki +242 -0
  24. data/docs/lib/file.wiki +325 -0
  25. data/docs/lib/os/popen.md +70 -0
  26. data/docs/modules.md +38 -0
  27. data/docs/narwhal.md +487 -0
  28. data/docs/packages-howto.md +32 -0
  29. data/docs/packages.md +30 -0
  30. data/docs/posts/2009-07-29-hello-0.1.md +19 -0
  31. data/docs/quick-start.md +69 -0
  32. data/docs/sea.md +49 -0
  33. data/engines/browser/lib/binary.js +2 -0
  34. data/engines/browser/lib/reactor.js +21 -0
  35. data/engines/browser/lib/system.js +3 -0
  36. data/engines/default/lib/array.js +164 -0
  37. data/engines/default/lib/binary-engine.js +53 -0
  38. data/engines/default/lib/binary.js +755 -0
  39. data/engines/default/lib/date.js +8 -0
  40. data/engines/default/lib/file-engine.js +119 -0
  41. data/engines/default/lib/function.js +119 -0
  42. data/engines/default/lib/global.js +11 -0
  43. data/engines/default/lib/io-engine.js +26 -0
  44. data/engines/default/lib/json.js +488 -0
  45. data/engines/default/lib/object.js +69 -0
  46. data/engines/default/lib/os-engine.js +3 -0
  47. data/engines/default/lib/reactor.js +12 -0
  48. data/engines/default/lib/string.js +84 -0
  49. data/engines/default/lib/system.js +20 -0
  50. data/engines/default/lib/worker.js +133 -0
  51. data/engines/jsc/README.md +18 -0
  52. data/engines/jsc/bootstrap.js +53 -0
  53. data/engines/jsc/deps/http-parser/LICENSE +77 -0
  54. data/engines/jsc/deps/http-parser/README.md +145 -0
  55. data/engines/jsc/deps/http-parser/http_parser.c +6087 -0
  56. data/engines/jsc/deps/http-parser/http_parser.h +141 -0
  57. data/engines/jsc/deps/http-parser/http_parser.rl +500 -0
  58. data/engines/jsc/deps/http-parser/test.c +858 -0
  59. data/engines/jsc/include/binary-engine.h +11 -0
  60. data/engines/jsc/include/io-engine.h +23 -0
  61. data/engines/jsc/include/narwhal.h +427 -0
  62. data/engines/jsc/lib/file-engine.js +31 -0
  63. data/engines/jsc/lib/http.js +1 -0
  64. data/engines/jsc/lib/io-engine.js +202 -0
  65. data/engines/jsc/lib/os-engine.js +25 -0
  66. data/engines/jsc/lib/system.js +18 -0
  67. data/engines/jsc/lib/zip.js +1 -0
  68. data/engines/jsc/narwhal-jsc.c +273 -0
  69. data/engines/jsc/narwhal.c +29 -0
  70. data/engines/jsc/package.json +8 -0
  71. data/engines/jsc/src/binary-engine.cc +290 -0
  72. data/engines/jsc/src/file-engine.cc +405 -0
  73. data/engines/jsc/src/io-engine.cc +423 -0
  74. data/engines/jsc/src/jack/handler/jill.cc +710 -0
  75. data/engines/jsc/src/os-engine.cc +210 -0
  76. data/engines/rhino/bin/narwhal-rhino +68 -0
  77. data/engines/rhino/bin/narwhal-rhino.cmd +34 -0
  78. data/engines/rhino/bootstrap.js +119 -0
  79. data/engines/rhino/jars/jline.jar +0 -0
  80. data/engines/rhino/jars/jna.jar +0 -0
  81. data/engines/rhino/jars/js.jar +0 -0
  82. data/engines/rhino/lib/binary-engine.js +83 -0
  83. data/engines/rhino/lib/concurrency.js +6 -0
  84. data/engines/rhino/lib/event-queue.js +18 -0
  85. data/engines/rhino/lib/file-engine.js +216 -0
  86. data/engines/rhino/lib/http-client-engine.js +90 -0
  87. data/engines/rhino/lib/http-engine.js +10 -0
  88. data/engines/rhino/lib/io-engine.js +347 -0
  89. data/engines/rhino/lib/md5-engine.js +40 -0
  90. data/engines/rhino/lib/os-engine.js +150 -0
  91. data/engines/rhino/lib/packages-engine.js +71 -0
  92. data/engines/rhino/lib/sandbox-engine.js +70 -0
  93. data/engines/rhino/lib/system.js +38 -0
  94. data/engines/rhino/lib/worker-engine.js +23 -0
  95. data/engines/rhino/lib/zip.js +78 -0
  96. data/engines/rhino/package.json +4 -0
  97. data/engines/secure/lib/file.js +6 -0
  98. data/engines/secure/lib/system.js +6 -0
  99. data/engines/template/bin/narwhal-engine-name +32 -0
  100. data/engines/template/bootstrap.js +40 -0
  101. data/engines/template/lib/file-engine.js +118 -0
  102. data/engines/template/lib/system.js +17 -0
  103. data/examples/browser-deployment-jackconfig.js +35 -0
  104. data/examples/fibonacci-worker.js +35 -0
  105. data/examples/fibonacci.js +19 -0
  106. data/examples/hello +2 -0
  107. data/examples/narwhal +3 -0
  108. data/examples/not-quite-a-quine.js +1 -0
  109. data/extconf.rb +44 -0
  110. data/gem_bin/narwhal +5 -0
  111. data/gem_bin/sea +4 -0
  112. data/gem_bin/tusk +4 -0
  113. data/lib/args.js +849 -0
  114. data/lib/base16.js +16 -0
  115. data/lib/base64.js +120 -0
  116. data/lib/codec/base64.js +8 -0
  117. data/lib/crc32.js +60 -0
  118. data/lib/file-bootstrap.js +187 -0
  119. data/lib/file.js +659 -0
  120. data/lib/hash.js +28 -0
  121. data/lib/hashp.js +65 -0
  122. data/lib/html.js +16 -0
  123. data/lib/http-client.js +134 -0
  124. data/lib/http.js +17 -0
  125. data/lib/io.js +98 -0
  126. data/lib/jsmin.js +315 -0
  127. data/lib/jsonpath.js +89 -0
  128. data/lib/logger.js +55 -0
  129. data/lib/md4.js +146 -0
  130. data/lib/md5.js +164 -0
  131. data/lib/mime.js +166 -0
  132. data/lib/narwhal.js +102 -0
  133. data/lib/narwhal/client.js +261 -0
  134. data/lib/narwhal/compile.js +99 -0
  135. data/lib/narwhal/env.js +140 -0
  136. data/lib/narwhal/inline.js +106 -0
  137. data/lib/narwhal/json.js +324 -0
  138. data/lib/narwhal/json.md +178 -0
  139. data/lib/narwhal/repl.js +96 -0
  140. data/lib/narwhal/server-test.js +6 -0
  141. data/lib/narwhal/server.js +270 -0
  142. data/lib/narwhal/tusk.js +170 -0
  143. data/lib/narwhal/tusk/bin.js +13 -0
  144. data/lib/narwhal/tusk/bundle.js +0 -0
  145. data/lib/narwhal/tusk/catalog.js +22 -0
  146. data/lib/narwhal/tusk/clone.js +66 -0
  147. data/lib/narwhal/tusk/consolidate.js +25 -0
  148. data/lib/narwhal/tusk/create-catalog.js +80 -0
  149. data/lib/narwhal/tusk/engine.js +42 -0
  150. data/lib/narwhal/tusk/freeze.js +0 -0
  151. data/lib/narwhal/tusk/init.js +56 -0
  152. data/lib/narwhal/tusk/install.js +288 -0
  153. data/lib/narwhal/tusk/list.js +20 -0
  154. data/lib/narwhal/tusk/orphans.js +0 -0
  155. data/lib/narwhal/tusk/reheat.js +15 -0
  156. data/lib/narwhal/tusk/remove.js +15 -0
  157. data/lib/narwhal/tusk/search.js +145 -0
  158. data/lib/narwhal/tusk/update.js +21 -0
  159. data/lib/narwhal/tusk/upgrade.js +0 -0
  160. data/lib/os.js +33 -0
  161. data/lib/packages.js +423 -0
  162. data/lib/printf.js +169 -0
  163. data/lib/promise.js +352 -0
  164. data/lib/querystring.js +176 -0
  165. data/lib/ref-send.js +257 -0
  166. data/lib/regexp.js +12 -0
  167. data/lib/sandbox.js +422 -0
  168. data/lib/sha.js +112 -0
  169. data/lib/sha256.js +102 -0
  170. data/lib/struct.js +228 -0
  171. data/lib/term.js +179 -0
  172. data/lib/test/assert.js +95 -0
  173. data/lib/test/equiv.js +188 -0
  174. data/lib/test/jsdump.js +165 -0
  175. data/lib/test/runner.js +129 -0
  176. data/lib/unload.js +13 -0
  177. data/lib/uri.js +378 -0
  178. data/lib/url.js +5 -0
  179. data/lib/utf8.js +64 -0
  180. data/lib/util.js +985 -0
  181. data/lib/uuid.js +89 -0
  182. data/lib/xregexp.js +521 -0
  183. data/local.json.template +1 -0
  184. data/narwhal.gemspec +105 -0
  185. data/narwhal.js +213 -0
  186. data/package.json +26 -0
  187. data/packages/readline/engines/default/lib/readline.js +4 -0
  188. data/packages/readline/engines/rhino/lib/readline.js +6 -0
  189. data/packages/readline/package.json +5 -0
  190. data/sources.json +207 -0
  191. data/tests/all-tests.js +17 -0
  192. data/tests/args.js +31 -0
  193. data/tests/args/domain.js +215 -0
  194. data/tests/args/options.js +36 -0
  195. data/tests/args/shifting.js +92 -0
  196. data/tests/args/validation.js +31 -0
  197. data/tests/base64.js +23 -0
  198. data/tests/commonjs.js +3 -0
  199. data/tests/commonjs/all-tests.js +12 -0
  200. data/tests/commonjs/bytearray-encodings-tests.js +69 -0
  201. data/tests/commonjs/bytearray-tests.js +465 -0
  202. data/tests/commonjs/bytestring-encodings-tests.js +89 -0
  203. data/tests/commonjs/bytestring-tests.js +263 -0
  204. data/tests/commonjs/es5/all-tests.js +3 -0
  205. data/tests/commonjs/es5/bind.js +29 -0
  206. data/tests/commonjs/file-tests.js +315 -0
  207. data/tests/commonjs/file/dirname.js +31 -0
  208. data/tests/commonjs/file/extension.js +45 -0
  209. data/tests/commonjs/file/is-absolute.js +11 -0
  210. data/tests/commonjs/file/iterator.js +101 -0
  211. data/tests/commonjs/file/normal.js +27 -0
  212. data/tests/commonjs/file/path.js +17 -0
  213. data/tests/commonjs/file/relative.js +42 -0
  214. data/tests/commonjs/file/resolve.js +44 -0
  215. data/tests/commonjs/module-tests.js +9 -0
  216. data/tests/commonjs/modules/absolute/b.js +1 -0
  217. data/tests/commonjs/modules/absolute/program.js +5 -0
  218. data/tests/commonjs/modules/absolute/submodule/a.js +3 -0
  219. data/tests/commonjs/modules/absolute/test.js +9 -0
  220. data/tests/commonjs/modules/all-tests.js +47 -0
  221. data/tests/commonjs/modules/config.js +11 -0
  222. data/tests/commonjs/modules/cyclic/a.js +4 -0
  223. data/tests/commonjs/modules/cyclic/b.js +4 -0
  224. data/tests/commonjs/modules/cyclic/program.js +10 -0
  225. data/tests/commonjs/modules/cyclic/test.js +9 -0
  226. data/tests/commonjs/modules/determinism/program.js +3 -0
  227. data/tests/commonjs/modules/determinism/submodule/a.js +8 -0
  228. data/tests/commonjs/modules/determinism/submodule/b.js +2 -0
  229. data/tests/commonjs/modules/determinism/test.js +9 -0
  230. data/tests/commonjs/modules/exactExports/a.js +3 -0
  231. data/tests/commonjs/modules/exactExports/program.js +4 -0
  232. data/tests/commonjs/modules/exactExports/test.js +9 -0
  233. data/tests/commonjs/modules/hasOwnProperty/hasOwnProperty.js +0 -0
  234. data/tests/commonjs/modules/hasOwnProperty/program.js +3 -0
  235. data/tests/commonjs/modules/hasOwnProperty/test.js +9 -0
  236. data/tests/commonjs/modules/hasOwnProperty/toString.js +0 -0
  237. data/tests/commonjs/modules/method/a.js +12 -0
  238. data/tests/commonjs/modules/method/program.js +8 -0
  239. data/tests/commonjs/modules/method/test.js +9 -0
  240. data/tests/commonjs/modules/missing/program.js +8 -0
  241. data/tests/commonjs/modules/missing/test.js +9 -0
  242. data/tests/commonjs/modules/monkeys/a.js +1 -0
  243. data/tests/commonjs/modules/monkeys/program.js +4 -0
  244. data/tests/commonjs/modules/monkeys/test.js +9 -0
  245. data/tests/commonjs/modules/nested/a/b/c/d.js +3 -0
  246. data/tests/commonjs/modules/nested/program.js +3 -0
  247. data/tests/commonjs/modules/nested/test.js +9 -0
  248. data/tests/commonjs/modules/relative/program.js +5 -0
  249. data/tests/commonjs/modules/relative/submodule/a.js +1 -0
  250. data/tests/commonjs/modules/relative/submodule/b.js +2 -0
  251. data/tests/commonjs/modules/relative/test.js +9 -0
  252. data/tests/commonjs/modules/transitive/a.js +1 -0
  253. data/tests/commonjs/modules/transitive/b.js +1 -0
  254. data/tests/commonjs/modules/transitive/c.js +3 -0
  255. data/tests/commonjs/modules/transitive/program.js +3 -0
  256. data/tests/commonjs/modules/transitive/test.js +9 -0
  257. data/tests/file/all-tests.js +61 -0
  258. data/tests/file/fnmatch.js +102 -0
  259. data/tests/file/glob.js +466 -0
  260. data/tests/file/match.js +102 -0
  261. data/tests/global.js +6 -0
  262. data/tests/global/array.js +19 -0
  263. data/tests/hashes.js +94 -0
  264. data/tests/html.js +13 -0
  265. data/tests/io/stringio.js +21 -0
  266. data/tests/os/all-tests.js +4 -0
  267. data/tests/os/popen.js +41 -0
  268. data/tests/os/system.js +22 -0
  269. data/tests/printf.js +123 -0
  270. data/tests/query-string.js +87 -0
  271. data/tests/sandbox/byte-io.js +20 -0
  272. data/tests/sandbox/fileName.js +3 -0
  273. data/tests/sandbox/foo.js +0 -0
  274. data/tests/sandbox/reload.js +79 -0
  275. data/tests/string.js +35 -0
  276. data/tests/uri.js +41 -0
  277. data/tests/util/all-tests.js +79 -0
  278. data/tests/util/array.js +207 -0
  279. data/tests/util/array/is-arguments.js +29 -0
  280. data/tests/util/array/is-array-like.js +29 -0
  281. data/tests/util/case.js +9 -0
  282. data/tests/util/collection.js +104 -0
  283. data/tests/util/eq.js +57 -0
  284. data/tests/util/expand.js +45 -0
  285. data/tests/util/object.js +125 -0
  286. data/tests/util/operator.js +25 -0
  287. data/tests/util/range.js +19 -0
  288. data/tests/util/repr.js +26 -0
  289. data/tests/util/string.js +34 -0
  290. data/tests/util/unique.js +12 -0
  291. metadata +434 -0
data/lib/mime.js ADDED
@@ -0,0 +1,166 @@
1
+ /**
2
+ This module provides basic functions for handling mime-types. It can
3
+ handle matching mime-types against a list of media-ranges. See section
4
+ 14.1 of the HTTP specification [RFC 2616] for a complete explanation.
5
+
6
+ <http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.1>
7
+
8
+ A port to JavaScript of Joe Gregorio's MIME-Type Parser:
9
+
10
+ <http://code.google.com/p/mimeparse/>
11
+
12
+ Ported by J. Chris Anderson <jchris@apache.org>, targeting the Spidermonkey runtime.
13
+
14
+ To run the tests, open mimeparse-js-test.html in a browser.
15
+ Ported from version 0.1.2.
16
+ Comments are mostly excerpted from the original.
17
+ */
18
+
19
+ var util = require("util");
20
+
21
+ /*** parseMimeType
22
+ Carves up a mime-type and returns an Array of the
23
+ [type, subtype, params] where "params" is a Hash of all
24
+ the parameters for the media range.
25
+
26
+ For example, the media range "application/xhtml;q=0.5" would
27
+ get parsed into::
28
+
29
+ ["application", "xhtml", { "q" : "0.5" }]
30
+ */
31
+ exports.parseMimeType = function (mimeType) {
32
+ var fullType, typeParts, params = {}, parts = mimeType.split(';');
33
+ for (var i=0; i < parts.length; i++) {
34
+ var p = parts[i].split('=');
35
+ if (p.length == 2) {
36
+ params[util.trim(p[0])] = util.trim(p[1]);
37
+ }
38
+ };
39
+ fullType = parts[0].replace(/^\s+/, '').replace(/\s+$/, '');
40
+ if (fullType == '*') fullType = '*/*';
41
+ typeParts = fullType.split('/');
42
+ return [typeParts[0], typeParts[1], params];
43
+ };
44
+
45
+ /*** parseMediaRange
46
+ Carves up a media range and returns an Array of the
47
+ [type, subtype, params] where "params" is a Object with
48
+ all the parameters for the media range.
49
+
50
+ For example, the media range "application/*;q=0.5" would
51
+ get parsed into::
52
+
53
+ ["application", "*", { "q" : "0.5" }]
54
+
55
+ In addition this function also guarantees that there
56
+ is a value for "q" in the params dictionary, filling it
57
+ in with a proper default if necessary.
58
+ */
59
+ exports.parseMediaRange = function (range) {
60
+ var q, parsedType = exports.parseMimeType(range);
61
+ if (!parsedType[2]['q']) {
62
+ parsedType[2]['q'] = '1';
63
+ } else {
64
+ q = parseFloat(parsedType[2]['q']);
65
+ if (isNaN(q)) {
66
+ parsedType[2]['q'] = '1';
67
+ } else if (q > 1 || q < 0) {
68
+ parsedType[2]['q'] = '1';
69
+ }
70
+ }
71
+ return parsedType;
72
+ };
73
+
74
+ /*** fitnessAndQualityParsed
75
+ Find the best match for a given mime-type against
76
+ a list of media_ranges that have already been
77
+ parsed by parseMediaRange(). Returns an array of
78
+ the fitness value and the value of the 'q' quality
79
+ parameter of the best match, or (-1, 0) if no match
80
+ was found. Just as for qualityParsed(), 'parsed_ranges'
81
+ must be a list of parsed media ranges.
82
+ */
83
+ exports.fitnessAndQualityParsed = function (mimeType, parsedRanges) {
84
+ var bestFitness = -1, bestFitQ = 0, target = exports.parseMediaRange(mimeType);
85
+ var targetType = target[0], targetSubtype = target[1], targetParams = target[2];
86
+
87
+ for (var i=0; i < parsedRanges.length; i++) {
88
+ var parsed = parsedRanges[i];
89
+ var type = parsed[0], subtype = parsed[1], params = parsed[2];
90
+ if ((type == targetType || type == "*" || targetType == "*") &&
91
+ (subtype == targetSubtype || subtype == "*" || targetSubtype == "*")) {
92
+ var matchCount = 0;
93
+ for (param in targetParams) {
94
+ if (param != 'q' && params[param] && params[param] == targetParams[param]) {
95
+ matchCount += 1;
96
+ }
97
+ }
98
+
99
+ var fitness = (type == targetType) ? 100 : 0;
100
+ fitness += (subtype == targetSubtype) ? 10 : 0;
101
+ fitness += matchCount;
102
+
103
+ if (fitness > bestFitness) {
104
+ bestFitness = fitness;
105
+ bestFitQ = params["q"];
106
+ }
107
+ }
108
+ };
109
+ return [bestFitness, parseFloat(bestFitQ)];
110
+ };
111
+
112
+ /*** qualityParsed
113
+ Find the best match for a given mime-type against
114
+ a list of media_ranges that have already been
115
+ parsed by parseMediaRange(). Returns the
116
+ 'q' quality parameter of the best match, 0 if no
117
+ match was found. This function bahaves the same as quality()
118
+ except that 'parsedRanges' must be a list of
119
+ parsed media ranges.
120
+ */
121
+ exports.qualityParsed = function (mimeType, parsedRanges) {
122
+ return exports.fitnessAndQualityParsed(mimeType, parsedRanges)[1];
123
+ };
124
+
125
+ /*** quality
126
+ Returns the quality 'q' of a mime-type when compared
127
+ against the media-ranges in ranges. For example::
128
+
129
+ >>> Mimeparse.quality('text/html','text/*;q=0.3, text/html;q=0.7, text/html;level=1, text/html;level=2;q=0.4, *\/*;q=0.5')
130
+ 0.7
131
+ */
132
+ exports.quality = function (mimeType, ranges) {
133
+ return exports.qualityParsed(mimeType, parseRanges(ranges));
134
+ };
135
+
136
+ /*** bestMatch
137
+ Takes a list of supported mime-types and finds the best
138
+ match for all the media-ranges listed in header. The value of
139
+ header must be a string that conforms to the format of the
140
+ HTTP Accept: header. The value of 'supported' is a list of
141
+ mime-types::
142
+
143
+ >>> bestMatch(['application/xbel+xml', 'text/xml'], 'text/*;q=0.5,*\/*; q=0.1')
144
+ 'text/xml'
145
+ */
146
+ exports.bestMatch = function (supported, header) {
147
+ var parsedHeader = parseRanges(header);
148
+ var weighted = [];
149
+ for (var i=0; i < supported.length; i++) {
150
+ weighted.push([
151
+ exports.fitnessAndQualityParsed(supported[i], parsedHeader),
152
+ supported[i]
153
+ ])
154
+ };
155
+ weighted.sort();
156
+ return weighted[weighted.length-1][0][1] ? weighted[weighted.length-1][1] : '';
157
+ };
158
+
159
+ function parseRanges(ranges) {
160
+ var parsedRanges = [], rangeParts = ranges.split(",");
161
+ for (var i=0; i < rangeParts.length; i++) {
162
+ parsedRanges.push(exports.parseMediaRange(rangeParts[i]));
163
+ };
164
+ return parsedRanges;
165
+ };
166
+
data/lib/narwhal.js ADDED
@@ -0,0 +1,102 @@
1
+
2
+ var args = require("args");
3
+
4
+ var parser = exports.parser = new args.Parser();
5
+
6
+ parser.arg('script').optional();
7
+
8
+ parser.help(
9
+ 'Runs the Narwhal JavaScript interpreter.\n' +
10
+ 'If no script is specified, runs interactively.'
11
+ );
12
+
13
+ parser.option('-e', '-c', '--command', 'command')
14
+ .help("evaluate command")
15
+ .todo("eval", "command")
16
+ .halt();
17
+
18
+ parser.option('-m', '--module', 'main')
19
+ .help("run a library module as a script")
20
+ .set()
21
+ .halt();
22
+
23
+ parser.option('-i', '--interactive', 'interactive')
24
+ .help('enter interactive mode after running scripts')
25
+ .set(true)
26
+ .hidden();
27
+
28
+ var modulesGroup = parser.group('modules');
29
+
30
+ modulesGroup.option('-r', '--require', 'module')
31
+ .help("pre-load a module")
32
+ .todo("require", "module");
33
+
34
+ modulesGroup.option('-I', '--include', 'lib')
35
+ .help("add a library")
36
+ .todo("include", "lib");
37
+
38
+ modulesGroup.option('-p', '--package', 'prefix', 'prefixes')
39
+ .help("add a package")
40
+ .push();
41
+
42
+ modulesGroup.option('-P', '--no-packages', 'noPackages')
43
+ .help("don't load packages")
44
+ .set(true);
45
+
46
+ modulesGroup.option('-:', '--path', 'delimiter')
47
+ .help("prints an augmented PATH with all package bins/")
48
+ .todo("path", "delimiter");
49
+
50
+ parser.option('-E', '--no-use-env', 'useEnv')
51
+ .help('ignore environment variables like JS_PATH, NARWHAL_PATH')
52
+ .def(true)
53
+ .set(false)
54
+ .hidden();
55
+
56
+ parser.option('-d', '--debug', 'debug')
57
+ .help('set debug mode, system.debug = true')
58
+ .inc();
59
+
60
+ parser.option('-v', '--verbose', 'verbose')
61
+ .help("verbose mode: trace 'require' calls.")
62
+ .set(true);
63
+
64
+ parser.option('-x', '--shebang', 'shebang')
65
+ .help('skip every line before the Unix #!shebang for non-Unix shebangs')
66
+ .set(true)
67
+ .hidden();
68
+
69
+ parser.option('-u', '--unbuffered')
70
+ .help('unbuffered stdin and stdout; no auto-flush on lines')
71
+ .set(true)
72
+ .hidden();
73
+
74
+ parser.option('-l', '--log', 'level')
75
+ .help('set the log level')
76
+ .choices({'critical': 0, 'error': 1, 'warn': 2, 'info': 3, 'debug': 4});
77
+
78
+ parser.option('-V', '--version')
79
+ .help("print Narwhal version number and exit.")
80
+ .action(function () {
81
+ this.print("Narwhal Version 0.");
82
+ this.exit();
83
+ });
84
+
85
+ parser.option('-O', 'optimize').inc().hidden();
86
+
87
+ parser.option('--narwhal')
88
+ .def('left')
89
+ .choices(['left', 'right'])
90
+ .action(function (options, name, value) {
91
+ this.print(exports[value.toUpperCase()]);
92
+ })
93
+ .halt()
94
+ .hidden();
95
+
96
+ parser.helpful();
97
+
98
+ // and now for something completely different
99
+
100
+ exports.LEFT = " ,\n ,f\n ,t,\n ,:L.\n tL,\n :EDDEKL :Lt\n DDDDLGKKKK ,,tD\n ,GDDfi.itLKKEKL tEi\n DDEEf,,tfLLDEEDL,D\n .GEDEf,itLLfDLDLDDfD\n DDEDLf,,fLLGLLDLDti:DL\n DGDDGL,tttLDLDLfttttiLD\n GDDLLt,fLLLDLLtLi,ttfLG\n GGDGt,tLLLDfftii,i,ttLf\n DGLLtttftftttf,,tttitLt\n DEtftttLffttttii ttfLfj\n .DLtittftLftt,,i,,itLfLj\n DGL;t,tftiti,,,,,,tLLLt\n DGGttttttii,,,,,:,tttDG\n ,DLtjtiitii,,:,:,,t ,tG:\n DDjttttt,ii,,,,:::t:ttL\n ;GLjtttti,i,,, ,,LG,,ft\n DDLttftttti;,,ifDLDtiit\n EGLjtjftt,,,ifLt DLt,:\n DGfffijittfftt .DLLt\n:DGfjffftfLft EEDf\n:EGfftjjLLj EED\n:DGfLfjLGG ;E,\n GGfffLLL\n DGffLDf\n DGLfGL.\n fGLfGL\n DGLDL\n EGGGG\n DLGG\n EGLL\n ELG\n EEDKDGEE\n jKEKKKK\n EEKKKK\n DEE\n .EEKG\n Lf";
101
+ exports.RIGHT = ",\nf,\n ,t,\n .L:,\n ,Lt\n tL: LKEDDE:\n Dt,, KKKKGLDDDD\n iEt LKEKKLti.ifDDG,\n D,LDEEDLLft,,fEEDD\n DfDDLDLDfLLti,fEDEG.\n LD:itDLDLLGLLf,,fLDEDD\n DLittttfLDLDLttt,LGDDGD\n GLftt,iLtLLDLLLf,tLLDDG\n fLtt,i,iitffDLLLt,tGDGG\n tLtittt,,ftttftftttLLGD\n jfLftt iittttffLtttftED\n jLfLti,,i,,ttfLtfttitLD.\n tLLLt,,,,,,ititft,t;LGD\n GDttt,:,,,,,iittttttGGD\n :Gt, t,,:,:,,iitiitjtLD,\n Ltt:t:::,,,,ii,tttttjDD\n tf,,GL,, ,,,i,ittttjLG;\n tiitDLDfi,,;ittttfttLDD\n :,tLD tLfi,,,ttfjtjLGE\n tLLD. ttffttijifffGD\n fDEE tfLftfffjfGD:\n DEE jLLjjtffGE:\n ,E; GGLjfLfGD:\n LLLfffGG\n fDLffGD\n .LGfLGD\n LGfLGf\n LDLGD\n GGGGE\n GGLD\n LLGE\n GLE\n EEGDKDEE\n KKKKEKj\n KKKKEE\n EED\n GKEE.\n fL\n";
102
+
@@ -0,0 +1,261 @@
1
+
2
+ // the catalog, inherited from inline.js, is a lookup table of top level module
3
+ // identifiers to catalog entries. catalog entries include a module factory
4
+ // function and an array of top level identifiers of each dependency.
5
+ var catalog = require.catalog;
6
+ // the requests, is an array of the top-level identifiers sent to
7
+ // require.request before the mechanisms to fulfill those requests were set up.
8
+ // a "request" is like "require" or "require.async" except it just asks that a
9
+ // module be required whenever its transitive dependencies are ready to be
10
+ // loaded.
11
+ var requests = require.requests;
12
+ // a lookup table of module top level identifiers to
13
+ // module exports objects. these are constructed by calling
14
+ // the module factory with (require, exports, ...).
15
+ var modules = {};
16
+ // a lookup table of the top level identifier of any module that has ever been
17
+ // mentioned, either by having been registered, or having been noted in a
18
+ // module's dependency array, to a corresponding promise that will be
19
+ // fullfilled when that module and its transitive dependencies have all been
20
+ // registered, and thus can be loaded synchronously.
21
+ var readys = {};
22
+ // a lookup table of the top level identifier of any module that has ever been
23
+ // mentioned in the dependency array of another catalog entry to a promise that
24
+ // will be fulfilled when that module is registered. registrations come in
25
+ // asynchronously through script injection.
26
+ var arrivals = {};
27
+ // this will eventually be the ref-send promise module.
28
+ var Q;
29
+ // this will eventually be the sandbox function, the requirer.
30
+ var sandbox;
31
+
32
+ require.arrive = function (id) {
33
+ if (catalog['reactor'] && catalog['ref-send'])
34
+ boot();
35
+ };
36
+
37
+ // gets a promise that will be fulfilled when the module corresponding to the
38
+ // given identifier and its transitive dependencies have all been registered,
39
+ // which means that it's safe to call require(id). this function uses the
40
+ // readys lookup table as a memo, constructing promises on demand, and
41
+ // immediately fullfilling them if conditions warrant.
42
+ var getReady = function (id) {
43
+ require.preload([id]); // idempotent
44
+ if (!readys[id])
45
+ readys[id] = Q.defer();
46
+ if (modules[id])
47
+ readys[id].resolve(catalog[id]);
48
+ return readys[id];
49
+ };
50
+
51
+ // gets a promise that will be fulfilled when the module corresponding to the
52
+ // given identifier has been registered, which means that any module depending
53
+ // on this module may be ready.
54
+ var getArrival = function (id) {
55
+ require.preload([id]); // idempotent
56
+ if (!arrivals[id])
57
+ arrivals[id] = Q.defer();
58
+ if (catalog[id])
59
+ arrivals[id].resolve(catalog[id]);
60
+ return arrivals[id];
61
+ };
62
+
63
+ // require.arrive is called by the require.register function defined in
64
+ // inline.js whenever a catalog entry arrives through script injection. the
65
+ // require.arrive function starts off as a stub that does nothing, since there
66
+ // is nothing it can do until the promise and reactor modules arrive. we
67
+ // replace the original arrival method that notices when these modules are
68
+ // ready and initiates the boot process.
69
+ require.arrive = function (id) {
70
+ if (catalog.reactor && catalog['ref-send'])
71
+ boot();
72
+ };
73
+
74
+ // check whether reactor and promise have already arrived
75
+ require.arrive();
76
+
77
+ // use the promise and reactor modules to move on to the next phase of the boot
78
+ // process, which is the creation of a module loader sandbox with normalized
79
+ // globals, primordials, and a system module. after we have all that set up,
80
+ // we can begin watching for the arrival of the requested program module(s).
81
+ function boot() {
82
+
83
+ // create a stub module loader that can load the promise and reactor
84
+ // modules. we have to construct them manually and in the proper order in
85
+ // the absense of a full loader.
86
+ var subRequire = function (id) {return modules[id];};
87
+ modules.reactor = {};
88
+ catalog.reactor.factory(subRequire, modules.reactor);
89
+ Q = modules['ref-send'] = {};
90
+ catalog['ref-send'].factory(subRequire, modules['ref-send']);
91
+
92
+ // a signal that the sandbox has been hooked up and
93
+ // modules may be required.
94
+ var ready = Q.defer();
95
+
96
+ // global public API for asynchronously requiring a module, that will be
97
+ // fulfilled with the module's exports whenever it can be loaded, which
98
+ // entails registration of that module's transitive dependencies.
99
+ require.async = function (id) {
100
+ var q = Q.defer();
101
+ Q.when(ready.promise, function () {
102
+ Q.when(getReady(id).promise, function () {
103
+ q.resolve(sandbox(id));
104
+ }, function () {
105
+ q.reject();
106
+ });
107
+ }, function () {
108
+ q.reject();
109
+ });
110
+ return q.promise;
111
+ };
112
+
113
+ // global public API: a shortcut for attaching callbacks to a promise to be
114
+ // fulfilled when a requested module is ready to be loaded.
115
+ require.when = function (id, fulfilled, rejected) {
116
+ return Q.when(getReady(id).promise, fulfilled, rejected);
117
+ };
118
+
119
+ // we are now ready to make promises about the arrival and readiness of
120
+ // modules. this is the third replacement of the require.arrive event
121
+ // handler called by require.register whenever it gets executed by an
122
+ // injected script. this version will create a graph of promises that will
123
+ // collectively determine when each module is ready.
124
+ require.arrive = function (id) {
125
+ var depends = catalog[id].depends;
126
+ var length = depends.length;
127
+
128
+ // the module has arrived, but it won't be ready until all of its
129
+ // dependencies are ready. this promise will be fulfilled when all the
130
+ // dependencies are ready, and in turn will fulfill this module's ready
131
+ // promise. a module with no dependencies is the basis, so this
132
+ // promise will need to be fulfilled immediately in that case.
133
+ var a = Q.defer();
134
+ Q.when(a.promise, function () {
135
+ getReady(id).resolve(catalog[id]);
136
+ });
137
+
138
+ // create a chain of promises that will be ultimately fulfilled when
139
+ // EVERY dependency is ready.
140
+ for (var i = 0; i < length; i++) {
141
+ var depend = depends[i];
142
+ // trap the previous promise and the dependency name in an
143
+ // enclosure.
144
+ a = (function (a, depend) {
145
+ var b = Q.defer();
146
+ // the new promise is that the previous promise has been
147
+ // fulfilled and this dependency is ready. this is a logical
148
+ // AND promise.
149
+ Q.when(getReady(depend).promise, function () {
150
+ return Q.when(b.promise, function () {
151
+ a.resolve(true);
152
+ });
153
+ })
154
+ return b;
155
+ })(a, depend);
156
+ }
157
+
158
+ // if there are no dependencies, this resolves the original promise and
159
+ // in turn marks this module as ready. if there are dependencies, this
160
+ // half fulfills second operand of the last AND junction among the
161
+ // dependencies, which starts the ball rolling.
162
+ a.resolve(true);
163
+
164
+ // oh, by the way, signal the arrival of this module, so some of my
165
+ // dependees can get ready.
166
+ getArrival(id).resolve(catalog[id]);
167
+ };
168
+
169
+ // process arrivals that have already occurred. the catalog already
170
+ // contains several entries for modules that arrived, but they have not
171
+ // been properly processed with the promise system.
172
+ for (var id in catalog) {
173
+ if (Object.prototype.hasOwnProperty.call(catalog, id)) {
174
+ var entry = catalog[id];
175
+ require.arrive(id);
176
+ }
177
+ }
178
+
179
+ // now that we can use promises to observe when modules are ready
180
+ // to load, we can move on to the next phase: installing a module
181
+ // loader and kicking off the requested programs.
182
+
183
+ // this is another logical AND of promises. when the "sandbox", "global",
184
+ // and "system" modules with all of their transitive dependencies are ready
185
+ // to be loaded, we proceed.
186
+ Q.when(getReady("sandbox").promise, function () {
187
+ return Q.when(getReady("global").promise, function () {
188
+ return Q.when(getReady("system").promise, function () {
189
+
190
+ // the sandbox module needs a semi-functional system object
191
+ var system = {};
192
+ system.print = function () {
193
+ if (typeof console != "undefined") {
194
+ console.log(Array.prototype.join.call(arguments, ' '));
195
+ }
196
+ };
197
+ system.fs = {
198
+ normal: function (path) {
199
+ return path;
200
+ }
201
+ };
202
+ system.engine = "browser";
203
+ system.engines = ["browser"];
204
+
205
+ // the loader is relatively simple since it doesn't need to do
206
+ // any searching or extension resolving.
207
+ var loader = {};
208
+ loader.reload = function (id) {
209
+ if (!catalog[id])
210
+ throw new Error(id + " has not been preloaded.");
211
+ return catalog[id].factory;
212
+ };
213
+ loader.load = function (id) {
214
+ return loader.reload(id);
215
+ };
216
+
217
+ // load the sandbox module manually.
218
+ var SANDBOX = {};
219
+ loader.load('sandbox')(
220
+ function () {return system},
221
+ SANDBOX,
222
+ {},
223
+ system,
224
+ system.print
225
+ );
226
+ sandbox = SANDBOX.Sandbox({loader: loader});
227
+ // patch the loader with the sandbox module's general purpose resolve
228
+ // function.
229
+ loader.resolve = SANDBOX.resolve;
230
+
231
+ sandbox.async = require.async;
232
+
233
+ // apply the system module to the existing system object
234
+ sandbox.force("system");
235
+ // patch the primordials to approach something near ES5 compliance
236
+ sandbox("global");
237
+
238
+ // up to this point, the require(id) function defined in inline.js
239
+ // defers to require.require(id), if it is defined. otherwise it
240
+ // throws an error. now, we have a sandbox, so we can return modules.
241
+ require.require = sandbox;
242
+
243
+ // notify any requested module programs that they may
244
+ // require modules.
245
+ ready.resolve(true);
246
+
247
+ // we now have all of the plumbing to request, register, load, and
248
+ // require modules. we have a backlog of module's to request (these
249
+ // were deferred by the require.request function defined in inline.js).
250
+ // with our new require.request method, complete those requests.
251
+ var length = requests.length;
252
+ for (var i = 0; i < length; i++) {
253
+ var id = requests[i];
254
+ require.async(id);
255
+ }
256
+
257
+ // because lisp wasn't bad enough
258
+ });});});
259
+
260
+ }
261
+