Work on exception handling, especially around ratio arithmetic

Much simplified but will break things!
This commit is contained in:
Simon Brooke 2021-07-25 17:02:28 +01:00
parent d2101dbd47
commit 70d176982b
No known key found for this signature in database
GPG key ID: A7A4F18D1D4DF987
14 changed files with 298 additions and 258 deletions

View file

@ -110,6 +110,37 @@ struct cons_pointer eval_forms( struct stack_frame *frame,
return c_reverse( result);
}
/**
* OK, the idea here (and I know this is less than perfect) is that the basic `try`
* function in PSSE takes two arguments, the first, `body`, being a list of forms,
* and the second, `catch`, being a catch handler (which is also a list of forms).
* Forms from `body` are evaluated in turn until one returns an exception object,
* or until the list is exhausted. If the list was exhausted, then the value of
* evaluating the last form in `body` is returned. If an exception was encountered,
* then each of the forms in `catch` is evaluated and the value of the last of
* those is returned.
*
* This is experimental. It almost certainly WILL change.
*/
struct cons_pointer lisp_try(struct stack_frame *frame,
struct cons_pointer frame_pointer,
struct cons_pointer env) {
struct cons_pointer result = c_progn(frame, frame_pointer, frame->arg[0], env);
if (exceptionp(result))
{
// TODO: need to put the exception into the environment!
result = c_progn(frame, frame_pointer, frame->arg[1],
make_cons(
make_cons(c_string_to_lisp_keyword(L"*exception*"),
result),
env));
}
return result;
}
/**
* Return the object list (root namespace).
*
@ -251,6 +282,11 @@ eval_lambda( struct cons_space_object cell, struct stack_frame *frame,
dec_ref( result );
result = eval_form( frame, frame_pointer, sexpr, new_env );
if (exceptionp(result))
{
break;
}
}
dec_ref( new_env );