h3rald / min

A small but practical concatenative programming language and shell
https://min-lang.org
MIT License
311 stars 23 forks source link

Pollution Conflicts #72

Closed ghost closed 3 years ago

ghost commented 3 years ago

I am getting an pollution error when running my ./src/base.min I could get and paste the code here but you should look at my module. Because there are so many used operators in my files. Error is very bad and i am stucked. You may clone and run if you solve that or not i don't know really what must i do? Please don't want to write all error included codes here. It is so long. I don't want to write all of those. But i can say where error is: primeNextImpl. Error says it is polluting - it is joking me! . I controlled and this error occurs when running it with map and mray too.

ghost commented 3 years ago

And i think: there is bug at if . It has returning and this isn't works very well.

ghost commented 3 years ago

It causes pollution error because its returning pollutes my code.

h3rald commented 3 years ago

Alright... so, the operator symbol takes a snapshot of the stack at the start and at the end of the operator code, and it verifies that only the declared output values are added to the stack, nothing else.

Note that the values bound to the declared output values are automatically pushed on the stack at the end of the operator execution or when a return symbol is encountered, so essentially your operator code simply cannot leave anything on the stack, or you will get that error.

Now, one thing that I could add to the error is printing which extra values are left on the stack... but for now you could try adding get-stack puts! in your code to see where the pollution takes place... it's a very common thing really, but it should work properly: I have been testing it this week on my code and every time it happened it wasn't a bug... or better, the bug was in my code. That being said it could also be a bug in one of min native symbols of course...

ghost commented 3 years ago

I think, you don't know what i can make nothing after an error which is unsolved. What you said are true but error exists yet. I am unable to solve because i don't know semantics of statements(if while ...). They are very interesting: https://gist.github.com/f58aa4594c3a53e324a0f60d3489e634.git

h3rald commented 3 years ago

I am reopening this because I need to take a look at your gist: by the looks of it there could be a bug, maybe in the while implementation: from the stack trace it seems to get executed twice at least, and at the end it fires the error.

On the other hand, it may just be the standard trace you get for this kind of error: unfortunately I cannot determine exactly where the problem is within the primeNextImpl operator, BUT I think it should be somewhere in there, and not in the other operators that you implemented (pretty well I may add! 👍), otherwise it would be able to catch the error earlier, in another operator. Or at least that's how it should all work...

ghost commented 3 years ago

I could wait you until the problem goes away.

h3rald commented 3 years ago

Found the problem!

Apparently the implementation of the while symbol has some problems 😞

Unfortunately I introduced the concept of pollution checks only recently, and at the moment there are no checks for native symbols implemented in Nim 😬 erhm...

Alright, I'll release a fix soon!

h3rald commented 3 years ago

Fix released -- tried out your examples and it seems to work properly now!