Class: Block

Inherits:
DataType show all
Defined in:
lib/sdx/vm/datatypes.rb

Instance Attribute Summary

Attributes inherited from DataType

#fields, #internal

Instance Method Summary collapse

Constructor Details

#initialize(body) ⇒ Block

Returns a new instance of Block.



480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
# File 'lib/sdx/vm/datatypes.rb', line 480

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



497
498
499
500
501
502
503
504
505
506
# File 'lib/sdx/vm/datatypes.rb', line 497

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