Skip to content

Commit bdb6885

Browse files
committed
Add builtin definitions
1 parent 80a5770 commit bdb6885

File tree

1 file changed

+62
-6
lines changed

1 file changed

+62
-6
lines changed

src/rfcs/0002-knums.md

Lines changed: 62 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ Prior to the body, one or more attributes may be specified. Attributes are of th
232232

233233
The following attributes are currently recognized:
234234
* `align(N)`, `N` must an expression of type `ulong`, and must be a power of two. Indicates that the type requires alignment to at least `N` bytes.
235-
* `option(ID)`. Inserts a field at the start of the structure type `ExtendedOptionHead` (The file `types::option` must be `use`d to use this struct attribute), and provides sufficient definitions. Must appear on a `struct`.
235+
* `option(ID)`. Inserts a field at the start of the structure type `ExtendedOptionHead`, and provides sufficient definitions. Must appear on a `struct`. Both `types::option` and `types::uuid` must be `use`d to use this attribute,
236236
* `option_head(N)`: Must appear on a `union`. Inserts a field of an unnamed struct type, containing a field of type `ExtendedOptionHead` (the file `types::option` must be `use`d to use this attribute), and a field of type `[byte; N]`.
237237

238238
#### `type` items
@@ -310,10 +310,6 @@ A UUID literal starts with `U` and is immediately followed by a braced UUID. Das
310310

311311
A `const` item in scope may be named by an expression. The value of the expression is the value of the const. The const value is evaluated before being substituted - in particular, the substituted expression is not reparsed.
312312

313-
Special constant values are always in scope:
314-
* `__LILIUM_SIZEOF_POINTER__` is defined to be the number of bytes in a pointer, a power of 2 that is at least 4
315-
* Constants that begin with `__LILIUM` are reserved for future definitions.
316-
317313
#### Unary Operator Expressions
318314

319315
Unary Operators may prefix an expression with an integer type. `-` is a value-wise negation of the value mod 2^N. `!` is a bitwise negation. `+` is an identity operation.
@@ -340,7 +336,67 @@ Parenthesis may surround an expression. This provides explicit grouping for the
340336

341337
### Standard Types
342338

343-
The following modules are
339+
The following modules are predefined:
340+
* `types::int`
341+
* `types::hdl`
342+
* `types::option`
343+
* `types::uuid`
344+
* `types`
345+
346+
Other than the `types` module, which simply acts as if it contains `inline use` declarations for each of the preceeding, we define the contents of each of the modules below
347+
348+
#### `types::int`
349+
350+
The `types::int` module contains the following definitions. Additionally, any knums module that refers to an integer type must (potentially-indirectly) contain the declaration `use types::int;`.
351+
352+
```
353+
const __LILIUM_SIZEOF_POINTER__: ulong = /*see below*/;
354+
```
355+
356+
`__LILIUM_SIZEOF_POINTER__` is defined to be equal to the number of bytes in a pointer.
357+
358+
#### `types::hdl`
359+
360+
The `types::hdl` module contains the following definitions. Additionally, any knums module that refers to `*handle T` or `*shared_handle T` must (potentially-indirectly) contain the declaration `use types::hdl;`
361+
362+
```
363+
use types::int; // Required for __LILIUM_SIZEOF_POINTER__ below
364+
/// Base type of all handles in Lilium
365+
struct Handle : opaque;
366+
367+
/// Handle Pointer that contains 16 bytes. A non-null pointer is guaranteed not to overlap in bit representation with a `Uuid`
368+
struct WideHandle<H> : align(16) {
369+
hdl: *handle H!Handle,
370+
pad([*const void; (16 - __LILIUM_SIZEOF_POINTER__)/__LILIUM_SIZEOF_POINTER__])
371+
}
372+
```
373+
374+
#### `types::option`
375+
376+
The `types::option` module contains the following definitions. Additionally, any knums module that uses the `option` or `option_head` struct attributes must (potentially-indirectly) contain the declaration `use types::option`.
377+
378+
```
379+
use types::int;
380+
use types::uuid;
381+
382+
struct ExtendedOptionHead {
383+
id: Uuid,
384+
flags: u32,
385+
pad([u32; 3])
386+
}
387+
```
388+
389+
#### `types::uuid`
390+
391+
The `types::uuid` module contains the following definitions. Additionally, any knums module that uses the `option` struct attribute or a UUID literal must (potentially-indirectly) contain the declaration `use types::uuid`.
392+
393+
```
394+
use types::int;
395+
struct Uuid : align(16) {
396+
minor: u64,
397+
major: u64,
398+
}
399+
```
344400

345401
## Security Considerations
346402

0 commit comments

Comments
 (0)