Skip to content

Instantly share code, notes, and snippets.

DeadMG DeadMG

Block or report user

Report or block DeadMG

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View gist:b7b7b9988067e8b32954
std::shared_ptr<Expression> ClangFunctionType::BuildCall(std::shared_ptr<Expression> val, std::vector<std::shared_ptr<Expression>> args, Context c) {
struct Call : Expression {
Call(Analyzer& an, std::shared_ptr<Expression> self, std::vector<std::shared_ptr<Expression>> args, Context c)
: a(an), args(std::move(args)), val(std::move(self))
{
if (GetType()->AlwaysKeepInMemory()) {
Ret = Wide::Memory::MakeUnique<ImplicitTemporaryExpr>(GetType(), c);
if (!GetType()->IsTriviallyDestructible())
Destructor = GetType()->BuildDestructorCall(Ret, c, true);
View gist:342d6fa38a790f04b3b3
struct Renderable { virtual ~Renderable() {} };
struct SelfRenderable : Renderable {
virtual void Render(Renderer& render) = 0;
};
class Renderer {
com_ptr<ID3D10Device> device;
public:
std::unordered_map<std::type_index, std::function<void(Renderer& renderer, const Renderable& renderable)>> rendering_functions;
void Render(Renderable& renderable) {
if (rendering_functions.find(typeid(renderable)) ! rendering_functions.end())
View gist:ce224c129f7c71224da4
Dependencies
Recently I've been working on a cross-platform program. This program depends on LLVM/Clang, and currently targets Windows and Linux. Furthermore, the program runs both as a console application and library- for example, to support a VS addin. I wanted to share some of my stories depending on these libraries, and present some don'ts of creating a library. Some of them are more subtle than others.
Mutate global state of any form. This includes direct interaction with stdin/stdout/stderr, environment variables, filesystem, the works. It's one thing to provide helpers to make interaction with them simple, and another to simply interact with them regardless. LLVM keeps global mutable lists of things like loaded DLLs. Both libraries have a nasty habit of dumping things to stdout. Running tests on Linux produces 2MB of gunk that makes the real output unreadable. And if you're running as a VS addin, nobody is listening to stdout, so it's all wasted even if you wanted to read it.
Keep private state. Ser
You can’t perform that action at this time.