コード例 #1
0
ファイル: test_equality.py プロジェクト: markrwilliams/typhon
 def testListEqualityRecursion(self):
     # Yes, this is very hacky.
     first = ConstList([IntObject(42)])
     first.strategy.append(first, [first])
     second = ConstList([IntObject(42)])
     second.strategy.append(second, [second])
     self.assertEqual(optSame(first, second), EQUAL)
コード例 #2
0
ファイル: proxy.py プロジェクト: monte-language/typhon
 def eq(self, other):
     if not isinstance(other, Proxy):
         return False
     if self.checkSlot() or other.checkSlot():
         raise userError(u"equals comparison of resolved proxy is"
                         u" impossible")
     return optSame(self.handler, other.handler) is EQUAL
コード例 #3
0
ファイル: test_equality.py プロジェクト: markrwilliams/typhon
 def testRefEqualitySettled(self):
     with scopedVat(testingVat()):
         first, r = makePromise()
         r.resolve(IntObject(42))
         second, r = makePromise()
         r.resolve(IntObject(42))
         self.assertEqual(optSame(first, second), EQUAL)
コード例 #4
0
ファイル: test_equality.py プロジェクト: dckc/typhon
 def testRefEqualitySettled(self):
     with scopedVat(testingVat()):
         first, r = makePromise()
         r.resolve(IntObject(42))
         second, r = makePromise()
         r.resolve(IntObject(42))
         self.assertEqual(optSame(first, second), EQUAL)
コード例 #5
0
ファイル: proxy.py プロジェクト: markrwilliams/typhon
 def eq(self, other):
     if not isinstance(other, Proxy):
         return False
     if self.checkSlot() or other.checkSlot():
         raise userError(u"equals comparison of resolved proxy is"
                         u" impossible")
     return optSame(self.handler, other.handler) is EQUAL
コード例 #6
0
ファイル: test_equality.py プロジェクト: dckc/typhon
 def testListEqualityRecursion(self):
     first = wrapList([IntObject(42), NullObject])
     # Hax.
     first.objs.append(first)
     second = wrapList([IntObject(42), NullObject])
     # Hax.
     second.objs.append(second)
     self.assertEqual(optSame(first, second), EQUAL)
コード例 #7
0
ファイル: lists.py プロジェクト: markrwilliams/typhon
 def startOf(self, needleList, start=0):
     # This is quadratic. It could be better.
     from typhon.objects.equality import EQUAL, optSame
     for index in range(start, self.strategy.size(self)):
         for needleIndex, needle in enumerate(needleList):
             offset = index + needleIndex
             if optSame(self.strategy.fetch(self, offset), needle) is not EQUAL:
                 break
             return index
     return -1
コード例 #8
0
ファイル: guards.py プロジェクト: markrwilliams/typhon
    def recv(self, atom, args):
        from typhon.nodes import Noun, Method, Obj
        from typhon.objects.equality import optSame, EQUAL
        from typhon.objects.user import Audition

        if atom is _UNCALL_0:
            from typhon.objects.collections.maps import EMPTY_MAP

            return ConstList([subrangeGuardMaker, StrObject(u"get"), ConstList([self.superGuard]), EMPTY_MAP])

        if atom is AUDIT_1:
            audition = args[0]
            if not isinstance(audition, Audition):
                raise userError(u"not invoked with an Audition")
            ast = audition.ast
            if not isinstance(ast, Obj):
                raise userError(u"audition not created with an object expr")
            methods = ast._script._methods
            for m in methods:
                if isinstance(m, Method) and m._verb == u"coerce":
                    mguard = m._g
                    if isinstance(mguard, Noun):
                        rGSG = audition.getGuard(mguard.name)
                        if isinstance(rGSG, FinalSlotGuard):
                            rGSG0 = rGSG.valueGuard
                            if isinstance(rGSG0, SameGuard):
                                resultGuard = rGSG0.value

                                if optSame(resultGuard, self.superGuard) is EQUAL or (
                                    SUPERSETOF_1 in self.superGuard.respondingAtoms()
                                    and self.superGuard.call(u"supersetOf", [resultGuard]) is wrapBool(True)
                                ):
                                    return wrapBool(True)
                                raise userError(
                                    u"%s does not have a result guard implying "
                                    u"%s, but %s" % (audition.fqn, self.superGuard.toQuote(), resultGuard.toQuote())
                                )
                            raise userError(
                                u"%s does not have a determinable "
                                u"result guard, but <& %s> :%s" % (audition.fqn, mguard.name, rGSG.toQuote())
                            )
                    break
            return self
        if atom is PASSES_1:
            return wrapBool(args[0].auditedBy(self))
        if atom is COERCE_2:
            specimen, ej = args[0], args[1]
            if specimen.auditedBy(self):
                return specimen
            c = specimen.call(u"_conformTo", [self])
            if c.auditedBy(self):
                return c
            throw(ej, StrObject(u"%s does not conform to %s" % (specimen.toQuote(), self.toQuote())))

        raise Refused(self, atom, args)
