Open andychu opened 5 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)
}
Another enhancement is motivated by _Dispatch
in osh/cmd_exec.py
. This function has two checks for variants of command
strict_errexit
check (which other shells don't have)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?
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.
Now talking about this on a new channel #zephyr-asdl on Zulip:
https://oilshell.zulipchat.com/#narrow/stream/208950-zephyr-asdl
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.)
value
? because of the multiple inheritance problem? But that doesn't happen to apply in the value_t
case. Maybe you can make a special case for it.class value_t {
uint16_t tag;
uint16_t cell_flags
}; // 4 bytes
And then:
Str
can inline the length and pointer. That's really inlining mylib.MaybeStrArray
could be a pointer and length too? Although it also needs a capacity.AssocArray
could store length? Not sure if you need it right there.value_t
a 16-byte value type instead of an 8-byte pointer type?
val.s
instead of val->s
, etc.Str
fields would too. But value__Str
with inline cell is still valuable. So there are 2 optimizations available.
use
keywordId_t
. It generates a custom Python import at the top of the module.map[string, bool]
simple_int_sum
forId
and integer types for IFS state machinesyntax_asdl::command_t
andruntime_asdl::cell
e_suffix
or something? This part needs to be cleaned up.Exception
is required in Python. Inheriting fromstd::exception
in C++ is apparently only needed for what(), which we don't use.asdl/typed_demo.py
could be renamed togen_python_test.py
asdl.txt
). This enables a bunch of schema changes (which are minor optimizations, and make the code cleaner):frontend/syntax.asdl
:token
CompoundWord
CompoundWord
expr
andword_part
:ShCommandSub
andOilCommandSub
($()
and eventually$[]
)ShArrayLiteral
andArrayLiteral
(local x=(a b)
andvar x = @(a b)
and eventually@[a b]
)cmd_part = compound_word | simple_redir | here_doc
cell.readonly
andcell.exported
could be represented as a bitfieldspids
field explicit withattributes
mechanismtrace = External(string* argv) | ForkWait | ...
, thetrace.ForkWait()
constructor shouldn't allocateedit 9/2019: A lot of this was done. Still need to refactor the schema with new "shared variant" capability.