Lhogho  0.0.028
 All Data Structures Files Functions Variables Typedefs Macros Pages
errors.h File Reference

Go to the source code of this file.

Macros

#define FORMAT_ERR_CODE   TEXT("{ERR#%d")
 
#define FORMAT_ERR_POS   TEXT("@%d}")
 

Functions

void init_errors ()
 initializes errors More...
 
void finit_errors ()
 finalizes errors More...
 
atom_t new_error (uint_t code, atom_t data)
 creates a new error atom More...
 
atom_t new_os_error (chars_t filename)
 creates error atom for OS error More...
 
atom_t new_os_error_atom (atom_t filename)
 
atom_t new_parse_error (uint_t code, int position, atom_t source)
 creates error atom for parser's error More...
 
void add_error_source (atom_t error, atom_t source)
 adds new error position to an error More...
 
int get_error_position (atom_t data, chars_t *source)
 gets error position More...
 
void delete_error (atom_t a)
 deletes error atom More...
 
void dump_error (atom_t a, int level)
 dumps error atom More...
 
void clear_all_errors ()
 clears all errors More...
 

Variables

atom_t error_texts []
 Texts for error messages. More...
 
int last_os_error
 records last OS error code More...
 

Exit codes

See Errors for details

#define ERROR_INCOMPLETE_PAIR   1
 
#define ERROR_EMPTY_EXPRESSION   2
 
#define ERROR_CROWDED_EXPRESSION   3
 
#define ERROR_MISSING_LEFTS   4
 
#define ERROR_MISSING_RIGHTS   5
 
#define ERROR_EMPTY_TO_END   6
 
#define ERROR_MISSING_NAME   7
 
#define ERROR_DUPLICATE_INPUT   8
 
#define ERROR_UNKNOWN_OPTION   9
 
#define ERROR_CROWDED_SOURCES   10
 
#define ERROR_OS_ERROR   11
 
#define ERROR_INCOMPATIBLE_REDEFINITION   12
 
#define ERROR_NOT_A_NUMBER   13
 
#define ERROR_UNUSED_VALUE   14
 
#define ERROR_MISSING_VALUE   15
 
#define ERROR_DO_NOT_KNOW   16
 
#define ERROR_UNKNOWN_VAR   17
 
#define ERROR_BOOLEAN_EXPECTED   18
 
#define ERROR_NOT_AN_INTEGER   19
 
#define ERROR_NOT_A_LIST   20
 
#define ERROR_NOT_A_WORD   21
 
#define ERROR_INCOMPATIBLE_DATA   22
 
#define ERROR_TOO_BIG_NUMBER   23
 
#define ERROR_TOO_SMALL_NUMBER   24
 
#define ERROR_NOT_A_VAR   25
 
#define EXIT_BY_BYE   26
 
#define EXIT_BY_THROW_TOPLEVEL   27
 
#define EXIT_BY_THROW_SYSTEM   28
 
#define EXIT_BY_THROW_ERROR   29
 
#define EXIT_BY_THROW_USER_ERROR   30
 
#define EXIT_BY_THROW_TAG   31
 
#define EXIT_BY_THROW_TAG_VALUE   32
 
#define ERROR_NOT_A_TAG   33
 
#define ERROR_NOT_A_USER_FUNCTION   34
 
#define ERROR_VAR_HAS_NO_VALUE   35
 
#define ERROR_NOT_A_FUNCTION   36
 
#define ERROR_NOT_A_LIST_CONST   37
 
#define ERROR_NOT_A_WORD_CONST   38
 
#define ERROR_MISSING_FOR_LIMITS   39
 
#define ERROR_NOT_A_TYPE_NAME   40
 
#define ERROR_BAD_PROTOTYPE   41
 
#define ERROR_NOT_A_MEM   42
 
#define ERROR_OUT_OF_MEM   43
 
#define ERROR_FILE_NOT_OPENED   44
 
#define ERROR_NOT_BLOCK_OR_DEF   45
 
#define FIRST_EXIT_CODE   26
 first EXIT_ code More...
 
#define LAST_EXIT_CODE   32
 last EXIT_ code More...
 
#define LAST_ERROR_CODE   45
 last (max) error or exit code More...
 

Error fields

These macros are used to access errors. Error code is in ERRCODE(), error source is in ERRSRC(), and the error position within the source is in ERRPOS().

#define ERRCODE(x)   ((x)->unode.s[3])
 
#define ERRPOS(x)   ((x)->unode.a[2])
 
#define ERRDATA(x)   ((x)->unode.a[3])
 
#define IS_ERROR(x)   (ID(x)==ERROR_ID)
 

Macro Definition Documentation

#define ERROR_INCOMPLETE_PAIR   1

Definition at line 67 of file errors.h.

#define ERROR_EMPTY_EXPRESSION   2

Definition at line 68 of file errors.h.

#define ERROR_CROWDED_EXPRESSION   3

Definition at line 69 of file errors.h.

#define ERROR_MISSING_LEFTS   4

Definition at line 70 of file errors.h.

#define ERROR_MISSING_RIGHTS   5

Definition at line 71 of file errors.h.

#define ERROR_EMPTY_TO_END   6

Definition at line 72 of file errors.h.

#define ERROR_MISSING_NAME   7

Definition at line 73 of file errors.h.

#define ERROR_DUPLICATE_INPUT   8

Definition at line 74 of file errors.h.

#define ERROR_UNKNOWN_OPTION   9

Definition at line 75 of file errors.h.

#define ERROR_CROWDED_SOURCES   10

Definition at line 76 of file errors.h.

#define ERROR_OS_ERROR   11

Definition at line 77 of file errors.h.

#define ERROR_INCOMPATIBLE_REDEFINITION   12

Definition at line 78 of file errors.h.

#define ERROR_NOT_A_NUMBER   13

Definition at line 79 of file errors.h.

#define ERROR_UNUSED_VALUE   14

Definition at line 80 of file errors.h.

#define ERROR_MISSING_VALUE   15

Definition at line 81 of file errors.h.

#define ERROR_DO_NOT_KNOW   16

Definition at line 82 of file errors.h.

#define ERROR_UNKNOWN_VAR   17

Definition at line 83 of file errors.h.

#define ERROR_BOOLEAN_EXPECTED   18

Definition at line 84 of file errors.h.

#define ERROR_NOT_AN_INTEGER   19

Definition at line 85 of file errors.h.

#define ERROR_NOT_A_LIST   20

Definition at line 86 of file errors.h.

#define ERROR_NOT_A_WORD   21

Definition at line 87 of file errors.h.

#define ERROR_INCOMPATIBLE_DATA   22

Definition at line 88 of file errors.h.

#define ERROR_TOO_BIG_NUMBER   23

Definition at line 89 of file errors.h.

#define ERROR_TOO_SMALL_NUMBER   24

Definition at line 90 of file errors.h.

#define ERROR_NOT_A_VAR   25

Definition at line 91 of file errors.h.

#define EXIT_BY_BYE   26

Definition at line 92 of file errors.h.

#define EXIT_BY_THROW_TOPLEVEL   27

Definition at line 93 of file errors.h.

#define EXIT_BY_THROW_SYSTEM   28

Definition at line 94 of file errors.h.

#define EXIT_BY_THROW_ERROR   29

Definition at line 95 of file errors.h.

#define EXIT_BY_THROW_USER_ERROR   30

Definition at line 96 of file errors.h.

#define EXIT_BY_THROW_TAG   31

Definition at line 97 of file errors.h.

#define EXIT_BY_THROW_TAG_VALUE   32

Definition at line 98 of file errors.h.

#define ERROR_NOT_A_TAG   33

Definition at line 99 of file errors.h.

#define ERROR_NOT_A_USER_FUNCTION   34

Definition at line 100 of file errors.h.

#define ERROR_VAR_HAS_NO_VALUE   35

Definition at line 101 of file errors.h.

#define ERROR_NOT_A_FUNCTION   36

Definition at line 102 of file errors.h.

#define ERROR_NOT_A_LIST_CONST   37

Definition at line 103 of file errors.h.

#define ERROR_NOT_A_WORD_CONST   38

Definition at line 104 of file errors.h.

#define ERROR_MISSING_FOR_LIMITS   39

Definition at line 105 of file errors.h.

#define ERROR_NOT_A_TYPE_NAME   40

Definition at line 106 of file errors.h.

#define ERROR_BAD_PROTOTYPE   41

Definition at line 107 of file errors.h.

#define ERROR_NOT_A_MEM   42

Definition at line 108 of file errors.h.

#define ERROR_OUT_OF_MEM   43

Definition at line 109 of file errors.h.

#define ERROR_FILE_NOT_OPENED   44

Definition at line 110 of file errors.h.

#define ERROR_NOT_BLOCK_OR_DEF   45

Definition at line 111 of file errors.h.

#define FIRST_EXIT_CODE   26

Definition at line 115 of file errors.h.

#define LAST_EXIT_CODE   32

Definition at line 116 of file errors.h.

#define LAST_ERROR_CODE   45

Definition at line 117 of file errors.h.

#define ERRCODE (   x)    ((x)->unode.s[3])

Definition at line 127 of file errors.h.

#define ERRPOS (   x)    ((x)->unode.a[2])

Definition at line 128 of file errors.h.

#define ERRDATA (   x)    ((x)->unode.a[3])

Definition at line 129 of file errors.h.

#define IS_ERROR (   x)    (ID(x)==ERROR_ID)

Definition at line 131 of file errors.h.

#define FORMAT_ERR_CODE   TEXT("{ERR#%d")

Definition at line 135 of file errors.h.

#define FORMAT_ERR_POS   TEXT("@%d}")

Definition at line 136 of file errors.h.

Function Documentation

void init_errors ( )

Initializes the table with error messages taken from TR_ERRORS.

Definition at line 91 of file errors.c.

92 {
93  error_texts[0] = unbound;
94 
95  atom_t names = new_word( TR_ERRORS, UNKNOWN );
96  atom_t tokens = tokenize( names, TOKENIZE_DATA );
97  atom_t t = tokens;
98 
99  // create error texts
100  int i;
101  for( i = 1; i<=LAST_ERROR_CODE; i++, t=CDR(t) )
102  {
103  #ifdef SAFEMODE
104  assert( IS_NOT_EMPTY(t) ); // too few words in TR_PRIMITIVES
105  #endif
106 
107  error_texts[i] = USE(CAR(t));
108  }
109 
110  #ifdef SAFEMODE
111  assert( IS_EMPTY(t) ); // too many words in TR_PRIMITIVES
112  #endif
113 
114  DEUSE( names );
115  DEUSE( tokens );
116 }
void finit_errors ( )

Frees atoms holding error texts.

Definition at line 127 of file errors.c.

128 {
129  int i;
130  for( i = 1; i<=LAST_ERROR_CODE; i++ )
131  {
132  DEUSE(error_texts[i]);
133  }
134 }
atom_t new_error ( uint_t  code,
atom_t  data 
)
Parameters
codeerror code
dataerror data
Returns
error atom

Creates an error atom with reference count 1. The reference count of data is increased. Initializes the error position to be a list containing one element, which is the data parameter itself.

Definition at line 152 of file errors.c.

153 {
154  //printf("-----------\n");
155  //printf("new error code=%d\n",code);
156  //printf("new error data="); dumpln(data);
157  //printf("-----------\n");
158 
160 
161  #ifdef SAFEMODE
162  assert( data );
163  #endif //SAFEMODE
164 
165  REF(a) = 1;
166  ID(a) = ERROR_ID;
167  ERRCODE(a) = code;
168  ERRPOS(a) = new_list( USE(data), empty_list );
169  ERRDATA(a) = USE(data);
170 
171  #ifdef DEBUG_ATOM
172  printf("<ATOM> [%08x] error=[code=%d]\n",(int)a,code);
173  #endif //DEBUG_ATOM
174 
175  #ifdef ADVANCED
176  stats[ID(a)].allocs++;
177  if( stats[ID(a)].max<(stats[ID(a)].allocs-stats[ID(a)].deallocs) )
178  stats[ID(a)].max=(stats[ID(a)].allocs-stats[ID(a)].deallocs);
179  stats_free--;
180  #endif //ADVANCED
181 
182  #ifdef DEBUG_RUNTIME_ATOMS
184  {
185  outter( TEXT("<RUNTIME> new "), -1 );
186  dump_atom_address( a );
187  dump_atom( a, 1 );
188  outter( TEXT("\n"), -1 );
189  }
190  #endif
191  #ifdef DEBUG_COMPILETIME_ATOMS
192  if( compiling_code )
193  {
194  outter( TEXT("<COMPILETIME> new "), -1 );
195  dump_atom_address( a );
196  dump_atom( a, 1 );
197  outter( TEXT("\n"), -1 );
198  }
199  #endif
200 
203 
204  return a;
205 }
atom_t new_os_error ( chars_t  filename)
Parameters
filenamefile name associated with the error
Returns
error atom

