Extracting the mom instruction from builtin modules

Since they were embedded at first (easier copy/paste) they now got own files, like their brethren
also mini tests for each instruction , nice start
This commit is contained in:
Torsten Rüger 2019-08-12 13:16:15 +03:00
parent fa0aa30386
commit 9a2716280c
31 changed files with 556 additions and 338 deletions

View File

@ -0,0 +1,34 @@
module Mom
module Builtin
class Comparison < ::Mom::Instruction
attr_reader :operator
def initialize(name , operator)
super(name)
@operator = operator
end
def to_risc(compiler)
builder = compiler.builder(compiler.source)
operator = @operator # make accessible in block
builder.build do
integer! << message[:receiver]
integer.reduce_int
integer_reg! << message[:arguments]
integer_reg << integer_reg[Parfait::NamedList.type_length + 0] #"other" is at index 0
integer_reg.reduce_int
swap_names(:integer , :integer_reg) if(operator.to_s.start_with?('<') )
integer.op :- , integer_reg
if_minus false_label
if_zero( false_label ) if operator.to_s.length == 1
object! << Parfait.object_space.true_object
branch merge_label
add_code false_label
object << Parfait.object_space.false_object
add_code merge_label
message[:return_value] << object
end
return compiler
end
end
end
end

65
lib/mom/builtin/div10.rb Normal file
View File

@ -0,0 +1,65 @@
module Mom
module Builtin
class Div10 < ::Mom::Instruction
def to_risc(compiler)
s = "div_10 "
builder = compiler.builder(compiler.source)
integer_tmp = builder.allocate_int
builder.build do
integer_self! << message[:receiver]
integer_self.reduce_int
integer_1! << integer_self
integer_reg! << integer_self
integer_const! << 1
integer_1.op :>> , integer_const
integer_const << 2
integer_reg.op :>> , integer_const
integer_reg.op :+ , integer_1
integer_const << 4
integer_1 << integer_reg
integer_reg.op :>> , integer_1
integer_reg.op :+ , integer_1
integer_const << 8
integer_1 << integer_reg
integer_1.op :>> , integer_const
integer_reg.op :+ , integer_1
integer_const << 16
integer_1 << integer_reg
integer_1.op :>> , integer_const
integer_reg.op :+ , integer_1
integer_const << 3
integer_reg.op :>> , integer_const
integer_const << 10
integer_1 << integer_reg
integer_1.op :* , integer_const
integer_self.op :- , integer_1
integer_1 << integer_self
integer_const << 6
integer_1.op :+ , integer_const
integer_const << 4
integer_1.op :>> , integer_const
integer_reg.op :+ , integer_1
integer_tmp[Parfait::Integer.integer_index] << integer_reg
message[:return_value] << integer_tmp
end
return compiler
end
end
end
end

19
lib/mom/builtin/div4.rb Normal file
View File

@ -0,0 +1,19 @@
module Mom
module Builtin
class Div4 < ::Mom::Instruction
def to_risc(compiler)
builder = compiler.builder(compiler.source)
integer_tmp = builder.allocate_int
builder.build do
integer_self! << message[:receiver]
integer_self.reduce_int
integer_1! << 2
integer_self.op :>> , integer_1
integer_tmp[Parfait::Integer.integer_index] << integer_self
message[:return_value] << integer_tmp
end
return compiler
end
end
end
end

12
lib/mom/builtin/exit.rb Normal file
View File

@ -0,0 +1,12 @@
module Mom
module Builtin
class Exit < ::Mom::Instruction
def to_risc(compiler)
builder = compiler.builder(compiler.source)
builder.prepare_int_return # makes integer_tmp variable as return
Builtin.exit_sequence(builder)
return compiler
end
end
end
end

View File

@ -0,0 +1,20 @@
module Mom
module Builtin
class GetInternalByte < ::Mom::Instruction
def to_risc(compiler)
builder = compiler.builder(compiler.source)
integer_tmp = builder.allocate_int
builder.build do
object! << message[:receiver]
integer! << message[:arguments]
integer << integer[Parfait::NamedList.type_length + 0] #"at" is at index 0
integer.reduce_int
object <= object[integer]
integer_tmp[Parfait::Integer.integer_index] << object
message[:return_value] << integer_tmp
end
return compiler
end
end
end
end

View File

@ -0,0 +1,16 @@
module Mom
module Builtin
class GetInternalWord < ::Mom::Instruction
def to_risc(compiler)
compiler.builder(compiler.source).build do
object! << message[:receiver]
integer! << message[:arguments]
integer << integer[Parfait::NamedList.type_length + 0] #"at" is at index 0
integer.reduce_int
object << object[integer]
message[:return_value] << object
end
end
end
end
end

36
lib/mom/builtin/init.rb Normal file
View File

@ -0,0 +1,36 @@
module Mom
module Builtin
class Init < ::Mom::Instruction
def to_risc(compiler)
builder = compiler.builder(compiler.source)
builder.build do
factory! << Parfait.object_space.get_factory_for(:Message)
message << factory[:next_object]
next_message! << message[:next_message]
factory[:next_object] << next_message
end
Mom::MessageSetup.new(Parfait.object_space.get_main).build_with( builder )
builder.build do
message << message[:next_message]
space? << Parfait.object_space
message[:receiver] << space
end
exit_label = Risc.label(compiler.source , "#{compiler.receiver_type.object_class.name}.#{compiler.source.name}" )
ret_tmp = compiler.use_reg(:Label).set_builder(builder)
builder.build do
ret_tmp << exit_label
message[:return_address] << ret_tmp
add_code Risc.function_call( "__init__ issue call" , Parfait.object_space.get_main)
add_code exit_label
end
compiler.reset_regs
exit_sequence(builder)
return compiler
end
end
end
end

View File

@ -1,3 +1,8 @@
require_relative "div4"
require_relative "div10"
require_relative "operator"
require_relative "comparison"
module Mom
module Builtin
# integer related kernel functions
@ -17,21 +22,6 @@ module Mom
compiler.add_code Div4.new("div4")
return compiler
end
class Div4 < ::Mom::Instruction
def to_risc(compiler)
builder = compiler.builder(compiler.source)
integer_tmp = builder.allocate_int
builder.build do
integer_self! << message[:receiver]
integer_self.reduce_int
integer_1! << 2
integer_self.op :>> , integer_1
integer_tmp[Parfait::Integer.integer_index] << integer_self
message[:return_value] << integer_tmp
end
return compiler
end
end
# implemented by the comparison
def >( context )
@ -62,35 +52,6 @@ module Mom
compiler.add_code Comparison.new("comparison" , operator)
return compiler
end
class Comparison < ::Mom::Instruction
attr_reader :operator
def initialize(name , operator)
super(name)
@operator = operator
end
def to_risc(compiler)
builder = compiler.builder(compiler.source)
operator = @operator # make accessible in block
builder.build do
integer! << message[:receiver]
integer.reduce_int
integer_reg! << message[:arguments]
integer_reg << integer_reg[Parfait::NamedList.type_length + 0] #"other" is at index 0
integer_reg.reduce_int
swap_names(:integer , :integer_reg) if(operator.to_s.start_with?('<') )
integer.op :- , integer_reg
if_minus false_label
if_zero( false_label ) if operator.to_s.length == 1
object! << Parfait.object_space.true_object
branch merge_label
add_code false_label
object << Parfait.object_space.false_object
add_code merge_label
message[:return_value] << object
end
return compiler
end
end
# implemented all known binary operators that map straight to machine codes
# this function (similar to comparison):
@ -100,33 +61,9 @@ module Mom
# - returns the new int
def operator_method( op_sym )
compiler = compiler_for(:Integer, op_sym ,{other: :Integer })
compiler.add_code OperatorInstruction.new("operator" , op_sym)
compiler.add_code Operator.new("operator" , op_sym)
return compiler
end
class OperatorInstruction < ::Mom::Instruction
attr_reader :operator
def initialize(name , operator)
super(name)
@operator = operator
end
def to_risc(compiler)
builder = compiler.builder(compiler.source)
integer_tmp = builder.allocate_int
operator = @operator # make accessible in block
builder.build do
integer! << message[:receiver]
integer.reduce_int
integer_reg! << message[:arguments]
integer_reg << integer_reg[Parfait::NamedList.type_length + 0] #"other" is at index 0
integer_reg.reduce_int
integer.op operator , integer_reg
integer_tmp[Parfait::Integer.integer_index] << integer
message[:return_value] << integer_tmp
end
return compiler
end
end
# as the name suggests, this devides the integer (self) by ten
#
@ -141,67 +78,6 @@ module Mom
compiler.add_code Div10.new("div10")
return compiler
end
class Div10 < ::Mom::Instruction
def to_risc(compiler)
s = "div_10 "
builder = compiler.builder(compiler.source)
integer_tmp = builder.allocate_int
builder.build do
integer_self! << message[:receiver]
integer_self.reduce_int
integer_1! << integer_self
integer_reg! << integer_self
integer_const! << 1
integer_1.op :>> , integer_const
integer_const << 2
integer_reg.op :>> , integer_const
integer_reg.op :+ , integer_1
integer_const << 4
integer_1 << integer_reg
integer_reg.op :>> , integer_1
integer_reg.op :+ , integer_1
integer_const << 8
integer_1 << integer_reg
integer_1.op :>> , integer_const
integer_reg.op :+ , integer_1
integer_const << 16
integer_1 << integer_reg
integer_1.op :>> , integer_const
integer_reg.op :+ , integer_1
integer_const << 3
integer_reg.op :>> , integer_const
integer_const << 10
integer_1 << integer_reg
integer_1.op :* , integer_const
integer_self.op :- , integer_1
integer_1 << integer_self
integer_const << 6
integer_1.op :+ , integer_const
integer_const << 4
integer_1.op :>> , integer_const
integer_reg.op :+ , integer_1
integer_tmp[Parfait::Integer.integer_index] << integer_reg
message[:return_value] << integer_tmp
end
return compiler
end
end
end
extend ClassMethods
end

