Skip to content

Instantly share code, notes, and snippets.

View chriswailes's full-sized avatar

Chris Wailes chriswailes

View GitHub Profile
@chriswailes
chriswailes / gist:3762434
Created September 21, 2012 16:20
Visitor Implementation Options
class MyVisitor < RLTK::Visitor
def wrapper_fun
...
yield
...
end
# Option 1
on KlassName do
wrapper_fun do |params|
@chriswailes
chriswailes / gist:3364325
Created August 15, 2012 22:35
C++11 Type Trait Issue
#ifndef RATIONAL_H
#define RATIONAL_H
/*
* Standard Includes
*/
#include <type_traits>
/*
@chriswailes
chriswailes / gist:3173150
Created July 24, 2012 22:43
Casting Problems with Templates
class MyClass {
template <typename IntType>
inline operator typename std::enable_if<std::is_integral<IntType>::value, IntType>::type () {
// Integer specific code.
}
template <typename FloatType>
inline operator typename std::enable_if<std::is_floating_point<FloatType>::value, FloatType>::type () {
// Float specific code.
}
@chriswailes
chriswailes / gist:2962792
Created June 20, 2012 23:04
RLTK/LLVM-ECB Example File
# Ruby Language Toolkit
require 'rltk/cg/llvm'
require 'rltk/cg/module'
require 'rltk/cg/execution_engine'
require 'rltk/cg/target'
require 'rltk/cg/type'
require 'rltk/cg/value'
RLTK::CG::LLVM.init(:all)
RLTK::CG::LLVM.init_asm_parser(:all)
@chriswailes
chriswailes / abstract_class.rb
Created April 20, 2012 23:47
Abstract Class implementation for Ruby
module AbstractClass
def self.included(klass)
klass.instance_exec do
@abstract_class = klass
def self.new(*args)
if self == @abstract_class
raise "Instantiating abstract class #{self} is not allowed."
else
super
module A
def A.included(klass)
klass.instance_exec do
@@foo = 0
def inc()
puts self.object_id
puts @@foo