Class: Stone::AST::Lambda
- Inherits:
-
Expression
- Object
- Stone::AST
- Expression
- Stone::AST::Lambda
- Defined in:
- lib/stone/ast/lambda.rb
Class Attribute Summary collapse
-
.lambda_count ⇒ Object
Returns the value of attribute lambda_count.
Instance Attribute Summary collapse
-
#block ⇒ Object
readonly
Returns the value of attribute block.
-
#parameters ⇒ Object
readonly
Returns the value of attribute parameters.
Attributes inherited from Stone::AST
Instance Method Summary collapse
-
#initialize(parameters, statements) ⇒ Lambda
constructor
A new instance of Lambda.
- #to_llir(_builder, mod, scope = Stone::Scope.top_level) ⇒ Object
- #to_s ⇒ Object
- #type(context = nil) ⇒ Object
Constructor Details
#initialize(parameters, statements) ⇒ Lambda
18 19 20 21 22 23 |
# File 'lib/stone/ast/lambda.rb', line 18 def initialize(parameters, statements) @name = :lambda @parameters = parameters @block = Block.new(statements) @lambda_id = next_lambda_id end |
Class Attribute Details
.lambda_count ⇒ Object
Returns the value of attribute lambda_count.
13 14 15 |
# File 'lib/stone/ast/lambda.rb', line 13 def lambda_count @lambda_count end |
Instance Attribute Details
#block ⇒ Object (readonly)
Returns the value of attribute block.
10 11 12 |
# File 'lib/stone/ast/lambda.rb', line 10 def block @block end |
#parameters ⇒ Object (readonly)
Returns the value of attribute parameters.
10 11 12 |
# File 'lib/stone/ast/lambda.rb', line 10 def parameters @parameters end |
Instance Method Details
#to_llir(_builder, mod, scope = Stone::Scope.top_level) ⇒ Object
25 26 27 28 |
# File 'lib/stone/ast/lambda.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 lambda). mod.functions[function_name] || create_function(mod, function_name, function_type, scope) end |
#to_s ⇒ Object
30 31 32 |
# File 'lib/stone/ast/lambda.rb', line 30 def to_s "λ(#{parameters.join(', ')}) { #{block.statements.join("\n")} }" end |
#type(context = nil) ⇒ Object
34 35 36 37 38 |
# File 'lib/stone/ast/lambda.rb', line 34 def type(context = nil) return_type = @block.type(context) || Stone::Type::Int param_types = parameters.map { Stone::Type::Int } Stone::Type.function(param_types:, return_type:) end |