Commit Graph

3594 Commits

Author SHA1 Message Date
Andrew Kelley
820bf054ea std.fmt.format: handle non-pointer struct/union/enum
Also adds support for printing structs via reflection.
The case when structs have pointers to themselves is not
handled yet.

closes #1380
2018-08-20 16:04:03 -04:00
Michael Noronha
b8ce8f219c translate-c: Correctly translate enum init values, addressing #1360 (#1377)
* translate-c: Correctly translate enum init values

* translate-c: Test enum initialization

* translate-c: Flip to positive using APSInt builtins

* src/translate_c.cpp: correctly bridge llvm::APSInt with Zig BigInt;

ACHTUNG: llvm::APSInt stores an int's sign inside of its getRawData; Internally to Zig we store an integer's sign outside of getRawData! (~aps_int) calls .flip() internally on the raw data to match Zig.

* test/translate_c.zig: enum: add wider range of values (u64) to try;

closes #1360
2018-08-20 14:29:26 -04:00
Andrew Kelley
3ee1b60edf langref: add docs for peer type resolution
closes #1367
2018-08-20 14:22:16 -04:00
Shawn Landden
bb93886791 do not use an allocator when we don't need to because of the existance of PATH_MAX 2018-08-19 21:42:48 -07:00
Marc Tiehuis
53b18b0791 Add secureZero function
This is identical to `mem.set(u8, slice, 0)` except that it will never
be optimized out by the compiler. Intended usage is for clearing
secret data.

The resulting assembly has been manually verified in --release-* modes.

It would be valuable to test the 'never be optimized out' claim in tests
but this is harder than initially expected due to how much Zig appears
to know locally. May be doable with @intToPtr, @ptrToInt to get around
known data dependencies but I could not work it out right now.
2018-08-18 12:15:39 +12:00
Marc Tiehuis
1da93caced docs: correct @memcpy, @memset function signatures 2018-08-18 12:06:25 +12:00
Andrew Kelley
4c95b2f9d1
Merge pull request #1379 from tgschultz/patch-1
fixed handling of [*]u8 when no format specifier is set
2018-08-14 14:38:20 -04:00
tgschultz
fa955f0024
fixed handling of [*]u8 when no format specifier is set
If fmt was called on with a [*]u8 or [*]const u8 argument, but the fmt string did not specify 's' to treat it as a string, it produced a compile error due to accessing index 1 of a 0 length slice.
2018-08-14 12:56:41 -05:00
Andrew Kelley
52471f6221
Merge pull request #1378 from prazzb/cmake-fix
Find local llvm-config first
2018-08-14 12:53:54 -04:00
prazzb
6e55f61581 Find local llvm-config first
Distro's llvm usually have a 6.0 suffix.Any custom llvm build
names the binary as llvm-config.Keeping 6.0 variant first causes
the distro's llvm to be compiled in place of a custom one even if
given using CMAKE_PREFIX_PATH.
2018-08-13 22:55:19 +05:30
Andrew Kelley
65497121f4
Merge pull request #1370 from shawnl/master
rb: some style fixes
2018-08-12 12:58:11 -04:00
Shawn Landden
64a71be5c3 rb: some style fixes
avoid @import("std") as is the custom

compare function name
2018-08-10 21:46:30 -07:00
Andrew Kelley
c4b9466da7
Merge pull request #1294 from ziglang/async-fs
introduce std.event.fs for async file system functions
2018-08-10 15:51:17 -04:00
Andrew Kelley
598e80957e windows: call CancelIo when canceling an fs watch 2018-08-10 13:19:07 -04:00
Andrew Kelley
0df485d4dc self-hosted: reorganize creation and destruction of Compilation 2018-08-10 12:28:20 -04:00
Andrew Kelley
d40f3fac74 docgen: fix usage of std.HashMap 2018-08-10 00:03:16 -04:00
Andrew Kelley
23af36c54f windows fs watching: fix not initializing table value 2018-08-09 21:48:25 -04:00
Andrew Kelley
26a842c264 windows: only create io completion port once 2018-08-09 20:12:46 -04:00
Andrew Kelley
b219feb3f1 initial windows implementation of std.event.fs.Watch 2018-08-09 16:48:44 -04:00
Andrew Kelley
c63ec9886a std.event.fs.preadv windows implementation 2018-08-08 16:55:19 -04:00
Andrew Kelley
8b456927be std.event.fs.pwritev windows implementation
also fix 2 bugs where the function didn't call allocator.shrink:
 * std.mem.join
 * std.os.path.resolve
