Esempio n. 1
0
 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)
Esempio n. 2
0
def connectStreamCB(connect, status):
    status = intmask(status)
    stream = connect.c_handle

    try:
        vat, resolvers = ruv.unstashStream(stream)
        sourceResolver, sinkResolver = unwrapList(resolvers)
        assert isinstance(sourceResolver, LocalResolver)
        assert isinstance(sinkResolver, LocalResolver)

        with scopedVat(vat):
            if status >= 0:
                debug_print("Made connection!")
                wrappedStream = ruv.wrapStream(stream, 2)
                sourceResolver.resolve(StreamSource(wrappedStream, vat))
                sinkResolver.resolve(StreamSink(wrappedStream, vat))
            else:
                error = "Connection failed: " + ruv.formatError(status)
                debug_print(error)
                sourceResolver.smash(StrObject(error.decode("utf-8")))
                sinkResolver.smash(StrObject(error.decode("utf-8")))
                # Done with stream.
                ruv.closeAndFree(stream)
    except:
        if not we_are_translated():
            raise
Esempio n. 3
0
    def testSwitchableBecomesResolved(self):
        with scopedVat(testingVat()):
            p, r = makePromise()
            self.assertFalse(isResolved(p))

            r.resolve(IntObject(42))
            self.assertTrue(isResolved(p))
Esempio n. 4
0
 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)
Esempio n. 5
0
def runUntilDone(vatManager, uv_loop, recorder):
    # This may take a while.
    anyVatHasTurns = vatManager.anyVatHasTurns()
    while anyVatHasTurns or ruv.loopAlive(uv_loop):
        for vat in vatManager.vats:
            if vat.hasTurns():
                with scopedVat(vat) as vat:
                    with recorder.context("Time spent in vats"):
                        vat.takeSomeTurns()

        if ruv.loopAlive(uv_loop):
            with recorder.context("Time spent in I/O"):
                ruv.cleanup()
                try:
                    if anyVatHasTurns:
                        # More work to be done, so don't block.
                        ruv.run(uv_loop, ruv.RUN_NOWAIT)
                    else:
                        # No more work to be done, so blocking is fine.
                        ruv.run(uv_loop, ruv.RUN_ONCE)
                except CompilerFailed as cf:
                    debug_print("Caught fatal exception while reacting:",
                            cf.formatError())
                    raise
                except UserException as ue:
                    debug_print("Caught exception while reacting:",
                            ue.formatError())

        anyVatHasTurns = vatManager.anyVatHasTurns()
Esempio n. 6
0
def runUntilDone(vatManager, uv_loop, recorder):
    # This may take a while.
    anyVatHasTurns = vatManager.anyVatHasTurns()
    while anyVatHasTurns or ruv.loopAlive(uv_loop):
        for vat in vatManager.vats:
            if vat.hasTurns():
                with scopedVat(vat) as vat:
                    with recorder.context("Time spent in vats"):
                        vat.takeSomeTurns()

        if ruv.loopAlive(uv_loop):
            with recorder.context("Time spent in I/O"):
                ruv.cleanup()
                try:
                    if anyVatHasTurns:
                        # More work to be done, so don't block.
                        ruv.run(uv_loop, ruv.RUN_NOWAIT)
                    else:
                        # No more work to be done, so blocking is fine.
                        ruv.run(uv_loop, ruv.RUN_ONCE)
                except CompilerFailed as cf:
                    debug_print("Caught fatal exception while reacting:",
                            cf.formatError())
                    raise
                except UserException as ue:
                    debug_print("Caught exception while reacting:",
                            ue.formatError())

        anyVatHasTurns = vatManager.anyVatHasTurns()
Esempio n. 7
0
    def testSwitchableBecomesResolved(self):
        with scopedVat(testingVat()):
            p, r = makePromise()
            self.assertFalse(isResolved(p))

            r.resolve(IntObject(42))
            self.assertTrue(isResolved(p))
Esempio n. 8
0
def connectCB(connect, status):
    status = intmask(status)
    stream = connect.c_handle

    try:
        vat, resolvers = ruv.unstashStream(stream)
        fountResolver, drainResolver = unwrapList(resolvers)
        assert isinstance(fountResolver, LocalResolver)
        assert isinstance(drainResolver, LocalResolver)

        with scopedVat(vat):
            if status >= 0:
                debug_print("Made connection!")
                fountResolver.resolve(StreamFount(stream, vat))
                drainResolver.resolve(StreamDrain(stream, vat))
            else:
                error = "Connection failed: " + ruv.formatError(status)
                debug_print(error)
                fountResolver.smash(StrObject(error.decode("utf-8")))
                drainResolver.smash(StrObject(error.decode("utf-8")))
                # Done with stream.
                ruv.closeAndFree(stream)
    except:
        if not we_are_translated():
            raise
Esempio n. 9
0
 def run(self, state, k):
     from typhon.objects.collections.maps import EMPTY_MAP
     r, sink = self.target._nextSink()
     with scopedVat(self.target._vat):
         p = self.target._vat.send(sink, self.verb, self.args, EMPTY_MAP)
     r.resolve(p)
     if k:
         k.do(state, Ok(None))
Esempio n. 10
0
 def run(self, state, k):
     from typhon.objects.collections.maps import EMPTY_MAP
     for r, sink in self.target._queue:
         r.resolve(NullObject)
         with scopedVat(self.target._vat):
             self.target._vat.send(sink, self.verb, self.args, EMPTY_MAP)
     if k:
         k.do(state, Ok(None))
Esempio n. 11
0
    def exited(self, exit_status, term_signal):
        if self.pid == self.EMPTY_PID:
            self.retrievePID()
        self.exit_and_signal = (intmask(exit_status), intmask(term_signal))
        toResolve, self.resolvers = self.resolvers, []

        with scopedVat(self.vat):
            for resolver in toResolve:
                self.resolveWaiter(resolver)
Esempio n. 12
0
    def exited(self, exit_status, term_signal):
        if self.pid == self.EMPTY_PID:
            self.retrievePID()
        self.exit_and_signal = (intmask(exit_status), intmask(term_signal))
        toResolve, self.resolvers = self.resolvers, []

        with scopedVat(self.vat):
            for resolver in toResolve:
                self.resolveWaiter(resolver)
Esempio n. 13
0
    def testSwitchableChains(self):
        with scopedVat(testingVat()):
            p, r = makePromise()
            p2, r2 = makePromise()

            r.resolve(p2)
            self.assertFalse(isResolved(p))

            r2.resolve(IntObject(42))
            self.assertTrue(isResolved(p))
Esempio n. 14
0
    def testSwitchableChains(self):
        with scopedVat(testingVat()):
            p, r = makePromise()
            p2, r2 = makePromise()

            r.resolve(p2)
            self.assertFalse(isResolved(p))

            r2.resolve(IntObject(42))
            self.assertTrue(isResolved(p))
Esempio n. 15
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(ConstList(gaiList[:]))
    ruv.freeAddrInfo(ai)
    ruv.free(gai)
Esempio n. 16
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(ConstList(gaiList[:]))
    ruv.freeAddrInfo(ai)
    ruv.free(gai)
Esempio n. 17
0
def readFileCB(fs):
    size = intmask(fs.c_result)
    with ruv.unstashingFS(fs) as (vat, source):
        assert isinstance(source, FileSource)
        with scopedVat(vat):
            if size > 0:
                data = charpsize2str(source._buf.c_base, size)
                source.deliver(data)
            elif size < 0:
                msg = ruv.formatError(size).decode("utf-8")
                source.abort(u"libuv error: %s" % msg)
            else:
                # EOF.
                source.complete()
