Skip to content

Instantly share code, notes, and snippets.

View andrewrk's full-sized avatar

Andrew Kelley andrewrk

View GitHub Profile
@andrewrk
andrewrk / README.md
Last active November 6, 2019 20:10
simple tcp chat server demo from the live stream
@andrewrk
andrewrk / libc.txt
Created October 25, 2019 04:42
example of `zig.exe libc` output
# The directory that contains `stdlib.h`.
# On POSIX-like systems, include directories be found with: `cc -E -Wp,-v -xc /dev/null`
include_dir=C:\Program Files (x86)\Windows Kits\10\\Include\10.0.18362.0\ucrt
# The system-specific include directory. May be the same as `include_dir`.
# On Windows it's the directory that includes `vcruntime.h`.
# On POSIX it's the directory that includes `sys/errno.h`.
sys_include_dir=C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.15.26726\lib\x64\\..\..\include
# The directory that contains `crt1.o` or `crt2.o`.
# On POSIX, can be found with `cc -print-file-name=crt1.o`.
@andrewrk
andrewrk / hello.s
Last active October 22, 2019 20:55
x86_64-linux hello world in assembly
.text
.globl _start
_start:
movl $1, %eax
movl $1, %edi
movl $msg, %esi
movl $12, %edx
syscall
movl $60, %eax
xorl %edi, %edi
@andrewrk
andrewrk / fib.zig
Created August 30, 2019 23:40
safe recursion demo with fibonacci
const std = @import("std");
const Allocator = std.mem.Allocator;
const suspending_implementation = true; // try flipping this to false
fn fib(allocator: *Allocator, x: u32) error{OutOfMemory}!u32 {
if (x <= 1) return x;
if (suspending_implementation) {
suspend {
@andrewrk
andrewrk / 0test.zig
Last active July 23, 2019 19:13
simple coroutine demo
var x: i32 = 1;
export fn entry() void {
const p = async simpleAsyncFn();
}
fn simpleAsyncFn() void {
x += 1;
suspend;
x += 1;
}
@andrewrk
andrewrk / 1simple.zig
Created July 21, 2019 05:23
coroutine brainstorming
fn simpleAsyncFn() void {
x += 1;
suspend;
x += 1;
}
// implementation with switch
const Frame = struct {
index: u2,
};
fn simpleAsyncFn(locals: *Frame) void {
@andrewrk
andrewrk / build-commands.txt
Created July 12, 2019 16:59
troubleshooting segfault with cross compiled windows binaries that link libc
[nix-shell:~/downloads/zig/build]$ ./zig build-exe --c-source hello.c -target x86_64-windows-gnu --library c --verbose-cc --verbose-link
/home/andy/downloads/zig/build/zig cc -MD -MV -MF zig-cache/tmp/RYvsWTfvvK2C-hello.obj.d -nostdinc -fno-spell-checking -isystem /home/andy/downloads/zig/build/lib/zig/include -isystem /home/andy/downloads/zig/build/lib/zig/libc/include/x86_64-windows-gnu -isystem /home/andy/downloads/zig/build/lib/zig/libc/include/generic-mingw -isystem /home/andy/downloads/zig/build/lib/zig/libc/include/x86_64-windows-any -isystem /home/andy/downloads/zig/build/lib/zig/libc/include/any-windows-any -target x86_64-unknown-windows-gnu -Wno-pragma-pack -g -D_DEBUG -fstack-protector-strong --param ssp-buffer-size=4 -fno-omit-frame-pointer -o zig-cache/tmp/RYvsWTfvvK2C-hello.obj -c hello.c
/home/andy/downloads/zig/build/zig cc -MD -MV -MF /home/andy/.local/share/zig/stage1/tmp/HjzIZ8o3Jv1I-crtexe.obj.d -nostdinc -fno-spell-checking -isystem /home/andy/downloads/zig/build/lib/zig/include -target
@andrewrk
andrewrk / c.ll
Last active July 8, 2019 21:12
clang-8 -c c.ll -O3 -target wasm32-unknown-musl
; ModuleID = 'c'
source_filename = "c"
target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128"
target triple = "wasm32-unknown-unknown-musl"
%"[]u8.0" = type { i8*, i32 }
%builtin.StackTrace.1 = type { i32, %"[]usize.2" }
%"[]usize.2" = type { i32*, i32 }
%"std.math.frexp.frexp_result(f64)" = type { double, i32 }
%std.math.fma.dd = type { double, double }
@andrewrk
andrewrk / 0test.zig
Created June 8, 2019 22:57
result location demo
export fn entry() void {
const static = Foo{
.x = 9,
.bar = Bar{ .y = 10 },
};
const runtime = foo(true);
}
fn foo(c: bool) Foo {
return Foo{
@andrewrk
andrewrk / errno.h
Last active May 27, 2019 04:06
windows ucrt libc errno.h
//
// errno.h
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// System error numbers for use with errno and errno_t.
//
#pragma once
#ifndef _INC_ERRNO // include guard for 3rd party interop
#define _INC_ERRNO