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

Module syntax #44

Open
LighghtEeloo opened this issue Apr 15, 2023 · 1 comment
Open

Module syntax #44

LighghtEeloo opened this issue Apr 15, 2023 · 1 comment
Assignees
Labels
design Discussion of design issues

Comments

@LighghtEeloo
Copy link
Contributor

As the standard library continues to expand, it becomes essential to introduce a namespace system to better manage and organize the growing codebase. We propose implementing a lightweight module system, coupled with the name resolution phase, to address the issues of increasingly long variable names and parsing time.

Notice that the word "module" here is abused - we have no intension in achieving modularity in any sense. Our module system will primarily focus on namespace management and will serve as syntactic sugar for fully qualified names, rather than being a first-class term. This design aims to streamline the code organization without adding unnecessary complexity.

The ability to export a symbol table from a module will be reserved for future enhancements in the language. These improvements will be closely tied to the semantics of visibility control using the pub keyword.

The principles and goals for this design have been outlined above. Concrete design choices and implementation details will be left to @SchwarzXia to determine and document as the development progresses.

@SchwarzXia
Copy link
Contributor

Here's a list of tentative new syntaxes that I think we should add in this first stage:

  1. module <name> ... end: Defining a module. Every definition, say <var>, inside will be named as <name>.<var> outside of module. Submodules are supported by nesting module definitions.
  2. open <module>;. Opens a module and introduces the contents in the module so that the user can refer to them directly by name without module name. Effective till the end of the scope open is in. See Introduce name resolution phase #12 for name conflict/ambiguity issues.
  3. open <module> using <name>,...;. A variant on open that only introduces names the user specified. This is useful for users to avoid name conflict issues, especially on large modules like std.
  4. import <filename>. This allows for multi-file programs. Definitions in another file would need to be imported first before being able to be used. import should only appear on the outer most scope and would import the files in the given order. At current, we can assume that all user code files are in one flat directory, and that the standard library is in one file and is always imported (unless we really need to separate that into multiple files). We would need to do some sort of circular dependency/duplicate import checking.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
design Discussion of design issues
Projects
None yet
Development

No branches or pull requests

2 participants