start on class compiler
idea is to get cleaner layer seperation reduce machine and rework builtin boot
This commit is contained in:
@ -10,6 +10,7 @@ module Risc
|
||||
class TestRegisterValue < MiniTest::Test
|
||||
|
||||
def setup
|
||||
Parfait.boot!
|
||||
Risc.machine.boot
|
||||
@r0 = RegisterValue.new(:r0 , :Message)
|
||||
@r1 = RegisterValue.new(:r1 , :Space)
|
||||
|
@ -21,17 +21,17 @@ end
|
||||
module MomCompile
|
||||
include ScopeHelper
|
||||
|
||||
def compile_first_method( input )
|
||||
# works a lot like Vool.ruby_to_vool
|
||||
# but here we return the intermediate mom instructions that are otherwise not available
|
||||
statements = RubyX::RubyCompiler.compile as_test_main( input )
|
||||
statements = statements.normalize
|
||||
def compile_mom(input)
|
||||
statements = RubyX::RubyXCompiler.ruby_to_vool input
|
||||
res = statements.to_mom(nil)
|
||||
assert_equal Parfait::Class , statements.clazz.class , statements
|
||||
@method = statements.clazz.get_method(:main)
|
||||
assert_equal Parfait::VoolMethod , @method.class
|
||||
#puts "#{res.class}"
|
||||
res.first
|
||||
res
|
||||
end
|
||||
def compile_first_method( input )
|
||||
res = compile_mom( as_test_main( input ))
|
||||
res.clazz.instance_methods.first.compile_to_mom(res.clazz.instance_type)
|
||||
end
|
||||
|
||||
def check_array( should , is )
|
||||
|
@ -6,6 +6,7 @@ module Vool
|
||||
include Mom
|
||||
|
||||
def setup
|
||||
Parfait.boot!
|
||||
Risc.machine.boot
|
||||
@ins = compile_first_method( "a = main(1 + 2)" )
|
||||
end
|
||||
|
@ -6,6 +6,7 @@ module Vool
|
||||
include Mom
|
||||
|
||||
def setup
|
||||
Parfait.boot!
|
||||
Risc.machine.boot
|
||||
@ins = compile_first_method( "a = 5; a.div4")
|
||||
end
|
||||
|
17
test/vool/test_class_statement.rb
Normal file
17
test/vool/test_class_statement.rb
Normal file
@ -0,0 +1,17 @@
|
||||
|
||||
require_relative "helper"
|
||||
|
||||
module Vool
|
||||
class TestClassStatement < MiniTest::Test
|
||||
include MomCompile
|
||||
|
||||
def setup
|
||||
Parfait.boot!
|
||||
@ins = compile_mom( "class Test ; def main(); return 1; end; end;")
|
||||
end
|
||||
|
||||
def test_return
|
||||
assert_equal Mom::ClassCompiler , @ins.class
|
||||
end
|
||||
end
|
||||
end
|
@ -43,6 +43,7 @@ module Vool
|
||||
include Mom
|
||||
|
||||
def setup
|
||||
Parfait.boot!
|
||||
Risc.machine.boot
|
||||
@ins = compile_first_method( "return 5.div4")
|
||||
end
|
||||
|
Reference in New Issue
Block a user