neko icon indicating copy to clipboard operation
neko copied to clipboard

Invalid_argument(Array.get) from nekoc

Open btiffin opened this issue 7 years ago • 1 comments

This should be infinite loop code, I think, while experimenting with Neko programming.

prompt$ cat gotos.neko
$print("start");
$goto(next);

$print("skip");

next:
$print("continue");
$goto(end);

$print("skip");

end: 
$print("end");

$goto(next);

Instead, the VM translation fails

prompt$ nekoc gotos.neko
Called from neko/Main.nml line 153 
Called from core/Args.nml line 57
Called from neko/Main.nml line 68
Called from core/Array.nml line 120
Called from neko/Bytecode.nml line 320
Called from core/Core.nml line 179
Called from core/Core.nml line 212
Exception : Invalid_argument(Array.get)

Fedora 27, from packages nekovm, nekovm-devel 2.2.0-4 x86_64

Replace the last $goto and all goes well.

btiffin avatar Aug 15 '18 16:08 btiffin

I can reproduce it with ToT revision on FreeBSD. It looks like an out-of-bounds error from the code calculating the jump target.

$ cat go2.neko
$print("start");

next:
$print("continue");

$goto(next);

$ bin/nekoc go2.neko
Called from neko/Main.nml line 153
Called from core/Args.nml line 57
Called from neko/Main.nml line 68
Called from core/Array.nml line 120
Called from neko/Bytecode.nml line 320
Called from core/Core.nml line 179
Called from core/Core.nml line 212
Exception : Invalid_argument(Array.get)

What is interesting, is that removing the first $print makes the error go away as well:

$ cat go2+.neko
next:
$print("continue");

$goto(next);

$ bin/nekoc go2+.neko
$

ppenzin avatar Aug 16 '18 01:08 ppenzin