13.07.2015 Views

A Graph-Based Generic Type System for Object-Oriented Programs

A Graph-Based Generic Type System for Object-Oriented Programs

A Graph-Based Generic Type System for Object-Oriented Programs

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Execution Environment 40We extract all the class methods C :: m as a list C :: m{c}, and the Main method as {Te x; c}.In this way, a program is denoted asP = C :: m{c} • {Te x; c}.Definition 16 (Well-<strong>Type</strong>d Program) Let Γ be a type graph and P a program. If Γ ⊢ P →P ′ , P ′ is a well-typed program under type graph Γ.After the type-checking, if a program P ′ is well-typed under Γ, P ′ contains the environmentdependent commands <strong>for</strong> all the methods. The type-checking rules <strong>for</strong> methods and programsare given in Table 8.6 Execution EnvironmentThe environment of a program stores the structure of the initial object plus the method bodycommands <strong>for</strong> each concrete class. An initial object in the environment is represented by a typenode in the environment graph. The outgoing edges of this node are labeled by the attributes ofthe class and the targets of the these edges are the default (or initial) values of the correspondingattributes. It also has an outgoing edge labeled by σ to the static table of the class, representedas a node with outgoing edges labeled by method names of the class to the corresponding bodycommands. The outgoing edges, the targeted literals and the static table of the class constitutethe structure of the initial object of the class, called a class frame. There is also a set of nodesrecorded on the static table of each class, representing its supertypes.<strong>Based</strong> on an environment graph, the execution of a program looks up methods, creates classinstances and checks typecasts at runtime without the need of a type graph.6.1 Environment <strong>Graph</strong>sLet L be the set of literals, including the null object and the values of primitive types, and Kthe set of commands. We assume that L , K , O and N are disjoint.Definition 17 (Environment <strong>Graph</strong>) An environment graph is a directed and labeled graphR = 〈N, E, S〉, where– N ⊆ N ∪ L ∪ K , is the set of type nodes, static tables, literals and commands,– E : (N ∩ N ) × (A ∪ {σ}) → N is the set of edges,Report No. 448, June 2011UNU-IIST, P.O. Box 3058, Macao

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!