From a19b740a287a2f86232dc253669a42265cc16c94 Mon Sep 17 00:00:00 2001 From: Daniel_Cortez Date: Wed, 31 Jan 2018 19:15:10 +0700 Subject: [PATCH] emit: Allow the use of labels in arguments of type 'any' --- source/compiler/sc.h | 1 + source/compiler/sc1.c | 11 ++++++----- source/compiler/sc4.c | 3 +++ source/compiler/sc6.c | 8 +++++++- 4 files changed, 17 insertions(+), 6 deletions(-) diff --git a/source/compiler/sc.h b/source/compiler/sc.h index 46ff20a..e38b147 100644 --- a/source/compiler/sc.h +++ b/source/compiler/sc.h @@ -478,6 +478,7 @@ typedef enum s_optmark { #define eotNUMBER 0 #define eotFUNCTION 1 +#define eotLABEL 2 typedef struct s_emit_outval { int type; union { diff --git a/source/compiler/sc1.c b/source/compiler/sc1.c index 3a773cb..5d7ff97 100644 --- a/source/compiler/sc1.c +++ b/source/compiler/sc1.c @@ -5981,10 +5981,12 @@ fetchtok: break; } /* if */ if (sym->ident==iLABEL) { - tok=tLABEL; - goto invalid_token; - } /* if */ - if (sym->ident==iFUNCTN || sym->ident==iREFFUNC) { + if (neg!=FALSE) + goto invalid_token_neg; + sym->usage|=uREAD; + p->type=eotLABEL; + p->value.ucell=(ucell)sym->addr; + } else if (sym->ident==iFUNCTN || sym->ident==iREFFUNC) { if (neg!=FALSE) goto invalid_token_neg; if ((sym->usage & uNATIVE)!=0 && (sym->usage & uREAD)==0 && sym->addr>=0) @@ -6024,7 +6026,6 @@ fetchtok: break; } /* if */ default: - invalid_token: emit_invalid_token(teNUMERIC,tok); } /* switch */ } diff --git a/source/compiler/sc4.c b/source/compiler/sc4.c index b335ddb..410f7a9 100644 --- a/source/compiler/sc4.c +++ b/source/compiler/sc4.c @@ -1390,6 +1390,9 @@ SC_FUNC void outinstr(const char *name, emit_outval params[],int numparams) stgwrite(" "); switch (params[i].type) { + case eotLABEL: + stgwrite("l."); + /* fallthrough */ case eotNUMBER: stgwrite(itoh(params[i].value.ucell)); break; diff --git a/source/compiler/sc6.c b/source/compiler/sc6.c index 0216f41..21b5806 100644 --- a/source/compiler/sc6.c +++ b/source/compiler/sc6.c @@ -102,7 +102,7 @@ static ucell getparam(const char *s,char **n) char name[sNAMEMAX+1]; symbol *sym; - if (*s=='.') { + if (s[0]=='.') { /* this is a function, find it in the global symbol table */ for (i=0; !isspace(*(++s)); i++) { assert(*s!='\0'); @@ -115,6 +115,12 @@ static ucell getparam(const char *s,char **n) assert(sym->ident==iFUNCTN || sym->ident==iREFFUNC); assert(sym->vclass==sGLOBAL); result=sym->addr; + } else if (s[0]=='l' && s[1]=='.') { + /* this is a label */ + i=(int)hex2long(s+2,NULL); + assert(i>=0 && i