1
0
mirror of https://github.com/dschmenk/PLASMA.git synced 2024-12-28 10:30:17 +00:00

Fix case tatement in self hosted compiler and Apple 1 module loading

This commit is contained in:
David Schmenk 2024-03-07 15:18:15 -08:00
parent d90b7ba69d
commit 7aeda2d98b
5 changed files with 51 additions and 82 deletions

View File

@ -205,7 +205,7 @@ def emit_caseblock(cnt, oflist, typlist, taglist)#0
emit_pending_seq emit_pending_seq
emit_byte(cnt) emit_byte(cnt)
for i = 0 to cnt-1 for i = 0 to cnt-1
if typlist=>[i] & CONSTADDR_TYPE if typlist=>[i] == CONSTADDR_TYPE
emit_addr(oflist=>[i], 0) emit_addr(oflist=>[i], 0)
else else
emit_word(oflist=>[i]) emit_word(oflist=>[i])

View File

@ -614,7 +614,7 @@ def parse_stmnt
byte type, elem_type, elem_size, cfnvals byte type, elem_type, elem_size, cfnvals
word seq, fromseq, toseq, tag_prevbrk, tag_prevcnt, tag_else, tag_endif, tag_while, tag_wend word seq, fromseq, toseq, tag_prevbrk, tag_prevcnt, tag_else, tag_endif, tag_while, tag_wend
word tag_repeat, tag_for, tag_choice, tag_of, idptr, addr, stepdir word tag_repeat, tag_for, tag_choice, tag_of, idptr, addr, stepdir
word caseconst, casetype, casecnt, caseval, casetyp, casetag, i word case_const, case_type, casecnt, caseval, casetyp, casetag, i
if token <> END_TKN and token <> DONE_TKN and token <> OF_TKN and token <> DEFAULT_TKN if token <> END_TKN and token <> DONE_TKN and token <> OF_TKN and token <> DEFAULT_TKN
prevstmnt = token prevstmnt = token
@ -802,9 +802,9 @@ def parse_stmnt
tag_prevbrk = break_tag tag_prevbrk = break_tag
break_tag = new_tag(RELATIVE_FIXUP) break_tag = new_tag(RELATIVE_FIXUP)
tag_choice = new_tag(RELATIVE_FIXUP) tag_choice = new_tag(RELATIVE_FIXUP)
caseval = heapalloc(CASENUM) caseval = heapalloc(CASENUM*2)
casetyp = heapalloc(CASENUM) casetyp = heapalloc(CASENUM*2)
casetag = heapalloc(CASENUM) casetag = heapalloc(CASENUM*2)
casecnt = 0 casecnt = 0
seq, cfnvals = parse_expr(NULL) seq, cfnvals = parse_expr(NULL)
if !seq; exit_err(ERR_INVAL|ERR_STATE); fin if !seq; exit_err(ERR_INVAL|ERR_STATE); fin
@ -819,10 +819,10 @@ def parse_stmnt
when token when token
is OF_TKN is OF_TKN
if casecnt == CASENUM; exit_err(ERR_OVER|ERR_TABLE); fin if casecnt == CASENUM; exit_err(ERR_OVER|ERR_TABLE); fin
caseconst, drop, casetype = parse_constexpr case_const, drop, case_type = parse_constexpr
tag_of = new_tag(RELATIVE_FIXUP) tag_of = new_tag(RELATIVE_FIXUP)
i = casecnt i = casecnt
while i > 0 and caseval=>[i-1] > caseconst while i > 0 and caseval=>[i-1] > case_const
// //
// Move larger case consts up // Move larger case consts up
// //
@ -831,9 +831,9 @@ def parse_stmnt
casetag=>[i] = casetag=>[i-1] casetag=>[i] = casetag=>[i-1]
i-- i--
loop loop
if i < casecnt and caseval=>[i] == caseconst; exit_err(ERR_DUP|ERR_STATE); fin if i < casecnt and caseval=>[i] == case_const; exit_err(ERR_DUP|ERR_STATE); fin
caseval=>[i] = caseconst caseval=>[i] = case_const
casetyp=>[i] = casetype casetyp=>[i] = case_type
casetag=>[i] = tag_of casetag=>[i] = tag_of
casecnt++ casecnt++
emit_tag(tag_of) emit_tag(tag_of)
@ -848,7 +848,7 @@ def parse_stmnt
emit_branch(tag_of) emit_branch(tag_of)
fin fin
emit_tag(tag_choice) emit_tag(tag_choice)
emit_caseblock(casecnt, caseval, casetype, casetag) emit_caseblock(casecnt, caseval, casetyp, casetag)
tag_choice = 0 tag_choice = 0
if tag_of if tag_of
emit_tag(tag_of) emit_tag(tag_of)

