opal 0.3.15 → 0.3.16

Sign up to get free protection for your applications and to get access to all the features.
Files changed (236) hide show
  1. data/.gitignore +1 -1
  2. data/Gemfile +8 -2
  3. data/README.md +1 -1
  4. data/Rakefile +51 -57
  5. data/bin/opal +50 -2
  6. data/{runtime/corelib → core}/alpha.rb +6 -1
  7. data/{runtime/corelib → core}/array.rb +38 -42
  8. data/{runtime/corelib → core}/basic_object.rb +6 -17
  9. data/core/boolean.rb +40 -0
  10. data/core/class.rb +69 -0
  11. data/{runtime/corelib → core}/comparable.rb +0 -0
  12. data/core/debug.js +59 -0
  13. data/core/debug.rb +35 -0
  14. data/core/dir.rb +90 -0
  15. data/core/enumerable.rb +331 -0
  16. data/core/enumerator.rb +126 -0
  17. data/core/error.rb +40 -0
  18. data/{runtime/corelib → core}/file.rb +6 -3
  19. data/core/gemlib.rb +30 -0
  20. data/{runtime/corelib → core}/hash.rb +37 -35
  21. data/{runtime/corelib → core}/io.rb +0 -0
  22. data/{runtime/corelib → core}/kernel.rb +26 -21
  23. data/{runtime/corelib → core}/load_order +2 -5
  24. data/{runtime/corelib → core}/match_data.rb +2 -4
  25. data/core/module.rb +204 -0
  26. data/{runtime/corelib → core}/nil_class.rb +1 -7
  27. data/{runtime/corelib → core}/numeric.rb +9 -13
  28. data/core/object.rb +17 -0
  29. data/{runtime/corelib → core}/proc.rb +2 -13
  30. data/{runtime/corelib → core}/range.rb +19 -7
  31. data/{runtime/corelib → core}/rational.rb +0 -0
  32. data/{runtime/corelib → core}/regexp.rb +2 -6
  33. data/core/runtime.js +672 -0
  34. data/{runtime/corelib → core}/string.rb +25 -9
  35. data/{runtime/corelib → core}/struct.rb +0 -0
  36. data/core/time.rb +111 -0
  37. data/{runtime/corelib → core}/top_self.rb +0 -0
  38. data/{runtime/spec → core_spec}/README.md +0 -0
  39. data/{runtime/spec → core_spec}/core/array/allocate_spec.rb +0 -0
  40. data/{runtime/spec → core_spec}/core/array/append_spec.rb +0 -0
  41. data/{runtime/spec → core_spec}/core/array/assoc_spec.rb +0 -0
  42. data/{runtime/spec → core_spec}/core/array/at_spec.rb +0 -0
  43. data/{runtime/spec → core_spec}/core/array/clear_spec.rb +0 -0
  44. data/{runtime/spec → core_spec}/core/array/collect_spec.rb +0 -0
  45. data/{runtime/spec → core_spec}/core/array/compact_spec.rb +0 -0
  46. data/{runtime/spec → core_spec}/core/array/concat_spec.rb +0 -0
  47. data/{runtime/spec → core_spec}/core/array/constructor_spec.rb +0 -0
  48. data/{runtime/spec → core_spec}/core/array/count_spec.rb +0 -0
  49. data/{runtime/spec → core_spec}/core/array/delete_at_spec.rb +0 -0
  50. data/{runtime/spec → core_spec}/core/array/delete_if_spec.rb +0 -0
  51. data/{runtime/spec → core_spec}/core/array/delete_spec.rb +0 -0
  52. data/{runtime/spec → core_spec}/core/array/each_index_spec.rb +0 -0
  53. data/{runtime/spec → core_spec}/core/array/each_spec.rb +0 -0
  54. data/{runtime/spec → core_spec}/core/array/element_reference_spec.rb +0 -0
  55. data/{runtime/spec → core_spec}/core/array/element_set_spec.rb +0 -0
  56. data/{runtime/spec → core_spec}/core/array/empty_spec.rb +0 -0
  57. data/{runtime/spec → core_spec}/core/array/eql_spec.rb +0 -0
  58. data/{runtime/spec → core_spec}/core/array/equal_value_spec.rb +0 -0
  59. data/{runtime/spec → core_spec}/core/array/fetch_spec.rb +0 -0
  60. data/{runtime/spec → core_spec}/core/array/first_spec.rb +0 -0
  61. data/{runtime/spec → core_spec}/core/array/fixtures/classes.rb +0 -0
  62. data/{runtime/spec → core_spec}/core/array/flatten_spec.rb +0 -0
  63. data/{runtime/spec → core_spec}/core/array/include_spec.rb +0 -0
  64. data/{runtime/spec → core_spec}/core/array/insert_spec.rb +0 -0
  65. data/{runtime/spec → core_spec}/core/array/last_spec.rb +0 -0
  66. data/{runtime/spec → core_spec}/core/array/length_spec.rb +0 -0
  67. data/{runtime/spec → core_spec}/core/array/map_spec.rb +0 -0
  68. data/{runtime/spec → core_spec}/core/array/plus_spec.rb +0 -0
  69. data/{runtime/spec → core_spec}/core/array/pop_spec.rb +0 -0
  70. data/{runtime/spec → core_spec}/core/array/push_spec.rb +0 -0
  71. data/{runtime/spec → core_spec}/core/array/rassoc_spec.rb +0 -0
  72. data/{runtime/spec → core_spec}/core/array/reject_spec.rb +0 -0
  73. data/{runtime/spec → core_spec}/core/array/replace_spec.rb +0 -0
  74. data/{runtime/spec → core_spec}/core/array/reverse_each_spec.rb +0 -0
  75. data/{runtime/spec → core_spec}/core/array/reverse_spec.rb +0 -0
  76. data/{runtime/spec → core_spec}/core/array/shared/collect.rb +0 -0
  77. data/{runtime/spec → core_spec}/core/array/shared/eql.rb +0 -0
  78. data/{runtime/spec → core_spec}/core/array/shared/length.rb +0 -0
  79. data/{runtime/spec → core_spec}/core/array/shared/replace.rb +0 -0
  80. data/{runtime/spec → core_spec}/core/class/new_spec.rb +0 -0
  81. data/{runtime/spec → core_spec}/core/enumerable/all_spec.rb +0 -0
  82. data/{runtime/spec → core_spec}/core/enumerable/any_spec.rb +0 -0
  83. data/{runtime/spec → core_spec}/core/enumerable/collect_spec.rb +0 -0
  84. data/{runtime/spec → core_spec}/core/enumerable/count_spec.rb +0 -0
  85. data/{runtime/spec → core_spec}/core/enumerable/detect_spec.rb +0 -0
  86. data/{runtime/spec → core_spec}/core/enumerable/find_spec.rb +0 -0
  87. data/core_spec/core/enumerable/first_spec.rb +3 -0
  88. data/{runtime/spec → core_spec}/core/enumerable/fixtures/classes.rb +0 -0
  89. data/{runtime/spec → core_spec}/core/enumerable/shared/collect.rb +0 -0
  90. data/{runtime/spec → core_spec}/core/enumerable/shared/entries.rb +0 -0
  91. data/{runtime/spec → core_spec}/core/enumerable/shared/find.rb +0 -0
  92. data/core_spec/core/enumerable/shared/take.rb +31 -0
  93. data/{runtime/spec → core_spec}/core/enumerable/to_a_spec.rb +0 -0
  94. data/{runtime/spec → core_spec}/core/false/and_spec.rb +0 -0
  95. data/{runtime/spec → core_spec}/core/false/inspect_spec.rb +0 -0
  96. data/{runtime/spec → core_spec}/core/false/or_spec.rb +0 -0
  97. data/{runtime/spec → core_spec}/core/false/to_s_spec.rb +0 -0
  98. data/{runtime/spec → core_spec}/core/false/xor_spec.rb +0 -0
  99. data/{runtime/spec → core_spec}/core/hash/allocate_spec.rb +0 -0
  100. data/{runtime/spec → core_spec}/core/hash/assoc_spec.rb +0 -0
  101. data/{runtime/spec → core_spec}/core/hash/clear_spec.rb +0 -0
  102. data/{runtime/spec → core_spec}/core/hash/clone_spec.rb +0 -0
  103. data/{runtime/spec → core_spec}/core/hash/default_spec.rb +0 -0
  104. data/{runtime/spec → core_spec}/core/hash/delete_if_spec.rb +0 -0
  105. data/{runtime/spec → core_spec}/core/hash/element_reference_spec.rb +0 -0
  106. data/{runtime/spec → core_spec}/core/hash/element_set_spec.rb +0 -0
  107. data/{runtime/spec → core_spec}/core/hash/new_spec.rb +0 -0
  108. data/{runtime/spec → core_spec}/core/matchdata/to_a_spec.rb +0 -0
  109. data/{runtime/spec → core_spec}/core/nil/and_spec.rb +0 -0
  110. data/{runtime/spec → core_spec}/core/nil/inspect_spec.rb +0 -0
  111. data/{runtime/spec → core_spec}/core/nil/nil_spec.rb +0 -0
  112. data/{runtime/spec → core_spec}/core/nil/or_spec.rb +0 -0
  113. data/{runtime/spec → core_spec}/core/nil/to_a_spec.rb +0 -0
  114. data/{runtime/spec → core_spec}/core/nil/to_f_spec.rb +0 -0
  115. data/{runtime/spec → core_spec}/core/nil/to_i_spec.rb +0 -0
  116. data/{runtime/spec → core_spec}/core/nil/to_s_spec.rb +0 -0
  117. data/{runtime/spec → core_spec}/core/nil/xor_spec.rb +0 -0
  118. data/{runtime/spec → core_spec}/core/numeric/equal_value_spec.rb +0 -0
  119. data/{runtime/spec → core_spec}/core/object/is_a_spec.rb +0 -0
  120. data/{runtime/spec → core_spec}/core/object/shared/kind_of.rb +0 -0
  121. data/{runtime/spec → core_spec}/core/regexp/match_spec.rb +0 -0
  122. data/{runtime/spec → core_spec}/core/regexp/shared/match.rb +0 -0
  123. data/{runtime/spec → core_spec}/core/symbol/to_proc_spec.rb +0 -0
  124. data/{runtime/spec → core_spec}/core/true/and_spec.rb +0 -0
  125. data/{runtime/spec → core_spec}/core/true/inspect_spec.rb +0 -0
  126. data/{runtime/spec → core_spec}/core/true/or_spec.rb +0 -0
  127. data/{runtime/spec → core_spec}/core/true/to_s_spec.rb +0 -0
  128. data/{runtime/spec → core_spec}/core/true/xor_spec.rb +0 -0
  129. data/{runtime/spec → core_spec}/language/alias_spec.rb +0 -0
  130. data/{runtime/spec → core_spec}/language/and_spec.rb +0 -0
  131. data/{runtime/spec → core_spec}/language/array_spec.rb +0 -0
  132. data/{runtime/spec → core_spec}/language/block_spec.rb +0 -0
  133. data/{runtime/spec → core_spec}/language/break_spec.rb +0 -0
  134. data/{runtime/spec → core_spec}/language/case_spec.rb +0 -0
  135. data/{runtime/spec → core_spec}/language/defined_spec.rb +0 -0
  136. data/{runtime/spec → core_spec}/language/ensure_spec.rb +0 -0
  137. data/{runtime/spec → core_spec}/language/fixtures/block.rb +0 -0
  138. data/{runtime/spec → core_spec}/language/fixtures/break.rb +0 -0
  139. data/{runtime/spec → core_spec}/language/fixtures/defined.rb +0 -0
  140. data/{runtime/spec → core_spec}/language/fixtures/ensure.rb +0 -0
  141. data/{runtime/spec → core_spec}/language/fixtures/next.rb +0 -0
  142. data/{runtime/spec → core_spec}/language/fixtures/send.rb +0 -0
  143. data/{runtime/spec → core_spec}/language/fixtures/super.rb +0 -0
  144. data/{runtime/spec → core_spec}/language/hash_spec.rb +0 -0
  145. data/{runtime/spec → core_spec}/language/if_spec.rb +0 -0
  146. data/{runtime/spec → core_spec}/language/loop_spec.rb +0 -0
  147. data/{runtime/spec → core_spec}/language/next_spec.rb +0 -0
  148. data/{runtime/spec → core_spec}/language/or_spec.rb +0 -0
  149. data/{runtime/spec → core_spec}/language/predefined_spec.rb +0 -0
  150. data/{runtime/spec → core_spec}/language/regexp/interpolation_spec.rb +8 -0
  151. data/{runtime/spec → core_spec}/language/regexp_spec.rb +0 -0
  152. data/{runtime/spec → core_spec}/language/send_spec.rb +0 -0
  153. data/{runtime/spec → core_spec}/language/string_spec.rb +0 -0
  154. data/{runtime/spec → core_spec}/language/super_spec.rb +0 -0
  155. data/{runtime/spec → core_spec}/language/symbol_spec.rb +0 -0
  156. data/{runtime/spec → core_spec}/language/undef_spec.rb +0 -0
  157. data/{runtime/spec → core_spec}/language/unless_spec.rb +0 -0
  158. data/{runtime/spec → core_spec}/language/until_spec.rb +0 -0
  159. data/core_spec/language/variables_spec.rb +112 -0
  160. data/{runtime/spec → core_spec}/language/versions/hash_1.9.rb +0 -0
  161. data/{runtime/spec → core_spec}/language/while_spec.rb +0 -0
  162. data/{runtime/spec → core_spec}/opal/opal/defined_spec.rb +0 -0
  163. data/{runtime/spec → core_spec}/opal/opal/function_spec.rb +0 -0
  164. data/{runtime/spec → core_spec}/opal/opal/native_spec.rb +0 -0
  165. data/{runtime/spec → core_spec}/opal/opal/null_spec.rb +0 -0
  166. data/{runtime/spec → core_spec}/opal/opal/number_spec.rb +0 -0
  167. data/{runtime/spec → core_spec}/opal/opal/object_spec.rb +0 -0
  168. data/{runtime/spec → core_spec}/opal/opal/string_spec.rb +0 -0
  169. data/{runtime/spec → core_spec}/opal/opal/typeof_spec.rb +0 -0
  170. data/{runtime/spec → core_spec}/opal/opal/undefined_spec.rb +0 -0
  171. data/{runtime/spec → core_spec}/opal/true/case_compare_spec.rb +0 -0
  172. data/{runtime/spec → core_spec}/opal/true/class_spec.rb +0 -0
  173. data/{docs/spec_runner.html → core_spec/release_runner.html} +4 -3
  174. data/core_spec/runner.html +16 -0
  175. data/core_spec/spec_helper.rb +23 -0
  176. data/lib/opal.rb +85 -2
  177. data/lib/opal/builder.rb +129 -46
  178. data/lib/opal/context.rb +47 -26
  179. data/lib/opal/dependency_builder.rb +113 -14
  180. data/lib/opal/environment.rb +40 -45
  181. data/lib/opal/parser/grammar.rb +2296 -2254
  182. data/lib/opal/parser/grammar.y +27 -8
  183. data/lib/opal/parser/lexer.rb +12 -3
  184. data/lib/opal/parser/parser.rb +117 -30
  185. data/lib/opal/parser/scope.rb +2 -2
  186. data/lib/opal/version.rb +1 -1
  187. data/opal.gemspec +3 -8
  188. data/spec/grammar/masgn_spec.rb +37 -0
  189. metadata +177 -227
  190. data/index.html +0 -434
  191. data/lib/opal/command.rb +0 -73
  192. data/runtime/README.md +0 -25
  193. data/runtime/corelib/boolean.rb +0 -44
  194. data/runtime/corelib/class.rb +0 -43
  195. data/runtime/corelib/complex.rb +0 -2
  196. data/runtime/corelib/dir.rb +0 -29
  197. data/runtime/corelib/enumerable.rb +0 -316
  198. data/runtime/corelib/enumerator.rb +0 -80
  199. data/runtime/corelib/error.rb +0 -25
  200. data/runtime/corelib/module.rb +0 -171
  201. data/runtime/corelib/native.rb +0 -50
  202. data/runtime/corelib/object.rb +0 -21
  203. data/runtime/corelib/time.rb +0 -196
  204. data/runtime/gemlib/alpha.rb +0 -5
  205. data/runtime/gemlib/kernel.rb +0 -17
  206. data/runtime/gemlib/load_order +0 -2
  207. data/runtime/kernel/class.js +0 -256
  208. data/runtime/kernel/debug.js +0 -42
  209. data/runtime/kernel/init.js +0 -114
  210. data/runtime/kernel/load_order +0 -5
  211. data/runtime/kernel/loader.js +0 -151
  212. data/runtime/kernel/runtime.js +0 -414
  213. data/runtime/spec/language/variables_spec.rb +0 -28
  214. data/runtime/spec/library/stringscanner/scan_spec.rb +0 -36
  215. data/runtime/spec/opal/forwardable/def_instance_delegator_spec.rb +0 -49
  216. data/runtime/spec/spec_helper.rb +0 -25
  217. data/runtime/stdlib/base64.rb +0 -91
  218. data/runtime/stdlib/date.rb +0 -4
  219. data/runtime/stdlib/dev.rb +0 -171
  220. data/runtime/stdlib/forwardable.rb +0 -33
  221. data/runtime/stdlib/optparse.rb +0 -0
  222. data/runtime/stdlib/pp.rb +0 -6
  223. data/runtime/stdlib/racc/parser.rb +0 -159
  224. data/runtime/stdlib/rbconfig.rb +0 -0
  225. data/runtime/stdlib/si.rb +0 -17
  226. data/runtime/stdlib/strscan.rb +0 -53
  227. data/runtime/stdlib/uri.rb +0 -111
  228. data/runtime/stdlib/uri/common.rb +0 -1014
  229. data/runtime/stdlib/uri/ftp.rb +0 -261
  230. data/runtime/stdlib/uri/generic.rb +0 -1599
  231. data/runtime/stdlib/uri/http.rb +0 -106
  232. data/runtime/stdlib/uri/https.rb +0 -22
  233. data/runtime/stdlib/uri/ldap.rb +0 -260
  234. data/runtime/stdlib/uri/ldaps.rb +0 -20
  235. data/runtime/stdlib/uri/mailto.rb +0 -280
  236. data/spec/builder/output_path_spec.rb +0 -50
