1
0
mirror of https://github.com/dschmenk/PLASMA.git synced 2025-03-26 12:30:21 +00:00

On the road to 1.0

This commit is contained in:
dschmenk 2017-05-31 18:31:04 -07:00
parent 4543667a37
commit b19956b3ba
17 changed files with 2994 additions and 2396 deletions

82
src/makefile Normal file → Executable file
View File

@ -44,8 +44,8 @@ MEMMGR = MEMMGR\#FE1000
MEMTEST = MEMTEST\#FE1000 MEMTEST = MEMTEST\#FE1000
FIBER = FIBER\#FE1000 FIBER = FIBER\#FE1000
PLASM = plasm PLASM = plasm
INCS = toolsrc/tokens.h toolsrc/symbols.h toolsrc/lex.h toolsrc/parse.h toolsrc/codegen.h INCS = toolsrc/plasm.h toolsrc/tokens.h toolsrc/symbols.h toolsrc/lex.h toolsrc/parse.h toolsrc/codegen.h
OBJS = toolsrc/plasm.c toolsrc/parse.o toolsrc/lex.o toolsrc/codegen.o OBJS = toolsrc/plasm.c toolsrc/parse.c toolsrc/lex.c toolsrc/codegen.c
# #
# Image filetypes for Virtual ][ # Image filetypes for Virtual ][
# #
@ -83,20 +83,20 @@ $(PLVM): vmsrc/plvm.c
cc vmsrc/plvm.c -o $(PLVM) cc vmsrc/plvm.c -o $(PLVM)
vmsrc/a1cmd.a: vmsrc/a1cmd.pla $(PLASM) vmsrc/a1cmd.a: vmsrc/a1cmd.pla $(PLASM)
./$(PLASM) -A < vmsrc/a1cmd.pla > vmsrc/a1cmd.a ./$(PLASM) -AO < vmsrc/a1cmd.pla > vmsrc/a1cmd.a
$(PLVM01): vmsrc/plvm01.s vmsrc/a1cmd.a $(PLVM01): vmsrc/plvm01.s vmsrc/a1cmd.a
acme -o $(PLVM01) -l vmsrc/plvm01.sym vmsrc/plvm01.s acme -o $(PLVM01) -l vmsrc/plvm01.sym vmsrc/plvm01.s
$(CMD): vmsrc/cmd.pla vmsrc/cmdstub.s $(PLVM02) $(PLASM) $(CMD): vmsrc/cmd.pla vmsrc/cmdstub.s $(PLVM02) $(PLASM)
./$(PLASM) -A < vmsrc/cmd.pla > vmsrc/cmd.a ./$(PLASM) -AO < vmsrc/cmd.pla > vmsrc/cmd.a
acme --setpc 8192 -o $(CMD) vmsrc/cmdstub.s acme --setpc 8192 -o $(CMD) vmsrc/cmdstub.s
$(PLVM02): vmsrc/plvm02.s $(PLVM02): vmsrc/plvm02.s
acme -o $(PLVM02) -l vmsrc/plvm02.sym vmsrc/plvm02.s acme -o $(PLVM02) -l vmsrc/plvm02.sym vmsrc/plvm02.s
vmsrc/soscmd.a: vmsrc/soscmd.pla $(PLASM) vmsrc/soscmd.a: vmsrc/soscmd.pla $(PLASM)
./$(PLASM) -A < vmsrc/soscmd.pla > vmsrc/soscmd.a ./$(PLASM) -AO < vmsrc/soscmd.pla > vmsrc/soscmd.a
$(PLVM03): vmsrc/plvm03.s vmsrc/soscmd.a $(PLVM03): vmsrc/plvm03.s vmsrc/soscmd.a
acme -o $(PLVM03) -l vmsrc/plvm03.sym vmsrc/plvm03.s acme -o $(PLVM03) -l vmsrc/plvm03.sym vmsrc/plvm03.s
@ -105,143 +105,143 @@ $(PLVM03): vmsrc/plvm03.s vmsrc/soscmd.a
# Sample code # Sample code
# #
test: samplesrc/test.pla samplesrc/testlib.pla $(PLVM) $(PLASM) test: samplesrc/test.pla samplesrc/testlib.pla $(PLVM) $(PLASM)
./$(PLASM) -AM < samplesrc/test.pla > samplesrc/test.a ./$(PLASM) -AMO < samplesrc/test.pla > samplesrc/test.a
acme --setpc 4094 -o $(TEST) samplesrc/test.a acme --setpc 4094 -o $(TEST) samplesrc/test.a
./$(PLASM) -AM < samplesrc/testlib.pla > samplesrc/testlib.a ./$(PLASM) -AMO < samplesrc/testlib.pla > samplesrc/testlib.a
acme --setpc 4094 -o $(TESTLIB) samplesrc/testlib.a acme --setpc 4094 -o $(TESTLIB) samplesrc/testlib.a
./$(PLVM) TEST ./$(PLVM) TEST
$(ED): toolsrc/ed.pla $(PLVM02) $(PLASM) toolsrc/ed.pla $(ED): toolsrc/ed.pla $(PLVM02) $(PLASM) toolsrc/ed.pla
./$(PLASM) -A < toolsrc/ed.pla > toolsrc/ed.a ./$(PLASM) -AO < toolsrc/ed.pla > toolsrc/ed.a
acme --setpc 8192 -o $(ED) toolsrc/ed.a acme --setpc 8192 -o $(ED) toolsrc/ed.a
$(SB): toolsrc/sb.pla $(PLVM02) $(PLASM) toolsrc/sb.pla $(SB): toolsrc/sb.pla $(PLVM02) $(PLASM) toolsrc/sb.pla
./$(PLASM) -A < toolsrc/sb.pla > toolsrc/sb.a ./$(PLASM) -AO < toolsrc/sb.pla > toolsrc/sb.a
acme --setpc 8192 -o $(SB) toolsrc/sb.a acme --setpc 8192 -o $(SB) toolsrc/sb.a
$(ARGS): libsrc/args.pla $(PLVM02) $(PLASM) $(ARGS): libsrc/args.pla $(PLVM02) $(PLASM)
./$(PLASM) -AM < libsrc/args.pla > libsrc/args.a ./$(PLASM) -AMO < libsrc/args.pla > libsrc/args.a
acme --setpc 4094 -o $(ARGS) libsrc/args.a acme --setpc 4094 -o $(ARGS) libsrc/args.a
$(MEMMGR): libsrc/memmgr.pla $(PLVM02) $(PLASM) $(MEMMGR): libsrc/memmgr.pla $(PLVM02) $(PLASM)
./$(PLASM) -AM < libsrc/memmgr.pla > libsrc/memmgr.a ./$(PLASM) -AMO < libsrc/memmgr.pla > libsrc/memmgr.a
acme --setpc 4094 -o $(MEMMGR) libsrc/memmgr.a acme --setpc 4094 -o $(MEMMGR) libsrc/memmgr.a
$(MEMTEST): samplesrc/memtest.pla $(PLVM02) $(PLASM) $(MEMTEST): samplesrc/memtest.pla $(PLVM02) $(PLASM)
./$(PLASM) -AM < samplesrc/memtest.pla > samplesrc/memtest.a ./$(PLASM) -AMO < samplesrc/memtest.pla > samplesrc/memtest.a
acme --setpc 4094 -o $(MEMTEST) samplesrc/memtest.a acme --setpc 4094 -o $(MEMTEST) samplesrc/memtest.a
$(FIBER): libsrc/fiber.pla $(PLVM02) $(PLASM) $(FIBER): libsrc/fiber.pla $(PLVM02) $(PLASM)
./$(PLASM) -AM < libsrc/fiber.pla > libsrc/fiber.a ./$(PLASM) -AMO < libsrc/fiber.pla > libsrc/fiber.a
acme --setpc 4094 -o $(FIBER) libsrc/fiber.a acme --setpc 4094 -o $(FIBER) libsrc/fiber.a
$(MON): samplesrc/mon.pla $(PLVM02) $(PLASM) $(MON): samplesrc/mon.pla $(PLVM02) $(PLASM)
./$(PLASM) -AM < samplesrc/mon.pla > samplesrc/mon.a ./$(PLASM) -AMO < samplesrc/mon.pla > samplesrc/mon.a
acme --setpc 4094 -o $(MON) samplesrc/mon.a acme --setpc 4094 -o $(MON) samplesrc/mon.a
$(ROD): samplesrc/rod.pla $(PLVM02) $(PLASM) $(ROD): samplesrc/rod.pla $(PLVM02) $(PLASM)
./$(PLASM) -AM < samplesrc/rod.pla > samplesrc/rod.a ./$(PLASM) -AMO < samplesrc/rod.pla > samplesrc/rod.a
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) -AM < samplesrc/sieve.pla > samplesrc/sieve.a ./$(PLASM) -AMO < 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)
./$(PLASM) -AM < libsrc/uthernet.pla > libsrc/uthernet.a ./$(PLASM) -AMO < libsrc/uthernet.pla > libsrc/uthernet.a
acme --setpc 4094 -o $(UTHERNET) libsrc/uthernet.a acme --setpc 4094 -o $(UTHERNET) libsrc/uthernet.a
$(UTHERNET2): libsrc/uthernet2.pla $(PLVM02) $(PLASM) $(UTHERNET2): libsrc/uthernet2.pla $(PLVM02) $(PLASM)
./$(PLASM) -AM < libsrc/uthernet2.pla > libsrc/uthernet2.a ./$(PLASM) -AMO < libsrc/uthernet2.pla > libsrc/uthernet2.a
acme --setpc 4094 -o $(UTHERNET2) libsrc/uthernet2.a acme --setpc 4094 -o $(UTHERNET2) libsrc/uthernet2.a
$(ETHERIP): libsrc/etherip.pla $(PLVM02) $(PLASM) $(ETHERIP): libsrc/etherip.pla $(PLVM02) $(PLASM)
./$(PLASM) -AM < libsrc/etherip.pla > libsrc/etherip.a ./$(PLASM) -AMO < libsrc/etherip.pla > libsrc/etherip.a
acme --setpc 4094 -o $(ETHERIP) libsrc/etherip.a acme --setpc 4094 -o $(ETHERIP) libsrc/etherip.a
$(INET): libsrc/inet.pla $(PLVM02) $(PLASM) $(INET): libsrc/inet.pla $(PLVM02) $(PLASM)
./$(PLASM) -AM < libsrc/inet.pla > libsrc/inet.a ./$(PLASM) -AMO < libsrc/inet.pla > libsrc/inet.a
acme --setpc 4094 -o $(INET) libsrc/inet.a acme --setpc 4094 -o $(INET) libsrc/inet.a
$(DHCP): libsrc/dhcp.pla $(PLVM02) $(PLASM) $(DHCP): libsrc/dhcp.pla $(PLVM02) $(PLASM)
./$(PLASM) -AM < libsrc/dhcp.pla > libsrc/dhcp.a ./$(PLASM) -AMO < libsrc/dhcp.pla > libsrc/dhcp.a
acme --setpc 4094 -o $(DHCP) libsrc/dhcp.a acme --setpc 4094 -o $(DHCP) libsrc/dhcp.a
$(HTTPD): samplesrc/httpd.pla $(PLVM02) $(PLASM) $(HTTPD): samplesrc/httpd.pla $(PLVM02) $(PLASM)
./$(PLASM) -AM < samplesrc/httpd.pla > samplesrc/httpd.a ./$(PLASM) -AMO < samplesrc/httpd.pla > samplesrc/httpd.a
acme --setpc 4094 -o $(HTTPD) samplesrc/httpd.a acme --setpc 4094 -o $(HTTPD) samplesrc/httpd.a
$(FILEIO): libsrc/fileio.pla $(PLVM02) $(PLASM) $(FILEIO): libsrc/fileio.pla $(PLVM02) $(PLASM)
./$(PLASM) -AM < libsrc/fileio.pla > libsrc/fileio.a ./$(PLASM) -AMO < libsrc/fileio.pla > libsrc/fileio.a
acme --setpc 4094 -o $(FILEIO) libsrc/fileio.a acme --setpc 4094 -o $(FILEIO) libsrc/fileio.a
$(TONE): libsrc/tone.pla $(PLVM02) $(PLASM) $(TONE): libsrc/tone.pla $(PLVM02) $(PLASM)
./$(PLASM) -AM < libsrc/tone.pla > libsrc/tone.a ./$(PLASM) -AMO < libsrc/tone.pla > libsrc/tone.a
acme --setpc 4094 -o $(TONE) libsrc/tone.a acme --setpc 4094 -o $(TONE) libsrc/tone.a
$(FATCAT): samplesrc/fatcat.pla $(PLVM02) $(PLASM) $(FATCAT): samplesrc/fatcat.pla $(PLVM02) $(PLASM)
./$(PLASM) -AM < samplesrc/fatcat.pla > samplesrc/fatcat.a ./$(PLASM) -AMO < samplesrc/fatcat.pla > samplesrc/fatcat.a
acme --setpc 4094 -o $(FATCAT) samplesrc/fatcat.a acme --setpc 4094 -o $(FATCAT) samplesrc/fatcat.a
$(FATGET): samplesrc/fatget.pla $(PLVM02) $(PLASM) $(FATGET): samplesrc/fatget.pla $(PLVM02) $(PLASM)
./$(PLASM) -AM < samplesrc/fatget.pla > samplesrc/fatget.a ./$(PLASM) -AMO < samplesrc/fatget.pla > samplesrc/fatget.a
acme --setpc 4094 -o $(FATGET) samplesrc/fatget.a acme --setpc 4094 -o $(FATGET) samplesrc/fatget.a
$(FATPUT): samplesrc/fatput.pla $(PLVM02) $(PLASM) $(FATPUT): samplesrc/fatput.pla $(PLVM02) $(PLASM)
./$(PLASM) -AM < samplesrc/fatput.pla > samplesrc/fatput.a ./$(PLASM) -AMO < samplesrc/fatput.pla > samplesrc/fatput.a
acme --setpc 4094 -o $(FATPUT) samplesrc/fatput.a acme --setpc 4094 -o $(FATPUT) samplesrc/fatput.a
$(FATWDSK): samplesrc/fatwritedsk.pla $(PLVM02) $(PLASM) $(FATWDSK): samplesrc/fatwritedsk.pla $(PLVM02) $(PLASM)
./$(PLASM) -AM < samplesrc/fatwritedsk.pla > samplesrc/fatwritedsk.a ./$(PLASM) -AMO < samplesrc/fatwritedsk.pla > samplesrc/fatwritedsk.a
acme --setpc 4094 -o $(FATWDSK) samplesrc/fatwritedsk.a acme --setpc 4094 -o $(FATWDSK) samplesrc/fatwritedsk.a
$(FATRDSK): samplesrc/fatreaddsk.pla $(PLVM02) $(PLASM) $(FATRDSK): samplesrc/fatreaddsk.pla $(PLVM02) $(PLASM)
./$(PLASM) -AM < samplesrc/fatreaddsk.pla > samplesrc/fatreaddsk.a ./$(PLASM) -AMO < samplesrc/fatreaddsk.pla > samplesrc/fatreaddsk.a
acme --setpc 4094 -o $(FATRDSK) samplesrc/fatreaddsk.a acme --setpc 4094 -o $(FATRDSK) samplesrc/fatreaddsk.a
$(SDFAT): libsrc/sdfat.pla $(PLVM02) $(PLASM) $(SDFAT): libsrc/sdfat.pla $(PLVM02) $(PLASM)
./$(PLASM) -AM < libsrc/sdfat.pla > libsrc/sdfat.a ./$(PLASM) -AMO < libsrc/sdfat.pla > libsrc/sdfat.a
acme --setpc 4094 -o $(SDFAT) libsrc/sdfat.a acme --setpc 4094 -o $(SDFAT) libsrc/sdfat.a
$(SPIPORT): libsrc/spiport.pla $(PLVM02) $(PLASM) $(SPIPORT): libsrc/spiport.pla $(PLVM02) $(PLASM)
./$(PLASM) -AM < libsrc/spiport.pla > libsrc/spiport.a ./$(PLASM) -AMO < libsrc/spiport.pla > libsrc/spiport.a
acme --setpc 4094 -o $(SPIPORT) libsrc/spiport.a acme --setpc 4094 -o $(SPIPORT) libsrc/spiport.a
$(PORTIO): libsrc/portio.pla $(PLVM02) $(PLASM) $(PORTIO): libsrc/portio.pla $(PLVM02) $(PLASM)
./$(PLASM) -AM < libsrc/portio.pla > libsrc/portio.a ./$(PLASM) -AMO < libsrc/portio.pla > libsrc/portio.a
acme --setpc 4094 -o $(PORTIO) libsrc/portio.a acme --setpc 4094 -o $(PORTIO) libsrc/portio.a
$(DGR): libsrc/dgr.pla $(PLVM02) $(PLASM) $(DGR): libsrc/dgr.pla $(PLVM02) $(PLASM)
./$(PLASM) -AM < libsrc/dgr.pla > libsrc/dgr.a ./$(PLASM) -AMO < libsrc/dgr.pla > libsrc/dgr.a
acme --setpc 4094 -o $(DGR) libsrc/dgr.a acme --setpc 4094 -o $(DGR) libsrc/dgr.a
$(DGRTEST): samplesrc/dgrtest.pla $(PLVM02) $(PLASM) $(DGRTEST): samplesrc/dgrtest.pla $(PLVM02) $(PLASM)
./$(PLASM) -AM < samplesrc/dgrtest.pla > samplesrc/dgrtest.a ./$(PLASM) -AMO < samplesrc/dgrtest.pla > samplesrc/dgrtest.a
acme --setpc 4094 -o $(DGRTEST) samplesrc/dgrtest.a acme --setpc 4094 -o $(DGRTEST) samplesrc/dgrtest.a
$(ROGUE): samplesrc/rogue.pla $(PLVM02) $(PLASM) $(ROGUE): samplesrc/rogue.pla $(PLVM02) $(PLASM)
./$(PLASM) -AM < samplesrc/rogue.pla > samplesrc/rogue.a ./$(PLASM) -AMO < samplesrc/rogue.pla > samplesrc/rogue.a
acme --setpc 4094 -o $(ROGUE) samplesrc/rogue.a acme --setpc 4094 -o $(ROGUE) samplesrc/rogue.a
$(ROGUEIO): samplesrc/rogue.io.pla $(PLVM02) $(PLASM) $(ROGUEIO): samplesrc/rogue.io.pla $(PLVM02) $(PLASM)
./$(PLASM) -AM < samplesrc/rogue.io.pla > samplesrc/rogue.io.a ./$(PLASM) -AMO < samplesrc/rogue.io.pla > samplesrc/rogue.io.a
acme --setpc 4094 -o $(ROGUEIO) samplesrc/rogue.io.a acme --setpc 4094 -o $(ROGUEIO) samplesrc/rogue.io.a
$(ROGUECOMBAT): samplesrc/rogue.combat.pla $(PLVM02) $(PLASM) $(ROGUECOMBAT): samplesrc/rogue.combat.pla $(PLVM02) $(PLASM)
./$(PLASM) -AM < samplesrc/rogue.combat.pla > samplesrc/rogue.combat.a ./$(PLASM) -AMO < samplesrc/rogue.combat.pla > samplesrc/rogue.combat.a
acme --setpc 4094 -o $(ROGUECOMBAT) samplesrc/rogue.combat.a acme --setpc 4094 -o $(ROGUECOMBAT) samplesrc/rogue.combat.a
$(ROGUEMAP): samplesrc/rogue.map.pla $(PLVM02) $(PLASM) $(ROGUEMAP): samplesrc/rogue.map.pla $(PLVM02) $(PLASM)
./$(PLASM) -AM < samplesrc/rogue.map.pla > samplesrc/rogue.map.a ./$(PLASM) -AMO < samplesrc/rogue.map.pla > samplesrc/rogue.map.a
acme --setpc 4094 -o $(ROGUEMAP) samplesrc/rogue.map.a acme --setpc 4094 -o $(ROGUEMAP) samplesrc/rogue.map.a
$(HGR1): samplesrc/hgr1.pla samplesrc/hgr1test.pla $(PLVM02) $(PLASM) $(HGR1): samplesrc/hgr1.pla samplesrc/hgr1test.pla $(PLVM02) $(PLASM)
./$(PLASM) -AM < samplesrc/hgr1test.pla > samplesrc/hgr1test.a ./$(PLASM) -AMO < samplesrc/hgr1test.pla > samplesrc/hgr1test.a
acme --setpc 4094 -o $(HGR1TEST) samplesrc/hgr1test.a acme --setpc 4094 -o $(HGR1TEST) samplesrc/hgr1test.a
./$(PLASM) -AM < samplesrc/hgr1.pla > samplesrc/hgr1.a ./$(PLASM) -AMO < samplesrc/hgr1.pla > samplesrc/hgr1.a
acme --setpc 4094 -o $(HGR1) samplesrc/hgr1.a acme --setpc 4094 -o $(HGR1) samplesrc/hgr1.a
hello: samplesrc/hello.pla $(PLVM) $(PLASM) hello: samplesrc/hello.pla $(PLVM) $(PLASM)
./$(PLASM) -AM < samplesrc/hello.pla > samplesrc/hello.a ./$(PLASM) -AMO < samplesrc/hello.pla > samplesrc/hello.a
acme --setpc 4094 -o $(HELLO) samplesrc/hello.a acme --setpc 4094 -o $(HELLO) samplesrc/hello.a
./$(PLVM) HELLO ./$(PLVM) HELLO

View File

@ -1,10 +1,7 @@
#include <stdint.h> #include <stdint.h>
#include <stdio.h> #include <stdio.h>
#include <ctype.h> #include <ctype.h>
#include "tokens.h" #include "plasm.h"
#include "lex.h"
#include "symbols.h"
#include "codegen.h"
/* /*
* Symbol table and fixup information. * Symbol table and fixup information.
*/ */
@ -30,6 +27,8 @@ static int idlocal_offset[128];
static char fixup_size[2048]; static char fixup_size[2048];
static int fixup_type[2048]; static int fixup_type[2048];
static int fixup_tag[2048]; static int fixup_tag[2048];
static t_opseq optbl[256];
static t_opseq *freeop_lst = &optbl[0];
#define FIXUP_BYTE 0x00 #define FIXUP_BYTE 0x00
#define FIXUP_WORD 0x80 #define FIXUP_WORD 0x80
int id_match(char *name, int len, char *id) int id_match(char *name, int len, char *id)
@ -162,6 +161,11 @@ int id_add(char *name, int len, int type, int size)
{ {
return ((type & LOCAL_TYPE) ? idlocal_add(name, len, type, size) : idglobal_add(name, len, type, size)); return ((type & LOCAL_TYPE) ? idlocal_add(name, len, type, size) : idglobal_add(name, len, type, size));
} }
void idlocal_reset(void)
{
locals = 0;
localsize = 0;
}
int idfunc_add(char *name, int len, int type, int tag) int idfunc_add(char *name, int len, int type, int tag)
{ {
if (globals > 1024) if (globals > 1024)
@ -255,10 +259,6 @@ int fixup_new(int tag, int type, int size)
/* /*
* Emit assembly code. * Emit assembly code.
*/ */
#define BYTECODE_SEG 8
#define INIT 16
#define SYSFLAGS 32
static int outflags = 0;
static const char *DB = ".BYTE"; static const char *DB = ".BYTE";
static const char *DW = ".WORD"; static const char *DW = ".WORD";
static const char *DS = ".RES"; static const char *DS = ".RES";
@ -305,8 +305,7 @@ void emit_dci(char *str, int len)
} }
void emit_flags(int flags) void emit_flags(int flags)
{ {
outflags = flags; if (flags & ACME)
if (outflags & ACME)
{ {
DB = "!BYTE"; DB = "!BYTE";
DW = "!WORD"; DW = "!WORD";
@ -316,6 +315,8 @@ void emit_flags(int flags)
} }
void emit_header(void) void emit_header(void)
{ {
int i;
if (outflags & ACME) if (outflags & ACME)
printf("; ACME COMPATIBLE OUTPUT\n"); printf("; ACME COMPATIBLE OUTPUT\n");
else else
@ -324,7 +325,7 @@ void emit_header(void)
{ {
printf("\t%s\t_SEGEND-_SEGBEGIN\t; LENGTH OF HEADER + CODE/DATA + BYTECODE SEGMENT\n", DW); printf("\t%s\t_SEGEND-_SEGBEGIN\t; LENGTH OF HEADER + CODE/DATA + BYTECODE SEGMENT\n", DW);
printf("_SEGBEGIN%c\n", LBL); printf("_SEGBEGIN%c\n", LBL);
printf("\t%s\t$DA7E\t\t\t; MAGIC #\n", DW); printf("\t%s\t$DA7F\t\t\t; MAGIC #\n", DW);
printf("\t%s\t_SYSFLAGS\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_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_DEFCNT\t\t\t; BYTECODE DEF COUNT\n", DW);
@ -334,6 +335,12 @@ void emit_header(void)
{ {
printf("\tJMP\t_INIT\t\t\t; MODULE INITIALIZATION ROUTINE\n"); printf("\tJMP\t_INIT\t\t\t; MODULE INITIALIZATION ROUTINE\n");
} }
/*
* Init free op sequence table
*/
for (i = 0; i < sizeof(optbl)/sizeof(t_opseq)-1; i++)
optbl[i].nextop = &optbl[i+1];
optbl[i].nextop = NULL;
} }
void emit_rld(void) void emit_rld(void)
{ {
@ -448,9 +455,16 @@ void emit_idglobal(int tag, int size, char *name)
else else
printf("_D%03d%c\t%s\t%d\t\t\t; %s\n", tag, LBL, DS, size, name); printf("_D%03d%c\t%s\t%d\t\t\t; %s\n", tag, LBL, DS, size, name);
} }
void emit_idfunc(int tag, int type, char *name) void emit_idfunc(int tag, int type, char *name, int is_bytecode)
{ {
printf("%s%c\t\t\t\t\t; %s()\n", tag_string(tag, type), LBL, name); if (name)
printf("%s%c\t\t\t\t\t; %s()\n", tag_string(tag, type), LBL, name);
if (!(outflags & MODULE))
{
//printf("%s%c\n", name, LBL);
if (is_bytecode)
printf("\tJSR\tINTERP\n");
}
} }
void emit_idconst(char *name, int value) void emit_idconst(char *name, int value)
{ {
@ -519,17 +533,6 @@ int emit_data(int vartype, int consttype, long constval, int constsize)
} }
return (datasize); return (datasize);
} }
void emit_def(const char *name, int is_bytecode)
{
if (!(outflags & MODULE))
{
//printf("%s%c\n", name, LBL);
if (is_bytecode)
printf("\tJSR\tINTERP\n");
}
locals = 0;
localsize = 0;
}
void emit_codetag(int tag) void emit_codetag(int tag)
{ {
printf("_B%03d%c\n", tag, LBL); printf("_B%03d%c\n", tag, LBL);
@ -566,17 +569,31 @@ void emit_llw(int index)
} }
void emit_lab(int tag, int offset, int type) void emit_lab(int tag, int offset, int type)
{ {
int fixup = fixup_new(tag, type, FIXUP_WORD); if (type)
char *taglbl = tag_string(tag, type); {
printf("\t%s\t$68\t\t\t; LAB\t%s+%d\n", DB, taglbl, offset); int fixup = fixup_new(tag, type, FIXUP_WORD);
printf("_F%03d%c\t%s\t%s+%d\t\t\n", fixup, LBL, DW, type & EXTERN_TYPE ? "0" : taglbl, offset); char *taglbl = tag_string(tag, type);
printf("\t%s\t$68\t\t\t; LAB\t%s+%d\n", DB, taglbl, offset);
printf("_F%03d%c\t%s\t%s+%d\t\t\n", fixup, LBL, DW, type & EXTERN_TYPE ? "0" : taglbl, offset);
}
else
{
printf("\t%s\t$68,$%02X,$%02X\t\t; LAB\t%d\n", DB, offset&0xFF,(offset>>8)&0xFF, offset);
}
} }
void emit_law(int tag, int offset, int type) void emit_law(int tag, int offset, int type)
{ {
int fixup = fixup_new(tag, type, FIXUP_WORD); if (type)
char *taglbl = tag_string(tag, type); {
printf("\t%s\t$6A\t\t\t; LAW\t%s+%d\n", DB, taglbl, offset); int fixup = fixup_new(tag, type, FIXUP_WORD);
printf("_F%03d%c\t%s\t%s+%d\t\t\n", fixup, LBL, DW, type & EXTERN_TYPE ? "0" : taglbl, offset); char *taglbl = tag_string(tag, type);
printf("\t%s\t$6A\t\t\t; LAW\t%s+%d\n", DB, taglbl, offset);
printf("_F%03d%c\t%s\t%s+%d\t\t\n", fixup, LBL, DW, type & EXTERN_TYPE ? "0" : taglbl, offset);
}
else
{
printf("\t%s\t$6A,$%02X,$%02X\t\t; LAW\t%d\n", DB, offset&0xFF,(offset>>8)&0xFF, offset);
}
} }
void emit_sb(void) void emit_sb(void)
{ {
@ -604,31 +621,45 @@ void emit_dlw(int index)
} }
void emit_sab(int tag, int offset, int type) void emit_sab(int tag, int offset, int type)
{ {
int fixup = fixup_new(tag, type, FIXUP_WORD); if (type)
char *taglbl = tag_string(tag, type); {
printf("\t%s\t$78\t\t\t; SAB\t%s+%d\n", DB, taglbl, offset); int fixup = fixup_new(tag, type, FIXUP_WORD);
printf("_F%03d%c\t%s\t%s+%d\t\t\n", fixup, LBL, DW, type & EXTERN_TYPE ? "0" : taglbl, offset); char *taglbl = tag_string(tag, type);
printf("\t%s\t$78\t\t\t; SAB\t%s+%d\n", DB, taglbl, offset);
printf("_F%03d%c\t%s\t%s+%d\t\t\n", fixup, LBL, DW, type & EXTERN_TYPE ? "0" : taglbl, offset);
}
else
{
printf("\t%s\t$78,$%02X,$%02X\t\t; SAB\t%d\n", DB, offset&0xFF,(offset>>8)&0xFF, offset);
}
} }
void emit_saw(int tag, int offset, int type) void emit_saw(int tag, int offset, int type)
{
if (type)
{
int fixup = fixup_new(tag, type, FIXUP_WORD);
char *taglbl = tag_string(tag, type);
printf("\t%s\t$7A\t\t\t; SAW\t%s+%d\n", DB, taglbl, offset);
printf("_F%03d%c\t%s\t%s+%d\t\t\n", fixup, LBL, DW, type & EXTERN_TYPE ? "0" : taglbl, offset);
}
else
{
printf("\t%s\t$7A,$%02X,$%02X\t\t; SAW\t%d\n", DB, offset&0xFF,(offset>>8)&0xFF, offset);
}
}
void emit_dab(int tag, int offset, int type)
{ {
int fixup = fixup_new(tag, type, FIXUP_WORD); int fixup = fixup_new(tag, type, FIXUP_WORD);
char *taglbl = tag_string(tag, type); char *taglbl = tag_string(tag, type);
printf("\t%s\t$7A\t\t\t; SAW\t%s+%d\n", DB, taglbl, offset); printf("\t%s\t$7C\t\t\t; DAB\t%s+%d\n", DB, taglbl, offset);
printf("_F%03d%c\t%s\t%s+%d\t\t\n", fixup, LBL, DW, type & EXTERN_TYPE ? "0" : taglbl, offset); printf("_F%03d%c\t%s\t%s+%d\t\t\n", fixup, LBL, DW, type & EXTERN_TYPE ? "0" : taglbl, offset);
} }
void emit_dab(int tag, int type) void emit_daw(int tag, int offset, int type)
{ {
int fixup = fixup_new(tag, type, FIXUP_WORD); int fixup = fixup_new(tag, type, FIXUP_WORD);
char *taglbl = tag_string(tag, type); char *taglbl = tag_string(tag, type);
printf("\t%s\t$7C\t\t\t; DAB\t%s\n", DB, taglbl); printf("\t%s\t$7E\t\t\t; DAW\t%s+%d\n", DB, taglbl, offset);
printf("_F%03d%c\t%s\t%s\t\t\n", fixup, LBL, DW, type & EXTERN_TYPE ? "0" : taglbl); printf("_F%03d%c\t%s\t%s+%d\t\t\n", fixup, LBL, DW, type & EXTERN_TYPE ? "0" : taglbl, offset);
}
void emit_daw(int tag, int type)
{
int fixup = fixup_new(tag, type, FIXUP_WORD);
char *taglbl = tag_string(tag, type);
printf("\t%s\t$7E\t\t\t; DAW\t%s\n", DB, taglbl);
printf("_F%03d%c\t%s\t%s\t\t\n", fixup, LBL, DW, type & EXTERN_TYPE ? "0" : taglbl);
} }
void emit_localaddr(int index) void emit_localaddr(int index)
{ {
@ -725,27 +756,23 @@ void emit_start(void)
outflags |= INIT; outflags |= INIT;
defs++; defs++;
} }
void emit_dup(void) void emit_push_exp(void)
{ {
printf("\t%s\t$32\t\t\t; DUP\n", DB); printf("\t%s\t$34\t\t\t; PUSH EXP\n", DB);
} }
void emit_push(void) void emit_pull_exp(void)
{ {
printf("\t%s\t$34\t\t\t; PUSH\n", DB); printf("\t%s\t$36\t\t\t; PULL EXP\n", DB);
}
void emit_pull(void)
{
printf("\t%s\t$36\t\t\t; PULL\n", DB);
}
void emit_swap(void)
{
printf("\t%s\t$2E\t\t\t; SWAP\n", DB);
} }
void emit_drop(void) void emit_drop(void)
{ {
printf("\t%s\t$30\t\t\t; DROP\n", DB); printf("\t%s\t$30\t\t\t; DROP\n", DB);
} }
int emit_unaryop(int op) void emit_dup(void)
{
printf("\t%s\t$32\t\t\t; DUP\n", DB);
}
int emit_unaryop(t_token op)
{ {
switch (op) switch (op)
{ {
@ -841,3 +868,459 @@ int emit_op(t_token op)
} }
return (1); return (1);
} }
/*
* New/release sequence ops
*/
t_opseq *new_op(void)
{
t_opseq* op = freeop_lst;
if (!op)
{
fprintf(stderr, "Compiler out of sequence ops!\n");
return (NULL);
}
freeop_lst = freeop_lst->nextop;
op->nextop = NULL;
return (op);
}
void release_op(t_opseq *op)
{
if (op)
{
op->nextop = freeop_lst;
freeop_lst = op;
}
}
void release_seq(t_opseq *seq)
{
t_opseq *op;
while (seq)
{
op = seq;
seq = seq->nextop;
/*
* Free this op
*/
op->nextop = freeop_lst;
freeop_lst = op;
}
}
/*
* Crunch sequence (peephole optimize)
*/
int crunch_seq(t_opseq *seq)
{
t_opseq *opnext, *opnextnext;
t_opseq *op = seq;
int crunched = 0;
int freeops = 0;
while (op && (opnext = op->nextop))
{
switch (op->code)
{
case CONST_CODE:
//fprintf(stderr, "CONST -> $%04X", opnext->code);
if (op->val == 1)
{
if (opnext->code == BINARY_CODE(ADD_TOKEN))
{
op->code = INC_CODE;
freeops = 1;
break;
}
if (opnext->code == BINARY_CODE(SUB_TOKEN))
{
op->code = DEC_CODE;
freeops = 1;
break;
}
}
switch (opnext->code)
{
case NEG_CODE:
op->val = -(op->val);
freeops = 1;
break;
case COMP_CODE:
op->val = ~(op->val);
freeops = 1;
break;
case LOGIC_NOT_CODE:
op->val = op->val ? 0 : 1;
freeops = 1;
break;
case UNARY_CODE(BPTR_TOKEN):
case LB_CODE:
op->offsz = op->val;
op->code = LAB_CODE;
freeops = 1;
break;
case UNARY_CODE(WPTR_TOKEN):
case LW_CODE:
op->offsz = op->val;
op->code = LAW_CODE;
freeops = 1;
break;
case SB_CODE:
op->offsz = op->val;
op->code = SAB_CODE;
freeops = 1;
break;
case SW_CODE:
op->offsz = op->val;
op->code = SAW_CODE;
freeops = 1;
break;
case CONST_CODE: // Collapse constant operation
if ((opnextnext = opnext->nextop))
switch (opnextnext->code)
{
case BINARY_CODE(MUL_TOKEN):
op->val *= opnext->val;
freeops = 2;
break;
case BINARY_CODE(DIV_TOKEN):
op->val /= opnext->val;
freeops = 2;
break;
case BINARY_CODE(MOD_TOKEN):
op->val %= opnext->val;
freeops = 2;
break;
case BINARY_CODE(ADD_TOKEN):
op->val += opnext->val;
freeops = 2;
break;
case BINARY_CODE(SUB_TOKEN):
op->val -= opnext->val;
freeops = 2;
break;
case BINARY_CODE(SHL_TOKEN):
op->val <<= opnext->val;
freeops = 2;
break;
case BINARY_CODE(SHR_TOKEN):
op->val >>= opnext->val;
freeops = 2;
break;
case BINARY_CODE(AND_TOKEN):
op->val &= opnext->val;
freeops = 2;
break;
case BINARY_CODE(OR_TOKEN):
op->val |= opnext->val;
freeops = 2;
break;
case BINARY_CODE(EOR_TOKEN):
op->val ^= opnext->val;
freeops = 2;
break;
case BINARY_CODE(EQ_TOKEN):
op->val = op->val == opnext->val ? 1 : 0;
freeops = 2;
break;
case BINARY_CODE(NE_TOKEN):
op->val = op->val != opnext->val ? 1 : 0;
freeops = 2;
break;
case BINARY_CODE(GE_TOKEN):
op->val = op->val >= opnext->val ? 1 : 0;
freeops = 2;
break;
case BINARY_CODE(LT_TOKEN):
op->val = op->val < opnext->val ? 1 : 0;
freeops = 2;
break;
case BINARY_CODE(GT_TOKEN):
op->val = op->val > opnext->val ? 1 : 0;
freeops = 2;
break;
case BINARY_CODE(LE_TOKEN):
op->val = op->val <= opnext->val ? 1 : 0;
freeops = 2;
break;
case BINARY_CODE(LOGIC_OR_TOKEN):
op->val = op->val || opnext->val ? 1 : 0;
freeops = 2;
break;
case BINARY_CODE(LOGIC_AND_TOKEN):
op->val = op->val && opnext->val ? 1 : 0;
freeops = 2;
break;
}
break; // CONST_CODE
}
break; // CONST_CODE
case LADDR_CODE:
switch (opnext->code)
{
case CONST_CODE:
if ((opnextnext = opnext->nextop))
switch (opnextnext->code)
{
case ADD_CODE:
case INDEXB_CODE:
op->offsz += opnext->val;
freeops = 2;
break;
case INDEXW_CODE:
op->offsz += opnext->val * 2;
freeops = 2;
break;
}
break;
case LB_CODE:
op->code = LLB_CODE;
freeops = 1;
break;
case LW_CODE:
op->code = LLW_CODE;
freeops = 1;
break;
case SB_CODE:
op->code = SLB_CODE;
freeops = 1;
break;
case SW_CODE:
op->code = SLW_CODE;
freeops = 1;
break;
}
break; // LADDR_CODE
case GADDR_CODE:
switch (opnext->code)
{
case CONST_CODE:
if ((opnextnext = opnext->nextop))
switch (opnextnext->code)
{
case ADD_CODE:
case INDEXB_CODE:
op->offsz += opnext->val;
freeops = 2;
break;
case INDEXW_CODE:
op->offsz += opnext->val * 2;
freeops = 2;
break;
}
break;
case LB_CODE:
op->code = LAB_CODE;
freeops = 1;
break;
case LW_CODE:
op->code = LAW_CODE;
freeops = 1;
break;
case SB_CODE:
op->code = SAB_CODE;
freeops = 1;
break;
case SW_CODE:
op->code = SAW_CODE;
freeops = 1;
break;
case ICAL_CODE:
op->code = CALL_CODE;
freeops = 1;
break;
}
break; // GADDR_CODE
}
//
// Free up crunched ops
//
while (freeops)
{
op->nextop = opnext->nextop;
opnext->nextop = freeop_lst;
freeop_lst = opnext;
opnext = op->nextop;
crunched = 1;
freeops--;
}
op = opnext;
}
return (crunched);
}
/*
* Generate a sequence of code
*/
t_opseq *gen_seq(t_opseq *seq, int opcode, long cval, int tag, int offsz, int type)
{
t_opseq *op;
if (!seq)
{
op = seq = new_op();
}
else
{
op = seq;
while (op->nextop)
op = op->nextop;
op->nextop = new_op();
op = op->nextop;
}
op->code = opcode;
op->val = cval;
op->tag = tag;
op->offsz = offsz;
op->type = type;
return (seq);
}
/*
* Append one sequence to the end of another
*/
t_opseq *cat_seq(t_opseq *seq1, t_opseq *seq2)
{
t_opseq *op;
if (!seq1)
return (seq2);
for (op = seq1; op->nextop; op = op->nextop);
op->nextop = seq2;
return (seq1);
}
/*
* Emit a sequence of ops
*/
int emit_seq(t_opseq *seq)
{
t_opseq *op;
if (!seq)
return (0);
if (outflags & OPTIMIZE)
while (crunch_seq(seq));
while (seq)
{
op = seq;
switch (op->code)
{
case NEG_CODE:
case COMP_CODE:
case LOGIC_NOT_CODE:
case INC_CODE:
case DEC_CODE:
case BPTR_CODE:
case WPTR_CODE:
emit_unaryop(op->code);
break;
case MUL_CODE:
case DIV_CODE:
case MOD_CODE:
case ADD_CODE:
case SUB_CODE:
case SHL_CODE:
case SHR_CODE:
case AND_CODE:
case OR_CODE:
case EOR_CODE:
case EQ_CODE:
case NE_CODE:
case GE_CODE:
case LT_CODE:
case GT_CODE:
case LE_CODE:
case LOGIC_OR_CODE:
case LOGIC_AND_CODE:
emit_op(op->code);
break;
case CONST_CODE:
emit_const(op->val);
break;
case STR_CODE:
emit_conststr(op->val, op->offsz);
break;
case LB_CODE:
emit_lb();
break;
case LW_CODE:
emit_lw();
break;
case LLB_CODE:
emit_llb(op->offsz);
break;
case LLW_CODE:
emit_llw(op->offsz);
break;
case LAB_CODE:
emit_lab(op->tag, op->offsz, op->type);
break;
case LAW_CODE:
emit_law(op->tag, op->offsz, op->type);
break;
case SB_CODE:
emit_sb();
break;
case SW_CODE:
emit_sw();
break;
case SLB_CODE:
emit_slb(op->offsz);
break;
case SLW_CODE:
emit_slw(op->offsz);
break;
case DLB_CODE:
emit_dlb(op->offsz);
break;
case DLW_CODE:
emit_dlw(op->offsz);
break;
case SAB_CODE:
emit_sab(op->tag, op->offsz, op->type);
break;
case SAW_CODE:
emit_saw(op->tag, op->offsz, op->type);
break;
case DAB_CODE:
emit_dab(op->tag, op->offsz, op->type);
break;
case DAW_CODE:
emit_daw(op->tag, op->offsz, op->type);
break;
case CALL_CODE:
emit_call(op->tag, op->type);
break;
case ICAL_CODE:
emit_ical();
break;
case LADDR_CODE:
emit_localaddr(op->offsz);
break;
case GADDR_CODE:
emit_globaladdr(op->tag, op->offsz, op->type);
break;
case INDEXB_CODE:
emit_indexbyte();
break;
case INDEXW_CODE:
emit_indexword();
break;
case DROP_CODE:
emit_drop();
break;
case DUP_CODE:
emit_dup();
break;
case PUSH_EXP_CODE:
emit_push_exp();
break;
case PULL_EXP_CODE:
emit_pull_exp();
break;
default:
return (0);
}
seq = seq->nextop;
/*
* Free this op
*/
op->nextop = freeop_lst;
freeop_lst = op;
}
return (1);
}

View File

@ -1,5 +1,84 @@
#define ACME 1 typedef struct _opseq {
#define MODULE 2 int code;
long val;
int tag;
int offsz;
int type;
struct _opseq *nextop;
} t_opseq;
#define UNARY_CODE(tkn) ((tkn)|0x0100)
#define BINARY_CODE(tkn) ((tkn)|0x0200)
#define NEG_CODE 0x0100|NEG_TOKEN
#define COMP_CODE 0x0100|COMP_TOKEN
#define LOGIC_NOT_CODE 0x0100|LOGIC_NOT_TOKEN
#define INC_CODE 0x0100|INC_TOKEN
#define DEC_CODE 0x0100|DEC_TOKEN
#define BPTR_CODE 0x0100|BPTR_TOKEN
#define WPTR_CODE 0x0100|WPTR_TOKEN
#define MUL_CODE 0x0200|MUL_TOKEN
#define DIV_CODE 0x0200|DIV_TOKEN
#define MOD_CODE 0x0200|MOD_TOKEN
#define ADD_CODE 0x0200|ADD_TOKEN
#define SUB_CODE 0x0200|SUB_TOKEN
#define SHL_CODE 0x0200|SHL_TOKEN
#define SHR_CODE 0x0200|SHR_TOKEN
#define AND_CODE 0x0200|AND_TOKEN
#define OR_CODE 0x0200|OR_TOKEN
#define EOR_CODE 0x0200|EOR_TOKEN
#define EQ_CODE 0x0200|EQ_TOKEN
#define NE_CODE 0x0200|NE_TOKEN
#define GE_CODE 0x0200|GE_TOKEN
#define LT_CODE 0x0200|LT_TOKEN
#define GT_CODE 0x0200|GT_TOKEN
#define LE_CODE 0x0200|LE_TOKEN
#define LOGIC_OR_CODE 0x0200|LOGIC_OR_TOKEN
#define LOGIC_AND_CODE 0x0200|LOGIC_AND_TOKEN
#define CONST_CODE 0x0300
#define STR_CODE 0x0301
#define LB_CODE 0x0302
#define LW_CODE 0x0303
#define LLB_CODE 0x0304
#define LLW_CODE 0x0305
#define LAB_CODE 0x0306
#define LAW_CODE 0x0307
#define SB_CODE 0x0308
#define SW_CODE 0x0309
#define SLB_CODE 0x030A
#define SLW_CODE 0x030B
#define DLB_CODE 0x030C
#define DLW_CODE 0x030D
#define SAB_CODE 0x030E
#define SAW_CODE 0x030F
#define DAB_CODE 0x0310
#define DAW_CODE 0x0311
#define CALL_CODE 0x0312
#define ICAL_CODE 0x0313
#define LADDR_CODE 0x0314
#define GADDR_CODE 0x0315
#define INDEXB_CODE 0x0316
#define INDEXW_CODE 0x0317
#define DROP_CODE 0x0318
#define DUP_CODE 0x0319
#define PUSH_EXP_CODE 0x031A
#define PULL_EXP_CODE 0x031B
#define gen_uop(seq,op) gen_seq(seq,UNARY_CODE(op),0,0,0,0)
#define gen_op(seq,op) gen_seq(seq,BINARY_CODE(op),0,0,0,0)
#define gen_const(seq,val) gen_seq(seq,CONST_CODE,val,0,0,0)
#define gen_str(seq,str,len) gen_seq(seq,STR_CODE,str,0,len,0)
#define gen_lcladr(seq,idx) gen_seq(seq,LADDR_CODE,0,0,idx,0)
#define gen_gbladr(seq,tag,typ) gen_seq(seq,GADDR_CODE,0,tag,0,typ)
#define gen_idxb(seq) gen_seq(seq,ADD_CODE,0,0,0,0)
#define gen_idxw(seq) gen_seq(seq,INDEXW_CODE,0,0,0,0)
#define gen_lb(seq) gen_seq(seq,LB_CODE,0,0,0,0)
#define gen_lw(seq) gen_seq(seq,LW_CODE,0,0,0,0)
#define gen_sb(seq) gen_seq(seq,SB_CODE,0,0,0,0)
#define gen_sw(seq) gen_seq(seq,SW_CODE,0,0,0,0)
#define gen_icall(seq) gen_seq(seq,ICAL_CODE,0,0,0,0)
#define gen_pushexp(seq) gen_seq(seq,PUSH_EXP_CODE,0,0,0,0)
#define gen_pullexp(seq) gen_seq(seq,PULL_EXP_CODE,0,0,0,0)
#define gen_drop(seq) gen_seq(seq,DROP_CODE,0,0,0,0)
void emit_flags(int flags); void emit_flags(int flags);
void emit_header(void); void emit_header(void);
void emit_trailer(void); void emit_trailer(void);
@ -10,9 +89,8 @@ void emit_comment(char *s);
void emit_asm(char *s); void emit_asm(char *s);
void emit_idlocal(char *name, int value); void emit_idlocal(char *name, int value);
void emit_idglobal(int value, int size, char *name); void emit_idglobal(int value, int size, char *name);
void emit_idfunc(int tag, int type, char *name); void emit_idfunc(int tag, int type, char *name, int is_bytecode);
void emit_idconst(char *name, int value); void emit_idconst(char *name, int value);
void emit_def(const char *name, int is_bytecode);
int emit_data(int vartype, int consttype, long constval, int constsize); int emit_data(int vartype, int consttype, long constval, int constsize);
void emit_codetag(int tag); void emit_codetag(int tag);
void emit_const(int cval); void emit_const(int cval);
@ -30,16 +108,16 @@ void emit_slw(int index);
void emit_dlb(int index); void emit_dlb(int index);
void emit_dlw(int index); void emit_dlw(int index);
void emit_sab(int tag, int offset, int type); void emit_sab(int tag, int offset, int type);
void emit_saw(int tag, int ofset, int type); void emit_saw(int tag, int offset, int type);
void emit_dab(int tag, int type); void emit_dab(int tag, int offset, int type);
void emit_daw(int tag, int type); void emit_daw(int tag, int offset, int type);
void emit_call(int tag, int type); void emit_call(int tag, int type);
void emit_ical(void); void emit_ical(void);
void emit_localaddr(int index); void emit_localaddr(int index);
void emit_globaladdr(int tag, int offset, int type); void emit_globaladdr(int tag, int offset, int type);
void emit_indexbyte(void); void emit_indexbyte(void);
void emit_indexword(void); void emit_indexword(void);
int emit_unaryop(int op); int emit_unaryop(t_token op);
int emit_op(t_token op); int emit_op(t_token op);
void emit_brtru(int tag); void emit_brtru(int tag);
void emit_brfls(int tag); void emit_brfls(int tag);
@ -47,14 +125,19 @@ void emit_brgt(int tag);
void emit_brlt(int tag); void emit_brlt(int tag);
void emit_brne(int tag); void emit_brne(int tag);
void emit_brnch(int tag); void emit_brnch(int tag);
void emit_swap(void); void emit_empty(void);
void emit_dup(void); void emit_push_exp(void);
void emit_push(void); void emit_pull_exp(void);
void emit_pull(void);
void emit_drop(void); void emit_drop(void);
void emit_dup(void);
void emit_leave(void); void emit_leave(void);
void emit_ret(void); void emit_ret(void);
void emit_enter(int cparams); void emit_enter(int cparams);
void emit_start(void); void emit_start(void);
void emit_rld(void); void emit_rld(void);
void emit_esd(void); void emit_esd(void);
void release_seq(t_opseq *seq);
int crunch_seq(t_opseq *seq);
t_opseq *gen_seq(t_opseq *seq, int opcode, long cval, int tag, int offsz, int type);
t_opseq *cat_seq(t_opseq *seq1, t_opseq *seq2);
int emit_seq(t_opseq *seq);

View File

@ -13,8 +13,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <ctype.h> #include <ctype.h>
#include "tokens.h" #include "plasm.h"
#include "symbols.h"
char *statement, *tokenstr, *scanpos = (char*) ""; char *statement, *tokenstr, *scanpos = (char*) "";
t_token scantoken, prevtoken; t_token scantoken, prevtoken;
@ -66,6 +65,8 @@ t_token keywords[] = {
EOL_TOKEN EOL_TOKEN
}; };
extern int outflags;
void parse_error(const char *errormsg) void parse_error(const char *errormsg)
{ {
char *error_carrot = statement; char *error_carrot = statement;
@ -76,7 +77,18 @@ void parse_error(const char *errormsg)
fprintf(stderr, "^\nError: %s\n", errormsg); fprintf(stderr, "^\nError: %s\n", errormsg);
exit(1); exit(1);
} }
void parse_warn(const char *warnmsg)
{
if (outflags & WARNINGS)
{
char *error_carrot = statement;
fprintf(stderr, "\n%s %4d: %s\n%*s ", filename, lineno, statement, (int)strlen(filename), "");
for (error_carrot = statement; error_carrot != tokenstr; error_carrot++)
putc(*error_carrot == '\t' ? '\t' : ' ', stderr);
fprintf(stderr, "^\nWarning: %s\n", warnmsg);
}
}
int hexdigit(char ch) int hexdigit(char ch)
{ {
ch = toupper(ch); ch = toupper(ch);

View File

@ -4,6 +4,7 @@ extern int tokenlen;
extern long constval; extern long constval;
extern char inputline[]; extern char inputline[];
void parse_error(const char *errormsg); void parse_error(const char *errormsg);
void parse_warn(const char *warnmsg);
int next_line(void); int next_line(void);
void scan_rewind(char *backptr); void scan_rewind(char *backptr);
int scan_lookahead(void); int scan_lookahead(void);

File diff suppressed because it is too large Load Diff

View File

@ -1,8 +1,7 @@
#include <stdio.h> #include <stdio.h>
#include "tokens.h" #include "plasm.h"
#include "lex.h"
#include "codegen.h" int outflags = 0;
#include "parse.h"
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
@ -10,23 +9,28 @@ int main(int argc, char **argv)
for (i = 1; i < argc; i++) for (i = 1; i < argc; i++)
{ {
if (argv[i][0] == '-') if (argv[i][0] == '-')
{ {
j = 1; j = 1;
while (argv[i][j]) while (argv[i][j])
{ {
switch(argv[i][j++]) switch(argv[i][j++])
{ {
case 'A': case 'A':
flags |= ACME; outflags |= ACME;
break; break;
case 'M': case 'M':
flags |= MODULE; outflags |= MODULE;
break; break;
case 'O':
outflags |= OPTIMIZE;
break;
case 'W':
outflags |= WARNINGS;
} }
} }
} }
} }
emit_flags(flags); emit_flags(outflags);
if (parse_module()) if (parse_module())
{ {
fprintf(stderr, "Compilation complete.\n"); fprintf(stderr, "Compilation complete.\n");

16
src/toolsrc/plasm.h Executable file
View File

@ -0,0 +1,16 @@
/*
* Global flags.
*/
#define ACME (1<<0)
#define MODULE (1<<1)
#define OPTIMIZE (1<<2)
#define BYTECODE_SEG (1<<3)
#define INIT (1<<4)
#define SYSFLAGS (1<<5)
#define WARNINGS (1<<6)
extern int outflags;
#include "tokens.h"
#include "lex.h"
#include "symbols.h"
#include "parse.h"
#include "codegen.h"

View File

@ -10,7 +10,7 @@
#define DEF_TYPE (1 << 4) #define DEF_TYPE (1 << 4)
#define BRANCH_TYPE (1 << 5) #define BRANCH_TYPE (1 << 5)
#define LOCAL_TYPE (1 << 6) #define LOCAL_TYPE (1 << 6)
#define EXTERN_TYPE (1 << 7) #define EXTERN_TYPE (1 << 7)
#define ADDR_TYPE (VAR_TYPE | FUNC_TYPE | EXTERN_TYPE) #define ADDR_TYPE (VAR_TYPE | FUNC_TYPE | EXTERN_TYPE)
#define WPTR_TYPE (1 << 8) #define WPTR_TYPE (1 << 8)
#define BPTR_TYPE (1 << 9) #define BPTR_TYPE (1 << 9)
@ -18,8 +18,16 @@
#define STRING_TYPE (1 << 10) #define STRING_TYPE (1 << 10)
#define TAG_TYPE (1 << 11) #define TAG_TYPE (1 << 11)
#define EXPORT_TYPE (1 << 12) #define EXPORT_TYPE (1 << 12)
#define PREDEF_TYPE (1 << 13) #define PREDEF_TYPE (1 << 13)
#define FUNC_TYPE (ASM_TYPE | DEF_TYPE | PREDEF_TYPE) #define FUNC_TYPE (ASM_TYPE | DEF_TYPE | PREDEF_TYPE)
#define FUNC_PARMS (0x0F << 16)
#define FUNC_VALS (0x0F << 20)
#define FUNC_PARMVALS (FUNC_PARMS|FUNC_VALS)
#define funcparms_type(p) (((p)&0x0F)<<16)
#define funcparms_cnt(t) (((t)>>16)&0x0F)
#define funcvals_type(v) (((v)&0x0F)<<20)
#define funcvals_cnt(t) (((t)>>20)&0x0F)
int id_match(char *name, int len, char *id); int id_match(char *name, int len, char *id);
int idlocal_lookup(char *name, int len); int idlocal_lookup(char *name, int len);
int idglobal_lookup(char *name, int len); int idglobal_lookup(char *name, int len);
@ -27,6 +35,7 @@ int idconst_lookup(char *name, int len);
int idlocal_add(char *name, int len, int type, int size); int idlocal_add(char *name, int len, int type, int size);
int idglobal_add(char *name, int len, int type, int size); int idglobal_add(char *name, int len, int type, int size);
int id_add(char *name, int len, int type, int size); int id_add(char *name, int len, int type, int size);
void idlocal_reset(void);
int idfunc_set(char *name, int len, int type, int tag); int idfunc_set(char *name, int len, int type, int tag);
int idfunc_add(char *name, int len, int type, int tag); int idfunc_add(char *name, int len, int type, int tag);
int idconst_add(char *name, int len, int value); int idconst_add(char *name, int len, int value);

156
src/vmsrc/a1cmd.pla Normal file → Executable file
View File

@ -39,7 +39,7 @@ predef loadmod, execmod, lookupstrmod
// //
// System variables. // System variables.
// //
word version = $0094 // 00.94 word version = $0099 // 00.99
word systemflags = 0 word systemflags = 0
word heap word heap
word symtbl, lastsym word symtbl, lastsym
@ -90,18 +90,18 @@ byte execstr[] = "MODEXEC"
byte modadrstr[] = "MODADDR" byte modadrstr[] = "MODADDR"
byte argstr[] = "ARGS" byte argstr[] = "ARGS"
word exports[] = @sysstr, @syscall word exports[] = @sysstr, @syscall
word = @callstr, @call word = @callstr, @call
word = @putcstr, @cout word = @putcstr, @cout
word = @putlnstr, @crout word = @putlnstr, @crout
word = @putsstr, @prstr word = @putsstr, @prstr
word = @getcstr, @cin word = @getcstr, @cin
word = @getsstr, @rdstr word = @getsstr, @rdstr
word = @hpmarkstr, @markheap word = @hpmarkstr, @markheap
word = @hpallocstr,@allocheap word = @hpallocstr,@allocheap
word = @hpalignstr,@allocalignheap word = @hpalignstr,@allocalignheap
word = @hprelstr, @releaseheap word = @hprelstr, @releaseheap
word = @memsetstr, @memset word = @memsetstr, @memset
word = @memcpystr, @memcpy word = @memcpystr, @memcpy
word = @uisgtstr, @uword_isgt word = @uisgtstr, @uword_isgt
word = @uisgestr, @uword_isge word = @uisgestr, @uword_isge
word = @uisltstr, @uword_islt word = @uisltstr, @uword_islt
@ -112,21 +112,21 @@ word = @modadrstr, @lookupstrmod
word = @machidstr, @machid word = @machidstr, @machid
word = @argstr, @cmdptr word = @argstr, @cmdptr
word = 0 word = 0
word syslibsym = @exports word syslibsym = @exports
// //
// CALL CFFA1 API ENTRYPOINT // CALL CFFA1 API ENTRYPOINT
// SYSCALL(CMD) // SYSCALL(CMD)
// //
asm syscall asm syscall
LDA ESTKL,X LDA ESTKL,X
STX ESP STX ESP
TAX TAX
JSR $900C JSR $900C
LDX ESP LDX ESP
LDY #$00 LDY #$00
STA ESTKL,X STA ESTKL,X
STY ESTKH,X STY ESTKH,X
RTS RTS
end end
// //
// CALL 6502 ROUTINE // CALL 6502 ROUTINE
@ -351,7 +351,7 @@ asm interp
STA ESTKH,X STA ESTKH,X
RTS RTS
end end
// //
// A DCI string is one that has the high bit set for every character except the last. // A DCI string is one that has the high bit set for every character except the last.
// More efficient than C or Pascal strings. // More efficient than C or Pascal strings.
// //
@ -650,7 +650,7 @@ end
def finddirentry(filename) def finddirentry(filename)
*CFFAFileName = filename *CFFAFileName = filename
perr = syscall($14) perr = syscall($14)
return *CFFAEntryPtr return *CFFAEntryPtr
end end
def readfile(filename, buffer) def readfile(filename, buffer)
*CFFADest = buffer *CFFADest = buffer
@ -783,12 +783,12 @@ def loadmod(mod)
fin fin
if rdlen > 0 if rdlen > 0
readfile(@filename, heap) readfile(@filename, heap)
memcpy(@header, heap, 128) memcpy(@header, heap, 128)
modsize = header:0 modsize = header:0
moddep = @header.1 moddep = @header.1
defofst = modsize defofst = modsize
init = 0 init = 0
if rdlen > 4 and heap=>2 == $DA7E // DAVE = magic number :-) if rdlen > 4 and heap=>2 == $DA7F // DAVE+1 = magic number :-)
// //
// This is an EXTended RELocatable (data+bytecode) module. // This is an EXTended RELocatable (data+bytecode) module.
// //
@ -796,44 +796,46 @@ def loadmod(mod)
defcnt = header:8 defcnt = header:8
init = header:10 init = header:10
moddep = @header.12 moddep = @header.12
// //
// Load module dependencies. // Load module dependencies.
// //
while ^moddep while ^moddep
if !lookupmod(moddep) if !lookupmod(moddep)
if loadmod(moddep) < 0 if loadmod(moddep) < 0
return -perr return -perr
fin fin
fin fin
moddep = moddep + dcitos(moddep, @str) moddep = moddep + dcitos(moddep, @str)
loop loop
// //
// Init def table. // Init def table.
// //
deftbl = allocheap(defcnt * 5 + 1) deftbl = allocheap(defcnt * 5 + 1)
deflast = deftbl deflast = deftbl
^deflast = 0 ^deflast = 0
// //
// Re-read file // Re-read file
// //
readfile(@filename, heap) readfile(@filename, heap)
else
return -69
fin fin
// //
// Alloc heap space for relocated module (data + bytecode). // Alloc heap space for relocated module (data + bytecode).
// //
moddep = moddep + 1 - @header + heap moddep = moddep + 1 - @header + heap
modfix = moddep - (heap + 2) // Adjust to skip header modfix = moddep - (heap + 2) // Adjust to skip header
modsize = modsize - modfix modsize = modsize - modfix
rdlen = rdlen - modfix - 2 rdlen = rdlen - modfix - 2
modaddr = allocheap(modsize) modaddr = allocheap(modsize)
memcpy(modaddr, moddep, rdlen) memcpy(modaddr, moddep, rdlen)
// //
// Add module to symbol table. // Add module to symbol table.
// //
addmod(mod, modaddr) addmod(mod, modaddr)
// //
// Apply all fixups and symbol import/export. // Apply all fixups and symbol import/export.
// //
modfix = modaddr - modfix modfix = modaddr - modfix
bytecode = defofst + modfix - MODADDR bytecode = defofst + modfix - MODADDR
modend = modaddr + modsize modend = modaddr + modsize
@ -841,16 +843,16 @@ def loadmod(mod)
esd = rld // Extern+Entry Symbol Directory esd = rld // Extern+Entry Symbol Directory
while ^esd // Scan to end of ESD while ^esd // Scan to end of ESD
esd = esd + 4 esd = esd + 4
loop loop
esd = esd + 1 esd = esd + 1
// //
// Run through the Re-Location Dictionary. // Run through the Re-Location Dictionary.
// //
while ^rld while ^rld
if ^rld == $02 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(rld=>1 - defofst + bytecode, @deflast) adddef(rld=>1 - defofst + bytecode, @deflast)
else else
addr = rld=>1 + modfix addr = rld=>1 + modfix
@ -880,21 +882,21 @@ def loadmod(mod)
fin fin
rld = rld + 4 rld = rld + 4
loop loop
// //
// Run through the External/Entry Symbol Directory. // Run through the External/Entry Symbol Directory.
// //
while ^esd while ^esd
sym = esd sym = esd
esd = esd + dcitos(esd, @str) esd = esd + dcitos(esd, @str)
if ^esd & $08 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 addr = esd=>1 + modfix - MODADDR
if uword_isge(addr, bytecode) if uword_isge(addr, bytecode)
// //
// Use the def directory address for bytecode. // Use the def directory address for bytecode.
// //
addr = lookupdef(addr - bytecode + bytecode, deftbl) addr = lookupdef(addr - bytecode + bytecode, deftbl)
fin fin
addsym(sym, addr) addsym(sym, addr)
@ -910,13 +912,13 @@ def loadmod(mod)
// //
fixup = 0 fixup = 0
if init if init
fixup = adddef(init - defofst + bytecode, @deflast)() fixup = adddef(init - defofst + bytecode, @deflast)()
if fixup < 0 if fixup < 0
perr = -fixup perr = -fixup
fin fin
if !(systemflags & modinitkeep) if !(systemflags & modinitkeep)
modend = init - defofst + bytecode modend = init - defofst + bytecode
fin fin
fin fin
// //
// Free up the end-of-module in main memory. // Free up the end-of-module in main memory.

1148
src/vmsrc/cmd.pla Normal file → Executable file

File diff suppressed because it is too large Load Diff

View File

@ -17,32 +17,32 @@ int show_state = 0;
/* /*
* Bytecode memory * Bytecode memory
*/ */
#define BYTE_PTR(bp) ((byte)((bp)[0])) #define BYTE_PTR(bp) ((byte)((bp)[0]))
#define WORD_PTR(bp) ((word)((bp)[0] | ((bp)[1] << 8))) #define WORD_PTR(bp) ((word)((bp)[0] | ((bp)[1] << 8)))
#define UWORD_PTR(bp) ((uword)((bp)[0] | ((bp)[1] << 8))) #define UWORD_PTR(bp) ((uword)((bp)[0] | ((bp)[1] << 8)))
#define TO_UWORD(w) ((uword)((w))) #define TO_UWORD(w) ((uword)((w)))
#define MOD_ADDR 0x1000 #define MOD_ADDR 0x1000
#define DEF_CALL 0x0800 #define DEF_CALL 0x0800
#define DEF_CALLSZ 0x0800 #define DEF_CALLSZ 0x0800
#define DEF_ENTRYSZ 6 #define DEF_ENTRYSZ 6
#define MEM_SIZE 65536 #define MEM_SIZE 65536
byte mem_data[MEM_SIZE]; byte mem_data[MEM_SIZE];
uword sp = 0x01FE, fp = 0xFFFF, heap = 0x0200, deftbl = DEF_CALL, lastdef = DEF_CALL; uword sp = 0x01FE, fp = 0xFFFF, heap = 0x0200, deftbl = DEF_CALL, lastdef = DEF_CALL;
#define PHA(b) (mem_data[sp--]=(b)) #define PHA(b) (mem_data[sp--]=(b))
#define PLA() (mem_data[++sp]) #define PLA (mem_data[++sp])
#define EVAL_STACKSZ 16 #define EVAL_STACKSZ 16
#define PUSH(v) (*(--esp))=(v) #define PUSH(v) (*(--esp))=(v)
#define POP ((word)(*(esp++))) #define POP ((word)(*(esp++)))
#define UPOP ((uword)(*(esp++))) #define UPOP ((uword)(*(esp++)))
#define TOS (esp[0]) #define TOS (esp[0])
word eval_stack[EVAL_STACKSZ]; word eval_stack[EVAL_STACKSZ];
word *esp = eval_stack + EVAL_STACKSZ; word *esp = eval_stack + EVAL_STACKSZ;
#define SYMTBLSZ 1024 #define SYMTBLSZ 1024
#define SYMSZ 16 #define SYMSZ 16
#define MODTBLSZ 128 #define MODTBLSZ 128
#define MODSZ 16 #define MODSZ 16
#define MODLSTSZ 32 #define MODLSTSZ 32
byte symtbl[SYMTBLSZ]; byte symtbl[SYMTBLSZ];
byte *lastsym = symtbl; byte *lastsym = symtbl;
byte modtbl[MODTBLSZ]; byte modtbl[MODTBLSZ];
@ -53,7 +53,7 @@ byte *lastmod = modtbl;
void interp(code *ip); void interp(code *ip);
/* /*
* Utility routines. * Utility routines.
* *
* A DCI string is one that has the high bit set for every character except the last. * A DCI string is one that has the high bit set for every character except the last.
* More efficient than C or Pascal strings. * More efficient than C or Pascal strings.
*/ */
@ -126,7 +126,7 @@ void dump_tbl(byte *tbl)
putchar(':'); putchar(':');
while (len++ < 15) while (len++ < 15)
putchar(' '); putchar(' ');
printf("$%04X\n", tbl[0] | (tbl[1] << 8)); printf("$%04X\n", tbl[0] | (tbl[1] << 8));
tbl += 2; tbl += 2;
} }
} }
@ -248,7 +248,7 @@ int load_mod(byte *mod)
moddep = header + 1; moddep = header + 1;
modsize = header[0] | (header[1] << 8); modsize = header[0] | (header[1] << 8);
magic = header[2] | (header[3] << 8); magic = header[2] | (header[3] << 8);
if (magic == 0xDA7E) if (magic == 0xDA7F)
{ {
/* /*
* This is a relocatable bytecode module. * This is a relocatable bytecode module.
@ -282,7 +282,7 @@ int load_mod(byte *mod)
} }
/* /*
* Alloc heap space for relocated module (data + bytecode). * Alloc heap space for relocated module (data + bytecode).
*/ */
moddep += 1; moddep += 1;
hdrlen = moddep - header; hdrlen = moddep - header;
len -= hdrlen; len -= hdrlen;
@ -381,7 +381,7 @@ int load_mod(byte *mod)
{ {
if (show_state) printf("BYTE"); if (show_state) printf("BYTE");
mem_data[addr] = fixup; mem_data[addr] = fixup;
} }
} }
else else
{ {
@ -502,18 +502,18 @@ void call(uword pc)
exit(1); exit(1);
} }
} }
/* /*
* OPCODE TABLE * OPCODE TABLE
* *
OPTBL: DW ZERO,ADD,SUB,MUL,DIV,MOD,INCR,DECR ; 00 02 04 06 08 0A 0C 0E OPTBL: DW ZERO,ADD,SUB,MUL,DIV,MOD,INCR,DECR ; 00 02 04 06 08 0A 0C 0E
DW NEG,COMP,AND,IOR,XOR,SHL,SHR,IDXW ; 10 12 14 16 18 1A 1C 1E DW NEG,COMP,AND,IOR,XOR,SHL,SHR,IDXW ; 10 12 14 16 18 1A 1C 1E
DW NOT,LOR,LAND,LA,LLA,CB,CW,CS ; 20 22 24 26 28 2A 2C 2E DW NOT,LOR,LAND,LA,LLA,CB,CW,CS ; 20 22 24 26 28 2A 2C 2E
DW DROP,DUP,PUSH,PULL,BRGT,BRLT,BREQ,BRNE ; 30 32 34 36 38 3A 3C 3E DW DROP,DUP,PUSH,PULL,BRGT,BRLT,BREQ,BRNE ; 30 32 34 36 38 3A 3C 3E
DW ISEQ,ISNE,ISGT,ISLT,ISGE,ISLE,BRFLS,BRTRU ; 40 42 44 46 48 4A 4C 4E DW ISEQ,ISNE,ISGT,ISLT,ISGE,ISLE,BRFLS,BRTRU ; 40 42 44 46 48 4A 4C 4E
DW BRNCH,IBRNCH,CALL,ICAL,ENTER,LEAVE,RET,??? ; 50 52 54 56 58 5A 5C 5E DW BRNCH,IBRNCH,CALL,ICAL,ENTER,LEAVE,RET,??? ; 50 52 54 56 58 5A 5C 5E
DW LB,LW,LLB,LLW,LAB,LAW,DLB,DLW ; 60 62 64 66 68 6A 6C 6E DW LB,LW,LLB,LLW,LAB,LAW,DLB,DLW ; 60 62 64 66 68 6A 6C 6E
DW SB,SW,SLB,SLW,SAB,SAW,DAB,DAW ; 70 72 74 76 78 7A 7C 7E DW SB,SW,SLB,SLW,SAB,SAW,DAB,DAW ; 70 72 74 76 78 7A 7C 7E
*/ */
void interp(code *ip) void interp(code *ip)
{ {
@ -533,9 +533,9 @@ void interp(code *ip)
} }
switch (*ip++) switch (*ip++)
{ {
/* /*
* 0x00-0x0F * 0x00-0x0F
*/ */
case 0x00: // ZERO : TOS = 0 case 0x00: // ZERO : TOS = 0
PUSH(0); PUSH(0);
break; break;
@ -656,13 +656,11 @@ void interp(code *ip)
PUSH(val); PUSH(val);
break; break;
case 0x34: // PUSH : TOSP = TOS case 0x34: // PUSH : TOSP = TOS
val = POP; val = esp - eval_stack;
PHA(val >> 8);
PHA(val); PHA(val);
break; break;
case 0x36: // PULL : TOS = TOSP case 0x36: // PULL : TOS = TOSP
PUSH(mem_data[sp] | (mem_data[sp + 1] << 8)); esp = eval_stack + PLA;
sp += 2;
break; break;
case 0x38: // BRGT : TOS-1 > TOS ? IP += (IP) case 0x38: // BRGT : TOS-1 > TOS ? IP += (IP)
val = POP; val = POP;
@ -775,7 +773,7 @@ void interp(code *ip)
printf("\n"); printf("\n");
break; break;
case 0x5A: // LEAVE : DEL FRAME, IP = TOFP case 0x5A: // LEAVE : DEL FRAME, IP = TOFP
fp += PLA(); fp += PLA;
case 0x5C: // RET : IP = TOFP case 0x5C: // RET : IP = TOFP
return; return;
case 0x5E: // ??? case 0x5E: // ???
@ -822,14 +820,14 @@ void interp(code *ip)
/* /*
* 0x70-0x7F * 0x70-0x7F
*/ */
case 0x70: // SB : BYTE (TOS) = TOS-1 case 0x70: // SB : BYTE (TOS-1) = TOS
val = POP;
ea = UPOP; ea = UPOP;
val = POP;
mem_data[ea] = val; mem_data[ea] = val;
break; break;
case 0x72: // SW : WORD (TOS) = TOS-1 case 0x72: // SW : WORD (TOS-1) = TOS
val = POP;
ea = UPOP; ea = UPOP;
val = POP;
mem_data[ea] = val; mem_data[ea] = val;
mem_data[ea + 1] = val >> 8; mem_data[ea + 1] = val >> 8;
break; break;
@ -889,7 +887,7 @@ int main(int argc, char **argv)
{ {
byte dci[32]; byte dci[32];
int i; int i;
if (--argc) if (--argc)
{ {
argv++; argv++;

File diff suppressed because it is too large Load Diff

439
src/vmsrc/plvm02.s Normal file → Executable file

File diff suppressed because it is too large Load Diff

View File

@ -218,7 +218,7 @@ _DIVEX INX
OPTBL !WORD ZERO,ADD,SUB,MUL,DIV,MOD,INCR,DECR ; 00 02 04 06 08 0A 0C 0E OPTBL !WORD ZERO,ADD,SUB,MUL,DIV,MOD,INCR,DECR ; 00 02 04 06 08 0A 0C 0E
!WORD NEG,COMP,BAND,IOR,XOR,SHL,SHR,IDXW ; 10 12 14 16 18 1A 1C 1E !WORD NEG,COMP,BAND,IOR,XOR,SHL,SHR,IDXW ; 10 12 14 16 18 1A 1C 1E
!WORD LNOT,LOR,LAND,LA,LLA,CB,CW,CS ; 20 22 24 26 28 2A 2C 2E !WORD LNOT,LOR,LAND,LA,LLA,CB,CW,CS ; 20 22 24 26 28 2A 2C 2E
!WORD DROP,DUP,PUSH,PULL,BRGT,BRLT,BREQ,BRNE ; 30 32 34 36 38 3A 3C 3E !WORD DROP,DUP,PUSHEP,PULLEP,BRGT,BRLT,BREQ,BRNE ; 30 32 34 36 38 3A 3C 3E
!WORD ISEQ,ISNE,ISGT,ISLT,ISGE,ISLE,BRFLS,BRTRU ; 40 42 44 46 48 4A 4C 4E !WORD ISEQ,ISNE,ISGT,ISLT,ISGE,ISLE,BRFLS,BRTRU ; 40 42 44 46 48 4A 4C 4E
!WORD BRNCH,IBRNCH,CALL,ICAL,ENTER,LEAVE,RET,NEXTOP ; 50 52 54 56 58 5A 5C 5E !WORD BRNCH,IBRNCH,CALL,ICAL,ENTER,LEAVE,RET,NEXTOP ; 50 52 54 56 58 5A 5C 5E
!WORD LB,LW,LLB,LLW,LAB,LAW,DLB,DLW ; 60 62 64 66 68 6A 6C 6E !WORD LB,LW,LLB,LLW,LAB,LAW,DLB,DLW ; 60 62 64 66 68 6A 6C 6E
@ -488,23 +488,16 @@ DUP DEX
STA ESTKH,X STA ESTKH,X
JMP NEXTOP JMP NEXTOP
;* ;*
;* PUSH FROM EVAL STACK TO CALL STACK ;* PUSH EVAL STACK POINTER TO CALL STACK
;* ;*
PUSH LDA ESTKL,X PUSHEP TXA
PHA PHA
LDA ESTKH,X JMP NEXTOP
PHA
; INX
; JMP NEXTOP
JMP DROP
;* ;*
;* PULL FROM CALL STACK TO EVAL STACK ;* PULL FROM CALL STACK TO EVAL STACK
;* ;*
PULL DEX PULLEP PLA
PLA TAX
STA ESTKH,X
PLA
STA ESTKL,X
JMP NEXTOP JMP NEXTOP
;* ;*
;* CONSTANT ;* CONSTANT
@ -702,11 +695,11 @@ LAW +INC_IP
;* ;*
;* STORE VALUE TO ADDRESS ;* STORE VALUE TO ADDRESS
;* ;*
SB LDA ESTKL+1,X SB LDA ESTKL,X
STA TMPL STA TMPL
LDA ESTKH+1,X LDA ESTKH,X
STA TMPH STA TMPH
LDA ESTKL,X LDA ESTKL+1,X
STY IPY STY IPY
LDY #$00 LDY #$00
STA (TMP),Y STA (TMP),Y
@ -715,16 +708,16 @@ SB LDA ESTKL+1,X
; INX ; INX
; JMP NEXTOP ; JMP NEXTOP
JMP DROP JMP DROP
SW LDA ESTKL+1,X SW LDA ESTKL,X
STA TMPL STA TMPL
LDA ESTKH+1,X LDA ESTKH,X
STA TMPH STA TMPH
STY IPY STY IPY
LDY #$00 LDY #$00
LDA ESTKL,X LDA ESTKL+1,X
STA (TMP),Y STA (TMP),Y
INY INY
LDA ESTKH,X LDA ESTKH+1,X
STA (TMP),Y STA (TMP),Y
LDY IPY LDY IPY
INX INX

6
src/vmsrc/plvmzp.inc Normal file → Executable file
View File

@ -10,9 +10,9 @@ DST = SRC+2
DSTL = DST DSTL = DST
DSTH = DST+1 DSTH = DST+1
ESTKSZ = $20 ESTKSZ = $20
XSTK = $A0 XSTK = $A0
XSTKL = XSTK XSTKL = XSTK
XSTKH = XSTK+ESTKSZ/2 XSTKH = XSTK+ESTKSZ/2
ESTK = $C0 ESTK = $C0
ESTKL = ESTK ESTKL = ESTK
ESTKH = ESTK+ESTKSZ/2 ESTKH = ESTK+ESTKSZ/2

24
src/vmsrc/soscmd.pla Normal file → Executable file
View File

@ -34,13 +34,13 @@ predef loadmod, execmod, lookupstrmod
// //
// System variables. // System variables.
// //
word version = $0094 // 00.94 word version = $0099 // 00.99
word systemflags = 0 word systemflags = 0
byte refcons = 0 byte refcons = 0
byte devcons = 0 byte devcons = 0
word heap = $2000 word heap = $2000
byte modid = 0 byte modid = 0
byte modseg[15] byte modseg[15]
word symtbl, lastsym word symtbl, lastsym
byte perr, terr, lerr byte perr, terr, lerr
// //
@ -108,7 +108,7 @@ word = @modadrstr, @lookupstrmod
word = @machidstr, @machid word = @machidstr, @machid
word = @argstr, @cmdptr word = @argstr, @cmdptr
word = 0 word = 0
word syslibsym = @exports word syslibsym = @exports
// //
// CALL SOS // CALL SOS
// SYSCALL(CMD, PARAMS) // SYSCALL(CMD, PARAMS)
@ -411,7 +411,7 @@ asm interp
STA ESTKH,X STA ESTKH,X
RTS RTS
end end
// //
// A DCI string is one that has the high bit set for every character except the last. // A DCI string is one that has the high bit set for every character except the last.
// More efficient than C or Pascal strings. // More efficient than C or Pascal strings.
// //
@ -691,7 +691,7 @@ end
// //
def dev_control(devnum, code, list) def dev_control(devnum, code, list)
byte params[5] byte params[5]
params.0 = 3 params.0 = 3
params.1 = devnum params.1 = devnum
params.2 = code params.2 = code
@ -701,7 +701,7 @@ def dev_control(devnum, code, list)
end end
def dev_getnum(name) def dev_getnum(name)
byte params[4] byte params[4]
params.0 = 2 params.0 = 2
params:1 = name params:1 = name
params.3 = 0 params.3 = 0
@ -710,7 +710,7 @@ def dev_getnum(name)
end end
def dev_info(devnum, name, list, listlen) def dev_info(devnum, name, list, listlen)
byte params[7] byte params[7]
params.0 = 4 params.0 = 4
params.1 = devnum params.1 = devnum
params:2 = name params:2 = name
@ -724,7 +724,7 @@ end
// //
def seg_request(base, limit, id) def seg_request(base, limit, id)
byte params[7] byte params[7]
params.0 = 4 params.0 = 4
params:1 = base params:1 = base
params:3 = limit params:3 = limit
@ -735,7 +735,7 @@ def seg_request(base, limit, id)
end end
def seg_find(search, base, limit, pages, id) def seg_find(search, base, limit, pages, id)
byte params[10] byte params[10]
params.0 = 6 params.0 = 6
params.1 = search params.1 = search
params.2 = id params.2 = id
@ -750,7 +750,7 @@ def seg_find(search, base, limit, pages, id)
end end
def seg_release(segnum) def seg_release(segnum)
byte params[2] byte params[2]
params.0 = 1 params.0 = 1
params.1 = segnum params.1 = segnum
perr = syscall($45, @params) perr = syscall($45, @params)
@ -948,7 +948,7 @@ def loadmod(mod)
moddep = @header.1 moddep = @header.1
defofst = modsize defofst = modsize
init = 0 init = 0
if rdlen > 4 and header:2 == $DA7E // DAVE = magic number :-) if rdlen > 4 and header:2 == $DA7F // DAVE+1 = magic number :-)
// //
// This is an EXTended RELocatable (data+bytecode) module. // This is an EXTended RELocatable (data+bytecode) module.
// //
@ -985,6 +985,8 @@ def loadmod(mod)
refnum = open(@filename, O_READ) refnum = open(@filename, O_READ)
rdlen = read(refnum, @header, 128) rdlen = read(refnum, @header, 128)
fin fin
else
return -69
fin fin
// //
// Alloc heap space for relocated module (data + bytecode). // Alloc heap space for relocated module (data + bytecode).