summaryrefslogtreecommitdiff
path: root/chickadee
diff options
context:
space:
mode:
authorDavid Thompson <dthompson2@worcester.edu>2017-10-14 21:42:15 -0400
committerDavid Thompson <dthompson2@worcester.edu>2017-10-14 21:42:15 -0400
commit88534f7472b8171304fc1da4ae0aef58c2a52708 (patch)
treecc392b8f538f37f20573ef18b9d2835594654bc1 /chickadee
parente659085e675c331bfbd43c85c101af21978145b4 (diff)
scripting: Rename coroutine to script.
* chickadee/scripting/coroutine.scm: Move to... * chickadee/scripting/script.scm: ...here, and s/coroutine/script. * chickadee/scripting/channel.scm (channel-get, channel-put): Update docstring to say "script" instead of "coroutine". * chickadee/scripting.scm: s/coroutine/script/ * Makefile.am (SOURCES): Replace coroutine.scm with script.scm. * doc/api.texi: s/coroutine/script/
Diffstat (limited to 'chickadee')
-rw-r--r--chickadee/scripting.scm10
-rw-r--r--chickadee/scripting/channel.scm10
-rw-r--r--chickadee/scripting/coroutine.scm90
-rw-r--r--chickadee/scripting/script.scm90
4 files changed, 100 insertions, 100 deletions
diff --git a/chickadee/scripting.scm b/chickadee/scripting.scm
index 0e29fa6..d88e422 100644
--- a/chickadee/scripting.scm
+++ b/chickadee/scripting.scm
@@ -20,7 +20,7 @@
#:use-module (chickadee math easings)
#:use-module (chickadee scripting agenda)
#:use-module (chickadee scripting channel)
- #:use-module (chickadee scripting coroutine)
+ #:use-module (chickadee scripting script)
#:export (forever
sleep
tween)
@@ -30,7 +30,7 @@
(eval-when (eval load compile)
(begin
(define %public-modules
- '(agenda channel coroutine))
+ '(agenda channel script))
(for-each (let ((i (module-public-interface (current-module))))
(lambda (m)
(module-use! i (resolve-interface
@@ -42,9 +42,9 @@
(while #t body ...))
(define (sleep duration)
- "Wait DURATION before resuming the current coroutine."
- ;; Capture the current agenda before suspending the coroutine so
- ;; that we schedule the continuation in the right place.
+ "Wait DURATION before resuming the current script."
+ ;; Capture the current agenda before suspending the script so that
+ ;; we schedule the continuation in the right place.
(let ((agenda (current-agenda)))
(yield
(lambda (cont)
diff --git a/chickadee/scripting/channel.scm b/chickadee/scripting/channel.scm
index 0c78ffa..9402636 100644
--- a/chickadee/scripting/channel.scm
+++ b/chickadee/scripting/channel.scm
@@ -22,7 +22,7 @@
#:use-module (srfi srfi-9 gnu)
#:use-module (srfi srfi-11)
#:use-module (chickadee queue)
- #:use-module (chickadee scripting coroutine)
+ #:use-module (chickadee scripting script)
#:export (make-channel
channel?
channel-get
@@ -58,16 +58,16 @@
(put-cont)))))))
(define (channel-get channel)
- "Retrieve a value from CHANNEL. The current coroutine suspends
-until a value is available."
+ "Retrieve a value from CHANNEL. The current script suspends until a
+value is available."
(yield
(lambda (cont)
(enqueue! (channel-get-queue channel) cont)
(maybe-deliver channel))))
(define (channel-put channel data)
- "Send DATA to CHANNEL. The current coroutine suspends until another
-coroutine is available to retrieve the value."
+ "Send DATA to CHANNEL. The current script suspends until another
+script is available to retrieve the value."
(yield
(lambda (cont)
(enqueue! (channel-put-queue channel) (cons data cont))
diff --git a/chickadee/scripting/coroutine.scm b/chickadee/scripting/coroutine.scm
deleted file mode 100644
index 642ff83..0000000
--- a/chickadee/scripting/coroutine.scm
+++ /dev/null
@@ -1,90 +0,0 @@
-;;; Chickadee Game Toolkit
-;;; Copyright © 2017 David Thompson <davet@gnu.org>
-;;;
-;;; Chickadee is free software: you can redistribute it and/or modify
-;;; it under the terms of the GNU General Public License as published
-;;; by the Free Software Foundation, either version 3 of the License,
-;;; or (at your option) any later version.
-;;;
-;;; Chickadee is distributed in the hope that it will be useful, but
-;;; WITHOUT ANY WARRANTY; without even the implied warranty of
-;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-;;; General Public License for more details.
-;;;
-;;; You should have received a copy of the GNU General Public License
-;;; along with this program. If not, see
-;;; <http://www.gnu.org/licenses/>.
-
-(define-module (chickadee scripting coroutine)
- #:use-module (ice-9 format)
- #:use-module (srfi srfi-9)
- #:use-module (srfi srfi-9 gnu)
- #:export (coroutine?
- coroutine-cancelled?
- coroutine-running?
- coroutine-complete?
- spawn-coroutine
- coroutine
- cancel-coroutine
- yield)
- #:replace (yield))
-
-(define-record-type <coroutine>
- (make-coroutine status)
- coroutine?
- (status coroutine-status set-coroutine-status!))
-
-(define (display-coroutine co port)
- (format port "<coroutine status: ~a>" (coroutine-status co)))
-
-(set-record-type-printer! <coroutine> display-coroutine)
-
-(define (coroutine-cancelled? co)
- "Return #t if CO has been cancelled."
- (eq? 'cancelled (coroutine-status co)))
-
-(define (coroutine-running? co)
- "Return #t if CO has not yet terminated or been cancelled."
- (eq? 'cancelled (coroutine-status co)))
-
-(define (coroutine-complete? co)
- "Return #t if CO has terminated."
- (eq? 'cancelled (coroutine-status co)))
-
-(define (cancel-coroutine co)
- "Prevent further execution of CO."
- (set-coroutine-status! co 'cancelled)
- *unspecified*)
-
-(define coroutine-prompt (make-prompt-tag 'coroutine))
-
-(define (spawn-coroutine thunk)
- "Apply THUNK as a coroutine."
- (let ((co (make-coroutine 'running)))
- (define (handler cont callback . args)
- (define (resume . args)
- ;; Call continuation that resumes the procedure, unless, of
- ;; course, the coroutine has been cancelled in the meantime.
- (unless (coroutine-cancelled? co)
- (call-with-prompt coroutine-prompt
- (lambda () (apply cont args))
- handler)))
- (when (procedure? callback)
- (apply callback resume args)))
- (define task
- (let ((dynamic-state (current-dynamic-state)))
- (lambda ()
- (with-dynamic-state dynamic-state thunk)
- (set-coroutine-status! co 'complete))))
- ;; Start the coroutine.
- (call-with-prompt coroutine-prompt task handler)
- co))
-
-(define-syntax-rule (coroutine body ...)
- "Evaluate BODY in a coroutine."
- (spawn-coroutine (lambda () body ...)))
-
-(define (yield handler)
- "Suspend the current coroutine and pass its continuation to the
-procedure HANDLER."
- (abort-to-prompt coroutine-prompt handler))
diff --git a/chickadee/scripting/script.scm b/chickadee/scripting/script.scm
new file mode 100644
index 0000000..df2d6bb
--- /dev/null
+++ b/chickadee/scripting/script.scm
@@ -0,0 +1,90 @@
+;;; Chickadee Game Toolkit
+;;; Copyright © 2017 David Thompson <davet@gnu.org>
+;;;
+;;; Chickadee is free software: you can redistribute it and/or modify
+;;; it under the terms of the GNU General Public License as published
+;;; by the Free Software Foundation, either version 3 of the License,
+;;; or (at your option) any later version.
+;;;
+;;; Chickadee is distributed in the hope that it will be useful, but
+;;; WITHOUT ANY WARRANTY; without even the implied warranty of
+;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+;;; General Public License for more details.
+;;;
+;;; You should have received a copy of the GNU General Public License
+;;; along with this program. If not, see
+;;; <http://www.gnu.org/licenses/>.
+
+(define-module (chickadee scripting script)
+ #:use-module (ice-9 format)
+ #:use-module (srfi srfi-9)
+ #:use-module (srfi srfi-9 gnu)
+ #:export (script?
+ script-cancelled?
+ script-running?
+ script-complete?
+ spawn-script
+ script
+ cancel-script
+ yield)
+ #:replace (yield))
+
+(define-record-type <script>
+ (make-script status)
+ script?
+ (status script-status set-script-status!))
+
+(define (display-script script port)
+ (format port "<script status: ~a>" (script-status script)))
+
+(set-record-type-printer! <script> display-script)
+
+(define (script-cancelled? script)
+ "Return #t if SCRIPT has been cancelled."
+ (eq? 'cancelled (script-status script)))
+
+(define (script-running? script)
+ "Return #t if SCRIPT has not yet terminated or been cancelled."
+ (eq? 'cancelled (script-status script)))
+
+(define (script-complete? script)
+ "Return #t if SCRIPT has terminated."
+ (eq? 'cancelled (script-status script)))
+
+(define (cancel-script script)
+ "Prevent further execution of SCRIPT."
+ (set-script-status! script 'cancelled)
+ *unspecified*)
+
+(define script-prompt (make-prompt-tag 'script))
+
+(define (spawn-script thunk)
+ "Apply THUNK as a script."
+ (let ((script (make-script 'running)))
+ (define (handler cont callback . args)
+ (define (resume . args)
+ ;; Call continuation that resumes the procedure, unless, of
+ ;; course, the script has been cancelled in the meantime.
+ (unless (script-cancelled? script)
+ (call-with-prompt script-prompt
+ (lambda () (apply cont args))
+ handler)))
+ (when (procedure? callback)
+ (apply callback resume args)))
+ (define task
+ (let ((dynamic-state (current-dynamic-state)))
+ (lambda ()
+ (with-dynamic-state dynamic-state thunk)
+ (set-script-status! script 'complete))))
+ ;; Start the script.
+ (call-with-prompt script-prompt task handler)
+ script))
+
+(define-syntax-rule (script body ...)
+ "Evaluate BODY in a script."
+ (spawn-script (lambda () body ...)))
+
+(define (yield handler)
+ "Suspend the current script and pass its continuation to the
+procedure HANDLER."
+ (abort-to-prompt script-prompt handler))