opal 0.4.3 → 0.4.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (303) hide show
  1. data/.rspec +3 -0
  2. data/.travis.yml +0 -4
  3. data/README.md +6 -0
  4. data/Rakefile +30 -6
  5. data/bin/opal +6 -82
  6. data/corelib/{opal/array.rb → array.rb} +40 -56
  7. data/corelib/{opal/basic_object.rb → basic_object.rb} +2 -2
  8. data/corelib/{opal/boolean.rb → boolean.rb} +0 -8
  9. data/corelib/class.rb +47 -0
  10. data/corelib/{opal/comparable.rb → comparable.rb} +0 -0
  11. data/corelib/{opal/enumerable.rb → enumerable.rb} +208 -141
  12. data/corelib/{opal/enumerator.rb → enumerator.rb} +3 -3
  13. data/corelib/{opal/error.rb → error.rb} +1 -0
  14. data/corelib/{opal/hash.rb → hash.rb} +67 -56
  15. data/corelib/io.rb +39 -0
  16. data/corelib/{opal/kernel.rb → kernel.rb} +35 -31
  17. data/corelib/{opal/class.rb → module.rb} +29 -57
  18. data/corelib/native.rb +148 -0
  19. data/corelib/{opal/nil_class.rb → nil_class.rb} +2 -10
  20. data/corelib/{opal/numeric.rb → numeric.rb} +39 -14
  21. data/corelib/opal.rb +42 -25
  22. data/corelib/{opal/proc.rb → proc.rb} +3 -3
  23. data/corelib/{opal/range.rb → range.rb} +5 -1
  24. data/corelib/{opal/regexp.rb → regexp.rb} +0 -0
  25. data/corelib/{opal/runtime.js → runtime.js} +96 -188
  26. data/corelib/{opal/string.rb → string.rb} +20 -15
  27. data/corelib/struct.rb +139 -0
  28. data/corelib/{opal/time.rb → time.rb} +0 -0
  29. data/lib/opal.rb +4 -0
  30. data/lib/opal/cli.rb +79 -32
  31. data/lib/opal/cli_options.rb +91 -0
  32. data/lib/opal/erb.rb +41 -8
  33. data/lib/opal/grammar.rb +24 -10
  34. data/lib/opal/grammar.y +15 -4
  35. data/lib/opal/grammar_helpers.rb +4 -0
  36. data/lib/opal/lexer.rb +214 -143
  37. data/lib/opal/parser.rb +596 -562
  38. data/lib/opal/require_parser.rb +1 -1
  39. data/lib/opal/source_map.rb +15 -30
  40. data/lib/opal/target_scope.rb +24 -5
  41. data/lib/opal/version.rb +1 -1
  42. data/mri_spec/cli_spec.rb +18 -0
  43. data/mri_spec/fixtures/opal_file.rb +2 -0
  44. data/mri_spec/spec_helper.rb +17 -0
  45. data/opal.gemspec +5 -2
  46. data/spec/{rubyspec/filters → filters}/bugs/alias.rb +0 -0
  47. data/spec/{rubyspec/filters → filters}/bugs/ancestors.rb +0 -0
  48. data/spec/{rubyspec/filters → filters}/bugs/array.rb +0 -0
  49. data/spec/filters/bugs/array/combination.rb +11 -0
  50. data/spec/filters/bugs/array/count.rb +3 -0
  51. data/spec/filters/bugs/array/delete_if.rb +3 -0
  52. data/spec/filters/bugs/array/drop.rb +3 -0
  53. data/spec/filters/bugs/array/drop_while.rb +5 -0
  54. data/spec/filters/bugs/array/eql.rb +3 -0
  55. data/spec/filters/bugs/array/flatten.rb +9 -0
  56. data/spec/filters/bugs/array/minus.rb +5 -0
  57. data/spec/filters/bugs/array/multipliy.rb +9 -0
  58. data/spec/filters/bugs/array/new.rb +3 -0
  59. data/spec/filters/bugs/array/pop.rb +6 -0
  60. data/spec/filters/bugs/array/rassoc.rb +4 -0
  61. data/spec/filters/bugs/array/rindex.rb +6 -0
  62. data/spec/filters/bugs/array/select.rb +3 -0
  63. data/spec/filters/bugs/array/shift.rb +7 -0
  64. data/spec/filters/bugs/array/shuffle.rb +11 -0
  65. data/spec/filters/bugs/array/slice.rb +7 -0
  66. data/spec/filters/bugs/array/take.rb +3 -0
  67. data/spec/filters/bugs/array/to_a.rb +3 -0
  68. data/spec/filters/bugs/array/try_convert.rb +7 -0
  69. data/spec/filters/bugs/array/uniq.rb +10 -0
  70. data/spec/filters/bugs/array/zip.rb +4 -0
  71. data/spec/{rubyspec/filters → filters}/bugs/array_delete.rb +1 -0
  72. data/spec/{rubyspec/filters → filters}/bugs/array_fetch.rb +0 -0
  73. data/spec/{rubyspec/filters → filters}/bugs/array_first.rb +0 -0
  74. data/spec/{rubyspec/filters → filters}/bugs/array_flatten.rb +0 -0
  75. data/spec/{rubyspec/filters → filters}/bugs/array_intersection.rb +0 -0
  76. data/spec/{rubyspec/filters → filters}/bugs/array_join.rb +0 -0
  77. data/spec/{rubyspec/filters → filters}/bugs/break.rb +0 -0
  78. data/spec/filters/bugs/case.rb +4 -0
  79. data/spec/{rubyspec/filters → filters}/bugs/coerce_integer.rb +0 -0
  80. data/spec/filters/bugs/enumerable_sort_by.rb +3 -0
  81. data/spec/{rubyspec/filters → filters}/bugs/kernel/instance_variables.rb +0 -0
  82. data/spec/filters/bugs/kernel/rand.rb +4 -0
  83. data/spec/filters/bugs/language/array.rb +3 -0
  84. data/spec/filters/bugs/language/block.rb +6 -0
  85. data/spec/filters/bugs/language/break.rb +3 -0
  86. data/spec/{rubyspec/filters → filters}/bugs/language/class.rb +3 -0
  87. data/spec/{rubyspec/filters → filters}/bugs/language/class_variables.rb +0 -0
  88. data/spec/filters/bugs/language/def.rb +27 -0
  89. data/spec/filters/bugs/language/defined.rb +3 -0
  90. data/spec/filters/bugs/language/ensure.rb +4 -0
  91. data/spec/filters/bugs/language/execution.rb +4 -0
  92. data/spec/filters/bugs/language/for.rb +18 -0
  93. data/spec/filters/bugs/language/if.rb +13 -0
  94. data/spec/filters/bugs/language/loop.rb +4 -0
  95. data/spec/filters/bugs/language/metaclass.rb +14 -0
  96. data/spec/filters/bugs/language/module.rb +6 -0
  97. data/spec/filters/bugs/language/next.rb +3 -0
  98. data/spec/filters/bugs/language/or.rb +3 -0
  99. data/spec/filters/bugs/language/order.rb +4 -0
  100. data/spec/filters/bugs/language/precedence.rb +10 -0
  101. data/spec/filters/bugs/language/proc.rb +24 -0
  102. data/spec/filters/bugs/language/redo.rb +5 -0
  103. data/spec/filters/bugs/language/rescue.rb +9 -0
  104. data/spec/filters/bugs/language/retry.rb +5 -0
  105. data/spec/filters/bugs/language/send.rb +10 -0
  106. data/spec/filters/bugs/language/super.rb +9 -0
  107. data/spec/filters/bugs/language/until.rb +8 -0
  108. data/spec/filters/bugs/language/variables.rb +37 -0
  109. data/spec/filters/bugs/language/while.rb +6 -0
  110. data/spec/filters/bugs/language/yield.rb +5 -0
  111. data/spec/{rubyspec/filters → filters}/bugs/module/class_variables.rb +0 -0
  112. data/spec/filters/bugs/module/method_defined.rb +6 -0
  113. data/spec/filters/bugs/parser.rb +10 -0
  114. data/spec/{rubyspec/filters → filters}/bugs/public_methods.rb +1 -0
  115. data/spec/filters/bugs/return.rb +7 -0
  116. data/spec/filters/bugs/singleton/instance.rb +4 -0
  117. data/spec/filters/bugs/source_map.rb +3 -0
  118. data/spec/filters/bugs/string/center.rb +4 -0
  119. data/spec/filters/bugs/string/lines.rb +3 -0
  120. data/spec/{rubyspec/filters → filters}/mspec/mocks.rb +0 -0
  121. data/spec/{rubyspec/filters → filters}/mspec/ruby_exe.rb +0 -0
  122. data/spec/{rubyspec/filters → filters}/mspec/should_receive.rb +0 -0
  123. data/spec/{rubyspec/filters → filters}/parser/block_args.rb +0 -0
  124. data/spec/{rubyspec/filters → filters}/unsupported/array_subclasses.rb +1 -0
  125. data/spec/filters/unsupported/frozen.rb +32 -0
  126. data/spec/filters/unsupported/immutable_strings.rb +3 -0
  127. data/spec/filters/unsupported/tainted.rb +17 -0
  128. data/spec/filters/unsupported/trusted.rb +15 -0
  129. data/spec/opal/class/constants_spec.rb +7 -0
  130. data/spec/opal/erb/erb_spec.rb +7 -1
  131. data/spec/opal/erb/inline_block.opalerb +3 -0
  132. data/spec/opal/hash/allocate_spec.rb +16 -0
  133. data/spec/opal/hash/new_spec.rb +10 -0
  134. data/spec/opal/hash/to_s_spec.rb +9 -0
  135. data/spec/opal/kernel/instance_variable_defined_spec.rb +15 -0
  136. data/spec/opal/kernel/rand_spec.rb +5 -5
  137. data/spec/opal/kernel/respond_to_spec.rb +14 -1
  138. data/spec/opal/language/block_spec.rb +13 -0
  139. data/spec/opal/language/rescue_spec.rb +27 -0
  140. data/spec/opal/language/return_spec.rb +38 -0
  141. data/spec/opal/language/singleton_class_spec.rb +13 -0
  142. data/spec/opal/language/super_spec.rb +99 -0
  143. data/spec/opal/language/variables_spec.rb +20 -0
  144. data/spec/opal/module/attr_accessor_spec.rb +8 -0
  145. data/spec/opal/module/constants_spec.rb +2 -2
  146. data/spec/opal/native/alias_native_spec.rb +18 -0
  147. data/spec/opal/native/each_spec.rb +14 -0
  148. data/spec/opal/native/element_reference_spec.rb +14 -0
  149. data/spec/opal/native/method_missing_spec.rb +39 -0
  150. data/spec/opal/native/new_spec.rb +19 -0
  151. data/spec/opal/native/nil_spec.rb +14 -0
  152. data/spec/opal/runtime2/class_hierarchy_spec.rb +2 -2
  153. data/spec/opal/source_map_spec.rb +3 -7
  154. data/spec/ospec/main.rb.erb +2 -5
  155. data/spec/parser/alias_spec.rb +4 -4
  156. data/spec/parser/and_spec.rb +2 -2
  157. data/spec/parser/array_spec.rb +6 -6
  158. data/spec/parser/attrasgn_spec.rb +8 -8
  159. data/spec/parser/begin_spec.rb +11 -11
  160. data/spec/parser/block_spec.rb +3 -3
  161. data/spec/parser/break_spec.rb +4 -4
  162. data/spec/parser/call_spec.rb +50 -48
  163. data/spec/parser/class_spec.rb +2 -2
  164. data/spec/parser/const_spec.rb +1 -1
  165. data/spec/parser/cvar_spec.rb +1 -1
  166. data/spec/parser/def_spec.rb +5 -5
  167. data/spec/parser/gvar_spec.rb +2 -2
  168. data/spec/parser/hash_spec.rb +4 -4
  169. data/spec/parser/iasgn_spec.rb +3 -3
  170. data/spec/parser/if_spec.rb +6 -6
  171. data/spec/parser/iter_spec.rb +6 -6
  172. data/spec/parser/lambda_spec.rb +5 -5
  173. data/spec/parser/lasgn_spec.rb +2 -2
  174. data/spec/parser/line_spec.rb +2 -2
  175. data/spec/parser/lvar_spec.rb +5 -5
  176. data/spec/parser/masgn_spec.rb +1 -1
  177. data/spec/parser/module_spec.rb +2 -2
  178. data/spec/parser/not_spec.rb +4 -4
  179. data/spec/parser/op_asgn1_spec.rb +2 -2
  180. data/spec/parser/op_asgn2_spec.rb +2 -2
  181. data/spec/parser/or_spec.rb +2 -2
  182. data/spec/parser/parse_spec.rb +66 -0
  183. data/spec/parser/parser_spec.rb +32 -38
  184. data/spec/parser/regexp_spec.rb +4 -4
  185. data/spec/parser/return_spec.rb +4 -4
  186. data/spec/parser/sclass_spec.rb +4 -4
  187. data/spec/parser/str_spec.rb +3 -3
  188. data/spec/parser/super_spec.rb +6 -6
  189. data/spec/parser/undef_spec.rb +3 -3
  190. data/spec/parser/unless_spec.rb +4 -4
  191. data/spec/parser/while_spec.rb +3 -3
  192. data/spec/parser/xstr_spec.rb +3 -3
  193. data/spec/parser/yield_spec.rb +6 -6
  194. data/spec/rubyspec/core/array/drop_spec.rb +1 -1
  195. data/spec/rubyspec/core/array/keep_if_spec.rb +1 -3
  196. data/spec/rubyspec/core/array/length_spec.rb +1 -3
  197. data/spec/rubyspec/core/array/map_spec.rb +2 -6
  198. data/spec/rubyspec/core/array/minus_spec.rb +3 -3
  199. data/spec/rubyspec/core/array/multiply_spec.rb +14 -16
  200. data/spec/rubyspec/core/array/new_spec.rb +3 -5
  201. data/spec/rubyspec/core/array/plus_spec.rb +2 -2
  202. data/spec/rubyspec/core/array/pop_spec.rb +4 -4
  203. data/spec/rubyspec/core/array/rassoc_spec.rb +2 -2
  204. data/spec/rubyspec/core/array/reject_spec.rb +2 -6
  205. data/spec/rubyspec/core/array/replace_spec.rb +1 -3
  206. data/spec/rubyspec/core/array/reverse_each_spec.rb +1 -3
  207. data/spec/rubyspec/core/array/reverse_spec.rb +4 -4
  208. data/spec/rubyspec/core/array/rindex_spec.rb +1 -1
  209. data/spec/rubyspec/core/array/select_spec.rb +3 -7
  210. data/spec/rubyspec/core/array/shared/collect.rb +7 -0
  211. data/spec/rubyspec/core/array/shared/index.rb +1 -1
  212. data/spec/rubyspec/core/array/shared/keep_if.rb +3 -0
  213. data/spec/rubyspec/core/array/shared/length.rb +3 -0
  214. data/spec/rubyspec/core/array/shared/replace.rb +3 -0
  215. data/spec/rubyspec/core/array/shared/slice.rb +3 -0
  216. data/spec/rubyspec/core/array/shuffle_spec.rb +1 -1
  217. data/spec/rubyspec/core/array/size_spec.rb +1 -3
  218. data/spec/rubyspec/core/array/slice_spec.rb +4 -6
  219. data/spec/rubyspec/core/array/sort_spec.rb +2 -2
  220. data/spec/rubyspec/core/array/to_a_spec.rb +1 -1
  221. data/spec/rubyspec/core/array/try_convert_spec.rb +7 -7
  222. data/spec/rubyspec/core/array/uniq_spec.rb +7 -7
  223. data/spec/rubyspec/core/array/zip_spec.rb +1 -1
  224. data/spec/rubyspec/core/enumerable/collect_spec.rb +24 -0
  225. data/spec/rubyspec/core/enumerable/count_spec.rb +35 -19
  226. data/spec/rubyspec/core/enumerable/find_spec.rb +5 -0
  227. data/spec/rubyspec/core/hash/each_pair_spec.rb +7 -7
  228. data/spec/rubyspec/core/hash/each_spec.rb +13 -7
  229. data/spec/rubyspec/core/module/method_defined_spec.rb +4 -4
  230. data/spec/rubyspec/core/module/public_method_defined_spec.rb +19 -0
  231. data/spec/rubyspec/core/module/remove_const_spec.rb +23 -0
  232. data/spec/rubyspec/core/numeric/step_spec.rb +14 -0
  233. data/spec/rubyspec/core/string/center_spec.rb +43 -65
  234. data/spec/rubyspec/core/string/lines_spec.rb +1 -1
  235. data/spec/rubyspec/core/string/ljust_spec.rb +25 -9
  236. data/spec/rubyspec/core/string/rjust_spec.rb +26 -10
  237. data/spec/rubyspec/core/struct/fixtures/classes.rb +26 -0
  238. data/spec/rubyspec/core/struct/initialize_spec.rb +11 -0
  239. data/spec/rubyspec/core/struct/new_spec.rb +24 -0
  240. data/spec/rubyspec/fixtures/constants.rb +7 -0
  241. data/spec/rubyspec/language/break_spec.rb +1 -1
  242. data/spec/rubyspec/language/case_spec.rb +30 -30
  243. data/spec/rubyspec/language/def_spec.rb +34 -34
  244. data/spec/rubyspec/language/defined_spec.rb +2 -2
  245. data/spec/rubyspec/language/ensure_spec.rb +2 -2
  246. data/spec/rubyspec/language/execution_spec.rb +2 -2
  247. data/spec/rubyspec/language/for_spec.rb +17 -17
  248. data/spec/rubyspec/language/hash_spec.rb +3 -3
  249. data/spec/rubyspec/language/if_spec.rb +11 -11
  250. data/spec/rubyspec/language/loop_spec.rb +3 -3
  251. data/spec/rubyspec/language/metaclass_spec.rb +14 -14
  252. data/spec/rubyspec/language/module_spec.rb +6 -6
  253. data/spec/rubyspec/language/next_spec.rb +5 -5
  254. data/spec/rubyspec/language/not_spec.rb +1 -1
  255. data/spec/rubyspec/language/or_spec.rb +1 -1
  256. data/spec/rubyspec/language/order_spec.rb +3 -5
  257. data/spec/rubyspec/language/precedence_spec.rb +19 -19
  258. data/spec/rubyspec/language/proc_spec.rb +29 -29
  259. data/spec/rubyspec/language/redo_spec.rb +3 -5
  260. data/spec/rubyspec/language/rescue_spec.rb +7 -7
  261. data/spec/rubyspec/language/retry_spec.rb +2 -2
  262. data/spec/rubyspec/language/return_spec.rb +12 -12
  263. data/spec/rubyspec/language/send_spec.rb +9 -9
  264. data/spec/rubyspec/language/singleton_class_spec.rb +3 -4
  265. data/spec/rubyspec/language/super_spec.rb +7 -11
  266. data/spec/rubyspec/language/until_spec.rb +10 -10
  267. data/spec/rubyspec/language/variables_spec.rb +59 -67
  268. data/spec/rubyspec/language/versions/array_1.9.rb +1 -1
  269. data/spec/rubyspec/language/versions/block_1.9.rb +0 -0
  270. data/spec/rubyspec/language/versions/break_1.9.rb +0 -0
  271. data/spec/rubyspec/language/versions/literal_lambda_1.9.rb +12 -12
  272. data/spec/rubyspec/language/versions/send_1.9.rb +23 -23
  273. data/spec/rubyspec/language/versions/symbol_1.9.rb +2 -2
  274. data/spec/rubyspec/language/versions/variables_1.9.rb +1 -1
  275. data/spec/rubyspec/language/while_spec.rb +4 -4
  276. data/spec/rubyspec/language/yield_spec.rb +3 -3
  277. data/spec/rubyspec/library/erb/util/html_escape_spec.rb +10 -0
  278. data/spec/rubyspec/library/singleton/clone_spec.rb +8 -0
  279. data/spec/rubyspec/library/singleton/dup_spec.rb +8 -0
  280. data/spec/rubyspec/library/singleton/fixtures/classes.rb +18 -0
  281. data/spec/rubyspec/library/singleton/instance_spec.rb +30 -0
  282. data/spec/spec_helper.rb +214 -0
  283. data/stdlib/buffer.rb +40 -0
  284. data/stdlib/buffer/array.rb +66 -0
  285. data/stdlib/buffer/view.rb +70 -0
  286. data/stdlib/erb.rb +11 -20
  287. data/stdlib/forwardable.rb +71 -0
  288. data/stdlib/json.rb +78 -0
  289. data/stdlib/ostruct.rb +69 -0
  290. data/stdlib/rbconfig.rb +1 -0
  291. data/stdlib/singleton.rb +40 -0
  292. data/stdlib/stringio.rb +173 -0
  293. data/stdlib/template.rb +44 -0
  294. metadata +285 -79
  295. data/corelib/opal/native.rb +0 -31
  296. data/spec/opal/class/bridge_class_spec.rb +0 -39
  297. data/spec/opal/native_spec.rb +0 -209
  298. data/spec/ospec/runner.rb +0 -223
  299. data/spec/rubyspec/filters/bugs/block_args.rb +0 -3
  300. data/spec/rubyspec/filters/bugs/case.rb +0 -8
  301. data/spec/rubyspec/filters/bugs/language/module.rb +0 -3
  302. data/spec/rubyspec/filters/unsupported/frozen.rb +0 -4
  303. data/spec/rubyspec/filters/unsupported/tainted.rb +0 -7
