]> rethought.computer Git - sorel-lang.git/commitdiff
tighter putstack output
authorBryan English <bryan@rethought.computer>
Sat, 22 Aug 2026 03:14:56 +0000 (23:14 -0400)
committerBryan English <bryan@rethought.computer>
Sat, 22 Aug 2026 03:18:48 +0000 (23:18 -0400)
stdlib/out.sorel

index efe769e5e85e9e3fbbc50b3a3059dcbeffd0929f..02a26ce87cfd5c294ea3d88f71bbf166aa912e91 100644 (file)
@@ -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
 ;