Then you can use normal gdb commands!
The `tui layout asm` is highly recommended.
-Note that if you'l linking `putstack.c`, that will use libc, which drastically inflates the binary and hijack's init.
-This can make things quite a pain in `gdb`, so try to build without it (i.e. uncomment the LD line and comment out the CC line in `test.sh`, and remove all references to `putstack` in code).
Over,
Rot,
StackPointer,
+ StackBottom,
If,
Else,
EndIf,
"over" => IR::Over,
"rot" => IR::Rot,
"sp" => IR::StackPointer,
+ "stackbottom" => IR::StackBottom,
"if" => IR::If,
"else" => IR::Else,
"endif" => IR::EndIf,
self.lines.push(line.to_string());
}
- asm_macro!(copy_top_stack_value_to, "ld {}, 0(s2)", &str);
- asm_macro!(copy_offset_stack_value_to, "ld {}, {}*8(s2)", &str, isize);
+ asm_macro!(copy_top_stack_value_to, "ld {}, 0(s2)", &str);
+ asm_macro!(copy_offset_stack_value_to, "ld {}, {}*8(s2)", &str, isize);
asm_macro!(copy_to_top_of_stack, "sd {}, 0(s2)", &str);
asm_macro!(move_stack_ptr_by_cells, "addi s2, s2, {}*8", isize);
self.push_from("t0");
self.push_from("t1");
},
+ IR::Over => {
+ // TODO this is super inefficient. There's no need to pop anything. Just read
+ // from the second stack position and push it.
+ self.label("# over");
+ self.pop_some_to("t0 t1");
+ self.push_from("t0");
+ self.push_from("t1");
+ self.push_from("t0");
+ },
IR::Rot => {
self.label("# rot");
self.pop_some_to("t0 t1 t2");
self.line("addi t0, s2, 0");
self.push_from("t0");
},
+ IR::StackBottom => {
+ self.label("# stackbottom");
+ self.line("la t0, data_stack_end");
+ self.push_from("t0");
+ }
IR::Drop => {
self.label("# drop");
self.move_stack_ptr_by_cells(1);
drop \ ( num )
;
+export putstack
+
+: putstack ( -- )
+ sp stackbottom \ ( sp stack_end )
+ swap \ ( stack_end sp )
+ - \ ( 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
+ loop \ ( stack_height_in_cells index )
+ over over \ ( stack_height_in_cells index stack_height_in_cells index )
+ - \ (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 )
+ 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
+;
+
+++ /dev/null
-#include <stdio.h>
-
-extern unsigned long data_stack_end;
-register unsigned long * stack_pointer asm("s2");
-
-void putstack() {
- unsigned long * stack_index = &data_stack_end;
- printf("stack: ");
- while (stack_index != stack_pointer) {
- printf("%ld ", *stack_index);
- stack_index -= 1;
- }
- printf("%ld\n", *stack_pointer);
-}
-
-
../target/debug/sorelc test1.sorel
$AS -g -o test1.o test1.asm
-$CC -O1 -no-pie -o test1.out test1.o putstack.c -nostartfiles
-# $LD -o test1.out test1.o
+$LD -o test1.out test1.o
./test1.out
import "std:mem"
import "std:out"
-extern putstack
-
16 alloc \ ( ptr )
dup \ ( ptr ptr )
-"To be copied!" \ ( ptr ptr strptr )
+"To be copied!\n" \ ( ptr ptr strptr )
dup \ ( ptr ptr strptr strptr )
strlen 1 + \ ( ptr ptr strptr len )
rot \ ( ptr strptr len ptr )
puts \ ( ptr )
free \ ( )
-
+42 43 44 "soup" putstack