Quellcode durchsuchen

forth: Forth-ify "ABORT""

pull/95/head
Virgil Dupras vor 4 Jahren
Ursprung
Commit
4627e1c977
4 geänderte Dateien mit 39 neuen und 50 gelöschten Zeilen
  1. +2
    -1
      forth/core.fs
  2. +2
    -1
      forth/dictionary.txt
  3. +2
    -0
      forth/fmt.fs
  4. +33
    -48
      forth/forth.asm

+ 2
- 1
forth/core.fs Datei anzeigen

@@ -1,6 +1,7 @@
: H HERE @ ;
: -^ SWAP - ;
: COMPILE ' LITN ['] , , ; IMMEDIATE
: [COMPILE] ' , ; IMMEDIATE
: BEGIN H ; IMMEDIATE
: AGAIN COMPILE (bbr) H -^ C, ; IMMEDIATE
: UNTIL COMPILE SKIP? COMPILE (bbr) H -^ C, ; IMMEDIATE
@@ -36,7 +37,6 @@
H 1 - ( push a. -1 for allot offset )
; IMMEDIATE

: ? @ . ;
: VARIABLE CREATE 2 ALLOT ;
: CONSTANT CREATE H ! DOES> @ ;
: = CMP NOT ;
@@ -44,6 +44,7 @@
: > CMP 1 = ;
: / /MOD SWAP DROP ;
: MOD /MOD DROP ;
: ABORT" [COMPILE] ." COMPILE ABORT ; IMMEDIATE

( In addition to pushing H this compiles 2 >R so that loop variables are sent
to PS at runtime )


+ 2
- 1
forth/dictionary.txt Datei anzeigen

@@ -44,7 +44,8 @@ directly, but as part of another word.
ALLOT n -- Move HERE by n bytes
C, b -- Write byte b in HERE and advance it.
CREATE x -- Create cell named x. Doesn't allocate a PF.
[COMPILE] x -- Compile word x and write it to HERE
[COMPILE] x -- Compile word x and write it to HERE. IMMEDIATE
words are *not* executed.
COMPILE x -- Meta compiles. Kind of blows the mind. See below.
CONSTANT x n -- Creates cell x that when called pushes its value
DOES> -- See description at top of file


+ 2
- 0
forth/fmt.fs Datei anzeigen

@@ -23,6 +23,8 @@
AGAIN
;

: ? @ . ;

: PUSHDGTS
999 SWAP ( stop indicator )
DUP 0 = IF '0' EXIT THEN ( 0 is a special case )


+ 33
- 48
forth/forth.asm Datei anzeigen

@@ -712,21 +712,9 @@ abortUnderflow:
.dw PRINT
.dw ABORT

.db "ABORT", '"'
.fill 1
.dw ABORT
.db 1 ; IMMEDIATE
ABORTI:
.dw compiledWord
.dw PRINTI
.dw NUMBER
.dw ABORT
.dw WR
.dw EXIT

.db "BYE"
.fill 4
.dw ABORTI
.dw ABORT
.db 0
BYE:
.dw nativeWord
@@ -871,42 +859,9 @@ EXECUTE:
jp (hl) ; go!


.db "[COMPIL"
.dw EXECUTE
.db 1 ; IMMEDIATE
COMPILE:
.dw compiledWord
.dw WORD
.dw FIND_
.dw CSKIP
.dw .maybeNum
.dw DUP
.dw ISIMMED
.dw CSKIP
.dw .word
; is immediate. just execute.
.dw EXECUTE
.dw EXIT

.word:
.dw compiledWord
.dw WR
.dw R2P ; exit COMPILE
.dw DROP
.dw EXIT

.maybeNum:
.dw compiledWord
.dw PARSEI
.dw LITN
.dw R2P ; exit COMPILE
.dw DROP
.dw EXIT


.db ";"
.fill 6
.dw COMPILE
.dw EXECUTE
.db 1 ; IMMEDIATE
ENDDEF:
.dw compiledWord
@@ -931,11 +886,41 @@ DEFINE:
.dw compiledWord
.dw WR
; BBR branch mark
.dw COMPILE
.dw .compile
.dw BBR
.db 4
; no need for EXIT, ENDDEF takes care of taking us out

.compile:
.dw compiledWord
.dw WORD
.dw FIND_
.dw CSKIP
.dw .maybeNum
.dw DUP
.dw ISIMMED
.dw CSKIP
.dw .word
; is immediate. just execute.
.dw EXECUTE
.dw EXIT

.word:
.dw compiledWord
.dw WR
.dw R2P ; exit .compile
.dw DROP
.dw EXIT

.maybeNum:
.dw compiledWord
.dw PARSEI
.dw LITN
.dw R2P ; exit .compile
.dw DROP
.dw EXIT



.db "DOES>"
.fill 2


Laden…
Abbrechen
Speichern