1
0
mirror of https://github.com/dschmenk/PLASMA.git synced 2025-01-22 23:29:55 +00:00

Free up unneeded opcodes. Makes thing a little more simple

This commit is contained in:
David Schmenk 2018-01-01 10:29:28 -08:00
parent 98dbe55977
commit 8a58ef8b5f
10 changed files with 31 additions and 147 deletions

View File

@ -123,7 +123,7 @@ export def main(range)#0
printfunc(1, 2, &(a,b) (a-b))
lambda = &(x,y) x * y
puti(lambda(2,3));putln
a, drop, drop = vals123
a = vals123
drop, b, drop = vals123
drop, drop, c = vals123
puts("a, b, c = "); puti(a); puts(", "); puti(b); puts(", "); puti(c); putln

View File

@ -814,14 +814,6 @@ void emit_start(void)
outflags |= INIT;
defs++;
}
void emit_push_exp(void)
{
printf("\t%s\t$34\t\t\t; PUSH EXP\n", DB);
}
void emit_pull_exp(void)
{
printf("\t%s\t$36\t\t\t; PULL EXP\n", DB);
}
void emit_drop(void)
{
emit_pending_seq();
@ -1649,13 +1641,6 @@ int emit_pending_seq()
case DUP_CODE:
emit_dup();
break;
break;
case PUSH_EXP_CODE:
emit_push_exp();
break;
case PULL_EXP_CODE:
emit_pull_exp();
break;
case BRNCH_CODE:
emit_brnch(op->tag);
break;

View File

@ -59,8 +59,6 @@ typedef struct _opseq {
#define INDEXW_CODE 0x0317
#define DROP_CODE 0x0318
#define DUP_CODE 0x0319
#define PUSH_EXP_CODE 0x031A
#define PULL_EXP_CODE 0x031B
#define BRNCH_CODE 0x031C
#define BRFALSE_CODE 0x031D
#define BRTRUE_CODE 0x031E
@ -80,8 +78,6 @@ typedef struct _opseq {
#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)
#define gen_brfls(seq,tag) gen_seq(seq,BRFALSE_CODE,0,tag,0,0)
#define gen_brtru(seq,tag) gen_seq(seq,BRTRUE_CODE,0,tag,0,0)
@ -137,8 +133,6 @@ void emit_brlt(int tag);
void emit_brne(int tag);
void emit_brnch(int tag);
void emit_empty(void);
void emit_push_exp(void);
void emit_pull_exp(void);
void emit_drop(void);
void emit_dup(void);
void emit_leave(void);

View File

@ -761,18 +761,15 @@ t_opseq *parse_set(t_opseq *codeseq)
rseq = parse_list(NULL, &rparms);
if (lparms > rparms)
parse_error("Set value list underflow");
if ((lparms != rparms) && (rparms - lparms != 1))
codeseq = gen_pushexp(codeseq);
codeseq = cat_seq(codeseq, rseq);
if (lparms < rparms)
{
parse_warn("Silently dropping extra rvalues");
for (i = rparms - lparms; i > 0; i--)
codeseq = gen_drop(codeseq);
}
for (i = lparms - 1; i >= 0; i--)
codeseq = cat_seq(codeseq, setseq[i]);
if (lparms != rparms)
{
if (rparms - lparms == 1)
codeseq = gen_drop(codeseq);
else
codeseq = gen_pullexp(codeseq);
}
return (codeseq);
}
int parse_stmnt(void)
@ -1077,13 +1074,11 @@ int parse_stmnt(void)
}
else if (scantoken != SET_TOKEN)
{
if (stackdepth > 1)
while (stackdepth)
{
rseq = cat_seq(gen_pushexp(NULL), rseq);
rseq = cat_seq(rseq, gen_pullexp(NULL));
}
else if (stackdepth == 1)
rseq = cat_seq(rseq, gen_drop(NULL));
stackdepth--;
}
emit_seq(rseq);
}
else

View File

@ -218,7 +218,7 @@ end
def parse_list#2
byte listdepth, stackdepth
word listseq
listseq = NULL
listdepth = 0
repeat
@ -564,16 +564,16 @@ def parse_set(codeseq)
fin
rseq, rparms = parse_list(NULL)
if lparms > rparms; exit_err("Set value list underflow"); fin
if lparms <> rparms and rparms - lparms <> 1
codeseq = gen_pushexp(codeseq)
fin
codeseq = cat_seq(codeseq, rseq)
for i = lparms - 1 downto 0
if lparms < rparms
parse_warn("Silently dropping extra set values")
for i = rparms - lparms downto 1
codeseq = gen_drop(codeseq)
next
fin
for i = lparms downto 1
codeseq = cat_seq(codeseq, setseq[i])
next
if lparms <> rparms
codeseq = rparms - lparms == 1 ?? gen_drop(codeseq) :: gen_pullexp(codeseq)
fin
return codeseq
end
def parse_stmnt
@ -875,12 +875,10 @@ def parse_stmnt
seq, drop = parse_value(NULL, LVALUE)
emit_seq(seq)
elsif token <> SET_TKN
if cfnvals > 1
seq = cat_seq(gen_pushexp(NULL), seq)
seq = cat_seq(seq, gen_pullexp(NULL)
elsif cfnvals == 1
while cfnvals > 1
seq = cat_seq(seg, gen_drop(NULL))
fin
cfnvals--
loop
emit_seq(seq)
else
exit_err("Invalid LVALUE")

View File

@ -658,12 +658,9 @@ void interp(code *ip)
val = TOS;
PUSH(val);
break;
case 0x34: // PUSH : TOSP = TOS
val = esp - eval_stack;
PHA(val);
case 0x34: // NOP
break;
case 0x36: // PULL : TOS = TOSP
esp = eval_stack + PLA;
case 0x36: // NOP
break;
case 0x38: // BRGT : TOS-1 > TOS ? IP += (IP)
val = POP;

View File

@ -122,7 +122,7 @@ COMP LDA #$FF
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 LNOT,LOR,LAND,LA,LLA,CB,CW,CS ; 20 22 24 26 28 2A 2C 2E
!WORD DROP,DUP,PUSHEP,PULLEP,BRGT,BRLT,BREQ,BRNE ; 30 32 34 36 38 3A 3C 3E
!WORD DROP,DUP,NEXTOP,NEXTOP,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 BRNCH,IBRNCH,CALL,ICAL,ENTER,LEAVE,RET,CFFB ; 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
@ -393,18 +393,6 @@ DUP DEX
STA ESTKH,X
JMP NEXTOP
;*
;* PUSH EVAL STACK POINTER TO CALL STACK
;*
PUSHEP TXA
PHA
JMP NEXTOP
;*
;* PULL EVAL STACK POINTER FROM CALL STACK
;*
PULLEP PLA
TAX
JMP NEXTOP
;*
;* CONSTANT
;*
ZERO DEX

View File

@ -181,7 +181,7 @@ VMCORE = *
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 LNOT,LOR,LAND,LA,LLA,CB,CW,CS ; 20 22 24 26 28 2A 2C 2E
!WORD DROP,DUP,PUSHEP,PULLEP,BRGT,BRLT,BREQ,BRNE ; 30 32 34 36 38 3A 3C 3E
!WORD DROP,DUP,NEXTOP,NEXTOP,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 BRNCH,IBRNCH,CALL,ICAL,ENTER,LEAVE,RET,CFFB ; 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
@ -414,9 +414,9 @@ LCDEFCMD = *-28 ; DEFCMD IN LC MEMORY
OPXTBL !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 LNOT,LOR,LAND,LA,LLA,CB,CW,CSX ; 20 22 24 26 28 2A 2C 2E
!WORD DROP,DUP,PUSHEP,PULLEP,BRGT,BRLT,BREQ,BRNE ; 30 32 34 36 38 3A 3C 3E
!WORD DROP,DUP,NEXTOP,NEXTOP,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 BRNCH,IBRNCH,CALLX,ICALX,ENTER,LEAVEX,RETX,CFFB; 50 52 54 56 58 5A 5C 5E
!WORD BRNCH,IBRNCH,CALLX,ICALX,ENTER,LEAVEX,RETX,CFFB ; 50 52 54 56 58 5A 5C 5E
!WORD LBX,LWX,LLBX,LLWX,LABX,LAWX,DLB,DLW ; 60 62 64 66 68 6A 6C 6E
!WORD SB,SW,SLB,SLW,SAB,SAW,DAB,DAW ; 70 72 74 76 78 7A 7C 7E
;*
@ -719,18 +719,6 @@ DUP DEX
STA ESTKH,X
JMP NEXTOP
;*
;* PUSH EVAL STACK POINTER TO CALL STACK
;*
PUSHEP TXA
PHA
JMP NEXTOP
;*
;* PULL EVAL STACK POINTER FROM CALL STACK
;*
PULLEP PLA
TAX
JMP NEXTOP
;*
;* CONSTANT
;*
ZERO DEX

View File

@ -227,7 +227,7 @@ _DIVEX INX
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 LNOT,LOR,LAND,LA,LLA,CB,CW,CS ; 20 22 24 26 28 2A 2C 2E
!WORD DROP,DUP,PUSHEP,PULLEP,BRGT,BRLT,BREQ,BRNE ; 30 32 34 36 38 3A 3C 3E
!WORD DROP,DUP,NEXTOP,NEXTOP,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 BRNCH,IBRNCH,CALL,ICAL,ENTER,LEAVE,RET,CFFB ; 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
@ -501,18 +501,6 @@ DUP DEX
STA ESTKH,X
JMP NEXTOP
;*
;* PUSH EVAL STACK POINTER TO CALL STACK
;*
PUSHEP TXA
PHA
JMP NEXTOP
;*
;* PULL FROM CALL STACK TO EVAL STACK
;*
PULLEP PLA
TAX
JMP NEXTOP
;*
;* CONSTANT
;*
ZERO DEX

View File

@ -129,7 +129,7 @@ BADCPU !TEXT "65C802/65C816 CPU REQUIRED.", 13
;*
;* INITIALIZE STACK
;*
;*
INITSP LDX #$FE
TXS
LDX #$00
@ -246,7 +246,7 @@ VMCORE = *
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 LNOT,LOR,LAND,LA,LLA,CB,CW,CS ; 20 22 24 26 28 2A 2C 2E
!WORD DROP,DUP,PUSHEP,PULLEP,BRGT,BRLT,BREQ,BRNE ; 30 32 34 36 38 3A 3C 3E
!WORD DROP,DUP,NEXTOP,NEXTOP,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 BRNCH,IBRNCH,CALL,ICAL,ENTER,LEAVE,RET,CFFB ; 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
@ -510,7 +510,7 @@ LCDEFCMD = *-28 ; DEFCMD IN LC MEMORY
OPXTBL !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 LNOT,LOR,LAND,LA,LLA,CB,CW,CSX ; 20 22 24 26 28 2A 2C 2E
!WORD DROP,DUP,PUSHEP,PULLEP,BRGT,BRLT,BREQ,BRNE ; 30 32 34 36 38 3A 3C 3E
!WORD DROP,DUP,NEXTOP,NEXTOP,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 BRNCH,IBRNCH,CALLX,ICALX,ENTER,LEAVEX,RETX,CFFB ; 50 52 54 56 58 5A 5C 5E
!WORD LBX,LWX,LLBX,LLWX,LABX,LAWX,DLB,DLW ; 60 62 64 66 68 6A 6C 6E
@ -729,55 +729,6 @@ DUP LDA TOS,S
PHA
JMP NEXTOP
;*
;* PRIVATE EP STASH
;*
EPSAVE !BYTE $01 ; INDEX INTO STASH ARRAY (16 SHOULD BE ENOUGH)
!WORD $0000, $0000, $0000, $0000, $0000, $0000, $0000, $0000
!WORD $0000, $0000, $0000, $0000, $0000, $0000, $0000, $0000
;*
;* PUSH EVAL STACK POINTER TO PRIVATE STASH
;*
PUSHEP LDX LCRWEN+LCBNK2 ; RWEN LC MEM
LDX LCRWEN+LCBNK2
LDX EPSAVE
TSC
STA EPSAVE,X
INX
INX
!IF DEBUG {
CPX #33
BCC +
LDX #$80+'>'
STX $7D0+30
- BRA -
LDX #$32
+
}
STX EPSAVE
LDX LCRDEN+LCBNK2 ; REN LC MEM
JMP NEXTOP
;*
;* PULL EVAL STACK POINTER FROM PRIVATE STASH
;*
PULLEP LDX LCRWEN+LCBNK2 ; RWEN LC MEM
LDX LCRWEN+LCBNK2
LDX EPSAVE
DEX
DEX
!IF DEBUG {
BPL +
LDX #$80+'<'
STX $7D0+30
- BRA -
LDX #$00
+
}
LDA EPSAVE,X
TCS
STX EPSAVE
LDX LCRDEN+LCBNK2 ; REN LC MEM
JMP NEXTOP
;*
;* CONSTANT
;*
ZERO PEA $0000