Source tensors, gradients and Linux native-exe
Published compiler: v0.0.7-alpha.5.
Tensor types and shape checks
tensor<float, ...> includes dimensions in its type. Immutable finite binary64 tensors support checked indexing, broadcasting, batched matmul, reshape, transpose, concatenation and reductions. Rank is at most eight and cell count at most 65,536; work and memory budgets apply.
Gradient and optimizer
tensor_value_grad returns a value and gradient for a selected parameter; tensor_sgd, Adam and AdamW offer bounded updates. Here is the tagged upstream source and exact output, including binary64 rounding.
pure funcra identity<T>(value: T) -> T {
return value;
}
bind features: tensor<float, 2, 2> = [[1.0, 2.0], [3.0, 4.0]];
bind weights: tensor<float, 2, 1> = [[0.5], [1.0]];
bind scores = identity(matmul(features, weights));
bind result = tensor_value_grad(weights, tensor_sum(tensor_square(matmul(features, weights))));
bind next_weights = tensor_sgd(weights, result[1], 0.01);
print(scores, result[0]);
print(result[1], next_weights);
bind x = 3.0;
bind offset = 2.0;
print(value_grad(x, scalar_square(x) + x * offset));
tensor<float, 2, 1> [2.5, 5.5] 36.5
tensor<float, 2, 1> [38.0, 54.0] tensor<float, 2, 1> [0.12, 0.45999999999999996]
(15.0, 8.0)
Run: scarp exec examples/tensor_learning.srp. Pinned source · Pinned stdout.
Signed and unsigned fixed-width integers
i8…i128, u8…u128, and 64-bit isize/usize are distinct types. Explicit to_i8…to_u128 conversions check representability, and mixed widths do not coerce. Default arithmetic checks overflow; wrapping and saturating helpers are explicit.
Bounded Linux executable
scarp native-exe emits standalone Linux x86-64 ELF64. Source needs zero-argument pure funcra main() -> integer. I/O, tensors, heap data and recursion are unsupported. Work and private stack limits are required. Exit codes 0–125 represent returned values; 126 means out-of-range return and 129–135 encode native runtime errors. The output filename must be new.
pure funcra sum_to(count: integer) -> integer {
var total = 0;
repeat count as index {
total += index;
}
return total;
}
pure funcra main() -> integer {
return sum_to(10);
}
scarp native-exe linux-x86_64 1000 4096 examples/native_linux_exit.srp -o scarp-exit
./scarp-exit
echo $? # 45
BigInt file format and lifetime
Experimental file-backed scarp bigint can convert checksummed SCBIGV01 storage. File-backed and interpreter BigInt have separate budgets. Lifetime releases dead interpreter bindings after their last use; this is neither a process RAM cap nor a cycle collector.