Class: Stone::AST::Block
- Inherits:
-
Expression
- Object
- Stone::AST
- Expression
- Stone::AST::Block
- Includes:
- TwoPhaseProcessing
- Defined in:
- lib/stone/ast/block.rb
Class Attribute Summary collapse
-
.block_count ⇒ Object
Returns the value of attribute block_count.
Instance Attribute Summary collapse
-
#statements ⇒ Object
readonly
Returns the value of attribute statements.
Attributes inherited from Stone::AST
Instance Method Summary collapse
-
#evaluate_body_and_return(builder, mod, scope) ⇒ Object
Evaluate all statements in block and return value of last statement.
-
#initialize(statements) ⇒ Block
constructor
A new instance of Block.
- #to_llir(_builder, mod, scope = Stone::Scope.top_level) ⇒ Object
- #to_s ⇒ Object
- #type(context = nil) ⇒ Object
Constructor Details
#initialize(statements) ⇒ Block
19 20 21 22 23 |
# File 'lib/stone/ast/block.rb', line 19 def initialize(statements) @name = :block @statements = statements @block_id = next_block_id end |
Class Attribute Details
.block_count ⇒ Object
Returns the value of attribute block_count.
14 15 16 |
# File 'lib/stone/ast/block.rb', line 14 def block_count @block_count end |
Instance Attribute Details
#statements ⇒ Object (readonly)
Returns the value of attribute statements.
11 12 13 |
# File 'lib/stone/ast/block.rb', line 11 def statements @statements end |
Instance Method Details
#evaluate_body_and_return(builder, mod, scope) ⇒ Object
Evaluate all statements in block and return value of last statement.
70 71 72 73 74 75 |
# File 'lib/stone/ast/block.rb', line 70 def evaluate_body_and_return(builder, mod, scope) child_scope = scope.child register_type_declarations(child_scope) last_result = compile_statements(builder, mod, child_scope) builder.ret(last_result) end |
#to_llir(_builder, mod, scope = Stone::Scope.top_level) ⇒ Object
25 26 27 28 |
# File 'lib/stone/ast/block.rb', line 25 def to_llir(_builder, mod, scope = Stone::Scope.top_level) # Check if function already exists (happens if to_llir called multiple times on same block). mod.functions[function_name] || create_function(mod, function_name, function_type, scope) end |
#to_s ⇒ Object
30 31 32 |
# File 'lib/stone/ast/block.rb', line 30 def to_s "{ #{statements.join("\n")} }" end |
#type(context = nil) ⇒ Object
34 35 36 37 |
# File 'lib/stone/ast/block.rb', line 34 def type(context = nil) last_expression = statements.reverse.find { |stmt| stmt.type(context) } last_expression&.type(context) end |