2016-12-15 18:31:39 +01:00
|
|
|
require_relative "compile_helper"
|
|
|
|
|
2015-07-01 20:45:41 +02:00
|
|
|
module Register
|
|
|
|
module Builtin
|
|
|
|
module Word
|
|
|
|
module ClassMethods
|
2016-12-15 18:31:39 +01:00
|
|
|
include CompileHelper
|
2015-11-19 09:08:41 +01:00
|
|
|
|
2015-07-01 20:45:41 +02:00
|
|
|
def putstring context
|
2017-01-17 20:23:58 +01:00
|
|
|
compiler = Vm::MethodCompiler.create_method(:Word , :putstring ).init_method
|
2016-12-28 19:37:54 +01:00
|
|
|
compiler.add_slot_to_reg( "putstring" , :message , :receiver , :new_message )
|
2015-11-16 17:03:29 +01:00
|
|
|
index = Parfait::Word.get_length_index
|
|
|
|
reg = RegisterValue.new(:r2 , :Integer)
|
2016-12-28 19:37:54 +01:00
|
|
|
compiler.add_slot_to_reg( "putstring" , :new_message , index , reg )
|
2015-10-28 20:37:42 +01:00
|
|
|
Kernel.emit_syscall( compiler , :putstring )
|
|
|
|
compiler.method
|
2015-07-01 20:45:41 +02:00
|
|
|
end
|
2016-12-15 18:31:39 +01:00
|
|
|
|
2015-11-19 09:08:41 +01:00
|
|
|
# self[index] basically. Index is the first arg > 0
|
|
|
|
# return (and word sized int) is stored in return_value
|
|
|
|
def get_internal_byte context
|
2016-12-15 18:31:39 +01:00
|
|
|
compiler = compiler_for(:Word , :get_internal_byte)
|
|
|
|
source = "get_internal_byte"
|
2016-12-21 21:35:36 +01:00
|
|
|
me , index = self_and_int_arg(compiler,source)
|
2015-11-19 09:08:41 +01:00
|
|
|
# reduce me to me[index]
|
2016-12-28 19:37:54 +01:00
|
|
|
compiler.add_byte_to_reg( source , me , index , me)
|
2015-11-19 09:08:41 +01:00
|
|
|
# and put it back into the return value
|
2016-12-28 19:37:54 +01:00
|
|
|
compiler.add_reg_to_slot( source , me , :message , :return_value)
|
2015-11-19 09:08:41 +01:00
|
|
|
return compiler.method
|
|
|
|
end
|
|
|
|
|
|
|
|
# self[index] = val basically. Index is the first arg ( >0),
|
|
|
|
# value the second
|
|
|
|
# no return
|
|
|
|
def set_internal_byte context
|
2016-12-15 18:31:39 +01:00
|
|
|
compiler = compiler_for(:Word, :set_internal_byte , {:value => :Integer} )
|
2016-12-27 19:34:11 +01:00
|
|
|
args = compiler.method.arguments
|
|
|
|
len = args.instance_length
|
|
|
|
raise "Compiler arg number mismatch, method=#{args} " if len != 3
|
2016-12-15 18:31:39 +01:00
|
|
|
source = "set_internal_byte"
|
2016-12-21 21:35:36 +01:00
|
|
|
me , index = self_and_int_arg(compiler,source)
|
2016-12-27 19:34:11 +01:00
|
|
|
value = load_int_arg_at(compiler , source , 2 )
|
2015-11-19 09:08:41 +01:00
|
|
|
# do the set
|
2016-12-28 19:37:54 +01:00
|
|
|
compiler.add_reg_to_byte( source , value , me , index)
|
2015-11-19 09:08:41 +01:00
|
|
|
return compiler.method
|
|
|
|
end
|
|
|
|
|
2015-07-01 20:45:41 +02:00
|
|
|
end
|
|
|
|
extend ClassMethods
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|