refactor(runtime,packages,examples): named constants, package enums, idiom sweep
- runtime: HEADLESS_FRAME_PATH, STICK_DEADZONE / STICK_LEFT_X/Y, key and byte codes as char literals throughout (`k == 'w'`, `fill(rt_map, ' ', …)`) - ludic.gameplay/stats: drop the duplicate `stat_field` (it answered "atk" for every build stat); Stats.base uses stats_field_name - ludic.shooter: compare aim modes and fire patterns with AimMode.* and WeaponPattern.* instead of raw ints; STICK_RIGHT_X/Y - ludic.npcai: DecisionMade / brain_set_state use AiState.* - examples/games/menu.ludic uses Font.load / Ui.* with FONT_PATH and BACKDROP named; strings.ludic header says what it prints - whole tree: `x = x + 1` → `x += 1` (single-term right-hand sides only), `0 - x` → `-x`, ASCII codes → char literals; every .ludic and every ```ludic fence reformatted with the fixed formatter (whitespace only) Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
parent
e3e1bc7784
commit
bf36bc8a8f
103 changed files with 1256 additions and 1252 deletions
|
|
@ -47,7 +47,7 @@ function http_init() -> void {
|
|||
h_used[i] = 0; h_native[i] = 0; h_sent[i] = 0; h_res[i] = 0
|
||||
h_status[i] = 0; h_blen[i] = 0
|
||||
h_req[i] = null; h_body[i] = null; h_hdr[i] = null
|
||||
i = i + 1
|
||||
i += 1
|
||||
}
|
||||
h_ready = true
|
||||
}
|
||||
|
|
@ -62,9 +62,9 @@ function http_slot_alloc() -> int {
|
|||
h_req[i] = null; h_body[i] = null; h_hdr[i] = null
|
||||
return i
|
||||
}
|
||||
i = i + 1
|
||||
i += 1
|
||||
}
|
||||
return 0 - 1
|
||||
return -1
|
||||
}
|
||||
|
||||
function http_valid(h: int) -> bool {
|
||||
|
|
@ -77,7 +77,7 @@ function http_valid(h: int) -> bool {
|
|||
function http_cstr_len(p: pointer) -> int {
|
||||
if p == null { return 0 }
|
||||
var n = 0
|
||||
while p[n] != 0 { n = n + 1 }
|
||||
while p[n] != 0 { n += 1 }
|
||||
return n
|
||||
}
|
||||
|
||||
|
|
@ -147,9 +147,9 @@ function http_poll(h: int) -> int {
|
|||
if not http_valid(h) { return 0 }
|
||||
let s = h - 1
|
||||
if h_native[s] == 0 { return h_status[s] } # a parsed handle is ready immediately
|
||||
if h_sent[s] == 0 { return 0 - 1 }
|
||||
if h_sent[s] == 0 { return -1 }
|
||||
if h_res[s] == 1 { return h_status[s] }
|
||||
if hs_done(s) == 0 { return 0 - 1 }
|
||||
if hs_done(s) == 0 { return -1 }
|
||||
# first time we see it finished: cache the fields off the worker.
|
||||
h_status[s] = hs_status(s)
|
||||
h_body[s] = hs_body(s)
|
||||
|
|
@ -204,13 +204,13 @@ function http_slice_dup(src: pointer, a: int, b: int) -> pointer {
|
|||
if n < 0 { n = 0 }
|
||||
let out = bytes(n + 1)
|
||||
var i = 0
|
||||
while i < n { out[i] = src[a + i]; i = i + 1 }
|
||||
while i < n { out[i] = src[a + i]; i += 1 }
|
||||
out[n] = 0
|
||||
return out
|
||||
}
|
||||
|
||||
function http_is_digit(c: int) -> bool { return (c >= 48) and (c <= 57) }
|
||||
function http_lower(c: int) -> int { if (c >= 65) and (c <= 90) { return c + 32 }; return c }
|
||||
function http_is_digit(c: int) -> bool { return (c >= '0') and (c <= '9') }
|
||||
function http_lower(c: int) -> int { if (c >= 'A') and (c <= 'Z') { return c + 32 }; return c }
|
||||
|
||||
# Parse a raw HTTP/1.1 response (status line + headers + blank line + body) into
|
||||
# a ready handle. Useful for cached/custom transports and offline tests.
|
||||
|
|
@ -221,20 +221,20 @@ function http_parse(resp: pointer, len: int) -> int {
|
|||
|
||||
# status: the token after the first space on the status line.
|
||||
var i = 0
|
||||
while (i < len) and (resp[i] != 32) { i = i + 1 } # skip "HTTP/1.1"
|
||||
while (i < len) and (resp[i] == 32) { i = i + 1 } # skip the space(s)
|
||||
while (i < len) and (resp[i] != ' ') { i += 1 } # skip "HTTP/1.1"
|
||||
while (i < len) and (resp[i] == ' ') { i += 1 } # skip the space(s)
|
||||
var st = 0
|
||||
while (i < len) and http_is_digit(resp[i]) { st = (st * 10) + (resp[i] - 48); i = i + 1 }
|
||||
while (i < len) and http_is_digit(resp[i]) { st = (st * 10) + (resp[i] - 48); i += 1 }
|
||||
h_status[s] = st
|
||||
|
||||
# header/body split at the first CRLFCRLF.
|
||||
var split = 0 - 1
|
||||
var split = -1
|
||||
var j = 0
|
||||
while (j + 3) < len {
|
||||
if (resp[j] == 13) and (resp[j + 1] == 10) and (resp[j + 2] == 13) and (resp[j + 3] == 10) {
|
||||
if (resp[j] == '\r') and (resp[j + 1] == '\n') and (resp[j + 2] == '\r') and (resp[j + 3] == '\n') {
|
||||
split = j
|
||||
j = len
|
||||
} else { j = j + 1 }
|
||||
} else { j += 1 }
|
||||
}
|
||||
var hdr_end = split
|
||||
var body_start = split + 4
|
||||
|
|
@ -243,8 +243,8 @@ function http_parse(resp: pointer, len: int) -> int {
|
|||
# header block starts after the status line's CRLF.
|
||||
var hs = 0
|
||||
while (hs + 1) < len {
|
||||
if (resp[hs] == 13) and (resp[hs + 1] == 10) { hs = hs + 2; break }
|
||||
hs = hs + 1
|
||||
if (resp[hs] == '\r') and (resp[hs + 1] == '\n') { hs += 2; break }
|
||||
hs += 1
|
||||
}
|
||||
if hs > hdr_end { hs = hdr_end }
|
||||
h_hdr[s] = http_slice_dup(resp, hs, hdr_end)
|
||||
|
|
@ -264,17 +264,17 @@ function http_find_header(hdr: pointer, name: pointer) -> pointer {
|
|||
while i < hlen {
|
||||
# match name at the start of a line, followed by ':'.
|
||||
var k = 0
|
||||
while (k < nlen) and ((i + k) < hlen) and (http_lower(hdr[i + k]) == http_lower(name[k])) { k = k + 1 }
|
||||
if (k == nlen) and ((i + k) < hlen) and (hdr[i + k] == 58) {
|
||||
while (k < nlen) and ((i + k) < hlen) and (http_lower(hdr[i + k]) == http_lower(name[k])) { k += 1 }
|
||||
if (k == nlen) and ((i + k) < hlen) and (hdr[i + k] == ':') {
|
||||
var v = i + k + 1
|
||||
while (v < hlen) and (hdr[v] == 32) { v = v + 1 } # skip spaces after ':'
|
||||
while (v < hlen) and (hdr[v] == ' ') { v += 1 } # skip spaces after ':'
|
||||
var e = v
|
||||
while (e < hlen) and (hdr[e] != 13) and (hdr[e] != 10) { e = e + 1 }
|
||||
while (e < hlen) and (hdr[e] != '\r') and (hdr[e] != '\n') { e += 1 }
|
||||
return http_slice_dup(hdr, v, e)
|
||||
}
|
||||
# advance to the next line.
|
||||
while (i < hlen) and (hdr[i] != 10) { i = i + 1 }
|
||||
i = i + 1
|
||||
while (i < hlen) and (hdr[i] != '\n') { i += 1 }
|
||||
i += 1
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue