Skip to content

Instantly share code, notes, and snippets.

~/r/zig/build master *4 ?54 ↯ 0.9.1 cmake .. -DCMAKE_PREFIX_PATH=$(brew --prefix llvm) -DZIG_STATIC_LLVM=on -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_CXX_FLAGS="-fuse-ld=lld"
-- The C compiler identification is Clang 15.0.0
-- The CXX compiler identification is Clang 15.0.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - failed
-- Check for working C compiler: /usr/local/opt/llvm/bin/clang
-- Check for working C compiler: /usr/local/opt/llvm/bin/clang - broken
CMake Error at /usr/local/Cellar/cmake/3.24.2/share/cmake/Modules/CMakeTestCCompiler.cmake:69 (message):
The C compiler
$ zig build -Denable-llvm=true -Dskip-run-translated-c=true -Dskip-non-native=true -Dtarget='x86_64-macos.10.15.7...10.15.7-gnu' test-stage2
Test [1/100] test ""... compiler [1/847] stage2 compile errors [5/5] update [2/3] thread 7970261 panic: reached unreachable code
/Users/johnschmidt/repos/zig/build/lib/zig/std/debug.zig:234:14: 0x103f877f8 in std.debug.assert (test)
if (!ok) unreachable; // assertion failure
^
/Users/johnschmidt/repos/zig/src/Module.zig:561:15: 0x10437573f in Module.Decl.zirBlockIndex (test)
assert(decl.zir_decl_index != 0);
^
/Users/johnschmidt/repos/zig/src/Module.zig:3861:47: 0x104237ddf in Module.semaDecl (test)
@schmee
schmee / console
Last active January 12, 2020 11:16
DES
cat /dev/urandom | head -c300000000 > random_test_data.bin
➜ zig-crypto git:(new-api) ✗ time openssl enc -des-ecb -in random_test_data.bin -out enc.bin -K 133457799BBCDFF1 -nopad
openssl enc -des-ecb -in src/random_test_data.bin -out enc.bin -K -nopad 3.59s user 0.41s system 95% cpu 4.195 total
➜ zig-crypto git:(new-api) ✗ zig build-exe main.zig --release-fast --main-pkg-path . && time ./des
78
./des 3.52s user 0.21s system 99% cpu 3.741 total
@schmee
schmee / client.java
Created September 10, 2019 08:17
Finagle Java Client
package foo;
import com.twitter.finagle.Service;
import com.twitter.finagle.ServiceFactory;
import com.twitter.finagle.Stack;
import com.twitter.finagle.client.StdStackClient;
import com.twitter.finagle.client.Transporter;
import com.twitter.finagle.param.ClientAdmissionControlParams;
import com.twitter.finagle.param.ClientSessionParams;
import com.twitter.finagle.param.ClientTransportParams;
@schmee
schmee / assembly.log
Created August 6, 2019 18:53
Vector API in Clojure!
vector_clj/core$i256_add.invoke(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; [0x000000011f8acdc0, 0x000000011f8ad058] 664 bytes
[Entry Point]
[Constants]
# {method} {0x000000013253d3b8} 'invoke' '(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;' in 'vector_clj/core$i256_add'
# this: rsi:rsi = 'vector_clj/core$i256_add'
# parm0: rdx:rdx = 'java/lang/Object'
# parm1: rcx:rcx = 'java/lang/Object'
# [sp+0x30] (sp of caller)
.....
0x000000011f8acec3: prefetchw BYTE PTR [r10+0x180]
@schmee
schmee / temp_converter.clj
Last active August 4, 2019 21:52
Temperature converter
;; Comments
;; 1. Functions take data and return data! If you compare your solution, you see that
;; there is a chain of method calls: get-user-input -> parse-input -> print-temp -> convert-temp
;; Since get-user-input and print-temp are unpure, this makes it hard to break apart and to test.
;; Compare here: convert-temp, temp->str and parse-input all take data and return data, and all IO
;; happens in read-loop.
;; 2. There are many approaches to error handling, but initially a simple try/catch will do!
;; try/catch works the same way is in Java, so it is a good idea to get familiar with Java exceptions.
pub const Leaf = struct {
frequency: u32,
value: u8,
};
pub const Branch = struct {
frequency: u32,
left: ?*Node,
right: ?*Node,
};
@schmee
schmee / generic.zig
Last active February 19, 2019 21:40
Generic function question
fn S(comptime T: type) type {
return struct {
const Self = @This();
foo: fn (a: T, b: T) bool,
fn init(foo: fn (a: T, b: T) bool) Self {
return Self {
.foo = foo
};
@schmee
schmee / foo.zig
Last active February 13, 2019 21:42
Using example syntax
"self" is
struct {
elems: []T,
count: usize,
allocator: *Allocator
}
without using:
@schmee
schmee / des.zig
Last active February 10, 2019 18:58
DES bug
const assert = @import("std").debug.assert;
const fmt = @import("std").fmt;
const io = @import("std").io;
const math = @import("std").math;
const mem = @import("std").mem;
const os = @import("std").os;
const std = @import("std");
const warn = @import("std").debug.warn;
const ip = [64]u6{