Skip to content

Commit 7e7f8ed

Browse files
committed
initial draft of axiom syntax for JSketch.
1 parent 820e652 commit 7e7f8ed

File tree

1 file changed

+61
-0
lines changed

1 file changed

+61
-0
lines changed

axioms/ArrayList.java

+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
@axiom // lets compiler know this is an adt
2+
class ArrayList {
3+
// Gave names to the parameters so we can specify names for the adt fields here
4+
@adt // constructor in adt
5+
Object get(int i);
6+
7+
// I think we only need set if we have an axiom where we're worried
8+
// about the return value from set
9+
@adt
10+
Object set(int i, Object o);
11+
@adt // constructor in adt
12+
Object set!(int i, Object o);
13+
14+
@axiom // this should be used to fill in xform
15+
Object get(set!(ArrayList a, int i, Object o), int j) => i == j ? o : get(a, j);
16+
// or
17+
@axiom
18+
Object get(set!(ArrayList a, int i, Object o), int j) { return i == j ? o : get(a, j); }
19+
}
20+
/*
21+
* Every constructor in adt has field of its own type?
22+
23+
@axiom
24+
class ArrayList { } =>
25+
adt ArrayList { }
26+
27+
@adt
28+
Object get(int); =>
29+
adt ArrayList {
30+
Get { ArrayList a; int i; } }
31+
32+
@adt
33+
Object set(int); =>
34+
adt ArrayList {
35+
Get { ArrayList a; int i; }
36+
Set { ArrayList a; int i; Object o; } }
37+
38+
@adt
39+
Object set!(int); =>
40+
adt ArrayList {
41+
Get { ArrayList a; int i; }
42+
Set { ArrayList a; int i; Object o; }
43+
SetB { ArrayList a; int i; Object o; } }
44+
45+
@axiom
46+
Object get(set!(ArrayList a, int i, Object o), int j) => i == j ? o : get(a, j); =>
47+
// We assume this is getting called on the `a` in a get(a, _)
48+
xform_get(ArrayList a, int j) {
49+
switch(a) {
50+
// since get is the first method in the axiom if fires on this case
51+
case Get: assert fail; // No axioms for get(get(_))
52+
case Set: assert fail; // No axioms for get(set(_))
53+
case SetB: { // since we are in the set
54+
if (a.i == j) return a.o;
55+
else return xform_get(a.a, j);
56+
}
57+
}
58+
}
59+
60+
*/
61+

0 commit comments

Comments
 (0)