forked from CharleyShattuck/myforth-arduino
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnumbers.fs
59 lines (42 loc) · 1.78 KB
/
numbers.fs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
\ numbers.fs
0 [if]
Copyright (C) 2015 by Charles Shattuck.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
For LGPL information: http://www.gnu.org/copyleft/lesser.txt
[then]
variable base
: decimal $0a #, base ! ;
: hex $10 #, base ! ;
variable holder
: hold ( c) holder @ 1 #- dup holder ! c! ;
: sign ( n) -if char - #, hold then drop ;
: <# ( ud - ud) pad #, holder ! ;
: #> ( ud - adr len) 2drop holder @ pad #, over - ;
: # ( ud1 - ud2) base @ ud/mod rot 9 #, over - -if
drop 7 #, + dup then drop 48 #, + hold ;
: #s ( ud - 0 0) begin # 2dup or while drop repeat drop ;
: (h.) ( u - adr len) base @ push hex 0 #, <# # # # # #> pop base ! ;
: h. ( u) (h.) type space ;
: ud. ( ud) <# #s #> type space ;
: u. ( u) 0 #, ud. ;
: d. ( d) dup push dabs <# #s pop sign #> type space ;
: 0< ( n - flag) -if drop -1 #, ; then drop 0 #, ;
: . ( n) dup 0< d. ;
: .f ( f) 10000 #, *. dup push abs 0 #,
<# # # # # char . #, hold # pop sign #> type space ;
-: sp@ ( - a) dup X T movw, ;
: depth ( - n) s0 #, sp@ - 2/ 2 #- ;
: ? @ . ;
: .s apush depth [ s0 4 - ] #, swap if
for dup ? 2 #- next dup
then 2drop apop ;