took a break and started to figure out worker codenames for fun

This commit is contained in:
2025-07-07 23:32:35 -04:00
parent 6d780482c7
commit a617ecc61f
18 changed files with 206 additions and 21 deletions

View File

@ -0,0 +1,30 @@
package grime
// Provides an alternative syntax for pointers
Ptr :: struct( $ Type : typeid ) {
v : Type,
}
exmaple_ptr :: proc()
{
a, b : int
var : ^Ptr(int)
reg : ^int
a = 1
b = 1
var = &{a}
var.v = 2
var = &{b}
var.v = 3
a = 1
b = 1
reg = (& a)
(reg^) = 2
reg = (& b)
(reg^) = 3
}

View File

@ -0,0 +1,96 @@
package grime
import "core:mem"
RingBuffer :: struct($T: typeid) {
data: []T,
head: int,
tail: int,
len: int,
is_full: bool,
}
init :: proc(rb: ^RingBuffer($T), capacity: int, allocator := context.allocator) -> mem.Allocator_Error {
data, err := make([]T, capacity, allocator)
if err != nil {
return err
}
rb.data = data
rb.head = 0
rb.tail = 0
rb.len = 0
rb.is_full = false
return nil
}
destroy :: proc(rb: ^RingBuffer($T)) {
delete(rb.data)
rb^ = {}
}
len :: proc(rb: RingBuffer($T)) -> int {
return rb.len
}
cap :: proc(rb: RingBuffer($T)) -> int {
return len(rb.data)
}
is_empty :: proc(rb: RingBuffer($T)) -> bool {
return rb.len == 0
}
is_full :: proc(rb: RingBuffer($T)) -> bool {
return rb.is_full
}
push_back :: proc(rb: ^RingBuffer($T), value: T) {
if rb.is_full {
rb.data[rb.head] = value
rb.head = (rb.head + 1) % len(rb.data)
rb.tail = rb.head
} else {
rb.data[rb.tail] = value
rb.tail = (rb.tail + 1) % len(rb.data)
rb.len += 1
rb.is_full = rb.len == len(rb.data)
}
}
pop_front :: proc(rb: ^RingBuffer($T)) -> (T, bool) {
if rb.len == 0 {
return T{}, false
}
value := rb.data[rb.head]
rb.head = (rb.head + 1) % len(rb.data)
rb.len -= 1
rb.is_full = false
return value, true
}
get :: proc(rb: RingBuffer($T), index: int) -> (T, bool) {
if index < 0 || index >= rb.len {
return T{}, false
}
actual_index := (rb.head + index) % len(rb.data)
return rb.data[actual_index], true
}
RingBufferIterator :: struct($T: typeid) {
rb: ^RingBuffer(T),
current: int,
}
iterator :: proc(rb: ^RingBuffer($T)) -> RingBufferIterator(T) {
return RingBufferIterator(T){rb = rb, current = 0}
}
next :: proc(it: ^RingBufferIterator($T)) -> (T, bool) {
if it.current >= it.rb.len {
return T{}, false
}
value, _ := get(it.rb^, it.current)
it.current += 1
return value, true
}