ext/dl/mkcall.rb


DEFINITIONS

This source file includes following functions.


   1  # -*- ruby -*-
   2  
   3  require 'mkmf'
   4  $:.unshift File.dirname(__FILE__)
   5  require 'type'
   6  require 'dlconfig'
   7  
   8  $int_eq_long = try_run(<<EOF)
   9  int main() {
  10    return sizeof(int) == sizeof(long) ? 0 : 1;
  11  }
  12  EOF
  13  
  14  def output_arg(x,i)
  15    "args[#{i}].#{DLTYPE[x][:stmem]}"
  16  end
  17  
  18  def output_args(types)
  19    t = []
  20    types[1..-1].each_with_index{|x,i| t.push(output_arg(x,i))}
  21    t.join(",")
  22  end
  23  
  24  def output_callfunc(types)
  25    t = types[0]
  26    stmem = DLTYPE[t][:stmem]
  27    ctypes = types2ctypes(types)
  28    if( t == VOID )
  29      callstm = "(*f)(#{output_args(types)})"
  30    else
  31      callstm = "ret.#{stmem} = (*f)(#{output_args(types)})"
  32    end
  33    [ "{",
  34      "#{ctypes[0]} (*f)(#{ctypes[1..-1].join(',')}) = func;",
  35      "#{callstm};",
  36      "}"].join(" ")
  37  end
  38  
  39  def output_case(types)
  40    num = types2num(types)
  41    callfunc_stm = output_callfunc(types)
  42  <<EOF
  43    case #{num}:
  44  #ifdef DEBUG
  45      printf("#{callfunc_stm}\\n");
  46  #endif
  47      #{callfunc_stm};
  48      break;
  49  EOF
  50  end
  51  
  52  def rec_output(types = [VOID])
  53    print output_case(types)
  54    if( types.length <= MAX_ARG )
  55      DLTYPE.keys.sort.each{|t|
  56        if( t != VOID && DLTYPE[t][:sym] )
  57          rec_output(types + [t])
  58        end
  59      }
  60    end
  61  end
  62  
  63  DLTYPE.keys.sort.each{|t|
  64    if( DLTYPE[t][:sym] )
  65      $stderr.printf("  #{DLTYPE[t][:ctype]}\n")
  66      rec_output([t])
  67    end
  68  }