compiler/
lib/
examples/
std/
arch/
rv64/
tests/
abi.sizes.rad
3.4 KiB
aggregate.return.rad
4.0 KiB
arith.assignment.rad
580 B
arith.basic.rad
176 B
arith.modulo.rad
96 B
arith.subword.rad
3.8 KiB
arith.sum.rad
177 B
arith.w64.rad
4.1 KiB
array.assign.rad
221 B
array.bounds.check.rad
321 B
array.index.assign.rad
367 B
array.index.rad
249 B
array.length.rad
262 B
array.math.rad
1.2 KiB
array.nested.assign.rad
319 B
array.nested.rad
325 B
array.record.elements.rad
1.7 KiB
array.repeat.edge.rad
548 B
array.repeat.rad
828 B
array.return.rad
330 B
array.slice.empty.rad
108 B
array.slice.gen.end.rad
126 B
array.slice.gen.index.rad
139 B
array.slice.gen.open.rad
125 B
array.slice.gen.start.end.rad
127 B
array.slice.gen.start.rad
126 B
array.slice.rad
759 B
as.precedence.rad
212 B
assert.basic.rad
387 B
assert.fail.rad
138 B
assert.false.rad
140 B
assert.true.rad
100 B
assign.mutable.rad
6.1 KiB
assign.rad
129 B
assign.shadow.mutable.rad
461 B
binop.bitwise.rad
1.2 KiB
binop.cmp.rad
426 B
bool.comparison.array.rad
688 B
bool.comparison.nested.gen.rad
1.0 KiB
bool.comparison.opt.rad
905 B
bool.comparison.record.gen.rad
1.0 KiB
bool.comparison.record.rad
1.1 KiB
bool.comparison.slice.gen.rad
157 B
bool.comparison.slice.rad
4.1 KiB
bool.comparison.slice.record.gen.rad
2.0 KiB
bool.comparison.slice.union.gen.rad
2.5 KiB
bool.comparison.union.ctor.rad
690 B
bool.comparison.union.gen.rad
1.2 KiB
bool.comparison.union.record.gen.rad
1.5 KiB
bool.comparison.union.simple.gen.rad
281 B
bool.operators.complex.rad
384 B
bool.operators.rad
831 B
bool.short.circuit.rad
2.3 KiB
bool.simple.rad
194 B
bool.values.rad
772 B
builtin.size.align.rad
1.3 KiB
builtin.sliceof.mut.rad
606 B
builtin.sliceof.rad
505 B
call.arg.clobber.rad
717 B
call.basic.rad
241 B
call.clobber.rad
462 B
cast.same.size.rad
1.0 KiB
casting.numbers.rad
1.5 KiB
char.literal.rad
165 B
compound.assign.field.rad
285 B
compound.assign.rad
1.1 KiB
cond.assign.rad
723 B
cond.expr.aggregate.rad
1.1 KiB
cond.expr.rad
1.8 KiB
cond.for.else.break.rad
326 B
cond.for.indexed.rad
238 B
cond.for.rad
165 B
cond.for.range.indexed.rad
526 B
cond.for.range.rad
171 B
cond.for.unsigned.range.rad
644 B
cond.forever.break.continue.rad
182 B
cond.forever.break.rad
232 B
cond.fused.rad
926 B
cond.if.case.rad
2.2 KiB
cond.if.else.min.rad
143 B
cond.if.else.rad
225 B
cond.if.elseif.rad
420 B
cond.if.noelse.rad
120 B
cond.if.rad
865 B
cond.match.fallthrough.rad
369 B
cond.match.guard.rad
1.4 KiB
cond.match.guard.regalloc.rad
1.3 KiB
cond.while.else.break.rad
282 B
cond.while.rad
119 B
const.array.copy.mutate.rad
386 B
const.array.rad
195 B
const.basic.rad
325 B
const.char.rad
159 B
const.fn.array.rad
664 B
const.record.array.rad
1.2 KiB
const.record.array.simple.rad
523 B
const.record.ctor.rad
170 B
const.record.fn.rad
353 B
const.record.rad
182 B
const.slice.param.rad
333 B
const.union.payload.ctor.rad
349 B
const.union.record.literal.rad
359 B
data.array.rad
767 B
data.bool.rad
216 B
data.i16.rad
261 B
data.i32.rad
281 B
data.i8.rad
248 B
data.record.rad
561 B
data.simple.rad
436 B
data.u16.rad
220 B
data.u32.rad
240 B
data.u8.rad
208 B
data.union.rad
886 B
debug.tag.rad
557 B
edge.cases.2.rad
337 B
edge.cases.3.rad
594 B
edge.cases.4.rad
1.2 KiB
edge.cases.5.rad
1.0 KiB
edge.cases.6.rad
2.6 KiB
edge.cases.7.addr.bug.rad
224 B
edge.cases.8.bug.rad
508 B
edge.cases.rad
223 B
error.basic.rad
159 B
error.catch.rad
1.6 KiB
error.division.zero.rad
164 B
error.modulo.zero.rad
162 B
error.multi.basic.rad
672 B
error.multi.catch.rad
772 B
error.multi.catch.typed.binding.rad
791 B
error.multi.catch.typed.catchall.rad
1.0 KiB
error.multi.catch.typed.rad
1.1 KiB
error.multi.propagate.multi.rad
953 B
error.multi.propagate.rad
825 B
error.multi.try.optional.rad
507 B
error.slice.bounds.rad
219 B
error.try.bang.success.rad
370 B
error.try.catch.binding.rad
2.0 KiB
error.try.optional.rad
1.8 KiB
error.try.rad
4.0 KiB
fn.block.scope.rad
508 B
fn.callback.nested.rad
1.2 KiB
fn.default.rad
131 B
fn.local.rad
140 B
fn.recursion.2.rad
239 B
fn.void.rad
150 B
for.else.continue.rad
1.1 KiB
frame.large.rad
567 B
if-let-mut.rad
1.1 KiB
iflet.shadow.leak.rad
317 B
integer.bitwise.basic.rad
693 B
integer.overflow.rad
1.8 KiB
large.blit.store.rad
2.1 KiB
let.guard.rad
1.9 KiB
literal.w64.rad
1.7 KiB
loc.addr.offset.bug.rad
410 B
loc.addr.opt.to.opt.rad
433 B
loc.addr.optional.assign.rad
408 B
loc.addr.record.assign.rad
443 B
loop.complex.flow.rad
1007 B
loop.sealblock.rad
911 B
match.array.rad
3.4 KiB
match.char.rad
1.6 KiB
match.multi.seal.rad
987 B
match.multi.survive.rad
1.6 KiB
match.mutref.push.rad
1.0 KiB
match.mutref.union.rad
662 B
match.nested.call.rad
1.7 KiB
match.nested.deep.rad
2.2 KiB
match.nested.deref.rad
3.7 KiB
match.nested.guard.rad
1.6 KiB
match.nested.iflet.guard.rad
1.6 KiB
match.nested.iflet.rad
1.4 KiB
match.nested.letelse.rad
813 B
match.nested.letelse.union.rad
1.3 KiB
match.nested.literal.rad
3.1 KiB
match.nested.multi.rad
2.4 KiB
match.nested.pattern.rad
5.2 KiB
match.nested.record.rad
2.0 KiB
match.nested.union.rad
2.3 KiB
match.nested.whilelet.rad
2.4 KiB
match.string.rad
1.8 KiB
match.value.copy.rad
2.0 KiB
match.void.then.or.rad
1.6 KiB
memzero.result.bug.rad
806 B
memzero.union.bug.rad
576 B
mutref.loop.bug.rad
1.8 KiB
opt.assignment.bug.rad
1.3 KiB
opt.bug.test.rad
1.4 KiB
opt.if.let.complex.rad
6.2 KiB
opt.if.let.guard.rad
809 B
opt.if.let.rad
956 B
opt.nil.check.rad
1.5 KiB
opt.record.eq.rad
842 B
opt.record.rad
655 B
opt.return.array.rad
289 B
opt.return.nested.rad
797 B
opt.return.record.rad
344 B
opt.slice.npo.rad
2.8 KiB
opt.type.rad
200 B
opt.while.let.complex.rad
404 B
panic.rad
111 B
placeholder.basic.rad
133 B
placeholder.comprehensive.rad
562 B
pointer.copy.edge.case.rad
1.3 KiB
pointer.slice.index.rad
269 B
pointer.slice.store.rad
881 B
prog.ackermann.rad
5.0 KiB
prog.bignum.rad
9.4 KiB
prog.binsearch.rad
2.4 KiB
prog.bubblesort.rad
2.0 KiB
prog.cordic.rad
6.9 KiB
prog.crc32.rad
2.7 KiB
prog.dijkstra.rad
7.7 KiB
prog.eval.rad
6.2 KiB
prog.hanoi.rad
3.8 KiB
prog.huffman.rad
9.3 KiB
prog.hybridsort.rad
3.0 KiB
prog.linkedlist.rad
5.8 KiB
prog.lzw.rad
6.7 KiB
prog.matmul.rad
2.9 KiB
prog.mersenne.rad
5.2 KiB
prog.nqueens.rad
3.4 KiB
prog.rbtree.rad
8.2 KiB
prog.regex.rad
10.2 KiB
prog.sha256.rad
7.0 KiB
prog.sieve.rad
2.8 KiB
prog.symtab.rad
10.1 KiB
prog.tokenizer.rad
13.8 KiB
prog.vm.rad
17.4 KiB
ptr.assign.rad
137 B
ptr.deref.rad
622 B
ptr.eq.rad
966 B
ptr.mutate.rad
244 B
ptr.opaque.rad
1.4 KiB
record.access.rad
285 B
record.alignment.rad
179 B
record.array.elements.rad
1.7 KiB
record.copy.rad
2.0 KiB
record.field.assign.rad
184 B
record.nested.calls.2.rad
612 B
record.nested.calls.3.rad
734 B
record.param.lit.rad
353 B
record.ptr.access.rad
227 B
record.ptr.mutate.rad
243 B
record.shorthand.rad
1.5 KiB
record.unlabeled.rad
407 B
ref.if.bug.rad
519 B
ref.immut.loop.bug.rad
670 B
ref.mut.ptr.rad
261 B
regalloc.callee.save.rad
1.5 KiB
regalloc.spill.reuse.rad
473 B
reserve.loop.rad
392 B
result.void.success.rad
716 B
slice.alloc.loop.rad
788 B
slice.append.rad
3.3 KiB
slice.cap.rad
941 B
slice.delete.rad
971 B
slice.of.rad
460 B
slice.subslice.rad
1.4 KiB
spill.blockarg.clobber.rad
3.5 KiB
spill.loop.rad
1.6 KiB
stack.local.corrupt.rad
320 B
static.array.mutate.rad
387 B
static.basic.rad
327 B
static.fn.array.rad
628 B
static.record.array.rad
503 B
static.slice.index.assign.rad
408 B
static.slice.offset.rad
668 B
string.basic.rad
149 B
string.escape.rad
349 B
string.index.rad
116 B
switch.blockargs.clobber.rad
1.3 KiB
trait.aggregate.ret.rad
1.5 KiB
trait.array.optional.rad
1.7 KiB
trait.basic.rad
565 B
trait.control.flow.rad
1.1 KiB
trait.fn.param.rad
1.6 KiB
trait.multiple.methods.rad
1.2 KiB
trait.multiple.traits.rad
1.2 KiB
trait.multiple.types.rad
1.3 KiB
trait.supertrait.rad
2.5 KiB
trait.throws.rad
1.0 KiB
trait.writer.rad
2.6 KiB
type.unify.rad
4.5 KiB
undefined.rad
417 B
union-tag.rad
911 B
union.bitfield.rad
1.2 KiB
union.discriminant.cast.rad
389 B
union.edge.case.2.rad
679 B
union.edge.case.3.rad
608 B
union.mixed.assign.rad
977 B
union.payload.mutref.rad
1.4 KiB
union.payload.rad
580 B
union.record.forward.rad
1.3 KiB
union.void.match.rad
403 B
union.void.rad
824 B
unsigned.compare.rad
1.9 KiB
var.align.rad
1013 B
var.infer.rad
549 B
decode.rad
14.6 KiB
emit.rad
24.4 KiB
encode.rad
19.9 KiB
isel.rad
41.1 KiB
printer.rad
13.0 KiB
tests.rad
15.7 KiB
rv64.rad
13.0 KiB
collections/
lang/
sys/
arch.rad
65 B
collections.rad
36 B
fmt.rad
3.8 KiB
intrinsics.rad
206 B
io.rad
1.2 KiB
lang.rad
222 B
mem.rad
2.2 KiB
sys.rad
167 B
testing.rad
2.4 KiB
tests.rad
11.6 KiB
vec.rad
3.1 KiB
std.rad
231 B
scripts/
seed/
test/
vim/
.gitignore
353 B
.gitsigners
112 B
LICENSE
1.1 KiB
Makefile
3.1 KiB
README
2.5 KiB
std.lib
987 B
std.lib.test
252 B
lib/std/arch/rv64/tests/assign.mutable.rad
raw
| 1 | //! returns: 0 |
| 2 | //! Test suite for stack memory allocation and aliasing behavior. |
| 3 | //! Tests variable aliasing, mutations, and stack frame management. |
| 4 | |
| 5 | record Person { |
| 6 | age: i32, |
| 7 | score: i32, |
| 8 | } |
| 9 | |
| 10 | record Container { |
| 11 | values: [i32; 3], |
| 12 | count: i32, |
| 13 | } |
| 14 | |
| 15 | /// Basic variable aliasing and mutation. |
| 16 | fn testBasicAliasing() -> i32 { |
| 17 | let mut x: i32 = 10; |
| 18 | let mut y: i32 = x; // y aliases x's value |
| 19 | |
| 20 | x = 20; // Modify x |
| 21 | y += 5; // Modify y independently |
| 22 | |
| 23 | return x + y; // Should be 20 + 15 = 35 |
| 24 | } |
| 25 | |
| 26 | /// Struct aliasing and field mutation. |
| 27 | fn testStructAliasing() -> i32 { |
| 28 | let mut p1: Person = Person { age: 25, score: 100 }; |
| 29 | let mut p2: Person = p1; // Copy record |
| 30 | |
| 31 | p1.age = 30; // Modify original |
| 32 | p2.score = 0; // Modify copy |
| 33 | |
| 34 | return p1.age + p1.score + p2.age + p2.score; // 30+100+25+0 = 155 |
| 35 | } |
| 36 | |
| 37 | /// Array aliasing and element mutation. |
| 38 | fn testArrayAliasing() -> i32 { |
| 39 | let mut arr1: [i32; 3] = [1, 2, 3]; |
| 40 | let mut arr2: [i32; 3] = arr1; // Copy array |
| 41 | arr1[0] = 10; // Modify original |
| 42 | arr2[1] = 20; // Modify copy |
| 43 | // Arrays should be independent |
| 44 | return arr1[0] + arr1[1] + arr2[0] + arr2[1]; // 10+2+1+20 = 33 |
| 45 | } |
| 46 | |
| 47 | /// Test 4: Nested record with array mutation. |
| 48 | fn testNestedStructArrayMutation() -> i32 { |
| 49 | let mut container1: Container = Container { |
| 50 | values: [1, 2, 3], |
| 51 | count: 3 |
| 52 | }; |
| 53 | let mut container2: Container = container1; // Copy entire record |
| 54 | |
| 55 | container1.values[0] = 50; // Modify nested array in original |
| 56 | container1.count = 5; // Modify field in original |
| 57 | |
| 58 | container2.values[2] = 60; // Modify nested array in copy |
| 59 | container2.count = 7; // Modify field in copy |
| 60 | |
| 61 | return container1.values[0] + container1.count + |
| 62 | container2.values[2] + container2.count; // 50+5+60+7 = 122 |
| 63 | } |
| 64 | |
| 65 | /// Variable overwriting with different types/scopes. |
| 66 | fn testVariableOverwriting() -> i32 { |
| 67 | let mut result: i32 = 0; |
| 68 | let mut temp: i32 = 10; |
| 69 | result = temp; // First assignment |
| 70 | |
| 71 | temp = 20; // Overwrite temp |
| 72 | result += temp; // result = 10 + 20 = 30 |
| 73 | |
| 74 | // Create new scope with same variable name |
| 75 | if true { |
| 76 | let mut temp: i32 = 50; // Shadow outer temp |
| 77 | result += temp; // result = 30 + 50 = 80 |
| 78 | temp = 60; // Modify inner temp |
| 79 | result += temp; // result = 80 + 60 = 140 |
| 80 | } |
| 81 | result += temp; // Should use outer temp (20) |
| 82 | |
| 83 | return result; // 140 + 20 = 160 |
| 84 | } |
| 85 | |
| 86 | /// Array of structs with aliasing. |
| 87 | fn testArrayOfStructsAliasing() -> i32 { |
| 88 | let mut people: [Person; 2] = [ |
| 89 | Person { age: 10, score: 20 }, |
| 90 | Person { age: 15, score: 25 } |
| 91 | ]; |
| 92 | let mut backup: [Person; 2] = people; // Copy array of structs |
| 93 | |
| 94 | people[0].age = 12; // Modify original |
| 95 | people[1].score = 30; // Modify original |
| 96 | |
| 97 | backup[0].score = 22; // Modify copy |
| 98 | backup[1].age = 18; // Modify copy |
| 99 | |
| 100 | return people[0].age + people[0].score + people[1].age + people[1].score + |
| 101 | backup[0].age + backup[0].score + backup[1].age + backup[1].score; |
| 102 | } |
| 103 | |
| 104 | /// Complex mutation chain. |
| 105 | fn testMutationChain() -> i32 { |
| 106 | let mut a: i32 = 1; |
| 107 | let mut b: i32 = 2; |
| 108 | let mut c: i32 = 3; |
| 109 | |
| 110 | a = b; // a = 2 |
| 111 | b = c; // b = 3 |
| 112 | c = a + b; // c = 2 + 3 = 5 |
| 113 | a = c - b; // a = 5 - 3 = 2 |
| 114 | b = a * c; // b = 2 * 5 = 10 |
| 115 | |
| 116 | return a + b + c; // 2 + 10 + 5 = 17 |
| 117 | } |
| 118 | |
| 119 | /// Struct field reassignment with aliasing. |
| 120 | fn testStructFieldReassignment() -> i32 { |
| 121 | let mut original: Person = Person { age: 30, score: 40 }; |
| 122 | let mut copied: Person = original; |
| 123 | |
| 124 | // Swap fields in original |
| 125 | let mut temp: i32 = original.age; |
| 126 | original.age = original.score; |
| 127 | original.score = temp; |
| 128 | |
| 129 | // Different swap in copy |
| 130 | temp = copied.score; |
| 131 | copied.score = copied.age; |
| 132 | copied.age = temp; |
| 133 | |
| 134 | return original.age + original.score + copied.age + copied.score; |
| 135 | // 40+30 + 40+30 = 140 |
| 136 | } |
| 137 | |
| 138 | /// Array index mutation with aliasing. |
| 139 | fn testArrayIndexMutation() -> i32 { |
| 140 | let mut indices: [u32; 3] = [0, 1, 2]; |
| 141 | let mut values: [i32; 3] = [10, 20, 30]; |
| 142 | let mut backup: [i32; 3] = values; |
| 143 | |
| 144 | // Use indices to modify values |
| 145 | values[indices[0]] = 25; // values[0] = 25 |
| 146 | values[indices[1]] = 35; // values[1] = 35 |
| 147 | |
| 148 | // Modify indices |
| 149 | indices[0] = 2; |
| 150 | indices[2] = 0; |
| 151 | |
| 152 | // Use new indices on backup |
| 153 | backup[indices[0]] = 40; // backup[2] = 40 |
| 154 | backup[indices[2]] = 45; // backup[0] = 45 |
| 155 | |
| 156 | return values[0] + values[1] + values[2] + |
| 157 | backup[0] + backup[1] + backup[2]; |
| 158 | // 25+35+30 + 45+20+40 = 195 |
| 159 | } |
| 160 | |
| 161 | /// Multiple assignment levels. |
| 162 | fn testMultipleAssignmentLevels() -> i32 { |
| 163 | let mut level1: Person = Person { age: 10, score: 20 }; |
| 164 | let mut level2: Person = level1; |
| 165 | let mut level3: Person = level2; |
| 166 | let mut level4: Person = level3; |
| 167 | |
| 168 | // Modify each level |
| 169 | level1.age = 11; |
| 170 | level2.age = 12; |
| 171 | level3.age = 13; |
| 172 | level4.age = 14; |
| 173 | |
| 174 | level1.score = 21; |
| 175 | level2.score = 22; |
| 176 | level3.score = 23; |
| 177 | level4.score = 24; |
| 178 | |
| 179 | return (level1.age + level1.score) + |
| 180 | (level2.age + level2.score) + |
| 181 | (level3.age + level3.score) + |
| 182 | (level4.age + level4.score); |
| 183 | // (11+21) + (12+22) + (13+23) + (14+24) = 32+34+36+38 = 140 |
| 184 | } |
| 185 | |
| 186 | @default fn main() -> i32 { |
| 187 | if (testBasicAliasing() != 35) { |
| 188 | return 1; // Failure |
| 189 | } |
| 190 | if (testStructAliasing() != 155) { |
| 191 | return 1; // Failure |
| 192 | } |
| 193 | if (testArrayAliasing() != 33) { |
| 194 | return 1; // Failure |
| 195 | } |
| 196 | if (testNestedStructArrayMutation() != 122) { |
| 197 | return 1; // Failure |
| 198 | } |
| 199 | if (testVariableOverwriting() != 160) { |
| 200 | return 1; // Failure |
| 201 | } |
| 202 | if (testArrayOfStructsAliasing() != 152) { |
| 203 | return 1; // Failure |
| 204 | } |
| 205 | if (testMutationChain() != 17) { |
| 206 | return 1; // Failure |
| 207 | } |
| 208 | if (testStructFieldReassignment() != 140) { |
| 209 | return 1; // Failure |
| 210 | } |
| 211 | if (testArrayIndexMutation() != 195) { |
| 212 | return 1; // Failure |
| 213 | } |
| 214 | if (testMultipleAssignmentLevels() != 140) { |
| 215 | return 1; // Failure |
| 216 | } |
| 217 | return 0; // Success |
| 218 | } |