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
class Visitor: | |
def dispatch(self, tree): | |
"Dispatcher function, dispatching tree type T to method _T." | |
meth = getattr(self, "_"+tree.__class__.__name__) | |
meth(tree) | |
test edit |
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
from mm import multimethod | |
class Scope: | |
pass | |
class GlobalScope(Scope): | |
pass | |
class Statement: | |
pass |
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 dispatch | |
class Visitor: | |
@dispatch.on('node') | |
def visit(node): | |
print "Base implementation" | |
@visit.when(Scope) | |
def visit(node): |
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
class Visitor: | |
def visit(self, node): | |
"Dispatcher function, dispatching tree type T to method _T." | |
meth = getattr(self, "_"+node.__class__.__name__) | |
meth(node) | |
def _Scope(self, node): | |
print "Scope" |
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
registry = {} | |
class MultiMethod(object): | |
def __init__(self, name): | |
self._name = name | |
self._typemap = {} | |
def __call__(self, *args): | |
types = tuple(arg.__class__ for arg in args) | |
function = self._typemap.get(types) | |
if function is None: |
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 dispatch | |
class Visitor: | |
@dispatch.on('node') | |
def visit(self, node): | |
print "Base implementation" |
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
#include <petscsys.h> | |
#include <petscksp.h> | |
// Struct copied from reg.c so we can access the members of a PetscFList | |
struct _n_PetscFList { | |
void (*routine)(void); /* the routine */ | |
char *path; /* path of link library containing routine */ | |
char *name; /* string to identify routine */ | |
char *rname; /* routine name in dynamic library */ | |
PetscFList next; /* next 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
# Set up finite element problem. We do this by defining the finite element | |
# variational forms using the Unified Form Language (UFL) | |
E = FiniteElement("Lagrange", "triangle", 1) | |
v = TestFunction(E) | |
u = TrialFunction(E) | |
f = Coefficient(E) | |
g = Coefficient(E) |
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
int* f() | |
{ | |
static int a[3] = {1,2,3}; | |
return a; | |
} |
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
module IBZ | |
implicit none | |
type Plane | |
integer :: M(1,1) | |
end type Plane | |
contains | |
integer function t() |
OlderNewer