<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array">
    <added>
      <filename>kernel/compiler/blocks.rb</filename>
    </added>
    <added>
      <filename>kernel/compiler/blocks_graph.rb</filename>
    </added>
    <added>
      <filename>kernel/compiler/bytecode.rb</filename>
    </added>
    <added>
      <filename>kernel/compiler/compile.rb</filename>
    </added>
    <added>
      <filename>kernel/compiler/compiled_file.rb</filename>
    </added>
    <added>
      <filename>kernel/compiler/compiler.rb</filename>
    </added>
    <added>
      <filename>kernel/compiler/execute.rb</filename>
    </added>
    <added>
      <filename>kernel/compiler/generator.rb</filename>
    </added>
    <added>
      <filename>kernel/compiler/graph.rb</filename>
    </added>
    <added>
      <filename>kernel/compiler/iseq.rb</filename>
    </added>
    <added>
      <filename>kernel/compiler/local.rb</filename>
    </added>
    <added>
      <filename>kernel/compiler/node.rb</filename>
    </added>
    <added>
      <filename>kernel/compiler/nodes.rb</filename>
    </added>
    <added>
      <filename>kernel/compiler/plugins.rb</filename>
    </added>
    <added>
      <filename>kernel/compiler/sexp.rb</filename>
    </added>
    <added>
      <filename>kernel/compiler/stack.rb</filename>
    </added>
    <added>
      <filename>kernel/compiler/sydney_rewriter.rb</filename>
    </added>
    <added>
      <filename>kernel/compiler/text.rb</filename>
    </added>
  </added>
  <modified type="array">
    <modified>
      <diff>@@ -612,6 +612,138 @@ module Kernel
     &quot;#&lt;#{self.__class__}:0x#{self.__id__.to_s(16)}&gt;&quot;
   end
 
