Permalink
Browse files

Dozens more c2 and spec fixes

  • Loading branch information...
evanphx committed Dec 30, 2007
1 parent 7fa8f2e commit 3073442500beab599eec62d65dab0fcbb7b4d35a
Showing with 315 additions and 182 deletions.
  1. +24 −3 Rakefile
  2. +0 −5 kernel/bootstrap/bignum.rb
  3. +5 −8 kernel/bootstrap/bytearray.rb
  4. +9 −9 kernel/bootstrap/class.rb
  5. +1 −1 kernel/bootstrap/context.rb
  6. +29 −30 kernel/bootstrap/object.rb
  7. +1 −6 kernel/bootstrap/string.rb
  8. +2 −0 kernel/core/array.rb
  9. +1 −1 kernel/core/bignum.rb
  10. +1 −1 kernel/core/class.rb
  11. +3 −1 kernel/core/compile.rb
  12. +12 −12 kernel/core/compiled_method.rb
  13. +1 −1 kernel/core/exception.rb
  14. +2 −1 kernel/core/iseq.rb
  15. +2 −2 kernel/core/kernel.rb
  16. +11 −5 kernel/core/module.rb
  17. +11 −2 kernel/core/string.rb
  18. +6 −9 kernel/core/thread.rb
  19. +8 −2 kernel/core/throw_catch.rb
  20. +2 −1 lib/compiler1/bytecode/encoder.rb
  21. +32 −19 lib/compiler2/bytecode.rb
  22. +3 −0 lib/compiler2/compiler.rb
  23. +0 −2 lib/compiler2/garnet/cerberus.rb
  24. +0 −30 lib/compiler2/garnet/test.rb
  25. +9 −1 lib/compiler2/generator.rb
  26. +56 −5 lib/compiler2/nodes.rb
  27. +23 −1 lib/compiler2/text.rb
  28. +7 −5 ruby/spec/1.8/core/bignum/right_shift_spec.rb
  29. +8 −6 ruby/spec/1.8/core/exception/no_method_error_spec.rb
  30. +1 −1 ruby/spec/1.8/core/file/ftype_spec.rb
  31. +1 −1 ruby/spec/1.8/language/block_spec.rb
  32. +1 −1 ruby/spec/1.8/language/metaclass_spec.rb
  33. +7 −7 ruby/spec/1.8/language/variables_spec.rb
  34. BIN runtime/stable/bootstrap.rba
  35. BIN runtime/stable/compiler1.rba
  36. BIN runtime/stable/core.rba
  37. BIN runtime/stable/loader.rbc
  38. BIN runtime/stable/platform.rba
  39. +4 −1 shotgun/lib/cpu_instructions.c
  40. +7 −1 shotgun/lib/grammar_runtime.c
  41. +24 −0 shotgun/lib/instructions.rb
  42. +1 −1 shotgun/lib/primitives.rb
View
@@ -113,7 +113,9 @@ def compile(name, output, check_mtime=false)
return
end
- if $compiler
+ if $compiler == :c2
+ inc = "-Iruntime/stable/compiler2.rba -rcompiler2/init"
+ elsif $compiler
inc = "-I#{$compiler}"
else
inc = ""
@@ -136,7 +138,11 @@ task :stable_compiler do
if ENV['USE_CURRENT']
puts "Use current versions, not stable."
else
- $compiler = "runtime/stable/compiler1.rba"
+ if ENV['USE_C1']
+ $compiler = "runtime/stable/compiler1.rba"
+ else
+ $compiler = :c2
+ end
ENV['RBX_BOOTSTRAP'] = "runtime/stable/bootstrap.rba"
ENV['RBX_CORE'] = "runtime/stable/core.rba"
ENV['RBX_LOADER'] = "runtime/stable/loader.rbc"
@@ -148,7 +154,7 @@ task :stable_shell => :stable_compiler do
sh "shotgun/rubinius --gdb"
end
-rule ".rbc" => %w[compiler .rb] do |t|
+rule ".rbc" => %w[.rb] do |t|
compile t.source, t.name
end
@@ -264,6 +270,10 @@ file 'runtime/stable/compiler1.rba' => 'build:compiler1' do
sh "cd lib; zip -r ../runtime/stable/compiler1.rba compiler1 -x \\*.rb"
end
+file 'runtime/stable/compiler2.rba' => 'build:compiler2' do
+ sh "cd lib; zip -r ../runtime/stable/compiler2.rba compiler2 -x \\*.rb"
+end
+
Rake::StructGeneratorTask.new do |t|
t.dest = "lib/etc.rb"
end
@@ -399,6 +409,7 @@ task :pristine do
next if /^runtime/.match(fn)
next if %r!fixtures/require!.match(fn)
next if %r!lib/compiler1!.match(fn)
+ next if %r!lib/compiler2!.match(fn)
FileUtils.rm fn rescue nil
end
end
@@ -415,6 +426,10 @@ namespace :clean do
rm_f f, :verbose => $verbose
end
+ (Dir["lib/compiler2/*.rbc"] + Dir["lib/compiler2/**/*.rbc"]).each do |f|
+ rm_f f, :verbose => $verbose
+ end
+
rm_f "runtime/platform.conf"
end
@@ -436,6 +451,7 @@ namespace :build do
build:platform
build:rbc
compiler1
+ compiler2
lib/etc.rb
lib/rbconfig.rb
extensions
@@ -475,13 +491,18 @@ namespace :build do
task :compiler1 => :stable_compiler do
compile_dir "lib/compiler1"
end
+
+ task :compiler2 => :stable_compiler do
+ compile_dir "lib/compiler2"
+ 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/core.rba
runtime/stable/compiler1.rba
+ runtime/stable/compiler2.rba
runtime/stable/loader.rbc
runtime/stable/platform.rba
]
@@ -63,11 +63,6 @@ def ==(o)
super(o)
end
- def eql?(other)
- false unless other.is_a?(Bignum)
- self == other
- end
-
def __bignum_left_shift__(s)
Ruby.primitive :bignum_left_shift
end
@@ -5,14 +5,11 @@ def self.allocate(cnt)
def self.new(cnt)
obj = allocate(cnt)
- Ruby.asm <<-CODE
-push_block
-#local obj
-push 0
-set_args
-set_call_flags 1
-&send initialize +
- CODE
+ Rubinius.asm(obj) do |obj|
+ push_block
+ run obj
+ send_with_block :initialize, 0, true
+ end
return obj
end
View
@@ -10,15 +10,15 @@ def allocate
def new(*args)
obj = allocate()
- Ruby.asm <<-CODE
-#local args
-cast_array_for_args 0
-push_array
-push_block
-#local obj
-set_call_flags 1
-&send initialize +
- CODE
+ Rubinius.asm(args, obj) do |args, obj|
+ run args
+ cast_array_for_args 0
+ push_array
+ push_block
+ run obj
+ set_call_flags 1
+ send_with_register :initialize
+ end
return obj
end
@@ -1,6 +1,6 @@
class MethodContext
def self.current
- cur = Ruby.asm "push_context\n"
+ cur = Rubinius.asm { push_context }
return cur.sender
end
View
@@ -33,51 +33,50 @@ def equal?(other)
end
def kind_of?(cls)
- Ruby.asm <<-ASM
-#local cls
-push self
-kind_of
- ASM
+ Rubinius.asm(cls) do |c|
+ run c
+ push :self
+ kind_of
+ end
end
def respond_to?(meth,include_private=false)
meth = meth.to_sym
- cm = Ruby.asm <<-ASM
-push self
-#local meth
-#local include_private
-locate_method
- ASM
+ cm = Rubinius.asm(meth, include_private) do |m,i|
+ push :self
+ run m
+ run i
+ locate_method
+ end
!cm.nil?
end
def __send__(name, *args)
meth = name.to_sym
count = args.size.to_i
- prc = Ruby.asm "push_block\n"
-
- Ruby.asm <<-ASM
-#local args
-push_array
-push self
-#local prc
-#local meth
-#local count
-set_args
-set_call_flags 1
-send_off_stack
- ASM
+ Rubinius.asm(args, meth, count) do |a,m,c|
+ run a
+ push_array
+ push :self
+ push_block
+ run m
+ run c
+ set_args
+ set_call_flags 1
+ send_off_stack
+ end
end
def __find_method__(meth)
meth = meth.to_sym
- cm = Ruby.asm <<-ASM
-push self
-#local meth
-push true
-locate_method
- ASM
+ cm = Rubinius.asm(meth) do |m|
+ push :self
+ run m
+ push :true
+ locate_method
+ end
+
return cm
end
@@ -22,16 +22,11 @@ def __crypt__(other_str)
def append(str)
Ruby.primitive :string_append
- unless str.kind_of? String
- raise TypeError, "only a String instance is accepted"
- end
-
- Ruby.asm "#local str\npush self\nstring_append\n"
+ raise TypeError, "only a String instance is accepted"
end
def dup
Ruby.primitive :string_dup
- Ruby.asm "push self\nstring_dup\n"
end
def to_s
View
@@ -493,6 +493,8 @@ def delete(obj)
i += 1
end
+
+ yield if block_given?
end
# Deletes the element at the given index and returns
View
@@ -45,7 +45,7 @@ def <<(s)
end
def eql?(value)
- return false unless value.kind_of?(Bignum)
+ return false unless value.kind_of?(Integer)
self == value
end
View
@@ -4,7 +4,7 @@ def self.new(sclass=Object)
raise TypeError, "superclass must be a Class (#{sclass.class.name} given)" unless sclass.kind_of?(Class)
obj = Rubinius.class_constitute(sclass, nil)
- block = Ruby.asm "push_block"
+ block = block_given?
obj.class_eval(&block) if block
# add clas to sclass's subclass list, for ObjectSpace.each_object(Class)
# NOTE: This is non-standard; Ruby does not normally track subclasses
View
@@ -9,7 +9,7 @@ module Compile
@compiler = nil
- DefaultCompiler = "compiler1"
+ DefaultCompiler = "compiler2"
def self.register_compiler(obj)
if $DEBUG
@@ -121,6 +121,8 @@ def self.single_load(dir, rb, rbc, ext, requiring = nil)
if File.file? rb_path
rbc_path = "#{dir}#{rbc}"
+
+ cm = nil
# Use source only if it is newer
if !File.file?(rbc_path) or File.mtime(rb_path) > File.mtime(rbc_path)
@@ -119,18 +119,18 @@ def activate(recv, mod, args, locals=nil, &prc)
block = nil
end
- out = Ruby.asm <<-ASM
-#local args
-push_array
-#local block
-#local locals
-#local sz
-#local mod
-push self
-#local recv
-activate_method
- ASM
-
+ out = Rubinius.asm(args, block, locals, sz, mod, recv) do |a,b,l,s,m,r|
+ run a
+ push_array
+ run b
+ run l
+ run s
+ run m
+ push :self
+ run r
+ activate_method 0
+ end
+
return out
end
View
@@ -182,7 +182,7 @@ class ReturnException
attr_reader :return_value
def initialize(val)
- super()
+ super(nil) # HACK
@return_value = val
end
end
View
@@ -117,7 +117,8 @@ class InstructionSet
{:opcode => :set_literal, :args => [:literal]},
{:opcode => :passed_blockarg, :args => [:int]},
{:opcode => :create_block2, :args => [], :vm_flags => [:check_interrupts]},
- {:opcode => :cast_for_single_block_arg, :args => []}
+ {:opcode => :cast_for_single_block_arg, :args => []},
+ {:opcode => :cast_for_multi_block_arg, :args => []}
]
InstructionSize = 4
View
@@ -94,7 +94,7 @@ def raise(exc=$!, msg=nil, trace=nil)
end
exc.set_backtrace MethodContext.current.sender unless exc.backtrace
- Ruby.asm "#local exc\nraise_exc"
+ Rubinius.asm(exc) { |e| e.bytecode(self); raise_exc }
end
alias_method :fail, :raise
@@ -203,7 +203,7 @@ def rand(max=nil)
end
def lambda
- block = Ruby.asm "push_block"
+ block = block_given?
raise ArgumentError, "block required" if block.nil?
block.disable_long_return!
Oops, something went wrong.

0 comments on commit 3073442

Please sign in to comment.