commit 3e29c9b57645e7b5285b1900270cb211c1d87f70
parent 2bebff836cbe048fa3a031aa718de7a39762f0db
Author: Andres Navarro <canavarro82@gmail.com>
Date: Wed, 20 Apr 2011 23:35:50 -0300
Added source code info tracking with si_table. BUGS PENDING (may be GC related).
Diffstat:
4 files changed, 31 insertions(+), 11 deletions(-)
diff --git a/src/Makefile b/src/Makefile
@@ -53,7 +53,7 @@ kstring.o: kstring.c kstring.h kobject.h kstate.h kmem.h klisp.h kgc.h
ksymbol.o: ksymbol.c ksymbol.h kobject.h kpair.h kstring.h kstate.h kmem.h \
klisp.h kgc.h
kread.o: kread.c kread.h kobject.h ktoken.h kpair.h kstate.h kerror.h klisp.h \
- kport.h
+ kport.h ktable.h
kwrite.o: kwrite.c kwrite.h kobject.h kpair.h kstring.h kstate.h kerror.h \
klisp.h kport.h kinteger.h ktable.h
kstate.o: kstate.c kstate.h klisp.h kobject.h kmem.h kstring.h klisp.h \
diff --git a/src/klispconf.h b/src/klispconf.h
@@ -19,9 +19,11 @@
/*#define KDEBUG_GC 1 */
/*
-#define KTRACK_MARKS (true)
+#define KTRACK_MARKS true
*/
+#define KTRACK_SI true
+
/* These are unused for now, but will be once incremental collection is
activated */
/* TEMP: for now the threshold is set manually at the start and then
diff --git a/src/kpair.h b/src/kpair.h
@@ -106,10 +106,6 @@ TValue klist_g(klisp_State *K, bool m, int32_t n, ...);
#define klist(K_, n_, ...) (klist_g(K_, true, n_, __VA_ARGS__))
#define kimm_list(K_, n_, ...) (klist_g(K_, false, n_, __VA_ARGS__))
-/* TODO use a source info table */
-#define kget_source_info(p_) (UNUSED(p_), KNIL)
-#define kset_source_info(K_, p_, si_) (UNUSED(K_), UNUSED(p_), UNUSED(si_))
-
inline TValue kget_dummy1(klisp_State *K)
{
klisp_assert(ttispair(K->dummy_pair1) && ttisnil(kcdr(K->dummy_pair1)));
diff --git a/src/kread.c b/src/kread.c
@@ -14,6 +14,7 @@
#include "ktoken.h"
#include "kstate.h"
#include "kerror.h"
+#include "ktable.h"
/*
@@ -52,6 +53,24 @@ typedef enum {
/*
+** Source code tracking
+** MAYBE: add source code tracking to symbols
+*/
+TValue kget_source_info(klisp_State *K, TValue pair)
+{
+ const TValue *node = klispH_get(tv2table(K->si_table), pair);
+ return (node == &kfree)? KNIL : *node;
+}
+
+/* GC: Assumes pair and si are rooted */
+void kset_source_info(klisp_State *K, TValue pair, TValue si)
+{
+// TValue *node = klispH_set(K, tv2table(K->si_table), pair);
+// *node = si;
+}
+
+
+/*
** Error management
*/
void kread_error(klisp_State *K, char *str)
@@ -175,7 +194,10 @@ TValue kread_fsm(klisp_State *K)
** in np (later it will be replace by the source info
** of the car of the list
*/
- kset_source_info(K, np, ktok_get_source_info(K));
+ TValue si = ktok_get_source_info(K);
+ krooted_tvs_push(K, si);
+ kset_source_info(K, np, si);
+ krooted_tvs_pop(K);
/* update the shared def to point to the new list */
/* NOTE: this is necessary for self referencing lists */
@@ -208,7 +230,7 @@ TValue kread_fsm(klisp_State *K)
pop_data(K);
obj = KNIL;
- obj_si = kget_source_info(fp_with_old_si);
+ obj_si = kget_source_info(K, fp_with_old_si);
read_next_token = false;
break;
}
@@ -393,15 +415,15 @@ TValue kread_fsm(klisp_State *K)
/* NOTE: the old one will be returned when list is complete */
/* GC: the way things are done here fp is rooted at all
times */
- TValue fp_old_si = kget_source_info(fp);
+ TValue fp_old_si = kget_source_info(K, fp);
+ krooted_tvs_push(K, fp);
+ krooted_tvs_push(K, fp_old_si);
kset_source_info(K, fp, obj_si);
kset_car_unsafe(K, fp, obj);
/* continue reading objects of list */
/* save first & last pair of the (still incomplete) list */
pop_data(K);
- krooted_tvs_push(K, fp);
- krooted_tvs_push(K, fp_old_si);
push_data(K, kcons (K, fp, fp_old_si));
krooted_tvs_pop(K);
krooted_tvs_pop(K);