Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modules #19

Merged
merged 9 commits into from
Feb 26, 2023
Merged

Modules #19

merged 9 commits into from
Feb 26, 2023

Conversation

jprochazk
Copy link
Owner

Closes #3

Some things which the original plan didn't consider:

  • There needs to be a difference between the main module and other modules, because the main module is never fully initialized. The main module should also never be cached, but it should still be possible for module_vars in it to be accessible.

@jprochazk
Copy link
Owner Author

This needs a nice rebase, and a changelog entry 🙂

@jprochazk
Copy link
Owner Author

Also more tests for stuff like:

  • Calling a function from another module
  • Calling a function which uses module vars from another module
  • Instantiating classes from a different module
  • etc., generally, anything that went from LoadGlobal/StoreGlobal -> LoadModuleVar/StoreModuleVar should be tested

- each function now gets a `FunctionDescriptor`.
- the descriptor is used to instantiate the function
  at runtime by the `CreateFunction` instruction.
- added concept of module variables, which are
  globals scoped to a specific module. this allows
  functions to refer to globals from the module
  in which they were declared without conflicting
  with other modules' globals.
- introduced `ModuleLoader` trait, which allows
  configuring where modules are loaded from, and
  the `ModuleRegistry` struct, which is used to
  store modules at runtime.
- the root module still emits global accesses using
  `LoadGlobal` and `StoreGlobal` instructions.
- also did some renaming (`desc` -> `descriptor`)
  and added a builder for configuring the `Hebi`
  instance.
- `class` -> `class instance`
- `class def` -> `class`
- added `Import` and `ImportNamed` instructions
- updated import syntax to match Python (mostly)
- implemented module loading (except native modules)
- functions were not respecting module scope,
  because the module kind was kept per function.
  it's been changed to be per-emitter.
- the result of `get_module_var` was not being assigned
  to the accumulator.
@jprochazk jprochazk marked this pull request as ready for review February 26, 2023 20:05
@jprochazk
Copy link
Owner Author

jprochazk commented Feb 26, 2023

I think that's enough tests for now, ship it 🚀

@jprochazk jprochazk merged commit 41ffc94 into main Feb 26, 2023
@jprochazk jprochazk deleted the modules branch April 28, 2023 19:48
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.

Modules
1 participant