summaryrefslogtreecommitdiff
path: root/template
diff options
context:
space:
mode:
Diffstat (limited to 'template')
-rw-r--r--template/Doxyfile.tmpl265
-rw-r--r--template/GNUmakefile.in5
-rw-r--r--template/configure-ext.mk.tmpl44
-rw-r--r--template/encdb.h.tmpl92
-rw-r--r--template/extinit.c.tmpl17
-rw-r--r--template/exts.mk.tmpl148
-rw-r--r--template/fake.rb.in40
-rw-r--r--template/id.c.tmpl43
-rw-r--r--template/id.h.tmpl97
-rw-r--r--template/insns.inc.tmpl24
-rw-r--r--template/insns_info.inc.tmpl109
-rw-r--r--template/known_errors.inc.tmpl14
-rw-r--r--template/limits.c.tmpl97
-rw-r--r--template/minsns.inc.tmpl14
-rw-r--r--template/opt_sc.inc.tmpl35
-rw-r--r--template/optinsn.inc.tmpl78
-rw-r--r--template/optunifs.inc.tmpl67
-rw-r--r--template/prelude.c.tmpl238
-rw-r--r--template/ruby-runner.h.in7
-rw-r--r--template/ruby.pc.in58
-rw-r--r--template/sizes.c.tmpl54
-rw-r--r--template/transdb.h.tmpl59
-rw-r--r--template/unicode_norm_gen.tmpl220
-rw-r--r--template/verconf.h.tmpl63
-rw-r--r--template/vm.inc.tmpl33
-rw-r--r--template/vmtc.inc.tmpl21
-rw-r--r--template/yarvarch.en7
-rw-r--r--template/yarvarch.ja454
-rw-r--r--template/yasmdata.rb.tmpl20
29 files changed, 2423 insertions, 0 deletions
diff --git a/template/Doxyfile.tmpl b/template/Doxyfile.tmpl
new file mode 100644
index 0000000000..0361c48bdd
--- /dev/null
+++ b/template/Doxyfile.tmpl
@@ -0,0 +1,265 @@
+# Doxyfile 1.5.7
+<%
+srcdir = miniruby = nil
+opt = OptionParser.new do |o|
+ o.on('--srcdir=SRCDIR') {|v| srcdir = v}
+ o.on('--miniruby=MINIRUBY') {|v| miniruby = v}
+ o.order!(ARGV)
+end
+srcdir ||= File.dirname(File.dirname(__FILE__))
+load 'rbconfig.rb'
+unless miniruby
+ miniruby = './miniruby$(EXEEXT) -I$(srcdir)/lib -I$(EXTOUT)/common -I./-'
+ RbConfig.expand(miniruby, RbConfig::CONFIG.merge("srcdir"=>srcdir))
+end
+dot = RbConfig::CONFIG['DOT'] || ""
+have_dot = dot.empty? ? "NO" : "YES"
+%>
+#---------------------------------------------------------------------------
+# Project related configuration options
+#---------------------------------------------------------------------------
+PROJECT_NAME = Ruby
+PROJECT_NUMBER = <%=RUBY_VERSION%><%= RUBY_PATCHLEVEL < 0 ? 'dev' : "p#{RUBY_PATCHLEVEL}" %> (<%=RUBY_RELEASE_DATE%> revision <%=RUBY_REVISION%>)
+STRIP_FROM_PATH = <%=srcdir%>
+FILE_VERSION_FILTER = "<%=miniruby%> <%=srcdir%>/tool/file2lastrev.rb -q"
+INPUT = <%=srcdir%> .
+INPUT_FILTER = "<%=miniruby%> <%=srcdir%>/tool/strip-rdoc.rb"
+
+DOXYFILE_ENCODING = UTF-8
+OUTPUT_DIRECTORY = doc/capi
+CREATE_SUBDIRS = YES
+OUTPUT_LANGUAGE = English
+BRIEF_MEMBER_DESC = YES
+REPEAT_BRIEF = YES
+ABBREVIATE_BRIEF =
+ALWAYS_DETAILED_SEC = YES
+INLINE_INHERITED_MEMB = NO
+FULL_PATH_NAMES = YES
+STRIP_FROM_INC_PATH =
+SHORT_NAMES = NO
+JAVADOC_AUTOBRIEF = YES
+QT_AUTOBRIEF = YES
+MULTILINE_CPP_IS_BRIEF = NO
+INHERIT_DOCS = YES
+SEPARATE_MEMBER_PAGES = NO
+TAB_SIZE = 8
+ALIASES =
+OPTIMIZE_OUTPUT_FOR_C = YES
+OPTIMIZE_OUTPUT_JAVA = NO
+OPTIMIZE_FOR_FORTRAN = NO
+OPTIMIZE_OUTPUT_VHDL = NO
+BUILTIN_STL_SUPPORT = NO
+CPP_CLI_SUPPORT = NO
+SIP_SUPPORT = NO
+IDL_PROPERTY_SUPPORT = NO
+DISTRIBUTE_GROUP_DOC = NO
+SUBGROUPING = YES
+TYPEDEF_HIDES_STRUCT = NO
+SYMBOL_CACHE_SIZE = 0
+#---------------------------------------------------------------------------
+# Build related configuration options
+#---------------------------------------------------------------------------
+EXTRACT_ALL = YES
+EXTRACT_PRIVATE = NO
+EXTRACT_STATIC = NO
+EXTRACT_LOCAL_CLASSES = YES
+EXTRACT_LOCAL_METHODS = NO
+EXTRACT_ANON_NSPACES = NO
+HIDE_UNDOC_MEMBERS = NO
+HIDE_UNDOC_CLASSES = NO
+HIDE_FRIEND_COMPOUNDS = NO
+HIDE_IN_BODY_DOCS = YES
+INTERNAL_DOCS = NO
+CASE_SENSE_NAMES = NO
+HIDE_SCOPE_NAMES = NO
+SHOW_INCLUDE_FILES = YES
+INLINE_INFO = YES
+SORT_MEMBER_DOCS = YES
+SORT_BRIEF_DOCS = NO
+SORT_GROUP_NAMES = NO
+SORT_BY_SCOPE_NAME = NO
+GENERATE_TODOLIST = YES
+GENERATE_TESTLIST = YES
+GENERATE_BUGLIST = YES
+GENERATE_DEPRECATEDLIST= YES
+ENABLED_SECTIONS =
+MAX_INITIALIZER_LINES = 30
+SHOW_USED_FILES = YES
+SHOW_FILES = YES
+SHOW_NAMESPACES = YES
+LAYOUT_FILE =
+#---------------------------------------------------------------------------
+# configuration options related to warning and progress messages
+#---------------------------------------------------------------------------
+QUIET = NO
+WARNINGS = YES
+WARN_IF_UNDOCUMENTED = YES
+WARN_IF_DOC_ERROR = YES
+WARN_NO_PARAMDOC = NO
+WARN_FORMAT = "$file:$line: $text"
+WARN_LOGFILE =
+#---------------------------------------------------------------------------
+# configuration options related to the input files
+#---------------------------------------------------------------------------
+INPUT_ENCODING = UTF-8
+FILE_PATTERNS = *.c *.h *.y *.def
+RECURSIVE = YES
+EXCLUDE = <%=srcdir%>/ext/dl/callback <%=srcdir%>/ccan <%=srcdir%>/ext/psych/yaml
+EXCLUDE_SYMLINKS = YES
+EXCLUDE_PATTERNS = *.src doc enc build */ext/-test-/* tmp test yarvtest lib bootstraptest spec .ext .git .svn extconf.h *prelude.c encdb.h transdb.h insns.def
+EXCLUDE_SYMBOLS =
+EXAMPLE_PATH =
+EXAMPLE_PATTERNS =
+EXAMPLE_RECURSIVE = NO
+IMAGE_PATH = <%=srcdir%>/doc/images
+FILTER_PATTERNS =
+FILTER_SOURCE_FILES = YES
+#---------------------------------------------------------------------------
+# configuration options related to source browsing
+#---------------------------------------------------------------------------
+SOURCE_BROWSER = YES
+INLINE_SOURCES = NO
+STRIP_CODE_COMMENTS = YES
+REFERENCED_BY_RELATION = YES
+REFERENCES_RELATION = YES
+REFERENCES_LINK_SOURCE = YES
+USE_HTAGS = NO
+VERBATIM_HEADERS = YES
+#---------------------------------------------------------------------------
+# configuration options related to the alphabetical class index
+#---------------------------------------------------------------------------
+COLS_IN_ALPHA_INDEX = 5
+IGNORE_PREFIX =
+#---------------------------------------------------------------------------
+# configuration options related to the HTML output
+#---------------------------------------------------------------------------
+GENERATE_HTML = YES
+HTML_OUTPUT = html
+HTML_FILE_EXTENSION = .html
+HTML_HEADER =
+HTML_FOOTER =
+HTML_STYLESHEET =
+HTML_DYNAMIC_SECTIONS = NO
+GENERATE_DOCSET = NO
+DOCSET_FEEDNAME = "Doxygen generated docs"
+DOCSET_BUNDLE_ID = org.doxygen.Project
+GENERATE_HTMLHELP = NO
+CHM_FILE =
+HHC_LOCATION =
+GENERATE_CHI = NO
+CHM_INDEX_ENCODING =
+BINARY_TOC = NO
+TOC_EXPAND = NO
+GENERATE_QHP = NO
+QCH_FILE =
+QHP_NAMESPACE = org.doxygen.Project
+QHP_VIRTUAL_FOLDER = doc
+QHG_LOCATION =
+DISABLE_INDEX = NO
+ENUM_VALUES_PER_LINE = 4
+GENERATE_TREEVIEW = NO
+TREEVIEW_WIDTH = 250
+FORMULA_FONTSIZE = 10
+#---------------------------------------------------------------------------
+# configuration options related to the LaTeX output
+#---------------------------------------------------------------------------
+GENERATE_LATEX = NO
+LATEX_OUTPUT = latex
+LATEX_CMD_NAME = latex
+MAKEINDEX_CMD_NAME = makeindex
+COMPACT_LATEX = NO
+PAPER_TYPE = a4wide
+EXTRA_PACKAGES =
+LATEX_HEADER =
+PDF_HYPERLINKS = YES
+USE_PDFLATEX = YES
+LATEX_BATCHMODE = NO
+LATEX_HIDE_INDICES = NO
+#---------------------------------------------------------------------------
+# configuration options related to the RTF output
+#---------------------------------------------------------------------------
+GENERATE_RTF = NO
+RTF_OUTPUT = rtf
+COMPACT_RTF = NO
+RTF_HYPERLINKS = NO
+RTF_STYLESHEET_FILE =
+RTF_EXTENSIONS_FILE =
+#---------------------------------------------------------------------------
+# configuration options related to the man page output
+#---------------------------------------------------------------------------
+GENERATE_MAN = NO
+MAN_OUTPUT = man
+MAN_EXTENSION = .3
+MAN_LINKS = NO
+#---------------------------------------------------------------------------
+# configuration options related to the XML output
+#---------------------------------------------------------------------------
+GENERATE_XML = NO
+XML_OUTPUT = xml
+XML_SCHEMA =
+XML_DTD =
+XML_PROGRAMLISTING = YES
+#---------------------------------------------------------------------------
+# configuration options for the AutoGen Definitions output
+#---------------------------------------------------------------------------
+GENERATE_AUTOGEN_DEF = NO
+#---------------------------------------------------------------------------
+# configuration options related to the Perl module output
+#---------------------------------------------------------------------------
+GENERATE_PERLMOD = NO
+PERLMOD_LATEX = NO
+PERLMOD_PRETTY = YES
+PERLMOD_MAKEVAR_PREFIX =
+#---------------------------------------------------------------------------
+# Configuration options related to the preprocessor
+#---------------------------------------------------------------------------
+ENABLE_PREPROCESSING = YES
+MACRO_EXPANSION = NO
+EXPAND_ONLY_PREDEF = NO
+SEARCH_INCLUDES = YES
+INCLUDE_PATH = <%=srcdir%> <%=srcdir%>/include
+INCLUDE_FILE_PATTERNS =
+PREDEFINED =
+EXPAND_AS_DEFINED =
+SKIP_FUNCTION_MACROS = YES
+#---------------------------------------------------------------------------
+# Configuration::additions related to external references
+#---------------------------------------------------------------------------
+TAGFILES =
+GENERATE_TAGFILE =
+ALLEXTERNALS = NO
+EXTERNAL_GROUPS = YES
+PERL_PATH = /usr/bin/perl
+#---------------------------------------------------------------------------
+# Configuration options related to the dot tool
+#---------------------------------------------------------------------------
+CLASS_DIAGRAMS = NO
+MSCGEN_PATH =
+HIDE_UNDOC_RELATIONS = YES
+HAVE_DOT = <%= have_dot %>
+DOT_FONTNAME = FreeSans
+DOT_FONTPATH =
+CLASS_GRAPH = NO
+COLLABORATION_GRAPH = NO
+GROUP_GRAPHS = YES
+UML_LOOK = NO
+TEMPLATE_RELATIONS = NO
+INCLUDE_GRAPH = YES
+INCLUDED_BY_GRAPH = YES
+CALL_GRAPH = NO
+CALLER_GRAPH = NO
+GRAPHICAL_HIERARCHY = NO
+DIRECTORY_GRAPH = NO
+DOT_IMAGE_FORMAT = png
+DOT_PATH =
+DOTFILE_DIRS =
+DOT_GRAPH_MAX_NODES = 50
+MAX_DOT_GRAPH_DEPTH = 0
+DOT_TRANSPARENT = NO
+DOT_MULTI_TARGETS = NO
+GENERATE_LEGEND = YES
+DOT_CLEANUP = YES
+#---------------------------------------------------------------------------
+# Configuration::additions related to the search engine
+#---------------------------------------------------------------------------
+SEARCHENGINE = NO
diff --git a/template/GNUmakefile.in b/template/GNUmakefile.in
new file mode 100644
index 0000000000..c904d3474e
--- /dev/null
+++ b/template/GNUmakefile.in
@@ -0,0 +1,5 @@
+include Makefile
+-include uncommon.mk
+include $(srcdir)/defs/gmake.mk
+
+GNUmakefile: $(srcdir)/template/GNUmakefile.in
diff --git a/template/configure-ext.mk.tmpl b/template/configure-ext.mk.tmpl
new file mode 100644
index 0000000000..4f0d31d700
--- /dev/null
+++ b/template/configure-ext.mk.tmpl
@@ -0,0 +1,44 @@
+V = 0
+Q1 = $(V:1=)
+Q = $(Q1:0=@)
+ECHO1 = $(V:1=@:)
+ECHO = $(ECHO1:0=@echo)
+
+<%
+srcdir = miniruby = script_args = nil
+opt = OptionParser.new do |o|
+ o.on('--srcdir=SRCDIR') {|v| srcdir = v}
+ o.on('--miniruby=MINIRUBY') {|v| miniruby = v}
+ o.on('--script-args=MINIRUBY') {|v| script_args = v}
+ o.order!(ARGV)
+end
+srcdir ||= File.dirname(File.dirname(__FILE__))
+exts = {}
+[
+ ["exts", "ext", "--extstatic $(EXTSTATIC)"],
+ ["gems", "gems", "--no-extstatic"],
+].each do |t, d, o|
+ exts[t] = [o, Dir.glob("#{srcdir}/#{d}/*/").map {|n| n[(srcdir.size+1)..-2]}]
+end
+%>
+MINIRUBY = <%=miniruby%>
+SCRIPT_ARGS = <%=script_args%>
+EXTMK_ARGS = $(SCRIPT_ARGS) --gnumake=$(gnumake) --extflags="$(EXTLDFLAGS)" \
+ --make-flags='MINIRUBY=$(MINIRUBY)'
+
+all: exts gems
+exts:
+gems:
+
+% exts.each do |t, (o, dirs)|
+% dirs.each do |d|
+<%=t%>: <%=d%>/exts.mk
+<%=d%>/exts.mk: FORCE
+ $(Q)$(MINIRUBY) $(srcdir)/ext/extmk.rb --make='$(MAKE)' \
+ --command-output=$@ $(EXTMK_ARGS) <%=o%> \
+ -- configure $(@D)
+% end
+% end
+
+.PHONY: FORCE all exts gems
+FORCE:
diff --git a/template/encdb.h.tmpl b/template/encdb.h.tmpl
new file mode 100644
index 0000000000..9de29bebde
--- /dev/null
+++ b/template/encdb.h.tmpl
@@ -0,0 +1,92 @@
+<%
+#
+# OnigEncodingDefine(foo, Foo) = {
+# ..
+# "Shift_JIS", /* Canonical Name */
+# ..
+# };
+# ENC_ALIAS("SJIS", "Shift_JIS")
+# ENC_REPLICATE("Windows-31J", "Shift_JIS")
+# ENC_ALIAS("CP932", "Windows-31J")
+#
+
+def check_duplication(defs, name, fn, line)
+ if defs[name]
+ raise ArgumentError, "%s:%d: encoding %s is already registered(%s:%d)" %
+ [fn, line, name, *defs[name]]
+ else
+ defs[name.upcase] = [fn,line]
+ end
+end
+
+lines = []
+BUILTIN_ENCODINGS = {
+ 'ASCII-8BIT' => 0,
+ 'UTF-8' => 1,
+ 'US-ASCII' => 2,
+}
+encodings = %w[ASCII-8BIT UTF-8 US-ASCII] # BUILTIN_ENCODINGS.keys is not available on cross compiling and used ruby 1.8
+count = encodings.size
+defs = {}
+encdirs = ARGV.dup
+encdirs << 'enc' if encdirs.empty?
+files = {}
+encdirs.each do |encdir|
+ next unless File.directory?(encdir)
+ Dir.open(encdir) {|d| d.grep(/.+\.[ch]\z/)}.sort_by {|e|
+ e.scan(/(\d+)|(\D+)/).map {|n,a| a||[n.size,n.to_i]}.flatten
+ }.each do |fn|
+ next if files[fn]
+ files[fn] = true
+ open(File.join(encdir,fn)) do |f|
+ name = nil
+ f.each_line do |line|
+ if (/^#ifndef RUBY/ =~ line)..(/^#endif/ =~ line)
+ elsif (/^OnigEncodingDefine/ =~ line)..(/"(.*?)"/ =~ line)
+ if $1
+ if name
+ lines << %[ENC_SET_BASE("#$1", "#{name}");]
+ else
+ name = $1
+ end
+ check_duplication(defs, $1, fn, $.)
+ next if BUILTIN_ENCODINGS[name]
+ encodings << $1
+ count += 1
+ end
+ else
+ case line
+ when /^\s*rb_enc_register\(\s*"([^"]+)"/
+ count += 1
+ line = nil
+ encodings << $1
+ when /^ENC_REPLICATE\(\s*"([^"]+)"\s*,\s*"([^"]+)"/
+ raise ArgumentError,
+ '%s:%d: ENC_REPLICATE: %s is not defined yet. (replica %s)' %
+ [fn, $., $2, $1] unless defs[$2.upcase]
+ count += 1
+ when /^ENC_ALIAS\(\s*"([^"]+)"\s*,\s*"([^"]+)"/
+ raise ArgumentError,
+ '%s:%d: ENC_ALIAS: %s is not defined yet. (alias %s)' %
+ [fn, $., $2, $1] unless defs[$2.upcase]
+ when /^ENC_DUMMY\w*\(\s*"([^"]+)"/
+ count += 1
+ else
+ next
+ end
+ check_duplication(defs, $1, fn, $.)
+ lines << line.sub(/;.*/m, "").chomp + ";" if line
+ end
+ end
+ end
+ end
+end
+encodings.each_with_index do |e, i|
+%>ENC_DEFINE("<%=e%>");
+% end
+% encidx = encodings.size - 1
+% lines.each do |line|
+<%=line%>
+% end
+
+#define ENCODING_COUNT <%=count%>
diff --git a/template/extinit.c.tmpl b/template/extinit.c.tmpl
new file mode 100644
index 0000000000..7a9c910633
--- /dev/null
+++ b/template/extinit.c.tmpl
@@ -0,0 +1,17 @@
+%# -*- C -*-
+% extinits = ARGV.map {|n| [n[%r[[^/.]+(?=\.[^/]*)?\z]], n]}
+#include "ruby/ruby.h"
+
+#define init(func, name) { \
+ extern void func(void); \
+ ruby_init_ext(name".so", func); \
+}
+
+void ruby_init_ext(const char *name, void (*init)(void));
+
+void Init_ext(void)
+{
+% extinits.each do |f, n|
+ init(Init_<%=f%>, <%=n.dump%>);
+% end
+}
diff --git a/template/exts.mk.tmpl b/template/exts.mk.tmpl
new file mode 100644
index 0000000000..e35c28294e
--- /dev/null
+++ b/template/exts.mk.tmpl
@@ -0,0 +1,148 @@
+# -*- makefile -*-
+V = 0
+Q1 = $(V:1=)
+Q = $(Q1:0=@)
+ECHO1 = $(V:1=@:)
+ECHO = $(ECHO1:0=@echo)
+<%
+require './rbconfig'
+macros = {}
+deps = []
+notes = {}
+rubies = []
+exeext = RbConfig::CONFIG['EXEEXT']
+gnumake = false
+opt = OptionParser.new do |o|
+ o.on('--gnumake=BOOL') {|v| gnumake = v == 'yes'}
+ o.order!(ARGV)
+end
+contpat = /(?>(?>[^\\\n]|\\.)*\\\n)*(?>[^\\\n]|\\.)*/
+Dir.glob("{ext,gems}/*/exts.mk") do |e|
+ gem = /\Agems(?=\/)/ =~ e
+ s = File.read(e)
+ s.scan(/^(extensions|SUBMAKEOPTS|EXT[A-Z]+|MFLAGS|NOTE_[A-Z]+)[ \t]*=[ \t]*(#{contpat})$/o) do |n, v|
+ v.gsub!(/\\\n[ \t]*/, ' ')
+ next if v.empty?
+ next if gem and n != "extensions"
+ v = v.split
+ m = macros[n] ||= []
+ case n
+ when "LIBS"
+ m.concat(v)
+ else
+ macros[n] = m | v
+ end
+ end
+ if gem
+ r = ""
+ else
+ r = s[/^all static: (.+)$/, 1]
+ deps << $&
+ rubies |= r.split if r
+ r = "(?:#{Regexp.new(r)})|"
+ end
+ s.scan(%r"^(ext/\S+)/[^/\s:]+:[ \t]*\1/static$|
+ ^(?:#{r}
+ all|static|install(?:-(?:so|rb))?|
+ (?:dist|real)?clean
+ ):.+$
+ "x) do
+ deps << $&.sub(/ +note$/, '')
+ end
+ s.scan(%r"^(note(?:-\w+)?):(:)?[ \t]*(#{contpat})\n((?:\t.+\n)*)"o) do |(t, m, d, n)|
+ note = (notes[t] ||= [[m||""], []])
+ note[0] |= d.split(/(?:\\\n|[ \t])[ \t]*/)
+ n = n.split(/^/)
+ if m
+ note[1].concat(n)
+ else
+ note[1] |= n
+ end
+ end
+end
+deps.uniq!
+if objs = macros["EXTOBJS"] and objs.any? {|e|e.start_with?("ext/extinit.")}
+ objs.delete_if {|e|e.start_with?("dmyext.")}
+end
+macros.default = [].freeze
+class Array
+ def fold(h, w = 70)
+ return "" if empty?
+ w -= h
+ ret = [s = String.new]
+ each do |e|
+ if s.size + e.size + 1 > w
+ ret << (s = String.new)
+ end
+ s << " " << e
+ end
+ ret.join(" \\\n" + "\t" * (h / 8) + " " * (h % 8))
+ end
+end
+@erbout = _erbout
+def self.column
+ w = 0
+ @erbout[/^.*\z/].scan(/\t|([^\t]+)/) {|s,| w += (s ? s.size : 8 - w % 8)}
+ w
+end
+targets = %w[all static install install-so install-rb clean distclean realclean]
+objext = RbConfig::CONFIG["OBJEXT"]
+if gnumake
+ submake = "$(MAKE) -C $(@D)"
+else
+ submake = "cd $(@D) && "
+ exec = RbConfig::CONFIG["exec"] and !exec.empty? and submake << exec << " "
+ submake << "$(MAKE)"
+ mflags = " $(MFLAGS)"
+end
+-%>
+% macros.each_pair do |k, v|
+<%=k%> =<%= v.fold(column) %>
+% end
+% RbConfig::MAKEFILE_CONFIG.keys.grep(/RM/) do |k|
+<%=k%> = <%=RbConfig::MAKEFILE_CONFIG[k]%>
+% end
+
+all:
+static:
+
+clean:
+ -$(Q)$(RM) ext/extinit.<%= objext %>
+distclean:
+ -$(Q)$(RM) ext/extinit.c
+
+% deps.each do |d|
+<%= d %>
+% end
+
+% rubies.each do |ruby|
+<%= ruby %>:
+ $(Q)$(MAKE)<%=mflags%> $(SUBMAKEOPTS) $@
+% end
+% if rubies.size > 1
+<%= rubies[1..-1].join(' ')%>: <%= rubies[0] %>
+% end
+
+libencs:
+ $(Q)$(MAKE)<%=mflags%> -f enc.mk V=$(V) $@
+ext/extinit.<%=objext%>:
+ $(Q)$(MAKE)<%=mflags%> V=$(V) EXTINITS="$(EXTINITS)" $@
+
+% targets.product(macros["extensions"].map {|e|e.chomp("/.")}) do |t, e|
+<%=e%>/<%=t%>:
+% if /^(dist|real)clean$/ =~ t
+ $(ECHO) $(@F)ing $(@D)
+% end
+ $(Q)<%= submake %><%=mflags%> V=$(V) $(@F)
+% if /^(dist|real)clean$/ =~ t
+ $(Q)$(RMDIRS) $(@D)
+% end
+% end
+
+extso:
+ @echo EXTSO=$(EXTSO)
+
+% notes.each_pair do |k, (d, n)|
+<%= k %>:<%= d.join(' ') %>
+<%= n.join("") %>
+% end
diff --git a/template/fake.rb.in b/template/fake.rb.in
new file mode 100644
index 0000000000..5e95530c38
--- /dev/null
+++ b/template/fake.rb.in
@@ -0,0 +1,40 @@
+<%
+arg = {}
+while /\A(\w+)=(.*)/ =~ ARGV[0]
+ arg[$1] = $2
+ arg[$1].tr!(File::ALT_SEPARATOR, File::SEPARATOR) if File::ALT_SEPARATOR
+ ARGV.shift
+end
+if inc = arg['i']
+ src = inc == '-' ? STDIN.read : File.read(inc)
+ arg['versions'] = version = {}
+ File.read(File.join(arg['srcdir'], 'version.c')).
+ scan(/rb_define_global_const\("(RUBY_\w+)",[^;]*?\bMK(?:INT|STR)\(([^()]*)\)/m) do |n, v|
+ version[n] =
+ eval(src[/\bruby_#{v}(?:\[\])?\s*=\s*((?:"(?:\\.|[^\"\\])*"\s*)*(?=;)|[^{};]+)/m, 1].gsub(/#/, '\\#'))
+ end
+end
+%>baseruby="<%=arg['BASERUBY']%>"
+_\
+=begin
+_=
+ruby="${RUBY-$baseruby}"
+case "$ruby" in "echo "*) $ruby; exit $?;; esac
+case "$0" in /*) r=-r"$0";; *) r=-r"./$0";; esac
+exec $ruby "$r" "$@"
+=end
+=baseruby
+class Object
+ remove_const :CROSS_COMPILING if defined?(CROSS_COMPILING)
+ CROSS_COMPILING = RUBY_PLATFORM
+ constants.grep(/^RUBY_/) {|n| remove_const n}
+% arg['versions'].each {|n, v|
+ <%=n%> = <%=v.inspect%>
+% }
+end
+builddir = File.dirname(File.expand_path(__FILE__))
+srcdir = "<%=arg['srcdir']%>"
+top_srcdir = File.realpath(srcdir, builddir)
+fake = File.join(top_srcdir, "tool/fake.rb")
+eval(File.read(fake), nil, fake)
+ENV["RUBYOPT"] = ["-r#{__FILE__}", ENV["RUBYOPT"]].compact.join(" ")
diff --git a/template/id.c.tmpl b/template/id.c.tmpl
new file mode 100644
index 0000000000..477a76bc26
--- /dev/null
+++ b/template/id.c.tmpl
@@ -0,0 +1,43 @@
+%# -*- c -*-
+/* DO NOT EDIT THIS FILE DIRECTLY */
+/**********************************************************************
+
+ id.c -
+
+ $Author$
+ created at: Wed Dec 5 02:36:10 2012
+
+ Copyright (C) 2004-2007 Koichi Sasada
+
+**********************************************************************/
+<%
+defs = File.join(File.dirname(File.dirname(erb.filename)), "defs/id.def")
+ids = eval(File.read(defs), binding, defs)
+ops = ids[:token_op].uniq {|id, op, token| token && op}
+%>
+% ops.each do |_id, _op, token|
+% next unless token
+#define t<%=token%> RUBY_TOKEN(<%=token%>)
+% end
+
+static const struct {
+ unsigned short token;
+ const char name[3], term;
+} op_tbl[] = {
+% ops.each do |_id, op, token|
+% next unless token
+ {t<%=token%>, "<%=op%>"},
+% end
+};
+
+static void
+Init_id(void)
+{
+#undef rb_intern
+#define rb_intern(str) rb_intern_const(str)
+ rb_encoding *enc = rb_usascii_encoding();
+
+% ids[:predefined].each do |token, name|
+ REGISTER_SYMID(id<%=token%>, "<%=name%>");
+% end
+}
diff --git a/template/id.h.tmpl b/template/id.h.tmpl
new file mode 100644
index 0000000000..687cbbbe40
--- /dev/null
+++ b/template/id.h.tmpl
@@ -0,0 +1,97 @@
+%# -*- c -*-
+/* DO NOT EDIT THIS FILE DIRECTLY */
+/**********************************************************************
+
+ id.h -
+
+ $Author$
+ created at: Sun Oct 19 21:12:51 2008
+
+ Copyright (C) 2007 Koichi Sasada
+
+**********************************************************************/
+<%
+op_id_offset = 128
+
+defs = File.join(File.dirname(File.dirname(erb.filename)), "defs/id.def")
+ids = eval(File.read(defs), binding, defs)
+types = ids.keys.grep(/^[A-Z]/)
+%>
+#ifndef RUBY_ID_H
+#define RUBY_ID_H
+
+enum ruby_id_types {
+ RUBY_ID_STATIC_SYM = 0x01,
+ RUBY_ID_LOCAL = 0x00,
+ RUBY_ID_INSTANCE = (0x01<<1),
+ RUBY_ID_GLOBAL = (0x03<<1),
+ RUBY_ID_ATTRSET = (0x04<<1),
+ RUBY_ID_CONST = (0x05<<1),
+ RUBY_ID_CLASS = (0x06<<1),
+ RUBY_ID_JUNK = (0x07<<1),
+ RUBY_ID_INTERNAL = RUBY_ID_JUNK,
+ RUBY_ID_SCOPE_SHIFT = 4,
+ RUBY_ID_SCOPE_MASK = (~(~0U<<(RUBY_ID_SCOPE_SHIFT-1))<<1)
+};
+
+#define ID_STATIC_SYM RUBY_ID_STATIC_SYM
+#define ID_SCOPE_SHIFT RUBY_ID_SCOPE_SHIFT
+#define ID_SCOPE_MASK RUBY_ID_SCOPE_MASK
+#define ID_LOCAL RUBY_ID_LOCAL
+#define ID_INSTANCE RUBY_ID_INSTANCE
+#define ID_GLOBAL RUBY_ID_GLOBAL
+#define ID_ATTRSET RUBY_ID_ATTRSET
+#define ID_CONST RUBY_ID_CONST
+#define ID_CLASS RUBY_ID_CLASS
+#define ID_JUNK RUBY_ID_JUNK
+#define ID_INTERNAL RUBY_ID_INTERNAL
+
+#define symIFUNC ID2SYM(idIFUNC)
+#define symCFUNC ID2SYM(idCFUNC)
+
+% index = op_id_offset
+% ids[:token_op].each do |_id, _op, token|
+% next unless token
+#define RUBY_TOKEN_<%=token%> <%=index%>
+% index += 1
+% end
+#define RUBY_TOKEN(t) RUBY_TOKEN_##t
+
+#define RUBY_TOKEN2ID_TYPE(tok, type) ((tok<<RUBY_ID_SCOPE_SHIFT)|type|RUBY_ID_STATIC_SYM)
+% types.each do |type|
+#define TOKEN2<%=type%>ID(tok) RUBY_TOKEN2ID_TYPE(tok, RUBY_ID_<%=type%>)
+% end
+
+enum ruby_method_ids {
+% ids[:token_op].uniq {|_, op| op}.each do |id, op, token|
+ id<%=id%> = <%=token ? "RUBY_TOKEN(#{token})" : "'#{op}'"%>,
+% end
+ tPRESERVED_ID_BEGIN = <%=index-1%>,
+% ids[:preserved].each do |token|
+ id<%=token%>,
+% end
+ tPRESERVED_ID_END,
+% prev = 'tPRESERVED_ID_END'
+% types.each do |type|
+% tokens = ids[type]
+ tTOKEN_<%=type%>_BEGIN = <%=prev%>-1,
+% tokens.each do |token|
+ t<%=token%>,
+% end
+% prev = "tTOKEN_#{type}_END"
+ <%=prev%>,
+% end
+ tNEXT_ID = <%=prev%>,
+% types.each do |type|
+% tokens = ids[type]
+#define DEFINE_<%=type%>ID_FROM_TOKEN(n) id##n = TOKEN2<%=type%>ID(t##n)
+% tokens or next
+% tokens.each do |token|
+ DEFINE_<%=type%>ID_FROM_TOKEN(<%=token%>),
+% end
+% end
+ tLAST_OP_ID = tPRESERVED_ID_END-1,
+ idLAST_OP_ID = tLAST_OP_ID >> ID_SCOPE_SHIFT
+};
+
+#endif /* RUBY_ID_H */
diff --git a/template/insns.inc.tmpl b/template/insns.inc.tmpl
new file mode 100644
index 0000000000..112732dce5
--- /dev/null
+++ b/template/insns.inc.tmpl
@@ -0,0 +1,24 @@
+/** -*-c-*-
+ This file contains YARV instructions list.
+
+ ----
+ This file is auto generated by insns2vm.rb
+ DO NOT TOUCH!
+
+ If you want to fix something, you must edit 'template/insns.inc.tmpl'
+ or tool/insns2vm.rb
+ */
+
+
+/* BIN : Basic Instruction Name */
+#define BIN(n) YARVINSN_##n
+
+enum ruby_vminsn_type {
+% @insns.each do |insn|
+ BIN(<%=insn.name%>),
+% end
+ VM_INSTRUCTION_SIZE
+};
+
+#define ASSERT_VM_INSTRUCTION_SIZE(array) \
+ STATIC_ASSERT(numberof_##array, numberof(array) == VM_INSTRUCTION_SIZE)
diff --git a/template/insns_info.inc.tmpl b/template/insns_info.inc.tmpl
new file mode 100644
index 0000000000..933eb5ae0e
--- /dev/null
+++ b/template/insns_info.inc.tmpl
@@ -0,0 +1,109 @@
+/** -*-c-*-
+ This file contains instruction information for yarv instruction sequence.
+
+ ----
+ This file is auto generated by insns2vm.rb
+ DO NOT TOUCH!
+
+ If you want to fix something, you must edit 'template/insns_info.inc.tmpl'
+ or tool/insns2vm.rb
+ */
+
+% TYPE_CHARS.each do |t, c|
+#define <%=t%> '<%=c%>'
+% end
+
+static const unsigned short insn_name_info_offset[] = {
+% insn_name_length = @insns.inject(0) do |ofs, insn|
+ <%= ofs %>,
+% ofs + insn.name.size + 1
+% end
+};
+
+ASSERT_VM_INSTRUCTION_SIZE(insn_name_info_offset);
+
+static const char insn_name_info_base[<%=insn_name_length%>] = ""
+% @insns.each do |insn|
+ "<%= insn.name %>\0"
+% end
+;
+
+#define insn_name_info insn_name_info_base+insn_name_info_offset
+
+static const char insn_operand_info[][8] = {
+% @insns.each do |insn|
+ "\<%= (insn.opes.size+1).to_s(8) %>""<%
+ insn.opes.each {|type, _|
+ %><%=TYPE_CHARS.fetch(op2typesig(type))%><%
+ }%>",
+% end
+};
+
+ASSERT_VM_INSTRUCTION_SIZE(insn_operand_info);
+
+#ifdef USE_INSN_RET_NUM
+static const unsigned short insn_stack_push_num_info[] = {
+% @insns.each do |insn|
+ <%= insn.rets.size %>,
+% end
+};
+
+ASSERT_VM_INSTRUCTION_SIZE(insn_stack_push_num_info);
+#endif
+
+#ifdef USE_INSN_STACK_INCREASE
+static int
+insn_stack_increase(int depth, int insn, VALUE *opes)
+{
+ switch (insn) {
+% @insns.each do |insn|
+ case BIN(<%= insn.name %>): {
+ <%= insn.sp_increase_c_expr %>
+ }
+% end
+ default:
+ rb_bug("insn_sp_increase: unreachable");
+ }
+ return 0;
+}
+#endif
+
+/* some utilities */
+
+static int
+insn_len(VALUE insn)
+{
+ return (unsigned char)insn_operand_info[(int)insn][0];
+}
+
+static const char *
+insn_name(VALUE insn)
+{
+ return insn_name_info[(int)insn];
+}
+
+static const char *
+insn_op_types(VALUE insn)
+{
+ return insn_operand_info[(int)insn]+1;
+}
+
+static int
+insn_op_type(VALUE insn, long pos)
+{
+ int len = insn_len(insn) - 1;
+ if (pos < len) {
+ return insn_operand_info[(int)insn][pos+1];
+ }
+ else{
+ return 0;
+ }
+}
+
+#ifdef USE_INSN_RET_NUM
+static int
+insn_ret_num(VALUE insn)
+{
+ return insn_stack_push_num_info[(int)insn];
+}
+#endif
diff --git a/template/known_errors.inc.tmpl b/template/known_errors.inc.tmpl
new file mode 100644
index 0000000000..c3aee77477
--- /dev/null
+++ b/template/known_errors.inc.tmpl
@@ -0,0 +1,14 @@
+/** -*-c-*-
+ * DO NOT EDIT
+ * This file is automatically generated by tool/generic_erb.rb from
+ * template/known_errors.inc.tmpl and defs/known_errors.def.
+ */
+
+% error_names = ARGF.read.split(/\s+/)
+% error_names.each do |name|
+#ifdef <%=name%>
+ defined_error("<%=name%>", <%=name%>)
+#else
+ undefined_error("<%=name%>")
+#endif
+% end
diff --git a/template/limits.c.tmpl b/template/limits.c.tmpl
new file mode 100644
index 0000000000..de35354829
--- /dev/null
+++ b/template/limits.c.tmpl
@@ -0,0 +1,97 @@
+%# -*- c -*-
+% limits = %w[
+% FIXNUM
+% CHAR SCHAR UCHAR WCHAR
+% SHRT USHRT
+% INT UINT
+% LONG ULONG
+% LLONG ULLONG
+% INT8 UINT8 INT_LEAST8 UINT_LEAST8 INT_FAST8 UINT_FAST8
+% INT16 UINT16 INT_LEAST16 UINT_LEAST16 INT_FAST16 UINT_FAST16
+% INT32 UINT32 INT_LEAST32 UINT_LEAST32 INT_FAST32 UINT_FAST32
+% INT64 UINT64 INT_LEAST64 UINT_LEAST64 INT_FAST64 UINT_FAST64
+% INT128 UINT128
+% INTMAX UINTMAX
+% INTPTR UINTPTR
+% SSZIE SIZE
+% PTRDIFF
+% ]
+%
+% verbatim_integers = %w[
+% FLT_RADIX
+% FLT_ROUNDS
+% FLT_EVAL_METHOD
+% FLT_MANT_DIG DBL_MANT_DIG LDBL_MANT_DIG
+% FLT_DIG DBL_DIG LDBL_DIG
+% FLT_MIN_EXP DBL_MIN_EXP LDBL_MIN_EXP
+% FLT_MIN_10_EXP DBL_MIN_10_EXP LDBL_MIN_10_EXP
+% FLT_MAX_EXP DBL_MAX_EXP LDBL_MAX_EXP
+% FLT_MAX_10_EXP DBL_MAX_10_EXP LDBL_MAX_10_EXP
+% FLT_DECIMAL_DIG DBL_DECIMAL_DIG LDBL_DECIMAL_DIG DECIMAL_DIG
+% FLT_HAS_SUBNORM DBL_HAS_SUBNORM LDBL_HAS_SUBNORM
+% ]
+%
+% # Beware; Ruby cannot handle LDBL_MAX.
+% verbatim_doubles = %w[
+% FLT_MAX DBL_MAX
+% FLT_EPSILON DBL_EPSILON
+% FLT_MIN DBL_MIN
+% FLT_TRUE_MIN DBL_TRUE_MIN
+% ]
+%
+#include <limits.h>
+#include "ruby/ruby.h"
+#ifdef HAVE_STDINT_H
+# include <stdint.h>
+#endif
+#ifdef HAVE_INTTYPES_H
+# include <stdint.h>
+#endif
+#ifdef HAVE_FLOAT_H
+# include <float.h>
+#endif
+
+void
+Init_limits(void)
+{
+ VALUE h = rb_hash_new();
+ rb_define_const(rb_define_module("RbConfig"), "LIMITS", h);
+
+#ifdef HAVE_LONG_LONG
+#ifndef ULLONG_MAX
+#define ULLONG_MAX ((unsigned LONG_LONG)LLONG_MAX*2+1)
+#endif
+#define MAX2NUM(name) ULL2NUM(name ## _MAX)
+#define MIN2NUM(name) LL2NUM(name ## _MIN)
+#else
+#define MAX2NUM(name) ULONG2NUM(name ## _MAX)
+#define MIN2NUM(name) LONG2NUM(name ## _MIN)
+#endif
+#define DEFINE(k, v) rb_hash_aset(h, rb_str_new_cstr(#k), v)
+
+% limits.each do |type|
+#ifdef <%= type %>_MAX
+ DEFINE(<%= type %>_MAX, MAX2NUM(<%= type %>));
+#endif
+#ifdef <%= type %>_MIN
+ DEFINE(<%= type %>_MIN, MIN2NUM(<%= type %>));
+#endif
+% end
+
+% verbatim_integers.each do |name|
+#ifdef <%= name %>
+ DEFINE(<%= name %>, LONG2NUM(<%= name %>));
+#endif
+% end
+
+% verbatim_doubles.each do |name|
+#ifdef <%= name %>
+ DEFINE(<%= name %>, DBL2NUM(<%= name %>));
+#endif
+% end
+
+#undef DEFINE
+#undef MIN2NUM
+#undef MAX2NUM
+ OBJ_FREEZE(h);
+}
diff --git a/template/minsns.inc.tmpl b/template/minsns.inc.tmpl
new file mode 100644
index 0000000000..f32b28cb7f
--- /dev/null
+++ b/template/minsns.inc.tmpl
@@ -0,0 +1,14 @@
+/** -*-c-*-
+ This file contains YARV instructions list, to define YARVCore::Instructions.
+
+ ----
+ This file is auto generated by insns2vm.rb
+ DO NOT TOUCH!
+
+ If you want to fix something, you must edit 'template/minsns.inc.tmpl'
+ or tool/insns2vm.rb
+ */
+
+% @insns.each_with_index do |insn, i|
+ rb_define_const(mYarvInsns, "I<%=insn.name%>", INT2FIX(<%=i%>));
+% end
diff --git a/template/opt_sc.inc.tmpl b/template/opt_sc.inc.tmpl
new file mode 100644
index 0000000000..4c85f96c0f
--- /dev/null
+++ b/template/opt_sc.inc.tmpl
@@ -0,0 +1,35 @@
+/* -*-c-*- *********************************************************/
+/*******************************************************************/
+/*******************************************************************/
+/**
+ This file is for threaded code.
+
+ ----
+ This file is auto generated by insns2vm.rb
+ DO NOT TOUCH!
+
+ If you want to fix something, you must edit 'template/opt_sc.inc.tmpl'
+ or tool/insns2vm.rb
+ */
+
+#define SC_STATE_SIZE 6
+
+#define SCS_XX 1
+#define SCS_AX 2
+#define SCS_BX 3
+#define SCS_AB 4
+#define SCS_BA 5
+
+#define SC_ERROR 0xffffffff
+
+static const VALUE sc_insn_info[][SC_STATE_SIZE] = {
+<%= sc_insn_info %>
+};
+
+ASSERT_VM_INSTRUCTION_SIZE(sc_insn_info);
+
+static const VALUE sc_insn_next[] = {
+<%= sc_insn_next %>
+};
+
+ASSERT_VM_INSTRUCTION_SIZE(sc_insn_next);
diff --git a/template/optinsn.inc.tmpl b/template/optinsn.inc.tmpl
new file mode 100644
index 0000000000..b1fba6dea3
--- /dev/null
+++ b/template/optinsn.inc.tmpl
@@ -0,0 +1,78 @@
+/* -*-c-*- *********************************************************/
+/*******************************************************************/
+/*******************************************************************/
+/**
+ This file is for threaded code.
+
+ ----
+ This file is auto generated by insns2vm.rb
+ DO NOT TOUCH!
+
+ If you want to fix something, you must edit 'template/optinsn.inc.tmpl'
+ or tool/insns2vm.rb
+ */
+
+static INSN *
+insn_operands_unification(INSN *insnobj)
+{
+#ifdef OPT_OPERANDS_UNIFICATION
+ /* optimize rule */
+ switch(insnobj->insn_id){
+% opt_insns_map.each do |originsn, optinsns|
+ case BIN(<%=originsn.name%>):
+% optinsns.each {|opti|
+ if (
+% opti.defopes.each_with_index {|opinfo, i|
+% next if opinfo[1] == '*'
+ insnobj->operands[<%=i%>] == <%=val_as_type(opinfo)%> &&
+% }
+ 1) {
+% idx = 0
+% opti.defopes.each_with_index {|opinfo, n|
+% if opinfo[1] == '*'
+% if idx != n
+ insnobj->operands[<%=idx%>] = insnobj->operands[<%=n%>];
+% end
+% idx += 1
+% end
+% }
+ insnobj->insn_id = BIN(<%=opti.name%>);
+ insnobj->operand_size = <%=idx%>;
+ break;
+ }
+% }
+ break;
+% end
+
+ default:
+ /* do nothing */;
+ break;
+ }
+#endif
+ return insnobj;
+}
+
+int
+rb_insn_unified_local_var_level(VALUE insn)
+{
+#ifdef OPT_OPERANDS_UNIFICATION
+ /* optimize rule */
+ switch (insn) {
+% opt_insns_map.each do |originsn, optinsns|
+% optinsns.each {|opti|
+ case BIN(<%=opti.name%>):
+% opti.defopes.each {|opinfo|
+% next if opinfo[1] == '*'
+ return <%=opinfo[1]%>;
+% break
+% }
+% }
+% end
+
+ default:
+ /* do nothing */;
+ break;
+ }
+#endif
+ return -1;
+}
diff --git a/template/optunifs.inc.tmpl b/template/optunifs.inc.tmpl
new file mode 100644
index 0000000000..3ac5872346
--- /dev/null
+++ b/template/optunifs.inc.tmpl
@@ -0,0 +1,67 @@
+/* -*-c-*- *********************************************************/
+/*******************************************************************/
+/*******************************************************************/
+/**
+ This file is for threaded code.
+
+ ----
+ This file is auto generated by insns2vm.rb
+ DO NOT TOUCH!
+
+ If you want to fix something, you must edit 'template/optunifs.inc.tmpl'
+ or tool/insns2vm.rb
+ */
+
+/*
+ static const int UNIFIED_insn_name_1[] = {id, size, ...};
+ static const int UNIFIED_insn_name_2[] = {id, size, ...};
+ ...
+
+ static const int *const UNIFIED_insn_name[] = {size,
+ UNIFIED_insn_name_1,
+ UNIFIED_insn_name_2, ...};
+ ...
+
+ static const int *const *const unified_insns_data[] = {
+ UNIFIED_insn_nameA,
+ UNIFIED_insn_nameB, ...};
+ */
+
+% unif_insns_data = @insns.find_all {|insn| !insn.is_sc}.map do |insn|
+% size = insn.unifs.size
+% if size > 0
+% name = "UNIFIED_#{insn.name}"
+% insn.unifs.sort_by{|unif| -unif[1].size}.each_with_index do |(uni_insn, uni_insns), i|
+% uni_insns = uni_insns[1..-1]
+static const int <%=name%>_<%=i%>[] = {
+ BIN(<%=uni_insn.name%>), <%=uni_insns.size + 2%>,
+ <% uni_insns.map{|e| -%>
+BIN(<%=e.name%>),<% -%>
+% }
+
+};
+% end
+
+static const int *const <%=name%>[] = {(int *)<%=size+1%>,
+% size.times do |e|
+ <%=name%>_<%=e%>,
+% end
+};
+% name
+% end
+% end
+
+static const int *const *const unified_insns_data[] = {<%#-%>
+% unif_insns_data.each_with_index do |insn, i|
+% if (i%8).zero?
+
+ <% -%>
+% end
+ <%=insn || "0"%>,<%#-%>
+% end
+
+};
+
+#undef GET_INSN_NAME
+
+ASSERT_VM_INSTRUCTION_SIZE(unified_insns_data);
diff --git a/template/prelude.c.tmpl b/template/prelude.c.tmpl
new file mode 100644
index 0000000000..11ec71f575
--- /dev/null
+++ b/template/prelude.c.tmpl
@@ -0,0 +1,238 @@
+<%
+# This file is interpreted by $(BASERUBY) and miniruby.
+# $(BASERUBY) is used for miniprelude.c.
+# miniruby is used for prelude.c.
+# Since $(BASERUBY) may be older than Ruby 1.9,
+# Ruby 1.9 feature should not be used.
+
+class Prelude
+ LINE_LIMIT = 509 # by C89
+
+ C_ESC = {
+ "/*" => "/\\*",
+ "*/" => "*\\/",
+ "\\" => "\\\\",
+ '"' => '\"',
+ "\n" => '\n',
+ }
+
+ 0x00.upto(0x1f) {|ch| C_ESC[[ch].pack("C")] ||= "\\%03o" % ch }
+ 0x7f.upto(0xff) {|ch| C_ESC[[ch].pack("C")] = "\\%03o" % ch }
+ C_ESC_PAT = Regexp.union(*C_ESC.keys)
+
+ def c_esc(str)
+ str.gsub(C_ESC_PAT) { C_ESC[$&] }
+ end
+ def prelude_base(filename)
+ filename.chomp(".rb")
+ end
+ def prelude_name(filename)
+ "<internal:" + prelude_base(filename) + ">"
+ end
+
+ def initialize(init_name, preludes, vpath)
+ @init_name = init_name
+ @have_sublib = false
+ @vpath = vpath
+ @preludes = {}
+ @mains = preludes.map {|filename| translate(filename)[0]}
+ @preludes.delete_if {|_, (_, _, lines, sub)| sub && lines.empty?}
+ end
+
+ def translate(filename, sub = false)
+ idx = @preludes[filename]
+ return idx if idx
+ lines = []
+ result = [@preludes.size, @vpath.strip(filename), lines, sub]
+ @vpath.foreach(filename) do |line|
+ @preludes[filename] ||= result
+ comment = ($1 || '' if line.sub!(/(?:^|\s+)\#(?:$|[#\s](.*))/, ''))
+ if line.size > LINE_LIMIT
+ raise "#{filename}:#{lines.size+1}: too long line"
+ end
+ line.sub!(/require(_relative)?\s*\(?\s*(["'])(.*?)(?:\.rb)?\2\)?/) do
+ orig, rel, path = $&, $2, $3
+ if rel
+ path = File.join(File.dirname(filename), path)
+ nil while path.gsub!(%r'(\A|/)(?!\.\.?/)[^/]+/\.\.(?:/|\z)', '')
+ end
+ path = translate("#{path}.rb", true) rescue nil
+ if path
+ @have_sublib = true
+ "TMP_RUBY_PREFIX.require(#{path[0]})"
+ else
+ orig
+ end
+ end
+ lines << [line, comment]
+ end
+ result
+ end
+end
+Prelude.new(output && output[/\w+(?=_prelude.c\b)/] || 'prelude', ARGV, vpath).instance_eval do
+-%>
+/* -*-c-*-
+ THIS FILE WAS AUTOGENERATED BY template/prelude.c.tmpl. DO NOT EDIT.
+
+ sources: <%= @preludes.map {|n,*| prelude_base(n)}.join(', ') %><%=%>
+*/
+%unless @preludes.empty?
+#include "ruby/ruby.h"
+#include "internal.h"
+#include "vm_core.h"
+#include "iseq.h"
+
+% preludes = @preludes.values.sort
+% preludes.each {|i, prelude, lines, sub|
+
+% name = prelude_name(*prelude)
+static const struct {
+ char L0[<%=name.size%><%=%>];
+} prelude_name<%=i%><%=%> = {"<%=c_esc(name)%>"};
+static const struct {
+% size = beg = 0
+% lines.each_with_index {|(line, comment), n|
+% if size + line.size < Prelude::LINE_LIMIT
+% size += line.size
+% next
+% end
+ char L<%=beg%><%=%>[<%=size%><%=%>]; /* <%=beg+1%>..<%=n%> */
+% size = line.size
+% beg = n
+% }
+% if size > 0
+ char L<%=beg%><%=%>[<%=size%><%=%>]; /* <%=beg+1%>..<%=lines.size+1%> */
+% end
+} prelude_code<%=i%><%=%> = {
+% size = 0
+#line 1 "<%=c_esc(prelude)%>"
+% lines.each_with_index {|(line, comment), n|
+% if size + line.size >= Prelude::LINE_LIMIT
+% size = 0
+,
+#line <%=n+1%> "<%=c_esc(prelude)%>"
+% end
+% size += line.size
+"<%=c_esc(line)%>"<%if comment%>/* <%=c_esc(comment)%> */<%end%>
+% }
+#line <%=_erbout.count("\n")+2%> "<%=@init_name%>.c"
+};
+% }
+
+% if @have_sublib
+#define PRELUDE_COUNT <%=preludes.size%>
+
+struct prelude_env {
+ volatile VALUE prefix_path;
+#if PRELUDE_COUNT > 0
+ char loaded[PRELUDE_COUNT];
+#endif
+};
+
+static VALUE
+prelude_prefix_path(VALUE self)
+{
+ struct prelude_env *ptr = DATA_PTR(self);
+ return ptr->prefix_path;
+}
+% end
+
+% unless preludes.empty?
+#define PRELUDE_STR(n) rb_usascii_str_new_static(prelude_##n.L0, sizeof(prelude_##n))
+#ifdef __GNUC__
+# pragma GCC diagnostic push
+# pragma GCC diagnostic error "-Wmissing-field-initializers"
+#endif
+static void
+prelude_eval(VALUE code, VALUE name, int line)
+{
+ static const rb_compile_option_t optimization = {
+ TRUE, /* int inline_const_cache; */
+ TRUE, /* int peephole_optimization; */
+ TRUE, /* int tailcall_optimization; */
+ TRUE, /* int specialized_instruction; */
+ TRUE, /* int operands_unification; */
+ TRUE, /* int instructions_unification; */
+ TRUE, /* int stack_caching; */
+ TRUE, /* int frozen_string_literal; */
+ FALSE, /* int debug_frozen_string_literal; */
+ FALSE, /* unsigned int coverage_enabled; */
+ 0, /* int debug_level; */
+ };
+
+ rb_ast_t *ast = rb_parser_compile_string_path(rb_parser_new(), name, code, line);
+ if (!ast->root) {
+ rb_ast_dispose(ast);
+ rb_exc_raise(rb_errinfo());
+ }
+ rb_iseq_eval(rb_iseq_new_with_opt(ast->root, name, name, Qnil, INT2FIX(line),
+ NULL, ISEQ_TYPE_TOP, &optimization));
+ rb_ast_dispose(ast);
+}
+#ifdef __GNUC__
+# pragma GCC diagnostic pop
+#endif
+% end
+
+% if @have_sublib
+static VALUE
+prelude_require(VALUE self, VALUE nth)
+{
+ struct prelude_env *ptr = DATA_PTR(self);
+ VALUE code, name;
+ int n = FIX2INT(nth);
+
+ if (n > PRELUDE_COUNT) return Qfalse;
+ if (ptr->loaded[n]) return Qfalse;
+ ptr->loaded[n] = 1;
+ switch (n) {
+% @preludes.each_value do |i, prelude, lines, sub|
+% if sub
+ case <%=i%><%=%>:
+ code = PRELUDE_STR(code<%=i%><%=%>);
+ name = PRELUDE_STR(name<%=i%><%=%>);
+ break;
+% end
+% end
+ default:
+ return Qfalse;
+ }
+ prelude_eval(code, name, 1);
+ return Qtrue;
+}
+
+% end
+%end
+void
+Init_<%=@init_name%><%=%>(void)
+{
+%unless @preludes.empty?
+% if @have_sublib
+ struct prelude_env memo;
+ ID name = rb_intern("TMP_RUBY_PREFIX");
+ VALUE prelude = Data_Wrap_Struct(rb_cData, 0, 0, &memo);
+
+ memo.prefix_path = rb_const_remove(rb_cObject, name);
+ rb_const_set(rb_cObject, name, prelude);
+ rb_define_singleton_method(prelude, "to_s", prelude_prefix_path, 0);
+% end
+% if @have_sublib
+ memset(memo.loaded, 0, sizeof(memo.loaded));
+ rb_define_singleton_method(prelude, "require", prelude_require, 1);
+% end
+% preludes.each do |i, prelude, lines, sub|
+% next if sub
+ prelude_eval(PRELUDE_STR(code<%=i%><%=%>), PRELUDE_STR(name<%=i%><%=%>), 1);
+% end
+% if @have_sublib
+ rb_gc_force_recycle(prelude);
+% end
+
+#if 0
+% preludes.length.times {|i|
+ printf("%.*s", (int)sizeof(prelude_code<%=i%><%=%>), prelude_code<%=i%><%=%>.L0);
+% }
+#endif
+%end
+}
+<%end -%>
diff --git a/template/ruby-runner.h.in b/template/ruby-runner.h.in
new file mode 100644
index 0000000000..b94086c565
--- /dev/null
+++ b/template/ruby-runner.h.in
@@ -0,0 +1,7 @@
+#define ABS_SRCDIR "@abs_srcdir@"
+#define BUILDDIR "@abs_top_builddir@"
+#define LIBPATHENV "@LIBPATHENV@"
+#define PATH_SEPARATOR "@PATH_SEPARATOR@"
+#define PATH_SEP '@PATH_SEPARATOR@'
+#define EXTOUT "@EXTOUT@"
+#define ARCH "@arch@"
diff --git a/template/ruby.pc.in b/template/ruby.pc.in
new file mode 100644
index 0000000000..d874f92c3b
--- /dev/null
+++ b/template/ruby.pc.in
@@ -0,0 +1,58 @@
+arch=@arch@
+sitearch=@sitearch@
+prefix=@prefix@
+exec_prefix=@exec_prefix@
+bindir=@bindir@
+libdir=@libdir@
+includedir=@includedir@
+MAJOR=@MAJOR@
+MINOR=@MINOR@
+TEENY=@TEENY@
+ruby_version=@ruby_version@
+RUBY_API_VERSION=@RUBY_API_VERSION@
+RUBY_PROGRAM_VERSION=@RUBY_PROGRAM_VERSION@
+RUBY_BASE_NAME=@RUBY_BASE_NAME@
+RUBY_VERSION_NAME=@RUBY_VERSION_NAME@
+RUBY_SO_NAME=@RUBY_SO_NAME@
+RUBY_INSTALL_NAME=@RUBY_INSTALL_NAME@
+DEFFILE=@DEFFILE@
+archlibdir=@archlibdir@
+sitearchlibdir=@sitearchlibdir@
+archincludedir=@archincludedir@
+sitearchincludedir=@sitearchincludedir@
+ruby=${bindir}/${RUBY_INSTALL_NAME}@EXEEXT@
+rubylibprefix=@rubylibprefix@
+rubyarchprefix=@rubyarchprefix@
+rubysitearchprefix=@rubysitearchprefix@
+rubylibdir=@rubylibdir@
+vendordir=@vendordir@
+sitedir=@sitedir@
+vendorlibdir=@vendorlibdir@
+sitelibdir=@sitelibdir@
+rubyarchdir=@rubyarchdir@
+vendorarchdir=@vendorarchdir@
+sitearchdir=@sitearchdir@
+rubyhdrdir=@rubyhdrdir@
+vendorhdrdir=@vendorhdrdir@
+sitehdrdir=@sitehdrdir@
+rubyarchhdrdir=@rubyarchhdrdir@
+vendorarchhdrdir=@vendorarchhdrdir@
+sitearchhdrdir=@sitearchhdrdir@
+SOEXT=@SOEXT@
+LIBPATH=@LIBPATH@
+LIBRUBY_A=@LIBRUBY_A@
+LIBRUBY_SO=@LIBRUBY_SO@
+LIBRUBY=@LIBRUBY@
+LIBRUBYARG_SHARED=@LIBRUBYARG_SHARED@
+LIBRUBYARG_STATIC=@LIBRUBYARG_STATIC@
+LIBRUBYARG=@LIBRUBYARG@
+LIBS=@LIBS@
+DLDFLAGS=@DLDFLAGS@
+
+Name: Ruby
+Description: Object Oriented Script Language
+Version: ${ruby_version}
+URL: https://www.ruby-lang.org
+Cflags: -I${rubyarchhdrdir} -I${rubyhdrdir}
+Libs: ${DLDFLAGS} ${LIBRUBYARG_SHARED} ${LIBS}
+Requires:
diff --git a/template/sizes.c.tmpl b/template/sizes.c.tmpl
new file mode 100644
index 0000000000..848a29f4be
--- /dev/null
+++ b/template/sizes.c.tmpl
@@ -0,0 +1,54 @@
+%# -*- c -*-
+#include "ruby/ruby.h"
+<%
+class String
+ def tr_cpp
+ strip.upcase.tr_s("^A-Z0-9_*", "_").tr_s("*", "P")
+ end
+end
+headers = Hash.new {[]}
+sizes = {}
+types = ARGF.grep(/^\s*RUBY_CHECK_SIZEOF\((\w[^\[\],#]*)[^#]*\)|
+ ^\s*RUBY_DEFINT\((\w[^\[\],#]*)[^#]*\)|
+ ^\s*have_type\('(.+?)'(?:,\s*%w\[(.+)\])?\)/x) do
+ sizes[type = $3] = true
+ hdrs = $4 and hdrs.split.each {|h| headers[h] <<= type}
+ type || $+
+end
+conditions = {
+ "long long" => 'defined(HAVE_TRUE_LONG_LONG)',
+}
+%>
+% headers.each do |h, type|
+#if <%= type.map {|t| "defined(HAVE_TYPE_#{t.tr_cpp})"}.join(' || ') %>
+# include <<%= h %>>
+#endif
+
+% end
+extern void Init_limits(void);
+void
+Init_sizeof(void)
+{
+ VALUE s = rb_hash_new();
+ rb_define_const(rb_define_module("RbConfig"), "SIZEOF", s);
+
+#define DEFINE(type, size) rb_hash_aset(s, rb_str_new_cstr(#type), INT2FIX(SIZEOF_##size))
+#define DEFINE_SIZE(type) rb_hash_aset(s, rb_str_new_cstr(#type), INT2FIX(sizeof(type)))
+
+% types.each do |type|
+% if sizes[type]
+#ifdef HAVE_TYPE_<%= type.tr_cpp %>
+ DEFINE_SIZE(<%= type %>);
+#endif
+% next
+% end
+% cond = conditions[type]
+#if SIZEOF_<%= type.tr_cpp %> != 0<%= " && #{cond}" if cond %>
+ DEFINE(<%= type %>, <%= type.tr_cpp %>);
+#endif
+% end
+ OBJ_FREEZE(s);
+
+#undef DEFINE
+ Init_limits();
+}
diff --git a/template/transdb.h.tmpl b/template/transdb.h.tmpl
new file mode 100644
index 0000000000..d0cf101344
--- /dev/null
+++ b/template/transdb.h.tmpl
@@ -0,0 +1,59 @@
+<%
+#
+# static const rb_transcoder
+# rb_from_US_ASCII = {
+# "US-ASCII", "UTF-8", &from_US_ASCII, 1, 0,
+# NULL, NULL,
+# };
+#
+
+count = 0
+converters = {}
+transdirs = ARGV.dup
+transdirs << 'enc/trans' if transdirs.empty?
+
+transdirs = transdirs.sort_by {|td|
+ -td.length
+}.inject([]) {|tds, td|
+ next tds unless File.directory?(td)
+ tds << td if tds.all? {|td2| !File.identical?(td2, td) }
+ tds
+}
+
+files = {}
+names_t = []
+converter_list = []
+transdirs.each do |transdir|
+ names = Dir.entries(transdir)
+ names_t += names.map {|n| /(?!\A)\.trans\z/ =~ n ? $` : nil }.compact
+ names_c = names.map {|n| /(?!\A)\.c\z/ =~ n ? $` : nil }.compact
+ (names_t & names_c).map {|n|
+ "#{n}.c"
+ }.sort_by {|e|
+ e.scan(/(\d+)|(\D+)/).map {|n,a| a||[n.size,n.to_i]}.flatten
+ }.each do |fn|
+ next if files[fn]
+ files[fn] = true
+ path = File.join(transdir,fn)
+ open(path) do |f|
+ f.each_line do |line|
+ if (/^static const rb_transcoder/ =~ line)..(/"(.*?)"\s*,\s*"(.*?)"/ =~ line)
+ if $1 && $2
+ from_to = "%s to %s" % [$1, $2]
+ if converters[from_to]
+ raise ArgumentError, '%s:%d: transcode "%s" is already registered at %s:%d' %
+ [path, $., from_to, *converters[from_to].values_at(3, 4)]
+ else
+ converters[from_to] = [$1, $2, fn[0..-3], path, $.]
+ converter_list << from_to
+ end
+ end
+ end
+ end
+ end
+ end
+end
+converter_list.each do |from_to|
+ from, to, fn = *converters[from_to]
+%>rb_declare_transcoder("<%=from%>", "<%=to%>", "<%=fn%>");
+% end
diff --git a/template/unicode_norm_gen.tmpl b/template/unicode_norm_gen.tmpl
new file mode 100644
index 0000000000..64acfc8d18
--- /dev/null
+++ b/template/unicode_norm_gen.tmpl
@@ -0,0 +1,220 @@
+%# -*- mode: ruby; coding: utf-8 -*-
+<%
+# Copyright Ayumu Nojima (野島 歩) and Martin J. Dürst (duerst@it.aoyama.ac.jp)
+
+# Script to generate Ruby data structures used in implementing
+# String#unicode_normalize,...
+
+# Constants for input and ouput directory
+InputDataDir = ARGV[0] || 'enc/unicode/data'
+unicode_version = InputDataDir[/.*\/(\d+\.\d+\.\d+)(?=\/|\z)/, 1]
+
+# convenience methods
+class Integer
+ def to_UTF8() # convert to string, taking legibility into account
+ if self>0xFFFF
+ "\\u{#{to_s(16).upcase}}"
+ elsif self>0x7f
+ "\\u#{to_s(16).upcase.rjust(4, '0')}"
+ else
+ chr.sub(/[\\\"]/, "\\\\\\\&")
+ end
+ end
+end
+
+module Enumerable
+ unless method_defined?(:each_slice)
+ def each_slice(n)
+ ary = []
+ each do |i|
+ ary << i
+ if ary.size >= n
+ yield ary
+ ary = []
+ end
+ end
+ yield ary unless ary.empty?
+ self
+ end
+ end
+end
+
+class Array
+ def to_UTF8() collect {|c| c.to_UTF8}.join('') end
+
+ def each_regexp_chars(n = 8) # converts an array of Integers to character ranges
+ sort.inject([]) do |ranges, value|
+ if ranges.last and ranges.last[1]+1>=value
+ ranges.last[1] = value
+ ranges
+ else
+ ranges << [value, value]
+ end
+ end.collect do |first, last|
+ case last-first
+ when 0
+ first.to_UTF8
+ when 1
+ first.to_UTF8 + last.to_UTF8
+ else
+ first.to_UTF8 + '-' + last.to_UTF8
+ end
+ end.each_slice(n) do |slice|
+ yield slice.join('')
+ end
+ end
+end
+
+# read the file 'CompositionExclusions.txt'
+composition_exclusions = vpath.open("#{InputDataDir}/CompositionExclusions.txt", 'rb') {|f|
+ base = Regexp.quote(File.basename(f.path, '.*'))
+ ext = Regexp.quote(File.extname(f.path))
+ version = (line = f.gets)[/^# *#{base}-([\d.]+)#{ext}\s*$/, 1] or
+ abort "No file version in #{f.path}: #{line}"
+ (unicode_version ||= version) == version or
+ abort "Unicode version of directory (#{unicode_version}) and file (#{version}) mismatch"
+ f.grep(/^[A-Z0-9]{4,5}/) {|code| code.hex}
+}
+
+decomposition_table = {}
+kompatible_table = {}
+combining_class = {} # constant to allow use in Integer#to_UTF8
+
+# read the file 'UnicodeData.txt'
+vpath.foreach("#{InputDataDir}/UnicodeData.txt") do |line|
+ codepoint, name, _2, char_class, _4, decomposition, *_rest = line.split(";")
+
+ case decomposition
+ when /^[0-9A-F]/
+ decomposition_table[codepoint.hex] = decomposition.split(' ').collect {|w| w.hex}
+ when /^</
+ kompatible_table[codepoint.hex] = decomposition.split(' ')[1..-1].collect {|w| w.hex}
+ end
+ combining_class[codepoint.hex] = char_class.to_i if char_class != "0"
+
+ if name=~/(First|Last)>$/ and (char_class!="0" or decomposition!="")
+ warn "Unexpected: Character range with data relevant to normalization!"
+ end
+end
+
+# calculate compositions from decompositions
+composition_table = decomposition_table.reject do |character, decomposition|
+ composition_exclusions.member? character or # predefined composition exclusion
+ decomposition.length<=1 or # Singleton Decomposition
+ combining_class[character] or # character is not a Starter
+ combining_class[decomposition.first] # decomposition begins with a character that is not a Starter
+end.invert
+
+# recalculate composition_exclusions
+composition_exclusions = decomposition_table.keys - composition_table.values
+
+accent_array = combining_class.keys + composition_table.keys.collect {|key| key.last}
+
+composition_starters = composition_table.keys.collect {|key| key.first}
+
+hangul_no_trailing = []
+0xAC00.step(0xD7A3, 28) {|c| hangul_no_trailing << c}
+
+# expand decomposition table values
+decomposition_table.each do |key, value|
+ position = 0
+ while position < value.length
+ if decomposition = decomposition_table[value[position]]
+ decomposition_table[key] = value = value.dup # avoid overwriting composition_table key
+ value[position, 1] = decomposition
+ else
+ position += 1
+ end
+ end
+end
+
+# deal with relationship between canonical and kompatibility decompositions
+decomposition_table.each do |key, value|
+ value = value.dup
+ expanded = false
+ position = 0
+ while position < value.length
+ if decomposition = kompatible_table[value[position]]
+ value[position, 1] = decomposition
+ expanded = true
+ else
+ position += 1
+ end
+ end
+ kompatible_table[key] = value if expanded
+end
+
+while kompatible_table.any? {|key, value|
+ expanded = value.map {|v| kompatible_table[v] || v}.flatten
+ kompatible_table[key] = expanded unless value == expanded
+ }
+end
+
+# generate normalization tables file
+%># coding: us-ascii
+# frozen_string_literal: true
+%# >
+
+# automatically generated by template/unicode_norm_gen.tmpl
+
+module UnicodeNormalize # :nodoc:
+ accents = "" \
+ "[<% accent_array.each_regexp_chars do |rx|%><%=rx%>" \
+ "<% end%>]"
+ ACCENTS = accents
+ REGEXP_D_STRING = "#{'' # composition starters and composition exclusions
+ }" \
+ "[<% (composition_table.values+composition_exclusions).each_regexp_chars do |rx|%><%=rx%>" \
+ "<% end%>]#{accents}*" \
+ "|#{'' # characters that can be the result of a composition, except composition starters
+ }" \
+ "[<% (composition_starters-composition_table.values).each_regexp_chars do |rx|%><%=rx%>" \
+ "<% end%>]?#{accents}+" \
+ "|#{'' # precomposed Hangul syllables
+ }" \
+ "[\u{AC00}-\u{D7A4}]"
+ REGEXP_C_STRING = "#{'' # composition exclusions
+ }" \
+ "[<% composition_exclusions.each_regexp_chars do |rx|%><%=rx%>" \
+ "<% end%>]#{accents}*" \
+ "|#{'' # composition starters and characters that can be the result of a composition
+ }" \
+ "[<% (composition_starters+composition_table.values).each_regexp_chars do |rx|%><%=rx%>" \
+ "<% end%>]?#{accents}+" \
+ "|#{'' # Hangul syllables with separate trailer
+ }" \
+ "[<% hangul_no_trailing.each_regexp_chars do |rx|%><%=rx%>" \
+ "<% end%>][\u11A8-\u11C2]" \
+ "|#{'' # decomposed Hangul syllables
+ }" \
+ "[\u1100-\u1112][\u1161-\u1175][\u11A8-\u11C2]?"
+ REGEXP_K_STRING = "" \
+ "[<% kompatible_table.keys.each_regexp_chars do |rx|%><%=rx%>" \
+ "<%end%>]"
+
+ class_table = {
+% combining_class.each_slice(8) do |slice|
+ <% slice.each do |key, value|%> "<%=key.to_UTF8%>"=><%=value%><%=%>,<% end%>
+% end
+ }
+ class_table.default = 0
+ CLASS_TABLE = class_table.freeze
+
+ DECOMPOSITION_TABLE = {
+% decomposition_table.each_slice(8) do |slice|
+ <% slice.each do |key, value|%> "<%=key.to_UTF8%>"=>"<%=value.to_UTF8%>"<%=%>,<% end%>
+% end
+ }.freeze
+
+ KOMPATIBLE_TABLE = {
+% kompatible_table.each_slice(8) do |slice|
+ <% slice.each do |key, value|%> "<%=key.to_UTF8%>"=>"<%=value.to_UTF8%>"<%=%>,<% end%>
+% end
+ }.freeze
+
+ COMPOSITION_TABLE = {
+% composition_table.each_slice(8) do |slice|
+ <% slice.each do |key, value|%> "<%=key.to_UTF8%>"=>"<%=value.to_UTF8%>"<%=%>,<% end%>
+% end
+ }.freeze
+end
diff --git a/template/verconf.h.tmpl b/template/verconf.h.tmpl
new file mode 100644
index 0000000000..3b8a8aad76
--- /dev/null
+++ b/template/verconf.h.tmpl
@@ -0,0 +1,63 @@
+% config = File.read(conffile = 'rbconfig.rb')
+% config.sub!(/^(\s*)RUBY_VERSION\b.*(\sor\s*)$/, '\1true\2')
+% rbconfig = Module.new {module_eval(config, conffile)}::RbConfig
+% C = rbconfig::MAKEFILE_CONFIG.dup
+% def C.[](name) str = super and (str unless str.empty?); end
+#define RUBY_BASE_NAME "${RUBY_BASE_NAME}"
+#define RUBY_VERSION_NAME RUBY_BASE_NAME"-"RUBY_LIB_VERSION
+% if C["RUBY_LIB_VERSION_STYLE"]
+#define RUBY_LIB_VERSION_STYLE ${RUBY_LIB_VERSION_STYLE}
+% elsif !C["RUBY_LIB_VERSION"]
+#define RUBY_LIB_VERSION_STYLE 3 /* full */
+% else
+#define RUBY_LIB_VERSION "${RUBY_LIB_VERSION}"
+% end
+#define RUBY_EXEC_PREFIX "<%='${RUBY_EXEC_PREFIX}' if C['RUBY_EXEC_PREFIX']%>"
+#define RUBY_LIB_PREFIX "${rubylibprefix}"
+% unless (sitearch = C["sitearch"]) == '$(arch)'
+#define RUBY_SITEARCH "<%=sitearch%>"
+% end
+#define RUBY_ARCH_PREFIX_FOR(arch) "${rubyarchprefix}"
+#define RUBY_SITEARCH_PREFIX_FOR(arch) "${rubysitearchprefix}"
+#define RUBY_LIB "${rubylibdir}"
+#define RUBY_ARCH_LIB_FOR(arch) "${rubyarchdir}"
+% if !C["sitedir"] || C["sitedir"] == "no"
+#define NO_RUBY_SITE_LIB 1
+% else
+#define RUBY_SITE_LIB "${sitedir}"
+#define RUBY_SITE_ARCH_LIB_FOR(arch) "${sitearchdir}"
+% end
+% if !C["vendordir"] || C["vendordir"] == "no"
+#define NO_RUBY_VENDOR_LIB 1
+% else
+#define RUBY_VENDOR_LIB "${vendordir}"
+#define RUBY_VENDOR_ARCH_LIB_FOR(arch) "${vendorarchdir}"
+% end
+% if C["RUBY_SEARCH_PATH"]
+#define RUBY_SEARCH_PATH "${RUBY_SEARCH_PATH}"
+% end
+%
+% R = {}
+% R["ruby_version"] = '"RUBY_LIB_VERSION"'
+% R["arch"] = '"arch"'
+% R["sitearch"] = '"arch"'
+% R["vendorlibdir"] = '"RUBY_VENDOR_LIB2"'
+% R["sitelibdir"] = '"RUBY_SITE_LIB2"'
+% R["vendordir"] = '"RUBY_VENDOR_LIB"'
+% R["sitedir"] = '"RUBY_SITE_LIB"'
+% R["rubylibdir"] = '"RUBY_LIB"'
+% R["rubylibprefix"] = '"RUBY_LIB_PREFIX"'
+% R["rubyarchprefix"] = '"RUBY_ARCH_PREFIX_FOR(arch)"'
+% R["rubysitearchprefix"] = '"RUBY_SITEARCH_PREFIX_FOR(arch)"'
+% R["exec_prefix"] = '"RUBY_EXEC_PREFIX"'
+% R["prefix"] = '"RUBY_EXEC_PREFIX"'
+% exec_prefix_pat = /\A"#{Regexp.quote(rbconfig::CONFIG['exec_prefix'])}(?=\/|\z)/
+% _erbout.gsub!(/^(#define\s+(\S+)\s+)(.*)/) {
+% pre, name, repl = $1, $2, $3
+% pat = %["#{name}"]
+% c = C.merge(R.reject {|key, value| key == name or value.include?(pat)})
+% rbconfig.expand(repl, c)
+% repl.gsub!(/^""(?!$)|(.)""$/, '\1')
+% repl.sub!(exec_prefix_pat, 'RUBY_EXEC_PREFIX"')
+% pre + repl
+% }
diff --git a/template/vm.inc.tmpl b/template/vm.inc.tmpl
new file mode 100644
index 0000000000..14b6ba3f10
--- /dev/null
+++ b/template/vm.inc.tmpl
@@ -0,0 +1,33 @@
+/* -*-c-*- *********************************************************/
+/*******************************************************************/
+/*******************************************************************/
+/**
+ This file is VM main loop.
+
+ ----
+ This file is auto generated by insns2vm.rb
+ DO NOT TOUCH!
+
+ If you want to fix something, you must edit 'insns.def'
+ */
+
+
+% line = _erbout.count("\n") + 1
+% @insns.each do |insn|
+<%
+line += 1
+make_insn_def(insn).split(/(__CURRENT_LINE__|__CURRENT_FILE__)/).each {|e|
+ %><%=
+ case e
+ when '__CURRENT_LINE__'
+ line.to_s
+ when '__CURRENT_FILE__'
+ "vm.inc"
+ else
+ line += e.count("\n")
+ e
+ end
+ %><%
+}
+%>
+% end
diff --git a/template/vmtc.inc.tmpl b/template/vmtc.inc.tmpl
new file mode 100644
index 0000000000..3c313113a5
--- /dev/null
+++ b/template/vmtc.inc.tmpl
@@ -0,0 +1,21 @@
+/* -*-c-*- *********************************************************/
+/*******************************************************************/
+/*******************************************************************/
+/**
+ This file is for threaded code.
+
+ ----
+ This file is auto generated by insns2vm.rb
+ DO NOT TOUCH!
+
+ If you want to fix something, you must edit 'template/vmtc.inc.tmpl'
+ or insns2vm.rb
+ */
+
+static const void *const insns_address_table[] = {
+% @insns.each do |insn|
+ LABEL_PTR(<%=insn.name%>),
+% end
+};
+
+ASSERT_VM_INSTRUCTION_SIZE(insns_address_table);
diff --git a/template/yarvarch.en b/template/yarvarch.en
new file mode 100644
index 0000000000..7a76e25b7e
--- /dev/null
+++ b/template/yarvarch.en
@@ -0,0 +1,7 @@
+#title YARV: Yet another RubyVM - Software Architecture
+
+maybe writing.
+
+* YARV instruction set
+
+<%= d %>
diff --git a/template/yarvarch.ja b/template/yarvarch.ja
new file mode 100644
index 0000000000..2739ec6b14
--- /dev/null
+++ b/template/yarvarch.ja
@@ -0,0 +1,454 @@
+#title YARVアーキテクチャ
+#set author 日本 Ruby の会 ささだこういち
+
+
+- 2005-03-03(Thu) 00:31:12 +0900 いろいろと書き直し
+
+----
+
+* これは?
+
+[[YARV: Yet Another RubyVM|http://www.atdot.net/yarv]] の 設計メモです。
+
+
+YARV は、Ruby プログラムのための次の機能を提供します。
+
+- Compiler
+- VM Generator
+- VM (Virtual Machine)
+- Assembler
+- Dis-Assembler
+- (experimental) JIT Compiler
+- (experimental) AOT Compiler
+
+
+現在の YARV は Ruby インタプリタの拡張ライブラリとして実装しています。こ
+れにより、Ruby インタプリタの必要な機能(パーサ、オブジェクト管理、既存
+の拡張ライブラリ)などがほぼそのまま利用できます。
+
+ただし、いくつかのパッチを Ruby インタプリタに当てなければなりません。
+
+今後は、Ruby 本体のインタプリタ部分(eval.c)を置き換えることを目指して
+開発を継続する予定です。
+
+
+* Compiler (compile.h, compile.c)
+
+コンパイラは、Ruby インタプリタのパーサによって生成された構文木(RNode
+データによる木)を YARV 命令列に変換します。YARV 命令については後述しま
+す。
+
+とくに難しいことはしていませんが、スコープなどの開始時にローカル変数の初
+期化などを行い、あとは構文木を辿り変換していきます。
+
+変換中は Ruby の Array オブジェクトに YARV 命令オブジェクト、およびオペ
+ランドを格納していき、最後に実行できる形に変換します。コンパイラでは、コ
+ンパイル中に生成するメモリ領域の管理が問題になることがありますが、YARV
+の場合、Ruby インタプリタがすべて面倒をみてくれるのでこの部分は非常に楽
+に作ることができました(ガーベージコレクタによって自動的にメモリ管理をし
+てくれるため)。
+
+YARV 命令は、命令を示す識別子、オペランドなど、すべて 1 word (マシンで
+表現できる自然な値。C 言語ではポインタのサイズ。Ruby インタプリタ用語で
+は VALUE のサイズ)で表現されます。そのため、YARV 命令はいわゆる「バイト
+コード」ではありません。そのため、YARV の説明などでは「命令列」という用
+語を使っています。
+
+1 word であるため、メモリの利用効率は多少悪くなりますが、アクセス速度な
+どを考慮すると、本方式が一番いいと考えております。たとえばオペランドをコ
+ンスタントプールに格納し、インデックスのみをオペランドで示すことも可能で
+すが、間接アクセスになってしまうので性能に影響が出るため、却下しました。
+
+
+* VM Generator (rb/insns2vm.rb, insns.def)
+
+rb/insns2vm.rb というスクリプトは、insns.def というファイルを読み込み、
+VM のために必要なファイルを生成します。具体的には、命令を実行する部分を
+生成しますが、ほかにもコンパイルに必要な情報、最適化に必要な情報、やアセ
+ンブラ、逆アセンブラに必要な情報を示すファイルも生成します。
+
+
+** 命令記述
+
+insns.def には、各命令がどのような命令であるかを記述します。具体的には次
+の情報を記述します。
+
+- 命令の名前
+- その命令のカテゴリ、コメント(英語、日本語)
+- オペランドの名前
+- その命令実行前にスタックからポップする値
+- その命令実行後にスタックにプッシュする値
+- その命令のロジック(C 言語で記述)
+
+たとえば、スタックに self をおく putself という命令は次のように記述しま
+す。
+
+#code
+/**
+ @c put
+ @e put self.
+ @j self を置く。
+ */
+DEFINE_INSN
+putself
+()
+()
+(VALUE val)
+{
+ val = GET_SELF();
+}
+#end
+
+この場合、オペランドと、スタックからポップする値は無いことになります。命
+令終了後、self をスタックトップに置きたいわけですが、それは val という、
+スタックにプッシュする値として宣言しておいた変数に代入しておくことで、こ
+れを変換するとスタックトップに置く C プログラムが生成されます。
+
+細かいフォーマットは insns.def の冒頭を参照してください。そんなに難しく
+ないと思います。
+
+insnhelper.h というファイルに、命令ロジックを記述するために必要なマクロ
+が定義されています。また、VM の内部構造に関する定義は vm.h というファイ
+ルにあります。
+
+
+* VM (Virtual Machine, vm.h, vm.c)
+
+VM は、実際にコンパイルした結果生成される YARV 命令列を実行します。まさ
+に、この部分が YARV のキモになり、将来的には eval.c をこの VM で置き換え
+たいと考えています。
+
+現在の Ruby インタプリタで実行できるすべてのことが、この VM で実現できる
+ように作っています(現段階ではまだ完全ではありませんが、そうなるべきです)。
+
+VM は、単純なスタックマシンとして実装しています。スレッドひとつにスタッ
+クひとつを保持します。スタックの領域はヒープから取得するので、柔軟な領域
+設定が可能です。
+
+
+** レジスタ
+
+VM は 5 つの仮想的なレジスタによって制御されます。
+
+- PC (Program Counter)
+- SP (Stack Pointer)
+- CFP (Control Frame Pointer)
+- LFP (Local Frame Pointer)
+- DFP (Dynamic Frame Pointer)
+
+PC は現在実行中の命令列の位置を示します。SP はスタックトップの位置を示し
+ます。CFP、LFP、DFP はそれぞれフレームの情報を示します。詳細は後述します。
+
+
+** スタックフレーム
+
+obsolete (update soon)
+
+
+** フレームデザインについての補足
+
+Lisp の処理系などをかんがえると、わざわざブロックローカルフレームとメソ
+ッドローカルフレームのようなものを用意するのは奇異に見えるかもしれません。
+あるフレームを、入れ子構造にして、ローカル変数のアクセスはその入れ子を外
+側に辿れば必ずたどり着くことができるからです(つまり、lfp は必要ない)。
+
+しかし、Ruby ではいくつか状況が違います。まず、メソッドローカルな情報が
+あること、具体的にはブロックとself(callee からみると receiver)です。こ
+の情報をそれぞれのフレームにもたせるのは無駄です。
+
+また、Ruby2.0 からはブロックローカル変数はなくなります(ブロックローカル
+引数は残るので、構造自体はあまり変わりません)。そのため、メソッドローカ
+ル変数へのアクセスが頻発することが予想されます。
+
+このとき、メソッドローカル変数へのアクセスのたびにフレーム(スコープ)の
+リストをたどるのは無駄であると判断し、明示的にメソッドローカルスコープと
+ブロックフレームを分離し、ブロックフレームからはメソッドローカルフレーム
+が lfpレジスタによって容易にアクセスできるようにしました。
+
+
+** メソッド呼び出しについて
+
+メソッド呼び出しは、YARV 命令列で記述されたメソッドか、C で記述されたメ
+ソッドかによってディスパッチ手法が変わります。
+
+YARV 命令列であった場合、上述したスタックフレームを作成して命令を継続し
+ます。とくに VM の関数を再帰呼び出すすることは行ないません。
+
+C で記述されたメソッドだった場合、単純にその関数を呼び出します(ただし、
+バックトレースを正しく生成するためにメソッド呼び出しの情報を付加してから
+行ないます)。
+
+このため、VM 用スタックを別途用意したものの、プログラムによってはマシン
+スタックを使い切ってしまう可能性があります(C -> Ruby -> C -> ... という
+呼び出しが続いた場合)。これは、現在では避けられない仕様となっています。
+
+
+** 例外
+
+例外は、Java の JVM と同様に例外テーブルを用意することで実現します。例外
+が発生したら、当該フレームを、例外テーブルを検査します。そこで、例外が発
+生したときの PC の値に合致するエントリがあった場合、そのエントリに従って
+動作します。もしエントリが見つからなかった場合、スタックを撒き戻してまた
+同様にそのスコープの例外テーブルを検査します。
+
+また、break、return(ブロック中)、retry なども同様の仕組みで実現します。
+
+*** 例外テーブル
+
+例外テーブルエントリは具体的には次の情報が格納されています。
+
+- 対象とする PC の範囲
+- 対象とする例外の種類
+- もし対象となったときにジャンプする先(種類による)
+- もし対象となったときに起動するブロックの iseq
+
+
+*** rescue
+
+rescue 節はブロックとして実現しています。$! の値を唯一の引数として持ちま
+す。
+
+#code
+begin
+rescue A
+rescue B
+rescue C
+end
+#end
+
+は、次のような Ruby スクリプトに変換されます。
+
+#code
+{|err|
+ case err
+ when A === err
+ when B === err
+ when C === err
+ else
+ raise # yarv の命令では throw
+ end
+}
+#end
+
+
+*** ensure
+
+正常系(例外が発生しなかった場合)と異常系(例外が発生したときなど)の2
+種類の命令列が生成されます。正常系では、ただの連続したコード領域としてコ
+ンパイルされます。また、異常系ではブロックとして実装します。最後は必ず
+throw 命令で締めることになります。
+
+
+*** break, return(ブロック中)、retry
+
+break 文、ブロック中の return 文、retry 文は throw 命令としてコンパイル
+されます。どこまで戻るかは、break をフックする例外テーブルのエントリが判
+断します。
+
+
+** 定数の検索
+
+定数という名前なのに、Ruby ではコンパイル時に決定しません。というか、い
+つまでも再定義可能になっています。
+
+定数アクセスのためのRuby記述は次のようになります。
+
+#code
+Ruby表現:
+expr::ID::...::ID
+#end
+
+これは、yarv命令セットでは次のようになります。
+
+#code
+(expr)
+getconstant ID
+...
+getconstant ID
+#end
+
+
+*** 定数検索パス
+
+もし expr が nil だった場合、定数検索パスに従って定数を検索します。この
+挙動は今後 Ruby 2.0 に向けて変更される場合があります。
+
++ クラス、モジュールの動的ネスト関係(プログラムの字面上)をルートまで辿る
++ 継承関係をルート(Object)まで辿る
+
+このため、クラス、モジュールの動的ネスト関係を保存しなければなりません。
+このために、thread_object には klass_nest_stack というものを用意しました。
+これは、現在のネストの情報を保存します。
+
+メソッド定義時、その現在のネスト情報をメソッド定義時に(dupして)加える
+ことで、そのメソッドの実行時、そのネスト情報を参照することが可能になりま
+す。
+
+トップレベルでは、その情報はないことになります。
+
+クラス/モジュール定義文実行時は、現在の情報そのものを参照することになり
+ます。これは、クラススコープ突入時、その情報をクラス定義文にコピーします
+(すでにコピーされていれば、これを行いません)。
+
+これにより、動的なネスト情報を統一的に扱うことができます。
+
+
+** 最適化手法
+
+YARV では高速化を目的としているので、さまざまな最適化手法を利用していま
+す。詳細は割愛しますが、以下に述べる最適化などを行なっております。
+
+
+*** threaded code
+
+GCC の C 言語拡張である値としてのラベルを利用して direct threaded code
+を実現しています。
+
+
+*** Peephole optimization
+
+いくつかの簡単な最適化をしています。
+
+
+*** inline method cache
+
+命令列の中にメソッド検索結果を埋め込みます。
+
+
+*** inline constant cache
+
+命令列の中に定数検索結果を埋め込みます。
+
+
+*** ブロックと Proc オブジェクトの分離
+
+ブロック付きメソッド呼び出しが行なわれたときにはすぐにはブロックを Proc
+オブジェクトとして生成しません。これにより、必要ない Proc オブジェクトの
+生成を抑えています。
+
+Proc メソッドは、実際に必要になった時点で作られ、そのときに環境(スコー
+プ上に確保された変数など)をヒープに保存します。
+
+
+*** 特化命令
+
+Fixnum 同士の加算などを正直に関数呼び出しによって行なうと、コストがかか
+るので、これらのプリミティブな操作を行なうためのメソッド呼び出しは専用命
+令を用意しました。
+
+
+*** 命令融合
+
+複数の命令を 1 命令に変換します。融合命令は opt_insn_unif.def の記述によ
+り自動的に生成されます。
+
+
+*** オペランド融合
+
+複数のオペランドを含めた命令を生成します。融合命令は opt_operand.def の
+記述によって自動的に生成されます。
+
+
+*** stack caching
+
+スタックトップを仮想レジスタに保持するようにします。現在は 2 個の仮想レ
+ジスタを想定し、5状態のスタックキャッシングを行ないます。スタックキャッ
+シングする命令は自動的に生成されます。
+
+
+*** JIT Compile
+
+機械語を切り貼りします。非常に実験的なコードものしか作っておりません。ほ
+とんどのプログラムは動きません。
+
+
+*** AOT Compile
+
+YARV 命令列を C 言語に変換します。まだ十分な最適化を行なえておりませんが、
+それなりに動きます。rb/aotc.rb がコンパイラです。
+
+
+* Assembler (rb/yasm.rb)
+
+YARV 命令列のアセンブラを用意しました。使い方は rb/yasm.rb を参照してく
+ださい(まだ、例示してある生成手法のすべてをサポートしているわけではあり
+ません)。
+
+
+* Dis-Assembler (disasm.c)
+
+YARV 命令列を示すオブジェクト YARVCore::InstructionSequence には disasm
+メソッドがあります。これは、命令列を逆アセンブルした文字列を返します。
+
+
+* YARV 命令セット
+
+<%= d %>
+
+* その他
+
+** テスト
+
+test/test_* がテストケースです。一応、ミスなく動くはずです。逆にいうと、
+このテストに記述されている例ではきちんと動作するということです。
+
+
+** ベンチマーク
+
+benchmark/bm_* にベンチマークプログラムがおいてあります。
+
+
+** 今後の予定
+
+まだまだやらなければいけないこと、未実装部分がたくさんありますんでやって
+いかなければなりません。一番大きな目標は eval.c を置き換えることでしょう
+か。
+
+
+*** Verifier
+
+YARV 命令列は、ミスがあっても動かしてしまうため危険である可能性がありま
+す。そのため、スタックの利用状態をきちんと事前に検証するようなベリファイ
+アを用意しなければならないと考えています。
+
+
+*** Compiled File の構想
+
+Ruby プログラムをこの命令セットにシリアライズしたデータ構造をファイルに
+出力できるようにしたいと考えています。これを利用して一度コンパイルした命
+令列をファイルに保存しておけば、次回ロード時にはコンパイルの手間、コスト
+を省くことができます。
+
+
+**** 全体構成
+
+次のようなファイル構成を考えていますが、まだ未定です。
+
+#code
+u4 : 4 byte unsigned storage
+u2 : 2 byte unsigned storage
+u1 : 1 byte unsigned storage
+
+every storages are little endian :-)
+
+CompiledFile{
+ u4 magic;
+
+ u2 major;
+ u2 minor;
+
+ u4 character_code;
+
+ u4 constants_pool_count;
+ ConstantEntry constants_pool[constants_pool_count];
+
+ u4 block_count;
+ blockEntry blocks[block_count];
+
+ u4 method_count;
+ MethodEntry methods[method_count];
+}
+#end
+
+Java classfile のパクリ。
+
diff --git a/template/yasmdata.rb.tmpl b/template/yasmdata.rb.tmpl
new file mode 100644
index 0000000000..a11df0a712
--- /dev/null
+++ b/template/yasmdata.rb.tmpl
@@ -0,0 +1,20 @@
+# -*-ruby-*-
+#
+
+class VM
+ class InstructionSequence
+ class Instruction
+ InsnID2NO = {
+<%= insn_id2no %>
+ }
+
+ def self.id2insn_no id
+ if InsnID2NO.has_key? id
+ InsnID2NO[id]
+ end
+ end
+ end
+ end
+end
+
+