opal 0.3.16 → 0.3.17

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 (251) hide show
  1. data/.gitignore +2 -0
  2. data/CHANGELOG.md +12 -0
  3. data/Gemfile +8 -7
  4. data/README.md +21 -13
  5. data/Rakefile +64 -78
  6. data/bin/opal +18 -29
  7. data/core/alpha.rb +2 -9
  8. data/core/array.rb +106 -50
  9. data/core/basic_object.rb +10 -8
  10. data/core/boolean.rb +2 -0
  11. data/core/class.rb +25 -13
  12. data/core/comparable.rb +6 -6
  13. data/core/enumerable.rb +90 -94
  14. data/core/enumerator.rb +3 -3
  15. data/core/hash.rb +86 -46
  16. data/core/kernel.rb +55 -39
  17. data/core/load_order +2 -5
  18. data/core/match_data.rb +1 -1
  19. data/core/module.rb +45 -20
  20. data/core/nil_class.rb +6 -2
  21. data/core/numeric.rb +20 -10
  22. data/core/proc.rb +2 -2
  23. data/core/range.rb +72 -13
  24. data/core/regexp.rb +5 -3
  25. data/core/runtime.js +228 -287
  26. data/core/string.rb +345 -37
  27. data/core/top_self.rb +1 -1
  28. data/lib/opal.rb +13 -91
  29. data/lib/opal/builder.rb +47 -120
  30. data/lib/opal/builder_task.rb +74 -0
  31. data/lib/opal/{parser/grammar.rb → grammar.rb} +1094 -1083
  32. data/lib/opal/{parser/grammar.y → grammar.y} +7 -0
  33. data/lib/opal/{parser/lexer.rb → lexer.rb} +32 -11
  34. data/lib/opal/{parser/parser.rb → parser.rb} +232 -238
  35. data/lib/opal/{parser/scope.rb → scope.rb} +72 -9
  36. data/lib/opal/version.rb +2 -3
  37. data/opal.gemspec +1 -2
  38. data/{core_spec → spec}/core/array/allocate_spec.rb +1 -3
  39. data/{core_spec → spec}/core/array/append_spec.rb +1 -4
  40. data/{core_spec → spec}/core/array/assoc_spec.rb +1 -4
  41. data/{core_spec → spec}/core/array/at_spec.rb +1 -3
  42. data/{core_spec → spec}/core/array/clear_spec.rb +1 -3
  43. data/spec/core/array/clone_spec.rb +15 -0
  44. data/{core_spec/core/array/shared/collect.rb → spec/core/array/collect_spec.rb} +1 -1
  45. data/{core_spec → spec}/core/array/compact_spec.rb +1 -3
  46. data/{core_spec → spec}/core/array/concat_spec.rb +1 -3
  47. data/{core_spec → spec}/core/array/constructor_spec.rb +9 -3
  48. data/{core_spec → spec}/core/array/count_spec.rb +1 -3
  49. data/{core_spec → spec}/core/array/delete_at_spec.rb +1 -4
  50. data/{core_spec → spec}/core/array/delete_if_spec.rb +1 -4
  51. data/{core_spec → spec}/core/array/delete_spec.rb +1 -4
  52. data/{core_spec → spec}/core/array/each_index_spec.rb +1 -4
  53. data/{core_spec → spec}/core/array/each_spec.rb +1 -4
  54. data/{core_spec → spec}/core/array/element_reference_spec.rb +74 -4
  55. data/{core_spec → spec}/core/array/empty_spec.rb +1 -4
  56. data/{core_spec/core/array/shared/eql.rb → spec/core/array/eql_spec.rb} +1 -1
  57. data/{core_spec → spec}/core/array/fetch_spec.rb +1 -4
  58. data/{core_spec → spec}/core/array/first_spec.rb +1 -3
  59. data/{core_spec → spec}/core/array/flatten_spec.rb +1 -3
  60. data/{core_spec → spec}/core/array/include_spec.rb +1 -3
  61. data/{core_spec → spec}/core/array/insert_spec.rb +1 -4
  62. data/{core_spec → spec}/core/array/last_spec.rb +1 -4
  63. data/{core_spec/core/array/shared/length.rb → spec/core/array/length_spec.rb} +1 -1
  64. data/spec/core/array/map_spec.rb +53 -0
  65. data/{core_spec → spec}/core/array/plus_spec.rb +1 -4
  66. data/{core_spec → spec}/core/array/pop_spec.rb +1 -4
  67. data/{core_spec → spec}/core/array/push_spec.rb +1 -4
  68. data/{core_spec → spec}/core/array/rassoc_spec.rb +1 -4
  69. data/{core_spec → spec}/core/array/reject_spec.rb +1 -4
  70. data/{core_spec/core/array/shared/replace.rb → spec/core/array/replace_spec.rb} +1 -1
  71. data/{core_spec → spec}/core/array/reverse_each_spec.rb +1 -4
  72. data/{core_spec → spec}/core/array/reverse_spec.rb +1 -4
  73. data/spec/core/array/size_spec.rb +6 -0
  74. data/spec/core/array/to_ary_spec.rb +6 -0
  75. data/spec/core/array/uniq_spec.rb +22 -0
  76. data/spec/core/array/zip_spec.rb +20 -0
  77. data/{core_spec → spec}/core/class/new_spec.rb +1 -4
  78. data/{core_spec → spec}/core/enumerable/all_spec.rb +1 -4
  79. data/{core_spec → spec}/core/enumerable/any_spec.rb +1 -4
  80. data/{core_spec/core/enumerable/shared/collect.rb → spec/core/enumerable/collect_spec.rb} +1 -1
  81. data/{core_spec → spec}/core/enumerable/count_spec.rb +2 -5
  82. data/{core_spec → spec}/core/enumerable/fixtures/classes.rb +1 -2
  83. data/{core_spec → spec}/core/false/and_spec.rb +1 -3
  84. data/{core_spec → spec}/core/false/inspect_spec.rb +1 -3
  85. data/{core_spec → spec}/core/false/or_spec.rb +1 -3
  86. data/{core_spec → spec}/core/false/to_s_spec.rb +1 -3
  87. data/{core_spec → spec}/core/false/xor_spec.rb +1 -3
  88. data/{core_spec → spec}/core/hash/allocate_spec.rb +1 -3
  89. data/spec/core/hash/assoc_spec.rb +25 -0
  90. data/{core_spec → spec}/core/hash/clear_spec.rb +1 -3
  91. data/{core_spec → spec}/core/hash/clone_spec.rb +1 -3
  92. data/{core_spec → spec}/core/hash/default_spec.rb +1 -3
  93. data/{core_spec → spec}/core/hash/delete_if_spec.rb +1 -3
  94. data/{core_spec → spec}/core/hash/element_reference_spec.rb +1 -3
  95. data/{core_spec → spec}/core/hash/element_set_spec.rb +1 -3
  96. data/spec/core/hash/merge_spec.rb +37 -0
  97. data/{core_spec → spec}/core/hash/new_spec.rb +1 -3
  98. data/{core_spec → spec}/core/matchdata/to_a_spec.rb +1 -3
  99. data/{core_spec → spec}/core/nil/and_spec.rb +1 -4
  100. data/{core_spec → spec}/core/nil/inspect_spec.rb +1 -4
  101. data/{core_spec → spec}/core/nil/nil_spec.rb +1 -4
  102. data/{core_spec → spec}/core/nil/or_spec.rb +1 -4
  103. data/{core_spec → spec}/core/nil/to_a_spec.rb +1 -4
  104. data/{core_spec → spec}/core/nil/to_f_spec.rb +1 -4
  105. data/{core_spec → spec}/core/nil/to_i_spec.rb +1 -4
  106. data/{core_spec → spec}/core/nil/to_s_spec.rb +1 -4
  107. data/{core_spec → spec}/core/nil/xor_spec.rb +1 -4
  108. data/{core_spec → spec}/core/numeric/equal_value_spec.rb +1 -3
  109. data/{core_spec → spec}/core/regexp/match_spec.rb +10 -3
  110. data/{core_spec → spec}/core/symbol/to_proc_spec.rb +1 -3
  111. data/{core_spec → spec}/core/true/and_spec.rb +1 -3
  112. data/{core_spec → spec}/core/true/inspect_spec.rb +1 -3
  113. data/{core_spec → spec}/core/true/or_spec.rb +1 -3
  114. data/{core_spec → spec}/core/true/to_s_spec.rb +1 -3
  115. data/{core_spec → spec}/core/true/xor_spec.rb +1 -3
  116. data/spec/index.html +11 -0
  117. data/{core_spec → spec}/language/alias_spec.rb +1 -3
  118. data/{core_spec → spec}/language/and_spec.rb +1 -4
  119. data/{core_spec → spec}/language/array_spec.rb +1 -4
  120. data/{core_spec → spec}/language/block_spec.rb +20 -3
  121. data/{core_spec → spec}/language/break_spec.rb +40 -3
  122. data/{core_spec → spec}/language/case_spec.rb +1 -4
  123. data/{core_spec → spec}/language/defined_spec.rb +9 -3
  124. data/{core_spec → spec}/language/ensure_spec.rb +38 -3
  125. data/{core_spec → spec}/language/hash_spec.rb +1 -3
  126. data/{core_spec → spec}/language/if_spec.rb +1 -4
  127. data/{core_spec → spec}/language/loop_spec.rb +1 -3
  128. data/spec/language/metaclass_spec.rb +13 -0
  129. data/{core_spec → spec}/language/next_spec.rb +47 -3
  130. data/{core_spec → spec}/language/or_spec.rb +1 -4
  131. data/{core_spec → spec}/language/predefined_spec.rb +1 -3
  132. data/{core_spec/language/regexp/interpolation_spec.rb → spec/language/regexp_spec.rb} +6 -3
  133. data/{core_spec → spec}/language/send_spec.rb +38 -4
  134. data/spec/language/singleton_class_spec.rb +31 -0
  135. data/spec/language/super_spec.rb +188 -0
  136. data/{core_spec → spec}/language/symbol_spec.rb +1 -3
  137. data/{core_spec → spec}/language/undef_spec.rb +1 -3
  138. data/{core_spec → spec}/language/unless_spec.rb +1 -4
  139. data/{core_spec → spec}/language/until_spec.rb +1 -3
  140. data/{core_spec → spec}/language/variables_spec.rb +1 -3
  141. data/{core_spec → spec}/language/while_spec.rb +1 -3
  142. data/{spec → test}/builder/build_source_spec.rb +0 -0
  143. data/{spec → test}/builder/fixtures/build_source/adam.rb +0 -0
  144. data/{spec → test}/builder/fixtures/build_source/bar/a.rb +0 -0
  145. data/{spec → test}/builder/fixtures/build_source/bar/wow/b.rb +0 -0
  146. data/{spec → test}/builder/fixtures/build_source/bar/wow/cow/c.rb +0 -0
  147. data/{spec → test}/builder/fixtures/build_source/beynon.rb +0 -0
  148. data/{spec → test}/builder/fixtures/build_source/charles.js +0 -0
  149. data/{spec → test}/builder/fixtures/build_source/foo/a.rb +0 -0
  150. data/{spec → test}/builder/fixtures/build_source/foo/b.rb +0 -0
  151. data/{spec → test}/builder/fixtures/build_source/foo/x.js +0 -0
  152. data/{spec → test}/builder/fixtures/build_source/foo/y.js +0 -0
  153. data/{spec → test}/grammar/alias_spec.rb +0 -0
  154. data/{spec → test}/grammar/and_spec.rb +0 -0
  155. data/{spec → test}/grammar/array_spec.rb +0 -0
  156. data/{spec → test}/grammar/attrasgn_spec.rb +0 -0
  157. data/{spec → test}/grammar/begin_spec.rb +0 -0
  158. data/{spec → test}/grammar/block_spec.rb +0 -0
  159. data/{spec → test}/grammar/break_spec.rb +0 -0
  160. data/{spec → test}/grammar/call_spec.rb +0 -0
  161. data/{spec → test}/grammar/class_spec.rb +0 -0
  162. data/{spec → test}/grammar/const_spec.rb +0 -0
  163. data/{spec → test}/grammar/cvar_spec.rb +0 -0
  164. data/{spec → test}/grammar/def_spec.rb +0 -0
  165. data/{spec → test}/grammar/false_spec.rb +0 -0
  166. data/{spec → test}/grammar/file_spec.rb +0 -0
  167. data/{spec → test}/grammar/gvar_spec.rb +0 -0
  168. data/{spec → test}/grammar/hash_spec.rb +0 -0
  169. data/{spec → test}/grammar/iasgn_spec.rb +0 -0
  170. data/{spec → test}/grammar/if_spec.rb +0 -0
  171. data/{spec → test}/grammar/iter_spec.rb +0 -0
  172. data/{spec → test}/grammar/ivar_spec.rb +0 -0
  173. data/{spec → test}/grammar/lasgn_spec.rb +0 -0
  174. data/{spec → test}/grammar/line_spec.rb +0 -0
  175. data/{spec → test}/grammar/lvar_spec.rb +0 -0
  176. data/{spec → test}/grammar/masgn_spec.rb +0 -0
  177. data/{spec → test}/grammar/module_spec.rb +0 -0
  178. data/{spec → test}/grammar/nil_spec.rb +0 -0
  179. data/{spec → test}/grammar/not_spec.rb +0 -0
  180. data/{spec → test}/grammar/op_asgn1_spec.rb +0 -0
  181. data/{spec → test}/grammar/op_asgn2_spec.rb +0 -0
  182. data/{spec → test}/grammar/or_spec.rb +0 -0
  183. data/{spec → test}/grammar/return_spec.rb +0 -0
  184. data/{spec → test}/grammar/sclass_spec.rb +0 -0
  185. data/{spec → test}/grammar/self_spec.rb +0 -0
  186. data/{spec → test}/grammar/str_spec.rb +0 -0
  187. data/{spec → test}/grammar/super_spec.rb +0 -0
  188. data/{spec → test}/grammar/true_spec.rb +0 -0
  189. data/{spec → test}/grammar/undef_spec.rb +0 -0
  190. data/{spec → test}/grammar/unless_spec.rb +0 -0
  191. data/{spec → test}/grammar/while_spec.rb +0 -0
  192. data/{spec → test}/grammar/xstr_spec.rb +0 -0
  193. data/{spec → test}/grammar/yield_spec.rb +0 -0
  194. data/{spec → test}/spec_helper.rb +0 -0
  195. metadata +330 -264
  196. data/core/debug.js +0 -59
  197. data/core/debug.rb +0 -35
  198. data/core/dir.rb +0 -90
  199. data/core/file.rb +0 -83
  200. data/core/gemlib.rb +0 -30
  201. data/core/io.rb +0 -44
  202. data/core_spec/README.md +0 -34
  203. data/core_spec/core/array/collect_spec.rb +0 -3
  204. data/core_spec/core/array/element_set_spec.rb +0 -7
  205. data/core_spec/core/array/eql_spec.rb +0 -3
  206. data/core_spec/core/array/equal_value_spec.rb +0 -3
  207. data/core_spec/core/array/fixtures/classes.rb +0 -8
  208. data/core_spec/core/array/length_spec.rb +0 -3
  209. data/core_spec/core/array/map_spec.rb +0 -3
  210. data/core_spec/core/array/replace_spec.rb +0 -3
  211. data/core_spec/core/enumerable/collect_spec.rb +0 -3
  212. data/core_spec/core/enumerable/detect_spec.rb +0 -3
  213. data/core_spec/core/enumerable/find_spec.rb +0 -3
  214. data/core_spec/core/enumerable/first_spec.rb +0 -3
  215. data/core_spec/core/enumerable/shared/entries.rb +0 -7
  216. data/core_spec/core/enumerable/shared/find.rb +0 -49
  217. data/core_spec/core/enumerable/shared/take.rb +0 -31
  218. data/core_spec/core/enumerable/to_a_spec.rb +0 -7
  219. data/core_spec/core/hash/assoc_spec.rb +0 -29
  220. data/core_spec/core/object/is_a_spec.rb +0 -2
  221. data/core_spec/core/object/shared/kind_of.rb +0 -0
  222. data/core_spec/core/regexp/shared/match.rb +0 -11
  223. data/core_spec/language/fixtures/block.rb +0 -19
  224. data/core_spec/language/fixtures/break.rb +0 -39
  225. data/core_spec/language/fixtures/defined.rb +0 -9
  226. data/core_spec/language/fixtures/ensure.rb +0 -37
  227. data/core_spec/language/fixtures/next.rb +0 -46
  228. data/core_spec/language/fixtures/send.rb +0 -36
  229. data/core_spec/language/fixtures/super.rb +0 -43
  230. data/core_spec/language/regexp_spec.rb +0 -7
  231. data/core_spec/language/string_spec.rb +0 -4
  232. data/core_spec/language/super_spec.rb +0 -18
  233. data/core_spec/language/versions/hash_1.9.rb +0 -20
  234. data/core_spec/opal/opal/defined_spec.rb +0 -15
  235. data/core_spec/opal/opal/function_spec.rb +0 -11
  236. data/core_spec/opal/opal/native_spec.rb +0 -16
  237. data/core_spec/opal/opal/null_spec.rb +0 -10
  238. data/core_spec/opal/opal/number_spec.rb +0 -11
  239. data/core_spec/opal/opal/object_spec.rb +0 -16
  240. data/core_spec/opal/opal/string_spec.rb +0 -11
  241. data/core_spec/opal/opal/typeof_spec.rb +0 -9
  242. data/core_spec/opal/opal/undefined_spec.rb +0 -10
  243. data/core_spec/opal/true/case_compare_spec.rb +0 -12
  244. data/core_spec/opal/true/class_spec.rb +0 -10
  245. data/core_spec/release_runner.html +0 -17
  246. data/core_spec/runner.html +0 -16
  247. data/core_spec/spec_helper.rb +0 -23
  248. data/lib/opal/context.rb +0 -269
  249. data/lib/opal/dependency_builder.rb +0 -133
  250. data/lib/opal/environment.rb +0 -87
  251. data/lib/opal/parser/sexp.rb +0 -17
