Class: CodeTools::AST::SplatValue

Inherits:
Node
  • Object
show all
Defined in:
lib/rubinius/ast/values.rb

Instance Attribute Summary collapse

Attributes inherited from Node

#line

Instance Method Summary collapse

Methods inherited from Node

#ascii_graph, #attributes, #children, #defined, match_arguments?, match_send?, #new_block_generator, #new_generator, #node_name, #or_bytecode, #pos, #set_child, #transform, transform, transform_comment, transform_kind, transform_kind=, transform_name, #value_defined, #visit, #walk

Constructor Details

#initialize(line, value) ⇒ SplatValue

Returns a new instance of SplatValue.



8
9
10
11
# File 'lib/rubinius/ast/values.rb', line 8

def initialize(line, value)
  @line = line
  @value = value
end

Instance Attribute Details

#valueObject

Returns the value of attribute value.



6
7
8
# File 'lib/rubinius/ast/values.rb', line 6

def value
  @value
end

Instance Method Details

#bytecode(g) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/rubinius/ast/values.rb', line 13

def bytecode(g)
  done = g.new_label
  coerce = g.new_label
  make_array = g.new_label
  dup_as_array = g.new_label

  @value.bytecode(g)

  instance_of_array(g, dup_as_array)
  kind_of_array(g, dup_as_array)

  g.dup
  g.push_literal :to_a
  g.push :true
  g.send :respond_to?, 2, true
  g.git coerce

  make_array.set!
  g.make_array 1
  g.goto done

  discard = g.new_label

  dup_as_array.set!
  g.dup
  g.push_rubinius
  g.find_const :Runtime
  g.swap
  g.send :dup_as_array, 1, true
  g.goto discard

  coerce.set!
  g.dup
  g.send :to_a, 0, true

  check_array = g.new_label

  g.dup
  g.is_nil
  g.gif check_array

  g.pop
  g.goto make_array

  check_array.set!
  kind_of_array(g, discard)

  g.push_type
  g.move_down 2
  g.push_literal :to_a
  g.push_cpath_top
  g.find_const :Array
  g.send :coerce_to_type_error, 4, true
  g.goto done

  discard.set!
  g.swap
  g.pop

  done.set!
end

#instance_of_array(g, label) ⇒ Object



75
76
77
78
79
80
81
82
# File 'lib/rubinius/ast/values.rb', line 75

def instance_of_array(g, label)
  g.dup
  g.push_cpath_top
  g.find_const :Array
  g.swap
  g.instance_of
  g.git label
end

#kind_of_array(g, label) ⇒ Object



84
85
86
87
88
89
90
91
# File 'lib/rubinius/ast/values.rb', line 84

def kind_of_array(g, label)
  g.dup
  g.push_cpath_top
  g.find_const :Array
  g.swap
  g.kind_of
  g.git label
end

#splat?Boolean

Returns:

  • (Boolean)


97
98
99
# File 'lib/rubinius/ast/values.rb', line 97

def splat?
  true
end

#to_sexpObject



93
94
95
# File 'lib/rubinius/ast/values.rb', line 93

def to_sexp
  [:splat, @value.to_sexp]
end