Use expressions in constants, for clarity

d91f35a2363d068d0dd70bf55e7e2b3a7d7154c0892dd3275e3c98867e84ba56
Alexis Sellier committed ago 1 parent 32bb87b2
lib/std/arch/rv64/emit.rad +2 -3
11 11
12 12
use super::encode;
13 13
14 14
/// Maximum number of instructions in code buffer.
15 15
const MAX_INSTRS: u32 = 2097152;
16 -
/// Maximum code length before byte offset overflows 32-bits.
17 -
/// Computed as `0x7FFFFFFF` / [`super::INSTR_SIZE`].
18 -
const MAX_CODE_LEN: u32 = 0x3FFFFFFE;
16 +
/// Maximum code length before byte offset overflows signed 32-bits.
17 +
const MAX_CODE_LEN: u32 = 0x7FFFFFFF / super::INSTR_SIZE as u32;
19 18
/// Maximum number of pending branches awaiting patching.
20 19
const MAX_PENDING: u32 = 65536;
21 20
/// Maximum number of function entries.
22 21
const MAX_FUNCS: u32 = 4096;
23 22
/// Maximum number of debug entries.
lib/std/arch/rv64/isel.rad +6 -6
38 38
39 39
///////////////
40 40
// Constants //
41 41
///////////////
42 42
43 -
/// Shift amount for byte sign/zero extension (64 - 8).
44 -
const SHIFT_W8: i32 = 56;
45 -
/// Shift amount for halfword sign/zero extension (64 - 16).
46 -
const SHIFT_W16: i32 = 48;
47 -
/// Shift amount for word sign/zero extension (64 - 32).
48 -
const SHIFT_W32: i32 = 32;
43 +
/// Shift amount for byte sign/zero extension.
44 +
const SHIFT_W8: i32 = 64 - 8;
45 +
/// Shift amount for halfword sign/zero extension.
46 +
const SHIFT_W16: i32 = 64 - 16;
47 +
/// Shift amount for word sign/zero extension.
48 +
const SHIFT_W32: i32 = 64 - 32;
49 49
/// Mask for extracting byte value.
50 50
const MASK_W8: i32 = 0xFF;
51 51
/// Maximum number of block arguments supported.
52 52
const MAX_BLOCK_ARGS: u32 = 16;
53 53
lib/std/fmt.rad +1 -1
2 2
use super::mem;
3 3
4 4
/// Maximum string length for a formatted u32 (eg. "4294967295").
5 5
pub const U32_STR_LEN: u32 = 10;
6 6
/// Maximum string length for a formatted i32 (eg. "-2147483648").
7 -
pub const I32_STR_LEN: u32 = 11;
7 +
pub const I32_STR_LEN: u32 = U32_STR_LEN + 1;
8 8
/// Maximum string length for a formatted u64 (eg. "18446744073709551615").
9 9
pub const U64_STR_LEN: u32 = 20;
10 10
/// Maximum string length for a formatted i64 (eg. "-9223372036854775808").
11 11
pub const I64_STR_LEN: u32 = 20;
12 12
/// Maximum string length for a formatted bool (eg. "false").
lib/std/lang/gen/data.rad +1 -1
11 11
/// Maximum number of data symbols.
12 12
pub const MAX_DATA_SYMS: u32 = 8192;
13 13
14 14
/// Size of the data symbol hash table. Must be a power of two
15 15
/// and at least twice the size of [`MAX_DATA_SYMS`].
16 -
pub const DATA_SYM_TABLE_SIZE: u32 = 16384;
16 +
pub const DATA_SYM_TABLE_SIZE: u32 = MAX_DATA_SYMS * 2;
17 17
18 18
/// Data symbol entry mapping name to address.
19 19
pub record DataSym {
20 20
    /// Symbol name.
21 21
    name: *[u8],
lib/std/lang/gen/labels.rad +1 -1
7 7
/// Maximum number of blocks per function.
8 8
pub const MAX_BLOCKS_PER_FN: u32 = 4096;
9 9
/// Maximum number of functions.
10 10
pub const MAX_FUNCS: u32 = 8192;
11 11
/// Size of the function hash table. Must be a power of two.
12 -
pub const FUNC_TABLE_SIZE: u32 = 16384;
12 +
pub const FUNC_TABLE_SIZE: u32 = MAX_FUNCS * 2;
13 13
14 14
/// Label tracking for code emission.
15 15
pub record Labels {
16 16
    /// Block offsets indexed by block index.
17 17
    /// Per-function, reset each function.
lib/std/lang/lower.rad +5 -5
211 211
// `{ ptr: u32, len: u32 }`.
212 212
213 213
/// Slice data pointer offset.
214 214
const SLICE_PTR_OFFSET: i32 = 0;
215 215
/// Offset of slice length in slice data structure.
216 -
const SLICE_LEN_OFFSET: i32 = 8;
216 +
const SLICE_LEN_OFFSET: i32 = resolver::PTR_SIZE as i32;
217 217
/// Offset of slice capacity in slice data structure.
218 -
const SLICE_CAP_OFFSET: i32 = 12;
218 +
const SLICE_CAP_OFFSET: i32 = resolver::PTR_SIZE as i32 + 4;
219 219
220 220
// Trait Object Layout
221 221
//
222 222
// A trait object is a fat pointer consisting of a data pointer and a
223 223
// v-table pointer. `{ data: *T, vtable: *VTable }`.
224 224
225 225
/// Trait object data pointer offset.
226 226
const TRAIT_OBJ_DATA_OFFSET: i32 = 0;
227 227
/// Trait object v-table pointer offset.
228 -
const TRAIT_OBJ_VTABLE_OFFSET: i32 = 8;
228 +
const TRAIT_OBJ_VTABLE_OFFSET: i32 = resolver::PTR_SIZE as i32;
229 229
230 230
// Tagged Value Layout (optionals, tagged unions)
231 231
//
232 232
// Optionals and unions use 1-byte tags. Results use 8-byte tags.
233 233
//
239 239
// Tagged unions have a payload the size of the maximum variant size.
240 240
241 241
/// Offset of tag in tagged value data structure.
242 242
const TVAL_TAG_OFFSET: i32 = 0;
243 243
/// Offset of value in result data structure (8-byte tag).
244 -
const RESULT_VAL_OFFSET: i32 = 8;
244 +
const RESULT_VAL_OFFSET: i32 = resolver::PTR_SIZE as i32;
245 245
246 246
//////////////////////////
247 247
// Core Data Structures //
248 248
//////////////////////////
249 249
4044 4044
) -> il::Val throws (LowerError) {
4045 4045
    let successType = *self.fnType.returnType;
4046 4046
    let layout = resolver::getResultLayout(
4047 4047
        successType, self.fnType.throwList
4048 4048
    );
4049 -
    return try buildTagged(self, layout, tag, payload, payloadType, 8, RESULT_VAL_OFFSET);
4049 +
    return try buildTagged(self, layout, tag, payload, payloadType, resolver::PTR_SIZE as i32, RESULT_VAL_OFFSET);
4050 4050
}
4051 4051
4052 4052
/// Build a slice aggregate from a data pointer, length and capacity.
4053 4053
fn buildSliceValue(
4054 4054
    self: *mut FnLowerer,