PistonDevelopers/dyon

Dynamic modules

bvssvni opened this issue · 0 comments

Dyon uses dynamic modules to organize code.

List of included functions for dynamic modules

  • fn load(source_file: str) -> res
  • fn load_source_imports(source_file: str, imports: []) -> res
  • fn call(module, function_name: str, arguments: [])
  • fn call_ret(module, function_name: str, arguments: []) ->

call and call_ret can be unsafe to use if the function takes lifetimes (later changes to the language might address this).

What is a dynamic module?

A dynamic module is loaded at run-time, while running the program, instead of being parsed before running the program. When the module is loaded, you can call functions inside that module through call and call_ret.

Design

When Dyon imports a module X for a new dynamic module A, the module X becomes part of the prelude for A. This makes it easy to:

  • swap a back-end module without changing the source
  • rewrite functions in Rust without changing code
  • write loader scripts that refreshes a module while running the program
  • replaced need for eval, which might be easily insecure and make a mess