def toFun(self, n): idx = simplify(n).as_long() # In case the solver randomly select a solution to be a fun # without fmap existing in the model arity = self.arity[idx] if self.fmap is None or self.fmap[idx] is None: return self.defaultFun(arity) defn = self.getArrayDecl(self.fmap[idx], self.erl.List).as_list() # Also prune keys with the wrong arity (mainly to genericFun specs adding an Exists axiom) kvs = [self.encodeKVPair(args, val) for [args, val] in defn[0:-1] if self.getActualArity(args) == arity] if len(kvs) == 0: default = self.encodeDefault(defn[-1]) return cc.mk_const_fun(arity, default) else: default = cc.get_value_from_fun_entry(kvs[0]) # Do not add the arity. # It will be deducted from the number of the arguments of the # first input. # return {"t": cc.JSON_TYPE_FUN, "v": kvs, "x": arity} return cc.mk_fun(arity, kvs, default)
def defaultFun(self, arity): default = self.encodeDefault(self.erl.Term.int(0)) return cc.mk_const_fun(arity, default)