state handling commands in the interpreter added

parent 369b5f88
......@@ -71,6 +71,7 @@ SOURCES = \
logic/guile-log/guile-prolog/readline.scm \
logic/guile-log/guile-prolog/fluid.scm \
logic/guile-log/guile-prolog/interpreter.scm \
logic/guile-log/guile-prolog/state.scm \
language/prolog/spec.scm
AM_MAKEINFOFLAGS=--force
......
(define-module (logic guile-log guile-prolog interpreter)
#:use-module ((logic guile-log) #:select
(<clear> <define> <let> <let*> <=> <lookup> <match> <fail>
<cut> <wrap>))
<cut> <wrap> <state-ref> <state-set!> <continue>))
#:use-module (logic guile-log guile-prolog hash)
#:use-module (logic guile-log guile-prolog fluid)
#:use-module (ice-9 match)
......@@ -53,12 +53,16 @@
(define -n- (@ (logic guile-log guile-prolog readline)
-n-))
(define *states* (make-hash-table))
(define (read-prolog port env)
(define all? #f)
(define fail? #f)
(define mute? #f)
(define n? #f)
(define help? #f)
(define save #f)
(define load #f)
(define cont #f)
(let* ((l
(with-input-from-port port
(lambda ()
......@@ -83,11 +87,18 @@
((all *) (set! all? #t))
((once) (set! n? 1))
((h help) (set! help? #t))
((s save) (set! save ((@ (guile) read))))
((l load) (set! load ((@ (guile) read))))
((c cont) (set! cont #t))
(else
(set! fail? #t))))
(if (or fail? help?)
#f
(lp #t (peek-char) '())))
(cond
((or fail? help?)
#f)
((or load save cont)
#t)
(else
(lp #t (peek-char) '()))))
(list->string (reverse (cons #\. r)))))
(#\,
......@@ -108,18 +119,41 @@
(lp #f (peek-char) (cons ch r)))))))))
(cond
(load
`((@ (guile) begin)
((@ (logic guile-log) <state-set!>)
((@ (guile) hash-ref) (@@ (logic guile-log guile-prolog interpreter)
*states*)
',load))
((@ (guile) if) #f #f)))
(save
`((@ (guile) begin)
((@ (guile) hash-set!)
(@@ (logic guile-log guile-prolog interpreter) *states*)
',save
((@ (logic guile-log) <state-ref>)))
((@ (guile) if) #f #f)))
(cont
`((@ (logic guile-log) <continue>)))
(fail?
'(begin
'((@ (guile) begin)
((@ (guile) format) #t "wrong-input of '.' action ~%")
(if #f #f)))
((@ (guile) if) #f #f)))
(help?
(format #t "
HELP FOR PROLOG COMMANDS
.n try to find n solutions
.all .* try to find all solutions
.once .1 try to find one solution
.mute .m no value output is written.
(.n ) try to find n solutions
(.all | .*) try to find all solutions
(.once | .1) try to find one solution
(.mute | .m) no value output is written.
(.save | .s) <ref> associate current state with ref
(.load | .l) <ref> restore associate state with ref
(.cont | .c) continue the execution from last stall point
")
'(if #f #f))
......@@ -133,26 +167,20 @@ HELP FOR PROLOG COMMANDS
(lambda ()
((@@ (system repl command) meta-command) repl)))
(set! str "do[#f]"))
`(let ((fr ((@ (logic guile-log umatch) gp-newframe)
((@ (guile) fluid-ref)
(@ (logic guile-log umatch) *current-stack*)))))
((@ (guile) dynamic-wind)
((@ (guile) lambda) () #f)
((@ (guile) lambda) ()
((@@ (logic guile-log iso-prolog) prolog-run) 1 ()
((@@ (logic guile-log guile-prolog interpreter)
conversation1)
,str
,((@ (guile) cond)
(all? '(@ (logic guile-log iso-prolog) true))
(n? n?)
(else
'(@ (logic guile-log iso-prolog) false)))
,(if mute?
'(@ (logic guile-log iso-prolog) true)
'(@ (logic guile-log iso-prolog) false)))))
((@ (guile) lambda) ()
((@ (logic guile-log umatch) gp-unwind) fr)))
`(let ()
((@ (logic guile-log) <clear>))
((@@ (logic guile-log iso-prolog) prolog-run) 1 ()
((@@ (logic guile-log guile-prolog interpreter)
conversation1)
,str
,((@ (guile) cond)
(all? '(@ (logic guile-log iso-prolog) true))
(n? n?)
(else
'(@ (logic guile-log iso-prolog) false)))
,(if mute?
'(@ (logic guile-log iso-prolog) true)
'(@ (logic guile-log iso-prolog) false))))
(if #f #f))))
(else
l))))
......@@ -204,7 +232,7 @@ conversation_ :-
scm[-all-],
(
do[ (fluid-set! -all- false) ],
nl,read_term(T,[variables(V),variable_names(N)]),
nl,readline_term(T,[variables(V),variable_names(N)]),
consult(T,V,N,false,false)
)
)
......
(define-module (logic guile-log guile-prolog state)
#:use-module (logic guile-log)
#:export (stall))
#|
state handling e.g. be able to store a state entering a repl, as well
as storing a state.
|#
store(a)
restore(a)
new_interpreter
goto_interpreter
current_interpretter
(define stall <stall>)
......
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