Skip to content

Module import export fixes#97

Merged
jow- merged 8 commits intomasterfrom
module-import-export-fixes
Aug 6, 2022
Merged

Module import export fixes#97
jow- merged 8 commits intomasterfrom
module-import-export-fixes

Conversation

@jow-
Copy link
Copy Markdown
Owner

@jow- jow- commented Aug 5, 2022

This PR introduces a series of fixes for the compilation of import and export statements.

  • Fixes segmentation fault on loading and executing module constructors containing import upvals
  • Fixes allocating export registry slots in the compiler
  • Stricter compilation rules for modules
  • Fixed relative module path resolving
  • Improved error message formatting

jow- added 8 commits August 5, 2022 15:50
Introduce a further uc_function_t structure member indicating whether the
underlying function is a module constructor.

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
Module function upvalues are patched through import operations, ensure to
leave them uninitialized when loading and executing the module constructor.

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
 - Disallow toplevel `return` statements in module functions
 - Disallow `export` statements in non-module functions

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
The current implementation of `uc_compiler_canonicalize_path()` used the
entire runtime path of the source object as path prefix, not just the
directory part of it.

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
The current implementation of the module export offset tracking was
inadequate and failed to properly handle larger module dependency
graphs. In order to properly support nested module imports/exports,
the following changes have been introduced:

 - Gather export slots during module compilation and emit corresponding
   export opcodes as one contiguous block at the end of the module
   function body, right before the final return. This ensures that
   interleaved imports of other modules do not place foreign exports
   between our module exports.

 - Track the number of program wide allocated export slots in order
   to derive per-module-source offsets for the global VM export list.

 - Derive import opcode source index from the module source export
   offset and the index of the requested name within the module source
   export name list.

 - Improve error reporting for circular module imports.

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
Since we track the offsets in the compiler directly now there's no need
to keep this function.

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
Indent inner messages and prepend them with a vertical bar to increase
visual separation of messages. Also include file name in source context
output when the compiled program contains more than one source file.

Adjust affected testcase outputs accordingly.

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
@jow- jow- force-pushed the module-import-export-fixes branch from 0a8d621 to b4a3f68 Compare August 5, 2022 14:37
@jow- jow- merged commit f1e3938 into master Aug 6, 2022
@jow- jow- deleted the module-import-export-fixes branch August 6, 2022 07:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant