remove div and add div10
general division is for another day, the 10 version is manageable also same code produces mod10 wip
This commit is contained in:
parent
a5afca10f6
commit
5c862111b9
@ -195,8 +195,6 @@ module Interpreter
|
|||||||
result = left + right
|
result = left + right
|
||||||
when "-"
|
when "-"
|
||||||
result = left - right
|
result = left - right
|
||||||
when "/"
|
|
||||||
result = left / right
|
|
||||||
when ">>"
|
when ">>"
|
||||||
result = left >> right
|
result = left >> right
|
||||||
when "<<"
|
when "<<"
|
||||||
|
@ -152,7 +152,7 @@ module Register
|
|||||||
@space.get_class_by_name(:Word).add_instance_method Builtin::Word.send(:putstring , nil)
|
@space.get_class_by_name(:Word).add_instance_method Builtin::Word.send(:putstring , nil)
|
||||||
|
|
||||||
obj = @space.get_class_by_name(:Integer)
|
obj = @space.get_class_by_name(:Integer)
|
||||||
[:mod , :putint].each do |f|
|
[:mod , :putint , :div10 , :mod10].each do |f|
|
||||||
obj.add_instance_method Builtin::Integer.send(f , nil)
|
obj.add_instance_method Builtin::Integer.send(f , nil)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -5,6 +5,22 @@ module Register
|
|||||||
module ClassMethods
|
module ClassMethods
|
||||||
include AST::Sexp
|
include AST::Sexp
|
||||||
|
|
||||||
|
def div10 context
|
||||||
|
compiler = Soml::Compiler.new.create_method(:Integer,:div10 ).init_method
|
||||||
|
do_div10(compiler)
|
||||||
|
# return div
|
||||||
|
return compiler.method
|
||||||
|
end
|
||||||
|
def mod10 context
|
||||||
|
compiler = Soml::Compiler.new.create_method(:Integer,:mod10 ).init_method
|
||||||
|
do_div10(compiler)
|
||||||
|
#return mod
|
||||||
|
return compiler.method
|
||||||
|
end
|
||||||
|
|
||||||
|
def do_div10 compiler
|
||||||
|
|
||||||
|
end
|
||||||
# The conversion to base10 is quite a bit more complicated than i thought.
|
# The conversion to base10 is quite a bit more complicated than i thought.
|
||||||
# The bulk of it is in div10
|
# The bulk of it is in div10
|
||||||
# We set up variables, do the devision and write the result to the string
|
# We set up variables, do the devision and write the result to the string
|
||||||
|
@ -13,7 +13,7 @@ class Integer < Value
|
|||||||
int num = as_char()
|
int num = as_char()
|
||||||
str = str.push_char( num )
|
str = str.push_char( num )
|
||||||
else
|
else
|
||||||
int rest = self / 10
|
int rest = self.div10()
|
||||||
str = rest.as_string( str )
|
str = rest.as_string( str )
|
||||||
rest = rest * 10
|
rest = rest * 10
|
||||||
rest = self - rest
|
rest = self - rest
|
||||||
@ -33,14 +33,7 @@ class Integer < Value
|
|||||||
return self
|
return self
|
||||||
end
|
end
|
||||||
|
|
||||||
int div( Integer by)
|
int mod4()
|
||||||
int ret = self / by
|
return self & 3
|
||||||
return ret
|
|
||||||
end
|
|
||||||
|
|
||||||
int mod(Integer by)
|
|
||||||
int base = self / by
|
|
||||||
base = base * by
|
|
||||||
return self - base
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -2,7 +2,7 @@ class Word < Object
|
|||||||
|
|
||||||
int char_at(int index)
|
int char_at(int index)
|
||||||
int word_index = index - 1
|
int word_index = index - 1
|
||||||
word_index = word_index / 4
|
word_index = word_index >> 2
|
||||||
word_index = word_index + 3
|
word_index = word_index + 3
|
||||||
int rest = index - 1
|
int rest = index - 1
|
||||||
rest = rest.mod(4)
|
rest = rest.mod(4)
|
||||||
@ -23,7 +23,7 @@ class Word < Object
|
|||||||
self.set_length(index)
|
self.set_length(index)
|
||||||
|
|
||||||
int word_index = index - 1
|
int word_index = index - 1
|
||||||
word_index = word_index / 4
|
word_index = word_index >> 2
|
||||||
word_index = word_index + 3
|
word_index = word_index + 3
|
||||||
|
|
||||||
int rest = index - 1
|
int rest = index - 1
|
||||||
|
@ -29,6 +29,15 @@ HERE
|
|||||||
@interpreter.tick
|
@interpreter.tick
|
||||||
end while( ! @interpreter.instruction.nil?)
|
end while( ! @interpreter.instruction.nil?)
|
||||||
assert_equal @stdout , @interpreter.stdout
|
assert_equal @stdout , @interpreter.stdout
|
||||||
|
# write_file if true
|
||||||
|
end
|
||||||
|
|
||||||
|
def write_file
|
||||||
|
file_name = caller(3).first.split("in ").last.chop.reverse.chop.reverse
|
||||||
|
file_name = File.dirname(__FILE__) + "/" + file_name + ".o"
|
||||||
|
Register.machine.translate_arm
|
||||||
|
writer = Elf::ObjectWriter.new
|
||||||
|
writer.save file_name
|
||||||
end
|
end
|
||||||
|
|
||||||
def check_return val
|
def check_return val
|
||||||
|
Loading…
Reference in New Issue
Block a user