2018-08-08 15:06:32 -04:00
Wink Saville
d927f347de Fix ir_analyze_instruction_atomic_rmw (#1351)
There were two tests of type_is_valid(casted_ptr->value.type) change the
second one to type_is_valie(casted_operand->value.type).
2018-08-07 23:18:26 -04:00
Andrew Kelley
ac12f0df71 fix linux regressions 2018-08-07 22:23:26 -04:00
Andrew Kelley
60955feab8 std.event.fs.Watch distinguishes between Delete and CloseWrite on darwin
TODO: after 1 event emitted for a deleted file, the file is no longer
watched
2018-08-07 22:14:30 -04:00
Andrew Kelley
5cbfe392be implement std.event.fs.Watch for macos 2018-08-07 21:06:21 -04:00
Shawn Landden
a583beb76c mem: use pub on Compare (#1352)
fixes rb

/home/shawn/git/zig/std/rb.zig:133:37: error: 'Compare' is private
    compare_fn: fn(*Node, *Node) mem.Compare,
2018-08-07 19:15:11 -04:00
Andrew Kelley
034363a86c
Merge pull request #1338 from shawnl/master
std: add red-black tree implementation
2018-08-07 12:47:28 -04:00
Shawn Landden
bbbb26f4d3 mem: add mem.compare(), and use it for mem.lessThan() 2018-08-07 05:30:54 -07:00
Shawn Landden
86b512c5cd mem: move enum Compare from rb to mem 2018-08-07 04:57:41 -07:00
Andrew Kelley
dcf3869acd
Merge pull request #1346 from shawnl/doc
doc: @addWithOverflow also returns if overflow occured
2018-08-07 01:28:55 -04:00
Shawn Landden
5d2abf4402 std: add red-black tree implementation
This is to be used with @fieldParentPtr();

Example:

const rb = @import("std").rb;

const Number = struct {
    node: rb.Node,
    value: i32,
};

fn number(node: *rb.Node) *Number {
    @fieldParentPtr(Number, "node", node);
}

fn compare(l: *rb.Node, r: *rb.Node) rb.Compare {
    var left = number(l);
    var right = number(r);

    if (left.value < right.value) {
        return rb.Compare.LessThan;
    } else if (left.value == right.value) {
        return rb.Compare.Equal;
    } else if (left.value > right.value) {
        return rb.Compare.GreaterThan;
    }
    unreachable;
}
--

A version that caches rb.Tree.first() could be added in the future.
2018-08-06 22:18:44 -07:00
Shawn Landden
cb0ef3ad4c doc: @addWithOverflow also returns if overflow occured 2018-08-06 22:12:14 -07:00
Andrew Kelley
1a28f09684 fix hash map test 2018-08-07 00:54:19 -04:00
Andrew Kelley
fd50a6896b std.event.fs support for macos
The file I/O stuff is working, but the fs watching
stuff is not yet.
2018-08-07 00:49:09 -04:00
Andrew Kelley
2c9ed664dd merge @kristate's std lib changes to darwin 2018-08-06 19:36:31 -04:00
Andrew Kelley
97be8debab std.HashMap.autoHash: use xor instead of wrapping mult 2018-08-06 19:09:22 -04:00
Andrew Kelley
c02ed80512 Merge branch 'mdsteele-threadid' 2018-08-06 17:32:55 -04:00
Andrew Kelley
24d74cbf44 fix Thread impl on Linux and add docs 2018-08-06 17:31:52 -04:00
Andrew Kelley
d2dd29e80c separate os.Thread.Id and os.Thread.Handle because of windows 2018-08-06 17:25:24 -04:00
Andrew Kelley
0a3ae9dc6e fix std.os.Thread.getCurrentId for linux 2018-08-06 16:48:49 -04:00
Andrew Kelley
647fd0f4f1 Merge branch 'threadid' of https://github.com/mdsteele/zig into mdsteele-threadid 2018-08-06 16:12:37 -04:00
Andrea Orru
72bac72338
Merge pull request #1339 from ziglang/zen_stdlib
Updates and fixes for the Zen stdlib
2018-08-06 03:05:22 -04:00
Andrea Orru
79d77faebf More type cast fixes 2018-08-06 02:42:12 -04:00
Andrea Orru
641066d82e Fix casts 2018-08-06 02:29:11 -04:00
Andrea Orru
d2f5e57b68 Merge branch 'master' into zen_stdlib 2018-08-06 01:43:19 -04:00
Andrew Kelley
63a23e848a translate-c: fix for loops with var init and empty body 2018-08-05 18:40:14 -04:00
Andrew Kelley
387fab60a6 translate-c: fix do while with empty body 2018-08-05 18:32:38 -04:00
Andrew Kelley
c420b234cc translate-c: handle for loop with empty body 2018-08-05 18:18:24 -04:00
Andrew Kelley
aa232089f2 translate-c: fix while loop with no body 2018-08-05 18:06:39 -04:00
Matthew D. Steele
7a2401ef1e Don't compare ?Thread.Id == Thread.Id in the test
It doesn't work, because of issue #1332.
2018-08-04 21:47:13 -04:00