Esempio n. 18
0
def closeSetContentsCB(fs):
    try:
        vat, sc = ruv.unstashFS(fs)
        # Need to scope vat here.
        with scopedVat(vat):
            assert isinstance(sc, SetContents)
            size = intmask(fs.c_result)
            if size < 0:
                msg = ruv.formatError(size).decode("utf-8")
                sc.fail(u"libuv error: %s" % msg)
            else:
                # Success.
                sc.rename()
    except:
        print "Exception in closeSetContentsCB"
Esempio n. 19
0
File: files.py Progetto: dckc/typhon
def closeSetContentsCB(fs):
    try:
        vat, sc = ruv.unstashFS(fs)
        # Need to scope vat here.
        with scopedVat(vat):
            assert isinstance(sc, SetContents)
            size = intmask(fs.c_result)
            if size < 0:
                msg = ruv.formatError(size).decode("utf-8")
                sc.fail(u"libuv error: %s" % msg)
            else:
                # Success.
                sc.rename()
    except:
        print "Exception in closeSetContentsCB"
Esempio n. 20
0
def readFileCB(fs):
    size = intmask(fs.c_result)
    vat, source = ruv.unstashFS(fs)
    assert isinstance(source, FileSource)
    with scopedVat(vat):
        if size > 0:
            data = charpsize2str(source._buf.c_base, size)
            source.deliver(data)
        elif size < 0:
            msg = ruv.formatError(size).decode("utf-8")
            source.abort(u"libuv error: %s" % msg)
        else:
            # EOF.
            source.complete()
    ruv.fsDiscard(fs)
Esempio n. 21
0
File: files.py Progetto: dckc/typhon
def openDrainCB(fs):
    # As above.
    try:
        fd = intmask(fs.c_result)
        vat, r = ruv.unstashFS(fs)
        assert isinstance(r, LocalResolver)
        with scopedVat(vat):
            if fd < 0:
                msg = ruv.formatError(fd).decode("utf-8")
                r.smash(StrObject(u"Couldn't open file drain: %s" % msg))
                # Done with fs.
                ruv.fsDiscard(fs)
            else:
                r.resolve(FileDrain(fs, fd, vat))
    except:
        print "Exception in openDrainCB"
Esempio n. 22
0
def openDrainCB(fs):
    # As above.
    try:
        fd = intmask(fs.c_result)
        vat, r = ruv.unstashFS(fs)
        assert isinstance(r, LocalResolver)
        with scopedVat(vat):
            if fd < 0:
                msg = ruv.formatError(fd).decode("utf-8")
                r.smash(StrObject(u"Couldn't open file drain: %s" % msg))
                # Done with fs.
                ruv.fsDiscard(fs)
            else:
                r.resolve(FileDrain(fs, fd, vat))
    except:
        print "Exception in openDrainCB"
Esempio n. 23
0
File: files.py Progetto: dckc/typhon
def openFountCB(fs):
    # Does *not* run user-level code. The scoped vat is only for promise
    # resolution.
    try:
        fd = intmask(fs.c_result)
        vat, r = ruv.unstashFS(fs)
        assert isinstance(r, LocalResolver)
        with scopedVat(vat):
            if fd < 0:
                msg = ruv.formatError(fd).decode("utf-8")
                r.smash(StrObject(u"Couldn't open file fount: %s" % msg))
                # Done with fs.
                ruv.fsDiscard(fs)
            else:
                r.resolve(FileFount(fs, fd, vat))
    except:
        print "Exception in openFountCB"
Esempio n. 24
0
def openFountCB(fs):
    # Does *not* run user-level code. The scoped vat is only for promise
    # resolution.
    try:
        fd = intmask(fs.c_result)
        vat, r = ruv.unstashFS(fs)
        assert isinstance(r, LocalResolver)
        with scopedVat(vat):
            if fd < 0:
                msg = ruv.formatError(fd).decode("utf-8")
                r.smash(StrObject(u"Couldn't open file fount: %s" % msg))
                # Done with fs.
                ruv.fsDiscard(fs)
            else:
                r.resolve(FileFount(fs, fd, vat))
    except:
        print "Exception in openFountCB"
Esempio n. 25
0
File: files.py Progetto: dckc/typhon
def openGetContentsCB(fs):
    try:
        fd = intmask(fs.c_result)
        vat, r = ruv.unstashFS(fs)
        assert isinstance(r, LocalResolver)
        with scopedVat(vat):
            if fd < 0:
                msg = ruv.formatError(fd).decode("utf-8")
                r.smash(StrObject(u"Couldn't open file fount: %s" % msg))
                # Done with fs.
                ruv.fsDiscard(fs)
            else:
                # Strategy: Read and use the callback to queue additional reads
                # until done. This call is known to its caller to be expensive, so
                # there's not much point in trying to be clever about things yet.
                gc = GetContents(vat, fs, fd, r)
                gc.queueRead()
    except:
        print "Exception in openGetContentsCB"
Esempio n. 26
0
def openGetContentsCB(fs):
    try:
        fd = intmask(fs.c_result)
        vat, r = ruv.unstashFS(fs)
        assert isinstance(r, LocalResolver)
        with scopedVat(vat):
            if fd < 0:
                msg = ruv.formatError(fd).decode("utf-8")
                r.smash(StrObject(u"Couldn't open file fount: %s" % msg))
                # Done with fs.
                ruv.fsDiscard(fs)
            else:
                # Strategy: Read and use the callback to queue additional reads
                # until done. This call is known to its caller to be expensive, so
                # there's not much point in trying to be clever about things yet.
                gc = GetContents(vat, fs, fd, r)
                gc.queueRead()
    except:
        print "Exception in openGetContentsCB"
Esempio n. 27
0
def readStreamCB(stream, status, buf):
    status = intmask(status)
    # We only restash in the success case, not the error cases.
    vat, source = ruv.unstashStream(stream)
    assert isinstance(source, StreamSource), "Implementation error"
    # Don't read any more. We'll call .readStart() when we're interested in
    # reading again.
    ruv.readStop(stream)
    with scopedVat(vat):
        if status > 0:
            # Restash required.
            ruv.stashStream(stream, (vat, source))
            data = charpsize2str(buf.c_base, status)
            source.deliver(data)
        elif status == -4095:
            # EOF.
            source.complete()
        else:
            msg = ruv.formatError(status).decode("utf-8")
            source.abort(u"libuv error: %s" % msg)
Esempio n. 28
0
def readStreamCB(stream, status, buf):
    status = intmask(status)
    # We only restash in the success case, not the error cases.
    vat, source = ruv.unstashStream(stream)
    assert isinstance(source, StreamSource), "Implementation error"
    # Don't read any more. We'll call .readStart() when we're interested in
    # reading again.
    ruv.readStop(stream)
    with scopedVat(vat):
        if status > 0:
            # Restash required.
            ruv.stashStream(stream, (vat, source))
            data = charpsize2str(buf.c_base, status)
            source.deliver(data)
        elif status == -4095:
            # EOF.
            source.complete()
        else:
            msg = ruv.formatError(status).decode("utf-8")
            source.abort(u"libuv error: %s" % msg)
Esempio n. 29
0
def readCB(stream, status, buf):
    status = intmask(status)
    try:
        # We only restash in the success case, not the error cases.
        vat, fount = ruv.unstashStream(stream)
        assert isinstance(fount, StreamFount), "Implementation error"
        with scopedVat(vat):
            if status > 0:
                # Restash required.
                ruv.stashStream(stream, (vat, fount))
                data = charpsize2str(buf.c_base, status)
                fount.receive(data)
            elif status == 0:
                # EOF.
                fount.stop(u"End of stream")
            else:
                msg = ruv.formatError(status).decode("utf-8")
                fount.abort(u"libuv error: %s" % msg)
    except:
        if not we_are_translated():
            raise
Esempio n. 30
0
 def testUnwrapMapPromise(self):
     with scopedVat(testingVat()):
         p = makeNear(ConstMap({}))
         self.assertEqual(unwrapMap(p).items(), [])
