Skip to content

Commit

Permalink
compiler is dead, long live compiler1!
Browse files Browse the repository at this point in the history
Moved the entire current compiler to lib/compiler1 and rearchitected how
the compiler is loaded. It's much simpiler and more powerful that before.
  • Loading branch information
evanphx committed Dec 13, 2007
1 parent faaa193 commit eda2c1b
Show file tree
Hide file tree
Showing 67 changed files with 706 additions and 416 deletions.
61 changes: 46 additions & 15 deletions Rakefile
Expand Up @@ -4,6 +4,7 @@ $VERBOSE = true
$verbose = Rake.application.options.trace $verbose = Rake.application.options.trace
$dlext = Config::CONFIG["DLEXT"] $dlext = Config::CONFIG["DLEXT"]
$redcloth_available = nil $redcloth_available = nil
$compiler = nil


require 'tsort' require 'tsort'
require 'rakelib/struct_generator' require 'rakelib/struct_generator'
Expand Down Expand Up @@ -100,45 +101,56 @@ def create_load_order(files, output=".load_order.txt")
end end
end end


def compile(name, output) def compile(name, output, check_mtime=false)
dir = File.dirname(output) dir = File.dirname(output)


unless File.exists?(dir) unless File.exists?(dir)
FileUtils.mkdir_p dir FileUtils.mkdir_p dir
end end

if check_mtime and File.exists?(output) and File.mtime(output) > File.mtime(name)
return
end

if $compiler
inc = "-I#{$compiler}"
else
inc = ""
end


if ENV['GDB'] if ENV['GDB']
sh "shotgun/rubinius --gdb compile #{name} #{output}", :verbose => $verbose sh "shotgun/rubinius --gdb #{inc} compile #{name} #{output}", :verbose => $verbose
else else
sh "shotgun/rubinius compile #{name} #{output}", :verbose => $verbose sh "shotgun/rubinius #{inc} compile #{name} #{output}", :verbose => $verbose
end end
end end


task :compiler do def compile_dir(dir)
(Dir["#{dir}/*.rb"] + Dir["#{dir}/**/*.rb"]).each do |file|
compile file, "#{file}c", true
end
end

task :stable_compiler do
if ENV['USE_CURRENT'] if ENV['USE_CURRENT']
puts "Use current versions, not stable." puts "Use current versions, not stable."
else else
$compiler = "runtime/stable/compiler1.rba"
ENV['RBX_BOOTSTRAP'] = "runtime/stable/bootstrap.rba" ENV['RBX_BOOTSTRAP'] = "runtime/stable/bootstrap.rba"
ENV['RBX_COMPILER'] = "runtime/stable/compiler.rba"
ENV['RBX_CORE'] = "runtime/stable/core.rba" ENV['RBX_CORE'] = "runtime/stable/core.rba"
ENV['RBX_LOADER'] = "runtime/stable/loader.rbc" ENV['RBX_LOADER'] = "runtime/stable/loader.rbc"
ENV['RBX_PLATFORM'] = "runtime/stable/platform.rba" ENV['RBX_PLATFORM'] = "runtime/stable/platform.rba"
end end
end end


task :stable_shell => :compiler do task :stable_shell => :stable_compiler do
sh "shotgun/rubinius --gdb" sh "shotgun/rubinius --gdb"
end end


rule ".rbc" => %w[compiler .rb] do |t| rule ".rbc" => %w[compiler .rb] do |t|
compile t.source, t.name compile t.source, t.name
end end


#file 'runtime/core/kernel/core/proc.rbc' => 'kernel/core/proc.rb' do |t|
# p t.prerequisites
# p t.name
#end

class CodeGroup class CodeGroup


def initialize(files, compile_dir, rba_name, load_order=true) def initialize(files, compile_dir, rba_name, load_order=true)
Expand Down Expand Up @@ -238,7 +250,6 @@ Core = CodeGroup.new(files, 'runtime/core', 'core')
Bootstrap = CodeGroup.new 'kernel/bootstrap/*.rb', 'runtime/bootstrap', Bootstrap = CodeGroup.new 'kernel/bootstrap/*.rb', 'runtime/bootstrap',
'bootstrap' 'bootstrap'
Platform = CodeGroup.new 'kernel/platform/*.rb', 'runtime/platform', 'platform' Platform = CodeGroup.new 'kernel/platform/*.rb', 'runtime/platform', 'platform'
Compiler = CodeGroup.new 'compiler/**/*.rb', 'runtime', 'compiler', false


file 'runtime/loader.rbc' => 'kernel/loader.rb' do file 'runtime/loader.rbc' => 'kernel/loader.rb' do
compile 'kernel/loader.rb', 'runtime/loader.rbc' compile 'kernel/loader.rb', 'runtime/loader.rbc'
Expand All @@ -248,6 +259,10 @@ file 'runtime/stable/loader.rbc' => 'runtime/loader.rbc' do
cp 'runtime/loader.rbc', 'runtime/stable', :verbose => $verbose cp 'runtime/loader.rbc', 'runtime/stable', :verbose => $verbose
end end


file 'runtime/stable/compiler1.rba' => 'build:compiler1' do
sh "cd lib; zip -r ../runtime/stable/compiler1.rba compiler1 -x \\*.rb"
end

