@@ 155,7 155,8 @@ 0 v,1 \ EI_OSABI = ELFOSABI_NONE
\ EI_ABIVERSION 1 byte, undefined, merge with EI_PAD
pad8 \ EI_PAD - pad to 16 bytes
- \ all header struct members are properly arranged so there is no padding
+ \ all header struct members are properly arranged so there is
+ \ no padding
1 v,2 \ e_type = ET_REL
3e v,2 \ e_machine = EM_X86_64
@@ 485,7 486,8 @@ gsymtab-idx
rpad8 rpad8 \ st_value, st_size
gsymtab-idx @ gsymtab++ ;
- \ Q: when we search symbol, do we need to find the last symbol?
+ \ Q: when we search symbol, do we need to find
+ \ the last symbol?
\ A: we are only searching symbols in bootstrap.asm, and
\ every symbol exists only once. so first hit is the
\ result. this assumes that all symbols in the code to
@@ 603,7 605,8 @@ fh \ file handle
\ write all records of the given record type to fh
( rt -- )
-: rtwrite db begin over rtnext 0=? for dup rsplit mwrite next drop drop ;
+: rtwrite db begin over rtnext 0=? for dup rsplit mwrite next
+ drop drop ;
( current file offset )
elfh-size var
@@ 635,7 638,8 @@ foffset
: .relo! glink-all
off sht-.rela.text-idx sh.offset!
- relo-ext-idx @ relo-idx @ + sht-relo-size * dup sht-.rela.text-idx sh.size! off+ ;
+ relo-ext-idx @ relo-idx @ + sht-relo-size * dup
+ sht-.rela.text-idx sh.size! off+ ;
\ keep order in sync with write-all
: arrange () sht! .data! .bss! .text! .shstrtab!
@@ 716,8 720,8 @@ the 32-bit value is zero extended into R
\ because of external words we have to rewrite call, as we
\ have to add a global symbol+relo in this case.
( target-dictaddr -- )
-: call, e8 ,1 here over cfl @ over - ( near call is relative addressing )
- 4 - ( the difference is taken from address of next instruction )
+: call, e8 ,1 here over cfl @ over - \ near call is relative addressing
+ 4 - \ the difference is taken from address of next instruction
( target-dictaddr src-addr call-offset )
,4 ( dictaddr src-addr ) extern, ;
@@ 734,8 738,9 @@ the 32-bit value is zero extended into R
: #-old # ffind # call,-old # ;
- \ must be recompiled because it used comp, which uses call,
\ switch to compile mode
+ \ must be recompiled because it used comp,
+ \ which uses call.
: # () rdrop begin
word comp dup 1+ drop
if ". ." : no such word " \n ;; then drop
@@ 794,8 799,8 @@ m: ." ^ " # ffind ". # cpush-old call,
\ overwrite ':' so it gives us a symtab entry
\ note: the 3rd # is read by ffind
- \ we use the old fcreate because here - the preparation area -
- \ as we dont want to write elf data now
+ \ we use the old fcreate because here - the preparation
+ \ area - as we dont want to write elf data now
fcreate-old : #-old fcreate # ffind # call,-old # ;
fcreate-old m: #-old mcreate # ffind # call,-old # ;
@@ 14,67 14,69 @@ deci
800 var rows 1200 var cols
hex
+ \ compile an arithmetic shift left by n digits
( c: n:int8 -- ; r: i -- i<<n )
- ( compile an arithmetic shift left by n digits )
-m: n<< rex.w, e0c1 ,2 ( n ) ,1 ; ( sal rax, n )
+m: n<< rex.w, e0c1 ,2 ( n ) ,1 ; \ sal rax, n
+ \ compile an arithmetic shift right by n digits
( c: n:int8 -- ; r: i -- i>>n )
- ( compile an arithmetic shift right by n digits )
-m: n>> rex.w, f8c1 ,2 ( n ) ,1 ; ( sar eax, n )
+m: n>> rex.w, f8c1 ,2 ( n ) ,1 ; \ sar eax, n
-1d ( deci 29 ) const scalef
+ 1d ( deci 29 ) const
+scalef
-m: scale scalef ^ n<< ; ( sal rax, scalef )
+m: scale scalef ^ n<< ; \ sal rax, scalef
: scale scale ;
-m: unscale scalef ^ n>> ; ( sar rax, scalef )
+m: unscale scalef ^ n>> ; \ sar rax, scalef
: unscale unscale ;
( a b -- a b a+b )
m: +` ^ dup
- rex.w, 084603 ,3 ; ( add rax, [rsi+8] )
+ rex.w, 084603 ,3 ; \ add rax, [rsi+8]
- ( a b -- a-b a b )
+ ( a b -- a b a-b )
m: -` ^ over
- rex.w, 062b ,2 ; ( sub rax, [rsi] )
+ rex.w, 062b ,2 ; \ sub rax, [rsi]
- ( svar creates a scaled variable )
+ \ svar creates a scaled variable
: svar scale var ;
-( the area to visualize, given by the x dimension and y center point )
-0 2 - svar x1 ( -2 )
+\ the area to visualize, given by the x dimension and y center point
+0 2 - svar x1 \ -2
1 svar x2
-0 svar yc ( center on y axis )
+0 svar yc \ center on y axis
-( these values will be computed )
+\ these values will be calculated
0 var y2
0 var y1
0 var delta
- ( compute delta, a step in x- or y-direction, represented by one pixel )
-: setdelta ( ) x2 @ x1 @ - cols @ / delta ! ;
+ \ compute delta, a step in x- or y-direction,
+ \ represented by one pixel
+: setdelta () x2 @ x1 @ - cols @ / delta ! ;
- ( adjust x2 and x1, according to delta )
- ( take center of x-axis, and go x/2 to the left and right using delta )
-: xc ( ) x2 @ x1 @ + 2 / ;
-: adjustx ( ) xc cols @ 2 / delta @ *
+ \ adjust x2 and x1, according to delta
+ \ take center of x-axis, and go x/2 to the left and
+ \ right using delta
+: xc () x2 @ x1 @ + 2 / ;
+: adjustx () xc cols @ 2 / delta @ *
+` x2 ! - x1 ! ;
- ( compute y1 and y2 by using yc )
-: adjusty ( ) yc @ rows @ 2 / delta @ *
+ \ compute y1 and y2 by using yc
+: adjusty () yc @ rows @ 2 / delta @ *
+` y2 ! - y1 ! ;
- ( stdout for easier testing )
+ \ stdout for easier testing
1 var
fh
- ( saddr - )
-: swrite fh @ swap "write ;
+
+: swrite ( *str - ) fh @ swap "write ;
- ( number -- )
-: nwrite a itoa swrite ;
+: nwrite ( n -- ) a itoa swrite ;
-( do not remove the trailing space after the first '"' - '"' is a word
- and needs this trailing space! )
+\ do not remove the trailing space after the first '"' - '"' is a word
+\ and needs this trailing space!
"
" string nl
@@ 82,12 84,13 @@ fh
" " string space
-( colors rows cols -- )
+ ( colors rows cols -- )
: pgmheader " P5" swrite writenl
nwrite space swrite nwrite writenl
nwrite writenl ;
- \ current position in buffer, place to write the next char to
+ \ current position in buffer, place to write
+ \ the next char to
0 var
buf-pos
@@ 95,7 98,7 @@ buf-pos
wbuf
: buf-reset () wbuf buf-pos ! ;
-: buf-len ( -- n ) buf-pos @ wbuf - ;
+: buf-len ( -- n ) buf-pos @ wbuf - ;
\ write buffer to file fh
: buf-flush () fh @ wbuf buf-len write throw buf-reset ;
@@ 106,43 109,39 @@ wbuf
buf-reset
-m: unscale1 scalef 1 - ^ n>> ; ( sar eax, scalef-1 )
+m: unscale1 scalef 1 - ^ n>> ; \ sar eax, scalef-1
( a b -- 2*a*b )
m: 2xy ^ * ^ unscale1 ;
-( y0 x0 y x x^2 y^2 -- y0 x0 y[n+1] x[n+1] )
-: z(n+1)
- -
- ( y0 x0 y x x^2-y^2 )
- rpush 2xy
- ( y0 x0 2xy r: x^2-y^2 )
- uber +
- ( y0 x0 2yx+y0 r: x^2-y^2 )
- over rpop +
- ( y0 x0 2yx+y0 x^2-y^2+x0 ) ;
+ ( y0 x0 y x x^2 y^2 -- y0 x0 y[n+1] x[n+1] )
+: z(n+1) -
+ ( y0 x0 y x x^2-y^2 )
+ rpush 2xy
+ ( y0 x0 2xy r: x^2-y^2 )
+ uber +
+ ( y0 x0 2yx+y0 r: x^2-y^2 )
+ over rpop +
+ ( y0 x0 2yx+y0 x^2-y^2+x0 ) ;
- ( append i to buffer )
- ( i -- )
-: wplot buf, ;
+ \ append i to buffer
+: wplot ( i -- ) buf, ;
: wplot1 10 / dup * wplot ;
( x -- x^2 )
m: sq rex.w, e8f7 ,2 ( imul rax ) ^ unscale ;
- ( -- )
-m: 3drop ^ drop ^ drop ^ drop ;
+m: 3drop () ^ drop ^ drop ^ drop ;
m: r-- rex.w, 240cff ,3 ; \ dec qword ptr [rsp]
- ( branch if signed, non consuming )
+ \ branch if signed, non consuming
( -- branch-addr )
-m: +if 78 ,1 ( js )
- here 0 ,1 ; ( push branch address and leave space )
+m: +if 78 ,1 \ js
+ here 0 ,1 ; \ push branch address and leave space
-( x0 y0 -- )
-: plot
+: plot ( x0 y0 -- )
over over \ start with z = x0 + iy0
100 rpush \ i, counter
begin
@@ 163,25 162,23 @@ m: +if 78 ,1 ( js )
3drop drop
rpop wplot ;
- ( next x- or y value )
- ( x -- x )
-: advance delta @ + ;
+ \ next x- or y value
+: advance ( x -- x ) delta @ + ;
-( y -- )
-: draw-row
+: draw-row ( y -- )
x2 @ x1 @
begin
=? for
- ( top: x x2 y )
+ ( y x2 x )
uber over plot
advance
next 3drop ;
-: write-image ( )
+: write-image ()
buf-reset y2 @ y1 @
begin
=? for
- ( top: y y2 )
+ ( y2 y )
dup draw-row
buf-flush
advance
@@ 195,11 192,7 @@ m: +if 78 ,1 ( js )
: close-file () fh @ fclose ;
-: mb () initmain setup create-file write-header write-image close-file
- ." done " ( a emit ) bye ;
-end-app
+: mb () initmain setup create-file write-header write-image
+ close-file ." done " ( a emit ) bye ;
-start-with mb
-
-" mandelbrot.o" write-obj
-
+end-app start-with mb " mandelbrot.o" write-obj