Esempio n. 31
0
 def testUnwrapListPromise(self):
     with scopedVat(testingVat()):
         p = makeNear(ConstList([]))
         self.assertEqual(unwrapList(p), [])
Esempio n. 32
0
 def testPromiseResolved(self):
     with scopedVat(testingVat()):
         p, r = makePromise()
         r.resolve(IntObject(42))
         self.assertTrue(isSettled(p))
Esempio n. 33
0
 def testRefEquality(self):
     with scopedVat(testingVat()):
         first, r = makePromise()
         second, r = makePromise()
         self.assertEqual(optSame(first, second), NOTYET)
Esempio n. 34
0
File: files.py Progetto: dckc/typhon
 def abort(self, reason):
     if self.fount is not None:
         with scopedVat(self.vat):
             from typhon.objects.collections.maps import EMPTY_MAP
             self.vat.sendOnly(self.fount, ABORTFLOW_0, [], EMPTY_MAP)
     self.closing()
Esempio n. 35
0
def runTyphon(argv):
    # Start metrics.
    recorder = globalRecorder()
    recorder.start()

    # Initialize libsodium.
    if rsodium.init() < 0:
        print "Couldn't initialize libsodium!"
        return 1

    config = Configuration(argv)

    if config.verbose:
        enableDebugPrint()

    config.enableLogging()

    if len(config.argv) < 2:
        print "No file provided?"
        return 1

    # Pass user configuration to the JIT.
    set_user_param(None, config.jit)

    # Intialize our loop.
    uv_loop = ruv.alloc_loop()

    # Usurp SIGPIPE, as libuv does not handle it.
    rsignal.pypysig_ignore(rsignal.SIGPIPE)

    # Initialize our first vat. It shall be immortal.
    vatManager = VatManager()
    vat = Vat(vatManager, uv_loop, checkpoints=-1)
    vatManager.vats.append(vat)

    # Update loop timing information. Until the loop really gets going, we
    # have to do this ourselves in order to get the timing correct for early
    # timers.
    ruv.update_time(uv_loop)
    try:
        with scopedVat(vat) as vat:
            prelude = loadPrelude(config, recorder, vat)
    except LoadFailed as lf:
        print lf
        return 1
    except CompilerFailed as cf:
        debug_print("Caught exception while importing prelude:",
                cf.formatError())
        return 1
    except UserException as ue:
        debug_print("Caught exception while importing prelude:",
                ue.formatError())
        return 1

    registerGlobals(prelude)

    scope = safeScope()
    scope.update(prelude)
    ss = scope.copy()
    reflectedSS = monteMap()
    for k, b in ss.iteritems():
        reflectedSS[StrObject(u"&&" + k)] = b
    ss[u"safeScope"] = finalBinding(ConstMap(reflectedSS), deepFrozenGuard)
    reflectedSS[StrObject(u"&&safeScope")] = ss[u"safeScope"]
    scope[u"safeScope"] = ss[u"safeScope"]
    scope.update(unsafeScope(config))
    # The initial vat is included as `currentVat` to the first level of
    # loading and such.
    scope[u"currentVat"] = finalBinding(vat, anyGuard)
    reflectedUnsafeScope = monteMap()
    unsafeScopeDict = {}
    for k, b in scope.iteritems():
        reflectedUnsafeScope[StrObject(u"&&" + k)] = b
        unsafeScopeDict[k] = b
    rus = finalBinding(ConstMap(reflectedUnsafeScope), anyGuard)
    reflectedUnsafeScope[StrObject(u"&&unsafeScope")] = rus
    unsafeScopeDict[u"unsafeScope"] = rus
    try:
        module = obtainModule([""], recorder, config.argv[1])
    except LoadFailed as lf:
        print lf
        return 1

    if config.loadOnly:
        # We are finished.
        return 0

    if not config.benchmark:
        benchmarkSettings.disable()

    with profiling("vmprof.log", config.profile):
        # Update loop timing information.
        ruv.update_time(uv_loop)
        debug_print("Taking initial turn in script...")
        result = NullObject
        try:
            with recorder.context("Time spent in vats"):
                with scopedVat(vat):
                    result = module.eval(unsafeScopeDict)[0]
            if result is None:
                return 1
        except UserException as ue:
            debug_print("Caught exception while taking initial turn:",
                    ue.formatError())
            return 1

        # Exit status code.
        exitStatus = 0
        # Update loop timing information.
        ruv.update_time(uv_loop)
        try:
            runUntilDone(vatManager, uv_loop, recorder)
            rv = resolution(result) if result is not None else NullObject
            if isinstance(rv, IntObject):
                exitStatus = rv.getInt()
        except SystemExit:
            pass
            # Huh, apparently this doesn't work. Wonder why/why not.
            # exitStatus = se.code
        finally:
            recorder.stop()
            recorder.printResults()

    # Clean up and exit.
    cleanUpEverything()
    return exitStatus
