Skip to content

Commit

Permalink
Move compiler2 => compiler, and Compiler2 => Compiler
Browse files Browse the repository at this point in the history
  • Loading branch information
evanphx committed Jan 9, 2008
1 parent 5aa5cc6 commit 85e9849
Show file tree
Hide file tree
Showing 59 changed files with 169 additions and 6,469 deletions.
99 changes: 40 additions & 59 deletions Rakefile
Expand Up @@ -102,24 +102,20 @@ def create_load_order(files, output=".load_order.txt")
end end
end end


def compile(name, output, check_mtime=false) def compile(name, output=nil, check_mtime=false)
dir = File.dirname(output) if 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) if check_mtime and File.exists?(output) and File.mtime(output) > File.mtime(name)
return return
end
end end


if $compiler == :c2 inc = "-Iruntime/stable/compiler2.rba -rcompiler2/init"
inc = "-Iruntime/stable/compiler2.rba -rcompiler2/init"
elsif $compiler
inc = "-I#{$compiler} -rcompiler1/init"
else
inc = ""
end


if ENV['GDB'] if ENV['GDB']
sh "shotgun/rubinius --gdb #{inc} compile #{name} #{output}", :verbose => $verbose sh "shotgun/rubinius --gdb #{inc} compile #{name} #{output}", :verbose => $verbose
Expand All @@ -138,11 +134,6 @@ 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
if ENV['USE_C1']
$compiler = "runtime/stable/compiler1.rba"
else
$compiler = :c2
end
ENV['RBX_BOOTSTRAP'] = "runtime/stable/bootstrap.rba" ENV['RBX_BOOTSTRAP'] = "runtime/stable/bootstrap.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"
Expand Down Expand Up @@ -266,12 +257,8 @@ 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 file 'runtime/stable/compiler.rba' => 'build:compiler' do
sh "cd lib; zip -r ../runtime/stable/compiler1.rba compiler1 -x \\*.rb" sh "cd lib; zip -r ../runtime/stable/compiler.rba compiler -x \\*.rb"
end

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


Rake::StructGeneratorTask.new do |t| Rake::StructGeneratorTask.new do |t|
Expand Down Expand Up @@ -409,8 +396,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 %r!fixtures/require!.match(fn) next if %r!fixtures/require!.match(fn)
next if %r!lib/compiler1!.match(fn) next if %r!lib/compiler!.match(fn)
next if %r!lib/compiler2!.match(fn)
FileUtils.rm fn rescue nil FileUtils.rm fn rescue nil
end end
end end
Expand All @@ -423,11 +409,7 @@ namespace :clean do
rm_f f, :verbose => $verbose rm_f f, :verbose => $verbose
end end


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

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


Expand Down Expand Up @@ -458,8 +440,7 @@ namespace :build do
build:shotgun build:shotgun
build:platform build:platform
build:rbc build:rbc
compiler1 compiler
compiler2
lib/etc.rb lib/etc.rb
lib/rbconfig.rb lib/rbconfig.rb
extensions extensions
Expand Down Expand Up @@ -496,21 +477,16 @@ namespace :build do


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


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

task :compiler2 => :stable_compiler do
compile_dir "lib/compiler2"
end 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/core.rba runtime/stable/core.rba
runtime/stable/compiler1.rba runtime/stable/compiler.rba
runtime/stable/compiler2.rba
runtime/stable/loader.rbc runtime/stable/loader.rbc
runtime/stable/platform.rba runtime/stable/platform.rba
] ]
Expand Down Expand Up @@ -658,7 +634,7 @@ namespace :extension do
'lib/ext/digest/md5/*.h', 'lib/ext/digest/md5/*.h',
'lib/ext/digest/defs.h', 'lib/ext/digest/defs.h',
] do ] do
sh './shotgun/rubinius compile lib/ext/digest/md5' compile 'lib/ext/digest/md5'
end end


task :fcntl => "lib/ext/fcntl/fcntl.#{$dlext}" task :fcntl => "lib/ext/fcntl/fcntl.#{$dlext}"
Expand All @@ -668,7 +644,7 @@ namespace :extension do
'lib/ext/fcntl/build.rb', 'lib/ext/fcntl/build.rb',
'lib/ext/fcntl/*.c' 'lib/ext/fcntl/*.c'
] do ] do
sh "./shotgun/rubinius compile lib/ext/fcntl" compile "lib/ext/fcntl"
end end


task :syck => "lib/ext/syck/rbxext.#{$dlext}" task :syck => "lib/ext/syck/rbxext.#{$dlext}"
Expand All @@ -679,7 +655,7 @@ namespace :extension do
'lib/ext/syck/*.c', 'lib/ext/syck/*.c',
'lib/ext/syck/*.h', 'lib/ext/syck/*.h',
] do ] do
sh "./shotgun/rubinius compile lib/ext/syck" compile "lib/ext/syck"
end end


