use method missing in resolve method
not just exit try to print name next
This commit is contained in:
parent
7ee57f2b08
commit
d913bb01de
@ -62,10 +62,7 @@ module Mom
|
|||||||
branch while_start_label
|
branch while_start_label
|
||||||
|
|
||||||
add_code exit_label
|
add_code exit_label
|
||||||
# temporary, need to raise really.
|
MethodMissing.new(compiler.source_name).to_risc(compiler)
|
||||||
factory! << Parfait.object_space.get_factory_for(:Integer)
|
|
||||||
integer_tmp! << factory[:reserve]
|
|
||||||
Mom::Macro.emit_syscall( builder , :died ) #uses integer_tmp
|
|
||||||
|
|
||||||
add_code ok_label
|
add_code ok_label
|
||||||
cache_entry[:cached_method] << callable_method
|
cache_entry[:cached_method] << callable_method
|
||||||
|
@ -1,9 +1,17 @@
|
|||||||
module Mom
|
module Mom
|
||||||
|
# Init "method" is the first thing that happens in the machine
|
||||||
|
# There is an inital jump to it, but that's it, no setup, no nothing
|
||||||
|
#
|
||||||
|
# The method is in quotes, because it is not really a method, it does not return!!
|
||||||
|
# This is common to all double underscore "methods", but __init also does not
|
||||||
|
# rely on the message. In fact it's job is to set up the first message
|
||||||
|
# and to call the main (possibly later _init_ , single undescrore)
|
||||||
|
#
|
||||||
class Init < Macro
|
class Init < Macro
|
||||||
def to_risc(compiler)
|
def to_risc(compiler)
|
||||||
builder = compiler.builder(compiler.source)
|
builder = compiler.builder(compiler.source)
|
||||||
main = Parfait.object_space.get_method!(:Space, :main)
|
main = Parfait.object_space.get_method!(:Space, :main)
|
||||||
|
# Set up the first message, but advance one, so main has somewhere to return to
|
||||||
builder.build do
|
builder.build do
|
||||||
factory! << Parfait.object_space.get_factory_for(:Message)
|
factory! << Parfait.object_space.get_factory_for(:Message)
|
||||||
message << factory[:next_object]
|
message << factory[:next_object]
|
||||||
@ -11,14 +19,14 @@ module Mom
|
|||||||
factory[:next_object] << next_message
|
factory[:next_object] << next_message
|
||||||
end
|
end
|
||||||
builder.reset_names
|
builder.reset_names
|
||||||
|
# Set up the call to main, with space as receiver
|
||||||
Mom::MessageSetup.new(main).build_with( builder )
|
Mom::MessageSetup.new(main).build_with( builder )
|
||||||
|
|
||||||
builder.build do
|
builder.build do
|
||||||
message << message[:next_message]
|
message << message[:next_message]
|
||||||
space? << Parfait.object_space
|
space? << Parfait.object_space
|
||||||
message[:receiver] << space
|
message[:receiver] << space
|
||||||
end
|
end
|
||||||
|
# set up return address and jump to main
|
||||||
exit_label = Risc.label(compiler.source , "#{compiler.receiver_type.object_class.name}.#{compiler.source.name}" )
|
exit_label = Risc.label(compiler.source , "#{compiler.receiver_type.object_class.name}.#{compiler.source.name}" )
|
||||||
ret_tmp = compiler.use_reg(:Label).set_builder(builder)
|
ret_tmp = compiler.use_reg(:Label).set_builder(builder)
|
||||||
builder.build do
|
builder.build do
|
||||||
@ -28,7 +36,7 @@ module Mom
|
|||||||
add_code exit_label
|
add_code exit_label
|
||||||
end
|
end
|
||||||
compiler.reset_regs
|
compiler.reset_regs
|
||||||
Macro.exit_sequence(builder)
|
Macro.exit_sequence(builder) # exit will use mains return_value as exit_code
|
||||||
return compiler
|
return compiler
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -1,9 +1,12 @@
|
|||||||
module Mom
|
module Mom
|
||||||
class MethodMissing < Macro
|
class MethodMissing < Macro
|
||||||
def to_risc(compiler)
|
def to_risc(compiler)
|
||||||
builder = compiler.builder(compiler.source)
|
builder = compiler.builder(compiler.source_name)
|
||||||
builder.prepare_int_return # makes integer_tmp variable as return
|
builder.build do
|
||||||
Macro.emit_syscall( builder , :exit )
|
factory! << Parfait.object_space.get_factory_for(:Integer)
|
||||||
|
integer_tmp! << factory[:reserve]
|
||||||
|
Mom::Macro.emit_syscall( builder , :died ) #uses integer_tmp
|
||||||
|
end
|
||||||
return compiler
|
return compiler
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -14,15 +14,18 @@ module Mom
|
|||||||
@method_compilers = compilers
|
@method_compilers = compilers
|
||||||
end
|
end
|
||||||
|
|
||||||
# lazily instantiate the compiler for init function
|
# lazily instantiate the compiler for __init__ function and __method_missing__
|
||||||
def init_compiler
|
def init_compiler
|
||||||
@init_compilers ||= MomCollection.create_init_compiler
|
@init_compilers ||= [
|
||||||
|
MomCollection.create_init_compiler ,
|
||||||
|
MomCollection.create_mm_compiler ,
|
||||||
|
]
|
||||||
end
|
end
|
||||||
|
|
||||||
# Return all compilers, namely the MethodCompilers passed in, plus the
|
# Return all compilers, namely the MethodCompilers passed in, plus the
|
||||||
# boot_function's compilers (boot_compilers)
|
# boot_function's compilers (boot_compilers)
|
||||||
def compilers
|
def compilers
|
||||||
@method_compilers << init_compiler
|
@method_compilers + init_compiler
|
||||||
end
|
end
|
||||||
|
|
||||||
# Append another MomCompilers method_compilers to this one.
|
# Append another MomCompilers method_compilers to this one.
|
||||||
@ -41,18 +44,20 @@ module Mom
|
|||||||
Risc::RiscCollection.new(riscs)
|
Risc::RiscCollection.new(riscs)
|
||||||
end
|
end
|
||||||
|
|
||||||
# this is the really really first place the machine starts (apart from the jump here)
|
# See Init instruction. We must have an init (ie we need it in code), so it is created in code
|
||||||
# it isn't really a function, ie it is jumped to (not called), exits and may not return
|
|
||||||
# so it is responsible for initial setup:
|
|
||||||
# - load fist message, set up Space as receiver
|
|
||||||
# - call main, ie set up message for that etc
|
|
||||||
# - exit (exit_sequence) which passes a machine int out to c
|
|
||||||
def self.create_init_compiler
|
def self.create_init_compiler
|
||||||
compiler = compiler_for(:Object,:__init__ ,{})
|
compiler = compiler_for(:Object,:__init__ ,{})
|
||||||
compiler._reset_for_init # no return, just for init
|
compiler._reset_for_init # no return, just for init
|
||||||
compiler.add_code Init.new("missing")
|
compiler.add_code Init.new("missing")
|
||||||
return compiler
|
return compiler
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.create_mm_compiler
|
||||||
|
compiler = compiler_for(:Object,:__method_missing__ ,{})
|
||||||
|
compiler.add_code MethodMissing.new("missing")
|
||||||
|
return compiler
|
||||||
|
end
|
||||||
|
|
||||||
def self.compiler_for( clazz_name , method_name , arguments , locals = {})
|
def self.compiler_for( clazz_name , method_name , arguments , locals = {})
|
||||||
frame = Parfait::NamedList.type_for( locals )
|
frame = Parfait::NamedList.type_for( locals )
|
||||||
args = Parfait::NamedList.type_for( arguments )
|
args = Parfait::NamedList.type_for( arguments )
|
||||||
|
@ -14,7 +14,7 @@ module Mom
|
|||||||
assert_equal Risc::MethodCompiler , @method.to_risc.class
|
assert_equal Risc::MethodCompiler , @method.to_risc.class
|
||||||
end
|
end
|
||||||
def test_risc_length
|
def test_risc_length
|
||||||
assert_equal 42 , @method.to_risc.risc_instructions.length
|
assert_equal 21 , @method.to_risc.risc_instructions.length
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -12,13 +12,16 @@ module Mom
|
|||||||
assert_equal MomCollection , @comp.class
|
assert_equal MomCollection , @comp.class
|
||||||
end
|
end
|
||||||
def test_compilers
|
def test_compilers
|
||||||
assert_equal 2 , @comp.compilers.length
|
assert_equal 3 , @comp.compilers.length
|
||||||
|
end
|
||||||
|
def test_init_compilers
|
||||||
|
assert_equal Array , @comp.init_compiler.class
|
||||||
end
|
end
|
||||||
def test_init_compiler
|
def test_init_compiler
|
||||||
assert_equal Mom::MethodCompiler , @comp.init_compiler.class
|
assert_equal Mom::MethodCompiler , @comp.init_compiler.first.class
|
||||||
end
|
end
|
||||||
def test_compilers_bare
|
def test_compilers_bare
|
||||||
assert_equal 1 , MomCollection.new.compilers.length
|
assert_equal 2 , MomCollection.new.compilers.length
|
||||||
end
|
end
|
||||||
def test_append_class
|
def test_append_class
|
||||||
assert_equal MomCollection, (@comp.append @comp).class
|
assert_equal MomCollection, (@comp.append @comp).class
|
||||||
@ -42,7 +45,7 @@ module Mom
|
|||||||
end
|
end
|
||||||
def test_has_risc_compiler
|
def test_has_risc_compiler
|
||||||
assert_equal Risc::MethodCompiler, compiler.class
|
assert_equal Risc::MethodCompiler, compiler.class
|
||||||
assert_equal 2, @collection.method_compilers.length
|
assert_equal 3, @collection.method_compilers.length
|
||||||
end
|
end
|
||||||
def test_has_risc_instructions
|
def test_has_risc_instructions
|
||||||
assert_equal Risc::Label, compiler.risc_instructions.class
|
assert_equal Risc::Label, compiler.risc_instructions.class
|
||||||
|
@ -38,7 +38,7 @@ module Risc
|
|||||||
ret = main_ticks(49)
|
ret = main_ticks(49)
|
||||||
assert_equal FunctionReturn , ret.class
|
assert_equal FunctionReturn , ret.class
|
||||||
assert_equal :r3 , ret.register.symbol
|
assert_equal :r3 , ret.register.symbol
|
||||||
assert_equal 38140 , @interpreter.get_register(ret.register)
|
assert_equal 38236 , @interpreter.get_register(ret.register)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -38,7 +38,7 @@ module Risc
|
|||||||
end
|
end
|
||||||
|
|
||||||
def len
|
def len
|
||||||
1476
|
1479
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_collect_all_types
|
def test_collect_all_types
|
||||||
@ -70,7 +70,7 @@ module Risc
|
|||||||
end
|
end
|
||||||
|
|
||||||
def len
|
def len
|
||||||
2956
|
2959
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -52,14 +52,11 @@ module Risc
|
|||||||
@interpreter.tick
|
@interpreter.tick
|
||||||
assert_equal 2 , @interpreter.clock
|
assert_equal 2 , @interpreter.clock
|
||||||
end
|
end
|
||||||
def test_pc1
|
def test_pc
|
||||||
@interpreter.tick
|
@interpreter.tick
|
||||||
assert_equal 37704 , @interpreter.pc
|
assert_equal t = 37800 , @interpreter.pc
|
||||||
end
|
|
||||||
def test_pc2
|
|
||||||
@interpreter.tick
|
@interpreter.tick
|
||||||
@interpreter.tick
|
assert_equal t + 4 , @interpreter.pc
|
||||||
assert_equal 37708 , @interpreter.pc
|
|
||||||
end
|
end
|
||||||
def test_tick2
|
def test_tick2
|
||||||
@interpreter.tick
|
@interpreter.tick
|
||||||
|
@ -24,7 +24,7 @@ module Risc
|
|||||||
assert_equal 0 , Position.get(@linker.cpu_init).at
|
assert_equal 0 , Position.get(@linker.cpu_init).at
|
||||||
end
|
end
|
||||||
def test_cpu_at
|
def test_cpu_at
|
||||||
assert_equal "0x93bc" , Position.get(@linker.cpu_init.first).to_s
|
assert_equal "0x941c" , Position.get(@linker.cpu_init.first).to_s
|
||||||
end
|
end
|
||||||
def test_cpu_label
|
def test_cpu_label
|
||||||
assert_equal Position , Position.get(@linker.cpu_init.first).class
|
assert_equal Position , Position.get(@linker.cpu_init.first).class
|
||||||
|
@ -16,7 +16,7 @@ module Risc
|
|||||||
assert_equal 1 , mains.length
|
assert_equal 1 , mains.length
|
||||||
end
|
end
|
||||||
def test_assembler_num
|
def test_assembler_num
|
||||||
assert_equal 2 , @linker.assemblers.length
|
assert_equal 3 , @linker.assemblers.length
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -28,7 +28,7 @@ GET
|
|||||||
assert_equal Mom::MethodMissing , compiler.mom_instructions.next.class
|
assert_equal Mom::MethodMissing , compiler.mom_instructions.next.class
|
||||||
end
|
end
|
||||||
def test_risc
|
def test_risc
|
||||||
assert_equal 42 , compiler.to_risc.risc_instructions.length
|
assert_equal 21 , compiler.to_risc.risc_instructions.length
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -23,7 +23,7 @@ module RubyX
|
|||||||
end
|
end
|
||||||
def test_asm_len
|
def test_asm_len
|
||||||
linker = @collection.translate(:interpreter)
|
linker = @collection.translate(:interpreter)
|
||||||
assert_equal 2 , linker.assemblers.length
|
assert_equal 3 , linker.assemblers.length
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
class TestRubyXCompilerParfait < MiniTest::Test
|
class TestRubyXCompilerParfait < MiniTest::Test
|
||||||
|
@ -36,7 +36,7 @@ module RubyX
|
|||||||
assert_equal 2 , compiler.vool.length
|
assert_equal 2 , compiler.vool.length
|
||||||
linker = compiler.to_binary(:interpreter)
|
linker = compiler.to_binary(:interpreter)
|
||||||
assert_equal Risc::Linker , linker.class
|
assert_equal Risc::Linker , linker.class
|
||||||
assert_equal 3 , linker.assemblers.length
|
assert_equal 4 , linker.assemblers.length
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user