20
Distributed Meta- Programming Rui Shi , Chiyan Chen and Hongwei Xi Boston University

Distributed Meta- Programming Rui Shi, Chiyan Chen and Hongwei Xi Boston University

Embed Size (px)

Citation preview

Page 1: Distributed Meta- Programming Rui Shi, Chiyan Chen and Hongwei Xi Boston University

Distributed Meta-Programming

Rui Shi, Chiyan Chen and Hongwei Xi

Boston University

Page 2: 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

Page 3: Distributed Meta- Programming Rui Shi, Chiyan Chen and Hongwei Xi Boston University

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))))

Page 4: Distributed Meta- Programming Rui Shi, Chiyan Chen and Hongwei Xi Boston University

Distributed Meta-Programming

Code

Code

Run-time code generation

Distributed execution

Page 5: 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

Page 6: Distributed Meta- Programming Rui Shi, Chiyan Chen and Hongwei Xi Boston University

`(“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’

Page 7: Distributed Meta- Programming Rui Shi, Chiyan Chen and Hongwei Xi Boston University

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.

Page 8: 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

Page 9: Distributed Meta- Programming Rui Shi, Chiyan Chen and Hongwei Xi Boston University

The Language dist

Page 10: Distributed Meta- Programming Rui Shi, Chiyan Chen and Hongwei Xi Boston University

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

Page 11: Distributed Meta- Programming Rui Shi, Chiyan Chen and Hongwei Xi Boston University

Some Primitive Functions

Page 12: Distributed Meta- Programming Rui Shi, Chiyan Chen and Hongwei Xi Boston University

Constant Messages

Constant messages refer to the messages which can be interpreted at all sites.

Example: perform addition of two integers at remote site

Page 13: Distributed Meta- Programming Rui Shi, Chiyan Chen and Hongwei Xi Boston University

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

Page 14: 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

Page 15: Distributed Meta- Programming Rui Shi, Chiyan Chen and Hongwei Xi Boston University

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(¢))

Page 16: Distributed Meta- Programming Rui Shi, Chiyan Chen and Hongwei Xi Boston University

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

Page 17: 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

Page 18: Distributed Meta- Programming Rui Shi, Chiyan Chen and Hongwei Xi Boston University

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.

Page 19: Distributed Meta- Programming Rui Shi, Chiyan Chen and Hongwei Xi Boston University

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.

Page 20: Distributed Meta- Programming Rui Shi, Chiyan Chen and Hongwei Xi Boston University

Thank You!