Add project files.

This commit is contained in:
alejo committed 2026-09-12 00:08:03 -03:00
commit 3087fcea8a
71 files changed
+8325

No files matched your search

@@ -0,0 +1,47 @@
/* CppWidgetApi.h -- a C++ (not extern "C") surface living alongside
* PluginApi.h's plain C one, in the SAME plugin build. Every member
* function below keeps its real, compiler-mangled name; nothing here
* needs special handling by source/HotReload, which classifies
* symbols by their type and section, never by what their name looks
* like -- see hot_reload.h's "REQUIREMENTS ON A HOT-RELOADABLE
* MODULE" and README.md's "Hot reloading C++ symbols" for the full
* picture.
*
* The two methods below are reached two different ways from
* Host/Main.cpp, deliberately: see that file's comments for why.
*/
#pragma once
class CppWidget
{
public:
virtual ~CppWidget() = default;
/* Virtual: Host/Main.cpp calls this through ordinary C++
* polymorphic dispatch (widget->virtualTick(x)) and needs no
* manual symbol lookup at all -- the call compiles down to an
* indirect call through the object's vtable slot, not a direct
* reference to this specific symbol, so it needs no link-time
* dependency on whichever plugin build actually defines it. */
virtual int virtualTick(int input);
/* An ordinary out-of-line method. Calling this as widget->tick(x)
* would compile to a direct call to CppWidget::tick's own mangled
* symbol, which would need the Host to link against a plugin
* build at build time -- exactly what hot-reloading a plugin
* means avoiding. So Host/Main.cpp instead resolves it manually
* by its mangled name via hot_reload_get_symbol(), the same way
* it resolves PluginApi.h's plain C functions. */
int tick(int input);
/* An overloaded operator: mechanically just a function with an
* unusual mangled name, reached the same manual way as tick()
* above. */
CppWidget operator+(const CppWidget& other) const;
};
/* The one entry point Host/Main.cpp looks up by a plain, human-typed
* name -- extern "C" here for exactly the reason hot_reload.h
* recommends it: something to hand a human-readable name to, without
* needing to know or hardcode a mangled string. */
extern "C" CppWidget* make_cpp_widget();
@@ -0,0 +1,55 @@
/* PluginApi.h -- the contract PluginV1 and PluginV2 both implement,
* and the Host loads by name. Every function here follows
* cpp-style-guide.md section 11's rule for anything loaded at runtime:
* plain C linkage, no classes or exceptions crossing the boundary.
*
* This header is deliberately identical for both plugin versions --
* in a real project this is the file that stays stable while
* PluginV1/src/Plugin.cpp and PluginV2/src/Plugin.cpp (standing in for
* "the same file, before and after your edit") diverge.
*/
#pragma once
#ifdef __cplusplus
extern "C"
{
#endif
/* Changes behavior between V1 and V2 -- watch this one get
* HOT_RELOAD_SYMBOL_PATCHED. */
int plugin_tick(int input);
/* Only in V1, gone in V2 -- watch this one get
* HOT_RELOAD_SYMBOL_REMOVED, and the Host's stub take over for any
* call still aimed at it afterwards. */
int plugin_legacy_feature(int input);
/* Only in V2 -- watch this one get HOT_RELOAD_SYMBOL_ADDED, then
* get called for the first time right after. */
int plugin_new_feature(int input);
#if defined(__GNUC__) || defined(__clang__)
/* Deliberately too small to safely hold a jump on any of this
* library's backends (its patchable-function-entry padding is
* overridden down to zero) -- watch this one get
* HOT_RELOAD_SYMBOL_SKIPPED_TOO_SMALL rather than corrupt whatever
* comes after it. MSVC has no equivalent per-function override
* this demo could apply, so this one only exists on GCC/Clang.
*/
__attribute__((patchable_function_entry(0))) int plugin_tiny_function(int input);
#endif
/* An exported VARIABLE, not a function, sitting right next to
* real functions in the same library and changing value between
* V1 and V2 just like plugin_tick's behavior does -- watch this
* one get HOT_RELOAD_SYMBOL_SKIPPED_NOT_CODE. This is the
* mechanical proof behind hot_reload.h's "only executable code
* changes" guarantee: nothing here tells the library "this one is
* data, don't touch it" -- it discovers that itself from the
* symbol table, the same way it discovers plugin_tick is code.
*/
extern int plugin_build_marker;
#ifdef __cplusplus
}
#endif