Class: Block
Instance Attribute Summary
Attributes inherited from DataType
Instance Method Summary collapse
- #call(passed, scope) ⇒ Object
-
#initialize(body) ⇒ Block
constructor
A new instance of Block.
Constructor Details
#initialize(body) ⇒ Block
Returns a new instance of Block.
642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 |
# File 'lib/sdx/vm/datatypes.rb', line 642 def initialize(body) @internal = body @fields = { "__call" => (NativeFnInternal.new (Proc.new do |args, scope| call args, scope end)), "__arity" => (Int.new 1), "__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 Method Details
#call(passed, scope) ⇒ Object
659 660 661 662 663 664 665 666 667 668 |
# File 'lib/sdx/vm/datatypes.rb', line 659 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 vm.global.add_var "_", passed[0] vm.interpret vm.stack[-1] end |