Class: Nydp::Builtin::TypeOf

Inherits:
Object
  • Object
show all
Includes:
Base, Singleton
Defined in:
lib/nydp/builtin/type_of.rb

Instance Method Summary collapse

Methods included from Base

#builtin_invoke_2, #builtin_invoke_3, #builtin_invoke_4, #handle_error, #inspect, #invoke, #invoke_1, #invoke_2, #invoke_3, #invoke_4, #name, #nydp_type, #to_s

Methods included from Helper

#cons, #list, #literal?, #pair?, #sig, #sym, #sym?

Methods included from Converter

#n2r, #r2n

Instance Method Details

#builtin_invoke(vm, args) ⇒ Object



18
19
20
# File 'lib/nydp/builtin/type_of.rb', line 18

def builtin_invoke vm, args
  builtin_invoke_1 vm, args.car
end

#builtin_invoke_1(vm, a0) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/nydp/builtin/type_of.rb', line 4

def builtin_invoke_1 vm, a0
  typename = if a0.respond_to?(:nydp_type)
               a0.nydp_type.to_sym
             elsif a0.is_a? Numeric
               :number
             else
               "ruby/#{a0.class.name}".to_sym
             end

  type = Nydp::Symbol.mk(typename, vm.ns)

  vm.push_arg(type || Nydp::NIL)
end