Class: Rubex::AST::Expression::Require

Inherits:
Base
  • Object
show all
Defined in:
lib/rubex/ast/expression/command_call/require.rb

Instance Attribute Summary

Attributes inherited from Base

#entry, #type, #typecast

Instance Method Summary collapse

Methods inherited from Base

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

Constructor Details

#initialize(args) ⇒ Require

Returns a new instance of Require.



5
6
7
# File 'lib/rubex/ast/expression/command_call/require.rb', line 5

def initialize args
  @args = args
end

Instance Method Details

#analyse_types(local_scope) ⇒ Object



9
10
11
12
13
14
# File 'lib/rubex/ast/expression/command_call/require.rb', line 9

def analyse_types(local_scope)
  raise "require can only support single string argument." if @args.size > 1
  if !@args[0].is_a?(Expression::Literal::StringLit)
    raise "Argument to require must be a string literal. not #{@args[0].class}."
  end
end

#c_code(_local_scope) ⇒ Object



21
22
23
# File 'lib/rubex/ast/expression/command_call/require.rb', line 21

def c_code(_local_scope)
  @c_code
end

#generate_evaluation_code(code, local_scope) ⇒ Object



16
17
18
19
# File 'lib/rubex/ast/expression/command_call/require.rb', line 16

def generate_evaluation_code(code, local_scope)
  string = @args[0].instance_variable_get(:@name)          
  @c_code = "rb_funcall(rb_cObject, rb_intern(\"require\"), 1, rb_str_new2(\"#{string}\"))"
end