# 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 messageDescs := def typeEncodings := [] def [=> OpCode :DeepFrozen] | _ := typeEncodings def argTable2 :DeepFrozen := accum [].asMap() for rec in messageDescs[typeEncodings] { _.with( def [verb, opCode :(OpCode.asType()), encoders :DeepFrozen] := rec verb, def encodeMsg(out, args) implements DeepFrozen { require(args.size() == encoders.size()) OpCode.writingTo(out)(opCode) for i => encoder in encoders { encoder.writingTo(out)(args[i]) } } ) } def makeCapTPSerializer(messageStreams) implements ExitViaHere, DeepFrozen { return def capTPSerializer { match [verb, args] { def encoder := argTable2[verb] def [s] := messageStreams.takeAtMost(1) try { encoder(s, args) } finally { s <- reserve() <- resolve(null) } null } } }