/* * cat/backend/c.h -- the C backend (ahead-of-time compilation). * * Naming rule: symbols here are cat_backend_c_* / CAT_BACKEND_C_*. * * The bytecode produced by the compiler is lowered to a standalone C * translation unit. The generated program embeds its bytecode and runs * it on the catscript runtime, but contains no compiler: a native `cc` * build of the output is the executable, so nothing is parsed or * compiled at run time. * * Two entry points: * - cat_backend_c_emit() write the C for a compiled program * - cat_backend_c_compile() emit + invoke cc to produce a binary */ #ifndef CAT_BACKEND_C_H #define CAT_BACKEND_C_H #include "cat/bytecode.h" #include #include /* Write a self-contained C translation unit for `fn` to `out`. * `module_name`/`module_path` seed the runtime `module` table. */ int cat_backend_c_emit(CAT_BYTECODE_Function *fn, const char *module_name, const char *module_path, FILE *out); /* Emit the C for `fn` to a temporary file, compile it with the system C * compiler, and write the executable to `outpath`. On failure returns * non-zero and fills `errbuf`. */ int cat_backend_c_compile(CAT_BYTECODE_Function *fn, const char *module_name, const char *module_path, const char *outpath, char *errbuf, size_t errsz); #endif /* CAT_BACKEND_C_H */