oilshell / oil

Oils is our upgrade path from bash to a better language and runtime. It's also for Python and JavaScript users who avoid shell!
http://www.oilshell.org/
Other
2.78k stars 150 forks source link

ASDL enhancements #443

Open andychu opened 4 years ago

andychu commented 4 years ago

edit 9/2019: A lot of this was done. Still need to refactor the schema with new "shared variant" capability.

andychu commented 4 years ago

Idea for spids fields:

Develop and Oil language syntax like enum { ... }. And add common fields first, e.g. like the suggestion here:

https://www.reddit.com/r/ProgrammingLanguages/comments/cvwc7n/sum_types_vs_classes/

nitpick: I don't like putting spids first in the constructor... I want them to be optional at the end. Keyword args?

Do we allow default values like function calls / constructors do?

enum op = Plus | Minus
enum expr {
  Binary(o op = op.Plus, left expr, right expr)
}
andychu commented 4 years ago

Another enhancement is motivated by _Dispatch in osh/cmd_exec.py. This function has two checks for variants of command

It would be nice to have some way of quickly checking these types / sets? A big bitfield?

But I wanted every type in the program to have a unique integer? Maybe I can just pack the command enum into the first 32 or 64?

andychu commented 4 years ago

A size optimization issue:

Python's dict node is represented as:

expr = ... | Dict(expr* keys, expr* values)

I guess this is the most efficient. Except that we added implicit values, which means that the expression can be missing.

Oh I guess the best thing to do is add Implicit as a variant of expr and not create a new dict_val type.

OK that solves this problem. I was wondering if

expr = ... | Dict(dict_pair* pairs)

would be better.

andychu commented 4 years ago

Now talking about this on a new channel #zephyr-asdl on Zulip:

https://oilshell.zulipchat.com/#narrow/stream/208950-zephyr-asdl

andychu commented 4 years ago

Idea: combine cell and value. cell only needs 3 bits. (And honestly -n and -x don't apply to anything except strings, though I guess -x applies to Undef too.)

class value_t {
  uint16_t tag;
  uint16_t cell_flags
};  // 4 bytes

And then: