File: mkcall.rb

# mkcall.rb

Path: | dl/mkcall.rb
Last Update: | Fri Nov 08 02:42:07 AUS Eastern Daylight Time 2002

-*- ruby -*-

### Required files

mkmf type dlconfig

### Methods

output_arg output_args output_callfunc output_case rec_output

### Public Instance methods

output_arg(x,i)

[Source]

    # File dl/mkcall.rb, line 8
    def output_arg(x,i)
      "args[#{i}].#{DLTYPE[x][:stmem]}"
    end

output_args(types)

[Source]

    # File dl/mkcall.rb, line 12
    def output_args(types)
      t = []
      types[1..-1].each_with_index{|x,i| t.push(output_arg(x,i))}
      t.join(",")
    end

output_callfunc(types)

[Source]

    # File dl/mkcall.rb, line 18
    def output_callfunc(types)
      t = types[0]
      stmem = DLTYPE[t][:stmem]
      ctypes = types2ctypes(types)
      if( t == VOID )
        callstm = "(*f)(#{output_args(types)})"
      else
        callstm = "ret.#{stmem} = (*f)(#{output_args(types)})"
      end
      [ "{",
        "#{ctypes[0]} (*f)(#{ctypes[1..-1].join(',')}) = func;",
        "#{callstm};",
        "}"].join(" ")
    end

output_case(types)

[Source]

    # File dl/mkcall.rb, line 33
    def output_case(types)
      num = types2num(types)
      callfunc_stm = output_callfunc(types)
    "  case \#{num}:\n#ifdef DEBUG\n    printf(\"\#{callfunc_stm}\\\\n\");\n#endif\n    \#{callfunc_stm};\n    break;\n"
    end

rec_output(types = [VOID])

[Source]

    # File dl/mkcall.rb, line 47
    def rec_output(types = [VOID])
      print output_case(types)
      if( types.length <= MAX_ARG )
        DLTYPE.keys.sort.each{|t|
          if( t != VOID && DLTYPE[t][:sym] )
            rec_output(types + [t])
          end
        }
      end
    end

[Validate]