emit/__emit: Syntax change

This commit is contained in:
Daniel_Cortez 2017-11-29 21:50:13 +07:00
parent afc829977e
commit 907c4b610e
4 changed files with 53 additions and 29 deletions

View File

@ -870,7 +870,16 @@ SC_VDECL FILE *outf; /* file written to */
SC_VDECL jmp_buf errbuf; /* target of longjmp() on a fatal error */ SC_VDECL jmp_buf errbuf; /* target of longjmp() on a fatal error */
SC_VDECL int emit_block_parsing;
/* Possible entries for "emit_parsing_mode"
* Bits: 0 (epmBLOCK) multiline ('{}' block) syntax
* 1 (epmEXPR) used within an expression
* 2 (epmGLOBAL) used outside of function
*/
#define epmBLOCK 1
#define epmEXPR 2
#define epmGLOBAL 4
SC_VDECL int emit_parsing_mode;
#if !defined SC_LIGHT #if !defined SC_LIGHT
SC_VDECL int sc_makereport; /* generate a cross-reference report */ SC_VDECL int sc_makereport; /* generate a cross-reference report */

View File

@ -895,7 +895,7 @@ static void resetglobals(void)
sc_curstates=0; sc_curstates=0;
pc_memflags=0; pc_memflags=0;
pc_naked=FALSE; pc_naked=FALSE;
emit_block_parsing=FALSE; emit_parsing_mode=0;
} }
static void initglobals(void) static void initglobals(void)
@ -1652,9 +1652,10 @@ static void parse(void)
break; break;
case tEMIT: case tEMIT:
case t__EMIT: case t__EMIT:
emit_block_parsing=FALSE; emit_parsing_mode |= epmGLOBAL;
lex(&val,&str); lex(&val,&str);
emit_parse_line(); emit_parse_line();
emit_parsing_mode &= ~epmGLOBAL;
break; break;
case tNEW: case tNEW:
if (getclassspec(tok,&fpublic,&fstatic,&fstock,&fconst)) if (getclassspec(tok,&fpublic,&fstatic,&fstock,&fconst))
@ -5102,10 +5103,10 @@ static void statement(int *lastindent,int allow_decl)
if (tok==tEMIT || tok==t__EMIT) { if (tok==tEMIT || tok==t__EMIT) {
doemit(); doemit();
return; return;
} else if (emit_block_parsing) { } else if ((emit_parsing_mode & epmBLOCK)!=0) {
emit_parse_line(); emit_parse_line();
return; return;
} } /* if */
if (tok!='{') { if (tok!='{') {
insert_dbgline(fline); insert_dbgline(fline);
setline(TRUE); setline(TRUE);
@ -6527,33 +6528,48 @@ SC_FUNC void emit_parse_line(void)
len=strlen(sc_tokens[tok-tFIRST]); len=strlen(sc_tokens[tok-tFIRST]);
else else
len=strlen(st); len=strlen(st);
/* move back to the start of the last fetched token
* and copy the instruction name
*/
lptr-=len; lptr-=len;
for(i=0; i<sizeof(name) && (isalnum(*lptr) || *lptr=='.'); ++i,++lptr) for(i=0; i<sizeof(name) && (isalnum(*lptr) || *lptr=='.'); ++i,++lptr)
name[i]=(char)tolower(*lptr); name[i]=(char)tolower(*lptr);
name[i]='\0'; name[i]='\0';
/* find the corresponding argument handler and call it */
i=emit_findopcode(name,strlen(name)); i=emit_findopcode(name,strlen(name));
if (emit_opcodelist[i].name==NULL && *name!='\0') if (emit_opcodelist[i].name==NULL && *name!='\0')
error(104,name); /* invalid assembler instruction */ error(104,name); /* invalid assembler instruction */
emit_opcodelist[i].func(name); emit_opcodelist[i].func(name);
/* make sure the string only contains whitespaces
* and/or an optional trailing '}' if ((emit_parsing_mode & epmEXPR)==0) {
*/ /* make sure the string only contains whitespaces
while (*lptr<=' ' && *lptr!='\0') * and/or an optional trailing '}' or ';'
lptr++; */
if (*lptr!='\0' && *lptr!='}') while (*lptr<=' ' && *lptr!='\0')
error(38); /* extra characters on line */ lptr++;
if (*lptr!='\0' && *lptr!='}' && (*lptr!=';' || (emit_parsing_mode & epmBLOCK)!=0))
error(38); /* extra characters on line */
} /* if */
} else if (tok==tLABEL) { } else if (tok==tLABEL) {
if (!emit_block_parsing) if ((emit_parsing_mode & epmEXPR)!=0) {
error(38); /* extra characters on line */ error(29); /* invalid expression, assumed zero */
if (find_constval(&tagname_tab,st,0)!=NULL) } else if ((emit_parsing_mode & epmGLOBAL)!=0) {
error(11); /* invalid outside functions */
} else if (find_constval(&tagname_tab,st,0)!=NULL) {
error(221,st); /* label name shadows tagname */ error(221,st); /* label name shadows tagname */
sym=fetchlab(st); } else {
setlabel((int)sym->addr); sym=fetchlab(st);
sym->usage|=uDEFINE; setlabel((int)sym->addr);
sym->usage|=uDEFINE;
} /* if */
} /* if */ } /* if */
if (!emit_block_parsing || matchtoken('}')) { if ((emit_parsing_mode & epmBLOCK)!=0) {
if (matchtoken('}'))
emit_parsing_mode &= ~epmBLOCK;
} else if ((emit_parsing_mode & epmEXPR)==0) {
matchtoken(';'); matchtoken(';');
emit_block_parsing=FALSE;
} /* if */ } /* if */
} }
@ -6562,10 +6578,9 @@ static void doemit(void)
cell val; cell val;
char *st; char *st;
emit_block_parsing=FALSE; if (matchtoken('{')) {
if (matchtoken((int)'{')) {
lexpush(); lexpush();
emit_block_parsing=TRUE; emit_parsing_mode |= epmBLOCK;
} else { } else {
lex(&val,&st); lex(&val,&st);
emit_parse_line(); emit_parse_line();

View File

@ -1452,13 +1452,13 @@ static int hier2(value *lval)
case t__EMIT: { case t__EMIT: {
cell val; cell val;
char* st; char* st;
if (!matchtoken('{')) if (matchtoken('{'))
error(38); /* extra characters on line */ error(29); /* invalid expression, assumed zero */
lex(&val,&st);
lval->ident=iEXPRESSION; lval->ident=iEXPRESSION;
emit_parsing_mode |= epmEXPR;
lex(&val,&st);
emit_parse_line(); emit_parse_line();
if (!matchtoken('}')) emit_parsing_mode &= ~epmEXPR;
error(38); /* extra characters on line */
return FALSE; return FALSE;
} /* case */ } /* case */
default: default:

View File

@ -105,7 +105,7 @@ SC_VDEFINE FILE *outf = NULL; /* (intermediate) text file written to */
SC_VDEFINE jmp_buf errbuf; SC_VDEFINE jmp_buf errbuf;
SC_VDEFINE int emit_block_parsing=FALSE; SC_VDEFINE int emit_parsing_mode=0;
#if !defined SC_LIGHT #if !defined SC_LIGHT
SC_VDEFINE int sc_makereport=FALSE; /* generate a cross-reference report */ SC_VDEFINE int sc_makereport=FALSE; /* generate a cross-reference report */