Add sysflags to language parser

This commit is contained in:
David Schmenk
2014-05-18 22:31:13 -07:00
parent 1c05c27678
commit 96cb23ed57
10 changed files with 203 additions and 138 deletions

View File

@@ -12,7 +12,7 @@ const xreg = 1
const yreg = 2
const preg = 3
;
; Memory allocator screen holes.
; System flags: memory allocator screen holes.
;
const restxt1 = $0001
const restxt2 = $0002
@@ -93,7 +93,7 @@ byte prefix[32] = ""
word heapsttart, heap
word lastsym = symtbl
word xheap = $0400
word sysflags = 0
word systemflags = 0
word perr
word cmdptr
;
@@ -882,13 +882,13 @@ def allocheap(size)
word addr
addr = heap
heap = heap + size
if sysflags & reshgr1
if systemflags & reshgr1
if uword_isle(addr, $4000) and uword_isgt(heap, $2000)
addr = $4000
heap = addr + size
fin
fin
if sysflags & reshgr2
if systemflags & reshgr2
if uword_isle(addr, $6000) and uword_isgt(heap, $4000)
addr = $6000
heap = addr + size
@@ -926,25 +926,25 @@ def allocxheap(size)
word xaddr
xaddr = xheap
xheap = xheap + size
if sysflags & restxt1
if systemflags & restxt1
if uword_isle(xaddr, $0800) and uword_isgt(xheap, $0400)
xaddr = $0800
xheap = xaddr + size
fin
fin
if sysflags & restxt2
if systemflags & restxt2
if uword_isle(xaddr, $0C00) and uword_isgt(xheap, $0800)
xaddr = $0C00
xheap = xaddr + size
fin
fin
if sysflags & resxhgr1
if systemflags & resxhgr1
if uword_isle(xaddr, $4000) and uword_isgt(xheap, $2000)
xaddr = $4000
xheap = xaddr + size
fin
fin
if sysflags & resxhgr2
if systemflags & resxhgr2
if uword_isle(xaddr, $6000) and uword_isgt(xheap, $4000)
xaddr = $6000
xheap = xaddr + size
@@ -1067,7 +1067,7 @@ def loadmod(mod)
;
; This is an EXTended RELocatable (data+bytecode) module.
;
sysflags = header:4 | sysflags
systemflags = header:4 | systemflags
defofst = header:6
defcnt = header:8
init = header:10
@@ -1385,10 +1385,10 @@ def execmod(modfile)
saveheap = heap
savexheap = xheap
savesym = lastsym
saveflags = sysflags
saveflags = systemflags
^lastsym = 0
perr = loadmod(@moddci)
sysflags = saveflags
systemflags = saveflags
lastsym = savesym
xheap = savexheap
heap = saveheap

View File

