authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-05-01 01:53:04-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-05-01 01:53:04-04:00
logac4d55dec1e32ddef945bfa246eb78f20f31ec44
tree31e91383c77a6b19f77e76096c38f5976161b9dd
parenta35b366eb64272c6d4646aedc035a837ed0c3cb0

behavior tests passing with new pointer deref syntax


19 files changed, 1132 insertions(+), 631 deletions(-)

std/array_list.zig+33-21
......@@ -8,7 +8,7 @@ pub fn ArrayList(comptime T: type) type {
88 return AlignedArrayList(T, @alignOf(T));
99}
1010
11pub fn AlignedArrayList(comptime T: type, comptime A: u29) type{
11pub fn AlignedArrayList(comptime T: type, comptime A: u29) type {
1212 return struct {
1313 const Self = this;
1414
......@@ -21,7 +21,7 @@ pub fn AlignedArrayList(comptime T: type, comptime A: u29) type{
2121
2222 /// Deinitialize with `deinit` or use `toOwnedSlice`.
2323 pub fn init(allocator: &Allocator) Self {
24 return Self {
24 return Self{
2525 .items = []align(A) T{},
2626 .len = 0,
2727 .allocator = allocator,
......@@ -48,7 +48,7 @@ pub fn AlignedArrayList(comptime T: type, comptime A: u29) type{
4848 /// allocated with `allocator`.
4949 /// Deinitialize with `deinit` or use `toOwnedSlice`.
5050 pub fn fromOwnedSlice(allocator: &Allocator, slice: []align(A) T) Self {
51 return Self {
51 return Self{
5252 .items = slice,
5353 .len = slice.len,
5454 .allocator = allocator,
......@@ -59,7 +59,7 @@ pub fn AlignedArrayList(comptime T: type, comptime A: u29) type{
5959 pub fn toOwnedSlice(self: &Self) []align(A) T {
6060 const allocator = self.allocator;
6161 const result = allocator.alignedShrink(T, A, self.items, self.len);
62 *self = init(allocator);
62 self.* = init(allocator);
6363 return result;
6464 }
6565
......@@ -67,21 +67,21 @@ pub fn AlignedArrayList(comptime T: type, comptime A: u29) type{
6767 try l.ensureCapacity(l.len + 1);
6868 l.len += 1;
6969
70 mem.copy(T, l.items[n+1..l.len], l.items[n..l.len-1]);
71 l.items[n] = *item;
70 mem.copy(T, l.items[n + 1..l.len], l.items[n..l.len - 1]);
71 l.items[n] = item.*;
7272 }
7373
7474 pub fn insertSlice(l: &Self, n: usize, items: []align(A) const T) !void {
7575 try l.ensureCapacity(l.len + items.len);
7676 l.len += items.len;
7777
78 mem.copy(T, l.items[n+items.len..l.len], l.items[n..l.len-items.len]);
79 mem.copy(T, l.items[n..n+items.len], items);
78 mem.copy(T, l.items[n + items.len..l.len], l.items[n..l.len - items.len]);
79 mem.copy(T, l.items[n..n + items.len], items);
8080 }
8181
8282 pub fn append(l: &Self, item: &const T) !void {
8383 const new_item_ptr = try l.addOne();
84 *new_item_ptr = *item;
84 new_item_ptr.* = item.*;
8585 }
8686
8787 pub fn appendSlice(l: &Self, items: []align(A) const T) !void {
......@@ -124,8 +124,7 @@ pub fn AlignedArrayList(comptime T: type, comptime A: u29) type{
124124 }
125125
126126 pub fn popOrNull(self: &Self) ?T {
127 if (self.len == 0)
128 return null;
127 if (self.len == 0) return null;
129128 return self.pop();
130129 }
131130 };
......@@ -135,25 +134,35 @@ test "basic ArrayList test" {
135134 var list = ArrayList(i32).init(debug.global_allocator);
136135 defer list.deinit();
137136
138 {var i: usize = 0; while (i < 10) : (i += 1) {
139 list.append(i32(i + 1)) catch unreachable;
140 }}
137 {
138 var i: usize = 0;
139 while (i < 10) : (i += 1) {
140 list.append(i32(i + 1)) catch unreachable;
141 }
142 }
141143
142 {var i: usize = 0; while (i < 10) : (i += 1) {
143 assert(list.items[i] == i32(i + 1));
144 }}
144 {
145 var i: usize = 0;
146 while (i < 10) : (i += 1) {
147 assert(list.items[i] == i32(i + 1));
148 }
149 }
145150
146151 assert(list.pop() == 10);
147152 assert(list.len == 9);
148153
149 list.appendSlice([]const i32 { 1, 2, 3 }) catch unreachable;
154 list.appendSlice([]const i32{
155 1,
156 2,
157 3,
158 }) catch unreachable;
150159 assert(list.len == 12);
151160 assert(list.pop() == 3);
152161 assert(list.pop() == 2);
153162 assert(list.pop() == 1);
154163 assert(list.len == 9);
155164
156 list.appendSlice([]const i32 {}) catch unreachable;
165 list.appendSlice([]const i32{}) catch unreachable;
157166 assert(list.len == 9);
158167}
159168
......@@ -166,12 +175,15 @@ test "insert ArrayList test" {
166175 assert(list.items[0] == 5);
167176 assert(list.items[1] == 1);
168177
169 try list.insertSlice(1, []const i32 { 9, 8 });
178 try list.insertSlice(1, []const i32{
179 9,
180 8,
181 });
170182 assert(list.items[0] == 5);
171183 assert(list.items[1] == 9);
172184 assert(list.items[2] == 8);
173185
174 const items = []const i32 { 1 };
186 const items = []const i32{1};
175187 try list.insertSlice(0, items[0..0]);
176188 assert(list.items[0] == 5);
177189}
std/fmt/index.zig+38-55
......@@ -11,9 +11,7 @@ const max_int_digits = 65;
1111/// Renders fmt string with args, calling output with slices of bytes.
1212/// If `output` returns an error, the error is returned from `format` and
1313/// `output` is not called again.
14pub fn format(context: var, comptime Errors: type, output: fn(@typeOf(context), []const u8) Errors!void,
15 comptime fmt: []const u8, args: ...) Errors!void
16{
14pub fn format(context: var, comptime Errors: type, output: fn(@typeOf(context), []const u8) Errors!void, comptime fmt: []const u8, args: ...) Errors!void {
1715 const State = enum {
1816 Start,
1917 OpenBrace,
......@@ -221,7 +219,7 @@ pub fn format(context: var, comptime Errors: type, output: fn(@typeOf(context),
221219 }
222220}
223221
224pub fn formatValue(value: var, context: var, comptime Errors: type, output: fn(@typeOf(context), []const u8)Errors!void) Errors!void {
222pub fn formatValue(value: var, context: var, comptime Errors: type, output: fn(@typeOf(context), []const u8) Errors!void) Errors!void {
225223 const T = @typeOf(value);
226224 switch (@typeId(T)) {
227225 builtin.TypeId.Int => {
......@@ -256,7 +254,7 @@ pub fn formatValue(value: var, context: var, comptime Errors: type, output: fn(@
256254 },
257255 builtin.TypeId.Pointer => {
258256 if (@typeId(T.Child) == builtin.TypeId.Array and T.Child.Child == u8) {
259 return output(context, (*value)[0..]);
257 return output(context, (value.*)[0..]);
260258 } else {
261259 return format(context, Errors, output, "{}@{x}", @typeName(T.Child), @ptrToInt(value));
262260 }
......@@ -270,13 +268,11 @@ pub fn formatValue(value: var, context: var, comptime Errors: type, output: fn(@
270268 }
271269}
272270
273pub fn formatAsciiChar(c: u8, context: var, comptime Errors: type, output: fn(@typeOf(context), []const u8)Errors!void) Errors!void {
271pub fn formatAsciiChar(c: u8, context: var, comptime Errors: type, output: fn(@typeOf(context), []const u8) Errors!void) Errors!void {
274272 return output(context, (&c)[0..1]);
275273}
276274
277pub fn formatBuf(buf: []const u8, width: usize,
278 context: var, comptime Errors: type, output: fn(@typeOf(context), []const u8)Errors!void) Errors!void
279{
275pub fn formatBuf(buf: []const u8, width: usize, context: var, comptime Errors: type, output: fn(@typeOf(context), []const u8) Errors!void) Errors!void {
280276 try output(context, buf);
281277
282278 var leftover_padding = if (width > buf.len) (width - buf.len) else return;
......@@ -289,7 +285,7 @@ pub fn formatBuf(buf: []const u8, width: usize,
289285// Print a float in scientific notation to the specified precision. Null uses full precision.
290286// It should be the case that every full precision, printed value can be re-parsed back to the
291287// same type unambiguously.
292pub fn formatFloatScientific(value: var, maybe_precision: ?usize, context: var, comptime Errors: type, output: fn(@typeOf(context), []const u8)Errors!void) Errors!void {
288pub fn formatFloatScientific(value: var, maybe_precision: ?usize, context: var, comptime Errors: type, output: fn(@typeOf(context), []const u8) Errors!void) Errors!void {
293289 var x = f64(value);
294290
295291 // Errol doesn't handle these special cases.
......@@ -338,7 +334,7 @@ pub fn formatFloatScientific(value: var, maybe_precision: ?usize, context: var,
338334 var printed: usize = 0;
339335 if (float_decimal.digits.len > 1) {
340336 const num_digits = math.min(float_decimal.digits.len, precision + 1);
341 try output(context, float_decimal.digits[1 .. num_digits]);
337 try output(context, float_decimal.digits[1..num_digits]);
342338 printed += num_digits - 1;
343339 }
344340
......@@ -350,12 +346,9 @@ pub fn formatFloatScientific(value: var, maybe_precision: ?usize, context: var,
350346 try output(context, float_decimal.digits[0..1]);
351347 try output(context, ".");
352348 if (float_decimal.digits.len > 1) {
353 const num_digits = if (@typeOf(value) == f32)
354 math.min(usize(9), float_decimal.digits.len)
355 else
356 float_decimal.digits.len;
349 const num_digits = if (@typeOf(value) == f32) math.min(usize(9), float_decimal.digits.len) else float_decimal.digits.len;
357350
358 try output(context, float_decimal.digits[1 .. num_digits]);
351 try output(context, float_decimal.digits[1..num_digits]);
359352 } else {
360353 try output(context, "0");
361354 }
......@@ -381,7 +374,7 @@ pub fn formatFloatScientific(value: var, maybe_precision: ?usize, context: var,
381374
382375// Print a float of the format x.yyyyy where the number of y is specified by the precision argument.
383376// By default floats are printed at full precision (no rounding).
384pub fn formatFloatDecimal(value: var, maybe_precision: ?usize, context: var, comptime Errors: type, output: fn(@typeOf(context), []const u8)Errors!void) Errors!void {
377pub fn formatFloatDecimal(value: var, maybe_precision: ?usize, context: var, comptime Errors: type, output: fn(@typeOf(context), []const u8) Errors!void) Errors!void {
385378 var x = f64(value);
386379
387380 // Errol doesn't handle these special cases.
......@@ -431,14 +424,14 @@ pub fn formatFloatDecimal(value: var, maybe_precision: ?usize, context: var, com
431424
432425 if (num_digits_whole > 0) {
433426 // We may have to zero pad, for instance 1e4 requires zero padding.
434 try output(context, float_decimal.digits[0 .. num_digits_whole_no_pad]);
427 try output(context, float_decimal.digits[0..num_digits_whole_no_pad]);
435428
436429 var i = num_digits_whole_no_pad;
437430 while (i < num_digits_whole) : (i += 1) {
438431 try output(context, "0");
439432 }
440433 } else {
441 try output(context , "0");
434 try output(context, "0");
442435 }
443436
444437 // {.0} special case doesn't want a trailing '.'
......@@ -470,10 +463,10 @@ pub fn formatFloatDecimal(value: var, maybe_precision: ?usize, context: var, com
470463 // Remaining fractional portion, zero-padding if insufficient.
471464 debug.assert(precision >= printed);
472465 if (num_digits_whole_no_pad + precision - printed < float_decimal.digits.len) {
473 try output(context, float_decimal.digits[num_digits_whole_no_pad .. num_digits_whole_no_pad + precision - printed]);
466 try output(context, float_decimal.digits[num_digits_whole_no_pad..num_digits_whole_no_pad + precision - printed]);
474467 return;
475468 } else {
476 try output(context, float_decimal.digits[num_digits_whole_no_pad ..]);
469 try output(context, float_decimal.digits[num_digits_whole_no_pad..]);
477470 printed += float_decimal.digits.len - num_digits_whole_no_pad;
478471
479472 while (printed < precision) : (printed += 1) {
......@@ -489,14 +482,14 @@ pub fn formatFloatDecimal(value: var, maybe_precision: ?usize, context: var, com
489482
490483 if (num_digits_whole > 0) {
491484 // We may have to zero pad, for instance 1e4 requires zero padding.
492 try output(context, float_decimal.digits[0 .. num_digits_whole_no_pad]);
485 try output(context, float_decimal.digits[0..num_digits_whole_no_pad]);
493486
494487 var i = num_digits_whole_no_pad;
495488 while (i < num_digits_whole) : (i += 1) {
496489 try output(context, "0");
497490 }
498491 } else {
499 try output(context , "0");
492 try output(context, "0");
500493 }
501494
502495 // Omit `.` if no fractional portion
......@@ -516,14 +509,11 @@ pub fn formatFloatDecimal(value: var, maybe_precision: ?usize, context: var, com
516509 }
517510 }
518511
519 try output(context, float_decimal.digits[num_digits_whole_no_pad ..]);
512 try output(context, float_decimal.digits[num_digits_whole_no_pad..]);
520513 }
521514}
522515
523
524pub fn formatInt(value: var, base: u8, uppercase: bool, width: usize,
525 context: var, comptime Errors: type, output: fn(@typeOf(context), []const u8)Errors!void) Errors!void
526{
516pub fn formatInt(value: var, base: u8, uppercase: bool, width: usize, context: var, comptime Errors: type, output: fn(@typeOf(context), []const u8) Errors!void) Errors!void {
527517 if (@typeOf(value).is_signed) {
528518 return formatIntSigned(value, base, uppercase, width, context, Errors, output);
529519 } else {
......@@ -531,9 +521,7 @@ pub fn formatInt(value: var, base: u8, uppercase: bool, width: usize,
531521 }
532522}
533523
534fn formatIntSigned(value: var, base: u8, uppercase: bool, width: usize,
535 context: var, comptime Errors: type, output: fn(@typeOf(context), []const u8)Errors!void) Errors!void
536{
524fn formatIntSigned(value: var, base: u8, uppercase: bool, width: usize, context: var, comptime Errors: type, output: fn(@typeOf(context), []const u8) Errors!void) Errors!void {
537525 const uint = @IntType(false, @typeOf(value).bit_count);
538526 if (value < 0) {
539527 const minus_sign: u8 = '-';
......@@ -552,9 +540,7 @@ fn formatIntSigned(value: var, base: u8, uppercase: bool, width: usize,
552540 }
553541}
554542
555fn formatIntUnsigned(value: var, base: u8, uppercase: bool, width: usize,
556 context: var, comptime Errors: type, output: fn(@typeOf(context), []const u8)Errors!void) Errors!void
557{
543fn formatIntUnsigned(value: var, base: u8, uppercase: bool, width: usize, context: var, comptime Errors: type, output: fn(@typeOf(context), []const u8) Errors!void) Errors!void {
558544 // max_int_digits accounts for the minus sign. when printing an unsigned
559545 // number we don't need to do that.
560546 var buf: [max_int_digits - 1]u8 = undefined;
......@@ -566,8 +552,7 @@ fn formatIntUnsigned(value: var, base: u8, uppercase: bool, width: usize,
566552 index -= 1;
567553 buf[index] = digitToChar(u8(digit), uppercase);
568554 a /= base;
569 if (a == 0)
570 break;
555 if (a == 0) break;
571556 }
572557
573558 const digits_buf = buf[index..];
......@@ -579,8 +564,7 @@ fn formatIntUnsigned(value: var, base: u8, uppercase: bool, width: usize,
579564 while (true) {
580565 try output(context, (&zero_byte)[0..1]);
581566 leftover_padding -= 1;
582 if (leftover_padding == 0)
583 break;
567 if (leftover_padding == 0) break;
584568 }
585569 mem.set(u8, buf[0..index], '0');
586570 return output(context, buf);
......@@ -592,7 +576,7 @@ fn formatIntUnsigned(value: var, base: u8, uppercase: bool, width: usize,
592576}
593577
594578pub fn formatIntBuf(out_buf: []u8, value: var, base: u8, uppercase: bool, width: usize) usize {
595 var context = FormatIntBuf {
579 var context = FormatIntBuf{
596580 .out_buf = out_buf,
597581 .index = 0,
598582 };
......@@ -609,10 +593,8 @@ fn formatIntCallback(context: &FormatIntBuf, bytes: []const u8) (error{}!void) {
609593}
610594
611595pub fn parseInt(comptime T: type, buf: []const u8, radix: u8) !T {
612 if (!T.is_signed)
613 return parseUnsigned(T, buf, radix);
614 if (buf.len == 0)
615 return T(0);
596 if (!T.is_signed) return parseUnsigned(T, buf, radix);
597 if (buf.len == 0) return T(0);
616598 if (buf[0] == '-') {
617599 return math.negate(try parseUnsigned(T, buf[1..], radix));
618600 } else if (buf[0] == '+') {
......@@ -632,9 +614,10 @@ test "fmt.parseInt" {
632614 assert(if (parseInt(u8, "256", 10)) |_| false else |err| err == error.Overflow);
633615}
634616
635const ParseUnsignedError = error {
617const ParseUnsignedError = error{
636618 /// The result cannot fit in the type specified
637619 Overflow,
620
638621 /// The input had a byte that was not a digit
639622 InvalidCharacter,
640623};
......@@ -659,8 +642,7 @@ pub fn charToDigit(c: u8, radix: u8) (error{InvalidCharacter}!u8) {
659642 else => return error.InvalidCharacter,
660643 };
661644
662 if (value >= radix)
663 return error.InvalidCharacter;
645 if (value >= radix) return error.InvalidCharacter;
664646
665647 return value;
666648}
......@@ -684,20 +666,21 @@ fn bufPrintWrite(context: &BufPrintContext, bytes: []const u8) !void {
684666}
685667
686668pub fn bufPrint(buf: []u8, comptime fmt: []const u8, args: ...) ![]u8 {
687 var context = BufPrintContext { .remaining = buf, };
669 var context = BufPrintContext{ .remaining = buf };
688670 try format(&context, error{BufferTooSmall}, bufPrintWrite, fmt, args);
689671 return buf[0..buf.len - context.remaining.len];
690672}
691673
692674pub fn allocPrint(allocator: &mem.Allocator, comptime fmt: []const u8, args: ...) ![]u8 {
693675 var size: usize = 0;
694 format(&size, error{}, countSize, fmt, args) catch |err| switch (err) {};
676 format(&size, error{}, countSize, fmt, args) catch |err| switch (err) {
677 };
695678 const buf = try allocator.alloc(u8, size);
696679 return bufPrint(buf, fmt, args);
697680}
698681
699682fn countSize(size: &usize, bytes: []const u8) (error{}!void) {
700 *size += bytes.len;
683 size.* += bytes.len;
701684}
702685
703686test "buf print int" {
......@@ -773,9 +756,7 @@ test "fmt.format" {
773756 unused: u8,
774757 };
775758 var buf1: [32]u8 = undefined;
776 const value = Struct {
777 .unused = 42,
778 };
759 const value = Struct{ .unused = 42 };
779760 const result = try bufPrint(buf1[0..], "pointer: {}\n", &value);
780761 assert(mem.startsWith(u8, result, "pointer: Struct@"));
781762 }
......@@ -988,7 +969,7 @@ test "fmt.format" {
988969
989970pub fn trim(buf: []const u8) []const u8 {
990971 var start: usize = 0;
991 while (start < buf.len and isWhiteSpace(buf[start])) : (start += 1) { }
972 while (start < buf.len and isWhiteSpace(buf[start])) : (start += 1) {}
992973
993974 var end: usize = buf.len;
994975 while (true) {
......@@ -1000,7 +981,6 @@ pub fn trim(buf: []const u8) []const u8 {
1000981 }
1001982 }
1002983 break;
1003
1004984 }
1005985 return buf[start..end];
1006986}
......@@ -1015,7 +995,10 @@ test "fmt.trim" {
1015995
1016996pub fn isWhiteSpace(byte: u8) bool {
1017997 return switch (byte) {
1018 ' ', '\t', '\n', '\r' => true,
998 ' ',
999 '\t',
1000 '\n',
1001 '\r' => true,
10191002 else => false,
10201003 };
10211004}
std/heap.zig+52-54
......@@ -10,7 +10,7 @@ const c = std.c;
1010const Allocator = mem.Allocator;
1111
1212pub const c_allocator = &c_allocator_state;
13var c_allocator_state = Allocator {
13var c_allocator_state = Allocator{
1414 .allocFn = cAlloc,
1515 .reallocFn = cRealloc,
1616 .freeFn = cFree,
......@@ -18,10 +18,7 @@ var c_allocator_state = Allocator {
1818
1919fn cAlloc(self: &Allocator, n: usize, alignment: u29) ![]u8 {
2020 assert(alignment <= @alignOf(c_longdouble));
21 return if (c.malloc(n)) |buf|
22 @ptrCast(&u8, buf)[0..n]
23 else
24 error.OutOfMemory;
21 return if (c.malloc(n)) |buf| @ptrCast(&u8, buf)[0..n] else error.OutOfMemory;
2522}
2623
2724fn cRealloc(self: &Allocator, old_mem: []u8, new_size: usize, alignment: u29) ![]u8 {
......@@ -48,8 +45,8 @@ pub const DirectAllocator = struct {
4845 const HeapHandle = if (builtin.os == Os.windows) os.windows.HANDLE else void;
4946
5047 pub fn init() DirectAllocator {
51 return DirectAllocator {
52 .allocator = Allocator {
48 return DirectAllocator{
49 .allocator = Allocator{
5350 .allocFn = alloc,
5451 .reallocFn = realloc,
5552 .freeFn = free,
......@@ -71,39 +68,39 @@ pub const DirectAllocator = struct {
7168 const self = @fieldParentPtr(DirectAllocator, "allocator", allocator);
7269
7370 switch (builtin.os) {
74 Os.linux, Os.macosx, Os.ios => {
71 Os.linux,
72 Os.macosx,
73 Os.ios => {
7574 const p = os.posix;
76 const alloc_size = if(alignment <= os.page_size) n else n + alignment;
77 const addr = p.mmap(null, alloc_size, p.PROT_READ|p.PROT_WRITE,
78 p.MAP_PRIVATE|p.MAP_ANONYMOUS, -1, 0);
79 if(addr == p.MAP_FAILED) return error.OutOfMemory;
80
81 if(alloc_size == n) return @intToPtr(&u8, addr)[0..n];
82
75 const alloc_size = if (alignment <= os.page_size) n else n + alignment;
76 const addr = p.mmap(null, alloc_size, p.PROT_READ | p.PROT_WRITE, p.MAP_PRIVATE | p.MAP_ANONYMOUS, -1, 0);
77 if (addr == p.MAP_FAILED) return error.OutOfMemory;
78
79 if (alloc_size == n) return @intToPtr(&u8, addr)[0..n];
80
8381 var aligned_addr = addr & ~usize(alignment - 1);
8482 aligned_addr += alignment;
85
83
8684 //We can unmap the unused portions of our mmap, but we must only
8785 // pass munmap bytes that exist outside our allocated pages or it
8886 // will happily eat us too
89
87
9088 //Since alignment > page_size, we are by definition on a page boundry
9189 const unused_start = addr;
9290 const unused_len = aligned_addr - 1 - unused_start;
9391
9492 var err = p.munmap(unused_start, unused_len);
9593 debug.assert(p.getErrno(err) == 0);
96
94
9795 //It is impossible that there is an unoccupied page at the top of our
9896 // mmap.
99
97
10098 return @intToPtr(&u8, aligned_addr)[0..n];
10199 },
102100 Os.windows => {
103101 const amt = n + alignment + @sizeOf(usize);
104102 const heap_handle = self.heap_handle ?? blk: {
105 const hh = os.windows.HeapCreate(os.windows.HEAP_NO_SERIALIZE, amt, 0)
106 ?? return error.OutOfMemory;
103 const hh = os.windows.HeapCreate(os.windows.HEAP_NO_SERIALIZE, amt, 0) ?? return error.OutOfMemory;
107104 self.heap_handle = hh;
108105 break :blk hh;
109106 };
......@@ -113,7 +110,7 @@ pub const DirectAllocator = struct {
113110 const march_forward_bytes = if (rem == 0) 0 else (alignment - rem);
114111 const adjusted_addr = root_addr + march_forward_bytes;
115112 const record_addr = adjusted_addr + n;
116 *@intToPtr(&align(1) usize, record_addr) = root_addr;
113 @intToPtr(&align(1) usize, record_addr).* = root_addr;
117114 return @intToPtr(&u8, adjusted_addr)[0..n];
118115 },
119116 else => @compileError("Unsupported OS"),
......@@ -124,7 +121,9 @@ pub const DirectAllocator = struct {
124121 const self = @fieldParentPtr(DirectAllocator, "allocator", allocator);
125122
126123 switch (builtin.os) {
127 Os.linux, Os.macosx, Os.ios => {
124 Os.linux,
125 Os.macosx,
126 Os.ios => {
128127 if (new_size <= old_mem.len) {
129128 const base_addr = @ptrToInt(old_mem.ptr);
130129 const old_addr_end = base_addr + old_mem.len;
......@@ -144,13 +143,13 @@ pub const DirectAllocator = struct {
144143 Os.windows => {
145144 const old_adjusted_addr = @ptrToInt(old_mem.ptr);
146145 const old_record_addr = old_adjusted_addr + old_mem.len;
147 const root_addr = *@intToPtr(&align(1) usize, old_record_addr);
146 const root_addr = @intToPtr(&align(1) usize, old_record_addr).*;
148147 const old_ptr = @intToPtr(os.windows.LPVOID, root_addr);
149148 const amt = new_size + alignment + @sizeOf(usize);
150149 const new_ptr = os.windows.HeapReAlloc(??self.heap_handle, 0, old_ptr, amt) ?? blk: {
151150 if (new_size > old_mem.len) return error.OutOfMemory;
152151 const new_record_addr = old_record_addr - new_size + old_mem.len;
153 *@intToPtr(&align(1) usize, new_record_addr) = root_addr;
152 @intToPtr(&align(1) usize, new_record_addr).* = root_addr;
154153 return old_mem[0..new_size];
155154 };
156155 const offset = old_adjusted_addr - root_addr;
......@@ -158,7 +157,7 @@ pub const DirectAllocator = struct {
158157 const new_adjusted_addr = new_root_addr + offset;
159158 assert(new_adjusted_addr % alignment == 0);
160159 const new_record_addr = new_adjusted_addr + new_size;
161 *@intToPtr(&align(1) usize, new_record_addr) = new_root_addr;
160 @intToPtr(&align(1) usize, new_record_addr).* = new_root_addr;
162161 return @intToPtr(&u8, new_adjusted_addr)[0..new_size];
163162 },
164163 else => @compileError("Unsupported OS"),
......@@ -169,12 +168,14 @@ pub const DirectAllocator = struct {
169168 const self = @fieldParentPtr(DirectAllocator, "allocator", allocator);
170169
171170 switch (builtin.os) {
172 Os.linux, Os.macosx, Os.ios => {
171 Os.linux,
172 Os.macosx,
173 Os.ios => {
173174 _ = os.posix.munmap(@ptrToInt(bytes.ptr), bytes.len);
174175 },
175176 Os.windows => {
176177 const record_addr = @ptrToInt(bytes.ptr) + bytes.len;
177 const root_addr = *@intToPtr(&align(1) usize, record_addr);
178 const root_addr = @intToPtr(&align(1) usize, record_addr).*;
178179 const ptr = @intToPtr(os.windows.LPVOID, root_addr);
179180 _ = os.windows.HeapFree(??self.heap_handle, 0, ptr);
180181 },
......@@ -195,8 +196,8 @@ pub const ArenaAllocator = struct {
195196 const BufNode = std.LinkedList([]u8).Node;
196197
197198 pub fn init(child_allocator: &Allocator) ArenaAllocator {
198 return ArenaAllocator {
199 .allocator = Allocator {
199 return ArenaAllocator{
200 .allocator = Allocator{
200201 .allocFn = alloc,
201202 .reallocFn = realloc,
202203 .freeFn = free,
......@@ -228,7 +229,7 @@ pub const ArenaAllocator = struct {
228229 const buf = try self.child_allocator.alignedAlloc(u8, @alignOf(BufNode), len);
229230 const buf_node_slice = ([]BufNode)(buf[0..@sizeOf(BufNode)]);
230231 const buf_node = &buf_node_slice[0];
231 *buf_node = BufNode {
232 buf_node.* = BufNode{
232233 .data = buf,
233234 .prev = null,
234235 .next = null,
......@@ -253,7 +254,7 @@ pub const ArenaAllocator = struct {
253254 cur_node = try self.createNode(cur_buf.len, n + alignment);
254255 continue;
255256 }
256 const result = cur_buf[adjusted_index .. new_end_index];
257 const result = cur_buf[adjusted_index..new_end_index];
257258 self.end_index = new_end_index;
258259 return result;
259260 }
......@@ -269,7 +270,7 @@ pub const ArenaAllocator = struct {
269270 }
270271 }
271272
272 fn free(allocator: &Allocator, bytes: []u8) void { }
273 fn free(allocator: &Allocator, bytes: []u8) void {}
273274};
274275
275276pub const FixedBufferAllocator = struct {
......@@ -278,8 +279,8 @@ pub const FixedBufferAllocator = struct {
278279 buffer: []u8,
279280
280281 pub fn init(buffer: []u8) FixedBufferAllocator {
281 return FixedBufferAllocator {
282 .allocator = Allocator {
282 return FixedBufferAllocator{
283 .allocator = Allocator{
283284 .allocFn = alloc,
284285 .reallocFn = realloc,
285286 .freeFn = free,
......@@ -299,7 +300,7 @@ pub const FixedBufferAllocator = struct {
299300 if (new_end_index > self.buffer.len) {
300301 return error.OutOfMemory;
301302 }
302 const result = self.buffer[adjusted_index .. new_end_index];
303 const result = self.buffer[adjusted_index..new_end_index];
303304 self.end_index = new_end_index;
304305
305306 return result;
......@@ -315,7 +316,7 @@ pub const FixedBufferAllocator = struct {
315316 }
316317 }
317318
318 fn free(allocator: &Allocator, bytes: []u8) void { }
319 fn free(allocator: &Allocator, bytes: []u8) void {}
319320};
320321
321322/// lock free
......@@ -325,8 +326,8 @@ pub const ThreadSafeFixedBufferAllocator = struct {
325326 buffer: []u8,
326327
327328 pub fn init(buffer: []u8) ThreadSafeFixedBufferAllocator {
328 return ThreadSafeFixedBufferAllocator {
329 .allocator = Allocator {
329 return ThreadSafeFixedBufferAllocator{
330 .allocator = Allocator{
330331 .allocFn = alloc,
331332 .reallocFn = realloc,
332333 .freeFn = free,
......@@ -348,8 +349,7 @@ pub const ThreadSafeFixedBufferAllocator = struct {
348349 if (new_end_index > self.buffer.len) {
349350 return error.OutOfMemory;
350351 }
351 end_index = @cmpxchgWeak(usize, &self.end_index, end_index, new_end_index,
352 builtin.AtomicOrder.SeqCst, builtin.AtomicOrder.SeqCst) ?? return self.buffer[adjusted_index .. new_end_index];
352 end_index = @cmpxchgWeak(usize, &self.end_index, end_index, new_end_index, builtin.AtomicOrder.SeqCst, builtin.AtomicOrder.SeqCst) ?? return self.buffer[adjusted_index..new_end_index];
353353 }
354354 }
355355
......@@ -363,11 +363,9 @@ pub const ThreadSafeFixedBufferAllocator = struct {
363363 }
364364 }
365365
366 fn free(allocator: &Allocator, bytes: []u8) void { }
366 fn free(allocator: &Allocator, bytes: []u8) void {}
367367};
368368
369
370
371369test "c_allocator" {
372370 if (builtin.link_libc) {
373371 var slice = c_allocator.alloc(u8, 50) catch return;
......@@ -415,8 +413,8 @@ fn testAllocator(allocator: &mem.Allocator) !void {
415413 var slice = try allocator.alloc(&i32, 100);
416414
417415 for (slice) |*item, i| {
418 *item = try allocator.create(i32);
419 **item = i32(i);
416 item.* = try allocator.create(i32);
417 item.*.* = i32(i);
420418 }
421419
422420 for (slice) |item, i| {
......@@ -434,26 +432,26 @@ fn testAllocator(allocator: &mem.Allocator) !void {
434432fn testAllocatorLargeAlignment(allocator: &mem.Allocator) mem.Allocator.Error!void {
435433 //Maybe a platform's page_size is actually the same as or
436434 // very near usize?
437 if(os.page_size << 2 > @maxValue(usize)) return;
438
435 if (os.page_size << 2 > @maxValue(usize)) return;
436
439437 const USizeShift = @IntType(false, std.math.log2(usize.bit_count));
440438 const large_align = u29(os.page_size << 2);
441
439
442440 var align_mask: usize = undefined;
443441 _ = @shlWithOverflow(usize, ~usize(0), USizeShift(@ctz(large_align)), &align_mask);
444
442
445443 var slice = try allocator.allocFn(allocator, 500, large_align);
446444 debug.assert(@ptrToInt(slice.ptr) & align_mask == @ptrToInt(slice.ptr));
447
445
448446 slice = try allocator.reallocFn(allocator, slice, 100, large_align);
449447 debug.assert(@ptrToInt(slice.ptr) & align_mask == @ptrToInt(slice.ptr));
450
448
451449 slice = try allocator.reallocFn(allocator, slice, 5000, large_align);
452450 debug.assert(@ptrToInt(slice.ptr) & align_mask == @ptrToInt(slice.ptr));
453
451
454452 slice = try allocator.reallocFn(allocator, slice, 10, large_align);
455453 debug.assert(@ptrToInt(slice.ptr) & align_mask == @ptrToInt(slice.ptr));
456
454
457455 slice = try allocator.reallocFn(allocator, slice, 20000, large_align);
458456 debug.assert(@ptrToInt(slice.ptr) & align_mask == @ptrToInt(slice.ptr));
459457
std/io.zig+18-47
......@@ -18,32 +18,17 @@ const is_windows = builtin.os == builtin.Os.windows;
1818const GetStdIoErrs = os.WindowsGetStdHandleErrs;
1919
2020pub fn getStdErr() GetStdIoErrs!File {
21 const handle = if (is_windows)
22 try os.windowsGetStdHandle(os.windows.STD_ERROR_HANDLE)
23 else if (is_posix)
24 os.posix.STDERR_FILENO
25 else
26 unreachable;
21 const handle = if (is_windows) try os.windowsGetStdHandle(os.windows.STD_ERROR_HANDLE) else if (is_posix) os.posix.STDERR_FILENO else unreachable;
2722 return File.openHandle(handle);
2823}
2924
3025pub fn getStdOut() GetStdIoErrs!File {
31 const handle = if (is_windows)
32 try os.windowsGetStdHandle(os.windows.STD_OUTPUT_HANDLE)
33 else if (is_posix)
34 os.posix.STDOUT_FILENO
35 else
36 unreachable;
26 const handle = if (is_windows) try os.windowsGetStdHandle(os.windows.STD_OUTPUT_HANDLE) else if (is_posix) os.posix.STDOUT_FILENO else unreachable;
3727 return File.openHandle(handle);
3828}
3929
4030pub fn getStdIn() GetStdIoErrs!File {
41 const handle = if (is_windows)
42 try os.windowsGetStdHandle(os.windows.STD_INPUT_HANDLE)
43 else if (is_posix)
44 os.posix.STDIN_FILENO
45 else
46 unreachable;
31 const handle = if (is_windows) try os.windowsGetStdHandle(os.windows.STD_INPUT_HANDLE) else if (is_posix) os.posix.STDIN_FILENO else unreachable;
4732 return File.openHandle(handle);
4833}
4934
......@@ -56,11 +41,9 @@ pub const FileInStream = struct {
5641 pub const Stream = InStream(Error);
5742
5843 pub fn init(file: &File) FileInStream {
59 return FileInStream {
44 return FileInStream{
6045 .file = file,
61 .stream = Stream {
62 .readFn = readFn,
63 },
46 .stream = Stream{ .readFn = readFn },
6447 };
6548 }
6649
......@@ -79,11 +62,9 @@ pub const FileOutStream = struct {
7962 pub const Stream = OutStream(Error);
8063
8164 pub fn init(file: &File) FileOutStream {
82 return FileOutStream {
65 return FileOutStream{
8366 .file = file,
84 .stream = Stream {
85 .writeFn = writeFn,
86 },
67 .stream = Stream{ .writeFn = writeFn },
8768 };
8869 }
8970
......@@ -121,8 +102,7 @@ pub fn InStream(comptime ReadError: type) type {
121102 }
122103
123104 const new_buf_size = math.min(max_size, actual_buf_len + os.page_size);
124 if (new_buf_size == actual_buf_len)
125 return error.StreamTooLong;
105 if (new_buf_size == actual_buf_len) return error.StreamTooLong;
126106 try buffer.resize(new_buf_size);
127107 }
128108 }
......@@ -165,9 +145,7 @@ pub fn InStream(comptime ReadError: type) type {
165145 /// memory would be greater than `max_size`, returns `error.StreamTooLong`.
166146 /// Caller owns returned memory.
167147 /// If this function returns an error, the contents from the stream read so far are lost.
168 pub fn readUntilDelimiterAlloc(self: &Self, allocator: &mem.Allocator,
169 delimiter: u8, max_size: usize) ![]u8
170 {
148 pub fn readUntilDelimiterAlloc(self: &Self, allocator: &mem.Allocator, delimiter: u8, max_size: usize) ![]u8 {
171149 var buf = Buffer.initNull(allocator);
172150 defer buf.deinit();
173151
......@@ -283,7 +261,7 @@ pub fn BufferedInStream(comptime Error: type) type {
283261pub fn BufferedInStreamCustom(comptime buffer_size: usize, comptime Error: type) type {
284262 return struct {
285263 const Self = this;
286 const Stream = InStream(Error);
264 const Stream = InStream(Error);
287265
288266 pub stream: Stream,
289267
......@@ -294,7 +272,7 @@ pub fn BufferedInStreamCustom(comptime buffer_size: usize, comptime Error: type)
294272 end_index: usize,
295273
296274 pub fn init(unbuffered_in_stream: &Stream) Self {
297 return Self {
275 return Self{
298276 .unbuffered_in_stream = unbuffered_in_stream,
299277 .buffer = undefined,
300278
......@@ -305,9 +283,7 @@ pub fn BufferedInStreamCustom(comptime buffer_size: usize, comptime Error: type)
305283 .start_index = buffer_size,
306284 .end_index = buffer_size,
307285
308 .stream = Stream {
309 .readFn = readFn,
310 },
286 .stream = Stream{ .readFn = readFn },
311287 };
312288 }
313289
......@@ -368,13 +344,11 @@ pub fn BufferedOutStreamCustom(comptime buffer_size: usize, comptime OutStreamEr
368344 index: usize,
369345
370346 pub fn init(unbuffered_out_stream: &Stream) Self {
371 return Self {
347 return Self{
372348 .unbuffered_out_stream = unbuffered_out_stream,
373349 .buffer = undefined,
374350 .index = 0,
375 .stream = Stream {
376 .writeFn = writeFn,
377 },
351 .stream = Stream{ .writeFn = writeFn },
378352 };
379353 }
380354
......@@ -416,11 +390,9 @@ pub const BufferOutStream = struct {
416390 pub const Stream = OutStream(Error);
417391
418392 pub fn init(buffer: &Buffer) BufferOutStream {
419 return BufferOutStream {
393 return BufferOutStream{
420394 .buffer = buffer,
421 .stream = Stream {
422 .writeFn = writeFn,
423 },
395 .stream = Stream{ .writeFn = writeFn },
424396 };
425397 }
426398
......@@ -430,7 +402,6 @@ pub const BufferOutStream = struct {
430402 }
431403};
432404
433
434405pub const BufferedAtomicFile = struct {
435406 atomic_file: os.AtomicFile,
436407 file_stream: FileOutStream,
......@@ -441,7 +412,7 @@ pub const BufferedAtomicFile = struct {
441412 var self = try allocator.create(BufferedAtomicFile);
442413 errdefer allocator.destroy(self);
443414
444 *self = BufferedAtomicFile {
415 self.* = BufferedAtomicFile{
445416 .atomic_file = undefined,
446417 .file_stream = undefined,
447418 .buffered_stream = undefined,
......@@ -489,7 +460,7 @@ pub fn readLine(buf: []u8) !usize {
489460 '\r' => {
490461 // trash the following \n
491462 _ = stream.readByte() catch return error.EndOfFile;
492 return index;
463 return index;
493464 },
494465 '\n' => return index,
495466 else => {
std/linked_list.zig+55-40
......@@ -26,10 +26,10 @@ fn BaseLinkedList(comptime T: type, comptime ParentType: type, comptime field_na
2626 data: T,
2727
2828 pub fn init(value: &const T) Node {
29 return Node {
29 return Node{
3030 .prev = null,
3131 .next = null,
32 .data = *value,
32 .data = value.*,
3333 };
3434 }
3535
......@@ -45,18 +45,18 @@ fn BaseLinkedList(comptime T: type, comptime ParentType: type, comptime field_na
4545 };
4646
4747 first: ?&Node,
48 last: ?&Node,
49 len: usize,
48 last: ?&Node,
49 len: usize,
5050
5151 /// Initialize a linked list.
5252 ///
5353 /// Returns:
5454 /// An empty linked list.
5555 pub fn init() Self {
56 return Self {
56 return Self{
5757 .first = null,
58 .last = null,
59 .len = 0,
58 .last = null,
59 .len = 0,
6060 };
6161 }
6262
......@@ -131,7 +131,7 @@ fn BaseLinkedList(comptime T: type, comptime ParentType: type, comptime field_na
131131 } else {
132132 // Empty list.
133133 list.first = new_node;
134 list.last = new_node;
134 list.last = new_node;
135135 new_node.prev = null;
136136 new_node.next = null;
137137
......@@ -217,7 +217,7 @@ fn BaseLinkedList(comptime T: type, comptime ParentType: type, comptime field_na
217217 pub fn createNode(list: &Self, data: &const T, allocator: &Allocator) !&Node {
218218 comptime assert(!isIntrusive());
219219 var node = try list.allocateNode(allocator);
220 *node = Node.init(data);
220 node.* = Node.init(data);
221221 return node;
222222 }
223223 };
......@@ -227,11 +227,11 @@ test "basic linked list test" {
227227 const allocator = debug.global_allocator;
228228 var list = LinkedList(u32).init();
229229
230 var one = try list.createNode(1, allocator);
231 var two = try list.createNode(2, allocator);
230 var one = try list.createNode(1, allocator);
231 var two = try list.createNode(2, allocator);
232232 var three = try list.createNode(3, allocator);
233 var four = try list.createNode(4, allocator);
234 var five = try list.createNode(5, allocator);
233 var four = try list.createNode(4, allocator);
234 var five = try list.createNode(5, allocator);
235235 defer {
236236 list.destroyNode(one, allocator);
237237 list.destroyNode(two, allocator);
......@@ -240,11 +240,11 @@ test "basic linked list test" {
240240 list.destroyNode(five, allocator);
241241 }
242242
243 list.append(two); // {2}
244 list.append(five); // {2, 5}
245 list.prepend(one); // {1, 2, 5}
246 list.insertBefore(five, four); // {1, 2, 4, 5}
247 list.insertAfter(two, three); // {1, 2, 3, 4, 5}
243 list.append(two); // {2}
244 list.append(five); // {2, 5}
245 list.prepend(one); // {1, 2, 5}
246 list.insertBefore(five, four); // {1, 2, 4, 5}
247 list.insertAfter(two, three); // {1, 2, 3, 4, 5}
248248
249249 // Traverse forwards.
250250 {
......@@ -266,13 +266,13 @@ test "basic linked list test" {
266266 }
267267 }
268268
269 var first = list.popFirst(); // {2, 3, 4, 5}
270 var last = list.pop(); // {2, 3, 4}
271 list.remove(three); // {2, 4}
269 var first = list.popFirst(); // {2, 3, 4, 5}
270 var last = list.pop(); // {2, 3, 4}
271 list.remove(three); // {2, 4}
272272
273 assert ((??list.first).data == 2);
274 assert ((??list.last ).data == 4);
275 assert (list.len == 2);
273 assert((??list.first).data == 2);
274 assert((??list.last).data == 4);
275 assert(list.len == 2);
276276}
277277
278278const ElementList = IntrusiveLinkedList(Element, "link");
......@@ -285,17 +285,32 @@ test "basic intrusive linked list test" {
285285 const allocator = debug.global_allocator;
286286 var list = ElementList.init();
287287
288 var one = Element { .value = 1, .link = ElementList.Node.initIntrusive() };
289 var two = Element { .value = 2, .link = ElementList.Node.initIntrusive() };
290 var three = Element { .value = 3, .link = ElementList.Node.initIntrusive() };
291 var four = Element { .value = 4, .link = ElementList.Node.initIntrusive() };
292 var five = Element { .value = 5, .link = ElementList.Node.initIntrusive() };
288 var one = Element{
289 .value = 1,
290 .link = ElementList.Node.initIntrusive(),
291 };
292 var two = Element{
293 .value = 2,
294 .link = ElementList.Node.initIntrusive(),
295 };
296 var three = Element{
297 .value = 3,
298 .link = ElementList.Node.initIntrusive(),
299 };
300 var four = Element{
301 .value = 4,
302 .link = ElementList.Node.initIntrusive(),
303 };
304 var five = Element{
305 .value = 5,
306 .link = ElementList.Node.initIntrusive(),
307 };
293308
294 list.append(&two.link); // {2}
295 list.append(&five.link); // {2, 5}
296 list.prepend(&one.link); // {1, 2, 5}
297 list.insertBefore(&five.link, &four.link); // {1, 2, 4, 5}
298 list.insertAfter(&two.link, &three.link); // {1, 2, 3, 4, 5}
309 list.append(&two.link); // {2}
310 list.append(&five.link); // {2, 5}
311 list.prepend(&one.link); // {1, 2, 5}
312 list.insertBefore(&five.link, &four.link); // {1, 2, 4, 5}
313 list.insertAfter(&two.link, &three.link); // {1, 2, 3, 4, 5}
299314
300315 // Traverse forwards.
301316 {
......@@ -317,11 +332,11 @@ test "basic intrusive linked list test" {
317332 }
318333 }
319334
320 var first = list.popFirst(); // {2, 3, 4, 5}
321 var last = list.pop(); // {2, 3, 4}
322 list.remove(&three.link); // {2, 4}
335 var first = list.popFirst(); // {2, 3, 4, 5}
336 var last = list.pop(); // {2, 3, 4}
337 list.remove(&three.link); // {2, 4}
323338
324 assert ((??list.first).toData().value == 2);
325 assert ((??list.last ).toData().value == 4);
326 assert (list.len == 2);
339 assert((??list.first).toData().value == 2);
340 assert((??list.last).toData().value == 4);
341 assert(list.len == 2);
327342}
std/os/index.zig+38-42
......@@ -137,7 +137,7 @@ pub fn getRandomBytes(buf: []u8) !void {
137137 }
138138 },
139139 Os.zen => {
140 const randomness = []u8 {
140 const randomness = []u8{
141141 42,
142142 1,
143143 7,
......@@ -265,7 +265,7 @@ pub fn posixRead(fd: i32, buf: []u8) !void {
265265 }
266266}
267267
268pub const PosixWriteError = error {
268pub const PosixWriteError = error{
269269 WouldBlock,
270270 FileClosed,
271271 DestinationAddressRequired,
......@@ -310,7 +310,7 @@ pub fn posixWrite(fd: i32, bytes: []const u8) !void {
310310 }
311311}
312312
313pub const PosixOpenError = error {
313pub const PosixOpenError = error{
314314 OutOfMemory,
315315 AccessDenied,
316316 FileTooBig,
......@@ -477,7 +477,7 @@ pub fn posixExecve(argv: []const []const u8, env_map: &const BufMap, allocator:
477477 return posixExecveErrnoToErr(err);
478478}
479479
480pub const PosixExecveError = error {
480pub const PosixExecveError = error{
481481 SystemResources,
482482 AccessDenied,
483483 InvalidExe,
......@@ -512,7 +512,7 @@ fn posixExecveErrnoToErr(err: usize) PosixExecveError {
512512 };
513513}
514514
515pub var linux_aux_raw = []usize {0} ** 38;
515pub var linux_aux_raw = []usize{0} ** 38;
516516pub var posix_environ_raw: []&u8 = undefined;
517517
518518/// Caller must free result when done.
......@@ -667,7 +667,7 @@ pub fn symLink(allocator: &Allocator, existing_path: []const u8, new_path: []con
667667 }
668668}
669669
670pub const WindowsSymLinkError = error {
670pub const WindowsSymLinkError = error{
671671 OutOfMemory,
672672 Unexpected,
673673};
......@@ -686,7 +686,7 @@ pub fn symLinkWindows(allocator: &Allocator, existing_path: []const u8, new_path
686686 }
687687}
688688
689pub const PosixSymLinkError = error {
689pub const PosixSymLinkError = error{
690690 OutOfMemory,
691691 AccessDenied,
692692 DiskQuota,
......@@ -895,7 +895,7 @@ pub const AtomicFile = struct {
895895 else => return err,
896896 };
897897
898 return AtomicFile {
898 return AtomicFile{
899899 .allocator = allocator,
900900 .file = file,
901901 .tmp_path = tmp_path,
......@@ -1087,7 +1087,7 @@ pub fn deleteDir(allocator: &Allocator, dir_path: []const u8) !void {
10871087/// removes it. If it cannot be removed because it is a non-empty directory,
10881088/// this function recursively removes its entries and then tries again.
10891089/// TODO non-recursive implementation
1090const DeleteTreeError = error {
1090const DeleteTreeError = error{
10911091 OutOfMemory,
10921092 AccessDenied,
10931093 FileTooBig,
......@@ -1217,7 +1217,7 @@ pub const Dir = struct {
12171217 Os.ios => 0,
12181218 else => {},
12191219 };
1220 return Dir {
1220 return Dir{
12211221 .allocator = allocator,
12221222 .fd = fd,
12231223 .darwin_seek = darwin_seek_init,
......@@ -1294,7 +1294,7 @@ pub const Dir = struct {
12941294 posix.DT_WHT => Entry.Kind.Whiteout,
12951295 else => Entry.Kind.Unknown,
12961296 };
1297 return Entry {
1297 return Entry{
12981298 .name = name,
12991299 .kind = entry_kind,
13001300 };
......@@ -1355,7 +1355,7 @@ pub const Dir = struct {
13551355 posix.DT_SOCK => Entry.Kind.UnixDomainSocket,
13561356 else => Entry.Kind.Unknown,
13571357 };
1358 return Entry {
1358 return Entry{
13591359 .name = name,
13601360 .kind = entry_kind,
13611361 };
......@@ -1465,7 +1465,7 @@ pub fn posix_setregid(rgid: u32, egid: u32) !void {
14651465 };
14661466}
14671467
1468pub const WindowsGetStdHandleErrs = error {
1468pub const WindowsGetStdHandleErrs = error{
14691469 NoStdHandles,
14701470 Unexpected,
14711471};
......@@ -1489,7 +1489,7 @@ pub const ArgIteratorPosix = struct {
14891489 count: usize,
14901490
14911491 pub fn init() ArgIteratorPosix {
1492 return ArgIteratorPosix {
1492 return ArgIteratorPosix{
14931493 .index = 0,
14941494 .count = raw.len,
14951495 };
......@@ -1522,16 +1522,14 @@ pub const ArgIteratorWindows = struct {
15221522 quote_count: usize,
15231523 seen_quote_count: usize,
15241524
1525 pub const NextError = error {
1526 OutOfMemory,
1527 };
1525 pub const NextError = error{OutOfMemory};
15281526
15291527 pub fn init() ArgIteratorWindows {
15301528 return initWithCmdLine(windows.GetCommandLineA());
15311529 }
15321530
15331531 pub fn initWithCmdLine(cmd_line: &const u8) ArgIteratorWindows {
1534 return ArgIteratorWindows {
1532 return ArgIteratorWindows{
15351533 .index = 0,
15361534 .cmd_line = cmd_line,
15371535 .in_quote = false,
......@@ -1676,9 +1674,7 @@ pub const ArgIterator = struct {
16761674 inner: InnerType,
16771675
16781676 pub fn init() ArgIterator {
1679 return ArgIterator {
1680 .inner = InnerType.init(),
1681 };
1677 return ArgIterator{ .inner = InnerType.init() };
16821678 }
16831679
16841680 pub const NextError = ArgIteratorWindows.NextError;
......@@ -1757,33 +1753,33 @@ pub fn argsFree(allocator: &mem.Allocator, args_alloc: []const []u8) void {
17571753}
17581754
17591755test "windows arg parsing" {
1760 testWindowsCmdLine(c"a b\tc d", [][]const u8 {
1756 testWindowsCmdLine(c"a b\tc d", [][]const u8{
17611757 "a",
17621758 "b",
17631759 "c",
17641760 "d",
17651761 });
1766 testWindowsCmdLine(c"\"abc\" d e", [][]const u8 {
1762 testWindowsCmdLine(c"\"abc\" d e", [][]const u8{
17671763 "abc",
17681764 "d",
17691765 "e",
17701766 });
1771 testWindowsCmdLine(c"a\\\\\\b d\"e f\"g h", [][]const u8 {
1767 testWindowsCmdLine(c"a\\\\\\b d\"e f\"g h", [][]const u8{
17721768 "a\\\\\\b",
17731769 "de fg",
17741770 "h",
17751771 });
1776 testWindowsCmdLine(c"a\\\\\\\"b c d", [][]const u8 {
1772 testWindowsCmdLine(c"a\\\\\\\"b c d", [][]const u8{
17771773 "a\\\"b",
17781774 "c",
17791775 "d",
17801776 });
1781 testWindowsCmdLine(c"a\\\\\\\\\"b c\" d e", [][]const u8 {
1777 testWindowsCmdLine(c"a\\\\\\\\\"b c\" d e", [][]const u8{
17821778 "a\\\\b c",
17831779 "d",
17841780 "e",
17851781 });
1786 testWindowsCmdLine(c"a b\tc \"d f", [][]const u8 {
1782 testWindowsCmdLine(c"a b\tc \"d f", [][]const u8{
17871783 "a",
17881784 "b",
17891785 "c",
......@@ -1791,7 +1787,7 @@ test "windows arg parsing" {
17911787 "f",
17921788 });
17931789
1794 testWindowsCmdLine(c"\".\\..\\zig-cache\\build\" \"bin\\zig.exe\" \".\\..\" \".\\..\\zig-cache\" \"--help\"", [][]const u8 {
1790 testWindowsCmdLine(c"\".\\..\\zig-cache\\build\" \"bin\\zig.exe\" \".\\..\" \".\\..\\zig-cache\" \"--help\"", [][]const u8{
17951791 ".\\..\\zig-cache\\build",
17961792 "bin\\zig.exe",
17971793 ".\\..",
......@@ -1811,7 +1807,7 @@ fn testWindowsCmdLine(input_cmd_line: &const u8, expected_args: []const []const
18111807
18121808// TODO make this a build variable that you can set
18131809const unexpected_error_tracing = false;
1814const UnexpectedError = error {
1810const UnexpectedError = error{
18151811 /// The Operating System returned an undocumented error code.
18161812 Unexpected,
18171813};
......@@ -1950,7 +1946,7 @@ pub fn isTty(handle: FileHandle) bool {
19501946 }
19511947}
19521948
1953pub const PosixSocketError = error {
1949pub const PosixSocketError = error{
19541950 /// Permission to create a socket of the specified type and/or
19551951 /// pro‐tocol is denied.
19561952 PermissionDenied,
......@@ -1992,7 +1988,7 @@ pub fn posixSocket(domain: u32, socket_type: u32, protocol: u32) !i32 {
19921988 }
19931989}
19941990
1995pub const PosixBindError = error {
1991pub const PosixBindError = error{
19961992 /// The address is protected, and the user is not the superuser.
19971993 /// For UNIX domain sockets: Search permission is denied on a component
19981994 /// of the path prefix.
......@@ -2065,7 +2061,7 @@ pub fn posixBind(fd: i32, addr: &const posix.sockaddr) PosixBindError!void {
20652061 }
20662062}
20672063
2068const PosixListenError = error {
2064const PosixListenError = error{
20692065 /// Another socket is already listening on the same port.
20702066 /// For Internet domain sockets, the socket referred to by sockfd had not previously
20712067 /// been bound to an address and, upon attempting to bind it to an ephemeral port, it
......@@ -2098,7 +2094,7 @@ pub fn posixListen(sockfd: i32, backlog: u32) PosixListenError!void {
20982094 }
20992095}
21002096
2101pub const PosixAcceptError = error {
2097pub const PosixAcceptError = error{
21022098 /// The socket is marked nonblocking and no connections are present to be accepted.
21032099 WouldBlock,
21042100
......@@ -2165,7 +2161,7 @@ pub fn posixAccept(fd: i32, addr: &posix.sockaddr, flags: u32) PosixAcceptError!
21652161 }
21662162}
21672163
2168pub const LinuxEpollCreateError = error {
2164pub const LinuxEpollCreateError = error{
21692165 /// Invalid value specified in flags.
21702166 InvalidSyscall,
21712167
......@@ -2198,7 +2194,7 @@ pub fn linuxEpollCreate(flags: u32) LinuxEpollCreateError!i32 {
21982194 }
21992195}
22002196
2201pub const LinuxEpollCtlError = error {
2197pub const LinuxEpollCtlError = error{
22022198 /// epfd or fd is not a valid file descriptor.
22032199 InvalidFileDescriptor,
22042200
......@@ -2271,7 +2267,7 @@ pub fn linuxEpollWait(epfd: i32, events: []linux.epoll_event, timeout: i32) usiz
22712267 }
22722268}
22732269
2274pub const PosixGetSockNameError = error {
2270pub const PosixGetSockNameError = error{
22752271 /// Insufficient resources were available in the system to perform the operation.
22762272 SystemResources,
22772273
......@@ -2295,7 +2291,7 @@ pub fn posixGetSockName(sockfd: i32) PosixGetSockNameError!posix.sockaddr {
22952291 }
22962292}
22972293
2298pub const PosixConnectError = error {
2294pub const PosixConnectError = error{
22992295 /// For UNIX domain sockets, which are identified by pathname: Write permission is denied on the socket
23002296 /// file, or search permission is denied for one of the directories in the path prefix.
23012297 /// or
......@@ -2484,7 +2480,7 @@ pub const Thread = struct {
24842480 }
24852481};
24862482
2487pub const SpawnThreadError = error {
2483pub const SpawnThreadError = error{
24882484 /// A system-imposed limit on the number of threads was encountered.
24892485 /// There are a number of limits that may trigger this error:
24902486 /// * the RLIMIT_NPROC soft resource limit (set via setrlimit(2)),
......@@ -2532,7 +2528,7 @@ pub fn spawnThread(context: var, comptime startFn: var) SpawnThreadError!&Thread
25322528 if (@sizeOf(Context) == 0) {
25332529 return startFn({});
25342530 } else {
2535 return startFn(*@ptrCast(&Context, @alignCast(@alignOf(Context), arg)));
2531 return startFn(@ptrCast(&Context, @alignCast(@alignOf(Context), arg)).*);
25362532 }
25372533 }
25382534 };
......@@ -2562,7 +2558,7 @@ pub fn spawnThread(context: var, comptime startFn: var) SpawnThreadError!&Thread
25622558 if (@sizeOf(Context) == 0) {
25632559 return startFn({});
25642560 } else {
2565 return startFn(*@intToPtr(&const Context, ctx_addr));
2561 return startFn(@intToPtr(&const Context, ctx_addr).*);
25662562 }
25672563 }
25682564 extern fn posixThreadMain(ctx: ?&c_void) ?&c_void {
......@@ -2570,7 +2566,7 @@ pub fn spawnThread(context: var, comptime startFn: var) SpawnThreadError!&Thread
25702566 _ = startFn({});
25712567 return null;
25722568 } else {
2573 _ = startFn(*@ptrCast(&const Context, @alignCast(@alignOf(Context), ctx)));
2569 _ = startFn(@ptrCast(&const Context, @alignCast(@alignOf(Context), ctx)).*);
25742570 return null;
25752571 }
25762572 }
......@@ -2590,7 +2586,7 @@ pub fn spawnThread(context: var, comptime startFn: var) SpawnThreadError!&Thread
25902586 stack_end -= stack_end % @alignOf(Context);
25912587 assert(stack_end >= stack_addr);
25922588 const context_ptr = @alignCast(@alignOf(Context), @intToPtr(&Context, stack_end));
2593 *context_ptr = context;
2589 context_ptr.* = context;
25942590 arg = stack_end;
25952591 }
25962592
std/os/linux/index.zig+189-190
......@@ -30,96 +30,95 @@ pub const FUTEX_PRIVATE_FLAG = 128;
3030
3131pub const FUTEX_CLOCK_REALTIME = 256;
3232
33
34pub const PROT_NONE = 0;
35pub const PROT_READ = 1;
36pub const PROT_WRITE = 2;
37pub const PROT_EXEC = 4;
33pub const PROT_NONE = 0;
34pub const PROT_READ = 1;
35pub const PROT_WRITE = 2;
36pub const PROT_EXEC = 4;
3837pub const PROT_GROWSDOWN = 0x01000000;
39pub const PROT_GROWSUP = 0x02000000;
40
41pub const MAP_FAILED = @maxValue(usize);
42pub const MAP_SHARED = 0x01;
43pub const MAP_PRIVATE = 0x02;
44pub const MAP_TYPE = 0x0f;
45pub const MAP_FIXED = 0x10;
46pub const MAP_ANONYMOUS = 0x20;
47pub const MAP_NORESERVE = 0x4000;
48pub const MAP_GROWSDOWN = 0x0100;
49pub const MAP_DENYWRITE = 0x0800;
38pub const PROT_GROWSUP = 0x02000000;
39
40pub const MAP_FAILED = @maxValue(usize);
41pub const MAP_SHARED = 0x01;
42pub const MAP_PRIVATE = 0x02;
43pub const MAP_TYPE = 0x0f;
44pub const MAP_FIXED = 0x10;
45pub const MAP_ANONYMOUS = 0x20;
46pub const MAP_NORESERVE = 0x4000;
47pub const MAP_GROWSDOWN = 0x0100;
48pub const MAP_DENYWRITE = 0x0800;
5049pub const MAP_EXECUTABLE = 0x1000;
51pub const MAP_LOCKED = 0x2000;
52pub const MAP_POPULATE = 0x8000;
53pub const MAP_NONBLOCK = 0x10000;
54pub const MAP_STACK = 0x20000;
55pub const MAP_HUGETLB = 0x40000;
56pub const MAP_FILE = 0;
50pub const MAP_LOCKED = 0x2000;
51pub const MAP_POPULATE = 0x8000;
52pub const MAP_NONBLOCK = 0x10000;
53pub const MAP_STACK = 0x20000;
54pub const MAP_HUGETLB = 0x40000;
55pub const MAP_FILE = 0;
5756
5857pub const F_OK = 0;
5958pub const X_OK = 1;
6059pub const W_OK = 2;
6160pub const R_OK = 4;
6261
63pub const WNOHANG = 1;
64pub const WUNTRACED = 2;
65pub const WSTOPPED = 2;
66pub const WEXITED = 4;
62pub const WNOHANG = 1;
63pub const WUNTRACED = 2;
64pub const WSTOPPED = 2;
65pub const WEXITED = 4;
6766pub const WCONTINUED = 8;
68pub const WNOWAIT = 0x1000000;
69
70pub const SA_NOCLDSTOP = 1;
71pub const SA_NOCLDWAIT = 2;
72pub const SA_SIGINFO = 4;
73pub const SA_ONSTACK = 0x08000000;
74pub const SA_RESTART = 0x10000000;
75pub const SA_NODEFER = 0x40000000;
76pub const SA_RESETHAND = 0x80000000;
77pub const SA_RESTORER = 0x04000000;
78
79pub const SIGHUP = 1;
80pub const SIGINT = 2;
81pub const SIGQUIT = 3;
82pub const SIGILL = 4;
83pub const SIGTRAP = 5;
84pub const SIGABRT = 6;
85pub const SIGIOT = SIGABRT;
86pub const SIGBUS = 7;
87pub const SIGFPE = 8;
88pub const SIGKILL = 9;
89pub const SIGUSR1 = 10;
90pub const SIGSEGV = 11;
91pub const SIGUSR2 = 12;
92pub const SIGPIPE = 13;
93pub const SIGALRM = 14;
94pub const SIGTERM = 15;
67pub const WNOWAIT = 0x1000000;
68
69pub const SA_NOCLDSTOP = 1;
70pub const SA_NOCLDWAIT = 2;
71pub const SA_SIGINFO = 4;
72pub const SA_ONSTACK = 0x08000000;
73pub const SA_RESTART = 0x10000000;
74pub const SA_NODEFER = 0x40000000;
75pub const SA_RESETHAND = 0x80000000;
76pub const SA_RESTORER = 0x04000000;
77
78pub const SIGHUP = 1;
79pub const SIGINT = 2;
80pub const SIGQUIT = 3;
81pub const SIGILL = 4;
82pub const SIGTRAP = 5;
83pub const SIGABRT = 6;
84pub const SIGIOT = SIGABRT;
85pub const SIGBUS = 7;
86pub const SIGFPE = 8;
87pub const SIGKILL = 9;
88pub const SIGUSR1 = 10;
89pub const SIGSEGV = 11;
90pub const SIGUSR2 = 12;
91pub const SIGPIPE = 13;
92pub const SIGALRM = 14;
93pub const SIGTERM = 15;
9594pub const SIGSTKFLT = 16;
96pub const SIGCHLD = 17;
97pub const SIGCONT = 18;
98pub const SIGSTOP = 19;
99pub const SIGTSTP = 20;
100pub const SIGTTIN = 21;
101pub const SIGTTOU = 22;
102pub const SIGURG = 23;
103pub const SIGXCPU = 24;
104pub const SIGXFSZ = 25;
95pub const SIGCHLD = 17;
96pub const SIGCONT = 18;
97pub const SIGSTOP = 19;
98pub const SIGTSTP = 20;
99pub const SIGTTIN = 21;
100pub const SIGTTOU = 22;
101pub const SIGURG = 23;
102pub const SIGXCPU = 24;
103pub const SIGXFSZ = 25;
105104pub const SIGVTALRM = 26;
106pub const SIGPROF = 27;
107pub const SIGWINCH = 28;
108pub const SIGIO = 29;
109pub const SIGPOLL = 29;
110pub const SIGPWR = 30;
111pub const SIGSYS = 31;
105pub const SIGPROF = 27;
106pub const SIGWINCH = 28;
107pub const SIGIO = 29;
108pub const SIGPOLL = 29;
109pub const SIGPWR = 30;
110pub const SIGSYS = 31;
112111pub const SIGUNUSED = SIGSYS;
113112
114113pub const O_RDONLY = 0o0;
115114pub const O_WRONLY = 0o1;
116pub const O_RDWR = 0o2;
115pub const O_RDWR = 0o2;
117116
118117pub const SEEK_SET = 0;
119118pub const SEEK_CUR = 1;
120119pub const SEEK_END = 2;
121120
122pub const SIG_BLOCK = 0;
121pub const SIG_BLOCK = 0;
123122pub const SIG_UNBLOCK = 1;
124123pub const SIG_SETMASK = 2;
125124
......@@ -408,7 +407,6 @@ pub const DT_LNK = 10;
408407pub const DT_SOCK = 12;
409408pub const DT_WHT = 14;
410409
411
412410pub const TCGETS = 0x5401;
413411pub const TCSETS = 0x5402;
414412pub const TCSETSW = 0x5403;
......@@ -539,23 +537,23 @@ pub const MS_BIND = 4096;
539537pub const MS_MOVE = 8192;
540538pub const MS_REC = 16384;
541539pub const MS_SILENT = 32768;
542pub const MS_POSIXACL = (1<<16);
543pub const MS_UNBINDABLE = (1<<17);
544pub const MS_PRIVATE = (1<<18);
545pub const MS_SLAVE = (1<<19);
546pub const MS_SHARED = (1<<20);
547pub const MS_RELATIME = (1<<21);
548pub const MS_KERNMOUNT = (1<<22);
549pub const MS_I_VERSION = (1<<23);
550pub const MS_STRICTATIME = (1<<24);
551pub const MS_LAZYTIME = (1<<25);
552pub const MS_NOREMOTELOCK = (1<<27);
553pub const MS_NOSEC = (1<<28);
554pub const MS_BORN = (1<<29);
555pub const MS_ACTIVE = (1<<30);
556pub const MS_NOUSER = (1<<31);
557
558pub const MS_RMT_MASK = (MS_RDONLY|MS_SYNCHRONOUS|MS_MANDLOCK|MS_I_VERSION|MS_LAZYTIME);
540pub const MS_POSIXACL = (1 << 16);
541pub const MS_UNBINDABLE = (1 << 17);
542pub const MS_PRIVATE = (1 << 18);
543pub const MS_SLAVE = (1 << 19);
544pub const MS_SHARED = (1 << 20);
545pub const MS_RELATIME = (1 << 21);
546pub const MS_KERNMOUNT = (1 << 22);
547pub const MS_I_VERSION = (1 << 23);
548pub const MS_STRICTATIME = (1 << 24);
549pub const MS_LAZYTIME = (1 << 25);
550pub const MS_NOREMOTELOCK = (1 << 27);
551pub const MS_NOSEC = (1 << 28);
552pub const MS_BORN = (1 << 29);
553pub const MS_ACTIVE = (1 << 30);
554pub const MS_NOUSER = (1 << 31);
555
556pub const MS_RMT_MASK = (MS_RDONLY | MS_SYNCHRONOUS | MS_MANDLOCK | MS_I_VERSION | MS_LAZYTIME);
559557
560558pub const MS_MGC_VAL = 0xc0ed0000;
561559pub const MS_MGC_MSK = 0xffff0000;
......@@ -565,7 +563,6 @@ pub const MNT_DETACH = 2;
565563pub const MNT_EXPIRE = 4;
566564pub const UMOUNT_NOFOLLOW = 8;
567565
568
569566pub const S_IFMT = 0o170000;
570567
571568pub const S_IFDIR = 0o040000;
......@@ -626,15 +623,30 @@ pub const TFD_CLOEXEC = O_CLOEXEC;
626623pub const TFD_TIMER_ABSTIME = 1;
627624pub const TFD_TIMER_CANCEL_ON_SET = (1 << 1);
628625
629fn unsigned(s: i32) u32 { return @bitCast(u32, s); }
630fn signed(s: u32) i32 { return @bitCast(i32, s); }
631pub fn WEXITSTATUS(s: i32) i32 { return signed((unsigned(s) & 0xff00) >> 8); }
632pub fn WTERMSIG(s: i32) i32 { return signed(unsigned(s) & 0x7f); }
633pub fn WSTOPSIG(s: i32) i32 { return WEXITSTATUS(s); }
634pub fn WIFEXITED(s: i32) bool { return WTERMSIG(s) == 0; }
635pub fn WIFSTOPPED(s: i32) bool { return (u16)(((unsigned(s)&0xffff)*%0x10001)>>8) > 0x7f00; }
636pub fn WIFSIGNALED(s: i32) bool { return (unsigned(s)&0xffff)-%1 < 0xff; }
637
626fn unsigned(s: i32) u32 {
627 return @bitCast(u32, s);
628}
629fn signed(s: u32) i32 {
630 return @bitCast(i32, s);
631}
632pub fn WEXITSTATUS(s: i32) i32 {
633 return signed((unsigned(s) & 0xff00) >> 8);
634}
635pub fn WTERMSIG(s: i32) i32 {
636 return signed(unsigned(s) & 0x7f);
637}
638pub fn WSTOPSIG(s: i32) i32 {
639 return WEXITSTATUS(s);
640}
641pub fn WIFEXITED(s: i32) bool {
642 return WTERMSIG(s) == 0;
643}
644pub fn WIFSTOPPED(s: i32) bool {
645 return (u16)(((unsigned(s) & 0xffff) *% 0x10001) >> 8) > 0x7f00;
646}
647pub fn WIFSIGNALED(s: i32) bool {
648 return (unsigned(s) & 0xffff) -% 1 < 0xff;
649}
638650
639651pub const winsize = extern struct {
640652 ws_row: u16,
......@@ -707,8 +719,7 @@ pub fn umount2(special: &const u8, flags: u32) usize {
707719}
708720
709721pub fn mmap(address: ?&u8, length: usize, prot: usize, flags: u32, fd: i32, offset: isize) usize {
710 return syscall6(SYS_mmap, @ptrToInt(address), length, prot, flags, usize(fd),
711 @bitCast(usize, offset));
722 return syscall6(SYS_mmap, @ptrToInt(address), length, prot, flags, usize(fd), @bitCast(usize, offset));
712723}
713724
714725pub fn munmap(address: usize, length: usize) usize {
......@@ -812,7 +823,8 @@ pub fn clock_gettime(clk_id: i32, tp: &timespec) usize {
812823 if (@ptrToInt(f) != 0) {
813824 const rc = f(clk_id, tp);
814825 switch (rc) {
815 0, @bitCast(usize, isize(-EINVAL)) => return rc,
826 0,
827 @bitCast(usize, isize(-EINVAL)) => return rc,
816828 else => {},
817829 }
818830 }
......@@ -823,8 +835,7 @@ var vdso_clock_gettime = init_vdso_clock_gettime;
823835extern fn init_vdso_clock_gettime(clk: i32, ts: &timespec) usize {
824836 const addr = vdso.lookup(VDSO_CGT_VER, VDSO_CGT_SYM);
825837 var f = @intToPtr(@typeOf(init_vdso_clock_gettime), addr);
826 _ = @cmpxchgStrong(@typeOf(init_vdso_clock_gettime), &vdso_clock_gettime, init_vdso_clock_gettime, f,
827 builtin.AtomicOrder.Monotonic, builtin.AtomicOrder.Monotonic);
838 _ = @cmpxchgStrong(@typeOf(init_vdso_clock_gettime), &vdso_clock_gettime, init_vdso_clock_gettime, f, builtin.AtomicOrder.Monotonic, builtin.AtomicOrder.Monotonic);
828839 if (@ptrToInt(f) == 0) return @bitCast(usize, isize(-ENOSYS));
829840 return f(clk, ts);
830841}
......@@ -918,18 +929,18 @@ pub fn getpid() i32 {
918929}
919930
920931pub fn sigprocmask(flags: u32, noalias set: &const sigset_t, noalias oldset: ?&sigset_t) usize {
921 return syscall4(SYS_rt_sigprocmask, flags, @ptrToInt(set), @ptrToInt(oldset), NSIG/8);
932 return syscall4(SYS_rt_sigprocmask, flags, @ptrToInt(set), @ptrToInt(oldset), NSIG / 8);
922933}
923934
924935pub fn sigaction(sig: u6, noalias act: &const Sigaction, noalias oact: ?&Sigaction) usize {
925936 assert(sig >= 1);
926937 assert(sig != SIGKILL);
927938 assert(sig != SIGSTOP);
928 var ksa = k_sigaction {
939 var ksa = k_sigaction{
929940 .handler = act.handler,
930941 .flags = act.flags | SA_RESTORER,
931942 .mask = undefined,
932 .restorer = @ptrCast(extern fn()void, restore_rt),
943 .restorer = @ptrCast(extern fn() void, restore_rt),
933944 };
934945 var ksa_old: k_sigaction = undefined;
935946 @memcpy(@ptrCast(&u8, &ksa.mask), @ptrCast(&const u8, &act.mask), 8);
......@@ -952,22 +963,22 @@ const all_mask = []usize{@maxValue(usize)};
952963const app_mask = []usize{0xfffffffc7fffffff};
953964
954965const k_sigaction = extern struct {
955 handler: extern fn(i32)void,
966 handler: extern fn(i32) void,
956967 flags: usize,
957 restorer: extern fn()void,
968 restorer: extern fn() void,
958969 mask: [2]u32,
959970};
960971
961972/// Renamed from `sigaction` to `Sigaction` to avoid conflict with the syscall.
962973pub const Sigaction = struct {
963 handler: extern fn(i32)void,
974 handler: extern fn(i32) void,
964975 mask: sigset_t,
965976 flags: u32,
966977};
967978
968pub const SIG_ERR = @intToPtr(extern fn(i32)void, @maxValue(usize));
969pub const SIG_DFL = @intToPtr(extern fn(i32)void, 0);
970pub const SIG_IGN = @intToPtr(extern fn(i32)void, 1);
979pub const SIG_ERR = @intToPtr(extern fn(i32) void, @maxValue(usize));
980pub const SIG_DFL = @intToPtr(extern fn(i32) void, 0);
981pub const SIG_IGN = @intToPtr(extern fn(i32) void, 1);
971982pub const empty_sigset = []usize{0} ** sigset_t.len;
972983
973984pub fn raise(sig: i32) usize {
......@@ -980,25 +991,25 @@ pub fn raise(sig: i32) usize {
980991}
981992
982993fn blockAllSignals(set: &sigset_t) void {
983 _ = syscall4(SYS_rt_sigprocmask, SIG_BLOCK, @ptrToInt(&all_mask), @ptrToInt(set), NSIG/8);
994 _ = syscall4(SYS_rt_sigprocmask, SIG_BLOCK, @ptrToInt(&all_mask), @ptrToInt(set), NSIG / 8);
984995}
985996
986997fn blockAppSignals(set: &sigset_t) void {
987 _ = syscall4(SYS_rt_sigprocmask, SIG_BLOCK, @ptrToInt(&app_mask), @ptrToInt(set), NSIG/8);
998 _ = syscall4(SYS_rt_sigprocmask, SIG_BLOCK, @ptrToInt(&app_mask), @ptrToInt(set), NSIG / 8);
988999}
9891000
9901001fn restoreSignals(set: &sigset_t) void {
991 _ = syscall4(SYS_rt_sigprocmask, SIG_SETMASK, @ptrToInt(set), 0, NSIG/8);
1002 _ = syscall4(SYS_rt_sigprocmask, SIG_SETMASK, @ptrToInt(set), 0, NSIG / 8);
9921003}
9931004
9941005pub fn sigaddset(set: &sigset_t, sig: u6) void {
9951006 const s = sig - 1;
996 (*set)[usize(s) / usize.bit_count] |= usize(1) << (s & (usize.bit_count - 1));
1007 (set.*)[usize(s) / usize.bit_count] |= usize(1) << (s & (usize.bit_count - 1));
9971008}
9981009
9991010pub fn sigismember(set: &const sigset_t, sig: u6) bool {
10001011 const s = sig - 1;
1001 return ((*set)[usize(s) / usize.bit_count] & (usize(1) << (s & (usize.bit_count - 1)))) != 0;
1012 return ((set.*)[usize(s) / usize.bit_count] & (usize(1) << (s & (usize.bit_count - 1)))) != 0;
10021013}
10031014
10041015pub const in_port_t = u16;
......@@ -1062,9 +1073,7 @@ pub fn recvmsg(fd: i32, msg: &msghdr, flags: u32) usize {
10621073 return syscall3(SYS_recvmsg, usize(fd), @ptrToInt(msg), flags);
10631074}
10641075
1065pub fn recvfrom(fd: i32, noalias buf: &u8, len: usize, flags: u32,
1066 noalias addr: ?&sockaddr, noalias alen: ?&socklen_t) usize
1067{
1076pub fn recvfrom(fd: i32, noalias buf: &u8, len: usize, flags: u32, noalias addr: ?&sockaddr, noalias alen: ?&socklen_t) usize {
10681077 return syscall6(SYS_recvfrom, usize(fd), @ptrToInt(buf), len, flags, @ptrToInt(addr), @ptrToInt(alen));
10691078}
10701079
......@@ -1132,25 +1141,16 @@ pub fn fgetxattr(fd: usize, name: &const u8, value: &void, size: usize) usize {
11321141 return syscall4(SYS_lgetxattr, fd, @ptrToInt(name), @ptrToInt(value), size);
11331142}
11341143
1135pub fn setxattr(path: &const u8, name: &const u8, value: &const void,
1136 size: usize, flags: usize) usize {
1137
1138 return syscall5(SYS_setxattr, @ptrToInt(path), @ptrToInt(name), @ptrToInt(value),
1139 size, flags);
1144pub fn setxattr(path: &const u8, name: &const u8, value: &const void, size: usize, flags: usize) usize {
1145 return syscall5(SYS_setxattr, @ptrToInt(path), @ptrToInt(name), @ptrToInt(value), size, flags);
11401146}
11411147
1142pub fn lsetxattr(path: &const u8, name: &const u8, value: &const void,
1143 size: usize, flags: usize) usize {
1144
1145 return syscall5(SYS_lsetxattr, @ptrToInt(path), @ptrToInt(name), @ptrToInt(value),
1146 size, flags);
1148pub fn lsetxattr(path: &const u8, name: &const u8, value: &const void, size: usize, flags: usize) usize {
1149 return syscall5(SYS_lsetxattr, @ptrToInt(path), @ptrToInt(name), @ptrToInt(value), size, flags);
11471150}
11481151
1149pub fn fsetxattr(fd: usize, name: &const u8, value: &const void,
1150 size: usize, flags: usize) usize {
1151
1152 return syscall5(SYS_fsetxattr, fd, @ptrToInt(name), @ptrToInt(value),
1153 size, flags);
1152pub fn fsetxattr(fd: usize, name: &const u8, value: &const void, size: usize, flags: usize) usize {
1153 return syscall5(SYS_fsetxattr, fd, @ptrToInt(name), @ptrToInt(value), size, flags);
11541154}
11551155
11561156pub fn removexattr(path: &const u8, name: &const u8) usize {
......@@ -1199,7 +1199,7 @@ pub fn timerfd_create(clockid: i32, flags: u32) usize {
11991199
12001200pub const itimerspec = extern struct {
12011201 it_interval: timespec,
1202 it_value: timespec
1202 it_value: timespec,
12031203};
12041204
12051205pub fn timerfd_gettime(fd: i32, curr_value: &itimerspec) usize {
......@@ -1211,30 +1211,30 @@ pub fn timerfd_settime(fd: i32, flags: u32, new_value: &const itimerspec, old_va
12111211}
12121212
12131213pub const _LINUX_CAPABILITY_VERSION_1 = 0x19980330;
1214pub const _LINUX_CAPABILITY_U32S_1 = 1;
1214pub const _LINUX_CAPABILITY_U32S_1 = 1;
12151215
12161216pub const _LINUX_CAPABILITY_VERSION_2 = 0x20071026;
1217pub const _LINUX_CAPABILITY_U32S_2 = 2;
1217pub const _LINUX_CAPABILITY_U32S_2 = 2;
12181218
12191219pub const _LINUX_CAPABILITY_VERSION_3 = 0x20080522;
1220pub const _LINUX_CAPABILITY_U32S_3 = 2;
1220pub const _LINUX_CAPABILITY_U32S_3 = 2;
12211221
1222pub const VFS_CAP_REVISION_MASK = 0xFF000000;
1223pub const VFS_CAP_REVISION_SHIFT = 24;
1224pub const VFS_CAP_FLAGS_MASK = ~VFS_CAP_REVISION_MASK;
1222pub const VFS_CAP_REVISION_MASK = 0xFF000000;
1223pub const VFS_CAP_REVISION_SHIFT = 24;
1224pub const VFS_CAP_FLAGS_MASK = ~VFS_CAP_REVISION_MASK;
12251225pub const VFS_CAP_FLAGS_EFFECTIVE = 0x000001;
12261226
12271227pub const VFS_CAP_REVISION_1 = 0x01000000;
1228pub const VFS_CAP_U32_1 = 1;
1229pub const XATTR_CAPS_SZ_1 = @sizeOf(u32)*(1 + 2*VFS_CAP_U32_1);
1228pub const VFS_CAP_U32_1 = 1;
1229pub const XATTR_CAPS_SZ_1 = @sizeOf(u32) * (1 + 2 * VFS_CAP_U32_1);
12301230
12311231pub const VFS_CAP_REVISION_2 = 0x02000000;
1232pub const VFS_CAP_U32_2 = 2;
1233pub const XATTR_CAPS_SZ_2 = @sizeOf(u32)*(1 + 2*VFS_CAP_U32_2);
1232pub const VFS_CAP_U32_2 = 2;
1233pub const XATTR_CAPS_SZ_2 = @sizeOf(u32) * (1 + 2 * VFS_CAP_U32_2);
12341234
1235pub const XATTR_CAPS_SZ = XATTR_CAPS_SZ_2;
1236pub const VFS_CAP_U32 = VFS_CAP_U32_2;
1237pub const VFS_CAP_REVISION = VFS_CAP_REVISION_2;
1235pub const XATTR_CAPS_SZ = XATTR_CAPS_SZ_2;
1236pub const VFS_CAP_U32 = VFS_CAP_U32_2;
1237pub const VFS_CAP_REVISION = VFS_CAP_REVISION_2;
12381238
12391239pub const vfs_cap_data = extern struct {
12401240 //all of these are mandated as little endian
......@@ -1245,49 +1245,48 @@ pub const vfs_cap_data = extern struct {
12451245 };
12461246
12471247 magic_etc: u32,
1248 data: [VFS_CAP_U32]Data,
1248 data: [VFS_CAP_U32]Data,
12491249};
12501250
1251
1252pub const CAP_CHOWN = 0;
1253pub const CAP_DAC_OVERRIDE = 1;
1254pub const CAP_DAC_READ_SEARCH = 2;
1255pub const CAP_FOWNER = 3;
1256pub const CAP_FSETID = 4;
1257pub const CAP_KILL = 5;
1258pub const CAP_SETGID = 6;
1259pub const CAP_SETUID = 7;
1260pub const CAP_SETPCAP = 8;
1261pub const CAP_LINUX_IMMUTABLE = 9;
1262pub const CAP_NET_BIND_SERVICE = 10;
1263pub const CAP_NET_BROADCAST = 11;
1264pub const CAP_NET_ADMIN = 12;
1265pub const CAP_NET_RAW = 13;
1266pub const CAP_IPC_LOCK = 14;
1267pub const CAP_IPC_OWNER = 15;
1268pub const CAP_SYS_MODULE = 16;
1269pub const CAP_SYS_RAWIO = 17;
1270pub const CAP_SYS_CHROOT = 18;
1271pub const CAP_SYS_PTRACE = 19;
1272pub const CAP_SYS_PACCT = 20;
1273pub const CAP_SYS_ADMIN = 21;
1274pub const CAP_SYS_BOOT = 22;
1275pub const CAP_SYS_NICE = 23;
1276pub const CAP_SYS_RESOURCE = 24;
1277pub const CAP_SYS_TIME = 25;
1278pub const CAP_SYS_TTY_CONFIG = 26;
1279pub const CAP_MKNOD = 27;
1280pub const CAP_LEASE = 28;
1281pub const CAP_AUDIT_WRITE = 29;
1282pub const CAP_AUDIT_CONTROL = 30;
1283pub const CAP_SETFCAP = 31;
1284pub const CAP_MAC_OVERRIDE = 32;
1285pub const CAP_MAC_ADMIN = 33;
1286pub const CAP_SYSLOG = 34;
1287pub const CAP_WAKE_ALARM = 35;
1288pub const CAP_BLOCK_SUSPEND = 36;
1289pub const CAP_AUDIT_READ = 37;
1290pub const CAP_LAST_CAP = CAP_AUDIT_READ;
1251pub const CAP_CHOWN = 0;
1252pub const CAP_DAC_OVERRIDE = 1;
1253pub const CAP_DAC_READ_SEARCH = 2;
1254pub const CAP_FOWNER = 3;
1255pub const CAP_FSETID = 4;
1256pub const CAP_KILL = 5;
1257pub const CAP_SETGID = 6;
1258pub const CAP_SETUID = 7;
1259pub const CAP_SETPCAP = 8;
1260pub const CAP_LINUX_IMMUTABLE = 9;
1261pub const CAP_NET_BIND_SERVICE = 10;
1262pub const CAP_NET_BROADCAST = 11;
1263pub const CAP_NET_ADMIN = 12;
1264pub const CAP_NET_RAW = 13;
1265pub const CAP_IPC_LOCK = 14;
1266pub const CAP_IPC_OWNER = 15;
1267pub const CAP_SYS_MODULE = 16;
1268pub const CAP_SYS_RAWIO = 17;
1269pub const CAP_SYS_CHROOT = 18;
1270pub const CAP_SYS_PTRACE = 19;
1271pub const CAP_SYS_PACCT = 20;
1272pub const CAP_SYS_ADMIN = 21;
1273pub const CAP_SYS_BOOT = 22;
1274pub const CAP_SYS_NICE = 23;
1275pub const CAP_SYS_RESOURCE = 24;
1276pub const CAP_SYS_TIME = 25;
1277pub const CAP_SYS_TTY_CONFIG = 26;
1278pub const CAP_MKNOD = 27;
1279pub const CAP_LEASE = 28;
1280pub const CAP_AUDIT_WRITE = 29;
1281pub const CAP_AUDIT_CONTROL = 30;
1282pub const CAP_SETFCAP = 31;
1283pub const CAP_MAC_OVERRIDE = 32;
1284pub const CAP_MAC_ADMIN = 33;
1285pub const CAP_SYSLOG = 34;
1286pub const CAP_WAKE_ALARM = 35;
1287pub const CAP_BLOCK_SUSPEND = 36;
1288pub const CAP_AUDIT_READ = 37;
1289pub const CAP_LAST_CAP = CAP_AUDIT_READ;
12911290
12921291pub fn cap_valid(u8: x) bool {
12931292 return x >= 0 and x <= CAP_LAST_CAP;
std/special/bootstrap.zig+4-4
......@@ -27,10 +27,10 @@ extern fn zen_start() noreturn {
2727nakedcc fn _start() noreturn {
2828 switch (builtin.arch) {
2929 builtin.Arch.x86_64 => {
30 argc_ptr = asm("lea (%%rsp), %[argc]": [argc] "=r" (-> &usize));
30 argc_ptr = asm ("lea (%%rsp), %[argc]" : [argc] "=r" (-> &usize));
3131 },
3232 builtin.Arch.i386 => {
33 argc_ptr = asm("lea (%%esp), %[argc]": [argc] "=r" (-> &usize));
33 argc_ptr = asm ("lea (%%esp), %[argc]" : [argc] "=r" (-> &usize));
3434 },
3535 else => @compileError("unsupported arch"),
3636 }
......@@ -46,7 +46,7 @@ extern fn WinMainCRTStartup() noreturn {
4646}
4747
4848fn posixCallMainAndExit() noreturn {
49 const argc = *argc_ptr;
49 const argc = argc_ptr.*;
5050 const argv = @ptrCast(&&u8, &argc_ptr[1]);
5151 const envp_nullable = @ptrCast(&?&u8, &argv[argc + 1]);
5252 var envp_count: usize = 0;
......@@ -56,7 +56,7 @@ fn posixCallMainAndExit() noreturn {
5656 const auxv = &@ptrCast(&usize, envp.ptr)[envp_count + 1];
5757 var i: usize = 0;
5858 while (auxv[i] != 0) : (i += 2) {
59 if (auxv[i] < std.os.linux_aux_raw.len) std.os.linux_aux_raw[auxv[i]] = auxv[i+1];
59 if (auxv[i] < std.os.linux_aux_raw.len) std.os.linux_aux_raw[auxv[i]] = auxv[i + 1];
6060 }
6161 std.debug.assert(std.os.linux_aux_raw[std.elf.AT_PAGESZ] == std.os.page_size);
6262 }
std/special/compiler_rt/fixuint.zig+2-4
......@@ -36,12 +36,10 @@ pub fn fixuint(comptime fp_t: type, comptime fixuint_t: type, a: fp_t) fixuint_t
3636 const significand: rep_t = (aAbs & significandMask) | implicitBit;
3737
3838 // If either the value or the exponent is negative, the result is zero.
39 if (sign == -1 or exponent < 0)
40 return 0;
39 if (sign == -1 or exponent < 0) return 0;
4140
4241 // If the value is too large for the integer type, saturate.
43 if (c_uint(exponent) >= fixuint_t.bit_count)
44 return ~fixuint_t(0);
42 if (c_uint(exponent) >= fixuint_t.bit_count) return ~fixuint_t(0);
4543
4644 // If 0 <= exponent < significandBits, right shift to get the result.
4745 // Otherwise, shift left.
std/special/compiler_rt/fixunsdfdi.zig-1
......@@ -9,4 +9,3 @@ pub extern fn __fixunsdfdi(a: f64) u64 {
99test "import fixunsdfdi" {
1010 _ = @import("fixunsdfdi_test.zig");
1111}
12
std/special/compiler_rt/fixunsdfsi.zig-1
......@@ -9,4 +9,3 @@ pub extern fn __fixunsdfsi(a: f64) u32 {
99test "import fixunsdfsi" {
1010 _ = @import("fixunsdfsi_test.zig");
1111}
12
std/special/compiler_rt/fixunssfti.zig-1
......@@ -9,4 +9,3 @@ pub extern fn __fixunssfti(a: f32) u128 {
99test "import fixunssfti" {
1010 _ = @import("fixunssfti_test.zig");
1111}
12
std/special/compiler_rt/fixunstfti.zig-1
......@@ -9,4 +9,3 @@ pub extern fn __fixunstfti(a: f128) u128 {
99test "import fixunstfti" {
1010 _ = @import("fixunstfti_test.zig");
1111}
12
std/special/compiler_rt/index.zig+674-144
......@@ -91,9 +91,10 @@ pub fn setXmm0(comptime T: type, value: T) void {
9191 const aligned_value: T align(16) = value;
9292 asm volatile (
9393 \\movaps (%[ptr]), %%xmm0
94 :
95 : [ptr] "r" (&aligned_value)
96 : "xmm0");
94
95 :
96 : [ptr] "r" (&aligned_value)
97 : "xmm0");
9798}
9899
99100extern fn __udivdi3(a: u64, b: u64) u64 {
......@@ -282,26 +283,27 @@ extern fn __udivmodsi4(a: u32, b: u32, rem: &u32) u32 {
282283 @setRuntimeSafety(is_test);
283284
284285 const d = __udivsi3(a, b);
285 *rem = u32(i32(a) -% (i32(d) * i32(b)));
286 rem.* = u32(i32(a) -% (i32(d) * i32(b)));
286287 return d;
287288}
288289
289
290290extern fn __udivsi3(n: u32, d: u32) u32 {
291291 @setRuntimeSafety(is_test);
292292
293293 const n_uword_bits: c_uint = u32.bit_count;
294294 // special cases
295 if (d == 0)
296 return 0; // ?!
297 if (n == 0)
298 return 0;
295 if (d == 0) return 0; // ?!
296 if (n == 0) return 0;
299297 var sr = @bitCast(c_uint, c_int(@clz(d)) - c_int(@clz(n)));
300298 // 0 <= sr <= n_uword_bits - 1 or sr large
301 if (sr > n_uword_bits - 1) // d > r
299 if (sr > n_uword_bits - 1) {
300 // d > r
302301 return 0;
303 if (sr == n_uword_bits - 1) // d == 1
302 }
303 if (sr == n_uword_bits - 1) {
304 // d == 1
304305 return n;
306 }
305307 sr += 1;
306308 // 1 <= sr <= n_uword_bits - 1
307309 // Not a special case
......@@ -340,139 +342,667 @@ fn test_one_umoddi3(a: u64, b: u64, expected_r: u64) void {
340342}
341343
342344test "test_udivsi3" {
343 const cases = [][3]u32 {
344 []u32{0x00000000, 0x00000001, 0x00000000},
345 []u32{0x00000000, 0x00000002, 0x00000000},
346 []u32{0x00000000, 0x00000003, 0x00000000},
347 []u32{0x00000000, 0x00000010, 0x00000000},
348 []u32{0x00000000, 0x078644FA, 0x00000000},
349 []u32{0x00000000, 0x0747AE14, 0x00000000},
350 []u32{0x00000000, 0x7FFFFFFF, 0x00000000},
351 []u32{0x00000000, 0x80000000, 0x00000000},
352 []u32{0x00000000, 0xFFFFFFFD, 0x00000000},
353 []u32{0x00000000, 0xFFFFFFFE, 0x00000000},
354 []u32{0x00000000, 0xFFFFFFFF, 0x00000000},
355 []u32{0x00000001, 0x00000001, 0x00000001},
356 []u32{0x00000001, 0x00000002, 0x00000000},
357 []u32{0x00000001, 0x00000003, 0x00000000},
358 []u32{0x00000001, 0x00000010, 0x00000000},
359 []u32{0x00000001, 0x078644FA, 0x00000000},
360 []u32{0x00000001, 0x0747AE14, 0x00000000},
361 []u32{0x00000001, 0x7FFFFFFF, 0x00000000},
362 []u32{0x00000001, 0x80000000, 0x00000000},
363 []u32{0x00000001, 0xFFFFFFFD, 0x00000000},
364 []u32{0x00000001, 0xFFFFFFFE, 0x00000000},
365 []u32{0x00000001, 0xFFFFFFFF, 0x00000000},
366 []u32{0x00000002, 0x00000001, 0x00000002},
367 []u32{0x00000002, 0x00000002, 0x00000001},
368 []u32{0x00000002, 0x00000003, 0x00000000},
369 []u32{0x00000002, 0x00000010, 0x00000000},
370 []u32{0x00000002, 0x078644FA, 0x00000000},
371 []u32{0x00000002, 0x0747AE14, 0x00000000},
372 []u32{0x00000002, 0x7FFFFFFF, 0x00000000},
373 []u32{0x00000002, 0x80000000, 0x00000000},
374 []u32{0x00000002, 0xFFFFFFFD, 0x00000000},
375 []u32{0x00000002, 0xFFFFFFFE, 0x00000000},
376 []u32{0x00000002, 0xFFFFFFFF, 0x00000000},
377 []u32{0x00000003, 0x00000001, 0x00000003},
378 []u32{0x00000003, 0x00000002, 0x00000001},
379 []u32{0x00000003, 0x00000003, 0x00000001},
380 []u32{0x00000003, 0x00000010, 0x00000000},
381 []u32{0x00000003, 0x078644FA, 0x00000000},
382 []u32{0x00000003, 0x0747AE14, 0x00000000},
383 []u32{0x00000003, 0x7FFFFFFF, 0x00000000},
384 []u32{0x00000003, 0x80000000, 0x00000000},
385 []u32{0x00000003, 0xFFFFFFFD, 0x00000000},
386 []u32{0x00000003, 0xFFFFFFFE, 0x00000000},
387 []u32{0x00000003, 0xFFFFFFFF, 0x00000000},
388 []u32{0x00000010, 0x00000001, 0x00000010},
389 []u32{0x00000010, 0x00000002, 0x00000008},
390 []u32{0x00000010, 0x00000003, 0x00000005},
391 []u32{0x00000010, 0x00000010, 0x00000001},
392 []u32{0x00000010, 0x078644FA, 0x00000000},
393 []u32{0x00000010, 0x0747AE14, 0x00000000},
394 []u32{0x00000010, 0x7FFFFFFF, 0x00000000},
395 []u32{0x00000010, 0x80000000, 0x00000000},
396 []u32{0x00000010, 0xFFFFFFFD, 0x00000000},
397 []u32{0x00000010, 0xFFFFFFFE, 0x00000000},
398 []u32{0x00000010, 0xFFFFFFFF, 0x00000000},
399 []u32{0x078644FA, 0x00000001, 0x078644FA},
400 []u32{0x078644FA, 0x00000002, 0x03C3227D},
401 []u32{0x078644FA, 0x00000003, 0x028216FE},
402 []u32{0x078644FA, 0x00000010, 0x0078644F},
403 []u32{0x078644FA, 0x078644FA, 0x00000001},
404 []u32{0x078644FA, 0x0747AE14, 0x00000001},
405 []u32{0x078644FA, 0x7FFFFFFF, 0x00000000},
406 []u32{0x078644FA, 0x80000000, 0x00000000},
407 []u32{0x078644FA, 0xFFFFFFFD, 0x00000000},
408 []u32{0x078644FA, 0xFFFFFFFE, 0x00000000},
409 []u32{0x078644FA, 0xFFFFFFFF, 0x00000000},
410 []u32{0x0747AE14, 0x00000001, 0x0747AE14},
411 []u32{0x0747AE14, 0x00000002, 0x03A3D70A},
412 []u32{0x0747AE14, 0x00000003, 0x026D3A06},
413 []u32{0x0747AE14, 0x00000010, 0x00747AE1},
414 []u32{0x0747AE14, 0x078644FA, 0x00000000},
415 []u32{0x0747AE14, 0x0747AE14, 0x00000001},
416 []u32{0x0747AE14, 0x7FFFFFFF, 0x00000000},
417 []u32{0x0747AE14, 0x80000000, 0x00000000},
418 []u32{0x0747AE14, 0xFFFFFFFD, 0x00000000},
419 []u32{0x0747AE14, 0xFFFFFFFE, 0x00000000},
420 []u32{0x0747AE14, 0xFFFFFFFF, 0x00000000},
421 []u32{0x7FFFFFFF, 0x00000001, 0x7FFFFFFF},
422 []u32{0x7FFFFFFF, 0x00000002, 0x3FFFFFFF},
423 []u32{0x7FFFFFFF, 0x00000003, 0x2AAAAAAA},
424 []u32{0x7FFFFFFF, 0x00000010, 0x07FFFFFF},
425 []u32{0x7FFFFFFF, 0x078644FA, 0x00000011},
426 []u32{0x7FFFFFFF, 0x0747AE14, 0x00000011},
427 []u32{0x7FFFFFFF, 0x7FFFFFFF, 0x00000001},
428 []u32{0x7FFFFFFF, 0x80000000, 0x00000000},
429 []u32{0x7FFFFFFF, 0xFFFFFFFD, 0x00000000},
430 []u32{0x7FFFFFFF, 0xFFFFFFFE, 0x00000000},
431 []u32{0x7FFFFFFF, 0xFFFFFFFF, 0x00000000},
432 []u32{0x80000000, 0x00000001, 0x80000000},
433 []u32{0x80000000, 0x00000002, 0x40000000},
434 []u32{0x80000000, 0x00000003, 0x2AAAAAAA},
435 []u32{0x80000000, 0x00000010, 0x08000000},
436 []u32{0x80000000, 0x078644FA, 0x00000011},
437 []u32{0x80000000, 0x0747AE14, 0x00000011},
438 []u32{0x80000000, 0x7FFFFFFF, 0x00000001},
439 []u32{0x80000000, 0x80000000, 0x00000001},
440 []u32{0x80000000, 0xFFFFFFFD, 0x00000000},
441 []u32{0x80000000, 0xFFFFFFFE, 0x00000000},
442 []u32{0x80000000, 0xFFFFFFFF, 0x00000000},
443 []u32{0xFFFFFFFD, 0x00000001, 0xFFFFFFFD},
444 []u32{0xFFFFFFFD, 0x00000002, 0x7FFFFFFE},
445 []u32{0xFFFFFFFD, 0x00000003, 0x55555554},
446 []u32{0xFFFFFFFD, 0x00000010, 0x0FFFFFFF},
447 []u32{0xFFFFFFFD, 0x078644FA, 0x00000022},
448 []u32{0xFFFFFFFD, 0x0747AE14, 0x00000023},
449 []u32{0xFFFFFFFD, 0x7FFFFFFF, 0x00000001},
450 []u32{0xFFFFFFFD, 0x80000000, 0x00000001},
451 []u32{0xFFFFFFFD, 0xFFFFFFFD, 0x00000001},
452 []u32{0xFFFFFFFD, 0xFFFFFFFE, 0x00000000},
453 []u32{0xFFFFFFFD, 0xFFFFFFFF, 0x00000000},
454 []u32{0xFFFFFFFE, 0x00000001, 0xFFFFFFFE},
455 []u32{0xFFFFFFFE, 0x00000002, 0x7FFFFFFF},
456 []u32{0xFFFFFFFE, 0x00000003, 0x55555554},
457 []u32{0xFFFFFFFE, 0x00000010, 0x0FFFFFFF},
458 []u32{0xFFFFFFFE, 0x078644FA, 0x00000022},
459 []u32{0xFFFFFFFE, 0x0747AE14, 0x00000023},
460 []u32{0xFFFFFFFE, 0x7FFFFFFF, 0x00000002},
461 []u32{0xFFFFFFFE, 0x80000000, 0x00000001},
462 []u32{0xFFFFFFFE, 0xFFFFFFFD, 0x00000001},
463 []u32{0xFFFFFFFE, 0xFFFFFFFE, 0x00000001},
464 []u32{0xFFFFFFFE, 0xFFFFFFFF, 0x00000000},
465 []u32{0xFFFFFFFF, 0x00000001, 0xFFFFFFFF},
466 []u32{0xFFFFFFFF, 0x00000002, 0x7FFFFFFF},
467 []u32{0xFFFFFFFF, 0x00000003, 0x55555555},
468 []u32{0xFFFFFFFF, 0x00000010, 0x0FFFFFFF},
469 []u32{0xFFFFFFFF, 0x078644FA, 0x00000022},
470 []u32{0xFFFFFFFF, 0x0747AE14, 0x00000023},
471 []u32{0xFFFFFFFF, 0x7FFFFFFF, 0x00000002},
472 []u32{0xFFFFFFFF, 0x80000000, 0x00000001},
473 []u32{0xFFFFFFFF, 0xFFFFFFFD, 0x00000001},
474 []u32{0xFFFFFFFF, 0xFFFFFFFE, 0x00000001},
475 []u32{0xFFFFFFFF, 0xFFFFFFFF, 0x00000001},
345 const cases = [][3]u32{
346 []u32{
347 0x00000000,
348 0x00000001,
349 0x00000000,
350 },
351 []u32{
352 0x00000000,
353 0x00000002,
354 0x00000000,
355 },
356 []u32{
357 0x00000000,
358 0x00000003,
359 0x00000000,
360 },
361 []u32{
362 0x00000000,
363 0x00000010,
364 0x00000000,
365 },
366 []u32{
367 0x00000000,
368 0x078644FA,
369 0x00000000,
370 },
371 []u32{
372 0x00000000,
373 0x0747AE14,
374 0x00000000,
375 },
376 []u32{
377 0x00000000,
378 0x7FFFFFFF,
379 0x00000000,
380 },
381 []u32{
382 0x00000000,
383 0x80000000,
384 0x00000000,
385 },
386 []u32{
387 0x00000000,
388 0xFFFFFFFD,
389 0x00000000,
390 },
391 []u32{
392 0x00000000,
393 0xFFFFFFFE,
394 0x00000000,
395 },
396 []u32{
397 0x00000000,
398 0xFFFFFFFF,
399 0x00000000,
400 },
401 []u32{
402 0x00000001,
403 0x00000001,
404 0x00000001,
405 },
406 []u32{
407 0x00000001,
408 0x00000002,
409 0x00000000,
410 },
411 []u32{
412 0x00000001,
413 0x00000003,
414 0x00000000,
415 },
416 []u32{
417 0x00000001,
418 0x00000010,
419 0x00000000,
420 },
421 []u32{
422 0x00000001,
423 0x078644FA,
424 0x00000000,
425 },
426 []u32{
427 0x00000001,
428 0x0747AE14,
429 0x00000000,
430 },
431 []u32{
432 0x00000001,
433 0x7FFFFFFF,
434 0x00000000,
435 },
436 []u32{
437 0x00000001,
438 0x80000000,
439 0x00000000,
440 },
441 []u32{
442 0x00000001,
443 0xFFFFFFFD,
444 0x00000000,
445 },
446 []u32{
447 0x00000001,
448 0xFFFFFFFE,
449 0x00000000,
450 },
451 []u32{
452 0x00000001,
453 0xFFFFFFFF,
454 0x00000000,
455 },
456 []u32{
457 0x00000002,
458 0x00000001,
459 0x00000002,
460 },
461 []u32{
462 0x00000002,
463 0x00000002,
464 0x00000001,
465 },
466 []u32{
467 0x00000002,
468 0x00000003,
469 0x00000000,
470 },
471 []u32{
472 0x00000002,
473 0x00000010,
474 0x00000000,
475 },
476 []u32{
477 0x00000002,
478 0x078644FA,
479 0x00000000,
480 },
481 []u32{
482 0x00000002,
483 0x0747AE14,
484 0x00000000,
485 },
486 []u32{
487 0x00000002,
488 0x7FFFFFFF,
489 0x00000000,
490 },
491 []u32{
492 0x00000002,
493 0x80000000,
494 0x00000000,
495 },
496 []u32{
497 0x00000002,
498 0xFFFFFFFD,
499 0x00000000,
500 },
501 []u32{
502 0x00000002,
503 0xFFFFFFFE,
504 0x00000000,
505 },
506 []u32{
507 0x00000002,
508 0xFFFFFFFF,
509 0x00000000,
510 },
511 []u32{
512 0x00000003,
513 0x00000001,
514 0x00000003,
515 },
516 []u32{
517 0x00000003,
518 0x00000002,
519 0x00000001,
520 },
521 []u32{
522 0x00000003,
523 0x00000003,
524 0x00000001,
525 },
526 []u32{
527 0x00000003,
528 0x00000010,
529 0x00000000,
530 },
531 []u32{
532 0x00000003,
533 0x078644FA,
534 0x00000000,
535 },
536 []u32{
537 0x00000003,
538 0x0747AE14,
539 0x00000000,
540 },
541 []u32{
542 0x00000003,
543 0x7FFFFFFF,
544 0x00000000,
545 },
546 []u32{
547 0x00000003,
548 0x80000000,
549 0x00000000,
550 },
551 []u32{
552 0x00000003,
553 0xFFFFFFFD,
554 0x00000000,
555 },
556 []u32{
557 0x00000003,
558 0xFFFFFFFE,
559 0x00000000,
560 },
561 []u32{
562 0x00000003,
563 0xFFFFFFFF,
564 0x00000000,
565 },
566 []u32{
567 0x00000010,
568 0x00000001,
569 0x00000010,
570 },
571 []u32{
572 0x00000010,
573 0x00000002,
574 0x00000008,
575 },
576 []u32{
577 0x00000010,
578 0x00000003,
579 0x00000005,
580 },
581 []u32{
582 0x00000010,
583 0x00000010,
584 0x00000001,
585 },
586 []u32{
587 0x00000010,
588 0x078644FA,
589 0x00000000,
590 },
591 []u32{
592 0x00000010,
593 0x0747AE14,
594 0x00000000,
595 },
596 []u32{
597 0x00000010,
598 0x7FFFFFFF,
599 0x00000000,
600 },
601 []u32{
602 0x00000010,
603 0x80000000,
604 0x00000000,
605 },
606 []u32{
607 0x00000010,
608 0xFFFFFFFD,
609 0x00000000,
610 },
611 []u32{
612 0x00000010,
613 0xFFFFFFFE,
614 0x00000000,
615 },
616 []u32{
617 0x00000010,
618 0xFFFFFFFF,
619 0x00000000,
620 },
621 []u32{
622 0x078644FA,
623 0x00000001,
624 0x078644FA,
625 },
626 []u32{
627 0x078644FA,
628 0x00000002,
629 0x03C3227D,
630 },
631 []u32{
632 0x078644FA,
633 0x00000003,
634 0x028216FE,
635 },
636 []u32{
637 0x078644FA,
638 0x00000010,
639 0x0078644F,
640 },
641 []u32{
642 0x078644FA,
643 0x078644FA,
644 0x00000001,
645 },
646 []u32{
647 0x078644FA,
648 0x0747AE14,
649 0x00000001,
650 },
651 []u32{
652 0x078644FA,
653 0x7FFFFFFF,
654 0x00000000,
655 },
656 []u32{
657 0x078644FA,
658 0x80000000,
659 0x00000000,
660 },
661 []u32{
662 0x078644FA,
663 0xFFFFFFFD,
664 0x00000000,
665 },
666 []u32{
667 0x078644FA,
668 0xFFFFFFFE,
669 0x00000000,
670 },
671 []u32{
672 0x078644FA,
673 0xFFFFFFFF,
674 0x00000000,
675 },
676 []u32{
677 0x0747AE14,
678 0x00000001,
679 0x0747AE14,
680 },
681 []u32{
682 0x0747AE14,
683 0x00000002,
684 0x03A3D70A,
685 },
686 []u32{
687 0x0747AE14,
688 0x00000003,
689 0x026D3A06,
690 },
691 []u32{
692 0x0747AE14,
693 0x00000010,
694 0x00747AE1,
695 },
696 []u32{
697 0x0747AE14,
698 0x078644FA,
699 0x00000000,
700 },
701 []u32{
702 0x0747AE14,
703 0x0747AE14,
704 0x00000001,
705 },
706 []u32{
707 0x0747AE14,
708 0x7FFFFFFF,
709 0x00000000,
710 },
711 []u32{
712 0x0747AE14,
713 0x80000000,
714 0x00000000,
715 },
716 []u32{
717 0x0747AE14,
718 0xFFFFFFFD,
719 0x00000000,
720 },
721 []u32{
722 0x0747AE14,
723 0xFFFFFFFE,
724 0x00000000,
725 },
726 []u32{
727 0x0747AE14,
728 0xFFFFFFFF,
729 0x00000000,
730 },
731 []u32{
732 0x7FFFFFFF,
733 0x00000001,
734 0x7FFFFFFF,
735 },
736 []u32{
737 0x7FFFFFFF,
738 0x00000002,
739 0x3FFFFFFF,
740 },
741 []u32{
742 0x7FFFFFFF,
743 0x00000003,
744 0x2AAAAAAA,
745 },
746 []u32{
747 0x7FFFFFFF,
748 0x00000010,
749 0x07FFFFFF,
750 },
751 []u32{
752 0x7FFFFFFF,
753 0x078644FA,
754 0x00000011,
755 },
756 []u32{
757 0x7FFFFFFF,
758 0x0747AE14,
759 0x00000011,
760 },
761 []u32{
762 0x7FFFFFFF,
763 0x7FFFFFFF,
764 0x00000001,
765 },
766 []u32{
767 0x7FFFFFFF,
768 0x80000000,
769 0x00000000,
770 },
771 []u32{
772 0x7FFFFFFF,
773 0xFFFFFFFD,
774 0x00000000,
775 },
776 []u32{
777 0x7FFFFFFF,
778 0xFFFFFFFE,
779 0x00000000,
780 },
781 []u32{
782 0x7FFFFFFF,
783 0xFFFFFFFF,
784 0x00000000,
785 },
786 []u32{
787 0x80000000,
788 0x00000001,
789 0x80000000,
790 },
791 []u32{
792 0x80000000,
793 0x00000002,
794 0x40000000,
795 },
796 []u32{
797 0x80000000,
798 0x00000003,
799 0x2AAAAAAA,
800 },
801 []u32{
802 0x80000000,
803 0x00000010,
804 0x08000000,
805 },
806 []u32{
807 0x80000000,
808 0x078644FA,
809 0x00000011,
810 },
811 []u32{
812 0x80000000,
813 0x0747AE14,
814 0x00000011,
815 },
816 []u32{
817 0x80000000,
818 0x7FFFFFFF,
819 0x00000001,
820 },
821 []u32{
822 0x80000000,
823 0x80000000,
824 0x00000001,
825 },
826 []u32{
827 0x80000000,
828 0xFFFFFFFD,
829 0x00000000,
830 },
831 []u32{
832 0x80000000,
833 0xFFFFFFFE,
834 0x00000000,
835 },
836 []u32{
837 0x80000000,
838 0xFFFFFFFF,
839 0x00000000,
840 },
841 []u32{
842 0xFFFFFFFD,
843 0x00000001,
844 0xFFFFFFFD,
845 },
846 []u32{
847 0xFFFFFFFD,
848 0x00000002,
849 0x7FFFFFFE,
850 },
851 []u32{
852 0xFFFFFFFD,
853 0x00000003,
854 0x55555554,
855 },
856 []u32{
857 0xFFFFFFFD,
858 0x00000010,
859 0x0FFFFFFF,
860 },
861 []u32{
862 0xFFFFFFFD,
863 0x078644FA,
864 0x00000022,
865 },
866 []u32{
867 0xFFFFFFFD,
868 0x0747AE14,
869 0x00000023,
870 },
871 []u32{
872 0xFFFFFFFD,
873 0x7FFFFFFF,
874 0x00000001,
875 },
876 []u32{
877 0xFFFFFFFD,
878 0x80000000,
879 0x00000001,
880 },
881 []u32{
882 0xFFFFFFFD,
883 0xFFFFFFFD,
884 0x00000001,
885 },
886 []u32{
887 0xFFFFFFFD,
888 0xFFFFFFFE,
889 0x00000000,
890 },
891 []u32{
892 0xFFFFFFFD,
893 0xFFFFFFFF,
894 0x00000000,
895 },
896 []u32{
897 0xFFFFFFFE,
898 0x00000001,
899 0xFFFFFFFE,
900 },
901 []u32{
902 0xFFFFFFFE,
903 0x00000002,
904 0x7FFFFFFF,
905 },
906 []u32{
907 0xFFFFFFFE,
908 0x00000003,
909 0x55555554,
910 },
911 []u32{
912 0xFFFFFFFE,
913 0x00000010,
914 0x0FFFFFFF,
915 },
916 []u32{
917 0xFFFFFFFE,
918 0x078644FA,
919 0x00000022,
920 },
921 []u32{
922 0xFFFFFFFE,
923 0x0747AE14,
924 0x00000023,
925 },
926 []u32{
927 0xFFFFFFFE,
928 0x7FFFFFFF,
929 0x00000002,
930 },
931 []u32{
932 0xFFFFFFFE,
933 0x80000000,
934 0x00000001,
935 },
936 []u32{
937 0xFFFFFFFE,
938 0xFFFFFFFD,
939 0x00000001,
940 },
941 []u32{
942 0xFFFFFFFE,
943 0xFFFFFFFE,
944 0x00000001,
945 },
946 []u32{
947 0xFFFFFFFE,
948 0xFFFFFFFF,
949 0x00000000,
950 },
951 []u32{
952 0xFFFFFFFF,
953 0x00000001,
954 0xFFFFFFFF,
955 },
956 []u32{
957 0xFFFFFFFF,
958 0x00000002,
959 0x7FFFFFFF,
960 },
961 []u32{
962 0xFFFFFFFF,
963 0x00000003,
964 0x55555555,
965 },
966 []u32{
967 0xFFFFFFFF,
968 0x00000010,
969 0x0FFFFFFF,
970 },
971 []u32{
972 0xFFFFFFFF,
973 0x078644FA,
974 0x00000022,
975 },
976 []u32{
977 0xFFFFFFFF,
978 0x0747AE14,
979 0x00000023,
980 },
981 []u32{
982 0xFFFFFFFF,
983 0x7FFFFFFF,
984 0x00000002,
985 },
986 []u32{
987 0xFFFFFFFF,
988 0x80000000,
989 0x00000001,
990 },
991 []u32{
992 0xFFFFFFFF,
993 0xFFFFFFFD,
994 0x00000001,
995 },
996 []u32{
997 0xFFFFFFFF,
998 0xFFFFFFFE,
999 0x00000001,
1000 },
1001 []u32{
1002 0xFFFFFFFF,
1003 0xFFFFFFFF,
1004 0x00000001,
1005 },
4761006 };
4771007
4781008 for (cases) |case| {
std/special/compiler_rt/udivmod.zig+23-20
......@@ -1,7 +1,10 @@
11const builtin = @import("builtin");
22const is_test = builtin.is_test;
33
4const low = switch (builtin.endian) { builtin.Endian.Big => 1, builtin.Endian.Little => 0 };
4const low = switch (builtin.endian) {
5 builtin.Endian.Big => 1,
6 builtin.Endian.Little => 0,
7};
58const high = 1 - low;
69
710pub fn udivmod(comptime DoubleInt: type, a: DoubleInt, b: DoubleInt, maybe_rem: ?&DoubleInt) DoubleInt {
......@@ -11,8 +14,8 @@ pub fn udivmod(comptime DoubleInt: type, a: DoubleInt, b: DoubleInt, maybe_rem:
1114 const SignedDoubleInt = @IntType(true, DoubleInt.bit_count);
1215 const Log2SingleInt = @import("../../math/index.zig").Log2Int(SingleInt);
1316
14 const n = *@ptrCast(&const [2]SingleInt, &a); // TODO issue #421
15 const d = *@ptrCast(&const [2]SingleInt, &b); // TODO issue #421
17 const n = @ptrCast(&const [2]SingleInt, &a).*; // TODO issue #421
18 const d = @ptrCast(&const [2]SingleInt, &b).*; // TODO issue #421
1619 var q: [2]SingleInt = undefined;
1720 var r: [2]SingleInt = undefined;
1821 var sr: c_uint = undefined;
......@@ -23,7 +26,7 @@ pub fn udivmod(comptime DoubleInt: type, a: DoubleInt, b: DoubleInt, maybe_rem:
2326 // ---
2427 // 0 X
2528 if (maybe_rem) |rem| {
26 *rem = n[low] % d[low];
29 rem.* = n[low] % d[low];
2730 }
2831 return n[low] / d[low];
2932 }
......@@ -31,7 +34,7 @@ pub fn udivmod(comptime DoubleInt: type, a: DoubleInt, b: DoubleInt, maybe_rem:
3134 // ---
3235 // K X
3336 if (maybe_rem) |rem| {
34 *rem = n[low];
37 rem.* = n[low];
3538 }
3639 return 0;
3740 }
......@@ -42,7 +45,7 @@ pub fn udivmod(comptime DoubleInt: type, a: DoubleInt, b: DoubleInt, maybe_rem:
4245 // ---
4346 // 0 0
4447 if (maybe_rem) |rem| {
45 *rem = n[high] % d[low];
48 rem.* = n[high] % d[low];
4649 }
4750 return n[high] / d[low];
4851 }
......@@ -54,7 +57,7 @@ pub fn udivmod(comptime DoubleInt: type, a: DoubleInt, b: DoubleInt, maybe_rem:
5457 if (maybe_rem) |rem| {
5558 r[high] = n[high] % d[high];
5659 r[low] = 0;
57 *rem = *@ptrCast(&align(@alignOf(SingleInt)) DoubleInt, &r[0]); // TODO issue #421
60 rem.* = @ptrCast(&align(@alignOf(SingleInt)) DoubleInt, &r[0]).*; // TODO issue #421
5861 }
5962 return n[high] / d[high];
6063 }
......@@ -66,7 +69,7 @@ pub fn udivmod(comptime DoubleInt: type, a: DoubleInt, b: DoubleInt, maybe_rem:
6669 if (maybe_rem) |rem| {
6770 r[low] = n[low];
6871 r[high] = n[high] & (d[high] - 1);
69 *rem = *@ptrCast(&align(@alignOf(SingleInt)) DoubleInt, &r[0]); // TODO issue #421
72 rem.* = @ptrCast(&align(@alignOf(SingleInt)) DoubleInt, &r[0]).*; // TODO issue #421
7073 }
7174 return n[high] >> Log2SingleInt(@ctz(d[high]));
7275 }
......@@ -77,7 +80,7 @@ pub fn udivmod(comptime DoubleInt: type, a: DoubleInt, b: DoubleInt, maybe_rem:
7780 // 0 <= sr <= SingleInt.bit_count - 2 or sr large
7881 if (sr > SingleInt.bit_count - 2) {
7982 if (maybe_rem) |rem| {
80 *rem = a;
83 rem.* = a;
8184 }
8285 return 0;
8386 }
......@@ -98,7 +101,7 @@ pub fn udivmod(comptime DoubleInt: type, a: DoubleInt, b: DoubleInt, maybe_rem:
98101 if ((d[low] & (d[low] - 1)) == 0) {
99102 // d is a power of 2
100103 if (maybe_rem) |rem| {
101 *rem = n[low] & (d[low] - 1);
104 rem.* = n[low] & (d[low] - 1);
102105 }
103106 if (d[low] == 1) {
104107 return a;
......@@ -106,7 +109,7 @@ pub fn udivmod(comptime DoubleInt: type, a: DoubleInt, b: DoubleInt, maybe_rem:
106109 sr = @ctz(d[low]);
107110 q[high] = n[high] >> Log2SingleInt(sr);
108111 q[low] = (n[high] << Log2SingleInt(SingleInt.bit_count - sr)) | (n[low] >> Log2SingleInt(sr));
109 return *@ptrCast(&align(@alignOf(SingleInt)) DoubleInt, &q[0]); // TODO issue #421
112 return @ptrCast(&align(@alignOf(SingleInt)) DoubleInt, &q[0]).*; // TODO issue #421
110113 }
111114 // K X
112115 // ---
......@@ -141,7 +144,7 @@ pub fn udivmod(comptime DoubleInt: type, a: DoubleInt, b: DoubleInt, maybe_rem:
141144 // 0 <= sr <= SingleInt.bit_count - 1 or sr large
142145 if (sr > SingleInt.bit_count - 1) {
143146 if (maybe_rem) |rem| {
144 *rem = a;
147 rem.* = a;
145148 }
146149 return 0;
147150 }
......@@ -170,25 +173,25 @@ pub fn udivmod(comptime DoubleInt: type, a: DoubleInt, b: DoubleInt, maybe_rem:
170173 var r_all: DoubleInt = undefined;
171174 while (sr > 0) : (sr -= 1) {
172175 // r:q = ((r:q) << 1) | carry
173 r[high] = (r[high] << 1) | (r[low] >> (SingleInt.bit_count - 1));
174 r[low] = (r[low] << 1) | (q[high] >> (SingleInt.bit_count - 1));
175 q[high] = (q[high] << 1) | (q[low] >> (SingleInt.bit_count - 1));
176 q[low] = (q[low] << 1) | carry;
176 r[high] = (r[high] << 1) | (r[low] >> (SingleInt.bit_count - 1));
177 r[low] = (r[low] << 1) | (q[high] >> (SingleInt.bit_count - 1));
178 q[high] = (q[high] << 1) | (q[low] >> (SingleInt.bit_count - 1));
179 q[low] = (q[low] << 1) | carry;
177180 // carry = 0;
178181 // if (r.all >= b)
179182 // {
180183 // r.all -= b;
181184 // carry = 1;
182185 // }
183 r_all = *@ptrCast(&align(@alignOf(SingleInt)) DoubleInt, &r[0]); // TODO issue #421
186 r_all = @ptrCast(&align(@alignOf(SingleInt)) DoubleInt, &r[0]).*; // TODO issue #421
184187 const s: SignedDoubleInt = SignedDoubleInt(b -% r_all -% 1) >> (DoubleInt.bit_count - 1);
185188 carry = u32(s & 1);
186189 r_all -= b & @bitCast(DoubleInt, s);
187 r = *@ptrCast(&[2]SingleInt, &r_all); // TODO issue #421
190 r = @ptrCast(&[2]SingleInt, &r_all).*; // TODO issue #421
188191 }
189 const q_all = ((*@ptrCast(&align(@alignOf(SingleInt)) DoubleInt, &q[0])) << 1) | carry; // TODO issue #421
192 const q_all = ((@ptrCast(&align(@alignOf(SingleInt)) DoubleInt, &q[0]).*) << 1) | carry; // TODO issue #421
190193 if (maybe_rem) |rem| {
191 *rem = r_all;
194 rem.* = r_all;
192195 }
193196 return q_all;
194197}
std/special/compiler_rt/udivmodti4.zig+1-1
......@@ -9,7 +9,7 @@ pub extern fn __udivmodti4(a: u128, b: u128, maybe_rem: ?&u128) u128 {
99
1010pub extern fn __udivmodti4_windows_x86_64(a: &const u128, b: &const u128, maybe_rem: ?&u128) void {
1111 @setRuntimeSafety(builtin.is_test);
12 compiler_rt.setXmm0(u128, udivmod(u128, *a, *b, maybe_rem));
12 compiler_rt.setXmm0(u128, udivmod(u128, a.*, b.*, maybe_rem));
1313}
1414
1515test "import udivmodti4" {
std/special/compiler_rt/umodti3.zig+1-1
......@@ -11,5 +11,5 @@ pub extern fn __umodti3(a: u128, b: u128) u128 {
1111
1212pub extern fn __umodti3_windows_x86_64(a: &const u128, b: &const u128) void {
1313 @setRuntimeSafety(builtin.is_test);
14 compiler_rt.setXmm0(u128, __umodti3(*a, *b));
14 compiler_rt.setXmm0(u128, __umodti3(a.*, b.*));
1515}
test/cases/cast.zig+3-3
......@@ -14,7 +14,7 @@ test "integer literal to pointer cast" {
1414}
1515
1616test "pointer reinterpret const float to int" {
17 const float: f64 = 5.99999999999994648725e - 01;
17 const float: f64 = 5.99999999999994648725e-01;
1818 const float_ptr = &float;
1919 const int_ptr = @ptrCast(&const i32, float_ptr);
2020 const int_val = int_ptr.*;
......@@ -121,13 +121,13 @@ test "implicitly cast indirect pointer to maybe-indirect pointer" {
121121 return (p.*).x;
122122 }
123123 fn maybeConstConst(p: ?&const &const Self) u8 {
124 return (??p.*).x;
124 return ((??p).*).x;
125125 }
126126 fn constConstConst(p: &const &const &const Self) u8 {
127127 return (p.*.*).x;
128128 }
129129 fn maybeConstConstConst(p: ?&const &const &const Self) u8 {
130 return (??p.*.*).x;
130 return ((??p).*.*).x;
131131 }
132132 };
133133 const s = S {
test/cases/generics.zig+1-1
......@@ -127,7 +127,7 @@ test "generic fn with implicit cast" {
127127 }) == 0);
128128}
129129fn getByte(ptr: ?&const u8) u8 {
130 return ??ptr.*;
130 return (??ptr).*;
131131}
132132fn getFirstByte(comptime T: type, mem: []const T) u8 {
133133 return getByte(@ptrCast(&const u8, &mem[0]));