deprecating ruby package

to be replaced by vool and mom
This commit is contained in:
Torsten Ruger
2017-08-31 16:18:59 +03:00
parent 0b161ffa06
commit 112ec26bd1
28 changed files with 7 additions and 6 deletions

View File

@ -1,3 +1,4 @@
require "parser/ruby22"
require "logging"
require "elf/object_writer"
require "ast"
@ -13,6 +14,5 @@ require "risc"
require "risc/builtin/space"
require "arm/arm_machine"
require "arm/translator"
require "rubyx/ruby_compiler"
require "vool"
require "mom"

View File

@ -1,25 +0,0 @@
module Rubyx
module Passes
class LocalsCollector < TotalProcessor
def initialize
@locals = {}
end
def collect(statement)
process statement
@locals
end
def on_lvasgn statement
add_local( statement )
end
def add_local(statement)
var = statement.children[0]
@locals[var] = :Object #not really used right now
end
end
end
end

View File

@ -1,38 +0,0 @@
module Rubyx
module Passes
class MethodCollector < TotalProcessor
def initialize
@methods = []
end
def collect(statement)
process statement
@methods
end
def on_def(statement)
name , args , body = *statement
args_type = make_type(args)
locals_type = make_locals(body)
@methods << Vool::VoolMethod.new(name , args_type , locals_type , body )
end
private
def make_type( statement )
type_hash = {}
statement.children.each do |arg|
type_hash[arg.children[0]] = :Object
end
Parfait::NamedList.type_for( type_hash )
end
def make_locals(body)
type_hash = LocalsCollector.new.collect(body)
Parfait::NamedList.type_for( type_hash )
end
end
end
end

View File

@ -1,61 +0,0 @@
module Rubyx
module Passes
class MethodCompiler < AST::Processor
def initialize( ruby_method )
@ruby_method = ruby_method
end
def get_code
process(@ruby_method.source)
end
def on_ivasgn(statement)
name , value = *statement
w = Vm::Tree::Assignment.new()
w.name = Vm::Tree::InstanceName.new( name[1..-1].to_sym)
w.value = process(value)
w
end
def on_ivar( var )
name = var.children.first
w = Vm::Tree::FieldAccess.new()
w.receiver = Vm::Tree::KnownName.new(:self)
w.field = Vm::Tree::InstanceName.new( name[1..-1].to_sym)
w
end
def on_send( statement )
receiver , name , args = *statement
w = Vm::Tree::CallSite.new()
w.name = name
w.arguments = process(args) || []
w.receiver = process(receiver)
w
end
def on_lvar(statement)
name = statement.children.first.to_sym
if(@ruby_method.args_type.variable_index(name))
return Vm::Tree::ArgumentName.new(name)
end
raise "Not found #{name}"
end
def on_str( string )
Vm::Tree::StringExpression.new(string.children.first)
end
def on_int( expression)
Vm::Tree::IntegerExpression.new(expression.children.first)
end
def handler_missing(node)
raise "No handler for #{node}"
end
end
end
end

View File

@ -1,12 +0,0 @@
module Rubyx
module Passes
class Normalizer < AST::Processor
def initialize( ruby_method )
@ruby_method
end
end
end
end

View File

@ -1,14 +0,0 @@
module Rubyx
module Passes
class TotalProcessor < AST::Processor
def handler_missing(node)
node.children.each do |kid |
process(kid) if kid.is_a?(AST::Node)
end
end
end
end
end

View File

@ -1,29 +0,0 @@
module Rubyx
module Passes
class TypeCollector < TotalProcessor
def initialize
@ivars = {}
end
def collect(statement)
process statement
@ivars
end
def on_ivar(statement)
add_ivar(statement)
end
def on_ivasgn( statement )
add_ivar(statement)
end
def add_ivar(statement)
var = statement.children[0].to_s[1..-1].to_sym
@ivars[var] = :Object #guess, can maybe guess better
end
end
end
end

View File

@ -1,64 +0,0 @@
require "parser/ruby22"
require_relative "passes/total_processor"
require_relative "passes/type_collector"
require_relative "passes/method_collector"
require_relative "passes/method_compiler"
require_relative "passes/locals_collector"
require_relative "passes/normalizer"
require "vool/vool_method"
module Rubyx
class RubyxCompiler < Passes::TotalProcessor
def self.compile( input )
ast = Parser::Ruby22.parse( input )
self.new.process( ast )
end
def on_class statement
name , sup , body = *statement
class_name = get_name(name)
clazz = Parfait.object_space.get_class_by_name(class_name )
if(clazz)
#FIXME super class check with "sup"
else #existing class, don't overwrite type (parfait only?)
clazz = Parfait.object_space.create_class(class_name , get_name(sup) )
ivar_hash = Passes::TypeCollector.new.collect(body)
clazz.set_instance_type( Parfait::Type.for_hash( clazz , ivar_hash ) )
end
methods = create_methods(clazz , body)
compile_methods(clazz,methods)
end
def create_methods(clazz , body)
methods = Passes::MethodCollector.new.collect(body)
methods.each do |method|
clazz.add_method( method )
normalizer = Passes::Normalizer.new(method)
method.normalize_source { |sourc| normalizer.process( sourc ) }
end
methods
end
def compile_methods(clazz , methods)
methods.each do |method|
code = Passes::MethodCompiler.new(method).get_code
typed_method = method.create_vm_method(clazz.instance_type)
Vm::MethodCompiler.new( typed_method ).init_method.process( code )
end
end
private
def get_name( statement )
return nil unless statement
raise "Not const #{statement}" unless statement.type == :const
name = statement.children[1]
raise "Not symbol #{name}" unless name.is_a? Symbol
name
end
end
end

View File

@ -1 +1,2 @@
require_relative "vool/vool_compiler"
require_relative "vool/vool_method"