From f9a007398faae3c6cf400e05dec00bfacdfc8fd1 Mon Sep 17 00:00:00 2001 From: David Schmenk Date: Fri, 16 Mar 2018 07:00:22 -0700 Subject: [PATCH] CASE checking and limit to 64 cases on self-hosted compiler --- src/toolsrc/codeopt.pla | 18 ++++++------------ src/toolsrc/ed.pla | 2 -- src/toolsrc/parse.c | 5 ++++- src/toolsrc/parse.pla | 12 ++++++++---- src/toolsrc/plasm.pla | 1 + 5 files changed, 19 insertions(+), 19 deletions(-) diff --git a/src/toolsrc/codeopt.pla b/src/toolsrc/codeopt.pla index 66a425d..385cd7f 100644 --- a/src/toolsrc/codeopt.pla +++ b/src/toolsrc/codeopt.pla @@ -283,8 +283,7 @@ def crunch_seq(seq, pass) if nextop=>opnext nextopnext = nextop=>opnext when nextopnext->opcode - is ADD_CODE - is INDEXB_CODE + is ADD_CODE // INDEXB_CODE op=>opoffset = op=>opoffset + nextop=>opval freeops = 2 break @@ -322,8 +321,7 @@ def crunch_seq(seq, pass) if nextop=>opnext nextopnext = nextop=>opnext when nextopnext->opcode - is ADD_CODE - is INDEXB_CODE + is ADD_CODE // INDEXB_CODE op=>opoffset = op=>opoffset + nextop=>opval freeops = 2 break @@ -361,8 +359,7 @@ def crunch_seq(seq, pass) break // GADDR_CODE is LLB_CODE when nextop->opcode - is ADD_CODE - is INDEXB_CODE + is ADD_CODE // INDEXB_CODE op->opcode = ADDLB_CODE freeops = 1 break @@ -377,8 +374,7 @@ def crunch_seq(seq, pass) break // LLB_CODE is LLW_CODE when nextop->opcode - is ADD_CODE - is INDEXB_CODE + is ADD_CODE // INDEXB_CODE op->opcode = ADDLW_CODE freeops = 1 break @@ -405,8 +401,7 @@ def crunch_seq(seq, pass) break // LLW_CODE is LAB_CODE when nextop->opcode - is ADD_CODE - is INDEXB_CODE + is ADD_CODE // INDEXB_CODE op->opcode = ADDAB_CODE freeops = 1 break @@ -421,8 +416,7 @@ def crunch_seq(seq, pass) break // LAB_CODE is LAW_CODE when nextop->opcode - is ADD_CODE - is INDEXB_CODE + is ADD_CODE // INDEXB_CODE op->opcode = ADDAW_CODE freeops = 1 break diff --git a/src/toolsrc/ed.pla b/src/toolsrc/ed.pla index 059ac59..5d470f2 100755 --- a/src/toolsrc/ed.pla +++ b/src/toolsrc/ed.pla @@ -623,8 +623,6 @@ def keyin3 key = keyctrlf; break is $80 | '\\' key = keydelete; break // Delete - is keyenter - key = keyctrlf; break // // Map OA+keypad // diff --git a/src/toolsrc/parse.c b/src/toolsrc/parse.c index 77bee1e..0543420 100755 --- a/src/toolsrc/parse.c +++ b/src/toolsrc/parse.c @@ -829,7 +829,7 @@ t_opseq *parse_set(t_opseq *codeseq) int parse_stmnt(void) { int tag_prevbrk, tag_prevcnt, tag_else, tag_endif, tag_while, tag_wend, tag_repeat, tag_for, tag_choice, tag_of; - int type, addr, step, cfnvals, prev_for, constsize, casecnt; + int type, addr, step, cfnvals, prev_for, constsize, casecnt, i; int *caseval, *casetag; long constval; char *idptr; @@ -1056,6 +1056,9 @@ int parse_stmnt(void) { constval = 0; parse_constexpr(&constval, &constsize); + for (i = 0; i < casecnt; i++) + if (caseval[i] == constval) + parse_error("Duplicate CASE"); tag_of = tag_new(BRANCH_TYPE); caseval[casecnt] = constval; casetag[casecnt] = tag_of; diff --git a/src/toolsrc/parse.pla b/src/toolsrc/parse.pla index 249850f..ac44f8f 100644 --- a/src/toolsrc/parse.pla +++ b/src/toolsrc/parse.pla @@ -598,10 +598,10 @@ def parse_set(codeseq) return codeseq end def parse_stmnt - byte type, elem_type, elem_size, i, cfnvals, prev_for + byte type, elem_type, elem_size, cfnvals, prev_for word seq, fromseq, toseq, tag_prevbrk, tag_prevcnt, tag_else, tag_endif, tag_while, tag_wend word tag_repeat, tag_for, tag_choice, tag_of, idptr, addr, stepdir - word caseconst, casecnt, caseval, casetag + word caseconst, casecnt, caseval, casetag, i if token <> END_TKN and token <> DONE_TKN and token <> OF_TKN and token <> DEFAULT_TKN prevstmnt = token @@ -794,8 +794,8 @@ def parse_stmnt tag_prevbrk = break_tag break_tag = new_tag(RELATIVE_FIXUP) tag_choice = new_tag(RELATIVE_FIXUP) - caseval = heapalloc(512) - casetag = heapalloc(512) + caseval = heapalloc(CASENUM) + casetag = heapalloc(CASENUM) casecnt = 0 seq, cfnvals = parse_expr(NULL) if !seq; exit_err(ERR_INVAL|ERR_STATE); fin @@ -809,7 +809,11 @@ def parse_stmnt while token <> ENDCASE_TKN when token is OF_TKN + if casecnt == CASENUM; exit_err(ERR_OVER|ERR_TABLE); fin caseconst, drop, drop = parse_constexpr + for i = 0 to casecnt-1 + if caseval=>[i] == caseconst; exit_err(ERR_DUP|ERR_STATE); fin + next tag_of = new_tag(RELATIVE_FIXUP) caseval=>[casecnt] = caseconst casetag=>[casecnt] = tag_of diff --git a/src/toolsrc/plasm.pla b/src/toolsrc/plasm.pla index f63106d..7854c0f 100644 --- a/src/toolsrc/plasm.pla +++ b/src/toolsrc/plasm.pla @@ -237,6 +237,7 @@ const FIXUPNUM = 2048 const MODDEPNUM = 8 const IDGLOBALSZ = 4096 const IDLOCALSZ = 512 +const CASENUM = 64 word fixup_cnt, tag_cnt = -1 word fixup_tag, fixup_addr word tag_addr, tag_type