26 exported symbols · inventory checked against src/script/tcc_host.h

Nested Compilation & VFS Reference

The foundation of the application-level plugin system: scripts can create further TCC compilers, compile new code and resolve symbols. The recommended entry point is xsCreateTCC — it presets the standard include/lib paths and the full host symbol import; the tables below are the complete capability surface underneath it.

What xsCreateTCC presets

PresetContents
Output typeTCC_OUTPUT_MEMORY — the compilation product stays purely in memory, never touching disk
include pathsthe app's dev_inc + the VFS-built-in SDK (xsbase.h / xrt_decl.h / libtcc.h)
Symbol importsthe same four-layer symbol table as the host: xrt 3,030 + the XServer contract 20 + libtcc/VFS 26 + extensions (per variant)
System librariesmsvcrt/kernel32 automatic on Windows; 7 system libraries explicitly available

In other words: nested-compiled code holds the same privileges as host scripts — it can call every API (including nesting further). That is power and responsibility; the boundary discussion is in chapter 40 and chapter 44.

Compiler control (18)

FunctionPurpose
tcc_new / tcc_deletecreate / destroy a compiler instance (before delete, ensure the product's symbols are no longer in use)
tcc_set_lib_path / tcc_set_optionslibrary search root / command-line-style options
tcc_set_error_funccompile-error callback (defaults to stderr — plugin scenarios should take it over)
tcc_add_include_path / tcc_add_sysinclude_pathordinary / system header search paths
tcc_define_symbol / tcc_undefine_symbolpredefine / undefine macros (e.g. the extension switch XS_USE_SQLITE=1)
tcc_add_library_path / tcc_add_librarylibrary directory / libraries to link (works with the app's dev_lib)
tcc_add_filecompile a source file (disk or VFS path)
tcc_add_symbolregister a host symbol (name → address) — the channel by which plugins call the host
tcc_set_output_typeoutput shape (plugins use MEMORY)
tcc_compile_stringcompile a source string — the main entry for expression evaluation / dynamic plugins
tcc_output_fileoutput to a file (for exporting .dll/.so; not used in plugin mode)
tcc_relocatelink & relocate into memory — symbols can only be fetched afterwards
tcc_get_symbolfetch a product symbol's address by name (call it as soon as you hold the function pointer)
The five steps of plugin compilation
TCCState* pTcc = xsCreateTCC();            /* 1. a preset instance */
/* 2. (optional) tcc_add_symbol registers plugin-only symbols */
tcc_compile_string(pTcc, sPluginSource);    /* 3. compile */
tcc_relocate(pTcc, TCC_RELOCATE_AUTO);      /* 4. relocate */
void* pfn = tcc_get_symbol(pTcc, "plugin_main");
/* 5. call; xsDestroyTCC(pTcc) once no longer used */

VFS file layer (8)

FunctionPurpose
tcc_vfs_open / tcc_vfs_closeopen / close a VFS file handle
tcc_vfs_read / tcc_vfs_lseekread / seek (POSIX-style semantics)
tcc_vfs_fopen / tcc_vfs_fcloseFILE*-style open / close
tcc_vfs_mount_memory / tcc_vfs_unmountmount memory as a VFS path — the channel for injecting headers/sources at runtime

The VFS's static contents (SDK headers, TCC includes, system library definitions) are covered in the VFS resources reference; mount_memory lets you hand the nested compiler files "out of thin air" at runtime — that is exactly how the host loads its own scripts (sources are mounted at the virtual path /xs/script/%p.c and then add_file'd).