refactor also building word
obviously created by copy/paste, more refactoring possible
This commit is contained in:
parent
5ea6bfed27
commit
dc56274940
@ -12,8 +12,9 @@ module Register
|
||||
return me , index
|
||||
end
|
||||
|
||||
def compiler_for( method_name , args)
|
||||
Typed::Compiler.new.create_method(:Object , method_name , args ).init_method
|
||||
def compiler_for( type , method_name , extra_args = {})
|
||||
args = {:index => :Integer}.merge( extra_args )
|
||||
Typed::Compiler.new.create_method(type , method_name , args ).init_method
|
||||
end
|
||||
|
||||
# Load the value
|
||||
|
@ -10,7 +10,7 @@ module Register
|
||||
# return is stored in return_value
|
||||
# (this method returns a new method off course, like all builtin)
|
||||
def get_internal_word context
|
||||
compiler = compiler_for(:get_internal_word , {:index => :Integer})
|
||||
compiler = compiler_for(:Object , :get_internal_word )
|
||||
source = "get_internal_word"
|
||||
me , index = self_and_arg(compiler,source)
|
||||
# reduce me to me[index]
|
||||
@ -23,7 +23,7 @@ module Register
|
||||
# self[index] = val basically. Index is the first arg , value the second
|
||||
# no return
|
||||
def set_internal_word context
|
||||
compiler = compiler_for(:set_internal_word , {:index => :Integer, :value => :Object} )
|
||||
compiler = compiler_for(:Object , :set_internal_word , {:value => :Object} )
|
||||
source = "set_internal_word"
|
||||
me , index = self_and_arg(compiler,source)
|
||||
value = do_load(compiler,source)
|
||||
|
@ -1,8 +1,10 @@
|
||||
require_relative "compile_helper"
|
||||
|
||||
module Register
|
||||
module Builtin
|
||||
module Word
|
||||
module ClassMethods
|
||||
include AST::Sexp
|
||||
include CompileHelper
|
||||
|
||||
def putstring context
|
||||
compiler = Typed::Compiler.new.create_method(:Word , :putstring ).init_method
|
||||
@ -13,17 +15,13 @@ module Register
|
||||
Kernel.emit_syscall( compiler , :putstring )
|
||||
compiler.method
|
||||
end
|
||||
|
||||
|
||||
# self[index] basically. Index is the first arg > 0
|
||||
# return (and word sized int) is stored in return_value
|
||||
def get_internal_byte context
|
||||
compiler = Typed::Compiler.new.create_method(:Word , :get_internal_byte , {:index => :Integer }).init_method
|
||||
source = "get_internal_word"
|
||||
#Load self by "calling" on_name
|
||||
me = compiler.process( Typed::Tree::NameExpression.new( :self) )
|
||||
# Load the argument
|
||||
index = compiler.use_reg :Integer
|
||||
compiler.add_code Register.get_slot(source , :message , Parfait::Message.get_indexed(1), index )
|
||||
compiler = compiler_for(:Word , :get_internal_byte)
|
||||
source = "get_internal_byte"
|
||||
me , index = self_and_arg(compiler,source)
|
||||
# reduce me to me[index]
|
||||
compiler.add_code GetByte.new( source , me , index , me)
|
||||
# and put it back into the return value
|
||||
@ -35,17 +33,10 @@ module Register
|
||||
# value the second
|
||||
# no return
|
||||
def set_internal_byte context
|
||||
compiler = Typed::Compiler.new.create_method(:Word , :set_internal_byte ,
|
||||
{:index => :Integer, :value => :Integer } ).init_method
|
||||
source = "set_internal_word"
|
||||
#Load self by "calling" on_name
|
||||
me = compiler.process( Typed::Tree::NameExpression.new( :self) )
|
||||
# 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 )
|
||||
compiler = compiler_for(:Word, :set_internal_byte , {:value => :Integer} )
|
||||
source = "set_internal_byte"
|
||||
me , index = self_and_arg(compiler,source)
|
||||
value = do_load(compiler,source)
|
||||
# do the set
|
||||
compiler.add_code SetByte.new( source , value , me , index)
|
||||
return compiler.method
|
||||
|
@ -46,7 +46,6 @@ module Register
|
||||
def translate_methods(methods , translator )
|
||||
methods.each do |method|
|
||||
instruction = method.instructions
|
||||
puts method.name
|
||||
while instruction.next
|
||||
nekst = instruction.next
|
||||
t = translator.translate(nekst) # returning nil means no replace
|
||||
|
Loading…
Reference in New Issue
Block a user