From 88534f7472b8171304fc1da4ae0aef58c2a52708 Mon Sep 17 00:00:00 2001 From: David Thompson Date: Sat, 14 Oct 2017 21:42:15 -0400 Subject: 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/ --- Makefile.am | 2 +- chickadee/scripting.scm | 10 ++-- chickadee/scripting/channel.scm | 10 ++-- chickadee/scripting/coroutine.scm | 90 ------------------------------------ chickadee/scripting/script.scm | 90 ++++++++++++++++++++++++++++++++++++ doc/api.texi | 96 +++++++++++++++++++-------------------- 6 files changed, 148 insertions(+), 150 deletions(-) delete mode 100644 chickadee/scripting/coroutine.scm create mode 100644 chickadee/scripting/script.scm diff --git a/Makefile.am b/Makefile.am index e80bb90..de01b08 100644 --- a/Makefile.am +++ b/Makefile.am @@ -71,7 +71,7 @@ SOURCES = \ chickadee/render.scm \ chickadee/window.scm \ chickadee/scripting/agenda.scm \ - chickadee/scripting/coroutine.scm \ + chickadee/scripting/script.scm \ chickadee/scripting/channel.scm \ chickadee/scripting.scm \ chickadee.scm \ 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 -;;; -;;; 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 -;;; . - -(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 - (make-coroutine status) - coroutine? - (status coroutine-status set-coroutine-status!)) - -(define (display-coroutine co port) - (format port "" (coroutine-status co))) - -(set-record-type-printer! 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 +;;; +;;; 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 +;;; . + +(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