data/core/load_order CHANGED
@@ -1,10 +1,10 @@
1
1
  alpha
2
2
  module
3
- class
4
3
  kernel
5
4
  basic_object
6
5
  object
7
6
  top_self
7
+ class
8
8
  boolean
9
9
  nil_class
10
10
  enumerable
@@ -20,7 +20,4 @@ error
20
20
  regexp
21
21
  match_data
22
22
  time
23
- struct
24
- io
25
- file
26
- dir
23
+ struct
data/core/match_data.rb CHANGED
@@ -8,7 +8,7 @@ class MatchData
8
8
  }
9
9
 
10
10
  if (index >= length || index < 0) {
11
- return nil;
11
+ return null;
12
12
  }
13
13
 
14
14
  return this.$data[index];
data/core/module.rb CHANGED
@@ -1,10 +1,22 @@
1
1
  class Module
2
2
  def ===(object)
3
- object.kind_of? self
3
+ %x{
4
+ var search = object._klass;
5
+
6
+ while (search) {
7
+ if (search === this) {
8
+ return true;
9
+ }
10
+
11
+ search = search._super;
12
+ }
13
+
14
+ return false;
15
+ }
4
16
  end
5
17
 
6
18
  def alias_method(newname, oldname)
7
- `$opal.alias(this, newname, oldname)`
19
+ `opal.alias(this, newname, oldname)`
8
20
 
