Giter Site home page Giter Site logo

Comments (7)

DeadlySurgeon avatar DeadlySurgeon commented on July 30, 2024

This also extends into EvalContext calling evalProgram which then executes Eval, further dropping the context.

from monkey.

skx avatar skx commented on July 30, 2024

Now you say it .. yes. This is obviously incorrect! Thank you for the bug-report.

If you want to have a stab at resolving it you're welcome, otherwise I'll look at it over the weekend.

from monkey.

DeadlySurgeon avatar DeadlySurgeon commented on July 30, 2024

I think you should take a swing at it. I recommend just temp removing the Eval function, and then any places that call it that are giving an error should just be changed to EvalContext, and then once that's resolved add it back.

from monkey.

skx avatar skx commented on July 30, 2024

I suspect this solution would get messy quickly, since EvalContext passes to evalBlockStatement, etc, etc.

The better change is to add a call to "SetContext", and use that to update the global context variable - which defaults to context.Background, and only test that. There then wouldn't be any difference between Eval and EvalWithContext.

  • Shuffle the code into eval where it used to live.
    • Add the context-testing at the head of that function, using the global variable.
  • EvalWithContext is then a minimal wrapper which does two things:
    • call SetContext to update the global variable.
    • call Eval(...)

Possibly SetContext and the global variable can be local/package-local, rather than externally accessible. That preserves the current API.

from monkey.

DeadlySurgeon avatar DeadlySurgeon commented on July 30, 2024

I wouldn't have a global variable context, that's pretty bad practice. Changing unexported functions isn't a breaking change.

EDIT:
I just noticed the existing global context, and I'd honestly remove it as it isn't concurrent safe and allows for bad flow control.

Also it looks like SetContext is only used in a test file, removing it wouldn't break any other bits if your code base, you could just change your tests to call EvalContext.

from monkey.

skx avatar skx commented on July 30, 2024

Yeah having the global is not great - the issue with this implemetnation is that everything's global, more or less, there should be a struct to start state of the interpreter and mediate access appropriately.

Still it looks like your PR does all the right things and I'll merge that. Thanks for taking the time to report the issue and resolve it.

from monkey.

DeadlySurgeon avatar DeadlySurgeon commented on July 30, 2024

NP. I've been trying to complete my own monkey interpreter for a while and kept getting sidetracked, and seeing your repository has helped a lot in my own pursuit, especially around the part where I parse my tokens into the AST for then further execution.

from monkey.

Related Issues (20)

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.