Skip to content

Instantly share code, notes, and snippets.

@dcampbell24
dcampbell24 / gist:3470851
Created August 25, 2012 20:54
julia ccall macro
macro ccallWrap(lib, fnSym, retType, argTypes)
argTypes = eval(argTypes)
assertOp = :(sym::Type).head
args = [gensym() for i in 1:length(argTypes)]
fnArgs = [Expr(assertOp, {args[i], argTypes[i]}, Any)
for i in 1:length(argTypes)]
dlsymExpr = Expr(:call, {:dlsym, lib, fnSym}, Any)
ccallExpr = Expr(:call,{:ccall, dlsymExpr, retType, argTypes, args...},Any)
fnBody = Expr(:block, {ccallExpr}, Any)
@dcampbell24
dcampbell24 / gist:3162325
Created July 23, 2012 06:51
Function manipulating int8 values
# Returns the new cell index from the specified cell in the
# specified direction. The index is only valid if the
# starting cell and direction have been checked by the
# out_of_bounds function first.
function shift(cell_::Int8, dir::Int8)
div5_mod2(x) = (x - 1)/5 % 2 != 0
if dir == E
return int8(cell_ + 1)
elseif dir == ESE
if div5_mod2(cell_)