opal 0.3.15 → 0.3.16
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.
- data/.gitignore +1 -1
- data/Gemfile +8 -2
- data/README.md +1 -1
- data/Rakefile +51 -57
- data/bin/opal +50 -2
- data/{runtime/corelib → core}/alpha.rb +6 -1
- data/{runtime/corelib → core}/array.rb +38 -42
- data/{runtime/corelib → core}/basic_object.rb +6 -17
- data/core/boolean.rb +40 -0
- data/core/class.rb +69 -0
- data/{runtime/corelib → core}/comparable.rb +0 -0
- data/core/debug.js +59 -0
- data/core/debug.rb +35 -0
- data/core/dir.rb +90 -0
- data/core/enumerable.rb +331 -0
- data/core/enumerator.rb +126 -0
- data/core/error.rb +40 -0
- data/{runtime/corelib → core}/file.rb +6 -3
- data/core/gemlib.rb +30 -0
- data/{runtime/corelib → core}/hash.rb +37 -35
- data/{runtime/corelib → core}/io.rb +0 -0
- data/{runtime/corelib → core}/kernel.rb +26 -21
- data/{runtime/corelib → core}/load_order +2 -5
- data/{runtime/corelib → core}/match_data.rb +2 -4
- data/core/module.rb +204 -0
- data/{runtime/corelib → core}/nil_class.rb +1 -7
- data/{runtime/corelib → core}/numeric.rb +9 -13
- data/core/object.rb +17 -0
- data/{runtime/corelib → core}/proc.rb +2 -13
- data/{runtime/corelib → core}/range.rb +19 -7
- data/{runtime/corelib → core}/rational.rb +0 -0
- data/{runtime/corelib → core}/regexp.rb +2 -6
- data/core/runtime.js +672 -0
- data/{runtime/corelib → core}/string.rb +25 -9
- data/{runtime/corelib → core}/struct.rb +0 -0
- data/core/time.rb +111 -0
- data/{runtime/corelib → core}/top_self.rb +0 -0
- data/{runtime/spec → core_spec}/README.md +0 -0
- data/{runtime/spec → core_spec}/core/array/allocate_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/array/append_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/array/assoc_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/array/at_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/array/clear_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/array/collect_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/array/compact_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/array/concat_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/array/constructor_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/array/count_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/array/delete_at_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/array/delete_if_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/array/delete_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/array/each_index_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/array/each_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/array/element_reference_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/array/element_set_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/array/empty_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/array/eql_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/array/equal_value_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/array/fetch_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/array/first_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/array/fixtures/classes.rb +0 -0
- data/{runtime/spec → core_spec}/core/array/flatten_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/array/include_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/array/insert_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/array/last_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/array/length_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/array/map_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/array/plus_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/array/pop_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/array/push_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/array/rassoc_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/array/reject_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/array/replace_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/array/reverse_each_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/array/reverse_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/array/shared/collect.rb +0 -0
- data/{runtime/spec → core_spec}/core/array/shared/eql.rb +0 -0
- data/{runtime/spec → core_spec}/core/array/shared/length.rb +0 -0
- data/{runtime/spec → core_spec}/core/array/shared/replace.rb +0 -0
- data/{runtime/spec → core_spec}/core/class/new_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/enumerable/all_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/enumerable/any_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/enumerable/collect_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/enumerable/count_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/enumerable/detect_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/enumerable/find_spec.rb +0 -0
- data/core_spec/core/enumerable/first_spec.rb +3 -0
- data/{runtime/spec → core_spec}/core/enumerable/fixtures/classes.rb +0 -0
- data/{runtime/spec → core_spec}/core/enumerable/shared/collect.rb +0 -0
- data/{runtime/spec → core_spec}/core/enumerable/shared/entries.rb +0 -0
- data/{runtime/spec → core_spec}/core/enumerable/shared/find.rb +0 -0
- data/core_spec/core/enumerable/shared/take.rb +31 -0
- data/{runtime/spec → core_spec}/core/enumerable/to_a_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/false/and_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/false/inspect_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/false/or_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/false/to_s_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/false/xor_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/hash/allocate_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/hash/assoc_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/hash/clear_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/hash/clone_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/hash/default_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/hash/delete_if_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/hash/element_reference_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/hash/element_set_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/hash/new_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/matchdata/to_a_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/nil/and_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/nil/inspect_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/nil/nil_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/nil/or_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/nil/to_a_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/nil/to_f_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/nil/to_i_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/nil/to_s_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/nil/xor_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/numeric/equal_value_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/object/is_a_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/object/shared/kind_of.rb +0 -0
- data/{runtime/spec → core_spec}/core/regexp/match_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/regexp/shared/match.rb +0 -0
- data/{runtime/spec → core_spec}/core/symbol/to_proc_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/true/and_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/true/inspect_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/true/or_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/true/to_s_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/true/xor_spec.rb +0 -0
- data/{runtime/spec → core_spec}/language/alias_spec.rb +0 -0
- data/{runtime/spec → core_spec}/language/and_spec.rb +0 -0
- data/{runtime/spec → core_spec}/language/array_spec.rb +0 -0
- data/{runtime/spec → core_spec}/language/block_spec.rb +0 -0
- data/{runtime/spec → core_spec}/language/break_spec.rb +0 -0
- data/{runtime/spec → core_spec}/language/case_spec.rb +0 -0
- data/{runtime/spec → core_spec}/language/defined_spec.rb +0 -0
- data/{runtime/spec → core_spec}/language/ensure_spec.rb +0 -0
- data/{runtime/spec → core_spec}/language/fixtures/block.rb +0 -0
- data/{runtime/spec → core_spec}/language/fixtures/break.rb +0 -0
- data/{runtime/spec → core_spec}/language/fixtures/defined.rb +0 -0
- data/{runtime/spec → core_spec}/language/fixtures/ensure.rb +0 -0
- data/{runtime/spec → core_spec}/language/fixtures/next.rb +0 -0
- data/{runtime/spec → core_spec}/language/fixtures/send.rb +0 -0
- data/{runtime/spec → core_spec}/language/fixtures/super.rb +0 -0
- data/{runtime/spec → core_spec}/language/hash_spec.rb +0 -0
- data/{runtime/spec → core_spec}/language/if_spec.rb +0 -0
- data/{runtime/spec → core_spec}/language/loop_spec.rb +0 -0
- data/{runtime/spec → core_spec}/language/next_spec.rb +0 -0
- data/{runtime/spec → core_spec}/language/or_spec.rb +0 -0
- data/{runtime/spec → core_spec}/language/predefined_spec.rb +0 -0
- data/{runtime/spec → core_spec}/language/regexp/interpolation_spec.rb +8 -0
- data/{runtime/spec → core_spec}/language/regexp_spec.rb +0 -0
- data/{runtime/spec → core_spec}/language/send_spec.rb +0 -0
- data/{runtime/spec → core_spec}/language/string_spec.rb +0 -0
- data/{runtime/spec → core_spec}/language/super_spec.rb +0 -0
- data/{runtime/spec → core_spec}/language/symbol_spec.rb +0 -0
- data/{runtime/spec → core_spec}/language/undef_spec.rb +0 -0
- data/{runtime/spec → core_spec}/language/unless_spec.rb +0 -0
- data/{runtime/spec → core_spec}/language/until_spec.rb +0 -0
- data/core_spec/language/variables_spec.rb +112 -0
- data/{runtime/spec → core_spec}/language/versions/hash_1.9.rb +0 -0
- data/{runtime/spec → core_spec}/language/while_spec.rb +0 -0
- data/{runtime/spec → core_spec}/opal/opal/defined_spec.rb +0 -0
- data/{runtime/spec → core_spec}/opal/opal/function_spec.rb +0 -0
- data/{runtime/spec → core_spec}/opal/opal/native_spec.rb +0 -0
- data/{runtime/spec → core_spec}/opal/opal/null_spec.rb +0 -0
- data/{runtime/spec → core_spec}/opal/opal/number_spec.rb +0 -0
- data/{runtime/spec → core_spec}/opal/opal/object_spec.rb +0 -0
- data/{runtime/spec → core_spec}/opal/opal/string_spec.rb +0 -0
- data/{runtime/spec → core_spec}/opal/opal/typeof_spec.rb +0 -0
- data/{runtime/spec → core_spec}/opal/opal/undefined_spec.rb +0 -0
- data/{runtime/spec → core_spec}/opal/true/case_compare_spec.rb +0 -0
- data/{runtime/spec → core_spec}/opal/true/class_spec.rb +0 -0
- data/{docs/spec_runner.html → core_spec/release_runner.html} +4 -3
- data/core_spec/runner.html +16 -0
- data/core_spec/spec_helper.rb +23 -0
- data/lib/opal.rb +85 -2
- data/lib/opal/builder.rb +129 -46
- data/lib/opal/context.rb +47 -26
- data/lib/opal/dependency_builder.rb +113 -14
- data/lib/opal/environment.rb +40 -45
- data/lib/opal/parser/grammar.rb +2296 -2254
- data/lib/opal/parser/grammar.y +27 -8
- data/lib/opal/parser/lexer.rb +12 -3
- data/lib/opal/parser/parser.rb +117 -30
- data/lib/opal/parser/scope.rb +2 -2
- data/lib/opal/version.rb +1 -1
- data/opal.gemspec +3 -8
- data/spec/grammar/masgn_spec.rb +37 -0
- metadata +177 -227
- data/index.html +0 -434
- data/lib/opal/command.rb +0 -73
- data/runtime/README.md +0 -25
- data/runtime/corelib/boolean.rb +0 -44
- data/runtime/corelib/class.rb +0 -43
- data/runtime/corelib/complex.rb +0 -2
- data/runtime/corelib/dir.rb +0 -29
- data/runtime/corelib/enumerable.rb +0 -316
- data/runtime/corelib/enumerator.rb +0 -80
- data/runtime/corelib/error.rb +0 -25
- data/runtime/corelib/module.rb +0 -171
- data/runtime/corelib/native.rb +0 -50
- data/runtime/corelib/object.rb +0 -21
- data/runtime/corelib/time.rb +0 -196
- data/runtime/gemlib/alpha.rb +0 -5
- data/runtime/gemlib/kernel.rb +0 -17
- data/runtime/gemlib/load_order +0 -2
- data/runtime/kernel/class.js +0 -256
- data/runtime/kernel/debug.js +0 -42
- data/runtime/kernel/init.js +0 -114
- data/runtime/kernel/load_order +0 -5
- data/runtime/kernel/loader.js +0 -151
- data/runtime/kernel/runtime.js +0 -414
- data/runtime/spec/language/variables_spec.rb +0 -28
- data/runtime/spec/library/stringscanner/scan_spec.rb +0 -36
- data/runtime/spec/opal/forwardable/def_instance_delegator_spec.rb +0 -49
- data/runtime/spec/spec_helper.rb +0 -25
- data/runtime/stdlib/base64.rb +0 -91
- data/runtime/stdlib/date.rb +0 -4
- data/runtime/stdlib/dev.rb +0 -171
- data/runtime/stdlib/forwardable.rb +0 -33
- data/runtime/stdlib/optparse.rb +0 -0
- data/runtime/stdlib/pp.rb +0 -6
- data/runtime/stdlib/racc/parser.rb +0 -159
- data/runtime/stdlib/rbconfig.rb +0 -0
- data/runtime/stdlib/si.rb +0 -17
- data/runtime/stdlib/strscan.rb +0 -53
- data/runtime/stdlib/uri.rb +0 -111
- data/runtime/stdlib/uri/common.rb +0 -1014
- data/runtime/stdlib/uri/ftp.rb +0 -261
- data/runtime/stdlib/uri/generic.rb +0 -1599
- data/runtime/stdlib/uri/http.rb +0 -106
- data/runtime/stdlib/uri/https.rb +0 -22
- data/runtime/stdlib/uri/ldap.rb +0 -260
- data/runtime/stdlib/uri/ldaps.rb +0 -20
- data/runtime/stdlib/uri/mailto.rb +0 -280
- data/spec/builder/output_path_spec.rb +0 -50
data/lib/opal/parser/grammar.y
CHANGED
@@ -83,9 +83,13 @@ stmts:
|
|
83
83
|
}
|
84
84
|
|
85
85
|
stmt:
|
86
|
-
ALIAS fitem
|
86
|
+
ALIAS fitem
|
87
87
|
{
|
88
|
-
|
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 =
|
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 =
|
155
|
+
result = s(:masgn, val[0], s(:to_ary, val[2]))
|
152
156
|
}
|
153
157
|
| mlhs '=' mrhs
|
154
158
|
{
|
155
|
-
result =
|
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 =
|
267
|
+
result = val[0]
|
264
268
|
}
|
265
269
|
| mlhs_head mlhs_item
|
266
270
|
{
|
267
|
-
result =
|
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 =
|
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
|
data/lib/opal/parser/lexer.rb
CHANGED
@@ -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 = :
|
1304
|
+
@lex_state = :expr_fname
|
1296
1305
|
return :ALIAS, matched
|
1297
1306
|
end
|
1298
1307
|
|
data/lib/opal/parser/parser.rb
CHANGED
@@ -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, :
|
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}
|
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
|
-
'
|
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 += "(
|
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[
|
469
|
-
args
|
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
|
-
|
483
|
-
|
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
|
-
|
549
|
+
tmprecv = @scope.new_temp
|
550
|
+
block = process arglist.pop, :expression
|
536
551
|
elsif iter
|
537
552
|
tmpproc = @scope.new_temp
|
538
|
-
|
539
|
-
|
540
|
-
|
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
|
-
|
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 =
|
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
|
794
|
+
code += "#{splat} = $slice.call(arguments, #{len});" if splat
|
755
795
|
code += process(stmts, :statement)
|
756
796
|
|
757
797
|
if @scope.uses_block?
|
758
|
-
|
759
|
-
blk = "var
|
760
|
-
blk += "var $context = $yield.$S
|
761
|
-
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
|
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
|
-
"
|
830
|
+
"def.#{mid} = #{defcode}"
|
782
831
|
elsif @scope.type == :module
|
783
832
|
@scope.methods << mid
|
784
|
-
"
|
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
|
-
"
|
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
|
|
data/lib/opal/parser/scope.rb
CHANGED
@@ -40,10 +40,10 @@ module Opal; class Parser
|
|
40
40
|
|
41
41
|
if @type == :class
|
42
42
|
vars << '$const = this.$const'
|
43
|
-
vars << '
|
43
|
+
vars << 'def = this.$proto'
|
44
44
|
elsif @type == :module
|
45
45
|
vars << '$const = this.$const'
|
46
|
-
vars << '
|
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
data/opal.gemspec
CHANGED
@@ -1,14 +1,12 @@
|
|
1
|
-
#
|
2
|
-
|
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://
|
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
|