opal 0.5.2 → 0.5.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (62) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +2 -0
  3. data/lib/opal.rb +0 -5
  4. data/lib/opal/compiler.rb +24 -44
  5. data/lib/opal/nodes/base.rb +5 -8
  6. data/lib/opal/nodes/call.rb +4 -0
  7. data/lib/opal/nodes/class.rb +6 -7
  8. data/lib/opal/nodes/def.rb +4 -4
  9. data/lib/opal/nodes/definitions.rb +0 -14
  10. data/lib/opal/nodes/iter.rb +51 -38
  11. data/lib/opal/nodes/literal.rb +21 -24
  12. data/lib/opal/nodes/module.rb +4 -4
  13. data/lib/opal/nodes/runtime_helpers.rb +45 -0
  14. data/lib/opal/nodes/scope.rb +280 -0
  15. data/lib/opal/nodes/singleton_class.rb +4 -5
  16. data/lib/opal/nodes/super.rb +1 -1
  17. data/lib/opal/nodes/top.rb +9 -7
  18. data/lib/opal/nodes/yield.rb +14 -3
  19. data/lib/opal/parser.rb +4 -18
  20. data/lib/opal/parser/grammar.rb +3745 -3667
  21. data/lib/opal/parser/grammar.y +1692 -1778
  22. data/lib/opal/parser/keywords.rb +35 -35
  23. data/lib/opal/parser/lexer.rb +356 -325
  24. data/lib/opal/parser/sexp.rb +1 -1
  25. data/lib/opal/version.rb +1 -1
  26. data/opal.gemspec +1 -0
  27. data/opal/core/array.rb +320 -81
  28. data/opal/core/enumerable.rb +46 -5
  29. data/opal/core/hash.rb +6 -64
  30. data/opal/core/helpers.rb +67 -0
  31. data/opal/core/method.rb +1 -1
  32. data/opal/core/module.rb +4 -4
  33. data/opal/core/range.rb +1 -12
  34. data/opal/core/regexp.rb +2 -8
  35. data/opal/core/runtime.js +74 -3
  36. data/opal/core/string.rb +99 -74
  37. data/opal/opal.rb +3 -72
  38. data/spec/filters/bugs/array.rb +2 -30
  39. data/spec/filters/bugs/basic_object.rb +0 -1
  40. data/spec/filters/bugs/string.rb +26 -21
  41. data/spec/filters/unsupported/enumerator.rb +3 -0
  42. data/spec/filters/unsupported/float.rb +1 -0
  43. data/spec/filters/unsupported/immutable_strings.rb +15 -0
  44. data/spec/filters/unsupported/tainted.rb +58 -30
  45. data/spec/filters/unsupported/trusted.rb +35 -15
  46. data/spec/opal/parser/class_spec.rb +4 -4
  47. data/spec/opal/parser/def_spec.rb +4 -4
  48. data/spec/opal/parser/lvar_spec.rb +6 -6
  49. data/spec/opal/parser/module_spec.rb +4 -4
  50. data/spec/opal/parser/sclass_spec.rb +2 -2
  51. data/spec/stdlib/native/exposure_spec.rb +33 -0
  52. data/stdlib/buffer.rb +1 -1
  53. data/stdlib/buffer/view.rb +1 -1
  54. data/stdlib/native.rb +193 -174
  55. data/stdlib/opal-parser.rb +0 -6
  56. data/stdlib/pp.rb +9 -0
  57. data/tasks/mspec.rake +3 -1
  58. metadata +9 -9
  59. data/lib/opal/nodes/base_scope.rb +0 -11
  60. data/lib/opal/target_scope.rb +0 -281
  61. data/spec/filters/20.rb +0 -4
  62. data/spec/filters/unsupported/array_subclasses.rb +0 -37
@@ -3,12 +3,6 @@ require 'opal/builder'
3
3
  require 'opal/erb'
4
4
  require 'opal/version'
5
5
 
6
- module Opal
7
- def self.compile(source, options = {})
8
- Compiler.new.compile(source, options)
9
- end
10
- end
11
-
12
6
  module Kernel
13
7
  def eval(str)
14
8
  code = Opal.compile str
@@ -1,3 +1,12 @@
1
1
  module Kernel
