Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crash if the program consists of an unused function and nothing else #7

Closed
martin-t opened this issue Apr 17, 2021 · 1 comment
Closed

Comments

@martin-t
Copy link

Example .fml file:

function f() -> print("x\n");

Error (using the run command):

thread 'main' panicked at 'Interpreter error: Code address 0002 out of bounds (0..2)', src/main.rs:141:14

It works fine if the implicit global function contains anything else - e.g. just null.

Version 1 doesn't crash.

My compiler+interpreter has pretty much the same bug - there are 2 causes:

  • With an empty input file, the parser returns a Top which contains a Null node so there's 1 instruction in the generated code. With a file that contains a function but nothing else, the parser returns a Top which contains the function but no other nodes so the implicit global function ends up having 0 instructions.
  • My interpreter first gets the instruction from the code vector (this is the index out of bounds), executes it, then breaks the loop if the instruction pointer has jumped out of the code vector. Moving this check to the start of the loop fixes the crash for me, maybe your interpreter does something similar.
@kondziu
Copy link
Owner

kondziu commented Feb 17, 2022

Fixed by 908314f

@kondziu kondziu closed this as completed Feb 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants