Skip to content

Instantly share code, notes, and snippets.

View metaleap's full-sized avatar

Phil Schumann metaleap

View GitHub Profile
@metaleap
metaleap / main.cpp
Created January 17, 2024 19:04
Simple no-content Wicked Engine prog (just FPS prints etc)
#include <cstdio>
#include <SDL2/SDL.h>
#include <WickedEngine.h>
void mainLoop(wi::Application&);
int main() {
wi::renderer::SetShaderSourcePath("../libdeps/WickedEngine/WickedEngine/shaders/");
CXX = g++
CXXFLAGS = --debug -std=c++20 -march=native
bin/app: bin/app_util_util.o, bin/app_main.o, bin/app_gui_gui.o
$(CXX) $(CXXFLAGS) bin/app_main.o bin/app_gui_gui.o bin/app_util_util.o -o bin/app
bin/app_util_util.o: app/util/util.cpp, app/util/util.h, app/util/util.cpp
$(CXX) -c $(CXXFLAGS) app/util/util.cpp -o bin/app_util_util.o
Archive/Roguelike Pack (15×)/: mismatching "local" filename (Archive/Roguelike Pack (15├Ч)/),
continuing with "central" filename version
Archive/Roguelike Pack (15×)/Roguelike Pack (15×).zip: mismatching "local" filename (Archive/Roguelike Pack (15├Ч)/Roguelike Pack (15├Ч).zip),
continuing with "central" filename version
Archive/Roguelike Pack (15×)/Thumbs.db: mismatching "local" filename (Archive/Roguelike Pack (15├Ч)/Thumbs.db),
continuing with "central" filename version
2D assets/1-Bit Input Prompts Pixel 16×/: mismatching "local" filename (2D assets/1-Bit Input Prompts Pixel 16├Ч/),
continuing with "central" filename version
2D assets/1-Bit Input Prompts Pixel 16×/License.txt: mismatching "local" filename (2D assets/1-Bit Input Prompts Pixel 16├Ч/License.txt),
continuing with "central" filename version
@metaleap
metaleap / borrow_inference.md
Created April 26, 2020 18:57 — forked from paniq/borrow_inference.md
Borrow Inference

Borrow Inference

by Leonard Ritter, Duangle GbR

This is a description of borrow inference, an alternative to borrow checking that requires no declarative annotations to support proper management of unique values and borrowed references at compile time.

We are trying to infer whether a value is borrowed or has to be unique, applying this constraint going backwards through the function, as we also need to prevent

pub fn isTypeHashMapLike(comptime T: type) bool {
switch (@typeInfo(T)) {
else => {},
.Struct => |maybe_hashmap_struct_info| {
inline for (maybe_hashmap_struct_info.decls) |decl_in_hashmap| {
comptime if (decl_in_hashmap.is_pub and std.mem.eql(u8, "iterator", decl_in_hashmap.name)) {
switch (decl_in_hashmap.data) {
else => {},
.Fn => |fn_decl_hashmap_iterator| {
@metaleap
metaleap / keyword-args-of-sorts.zig
Last active January 28, 2020 17:30
./main.zig:4:26: error: expected type 'struct:11:32', found 'struct:11:32'
const std = @import("std");
pub fn main() void {
var sess = Protocol(.{
.TIn = MyIn,
.TOut = MyOut,
}){};
sess.serve(); // forever-loop
}
const std = @import("std");
pub const String = []const u8;
pub const IntOrString = union(enum) {
int: isize,
string: String,
};
// we don't use std.json.Value union here because:
const std = @import("std");
pub fn main() !void {
var mem = std.heap.ArenaAllocator.init(std.heap.page_allocator);
defer mem.deinit();
const list = try listFromStr(&mem.allocator, "Hail Zig =)");
std.debug.warn("{}", .{try listToStr(&mem.allocator, list)});
}
pub inline fn isStr(comptime it: type) bool {
return switch (@typeInfo(it)) {
std.builtin.TypeId.Array => |ta| u8 == ta.child,
std.builtin.TypeId.Pointer => |tp| u8 == tp.child or switch (@typeInfo(tp.child)) {
std.builtin.TypeId.Array => |tpa| u8 == tpa.child,
else => false,
},
else => false,
};
}
pub fn exprNumListToBytes(mem: *std.mem.Allocator, maybeNumList: ?[]const Expr) !?[]const u8 {
if (maybeNumList) |it| {
const bytes = try mem.alloc(u8, it.len);
for (it) |expr, i|
if (expr.is(.NumInt)) |n| { // .is() expands to: switch(expr) { .NumInt => |n| ..., else => ... }
if (n >= 0 and n <= 255)
bytes[i] = @intCast(u8, n)
else {
mem.free(bytes);
return null;