rubyx/lib/soml/parfait/integer.soml

40 lines
618 B
Plaintext
Raw Normal View History

2015-11-08 13:30:42 +01:00
class Integer < Value
2015-11-10 18:09:17 +01:00
int as_char()
if_plus( self - 9)
2015-11-08 16:11:03 +01:00
return 32
else
2015-11-11 19:45:40 +01:00
return 48 + self
2015-11-08 13:30:42 +01:00
end
end
2015-11-08 16:11:03 +01:00
Word as_string(Word str)
2015-11-08 22:58:54 +01:00
if_minus( self - 10 )
2015-11-10 18:09:17 +01:00
int num = as_char()
str = str.push_char( num )
2015-11-08 22:58:54 +01:00
else
int rest = self.div10()
2015-11-08 22:58:54 +01:00
str = rest.as_string( str )
2015-11-10 18:09:17 +01:00
rest = rest * 10
rest = self - rest
str = rest.as_string(str)
2015-11-08 13:30:42 +01:00
end
return str
end
2015-11-08 16:11:03 +01:00
Word to_s()
2015-11-08 13:30:42 +01:00
Word start = " "
2015-11-08 16:11:03 +01:00
return as_string( start )
2015-11-08 13:30:42 +01:00
end
2015-11-10 18:09:17 +01:00
int puti()
Word str = self.to_s()
str.putstring()
return self
end
2015-11-11 19:36:40 +01:00
int mod4()
return self & 3
2015-11-11 19:36:40 +01:00
end
2015-11-08 13:30:42 +01:00
end