rubinius-ast 1.2.0 → 1.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2cda7718a6f58243f0f865ec0120f5e9971b3cb5
4
- data.tar.gz: a630561d268b422713f711d7885c921cd003c3a3
3
+ metadata.gz: 91409a26aa4135352fb1e50a67a5952c7e8bfcca
4
+ data.tar.gz: 8d5c8f3ea2def5e0c6214e0678d9aac81a205ff5
5
5
  SHA512:
6
- metadata.gz: 0d188bcf3227a86c2ddffd829a4d4078a774a326ed85e6d4df19296d25983e9a4c7bd8feeabcd42725f9c171b09d573e6f3b7a32252e56e0e23f89e9eb13a769
7
- data.tar.gz: 8a7afeb5cbec85d572c3613a5d3a1b1d5a8e0a6d5ea657c96da90952a6fe452ab120bfc1a4d8bd70fa55636c2b87f53c55ae20b1c36aa09dc2ff33707ae64baa
6
+ metadata.gz: b33a2f0f6358b5e87808135050401046843999e168b4e35115d3a9d0cd3853b86c0e99615032002548f555d0cead76f2d140755bebbd2a358233287808372241
7
+ data.tar.gz: 5a2d6b73f476c7337b31406bd9999d6402378937ff713a2748b31c089076d2c66d618ba125cdfc078b1f0bcb35dbc6714a27213f1cff218e9649b7a28ea57690
@@ -233,7 +233,6 @@ module Rubinius::ToolSets.current::ToolSet
233
233
 
234
234
  fin.set!
235
235
  else
236
- fin = g.new_label
237
236
  assign = g.new_label
238
237
 
239
238
  old_break = g.break
@@ -281,7 +280,6 @@ module Rubinius::ToolSets.current::ToolSet
281
280
  g.send :[]=, @arguments.size + 1
282
281
  end
283
282
 
284
- fin.set!
285
283
  g.pop
286
284
  end
287
285
  end
@@ -12,7 +12,83 @@ module Rubinius::ToolSets.current::ToolSet
12
12
 
13
13
  def bytecode(g)
14
14
  @value.bytecode(g)
15
- g.cast_array unless @value.kind_of? ArrayLiteral
15
+ return if @value.kind_of? ArrayLiteral
16
+
17
+ convert_to_ary(g)
18
+ end
19
+
20
+ def convert_to_ary(g)
21
+ done = g.new_label
22
+ coerce = g.new_label
23
+ coerce_method = :to_ary
24
+
25
+ kind_of_array(g, done)
26
+
27
+ check_respond_to = g.new_label
28
+
29
+ g.dup
30
+ g.push :nil
31
+ g.swap
32
+ g.send :equal?, 1, true
33
+ g.gif check_respond_to
34
+
35
+ g.make_array 1
36
+ g.goto done
37
+
38
+ check_respond_to.set!
39
+ g.dup
40
+ g.push_literal :to_ary
41
+ g.send :respond_to?, 1, true
42
+ g.git coerce
43
+
44
+ discard = g.new_label
45
+ check_array = g.new_label
46
+
47
+ make_array = g.new_label
48
+ make_array.set!
49
+ g.dup
50
+ g.send :to_a, 0, true
51
+ coerce_method = :to_a
52
+ g.goto check_array
53
+
54
+ coerce.set!
55
+ g.dup
56
+ g.send :to_ary, 0, true
57
+
58
+ g.dup
59
+ g.push :nil
60
+ g.send :equal?, 1, true
61
+ coerce_method = :to_ary
62
+ g.gif check_array
63
+
64
+ g.pop
65
+ g.goto make_array
66
+
67
+ check_array.set!
68
+ kind_of_array(g, discard)
69
+
70
+ g.push_type
71
+ g.move_down 2
72
+ g.push_literal coerce_method
73
+ g.push_cpath_top
74
+ g.find_const :Array
75
+ g.send :coerce_to_type_error, 4, true
76
+ g.goto done
77
+
78
+ discard.set!
79
+ g.swap
80
+ g.pop
81
+
82
+ done.set!
83
+ end
84
+
85
+ def kind_of_array(g, label)
86
+ g.dup
87
+ g.push_cpath_top
88
+ g.find_const :Array
89
+ g.swap
90
+ g.kind_of
91
+ g.git label
16
92
  end
17
93
 
18
94
  def to_sexp
@@ -37,7 +113,7 @@ module Rubinius::ToolSets.current::ToolSet
37
113
  if @array
38
114
  @array.bytecode(g)
39
115
  @rest.bytecode(g)
40
- g.cast_array
116
+ convert_to_ary(g)
41
117
  g.send :+, 1
42
118
  else
43
119
  @rest.bytecode(g)