data/corelib/opal.rb CHANGED
@@ -1,22 +1,25 @@
1
- require 'opal/runtime'
2
- require 'opal/class'
3
- require 'opal/basic_object'
4
- require 'opal/kernel'
5
- require 'opal/nil_class'
6
- require 'opal/boolean'
7
- require 'opal/error'
8
- require 'opal/regexp'
9
- require 'opal/comparable'
10
- require 'opal/enumerable'
11
- require 'opal/enumerator'
12
- require 'opal/array'
13
- require 'opal/hash'
14
- require 'opal/string'
15
- require 'opal/numeric'
16
- require 'opal/proc'
17
- require 'opal/range'
18
- require 'opal/time'
19
- require 'opal/native'
1
+ require 'runtime'
2
+ require 'module'
3
+ require 'class'
4
+ require 'basic_object'
5
+ require 'kernel'
6
+ require 'nil_class'
7
+ require 'boolean'
8
+ require 'error'
9
+ require 'regexp'
10
+ require 'comparable'
11
+ require 'enumerable'
12
+ require 'enumerator'
13
+ require 'array'
14
+ require 'hash'
15
+ require 'string'
16
+ require 'numeric'
17
+ require 'proc'
18
+ require 'range'
19
+ require 'time'
20
+ require 'struct'
21
+ require 'native'
22
+ require 'io'
20
23
 
21
24
  # regexp matches
22
25
  $& = $~ = $` = $' = nil
@@ -26,9 +29,10 @@ $: = []
26
29
 
27
30
  # split lines
28
31
  $/ = "\n"
32
+ $, = " "
29
33
 
30
34
  # native global
31
- $$ = $global = `Opal.global`
35
+ $$ = $global = Native(`Opal.global`)
32
36
 
33
37
  ARGV = []
34
38
  ARGF = Object.new
@@ -37,15 +41,28 @@ TRUE = true
37
41
  FALSE = false
38
42
  NIL = nil
39
43
 
40
- STDERR = $stderr = Object.new
41
- STDIN = $stdin = Object.new
42
- STDOUT = $stdout = Object.new
44
+ STDERR = $stderr = IO.new
45
+ STDIN = $stdin = IO.new
46
+ STDOUT = $stdout = IO.new
47
+
48
+ def $stdout.puts(*strs)
49
+ %x{
50
+ for (var i = 0; i < strs.length; i++) {
51
+ if(strs[i] instanceof Array) {
52
+ #{ puts(*`strs[i]`) }
53
+ } else {
54
+ $opal.puts(#{ `strs[i]`.to_s });
55
+ }
56
+ }
57
+ }
58
+ nil
59
+ end
43
60
 
44
61
  RUBY_PLATFORM = 'opal'
45
62
  RUBY_ENGINE = 'opal'
46
63
  RUBY_VERSION = '1.9.3'
47
- RUBY_ENGINE_VERSION = '0.4.3'
48
- RUBY_RELEASE_DATE = '2013-07-24'
64
+ RUBY_ENGINE_VERSION = '0.4.4'
65
+ RUBY_RELEASE_DATE = '2013-08-13'
49
66
 
50
67
  def self.to_s
51
68
  'main'
@@ -3,7 +3,7 @@ class Proc
3
3
  `def.is_lambda = true`
4
4
 
5
5
  def self.new(&block)
6
- `if (block === nil) no_block_given();`
6
+ `if (block === nil) { throw new Error("no block given"); }`
7
7
  `block.is_lambda = false`
8
8
  block
9
9
  end
@@ -12,8 +12,8 @@ class Proc
12
12
  %x{
13
13
  var result = #{self}.apply(null, #{args});
14
14
 
15
- if (result === __breaker) {
16
- return __breaker.$v;
15
+ if (result === $breaker) {
16
+ return $breaker.$v;
17
17
  }
18
18
 
19
19
  return result;
@@ -42,6 +42,10 @@ class Range
42
42
  `#{self}.begin` <= value && value <= (exclude_end? ? `#{self}.end` - 1 : `#{self}.end`)