View File

@ -508,7 +508,7 @@ include "toolsrc/parse.pla"
// //
// Look at command line arguments and compile module // Look at command line arguments and compile module
// //
puts("PLASMA Compiler, Version 2.1\n") puts("PLASMA Compiler, Version 2.11\n")
arg = argNext(argFirst) arg = argNext(argFirst)
if ^arg and ^(arg + 1) == '-' if ^arg and ^(arg + 1) == '-'
opt = arg + 2 opt = arg + 2

View File

@ -53,7 +53,7 @@ word = @syslookuptbl
// String pool. // String pool.
// //
byte autorun[] = "AUTORUN" byte autorun[] = "AUTORUN"
byte verstr[] = "\nPLASMA BETA" byte verstr[] = "\nAPPLE1 PLASMA "
byte freestr[] = "MEM FREE:$" byte freestr[] = "MEM FREE:$"
byte errorstr[] = "ERR:$" byte errorstr[] = "ERR:$"
byte prompt[] = "PLASMA" byte prompt[] = "PLASMA"
@ -132,24 +132,17 @@ word syslibsym = @exports
// //
// Utility functions // Utility functions
// //
asm saveX#0
STX XREG+1
end
asm restoreX#0
XREG LDX #$00
RTS
end
// //
// CALL CFFA1 API ENTRYPOINT // CALL CFFA1 API ENTRYPOINT
// SYSCALL(CMD, 0) // SYSCALL(CMD, 0)
// //
asm syscall(cmd, null)#1 asm syscall(cmd, null)#1
INX
LDA ESTKL,X LDA ESTKL,X
STX ESP STX ESP
TAX TAX
JSR $900C JSR $900C
LDX ESP LDX ESP
INX
LDY #$00 LDY #$00
STA ESTKL,X STA ESTKL,X
STY ESTKH,X STY ESTKH,X
@ -199,7 +192,7 @@ end
// QUIT TO MONITOR // QUIT TO MONITOR
// //
asm quit()#0 asm quit()#0
JMP $9000 JMP $9000
end end
// //
// SET MEMORY TO VALUE // SET MEMORY TO VALUE
@ -744,15 +737,19 @@ end
asm cout(c)#0 asm cout(c)#0
LDA ESTKL,X LDA ESTKL,X
JSR TOUPR JSR TOUPR
INX
ORA #$80 ORA #$80
JMP $FFEF JMP $FFEF
; JMP $FDED
end end
asm cin()#1 asm cin()#1
DEX
- LDA $D011 - LDA $D011
;- LDA $C000
BPL - BPL -
LDA $D010 LDA $D010
; STA $C010
AND #$7F AND #$7F
DEX
STA ESTKL,X STA ESTKL,X
LDA #$00 LDA #$00
STA ESTKH,X STA ESTKH,X
@ -775,32 +772,32 @@ end
def rdstr(prompt)#1 def rdstr(prompt)#1
byte ch, maxlen byte ch, maxlen
maxlen = 0 maxlen = 0
inbuff.0 = 0 ^inbuff = 0
cout(prompt) cout(prompt)
repeat repeat
ch = cin ch = cin
when ch when ch
is $15 // right arrow is $15 // right arrow
if ^inbuff < maxlen //inbuff.0 < maxlen if ^inbuff < maxlen
inbuff.0++ ^inbuff++
ch = inbuff[inbuff.0] ch = ^(inbuff + ^inbuff)]
cout(ch) cout(ch)
fin fin
break break
is $08 // left arrow is $08 // left arrow
if inbuff.0 if ^inbuff
cout('\\') cout('\\')
cout(inbuff[inbuff.0]) cout(^(inbuff + ^inbuff))
inbuff.0-- inbuff.0--
fin fin
break break
is $04 // ctrl-d is $04 // ctrl-d
if inbuff.0 if inbuff.0
cout('#') cout('#')
cout(inbuff[inbuff.0]) cout(^(inbuff + ^inbuff))
memcpy(inbuff + inbuff.0, inbuff + inbuff.0 + 1, maxlen - inbuff.0) memcpy(inbuff + ^inbuff, inbuff + ^inbuff + 1, maxlen - ^inbuff)
maxlen-- maxlen--
inbuff.0-- ^inbuff--
fin fin
break break
is $0C // ctrl-l is $0C // ctrl-l
@ -808,25 +805,26 @@ def rdstr(prompt)#1
prstr(inbuff) prstr(inbuff)
break break
is $0D // return is $0D // return
break
is $18 // ctrl-x is $18 // ctrl-x
crout crout
inbuff.0 = 0 ^inbuff = 0
break break
is $9B // escape is $9B // escape
inbuff.0 = 0 ^inbuff = 0
ch = $0D ch = $0D
break break
otherwise otherwise
if ch >= ' ' if ch >= ' '
cout(ch) cout(ch)
inbuff.0++ ^inbuff++
inbuff[inbuff.0] = ch ^(inbuff + ^inbuff) = ch
if inbuff.0 > maxlen if ^inbuff > maxlen
maxlen = inbuff.0 maxlen = ^inbuff
fin fin
fin fin
wend wend
until ch == $0D or inbuff.0 == $7F until ch == $0D or ^inbuff == $7F
cout($0D) cout($0D)
return inbuff return inbuff
end end
@ -855,14 +853,6 @@ end
// CFFA1 routines // CFFA1 routines
// FILE I/O // FILE I/O
// //
//def opendir
// perr = syscall($10, 0)
// return perr
//end
//def readdir
// perr = syscall($12, 0)
// return *CFFAEntryPtr
//end
def finddirentry(filename)#1 def finddirentry(filename)#1
*CFFAFileName = filename *CFFAFileName = filename
perr = syscall($14, 0) perr = syscall($14, 0)
@ -982,7 +972,7 @@ def loadmod(mod)#1
moddep = @header.1 moddep = @header.1
defofst = modsize + RELADDR defofst = modsize + RELADDR
init = 0 init = 0
if rdlen > 4 and heap=>2 == $6502 // magic number if rdlen > 4 and header:2 == $6502 // magic number
// //
// This is an EXTended RELocatable (data+bytecode) module. // This is an EXTended RELocatable (data+bytecode) module.
// //
@ -1042,10 +1032,12 @@ def loadmod(mod)#1
// //
// Run through the DeFinition Dictionary. // Run through the DeFinition Dictionary.
// //
prstr("Bytecode = "); prword(bytecode); crout
while ^rld == $02 while ^rld == $02
// //
// This is a bytcode def entry - add it to the def directory. // This is a bytcode def entry - add it to the def directory.
// //
prstr("Add DEF: "); prword(rld=>1 + defofst); prstr(" -> "); prword(deflast); crout
adddef(rld=>1 + defofst, @deflast) adddef(rld=>1 + defofst, @deflast)
rld = rld + 4 rld = rld + 4
loop loop
@ -1058,31 +1050,6 @@ def loadmod(mod)#1
*addr = ^rld & $10 ?? *addr + lookupextern(esd, rld->3) :: lookupdef(fixup + defofst, deftbl) *addr = ^rld & $10 ?? *addr + lookupextern(esd, rld->3) :: lookupdef(fixup + defofst, deftbl)
rld = rld + 4 rld = rld + 4
fin fin
//addr = rld=>1 + modfix
//if uword_isge(addr, modaddr) // Skip fixups to header
// if type & $80 // WORD sized fixup.
// fixup = *addr
// else // BYTE sized fixup.
// fixup = ^addr
// fin
// if ^rld & $10 // EXTERN reference.
// fixup = fixup + lookupextern(esd, rld->3)
// else // INTERN fixup.
// fixup = fixup + modofst
// if uword_isge(fixup, bytecode)
// //
// // Bytecode address - replace with call def directory.
// //
// fixup = lookupdef(fixup + defofst, deftbl)
// fin
// fin
// if type & $80 // WORD sized fixup.
// *addr = fixup
// else // BYTE sized fixup.
// ^addr = fixup
// fin
//fin
//rld = rld + 4
loop loop
// //
// Run through the External/Entry Symbol Directory. // Run through the External/Entry Symbol Directory.
@ -1094,12 +1061,13 @@ def loadmod(mod)#1
// //
// EXPORT symbol - add it to the global symbol table. // EXPORT symbol - add it to the global symbol table.
// //
addr = esd=>1 + modofst addr = esd=>1 + defofst // modofst
if uword_isge(addr, bytecode) if uword_isge(addr, bytecode)
// //
// Use the def directory address for bytecode. // Use the def directory address for bytecode.
// //
addr = lookupdef(addr + defofst, deftbl) //addr = lookupdef(addr + defofst, deftbl)
addr = lookupdef(addr, deftbl)
fin fin
addsym(sym, addr) addsym(sym, addr)
fin fin
@ -1118,8 +1086,7 @@ def loadmod(mod)#1
// //
fixup = modkeep fixup = modkeep
if init if init
init = init - defofst + bytecode fixup = adddef(init + defofst, @deflast)()
fixup = adddef(init, @deflast)()
if fixup < 0 if fixup < 0
perr = -fixup perr = -fixup
fin fin
@ -1234,6 +1201,7 @@ while 1
when toupper(parsecmd(cmdptr)) when toupper(parsecmd(cmdptr))
is 'Q' is 'Q'
quit quit
break
is 'M' is 'M'
syscall($02, 0) syscall($02, 0)
break break
@ -1250,7 +1218,7 @@ while 1
else else
prstr(@okstr) prstr(@okstr)
fin fin
crout() crout()
fin fin
prstr(@prompt) prstr(@prompt)
cmdptr = rdstr($BA) cmdptr = rdstr($BA)

View File

@ -22,6 +22,7 @@ OPPAGE = OPIDX+1
;* INTERPRETER HEADER+INITIALIZATION ;* INTERPRETER HEADER+INITIALIZATION
;* ;*
*= $0280 *= $0280
;* *= $2000
SEGBEGIN JMP VMINIT SEGBEGIN JMP VMINIT
;* ;*
;* SYSTEM INTERPRETER ENTRYPOINT ;* SYSTEM INTERPRETER ENTRYPOINT
@ -33,7 +34,7 @@ INTERP PLA
PLA PLA
ADC #$00 ADC #$00
STA IPH STA IPH
LDY #$01 LDY #$00
JMP FETCHOP JMP FETCHOP
;* ;*
;* ENTER INTO USER BYTECODE INTERPRETER ;* ENTER INTO USER BYTECODE INTERPRETER
@ -774,7 +775,7 @@ ISGE LDA ESTKL+1,X
BPL ISTRU BPL ISTRU
BMI ISFLS BMI ISFLS
+ +
- BPL ISFLS - BPL ISFLS
BMI ISTRU BMI ISTRU
ISLE LDA ESTKL,X ISLE LDA ESTKL,X
CMP ESTKL+1,X CMP ESTKL+1,X