Skip to content

Commit

Permalink
r60@vatu: evan | 2006-09-20 23:21:54 -0700
Browse files Browse the repository at this point in the history
 A good portion of the typer facility is working, this adds the upper translation
 piece which interfaces the typing to the C translator.
  • Loading branch information
evanphx committed Sep 21, 2006
1 parent 3085cb7 commit beac24d
Show file tree
Hide file tree
Showing 25 changed files with 1,104 additions and 192 deletions.
2 changes: 2 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@

desc "Run all rubinius's tests"
task :test do
system("ruby -Ilib test/tc_all.rb")
end

desc "Build syd-parser."
task :syd do
system("cd externals/syd-parser; rake gem")
puts
Expand Down
11 changes: 9 additions & 2 deletions externals/syd-parser/bin/syd_pt_show
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,17 @@ require 'pp'
if ARGV.first == "-l"
newlines = true
ARGV.shift
elsif ARGV.first == "-u"
unified = true
ARGV.shift
end

name = ARGV.shift
File.open(name, "r") do |fd|
syd = SydneyParser.load_file fd
pp syd.sexp(false, newlines)
if unified
pp SydneyParser.unified_sexp(fd)
else
syd = SydneyParser.load_file fd
pp syd.sexp(false, newlines)
end
end
13 changes: 8 additions & 5 deletions externals/syd-parser/lib/sydparse.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,22 @@ class SydneyParser

# Generate a sexp which includes comments from +var+. +var+ is either a String
# or something that can become an IO object.
def self.unified_sexp(var)
def self.unified_sexp(var, merge=false)
if String === var
syd = load_string var, true
else
syd = load_file var.to_io, false, true
end

return syd.unified_sexp
return syd.unified_sexp(merge)

end

# Generate a sexp which includes comments from +var+.
def unified_sexp
def unified_sexp(merge=false)
comms = collapse_per_line comments()
x = sexp(true)
insert_comments(x, comms)
insert_comments(x, comms, merge)
end

private
Expand Down Expand Up @@ -81,7 +81,7 @@ def insert_comments_rec(sexp, lines, comments)
sexp.pop
init_comments = find_comments(lines, comments, line)
if init_comments.size > 0
init_comments.unshift :comment
init_comments
else
init_comments = nil
end
Expand All @@ -101,6 +101,9 @@ def insert_comments_rec(sexp, lines, comments)
end
end

if init_comments
init_comments

[init_comments, out]
end

Expand Down
2 changes: 2 additions & 0 deletions lib/gc/heap.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ def reset!

attr_accessor :current

# T: Fixnum => bool
def contains?(addr)
return false if addr < @address
return false if addr >= @address + @size
Expand Down Expand Up @@ -55,6 +56,7 @@ def enough_space?(size)
return true
end

# T: RObject => RObject
def copy_object(obj)
return obj if contains?(obj.address)
sz = obj.memory_size
Expand Down
4 changes: 4 additions & 0 deletions lib/log.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,12 @@ def format_message(severity, time, name, msg)

Log = Rubinius::Logger.new(STDOUT)



if $DEBUG or ENV['RDEBUG']
Log.level = Logger::DEBUG
elsif ENV['TESTING']
Log.level = Logger::FATAL
else
Log.level = Logger::INFO
end
80 changes: 35 additions & 45 deletions lib/object.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ def self.setup(heap, klass, fields)
end

def self.create(heap, klass, fields)
if klass.kind_of? RObject
klass = klass.address
elsif !klass
if klass.nil?
klass = 4 # nil
elsif klass.kind_of? RObject
klass = klass.address
end

size = HeaderSize + (fields * 4)
address = heap.allocate(size)

Expand All @@ -40,7 +40,7 @@ def self.create(heap, klass, fields)
def initialize_fields
start = @address + HeaderSize

0.upto(fields) do |i|
0.upto(fields-1) do |i|
Memory.store_long start, i, 4
end

Expand Down Expand Up @@ -99,7 +99,7 @@ def references
0.upto(fields-1) do |i|
obj = at(i)
if obj.reference?
out << [obj,i] unless out.find { |ent| ent.first == obj }
out << [obj,i]
end
end
out
Expand All @@ -110,24 +110,7 @@ def references
def hash_int
@address
end

IsMetaFlag = 0x80

def rclass
m = Memory.fetch_long @address + 4, 0
obj = RObject.new(m)
while obj.reference? and obj.flag_set?(IsMetaFlag)
obj.as :class
obj = obj.superclass
end
obj.as :class
return obj
end

def rclass=(obj)
Memory.store_long @address + 4, 0, obj.address
end


def ==(obj)
@address == obj.address
end
Expand Down Expand Up @@ -178,24 +161,19 @@ def self.remove_write_barrier
end

def self.wrap(val)
case val
when FalseClass
i = 0
when TrueClass
i = 2
when NilClass
i = 4
when Fixnum
fx = (val.abs << 3) | 1
fx |= 4 if val < 0
i = fx
else
raise ArgumentError, "Unable to wrap #{val}"
end
fx = (val.abs << 3) | 1
fx |= 4 if val < 0
i = fx

return RObject.new(i)
end

def to_int
fx = @address >> 3
fx = -fx if fixnum_neg?
fx
end

def reference?
@address > 10 and (@address & 1 == 0)
end
Expand Down Expand Up @@ -236,12 +214,6 @@ def symbol_index
@address >> 2
end

def to_int
fx = @address >> 3
fx = -fx if fixnum_neg?
fx
end

def true?
@address == 2
end
Expand Down Expand Up @@ -292,6 +264,7 @@ def fetch_byte(idx)
Memory.fetch_byte addr
end

# hint:skip_translation
def as(type)
extend Rubinius::Types[type]
return self
Expand Down Expand Up @@ -319,6 +292,23 @@ def as_string
"#<RObject:0x" + @address.to_s(16) + ">"
end

IsMetaFlag = 0x80

def rclass
m = Memory.fetch_long @address + 4, 0
obj = RObject.new(m)
while obj.reference? and obj.flag_set?(IsMetaFlag)
obj.as :class
obj = obj.superclass
end
obj.as :class
return obj
end

def rclass=(obj)
Memory.store_long @address + 4, 0, obj.address
end

def create_metaclass(sup)
unless sup
sup = self.direct_class
Expand All @@ -333,7 +323,7 @@ def create_metaclass(sup)
def access_metaclass
m = Memory.fetch_long @address + 4, 0
obj = RObject.new(m)
if obj.reference? and !Rubinius::MetaClass.metaclass?(obj)
if obj.reference? and !obj.flag_set?(IsMetaFlag)
# puts "#{obj.inspect} is in the class slot, but not a metaclass!"
# obj = RObject.nil
obj = RObject.nil
Expand Down
77 changes: 77 additions & 0 deletions lib/translation/extractors.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,81 @@ def process_call(x)
@requires += args.map { |s| s.last }
end
end
end

class ExtractHints < SexpProcessor
def initialize
super
self.expected = Array
@hints = Hash.new
@current_class = nil
end

attr_reader :hints

def process_class(x)
x.shift
name = x.shift
sup = x.shift
body = x.shift

@current_class = name.last
begin
nb = process(body)
ensure
@current_class = nil
end

return [:class, name, sup, nb]
end

def process_comment(x)
x.shift
str = x.shift.strip
hint = []
if m = /T:\s*([\w\s]*) => (\w*)/.match(str)
ret = $2
args = $1.split(/\s*,\s*/).map { |a| Type.method_missing(a.strip) }
hint = [:hint, :type, ::Type.method_missing(ret), args]
elsif m = /hints:\s*([\w\s]*)/.match(str)
tags = $1.split(/\s*,\s*/)
hint = [:hint, :tag, tags]
end

return hint
end

def process_block(x)
x.shift
@hint = nil
while node = x.shift
cur = process(node)
if cur.first == :hint
@hint = cur
else
@hint = nil
end
end
return []
end

def process_defn(x)
x.shift
name = x.shift
if @hint
@hints[[@current_class, name]] = @hint
end
x.clear
[]
end

def process_defs(x)
x.shift
recv = x.shift
return unless recv == [:self]
name = x.shift
@hints[[[@current_class, :self], name]] = @hint
x.clear
[]
end
end
Loading

0 comments on commit beac24d

Please sign in to comment.