Exemple #1
0
 def _uncall(self):
     from typhon.objects.makers import theMakeBytes
     from typhon.objects.collections.lists import wrapList
     from typhon.objects.collections.maps import EMPTY_MAP
     ints = [IntObject(ord(c)) for c in self._bs]
     return [theMakeBytes, StrObject(u"fromInts"),
             wrapList([wrapList(ints)]), EMPTY_MAP]
Exemple #2
0
 def _uncall(self):
     from typhon.objects.collections.lists import wrapList
     from typhon.objects.collections.maps import EMPTY_MAP
     # [1,2,3].asSet().diverge() -> [[[1,2,3], "asSet"], "diverge"]
     rv = wrapList(self.objectSet.keys())
     return [wrapList([rv, StrObject(u"asSet"), wrapList([]), EMPTY_MAP]),
             StrObject(u"diverge"), wrapList([]), EMPTY_MAP]
Exemple #3
0
 def _uncall(self):
     from typhon.objects.collections.lists import wrapList
     from typhon.scopes.safe import theMakeMap
     pairs = wrapList([wrapList([k, v])
                       for k, v in self.objectMap.items()])
     rv = wrapList([pairs])
     return [theMakeMap, StrObject(u"fromPairs"), rv, EMPTY_MAP]
Exemple #4
0
 def uncall(self):
     return wrapList([
         self._target,
         StrObject(self._verb),
         wrapList(self._args),
         wrapList(self._namedArgs)
     ])
Exemple #5
0
 def _uncall(self):
     from typhon.objects.collections.maps import EMPTY_MAP
     from typhon.scopes.safe import theSlotBinder
     return [wrapList([theSlotBinder, StrObject(u"run"),
                      wrapList([self.guard])]),
             StrObject(u"run"),
             wrapList([self.slot, NullObject]),
             EMPTY_MAP]
Exemple #6
0
 def uncall(self):
     return wrapList([
         StrObject(self._d if self._d else u""),
         StrObject(self._verb),
         wrapList(self._ps),
         wrapList(self._namedParams),
         self._g if self._g is not None else NullObject, self._b
     ])
Exemple #7
0
 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)
Exemple #8
0
def unsealException(specimen, ej):
    """
    Unseal a specimen.
    """

    if isinstance(specimen, SealedException):
        trail = wrapList([StrObject(s) for s in specimen.trail])
        return wrapList([specimen.value, trail])
    throwStr(ej, u"Cannot unseal non-thrown object")
Exemple #9
0
 def _uncall(self):
     from typhon.objects.makers import theMakeBytes
     from typhon.objects.collections.lists import wrapList
     from typhon.objects.collections.maps import EMPTY_MAP
     ints = [IntObject(ord(c)) for c in self._bs]
     return [
         theMakeBytes,
         StrObject(u"fromInts"),
         wrapList([wrapList(ints)]), EMPTY_MAP
     ]
Exemple #10
0
def unsealException(specimen, ej):
    """
    Unseal a specimen.
    """

    if isinstance(specimen, SealedException):
        ue = specimen.ue
        trail = wrapList([StrObject(s) for s in ue.formatTrail()])
        return wrapList([ue.getPayload(), trail])
    throwStr(ej, u"Cannot unseal non-thrown object")
Exemple #11
0
 def _uncall(self):
     from typhon.objects.collections.lists import wrapList
     from typhon.objects.collections.maps import EMPTY_MAP
     # [1,2,3].asSet().diverge() -> [[[1,2,3], "asSet"], "diverge"]
     rv = wrapList(self.objectSet.keys())
     return [
         wrapList([rv, StrObject(u"asSet"),
                   wrapList([]), EMPTY_MAP]),
         StrObject(u"diverge"),
         wrapList([]), EMPTY_MAP
     ]
