From cf436209eefe44fe5c6fb5edcdca9220d192f6d4 Mon Sep 17 00:00:00 2001 From: Dave Schmenk Date: Sat, 11 Nov 2017 06:51:30 -0800 Subject: [PATCH 1/2] Don't mess with interrupts in VM (work needed for unenhanced //e) --- Platform/Apple/tools/PLASMA/src/PLVM02#4000 | Bin 2495 -> 2488 bytes Platform/Apple/tools/PLASMA/src/plvm02.s | 14 +++++++------- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Platform/Apple/tools/PLASMA/src/PLVM02#4000 b/Platform/Apple/tools/PLASMA/src/PLVM02#4000 index 238e6e31354a3608917acba42f78d92f96db7e3a..c03247fd43fe5fee649a31238afb2f94acc77bbd 100644 GIT binary patch delta 402 zcmdllyhC_GUj3!ZpD!|BQoD5O(v?fkF1^3B>(Z}FoR=jot6w&|9DZ5&QuF1Nm#19* za9Qr^eIUtp^TxmHyf;FxXI<~VzW#ds_4(H?U*CWI)^)QR?l+d+ z_;N$_ruEG`msejobj9SV&(%d&k6c}HZTmHwYZ2Efuk~Czf9>5hq3ec>*C&3gt$+3E z6>08JCdwVfH%)#%=#D#AeqTww+I;opRl#fM?qCKwWb#|ayvZ?4{oK))o;}}s zQGoM>LiFTsOfKA+m)xFjc7QYWVC)=d7<^!WCJ!)zNKG1 zmVWV=;nB-cg4_Y6sWJrD3`Z%NYK}PGt1fbfb JK(VC=5diS^_D%o* delta 386 zcmdlXykB@iUj60EUoNs-QonTi($!1PFMYVQ`_k`AT$d#;Yg{(J9C2CXQp@F4m#1F- zcv=4H10czM&E}kF=5xqjgK?d#?@JZ`MG z@$-iEO{bf8FR!_B_=@RO->ZwS9=*Es+Ky|s*CMY~UF*Ge;oAFa!q<%$uTT6~TmS0S zE7IJdLX5&>eTL{JD~LwdLxot3ub%-N6iW$mF+-d5jg4qnY}-V=g^= zzV)I2=L?0H$zPdVxU(*~J>T%s=L3U6)@B#x9#+P0lP_}UvPLL;yHPQjky8c8SL0NH o@_jko)FUz^QXjNFTFH?5u=R09>w}EehY7t*2O^dN1(za(0C^be(*OVf diff --git a/Platform/Apple/tools/PLASMA/src/plvm02.s b/Platform/Apple/tools/PLASMA/src/plvm02.s index 678c1fc0..53602416 100644 --- a/Platform/Apple/tools/PLASMA/src/plvm02.s +++ b/Platform/Apple/tools/PLASMA/src/plvm02.s @@ -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 From dc790dc566706ad802711a2ab282475659d4cc81 Mon Sep 17 00:00:00 2001 From: David Schmenk Date: Sat, 25 Nov 2017 12:53:00 -0800 Subject: [PATCH 2/2] Update compiler with ternary op support --- Platform/Apple/tools/PLASMA/src/codegen.c | 12 ++++ Platform/Apple/tools/PLASMA/src/codegen.h | 5 ++ Platform/Apple/tools/PLASMA/src/lex.c | 36 ++++++++++- Platform/Apple/tools/PLASMA/src/parse.c | 74 ++++++++++++++++++----- Platform/Apple/tools/PLASMA/src/test.pla | 2 + Platform/Apple/tools/PLASMA/src/tokens.h | 6 +- 6 files changed, 117 insertions(+), 18 deletions(-) diff --git a/Platform/Apple/tools/PLASMA/src/codegen.c b/Platform/Apple/tools/PLASMA/src/codegen.c index 59632f00..968d7676 100644 --- a/Platform/Apple/tools/PLASMA/src/codegen.c +++ b/Platform/Apple/tools/PLASMA/src/codegen.c @@ -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); } diff --git a/Platform/Apple/tools/PLASMA/src/codegen.h b/Platform/Apple/tools/PLASMA/src/codegen.h index 069a3325..750adcd9 100644 --- a/Platform/Apple/tools/PLASMA/src/codegen.h +++ b/Platform/Apple/tools/PLASMA/src/codegen.h @@ -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); diff --git a/Platform/Apple/tools/PLASMA/src/lex.c b/Platform/Apple/tools/PLASMA/src/lex.c index 1bd64f51..5a42f6dd 100644 --- a/Platform/Apple/tools/PLASMA/src/lex.c +++ b/Platform/Apple/tools/PLASMA/src/lex.c @@ -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; diff --git a/Platform/Apple/tools/PLASMA/src/parse.c b/Platform/Apple/tools/PLASMA/src/parse.c index 4b87b334..54845fc7 100644 --- a/Platform/Apple/tools/PLASMA/src/parse.c +++ b/Platform/Apple/tools/PLASMA/src/parse.c @@ -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); } diff --git a/Platform/Apple/tools/PLASMA/src/test.pla b/Platform/Apple/tools/PLASMA/src/test.pla index e39124dc..1f95baa9 100644 --- a/Platform/Apple/tools/PLASMA/src/test.pla +++ b/Platform/Apple/tools/PLASMA/src/test.pla @@ -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 diff --git a/Platform/Apple/tools/PLASMA/src/tokens.h b/Platform/Apple/tools/PLASMA/src/tokens.h index 74f5735d..9f44713c 100644 --- a/Platform/Apple/tools/PLASMA/src/tokens.h +++ b/Platform/Apple/tools/PLASMA/src/tokens.h @@ -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. */