refactoring

parent e03f710d
......@@ -115,6 +115,7 @@ PSSOURCES = \
language/prolog/modules/sandbox.pl \
language/prolog/modules/boot/expand.pl \
language/prolog/modules/boot/dcg.pl \
language/prolog/modules/boot/if.pl \
language/prolog/modules/swi/term_macro.pl \
language/prolog/modules/library/error.pl \
language/prolog/modules/library/vhash.scm \
......
......@@ -19,6 +19,7 @@
(#:boot (language prolog modules sandbox))
(#:boot (language prolog modules boot expand))
(#:boot (language prolog modules boot dcg))
(#:boot (language prolog modules boot if))
(#:boot (language prolog modules library error))
(#:boot (language prolog modules library pairs))
(#:boot (language prolog modules library lists))
......
:- module(if,
[fast_compile/1,
eval/1,
term(compile),
if/1,
else/0,
elseif/1,
endif/0,
term(ifmacro)
]).
%%
:- dynamic(fast_compile/1).
nocolon(:) :- !, fail.
nocolon(_).
compile((:- eval(X) ), []) :- X.
compile((:- fast_compile(X)), []) :-
X=="true" ->
asserta((fast_compile(true) :- !));
X=="false" ->
asserta((fast_compile(true) :- !, fail));
asserta((fast_compile(X) :- !)).
compile((:- X), _) :- !,fail.
compile((? X), _) :- !,fail.
compile((- X), _) :- !,fail.
compile((X :- Y),[X :- Y]) :- !,
X =.. [F|_], nocolon(F), (fast_compile(true) ; fast_compile(F)),!,write(did1(F)),nl.
compile(X,[X]) :-
X =.. [F|_], nocolon(F), (fast_compile(true) ; fast_compile(F)),!,write(did2(F)),nl.
%% This is the dynamic.
:- dynamic(doif/0).
doif(1).
ifmacro((:- if(Code)),[]) :- !,
Code -> asserta(doif(1)) ; asserta(doif(0)).
ifmacro((:- endif), []) :- !,
asserta(doif(1)).
ifmacro((:- elseif(Code)), []) :- !,
Code -> asserta(doif(1)) ; asserta(doif(0)).
ifmacro((:- else), []) :- !,
(doif(X),!,X==1) -> asserta(doif(0)) ; asserta(doif(1)).
ifmacro(X,[Y]) :-
(doif(Z),!,Z==1) -> fail ; Y=[].
......@@ -162,6 +162,8 @@
:- op(700, xfx, cis_leq).
:- op(700, xfx, cis_lt).
:- fast_compile(true).
/** <module> Constraint Logic Programming over Finite Domains
### Introduction {#clpfd-intro}
......
:- module(term_macro,
[
if/1,
else/0,
elseif/1,
endif/0,
term(ifmacro),
term(attr_macro),
term(term_macro),
term(goal_macro),
term(directives),
% term(doall),
goal(goalex)
]).
[term(attr_macro),
term(term_macro),
term(goal_macro),
term(directives),
goal(goalex)
]).
/*
To get swi prolog attribute functionality we can use the following
......@@ -37,25 +30,6 @@ doall(A,[A]) :- \+ A =..[(_ : _) | _], \+ A=(_ : _).
directives((:- "fast_compile"),[]) :-
do[((@ (guile) set!) (@@ (logic guile-log prolog base) *eval-only*) #t)].
:- dynamic(doif/0).
doif(1).
ifmacro((:- if(Code)),[]) :- !,
Code -> asserta(doif(1)) ; asserta(doif(0)).
ifmacro((:- endif), []) :- !,
asserta(doif(1)).
ifmacro((:- elseif(Code)), []) :- !,
Code -> asserta(doif(1)) ; asserta(doif(0)).
ifmacro((:- else), []) :- !,
(doif(X),!,X==1) -> asserta(doif(0)) ; asserta(doif(1)).
ifmacro(X,[Y]) :-
(doif(Z),!,Z==1) -> fail ; Y=[].
mname(X) :- module_name(N), X@@! = N.
......
......@@ -18,6 +18,9 @@
(define (default-extensions)
(list prolog-and 'and prolog-or 'or prolog-not 'not prolog=.. '=..))
(define (simplify x)
(datum->syntax #'simple-stx (syntax->datum x)))
(define do-print #f)
(define pp
(case-lambda
......@@ -694,6 +697,7 @@
(lambda (f)
(lam f)))
(if source?
(simplify
#`(let ()
(define-syntax f
(syntax-rules ()
......@@ -710,7 +714,7 @@
ffkn)
(map (lambda (x) #'((@ (logic guile-log umatch)
gp-make-var)))
(append vars ovars)))))
(append vars ovars))))))
(apply lam
(append ffkn (map (lambda (x) (gp-make-var))
......@@ -718,3 +722,4 @@
(set! (@@ (logic guile-log match) compile-prolog) compile-prolog)
......@@ -195,12 +195,12 @@
*prolog-dynamic-modularation*
'()))~%")
(if (not boot?)
(format #t
"
(compile-prolog-string
\"
:- use_module(boot(if)).
:- use_module(boot(dcg)).
:- use_module(sandbox).
:- use_module(user).
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment