feat(http): Http.* poll-based HTTP/HTTPS client over a native NSURLConnection backend (#6)
All checks were successful
bootstrap / cfree-fixpoint (push) Successful in 19s
ci / build-and-test (push) Successful in 1m26s
commit-lint / conventional-commits (push) Successful in 5s
docs / build-and-deploy (push) Successful in 21s

Adds the Http.* namespace and its transport, the HTTP client from #6. The JSON
companion the proposal called for already shipped as Json.* (#44).

- runtime/native/http.ll: the macOS transport — NSURLConnection driven through
  the objc runtime C ABI (no ObjC/C source), run on a detached pthread so the
  frame never blocks; TLS is the system's, on by default. A fixed slot pool holds
  each in-flight request; the worker publishes status/body/response behind an
  atomic done flag (release/acquire). Spliced + Foundation linked only when a
  program uses Http.*.
- runtime/native/http.ludic: the Http.* runtime — get/post/request, the
  open/set/body/send builder, poll/status/ok/text/body_len/header/free, plus a
  pure-Ludic response parser (Http.parse + case-insensitive header lookup) that
  is transport-independent and portable.
- compiler: Http.* dispatch, g_uses_http splice, hs_* transport intrinsics +
  declarations, the conditional Foundation link, and a new \r string/char escape
  the protocol needs.
- docs: a full docs/language/http section (16 pages); check-impl/check-docs green.
- test: examples/library/http.ludic self-asserts the parser offline (Darwin-gated
  build via the canonical path, since it links Foundation).

Verified end to end against real endpoints: HTTPS GET (200 + headers + body) and
POST (body + custom header). HTTP is out-of-band and never feeds the
deterministic sim. Reseeded; suites green (81 + 29).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
Orkun ÇAKILKAYA 2026-08-31 18:10:53 +03:00
parent 4eef5ebbce
commit 3df6640fa5
29 changed files with 24936 additions and 22396 deletions

View file

@ -231,6 +231,27 @@ function emit_ns_call(ns: pointer, meth: pointer, e: Node) -> Val {
if (meth == "pitch") { bare = "audio_pitch"; push(labels, "v") }
if (meth == "is_playing") { bare = "audio_is_playing"; push(labels, "id") }
}
# Http.* (#6) — a poll-based HTTP/HTTPS client (runtime/native/http.ludic +
# http.ll). Out-of-band, never part of the deterministic sim. Pairs with Json.*
# (#44) for (de)serialization: Json.parse(Http.text(h)).
if (ns == "Http") {
if (meth == "get") { bare = "http_get"; push(labels, "url") }
if (meth == "post") { bare = "http_post"; push(labels, "url"); push(labels, "body") }
if (meth == "request") { bare = "http_request"; push(labels, "method"); push(labels, "url"); push(labels, "body") }
if (meth == "open") { bare = "http_open"; push(labels, "method"); push(labels, "url") }
if (meth == "set") { bare = "http_set_header"; push(labels, "handle"); push(labels, "name"); push(labels, "value") }
if (meth == "body") { bare = "http_body"; push(labels, "handle"); push(labels, "body") }
if (meth == "body_bytes"){ bare = "http_body_n"; push(labels, "handle"); push(labels, "bytes"); push(labels, "len") }
if (meth == "send") { bare = "http_send_req"; push(labels, "handle") }
if (meth == "poll") { bare = "http_poll"; push(labels, "handle") }
if (meth == "status") { bare = "http_status_of"; push(labels, "handle") }
if (meth == "ok") { bare = "http_ok"; push(labels, "handle") }
if (meth == "text") { bare = "http_text"; push(labels, "handle") }
if (meth == "body_len") { bare = "http_body_len"; push(labels, "handle") }
if (meth == "header") { bare = "http_header_of"; push(labels, "handle"); push(labels, "name") }
if (meth == "free") { bare = "http_close"; push(labels, "handle") }
if (meth == "parse") { bare = "http_parse"; push(labels, "bytes"); push(labels, "len") }
}
# Phase 3: the bare reflection / networking / process builtins, namespaced.
# Each is a pure alias — the callee is rewritten to the bare name below.
if (ns == "World") {

View file

@ -73,6 +73,16 @@ function emit_header() -> void {
emith("declare i32 @snd_playing(ptr)\n")
emith("declare void @snd_set_volume(ptr, i32)\n")
emith("declare void @snd_set_rate(ptr, i32)\n")
emith("declare ptr @hs_req_new(ptr, ptr)\n") # #6 HTTP transport (http.ll)
emith("declare void @hs_req_header(ptr, ptr, ptr)\n")
emith("declare void @hs_req_body(ptr, ptr, i32)\n")
emith("declare void @hs_send(i32, ptr)\n")
emith("declare i32 @hs_done(i32)\n")
emith("declare i32 @hs_status(i32)\n")
emith("declare ptr @hs_body(i32)\n")
emith("declare i32 @hs_blen(i32)\n")
emith("declare ptr @hs_header(i32, ptr)\n")
emith("declare void @hs_free(i32)\n")
emith("@__stderrp = external global ptr\n")
emith("@__stdoutp = external global ptr\n")
emith("@.fmt_int = private unnamed_addr constant [4 x i8] c\"%d\\0A\\00\"\n")

View file

@ -15,6 +15,9 @@ function is_intrinsic2(name: pointer) -> bool {
if (name == "win_pad") or (name == "win_touch") { return true } # #51 gamepad / touch
if (name == "snd_load") or (name == "snd_play") or (name == "snd_stop") { return true } # #22 audio
if (name == "snd_playing") or (name == "snd_set_volume") or (name == "snd_set_rate") { return true }
if (name == "hs_req_new") or (name == "hs_req_header") or (name == "hs_req_body") { return true } # #6 HTTP
if (name == "hs_send") or (name == "hs_done") or (name == "hs_status") or (name == "hs_body") { return true }
if (name == "hs_blen") or (name == "hs_header") or (name == "hs_free") { return true }
return false
}
@ -72,5 +75,16 @@ function emit_intrinsic2(name: pointer, e: Node) -> Val {
if (name == "snd_playing") { let a = arg_code(e, 0); return val(emit_bind(`call i32 @snd_playing(ptr {a})`), "int") }
if (name == "snd_set_volume") { let a = arg_code(e, 0); let b = arg_code(e, 1); emit(" call void @snd_set_volume(ptr "); emit(a); emit(", i32 "); emit(b); emit(")\n"); return val("0", "void") }
if (name == "snd_set_rate") { let a = arg_code(e, 0); let b = arg_code(e, 1); emit(" call void @snd_set_rate(ptr "); emit(a); emit(", i32 "); emit(b); emit(")\n"); return val("0", "void") }
# #6 HTTP transport — NSURLConnection on a background thread (http.ll).
if (name == "hs_req_new") { let a = arg_code(e, 0); let b = arg_code(e, 1); return val(emit_bind(`call ptr @hs_req_new(ptr {a}, ptr {b})`), "pointer") }
if (name == "hs_req_header") { let a = arg_code(e, 0); let b = arg_code(e, 1); let c = arg_code(e, 2); emit(" call void @hs_req_header(ptr "); emit(a); emit(", ptr "); emit(b); emit(", ptr "); emit(c); emit(")\n"); return val("0", "void") }
if (name == "hs_req_body") { let a = arg_code(e, 0); let b = arg_code(e, 1); let c = arg_code(e, 2); emit(" call void @hs_req_body(ptr "); emit(a); emit(", ptr "); emit(b); emit(", i32 "); emit(c); emit(")\n"); return val("0", "void") }
if (name == "hs_send") { let a = arg_code(e, 0); let b = arg_code(e, 1); emit(" call void @hs_send(i32 "); emit(a); emit(", ptr "); emit(b); emit(")\n"); return val("0", "void") }
if (name == "hs_done") { let a = arg_code(e, 0); return val(emit_bind(`call i32 @hs_done(i32 {a})`), "int") }
if (name == "hs_status") { let a = arg_code(e, 0); return val(emit_bind(`call i32 @hs_status(i32 {a})`), "int") }
if (name == "hs_body") { let a = arg_code(e, 0); return val(emit_bind(`call ptr @hs_body(i32 {a})`), "pointer") }
if (name == "hs_blen") { let a = arg_code(e, 0); return val(emit_bind(`call i32 @hs_blen(i32 {a})`), "int") }
if (name == "hs_header") { let a = arg_code(e, 0); let b = arg_code(e, 1); return val(emit_bind(`call ptr @hs_header(i32 {a}, ptr {b})`), "pointer") }
if (name == "hs_free") { let a = arg_code(e, 0); emit(" call void @hs_free(i32 "); emit(a); emit(")\n"); return val("0", "void") }
return val("0", "void")
}

View file

@ -60,6 +60,7 @@ function lex(src: pointer) -> void {
let e = src[i + 1]
var r = e
if e == 110 { r = 10 }
if e == 114 { r = 13 }
if e == 116 { r = 9 }
if e == 48 { r = 0 }
out[j] = r; j = j + 1; i = i + 2
@ -86,6 +87,7 @@ function lex(src: pointer) -> void {
if src[i] == 92 {
let e = src[i + 1]
if e == 110 { v = 10 }
if e == 114 { v = 13 }
if e == 116 { v = 9 }
if e == 48 { v = 0 }
i = i + 2

View file

@ -194,6 +194,8 @@ function p_postfix() -> Node {
if e.a.kind == E_ID and e.a.s == "Motion" and e.s == "to" { g_uses_anim_rt = true }
# Audio.* (#22) — any Audio method splices the audio runtime.
if e.a.kind == E_ID and e.a.s == "Audio" { g_uses_audio = true }
# Http.* (#6) — any Http method splices the HTTP client runtime.
if e.a.kind == E_ID and e.a.s == "Http" { g_uses_http = true }
# Tween.to/chain/delay/value/stop/parallel (#48): the fluent stateful handles
# live in tween.ludic, advanced by an engine-owned system each Update tick.
if e.a.kind == E_ID and e.a.s == "Tween" and (e.s == "to" or e.s == "chain" or e.s == "delay" or e.s == "value" or e.s == "stop" or e.s == "parallel") { g_uses_tween_rt = true }
@ -429,6 +431,7 @@ var g_uses_input: bool = false # a program used Input.bind/down/poll/… (act
var g_uses_anim_rt: bool = false # Anim.play/clip/on_frame/fired or Motion.to (#48) -> splice systems.ludic + force the reflection ABI
var g_uses_tween_rt: bool = false # Tween.to/chain/delay/… (#48) -> splice tween.ludic + run esys_tween each Update
var g_uses_audio: bool = false # Audio.* (#22) -> splice audio.ludic; a windowed build also links audio.ll + AVFoundation
var g_uses_http: bool = false # Http.* (#6) -> splice http.ludic; links http.ll + Foundation (macOS)
function already_loaded(full: pointer) -> bool {
var i = 0
@ -657,6 +660,14 @@ function maybe_splice_runtime() -> void {
do_import("runtime/native/audio.ludic")
cur_dir = saved
}
# Http.* (#6): splice the HTTP client. The transport (hs_* intrinsics) is native
# (linked from http.ll), but the response parser is pure Ludic; self-contained,
# so it works in a plain program too.
if g_uses_http {
cur_dir = ""
do_import("runtime/native/http.ludic")
cur_dir = saved
}
# Anim.play/Motion.to sugar (#48): the writes live in systems.ludic and use the
# reflection ABI, so splice it and force the world table even when the game does
# not otherwise trip uses_engine_systems.

File diff suppressed because it is too large Load diff

View file

@ -173,6 +173,13 @@ entry {
cmd = `{cmd} {audio} -Wl,-needed_framework,AVFoundation`
}
}
# Http.* (#6) links the native transport and Foundation (NSURLConnection etc.,
# reached by name). Works headless too, so it is outside the windowed block —
# macOS-only for now, which is where the toolchain runs.
if g_uses_http {
let http = path_join(home, "runtime/native/http.ll")
cmd = `{cmd} {http} -Wl,-needed_framework,Foundation`
}
cmd = `{cmd} -o {out}`
let rc = run(cmd)