Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: 24127f198a
Fetching contributors…

Cannot retrieve contributors at this time

190 lines (187 sloc) 5.839 kb
import CodeObjects as co
class TestResponder(object):
def handlerFunctionClosure(s, n):
def handlerFunction(*x):
return (n,) + x
return handlerFunction
def __getattr__(s, n):
return s.handlerFunctionClosure(n)
class ObjResponder(object):
def voidT(s):
return co.voidTyp
def boolT(s):
return co.boolTyp
def intT(s):
return co.intTyp
def strT(s):
return co.strTyp
def bigness(s, x):
return len(x)
def setT(s, t, b):
return co.mapTypOf(x[1], co.VoidTyp)(bigness=b)
def listT(s, t, b):
return co.mapTypOf(co.IntTyp, x[1])(bigness=x[0])
def mapT(s, t, b):
return co.mapTypOf(co.StrTyp, x[1])(bigness=x[0])
def boolTrue(s):
return co.LitExpr(val=True)
def boolFalse(s):
return co.LitExpr(val=False)
def intLit(s, v):
return co.LitExpr(val=int(v))
def strLit(s, v):
d = { ':' : ':', ')' : '\n', '>' : '\t', 'o' : '\x07',
'"' : '"' }
return co.LitExpr(
re.sub(':(.)', lambda m: d[]
if in d
else, v[1:-1]))
def notEqual(s, a, b):
return co.NegateExpr(co.EqExpr(terms=(a, b)))
def greaterThan(s, a, b):
return co.GrtExpr(terms=(a, b))
def lessThan(s, a, b):
return co.LessExpr(terms=(a, b))
def equals(s, a, b):
return co.EqExpr(terms=(a, b))
def or_(s, x):
return co.OrExpr(terms=x)
def xor(s, a, b):
return co.OrExpr(terms=(a, b))
def and_(s, x):
return co.AndExpr(terms=x)
def not_(s, x):
return co.NegateExpr(x)
def concat(s, x):
return co.ConcatExpr(x)
def sliceClause(s, o, x):
return (o.lower(), x)
def slice_(s, x, *c):
return co.SlicingExpr(strExpr=x, **dict(c))
def max_(s, x):
return co.MaxExpr(terms=x)
def min_(s, x):
return co.MinExpr(terms=x)
def add(s, x):
return co.AddExpr(terms=x)
def diff(s, x):
return co.DiffExpr(terms=x)
def divide(s, x):
return co.DivExpr(terms=x)
def mult(s, x):
return co.MultExpr(terms=x)
def modulus(s, x):
return co.ModExpr(terms=x)
def negative(s, x):
return co.DiffExpr(terms=[0, x])
def first(s, x):
return co.FirstExpr(agg=x)
def last(s, x):
return co.LastExpr(agg=x)
def get(s, i, a):
return co.GetExpr(subj=a, index=i)
def cast(s, v, t):
return co.CastExpr(val=v, typ=t)
def call(s, h, *a):
return co.CallExpr(head=h, args=a)
def exprSt(s, x):
return co.ExprStmnt(expr=x)
def decl(s, v, t):
return co.Declaration(var=v, typ=t)
def assign(s, v, x):
return co.Assignment(var=v, expr=x)
def insertSt(s, a, k, v*):
assert len(v) < 2
return co.InsertStmnt(agg=a, key=k,
val=v[0] if v else None)
def removeSt(s, a, k):
return co.RemoveStmnt(agg=a, key=k)
def unionSt(s, l, r):
return co.UnionStmnt(lagg=l, ragg=r)
def diffSt(s, l, r):
return co.DiffStmnt(lagg=l, ragg=r)
def interSt(s, l, r):
return co.InterStmnt(lagg=l, ragg=r)
def castSt(s, v, t):
return co.Assignment(var=v, expr=co.CastExpr(
val=co.VariableExpr(var=v), typ=t))
def inputSt(s, x):
readType, var = (['LINE'] + x)[-2:]
return co.InputStmnt(var=var, read=readType.lower())
def outputSt(s, x):
return co.OutputStmnt(handle='out', terms=x, nl=False)
def outputLnSt(s, x):
return co.OutputStmnt(handle='out', terms=x, nl=True)
def debugSt(s, x):
return co.OutputStmnt(handle='err', terms=x, nl=False)
def debugLnSt(s, x):
return co.OutputStmnt(handle='err', terms=x, nl=True)
def posCon(s, x):
return (True, None)
def negCon(s, x):
return (False, None)
def exprCon(s, x):
return (None, x)
def condBlock(s, e, b):
return e + (b,)
def condSt(s, x, c*):
return co.Conditional(test=x, blocks=c)
def caseExpr(s, x):
return x
def caseDefault(s, x):
return None
def caseBlock(s, x, b):
return (x, b)
def caseSt(s, x, b*):
return co.Case(test=x, blocks=b)
def until(s, x):
return {'term': co.NegateExpr(x)}
def while_(s, x):
return {'term': x}
def loopLabel(s, x):
return co.LabelName(x)
def ctrInc(s):
return co.Simple('++')
def ctrDec(s):
return co.Simple('--')
def ctrDir(s, d, v):
return {'count': (v, d)}
def ctrHead(s, c*):
d = { 'count': None, 'term': None }
return d
def ctrSt(s, lo, h, b, lc):
assert lo == lc
return co.Counter(lo, b, **h)
def iterVars(s, iv, vv=None):
return {'iter': iv, 'iterVal': vv }
def iterHead(s, v, agg, tc=None):
d = {}
d['agg'] = agg
return d
def iterSt(s, lo, h, b, lc):
assert lo == lc
return co.Iterator(lo, b, **h)
def breakSt(s, label=None):
return co.Break(label)
def continueSt(s, label=None):
return co.Continue(label)
def returnSt(s, expr):
return co.Return(expr)
def arg(s, a):
d = {'var': a[-1]}
d['type'] = a[0] if len(a) > 1
def args(s, ax):
return tuple(ax)
def returnType(s, t):
return t
def funcDef(s, nm, ax, t, b):
return co.Function(name=nm, args=ax, ret=t, body=b)
def block(s, ax):
return co.Block(ax)
def fileHeader(s, numbers):
return { 'version': numbers }
def fileAll(s, v, b):
return co.File(v, b)
Jump to Line
Something went wrong with that request. Please try again.