Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View DutchGhost's full-sized avatar

DutchGhost DutchGhost

View GitHub Profile
@DutchGhost
DutchGhost / route.zig
Last active July 1, 2023 22:13
funky compime zig
const std = @import("std");
// Just a simple struct representing a http route
// you can image this having a handler: fn() HttpResponse
// of some kind.
const Route = struct {
url: []const u8,
};
// a router namespace
#include <stdio.h>
int main() {
void *instructions[5];
int ip = 0;
int n = 0;
int a, b;
a = 10;
@DutchGhost
DutchGhost / parsed.rs
Created November 24, 2022 21:35
Parsed. Const parsing of strings to integral types
#![feature(const_for)]
#![feature(const_refs_to_cell)]
#![feature(const_trait_impl)]
#![feature(generic_const_exprs)]
use {
core::{
ops::{Div, Mul, Not, Add}
},
};
@DutchGhost
DutchGhost / little_lang.rs
Created November 12, 2022 16:48
Little language with push, pop, add, mul, div, sub and call instructions
use std::collections::HashMap;
const SRC: &str = "
function x
pop r1
pop r2
add r1 20
add r1 r2
@DutchGhost
DutchGhost / cvec.rs
Last active February 17, 2023 12:59
const vec
#![feature(const_ptr_is_null)]
#![feature(const_ptr_write)]
#![feature(const_mut_refs)]
#![feature(core_intrinsics)]
#![feature(inline_const)]
#![feature(const_heap)]
use core::intrinsics::{const_allocate, const_deallocate};
struct CVec<T> {
ptr: *mut T,
@DutchGhost
DutchGhost / almost_const_iter.rs
Created June 1, 2022 19:18
maybe this will work out one day?
#![feature(const_slice_index)]
#![feature(inline_const)]
#![feature(strict_provenance)]
#![feature(const_raw_ptr_comparison)]
#![feature(const_mut_refs)]
#![feature(const_trait_impl)]
use core::marker::PhantomData;
trait ConstIterator {
@DutchGhost
DutchGhost / list.zig
Created May 2, 2022 08:38
Linked list removal
const List = struct {
const Node = struct {
value: u32,
next: ?*Node = null,
};
head: ?*Node = null,
fn addNode(this: *@This(), node: *Node) void {
node.next = this.head;
@DutchGhost
DutchGhost / linked.rs
Last active September 14, 2022 08:52
Linked List generic over the ptr type
//#![feature(generic_associated_types)]
use std::ops::DerefMut;
trait PointerFamily {
type Pointer<'a, T: ?Sized + 'a>: DerefMut<Target = T>;
}
#[derive(Debug)]
struct RefFamily;
@DutchGhost
DutchGhost / const_table.rs
Last active August 9, 2022 08:20
Const table of 10's
#![feature(const_type_name)]
#![feature(const_refs_to_cell)]
#![feature(const_trait_impl)]
#![feature(generic_const_exprs)]
use core::ops::{Div, Mul, Not};
trait TableRaw<const SIZE: usize>: Sized + Copy {
const TABLE: [Self; SIZE];
}
//=============BUILD.ZIG===============
const std = @import("std");
pub fn build(b: *std.build.Builder) void {
// Standard release options allow the person running `zig build` to select
// between Debug, ReleaseSafe, ReleaseFast, and ReleaseSmall.
const mode = b.standardReleaseOptions();
const lib = b.addStaticLibrary("SelectList", "src/main.zig");
lib.setBuildMode(mode);