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