Class: MilkTea::CompileTime::BlockContext
- Inherits:
-
Object
- Object
- MilkTea::CompileTime::BlockContext
- Defined in:
- lib/milk_tea/core/compile_time.rb
Instance Attribute Summary collapse
-
#checker ⇒ Object
readonly
Returns the value of attribute checker.
Instance Method Summary collapse
- #evaluate_block(statements, scopes: nil) ⇒ Object
-
#initialize(checker, initial_variables: nil) ⇒ BlockContext
constructor
A new instance of BlockContext.
Constructor Details
#initialize(checker, initial_variables: nil) ⇒ BlockContext
Returns a new instance of BlockContext.
23 24 25 26 |
# File 'lib/milk_tea/core/compile_time.rb', line 23 def initialize(checker, initial_variables: nil) @checker = checker @variables = initial_variables || {} end |
Instance Attribute Details
#checker ⇒ Object (readonly)
Returns the value of attribute checker.
21 22 23 |
# File 'lib/milk_tea/core/compile_time.rb', line 21 def checker @checker end |
Instance Method Details
#evaluate_block(statements, scopes: nil) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/milk_tea/core/compile_time.rb', line 28 def evaluate_block(statements, scopes: nil) result = nil statements.each do |statement| case statement when AST::LocalDecl result = evaluate_local_decl(statement, scopes:) when AST::ReturnStmt value = statement.value ? evaluate_expression(statement.value, scopes:) : nil raise ReturnValue.new(value) when AST::WhileStmt result = evaluate_while(statement, scopes:) when AST::ForStmt result = evaluate_for(statement, scopes:) when AST::Assignment result = evaluate_assignment(statement, scopes:) when AST::IfStmt result = evaluate_if(statement, scopes:) when AST::ExpressionStmt evaluate_expression(statement.expression, scopes:) when AST::PassStmt, AST::BreakStmt, AST::ContinueStmt # no-op at compile time when AST::EmitStmt # evaluated during lowering result = nil else result = nil end end result end |