task :mongrel => "lib/ext/mongrel/http11.#{$dlext}" task :mongrel => "lib/ext/mongrel/http11.#{$dlext}"
Expand All @@ -690,7 +666,7 @@ namespace :extension do
'lib/ext/mongrel/*.c', 'lib/ext/mongrel/*.c',
'lib/ext/mongrel/*.h', 'lib/ext/mongrel/*.h',
] do ] do
sh "./shotgun/rubinius compile lib/ext/mongrel" compile "lib/ext/mongrel"
end end


task :zlib => %W[lib/ext/zlib/zlib.#{$dlext} lib/zlib.rb] task :zlib => %W[lib/ext/zlib/zlib.#{$dlext} lib/zlib.rb]
Expand All @@ -700,7 +676,7 @@ namespace :extension do
'lib/ext/zlib/build.rb', 'lib/ext/zlib/build.rb',
'lib/ext/zlib/*.c' 'lib/ext/zlib/*.c'
] do ] do
sh "./shotgun/rubinius compile lib/ext/zlib" compile "lib/ext/zlib"
end end


task :readline => %W[lib/ext/readline/readline.#{$dlext} lib/readline.rb] task :readline => %W[lib/ext/readline/readline.#{$dlext} lib/readline.rb]
Expand All @@ -710,7 +686,7 @@ namespace :extension do
'lib/ext/readline/build.rb', 'lib/ext/readline/build.rb',
'lib/ext/readline/*.c' 'lib/ext/readline/*.c'
] do ] do
sh "./shotgun/rubinius compile lib/ext/readline" compile "lib/ext/readline"
end end
end end


Expand Down Expand Up @@ -746,19 +722,24 @@ namespace "doc" do


desc "Generate HTML in doc/vm from YAML and Textile sources" desc "Generate HTML in doc/vm from YAML and Textile sources"
task "html" task "html"


# Define tasks for each opcode html file on the corresponding YAML file begin
require 'doc/vm/op_code_info' # Define tasks for each opcode html file on the corresponding YAML file
OpCode::Info.op_codes.each do |op| require 'doc/vm/op_code_info'
html = "doc/vm/op_codes/#{op}.html" OpCode::Info.op_codes.each do |op|
yaml = "doc/vm/op_codes/#{op}.yaml" html = "doc/vm/op_codes/#{op}.html"
file html => yaml do yaml = "doc/vm/op_codes/#{op}.yaml"
cd 'doc/vm' do file html => yaml do
ruby "gen_op_code_html.rb #{op}" cd 'doc/vm' do
ruby "gen_op_code_html.rb #{op}"
end
end end

task "html" => html
end end


task "html" => html rescue LoadError

end end


# Define tasks for each section html file on the corresponding textile file # Define tasks for each section html file on the corresponding textile file
Expand Down
2 changes: 1 addition & 1 deletion bin/ci
@@ -1,6 +1,6 @@
#!/usr/bin/env ruby #!/usr/bin/env ruby


CI_FILE_SPECS = ['spec/ruby/1.8/core', 'spec/ruby/1.8/language', 'spec/compiler2', 'spec/parser'] CI_FILE_SPECS = ['spec/ruby/1.8/core', 'spec/ruby/1.8/language', 'spec/compiler', 'spec/parser']
CI_EXCLUDES_DIR = File.expand_path(File.dirname(__FILE__) + '/../spec/data') CI_EXCLUDES_DIR = File.expand_path(File.dirname(__FILE__) + '/../spec/data')


require File.dirname(__FILE__) + '/../mspec/scripts/ci' require File.dirname(__FILE__) + '/../mspec/scripts/ci'
5 changes: 3 additions & 2 deletions kernel/core/compile.rb
Expand Up @@ -11,7 +11,7 @@ module Compile


@compiler = nil @compiler = nil


DefaultCompiler = "compiler2" DefaultCompiler = "compiler"


def self.register_compiler(obj) def self.register_compiler(obj)
if $DEBUG if $DEBUG
Expand All @@ -24,7 +24,8 @@ def self.find_compiler
begin begin
require "#{DefaultCompiler}/init" require "#{DefaultCompiler}/init"
rescue Exception => e rescue Exception => e
STDERR.puts "Unable to load default compiler" STDERR.puts "Unable to load default compiler: #{e.message}"
puts e.backtrace.show
raise e raise e
end end


Expand Down
4 changes: 2 additions & 2 deletions kernel/core/context.rb
Expand Up @@ -8,7 +8,7 @@ class MethodContext


