opal 0.0.1 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (306) hide show
  1. data/.gitignore +10 -1
  2. data/.gitmodules +0 -0
  3. data/Opalfile +371 -0
  4. data/README.md +45 -0
  5. data/Rakefile +237 -34
  6. data/VERSION +1 -1
  7. data/bin/opal +13 -0
  8. data/demos/apps/browser_demo/index.html +11 -0
  9. data/demos/apps/browser_demo/lib/browser_demo.rb +31 -0
  10. data/demos/apps/simple_opal/Opalfile +13 -0
  11. data/demos/apps/simple_opal/index.html +11 -0
  12. data/demos/apps/simple_opal/lib/app_controller.rb +62 -0
  13. data/demos/apps/simple_opal/lib/main_window.rb +146 -0
  14. data/demos/browser/request/index.html +52 -0
  15. data/demos/browser/request/request.rb +48 -0
  16. data/gen/browser/__PROJECT_NAME__/index.html +10 -0
  17. data/gen/browser/__PROJECT_NAME__/lib/__PROJECT_NAME__.rb +1 -0
  18. data/lib/opal.rb +48 -3
  19. data/lib/opal/builders/base.rb +50 -0
  20. data/lib/opal/builders/css.rb +46 -0
  21. data/lib/opal/builders/javascript.rb +44 -0
  22. data/lib/opal/builders/opal.rb +79 -0
  23. data/lib/opal/builders/ruby.rb +50 -0
  24. data/lib/opal/builders/ruby/generate.rb +1851 -0
  25. data/lib/opal/builders/ruby/nodes.rb +210 -0
  26. data/lib/opal/builders/ruby/ruby.rb +916 -0
  27. data/lib/opal/builders/ruby/ruby_parser.rb +6008 -0
  28. data/lib/opal/builders/ruby/ruby_parser.rb.y +1451 -0
  29. data/lib/opal/models/build_item.rb +104 -0
  30. data/lib/opal/models/hash_struct.rb +40 -0
  31. data/lib/opal/models/project.rb +215 -0
  32. data/lib/opal/models/struct_accessors.rb +58 -0
  33. data/lib/opal/models/target.rb +176 -0
  34. data/lib/opal/opal/env/console.rb +66 -0
  35. data/lib/opal/opal/env/fs.rb +98 -0
  36. data/lib/opal/opal/env/object.rb +48 -0
  37. data/lib/opal/opal/environment.rb +139 -0
  38. data/lib/opal/opal/gen.rb +62 -0
  39. data/lib/opal/opal/opal.rb +68 -0
  40. data/lib/opal/opal/repl.rb +38 -0
  41. data/lib/opal/opalfile/dsl.rb +62 -0
  42. data/lib/opal/opalfile/opalfile.rb +133 -0
  43. data/lib/opal/opalfile/task.rb +96 -0
  44. data/lib/opal/opalfile/task_manager.rb +63 -0
  45. data/lib/opal/opalfile/task_scope.rb +52 -0
  46. data/lib/opal/rack/app_server.rb +119 -0
  47. data/opals/aristo/README.md +16 -0
  48. data/opals/browser/Opalfile +11 -0
  49. data/opals/browser/README.md +146 -0
  50. data/opals/browser/SIZZLE_LICESNSE.txt +148 -0
  51. data/opals/browser/lib/browser.rb +118 -0
  52. data/opals/browser/lib/browser/builder.rb +41 -0
  53. data/opals/browser/lib/browser/canvas_context.rb +115 -0
  54. data/opals/browser/lib/browser/dimensions.rb +50 -0
  55. data/opals/browser/lib/browser/document.rb +146 -0
  56. data/opals/browser/lib/browser/element.rb +487 -0
  57. data/opals/browser/lib/browser/element/attributes.rb +88 -0
  58. data/opals/browser/lib/browser/element/css.rb +290 -0
  59. data/opals/browser/lib/browser/element/form.rb +146 -0
  60. data/opals/browser/lib/browser/event/dom_events.rb +81 -0
  61. data/opals/browser/lib/browser/event/event.rb +177 -0
  62. data/opals/browser/lib/browser/event/trigger_events.rb +53 -0
  63. data/opals/browser/lib/browser/geometry.rb +97 -0
  64. data/opals/browser/lib/browser/json.rb +32 -0
  65. data/opals/browser/lib/browser/json_parse.js +321 -0
  66. data/opals/browser/lib/browser/request/request.rb +201 -0
  67. data/opals/browser/lib/browser/sizzle.js +1068 -0
  68. data/opals/browser/lib/browser/string.rb +42 -0
  69. data/opals/browser/lib/browser/touch.rb +37 -0
  70. data/{runtime/yaml.js → opals/browser/lib/browser/vml_context.js} +8 -8
  71. data/opals/browser/lib/browser/window.rb +36 -0
  72. data/opals/browser/spec/browser/browser_detection_spec.rb +7 -0
  73. data/opals/browser/spec/document/aref_spec.rb +110 -0
  74. data/opals/browser/spec/document/ready_spec.rb +16 -0
  75. data/opals/browser/spec/element/body_spec.rb +11 -0
  76. data/opals/browser/spec/element/clear_spec.rb +26 -0
  77. data/opals/browser/spec/element/empty_spec.rb +29 -0
  78. data/opals/browser/spec/element/has_class_spec.rb +40 -0
  79. data/opals/browser/spec/element/hidden_spec.rb +23 -0
  80. data/opals/browser/spec/element/hide_spec.rb +31 -0
  81. data/opals/browser/spec/element/remove_spec.rb +25 -0
  82. data/opals/browser/spec/element/show_spec.rb +31 -0
  83. data/opals/browser/spec/element/style_spec.rb +69 -0
  84. data/opals/browser/spec/element/toggle_spec.rb +31 -0
  85. data/opals/browser/spec/element/visible_spec.rb +23 -0
  86. data/opals/browser/spec/spec_helper.rb +1 -0
  87. data/opals/cherry_kit/Opalfile +6 -0
  88. data/opals/cherry_kit/bin/cherry_kit.rb +11 -0
  89. data/opals/cherry_kit/lib/cherry_kit.rb +29 -0
  90. data/opals/foundation/Opalfile +11 -0
  91. data/opals/foundation/bin/foundation.rb +12 -0
  92. data/opals/foundation/lib/foundation.rb +32 -0
  93. data/opals/foundation/lib/foundation/__table_view_desktop/outline_view.rb +57 -0
  94. data/opals/foundation/lib/foundation/__table_view_desktop/table_column.rb +59 -0
  95. data/opals/foundation/lib/foundation/__table_view_desktop/table_header_view.rb +34 -0
  96. data/opals/foundation/lib/foundation/__table_view_desktop/table_view.rb +304 -0
  97. data/opals/foundation/lib/foundation/controllers/array_controller.rb +54 -0
  98. data/opals/foundation/lib/foundation/controllers/controller.rb +74 -0
  99. data/opals/foundation/lib/foundation/controllers/controller_selection_proxy.rb +67 -0
  100. data/opals/foundation/lib/foundation/controllers/object_controller.rb +145 -0
  101. data/opals/foundation/lib/foundation/controllers/view.rb +40 -0
  102. data/opals/foundation/lib/foundation/core/application.rb +476 -0
  103. data/opals/foundation/lib/foundation/core/attributes.rb +146 -0
  104. data/opals/foundation/lib/foundation/core/bindings.rb +125 -0
  105. data/opals/foundation/lib/foundation/core/builder.rb +101 -0
  106. data/opals/foundation/lib/foundation/core/event.rb +112 -0
  107. data/opals/foundation/lib/foundation/core/index_path.rb +49 -0
  108. data/opals/foundation/lib/foundation/core/index_set.rb +97 -0
  109. data/opals/foundation/lib/foundation/core/notification.rb +113 -0
  110. data/opals/foundation/lib/foundation/core/observable.rb +275 -0
  111. data/opals/foundation/lib/foundation/core/observable_array.rb +30 -0
  112. data/opals/foundation/lib/foundation/core/responder.rb +85 -0
  113. data/opals/foundation/lib/foundation/core/run_loop.rb +89 -0
  114. data/opals/foundation/lib/foundation/core/touch.rb +95 -0
  115. data/opals/foundation/lib/foundation/gestures/gesture_recognizer.rb +35 -0
  116. data/opals/foundation/lib/foundation/rendering/render_context.rb +100 -0
  117. data/opals/foundation/lib/foundation/rendering/renderer.rb +137 -0
  118. data/opals/foundation/lib/foundation/rendering/root_theme.rb +77 -0
  119. data/opals/foundation/lib/foundation/rendering/root_theme/button.rb +62 -0
  120. data/opals/foundation/lib/foundation/rendering/root_theme/control.rb +72 -0
  121. data/opals/foundation/lib/foundation/rendering/root_theme/label.rb +54 -0
  122. data/opals/foundation/lib/foundation/rendering/root_theme/scroller.rb +58 -0
  123. data/opals/foundation/lib/foundation/rendering/root_theme/slider.rb +72 -0
  124. data/opals/foundation/lib/foundation/rendering/root_theme/table_view.rb +97 -0
  125. data/opals/foundation/lib/foundation/rendering/root_theme/text_field.rb +55 -0
  126. data/opals/foundation/lib/foundation/rendering/root_theme/view.rb +81 -0
  127. data/opals/foundation/lib/foundation/rendering/theme.rb +38 -0
  128. data/opals/foundation/lib/foundation/table_view/cell.rb +39 -0
  129. data/opals/foundation/lib/foundation/table_view/table.rb +171 -0
  130. data/opals/foundation/lib/foundation/views/button.rb +63 -0
  131. data/opals/foundation/lib/foundation/views/checkbox.rb +28 -0
  132. data/opals/foundation/lib/foundation/views/clip.rb +47 -0
  133. data/opals/foundation/lib/foundation/views/control.rb +199 -0
  134. data/opals/foundation/lib/foundation/views/label.rb +54 -0
  135. data/opals/foundation/lib/foundation/views/scroll.rb +294 -0
  136. data/opals/foundation/lib/foundation/views/scroll_view_desktop.rb +152 -0
  137. data/opals/foundation/lib/foundation/views/scroller.rb +54 -0
  138. data/opals/foundation/lib/foundation/views/slider.rb +93 -0
  139. data/opals/foundation/lib/foundation/views/text_field.rb +83 -0
  140. data/opals/foundation/lib/foundation/views/view.rb +426 -0
  141. data/opals/foundation/lib/foundation/windows/window.rb +191 -0
  142. data/opals/foundation/resources/button/button.css +23 -0
  143. data/{runtime/init.js → opals/foundation/resources/foundation.css} +27 -33
  144. data/opals/foundation/resources/scroll/scroll.css +22 -0
  145. data/opals/foundation/resources/scroll_view/scroll_view.css +3 -0
  146. data/opals/foundation/resources/scroll_view/scroller.css +3 -0
  147. data/opals/foundation/resources/slider/regular/slider.css +3 -0
  148. data/opals/foundation/resources/slider/slider.css +27 -0
  149. data/opals/foundation/resources/table_view/outline_view.css +3 -0
  150. data/opals/foundation/resources/table_view/table_view.css +15 -0
  151. data/opals/foundation/resources/text_field/text_field.css +71 -0
  152. data/opals/foundation/spec/spec_helper.rb +1 -0
  153. data/opals/foundation/spec/system/attributes/get_attribute_spec.rb +69 -0
  154. data/opals/foundation/spec/system/attributes/get_path_spec.rb +44 -0
  155. data/opals/foundation/spec/system/attributes/set_path_spec.rb +24 -0
  156. data/opals/foundation/spec/system/attributes/set_spec.rb +58 -0
  157. data/opals/foundation/spec/system/bindings/bindings.rb +85 -0
  158. data/opals/foundation/spec/system/key_value_binding/bind_spec.rb +43 -0
  159. data/opals/foundation/spec/system/observable/dependant_keys_spec.rb +74 -0
  160. data/opals/foundation/spec/system/observable/observe_spec.rb +292 -0
  161. data/opals/foundation/spec/system/observable/remove_observer_spec.rb +60 -0
  162. data/opals/opal/Opalfile +14 -0
  163. data/opals/opal/spec/core/array/append_spec.rb +30 -0
  164. data/opals/opal/spec/core/array/assoc_spec.rb +29 -0
  165. data/opals/opal/spec/core/array/at_spec.rb +37 -0
  166. data/opals/opal/spec/core/array/clear_spec.rb +22 -0
  167. data/opals/opal/spec/core/array/collect_bang_spec.rb +27 -0
  168. data/opals/opal/spec/core/array/collect_spec.rb +27 -0
  169. data/opals/opal/spec/core/array/compact_spec.rb +15 -0
  170. data/opals/opal/spec/core/array/concat_spec.rb +15 -0
  171. data/opals/opal/spec/core/array/constructor_spec.rb +14 -0
  172. data/opals/opal/spec/core/array/each_spec.rb +9 -0
  173. data/opals/opal/spec/core/array/element_reference_spec.rb +4 -0
  174. data/opals/opal/spec/core/array/first_spec.rb +35 -0
  175. data/opals/opal/spec/core/array/include_spec.rb +9 -0
  176. data/opals/opal/spec/core/array/map_spec.rb +31 -0
  177. data/opals/opal/spec/core/builtin_constants/builtin_constants_spec.rb +7 -0
  178. data/opals/opal/spec/core/false/and_spec.rb +10 -0
  179. data/opals/opal/spec/core/false/inspect_spec.rb +6 -0
  180. data/opals/opal/spec/core/false/or_spec.rb +10 -0
  181. data/opals/opal/spec/core/false/to_s_spec.rb +6 -0
  182. data/opals/opal/spec/core/false/xor_spec.rb +10 -0
  183. data/opals/opal/spec/core/file/join_spec.rb +19 -0
  184. data/opals/opal/spec/core/kernel/instance_eval_spec.rb +0 -0
  185. data/opals/opal/spec/core/kernel/loop_spec.rb +24 -0
  186. data/opals/opal/spec/core/kernel/raise_spec.rb +0 -0
  187. data/opals/opal/spec/core/module/attr_accessor_spec.rb +28 -0
  188. data/opals/opal/spec/core/number/lt_spec.rb +12 -0
  189. data/opals/opal/spec/core/true/and_spec.rb +10 -0
  190. data/opals/opal/spec/core/true/inspect_spec.rb +6 -0
  191. data/opals/opal/spec/core/true/or_spec.rb +10 -0
  192. data/opals/opal/spec/core/true/to_s_spec.rb +6 -0
  193. data/opals/opal/spec/core/true/xor_spec.rb +10 -0
  194. data/opals/opal/spec/fixtures/super.rb +70 -0
  195. data/opals/opal/spec/language/____temp_remove_this.rb +12 -0
  196. data/opals/opal/spec/language/and_spec.rb +62 -0
  197. data/opals/opal/spec/language/array_spec.rb +52 -0
  198. data/opals/opal/spec/language/block_spec.rb +18 -0
  199. data/opals/opal/spec/language/break_spec.rb +36 -0
  200. data/opals/opal/spec/language/case_spec.rb +103 -0
  201. data/opals/opal/spec/language/def_spec.rb +11 -0
  202. data/opals/opal/spec/language/eigenclass_spec.rb +60 -0
  203. data/opals/opal/spec/language/hash_spec.rb +29 -0
  204. data/opals/opal/spec/language/if_spec.rb +54 -0
  205. data/opals/opal/spec/language/loop_spec.rb +11 -0
  206. data/opals/opal/spec/language/metaclass_spec.rb +21 -0
  207. data/opals/opal/spec/language/method_spec.rb +64 -0
  208. data/opals/opal/spec/language/next_spec.rb +25 -0
  209. data/opals/opal/spec/language/or_spec.rb +34 -0
  210. data/opals/opal/spec/language/redo_spec.rb +24 -0
  211. data/opals/opal/spec/language/rescue_spec.rb +20 -0
  212. data/opals/opal/spec/language/return_spec.rb +47 -0
  213. data/opals/opal/spec/language/string_spec.rb +25 -0
  214. data/opals/opal/spec/language/super_spec.rb +26 -0
  215. data/opals/opal/spec/language/until_spec.rb +157 -0
  216. data/opals/opal/spec/language/while_spec.rb +163 -0
  217. data/opals/opal/spec/spec_helper.rb +5 -0
  218. data/opals/runtime/Opalfile +68 -0
  219. data/opals/runtime/README.md +12 -0
  220. data/opals/runtime/docs/debugging.md +51 -0
  221. data/opals/runtime/lib/array.rb +1516 -0
  222. data/opals/runtime/lib/basic_object.rb +49 -0
  223. data/opals/runtime/lib/class.rb +54 -0
  224. data/opals/runtime/lib/dir.rb +36 -0
  225. data/opals/runtime/lib/error.rb +49 -0
  226. data/opals/runtime/lib/false_class.rb +52 -0
  227. data/opals/runtime/lib/file.rb +79 -0
  228. data/opals/runtime/lib/hash.rb +791 -0
  229. data/opals/runtime/lib/io.rb +39 -0
  230. data/opals/runtime/lib/kernel.rb +288 -0
  231. data/opals/runtime/lib/match_data.rb +36 -0
  232. data/opals/runtime/lib/module.rb +109 -0
  233. data/opals/runtime/lib/nil_class.rb +69 -0
  234. data/opals/runtime/lib/number.rb +398 -0
  235. data/opals/runtime/lib/proc.rb +77 -0
  236. data/opals/runtime/lib/range.rb +63 -0
  237. data/opals/runtime/lib/regexp.rb +111 -0
  238. data/opals/runtime/lib/ruby.rb +30 -0
  239. data/opals/runtime/lib/string.rb +328 -0
  240. data/opals/runtime/lib/symbol.rb +40 -0
  241. data/opals/runtime/lib/top_self.rb +33 -0
  242. data/opals/runtime/lib/true_class.rb +45 -0
  243. data/opals/runtime/runtime/browser.js +287 -0
  244. data/opals/runtime/runtime/debug.js +182 -0
  245. data/opals/runtime/runtime/opal.js +1010 -0
  246. data/opals/runtime/runtime/post_opal.js +1 -0
  247. data/opals/runtime/runtime/pre_opal.js +2 -0
  248. data/opals/runtime/runtime/server_side.js +50 -0
  249. data/opals/spec/LICENSE.txt +26 -0
  250. data/opals/spec/Opalfile +5 -0
  251. data/opals/spec/bin/spec.rb +43 -0
  252. data/opals/spec/lib/spec.rb +33 -0
  253. data/opals/spec/lib/spec/dsl.rb +41 -0
  254. data/opals/spec/lib/spec/example.rb +35 -0
  255. data/opals/spec/lib/spec/example/before_and_after_hooks.rb +81 -0
  256. data/opals/spec/lib/spec/example/errors.rb +42 -0
  257. data/opals/spec/lib/spec/example/example_group.rb +37 -0
  258. data/opals/spec/lib/spec/example/example_group_factory.rb +43 -0
  259. data/opals/spec/lib/spec/example/example_group_hierarchy.rb +45 -0
  260. data/opals/spec/lib/spec/example/example_group_methods.rb +142 -0
  261. data/opals/spec/lib/spec/example/example_group_proxy.rb +41 -0
  262. data/opals/spec/lib/spec/example/example_methods.rb +73 -0
  263. data/opals/spec/lib/spec/example/example_proxy.rb +48 -0
  264. data/opals/spec/lib/spec/expectations.rb +46 -0
  265. data/opals/spec/lib/spec/expectations/errors.rb +35 -0
  266. data/opals/spec/lib/spec/expectations/fail_with.rb +37 -0
  267. data/opals/spec/lib/spec/expectations/handler.rb +48 -0
  268. data/opals/spec/lib/spec/matchers.rb +50 -0
  269. data/opals/spec/lib/spec/matchers/be.rb +26 -0
  270. data/opals/spec/lib/spec/matchers/generated_descriptions.rb +47 -0
  271. data/opals/spec/lib/spec/matchers/operator_matcher.rb +66 -0
  272. data/opals/spec/lib/spec/runner.rb +48 -0
  273. data/opals/spec/lib/spec/runner/example_group_runner.rb +71 -0
  274. data/opals/spec/lib/spec/runner/formatter/html_formatter.rb +100 -0
  275. data/opals/spec/lib/spec/runner/formatter/terminal_formatter.rb +82 -0
  276. data/opals/spec/lib/spec/runner/options.rb +63 -0
  277. data/opals/spec/lib/spec/runner/reporter.rb +123 -0
  278. data/opals/spec/resources/index.html +25 -0
  279. data/opals/spec/resources/spec.css +132 -0
  280. data/spec/cherry_kit/iseq_spec.rb +38 -0
  281. data/spec/spec_helper.rb +16 -0
  282. data/spec/vienna_spec.rb +7 -0
  283. data/yard/index.html +43 -0
  284. data/yard/style.css +765 -0
  285. metadata +312 -49
  286. data/docs/jarv.rdoc +0 -27
  287. data/runtime/array.js +0 -153
  288. data/runtime/class.js +0 -469
  289. data/runtime/compar.js +0 -73
  290. data/runtime/dir.js +0 -115
  291. data/runtime/enum.js +0 -74
  292. data/runtime/file.js +0 -165
  293. data/runtime/gem.js +0 -241
  294. data/runtime/hash.js +0 -181
  295. data/runtime/load.js +0 -251
  296. data/runtime/module.js +0 -98
  297. data/runtime/number.js +0 -148
  298. data/runtime/object.js +0 -522
  299. data/runtime/opal.js +0 -200
  300. data/runtime/parse.js +0 -2218
  301. data/runtime/range.js +0 -56
  302. data/runtime/re.js +0 -91
  303. data/runtime/string.js +0 -199
  304. data/runtime/variable.js +0 -184
  305. data/runtime/vm.js +0 -1150
  306. data/tasks/build.rb +0 -16
