This commit is contained in:
Martin Haye 2017-11-29 08:45:27 -08:00
commit c137981da2
8 changed files with 124 additions and 25 deletions

View File

@ -1062,6 +1062,13 @@ int crunch_seq(t_opseq **seq, int pass)
freeops = 1;
break;
}
if (opnext->code == BINARY_CODE(SHL_TOKEN))
{
op->code = DUP_CODE;
opnext->code = BINARY_CODE(ADD_TOKEN);
crunched = 1;
break;
}
}
switch (opnext->code)
{
@ -1667,6 +1674,11 @@ int emit_pending_seq()
case BRTRUE_CODE:
emit_brtru(op->tag);
break;
case CODETAG_CODE:
printf("_B%03d%c\n", op->tag, LBL);
break;
case NOP_CODE:
break;
default:
return (0);
}

View File

@ -73,6 +73,8 @@ typedef struct _opseq {
#define BRNCH_CODE 0x031C
#define BRFALSE_CODE 0x031D
#define BRTRUE_CODE 0x031E
#define CODETAG_CODE 0x031F
#define NOP_CODE 0x0320
#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)
@ -92,6 +94,9 @@ typedef struct _opseq {
#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)
#define gen_brnch(seq,tag) gen_seq(seq,BRNCH_CODE,0,tag,0,0)
#define gen_codetag(seq,tag) gen_seq(seq, CODETAG_CODE,0,tag,0,0)
#define gen_nop(seq) gen_seq(seq,NOP_CODE,0,0,0,0)
void emit_flags(int flags);
void emit_header(void);

View File

@ -15,7 +15,7 @@
#include "plasm.h"
char *statement, *tokenstr, *scanpos = "", *strpos = "";
t_token scantoken, prevtoken;
t_token scantoken = EOL_TOKEN, prevtoken;
int tokenlen;
long constval;
FILE* inputfile;
@ -397,6 +397,30 @@ t_token scan(void)
scanpos++;
}
break;
case ':':
if (scanpos[1] == ':')
{
scantoken = TRIELSE_TOKEN;
scanpos += 2;
}
else
{
scantoken = COLON_TOKEN;
scanpos++;
}
break;
case '?':
if (scanpos[1] == '?')
{
scantoken = TERNARY_TOKEN;
scanpos += 2;
}
else
{
scantoken = TERNARY_TOKEN;
scanpos++;
}
break;
default:
/*
* Simple single character tokens.
@ -449,6 +473,12 @@ int next_line(void)
}
else
{
if (!(scantoken == EOL_TOKEN || scantoken == EOF_TOKEN))
{
fprintf(stderr, "scantoken = %d (%c)\n", scantoken & 0x7F, scantoken & 0x7F);
parse_error("Extraneous characters");
return EOF_TOKEN;
}
statement = inputline;
scanpos = inputline;
/*
@ -501,6 +531,10 @@ int next_line(void)
scantoken = EOF_TOKEN;
return EOF_TOKEN;
}
if (scan() != EOL_TOKEN)
{
parse_error("Extraneous characters");
}
outer_inputfile = inputfile;
outer_filename = filename;
outer_lineno = lineno;

View File

@ -593,6 +593,11 @@ t_opseq *parse_value(t_opseq *codeseq, int rvalue, int *stackdepth)
type = (scantoken == PTRB_TOKEN) ? BPTR_TYPE : WPTR_TYPE;
if (!parse_const(&const_offset))
{
if (scantoken == EOL_TOKEN || scantoken == CLOSE_PAREN_TOKEN)
{
parse_error("Syntax");
return (NULL);
}
/*
* Setting type override for following operations
*/
@ -627,6 +632,11 @@ t_opseq *parse_value(t_opseq *codeseq, int rvalue, int *stackdepth)
: ((scantoken == DOT_TOKEN) ? BPTR_TYPE : WPTR_TYPE);
if (!parse_const(&const_offset))
{
if (scantoken == EOL_TOKEN || scantoken == CLOSE_PAREN_TOKEN)
{
parse_error("Syntax");
return (NULL);
}
/*
* Setting type override for following operations
*/
@ -745,6 +755,32 @@ t_opseq *parse_expr(t_opseq *codeseq, int *stackdepth)
if (stackdepth)
(*stackdepth)--;
}
/*
* Look for ternary operator
*/
if (scantoken == TERNARY_TOKEN)
{
int tag_else, tag_endtri;
int stackdepth1;
if (*stackdepth != 1)
parse_error("Ternary op must evaluate to single value");
tag_else = tag_new(BRANCH_TYPE);
tag_endtri = tag_new(BRANCH_TYPE);
codeseq = gen_brfls(codeseq, tag_else);
codeseq = parse_expr(codeseq, &stackdepth1);
if (scantoken != TRIELSE_TOKEN)
{
parse_error("Missing '::' in ternary op");
return (NULL);
}
codeseq = gen_brnch(codeseq, tag_endtri);
codeseq = gen_codetag(codeseq, tag_else);
codeseq = parse_expr(codeseq, stackdepth);
if (stackdepth1 != *stackdepth)
parse_error("Inconsistent value counts in ternary op");
codeseq = gen_codetag(codeseq, tag_endtri);
}
return (codeseq);
}
t_opseq *parse_set(t_opseq *codeseq)
@ -819,7 +855,7 @@ int parse_stmnt(void)
tag_endif = tag_new(BRANCH_TYPE);
seq = gen_brfls(seq, tag_else);
emit_seq(seq);
scan();
//scan();
do
{
while (parse_stmnt()) next_line();
@ -1074,7 +1110,7 @@ int parse_stmnt(void)
}
break;
case EOL_TOKEN:
case COMMENT_TOKEN:
//case COMMENT_TOKEN:
return (1);
case ELSE_TOKEN:
case ELSEIF_TOKEN:
@ -1130,7 +1166,7 @@ int parse_stmnt(void)
}
}
}
if (scan() != EOL_TOKEN && scantoken != COMMENT_TOKEN)
if (scan() != EOL_TOKEN /*&& scantoken != COMMENT_TOKEN*/)
{
parse_error("Extraneous characters");
return (0);
@ -1223,6 +1259,7 @@ int parse_struc(void)
struclen = tokenlen;
for (idlen = 0; idlen < struclen; idlen++)
strucid[idlen] = tokenstr[idlen];
scan();
}
while (next_line() == BYTE_TOKEN || scantoken == WORD_TOKEN || scantoken == EOL_TOKEN)
{
@ -1265,12 +1302,16 @@ int parse_struc(void)
idconst_add(idstr, idlen, offset);
offset += size;
} while (scantoken == COMMA_TOKEN);
if (scantoken != EOL_TOKEN && scantoken != COMMENT_TOKEN)
if (scantoken != EOL_TOKEN /*&& scantoken != COMMENT_TOKEN*/)
return (0);
}
if (struclen)
idconst_add(strucid, struclen, offset);
return (scantoken == END_TOKEN);
//return (scantoken == END_TOKEN);
if (scantoken != END_TOKEN)
return (0);
scan();
return (1);
}
int parse_vars(int type)
{
@ -1443,7 +1484,7 @@ int parse_vars(int type)
return (0);
}
case EOL_TOKEN:
case COMMENT_TOKEN:
//case COMMENT_TOKEN:
return (1);
default:
return (0);
@ -1467,13 +1508,13 @@ int parse_mods(void)
parse_error("Syntax error");
return (0);
}
if (scan() != EOL_TOKEN && scantoken != COMMENT_TOKEN)
if (scan() != EOL_TOKEN /*&& scantoken != COMMENT_TOKEN*/)
{
parse_error("Extraneous characters");
return (0);
}
}
if (scantoken == EOL_TOKEN || scantoken == COMMENT_TOKEN)
if (scantoken == EOL_TOKEN /*|| scantoken == COMMENT_TOKEN*/)
return (1);
emit_moddep(0, 0);
return (0);
@ -1650,7 +1691,7 @@ int parse_defs(void)
parse_error("Syntax error");
return (0);
}
if (scan() != EOL_TOKEN && scantoken != COMMENT_TOKEN)
if (scan() != EOL_TOKEN /*&& scantoken != COMMENT_TOKEN*/)
{
parse_error("Extraneous characters");
return (0);
@ -1739,18 +1780,19 @@ int parse_defs(void)
idstr[idlen] = c;
do
{
if (scantoken == EOL_TOKEN || scantoken == COMMENT_TOKEN)
next_line();
else if (scantoken != END_TOKEN)
///if (scantoken == EOL_TOKEN /*|| scantoken == COMMENT_TOKEN*/)
//next_line();
if (scantoken != END_TOKEN && scantoken != EOL_TOKEN)
{
scantoken = EOL_TOKEN;
emit_asm(inputline);
next_line();
}
}
while (scantoken != END_TOKEN);
next_line();
} while (scantoken != END_TOKEN);
scan();
return (1);
}
if (scantoken == EOL_TOKEN || scantoken == COMMENT_TOKEN)
if (scantoken == EOL_TOKEN /*|| scantoken == COMMENT_TOKEN*/)
return (1);
return (0);
}

View File

@ -244,7 +244,7 @@ IINTRPX PLA
STA IFPH
LDA #>OPXTBL
STA OPPAGE
SEI
;SEI UNTIL I KNOW WHAT TO DO WITH THE UNENHANCED IIE
STA ALTRDON
JMP FETCHOP
;*
@ -1207,9 +1207,9 @@ CALLX +INC_IP
TYA
PHA
STA ALTRDOFF
CLI
;CLI UNTIL I KNOW WHAT TO DO WITH THE UNENHANCED IIE
JSR JMPTMP
SEI
;SEI UNTIL I KNOW WHAT TO DO WITH THE UNENHANCED IIE
STA ALTRDON
PLA
TAY
@ -1257,9 +1257,9 @@ ICALX LDA ESTKL,X
TYA
PHA
STA ALTRDOFF
CLI
;CLI UNTIL I KNOW WHAT TO DO WITH THE UNENHANCED IIE
JSR JMPTMP
SEI
;SEI UNTIL I KNOW WHAT TO DO WITH THE UNENHANCED IIE
STA ALTRDON
PLA
TAY
@ -1308,7 +1308,7 @@ ENTER INY
;* LEAVE FUNCTION
;*
LEAVEX STA ALTRDOFF
CLI
;CLI UNTIL I KNOW WHAT TO DO WITH THE UNENHANCED IIE
LEAVE PLA ; DEALLOCATE POOL + FRAME
CLC
ADC IFPL
@ -1323,7 +1323,7 @@ LEAVE PLA ; DEALLOCATE POOL + FRAME
RTS
;
RETX STA ALTRDOFF
CLI
;CLI UNTIL I KNOW WHAT TO DO WITH THE UNENHANCED IIE
RET LDA IFPL ; DEALLOCATE POOL
STA PPL
LDA IFPH

View File

@ -160,4 +160,6 @@ putln
puts(@constr); puti(constval); putln
puts("Signed byte constant:"); puti(-3); putln
puts("Hello from in-line string!\$7F\n")
puts(1 ?? "This is TRUE\n" :: "This is FALSE\n")
puts(0 ?? "This is TRUE\n" :: "This is FALSE\n")
done

View File

@ -7,7 +7,6 @@
* ANY KIND, either express or implied. See the License for the specific language
* governing permissions and limitations under the License.
*/
#define TOKEN(c) (0x80|(c))
#define IS_TOKEN(c) (0x80&(c))
/*
@ -54,6 +53,11 @@
#define STRUC_TOKEN TOKEN(31)
#define CONTINUE_TOKEN TOKEN(32)
//#define EVAL_TOKEN TOKEN(32)
/*
* Ternary operand operators.
*/
#define TERNARY_TOKEN TOKEN('?')
#define TRIELSE_TOKEN TOKEN('_')
/*
* Double operand operators.
*/