Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

simplified u.r - albeit not sure whether it can be called a simplification. It's shorter though. #45

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 9 additions & 14 deletions src/cforth/dot.fth
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,13 @@ create digits

: space bl emit ;
: spaces 0 max 0 ?do space loop ;
: u.r ( n #digits -- )
0 >r swap ( #digits n r: 0 )
begin ( #digits n r: 0 ascii .. )
swap 1 - swap ( #digits' n r: 0 ascii .. )
dup 4 rshift swap f and ( #digits rem n' 0 ascii .. )
\ 0 base @ um/mod swap ( #digits n' rem 0 ascii .. )
digits + c@ >r ( #digits n r: ascii ... )
?dup 0= until ( #digits r: ascii )
( #digits )
0 max spaces
begin r> ?dup while emit repeat
;

: u.r ( n #digits -- ) \ radix max #16 because of digits table
1- swap
0 base @ um/mod
?dup if rot recurse else swap 0 max spaces then
digits + c@ emit ;

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like your code but please reformat according to my conventions, including running stack diagrams on the right. I'm a stickler about stylistic consistency within a code base.

: . 0 u.r space ;
: bounds ( start len -- end start ) over + swap ;
: ldump ( adr len -- )
Expand All @@ -29,8 +24,8 @@ create digits
8 cells i over bounds ?do i @ 9 u.r cell +loop cr
+loop
;
: <= 2dup < -rot = or ;
: >= 2dup > -rot = or ;
: <= ( n1 n2 -- flag ) > 0= ;
: >= ( n1 n2 -- flag ) < 0= ;
: between ( n low high -- flag ) rot tuck >= -rot <= and ;
: printable? ( n -- flag ) bl 7e between ;
: dump ( adr len -- )
Expand Down
6 changes: 6 additions & 0 deletions src/cforth/util.fth
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@
then
; immediate

: s(
[char] ) parse ;

: .(
s( type ;

: ok ;
: trigger 0 0 2>r 2r> drop drop ; immediate
\ : [cr] cr ; immediate
Expand Down