Convert comment symbol to '//' and allow multiple statements per line

with ';'
This commit is contained in:
David Schmenk 2014-08-14 19:28:31 -07:00
parent a6ebac6b5e
commit fb3f6722cf
5 changed files with 305 additions and 290 deletions

View File

@ -4,37 +4,37 @@ const databuff = $2000
const MODADDR = $1000
const symtbl = $0C00
const freemem = $0006
;
; System flags: memory allocator screen holes.
;
//
// System flags: memory allocator screen holes.
//
const restxt1 = $0001
const restxt2 = $0002
const reshgr1 = $0004
const reshgr2 = $0008
const resxhgr1 = $0010
const resxhgr2 = $0020
;
; Pedefined functions.
;
//
// Pedefined functions.
//
predef syscall, call
predef crout, cout, prstr, cin, rdstr
predef markheap, allocheap, allocalignheap, releaseheap, availheap
predef memset, memcpy
predef uword_isgt, uword_isge, uword_islt, uword_isle
predef loadmod, execmod, lookupstrmod
;
; System variable.
;
word version = $0010 ; 00.10
//
// System variable.
//
word version = $0010 // 00.10
word systemflags = 0
word heap
word xheap = $0800
word lastsym = symtbl
byte perr
word cmdptr
;
; Standard Library exported functions.
;
//
// Standard Library exported functions.
//
byte stdlibstr[] = "STDLIB"
byte machidstr[] = "MACHID"
byte sysstr[] = "SYSCALL"
@ -81,9 +81,9 @@ word = @modadrstr, @lookupstrmod
word = @machidstr, MACHID
word = 0
word stdlibsym = @exports
;
; String pool.
;
//
// String pool.
//
byte autorun[] = "AUTORUN"
byte verstr[] = "PLASMA "
byte freestr[] = "MEM FREE:$"
@ -91,14 +91,14 @@ byte errorstr[] = "ERR:$"
byte okstr[] = "OK"
byte huhstr[] = "?\n"
byte prefix[32] = ""
;
; Utility functions
;
;asm equates included from cmdstub.s
;
; CALL PRODOS
; SYSCALL(CMD, PARAMS)
;
//
// Utility functions
//
//asm equates included from cmdstub.s
//
// CALL PRODOS
// SYSCALL(CMD, PARAMS)
//
asm syscall
LDA ESTKL,X
LDY ESTKH,X
@ -115,10 +115,10 @@ PARAMS: !WORD 0000
STY ESTKH,X
RTS
end
;
; CALL 6502 ROUTINE
; CALL(ADDR, AREG, XREG, YREG, STATUS)
;
//
// CALL 6502 ROUTINE
// CALL(ADDR, AREG, XREG, YREG, STATUS)
//
asm call
REGVALS = SRC
PHP
@ -159,9 +159,9 @@ REGVALS = SRC
RTS
JMPTMP JMP (TMP)
end
;
; CALL LOADED SYSTEM PROGRAM
;
//
// CALL LOADED SYSTEM PROGRAM
//
asm exec
LDX #$00
STX IFPL
@ -173,19 +173,19 @@ asm exec
BIT ROMEN
JMP $2000
end
;
; EXIT
;
//
// EXIT
//
asm reboot
BIT ROMEN
DEC $03F4 ; INVALIDATE POWER-UP BYTE
JMP ($FFFC) ; RESET
end
;
; SET MEMORY TO VALUE
; MEMSET(ADDR, SIZE, VALUE)
; With optimizations from Peter Ferrie
;
//
// SET MEMORY TO VALUE
// MEMSET(ADDR, SIZE, VALUE)
// With optimizations from Peter Ferrie
//
asm memset
LDY #$00
LDA ESTKL+2,X
@ -212,10 +212,10 @@ SETMEX INX
INX
RTS
end
;
; COPY MEMORY
; MEMCPY(DSTADDR, SRCADDR, SIZE)
;
//
// COPY MEMORY
// MEMCPY(DSTADDR, SRCADDR, SIZE)
//
asm memcpy
INX
INX
@ -285,11 +285,11 @@ REVCPYLP LDA (SRC),Y
BNE REVCPYLP
CPYMEX RTS
end
;
; COPY FROM MAIN MEM TO AUX MEM.
;
; MEMXCPY(DST, SRC, SIZE)
;
//
// COPY FROM MAIN MEM TO AUX MEM.
//
// MEMXCPY(DST, SRC, SIZE)
//
asm memxcpy
LDA ESTKL+1,X
STA $3C
@ -318,12 +318,12 @@ asm crout
DEX
LDA #$8D
STA ESTKL,X
; FALL THROUGH TO COUT
// FALL THROUGH TO COUT
end
;
; CHAR OUT
; COUT(CHAR)
;
//
// CHAR OUT
// COUT(CHAR)
//
asm cout
LDA ESTKL,X
BIT $BF98
@ -335,10 +335,10 @@ asm cout
BIT LCRDEN+LCBNK2
RTS
end
;
; CHAR IN
; RDKEY()
;
//
// CHAR IN
// RDKEY()
//
asm cin
BIT ROMEN
JSR $FD0C
@ -349,10 +349,10 @@ asm cin
STY ESTKH,X
RTS
end
;
; PRINT STRING
; PRSTR(STR)
;
//
// PRINT STRING
// PRSTR(STR)
//
asm prstr
LDY #$00
LDA ESTKL,X
@ -375,9 +375,9 @@ asm prstr
BIT LCRDEN+LCBNK2
++ RTS
end
;
; PRINT BYTE
;
//
// PRINT BYTE
//
asm prbyte
LDA ESTKL,X
STX ESP
@ -387,9 +387,9 @@ asm prbyte
BIT LCRDEN+LCBNK2
RTS
end
;
; PRINT WORD
;
//
// PRINT WORD
//
asm prword
STX ESP
TXA
@ -402,10 +402,10 @@ asm prword
BIT LCRDEN+LCBNK2
RTS
end
;
; READ STRING
; STR = RDSTR(PROMPTCHAR)
;
//
// READ STRING
// STR = RDSTR(PROMPTCHAR)
//
asm rdstr
LDA ESTKL,X
STA $33
@ -476,23 +476,23 @@ asm uword_islt
INX
RTS
end
;
; Utility routines.
;
; A DCI string is one that has the high bit set for every character except the last.
; More efficient than C or Pascal strings.
;
;def dcitos(dci, str)
; byte len, c
; len = 0
; repeat
; c = (dci).[len]
; len = len + 1
; (str).[len] = c & $7F
; until !(c & $80)
; ^str = len
; return len
;end
//
// Utility routines.
//
// A DCI string is one that has the high bit set for every character except the last.
// More efficient than C or Pascal strings.
//
//def dcitos(dci, str)
// byte len, c
// len = 0
// repeat
// c = (dci).[len]
// len = len + 1
// (str).[len] = c & $7F
// until !(c & $80)
// ^str = len
// return len
//end
asm dcitos
LDA ESTKL,X
STA DSTL
@ -517,22 +517,22 @@ asm dcitos
STY ESTKH,X
RTS
end
;def stodci(str, dci)
; byte len, c
; len = ^str
; if len == 0
; return
; fin
; c = toupper((str).[len]) & $7F
; len = len - 1
; (dci).[len] = c
; while len
; c = toupper((str).[len]) | $80
; len = len - 1
; (dci).[len] = c
; loop
; return ^str
;end
//def stodci(str, dci)
// byte len, c
// len = ^str
// if len == 0
// return
// fin
// c = toupper((str).[len]) & $7F
// len = len - 1
// (dci).[len] = c
// while len
// c = toupper((str).[len]) | $80
// len = len - 1
// (dci).[len] = c
// loop
// return ^str
//end
asm stodci
LDA ESTKL,X
STA DSTL
@ -572,22 +572,22 @@ TOUPR AND #$7F
+ STA ESTKL,X
RTS
end
;
; Module symbols are entered into the symbol table
; pre-pended with a '#' to differentiate them
; from normal symbols.
;
;def modtosym(mod, dci)
; byte len, c
; (dci).0 = '#'|$80
; len = 0
; repeat
; c = (mod).[len]
; len = len + 1
; (dci).[len] = c
; until !(c & $80)
; return dci
;end
//
// Module symbols are entered into the symbol table
// pre-pended with a '#' to differentiate them
// from normal symbols.
//
//def modtosym(mod, dci)
// byte len, c
// (dci).0 = '#'|$80
// len = 0
// repeat
// c = (mod).[len]
// len = len + 1
// (dci).[len] = c
// until !(c & $80)
// return dci
//end
asm modtosym
LDA ESTKL+1,X
STA SRCL
@ -609,26 +609,26 @@ asm modtosym
BCS -
RTS
end
;
; Lookup routines.
;
;def lookuptbl(dci, tbl)
; word match
; while ^tbl
; match = dci
; while ^tbl == ^match
; if !(^tbl & $80)
; return (tbl):1
; fin
; tbl = tbl + 1
; match = match + 1
; loop
; while (^tbl & $80)
; tbl = tbl + 1
; loop
; tbl = tbl + 3
; loop
; return 0
//
// Lookup routines.
//
//def lookuptbl(dci, tbl)
// word match
// while ^tbl
// match = dci
// while ^tbl == ^match
// if !(^tbl & $80)
// return (tbl):1
// fin
// tbl = tbl + 1
// match = match + 1
// loop
// while (^tbl & $80)
// tbl = tbl + 1
// loop
// tbl = tbl + 3
// loop
// return 0
asm lookuptbl
LDA ESTKL,X
STA DSTL
@ -670,9 +670,9 @@ asm lookuptbl
INC DSTH
BCS -
end
;
; ProDOS routines
;
//
// ProDOS routines
//
def getpfx(path)
byte params[3]
@ -719,9 +719,9 @@ def read(refnum, buff, len)
perr = syscall($CA, @params)
return params:6
end
;
; Heap routines.
;
//
// Heap routines.
//
def availheap
byte fp
return @fp - heap
@ -761,11 +761,11 @@ def allocalignheap(size, pow2, freeaddr)
return addr
end
def markheap
return heap;
return heap//
end
def releaseheap(newheap)
heap = newheap;
return @newheap - heap;
heap = newheap//
return @newheap - heap//
end
def allocxheap(size)
word xaddr
@ -800,9 +800,9 @@ def allocxheap(size)
fin
return xaddr
end
;
; Symbol table routines.
;
//
// Symbol table routines.
//
def lookupsym(sym)
return lookuptbl(sym, symtbl)
end
@ -817,9 +817,9 @@ def addsym(sym, addr)
lastsym = lastsym + 3
^lastsym = 0
end
;
; Module routines.
;
//
// Module routines.
//
def lookupmod(mod)
byte dci[17]
return lookuptbl(modtosym(mod, @dci), symtbl)
@ -858,13 +858,13 @@ def adddef(bank, addr, deflast)
defentry = *deflast
*deflast = defentry + 5
if bank
defentry=>1 = $03DC ; JSR $03DC (AUX MEM INTERP)
defentry=>1 = $03DC // JSR $03DC (AUX MEM INTERP)
else
defentry=>1 = $03D6 ; JSR $03D6 (MAIN MEM INTERP)
defentry=>1 = $03D6 // JSR $03D6 (MAIN MEM INTERP)
fin
defentry->0 = $20
defentry=>3 = addr
defentry->5 = 0 ; NULL out next entry
defentry->5 = 0 // NULL out next entry
return defentry
end
def lookupdef(addr, deftbl)
@ -883,9 +883,9 @@ def loadmod(mod)
word moddep, rld, esd, sym
byte defbank, str[16], filename[64]
byte header[128]
;
; Read the RELocatable module header (first 128 bytes)
;
//
// Read the RELocatable module header (first 128 bytes)
//
dcitos(mod, @filename)
refnum = open(@filename, iobuffer)
if refnum > 0
@ -894,18 +894,18 @@ def loadmod(mod)
moddep = @header.1
defofst = modsize
init = 0
if rdlen > 4 and header:2 == $DA7E ; DAVE = magic number :-)
;
; This is an EXTended RELocatable (data+bytecode) module.
;
if rdlen > 4 and header:2 == $DA7E // DAVE = magic number :-)
//
// This is an EXTended RELocatable (data+bytecode) module.
//
systemflags = header:4 | systemflags
defofst = header:6
defcnt = header:8
init = header:10
moddep = @header.12
;
; Load module dependencies.
;
//
// Load module dependencies.
//
while ^moddep
if !lookupmod(moddep)
close(refnum)
@ -916,57 +916,57 @@ def loadmod(mod)
fin
moddep = moddep + dcitos(moddep, @str)
loop
;
; Init def table.
;
//
// Init def table.
//
deftbl = allocheap(defcnt * 5 + 1)
deflast = deftbl
^deflast = 0
if !refnum
;
; Reset read pointer.
;
//
// Reset read pointer.
//
refnum = open(@filename, iobuffer)
rdlen = read(refnum, @header, 128)
fin
fin
;
; Alloc heap space for relocated module (data + bytecode).
;
//
// Alloc heap space for relocated module (data + bytecode).
//
moddep = moddep + 1
modfix = moddep - @header.2 ; Adjust to skip header
modfix = moddep - @header.2 // Adjust to skip header
modsize = modsize - modfix
rdlen = rdlen - modfix - 2
modaddr = allocheap(modsize)
memcpy(modaddr, moddep, rdlen)
;
; Read in remainder of module into memory for fixups.
;
addr = modaddr;
//
// Read in remainder of module into memory for fixups.
//
addr = modaddr//
repeat
addr = addr + rdlen
rdlen = read(refnum, addr, 4096)
until rdlen <= 0
close(refnum)
;
; Add module to symbol table.
;
//
// Add module to symbol table.
//
addmod(mod, modaddr)
;
; Apply all fixups and symbol import/export.
;
//
// Apply all fixups and symbol import/export.
//
modfix = modaddr - modfix
bytecode = defofst + modfix - MODADDR
modend = modaddr + modsize
rld = modend ; Re-Locatable Directory
esd = rld ; Extern+Entry Symbol Directory
while ^esd ; Scan to end of ESD
rld = modend // Re-Locatable Directory
esd = rld // Extern+Entry Symbol Directory
while ^esd // Scan to end of ESD
esd = esd + 4
loop
esd = esd + 1
;
; Locate bytecode defs in appropriate bank.
;
//
// Locate bytecode defs in appropriate bank.
//
if ^MACHID & $30 == $30
defbank = 1
defaddr = allocxheap(rld - bytecode)
@ -975,58 +975,58 @@ def loadmod(mod)
defbank = 0
defaddr = bytecode
fin
;
; Run through the Re-Location Dictionary.
;
//
// Run through the Re-Location Dictionary.
//
while ^rld
if ^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.
//
adddef(defbank, rld=>1 - defofst + defaddr, @deflast)
else
addr = rld=>1 + modfix
if uword_isge(addr, modaddr) ; Skip fixups to header
if ^rld & $80 ; WORD sized fixup.
if uword_isge(addr, modaddr) // Skip fixups to header
if ^rld & $80 // WORD sized fixup.
fixup = *addr
else ; BYTE sized fixup.
else // BYTE sized fixup.
fixup = ^addr
fin
if ^rld & $10 ; EXTERN reference.
if ^rld & $10 // EXTERN reference.
fixup = fixup + lookupextern(esd, rld->3)
else ; INTERN fixup.
else // INTERN fixup.
fixup = fixup + modfix - MODADDR
if uword_isge(fixup, bytecode)
;
; Bytecode address - replace with call def directory.
;
//
// Bytecode address - replace with call def directory.
//
fixup = lookupdef(fixup - bytecode + defaddr, deftbl)
fin
fin
if ^rld & $80 ; WORD sized fixup.
if ^rld & $80 // WORD sized fixup.
*addr = fixup
else ; BYTE sized fixup.
else // BYTE sized fixup.
^addr = fixup
fin
fin
fin
rld = rld + 4
loop
;
; Run through the External/Entry Symbol Directory.
;
//
// Run through the External/Entry Symbol Directory.
//
while ^esd
sym = esd
esd = esd + dcitos(esd, @str)
if ^esd & $08
;
; EXPORT symbol - add it to the global symbol table.
;
//
// EXPORT symbol - add it to the global symbol table.
//
addr = esd=>1 + modfix - MODADDR
if uword_isge(addr, bytecode)
;
; Use the def directory address for bytecode.
;
//
// Use the def directory address for bytecode.
//
addr = lookupdef(addr - bytecode + defaddr, deftbl)
fin
addsym(sym, addr)
@ -1034,18 +1034,18 @@ def loadmod(mod)
esd = esd + 3
loop
if defbank
;
; Move bytecode to AUX bank.
;
//
// Move bytecode to AUX bank.
//
memxcpy(defaddr, bytecode, modsize - (bytecode - modaddr))
fin
fin
if perr
return -perr
fin
;
; Call init routine if it exists.
;
//
// Call init routine if it exists.
//
if init
fixup = adddef(defbank, init - defofst + defaddr, @deflast)()
if defbank
@ -1056,15 +1056,15 @@ def loadmod(mod)
else
fixup = 0
fin
;
; Free up the end-of-module in main memory.
;
//
// Free up the end-of-module in main memory.
//
releaseheap(modend)
return fixup
end
;
; Command mode
;
//
// Command mode
//
def volumes
byte params[4]
word strbuf
@ -1120,7 +1120,7 @@ def catalog(optpath)
len = type & $0F
^entry = len
prstr(entry)
if type & $F0 == $D0 ; Is it a directory?
if type & $F0 == $D0 // Is it a directory?
cout('/')
len = len + 1
elsif entry->$10 == $FF
@ -1186,14 +1186,14 @@ def parsecmd(strptr)
return cmd
end
def resetmemfiles
;
; Close all files
;
//
// Close all files
//
^$BFD8 = 0
close(0)
;
; Set memory bitmap
;
//
// Set memory bitmap
//
memset($BF58, 24, 0)
^$BF58 = $CF
^$BF6F = $01
@ -1240,13 +1240,13 @@ def execmod(modfile)
heap = saveheap
fin
end
;
; Get heap start.
;
//
// Get heap start.
//
heap = *freemem
;
; Init symbol table.
;
//
// Init symbol table.
//
stodci(@stdlibstr, heap)
addmod(heap, @version)
while *stdlibsym
@ -1254,15 +1254,15 @@ while *stdlibsym
addsym(heap, stdlibsym=>2)
stdlibsym = stdlibsym + 4
loop
;
; Try to run autorun module.
;
//
// Try to run autorun module.
//
resetmemfiles()
execmod(@autorun)
perr = 0
;
; Print some startup info.
;
//
// Print some startup info.
//
prstr(@verstr)
prbyte(version.1)
cout('.')

