YAP 7.1.0
save.yap
Go to the documentation of this file.
1 /*************************************************************************
2 * *
3 * YAP Prolog *
4 * *
5 * Yap Prolog was developed at NCCUP - Universidade do Porto *
6 * *
7 * Copyright L.Damas, V.S.Costa and Universidade do Porto 1985-2010 *
8 * *
9 **************************************************************************
10 * *
11 * File: save.yap *
12 * Last rev: 11/29/10 *
13 * mods: *
14 * comments: Some utility predicates to support save/restore in yap *
15 * *
16 *************************************************************************/
17
18/**
19 * @file save.yap
20 * @author VITOR SANTOS COSTA <vsc@VITORs-MBP-2.lan>
21 * @date Thu Oct 19 12:10:47 2017
22 *
23 * @brief Old Style save
24 *
25 * @addtòxgroup QLY
26 *
27*/
28
29:- system_module( '$_save', [], []).
30
31%%% Saving and restoring a computation
32/*
33save(A) :- save(A,_).
34
35save(A,_) :- var(A), !,
36 '$do_error'(instantiation_error,save(A)).
37save(A,OUT) :- atom(A), !, atom_codes(A,S), '$save'(S,OUT).
38save(S,OUT) :- '$save'(S,OUT).
39
40save_program(A) :- var(A), !,
41 '$do_error'(instantiation_error,save_program(A)).
42save_program(A) :- atom(A), !,
43 atom_codes(A,S),
44 '$save_program2'(S, true).
45save_program(S) :- '$save_program2'(S, true).
46
47save_program(A, G) :- var(A), !,
48 '$do_error'(instantiation_error, save_program(A,G)).
49save_program(A, G) :- var(G), !,
50 '$do_error'(instantiation_error, save_program(A,G)).
51save_program(A, G) :- \+ must_be_callable(G), !,
52 '$do_error'(type_error(callable,G), save_program(A,G)).
53save_program(A, G) :-
54 ( atom(A) -> atom_codes(A,S) ; A = S),
55 '$save_program2'(S, G),
56 fail.
57save_program(_,_).
58
59'$save_program2'(S,G) :-
60 (
61 G == true
62 ->
63 true
64 ;
65 recorda('$restore_goal', G ,R)
66 ),
67 (
68 '$undefined'(reload_foreign_libraries, shlib)
69 ->
70 true
71 ;
72 recorda('$reload_foreign_libraries', true, R1)
73 ),
74 '$save_program'(S),
75 (
76 var(R1)
77 ->
78 true
79 ;
80 erase(R1)
81 ),
82 (
83 var(R)
84 ->
85 true
86 ;
87 erase(R)
88 ),
89 fail.
90'$save_program2'(_,_).
91
92restore(A) :- var(A), !,
93 '$do_error'(instantiation_error,restore(A)).
94restore(A) :- atom(A), !, name(A,S), '$restore'(S).
95restore(S) :- '$restore'(S).
96
97*/
98