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

are modules supported? #2

Open
naturallymitchell opened this issue Jan 24, 2019 · 1 comment
Open

are modules supported? #2

naturallymitchell opened this issue Jan 24, 2019 · 1 comment

Comments

@naturallymitchell
Copy link

module: a collection of variables and functions contained in a single file

@transistorfet
Copy link
Owner

Yes, modules are supported although I need to improve how they work currently.

At the moment, modules are implicit. Each source file is a module and all the functions and classes at the top level scope of the source file are exported (listed in the module's corresponding .dec file). A module run function is generated for each module that initializes and runs all top level expressions. By passing in the -l flag when compiling, it will not insert a "main" function, so all modules except the entry point should be compiled with -l. Using the "import" keyword, you can import the declarations from another module, and then you can later link the resulting files. There is a limitation atm where you must compile all files from the same directory, or there will be a link error. This is because I used a pretty hacky way of determining the module run function's name, using the import path. The core library, libcore, is a module and the molten script will compile it if necessary and link it to whatever you're trying to run.

I've partially added a means of controlling what symbols are exported, and I will eventually make a means of importing a module as an object to keep the functions scoped under one name, although I'm not yet sure what syntax and semantics I want for that. I will also eventually memoize the module object so that even if a module is "import"ed multiple times, it will only run the module's top level expressions once and return the module object on all subsequent imports.

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

No branches or pull requests

2 participants