Class: Function
Instance Attribute Summary collapse
-
#args ⇒ Object
readonly
Returns the value of attribute args.
Attributes inherited from DataType
Instance Method Summary collapse
- #call(passed, scope) ⇒ Object
-
#initialize(args, body) ⇒ Function
constructor
A new instance of Function.
Constructor Details
#initialize(args, body) ⇒ Function
Returns a new instance of Function.
609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 |
# File 'lib/sdx/vm/datatypes.rb', line 609 def initialize(args, body) @args = args @internal = body @fields = { "__call" => (NativeFnInternal.new (lambda do |args, scope| call args, scope end)), "__arity" => (Int.new args.size), "__eq" => (NativeFnInternal.new (lambda do |other| Bool.new @internal == other[0].internal end)), "__neq" => (NativeFnInternal.new (lambda do |other| Bool.new @internal != other[0].internal end)) } end |
Instance Attribute Details
#args ⇒ Object (readonly)
Returns the value of attribute args.
607 608 609 |
# File 'lib/sdx/vm/datatypes.rb', line 607 def args @args end |
Instance Method Details
#call(passed, scope) ⇒ Object
627 628 629 630 631 632 633 634 635 636 637 638 |
# File 'lib/sdx/vm/datatypes.rb', line 627 def call(passed, scope) passed.reverse! vm = VM.new StringIO.new @internal scope.variables.each do |k| vm.global.add_var k[0], (scope.get_var k[0]) end args.each_with_index do |arg, i| vm.global.add_var arg, passed[i] end vm.interpret vm.stack[-1] end |