:- use_module(library(aspects), [aspect/3, aspect_declaration/1]). :- use_module(library(avl), [ avl_get/3, avl_replace/4, avl_put/4, avl_has/2, avl_empty/1 ]). :- aspect_declaration(use_module(library(avl), [ avl_get/3, avl_replace/4, avl_put/4, avl_has/2, avl_empty/1 ])). :- aspect(around, initialize_memory(Mem), (avl_empty(Empty), avl_put(Empty, 0, value(0), AVL), Mem = memory(0, AVL))). :- aspect(around, selected_memory_cell(Datum, P0, P1), (P0 = program(_, _, _, memory(Index, AVL), _), avl_get(AVL, Index, value(Datum)), P1 = P0)). :- aspect(around, command(Cmd, P0, P1), (Cmd = store, !, P0 = program(A, H, R, memory(Index, AVL0), P), get_active_ring(A, R, ring(_, _, _, Value)), avl_replace(AVL0, Index, Value, AVL1), P1 = program(A, H, R, memory(Index, AVL1), P))). :- ensure_loaded(library(math)). :- aspect_declaration(ensure_loaded(library(math))). :- aspect(around, command(Cmd, P0, P1), (Cmd = dadd, P0 = program(ops, H, Rings, memory(Index, AVL0), P), !, get_active_ring(ops, Rings, ring(ops, _, _, value(X))), floor(X, Y), NewIndex is Index + Y, (avl_has(AVL0, NewIndex) -> AVL1 = AVL0; avl_put(AVL0, NewIndex, value(0), AVL1)), P1 = program(ops, H, Rings, memory(NewIndex, AVL1), P))). :- aspect(around, command(Cmd, P0, P1), (Cmd = intIO, P0 = program(ops, H, Rings, memory(Index, AVL0), P), get_active_ring(ops, Rings, ring(ops, _, _, value(0))), !, read_term(N, []), (integer(N)-> true; raise_exception(integral_expected(received(N)))), avl_replace(AVL0, Index, value(N), AVL1), P1 = program(ops, H, Rings, memory(Index, AVL1), P))). :- aspect(around, command(Cmd, P0, P1), (Cmd = ascIO, P0 = program(ops, H, Rings, memory(Index, AVL0), P), get_active_ring(ops, Rings, ring(ops, _, _, value(0))), !, get(Char), avl_replace(AVL0, Index, value(Char), AVL1), P1 = program(ops, H, Rings, memory(Index, AVL1), P))). :- aspect(around, command(_, _, _), prove_goal).