1
0
mirror of https://github.com/dschmenk/PLASMA.git synced 2025-01-10 06:30:41 +00:00

Functional <BUILD DOES>

This commit is contained in:
Dave Schmenk 2023-12-19 14:21:37 -08:00
parent ec16b9cc78
commit ec9718de53

View File

@ -25,9 +25,9 @@ predef _drop_(a)#0, _swap_(a,b)#2, _dup_(a)#2
predef _add_(a,b)#1, _sub_(a,b)#1, _mul_(a,b)#1, _div_(a,b)#1 predef _add_(a,b)#1, _sub_(a,b)#1, _mul_(a,b)#1, _div_(a,b)#1
predef _cset_(a,b)#0, _cget_(a)#1, _wset_(a,b)#0, _wget_(a)#1 predef _cset_(a,b)#0, _cget_(a)#1, _wset_(a,b)#0, _wget_(a)#1
predef _cfa_(a)#1, _lfa_(a)#1 predef _cfa_(a)#1, _lfa_(a)#1
predef _create_#0, _builds_#0, _does_#0, _pset_(a)#0, _colon_#0, _semi_#0 predef _create_#0, _builds_#0, _dodoes_(words)#0, _filldoes_#0, _does_#0, _pset_(a)#0, _colon_#0, _semi_#0
predef _var_(a)#0, _lit_#1, _forget_#0 predef _var_(a)#0, _lit_#1, _tick_#1, _forget_#0
predef _vlist_#0, _show_#0, _bye_#0 predef _vlist_#0, _tron_#0, _troff_#0, _show_#0, _bye_#0
// DROP // DROP
char d_drop = "DROP" char d_drop = "DROP"
word = 0, @_drop_, 0 word = 0, @_drop_, 0
@ -75,9 +75,15 @@ word = @d_allot, @_forget_, 0
// BUILDS // BUILDS
char d_builds = "<BUILDS" char d_builds = "<BUILDS"
word = @d_forget, @_builds_, 0 word = @d_forget, @_builds_, 0
// FILL DOES COMPILE TIME
char d_filldoes = "FILLDOES"
word = @d_builds, @_filldoes_, 0
// DO DOES RUN TIME
char d_dodoes = "DODOES>"
word = @d_filldoes, @_dodoes_, 0
// DOES // DOES
char d_does = "DOES>" char d_does = "DOES>"
word = @d_builds, @_does_, 0 word = @d_dodoes, @_does_, 0
// COMMA // COMMA
char d_comma = "," char d_comma = ","
word = @d_does, @_pset_, 0 word = @d_does, @_pset_, 0
@ -87,21 +93,33 @@ word = @d_comma, @_colon_, 0
// SEMI // SEMI
char d_semi = ";" char d_semi = ";"
word = @d_colon, @_semi_, 0 word = @d_colon, @_semi_, 0
// TICK
char d_tick = "'"
word = @d_semi, @_tick_, 0
// LITERAL // LITERAL
char d_lit = "LIT" char d_lit = "LIT"
word = @d_semi, @_lit_, 0 word = @d_tick, @_lit_, 0
// PRINT TOS // PRINT TOS
char d_prtos = "." char d_prtos = "."
word = @d_lit, @puti, 0 word = @d_lit, @puti, 0
// PRINT TOS HEX
char d_prtoshex = ".$"
word = @d_prtos, @puth, 0
// EXIT // EXIT
char d_bye = "BYE" char d_bye = "BYE"
word = @d_prtos, @_bye_, 0 word = @d_prtoshex, @_bye_, 0
// SHOW DEFINITION // SHOW DEFINITION
char d_show = "SHOW" char d_show = "SHOW"
word = @d_bye, @_show_, 0 word = @d_bye, @_show_, 0
// TRACE ON
char d_tron = "TRON"
word = @d_show, @_tron_, 0
// TRACE OFF
char d_troff = "TROFF"
word = @d_tron, @_troff_, 0
// LIST VOCAB // LIST VOCAB
char d_vlist = "VLIST" char d_vlist = "VLIST"
word = @d_show, @_vlist_, 0 word = @d_troff, @_vlist_, 0
// //
// Internal variables // Internal variables
// //
@ -114,6 +132,7 @@ const comp_flag = $01
const build_flag = $02 const build_flag = $02
const exit_flag = $80 const exit_flag = $80
char state = 0 char state = 0
char trace = 0
// //
// Dictionary routines // Dictionary routines
// //
@ -145,18 +164,6 @@ def find#1
return 0 return 0
end end
// //
// Execute code in CFA
//
def exec(dentry)#0
//char l
//l = ^dentry
//^dentry = l & len_mask
//puts("Exec "); puts(dentry); putln
//^dentry = l
W = _cfa_(dentry)
(*W)()#0
end
//
// Convert input into number // Convert input into number
// //
def isnum#2 def isnum#2
@ -234,20 +241,49 @@ def _pfa_(dentry)#1
l = ^dentry & len_mask l = ^dentry & len_mask
return dentry + l + 5 return dentry + l + 5
end end
//
// Execute code in CFA
//
def execword(dentry)#0
char l
if trace
l = ^dentry
^dentry = l & len_mask
puts(": "); puts(dentry); putln
^dentry = l
fin
W = _cfa_(dentry)
(*W)()#0
end
def execwords(wlist)#0
word prevIP
prevIP = IIP
IIP = wlist
while *IIP
execword(*IIP)
IIP = IIP + 2
loop
IIP = prevIP
end
def _dovar_#1 def _dovar_#1
return W + 2 return W + 2
end end
def _docolon_#0 def _docolon_#0
word prevIP //puts("DOCOLON:\n")
execwords(W + 2)
puts("DOCOLON:\n") end
prevIP = IIP def _pushPFA_#1
IIP = W + 2 return W + 2
while *IIP end
exec(*IIP) def _dodoes_(words)#0
IIP = IIP + 2 //puts("DODOES:\n")
loop (@_pushPFA_)()#0 // Stack hacks
IIP = prevIP execwords(words)
end
def _filldoes_#0
*(_cfa_(vlist)) = IIP + 4
end end
def _lit_#1 def _lit_#1
IIP = IIP + 2 IIP = IIP + 2
@ -275,14 +311,19 @@ def _create_#0
fin fin
end end
def _builds_#0 def _builds_#0
if state == comp_flag _create_
state = build_flag
fin
end end
def _does_#0 def _does_#0
if state == build_flag *(heapalloc(2)) = @d_filldoes
state = comp_flag *(heapalloc(2)) = 0
fin // Build PLASMA bytecode routine
^(heapalloc(1)) = (@divmod)->0 // JSR INTERP
*(heapalloc(2)) = (@divmod)=>1
^(heapalloc(1)) = $2C // CONSTANT WORD
*(heapalloc(2)) = heapmark + 6
^(heapalloc(1)) = $54 // CALL _dodoes_
*(heapalloc(2)) = @_dodoes_
^(heapalloc(1)) = $5C // RET
end end
def _pset_(a)#0 def _pset_(a)#0
*(heapalloc(2)) = a *(heapalloc(2)) = a
@ -306,6 +347,12 @@ end
def _immediate_#0 def _immediate_#0
^vlist = ^vlist | imm_flag ^vlist = ^vlist | imm_flag
end end
def _tick_#1
while ^inptr == ' '
inptr++
loop
return find
end
def _forget_#0 def _forget_#0
word dentry word dentry
@ -321,13 +368,17 @@ def _show_#0
word dentry, pfa, w word dentry, pfa, w
char l, f char l, f
while ^inptr == ' ' while ^inptr == ' '
inptr++ inptr++
loop loop
if ^inptr > ' ' if ^inptr > ' '
dentry = find dentry = find
if dentry if dentry
pfa = _pfa_(dentry) if *_cfa_(dentry) == @_docolon_
pfa = _pfa_(dentry)
else
pfa = *_cfa_(dentry) + 10
fin
w = *pfa w = *pfa
while w while w
f = ^w f = ^w
@ -341,6 +392,12 @@ if ^inptr > ' '
fin fin
fin fin
end end
def _tron_#0
trace = 1
end
def _troff_#0
trace = 0
end
def _vlist_#0 def _vlist_#0
word d word d
char f, l char f, l
@ -368,6 +425,7 @@ def _quit_#0
// Set flags on words // Set flags on words
// //
d_semi = d_semi | imm_flag d_semi = d_semi | imm_flag
d_does = d_does | imm_flag
repeat repeat
puts(" OK") puts(" OK")
inptr = gets('\n'|$80) inptr = gets('\n'|$80)
@ -388,7 +446,7 @@ def _quit_#0
dentry = find dentry = find
if dentry if dentry
if (not state & comp_flag) or (^dentry & imm_flag) if (not state & comp_flag) or (^dentry & imm_flag)
exec(dentry) execword(dentry)
else else
//puts("Compile "); puts(dentry); putln //puts("Compile "); puts(dentry); putln
_pset_(dentry) _pset_(dentry)