Update 'Variable Definition and Type Notation'
parent
d43f320444
commit
fb90c7eabc
@ -1,13 +1,36 @@
|
||||
In ARF, variables are defined using the syntax `name:Type:qualifier`, where name
|
||||
is a name token and type is either just a name token describing what type it is,
|
||||
or a pointer to a value of that type or an array to a value of that type. The
|
||||
only supported qualifier is `:mut`, which marks the variable's data as mutable.
|
||||
Variables are immutable by default.
|
||||
In ARF, a type can be described using a type specifier. Syntactically, type specifiers are lists of items that are joined together with colons.
|
||||
|
||||
Pointers are defined like `name:{Type}` and arrays are defined like
|
||||
`name:{Type length}` where length is an unsigned integer literal or an ellipsis
|
||||
token (..). If an integer token is given, the length of the array is static, and
|
||||
if an ellipsis is given, the length is dynamic and can be changed at runtime.
|
||||
```
|
||||
# Simple integer
|
||||
Int
|
||||
|
||||
Variables can be defined wherever they are used. For example, `set x:Int 5`
|
||||
defines a variable of type Int and sets it to 5.
|
||||
# Static array of 5 integers
|
||||
Int:5
|
||||
|
||||
# Pointer to a single integer
|
||||
{Int}
|
||||
|
||||
# Dynamic array of integers
|
||||
{Int ..}
|
||||
|
||||
# Static array of 5 integers, with default values
|
||||
Int:5:<398 298 17 40 98>
|
||||
|
||||
# Object that has two integer members: x and y
|
||||
Obj:(
|
||||
.ro x:Int
|
||||
.ro y:Int)
|
||||
|
||||
# Variable length array of objects that have a single integer member called x
|
||||
{Obj:(.x Int) ..}
|
||||
```
|
||||
|
||||
The first item is always the name that the type inherits from. If the first item is wrapped in curly braces, the type specifier describes a pointer to whatever type is inside of it. If, after the type that is inside of it, there is an elipsis token, the type specifier describes an array of dynamic length.
|
||||
|
||||
If an item is a UInt token, it defines a static for the type. The type becomes an array of static length. This number cannot be zero, and if no number is given, the length is assumed to be one (which just means it is a singlular value).
|
||||
|
||||
If an item is a name token with the value `mut`, the data that the type directly holds becomes mutable. This is only understood if the type specifier is being instantiated in-place—it does not have an effect in [type sections](Type-Definitions).
|
||||
|
||||
If an item is delimited by less than and greater than tokens, it is understood as a simple default value for the type. One or more arguments may be listed in this area, depending on what the length of the type is.
|
||||
|
||||
If an item is delimited by parentheses, it may contian definitions for new members, and new default values for inherited members. This construct is only understood when the type specifier inherits from another object type.
|
Reference in New Issue
Block a user