From 907c4b610e353dbc143d674c260912345d99f132 Mon Sep 17 00:00:00 2001 From: Daniel_Cortez Date: Wed, 29 Nov 2017 21:50:13 +0700 Subject: [PATCH] emit/__emit: Syntax change --- source/compiler/sc.h | 11 +++++++- source/compiler/sc1.c | 59 +++++++++++++++++++++++++--------------- source/compiler/sc3.c | 10 +++---- source/compiler/scvars.c | 2 +- 4 files changed, 53 insertions(+), 29 deletions(-) diff --git a/source/compiler/sc.h b/source/compiler/sc.h index f4369df..f403e45 100644 --- a/source/compiler/sc.h +++ b/source/compiler/sc.h @@ -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 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 SC_VDECL int sc_makereport; /* generate a cross-reference report */ diff --git a/source/compiler/sc1.c b/source/compiler/sc1.c index db7575b..3c0f282 100644 --- a/source/compiler/sc1.c +++ b/source/compiler/sc1.c @@ -895,7 +895,7 @@ static void resetglobals(void) sc_curstates=0; pc_memflags=0; pc_naked=FALSE; - emit_block_parsing=FALSE; + emit_parsing_mode=0; } static void initglobals(void) @@ -1652,9 +1652,10 @@ static void parse(void) break; case tEMIT: case t__EMIT: - emit_block_parsing=FALSE; + emit_parsing_mode |= epmGLOBAL; lex(&val,&str); emit_parse_line(); + emit_parsing_mode &= ~epmGLOBAL; break; case tNEW: 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) { doemit(); return; - } else if (emit_block_parsing) { + } else if ((emit_parsing_mode & epmBLOCK)!=0) { emit_parse_line(); return; - } + } /* if */ if (tok!='{') { insert_dbgline(fline); setline(TRUE); @@ -6527,33 +6528,48 @@ SC_FUNC void emit_parse_line(void) len=strlen(sc_tokens[tok-tFIRST]); else len=strlen(st); + + /* move back to the start of the last fetched token + * and copy the instruction name + */ lptr-=len; for(i=0; iaddr); - sym->usage|=uDEFINE; + } else { + sym=fetchlab(st); + setlabel((int)sym->addr); + sym->usage|=uDEFINE; + } /* 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(';'); - emit_block_parsing=FALSE; } /* if */ } @@ -6562,10 +6578,9 @@ static void doemit(void) cell val; char *st; - emit_block_parsing=FALSE; - if (matchtoken((int)'{')) { + if (matchtoken('{')) { lexpush(); - emit_block_parsing=TRUE; + emit_parsing_mode |= epmBLOCK; } else { lex(&val,&st); emit_parse_line(); diff --git a/source/compiler/sc3.c b/source/compiler/sc3.c index de9e89f..cb8ae85 100644 --- a/source/compiler/sc3.c +++ b/source/compiler/sc3.c @@ -1452,13 +1452,13 @@ static int hier2(value *lval) case t__EMIT: { cell val; char* st; - if (!matchtoken('{')) - error(38); /* extra characters on line */ - lex(&val,&st); + if (matchtoken('{')) + error(29); /* invalid expression, assumed zero */ lval->ident=iEXPRESSION; + emit_parsing_mode |= epmEXPR; + lex(&val,&st); emit_parse_line(); - if (!matchtoken('}')) - error(38); /* extra characters on line */ + emit_parsing_mode &= ~epmEXPR; return FALSE; } /* case */ default: diff --git a/source/compiler/scvars.c b/source/compiler/scvars.c index 562b767..2038ad8 100644 --- a/source/compiler/scvars.c +++ b/source/compiler/scvars.c @@ -105,7 +105,7 @@ SC_VDEFINE FILE *outf = NULL; /* (intermediate) text file written to */ SC_VDEFINE jmp_buf errbuf; -SC_VDEFINE int emit_block_parsing=FALSE; +SC_VDEFINE int emit_parsing_mode=0; #if !defined SC_LIGHT SC_VDEFINE int sc_makereport=FALSE; /* generate a cross-reference report */