Files
JetCore/jetc/host_test.cpp
T
Brad ArantandClaude Sonnet 5 9bbb95cc57 jetc: rename --shared build output convention from .so to .jtc
Purely a naming-convention change per user request, not a format
change - the output is still a real ELF shared object (-shared -fPIC),
still dlopen()-able exactly as before. .jtc ("jet compiled") marks it as
an APIServer-loadable content module rather than a generic library.

build-shared.sh: usage text and STEM derivation
(basename "$OUTPUT" .so -> .jtc) both updated - the STEM change is the
one functional piece here, everything else in this commit is comments/
usage strings. Doc comments in jetc.cpp/JetCodegen.h/host_test.cpp/
api_test.cpp updated to match.

Verified live: rebuilt jetc and all five demo*.jtc modules, reran
api_test/host_test against demo3.jtc (still resolves jetc_api_demo3/
jetc_render_demo3 and renders correctly) - the extension is purely
cosmetic to dlopen(), as expected.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-08-25 11:41:44 -07:00

52 lines
1.6 KiB
C++

// Minimal stand-in for a server: dlopen()s a compiled
// template .jtc and calls its exported render entry point directly, the
// way a persistent content-provider process would (no process spawn per
// request, no re-parsing the .jet source - both the compile step AND
// the shared-object load happen once, ahead of time).
#include "Global.h"
#include "MString.h"
#include "Exception.h"
#include <dlfcn.h>
#include <iostream>
#include <cstdlib>
typedef void (*RenderFn)(jet::Global &, coreutils::MString &);
int main(int argc, char **argv, char **envp) {
if (argc < 3) {
std::cerr << "usage: host_test <module.jtc> <symbol>" << std::endl;
return 1;
}
void *handle = dlopen(argv[1], RTLD_NOW);
if (!handle) {
std::cerr << "dlopen failed: " << dlerror() << std::endl;
return 1;
}
dlerror();
RenderFn render = (RenderFn)dlsym(handle, argv[2]);
const char *err = dlerror();
if (err) {
std::cerr << "dlsym failed: " << err << std::endl;
return 1;
}
// Simulate the host calling the SAME module twice, for two different
// "requests", to prove the .jtc is reusable across calls without being
// reloaded - the actual point of a persistent content provider.
for (int i = 0; i < 2; ++i) {
jet::Global global(envp);
coreutils::MString out;
try {
render(global, out);
global.outputHeaders();
std::cout << "--- render call " << i << " ---" << std::endl;
std::cout << out;
} catch (coreutils::Exception &e) {
std::cout << "render call " << i << " threw: " << e.text << std::endl;
}
}
dlclose(handle);
return 0;
}