commit 381168551af04f57d0976e1cae57b65803e86056
parent dd9f431bd8ab71df15e8d636ade94d4f8c712ea4
Author: Andres Navarro <canavarro82@gmail.com>
Date: Thu, 28 Apr 2011 19:16:08 -0300
Added error object support to the gc.
Diffstat:
4 files changed, 22 insertions(+), 1 deletion(-)
diff --git a/src/Makefile b/src/Makefile
@@ -152,4 +152,4 @@ kgstrings.o: kgstrings.c kgstrings.h kghelpers.h kstate.h klisp.h \
imath.o: kobject.h kstate.h kmem.h kerror.h
imrath.o: kobject.h kstate.h kmem.h kerror.h
kgc.o: kgc.c kgc.h kobject.h kmem.h kstate.h kport.h imath.h imrat.h \
- ktable.h kstring.h
+ ktable.h kstring.h kerror.h
diff --git a/src/kerror.c b/src/kerror.c
@@ -29,6 +29,11 @@ TValue klispE_new(klisp_State *K, TValue who, TValue cont, TValue msg,
return gc2error(new_error);
}
+void klispE_free(klisp_State *K, Error *error)
+{
+ klispM_free(K, error);
+}
+
/*
** Clear all stacks & buffers
*/
diff --git a/src/kerror.h b/src/kerror.h
@@ -15,6 +15,9 @@
TValue klispE_new(klisp_State *K, TValue who, TValue cont, TValue msg,
TValue irritants);
+
+void klispE_free(klisp_State *K, Error *error);
+
void klispE_throw_simple(klisp_State *K, char *msg);
void klispE_throw_with_irritants(klisp_State *K, char *msg, TValue irritants);
diff --git a/src/kgc.c b/src/kgc.c
@@ -20,6 +20,7 @@
#include "imrat.h"
#include "ktable.h"
#include "kstring.h"
+#include "kerror.h"
#define GCSTEPSIZE 1024u
#define GCSWEEPMAX 40
@@ -106,6 +107,7 @@ static void reallymarkobject (klisp_State *K, GCObject *o)
case K_TPROMISE:
case K_TPORT:
case K_TTABLE:
+ case K_TERROR:
o->gch.gclist = K->gray;
K->gray = o;
break;
@@ -305,6 +307,14 @@ static int32_t propagatemark (klisp_State *K) {
return sizeof(Table) + sizeof(TValue) * h->sizearray +
sizeof(Node) * sizenode(h);
}
+ case K_TERROR: {
+ Error *e = cast(Error *, o);
+ markvalue(K, e->who);
+ markvalue(K, e->cont);
+ markvalue(K, e->msg);
+ markvalue(K, e->irritants);
+ return sizeof(Error);
+ }
default:
fprintf(stderr, "Unknown GCObject type (in GC propagate): %d\n",
type);
@@ -430,6 +440,9 @@ static void freeobj (klisp_State *K, GCObject *o) {
case K_TTABLE:
klispH_free(K, (Table *)o);
break;
+ case K_TERROR:
+ klispE_free(K, (Error *)o);
+ break;
default:
/* shouldn't happen */
fprintf(stderr, "Unknown GCObject type (in GC free): %d\n",