PassByConstruction

From Erights

(Difference between revisions)
Jump to: navigation, search
m
(revert)
 
(3 intermediate revisions not shown)
Line 1: Line 1:
-
An object declared as, for example
+
A PassByConstruction (also 'pbc') object is one which, when sent over a [[comm system]] (e.g. [[CapTP]]) to another vat, is sent as some serialized representation, and will typically arive [[near]] rather than as a [[far reference]] back to the originating vat ([[PassByProxy]]).
 +
 
 +
{{XXX|Are there any references neither PBP nor PBC?}}
 +
 
 +
PassByConstruction objects may additionally be [[Selfless]], which by definition makes them [[PassByCopy]], i.e. exactly duplicated. On the other hand, [[Selfish]] PassByConstruction objects are used, for example, for [[una]].
 +
 
 +
==Defining pass-by-construction objects==
 +
 
 +
E [[comm system]]s serialize any object approved by the <code>pbc</code> auditor as the [[portrayal]] returned by its [[Miranda optUncall|__optUncall/0]] method. For example, this is an object which will always arrive as the number 3:
 +
 
<code>
<code>
     def foo implements pbc {
     def foo implements pbc {
-
         to __optUncall() { return [1, "add", [2]] }
+
         to [[Miranda optUncall|__optUncall]]() { return [1, "add", [2]] }
         # ...
         # ...
     }
     }
</code>
</code>
-
will be passed-by-construction across CapTP. This means that its __optUncall() method will be called on the sending side, the elements of the result triple will be passed, and the corresponding triple as received will be called (here, as “E.call(1, "add", [2])”) to create the object as received.
 
