Skip to content

Instantly share code, notes, and snippets.

View andrewrk's full-sized avatar

Andrew Kelley andrewrk

View GitHub Profile
[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
@andrewrk
andrewrk / async-threads-example.zig
Last active March 23, 2020 18:42
using async/await manually with threads
const std = @import("std");
var all_threads: [10]*std.Thread = undefined;
var next_thread_index: usize = 0;
pub fn main() anyerror!void {
_ = async asyncMain();
var i: usize = 0;
while (i < next_thread_index) : (i += 1) {
all_threads[i].wait();
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
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 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 {