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:
2019-08-12 13:16:15 +03:00
parent fa0aa30386
commit 9a2716280c
31 changed files with 556 additions and 338 deletions

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