Class: Rubex::AST::Expression::Literal::ArrayLit
- Inherits:
-
Base
- Object
- Base
- Base
- Rubex::AST::Expression::Literal::ArrayLit
show all
- Includes:
- Enumerable
- Defined in:
- lib/rubex/ast/expression/literal/array_lit.rb
Instance Attribute Summary collapse
Attributes inherited from Base
#entry, #type, #typecast
Instance Method Summary
collapse
Methods inherited from Base
#==, #c_name, #literal?
Methods inherited from Base
#allocate_temp, #allocate_temps, #analyse_for_target_type, #expression?, #from_ruby_object, #generate_and_dispose_subexprs, #generate_assignment_code, #has_temp, #possible_typecast, #release_temp, #release_temps, #to_ruby_object
Constructor Details
#initialize(array_list) ⇒ ArrayLit
Returns a new instance of ArrayLit.
14
15
16
17
|
# File 'lib/rubex/ast/expression/literal/array_lit.rb', line 14
def initialize(array_list)
@array_list = array_list
@subexprs = []
end
|
Instance Attribute Details
#c_array ⇒ Object
Returns the value of attribute c_array.
8
9
10
|
# File 'lib/rubex/ast/expression/literal/array_lit.rb', line 8
def c_array
@c_array
end
|
Instance Method Details
#analyse_types(local_scope) ⇒ Object
19
20
21
22
23
24
25
26
27
28
|
# File 'lib/rubex/ast/expression/literal/array_lit.rb', line 19
def analyse_types(local_scope)
@has_temp = true
@type = DataType::RubyObject.new
@array_list.map! do |e|
e.analyse_types local_scope
e = e.to_ruby_object
@subexprs << e
e
end
end
|
#c_code(_local_scope) ⇒ Object
44
45
46
|
# File 'lib/rubex/ast/expression/literal/array_lit.rb', line 44
def c_code(_local_scope)
@c_code
end
|
#each(&block) ⇒ Object
10
11
12
|
# File 'lib/rubex/ast/expression/literal/array_lit.rb', line 10
def each(&block)
@array_list.each(&block)
end
|
#generate_disposal_code(code) ⇒ Object
39
40
41
42
|
# File 'lib/rubex/ast/expression/literal/array_lit.rb', line 39
def generate_disposal_code(code)
code << "#{@c_code} = 0;"
code.nl
end
|
#generate_evaluation_code(code, local_scope) ⇒ Object
30
31
32
33
34
35
36
37
|
# File 'lib/rubex/ast/expression/literal/array_lit.rb', line 30
def generate_evaluation_code(code, local_scope)
code << "#{@c_code} = rb_ary_new2(#{@array_list.size});"
code.nl
@array_list.each do |e|
code << "rb_ary_push(#{@c_code}, #{e.c_code(local_scope)});"
code.nl
end
end
|