@@ -245,6 +245,7 @@ int fixup_new(int tag, int type, int size)
*/
#define BYTECODE_SEG 8
#define INIT 16
#define SYSFLAGS 32
static int outflags = 0;
static char *DB = ".BYTE";
static char *DW = ".WORD";
@@ -312,7 +313,7 @@ void emit_header(void)
printf("_SEGBEGIN%c\n", LBL);
printf("\t%s\t_SEGEND-_SEGBEGIN\t; LENGTH OF HEADER + CODE/DATA + BYTECODE SEGMENT\n", DW);
printf("\t%s\t$DA7E\t\t\t; MAGIC #\n", DW);
printf("\t%s\t0\t\t\t; SYSTEM FLAGS\n", DW);
printf("\t%s\t_SYSFLAGS\t\t\t; SYSTEM FLAGS\n", DW);
printf("\t%s\t_SUBSEG\t\t\t; BYTECODE SUB-SEGMENT\n", DW);
printf("\t%s\t_DEFCNT\t\t\t; BYTECODE DEF COUNT\n", DW);
printf("\t%s\t_INIT\t\t\t; MODULE INITIALIZATION ROUTINE\n", DW);
@@ -385,6 +386,8 @@ void emit_trailer(void)
emit_bytecode_seg();
if (!(outflags & INIT))
printf("_INIT\t=\t0\n");
if (!(outflags & SYSFLAGS))
printf("_SYSFLAGS\t=\t0\n");
if (outflags & MODULE)
{
printf("_DEFCNT\t=\t%d\n", defs);
@@ -400,6 +403,11 @@ void emit_moddep(char *name, int len)
else
printf("\t%s\t$00\t\t\t; END OF MODULE DEPENDENCIES\n", DB);
}
void emit_sysflags(int val)
{
printf("_SYSFLAGS\t=\t$%04X\t\t; SYSTEM FLAGS\n", val);
outflags |= SYSFLAGS;
}
void emit_bytecode_seg(void)
{
if ((outflags & MODULE) && !(outflags & BYTECODE_SEG))

View File

@@ -4,6 +4,7 @@ void emit_flags(int flags);
void emit_header(void);
void emit_trailer(void);
void emit_moddep(char *name, int len);
void emit_sysflags(int val);
void emit_bytecode_seg(void);
void emit_comment(char *s);
void emit_asm(char *s);

21
PLASMA/src/hgr1.pla Normal file
View File

@@ -0,0 +1,21 @@
import STDLIB
predef memset
;
; System flags: memory allocator screen holes.
;
const restxt1 = $0001
const restxt2 = $0002
const reshgr1 = $0004
const reshgr2 = $0008
const resxhgr1 = $0010
const resxhgr2 = $0020
end
sysflags reshgr1 ; Reserve HGR page 1
memset($2000, $2000, 0) ; Clear HGR page 1
^$C054
^$C052
^$C057
^$C050
done

16
PLASMA/src/hgr1test.pla Normal file
View File

@@ -0,0 +1,16 @@
import STDLIB
predef memset, memcpy, cin
end
import HGR1
end
byte i = 0
word hcolor[] = $0000, $552A, $2A55, $7F7F, $8080, $D5AA, $AAD5, $FFFF
repeat
memset($2000, $2000, hcolor[i])
i = (i + 1) & 7
until ^$C000 >= 128
^$C010
^$C054
^$C051
done

View File

@@ -34,7 +34,6 @@ t_token keywords[] = {
IMPORT_TOKEN, 'I', 'M', 'P', 'O', 'R', 'T',
RETURN_TOKEN, 'R', 'E', 'T', 'U', 'R', 'N',
END_TOKEN, 'E', 'N', 'D',
START_TOKEN, 'S', 'T', 'A', 'R', 'T',
EXIT_TOKEN, 'E', 'X', 'I', 'T',
DONE_TOKEN, 'D', 'O', 'N', 'E',
LOGIC_NOT_TOKEN, 'N', 'O', 'T',
@@ -44,6 +43,7 @@ t_token keywords[] = {
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',
EOL_TOKEN
};

View File

@@ -65,3 +65,9 @@ hello: hello.pla $(PLVM) $(PLASM)
ROD.REL: rod.pla $(PLVM) $(PLASM)
./$(PLASM) -AM < rod.pla > rod.a
acme --setpc 4096 -o ROD.REL rod.a
HGR1: hgr1.pla hgr1test.pla $(PLVM) $(PLASM)
./$(PLASM) -AM < hgr1test.pla > hgr1test.a
acme --setpc 4096 -o HGR1TEST.REL hgr1test.a
./$(PLASM) -AM < hgr1.pla > hgr1.a
acme --setpc 4096 -o HGR1 hgr1.a

View File

@@ -1024,6 +1024,19 @@ int parse_vars(int type)
switch (scantoken)
{
case SYSFLAGS_TOKEN:
if (type & (EXTERN_TYPE | LOCAL_TYPE))
{
parse_error("sysflags must be global");
return (0);
}
if (!parse_constexpr(&value, &size))
{
parse_error("Bad constant");
return (0);
}
emit_sysflags(value);
break;
case CONST_TOKEN:
if (scan() != ID_TOKEN)
{
@@ -1113,7 +1126,7 @@ int parse_vars(int type)
}
return (1);
}
int parse_imps(void)
int parse_mods(void)
{
if (scantoken == IMPORT_TOKEN)
{
@@ -1306,7 +1319,7 @@ int parse_module(void)
emit_header();
if (next_line())
{
while (parse_imps()) next_line();
while (parse_mods()) next_line();
while (parse_vars(GLOBAL_TYPE)) next_line();
while (parse_defs()) next_line();
if (scantoken != DONE_TOKEN && scantoken != EOF_TOKEN)

View File

@@ -41,7 +41,7 @@
#define DONE_TOKEN TOKEN(27)
#define RETURN_TOKEN TOKEN(28)
#define BREAK_TOKEN TOKEN(29)
#define START_TOKEN TOKEN(30)
#define SYSFLAGS_TOKEN TOKEN(30)
#define EXIT_TOKEN TOKEN(31)
#define EVAL_TOKEN TOKEN(32)
/*