Skip to content

Instantly share code, notes, and snippets.

@9rnsr
9rnsr / patch.diff
Created February 1, 2013 11:38
A patch to allow "nested union".
diff --git a/src/struct.c b/src/struct.c
index f6fd857..3a6fe5f 100644
--- a/src/struct.c
+++ b/src/struct.c
@@ -684,9 +684,19 @@ void StructDeclaration::finalizeSize(Scope *sc)
// Set the offsets of the fields and determine the size of the struct
unsigned offset = 0;
bool isunion = isUnionDeclaration() != NULL;
+ unsigned maxofs = 0;
for (size_t i = 0; i < members->dim; i++)
@9rnsr
9rnsr / gist:4152297
Last active June 13, 2019 06:24
isType, isFunction, isPropertyFunction, isVariable, isEnum, isFinal
import std.traits;
/**
* Detect whether $(D X) is a type or not.
*/
template isType(X...) if (X.length == 1)
{
enum isType = is(X[0]);
}
@9rnsr
9rnsr / gist:3156840
Created July 21, 2012 19:01
A library implementation of arr.dup/idup
template isMutable(T)
{
enum isMutable = !is(T == const) && !is(T == immutable) && !is(T == inout);
}
template Unqual(T)
{
static if (is(T U == shared(const U))) alias U Unqual;
else static if (is(T U == const U )) alias U Unqual;
else static if (is(T U == immutable U )) alias U Unqual;
else static if (is(T U == inout U )) alias U Unqual;
@9rnsr
9rnsr / functionstyle.d
Created June 5, 2012 04:04 — forked from majiang/functionstyle.d
function style
import std.stdio;
void main()
{
T delegate(T) zero(T)(T delegate(T) f)
{
return x => x;
}
T delegate(T) delegate(T delegate(T)) succ(T)(T delegate(T) delegate(T delegate(T)) n)
@9rnsr
9rnsr / makefile
Created June 24, 2011 17:02
D programming language build makefile in Windows
# reqire DigitalMars make, and cp command in MSYS.
######## MAKE PARAMETERS ########
#DMCDIR=c:\dm
#DMDDIR=c:\dmd2
## INTERNAL VARIABLES ##
/**
Source,Pool,Sinkの3つを基本I/Fと置く
(バッファリングされたSinkを明示的に扱う手段はなくす)
それぞれがやり取りする要素の型は任意だが、Fileはubyteをやり取りする
(D言語的にはvoid[]でもいいかも)
Encodedはubyteを任意型にcastする機能を提供する
Bufferedはバッファリングを行う
@9rnsr
9rnsr / sealed.d
Created November 5, 2010 14:56
Sealed struct
module sealed;
import std.stdio;
@trusted struct Sealed(T)
{
//private T* p;
public T* p;
this(ref T t)
{