Class: Rubex::AST::Expression::RubyHashElementRef

Inherits:
RubyObjectElementRef show all
Defined in:
lib/rubex/ast/expression/ruby_object_element_ref/ruby_hash_element_ref.rb

Instance Attribute Summary

Attributes inherited from Base

#entry, #type, #typecast

Instance Method Summary collapse

Methods inherited from RubyObjectElementRef

#generate_element_ref_code

Methods inherited from AnalysedElementRef

#c_code, #initialize

Methods inherited from Base

#allocate_temp, #allocate_temps, #analyse_for_target_type, #c_code, #expression?, #from_ruby_object, #generate_and_dispose_subexprs, #generate_disposal_code, #has_temp, #possible_typecast, #release_temp, #release_temps, #to_ruby_object

Constructor Details

This class inherits a constructor from Rubex::AST::Expression::AnalysedElementRef

Instance Method Details

#analyse_types(local_scope) ⇒ Object



5
6
7
8
9
10
# File 'lib/rubex/ast/expression/ruby_object_element_ref/ruby_hash_element_ref.rb', line 5

def analyse_types(local_scope)
  if @pos.size > 1
    raise "Ruby Hash#[] expects 1 argument. Not #{@pos.size}."
  end
  super
end

#generate_assignment_code(rhs, code, local_scope) ⇒ Object



20
21
22
23
24
25
26
# File 'lib/rubex/ast/expression/ruby_object_element_ref/ruby_hash_element_ref.rb', line 20

def generate_assignment_code(rhs, code, local_scope)
  generate_and_dispose_subexprs(code, local_scope) do
    code << "rb_hash_aset(#{@entry.c_name}, #{@pos[0].c_code(local_scope)},"
    code << "#{rhs.c_code(local_scope)});"
    code.nl
  end
end

#generate_evaluation_code(code, local_scope) ⇒ Object



12
13
14
15
16
17
18
# File 'lib/rubex/ast/expression/ruby_object_element_ref/ruby_hash_element_ref.rb', line 12

def generate_evaluation_code(code, local_scope)
  generate_and_dispose_subexprs(code, local_scope) do
    code << "#{@c_code} = rb_hash_aref(#{@entry.c_name}, "
    code << "#{@pos[0].c_code(local_scope)});"
    code.nl
  end
end