Skip to content

Instantly share code, notes, and snippets.

View UplinkCoder's full-sized avatar

Stefan Koch UplinkCoder

View GitHub Profile
@UplinkCoder
UplinkCoder / test0168.d
Last active August 29, 2015 14:07
TernaryOperator test and output
//T compiles:yes
//T has-passed:yes
//T retval:42
//? Tests TernaryOperator
import std.stdio;
int main() {
auto s = 0;
ubyte right = cast(ubyte) 42;
@UplinkCoder
UplinkCoder / valuerange.d
Last active August 29, 2015 14:07
ValueRange Visitor
module d.semantic.valuerange;
import d.semantic.semantic;
import d.ir.type;
import d.ast.expression;
import d.ir.expression;
struct ValueRange {
double _min;
import std.stdio;
import std.string;
void main() {
getLibString().writeLibs();
}
string getLibString(string p_llvmConfig="llvm-config") {
import std.process;
module combtest;
import std.string;
import std.stdio;
import std.file;
import std.conv;
struct Test {
public:
uint number;
bool compiles;
@UplinkCoder
UplinkCoder / comb.d
Created November 5, 2014 09:21
Almost sdc tests combind into one.
static struct Test0 {
static:
// Tests the simplest of programs.
int main() {
return 42;
}
bool run() { return main() == 42; }
@UplinkCoder
UplinkCoder / traits.d
Created November 8, 2014 18:48
Useful traits for ast
module d.convenience.traits;
import d.ir.expression;
import d.ir.type;
QualType elementType(Expression e) {
assert(isSliceOrArray(e) || isPointer(e), typeid(e.type.type).toString() ~ " has no elementType");
return elementType(e.type);
}
@UplinkCoder
UplinkCoder / rot13_leetify.d
Created January 21, 2015 09:45
rot13-leetify
module rot13_leetify;
import std.stdio;
import std.algorithm:map,filter;
char rot13(char c) pure {
switch(c) {
case 'a': .. case 'm':
@UplinkCoder
UplinkCoder / patternm.d
Last active August 29, 2015 14:14
small patternMatching template
// returns where the pattern matched
uint[] match(T)(T[] elems, T[] pattern) {
uint[] positionsMatched;
uint posInPattern;
uint posInElems;
while (elems.length - posInElems >= pattern.length - posInPattern) {
if (pattern[posInPattern] == elems[posInElems]) {
if (posInPattern == pattern.length-1) {
@UplinkCoder
UplinkCoder / ctfeTest.d
Last active November 1, 2018 16:46
Current Compilable code with the new CTFE engine
struct V3 {
int x;
int y;
int z;
int w = 30;
}
int fn(V3 v3) {
return v3.y;
}
int fn2(V3 v3) {
diff --git a/src/dtemplate.d b/src/dtemplate.d
index d90d25c..d3c1587 100644
--- a/src/dtemplate.d
+++ b/src/dtemplate.d
@@ -7943,8 +7943,8 @@ extern (C++) class TemplateInstance : ScopeDsymbol
Declaration d = sa.isDeclaration();
if ((td && td.literal) || (ti && ti.enclosing) || (d && !d.isDataseg() && !(d.storage_class & STCmanifest) && (!d.isFuncDeclaration() || d.isFuncDeclaration().isNested()) && !isTemplateMixin()))
{
- // if module level template
- if (isstatic)