View File

@ -0,0 +1,12 @@
module Mom
module Builtin
class MethodMissing < ::Mom::Instruction
def to_risc(compiler)
builder = compiler.builder(compiler.source)
builder.prepare_int_return # makes integer_tmp variable as return
Builtin.emit_syscall( builder , :exit )
return compiler
end
end
end
end

View File

@ -1,3 +1,9 @@
require_relative "get_internal_word"
require_relative "set_internal_word"
require_relative "method_missing"
require_relative "init"
require_relative "exit"
module Mom
module Builtin
class Object
@ -11,19 +17,6 @@ module Mom
compiler.add_code GetInternalWord.new("get_internal_word")
return compiler
end
class GetInternalWord < ::Mom::Instruction
def to_risc(compiler)
compiler.builder(compiler.source).build do
object! << message[:receiver]
integer! << message[:arguments]
integer << integer[Parfait::NamedList.type_length + 0] #"at" is at index 0
integer.reduce_int
object << object[integer]
message[:return_value] << object
end
end
end
# self[index] = val basically. Index is the first arg , value the second
# return the value passed in
def set_internal_word( context )
@ -32,21 +25,6 @@ module Mom
return compiler
end
class SetInternalWord < ::Mom::Instruction
def to_risc(compiler)
compiler.builder(compiler.source).build do
object! << message[:receiver]
integer! << message[:arguments]
object_reg! << integer[Parfait::NamedList.type_length + 1] #"value" is at index 1
integer << integer[Parfait::NamedList.type_length + 0] #"at" is at index 0
integer.reduce_int
object[integer] << object_reg
message[:return_value] << object_reg
end
return compiler
end
end
# every object needs a method missing.
# Even if it's just this one, sys_exit (later raise)
def _method_missing( context )
@ -55,15 +33,6 @@ module Mom
return compiler
end
class MethodMissing < ::Mom::Instruction
def to_risc(compiler)
builder = compiler.builder(compiler.source)
builder.prepare_int_return # makes integer_tmp variable as return
Builtin.emit_syscall( builder , :exit )
return compiler
end
end
# this is the really really first place the machine starts (apart from the jump here)
# 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:
@ -77,38 +46,6 @@ module Mom
return compiler
end
class Init < ::Mom::Instruction
def to_risc(compiler)
builder = compiler.builder(compiler.source)
builder.build do
factory! << Parfait.object_space.get_factory_for(:Message)
message << factory[:next_object]
next_message! << message[:next_message]
factory[:next_object] << next_message
end
Mom::MessageSetup.new(Parfait.object_space.get_main).build_with( builder )
builder.build do
message << message[:next_message]
space? << Parfait.object_space
message[:receiver] << space
end
exit_label = Risc.label(compiler.source , "#{compiler.receiver_type.object_class.name}.#{compiler.source.name}" )
ret_tmp = compiler.use_reg(:Label).set_builder(builder)
builder.build do
ret_tmp << exit_label
message[:return_address] << ret_tmp
add_code Risc.function_call( "__init__ issue call" , Parfait.object_space.get_main)
add_code exit_label
end
compiler.reset_regs
exit_sequence(builder)
return compiler
end
end
# the exit function
# mainly calls exit_sequence
def exit( context )
@ -117,14 +54,6 @@ module Mom
return compiler
end
class Exit < ::Mom::Instruction
def to_risc(compiler)
builder = compiler.builder(compiler.source)
builder.prepare_int_return # makes integer_tmp variable as return
Builtin.exit_sequence(builder)
return compiler
end
end
end
extend ClassMethods
end

View File

@ -0,0 +1,28 @@
module Mom
module Builtin
class Operator < ::Mom::Instruction
attr_reader :operator
def initialize(name , operator)
super(name)
@operator = operator
end
def to_risc(compiler)
builder = compiler.builder(compiler.source)
integer_tmp = builder.allocate_int
operator = @operator # make accessible in block
builder.build do
integer! << message[:receiver]
integer.reduce_int
integer_reg! << message[:arguments]
integer_reg << integer_reg[Parfait::NamedList.type_length + 0] #"other" is at index 0
integer_reg.reduce_int
integer.op operator , integer_reg
integer_tmp[Parfait::Integer.integer_index] << integer
message[:return_value] << integer_tmp
end
return compiler
end
end
end
end

View File

@ -0,0 +1,16 @@
module Mom
module Builtin
class Putstring < ::Mom::Instruction
def to_risc(compiler)
builder = compiler.builder(compiler.source)
builder.prepare_int_return # makes integer_tmp variable as return
builder.build do
word! << message[:receiver]
integer! << word[Parfait::Word.get_length_index]
end
Mom::Builtin.emit_syscall( builder , :putstring )
compiler
end
end
end
end

View File

@ -0,0 +1,19 @@
module Mom
module Builtin
class SetInternalByte < ::Mom::Instruction
def to_risc(compiler)
compiler.builder(compiler.source).build do
word! << message[:receiver]
integer! << message[:arguments]
integer_reg! << integer[Parfait::NamedList.type_length + 1] #"value" is at index 1
message[:return_value] << integer_reg
integer << integer[Parfait::NamedList.type_length + 0] #"at" is at index 0
integer.reduce_int
integer_reg.reduce_int
word[integer] <= integer_reg
end
return compiler
end
end
end
end

View File

@ -0,0 +1,18 @@
module Mom
module Builtin
class SetInternalWord < ::Mom::Instruction
def to_risc(compiler)
compiler.builder(compiler.source).build do
object! << message[:receiver]
integer! << message[:arguments]
object_reg! << integer[Parfait::NamedList.type_length + 1] #"value" is at index 1
integer << integer[Parfait::NamedList.type_length + 0] #"at" is at index 0
integer.reduce_int
object[integer] << object_reg
message[:return_value] << object_reg
end
return compiler
end
end
end
end

View File

