2017-12-09 17:01:40 +00:00
|
|
|
;;; The Geesh Shell Interpreter
|
2018-07-17 18:40:30 +01:00
|
|
|
;;; Copyright 2017, 2018 Timothy Sample <samplet@ngyro.com>
|
2017-12-09 17:01:40 +00:00
|
|
|
;;;
|
|
|
|
;;; This file is part of Geesh.
|
|
|
|
;;;
|
|
|
|
;;; Geesh 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.
|
|
|
|
;;;
|
|
|
|
;;; Geesh 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 Geesh. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
(define-module (geesh repl)
|
2018-07-17 18:40:30 +01:00
|
|
|
#:use-module (geesh environment)
|
|
|
|
#:use-module (geesh eval)
|
|
|
|
#:use-module (geesh parser)
|
2017-12-09 17:01:40 +00:00
|
|
|
#:use-module (ice-9 rdelim)
|
|
|
|
#:export (run-repl))
|
|
|
|
|
|
|
|
;;; Commentary:
|
|
|
|
;;;
|
|
|
|
;;; The read-eval-print loop (REPL) of the shell.
|
|
|
|
;;;
|
|
|
|
;;; Code:
|
|
|
|
|
|
|
|
(define (run-repl)
|
2018-07-18 04:31:29 +01:00
|
|
|
(let loop ((env (make-environment (environ->alist (environ))))
|
2018-07-17 18:40:30 +01:00
|
|
|
(exp (read-sh (current-input-port))))
|
2018-10-17 00:58:15 +01:00
|
|
|
(if (eof-object? exp)
|
Add 'status' field to environment
Instead of using an environment variable named '?', we will use a
special environment field called 'status'. This lets us get rid of a
lot of number-string conversions (since an environment variable has to
have a string value).
* geesh/environment.scm (<environment>): Add a 'status' field.
(make-environment): Set it to 0 by default.
* geesh/repl.scm (run-repl): Use new field in place of '?' variable.
* geesh/shell.scm (exec-utility, sh:and, sh:exec-let, sh:for, sh:not,
sh:or, sh:pipeline, sh:subshell, sh:substitute-command): Ditto.
* geesh/word.scm (parameter-ref): New function that handles both
special parameters (e.g., '?') and variables.
(parameter-ref*): Like 'var-ref*', but for 'parameter-ref'.
(word->qword): Replace 'var-ref' and 'var-ref*' with 'parameter-ref'
and 'parameter-ref*' respectively.
2018-11-09 02:29:19 +00:00
|
|
|
(environment-status env)
|
2018-10-17 00:58:15 +01:00
|
|
|
(begin
|
|
|
|
(eval-sh env exp)
|
|
|
|
(loop env (read-sh (current-input-port)))))))
|