Skip to content
Snippets Groups Projects
  1. Sep 04, 2018
  2. Aug 16, 2018
    • Damien George's avatar
      py/emitnative: Optimise and improve exception handling in native code. · a3de7764
      Damien George authored
      Prior to this patch, native code would use a full nlr_buf_t for each
      exception handler (try-except, try-finally, with).  For nested exception
      handlers this would use a lot of C stack and be rather inefficient.
      
      This patch changes how exceptions are handled in native code by setting up
      only a single nlr_buf_t context for the entire function, and then manages a
      state machine (using the PC) to work out which exception handler to run
      when an exception is raised by an nlr_jump.  This keeps the C stack usage
      at a constant level regardless of the depth of Python exception blocks.
      
      The patch also fixes an existing bug when local variables are written to
      within an exception handler, then their value was incorrectly restored if
      an exception was raised (since the nlr_jump would restore register values,
      back to the point of the nlr_push).
      
      And it also gets nested try-finally+with working with the viper emitter.
      
      Broadly speaking, efficiency of executing native code that doesn't use
      any exception blocks is unchanged, and emitted code size is only slightly
      increased for such function.  C stack usage of all native functions is
      either equal or less than before.  Emitted code size for native functions
      that use exception blocks is increased by roughly 10% (due in part to
      fixing of above-mentioned bugs).
      
      But, most importantly, this patch allows to implement more Python features
      in native code, like unwind jumps and yielding from within nested exception
      blocks.
      a3de7764
  3. Apr 10, 2018
    • Damien George's avatar
      py: Refactor how native emitter code is compiled with a file per arch. · ef12a4bd
      Damien George authored
      Instead of emitnative.c having configuration code for each supported
      architecture, and then compiling this file multiple times with different
      macros defined, this patch adds a file per architecture with the necessary
      code to configure the native emitter.  These files then #include the
      emitnative.c file.
      
      This simplifies emitnative.c (which is already very large), and simplifies
      the build system because emitnative.c no longer needs special handling for
      compilation and qstr extraction.
      ef12a4bd
Loading