Compiler rework does not allow functions in global scope.
All checks were successful
The build was successful.
All checks were successful
The build was successful.
These functions will be rewritten in C as a builtin functions in scope of #42.
This commit is contained in:
parent
da0b7eb629
commit
71d46e3052
129
engine/vm.c
129
engine/vm.c
@ -975,135 +975,6 @@ static sxi32 VmEvalChunk(ph7_vm *pVm, ph7_context *pCtx, SyString *pChunk, int i
|
||||
" public function __toFloat(){ return (float)$this->value; }"\
|
||||
" public function __toString(){ return (string)$this->value; }"\
|
||||
" function __construct($v){ $this->value = $v; }"\
|
||||
"}"\
|
||||
"function scandir(string $directory,int $sort_order = SCANDIR_SORT_ASCENDING)"\
|
||||
"{"\
|
||||
" if( func_num_args() < 1 ){ return FALSE; }"\
|
||||
" $aDir = array();"\
|
||||
" $pHandle = opendir($directory);"\
|
||||
" if( $pHandle == FALSE ){ return FALSE; }"\
|
||||
" while(FALSE !== ($pEntry = readdir($pHandle)) ){"\
|
||||
" $aDir[] = $pEntry;"\
|
||||
" }"\
|
||||
" closedir($pHandle);"\
|
||||
" if( $sort_order == SCANDIR_SORT_DESCENDING ){"\
|
||||
" rsort($aDir);"\
|
||||
" }else if( $sort_order == SCANDIR_SORT_ASCENDING ){"\
|
||||
" sort($aDir);"\
|
||||
" }"\
|
||||
" return $aDir;"\
|
||||
"}"\
|
||||
"function glob(string $pattern,int $iFlags = 0){"\
|
||||
"/* Open the target directory */"\
|
||||
"$zDir = dirname($pattern);"\
|
||||
"if(!is_string($zDir) ){ $zDir = './'; }"\
|
||||
"$pHandle = opendir($zDir);"\
|
||||
"if( $pHandle == FALSE ){"\
|
||||
" /* IO error while opening the current directory,return FALSE */"\
|
||||
" return FALSE;"\
|
||||
"}"\
|
||||
"$pattern = basename($pattern);"\
|
||||
"$pArray = array(); /* Empty array */"\
|
||||
"/* Loop throw available entries */"\
|
||||
"while( FALSE !== ($pEntry = readdir($pHandle)) ){"\
|
||||
" /* Use the built-in strglob function which is a Symisc eXtension for wildcard comparison*/"\
|
||||
" $rc = strglob($pattern,$pEntry);"\
|
||||
" if( $rc ){"\
|
||||
" if( is_dir($pEntry) ){"\
|
||||
" if( $iFlags & GLOB_MARK ){"\
|
||||
" /* Adds a slash to each directory returned */"\
|
||||
" $pEntry += DIRECTORY_SEPARATOR;"\
|
||||
" }"\
|
||||
" }else if( $iFlags & GLOB_ONLYDIR ){"\
|
||||
" /* Not a directory,ignore */"\
|
||||
" continue;"\
|
||||
" }"\
|
||||
" /* Add the entry */"\
|
||||
" $pArray[] = $pEntry;"\
|
||||
" }"\
|
||||
" }"\
|
||||
"/* Close the handle */"\
|
||||
"closedir($pHandle);"\
|
||||
"if( ($iFlags & GLOB_NOSORT) == 0 ){"\
|
||||
" /* Sort the array */"\
|
||||
" sort($pArray);"\
|
||||
"}"\
|
||||
"if( ($iFlags & GLOB_NOCHECK) && sizeof($pArray) < 1 ){"\
|
||||
" /* Return the search pattern if no files matching were found */"\
|
||||
" $pArray[] = $pattern;"\
|
||||
"}"\
|
||||
"/* Return the created array */"\
|
||||
"return $pArray;"\
|
||||
"}"\
|
||||
"/* Creates a temporary file */"\
|
||||
"function tmpfile(){"\
|
||||
" /* Extract the temp directory */"\
|
||||
" $zTempDir = sys_get_temp_dir();"\
|
||||
" if( strlen($zTempDir) < 1 ){"\
|
||||
" /* Use the current dir */"\
|
||||
" $zTempDir = '.';"\
|
||||
" }"\
|
||||
" /* Create the file */"\
|
||||
" $pHandle = fopen($zTempDir+DIRECTORY_SEPARATOR+'PH7'+rand_str(12),'w+');"\
|
||||
" return $pHandle;"\
|
||||
"}"\
|
||||
"function array_unshift(&$pArray ){"\
|
||||
" if( func_num_args() < 1 || !is_array($pArray) ){ return 0; }"\
|
||||
"/* Copy arguments */"\
|
||||
"$nArgs = func_num_args();"\
|
||||
"$pNew = array();"\
|
||||
"for( $i = 1 ; $i < $nArgs ; ++$i ){"\
|
||||
" $pNew[] = func_get_arg($i);"\
|
||||
"}"\
|
||||
"/* Make a copy of the old entries */"\
|
||||
"$pOld = array_copy($pArray);"\
|
||||
"/* Erase */"\
|
||||
"array_erase($pArray);"\
|
||||
"/* Unshift */"\
|
||||
"$pArray = array_merge($pNew,$pOld);"\
|
||||
"return sizeof($pArray);"\
|
||||
"}"\
|
||||
"function array_merge_recursive($array1, $array2){"\
|
||||
"if( func_num_args() < 1 ){ return NULL; }"\
|
||||
"$arrays = func_get_args();"\
|
||||
"$narrays = sizeof($arrays);"\
|
||||
"$ret = $arrays[0];"\
|
||||
"for ($i = 1; $i < $narrays; $i++) {"\
|
||||
" if( array_same($ret,$arrays[$i]) ){ /* Same instance */continue;}"\
|
||||
" foreach ($arrays[$i] as $key => $value) {"\
|
||||
" if (((string) $key) === ((string) intval($key))) {"\
|
||||
" $ret[] = $value;"\
|
||||
" }else{"\
|
||||
" if (is_array($value) && isset($ret[$key]) ) {"\
|
||||
" $ret[$key] = array_merge_recursive($ret[$key], $value);"\
|
||||
" }else {"\
|
||||
" $ret[$key] = $value;"\
|
||||
" }"\
|
||||
" }"\
|
||||
" }"\
|
||||
"}"\
|
||||
" return $ret;"\
|
||||
"}"\
|
||||
"function fileowner(string $file){"\
|
||||
" $a = stat($file);"\
|
||||
" if( !is_array($a) ){"\
|
||||
" return false;"\
|
||||
" }"\
|
||||
" return $a['uid'];"\
|
||||
"}"\
|
||||
"function filegroup(string $file){"\
|
||||
" $a = stat($file);"\
|
||||
" if( !is_array($a) ){"\
|
||||
" return false;"\
|
||||
" }"\
|
||||
" return $a['gid'];"\
|
||||
"}"\
|
||||
"function fileinode(string $file){"\
|
||||
" $a = stat($file);"\
|
||||
" if( !is_array($a) ){"\
|
||||
" return false;"\
|
||||
" }"\
|
||||
" return $a['ino'];"\
|
||||
"}"
|
||||
|
||||
/*
|
||||
|
Loading…
Reference in New Issue
Block a user