Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def __eq__(self, other):
if self.astType == 'alias':
self = self.value
if other.astType == 'alias':
other = other.value
if not isinstance(other, ASTNode):
return False
for name in self.cmpnames:
if getattr(self, name) != getattr(other, name):
return False
return True
children += [ASTNode('raw', 'none',
interpreter.funccodes[funcname])]
break
else:
raise NotImplementedError(
"couldn't find matching opcode for '%s'"
% (ast.value + '_' + retsig + basesig))
# First just cast constants, then cast variables if necessary:
for i, (have, want) in enumerate(zip(basesig, sig)):
if have != want:
kind = typecode_to_kind[want]
if children[i].astType == 'constant':
children[i] = ASTNode('constant', kind, children[i].value)
else:
opname = "cast"
children[i] = ASTNode('op', kind, opname, [children[i]])
else:
value = ast.value
children = ast.children
return ASTNode(ast.astType, ast.astKind, value,
[typeCompileAst(c) for c in children])
funcname = (ast.value + '_' + retsig + sig).encode('ascii')
if funcname in interpreter.funccodes:
value = ('func_%sn' % (retsig + sig)).encode('ascii')
children += [ASTNode('raw', 'none',
interpreter.funccodes[funcname])]
break
else:
raise NotImplementedError(
"couldn't find matching opcode for '%s'"
% (ast.value + '_' + retsig + basesig))
# First just cast constants, then cast variables if necessary:
for i, (have, want) in enumerate(zip(basesig, sig)):
if have != want:
kind = typecode_to_kind[want]
if children[i].astType == 'constant':
children[i] = ASTNode('constant', kind, children[i].value)
else:
opname = "cast"
children[i] = ASTNode('op', kind, opname, [children[i]])
else:
value = ast.value
children = ast.children
return ASTNode(ast.astType, ast.astKind, value,
[typeCompileAst(c) for c in children])
def precompile(ex, signature=(), context={}):
"""Compile the expression to an intermediate form.
"""
types = dict(signature)
input_order = [name for (name, type_) in signature]
if isinstance(ex, (str, unicode)):
ex = stringToExpression(ex, types, context)
# the AST is like the expression, but the node objects don't have
# any odd interpretations
ast = expressionToAST(ex)
if ex.astType != 'op':
ast = ASTNode('op', value='copy', astKind=ex.astKind, children=(ast,))
ast = typeCompileAst(ast)
aliases = collapseDuplicateSubtrees(ast)
assignLeafRegisters(ast.allOf('raw'), Immediate)
assignLeafRegisters(ast.allOf('variable', 'constant'), Register)
assignBranchRegisters(ast.allOf('op'), Register)
# assign registers for aliases
for a in aliases:
a.reg = a.value.reg
input_order = getInputOrder(ast, input_order)
constants_order, constants = getConstants(ast)
raise NotImplementedError(
"couldn't find matching opcode for '%s'"
% (ast.value + '_' + retsig + basesig))
# First just cast constants, then cast variables if necessary:
for i, (have, want) in enumerate(zip(basesig, sig)):
if have != want:
kind = typecode_to_kind[want]
if children[i].astType == 'constant':
children[i] = ASTNode('constant', kind, children[i].value)
else:
opname = "cast"
children[i] = ASTNode('op', kind, opname, [children[i]])
else:
value = ast.value
children = ast.children
return ASTNode(ast.astType, ast.astKind, value,
[typeCompileAst(c) for c in children])
"""
children = list(ast.children)
if ast.astType == 'op':
retsig = ast.typecode()
basesig = ''.join(x.typecode() for x in list(ast.children))
# Find some operation that will work on an acceptable casting of args.
for sig in sigPerms(basesig):
value = (ast.value + '_' + retsig + sig).encode('ascii')
if value in interpreter.opcodes:
break
else:
for sig in sigPerms(basesig):
funcname = (ast.value + '_' + retsig + sig).encode('ascii')
if funcname in interpreter.funccodes:
value = ('func_%sn' % (retsig + sig)).encode('ascii')
children += [ASTNode('raw', 'none',
interpreter.funccodes[funcname])]
break
else:
raise NotImplementedError(
"couldn't find matching opcode for '%s'"
% (ast.value + '_' + retsig + basesig))
# First just cast constants, then cast variables if necessary:
for i, (have, want) in enumerate(zip(basesig, sig)):
if have != want:
kind = typecode_to_kind[want]
if children[i].astType == 'constant':
children[i] = ASTNode('constant', kind, children[i].value)
else:
opname = "cast"
children[i] = ASTNode('op', kind, opname, [children[i]])
else: