expWhen this annotated expression is to be evaluated, pred in the annotation is evaluated first. If the result is true, replicas of objects that are bound to the variables 17#17 are created; and the exp is evaluated in an environment such that the variables 17#17 are bound to the replicas. We can add annotations to the function product shown in Figure 2, so as to employ replicas. The program with annotations is shown in Figure 8. Note that the only difference between this program and the original one is the addition of the annotation.{replicate (17#17) :whenpred}
|
1: (defmethod replica-eval eval-annotation (body args env)
1: (defmethod replica-eval eval-annotation (body args env)
2: (if (eval self (replica-predicate args) env)
3: (let* ((target (replica-target args))
4: (obj (lookup target env))
5: (rep (denotation (copy-object (meta obj) (this-pe))))
6: (ex-env (extend-env env (list target) (list rep))))
7: (let ((answer (eval self body ex-env)))
8: (copy-back (meta rep))
9: answer))
10: (eval self body env)))
2: (if (eval self (replica-predicate args) env) 3: (let* ((target (replica-target args)) 4: (obj (lookup target env)) 5: (rep (denotation (copy-object (meta obj) (this-pe)))) 6: (ex-env (extend-env env (list target) (list rep)))) 7: (let ((answer (eval self body ex-env))) 8: (copy-back (meta rep)) 9: answer)) 10: (eval self body env))) (l.2) It evaluates pred in an annotation. If it is true, (l.5) a replica of a specified object is created. The functions denotation and meta return corresponding base-level object and meta-object, respectively; and the function this-pe returns a current processor ID. (l.7) The body of the expression is then evaluated in an extended environment. (l.8) Method copy-back is a user-defined method of the replicated metaobject, which writes values of instance variables in the original metaobject's for consistency management. (l.10) If the pred is false, it evaluates the body of the expression as usual. |