| author | |
| committer | |
| log | 47cf8520adb245dbd34ad60fc9206b7eaab5e0be |
| tree | e2859d84e1dbf803b63bd3ac11014f7b3709f467 |
| parent | 6a5e61acd117277eb2f943f5bc02ff7043542d4b |
See #22122 files changed, 82 insertions(+), 79 deletions(-)
doc/langref.md+2-2| ... | ... | @@ -15,7 +15,7 @@ ErrorValueDecl = "error" Symbol ";" |
| 15 | 15 | |
| 16 | 16 | GlobalVarDecl = VariableDeclaration ";" |
| 17 | 17 | |
| 18 | VariableDeclaration = option("inline") ("var" | "const") Symbol option(":" TypeExpr) "=" Expression | |
| 18 | VariableDeclaration = option("comptime") ("var" | "const") Symbol option(":" TypeExpr) "=" Expression | |
| 19 | 19 | |
| 20 | 20 | StructMember = (StructField | FnDef | GlobalVarDecl) |
| 21 | 21 | |
| ... | ... | @@ -33,7 +33,7 @@ FnDef = option("inline" | "extern") FnProto Block |
| 33 | 33 | |
| 34 | 34 | ParamDeclList = "(" list(ParamDecl, ",") ")" |
| 35 | 35 | |
| 36 | ParamDecl = option("noalias" | "inline") option(Symbol ":") TypeExpr | "..." | |
| 36 | ParamDecl = option("noalias" | "comptime") option(Symbol ":") TypeExpr | "..." | |
| 37 | 37 | |
| 38 | 38 | Block = "{" list(option(Statement), ";") "}" |
| 39 | 39 |
doc/vim/syntax/zig.vim+1-1| ... | ... | @@ -8,7 +8,7 @@ if exists("b:current_syntax") |
| 8 | 8 | endif |
| 9 | 9 | let b:current_syntax = "zig" |
| 10 | 10 | |
| 11 | syn keyword zigStorage const var extern export pub noalias inline nakedcc coldcc | |
| 11 | syn keyword zigStorage const var extern export pub noalias inline comptime nakedcc coldcc | |
| 12 | 12 | syn keyword zigStructure struct enum union |
| 13 | 13 | syn keyword zigStatement goto break return continue asm defer |
| 14 | 14 | syn keyword zigConditional if else switch |
src/analyze.cpp+1-1| ... | ... | @@ -979,7 +979,7 @@ static TypeTableEntry *analyze_fn_type(CodeGen *g, AstNode *proto_node, Scope *c |
| 979 | 979 | if (param_is_inline) { |
| 980 | 980 | if (fn_type_id.is_extern) { |
| 981 | 981 | add_node_error(g, param_node, |
| 982 | buf_sprintf("inline parameter not allowed in extern function")); | |
| 982 | buf_sprintf("comptime parameter not allowed in extern function")); | |
| 983 | 983 | return g->builtin_types.entry_invalid; |
| 984 | 984 | } |
| 985 | 985 | return get_generic_fn_type(g, &fn_type_id); |
src/parser.cpp+9-9| ... | ... | @@ -250,7 +250,7 @@ static AstNode *ast_parse_type_expr(ParseContext *pc, size_t *token_index, bool |
| 250 | 250 | } |
| 251 | 251 | |
| 252 | 252 | /* |
| 253 | ParamDecl = option("noalias" | "inline") option("Symbol" ":") TypeExpr | "..." | |
| 253 | ParamDecl = option("noalias" | "comptime") option(Symbol ":") TypeExpr | "..." | |
| 254 | 254 | */ |
| 255 | 255 | static AstNode *ast_parse_param_decl(ParseContext *pc, size_t *token_index) { |
| 256 | 256 | Token *token = &pc->tokens->at(*token_index); |
| ... | ... | @@ -266,7 +266,7 @@ static AstNode *ast_parse_param_decl(ParseContext *pc, size_t *token_index) { |
| 266 | 266 | node->data.param_decl.is_noalias = true; |
| 267 | 267 | *token_index += 1; |
| 268 | 268 | token = &pc->tokens->at(*token_index); |
| 269 | } else if (token->id == TokenIdKeywordInline) { | |
| 269 | } else if (token->id == TokenIdKeywordCompTime) { | |
| 270 | 270 | node->data.param_decl.is_inline = true; |
| 271 | 271 | *token_index += 1; |
| 272 | 272 | token = &pc->tokens->at(*token_index); |
| ... | ... | @@ -1492,7 +1492,7 @@ static AstNode *ast_parse_defer_expr(ParseContext *pc, size_t *token_index) { |
| 1492 | 1492 | } |
| 1493 | 1493 | |
| 1494 | 1494 | /* |
| 1495 | VariableDeclaration = option("inline") ("var" | "const") Symbol option(":" TypeExpr) "=" Expression | |
| 1495 | VariableDeclaration = option("comptime") ("var" | "const") Symbol option(":" TypeExpr) "=" Expression | |
| 1496 | 1496 | */ |
| 1497 | 1497 | static AstNode *ast_parse_variable_declaration_expr(ParseContext *pc, size_t *token_index, bool mandatory, |
| 1498 | 1498 | VisibMod visib_mod) |
| ... | ... | @@ -1501,9 +1501,9 @@ static AstNode *ast_parse_variable_declaration_expr(ParseContext *pc, size_t *to |
| 1501 | 1501 | Token *var_token; |
| 1502 | 1502 | |
| 1503 | 1503 | bool is_const; |
| 1504 | bool is_inline; | |
| 1505 | if (first_token->id == TokenIdKeywordInline) { | |
| 1506 | is_inline = true; | |
| 1504 | bool is_comptime; | |
| 1505 | if (first_token->id == TokenIdKeywordCompTime) { | |
| 1506 | is_comptime = true; | |
| 1507 | 1507 | var_token = &pc->tokens->at(*token_index + 1); |
| 1508 | 1508 | |
| 1509 | 1509 | if (var_token->id == TokenIdKeywordVar) { |
| ... | ... | @@ -1518,12 +1518,12 @@ static AstNode *ast_parse_variable_declaration_expr(ParseContext *pc, size_t *to |
| 1518 | 1518 | |
| 1519 | 1519 | *token_index += 2; |
| 1520 | 1520 | } else if (first_token->id == TokenIdKeywordVar) { |
| 1521 | is_inline = false; | |
| 1521 | is_comptime = false; | |
| 1522 | 1522 | is_const = false; |
| 1523 | 1523 | var_token = first_token; |
| 1524 | 1524 | *token_index += 1; |
| 1525 | 1525 | } else if (first_token->id == TokenIdKeywordConst) { |
| 1526 | is_inline = false; | |
| 1526 | is_comptime = false; | |
| 1527 | 1527 | is_const = true; |
| 1528 | 1528 | var_token = first_token; |
| 1529 | 1529 | *token_index += 1; |
| ... | ... | @@ -1535,7 +1535,7 @@ static AstNode *ast_parse_variable_declaration_expr(ParseContext *pc, size_t *to |
| 1535 | 1535 | |
| 1536 | 1536 | AstNode *node = ast_create_node(pc, NodeTypeVariableDeclaration, var_token); |
| 1537 | 1537 | |
| 1538 | node->data.variable_declaration.is_inline = is_inline; | |
| 1538 | node->data.variable_declaration.is_inline = is_comptime; | |
| 1539 | 1539 | node->data.variable_declaration.is_const = is_const; |
| 1540 | 1540 | node->data.variable_declaration.visib_mod = visib_mod; |
| 1541 | 1541 |
src/tokenizer.cpp+2| ... | ... | @@ -110,6 +110,7 @@ static const struct ZigKeyword zig_keywords[] = { |
| 110 | 110 | {"asm", TokenIdKeywordAsm}, |
| 111 | 111 | {"break", TokenIdKeywordBreak}, |
| 112 | 112 | {"coldcc", TokenIdKeywordColdCC}, |
| 113 | {"comptime", TokenIdKeywordCompTime}, | |
| 113 | 114 | {"const", TokenIdKeywordConst}, |
| 114 | 115 | {"continue", TokenIdKeywordContinue}, |
| 115 | 116 | {"defer", TokenIdKeywordDefer}, |
| ... | ... | @@ -1475,6 +1476,7 @@ const char * token_name(TokenId id) { |
| 1475 | 1476 | case TokenIdKeywordError: return "error"; |
| 1476 | 1477 | case TokenIdKeywordType: return "type"; |
| 1477 | 1478 | case TokenIdKeywordInline: return "inline"; |
| 1479 | case TokenIdKeywordCompTime: return "comptime"; | |
| 1478 | 1480 | case TokenIdKeywordDefer: return "defer"; |
| 1479 | 1481 | case TokenIdKeywordColdCC: return "coldcc"; |
| 1480 | 1482 | case TokenIdKeywordNakedCC: return "nakedcc"; |
src/tokenizer.hpp+1| ... | ... | @@ -43,6 +43,7 @@ enum TokenId { |
| 43 | 43 | TokenIdKeywordError, |
| 44 | 44 | TokenIdKeywordType, |
| 45 | 45 | TokenIdKeywordInline, |
| 46 | TokenIdKeywordCompTime, | |
| 46 | 47 | TokenIdKeywordDefer, |
| 47 | 48 | TokenIdKeywordThis, |
| 48 | 49 | TokenIdKeywordColdCC, |
std/bootstrap.zig+1-1| ... | ... | @@ -16,7 +16,7 @@ var argv: &&u8 = undefined; |
| 16 | 16 | export nakedcc fn _start() -> unreachable { |
| 17 | 17 | @setFnVisible(this, want_start_symbol); |
| 18 | 18 | |
| 19 | inline switch (@compileVar("arch")) { | |
| 19 | switch (@compileVar("arch")) { | |
| 20 | 20 | Arch.x86_64 => { |
| 21 | 21 | argc = asm("mov (%%rsp), %[argc]": [argc] "=r" (-> usize)); |
| 22 | 22 | argv = asm("lea 0x8(%%rsp), %[argv]": [argv] "=r" (-> &&u8)); |
std/debug.zig+1-1| ... | ... | @@ -241,7 +241,7 @@ fn parseFormValueRefLen(in_stream: &io.InStream, size: usize) -> %FormValue { |
| 241 | 241 | return FormValue.Ref { buf }; |
| 242 | 242 | } |
| 243 | 243 | |
| 244 | fn parseFormValueRef(in_stream: &io.InStream, inline T: type) -> %FormValue { | |
| 244 | fn parseFormValueRef(in_stream: &io.InStream, comptime T: type) -> %FormValue { | |
| 245 | 245 | const block_len = %return in_stream.readIntLe(T); |
| 246 | 246 | return parseFormValueRefLen(in_stream, block_len); |
| 247 | 247 | } |
std/endian.zig+4-4| ... | ... | @@ -1,16 +1,16 @@ |
| 1 | pub inline fn swapIfLe(inline T: type, x: T) -> T { | |
| 1 | pub inline fn swapIfLe(comptime T: type, x: T) -> T { | |
| 2 | 2 | swapIf(false, T, x) |
| 3 | 3 | } |
| 4 | 4 | |
| 5 | pub inline fn swapIfBe(inline T: type, x: T) -> T { | |
| 5 | pub inline fn swapIfBe(comptime T: type, x: T) -> T { | |
| 6 | 6 | swapIf(true, T, x) |
| 7 | 7 | } |
| 8 | 8 | |
| 9 | pub inline fn swapIf(is_be: bool, inline T: type, x: T) -> T { | |
| 9 | pub inline fn swapIf(is_be: bool, comptime T: type, x: T) -> T { | |
| 10 | 10 | if (@compileVar("is_big_endian") == is_be) swap(T, x) else x |
| 11 | 11 | } |
| 12 | 12 | |
| 13 | pub fn swap(inline T: type, x: T) -> T { | |
| 13 | pub fn swap(comptime T: type, x: T) -> T { | |
| 14 | 14 | const x_slice = ([]u8)((&const x)[0...1]); |
| 15 | 15 | var result: T = undefined; |
| 16 | 16 | const result_slice = ([]u8)((&result)[0...1]); |
std/hash_map.zig+2-2| ... | ... | @@ -7,8 +7,8 @@ const Allocator = mem.Allocator; |
| 7 | 7 | const want_modification_safety = !@compileVar("is_release"); |
| 8 | 8 | const debug_u32 = if (want_modification_safety) u32 else void; |
| 9 | 9 | |
| 10 | pub fn HashMap(inline K: type, inline V: type, inline hash: fn(key: K)->u32, | |
| 11 | inline eql: fn(a: K, b: K)->bool) -> type | |
| 10 | pub fn HashMap(comptime K: type, comptime V: type, comptime hash: fn(key: K)->u32, | |
| 11 | comptime eql: fn(a: K, b: K)->bool) -> type | |
| 12 | 12 | { |
| 13 | 13 | struct { |
| 14 | 14 | entries: []Entry, |
std/io.zig+9-9| ... | ... | @@ -105,7 +105,7 @@ pub const OutStream = struct { |
| 105 | 105 | return byte_count; |
| 106 | 106 | } |
| 107 | 107 | |
| 108 | pub fn printInt(self: &OutStream, inline T: type, x: T) -> %usize { | |
| 108 | pub fn printInt(self: &OutStream, comptime T: type, x: T) -> %usize { | |
| 109 | 109 | // TODO replace max_u64_base10_digits with math.log10(math.pow(2, @sizeOf(T))) |
| 110 | 110 | if (self.index + max_u64_base10_digits >= self.buffer.len) { |
| 111 | 111 | %return self.flush(); |
| ... | ... | @@ -255,22 +255,22 @@ pub const InStream = struct { |
| 255 | 255 | return result[0]; |
| 256 | 256 | } |
| 257 | 257 | |
| 258 | pub fn readIntLe(is: &InStream, inline T: type) -> %T { | |
| 258 | pub fn readIntLe(is: &InStream, comptime T: type) -> %T { | |
| 259 | 259 | is.readInt(false, T) |
| 260 | 260 | } |
| 261 | 261 | |
| 262 | pub fn readIntBe(is: &InStream, inline T: type) -> %T { | |
| 262 | pub fn readIntBe(is: &InStream, comptime T: type) -> %T { | |
| 263 | 263 | is.readInt(true, T) |
| 264 | 264 | } |
| 265 | 265 | |
| 266 | pub fn readInt(is: &InStream, is_be: bool, inline T: type) -> %T { | |
| 266 | pub fn readInt(is: &InStream, is_be: bool, comptime T: type) -> %T { | |
| 267 | 267 | var result: T = undefined; |
| 268 | 268 | const result_slice = ([]u8)((&result)[0...1]); |
| 269 | 269 | %return is.readNoEof(result_slice); |
| 270 | 270 | return endian.swapIf(!is_be, T, result); |
| 271 | 271 | } |
| 272 | 272 | |
| 273 | pub fn readVarInt(is: &InStream, is_be: bool, inline T: type, size: usize) -> %T { | |
| 273 | pub fn readVarInt(is: &InStream, is_be: bool, comptime T: type, size: usize) -> %T { | |
| 274 | 274 | assert(size <= @sizeOf(T)); |
| 275 | 275 | assert(size <= 8); |
| 276 | 276 | var input_buf: [8]u8 = undefined; |
| ... | ... | @@ -355,7 +355,7 @@ pub const InStream = struct { |
| 355 | 355 | } |
| 356 | 356 | }; |
| 357 | 357 | |
| 358 | pub fn parseUnsigned(inline T: type, buf: []u8, radix: u8) -> %T { | |
| 358 | pub fn parseUnsigned(comptime T: type, buf: []u8, radix: u8) -> %T { | |
| 359 | 359 | var x: T = 0; |
| 360 | 360 | |
| 361 | 361 | for (buf) |c| { |
| ... | ... | @@ -381,11 +381,11 @@ fn charToDigit(c: u8, radix: u8) -> %u8 { |
| 381 | 381 | return if (value >= radix) error.InvalidChar else value; |
| 382 | 382 | } |
| 383 | 383 | |
| 384 | pub fn bufPrintInt(inline T: type, out_buf: []u8, x: T) -> usize { | |
| 384 | pub fn bufPrintInt(comptime T: type, out_buf: []u8, x: T) -> usize { | |
| 385 | 385 | if (T.is_signed) bufPrintSigned(T, out_buf, x) else bufPrintUnsigned(T, out_buf, x) |
| 386 | 386 | } |
| 387 | 387 | |
| 388 | fn bufPrintSigned(inline T: type, out_buf: []u8, x: T) -> usize { | |
| 388 | fn bufPrintSigned(comptime T: type, out_buf: []u8, x: T) -> usize { | |
| 389 | 389 | const uint = @intType(false, T.bit_count); |
| 390 | 390 | if (x < 0) { |
| 391 | 391 | out_buf[0] = '-'; |
| ... | ... | @@ -395,7 +395,7 @@ fn bufPrintSigned(inline T: type, out_buf: []u8, x: T) -> usize { |
| 395 | 395 | } |
| 396 | 396 | } |
| 397 | 397 | |
| 398 | fn bufPrintUnsigned(inline T: type, out_buf: []u8, x: T) -> usize { | |
| 398 | fn bufPrintUnsigned(comptime T: type, out_buf: []u8, x: T) -> usize { | |
| 399 | 399 | var buf: [max_u64_base10_digits]u8 = undefined; |
| 400 | 400 | var a = x; |
| 401 | 401 | var index: usize = buf.len; |
std/list.zig+1-1| ... | ... | @@ -3,7 +3,7 @@ const assert = debug.assert; |
| 3 | 3 | const mem = @import("mem.zig"); |
| 4 | 4 | const Allocator = mem.Allocator; |
| 5 | 5 | |
| 6 | pub fn List(inline T: type) -> type{ | |
| 6 | pub fn List(comptime T: type) -> type{ | |
| 7 | 7 | struct { |
| 8 | 8 | const Self = this; |
| 9 | 9 |
std/math.zig+4-4| ... | ... | @@ -13,19 +13,19 @@ pub fn max(x: var, y: var) -> @typeOf(x + y) { |
| 13 | 13 | } |
| 14 | 14 | |
| 15 | 15 | error Overflow; |
| 16 | pub fn mulOverflow(inline T: type, a: T, b: T) -> %T { | |
| 16 | pub fn mulOverflow(comptime T: type, a: T, b: T) -> %T { | |
| 17 | 17 | var answer: T = undefined; |
| 18 | 18 | if (@mulWithOverflow(T, a, b, &answer)) error.Overflow else answer |
| 19 | 19 | } |
| 20 | pub fn addOverflow(inline T: type, a: T, b: T) -> %T { | |
| 20 | pub fn addOverflow(comptime T: type, a: T, b: T) -> %T { | |
| 21 | 21 | var answer: T = undefined; |
| 22 | 22 | if (@addWithOverflow(T, a, b, &answer)) error.Overflow else answer |
| 23 | 23 | } |
| 24 | pub fn subOverflow(inline T: type, a: T, b: T) -> %T { | |
| 24 | pub fn subOverflow(comptime T: type, a: T, b: T) -> %T { | |
| 25 | 25 | var answer: T = undefined; |
| 26 | 26 | if (@subWithOverflow(T, a, b, &answer)) error.Overflow else answer |
| 27 | 27 | } |
| 28 | pub fn shlOverflow(inline T: type, a: T, b: T) -> %T { | |
| 28 | pub fn shlOverflow(comptime T: type, a: T, b: T) -> %T { | |
| 29 | 29 | var answer: T = undefined; |
| 30 | 30 | if (@shlWithOverflow(T, a, b, &answer)) error.Overflow else answer |
| 31 | 31 | } |
std/mem.zig+8-8| ... | ... | @@ -15,7 +15,7 @@ pub const Allocator = struct { |
| 15 | 15 | context: ?&Context, |
| 16 | 16 | |
| 17 | 17 | /// Aborts the program if an allocation fails. |
| 18 | fn checkedAlloc(self: &Allocator, inline T: type, n: usize) -> []T { | |
| 18 | fn checkedAlloc(self: &Allocator, comptime T: type, n: usize) -> []T { | |
| 19 | 19 | alloc(self, T, n) %% |err| { |
| 20 | 20 | // TODO var args printf |
| 21 | 21 | %%io.stderr.write("allocation failure: "); |
| ... | ... | @@ -25,37 +25,37 @@ pub const Allocator = struct { |
| 25 | 25 | } |
| 26 | 26 | } |
| 27 | 27 | |
| 28 | fn alloc(self: &Allocator, inline T: type, n: usize) -> %[]T { | |
| 28 | fn alloc(self: &Allocator, comptime T: type, n: usize) -> %[]T { | |
| 29 | 29 | const byte_count = %return math.mulOverflow(usize, @sizeOf(T), n); |
| 30 | 30 | ([]T)(%return self.allocFn(self, byte_count)) |
| 31 | 31 | } |
| 32 | 32 | |
| 33 | fn realloc(self: &Allocator, inline T: type, old_mem: []T, n: usize) -> %[]T { | |
| 33 | fn realloc(self: &Allocator, comptime T: type, old_mem: []T, n: usize) -> %[]T { | |
| 34 | 34 | const byte_count = %return math.mulOverflow(usize, @sizeOf(T), n); |
| 35 | 35 | ([]T)(%return self.reallocFn(self, ([]u8)(old_mem), byte_count)) |
| 36 | 36 | } |
| 37 | 37 | |
| 38 | 38 | // TODO mem: []var and get rid of 2nd param |
| 39 | fn free(self: &Allocator, inline T: type, mem: []T) { | |
| 39 | fn free(self: &Allocator, comptime T: type, mem: []T) { | |
| 40 | 40 | self.freeFn(self, ([]u8)(mem)); |
| 41 | 41 | } |
| 42 | 42 | }; |
| 43 | 43 | |
| 44 | 44 | /// Copy all of source into dest at position 0. |
| 45 | 45 | /// dest.len must be >= source.len. |
| 46 | pub fn copy(inline T: type, dest: []T, source: []const T) { | |
| 46 | pub fn copy(comptime T: type, dest: []T, source: []const T) { | |
| 47 | 47 | @setDebugSafety(this, false); |
| 48 | 48 | assert(dest.len >= source.len); |
| 49 | 49 | for (source) |s, i| dest[i] = s; |
| 50 | 50 | } |
| 51 | 51 | |
| 52 | pub fn set(inline T: type, dest: []T, value: T) { | |
| 52 | pub fn set(comptime T: type, dest: []T, value: T) { | |
| 53 | 53 | for (dest) |*d| *d = value; |
| 54 | 54 | } |
| 55 | 55 | |
| 56 | 56 | /// Return < 0, == 0, or > 0 if memory a is less than, equal to, or greater than, |
| 57 | 57 | /// memory b, respectively. |
| 58 | pub fn cmp(inline T: type, a: []const T, b: []const T) -> Cmp { | |
| 58 | pub fn cmp(comptime T: type, a: []const T, b: []const T) -> Cmp { | |
| 59 | 59 | const n = math.min(a.len, b.len); |
| 60 | 60 | var i: usize = 0; |
| 61 | 61 | while (i < n; i += 1) { |
| ... | ... | @@ -66,7 +66,7 @@ pub fn cmp(inline T: type, a: []const T, b: []const T) -> Cmp { |
| 66 | 66 | return if (a.len > b.len) Cmp.Greater else if (a.len < b.len) Cmp.Less else Cmp.Equal; |
| 67 | 67 | } |
| 68 | 68 | |
| 69 | pub fn sliceAsInt(buf: []u8, is_be: bool, inline T: type) -> T { | |
| 69 | pub fn sliceAsInt(buf: []u8, is_be: bool, comptime T: type) -> T { | |
| 70 | 70 | var result: T = undefined; |
| 71 | 71 | const result_slice = ([]u8)((&result)[0...1]); |
| 72 | 72 | set(u8, result_slice, 0); |
std/rand.zig+9-9| ... | ... | @@ -29,7 +29,7 @@ pub const Rand = struct { |
| 29 | 29 | } |
| 30 | 30 | |
| 31 | 31 | /// Get an integer with random bits. |
| 32 | pub fn scalar(r: &Rand, inline T: type) -> T { | |
| 32 | pub fn scalar(r: &Rand, comptime T: type) -> T { | |
| 33 | 33 | if (T == usize) { |
| 34 | 34 | return r.rng.get(); |
| 35 | 35 | } else { |
| ... | ... | @@ -59,7 +59,7 @@ pub const Rand = struct { |
| 59 | 59 | /// Get a random unsigned integer with even distribution between `start` |
| 60 | 60 | /// inclusive and `end` exclusive. |
| 61 | 61 | // TODO support signed integers and then rename to "range" |
| 62 | pub fn rangeUnsigned(r: &Rand, inline T: type, start: T, end: T) -> T { | |
| 62 | pub fn rangeUnsigned(r: &Rand, comptime T: type, start: T, end: T) -> T { | |
| 63 | 63 | const range = end - start; |
| 64 | 64 | const leftover = @maxValue(T) % range; |
| 65 | 65 | const upper_bound = @maxValue(T) - leftover; |
| ... | ... | @@ -75,7 +75,7 @@ pub const Rand = struct { |
| 75 | 75 | } |
| 76 | 76 | |
| 77 | 77 | /// Get a floating point value in the range 0.0..1.0. |
| 78 | pub fn float(r: &Rand, inline T: type) -> T { | |
| 78 | pub fn float(r: &Rand, comptime T: type) -> T { | |
| 79 | 79 | // TODO Implement this way instead: |
| 80 | 80 | // const int = @int_type(false, @sizeOf(T) * 8); |
| 81 | 81 | // const mask = ((1 << @float_mantissa_bit_count(T)) - 1); |
| ... | ... | @@ -94,12 +94,12 @@ pub const Rand = struct { |
| 94 | 94 | }; |
| 95 | 95 | |
| 96 | 96 | fn MersenneTwister( |
| 97 | inline int: type, inline n: usize, inline m: usize, inline r: int, | |
| 98 | inline a: int, | |
| 99 | inline u: int, inline d: int, | |
| 100 | inline s: int, inline b: int, | |
| 101 | inline t: int, inline c: int, | |
| 102 | inline l: int, inline f: int) -> type | |
| 97 | comptime int: type, comptime n: usize, comptime m: usize, comptime r: int, | |
| 98 | comptime a: int, | |
| 99 | comptime u: int, comptime d: int, | |
| 100 | comptime s: int, comptime b: int, | |
| 101 | comptime t: int, comptime c: int, | |
| 102 | comptime l: int, comptime f: int) -> type | |
| 103 | 103 | { |
| 104 | 104 | struct { |
| 105 | 105 | const Self = this; |
std/sort.zig+2-2| ... | ... | @@ -5,13 +5,13 @@ const math = @import("math.zig"); |
| 5 | 5 | |
| 6 | 6 | pub const Cmp = math.Cmp; |
| 7 | 7 | |
| 8 | pub fn sort(inline T: type, array: []T, inline cmp: fn(a: &const T, b: &const T)->Cmp) { | |
| 8 | pub fn sort(comptime T: type, array: []T, comptime cmp: fn(a: &const T, b: &const T)->Cmp) { | |
| 9 | 9 | if (array.len > 0) { |
| 10 | 10 | quicksort(T, array, 0, array.len - 1, cmp); |
| 11 | 11 | } |
| 12 | 12 | } |
| 13 | 13 | |
| 14 | fn quicksort(inline T: type, array: []T, left: usize, right: usize, inline cmp: fn(a: &const T, b: &const T)->Cmp) { | |
| 14 | fn quicksort(comptime T: type, array: []T, left: usize, right: usize, comptime cmp: fn(a: &const T, b: &const T)->Cmp) { | |
| 15 | 15 | var i = left; |
| 16 | 16 | var j = right; |
| 17 | 17 | const p = (i + j) / 2; |
std/str.zig+1-1| ... | ... | @@ -4,7 +4,7 @@ pub fn eql(a: []const u8, b: []const u8) -> bool { |
| 4 | 4 | sliceEql(u8, a, b) |
| 5 | 5 | } |
| 6 | 6 | |
| 7 | pub fn sliceEql(inline T: type, a: []const T, b: []const T) -> bool { | |
| 7 | pub fn sliceEql(comptime T: type, a: []const T, b: []const T) -> bool { | |
| 8 | 8 | if (a.len != b.len) return false; |
| 9 | 9 | for (a) |item, index| { |
| 10 | 10 | if (b[index] != item) return false; |
test/cases/eval.zig+4-4| ... | ... | @@ -25,17 +25,17 @@ fn testStaticAddOne() { |
| 25 | 25 | fn inlinedLoop() { |
| 26 | 26 | @setFnTest(this); |
| 27 | 27 | |
| 28 | inline var i = 0; | |
| 29 | inline var sum = 0; | |
| 28 | comptime var i = 0; | |
| 29 | comptime var sum = 0; | |
| 30 | 30 | inline while (i <= 5; i += 1) |
| 31 | 31 | sum += i; |
| 32 | 32 | assert(sum == 15); |
| 33 | 33 | } |
| 34 | 34 | |
| 35 | fn gimme1or2(inline a: bool) -> i32 { | |
| 35 | fn gimme1or2(comptime a: bool) -> i32 { | |
| 36 | 36 | const x: i32 = 1; |
| 37 | 37 | const y: i32 = 2; |
| 38 | inline var z: i32 = if (a) x else y; | |
| 38 | comptime var z: i32 = if (a) x else y; | |
| 39 | 39 | return z; |
| 40 | 40 | } |
| 41 | 41 | fn inlineVariableGetsResultOfConstIf() { |
test/cases/generics.zig+8-8| ... | ... | @@ -8,11 +8,11 @@ fn simpleGenericFn() { |
| 8 | 8 | assert(add(2, 3) == 5); |
| 9 | 9 | } |
| 10 | 10 | |
| 11 | fn max(inline T: type, a: T, b: T) -> T { | |
| 11 | fn max(comptime T: type, a: T, b: T) -> T { | |
| 12 | 12 | return if (a > b) a else b; |
| 13 | 13 | } |
| 14 | 14 | |
| 15 | fn add(inline a: i32, b: i32) -> i32 { | |
| 15 | fn add(comptime a: i32, b: i32) -> i32 { | |
| 16 | 16 | return @staticEval(a) + b; |
| 17 | 17 | } |
| 18 | 18 | |
| ... | ... | @@ -67,11 +67,11 @@ fn max_f64(a: f64, b: f64) -> f64 { |
| 67 | 67 | } |
| 68 | 68 | |
| 69 | 69 | |
| 70 | pub fn List(inline T: type) -> type { | |
| 70 | pub fn List(comptime T: type) -> type { | |
| 71 | 71 | SmallList(T, 8) |
| 72 | 72 | } |
| 73 | 73 | |
| 74 | pub fn SmallList(inline T: type, inline STATIC_SIZE: usize) -> type { | |
| 74 | pub fn SmallList(comptime T: type, comptime STATIC_SIZE: usize) -> type { | |
| 75 | 75 | struct { |
| 76 | 76 | items: []T, |
| 77 | 77 | length: usize, |
| ... | ... | @@ -100,7 +100,7 @@ fn genericStruct() { |
| 100 | 100 | assert(a1.value == a1.getVal()); |
| 101 | 101 | assert(b1.getVal()); |
| 102 | 102 | } |
| 103 | fn GenNode(inline T: type) -> type { | |
| 103 | fn GenNode(comptime T: type) -> type { | |
| 104 | 104 | struct { |
| 105 | 105 | value: T, |
| 106 | 106 | next: ?&GenNode(T), |
| ... | ... | @@ -113,7 +113,7 @@ fn constDeclsInStruct() { |
| 113 | 113 | |
| 114 | 114 | assert(GenericDataThing(3).count_plus_one == 4); |
| 115 | 115 | } |
| 116 | fn GenericDataThing(inline count: isize) -> type { | |
| 116 | fn GenericDataThing(comptime count: isize) -> type { | |
| 117 | 117 | struct { |
| 118 | 118 | const count_plus_one = count + 1; |
| 119 | 119 | } |
| ... | ... | @@ -125,7 +125,7 @@ fn useGenericParamInGenericParam() { |
| 125 | 125 | |
| 126 | 126 | assert(aGenericFn(i32, 3, 4) == 7); |
| 127 | 127 | } |
| 128 | fn aGenericFn(inline T: type, inline a: T, b: T) -> T { | |
| 128 | fn aGenericFn(comptime T: type, comptime a: T, b: T) -> T { | |
| 129 | 129 | return a + b; |
| 130 | 130 | } |
| 131 | 131 | |
| ... | ... | @@ -137,6 +137,6 @@ fn genericFnWithImplicitCast() { |
| 137 | 137 | assert(getFirstByte(u16, []u16 {0, 13}) == 0); |
| 138 | 138 | } |
| 139 | 139 | fn getByte(ptr: ?&u8) -> u8 {*??ptr} |
| 140 | fn getFirstByte(inline T: type, mem: []T) -> u8 { | |
| 140 | fn getFirstByte(comptime T: type, mem: []T) -> u8 { | |
| 141 | 141 | getByte((&u8)(&mem[0])) |
| 142 | 142 | } |
test/cases/misc.zig+2-2| ... | ... | @@ -292,10 +292,10 @@ fn genericMallocFree() { |
| 292 | 292 | memFree(u8, a); |
| 293 | 293 | } |
| 294 | 294 | const some_mem : [100]u8 = undefined; |
| 295 | fn memAlloc(inline T: type, n: usize) -> %[]T { | |
| 295 | fn memAlloc(comptime T: type, n: usize) -> %[]T { | |
| 296 | 296 | return (&T)(&some_mem[0])[0...n]; |
| 297 | 297 | } |
| 298 | fn memFree(inline T: type, mem: []T) { } | |
| 298 | fn memFree(comptime T: type, mem: []T) { } | |
| 299 | 299 | |
| 300 | 300 | |
| 301 | 301 | fn castUndefined() { |
test/cases/this.zig+1-1| ... | ... | @@ -2,7 +2,7 @@ const assert = @import("std").debug.assert; |
| 2 | 2 | |
| 3 | 3 | const module = this; |
| 4 | 4 | |
| 5 | fn Point(inline T: type) -> type { | |
| 5 | fn Point(comptime T: type) -> type { | |
| 6 | 6 | struct { |
| 7 | 7 | const Self = this; |
| 8 | 8 | x: T, |
test/run_tests.cpp+9-9| ... | ... | @@ -1195,7 +1195,7 @@ const invalid = foo > foo; |
| 1195 | 1195 | )SOURCE", 1, ".tmp_source.zig:3:21: error: operator not allowed for type 'fn()'"); |
| 1196 | 1196 | |
| 1197 | 1197 | add_compile_fail_case("generic function instance with non-constant expression", R"SOURCE( |
| 1198 | fn foo(inline x: i32, y: i32) -> i32 { return x + y; } | |
| 1198 | fn foo(comptime x: i32, y: i32) -> i32 { return x + y; } | |
| 1199 | 1199 | fn test1(a: i32, b: i32) -> i32 { |
| 1200 | 1200 | return foo(a, b); |
| 1201 | 1201 | } |
| ... | ... | @@ -1407,18 +1407,18 @@ fn f() { |
| 1407 | 1407 | } |
| 1408 | 1408 | )SOURCE", 1, ".tmp_source.zig:3:13: error: unable to evaluate constant expression"); |
| 1409 | 1409 | |
| 1410 | add_compile_fail_case("export function with inline parameter", R"SOURCE( | |
| 1411 | export fn foo(inline x: i32, y: i32) -> i32{ | |
| 1410 | add_compile_fail_case("export function with comptime parameter", R"SOURCE( | |
| 1411 | export fn foo(comptime x: i32, y: i32) -> i32{ | |
| 1412 | 1412 | x + y |
| 1413 | 1413 | } |
| 1414 | )SOURCE", 1, ".tmp_source.zig:2:15: error: inline parameter not allowed in extern function"); | |
| 1414 | )SOURCE", 1, ".tmp_source.zig:2:15: error: comptime parameter not allowed in extern function"); | |
| 1415 | 1415 | |
| 1416 | add_compile_fail_case("extern function with inline parameter", R"SOURCE( | |
| 1417 | extern fn foo(inline x: i32, y: i32) -> i32; | |
| 1416 | add_compile_fail_case("extern function with comptime parameter", R"SOURCE( | |
| 1417 | extern fn foo(comptime x: i32, y: i32) -> i32; | |
| 1418 | 1418 | fn f() -> i32 { |
| 1419 | 1419 | foo(1, 2) |
| 1420 | 1420 | } |
| 1421 | )SOURCE", 1, ".tmp_source.zig:2:15: error: inline parameter not allowed in extern function"); | |
| 1421 | )SOURCE", 1, ".tmp_source.zig:2:15: error: comptime parameter not allowed in extern function"); | |
| 1422 | 1422 | |
| 1423 | 1423 | add_compile_fail_case("convert fixed size array to slice with invalid size", R"SOURCE( |
| 1424 | 1424 | fn f() { |
| ... | ... | @@ -1429,12 +1429,12 @@ fn f() { |
| 1429 | 1429 | |
| 1430 | 1430 | add_compile_fail_case("non-pure function returns type", R"SOURCE( |
| 1431 | 1431 | var a: u32 = 0; |
| 1432 | pub fn List(inline T: type) -> type { | |
| 1432 | pub fn List(comptime T: type) -> type { | |
| 1433 | 1433 | a += 1; |
| 1434 | 1434 | SmallList(T, 8) |
| 1435 | 1435 | } |
| 1436 | 1436 | |
| 1437 | pub fn SmallList(inline T: type, inline STATIC_SIZE: usize) -> type { | |
| 1437 | pub fn SmallList(comptime T: type, comptime STATIC_SIZE: usize) -> type { | |
| 1438 | 1438 | struct { |
| 1439 | 1439 | items: []T, |
| 1440 | 1440 | length: usize, |