Add TextWriter, IOException, per-VM module data and pre-load imports; Add console module with Console class

This commit is contained in:
2026-11-23 18:36:46 +01:00
parent 2243557bf5
commit 4d06edd045
55 changed files with 1679 additions and 675 deletions
+35
View File
@@ -1389,6 +1389,11 @@ struct VmModule {
SyString sFile; /* Module library file */
SyString sDesc; /* Module short description */
ph7_real fVer; /* Module version */
/* Per-VM module state published by the module itself (C13). aModules
* survives ph7_vm_reset(), so this data does too; xRelease runs exactly
* once when the VM is released or when the data is overwritten. */
void *pUserData; /* Module-owned state, NULL when unused */
void (*xRelease)(void *); /* Release callback for pUserData */
};
/*
* Each installed class autoload callback (registered using [register_autoload_handler()] )
@@ -1788,6 +1793,13 @@ PH7_PRIVATE sxi32 PH7_VmOutputConsume(ph7_vm *pVm, SyString *pString);
PH7_PRIVATE sxi32 PH7_VmOutputConsumeAp(ph7_vm *pVm, const char *zFormat, va_list ap);
PH7_PRIVATE sxi32 PH7_VmMemoryError(ph7_vm *pVm);
PH7_PRIVATE sxi32 PH7_VmThrowError(ph7_vm *pVm, sxi32 iErr, const char *zMessage, ...);
/* classes.c: publish a core IOException instance as a pending exception.
* Returns PH7_EXCEPTION on success, PH7_ABORT on allocation failure. */
PH7_PRIVATE sxi32 PH7_VmThrowIoException(ph7_context *pCtx, int nCode, const char *zMsg);
/* vm.c: per-VM, per-module opaque state (C13). Lookups are by module name. */
PH7_PRIVATE void *PH7_VmModuleData(ph7_vm *pVm, const char *zModule);
PH7_PRIVATE sxi32 PH7_VmSetModuleData(ph7_vm *pVm, const char *zModule,
void *pData, void (*xRelease)(void *));
PH7_PRIVATE void PH7_VmExpandConstantValue(ph7_value *pVal, void *pUserData);
PH7_PRIVATE sxi32 VmExtractDebugTrace(ph7_vm *pVm, SySet *pDebugTrace);
PH7_PRIVATE sxi32 PH7_VmDump(ph7_vm *pVm, ProcConsumer xConsumer, void *pUserData);
@@ -1876,6 +1888,24 @@ PH7_PRIVATE sxi32 PH7_ProcessCsv(const char *zInput, int nByte, int delim, int e
PH7_PRIVATE sxi32 PH7_CsvConsumer(const char *zToken, int nTokenLen, void *pUserData);
PH7_PRIVATE sxi32 PH7_StripTagsFromString(ph7_context *pCtx, const char *zIn, int nByte, const char *zTaglist, int nTaglen);
PH7_PRIVATE sxi32 PH7_ParseIniString(ph7_context *pCtx, const char *zIn, sxu32 nByte, int bProcessSection);
/* textwriter.c — TextWriter C API. A writer backend owns three callbacks:
* xWrite emits one already-formatted chunk, xFlush flushes it and xRelease
* frees the backend exactly once, from a TextWriter instance destructor. */
typedef struct ph7_text_writer_methods {
int (*xWrite)(void *, const void *, unsigned int);
int (*xFlush)(void *);
void (*xRelease)(void *);
} ph7_text_writer_methods;
PH7_PRIVATE int ph7_text_writer_new(ph7_context *, const ph7_text_writer_methods *, void *, ph7_value *);
PH7_PRIVATE int ph7_text_writer_emit(ph7_context *, int (*)(void *, const void *, unsigned int),
void *, int nArg, ph7_value **, int bLine);
/* Native callbacks backing the core TextWriter class (registered in classes.c). */
PH7_PRIVATE int TextWriterConstruct(ph7_context *, int, ph7_value **);
PH7_PRIVATE int TextWriterDestruct(ph7_context *, int, ph7_value **);
PH7_PRIVATE int TextWriterClone(ph7_context *, int, ph7_value **);
PH7_PRIVATE int TextWriterPrint(ph7_context *, int, ph7_value **);
PH7_PRIVATE int TextWriterPrintLine(ph7_context *, int, ph7_value **);
PH7_PRIVATE int TextWriterFlush(ph7_context *, int, ph7_value **);
/* oo.c function prototypes */
PH7_PRIVATE ph7_class_info *PH7_NewClassInfo(ph7_vm *pVm, const SyString *pName);
PH7_PRIVATE ph7_class *PH7_NewRawClass(ph7_vm *pVm, const SyString *pName);
@@ -1918,6 +1948,11 @@ PH7_PRIVATE const char *PH7_ExtractDirName(const char *zPath, int nByte, int *pL
PH7_PRIVATE sxi32 PH7_RegisterIORoutine(ph7_vm *pVm);
PH7_PRIVATE const ph7_vfs *PH7_ExportBuiltinVfs(void);
PH7_PRIVATE void *PH7_ExportStdin(ph7_vm *pVm);
PH7_PRIVATE void PH7_StdinUnread(ph7_vm *, unsigned char);
PH7_PRIVATE int PH7_StdinReadCodepoint(ph7_vm *);
/* Read one line from the shared stdin handle, including its line ending.
* Returns NULL at EOF without data; the caller owns the returned bytes. */
PH7_PRIVATE char *PH7_StdinReadLine(ph7_vm *pVm, int *pLen);
PH7_PRIVATE void *PH7_ExportStdout(ph7_vm *pVm);
PH7_PRIVATE void *PH7_ExportStderr(ph7_vm *pVm);
/* lib.c function prototypes */