This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const std = @import("std"); | |
pub fn build(b: *std.Build) void { | |
const optimize = b.standardOptimizeOption(.{}); | |
const exe = b.addExecutable(.{ | |
.name = "lib", | |
.root_source_file = .{ .path = "src/lib.zig" }, | |
.target = b.resolveTargetQuery(std.zig.CrossTarget.parse( | |
.{ .arch_os_abi = "wasm32-freestanding" }, | |
) catch unreachable), |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# generates valid zig multiply test case code which may used in matrix.zig | |
import numpy as np | |
np.random.seed(42) | |
# A = np.empty((2, 3, 2)) | |
# A.fill(1) | |
# A = np.array([ | |
# [ | |
# [1,2,3], | |
# [4,5,6], |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pub fn VecMethods(comptime Self: type) type { | |
return struct { | |
const info = @typeInfo(Self); | |
pub const len = info.Struct.fields.len; | |
pub const Arr = [len]info.Struct.fields[0].type; | |
pub const Simd = @Vector(len, info.Struct.fields[0].type); | |
pub fn arr(self: Self) Arr { | |
return @bitCast(self); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// zig build-obj -fstrip -OReleaseSmall /tmp/tmp.zig -femit-bin=/tmp/tmp.o && objdump -d /tmp/tmp.o | |
const std = @import("std"); | |
pub fn panic(msg: []const u8, st: ?*std.builtin.StackTrace, start: ?usize) noreturn { | |
_ = .{ msg, st, start }; | |
@trap(); | |
} | |
pub export fn _start() callconv(.Naked) noreturn { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//! https://en.wikipedia.org/wiki/Levenshtein_distance | |
const std = @import("std"); | |
pub fn levRec(a: []const u8, b: []const u8) u16 { | |
if (a.len == 0) return @truncate(b.len); | |
if (b.len == 0) return @truncate(a.len); | |
if (a[0] == b[0]) | |
return levRec(a[1..], b[1..]); | |
return @min( |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//! adapted from https://ravendb.net/articles/atomic-reference-counting-with-zig-code-samples | |
//! compiled with zig version 0.11.0-dev.3771+128fd7dd0 | |
const std = @import("std"); | |
pub fn RefCounted(comptime T: type) type { | |
return struct { | |
const Self = @This(); | |
const InternalRef = packed union { item: packed struct { value: u44, is_error: bool, references: u19 }, raw: u64 }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# create this file at <roc-repo-root>/examples/parser/parse-json.roc | |
# run | |
# $ cd <roc-repo-root> && roc examples/parser/parse-json.roc | |
# | |
# one-liner: clone roc repo to /tmp + wget gist + run gist | |
# $ cd /tmp && git clone git@github.com:roc-lang/roc.git && cd roc && wget https://gist.github.com/travisstaloch/acae64ec4d8346597f1aaecfe8c401e4/raw/parse-json.roc -O examples/parser/parse-json.roc && roc examples/parser/parse-json.roc | |
# | |
# resources: | |
# https://github.com/tsoding/haskell-json/blob/master/Main.hs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# create this file at <roc-repo-root>/examples/parser/repro.roc | |
# run | |
# $ cd <roc-repo-root> && roc examples/parser/repro.roc | |
# | |
app "lazy-parser-repro" | |
packages { pf: "platform/main.roc" } | |
imports [ | |
Parser.Core.{ Parser, map, lazy}, | |
Parser.Str.{ parseStr, RawStr } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# create this file at <roc-repo-root>/examples/parser/parse-json.roc | |
# run | |
# $ cd <roc-repo-root> && roc examples/parser/parse-json.roc | |
# | |
app "parse-json" | |
packages { pf: "platform/main.roc" } | |
imports [ | |
Parser.Core.{ Parser, oneOf, flatten, map, apply, many, const, maybe, between, alt, sepBy, ignore, lazy}, | |
Parser.Str.{ string, strFromRaw, parseStr, RawStr, codeunitSatisfies, codeunit } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# create this file at <roc-repo-root>/examples/parser/float-parsing-repro.roc | |
# run | |
# $ cd <roc-repo-root> && roc examples/parser/float-parsing-repro.roc | |
# | |
app "parse-json-repro" | |
packages { pf: "platform/main.roc" } | |
imports [ | |
Parser.Core.{ Parser, flatten, map, apply, many, const, maybe}, | |
Parser.Str.{ strFromRaw, parseStr, RawStr, codeunitSatisfies, codeunit } |
NewerOlder