Next: , Previous: , Up: Executive Assembler Introduction   [Index]


8.1.6 The Error Reporters

Most of the program execution errors will be reported by the aime libraries. An error reporter construct is required by the error reporting libaime routines.

See Error Reporter Construct.

The error report introducing routine:

static int
line_flat(void *context)
{
    struct context_type *context_data;

    context_data = context;

    fflush(stdout);
    fputs(context_data->self, stderr);
    fputs(":", stderr);
    if (context_data->program) {
	fputs(" ", stderr);
	fputs(context_data->program, stderr);
	fputs(":", stderr);
    }
    if (1) {
	int (*line)(struct context_type *, unsigned *);

	line = context_data->line;
	if (line) {
	    unsigned copy, miss;

Display the line number:

	    line(context, &copy);
	    seek_line(context, copy, &miss);
	    fprintf(stderr, " %u:", miss + 1);
	}
    }

    fputs(" ", stderr);

    return 0;
}

The error report constructor routine:

static int
push_flat(void *context, const char *data, unsigned size)
{
    fwrite(data, size, 1, stderr);

    return 0;
}

The error report poster routine:

static int
post_flat(void *context)
{

Set the "error reported" flag:

    ((struct context_type *) context)->error = 1;

    fputs("\n", stderr);

    return 0;
}

The errors not reported during program execution are reported later by the standalone interpreter:

static int
flush_error(struct context_type *context_data, const char *program)
{

Check whether the error was reported already:

    if (context_data->error) {
    } else {
	fflush(stdout);
	fprintf(stderr, "%s:", context_data->self);
	if (program) {
	    fprintf(stderr, " %s:", program);
	}
	if (1) {
	    int (*line)(struct context_type *, unsigned *);

	    line = context_data->line;
	    if (line) {
		unsigned copy, miss;

Display the line number:

		line(context_data, &copy);
		seek_line(context_data, copy, &miss);
		fprintf(stderr, " %u:", miss + 1);
	    }
	}

	fprintf(stderr, " cannot execute program\n");
    }

    return 17;
}

The function calculating the source line number corresponding the error:

static int
seek_line(struct context_type *context_data, unsigned copy, unsigned *miss)
{
    const char *data;
    unsigned line = 0;

    data = context_data->data;
    while (copy) {
	if (*data == '\n') {
	    line++;
	}

	copy--;
	data++;
    }

    *miss = line;

    return 0;
}

Next: The Library Object Constructors, Previous: The Resource Management, Up: Executive Assembler Introduction   [Index]