15:- module(dasm, []). 16
18
20f_disassemble(function(Symbol),Options, Code):- !, f_disassemble(Symbol,Options, Code).
21f_disassemble([quote,Symbol], Options,Code):- !, f_disassemble(Symbol, Options,Code).
22f_disassemble(StringL,Options,Code):- \+ string(StringL),is_stringp(StringL),to_prolog_string_if_needed(StringL,String),!,f_disassemble(String,Options,Code).
23f_disassemble(Function,_Options, Prolog):-
24 writeln('#| DISASSEMBLY FOR':Function),
25 make_holder(Holder),
26 print_related_clauses(Holder,_Module,Function),
27 nb_holder_value(Holder,ListOut),
28 Prolog = '$OBJ'(claz_prolog,ListOut),
29 nop(ListOut==[]-> xlisting(Function) ; true),
30 writeln('|#').
31
32
33clauses_related(M,Obj,H,B,PrintKeyRef):- nonvar(Obj), get_opv(Obj,symbol_function,Obj2),clauses_related(M,Obj2,H,B,PrintKeyRef).
35clauses_related(_,P,H,B,PrintKeyRef):-
36 H= wl:lambda_def(_DefType,H1,H2,_Args,_Body),
37 clause_interface(H,B,PrintKeyRef),
38 (related_functor(P,H1);related_functor(P,H2)).
39clauses_related(_,P,H,B,PrintKeyRef):-
40 H= wl:arglist_info(H1,H2,_,_),
41 clause_interface(H,B,PrintKeyRef),
42 (related_functor(P,H1);related_functor(P,H2)).
43clauses_related(_,P,H,B,PrintKeyRef):-
44 H= wl:init_args(_,H1),
45 clause_interface(H,B,PrintKeyRef),
46 (related_functor(P,H1)).
47clauses_related(Module,P,Module:H,B,PrintKeyRef):-
48 current_module(Module),
49 current_predicate(_,Module:H),
50 \+ predicate_property(Module:H,imported_from(_)),
51 \+ predicate_property(Module:H,foreign),
52 clause_interface(Module:H,B,PrintKeyRef),
53 related_functor(P,H).
54
55
56related_functor(P,Q):- to_related_functor(P,PP),to_related_functor(Q,QQ),QQ=PP,!.
58to_related_functor(P,PP):- string(P),atom_string(A,P),!,to_related_functor(A,PP).
59to_related_functor(P,PP):- \+ compound(P),!,to_related_functor_each(P,PP).
60to_related_functor(P,PP):- compound_name_arguments(P,F,[A,B,C|_]),!,
61 (to_related_functor_each(F,PP);to_related_functor(A,PP);to_related_functor(B,PP);to_related_functor(C,PP)).
62to_related_functor(P,PP):- compound_name_arguments(P,F,[]),!,(to_related_functor_each(F,PP)).
63to_related_functor(P,PP):- compound_name_arguments(P,F,[A]),!,(to_related_functor_each(F,PP);to_related_functor(A,PP)).
64to_related_functor(P,PP):- compound_name_arguments(P,F,[A,B]),!,(to_related_functor_each(F,PP);to_related_functor(A,PP);to_related_functor(B,PP)).
65
66
67
68to_related_functor_each(P,_):- \+ atom(P),!,fail.
69to_related_functor_each(P,PP):- to_related_functor_each1(P,PP).
70to_related_functor_each(P,PP):- to_related_functor_each1(P,PPP),to_related_functor_each0(PPP,PP).
71
72to_related_functor_each1(P,P).
73to_related_functor_each1(P,PP):- downcase_atom(P,PP),PP\==P.
74
75to_related_functor_each0(P,PP):-atom_concat('f_',PP,P).
76to_related_functor_each0(P,PP):-atom_concat('u_',PP,P).
77to_related_functor_each0(P,PP):-atom_concat('mf_',PP,P).
78
79print_related_clauses(ExceptFor,_OModule,P):-
80 ignore((
81 no_repeats(clauses_related(_Module,P,H,B,PrintKeyRef)),
82 PC = (H :- B),
83 nb_holder_value(ExceptFor,Printed),
84 \+ member(PrintKeyRef,Printed),
85 nb_holder_append(ExceptFor,PrintKeyRef),
86 once(print_clause_plain(PC)),
87 fail)).
88
89print_clause_plain(I):-
90 (current_prolog_flag(color_term, Was);Was=[]),!,
91 make_pretty(I,O),
92 setup_call_cleanup(set_prolog_flag(color_term, false),
93 (nl,lcolormsg1((O))),
94 set_prolog_flag(color_term, Was)).
95
96
97lcolormsg1(Msg):- mesg_color(Msg,Ctrl),!,ansicall_maybe(Ctrl,fmt9(Msg)).
98
100
101
102
103make_pretty(I,O):- !,call_each(must_or_rtrace,(shrink_lisp_strings(I,M), pretty_numbervars(M,O))).
106
109
110
111
112
174:- fixup_exports.