From 4a275323625ab6e99c4b898a7fce271aae443f9f Mon Sep 17 00:00:00 2001 From: Bryan English Date: Fri, 21 Aug 2026 23:14:56 -0400 Subject: [PATCH] tighter putstack output --- stdlib/out.sorel | 43 ++++++++++++++++++++++++++----------------- 1 file changed, 26 insertions(+), 17 deletions(-) diff --git a/stdlib/out.sorel b/stdlib/out.sorel index efe769e..02a26ce 100644 --- a/stdlib/out.sorel +++ b/stdlib/out.sorel @@ -22,9 +22,7 @@ export puts : 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 ) @@ -47,14 +45,25 @@ export putn 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 @@ -65,21 +74,21 @@ 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 ; -- 2.43.0