system.fox: fix ralign and @1
6 files changed, 44 insertions(+), 6 deletions(-)

M bootstrap.asm
M bootstrap2.fox
M bootstrap2.sh
M mandelbrot.fox
M swapwm.fox
M system.fox
M bootstrap.asm +7 -0
@@ 968,6 968,11 @@ fcreate words
 	mpop
 	ret
 
+section .data
+	procstack dp 0
+
+aconst procstack
+
 section .rodata
 	; init interprete last, must be in front of last interprete word
 initfdp:

          
@@ 983,4 988,6 @@ fcreate initmain
 	initbuf 0
 	; init number base
 	mov ptr [base], 16
+	lea rdx, [rsp+8]
+	mov ptr [procstack], rdx
 	ret

          
M bootstrap2.fox +32 -1
@@ 26,16 26,19 @@ stacksize
 : initstack	\ lea rsi, [rbx+(stacksize+cell)]
 			# b38d48 ,3 stacksize 1 cell + ,4 # ;
 
+
 			\ room for tmp vars and data stack
 			1000 const
 tls-size
 
 			balign tls-size buffer
 main-tls
+
+
 			\ keep addr push code in sync with vpush, bpush, cpush
 : initmain	# fc ,1				\ cld, for lodsd and "=?
 			bb ,1 				\ mov ebx, main-tls
-			main-tls here over ,4 relo,b # 
+			main-tls here over ,4 relo,b #
 			initstack ;
 
 \ use new stack and tls from now on so the new .s will work

          
@@ 185,6 188,34 @@ m: ."		^ " # ffind ". # lit call, ;
 			over over - neg drop -if \n drop drop ;; then
 			dup @ . space # 1 cell # lit -
 		loop ;
+			\ init with procstack from bootstrap.asm, so we can 
+			\ debug in interprete mode
+			procstack @ var
+procstack	\ process stack
+
+			\ must be called in the _start routine, as
+			\ it needs to access the initial rsp set by the os
+m: initprocstack () \ mov qword ptr [procstack], rsp
+			25248948 ,4 procstack here over ,4 relo,v ;
+
+: #args		procstack @ @ ;
+
+: env		procstack @ #args # 1 cell # lit * + ;
+
+                \ returns the #bytes to the next \0 from addr, excluding the \0 byte
+                ( addr -- len )
+: len\0 dup
+                begin
+                        dup @1 dup + drop
+                for 1+ next - neg ;
+
+                \ print \0 terminated string
+                ( addr -- )
+: .\0   1 swap dup len\0 write drop ;
+
+: env1		env @ . \n ;
+
+
 
 		\ print the stack whenever a word is called.
 		( *str )

          
M bootstrap2.sh +1 -1
@@ 1,2 1,2 @@ 
 make fox
-cat system.fox fileio.fox elf64.fox bootstrap2.fox - | ./fox
+cat system.fox fileio.fox elf64.fox bootstrap2.fox - | ./fox $@

          
M mandelbrot.fox +1 -1
@@ 192,7 192,7 @@ m: +if	78 ,1				\ js
 
 : close-file	() fh @ fclose ;
 
-: mb			() initmain setup create-file write-header write-image
+: mb			() initmain initprocstack env1 setup create-file write-header write-image
 					close-file ." done " ( a emit ) bye ;
 
 end-app   start-with mb   " mandelbrot.o" write-obj

          
M swapwm.fox +1 -1
@@ 787,7 787,7 @@ cleanmask
 
 : ev-loop	() begin dodbg next-ev dispatch loop ;
 
-: run	 	() initmain init ev-loop ;
+: run	 	() initprocstack initmain init ev-loop ;
 
 end-app   start-with run   " swapwm.o" write-obj
 

          
M system.fox +2 -2
@@ 80,7 80,7 @@ m: @4	008b ,2 ;					( mov eax, [rax] )
 : @8 #	: @ @ ;			: @4 @4 ;
 m: @2 	00b70f48 ,4 ;	: @2 @2 ;	( movzx rax, word ptr [rax] )
 m: "len	#		( fetch string length )
-m: @1	00b60f67 ,4 ;				( movzx rax, byte ptr [rax] )
+m: @1	00b60f48 ,4 ;				( movzx rax, byte ptr [rax] )
 : "len "len ;		: @1 @1 ;
 		( n addr --  )
 m: !8	#

          
@@ 349,7 349,7 @@ salign
 
 			\ align right
 			( width  -- )
-: ralign	dwidth - neg salign !4 salign ". ;
+: ralign	dwidth - neg salign !"len salign ". ;
 
 		\ dump output for a number
 		( n -- )