Upload
austen-charles
View
214
Download
1
Embed Size (px)
Citation preview
Distributed Meta-Programming
Rui Shi, Chiyan Chen and Hongwei Xi
Boston University
Outline
MP vs. DMP Typeful Code Representation The Language dist
The Language +dist
Discussion and Conclusion
Meta-Programming
(define (run code) (eval code nil))(define (power n x)(if (= n 0) 1 `(* ,x ,(power (- n 1) x))))
;;; (power 2 ‘x) yields (* x (* x 1))(define square(run `(lambda (x) ,(power 2 ‘x))))
;;; (power 3 ‘y) yields (* y (* y (* y 1)))(define cube(run `(lambda (y) ,(power 3 ‘y))))
Distributed Meta-Programming
Code
Code
Run-time code generation
Distributed execution
Outline
MP vs. DMP Typeful Code Representation The Language dist
The Language +dist
Discussion and Conclusion
`(“abc” + 10) (ill-typed) `(( y.x) 10) (open code)
Un-typed Code Representation
No guarantee on the safety of generated code. Code can be syntactically ill-formed or ill-typed,
which lead to run-time errors when executed at remote sites.
Issues of locality and heterogeneity of resources Different sites may have different resources and thus likely to
provide different services.
f : (Int ! Int)@L
L `(f 100)
L’
Typeful Code Representation (T.C.R) The types of object programs can be reflected in the types of meta
programs E.g. code of type h , T i represents an object program of type T under
the type environment .
The type of the code also reflects where it should be sent for execution. E.g. code of type h L, , T i can be sent to location L for execution.
The compiler can statically guarantee that only well-typed code can be constructed at run-time and sent to proper locations for execution.
Outline
MP vs. DMP Typeful Code Representation The Language dist
The Language +dist
Discussion and Conclusion
The Language dist
First-Order Code Constructors
For example, the term x. y. y (x) can be represented as:
which can be of type (with static variables properly instantiated)
Lam (Lam (App (One) (Shi (One))))
8 . h , , int ! (int ! int) ! int i
Some Primitive Functions
Constant Messages
Constant messages refer to the messages which can be interpreted at all sites.
Example: perform addition of two integers at remote site
An Example in dist
f : (Int ! Int)@L
L `(f 100)
rgetint (L, rexec (L, App (Lift (n2m f)), Lift 100) ))
of type h L, , int i
Outline
MP vs. DMP Typeful Code Representation The Language dist
The Language +dist
Discussion and Conclusion
The Language +dist
We extend dist to +dist with some language constructs
adopted from meta-programming (supported in Scheme and MetaML):
`(e) for the code representation of e ^(e) for spliceing the code e into some context %(¢) is a shorthand for ^(Lift(¢))
An Example in Concrete Syntax of +
dist
typedef CodeType (L: loc) = <L, nil, (int -> int) -> int>
fun rZeroFind2{L:loc} (L:loc(L)) (n: (int -> int) @ L) : int = let val zeroFindCode : CodeType (L) = `(lam f => (fix aux i => if f (i) = 0 then i else aux (i+1)) 0) in rexecInt (L, `(^zeroFindCode %(n2m n))) end
Outline
MP vs. DMP Typeful Code Representation The Language dist
The Language +dist
Discussion and Conclusion
Discussion
We have a transformation scheme from +dist to
dist to justify the soundness of +dist .
We have a process to elaborate programs (partial type inference) in the concrete syntax to the formal syntax of +
dist
DMP is implemented as a part of ATS (Applied Type System) framework.
Conclusion
A simple and general approach to support typed mobile computing.
Combines meta-programming with distributed programming in a coherent manner.
In future, we are planning to study issues such as exception handling and distributed garbage collection in this context.
Thank You!