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:
parent
fa0aa30386
commit
9a2716280c
34
lib/mom/builtin/comparison.rb
Normal file
34
lib/mom/builtin/comparison.rb
Normal 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
65
lib/mom/builtin/div10.rb
Normal 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
19
lib/mom/builtin/div4.rb
Normal 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
12
lib/mom/builtin/exit.rb
Normal 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
|
20
lib/mom/builtin/get_internal_byte.rb
Normal file
20
lib/mom/builtin/get_internal_byte.rb
Normal 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
|
16
lib/mom/builtin/get_internal_word.rb
Normal file
16
lib/mom/builtin/get_internal_word.rb
Normal 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
36
lib/mom/builtin/init.rb
Normal 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
|
@ -1,3 +1,8 @@
|
|||||||
|
require_relative "div4"
|
||||||
|
require_relative "div10"
|
||||||
|
require_relative "operator"
|
||||||
|
require_relative "comparison"
|
||||||
|
|
||||||
module Mom
|
module Mom
|
||||||
module Builtin
|
module Builtin
|
||||||
# integer related kernel functions
|
# integer related kernel functions
|
||||||
@ -17,21 +22,6 @@ module Mom
|
|||||||
compiler.add_code Div4.new("div4")
|
compiler.add_code Div4.new("div4")
|
||||||
return compiler
|
return compiler
|
||||||
end
|
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
|
# implemented by the comparison
|
||||||
def >( context )
|
def >( context )
|
||||||
@ -62,35 +52,6 @@ module Mom
|
|||||||
compiler.add_code Comparison.new("comparison" , operator)
|
compiler.add_code Comparison.new("comparison" , operator)
|
||||||
return compiler
|
return compiler
|
||||||
end
|
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
|
# implemented all known binary operators that map straight to machine codes
|
||||||
# this function (similar to comparison):
|
# this function (similar to comparison):
|
||||||
@ -100,33 +61,9 @@ module Mom
|
|||||||
# - returns the new int
|
# - returns the new int
|
||||||
def operator_method( op_sym )
|
def operator_method( op_sym )
|
||||||
compiler = compiler_for(:Integer, op_sym ,{other: :Integer })
|
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
|
return compiler
|
||||||
end
|
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
|
# as the name suggests, this devides the integer (self) by ten
|
||||||
#
|
#
|
||||||
@ -141,67 +78,6 @@ module Mom
|
|||||||
compiler.add_code Div10.new("div10")
|
compiler.add_code Div10.new("div10")
|
||||||
return compiler
|
return compiler
|
||||||
end
|
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
|
end
|
||||||
extend ClassMethods
|
extend ClassMethods
|
||||||
end
|
end
|
||||||
|
12
lib/mom/builtin/method_missing.rb
Normal file
12
lib/mom/builtin/method_missing.rb
Normal 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
|
@ -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 Mom
|
||||||
module Builtin
|
module Builtin
|
||||||
class Object
|
class Object
|
||||||
@ -11,19 +17,6 @@ module Mom
|
|||||||
compiler.add_code GetInternalWord.new("get_internal_word")
|
compiler.add_code GetInternalWord.new("get_internal_word")
|
||||||
return compiler
|
return compiler
|
||||||
end
|
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
|
# self[index] = val basically. Index is the first arg , value the second
|
||||||
# return the value passed in
|
# return the value passed in
|
||||||
def set_internal_word( context )
|
def set_internal_word( context )
|
||||||
@ -32,21 +25,6 @@ module Mom
|
|||||||
return compiler
|
return compiler
|
||||||
end
|
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.
|
# every object needs a method missing.
|
||||||
# Even if it's just this one, sys_exit (later raise)
|
# Even if it's just this one, sys_exit (later raise)
|
||||||
def _method_missing( context )
|
def _method_missing( context )
|
||||||
@ -55,15 +33,6 @@ module Mom
|
|||||||
return compiler
|
return compiler
|
||||||
end
|
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)
|
# 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
|
# 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:
|
# so it is responsible for initial setup:
|
||||||
@ -77,38 +46,6 @@ module Mom
|
|||||||
return compiler
|
return compiler
|
||||||
end
|
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
|
# the exit function
|
||||||
# mainly calls exit_sequence
|
# mainly calls exit_sequence
|
||||||
def exit( context )
|
def exit( context )
|
||||||
@ -117,14 +54,6 @@ module Mom
|
|||||||
return compiler
|
return compiler
|
||||||
end
|
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
|
end
|
||||||
extend ClassMethods
|
extend ClassMethods
|
||||||
end
|
end
|
||||||
|
28
lib/mom/builtin/operator.rb
Normal file
28
lib/mom/builtin/operator.rb
Normal 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
|
16
lib/mom/builtin/putstring.rb
Normal file
16
lib/mom/builtin/putstring.rb
Normal 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
|
19
lib/mom/builtin/set_internal_byte.rb
Normal file
19
lib/mom/builtin/set_internal_byte.rb
Normal 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
|
18
lib/mom/builtin/set_internal_word.rb
Normal file
18
lib/mom/builtin/set_internal_word.rb
Normal 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
|
@ -1,3 +1,7 @@
|
|||||||
|
require_relative "get_internal_byte"
|
||||||
|
require_relative "set_internal_byte"
|
||||||
|
require_relative "putstring"
|
||||||
|
|
||||||
module Mom
|
module Mom
|
||||||
module Builtin
|
module Builtin
|
||||||
module Word
|
module Word
|
||||||
@ -15,18 +19,6 @@ module Mom
|
|||||||
compiler.add_code Putstring.new("putstring")
|
compiler.add_code Putstring.new("putstring")
|
||||||
return compiler
|
return compiler
|
||||||
end
|
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
|
# self[index] basically. Index is the first arg > 0
|
||||||
# return a word sized new int, in return_value
|
# return a word sized new int, in return_value
|
||||||
#
|
#
|
||||||
@ -37,22 +29,6 @@ module Mom
|
|||||||
compiler.add_code GetInternalByte.new("get_internal_byte")
|
compiler.add_code GetInternalByte.new("get_internal_byte")
|
||||||
return compiler
|
return compiler
|
||||||
end
|
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),
|
# self[index] = val basically. Index is the first arg ( >0 , unchecked),
|
||||||
# value the second, which is also returned
|
# value the second, which is also returned
|
||||||
def set_internal_byte( context )
|
def set_internal_byte( context )
|
||||||
@ -60,21 +36,6 @@ module Mom
|
|||||||
compiler.add_code SetInternalByte.new("set_internal_byte")
|
compiler.add_code SetInternalByte.new("set_internal_byte")
|
||||||
return compiler
|
return compiler
|
||||||
end
|
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
|
end
|
||||||
extend ClassMethods
|
extend ClassMethods
|
||||||
end
|
end
|
||||||
|
@ -1,8 +1,10 @@
|
|||||||
# Builtin Testing
|
# Builtin Testing
|
||||||
|
|
||||||
Mostly testing that
|
At the Module level (word/object/integer) mostly testing that
|
||||||
- functions exist
|
- functions exist
|
||||||
- they compile
|
- they compile
|
||||||
- basic length tests (no "contents")
|
- 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
|
Functionality is tested by interpreter over in interpreter dir
|
||||||
|
30
test/mom/builtin/test_comparison.rb
Normal file
30
test/mom/builtin/test_comparison.rb
Normal 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
|
18
test/mom/builtin/test_div10.rb
Normal file
18
test/mom/builtin/test_div10.rb
Normal 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
|
18
test/mom/builtin/test_div4.rb
Normal file
18
test/mom/builtin/test_div4.rb
Normal 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
|
18
test/mom/builtin/test_exit.rb
Normal file
18
test/mom/builtin/test_exit.rb
Normal 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
|
18
test/mom/builtin/test_get_internal_byte.rb
Normal file
18
test/mom/builtin/test_get_internal_byte.rb
Normal 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
|
18
test/mom/builtin/test_get_internal_word.rb
Normal file
18
test/mom/builtin/test_get_internal_word.rb
Normal 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
|
18
test/mom/builtin/test_init.rb
Normal file
18
test/mom/builtin/test_init.rb
Normal 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
|
@ -13,12 +13,6 @@ module Mom
|
|||||||
def test_mom_length
|
def test_mom_length
|
||||||
assert_equal 5 , @method.mom_instructions.length
|
assert_equal 5 , @method.mom_instructions.length
|
||||||
end
|
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
|
||||||
class TestIntDiv10 < BootTest
|
class TestIntDiv10 < BootTest
|
||||||
def setup
|
def setup
|
||||||
@ -31,12 +25,6 @@ module Mom
|
|||||||
def test_mom_length
|
def test_mom_length
|
||||||
assert_equal 5 , @method.mom_instructions.length
|
assert_equal 5 , @method.mom_instructions.length
|
||||||
end
|
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
|
||||||
class TestIntComp1 < BootTest
|
class TestIntComp1 < BootTest
|
||||||
def setup
|
def setup
|
||||||
@ -49,12 +37,6 @@ module Mom
|
|||||||
def test_mom_length
|
def test_mom_length
|
||||||
assert_equal 5 , @method.mom_instructions.length
|
assert_equal 5 , @method.mom_instructions.length
|
||||||
end
|
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
|
end
|
||||||
class TestIntComp2 < BootTest
|
class TestIntComp2 < BootTest
|
||||||
def setup
|
def setup
|
||||||
@ -67,12 +49,6 @@ module Mom
|
|||||||
def test_mom_length
|
def test_mom_length
|
||||||
assert_equal 5 , @method.mom_instructions.length
|
assert_equal 5 , @method.mom_instructions.length
|
||||||
end
|
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
|
||||||
class TestIntOperators < BootTest
|
class TestIntOperators < BootTest
|
||||||
def setup
|
def setup
|
||||||
@ -90,16 +66,6 @@ module Mom
|
|||||||
assert_equal 5 , method.mom_instructions.length
|
assert_equal 5 , method.mom_instructions.length
|
||||||
end
|
end
|
||||||
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
|
end
|
||||||
end
|
end
|
||||||
|
18
test/mom/builtin/test_method_missing.rb
Normal file
18
test/mom/builtin/test_method_missing.rb
Normal 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
|
@ -2,7 +2,7 @@ require_relative "helper"
|
|||||||
|
|
||||||
module Mom
|
module Mom
|
||||||
module Builtin
|
module Builtin
|
||||||
class TestObjectFunctionGet < BootTest
|
class TestObjectGet < BootTest
|
||||||
def setup
|
def setup
|
||||||
super
|
super
|
||||||
@method = get_compiler(:get_internal_word)
|
@method = get_compiler(:get_internal_word)
|
||||||
@ -13,14 +13,8 @@ module Mom
|
|||||||
def test_mom_length
|
def test_mom_length
|
||||||
assert_equal 5 , @method.mom_instructions.length
|
assert_equal 5 , @method.mom_instructions.length
|
||||||
end
|
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
|
end
|
||||||
class TestObjectFunctionSet < BootTest
|
class TestObjectSet < BootTest
|
||||||
def setup
|
def setup
|
||||||
super
|
super
|
||||||
@method = get_compiler(:set_internal_word)
|
@method = get_compiler(:set_internal_word)
|
||||||
@ -31,14 +25,8 @@ module Mom
|
|||||||
def test_mom_length
|
def test_mom_length
|
||||||
assert_equal 5 , @method.mom_instructions.length
|
assert_equal 5 , @method.mom_instructions.length
|
||||||
end
|
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
|
end
|
||||||
class TestObjectFunctionMissing < BootTest
|
class TestObjectMissing < BootTest
|
||||||
def setup
|
def setup
|
||||||
super
|
super
|
||||||
@method = get_compiler(:method_missing)
|
@method = get_compiler(:method_missing)
|
||||||
@ -49,14 +37,8 @@ module Mom
|
|||||||
def test_mom_length
|
def test_mom_length
|
||||||
assert_equal 5 , @method.mom_instructions.length
|
assert_equal 5 , @method.mom_instructions.length
|
||||||
end
|
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
|
||||||
class TestObjectFunctionExit < BootTest
|
class TestObjectExit < BootTest
|
||||||
def setup
|
def setup
|
||||||
super
|
super
|
||||||
@method = get_compiler(:exit)
|
@method = get_compiler(:exit)
|
||||||
@ -67,14 +49,8 @@ module Mom
|
|||||||
def test_mom_length
|
def test_mom_length
|
||||||
assert_equal 5 , @method.mom_instructions.length
|
assert_equal 5 , @method.mom_instructions.length
|
||||||
end
|
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
|
||||||
class TestObjectFunctionInit < BootTest
|
class TestObjectInit < BootTest
|
||||||
def setup
|
def setup
|
||||||
super
|
super
|
||||||
@method = get_compiler(:__init__)
|
@method = get_compiler(:__init__)
|
||||||
@ -85,12 +61,6 @@ module Mom
|
|||||||
def test_mom_length
|
def test_mom_length
|
||||||
assert_equal 5 , @method.mom_instructions.length
|
assert_equal 5 , @method.mom_instructions.length
|
||||||
end
|
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
|
end
|
||||||
end
|
end
|
||||||
|
27
test/mom/builtin/test_operator.rb
Normal file
27
test/mom/builtin/test_operator.rb
Normal 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
|
18
test/mom/builtin/test_putstring.rb
Normal file
18
test/mom/builtin/test_putstring.rb
Normal 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
|
18
test/mom/builtin/test_set_internal_byte.rb
Normal file
18
test/mom/builtin/test_set_internal_byte.rb
Normal 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
|
18
test/mom/builtin/test_set_internal_word.rb
Normal file
18
test/mom/builtin/test_set_internal_word.rb
Normal 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
|
@ -13,12 +13,6 @@ module Mom
|
|||||||
def test_mom_length
|
def test_mom_length
|
||||||
assert_equal 5 , @method.mom_instructions.length
|
assert_equal 5 , @method.mom_instructions.length
|
||||||
end
|
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
|
||||||
class TestWordGet < BootTest
|
class TestWordGet < BootTest
|
||||||
def setup
|
def setup
|
||||||
@ -31,12 +25,6 @@ module Mom
|
|||||||
def test_mom_length
|
def test_mom_length
|
||||||
assert_equal 5 , @method.mom_instructions.length
|
assert_equal 5 , @method.mom_instructions.length
|
||||||
end
|
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
|
||||||
class TestWordSet < BootTest
|
class TestWordSet < BootTest
|
||||||
def setup
|
def setup
|
||||||
@ -49,12 +37,6 @@ module Mom
|
|||||||
def test_mom_length
|
def test_mom_length
|
||||||
assert_equal 5 , @method.mom_instructions.length
|
assert_equal 5 , @method.mom_instructions.length
|
||||||
end
|
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
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user