authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2017-01-22 19:51:37-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2017-01-22 19:51:37-05:00
log47cf8520adb245dbd34ad60fc9206b7eaab5e0be
treee2859d84e1dbf803b63bd3ac11014f7b3709f467
parent6a5e61acd117277eb2f943f5bc02ff7043542d4b

use comptime instead of inline for var and params

See #221

22 files changed, 82 insertions(+), 79 deletions(-)

doc/langref.md+2-2
......@@ -15,7 +15,7 @@ ErrorValueDecl = "error" Symbol ";"
1515
1616GlobalVarDecl = VariableDeclaration ";"
1717
18VariableDeclaration = option("inline") ("var" | "const") Symbol option(":" TypeExpr) "=" Expression
18VariableDeclaration = option("comptime") ("var" | "const") Symbol option(":" TypeExpr) "=" Expression
1919
2020StructMember = (StructField | FnDef | GlobalVarDecl)
2121
......@@ -33,7 +33,7 @@ FnDef = option("inline" | "extern") FnProto Block
3333
3434ParamDeclList = "(" list(ParamDecl, ",") ")"
3535
36ParamDecl = option("noalias" | "inline") option(Symbol ":") TypeExpr | "..."
36ParamDecl = option("noalias" | "comptime") option(Symbol ":") TypeExpr | "..."
3737
3838Block = "{" list(option(Statement), ";") "}"
3939
doc/vim/syntax/zig.vim+1-1
......@@ -8,7 +8,7 @@ if exists("b:current_syntax")
88endif
99let b:current_syntax = "zig"
1010
11syn keyword zigStorage const var extern export pub noalias inline nakedcc coldcc
11syn keyword zigStorage const var extern export pub noalias inline comptime nakedcc coldcc
1212syn keyword zigStructure struct enum union
1313syn keyword zigStatement goto break return continue asm defer
1414syn 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
979979 if (param_is_inline) {
980980 if (fn_type_id.is_extern) {
981981 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"));
983983 return g->builtin_types.entry_invalid;
984984 }
985985 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
250250}
251251
252252/*
253ParamDecl = option("noalias" | "inline") option("Symbol" ":") TypeExpr | "..."
253ParamDecl = option("noalias" | "comptime") option(Symbol ":") TypeExpr | "..."
254254*/
255255static AstNode *ast_parse_param_decl(ParseContext *pc, size_t *token_index) {
256256 Token *token = &pc->tokens->at(*token_index);
......@@ -266,7 +266,7 @@ static AstNode *ast_parse_param_decl(ParseContext *pc, size_t *token_index) {
266266 node->data.param_decl.is_noalias = true;
267267 *token_index += 1;
268268 token = &pc->tokens->at(*token_index);
269 } else if (token->id == TokenIdKeywordInline) {
269 } else if (token->id == TokenIdKeywordCompTime) {
270270 node->data.param_decl.is_inline = true;
271271 *token_index += 1;
272272 token = &pc->tokens->at(*token_index);
......@@ -1492,7 +1492,7 @@ static AstNode *ast_parse_defer_expr(ParseContext *pc, size_t *token_index) {
14921492}
14931493
14941494/*
1495VariableDeclaration = option("inline") ("var" | "const") Symbol option(":" TypeExpr) "=" Expression
1495VariableDeclaration = option("comptime") ("var" | "const") Symbol option(":" TypeExpr) "=" Expression
14961496*/
14971497static AstNode *ast_parse_variable_declaration_expr(ParseContext *pc, size_t *token_index, bool mandatory,
14981498 VisibMod visib_mod)
......@@ -1501,9 +1501,9 @@ static AstNode *ast_parse_variable_declaration_expr(ParseContext *pc, size_t *to
15011501 Token *var_token;
15021502
15031503 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;
15071507 var_token = &pc->tokens->at(*token_index + 1);
15081508
15091509 if (var_token->id == TokenIdKeywordVar) {
......@@ -1518,12 +1518,12 @@ static AstNode *ast_parse_variable_declaration_expr(ParseContext *pc, size_t *to
15181518
15191519 *token_index += 2;
15201520 } else if (first_token->id == TokenIdKeywordVar) {
1521 is_inline = false;
1521 is_comptime = false;
15221522 is_const = false;
15231523 var_token = first_token;
15241524 *token_index += 1;
15251525 } else if (first_token->id == TokenIdKeywordConst) {
1526 is_inline = false;
1526 is_comptime = false;
15271527 is_const = true;
15281528 var_token = first_token;
15291529 *token_index += 1;
......@@ -1535,7 +1535,7 @@ static AstNode *ast_parse_variable_declaration_expr(ParseContext *pc, size_t *to
15351535
15361536 AstNode *node = ast_create_node(pc, NodeTypeVariableDeclaration, var_token);
15371537
1538 node->data.variable_declaration.is_inline = is_inline;
1538 node->data.variable_declaration.is_inline = is_comptime;
15391539 node->data.variable_declaration.is_const = is_const;
15401540 node->data.variable_declaration.visib_mod = visib_mod;
15411541
src/tokenizer.cpp+2
......@@ -110,6 +110,7 @@ static const struct ZigKeyword zig_keywords[] = {
110110 {"asm", TokenIdKeywordAsm},
111111 {"break", TokenIdKeywordBreak},
112112 {"coldcc", TokenIdKeywordColdCC},
113 {"comptime", TokenIdKeywordCompTime},
113114 {"const", TokenIdKeywordConst},
114115 {"continue", TokenIdKeywordContinue},
115116 {"defer", TokenIdKeywordDefer},
......@@ -1475,6 +1476,7 @@ const char * token_name(TokenId id) {
14751476 case TokenIdKeywordError: return "error";
14761477 case TokenIdKeywordType: return "type";
14771478 case TokenIdKeywordInline: return "inline";
1479 case TokenIdKeywordCompTime: return "comptime";
14781480 case TokenIdKeywordDefer: return "defer";
14791481 case TokenIdKeywordColdCC: return "coldcc";
14801482 case TokenIdKeywordNakedCC: return "nakedcc";
src/tokenizer.hpp+1
......@@ -43,6 +43,7 @@ enum TokenId {
4343 TokenIdKeywordError,
4444 TokenIdKeywordType,
4545 TokenIdKeywordInline,
46 TokenIdKeywordCompTime,
4647 TokenIdKeywordDefer,
4748 TokenIdKeywordThis,
4849 TokenIdKeywordColdCC,
std/bootstrap.zig+1-1
......@@ -16,7 +16,7 @@ var argv: &&u8 = undefined;
1616export nakedcc fn _start() -> unreachable {
1717 @setFnVisible(this, want_start_symbol);
1818
19 inline switch (@compileVar("arch")) {
19 switch (@compileVar("arch")) {
2020 Arch.x86_64 => {
2121 argc = asm("mov (%%rsp), %[argc]": [argc] "=r" (-> usize));
2222 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 {
241241 return FormValue.Ref { buf };
242242}
243243
244fn parseFormValueRef(in_stream: &io.InStream, inline T: type) -> %FormValue {
244fn parseFormValueRef(in_stream: &io.InStream, comptime T: type) -> %FormValue {
245245 const block_len = %return in_stream.readIntLe(T);
246246 return parseFormValueRefLen(in_stream, block_len);
247247}
std/endian.zig+4-4
......@@ -1,16 +1,16 @@
1pub inline fn swapIfLe(inline T: type, x: T) -> T {
1pub inline fn swapIfLe(comptime T: type, x: T) -> T {
22 swapIf(false, T, x)
33}
44
5pub inline fn swapIfBe(inline T: type, x: T) -> T {
5pub inline fn swapIfBe(comptime T: type, x: T) -> T {
66 swapIf(true, T, x)
77}
88
9pub inline fn swapIf(is_be: bool, inline T: type, x: T) -> T {
9pub inline fn swapIf(is_be: bool, comptime T: type, x: T) -> T {
1010 if (@compileVar("is_big_endian") == is_be) swap(T, x) else x
1111}
1212
13pub fn swap(inline T: type, x: T) -> T {
13pub fn swap(comptime T: type, x: T) -> T {
1414 const x_slice = ([]u8)((&const x)[0...1]);
1515 var result: T = undefined;
1616 const result_slice = ([]u8)((&result)[0...1]);
std/hash_map.zig+2-2
......@@ -7,8 +7,8 @@ const Allocator = mem.Allocator;
77const want_modification_safety = !@compileVar("is_release");
88const debug_u32 = if (want_modification_safety) u32 else void;
99
10pub fn HashMap(inline K: type, inline V: type, inline hash: fn(key: K)->u32,
11 inline eql: fn(a: K, b: K)->bool) -> type
10pub fn HashMap(comptime K: type, comptime V: type, comptime hash: fn(key: K)->u32,
11 comptime eql: fn(a: K, b: K)->bool) -> type
1212{
1313 struct {
1414 entries: []Entry,
std/io.zig+9-9
......@@ -105,7 +105,7 @@ pub const OutStream = struct {
105105 return byte_count;
106106 }
107107
108 pub fn printInt(self: &OutStream, inline T: type, x: T) -> %usize {
108 pub fn printInt(self: &OutStream, comptime T: type, x: T) -> %usize {
109109 // TODO replace max_u64_base10_digits with math.log10(math.pow(2, @sizeOf(T)))
110110 if (self.index + max_u64_base10_digits >= self.buffer.len) {
111111 %return self.flush();
......@@ -255,22 +255,22 @@ pub const InStream = struct {
255255 return result[0];
256256 }
257257
258 pub fn readIntLe(is: &InStream, inline T: type) -> %T {
258 pub fn readIntLe(is: &InStream, comptime T: type) -> %T {
259259 is.readInt(false, T)
260260 }
261261
262 pub fn readIntBe(is: &InStream, inline T: type) -> %T {
262 pub fn readIntBe(is: &InStream, comptime T: type) -> %T {
263263 is.readInt(true, T)
264264 }
265265
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 {
267267 var result: T = undefined;
268268 const result_slice = ([]u8)((&result)[0...1]);
269269 %return is.readNoEof(result_slice);
270270 return endian.swapIf(!is_be, T, result);
271271 }
272272
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 {
274274 assert(size <= @sizeOf(T));
275275 assert(size <= 8);
276276 var input_buf: [8]u8 = undefined;
......@@ -355,7 +355,7 @@ pub const InStream = struct {
355355 }
356356};
357357
358pub fn parseUnsigned(inline T: type, buf: []u8, radix: u8) -> %T {
358pub fn parseUnsigned(comptime T: type, buf: []u8, radix: u8) -> %T {
359359 var x: T = 0;
360360
361361 for (buf) |c| {
......@@ -381,11 +381,11 @@ fn charToDigit(c: u8, radix: u8) -> %u8 {
381381 return if (value >= radix) error.InvalidChar else value;
382382}
383383
384pub fn bufPrintInt(inline T: type, out_buf: []u8, x: T) -> usize {
384pub fn bufPrintInt(comptime T: type, out_buf: []u8, x: T) -> usize {
385385 if (T.is_signed) bufPrintSigned(T, out_buf, x) else bufPrintUnsigned(T, out_buf, x)
386386}
387387
388fn bufPrintSigned(inline T: type, out_buf: []u8, x: T) -> usize {
388fn bufPrintSigned(comptime T: type, out_buf: []u8, x: T) -> usize {
389389 const uint = @intType(false, T.bit_count);
390390 if (x < 0) {
391391 out_buf[0] = '-';
......@@ -395,7 +395,7 @@ fn bufPrintSigned(inline T: type, out_buf: []u8, x: T) -> usize {
395395 }
396396}
397397
398fn bufPrintUnsigned(inline T: type, out_buf: []u8, x: T) -> usize {
398fn bufPrintUnsigned(comptime T: type, out_buf: []u8, x: T) -> usize {
399399 var buf: [max_u64_base10_digits]u8 = undefined;
400400 var a = x;
401401 var index: usize = buf.len;
std/list.zig+1-1
......@@ -3,7 +3,7 @@ const assert = debug.assert;
33const mem = @import("mem.zig");
44const Allocator = mem.Allocator;
55
6pub fn List(inline T: type) -> type{
6pub fn List(comptime T: type) -> type{
77 struct {
88 const Self = this;
99
std/math.zig+4-4
......@@ -13,19 +13,19 @@ pub fn max(x: var, y: var) -> @typeOf(x + y) {
1313}
1414
1515error Overflow;
16pub fn mulOverflow(inline T: type, a: T, b: T) -> %T {
16pub fn mulOverflow(comptime T: type, a: T, b: T) -> %T {
1717 var answer: T = undefined;
1818 if (@mulWithOverflow(T, a, b, &answer)) error.Overflow else answer
1919}
20pub fn addOverflow(inline T: type, a: T, b: T) -> %T {
20pub fn addOverflow(comptime T: type, a: T, b: T) -> %T {
2121 var answer: T = undefined;
2222 if (@addWithOverflow(T, a, b, &answer)) error.Overflow else answer
2323}
24pub fn subOverflow(inline T: type, a: T, b: T) -> %T {
24pub fn subOverflow(comptime T: type, a: T, b: T) -> %T {
2525 var answer: T = undefined;
2626 if (@subWithOverflow(T, a, b, &answer)) error.Overflow else answer
2727}
28pub fn shlOverflow(inline T: type, a: T, b: T) -> %T {
28pub fn shlOverflow(comptime T: type, a: T, b: T) -> %T {
2929 var answer: T = undefined;
3030 if (@shlWithOverflow(T, a, b, &answer)) error.Overflow else answer
3131}
std/mem.zig+8-8
......@@ -15,7 +15,7 @@ pub const Allocator = struct {
1515 context: ?&Context,
1616
1717 /// 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 {
1919 alloc(self, T, n) %% |err| {
2020 // TODO var args printf
2121 %%io.stderr.write("allocation failure: ");
......@@ -25,37 +25,37 @@ pub const Allocator = struct {
2525 }
2626 }
2727
28 fn alloc(self: &Allocator, inline T: type, n: usize) -> %[]T {
28 fn alloc(self: &Allocator, comptime T: type, n: usize) -> %[]T {
2929 const byte_count = %return math.mulOverflow(usize, @sizeOf(T), n);
3030 ([]T)(%return self.allocFn(self, byte_count))
3131 }
3232
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 {
3434 const byte_count = %return math.mulOverflow(usize, @sizeOf(T), n);
3535 ([]T)(%return self.reallocFn(self, ([]u8)(old_mem), byte_count))
3636 }
3737
3838 // 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) {
4040 self.freeFn(self, ([]u8)(mem));
4141 }
4242};
4343
4444/// Copy all of source into dest at position 0.
4545/// dest.len must be >= source.len.
46pub fn copy(inline T: type, dest: []T, source: []const T) {
46pub fn copy(comptime T: type, dest: []T, source: []const T) {
4747 @setDebugSafety(this, false);
4848 assert(dest.len >= source.len);
4949 for (source) |s, i| dest[i] = s;
5050}
5151
52pub fn set(inline T: type, dest: []T, value: T) {
52pub fn set(comptime T: type, dest: []T, value: T) {
5353 for (dest) |*d| *d = value;
5454}
5555
5656/// Return < 0, == 0, or > 0 if memory a is less than, equal to, or greater than,
5757/// memory b, respectively.
58pub fn cmp(inline T: type, a: []const T, b: []const T) -> Cmp {
58pub fn cmp(comptime T: type, a: []const T, b: []const T) -> Cmp {
5959 const n = math.min(a.len, b.len);
6060 var i: usize = 0;
6161 while (i < n; i += 1) {
......@@ -66,7 +66,7 @@ pub fn cmp(inline T: type, a: []const T, b: []const T) -> Cmp {
6666 return if (a.len > b.len) Cmp.Greater else if (a.len < b.len) Cmp.Less else Cmp.Equal;
6767}
6868
69pub fn sliceAsInt(buf: []u8, is_be: bool, inline T: type) -> T {
69pub fn sliceAsInt(buf: []u8, is_be: bool, comptime T: type) -> T {
7070 var result: T = undefined;
7171 const result_slice = ([]u8)((&result)[0...1]);
7272 set(u8, result_slice, 0);
std/rand.zig+9-9
......@@ -29,7 +29,7 @@ pub const Rand = struct {
2929 }
3030
3131 /// 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 {
3333 if (T == usize) {
3434 return r.rng.get();
3535 } else {
......@@ -59,7 +59,7 @@ pub const Rand = struct {
5959 /// Get a random unsigned integer with even distribution between `start`
6060 /// inclusive and `end` exclusive.
6161 // 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 {
6363 const range = end - start;
6464 const leftover = @maxValue(T) % range;
6565 const upper_bound = @maxValue(T) - leftover;
......@@ -75,7 +75,7 @@ pub const Rand = struct {
7575 }
7676
7777 /// 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 {
7979 // TODO Implement this way instead:
8080 // const int = @int_type(false, @sizeOf(T) * 8);
8181 // const mask = ((1 << @float_mantissa_bit_count(T)) - 1);
......@@ -94,12 +94,12 @@ pub const Rand = struct {
9494};
9595
9696fn 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
103103{
104104 struct {
105105 const Self = this;
std/sort.zig+2-2
......@@ -5,13 +5,13 @@ const math = @import("math.zig");
55
66pub const Cmp = math.Cmp;
77
8pub fn sort(inline T: type, array: []T, inline cmp: fn(a: &const T, b: &const T)->Cmp) {
8pub fn sort(comptime T: type, array: []T, comptime cmp: fn(a: &const T, b: &const T)->Cmp) {
99 if (array.len > 0) {
1010 quicksort(T, array, 0, array.len - 1, cmp);
1111 }
1212}
1313
14fn quicksort(inline T: type, array: []T, left: usize, right: usize, inline cmp: fn(a: &const T, b: &const T)->Cmp) {
14fn quicksort(comptime T: type, array: []T, left: usize, right: usize, comptime cmp: fn(a: &const T, b: &const T)->Cmp) {
1515 var i = left;
1616 var j = right;
1717 const p = (i + j) / 2;
std/str.zig+1-1
......@@ -4,7 +4,7 @@ pub fn eql(a: []const u8, b: []const u8) -> bool {
44 sliceEql(u8, a, b)
55}
66
7pub fn sliceEql(inline T: type, a: []const T, b: []const T) -> bool {
7pub fn sliceEql(comptime T: type, a: []const T, b: []const T) -> bool {
88 if (a.len != b.len) return false;
99 for (a) |item, index| {
1010 if (b[index] != item) return false;
test/cases/eval.zig+4-4
......@@ -25,17 +25,17 @@ fn testStaticAddOne() {
2525fn inlinedLoop() {
2626 @setFnTest(this);
2727
28 inline var i = 0;
29 inline var sum = 0;
28 comptime var i = 0;
29 comptime var sum = 0;
3030 inline while (i <= 5; i += 1)
3131 sum += i;
3232 assert(sum == 15);
3333}
3434
35fn gimme1or2(inline a: bool) -> i32 {
35fn gimme1or2(comptime a: bool) -> i32 {
3636 const x: i32 = 1;
3737 const y: i32 = 2;
38 inline var z: i32 = if (a) x else y;
38 comptime var z: i32 = if (a) x else y;
3939 return z;
4040}
4141fn inlineVariableGetsResultOfConstIf() {
test/cases/generics.zig+8-8
......@@ -8,11 +8,11 @@ fn simpleGenericFn() {
88 assert(add(2, 3) == 5);
99}
1010
11fn max(inline T: type, a: T, b: T) -> T {
11fn max(comptime T: type, a: T, b: T) -> T {
1212 return if (a > b) a else b;
1313}
1414
15fn add(inline a: i32, b: i32) -> i32 {
15fn add(comptime a: i32, b: i32) -> i32 {
1616 return @staticEval(a) + b;
1717}
1818
......@@ -67,11 +67,11 @@ fn max_f64(a: f64, b: f64) -> f64 {
6767}
6868
6969
70pub fn List(inline T: type) -> type {
70pub fn List(comptime T: type) -> type {
7171 SmallList(T, 8)
7272}
7373
74pub fn SmallList(inline T: type, inline STATIC_SIZE: usize) -> type {
74pub fn SmallList(comptime T: type, comptime STATIC_SIZE: usize) -> type {
7575 struct {
7676 items: []T,
7777 length: usize,
......@@ -100,7 +100,7 @@ fn genericStruct() {
100100 assert(a1.value == a1.getVal());
101101 assert(b1.getVal());
102102}
103fn GenNode(inline T: type) -> type {
103fn GenNode(comptime T: type) -> type {
104104 struct {
105105 value: T,
106106 next: ?&GenNode(T),
......@@ -113,7 +113,7 @@ fn constDeclsInStruct() {
113113
114114 assert(GenericDataThing(3).count_plus_one == 4);
115115}
116fn GenericDataThing(inline count: isize) -> type {
116fn GenericDataThing(comptime count: isize) -> type {
117117 struct {
118118 const count_plus_one = count + 1;
119119 }
......@@ -125,7 +125,7 @@ fn useGenericParamInGenericParam() {
125125
126126 assert(aGenericFn(i32, 3, 4) == 7);
127127}
128fn aGenericFn(inline T: type, inline a: T, b: T) -> T {
128fn aGenericFn(comptime T: type, comptime a: T, b: T) -> T {
129129 return a + b;
130130}
131131
......@@ -137,6 +137,6 @@ fn genericFnWithImplicitCast() {
137137 assert(getFirstByte(u16, []u16 {0, 13}) == 0);
138138}
139139fn getByte(ptr: ?&u8) -> u8 {*??ptr}
140fn getFirstByte(inline T: type, mem: []T) -> u8 {
140fn getFirstByte(comptime T: type, mem: []T) -> u8 {
141141 getByte((&u8)(&mem[0]))
142142}
test/cases/misc.zig+2-2
......@@ -292,10 +292,10 @@ fn genericMallocFree() {
292292 memFree(u8, a);
293293}
294294const some_mem : [100]u8 = undefined;
295fn memAlloc(inline T: type, n: usize) -> %[]T {
295fn memAlloc(comptime T: type, n: usize) -> %[]T {
296296 return (&T)(&some_mem[0])[0...n];
297297}
298fn memFree(inline T: type, mem: []T) { }
298fn memFree(comptime T: type, mem: []T) { }
299299
300300
301301fn castUndefined() {
test/cases/this.zig+1-1
......@@ -2,7 +2,7 @@ const assert = @import("std").debug.assert;
22
33const module = this;
44
5fn Point(inline T: type) -> type {
5fn Point(comptime T: type) -> type {
66 struct {
77 const Self = this;
88 x: T,
test/run_tests.cpp+9-9
......@@ -1195,7 +1195,7 @@ const invalid = foo > foo;
11951195 )SOURCE", 1, ".tmp_source.zig:3:21: error: operator not allowed for type 'fn()'");
11961196
11971197 add_compile_fail_case("generic function instance with non-constant expression", R"SOURCE(
1198fn foo(inline x: i32, y: i32) -> i32 { return x + y; }
1198fn foo(comptime x: i32, y: i32) -> i32 { return x + y; }
11991199fn test1(a: i32, b: i32) -> i32 {
12001200 return foo(a, b);
12011201}
......@@ -1407,18 +1407,18 @@ fn f() {
14071407}
14081408 )SOURCE", 1, ".tmp_source.zig:3:13: error: unable to evaluate constant expression");
14091409
1410 add_compile_fail_case("export function with inline parameter", R"SOURCE(
1411export fn foo(inline x: i32, y: i32) -> i32{
1410 add_compile_fail_case("export function with comptime parameter", R"SOURCE(
1411export fn foo(comptime x: i32, y: i32) -> i32{
14121412 x + y
14131413}
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");
14151415
1416 add_compile_fail_case("extern function with inline parameter", R"SOURCE(
1417extern fn foo(inline x: i32, y: i32) -> i32;
1416 add_compile_fail_case("extern function with comptime parameter", R"SOURCE(
1417extern fn foo(comptime x: i32, y: i32) -> i32;
14181418fn f() -> i32 {
14191419 foo(1, 2)
14201420}
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");
14221422
14231423 add_compile_fail_case("convert fixed size array to slice with invalid size", R"SOURCE(
14241424fn f() {
......@@ -1429,12 +1429,12 @@ fn f() {
14291429
14301430 add_compile_fail_case("non-pure function returns type", R"SOURCE(
14311431var a: u32 = 0;
1432pub fn List(inline T: type) -> type {
1432pub fn List(comptime T: type) -> type {
14331433 a += 1;
14341434 SmallList(T, 8)
14351435}
14361436
1437pub fn SmallList(inline T: type, inline STATIC_SIZE: usize) -> type {
1437pub fn SmallList(comptime T: type, comptime STATIC_SIZE: usize) -> type {
14381438 struct {
14391439 items: []T,
14401440 length: usize,