Skip to content

Instantly share code, notes, and snippets.

@gingerBill
gingerBill / plugin_system_idea.md
Last active April 16, 2017 10:56
Plug-in System for a Compiler (Idea for Odin)

One of the original goals in Odin was metaprogramming. However, as development progressed, it has come clear that this is such a broad term which could mean anything.

The kinds of metaprogramming originally conceived are compile time execution, AST modification, and "semantic macros".

Here is the new idea: allow the user to "plug-in" their own metaprogramming functionality as a stage in the compiler. With the specific stages being:

  • File loading (get text into memory)
  • Tokenizing/Lexing
  • Parsing
  • Type checking
@gingerBill
gingerBill / stb_image.odin
Last active November 4, 2017 11:39
stb_image in Odin
when ODIN_OS == "windows" do foreign import stbi "stb_image.lib"
//
// load image by filename, open file, or memory buffer
//
Io_Callbacks :: struct #ordered {
read: proc "c" (user: rawptr, data: ^u8, size: i32) -> i32, // fill 'data' with 'size' u8s. return number of u8s actually read
skip: proc "c" (user: rawptr, n: i32), // skip the next 'n' u8s, or 'unget' the last -n u8s if negative
eof: proc "c" (user: rawptr) -> i32, // returns nonzero if we are at end of file/data
}
Brief comments on https://eev.ee/blog/2016/12/01/lets-stop-copying-c/ for Odin
A - Agree with eev.ee
D - Disagree with eev.ee
S - Have it for sanity reasons
O - Other reason
[A] Textual Inclusion
[A] Optional block delimiters
[A] Bitwise operator precedence
#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
@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)

@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 / 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",
%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 / 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();
@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;
}