43
43
  end
44
44
 
45
+ def last
46
+ self.end
47
+ end
48
+
45
49
  def each(&block)
46
50
  current = min
47
51
 
@@ -67,7 +71,7 @@ class Range
67
71
  end
68
72
 
69
73
  # FIXME: currently hardcoded to assume range holds numerics
70
- def include?(val)
74
+ def include?(obj)
71
75
  `return obj >= #{self}.begin && obj <= #{self}.end`
72
76
  end
73
77
 
File without changes
@@ -11,6 +11,9 @@
11
11
  // Class' class
12
12
  function Class(){}
13
13
 
14
+ // Module's class
15
+ function Module(){}
16
+
14
17
  // the class of nil
15
18
  function NilClass(){}
16
19
 
@@ -27,8 +30,8 @@
27
30
  Opal.global = this;
28
31
 
29
32
  // Minify common function calls
30
- var __hasOwn = Opal.hasOwnProperty;
31
- var __slice = Opal.slice = Array.prototype.slice;
33
+ var $hasOwn = Opal.hasOwnProperty;
34
+ var $slice = Opal.slice = Array.prototype.slice;
32
35
 
33
36
  // Generates unique id for every ruby object
34
37
  var unique_id = 0;
@@ -61,20 +64,6 @@
61
64
  }