Creates error atom describing OS error.

Definition at line 217 of file errors.c.

218 {
219  atom_t wrd = new_word( filename, UNKNOWN );
220  atom_t res = new_os_error_atom( wrd );
221  DEUSE( wrd );
222  return res;
223  //return new_error( ERROR_OS_ERROR, wrd );
224 }
atom_t new_os_error_atom ( atom_t  filename)

Definition at line 225 of file errors.c.

226 {
227  last_os_error = errno;
228  return new_error( ERROR_OS_ERROR, filename );
229 }
atom_t new_parse_error ( uint_t  code,
int  position,
atom_t  source 
)
Parameters
codeerror code
positioncharacter position within the source
source(sub)word containing the source
Returns
error atom

Creates error atom describing an error generated by the parser.

Definition at line 245 of file errors.c.

246 {
247  atom_t errsrc = new_subword( source, STRING(source)+position, 1 );
248  atom_t error = new_error( code, unbound );
249  CAR(ERRPOS(error)) = errsrc;
250  return error;
251 }
void add_error_source ( atom_t  error,
atom_t  source 
)
Parameters
errorerror to which new position will be added
sourceerror source

Adds a new error position to an already existing error atom. The error position is simply an atom which may have been extracted from the actual source. The new error position is inserted in the first place of the list of error positions.

Definition at line 268 of file errors.c.

269 {
270  //printf("register error pos>>>---------------\n");
271  //printf("register error src>>>"); dumpln(source);
272  //printf("register error err>>>"); dumpln(error);
273  //printf("register error pos>>>---------------\n");
274  //printf("errpos old ref=%d\n",REF(ERRPOS(error)));
275  ERRPOS(error) = new_list( USE(source), ERRPOS(error) );
276  //printf("errpos new ref=%d\n",REF(ERRPOS(error)));
277 }
int get_error_position ( atom_t  data,
chars_t source 
)
Parameters
datadata to search for
sourcesource where the data is found
Returns
position of data within found source

Tries to identify the position of the first (sub)word in the data in the original source. This function returns the character position and the source. If the source cannot be identified, then return -1 and set source to NULL.

Definition at line 314 of file errors.c.

315 {
316  // dig in a list to find the first (sub)word
317  while( IS_LIST(data) & IS_NOT_EMPTY(data) ) data = CAR(data);
318 
319  // if it is a word then return we have found something
320  if( IS_WORD(data) )
321  {
322  *source = STRING(data);
323  return 0;
324  }
325 
326  // if it is a subword then return we have found something
327  if( IS_SUBWORD(data) )
328  {
329  *source = STRING(WORD(data));
330  return STRING(data)-STRING(WORD(data));
331  }
332 
333  // no, could not find the error position
334  *source = NULL;
335  return -1;
336 }
void delete_error ( atom_t  a)
Parameters
aatom to delete

Deletes error atom by returning it back to the data pool. The source atom is dereferenced.

Definition at line 290 of file errors.c.

291 {
292  //printf("****** DELETING ERROR ****** [%x]\n",(int)a);
293  DEUSE( ERRPOS(a) );
294  DEUSE( ERRDATA(a) );
295  return_to_pool( &data_pool, a );
296 }
void dump_error ( atom_t  a,
int  level 
)
Parameters
aatom to dump
leveldump level

Dumps error atom through the current outter function.

Definition at line 411 of file errors.c.

