Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
victorlei committed Dec 20, 2016
1 parent 2c3a146 commit a3c6dd4
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 77 deletions.
61 changes: 28 additions & 33 deletions smop/resolve.pl
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
%:- discontiguous is_def/1.
%:- discontiguous is_def/1.
%:- discontiguous shape/2.
%:- discontiguous let/2.
:- dynamic is_def/1.
:- dynamic is_ref/1.
:- dynamic is_definition/1.
:- dynamic is_reference/1.
:- dynamic resolve/1.
:- dynamic do_resolve/1.
:- dynamic lhs_resolve/1.

:- op(800,xfy, (=.)).

prog([
Expand Down Expand Up @@ -42,29 +39,27 @@
% 8. Macroexpand
% 10. parser
% 12. backend
do_resolve(A) :-
%retractall(is_def(_)),
%retractall(is_ref(_)),
resolve(A).
%listing(is_def/1),
%listing(is_ref/1).

is_unused(A) :-
is_def(A),
\+ is_ref(A).
name_ident(Name,Ident) :-
% Given a Name, create ident(Name,Addr)
% having brand new Addr.
gensym('',Atom),
atom_number(Atom,Addr),
Ident=ident(Name,Addr),
writeln(Ident).

is_arrayref(A) :-
is_def(A).
cleanupall :-
retractall(is_reference(Ident)),
retractall(is_definition(Ident)).

is_funcall(A) :-
is_ref(A),
\+ is_def.

resolve(A) :-
atom(A),
do_resolve(A) :-
resolve(A).

resolve(Name) :-
atom(Name),
!,
writeln(A),
assertz(is_ref(A)).
name_ident(Name,Ident),
assertz(is_reference(Ident)).

resolve(A) :-
number(A),
Expand All @@ -90,18 +85,15 @@
compound(A),
!,
compound_name_arguments(A,B,C),
%write("A="), writeln(A),
resolve(B),
%write("B="), writeln(B),
resolve(C),
%write("C="), writeln(C),
writeln("()").
%--------------------------------
lhs_resolve(A) :- % A=...
atom(A),

lhs_resolve(Name) :- % A=...
atom(Name),
!,
writeln(A),
assertz(is_def(A)).
name_ident(Name,Ident),
assertz(is_definition(Ident)).

%lhs_resolve(A) :-
% number(A).
Expand Down Expand Up @@ -129,4 +121,7 @@
resolve(C),
writeln("()").

has_definitions(Name,AddrList) :-
findall(Addr, is_definition(ident(Name,Addr)), AddrList).

% vim : syntax=prolog
44 changes: 0 additions & 44 deletions smop/rules.pl
Original file line number Diff line number Diff line change
Expand Up @@ -28,50 +28,6 @@
% foo([A,B...] - funcall or arrayref
% [expr1 ... exprN]
%
resolve(A) :-
atom(A),
assertz(is_ref(A)).

resolve(A) :-
number(A).

resolve(let(A,B)) :-
resolve(B),
lhs_resolve(A).

resolve(A) :-
compound(A),
compound_name_arguments(A,B,C),
resolve(B),
resolve(C).

resolve([]).
resolve([A|B]) :-
resolve(A),
resolve(B).

%-----
lhs_resolve(A) :- % A=...
atom(A),
assertz(is_def(A)).

lhs_resolve(A) :-
number(A).

%lhs_resolve(let(A,B)) :- % A=B...
% resolve(B),
% lhs_resolve(A).

lhs_resolve(A) :- % A(B)= ...
compound(A),
compound_name_arguments(A,B,C),
lhs_resolve(B),
resolve(C).

lhs_resolve([]).
lhs_resolve([A|B]) :-
lhs_resolve(A),
lhs_resolve(B).

%matlab_eval([],[]).
%matlab_eval([A|B], [C|D]) :- matlab_eval(A,C) , matlab_eval(B,D).
Expand Down

0 comments on commit a3c6dd4

Please sign in to comment.