Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
HeronErin committed May 7, 2024
2 parents 0d4a6c8 + a16b39b commit c1d0b35
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
9 changes: 6 additions & 3 deletions spec/grammar.md
Original file line number Diff line number Diff line change
Expand Up @@ -154,17 +154,20 @@ All types may, but not must, contain member declarations, and the above are only

`(types..)`

Tagged have a tag which indicates what kind of value they hold, but they will only ever hold one of their fields as a value. Tagged may be checked for their `tag` by doing `foo is name` or `foo is type` like in `foo is V4`.
Tagged have a `tag` which indicates what kind of value they hold, but they will only ever hold one of their fields as a value. Tagged may be checked for their `tag` by doing `foo is name` or `foo is type` like in `foo is V4`.

Unlike all other types, tagged may inherit a builtin type as a prime inherit, which will act as the default type for all fields which do not have a type declared.

Tagged may be implicitly created by wrapping multiple types in parenthesis, like `(int, short) foo` and assignment when value is one of `int` and `short`.
Additionally, tagged may implicitly create from a type by accessing a member, like from `IpAddr.V4` in which the default value of `V4` is selected.

If all members of a tagged are `const`, they may have a value assigned by default, `tag` is stripped away (but may still be accessed) and it acts exactly as an `enum` would in languages like D, Java, or C#. Otherwise default assignment is not allowed.

```
tagged A : ^ubyte
{
a = 3;
// This will result in the runtime having to do a lookup if converting 3 to A, because A is not entirely const.
const a = 3;
int b;
}
Expand Down Expand Up @@ -404,7 +407,7 @@ Functions have their attributes ***after*** their signature, having attributes p
| `unsafe` | Ignores all safety checks usually applied to functions. | Function |
| `@tapped` | Ignores all attributes that may be inferred or applied to the parent scope(s). | Function |
| `inline` | Guarantees that a function is inlined by the compiler or an error is thrown. | Function |
| `const` | Immutable, including by any direct references, does not indicate read-only memory. | Variables |
| `const` | Immutable, including by any direct references, does not indicate read-only memory. | Variables, Types |
| `auto` | Infers type at comptime, similar to type aliasing but implicit. | Variables |
| `ref` | Carries a reference to data. | Parameters, Return Values |
| `mustuse` | Must be used or cast to `void` or an error is thrown. | Return Values |
Expand Down
8 changes: 6 additions & 2 deletions spec/lexical.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,11 @@ Scopes in Fern are started and ended using curly brackets.
| `continue` | [Statement](grammar.md#statements)
| `mixin` | [Mixin](grammar.md#mixins)
| `is` | [Conditional](grammar.md#types)
| `debug` | [Versioning](model.md#versoning) |
| `export` | Reserved |
| `extern` | Reserved |
| `assert` | Reserved |
| `debug` | [Versioning](model.md#versoning) |
| `__asm` | Reserved |

## Special Symbols

Expand Down Expand Up @@ -155,4 +156,7 @@ The prefix `__` is resserved for implementation and thus should be blacklisted f
| `.sizeof` | The size in bytes of the symbol being targeted, this is a member. |
| `.alignof` | The alignment in bytes of the symbol being targeted, this is a member. |
| `.offsetof` | The offset in bytes of the symbol being targeted, this is a member. |
| `.typeof` | The type of the symbol being targeted, this is a member. |
| `.typeof` | The type of the symbol being targeted, this is a member. |
| `.tag` | The tag of a tagged, this is a member. |
| `.ptr` | The pointer of an object, this is a member. |
| `.length` | The length of an array, this is a member. |
2 changes: 1 addition & 1 deletion std/hresult.fn
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/// Windows `HResult` enum implementation and helper functions.
module std.hresult;

public tagged HResult
public const tagged HResult : ^int
{
S_OK = 0x00000000;
S_FALSE = 0x00000001;
Expand Down

0 comments on commit c1d0b35

Please sign in to comment.