compiler/
lib/
examples/
std/
arch/
char/
collections/
graph/
lang/
alloc/
ast/
gen/
il/
module/
parser/
resolver/
scanner/
alloc.rad
7.1 KiB
ast.rad
26.9 KiB
gen.rad
513 B
il.rad
20.4 KiB
lower.rad
321.7 KiB
module.rad
17.3 KiB
package.rad
1.3 KiB
parser.rad
92.2 KiB
resolver.rad
511.1 KiB
scanner.rad
17.9 KiB
sexpr.rad
6.7 KiB
strings.rad
2.2 KiB
types.rad
1.6 KiB
sys/
arch.rad
68 B
char.rad
855 B
collections.rad
39 B
fmt.rad
8.3 KiB
graph.rad
4.3 KiB
intrinsics.rad
467 B
io.rad
1.7 KiB
lang.rad
276 B
mem.rad
2.3 KiB
sys.rad
179 B
testing.rad
2.4 KiB
tests.rad
15.7 KiB
vec.rad
3.2 KiB
std.rad
299 B
scripts/
seed/
sublime/
test/
vim/
.gitignore
336 B
.gitsigners
112 B
CELL_PERMISSIONS
6.8 KiB
CONTRIBUTING
2.1 KiB
LICENSE
1.1 KiB
Makefile
5.4 KiB
README
2.5 KiB
STYLE
2.5 KiB
std.lib
1.5 KiB
std.lib.test
808 B
lib/std/lang/types.rad
raw
| 1 | //! Shared Radiance language types. |
| 2 | |
| 3 | /// Ownership and safety class for pointer-like types. |
| 4 | export union PointerClass: Copy { |
| 5 | /// Owned pointer, eg. `*T`. |
| 6 | Owned, |
| 7 | /// Reference, borrowed pointer, eg. `&T`. |
| 8 | Ref, |
| 9 | /// Reference retained by one resolved lexical region. |
| 10 | Region(*unsafe Region), |
| 11 | /// Unsafe, raw pointer, eg. `*unsafe T`. |
| 12 | Unsafe, |
| 13 | } |
| 14 | |
| 15 | /// Source construct that introduces a region identity. |
| 16 | export union RegionOrigin: Copy { |
| 17 | /// Caller-supplied declaration parameter. |
| 18 | Parameter, |
| 19 | /// Concrete region delimited by a lexical block. |
| 20 | Block, |
| 21 | } |
| 22 | |
| 23 | /// Semantic identity and ancestry of a source region. |
| 24 | export record Region: Copy { |
| 25 | /// Globally unique AST node ID of the region declaration. |
| 26 | id: u32, |
| 27 | /// Source construct that supplies the region lifetime. |
| 28 | origin: RegionOrigin, |
| 29 | /// Source spelling used in diagnostics. |
| 30 | name: *[u8], |
| 31 | /// Proven enclosing region, if one is declared. |
| 32 | parent: ?*unsafe Region, |
| 33 | } |
| 34 | |
| 35 | /// Return whether a pointer class denotes checked borrowed storage. |
| 36 | export fn isReference(class: PointerClass) -> bool { |
| 37 | match class { |
| 38 | case PointerClass::Ref, PointerClass::Region(_) => return true, |
| 39 | else => return false, |
| 40 | } |
| 41 | } |
| 42 | |
| 43 | /// Return whether a region is equal to, or contains, another region. |
| 44 | /// Parent links must form an acyclic graph within one resolver. |
| 45 | export unsafe fn regionContains(parent: *unsafe Region, child: *unsafe Region) -> bool { |
| 46 | let mut current: ?*unsafe Region = child; |
| 47 | while let region = current { |
| 48 | if region.id == parent.id { |
| 49 | return true; |
| 50 | } |
| 51 | set current = region.parent; |
| 52 | } |
| 53 | return false; |
| 54 | } |