Commit Graph

471 Commits

Author SHA1 Message Date
Timothy Sample 3fad06a756 Add function definition support
* geesh/eval.scm (eval-sh): Handle '<sh-defun>'.
2018-12-03 20:19:56 -05:00
Timothy Sample 93a5cba568 Add function call semantics
* geesh/shell.scm (exec-let): Find and use functions when appropriate.
2018-12-03 20:19:39 -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 801e9c8012 Use '$?' as the return value of the REPL
* geesh/repl.scm (run-repl): Return the value of '$?' (converted to a
number).
2018-12-03 20:16:01 -05:00
Timothy Sample fb493cc5f4 Process the return value of built-ins
* geesh/shell.scm (sh:exec-let): Set the '$?' variable to the return
value of built-in utilities.
2018-12-03 20:15:40 -05:00
Timothy Sample 21b862d326 Add the 'false' utility
* geesh/built-ins/false.scm: New file.
* Makefile.am: Add it.
* geesh/built-ins.scm (*built-ins*): Define 'false'.
2018-12-03 20:15:19 -05:00
Timothy Sample 5dae68d90a Make echo return a status code
* geesh/built-ins/echo.scm (echo): Return a status a code.
2018-12-03 20:14:57 -05:00
Timothy Sample 339f59d639 Add the 'read' utility
* geesh/built-ins/read.scm: New file.
* Makefile.am: Add it.
* geesh/built-ins.scm (*built-ins*): Define 'read'.
2018-12-03 20:14:36 -05:00
Timothy Sample 2db7833d61 Add for-loop support
* geesh/eval.scm (eval-sh): Handle '<sh-for>'.
2018-12-03 20:13:23 -05:00
Timothy Sample db56b1cc0a Add for-loop semantics
* geesh/shell.scm (sh:for): New public function.
* .dir-locals.el: Indent it nicely.
2018-12-03 20:12:51 -05:00
Timothy Sample 46ae7129d5 Add boolean support
* geesh/eval.scm (eval-sh): Handle '<sh-and>', '<sh-not>', and '<sh-or>'.
2018-12-03 20:12:22 -05:00
Timothy Sample 240ca130e8 Add boolean semantics
* geesh/shell.scm (sh:and, sh:not, sh:or): New public functions.
2018-12-03 20:12:02 -05:00
Timothy Sample 211e73ca43 Add pipeline support
* geesh/eval.scm (eval-sh): Handle '<sh-pipeline>'.
2018-12-03 20:11:28 -05:00
Timothy Sample 37f4ce6ea8 Add pipeline semantics
* geesh/shell.scm (swap-and-shift-pairs): New function.
(make-pipes): New function.
(plumb): New function.
(sh:pipeline): New public function.
* tests/shell.scm: Test it.
2018-12-03 20:09:55 -05:00
Timothy Sample 553b8f2b96 Use ports for redirects
Before, we were using raw file descriptors.  This worked okay, but
there was interference caused by port buffering.  Doing everything at
the port level avoids this problem, and has the added benefit of
allowing one to use the 'current-*-port' parameters with the shell
module (in a limited way, but there is room for improvement).

