// field ::= 'fst' | 'snd' // Relations representing the program: // ploadconst : loc -> reg -> num -> type (l : x = n) // pallocpair : loc -> reg -> reg -> reg -> type (l : x = < y , z >) // pgetfield : loc -> reg -> reg -> field -> type (l : x = y.f) // psetfield : loc -> reg -> field -> reg -> type (l : x.f = y) // values are numbers or locations: // value = | loc(l) // The relations we want to define: // valueofreg : reg -> value -> type // valueoffield : loc -> field -> value -> type // TASK: // Rule 1: If ploadconst(?l, ?r, ?n), // what can you say about the value of register ?r ? // Rule 2: If pgetfield(?l2, ?r1, ?r2, ?f) // and register ?r2 can have value ?l // and field ?l.?f can have value ?v, // what can you say about the value of r1? // Rule 3: If psetfield(?l2 , ?r1 , ?f , ?r2), // what do you need to know about the values of ?r1 and ?r2 // to know something about the value of the field ?l.?f ? // Rules 4 5 and 6: If pallocpair(?l , ?r , ?r1 , ?r2), // what can you say about // the values of: // (a) the field ?l.'fst' // (b) the field ?l.'snd' // (c) the register ?r // ---------------------------------------------------------------------- // the progam ploadconst('l1', 'w', 0). // l1 : w = 0 ploadconst('l2', 'x', 1). // l2 : x = 1 ploadconst('l3', 'y', 2). // l3 : y = 2 ploadconst('l4', 'z', 3). // l4 : z = 3 pallocpair('l5', 'p1', 'w', 'x'). // l5 : p1 = < w , x > pallocpair('l6', 'p2', 'y', 'z'). // l6 : p2 = < y , z > pallocpair('l7' , 'p' , 'p1' , 'p2'). // l7 : p = psetfield('l12', 'p', 'fst', 'p2'). // l12 : p.fst = p2 psetfield('l13', 'p', 'snd', 'p1'). // l13 : p.snd = p1 pgetfield('l8', 'p1' , 'p' , 'fst'). // l8 : p1 = p.fst pgetfield('l9', 'p2' , 'p' , 'snd'). // l9 : p2 = p.snd pgetfield('l10', 'r1', 'p1' , 'fst'). // l10 : r1 = p1.fst pgetfield('l11', 'r2', 'p2' , 'snd'). // l11 : r2 = p2.snd // SHOULD BE: 0,2 ?- valueofreg('r1',?v1). // SHOULD BE: 3,1 ?- valueofreg('r2',?v2).