Added spec for Kernel#eval with binding from method defined by #eval.
[rbx.git] / stdlib / ext / dl / mkcall.rb
blob6a855701521708c0fa9464053ed0000ca169c9d2
1 # -*- ruby -*-
3 require 'mkmf'
4 $:.unshift File.dirname(__FILE__)
5 require 'type'
6 require 'dlconfig'
8 def output_arg(x,i)
9   "args[#{i}].#{DLTYPE[x][:stmem]}"
10 end
12 def output_args(types)
13   t = []
14   types[1..-1].each_with_index{|x,i| t.push(output_arg(x,i))}
15   t.join(",")
16 end
18 def output_callfunc(types)
19   t = types[0]
20   stmem = DLTYPE[t][:stmem]
21   ctypes = types2ctypes(types)
22   if( t == VOID )
23     callstm = "(*f)(#{output_args(types)})"
24   else
25     callstm = "ret.#{stmem} = (*f)(#{output_args(types)})"
26   end
27   [ "{",
28     "#{ctypes[0]} (*f)(#{ctypes[1..-1].join(',')}) = func;",
29     "#{callstm};",
30     "}"].join(" ")
31 end
33 def output_case(types)
34   num = types2num(types)
35   callfunc_stm = output_callfunc(types)
36 <<EOF
37   case #{num}:
38 #ifdef DEBUG
39     printf("#{callfunc_stm}\\n");
40 #endif
41     #{callfunc_stm};
42     break;
43 EOF
44 end
46 def rec_output(types = [VOID])
47   print output_case(types)
48   if( types.length <= MAX_ARG )
49     DLTYPE.keys.sort.each{|t|
50       if( t != VOID && DLTYPE[t][:sym] )
51         rec_output(types + [t])
52       end
53     }
54   end
55 end
57 DLTYPE.keys.sort.each{|t|
58   if( DLTYPE[t][:sym] )
59     $stderr.printf("  #{DLTYPE[t][:ctype]}\n")
60     rec_output([t])
61   end