Class: Keisan::AST::FunctionAssignment
- Inherits:
-
Object
- Object
- Keisan::AST::FunctionAssignment
- Defined in:
- lib/keisan/ast/function_assignment.rb
Instance Attribute Summary collapse
-
#context ⇒ Object
readonly
Returns the value of attribute context.
-
#lhs ⇒ Object
readonly
Returns the value of attribute lhs.
-
#local ⇒ Object
readonly
Returns the value of attribute local.
-
#rhs ⇒ Object
readonly
Returns the value of attribute rhs.
Instance Method Summary collapse
- #argument_names ⇒ Object
- #evaluate ⇒ Object
- #expression_function ⇒ Object
-
#initialize(context, lhs, rhs, local) ⇒ FunctionAssignment
constructor
A new instance of FunctionAssignment.
Constructor Details
#initialize(context, lhs, rhs, local) ⇒ FunctionAssignment
Returns a new instance of FunctionAssignment.
6 7 8 9 10 11 12 13 14 15 |
# File 'lib/keisan/ast/function_assignment.rb', line 6 def initialize(context, lhs, rhs, local) @context = context @lhs = lhs @rhs = rhs @local = local unless lhs.children.all? {|arg| arg.is_a?(Variable)} raise Exceptions::InvalidExpression.new("Left hand side function must have variables as arguments") end end |
Instance Attribute Details
#context ⇒ Object (readonly)
Returns the value of attribute context.
4 5 6 |
# File 'lib/keisan/ast/function_assignment.rb', line 4 def context @context end |
#lhs ⇒ Object (readonly)
Returns the value of attribute lhs.
4 5 6 |
# File 'lib/keisan/ast/function_assignment.rb', line 4 def lhs @lhs end |
#local ⇒ Object (readonly)
Returns the value of attribute local.
4 5 6 |
# File 'lib/keisan/ast/function_assignment.rb', line 4 def local @local end |
#rhs ⇒ Object (readonly)
Returns the value of attribute rhs.
4 5 6 |
# File 'lib/keisan/ast/function_assignment.rb', line 4 def rhs @rhs end |
Instance Method Details
#argument_names ⇒ Object
17 18 19 |
# File 'lib/keisan/ast/function_assignment.rb', line 17 def argument_names @argument_names ||= lhs.children.map(&:name) end |
#evaluate ⇒ Object
30 31 32 33 34 35 |
# File 'lib/keisan/ast/function_assignment.rb', line 30 def evaluate # Blocks might have local variable/function definitions, so skip check verify_rhs_of_function_assignment_is_valid! context.register_function!(lhs.name, expression_function, local: local) rhs end |
#expression_function ⇒ Object
21 22 23 24 25 26 27 28 |
# File 'lib/keisan/ast/function_assignment.rb', line 21 def expression_function Functions::ExpressionFunction.new( lhs.name, argument_names, rhs.evaluate_assignments(context.spawn_child(shadowed: argument_names, transient: true)), context.transient_definitions ) end |