Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions docs/language.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,13 @@ To type a variable as a signed integer N bits wide, use `iN`:

For an unsigned integer, use a `u` prefix instead of `i`.

Type aliases can be used with annotations to create integer types with specific byte orders:

```
type be16 = u16 @byte_order(BigEndian);
type le16 = u16 @byte_order(LittleEndian);
```

### Floats

Use the type `float` for floating-point numbers.
Expand Down Expand Up @@ -170,6 +177,33 @@ Single-element structs do not require a trailing comma:
let Thing thing = { 1234 };
```

#### Structure Layout

To pack a structure in Haven, use the `@layout` annotation:

```
type Point = struct @layout(packed) {
i32 x;
i32 y; /* starts at 4th byte of structure - packed layout omits any inter-field padding */
};
```

To control the layout of a structure in Haven, use the `@offset` annotation:

```
type Point = struct {
i32 x @offset(8); /* starts at 8th byte of the structure */
i32 y @offset(4); /* starts at 4th byte of the structure */
i32 z; /* fills the available hole at byte 0 of the structure */
i32 w; /* starts at next available slot in the structure, at 12th byte */
};
```

Fields that do not have offsets specified will fill available holes in the structure on either side of `@offset`-positioned fields.

Offsets are not permitted to overlap and compile-time analysis will error if an impossible layout is requested.
Note that adding offsets implies a packed structure layout, even without the annotation.

### Enums

You may define an enum type using two forms.
Expand Down
6 changes: 1 addition & 5 deletions src/bin/lsp/semantic_tokens.ml
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ let symbol_is_operator = function
| LtEq | GtEq | LShift | RShift | Lt | Gt | Star | Caret | Plus | Minus
| Slash | Percent | Equal | Ampersand | Pipe | Bang | Tilde | LParen | RParen
| LBrace | RBrace | LBracket | RBracket | Comma | Dot | Semicolon | Colon
| Underscore ->
| Underscore | At ->
true

let collect_lexical_tokens (parsed : CST.parsed_program) =
Expand All @@ -219,10 +219,6 @@ let collect_lexical_tokens (parsed : CST.parsed_program) =
(loc_of_raw_tok
{ tok = entry.token; startp = entry.startp; endp = entry.endp })
| Lexer.Raw.Ident _ -> acc
| Lexer.Raw.Directive Assert ->
add_token_for_loc acc ~token_type:"keyword"
(loc_of_raw_tok
{ tok = entry.token; startp = entry.startp; endp = entry.endp })
| Lexer.Raw.Numeric_type _ | Vec_type _ | Mat_type _ | Vec_hole_type
| Mat_hole_type | Float_type | Void_type | Str_type ->
add_token_for_loc acc ~token_type:"type"
Expand Down
Loading
Loading