[pypy-commit] stmgc default: in-progress

arigo noreply at buildbot.pypy.org
Tue Jun 25 16:43:38 CEST 2013


Author: Armin Rigo <arigo at tunes.org>
Branch: 
Changeset: r276:25825a02e0f9
Date: 2013-06-25 16:21 +0200
http://bitbucket.org/pypy/stmgc/changeset/25825a02e0f9/

Log:	in-progress

diff --git a/duhton/Makefile b/duhton/Makefile
--- a/duhton/Makefile
+++ b/duhton/Makefile
@@ -2,10 +2,10 @@
 all: duhton_debug duhton
 
 duhton: *.c *.h ../c4/*.c ../c4/*.h
-	gcc -pthread -g -O2 -o duhton *.c ../c4/stmgc.c -Wall
+	gcc -lrt -pthread -g -O2 -o duhton *.c ../c4/stmgc.c -Wall
 
 duhton_debug: *.c *.h ../c4/*.c ../c4/*.h
-	gcc -pthread -g -DDu_DEBUG -o duhton_debug *.c ../c4/stmgc.c -Wall
+	gcc -lrt -pthread -g -DDu_DEBUG -o duhton_debug *.c ../c4/stmgc.c -Wall
 
 clean:
 	rm -f duhton duhton_debug
diff --git a/duhton/consobject.c b/duhton/consobject.c
--- a/duhton/consobject.c
+++ b/duhton/consobject.c
@@ -5,6 +5,13 @@
     DuObject *car, *cdr;
 } DuConsObject;
 
+
+void cons_trace(DuConsObject *ob, void visit(gcptr *))
+{
+    visit(&ob->car);
+    visit(&ob->cdr);
+}
+
 void cons_print(DuConsObject *ob)
 {
     DuObject *p;
@@ -39,6 +46,7 @@
     "cons",
     DUTYPE_CONS,
     sizeof(DuConsObject),
+    (trace_fn)cons_trace,
     (print_fn)cons_print,
     (eval_fn)cons_eval,
 };
diff --git a/duhton/containerobject.c b/duhton/containerobject.c
--- a/duhton/containerobject.c
+++ b/duhton/containerobject.c
@@ -5,6 +5,12 @@
     DuObject *ob_reference;
 } DuContainerObject;
 
+
+void container_trace(DuContainerObject *ob, void visit(gcptr *))
+{
+    visit(&ob->ob_reference);
+}
+
 void container_print(DuContainerObject *ob)
 {
     printf("<container ");
@@ -32,6 +38,7 @@
     "container",
     DUTYPE_CONTAINER,
     sizeof(DuContainerObject),
+    (trace_fn)container_trace,
     (print_fn)container_print,
 };
 
diff --git a/duhton/duhton.h b/duhton/duhton.h
--- a/duhton/duhton.h
+++ b/duhton/duhton.h
@@ -2,6 +2,7 @@
 #define _DUHTON_H_
 
 #include "../c4/stmgc.h"
+#include "../c4/fprintcolor.h"
 #include <stdio.h>
 #include <stdlib.h>
 #include <assert.h>
@@ -21,6 +22,7 @@
 #endif
 
 
+typedef void(*trace_fn)(DuObject *, void visit(gcptr *));
 typedef void(*print_fn)(DuObject *);
 typedef DuObject *(*eval_fn)(DuObject *, DuObject *);
 typedef int(*len_fn)(DuObject *);
@@ -29,6 +31,7 @@
     const char *dt_name;
     int dt_typeindex;
     int dt_size;
+    trace_fn dt_trace;
     print_fn dt_print;
     eval_fn dt_eval;
     len_fn dt_is_true;
@@ -43,8 +46,9 @@
 #define DUTYPE_LIST          5
 #define DUTYPE_TUPLE         6
 #define DUTYPE_FRAME         7
-#define DUTYPE_CONTAINER     8
-#define _DUTYPE_TOTAL        9
+#define DUTYPE_FRAMENODE     8
+#define DUTYPE_CONTAINER     9
+#define _DUTYPE_TOTAL       10
 
 extern DuType DuNone_Type;
 extern DuType DuInt_Type;
@@ -92,6 +96,7 @@
 DuObject *DuList_GetItem(DuObject *list, int index);
 void DuList_SetItem(DuObject *list, int index, DuObject *newobj);
 DuObject *DuList_Pop(DuObject *list, int index);
+size_t _DuTuple_ByteSize(DuObject *tuple);
 
 DuObject *DuContainer_New(DuObject *obj);
 DuObject *DuContainer_GetRef(DuObject *container);
diff --git a/duhton/frame.c b/duhton/frame.c
--- a/duhton/frame.c
+++ b/duhton/frame.c
@@ -2,6 +2,7 @@
 #include <stdint.h>
 
 struct dictentry {
+    revision_t symbol_id;
     DuObject *symbol;
     DuObject *value;
     eval_fn builtin_macro;
@@ -11,13 +12,30 @@
 
 typedef struct {
     DuOBJECT_HEAD
-    int entry_count;
-    struct dictentry *entries;
+    int ob_count;
+    struct dictentry ob_items[1];
+} DuFrameNodeObject;
+
+void framenode_trace(DuFrameNodeObject *ob, void visit(gcptr *))
+{
+    int i;
+    for (i=ob->ob_count-1; i>=0; i--) {
+        struct dictentry *e = &ob->ob_items[i];
+        visit(&e->symbol);
+        visit(&e->value);
+        visit(&e->func_arglist);
+        visit(&e->func_progn);
+    }
+}
+
+
+typedef struct {
+    DuOBJECT_HEAD
+    DuFrameNodeObject *ob_nodes;
 } DuFrameObject;
 
 DuFrameObject Du_GlobalsFrame = {
     DuOBJECT_HEAD_INIT(DUTYPE_FRAME),
-    0,
     NULL,
 };
 
@@ -29,11 +47,11 @@
 DuObject *DuFrame_New()
 {
     DuFrameObject *ob = (DuFrameObject *)DuObject_New(&DuFrame_Type);
-    ob->entry_count = 0;
-    ob->entries = NULL;
+    ob->ob_nodes = NULL;
     return (DuObject *)ob;
 }
 
+#if 0
 DuObject *DuFrame_Copy(DuObject *frame)
 {
     DuFrame_Ensure("DuFrame_Copy", frame);
@@ -53,19 +71,11 @@
     }
     return (DuObject *)dst;
 }
+#endif
 
-void frame_free(DuFrameObject *ob)
+void frame_trace(DuFrameObject *ob, void visit(gcptr *))
 {
-    int i;
-    for (i=0; i<ob->entry_count; i++) {
-        struct dictentry *e = &ob->entries[i];
-        Du_DECREF(e->symbol);
-        if (e->value        != NULL) Du_DECREF(e->value       );
-        if (e->func_arglist != NULL) Du_DECREF(e->func_arglist);
-        if (e->func_progn   != NULL) Du_DECREF(e->func_progn  );
-    }
-    free(ob->entries);
-    free(ob);
+    visit((gcptr *)&ob->ob_nodes);
 }
 
 void frame_print(DuFrameObject *ob)
@@ -74,58 +84,88 @@
 }
 
 static struct dictentry *
-find_entry(DuFrameObject *frame, DuObject *symbol, int add_if_missing)
+find_entry(DuFrameObject *frame, DuObject *symbol, int write_mode)
 {
+    _du_read1(frame);
+    DuFrameNodeObject *ob = frame->ob_nodes;
+
+    _du_read1(ob);
     int left = 0;
-    int right = frame->entry_count;
-    struct dictentry *entries = frame->entries;
+    int right = ob->ob_count;
+    struct dictentry *entries = ob->ob_items;
+    revision_t search_id = stm_id(symbol);
+
     while (right > left) {
         int middle = (left + right) / 2;
-        DuObject *found = entries[middle].symbol;
-        if ((intptr_t)found < (intptr_t)symbol)
+        revision_t found_id = entries[middle].symbol_id;
+        if (search_id < found_id)
             right = middle;
-        else if (found == symbol)
+        else if (search_id == found_id) {
+            if (write_mode) {
+                _du_write1(ob);
+                entries = ob->ob_items;
+            }
             return entries + middle;
+        }
         else
             left = middle + 1;
     }
-    if (add_if_missing) {
+
+    if (!write_mode) {
+        return NULL;
+    }
+    else {
         int i;
-        int newcount = frame->entry_count + 1;
-        struct dictentry *newentries = malloc(sizeof(struct dictentry) *
-                                              newcount);
+        size_t size = (sizeof(DuFrameNodeObject) +
+                       (ob->ob_count + 1 - 1)*sizeof(struct dictentry));
+        DuFrameNodeObject *newob;
+
+        _du_save3(ob, symbol, frame);
+        newob = (DuFrameNodeObject *)stm_allocate(size, DUTYPE_FRAMENODE);
+        _du_restore3(ob, symbol, frame);
+
+        newob->ob_count = ob->ob_count + 1;
+        struct dictentry *newentries = newob->ob_items;
+        entries = ob->ob_items;
+
         for (i=0; i<left; i++)
             newentries[i] = entries[i];
+
         DuSymbol_Ensure("find_entry", symbol);
-        newentries[left].symbol = symbol; Du_INCREF(symbol);
+        newentries[left].symbol = symbol;
         newentries[left].value = NULL;
         newentries[left].builtin_macro = NULL;
         newentries[left].func_arglist = NULL;
         newentries[left].func_progn = NULL;
-        for (i=left+1; i<newcount; i++)
+
+        for (i=left+1; i<newob->ob_count; i++)
             newentries[i] = entries[i-1];
-        frame->entries = newentries;
-        frame->entry_count = newcount;
-        free(entries);
+
+        _du_write1(frame);
+        frame->ob_nodes = newob;
+
         return newentries + left;
     }
-    else
-        return NULL;
 }
 
 void DuFrame_SetBuiltinMacro(DuObject *frame, char *name, eval_fn func)
 {
     DuFrame_Ensure("DuFrame_SetBuiltinMacro", frame);
+
+    _du_save1(frame);
     DuObject *sym = DuSymbol_FromString(name);
+    _du_restore1(frame);
+
     struct dictentry *e = find_entry((DuFrameObject *)frame, sym, 1);
     e->builtin_macro = func;
-    Du_DECREF(sym);
 }
 
 static void
 _parse_arguments(DuObject *symbol, DuObject *arguments,
                  DuObject *formallist, DuObject *caller, DuObject *callee)
 {
+    abort();
+#if 0
     while (DuCons_Check(formallist)) {
         if (!DuCons_Check(arguments))
             Du_FatalError("call to '%s': not enough arguments",
@@ -140,11 +180,14 @@
     if (arguments != Du_None)
         Du_FatalError("call to '%s': too many arguments",
                       DuSymbol_AsString(symbol));
+#endif
 }
 
 DuObject *_DuFrame_EvalCall(DuObject *frame, DuObject *symbol,
                             DuObject *rest, int execute_now)
 {
+    stm_fatalerror("_DuFrame_EvalCall\n");
+#if 0
     struct dictentry *e;
     DuFrame_Ensure("_DuFrame_EvalCall", frame);
 
@@ -184,10 +227,13 @@
  not_defined:
     Du_FatalError("symbol not defined as a function: '%s'",
                   DuSymbol_AsString(symbol));
+#endif
 }
 
 DuObject *DuFrame_GetSymbol(DuObject *frame, DuObject *symbol)
 {
+    stm_fatalerror("DuFrame_GetSymbol\n");
+#if 0
     struct dictentry *e;
     DuFrame_Ensure("DuFrame_GetSymbol", frame);
 
@@ -198,28 +244,37 @@
     }
     else
         return NULL;
+#endif
 }
 
 void DuFrame_SetSymbol(DuObject *frame, DuObject *symbol, DuObject *value)
 {
+    stm_fatalerror("DuFrame_SetSymbol\n");
+#if 0
     struct dictentry *e;
     DuFrame_Ensure("DuFrame_SetSymbol", frame);
 
     e = find_entry((DuFrameObject *)frame, symbol, 1);
     if (e->value) Du_DECREF(e->value);
     e->value = value; Du_INCREF(value);
+#endif
 }
 
 void DuFrame_SetSymbolStr(DuObject *frame, char *name, DuObject *value)
 {
+    stm_fatalerror("DuFrame_SetSymbolStr\n");
+#if 0
     DuObject *sym = DuSymbol_FromString(name);
     DuFrame_SetSymbol(frame, sym, value);
     Du_DECREF(sym);
+#endif
 }
 
 void DuFrame_SetUserFunction(DuObject *frame, DuObject *symbol,
                              DuObject *arglist, DuObject *progn)
 {
+    stm_fatalerror("DuFrame_SetUserFunction\n");
+#if 0
     struct dictentry *e;
     DuFrame_Ensure("DuFrame_SetUserFunction", frame);
 
@@ -228,18 +283,27 @@
     if (e->func_progn)   Du_DECREF(e->func_progn);
     e->func_arglist = arglist; Du_INCREF(arglist);
     e->func_progn   = progn;   Du_INCREF(progn);
+#endif
 }
 
 void DuFrame_Ensure(char *where, DuObject *ob)
 {
     if (!DuFrame_Check(ob))
         Du_FatalError("%s: expected 'frame' argument, got '%s'",
-                      where, ob->ob_type->dt_name);
+                      where, Du_TYPE(ob)->dt_name);
 }
 
+DuType DuFrameNode_Type = {    /* internal type */
+    "framenode",
+    DUTYPE_FRAMENODE,
+    sizeof(DuFrameNodeObject),
+    (trace_fn)framenode_trace,
+};
+
 DuType DuFrame_Type = {
     "frame",
     DUTYPE_FRAME,
     sizeof(DuFrameObject),
+    (trace_fn)frame_trace,
     (print_fn)frame_print,
 };
