Class: Nydp::Builtin::RubyWrap::Coder

Inherits:
Struct show all
Defined in:
lib/nydp/builtin/ruby_wrap.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Struct

#_nydp_procs, #_nydp_whitelist

Methods included from AutoWrap

#_nydp_get, #_nydp_ok?, #_nydp_procify?, #_nydp_safe_send, #_nydp_wrapper

Instance Attribute Details

#codeObject

Returns the value of attribute code

Returns:

  • (Object)

    the current value of code



8
9
10
# File 'lib/nydp/builtin/ruby_wrap.rb', line 8

def code
  @code
end

#helpersObject

Returns the value of attribute helpers

Returns:

  • (Object)

    the current value of helpers



8
9
10
# File 'lib/nydp/builtin/ruby_wrap.rb', line 8

def helpers
  @helpers
end

#nameObject

Returns the value of attribute name

Returns:

  • (Object)

    the current value of name



8
9
10
# File 'lib/nydp/builtin/ruby_wrap.rb', line 8

def name
  @name
end

#sizeObject

Returns the value of attribute size

Returns:

  • (Object)

    the current value of size



8
9
10
# File 'lib/nydp/builtin/ruby_wrap.rb', line 8

def size
  @size
end

Instance Method Details

#arg_mapperObject



11
12
13
14
15
16
17
18
19
20
21
# File 'lib/nydp/builtin/ruby_wrap.rb', line 11

def arg_mapper
  case size
  when 0 ; ""
  when 1 ; ", a0"
  when 2 ; ", a0, a1"
  when 3 ; ", a0, a1, a2"
  when 4 ; ", a0, a1, a2, a3"
  when 5 ; ", a0, a1, a2, a3, a4"
  else   ; raise "maximum 5 arguments!"
  end
end

#msizeObject



9
# File 'lib/nydp/builtin/ruby_wrap.rb', line 9

def msize ; size + 1 ; end

#to_rubyObject



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/nydp/builtin/ruby_wrap.rb', line 23

def to_ruby
  generic_code = code.
                   gsub(/a0/, "args.car").
                   gsub(/a1/, "args.cdr.car").
                   gsub(/a2/, "args.cdr.cdr.car").
                   gsub(/a3/, "args.cdr.cdr.cdr.car").
                   gsub(/a4/, "args.cdr.cdr.cdr.cdr.car")
  <<CODE
class #{name}
  include Nydp::Builtin::Base, Singleton#{helpers}

  def builtin_invoke_#{msize} vm#{ arg_mapper }
vm.push_arg(#{code})
  end

  def builtin_invoke vm, args
vm.push_arg(#{generic_code})
  end
end
CODE
end