From 2c378073700761df7fe73d19132039dd326a5ebe Mon Sep 17 00:00:00 2001 From: belliash Date: Tue, 31 Jul 2018 15:24:56 +0200 Subject: [PATCH] Get rid of global keyword, fixes #29 --- engine/compiler.c | 72 ----------------------------------------------- engine/lexer.c | 1 - include/ph7int.h | 1 - 3 files changed, 74 deletions(-) diff --git a/engine/compiler.c b/engine/compiler.c index 14bbf34..0399235 100644 --- a/engine/compiler.c +++ b/engine/compiler.c @@ -2538,77 +2538,6 @@ Synchronize: } return SXRET_OK; } -/* - * Compile the global construct. - * According to the PHP language reference - * In PHP global variables must be declared global inside a function if they are going - * to be used in that function. - * Example #1 Using global - * - * The above script will output 3. By declaring $a and $b global within the function - * all references to either variable will refer to the global version. There is no limit - * to the number of global variables that can be manipulated by a function. - */ -static sxi32 PH7_CompileGlobal(ph7_gen_state *pGen) { - SyToken *pTmp, *pNext = 0; - sxi32 nExpr; - sxi32 rc; - /* Jump the 'global' keyword */ - pGen->pIn++; - if(pGen->pIn >= pGen->pEnd || (pGen->pIn->nType & PH7_TK_SEMI)) { - /* Nothing to process */ - return SXRET_OK; - } - pTmp = pGen->pEnd; - nExpr = 0; - while(SXRET_OK == PH7_GetNextExpr(pGen->pIn, pTmp, &pNext)) { - if(pGen->pIn < pNext) { - pGen->pEnd = pNext; - if((pGen->pIn->nType & PH7_TK_DOLLAR) == 0) { - rc = PH7_GenCompileError(&(*pGen), E_ERROR, pGen->pIn->nLine, "global: Expected variable name"); - if(rc == SXERR_ABORT) { - return SXERR_ABORT; - } - } else { - pGen->pIn++; - if(pGen->pIn >= pGen->pEnd) { - /* Emit a warning */ - PH7_GenCompileError(&(*pGen), E_WARNING, pGen->pIn[-1].nLine, "global: Empty variable name"); - } else { - rc = PH7_CompileExpr(&(*pGen), 0, 0); - if(rc == SXERR_ABORT) { - return SXERR_ABORT; - } else if(rc != SXERR_EMPTY) { - nExpr++; - } - } - } - } - /* Next expression in the stream */ - pGen->pIn = pNext; - /* Jump trailing commas */ - while(pGen->pIn < pTmp && (pGen->pIn->nType & PH7_TK_COMMA)) { - pGen->pIn++; - } - } - /* Restore token stream */ - pGen->pEnd = pTmp; - if(nExpr > 0) { - /* Emit the uplink instruction */ - PH7_VmEmitInstr(pGen->pVm, PH7_OP_UPLINK, nExpr, 0, 0, 0); - } - return SXRET_OK; -} /* * Compile the return statement. * According to the PHP language reference @@ -5466,7 +5395,6 @@ static const LangConstruct aLangConstruct[] = { { PH7_TKWRD_RETURN, PH7_CompileReturn }, /* return statement */ { PH7_TKWRD_SWITCH, PH7_CompileSwitch }, /* Switch statement */ { PH7_TKWRD_DO, PH7_CompileDoWhile }, /* do{ }while(); statement */ - { PH7_TKWRD_GLOBAL, PH7_CompileGlobal }, /* global statement */ { PH7_TKWRD_STATIC, PH7_CompileStatic }, /* static statement */ { PH7_TKWRD_EXIT, PH7_CompileHalt }, /* exit language construct */ { PH7_TKWRD_TRY, PH7_CompileTry }, /* try statement */ diff --git a/engine/lexer.c b/engine/lexer.c index 1453761..85f9618 100644 --- a/engine/lexer.c +++ b/engine/lexer.c @@ -602,7 +602,6 @@ static sxu32 KeywordCode(const char *z, int n) { {"new", PH7_TKWRD_NEW}, {"const", PH7_TKWRD_CONST}, {"string", PH7_TKWRD_STRING}, - {"global", PH7_TKWRD_GLOBAL}, {"using", PH7_TKWRD_USING}, {"elseif", PH7_TKWRD_ELIF}, {"else", PH7_TKWRD_ELSE}, diff --git a/include/ph7int.h b/include/ph7int.h index 1b74ab7..961bc94 100644 --- a/include/ph7int.h +++ b/include/ph7int.h @@ -1511,7 +1511,6 @@ enum ph7_expr_id { #define PH7_TKWRD_CONTINUE 34 /* continue */ #define PH7_TKWRD_EXIT 35 /* exit */ #define PH7_TKWRD_ECHO 37 /* echo */ -#define PH7_TKWRD_GLOBAL 38 /* global */ #define PH7_TKWRD_IMPLEMENTS 39 /* implements */ #define PH7_TKWRD_INCONCE 40 /* include_once */ #define PH7_TKWRD_INCLUDE 41 /* include */