vermaseren / form

The FORM project for symbolic manipulation of very big expressions
GNU General Public License v3.0
1.16k stars 138 forks source link

Compile/runtime error with the filename and line number? #148

Open tueda opened 7 years ago

tueda commented 7 years ago

It would be nice if we could know the filename and line number when a compile/runtime error occurred. Currently what we can get is something like

MyCoolAndLongProcedure Line 2798 --> Unrecognized statement

or

Term too complex during normalization

   48014  152  24005  0  24002  0  8  1  4  3019  1  1  1  3  8  1  4  3018  1
     1  1  3  8  1  4  3017  1  1  1  3  8  1  4  3016  1  1  1  3  8  1  4
   3015  1  1  1  3  8  1  4  3014  1  1  1  3  8  1  4  3013  1  1  1  3  8
   1  4  3012  1  1  1  3  8  1  4  3011  1  1  1  3  8  1  4  3010  1  1  1
   3  8  1  4  3009  1  1  1  3  8  1  4  3008  1  1  1  3  8  1  4  3007  1
   1  1  3  8  1  4  3006  1  1  1  3  8  1  4  3005  1  1  1  3  8  1  4
   3004  1  1  1  3  8  1  4  3003  1  1  1  3  8  1  4  3002  1  1  1  3  8
   1  4  3001  1  1  1  3  8  1  4  3000  1  1  1  3  8  1  4  2999  1  1  1
   ...

For compilation errors, one can argue that what I need to do to go to the line in my editor is just typing /MyCoolAndLongProcedure<CR>2798j instead of 6294gg, but definitely 6294gg is easier to type and the former may not be easy for some editors. (OK, one could argue that we should ignore people who use minor editors that are not (neo)vim or stedi.) In principle such line information can be stored when #procedure is processed.

For runtime errors, the compiler buffer may store the line information such that they can be mapped from the program counter. But it would be not trivial to print error messages with the line information in core functions in deep (e.g., in reken.c) that currently just calls Terminate(-1) when an error occurs.

In modern programming languages, it can be easily solved by separating the code printing error messages from the point where an error occurs by just raising an exception, like

void Generator_or_Normalize(int program_counter) {
  try {
    ...
  } catch(const std::exception &e) {
    MesPrint(<use the program_counter and e->what()>)
  }
}

void Function_in_Deep(WORD *term) {
  ...
  if ([[unlikely]] has_error()) {
    throw some_error("an error occurred because blah blah blah...")
  }
  ...
}

but not so trivial in C.