def compile(expression, default_type=None, **types): """Compile 'expression'. 'expression' -- """ if isCompiledExpression(expression): # It is already compiled. return expression expression = asExpression(expression) if default_type is not None: # Set default symbol types. expression = op.setTypesFixed(expression, None, default_type) if len(types) != 0: # Set specific symbol types. expression = op.setTypes(expression, **types) # Do the compilation. expression = op.optimize(expression) return compiler.compile(expression)
# If it's numerical, wrap it in a constant. elif type(arg) in (int, float, long): expr = Constant(arg) # Don't know how to handle other things. else: raise TypeError, "argument must be an expression" # Substitute names. expr = substitute(expr, **names) # Set types. if types_from is not None: expr = setTypesFrom(expr, **types_from) if types is not None: expr = setTypes(expr, **types) # Compile it, if requested. if compile: expr = compiler.compile(expr) # All done. return expr def parse(expression_string, **names): expression = expr_parser.parse(expression_string) expression = substitute(expression, **names) return expression def compile(expression, default_type=None, **types): """Compile 'expression'.