tests for word macros
This commit is contained in:
parent
f264aec94a
commit
e8bfb9a58c
@ -16,4 +16,19 @@ module Mom
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
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[:arg1] #"at"
|
||||||
|
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
|
||||||
|
@ -13,4 +13,16 @@ module Mom
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
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
|
||||||
end
|
end
|
||||||
|
@ -15,4 +15,18 @@ module Mom
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
class SetInternalByte < ::Mom::Instruction
|
||||||
|
def to_risc(compiler)
|
||||||
|
compiler.builder(compiler.source).build do
|
||||||
|
word! << message[:receiver]
|
||||||
|
integer_reg! << message[:arg2] #VALUE
|
||||||
|
message[:return_value] << integer_reg
|
||||||
|
integer! << message[:arg1] #"index"
|
||||||
|
integer.reduce_int
|
||||||
|
integer_reg.reduce_int
|
||||||
|
word[integer] <= integer_reg
|
||||||
|
end
|
||||||
|
return compiler
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
@ -14,4 +14,17 @@ module Mom
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
class SetInternalWord < ::Mom::Instruction
|
||||||
|
def to_risc(compiler)
|
||||||
|
compiler.builder(compiler.source).build do
|
||||||
|
object! << message[:receiver]
|
||||||
|
integer! << message[:arg1] # "index"
|
||||||
|
object_reg! << message[:arg2]#"value"
|
||||||
|
integer.reduce_int
|
||||||
|
object[integer] << object_reg
|
||||||
|
message[:return_value] << object_reg
|
||||||
|
end
|
||||||
|
return compiler
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
@ -3,7 +3,8 @@ require_relative "../helper"
|
|||||||
module RubyX
|
module RubyX
|
||||||
module BuiltinHelper
|
module BuiltinHelper
|
||||||
def setup
|
def setup
|
||||||
@mom = RubyXCompiler.new(RubyX.default_test_options).ruby_to_mom(source)
|
whole ="class Space;def main(arg);return;end;end;" + source
|
||||||
|
@mom = RubyXCompiler.new(RubyX.default_test_options).ruby_to_mom(whole)
|
||||||
@mom.method_compilers.first
|
@mom.method_compilers.first
|
||||||
assert_equal Mom::MomCollection , @mom.class
|
assert_equal Mom::MomCollection , @mom.class
|
||||||
assert_equal Mom::MethodCompiler , compiler.class
|
assert_equal Mom::MethodCompiler , compiler.class
|
||||||
|
@ -6,11 +6,6 @@ module RubyX
|
|||||||
include BuiltinHelper
|
include BuiltinHelper
|
||||||
def source
|
def source
|
||||||
<<GET
|
<<GET
|
||||||
class Space
|
|
||||||
def main(arg)
|
|
||||||
return
|
|
||||||
end
|
|
||||||
end
|
|
||||||
class Object
|
class Object
|
||||||
def exit(at)
|
def exit(at)
|
||||||
X.exit
|
X.exit
|
||||||
|
@ -6,11 +6,6 @@ module RubyX
|
|||||||
include BuiltinHelper
|
include BuiltinHelper
|
||||||
def source
|
def source
|
||||||
<<GET
|
<<GET
|
||||||
class Space
|
|
||||||
def main(arg)
|
|
||||||
return
|
|
||||||
end
|
|
||||||
end
|
|
||||||
class Object
|
class Object
|
||||||
def __init(at)
|
def __init(at)
|
||||||
X.__init
|
X.__init
|
||||||
|
30
test/rubyx/builtin/test_word_get.rb
Normal file
30
test/rubyx/builtin/test_word_get.rb
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
require_relative "helper"
|
||||||
|
|
||||||
|
module RubyX
|
||||||
|
module Builtin
|
||||||
|
class TestWordGet < MiniTest::Test
|
||||||
|
include BuiltinHelper
|
||||||
|
def source
|
||||||
|
<<GET
|
||||||
|
class Word
|
||||||
|
def get_internal_byte(at)
|
||||||
|
X.get_internal_byte
|
||||||
|
end
|
||||||
|
end
|
||||||
|
GET
|
||||||
|
end
|
||||||
|
def test_mom_meth
|
||||||
|
assert_equal :get_internal_byte , compiler.callable.name
|
||||||
|
end
|
||||||
|
def test_instr_len
|
||||||
|
assert_equal 7 , compiler.mom_instructions.length
|
||||||
|
end
|
||||||
|
def test_instr_get
|
||||||
|
assert_equal Mom::GetInternalByte , compiler.mom_instructions.next.class
|
||||||
|
end
|
||||||
|
def test_risc
|
||||||
|
assert_equal 41 , compiler.to_risc.risc_instructions.length
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
30
test/rubyx/builtin/test_word_putstring.rb
Normal file
30
test/rubyx/builtin/test_word_putstring.rb
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
require_relative "helper"
|
||||||
|
|
||||||
|
module RubyX
|
||||||
|
module Builtin
|
||||||
|
class TestWordPutstring < MiniTest::Test
|
||||||
|
include BuiltinHelper
|
||||||
|
def source
|
||||||
|
<<GET
|
||||||
|
class Word
|
||||||
|
def putstring
|
||||||
|
X.putstring
|
||||||
|
end
|
||||||
|
end
|
||||||
|
GET
|
||||||
|
end
|
||||||
|
def test_mom_meth
|
||||||
|
assert_equal :putstring , compiler.callable.name
|
||||||
|
end
|
||||||
|
def test_instr_len
|
||||||
|
assert_equal 7 , compiler.mom_instructions.length
|
||||||
|
end
|
||||||
|
def test_instr_get
|
||||||
|
assert_equal Mom::Putstring , compiler.mom_instructions.next.class
|
||||||
|
end
|
||||||
|
def test_risc
|
||||||
|
assert_equal 44 , compiler.to_risc.risc_instructions.length
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
30
test/rubyx/builtin/test_word_set.rb
Normal file
30
test/rubyx/builtin/test_word_set.rb
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
require_relative "helper"
|
||||||
|
|
||||||
|
module RubyX
|
||||||
|
module Builtin
|
||||||
|
class TestWordSet < MiniTest::Test
|
||||||
|
include BuiltinHelper
|
||||||
|
def source
|
||||||
|
<<GET
|
||||||
|
class Word
|
||||||
|
def set_internal_byte( at , value)
|
||||||
|
X.set_internal_byte
|
||||||
|
end
|
||||||
|
end
|
||||||
|
GET
|
||||||
|
end
|
||||||
|
def test_mom_meth
|
||||||
|
assert_equal :set_internal_byte , compiler.callable.name
|
||||||
|
end
|
||||||
|
def test_instr_len
|
||||||
|
assert_equal 7 , compiler.mom_instructions.length
|
||||||
|
end
|
||||||
|
def test_instr_get
|
||||||
|
assert_equal Mom::SetInternalByte , compiler.mom_instructions.next.class
|
||||||
|
end
|
||||||
|
def test_risc
|
||||||
|
assert_equal 20 , compiler.to_risc.risc_instructions.length
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
Loading…
x
Reference in New Issue
Block a user