# The Nth group of the last regexp match. # The Nth group of the last regexp match.
# #
# Implemented to support Compiler2. # Implemented to support Compiler.
def nth_ref(n) def nth_ref(n)
if lm = @last_match if lm = @last_match
return lm[n] return lm[n]
Expand All @@ -19,7 +19,7 @@ def nth_ref(n)


# One of the special globals $&, $`, $' or $+. # One of the special globals $&, $`, $' or $+.
# #
# Implemented to support Compiler2. # Implemented to support Compiler.
def back_ref(kind) def back_ref(kind)
if lm = @last_match if lm = @last_match
res = case kind res = case kind
Expand Down
23 changes: 1 addition & 22 deletions kernel/core/eval.rb
Expand Up @@ -93,28 +93,7 @@ def instance_eval(string = nil, filename = "(eval)", line = 1, &prc)
string = StringValue(string) string = StringValue(string)


binding = Binding.setup(MethodContext.current.sender) binding = Binding.setup(MethodContext.current.sender)


text = false
if text
sexp = string.to_sexp(filename, line, true)

require 'compiler2/init'
require 'compiler2/text'

p sexp

comp = Compiler2.new(Compiler2::TextGenerator, binding) # flags[:binding])
node = comp.convert_sexp([:eval_expression, sexp])
p node
meth = node.to_description
puts ""
puts meth.generator.text
return nil

return node.to_description(:__eval_script__).to_cmethod
end


flags = { :binding => binding } flags = { :binding => binding }
compiled_method = Compile.compile_string string, flags, filename, line compiled_method = Compile.compile_string string, flags, filename, line
ctx = binding.context ctx = binding.context
Expand Down
10 changes: 5 additions & 5 deletions lib/compiler2/bytecode.rb → lib/compiler/bytecode.rb
@@ -1,9 +1,9 @@
# Implements methods on each Node subclass for generatng bytecode # Implements methods on each Node subclass for generatng bytecode
# from itself. # from itself.


require 'compiler2/generator' require 'compiler/generator'


class Compiler2 class Compiler
class MethodDescription class MethodDescription
def initialize(gen_class, locals) def initialize(gen_class, locals)
@generator = gen_class.new @generator = gen_class.new
Expand Down Expand Up @@ -37,7 +37,7 @@ def inspect
end end
end end


class Compiler2 class Compiler
class Node class Node


class GenerationError < Error; end class GenerationError < Error; end
Expand All @@ -61,7 +61,7 @@ def show_errors(gen)
class ClosedScope class ClosedScope


def new_description def new_description
Compiler2::MethodDescription.new(@compiler.generator_class, self.locals) Compiler::MethodDescription.new(@compiler.generator_class, self.locals)
end end


def to_description(name=nil) def to_description(name=nil)
Expand Down Expand Up @@ -608,7 +608,7 @@ def bytecode(g)
# TESTED # TESTED
class Iter class Iter
def bytecode(g) def bytecode(g)
desc = Compiler2::MethodDescription.new @compiler.generator_class, @locals desc = Compiler::MethodDescription.new @compiler.generator_class, @locals
desc.name = :__block__ desc.name = :__block__
sub = desc.generator sub = desc.generator


Expand Down
8 changes: 4 additions & 4 deletions lib/compiler2/compile.rb → lib/compiler/compile.rb
Expand Up @@ -12,7 +12,7 @@
def interactive def interactive
require 'readline' require 'readline'


c = Compiler2.new(Compiler2::Generator) c = Compiler.new(Compiler::Generator)
puts "Enter ? for help, ^D to exit." puts "Enter ? for help, ^D to exit."


while code = Readline.readline("rbx:compile> ") while code = Readline.readline("rbx:compile> ")
Expand All @@ -35,7 +35,7 @@ def interactive


# "Batch" mode # "Batch" mode
def batch(opts) def batch(opts)
c = Compiler2.new(Compiler2::Generator) c = Compiler.new(Compiler::Generator)
verbose = opts['verbose'] verbose = opts['verbose']


# Loopty-doop # Loopty-doop
Expand All @@ -56,8 +56,8 @@ def batch(opts)
#TODO: Figure out why text generation breaks subsequent compilation #TODO: Figure out why text generation breaks subsequent compilation
if verbose if verbose
old_gen = c.generator_class old_gen = c.generator_class
c.generator_class = Compiler2::TextGenerator c.generator_class = Compiler::TextGenerator
txt = Compiler2::TextGenerator.new txt = Compiler::TextGenerator.new
n.bytecode(txt) n.bytecode(txt)
txt.close txt.close
puts txt.text puts txt.text
Expand Down

0 comments on commit 85e9849

Please sign in to comment.