* geesh/shell.scm (*fd-count*): New variable.
(fd->current-port): New function.
(install-current-ports!): New function.
(exec-utility): Use it to set up file descriptors.
(save-and-install-redirect!): Rename this...
(save-and-set-redirect): ...to this and modify the current port
parameters instead of raw file descriptors.
(restore-saved-fdes!): Rename this...
(restore-saved-port): ...to this.
(sh:with-redirects): Adjust to use the renamed functions.
(sh:substitute-command): Parameterize the current ports directly
instead of using redirects.
* tests/shell.scm: Add tests to check if port buffers cause problems.
2018-12-03 20:07:53 -05:00
Timothy Sample 00d50fe7fd Add '-n' support to echo
* geesh/built-ins/echo.scm (echo): Omit trailing newline when '-n' is
the first argument.
2018-12-03 20:07:22 -05:00
Timothy Sample a6ceb8f3f2 Add command substitution support
* geesh/eval.scm (eval-word): Parameterize 'eval-cmd-sub' so that the
word module can substitute commands.
2018-12-03 20:07:06 -05:00
Timothy Sample 6b6ca11bce Add command substitution semantics
* geesh/shell.scm (%subshell): New function factored out from 'subshell'.
(subshell): Use it.
(substitute-command): New public function.
* tests/shell.scm: Test it.
* .dir-locals.el: Indent it nicely.
2018-12-03 20:06:47 -05:00
Timothy Sample 3148f66a21 Add subshell support
* geesh/eval.scm (exps->thunk): New function.
(eval-sh): Handle '<sh-subshell>'.
2018-12-03 20:04:55 -05:00
Jan Nieuwenhuizen f7617fce47 builtins: test: Fix a = b. 2018-12-03 21:01:37 +01:00
Jan Nieuwenhuizen d4f58ffa19 test: 04-word-at-word. 2018-12-02 09:51:57 +01:00
Jan Nieuwenhuizen 39761c0087 test: 04-word-at. 2018-12-02 09:51:57 +01:00
Jan Nieuwenhuizen 632295fa18 fix: 100-sed-fooRbar. 2018-12-02 09:03:02 +01:00
Jan Nieuwenhuizen 9115b9fbb6 test: 100-sed-fooRbar. 2018-12-02 09:03:02 +01:00
Jan Nieuwenhuizen f5bc1d45c4 fix: 50-redirect-in-out. 2018-12-02 09:03:02 +01:00
Jan Nieuwenhuizen 2c3630cfed test: 50-redirect-in-out, 100-tr. 2018-12-02 09:03:02 +01:00
Jan Nieuwenhuizen a043f9ef09 tr: New builtin.
* gash/commands/tr.scm: New file.
* gash/bournish-commands.scm: Use it.
* build-aux/build-guile.sh: Compile it.
* configure: Wrap it.
* .gitignore: Ignore it.
2018-12-02 09:03:02 +01:00
Jan Nieuwenhuizen 353af765eb cp: Support -f, --force. 2018-12-02 09:03:02 +01:00
Jan Nieuwenhuizen 0679cf9903 mv: Support -f, --force (by ignoring it). 2018-12-02 09:03:02 +01:00
Jan Nieuwenhuizen 73ecccef1e fix 01-script-$@. 2018-12-02 09:03:02 +01:00
Jan Nieuwenhuizen 1f0a7674d9 fix 01-script-$#. 2018-12-02 09:03:02 +01:00
Jan Nieuwenhuizen d5c94e75dd parse [ .. ] into plain command. fixes 10-if-bracket-false, 100-bracket-file. 2018-12-02 06:56:17 +01:00
Jan Nieuwenhuizen 6cf9cf7d0f test: 10-if-test, 10-if-test-false, 10-if-bracket, 10-if-bracket-false. 2018-12-02 06:56:17 +01:00
Jan Nieuwenhuizen ddc0f58896 test: 01-script-$#, 60-function-at. 2018-12-02 06:56:17 +01:00
Jan Nieuwenhuizen 6852e24dc4 test: 00-exit-error, 00-exit-var. 2018-12-02 06:56:17 +01:00
Jan Nieuwenhuizen 932339a5eb test: 30-substitution-word. 2018-12-02 06:56:17 +01:00
Jan Nieuwenhuizen d2d799a2f9 test: 20-exec. 2018-12-02 06:56:17 +01:00
Jan Nieuwenhuizen 8b925dd5e8 test: 03-echo-brace. 2018-12-02 06:56:17 +01:00
Jan Nieuwenhuizen 157bd5162d test: 10-if-line.sh.
Adding a newline to this file will no longer reproduce this bug.
2018-12-02 06:56:17 +01:00
Jan Nieuwenhuizen 380562c0b3 test: 100-test-file, 100-bracket-file. 2018-12-02 06:56:17 +01:00
Jan Nieuwenhuizen 8f12c6a562 test: 50-redirect-sed.sh 2018-12-02 06:56:17 +01:00
Jan Nieuwenhuizen 298238e8e6 guix: Update build. 2018-11-30 12:40:49 +01:00
Jan Nieuwenhuizen 0a09ab114a mv: New builtin.
* gash/commands/mv.scm: New file.
* gash/bournish-commands.scm: Use it.
* build-aux/build-guile.sh: Compile it.
* configure: Wrap it.
* .gitignore: Ignore it.
2018-11-30 12:38:24 +01:00
Timothy Sample 8739cafad9 Add subshell semantics
* geesh/shell.scm (subshell): New public function.
* tests/shell.scm: Test it.
* .dir-locals.el: Indent it nicely.
2018-11-28 23:07:03 -05:00
Timothy Sample b5e77fc27b Add support for '<sh-begin>'
* geesh/eval.scm (eval-sh): Handle '<sh-begin>'.
2018-11-28 23:07:03 -05:00
Timothy Sample d171a8cd15 Add support for setting variables
* geesh/eval.scm (eval-sh): Handle '<sh-set!>' forms.
2018-11-28 23:07:03 -05:00
Timothy Sample 5384009f75 Add redirect support
* geesh/eval.scm (eval-redir): New function.
(exp->thunk): New function.
(eval-sh): Handle '<sh-with-redirects>' forms.
2018-11-28 23:07:03 -05:00
Timothy Sample e6f732ada9 Add redirect semantics
* geesh/shell.scm (save-and-install-redirect!): New function.
(restore-saved-fdes!): New function.
(with-redirects): New public function.
* tests/shell.scm: Test it.
* .dir-locals.el: Indent it nicely.
2018-11-28 23:07:03 -05:00