sweep_op_info/2,
sweep_imenu_index/2,
sweep_module_path/2,
+ sweep_thread_signal/2,
sweep_top_level_server/2,
sweep_top_level_threads/2,
sweep_accept_top_level_client/2,
thread_property(Self, id(Id)),
retractall(sweep_top_level_thread_buffer(Id, _)).
+%! sweep_accept_top_level_client(+Buffer, -Result) is det.
+%
+% Signal the top-level server thread to accept a new TCP connection
+% from buffer Buffer.
+
sweep_accept_top_level_client(Buffer, _) :-
thread_send_message(sweep_top_level_server, accept(Buffer)).
+
+sweep_thread_signal([ThreadId|Goal0], _) :-
+ term_string(Goal, Goal0),
+ thread_signal(ThreadId, Goal).
(comint-send-input)))))
(defvar-local sweeprolog-top-level-timer nil "Buffer-local timer.")
+(defvar-local sweeprolog-top-level-thread-id nil
+ "Prolog top-level thread ID corresponding to this buffer.")
+
+(defun sweeprolog-top-level--populate-thread-id ()
+ (sweeprolog-open-query "user"
+ "sweep"
+ "sweep_top_level_thread_buffer"
+ (buffer-name)
+ t)
+ (let ((sol (sweeprolog-next-solution)))
+ (sweeprolog-close-query)
+ (when (sweeprolog-true-p sol)
+ (setq sweeprolog-top-level-thread-id (cdr sol)))))
+
+(defun sweeprolog-signal-thread (tid goal)
+ (sweeprolog-open-query "user"
+ "sweep"
+ "sweep_thread_signal"
+ (cons tid goal))
+ (let ((sol (sweeprolog-next-solution)))
+ (sweeprolog-close-query)
+ sol))
+
+(defun sweeprolog-top-level-signal (buffer goal)
+ "Signal the top-level thread corresponding to BUFFER to run GOAL."
+ (interactive
+ (list (read-buffer "Top-level buffer: "
+ nil t
+ (lambda (b)
+ (let ((bb (or (and (consp b) (car b)) b)))
+ (with-current-buffer bb
+ (and (derived-mode-p 'sweeprolog-top-level-mode)
+ sweeprolog-top-level-thread-id)))
+ (eq 'sweeprolog-top-level-mode
+ (buffer-local-value 'major-mode b))))
+ (read-string "Signal goal: ?- ")))
+ (sweeprolog-signal-thread (buffer-local-value 'sweeprolog-top-level-thread-id
+ buffer)
+ goal))
;;;###autoload
(define-derived-mode sweeprolog-top-level-mode comint-mode "sweep Top-level"
(length s)))
comint-delimiter-argument-list '(?,)
comment-start "%")
+ (add-hook 'comint-exec-hook #'sweeprolog-top-level--populate-thread-id nil t)
(add-hook 'post-self-insert-hook #'sweeprolog-top-level--post-self-insert-function nil t)
(setq sweeprolog-buffer-module "user")
(add-hook 'completion-at-point-functions #'sweeprolog-completion-at-point-function nil t)
(setq sweeprolog-top-level-timer (run-with-idle-timer 0.2 t #'sweeprolog-colourise-query (current-buffer)))
+ (add-hook 'kill-buffer-hook
+ (lambda ()
+ (sweeprolog-top-level-signal (current-buffer)
+ "thread_exit(0)"))
+ nil t)
(add-hook 'kill-buffer-hook
(lambda ()
(when (timerp sweeprolog-top-level-timer)
- (cancel-timer sweeprolog-top-level-timer)))))
+ (cancel-timer sweeprolog-top-level-timer)))
+ nil t))
(sweeprolog--ensure-module)
(when sweeprolog-init-on-load (sweeprolog-init))