DuckLogic / Pathos

A recursive decent parser for Python code
MIT License
0 stars 0 forks source link

Compile directly to bytecode, skipping most intermediate source generation #1

Closed Techcable closed 3 years ago

Techcable commented 3 years ago

This is different than our old approach of AST visitors, because we will still construct an intermediate AST for certain constructs such as patterns.

The rule is no longer 'no allocations', just that we should be able to compile most expressions and statements in a single pass.

More complex source constructs like patterns, closures, generators, and collection literals may require an exception to this rule.

Techcable commented 3 years ago

Note that we'd probably want to preserve the ability to construct an AST from these .

To avoid code duplication, we should consider dynamic dispatch on our listeners &mut dyn ExprListener.

Using monomorphization on a the listener could result in multiple copies of the entire codebase: One for the bytecode compiler and one for the AST builder. Yikes!

If we're truly aiming for some sort of maximally efficient parser + bytecode generator, than I think we can just disable the AST builder and hope LLVM's devirtualization will kick in. Although AFAIK, devirtualization is much better in C++ than in Rust :(