コード例 #9
0
ファイル: lists.py プロジェクト: markrwilliams/typhon
 def startOf(self, needleList, start=0):
     # This is quadratic. It could be better.
     from typhon.objects.equality import EQUAL, optSame
     for index in range(start, self.strategy.size(self)):
         for needleIndex, needle in enumerate(needleList):
             offset = index + needleIndex
             if optSame(self.strategy.fetch(self, offset),
                        needle) is not EQUAL:
                 break
             return index
     return -1
コード例 #10
0
ファイル: lists.py プロジェクト: dckc/typhon
 def _startOf(self, needleCL, start):
     if start < 0:
         raise userError(u"startOf/2: Negative start %d not permitted" %
                 start)
     # This is quadratic. It could be better.
     from typhon.objects.equality import EQUAL, optSame
     for index in range(start, len(self.objs)):
         for needleIndex, needle in enumerate(needleCL):
             offset = index + needleIndex
             if optSame(self.objs[offset], needle) is not EQUAL:
                 break
             return index
     return -1
コード例 #11
0
ファイル: lists.py プロジェクト: zarutian/typhon
 def _startOf(self, needleCL, start):
     if start < 0:
         raise userError(u"startOf/2: Negative start %d not permitted" %
                         start)
     # This is quadratic. It could be better.
     from typhon.objects.equality import EQUAL, optSame
     for index in range(start, len(self.objs)):
         for needleIndex, needle in enumerate(needleCL):
             offset = index + needleIndex
             if optSame(self.objs[offset], needle) is not EQUAL:
                 break
             return index
     return -1
コード例 #12
0
ファイル: guards.py プロジェクト: markrwilliams/typhon
    def recv(self, atom, args):
        if atom is _UNCALL_0:
            from typhon.objects.collections.maps import EMPTY_MAP

            return ConstList([sameGuardMaker, StrObject(u"get"), ConstList([self.value]), EMPTY_MAP])
        if atom is COERCE_2:
            from typhon.objects.equality import optSame, EQUAL

            specimen, ej = args[0], args[1]
            if optSame(specimen, self.value) is EQUAL:
                return specimen
            ej.call(u"run", [ConstList([specimen, StrObject(u"is not"), self.value])])
        if atom is GETVALUE_0:
            return self.value
        raise Refused(self, atom, args)
コード例 #13
0
ファイル: guards.py プロジェクト: washort/typhon
 def recv(self, atom, args):
     if atom is _UNCALL_0:
         from typhon.objects.collections.maps import EMPTY_MAP
         return ConstList([
             sameGuardMaker,
             StrObject(u"get"),
             ConstList([self.value]), EMPTY_MAP
         ])
     if atom is COERCE_2:
         from typhon.objects.equality import optSame, EQUAL
         specimen, ej = args[0], args[1]
         if optSame(specimen, self.value) is EQUAL:
             return specimen
         ej.call(u"run",
                 [ConstList([specimen,
                             StrObject(u"is not"), self.value])])
     if atom is GETVALUE_0:
         return self.value
     raise Refused(self, atom, args)
コード例 #14
0
ファイル: root.py プロジェクト: washort/typhon
    def auditedBy(self, prospect):
        """
        Whether a prospective stamp has been left on this object.
        """

        # The number of different objects that will pass through here is
        # surprisingly low; consider how Python would look if metaclasses were
        # promoted.
        prospect = promote(prospect)

        from typhon.objects.equality import optSame, EQUAL

        # Already audited with an identical stamp?
        for stamp in self.auditorStamps():
            if optSame(prospect, stamp) is EQUAL:
                return True

        # Sorry, but nope.
        return False
コード例 #15
0
ファイル: root.py プロジェクト: washort/typhon
    def auditedBy(self, prospect):
        """
        Whether a prospective stamp has been left on this object.
        """

        # The number of different objects that will pass through here is
        # surprisingly low; consider how Python would look if metaclasses were
        # promoted.
        prospect = promote(prospect)

        from typhon.objects.equality import optSame, EQUAL

        # Already audited with an identical stamp?
        for stamp in self.auditorStamps():
            if optSame(prospect, stamp) is EQUAL:
                return True

        # Sorry, but nope.
        return False
コード例 #16
0
    def audit(self, audition):
        from typhon.nodes import Noun, Method, Obj
        from typhon.objects.equality import optSame, EQUAL
        from typhon.objects.user import Audition
        if not isinstance(audition, Audition):
            raise userError(u"not invoked with an Audition")
        ast = audition.ast
        if not isinstance(ast, Obj):
            raise userError(u"audition not created with an object expr")
        methods = ast._script._methods
        for m in methods:
            if isinstance(m, Method) and m._verb == u"coerce":
                mguard = m._g
                if isinstance(mguard, Noun):
                    rGSG = audition.getGuard(mguard.name)
                    if isinstance(rGSG, FinalSlotGuard):
                        rGSG0 = rGSG.valueGuard
                        if isinstance(rGSG0, SameGuard):
                            resultGuard = rGSG0.value

                            if (optSame(resultGuard, self.superGuard)
                                is EQUAL or
                                (self.superGuard.call(u"supersetOf",
                                    [resultGuard])
                                 is wrapBool(True))):
                                return True
                            raise userError(
                                u"%s does not have a result guard implying "
                                u"%s, but %s" % (audition.fqn,
                                                 self.superGuard.toQuote(),
                                                 resultGuard.toQuote()))
                        raise userError(u"%s does not have a determinable "
                                        u"result guard, but <& %s> :%s" % (
                                            audition.fqn, mguard.name,
                                            rGSG.toQuote()))
                break
        return False
コード例 #17
0
ファイル: test_equality.py プロジェクト: markrwilliams/typhon
 def testNaNFail(self):
     # Found by accident.
     first = DoubleObject(float("nan"))
     second = IntObject(42)
     self.assertEqual(optSame(first, second), INEQUAL)
コード例 #18
0
ファイル: lists.py プロジェクト: dckc/typhon
 def indexOf(self, needle):
     from typhon.objects.equality import EQUAL, optSame
     for index, specimen in enumerate(self.objs):
         if optSame(needle, specimen) is EQUAL:
             return index
     return -1
コード例 #19
0
ファイル: test_equality.py プロジェクト: markrwilliams/typhon
 def testListInequalityLength(self):
     first = ConstList([IntObject(42)])
     second = ConstList([IntObject(42), IntObject(5)])
     self.assertEqual(optSame(first, second), INEQUAL)
コード例 #20
0
ファイル: test_equality.py プロジェクト: dckc/typhon
 def testListEquality(self):
     first = wrapList([IntObject(42)])
     second = wrapList([IntObject(42)])
     self.assertEqual(optSame(first, second), EQUAL)
コード例 #21
0
ファイル: test_equality.py プロジェクト: markrwilliams/typhon
 def testStrInequality(self):
     first = StrObject(u"false")
     second = StrObject(u"true")
     self.assertEqual(optSame(first, second), INEQUAL)
コード例 #22
0
ファイル: test_equality.py プロジェクト: dckc/typhon
 def testDoubleEquality(self):
     first = DoubleObject(4.2)
     second = DoubleObject(4.2)
     self.assertEqual(optSame(first, second), EQUAL)
コード例 #23
0
ファイル: test_equality.py プロジェクト: dckc/typhon
 def testIntEquality(self):
     first = IntObject(42)
     second = IntObject(42)
     self.assertEqual(optSame(first, second), EQUAL)
コード例 #24
0
ファイル: test_equality.py プロジェクト: markrwilliams/typhon
 def testListEquality(self):
     first = ConstList([IntObject(42)])
     second = ConstList([IntObject(42)])
     self.assertEqual(optSame(first, second), EQUAL)
コード例 #25
0
ファイル: lists.py プロジェクト: markrwilliams/typhon
 def contains(self, needle):
     from typhon.objects.equality import EQUAL, optSame
     for specimen in self.strategy.fetch_all(self):
         if optSame(needle, specimen) is EQUAL:
             return True
     return False
コード例 #26
0
ファイル: test_equality.py プロジェクト: markrwilliams/typhon
 def testIntEquality(self):
     first = IntObject(42)
     second = IntObject(42)
     self.assertEqual(optSame(first, second), EQUAL)
コード例 #27
0
ファイル: test_equality.py プロジェクト: markrwilliams/typhon
 def testBigIntAndIntEquality(self):
     first = BigInt(rbigint.fromint(42))
     second = IntObject(42)
     self.assertEqual(optSame(first, second), EQUAL)
コード例 #28
0
ファイル: test_equality.py プロジェクト: markrwilliams/typhon
 def testDoubleEqualityNaN(self):
     first = DoubleObject(float("nan"))
     second = DoubleObject(float("nan"))
     self.assertEqual(optSame(first, second), EQUAL)
コード例 #29
0
ファイル: test_equality.py プロジェクト: markrwilliams/typhon
 def testDoubleEquality(self):
     first = DoubleObject(4.2)
     second = DoubleObject(4.2)
     self.assertEqual(optSame(first, second), EQUAL)
コード例 #30
0
ファイル: test_equality.py プロジェクト: markrwilliams/typhon
 def testCharEquality(self):
     first = CharObject(u'c')
     second = CharObject(u'c')
     self.assertEqual(optSame(first, second), EQUAL)
コード例 #31
0
ファイル: test_equality.py プロジェクト: dckc/typhon
 def testNaNFail(self):
     # Found by accident.
     first = DoubleObject(float("nan"))
     second = IntObject(42)
     self.assertEqual(optSame(first, second), INEQUAL)
コード例 #32
0
ファイル: proxy.py プロジェクト: markrwilliams/typhon
 def eq(self, other):
     if not isinstance(other, FarRef):
         return False
     return (Proxy.eq(self, other) and optSame(
         self.resolutionIdentity, other.resolutionIdentity) is EQUAL)
コード例 #33
0
ファイル: test_equality.py プロジェクト: dckc/typhon
 def testCharEquality(self):
     first = CharObject(u'c')
     second = CharObject(u'c')
     self.assertEqual(optSame(first, second), EQUAL)
コード例 #34
0
ファイル: test_equality.py プロジェクト: markrwilliams/typhon
 def testRefEquality(self):
     with scopedVat(testingVat()):
         first, r = makePromise()
         second, r = makePromise()
         self.assertEqual(optSame(first, second), NOTYET)
コード例 #35
0
ファイル: test_equality.py プロジェクト: dckc/typhon
 def testDoubleEqualityNaN(self):
     first = DoubleObject(float("nan"))
     second = DoubleObject(float("nan"))
     self.assertEqual(optSame(first, second), EQUAL)
コード例 #36
0
ファイル: test_equality.py プロジェクト: markrwilliams/typhon
 def testListInequality(self):
     first = ConstList([IntObject(42)])
     second = ConstList([IntObject(41)])
     self.assertEqual(optSame(first, second), INEQUAL)
コード例 #37
0
ファイル: test_equality.py プロジェクト: dckc/typhon
 def testBigIntAndIntEquality(self):
     first = BigInt(rbigint.fromint(42))
     second = IntObject(42)
     self.assertEqual(optSame(first, second), EQUAL)
コード例 #38
0
ファイル: test_equality.py プロジェクト: dckc/typhon
 def testStrInequality(self):
     first = StrObject(u"false")
     second = StrObject(u"true")
     self.assertEqual(optSame(first, second), INEQUAL)
コード例 #39
0
ファイル: test_equality.py プロジェクト: dckc/typhon
 def testListEqualityRecursionReflexive(self):
     first = wrapList([IntObject(42), NullObject])
     # Hax.
     first.objs.append(first)
     self.assertEqual(optSame(first, first), EQUAL)
コード例 #40
0
ファイル: test_equality.py プロジェクト: dckc/typhon
 def testRefEqualityReflexive(self):
     with scopedVat(testingVat()):
         p, r = makePromise()
         self.assertEqual(optSame(p, p), EQUAL)
コード例 #41
0
ファイル: lists.py プロジェクト: dckc/typhon
 def contains(self, needle):
     from typhon.objects.equality import EQUAL, optSame
     for specimen in self.objs:
         if optSame(needle, specimen) is EQUAL:
             return True
     return False
コード例 #42
0
ファイル: test_equality.py プロジェクト: dckc/typhon
 def testRefEquality(self):
     with scopedVat(testingVat()):
         first, r = makePromise()
         second, r = makePromise()
         self.assertEqual(optSame(first, second), NOTYET)
コード例 #43
0
ファイル: test_equality.py プロジェクト: markrwilliams/typhon
 def testStrEquality(self):
     first = StrObject(u"cs")
     second = StrObject(u"cs")
     self.assertEqual(optSame(first, second), EQUAL)
コード例 #44
0
ファイル: test_equality.py プロジェクト: markrwilliams/typhon
 def testRefEqualityReflexive(self):
     with scopedVat(testingVat()):
         p, r = makePromise()
         self.assertEqual(optSame(p, p), EQUAL)
コード例 #45
0
ファイル: test_equality.py プロジェクト: markrwilliams/typhon
 def testListEqualityRecursionReflexive(self):
     first = ConstList([IntObject(42)])
     first.strategy.append(first, [first])
     self.assertEqual(optSame(first, first), EQUAL)
