

% ?- op(700, xfx, ->).


printIdxMap(In, idx(X)) :-
    tab(In),
    printString("idx "),
    write(X),
    nl.
printIdxMap(In, fun(F, Ds, Atr)) :-
    tab(In),
    printString("fun "),
    write(F),
    atrSrcMap(Atr, A),
    atrDstMap(Atr, B),
    print2Assoc(A, B),
    nl,
    Inpp is In + 2,
    printDaughtIdxMap(Inpp, Ds).
printIdxMap(In, var(V, Ds, Atr)) :-
    tab(In),
    printString("var "),
    write(V),
    atrSrcMap(Atr, A),
    atrDstMap(Atr, B),
    print2Assoc(A, B),
    nl,
    Inpp is In + 2,
    printDaughtIdxMap(Inpp, Ds).
printIdxMap(In, arr(I, D, Atr)) :-
    tab(In),
    printString("arr "),
    writeList(I),
    atrNodMap(Atr, A),
    print1Assoc(A),
    nl,
    Inpp is In + 2,
    printIdxMap(Inpp, D).

printDaughtIdxMap(_, []) :- !.
printDaughtIdxMap(In, [X | L]) :- printIdxMap(In, X), printDaughtIdxMap(In, L).

% Print node and target alignments

print1Assoc(A) :-
    current_output(Op),
    line_position(Op, P),
    S is 35 - P,
    tab(S),
    printAlign(A).

print2Assoc(A, B) :-
    current_output(Op),
    line_position(Op, P),
    S is 35 - P,
    tab(S),
    printAlign(A),
    line_position(Op, Q),
    T is 60 - Q,
    tab(T),
    printAlign(B).

printAlign(map(T, _, M)) :-
    write(T),
    printString(":"),
    write(M).

writeList([])      :- !.
writeList([X])     :- write(X), !.
writeList([X | L]) :- write(X), printString(", "), writeList(L).

printString([]) :- !.
printString([X | T]) :- put(X), printString(T).


