starting to fix builtin
start at Object get_interna_word using the pattern to replace the whole risc method with a single mom instruction. Copying the original risc code into the instrucitons to_risc also adding some very basic tests
This commit is contained in:
@ -1,14 +0,0 @@
|
||||
|
||||
module Risc
|
||||
module Builtin
|
||||
module CompileHelper
|
||||
|
||||
def compiler_for( clazz_name , method_name , arguments , locals = {})
|
||||
frame = Parfait::NamedList.type_for( locals )
|
||||
args = Parfait::NamedList.type_for( arguments )
|
||||
MethodCompiler.compiler_for_class(clazz_name , method_name , args, frame )
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
@ -8,17 +8,21 @@ module Risc
|
||||
# return is stored in return_value
|
||||
def get_internal_word( context )
|
||||
compiler = compiler_for(:Object , :get_internal_word ,{at: :Integer})
|
||||
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
|
||||
compiler.add_mom( Mom::ReturnSequence.new)
|
||||
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
|
||||
|
@ -8,7 +8,6 @@ module Risc
|
||||
# defined here as empty, to be redefined
|
||||
def main(context)
|
||||
compiler = compiler_for(:Space , :main ,{args: :Integer})
|
||||
compiler.add_mom( Mom::ReturnSequence.new)
|
||||
return compiler
|
||||
end
|
||||
|
||||
|
Reference in New Issue
Block a user