@@ -45,6 +121,69 @@ module Rubinius::ToolSets.current::ToolSet
45
121
  end
46
122
  end
47
123
 
124
+ # TODO: de-dup
125
+ def convert_to_ary(g)
126
+ done = g.new_label
127
+ coerce = g.new_label
128
+ make_array = g.new_label
129
+ coerce_method = :to_ary
130
+
131
+ kind_of_array(g, done)
132
+
133
+ g.dup
134
+ g.push_literal :to_ary
135
+ g.send :respond_to?, 1, true
136
+ g.git coerce
137
+
138
+ discard = g.new_label
139
+ check_array = g.new_label
140
+
141
+ make_array.set!
142
+ g.dup
143
+ g.send :to_a, 0, true
144
+ coerce_method = :to_a
145
+ g.goto check_array
146
+
147
+ coerce.set!
148
+ g.dup
149
+ g.send :to_ary, 0, true
150
+
151
+ g.dup
152
+ g.push :nil
153
+ g.send :equal?, 1, true
154
+ coerce_method = :to_ary
155
+ g.gif check_array
156
+
157
+ g.pop
158
+ g.goto make_array
159
+
160
+ check_array.set!
161
+ kind_of_array(g, discard)
162
+
163
+ g.push_type
164
+ g.move_down 2
165
+ g.push_literal :to_ary
166
+ g.push_cpath_top
167
+ g.find_const :Array
168
+ g.send :coerce_to_type_error, 4, true
169
+ g.goto done
170
+
171
+ discard.set!
172
+ g.swap
173
+ g.pop
174
+
175
+ done.set!
176
+ end
177
+
178
+ def kind_of_array(g, label)
179
+ g.dup
180
+ g.push_cpath_top
181
+ g.find_const :Array
182
+ g.swap
183
+ g.kind_of
184
+ g.git label
185
+ end
186
+
48
187
  # Dive down and try to find an array of regular values
49
188
  # that could construct the left side of a concatination.
50
189
  # This is used to minimize the splat doing a send.
@@ -142,8 +281,49 @@ module Rubinius::ToolSets.current::ToolSet
142
281
  def bytecode(g)
143
282
  pos(g)
144
283
 
284
+ done = g.new_label
285
+ coerce = g.new_label
286
+
145
287
  @value.bytecode(g)
146
- g.cast_multi_value
288
+ kind_of_array(g, done)
289
+
290
+ g.dup
291
+ g.push_literal :to_ary
292
+ g.send :respond_to?, 1, true
293
+ g.git coerce
294
+
295
+ g.make_array 1
296
+ g.goto done
297
+
298
+ coerce.set!
299
+ g.dup
300
+ g.send :to_ary, 0, true
301
+
302
+ discard = g.new_label
303
+ kind_of_array(g, discard)
304
+
305
+ g.push_type
306
+ g.move_down 2
307
+ g.push_literal :to_a
308
+ g.push_cpath_top
309
+ g.find_const :Array
310
+ g.send :coerce_to_type_error, 4, true
311
+ g.goto done
312
+
313
+ discard.set!
314
+ g.swap
315
+ g.pop
316
+
317
+ done.set!
318
+ end
319
+
320
+ def kind_of_array(g, label)
321
+ g.dup
322
+ g.push_cpath_top
323
+ g.find_const :Array
324
+ g.swap
325
+ g.kind_of
326
+ g.git label
147
327
  end
148
328
 
149
329
  def to_sexp
@@ -541,7 +541,7 @@ module Rubinius::ToolSets.current::ToolSet
541
541
  end
542
542
 
543
543
  class MultipleAssignment < Node
544
- attr_accessor :left, :right, :splat, :block, :post
544
+ attr_accessor :left, :right, :splat, :block
545
545
 
546
546
  def initialize(line, left, right, splat)
547
547
  @line = line
@@ -549,7 +549,6 @@ module Rubinius::ToolSets.current::ToolSet
549
549
  @right = right
550
550
  @splat = nil
551
551
  @block = nil # support for |&b|
552
- @post = nil # in `a,*b,c`, c is in post.
553
552
 
554
553
  @fixed = right.kind_of?(ArrayLiteral) ? true : false
555
554
 
@@ -574,44 +573,6 @@ module Rubinius::ToolSets.current::ToolSet
574
573
  end
575
574
  end
576
575
 
