Skip to content

Instantly share code, notes, and snippets.

View tauoverpi's full-sized avatar

Simon A. Nielsen Knights tauoverpi

View GitHub Profile
@tauoverpi
tauoverpi / import.zig
Created August 15, 2023 07:04
fix all imports
const std = @import("std");
const mem = std.mem;
const assert = std.debug.assert;
const Ast = std.zig.Ast;
pub fn main() !void {
var instance = std.heap.GeneralPurposeAllocator(.{}){};
defer assert(instance.deinit() == .ok);
const gpa = instance.allocator();
@tauoverpi
tauoverpi / import.zig
Created August 15, 2023 07:04
fix all imports
const std = @import("std");
const mem = std.mem;
const assert = std.debug.assert;
const Ast = std.zig.Ast;
pub fn main() !void {
var instance = std.heap.GeneralPurposeAllocator(.{}){};
defer assert(instance.deinit() == .ok);
const gpa = instance.allocator();
@tauoverpi
tauoverpi / kernel.js
Created June 10, 2023 10:20
Actor example
// Kernel
const newMail = (type, content) => {
console.log("new mail", type);
return { type: type.id, content: content };
};
// Default actor error handling
const Actor = behaviour => {
const wrapper = (rt, self, mail) => {
#include <fcntl.h>
#include <sys/mman.h>
#include <sys/stat.h>
#include <unistd.h>
#include <cassert>
#include <cstdint>
#include <iostream>
#include <map>
#include <memory>
#include <optional>
@tauoverpi
tauoverpi / count.zig
Last active May 31, 2023 09:01
Counting lines example
const std = @import("std");
// this isn't done properly
pub fn main() !void {
var file = try std.fs.cwd().openFile(std.mem.span(std.os.argv[1]), .{});
defer file.close();
const size = comptime @intCast(u32, std.simd.suggestVectorSize(u8) orelse 8);
const page_size = std.mem.page_size;
@tauoverpi
tauoverpi / rm2cap.zig
Created April 18, 2023 16:58
Dump and compress the remarkable2's framebuffer
const std = @import("std");
const io = std.io;
const os = std.os;
const mem = std.mem;
const testing = std.testing;
const width = 1404;
const height = 1872;
pub fn main() !void {}
const std = @import("std");
const io = std.io;
const os = std.os;
const mem = std.mem;
const testing = std.testing;
const width = 1404;
const height = 1872;
pub fn main() !void {}
@tauoverpi
tauoverpi / machine.zig
Created March 28, 2023 20:12
Basic register machine
const std = @import("std");
const Instruction = struct {
opcode: Opcode,
src: u4,
dst: u4,
pub const Opcode = enum(u8) {
add,
sub,
const std = @import("std");
const sdf = @import("sdf.zig");
const assert = std.debug.assert;
const f32x4 = sdf.f32x4;
pub const Instruction = packed struct(u64) {
operator: Operator,
data: Data,
const base = @typeInfo(Operator.Opcode).Enum.fields.len - 1;
@tauoverpi
tauoverpi / packed_ptr.zig
Created January 19, 2023 07:58
Packed pointer example
const std = @import("std");
pub fn PackedPtr(
comptime Ptr: type,
comptime Data: type,
comptime tag: ?@Type(.EnumLiteral),
) type {
const alignment: u16 = @typeInfo(Ptr).Pointer.alignment;
const mask: usize = alignment - 1;
const Int = std.meta.Int(.unsigned, @bitSizeOf(Data));