~ubuntu-branches/ubuntu/hardy/ruby1.8/hardy-updates

« back to all changes in this revision

Viewing changes to ext/dl/mkcall.rb

  • Committer: Bazaar Package Importer
  • Author(s): akira yamada
  • Date: 2007-03-13 22:11:58 UTC
  • mfrom: (1.1.5 upstream)
  • Revision ID: james.westby@ubuntu.com-20070313221158-h3oql37brlaf2go2
Tags: 1.8.6-1
* new upstream version, 1.8.6.
* libruby1.8 conflicts with libopenssl-ruby1.8 (< 1.8.6) (closes: #410018)
* changed packaging style to cdbs from dbs.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- ruby -*-
 
2
 
 
3
require 'mkmf'
 
4
$:.unshift File.dirname(__FILE__)
 
5
require 'type'
 
6
require 'dlconfig'
 
7
 
 
8
def output_arg(x,i)
 
9
  "args[#{i}].#{DLTYPE[x][:stmem]}"
 
10
end
 
11
 
 
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
 
17
 
 
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
 
32
 
 
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
 
45
 
 
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
 
56
 
 
57
DLTYPE.keys.sort.each{|t|
 
58
  if( DLTYPE[t][:sym] )
 
59
    $stderr.printf("  #{DLTYPE[t][:ctype]}\n")
 
60
    rec_output([t])
 
61
  end
 
62
}