View File

@ -4,7 +4,7 @@
#include "tokens.h"
#include "symbols.h"
char *statement, *scanpos, *tokenstr;
char *statement, *tokenstr, *scanpos = "";
t_token scantoken, prevtoken;
int tokenlen;
long constval;
@ -22,28 +22,28 @@ t_token keywords[] = {
ENDCASE_TOKEN, 'W', 'E', 'N', 'D',
FOR_TOKEN, 'F', 'O', 'R',
TO_TOKEN, 'T', 'O',
DOWNTO_TOKEN, 'D', 'O', 'W', 'N', 'T', 'O',
DOWNTO_TOKEN, 'D', 'O', 'W', 'N', 'T', 'O',
STEP_TOKEN, 'S', 'T', 'E', 'P',
NEXT_TOKEN, 'N', 'E', 'X', 'T',
REPEAT_TOKEN, 'R', 'E', 'P', 'E', 'A', 'T',
UNTIL_TOKEN, 'U', 'N', 'T', 'I', 'L',
BREAK_TOKEN, 'B', 'R', 'E', 'A', 'K',
UNTIL_TOKEN, 'U', 'N', 'T', 'I', 'L',
BREAK_TOKEN, 'B', 'R', 'E', 'A', 'K',
ASM_TOKEN, 'A', 'S', 'M',
DEF_TOKEN, 'D', 'E', 'F',
EXPORT_TOKEN, 'E', 'X', 'P', 'O', 'R', 'T',
IMPORT_TOKEN, 'I', 'M', 'P', 'O', 'R', 'T',
EXPORT_TOKEN, 'E', 'X', 'P', 'O', 'R', 'T',
IMPORT_TOKEN, 'I', 'M', 'P', 'O', 'R', 'T',
RETURN_TOKEN, 'R', 'E', 'T', 'U', 'R', 'N',
END_TOKEN, 'E', 'N', 'D',
EXIT_TOKEN, 'E', 'X', 'I', 'T',
DONE_TOKEN, 'D', 'O', 'N', 'E',
LOGIC_NOT_TOKEN, 'N', 'O', 'T',
LOGIC_AND_TOKEN, 'A', 'N', 'D',
LOGIC_OR_TOKEN, 'O', 'R',
LOGIC_OR_TOKEN, 'O', 'R',
BYTE_TOKEN, 'B', 'Y', 'T', 'E',
WORD_TOKEN, 'W', 'O', 'R', 'D',
CONST_TOKEN, 'C', 'O', 'N', 'S', 'T',
PREDEF_TOKEN, 'P', 'R', 'E', 'D', 'E', 'F',
SYSFLAGS_TOKEN, 'S', 'Y', 'S', 'F', 'L', 'A', 'G', 'S',
SYSFLAGS_TOKEN, 'S', 'Y', 'S', 'F', 'L', 'A', 'G', 'S',
EOL_TOKEN
};
@ -333,6 +333,15 @@ t_token scan(void)
scanpos++;
}
break;
case '/':
if (scanpos[1] == '/')
scantoken = EOL_TOKEN;
else
{
scantoken = DIV_TOKEN;
scanpos++;
}
break;
default:
/*
* Simple single character tokens.
@ -363,12 +372,21 @@ int scan_lookahead(void)
char inputline[512];
int next_line(void)
{
gets(inputline);
lineno++;
statement = inputline;
scanpos = inputline;
scantoken = EOL_TOKEN;
scan();
printf("; %03d: %s\n", lineno, inputline);
if (*scanpos == ';')
{
statement = ++scanpos;
scantoken = EOL_TOKEN;
scan();
}
else
{
gets(inputline);
lineno++;
statement = inputline;
scanpos = inputline;
scantoken = EOL_TOKEN;
scan();
printf("; %03d: %s\n", lineno, inputline);
}
return (1);
}

View File

@ -6,9 +6,9 @@ import stdlib
predef isugt, isuge, isult, isule
predef load, exec
word MACHID, sysvars
;
; System flags: memory allocator screen holes.
;
//
// System flags: memory allocator screen holes.
//
const restxt1 = $0001
const restxt2 = $0002
const reshgr1 = $0004

View File

@ -1,13 +1,13 @@
;
; Include all imported modules and their data/functions.
;
//
// Include all imported modules and their data/functions.
//
include(stdlib.plh)
include(testlib.plh)
;
; Declare all global variables for this module.
;
//
// Declare all global variables for this module.
//
byte hello[] = "Hello, Apple "
byte a1[] = "1"
@ -20,9 +20,9 @@ word struct[] = 1, 10, 100, 1000, 10000
word ptr
byte spaces[] = " "
;
; Define functions.
;
//
// Define functions.
//
def tens(start)
word i

View File

@ -1,21 +1,21 @@
;
; Include all imported modules and their data/functions.
;
//
// Include all imported modules and their data/functions.
//
include(stdlib.plh)
;
; Module data.
;
//
// Module data.
//
predef puti, puth, putln
export word print[] = @puti, @puth, @putln, @puts, @putc
byte valstr[] = '0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'
byte loadstr[] = "testlib loaded!"
;
; Define functions.
;
//
// Define functions.
//
def puth(h)
putc('$')
@ -26,10 +26,7 @@ def puth(h)
end
export def puti(i)
if i < 0
putc('-')
i = -i
fin
if i < 0; putc('-'); i = -i; fin
if i < 10
putc(i + '0')
else