Notes on how the compiler works:
- Pre-processing is completely handled in the Editor. All the C++ includes that handle macros are orphans that aren't called: ignore those.
- The Editor also prepares and aggregates the code snippets that make up the program. This entails writing the code for dialog scripts.
- When all is ready, the Editor calls ccCompileText() in file ags/Compiler/script/cs_compiler.cpp . This function calls cc_compile() in ags/Compiler/script/cs_parser.cpp which does the main work.
- ccCompileText(), above, returns a pointer to struct ccScript. This ccScript is defined in ags/Common/script/cc_script.h and contains all the results of the compiler run. So to write a standalone compiler, one only needs the data in that struct.
- However, whenever the compiler encountes an error, it sets the global variables ccError, ccErrorLine, ccErrorString, ccErrorCallStack. Those are declared "external" in ags/Common/script/cc_error.h and defined in ags/Common/script/cc_error.cpp. This means that if ccCompileText() returns NULL, then the global variables must be inspected for the error
- The compiler uses a symbol table for its work, and this symbol table is a global "extern" variable. The compiler refers to the symbol table by this extern variable name. This means that the compiler can't be forked: All the compiler instances would use the same symbol table and clobber each other's work.
- The compiler currently writes the name of the script it compiles into a global variable. This variable doesn't appear to be read anywhere.
General ideas on the standalone compiler in C++:
- Make a separate project and include the files in ags/Compiler/script into it.
- These files will reference files in ags/Common/script; one might want to provide their own code for some of these files that fits your needs.
- As concerns the C# code of the Editor, find and isolate the portions that do the preparation and preprocessing. Probably reference those portions as "external references" or some such.
- Then, call ccCompileText() and get the compilation outputs in the return value (or the errors in the global variables).
- Afterwards, write the results into the file. For that, steal more "external references" from the Editor or includes from the C++ side of AGS.