Permalink
Browse files

compiler is dead, long live compiler1!

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...
1 parent faaa193 commit eda2c1b5d296e3513c73395de42930e613245890 @evanphx evanphx committed Dec 13, 2007
Showing with 706 additions and 416 deletions.
  1. +46 −15 Rakefile
  2. +0 −165 compiler2/compiler.rb
  3. +8 −8 doc/vm/op_code_info.rb
  4. +35 −29 kernel/core/compile.rb
  5. +1 −1 kernel/core/global.rb
  6. +1 −1 kernel/core/kernel.rb
  7. +2 −1 kernel/core/object.rb
  8. +2 −20 kernel/loader.rb
  9. +0 −2 lib/bin/compile.rb
  10. +5 −5 lib/bin/describe.rb
  11. +3 −4 lib/bin/sirb.rb
  12. +3 −1 {compiler → lib/compiler1}/bytecode/assembler.rb
  13. +27 −6 {compiler → lib/compiler1}/bytecode/compiler.rb
  14. +3 −1 {compiler → lib/compiler1}/bytecode/disassembler.rb
  15. +2 −0 {compiler → lib/compiler1}/bytecode/encoder.rb
  16. +3 −0 {compiler → lib/compiler1}/bytecode/plugins.rb
  17. +2 −0 {compiler → lib/compiler1}/bytecode/primitive_names.rb
  18. +8 −4 {compiler → lib/compiler1}/bytecode/rubinius.rb
  19. 0 {compiler → lib/compiler1}/bytecode/system_hints.rb
  20. +4 −0 lib/compiler1/init.rb
  21. +2 −0 {compiler → lib/compiler1}/sexp/composite_processor.rb
  22. +3 −0 {compiler → lib/compiler1}/sexp/exceptions.rb
  23. +3 −1 {compiler → lib/compiler1}/sexp/simple_processor.rb
  24. +4 −2 {compiler → lib/compiler1}/translation/local_scoping.rb
  25. +4 −3 {compiler → lib/compiler1}/translation/normalize.rb
  26. +3 −3 {compiler → lib/compiler1}/translation/states.rb
  27. +17 −2 { → lib}/compiler2/compile.rb
  28. +24 −20 {compiler2 → lib/compiler2/compiler}/bytecode.rb
  29. +107 −0 lib/compiler2/compiler/compiler.rb
  30. 0 {compiler2 → lib/compiler2/compiler}/encoder.rb
  31. 0 {compiler2 → lib/compiler2/compiler}/execute.rb
  32. 0 {compiler2 → lib/compiler2/compiler}/garnet/bindingagent.rb
  33. +39 −0 lib/compiler2/compiler/garnet/cerberus.rb
  34. +18 −0 lib/compiler2/compiler/garnet/garnet.rb
  35. 0 {compiler2 → lib/compiler2/compiler}/garnet/test.rb
  36. +9 −2 {compiler2 → lib/compiler2/compiler}/generator.rb
  37. 0 {compiler2 → lib/compiler2/compiler}/graph.rb
  38. 0 {compiler2 → lib/compiler2/compiler}/local.rb
  39. +26 −0 lib/compiler2/compiler/macro.rb
  40. +98 −1 {compiler2 → lib/compiler2/compiler}/nodes.rb
  41. +70 −4 {compiler2 → lib/compiler2/compiler}/plugins.rb
  42. +1 −1 {compiler2 → lib/compiler2/compiler}/text.rb
  43. 0 { → lib}/compiler2/describe.rb
  44. +3 −0 lib/compiler2/init.rb
  45. 0 { → lib}/compiler2/spec/array_spec.rb
  46. 0 { → lib}/compiler2/spec/call_spec.rb
  47. 0 { → lib}/compiler2/spec/control_spec.rb
  48. 0 { → lib}/compiler2/spec/exception_spec.rb
  49. 0 { → lib}/compiler2/spec/helper.rb
  50. 0 { → lib}/compiler2/spec/hints_spec.rb
  51. 0 { → lib}/compiler2/spec/masgn_spec.rb
  52. 0 { → lib}/compiler2/spec/op_assign_spec.rb
  53. 0 { → lib}/compiler2/spec/scopes_spec.rb
  54. 0 { → lib}/compiler2/spec/simple_spec.rb
  55. 0 { → lib}/compiler2/spec/variables_spec.rb
  56. BIN runtime/stable/bootstrap.rba
  57. BIN runtime/stable/compiler.rba
  58. BIN runtime/stable/compiler1.rba
  59. BIN runtime/stable/core.rba
  60. BIN runtime/stable/loader.rbc
  61. BIN runtime/stable/platform.rba
  62. +2 −3 shotgun/lib/Makefile
  63. +0 −1 shotgun/lib/cpu.c
  64. +37 −22 shotgun/lib/cpu_instructions.c
  65. +1 −1 shotgun/lib/genheader.rb
  66. +16 −43 shotgun/lib/instructions.rb
  67. +64 −44 shotgun/rubinius
View
@@ -4,6 +4,7 @@ $VERBOSE = true
$verbose = Rake.application.options.trace
$dlext = Config::CONFIG["DLEXT"]
$redcloth_available = nil
+$compiler = nil
require 'tsort'
require 'rakelib/struct_generator'
@@ -100,45 +101,56 @@ def create_load_order(files, output=".load_order.txt")
end
end
-def compile(name, output)
+def compile(name, output, check_mtime=false)
dir = File.dirname(output)
unless File.exists?(dir)
FileUtils.mkdir_p dir
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']
- sh "shotgun/rubinius --gdb compile #{name} #{output}", :verbose => $verbose
+ sh "shotgun/rubinius --gdb #{inc} compile #{name} #{output}", :verbose => $verbose
else
- sh "shotgun/rubinius compile #{name} #{output}", :verbose => $verbose
+ sh "shotgun/rubinius #{inc} compile #{name} #{output}", :verbose => $verbose
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']
puts "Use current versions, not stable."
else
+ $compiler = "runtime/stable/compiler1.rba"
ENV['RBX_BOOTSTRAP'] = "runtime/stable/bootstrap.rba"
- ENV['RBX_COMPILER'] = "runtime/stable/compiler.rba"
ENV['RBX_CORE'] = "runtime/stable/core.rba"
ENV['RBX_LOADER'] = "runtime/stable/loader.rbc"
ENV['RBX_PLATFORM'] = "runtime/stable/platform.rba"
end
end
-task :stable_shell => :compiler do
+task :stable_shell => :stable_compiler do
sh "shotgun/rubinius --gdb"
end
rule ".rbc" => %w[compiler .rb] do |t|
compile t.source, t.name
end
-#file 'runtime/core/kernel/core/proc.rbc' => 'kernel/core/proc.rb' do |t|
-# p t.prerequisites
-# p t.name
-#end
-
class CodeGroup
def initialize(files, compile_dir, rba_name, load_order=true)
@@ -238,7 +250,6 @@ Core = CodeGroup.new(files, 'runtime/core', 'core')
Bootstrap = CodeGroup.new 'kernel/bootstrap/*.rb', 'runtime/bootstrap',
'bootstrap'
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
compile 'kernel/loader.rb', 'runtime/loader.rbc'
@@ -248,6 +259,10 @@ file 'runtime/stable/loader.rbc' => 'runtime/loader.rbc' do
cp 'runtime/loader.rbc', 'runtime/stable', :verbose => $verbose
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|
t.dest = "kernel/core/dir.rb"
end
@@ -260,7 +275,7 @@ Rake::StructGeneratorTask.new do |t|
t.dest = 'lib/zlib.rb'
end
-AllPreCompiled = Core.output + Bootstrap.output + Platform.output + Compiler.output
+AllPreCompiled = Core.output + Bootstrap.output + Platform.output
AllPreCompiled << "runtime/loader.rbc"
# spec tasks
@@ -367,6 +382,12 @@ task :config_env => 'shotgun/config.mk' do
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"
task :rebuild => %w[clean:rbc clean:shotgun build:all]
@@ -380,6 +401,7 @@ task :pristine do
FileList['**/*.rbc'].each do |fn|
next if /^runtime/.match(fn)
next if /require\/require_spec_.\.rbc/.match(fn)
+ next if %r!lib/compiler1!.match(fn)
FileUtils.rm fn rescue nil
end
end
@@ -391,6 +413,10 @@ namespace :clean do
AllPreCompiled.each do |f|
rm_f f, :verbose => $verbose
end
+
+ (Dir["lib/compiler1/*.rbc"] + Dir["lib/compiler1/**/*.rbc"]).each do |f|
+ rm_f f, :verbose => $verbose
+ end
end
desc "Cleans up VM building site"
@@ -409,6 +435,7 @@ namespace :build do
task :all => %w[
build:shotgun
build:rbc
+ compiler1
lib/etc.rb
lib/rbconfig.rb
extensions
@@ -441,16 +468,20 @@ namespace :build do
desc "Compiles shotgun (the C-code VM)"
task :shotgun => %w[configure shotgun/rubinius.bin]
- task :setup_rbc => :compiler
+ task :setup_rbc => :stable_compiler
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."
task :stable => %w[
build:all
runtime/stable/bootstrap.rba
- runtime/stable/compiler.rba
runtime/stable/core.rba
+ runtime/stable/compiler1.rba
runtime/stable/loader.rbc
runtime/stable/platform.rba
]
View
@@ -1,165 +0,0 @@
-class Compiler
-
- class Error < RuntimeError
- end
-
- class Node
- Mapping = {}
-
- def self.kind(name=nil)
- return @kind unless name
- Mapping[name] = self
- @kind = name
- end
-
- def self.create(compiler, sexp)
- sexp.shift
-
- node = new(compiler)
- args = node.consume(sexp)
-
- begin
- if node.respond_to? :normalize
- node = node.normalize(*args)
- else
- node.args(*args)
- end
- rescue ArgumentError => e
- raise ArgumentError, "#{kind} (#{self}) takes #{args.size} argument(s): passed #{args.inspect} (#{e.message})", e.context
- end
-
- return node
- end
-
- def initialize(compiler)
- @compiler = compiler
- end
-
- def convert(x)
- @compiler.convert_sexp(x)
- end
-
- def consume(sexp)
- # This lets nil come back from convert_sexp which means
- # leave it out of the stream. This is primarily so that
- # expressions can be optimized away and wont be seen at
- # all in the output stream.
- out = []
- sexp.each do |x|
- if x.kind_of? Array
- v = @compiler.convert_sexp(x)
- out << v unless v.nil?
- else
- out << x
- end
- end
-
- return out
- end
-
- def args
- end
-
- def get(tag)
- @compiler.get(tag)
- end
-
- def set(tag, val=true, &b)
- @compiler.set(tag, val, &b)
- end
-
- def inspect
- kind = self.class.kind
- if kind
- prefix = "Compiler:#{self.class.kind}"
- else
- prefix = self.class.name
- end
- prefix
-
- super(prefix)
- end
-
- def is?(clas)
- self.kind_of?(clas)
- end
- end
-
- def initialize(gen_class)
- @variables = {}
- @generator_class = gen_class
- @call_plugins = []
-
- @file = "(unknown)"
- @line = 0
-
- load_plugins
- end
-
- attr_reader :generator_class, :call_plugins
-
- def set_position(file, line)
- @file, @line = file, line
- end
-
- def load_plugins
- require File.dirname(__FILE__) + '/plugins'
-
- # The default plugins
- activate :block_given
- activate :primitive
- activate :assembly
- end
-
- def activate(name)
- cls = Compiler::Plugins.find_plugin(name)
- raise Error, "Unknown plugin '#{name}'" unless cls
- @call_plugins << cls.new(self)
- end
-
- def inspect
- "#<#{self.class}>"
- end
-
- def convert_sexp(sexp)
- return nil if sexp.nil?
-
- klass = Compiler::Node::Mapping[sexp.first]
-
- raise Error, "Unable to resolve #{sexp.first}" unless klass
-
- return klass.create(self, sexp)
- end
-
- def into_script(sexp)
- begin
- convert_sexp([:script, sexp])
- rescue Object => e
- puts "Compilation error detected: #{e.message}"
- puts " near #{@file}:#{@line}"
- puts
- puts e.backtrace.show
- end
- end
-
- def get(tag)
- @variables[tag]
- end
-
- def set(tag, val=true)
- cur = @variables.dup
- if tag.kind_of? Hash
- @variables.merge! tag
- else
- @variables[tag] = val
- end
- begin
- yield
- ensure
- @variables = cur
- end
- end
-end
-
-require File.dirname(__FILE__) + '/nodes'
-require File.dirname(__FILE__) + '/local'
View
@@ -1,6 +1,6 @@
-$: << File.dirname(__FILE__) + '/../../compiler'
-require 'bytecode/encoder'
-require 'bytecode/assembler'
+$: << File.dirname(__FILE__) + '/../../lib'
+require 'compiler1/bytecode/encoder'
+require 'compiler1/bytecode/assembler'
require 'yaml'
@@ -20,11 +20,11 @@ module OpCode
# Some information is gleaned from Rubinius source files, while
# descriptive info comes from opcode YAML files.
class Info
- @@op_codes = Bytecode::InstructionEncoder::OpCodes
- @@int_arg = Bytecode::InstructionEncoder::IntArg
- @@two_int = Bytecode::InstructionEncoder::TwoInt
+ @@op_codes = Compiler1::Bytecode::InstructionEncoder::OpCodes
+ @@int_arg = Compiler1::Bytecode::InstructionEncoder::IntArg
+ @@two_int = Compiler1::Bytecode::InstructionEncoder::TwoInt
@@instructs = ShotgunInstructions.new
- @@translations = Bytecode::Assembler::Translations.invert
+ @@translations = Compiler1::Bytecode::Assembler::Translations.invert
def self.op_codes
@@op_codes
@@ -71,4 +71,4 @@ def <=>(b)
to_s <=> b.to_s
end
end
-end
+end
Oops, something went wrong.

0 comments on commit eda2c1b

Please sign in to comment.