@@ -83,9 +83,13 @@ stmts:
83
83
  }
84
84
 
85
85
  stmt:
86
- ALIAS fitem fitem
86
+ ALIAS fitem
87
87
  {
88
- result = s(:alias, val[1], val[2])
88
+ @lex_state = :expr_fname
89
+ }
90
+ fitem
91
+ {
92
+ result = s(:alias, val[1], val[3])
89
93
  }
90
94
  | ALIAS GVAR GVAR
91
95
  {
@@ -125,7 +129,7 @@ stmt:
125
129
  }
126
130
  | mlhs '=' command_call
127
131
  {
128
- result = MlhsAssignNode.new val[1], val[0], val[2]
132
+ result = s(:masgn, val[0], s(:to_ary, val[2]))
129
133
  }
130
134
  | var_lhs OP_ASGN command_call
131
135
  {
@@ -148,11 +152,11 @@ stmt:
148
152
  }
149
153
  | mlhs '=' arg_value
150
154
  {
151
- result = MlhsAssignNode.new val[1], val[0], val[2]
155
+ result = s(:masgn, val[0], s(:to_ary, val[2]))
152
156
  }
153
157
  | mlhs '=' mrhs
154
158
  {
155
- result = MlhsAssignNode.new val[1], val[0], val[2]
159
+ result = s(:masgn, val[0], val[2])
156
160
  }
