opal 0.3.2 → 0.3.6

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 (203) hide show
  1. data/README.md +85 -127
  2. data/bin/opal +3 -3
  3. data/lib/core.rb +114 -0
  4. data/{gems/core/lib → lib}/core/array.rb +68 -187
  5. data/{gems/core/lib → lib}/core/basic_object.rb +22 -5
  6. data/lib/core/class.rb +38 -0
  7. data/{gems/core/lib → lib}/core/dir.rb +1 -1
  8. data/lib/core/enumerable.rb +33 -0
  9. data/{gems/core/lib → lib}/core/error.rb +1 -4
  10. data/{gems/core/lib → lib}/core/false_class.rb +0 -0
  11. data/{gems/core/lib → lib}/core/file.rb +11 -3
  12. data/{gems/core/lib → lib}/core/hash.rb +12 -0
  13. data/{gems/core/lib → lib}/core/kernel.rb +114 -86
  14. data/lib/core/match_data.rb +33 -0
  15. data/lib/core/module.rb +97 -0
  16. data/{gems/core/lib → lib}/core/nil_class.rb +0 -0
  17. data/{gems/core/lib → lib}/core/numeric.rb +5 -0
  18. data/{gems/core/lib → lib}/core/object.rb +0 -0
  19. data/{gems/core/lib → lib}/core/proc.rb +13 -3
  20. data/{gems/core/lib → lib}/core/range.rb +10 -0
  21. data/{gems/core/lib → lib}/core/regexp.rb +33 -1
  22. data/{gems/core/lib → lib}/core/string.rb +25 -10
  23. data/{gems/core/lib → lib}/core/symbol.rb +3 -3
  24. data/{gems/core/lib → lib}/core/top_self.rb +0 -0
  25. data/{gems/core/lib → lib}/core/true_class.rb +0 -0
  26. data/lib/dev.rb +169 -0
  27. data/{gems/ospec/lib → lib}/ospec.rb +1 -0
  28. data/lib/ospec/autorun.rb +8 -0
  29. data/{gems/ospec/lib → lib}/ospec/dsl.rb +2 -2
  30. data/{gems/ospec/lib → lib}/ospec/example.rb +0 -0
  31. data/{gems/ospec/lib → lib}/ospec/example/before_and_after_hooks.rb +0 -0
  32. data/{gems/ospec/lib → lib}/ospec/example/errors.rb +0 -0
  33. data/{gems/ospec/lib → lib}/ospec/example/example_group.rb +0 -0
  34. data/{gems/ospec/lib → lib}/ospec/example/example_group_factory.rb +0 -3
  35. data/{gems/ospec/lib → lib}/ospec/example/example_group_hierarchy.rb +4 -3
  36. data/{gems/ospec/lib → lib}/ospec/example/example_group_methods.rb +1 -1
  37. data/{gems/ospec/lib → lib}/ospec/example/example_group_proxy.rb +3 -2
  38. data/{gems/ospec/lib → lib}/ospec/example/example_methods.rb +1 -1
  39. data/{gems/ospec/lib → lib}/ospec/example/example_proxy.rb +7 -7
  40. data/{gems/ospec/lib → lib}/ospec/expectations.rb +0 -0
  41. data/{gems/ospec/lib → lib}/ospec/expectations/errors.rb +0 -0
  42. data/{gems/ospec/lib → lib}/ospec/expectations/fail_with.rb +4 -3
  43. data/{gems/ospec/lib → lib}/ospec/expectations/handler.rb +6 -0
  44. data/lib/ospec/helpers/scratch.rb +18 -0
  45. data/{gems/ospec/lib → lib}/ospec/matchers.rb +2 -2
  46. data/{gems/ospec/lib → lib}/ospec/matchers/be.rb +0 -0
  47. data/{gems/ospec/lib → lib}/ospec/matchers/generated_descriptions.rb +0 -0
  48. data/{gems/ospec/lib → lib}/ospec/matchers/operator_matcher.rb +2 -0
  49. data/lib/ospec/matchers/raise_error.rb +38 -0
  50. data/lib/ospec/runner.rb +90 -0
  51. data/{gems/ospec/lib → lib}/ospec/runner/example_group_runner.rb +10 -13
  52. data/lib/ospec/runner/formatter/html_formatter.rb +139 -0
  53. data/{gems/ospec/lib → lib}/ospec/runner/formatter/terminal_formatter.rb +0 -0
  54. data/{gems/ospec/lib → lib}/ospec/runner/options.rb +1 -3
  55. data/{gems/ospec/lib → lib}/ospec/runner/reporter.rb +0 -9
  56. data/lib/racc/parser.rb +165 -0
  57. data/lib/strscan.rb +52 -0
  58. data/{lib → opal_lib}/opal.rb +2 -0
  59. data/opal_lib/opal/build_methods.rb +51 -0
  60. data/opal_lib/opal/builder.rb +164 -0
  61. data/opal_lib/opal/bundle.rb +70 -0
  62. data/opal_lib/opal/command.rb +68 -0
  63. data/{lib → opal_lib}/opal/context.rb +21 -9
  64. data/{lib → opal_lib}/opal/context/console.rb +0 -2
  65. data/opal_lib/opal/context/file_system.rb +34 -0
  66. data/{lib → opal_lib}/opal/context/loader.rb +26 -8
  67. data/opal_lib/opal/gem.rb +84 -0
  68. data/{lib → opal_lib}/opal/rake/builder_task.rb +2 -2
  69. data/opal_lib/opal/rake/spec_task.rb +32 -0
  70. data/{lib → opal_lib}/opal/ruby/nodes.rb +730 -109
  71. data/{lib → opal_lib}/opal/ruby/parser.rb +90 -23
  72. data/opal_lib/opal/ruby/ruby_parser.rb +4862 -0
  73. data/opal_lib/opal/ruby/ruby_parser.y +1454 -0
  74. data/opal_lib/opal/version.rb +4 -0
  75. data/runtime/class.js +359 -0
  76. data/runtime/debug.js +84 -0
  77. data/runtime/fs.js +199 -0
  78. data/runtime/init.js +558 -0
  79. data/runtime/loader.js +351 -0
  80. data/runtime/module.js +109 -0
  81. data/runtime/post.js +10 -0
  82. data/runtime/pre.js +7 -0
  83. data/runtime/runtime.js +351 -0
  84. metadata +88 -175
  85. data/.gitignore +0 -7
  86. data/Changelog +0 -31
  87. data/LICENSE +0 -75
  88. data/Rakefile +0 -86
  89. data/gems/core/README.md +0 -14
  90. data/gems/core/Rakefile +0 -8
  91. data/gems/core/core.gemspec +0 -13
  92. data/gems/core/lib/core.rb +0 -34
  93. data/gems/core/lib/core/class.rb +0 -31
  94. data/gems/core/lib/core/module.rb +0 -100
  95. data/gems/core/lib/core/vm.rb +0 -16
  96. data/gems/core/spec/core/array/append_spec.rb +0 -30
  97. data/gems/core/spec/core/array/assoc_spec.rb +0 -29
  98. data/gems/core/spec/core/array/at_spec.rb +0 -37
  99. data/gems/core/spec/core/array/clear_spec.rb +0 -22
  100. data/gems/core/spec/core/array/collect_bang_spec.rb +0 -27
  101. data/gems/core/spec/core/array/collect_spec.rb +0 -27
  102. data/gems/core/spec/core/array/compact_spec.rb +0 -41
  103. data/gems/core/spec/core/array/concat_spec.rb +0 -15
  104. data/gems/core/spec/core/array/constructor_spec.rb +0 -14
  105. data/gems/core/spec/core/array/each_spec.rb +0 -9
  106. data/gems/core/spec/core/array/element_reference_spec.rb +0 -4
  107. data/gems/core/spec/core/array/first_spec.rb +0 -35
  108. data/gems/core/spec/core/array/include_spec.rb +0 -9
  109. data/gems/core/spec/core/array/join_spec.rb +0 -6
  110. data/gems/core/spec/core/array/last_spec.rb +0 -51
  111. data/gems/core/spec/core/array/length_spec.rb +0 -6
  112. data/gems/core/spec/core/array/map_spec.rb +0 -33
  113. data/gems/core/spec/core/array/reverse_spec.rb +0 -6
  114. data/gems/core/spec/core/builtin_constants/builtin_constants_spec.rb +0 -7
  115. data/gems/core/spec/core/false/and_spec.rb +0 -10
  116. data/gems/core/spec/core/false/inspect_spec.rb +0 -6
  117. data/gems/core/spec/core/false/or_spec.rb +0 -10
  118. data/gems/core/spec/core/false/to_s_spec.rb +0 -6
  119. data/gems/core/spec/core/false/xor_spec.rb +0 -10
  120. data/gems/core/spec/core/file/join_spec.rb +0 -19
  121. data/gems/core/spec/core/hash/assoc_spec.rb +0 -32
  122. data/gems/core/spec/core/kernel/instance_eval_spec.rb +0 -0
  123. data/gems/core/spec/core/kernel/loop_spec.rb +0 -24
  124. data/gems/core/spec/core/kernel/raise_spec.rb +0 -0
  125. data/gems/core/spec/core/module/attr_accessor_spec.rb +0 -28
  126. data/gems/core/spec/core/number/lt_spec.rb +0 -12
  127. data/gems/core/spec/core/string/sub_spec.rb +0 -24
  128. data/gems/core/spec/core/true/and_spec.rb +0 -10
  129. data/gems/core/spec/core/true/inspect_spec.rb +0 -6
  130. data/gems/core/spec/core/true/or_spec.rb +0 -10
  131. data/gems/core/spec/core/true/to_s_spec.rb +0 -6
  132. data/gems/core/spec/core/true/xor_spec.rb +0 -10
  133. data/gems/core/spec/language/and_spec.rb +0 -61
  134. data/gems/core/spec/language/array_spec.rb +0 -68
  135. data/gems/core/spec/language/block_spec.rb +0 -38
  136. data/gems/core/spec/language/break_spec.rb +0 -36
  137. data/gems/core/spec/language/case_spec.rb +0 -103
  138. data/gems/core/spec/language/def_spec.rb +0 -21
  139. data/gems/core/spec/language/eigenclass_spec.rb +0 -60
  140. data/gems/core/spec/language/file_spec.rb +0 -13
  141. data/gems/core/spec/language/fixtures/block.rb +0 -21
  142. data/gems/core/spec/language/fixtures/super.rb +0 -293
  143. data/gems/core/spec/language/hash_spec.rb +0 -29
  144. data/gems/core/spec/language/if_spec.rb +0 -54
  145. data/gems/core/spec/language/loop_spec.rb +0 -11
  146. data/gems/core/spec/language/metaclass_spec.rb +0 -21
  147. data/gems/core/spec/language/method_spec.rb +0 -124
  148. data/gems/core/spec/language/next_spec.rb +0 -25
  149. data/gems/core/spec/language/or_spec.rb +0 -34
  150. data/gems/core/spec/language/redo_spec.rb +0 -24
  151. data/gems/core/spec/language/regexp_spec.rb +0 -26
  152. data/gems/core/spec/language/rescue_spec.rb +0 -20
  153. data/gems/core/spec/language/return_spec.rb +0 -47
  154. data/gems/core/spec/language/string_spec.rb +0 -25
  155. data/gems/core/spec/language/super_spec.rb +0 -32
  156. data/gems/core/spec/language/until_spec.rb +0 -157
  157. data/gems/core/spec/language/variables_spec.rb +0 -155
  158. data/gems/core/spec/language/while_spec.rb +0 -163
  159. data/gems/core/spec/spec_helper.rb +0 -5
  160. data/gems/core_fs/README.md +0 -19
  161. data/gems/dev/Rakefile +0 -5
  162. data/gems/dev/lib/dev.js +0 -99
  163. data/gems/dev/lib/dev/generator.js +0 -1264
  164. data/gems/dev/lib/dev/parser.js +0 -979
  165. data/gems/dev/lib/dev/ruby_parser.js +0 -1088
  166. data/gems/dev/lib/dev/ruby_parser.y +0 -1267
  167. data/gems/dev/lib/dev/string_scanner.js +0 -38
  168. data/gems/dev/tools/racc2js/README.md +0 -39
  169. data/gems/dev/tools/racc2js/math_parser.js +0 -222
  170. data/gems/dev/tools/racc2js/math_parser.rb +0 -133
  171. data/gems/dev/tools/racc2js/math_parser.y +0 -28
  172. data/gems/dev/tools/racc2js/parser.js +0 -218
  173. data/gems/dev/tools/racc2js/racc2js.rb +0 -153
  174. data/gems/json/README.md +0 -4
  175. data/gems/json/json.gemspec +0 -14
  176. data/gems/json/lib/json.rb +0 -64
  177. data/gems/json/lib/json/ext.rb +0 -51
  178. data/gems/json/lib/json/json2.js +0 -481
  179. data/gems/ospec/README.md +0 -0
  180. data/gems/ospec/lib/ospec/autorun.rb +0 -3
  181. data/gems/ospec/lib/ospec/runner.rb +0 -40
  182. data/gems/ospec/lib/ospec/runner/formatter/html_formatter.rb +0 -91
  183. data/gems/ospec/ospec.gemspec +0 -0
  184. data/gems/rquery/README.md +0 -9
  185. data/gems/rquery/lib/rquery.rb +0 -10
  186. data/gems/rquery/lib/rquery/ajax.rb +0 -4
  187. data/gems/rquery/lib/rquery/css.rb +0 -96
  188. data/gems/rquery/lib/rquery/document.rb +0 -25
  189. data/gems/rquery/lib/rquery/element.rb +0 -292
  190. data/gems/rquery/lib/rquery/event.rb +0 -108
  191. data/gems/rquery/lib/rquery/jquery.js +0 -8177
  192. data/gems/rquery/lib/rquery/request.rb +0 -138
  193. data/gems/rquery/lib/rquery/response.rb +0 -49
  194. data/gems/rquery/rquery.gemspec +0 -16
  195. data/lib/opal.js +0 -1597
  196. data/lib/opal/builder.rb +0 -117
  197. data/lib/opal/bundle.rb +0 -131
  198. data/lib/opal/command.rb +0 -11
  199. data/lib/opal/context/file_system.rb +0 -19
  200. data/lib/opal/gem.rb +0 -153
  201. data/lib/opal/ruby/ruby_parser.rb +0 -5170
  202. data/lib/opal/ruby/ruby_parser.y +0 -1298
  203. data/opal.gemspec +0 -15