9
21
  self
10
22
  end
@@ -15,11 +27,16 @@ class Module
15
27
  result = [];
16
28
 
17
29
  while (parent) {
18
- if (!(parent.$flags & FL_SINGLETON)) {
30
+ if (parent._flags & FL_SINGLETON) {
31
+ continue;
32
+ }
33
+ else if (parent._flags & T_ICLASS)
34
+ result.push(parent._klass);
35
+ else {
19
36
  result.push(parent);
20
37
  }
21
38
 
22
- parent = parent.$s;
39
+ parent = parent._super;
23
40
  }
24
41
 
25
42
  return result;
@@ -46,8 +63,8 @@ class Module
46
63
 
47
64
  module.$included_in.push(klass);
48
65
 
49
- var donator = module.$allocator.prototype,
50
- prototype = klass.$proto,
66
+ var donator = module._alloc.prototype,
67
+ prototype = klass._proto,
51
68
  methods = [];
52
69
 
53
70
  for (var method in donator) {
@@ -74,12 +91,12 @@ class Module
74
91
  define_method(klass, mid_to_jsid(name), function() {
75
92
  var res = this[name];
76
93
 
77
- return res == null ? nil : res;
94
+ return res == null ? null : res;
78
95
  });
79
96
  }
80
97
 
81
98
  if (setter) {
82
- define_method(klass, mid_to_jsid(name + '='), function(block, val) {
99
+ define_method(klass, mid_to_jsid(name + '='), function(val) {
83
100
  return this[name] = val;
84
101
  });
85
102
  }
@@ -92,7 +109,7 @@ class Module
92
109
  define_attr(this, attrs[i], true, true);
93
110
  }
94
111
 
95
- return nil;
112
+ return null;
96
113
  }
97
114
  end
98
115
 
@@ -102,7 +119,7 @@ class Module
102
119
  define_attr(this, attrs[i], true, false);
103
120
  }
