Coder Social home page Coder Social logo

idea: add namespace management about magpie HOT 6 OPEN

 avatar commented on July 29, 2024
idea: add namespace management

from magpie.

Comments (6)

haifenghuang avatar haifenghuang commented on July 29, 2024

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

from magpie.

 avatar commented on July 29, 2024

@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?

from magpie.

haifenghuang avatar haifenghuang commented on July 29, 2024

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.

from magpie.

 avatar commented on July 29, 2024

@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

from magpie.

haifenghuang avatar haifenghuang commented on July 29, 2024

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.

from magpie.

haifenghuang avatar haifenghuang commented on July 29, 2024

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

from magpie.

Related Issues (17)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.