コード例 #46
0
ファイル: guards.py プロジェクト: washort/typhon
    def recv(self, atom, args):
        from typhon.nodes import Noun, Method, Obj
        from typhon.objects.equality import optSame, EQUAL
        from typhon.objects.user import Audition
        if atom is _UNCALL_0:
            from typhon.objects.collections.maps import EMPTY_MAP
            return ConstList([
                subrangeGuardMaker,
                StrObject(u"get"),
                ConstList([self.superGuard]), EMPTY_MAP
            ])

        if atom is AUDIT_1:
            audition = args[0]
            if not isinstance(audition, Audition):
                raise userError(u"not invoked with an Audition")
            ast = audition.ast
            if not isinstance(ast, Obj):
                raise userError(u"audition not created with an object expr")
            methods = ast._script._methods
            for m in methods:
                if isinstance(m, Method) and m._verb == u"coerce":
                    mguard = m._g
                    if isinstance(mguard, Noun):
                        rGSG = audition.getGuard(mguard.name)
                        if isinstance(rGSG, FinalSlotGuard):
                            rGSG0 = rGSG.valueGuard
                            if isinstance(rGSG0, SameGuard):
                                resultGuard = rGSG0.value

                                if (optSame(resultGuard,
                                            self.superGuard) is EQUAL or
                                    (SUPERSETOF_1
                                     in self.superGuard.respondingAtoms()
                                     and self.superGuard.call(
                                         u"supersetOf",
                                         [resultGuard]) is wrapBool(True))):
                                    return wrapBool(True)
                                raise userError(
                                    u"%s does not have a result guard implying "
                                    u"%s, but %s" %
                                    (audition.fqn, self.superGuard.toQuote(),
                                     resultGuard.toQuote()))
                            raise userError(
                                u"%s does not have a determinable "
                                u"result guard, but <& %s> :%s" %
                                (audition.fqn, mguard.name, rGSG.toQuote()))
                    break
            return self
        if atom is PASSES_1:
            return wrapBool(args[0].auditedBy(self))
        if atom is COERCE_2:
            specimen, ej = args[0], args[1]
            if specimen.auditedBy(self):
                return specimen
            c = specimen.call(u"_conformTo", [self])
            if c.auditedBy(self):
                return c
            throw(
                ej,
                StrObject(u"%s does not conform to %s" %
                          (specimen.toQuote(), self.toQuote())))

        raise Refused(self, atom, args)
コード例 #47
0
ファイル: lists.py プロジェクト: markrwilliams/typhon
 def indexOf(self, needle):
     from typhon.objects.equality import EQUAL, optSame
     for index, specimen in enumerate(self.strategy.fetch_all(self)):
         if optSame(needle, specimen) is EQUAL:
             return index
     return -1
コード例 #48
0
ファイル: proxy.py プロジェクト: monte-language/typhon
 def eq(self, other):
     if not isinstance(other, RemotePromise):
         return False
     return (Proxy.eq(self, other) and
             optSame(self.resolutionBox,
                     other.resolutionBox) is EQUAL)
コード例 #49
0
ファイル: proxy.py プロジェクト: markrwilliams/typhon
 def eq(self, other):
     if not isinstance(other, RemotePromise):
         return False
     return (Proxy.eq(self, other)
             and optSame(self.resolutionBox, other.resolutionBox) is EQUAL)
コード例 #50
0
ファイル: helpers.py プロジェクト: washort/typhon
def keyEq(first, second):
    from typhon.objects.equality import optSame, EQUAL
    first = resolveKey(first)
    second = resolveKey(second)
    return optSame(first, second) is EQUAL
コード例 #51
0
ファイル: proxy.py プロジェクト: monte-language/typhon
 def eq(self, other):
     if not isinstance(other, FarRef):
         return False
     return (Proxy.eq(self, other) and
             optSame(self.resolutionIdentity,
                     other.resolutionIdentity) is EQUAL)
コード例 #52
0
ファイル: test_equality.py プロジェクト: dckc/typhon
 def testListInequalityLength(self):
     first = wrapList([IntObject(42)])
     second = wrapList([IntObject(42), IntObject(5)])
     self.assertEqual(optSame(first, second), INEQUAL)
コード例 #53
0
ファイル: test_equality.py プロジェクト: dckc/typhon
 def testStrEquality(self):
     first = StrObject(u"cs")
     second = StrObject(u"cs")
     self.assertEqual(optSame(first, second), EQUAL)
コード例 #54
0
 def subCoerce(self, specimen):
     from typhon.objects.equality import optSame, EQUAL
     if optSame(specimen, self.value) is EQUAL:
         return specimen