157
161
  | expr
158
162
 
@@ -260,16 +264,28 @@ mlhs_entry:
260
264
  mlhs_basic:
261
265
  mlhs_head
262
266
  {
263
- result = [val[0]]
267
+ result = val[0]
264
268
  }
265
269
  | mlhs_head mlhs_item
266
270
  {
267
- result = [val[0] << val[1]]
271
+ result = val[0] << val[1]
268
272
  }
269
273
  | mlhs_head SPLAT mlhs_node
274
+ {
275
+ result = val[0] << s(:splat, val[2])
276
+ }
270
277
  | mlhs_head SPLAT
278
+ {
279
+ result = val[0] << s(:splat)
280
+ }
271
281
  | SPLAT mlhs_node
282
+ {
283
+ result = s(:array, s(:splat, val[1]))
284
+ }
272
285
  | SPLAT
286
+ {
287
+ result = s(:array, s(:splat))
288
+ }
273
289
 
274
290
  mlhs_item:
275
291
  mlhs_node
@@ -284,7 +300,7 @@ mlhs_item:
284
300
  mlhs_head:
285
301
  mlhs_item ','
286
302
  {
287
- result = [val[0]]
303
+ result = s(:array, val[0])
288
304
  }
289
305
  | mlhs_head mlhs_item ','
