class Obj

Attributes

args[R]

Public Class Methods

new(args, body) click to toggle source
# File lib/sdx/vm/datatypes.rb, line 674
def initialize(args, body)
    @args = args
    @internal = body

    @fields = {
        "__new" => (NativeFnInternal.new (Proc.new do |args, scope|
            _new 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

Public Instance Methods

_new(passed, scope) click to toggle source
# File lib/sdx/vm/datatypes.rb, line 692
def _new(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.global
end