From 912376b65834929b9b6f6f27086202fb7ca309c1 Mon Sep 17 00:00:00 2001 From: Daniel_Cortez Date: Fri, 17 Nov 2017 19:55:27 +0700 Subject: [PATCH] emit/__emit: Check if the argument of instruction 'call' is a Pawn function --- source/compiler/sc.h | 6 ++++-- source/compiler/sc1.c | 30 ++++++++++++++++++++---------- source/compiler/sc2.c | 3 ++- 3 files changed, 26 insertions(+), 13 deletions(-) diff --git a/source/compiler/sc.h b/source/compiler/sc.h index 234c11b..7fad6a1 100644 --- a/source/compiler/sc.h +++ b/source/compiler/sc.h @@ -406,9 +406,11 @@ typedef struct s_valuepair { #define teNUMBER 339 /* integer/rational number */ #define teDATA 340 /* data (variable name or address) */ #define teLOCAL 341 /* local variable (name or offset) */ +#define teFUNCTN 342 /* Pawn function */ +#define teNATIVE 343 /* native function */ /* for assigment to "lastst" only (see SC1.C) */ -#define tEXPR 342 -#define tENDLESS 343 /* endless loop */ +#define tEXPR 344 +#define tENDLESS 345 /* endless loop */ /* (reversed) evaluation of staging buffer */ #define sSTARTREORDER 0x01 diff --git a/source/compiler/sc1.c b/source/compiler/sc1.c index 366fe3d..a36d089 100644 --- a/source/compiler/sc1.c +++ b/source/compiler/sc1.c @@ -6182,20 +6182,30 @@ static void OPHANDLER_CALL emit_do_call(char *name) int tok; tok=lex(&val,&str); - if (tok!=tSYMBOL) + if (tok!=tSYMBOL) { emit_invalid_token(tSYMBOL,tok); + return; + } sym=findglb(str,sGLOBAL); if (sym==NULL) { - error(12); /* invalid function call */ - } else { - stgwrite("\t"); - stgwrite(name); - stgwrite(" ."); - stgwrite(str); - stgwrite("\n"); - code_idx+=opcodes(1)+opargs(1); - markusage(sym,uREAD); + error(17,str); /* undefined symbol */ + return; } + if (sym->ident!=iFUNCTN && sym->ident!=iREFFUNC && sym->ident!=iVARARGS) { + emit_invalid_token(teFUNCTN,(sym->ident==iCONSTEXPR) ? teNUMBER : teDATA); + return; + } + if ((sym->usage & uNATIVE)!=0) { + emit_invalid_token(teFUNCTN,teNATIVE); + return; + } + stgwrite("\t"); + stgwrite(name); + stgwrite(" ."); + stgwrite(str); + stgwrite("\n"); + code_idx+=opcodes(1)+opargs(1); + markusage(sym,uREAD); } static EMIT_OPCODE emit_opcodelist[] = { diff --git a/source/compiler/sc2.c b/source/compiler/sc2.c index b693eaa..14c280b 100644 --- a/source/compiler/sc2.c +++ b/source/compiler/sc2.c @@ -2097,7 +2097,8 @@ char *sc_tokens[] = { "#tryinclude", "#undef", "#warning", ";", ";", "-integer value-", "-rational value-", "-identifier-", "-label-", "-string-", - "-numeric value-", "-data offset-", "-local variable-" + "-numeric value-", "-data offset-", "-local variable-", "-function-", + "-native function-" }; SC_FUNC int lex(cell *lexvalue,char **lexsym)