src/stdlib/core.panack
Green: covered; red: known zero; amber: unavailable. Blank lines are outside the executable-start-line denominator.
1 // Automatically loaded core types and method implementations. 2 // The loader gives core_* functions internal, source-inaccessible identities. 3 4 enum Option[T] { 5 None, 6 Some(T) 7 } 8 9 enum Result[T, E] { 10 Ok(T), 11 Error(E) 12 } 13 14 // Lengths and offsets use Unicode code points, like starts_with_at. 15 pure core_ends_with(value: Str, suffix: Str): Bool { 16 value_length = len(value) 17 suffix_length = len(suffix) 18 if value_length >= suffix_length { 19 // The checker proves constant bounds, not relations between two lengths. 20 // Use exact signed arithmetic and a checked natural-number projection. 21 length: Int = value_length 22 offset = ((length - suffix_length) / 1).nat() 23 starts_with_at(value, suffix, offset) 24 } else { 25 false 26 } 27 } 28 29 pure core_first[T](values: [T]): Option[T] { 30 if values.len() == 0 { 31 None() 32 } else { 33 Some(values[0]) 34 } 35 } 36 37 // Stable merge sort. less(a, b) must describe a strict weak ordering. 38 // Equal elements come from the left half first, preserving input order. 39 pure core_sort_by[T](values: [T], less: PureFn[T,T,Bool]): [T] { 40 if values.len() < 2 { 41 values 42 } else { 43 middle = quotient(values.len(), 2) 44 mut left_input: [T] = [] 45 mut right_input: [T] = [] 46 for index in 0..middle { 47 left_input = left_input.append(values[index]) 48 } 49 for index in middle..values.len() { 50 right_input = right_input.append(values[index]) 51 } 52 left = core_sort_by(left_input, less) 53 right = core_sort_by(right_input, less) 54 mut result: [T] = [] 55 mut left_index: Nat = 0 56 mut right_index: Nat = 0 57 while left_index < left.len() && right_index < right.len() { 58 if less.call(right[right_index], left[left_index]) { 59 result = result.append(right[right_index]) 60 right_index = right_index + 1 61 } else { 62 result = result.append(left[left_index]) 63 left_index = left_index + 1 64 } 65 } 66 while left_index < left.len() { 67 result = result.append(left[left_index]) 68 left_index = left_index + 1 69 } 70 while right_index < right.len() { 71 result = result.append(right[right_index]) 72 right_index = right_index + 1 73 } 74 result 75 } 76 } 77
Functions
[
{
"id": "declaration/2",
"name": "core_ends_with",
"line": 15,
"state": "covered",
"entries": "24"
},
{
"id": "declaration/3",
"name": "core_first",
"line": 29,
"state": "covered",
"entries": "2"
},
{
"id": "declaration/4",
"name": "core_sort_by",
"line": 39,
"state": "covered",
"entries": "1218"
}
]Source branch outcomes
[
{
"id": "declaration/2/tail/decision/true",
"outcome": "true",
"line": 18,
"state": "covered",
"hits": "22"
},
{
"id": "declaration/2/tail/decision/false",
"outcome": "false",
"line": 18,
"state": "covered",
"hits": "2"
},
{
"id": "declaration/3/tail/decision/true",
"outcome": "true",
"line": 30,
"state": "covered",
"hits": "1"
},
{
"id": "declaration/3/tail/decision/false",
"outcome": "false",
"line": 30,
"state": "covered",
"hits": "1"
},
{
"id": "declaration/4/tail/decision/true",
"outcome": "true",
"line": 40,
"state": "covered",
"hits": "624"
},
{
"id": "declaration/4/tail/decision/false",
"outcome": "false",
"line": 40,
"state": "covered",
"hits": "594"
},
{
"id": "declaration/4/tail/false/statement/3/decision/body",
"outcome": "body",
"line": 46,
"state": "covered",
"hits": "2165"
},
{
"id": "declaration/4/tail/false/statement/3/decision/exit",
"outcome": "exit",
"line": 46,
"state": "covered",
"hits": "594"
},
{
"id": "declaration/4/tail/false/statement/4/decision/body",
"outcome": "body",
"line": 49,
"state": "covered",
"hits": "2211"
},
{
"id": "declaration/4/tail/false/statement/4/decision/exit",
"outcome": "exit",
"line": 49,
"state": "covered",
"hits": "594"
},
{
"id": "declaration/4/tail/false/statement/10/decision/body",
"outcome": "body",
"line": 57,
"state": "covered",
"hits": "2229"
},
{
"id": "declaration/4/tail/false/statement/10/decision/exit",
"outcome": "exit",
"line": 57,
"state": "covered",
"hits": "594"
},
{
"id": "declaration/4/tail/false/statement/10/condition/decision/evaluate-right",
"outcome": "evaluate-right",
"line": 57,
"state": "covered",
"hits": "2522"
},
{
"id": "declaration/4/tail/false/statement/10/condition/decision/skip-right",
"outcome": "skip-right",
"line": 57,
"state": "covered",
"hits": "301"
},
{
"id": "declaration/4/tail/false/statement/10/body/tail/decision/true",
"outcome": "true",
"line": 58,
"state": "covered",
"hits": "1127"
},
{
"id": "declaration/4/tail/false/statement/10/body/tail/decision/false",
"outcome": "false",
"line": 58,
"state": "covered",
"hits": "1102"
},
{
"id": "declaration/4/tail/false/statement/11/decision/body",
"outcome": "body",
"line": 66,
"state": "covered",
"hits": "1063"
},
{
"id": "declaration/4/tail/false/statement/11/decision/exit",
"outcome": "exit",
"line": 66,
"state": "covered",
"hits": "594"
},
{
"id": "declaration/4/tail/false/statement/12/decision/body",
"outcome": "body",
"line": 70,
"state": "covered",
"hits": "1084"
},
{
"id": "declaration/4/tail/false/statement/12/decision/exit",
"outcome": "exit",
"line": 70,
"state": "covered",
"hits": "594"
}
]Reviewed declaration exclusions
[
{
"id": "declaration/0",
"reason": "enum-declaration",
"line": 4
},
{
"id": "declaration/1",
"reason": "enum-declaration",
"line": 9
}
]