| ... | @@ -3,153 +3,153 @@ | ... | @@ -3,153 +3,153 @@ |
| 3 | ## Grammar | 3 | ## Grammar |
| 4 | | 4 | |
| 5 | ``` | 5 | ``` |
| 6 | Root : many(TopLevelDecl) "EOF" | 6 | Root = many(TopLevelDecl) "EOF" |
| 7 | | 7 | |
| 8 | TopLevelDecl : many(Directive) option(VisibleMod) (FnDef | ExternDecl | RootExportDecl | Import | ContainerDecl | GlobalVarDecl | ErrorValueDecl | CImportDecl) | 8 | TopLevelDecl = many(Directive) option(VisibleMod) (FnDef | ExternDecl | RootExportDecl | Import | ContainerDecl | GlobalVarDecl | ErrorValueDecl | CImportDecl) |
| 9 | | 9 | |
| 10 | CImportDecl : "c_import" Block | 10 | CImportDecl = "c_import" Block |
| 11 | | 11 | |
| 12 | ErrorValueDecl : "error" "Symbol" ";" | 12 | ErrorValueDecl = "error" "Symbol" ";" |
| 13 | | 13 | |
| 14 | GlobalVarDecl : VariableDeclaration ";" | 14 | GlobalVarDecl = VariableDeclaration ";" |
| 15 | | 15 | |
| 16 | VariableDeclaration : ("var" | "const") "Symbol" option(":" PrefixOpExpression) "=" Expression | 16 | VariableDeclaration = ("var" | "const") "Symbol" option(":" PrefixOpExpression) "=" Expression |
| 17 | | 17 | |
| 18 | ContainerDecl : ("struct" | "enum") "Symbol" "{" many(StructMember) "}" | 18 | ContainerDecl = ("struct" | "enum") "Symbol" "{" many(StructMember) "}" |
| 19 | | 19 | |
| 20 | StructMember: many(Directive) option(VisibleMod) (StructField | FnDef) | 20 | StructMember = many(Directive) option(VisibleMod) (StructField | FnDef) |
| 21 | | 21 | |
| 22 | StructField : "Symbol" option(":" Expression) ",") | 22 | StructField = "Symbol" option(":" Expression) ",") |
| 23 | | 23 | |
| 24 | Import : "import" "String" ";" | 24 | Import = "import" "String" ";" |
| 25 | | 25 | |
| 26 | RootExportDecl : "export" "Symbol" "String" ";" | 26 | RootExportDecl = "export" "Symbol" "String" ";" |
| 27 | | 27 | |
| 28 | ExternDecl : "extern" FnProto ";" | 28 | ExternDecl = "extern" FnProto ";" |
| 29 | | 29 | |
| 30 | FnProto : "fn" "Symbol" ParamDeclList option("->" PrefixOpExpression) | 30 | FnProto = "fn" option("Symbol") ParamDeclList option("->" PrefixOpExpression) |
| 31 | | 31 | |
| 32 | Directive : "#" "Symbol" "(" "String" ")" | 32 | Directive = "#" "Symbol" "(" "String" ")" |
| 33 | | 33 | |
| 34 | VisibleMod : "pub" | "export" | 34 | VisibleMod = "pub" | "export" |
| 35 | | 35 | |
| 36 | FnDef : FnProto Block | 36 | FnDef = FnProto Block |
| 37 | | 37 | |
| 38 | ParamDeclList : "(" list(ParamDecl, ",") ")" | 38 | ParamDeclList = "(" list(ParamDecl, ",") ")" |
| 39 | | 39 | |
| 40 | ParamDecl : option("noalias") "Symbol" ":" PrefixOpExpression | "..." | 40 | ParamDecl = option("noalias") option("Symbol" ":") PrefixOpExpression | "..." |
| 41 | | 41 | |
| 42 | Block : "{" list(option(Statement), ";") "}" | 42 | Block = "{" list(option(Statement), ";") "}" |
| 43 | | 43 | |
| 44 | Statement : Label | VariableDeclaration ";" | NonBlockExpression ";" | BlockExpression | 44 | Statement = Label | VariableDeclaration ";" | NonBlockExpression ";" | BlockExpression |
| 45 | | 45 | |
| 46 | Label: "Symbol" ":" | 46 | Label = "Symbol" ":" |
| 47 | | 47 | |
| 48 | Expression : BlockExpression | NonBlockExpression | 48 | Expression = BlockExpression | NonBlockExpression |
| 49 | | 49 | |
| 50 | NonBlockExpression : ReturnExpression | AssignmentExpression | 50 | NonBlockExpression = ReturnExpression | AssignmentExpression |
| 51 | | 51 | |
| 52 | AsmExpression : "asm" option("volatile") "(" "String" option(AsmOutput) ")" | 52 | AsmExpression = "asm" option("volatile") "(" "String" option(AsmOutput) ")" |
| 53 | | 53 | |
| 54 | AsmOutput : ":" list(AsmOutputItem, ",") option(AsmInput) | 54 | AsmOutput = ":" list(AsmOutputItem, ",") option(AsmInput) |
| 55 | | 55 | |
| 56 | AsmInput : ":" list(AsmInputItem, ",") option(AsmClobbers) | 56 | AsmInput = ":" list(AsmInputItem, ",") option(AsmClobbers) |
| 57 | | 57 | |
| 58 | AsmOutputItem : "[" "Symbol" "]" "String" "(" ("Symbol" | "->" PrefixOpExpression) ")" | 58 | AsmOutputItem = "[" "Symbol" "]" "String" "(" ("Symbol" | "->" PrefixOpExpression) ")" |
| 59 | | 59 | |
| 60 | AsmInputItem : "[" "Symbol" "]" "String" "(" Expression ")" | 60 | AsmInputItem = "[" "Symbol" "]" "String" "(" Expression ")" |
| 61 | | 61 | |
| 62 | AsmClobbers: ":" list("String", ",") | 62 | AsmClobbers= ":" list("String", ",") |
| 63 | | 63 | |
| 64 | UnwrapExpression : BoolOrExpression (UnwrapMaybe | UnwrapError) | BoolOrExpression | 64 | UnwrapExpression = BoolOrExpression (UnwrapMaybe | UnwrapError) | BoolOrExpression |
| 65 | | 65 | |
| 66 | UnwrapMaybe : "??" BoolOrExpression | 66 | UnwrapMaybe = "??" BoolOrExpression |
| 67 | | 67 | |
| 68 | UnwrapError : "%%" option("|" "Symbol" "|") BoolOrExpression | 68 | UnwrapError = "%%" option("|" "Symbol" "|") BoolOrExpression |
| 69 | | 69 | |
| 70 | AssignmentExpression : UnwrapExpression AssignmentOperator UnwrapExpression | UnwrapExpression | 70 | AssignmentExpression = UnwrapExpression AssignmentOperator UnwrapExpression | UnwrapExpression |
| 71 | | 71 | |
| 72 | AssignmentOperator : "=" | "*=" | "/=" | "%=" | "+=" | "-=" | "<<=" | ">>=" | "&=" | "^=" | "|=" | "&&=" | "||=" | 72 | AssignmentOperator = "=" | "*=" | "/=" | "%=" | "+=" | "-=" | "<<=" | ">>=" | "&=" | "^=" | "|=" | "&&=" | "||=" |
| 73 | | 73 | |
| 74 | BlockExpression : IfExpression | Block | WhileExpression | ForExpression | SwitchExpression | 74 | BlockExpression = IfExpression | Block | WhileExpression | ForExpression | SwitchExpression |
| 75 | | 75 | |
| 76 | SwitchExpression : "switch" "(" Expression ")" "{" many(SwitchProng) "}" | 76 | SwitchExpression = "switch" "(" Expression ")" "{" many(SwitchProng) "}" |
| 77 | | 77 | |
| 78 | SwitchProng : (list(SwitchItem, ",") | "else") option(":" "(" "Symbol" ")") "=>" Expression "," | 78 | SwitchProng = (list(SwitchItem, ",") | "else") option(":" "(" "Symbol" ")") "=>" Expression "," |
| 79 | | 79 | |
| 80 | SwitchItem : Expression | (Expression "..." Expression) | 80 | SwitchItem = Expression | (Expression "..." Expression) |
| 81 | | 81 | |
| 82 | WhileExpression : "while" "(" Expression ")" Expression | 82 | WhileExpression = "while" "(" Expression ")" Expression |
| 83 | | 83 | |
| 84 | ForExpression : "for" "(" "Symbol" "," Expression option("," "Symbol") ")" Expression | 84 | ForExpression = "for" "(" "Symbol" "," Expression option("," "Symbol") ")" Expression |
| 85 | | 85 | |
| 86 | BoolOrExpression : BoolAndExpression "||" BoolOrExpression | BoolAndExpression | 86 | BoolOrExpression = BoolAndExpression "||" BoolOrExpression | BoolAndExpression |
| 87 | | 87 | |
| 88 | ReturnExpression : option("%" | "?") "return" option(Expression) | 88 | ReturnExpression = option("%" | "?") "return" option(Expression) |
| 89 | | 89 | |
| 90 | IfExpression : IfVarExpression | IfBoolExpression | 90 | IfExpression = IfVarExpression | IfBoolExpression |
| 91 | | 91 | |
| 92 | IfBoolExpression : "if" "(" Expression ")" Expression option(Else) | 92 | IfBoolExpression = "if" "(" Expression ")" Expression option(Else) |
| 93 | | 93 | |
| 94 | IfVarExpression : "if" "(" ("const" | "var") "Symbol" option(":" PrefixOpExpression) "?=" Expression ")" Expression Option(Else) | 94 | IfVarExpression = "if" "(" ("const" | "var") "Symbol" option(":" PrefixOpExpression) "?=" Expression ")" Expression Option(Else) |
| 95 | | 95 | |
| 96 | Else : "else" Expression | 96 | Else = "else" Expression |
| 97 | | 97 | |
| 98 | BoolAndExpression : ComparisonExpression "&&" BoolAndExpression | ComparisonExpression | 98 | BoolAndExpression = ComparisonExpression "&&" BoolAndExpression | ComparisonExpression |
| 99 | | 99 | |
| 100 | ComparisonExpression : BinaryOrExpression ComparisonOperator BinaryOrExpression | BinaryOrExpression | 100 | ComparisonExpression = BinaryOrExpression ComparisonOperator BinaryOrExpression | BinaryOrExpression |
| 101 | | 101 | |
| 102 | ComparisonOperator : "==" | "!=" | "<" | ">" | "<=" | ">=" | 102 | ComparisonOperator = "==" | "!=" | "<" | ">" | "<=" | ">=" |
| 103 | | 103 | |
| 104 | BinaryOrExpression : BinaryXorExpression "|" BinaryOrExpression | BinaryXorExpression | 104 | BinaryOrExpression = BinaryXorExpression "|" BinaryOrExpression | BinaryXorExpression |
| 105 | | 105 | |
| 106 | BinaryXorExpression : BinaryAndExpression "^" BinaryXorExpression | BinaryAndExpression | 106 | BinaryXorExpression = BinaryAndExpression "^" BinaryXorExpression | BinaryAndExpression |
| 107 | | 107 | |
| 108 | BinaryAndExpression : BitShiftExpression "&" BinaryAndExpression | BitShiftExpression | 108 | BinaryAndExpression = BitShiftExpression "&" BinaryAndExpression | BitShiftExpression |
| 109 | | 109 | |
| 110 | BitShiftExpression : AdditionExpression BitShiftOperator BitShiftExpression | AdditionExpression | 110 | BitShiftExpression = AdditionExpression BitShiftOperator BitShiftExpression | AdditionExpression |
| 111 | | 111 | |
| 112 | BitShiftOperator : "<<" | ">>" | 112 | BitShiftOperator = "<<" | ">>" |
| 113 | | 113 | |
| 114 | AdditionExpression : MultiplyExpression AdditionOperator AdditionExpression | MultiplyExpression | 114 | AdditionExpression = MultiplyExpression AdditionOperator AdditionExpression | MultiplyExpression |
| 115 | | 115 | |
| 116 | AdditionOperator : "+" | "-" | "++" | 116 | AdditionOperator = "+" | "-" | "++" |
| 117 | | 117 | |
| 118 | MultiplyExpression : CurlySuffixExpression MultiplyOperator MultiplyExpression | CurlySuffixExpression | 118 | MultiplyExpression = CurlySuffixExpression MultiplyOperator MultiplyExpression | CurlySuffixExpression |
| 119 | | 119 | |
| 120 | CurlySuffixExpression : PrefixOpExpression option(ContainerInitExpression) | 120 | CurlySuffixExpression = PrefixOpExpression option(ContainerInitExpression) |
| 121 | | 121 | |
| 122 | MultiplyOperator : "*" | "/" | "%" | 122 | MultiplyOperator = "*" | "/" | "%" |
| 123 | | 123 | |
| 124 | PrefixOpExpression : PrefixOp PrefixOpExpression | SuffixOpExpression | 124 | PrefixOpExpression = PrefixOp PrefixOpExpression | SuffixOpExpression |
| 125 | | 125 | |
| 126 | SuffixOpExpression : PrimaryExpression option(FnCallExpression | ArrayAccessExpression | FieldAccessExpression | SliceExpression) | 126 | SuffixOpExpression = PrimaryExpression option(FnCallExpression | ArrayAccessExpression | FieldAccessExpression | SliceExpression) |
| 127 | | 127 | |
| 128 | FieldAccessExpression : "." "Symbol" | 128 | FieldAccessExpression = "." "Symbol" |
| 129 | | 129 | |
| 130 | FnCallExpression : "(" list(Expression, ",") ")" | 130 | FnCallExpression = "(" list(Expression, ",") ")" |
| 131 | | 131 | |
| 132 | ArrayAccessExpression : "[" Expression "]" | 132 | ArrayAccessExpression = "[" Expression "]" |
| 133 | | 133 | |
| 134 | SliceExpression : "[" Expression "..." option(Expression) "]" option("const") | 134 | SliceExpression = "[" Expression "..." option(Expression) "]" option("const") |
| 135 | | 135 | |
| 136 | ContainerInitExpression : "{" ContainerInitBody "}" | 136 | ContainerInitExpression = "{" ContainerInitBody "}" |
| 137 | | 137 | |
| 138 | ContainerInitBody : list(StructLiteralField, ",") | list(Expression, ",") | 138 | ContainerInitBody = list(StructLiteralField, ",") | list(Expression, ",") |
| 139 | | 139 | |
| 140 | StructLiteralField : "." "Symbol" "=" Expression | 140 | StructLiteralField = "." "Symbol" "=" Expression |
| 141 | | 141 | |
| 142 | PrefixOp : "!" | "-" | "~" | "*" | ("&" option("const")) | "?" | "%" | "%%" | 142 | PrefixOp = "!" | "-" | "~" | "*" | ("&" option("const")) | "?" | "%" | "%%" |
| 143 | | 143 | |
| 144 | PrimaryExpression : "Number" | "String" | "CharLiteral" | KeywordLiteral | GroupedExpression | GotoExpression | BlockExpression | "Symbol" | ("@" "Symbol" FnCallExpression) | ArrayType | AsmExpression | ("error" "." "Symbol") | 144 | PrimaryExpression = "Number" | "String" | "CharLiteral" | KeywordLiteral | GroupedExpression | GotoExpression | BlockExpression | "Symbol" | ("@" "Symbol" FnCallExpression) | ArrayType | FnProto | AsmExpression | ("error" "." "Symbol") |
| 145 | | 145 | |
| 146 | ArrayType : "[" option(Expression) "]" option("const") PrefixOpExpression | 146 | ArrayType = "[" option(Expression) "]" option("const") PrefixOpExpression |
| 147 | | 147 | |
| 148 | GotoExpression: "goto" "Symbol" | 148 | GotoExpression = "goto" "Symbol" |
| 149 | | 149 | |
| 150 | GroupedExpression : "(" Expression ")" | 150 | GroupedExpression = "(" Expression ")" |
| 151 | | 151 | |
| 152 | KeywordLiteral : "true" | "false" | "null" | "break" | "continue" | "undefined" | "error" | 152 | KeywordLiteral = "true" | "false" | "null" | "break" | "continue" | "undefined" | "error" |
| 153 | ``` | 153 | ``` |
| 154 | | 154 | |
| 155 | ## Operator Precedence | 155 | ## Operator Precedence |
| ... | @@ -204,9 +204,11 @@ c_ulonglong unsigned long long for ABI compatibility with C | ... | @@ -204,9 +204,11 @@ c_ulonglong unsigned long long for ABI compatibility with C |
| 204 | ``` | 204 | ``` |
| 205 | | 205 | |
| 206 | ### Boolean Type | 206 | ### Boolean Type |
| | 207 | |
| 207 | The boolean type has the name `bool` and represents either true or false. | 208 | The boolean type has the name `bool` and represents either true or false. |
| 208 | | 209 | |
| 209 | ### Function Type | 210 | ### Function Type |
| | 211 | |
| 210 | TODO | 212 | TODO |
| 211 | | 213 | |
| 212 | ### Fixed-Size Array Type | 214 | ### Fixed-Size Array Type |
| ... | @@ -222,6 +224,7 @@ A slice can be obtained with the slicing syntax: `array[start...end]` | ... | @@ -222,6 +224,7 @@ A slice can be obtained with the slicing syntax: `array[start...end]` |
| 222 | Example: `"aoeu"[0...2]` has type `[]u8`. | 224 | Example: `"aoeu"[0...2]` has type `[]u8`. |
| 223 | | 225 | |
| 224 | ### Struct Type | 226 | ### Struct Type |
| | 227 | |
| 225 | TODO | 228 | TODO |
| 226 | | 229 | |
| 227 | ### Enum Type | 230 | ### Enum Type |
| ... | @@ -296,34 +299,44 @@ Hex floating point TODO TODO | ... | @@ -296,34 +299,44 @@ Hex floating point TODO TODO |
| 296 | ``` | 299 | ``` |
| 297 | | 300 | |
| 298 | ### Identifiers | 301 | ### Identifiers |
| | 302 | |
| 299 | TODO | 303 | TODO |
| 300 | | 304 | |
| 301 | ### Declarations | 305 | ### Declarations |
| | 306 | |
| 302 | Declarations have type `void`. | 307 | Declarations have type `void`. |
| 303 | | 308 | |
| 304 | #### Function Declarations | 309 | #### Function Declarations |
| | 310 | |
| 305 | TODO | 311 | TODO |
| 306 | | 312 | |
| 307 | #### Variable Declarations | 313 | #### Variable Declarations |
| | 314 | |
| 308 | TODO | 315 | TODO |
| 309 | | 316 | |
| 310 | #### Struct Declarations | 317 | #### Struct Declarations |
| | 318 | |
| 311 | TODO | 319 | TODO |
| 312 | | 320 | |
| 313 | #### Enum Declarations | 321 | #### Enum Declarations |
| | 322 | |
| 314 | TODO | 323 | TODO |
| 315 | | 324 | |
| 316 | | 325 | |
| 317 | ## Built-in Functions | 326 | ## Built-in Functions |
| | 327 | |
| 318 | Built-in functions are prefixed with `@`. | 328 | Built-in functions are prefixed with `@`. |
| 319 | | 329 | |
| 320 | ### Typeof | 330 | ### Typeof |
| | 331 | |
| 321 | TODO | 332 | TODO |
| 322 | | 333 | |
| 323 | ### Sizeof | 334 | ### Sizeof |
| | 335 | |
| 324 | TODO | 336 | TODO |
| 325 | | 337 | |
| 326 | ### Overflow Arithmetic | 338 | ### Overflow Arithmetic |
| | 339 | |
| 327 | Overflow arithmetic functions have defined behavior on overflow or underflow. TODO what is that behaviour? | 340 | Overflow arithmetic functions have defined behavior on overflow or underflow. TODO what is that behaviour? |
| 328 | | 341 | |
| 329 | The functions take an integer (TODO float?) 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. | 342 | The functions take an integer (TODO float?) 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. |
| ... | @@ -336,10 +349,13 @@ bool mul_with_overflow(type, a: type, b: type, x: &type) *x = a * b | ... | @@ -336,10 +349,13 @@ bool mul_with_overflow(type, a: type, b: type, x: &type) *x = a * b |
| 336 | ``` | 349 | ``` |
| 337 | | 350 | |
| 338 | ### Memory Operations | 351 | ### Memory Operations |
| | 352 | |
| 339 | TODO memset and memcpy | 353 | TODO memset and memcpy |
| 340 | | 354 | |
| 341 | ### Value Count | 355 | ### Value Count |
| | 356 | |
| 342 | TODO | 357 | TODO |
| 343 | | 358 | |
| 344 | ### Max and Min Value | 359 | ### Max and Min Value |
| | 360 | |
| 345 | TODO | 361 | TODO |