Comments (7)
This also extends into EvalContext
calling evalProgram
which then executes Eval
, further dropping the context.
from monkey.
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.
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.
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.
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.
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.
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)
- Encountered a panic when attempting to retrieve an index value from a string HOT 1
- Encountered an issue when using backtick literals HOT 1
- Implement the range operator
- Crash with array.find
- Literal regular expressions should allow captures
- Implement switch-statements
- Updated embedded "standard-library" for go-implant
- call function from go HOT 1
- CI process not reporting an error.
- Ability to cancel a running Monkey Script HOT 1
- Feat: add code export and import HOT 2
- Add support for `elif` HOT 2
- Need help in adding Object Methods! HOT 5
- Asked some more stuff in #87 HOT 1
- execute env.mon got : identifier not found: self HOT 1
- iteration.mon : wrong hash key/value HOT 2
- Regex Built In should avoid MustCompile to avoid potential panic
- Range operator assumes increasing direction
- Add fuzz-testing HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from monkey.