Skip to content

Instantly share code, notes, and snippets.

View ikskuh's full-sized avatar
☺️
Hacking on Dunstwolke

Felix Queißner ikskuh

☺️
Hacking on Dunstwolke
View GitHub Profile
@ikskuh
ikskuh / forth.zig
Created February 18, 2021 01:08
Zig Comptime Forth
const std = @import("std");
test "forwarding a value" {
const result = forth("value", .{
.value = @as(u32, 42),
});
std.testing.expectEqual(@as(u32, 42), result);
}
@ikskuh
ikskuh / zig-update-git.sh
Created March 16, 2021 09:17
Zig Updater Script
#!/bin/bash
TARGET="///INVALID///"
function die()
{
if [ ! -z "${TARGET}" ]; then
rm -rf "${TARGET}"
fi
echo "$@"
@ikskuh
ikskuh / linkerscript.zig
Created March 19, 2021 00:02
linkerscript.zig
const std = @import("std");
/// The linker here is "preloaded" with all input object files / symbols.
/// After this function is run, the linker will resolve all symbol references
/// and print all unassigned symbols (\u2192 error)
pub fn link(l: *std.link.Linker) !void {
// Creates a new output section that will be loaded into the
// same address as its virtual address. It's also a (rx!w) section
const dot_text = l.createOutputSection(".text", .{
@ikskuh
ikskuh / any.zig
Created April 23, 2021 08:45
std::any implementation in zig
const std = @import("std");
pub fn main() !void {
var allocator = std.heap.page_allocator;
var a = try Any.init(allocator, @as(u32, 10));
defer a.deinit();
var b = try Any.init(allocator, @as([]const u8, "Hello, World!"));
defer b.deinit();
@ikskuh
ikskuh / Sdk.zig
Created June 14, 2021 19:14
sdkRoot()
const std = @import("std");
const Pkg = std.build.Pkg;
const Step = std.build.Step;
const FileSource = std.build.FileSource;
const GeneratedFile = std.build.GeneratedFile;
pub const Sdk = @This();
builder: *std.build.Builder,
@ikskuh
ikskuh / zig-packages.json
Last active February 19, 2022 10:06
Mini zpm
{
"ihex": {
"git": "https://github.com/MasterQ32/zig-ihex"
},
"args": {
"git": "https://github.com/MasterQ32/zig-args"
},
"parser-toolkit": {
"git": "https://github.com/MasterQ32/parser-toolkit"
},
@ikskuh
ikskuh / atomics.zig
Created February 27, 2022 14:37
Examples of why atomics are necessary
const std = @import("std");
var global: u32 = 0;
export fn normalStore(arg: u32) void {
global = arg;
}
export fn normalLoad() u32 {
return global;
@ikskuh
ikskuh / bad.zig
Created July 14, 2022 12:51
Comptime String Interning
const std = @import("std");
const input = @embedFile("input.txt");
export const capitalized = blk: {
@setEvalBranchQuota(100_000);
var result: []const []const u8 = &.{};
var iter = std.mem.tokenize(u8, input, ",.\r\n ");
@ikskuh
ikskuh / build.sh
Last active August 2, 2022 11:12
Arm 32 Kernel Example
#!/bin/bash
set -e
clear
zig build-exe -target arm-freestanding-eabi -mcpu baseline -T linker.ld -fsingle-threaded -fno-omit-frame-pointer -O ReleaseFast --name kernel kernel.zig
llvm-objdump -dt kernel
llvm-objcopy -O binary kernel kernel.bin
# cp kernel.bin disk.img
@ikskuh
ikskuh / ui-concept.zig
Last active December 16, 2022 17:12
Zig UI API Concept
//! xq @ UTC+2 (MasterQ32 @ GitHub) — gestern um 22:01 Uhr
//! more gui thoughts:
//!
//! i stopped using tree structures for my UIs and return to flat, ordered lists. this made the implementations sinpler by magnitudes, and one could always build stuff like a 'container' widget which would make it hierarchical by nesting UIs.
//!
//! right now, dunstwolke uses a immediate mode interface, which is now borked by a bugfix in stage2.
//!
//! now i'm thinking about how to decouple styling, layout and logic of the ui. also i'm still not sure how to manage UI events. i really dislike the callback approach of wpf/qt/winforms/...
//! compared to callbacks, immediate mode interfaces are very convenient to program, so i wonder if i can use a similar interface for a retained guy, for example a pull interface:
//! gui.pushInput(.mouse_down);