This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import csv | |
import pydot | |
def predecessors(pred, targets): | |
d = {} | |
graph = pydot.Dot(graph_type='digraph', graph_name='Predecessors') | |
for target_activity in targets: | |
target_list = [] | |
d[target_activity] = target_list | |
predecessors_impl(graph, pred, None, target_activity, target_list) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const TypeInfo = @import("builtin").TypeInfo; | |
// Generates the following: | |
// struct { pub const Self = this; data: Base, next: ?*Self, } | |
pub fn contrived_example(comptime Base: type) type { | |
comptime { | |
var fields = []TypeInfo.StructField { | |
TypeInfo.StructField { .name="data", .offset=null, .field_type=Base }, | |
// SelfType is defined as SelfType = @OpaqueType() | |
// It's simply a tag type that represents the resulting reified type. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const builtin = @import("builtin"); | |
const TypeId = builtin.TypeId; | |
const TypeInfo = builtin.TypeInfo; | |
const std = @import("std"); | |
const mem = std.mem; | |
const assert = std.debug.assert; | |
// @TODO Add const SelfType variant, perhaps SelfType(bool)? (to actually distinguish between const and non const methods) | |
pub const SelfType = *@OpaqueType(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const std = @import("std"); | |
const assert = std.debug.assert; | |
const Iterator_Buffer_Size = 24; | |
// Returns a function pointer to 'ImplType.next: fn(&ImplType) ?T' | |
// This could be generalized by taking a comptime name: []const u8 and looking up the function. | |
// Also, for nullable function pointers, with some metaprogramming we could determine wether the | |
// function is present in ImplType and only included it then. | |
fn get_next_fn(comptime ImplType: type, comptime T: type) fn(usize)?T { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const std = @import("std"); | |
// standard metaprogramming library, exposes wrappers over low level @reflect/@reify stuff. | |
const meta = std.meta; | |
pub const VTableEntry = struct { | |
const Self = this; | |
name: []const u8, | |
ftype: type, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const std = @import("std"); | |
const warn = std.debug.warn; | |
const TypeId = @import("builtin").TypeId; | |
const VTable = struct { | |
accelerate_fn: fn(self: usize) void, | |
}; | |
fn Unwraped(comptime T: type) type { | |
if (@typeId(T) == TypeId.Pointer) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const std = @import("std"); | |
const warn = std.debug.warn; | |
const TypeId = @import("builtin").TypeId; | |
fn Iterator(comptime T: type) type { | |
return struct { | |
const Self = this; | |
const ResetError = error { | |
NotResetable, | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const eql = @import("std").mem.eql; | |
fn field_adder(comptime Base: type, comptime name: []u8, comptime field_type: type) type { | |
var info = @reflect(Base); | |
var i : usize = 0 | |
while (i < @memberCount(Base)) : (i += 1) { | |
if (eql(u8, @memberName(Base, i), name)) { | |
@compileError("Member already present"); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const std = @import("std"); | |
const TypeId = @import("builtin").TypeId; | |
const allocPrint = std.fmt.allocPrint; | |
// This should be equivalent to Tuple(f32, f32) | |
fn TestTuple() type { | |
return struct { | |
const Self = this; | |
const Types = []type { f32, f32 }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Variant type checker to make sure definition and implementation are in sync. | |
template <typename VariantT, int Index, typename Current, typename... Args> | |
struct check_variant_sub { | |
inline static constexpr bool value = std::is_same_v<std::decay_t<decltype(std::get<Index>(std::declval<VariantT>()))>, Current> | |
&& check_variant_sub<VariantT, Index + 1, Args...>::value; | |
}; | |
template <typename VariantT, int Index, typename Last> | |
struct check_variant_sub<VariantT, Index, Last> { | |
inline static constexpr bool value = std::is_same_v<std::decay_t<decltype(std::get<Index>(std::declval<VariantT>()))>, Last>; |