stab at inter to string
wip
This commit is contained in:
parent
c38775e933
commit
6f69995284
@ -141,7 +141,7 @@ module Soml
|
||||
end
|
||||
|
||||
def self.load_parfait
|
||||
["word","class","layout","message" , "object"].each do |o|
|
||||
["word","class","layout","message" ,"integer", "object"].each do |o|
|
||||
str = File.open(File.expand_path("parfait/#{o}.soml", File.dirname(__FILE__))).read
|
||||
syntax = Parser::Salama.new.parse_with_debug(str)
|
||||
parts = Parser::Transform.new.apply(syntax)
|
||||
|
@ -1,35 +1,26 @@
|
||||
class Integer < Value
|
||||
Word digit( int rest )
|
||||
if_zero( rest == 5 )
|
||||
return "5"
|
||||
end
|
||||
if_zero( rest == 1 )
|
||||
return "1"
|
||||
end
|
||||
if_zero( rest == 2 )
|
||||
return "2"
|
||||
end
|
||||
if_zero( rest == 3 )
|
||||
return "3"
|
||||
end
|
||||
if_zero( rest == 4 )
|
||||
return "4"
|
||||
int digit()
|
||||
if_plus( self - 10)
|
||||
return 32
|
||||
else
|
||||
Word numbers = "0123456789"
|
||||
return numbers.at(self)
|
||||
end
|
||||
end
|
||||
Word add_string(Word str)
|
||||
int div
|
||||
div = self / 10
|
||||
int rest
|
||||
rest = self - div
|
||||
if_notzero( rest )
|
||||
rest = self.digit( rest )
|
||||
else
|
||||
str = div.add_string(str)
|
||||
|
||||
Word as_string(Word str)
|
||||
if_plus( self - 10 )
|
||||
int num = digit()
|
||||
str = str.add_digit( num )
|
||||
return str
|
||||
end
|
||||
int rest = self / 10
|
||||
str = rest.as_string( str )
|
||||
return str
|
||||
end
|
||||
Word to_string()
|
||||
|
||||
Word to_s()
|
||||
Word start = " "
|
||||
return add_string( start )
|
||||
return as_string( start )
|
||||
end
|
||||
end
|
||||
|
@ -1,2 +1,10 @@
|
||||
class Word < Object
|
||||
int at(int index)
|
||||
get_internal(index)
|
||||
end
|
||||
Word add_digit( int i)
|
||||
int l = self.char_length
|
||||
set_internal( l , i)
|
||||
return self
|
||||
end
|
||||
end
|
||||
|
@ -5,7 +5,8 @@ class TestPutiRT < MiniTest::Test
|
||||
|
||||
def test_puti
|
||||
@string_input = <<HERE
|
||||
5.puts()
|
||||
Word five = 5.to_s()
|
||||
five.putstring()
|
||||
HERE
|
||||
@stdout = "5"
|
||||
check
|
||||
|
@ -9,7 +9,7 @@ class TestObject < MiniTest::Test
|
||||
def test_object_create
|
||||
# another test sometime adds a field variable. Maybe should reboot ?
|
||||
res = 1
|
||||
[:boo1 , :boo2 , :runner].each { |v| res += 1 if @object.get_layout.variable_index(v) }
|
||||
[:boo1 , :boo2 , :bro , :runner].each { |v| res += 1 if @object.get_layout.variable_index(v) }
|
||||
assert_equal res , @object.get_layout.instance_length , @object.get_layout.inspect
|
||||
end
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user