check for redefining of methods and forbid
causing some test problems, but better that way (until it's done right off course)
This commit is contained in:
parent
3df54910cc
commit
1022390e0f
@ -6,9 +6,12 @@ module Vool
|
|||||||
end
|
end
|
||||||
|
|
||||||
def self.load_builtin(loads)
|
def self.load_builtin(loads)
|
||||||
|
return "class Space;def main(arg);return 0; end; end" if(loads == "Space.main")
|
||||||
|
raise "no preload #{loads}" unless builtin[loads]
|
||||||
clazz , meth = loads.split(".")
|
clazz , meth = loads.split(".")
|
||||||
"class #{clazz} #{derive(clazz)}; #{Vool::Builtin.builtin[loads]};end;"
|
"class #{clazz} #{derive(clazz)}; #{builtin[loads]};end;"
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.derive(clazz) #must get derived classes rigth, so no mismatch
|
def self.derive(clazz) #must get derived classes rigth, so no mismatch
|
||||||
case clazz
|
case clazz
|
||||||
when "Integer"
|
when "Integer"
|
||||||
@ -40,7 +43,6 @@ module Vool
|
|||||||
"Word.put" => "def putstring(at); X.putstring;end",
|
"Word.put" => "def putstring(at); X.putstring;end",
|
||||||
"Word.set" => "def set_internal_byte(at, val); X.set_internal_byte;end",
|
"Word.set" => "def set_internal_byte(at, val); X.set_internal_byte;end",
|
||||||
"Word.get" => "def get_internal_byte(at); X.get_internal_byte;end",
|
"Word.get" => "def get_internal_byte(at); X.get_internal_byte;end",
|
||||||
"Space.main" => "def main(args);return nil;end",
|
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
def self.builtin_code
|
def self.builtin_code
|
||||||
|
@ -13,6 +13,10 @@ module Vool
|
|||||||
# Must pass in the actual Parfait class (default nil is just to conform to api)
|
# Must pass in the actual Parfait class (default nil is just to conform to api)
|
||||||
def to_parfait( clazz = nil )
|
def to_parfait( clazz = nil )
|
||||||
raise "No class given to method #{name}" unless clazz
|
raise "No class given to method #{name}" unless clazz
|
||||||
|
if( method = clazz.get_instance_method(name))
|
||||||
|
#FIXME , should check arg_type, and if the same, clear method and ok
|
||||||
|
raise "Redefining #{clazz.name}.#{name} not supported #{method}"
|
||||||
|
end
|
||||||
clazz.add_instance_method_for(name , make_arg_type , make_frame , body )
|
clazz.add_instance_method_for(name , make_arg_type , make_frame , body )
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -4,8 +4,8 @@ module Mom
|
|||||||
module Builtin
|
module Builtin
|
||||||
class TestObjectInitRisc < BootTest
|
class TestObjectInitRisc < BootTest
|
||||||
def setup
|
def setup
|
||||||
Parfait.boot!(Parfait.default_test_options)
|
compiler = RubyX::RubyXCompiler.new(RubyX.default_test_options)
|
||||||
get_compiler("Space",:main)
|
coll = compiler.ruby_to_mom( get_preload("Space.main") )
|
||||||
@method = MomCollection.create_init_compiler
|
@method = MomCollection.create_init_compiler
|
||||||
end
|
end
|
||||||
def test_mom_length
|
def test_mom_length
|
||||||
|
@ -22,7 +22,7 @@ module Vool
|
|||||||
end
|
end
|
||||||
def test_method
|
def test_method
|
||||||
clazz = @clazz.to_parfait
|
clazz = @clazz.to_parfait
|
||||||
assert_equal Parfait::VoolMethod , method.to_parfait(clazz).class
|
assert_equal Parfait::VoolMethod , clazz.get_instance_method(:main).class
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -5,38 +5,45 @@ module Risc
|
|||||||
class IntMath < Minitest::Test
|
class IntMath < Minitest::Test
|
||||||
include Ticker
|
include Ticker
|
||||||
def setup
|
def setup
|
||||||
@preload = "all"
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_add
|
def test_add
|
||||||
|
@preload = "Integer.plus"
|
||||||
run_main_return "5 + 5"
|
run_main_return "5 + 5"
|
||||||
assert_equal 10 , get_return
|
assert_equal 10 , get_return
|
||||||
end
|
end
|
||||||
def test_minus
|
def test_minus
|
||||||
|
@preload = "Integer.minus"
|
||||||
run_main_return "5 - 5"
|
run_main_return "5 - 5"
|
||||||
assert_equal 0 , get_return
|
assert_equal 0 , get_return
|
||||||
end
|
end
|
||||||
def test_minus_neg
|
def test_minus_neg
|
||||||
|
@preload = "Integer.minus"
|
||||||
run_main_return "5 - 15"
|
run_main_return "5 - 15"
|
||||||
assert_equal( -10 , get_return)
|
assert_equal( -10 , get_return)
|
||||||
end
|
end
|
||||||
def test_rshift
|
def test_rshift
|
||||||
|
@preload = "Integer.rs"
|
||||||
run_main_return "#{2**8} >> 3"
|
run_main_return "#{2**8} >> 3"
|
||||||
assert_equal 2**5 , get_return
|
assert_equal 2**5 , get_return
|
||||||
end
|
end
|
||||||
def test_lshift
|
def test_lshift
|
||||||
|
@preload = "Integer.ls"
|
||||||
run_main_return "#{2**8} << 3"
|
run_main_return "#{2**8} << 3"
|
||||||
assert_equal 2**11 , get_return
|
assert_equal 2**11 , get_return
|
||||||
end
|
end
|
||||||
def test_div10
|
def test_div10
|
||||||
|
@preload = "Integer.div10"
|
||||||
run_main_return "45.div10"
|
run_main_return "45.div10"
|
||||||
assert_equal 4 , get_return
|
assert_equal 4 , get_return
|
||||||
end
|
end
|
||||||
def test_div4
|
def test_div4
|
||||||
|
@preload = "Integer.div4"
|
||||||
run_main_return "45.div4"
|
run_main_return "45.div4"
|
||||||
assert_equal 11 , get_return
|
assert_equal 11 , get_return
|
||||||
end
|
end
|
||||||
def test_mult
|
def test_mult
|
||||||
|
@preload = "Integer.mul"
|
||||||
run_main_return "4 * 4"
|
run_main_return "4 * 4"
|
||||||
assert_equal 16 , get_return
|
assert_equal 16 , get_return
|
||||||
end
|
end
|
||||||
|
@ -6,11 +6,6 @@ module RubyX
|
|||||||
include MacroHelper
|
include MacroHelper
|
||||||
def source
|
def source
|
||||||
<<GET
|
<<GET
|
||||||
class Space
|
|
||||||
def main(arg)
|
|
||||||
return
|
|
||||||
end
|
|
||||||
end
|
|
||||||
class Object
|
class Object
|
||||||
def method_missing(at)
|
def method_missing(at)
|
||||||
X.method_missing(:r1)
|
X.method_missing(:r1)
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
module Preloader
|
module Preloader
|
||||||
def get_preload(preload)
|
def get_preload(preload)
|
||||||
return "" unless preload
|
return "" unless preload
|
||||||
preload = Vool::Builtin.builtin.keys.join(";") if(preload == "all" )
|
if( preload == "all" )
|
||||||
preload.split(";").collect do |loads|
|
loading = Vool::Builtin.builtin.keys
|
||||||
raise "no preload #{loads}" unless Vool::Builtin.builtin[loads]
|
else
|
||||||
clazz , meth = loads.split(".")
|
loading = preload.split(";")
|
||||||
"class #{clazz} #{Vool::Builtin.derive(clazz)}; #{Vool::Builtin.builtin[loads]};end;"
|
end
|
||||||
end.join
|
loading.collect { |loads| Vool::Builtin.load_builtin(loads)}.join(";") + ";"
|
||||||
end
|
end
|
||||||
def preload
|
def preload
|
||||||
get_preload(@preload)
|
get_preload(@preload)
|
||||||
|
@ -105,7 +105,7 @@ module Risc
|
|||||||
# use the input as it, compile and run it
|
# use the input as it, compile and run it
|
||||||
# input muts contain a Space.main, but may contain more classes and methods
|
# input muts contain a Space.main, but may contain more classes and methods
|
||||||
def run_input(input)
|
def run_input(input)
|
||||||
@string_input = preload + input
|
@string_input = input
|
||||||
do_setup
|
do_setup
|
||||||
run_all
|
run_all
|
||||||
end
|
end
|
||||||
|
@ -21,15 +21,28 @@ module Vool
|
|||||||
assert_raises{ method.to_parfait }
|
assert_raises{ method.to_parfait }
|
||||||
end
|
end
|
||||||
def test_method
|
def test_method
|
||||||
clazz = @clazz.to_parfait
|
assert_equal Parfait::Class , @clazz.to_parfait.class
|
||||||
assert_equal Parfait::Class , clazz.class
|
|
||||||
meth = method.to_parfait(clazz)
|
|
||||||
assert_equal Parfait::VoolMethod , meth.class
|
|
||||||
assert_equal :main , meth.name
|
|
||||||
end
|
end
|
||||||
def test_is_instance_method
|
def test_is_instance_method
|
||||||
assert main = @clazz.to_parfait.get_instance_method(:main)
|
main = @clazz.to_parfait.get_instance_method(:main)
|
||||||
|
assert_equal Parfait::VoolMethod , main.class
|
||||||
|
assert_equal :main , main.name
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
class TestMethodExpressionDoubleDef < MiniTest::Test
|
||||||
|
include VoolCompile
|
||||||
|
|
||||||
|
def setup
|
||||||
|
Parfait.boot!(Parfait.default_test_options)
|
||||||
|
ruby_tree = Ruby::RubyCompiler.compile( as_main("a = 5") + ";" + as_main("a = 5") )
|
||||||
|
@clazz = ruby_tree.to_vool
|
||||||
|
end
|
||||||
|
def method
|
||||||
|
@clazz.body.first
|
||||||
|
end
|
||||||
|
def test_no_double
|
||||||
|
assert_raises {@clazz.to_parfait}
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user