-
==Example==
+
===Example===
The first part of the example is a maker for a 2D Vector. The created vectors are Pass By Construction, they should pass the guard :pbc.
The first part of the example is a maker for a 2D Vector. The created vectors are Pass By Construction, they should pass the guard :pbc.
-
The method __optUncall is a [Miranda_Method miranda method]. When the vector is copied to another [vat], the method __optUncall is called by the CapTP networking subsystem of E. The result of the method is used to recreate the object in the destination [vat].
+
This code should be positioned in an [[emaker]] file in the java classpath at the location "tests/makeVector.emaker"
-
This code should be positioned in a file in the java classpath at the location "tests.makeVector.emaker"
+
-
<code>
+
<pre>def makeVector implements pbc {
-
def makeVector implements pbc {
+
     to run(var x, var y) {
     to run(var x, var y) {
         def vector implements pbc {
         def vector implements pbc {
Line 26: Line 32:
     }
     }
     to __optUncall() :any {
     to __optUncall() :any {
-
         return [<import>, "get", ["tests.makeVector"]]
+
         return [&lt;import&gt;, "get", ["tests.makeVector"]]
     }
     }
-
}
+
}</pre>
-
</code>
+
Example of usage:
Example of usage:
-
<code>
+
<pre># create a new Vector object
-
#create a new Vector object
+
? def makeVector := &lt;import:tests.makeVector&gt;
-
? def makeVector := &lt;import:tests.makeVector&lgt;
+
# value: &lt;makeVector&gt;
# value: &lt;makeVector&gt;
Line 41: Line 45:
# value: &lt;Vector 6.6 7.7&gt;
# value: &lt;Vector 6.6 7.7&gt;
-
#create a new vat
 
? introducer.onTheAir()
? introducer.onTheAir()
# value: ["3DES_SDH_M2", "3DES_SDH_M"]
# value: ["3DES_SDH_M2", "3DES_SDH_M"]
-
? def seedVatAuthor := &lt;elang:interp.seedVatAuthor&gt;(&lt;unsafe&gt;).virtualize((introducer))
+
# function for creating a new local vat
 +
? def seedVatAuthor := &lt;elang:interp.seedVatAuthor&gt;(&lt;unsafe&gt;).virtualize(introducer)
# value: &lt;virtualSeedVat&gt;
# value: &lt;virtualSeedVat&gt;
-
# source code for the new vat
+
# Run this source code in the new vat. The method accepts a pbc object and prints it.
? def scriptSource:="def run(thing :pbc) {println(`Thing: $thing`)}"
? def scriptSource:="def run(thing :pbc) {println(`Thing: $thing`)}"
# value: "def run(thing :near) {println(`Thing: $thing`)}"
# value: "def run(thing :near) {println(`Thing: $thing`)}"
 +
# create the new vat. Return a far reference to the object and a reference to the vat object
? def [scriptObj, vat] := seedVatAuthor(scriptSource)
? def [scriptObj, vat] := seedVatAuthor(scriptSource)
# value: [&lt;Promise&gt;, &lt;Vat newVirtualSeedVat in &lt;runs in newVirtualSeedVat&gt;&gt;]
# value: [&lt;Promise&gt;, &lt;Vat newVirtualSeedVat in &lt;runs in newVirtualSeedVat&gt;&gt;]
 +
# pass the pbc object into the new vat
? scriptObj &lt;- run(vector)
? scriptObj &lt;- run(vector)
# value: &lt;Remote Promise&gt;
# value: &lt;Remote Promise&gt;
-
? Thing: &lt;Vector 6.6 7.7&gt;
+
? Thing: &lt;Vector 6.6 7.7&gt;</pre>
-
</code>
+
{{stub}}
 +
[[Category:ELib specification]]

Latest revision as of 22:48, 20 April 2011

A PassByConstruction (also 'pbc') object is one which, when sent over a comm system (e.g. CapTP) to another vat, is sent as some serialized representation, and will typically arive near rather than as a far reference back to the originating vat (PassByProxy).

XXX Are there any references neither PBP nor PBC?

PassByConstruction objects may additionally be Selfless, which by definition makes them PassByCopy, i.e. exactly duplicated. On the other hand, Selfish PassByConstruction objects are used, for example, for una.

Defining pass-by-construction objects

E comm systems serialize any object approved by the pbc auditor as the portrayal returned by its __optUncall/0 method. For example, this is an object which will always arrive as the number 3:

   def foo implements pbc {
       to __optUncall() { return [1, "add", [2]] }
       # ...
   }

Example

The first part of the example is a maker for a 2D Vector. The created vectors are Pass By Construction, they should pass the guard :pbc. This code should be positioned in an emaker file in the java classpath at the location "tests/makeVector.emaker"

def makeVector implements pbc {
    to run(var x, var y) {
        def vector implements pbc {
            to getX() :any { return x }
            to getY() :any { return y }
            to __optUncall() :any { return [makeVector, "run", [x,y]] }
            to __printOn(out) {out.print(`<Vector $x $y>`)}
        }
        return vector
    }
    to __optUncall() :any {
        return [<import>, "get", ["tests.makeVector"]]
    }
}

Example of usage:

# create a new Vector object
? def makeVector := <import:tests.makeVector>
# value: <makeVector>

? def vector := makeVector(6.6,7.7)
# value: <Vector 6.6 7.7>

? introducer.onTheAir()
# value: ["3DES_SDH_M2", "3DES_SDH_M"]

# function for creating a new local vat
? def seedVatAuthor := <elang:interp.seedVatAuthor>(<unsafe>).virtualize(introducer)
# value: <virtualSeedVat>

# Run this source code in the new vat. The method accepts a pbc object and prints it.
? def scriptSource:="def run(thing :pbc) {println(`Thing: $thing`)}"
# value: "def run(thing :near) {println(`Thing: $thing`)}"

# create the new vat. Return a far reference to the object and a reference to the vat object
? def [scriptObj, vat] := seedVatAuthor(scriptSource)
# value: [<Promise>, <Vat newVirtualSeedVat in <runs in newVirtualSeedVat>>]

# pass the pbc object into the new vat
? scriptObj <- run(vector)
# value: <Remote Promise>

? Thing: <Vector 6.6 7.7>
This page is a stub; it should be expanded with more information. If doing so, check the original E web site and the mailing list archives for content which could be moved into this page.
Personal tools
more tools