diff --git a/duhton/glob.c b/duhton/glob.c
--- a/duhton/glob.c
+++ b/duhton/glob.c
@@ -563,6 +563,8 @@
 
 void Du_Initialize(void)
 {
+    stm_initialize();
+
     DuFrame_SetBuiltinMacro(Du_Globals, "progn", Du_Progn);
     DuFrame_SetBuiltinMacro(Du_Globals, "setq", du_setq);
     DuFrame_SetBuiltinMacro(Du_Globals, "print", du_print);
@@ -599,4 +601,5 @@
 
 void Du_Finalize(void)
 {
+    stm_finalize();
 }
diff --git a/duhton/intobject.c b/duhton/intobject.c
--- a/duhton/intobject.c
+++ b/duhton/intobject.c
@@ -21,6 +21,7 @@
     "int",
     DUTYPE_INT,
     sizeof(DuIntObject),
+    (trace_fn)NULL,
     (print_fn)int_print,
     (eval_fn)NULL,
     (len_fn)int_is_true,
diff --git a/duhton/listobject.c b/duhton/listobject.c
--- a/duhton/listobject.c
+++ b/duhton/listobject.c
@@ -17,6 +17,19 @@
 } DuListObject;
 
 
+void tuple_trace(DuTupleObject *ob, void visit(gcptr *))
+{
+    int i;
+    for (i=ob->ob_count-1; i>=0; i--) {
+        visit(&ob->ob_items[i]);
+    }
+}
+
+void list_trace(DuListObject *ob, void visit(gcptr *))
+{
+    visit((gcptr *)&ob->ob_tuple);
+}
+
 void list_print(DuListObject *ob)
 {
     int i;
@@ -139,10 +152,28 @@
     return _list_pop((DuListObject *)list, index);
 }
 