577
- def pad_short(g)
578
- short = @left.body.size - @right.body.size
579
- if short > 0
580
- short.times { g.push :nil }
581
- g.make_array 0 if @splat
582
- end
583
- end
584
-
585
- def pop_excess(g)
586
- excess = @right.body.size - @left.body.size
587
- excess.times { g.pop } if excess > 0
588
- end
589
-
590
- def make_array(g)
591
- size = @right.body.size - @left.body.size
592
- g.make_array size if size >= 0
593
- end
594
-
595
- def make_retval(g)
596
- size = @right.body.size
597
- if @left and !@splat
598
- lhs = @left.body.size
599
- size = lhs if lhs > size
600
- end
601
- g.dup_many @right.body.size
602
- g.make_array @right.body.size
603
- g.move_down size
604
- end
605
-
606
- def rotate(g)
607
- if @splat
608
- size = @left.body.size + 1
609
- else
610
- size = @right.body.size
611
- end
612
- g.rotate size
613
- end
614
-
615
576
  def iter_arguments
616
577
  @iter_arguments = true
617
578
  end
@@ -640,83 +601,233 @@ module Rubinius::ToolSets.current::ToolSet
640
601
  end
641
602
 
642
603
  def bytecode(g, array_on_stack=false)
643
- unless array_on_stack
644
- g.cast_array unless @right or (@splat and not @left)
645
- end
646
-
647
604
  declare_local_scope(g.state.scope)
648
605
 
649
- if @fixed
650
- pad_short(g) if @left and !@splat
651
- @right.body.each { |x| x.bytecode(g) }
606
+ case @right
607
+ when ArrayLiteral, ConcatArgs
608
+ @right.bytecode(g)
609
+ when SplatValue
610
+ @right.bytecode(g)
611
+ convert_to_ary(g)
612
+ when ToArray
613
+ @right.bytecode(g)
614
+ when nil
615
+ convert_to_ary(g)
616
+ else
617
+ @right.bytecode(g)
618
+ convert_to_a(g)
619
+ end
652
620
 
653
- if @left
654
- make_retval(g)
621
+ size = g.new_stack_local
622
+ g.dup
623
+ g.send :size, 0, true
624
+ g.set_stack_local size
625
+ g.pop
655
626
 
656
- if @splat
657
- pad_short(g)
658
- make_array(g)
659
- end
627
+ index = g.new_stack_local
628
+ g.push 0
629
+ g.set_stack_local index
630
+ g.pop
660
631
 
661
- rotate(g)
632
+ g.state.push_masgn
662
633
 
663
- g.state.push_masgn
664
- @left.body.each do |x|
665
- x.bytecode(g)
666
- g.pop
667
- end
668
- g.state.pop_masgn
634
+ if @left
635
+ @left.body.each do |x|
636
+ convert_to_ary(g) if x.kind_of? MultipleAssignment
669
637
 
670
- pop_excess(g) unless @splat
671
- end
672
- else
673
- if @right
674
- if @right.kind_of? ArrayLiteral and @right.body.size == 1
675
- @right.body.first.bytecode(g)
676
- g.cast_multi_value
677
- else
678
- @right.bytecode(g)
679
- end
638
+ get_element(g, index)
680
639
 
681
- g.cast_array unless @right.kind_of? ToArray
682
- g.dup # Use the array as the return value
640
+ x.bytecode(g)
641
+ g.pop
683
642
  end
643
+ end
684
644
 
685
- if @left
686
- g.state.push_masgn
687
- @left.body.each do |x|
688
- g.shift_array
689
- g.cast_array if x.kind_of? MultipleAssignment and x.left
690
- x.bytecode(g)
691
- g.pop
692
- end
693
- g.state.pop_masgn
694
- end
645
+ if @splat
646
+ g.dup
695
647
 
696
- if @post
697
- g.state.push_masgn
698
- @post.body.each do |x|
699
- g.dup
700
- g.send :pop, 0
701
- g.cast_array if x.kind_of? MultipleAssignment and x.left
702
- x.bytecode(g)
703
- g.pop
704
- end
705
- g.state.pop_masgn
648
+ convert_to_ary(g) if @splat.kind_of? SplatValue
649
+
650
+ g.push_stack_local index
651
+
652
+ check_count = g.new_label
653
+
654
+ g.push_stack_local size
655
+ g.push_stack_local index
656
+ g.send :-, 1, true
657
+
658
+ g.goto check_count
659
+
660
+ underflow = g.new_label
661
+ assign_splat = g.new_label
662
+
663
+ underflow.set!
664
+ g.pop_many 3
665
+ g.make_array 0
666
+
667
+ g.goto assign_splat
668
+
669
+ check_count.set!
670
+ g.dup
671
+ g.push 0
672
+ g.send :<, 1, true
673
+ g.git underflow
674
+
675
+ g.dup
676
+ g.push_stack_local index
677
+ g.send :+, 1, true
678
+ g.set_stack_local index
679
+ g.pop
680
+
681
+ g.send :[], 2, true
682
+
683
+ assign_splat.set!
684
+
685
+ # TODO: Fix nodes to work correctly.
686
+ case @splat
687
+ when EmptySplat
688
+ # nothing
689
+ when SplatArray, SplatWrapped
690
+ @splat.value.bytecode(g)
691
+ else
692
+ @splat.bytecode(g)
706
693
  end
