arturo-lang / arturo

Simple, expressive & portable programming language for efficient scripting
http://arturo-lang.io
MIT License
682 stars 29 forks source link

Certain incomplete statements/functions result in a crash (Windows) #1193

Open ghost opened 1 year ago

ghost commented 1 year ago

Describe the bug The following statements, when written and then executed as-is, will result in a crash: "?/switch", "if", "if?", "a:".

To Reproduce Steps to reproduce the behavior:

  1. Open arturo.exe
  2. Type one of the mentioned statements (Ex: "?")
  3. Press enter
  4. The program crashes instantly

Expected behavior For it to return a normal runtime error

Desktop (please complete the following information):

Additional context I've tested all other keywords/statements/functions on the "In a Nutshell" page.

github-actions[bot] commented 1 year ago

Thank you for submitting an issue! :)

RickBarretto commented 1 year ago

Thanks for submitting this! We will have a look soon!

drkameleon commented 1 year ago

The following statements, when written and then executed as-is, will result in a crash: "?/switch", "if", "if?", "a:".

Thanks for mentioning this! 🚀

All this probably results from either AST transformations or - less likely - bytecode generation. So, we'll definitely have to deal with this.

Probably related: #1083, #1099

RickBarretto commented 1 year ago

image image

It don't seems to be at parser time... If I would guess something, I would say it probably can be an issue with Any as first argument... But, who knows...

drkameleon commented 1 year ago

@RickBarretto

Well, the pure parser phase (vm/parse) is usually innocuous. I mean it just takes the text/script and converts it into values. That's pretty much the safest part of the whole VM.

Now, the next step is the AST... which converts it into a tree. In that particular case (of if), there is however something particular: https://github.com/arturo-lang/arturo/blob/master/src/vm/ast.nim#L497

Basically, these are call nodes, but marked as "special" (have a look ^).

What "special" means is that the bytecode generator (vm/eval) handles them... in a special way (= ultra-optimized code generation). And here's where the magic happens:

https://github.com/arturo-lang/arturo/blob/master/src/vm/eval.nim#L418-L464

most of it pointing here: https://github.com/arturo-lang/arturo/blob/master/src/vm/eval.nim#L251

Not the easiest code, by far... but I guess this is the source of the issue. Now. should we deal with that there? Perhaps, the answer would be that we should have dealt with it before: that is, before even reaching the bytecode level; and that location would be the AST, where we actually generate the node. But not sure...

I'll have to investigate! 😉

RickBarretto commented 1 year ago

Exactly that! I tested while and unless/? too... They are having the same problem.

drkameleon commented 1 year ago

The "problematic" ones are well spotted... and unfortunately all related to the exact same thing... Let's see...

stale[bot] commented 5 months ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] commented 1 month ago

Closing issue as stale.