Written the constructor for exceptions; in the process, added a
metadata slot as a first class slot of exceptions.
This commit is contained in:
parent
f915a9993f
commit
83537391a6
11 changed files with 85 additions and 20 deletions
|
|
@ -11,16 +11,45 @@
|
|||
#include "memory/node.h"
|
||||
#include "memory/pointer.h"
|
||||
#include "memory/pso.h"
|
||||
#include "memory/pso3.h"
|
||||
#include "memory/pso4.h"
|
||||
#include "memory/tags.h"
|
||||
|
||||
#include "payloads/exception.h"
|
||||
|
||||
#include "ops/truth.h"
|
||||
|
||||
/**
|
||||
* @brief allocate an exception object, and, if successful, return a pointer
|
||||
* to it.
|
||||
*
|
||||
* Throwing an exception while generating an exception is meaningless. If
|
||||
* allocation fails utterly (i.e. out of heap, out of page space) this will
|
||||
* have to return `nil`, which might give rise to hard to trace bugs. But
|
||||
* otherwise it will return a pointer to a new exception.
|
||||
*
|
||||
* @param message expected to be a string, but anything printable is accepted.
|
||||
* @param frame the stack frame in which the exception was `thrown`, if any.
|
||||
* @param meta metadata for this exception. Must be an assoc list, hashtable,
|
||||
* or `nil`
|
||||
* @param cause the exception that caused this exception to be `thrown`.
|
||||
*/
|
||||
struct pso_pointer make_exception( struct pso_pointer message,
|
||||
struct pso_pointer frame_pointer,
|
||||
struct pso_pointer frame,
|
||||
struct pso_pointer meta,
|
||||
struct pso_pointer cause ) {
|
||||
// TODO: not yet implemented
|
||||
return nil;
|
||||
struct pso_pointer result = allocate(EXCEPTIONTAG, 3);
|
||||
|
||||
if (!nilp(result) && !exceptionp(result)) {
|
||||
struct pso3* object = (struct pso3*)pointer_to_object( result);
|
||||
|
||||
object->payload.exception.message = message;
|
||||
object->payload.exception.stack = stackp(frame) ? frame : nil;
|
||||
object->payload.exception.meta = (consp(meta) || hashtabp(meta)) ? meta : nil;
|
||||
object->payload.exception.cause = exceptionp(cause) ? cause : nil;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -34,8 +63,12 @@ struct pso_pointer destroy_exception( struct pso_pointer fp,
|
|||
if ( stackp( fp ) ) {
|
||||
struct pso4 *frame = pointer_to_pso4( fp );
|
||||
struct pso_pointer p = frame->payload.stack_frame.arg[0];
|
||||
struct pso3* object = (struct pso3*)pointer_to_object( p);
|
||||
|
||||
// TODO: decrement every pointer indicated by an exception.
|
||||
dec_ref( object->payload.exception.message);
|
||||
dec_ref( object->payload.exception.stack);
|
||||
dec_ref( object->payload.exception.meta);
|
||||
dec_ref( object->payload.exception.cause);
|
||||
}
|
||||
|
||||
return nil;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue