Ejemplo n.º 1
0
def mk_atom(chars):
    """
    Parameters
        chars : list of ints
    """
    t = ErlangTerm()
    t.type = ErlangTerm.ATOM
    t.atom_chars.extend(chars)
    return t
Ejemplo n.º 2
0
def mk_tuple(subterms):
    """
    Parameters
        subterms : list of ErlangTerm
    """
    t = ErlangTerm()
    t.type = ErlangTerm.TUPLE
    t.subterms.extend(subterms)
    return t
Ejemplo n.º 3
0
def mk_list(subterms):
    """
    Parameters
        subterms : list of ErlangTerm
    """
    t = ErlangTerm()
    t.type = ErlangTerm.LIST
    t.subterms.extend(subterms)
    return t
Ejemplo n.º 4
0
def mk_float(f):
    """
    Parameters
        f : float
    """
    t = ErlangTerm()
    t.type = ErlangTerm.FLOAT
    t.value = str(f)
    return t
Ejemplo n.º 5
0
def mk_atom(chars):
    """
    Parameters
        chars : list of ints
    """
    t = ErlangTerm()
    t.type = ErlangTerm.ATOM
    t.atom_chars.extend(chars)
    return t
Ejemplo n.º 6
0
def mk_int(i):
    """
    Parameters
        i : int
    """
    t = ErlangTerm()
    t.type = ErlangTerm.INTEGER
    t.value = str(i)
    return t
Ejemplo n.º 7
0
def mk_int(i):
    """
    Parameters
        i : int
    """
    t = ErlangTerm()
    t.type = ErlangTerm.INTEGER
    t.value = str(i)
    return t
Ejemplo n.º 8
0
def mk_alias(s):
    """
    Parameters
        s : string
    """
    t = ErlangTerm()
    t.type = ErlangTerm.SUBTERM
    t.value = s
    return t
Ejemplo n.º 9
0
def mk_symb(s):
    """
    Parameters
        s : string
    """
    t = ErlangTerm()
    t.type = ErlangTerm.SYMBOLIC_VARIABLE
    t.value = s
    return t
Ejemplo n.º 10
0
def mk_bitstring(bits):
    """
    Parameters
        bits : list of bool
    """
    t = ErlangTerm()
    t.type = ErlangTerm.BITSTRING
    t.bits.extend(bits)
    return t
Ejemplo n.º 11
0
def mk_list(subterms):
    """
    Parameters
        subterms : list of ErlangTerm
    """
    t = ErlangTerm()
    t.type = ErlangTerm.LIST
    t.subterms.extend(subterms)
    return t
Ejemplo n.º 12
0
def mk_tuple(subterms):
    """
    Parameters
        subterms : list of ErlangTerm
    """
    t = ErlangTerm()
    t.type = ErlangTerm.TUPLE
    t.subterms.extend(subterms)
    return t
Ejemplo n.º 13
0
def mk_alias(s):
    """
    Parameters
        s : string
    """
    t = ErlangTerm()
    t.type = ErlangTerm.SUBTERM
    t.value = s
    return t
Ejemplo n.º 14
0
def mk_bitstring(bits):
    """
    Parameters
        bits : list of bool
    """
    t = ErlangTerm()
    t.type = ErlangTerm.BITSTRING
    t.bits.extend(bits)
    return t
Ejemplo n.º 15
0
def mk_float(f):
    """
    Parameters
        f : float
    """
    t = ErlangTerm()
    t.type = ErlangTerm.FLOAT
    t.value = str(f)
    return t
Ejemplo n.º 16
0
def mk_symb(s):
    """
    Parameters
        s : string
    """
    t = ErlangTerm()
    t.type = ErlangTerm.SYMBOLIC_VARIABLE
    t.value = s
    return t
Ejemplo n.º 17
0
 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
Ejemplo n.º 18
0
 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
Ejemplo n.º 19
0
 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
Ejemplo n.º 20
0
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
Ejemplo n.º 21
0
 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
Ejemplo n.º 22
0
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
Ejemplo n.º 23
0
 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
Ejemplo n.º 24
0
 def toInt(self, term):
     t = ErlangTerm()
     t.type = ErlangTerm.INTEGER
     t.value = str(simplify(term).as_long())
     return t
Ejemplo n.º 25
0
 def toSymbolic(self, s):
     t = ErlangTerm()
     t.type = ErlangTerm.SYMBOLIC_VARIABLE
     t.value = s
     return t
Ejemplo n.º 26
0
def mk_any():
    t = ErlangTerm()
    t.type = ErlangTerm.ANY
    return t