Skip to content

v3.1.0

Compare
Choose a tag to compare
@Technologicat Technologicat released this 11 Feb 23:20
· 260 commits to master since this release

3.1.0 (12 February 2021) - Compiling on the high seas edition:

New:

  • The mcpyrate compiler (implementing the import algorithm) is now exposed in mcpyrate.compiler for run-time use.

    • You can just expand, or both expand and compile code, as needed.
    • It is now convenient to compile and run macro-enabled quoted code snippets (or source code) at run time, see the functions mcpyrate.compiler.run and mcpyrate.compiler.create_module.
      • This makes it easier to test macros that are best tested via the behavior of the run-time code they output. (It also makes macro-enabled Python into a poor man's staged language [1] [2].)
      • The system allows dynamically creating modules (for executing code snippets in) at run time, as well as running code in the namespace of an existing module.
        • These features combine, so you can let run automatically create a module the first time, and then re-use that module if you want.
        • You can also create a module with a specific dotted name in sys.modules. The multi-phase compiler itself uses this feature.
      • Source code input supports dialects, macros, and multi-phase compilation. The source code represents a module.
      • Quoted AST input supports macros and multi-phase compilation. No source transforms for this kind of input, because the input is already an AST. (Dialect AST transformers and postprocessors should work.) The top level of the quoted block (i.e. the body of a with q as quoted:) is seen by the compiler as the top level of a module.
      • While the code snippet is running, the module's __file__ and __name__ attributes are available, as usual.
      • For extracting results into the surrounding context, just assign them to variables inside the code snippet. The top level of the code snippet is the module's top level. You have that module object available in the surrounding context (where you call run), so you can access those variables as its attributes.
    • Full documentation is in docstrings for now, see mcpyrate.compiler. Usage examples can be found in mcpyrate.test.test_compiler.
  • Add support for PEP 582 - Python local packages directory in the macropython bootstrapper.

  • The unparser now supports all three top-level node types, and supports also a list of AST nodes (e.g. a statement suite in an AST) as input.

  • The StepExpansion dialect now works in AST-only mode, too.

    • It will enable DialectExpander debug mode in the source transform step, if that runs. If the AST transform step is reached and debug mode is still off, it will now enable debug mode at that time. Only one copy of the unprocessed code is printed regardless.
  • README: add instructions to configure Emacs syntax highlighting.

  • Add unpyrate.bunch.bunchify to convert an existing mapping instance into a Bunch.

Changed:

  • Nested quasiquotes now work properly.

    Unquoting now only occurs when quote level hits zero. Inner quotes and unquotes are detected, for tracking the quote level, but are then left in the output as-is.

    Note as-is means "as unexpanded macro invocations". Because the quasiquote operators are just macros, and in macro-enabled Python, the tradition is that a function actually being a macro is a property of the use site, not of its definition site, it follows that there's no guarantee whether the quote operators are in the expander's bindings at any later time. Even if they are, there is no guarantee whether they still have the names they had at the time when the outermost quote expanded.

    What we have now is the result of taking the current design to its logical extreme. A better solution (for next-next-gen) may need a break from tradition, in that maybe a function being a macro should be a property of its definition site, not of its use site. Also, maybe the quasiquote operators should be considered core functionality, and not be renameable (like regular macros are).

    However, the current solution does give useful level separation that has real practical applications; see the dynamically generated module example in mcpyrate.test.test_compiler.

    This is not considered a breaking change, because the previous behavior of nested quasiquotes didn't make any sense, so nothing useful could be built on it.

Fixed:

  • Fix INTI-CMNB/KiBot#29, with thanks to @skorokithakis and @set-soft.
  • Fix #21, with thanks to @thirtythreeforty for reporting.
  • Fix bug in unastify: drop the run-time part of q.
  • Fix bug in rename: handle also module name in ImportFrom nodes.
  • Fix SourceLocationInfoValidator.
  • macropython now reports mcpyrate version separately from the version of the macropython script itself when run with the -v (--version) command-line option.