2020-03-08 04:13:15 +11:00
|
|
|
; A dictionary entry has this structure:
|
2020-03-10 10:50:51 +11:00
|
|
|
; - 7b name (zero-padded)
|
|
|
|
; - 1b flags (bit 0: IMMEDIATE)
|
2020-03-08 04:13:15 +11:00
|
|
|
; - 2b prev pointer
|
|
|
|
; - 2b code pointer
|
2020-03-08 09:09:45 +11:00
|
|
|
; - Parameter field (PF)
|
2020-03-08 04:13:15 +11:00
|
|
|
;
|
|
|
|
; The code pointer point to "word routines". These routines expect to be called
|
2020-03-08 09:09:45 +11:00
|
|
|
; with IY pointing to the PF. They themselves are expected to end by jumping
|
2020-03-08 04:13:15 +11:00
|
|
|
; to the address at the top of the Return Stack. They will usually do so with
|
|
|
|
; "jp exit".
|
|
|
|
|
2020-03-08 09:09:45 +11:00
|
|
|
; Execute a word containing native code at its PF address (PFA)
|
2020-03-08 04:13:15 +11:00
|
|
|
nativeWord:
|
|
|
|
jp (iy)
|
|
|
|
|
2020-03-10 06:12:44 +11:00
|
|
|
; Execute a list of atoms, which usually ends with EXIT.
|
|
|
|
; IY points to that list.
|
2020-03-08 04:13:15 +11:00
|
|
|
compiledWord:
|
|
|
|
push iy \ pop hl
|
|
|
|
inc hl
|
|
|
|
inc hl
|
|
|
|
; HL points to next Interpreter pointer.
|
|
|
|
call pushRS
|
|
|
|
ld l, (iy)
|
|
|
|
ld h, (iy+1)
|
|
|
|
push hl \ pop iy
|
|
|
|
; IY points to code link
|
|
|
|
jp executeCodeLink
|
|
|
|
|
2020-03-08 09:09:45 +11:00
|
|
|
; Pushes the PFA directly
|
|
|
|
cellWord:
|
|
|
|
push iy
|
|
|
|
jp exit
|
|
|
|
|
|
|
|
; Pushes the address in the first word of the PF
|
|
|
|
sysvarWord:
|
|
|
|
ld l, (iy)
|
|
|
|
ld h, (iy+1)
|
|
|
|
push hl
|
|
|
|
jp exit
|
|
|
|
|
2020-03-08 14:18:14 +11:00
|
|
|
; The word was spawned from a definition word that has a DOES>. PFA+2 (right
|
|
|
|
; after the actual cell) is a link to the slot right after that DOES>.
|
|
|
|
; Therefore, what we need to do push the cell addr like a regular cell, then
|
|
|
|
; follow the link from the PFA, and then continue as a regular compiledWord.
|
|
|
|
doesWord:
|
|
|
|
push iy ; like a regular cell
|
|
|
|
ld l, (iy+2)
|
|
|
|
ld h, (iy+3)
|
|
|
|
push hl \ pop iy
|
|
|
|
jr compiledWord
|
|
|
|
|
2020-03-12 07:46:25 +11:00
|
|
|
; This word is followed by *relative* offset (to the cell's addr) to where to
|
|
|
|
; branch to. For example, The branching cell of "IF THEN" would contain 4. Add
|
|
|
|
; this value to RS.
|
2020-03-11 12:37:06 +11:00
|
|
|
branchWord:
|
2020-03-12 07:46:25 +11:00
|
|
|
push de
|
2020-03-11 12:37:06 +11:00
|
|
|
ld l, (ix)
|
|
|
|
ld h, (ix+1)
|
2020-03-12 07:46:25 +11:00
|
|
|
ld e, (hl)
|
|
|
|
inc hl
|
|
|
|
ld d, (hl)
|
|
|
|
dec hl
|
|
|
|
or a ; clear carry
|
|
|
|
add hl, de
|
2020-03-11 12:37:06 +11:00
|
|
|
ld (ix), l
|
|
|
|
ld (ix+1), h
|
2020-03-12 07:46:25 +11:00
|
|
|
pop de
|
2020-03-11 12:37:06 +11:00
|
|
|
jp exit
|
|
|
|
|
|
|
|
BRANCH:
|
|
|
|
.dw branchWord
|
|
|
|
|
|
|
|
; Conditional branch, only branch if TOS is zero
|
|
|
|
cbranchWord:
|
2020-03-10 05:19:51 +11:00
|
|
|
pop hl
|
|
|
|
ld a, h
|
|
|
|
or l
|
2020-03-11 12:37:06 +11:00
|
|
|
jr z, branchWord
|
|
|
|
; skip next 2 bytes
|
|
|
|
call skipRS
|
2020-03-10 05:19:51 +11:00
|
|
|
jp exit
|
|
|
|
|
2020-03-11 12:37:06 +11:00
|
|
|
CBRANCH:
|
|
|
|
.dw cbranchWord
|
|
|
|
|
2020-03-08 11:25:55 +11:00
|
|
|
; This is not a word, but a number literal. This works a bit differently than
|
|
|
|
; others: PF means nothing and the actual number is placed next to the
|
|
|
|
; numberWord reference in the compiled word list. What we need to do to fetch
|
|
|
|
; that number is to play with the Return stack: We pop it, read the number, push
|
|
|
|
; it to the Parameter stack and then push an increase Interpreter Pointer back
|
|
|
|
; to RS.
|
|
|
|
numberWord:
|
2020-03-11 12:37:06 +11:00
|
|
|
ld l, (ix)
|
|
|
|
ld h, (ix+1)
|
2020-03-08 11:25:55 +11:00
|
|
|
ld e, (hl)
|
|
|
|
inc hl
|
|
|
|
ld d, (hl)
|
|
|
|
inc hl
|
2020-03-11 12:37:06 +11:00
|
|
|
ld (ix), l
|
|
|
|
ld (ix+1), h
|
2020-03-08 11:25:55 +11:00
|
|
|
push de
|
|
|
|
jp exit
|
|
|
|
NUMBER:
|
|
|
|
.dw numberWord
|
|
|
|
|
2020-03-09 23:49:51 +11:00
|
|
|
; Similarly to numberWord, this is not a real word, but a string literal.
|
|
|
|
; Instead of being followed by a 2 bytes number, it's followed by a
|
|
|
|
; null-terminated string. This is not expected to be called in a regular
|
|
|
|
; context. Only words expecting those literals will look for them. This is why
|
|
|
|
; the litWord triggers abort.
|
|
|
|
litWord:
|
|
|
|
call popRS
|
|
|
|
call intoHL
|
|
|
|
call printstr ; let's print the word before abort.
|
|
|
|
ld hl, .msg
|
|
|
|
call printstr
|
|
|
|
jp abort
|
|
|
|
.msg:
|
|
|
|
.db "undefined word", 0
|
|
|
|
LIT:
|
|
|
|
.dw litWord
|
2020-03-08 11:25:55 +11:00
|
|
|
|
2020-03-08 04:13:15 +11:00
|
|
|
; ( R:I -- )
|
2020-03-09 23:49:51 +11:00
|
|
|
.db ";"
|
|
|
|
.fill 7
|
2020-03-08 04:13:15 +11:00
|
|
|
.dw 0
|
2020-03-10 06:12:44 +11:00
|
|
|
EXIT:
|
2020-03-08 04:13:15 +11:00
|
|
|
.dw nativeWord
|
|
|
|
; When we call the EXIT word, we have to do a "double exit" because our current
|
|
|
|
; Interpreter pointer is pointing to the word *next* to our EXIT reference when,
|
|
|
|
; in fact, we want to continue processing the one above it.
|
|
|
|
call popRS
|
|
|
|
exit:
|
2020-03-08 12:20:11 +11:00
|
|
|
; Before we continue: is SP within bounds?
|
|
|
|
call chkPS
|
|
|
|
; we're good
|
2020-03-08 04:13:15 +11:00
|
|
|
call popRS
|
|
|
|
; We have a pointer to a word
|
|
|
|
push hl \ pop iy
|
2020-03-09 23:49:51 +11:00
|
|
|
jp compiledWord
|
2020-03-08 04:13:15 +11:00
|
|
|
|
2020-03-08 09:09:45 +11:00
|
|
|
; ( R:I -- )
|
2020-03-10 10:50:51 +11:00
|
|
|
.db "QUIT"
|
|
|
|
.fill 4
|
2020-03-08 09:09:45 +11:00
|
|
|
.dw EXIT
|
2020-03-10 06:12:44 +11:00
|
|
|
QUIT:
|
2020-03-08 09:09:45 +11:00
|
|
|
.dw nativeWord
|
|
|
|
quit:
|
2020-03-09 23:49:51 +11:00
|
|
|
jp forthRdLine
|
2020-03-08 12:20:11 +11:00
|
|
|
|
2020-03-10 10:50:51 +11:00
|
|
|
.db "ABORT"
|
|
|
|
.fill 3
|
2020-03-08 12:20:11 +11:00
|
|
|
.dw QUIT
|
2020-03-10 06:12:44 +11:00
|
|
|
ABORT:
|
2020-03-08 12:20:11 +11:00
|
|
|
.dw nativeWord
|
|
|
|
abort:
|
2020-03-09 23:49:51 +11:00
|
|
|
; Reinitialize PS (RS is reinitialized in forthInterpret
|
2020-03-08 12:20:11 +11:00
|
|
|
ld sp, (INITIAL_SP)
|
2020-03-09 23:49:51 +11:00
|
|
|
jp forthRdLine
|
2020-03-11 12:37:06 +11:00
|
|
|
ABORTREF:
|
|
|
|
.dw ABORT
|
2020-03-08 09:09:45 +11:00
|
|
|
|
2020-03-08 05:15:19 +11:00
|
|
|
.db "BYE"
|
|
|
|
.fill 5
|
2020-03-08 12:20:11 +11:00
|
|
|
.dw ABORT
|
2020-03-10 06:12:44 +11:00
|
|
|
BYE:
|
2020-03-08 05:15:19 +11:00
|
|
|
.dw nativeWord
|
2020-03-09 23:49:51 +11:00
|
|
|
; Goodbye Forth! Before we go, let's restore the stack
|
|
|
|
ld sp, (INITIAL_SP)
|
|
|
|
; unwind stack underflow buffer
|
|
|
|
pop af \ pop af \ pop af
|
|
|
|
; success
|
|
|
|
xor a
|
|
|
|
ret
|
2020-03-08 05:15:19 +11:00
|
|
|
|
2020-03-08 04:13:15 +11:00
|
|
|
; ( c -- )
|
2020-03-10 10:50:51 +11:00
|
|
|
.db "EMIT"
|
|
|
|
.fill 4
|
2020-03-08 05:15:19 +11:00
|
|
|
.dw BYE
|
2020-03-10 06:12:44 +11:00
|
|
|
EMIT:
|
2020-03-08 04:13:15 +11:00
|
|
|
.dw nativeWord
|
|
|
|
pop hl
|
|
|
|
ld a, l
|
|
|
|
call stdioPutC
|
|
|
|
jp exit
|
|
|
|
|
2020-03-11 04:00:57 +11:00
|
|
|
; ( c port -- )
|
|
|
|
.db "PC!"
|
|
|
|
.fill 5
|
|
|
|
.dw EMIT
|
|
|
|
PSTORE:
|
|
|
|
.dw nativeWord
|
|
|
|
pop bc
|
|
|
|
pop hl
|
|
|
|
out (c), l
|
|
|
|
jp exit
|
|
|
|
|
|
|
|
; ( port -- c )
|
|
|
|
.db "PC@"
|
|
|
|
.fill 5
|
|
|
|
.dw PSTORE
|
|
|
|
PFETCH:
|
|
|
|
.dw nativeWord
|
|
|
|
pop bc
|
|
|
|
ld h, 0
|
|
|
|
in l, (c)
|
|
|
|
push hl
|
|
|
|
jp exit
|
|
|
|
|
2020-03-08 04:13:15 +11:00
|
|
|
; ( addr -- )
|
2020-03-10 10:50:51 +11:00
|
|
|
.db "EXECUTE"
|
|
|
|
.db 0
|
2020-03-11 04:00:57 +11:00
|
|
|
.dw PFETCH
|
2020-03-10 06:12:44 +11:00
|
|
|
EXECUTE:
|
2020-03-08 04:13:15 +11:00
|
|
|
.dw nativeWord
|
2020-03-10 06:12:44 +11:00
|
|
|
pop iy ; is a wordref
|
2020-03-08 04:13:15 +11:00
|
|
|
executeCodeLink:
|
|
|
|
ld l, (iy)
|
|
|
|
ld h, (iy+1)
|
|
|
|
; HL points to code pointer
|
|
|
|
inc iy
|
|
|
|
inc iy
|
|
|
|
; IY points to PFA
|
|
|
|
jp (hl) ; go!
|
|
|
|
|
2020-03-08 10:53:20 +11:00
|
|
|
.db ":"
|
|
|
|
.fill 7
|
|
|
|
.dw EXECUTE
|
2020-03-10 06:12:44 +11:00
|
|
|
DEFINE:
|
2020-03-08 10:53:20 +11:00
|
|
|
.dw nativeWord
|
|
|
|
call entryhead
|
|
|
|
ld de, compiledWord
|
|
|
|
ld (hl), e
|
|
|
|
inc hl
|
|
|
|
ld (hl), d
|
|
|
|
inc hl
|
2020-03-09 23:49:51 +11:00
|
|
|
; At this point, we've processed the name literal following the ':'.
|
|
|
|
; What's next? We have, in IP, a pointer to words that *have already
|
|
|
|
; been compiled by INTERPRET*. All those bytes will be copied as-is.
|
|
|
|
; All we need to do is to know how many bytes to copy. To do so, we
|
|
|
|
; skip compwords until EXIT is reached.
|
2020-03-10 13:13:11 +11:00
|
|
|
ex de, hl ; DE is our dest
|
2020-03-12 08:53:27 +11:00
|
|
|
ld (HERE), de ; update HERE
|
2020-03-10 10:50:51 +11:00
|
|
|
ld l, (ix)
|
|
|
|
ld h, (ix+1)
|
2020-03-08 10:53:20 +11:00
|
|
|
.loop:
|
2020-03-12 08:53:27 +11:00
|
|
|
call HLPointsEXIT
|
|
|
|
jr z, .loopend
|
|
|
|
call compSkip
|
2020-03-10 13:13:11 +11:00
|
|
|
jr .loop
|
2020-03-12 08:53:27 +11:00
|
|
|
.loopend:
|
|
|
|
; skip EXIT
|
|
|
|
inc hl \ inc hl
|
|
|
|
; We have out end offset. Let's get our offset
|
|
|
|
ld e, (ix)
|
|
|
|
ld d, (ix+1)
|
|
|
|
or a ; clear carry
|
|
|
|
sbc hl, de
|
|
|
|
; HL is our copy count.
|
|
|
|
ld b, h
|
|
|
|
ld c, l
|
|
|
|
ld l, (ix)
|
|
|
|
ld h, (ix+1)
|
|
|
|
ld de, (HERE) ; recall dest
|
|
|
|
; copy!
|
|
|
|
ldir
|
2020-03-09 23:49:51 +11:00
|
|
|
ld (ix), l
|
|
|
|
ld (ix+1), h
|
2020-03-12 08:53:27 +11:00
|
|
|
ld (HERE), de
|
2020-03-08 10:53:20 +11:00
|
|
|
jp exit
|
|
|
|
|
2020-03-10 13:13:11 +11:00
|
|
|
|
2020-03-10 10:50:51 +11:00
|
|
|
.db "DOES>"
|
|
|
|
.fill 3
|
2020-03-08 14:18:14 +11:00
|
|
|
.dw DEFINE
|
2020-03-10 06:12:44 +11:00
|
|
|
DOES:
|
2020-03-08 14:18:14 +11:00
|
|
|
.dw nativeWord
|
|
|
|
; We run this when we're in an entry creation context. Many things we
|
|
|
|
; need to do.
|
|
|
|
; 1. Change the code link to doesWord
|
|
|
|
; 2. Leave 2 bytes for regular cell variable.
|
|
|
|
; 3. Get the Interpreter pointer from the stack and write this down to
|
|
|
|
; entry PFA+2.
|
|
|
|
; 3. exit. Because we've already popped RS, a regular exit will abort
|
|
|
|
; colon definition, so we're good.
|
|
|
|
ld iy, (CURRENT)
|
|
|
|
ld hl, doesWord
|
|
|
|
call wrCompHL
|
|
|
|
inc iy \ inc iy ; cell variable space
|
|
|
|
call popRS
|
|
|
|
call wrCompHL
|
|
|
|
ld (HERE), iy
|
|
|
|
jp exit
|
|
|
|
|
2020-03-10 13:13:11 +11:00
|
|
|
|
|
|
|
.db "IMMEDIA"
|
|
|
|
.db 0
|
|
|
|
.dw DOES
|
|
|
|
IMMEDIATE:
|
|
|
|
.dw nativeWord
|
|
|
|
ld hl, (CURRENT)
|
|
|
|
dec hl
|
|
|
|
dec hl
|
|
|
|
dec hl
|
|
|
|
inc (hl)
|
|
|
|
jp exit
|
|
|
|
|
|
|
|
; ( n -- )
|
|
|
|
.db "LITERAL"
|
|
|
|
.db 1 ; IMMEDIATE
|
|
|
|
.dw IMMEDIATE
|
|
|
|
LITERAL:
|
|
|
|
.dw nativeWord
|
2020-03-11 12:37:06 +11:00
|
|
|
ld hl, (CMPDST)
|
2020-03-10 13:13:11 +11:00
|
|
|
ld de, NUMBER
|
2020-03-11 12:37:06 +11:00
|
|
|
call DEinHL
|
2020-03-10 13:13:11 +11:00
|
|
|
pop de ; number from stack
|
2020-03-11 12:37:06 +11:00
|
|
|
call DEinHL
|
|
|
|
ld (CMPDST), hl
|
2020-03-10 13:13:11 +11:00
|
|
|
jp exit
|
|
|
|
|
2020-03-08 04:13:15 +11:00
|
|
|
; ( -- c )
|
2020-03-08 09:09:45 +11:00
|
|
|
.db "KEY"
|
|
|
|
.fill 5
|
2020-03-10 13:13:11 +11:00
|
|
|
.dw LITERAL
|
2020-03-10 06:12:44 +11:00
|
|
|
KEY:
|
2020-03-08 04:13:15 +11:00
|
|
|
.dw nativeWord
|
|
|
|
call stdioGetC
|
|
|
|
ld h, 0
|
|
|
|
ld l, a
|
|
|
|
push hl
|
|
|
|
jp exit
|
|
|
|
|
2020-03-10 10:50:51 +11:00
|
|
|
.db "CREATE"
|
|
|
|
.fill 2
|
2020-03-11 12:37:06 +11:00
|
|
|
.dw KEY
|
2020-03-10 06:12:44 +11:00
|
|
|
CREATE:
|
2020-03-08 09:09:45 +11:00
|
|
|
.dw nativeWord
|
2020-03-08 10:53:20 +11:00
|
|
|
call entryhead
|
|
|
|
jp nz, quit
|
2020-03-08 09:09:45 +11:00
|
|
|
ld de, cellWord
|
|
|
|
ld (hl), e
|
|
|
|
inc hl
|
|
|
|
ld (hl), d
|
|
|
|
inc hl
|
|
|
|
ld (HERE), hl
|
|
|
|
jp exit
|
|
|
|
|
|
|
|
.db "HERE"
|
|
|
|
.fill 4
|
|
|
|
.dw CREATE
|
2020-03-10 06:12:44 +11:00
|
|
|
HERE_: ; Caution: conflicts with actual variable name
|
2020-03-08 09:09:45 +11:00
|
|
|
.dw sysvarWord
|
|
|
|
.dw HERE
|
|
|
|
|
2020-03-10 10:50:51 +11:00
|
|
|
.db "CURRENT"
|
|
|
|
.db 0
|
2020-03-08 14:18:14 +11:00
|
|
|
.dw HERE_
|
2020-03-10 06:12:44 +11:00
|
|
|
CURRENT_:
|
2020-03-08 14:18:14 +11:00
|
|
|
.dw sysvarWord
|
|
|
|
.dw CURRENT
|
|
|
|
|
2020-03-08 04:50:54 +11:00
|
|
|
; ( n -- )
|
|
|
|
.db "."
|
|
|
|
.fill 7
|
2020-03-08 14:18:14 +11:00
|
|
|
.dw CURRENT_
|
2020-03-10 06:12:44 +11:00
|
|
|
DOT:
|
2020-03-08 04:50:54 +11:00
|
|
|
.dw nativeWord
|
|
|
|
pop de
|
2020-03-08 12:20:11 +11:00
|
|
|
; We check PS explicitly because it doesn't look nice to spew gibberish
|
|
|
|
; before aborting the stack underflow.
|
|
|
|
call chkPS
|
2020-03-08 04:50:54 +11:00
|
|
|
call pad
|
|
|
|
call fmtDecimalS
|
|
|
|
call printstr
|
|
|
|
jp exit
|
2020-03-08 09:09:45 +11:00
|
|
|
|
|
|
|
; ( n a -- )
|
|
|
|
.db "!"
|
|
|
|
.fill 7
|
|
|
|
.dw DOT
|
2020-03-10 06:12:44 +11:00
|
|
|
STORE:
|
2020-03-08 09:09:45 +11:00
|
|
|
.dw nativeWord
|
|
|
|
pop iy
|
|
|
|
pop hl
|
|
|
|
ld (iy), l
|
|
|
|
ld (iy+1), h
|
|
|
|
jp exit
|
|
|
|
|
|
|
|
; ( a -- n )
|
|
|
|
.db "@"
|
|
|
|
.fill 7
|
|
|
|
.dw STORE
|
2020-03-10 06:12:44 +11:00
|
|
|
FETCH:
|
2020-03-08 09:09:45 +11:00
|
|
|
.dw nativeWord
|
|
|
|
pop hl
|
|
|
|
call intoHL
|
|
|
|
push hl
|
|
|
|
jp exit
|
2020-03-08 11:42:07 +11:00
|
|
|
|
2020-03-11 07:02:40 +11:00
|
|
|
; ( -- a )
|
|
|
|
.db "LIT@"
|
|
|
|
.fill 4
|
|
|
|
.dw FETCH
|
|
|
|
LITFETCH:
|
|
|
|
.dw nativeWord
|
|
|
|
call readLITTOS
|
|
|
|
push hl
|
|
|
|
jp exit
|
|
|
|
|
2020-03-08 13:12:30 +11:00
|
|
|
; ( a b -- b a )
|
|
|
|
.db "SWAP"
|
|
|
|
.fill 4
|
2020-03-11 07:02:40 +11:00
|
|
|
.dw LITFETCH
|
2020-03-10 06:12:44 +11:00
|
|
|
SWAP:
|
2020-03-08 13:12:30 +11:00
|
|
|
.dw nativeWord
|
|
|
|
pop hl
|
|
|
|
ex (sp), hl
|
|
|
|
push hl
|
|
|
|
jp exit
|
|
|
|
|
|
|
|
; ( a -- a a )
|
|
|
|
.db "DUP"
|
|
|
|
.fill 5
|
|
|
|
.dw SWAP
|
2020-03-10 06:12:44 +11:00
|
|
|
DUP:
|
2020-03-08 13:12:30 +11:00
|
|
|
.dw nativeWord
|
|
|
|
pop hl
|
|
|
|
push hl
|
|
|
|
push hl
|
|
|
|
jp exit
|
|
|
|
|
|
|
|
; ( a b -- a b a )
|
|
|
|
.db "OVER"
|
|
|
|
.fill 4
|
|
|
|
.dw DUP
|
2020-03-10 06:12:44 +11:00
|
|
|
OVER:
|
2020-03-08 13:12:30 +11:00
|
|
|
.dw nativeWord
|
|
|
|
pop hl ; B
|
|
|
|
pop de ; A
|
|
|
|
push de
|
|
|
|
push hl
|
|
|
|
push de
|
|
|
|
jp exit
|
|
|
|
|
2020-03-08 11:42:07 +11:00
|
|
|
; ( a b -- c ) A + B
|
|
|
|
.db "+"
|
|
|
|
.fill 7
|
2020-03-08 13:12:30 +11:00
|
|
|
.dw OVER
|
2020-03-10 06:12:44 +11:00
|
|
|
PLUS:
|
2020-03-08 11:42:07 +11:00
|
|
|
.dw nativeWord
|
|
|
|
pop hl
|
|
|
|
pop de
|
|
|
|
add hl, de
|
|
|
|
push hl
|
|
|
|
jp exit
|
|
|
|
|
|
|
|
; ( a b -- c ) A - B
|
|
|
|
.db "-"
|
|
|
|
.fill 7
|
|
|
|
.dw PLUS
|
2020-03-10 06:12:44 +11:00
|
|
|
MINUS:
|
2020-03-08 11:42:07 +11:00
|
|
|
.dw nativeWord
|
|
|
|
pop de ; B
|
|
|
|
pop hl ; A
|
|
|
|
or a ; reset carry
|
|
|
|
sbc hl, de
|
|
|
|
push hl
|
|
|
|
jp exit
|
|
|
|
|
|
|
|
; ( a b -- c ) A * B
|
|
|
|
.db "*"
|
|
|
|
.fill 7
|
|
|
|
.dw MINUS
|
2020-03-10 06:12:44 +11:00
|
|
|
MULT:
|
2020-03-08 11:42:07 +11:00
|
|
|
.dw nativeWord
|
|
|
|
pop de
|
|
|
|
pop bc
|
|
|
|
call multDEBC
|
|
|
|
push hl
|
|
|
|
jp exit
|
|
|
|
|
|
|
|
; ( a b -- c ) A / B
|
|
|
|
.db "/"
|
|
|
|
.fill 7
|
|
|
|
.dw MULT
|
2020-03-10 06:12:44 +11:00
|
|
|
DIV:
|
2020-03-08 11:42:07 +11:00
|
|
|
.dw nativeWord
|
|
|
|
pop de
|
|
|
|
pop hl
|
|
|
|
call divide
|
|
|
|
push bc
|
|
|
|
jp exit
|
|
|
|
|
2020-03-11 07:02:40 +11:00
|
|
|
; ( a1 a2 -- b )
|
|
|
|
.db "SCMP"
|
|
|
|
.fill 4
|
|
|
|
.dw DIV
|
|
|
|
SCMP:
|
|
|
|
.dw nativeWord
|
|
|
|
pop de
|
|
|
|
pop hl
|
|
|
|
call strcmp
|
|
|
|
call flagsToBC
|
|
|
|
push bc
|
|
|
|
jp exit
|
|
|
|
|
|
|
|
; ( n1 n2 -- f )
|
|
|
|
.db "CMP"
|
|
|
|
.fill 5
|
|
|
|
.dw SCMP
|
|
|
|
CMP:
|
|
|
|
.dw nativeWord
|
|
|
|
pop hl
|
|
|
|
pop de
|
|
|
|
or a ; clear carry
|
|
|
|
sbc hl, de
|
|
|
|
call flagsToBC
|
|
|
|
push bc
|
|
|
|
jp exit
|
|
|
|
|
2020-03-10 05:19:51 +11:00
|
|
|
.db "IF"
|
2020-03-11 12:37:06 +11:00
|
|
|
.fill 5
|
|
|
|
.db 1 ; IMMEDIATE
|
2020-03-11 07:02:40 +11:00
|
|
|
.dw CMP
|
2020-03-10 06:12:44 +11:00
|
|
|
IF:
|
2020-03-11 12:37:06 +11:00
|
|
|
.dw nativeWord
|
|
|
|
; Spit a conditional branching atom, followed by 2 empty bytes. Then,
|
|
|
|
; push the address of those 2 bytes on the PS. ELSE or THEN will pick
|
|
|
|
; them up and set their own address in those 2 bytes.
|
|
|
|
ld hl, (CMPDST)
|
|
|
|
ld de, CBRANCH
|
|
|
|
call DEinHL
|
|
|
|
push hl ; address of cell to fill
|
|
|
|
; For now, let's fill it with a reference to ABORT in case we have a
|
|
|
|
; malformed construct
|
|
|
|
ld de, ABORTREF
|
|
|
|
call DEinHL
|
|
|
|
ld (CMPDST), hl
|
|
|
|
jp exit
|
2020-03-10 05:19:51 +11:00
|
|
|
|
|
|
|
.db "ELSE"
|
2020-03-11 12:37:06 +11:00
|
|
|
.fill 3
|
|
|
|
.db 1 ; IMMEDIATE
|
2020-03-10 05:19:51 +11:00
|
|
|
.dw IF
|
2020-03-10 06:12:44 +11:00
|
|
|
ELSE:
|
2020-03-11 12:37:06 +11:00
|
|
|
.dw nativeWord
|
2020-03-12 07:46:25 +11:00
|
|
|
; First, let's set IF's branching cell.
|
|
|
|
pop de ; cell's address
|
|
|
|
ld hl, (CMPDST)
|
|
|
|
; also skip ELSE word.
|
|
|
|
inc hl \ inc hl \ inc hl \ inc hl
|
|
|
|
or a ; clear carry
|
|
|
|
sbc hl, de ; HL now has relative offset
|
|
|
|
ex de, hl ; HL has branching cell
|
|
|
|
call DEinHL
|
2020-03-11 12:37:06 +11:00
|
|
|
; Set IF's branching cell to current atom address and spit our own
|
|
|
|
; uncondition branching cell, which will then be picked up by THEN.
|
|
|
|
; First, let's spit our 4 bytes
|
|
|
|
ld hl, (CMPDST)
|
|
|
|
ld de, BRANCH
|
|
|
|
call DEinHL
|
|
|
|
push hl ; address of cell to fill
|
|
|
|
ld de, ABORTREF
|
|
|
|
call DEinHL
|
|
|
|
ld (CMPDST), hl
|
|
|
|
jp exit
|
2020-03-10 05:19:51 +11:00
|
|
|
|
|
|
|
.db "THEN"
|
2020-03-11 12:37:06 +11:00
|
|
|
.fill 3
|
|
|
|
.db 1 ; IMMEDIATE
|
2020-03-10 05:19:51 +11:00
|
|
|
.dw ELSE
|
2020-03-10 06:12:44 +11:00
|
|
|
THEN:
|
2020-03-11 12:37:06 +11:00
|
|
|
.dw nativeWord
|
|
|
|
; See comments in IF and ELSE
|
2020-03-12 07:46:25 +11:00
|
|
|
pop de ; cell's address
|
|
|
|
ld hl, (CMPDST)
|
|
|
|
; There is nothing to skip because THEN leaves nothing.
|
|
|
|
or a ; clear carry
|
|
|
|
sbc hl, de ; HL now has relative offset
|
|
|
|
ex de, hl ; HL has branching cell
|
2020-03-11 12:37:06 +11:00
|
|
|
call DEinHL
|
|
|
|
jp exit
|
2020-03-10 05:19:51 +11:00
|
|
|
|
2020-03-11 07:02:40 +11:00
|
|
|
.db "RECURSE"
|
|
|
|
.db 0
|
|
|
|
.dw THEN
|
|
|
|
RECURSE:
|
|
|
|
.dw nativeWord
|
|
|
|
call popRS
|
|
|
|
ld l, (ix)
|
|
|
|
ld h, (ix+1)
|
|
|
|
dec hl \ dec hl
|
|
|
|
push hl \ pop iy
|
|
|
|
jp compiledWord
|
|
|
|
|
2020-03-08 13:12:30 +11:00
|
|
|
; End of native words
|
|
|
|
|
|
|
|
; ( a -- )
|
|
|
|
; @ .
|
|
|
|
.db "?"
|
|
|
|
.fill 7
|
2020-03-11 07:02:40 +11:00
|
|
|
.dw RECURSE
|
2020-03-10 06:12:44 +11:00
|
|
|
FETCHDOT:
|
2020-03-08 13:12:30 +11:00
|
|
|
.dw compiledWord
|
2020-03-10 06:12:44 +11:00
|
|
|
.dw FETCH
|
|
|
|
.dw DOT
|
|
|
|
.dw EXIT
|
2020-03-08 13:12:30 +11:00
|
|
|
|
|
|
|
; ( n a -- )
|
|
|
|
; SWAP OVER @ + SWAP !
|
|
|
|
.db "+!"
|
|
|
|
.fill 6
|
|
|
|
.dw FETCHDOT
|
2020-03-10 06:12:44 +11:00
|
|
|
STOREINC:
|
2020-03-08 13:12:30 +11:00
|
|
|
.dw compiledWord
|
2020-03-10 06:12:44 +11:00
|
|
|
.dw SWAP
|
|
|
|
.dw OVER
|
|
|
|
.dw FETCH
|
|
|
|
.dw PLUS
|
|
|
|
.dw SWAP
|
|
|
|
.dw STORE
|
|
|
|
.dw EXIT
|
2020-03-08 13:12:30 +11:00
|
|
|
|
|
|
|
; ( n -- )
|
|
|
|
; HERE +!
|
2020-03-10 10:50:51 +11:00
|
|
|
.db "ALLOT"
|
|
|
|
.fill 3
|
2020-03-08 13:12:30 +11:00
|
|
|
.dw STOREINC
|
2020-03-10 06:12:44 +11:00
|
|
|
ALLOT:
|
2020-03-08 13:12:30 +11:00
|
|
|
.dw compiledWord
|
2020-03-10 06:12:44 +11:00
|
|
|
.dw HERE_
|
|
|
|
.dw STOREINC
|
|
|
|
.dw EXIT
|
2020-03-08 14:18:14 +11:00
|
|
|
|
2020-03-08 14:23:08 +11:00
|
|
|
; CREATE 2 ALLOT
|
2020-03-10 10:50:51 +11:00
|
|
|
.db "VARIABL"
|
|
|
|
.db 0
|
2020-03-08 14:23:08 +11:00
|
|
|
.dw ALLOT
|
2020-03-10 06:12:44 +11:00
|
|
|
VARIABLE:
|
2020-03-08 14:23:08 +11:00
|
|
|
.dw compiledWord
|
2020-03-10 06:12:44 +11:00
|
|
|
.dw CREATE
|
2020-03-08 14:23:08 +11:00
|
|
|
.dw NUMBER
|
|
|
|
.dw 2
|
2020-03-10 06:12:44 +11:00
|
|
|
.dw ALLOT
|
|
|
|
.dw EXIT
|
2020-03-08 14:23:08 +11:00
|
|
|
|
2020-03-08 14:18:14 +11:00
|
|
|
; ( n -- )
|
|
|
|
; CREATE HERE @ ! DOES> @
|
2020-03-10 10:50:51 +11:00
|
|
|
.db "CONSTAN"
|
|
|
|
.db 0
|
2020-03-08 14:23:08 +11:00
|
|
|
.dw VARIABLE
|
2020-03-10 06:12:44 +11:00
|
|
|
CONSTANT:
|
2020-03-08 14:18:14 +11:00
|
|
|
.dw compiledWord
|
2020-03-10 06:12:44 +11:00
|
|
|
.dw CREATE
|
|
|
|
.dw HERE_
|
|
|
|
.dw FETCH
|
|
|
|
.dw STORE
|
|
|
|
.dw DOES
|
|
|
|
.dw FETCH
|
|
|
|
.dw EXIT
|
2020-03-11 07:02:40 +11:00
|
|
|
|
|
|
|
; ( f -- f )
|
|
|
|
; IF 0 ELSE 1 THEN
|
|
|
|
.db "NOT"
|
|
|
|
.fill 5
|
|
|
|
.dw CONSTANT
|
|
|
|
NOT:
|
|
|
|
.dw compiledWord
|
|
|
|
.dw IF
|
|
|
|
.dw NUMBER
|
|
|
|
.dw 0
|
|
|
|
.dw ELSE
|
|
|
|
.dw NUMBER
|
|
|
|
.dw 1
|
|
|
|
.dw THEN
|
|
|
|
.dw EXIT
|
|
|
|
|
|
|
|
; ( n1 n2 -- f )
|
|
|
|
; CMP NOT
|
|
|
|
.db "="
|
|
|
|
.fill 7
|
|
|
|
.dw NOT
|
|
|
|
EQ:
|
|
|
|
.dw compiledWord
|
|
|
|
.dw CMP
|
|
|
|
.dw NOT
|
|
|
|
.dw EXIT
|
|
|
|
|
|
|
|
; ( n1 n2 -- f )
|
|
|
|
; CMP -1 =
|
|
|
|
.db "<"
|
|
|
|
.fill 7
|
|
|
|
.dw EQ
|
|
|
|
LT:
|
|
|
|
.dw compiledWord
|
|
|
|
.dw CMP
|
|
|
|
.dw NUMBER
|
|
|
|
.dw -1
|
|
|
|
.dw EQ
|
|
|
|
.dw EXIT
|
|
|
|
|
|
|
|
; ( n1 n2 -- f )
|
|
|
|
; CMP 1 =
|
|
|
|
.db ">"
|
|
|
|
.fill 7
|
|
|
|
.dw LT
|
|
|
|
GT:
|
|
|
|
LATEST:
|
|
|
|
.dw compiledWord
|
|
|
|
.dw CMP
|
|
|
|
.dw NUMBER
|
|
|
|
.dw 1
|
|
|
|
.dw EQ
|
|
|
|
.dw EXIT
|