62
65
  }
63
66
 
64
- /*
65
- Define a bridged class. Bridged classes will always be in the top level
66
- scope, and will always be a subclass of Object.
67
- */
68
- Opal.bridge = function(name, constructor) {
69
- var klass = bridge_class(constructor);
70
-
71
- klass._name = name;
72
-
73
- create_scope(Opal, klass, name);
74
-
75
- return klass;
76
- };
77
-
78
67
  Opal.klass = function(base, superklass, id, constructor) {
79
68
  var klass;
80
69
 
@@ -86,7 +75,7 @@
86
75
  superklass = ObjectClass;
87
76
  }
88
77
 
89
- if (__hasOwn.call(base._scope, id)) {
78
+ if ($hasOwn.call(base._scope, id)) {
90
79
  klass = base._scope[id];
91
80
 
92
81
  if (!klass._isClass) {
@@ -122,7 +111,7 @@
122
111
  base = base._klass;
123
112
  }
124
113
 
125
- if (__hasOwn.call(base._scope, id)) {
114
+ if ($hasOwn.call(base._scope, id)) {
126
115
  klass = base._scope[id];
127
116
 
128
117
  if (!klass._mod$ && klass !== ObjectClass) {
@@ -142,11 +131,6 @@
142
131
  return klass;
143
132
  };
144
133
 
145
- // Utility function to raise a "no block given" error
146
- var no_block_given = function() {
147
- throw new Error('no block given');
148
- };
149
-
150
134
  // Boot a base class (makes instances).
151
135
  var boot_defclass = function(id, constructor, superklass) {
152
136
  if (superklass) {
@@ -175,7 +159,6 @@
175
159
  RubyClass.prototype = new ctor();
176
160
 
177
161
  var prototype = RubyClass.prototype;
178
- prototype._isBoot = true;
179
162
  prototype._alloc = klass;
180
163
  prototype._isClass = true;
181
164
  prototype._name = id;
@@ -230,7 +213,7 @@
230
213
  return constructor;
231
214
  };
232
215
 
233
- var bridge_class = function(constructor) {
216
+ var bridge_class = function(name, constructor) {
234
217
  var klass = boot_class(ObjectClass, constructor);
235
218
  var i, length, m;
236
219
 
@@ -249,184 +232,102 @@
249
232
  constructor.prototype[m] = table[m];
250
233
  }
251
234
 
235
+ klass._name = name;
236
+ create_scope(Opal, klass, name);
237
+
252
238
  return klass;
253
239
  };
254
240
 
255
241
  Opal.puts = function(a) { console.log(a); };
256
242
 
257
- var native_singleton = {
258
- _scope: Opal,
259
- prototype: null
260
- };
261
-
262
- // Singleton class
263
- Opal.singleton = function(obj) {
264
- if (obj == null) {
265
- return Opal.NilClass;
266
- }
267
- else if (obj.$singleton_class) {
268
- return obj.$singleton_class();
269
- }
270
- else {
271
- native_singleton.prototype = obj;
272
- return native_singleton;
273
- }
274
- };
275
-
276
- // Method missing dispatcher
277
- Opal.mm = function(mid) {
278
- var dispatcher = function() {
279
- var args = __slice.call(arguments);
243
+ Opal.add_stubs = function(stubs) {
244
+ for (var i = 0, length = stubs.length; i < length; i++) {
245
+ var stub = stubs[i];
280
246
 
281
- if (this.$method_missing) {
282
- this.$method_missing._p = dispatcher._p;
283
- return this.$method_missing.apply(this, [mid].concat(args));
284
- }
285
- else {
286
- native_send._p = dispatcher._p;
287
- return native_send(this, mid, args);
247
+ if (!BasicObject.prototype[stub]) {
248
+ BasicObject.prototype[stub] = true;
249
+ add_stub_for(BasicObject.prototype, stub);
288
250
  }
289
- };
290
-
291
- return dispatcher;
292
- };
293
-
294
- // send a method to a native object
295
- var native_send = function(obj, mid, args) {
296
- var prop, block = native_send._p;
297
- native_send._p = null;
298
-
299
- if ( (prop = native_methods[mid]) ) {
300
- return prop(obj, args, block);
301
251
  }
252
+ };
302
253
 
303
- prop = obj[mid];
254
+ function add_stub_for(prototype, stub) {
255
+ function method_missing_stub() {
256
+ this.$method_missing._p = method_missing_stub._p;
257
+ method_missing_stub._p = null;
304
258
 
305
- if (typeof(prop) === "function") {
306
- prop = prop.apply(obj, args.$to_n());
259
+ return this.$method_missing.apply(this, [stub.slice(1)].concat($slice.call(arguments)));
307
260
  }
308
- else if (mid.charAt(mid.length - 1) === "=") {
309
- prop = mid.slice(0, mid.length - 1);
310
261
 
311
- if (args[0] === nil) {
312
- obj[prop] = null;
313
- return nil;
314
- }
315
-
316
- return obj[prop] = args[0];
317
- }
262
+ method_missing_stub.rb_stub = true;
263
+ prototype[stub] = method_missing_stub;
264
+ }
318
265
 
319
- if (prop == null) {
320
- return nil;
321
- }
266
+ Opal.add_stub_for = add_stub_for;
322
267
 
323
- return prop;
268
+ // Const missing dispatcher
269
+ Opal.cm = function(name) {
270
+ return this.base.$const_missing(name);
324
271
  };
325
272
 
326
- var native_methods = {
327
- "==": function(obj, args) {
328
- return obj === args[0];
329
- },
330
-
331
- "[]": function(obj, args) {
332
- var prop = obj[args[0]];
333
-
334
- if (prop == null) {
335
- return nil;
336
- }
337
-
338
- return prop;
339
- },
340
-
341
- "[]=": function(obj, args) {
342
- var value = args[1];
343
-
344
- if (value === nil) {
345
- value = null;
346
- }
347
-
348
- return obj[args[0]] = value;
349
- },
273
+ // Arity count error dispatcher
274
+ Opal.ac = function(actual, expected, object, meth) {
275
+ var inspect = ((typeof(object) !== 'function') ? object.constructor._name + '#' : object._name + '.') + meth;
276
+ var msg = '[' + inspect + '] wrong number of arguments(' + actual + ' for ' + expected + ')';
277
+ throw Opal.ArgumentError.$new(msg);
278
+ };
350
279
 
351
- "inspect": function(obj) {
352
- return obj.toString();
353
- },
280
+ // Super dispatcher
281
+ Opal.dispatch_super = function(obj, jsid, args, iter, defs) {
282
+ var dispatcher;
354
283
 
355
- "to_s": function(obj) {
356
- return obj.toString();
357
- },
284
+ if (defs) {
285
+ dispatcher = obj._isClass ? defs._super : obj._klass._proto;
286
+ }
287
+ else {
288
+ dispatcher = obj._isClass ? obj._klass : obj._klass._super._proto;
289
+ }
358
290
 
359
- "respond_to?": function(obj, args) {
360
- return obj[args[0]] != null;
361
- },
291
+ dispatcher = dispatcher['$' + jsid];
292
+ dispatcher._p = iter;
362
293
 
363
- "each": function(obj, args, block) {
364
- var prop;
294
+ return dispatcher.apply(obj, args);
295
+ };
365
296
 
366
- if (obj.length === +obj.length) {
367
- for (var i = 0, len = obj.length; i < len; i++) {
368
- prop = obj[i];
297
+ // return helper
298
+ Opal.$return = function(val) {
299
+ Opal.returner.$v = val;
300
+ throw Opal.returner;
301
+ };
369
302
 
370
- if (prop == null) {
371
- prop = nil;
372
- }
303
+ // handles yield calls for 1 yielded arg
304
+ Opal.$yield1 = function(block, arg) {
305
+ if (typeof(block) !== "function") {
306
+ throw Opal.LocalJumpError.$new("no block given");
307
+ }
373
308
 
374
- block(prop);
375
- }
309
+ if (block.length > 1) {
310
+ if (arg._isArray) {
311
+ return block.apply(null, arg);
376
312
  }
377
313
  else {
378
- for (var key in obj) {
379
- prop = obj[key];
380
-
381
- if (prop == null) {
382
- prop = nil;
383
- }
384
-
385
- block(key, prop);
386
- }
314
+ return block(arg);
387
315
  }
388
-
389
- return obj;
390
- },
391
-
392
- "to_a": function(obj, args) {
393
- var result = [];
394
-
395
- for (var i = 0, length = obj.length; i < length; i++) {
396
- result.push(obj[i]);
397
- }
398
-
399
- return result;
400
- },
401
-
402
- "to_h": function(obj) {
403
- var keys = [], values = {}, value;
404
-
405
- for (var key in obj) {
406
- value = obj[key];
407
- keys.push(key);
408
-
409
- if (value == null) {
410
- value = nil;
411
- }
412
-
413
- values[key] = value;
414
- }
415
-
416
- return Opal.hash2(keys, values);
316
+ }
317
+ else {
318
+ return block(arg);
417
319
  }
418
320
  };
419
321
 
420
- // Const missing dispatcher
421
- Opal.cm = function(name) {
422
- return this.base.$const_missing(name);
423
- };
322
+ // handles yield for > 1 yielded arg
323
+ Opal.$yieldX = function(block, args) {
324
+ if (block.length > 1 && args.length == 1) {
325
+ if (args[0]._isArray) {
326
+ return block.apply(null, args[0]);
327
+ }
328
+ }
424
329
 
425
- // Arity count error dispatcher
426
- Opal.ac = function(actual, expected, object, meth) {
427
- var inspect = ((typeof(object) !== 'function') ? object.constructor._name + '#' : object._name + '.') + meth;
428
- var msg = '[' + inspect + '] wrong number of arguments(' + actual + ' for ' + expected + ')';
429
- throw Opal.ArgumentError.$new(msg);
330
+ return block.apply(null, args);
430
331
  };
431
332
 
432
333
  /*
@@ -445,7 +346,7 @@
445
346
  @param [String] mid ruby method to call
446
347
  */
447
348
  Opal.send = function(recv, mid) {
448
- var args = __slice.call(arguments, 2),
349
+ var args = $slice.call(arguments, 2),
449
350
  func = recv['$' + mid];
450
351
 
451
352
  if (func) {
@@ -456,7 +357,7 @@
456
357
  };
457
358
 
458
359
  Opal.block_send = function(recv, mid, block) {
459
- var args = __slice.call(arguments, 3),
360
+ var args = $slice.call(arguments, 3),
460
361
  func = recv['$' + mid];
461
362
 
462
363
  if (func) {
@@ -500,22 +401,26 @@
500
401
  // Constructors for *instances* of core objects
501
402
  boot_defclass('BasicObject', BasicObject);
502
403
  boot_defclass('Object', Object, BasicObject);
503
- boot_defclass('Class', Class, Object);
404
+ boot_defclass('Module', Module, Object);
405
+ boot_defclass('Class', Class, Module);
504
406
 
505
407
  // Constructors for *classes* of core objects
506
408
  var BasicObjectClass = boot_makemeta('BasicObject', BasicObject, Class);
507
409
  var ObjectClass = boot_makemeta('Object', Object, BasicObjectClass.constructor);
508
- var ClassClass = boot_makemeta('Class', Class, ObjectClass.constructor);
410
+ var ModuleClass = boot_makemeta('Module', Module, ObjectClass.constructor);
411
+ var ClassClass = boot_makemeta('Class', Class, ModuleClass.constructor);
509
412
 
510
413
  // Fix booted classes to use their metaclass
511
414
  BasicObjectClass._klass = ClassClass;
512
415
  ObjectClass._klass = ClassClass;
416
+ ModuleClass._klass = ClassClass;
513
417
  ClassClass._klass = ClassClass;
514
418
 
515
419
  // Fix superclasses of booted classes
516
420
  BasicObjectClass._super = null;
517
421
  ObjectClass._super = BasicObjectClass;
518
- ClassClass._super = ObjectClass;
422
+ ModuleClass._super = ObjectClass;
423
+ ClassClass._super = ModuleClass;
519
424
 
520
425
  // Defines methods onto Object (which are then donated to bridged classes)
521
426
  ObjectClass._defn = function (mid, body) {
@@ -527,15 +432,17 @@
527
432
 
528
433
  Opal.base = ObjectClass;
529
434
  BasicObjectClass._scope = ObjectClass._scope = Opal;
530
- Opal.Module = Opal.Class;
531
435
  Opal.Kernel = ObjectClass;
532
436
 
437
+ create_scope(Opal, ModuleClass);
533
438
  create_scope(Opal, ClassClass);
534
439
 
535
440
  ObjectClass._proto.toString = function() {
536
441
  return this.$to_s();
537
442
  };
538
443
 
444
+ ClassClass._proto._defn = function(mid, body) { this._proto[mid] = body; };
445
+
539
446
  Opal.top = new ObjectClass._alloc();
540
447
 
541
448
  Opal.klass(ObjectClass, ObjectClass, 'NilClass', NilClass);
@@ -544,15 +451,16 @@
544
451
  nil.call = nil.apply = function() { throw Opal.LocalJumpError.$new('no block given'); };
545
452
 
546
453
  Opal.breaker = new Error('unexpected break');
547
-
548
- Opal.bridge('Array', Array);
549
- Opal.bridge('Boolean', Boolean);
550
- Opal.bridge('Numeric', Number);
551
- Opal.bridge('String', String);
552
- Opal.bridge('Proc', Function);
553
- Opal.bridge('Exception', Error);
554
- Opal.bridge('Regexp', RegExp);
555
- Opal.bridge('Time', Date);
454
+ Opal.returner = new Error('unexpected return');
455
+
456
+ bridge_class('Array', Array);
457
+ bridge_class('Boolean', Boolean);
458
+ bridge_class('Numeric', Number);
459
+ bridge_class('String', String);
460
+ bridge_class('Proc', Function);
461
+ bridge_class('Exception', Error);
462
+ bridge_class('Regexp', RegExp);
463
+ bridge_class('Time', Date);
556
464
 
557
465
  TypeError._super = Error;
558
466
  }).call(this);