Check for errors when opening program file.

Add a debug assertion in the reader to catch bugs like the last one.
This commit is contained in:
Jesse D. McDonald 2009-11-14 18:50:35 -06:00
parent 8e34feea0b
commit c1ac1323bf
2 changed files with 23 additions and 14 deletions

View File

@ -621,6 +621,7 @@ static value_t patch_placeholders(reader_state_t *state, value_t v)
for (value_t item = state->ref_alist.value; !is_nil(item); item = _CDDR(item))
{
assert(!is_placeholder(state, _CADR(item)));
tree_replace(&v, item, _CADR(item));
}

View File

@ -45,24 +45,32 @@ int main(int argc, char **argv)
}
else
{
gc_root_t argv_root;
FILE *f = fopen(argv[1], "r");
value_t program;
register_gc_root(&argv_root, NIL);
/* Construct list backward, so that we don't have to reverse it. */
for (int i = argc - 1; i >= 2; --i)
if (f)
{
value_t temp = string_to_value(argv[i]);
argv_root.value = cons(temp, argv_root.value);
gc_root_t argv_root;
value_t program;
register_gc_root(&argv_root, NIL);
/* Construct list backward, so that we don't have to reverse it. */
for (int i = argc - 1; i >= 2; --i)
{
value_t temp = string_to_value(argv[i]);
argv_root.value = cons(temp, argv_root.value);
}
program = read_value(f);
print_value(run_interpreter(program, argv_root.value));
nl();
fclose(f);
unregister_gc_root(&argv_root);
}
else
{
perror(argv[1]);
}
program = read_value(f);
print_value(run_interpreter(program, argv_root.value));
nl();
fclose(f);
unregister_gc_root(&argv_root);
}
return 0;