PassByConstruction

From Erights

(Difference between revisions)
Jump to: navigation, search
(Initial entry)
Line 7: Line 7:
</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.
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==
 +
 +
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 a file in the java classpath at the location "tests.makeVector.emaker"
 +
 +
<code>
 +
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"]]
 +
    }
 +
}
 +
</code>
 +
 +
Example of usage:
 +
<code>
 +
#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>
 +
 +
#create a new vat
 +
? introducer.onTheAir()
 +
# value: ["3DES_SDH_M2", "3DES_SDH_M"]
 +
 +
? def seedVatAuthor := <elang:interp.seedVatAuthor>(<unsafe>).virtualize((introducer))
 +
# value: <virtualSeedVat>
 +
 +
# source code for the new vat
 +
? def scriptSource:="def run(thing :pbc) {println(`Thing: $thing`)}"
 +
# value: "def run(thing :near) {println(`Thing: $thing`)}"
 +
 +
? def [scriptObj, vat] := seedVatAuthor(scriptSource)
 +
# value: [<Promise>, <Vat newVirtualSeedVat in <runs in newVirtualSeedVat>>]
 +
 +
? scriptObj <- run(vector)
 +
# value: <Remote Promise>
 +
 +
? Thing: <Vector 6.6 7.7>
 +
</code>

Revision as of 09:58, 18 April 2007

An object declared as, for example

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

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

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 a 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:

  1. create a new Vector object

? def makeVector := <import:tests.makeVector>

  1. value: <makeVector>

? def vector := makeVector(6.6,7.7)

  1. value: <Vector 6.6 7.7>
  1. create a new vat

? introducer.onTheAir()

  1. value: ["3DES_SDH_M2", "3DES_SDH_M"]

? def seedVatAuthor := <elang:interp.seedVatAuthor>(<unsafe>).virtualize((introducer))

  1. value: <virtualSeedVat>
  1. source code for the new vat

? def scriptSource:="def run(thing :pbc) {println(`Thing: $thing`)}"

  1. value: "def run(thing :near) {println(`Thing: $thing`)}"

? def [scriptObj, vat] := seedVatAuthor(scriptSource)

  1. value: [<Promise>, <Vat newVirtualSeedVat in <runs in newVirtualSeedVat>>]

? scriptObj <- run(vector)

  1. value: <Remote Promise>

? Thing: <Vector 6.6 7.7>

Personal tools
more tools