zom-lang/zom

Packages, modules, import system in Zom

Closed this issue · 2 comments

Clarify, packages, modules, create an import system in Zom:

  • Import item, in zom you can import the scope of symbols to the current file. like that :
import std.debug.println;

to import scope of the println function in the module. You can reexport symbols to another scole, with public imports,

pub import std.debug.println;
pub import std.test.assert;
pub import std.test.expect;
// ...
  • Write rules for Zom name mangling and put them into the book, then implement it (probably create its own issue)
  • Item visibility, visibility identifier
    • private, the item can only be called from the current, module, it's the default when pub isn't specified.
    • public, the item is usable in the whole package and packages that use it, use the pub keyword in front of the item.
  • export, when using export in front of an Item, the name mangling is disabled, and the symbol is exported. It's meant to facilitate interop with C. And because names aren't mangled, an error is omitted if to exported symbol have the same name
  • Modules can be declared, in another module, like that
mod childmod {
    // items ...
}

module declaration is an item so it can have a visibility identifier. Modules can also be declaraded from another file, like that:

mod modfile;
  • The global path of an Item is the path of it's container plus it's name. And the the path of the primary module is the name of the package. The primary module, is the path given to the first source file of a package. e.g:
// main.zom and package named 'example':

fn main() void {} // => example.main

pub mod somecode {
    fn hello() void { ... } // => example.somecode.hello
}

Maybe try to incorporate the LLD linker ?

Has been done in the pr #58