archive el_runtime.c — native El runtime complete, seed is self-contained

el_seed.c now defines el_request_start/el_request_end directly (delegating
to its own seed arena) rather than declaring them as externs from el_runtime.c.
Header comment updated to reflect self-contained build.
This commit is contained in:
Will Anderson
2026-05-03 17:08:49 -05:00
parent 71a1e41f93
commit beb4e436e1
3 changed files with 42 additions and 42 deletions
+15 -31
View File
@@ -1,21 +1,15 @@
/*
* el_seed.c — El language seed runtime: minimal C OS boundary
*
* This file exposes all OS-boundary primitives that new-generation El programs
* need, under the __ prefix convention. Implementations are lifted directly
* from el_runtime.c and wrapped/renamed rather than reimplemented.
* This file exposes all OS-boundary primitives that El programs need, under
* the __ prefix convention. It is self-contained: all allocators, arena
* management, and el_request_start / el_request_end are defined here.
*
* Threading is the most important new piece here. __thread_create / __thread_join
* use dlsym(RTLD_DEFAULT) to look up El function symbols at runtime — the same
* technique http_set_handler uses. This is the foundation of El's parallelism.
*
* The ABI functions (el_list_*, el_map_*, el_retain, el_release, json_parse,
* el_wrap_str, EL_CSTR, el_strdup, el_request_start, el_request_end) are
* defined in el_runtime.c and used here by declaration only. This file does
* NOT redefine them.
* Threading: __thread_create / __thread_join use dlsym(RTLD_DEFAULT) to look
* up El function symbols at runtime. This is the foundation of El's parallelism.
*
* Link: cc -std=c11 -I el-compiler/runtime -lcurl -lpthread \
* -o <out> <prog>.c el_seed.c el_runtime.c
* -o <out> <prog>.c el_seed.c
*/
#ifndef _GNU_SOURCE
@@ -43,26 +37,11 @@
#include <dlfcn.h>
#include <curl/curl.h>
/* ── Forward declarations from el_runtime.c (ABI + allocators) ──────────── */
/* These are defined in el_runtime.c and linked in. */
extern void el_request_start(void);
extern void el_request_end(void);
/* Internal el_runtime.c allocators — declared here so el_seed.c can use them.
* They are static in el_runtime.c; el_seed.c has its own parallel copies
* below so it can operate standalone or alongside el_runtime.c. */
/* ── Private allocator (parallel to el_runtime.c) ────────────────────────── */
/* ── Private allocator ───────────────────────────────────────────────────── */
/*
* el_seed.c carries its own arena so it can be compiled with or without
* el_runtime.c. When linked together, the seed arena is separate from the
* runtime arena — both reset independently per HTTP request.
*
* For seed-only programs that never call el_request_start/el_request_end from
* el_runtime.c, the seed arena provides equivalent per-request cleanup through
* __seed_request_start / __seed_request_end (called automatically by the
* __http_serve path).
* el_seed.c carries its own arena for per-request allocation tracking.
* The arena is reset at el_request_start / el_request_end, which are defined
* below and delegate to seed_request_start / seed_request_end.
*/
#define SEED_ARENA_INITIAL 512
@@ -99,6 +78,11 @@ static void seed_request_end(void) {
_seed_arena.count = 0;
}
/* el_request_start / el_request_end — formerly defined in el_runtime.c.
* Now self-contained in el_seed.c, delegating to the seed arena. */
void el_request_start(void) { seed_request_start(); }
void el_request_end(void) { seed_request_end(); }
/* Persistent alloc — bypasses arena (state, engram internals). */
static char* seed_strdup_persist(const char* s) {
if (!s) return strdup("");