added tostr
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
import stdlib.sl
|
import stdlib.sl
|
||||||
import io.sl
|
import io.sl
|
||||||
|
import mem.sl
|
||||||
|
|
||||||
word digitsN>num # ( d_{n-1} ... d0 n -- value ), digits bottom=MSD, top=LSD, length on top (MSD-most significant digit, LSD-least significant digit)
|
word digitsN>num # ( d_{n-1} ... d0 n -- value ), digits bottom=MSD, top=LSD, length on top (MSD-most significant digit, LSD-least significant digit)
|
||||||
0 swap # place accumulator below length
|
0 swap # place accumulator below length
|
||||||
@@ -34,6 +35,50 @@ word toint
|
|||||||
rdrop
|
rdrop
|
||||||
end
|
end
|
||||||
|
|
||||||
word main
|
word count_digits
|
||||||
"1234" toint 1 + puti cr
|
0
|
||||||
|
swap
|
||||||
|
while dup 0 > do
|
||||||
|
10 / swap 1 + swap
|
||||||
|
end
|
||||||
|
drop
|
||||||
|
end
|
||||||
|
|
||||||
|
word tostr
|
||||||
|
dup
|
||||||
|
count_digits
|
||||||
|
2dup >r alloc
|
||||||
|
nip swap rot swap
|
||||||
|
for
|
||||||
|
dup 10 % swap 10 /
|
||||||
|
end
|
||||||
|
drop
|
||||||
|
|
||||||
|
r>
|
||||||
|
1 swap dup
|
||||||
|
for
|
||||||
|
dup
|
||||||
|
2 + pick
|
||||||
|
2 pick
|
||||||
|
2 + pick
|
||||||
|
3 pick rot +
|
||||||
|
swap 48 + c!
|
||||||
|
drop
|
||||||
|
swap
|
||||||
|
1 +
|
||||||
|
swap
|
||||||
|
end
|
||||||
|
|
||||||
|
swap 0 +
|
||||||
|
pick 1 +
|
||||||
|
over for
|
||||||
|
rot drop
|
||||||
|
end drop
|
||||||
|
swap 1 + swap puts
|
||||||
|
end
|
||||||
|
|
||||||
|
word main
|
||||||
|
"1234" toint 1 + dup puti cr
|
||||||
|
tostr
|
||||||
|
puts
|
||||||
end
|
end
|
||||||
Reference in New Issue
Block a user