# Copyright 2007 Kevin Reid, under the terms of the MIT X license # found at http://www.opensource.org/licenses/mit-license.html ................ ? pragma.syntax("0.9") > pragma.enable("accumulator") ? def makeVine := ; null ? def makeHub := ; null ? def makeFlexMap := ; null ? def traceMessages := ; null In this file, we test that two linked CapTPConnections communicate successfully. ? def makeCapTPConnection := # value: ? var i := 10000000 > /** Deterministic source of pseudo-SwissNumbers so that our tracing output is deterministic. */ > def pseudoEntropy { > to nextSwiss() { return (i += 1) } > } > def pseudoWhenGarbage(_, _) {} > null This is a mechanism for tracing communication between the CapTPConnections. > def traceReceiver(label, ref) { > return traceMessages(fn t { stdout.print(label, " <- "); stdout.println(t) }, ref) > } > null ? def hub { > to isOurProxy(specimen) { > return false # XXX adequate? > } > } > null Now we can make the SwissTables and connections. ? def swissTableL := (pseudoEntropy, makeFlexMap, makeFlexMap); null ? def swissTableR := (pseudoEntropy, makeFlexMap, makeFlexMap); null ? def [[receiverL, outL, _], [receiverR, outR, _]] := > [makeCapTPConnection(traceReceiver("Right", receiverR), > swissTableL, > def locatorUnumL {}, > pseudoWhenGarbage, > hub, "L", [], "R"), > makeCapTPConnection(traceReceiver("Left", receiverL), > swissTableR, > def locatorUnumR {}, > pseudoWhenGarbage, > hub, "R", [], "L")] # value: [[, , ], [, , ]] --- Simple message with side effects and return value. ? def leftObj { > to ping() { println("pinged"); return "pong" } > to delayUC(x) { return fn { x.toUpperCase() } } > } # value: ? def swissL :int := swissTableL.getNewSwiss(leftObj); null ? swissTableL.lookupSwiss(swissL) == leftObj # value: true ? interp.waitAtTop(def leftViaRight := outR.nonceLocator() <- lookupSwiss(swissL, null)) # stdout: Left <- Deliver(-1, NewFarDesc(1, 1033912670282953026478972818820010722176128073325), 0, "lookupSwiss", [10000001, null]) # Left <- DeliverOnly(-1, "__whenMoreResolved", [NewFarDesc(2, 47255196895205160731987244561159478631887357377)]) # Right <- DeliverOnly(1, "run", [NewFarDesc(1, 382064925828890872342377433413917253333972024416)]) # Right <- DeliverOnly(2, "run", [ImportDesc(1)]) # ? leftViaRight # value: ? interp.waitAtTop(def r := leftViaRight <- ping()) # stdout: Left <- Deliver(-2, NewFarDesc(3, 412897248500657771667886264468852369692723684603), 1, "ping", []) # pinged # Left <- DeliverOnly(-2, "__whenMoreResolved", [NewFarDesc(4, 82190111274176756684133692948252028599388244870)]) # Right <- DeliverOnly(3, "run", ["pong"]) # Right <- DeliverOnly(4, "run", ["pong"]) # ? r # value: "pong" --- Pipelined sends. ? interp.waitAtTop(def r := leftViaRight <- delayUC(leftViaRight <- ping()) <- run()) # stdout: Left <- Deliver(-3, NewFarDesc(5, 682009956380579499771617381148460370106090083063), 1, "ping", []) # Left <- Deliver(-4, NewFarDesc(6, 1194597571256310373217679255844280815354866957945), 1, "delayUC", [IncomingDesc(-3)]) # pinged # Left <- Deliver(-5, NewFarDesc(7, 730711925653291799414144031897225860482398091347), -4, "run", []) # Left <- DeliverOnly(-5, "__whenMoreResolved", [NewFarDesc(8, 676259857959289598128720760374698425339633638932)]) # Right <- DeliverOnly(5, "run", ["pong"]) # Right <- DeliverOnly(6, "run", [NewFarDesc(2, 1201612705638176454711919383590853899224201778053)]) # Right <- DeliverOnly(7, "run", ["PONG"]) # Right <- DeliverOnly(8, "run", ["PONG"]) # ? r # value: "PONG"