2
2
  def pretty_inspect; inspect; end
3
+
4
+ if `(typeof console === "undefined" || typeof console.log === "undefined")`
5
+ alias :pp :p
6
+ else
7
+ def pp *args
8
+ args.each { |obj| `console.log(obj);` }
9
+ args.length <= 1 ? args[0] : args
10
+ end
11
+ end
3
12
  end
@@ -102,7 +102,9 @@ class RunSpec
102
102
  specs << (file.nil? ? Dir.glob("#{Dir.pwd}/spec/**/*_spec.{rb,opal}") : file)
103
103
 
104
104
  # add any rubyspecs we want to run (defined in spec/rubyspecs)
105
- specs.push File.read('spec/rubyspecs').split("\n").reject(&:empty?)
105
+ specs.push File.read('spec/rubyspecs').split("\n").reject {|line|
106
+ line.empty? || line.start_with?('#')
107
+ }
106
108
 
107
109
  specs.flatten
108
110
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: opal
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.2
4
+ version: 0.5.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adam Beynon
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-11-11 00:00:00.000000000 Z
11
+ date: 2013-11-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: source_map
@@ -147,7 +147,6 @@ files:
147
147
  - lib/opal/nodes/arglist.rb
148
148
  - lib/opal/nodes/array.rb
149
149
  - lib/opal/nodes/base.rb
150
- - lib/opal/nodes/base_scope.rb
151
150
  - lib/opal/nodes/call.rb
152
151
  - lib/opal/nodes/call_special.rb
153
152
  - lib/opal/nodes/case.rb
@@ -165,6 +164,8 @@ files:
165
164
  - lib/opal/nodes/masgn.rb
166
165
  - lib/opal/nodes/module.rb
167
166
  - lib/opal/nodes/rescue.rb
167
+ - lib/opal/nodes/runtime_helpers.rb
168
+ - lib/opal/nodes/scope.rb
168
169
  - lib/opal/nodes/singleton_class.rb
169
170
  - lib/opal/nodes/super.rb
170
171
  - lib/opal/nodes/top.rb
@@ -179,7 +180,6 @@ files:
179
180
  - lib/opal/parser/parser_scope.rb
180
181
  - lib/opal/parser/sexp.rb
181
182
  - lib/opal/source_map.rb
182
- - lib/opal/target_scope.rb
183
183
  - lib/opal/version.rb
184
184
  - mri_spec/cli_spec.rb
185
185
  - mri_spec/fixtures/opal_file.rb
@@ -195,6 +195,7 @@ files:
195
195
  - opal/core/enumerator.rb
196
196
  - opal/core/error.rb
197
197
  - opal/core/hash.rb
198
+ - opal/core/helpers.rb
198
199
  - opal/core/io.rb
199
200
  - opal/core/kernel.rb
200
201
  - opal/core/main.rb
@@ -402,7 +403,6 @@ files:
402
403
  - spec/corelib/string/to_i_spec.rb
403
404
  - spec/corelib/string/tr_s_spec.rb
404
405
  - spec/corelib/string/tr_spec.rb
405
- - spec/filters/20.rb
406
406
  - spec/filters/bugs/array.rb
407
407
  - spec/filters/bugs/basic_object.rb
408
408
  - spec/filters/bugs/class.rb
@@ -421,7 +421,6 @@ files:
421
421
  - spec/filters/bugs/symbol.rb
422
422
  - spec/filters/bugs/time.rb
423
423
  - spec/filters/bugs/unknown.rb
424
- - spec/filters/unsupported/array_subclasses.rb
425
424
  - spec/filters/unsupported/encoding.rb
426
425
  - spec/filters/unsupported/enumerator.rb
427
426
  - spec/filters/unsupported/float.rb
@@ -500,6 +499,7 @@ files:
500
499
  - spec/stdlib/native/alias_native_spec.rb
501
500
  - spec/stdlib/native/each_spec.rb
502
501
  - spec/stdlib/native/element_reference_spec.rb
502
+ - spec/stdlib/native/exposure_spec.rb
503
503
  - spec/stdlib/native/ext_spec.rb
504
504
  - spec/stdlib/native/initialize_spec.rb
