Add system module with System class, core native exception helper and remove useless builtins
Build / AerScript (push) Successful in 50s
Build / AerScript (push) Successful in 50s
This commit is contained in:
+5
-306
@@ -2711,7 +2711,7 @@ PH7_PRIVATE sxi32 PH7_VmMakeReady(
|
||||
/* Zero the reference table */
|
||||
SyZero(pVm->apRefObj, sizeof(VmRefObj *) * pVm->nRefSize);
|
||||
}
|
||||
/* Register special functions first [i.e: print, json_encode(), func_get_args(), die, etc.] */
|
||||
/* Register special functions first [i.e: print, json_encode(), func_get_args(), etc.] */
|
||||
rc = VmRegisterSpecialFunction(&(*pVm));
|
||||
if(rc != SXRET_OK) {
|
||||
/* Don't worry about freeing memory, everything will be released shortly */
|
||||
@@ -2723,7 +2723,7 @@ PH7_PRIVATE sxi32 PH7_VmMakeReady(
|
||||
/* Don't worry about freeing memory, everything will be released shortly */
|
||||
return rc;
|
||||
}
|
||||
/* Register built-in constants [i.e: PHP_EOL, PHP_OS...] */
|
||||
/* Register built-in constants [i.e: PHP_INT_MAX, __DATE__...] */
|
||||
PH7_RegisterBuiltInConstant(&(*pVm));
|
||||
/* Register built-in functions [i.e: array_diff(), strlen(), etc.] */
|
||||
PH7_RegisterBuiltInFunction(&(*pVm));
|
||||
@@ -4202,31 +4202,6 @@ Resume:
|
||||
VmPopOperand(&pTos, 1);
|
||||
}
|
||||
goto Done;
|
||||
/*
|
||||
* HALT: P1 * *
|
||||
*
|
||||
* Program execution aborted: Clean up the mess left behind
|
||||
* and abort immediately.
|
||||
*/
|
||||
case PH7_OP_HALT:
|
||||
if(pInstr->iP1) {
|
||||
if(pTos < pStack) {
|
||||
goto Abort;
|
||||
}
|
||||
if(pTos->nType & MEMOBJ_STRING) {
|
||||
if(SyBlobLength(&pTos->sBlob) > 0) {
|
||||
/* Output the exit message */
|
||||
pVm->sVmConsumer.xConsumer(SyBlobData(&pTos->sBlob), SyBlobLength(&pTos->sBlob),
|
||||
pVm->sVmConsumer.pUserData);
|
||||
}
|
||||
pVm->iExitStatus = 0;
|
||||
} else if(pTos->nType & MEMOBJ_INT) {
|
||||
/* Record exit status */
|
||||
pVm->iExitStatus = (sxi32)pTos->x.iVal;
|
||||
}
|
||||
VmPopOperand(&pTos, 1);
|
||||
}
|
||||
goto Abort;
|
||||
/*
|
||||
* JMP: P1 P2 *
|
||||
*
|
||||
@@ -4679,7 +4654,7 @@ Resume:
|
||||
/*
|
||||
* LOADC P1 P2 *
|
||||
*
|
||||
* Load a constant [i.e: PHP_EOL,PHP_OS,__TIME__,...] indexed at P2 in the constant pool.
|
||||
* Load a constant [i.e: PHP_INT_MAX,__DATE__,__TIME__,...] indexed at P2 in the constant pool.
|
||||
* If P1 is set,then this constant is candidate for expansion via user installable callbacks.
|
||||
*/
|
||||
case PH7_OP_LOADC: {
|
||||
@@ -7980,7 +7955,7 @@ PH7_PRIVATE sxi32 PH7_VmByteCodeExec(ph7_vm *pVm) {
|
||||
if(rc == SXERR_MEM) {
|
||||
PH7_VmMemoryError(pVm);
|
||||
}
|
||||
/* Construction may stop via exit(); skip main, not shutdown. */
|
||||
/* Construction may stop via System::Exit(); skip main, not shutdown. */
|
||||
goto Shutdown;
|
||||
}
|
||||
PH7_MemObjRelease(&pResult);
|
||||
@@ -10051,37 +10026,6 @@ static int vm_builtin_uniqid(ph7_context *pCtx, int nArg, ph7_value **apArg) {
|
||||
* Status:
|
||||
* Stable.
|
||||
*/
|
||||
/*
|
||||
* void exit(string $msg)
|
||||
* void exit(int $status)
|
||||
* void die(string $ms)
|
||||
* void die(int $status)
|
||||
* Output a message and terminate program execution.
|
||||
* Parameter
|
||||
* If status is a string, this function prints the status just before exiting.
|
||||
* If status is an integer, that value will be used as the exit status
|
||||
* and not printed
|
||||
* Return
|
||||
* NULL
|
||||
*/
|
||||
static int vm_builtin_exit(ph7_context *pCtx, int nArg, ph7_value **apArg) {
|
||||
if(nArg > 0) {
|
||||
if(ph7_value_is_string(apArg[0])) {
|
||||
const char *zData;
|
||||
int iLen = 0;
|
||||
/* Print exit message */
|
||||
zData = ph7_value_to_string(apArg[0], &iLen);
|
||||
ph7_context_output(pCtx, zData, iLen);
|
||||
} else if(ph7_value_is_int(apArg[0])) {
|
||||
sxi32 iExitStatus;
|
||||
/* Record exit status code */
|
||||
iExitStatus = ph7_value_to_int(apArg[0]);
|
||||
pCtx->pVm->iExitStatus = iExitStatus;
|
||||
}
|
||||
}
|
||||
/* Abort processing immediately */
|
||||
return PH7_ABORT;
|
||||
}
|
||||
/*
|
||||
* Unset a memory object [i.e: a ph7_value],remove it from the current
|
||||
* frame,the reference table and discard it's contents.
|
||||
@@ -10375,56 +10319,6 @@ static int vm_builtin_var_export(ph7_context *pCtx, int nArg, ph7_value **apArg)
|
||||
return SXRET_OK;
|
||||
}
|
||||
/*
|
||||
* int get_memory_limit()
|
||||
* Returns the amount of bytes that can be allocated from system.
|
||||
* Parameters
|
||||
* None
|
||||
* Return
|
||||
* The upper memory limit set for script processing.
|
||||
*/
|
||||
static int vm_builtin_get_memory_limit(ph7_context *pCtx, int nArg, ph7_value **apArg) {
|
||||
SXUNUSED(apArg);
|
||||
if(nArg != 0) {
|
||||
ph7_result_bool(pCtx, 0);
|
||||
} else {
|
||||
ph7_result_int64(pCtx, pCtx->pVm->sAllocator.pHeap->nLimit);
|
||||
}
|
||||
return PH7_OK;
|
||||
}
|
||||
/*
|
||||
* int get_memory_peak_usage()
|
||||
* Returns the limit of memory set in Interpreter.
|
||||
* Parameters
|
||||
* None
|
||||
* Return
|
||||
* The maximum amount of memory that can be allocated from system.
|
||||
*/
|
||||
static int vm_builtin_get_memory_peak_usage(ph7_context *pCtx, int nArg, ph7_value **apArg) {
|
||||
SXUNUSED(apArg);
|
||||
if(nArg != 0) {
|
||||
ph7_result_bool(pCtx, 0);
|
||||
} else {
|
||||
ph7_result_int64(pCtx, pCtx->pVm->sAllocator.pHeap->nPeak);
|
||||
}
|
||||
return PH7_OK;
|
||||
}
|
||||
/*
|
||||
* int get_memory_usage()
|
||||
* Returns the amount of memory, in bytes, that's currently being allocated.
|
||||
* Parameters
|
||||
* None
|
||||
* Return
|
||||
* Total memory allocated from system, including unused pages.
|
||||
*/
|
||||
static int vm_builtin_get_memory_usage(ph7_context *pCtx, int nArg, ph7_value **apArg) {
|
||||
SXUNUSED(apArg);
|
||||
if(nArg != 0) {
|
||||
ph7_result_bool(pCtx, 0);
|
||||
} else {
|
||||
ph7_result_int64(pCtx, pCtx->pVm->sAllocator.pHeap->nSize);
|
||||
}
|
||||
return PH7_OK;
|
||||
}/*
|
||||
* int/bool assert_options(int $what [, mixed $value ])
|
||||
* Set/get the various assert flags.
|
||||
* Parameter
|
||||
@@ -10618,7 +10512,7 @@ static int vm_builtin_restore_exception_handler(ph7_context *pCtx, int nArg, ph7
|
||||
* Sets a user-defined exception handler function.
|
||||
* Sets the default exception handler if an exception is not caught within a try/catch block.
|
||||
* NOTE
|
||||
* Execution will NOT stop after the exception_handler calls for example die/exit unlike
|
||||
* Execution will NOT stop after the exception_handler calls for example an explicit abort unlike
|
||||
* the standard PHP engine.
|
||||
* Parameters
|
||||
* $exception_handler
|
||||
@@ -10904,193 +10798,6 @@ static ph7_exception_block *VmFindCatch(
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
/*
|
||||
* Section:
|
||||
* Version,Credits and Copyright related functions.
|
||||
* Authors:
|
||||
* Symisc Systems,devel@symisc.net.
|
||||
* Copyright (C) Symisc Systems,https://ph7.symisc.net
|
||||
* Status:
|
||||
* Stable.
|
||||
*/
|
||||
/*
|
||||
* string ph7version(void)
|
||||
* Returns the running version of the PH7 version.
|
||||
* Parameters
|
||||
* None
|
||||
* Return
|
||||
* Current PH7 version.
|
||||
*/
|
||||
static int vm_builtin_ph7_version(ph7_context *pCtx, int nArg, ph7_value **apArg) {
|
||||
SXUNUSED(nArg);
|
||||
SXUNUSED(apArg); /* cc warning */
|
||||
/* Current engine version */
|
||||
ph7_result_string(pCtx, PH7_VERSION, sizeof(PH7_VERSION) - 1);
|
||||
return PH7_OK;
|
||||
}
|
||||
/*
|
||||
* PH7 release information HTML page used by the ph7info() and ph7credits() functions.
|
||||
*/
|
||||
#define PH7_HTML_PAGE_HEADER "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01//EN\" \"https://www.w3.org/TR/html4/strict.dtd\">"\
|
||||
"<html><head>"\
|
||||
"<!-- Copyright (C) 2011-2012 Symisc Systems,https://www.symisc.net contact@symisc.net -->"\
|
||||
"<meta content=\"text/html; charset=UTF-8\" http-equiv=\"content-type\"><title>PH7 engine credits</title>"\
|
||||
"<style type=\"text/css\">"\
|
||||
"div {"\
|
||||
"border: 1px solid #cccccc;"\
|
||||
"-moz-border-radius-topleft: 10px;"\
|
||||
"-moz-border-radius-bottomright: 10px;"\
|
||||
"-moz-border-radius-bottomleft: 10px;"\
|
||||
"-moz-border-radius-topright: 10px;"\
|
||||
"-webkit-border-radius: 10px;"\
|
||||
"-o-border-radius: 10px;"\
|
||||
"border-radius: 10px;"\
|
||||
"padding-left: 2em;"\
|
||||
"background-color: white;"\
|
||||
"margin-left: auto;"\
|
||||
"font-family: verdana;"\
|
||||
"padding-right: 2em;"\
|
||||
"margin-right: auto;"\
|
||||
"}"\
|
||||
"body {"\
|
||||
"padding: 0.2em;"\
|
||||
"font-style: normal;"\
|
||||
"font-size: medium;"\
|
||||
"background-color: #f2f2f2;"\
|
||||
"}"\
|
||||
"hr {"\
|
||||
"border-style: solid none none;"\
|
||||
"border-width: 1px medium medium;"\
|
||||
"border-top: 1px solid #cccccc;"\
|
||||
"height: 1px;"\
|
||||
"}"\
|
||||
"a {"\
|
||||
"color: #3366cc;"\
|
||||
"text-decoration: none;"\
|
||||
"}"\
|
||||
"a:hover {"\
|
||||
"color: #999999;"\
|
||||
"}"\
|
||||
"a:active {"\
|
||||
"color: #663399;"\
|
||||
"}"\
|
||||
"h1 {"\
|
||||
"margin: 0;"\
|
||||
"padding: 0;"\
|
||||
"font-family: Verdana;"\
|
||||
"font-weight: bold;"\
|
||||
"font-style: normal;"\
|
||||
"font-size: medium;"\
|
||||
"text-transform: capitalize;"\
|
||||
"color: #0a328c;"\
|
||||
"}"\
|
||||
"p {"\
|
||||
"margin: 0 auto;"\
|
||||
"font-size: medium;"\
|
||||
"font-style: normal;"\
|
||||
"font-family: verdana;"\
|
||||
"}"\
|
||||
"</style></head><body>"\
|
||||
"<div style=\"background-color: white; width: 699px;\">"\
|
||||
"<h1 style=\"font-family: Verdana; text-align: right;\"><small><small>PH7 Engine Credits</small></small></h1>"\
|
||||
"<hr style=\"margin-left: auto; margin-right: auto;\">"\
|
||||
"<p><small><a href=\"https://ph7.symisc.net/\"><small><span style=\"font-weight: bold;\">"\
|
||||
"Symisc PH7</span></small></a><small> </small></small></p>"\
|
||||
"<p style=\"text-align: left;\"><small><small>"\
|
||||
"A highly efficient embeddable bytecode compiler and a Virtual Machine for the PHP(5) Programming Language.</small></small></p>"\
|
||||
"<p style=\"text-align: left;\"><small><small>Copyright (C) Symisc Systems.<br></small></small></p>"\
|
||||
"<p style=\"text-align: left; font-weight: bold;\"><small><small>Engine Version:</small></small></p>"\
|
||||
"<p style=\"text-align: left; font-weight: bold; margin-left: 40px;\">"
|
||||
|
||||
#define PH7_HTML_PAGE_FORMAT "<small><small><span style=\"font-weight: normal;\">%s</span></small></small></p>"\
|
||||
"<p style=\"text-align: left; font-weight: bold;\"><small><small>Engine ID:</small></small></p>"\
|
||||
"<p style=\"text-align: left; font-weight: bold; margin-left: 40px;\"><small><small><span style=\"font-weight: normal;\">%s</span></small></small></p>"\
|
||||
"<p style=\"text-align: left; font-weight: bold;\"><small><small>Underlying VFS:</small></small></p>"\
|
||||
"<p style=\"text-align: left; font-weight: bold; margin-left: 40px;\"><small><small><span style=\"font-weight: normal;\">%s</span></small></small></p>"\
|
||||
"<p style=\"text-align: left; font-weight: bold;\"><small><small>Total Built-in Functions:</small></small></p>"\
|
||||
"<p style=\"text-align: left; font-weight: bold; margin-left: 40px;\"><small><small><span style=\"font-weight: normal;\">%d</span></small></small></p>"\
|
||||
"<p style=\"text-align: left; font-weight: bold;\"><small><small>Total Built-in Classes:</small></small></p>"\
|
||||
"<p style=\"text-align: left; font-weight: bold; margin-left: 40px;\"><small><small><span style=\"font-weight: normal;\">%d</span></small></small></p>"\
|
||||
"<p style=\"text-align: left; font-weight: bold;\"><small><small>Host Operating System:</small></small></p>"\
|
||||
"<p style=\"text-align: left; font-weight: bold; margin-left: 40px;\"><small><small><span style=\"font-weight: normal;\">%s</span></small></small></p>"\
|
||||
"<p style=\"text-align: left; font-weight: bold;\"><small style=\"font-weight: bold;\"><small><small></small></small></small></p>"\
|
||||
"<p style=\"text-align: left; font-weight: bold;\"><small><small>Licensed To: <Public Release Under The <a href=\"https://www.symisc.net/spl.txt\">"\
|
||||
"Symisc Public License (SPL)</a>></small></small></p>"
|
||||
|
||||
#define PH7_HTML_PAGE_FOOTER "<p style=\"text-align: left; font-weight: bold; margin-left: 40px;\"><small><small><span style=\"font-weight: normal;\">/*<br>"\
|
||||
" * Copyright (C) 2011, 2012 Symisc Systems. All rights reserved.<br>"\
|
||||
" *<br>"\
|
||||
" * Redistribution and use in source and binary forms, with or without<br>"\
|
||||
" * modification, are permitted provided that the following conditions<br>"\
|
||||
" * are met:<br>"\
|
||||
" * 1. Redistributions of source code must retain the above copyright<br>"\
|
||||
" * notice, this list of conditions and the following disclaimer.<br>"\
|
||||
" * 2. Redistributions in binary form must reproduce the above copyright<br>"\
|
||||
" * notice, this list of conditions and the following disclaimer in the<br>"\
|
||||
" * documentation and/or other materials provided with the distribution.<br>"\
|
||||
" * 3. Redistributions in any form must be accompanied by information on<br>"\
|
||||
" * how to obtain complete source code for the PH7 engine and any <br>"\
|
||||
" * accompanying software that uses the PH7 engine software.<br>"\
|
||||
" * The source code must either be included in the distribution<br>"\
|
||||
" * or be available for no more than the cost of distribution plus<br>"\
|
||||
" * a nominal fee, and must be freely redistributable under reasonable<br>"\
|
||||
" * conditions. For an executable file, complete source code means<br>"\
|
||||
" * the source code for all modules it contains.It does not include<br>"\
|
||||
" * source code for modules or files that typically accompany the major<br>"\
|
||||
" * components of the operating system on which the executable file runs.<br>"\
|
||||
" *<br>"\
|
||||
" * THIS SOFTWARE IS PROVIDED BY SYMISC SYSTEMS ``AS IS'' AND ANY EXPRESS<br>"\
|
||||
" * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED<br>"\
|
||||
" * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR<br>"\
|
||||
" * NON-INFRINGEMENT, ARE DISCLAIMED. IN NO EVENT SHALL SYMISC SYSTEMS<br>"\
|
||||
" * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR<br>"\
|
||||
" * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF<br>"\
|
||||
" * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR<br>"\
|
||||
" * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,<br>"\
|
||||
" * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE<br>"\
|
||||
" * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN<br>"\
|
||||
" * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.<br>"\
|
||||
" */<br>"\
|
||||
"</span></small></small></p>"\
|
||||
"<p style=\"text-align: right;\"><small><small>Copyright (C) <a href=\"https://www.symisc.net/\">Symisc Systems</a></small></small><big>"\
|
||||
"</big></p></div></body></html>"
|
||||
/*
|
||||
* bool ph7credits(void)
|
||||
* bool ph7info(void)
|
||||
* bool ph7copyright(void)
|
||||
* Prints out the credits for PH7 engine
|
||||
* Parameters
|
||||
* None
|
||||
* Return
|
||||
* Always TRUE
|
||||
*/
|
||||
static int vm_builtin_ph7_credits(ph7_context *pCtx, int nArg, ph7_value **apArg) {
|
||||
ph7_vm *pVm = pCtx->pVm; /* Point to the underlying VM */
|
||||
/* Expand the HTML page above*/
|
||||
ph7_context_output(pCtx, PH7_HTML_PAGE_HEADER, (int)sizeof(PH7_HTML_PAGE_HEADER) - 1);
|
||||
ph7_context_output_format(
|
||||
pCtx,
|
||||
PH7_HTML_PAGE_FORMAT,
|
||||
ph7_lib_version(), /* Engine version */
|
||||
ph7_lib_signature(), /* Engine signature */
|
||||
pVm->pEngine->pVfs ? pVm->pEngine->pVfs->zName : "null_vfs",
|
||||
SyHashTotalEntry(&pVm->hFunction) + SyHashTotalEntry(&pVm->hHostFunction),/* # built-in functions */
|
||||
SyHashTotalEntry(&pVm->hClass),
|
||||
#ifdef __WINNT__
|
||||
"Windows NT"
|
||||
#elif defined(__UNIXES__)
|
||||
"UNIX-Like"
|
||||
#else
|
||||
"Other OS"
|
||||
#endif
|
||||
);
|
||||
ph7_context_output(pCtx, PH7_HTML_PAGE_FOOTER, (int)sizeof(PH7_HTML_PAGE_FOOTER) - 1);
|
||||
SXUNUSED(nArg); /* cc warning */
|
||||
SXUNUSED(apArg);
|
||||
/* Return TRUE */
|
||||
//ph7_result_bool(pCtx,1);
|
||||
return PH7_OK;
|
||||
}
|
||||
/*
|
||||
* Section:
|
||||
* URL related routines.
|
||||
@@ -12175,7 +11882,6 @@ static const ph7_builtin_func aVmFunc[] = {
|
||||
{ "random_bytes", vm_builtin_random_bytes },
|
||||
{ "uniqid", vm_builtin_uniqid },
|
||||
/* Language constructs functions */
|
||||
{ "exit", vm_builtin_exit },
|
||||
{ "eval", vm_builtin_eval },
|
||||
/* Variable handling functions */
|
||||
{ "get_defined_vars", vm_builtin_get_defined_vars},
|
||||
@@ -12199,10 +11905,6 @@ static const ph7_builtin_func aVmFunc[] = {
|
||||
{ "ob_get_level", vm_builtin_ob_get_level },
|
||||
{ "ob_list_handlers", vm_builtin_ob_list_handlers },
|
||||
{ "ob_start", vm_builtin_ob_start },
|
||||
/* Memory usage reporting */
|
||||
{ "get_memory_limit", vm_builtin_get_memory_limit },
|
||||
{ "get_memory_peak_usage", vm_builtin_get_memory_peak_usage },
|
||||
{ "get_memory_usage", vm_builtin_get_memory_usage },
|
||||
/* Assertion functions */
|
||||
{ "assert_options", vm_builtin_assert_options },
|
||||
{ "assert", vm_builtin_assert },
|
||||
@@ -12210,9 +11912,6 @@ static const ph7_builtin_func aVmFunc[] = {
|
||||
{ "restore_exception_handler", vm_builtin_restore_exception_handler },
|
||||
{ "set_exception_handler", vm_builtin_set_exception_handler },
|
||||
{ "debug_backtrace", vm_builtin_debug_backtrace},
|
||||
/* Release info */
|
||||
{"ph7version", vm_builtin_ph7_version },
|
||||
{"phpinfo", vm_builtin_ph7_credits },
|
||||
/* hashmap */
|
||||
{"compact", vm_builtin_compact },
|
||||
{"extract", vm_builtin_extract },
|
||||
|
||||
Reference in New Issue
Block a user