Post-deletion cleanup (units run only on wasm): - types.h/compiler.cpp: drop the native-era SharedUnit fields so_name, bin_file_name, and the opt_so_optional cache-mode plumbing (no native optional .so path remains). The per-unit compile lock is re-keyed from so_name+.lock to wasm_name+.lock (still per-unit). - unit_info() and to_string(SharedUnit*) no longer expose .so artifact fields. - backend.h: drop the stale "+ fallback-token gate" comment. - Docs/comments corrected to wasm-only reality: README, tests/README, site/doc C++ preprocessor + error_pages + unit_info pages, site/info intro, site/demo/unit-browser artifact card; the Phase-5 native-vs-wasm benchmark harness (tests/wasm_benchmark.py) reframed for the wasm-only backend. Audit confirmed no live references remain to so_handle, load_shared_unit, compiler_load_shared_unit, compiler_invoke*/_cli/_websocket/_serve_http, COMPILE_SCRIPT/COMPILE_WASM_UNITS, or the native export-symbol constants; request_ref_handler/dv_call_handler are kept (live wasm funcref casts). Swept via the pi agent (delegated to a gpt-5.3-codex-spark sub-model); independently re-verified on the host: run_cli_tests --include-wasm-kill => 87 passed, 0 failed, 0 skipped. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
265 lines
5.8 KiB
C++
265 lines
5.8 KiB
C++
#pragma once
|
|
|
|
#include <string>
|
|
#include <map>
|
|
#include <list>
|
|
#include <vector>
|
|
#include <functional>
|
|
#include <sstream>
|
|
#include <atomic>
|
|
#include <set>
|
|
|
|
typedef unsigned char u8;
|
|
typedef signed char s8;
|
|
typedef unsigned short u16;
|
|
typedef signed short s16;
|
|
typedef unsigned int u32;
|
|
typedef signed int s32;
|
|
typedef float f32;
|
|
typedef double f64;
|
|
typedef unsigned long long u64;
|
|
typedef long long s64;
|
|
|
|
typedef std::string String;
|
|
|
|
// inline: this header is included by every runtime object (core/wasm/main); a
|
|
// non-inline definition here would be a duplicate symbol across them.
|
|
inline String operator+(String lhs, u64 rhs) {
|
|
return(lhs + std::to_string(rhs));
|
|
}
|
|
|
|
inline String operator+(String lhs, u32 rhs) {
|
|
return(lhs + std::to_string(rhs));
|
|
}
|
|
|
|
inline String operator+(String lhs, s64 rhs) {
|
|
return(lhs + std::to_string(rhs));
|
|
}
|
|
|
|
inline String operator+(String lhs, s32 rhs) {
|
|
return(lhs + std::to_string(rhs));
|
|
}
|
|
|
|
inline String operator+(String lhs, f64 rhs) {
|
|
return(lhs + std::to_string(rhs));
|
|
}
|
|
|
|
inline String operator+(String lhs, f32 rhs) {
|
|
return(lhs + std::to_string(rhs));
|
|
}
|
|
|
|
#define DEBUG_MEMORY_OFF
|
|
|
|
typedef std::map<String, String> StringMap;
|
|
typedef std::vector<String> StringList;
|
|
typedef std::ostringstream ByteStream;
|
|
|
|
struct Request;
|
|
struct DValue;
|
|
|
|
typedef void (*WasmRequestHandler)(Request& request);
|
|
typedef DValue* (*WasmDValueCallHandler)(DValue* call_param);
|
|
|
|
inline String to_string(s64 v) { return(std::to_string(v)); }
|
|
|
|
struct SharedUnit {
|
|
|
|
String file_name;
|
|
String wasm_name;
|
|
String wasm_check_file_name;
|
|
String api_file_name;
|
|
String meta_file_name;
|
|
String compile_output_file_name;
|
|
String setup_file_name;
|
|
StringList api_declarations;
|
|
|
|
String src_path;
|
|
String bin_path;
|
|
String pre_path;
|
|
String src_file_name;
|
|
String wasm_file_name;
|
|
String pre_file_name;
|
|
|
|
String compiler_messages;
|
|
String compile_status = "unknown";
|
|
String compile_error_status = "";
|
|
String runtime_error_status = "";
|
|
time_t last_compiled = 0;
|
|
time_t observed_compiled_time = 0;
|
|
time_t last_rendered = 0;
|
|
time_t last_error = 0;
|
|
String observed_metadata_content = "";
|
|
|
|
u64 request_count = 0;
|
|
u64 invoke_count = 0;
|
|
u64 runtime_error_count = 0;
|
|
|
|
u64 compile_count = 0;
|
|
u64 compile_success_count = 0;
|
|
u64 compile_failure_count = 0;
|
|
|
|
f64 last_compile_duration = 0;
|
|
f64 total_compile_duration = 0;
|
|
f64 best_compile_duration = 0;
|
|
f64 worst_compile_duration = 0;
|
|
|
|
f64 last_render_duration = 0;
|
|
f64 total_render_duration = 0;
|
|
f64 best_render_duration = 0;
|
|
f64 worst_render_duration = 0;
|
|
|
|
~SharedUnit();
|
|
};
|
|
|
|
struct UploadedFile {
|
|
String file_name;
|
|
String tmp_name;
|
|
u32 size;
|
|
};
|
|
|
|
struct ServerState {
|
|
|
|
std::map<String, SharedUnit*> units;
|
|
StringMap config;
|
|
u32 request_count = 0;
|
|
|
|
};
|
|
|
|
struct URI {
|
|
|
|
StringMap query;
|
|
StringMap parts;
|
|
|
|
};
|
|
|
|
String nibble(String div, String& haystack);
|
|
|
|
#include "dvalue.h"
|
|
|
|
struct Request {
|
|
|
|
ServerState* server = 0;
|
|
|
|
StringMap params;
|
|
StringMap get;
|
|
StringMap post;
|
|
StringMap cookies;
|
|
StringMap session;
|
|
String session_loaded_hash = "";
|
|
std::set<String> once_units;
|
|
|
|
DValue call;
|
|
DValue cfg;
|
|
DValue props;
|
|
DValue connection;
|
|
|
|
String session_id = "";
|
|
String session_name = "";
|
|
std::vector<UploadedFile> uploaded_files;
|
|
|
|
String response_code = "HTTP/1.1 200 OK";
|
|
StringMap header;
|
|
StringList set_cookies;
|
|
|
|
u64 random_seed = 0;
|
|
u64 random_index = 0;
|
|
|
|
std::vector<ByteStream*> ob_stack;
|
|
ByteStream* ob = 0;
|
|
|
|
String in;
|
|
String out;
|
|
String err;
|
|
|
|
struct Flags {
|
|
bool log_request = true;
|
|
bool is_finished = false;
|
|
int status = 0;
|
|
bool output_closed = false;
|
|
bool params_closed = false;
|
|
bool input_closed = false;
|
|
} flags;
|
|
|
|
struct Stats {
|
|
u32 bytes_written = 0;
|
|
f64 time_init = 0;
|
|
f64 time_start = 0;
|
|
f64 time_end = 0;
|
|
u64 mem_high = 0;
|
|
u64 mem_alloc = 0;
|
|
u32 invoke_count = 0;
|
|
} stats;
|
|
|
|
// OS-related resources
|
|
struct Resources {
|
|
std::vector<u64> sockets;
|
|
std::vector<void*> mysql_connections;
|
|
std::vector<void*> sqlite_connections;
|
|
u64 client_socket = 0;
|
|
u64 server_socket = 0;
|
|
bool is_websocket = false;
|
|
bool is_cli = false;
|
|
String websocket_connection_id = "";
|
|
String websocket_scope = "";
|
|
DValue* websocket_connection_state = 0;
|
|
StringList websocket_scope_connection_ids;
|
|
DValue websocket_dispatch_commands;
|
|
bool websocket_dispatch_capture = false;
|
|
u8 websocket_opcode = 0;
|
|
bool websocket_is_binary = false;
|
|
bool websocket_is_text = false;
|
|
String current_unit_file = "";
|
|
String params_buffer;
|
|
// True while a configured error page (page_compiling /
|
|
// page_compiler_error / page_runtime_error) is rendering, so a failing
|
|
// error page can never recurse into another error page.
|
|
bool error_page_active = false;
|
|
} resources;
|
|
|
|
void ob_start();
|
|
void set_status(s32 code, String reason = "");
|
|
|
|
~Request();
|
|
|
|
};
|
|
|
|
typedef Request FastCGIRequest;
|
|
|
|
// Native runtime is split across objects (core/wasm/main), so context is
|
|
// declared here and defined once in types.cpp. The wasm core is a single TU and
|
|
// wasm units resolve context through the loader's GOT, so both keep the
|
|
// in-place definition (unchanged ABI).
|
|
#if defined(__UCE_WASM_CORE__) || defined(__UCE_WASM_UNIT__)
|
|
Request* context;
|
|
#else
|
|
extern Request* context;
|
|
#endif
|
|
|
|
#include <iostream>
|
|
|
|
// NB: header templates must be inline — wasm units rely on
|
|
// -fvisibility-inlines-hidden binding instantiations locally (§6)
|
|
template <typename... Ts>
|
|
inline void print(Ts... args)
|
|
{
|
|
((*context->ob << args), ...);
|
|
}
|
|
|
|
template <typename... Ts>
|
|
inline void out(Ts... args)
|
|
{
|
|
((*context->ob << args), ...);
|
|
}
|
|
|
|
template <typename... Ts>
|
|
inline String concat(Ts... args)
|
|
{
|
|
ByteStream out;
|
|
((out << args), ...);
|
|
return(out.str());
|
|
}
|
|
|
|
// The global allocator override (request memory accounting) is defined once in
|
|
// types.cpp so it lives in a single runtime object; a header definition would
|
|
// duplicate it across core/wasm/main. Units (__UCE_WASM_UNIT__) import it.
|