505
505
  - spec/stdlib/native/method_missing_spec.rb
@@ -538,7 +538,8 @@ files:
538
538
  - stdlib/thread.rb
539
539
  - tasks/mspec.rake
540
540
  homepage: http://opalrb.org
541
- licenses: []
541
+ licenses:
542
+ - MIT
542
543
  metadata: {}
543
544
  post_install_message:
544
545
  rdoc_options: []
@@ -752,7 +753,6 @@ test_files:
752
753
  - spec/corelib/string/to_i_spec.rb
753
754
  - spec/corelib/string/tr_s_spec.rb
754
755
  - spec/corelib/string/tr_spec.rb
755
- - spec/filters/20.rb
756
756
  - spec/filters/bugs/array.rb
757
757
  - spec/filters/bugs/basic_object.rb
758
758
  - spec/filters/bugs/class.rb
@@ -771,7 +771,6 @@ test_files:
771
771
  - spec/filters/bugs/symbol.rb
772
772
  - spec/filters/bugs/time.rb
773
773
  - spec/filters/bugs/unknown.rb
774
- - spec/filters/unsupported/array_subclasses.rb
775
774
  - spec/filters/unsupported/encoding.rb
776
775
  - spec/filters/unsupported/enumerator.rb
777
776
  - spec/filters/unsupported/float.rb
@@ -850,6 +849,7 @@ test_files:
850
849
  - spec/stdlib/native/alias_native_spec.rb
851
850
  - spec/stdlib/native/each_spec.rb
852
851
  - spec/stdlib/native/element_reference_spec.rb
852
+ - spec/stdlib/native/exposure_spec.rb
853
853
  - spec/stdlib/native/ext_spec.rb
854
854
  - spec/stdlib/native/initialize_spec.rb
855
855
  - spec/stdlib/native/method_missing_spec.rb
