summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArne Babenhauserheide <arne_bab@web.de>2022-10-08 00:03:38 +0200
committerDavid Thompson <dthompson2@worcester.edu>2022-10-08 06:50:07 -0400
commit1578a7025c3c70cbbdb110aa42125c9acb57aeda (patch)
tree3a6efad5603151d8d22957293aa3f9e089395439
parentfbdb3e2983bfbbd2b277e1a3587f663545d6aea3 (diff)
Allow 'chickadee play' to use languages other than Scheme.
-rw-r--r--chickadee/cli/play.scm44
-rw-r--r--doc/chickadee.texi32
2 files changed, 65 insertions, 11 deletions
diff --git a/chickadee/cli/play.scm b/chickadee/cli/play.scm
index 7bbdb35..7745008 100644
--- a/chickadee/cli/play.scm
+++ b/chickadee/cli/play.scm
@@ -26,6 +26,7 @@
#:use-module (srfi srfi-1)
#:use-module (srfi srfi-9)
#:use-module (srfi srfi-37)
+ #:use-module (system base compile)
#:use-module (system repl command)
#:use-module (system repl debug)
#:use-module (system repl coop-server)
@@ -54,6 +55,10 @@ Play the game defined in FILE.~%")
--repl start REPL in this terminal")
(display "
--repl-server=[PORT] start REPL server on PORT or 37146 by default")
+ (display "
+ --language=LANG change language; default: scheme")
+ (display "
+ -x EXTENSION add EXTENSION to the front of the load extensions")
(newline)
(exit 1))
@@ -88,7 +93,13 @@ Play the game defined in FILE.~%")
(if arg
(string->number arg)
37146)
- result)))))
+ result)))
+ (option '("language") #t #f
+ (lambda (opt name arg result)
+ (alist-cons 'language (string->symbol arg) result)))
+ (option '(#\x) #t #f
+ (lambda (opt name arg result)
+ (alist-cons 'extension arg result)))))
(define %default-options
'((title . "chickadee")
@@ -97,7 +108,8 @@ Play the game defined in FILE.~%")
(fullscreen? . #f)
(resizable? . #f)
(update-hz . 60)
- (repl . #f)))
+ (repl . #f)
+ (language . scheme)))
(define %default-modules
'((chickadee)
@@ -164,15 +176,25 @@ Resume the game loop without entering a debugger."
(set-current-module module)
(chdir dir)
(add-to-load-path dir)
- (primitive-load (basename file-name))
- (let ((repl-opt (assq-ref opts 'repl)))
- (cond
- ((number? repl-opt)
- (set! repl (spawn-coop-repl-server
- (make-tcp-server-socket #:port repl-opt))))
- (repl-opt
- (set! repl (make-async-repl))
- (start-async-repl repl abort-game))))))))
+ (set! %load-extensions
+ (append (filter-map (match-lambda
+ (('extension . ext) ext)
+ (_ #f))
+ opts)
+ %load-extensions))
+ (load-compiled
+ (compile-file (basename file-name)
+ #:from (assq-ref opts 'language)
+ #:env module))
+ (parameterize ((current-language (assq-ref opts 'language)))
+ (let ((repl-opt (assq-ref opts 'repl)))
+ (cond
+ ((number? repl-opt)
+ (set! repl (spawn-coop-repl-server
+ (make-tcp-server-socket #:port repl-opt))))
+ (repl-opt
+ (set! repl (make-async-repl))
+ (start-async-repl repl abort-game)))))))))
(define (handle-error stack key args)
;; Setup the REPL debug object.
(let* ((tag (and (pair? (fluid-ref %stacks))
diff --git a/doc/chickadee.texi b/doc/chickadee.texi
index f561bae..b576641 100644
--- a/doc/chickadee.texi
+++ b/doc/chickadee.texi
@@ -278,6 +278,38 @@ Geiser} extension for Emacs is by far the best way to develop at the
REPL with Guile. Use @code{M-x connect-to-guile} to connect to the
REPL server.
+@item --language=@var{language}
+
+Process the input program using @var{language}, the identifier of a
+language within Guile's language tower. By default, unsurprisingly,
+Scheme is used.
+
+For example, to use the neat
+@url{https://www.draketo.de/software/wisp, Wisp} language as an
+alternative to Scheme's parenthetical syntax, pass
+@code{--language=wisp}. Wisp is not included with Guile and must be
+installed separately.
+
+@item -x @var{extension}
+
+Add @var{extension} to the list of file extensions that Guile will
+load.
+
+For example, Wisp files canonically use the @file{.w} extension.
+Here's what a ``hello, world'' Chickadee program looks like in Wisp:
+
+@example
+define : draw alpha
+ draw-text "Hello, world!" : vec2 260.0 240.0
+@end example
+
+Assuming the above code is saved to a @file{hello.w} file,
+@command{chickadee play} be invoked as follows:
+
+@example
+chickadee play --language=wisp -x .w hello.w
+@end example
+
@end table
@node Invoking chickadee bundle