2020-01-12 22:59:16 -05:00
|
|
|
// Global constants across the entirety of TAMER
|
|
|
|
//
|
2021-07-22 15:00:15 -04:00
|
|
|
// Copyright (C) 2014-2021 Ryan Specialty Group, LLC.
|
2020-03-06 11:05:18 -05:00
|
|
|
//
|
|
|
|
// This file is part of TAME.
|
2020-01-12 22:59:16 -05:00
|
|
|
//
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
//! System-wide static configuration.
|
|
|
|
//!
|
|
|
|
//! This module provides a system-wide configuration.
|
|
|
|
//! Subsystems should reference these values rather than defining their own
|
|
|
|
//! and risk incompatibilities or maintenance issues as requirements
|
|
|
|
//! change.
|
|
|
|
//!
|
2021-08-13 14:59:25 -04:00
|
|
|
//! This package contains static assertions to ensure that certain sizes
|
|
|
|
//! will play well with one-another and provide a clear direction if
|
|
|
|
//! something goes wrong
|
|
|
|
//! (beyond a slew of other type errors).
|
|
|
|
//!
|
2020-01-12 22:59:16 -05:00
|
|
|
//! By convention,
|
|
|
|
//! import this entire module rather than individual members and reference
|
|
|
|
//! them as `global::foo` to emphasize their nature and risk.
|
|
|
|
|
2021-08-13 14:59:25 -04:00
|
|
|
use std::{mem::size_of, num};
|
2020-01-12 22:59:16 -05:00
|
|
|
|
|
|
|
/// A size capable of representing every interned string in a package.
|
|
|
|
pub type PkgSymSize = u16;
|
2021-08-13 14:59:25 -04:00
|
|
|
const_assert!(size_of::<PkgSymSize>() <= size_of::<ProgSymSize>());
|
2020-01-12 22:59:16 -05:00
|
|
|
|
|
|
|
/// A non-zero equivalent of [`PkgSymSize`];
|
|
|
|
pub type NonZeroPkgSymSize = num::NonZeroU16;
|
|
|
|
|
|
|
|
/// A size capable of representing every interned string in a program.
|
|
|
|
pub type ProgSymSize = u32;
|
|
|
|
|
2021-09-22 16:04:56 -04:00
|
|
|
/// The initial capacity for global interners.
|
|
|
|
pub const INIT_GLOBAL_INTERNER_CAPACITY: usize = 1024;
|
|
|
|
|
2020-01-12 22:59:16 -05:00
|
|
|
/// A non-zero equivalent of [`ProgSymSize`];
|
|
|
|
pub type NonZeroProgSymSize = num::NonZeroU32;
|
|
|
|
|
2021-08-13 14:59:25 -04:00
|
|
|
/// Size large enough to accommodate the number of bytes in a source file.
|
|
|
|
pub type SourceFileSize = u32;
|
|
|
|
|
|
|
|
/// Length of tokens derived from source files.
|
|
|
|
///
|
|
|
|
/// This size should be kept small,
|
|
|
|
/// since its principle use is as an alternative to a byte offset
|
|
|
|
/// ([`SourceFileSize`]) for struct packing.
|
|
|
|
/// It should, however, be large enough to handle comment and
|
|
|
|
/// documentation tokens.
|
|
|
|
/// Tokens that are too large can potentially be split into multiple
|
|
|
|
/// tokens.
|
|
|
|
pub type FrontendTokenLength = u16;
|
|
|
|
const_assert!(size_of::<FrontendTokenLength>() <= size_of::<SourceFileSize>());
|
|
|
|
|
2020-01-12 22:59:16 -05:00
|
|
|
/// A size capable of representing indexes of each individual identifier
|
|
|
|
/// within a single package.
|
|
|
|
///
|
|
|
|
/// Note that,
|
|
|
|
/// since TAME is a metalanguage and can easily expand into a great
|
|
|
|
/// deal of code,
|
|
|
|
/// this must accommodate far more than the user's expectations
|
|
|
|
/// working within the provided level of abstraction.
|
|
|
|
///
|
|
|
|
/// This must be ≥ [`PkgSymSize`].
|
|
|
|
pub type PkgIdentSize = u16;
|
2021-08-13 14:59:25 -04:00
|
|
|
const_assert!(size_of::<PkgIdentSize>() >= size_of::<PkgSymSize>());
|
2020-01-12 22:59:16 -05:00
|
|
|
|
|
|
|
/// A size capable of representing every individual identifier and
|
|
|
|
/// expression within a single package.
|
|
|
|
///
|
|
|
|
/// Note that,
|
|
|
|
/// since TAME is a metalanguage and can easily expand into a great
|
|
|
|
/// deal of code,
|
|
|
|
/// this must accommodate far more than the user's expectations
|
|
|
|
/// working within the provided level of abstraction.
|
|
|
|
pub type PkgIdentExprSize = u32;
|
2021-08-13 14:59:25 -04:00
|
|
|
const_assert!(size_of::<PkgIdentExprSize>() <= size_of::<ProgIdentExprSize>());
|
2020-01-12 22:59:16 -05:00
|
|
|
|
|
|
|
/// A size capable of representing the union of every identifier of every
|
|
|
|
/// package used by an entire program.
|
|
|
|
///
|
|
|
|
/// This must be ≥ [`ProgSymSize`].
|
|
|
|
pub type ProgIdentSize = u32;
|
2021-08-13 14:59:25 -04:00
|
|
|
const_assert!(size_of::<ProgIdentSize>() >= size_of::<ProgSymSize>());
|
2020-01-12 22:59:16 -05:00
|
|
|
|
|
|
|
/// A size capable of representing the union of every identifier and every
|
|
|
|
/// expression of every package used by an entire program.
|
|
|
|
///
|
|
|
|
/// Note that,
|
|
|
|
/// since TAME is a metalanguage and can easily expand into a great
|
|
|
|
/// deal of code,
|
|
|
|
/// this must accommodate far more than the user's expectations
|
|
|
|
/// working within the provided level of abstraction.
|
|
|
|
///
|
|
|
|
/// This must be ≥ [`ProgSymSize`].
|
|
|
|
pub type ProgIdentExprSize = u32;
|
2021-08-13 14:59:25 -04:00
|
|
|
const_assert!(size_of::<ProgIdentExprSize>() >= size_of::<ProgSymSize>());
|