Skip to content

Instantly share code, notes, and snippets.

Andrew Kelley andrewrk

Block or report user

Report or block andrewrk

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View basic-chat-thing.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;
View twitch-chat.txt
This was as far up as it let me scroll to copy-paste.
Thank you for being so helpful while I was coding this.
If your links got cut off, please feel free to comment on this gist and add those links.
daurnimator: So there are multiple forms for each instructions, you usally want to break up by arity
daurnimator: so you want e.g. 2-arity mov
daurnimator: e.g. ret is C2 for 1-arity or C3 for 0-arity
daurnimator: to steal from the dynasm instruction table: `mov_2 = "OR:A3o|RO:A1O|mr:89Rm|rm:8BrM|rib:nB0ri|ridw:B8ri|mi:C70mi",` Which is saying that 2-arity mov has 7 forms
daurnimator: integer register, fp register, index operand, immediate, jump taget
@andrewrk
andrewrk / README.md
Last active Nov 6, 2019
simple tcp chat server demo from the live stream
View README.md
@andrewrk
andrewrk / libc.txt
Created Oct 25, 2019
example of `zig.exe libc` output
View libc.txt
# 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 Oct 22, 2019
x86_64-linux hello world in assembly
View hello.s
.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 Aug 30, 2019
safe recursion demo with fibonacci
View fib.zig
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 Jul 23, 2019
simple coroutine demo
View 0test.zig
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 Jul 21, 2019
coroutine brainstorming
View 1simple.zig
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 Jul 12, 2019
troubleshooting segfault with cross compiled windows binaries that link libc
View build-commands.txt
[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 Jul 8, 2019
clang-8 -c c.ll -O3 -target wasm32-unknown-musl
View c.ll
; 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 }
You can’t perform that action at this time.