Esempio n. 36
0
 def testUnwrapListPromise(self):
     with scopedVat(testingVat()):
         p = makeNear(wrapList([]))
         self.assertEqual(unwrapList(p), [])
Esempio n. 37
0
def runTyphon(argv):
    recorder = Recorder()
    recorder.start()

    # Initialize libsodium.
    if rsodium.init() < 0:
        print "Couldn't initialize libsodium!"
        return 1

    config = Configuration(argv)

    if config.verbose:
        enableDebugPrint()

    config.enableLogging()

    if len(config.argv) < 2:
        print "No file provided?"
        return 1

    # Pass user configuration to the JIT.
    set_user_param(None, config.jit)

    # Intialize our loop.
    uv_loop = ruv.alloc_loop()

    # Usurp SIGPIPE, as libuv does not handle it.
    rsignal.pypysig_ignore(rsignal.SIGPIPE)

    # Initialize our first vat. It shall be immortal.
    vatManager = VatManager()
    vat = Vat(vatManager, uv_loop, checkpoints=-1)
    vatManager.vats.append(vat)

    # Update loop timing information. Until the loop really gets going, we
    # have to do this ourselves in order to get the timing correct for early
    # timers.
    ruv.update_time(uv_loop)
    try:
        with scopedVat(vat) as vat:
            prelude = loadPrelude(config, recorder, vat)
    except LoadFailed as lf:
        print lf
        return 1

    registerGlobals(prelude)

    scope = safeScope()
    scope.update(prelude)
    ss = scope.copy()
    reflectedSS = monteMap()
    for k, b in ss.iteritems():
        reflectedSS[StrObject(u"&&" + k)] = b
    ss[u"safeScope"] = finalBinding(ConstMap(reflectedSS), deepFrozenGuard)
    reflectedSS[StrObject(u"&&safeScope")] = ss[u"safeScope"]
    scope[u"safeScope"] = ss[u"safeScope"]
    scope.update(unsafeScope(config))
    reflectedUnsafeScope = monteMap()
    unsafeScopeDict = {}
    for k, b in scope.iteritems():
        reflectedUnsafeScope[StrObject(u"&&" + k)] = b
        unsafeScopeDict[k] = b
    rus = finalBinding(ConstMap(reflectedUnsafeScope), anyGuard)
    reflectedUnsafeScope[StrObject(u"&&unsafeScope")] = rus
    unsafeScopeDict[u"unsafeScope"] = rus
    try:
        code = obtainModule([""], config.argv[1], recorder)
    except LoadFailed as lf:
        print lf
        return 1

    if config.loadOnly:
        # We are finished.
        return 0

    if not config.benchmark:
        benchmarkSettings.disable()

    with profiling("vmprof.log", config.profile):
        # Update loop timing information.
        ruv.update_time(uv_loop)
        debug_print("Taking initial turn in script...")
        result = NullObject
        with recorder.context("Time spent in vats"):
            with scopedVat(vat):
                result = evaluateTerms([code], unsafeScopeDict)
        if result is None:
            return 1

        # Exit status code.
        exitStatus = 0
        # Update loop timing information.
        ruv.update_time(uv_loop)
        try:
            runUntilDone(vatManager, uv_loop, recorder)
            rv = resolution(result) if result is not None else NullObject
            if isinstance(rv, IntObject):
                exitStatus = rv.getInt()
        except SystemExit:
            pass
            # Huh, apparently this doesn't work. Wonder why/why not.
            # exitStatus = se.code
        finally:
            recorder.stop()
            recorder.printResults()

    # Clean up and exit.
    cleanUpEverything()
    return exitStatus
