#ifndef __JetCodegen_h__ #define __JetCodegen_h__ #include "JetAST.h" #include #include namespace jetc { // Emits a standalone .cpp translation unit that renders a compiled JET // template. The static tag/text structure becomes real C++ control flow; // anything genuinely dynamic (variable values, expr/value comparisons, // loop bounds) still calls into the existing JetCore/CoreUtils runtime // (Tag::getVariable/resolveKeyword/assignVariable, jet::Operand) exactly // as the interpreter does - compiling doesn't try to eliminate that, only // the repeated re-parsing of the template's own structure. class Codegen { public: std::string generate(const std::vector &top, const std::string &sourceFileComment); private: std::ostringstream out; size_t nextId = 0; std::string id(const std::string &prefix) { return prefix + std::to_string(nextId++) + "_"; } void emitBody(const std::vector &nodes, int indent); void emitNode(const NodePtr &n, int indent); static std::string ind(int indent); static std::string cstr(const std::string &raw); // C++ string-literal escape static const char *staticTypeOp(const std::string &type, const char *rcVar); }; } #endif