@@ -1,11 +0,0 @@
1
- require 'opal/nodes/base'
2
-
3
- module Opal
4
- module Nodes
5
- class BaseScopeNode < Base
6
- def in_scope(type, &block)
7
- indent { compiler.in_scope(type, &block) }
8
- end
9
- end
10
- end
11
- end
@@ -1,281 +0,0 @@
1
- module Opal
2
- # Instances of TargetScope are used by the parser when a new scope is
3
- # being processed. It is used to keep track of used variables,
4
- # temp variables and ivars so they can be processed and output
5
- # along with the scope implementation.
6
- class TargetScope
7
-
8
- # Every scope can have a parent scope
9
- attr_accessor :parent
10
-
11
- # The class or module name if this scope is a class scope
12
- attr_accessor :name
13
-
14
- # The given block name for a def scope
15
- attr_accessor :block_name
16
-
17
- attr_reader :scope_name
18
- attr_reader :ivars
19
-
20
- attr_reader :type
21
-
22
- # One of - :class, :module, :top, :iter, :def
23
- attr_accessor :mid
24
-
25
- # true if singleton def, false otherwise
26
- attr_accessor :defs
27
-
28
- # used by modules to know what methods to donate to includees
29
- attr_reader :methods
30
-
31
- # uses parents super method
32
- attr_accessor :uses_super
33
- attr_accessor :uses_zuper
34
-
35
- attr_accessor :catch_return
36
-
37
- # @param [Symbol] type the scope type (:class, :module, :iter, :def, :top)
38
- # @param [Opal::Compiler] parser a parser instance used to create this scope
39
- def initialize(type, parser)
40
- @parser = parser
41
- @type = type
42
- @locals = []
43
- @temps = []
44
- @args = []
45
- @ivars = []
46
- @parent = nil
47
- @queue = []
48
- @unique = "a"
49
- @while_stack = []
50
-
51
- @methods = []
52
-
53
- @uses_block = false
54
-
55
- # used by classes to store all ivars used in direct def methods
56
- @proto_ivars = []
57
- end
58
-
59
- # Returns true if this scope is a class/module body scope
60
- def class_scope?
61
- @type == :class or @type == :module
62
- end
63
-
64
- # Returns true if this is strictly a class scope
65
- def class?
66
- @type == :class
67
- end
68
-
69
- # True if this is a module scope
70
- def module?
71
- @type == :module
72
- end
73
-
74
- def sclass?
75
- @type == :sclass
76
- end
77
-
78
- # Returns true if this is a top scope (main file body)
79
- def top?
80
- @type == :top
81
- end
82
-
83
- # True if a block/iter scope
84
- def iter?
85
- @type == :iter
86
- end
87
-
88
- def def?
89
- @type == :def
90
- end
91
-
92
- # Is this a normal def method directly inside a class? This is
93
- # used for optimizing ivars as we can set them to nil in the
94
- # class body
95
- def def_in_class?
96
- !@defs && @type == :def && @parent && @parent.class?
97
- end
98
-
99
- # Inside a class or module scope, the javascript variable name returned
100
- # by this function points to the classes' prototype. This is the target
101
- # to where methods are actually added inside a class body.
102
- def proto
103
- "def"
104
- end
105
-
106
- # A scope donates its methods if it is a module, or the core Object
107
- # class. Modules donate their methods to classes or objects they are
108
- # included in. Object donates methods to bridged classes whose native
109
- # prototypes do not actually inherit from Opal.Object.prototype.
110
- def should_donate?
111
- @type == :module
112
- end
113
-
114
- ##
115
- # Vars to use inside each scope
116
- def to_vars
117
- vars = @temps.dup
118
- vars.push(*@locals.map { |l| "#{l} = nil" })
119
-
120
- iv = ivars.map do |ivar|
121
- "if (self#{ivar} == null) self#{ivar} = nil;\n"
122
- end
123
-
124
- indent = @parser.parser_indent
125
- res = vars.empty? ? '' : "var #{vars.join ', '};"
126
- str = ivars.empty? ? res : "#{res}\n#{indent}#{iv.join indent}"
127
-
128
- if class? and !@proto_ivars.empty?
129
- #raise "FIXME to_vars"
130
- pvars = @proto_ivars.map { |i| "#{proto}#{i}"}.join(' = ')
131
- result = "%s\n%s%s = nil;" % [str, indent, pvars]
132
- else
133
- result = str
134
- end
135
-
136
- fragment(result)
137
- end
138
-
139
- def fragment(code, sexp = nil)
140
- @parser.fragment code
141
- end
142
-
143
- # Generates code for this module to donate methods
144
- def to_donate_methods
145
- if should_donate? and !@methods.empty?
146
- fragment("%s;$opal.donate(self, [%s]);" % [@parser.parser_indent, @methods.map(&:inspect).join(', ')])
147
- else
148
- fragment("")
149
- end
150
- end
151
-
152
- def add_ivar(ivar)
153
- if def_in_class?
154
- @parent.add_proto_ivar ivar
155
- else
156
- @ivars << ivar unless @ivars.include? ivar
157
- end
158
- end
159
-
160
- def add_proto_ivar(ivar)
161
- @proto_ivars << ivar unless @proto_ivars.include? ivar
162
- end
163
-
164
- def add_arg(arg)
165
- @args << arg unless @args.include? arg
166
- arg
167
- end
168
-
169
- def add_local(local)
170
- return if has_local? local
171
-
172
- @locals << local
173
- end
174
-
175
- def has_local?(local)
176
- return true if @locals.include? local or @args.include? local
177
- return @parent.has_local?(local) if @parent and @type == :iter
178
-
179
- false
180
- end
181
-
182
- def add_temp(*tmps)
183
- @temps.push(*tmps)
184
- end
185
-
186
- def has_temp?(tmp)
187
- @temps.include? tmp
188
- end
189
-
190
- def new_temp
191
- return @queue.pop unless @queue.empty?
192
-
193
- tmp = next_temp
194
- @temps << tmp
195
- tmp
196
- end
197
-
198
- def next_temp
199
- tmp = "$#{@unique}"
200
- @unique = @unique.succ
201
- tmp
202
- end
203
-
204
- def queue_temp(name)
205
- @queue << name
206
- end
207
-
208
- def push_while
209
- info = {}
210
- @while_stack.push info
211
- info
212
- end
213
-
214
- def pop_while
215
- @while_stack.pop
216
- end
217
-
218
- def in_while?
219
- !@while_stack.empty?
220
- end
221
-
222
- def uses_block!
223
- if @type == :iter && @parent
224
- @parent.uses_block!
225
- else
226
- @uses_block = true
227
- identify!
228
- end
229
- end
230
-
231
- def identify!
232
- return @identity if @identity
233
-
234
- @identity = @parser.unique_temp
235
- @parent.add_temp @identity if @parent
236
-
237
- @identity
238
- end
239
-
240
- def identity
241
- @identity
242
- end
243
-
244
- def find_parent_def
245
- scope = self
246
- while scope = scope.parent
247
- if scope.def?
248
- return scope
249
- end
250
- end
251
-
252
- nil
253
- end
254
-
255
- def get_super_chain
256
- chain, scope, defn, mid = [], self, 'null', 'null'
257
-
258
- while scope
259
- if scope.type == :iter
260
- chain << scope.identify!
261
- scope = scope.parent if scope.parent
262
-
263
- elsif scope.type == :def
264
- defn = scope.identify!
265
- mid = "'#{scope.mid}'"
266
- break
267
-
268
- else
269
- break
270
- end
271
- end
272
-
273
- [chain, defn, mid]
274
- end
275
-
276
- def uses_block?
277
- @uses_block
278
- end
279
- end
280
- end
281
-
@@ -1,4 +0,0 @@
1
- opal_filter "2.0 behaviour" do
2
- fails "Enumerator.new ignores block if arg given"
3
- fails "String#end_with? ignores arguments not convertible to string"
4
- end
@@ -1,37 +0,0 @@
1
- opal_filter "Array subclasses" do
2
- fails "Array.[] returns a new array populated with the given elements"
3
- fails "Array[] is a synonym for .[]"
4
- fails "Array.new returns an instance of a subclass"
5
- fails "Array#values_at does not return subclass instance on Array subclasses"
6
- fails "Array#to_a does not return subclass instance on Array subclasses"
7
- fails "Array#uniq returns subclass instance on Array subclasses"
8
- fails "Array#clone returns an Array or a subclass instance"
9
- fails "Array#<=> does not call #to_ary on Array subclasses"
10
- fails "Array#concat does not call #to_ary on Array subclasses"
11
- fails "Array#dup returns an Array or a subclass instance"
12
- fails "Array#[]= does not call to_ary on rhs array subclasses for multi-element sets"
13
- fails "Array#eql? does not call #to_ary on Array subclasses"
14
- fails "Array#== does not call #to_ary on Array subclasses"
15
- fails "Array#flatten returns subclass instance for Array subclasses"
16
- fails "Array#initialize with (array) does not call #to_ary on instances of Array or subclasses of Array"
17
- fails "Array#initialize is called on subclasses"
18
- fails "Array#* with an integer with a subclass of Array returns a subclass instance"
19
- fails "Array.new with (array) does not call #to_ary on instances of Array or subclasses of Array"
20
- fails "Array#replace does not call #to_ary on Array subclasses"
21
- fails "Array#slice with a subclass of Array returns a subclass instance with [-n...-m]"
22
- fails "Array#slice with a subclass of Array returns a subclass instance with [-n..-m]"
23
- fails "Array#slice with a subclass of Array returns a subclass instance with [n...m]"
24
- fails "Array#slice with a subclass of Array returns a subclass instance with [n..m]"
25
- fails "Array#slice with a subclass of Array returns a subclass instance with [-n, m]"
26
- fails "Array#slice with a subclass of Array returns a subclass instance with [n, m]"
27
-
28
- fails "Array#[] with a subclass of Array returns a subclass instance with [n, m]"
29
- fails "Array#[] with a subclass of Array returns a subclass instance with [-n, m]"
30
- fails "Array#[] with a subclass of Array returns a subclass instance with [n..m]"
31
- fails "Array#[] with a subclass of Array returns a subclass instance with [n...m]"
32
- fails "Array#[] with a subclass of Array returns a subclass instance with [-n..-m]"
33
- fails "Array#[] with a subclass of Array returns a subclass instance with [-n...-m]"
34
- fails "Array.[] with a subclass of Array returns an instance of the subclass"
35
- fails "Array#initialize_copy does not call #to_ary on Array subclasses"
36
- fails "Array#partition does not return subclass instances on Array subclasses"
37
- end