.githooks/
compiler/
kernel/
lib/
scripts/
seed/
sublime/
test/
boot/
bootstrap/
compiler/
cycles/
dispatch/
format/
host/
integration/
kernel/
loader/
kernel/
grown.rad
1.2 KiB
hostile.rad
15.0 KiB
loaded.rad
586 B
machine.ras
731 B
manifests/
mmio/
native/
packages/
runtime/
scheduling/
shared/
slots/
smp/
std/
sync/
termination/
tests/
trap/
verify/
Makefile
9.2 KiB
kernel.rad
776 B
runner.rad
11.6 KiB
vim/
.gitignore
333 B
.gitsigners
224 B
AGENTS.md
8.3 KiB
CONTRIBUTING
2.1 KiB
LICENSE
1.1 KiB
Makefile
2.5 KiB
README
3.4 KiB
STYLE
3.2 KiB
std.lib
2.1 KiB
std.lib.test
1.1 KiB
test/loader/grown.rad
raw
| 1 | //! A package that grows slices of pointer-holding elements in a static heap, executed by hosted |
| 2 | //! compilation and the loader. The loader reads a package from one page, so the program stays small. |
| 3 | |
| 4 | /// The allocation error, which the compiler knows. |
| 5 | @language union AllocError: Copy { OutOfMemory } |
| 6 | |
| 7 | /// A heap, which holds elements of any type. |
| 8 | @language record Heap {} |
| 9 | |
| 10 | /// Allocate the backing storage of a static heap. |
| 11 | @intrinsic constant fn new(size: u32) -> Heap; |
| 12 | |
| 13 | |
| 14 | /// The allocator view of a heap. |
| 15 | @language record Allocator {} |
| 16 | |
| 17 | /// Memory for the slices of this package. |
| 18 | static POOL: Heap = new(256); |
| 19 | |
| 20 | /// Numbers that holders point to. |
| 21 | static NUMBERS: [u32; 2] = [20, 22]; |
| 22 | |
| 23 | /// A record that holds a pointer. |
| 24 | record Holder { |
| 25 | /// Owned pointer to a number. |
| 26 | p: *u32, |
| 27 | } |
| 28 | |
| 29 | /// Grow slices, and return the checked result. |
| 30 | @default fn main() -> i32 { |
| 31 | let mut hs: *mut [Holder] = &mut []; |
| 32 | for i in 0 .. 2 { |
| 33 | try! hs.append(Holder { p: &NUMBERS[i] }, &POOL); |
| 34 | } |
| 35 | let mut big: *mut [Holder] = &mut []; |
| 36 | try big.reserve(1000, &POOL) catch e { |
| 37 | assert e == AllocError::OutOfMemory; |
| 38 | return (*hs[0].p + *hs[1].p) as i32; |
| 39 | }; |
| 40 | return 1; |
| 41 | } |