2015-07-01 20:45:41 +02:00
|
|
|
module Register
|
|
|
|
module Builtin
|
|
|
|
module Word
|
|
|
|
module ClassMethods
|
2015-11-19 09:08:41 +01:00
|
|
|
include AST::Sexp
|
|
|
|
|
2015-07-01 20:45:41 +02:00
|
|
|
def putstring context
|
2016-12-08 14:25:20 +01:00
|
|
|
compiler = Typed::Compiler.new.create_method(:Word , :putstring ).init_method
|
2015-10-28 20:37:42 +01:00
|
|
|
compiler.add_code Register.get_slot( "putstring" , :message , :receiver , :new_message )
|
2015-11-16 17:03:29 +01:00
|
|
|
index = Parfait::Word.get_length_index
|
|
|
|
reg = RegisterValue.new(:r2 , :Integer)
|
|
|
|
compiler.add_code Register.get_slot( "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-03-07 10:55:28 +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-08 14:25:20 +01:00
|
|
|
compiler = Typed::Compiler.new.create_method(:Word , :get_internal_byte , {:index => :Integer }).init_method
|
2015-11-19 09:08:41 +01:00
|
|
|
source = "get_internal_word"
|
|
|
|
#Load self by "calling" on_name
|
2016-03-07 10:55:28 +01:00
|
|
|
me = compiler.process( Soml::NameExpression.new( :self) )
|
2015-11-19 09:08:41 +01:00
|
|
|
# Load the argument
|
|
|
|
index = compiler.use_reg :Integer
|
|
|
|
compiler.add_code Register.get_slot(source , :message , Parfait::Message.get_indexed(1), index )
|
|
|
|
# reduce me to me[index]
|
|
|
|
compiler.add_code GetByte.new( source , me , index , me)
|
|
|
|
# and put it back into the return value
|
|
|
|
compiler.add_code Register.set_slot( source , me , :message , :return_value)
|
|
|
|
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-08 14:25:20 +01:00
|
|
|
compiler = Typed::Compiler.new.create_method(:Word , :set_internal_byte ,
|
2015-11-19 09:08:41 +01:00
|
|
|
{:index => :Integer, :value => :Integer } ).init_method
|
|
|
|
source = "set_internal_word"
|
|
|
|
#Load self by "calling" on_name
|
2016-03-07 10:55:28 +01:00
|
|
|
me = compiler.process( Soml::NameExpression.new( :self) )
|
2015-11-19 09:08:41 +01:00
|
|
|
# Load the index
|
|
|
|
index = compiler.use_reg :Integer
|
|
|
|
compiler.add_code Register.get_slot(source , :message , Parfait::Message.get_indexed(1), index )
|
|
|
|
# Load the value
|
|
|
|
value = compiler.use_reg :Integer
|
|
|
|
compiler.add_code Register.get_slot(source , :message , Parfait::Message.get_indexed(2), value )
|
|
|
|
# do the set
|
|
|
|
compiler.add_code SetByte.new( source , value , me , index)
|
|
|
|
return compiler.method
|
|
|
|
end
|
|
|
|
|
2015-07-01 20:45:41 +02:00
|
|
|
end
|
|
|
|
extend ClassMethods
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|