Skip to content

Instantly share code, notes, and snippets.

Andrew Kelley andrewrk

View GitHub Profile
View hello.zir
@noreturn = primitive(noreturn)
@void = primitive(void)
@usize = primitive(usize)
@0 = int(0)
@1 = int(1)
@2 = int(2)
@3 = int(3)
@syscall_array = str("syscall")
@sysoutreg_array = str("={rax}")
@andrewrk
andrewrk / benchmark_stuff.txt
Created May 13, 2020
RedisConf2020 Talk: "Writing Redis Modules in Zig" https://www.youtube.com/watch?v=Csz26Wy9Ses
View benchmark_stuff.txt
test "benchmark" {
var timer = try std.time.Timer.start();
const start = timer.lap();
var i: usize = 0;
var hash: usize = 0;
while (i < 1000000) : (i += 1) {
const src = "++++++++++[>+++++++>++++++++++>+++>+<<<<-]>++.>+.+++++++..+++.>++.<<+++++++++++++++.>.+++.------.--------.>+.>.";
var output: [100]u8 = undefined;
var bf: BrainFuckInterpreter = undefined;
bf.init(src, "", &output, 500);
View while-loop.zir
fn entry(start_index: usize, slice: []usize, value: usize) ?usize {
var i: usize = start_index;
while (i >= 0) : (i -= 1) {
if (slice[i] == value) {
return i;
}
}
return null;
View hello.zir
@0 = str("Hello, world!\n")
@1 = primitive(noreturn)
@2 = primitive(usize)
@3 = fntype([], @1, cc=Naked)
@4 = int(0)
@5 = int(1)
@6 = int(231)
@7 = str("len")
@8 = fn(@3, {
View auto_promoting_array_list.zig
const std = @import("std");
const need_auto_promoting = @sizeOf(usize) > 4;
const SmallInt = if (need_auto_promoting) u32 else usize;
pub fn AutoPromotingArrayList(comptime T: type) type {
return struct {
pointer: [*]T,
small_len: SmallInt,
small_capacity: SmallInt,
@andrewrk
andrewrk / process_headers_after.zig
Last active Apr 17, 2020
example of what doing my proposal would look like
View process_headers_after.zig
//! To get started, run this tool with no args and read the help message.
//!
//! The build systems of musl-libc and glibc require specifying a single target
//! architecture. Meanwhile, Zig supports out-of-the-box cross compilation for
//! every target. So the process to create libc headers that Zig ships is to use
//! this tool.
//! First, use the musl/glibc build systems to create installations of all the
//! targets in the `glibc_targets`/`musl_targets` variables.
//! Next, run this tool to create a new directory which puts .h files into
//! <arch> subdirectories, with `generic` being files that apply to all architectures.
View old-mcdonald-had-a-farm.zig
// Based on source here:
// https://www.reddit.com/r/programming/comments/fxswxe/c_needs_better_syntax_and_macros/fmx4f0y/
// (plant "far-field" "Old McDonald's Farm")
// (harvest "Old McDonald's Farm")
// (grind "stone-mill")
// (prepare-dough "sea-salt" "white-sugar" "ev-olive-oil")
// (make-base)
// (add-toppings "rosa-tomatoes" "mozzarella" "ham")
// (bake "stone oven")
// (enjoy))
@andrewrk
andrewrk / debug_libcxx.txt
Last active Mar 27, 2020
the commands that make runs on my system for building libc++ and libc++abi
View debug_libcxx.txt
/nix/store/qbn4f7k7yj5dj8ay292hr2nv0q8854vq-cmake-3.16.3/bin/cmake -S/home/andy/Downloads/llvm-project-10/libcxx -B/home/andy/Downloads/llvm-project-10/libcxx/build --check-build-system CMakeFiles/Makefile.cmake 0
/nix/store/qbn4f7k7yj5dj8ay292hr2nv0q8854vq-cmake-3.16.3/bin/cmake -E cmake_progress_start /home/andy/Downloads/llvm-project-10/libcxx/build/CMakeFiles /home/andy/Downloads/llvm-project-10/libcxx/build/CMakeFiles/progress.marks
make -f CMakeFiles/Makefile2 all
make[1]: Entering directory '/home/andy/Downloads/llvm-project-10/libcxx/build'
make -f src/CMakeFiles/cxx_shared.dir/build.make src/CMakeFiles/cxx_shared.dir/depend
make[2]: Entering directory '/home/andy/Downloads/llvm-project-10/libcxx/build'
cd /home/andy/Downloads/llvm-project-10/libcxx/build && /nix/store/qbn4f7k7yj5dj8ay292hr2nv0q8854vq-cmake-3.16.3/bin/cmake -E cmake_depends "Unix Makefiles" /home/andy/Downloads/llvm-project-10/libcxx /home/andy/Downloads/llvm-project-10/libcxx/src /home/andy/Downloads/llvm-project-10/libcxx/build /hom
View basic-tcp-chat.zig
const std = @import("std");
const net = std.net;
const fs = std.fs;
const os = std.os;
pub const io_mode = .evented;
pub fn main() anyerror!void {
const allocator = std.heap.page_allocator; // TODO use a more appropriate allocator
View warn-deadlock.txt
[External Code]
test.exe!std.mutex.Mutex::std.mutex.Mutex.acquireSlow(std.mutex.Held * self, std.mutex.Mutex *) Line 128
at C:\msys64\home\andy\dev\zig\lib\std\mutex.zig(128)
test.exe!std.mutex.Mutex::std.mutex.Mutex.acquire(std.mutex.Held * self, std.mutex.Mutex *) Line 100
at C:\msys64\home\andy\dev\zig\lib\std\mutex.zig(100)
test.exe!std.debug.warn(std.os.windows.struct:1204:69 * args) Line 64
at C:\msys64\home\andy\dev\zig\lib\std\debug.zig(64)
test.exe!std.os.windows.unexpectedError(std.builtin.StackTrace * err, std.os.windows.win32error.Win32Error) Line 1205
at C:\msys64\home\andy\dev\zig\lib\std\os\windows.zig(1205)
test.exe!std.os.windows.WriteFile(std.os.windows.WriteFileError!usize * handle, std.builtin.StackTrace * bytes, c_void * offset, []u8 *) Line 486
You can’t perform that action at this time.