diff --git a/engine/compiler.c b/engine/compiler.c index aa1260c..9086436 100644 --- a/engine/compiler.c +++ b/engine/compiler.c @@ -1221,6 +1221,33 @@ static sxi32 PH7_GenStateLoadLiteral(ph7_gen_state *pGen) { /* Emit the load constant instruction */ PH7_VmEmitInstr(pGen->pVm, PH7_OP_LOADC, 0, nIdx, 0, 0); return SXRET_OK; + } else if(pStr->nByte == sizeof("__DIR__") - 1 && + SyMemcmp(pStr->zString, "__DIR__", sizeof("__DIR__") - 1) == 0) { + pObj = PH7_ReserveConstObj(pGen->pVm, &nIdx); + if(pObj == 0) { + PH7_GenCompileError(pGen, E_ERROR, pToken->nLine, "Fatal, PH7 engine is running out of memory"); + return SXERR_ABORT; + } + SyString *pFile = (SyString *)SySetPeek(&pGen->pVm->aFiles); + if(pFile == 0) { + SyString pMemory; + SyStringInitFromBuf(&pMemory, ":MEMORY:", (int)sizeof(":MEMORY:") - 1); + PH7_MemObjInitFromString(pGen->pVm, pObj, &pMemory); + } else { + SyString pDir; + if(pFile->nByte > 0) { + const char *zDir; + int nLen; + zDir = PH7_ExtractDirName(pFile->zString, (int)pFile->nByte, &nLen); + SyStringInitFromBuf(&pDir, zDir, nLen); + } else { + SyStringInitFromBuf(&pDir, ".", 1); + } + PH7_MemObjInitFromString(pGen->pVm, pObj, &pDir); + } + /* Emit the load constant instruction */ + PH7_VmEmitInstr(pGen->pVm, PH7_OP_LOADC, 0, nIdx, 0, 0); + return SXRET_OK; } else if((pStr->nByte == sizeof("__FUNCTION__") - 1 && SyMemcmp(pStr->zString, "__FUNCTION__", sizeof("__FUNCTION__") - 1) == 0) || (pStr->nByte == sizeof("__METHOD__") - 1 && diff --git a/engine/constant.c b/engine/constant.c index 3e35b19..495eb66 100644 --- a/engine/constant.c +++ b/engine/constant.c @@ -144,30 +144,6 @@ static void PH7_DATE_Const(ph7_value *pVal, void *pUnused) { /* Expand */ ph7_value_string_format(pVal, "%04d-%02d-%02d", sTm.tm_year, sTm.tm_mon + 1, sTm.tm_mday); } -/* - * __DIR__ - * Directory holding the processed script. - */ -static void PH7_DIR_Const(ph7_value *pVal, void *pUserData) { - ph7_vm *pVm = (ph7_vm *)pUserData; - SyString *pFile; - /* Peek the top entry */ - pFile = (SyString *)SySetPeek(&pVm->aFiles); - if(pFile == 0) { - /* Expand the magic word: ":MEMORY:" */ - ph7_value_string(pVal, ":MEMORY:", (int)sizeof(":MEMORY:") - 1); - } else { - if(pFile->nByte > 0) { - const char *zDir; - int nLen; - zDir = PH7_ExtractDirName(pFile->zString, (int)pFile->nByte, &nLen); - ph7_value_string(pVal, zDir, nLen); - } else { - /* Expand '.' as the current directory*/ - ph7_value_string(pVal, ".", (int)sizeof(char)); - } - } -} /* * PHP_SHLIB_SUFFIX * Expand shared library suffix. @@ -1175,7 +1151,6 @@ static const ph7_builtin_constant aBuiltIn[] = { {"DIR_SEP", PH7_DIRSEP_Const }, {"__TIME__", PH7_TIME_Const }, {"__DATE__", PH7_DATE_Const }, - {"__DIR__", PH7_DIR_Const }, {"PHP_SHLIB_SUFFIX", PH7_PHP_SHLIB_SUFFIX_Const }, {"E_ERROR", PH7_E_ERROR_Const }, {"E_WARNING", PH7_E_WARNING_Const},