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

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Operational Semantics 50push(G, (self , x, x ∗ ), (o, n, q)), which is well-typed w.r.t. ∆ 1 = push(∆, (self , x), (u, t ′′ )). Noticethat Definition 19 of well-typed states permits extra auxiliary variables with names notin A .Since Γ ⊢ u :: m{k}, by (T-Meth), we have Γ, push(∆ ∅ , (self , x), (u, t ′′ )) ⊢ k. By Lemma 11,we also have Γ, ∆ 1 ⊢ k, and k cannot see any variables in ∆, including those in re. Also, theauxiliary variables x ∗ are used only by enter and leave and cannot be seen by k.By the induction hypothesis, if 〈k, G 1 〉 → G ′ 1 , we have that a state graph G′ 1 is well-typedw.r.t. ∆ 1 . It implies that pop(G ′ 1 ) is well-typed w.r.t. ∆, and neither re nor x∗ is changed inpop(G ′ 1 ). Hence, we can per<strong>for</strong>m the spo on re, variables or attributes, to retain the originaledges d <strong>for</strong> re. According to (T-Var), we maintain Γ, ∆ 1 ⊢ x : t ′′ . Thus n = eval(G ′ 1 , x) existand Γ ⊢ Γ(G ′ 1 , n) t′′ . There<strong>for</strong>e, the leave command swings d to n which are of subtypes oft ′ , <strong>for</strong> Γ ⊢ t ′′ t ′ being a premise of (T-Invk). Then it pops the graph. The resulted stategraph G ⋄ differs from pop(G ′ 1 ) only in the update of d, thus is still well-typed w.r.t. ∆.If 〈k, G 1 〉 → 〈k ′ , G ′ 1 〉, we have Γ, ∆′ 1 → ∆ 1 ⊢ k ′ and G ′ 1 well-typed w.r.t. ∆′ 1 . In orderto deduce Γ, ∆ ′ 1 → ∆ ⊢ (k′ ; leave(x, re)), we only need to setup an auxiliary typing ruleΓ, ∆ → pop(∆) ⊢ leave(x, re). This is possible, since we have shown that a leave commandin a method invocation expansion is always type-safe, and leave pops a state graph, meaningthat the type context also needs to be popped.– Case c is c 1 ; c 2 .Since Γ, ∆ → ∆ ⋄ ⊢ c 1 ; c 2 can only be resulted from (T-Seq), we have Γ, ∆ → ∆ mid ⊢ c 1and Γ, ∆ mid → ∆ ⋄ ⊢ c 2 <strong>for</strong> some ∆ mid . From the induction hypothesis, there are two cases:either (1) 〈c 1 , G〉 → G ′ <strong>for</strong> some G ′ well-typed w.r.t. ∆ mid ; or (2) 〈c 1 , G〉 → 〈c ′ 1 , G′ 〉 andΓ, ∆ ′ → ∆ mid ⊢ c ′ 1 <strong>for</strong> some ∆′ , c ′ 1 and G′ well-typed w.r.t. ∆ ′ . In the case (1), we have〈c 1 ; c 2 , G〉 → 〈c 2 , G ′ 〉 according to (Seq-Pri). In the case (2), we have 〈c 1 ; c 2 , G〉 → 〈c ′ 1 ; c 2, G ′ 〉according to (Seq), and Γ, ∆ ′ → ∆ ⋄ ⊢ c ′ 1 ; c 2 according to (T-Seq).– Case c is c 1 ⊳ e ⊲ c 2 .Since Γ, ∆ → ∆ ⋄ ⊢ c 1 ⊳ e ⊲ c 2 can only be resulted from (T-If), we have ∆ ⋄ = ∆, Γ, ∆ ⊢e : B, Γ, ∆ ⊢ c 1 and Γ, ∆ ⊢ c 2 . So, eval(G, e) equals true or false, Γ, ∆ → ∆ ⋄ ⊢ c 1 andΓ, ∆ → ∆ ⋄ ⊢ c 2 . If eval(G, e) = true, we have 〈c 1 ⊳ e ⊲ c 2 , G〉 → 〈c 1 , G〉 according to (If-T).Otherwise, we get 〈c 1 ⊳ e ⊲ c 2 , G〉 → 〈c 2 , G〉 according to (If-F).– Case c is e ∗ c 1 .Since Γ, ∆ → ∆ ⋄ ⊢ e ∗ c 1 can only be resulted from (T-While), we have ∆ ⋄ = ∆, Γ, ∆ ⊢e : B and Γ, ∆ ⊢ c 1 . As a result, eval(G, e) equals true or false and Γ, ∆ → ∆ ⊢ c 1 . Ifeval(G, e) = false, we have 〈e ∗ c 1 , G〉 → G according to (While-F). Otherwise, we get〈e ∗ c 1 , G〉 → 〈c 1 ; e ∗ c 1 , G〉 according to (While-T), and Γ, ∆ → ∆ ⋄ ⊢ c 1 ; e ∗ c 1 accordingto (T-Seq).<strong>Based</strong> on Lemma 12, Theorem 2 and 3, we can prove the type-safety of programs.□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!