Skip to content

Instantly share code, notes, and snippets.

View bendmorris's full-sized avatar

Ben Morris bendmorris

View GitHub Profile
@bendmorris
bendmorris / AssertTest.hx
Created March 2, 2018 17:47
Haxe assert macro
import haxe.macro.Context;
import haxe.macro.Expr;
import haxe.macro.ExprTools;
class AssertTest {
macro public static function assert(e:ExprOf<Bool>) {
#if debug
var assertion = ExprTools.toString(e);
return macro {
if (!$e) {
@bendmorris
bendmorris / test.kit
Created October 19, 2018 21:50
Kit allocator example
import kit.mem;
struct MyStruct {
public var x: Int;
public var y: Int;
public static function new(allocator: Box[Allocator]): Ptr[MyStruct] {
var newValue: Ptr[MyStruct] = allocator.alloc(sizeof MyStruct);
newValue.x = 1;
newValue.y = 2;
@bendmorris
bendmorris / test.kit
Last active October 26, 2018 18:36
Kit: additive blending
abstract Color: Uint32 {
rules {
(${a: Color} + ${b: Color}) =>
((($a & 0xff0000) + ($b & 0xff0000)) & 0xff0000) +
((($a & 0xff00) + ($b & 0xff00)) & 0xff00) +
((($a & 0xff) + ($b & 0xff)) & 0xff) as Color;
}
}
function main() {
@bendmorris
bendmorris / test.kit
Created October 26, 2018 23:18
Kit: trait method forwarding
trait MyTrait {
public function doSomething(): Void;
}
abstract MyType: Int {
rules {
($this.doSomething) => $this.MyTrait.doSomething;
}
}
@bendmorris
bendmorris / hellogc.kit
Created March 30, 2019 18:55
Kit GameCube example
// adapted from the original acube demo by tkcne.
// enjoy
include "stdlib.h";
include "string.h";
include "malloc.h";
include "math.h";
include "gccore.h";
include "stdio.h";