Exemple #12
0
def bench(obj, name):
    name = unwrapStr(name).encode("utf-8")

    if not benchmarkSettings.enabled:
        debug_print("Not running benchmark", name,
                    "since benchmarking is disabled")
        return wrapList([IntObject(0), DoubleObject(0.0)])

    debug_print("Benchmarking", name)

    # Step 1: Calibrate timing loop.
    debug_print("Calibrating timing loop...")
    # Unroll do-while iteration.
    loops = 1
    debug_print("Trying 1 loop...")
    taken = time.time()
    obj.call(u"run", [])
    taken = time.time() - taken
    while taken < 1.0 and loops < 100000000:
        debug_print("Took", taken, "seconds to run", loops, "loops")
        loops *= 10
        debug_print("Trying", loops, "loops...")
        acc = 0
        taken = time.time()
        while acc < loops:
            acc += 1
            obj.call(u"run", [])
        taken = time.time() - taken
    debug_print("Okay! Will take", loops, "loops at", taken, "seconds")

    # Step 2: Take trials.
    debug_print("Taking trials...")
    trialCount = 3 - 1
    # Unroll first iteration to get maximum.
    acc = 0
    taken = time.time()
    while acc < loops:
        acc += 1
        obj.call(u"run", [])
    taken = time.time() - taken
    result = taken
    while trialCount:
        trialCount -= 1
        acc = 0
        taken = time.time()
        while acc < loops:
            acc += 1
            obj.call(u"run", [])
        taken = time.time() - taken
        if taken < result:
            result = taken

    # All done!
    return wrapList([IntObject(loops), DoubleObject(taken)])
Exemple #13
0
 def _uncall(self):
     from typhon.objects.collections.maps import EMPTY_MAP
     from typhon.scopes.safe import theSlotBinder
     return [
         wrapList(
             [theSlotBinder,
              StrObject(u"run"),
              wrapList([self.guard])]),
         StrObject(u"run"),
         wrapList([self.slot, NullObject]), EMPTY_MAP
     ]
Exemple #14
0
 def _uncall(self):
     from typhon.objects.collections.lists import wrapList
     return [
         ConstMap(self.objectMap.copy()),
         StrObject(u"diverge"),
         wrapList([]), EMPTY_MAP
     ]
Exemple #15
0
 def _uncall(self):
     span = wrapList([NullObject])
     return [
         self.nodeMaker,
         StrObject(u"run"),
         self.uncall().call(u"add", [span]), EMPTY_MAP
     ]
Exemple #16
0
 def _uncall(self):
     from typhon.objects.collections.lists import wrapList
     args = wrapList([] if (self._kg is None and self._vg is None) else [
         self._kg, self._vg
     ])
     return [ConstMap(self.objectMap.copy()), StrObject(u"diverge"), args,
             EMPTY_MAP]
Exemple #17
0
 def _uncall(self):
     from typhon.scopes.safe import theFinalSlotMaker
     from typhon.objects.collections.maps import EMPTY_MAP
     return [
         theFinalSlotMaker,
         StrObject(u"run"),
         wrapList([self._obj, self._guard, NullObject]), EMPTY_MAP
     ]
Exemple #18
0
 def sendAll(self, atom, args, namedArgs):
     if self.checkSlot():
         ref = self.resolutionBox.get()
         return send(ref, atom, args, namedArgs)
     else:
         return send(self.handler, HANDLESEND_3, [StrObject(atom.verb),
                                                  wrapList(args),
                                                  namedArgs], EMPTY_MAP)
Exemple #19
0
    def runMatchers(self, atom, args, namedArgs):
        message = wrapList([StrObject(atom.verb), wrapList(args),
                            namedArgs])
        for matcher in self.getMatchers():
            with Ejector() as ej:
                try:
                    return self.runMatcher(matcher, message, ej)
                except Ejecting as e:
                    if e.ejector is ej:
                        # Looks like unification failed. On to the next
                        # matcher!
                        continue
                    else:
                        # It's not ours, cap'n.
                        raise

        raise Refused(self, atom, args)
Exemple #20
0
 def sendAll(self, atom, args, namedArgs):
     if self.checkSlot():
         ref = self.resolutionBox.get()
         return send(ref, atom, args, namedArgs)
     else:
         return send(self.handler, HANDLESEND_3, [StrObject(atom.verb),
                                                  wrapList(args),
                                                  namedArgs], EMPTY_MAP)
Exemple #21
0
 def _uncall(self):
     from typhon.objects.collections.lists import wrapList
     from typhon.objects.collections.maps import EMPTY_MAP
     return [
         makeSourceSpan, StrObject(u"run"),
         wrapList([wrapBool(self._isOneToOne), IntObject(self.startLine),
                    IntObject(self.startCol), IntObject(self.endLine),
                    IntObject(self.endCol)]), EMPTY_MAP]
Exemple #22
0
def gaiCB(gai, status, ai):
    status = intmask(status)
    vat, resolver = ruv.unstashGAI(gai)
    with scopedVat(vat):
        assert isinstance(resolver, LocalResolver), "implementation error"
        if status < 0:
            msg = ruv.formatError(status).decode("utf-8")
            resolver.smash(StrObject(u"libuv error: %s" % msg))
        else:
            gaiList = walkAI(ai)
            resolver.resolve(wrapList(gaiList[:]))
    ruv.freeAddrInfo(ai)
    ruv.free(gai)
Exemple #23
0
 def _uncall(self):
     from typhon.objects.collections.lists import wrapList
     from typhon.objects.collections.maps import EMPTY_MAP
     return [
         makeSourceSpan,
         StrObject(u"run"),
         wrapList([
             wrapBool(self._isOneToOne),
             IntObject(self.startLine),
             IntObject(self.startCol),
             IntObject(self.endLine),
             IntObject(self.endCol)
         ]), EMPTY_MAP
     ]
Exemple #24
0
def getAddrInfo(node, service):
    node = unwrapBytes(node)
    service = unwrapBytes(service)
    vat = currentVat.get()
    p, r = makePromise()
    emptyAI = nullptr(ruv.s.addrinfo)
    with io:
        ai = emptyAI
        try:
            ai = ruv.magic_getAddrInfo(vat, node, service)
        except object as err:
            smash(r, StrObject(u"libuv error: %s" % err))
        else:
            resolve(r, wrapList(walkAI(ai)[:]))
    return p
Exemple #25
0
    def connect(self):
        vat = currentVat.get()
        stream = ruv.alloc_tcp(vat.uv_loop)

        fount, fountResolver = makePromise()
        drain, drainResolver = makePromise()

        # Ugh, the hax.
        resolvers = wrapList([fountResolver, drainResolver])
        ruv.stashStream(ruv.rffi.cast(ruv.stream_tp, stream),
                        (vat, resolvers))

        # Make the actual connection.
        ruv.tcpConnect(stream, self.host, self.port, connectCB)

        # Return the promises.
        return [fount, drain]
Exemple #26
0
    def connectStream(self):
        vat = currentVat.get()
        stream = ruv.alloc_tcp(vat.uv_loop)

        source, sourceResolver = makePromise()
        sink, sinkResolver = makePromise()

        # Ugh, the hax.
        resolvers = wrapList([sourceResolver, sinkResolver])
        ruv.stashStream(ruv.rffi.cast(ruv.stream_tp, stream),
                        (vat, resolvers))

        # Make the actual connection.
        ruv.tcpConnect(stream, self.host, self.port, connectStreamCB)

        # Return the promises.
        return [source, sink]
Exemple #27
0
    def connectStream(self):
        """
        Connect this endpoint, returning a `[source, sink]` pair.of vows.
        """

        vat = currentVat.get()
        stream = ruv.alloc_tcp(vat.uv_loop)

        source, sourceResolver = makePromise()
        sink, sinkResolver = makePromise()

        # Ugh, the hax.
        resolvers = wrapList([sourceResolver, sinkResolver])
        ruv.stashStream(ruv.rffi.cast(ruv.stream_tp, stream),
                        (vat, resolvers))
        vat.enqueueEvent(ConnectStreamIOEvent(
            vat, stream, self.host, self.port, self.inet_type))
        # Return the promises.
        return [source, sink]
Exemple #28
0
    def connectStream(self):
        """
        Connect this endpoint, returning a `[source, sink]` pair.of vows.
        """

        vat = currentVat.get()
        stream = ruv.alloc_tcp(vat.uv_loop)

        source, sourceResolver = makePromise()
        sink, sinkResolver = makePromise()

        # Ugh, the hax.
        resolvers = wrapList([sourceResolver, sinkResolver])
        ruv.stashStream(ruv.rffi.cast(ruv.stream_tp, stream), (vat, resolvers))

        # Make the actual connection.
        if self.inet_type == 4:
            ruv.tcp4Connect(stream, self.host, self.port, connectStreamCB)
        elif self.inet_type == 6:
            ruv.tcp6Connect(stream, self.host, self.port, connectStreamCB)

        # Return the promises.
        return [source, sink]
Exemple #29
0
 def _uncall(self):
     return SealedPortrayal(wrapList([
         makeSealedException, StrObject(u"run"),
         wrapList([self.ue.getPayload()]), EMPTY_MAP]))
Exemple #30
0
 def uncall(self):
     return wrapList(
         [StrObject(self._d if self._d else u""), StrObject(self._verb),
          wrapList(self._ps), wrapList(self._namedParams), self._g,
          self._b])
Exemple #31
0
 def uncall(self):
     return wrapList([self._pattern, self._block])
Exemple #32
0
 def uncall(self):
     return wrapList([self._inner])
Exemple #33
0
 def uncall(self):
     return wrapList(
         [self._pattern, self._node,
          self._catchPattern if self._catchPattern is not None else NullObject,
          self._catchNode if self._catchNode is not None else NullObject])
Exemple #34
0
 def uncall(self):
     return wrapList([self._target, StrObject(self._verb),
                       wrapList(self._args),
                       wrapList(self._namedArgs)])
Exemple #35
0
 def uncall(self):
     return wrapList([Noun(self.name)])
Exemple #36
0
 def testHashInequalItems(self):
     a = wrapList([IntObject(42), CharObject(u'é')])
     b = wrapList([IntObject(42), CharObject(u'e')])
     self.assertNotEqual(a.samenessHash(), b.samenessHash())
Exemple #37
0
 def testSlice(self):
     l = wrapList(map(CharObject, "abcdefg"))
     result = l.call(u"slice", [IntObject(3), IntObject(6)])
     chars = [char._c for char in unwrapList(result)]
     self.assertEqual(chars, list("def"))
Exemple #38
0
 def testUnwrapListPromise(self):
     with scopedVat(testingVat()):
         p = makeNear(wrapList([]))
         self.assertEqual(unwrapList(p), [])
Exemple #39
0
 def testJoin(self):
     s = StrObject(u"|")
     result = s.call(
         u"join",
         [wrapList([StrObject(u"5"), StrObject(u"42")])])
     self.assertEqual(result._s, u"5|42")
Exemple #40
0
 def uncall(self):
     return wrapList([self._inner])
Exemple #41
0
 def uncall(self):
     return wrapList([self._test, self._then, self._otherwise])
Exemple #42
0
 def uncall(self):
     return wrapList([])
Exemple #43
0
 def uncall(self):
     return wrapList([Noun(self.target), self.rvalue])
Exemple #44
0
 def _uncall(self):
     from typhon.objects.collections.lists import wrapList
     from typhon.scopes.safe import theMakeMap
     pairs = wrapList([wrapList([k, v]) for k, v in self.objectMap.items()])
     rv = wrapList([pairs])
     return [theMakeMap, StrObject(u"fromPairs"), rv, EMPTY_MAP]
Exemple #45
0
 def uncall(self):
     return wrapList([self.key, self.value])
Exemple #46
0
 def uncall(self):
     return wrapList([self._block, self._atLast])
Exemple #47
0
 def uncall(self):
     return wrapList([self._p,
                       self._e if self._e is not None else NullObject,
                       self._v])
Exemple #48
0
 def testCmpShortRight(self):
     a = wrapList([IntObject(2), IntObject(4)])
     b = wrapList([IntObject(2)])
     result = a.call(u"op__cmp", [b])
     self.assertEqual(result.getInt(), 1)
Exemple #49
0
 def uncall(self):
     return wrapList([self._block, self._atLast])
Exemple #50
0
 def testHashEqual(self):
     a = wrapList([IntObject(42), CharObject(u'é')])
     b = wrapList([IntObject(42), CharObject(u'é')])
     self.assertEqual(a.samenessHash(), b.samenessHash())
Exemple #51
0
 def uncall(self):
     return wrapList([self._test, self._then, self._otherwise])
Exemple #52
0
 def testGetNegative(self):
     l = wrapList([])
     self.assertRaises(UserException, l.call, u"get", [IntObject(-1)])
Exemple #53
0
 def uncall(self):
     return wrapList([])
Exemple #54
0
 def uncall(self):
     return wrapList(
         [self._p, self._e if self._e is not None else NullObject, self._v])
Exemple #55
0
 def uncall(self):
     return wrapList([StrObject(self.name)])
Exemple #56
0
 def uncall(self):
     return wrapList([CharObject(self._c)])
Exemple #57
0
 def uncall(self):
     return wrapList([
         self._pattern, self._node, self._catchPattern
         if self._catchPattern is not None else NullObject,
         self._catchNode if self._catchNode is not None else NullObject
     ])
Exemple #58
0
 def uncall(self):
     return wrapList([self._pattern, self._block])