: ZERO_CHAR 48 ;
: NEWLINE_CHAR 10 ;
-export putn
-
-: putn ( num -- num )
+: putn_trimmed ( num -- num )
dup dup \ ( num num num )
10 rot rot \ ( num 10 num num ) // Mutltidigit stop point
10 < \ ( num 10 num is<10 )
dup 9 > \ ( num 10 digitn ... digit2 digit2>9 )
endloop \ ( num 10 )
drop \ ( num )
- NEWLINE_CHAR \ ( num 10 )
- sp \ ( num 10 ptr )
- 1 \ ( num 10 ptr 1 )
- swap \ (num 10 1 ptr )
- 1 \ ( num 10 1 ptr 1 )
- write \ ( num 10 result )
- drop \ ( num 10 )
- drop \ ( num )
+;
+
+: put_newline
+ NEWLINE_CHAR \ ( 10 )
+ sp \ ( 10 ptr )
+ 1 \ ( 10 ptr 1 )
+ swap \ ( 10 1 ptr )
+ 1 \ ( 10 1 ptr 1 )
+ write \ ( 10 result )
+ drop \ ( 10 )
+ drop \ ( )
+;
+
+
+export putn
+
+: putn ( num -- num )
+ putn_trimmed
+ put_newline
;
export putstack
- \ ( stack_height_in_bytes )
8 \ ( stack_height_in_bytes cell_length )
/ \ ( stack_height_in_cells )
- dup dup \ ( stack_height_in_cells stack_height_in_cells stack_height_in_cells )
- "\n________________________________ stack top\n" puts drop
+ dup \ ( stack_height_in_cells stack_height_in_cells )
+ "stack: (" puts drop
loop \ ( stack_height_in_cells index )
- over over \ ( stack_height_in_cells index stack_height_in_cells index )
- - \ (stack_height_in_cells index offset )
+ dup \ ( stack_height_in_cells index index )
+ 2 - \ ( stack_height_in_cells index offset )
sp 24 + \ ( stack_height_in_cells index offset sp ) \\\\ NOTE: We've added 3 cells to the stack, so need to rewind them here
swap 8 \ ( stack_height_in_cells index sp offset cell_length )
* \ ( stack_height_in_cells index sp true_offset )
+ \ ( stack_height_in_cells index ptr_to_print )
@ \ ( stack_height_in_cells index val_to_print )
- " " puts drop putn drop \ ( stack_height_in_cells index )
+ " " puts drop putn_trimmed drop \ ( stack_height_in_cells index )
1 - \ ( stack_height_in_cells index-1 )
dup \ ( stack_height_in_cells index-1 )
endloop \ ( stack_height_in_cells 0 )
drop drop \ ()
- "-------------------------------- stack bottom\n\n" puts drop
+ " )\n" puts drop
;