412 {
413  #define DUMP_BUF_SIZE 128
414  char_t buf[DUMP_BUF_SIZE];
415  int n;
416 
417  //printf("<<err ref=%d>> ",REF(a));
418  //printf("temporary dump of an error\n");
419  //printf(">>>>>>error ref = %d\n",REF(a));
420  //printf(">>>>>>error code = %d\n",ERRCODE(a));
421  //printf(">>>>>>error posn = "); dumpln(ERRPOS(a));
422  //printf(">>>>>>error data = "); dumpln(ERRDATA(a));
423  //return;
424 
425  int errpos = -1;
426  int errpos2 = -1;
427  int errpos3 = -1;
428  chars_t errsrc = NULL;
429  chars_t errsrc2 = NULL;
430  chars_t errsrc3 = NULL;
431  atom_t p;
432  //printf("errpos="); dump_atom(ERRPOS(a),1); printf("\n------------\n");
433  for( p=ERRPOS(a); IS_NOT_EMPTY(p); p=CDR(p) )
434  {
435  //printf("ERRPOS=");dumpln(CAR(p));
436  chars_t src;
437  int pos = get_error_position( CAR(p), &src );
438  if( pos>-1 )
439  {
440  errpos3 = errpos2;
441  errsrc3 = errsrc2;
442  errpos2 = errpos;
443  errsrc2 = errsrc;
444  errpos = pos;
445  errsrc = src;
446  }
447  //printf("pos=%d source=",pos); dumpln(CAR(p));
448  }
449 
451  {
452  errpos = errpos3;
453  errsrc = errsrc3;
454  }
455 
456  // print error code
457  n = SPRINTF( buf, DUMP_BUF_SIZE, FORMAT_ERR_CODE, ERRCODE(a) );
458  outter( buf, n );
459 
460  // print error position
461  n = SPRINTF( buf, DUMP_BUF_SIZE, FORMAT_ERR_POS, errpos );
462  outter( buf, n );
463 
464  // print error message
466  {
467  outter( TEXT(" - "), 3 );
468  dump( ERRDATA(a) );
469  }
470  else
471  {
472  #ifdef SAFEMODE
473  assert( ERRCODE(a)>0 );
474  assert( ERRCODE(a)<=LAST_ERROR_CODE );
475  #endif
476  outter( TEXT(" - "), 3 );
477  dump( error_texts[ERRCODE(a)] );
478  }
479 
480  if( ERRCODE(a)==ERROR_OS_ERROR )
481  {
482  chars_t msg = UNFILENAME(strerror(last_os_error));
483  outter( TEXT(": "), 2 );
484  outter( msg, -1 );
485  DEALLOC( msg );
486  }
487  outter( TEXT("\n"), -1 );
488 
489  // print error source
490  dump_neighbourhood( errsrc, errpos );
491 }
void clear_all_errors ( )

Clears all errors recorder in all_errors except for the one stored in last_error

Definition at line 503 of file errors.c.

504 {
505  atom_t err = all_errors;
506  if( err==NULL ) return;
507 
508  //printf("===INSIDE CLEAR_ALL_ERRORS===\n");
509  //printf("===EXCEPTION(%d): ",REF(last_error)); dumpln(last_error);
510  //printf("===ALL ERRORS (BEFORE): "); dumpln(all_errors);
511 
512  //printf("===START ERROR SCANNING===\n");
513  while( IS_NOT_EMPTY(err) )
514  {
515  //printf("===ERROR: [%x]\n",CAR(err));
516  if( CAR(err)!=last_error ) REF(CAR(err)) = 1;
517  err = CDR(err);
518  }
519  //printf("===END ERROR SCANNING===\n");
520 
521  USE( last_error );
522  //printf("AEREF=%d !!!!!!!!!!!!!!!!\n",REF(all_errors));
523  DEUSE( all_errors );
524  //printf("AEREF=%d !!!!!!!!!!!!!!!!\n",REF(all_errors));
525  DEUSE( last_error );
526 
528  //printf("===END OF CLEAR_ALL_ERRORS===\n\n");
529 }

Variable Documentation

atom_t error_texts[]

Definition at line 74 of file errors.c.

int last_os_error

Definition at line 79 of file errors.c.


[ HOME | INDEX | ATOMS | VARS | REFERENCE ]
Lhogho Developer's Documentation
Wed Jul 10 2013