comparison cbc/atton-master-sample.agda @ 72:dc8f140e299d

Add sample for atton-master
author atton <atton@cr.ie.u-ryukyu.ac.jp>
date Wed, 01 Feb 2017 05:05:35 +0000
parents
children a5cac9483f91
comparison
equal deleted inserted replaced
71:614997a2e21c 72:dc8f140e299d
1 module atton-master-sample where
2
3 open import Data.Nat
4 open import Data.Unit
5 open import Function
6 Int = ℕ
7
8 record Context : Set where
9 field
10 a : Int
11 b : Int
12 c : Int
13
14
15 open import subtype Context
16
17
18
19 record ds0 : Set where
20 field
21 a : Int
22 b : Int
23
24 record ds1 : Set where
25 field
26 c : Int
27
28 instance
29 _ : DataSegment ds0
30 _ = record { set = (\c d -> record c {a = (ds0.a d) ; b = (ds0.b d)})
31 ; get = (\c -> record { a = (Context.a c) ; b = (Context.b c)})}
32 _ : DataSegment ds1
33 _ = record { set = (\c d -> record c {c = (ds1.c d)})
34 ; get = (\c -> record { c = (Context.c c)})}
35
36 cs2 : {{_ : DataSegment ds1}} -> CodeSegment ds1 ds1
37 cs2 {{d}} = cs {{d}}{{d}} id
38
39 cs1 : CodeSegment ds1 ds1
40 cs1 = cs (\d -> goto cs2 d)
41
42 cs0 : {{_ : DataSegment ds0}} {{_ : DataSegment ds1}} -> CodeSegment ds0 ds1
43 cs0 {{d0}}{{d1}} = cs {{d0}}{{d1}} (\d -> goto {{d1}} {{d1}} cs1 (record {c = (ds0.a d) + (ds0.b d)}))
44
45 main : ds1
46 main = goto cs0 (record {a = 100 ; b = 50})