Skip to content

Instantly share code, notes, and snippets.

@gingerBill
gingerBill / defer.cpp
Last active November 20, 2022 17:45
Golang Defer in C++
////////////////////////////////////////////////////////////////
//
// Defer statement
// - Akin to D's SCOPE_EXIT or similar to Go's defer but scope-based
//
////////////////////////////////////////////////////////////////
#if defined(__cplusplus)
extern "C++" {
// NOTE(bill): Stupid fucking templates
template <typename T> struct gbRemove_Reference { typedef T Type; };
@gingerBill
gingerBill / augmented.c
Created June 6, 2016 13:55
Augmented C - 002
#ifndef AUGMENTED_C_GUARD
#define AUGMENTED_C_GUARD
#include <stddef.h>
typedef ptrdiff_t isize;
#define offset_of(Type, element) ((isize)&(((Type *)0)->element))
#define JOIN2_IND(a, b) a##b
#define JOIN2(a, b) JOIN2_IND(a, b)
@gingerBill
gingerBill / build_msvc.sublime-build
Created June 8, 2016 19:10
Sublime Build - MSVC
{
"shell_cmd": "build.bat",
"file_regex": "^ *([A-z]:.*)[(]([0-9]+)[)]",
"working_dir": "${project_path:${folder}}"
}
@gingerBill
gingerBill / gist:da32316b488950491189364e97198cd8
Last active November 5, 2017 11:57
Incomplete tokenizer for WIP language
// NOTE(bill): Requires gb.h v0.25a
// TODO(bill): Unicode support
b32 rune_is_letter(Rune r) {
if (gb_char_is_alpha(cast(char)r) || r == '_') {
return true;
}
return false;
}
@gingerBill
gingerBill / demo001.odin
Created August 26, 2016 11:11
First Odin Demo
// Demo 001
#load "basic.odin"
#load "game.odin"
main :: proc() {
_ = hellope();
procedures();
variables();
constants();
types();
%YAML 1.2
---
# http://www.sublimetext.com/docs/3/syntax.html
name: Odin
file_extensions:
- odin
first_line_match: "-[*]-( Mode:)? Odin -[*]-"
scope: source.odin
variables:
identifier: '\b[[:alpha:]_][[:alnum:]_]*\b'
@gingerBill
gingerBill / gist:a02887b5f989c0a19d94384c6051e365
Created October 27, 2016 19:11
Bill's Sublime Settings File
{
"auto_indent": true,
"auto_match_enabled": true,
"binary_file_patterns":
[
"*.dds",
"*.eot",
"*.gif",
"*.ico",
"*.jar",
@gingerBill
gingerBill / GCC
Last active October 27, 2016 22:01
{
"shell_cmd": "build",
"file_regex": "^(..[^:]*):([0-9]+):?([0-9]+)?:? (.*)$",
"working_dir": "${project_path:${folder}}"
}
@gingerBill
gingerBill / compile_time_execution_problems.md
Last active June 28, 2023 08:48
Compile Time Execution Problems (Metaprogramming)

Compile Time Execution Problems (Metaprogramming)

2016-11-02

Memory and Types

Compile time execution (CTE) is a stage of the compiler which runs any Odin code the user requests before the creation of the executable. The data modified and generated by this stage will be used as the initialization data for the compiled code.

The CTE stage is an interpreter running the generated single static assignment (SSA)

#foreign_library "stb_image"
DEFAULT :: 0
GREY :: 1
GREY_ALPHA :: 2
RGB :: 3
RGB_ALPHA :: 4
io_callbacks :: struct #ordered {
read: proc(user: rawptr, data: ^byte, size: i32) -> i32 // fill 'data' with 'size' bytes. return number of bytes actually read