104
121
 
105
- return nil;
122
+ return null;
106
123
  }
107
124
  end
108
125
 
@@ -112,7 +129,7 @@ class Module
112
129
  define_attr(this, attrs[i], false, true);
113
130
  }
114
131
 
115
- return nil;
132
+ return null;
116
133
  }
117
134
  end
118
135
 
@@ -124,25 +141,28 @@ class Module
124
141
 
125
142
  def define_method(name, &body)
126
143
  %x{
127
- if (body === nil) {
128
- raise(RubyLocalJumpError, 'no block given');
144
+ if (body === null) {
145
+ throw RubyLocalJumpError.$new('no block given');
129
146
  }
130
147
 
131
- define_method(this, mid_to_jsid(name), body);
148
+ var jsid = mid_to_jsid(name);
149
+
150
+ body.o$jsid = jsid;
151
+ define_method(this, jsid, body);
132
152
 
133
- return nil;
153
+ return null;
134
154
  }
135
155
  end
136
156
 
137
157
  # FIXME: this could do with a better name
138
158
  def donate(methods)
139
159
  %x{
140
- var included_in = this.$included_in, includee, method, table = this.$proto, dest;
160
+ var included_in = this.$included_in, includee, method, table = this._proto, dest;
141
161
 
142
162
  if (included_in) {
143
163
  for (var i = 0, length = included_in.length; i < length; i++) {
144
164
  includee = included_in[i];
145
- dest = includee.$proto;
165
+ dest = includee._proto;
146
166
  for (var j = 0, jj = methods.length; j < jj; j++) {
147
167
  method = methods[j];
148
168
  // if (!dest[method]) {
@@ -161,9 +181,14 @@ class Module
161
181
 
162
182
  def include(*mods)
163
183
  %x{
184
+ console.log("including " + this._name);
164
185
  var i = mods.length - 1, mod;
165
186
  while (i >= 0) {
166
187
  #{mod = `mods[i]`};
188
+ console.log("include: " + mod._name);
189
+
190
+ define_iclass(this, mod);
191
+
167
192
  #{mod.append_features self};
168
193
  #{mod.included self};
169
194
 
@@ -184,8 +209,8 @@ class Module
184
209
 
185
210
  def module_eval(&block)
186
211
  %x{
187
- if (block === nil) {
188
- raise(RubyLocalJumpError, 'no block given');
212
+ if (block === null) {
213
+ throw RubyLocalJumpError.$new('no block given');
189
214
  }
190
215
 
191
216
  return block.call(this, null);
@@ -195,7 +220,7 @@ class Module
195
220
  alias class_eval module_eval
196
221
 
197
222
  def name
198
- `this.$name`
223
+ `this._name`
199
224
  end
200
225
 
201
226
  alias public_instance_methods instance_methods
data/core/nil_class.rb CHANGED
@@ -12,7 +12,7 @@ class NilClass
12
12
  end
13
13
 
14
14
  def ==(other)
15
- `this === other`
15
+ `other === nil`
16
16
  end
17
17
 
18
18
  def inspect
@@ -23,6 +23,10 @@ class NilClass
23
23
  true
24
24
  end
25
25
 
26
+ def singleton_class
27
+ NilClass
28
+ end
29
+
26
30
  def to_a
27
31
  []
28
32
  end
@@ -38,4 +42,4 @@ class NilClass
38
42
  end
39
43
  end
40
44
 
41
- NIL = nil
45
+ NIL = nil
data/core/numeric.rb CHANGED
@@ -1,4 +1,6 @@
1
1
  class Numeric
2
+ include Comparable
3
+
2
4
  def +(other)
3
5
  `this + other`
4
6
  end
@@ -72,13 +74,13 @@ class Numeric
72
74
  end
73
75
 
74
76
  def ==(other)
75
- `this.valueOf() === other.valueOf()`
77
+ `this == other`
76
78
  end
77
79
 
78
80
  def <=>(other)
79
81
  %x{
80
82
  if (typeof(other) !== 'number') {
81
- return nil;
83
+ return null;
82
84
  }
83
85
 
84
86
  return this < other ? -1 : (this > other ? 1 : 0);
@@ -93,13 +95,17 @@ class Numeric
93
95
  `Math.ceil(this)`
94
96
  end
95
97
 
98
+ def chr
99
+ `String.fromCharCode(this)`
100
+ end
101
+
96
102
  def downto(finish, &block)
97
103
  return enum_for :downto, finish unless block_given?
98
104
 
99
105
  %x{
100
106
  for (var i = this; i >= finish; i--) {
101
- if ($yield.call($context, i) === $breaker) {
102
- return $breaker.$v;
107
+ if (block.call(__context, i) === __breaker) {
108
+ return __breaker.$v;
103
109
  }
104
110
  }
105
111
 
@@ -132,13 +138,17 @@ class Numeric
132
138
  end
133
139
 
134
140
  def nonzero?
135
- `this.valueOf() === 0 ? nil : this`
141
+ `this.valueOf() === 0 ? null : this`
136
142
  end
137
143
 
138
144
  def odd?
139
145
  `this % 2 !== 0`
140
146
  end
141
147
 
148
+ def ord
149
+ self
150
+ end
151
+
142
152
  def pred
143
153
  `this - 1`
144
154
  end
@@ -150,8 +160,8 @@ class Numeric
150
160
 
151
161
  %x{
152
162
  for (var i = 0; i <= this; i++) {
153
- if ($yield.call($context, i) === $breaker) {
154
- return $breaker.$v;
163
+ if (block.call(__context, i) === __breaker) {
164
+ return __breaker.$v;
155
165
  }
156
166
  }
157
167
 
@@ -168,7 +178,7 @@ class Numeric
168
178
  end
169
179
 
170
180
  def to_s(base = 10)
171
- `this.toString(base)`
181
+ `this.toString()`
172
182
  end
173
183
 
174
184
  def upto(finish, &block)
@@ -176,8 +186,8 @@ class Numeric
176
186
 
177
187
  %x{
178
188
  for (var i = 0; i <= finish; i++) {
179
- if ($yield.call($context, i) === $breaker) {
180
- return $breaker.$v;
189
+ if (block.call(__context, i) === __breaker) {
190
+ return __breaker.$v;
181
191
  }
182
192
  }
183
193
 
data/core/proc.rb CHANGED
@@ -10,7 +10,7 @@ class Proc
10
10
  end
11
11
 
12
12
  def call(*args)
13
- `this.apply(this.$S, args)`
13
+ `this.apply(this._s, #{args})`
14
14
  end
15
15
 
16
16
  def to_proc
@@ -28,4 +28,4 @@ class Proc
28
28
  def arity
29
29
  `this.length - 1`
30
30
  end
31
- end
31
+ end
data/core/range.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  # Helper function on runtime for creating range literals
2
2
  %x{
3
- $opal.range = function(beg, end, exc) {
4
- var range = new RubyRange.$allocator();
3
+ Opal.range = function(beg, end, exc) {
4
+ var range = new RubyRange._alloc();
5
5
  range.begin = beg;
6
6
  range.end = end;
7
7
  range.exclude = exc;
@@ -11,33 +11,92 @@
11
11
  }
12
12
 
13
13
  class Range
14
+ include Enumerable
15
+
16
+ def initialize(min, max, exclude = false)
17
+ @begin = min
18
+ @end = max
19
+ @exclude = exclude
20
+ end
21
+
22
+ def ==(other)
23
+ return false unless Range === other
24
+
25
+ exclude_end? == other.exclude_end? && `this.begin` == other.begin && `this.end` == other.end
26
+ end
27
+
28
+ # FIXME: currently hardcoded to assume range holds numerics
29
+ def ===(obj)
30
+ `return obj >= this.begin && obj <= this.end`
31
+ end
32
+
14
33
  def begin
15
34
  `this.begin`
16
35
  end
17
36
 
37
+ def cover?(value)
38
+ `this.begin` <= value && value <= (exclude_end? ? `this.end` - 1 : `this.end`)
39
+ end
40
+
41
+ def each
42
+ return enum_for :each unless block_given?
43
+
44
+ current = min
45
+
46
+ while current != max
47
+ yield current
48
+
49
+ current = current.succ
50
+ end
51
+
52
+ yield current unless exclude_end?
53
+
54
+ self
55
+ end
56
+
18
57
  def end
19
58
  `this.end`
20
59
  end
21
60
 
22
- alias first begin
23
- alias min begin
61
+ def eql?(other)
62
+ return false unless Range === other
24
63
 
25
- alias last end
26
- alias max end
64
+ exclude_end? == other.exclude_end? && `this.begin`.eql?(other.begin) && `this.end`.eql?(other.end)
65
+ end
27
66
 
28
- def initialize(min, max, exclude = false)
29
- @begin = min
30
- @end = max
31
- @exclude = exclude
67
+ def exclude_end?
68
+ `this.exclude`
32
69
  end
33
70
 
34
71
  # FIXME: currently hardcoded to assume range holds numerics
35
- def ===(obj)
72
+ def include?(val)
36
73
  `return obj >= this.begin && obj <= this.end`
37
74
  end
38
75
 
39
- def exclude_end?
40
- `this.exclude`
76
+ def max
77
+ if block_given?
78
+ # I actually don't get what this should do
79
+ raise NotImplementedError
80
+ else
81
+ `this.end`
82
+ end
83
+ end
84
+
85
+ def min
86
+ if block_given?
87
+ # I actually don't get what this should do
88
+ raise NotImplementedError
89
+ else
90
+ `this.begin`
91
+ end
92
+ end
93
+
94
+ alias member? include?
95
+
96
+ def step(n = 1)
97
+ return enum_for :step, n unless block_given?
98
+
99
+ raise NotImplementedError
41
100
  end
42
101
 
43
102
  def to_s
data/core/regexp.rb CHANGED
@@ -20,8 +20,9 @@ class Regexp
20
20
  var result = this.exec(string);
21
21
 
22
22
  if (result) {
23
- var match = new RubyMatch.$allocator();
24
- match.$data = result;
23
+ var match = new RubyMatch._alloc();
24
+ match.$data = result;
25
+
25
26
  #{$~ = `match`};
26
27
  }
27
28
  else {
@@ -43,8 +44,9 @@ class Regexp
43
44
  var result = this.exec(pattern);
44
45
 
45
46
  if (result) {
46
- var match = new RubyMatch.$allocator();
47
+ var match = new RubyMatch._alloc();
47
48
  match.$data = result;
49
+
48
50
  return #{$~ = `match`};
49
51
  }
50
52
  else {