+size_t _DuTuple_ByteSize(DuObject *tuple)
+{
+    DuTupleObject *t = (DuTupleObject *)tuple;
+    return sizeof(DuTupleObject) + (t->ob_count - 1) * sizeof(DuObject *);
+}
+
+DuType DuTuple_Type = {    /* "tuple" is mostly an internal type here */
+    "tuple",
+    DUTYPE_TUPLE,
+    0,    /* dt_size */
+    (trace_fn)tuple_trace,
+    (print_fn)NULL,
+    (eval_fn)NULL,
+    (len_fn)NULL,
+    (len_fn)NULL,
+};
+
 DuType DuList_Type = {
     "list",
     DUTYPE_LIST,
     sizeof(DuListObject),
+    (trace_fn)list_trace,
     (print_fn)list_print,
     (eval_fn)NULL,
     (len_fn)NULL,
diff --git a/duhton/object.c b/duhton/object.c
--- a/duhton/object.c
+++ b/duhton/object.c
@@ -14,6 +14,24 @@
 };
 
 
+/* callback: get the size of an object */
+size_t stmcb_size(gcptr obj)
+{
+    if (_DuObject_TypeNum(obj) == DUTYPE_TUPLE)
+        return _DuTuple_ByteSize(obj);
+    else
+        return Du_TYPE(obj)->dt_size;
+}
+
+/* callback: trace the content of an object */
+void stmcb_trace(gcptr obj, void visit(gcptr *))
+{
+    trace_fn trace = Du_TYPE(obj)->dt_trace;
+    if (trace)
+        trace(obj, visit);
+}
+
+
 DuObject *DuObject_New(DuType *tp)
 {
     assert(tp->dt_size >= sizeof(DuObject));
@@ -36,6 +54,7 @@
     "NoneType",
     DUTYPE_NONE,
     sizeof(DuObject),
+    (trace_fn)NULL,
     none_print,
     (eval_fn)NULL,
     none_is_true,
diff --git a/duhton/symbol.c b/duhton/symbol.c
--- a/duhton/symbol.c
+++ b/duhton/symbol.c
@@ -1,4 +1,5 @@
 #include <string.h>
+#include <stdlib.h>
 #include "duhton.h"
 
 typedef struct _Du_Symbol {
@@ -13,6 +14,11 @@
     NULL};
 
 
+void symbol_trace(DuSymbolObject *ob, void visit(gcptr *))
+{
+    visit((gcptr *)&ob->next);
+}
+
 void symbol_print(DuSymbolObject *ob)
 {
     _du_read1(ob);
@@ -39,6 +45,7 @@
     "symbol",
     DUTYPE_SYMBOL,
     sizeof(DuSymbolObject),
+    (trace_fn)symbol_trace,
     (print_fn)symbol_print,
     (eval_fn)symbol_eval,
 };


More information about the pypy-commit mailing list