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:
Torsten Rüger 2019-09-24 21:20:12 +03:00
parent 3df54910cc
commit 1022390e0f
9 changed files with 45 additions and 24 deletions

View File

@ -6,9 +6,12 @@ module Vool
end
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(".")
"class #{clazz} #{derive(clazz)}; #{Vool::Builtin.builtin[loads]};end;"
"class #{clazz} #{derive(clazz)}; #{builtin[loads]};end;"
end
def self.derive(clazz) #must get derived classes rigth, so no mismatch
case clazz
when "Integer"
@ -40,7 +43,6 @@ module Vool
"Word.put" => "def putstring(at); X.putstring;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",
"Space.main" => "def main(args);return nil;end",
}
end
def self.builtin_code

View File

@ -13,6 +13,10 @@ module Vool
# Must pass in the actual Parfait class (default nil is just to conform to api)
def to_parfait( clazz = nil )
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 )
end

View File

@ -4,8 +4,8 @@ module Mom
module Builtin
class TestObjectInitRisc < BootTest
def setup
Parfait.boot!(Parfait.default_test_options)
get_compiler("Space",:main)
compiler = RubyX::RubyXCompiler.new(RubyX.default_test_options)
coll = compiler.ruby_to_mom( get_preload("Space.main") )
@method = MomCollection.create_init_compiler
end
def test_mom_length

View File

@ -22,7 +22,7 @@ module Vool
end
def test_method
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

View File

@ -5,38 +5,45 @@ module Risc
class IntMath < Minitest::Test
include Ticker
def setup
@preload = "all"
end
def test_add
@preload = "Integer.plus"
run_main_return "5 + 5"
assert_equal 10 , get_return
end
def test_minus
@preload = "Integer.minus"
run_main_return "5 - 5"
assert_equal 0 , get_return
end
def test_minus_neg
@preload = "Integer.minus"
run_main_return "5 - 15"
assert_equal( -10 , get_return)
end
def test_rshift
@preload = "Integer.rs"
run_main_return "#{2**8} >> 3"
assert_equal 2**5 , get_return
end
def test_lshift
@preload = "Integer.ls"
run_main_return "#{2**8} << 3"
assert_equal 2**11 , get_return
end
def test_div10
@preload = "Integer.div10"
run_main_return "45.div10"
assert_equal 4 , get_return
end
def test_div4
@preload = "Integer.div4"
run_main_return "45.div4"
assert_equal 11 , get_return
end
def test_mult
@preload = "Integer.mul"
run_main_return "4 * 4"
assert_equal 16 , get_return
end

View File

@ -6,11 +6,6 @@ module RubyX
include MacroHelper
def source
<<GET
class Space
def main(arg)
return
end
end
class Object
def method_missing(at)
X.method_missing(:r1)

View File

@ -1,12 +1,12 @@
module Preloader
def get_preload(preload)
return "" unless preload
preload = Vool::Builtin.builtin.keys.join(";") if(preload == "all" )
preload.split(";").collect do |loads|
raise "no preload #{loads}" unless Vool::Builtin.builtin[loads]
clazz , meth = loads.split(".")
"class #{clazz} #{Vool::Builtin.derive(clazz)}; #{Vool::Builtin.builtin[loads]};end;"
end.join
if( preload == "all" )
loading = Vool::Builtin.builtin.keys
else
loading = preload.split(";")
end
loading.collect { |loads| Vool::Builtin.load_builtin(loads)}.join(";") + ";"
end
def preload
get_preload(@preload)

View File

@ -105,7 +105,7 @@ module Risc
# use the input as it, compile and run it
# input muts contain a Space.main, but may contain more classes and methods
def run_input(input)
@string_input = preload + input
@string_input = input
do_setup
run_all
end

View File

@ -21,15 +21,28 @@ module Vool
assert_raises{ method.to_parfait }
end
def test_method
clazz = @clazz.to_parfait
assert_equal Parfait::Class , clazz.class
meth = method.to_parfait(clazz)
assert_equal Parfait::VoolMethod , meth.class
assert_equal :main , meth.name
assert_equal Parfait::Class , @clazz.to_parfait.class
end
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
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