Class: Rubex::AST::Statement::BeginBlock::Begin
- Inherits:
-
Base
- Object
- Rubex::AST::Statement::Base
- Base
- Rubex::AST::Statement::BeginBlock::Begin
- Defined in:
- lib/rubex/ast/statement/begin_block/begin.rb
Instance Attribute Summary
Attributes inherited from Rubex::AST::Statement::Base
Instance Method Summary collapse
- #analyse_statement(local_scope) ⇒ Object
- #generate_code(code, local_scope) ⇒ Object
-
#initialize(statements, tails, location) ⇒ Begin
constructor
A new instance of Begin.
Methods inherited from Rubex::AST::Statement::Base
Constructor Details
#initialize(statements, tails, location) ⇒ Begin
Returns a new instance of Begin.
6 7 8 9 |
# File 'lib/rubex/ast/statement/begin_block/begin.rb', line 6 def initialize(statements, tails, location) @tails = tails super(statements, location) end |
Instance Method Details
#analyse_statement(local_scope) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/rubex/ast/statement/begin_block/begin.rb', line 11 def analyse_statement(local_scope) local_scope.found_begin_block declare_error_state_variable local_scope declare_error_klass_variable local_scope declare_unhandled_error_variable local_scope @block_scope = Rubex::SymbolTable::Scope::BeginBlock.new( block_name(local_scope), local_scope ) create_c_function_to_house_statements local_scope.outer_scope analyse_tails local_scope end |
#generate_code(code, local_scope) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/rubex/ast/statement/begin_block/begin.rb', line 23 def generate_code(code, local_scope) code.nl code << '/* begin-rescue-else-ensure-end block begins: */' code.nl super cb_c_name = local_scope.find(@begin_func.name).c_name state_var = local_scope.find(@state_var_name).c_name code << "#{state_var} = 0;\n" code << "rb_protect(#{cb_c_name}, Qnil, &#{state_var});" code.nl generate_rescue_else_ensure code, local_scope end |