data/runtime/loader.js ADDED
@@ -0,0 +1,351 @@
1
+
2
+ /**
3
+ Valid file extensions opal can load/run
4
+ */
5
+ var load_extensions = {};
6
+
7
+ load_extensions['.js'] = function(loader, path) {
8
+ var source = loader.file_contents(path);
9
+ return load_execute_file(loader, source, path);
10
+ };
11
+
12
+ load_extensions['.rb'] = function(loader, path) {
13
+ var source = loader.ruby_file_contents(path);
14
+ return load_execute_file(loader, source, path);
15
+ };
16
+
17
+ /**
18
+ Require a file by its given lib path/id, or a full path.
19
+
20
+ @param {String} id lib path/name
21
+ @return {Boolean}
22
+ */
23
+ var load_require = Op.require = Rt.require = function(lib) {
24
+ var resolved = Op.loader.resolve_lib(lib);
25
+ var cached = Op.cache[resolved];
26
+
27
+ // If we have a cache for this require then it has already been
28
+ // required. We return false to indicate this.
29
+ if (cached) return false;
30
+
31
+ Op.cache[resolved] = true;
32
+
33
+ // try/catch wrap entire file load?
34
+ load_file(Op.loader, resolved);
35
+
36
+ return true;
37
+ };
38
+
39
+ /**
40
+ Sets the primary 'gem', by name, so we know which cwd to use etc.
41
+ This can be changed at anytime, but it is only really recomended
42
+ before the application is run.
43
+
44
+ Also, if a gem with the given name cannot be found, then an error
45
+ will/should be thrown.
46
+
47
+ @param {String} name The root gem name to use
48
+ */
49
+ Op.primary = function(name) {
50
+ Fs.cwd = '/' + name;
51
+ };
52
+
53
+ /**
54
+ Just go ahead and run the given block of code. The passed function
55
+ should rake the usual runtime, self and file variables which it will
56
+ be passed.
57
+
58
+ @param {Function} body
59
+ */
60
+ Op.run = function(body) {
61
+ var res = Qnil;
62
+
63
+ if (typeof body != 'function') {
64
+ throw new Error("Expected body to be a function");
65
+ }
66
+
67
+ try {
68
+ res = body(Rt, Rt.top, "(opal)");
69
+ }
70
+ catch (exc) {
71
+ var exc, stack;
72
+
73
+ if (exc && exc['@message']) {
74
+ puts(exc.$klass.__classid__ + ': ' + exc['@message']);
75
+ }
76
+ else {
77
+ puts('NativeError: ' + exc.message);
78
+ }
79
+
80
+ // first try (if in debug mode...)
81
+ if (typeof OPAL_DEBUG != 'undefined') {
82
+ puts(stack);
83
+ Db.stack = [];
84
+ }
85
+ else if (stack = exc.stack) {
86
+ puts(stack);
87
+ }
88
+ }
89
+ return res;
90
+ };
91
+
92
+ /**
93
+ Register a lib or gem with the given info. If info is an object then
94
+ a gem will be registered with the object represented a JSON version
95
+ of the gemspec for the gem. If the info is simply a function (or
96
+ string?) then a singular lib will be registerd with the function as
97
+ its body.
98
+
99
+ @param {String} name The lib/gem name
100
+ @param {Object, Function} info
101
+ */
102
+ Op.register = function(name, info) {
103
+ // make sure name is useful
104
+ if (typeof name !== 'string') {
105
+ throw new Error("Cannot register a lib without a proper name");
106
+ }
107
+
108
+ // registering a lib/file?
109
+ if (typeof info === 'string' || typeof info === 'function') {
110
+ load_register_lib(name, info);
111
+ }
112
+ // registering a gem?
113
+ else if (typeof info === 'object') {
114
+ load_register_gem(name, info);
115
+ }
116
+ // something has gone wrong..
117
+ else {
118
+ throw new Error("Invalid gem/lib data for '" + name + "'");
119
+ }
120
+ };
121
+
122
+ /**
123
+ Actually register a predefined gem. This is for the browser context
124
+ where gems can be serialized into JSON and defined before hand.
125
+
126
+ @param {String} name Gem name
127
+ @param {Object} info Serialized gemspec
128
+ */
129
+ function load_register_gem(name, info) {
130
+ var factories = Op.loader.factories,
131
+ paths = Op.loader.paths;
132
+
133
+ // register all lib files
134
+ var files = info.files || {};
135
+
136
+ // root dir for gem is '/gem_name'
137
+ var root_dir = '/' + name;
138
+
139
+ // for now assume './lib' as dir for all libs (should be dynamic..)
140
+ var lib_dir = './lib';
141
+
142
+ // add lib dir to paths
143
+ paths.unshift(fs_expand_path(fs_join(root_dir, lib_dir)));
144
+
145
+ for (var file in files) {
146
+ if (files.hasOwnProperty(file)) {
147
+ var file_path = fs_expand_path(fs_join(root_dir, file));
148
+ factories[file_path] = files[file];
149
+ }
150
+ }
151
+
152
+ // register other info? (version etc??)
153
+ }
154
+
155
+ /**
156
+ Register a single lib/file in browser before its needed. These libs
157
+ are added to top level dir '/lib_name.rb'
158
+
159
+ @param {String} name Lib name
160
+ @param {Function, String} factory
161
+ */
162
+ function load_register_lib(name, factory) {
163
+ var path = '/' + name;
164
+ Op.loader.factories[path] = factory;
165
+ }
166
+
167
+ /**
168
+ The loader is the core machinery used for loading and executing libs
169
+ within opal. An instance of opal will have a `.loader` property which
170
+ is an instance of this Loader class. A Loader is responsible for
171
+ finding, opening and reading contents of libs on disk. Within the
172
+ browser a loader may use XHR requests or cached libs defined by JSON
173
+ to load required libs/gems.
174
+
175
+ @constructor
176
+ @param {opal} opal Opal instance to use
177
+ */
178
+ function Loader(opal) {
179
+ this.opal = opal;
180
+ this.paths = ['', '/lib'];
181
+ this.factories = {};
182
+ return this;
183
+ }
184
+
185
+ // For minimizing
186
+ var Lp = Loader.prototype;
187
+
188
+ /**
189
+ The paths property is an array of disk paths in which to search for
190
+ required modules. In the browser this functionality isn't really used.
191
+
192
+ This array is created within the constructor method for uniqueness
193
+ between instances for correct sandboxing.
194
+ */
195
+ Lp.paths = null;
196
+
197
+ /**
198
+ factories of registered packages, paths => function/string. This is
199
+ generic, but in reality only the browser uses this, and it is treated
200
+ as the mini filesystem. Not just factories can go here, anything can!
201
+ Images, text, json, whatever.
202
+ */
203
+ Lp.factories = {};
204
+
205
+ /**
206
+ Resolves the path to the lib, which can then be used to load. This
207
+ will throw an error if the module cannot be found. If this method
208
+ returns a successful path, then subsequent methods can assume that
209
+ the path exists.
210
+
211
+ @param {String} lib The lib name/path to look for
212
+ @return {String}
213
+ */
214
+ Lp.resolve_lib = function(lib) {
215
+ var resolved = this.find_lib(lib, this.paths);
216
+
217
+ if (!resolved) {
218
+ throw new Error("LoadError: no such file to load -- " + lib);
219
+ }
220
+
221
+ return resolved;
222
+ };
223
+
224
+ /**
225
+ Locates the lib/file using the given paths.
226
+
227
+ @param {String} lib The lib path/file to look for
228
+ @param {Array} paths Load paths to use
229
+ @return {String} Located path
230
+ */
231
+ Lp.find_lib = function(id, paths) {
232
+ var extensions = this.valid_extensions, factories = this.factories, candidate;
233
+
234
+ for (var i = 0, ii = extensions.length; i < ii; i++) {
235
+ for (var j = 0, jj = paths.length; j < jj; j++) {
236
+ candidate = fs_join(paths[j], id + extensions[i]);
237
+
238
+ if (factories[candidate]) {
239
+ return candidate;
240
+ }
241
+ }
242
+ }
243
+
244
+ // try full path (we try to load absolute path!)
245
+ if (factories[id]) {
246
+ return id;
247
+ }
248
+
249
+ // try full path with each extension
250
+ for (var i = 0; i < extensions.length; i++) {
251
+ candidate = id + extensions[i];
252
+ if (factories[candidate]) {
253
+ return candidate;
254
+ }
255
+ }
256
+
257
+ // try each path with no extension (if id already has extension)
258
+ for (var i = 0; i < paths.length; i++) {
259
+ candidate = fs_join(paths[j], id);
260
+
261
+ if (factories[candidate]) {
262
+ return candidate;
263
+ }
264
+ }
265
+
266
+ return null;
267
+ };
268
+
269
+ /**
270
+ Valid factory format for use in require();
271
+ */
272
+ Lp.valid_extensions = ['.js', '.rb'];
273
+
274
+ /**
275
+ Get lib contents for js files
276
+ */
277
+ Lp.file_contents = function(path) {
278
+ return this.factories[path];
279
+ };
280
+
281
+ Lp.ruby_file_contents = function(path) {
282
+ return this.factories[path];
283
+ };
284
+
285
+ /**
286
+ Actually run file with resolved name.
287
+
288
+ @param {Loader} loader
289
+ @param {String} path
290
+ */
291
+ function load_file(loader, path) {
292
+ var ext = load_extensions[PATH_RE.exec(path)[3] || '.js'];
293
+
294
+ if (!ext) {
295
+ throw new Error("load_run_file - Bad extension for resolved path");
296
+ }
297
+
298
+ ext(loader, path);
299
+ }
300
+
301
+ /**
302
+ Run content which must now be javascript. Arguments we pass to func
303
+ are:
304
+
305
+ $rb
306
+ top_self
307
+ filename
308
+
309
+ @param {String, Function} content
310
+ @param {String} path
311
+ */
312
+ function load_execute_file(loader, content, path) {
313
+ var args = [Rt, top_self, path];
314
+
315
+ if (typeof content === 'function') {
316
+ return content.apply(Op, args);
317
+
318
+ } else if (typeof content === 'string') {
319
+ var func = loader.wrap(content, path);
320
+ return func.apply(Op, args);
321
+
322
+ } else {
323
+ throw new Error(
324
+ "Loader.execute - bad content sent for '" + path + "'");
325
+ }
326
+ }
327
+
328
+ /**
329
+ Getter method for getting the load path for opal.
330
+
331
+ @param {String} id The globals id being retrieved.
332
+ @return {Array} Load paths
333
+ */
334
+ function load_path_getter(id) {
335
+ return Rt.A(opal.loader.paths);
336
+ }
337
+
338
+ /**
339
+ Getter method to get all loaded features.
340
+
341
+ @param {String} id Feature global id
342
+ @return {Array} Loaded features
343
+ */
344
+ function loaded_feature_getter(id) {
345
+ return loaded_features;
346
+ }
347
+
348
+ function obj_require(obj, path) {
349
+ return Rt.require(path) ? Qtrue : Qfalse;
350
+ }
351
+
data/runtime/module.js ADDED
@@ -0,0 +1,109 @@
1
+
2
+ /**
3
+ Define a top level module with the given id
4
+ */
5
+ function define_module(id) {
6
+ return define_module_under(cObject, id);
7
+ };
8
+
9
+ function define_module_under(base, id) {
10
+ var module;
11
+
12
+ if (const_defined(base, id)) {
13
+ module = const_get(base, id);
14
+ if (module.$flags & T_MODULE) {
15
+ return module;
16
+ }
17
+
18
+ throw new Error(id + " is not a module.");
19
+ }
20
+
21
+ module = define_module_id(id);
22
+
23
+ if (base == cObject) {
24
+ name_class(module, id);
25
+ } else {
26
+ name_class(module, base.__classid__ + '::' + id);
27
+ }
28
+
29
+ const_set(base, id, module);
30
+ module.$parent = base;
31
+ return module;
32
+ };
33
+
34
+ function define_module_id(id) {
35
+ var module = class_create(cModule);
36
+ make_metaclass(module, cModule);
37
+
38
+ module.$flags = T_MODULE;
39
+ module.$included_in = [];
40
+ return module;
41
+ };
42
+
43
+ function mod_create() {
44
+ return class_boot(cModule);
45
+ };
46
+
47
+ function include_module(klass, module) {
48
+
49
+ if (!klass.$included_modules) {
50
+ klass.$included_modules = [];
51
+ }
52
+
53
+ if (klass.$included_modules.indexOf(module) != -1) {
54
+ return;
55
+ }
56
+ klass.$included_modules.push(module);
57
+
58
+ if (!module.$included_in) {
59
+ module.$included_in = [];
60
+ }
61
+
62
+ module.$included_in.push(klass);
63
+
64
+ for (var method in module.$method_table) {
65
+ if (module.$method_table.hasOwnProperty(method)) {
66
+ define_raw_method(klass, method,
67
+ module.$m_tbl[method],
68
+ module.$m_tbl['$' + method]);
69
+ }
70
+ }
71
+
72
+ for (var constant in module.$c) {
73
+ if (module.$c.hasOwnProperty(constant)) {
74
+ const_set(klass, constant, module.$c[constant]);
75
+ }
76
+ }
77
+ };
78
+
79
+ Rt.include_module = include_module;
80
+
81
+ function extend_module(klass, module) {
82
+ if (!klass.$extended_modules) {
83
+ klass.$extended_modules = [];
84
+ }
85
+
86
+ if (klass.$extended_modules.indexOf(module) != -1) {
87
+ return;
88
+ }
89
+ klass.$extended_modules.push(module);
90
+
91
+ if (!module.$extended_in) {
92
+ module.$extended_in = [];
93
+ }
94
+
95
+ module.$extended_in.push(klass);
96
+
97
+ var meta = klass.$klass;
98
+
99
+ for (var method in module.$method_table) {
100
+ if (module.$method_table.hasOwnProperty(method)) {
101
+ define_raw_method(meta, method,
102
+ module.$m_tbl[method],
103
+ module.$m_tbl['$' + method]);
104
+ }
105
+ }
106
+ };
107
+
108
+ Rt.extend_module = extend_module;
109
+