# Default is to simply test the truth of the expression |
# Default is to simply test the truth of the expression |
return Test(Truth(expr), Value(True)) |
return Test(Truth(expr), Value(True)) |
|
|
|
when(expressionSignature, (Const,))(lambda expr: bool(expr.value)) |
|
|
def compileIn(expr, criterion): |
def compileIn(expr, criterion): |
"""Return a signature or predicate (or None) for 'expr in criterion'""" |
"""Return a signature or predicate (or None) for 'expr in criterion'""" |
try: |
try: |
|
|
|
|
|
|
|
|
|
|
class IndexedEngine(Engine, TreeBuilder): |
class IndexedEngine(Engine, TreeBuilder): |
"""A dispatching engine that builds trees using bitmap indexes""" |
"""A dispatching engine that builds trees using bitmap indexes""" |
|
|
|
|
# === As of this point, it should be possible to compile expressions! |
# === As of this point, it should be possible to compile expressions! |
# |
# |
when(expressionSignature, |
meta_function(isinstance)( |
# matches 'issubclass/isinstance(?, Const)' |
lambda __star__, __dstar__, *args, **kw: |
"expr in Call and expr.func in Const" |
compileIsXCall(isinstance, IsInstance, args, kw, __star__, __dstar__) |
" and (expr.func.value is issubclass or expr.func.value is isinstance)" |
) |
" and len(expr.args)==2 and expr.args[1] in Const" |
meta_function(issubclass)( |
) |
lambda __star__, __dstar__, *args, **kw: |
def convertIsXCall(expr): |
compileIsXCall(issubclass, IsSubclass, args, kw, __star__, __dstar__) |
func, (expr, seq) = expr.func.value, expr.args |
) |
if func is isinstance: |
def compileIsXCall(func, test, args, kw, star, dstar): |
expr = IsInstance(expr) |
if ( |
elif func is issubclass: |
kw or len(args)!=2 or not isinstance(args[1], Const) |
expr = IsSubclass(expr) |
or isinstance(args[0], Const) or star is not None or dstar is not None |
else: |
): |
raise AssertionError("Should only be called for isinstance/issubclass") |
return expressionSignature( |
|
Call(Const(func), args, tuple(kw.items()), star, dstar) |
return Test(expr, Disjunction(map(Class, _yield_tuples(seq.value)))) |
) |
|
expr, seq = args |
|
return Test(test(expr), Disjunction(map(Class, _yield_tuples(seq.value)))) |
|
|
def _yield_tuples(ob): |
def _yield_tuples(ob): |
if type(ob) is tuple: |
if type(ob) is tuple: |
|
|
|
|
|
|
|
|
|
|