Commit Graph

19 Commits

Author SHA1 Message Date
Timothy Sample c169a90753 Use default value when unpacking variable vector.
* geesh/environment.scm (getvar): Use 'dflt' when we have a vector but
'value' is '#f'.
2019-05-20 01:17:22 -04:00
Timothy Sample 177953c4b0 Add support for $$
* geesh/environment.scm (*root-pid*): New variable.
(get-root-pid): New public function.
* geesh/word.scm (parameter-ref): Handle '$'.
2018-12-05 16:23:51 -05:00
Timothy Sample 6b38897dc5 Initialize $PWD properly
* geesh/environment.scm (initial-pwd): New function.
(initial-variables): New function.
(*variables*): Initialize to the result of initial-variables.
2018-12-05 16:22:51 -05:00
Timothy Sample 66e89c1a05 Add return and exit semantics
* geesh/environment.scm (*return-tag*): New variable.
(call-with-return): New public function.
(sh:return): New public function.
(*atexit*): New variable.
(*exiting?*) New variable.
(set-atexit!): New public function.
(sh:exit): New public function.
* geesh/repl.scm (run-repl): Call sh:exit at the end of a script.
* geesh/shell.scm (sh:exec-let): Use call-with-return for functions.
* geesh/built-ins/dot.scm (main): Use call-with-return.
2018-12-05 16:08:09 -05:00
Timothy Sample 2fdbfe2ca4 Add a prefix to break and continue
These names are too common, and it will be even worse with 'exit'
and 'return'.

* geesh/environment.scm (break): Rename this...
(sh:break) ...to this.
(continue): Rename this...
(sh:continue) ...to this.
* geesh/built-ins/break.scm (main): Update call.
* geesh/built-ins/continue.scm (main): Ditto.
2018-12-05 16:08:09 -05:00
Timothy Sample c83dbcbdc8 Add options to the environment
* geesh/environment.scm (*options*): New variable.
(getopt): New public function.
(setopt!): New public function.
(*option-names*): New public variable.
(*option-letters*): New public variable.
2018-12-05 16:08:09 -05:00
Timothy Sample 4ef6907851 Globalize the environment module
Instead of passing around references to the environment, just treat it
as a global.  The old way was just the remains of an idea to make the
environment immutable and keep the interpreter from manipulating any
global state.  By making everything global and mutable, we will have
less impedance mismatch with POSIX going forward.

The following changelog is only a sketch, since nearly every function
has changed.

* geesh/environment.scm: Replace this module with one that treats the
environment as a global resource.
* tests/environment.scm: Delete file.
* Makefile.am: Remove it from the list of tests.
* geesh/shell.scm, geesh/eval.scm, geesh/repl.scm, geesh/word.scm,
geesh/built-ins/break.scm, geesh/built-ins/continue.scm,
geesh/built-ins/echo.scm, geesh/built-ins/export.scm,
geesh/built-ins/false.scm, geesh/built-ins/read.scm,
geesh/built-ins/readonly.scm, geesh/built-ins/set.scm,
geesh/built-ins/true.scm, geesh/built-ins/unset.scm: Remove 'env'
parameters and use the new environment module.
* .dir-locals.el: Update indentation of functions that no longer take
an 'env' parameter and add with-arguments, with-environ, and
with-variables from the new environment module.
* tests/shell.scm, tests/word.scm: Update environment creation and
manipulation in tests.
2018-12-05 16:08:09 -05:00
Timothy Sample 0d41cec2d6 Add the set built-in
* geesh/environment.scm: Export set-environment-arguments!.
* geesh/built-ins/set.scm: New file.
* Makefile.am: Add them.
* geesh/built-ins.scm: Add set.
2018-12-05 16:08:09 -05:00
Timothy Sample e784aaa658 Add export and read-only attributes to variables
* geesh/environment.scm (<variable>): New record type.
(make-environment): Initialize variables as records.
(var-ref): Extract value from record.
(set-var!): Inject value into record and throw an error if variable
is read-only.
(set-var-export!): New public function.
(set-var-read-only!): New public function.
(environment->environ): Only include exported variables.
2018-12-05 16:08:09 -05:00
Timothy Sample 06db42088a Add 'break' and 'continue'
* geesh/environment.scm (<environment>): Add 'break-prompt' and
'continue-prompt' fields.
(make-environment): Initialize them.
* geesh/shell.scm (sh:for): Setup break and continue prompts.
* geesh/built-ins/break.scm: New file.
* geesh/built-ins/continue.scm: New file.
* Makefile.am: Add them.
* geesh/built-ins.scm (*special-built-ins*): Add break and continue.
2018-12-05 16:08:09 -05:00
Timothy Sample 7e3bbda4cb Add 'unset' built-in
* geesh/environment.scm (delete-environment-vars!): New public function.
(delete-environment-functions!): New public function.
* geesh/built-ins/unset.scm: New file.
* Makefile.am: Add it.
* geesh/built-ins.scm: Enable 'unset'.
2018-12-05 16:08:09 -05:00
Timothy Sample 58f5644d2a Add 'arguments' field to environment
* geesh/environment.scm (<environment>): Add an 'arguments' field.
(make-environment): Add an optional 'arguments' parameter.
(with-environment-arguments): New public function.
.dir-locals.el: Indent it nicely.
2018-12-03 20:19:22 -05:00
Timothy Sample f03b438009 Keep track of functions in the environment
* geesh/environment.scm (<environment>): Add a 'functions' field.
(make-environment): Initialize it to the empty list.
(environment-function-ref): New public function.
(define-environment-function!): New public function.
2018-12-03 20:18:50 -05:00
Timothy Sample e43e6a88c4 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-12-03 20:17:56 -05:00
Timothy Sample 737ed6a1b7 Add function for reading an 'environ'
* geesh/environment.scm (environ->alist): New function.
* tests/environment.scm: Test it.
2018-11-28 23:07:03 -05:00
Timothy Sample 020adfc58b Add convenience function 'var-ref*'
* geesh/environment.scm (var-ref*): New public function.
* geesh/word.scm (word->qword): Use it to simplify things.
2018-11-28 23:07:03 -05:00
Timothy Sample da1746f2d6 Add missing doc strings in environment
* geesh/environment.scm (var-ref): Add doc string.
(set-var!): Add doc string.
2018-11-28 23:07:03 -05:00
Timothy Sample cfb2b5b99b Add function for creating an 'environ'
* geesh/environment.scm (environment->environ): New function.
* tests/environment.scm: Test it.
2018-11-28 23:07:03 -05:00
Timothy Sample 6678ae1e59 Add environment
* geesh/environment.scm: New file.
* tests/environment.scm: New file.
* Makefile.am: Add them.
2018-07-15 19:46:14 -04:00