compiler/
lib/
examples/
std/
arch/
char/
collections/
lang/
alloc/
ast/
gen/
il/
module/
parser/
resolver/
scanner/
alloc.rad
7.1 KiB
ast.rad
26.7 KiB
gen.rad
513 B
il.rad
20.3 KiB
lower.rad
315.6 KiB
module.rad
14.9 KiB
package.rad
1.3 KiB
parser.rad
91.2 KiB
resolver.rad
452.9 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
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
281 B
scripts/
seed/
sublime/
test/
vim/
.gitignore
336 B
.gitsigners
112 B
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
662 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 | export constant MAX_PACKAGES: u32 = 4; |
| 10 | |
| 11 | /// A compilation unit. |
| 12 | export record Package: Copy { |
| 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 | export fn init( |
| 24 | pkg: &mut Package, |
| 25 | id: u16, |
| 26 | name: *[u8], |
| 27 | pool: &mut strings::Pool |
| 28 | ) { |
| 29 | set pkg.id = id; |
| 30 | set pkg.name = strings::intern(pool, name); |
| 31 | set pkg.rootModuleId = nil; |
| 32 | |
| 33 | } |
| 34 | |
| 35 | /// Register a module described by the file path. |
| 36 | export unsafe fn registerModule(pkg: &mut Package, graph: &mut module::ModuleGraph, pool: &mut strings::Pool, filePath: *[u8]) -> u16 |
| 37 | throws (module::ModuleError) |
| 38 | { |
| 39 | let modId = try module::registerFromPath(graph, pool, pkg.id, pkg.rootModuleId, filePath); |
| 40 | // First registered module becomes the root. |
| 41 | if pkg.rootModuleId == nil { |
| 42 | set pkg.rootModuleId = modId; |
| 43 | } |
| 44 | return modId; |
| 45 | } |