diff options
author | Arne Babenhauserheide <arne_bab@web.de> | 2022-10-08 00:03:38 +0200 |
---|---|---|
committer | David Thompson <dthompson2@worcester.edu> | 2022-10-08 06:50:07 -0400 |
commit | 1578a7025c3c70cbbdb110aa42125c9acb57aeda (patch) | |
tree | 3a6efad5603151d8d22957293aa3f9e089395439 /chickadee | |
parent | fbdb3e2983bfbbd2b277e1a3587f663545d6aea3 (diff) |
Allow 'chickadee play' to use languages other than Scheme.
Diffstat (limited to 'chickadee')
-rw-r--r-- | chickadee/cli/play.scm | 44 |
1 files changed, 33 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)) |