@@ -0,0 +1,1010 @@
1
+ /*
2
+ * vienna.js
3
+ * vienna
4
+ *
5
+ * Created by Adam Beynon.
6
+ * Copyright 2010 Adam Beynon.
7
+ *
8
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
9
+ * of this software and associated documentation files (the "Software"), to deal
10
+ * in the Software without restriction, including without limitation the rights
11
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12
+ * copies of the Software, and to permit persons to whom the Software is
13
+ * furnished to do so, subject to the following conditions:
14
+ *
15
+ * The above copyright notice and this permission notice shall be included in
16
+ * all copies or substantial portions of the Software.
17
+ *
18
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24
+ * THE SOFTWARE.
25
+ */
26
+
27
+
28
+ var STACK_TRACE = true;
29
+
30
+ // lets just do this straight away, out of the way. Still need a way to log from
31
+ // IE, Opera etc etc etc
32
+ if (typeof console === 'undefined') {
33
+ global.console = {} ;
34
+ // console.info = console.warn = console.error = console.log = function(){};
35
+ }
36
+
37
+ // Core classes
38
+ // exports.c_object = null;
39
+ var class_basic_object = null,
40
+ class_module = null,
41
+ class_class = null,
42
+ class_object = null,
43
+ module_kernel = null,
44
+ class_symbol = null,
45
+ class_true_class = null,
46
+ class_false_class = null,
47
+ class_nil_class = null,
48
+ class_proc = null,
49
+ class_string = null,
50
+ class_array = null,
51
+ class_hash = null,
52
+ class_number = null,
53
+ class_regexp = null,
54
+ class_range = null,
55
+ class_exception = null;
56
+
57
+ // top self
58
+ exports.top_self = null;
59
+
60
+ // Core object literals (in main window scope)
61
+ global.vnNil = null;
62
+ global.vnTrue = null;
63
+ global.vnFalse = null;
64
+
65
+ // flags for object/class types
66
+ var T_CLASS = 1,
67
+ T_MODULE = 2,
68
+ T_OBJECT = 4,
69
+ T_BOOLEAN = 8,
70
+ T_STRING = 16,
71
+ T_ARRAY = 32,
72
+ T_NUMBER = 64,
73
+ T_PROC = 128,
74
+ T_SYMBOL = 256,
75
+ T_HASH = 512,
76
+ T_RANGE = 1024,
77
+ T_ICLASS = 2048,
78
+ FL_SINGLETON = 4096;
79
+
80
+
81
+ // create a ruby proc from javascript func
82
+
83
+
84
+
85
+ // hash from arguments vnH(key1, val1, key2, val2...)
86
+ global.vnH = function() {
87
+ var k, v, res = new class_hash.allocator();
88
+ res.__keys__ = [];
89
+ res.__assocs__ = {};
90
+ res.__default__ = vnNil;
91
+ for (var i = 0; i < arguments.length; i++) {
92
+ k = arguments[i], v = arguments[i+1];
93
+ i++;
94
+ res.__keys__.push(k);
95
+ res.__assocs__[k.hash()] = v;
96
+ }
97
+ return res;
98
+ };
99
+
100
+ // Regexp
101
+ global.vnR = function(reg) {
102
+ var res = new class_regexp.allocator();
103
+ res.__reg__ = reg;
104
+ return res;
105
+ };
106
+
107
+ var symbol_table = { };
108
+
109
+ // For object_id's .. each object/class will get an object_id
110
+ var hash_yield = 0;
111
+
112
+ var yield_hash = function() {
113
+ return hash_yield++;
114
+ };
115
+
116
+ if (!Array.prototype.indexOf) {
117
+ Array.prototype.indexOf = function (obj) {
118
+ for (var i = 0; i< this.length; i++) {
119
+ if (this[i] == obj) return i;
120
+ }
121
+ return -1;
122
+ };
123
+ };
124
+
125
+ // EntryPoint. Every time something causes ruby to be run, it must be done
126
+ // through this function. This includes events, timers firing and the initial
127
+ // main() code. This will capture possible errors and log them and their stack
128
+ // trace to the terminal.
129
+ //
130
+ // @param [Function] func to run as main entry point
131
+ // @return [Object] returns the result of the function
132
+ //
133
+ exports.entry_point = function(func) {
134
+ return func();
135
+ };
136
+
137
+ // Base of every object or class object in vienna. Every object, string, number,
138
+ // class, module, regexp, proc etc will be an instance of this, so const_set etc
139
+ // are all on the prototype of this. This keeps a lot from needing to go into
140
+ // global namespace, and keeps vienna export nice and clean.
141
+ //
142
+ // Update/Renaming scheme
143
+ // ======================
144
+ //
145
+ // We are now going to use the native String/Number/Array prototypes, so we need
146
+ // to make sure we avoid clashes. All ruby methods start with $, so all
147
+ // definitions/usage functions will end with $. No
148
+ // generated methods can end with $, so we avoid clashes. For example, the
149
+ // methods/properties above become...
150
+ //
151
+ // .t$ - true literal
152
+ // .f$ - false literal
153
+ // .n$ - nil literal
154
+ //
155
+ // .r$ - ruby truthiness
156
+ //
157
+ // .h$() - make hash from args
158
+ // .y$() - make symbol if not already exists
159
+ //
160
+ // .a$() - and test, takes a function as single param to make test
161
+ // .o$() - or test, takes a function as single param to make test
162
+ //
163
+ // .O$ - T_OBJECT
164
+ // .C$ - T_CLASS
165
+ // .M$ - T_MODULE
166
+ // .A$ - T_ARRAY
167
+ //
168
+ // .dc$() - define class
169
+ // .dm$() - define method
170
+ //
171
+ var __boot_base_class = function() {
172
+ this.id = yield_hash();
173
+ };
174
+
175
+ __boot_base_class.prototype.hash = function() {
176
+ return this.id;
177
+ };
178
+
179
+ // convert ruby id to jsid - for methods
180
+ __boot_base_class.prototype.mid2jsid = function(mid) {
181
+ return ("$" + mid).replace(/=/g, '$e').replace(/\?/g, '$q');
182
+ };
183
+
184
+
185
+ __boot_base_class.prototype.define_class = function(sup, id, body, flag) {
186
+
187
+ var klass, base = this;
188
+
189
+ if (base.flags & T_OBJECT)
190
+ base = base.isa;
191
+
192
+ switch (flag) {
193
+ // normal class
194
+ case 0:
195
+ if (sup === vnNil)
196
+ sup = class_object;
197
+
198
+ klass = define_class_under(base, id, sup);
199
+ break;
200
+ case 1:
201
+ // throw "running class shift for " + id.class_name
202
+ klass = id.singleton_class();
203
+ // return;
204
+ break;
205
+ case 2:
206
+ klass = define_module_under(base, id);
207
+ break;
208
+ default:
209
+ throw "define_class: unknown flag: " + flag
210
+ }
211
+
212
+ return body.apply(klass);
213
+
214
+ // return klass;
215
+ };
216
+
217
+ // get singleton class
218
+ __boot_base_class.prototype.singleton_class = function() {
219
+ var klass;
220
+
221
+ // if (this.info & )
222
+
223
+ if (this.info & FL_SINGLETON) {
224
+ klass = this.isa;
225
+ }
226
+ else {
227
+ // if we a re a class or module..
228
+ if ((this.info & T_CLASS) || (this.info & T_MODULE)) {
229
+ // if we have an __attached__, use it
230
+ if (this.__attached__) {
231
+ return this.__attached__;
232
+ }
233
+ // otherwise, create it
234
+ else {
235
+ var meta = __subclass(this.class_name, this.isa);
236
+ meta.info = meta.info | FL_SINGLETON;
237
+ this.__attached__ = this.isa = meta;
238
+ meta.__attached__ = this;
239
+ return meta;
240
+ }
241
+ }
242
+ else {
243
+ // object
244
+ // console.log("need to make singleton class for: " + this.class_name);
245
+
246
+ this.info = this.info | FL_SINGLETON;
247
+ var meta = __subclass(this.class_name, this.isa);
248
+ meta.info = meta.info | T_ICLASS;
249
+ var old_super = this.isa;
250
+ klass = this.isa = meta;
251
+ meta.__instance__ = this;
252
+ meta.constants = old_super.constants;
253
+ // klass = this.isa;
254
+ // var class_name = this.isa.class_name;
255
+ // klass = make_metaclass(this, this.isa);
256
+ }
257
+
258
+ }
259
+
260
+ return klass;
261
+ };
262
+
263
+ __boot_base_class.prototype.dm = function(m_id, body, singleton) {
264
+ // console.log(m_id + " for ");
265
+ // console.log(this.class_name);
266
+
267
+ // hack for replacing mid_to_jsid
268
+ var js_id = '$' + m_id;
269
+
270
+ body.method_id = m_id;
271
+ body.jsid = js_id;
272
+ body.displayName = m_id;
273
+ // register self as the current class for body (for super calls)
274
+ body.opal_class = this;
275
+
276
+ if (singleton) {
277
+ if ((this.info & T_CLASS) || (this.info & T_MODULE)) {
278
+ this.constructor.prototype[js_id] = body;
279
+ this.constructor.prototype.method_table[js_id] = body;
280
+ }
281
+ else {
282
+ // add method to singleton_object
283
+ this[js_id] = body;
284
+ // throw "need to add_method to singleton object"
285
+ }
286
+ }
287
+ else {
288
+ if ((this.info & T_CLASS) || (this.info & T_MODULE)) {
289
+ if (this.info & FL_SINGLETON) {
290
+ // console.log("need to define method for singleton.. " + m_id);
291
+ this.__attached__.constructor.prototype[js_id] = body;
292
+ this.__attached__.constructor.prototype.method_table[js_id] = body;
293
+ }
294
+ else {
295
+ this.allocator.prototype[js_id] = body;
296
+ this.allocator.prototype.method_table[js_id] = body;
297
+ }
298
+
299
+ if (this.info & T_ICLASS) {
300
+ this.__instance__[js_id] = body;
301
+ console.log("adding method " + m_id + " which is " + js_id);
302
+ // console.log(this.__instance__);
303
+ }
304
+ }
305
+ else {
306
+ // console.log("need to make into singleton object for: " + this.$inspect() + " with method " + m_id);
307
+ var cls = this.singleton_class();
308
+ cls.allocator.prototype[js_id] = body;
309
+ cls.allocator.prototype.method_table[js_id] = body;
310
+ // i_class singleton will only ever have one instance: this.
311
+ // cls.__instance__ = this;
312
+ body.opal_class = cls;
313
+ // cls.dm(m_id, body, singleton);
314
+ // add method to singleton object
315
+ this[js_id] = body;
316
+ // console.log(this);
317
+ // throw "need to add_method to object " + m_id
318
+ }
319
+ }
320
+ return this.n;
321
+ };
322
+
323
+ __boot_base_class.prototype.const_set = function(id, val) {
324
+
325
+ var base = this;
326
+
327
+ if (base.info & T_OBJECT)
328
+ base = base.isa;
329
+
330
+ base.constants[id] = val;
331
+ return val;
332
+ };
333
+
334
+ __boot_base_class.prototype.const_defined = function(id) {
335
+ var base = this;
336
+
337
+ if (base.info & T_OBJECT)
338
+ base = base.isa;
339
+
340
+ if (base.constants[id])
341
+ return true;
342
+
343
+ return false;
344
+ };
345
+
346
+ __boot_base_class.prototype.const_get = function(id) {
347
+
348
+ var base = this;
349
+
350
+ if (base.info & T_OBJECT)
351
+ base = base.isa;
352
+
353
+ if (base.constants[id])
354
+ return base.constants[id];
355
+
356
+ // need to go up through hierarchy
357
+ var search = base.opal_parent, res;
358
+ while (search) {
359
+ res = search.const_get(id);
360
+ if (res) {
361
+ return res;
362
+ }
363
+ search = search.opal_parent;
364
+ }
365
+ // console.log("my parent is:");
366
+ // console.log(base.opal_parent);
367
+ // console.log(base.opal_parent.constants.Reporter);
368
+
369
+ throw { toString: function() {
370
+ return "NameError: uninitialized constant: " + id;
371
+ }};
372
+ };
373
+
374
+ // ivar get
375
+ __boot_base_class.prototype.ig = function(id) {
376
+ if (this.hasOwnProperty(id))
377
+ return this[id];
378
+
379
+ return vnNil;
380
+ };
381
+
382
+ // ivar set
383
+ __boot_base_class.prototype.is = function(id, val) {
384
+ return this[id] = val;
385
+ };
386
+
387
+ __boot_base_class.prototype.include = function(module) {
388
+
389
+ if (!this.included_modules)
390
+ this.included_modules = [];
391
+
392
+ if (this.included_modules.indexOf(module) != -1)
393
+ return; // already included
394
+
395
+ this.included_modules.push(module);
396
+ module.included_in.push(this);
397
+
398
+ // add each method from module into class's prototype
399
+ for (method in module.allocator.prototype.method_table) {
400
+ // if (!this.allocator.prototype.method_table[method])
401
+ // if (!this.allocator.prototype.hasOwnProperty(method))
402
+ this.allocator.prototype.method_table[method] = module.allocator.prototype.method_table[method];
403
+ this.allocator.prototype[method] = module.allocator.prototype.method_table[method];
404
+ }
405
+
406
+ // console.log("checking include constants from " + module.class_name + " into " + this.class_name);
407
+ for (var prop in module.constants) {
408
+ if (module.constants.hasOwnProperty(prop) && !this.constants[prop]) {
409
+ this.constants[prop] = module.constants[prop];
410
+ }
411
+ }
412
+ };
413
+
414
+ __boot_base_class.prototype.extend = function(module) {
415
+ // add each method from module into class's prototype
416
+ for (method in module.allocator.prototype.method_table) {
417
+ // console.log("adding " +method);
418
+ this.constructor.prototype.method_table[method] = module.allocator.prototype.method_table[method];
419
+ this.constructor.prototype[method] = module.allocator.prototype.method_table[method];
420
+ }
421
+ };
422
+
423
+ // RTEST - true. false and nil override this
424
+ __boot_base_class.prototype.r = true;
425
+
426
+ // ANDTEST
427
+ __boot_base_class.prototype.a = function(lhs, rhs) {
428
+ if (lhs.r)
429
+ return rhs.apply(this);
430
+
431
+ return lhs;
432
+ };
433
+
434
+ // ORTEST
435
+ __boot_base_class.prototype.o = function(lhs, rhs) {
436
+ if (lhs.r)
437
+ return lhs;
438
+
439
+ return rhs.apply(this);
440
+ };
441
+
442
+ // Handle yielding
443
+ //
444
+ // @param {Function} proc to yield
445
+ // @param {Array} params to yield to proc
446
+ //
447
+ __boot_base_class.prototype.rbYield = function(proc, params) {
448
+ // if we tried to yield, and we were not given a block..
449
+ if (!proc) {
450
+ throw {
451
+ toString: function() {
452
+ return "Yield: no block given";
453
+ }
454
+ };
455
+ }
456
+
457
+ // otherwise, yield it in the 'self' context it was created in.
458
+ return proc.apply(proc.__self__, params);
459
+ };
460
+
461
+ // Handle while loops.
462
+ //
463
+ // @param {Function} expression wrapped in function to evaluate before each pass
464
+ // @param {Function} body wrapped in function to evaluate as eash pass
465
+ // @param {Boolean} should_redo - call the body once without reevaluating the
466
+ // expression. This allows for 'redo' support. Default is false, we set
467
+ // it to true ourselves by repplaying() the method.
468
+ //
469
+ // Example
470
+ //
471
+ // while true
472
+ // puts 10
473
+ // end
474
+ //
475
+ // self.rbWhile(function() {
476
+ // return self.t;
477
+ // }), function() {
478
+ // self.puts(10);
479
+ // };
480
+ // })
481
+ __boot_base_class.prototype.rbWhile = function(expression, body, should_redo) {
482
+ try {
483
+ // are we in a redo()? if so, apply body once first, then carry on
484
+ if (should_redo) {
485
+ body.apply(this);
486
+ }
487
+
488
+ while (expression.apply(this)) {
489
+ body.apply(this);
490
+ }
491
+ // while_loop.apply(this);
492
+ // default return nil if everything was ok
493
+ return this.n;
494
+ } catch (e) {
495
+ // try and catch a break statement
496
+ if (e.__keyword__ == 'break') {
497
+ return e.opal_value || this.n;
498
+ }
499
+
500
+ // testing next.. this might not work too well...
501
+ if (e.__keyword__ == 'next') {
502
+ return arguments.callee.apply(this, [expression, body]);
503
+ }
504
+
505
+ if (e.__keyword__ == 'redo') {
506
+ return arguments.callee.apply(this, [expression, body, true]);
507
+ }
508
+
509
+ // anything else, rethrow
510
+ throw e;
511
+ };
512
+ };
513
+
514
+ // redo keyword - no args ever
515
+ __boot_base_class.prototype.rbRedo = function() {
516
+ throw {
517
+ toString: function() {
518
+ return "uncaught redo";
519
+ },
520
+ __keyword__: 'redo'
521
+ };
522
+ };
523
+
524
+ // break keyword (with possible args?)
525
+ __boot_base_class.prototype.rbBreak = function(value) {
526
+ throw {
527
+ toString: function() {
528
+ return "uncaught break";
529
+ },
530
+ __keyword__: 'break',
531
+ opal_value: value == undefined ? this.n : value
532
+ };
533
+ };
534
+
535
+ // next keyword
536
+ __boot_base_class.prototype.rbNext = function(value) {
537
+ throw {
538
+ toString: function() {
539
+ return "uncaught next";
540
+ },
541
+ __keyword__: 'next',
542
+ opal_value: value || this.n
543
+ };
544
+ };
545
+
546
+ // return keyword (only within a block) with args..
547
+ __boot_base_class.prototype.rbReturn = function(value) {
548
+ throw {
549
+ toString: function() {
550
+ return "uncaught rbReturn";
551
+ },
552
+ __keyword__: 'return',
553
+ opal_value: value || this.n
554
+ };
555
+ };
556
+
557
+ // ruby proc from function
558
+ //
559
+ // A proc/block/llambda are simply javascript functions. Everytime a block is
560
+ // created in ruby, its current self, as in the self which the block should use
561
+ // for evaluating, is stored by the function onto the property .__self__, so
562
+ // that whenever the block is call()'d or yield()'d, it is apply()'d using this
563
+ // self so that it evaluates in that given context. To evaluate the block in
564
+ // another context, with, for exampke, instance_eval, we just apply() with our
565
+ // own custom self. We never need to replace __self__, we just apply uysing a
566
+ // different context.
567
+ //
568
+ // @param {Function} fun - the block implementation
569
+ __boot_base_class.prototype.P = function(fun) {
570
+ fun.__self__ = this;
571
+ return fun;
572
+ // var res = new class_proc.allocator();
573
+ // res.__fun__ = fun;
574
+ // return res;
575
+ };
576
+
577
+ // same as above, but lambda
578
+ __boot_base_class.prototype.L = function(fun) {
579
+ fun.__self__ = this;
580
+ fun.__lambda__ = true;
581
+ return fun;
582
+ };
583
+
584
+ // create a ruby symbol from javascript str. This checks the global sym table
585
+ // first to make sure we only create one symbol per name (id).
586
+ __boot_base_class.prototype.Y = function(str) {
587
+ if (symbol_table.hasOwnProperty(str))
588
+ return symbol_table[str];
589
+
590
+ var res = new class_symbol.allocator();
591
+ res.__ptr__ = str;
592
+ symbol_table[str] = res;
593
+ return res;
594
+ };
595
+
596
+ // ruby range
597
+ __boot_base_class.prototype.R = function(start, end, exclusive) {
598
+ var res = new class_range.allocator();
599
+ res.__start__ = start;
600
+ res.__end__ = end;
601
+ res.__exclusive__ = exclusive;
602
+ res.__real_end__ = exclusive ? end - 1 : end;
603
+ return res;
604
+ };
605
+
606
+ // calling super
607
+ //
608
+ // @param {Function} func of current func calling super
609
+ // @param {Array} args to pass to super implementation
610
+ // @return {Object} return value from super call
611
+ //
612
+ // CURRENTLY ONLY SUPPORTS INSTANCE CLASSES
613
+ //
614
+ __boot_base_class.prototype.opal_super = function(func, args) {
615
+ // get current imp's implementation
616
+ var cur_class = func.opal_class;
617
+ // for super, we just need the imp of the superclass's method. This will work
618
+ // up the chain as opal_class is set to the class on which the method was
619
+ // defines, so any method put in as a super class to this will have our super
620
+ // method.
621
+ var sup_class = cur_class.super_class;
622
+
623
+ if (!sup_class) {
624
+ throw "NativeError: no super class found from " + cur_class
625
+ }
626
+
627
+ var sup_func = sup_class.allocator.prototype[func.jsid];
628
+
629
+ if (!sup_func) {
630
+ throw "NativeError: no superclass method found for " + func.method_id;
631
+ }
632
+
633
+ // console.log("ok, going to call it");
634
+ // console.log(sup_func);
635
+ // console.log(args);
636
+ // if all ok, call it
637
+ var res = sup_func.apply(this, args);
638
+ // console.log("res is:");
639
+ // console.log(res);
640
+ return res;
641
+ };
642
+
643
+ // ruby error from native error
644
+ __boot_base_class.prototype.rbNativeError = function(err) {
645
+ var res = class_exception.$new();
646
+ res.is('@message', err.toString());
647
+ return res;
648
+ };
649
+
650
+ __boot_base_class.prototype.TN = T_NUMBER;
651
+ __boot_base_class.prototype.TS = T_STRING;
652
+ __boot_base_class.prototype.TP = T_PROC;
653
+ __boot_base_class.prototype.TA = T_ARRAY;
654
+ __boot_base_class.prototype.TH = T_HASH;
655
+
656
+ var define_class_under = function(base, id, super_class) {
657
+
658
+ if (base.const_defined(id))
659
+ return base.const_get(id);
660
+
661
+ if (!super_class)
662
+ super_class = class_object;
663
+
664
+ var res = __subclass(id, super_class);
665
+ // parent relationship
666
+ res.constructor.prototype.opal_parent = base;
667
+ base.const_set(id, res);
668
+ return res;
669
+ };
670
+
671
+ // Define a toll-free bridged ruby class. This is used for mixing native JS
672
+ // strings, arrays etc with ruby versions.
673
+ //
674
+ // Usage
675
+ // =====
676
+ //
677
+ // class_string = define_bridged_class("String", String);
678
+ //
679
+ // This uses the String constructor. For now, every toll free will inherit from
680
+ // object, and will be set as a constant in the Object:: namespace
681
+ //
682
+ var define_bridged_class = function(id, native_class) {
683
+ var res = __subclass(id, class_object);
684
+
685
+ var old_allocator = res.allocator.prototype;
686
+ res.allocator = native_class;
687
+
688
+ for (var prop in old_allocator) {
689
+ native_class.prototype[prop] = old_allocator[prop];
690
+ }
691
+
692
+ class_object.const_set(id, res);
693
+ return res;
694
+ };
695
+
696
+ var __subclass = exports.__subclass = function(id, super_class) {
697
+ var cls = function() {
698
+ this.id = yield_hash();
699
+ };
700
+
701
+ cls.prototype = new super_class.allocator();
702
+ cls.prototype.method_table = {};
703
+ cls.prototype.constructor = cls;
704
+ cls.prototype.class_name = id;
705
+ cls.prototype.super_class = super_class;
706
+ cls.prototype.info = T_OBJECT;
707
+
708
+ var meta = function() {
709
+ this.id = yield_hash();
710
+ }
711
+
712
+ meta.prototype = new super_class.constructor();
713
+ meta.prototype.method_table = {};
714
+ meta.prototype.allocator = cls;
715
+ meta.prototype.class_name = id;
716
+ meta.prototype.super_class = super_class;
717
+ meta.prototype.info = T_CLASS;
718
+ meta.prototype.constructor = meta;
719
+
720
+ // constants
721
+ meta.prototype.constants = new super_class.constants_alloc();
722
+ meta.prototype.constants_alloc = function() {};
723
+ meta.prototype.constants_alloc.prototype = meta.prototype.constants;
724
+
725
+ var res = new meta();
726
+ cls.prototype.isa = res;
727
+ return res;
728
+ }
729
+
730
+ var define_module_under = function(base, id) {
731
+
732
+ if (base.const_defined(id))
733
+ return base.const_get(id);
734
+
735
+ var mod = define_class_under(base, id, class_module);
736
+ mod.included_in = [];
737
+ mod.info = T_MODULE;
738
+ mod.allocator.prototype.info = T_MODULE;
739
+ return mod;
740
+ };
741
+
742
+ var __boot_defclass = function(id, super_class) {
743
+
744
+ var cls = function() {
745
+ this.id = yield_hash();
746
+ };
747
+
748
+ if (super_class)
749
+ cls.prototype = new super_class();
750
+ else
751
+ cls.prototype = new __boot_base_class();
752
+
753
+ cls.prototype.method_table = {};
754
+ cls.prototype.constructor = cls;
755
+ cls.prototype.class_name = id;
756
+ cls.prototype.super_class = super_class;
757
+ cls.prototype.info = T_OBJECT;
758
+ return cls;
759
+ };
760
+
761
+ var __boot_makemeta = function(klass, super_class) {
762
+
763
+ var meta = function() {
764
+ this.id = yield_hash();
765
+ };
766
+
767
+ meta.prototype = new super_class();
768
+
769
+ meta.prototype.included_in = [];
770
+ meta.prototype.method_table = {};
771
+ meta.prototype.allocator = klass;
772
+ meta.prototype.constructor = meta;
773
+ meta.prototype.class_name = klass.prototype.class_name;
774
+ meta.prototype.super_class = super_class;
775
+ meta.prototype.info = T_CLASS;
776
+
777
+ // constants etc
778
+ if (klass === boot_basic_object) {
779
+ meta.prototype.constants_alloc = function() {};
780
+ meta.prototype.constants = meta.prototype.constants_alloc.prototype;
781
+ } else {
782
+ meta.prototype.constants = new super_class.prototype.constants_alloc();
783
+ meta.prototype.constants_alloc = function() {};
784
+ meta.prototype.constants_alloc.prototype = meta.prototype.constants;
785
+ }
786
+
787
+ var res = new meta();
788
+ klass.prototype.isa = res;
789
+ return res;
790
+ };
791
+
792
+ var __boot_defmetameta = function(klass, meta) {
793
+ klass.isa = meta;
794
+ };
795
+
796
+ // ==============
797
+ // = Initialize =
798
+ // ==============
799
+
800
+ var metaclass;
801
+
802
+ var boot_basic_object = __boot_defclass("BasicObject", null);
803
+ var boot_object = __boot_defclass("Object", boot_basic_object);
804
+ var boot_module = __boot_defclass("Module", boot_object);
805
+ var boot_class = __boot_defclass("Class", boot_module);
806
+
807
+ class_basic_object = __boot_makemeta(boot_basic_object, boot_class);
808
+ class_object = __boot_makemeta(boot_object, class_basic_object.constructor);
809
+ class_module = __boot_makemeta(boot_module, class_object.constructor);
810
+ class_class = __boot_makemeta(boot_class, class_module.constructor);
811
+
812
+ __boot_defmetameta(class_basic_object, class_class);
813
+ __boot_defmetameta(class_object, class_class);
814
+ __boot_defmetameta(class_module, class_class);
815
+ __boot_defmetameta(class_class, class_class);
816
+
817
+ class_object.const_set("BasicObject", class_basic_object);
818
+ class_object.const_set("Object", class_object);
819
+ class_object.const_set("Class", class_class);
820
+ class_object.const_set("Module", class_module);
821
+
822
+ // Custom methods for modules to handle includes properly
823
+ class_module.constructor.prototype.dm = function(m_id, body, sing){
824
+
825
+ js_id = '$' + m_id;
826
+
827
+ // super
828
+ __boot_base_class.prototype.dm.apply(this, arguments);
829
+
830
+ // go through each class we are included in and add new method to that as well
831
+ for (var i = 0; i < this.included_in.length; i++) {
832
+ this.included_in[i].allocator.prototype[js_id] = body;
833
+ }
834
+ };
835
+
836
+ // and then fix again for class
837
+ class_class.constructor.prototype.dm = class_object.constructor.prototype.dm;
838
+
839
+
840
+ exports.Object = class_object;
841
+ exports.top_self = new class_object.allocator();
842
+
843
+ // Override Object.include so that we can also include each module into our
844
+ // Natives String, Array, Number etc.
845
+ class_object.include = function(module) {
846
+ // super
847
+ var res = __boot_base_class.prototype.include.apply(class_object, [module]);
848
+
849
+ var natives = [class_string, class_number, class_array, class_regexp];
850
+
851
+ // return res;
852
+ for (var i = 0; i < natives.length; i++) {
853
+ natives[i].include(module);
854
+ }
855
+
856
+ return res;
857
+ };
858
+
859
+ // When we define a method on object itself, we need to also set it on our
860
+ // natives.
861
+ class_object.dm = function() {
862
+ // super
863
+ var res = __boot_base_class.prototype.dm.apply(class_object, arguments);
864
+
865
+ var natives = [class_string, class_number, class_array, class_regexp];
866
+
867
+ // return res;
868
+ for (var i = 0; i < natives.length; i++) {
869
+ natives[i].dm.apply(natives[i], arguments);
870
+ }
871
+
872
+ return res;
873
+ };
874
+
875
+ // Proc class
876
+ // class_proc = define_class_under(class_object, "Proc", class_object);
877
+ // class_proc.allocator.prototype.info = T_OBJECT | T_PROC;
878
+
879
+ class_proc = define_bridged_class("Proc", Function);
880
+ class_proc.allocator.prototype.info = T_OBJECT | T_PROC;
881
+ // Fix for Object's super_class being a proc and causing inifite recusrion in
882
+ // super class chain Object->Proc->Object...etc
883
+ class_object.allocator.prototype.super_class = undefined;
884
+ class_object.super_class = undefined;
885
+
886
+ // Range class
887
+ class_range = define_class_under(class_object, "Range", class_object);
888
+ class_range.allocator.prototype.info = T_OBJECT | T_RANGE;
889
+
890
+ // True class
891
+ class_true_class = define_class_under(class_object, "TrueClass", class_object);
892
+ vnTrue = new class_true_class.allocator();
893
+ vnTrue.info = vnTrue.info | FL_SINGLETON;
894
+ __boot_base_class.prototype.t = vnTrue;
895
+
896
+ // False class
897
+ class_false_class = define_class_under(class_object, "FalseClass",class_object);
898
+ vnFalse = new class_false_class.allocator();
899
+ vnFalse.info = vnFalse.info | FL_SINGLETON;
900
+ __boot_base_class.prototype.f = vnFalse;
901
+
902
+ vnFalse.r = false;
903
+
904
+ // Nil class
905
+ class_nil_class = define_class_under(class_object, "NilClass", class_object);
906
+ vnNil = new class_nil_class.allocator();
907
+ vnNil.info = vnNil.info | FL_SINGLETON;
908
+ __boot_base_class.prototype.n = vnNil;
909
+
910
+ vnNil.r = false;
911
+
912
+ // Hash
913
+ class_hash = define_class_under(class_object, "Hash", class_object);
914
+ class_hash.allocator.prototype.info = T_OBJECT | T_HASH;
915
+
916
+ class_hash.allocator.prototype.hash_store = function(key, value) {
917
+ var hash = key.hash();
918
+ // if we dont have the hashed key, add it
919
+ if (!this.__assocs__.hasOwnProperty(hash)) {
920
+ this.__keys__.push(key);
921
+ }
922
+ // then in both cases reset the assoc
923
+ return this.__assocs__[hash] = value;
924
+ };
925
+
926
+ class_hash.allocator.prototype.hash_delete = function(key) {
927
+ var hash = key.hash();
928
+
929
+ if (this.__assocs__[hash]) {
930
+ var ret = this.__assocs__[hash];
931
+ delete this.__assocs__[hash];
932
+ this.__keys__.splice(this.__keys__.indexOf(key), 1);
933
+ return ret;
934
+ }
935
+
936
+ return this.__default__;
937
+ };
938
+
939
+ class_hash.allocator.prototype.hash_fetch = function(key) {
940
+ var hash = key.hash();
941
+
942
+ if (this.__assocs__.hasOwnProperty(hash))
943
+ return this.__assocs__[hash];
944
+
945
+ // default return nil (should be overrideable)
946
+ return this.__default__;
947
+ };
948
+
949
+ // Symbol class
950
+ class_symbol = define_class_under(class_object, "Symbol", class_object);
951
+
952
+ class_symbol.allocator.prototype.toString = function() {
953
+ return ":" + this.__ptr__;
954
+ };
955
+
956
+ // Regexp
957
+ class_regexp = define_class_under(class_object, "Regexp", class_object);
958
+
959
+
960
+ // Exceptions
961
+ class_exception = define_class_under(class_object, "Exception", class_object);
962
+
963
+ class_exception.allocator.prototype.toString = function() {
964
+ var message = this.ig('@message');
965
+ if (message && message.r)
966
+ return this.class_name + ": " + this.ig('@message').toString();
967
+
968
+ return this.class_name;
969
+ };
970
+
971
+ class_exception.allocator.prototype.raise = function() {
972
+ // console.log(this);
973
+ throw this;
974
+ };
975
+
976
+ // Special Classes: We do these three (Array, String, Number) last so that we
977
+ // have all our special runtime methods setup so we can add them to
978
+ // Array.prototype, String.prototype and Number.prototype. Note: we could also
979
+ // do RegExp....?
980
+
981
+ // Number class
982
+ class_number = define_bridged_class("Number", Number);
983
+ class_number.allocator.prototype.info = T_OBJECT | T_NUMBER;
984
+
985
+ class_number.allocator.prototype.hash = function() {
986
+ return '$$num$$' + this;
987
+ };
988
+
989
+
990
+ // String class
991
+ class_string = define_bridged_class("String", String);
992
+ class_string.allocator.prototype.info = T_OBJECT | T_STRING;
993
+
994
+ class_string.allocator.prototype.hash = function() {
995
+ return this;
996
+ };
997
+
998
+
999
+ // Array class
1000
+ class_array = define_bridged_class("Array", Array);
1001
+ class_array.allocator.prototype.info = T_OBJECT | T_ARRAY;
1002
+
1003
+ // Regexp class
1004
+ class_regexp = define_bridged_class("Regexp", RegExp);
1005
+ class_regexp.allocator.prototype.info = T_OBJECT;
1006
+
1007
+
1008
+ // Kernel module
1009
+ module_kernel = define_module_under(class_object, "Kernel");
1010
+ class_object.include(module_kernel);