Rake::StructGeneratorTask.new do |t| Rake::StructGeneratorTask.new do |t|
t.dest = "kernel/core/dir.rb" t.dest = "kernel/core/dir.rb"
end end
Expand All @@ -260,7 +275,7 @@ Rake::StructGeneratorTask.new do |t|
t.dest = 'lib/zlib.rb' t.dest = 'lib/zlib.rb'
end end


AllPreCompiled = Core.output + Bootstrap.output + Platform.output + Compiler.output AllPreCompiled = Core.output + Bootstrap.output + Platform.output
AllPreCompiled << "runtime/loader.rbc" AllPreCompiled << "runtime/loader.rbc"


# spec tasks # spec tasks
Expand Down Expand Up @@ -367,6 +382,12 @@ task :config_env => 'shotgun/config.mk' do
end end
end end


task :compiledir => :stable_compiler do
dir = ENV['DIR']
raise "Use DIR= to set which directory" if !dir or dir.empty?
compile_dir(dir)
end

desc "Recompile all ruby system files" desc "Recompile all ruby system files"
task :rebuild => %w[clean:rbc clean:shotgun build:all] task :rebuild => %w[clean:rbc clean:shotgun build:all]


Expand All @@ -380,6 +401,7 @@ task :pristine do
FileList['**/*.rbc'].each do |fn| FileList['**/*.rbc'].each do |fn|
next if /^runtime/.match(fn) next if /^runtime/.match(fn)
next if /require\/require_spec_.\.rbc/.match(fn) next if /require\/require_spec_.\.rbc/.match(fn)
next if %r!lib/compiler1!.match(fn)
FileUtils.rm fn rescue nil FileUtils.rm fn rescue nil
end end
end end
Expand All @@ -391,6 +413,10 @@ namespace :clean do
AllPreCompiled.each do |f| AllPreCompiled.each do |f|
rm_f f, :verbose => $verbose rm_f f, :verbose => $verbose
end end

(Dir["lib/compiler1/*.rbc"] + Dir["lib/compiler1/**/*.rbc"]).each do |f|
rm_f f, :verbose => $verbose
end
end end


desc "Cleans up VM building site" desc "Cleans up VM building site"
Expand All @@ -409,6 +435,7 @@ namespace :build do
task :all => %w[ task :all => %w[
build:shotgun build:shotgun
build:rbc build:rbc
compiler1
lib/etc.rb lib/etc.rb
lib/rbconfig.rb lib/rbconfig.rb
extensions extensions
Expand Down Expand Up @@ -441,16 +468,20 @@ namespace :build do
desc "Compiles shotgun (the C-code VM)" desc "Compiles shotgun (the C-code VM)"
task :shotgun => %w[configure shotgun/rubinius.bin] task :shotgun => %w[configure shotgun/rubinius.bin]


task :setup_rbc => :compiler task :setup_rbc => :stable_compiler


task :rbc => ([:setup_rbc] + AllPreCompiled) task :rbc => ([:setup_rbc] + AllPreCompiled)

task :compiler1 => :stable_compiler do
compile_dir "lib/compiler1"
end


desc "Rebuild runtime/stable/*. If you don't know why you're running this, don't." desc "Rebuild runtime/stable/*. If you don't know why you're running this, don't."
task :stable => %w[ task :stable => %w[
build:all build:all
runtime/stable/bootstrap.rba runtime/stable/bootstrap.rba
runtime/stable/compiler.rba
runtime/stable/core.rba runtime/stable/core.rba
runtime/stable/compiler1.rba
runtime/stable/loader.rbc runtime/stable/loader.rbc
runtime/stable/platform.rba runtime/stable/platform.rba
] ]
Expand Down
165 changes: 0 additions & 165 deletions compiler2/compiler.rb

This file was deleted.

16 changes: 8 additions & 8 deletions doc/vm/op_code_info.rb
@@ -1,6 +1,6 @@
$: << File.dirname(__FILE__) + '/../../compiler' $: << File.dirname(__FILE__) + '/../../lib'
require 'bytecode/encoder' require 'compiler1/bytecode/encoder'
require 'bytecode/assembler' require 'compiler1/bytecode/assembler'
require 'yaml' require 'yaml'




Expand All @@ -20,11 +20,11 @@ module OpCode
# Some information is gleaned from Rubinius source files, while # Some information is gleaned from Rubinius source files, while
# descriptive info comes from opcode YAML files. # descriptive info comes from opcode YAML files.
class Info class Info
@@op_codes = Bytecode::InstructionEncoder::OpCodes @@op_codes = Compiler1::Bytecode::InstructionEncoder::OpCodes
@@int_arg = Bytecode::InstructionEncoder::IntArg @@int_arg = Compiler1::Bytecode::InstructionEncoder::IntArg
@@two_int = Bytecode::InstructionEncoder::TwoInt @@two_int = Compiler1::Bytecode::InstructionEncoder::TwoInt
@@instructs = ShotgunInstructions.new @@instructs = ShotgunInstructions.new
@@translations = Bytecode::Assembler::Translations.invert @@translations = Compiler1::Bytecode::Assembler::Translations.invert


def self.op_codes def self.op_codes
@@op_codes @@op_codes
Expand Down Expand Up @@ -71,4 +71,4 @@ def <=>(b)
to_s <=> b.to_s to_s <=> b.to_s
end end
end end
end end

0 comments on commit eda2c1b

Please sign in to comment.