get method name out from method_missing
This commit is contained in:
parent
d58ed8e5e8
commit
e56db0a3ac
@ -62,7 +62,7 @@ module Mom
|
|||||||
branch while_start_label
|
branch while_start_label
|
||||||
|
|
||||||
add_code exit_label
|
add_code exit_label
|
||||||
MethodMissing.new(compiler.source_name).to_risc(compiler)
|
MethodMissing.new(compiler.source_name , word.symbol).to_risc(compiler)
|
||||||
|
|
||||||
add_code ok_label
|
add_code ok_label
|
||||||
cache_entry[:cached_method] << callable_method
|
cache_entry[:cached_method] << callable_method
|
||||||
|
@ -1,8 +1,20 @@
|
|||||||
module Mom
|
module Mom
|
||||||
class MethodMissing < Macro
|
class MethodMissing < Macro
|
||||||
|
attr_reader :name
|
||||||
|
|
||||||
|
def initialize( source , name )
|
||||||
|
super(source)
|
||||||
|
name = name.value if name.is_a?(Vool::SymbolConstant)
|
||||||
|
raise "No reg #{name.class}" unless name.class == Symbol
|
||||||
|
@name = name
|
||||||
|
end
|
||||||
|
|
||||||
def to_risc(compiler)
|
def to_risc(compiler)
|
||||||
builder = compiler.builder(compiler.source_name)
|
builder = compiler.builder(compiler.source_name)
|
||||||
builder.add_code Risc::Syscall.new("Method_missing_died", :died )
|
from = Risc::RegisterValue.new(@name , :Word)
|
||||||
|
to = Risc::RegisterValue.new(:r1 , :Word)
|
||||||
|
builder.add_code Risc::Transfer.new(self , from , to)
|
||||||
|
builder.add_code Risc::Syscall.new(self, :died )
|
||||||
return compiler
|
return compiler
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -54,7 +54,7 @@ module Mom
|
|||||||
|
|
||||||
def self.create_mm_compiler
|
def self.create_mm_compiler
|
||||||
compiler = compiler_for(:Object,:__method_missing__ ,{})
|
compiler = compiler_for(:Object,:__method_missing__ ,{})
|
||||||
compiler.add_code MethodMissing.new("missing")
|
compiler.add_code MethodMissing.new("missing" , :r1)
|
||||||
return compiler
|
return compiler
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -250,7 +250,7 @@ module Risc
|
|||||||
set_instruction(nil)
|
set_instruction(nil)
|
||||||
return false
|
return false
|
||||||
when :died
|
when :died
|
||||||
raise "Method not found #{@registers[:r0]}"
|
raise "Method #{@registers[:r1]} not found for #{@registers[:r0].receiver}"
|
||||||
else
|
else
|
||||||
raise "un-implemented syscall #{name}"
|
raise "un-implemented syscall #{name}"
|
||||||
end
|
end
|
||||||
|
@ -13,7 +13,7 @@ module Vool
|
|||||||
def self.builtin
|
def self.builtin
|
||||||
{
|
{
|
||||||
"Object.get" => "def get_internal_word(at); X.get_internal_word;end",
|
"Object.get" => "def get_internal_word(at); X.get_internal_word;end",
|
||||||
"Object.missing" => "def method_missing(at); X.method_missing;end",
|
"Object.missing" => "def method_missing(at); X.method_missing(:r1);end",
|
||||||
"Object.exit" => "def exit; X.exit;end",
|
"Object.exit" => "def exit; X.exit;end",
|
||||||
"Integer.div4" => "def div4; X.div4;end",
|
"Integer.div4" => "def div4; X.div4;end",
|
||||||
"Integer.div10" => "def div10; X.div10;end",
|
"Integer.div10" => "def div10; X.div10;end",
|
||||||
|
@ -10,7 +10,7 @@ module Mom
|
|||||||
ResolveMethod.new( "method" , :name , cache_entry )
|
ResolveMethod.new( "method" , :name , cache_entry )
|
||||||
end
|
end
|
||||||
def test_len
|
def test_len
|
||||||
assert_equal 18 , all.length , all_str
|
assert_equal 19 , all.length , all_str
|
||||||
end
|
end
|
||||||
def test_1_load_name
|
def test_1_load_name
|
||||||
assert_load risc(1) , Symbol , :r1
|
assert_load risc(1) , Symbol , :r1
|
||||||
@ -56,14 +56,17 @@ module Mom
|
|||||||
def test_14_goto_exit
|
def test_14_goto_exit
|
||||||
assert_label risc(14) , "exit_label_"
|
assert_label risc(14) , "exit_label_"
|
||||||
end
|
end
|
||||||
def test_15_die
|
def test_15_move_name
|
||||||
assert_syscall risc(15) , :died
|
assert_transfer( risc(15) , :r1 , :r1)
|
||||||
end
|
end
|
||||||
def test_16_label
|
def test_16_die
|
||||||
assert_label risc(16) , "ok_label_"
|
assert_syscall risc(16) , :died
|
||||||
end
|
end
|
||||||
def test_17_load_method
|
def test_17_label
|
||||||
assert_reg_to_slot risc(17) , :r4 , :r2 , 2
|
assert_label risc(17) , "ok_label_"
|
||||||
|
end
|
||||||
|
def test_18_load_method
|
||||||
|
assert_reg_to_slot risc(18) , :r4 , :r2 , 2
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -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 14 , @method.to_risc.risc_instructions.length
|
assert_equal 15 , @method.to_risc.risc_instructions.length
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -17,7 +17,7 @@ module Risc
|
|||||||
LoadConstant, RegToSlot, LoadConstant, LoadConstant, SlotToReg, #15
|
LoadConstant, RegToSlot, LoadConstant, LoadConstant, SlotToReg, #15
|
||||||
SlotToReg, LoadConstant, OperatorInstruction, IsZero, SlotToReg, #20
|
SlotToReg, LoadConstant, OperatorInstruction, IsZero, SlotToReg, #20
|
||||||
OperatorInstruction, IsZero, RegToSlot, LoadConstant, SlotToReg, #25
|
OperatorInstruction, IsZero, RegToSlot, LoadConstant, SlotToReg, #25
|
||||||
SlotToReg, Branch, RegToSlot, SlotToReg, SlotToReg, #30
|
Branch, SlotToReg, RegToSlot, SlotToReg, SlotToReg, #30
|
||||||
RegToSlot, LoadConstant, SlotToReg, RegToSlot, SlotToReg, #35
|
RegToSlot, LoadConstant, SlotToReg, RegToSlot, SlotToReg, #35
|
||||||
LoadConstant, SlotToReg, DynamicJump, LoadConstant, SlotToReg, #40
|
LoadConstant, SlotToReg, DynamicJump, LoadConstant, SlotToReg, #40
|
||||||
LoadConstant, OperatorInstruction, IsNotZero, SlotToReg, RegToSlot, #45
|
LoadConstant, OperatorInstruction, IsNotZero, SlotToReg, RegToSlot, #45
|
||||||
|
@ -13,7 +13,7 @@ module RubyX
|
|||||||
end
|
end
|
||||||
class Object
|
class Object
|
||||||
def method_missing(at)
|
def method_missing(at)
|
||||||
X.method_missing
|
X.method_missing(:r1)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
GET
|
GET
|
||||||
@ -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 14 , compiler.to_risc.risc_instructions.length
|
assert_equal 15 , compiler.to_risc.risc_instructions.length
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user