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

Implement module system for stdlib (msingi) and local libs (hapa) #97

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

gekkowrld
Copy link
Contributor

The module system is now nearly complete.

The module system is file based.
You can import a file (don't include the extension)
File extensions MUST be .nuru.
You can nest as deep as possible but the last part MUST always be a file.
e.g tumia d1::d2::d3::...::d99::f
Aliasing can be used e.g tumia lan::fr = en

The msingi and hapa resolutions are done and can be used.
Outside modules have not yet been implemented.
This can be bypassed by using vendoring system(s).

To use a module from std, just write

tumia msingi::hisabati

andika("Thamani ya PI ni {0}".panga(hisabati.PI()))

If the module name already exists, you can add = alias to change the name used.

tumia msingi::hisabati = math

andika("The value of PI is {0}".panga(math.PI()))

For the internal modules, then the syntax to be used is tumia hapa::faili

tumia hapa::majina

andika("Jina la pili ni {0}".panga(majina.pili()))

External modules are yet to be supported as of now.

A simple module that for now only works for the std lib.
The std lib is named as `mkt`.

A simple import can look like:
    where::file
    or
    where::dirs::file

The file is the last part of the import.

An example:

```nuru
tumia mkt::hisabati

andika("Thamani ya PI ni: {0}\n".panga(hisabati.PI()))
```

Faili hizi zinatafutwa:
    kwenye thamani ya mazingira: MAKTABA_YA_NURU
	mfano: MAKTABA_YA_NURU=$HOME/code/nr/maktaba
    -> /usr/lib/nuru/maktaba (something similar in Windows)
    -> /lib/nuru/maktaba

Kama haitapatikana hapo, kutakuwa na kosa kuonyesha kuwa haijapatikana.
Kwa sasa maktaba ya kawaida hayaandikwa, mifano hii haitafanya.

Maktaba ya awali yalikuwa yameandikwa kwa lugha ya programu ya Go.
Kutumia mabadilisho yanatumahi kuanzisha kuandika maktaba ya kawaida
kwenye lugha ya programu ya Nuru.

Faili zitakazo angaliwa ni ".nuru" badala ya zile za awali za ".sw" ama
".nr".

Signed-off-by: Gekko Wrld <[email protected]>
The module directory has been removed to make way for start of std
rewriting.

Signed-off-by: Gekko Wrld <[email protected]>
From previous changes, the tests started to fail because of added
<NEWLINE> token.

This is now fixed for most modules except the evaluator module.
The remaining problem may be related to the NEWLINE token.
The tests check the last token, which previously would be the value.
But now the last token would be the NEWLINE instead of another token
like INTEGER.

When running, the code works correctly.
This strongly indicates the problem to be in the tests instead of the
code (unlike the other tests).

Signed-off-by: Gekko Wrld <[email protected]>
Some modules were hardcoded, this has been removed.
Tests pass as before (except module related ones which don't currently
exist, and evaluator ones ofc).

Signed-off-by: Gekko Wrld <[email protected]>
Modules that are referenced by `hapa` e.g:
    tumia hapa::faili
can be read succesfully.

Add a new information to the token `Filename`.
This is used for resolving, so its empty in most parts.
its initialized by the import parser.

The stdlib will be referenced by `msingi` instead of `mkt`.
This is more approriate and sensible than the last.

Signed-off-by: Gekko Wrld <[email protected]>
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.

1 participant