@ -1,3 +1,7 @@
require_relative "get_internal_byte"
require_relative "set_internal_byte"
require_relative "putstring"
module Mom
module Builtin
module Word
@ -15,18 +19,6 @@ module Mom
compiler.add_code Putstring.new("putstring")
return compiler
end
class Putstring < ::Mom::Instruction
def to_risc(compiler)
builder = compiler.builder(compiler.source)
builder.prepare_int_return # makes integer_tmp variable as return
builder.build do
word! << message[:receiver]
integer! << word[Parfait::Word.get_length_index]
end
Mom::Builtin.emit_syscall( builder , :putstring )
compiler
end
end
# self[index] basically. Index is the first arg > 0
# return a word sized new int, in return_value
#
@ -37,22 +29,6 @@ module Mom
compiler.add_code GetInternalByte.new("get_internal_byte")
return compiler
end
class GetInternalByte < ::Mom::Instruction
def to_risc(compiler)
builder = compiler.builder(compiler.source)
integer_tmp = builder.allocate_int
builder.build do
object! << message[:receiver]
integer! << message[:arguments]
integer << integer[Parfait::NamedList.type_length + 0] #"at" is at index 0
integer.reduce_int
object <= object[integer]
integer_tmp[Parfait::Integer.integer_index] << object
message[:return_value] << integer_tmp
end
return compiler
end
end
# self[index] = val basically. Index is the first arg ( >0 , unchecked),
# value the second, which is also returned
def set_internal_byte( context )
@ -60,21 +36,6 @@ module Mom
compiler.add_code SetInternalByte.new("set_internal_byte")
return compiler
end
class SetInternalByte < ::Mom::Instruction
def to_risc(compiler)
compiler.builder(compiler.source).build do
word! << message[:receiver]
integer! << message[:arguments]
integer_reg! << integer[Parfait::NamedList.type_length + 1] #"value" is at index 1
message[:return_value] << integer_reg
integer << integer[Parfait::NamedList.type_length + 0] #"at" is at index 0
integer.reduce_int
integer_reg.reduce_int
word[integer] <= integer_reg
end
return compiler
end
end
end
extend ClassMethods
end

View File

@ -1,8 +1,10 @@
# Builtin Testing
Mostly testing that
At the Module level (word/object/integer) mostly testing that
- functions exist
- they compile
- basic length tests (no "contents")
Minimal tests for risc compilation, and again length only (should be array too)
Functionality is tested by interpreter over in interpreter dir

View File

@ -0,0 +1,30 @@
require_relative "helper"
module Mom
module Builtin
class TestIntComp1Risc < BootTest
def setup
super
@method = get_compiler(:<)
end
def test_compile
assert_equal Risc::MethodCompiler , @method.to_risc.class
end
def test_risc_length
assert_equal 28 , @method.to_risc.risc_instructions.length
end
end
class TestIntComp2Risc < BootTest
def setup
super
@method = get_compiler(:>=)
end
def test_compile
assert_equal Risc::MethodCompiler , @method.to_risc.class
end
def test_risc_length
assert_equal 27 , @method.to_risc.risc_instructions.length
end
end
end
end

View File

@ -0,0 +1,18 @@
require_relative "helper"
module Mom
module Builtin
class TestIntDiv10Risc < BootTest
def setup
super
@method = get_compiler(:div10)
end
def test_compile
assert_equal Risc::MethodCompiler , @method.to_risc.class
end
def test_risc_length
assert_equal 76 , @method.to_risc.risc_instructions.length
end
end
end
end

View File

@ -0,0 +1,18 @@
require_relative "helper"
module Mom
module Builtin
class TestIntDiv4Risc < BootTest
def setup
super
@method = get_compiler(:div4)
end
def test_compile
assert_equal Risc::MethodCompiler , @method.to_risc.class
end
def test_risc_length
assert_equal 47 , @method.to_risc.risc_instructions.length
end
end
end
end

View File

@ -0,0 +1,18 @@
require_relative "helper"
module Mom
module Builtin
class TestObjectExitRisc < BootTest
def setup
super
@method = get_compiler(:exit)
end
def test_compile
assert_equal Risc::MethodCompiler , @method.to_risc.class
end
def test_risc_length
assert_equal 46 , @method.to_risc.risc_instructions.length
end
end
end
end

View File

@ -0,0 +1,18 @@
require_relative "helper"
module Mom
module Builtin
class TestWordGetRisc < BootTest
def setup
super
@method = get_compiler(:get_internal_byte)
end
def test_compile
assert_equal Risc::MethodCompiler , @method.to_risc.class
end
def test_risc_length
assert_equal 48 , @method.to_risc.risc_instructions.length
end
end
end
end

View File

@ -0,0 +1,18 @@
require_relative "helper"
module Mom
module Builtin
class TestWordGetRisc < BootTest
def setup
super
@method = get_compiler(:get_internal_byte)
end
def test_compile
assert_equal Risc::MethodCompiler , @method.to_risc.class
end
def test_risc_length
assert_equal 48 , @method.to_risc.risc_instructions.length
end
end
end
end

View File

@ -0,0 +1,18 @@
require_relative "helper"
module Mom
module Builtin
class TestObjectInitRisc < BootTest
def setup
super
@method = get_compiler(:__init__)
end
def test_compile
assert_equal Risc::MethodCompiler , @method.to_risc.class
end
def test_risc_length
assert_equal 48 , @method.to_risc.risc_instructions.length
end
end
end
end

View File

@ -13,12 +13,6 @@ module Mom
def test_mom_length
assert_equal 5 , @method.mom_instructions.length
end
def test_compile
assert_equal Risc::MethodCompiler , @method.to_risc.class
end
def test_risc_length
assert_equal 47 , @method.to_risc.risc_instructions.length
end
end
class TestIntDiv10 < BootTest
def setup
@ -31,12 +25,6 @@ module Mom
def test_mom_length
assert_equal 5 , @method.mom_instructions.length
end
def test_compile
assert_equal Risc::MethodCompiler , @method.to_risc.class
end
def test_risc_length
assert_equal 76 , @method.to_risc.risc_instructions.length
end
end
class TestIntComp1 < BootTest
def setup
@ -49,12 +37,6 @@ module Mom
def test_mom_length
assert_equal 5 , @method.mom_instructions.length
end
def test_compile
assert_equal Risc::MethodCompiler , @method.to_risc.class
end
def test_risc_length
assert_equal 28 , @method.to_risc.risc_instructions.length
end
end
class TestIntComp2 < BootTest
def setup
@ -67,12 +49,6 @@ module Mom
def test_mom_length
assert_equal 5 , @method.mom_instructions.length
end
def test_compile
assert_equal Risc::MethodCompiler , @method.to_risc.class
end
def test_risc_length
assert_equal 27 , @method.to_risc.risc_instructions.length
end
end
class TestIntOperators < BootTest
def setup
@ -90,16 +66,6 @@ module Mom
assert_equal 5 , method.mom_instructions.length
end
end
def test_compile
each_method do |method|
assert_equal Risc::MethodCompiler , method.to_risc.class
end
end
def test_risc_length
each_method do |method|
assert_equal 49 , method.to_risc.risc_instructions.length
end
end
end
end
end

View File

@ -0,0 +1,18 @@
require_relative "helper"
module Mom
module Builtin
class TestObjectMissingRisc < BootTest
def setup
super
@method = get_compiler(:method_missing)
end
def test_compile
assert_equal Risc::MethodCompiler , @method.to_risc.class
end
def test_risc_length
assert_equal 48 , @method.to_risc.risc_instructions.length
end
end
end
end

View File

@ -2,7 +2,7 @@ require_relative "helper"
module Mom
module Builtin
class TestObjectFunctionGet < BootTest
class TestObjectGet < BootTest
def setup
super
@method = get_compiler(:get_internal_word)
@ -13,14 +13,8 @@ module Mom
def test_mom_length
assert_equal 5 , @method.mom_instructions.length
end
def test_compile
assert_equal Risc::MethodCompiler , @method.to_risc.class
end
def test_risc_length
assert_equal 20 , @method.to_risc.risc_instructions.length
end
end
class TestObjectFunctionSet < BootTest
class TestObjectSet < BootTest
def setup
super
@method = get_compiler(:set_internal_word)
@ -31,14 +25,8 @@ module Mom
def test_mom_length
assert_equal 5 , @method.mom_instructions.length
end
def test_compile
assert_equal Risc::MethodCompiler , @method.to_risc.class
end
def test_risc_length
assert_equal 21 , @method.to_risc.risc_instructions.length
end
end
class TestObjectFunctionMissing < BootTest
class TestObjectMissing < BootTest
def setup
super
@method = get_compiler(:method_missing)
@ -49,14 +37,8 @@ module Mom
def test_mom_length
assert_equal 5 , @method.mom_instructions.length
end
def test_compile
assert_equal Risc::MethodCompiler , @method.to_risc.class
end
def test_risc_length
assert_equal 48 , @method.to_risc.risc_instructions.length
end
end
class TestObjectFunctionExit < BootTest
class TestObjectExit < BootTest
def setup
super
@method = get_compiler(:exit)
@ -67,14 +49,8 @@ module Mom
def test_mom_length
assert_equal 5 , @method.mom_instructions.length
end
def test_compile
assert_equal Risc::MethodCompiler , @method.to_risc.class
end
def test_risc_length
assert_equal 46 , @method.to_risc.risc_instructions.length
end
end
class TestObjectFunctionInit < BootTest
class TestObjectInit < BootTest
def setup
super
@method = get_compiler(:__init__)
@ -85,12 +61,6 @@ module Mom
def test_mom_length
assert_equal 5 , @method.mom_instructions.length
end
def test_compile
assert_equal Risc::MethodCompiler , @method.to_risc.class
end
def test_risc_length
assert_equal 48 , @method.to_risc.risc_instructions.length
end
end
end
end

View File

@ -0,0 +1,27 @@
require_relative "helper"
module Mom
module Builtin
class TestIntOperatorsRisc < BootTest
def setup
super
end
def each_method &block
Risc.operators.each do |name|
method = get_compiler(name)
block.yield(method)
end
end
def test_compile
each_method do |method|
assert_equal Risc::MethodCompiler , method.to_risc.class
end
end
def test_risc_length
each_method do |method|
assert_equal 49 , method.to_risc.risc_instructions.length
end
end
end
end
end

View File

@ -0,0 +1,18 @@
require_relative "helper"
module Mom
module Builtin
class TestWordPutRisc < BootTest
def setup
super
@method = get_compiler(:putstring)
end
def test_compile
assert_equal Risc::MethodCompiler , @method.to_risc.class
end
def test_risc_length
assert_equal 50 , @method.to_risc.risc_instructions.length
end
end
end
end

View File

@ -0,0 +1,18 @@
require_relative "helper"
module Mom
module Builtin
class TestWordSetRisc < BootTest
def setup
super
@method = get_compiler(:set_internal_byte)
end
def test_compile
assert_equal Risc::MethodCompiler , @method.to_risc.class
end
def test_risc_length
assert_equal 22 , @method.to_risc.risc_instructions.length
end
end
end
end

View File

@ -0,0 +1,18 @@
require_relative "helper"
module Mom
module Builtin
class TestWordSetRisc < BootTest
def setup
super
@method = get_compiler(:set_internal_byte)
end
def test_compile
assert_equal Risc::MethodCompiler , @method.to_risc.class
end
def test_risc_length
assert_equal 22 , @method.to_risc.risc_instructions.length
end
end
end
end

View File

@ -13,12 +13,6 @@ module Mom
def test_mom_length
assert_equal 5 , @method.mom_instructions.length
end
def test_compile
assert_equal Risc::MethodCompiler , @method.to_risc.class
end
def test_risc_length
assert_equal 50 , @method.to_risc.risc_instructions.length
end
end
class TestWordGet < BootTest
def setup
@ -31,12 +25,6 @@ module Mom
def test_mom_length
assert_equal 5 , @method.mom_instructions.length
end
def test_compile
assert_equal Risc::MethodCompiler , @method.to_risc.class
end
def test_risc_length
assert_equal 48 , @method.to_risc.risc_instructions.length
end
end
class TestWordSet < BootTest
def setup
@ -49,12 +37,6 @@ module Mom
def test_mom_length
assert_equal 5 , @method.mom_instructions.length
end
def test_compile
assert_equal Risc::MethodCompiler , @method.to_risc.class
end
def test_risc_length
assert_equal 22 , @method.to_risc.risc_instructions.length
end
end
end
end