def build(fcn, args, original=None):
if all(isinstance(x, Literal) for x in args):
empty = SymbolTable()
schema, typedargs, subempty = fcn.buildtyped(args, empty)
if isinstance(schema, Impossible):
if schema.reason is not None:
reason = "\n\n " + schema.reason
else:
reason = ""
complain("Function \"{0}\" does not accept arguments with the given literal types:\n\n {0}({1}){2}".format(fcn.name, ",\n {0} ".format(" " * len(fcn.name)).join(pretty(x.schema, prefix=" " + " " * len(fcn.name)).lstrip() for x in typedargs), reason), original)
else:
return Literal(fcn.pythoneval([x.value for x in args]), original)
else:
if fcn.associative:
newargs = []
for arg in args:
if isinstance(arg, Call) and arg.fcn == fcn:
newargs.extend(arg.args)
else:
newargs.append(arg)
else:
newargs = args
return Call(fcn, newargs, original)
评论列表
文章目录