From 395f6c446c7800fbecf5fd5d352bedb23918c80f Mon Sep 17 00:00:00 2001 From: belliash Date: Wed, 17 Apr 2019 07:55:32 +0200 Subject: [PATCH] Get rid of known from PHP 'elseif' construction. --- engine/compiler.c | 10 +++++----- engine/lexer.c | 1 - include/ph7int.h | 3 +-- 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/engine/compiler.c b/engine/compiler.c index 598e2b8..1e6bad5 100644 --- a/engine/compiler.c +++ b/engine/compiler.c @@ -2335,16 +2335,16 @@ static sxi32 PH7_CompileIf(ph7_gen_state *pGen) { if(pGen->pIn >= pGen->pEnd || (pGen->pIn->nType & PH7_TK_KEYWORD) == 0) { break; } - /* Ensure that the keyword ID is 'else if' or 'else' */ + /* Ensure that the keyword ID is 'else' */ nKeyID = (sxu32)SX_PTR_TO_INT(pGen->pIn->pUserData); - if((nKeyID & (PH7_KEYWORD_ELSE | PH7_KEYWORD_ELIF)) == 0) { + if(nKeyID != PH7_KEYWORD_ELSE) { break; } /* Emit the unconditional jump */ PH7_VmEmitInstr(pGen->pVm, 0, PH7_OP_JMP, 0, 0, 0, &nJumpIdx); /* Save the instruction index so we can fix it later when the jump destination is resolved */ PH7_GenStateNewJumpFixup(pCondBlock, PH7_OP_JMP, nJumpIdx); - if(nKeyID & PH7_KEYWORD_ELSE) { + if(nKeyID == PH7_KEYWORD_ELSE) { pToken = &pGen->pIn[1]; if(pToken >= pGen->pEnd || (pToken->nType & PH7_TK_KEYWORD) == 0 || SX_PTR_TO_INT(pToken->pUserData) != PH7_KEYWORD_IF) { @@ -2352,7 +2352,7 @@ static sxi32 PH7_CompileIf(ph7_gen_state *pGen) { } pGen->pIn++; /* Jump the 'else' keyword */ } - pGen->pIn++; /* Jump the 'elseif/if' keyword */ + pGen->pIn++; /* Jump the 'if' keyword */ /* Synchronize cursors */ pToken = pGen->pIn; /* Fix the false jump */ @@ -2361,7 +2361,7 @@ static sxi32 PH7_CompileIf(ph7_gen_state *pGen) { /* Fix the false jump */ PH7_GenStateFixJumps(pCondBlock, PH7_OP_JMPZ, PH7_VmInstrLength(pGen->pVm)); if(pGen->pIn < pGen->pEnd && (pGen->pIn->nType & PH7_TK_KEYWORD) && - (SX_PTR_TO_INT(pGen->pIn->pUserData) & PH7_KEYWORD_ELSE)) { + (SX_PTR_TO_INT(pGen->pIn->pUserData) == PH7_KEYWORD_ELSE)) { /* Compile the else block */ pGen->pIn++; rc = PH7_CompileBlock(&(*pGen)); diff --git a/engine/lexer.c b/engine/lexer.c index a1d3797..1697e4a 100644 --- a/engine/lexer.c +++ b/engine/lexer.c @@ -623,7 +623,6 @@ static sxu32 KeywordCode(const char *z, int n) { {"foreach", PH7_KEYWORD_FOREACH}, {"switch", PH7_KEYWORD_SWITCH}, {"else", PH7_KEYWORD_ELSE}, - {"elseif", PH7_KEYWORD_ELIF}, {"if", PH7_KEYWORD_IF}, {"while", PH7_KEYWORD_WHILE}, /* Reserved keywords */ diff --git a/include/ph7int.h b/include/ph7int.h index 6d012d4..d263f69 100644 --- a/include/ph7int.h +++ b/include/ph7int.h @@ -1564,8 +1564,7 @@ enum ph7_expr_id { /* The number '8' is reserved for PH7_TK_ID */ #define PH7_KEYWORD_IMPORT 9 /* import */ #define PH7_KEYWORD_REQUIRE 10 /* require */ -#define PH7_KEYWORD_ELIF 0x4000000 /* elseif: MUST BE A POWER OF TWO */ -#define PH7_KEYWORD_ELSE 0x8000000 /* else: MUST BE A POWER OF TWO */ +#define PH7_KEYWORD_ELSE 12 /* else */ #define PH7_KEYWORD_IF 13 /* if */ #define PH7_KEYWORD_FINAL 14 /* final */ #define PH7_KEYWORD_STATIC 16 /* static */