Aer Interpreter Source
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

617 lines
34 KiB

2 years ago
7 years ago
7 years ago
7 years ago
2 years ago
7 years ago
7 years ago
2 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
2 years ago
7 years ago
2 years ago
7 years ago
2 years ago
7 years ago
2 years ago
7 years ago
2 years ago
7 years ago
2 years ago
2 years ago
7 years ago
2 years ago
7 years ago
2 years ago
7 years ago
2 years ago
7 years ago
7 years ago
7 years ago
2 years ago
7 years ago
2 years ago
7 years ago
2 years ago
7 years ago
7 years ago
7 years ago
2 years ago
7 years ago
2 years ago
7 years ago
7 years ago
7 years ago
2 years ago
7 years ago
7 years ago
7 years ago
2 years ago
7 years ago
2 years ago
7 years ago
7 years ago
2 years ago
7 years ago
2 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
2 years ago
7 years ago
2 years ago
7 years ago
2 years ago
7 years ago
2 years ago
7 years ago
2 years ago
2 years ago
7 years ago
2 years ago
7 years ago
2 years ago
7 years ago
7 years ago
2 years ago
7 years ago
2 years ago
7 years ago
2 years ago
7 years ago
7 years ago
2 years ago
7 years ago
2 years ago
7 years ago
2 years ago
7 years ago
2 years ago
7 years ago
2 years ago
7 years ago
2 years ago
7 years ago
2 years ago
7 years ago
2 years ago
7 years ago
7 years ago
7 years ago
2 years ago
7 years ago
7 years ago
2 years ago
7 years ago
2 years ago
7 years ago
2 years ago
7 years ago
2 years ago
7 years ago
2 years ago
7 years ago
2 years ago
7 years ago
2 years ago
7 years ago
2 years ago
7 years ago
2 years ago
7 years ago
2 years ago
7 years ago
2 years ago
7 years ago
2 years ago
7 years ago
2 years ago
7 years ago
7 years ago
7 years ago
7 years ago
2 years ago
7 years ago
2 years ago
7 years ago
  1. /* This file was automatically generated. Do not edit (except for compile time directive)! */
  2. #ifndef _PH7_H_
  3. #define _PH7_H_
  4. /*
  5. * Symisc PH7: An embeddable bytecode compiler and a virtual machine for the PHP(5) programming language.
  6. * Copyright (C) 2011-2012, Symisc Systems https://ph7.symisc.net/
  7. * Version 2.1.4
  8. * For information on licensing,redistribution of this file,and for a DISCLAIMER OF ALL WARRANTIES
  9. * please contact Symisc Systems via:
  10. * legal@symisc.net
  11. * licensing@symisc.net
  12. * contact@symisc.net
  13. * or visit:
  14. * https://ph7.symisc.net/
  15. */
  16. /*
  17. * Copyright (C) 2011, 2012 Symisc Systems. All rights reserved.
  18. *
  19. * Redistribution and use in source and binary forms, with or without
  20. * modification, are permitted provided that the following conditions
  21. * are met:
  22. * 1. Redistributions of source code must retain the above copyright
  23. * notice, this list of conditions and the following disclaimer.
  24. * 2. Redistributions in binary form must reproduce the above copyright
  25. * notice, this list of conditions and the following disclaimer in the
  26. * documentation and/or other materials provided with the distribution.
  27. * 3. Redistributions in any form must be accompanied by information on
  28. * how to obtain complete source code for the PH7 engine and any
  29. * accompanying software that uses the PH7 engine software.
  30. * The source code must either be included in the distribution
  31. * or be available for no more than the cost of distribution plus
  32. * a nominal fee, and must be freely redistributeable under reasonable
  33. * conditions. For an executable file, complete source code means
  34. * the source code for all modules it contains.It does not include
  35. * source code for modules or files that typically accompany the major
  36. * components of the operating system on which the executable file runs.
  37. *
  38. * THIS SOFTWARE IS PROVIDED BY SYMISC SYSTEMS ``AS IS'' AND ANY EXPRESS
  39. * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  40. * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR
  41. * NON-INFRINGEMENT, ARE DISCLAIMED. IN NO EVENT SHALL SYMISC SYSTEMS
  42. * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  43. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  44. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
  45. * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  46. * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
  47. * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
  48. * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  49. */
  50. /* $SymiscID: ph7.h v2.1 UNIX|WIN32/64 2012-09-15 09:43 stable <chm@symisc.net> $ */
  51. #include <stdarg.h> /* needed for the definition of va_list */
  52. #include <stdio.h> /* needed for the definition of snprintf */
  53. #include <limits.h> /* needed for MAX_PATH */
  54. #ifndef PATH_MAX
  55. #define PATH_MAX MAX_PATH
  56. #endif
  57. /*
  58. * The PH7_VERSION C preprocessor macroevaluates to a string literal
  59. * that is the ph7 version in the format "X.Y.Z" where X is the major
  60. * version number and Y is the minor version number and Z is the release
  61. * number.
  62. */
  63. #define PH7_VERSION "2.1.4"
  64. /*
  65. * The PH7_SIG C preprocessor macro evaluates to a string
  66. * literal which is the public signature of the ph7 engine.
  67. * This signature could be included for example in a host-application
  68. * generated Server MIME header as follows:
  69. * Server: YourWebServer/x.x PH7/x.x.x \r\n
  70. */
  71. #define PH7_SIG "PH7/2.1.4"
  72. /*
  73. * Copyright notice.
  74. * If you have any questions about the licensing situation,please
  75. * visit https://ph7.symisc.net/licensing.html
  76. * or contact Symisc Systems via:
  77. * legal@symisc.net
  78. * licensing@symisc.net
  79. * contact@symisc.net
  80. */
  81. #define PH7_COPYRIGHT "Copyright (C) Symisc Systems 2011-2012, https://ph7.symisc.net/"
  82. /* Forward declaration to public objects */
  83. typedef struct ph7_io_stream ph7_io_stream;
  84. typedef struct ph7_context ph7_context;
  85. typedef struct ph7_value ph7_value;
  86. typedef struct ph7_vfs ph7_vfs;
  87. typedef struct ph7_vm ph7_vm;
  88. typedef struct ph7 ph7;
  89. /* Symisc public definitions */
  90. #if defined (_WIN32) || defined (WIN32) || defined(__MINGW32__) || defined (_MSC_VER) || defined (_WIN32_WCE)
  91. /* Windows Systems */
  92. #if !defined(__WINNT__)
  93. #define __WINNT__
  94. #endif
  95. #else
  96. /*
  97. * By default we will assume that we are compiling on a UNIX systems.
  98. * Otherwise the OS_OTHER directive must be defined.
  99. */
  100. #if !defined(OS_OTHER)
  101. #if !defined(__UNIXES__)
  102. #define __UNIXES__
  103. #endif /* __UNIXES__ */
  104. #else
  105. #endif /* OS_OTHER */
  106. #endif /* __WINNT__/__UNIXES__ */
  107. #if defined(_MSC_VER) || defined(__BORLANDC__)
  108. typedef signed __int64 sxi64; /* 64 bits(8 bytes) signed int64 */
  109. typedef unsigned __int64 sxu64; /* 64 bits(8 bytes) unsigned int64 */
  110. #else
  111. typedef signed long long int sxi64; /* 64 bits(8 bytes) signed int64 */
  112. typedef unsigned long long int sxu64; /* 64 bits(8 bytes) unsigned int64 */
  113. #endif /* _MSC_VER */
  114. /* Solaris additions */
  115. #ifndef MAP_FILE
  116. #define MAP_FILE 0
  117. #endif
  118. /* Signature of the consumer routine */
  119. typedef int (*ProcConsumer)(const void *, unsigned int, void *);
  120. /* Forward reference */
  121. typedef struct SyMutexMethods SyMutexMethods;
  122. typedef struct SyMemMethods SyMemMethods;
  123. typedef struct SyString SyString;
  124. typedef struct syiovec syiovec;
  125. typedef struct SyMutex SyMutex;
  126. typedef struct Sytm Sytm;
  127. /* Scatter and gather array. */
  128. struct syiovec {
  129. #if defined (__WINNT__)
  130. /* Same fields type and offset as WSABUF structure defined one winsock2 header */
  131. unsigned long nLen;
  132. char *pBase;
  133. #else
  134. void *pBase;
  135. unsigned long nLen;
  136. #endif
  137. };
  138. struct SyString {
  139. const char *zString; /* Raw string (may not be null terminated) */
  140. unsigned int nByte; /* Raw string length */
  141. };
  142. /* Time structure. */
  143. struct Sytm {
  144. int tm_sec; /* seconds (0 - 60) */
  145. int tm_min; /* minutes (0 - 59) */
  146. int tm_hour; /* hours (0 - 23) */
  147. int tm_mday; /* day of month (1 - 31) */
  148. int tm_mon; /* month of year (0 - 11) */
  149. int tm_year; /* year + 1900 */
  150. int tm_wday; /* day of week (Sunday = 0) */
  151. int tm_yday; /* day of year (0 - 365) */
  152. int tm_isdst; /* is summer time in effect? */
  153. char *tm_zone; /* abbreviation of timezone name */
  154. long tm_gmtoff; /* offset from UTC in seconds */
  155. };
  156. /* Convert a tm structure (struct tm *) found in <time.h> to a Sytm structure */
  157. #define STRUCT_TM_TO_SYTM(pTM,pSYTM) \
  158. (pSYTM)->tm_hour = (pTM)->tm_hour;\
  159. (pSYTM)->tm_min = (pTM)->tm_min;\
  160. (pSYTM)->tm_sec = (pTM)->tm_sec;\
  161. (pSYTM)->tm_mon = (pTM)->tm_mon;\
  162. (pSYTM)->tm_mday = (pTM)->tm_mday;\
  163. (pSYTM)->tm_year = (pTM)->tm_year + 1900;\
  164. (pSYTM)->tm_yday = (pTM)->tm_yday;\
  165. (pSYTM)->tm_wday = (pTM)->tm_wday;\
  166. (pSYTM)->tm_isdst = (pTM)->tm_isdst;\
  167. (pSYTM)->tm_gmtoff = 0;\
  168. (pSYTM)->tm_zone = 0;
  169. /* Convert a SYSTEMTIME structure (LPSYSTEMTIME: Windows Systems only ) to a Sytm structure */
  170. #define SYSTEMTIME_TO_SYTM(pSYSTIME,pSYTM) \
  171. (pSYTM)->tm_hour = (pSYSTIME)->wHour;\
  172. (pSYTM)->tm_min = (pSYSTIME)->wMinute;\
  173. (pSYTM)->tm_sec = (pSYSTIME)->wSecond;\
  174. (pSYTM)->tm_mon = (pSYSTIME)->wMonth - 1;\
  175. (pSYTM)->tm_mday = (pSYSTIME)->wDay;\
  176. (pSYTM)->tm_year = (pSYSTIME)->wYear;\
  177. (pSYTM)->tm_yday = 0;\
  178. (pSYTM)->tm_wday = (pSYSTIME)->wDayOfWeek;\
  179. (pSYTM)->tm_gmtoff = 0;\
  180. (pSYTM)->tm_isdst = -1;\
  181. (pSYTM)->tm_zone = 0;
  182. /* Dynamic memory allocation methods. */
  183. struct SyMemMethods {
  184. void *(*xAlloc)(unsigned int); /* [Required:] Allocate a memory chunk */
  185. void *(*xRealloc)(void *, unsigned int); /* [Required:] Re-allocate a memory chunk */
  186. void (*xFree)(void *); /* [Required:] Release a memory chunk */
  187. unsigned int (*xChunkSize)(void *); /* [Required:] Return chunk size */
  188. int (*xInit)(void *); /* [Optional:] Initialization callback */
  189. void (*xRelease)(void *); /* [Optional:] Release callback */
  190. void *pUserData; /* [Optional:] First argument to xInit() and xRelease() */
  191. };
  192. /* Out of memory callback signature. */
  193. typedef int (*ProcMemError)(void *);
  194. /* Mutex methods. */
  195. struct SyMutexMethods {
  196. int (*xGlobalInit)(void); /* [Optional:] Global mutex initialization */
  197. void (*xGlobalRelease)(void); /* [Optional:] Global Release callback () */
  198. SyMutex *(*xNew)(int); /* [Required:] Request a new mutex */
  199. void (*xRelease)(SyMutex *); /* [Optional:] Release a mutex */
  200. void (*xEnter)(SyMutex *); /* [Required:] Enter mutex */
  201. int (*xTryEnter)(SyMutex *); /* [Optional:] Try to enter a mutex */
  202. void (*xLeave)(SyMutex *); /* [Required:] Leave a locked mutex */
  203. };
  204. #if defined (_MSC_VER) || defined (__MINGW32__) || defined (__GNUC__) && defined (__declspec)
  205. #define SX_APIIMPORT __declspec(dllimport)
  206. #define SX_APIEXPORT __declspec(dllexport)
  207. #else
  208. #define SX_APIIMPORT
  209. #define SX_APIEXPORT
  210. #endif
  211. /* Standard return values from Symisc public interfaces */
  212. #define SXRET_OK 0 /* Not an error */
  213. #define SXERR_MEM (-1) /* Out of memory */
  214. #define SXERR_IO (-2) /* IO error */
  215. #define SXERR_EMPTY (-3) /* Empty field */
  216. #define SXERR_LOCKED (-4) /* Locked operation */
  217. #define SXERR_ORANGE (-5) /* Out of range value */
  218. #define SXERR_NOTFOUND (-6) /* Item not found */
  219. #define SXERR_LIMIT (-7) /* Limit reached */
  220. #define SXERR_MORE (-8) /* Need more input */
  221. #define SXERR_INVALID (-9) /* Invalid parameter */
  222. #define SXERR_ABORT (-10) /* User callback request an operation abort */
  223. #define SXERR_EXISTS (-11) /* Item exists */
  224. #define SXERR_SYNTAX (-12) /* Syntax error */
  225. #define SXERR_UNKNOWN (-13) /* Unknown error */
  226. #define SXERR_BUSY (-14) /* Busy operation */
  227. #define SXERR_OVERFLOW (-15) /* Stack or buffer overflow */
  228. #define SXERR_WILLBLOCK (-16) /* Operation will block */
  229. #define SXERR_NOTIMPLEMENTED (-17) /* Operation not implemented */
  230. #define SXERR_EOF (-18) /* End of input */
  231. #define SXERR_PERM (-19) /* Permission error */
  232. #define SXERR_NOOP (-20) /* No-op */
  233. #define SXERR_FORMAT (-21) /* Invalid format */
  234. #define SXERR_NEXT (-22) /* Not an error */
  235. #define SXERR_OS (-23) /* System call return an error */
  236. #define SXERR_CORRUPT (-24) /* Corrupted pointer */
  237. #define SXERR_CONTINUE (-25) /* Not an error: Operation in progress */
  238. #define SXERR_NOMATCH (-26) /* No match */
  239. #define SXERR_RESET (-27) /* Operation reset */
  240. #define SXERR_DONE (-28) /* Not an error */
  241. #define SXERR_SHORT (-29) /* Buffer too short */
  242. #define SXERR_PATH (-30) /* Path error */
  243. #define SXERR_TIMEOUT (-31) /* Timeout */
  244. #define SXERR_BIG (-32) /* Too big for processing */
  245. #define SXERR_RETRY (-33) /* Retry your call */
  246. #define SXERR_IGNORE (-63) /* Ignore */
  247. /* Standard PH7 return values */
  248. #define PH7_OK SXRET_OK /* Successful result */
  249. /* beginning-of-error-codes */
  250. #define PH7_NOMEM SXERR_MEM /* Out of memory */
  251. #define PH7_ABORT SXERR_ABORT /* Foreign Function request operation abort/Another thread have released this instance */
  252. #define PH7_IO_ERR SXERR_IO /* IO error */
  253. #define PH7_CORRUPT SXERR_CORRUPT /* Corrupt pointer/Unknown configuration option */
  254. #define PH7_LOOKED SXERR_LOCKED /* Forbidden Operation */
  255. #define PH7_COMPILE_ERR (-70) /* Compilation error */
  256. #define PH7_VM_ERR (-71) /* Virtual machine error */
  257. /* end-of-error-codes */
  258. /*
  259. * If compiling for a processor that lacks floating point
  260. * support, substitute integer for floating-point.
  261. */
  262. typedef double ph7_real;
  263. typedef sxi64 ph7_int64;
  264. #define PH7_APIEXPORT SX_APIEXPORT
  265. #define PH7_APIIMPORT SX_APIIMPORT
  266. /*
  267. * Engine Configuration Commands.
  268. *
  269. * The following set of constants are the available configuration verbs that can
  270. * be used by the host-application to configure the PH7 engine.
  271. * These constants must be passed as the second argument to the [ph7_config()]
  272. * interface.
  273. * Each options require a variable number of arguments.
  274. * The [ph7_config()] interface will return PH7_OK on success, any other
  275. * return value indicates failure.
  276. * For a full discussion on the configuration verbs and their expected
  277. * parameters, please refer to this page:
  278. * https://ph7.symisc.net/c_api_func.html#ph7_config
  279. */
  280. #define PH7_CONFIG_ERR_OUTPUT 1 /* TWO ARGUMENTS: int (*xConsumer)(const void *pOut,unsigned int nLen,void *pUserData),void *pUserData */
  281. #define PH7_CONFIG_ERR_ABORT 2 /* RESERVED FOR FUTURE USE */
  282. #define PH7_CONFIG_ERR_LOG 3 /* TWO ARGUMENTS: const char **pzBuf,int *pLen */
  283. #define PH7_CONFIG_MEM_LIMIT 4 /* ONE ARGUMENT: char *nMemLimit */
  284. /*
  285. * Virtual Machine Configuration Commands.
  286. *
  287. * The following set of constants are the available configuration verbs that can
  288. * be used by the host-application to configure the PH7 Virtual machine.
  289. * These constants must be passed as the second argument to the [ph7_vm_config()]
  290. * interface.
  291. * Each options require a variable number of arguments.
  292. * The [ph7_vm_config()] interface will return PH7_OK on success, any other return
  293. * value indicates failure.
  294. * There are many options but the most importants are: PH7_VM_CONFIG_OUTPUT which install
  295. * a VM output consumer callback, PH7_VM_CONFIG_HTTP_REQUEST which parse and register
  296. * a HTTP request and PH7_VM_CONFIG_ARGV_ENTRY which populate the $argv array.
  297. * For a full discussion on the configuration verbs and their expected parameters, please
  298. * refer to this page:
  299. * https://ph7.symisc.net/c_api_func.html#ph7_vm_config
  300. */
  301. #define PH7_VM_CONFIG_OUTPUT 1 /* TWO ARGUMENTS: int (*xConsumer)(const void *pOut,unsigned int nLen,void *pUserData),void *pUserData */
  302. #define PH7_VM_CONFIG_IMPORT_PATH 3 /* ONE ARGUMENT: const char *zIncludePath */
  303. #define PH7_VM_CONFIG_ERR_REPORT 4 /* NO ARGUMENTS: Report all run-time errors in the VM output */
  304. #define PH7_VM_CONFIG_CREATE_SUPER 5 /* TWO ARGUMENTS: const char *zName,ph7_value *pValue */
  305. #define PH7_VM_CONFIG_CREATE_VAR 6 /* TWO ARGUMENTS: const char *zName,ph7_value *pValue */
  306. #define PH7_VM_CONFIG_HTTP_REQUEST 7 /* TWO ARGUMENTS: const char *zRawRequest,int nRequestLength */
  307. #define PH7_VM_CONFIG_SERVER_ATTR 8 /* THREE ARGUMENTS: const char *zKey,const char *zValue,int nLen */
  308. #define PH7_VM_CONFIG_ENV_ATTR 9 /* THREE ARGUMENTS: const char *zKey,const char *zValue,int nLen */
  309. #define PH7_VM_CONFIG_SESSION_ATTR 10 /* THREE ARGUMENTS: const char *zKey,const char *zValue,int nLen */
  310. #define PH7_VM_CONFIG_POST_ATTR 11 /* THREE ARGUMENTS: const char *zKey,const char *zValue,int nLen */
  311. #define PH7_VM_CONFIG_GET_ATTR 12 /* THREE ARGUMENTS: const char *zKey,const char *zValue,int nLen */
  312. #define PH7_VM_CONFIG_COOKIE_ATTR 13 /* THREE ARGUMENTS: const char *zKey,const char *zValue,int nLen */
  313. #define PH7_VM_CONFIG_HEADER_ATTR 14 /* THREE ARGUMENTS: const char *zKey,const char *zValue,int nLen */
  314. #define PH7_VM_CONFIG_IO_STREAM 15 /* ONE ARGUMENT: const ph7_io_stream *pStream */
  315. #define PH7_VM_CONFIG_ARGV_ENTRY 16 /* ONE ARGUMENT: const char *zValue */
  316. #define PH7_VM_CONFIG_EXTRACT_OUTPUT 17 /* TWO ARGUMENTS: const void **ppOut,unsigned int *pOutputLen */
  317. /*
  318. * Global Library Configuration Commands.
  319. *
  320. * The following set of constants are the available configuration verbs that can
  321. * be used by the host-application to configure the whole library.
  322. * These constants must be passed as the first argument to the [ph7_lib_config()]
  323. * interface.
  324. * Each options require a variable number of arguments.
  325. * The [ph7_lib_config()] interface will return PH7_OK on success, any other return
  326. * value indicates failure.
  327. * Notes:
  328. * The default configuration is recommended for most applications and so the call to
  329. * [ph7_lib_config()] is usually not necessary. It is provided to support rare
  330. * applications with unusual needs.
  331. * The [ph7_lib_config()] interface is not threadsafe. The application must insure that
  332. * no other [ph7_*()] interfaces are invoked by other threads while [ph7_lib_config()]
  333. * is running. Furthermore, [ph7_lib_config()] may only be invoked prior to library
  334. * initialization using [ph7_lib_init()] or [ph7_init()] or after shutdown
  335. * by [ph7_lib_shutdown()]. If [ph7_lib_config()] is called after [ph7_lib_init()]
  336. * or [ph7_init()] and before [ph7_lib_shutdown()] then it will return PH7_LOCKED.
  337. * Refer to the official documentation for more information on the configuration verbs
  338. * and their expected parameters.
  339. * For a full discussion on the configuration verbs and their expected parameters,please
  340. * refer to this page:
  341. * https://ph7.symisc.net/c_api_func.html#Global_Library_Management_Interfaces
  342. */
  343. #define PH7_LIB_CONFIG_USER_MALLOC 1 /* ONE ARGUMENT: const SyMemMethods *pMemMethods */
  344. #define PH7_LIB_CONFIG_MEM_ERR_CALLBACK 2 /* TWO ARGUMENTS: int (*xMemError)(void *),void *pUserData */
  345. #define PH7_LIB_CONFIG_USER_MUTEX 3 /* ONE ARGUMENT: const SyMutexMethods *pMutexMethods */
  346. #define PH7_LIB_CONFIG_THREAD_LEVEL_SINGLE 4 /* NO ARGUMENTS */
  347. #define PH7_LIB_CONFIG_THREAD_LEVEL_MULTI 5 /* NO ARGUMENTS */
  348. #define PH7_LIB_CONFIG_VFS 6 /* ONE ARGUMENT: const ph7_vfs *pVfs */
  349. /*
  350. * Compile-time flags.
  351. *
  352. * VmEvalChunk and PH7_CompileAerScript takes iFlags argument
  353. * which controls the behavior of the PH7 Engine while
  354. * processing the input.
  355. */
  356. #define PH7_AERSCRIPT_CODE 0x01 /* AerScript Code */
  357. #define PH7_AERSCRIPT_CHNK 0x02 /* AerScript Chunk of Code */
  358. #define PH7_AERSCRIPT_EXPR 0x04 /* AerScript Expression */
  359. /*
  360. * Call Context Error Message Severity Level.
  361. *
  362. * The following constans are the allowed severity level that can
  363. * passed as the second argument to the PH7_VmThrowError().
  364. * Refer to the official documentation for additional information.
  365. */
  366. #define PH7_CTX_ERR 1 /* Call context Error such as unexpected number of arguments,invalid types and so on. */
  367. #define PH7_CTX_WARNING 2 /* Call context Warning */
  368. #define PH7_CTX_NOTICE 3 /* Call context Notice */
  369. #define PH7_CTX_DEPRECATED 4 /* Call context Deprecated notice */
  370. /* Current VFS structure version*/
  371. #define PH7_VFS_VERSION 2
  372. /*
  373. * PH7 Virtual File System (VFS).
  374. *
  375. * An instance of the ph7_vfs object defines the interface between the PH7 core
  376. * and the underlying operating system. The "vfs" in the name of the object stands
  377. * for "virtual file system". The vfs is used to implement PHP system functions
  378. * such as mkdir(), chdir(), stat(), get_user_name() and many more.
  379. * The value of the iVersion field is initially 2 but may be larger in future versions
  380. * of PH7.
  381. * Additional fields may be appended to this object when the iVersion value is increased.
  382. * Only a single vfs can be registered within the PH7 core. Vfs registration is done
  383. * using the ph7_lib_config() interface with a configuration verb set to PH7_LIB_CONFIG_VFS.
  384. * Note that Windows and UNIX (Linux, FreeBSD, Solaris, Mac OS X, etc.) users does not have to
  385. * worry about registering and installing a vfs since PH7 come with a built-in vfs for these
  386. * platforms which implement most the methods defined below.
  387. * Host-application running on exotic systems (ie: Other than Windows and UNIX systems) must
  388. * register their own vfs in order to be able to use and call PHP system function.
  389. * Also note that the ph7_compile_file() interface depend on the xMmap() method of the underlying
  390. * vfs which mean that this method must be available (Always the case using the built-in VFS)
  391. * in order to use this interface.
  392. * Developers wishing to implement the vfs methods can contact symisc systems to obtain
  393. * the PH7 VFS C/C++ Specification manual.
  394. */
  395. struct ph7_vfs {
  396. const char *zName; /* Underlying VFS name [i.e: FreeBSD/Linux/Windows...] */
  397. int iVersion; /* Current VFS structure version [default 2] */
  398. /* Directory functions */
  399. int (*xChdir)(const char *); /* Change directory */
  400. int (*xChroot)(const char *); /* Change the root directory */
  401. int (*xGetcwd)(ph7_context *); /* Get the current working directory */
  402. int (*xMkdir)(const char *, int, int); /* Make directory */
  403. int (*xRmdir)(const char *); /* Remove directory */
  404. int (*xIsdir)(const char *); /* Tells whether the filename is a directory */
  405. int (*xRename)(const char *, const char *); /* Renames a file or directory */
  406. int (*xRealpath)(const char *, ph7_context *); /* Return canonicalized absolute pathname*/
  407. /* Systems functions */
  408. int (*xSleep)(unsigned int); /* Delay execution in microseconds */
  409. int (*xUnlink)(const char *); /* Deletes a file */
  410. int (*xFileExists)(const char *); /* Checks whether a file or directory exists */
  411. int (*xChmod)(const char *, int); /* Changes file mode */
  412. int (*xChown)(const char *, const char *); /* Changes file owner */
  413. int (*xChgrp)(const char *, const char *); /* Changes file group */
  414. ph7_int64(*xFreeSpace)(const char *); /* Available space on filesystem or disk partition */
  415. ph7_int64(*xTotalSpace)(const char *); /* Total space on filesystem or disk partition */
  416. ph7_int64(*xFileSize)(const char *); /* Gets file size */
  417. ph7_int64(*xFileAtime)(const char *); /* Gets last access time of file */
  418. ph7_int64(*xFileMtime)(const char *); /* Gets file modification time */
  419. ph7_int64(*xFileCtime)(const char *); /* Gets inode change time of file */
  420. ph7_int64(*xFileGroup)(const char *); /* Gets file group */
  421. ph7_int64(*xFileInode)(const char *); /* Gets file inode */
  422. ph7_int64(*xFileOwner)(const char *); /* Gets file owner */
  423. int (*xStat)(const char *, ph7_value *, ph7_value *); /* Gives information about a file */
  424. int (*xlStat)(const char *, ph7_value *, ph7_value *); /* Gives information about a file */
  425. int (*xIsFile)(const char *); /* Tells whether the filename is a regular file */
  426. int (*xIsLink)(const char *); /* Tells whether the filename is a symbolic link */
  427. int (*xReadable)(const char *); /* Tells whether a file exists and is readable */
  428. int (*xWritable)(const char *); /* Tells whether the filename is writable */
  429. int (*xExecutable)(const char *); /* Tells whether the filename is executable */
  430. int (*xFiletype)(const char *, ph7_context *); /* Gets file type [i.e: fifo,dir,file..] */
  431. int (*xGetenv)(const char *, ph7_context *); /* Gets the value of an environment variable */
  432. int (*xSetenv)(const char *, const char *); /* Sets the value of an environment variable */
  433. int (*xTouch)(const char *, ph7_int64, ph7_int64); /* Sets access and modification time of file */
  434. int (*xMmap)(const char *, void **, ph7_int64 *); /* Read-only memory map of the whole file */
  435. void (*xUnmap)(void *, ph7_int64); /* Unmap a memory view */
  436. int (*xLink)(const char *, const char *, int); /* Create hard or symbolic link */
  437. int (*xUmask)(int); /* Change the current umask */
  438. void (*xTempDir)(ph7_context *); /* Get path of the temporary directory */
  439. unsigned int (*xProcessId)(void); /* Get running process ID */
  440. int (*xUid)(void); /* user ID of the process */
  441. int (*xGid)(void); /* group ID of the process */
  442. void (*xUsername)(ph7_context *); /* Running username */
  443. };
  444. /* Current PH7 IO stream structure version. */
  445. #define PH7_IO_STREAM_VERSION 1
  446. /*
  447. * Possible open mode flags that can be passed to the xOpen() routine
  448. * of the underlying IO stream device .
  449. * Refer to the PH7 IO Stream C/C++ specification manual (https://ph7.symisc.net/io_stream_spec.html)
  450. * for additional information.
  451. */
  452. #define PH7_IO_OPEN_RDONLY 0x001 /* Read-only open */
  453. #define PH7_IO_OPEN_WRONLY 0x002 /* Write-only open */
  454. #define PH7_IO_OPEN_RDWR 0x004 /* Read-write open. */
  455. #define PH7_IO_OPEN_CREATE 0x008 /* If the file does not exist it will be created */
  456. #define PH7_IO_OPEN_TRUNC 0x010 /* Truncate the file to zero length */
  457. #define PH7_IO_OPEN_APPEND 0x020 /* Append mode.The file offset is positioned at the end of the file */
  458. #define PH7_IO_OPEN_EXCL 0x040 /* Ensure that this call creates the file,the file must not exist before */
  459. #define PH7_IO_OPEN_BINARY 0x080 /* Simple hint: Data is binary */
  460. #define PH7_IO_OPEN_TEMP 0x100 /* Simple hint: Temporary file */
  461. #define PH7_IO_OPEN_TEXT 0x200 /* Simple hint: Data is textual */
  462. /*
  463. * PH7 IO Stream Device.
  464. *
  465. * An instance of the ph7_io_stream object defines the interface between the PH7 core
  466. * and the underlying stream device.
  467. * A stream is a smart mechanism for generalizing file, network, data compression
  468. * and other IO operations which share a common set of functions using an abstracted
  469. * unified interface.
  470. * A stream device is additional code which tells the stream how to handle specific
  471. * protocols/encodings. For example, the http device knows how to translate a URL
  472. * into an HTTP/1.1 request for a file on a remote server.
  473. * PH7 come with two built-in IO streams device:
  474. * The file:// stream which perform very efficient disk IO and the php:// stream
  475. * which is a special stream that allow access various I/O streams (See the PHP official
  476. * documentation for more information on this stream).
  477. * A stream is referenced as: scheme://target
  478. * scheme(string) - The name of the wrapper to be used. Examples include: file,http,https,ftp,
  479. * ftps, compress.zlib, compress.bz2, and php. If no wrapper is specified,the function default
  480. * is used (typically file://).
  481. * target - Depends on the device used. For filesystem related streams this is typically a path
  482. * and filename of the desired file.For network related streams this is typically a hostname,often
  483. * with a path appended.
  484. * IO stream devices are registered using a call to ph7_vm_config() with a configuration verb
  485. * set to PH7_VM_CONFIG_IO_STREAM.
  486. * Currently the PH7 development team is working on the implementation of the http:// and ftp://
  487. * IO stream protocols. These devices will be available in the next major release of the PH7 engine.
  488. * Developers wishing to implement their own IO stream devices must understand and follow
  489. * The PH7 IO Stream C/C++ specification manual (https://ph7.symisc.net/io_stream_spec.html).
  490. */
  491. struct ph7_io_stream {
  492. const char *zName; /* Underlying stream name [i.e: file/http/zip/php,..] */
  493. int iVersion; /* IO stream structure version [default 1]*/
  494. int (*xOpen)(const char *, int, ph7_value *, void **); /* Open handle*/
  495. int (*xOpenDir)(const char *, ph7_value *, void **); /* Open directory handle */
  496. void (*xClose)(void *); /* Close file handle */
  497. void (*xCloseDir)(void *); /* Close directory handle */
  498. ph7_int64(*xRead)(void *, void *, ph7_int64); /* Read from the open stream */
  499. int (*xReadDir)(void *, ph7_context *); /* Read entry from directory handle */
  500. ph7_int64(*xWrite)(void *, const void *, ph7_int64); /* Write to the open stream */
  501. int (*xSeek)(void *, ph7_int64, int); /* Seek on the open stream */
  502. int (*xLock)(void *, int); /* Lock/Unlock the open stream */
  503. void (*xRewindDir)(void *); /* Rewind directory handle */
  504. ph7_int64(*xTell)(void *); /* Current position of the stream read/write pointer */
  505. int (*xTrunc)(void *, ph7_int64); /* Truncates the open stream to a given length */
  506. int (*xSync)(void *); /* Flush open stream data */
  507. int (*xStat)(void *, ph7_value *, ph7_value *); /* Stat an open stream handle */
  508. };
  509. /*
  510. * C-API-REF: Please refer to the official documentation for interfaces
  511. * purpose and expected parameters.
  512. */
  513. /* Engine Handling Interfaces */
  514. PH7_APIEXPORT int ph7_init(ph7 **ppEngine);
  515. PH7_APIEXPORT int ph7_config(ph7 *pEngine, int nConfigOp, ...);
  516. PH7_APIEXPORT int ph7_release(ph7 *pEngine);
  517. PH7_APIEXPORT int ph7_vm_init(ph7 *pEngine, ph7_vm **ppOutVm, int bDebug);
  518. /* Compile Interfaces */
  519. PH7_APIEXPORT int ph7_compile_code(ph7 *pEngine, const char *zSource, int nLen, ph7_vm **ppOutVm);
  520. PH7_APIEXPORT int ph7_compile_file(ph7 *pEngine, const char *zFilePath, ph7_vm **ppOutVm);
  521. /* Virtual Machine Handling Interfaces */
  522. PH7_APIEXPORT int ph7_vm_config(ph7_vm *pVm, int iConfigOp, ...);
  523. PH7_APIEXPORT int ph7_vm_exec(ph7_vm *pVm, int *pExitStatus);
  524. PH7_APIEXPORT int ph7_vm_reset(ph7_vm *pVm);
  525. PH7_APIEXPORT int ph7_vm_release(ph7_vm *pVm);
  526. PH7_APIEXPORT int ph7_vm_dump(ph7_vm *pVm, int (*xConsumer)(const void *, unsigned int, void *), void *pUserData);
  527. /* In-process Extending Interfaces */
  528. PH7_APIEXPORT int ph7_create_function(ph7_vm *pVm, const char *zName, int (*xFunc)(ph7_context *, int, ph7_value **), void *pUserData);
  529. PH7_APIEXPORT int ph7_delete_function(ph7_vm *pVm, const char *zName);
  530. PH7_APIEXPORT int ph7_create_constant(ph7_vm *pVm, const char *zName, void (*xExpand)(ph7_value *, void *), void *pUserData);
  531. PH7_APIEXPORT int ph7_delete_constant(ph7_vm *pVm, const char *zName);
  532. /* Foreign Function Parameter Values */
  533. PH7_APIEXPORT int ph7_value_to_int(ph7_value *pValue);
  534. PH7_APIEXPORT int ph7_value_to_bool(ph7_value *pValue);
  535. PH7_APIEXPORT ph7_int64 ph7_value_to_int64(ph7_value *pValue);
  536. PH7_APIEXPORT double ph7_value_to_double(ph7_value *pValue);
  537. PH7_APIEXPORT const char *ph7_value_to_string(ph7_value *pValue, int *pLen);
  538. PH7_APIEXPORT void *ph7_value_to_resource(ph7_value *pValue);
  539. PH7_APIEXPORT int ph7_value_compare(ph7_value *pLeft, ph7_value *pRight, int bStrict);
  540. /* Setting The Result Of A Foreign Function */
  541. PH7_APIEXPORT int ph7_result_int(ph7_context *pCtx, int iValue);
  542. PH7_APIEXPORT int ph7_result_int64(ph7_context *pCtx, ph7_int64 iValue);
  543. PH7_APIEXPORT int ph7_result_bool(ph7_context *pCtx, int iBool);
  544. PH7_APIEXPORT int ph7_result_double(ph7_context *pCtx, double Value);
  545. PH7_APIEXPORT int ph7_result_null(ph7_context *pCtx);
  546. PH7_APIEXPORT int ph7_result_string(ph7_context *pCtx, const char *zString, int nLen);
  547. PH7_APIEXPORT int ph7_result_string_format(ph7_context *pCtx, const char *zFormat, ...);
  548. PH7_APIEXPORT int ph7_result_value(ph7_context *pCtx, ph7_value *pValue);
  549. PH7_APIEXPORT int ph7_result_resource(ph7_context *pCtx, void *pUserData);
  550. /* Call Context Handling Interfaces */
  551. PH7_APIEXPORT int ph7_context_output(ph7_context *pCtx, const char *zString, int nLen);
  552. PH7_APIEXPORT int ph7_context_output_format(ph7_context *pCtx, const char *zFormat, ...);
  553. PH7_APIEXPORT unsigned int ph7_context_random_num(ph7_context *pCtx);
  554. PH7_APIEXPORT int ph7_context_random_string(ph7_context *pCtx, char *zBuf, int nBuflen);
  555. PH7_APIEXPORT void *ph7_context_user_data(ph7_context *pCtx);
  556. PH7_APIEXPORT int ph7_context_push_aux_data(ph7_context *pCtx, void *pUserData);
  557. PH7_APIEXPORT void *ph7_context_peek_aux_data(ph7_context *pCtx);
  558. PH7_APIEXPORT void *ph7_context_pop_aux_data(ph7_context *pCtx);
  559. PH7_APIEXPORT unsigned int ph7_context_result_buf_length(ph7_context *pCtx);
  560. PH7_APIEXPORT const char *ph7_function_name(ph7_context *pCtx);
  561. /* Call Context Memory Management Interfaces */
  562. PH7_APIEXPORT void *ph7_context_alloc_chunk(ph7_context *pCtx, unsigned int nByte, int ZeroChunk, int AutoRelease);
  563. PH7_APIEXPORT void *ph7_context_realloc_chunk(ph7_context *pCtx, void *pChunk, unsigned int nByte);
  564. PH7_APIEXPORT void ph7_context_free_chunk(ph7_context *pCtx, void *pChunk);
  565. /* On Demand Dynamically Typed Value Object allocation interfaces */
  566. PH7_APIEXPORT ph7_value *ph7_new_scalar(ph7_vm *pVm);
  567. PH7_APIEXPORT ph7_value *ph7_new_array(ph7_vm *pVm);
  568. PH7_APIEXPORT int ph7_release_value(ph7_vm *pVm, ph7_value *pValue);
  569. PH7_APIEXPORT ph7_value *ph7_context_new_scalar(ph7_context *pCtx);
  570. PH7_APIEXPORT ph7_value *ph7_context_new_array(ph7_context *pCtx);
  571. PH7_APIEXPORT void ph7_context_release_value(ph7_context *pCtx, ph7_value *pValue);
  572. /* Dynamically Typed Value Object Management Interfaces */
  573. PH7_APIEXPORT int ph7_value_int(ph7_value *pVal, int iValue);
  574. PH7_APIEXPORT int ph7_value_int64(ph7_value *pVal, ph7_int64 iValue);
  575. PH7_APIEXPORT int ph7_value_bool(ph7_value *pVal, int iBool);
  576. PH7_APIEXPORT int ph7_value_double(ph7_value *pVal, double Value);
  577. PH7_APIEXPORT int ph7_value_string(ph7_value *pVal, const char *zString, int nLen);
  578. PH7_APIEXPORT int ph7_value_string_format(ph7_value *pVal, const char *zFormat, ...);
  579. PH7_APIEXPORT int ph7_value_reset_string_cursor(ph7_value *pVal);
  580. PH7_APIEXPORT int ph7_value_resource(ph7_value *pVal, void *pUserData);
  581. PH7_APIEXPORT int ph7_value_release(ph7_value *pVal);
  582. PH7_APIEXPORT int ph7_value_void(ph7_value *pVal);
  583. PH7_APIEXPORT ph7_value *ph7_array_fetch(ph7_value *pArray, const char *zKey, int nByte);
  584. PH7_APIEXPORT int ph7_array_walk(ph7_value *pArray, int (*xWalk)(ph7_value *, ph7_value *, void *), void *pUserData);
  585. PH7_APIEXPORT int ph7_array_add_elem(ph7_value *pArray, ph7_value *pKey, ph7_value *pValue);
  586. PH7_APIEXPORT int ph7_array_add_strkey_elem(ph7_value *pArray, const char *zKey, ph7_value *pValue);
  587. PH7_APIEXPORT int ph7_array_add_intkey_elem(ph7_value *pArray, int iKey, ph7_value *pValue);
  588. PH7_APIEXPORT unsigned int ph7_array_count(ph7_value *pArray);
  589. PH7_APIEXPORT int ph7_object_walk(ph7_value *pObject, int (*xWalk)(const char *, ph7_value *, void *), void *pUserData);
  590. PH7_APIEXPORT ph7_value *ph7_object_fetch_attr(ph7_value *pObject, const char *zAttr);
  591. PH7_APIEXPORT const char *ph7_object_get_class_name(ph7_value *pObject, int *pLength);
  592. PH7_APIEXPORT int ph7_value_is_int(ph7_value *pVal);
  593. PH7_APIEXPORT int ph7_value_is_float(ph7_value *pVal);
  594. PH7_APIEXPORT int ph7_value_is_bool(ph7_value *pVal);
  595. PH7_APIEXPORT int ph7_value_is_string(ph7_value *pVal);
  596. PH7_APIEXPORT int ph7_value_is_callback(ph7_value *pVal);
  597. PH7_APIEXPORT int ph7_value_is_callable(ph7_value *pVal);
  598. PH7_APIEXPORT int ph7_value_is_array(ph7_value *pVal);
  599. PH7_APIEXPORT int ph7_value_is_numeric(ph7_value *pVal);
  600. PH7_APIEXPORT int ph7_value_is_object(ph7_value *pVal);
  601. PH7_APIEXPORT int ph7_value_is_resource(ph7_value *pVal);
  602. PH7_APIEXPORT int ph7_value_is_char(ph7_value *pVal);
  603. PH7_APIEXPORT int ph7_value_is_void(ph7_value *pVal);
  604. /* Global Library Management Interfaces */
  605. PH7_APIEXPORT int ph7_lib_init(void);
  606. PH7_APIEXPORT int ph7_lib_config(int nConfigOp, ...);
  607. PH7_APIEXPORT int ph7_lib_shutdown(void);
  608. PH7_APIEXPORT int ph7_lib_is_threadsafe(void);
  609. PH7_APIEXPORT const char *ph7_lib_version(void);
  610. PH7_APIEXPORT const char *ph7_lib_signature(void);
  611. PH7_APIEXPORT const char *ph7_lib_ident(void);
  612. PH7_APIEXPORT const char *ph7_lib_copyright(void);
  613. #endif /* _PH7_H_ */