+  def compile(path, out=nil, flags=nil)
+    out = &quot;#{path}c&quot; unless out
+    cm = Compiler::Utils.compile_file(path, flags)
+    raise LoadError, &quot;Unable to compile '#{path}'&quot; unless cm
+    Rubinius::CompiledFile.dump cm, out
+    return out
+  end
+  module_function :compile
+
+  ##
+  # Loads the given file as executable code and returns true. If
+  # the file cannot be found, cannot be compiled or some other
+  # error occurs, LoadError is raised with an explanation.
+  #
+  # Unlike #require, the file extension if any must be present but
+  # is not restricted to .rb, .rbc or .&lt;platform shared lib ext&gt;.
+  # Any other extensions (or no extension) are assumed to be plain
+  # Ruby files. The only exceptions to this rule are:
+  #
+  # 1.  if given a .rb or no/any-extensioned file and there is a
+  #     compiled version of the same file that is not older than
+  #     the source file (based on File.mtime), the compiled one
+  #     is loaded directly to avoid the compilation overhead.
+  # 2.  if a .rb file is given but it does not exist, the system
+  #     will try to load the corresponding .rbc instead (to allow
+  #     distributing just .rbc files.)
+  #
+  # If the path given starts with ./, ../, ~/ or /, it is treated
+  # as a &quot;qualified&quot; file and will be loaded directly (after path
+  # expansion) instead of matching against $LOAD_PATH. The relative
+  # paths use Dir.pwd.
+  #
+  # If the filename is plain (unqualified) then it is sequentially
+  # prefixed with each path in $LOAD_PATH ($:) to locate the file,
+  # using the first one that exists. If none of the resulting paths
+  # exist, LoadError is raised. Unqualified names may contain path
+  # elements so directories are valid targets and can be used with
+  # $LOAD_PATH.
+  #
+  # A few extra options are supported. If the second parameter is
+  # true, then the module is wrapped inside an anonymous module for
+  # loading to avoid polluting the namespace. This is actually a
+  # shorthand for passing in :wrap =&gt; true-ish in the second arg
+  # which may be an option Hash.
+  #
+  # If :recompile in option Hash is true-ish then the file in
+  # question is recompiled each time. If the source file is not
+  # present when recompiling is requested, a LoadError is raised.
+  #
+  # TODO: Support non-UNIX paths.
+  #
+  # TODO: The anonymous module wrapping is not implemented at all.
+  #
+  def load(path, opts = {:wrap =&gt; false, :recompile =&gt; false})
+    path = StringValue(path)
+    # Remap all library extensions behind the scenes, just like MRI
+    path.gsub!(/\.(so|bundle|dll|dylib)$/, &quot;#{Rubinius::LIBSUFFIX}&quot;)
+
+    opts = {:wrap =&gt; !!opts, :recompile =&gt; false} unless Hash === opts
+
+    if path.suffix? '.rbc'
+      rb, rbc, ext = nil, path, nil
+    elsif path.suffix? '.rb'
+      rb, rbc, ext = path, &quot;#{path}c&quot;, nil
+    elsif path.suffix? &quot;#{Rubinius::LIBSUFFIX}&quot;
+      rb, rbc, ext = nil, nil, path
+    else
+      dir, name = File.split(path)
+      rb = path
+      ext = nil
+
+      if name[0] == ?.
+        rbc = nil
+      else
+        rbc = &quot;#{dir}/#{name}.compiled.rbc&quot;
+      end
+    end
+
+    Compiler::Utils.unified_load path, rb, rbc, ext, nil, opts
+  end
+  module_function :load
+
+  # Attempt to load the given file, returning true if successful.
+  # If the file has already been successfully loaded and exists
+  # in $LOADED_FEATURES, it will not be re-evaluated and false
+  # is returned instead. If the filename cannot be resolved,
+  # a LoadError is raised.
+  #
+  # The file can have one of the following extensions:
+  #
+  # [.rb]                   Plain Ruby source file.
+  # [.rbc]                  Compiled Ruby source file.
+  # [.o, .so, .dylib, .dll] Shared library (platform-specific.)
+  # [&lt;none&gt;]                Filename without extension.
+  #
+  # (.rba files should be loaded using CodeArchive.load_everything.)
+  #
+  # If the file does not have an extension, #require attempts to
+  # match it using .rb, .rbc and .&lt;shared extension&gt; as extensions,
+  # in that order, instead. If foo.rb does not exist but foo.rbc
+  # does, the latter will be loaded even if called with foo.rb.
+  #
+  # If the path given starts with ./, ../, ~/ or /, it is treated
+  # as a &quot;qualified&quot; file and will be loaded directly (after path
+  # expansion) instead of matching against $LOAD_PATH. The relative
+  # paths use Dir.pwd.
+  #
+  # If the filename is plain (unqualified) then it is sequentially
+  # prefixed with each path in $LOAD_PATH ($:) to locate the file,
+  # using the first one that exists. If none of the resulting paths
+  # exist, LoadError is raised. Unqualified names may contain path
+  # elements so directories are valid targets and can be used with
+  # $LOAD_PATH.
+  #
+  # TODO: Support non-UNIX paths.
+  #
+  # TODO: See if we can safely use 1.9 rules with $LOADED_FEATURES,
+  #       i.e. expand paths into it. This should be possible if it
+  #       is completely transparent to the user in all normal cases.
+  #
+  # Each successfully loaded file is added to $LOADED_FEATURES
+  # ($&quot;), using the original unexpanded filename (with the
+  # exception that the file extension is added.)
+  #
+  def require(path)
+    path = StringValue(path)
+    rb, rbc, ext = Compiler::Utils.split_path path
+    Autoload.remove(rb)
+    Compiler::Utils.unified_load path, rb, rbc, ext, true
+  end
+  module_function :require
+
   def autoload(name, file)
     Object.autoload(name, file)
   end</diff>
      <filename>kernel/common/kernel.rb</filename>
    </modified>
    <modified>
      <diff>@@ -1,5 +1,3 @@
-# depends on: iseq.rb
-
 ##
 # Breakpoint objects represent debugging breakpoints in the bytecode of
 # CompiledMethod objects.
@@ -18,11 +16,9 @@ class Breakpoint
   self.private_class_method :new
 
   # Define a single encoder instance to be used for all breakpoints
-  @encoder = InstructionSequence::Encoder.new
-
   # Returns the shared class InstructionSequence::Encoder instance.
   def Breakpoint.encoder
-    @encoder
+    @encoder ||= InstructionSequence::Encoder.new
   end
 
   # Initializes the breakpoint</diff>
      <filename>kernel/delta/breakpoint.rb</filename>
    </modified>
    <modified>
      <diff>@@ -97,9 +97,6 @@ script = nil
 
 begin
 
-  # TODO: Temporary until compiler is refactored
-  Compiler::Utils.load_compiler
-
   script_debug_requested = false
   until ARGV.empty?
     arg = ARGV.shift</diff>
      <filename>kernel/loader.rb</filename>
    </modified>
    <modified>
      <diff>@@ -3,8 +3,6 @@ require 'rubygems'
 
 $:.push &quot;lib&quot;
 require 'ruby_parser'
-require 'compiler/text'
-require 'compiler/stack'
 $:.pop
 
 class Executable
@@ -12,9 +10,24 @@ class Executable
   attr_accessor :primitive
 end
 
-require File.dirname(__FILE__) + '/../../kernel/delta/compiled_file'
-require File.dirname(__FILE__) + '/../../kernel/delta/iseq'
-require File.dirname(__FILE__) + '/../../kernel/common/compiled_method'
+$: &lt;&lt; File.expand_path(File.dirname(__FILE__) + '/../../kernel')
+require 'compiler/blocks'
+require 'compiler/blocks_graph'
+require 'compiler/compiler'
+require 'compiler/node'
+require 'compiler/nodes'
+require 'compiler/iseq'
+require 'compiler/generator'
+require 'compiler/bytecode'
+require 'compiler/compiled_file'
+require 'compiler/execute'
+require 'compiler/text'
+require 'compiler/graph'
+require 'compiler/local'
+require 'compiler/plugins'
+require 'compiler/stack'
+require 'common/compiled_method'
+$:.pop
 
 class SendSite
   def initialize(name)</diff>
      <filename>lib/compiler/mri_shim.rb</filename>
    </modified>
    <modified>
      <diff>@@ -89,108 +89,106 @@ def compile_ruby(src, rbc, check_mtime = false, kernel = false)
 end
 
 # drake does not allow invoke to be called inside tasks
-
 def kernel_clean
-  rm_rf %w[runtime/bootstrap runtime/platform runtime/common runtime/delta],
-        :verbose =&gt; $verbose
-
-  files_to_delete = []
-  files_to_delete += Dir[&quot;*.rbc&quot;] + Dir[&quot;**/*.rbc&quot;] + Dir[&quot;**/.*.rbc&quot;]
-  files_to_delete += Dir[&quot;**/load_order.txt&quot;]
-  files_to_delete += [&quot;runtime/platform.conf&quot;]
-
-  rm_f files_to_delete, :verbose =&gt; $verbose
+  rm_f Dir[&quot;**/*.rbc&quot;,
+           &quot;**/.*.rbc&quot;,
+           &quot;runtime/**/load_order.txt&quot;,
+           &quot;runtime/platform.conf&quot;],
+    :verbose =&gt; $verbose
 end
 
-loose =  []
-modules = Hash.new { |h,k| h[k] = [] }
-
-Dir[&quot;kernel/**/*.rb&quot;].each do |path|
-  _, mod, file = path.split(&quot;/&quot;)
+# The default rule for compiling all kernel files use the
+# rbx-kernel compiler flag. Other files are exception cases.
+rule &quot;.rbc&quot; do |t|
+  rbc = t.name
+  src = t.prerequisites.first
 
-  if file
-    modules[mod] &lt;&lt; path
-  else
-    loose &lt;&lt; mod
-  end
+  compile_ruby src, rbc, false, true
 end
 
-all_kernel = []
-all_kernel &lt;&lt; 'kernel/bootstrap/rubinius_config.rb'
-all_kernel &lt;&lt; 'kernel/bootstrap/ruby_config.rb'
+# Create file dependencies for all kernel files
+unless File.exists? &quot;runtime/index&quot;
+  raise &quot;unable to build kernel, runtime/index is missing&quot;
+else
+  subdirs = IO.readlines(&quot;runtime/index&quot;).map { |line| line.chomp }
+end
 
-modules['bootstrap'] &lt;&lt; 'kernel/bootstrap/rubinius_config.rb'
-modules['bootstrap'] &lt;&lt; 'kernel/bootstrap/ruby_config.rb'
-modules.each do |name, files|
-  files.each do |rb|
-    rbc = &quot;runtime/#{name}/#{File.basename(rb)}c&quot;
-    all_kernel &lt;&lt; rbc
+kernel = [&quot;runtime/platform.conf&quot;]
 
-    file rbc =&gt; rb do
-      compile_ruby rb, rbc, false, true
-    end
+subdirs.each do |subdir|
+  Dir[&quot;kernel/#{subdir}/*.rb&quot;].each do |rb|
+    rbc = &quot;runtime/#{subdir}/#{File.basename(rb)}c&quot;
+    kernel &lt;&lt; rbc
+    file rbc =&gt; rb
   end
 end
 
-all_kernel &lt;&lt; 'runtime/alpha.rbc'
-all_kernel &lt;&lt; 'runtime/loader.rbc'
+rb  = &quot;kernel/bootstrap/rubinius_config.rb&quot;
+rbc = &quot;runtime/bootstrap/rubinius_config.rbc&quot;
+file rbc =&gt; rb
+kernel &lt;&lt; rb &lt;&lt; rbc
 
-file 'runtime/alpha.rbc' =&gt; 'kernel/alpha.rb' do |t|
-  rbc = t.name
-  src = t.prerequisites.first
-
-  compile_ruby src, rbc, false, true
-end
+rb  = &quot;kernel/bootstrap/ruby_config.rb&quot;
+rbc = &quot;runtime/bootstrap/ruby_config.rbc&quot;
+file rbc =&gt; rb
+kernel &lt;&lt; rb &lt;&lt; rbc
 
-file 'runtime/loader.rbc' =&gt; 'kernel/loader.rb'
+file &quot;runtime/alpha.rbc&quot; =&gt; &quot;kernel/alpha.rb&quot;
+kernel &lt;&lt; &quot;runtime/alpha.rbc&quot;
 
-rule &quot;.rbc&quot; do |t|
+file &quot;runtime/loader.rbc&quot; =&gt; &quot;kernel/loader.rb&quot; do |t|
   rbc = t.name
   src = t.prerequisites.first
 
-  compile_ruby src, rbc
+  compile_ruby src, rbc, false, true
 end
-
-COMPILER_SOURCES = Dir[&quot;lib/compiler/*.rb&quot;] +
-  %w(strscan stringio racc/parser ruby_lexer ruby_parser
-     ruby_parser_extras sexp sexp_processor).map { |f| &quot;lib/#{f}.rb&quot; }
-COMPILER_SOURCES &lt;&lt; &quot;kernel/delta/compiled_file.rb&quot;
-COMPILER_MTIME = COMPILER_SOURCES.map { |f| File::Stat.new(f).mtime }.max
-compiler = []
-
-COMPILER_SOURCES.each do |rb|
-  compiler &lt;&lt; &quot;#{rb}c&quot;
-  file &quot;#{rb}c&quot; =&gt; rb do
-    compile_ruby rb, &quot;#{rb}c&quot;, false, true
+kernel &lt;&lt; &quot;runtime/loader.rbc&quot;
+
+# TODO: extra_compiler is temporary until sexp processing is removed
+# from the compiler.
+extra_compiler = [&quot;lib/strscan.rb&quot;,
+                  &quot;lib/stringio.rb&quot;,
+                  &quot;lib/racc/parser.rb&quot;,
+                  &quot;lib/ruby_lexer.rb&quot;,
+                  &quot;lib/ruby_parser.rb&quot;,
+                  &quot;lib/ruby_parser_extras.rb&quot;,
+                  &quot;lib/sexp_processor.rb&quot;]
+extra_compiler.each do |rb|
+  rbc = &quot;#{rb}c&quot;
+  kernel &lt;&lt; rbc
+
+  file rbc =&gt; rb do |t|
+    src = t.prerequisites.first
+    dst = t.name
+
+    compile_ruby src, dst
   end
 end
 
+desc &quot;Build all kernel files&quot;
 task :kernel =&gt; 'kernel:build'
 
 namespace :kernel do
   task :check_compiler do
-    kernel_mtime = all_kernel.select do |f|
-      f =~ /rbc$/ and File.exist? f
-    end.map do |f|
-      File::Stat.new(f).mtime
-    end.min
+    unless ENV['NOCLEAN']
+      existing = kernel.select { |name| name =~ /rbc$/ and File.exists? name }
+      kernel_mtime = existing.map { |name| File.stat(name).mtime }.min
 
-    kernel_clean if !kernel_mtime or COMPILER_MTIME &gt; kernel_mtime unless ENV['NOCLEAN']
-  end
+      compiler = (Dir[&quot;kernel/compiler/*.rb&quot;] + extra_compiler)
+      compiler_mtime = compiler.map { |name| File.stat(name).mtime }.max
 
-  task :show do
-    p modules
-    p loose
+      kernel_clean if !kernel_mtime or compiler_mtime &gt; kernel_mtime
+    end
   end
 
-  task :build =&gt; ['kernel:check_compiler', all_kernel, compiler,
-                  'runtime/platform.conf'].flatten do
-    modules.each do |name, files|
-      create_load_order files, &quot;runtime/#{name}/load_order.txt&quot;
+  task :build =&gt; ['kernel:check_compiler'] + kernel + extra_compiler do
+    subdirs.each do |subdir|
+      files = Dir[&quot;kernel/#{subdir}/*.rb&quot;]
+      create_load_order files, &quot;runtime/#{subdir}/load_order.txt&quot;
     end
   end
 
-  desc &quot;clean up rbc files&quot;
+  desc &quot;Delete all .rbc files&quot;
   task :clean do
     kernel_clean
   end
@@ -228,4 +226,3 @@ namespace :kernel do
   end
 
 end
-</diff>
      <filename>rakelib/kernel.rake</filename>
    </modified>
    <modified>
      <diff>@@ -410,7 +410,7 @@ end
 
 file 'vm/primitives.o'                =&gt; 'vm/codegen/field_extract.rb'
 file 'vm/primitives.o'                =&gt; TYPE_GEN
-file 'vm/codegen/instructions_gen.rb' =&gt; 'kernel/delta/iseq.rb'
+file 'vm/codegen/instructions_gen.rb' =&gt; 'kernel/compiler/iseq.rb'
 file 'vm/instructions.rb'             =&gt; 'vm/gen'
 file 'vm/instructions.rb'             =&gt; 'vm/codegen/instructions_gen.rb'
 file 'vm/test/test_instructions.hpp'  =&gt; 'vm/codegen/instructions_gen.rb'</diff>
      <filename>rakelib/vm.rake</filename>
    </modified>
    <modified>
      <diff>@@ -2,3 +2,4 @@ bootstrap
 platform
 common
 delta
+compiler</diff>
      <filename>runtime/index</filename>
    </modified>
    <modified>
      <diff>@@ -12,7 +12,7 @@ class Object # for vm debugging
 end
 
 require 'yaml'
-require &quot;#{File.dirname(__FILE__)}/../../kernel/delta/iseq&quot;
+require &quot;#{File.dirname(__FILE__)}/../../kernel/compiler/iseq&quot;
 require 'rubygems'
 require 'parse_tree'
 </diff>
      <filename>vm/codegen/instructions_gen.rb</filename>
    </modified>
  </modified>
  <removed type="array">
    <removed>
      <filename>kernel/common/compile.rb</filename>
    </removed>
    <removed>
      <filename>kernel/delta/compiled_file.rb</filename>
    </removed>
    <removed>
      <filename>kernel/delta/iseq.rb</filename>
    </removed>
    <removed>
      <filename>lib/compiler/blocks.rb</filename>
    </removed>
    <removed>
      <filename>lib/compiler/blocks_graph.rb</filename>
    </removed>
    <removed>
      <filename>lib/compiler/bytecode.rb</filename>
    </removed>
    <removed>
      <filename>lib/compiler/compiler.rb</filename>
    </removed>
    <removed>
      <filename>lib/compiler/execute.rb</filename>
    </removed>
    <removed>
      <filename>lib/compiler/generator.rb</filename>
    </removed>
    <removed>
      <filename>lib/compiler/graph.rb</filename>
    </removed>
    <removed>
      <filename>lib/compiler/local.rb</filename>
    </removed>
    <removed>
      <filename>lib/compiler/node.rb</filename>
    </removed>
    <removed>
      <filename>lib/compiler/nodes.rb</filename>
    </removed>
    <removed>
      <filename>lib/compiler/plugins.rb</filename>
    </removed>
    <removed>
      <filename>lib/compiler/stack.rb</filename>
    </removed>
    <removed>
      <filename>lib/compiler/sydney_rewriter.rb</filename>
    </removed>
    <removed>
      <filename>lib/compiler/text.rb</filename>
    </removed>
  </removed>
  <parents type="array">
    <parent>
      <id>3ed339238a238db64d53b30e7ffbf558be38731f</id>
    </parent>
  </parents>
  <author>
    <name>Brian Ford</name>
    <email>bford@engineyard.com</email>
  </author>
  <url>http://github.com/evanphx/rubinius/commit/4dc34cab851a6d2b307baf7454637a047e14988d</url>
  <id>4dc34cab851a6d2b307baf7454637a047e14988d</id>
  <committed-date>2009-02-22T23:49:34-08:00</committed-date>
  <authored-date>2009-02-22T15:08:04-08:00</authored-date>
  <message>Move the patient to the operating room.</message>
  <tree>6a4690a3b38ebe2e84ba2c964d1dabb900465c00</tree>
  <committer>
    <name>Brian Ford</name>
    <email>bford@engineyard.com</email>
  </committer>
</commit>
