blog | oilshell.org

Diffuclties in Shell Implementation

2018-09-01

Since coming back, I've been slogging through the shell.

I made a "complete pass" over the front end, fixing various problems and polishing error messages.

I also touched the runtime. It reminded me that I haven't written much about the shell-runtime.

I don't think I will do that, because silly problems drop out of hat. I would rather work on the Oil language. (I've also been working on the OSH-to-Oil translator.

But here is a list of difficult issues.

Table of Contents
Implemented
The Core of the Project: Statically Parsing Shell
Here Docs and the LST
Word Evaluation
Consistency between Static and Dynamic Variants of the Same Language
String Operations with Quadratic Time
File Desciprotrs
Unimplemented
Printing Good Error Messages
Alias Requires feedback
Job Control
Interactive Completion
Signals and EINTR
Speculative
Writing Two Interpreters and a Compiler Is Hard
Good and Bad Design Decisions
Appendix A: Shell Parser Implementations

Implemented

The Core of the Project: Statically Parsing Shell

Static parsing. However see below about alias.

Here Docs and the LST

There is a small exception to the LST invariant, but the overall principle holds.

I wrote this arena invariant test.

Word Evaluation

I just fixed a bug with this, and it reminded me how complicated it was.

Consistency between Static and Dynamic Variants of the Same Language

Corrolary: find is a dynamic expression language, and we should have a statically-parsed variant of it!

Advertise: looking for someone to implement find/xargs

TODO: better terms than static and dynamic.

String Operations with Quadratic Time

${a ## }

Good thing: Oil no longer depends on Python's regex implementation. Only libc's.

These string ops are deprecated, and I will provide more powerful ones in Oil.

File Desciprotrs

Back to FD bug. OSH Runs Real Shell Programs

It happened asgain! Twice!! Why didn't I think of it?

It required two fixes for two bugs.

Unimplemented

Printing Good Error Messages

Alias Requires feedback

It makes parsing undecidable. See this parsing shell paper.

However it depends on how you define the problem.

Job Control

Not going to solve this

Need some kind of TLA+ formalism.

Looking at all the global variables in bash/dash etc. makes my eyes glaze over. That might be my own issue.

Oil is all abou testing. I'm having trouble imaginging how I would test this.

Interactive Completion

This is the last use case for the parser.

Signals and EINTR

The shell still needs another pass over this. I will probably throw out Python's implementation and make my own.

However, I like the fact that you can git clone Oil and run bin/osh and get started roughly. So it's not clear exactly how this will play out.

Speculative

Writing Two Interpreters and a Compiler Is Hard

I'm still on the first one. What about Scala-LMS? Can I do something there?

Oil is a project of DSLs.

Good and Bad Design Decisions

Very happy with (this should be a separate blog post)

Unknown:

Glad I changed:

I used return codes because I thought I would translate.

However if you know anything about compiling exceptions to control flow, let me know!

I'm learning about control flow graphs, the EmScriptem algorithm, WebAssembly, etc.

Appendix A: Shell Parser Implementations

I haven't

Multiple invention!