2015-12-09 14:20:31 -08:00
|
|
|
# Language Reference
|
|
|
|
|
|
|
|
## Grammar
|
|
|
|
|
|
|
|
```
|
2016-01-28 17:58:28 -08:00
|
|
|
Root = many(TopLevelDecl) "EOF"
|
2015-12-09 14:20:31 -08:00
|
|
|
|
2016-02-27 21:06:46 -08:00
|
|
|
TopLevelDecl = many(Directive) option(VisibleMod) (FnDef | ExternDecl | ContainerDecl | GlobalVarDecl | ErrorValueDecl | TypeDecl | UseDecl)
|
2016-01-20 17:18:50 -08:00
|
|
|
|
2016-01-31 00:20:47 -08:00
|
|
|
TypeDecl = "type" "Symbol" "=" TypeExpr ";"
|
|
|
|
|
2016-01-28 17:58:28 -08:00
|
|
|
ErrorValueDecl = "error" "Symbol" ";"
|
2015-12-11 23:10:37 -08:00
|
|
|
|
2016-01-28 17:58:28 -08:00
|
|
|
GlobalVarDecl = VariableDeclaration ";"
|
2016-01-04 15:57:22 -08:00
|
|
|
|
2016-01-31 00:20:47 -08:00
|
|
|
VariableDeclaration = ("var" | "const") "Symbol" option(":" TypeExpr) "=" Expression
|
2016-01-26 12:08:21 -08:00
|
|
|
|
2016-01-28 17:58:28 -08:00
|
|
|
ContainerDecl = ("struct" | "enum") "Symbol" "{" many(StructMember) "}"
|
2016-01-26 12:08:21 -08:00
|
|
|
|
2016-01-28 17:58:28 -08:00
|
|
|
StructMember = many(Directive) option(VisibleMod) (StructField | FnDef)
|
2015-12-11 23:10:37 -08:00
|
|
|
|
2016-01-28 17:58:28 -08:00
|
|
|
StructField = "Symbol" option(":" Expression) ",")
|
2016-01-10 10:48:54 -08:00
|
|
|
|
2016-02-27 21:06:46 -08:00
|
|
|
UseDecl = "use" Expression ";"
|
2015-12-09 14:20:31 -08:00
|
|
|
|
2016-01-29 15:06:17 -08:00
|
|
|
ExternDecl = "extern" (FnProto | VariableDeclaration) ";"
|
2015-12-09 14:20:31 -08:00
|
|
|
|
2016-04-06 11:38:12 -07:00
|
|
|
FnProto = "fn" option("Symbol") option(ParamDeclList) ParamDeclList option("->" TypeExpr)
|
2015-12-09 14:20:31 -08:00
|
|
|
|
2016-02-15 22:30:05 -08:00
|
|
|
Directive = "#" "Symbol" "(" Expression ")"
|
2015-12-09 14:20:31 -08:00
|
|
|
|
2016-01-28 17:58:28 -08:00
|
|
|
VisibleMod = "pub" | "export"
|
2015-12-09 14:20:31 -08:00
|
|
|
|
2016-02-01 16:25:38 -08:00
|
|
|
FnDef = option("inline") FnProto Block
|
2015-12-09 14:20:31 -08:00
|
|
|
|
2016-01-28 17:58:28 -08:00
|
|
|
ParamDeclList = "(" list(ParamDecl, ",") ")"
|
2015-12-09 14:20:31 -08:00
|
|
|
|
2016-01-31 00:20:47 -08:00
|
|
|
ParamDecl = option("noalias") option("Symbol" ":") TypeExpr | "..."
|
2015-12-09 14:20:31 -08:00
|
|
|
|
2016-01-28 17:58:28 -08:00
|
|
|
Block = "{" list(option(Statement), ";") "}"
|
2015-12-09 14:20:31 -08:00
|
|
|
|
2016-02-05 23:56:01 -08:00
|
|
|
Statement = Label | VariableDeclaration ";" | Defer ";" | NonBlockExpression ";" | BlockExpression
|
2015-12-09 14:20:31 -08:00
|
|
|
|
2016-01-28 17:58:28 -08:00
|
|
|
Label = "Symbol" ":"
|
2015-12-09 14:20:31 -08:00
|
|
|
|
2016-01-28 17:58:28 -08:00
|
|
|
Expression = BlockExpression | NonBlockExpression
|
2015-12-09 14:20:31 -08:00
|
|
|
|
2016-01-31 00:20:47 -08:00
|
|
|
TypeExpr = PrefixOpExpression
|
|
|
|
|
2016-02-05 23:56:01 -08:00
|
|
|
NonBlockExpression = ReturnExpression | AssignmentExpression
|
2015-12-10 14:34:38 -08:00
|
|
|
|
2016-01-28 17:58:28 -08:00
|
|
|
AsmExpression = "asm" option("volatile") "(" "String" option(AsmOutput) ")"
|
2015-12-10 14:34:38 -08:00
|
|
|
|
2016-01-28 17:58:28 -08:00
|
|
|
AsmOutput = ":" list(AsmOutputItem, ",") option(AsmInput)
|
2015-12-10 14:34:38 -08:00
|
|
|
|
2016-01-28 17:58:28 -08:00
|
|
|
AsmInput = ":" list(AsmInputItem, ",") option(AsmClobbers)
|
2015-12-10 14:34:38 -08:00
|
|
|
|
2016-01-31 00:20:47 -08:00
|
|
|
AsmOutputItem = "[" "Symbol" "]" "String" "(" ("Symbol" | "->" TypeExpr) ")"
|
2015-12-11 02:55:26 -08:00
|
|
|
|
2016-01-28 17:58:28 -08:00
|
|
|
AsmInputItem = "[" "Symbol" "]" "String" "(" Expression ")"
|
2015-12-11 02:55:26 -08:00
|
|
|
|
2016-01-28 17:58:28 -08:00
|
|
|
AsmClobbers= ":" list("String", ",")
|
2015-12-09 14:20:31 -08:00
|
|
|
|
2016-01-28 17:58:28 -08:00
|
|
|
UnwrapExpression = BoolOrExpression (UnwrapMaybe | UnwrapError) | BoolOrExpression
|
2016-01-07 02:23:38 -08:00
|
|
|
|
2016-02-06 18:28:11 -08:00
|
|
|
UnwrapMaybe = "??" Expression
|
2016-01-25 12:53:40 -08:00
|
|
|
|
2016-02-06 18:28:11 -08:00
|
|
|
UnwrapError = "%%" option("|" "Symbol" "|") Expression
|
2016-01-25 12:53:40 -08:00
|
|
|
|
2016-01-28 17:58:28 -08:00
|
|
|
AssignmentExpression = UnwrapExpression AssignmentOperator UnwrapExpression | UnwrapExpression
|
2015-12-12 17:17:27 -08:00
|
|
|
|
2016-01-28 17:58:28 -08:00
|
|
|
AssignmentOperator = "=" | "*=" | "/=" | "%=" | "+=" | "-=" | "<<=" | ">>=" | "&=" | "^=" | "|=" | "&&=" | "||="
|
2015-12-09 14:20:31 -08:00
|
|
|
|
2016-01-28 17:58:28 -08:00
|
|
|
BlockExpression = IfExpression | Block | WhileExpression | ForExpression | SwitchExpression
|
2015-12-24 13:37:43 -08:00
|
|
|
|
2016-01-28 17:58:28 -08:00
|
|
|
SwitchExpression = "switch" "(" Expression ")" "{" many(SwitchProng) "}"
|
2015-12-09 14:20:31 -08:00
|
|
|
|
2016-02-04 14:50:06 -08:00
|
|
|
SwitchProng = (list(SwitchItem, ",") | "else") "=>" option("|" "Symbol" "|") Expression ","
|
2016-01-18 06:00:45 -08:00
|
|
|
|
2016-01-28 17:58:28 -08:00
|
|
|
SwitchItem = Expression | (Expression "..." Expression)
|
2015-12-09 14:20:31 -08:00
|
|
|
|
2016-04-19 20:28:44 -07:00
|
|
|
WhileExpression = "while" "(" Expression option(";" Expression) ")" Expression
|
2016-01-19 18:15:36 -08:00
|
|
|
|
2016-04-20 11:58:01 -07:00
|
|
|
ForExpression = "for" "(" Expression ")" option("|" option("*") "Symbol" option("," "Symbol") "|") Expression
|
2016-01-19 18:15:36 -08:00
|
|
|
|
2016-01-28 17:58:28 -08:00
|
|
|
BoolOrExpression = BoolAndExpression "||" BoolOrExpression | BoolAndExpression
|
2016-01-19 18:15:36 -08:00
|
|
|
|
2016-01-28 17:58:28 -08:00
|
|
|
ReturnExpression = option("%" | "?") "return" option(Expression)
|
2015-12-09 14:20:31 -08:00
|
|
|
|
2016-02-05 23:56:01 -08:00
|
|
|
Defer = option("%" | "?") "defer" option(Expression)
|
2016-02-05 22:20:34 -08:00
|
|
|
|
2016-01-28 17:58:28 -08:00
|
|
|
IfExpression = IfVarExpression | IfBoolExpression
|
2015-12-26 14:05:27 -08:00
|
|
|
|
2016-01-28 17:58:28 -08:00
|
|
|
IfBoolExpression = "if" "(" Expression ")" Expression option(Else)
|
2015-12-09 14:20:31 -08:00
|
|
|
|
2016-01-31 00:20:47 -08:00
|
|
|
IfVarExpression = "if" "(" ("const" | "var") "Symbol" option(":" TypeExpr) "?=" Expression ")" Expression Option(Else)
|
2015-12-09 14:20:31 -08:00
|
|
|
|
2016-01-28 17:58:28 -08:00
|
|
|
Else = "else" Expression
|
2015-12-09 14:20:31 -08:00
|
|
|
|
2016-01-28 17:58:28 -08:00
|
|
|
BoolAndExpression = ComparisonExpression "&&" BoolAndExpression | ComparisonExpression
|
2015-12-09 14:20:31 -08:00
|
|
|
|
2016-01-28 17:58:28 -08:00
|
|
|
ComparisonExpression = BinaryOrExpression ComparisonOperator BinaryOrExpression | BinaryOrExpression
|
2015-12-09 14:20:31 -08:00
|
|
|
|
2016-01-28 17:58:28 -08:00
|
|
|
ComparisonOperator = "==" | "!=" | "<" | ">" | "<=" | ">="
|
2015-12-09 14:20:31 -08:00
|
|
|
|
2016-01-28 17:58:28 -08:00
|
|
|
BinaryOrExpression = BinaryXorExpression "|" BinaryOrExpression | BinaryXorExpression
|
2015-12-09 14:20:31 -08:00
|
|
|
|
2016-01-28 17:58:28 -08:00
|
|
|
BinaryXorExpression = BinaryAndExpression "^" BinaryXorExpression | BinaryAndExpression
|
2015-12-09 14:20:31 -08:00
|
|
|
|
2016-01-28 17:58:28 -08:00
|
|
|
BinaryAndExpression = BitShiftExpression "&" BinaryAndExpression | BitShiftExpression
|
2015-12-09 14:20:31 -08:00
|
|
|
|
2016-01-28 17:58:28 -08:00
|
|
|
BitShiftExpression = AdditionExpression BitShiftOperator BitShiftExpression | AdditionExpression
|
2015-12-09 14:20:31 -08:00
|
|
|
|
2016-01-28 17:58:28 -08:00
|
|
|
BitShiftOperator = "<<" | ">>"
|
2015-12-09 14:20:31 -08:00
|
|
|
|
2016-01-28 17:58:28 -08:00
|
|
|
AdditionExpression = MultiplyExpression AdditionOperator AdditionExpression | MultiplyExpression
|
2015-12-09 14:20:31 -08:00
|
|
|
|
2016-01-28 17:58:28 -08:00
|
|
|
AdditionOperator = "+" | "-" | "++"
|
2015-12-09 14:20:31 -08:00
|
|
|
|
2016-01-28 17:58:28 -08:00
|
|
|
MultiplyExpression = CurlySuffixExpression MultiplyOperator MultiplyExpression | CurlySuffixExpression
|
2016-01-15 16:40:12 -08:00
|
|
|
|
2016-01-31 00:20:47 -08:00
|
|
|
CurlySuffixExpression = TypeExpr option(ContainerInitExpression)
|
2015-12-09 14:20:31 -08:00
|
|
|
|
2016-01-28 17:58:28 -08:00
|
|
|
MultiplyOperator = "*" | "/" | "%"
|
2015-12-09 14:20:31 -08:00
|
|
|
|
2016-01-28 17:58:28 -08:00
|
|
|
PrefixOpExpression = PrefixOp PrefixOpExpression | SuffixOpExpression
|
2015-12-09 14:20:31 -08:00
|
|
|
|
2016-01-28 17:58:28 -08:00
|
|
|
SuffixOpExpression = PrimaryExpression option(FnCallExpression | ArrayAccessExpression | FieldAccessExpression | SliceExpression)
|
2015-12-11 23:10:37 -08:00
|
|
|
|
2016-01-28 17:58:28 -08:00
|
|
|
FieldAccessExpression = "." "Symbol"
|
2015-12-09 14:20:31 -08:00
|
|
|
|
2016-01-28 17:58:28 -08:00
|
|
|
FnCallExpression = "(" list(Expression, ",") ")"
|
2015-12-09 14:20:31 -08:00
|
|
|
|
2016-01-28 17:58:28 -08:00
|
|
|
ArrayAccessExpression = "[" Expression "]"
|
2015-12-09 14:20:31 -08:00
|
|
|
|
2016-01-28 17:58:28 -08:00
|
|
|
SliceExpression = "[" Expression "..." option(Expression) "]" option("const")
|
2016-01-07 04:29:11 -08:00
|
|
|
|
2016-01-28 17:58:28 -08:00
|
|
|
ContainerInitExpression = "{" ContainerInitBody "}"
|
2016-01-13 17:15:51 -08:00
|
|
|
|
2016-01-28 17:58:28 -08:00
|
|
|
ContainerInitBody = list(StructLiteralField, ",") | list(Expression, ",")
|
2016-01-13 17:15:51 -08:00
|
|
|
|
2016-01-28 17:58:28 -08:00
|
|
|
StructLiteralField = "." "Symbol" "=" Expression
|
2015-12-09 14:20:31 -08:00
|
|
|
|
2016-02-01 01:11:46 -08:00
|
|
|
PrefixOp = "!" | "-" | "~" | "*" | ("&" option("const")) | "?" | "%" | "%%" | "??"
|
2015-12-23 23:00:23 -08:00
|
|
|
|
2016-01-28 19:26:40 -08:00
|
|
|
PrimaryExpression = "Number" | "String" | "CharLiteral" | KeywordLiteral | GroupedExpression | GotoExpression | BlockExpression | "Symbol" | ("@" "Symbol" FnCallExpression) | ArrayType | (option("extern") FnProto) | AsmExpression | ("error" "." "Symbol")
|
2015-12-23 23:00:23 -08:00
|
|
|
|
2016-01-31 00:20:47 -08:00
|
|
|
ArrayType = "[" option(Expression) "]" option("const") TypeExpr
|
2015-12-09 14:20:31 -08:00
|
|
|
|
2016-01-28 17:58:28 -08:00
|
|
|
GotoExpression = "goto" "Symbol"
|
2015-12-09 14:20:31 -08:00
|
|
|
|
2016-01-28 17:58:28 -08:00
|
|
|
GroupedExpression = "(" Expression ")"
|
2015-12-09 14:20:31 -08:00
|
|
|
|
2016-01-31 00:20:47 -08:00
|
|
|
KeywordLiteral = "true" | "false" | "null" | "break" | "continue" | "undefined" | "error" | "type"
|
2015-12-09 14:20:31 -08:00
|
|
|
```
|
|
|
|
|
|
|
|
## Operator Precedence
|
|
|
|
|
|
|
|
```
|
2016-01-15 16:40:12 -08:00
|
|
|
x() x[] x.y
|
2016-01-25 14:45:05 -08:00
|
|
|
!x -x ~x *x &x ?x %x %%x
|
2016-01-15 16:40:12 -08:00
|
|
|
x{}
|
2015-12-09 14:20:31 -08:00
|
|
|
* / %
|
2016-01-25 20:56:29 -08:00
|
|
|
+ - ++
|
2015-12-09 14:20:31 -08:00
|
|
|
<< >>
|
|
|
|
&
|
|
|
|
^
|
|
|
|
|
|
|
|
|
== != < > <= >=
|
|
|
|
&&
|
|
|
|
||
|
2016-01-25 12:53:40 -08:00
|
|
|
?? %%
|
2015-12-12 17:17:27 -08:00
|
|
|
= *= /= %= += -= <<= >>= &= ^= |= &&= ||=
|
2015-12-09 14:20:31 -08:00
|
|
|
```
|
|
|
|
|
2016-01-20 00:27:53 -08:00
|
|
|
## Types
|
|
|
|
|
|
|
|
### Numeric Types
|
|
|
|
|
|
|
|
```
|
|
|
|
Type name C equivalent Description
|
|
|
|
|
|
|
|
i8 int8_t signed 8-bit integer
|
|
|
|
u8 uint8_t unsigned 8-bit integer
|
|
|
|
i16 int16_t signed 16-bit integer
|
|
|
|
u16 uint16_t unsigned 16-bit integer
|
|
|
|
i32 int32_t signed 32-bit integer
|
|
|
|
u32 uint32_t unsigned 32-bit integer
|
|
|
|
i64 int64_t signed 64-bit integer
|
|
|
|
u64 uint64_t unsigned 64-bit integer
|
|
|
|
|
|
|
|
f32 float 32-bit IEE754 floating point
|
|
|
|
f64 double 64-bit IEE754 floating point
|
|
|
|
|
|
|
|
isize intptr_t signed pointer sized integer
|
|
|
|
usize uintptr_t unsigned pointer sized integer
|
|
|
|
|
|
|
|
c_short short for ABI compatibility with C
|
|
|
|
c_ushort unsigned short for ABI compatibility with C
|
|
|
|
c_int int for ABI compatibility with C
|
|
|
|
c_uint unsigned int for ABI compatibility with C
|
|
|
|
c_long long for ABI compatibility with C
|
|
|
|
c_ulong unsigned long for ABI compatibility with C
|
|
|
|
c_longlong long long for ABI compatibility with C
|
|
|
|
c_ulonglong unsigned long long for ABI compatibility with C
|
2016-01-31 14:44:02 -08:00
|
|
|
c_long_double long double for ABI compatibility with C
|
2016-03-01 14:26:41 -08:00
|
|
|
c_void void for ABI compatibility with C
|
2016-01-20 00:27:53 -08:00
|
|
|
```
|
|
|
|
|
|
|
|
### Boolean Type
|
2016-01-28 17:58:28 -08:00
|
|
|
|
2016-01-20 00:27:53 -08:00
|
|
|
The boolean type has the name `bool` and represents either true or false.
|
|
|
|
|
2016-01-20 17:18:50 -08:00
|
|
|
### Function Type
|
2016-01-28 17:58:28 -08:00
|
|
|
|
2016-01-20 00:27:53 -08:00
|
|
|
TODO
|
|
|
|
|
2016-01-20 17:18:50 -08:00
|
|
|
### Fixed-Size Array Type
|
|
|
|
|
|
|
|
Example: The string `"aoeu"` has type `[4]u8`.
|
|
|
|
|
|
|
|
The size is known at compile time and is part of the type.
|
|
|
|
|
|
|
|
### Slice Type
|
|
|
|
|
|
|
|
A slice can be obtained with the slicing syntax: `array[start...end]`
|
|
|
|
|
|
|
|
Example: `"aoeu"[0...2]` has type `[]u8`.
|
2016-01-20 00:27:53 -08:00
|
|
|
|
2016-01-22 15:05:29 -08:00
|
|
|
### Struct Type
|
2016-01-28 17:58:28 -08:00
|
|
|
|
2016-01-20 00:27:53 -08:00
|
|
|
TODO
|
|
|
|
|
2016-01-22 15:05:29 -08:00
|
|
|
### Enum Type
|
|
|
|
|
|
|
|
TODO
|
|
|
|
|
|
|
|
### Maybe Type
|
|
|
|
|
|
|
|
TODO
|
|
|
|
|
2016-02-10 15:35:07 -08:00
|
|
|
### Pure Error Type
|
|
|
|
|
|
|
|
TODO
|
|
|
|
|
|
|
|
### Error Union Type
|
2016-01-22 15:05:29 -08:00
|
|
|
|
|
|
|
TODO
|
|
|
|
|
|
|
|
### Pointer Type
|
|
|
|
|
2016-01-20 00:27:53 -08:00
|
|
|
TODO
|
2015-12-09 14:20:31 -08:00
|
|
|
|
2016-01-20 00:27:53 -08:00
|
|
|
### Unreachable Type
|
2016-01-20 17:18:50 -08:00
|
|
|
|
2016-01-20 00:27:53 -08:00
|
|
|
The unreachable type has the name `unreachable`. TODO explanation
|
2015-12-09 14:20:31 -08:00
|
|
|
|
2016-01-20 00:27:53 -08:00
|
|
|
### Void Type
|
2016-01-20 17:18:50 -08:00
|
|
|
|
|
|
|
The void type has the name `void`. void types are zero bits and are omitted
|
|
|
|
from codegen.
|
2015-12-09 14:20:31 -08:00
|
|
|
|
|
|
|
|
2016-01-20 00:27:53 -08:00
|
|
|
## Expressions
|
|
|
|
|
|
|
|
### Literals
|
|
|
|
|
|
|
|
#### Character and String Literals
|
|
|
|
```
|
2016-04-03 18:44:17 -07:00
|
|
|
Literal Example Characters Escapes Null Term Type
|
2016-01-20 00:27:53 -08:00
|
|
|
|
2016-04-03 18:44:17 -07:00
|
|
|
Byte 'H' All ASCII Byte No u8
|
|
|
|
UTF-8 Bytes "hello" All Unicode Byte & Unicode No [5]u8
|
|
|
|
UTF-8 C string c"hello" All Unicode Byte & Unicode Yes &const u8
|
|
|
|
UTF-8 Raw String r"A(hello)A" All Unicode None No [5]u8
|
|
|
|
UTF-8 Raw C String rc"A(hello)A" All Unicode None Yes &const u8
|
2016-01-20 00:27:53 -08:00
|
|
|
```
|
|
|
|
|
2016-04-03 18:44:17 -07:00
|
|
|
##### Raw Strings
|
|
|
|
|
|
|
|
Raw string literals have no escapes and can span across multiple lines. To
|
|
|
|
start a raw string, use 'r"' or 'rc"' followed by unique bytes followed by '('.
|
|
|
|
To end a raw string, use ')' followed by the same unique bytes, followed by '"'.
|
|
|
|
|
|
|
|
|
2016-01-20 00:27:53 -08:00
|
|
|
```
|
|
|
|
Escape Name
|
|
|
|
|
|
|
|
\xNN hexadecimal 8-bit character code (exactly 2 digits)
|
|
|
|
\n Newline
|
|
|
|
\r Carriage return
|
|
|
|
\t Tab
|
|
|
|
\\ Backslash
|
|
|
|
\0 Null
|
|
|
|
\' Single quote
|
|
|
|
\" Double quote
|
|
|
|
```
|
2015-12-09 14:20:31 -08:00
|
|
|
|
|
|
|
### Unicode Escapes
|
|
|
|
|
2016-01-20 00:27:53 -08:00
|
|
|
Escape | Name
|
|
|
|
------------|-----------------------------------------------
|
|
|
|
\u{NNNNNN} | hexadecimal 24-bit Unicode character code (up to 6 digits)
|
|
|
|
|
|
|
|
#### Numeric Literals
|
|
|
|
|
|
|
|
```
|
|
|
|
Number literals Example Exponentiation
|
|
|
|
|
|
|
|
Decimal integer 98222 N/A
|
|
|
|
Hex integer 0xff N/A
|
|
|
|
Octal integer 0o77 N/A
|
|
|
|
Binary integer 0b11110000 N/A
|
|
|
|
Floating-point 123.0E+77 Optional
|
|
|
|
Hex floating point TODO TODO
|
|
|
|
```
|
|
|
|
|
|
|
|
### Identifiers
|
2016-01-28 17:58:28 -08:00
|
|
|
|
2016-01-20 00:27:53 -08:00
|
|
|
TODO
|
|
|
|
|
|
|
|
### Declarations
|
2016-01-28 17:58:28 -08:00
|
|
|
|
2016-01-20 00:27:53 -08:00
|
|
|
Declarations have type `void`.
|
|
|
|
|
|
|
|
#### Function Declarations
|
2016-01-28 17:58:28 -08:00
|
|
|
|
2016-01-20 00:27:53 -08:00
|
|
|
TODO
|
|
|
|
|
|
|
|
#### Variable Declarations
|
2016-01-28 17:58:28 -08:00
|
|
|
|
2016-01-20 00:27:53 -08:00
|
|
|
TODO
|
|
|
|
|
|
|
|
#### Struct Declarations
|
2016-01-28 17:58:28 -08:00
|
|
|
|
2016-01-20 00:27:53 -08:00
|
|
|
TODO
|
|
|
|
|
|
|
|
#### Enum Declarations
|
2016-01-28 17:58:28 -08:00
|
|
|
|
2016-01-20 00:27:53 -08:00
|
|
|
TODO
|
|
|
|
|
|
|
|
|
|
|
|
## Built-in Functions
|
2016-01-28 17:58:28 -08:00
|
|
|
|
2016-01-20 00:27:53 -08:00
|
|
|
Built-in functions are prefixed with `@`.
|
|
|
|
|
2016-02-10 15:35:07 -08:00
|
|
|
### @typeof
|
2016-01-28 17:58:28 -08:00
|
|
|
|
2016-02-10 15:35:07 -08:00
|
|
|
`@typeof(expression)`
|
2016-01-20 00:27:53 -08:00
|
|
|
|
2016-02-10 15:35:07 -08:00
|
|
|
### @sizeof
|
2016-01-28 17:58:28 -08:00
|
|
|
|
2016-02-10 15:35:07 -08:00
|
|
|
`@sizeof(type)`
|
2016-01-20 00:27:53 -08:00
|
|
|
|
|
|
|
### Overflow Arithmetic
|
2016-01-28 17:58:28 -08:00
|
|
|
|
2016-02-10 15:35:07 -08:00
|
|
|
Overflow arithmetic functions have defined behavior on overflow or underflow.
|
2016-01-20 00:27:53 -08:00
|
|
|
|
2016-02-10 15:35:07 -08:00
|
|
|
The functions take an integer type, two variables of the specified type, and a
|
|
|
|
pointer to a variable of the specified type where the result is stored. The
|
|
|
|
functions return a boolean value: true of overflow/underflow occurred, false
|
|
|
|
otherwise.
|
2016-01-20 00:27:53 -08:00
|
|
|
|
|
|
|
```
|
|
|
|
Function Operation
|
2016-02-10 15:35:07 -08:00
|
|
|
@add_with_overflow(T: type, a: T, b: T, x: &T) -> bool *x = a + b
|
|
|
|
@sub_with_overflow(T: type, a: T, b: T, x: &T) -> bool *x = a - b
|
|
|
|
@mul_with_overflow(T: type, a: T, b: T, x: &T) -> bool *x = a * b
|
2016-01-20 00:27:53 -08:00
|
|
|
```
|
|
|
|
|
2016-02-10 15:35:07 -08:00
|
|
|
### @memset
|
2016-01-28 17:58:28 -08:00
|
|
|
|
2016-02-10 15:35:07 -08:00
|
|
|
`@memset(dest, char, len)`
|
2015-12-09 14:20:31 -08:00
|
|
|
|
2016-02-10 15:35:07 -08:00
|
|
|
### @memcpy
|
2016-01-28 17:58:28 -08:00
|
|
|
|
2016-02-10 15:35:07 -08:00
|
|
|
`@memcpy(dest, source, len)`
|
|
|
|
|
|
|
|
### @member_count
|
|
|
|
|
|
|
|
`@member_count(enum_type)`
|
2015-12-09 14:20:31 -08:00
|
|
|
|
2016-01-20 00:27:53 -08:00
|
|
|
### Max and Min Value
|
2016-01-28 17:58:28 -08:00
|
|
|
|
2016-02-10 15:35:07 -08:00
|
|
|
`@max_value(type)`
|
|
|
|
`@min_value(type)`
|