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

idea: add namespace management #4

Open
ghost opened this issue Aug 14, 2020 · 6 comments
Open

idea: add namespace management #4

ghost opened this issue Aug 14, 2020 · 6 comments
Labels
wontfix This will not be worked on

Comments

@ghost
Copy link

ghost commented Aug 14, 2020

@haifenghuang

You can add something like this:

from module include *

function() // instead of module.function()

The magpie is amazing! Thanks!

@haifenghuang
Copy link
Owner

For the moment, I have no plan of adding this. Maybe someday I'll add this support.

@ghost
Copy link
Author

ghost commented Aug 17, 2020

@haifenghuang why I can’t include magpie modules?

include os // returns an error module not found
include net // too

Are they included by default? And is there any way to do not include them by default?

@haifenghuang
Copy link
Owner

haifenghuang commented Aug 18, 2020

You don't need to include os or net because they are built-in modules. You just need to use them, Take os built-in module for an example:

println(os.args())
println(os.getenv("PATH"))
println(os.getwd())
println(os.PATH_SEPARATOR)

Which methods or constants the os module contain? You can take a look at os.go source file. Particularly SetGlobalObj and CallMethod.

BTW, there is no way to not include them by default, sorry for this.

But..., If you really do not want to include them by default, then you must modify the source. How?
In object.go, there is a init method, which registers all the built-in modules. You can comment the modules you don't want.
for example, you don't want the os module, then you could comment NewOsObj() line.

@ghost
Copy link
Author

ghost commented Aug 18, 2020

@haifenghuang I want to add ability to include this modules from:

func (p *Parser) getIncludedStatements(importpath string) (*ast.Program, error) { ... }

Can I add NewOsObj() to parser.go to getIncludedStatements. Is a NewOsObj() the part of object.go and can I import this function to parser.go?

Thanks

@haifenghuang
Copy link
Owner

I think you can not do it.

If you check the os.go or object.go, You can see that they are all dealing with object, not AST(Abstract Syntax Tree).

What I mean is that in parser phase, it deals with AST, but in evaluator phase, it mainly deals with object.
They are different phases of the processing.

@haifenghuang
Copy link
Owner

haifenghuang commented Aug 18, 2020

For your understanding, the magpie interpreter works like below:

   Lexer---->Parser---->Evaluator

Below table lists the input & output of each phase:

Input Phase Output
source Lexer token
token Parser AST
AST Evaluator object

@haifenghuang haifenghuang added the wontfix This will not be worked on label Aug 25, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
wontfix This will not be worked on
Projects
None yet
Development

No branches or pull requests

1 participant