1
0
mirror of https://github.com/dschmenk/PLASMA.git synced 2025-04-05 03:37:43 +00:00

More efficient call sequence

This commit is contained in:
David Schmenk 2014-11-06 14:25:49 -08:00
parent 1649610d11
commit 8faa0ff8a3
8 changed files with 96 additions and 146 deletions

View File

@ -90,7 +90,7 @@ int idconst_add(char *name, int len, int value)
int idlocal_add(char *name, int len, int type, int size)
{
char c = name[len];
if (localsize > 255)
if (localsize > 254)
{
printf("Local variable size overflow\n");
return (0);
@ -176,15 +176,6 @@ void idglobal_size(int type, int size, int constsize)
else if (size)
emit_data(0, 0, 0, size);
}
int idlocal_size(void)
{
return (localsize);
}
void idlocal_reset(void)
{
locals = 0;
localsize = 2;
}
int id_tag(char *name, int len)
{
int i;
@ -511,6 +502,8 @@ void emit_def(char *name, int is_bytecode)
if (is_bytecode)
printf("\tJSR\tINTERP\n");
}
locals = 0;
localsize = 0;
}
void emit_codetag(int tag)
{
@ -672,9 +665,9 @@ void emit_ical(void)
{
printf("\t%s\t$56\t\t\t; ICAL\n", DB);
}
void emit_leave(int framesize)
void emit_leave(void)
{
if (framesize > 2)
if (localsize)
printf("\t%s\t$5A\t\t\t; LEAVE\n", DB);
else
printf("\t%s\t$5C\t\t\t; RET\n", DB);
@ -683,10 +676,10 @@ void emit_ret(void)
{
printf("\t%s\t$5C\t\t\t; RET\n", DB);
}
void emit_enter(int framesize, int cparams)
void emit_enter(int cparams)
{
if (framesize > 2)
printf("\t%s\t$58,$%02X,$%02X\t\t; ENTER\t%d,%d\n", DB, framesize, cparams, framesize, cparams);
if (localsize)
printf("\t%s\t$58,$%02X,$%02X\t\t; ENTER\t%d,%d\n", DB, localsize, cparams, localsize, cparams);
}
void emit_start(void)
{

View File

@ -51,9 +51,9 @@ void emit_dup(void);
void emit_push(void);
void emit_pull(void);
void emit_drop(void);
void emit_leave(int framesize);
void emit_leave(void);
void emit_ret(void);
void emit_enter(int framesize, int cparams);
void emit_enter(int cparams);
void emit_start(void);
void emit_rld(void);
void emit_esd(void);

View File

@ -869,7 +869,7 @@ int parse_stmnt(void)
emit_drop();
if (!parse_expr())
emit_const(0);
emit_leave(idlocal_size());
emit_leave();
}
else
{
@ -1235,7 +1235,6 @@ int parse_defs(void)
emit_idfunc(func_tag, type, tokenstr);
emit_def(tokenstr, 1);
tokenstr[tokenlen] = c;
idlocal_reset();
if (scan() == OPEN_PAREN_TOKEN)
{
do
@ -1255,7 +1254,7 @@ int parse_defs(void)
scan();
}
while (parse_vars(LOCAL_TYPE)) next_line();
emit_enter(idlocal_size(), cfnparms);
emit_enter(cfnparms);
prevstmnt = 0;
while (parse_stmnt()) next_line();
infunc = 0;
@ -1272,7 +1271,7 @@ int parse_defs(void)
if (prevstmnt != RETURN_TOKEN)
{
emit_const(0);
emit_leave(idlocal_size());
emit_leave();
}
return (1);
}

View File

@ -34,6 +34,4 @@ int id_tag(char *name, int len);
int id_const(char *name, int len);
int id_type(char *name, int len);
void idglobal_size(int type, int size, int constsize);
int idlocal_size(void);
void idlocal_reset(void);
int tag_new(int type);

View File

@ -28,7 +28,8 @@ int show_state = 0;
#define MEM_SIZE 65536
byte mem_data[MEM_SIZE];
uword sp = 0x01FE, fp = 0xFFFF, heap = 0x0200, deftbl = DEF_CALL, lastdef = DEF_CALL;
#define PHA(b) (mem_data[sp--]=(b))
#define PLA() (mem_data[++sp])
#define EVAL_STACKSZ 16
#define PUSH(v) (*(--esp))=(v)
#define POP ((word)(*(esp++)))
@ -656,8 +657,8 @@ void interp(code *ip)
break;
case 0x34: // PUSH : TOSP = TOS
val = POP;
mem_data[sp--] = val >> 8;
mem_data[sp--] = val;
PHA(val >> 8);
PHA(val);
break;
case 0x36: // PULL : TOS = TOSP
PUSH(mem_data[sp] | (mem_data[sp + 1] << 8));
@ -756,8 +757,7 @@ void interp(code *ip)
case 0x58: // ENTER : NEW FRAME, FOREACH PARAM LOCALVAR = TOS
frmsz = BYTE_PTR(ip);
ip++;
mem_data[fp - frmsz] = fp;
mem_data[fp - frmsz + 1] = fp >> 8;
PHA(frmsz);
if (show_state)
printf("< $%04X: $%04X > ", fp - frmsz, fp);
fp -= frmsz;
@ -766,16 +766,16 @@ void interp(code *ip)
while (parmcnt--)
{
val = POP;
mem_data[fp + parmcnt * 2 + 2] = val;
mem_data[fp + parmcnt * 2 + 3] = val >> 8;
mem_data[fp + parmcnt * 2 + 0] = val;
mem_data[fp + parmcnt * 2 + 1] = val >> 8;
if (show_state)
printf("< $%04X: $%04X > ", fp + parmcnt * 2 + 2, mem_data[fp + parmcnt * 2 + 2] | (mem_data[fp + parmcnt * 2 + 3] >> 8));
printf("< $%04X: $%04X > ", fp + parmcnt * 2 + 0, mem_data[fp + parmcnt * 2 + 0] | (mem_data[fp + parmcnt * 2 + 1] >> 8));
}
if (show_state)
printf("\n");
break;
case 0x5A: // LEAVE : DEL FRAME, IP = TOFP
fp = mem_data[fp] | (mem_data[fp + 1] << 8);
fp += PLA();
case 0x5C: // RET : IP = TOFP
return;
case 0x5E: // ???

View File

@ -842,51 +842,41 @@ ICALADR JSR $FFFF
;*
;* ENTER FUNCTION WITH FRAME SIZE AND PARAM COUNT
;*
ENTER +INC_IP
LDA IFPL
PHA
ENTER INY
LDA (IP),Y
PHA ; SAVE ON STACK FOR LEAVE
EOR #$FF
SEC
SBC (IP),Y
ADC IFPL
STA IFPL
LDA IFPH
PHA
SBC #$00
STA IFPH
+INC_IP
BCS +
DEC IFPH
+ INY
STY IPY
LDA (IP),Y
BEQ +
ASL
TAY
INY
BEQ +
- LDA ESTKH,X
STA (IFP),Y
DEY
LDA ESTKL,X
STA (IFP),Y
LDA ESTKL,X
INX
DEY
CPY #$01
STA (IFP),Y
BNE -
+ LDY #$01
PLA
STA (IFP),Y
DEY
PLA
STA (IFP),Y
LDY IPY
+ LDY IPY
JMP NEXTOP
;*
;* LEAVE FUNCTION
;*
LEAVE LDY #$01
LDA (IFP),Y
DEY
PHA
LDA (IFP),Y
LEAVE PLA
CLC
ADC IFPL
STA IFPL
PLA
STA IFPH
BCS LIFPH
RTS
LIFPH INC IFPH
RET RTS
A1CMD !SOURCE "vmsrc/a1cmd.a"
SEGEND = *

View File

@ -1441,100 +1441,77 @@ JMPTMP JMP (TMP)
;*
;* ENTER FUNCTION WITH FRAME SIZE AND PARAM COUNT
;*
ENTER +INC_IP
LDA IFPL
PHA
ENTER INY
LDA (IP),Y
PHA ; SAVE ON STACK FOR LEAVE
EOR #$FF
SEC
SBC (IP),Y
ADC IFPL
STA IFPL
LDA IFPH
PHA
SBC #$00
STA IFPH
+INC_IP
BCS +
DEC IFPH
+ INY
STY IPY
LDA (IP),Y
BEQ +
ASL
TAY
INY
BEQ +
- LDA ESTKH,X
STA (IFP),Y
DEY
LDA ESTKL,X
STA (IFP),Y
LDA ESTKL,X
INX
DEY
CPY #$01
STA (IFP),Y
BNE -
+ LDY #$01
PLA
STA (IFP),Y
DEY
PLA
STA (IFP),Y
LDY IPY
+ LDY IPY
JMP NEXTOP
;
ENTERX +INC_IP
LDA IFPL
PHA
ENTERX INY
LDA (IP),Y
PHA ; SAVE ON STACK FOR LEAVEX
EOR #$FF
SEC
SBC (IP),Y
ADC IFPL
STA IFPL
LDA IFPH
PHA
SBC #$00
STA IFPH
+INC_IP
STY IPY
BCS +
DEC IFPH
+ INY
LDA (IP),Y
STA ALTRDOFF
BEQ +
ASL
TAY
INY
BEQ +
- LDA ESTKH,X
STA (IFP),Y
DEY
LDA ESTKL,X
STA (IFP),Y
LDA ESTKL,X
INX
DEY
CPY #$01
STA (IFP),Y
BNE -
+ LDY #$01
PLA
STA (IFP),Y
DEY
PLA
STA (IFP),Y
STA ALTRDON
LDY IPY
+ STA ALTRDON
LDY #$02
JMP NEXTOP
;*
;* LEAVE FUNCTION
;*
LEAVE LDY #$01
LDA (IFP),Y
DEY
PHA
LDA (IFP),Y
LEAVE PLA
CLC
ADC IFPL
STA IFPL
PLA
STA IFPH
BCS LIFPH
RTS
LIFPH INC IFPH
RET RTS
;
LEAVEX STA ALTRDOFF
CLI
LDY #$01
LDA (IFP),Y
DEY
PHA
LDA (IFP),Y
STA IFPL
PLA
STA IFPH
CLC
ADC IFPL
STA IFPL
BCS LIFPH
RTS
RETX STA ALTRDOFF
CLI

View File

@ -938,51 +938,44 @@ ICALADR JSR $FFFF
;*
;* ENTER FUNCTION WITH FRAME SIZE AND PARAM COUNT
;*
ENTER +INC_IP
LDA IFPL
PHA
;*
;* ENTER FUNCTION WITH FRAME SIZE AND PARAM COUNT
;*
ENTER INY
LDA (IP),Y
PHA ; SAVE ON STACK FOR LEAVE
EOR #$FF
SEC
SBC (IP),Y
ADC IFPL
STA IFPL
LDA IFPH
PHA
SBC #$00
STA IFPH
+INC_IP
BCS +
DEC IFPH
+ INY
STY IPY
LDA (IP),Y
BEQ +
ASL
TAY
INY
BEQ +
- LDA ESTKH,X
STA (IFP),Y
DEY
LDA ESTKL,X
STA (IFP),Y
LDA ESTKL,X
INX
DEY
CPY #$01
STA (IFP),Y
BNE -
+ LDY #$01
PLA
STA (IFP),Y
DEY
PLA
STA (IFP),Y
LDY IPY
+ LDY IPY
JMP NEXTOP
;*
;* LEAVE FUNCTION
;*
LEAVE LDY #$01
LDA (IFP),Y
DEY
PHA
LDA (IFP),Y
LEAVE PLA
CLC
ADC IFPL
STA IFPL
PLA
STA IFPH
BCS LIFPH
RTS
LIFPH INC IFPH
RET RTS
SOSCMD = *
!SOURCE "vmsrc/soscmd.a"