mirror of
https://github.com/dschmenk/PLASMA.git
synced 2024-08-21 06:29:07 +00:00
Get PLASM parsing
This commit is contained in:
parent
c3c1f1fe17
commit
36c1dea04e
@ -44,7 +44,7 @@ predef a23newline(refnum, emask, nlchar), a2readblock(unit, buf, block), a2write
|
||||
//
|
||||
// Exported function table.
|
||||
//
|
||||
export word fileio[] = @a2getpfx, @a23setpfx, @a2getfileinfo, @a23geteof, @a2open, @a23close
|
||||
export word fileio[] = @a2getpfx, @a23setpfx, @a2getfileinfo, @a23geteof, @a2openbuf, @a2open, @a23close
|
||||
word = @a23read, @a2write, @a2create, @a23destroy
|
||||
word = @a23newline, @a2readblock, @a2writeblock
|
||||
//
|
||||
|
@ -235,7 +235,7 @@ def id_lookup(nameptr, len)
|
||||
idptr = idmatch(nameptr, len, idlocal_tbl, locals)
|
||||
if not idptr
|
||||
idptr = idmatch(nameptr, len, idglobal_tbl, globals)
|
||||
if not idptr; exit_err(ERR_UNDECL|ERR_ID); fin
|
||||
// if not idptr; exit_err(ERR_UNDECL|ERR_ID); fin
|
||||
fin
|
||||
return idptr
|
||||
end
|
||||
@ -243,7 +243,7 @@ def idglobal_lookup(nameptr, len)
|
||||
word idptr
|
||||
|
||||
idptr = idmatch(nameptr, len, idglobal_tbl, globals)
|
||||
if not idptr; exit_err(ERR_UNDECL|ERR_ID); fin
|
||||
// if not idptr; exit_err(ERR_UNDECL|ERR_ID); fin
|
||||
return idptr
|
||||
end
|
||||
def emit_iddata(value, size, namestr)#0
|
||||
@ -290,7 +290,7 @@ def idfunc_set(namestr, len, tag, cparms, cvals)#0
|
||||
|
||||
idptr = idglobal_lookup(namestr, len)
|
||||
if idptr
|
||||
idptr=>idtype = FUNC_TYPE
|
||||
if not idptr=>idtype & FUNC_TYPE; exit_err(ERR_UNDECL|ERR_CODE); fin
|
||||
idptr=>idval = tag
|
||||
idptr->funcparms = cparms
|
||||
idptr->funcvals = cvals
|
||||
|
@ -17,10 +17,10 @@ end
|
||||
def isalphanum(c)
|
||||
if c >= 'A' and c <= 'Z'
|
||||
return TRUE
|
||||
elsif c >= '0' and c <= '9'
|
||||
return TRUE
|
||||
elsif c >= 'a' and c <= 'z'
|
||||
return TRUE
|
||||
elsif c >= '0' and c <= '9'
|
||||
return TRUE
|
||||
elsif c == '_'
|
||||
return TRUE
|
||||
fin
|
||||
@ -148,14 +148,14 @@ def scan
|
||||
is 't'
|
||||
^constval = $09; break
|
||||
otherwise
|
||||
constval = ^scanptr
|
||||
^constval = ^scanptr
|
||||
wend
|
||||
fin
|
||||
constval++
|
||||
strconst++
|
||||
scanptr++
|
||||
loop
|
||||
if !^scanptr; exit_err(ERR_INVAL|ERR_CONST); fin
|
||||
if not ^scanptr; exit_err(ERR_INVAL|ERR_CONST); fin
|
||||
constval = @strconst
|
||||
scanptr++
|
||||
break
|
||||
@ -288,26 +288,31 @@ def nextln
|
||||
scanptr++
|
||||
scan
|
||||
else
|
||||
if token <> EOL_TKN or token <> EOF_TKN; exit_err("Extraneous characters"); fin
|
||||
if token <> EOL_TKN and token <> EOF_TKN; puti(token&$7F); puts("Extraneous characters\n"); exit_err(0); fin
|
||||
scanptr = inbuff
|
||||
^instr = fileio:read(refnum, inbuff, 127)
|
||||
if instr
|
||||
^(inbuff + instr + 1) = 0 // NULL terminate string
|
||||
^instr = fileio:read(refnum, inbuff, 127)
|
||||
if ^instr
|
||||
^(instr + ^instr) = NULL // NULL terminate string
|
||||
lineno++
|
||||
if !(lineno & $0F); putc('.'); fin
|
||||
if scan == INCLUDE_TKN
|
||||
if incref; exit_err("Nested INCLUDEs not allowed"); fin
|
||||
if scan <> STR_TKN; exit_err("Missing INCLUDE file"); fin
|
||||
incfile = scanptr - constval
|
||||
memcpy(@incfile + 1, constval, incfile)
|
||||
if incref; puts("Nested INCLUDEs not allowed\n"); exit_err(0); fin
|
||||
if scan <> STR_TKN; puts("Missing INCLUDE file\n"); exit_err(0); fin
|
||||
strcpy(@incfile, constval)
|
||||
sysincbuf = heapallocalign(1024, 8, @sysincfre)
|
||||
incref = fileio:openbuf(@incfile, sysincbuf)
|
||||
if not incref; exit_err("Unable to open INCLUDE file"); fin
|
||||
incref = fileio:openbuf(@incfile, sysincbuf)
|
||||
if not incref
|
||||
puts("Unable to open INCLUDE file: ")
|
||||
puts(@incfile)
|
||||
putln
|
||||
exit_err(0)
|
||||
fin
|
||||
fileio:newline(incref, $7F, $0D)
|
||||
refnum = incref
|
||||
parsefile = @incfile
|
||||
srcline = lineno
|
||||
lineno = 0
|
||||
scan
|
||||
return nextln
|
||||
fin
|
||||
else
|
||||
@ -316,7 +321,7 @@ def nextln
|
||||
heaprelease(sysincfre)
|
||||
incref = 0
|
||||
refnum = srcref
|
||||
parsefile = srcfile
|
||||
parsefile = @srcfile
|
||||
lineno = srcline
|
||||
return nextln
|
||||
else
|
||||
|
@ -13,16 +13,10 @@ def pop_op
|
||||
return opstack[opsp]
|
||||
end
|
||||
def tos_op
|
||||
if opsp < 0
|
||||
return 0
|
||||
fin
|
||||
return opstack[opsp]
|
||||
return opsp < 0 ?? 0 :: opstack[opsp-1]
|
||||
end
|
||||
def tos_op_prec(tos)
|
||||
if opsp < tos
|
||||
return 100
|
||||
fin
|
||||
return precstack[opsp]
|
||||
return opsp <= tos ?? 100 :: precstack[opsp-1]
|
||||
end
|
||||
def push_val(value, size, type)#0
|
||||
if valsp == 16; exit_err(ERR_OVER|ERR_CODE|ERR_FRAME); fin
|
||||
@ -277,14 +271,14 @@ def parse_value(codeseq, rvalue)#2
|
||||
when token
|
||||
is ID_TKN
|
||||
idptr = id_lookup(tknptr, tknlen)
|
||||
if !idptr; return NULL, 0; fin
|
||||
if !(idptr=>idtype); return NULL, 0; fin
|
||||
if not idptr; return NULL, 0; fin
|
||||
if not idptr=>idtype; return NULL, 0; fin
|
||||
type = type | idptr=>idtype
|
||||
value = idptr=>idval
|
||||
if type & CONST_TYPE
|
||||
valseq = gen_const(NULL, value)
|
||||
else
|
||||
valseq = type & LOCAL_TYPE ?? gen_oplcl(NULL, LADDR_CODE, value) :: gen_opglbl(NULL, GADDR_CODE, value, type)
|
||||
valseq = type & LOCAL_TYPE ?? gen_oplcl(NULL, LADDR_CODE, value) :: gen_opglbl(NULL, GADDR_CODE, value, 0)
|
||||
fin
|
||||
if type & FUNC_TYPE
|
||||
cfnparms = idptr->funcparms
|
||||
@ -858,6 +852,7 @@ def parse_stmnt
|
||||
is END_TKN
|
||||
is DONE_TKN
|
||||
is DEF_TKN
|
||||
is EOF_TKN
|
||||
return FALSE
|
||||
otherwise
|
||||
rewind(tknptr)
|
||||
@ -1165,14 +1160,10 @@ def parse_defs
|
||||
fin
|
||||
emit_ctag(func_tag)
|
||||
retfunc_tag = ctag_new
|
||||
while parse_vars(LOCAL_TYPE)
|
||||
nextln
|
||||
loop
|
||||
while parse_vars(LOCAL_TYPE); nextln; loop
|
||||
emit_enter(cfnparms)
|
||||
prevstmnt = 0
|
||||
while parse_stmnt
|
||||
nextln
|
||||
loop
|
||||
while parse_stmnt; nextln; loop
|
||||
infunc = FALSE
|
||||
if token <> END_TKN; exit_err(ERR_MISS|ERR_CLOSE|ERR_STATE); fin
|
||||
scan
|
||||
@ -1198,8 +1189,9 @@ def parse_module#0
|
||||
//
|
||||
// Compile module
|
||||
//
|
||||
while parse_mods; nextln; loop
|
||||
while parse_vars(GLOBAL_TYPE); nextln; loop
|
||||
while parse_defs; nextln; loop
|
||||
while parse_defs; nextln; loop
|
||||
entrypoint = codeptr
|
||||
prevstmnt = 0
|
||||
idlocal_init
|
||||
@ -1211,6 +1203,7 @@ def parse_module#0
|
||||
emit_const(0)
|
||||
emit_leave
|
||||
fin
|
||||
if token <> DONE_TKN; parse_warn("Missing DONE\n"); fin
|
||||
//dumpsym(idglobal_tbl, globals)
|
||||
fin
|
||||
end
|
||||
|
@ -196,11 +196,11 @@ byte = 10
|
||||
// Lowest precedence
|
||||
byte[16] opstack
|
||||
byte[16] precstack
|
||||
word opsp = 0
|
||||
word opsp
|
||||
word[16] valstack
|
||||
byte[16] sizestack
|
||||
byte[16] typestack
|
||||
word valsp = 0
|
||||
word valsp
|
||||
//
|
||||
// Constant code group
|
||||
//
|
||||
@ -333,22 +333,22 @@ byte outflags
|
||||
// ProDOS/SOS file references
|
||||
//
|
||||
byte refnum, srcref, incref
|
||||
byte[32] srcfile
|
||||
byte[32] incfile
|
||||
byte[32] relfile
|
||||
byte[32] srcfile, incfile, relfile
|
||||
word parsefile // Pointer to current file
|
||||
word sysincbuf, sysincfre // System I/O buffer for include files
|
||||
word srcline // Saved source line number
|
||||
//
|
||||
// Scanner variables
|
||||
//
|
||||
const inbuff = $0200
|
||||
const instr = $01FF
|
||||
word scanptr = inbuff
|
||||
byte scanchr, token, tknlen
|
||||
//const inbuff = $0200
|
||||
//const instr = $01FF
|
||||
//word scanptr = inbuff
|
||||
byte token = EOL_TKN
|
||||
word instr, inbuff, scanptr
|
||||
byte scanchr, tknlen
|
||||
word tknptr, parserrln
|
||||
word constval
|
||||
word lineno = 0
|
||||
word lineno
|
||||
//
|
||||
// Parser variables
|
||||
//
|
||||
@ -369,9 +369,9 @@ word[LAMBDANUM] lambda_seq
|
||||
word[LAMBDANUM] lambda_tag
|
||||
predef parse_constexpr#3, parse_expr(codeseq)#2, parse_lambda
|
||||
//
|
||||
// Arg pointer - overlay setjmp pointer
|
||||
// Arg pointer
|
||||
//
|
||||
word[] arg
|
||||
word arg, opt
|
||||
//
|
||||
// Long jump environment
|
||||
//
|
||||
@ -418,13 +418,9 @@ def nametostr(namestr, len, strptr)#0
|
||||
memcpy(strptr + 1, namestr, len)
|
||||
end
|
||||
def putcurln#0
|
||||
puts(parsefile); putc('['); puti(lineno); puts("] ")
|
||||
end
|
||||
def putmrkr#0
|
||||
byte i
|
||||
|
||||
putln
|
||||
puts(instr)
|
||||
putln; puts(parsefile); putc('['); puti(lineno); puts("]\n")
|
||||
puts(instr); putln
|
||||
for i = tknptr - inbuff downto 1
|
||||
putc(' ')
|
||||
next
|
||||
@ -436,8 +432,7 @@ end
|
||||
def exit_err(err)#0
|
||||
byte i
|
||||
|
||||
putcurln
|
||||
puts("Error:")
|
||||
puts("\nError:")
|
||||
if err & ERR_DUP; puts("duplicate "); fin
|
||||
if err & ERR_UNDECL; puts("undeclared "); fin
|
||||
if err & ERR_INVAL; puts("invalid "); fin
|
||||
@ -447,14 +442,14 @@ def exit_err(err)#0
|
||||
if err & ERR_LOCAL; puts("local "); fin
|
||||
if err & ERR_GLOBAL; puts("global "); fin
|
||||
if err & ERR_CODE; puts("code "); fin
|
||||
if err & ERR_ID; puts("identifier "); fin
|
||||
if err & ERR_ID; puts("identifier "); fin
|
||||
if err & ERR_CONST; puts("constant"); fin
|
||||
if err & ERR_INIT; puts("initializer"); fin
|
||||
if err & ERR_STATE; puts("statement"); fin
|
||||
if err * ERR_FRAME; puts("frame"); fin
|
||||
if err & ERR_FRAME; puts("frame"); fin
|
||||
if err & ERR_TABLE; puts("table"); fin
|
||||
if err & ERR_SYNTAX; puts("syntax"); fin
|
||||
putmrkr
|
||||
putcurln
|
||||
fileio:close(0) // Close all open files
|
||||
longjmp(exit, TRUE)
|
||||
end
|
||||
@ -463,10 +458,9 @@ end
|
||||
//
|
||||
def parse_warn(msg)#0
|
||||
if outflags & WARNINGS
|
||||
putcurln
|
||||
puts("Warning:")
|
||||
puts("\nWarning:")
|
||||
puts(msg)
|
||||
putmrkr
|
||||
putcurln
|
||||
fin
|
||||
end
|
||||
//
|
||||
@ -480,19 +474,21 @@ include "toolsrc/parse.pla"
|
||||
//
|
||||
arg = argNext(argFirst)
|
||||
if ^arg and ^(arg + 1) == '-'
|
||||
arg = arg + 2
|
||||
opt = arg + 2
|
||||
while TRUE
|
||||
if toupper(^arg) == 'O'
|
||||
if toupper(^opt) == 'O'
|
||||
outflags = outflags | OPTIMIZE
|
||||
arg++
|
||||
if ^arg == '2'
|
||||
opt++
|
||||
if ^opt == '2'
|
||||
outflags = outflags | OPTIMIZE2
|
||||
arg++
|
||||
opt++
|
||||
fin
|
||||
elsif toupper(^arg) == 'N'
|
||||
elsif toupper(^opt) == 'N'
|
||||
outflags = outflags | NO_COMBINE
|
||||
elsif toupper(^arg) == 'W'
|
||||
opt++
|
||||
elsif toupper(^opt) == 'W'
|
||||
outflags = outflags | WARNINGS
|
||||
opt++
|
||||
else
|
||||
break
|
||||
fin
|
||||
@ -512,7 +508,11 @@ if srcfile and relfile
|
||||
fileio:newline(srcref, $7F, $0D)
|
||||
refnum = srcref
|
||||
parsefile = @srcfile
|
||||
exit = heapalloc(t_longjmp)
|
||||
instr = heapalloc(128)
|
||||
*instr = 0
|
||||
inbuff = instr + 1
|
||||
scanptr = inbuff
|
||||
exit = heapalloc(t_longjmp)
|
||||
if not setjmp(exit)
|
||||
//
|
||||
// Parse source code module
|
||||
@ -537,6 +537,6 @@ if srcfile and relfile
|
||||
puts("Error opening: "); puts(@srcfile); putln
|
||||
fin
|
||||
else
|
||||
puts("Usage: +PLASM [-[W][O[2]][N]] <srcfile> <relfile>\n")
|
||||
puts("Usage: +PLASM [-[W][O[2]][N]] <src> <rel>\n")
|
||||
fin
|
||||
done
|
||||
|
Loading…
Reference in New Issue
Block a user