- separate compile time code from run time code
- small
- fast
- actually works
- use the <BUILDS DOES> syntax, which I have an aesthetic preference for
- might become a basis for more general-purpose objects later
Code: Select all
: konst <builds , does> @ ;
15 konst fifteen
: kkonst <builds , , does> 2@ ;
3.1415926 kkonst piCode: Select all
(konst)
jsr dodoes
.word fetch
.word exit
fifteen
jsr (konst)
.word 15
(kkonst)
jsr dodoes
.word twofetch
.word exit
pi
jsr (kkonst)
.byt df, 01, 75, 5e ; 31415926 as 32 bitsCode: Select all
konst
jsr enter
.word plit
.word (konst)
.word (create) ; like CREATE, but takes a stack argument of the CFA to use
.word comma
.word exit
kkonst
jsr enter
.word plit
.word (kkonst)
.word (create)
.word comma
.word comma
.word exitCode: Select all
dodoes
jsr slip ; slip something onto the stack
stx xsave
pla
tax
pla
tay
pla
sta tos
pla
sta tos+1 ; PFA to TOS
jsr inctos ; PFA was off by one because of what JSR pushes
lda ip+1
pha
lda ip
pha ; IP to return stack (for EXIT)
stx ip
sty ip+1 ; set IP from calling child word
ldx xsave
jmp next1 ; this entry point into NEXT only single-increments IPCode: Select all
: @swap! ( a b -- )
2dup 2>r
@ swap @
r> ! r> ! ;
: dpswap ( -- )
dp tdp @swap! ;
: <builds ( == ; "name" -- )
compiling?
if
dp tdp latest ( b c f )
bishwhet ( a a c b-a )
cmove
compile plit , compile (create)
then ; immediate
: does>
compiling?
if
compile exit
dp @ tdp @ >
if
dpswap
then
['] dodoes cfa,
then ; immediateCode: Select all
core tdict symnew
----+----+--- ----+----*- ----.-+-------
^A ^B ^C ^D ^E^F
A = DP before this definition was created
B = DP when <BUILDS is encountered
C = TDP before this definition was created
D = TDP after moving this definition to TDICT
E = CFA of LATEST definition
F = LATEST
bishwhet
ldy #4
jsr locals
brk
.byt popd | TOS
.byt st | N2 ; A
.byt ldd | N0 ; @dp
.byt popd | N0 ; reget B
.byt sub | N2 ; size
.byt st | N3 ; B-A
.byt ldd | N1 ; @tdp
.byt popd | N1 ; reget C
.byt st | N4
.byt std | TOS ; set latest E = C
.byt add | N3
.byt std | N0 ; set DP = C+X
.byt ld | N2
.byt std | N1
.byt st | TOS ; ( a )
.byt push ; ( a a )
.byt ld | N4
.byt push ; ( a a c )
.byt ld | N3
.byt push ; ( a a c b-a )
.byt nxt