Prepare short portable helpers and scalar record reads, improve JSON SIMD scanning, expose one-line execution, and publish qualified Alpha benchmark artifacts. Add the experimental verified lowered execution, serialization and Linux x86-64 backend with source maps. Physically remove 263 redundant test entry points and unused helpers, migrate retained helpers to Ziran, and execute the full retained suite without sharding. Allow ignored backup state for the managed physical Alpha workflow. Local validation: all 268 retained tests passed across the full run and corrected targeted reruns; bootstrap matches. Current assembly verifier, x86-64, executor and serializer tests passed. Website examples and all 4661 local links passed. Six Alpha JSON/text workloads retain verified artifacts, raw samples and explicit unsupported Wasm diagnostics. The mobile sub-500 ns target remains pending.
292 lines
9.3 KiB
Ziran
292 lines
9.3 KiB
Ziran
#import "std/vec"
|
|
#import "std/option"
|
|
|
|
Kernel :: (seed: s64, limit: s32, choose: bool) -> s64 {
|
|
total := seed
|
|
i: s32
|
|
while i < limit {
|
|
i += 1
|
|
if i % 5 == 0 { continue }
|
|
local := total + cast(s64)i
|
|
{
|
|
local := cast(s64)i * 3
|
|
total += local
|
|
}
|
|
if choose && i % 3 == 0 { total ^= local }
|
|
else if !choose || i % 7 == 0 { total -= local / 7 }
|
|
else { total += local & 255 }
|
|
selected := ifx choose then total + seed else total - seed
|
|
total = selected ^ (total >> 3)
|
|
if i > 19 { break }
|
|
}
|
|
return total
|
|
}
|
|
|
|
Named :: (seed: s64, limit: s32, choose: bool) -> s64 {
|
|
total := seed
|
|
for outer: 0..limit {
|
|
saved := total
|
|
for inner: 0..9 {
|
|
local := cast(s64)inner
|
|
if inner == 1 && choose { continue outer }
|
|
if outer > 5 && inner == 2 { break outer }
|
|
if inner == 7 { break }
|
|
total += local + saved
|
|
}
|
|
total += 1
|
|
}
|
|
return total
|
|
}
|
|
|
|
Numeric :: (seed: s64, limit: s32, choose: bool) -> s64 {
|
|
wide: u64 = 18446744073709551615
|
|
narrow: s8 = -128
|
|
real: float32 = cast(float32)16777217.0
|
|
total := seed
|
|
for i: 0..limit {
|
|
wide ^= wide >> cast(u64)7
|
|
wide ^= wide << cast(u64)13
|
|
narrow += cast(s8)i
|
|
real = real * cast(float32)0.5 + cast(float32)(i % 13)
|
|
total += cast(s64)(wide & 255) + cast(s64)narrow + cast(s64)real
|
|
if choose && wide > 9007199254740992 { total += 1 }
|
|
}
|
|
return total
|
|
}
|
|
|
|
Skipped :: (seed: s64, limit: s32, choose: bool) -> s64 {
|
|
zero: s64
|
|
if choose && false && seed / zero > 0 { return 91 }
|
|
if true || seed / zero > 0 { seed += 1 }
|
|
selected := ifx choose then seed + cast(s64)limit else seed - cast(s64)limit
|
|
return selected
|
|
}
|
|
|
|
Failure :: (seed: s64, limit: s32, choose: bool) -> s64 {
|
|
if choose { return seed / cast(s64)limit }
|
|
return seed << limit
|
|
}
|
|
|
|
RealFailure :: (seed: s64, limit: s32, choose: bool) -> s64 {
|
|
number: float64 = 1.0 / cast(float64)limit
|
|
if choose { number = -number }
|
|
return cast(s64)number + seed
|
|
}
|
|
|
|
TextScan :: (text: string, limit: s32, choose: bool) -> s64 {
|
|
selected := text
|
|
{
|
|
selected: string
|
|
if choose { selected = text }
|
|
if selected.count > text.count { return -1 }
|
|
}
|
|
total: s64
|
|
i := limit
|
|
while i >= 0 && i < cast(s32)selected.count {
|
|
byte := selected[i]
|
|
i += 1
|
|
if choose && byte == cast(u8)0 { continue }
|
|
total += cast(s64)byte
|
|
if byte == cast(u8)255 { break }
|
|
}
|
|
return total
|
|
}
|
|
|
|
TextFailure :: (text: string, limit: s32, choose: bool) -> s64 {
|
|
length := cast(s64)text.count
|
|
return ifx choose then cast(s64)text[limit] else length
|
|
}
|
|
|
|
TextCopy :: (text: string, limit: s32, choose: bool) -> string {
|
|
first := text
|
|
second: string
|
|
if choose { second = first; first = second }
|
|
else { first = second }
|
|
return ifx limit < 0 then text else first
|
|
}
|
|
|
|
TextCompare :: (text: string, limit: s32, choose: bool) -> s64 {
|
|
empty: string
|
|
selected := ifx choose then text else empty
|
|
result := cast(s64)(selected == text) + cast(s64)(selected != empty)
|
|
if limit > 0 && selected.count > 0 {
|
|
result += cast(s64)selected[0]
|
|
}
|
|
return result
|
|
}
|
|
|
|
CollectionTouch :: (values: []s64) -> s64 {
|
|
values[0] += 5
|
|
return values[0]
|
|
}
|
|
|
|
CollectionCopies :: (seed: s64, limit: s32, choose: bool) -> s64 {
|
|
values: [3]s64 = .[seed, seed + 1, seed + 2]
|
|
copy := values
|
|
total := CollectionTouch(values[:])
|
|
for round: 0..limit {
|
|
for value, index: copy {
|
|
if choose && index == 1 { continue }
|
|
total += value + round
|
|
if round > 5 { break }
|
|
}
|
|
}
|
|
return total
|
|
}
|
|
|
|
CollectionStrings :: (seed: s64, limit: s32, choose: bool) -> s64 {
|
|
texts: [3]string = .["a", "café", "世界"]
|
|
total := seed
|
|
for outer: 0..limit {
|
|
for text, index: texts {
|
|
total += text.count + cast(s64)text[0]
|
|
if choose && index == 1 { continue outer }
|
|
}
|
|
}
|
|
return total
|
|
}
|
|
|
|
CollectionZero :: (seed: s64, limit: s32, choose: bool) -> s64 {
|
|
values: [4]s64
|
|
empty: [0]u8
|
|
total := seed
|
|
for value: values { total += value }
|
|
for byte: empty { total += cast(s64)byte }
|
|
return total + cast(s64)limit + cast(s64)choose
|
|
}
|
|
|
|
PlanPair :: struct { low: s32; high: s32; }
|
|
PlanWide :: struct { count: s64; value: s64; tag: s64; text: string; }
|
|
|
|
RecordSum :: (pair: PlanPair) -> s64 {
|
|
return cast(s64)pair.low + cast(s64)pair.high
|
|
}
|
|
|
|
RecordFields :: (seed: s64, limit: s32, choose: bool) -> s64 {
|
|
pair: PlanPair = .{low = cast(s32)seed, high = limit}
|
|
if choose { pair.low += pair.high }
|
|
return RecordSum(pair) + cast(s64)pair.high
|
|
}
|
|
|
|
RecordCountField :: (seed: s64, limit: s32, choose: bool) -> s64 {
|
|
wide: PlanWide = .{count = seed, value = cast(s64)limit,
|
|
tag = cast(s64)choose, text = "café"}
|
|
return wide.count + wide.value + wide.tag + wide.text.count
|
|
}
|
|
|
|
ShortRead :: (seed: s64, limit: s32, choose: bool) -> s64 {
|
|
return seed
|
|
}
|
|
|
|
CallSet :: (target: *s64, value: s64) -> s64 { <<target = value; return 5 }
|
|
CallVoid :: (target: *s64, value: s64) { <<target = value }
|
|
CallPair :: (left: s64, right: s64) -> s64 { return left * 10 + right }
|
|
CallDivide :: (seed: s64, limit: s32) -> s64 { return seed / cast(s64)limit }
|
|
CallShift :: (seed: s64, limit: s32) -> s64 { return seed << limit }
|
|
CallRecurse :: (seed: s64, depth: s32) -> s64 {
|
|
if depth <= 0 { return seed }
|
|
return CallRecurse(seed + 1, depth - 1)
|
|
}
|
|
CallOrdering :: (seed: s64, limit: s32, choose: bool) -> s64 {
|
|
total := seed
|
|
first := total + CallSet(*total, cast(s64)limit) + total
|
|
total += CallSet(*total, 17)
|
|
CallVoid(*total, total + 1)
|
|
if choose && CallSet(*total, 23) > 0 { total += 1 }
|
|
if false && CallDivide(seed, 0) > 0 { return 91 }
|
|
if true || CallDivide(seed, 0) > 0 { total += 0 }
|
|
pair := CallPair(right = CallSet(*total, 3), left = total)
|
|
return first + total + pair
|
|
}
|
|
CallErrors :: (seed: s64, limit: s32, choose: bool) -> s64 {
|
|
return ifx choose then CallDivide(seed, limit) else CallShift(seed, limit)
|
|
}
|
|
CallRecursive :: (seed: s64, limit: s32, choose: bool) -> s64 {
|
|
depth := ifx limit > 16 then 16 else limit
|
|
result := CallRecurse(seed, depth)
|
|
if choose { result += CallPair(right = 2, left = 3) }
|
|
return result
|
|
}
|
|
Callback :: #type (value: s64) -> s64;
|
|
callback: Callback;
|
|
CallPlus :: (value: s64) -> s64 { return value + 3 }
|
|
CallMinus :: (value: s64) -> s64 { return value - 3 }
|
|
CallChoose :: (choose: bool) {
|
|
if choose { callback = CallPlus }
|
|
else { callback = CallMinus }
|
|
}
|
|
CallSlot :: (seed: s64, limit: s32, choose: bool) -> s64 {
|
|
CallChoose(choose)
|
|
first := callback(seed)
|
|
CallChoose(!choose)
|
|
return first + callback(cast(s64)limit)
|
|
}
|
|
FreshText :: (text: string) -> string {
|
|
builder: Vec(u8)
|
|
unused BuilderAppend(builder, text)
|
|
return BuilderFinish(builder)
|
|
}
|
|
TextCalls :: (text: string, limit: s32, choose: bool) -> string {
|
|
first := FreshText(text)
|
|
second := FreshText(first)
|
|
{
|
|
temporary := FreshText(second)
|
|
if choose { second = FreshText(temporary) }
|
|
}
|
|
replaced := FreshText(first)
|
|
if limit < 0 { return FreshText(second) }
|
|
return replaced
|
|
}
|
|
TextCallScan :: (text: string, limit: s32, choose: bool) -> s64 {
|
|
total := cast(s64)(FreshText(text) == FreshText(text))
|
|
copied := ifx choose then FreshText(text) else FreshText(text)
|
|
i: s32
|
|
while i < limit && i < cast(s32)copied.count {
|
|
total += cast(s64)FreshText(copied)[i]
|
|
i += 1
|
|
}
|
|
return total
|
|
}
|
|
TextReplace :: (target: *string, replacement: string) -> string {
|
|
<<target = FreshText(replacement)
|
|
return FreshText(replacement)
|
|
}
|
|
TextCallMutation :: (text: string, limit: s32, choose: bool) -> s64 {
|
|
saved := FreshText(text)
|
|
empty: string
|
|
same := saved == TextReplace(*saved, empty)
|
|
if choose { return cast(s64)same }
|
|
return cast(s64)saved.count + cast(s64)(limit == 0)
|
|
}
|
|
|
|
state: s32;
|
|
Bump :: () -> s32 { state = 10; return 5 }
|
|
Fallback :: () -> s32 {
|
|
state = 1
|
|
state += Bump()
|
|
return state
|
|
}
|
|
|
|
#program_export
|
|
Answer :: () -> s64 {
|
|
if RecordFields(7, 2, true) != 13 { return 23 }
|
|
if RecordCountField(7, 2, true) != 15 { return 24 }
|
|
if ShortRead(37, 2, false) != 37 { return 25 }
|
|
if CollectionCopies(1, 0, false) != 12 { return 20 }
|
|
if CollectionStrings(0, 0, false) != 436 { return 21 }
|
|
if CollectionZero(7, 2, true) != 10 { return 22 }
|
|
if Fallback() != 6 { return 1 }
|
|
if TextScan("ab", 0, false) != 195 || TextFailure("xy", 1, true) != 121 { return 3 }
|
|
if TextCopy("ab", 0, true) != "ab" || TextCompare("ab", 1, true) != 99 { return 4 }
|
|
if CallOrdering(3, 7, true) != 53 || CallErrors(9, 2, true) != 4 ||
|
|
CallRecursive(3, 7, true) != 42 || CallSlot(35, 7, true) != 42 { return 5 }
|
|
if TextCalls("ab", 1, true) != "ab" || TextCallScan("ab", 2, false) != 196 { return 6 }
|
|
if TextCallMutation("ab", 1, true) != 0 { return 7 }
|
|
result := Kernel(3, 7, true) + Named(1, 6, false) + Numeric(7, 11, true)
|
|
result += Skipped(2, 3, false) + Failure(9, 2, true) + RealFailure(3, 2, false)
|
|
result += Large(5, 3, false)
|
|
// The C driver compares dynamic arguments and every step boundary.
|
|
if result == 0 { return 2 }
|
|
return 42
|
|
}
|