Skip to content
This repository
tag: 1.6.5
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 84 lines (66 sloc) 1.883 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
require 'erb'

SRC_DIR = "src"
MAX_ARITY = 10

TEMPLATES = %w[
org/jruby/internal/runtime/methods/DynamicMethod
org/jruby/internal/runtime/methods/DefaultMethod
org/jruby/internal/runtime/methods/InterpretedMethod
org/jruby/ast/ArgsNode
org/jruby/runtime/DynamicScope
org/jruby/runtime/Block
org/jruby/runtime/BlockBody
org/jruby/runtime/NullBlockBody
]

GENERATED_WARNING = "
////////////////////////////////////////////////////////////////////////////////
// NOTE: THIS FILE IS GENERATED! DO NOT EDIT THIS FILE!
// generated from: <%= file_src %>
// using arities: <%= arities_src %>
////////////////////////////////////////////////////////////////////////////////
"

def n_args_in(n)
  ", " + n_args_in_bare(n) if n > 0
end

def n_args_in_bare(n)
  n_args_array(n, "IRubyObject ")
end

def n_args_out(n)
  ", " + n_args_out_bare(n) if n > 0
end

def n_args_out_bare(n)
  n_args_array(n)
end

def n_args_ary(n)
  ", " + n_args_ary_bare(n)
end

def n_args_ary_bare(n)
  return "IRubyObject.NULL_ARRAY" if n == 0

  "new IRubyObject[] {#{n_args_array(n)}}"
end

def n_args_array(n, arg_prefix="")
  (0..(n-1)).to_a.map { |i| "#{arg_prefix}arg#{i}" }.join(", ")
end

def generate(file_src, arities_src)
  file_template = ERB.new(File.read(file_src))
  file_template.filename = file_src
  arities_template = ERB.new(File.read(arities_src))
  arities_template.filename = arities_src
  arity_range = 0..MAX_ARITY
  generated_arities = ""

  for arity in arity_range do
    generated_arities << arities_template.result(binding)
  end

  generated_warning = ERB.new(GENERATED_WARNING).result(binding)

  file_template.result(binding)
end

def generate_all
  TEMPLATES.map do |name|
    name = "#{SRC_DIR}/" + name
    File.open(name +".java", 'w') do |f|
      f.write(generate(name + ".erb", name + ".arities.erb"))
    end
  end
end

if $0 == __FILE__
  generate_all
end
Something went wrong with that request. Please try again.