Add the return and exit built-ins

* geesh/built-ins/return.scm: New file.
* geesh/built-ins/exit.scm: New file.
* geesh/Makefile.am: Add them.
* geesh/built-ins.scm (*special-built-ins*): Add return and exit.
This commit is contained in:
Timothy Sample 2018-12-04 16:03:38 -05:00
parent 66e89c1a05
commit 3769dce584
4 changed files with 86 additions and 2 deletions

View File

@ -49,11 +49,13 @@ MODULES = \
geesh/built-ins/echo.scm \
geesh/built-ins/eval.scm \
geesh/built-ins/exec.scm \
geesh/built-ins/exit.scm \
geesh/built-ins/export.scm \
geesh/built-ins/false.scm \
geesh/built-ins/pwd.scm \
geesh/built-ins/read.scm \
geesh/built-ins/readonly.scm \
geesh/built-ins/return.scm \
geesh/built-ins/set.scm \
geesh/built-ins/shift.scm \
geesh/built-ins/true.scm \

View File

@ -38,10 +38,10 @@
("continue" . ,(@@ (geesh built-ins continue) main))
("eval" . ,(@@ (geesh built-ins eval) main))
("exec" . ,(@@ (geesh built-ins exec) main))
("exit" . ,undefined)
("exit" . ,(@@ (geesh built-ins exit) main))
("export" . ,(@@ (geesh built-ins export) main))
("readonly" . ,(@@ (geesh built-ins readonly) main))
("return" . ,undefined)
("return" . ,(@@ (geesh built-ins return) main))
("set" . ,(@@ (geesh built-ins set) main))
("shift" . ,(@@ (geesh built-ins shift) main))
("times" . ,undefined)

41
geesh/built-ins/exit.scm Normal file
View File

@ -0,0 +1,41 @@
;;; The Geesh Shell Interpreter
;;; Copyright 2018 Timothy Sample <samplet@ngyro.com>
;;;
;;; 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 built-ins exit)
#:use-module (geesh environment))
;;; Commentary:
;;;
;;; The 'exit' utility.
;;;
;;; Code:
(define (main . args)
(let* ((arg (or (and (pair? args)
(car (last-pair args)))
(number->string (get-status))
"0"))
(number (string->number arg))
(status (or (and (exact-integer? number)
(>= number 0)
(<= number 256)
number)
;; If the above is not true, the exit status is
;; undefined.
EXIT_FAILURE)))
(sh:exit status)))

View File

@ -0,0 +1,41 @@
;;; The Geesh Shell Interpreter
;;; Copyright 2018 Timothy Sample <samplet@ngyro.com>
;;;
;;; 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 built-ins return)
#:use-module (geesh environment))
;;; Commentary:
;;;
;;; The 'return' utility.
;;;
;;; Code:
(define (main . args)
(let* ((arg (or (and (pair? args)
(car (last-pair args)))
(number->string (get-status))
"0"))
(number (string->number arg))
(status (or (and (exact-integer? number)
(>= number 0)
(<= number 256)
number)
;; If the above is not true, the exit status is
;; undefined.
EXIT_FAILURE)))
(sh:return status)))