694
+ g.pop
707
695
  end
708
696
 
709
- if @splat
710
- g.state.push_masgn
711
- @splat.bytecode(g)
697
+ g.state.pop_masgn
698
+ end
712
699
 
713
- # Use the array as the return value
714
- g.dup if @fixed and !@left
700
+ def convert_to_a(g)
701
+ done = g.new_label
702
+ check_array = g.new_label
715
703
 
716
- g.state.pop_masgn
717
- end
704
+ kind_of_array(g, done)
705
+
706
+ wrap_tuple = g.new_label
707
+ kind_of_tuple(g, wrap_tuple)
708
+
709
+ g.dup
710
+ g.send :to_a, 0, true
711
+ g.goto check_array
712
+
713
+ wrap_tuple.set!
714
+ g.dup
715
+ g.make_array 0
716
+ g.dup
717
+ g.move_down 2
718
+ g.swap
719
+ g.push_literal :@tuple
720
+ g.swap
721
+ g.invoke_primitive :object_set_ivar, 3
722
+ g.send :size, 0, true
723
+ g.push_literal :@total
724
+ g.swap
725
+ g.invoke_primitive :object_set_ivar, 3
726
+ g.pop
727
+ g.goto done
728
+
729
+ discard = g.new_label
730
+
731
+ check_array.set!
732
+ kind_of_array(g, discard)
733
+
734
+ g.push_type
735
+ g.move_down 2
736
+ g.push_literal :to_a
737
+ g.push_cpath_top
738
+ g.find_const :Array
739
+ g.send :coerce_to_type_error, 4, true
740
+ g.goto done
741
+
742
+ discard.set!
743
+ g.swap
744
+ g.pop
745
+
746
+ done.set!
747
+ end
748
+
749
+ def convert_to_ary(g)
750
+ done = g.new_label
751
+ coerce = g.new_label
752
+ make_array = g.new_label
753
+ coerce_method = :to_ary
754
+
755
+ kind_of_array(g, done)
756
+
757
+ g.dup
758
+ g.push_literal :to_ary
759
+ g.send :respond_to?, 1, true
760
+ g.git coerce
761
+
762
+ discard = g.new_label
763
+ check_array = g.new_label
764
+
765
+ make_array.set!
766
+ g.dup
767
+ g.send :to_a, 0, true
768
+ coerce_method = :to_a
769
+ g.goto check_array
770
+
771
+ coerce.set!
772
+ g.dup
773
+ g.send :to_ary, 0, true
774
+
775
+ g.dup
776
+ g.push :nil
777
+ g.send :equal?, 1, true
778
+ coerce_method = :to_ary
779
+ g.gif check_array
780
+
781
+ g.pop
782
+ g.goto make_array
783
+
784
+ check_array.set!
785
+ kind_of_array(g, discard)
786
+
787
+ g.push_type
788
+ g.move_down 2
789
+ g.push_literal coerce_method
790
+ g.push_cpath_top
791
+ g.find_const :Array
792
+ g.send :coerce_to_type_error, 4, true
793
+ g.goto done
794
+
795
+ discard.set!
796
+ g.swap
797
+ g.pop
798
+
799
+ done.set!
800
+ end
801
+
802
+ def kind_of_array(g, label)
803
+ g.dup
804
+ g.push_cpath_top
805
+ g.find_const :Array
806
+ g.swap
807
+ g.kind_of
808
+ g.git label
809
+ end
810
+
811
+ def kind_of_tuple(g, label)
812
+ g.dup
813
+ g.push_rubinius
814
+ g.find_const :Tuple
815
+ g.swap
816
+ g.kind_of
817
+ g.git label
818
+ end
819
+
820
+ def get_element(g, index)
821
+ g.dup
822
+ g.push_stack_local index
823
+
824
+ g.dup
825
+ g.push 1
826
+ g.send :+, 1, true
827
+ g.set_stack_local index
828
+ g.pop
718
829
 
719
- g.pop if @right and (!@fixed or @splat)
830
+ g.send :[], 1, true
720
831
  end
721
832
 
722
833
  def defined(g)
@@ -1,5 +1,5 @@
1
1
  module Rubinius::ToolSets.current::ToolSet
2
2
  module AST
3
- VERSION = "1.2.0"
3
+ VERSION = "1.2.1"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubinius-ast
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brian Shirai
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-06-20 00:00:00.000000000 Z
11
+ date: 2014-06-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler