1
0
mirror of https://github.com/dschmenk/PLASMA.git synced 2025-08-14 02:26:10 +00:00

Basic, working PLASM

This commit is contained in:
David Schmenk
2018-01-05 22:29:03 -08:00
parent b0847c1166
commit 7593879455
5 changed files with 56 additions and 40 deletions

View File

@@ -169,7 +169,7 @@ $(ROD): samplesrc/rod.pla $(PLVM02) $(PLASM)
acme --setpc 4094 -o $(ROD) samplesrc/rod.a acme --setpc 4094 -o $(ROD) samplesrc/rod.a
$(SIEVE): samplesrc/sieve.pla $(PLVM02) $(PLASM) $(SIEVE): samplesrc/sieve.pla $(PLVM02) $(PLASM)
./$(PLASM) -AMOW < samplesrc/sieve.pla > samplesrc/sieve.a ./$(PLASM) -AMW < samplesrc/sieve.pla > samplesrc/sieve.a
acme --setpc 4094 -o $(SIEVE) samplesrc/sieve.a acme --setpc 4094 -o $(SIEVE) samplesrc/sieve.a
$(UTHERNET): libsrc/uthernet.pla $(PLVM02) $(PLASM) $(UTHERNET): libsrc/uthernet.pla $(PLVM02) $(PLASM)

View File

@@ -1,4 +1,7 @@
include "inc/cmdsys.plh" include "inc/cmdsys.plh"
puts("Hello, world.\n") repeat
puts("Hello, world.\n")
until ^$C000 < 128
^$C010
done done

View File

@@ -107,9 +107,9 @@ end
def emit_reladdr(tag)#0 def emit_reladdr(tag)#0
word updtptr word updtptr
if not tag_type->[tag] & RELATIVE_FIXUP; puts("Not relative tag fixup"); exit_err(0); fin // DEBUG if not (tag_type->[tag] & RELATIVE_FIXUP); puts("Not relative tag fixup"); exit_err(0); fin // DEBUG
if tag_type->[tag] & RESOLVED_FIXUP if tag_type->[tag] & RESOLVED_FIXUP
updtptr = codeptr - tag_addr=>[tag] updtptr = tag_addr=>[tag] - codeptr
else else
// //
// Add to list of tags needing resolution // Add to list of tags needing resolution
@@ -221,14 +221,13 @@ def emit_enter(cparms)#0
fin fin
end end
def emit_tag(tag)#0 def emit_tag(tag)#0
word codeofst, fixups, updtptr, nextptr word fixups, updtptr, nextptr
emit_pending_seq emit_pending_seq
if tag_type->[tag] & RESOLVED_FIXUP; puts("Tag already resolved"); exit_err(0); fin // DEBUG if tag_type->[tag] & RESOLVED_FIXUP; puts("Tag already resolved"); exit_err(0); fin // DEBUG
// //
// Update list of addresses needing resolution // Update list of addresses needing resolution
// //
codeofst = codeptr - codebuff
if tag_type->[tag] & RELATIVE_FIXUP if tag_type->[tag] & RELATIVE_FIXUP
updtptr = tag_addr=>[tag] updtptr = tag_addr=>[tag]
while updtptr while updtptr
@@ -238,13 +237,13 @@ def emit_tag(tag)#0
loop loop
else else
for fixups = fixup_cnt-1 downto 0 for fixups = fixup_cnt-1 downto 0
if fixup_tag->[fixups] == tag if fixup_tag=>[fixups] == tag
updtptr = fixup_addr=>[fixups] updtptr = fixup_addr=>[fixups]
*updtptr = *updtptr + codeofst *updtptr = *updtptr + codeptr - codebuff
fin fin
next next
fin fin
tag_addr=>[tag] = codeofst tag_addr=>[tag] = codeptr
tag_type->[tag] = tag_type->[tag] | RESOLVED_FIXUP tag_type->[tag] = tag_type->[tag] | RESOLVED_FIXUP
end end
// //
@@ -363,7 +362,7 @@ def emit_seq(seq)#0
// We must also force output if the sequence includes a CS opcode, as the // We must also force output if the sequence includes a CS opcode, as the
// associated 'constant' is only temporarily valid. // associated 'constant' is only temporarily valid.
// //
if not (outflags & (OPTIMIZE|OPTIMIZE2)) or (outflags & NO_COMBINE) or string if (not (outflags & (OPTIMIZE|OPTIMIZE2))) or (outflags & NO_COMBINE) or string
emit_pending_seq emit_pending_seq
fin fin
end end
@@ -423,14 +422,19 @@ def lookup_idglobal(nameptr, len)
end end
def add_iddata(namestr, len, type, size)#0 def add_iddata(namestr, len, type, size)#0
if idmatch(namestr, len, idglobal_tbl, globals); exit_err(ERR_DUP|ERR_ID); fin if idmatch(namestr, len, idglobal_tbl, globals); exit_err(ERR_DUP|ERR_ID); fin
lastglobal=>idval = datasize
lastglobal=>idtype = type
nametostr(namestr, len, lastglobal + idname) nametostr(namestr, len, lastglobal + idname)
emit_fill(size) lastglobal=>idtype = type
if type & EXTERN_TYPE
lastglobal=>idval = new_tag(EXTERN_FIXUP|WORD_FIXUP)//datasize
else
lastglobal=>idval = new_tag(WORD_FIXUP)//datasize
emit_tag(lastglobal=>idval)
emit_fill(size)
datasize = datasize + size
fin
globals++ globals++
lastglobal = lastglobal + t_id + len lastglobal = lastglobal + t_id + len
if lastglobal - idglobal_tbl > IDGLOBALSZ; exit_err(ERR_OVER|ERR_GLOBAL|ERR_ID|ERR_TABLE); fin if lastglobal - idglobal_tbl > IDGLOBALSZ; exit_err(ERR_OVER|ERR_GLOBAL|ERR_ID|ERR_TABLE); fin
datasize = datasize + size
end end
def size_iddata(type, varsize, initsize)#0 def size_iddata(type, varsize, initsize)#0
if varsize > initsize if varsize > initsize
@@ -462,7 +466,7 @@ def set_idfunc(namestr, len, tag, cparms, cvals)#0
idptr = lookup_idglobal(namestr, len) idptr = lookup_idglobal(namestr, len)
if idptr if idptr
if not idptr=>idtype & FUNC_TYPE; exit_err(ERR_UNDECL|ERR_CODE); fin 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
@@ -484,6 +488,7 @@ def init_idglobal#0
codebuff = heapalloc(codebufsz) codebuff = heapalloc(codebufsz)
codeptr = codebuff codeptr = codebuff
lastglobal = idglobal_tbl lastglobal = idglobal_tbl
puts("Data+Code buffer size = "); puti(codebufsz); putln
// //
//Init free op sequence list //Init free op sequence list
// //
@@ -653,7 +658,7 @@ def gen_ctag(seq, tag)
op=>optag = tag op=>optag = tag
return seq return seq
end end
def gen_uop(tkn, seq) def gen_uop(seq, tkn)
byte code byte code
word op word op
@@ -688,7 +693,7 @@ def gen_uop(tkn, seq)
op->opgroup = STACK_GROUP op->opgroup = STACK_GROUP
return seq return seq
end end
def gen_bop(tkn, seq) def gen_bop(seq, tkn)
byte code byte code
word op word op
@@ -756,7 +761,7 @@ def dcitos(dci, str)
c = ^(dci + len) c = ^(dci + len)
len++ len++
^(str + len) = c & $7F ^(str + len) = c & $7F
until not c & $80 until not (c & $80)
^str = len ^str = len
return len return len
end end
@@ -787,8 +792,8 @@ def writeheader(refnum)
moddep = moddep + stodci(@moddep_tbl[moddep_cnt*16], moddep) moddep = moddep + stodci(@moddep_tbl[moddep_cnt*16], moddep)
loop loop
^moddep = 0 // Terminate dependency list ^moddep = 0 // Terminate dependency list
len = moddep - 2 - @header len = moddep - 1 - @header
modfix = len + MODADDR - codebuff modfix = len + MODADDR - codebuff // Convert generated address into module adress
header:0 = len + codeptr - codebuff // sizeof header+data+bytecode header:0 = len + codeptr - codebuff // sizeof header+data+bytecode
header:2 = $DA7F // Magic # header:2 = $DA7F // Magic #
header:4 = modsysflags // Module SYSFLAGS header:4 = modsysflags // Module SYSFLAGS
@@ -801,7 +806,7 @@ end
// //
// Write DeFinition Directory // Write DeFinition Directory
// //
def writeDFD(refnum, modofst)#0 def writeDFD(refnum, modfix)#0
word dfd, idptr, idcnt word dfd, idptr, idcnt
byte defdir[128] byte defdir[128]
@@ -809,7 +814,8 @@ def writeDFD(refnum, modofst)#0
while idcnt while idcnt
if idptr=>idtype & (FUNC_TYPE|EXTERN_TYPE) == FUNC_TYPE if idptr=>idtype & (FUNC_TYPE|EXTERN_TYPE) == FUNC_TYPE
dfd->0 = $02 dfd->0 = $02
dfd=>1 = tag_addr=>[idptr=>idval] + modofst dfd=>1 = tag_addr=>[idptr=>idval] + modfix
dfd->3 = 0
dfd = dfd + 4 dfd = dfd + 4
fin fin
idptr = idptr + idptr->idname + t_id idptr = idptr + idptr->idname + t_id
@@ -821,8 +827,8 @@ end
// Build External Symbol Directory on heap // Build External Symbol Directory on heap
// //
def buildESD(modfix)#2 def buildESD(modfix)#2
byte symnum
word modofst, esd, idptr, idcnt, len word modofst, esd, idptr, idcnt, len
byte symnum
symnum, esd, idptr, idcnt = 0, heapmark, idglobal_tbl, globals symnum, esd, idptr, idcnt = 0, heapmark, idglobal_tbl, globals
while idcnt while idcnt
@@ -834,7 +840,7 @@ def buildESD(modfix)#2
elsif idptr=>idtype & EXTACCESS_TYPE elsif idptr=>idtype & EXTACCESS_TYPE
esd = esd + stodci(@idptr->idname, esd) esd = esd + stodci(@idptr->idname, esd)
esd->0 = $10 esd->0 = $10
esd->1 = symnum esd=>1 = symnum
esd = esd + 3 esd = esd + 3
idptr->extnum = symnum idptr->extnum = symnum
symnum++ symnum++
@@ -850,16 +856,16 @@ end
// //
// Write ReLocation Directory // Write ReLocation Directory
// //
def writeRLD(refnum, modfix)#0 def writeRLD(refnum, modofst)#0
word rld, rldlen, fixups, updtptr, idptr, idcnt word rld, rldlen, fixups, updtptr, idptr, idcnt, tag
byte tag, type byte type
rld = heapmark rld = heapmark
rldlen = 0 rldlen = 0
for fixups = fixup_cnt-1 downto 0 for fixups = fixup_cnt-1 downto 0
tag = fixup_tag->[fixups] tag = fixup_tag=>[fixups]
type = tag_type->[tag] type = tag_type->[tag]
if not type & RELATIVE_FIXUP if not (type & RELATIVE_FIXUP)
if rldlen == 64 // Write out blocks of entries if rldlen == 64 // Write out blocks of entries
fileio:write(refnum, heapmark, rld - heapmark) fileio:write(refnum, heapmark, rld - heapmark)
rld = heapmark rld = heapmark
@@ -868,14 +874,17 @@ def writeRLD(refnum, modfix)#0
if type & EXTERN_FIXUP if type & EXTERN_FIXUP
idptr = idglobal_tbl idptr = idglobal_tbl
for idcnt = globals-1 downto 0 for idcnt = globals-1 downto 0
if idptr=>idtype & EXTERN_TYPE and idptr=>idval == tag if (idptr=>idtype & EXTERN_TYPE) and (idptr=>idval == tag)
rld->3 = idptr->extnum rld->3 = idptr->extnum
break break
fin fin
idptr = idptr + idptr->idname + t_id
next next
else
rld->3 = 0
fin fin
rld->0 = $01 | (type & MASK_FIXUP) rld->0 = $01 | (type & MASK_FIXUP)
rld=>1 = fixup_addr=>[fixups] + modfix rld=>1 = fixup_addr=>[fixups] + modofst
rld = rld + 4 rld = rld + 4
rldlen++ rldlen++
fin fin
@@ -897,9 +906,9 @@ def writemodule(refnum)#0
// Adjust internal fixups for header size // Adjust internal fixups for header size
// //
for fixups = fixup_cnt-1 downto 0 for fixups = fixup_cnt-1 downto 0
if not tag_type->[fixup_tag->[fixups]] & (EXTERN_FIXUP|RELATIVE_FIXUP) if not (tag_type->[fixup_tag=>[fixups]] & (EXTERN_FIXUP|RELATIVE_FIXUP))
updtptr = fixup_addr=>[fixups] updtptr = fixup_addr=>[fixups]
*updtptr = *updtptr + modofst *updtptr = *updtptr + modfix
fin fin
next next
// //
@@ -913,11 +922,11 @@ def writemodule(refnum)#0
// //
// Build EXERN/ENTRY directory // Build EXERN/ENTRY directory
// //
esd, esdlen = buildESD(modofst) esd, esdlen = buildESD(modfix)
// //
// Write relocation directory // Write relocation directory
// //
writeRLD(refnum, modfix) writeRLD(refnum, modofst)
// //
// Write EXTERN/EBTRY directory // Write EXTERN/EBTRY directory
// //

View File

@@ -218,7 +218,7 @@ def parse_list#2
repeat repeat
listseq, stackdepth = parse_expr(listseq) listseq, stackdepth = parse_expr(listseq)
listdepth = listdepth + stackdepth listdepth = listdepth + stackdepth
until not listseq or token <> COMMA_TKN until (not listseq) or (token <> COMMA_TKN)
return listseq, listdepth return listseq, listdepth
end end
def parse_value(codeseq, rvalue)#2 def parse_value(codeseq, rvalue)#2
@@ -493,7 +493,7 @@ def parse_expr(codeseq)#2
if token == bops_tbl[i] if token == bops_tbl[i]
matchop = 2 matchop = 2
if bops_prec[i] >= tos_op_prec(optos) if bops_prec[i] >= tos_op_prec(optos)
codeseq = gen_op(codeseq, pop_op) codeseq = gen_bop(codeseq, pop_op)
stackdepth-- stackdepth--
fin fin
push_op(token, bops_prec[i]) push_op(token, bops_prec[i])
@@ -504,7 +504,7 @@ def parse_expr(codeseq)#2
until matchop <> 2 until matchop <> 2
if matchop == 0 and prevmatch == 2; exit_err(ERR_SYNTAX); fin if matchop == 0 and prevmatch == 2; exit_err(ERR_SYNTAX); fin
while optos < opsp while optos < opsp
codeseq = gen_op(codeseq, pop_op) codeseq = gen_bop(codeseq, pop_op)
stackdepth-- stackdepth--
loop loop
// //
@@ -539,7 +539,7 @@ def parse_set(codeseq)
if not setseq[lparms]; break; fin if not setseq[lparms]; break; fin
lparms++ lparms++
until token <> COMMA_TKN until token <> COMMA_TKN
if not lparms or token <> SET_TKN if (not lparms) or (token <> SET_TKN)
// //
// Not a set list - free everything up // Not a set list - free everything up
// //
@@ -565,7 +565,7 @@ def parse_set(codeseq)
codeseq = gen_op(codeseq, DROP_CODE) codeseq = gen_op(codeseq, DROP_CODE)
next next
fin fin
for i = lparms downto 1 for i = lparms-1 downto 0
codeseq = cat_seq(codeseq, setseq[i]) codeseq = cat_seq(codeseq, setseq[i])
next next
return codeseq return codeseq

View File

@@ -340,6 +340,10 @@ const ERR_SYNTAX = $8000
// //
// Handy functions // Handy functions
// //
def puth(hex)#0
putc('$')
call($F941, hex >> 8, hex, 0, 0)
end
def strcpy(dst, src) def strcpy(dst, src)
if ^src if ^src
memcpy(dst, src, ^src + 1) memcpy(dst, src, ^src + 1)