zetavm: Stack traces on exceptions & assert

Currently, every call site has an src_pos attribute which we can report in the stack trace.

@krypt-n pointed out that we may want to make sure to set the name attribute on every function, as much as possible. This will have to be handled at the parser level.

Another issue we need to discuss is that currently, assert maps to the abort instruction in the VM, which halts program execution. We have to decide whether we want to make assert simply throw an exception as in Python or keep the current behavior. The current behavior is based on the idea that assert is for circumstances which we really expect to be impossible, for sanity checks, whereas exceptions are for errors which we anticipate people could trigger.

If we make assert simply map to exceptions, things may be simpler, implementation-wise, because we wouldn’t have to add stack traces to abort. However, if we keep the abort instruction, we probably want stack traces anyway, so there is also a discussion to be had as to whether that instruction should be kept or not.

About this issue

  • Original URL
  • State: open
  • Created 7 years ago
  • Comments: 17 (17 by maintainers)

Most upvoted comments

Once again, I have to apologise for my absence. I should have at least shared my progress on this issue before staying silent for two months. https://github.com/krypt-n/zetavm/commit/82c0995e97ca5dad5dcbbbae7d39fc0fc3f5ba2b

test.pls:

#language "lang/plush/0"


var a = function() 
{
    throw "blub";
};

var b = function()
{
   a(); 
};

b();
$ ./zeta test.pls
ERROR: blub
in a at unknown location
in b at test.pls@11:5
in top-level at test.pls@14:2

TODO:

  • check position information on throw
    • Position information on runtimeCalls was missing
  • improve function name heuristics
  • handle RunError conversion if thrown inside VM context