Kaynağa Gözat

fmt: add word ".x" and fix .X to 4 chars output

Simpler code, more predictable output.
pull/102/head
Virgil Dupras 4 yıl önce
ebeveyn
işleme
7df7416e9e
2 değiştirilmiş dosya ile 19 ekleme ve 22 silme
  1. +3
    -2
      forth/dictionary.txt
  2. +16
    -20
      forth/fmt.fs

+ 3
- 2
forth/dictionary.txt Dosyayı Görüntüle

@@ -193,10 +193,11 @@ core.
number parsing. By default, (parse). number parsing. By default, (parse).
(print) a -- Print string at addr a. (print) a -- Print string at addr a.
. n -- Print n in its decimal form . n -- Print n in its decimal form
.X n -- Print n in its hexadecimal form. In hex, numbers
.x n -- Print n's LSB in hex form. Always 2 characters.
.X n -- Print n in hex form. Always 4 characters. Numbers
are never considered negative. "-1 .X" --> ffff
." xxx" -- *I* Compiles string literal xxx followed by a call ." xxx" -- *I* Compiles string literal xxx followed by a call
to (print) to (print)
are never considered negative. "-1 .X -> ffff"
C< -- c Read one char from buffered input. C< -- c Read one char from buffered input.
EMIT c -- Spit char c to output stream EMIT c -- Spit char c to output stream
IN> -- a Address of variable containing current pos in input IN> -- a Address of variable containing current pos in input


+ 16
- 20
forth/fmt.fs Dosyayı Görüntüle

@@ -1,7 +1,6 @@
( requires core, parse ) ( requires core, parse )


( TODO FORGET this word )
: PUSHDGTS
: _
999 SWAP ( stop indicator ) 999 SWAP ( stop indicator )
DUP 0 = IF '0' EXIT THEN ( 0 is a special case ) DUP 0 = IF '0' EXIT THEN ( 0 is a special case )
BEGIN BEGIN
@@ -16,7 +15,7 @@
( that "0 1 -" thing is because we don't parse negative ( that "0 1 -" thing is because we don't parse negative
number correctly yet. ) number correctly yet. )
DUP 0 < IF '-' EMIT 0 1 - * THEN DUP 0 < IF '-' EMIT 0 1 - * THEN
PUSHDGTS
_
BEGIN BEGIN
DUP '9' > IF DROP EXIT THEN ( stop indicator, we're done ) DUP '9' > IF DROP EXIT THEN ( stop indicator, we're done )
EMIT EMIT
@@ -25,24 +24,21 @@


: ? @ . ; : ? @ . ;


: PUSHDGTS
999 SWAP ( stop indicator )
DUP 0 = IF '0' EXIT THEN ( 0 is a special case )
BEGIN
DUP 0 = IF DROP EXIT THEN
16 /MOD ( r q )
SWAP ( r q )
: _
DUP 9 > IF 10 - 'a' + DUP 9 > IF 10 - 'a' +
ELSE '0' + THEN ( q d )
SWAP ( d q )
AGAIN
ELSE '0' + THEN
; ;


: .X ( n -- )
( For hex display, there are no negatives )
PUSHDGTS
BEGIN
DUP 'f' > IF DROP EXIT THEN ( stop indicator, we're done )
EMIT
AGAIN
( For hex display, there are no negatives )

: .x
256 MOD ( ensure < 0x100 )
16 /MOD ( l h )
_ EMIT ( l )
_ EMIT
;

: .X
256 /MOD ( l h )
.x .x
; ;

Yükleniyor…
İptal
Kaydet