[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Language spec
From: |
Timothy Sample |
Subject: |
Re: Language spec |
Date: |
Mon, 17 Aug 2020 22:25:57 -0400 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/26.3 (gnu/linux) |
Hi Stephen,
Stephen Scheck <singularsyntax@gmail.com> writes:
> Hello,
>
> I've been experimenting with implementing a language spec for Gash,
> such that you can use the shell from the Guile REPL:
>
> scheme@(guile-user)> ,language gash
> Happy hacking with Guile as Shell! To switch back, type `,L scheme'.
> gash@(guile-user)> find .
> .
> ./src
> ./src/language
> ./src/language/gash-compiled
> ./src/language/gash-compiled/spec.scm
> ./src/language/gash
> ./src/language/gash/spec.scm
> $1 = 0
> gash@(guile-user)> find foo
> find: 'foo': No such file or directory
> $2 = 1
Cool! I like that it returns the status as the result.
> To achieve this as a simple evaluated language is straightforward:
>
> (define-module (language gash spec)
> #:use-module (gash parser)
> #:use-module (gash eval)
> #:use-module (gash environment)
> #:use-module (system base language)
> #:export (gash))
>
> (define-language gash
> #:title "Guile as Shell"
> #:reader (lambda (port env) (read-sh port))
> #:evaluator (lambda (x module) (eval-sh x) (get-status))
> #:printer write)
>
> I'm wondering if there would be any interest in including something
> like this in Gash?
This is definitely on the roadmap. In fact, I wrote almost the same
code in February (minus the status returning), when I took a first stab
at implementing a Tree-IL compiler. So this is absolutely something we
want, but it might be worth holding out for a version with a compiler.
On the other hand, since this code will have to be in-place for the
compiler version, there’s no harm in tossing it in now if you would like
to prepare a patch. Let me know if you need any help with that (we
don’t have a contributors’ guide, but we follow more-or-less what GNU
Guix does).
> It's also not difficult to naively compile to tree-il, but I think the
> way I've done it would not be what is wanted, since it really just
> compiles the *interpreter* `eval-sh` code. Of course, `eval-sh`
> examines an expression of Gash tokens, producing bits of Scheme code
> and immediately evaluating them; a proper compiler should replace the
> Gash token stream with those same Scheme expression sequences without
> executing them, and pass that to the tree-il compiler. However, that's
> beyond the scope of my current familiarity with the Gash
> implementation.
If you want to become more familiar with Gash, writing a compiler would
do the trick! ;) (Seriously though, help is always welcome!)
Changing ‘eval-sh’ to be a compiler is pretty straightforward. Much of
it is just lightly wrapped calls into to procedures from “shell.scm”.
The issue that I ran into is that Gash actually has two evaluators: the
regular one, and one that does word expansion (cf. “word.scm”). It
would be best if each evaluator had a corresponding compiler, but the
current interface between the two makes this impossible. So we need to
refactor that interface before writing the compiler. Here’s the comment
I wrote earlier this year:
;; To really make this work, we would need to refactor 'expand-word'
;; so that it takes a 'qword' and make 'word->qword' the
;; responsibility of the evaluator. Then, we can make a compiled
;; version of 'word->qword'.
> Happy hacking with Guile as Shell!
Thanks!
-- Tim