Esempio n. 38
0
 def testPromise(self):
     with scopedVat(testingVat()):
         p, r = makePromise()
         self.assertFalse(isSettled(p))
Esempio n. 39
0
 def testUnwrapMapPromise(self):
     with scopedVat(testingVat()):
         p = makeNear(ConstMap({}))
         self.assertEqual(unwrapMap(p).items(), [])
Esempio n. 40
0
 def testRefEqualityReflexive(self):
     with scopedVat(testingVat()):
         p, r = makePromise()
         self.assertEqual(optSame(p, p), EQUAL)
Esempio n. 41
0
 def testUnwrapIntPromise(self):
     with scopedVat(testingVat()):
         p = makeNear(IntObject(42))
         self.assertEqual(unwrapInt(p), 42)
Esempio n. 42
0
 def testPromise(self):
     with scopedVat(testingVat()):
         p, r = makePromise()
         self.assertFalse(p.isSettled())
Esempio n. 43
0
 def testResolveNear(self):
     with scopedVat(testingVat()):
         p = makeNear(wrapBool(False))
         self.assertFalse(resolution(p).isTrue())
Esempio n. 44
0
 def testUnwrapBoolPromise(self):
     with scopedVat(testingVat()):
         p = makeNear(wrapBool(False))
         self.assertFalse(unwrapBool(p))
Esempio n. 45
0
 def testPromoteToDoublePromise(self):
     with scopedVat(testingVat()):
         p = makeNear(DoubleObject(4.2))
         self.assertAlmostEqual(promoteToDouble(p), 4.2)
Esempio n. 46
0
 def testPromoteToDoublePromise(self):
     with scopedVat(testingVat()):
         p = makeNear(DoubleObject(4.2))
         self.assertAlmostEqual(promoteToDouble(p), 4.2)
Esempio n. 47
0
 def testUnwrapBoolPromise(self):
     with scopedVat(testingVat()):
         p = makeNear(wrapBool(False))
         self.assertFalse(unwrapBool(p))
Esempio n. 48
0
 def testResolveNear(self):
     with scopedVat(testingVat()):
         p = makeNear(wrapBool(False))
         self.assertFalse(resolution(p).isTrue())
Esempio n. 49
0
 def testUnwrapIntPromise(self):
     with scopedVat(testingVat()):
         p = makeNear(IntObject(42))
         self.assertEqual(unwrapInt(p), 42)
Esempio n. 50
0
 def testRefEquality(self):
     with scopedVat(testingVat()):
         first, r = makePromise()
         second, r = makePromise()
         self.assertEqual(optSame(first, second), NOTYET)
Esempio n. 51
0
 def abort(self, reason):
     if self.fount is not None:
         with scopedVat(self.vat):
             from typhon.objects.collections.maps import EMPTY_MAP
             self.vat.sendOnly(self.fount, ABORTFLOW_0, [], EMPTY_MAP)
     self.closing()
Esempio n. 52
0
 def testRefEqualityReflexive(self):
     with scopedVat(testingVat()):
         p, r = makePromise()
         self.assertEqual(optSame(p, p), EQUAL)
Esempio n. 53
0
 def testPromiseResolved(self):
     with scopedVat(testingVat()):
         p, r = makePromise()
         r.resolve(IntObject(42))
         self.assertTrue(p.isSettled())