def mk_atom(chars): """ Parameters chars : list of ints """ t = ErlangTerm() t.type = ErlangTerm.ATOM t.atom_chars.extend(chars) return t
def mk_tuple(subterms): """ Parameters subterms : list of ErlangTerm """ t = ErlangTerm() t.type = ErlangTerm.TUPLE t.subterms.extend(subterms) return t
def mk_list(subterms): """ Parameters subterms : list of ErlangTerm """ t = ErlangTerm() t.type = ErlangTerm.LIST t.subterms.extend(subterms) return t
def mk_float(f): """ Parameters f : float """ t = ErlangTerm() t.type = ErlangTerm.FLOAT t.value = str(f) return t
def mk_int(i): """ Parameters i : int """ t = ErlangTerm() t.type = ErlangTerm.INTEGER t.value = str(i) return t
def mk_alias(s): """ Parameters s : string """ t = ErlangTerm() t.type = ErlangTerm.SUBTERM t.value = s return t
def mk_symb(s): """ Parameters s : string """ t = ErlangTerm() t.type = ErlangTerm.SYMBOLIC_VARIABLE t.value = s return t
def mk_bitstring(bits): """ Parameters bits : list of bool """ t = ErlangTerm() t.type = ErlangTerm.BITSTRING t.bits.extend(bits) return t
def toAtom(self, term): A = self.erl.Atom s = simplify(term) chars = [] while (is_true(simplify(A.is_acons(s)))): hd = simplify(A.ahd(s)) s = simplify(A.atl(s)) chars.append(simplify(hd).as_long()) t = ErlangTerm() t.type = ErlangTerm.ATOM t.atom_chars.extend(chars) return t
def toTuple(self, term): L = self.erl.List s = simplify(term) subterms = [] while (is_true(simplify(L.is_cons(s)))): hd = simplify(L.hd(s)) s = simplify(L.tl(s)) subterms.append(self.encode(hd)) t = ErlangTerm() t.type = ErlangTerm.TUPLE t.subterms.extend(subterms) return t
def mk_fun(arity, points, otherwise): """ Parameters arity : integer points : list of FunEntry otherwise : ErlangTerm """ t = ErlangTerm() t.type = ErlangTerm.FUN t.arity = arity t.otherwise.CopyFrom(otherwise) if len(points): t.points.extend(points) return t
def toBitstring(self, n, term): sz = simplify(n).as_long() if sz < 0: sz = 0 B = self.erl.BitStr s = simplify(term) bits = [] while (is_true(simplify(B.is_bcons(s)))) and sz > 0: sz -= 1 hd = simplify(B.bhd(s)) s = simplify(B.btl(s)) bits.append(True if simplify(hd).as_long() == 1 else False) if sz > 0: bits.extend([0] * sz) t = ErlangTerm() t.type = ErlangTerm.BITSTRING t.bits.extend(bits) return t
def mk_fun_entry(args, value): """ Parameters args : list of ErlangTerm value : ErlangTerm """ e = ErlangTerm.FunEntry() e.arguments.extend(args) e.value.CopyFrom(value) return e
def toFloat(self, term): s = simplify(term) t = ErlangTerm() t.type = ErlangTerm.FLOAT t.value = str(float(s.numerator_as_long()) / float(s.denominator_as_long())) return t
def toInt(self, term): t = ErlangTerm() t.type = ErlangTerm.INTEGER t.value = str(simplify(term).as_long()) return t
def toSymbolic(self, s): t = ErlangTerm() t.type = ErlangTerm.SYMBOLIC_VARIABLE t.value = s return t
def mk_any(): t = ErlangTerm() t.type = ErlangTerm.ANY return t