Skip to content

Instantly share code, notes, and snippets.

View winksaville's full-sized avatar

Wink Saville winksaville

  • Soquel, CA. USA
View GitHub Profile
@winksaville
winksaville / gist:8758b59384c7ce0c3604d8b4f708929c
Last active September 18, 2018 17:53
compiler aborts when there is a u0 field in a packed struct
const assert = @import("std").debug.assert;
// zig: ../src/analyze.cpp:499: ZigType* get_pointer_to_type_extra(CodeGen*, ZigType*, bool, bool, PtrLen, uint32_t, uint32_t, uint32_t): Assertion `byte_alignment == 0' failed.
// Aborted (core dumped)
test "u0-packed-struct-fails" {
const S = packed struct { f0: u0, };
var s = S { .f0 = 0, };
assert(s.f0 == 0);
}
const std = @import("std");
const assert = std.debug.assert;
test "u0-memory-address" {
var one: u1 = 1;
var zero: u0 = 0;
var pZero = &zero;
assert(pZero == &zero);
// $ zig test u0.zig
@winksaville
winksaville / pZeroConditional.zig
Last active September 17, 2018 23:24
Test ?*u0
const std = @import("std");
const assert = std.debug.assert;
const warn = std.debug.warn;
const builtin = @import("builtin");
const TypeId = builtin.TypeId;
test "u0" {
var zero: u0 = 0;
var pZeroOptional: ?*u0 = &zero;
assert(pZeroOptional != null); // this is true
//$ zig test opaquetype.zig
//opaquetype.zig:8:30: error: parameter of type '(anonymous opaque at opaquetype.zig:12:30)' not allowed
// fn getValue(pOpaqueSelf: @OpaqueType()) u32 {
// ^
const assert = @import("std").debug.assert;
const S = struct {
const Self = @This();
value: u32,
@winksaville
winksaville / gist:a094ac6fe99f7bccdf81301b2e942c0a
Created September 1, 2018 03:47
How to make a struct in zig
//$ zig test make_struct.zig
// make_struct.zig:20:7: error: no member named 'int64' in struct 'makeStruct((struct []const u8 constant),i64)'
// v1.int64 = -123;
// Seems the "name" parameter needs to be a "symbol"
// and the return would be something like:
// return struct { @symbol(name): T, };
fn makeStruct(comptime name: []const u8, comptime T: type) type {
return struct { name: T, };
}
[00:07:10] C:\projects\zig-d3l86\llvm+clang-6.0.0-win64-msvc-release\include\llvm/ADT/IntrusiveRefCntPtr.h(167): warning C4800: 'clang::TargetInfo *const ': forcing value to bool 'true' or 'false' (performance warning) [C:\projects\zig-d3l86\build-msvc-release\zig.vcxproj]
[00:07:10] C:\projects\zig-d3l86\llvm+clang-6.0.0-win64-msvc-release\include\llvm/ADT/IntrusiveRefCntPtr.h(167): warning C4800: 'clang::SourceManager *const ': forcing value to bool 'true' or 'false' (performance warning) [C:\projects\zig-d3l86\build-msvc-release\zig.vcxproj]
[00:07:10] C:\projects\zig-d3l86\llvm+clang-6.0.0-win64-msvc-release\include\llvm/ADT/IntrusiveRefCntPtr.h(167): warning C4800: 'clang::FileManager *const ': forcing value to bool 'true' or 'false' (performance warning) [C:\projects\zig-d3l86\build-msvc-release\zig.vcxproj]
[00:07:10] C:\projects\zig-d3l86\llvm+clang-6.0.0-win64-msvc-release\include\llvm/ADT/IntrusiveRefCntPtr.h(167): warning C4800: 'clang::vfs::FileSystem *const ': forcing value to bool 'true'
@winksaville
winksaville / main.y.zig
Last active July 19, 2018 18:41
Some zig code and compileLog at the bottom showing some types
const std = @import("std");
const warn = std.debug.warn;
fn Buffer(comptime buffer_size: usize) type {
return struct {
const Self = this;
pub buffer: [buffer_size]u8,
// Initialize if allocated in the stack
@winksaville
winksaville / gdb-log.txt
Created June 21, 2018 01:27
gdb-log running libponyc.tests on Ubuntu-18.04 with its LLVM-3.9.1 dynamic library
root@df5469b996ee:/home/pony/wink/prgs/pony/ponyc# gdb -q --args ./build/debug/libponyc.tests --gtest_filter=CodegenOptimisationTest.MergeSendMessageReordering
Reading symbols from ./build/debug/libponyc.tests...done.
(gdb) set pagination off
(gdb) set disassembly-flavor intel
(gdb) break _ZN4llvm15RuntimeDyldImpl14loadObjectImplERKNS_6object10ObjectFileE
Function "_ZN4llvm15RuntimeDyldImpl14loadObjectImplERKNS_6object10ObjectFileE" not defined.
Make breakpoint pending on future shared library load? (y or [n]) y
Breakpoint 1 (_ZN4llvm15RuntimeDyldImpl14loadObjectImplERKNS_6object10ObjectFileE) pending.
(gdb) r
Starting program: /home/pony/wink/prgs/pony/ponyc/build/debug/libponyc.tests --gtest_filter=CodegenOptimisationTest.MergeSendMessageReordering
@winksaville
winksaville / loadObjectImpl-ubuntu-18.04-docker.asm
Created June 21, 2018 01:23
The disassembly of loadObjecImpl from Ubuntu 18.04 LLVM-3.9.1
Dump of assembler code for function _ZN4llvm15RuntimeDyldImpl14loadObjectImplERKNS_6object10ObjectFileE:
=> 0x00007ffff65fc870 <+0>: push r15
0x00007ffff65fc872 <+2>: push r14
0x00007ffff65fc874 <+4>: push r13
0x00007ffff65fc876 <+6>: push r12
0x00007ffff65fc878 <+8>: mov r12,rdx
0x00007ffff65fc87b <+11>: push rbp
0x00007ffff65fc87c <+12>: push rbx
0x00007ffff65fc87d <+13>: mov r13,rsi
0x00007ffff65fc880 <+16>: sub rsp,0x158
@winksaville
winksaville / big-rebase.txt
Created April 10, 2018 18:40
Content of file for a big rebase --interactive --recreate-merges
label onto
# Branch Merging-in-work-from-branch
reset [new root]
pick 027dbf80 Initial commit
pick cc10751a Adding benchmark namespace and removing broken flags
pick e65ca767 Fix printing of time
label branch-point
pick bd5c1cd7 Remove duplicated macros header
pick ab8645c9 benchmark_min_time now works as expected