klisp

an open source interpreter for the Kernel Programming Language.
git clone http://git.hanabi.in/repos/klisp.git
Log | Files | Refs | README

commit ba957d7aafdabae3fdb87a63d7c59847272b9faa
parent d48fa2c9528abf5b53af1a0f6cae1470ba39e96c
Author: Andres Navarro <canavarro82@gmail.com>
Date:   Thu, 28 Apr 2011 16:51:06 -0300

Added constructor for error objects.

Diffstat:
Msrc/kerror.c | 19+++++++++++++++++++
Msrc/kerror.h | 2++
Msrc/kobject.h | 2+-
3 files changed, 22 insertions(+), 1 deletion(-)

diff --git a/src/kerror.c b/src/kerror.c @@ -9,6 +9,25 @@ #include "kmem.h" #include "kstring.h" +/* GC: assumes all objs passed are rooted */ +TValue klispE_new(klisp_State *K, TValue who, TValue cont, TValue msg, + TValue irritants) +{ + Error *new_error = klispM_new(K, Error); + + /* header + gc_fields */ + klispC_link(K, (GCObject *) new_error, K_TERROR, 0); + + /* error specific fields */ + new_error->who = who; + new_error->cont = cont; + new_error->msg = msg; + new_error->irritants = irritants; + + return gc2error(new_error); +} + + /* XXX: the msg buffers should be statically allocated and msgs should be copied there, otherwise problems may occur if the objects whose buffers were passed as parameters get GCted */ diff --git a/src/kerror.h b/src/kerror.h @@ -13,6 +13,8 @@ #include "klisp.h" #include "kstate.h" +TValue klispE_new(klisp_State *K, TValue who, TValue cont, TValue msg, + TValue irritants); void klispE_throw(klisp_State *K, char *msg); /* TEMP: for throwing with extra msg info */ void klispE_throw_extra(klisp_State *K, char *msg, char *extra_msg); diff --git a/src/kobject.h b/src/kobject.h @@ -450,7 +450,7 @@ typedef struct __attribute__ ((__packed__)) { /* Errors */ typedef struct __attribute__ ((__packed__)) { CommonHeader; - TValue creator; /* either #inert or creating combiner */ + TValue who; /* either #inert or creating combiner */ TValue cont; /* continuation context */ TValue msg; /* string msg */ TValue irritants; /* list of extra objs */