module MJSF.Examples.DynamicDispatch where
open import Prelude
open import Data.Maybe hiding (All)
open import Data.Vec hiding (_∈_; init; _++_)
import Data.Vec.All as Vec∀
open import Data.Star
open import Data.Bool
open import Data.List
open import Data.Integer
open import Data.List.Any
open import Data.List.Any.Membership.Propositional
open import Data.List.All hiding (lookup)
open import Data.Product hiding (Σ)
open import Relation.Binary.PropositionalEquality
open import Relation.Nullary.Decidable
k : ℕ
k = 10
open import MJSF.Syntax k
open import ScopesFrames.ScopesFrames k Ty
Root : Scope
Root = # 0
Int : Scope
Int = # 1
IntInc : Scope
IntInc = # 2
classes : List Ty
classes = (cᵗ Root Int ∷
cᵗ Root IntInc ∷ [])
Int-methods Int-fields : List Ty
Int-fields =
vᵗ int
∷ []
Int-methods =
mᵗ [] int ∷
mᵗ (ref Int ∷ []) int ∷
[]
IntInc-methods IntInc-fields : List Ty
IntInc-methods =
mᵗ (ref Int ∷ []) int ∷
[]
IntInc-fields = []
g : Graph
g zero =
classes , []
g (suc zero) =
(Int-methods ++ Int-fields) , zero ∷ []
g (suc (suc zero)) =
(IntInc-methods ++ IntInc-fields) , zero ∷ # 1 ∷ []
g (suc (suc (suc zero))) =
[] , Int ∷ []
g (suc (suc (suc (suc zero)))) =
vᵗ (ref Int) ∷ [] , Int ∷ []
g (suc (suc (suc (suc (suc zero))))) =
[] , IntInc ∷ []
g (suc (suc (suc (suc (suc (suc zero)))))) =
vᵗ (ref Int) ∷ [] , IntInc ∷ []
g (suc (suc (suc (suc (suc (suc (suc zero))))))) =
vᵗ (ref Int) ∷ [] , # 6 ∷ []
g (suc (suc (suc (suc (suc (suc (suc (suc zero)))))))) =
vᵗ (ref Int) ∷ [] , Root ∷ []
g (suc (suc (suc (suc (suc (suc (suc (suc (suc zero))))))))) =
vᵗ (ref IntInc) ∷ [] , # 8 ∷ []
g (suc (suc (suc (suc (suc (suc (suc (suc (suc (suc ()))))))))))
open SyntaxG g
open UsesGraph g
IntImpl : Class Root Int
IntImpl =
class0 {ms = Int-methods} {fs = Int-fields}
(#m' (meth (# 3)
(body ε
(var (path ((here refl) ∷ []) (there (there (here refl))))))) ∷
(#m' (meth (# 4)
(body ( asgn (path ((here refl) ∷ [])
(there (there (here refl))))
(get (var (path [] (here refl)))
(path [] (there (there (here refl)))))
◅ ε)
(call (this [] (here refl))
(path [] (here refl))
[])))) ∷ [])
((#v' tt) ∷ [])
[]
IntIncImpl : Class Root IntInc
IntIncImpl =
class1 {ms = IntInc-methods} {fs = IntInc-fields}
(path [] (here refl))
(#m'
(meth
(# 6)
(body
( loc (# 7) (ref Int)
◅ asgn (path [] (here refl))
(new (path ((here refl) ∷ ((here refl) ∷ ((here refl) ∷ [])))
(here refl)))
◅ set (var (path [] (here refl)))
(path [] (there (there (here refl))))
(iop Data.Integer._+_
(get (var (path ((here refl) ∷ []) (here refl)))
(path [] (there (there (here refl)))))
(num (+ 1)))
◅ ε)
(call (this (here refl ∷ []) (here refl))
(path (there (here refl) ∷ []) (there (here refl)))
((var (path [] (here refl))) ∷ [])))) ∷
[])
[]
(#m'
(path ((there (here refl)) ∷ []) (here refl) ,
(meth
(# 5)
(body
ε
(iop Data.Integer._+_
(var (path ((here refl) ∷ ((there (here refl)) ∷ []))
(there (there (here refl)))))
(num (+ 1)))))) ∷ [])
main : Body Root int
main =
body
( (loc (# 8) (ref Int))
◅ asgn (path [] (here refl))
(new (path (here refl ∷ []) (here refl)))
◅ set (var (path [] (here refl)))
(path [] (there (there (here refl))))
(num (+ 18))
◅ loc (# 9) (ref IntInc)
◅ asgn (path [] (here refl))
(new (path (here refl ∷ here refl ∷ [])
(there (here refl))))
◅ set (var (path [] (here refl)))
(path (there (here refl) ∷ []) (there (there (here refl))))
(num (+ 0))
◅ ε)
(call (var (path [] (here refl)))
(path [] (here refl))
(var (path ((here refl) ∷ []) (here refl)) ∷ []))
p : Program Root int
p = program classes
(#c' (IntImpl , Int , obj Int ⦃ refl ⦄) ∷
(#c' (IntIncImpl , Int , (super ⦃ refl ⦄ (obj Int ⦃ refl ⦄)))) ∷
[]) main
open import MJSF.Semantics
open Semantics _ g
open import MJSF.Values
open ValuesG _ g
test : p ⇓⟨ 100 ⟩ (λ v → v ≡ num (+ 20) )
test = refl