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