290
306
  {
@@ -293,6 +309,9 @@ mlhs_head:
293
309
 
294
310
  mlhs_node:
295
311
  variable
312
+ {
313
+ result = new_assignable val[0]
314
+ }
296
315
  | primary_value '[@' aref_args ']'
297
316
  | primary_value '.' IDENTIFIER
298
317
  | primary_value '::' IDENTIFIER
@@ -539,7 +539,7 @@ module Opal
539
539
  #puts "matced beg balance!"
540
540
  str_buffer << scanner.matched
541
541
  str_parse[:nesting] += 1
542
- elsif scanner.check(/#[$@]/)
542
+ elsif scanner.check(/#[@$]/)
543
543
  scanner.scan(/#/)
544
544
  if interpolate
545
545
  return :STRING_DVAR, scanner.matched
@@ -562,6 +562,7 @@ module Opal
562
562
 
563
563
  add_string_content str_buffer, str_parse
564
564
  complete_str = str_buffer.join ''
565
+ @line += complete_str.count("\n")
565
566
  return :STRING_CONTENT, complete_str
566
567
  end
567
568
 
@@ -600,7 +601,7 @@ module Opal
600
601
  scanner.pos -= 1
601
602
  break
602
603
 
603
- elsif interpolate && scanner.check(/#(?=[\@\{])/)
604
+ elsif interpolate && scanner.check(/#(?=[\$\@\{])/)
604
605
  break
605
606
 
606
607
  #elsif scanner.scan(/\\\\/)
@@ -925,6 +926,14 @@ module Opal
925
926
  @lex_state = :expr_end
926
927
  return '<<', '<<'
927
928
  elsif ![:expr_end, :expr_dot, :expr_endarg, :expr_class].include?(@lex_state) && space_seen
929
+ if scanner.scan(/(-?)(\w+)/)
930
+ heredoc = scanner[2]
931
+ # for now just scrap rest of line + skip down one line for
932
+ # string content
933
+ scanner.scan(/.*\n/)
934
+ @string_parse = { :beg => heredoc, :end => heredoc, :interpolate => true }
935
+ return :STRING_BEG, heredoc
936
+ end
928
937
  @lex_state = :expr_beg
929
938
  return '<<', '<<'
930
939
  end
@@ -1292,7 +1301,7 @@ module Opal
1292
1301
  return :YIELD, matched
1293
1302
 
1294
1303
  when 'alias'
1295
- @lex_state = :expr_arg
1304
+ @lex_state = :expr_fname
1296
1305
  return :ALIAS, matched
1297
1306
  end
1298
1307
 
@@ -85,17 +85,23 @@ module Opal
85
85
  def parse(source, file = '(file)')
86
86
  @file = file
87
87
  @helpers = {
88
- :breaker => true, :no_proc => true, :klass => true, :defn => true, :defs => true, :const_get => true,
88
+ :breaker => true, :no_proc => true, :klass => true, :const_get => true,
89
89
  :slice => true
90
90
  }
91
91
 
92
92
  parser = Grammar.new
93
93
  reset
94
94
 
95
+ # Debug mode always uses FILE for sending methods which have stack traces
96
+ @uses_file = true if @debug
97
+
98
+ # $send is needed in debug mode
99
+ @helpers[:send] = true if @debug
100
+
95
101
  begin
96
102
  top parser.parse(source, file)
97
103
  rescue Exception => e
98
- raise OpalParseError.new("#{e.message}\nfrom parsing #{file}:#{parser.line}")
104
+ raise OpalParseError.new("#{e.message} in #{file}:#{parser.line}")
99
105
  end
100
106
  end
101
107
 
@@ -112,7 +118,7 @@ module Opal
112
118
  end
113
119
 
114
120
  def mid_to_jsid(mid)
115
- 'm$' + if name = METHOD_NAMES[mid.to_sym]
121
+ '$' + if name = METHOD_NAMES[mid.to_sym]
116
122
  name + '$'
117
123
  else
118
124
  mid.sub('!', '$b').sub('?', '$p').sub('=', '$e')
@@ -166,7 +172,7 @@ module Opal
166
172
 
167
173
  @scope = parent
168
174
  end
169
-
175
+
170
176
  def indent(&block)
171
177
  indent = @indent
172
178
  @indent += INDENT
@@ -315,7 +321,7 @@ module Opal
315
321
 
316
322
  res = "(#{a} = #{l}, #{b} = #{r}, typeof(#{a}) === "
317
323
  res += "'number' ? #{a} #{meth} #{b} : #{a}.#{mid}"
318
- res += "(null, #{b}))"
324
+ res += "(#{b}))"
319
325
 
320
326
  @scope.queue_temp a
321
327
  @scope.queue_temp b
@@ -464,9 +470,13 @@ module Opal
464
470
  args ||= s(:masgn, s(:array))
465
471
  args = args.first == :lasgn ? s(:array, args) : args[1]
466
472
 
473
+ if args.last[0] == :block_pass
474
+ args.pop
475
+ end
476
+
467
477
  if args.last[0] == :splat
468
- splat = args[-1][1][1]
469
- args[-1] = s(:lasgn, splat)
478
+ splat = args.last[1][1]
479
+ args.pop
470
480
  len = args.length
471
481
  end
472
482
 
@@ -479,8 +489,12 @@ module Opal
479
489
  end
480
490
 
481
491
  params = js_block_args(args[1..-1])
482
- params.unshift '_$'
483
- code += "#{splat} = $slice.call(arguments, #{len - 1});" if splat
492
+
493
+ if splat
494
+ params << splat
495
+ code += "#{splat} = $slice.call(arguments, #{len - 1});"
496
+ end
497
+
484
498
  code += process body, :statement
485
499
 
486
500
  code = @scope.to_vars + code
@@ -532,29 +546,55 @@ module Opal
532
546
 
533
547
  if Sexp === arglist.last and arglist.last.first == :block_pass
534
548
  tmpproc = @scope.new_temp
535
- arglist.insert 1, s(:js_tmp, process(arglist.pop, :expression))
549
+ tmprecv = @scope.new_temp
550
+ block = process arglist.pop, :expression
536
551
  elsif iter
537
552
  tmpproc = @scope.new_temp
538
- arglist.insert 1, s(:js_tmp, "(#{tmpproc}=#{iter},#{tmpproc}.$S=this,#{tmpproc})")
539
- else
540
- arglist.insert 1, s(:js_tmp, 'null') unless arglist.length == 1
553
+ tmprecv = @scope.new_temp
554
+ block = iter
555
+ elsif splat or @debug
556
+ tmprecv = @scope.new_temp
541
557
  end
542
558
 
543
- tmprecv = @scope.new_temp if splat or @debug
544
559
  args = ""
545
560
 
546
561
  recv_code = recv.nil? ? 'this' : process(recv, :receiver)
547
562
 
563
+ if @debug
564
+ if iter
565
+ debugblock = "(#{tmpproc}=#{block},#{tmpproc}.$S=this, #{tmpproc})"
566
+ elsif block
567
+ debugblock = block
568
+ else
569
+ debugblock = 'null'
570
+ end
571
+ arglist.insert 1, s(:js_tmp, recv_code), s(:js_tmp, debugblock), s(:js_tmp, mid.inspect)
572
+ end
573
+
548
574
  args = process arglist, :expression
549
575
 
550
576
  @scope.queue_temp tmprecv if tmprecv
551
577
  @scope.queue_temp tmpproc if tmpproc
552
578
 
553
579
  if @debug
580
+ splat ? "$send.apply(null, #{args})" : "$send(#{args})"
581
+ elsif @method_missing
554
582
  pre = "((#{tmprecv}=#{recv_code}).#{mid} || $opal.mm('#{mid}'))."
555
583
  splat ? "#{pre}apply(#{tmprecv}, #{args})" : "#{pre}call(#{tmprecv}#{args == '' ? '' : ", #{args}"})"
556
584
  else
557
- splat ? "(#{tmprecv}=#{recv_code}).#{mid}.apply(#{tmprecv}, #{args})" : "#{recv_code}.#{mid}(#{args})"
585
+ if block
586
+ if iter
587
+ call = "(#{tmpproc}=(#{tmprecv}=#{recv_code}).#{mid}, (#{tmpproc}.$P = #{block}).$S = this, #{tmpproc})"
588
+ else # block_pass
589
+ call = "(#{tmpproc}=(#{tmprecv}=#{recv_code}).#{mid}, #{tmpproc}.$P = #{block}, #{tmpproc})"
590
+ end
591
+
592
+ args = ", #{args}" unless args.empty?
593
+ splat ? "#{call}.apply(#{tmprecv}#{args})" : "#{call}.call(#{tmprecv}#{args})"
594
+
595
+ else
596
+ splat ? "(#{tmprecv}=#{recv_code}).#{mid}.apply(#{tmprecv}, #{args})" : "#{recv_code}.#{mid}(#{args})"
597
+ end
558
598
  end
559
599
  end
560
600
 
@@ -704,16 +744,16 @@ module Opal
704
744
  mid = mid_to_jsid mid.to_s
705
745
 
706
746
  if recvr
707
- type = '$defs'
747
+ type = '$opal.defs'
708
748
  recv = process(recvr, :expression)
709
749
  else
710
- type = '$defn'
750
+ type = '$opal.defn'
711
751
  recv = 'this'
712
752
  end
713
753
 
714
754
  code = ''
715
755
  params = nil
716
- scope_name = @scope.name
756
+ scope_name = nil
717
757
 
718
758
  # opt args if last arg is sexp
719
759
  opt = args.pop if Sexp === args.last
@@ -734,11 +774,10 @@ module Opal
734
774
  end
735
775
  end
736
776
 
737
- aritycode = arity_check(args, opt, splat) if @debug
777
+ aritycode = arity_check(args, opt, splat) if @debug && false
738
778
 
739
779
  indent do
740
780
  in_scope(:def) do
741
- args.insert 1, '$yield'
742
781
  params = process args, :expression
743
782
 
744
783
  if block_name
@@ -747,18 +786,26 @@ module Opal
747
786
  end
748
787
 
749
788
  opt[1..-1].each do |o|
789
+ next if o[2][2] == :undefined
750
790
  id = process s(:lvar, o[1]), :expression
751
791
  code += "if (#{id} === undefined) { #{process o, :expression}; }"
752
792
  end if opt
753
793
 
754
- code += "#{splat} = $slice.call(arguments, #{len + 1});" if splat
794
+ code += "#{splat} = $slice.call(arguments, #{len});" if splat
755
795
  code += process(stmts, :statement)
756
796
 
757
797
  if @scope.uses_block?
758
- blk = "$yield || ($yield = $no_proc);"
759
- blk = "var #{block_name} = $yield || ($yield = $no_proc, nil);" if block_name
760
- blk += "var $context = $yield.$S;"
761
- blk = "var $block_given = ($yield != null); #{blk}"
798
+ scope_name = @scope.name = unique_temp
799
+ blk = "var $yield = #{scope_name}.$P;"
800
+ blk += "if ($yield) { var $context = $yield.$S"
801
+ blk += ", $block_given = true"
802
+ blk += ", #{block_name} = $yield" if block_name
803
+ blk += "; #{scope_name}.$P = null; }"
804
+
805
+ blk += "else { $yield = $no_proc"
806
+ blk += ", #{block_name} = nil" if block_name
807
+ blk += "; }"
808
+
762
809
  code = blk + code
763
810
  end
764
811
 
@@ -774,14 +821,16 @@ module Opal
774
821
 
775
822
  defcode = "#{"#{scope_name} = " if scope_name}function(#{params}) {#{code}#{fix_line end_line}}"
776
823
 
777
- if recvr
824
+ if @debug
825
+ "#{type}(#{recv}, '#{mid}', #{defcode}, FILE, #{line})"
826
+ elsif recvr
778
827
  "#{type}(#{recv}, '#{mid}', #{defcode})"
779
828
  elsif @scope.type == :class
780
829
  @scope.methods << mid if @scope.donates_methods
781
- "$proto.#{mid} = #{defcode}"
830
+ "def.#{mid} = #{defcode}"
782
831
  elsif @scope.type == :module
783
832
  @scope.methods << mid
784
- "$proto.#{mid} = #{defcode}"
833
+ "def.#{mid} = #{defcode}"
785
834
  else
786
835
  "#{type}(#{recv}, '#{mid}', #{defcode})"
787
836
  end
@@ -865,7 +914,7 @@ module Opal
865
914
 
866
915
  # s(:hash, key1, val1, key2, val2...)
867
916
  def hash(sexp, level)
868
- "(new $opal.hash(#{sexp.map { |p| process p, :expression }.join ', '}))"
917
+ "$opal.hash(#{sexp.map { |p| process p, :expression }.join ', '})"
869
918
  end
870
919
 
871
920
  # s(:while, exp, block, true)
@@ -951,6 +1000,45 @@ module Opal
951
1000
  "$opal.alias(this, #{process new, :expression}, #{process old, :expression})"
952
1001
  end
953
1002
 
1003
+ def masgn(sexp, level)
1004
+ lhs = sexp[0]
1005
+ rhs = sexp[1]
1006
+ tmp = @scope.new_temp
1007
+ len = 0
1008
+
1009
+ # remote :array part
1010
+ lhs.shift
1011
+ if rhs[0] == :array
1012
+ len = rhs.length - 1 # we are guaranteed an array of this length
1013
+ code = ["#{tmp} = #{process rhs, :expression}"]
1014
+ elsif rhs[0] == :to_ary
1015
+ code = ["#{tmp} = [#{process rhs[1], :expression}]"]
1016
+ elsif rhs[0] == :splat
1017
+ code = ["#{tmp} = #{process rhs[1], :expression}"]
1018
+ else
1019
+ raise "Unsupported mlhs type"
1020
+ end
1021
+
1022
+ lhs.each_with_index do |l, idx|
1023
+
1024
+ if l.first == :splat
1025
+ s = l[1]
1026
+ s << s(:js_tmp, "$slice.call(#{tmp}, #{idx})")
1027
+ code << process(s, :expression)
1028
+ else
1029
+ if idx >= len
1030
+ l << s(:js_tmp, "(#{tmp}[#{idx}] === undefined ? nil : #{tmp}[#{idx}])")
1031
+ else
1032
+ l << s(:js_tmp, "#{tmp}[#{idx}]")
1033
+ end
1034
+ code << process(l, :expression)
1035
+ end
1036
+ end
1037
+
1038
+ @scope.queue_temp tmp
1039
+ code.join ', '
1040
+ end
1041
+
954
1042
  def svalue(sexp, level)
955
1043
  process sexp.shift, level
956
1044
  end
@@ -1180,7 +1268,6 @@ module Opal
1180
1268
  def yield(sexp, level)
1181
1269
  @scope.uses_block!
1182
1270
  splat = sexp.any? { |s| s.first == :splat }
1183
- sexp.unshift s(:js_tmp, 'null')
1184
1271
  sexp.unshift s(:js_tmp, '$context') unless splat
1185
1272
  args = arglist(sexp, level)
1186
1273
 
@@ -40,10 +40,10 @@ module Opal; class Parser
40
40
 
41
41
  if @type == :class
42
42
  vars << '$const = this.$const'
43
- vars << '$proto = this.$proto'
43
+ vars << 'def = this.$proto'
44
44
  elsif @type == :module
45
45
  vars << '$const = this.$const'
46
- vars << '$proto = this.$proto'
46
+ vars << 'def = this.$proto'
47
47
  elsif @type == :sclass
48
48
  vars << '$const = this.$const'
49
49
  end
data/lib/opal/version.rb CHANGED
@@ -1,4 +1,4 @@
1
1
  module Opal
2
- VERSION = "0.3.15"
2
+ VERSION = "0.3.16"
3
3
  end
4
4
 
data/opal.gemspec CHANGED
@@ -1,14 +1,12 @@
1
- # coding: utf-8
2
- $:.push File.expand_path('../lib', __FILE__)
3
- require 'opal'
4
- require 'opal/version'
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/opal/version', __FILE__)
5
3
 
6
4
  Gem::Specification.new do |s|
7
5
  s.name = 'opal'
8
6
  s.version = Opal::VERSION
9
7
  s.author = 'Adam Beynon'
10
8
  s.email = 'adam@adambeynon.com'
11
- s.homepage = 'http://opalscript.org'
9
+ s.homepage = 'http://opalrb.org'
12
10
  s.summary = 'Ruby runtime and core library for javascript'
13
11
  s.description = 'Ruby runtime and core library for javascript.'
14
12
 
@@ -17,7 +15,4 @@ Gem::Specification.new do |s|
17
15
  s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
18
16
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
17
  s.require_paths = ['lib']
20
-
21
- s.add_development_dependency 'racc'
22
- s.add_development_dependency 'therubyracer'
23
18
  end