compiler/
lib/
examples/
std/
arch/
collections/
lang/
alloc/
ast/
gen/
il/
module/
parser/
resolver/
scanner/
alloc.rad
4.2 KiB
ast.rad
22.4 KiB
gen.rad
489 B
il.rad
15.1 KiB
lower.rad
259.5 KiB
module.rad
13.4 KiB
package.rad
1.2 KiB
parser.rad
78.5 KiB
resolver.rad
244.3 KiB
scanner.rad
18.1 KiB
sexpr.rad
6.3 KiB
strings.rad
2.2 KiB
sys/
arch.rad
65 B
collections.rad
36 B
fmt.rad
3.8 KiB
intrinsics.rad
399 B
io.rad
1.2 KiB
lang.rad
222 B
mem.rad
2.1 KiB
sys.rad
167 B
testing.rad
2.3 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.0 KiB
README
2.5 KiB
std.lib
1.0 KiB
std.lib.test
252 B
lib/std/lang/package.rad
raw
| 1 | //! A *package* is a compilation unit tracked by the Radiance compiler. |
| 2 | |
| 3 | use std::mem; |
| 4 | use std::lang::ast; |
| 5 | use std::lang::module; |
| 6 | use std::lang::strings; |
| 7 | |
| 8 | /// Maximum number of packages processed in a single invocation. |
| 9 | pub const MAX_PACKAGES: u32 = 4; |
| 10 | |
| 11 | /// A compilation unit. |
| 12 | pub record Package { |
| 13 | /// Package identifier (index in the package array). |
| 14 | id: u16, |
| 15 | /// Package name. |
| 16 | name: *[u8], |
| 17 | /// Root module identifier for this package, or `nil` if not yet registered. |
| 18 | // TODO: This shouldn't be optional. |
| 19 | rootModuleId: ?u16, |
| 20 | } |
| 21 | |
| 22 | /// Initialize `pkg` with the provided name and ID. |
| 23 | pub fn init( |
| 24 | pkg: *mut Package, |
| 25 | id: u16, |
| 26 | name: *[u8], |
| 27 | pool: *mut strings::Pool |
| 28 | ) -> *mut Package { |
| 29 | pkg.id = id; |
| 30 | pkg.name = strings::intern(pool, name); |
| 31 | pkg.rootModuleId = nil; |
| 32 | |
| 33 | return pkg; |
| 34 | } |
| 35 | |
| 36 | /// Register a module described by the file path. |
| 37 | pub fn registerModule(pkg: *mut Package, graph: *mut module::ModuleGraph, filePath: *[u8]) -> u16 |
| 38 | throws (module::ModuleError) |
| 39 | { |
| 40 | let modId = try module::registerFromPath(graph, pkg.id, pkg.rootModuleId, filePath); |
| 41 | // First registered module becomes the root. |
| 42 | if pkg.rootModuleId == nil { |
| 43 | pkg.rootModuleId = modId; |
| 44 | } |
| 45 | return modId; |
| 46 | } |