Add readonly built-in
* geesh/built-ins/utils.scm: New file. * geesh/built-ins/readonly.scm: New file. * Makefile.am: Add them. * geesh/built-ins/export.scm (split-assignments): Move to utils. * geesh/built-ins.scm (*special-built-ins*): Add readonly.
This commit is contained in:
parent
c5ac41b0f8
commit
671a926011
|
@ -47,8 +47,10 @@ MODULES = \
|
||||||
geesh/built-ins/export.scm \
|
geesh/built-ins/export.scm \
|
||||||
geesh/built-ins/false.scm \
|
geesh/built-ins/false.scm \
|
||||||
geesh/built-ins/read.scm \
|
geesh/built-ins/read.scm \
|
||||||
|
geesh/built-ins/readonly.scm \
|
||||||
geesh/built-ins/true.scm \
|
geesh/built-ins/true.scm \
|
||||||
geesh/built-ins/unset.scm \
|
geesh/built-ins/unset.scm \
|
||||||
|
geesh/built-ins/utils.scm \
|
||||||
geesh/built-ins.scm \
|
geesh/built-ins.scm \
|
||||||
geesh/environment.scm \
|
geesh/environment.scm \
|
||||||
geesh/eval.scm \
|
geesh/eval.scm \
|
||||||
|
|
|
@ -40,7 +40,7 @@
|
||||||
("exec" . ,undefined)
|
("exec" . ,undefined)
|
||||||
("exit" . ,undefined)
|
("exit" . ,undefined)
|
||||||
("export" . ,(@@ (geesh built-ins export) main))
|
("export" . ,(@@ (geesh built-ins export) main))
|
||||||
("readonly" . ,undefined)
|
("readonly" . ,(@@ (geesh built-ins readonly) main))
|
||||||
("return" . ,undefined)
|
("return" . ,undefined)
|
||||||
("set" . ,undefined)
|
("set" . ,undefined)
|
||||||
("shift" . ,undefined)
|
("shift" . ,undefined)
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
;;; along with Geesh. If not, see <http://www.gnu.org/licenses/>.
|
;;; along with Geesh. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
(define-module (geesh built-ins export)
|
(define-module (geesh built-ins export)
|
||||||
|
#:use-module (geesh built-ins utils)
|
||||||
#:use-module (geesh environment)
|
#:use-module (geesh environment)
|
||||||
#:use-module (ice-9 match))
|
#:use-module (ice-9 match))
|
||||||
|
|
||||||
|
@ -26,14 +27,6 @@
|
||||||
;;;
|
;;;
|
||||||
;;; Code:
|
;;; Code:
|
||||||
|
|
||||||
(define (split-assignment assignment)
|
|
||||||
(match (string-index assignment #\=)
|
|
||||||
(#f (values assignment #f))
|
|
||||||
(index (let ((name (substring assignment 0 index)))
|
|
||||||
(match (substring assignment (1+ index))
|
|
||||||
((? string-null?) (values name #f))
|
|
||||||
(value (values name value)))))))
|
|
||||||
|
|
||||||
(define (main env . args)
|
(define (main env . args)
|
||||||
(match args
|
(match args
|
||||||
(("-p") (throw 'not-implemented "export -p"))
|
(("-p") (throw 'not-implemented "export -p"))
|
||||||
|
|
|
@ -0,0 +1,38 @@
|
||||||
|
;;; 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 readonly)
|
||||||
|
#:use-module (geesh built-ins utils)
|
||||||
|
#:use-module (geesh environment)
|
||||||
|
#:use-module (ice-9 match))
|
||||||
|
|
||||||
|
;;; Commentary:
|
||||||
|
;;;
|
||||||
|
;;; The 'readonly' utility.
|
||||||
|
;;;
|
||||||
|
;;; Code:
|
||||||
|
|
||||||
|
(define (main env . args)
|
||||||
|
(match args
|
||||||
|
(("-p") (throw 'not-implemented "readonly -p"))
|
||||||
|
(_ (for-each (lambda (assignment)
|
||||||
|
(call-with-values (lambda () (split-assignment assignment))
|
||||||
|
(lambda (name value)
|
||||||
|
(set-var-read-only! env name value))))
|
||||||
|
args)
|
||||||
|
0)))
|
|
@ -0,0 +1,35 @@
|
||||||
|
;;; 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 utils)
|
||||||
|
#:use-module (ice-9 match)
|
||||||
|
#:export (split-assignment))
|
||||||
|
|
||||||
|
;;; Commentary:
|
||||||
|
;;;
|
||||||
|
;;; Utility functions shared by built-ins.
|
||||||
|
;;;
|
||||||
|
;;; Code:
|
||||||
|
|
||||||
|
(define (split-assignment assignment)
|
||||||
|
(match (string-index assignment #\=)
|
||||||
|
(#f (values assignment #f))
|
||||||
|
(index (let ((name (substring assignment 0 index)))
|
||||||
|
(match (substring assignment (1+ index))
|
||||||
|
((? string-null?) (values name #f))
|
||||||
|
(value (values name value)))))))
|
Loading…
Reference in New Issue