34
35:- module(pce_portray, []). 36:- use_module(pce_boot(pce_principal)). 37
38:- multifile
39 user:portray/1,
40 user:prolog_list_goal/1,
41 user:prolog_predicate_name/2,
42 user:prolog_clause_name/2. 43:- dynamic
44 user:portray/1. 45
50
51user:portray(Obj) :-
52 Obj = @Ref,
53 object(Obj),
54 !,
55 ( send(Obj, '_instance_of', var)
56 -> get(Obj, '_value', Value),
57 format('@~w(= ~p)', [Ref, Value])
58 ; get(Obj, '_class_name', CN),
59 format('@~w/~w', [Ref, CN])
60 ).
61user:portray(pce_principal:send_implementation(Id, Args, Receiver)) :-
62 object(Receiver),
63 !,
64 method_from_id(Id, (Class->_Method)),
65 format('Send-method on ~p: ~w->~p', [Receiver, Class, Args]).
66user:portray(pce_principal:get_implementation(Id, Args, Receiver, RVal)) :-
67 object(Receiver),
68 !,
69 method_from_id(Id, <-(Class, _Method)),
70 format('Get-method on ~p: ~w<-~p --> ~p',
71 [Receiver, Class, Args, RVal]).
72
77
78user:prolog_list_goal(pce_principal:send_implementation(Id, _Args, _Ref)) :-
79 !,
80 ( Head = pce_principal:send_implementation(Id, Args, Ref),
81 method_from_id(Id, ->(Class, Sel)),
82 clause(Head, Body)
83 -> format('~N~n% XPCE Method ~w->~w:~n~n', [Class, Sel]),
84 portray_clause(((Ref->Args) :- Body)),
85 nl
86 ; format('No XPCE method implementation for id=~p~n', [Id])
87 ).
88user:prolog_list_goal(pce_principal:get_implementation(Id, _Args, _Ref, _Rval)) :-
89 !,
90 ( Head = pce_principal:get_implementation(Id, Args, Ref, Rval),
91 method_from_id(Id, <-(Class, Sel)),
92 clause(Head, Body)
93 -> format('~N~n% XPCE Method ~w<-~w:~n~n', [Class, Sel]),
94 portray_clause(((Rval = <-(Ref,Args)) :- Body)),
95 nl
96 ; format('No XPCE method implementation for id=~p~n', [Id])
97 ).
104user:prolog_predicate_name(pce_principal:send_implementation(Id0, _, _),
105 Id) :-
106 method_from_id(Id0, SG),
107 atom_from_method(SG, Id).
108user:prolog_predicate_name(pce_principal:get_implementation(Id0, _, _, _),
109 Id) :-
110 method_from_id(Id0, SG),
111 atom_from_method(SG, Id).
118user:prolog_clause_name(Ref, Name) :-
119 clause(Head, _, Ref),
120 user:prolog_predicate_name(Head, Name).
121
122
123 126
129
130method_from_id(Id, Method) :-
131 compound(Id),
132 !,
133 arg(1, Id, Id2),
134 method_from_id(Id2, Method).
135method_from_id(Id, ->(Class, Selector)) :-
136 pce_principal:pce_lazy_send_method(Selector, Class, Binder),
137 arg(1, Binder, Id),
138 !.
139method_from_id(Id, <-(Class, Selector)) :-
140 pce_principal:pce_lazy_get_method(Selector, Class, Binder),
141 arg(1, Binder, Id).
142
143atom_from_method(->(Class, Selector), Atom) :-
144 atomic_list_concat([Class, (->), Selector], Atom).
145atom_from_method(<-(Class, Selector), Atom) :-
146 atomic_list_concat([Class, (<-), Selector], Atom)