Merge branch 'lang/sb-stdout' into lang/foundations

This commit is contained in:
Orkun ÇAKILKAYA 2026-09-28 23:17:32 +03:00
commit 0ed66baed0
3 changed files with 24 additions and 5 deletions

View file

@ -64,3 +64,10 @@ export function sb_pat(sb: StrBuf, pat: string, a: string, b: string, c: string,
}
}
}
# the buffer's bytes to standard output as they are (no string made, no newline added): a line a
# frame's code writes without the fence seeing a text kept
export function sb_stdout(sb: StrBuf) -> void {
if sb.n <= 0 { return }
unsafe { file_write(file_stdout(), data_of(sb.b), sb.n) }
}

View file

@ -13,21 +13,32 @@ export function jobs_at(jobs_st: JobsState, group: int, vendor: int) -> []int {
}
# every job of a group taken at some point, done ones too
export function jobs_taken(jobs_st: JobsState, group: int) -> []int {
let out = new []int
for i in 0 .. JOB_COUNT { if Jobs[i].group == group and jobs_state(jobs_st, i) != JOBS_OFFERED { push(out, i) } }
export function jobs_taken(jobs_st: mut JobsState, group: int) -> []int {
let out = jobs_st.jobs__lists[group * 2]
List.clear(out)
for i in 0 .. JOB_COUNT {
@alloc_ok("a kept list, cleared each ask: grows once to the group's jobs")
if Jobs[i].group == group and jobs_state(jobs_st, i) != JOBS_OFFERED { push(out, i) }
}
return out
}
# the first `most` of a group under way
export function jobs_shown(jobs_st: JobsState, group: int, most: int) -> []int {
let out = new []int
export function jobs_shown(jobs_st: mut JobsState, group: int, most: int) -> []int {
let out = jobs_st.jobs__lists[group * 2 + 1]
List.clear(out)
for i in 0 .. JOB_COUNT {
if len(out) >= most { break }
@alloc_ok("a kept list, cleared each ask: grows once to `most`")
if Jobs[i].group == group and jobs_under_way(jobs_st, i) { push(out, i) }
}
return out
}
function jobs__lists_new(n: int) -> [][]int {
let out = new [][]int
for i in 0 .. n { push(out, new []int) }
return out
}
# the first under way and not yet met, or -1
export function jobs_first_open(jobs_st: JobsState, group: int) -> int {

View file

@ -7,6 +7,7 @@ export state JobsState {
jobs__back: []int = jobs__ints(JOB_COUNT, 0) # given up: the first day it may be taken again
jobs__primed: bool = false # the first tick after a reset learns the offers quietly
jobs__done_n: []int = jobs__ints(JOBS_GROUPS, 0) # handed in, per group
jobs__lists: [][]int = jobs__lists_new(2 * JOBS_GROUPS) # jobs_taken's and jobs_shown's answers, per group, filled in place
jobs__off: []int = jobs__offsets()
jobs__pk: []int = jobs__ints(jobs__slots(), -1) # kind, -1 empty
jobs__pp: []int = jobs__ints(jobs__slots(), -1)