use rubyc_compiler as instance
not as before class methods so we can carry the state around
This commit is contained in:
parent
1505df894a
commit
22b1fea587
@ -2,24 +2,30 @@ require_relative "ruby_compiler"
|
|||||||
|
|
||||||
module RubyX
|
module RubyX
|
||||||
class RubyXCompiler
|
class RubyXCompiler
|
||||||
|
attr_reader :source
|
||||||
|
|
||||||
def self.ruby_to_vool( ruby_source )
|
def initialize(source)
|
||||||
vool = RubyCompiler.compile( ruby_source )
|
@source = source
|
||||||
|
end
|
||||||
|
|
||||||
|
def ruby_to_vool
|
||||||
|
vool = RubyCompiler.compile( source )
|
||||||
vool = vool.normalize
|
vool = vool.normalize
|
||||||
vool
|
vool
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.ruby_to_mom( ruby_source )
|
def ruby_to_mom
|
||||||
vool = self.ruby_to_vool(ruby_source)
|
vool = ruby_to_vool
|
||||||
vool.to_mom(nil)
|
vool.to_mom(nil)
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.ruby_to_binary(source , platform = :arm)
|
def ruby_to_binary(platform = :arm)
|
||||||
Parfait.boot!
|
Parfait.boot!
|
||||||
machine = Risc.machine.boot
|
machine = Risc.machine.boot
|
||||||
mom = ruby_to_mom(source)
|
mom = ruby_to_mom
|
||||||
#mom.translate(platform)
|
puts "MOM #{mom.class}"
|
||||||
machine.translate(platform)
|
mom.translate(platform)
|
||||||
|
#machine.translate(platform)
|
||||||
machine.position_all
|
machine.position_all
|
||||||
machine.create_binary
|
machine.create_binary
|
||||||
end
|
end
|
||||||
|
@ -8,13 +8,14 @@ module RubyX
|
|||||||
end
|
end
|
||||||
def ruby_to_risc(input , platform)
|
def ruby_to_risc(input , platform)
|
||||||
mom = ruby_to_mom(input)
|
mom = ruby_to_mom(input)
|
||||||
|
puts "MOM #{mom.class}"
|
||||||
mom.translate(platform)
|
mom.translate(platform)
|
||||||
end
|
end
|
||||||
def ruby_to_vool(input)
|
def ruby_to_vool(input)
|
||||||
RubyXCompiler.ruby_to_vool(input)
|
RubyXCompiler.new(input).ruby_to_vool
|
||||||
end
|
end
|
||||||
def ruby_to_mom(input)
|
def ruby_to_mom(input)
|
||||||
RubyXCompiler.ruby_to_mom(input)
|
RubyXCompiler.new(input).ruby_to_mom
|
||||||
end
|
end
|
||||||
def compile_in_test input
|
def compile_in_test input
|
||||||
vool = ruby_to_vool in_Test(input)
|
vool = ruby_to_vool in_Test(input)
|
||||||
|
@ -22,7 +22,7 @@ module MomCompile
|
|||||||
include ScopeHelper
|
include ScopeHelper
|
||||||
|
|
||||||
def compile_mom(input)
|
def compile_mom(input)
|
||||||
statements = RubyX::RubyXCompiler.ruby_to_vool input
|
statements = RubyX::RubyXCompiler.new(input).ruby_to_vool
|
||||||
res = statements.to_mom(nil)
|
res = statements.to_mom(nil)
|
||||||
assert_equal Parfait::Class , statements.clazz.class , statements
|
assert_equal Parfait::Class , statements.clazz.class , statements
|
||||||
@method = statements.clazz.get_method(:main)
|
@method = statements.clazz.get_method(:main)
|
||||||
@ -31,7 +31,12 @@ module MomCompile
|
|||||||
end
|
end
|
||||||
def compile_first_method( input )
|
def compile_first_method( input )
|
||||||
res = compile_mom( as_test_main( input ))
|
res = compile_mom( as_test_main( input ))
|
||||||
res.clazz.instance_methods.first.compile_to_mom(res.clazz.instance_type)
|
method = res.clazz.instance_methods.first
|
||||||
|
compile_to_mom(method , res.clazz.instance_type)
|
||||||
|
end
|
||||||
|
def compile_to_mom(method , for_type)
|
||||||
|
typed_method = create_typed_method(for_type)
|
||||||
|
source.to_mom( typed_method )
|
||||||
end
|
end
|
||||||
|
|
||||||
def check_array( should , is )
|
def check_array( should , is )
|
||||||
|
Loading…
x
Reference in New Issue
Block a user