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