diff --git a/.gitignore b/.gitignore index 1ce462c79..ece886dcd 100644 --- a/.gitignore +++ b/.gitignore @@ -18,6 +18,9 @@ backend/test/queue_unit_tests backend/test/skiplist_test backend/test/test_client +builtin/__builtin__.h +builtin/__builtin__.c + compiler/actonc compiler/package.yaml compiler/tests/*.ty diff --git a/Makefile b/Makefile index 8494fb055..60e856183 100644 --- a/Makefile +++ b/Makefile @@ -526,8 +526,8 @@ dist/types/__builtin__.ty: builtin/ty/out/types/__builtin__.ty builtin/ty/out/types/__builtin__.ty: builtin/ty/src/__builtin__.act $(ACTONC) @mkdir -p $(dir $@) $(ACTC) --always-build $< - cp builtin/ty/out/types/__builtin__.h builtin/__builtin__.h - cat builtin/ty/out/types/__builtin__.c builtin/__builtin__ADD.c > builtin/__builtin__.c + cp builtin/ty/out/types/__builtin__.h builtin/__builtin__.h + cp builtin/ty/out/types/__builtin__.c builtin/__builtin__.c # Build our standard library stdlib/out/dev/lib/libActonProject.a: $(STDLIB_SRCFILES) dist/types/__builtin__.ty $(DIST_HFILES) $(ACTONC) $(DEPSA) $(LIBGC) diff --git a/builtin/__builtin__ADD.c b/builtin/__builtin__ADD.c deleted file mode 100644 index f51a38850..000000000 --- a/builtin/__builtin__ADD.c +++ /dev/null @@ -1,16 +0,0 @@ - - B_HashableD_intG_methods.__eq__ = (B_bool (*)(B_HashableD_int, B_int, B_int))B_OrdD_intD___eq__; - B_HashableD_i64G_methods.__eq__ = (B_bool (*)(B_HashableD_i64, B_i64, B_i64))B_OrdD_i64D___eq__; - B_HashableD_i32G_methods.__eq__ = (B_bool (*)(B_HashableD_i32, B_i32, B_i32))B_OrdD_i32D___eq__; - B_HashableD_i16G_methods.__eq__ = (B_bool (*)(B_HashableD_i16, B_i16, B_i16))B_OrdD_i16D___eq__; - B_HashableD_u64G_methods.__eq__ = (B_bool (*)(B_HashableD_u64, B_u64, B_u64))B_OrdD_u64D___eq__; - B_HashableD_u32G_methods.__eq__ = (B_bool (*)(B_HashableD_u32, B_u32, B_u32))B_OrdD_u32D___eq__; - B_HashableD_u16G_methods.__eq__ = (B_bool (*)(B_HashableD_u16, B_u16, B_u16))B_OrdD_u16D___eq__; - B_HashableD_floatG_methods.__eq__ = (B_bool (*)(B_HashableD_float, B_float, B_float))B_OrdD_floatD___eq__; - B_HashableD_strG_methods.__eq__ = (B_bool (*)(B_HashableD_str, B_str, B_str))B_OrdD_strD___eq__; - B_HashableD_bytesG_methods.__eq__ = (B_bool (*)(B_HashableD_bytes, B_bytes, B_bytes))B_OrdD_bytesD___eq__; - -B_ContainerD_listG_methods.__len__ = (B_int (*)(B_ContainerD_list, B_list))B_CollectionD_SequenceD_listD___len__; -B_ContainerD_listG_methods.__fromiter__ = (B_list (*)(B_ContainerD_list, B_Iterable, $WORD))B_CollectionD_SequenceD_listD___fromiter__; -B_ContainerD_listG_methods.__iter__ = (B_Iterator (*)(B_ContainerD_list, B_list))B_CollectionD_SequenceD_listD___iter__; -} diff --git a/builtin/atom.c b/builtin/atom.c index 32e0cd8ab..9e53b4a81 100644 --- a/builtin/atom.c +++ b/builtin/atom.c @@ -13,6 +13,7 @@ */ struct B_atomG_class B_atomG_methods = { + 0, "B_atom", UNASSIGNED, ($SuperG_class)&B_valueG_methods diff --git a/builtin/bool.c b/builtin/bool.c index 672c0d046..a031c2938 100644 --- a/builtin/bool.c +++ b/builtin/bool.c @@ -12,7 +12,7 @@ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ - +GC_word B_boolD_gcbm[GC_BITMAP_SIZE(struct B_bool)]; // Serialization /////////////////////////////////////////////////////////////////////// @@ -52,7 +52,7 @@ B_bool B_boolG_new(B_value s) { } B_bool toB_bool(long b) { - B_bool res = malloc(sizeof(struct B_bool)); + B_bool res = GC_MALLOC_EXPLICITLY_TYPED(sizeof(struct B_bool), B_boolG_methods.$GCdescr); res->$class = &B_boolG_methods; res->val = b; return res; diff --git a/builtin/bool.h b/builtin/bool.h index a135ed82d..2d1577dd4 100644 --- a/builtin/bool.h +++ b/builtin/bool.h @@ -2,6 +2,7 @@ struct B_bool { struct B_boolG_class *$class; long val; }; +extern GC_word B_boolD_gcbm[GC_BITMAP_SIZE(struct B_bool)]; B_bool toB_bool(long b); long fromB_bool(B_bool b); diff --git a/builtin/builtin_functions.c b/builtin/builtin_functions.c index 333b9d057..a94457b76 100644 --- a/builtin/builtin_functions.c +++ b/builtin/builtin_functions.c @@ -91,8 +91,7 @@ B_IteratorD_enumerate B_IteratorD_enumerate$_deserialize(B_IteratorD_enumerate r return NULL; } -struct B_IteratorD_enumerateG_class B_IteratorD_enumerateG_methods = {"B_IteratorD_enumerate",UNASSIGNED,($SuperG_class)&B_IteratorG_methods,B_IteratorD_enumerate_init, - B_IteratorD_enumerate_serialize, B_IteratorD_enumerate$_deserialize, +struct B_IteratorD_enumerateG_class B_IteratorD_enumerateG_methods = {0,"B_IteratorD_enumerate",UNASSIGNED,($SuperG_class)&B_IteratorG_methods,B_IteratorD_enumerate_init, B_IteratorD_enumerate_serialize, B_IteratorD_enumerate$_deserialize, B_IteratorD_enumerate_bool,B_IteratorD_enumerate_str,B_IteratorD_enumerate_str, B_IteratorD_enumerate_next}; @@ -143,8 +142,7 @@ B_IteratorD_filter B_IteratorD_filter$_deserialize(B_IteratorD_filter res, $Seri return w; } -struct B_IteratorD_filterG_class B_IteratorD_filterG_methods = {"B_IteratorD_filter",UNASSIGNED,($SuperG_class)&B_IteratorG_methods,B_IteratorD_filter_init, - B_IteratorD_filter_serialize, B_IteratorD_filter$_deserialize, +struct B_IteratorD_filterG_class B_IteratorD_filterG_methods = {0,"B_IteratorD_filter",UNASSIGNED,($SuperG_class)&B_IteratorG_methods,B_IteratorD_filter_init, B_IteratorD_filter_serialize, B_IteratorD_filter$_deserialize, B_IteratorD_filter_bool,B_IteratorD_filter_str,B_IteratorD_filter_str, B_IteratorD_filter_next}; B_IteratorD_filter B_IteratorD_filterG_new(B_Iterator it, $pure f) { @@ -192,8 +190,7 @@ B_IteratorD_map B_IteratorD_map$_deserialize(B_IteratorD_map res, $Serial$state return NULL; } -struct B_IteratorD_mapG_class B_IteratorD_mapG_methods = {"B_IteratorD_map",UNASSIGNED,($SuperG_class)&B_IteratorG_methods,B_IteratorD_map_init, - B_IteratorD_map_serialize, B_IteratorD_map$_deserialize, +struct B_IteratorD_mapG_class B_IteratorD_mapG_methods = {0,"B_IteratorD_map",UNASSIGNED,($SuperG_class)&B_IteratorG_methods,B_IteratorD_map_init, B_IteratorD_map_serialize, B_IteratorD_map$_deserialize, B_IteratorD_map_bool,B_IteratorD_map_str,B_IteratorD_map_str, B_IteratorD_map_next}; B_IteratorD_map B_IteratorD_mapG_new(B_Iterator it, $pure f) { @@ -293,8 +290,7 @@ B_IteratorD_zip B_IteratorD_zip$_deserialize(B_IteratorD_zip res, $Serial$state return NULL; } -struct B_IteratorD_zipG_class B_IteratorD_zipG_methods = {" B_IteratorD_zip",UNASSIGNED,($SuperG_class)&B_IteratorG_methods,B_IteratorD_zip_init, - B_IteratorD_zip_serialize, B_IteratorD_zip$_deserialize, +struct B_IteratorD_zipG_class B_IteratorD_zipG_methods = {0," B_IteratorD_zip",UNASSIGNED,($SuperG_class)&B_IteratorG_methods,B_IteratorD_zip_init, B_IteratorD_zip_serialize, B_IteratorD_zip$_deserialize, B_IteratorD_zip_bool,B_IteratorD_zip_str,B_IteratorD_zip_str, B_IteratorD_zip_next}; B_IteratorD_zip B_IteratorD_zipG_new(B_Iterator iter1, B_Iterator iter2) { @@ -325,8 +321,7 @@ B_bool B_EqOptD___ne__(B_EqOpt wit, $WORD a, $WORD b) { return (!a && !b) ? B_False : B_True; } -struct B_EqOptG_class B_EqOptG_methods = {"B_EqOpt", UNASSIGNED, NULL, B_EqOptD___init__, B_EqOptD___eq__, B_EqOptD___ne__}; - +struct B_EqOptG_class B_EqOptG_methods = {0,"B_EqOpt", UNASSIGNED, NULL, B_EqOptD___init__, B_EqOptD___eq__, B_EqOptD___ne__}; B_EqOpt B_EqOptG_new(B_Eq W_Eq$A) { return $NEW(B_EqOpt, W_Eq$A); diff --git a/builtin/builtin_functions.h b/builtin/builtin_functions.h index c9637682b..3ca5237d7 100644 --- a/builtin/builtin_functions.h +++ b/builtin/builtin_functions.h @@ -8,7 +8,8 @@ struct B_IteratorD_enumerate; typedef struct B_IteratorD_enumerate *B_IteratorD_enumerate; struct B_IteratorD_enumerateG_class { - char *$GCINFO; + GC_descr $GCdescr; + char *$name; int $class_id; $SuperG_class $superclass; void (*__init__)(B_IteratorD_enumerate, B_Iterator,B_int); @@ -25,6 +26,7 @@ struct B_IteratorD_enumerate { B_Iterator it; int nxt; }; +extern GC_word B_IteratorD_enumerateD_gcbm[GC_BITMAP_SIZE(struct B_IteratorD_enumerate)]; extern struct B_IteratorD_enumerateG_class B_IteratorD_enumerateG_methods; B_IteratorD_enumerate B_IteratorD_enumerateG_new(B_Iterator,B_int); @@ -38,7 +40,8 @@ struct B_IteratorD_filter; typedef struct B_IteratorD_filter *B_IteratorD_filter; struct B_IteratorD_filterG_class { - char *$GCINFO; + GC_descr $GCdescr; + char *$name; int $class_id; $SuperG_class $superclass; void (*__init__)(B_IteratorD_filter, B_Iterator, $pure); @@ -55,6 +58,7 @@ struct B_IteratorD_filter { B_Iterator it; $pure f; }; +extern GC_word B_IteratorD_filterD_gcbm[GC_BITMAP_SIZE(struct B_IteratorD_filter)]; extern struct B_IteratorD_filterG_class B_IteratorD_filterG_methods; B_IteratorD_filter B_IteratorD_filterG_new(B_Iterator, $pure); @@ -67,7 +71,8 @@ struct B_IteratorD_map; typedef struct B_IteratorD_map *B_IteratorD_map; struct B_IteratorD_mapG_class { - char *$GCINFO; + GC_descr $GCdescr; + char *$name; int $class_id; $SuperG_class $superclass; void (*__init__)(B_IteratorD_map, B_Iterator, $pure); @@ -84,6 +89,7 @@ struct B_IteratorD_map { B_Iterator it; $pure f; }; +extern GC_word B_IteratorD_mapD_gcbm[GC_BITMAP_SIZE(struct B_IteratorD_map)]; extern struct B_IteratorD_mapG_class B_IteratorD_mapG_methods; B_IteratorD_map B_IteratorD_mapG_new(B_Iterator, $pure); @@ -94,7 +100,8 @@ struct B_IteratorD_zip; typedef struct B_IteratorD_zip *B_IteratorD_zip; struct B_IteratorD_zipG_class { - char *$GCINFO; + GC_descr $GCdescr; + char *$name; int $class_id; $SuperG_class $superclass; void (*__init__)(B_IteratorD_zip, B_Iterator, B_Iterator); @@ -111,6 +118,7 @@ struct B_IteratorD_zip { B_Iterator it1; B_Iterator it2; }; +extern GC_word B_IteratorD_zipD_gcbm[GC_BITMAP_SIZE(struct B_IteratorD_zip)]; extern struct B_IteratorD_zipG_class B_IteratorD_zipG_methods; B_IteratorD_zip B_IteratorD_zipG_new(B_Iterator, B_Iterator); @@ -124,7 +132,8 @@ struct B_EqOpt; typedef struct B_EqOpt *B_EqOpt; struct B_EqOptG_class { - char *$GCINFO; + GC_descr $GCdescr; + char *$name; int $class_id; $SuperG_class $superclass; void (*__init__)(B_EqOpt, B_Eq); @@ -136,6 +145,7 @@ struct B_EqOpt { struct B_EqOptG_class *$class; B_Eq W_Eq$A; }; +extern GC_word B_EqOptD_gcbm[GC_BITMAP_SIZE(struct B_EqOpt)]; B_EqOpt B_EqOptG_new(B_Eq); diff --git a/builtin/class_hierarchy.c b/builtin/class_hierarchy.c index dedde621f..dae71dcd3 100644 --- a/builtin/class_hierarchy.c +++ b/builtin/class_hierarchy.c @@ -38,19 +38,19 @@ B_NoneType B_objectD___init__ (B_object self) { */ B_str B_valueD___str__(B_value self) { char *s; - asprintf(&s,"<%s object at %p>",self->$class->$GCINFO,self); + asprintf(&s,"<%s object at %p>",self->$class->$name,self); return to$str(s); } B_str B_valueD___repr__(B_value self) { char *s; - asprintf(&s,"<%s object at %p>",self->$class->$GCINFO,self); + asprintf(&s,"<%s object at %p>",self->$class->$name,self); return to$str(s); } B_str B_objectD___str__(B_object self) { char *s; - asprintf(&s,"<%s object at %p>",self->$class->$GCINFO,self); + asprintf(&s,"<%s object at %p>",self->$class->$name,self); return to$str(s); } @@ -61,8 +61,7 @@ B_bool B_objectD___bool__(B_object self) { return B_True; } -struct $SerializableG_class $SerializableG_methods = {"$Serializable",UNASSIGNED,NULL, $SerializableD___init__,NULL,NULL}; - +struct $SerializableG_class $SerializableG_methods = {0,"$Serializable",UNASSIGNED,NULL, $SerializableD___init__,NULL,NULL}; //struct B_valueG_class B_valueG_methods = {"B_value",UNASSIGNED,($SuperG_class)&$SerializableG_methods,B_valueD___init__,NULL,NULL, B_valueD___bool__,B_valueD___str__,B_valueD___str__}; //struct B_objectG_class B_objectG_methods = {"B_object",UNASSIGNED,($SuperG_class)&B_valueG_methods,B_objectD___init__,NULL,NULL,B_objectD___bool__,B_objectD___str__,B_objectD___str__}; diff --git a/builtin/class_hierarchy.h b/builtin/class_hierarchy.h index 086807897..3eb1883a7 100644 --- a/builtin/class_hierarchy.h +++ b/builtin/class_hierarchy.h @@ -4,7 +4,8 @@ struct $SuperG_class { - char *$GCINFO; + GC_descr $GCdescr; + char *$name; int $class_id; $SuperG_class $superclass; }; @@ -12,6 +13,7 @@ struct $SuperG_class { struct $Super { $SuperG_class $class; }; +extern GC_word $SuperD_gcbm[GC_BITMAP_SIZE(struct $Super)]; /* typedef struct $InitializableG_class *$InitializableG_class; @@ -19,7 +21,8 @@ typedef struct $InitializableG_class *$InitializableG_class; typedef struct $Initializable *$Initializable; struct $InitializableG_class { - char *$GCINFO; + GC_descr $GCdescr; + char *$name; int $class_id; $SuperG_class $superclass; // = NULL B_NoneType (*__init__)($Initializable); @@ -28,6 +31,7 @@ struct $InitializableG_class { struct $Initializable { struct $InitializableG_class *$class; }; +extern GC_word $InitializableD_gcbm[GC_BITMAP_SIZE(struct $Initializable)]; extern struct $InitializableG_class $InitializableG_methods; $Initializable $InitializableG_new(); @@ -36,7 +40,8 @@ extern struct $InitializableG_class $InitializableG_methods; // Serializable ////////////////////////////////////////////////////// struct $SerializableG_class { - char *$GCINFO; + GC_descr $GCdescr; + char *$name; int $class_id; $SuperG_class $superclass; // = InitializableG_methods B_NoneType (*__init__)($Serializable); @@ -47,6 +52,7 @@ struct $SerializableG_class { struct $Serializable { struct $SerializableG_class *$class; }; +extern GC_word $SerializableD_gcbm[GC_BITMAP_SIZE(struct $Serializable)]; extern struct $SerializableG_class $SerializableG_methods; $Serializable $SerializableG_new(); diff --git a/builtin/complex.c b/builtin/complex.c index 0a8501f45..c125f692a 100644 --- a/builtin/complex.c +++ b/builtin/complex.c @@ -12,8 +12,10 @@ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +GC_word B_complexD_gcbm[GC_BITMAP_SIZE(struct B_complex)]; + B_complex toB_complex(complex double c) { - B_complex res = malloc(sizeof(struct B_complex)); + B_complex res = GC_MALLOC_EXPLICITLY_TYPED(sizeof(struct B_complex), B_complexG_methods.$GCdescr); res->$class = &B_complexG_methods; res->val = c; return res; @@ -191,6 +193,7 @@ struct B_EqD_complex B_EqD_complex_instance; struct B_HashableD_complex B_HashableD_complex_instance; struct B_NumberD_complexG_class B_NumberD_complexG_methods = { + 0, "B_NumberD_complex", UNASSIGNED, ($SuperG_class)&B_NumberG_methods, @@ -219,6 +222,7 @@ struct B_NumberD_complex B_NumberD_complex_instance = {&B_NumberD_complexG_metho B_NumberD_complex B_NumberD_complexG_witness = &B_NumberD_complex_instance; struct B_DivD_complexG_class B_DivD_complexG_methods = { + 0, "B_DivD_complex", UNASSIGNED, ($SuperG_class)&B_DivG_methods, @@ -236,6 +240,7 @@ struct B_DivD_complex B_DivD_complex_instance = {&B_DivD_complexG_methods}; B_DivD_complex B_DivD_complexG_witness = &B_DivD_complex_instance; struct B_MinusD_NumberD_complexG_class B_MinusD_NumberD_complexG_methods = { + 0, "B_MinusD_NumberD_complex", UNASSIGNED, ($SuperG_class)&B_MinusG_methods, @@ -252,6 +257,7 @@ struct B_MinusD_NumberD_complex B_MinusD_NumberD_complex_instance = {&B_MinusD_N B_MinusD_NumberD_complex B_MinusD_NumberD_complexG_witness = &B_MinusD_NumberD_complex_instance; struct B_EqD_complexG_class B_EqD_complexG_methods = { + 0, "B_EqD_complex", UNASSIGNED, ($SuperG_class)&B_EqG_methods, @@ -268,6 +274,7 @@ struct B_EqD_complex B_EqD_complex_instance = {&B_EqD_complexG_methods}; B_EqD_complex B_EqD_complexG_witness = &B_EqD_complex_instance; struct B_HashableD_complexG_class B_HashableD_complexG_methods = { + 0, "B_HashableD_complex", UNASSIGNED, ($SuperG_class)&B_HashableG_methods, diff --git a/builtin/complx.h b/builtin/complx.h index 6c7f56738..7dc965436 100644 --- a/builtin/complx.h +++ b/builtin/complx.h @@ -9,6 +9,7 @@ struct B_complex { struct B_complexG_class *$class; complex double val; }; +extern GC_word B_complexD_gcbm[GC_BITMAP_SIZE(struct B_complex)]; B_complex toB_complex(complex double c); diff --git a/builtin/dict.c b/builtin/dict.c index d874a17ad..f4de9665d 100644 --- a/builtin/dict.c +++ b/builtin/dict.c @@ -36,6 +36,8 @@ struct $table_struct { #define PERTURB_SHIFT 5 +GC_word B_dictD_gcbm[GC_BITMAP_SIZE(struct B_dict)]; + // Internal routines ////////////////////////////////////////////////////////////////// /* @@ -231,11 +233,11 @@ B_str B_dictD___str__(B_dict self) { B_value value = ((B_value)item->components[1]); B_str keystr = key->$class->__repr__(key); B_str valuestr = value->$class->__repr__(value); - B_str elem = malloc(sizeof(struct B_str)); + B_str elem = GC_MALLOC_EXPLICITLY_TYPED(sizeof(struct B_str), B_strG_methods.$GCdescr); elem->$class = &B_strG_methods; elem->nbytes = keystr->nbytes+valuestr->nbytes+1; elem->nchars = keystr->nchars+valuestr->nchars+1; - elem->str = malloc(elem->nbytes+1); + elem->str = GC_MALLOC_ATOMIC(elem->nbytes+1); memcpy(elem->str,keystr->str,keystr->nbytes); elem->str[keystr->nbytes] = ':'; memcpy(&elem->str[keystr->nbytes+1],valuestr->str,valuestr->nbytes); @@ -280,7 +282,7 @@ B_dict B_dictD___deserialize__(B_dict res, $Serial$state state) { return B_dictD_get(state->done,(B_Hashable)B_HashableD_intG_witness,to$int((long)this->blob[0]),NULL); } else { if (!res) - res = malloc(sizeof(struct B_dict)); + res = GC_MALLOC_EXPLICITLY_TYPED(sizeof(struct B_dict), B_dictG_methods.$GCdescr); B_dictD_setitem(state->done,(B_Hashable)B_HashableD_intG_witness,to$int(state->row_no-1),res); res->$class = &B_dictG_methods; res->numelements = (long)this->blob[0]; @@ -398,8 +400,7 @@ B_IteratorD_dict B_IteratorD_dict__deserialize(B_IteratorD_dict res, $Serial$sta } -struct B_IteratorD_dictG_class B_IteratorD_dictG_methods = {"B_IteratorD_dict",UNASSIGNED,($SuperG_class)&B_IteratorG_methods, B_IteratorD_dictD_init, - B_IteratorD_dictD_serialize, B_IteratorD_dict__deserialize, B_IteratorD_dictD_bool,B_IteratorD_dictD_str,B_IteratorD_dictD_str, B_IteratorD_dictD_next}; +struct B_IteratorD_dictG_class B_IteratorD_dictG_methods = {0,"B_IteratorD_dict",UNASSIGNED,($SuperG_class)&B_IteratorG_methods, B_IteratorD_dictD_init, B_IteratorD_dictD_serialize, B_IteratorD_dict__deserialize, B_IteratorD_dictD_bool,B_IteratorD_dictD_str,B_IteratorD_dictD_str, B_IteratorD_dictD_next}; B_Iterator B_MappingD_dictD___iter__ (B_MappingD_dict wit, B_dict dict) { @@ -504,8 +505,7 @@ B_IteratorD_dict_values B_IteratorD_dict_values_deserialize(B_IteratorD_dict_val return res; } -struct B_IteratorD_dict_valuesG_class B_IteratorD_dict_valuesG_methods = {"B_IteratorD_dict_values",UNASSIGNED,($SuperG_class)&B_IteratorG_methods, B_IteratorD_dict_values_init, - B_IteratorD_dict_values_serialize, B_IteratorD_dict_values_deserialize, B_IteratorD_dict_values_bool, B_IteratorD_dict_values_str,B_IteratorD_dict_values_str, +struct B_IteratorD_dict_valuesG_class B_IteratorD_dict_valuesG_methods = {0,"B_IteratorD_dict_values",UNASSIGNED,($SuperG_class)&B_IteratorG_methods, B_IteratorD_dict_values_init, B_IteratorD_dict_values_serialize, B_IteratorD_dict_values_deserialize, B_IteratorD_dict_values_bool, B_IteratorD_dict_values_str,B_IteratorD_dict_values_str, B_IteratorD_dict_values_next}; // items iterator @@ -560,8 +560,7 @@ B_IteratorD_dict_items B_IteratorD_dict_items_deserialize(B_IteratorD_dict_items -struct B_IteratorD_dict_itemsG_class B_IteratorD_dict_itemsG_methods = {"B_IteratorD_dict_items",UNASSIGNED,($SuperG_class)&B_IteratorG_methods, B_IteratorD_dict_items_init, - B_IteratorD_dict_items_serialize, B_IteratorD_dict_items_deserialize,B_IteratorD_dict_items_bool, B_IteratorD_dict_items_str, B_IteratorD_dict_items_str, B_IteratorD_dict_items_next}; +struct B_IteratorD_dict_itemsG_class B_IteratorD_dict_itemsG_methods = {0,"B_IteratorD_dict_items",UNASSIGNED,($SuperG_class)&B_IteratorG_methods, B_IteratorD_dict_items_init, B_IteratorD_dict_items_serialize, B_IteratorD_dict_items_deserialize,B_IteratorD_dict_items_bool, B_IteratorD_dict_items_str, B_IteratorD_dict_items_str, B_IteratorD_dict_items_next}; B_Iterator B_MappingD_dictD_values (B_MappingD_dict wit, B_dict dict) { @@ -708,6 +707,7 @@ struct B_MappingD_dictG_class B_MappingD_dictG_methods = { }; struct B_IndexedD_MappingD_dictG_class B_IndexedD_MappingD_dictG_methods = { + 0, "B_IndexedD_MappingD_dict", UNASSIGNED, ($SuperG_class)&B_IndexedG_methods, @@ -724,6 +724,7 @@ struct B_IndexedD_MappingD_dictG_class B_IndexedD_MappingD_dictG_methods = { struct B_OrdD_dictG_class B_OrdD_dictG_methods = { + 0, "B_OrdD_dict", UNASSIGNED, ($SuperG_class)&B_OrdG_methods, diff --git a/builtin/dict.h b/builtin/dict.h index 1dae6acdc..513c016f9 100644 --- a/builtin/dict.h +++ b/builtin/dict.h @@ -5,6 +5,7 @@ struct B_dict { long numelements; // nr of elements in dictionary $table table; // the hashtable }; +extern GC_word B_dictD_gcbm[GC_BITMAP_SIZE(struct B_dict)]; // Iterators over dicts /////////////////////////////////////////////////////// @@ -13,7 +14,8 @@ struct B_dict { typedef struct B_IteratorD_dict *B_IteratorD_dict; struct B_IteratorD_dictG_class { - char *$GCINFO; + GC_descr $GCdescr; + char *$name; int $class_id; $SuperG_class $superclass; void (*__init__)(B_IteratorD_dict, B_dict); @@ -30,6 +32,7 @@ struct B_IteratorD_dict { B_dict src; int nxt; }; +extern GC_word B_IteratorD_dictD_gcbm[GC_BITMAP_SIZE(struct B_IteratorD_dict)]; extern struct B_IteratorD_dictG_class B_IteratorD_dictG_methods; B_IteratorD_dict B_IteratorD_dictG_new(B_dict); @@ -39,7 +42,8 @@ B_IteratorD_dict B_IteratorD_dictG_new(B_dict); typedef struct B_IteratorD_dict_values *B_IteratorD_dict_values; struct B_IteratorD_dict_valuesG_class { - char *$GCINFO; + GC_descr $GCdescr; + char *$name; int $class_id; $SuperG_class $superclass; void (*__init__)(B_IteratorD_dict_values, B_dict); @@ -56,6 +60,7 @@ struct B_IteratorD_dict_values { B_dict src; int nxt; }; +extern GC_word B_IteratorD_dict_valuesD_gcbm[GC_BITMAP_SIZE(struct B_IteratorD_dict_values)]; extern struct B_IteratorD_dict_valuesG_class B_IteratorD_dict_valuesG_methods; B_IteratorD_dict_values B_IteratorD_dict_valuesG_new(B_dict); @@ -65,7 +70,8 @@ B_IteratorD_dict_values B_IteratorD_dict_valuesG_new(B_dict); typedef struct B_IteratorD_dict_items *B_IteratorD_dict_items; struct B_IteratorD_dict_itemsG_class { - char *$GCINFO; + GC_descr $GCdescr; + char *$name; int $class_id; $SuperG_class $superclass; void (*__init__)(B_IteratorD_dict_items, B_dict); @@ -82,6 +88,7 @@ struct B_IteratorD_dict_items { B_dict src; int nxt; }; +extern GC_word B_IteratorD_dict_itemsD_gcbm[GC_BITMAP_SIZE(struct B_IteratorD_dict_items)]; extern struct B_IteratorD_dict_itemsG_class B_IteratorD_dict_itemsG_methods; B_IteratorD_dict_items B_IteratorD_dict_itemsG_new(B_dict); diff --git a/builtin/env.c b/builtin/env.c index d35a547ae..8621f8147 100644 --- a/builtin/env.c +++ b/builtin/env.c @@ -80,7 +80,7 @@ B_Env B_EnvG_newactor(B_WorldAuth token, B_list args) { } B_WorldAuth B_WorldAuthG_new() { - B_WorldAuth $tmp = malloc(sizeof(struct B_WorldAuth)); + B_WorldAuth $tmp = GC_MALLOC_EXPLICITLY_TYPED(sizeof(struct B_WorldAuth), B_WorldAuthG_methods.$GCdescr); $tmp->$class = &B_WorldAuthG_methods; // B_WorldAuthG_methods.__init__($tmp); return $tmp; diff --git a/builtin/float.c b/builtin/float.c index cd8892164..27db222f1 100644 --- a/builtin/float.c +++ b/builtin/float.c @@ -14,6 +14,8 @@ #include +GC_word B_floatD_gcbm[GC_BITMAP_SIZE(struct B_float)]; + // General methods /////////////////////////////////////////////////////////////////////// B_float B_floatG_new(B_atom a) { @@ -86,7 +88,7 @@ B_str B_floatD___repr__(B_float x) { } B_float to$float(double x) { - B_float res = malloc(sizeof(struct B_float)); + B_float res = GC_MALLOC_EXPLICITLY_TYPED(sizeof(struct B_float), B_floatG_methods.$GCdescr); res->$class = &B_floatG_methods; res->val = x; return res; @@ -268,6 +270,7 @@ struct B_OrdD_float B_OrdD_float_instance; struct B_HashableD_float B_HashableD_float_instance; struct B_RealFloatD_floatG_class B_RealFloatD_floatG_methods = { + 0, "B_RealFloatD_float", UNASSIGNED, ($SuperG_class)&B_RealG_methods, @@ -301,6 +304,7 @@ struct B_RealFloatD_float B_RealFloatD_float_instance = {&B_RealFloatD_floatG_me B_RealFloatD_float B_RealFloatD_floatG_witness = &B_RealFloatD_float_instance; struct B_MinusD_RealFloatD_floatG_class B_MinusD_RealFloatD_floatG_methods = { + 0, "B_MinusD_RealFloatD_float", UNASSIGNED, ($SuperG_class)&B_MinusG_methods, @@ -318,6 +322,7 @@ struct B_MinusD_RealFloatD_float B_MinusD_RealFloatD_float_instance = {&B_MinusD B_MinusD_RealFloatD_float B_MinusD_RealFloatD_floatG_witness = &B_MinusD_RealFloatD_float_instance; struct B_DivD_floatG_class B_DivD_floatG_methods = { + 0, "B_DivD_float", UNASSIGNED, ($SuperG_class)&B_DivG_methods, @@ -336,6 +341,7 @@ B_DivD_float B_DivD_floatG_witness = &B_DivD_float_instance; struct B_OrdD_floatG_class B_OrdD_floatG_methods = { + 0, "B_OrdD_float", UNASSIGNED, ($SuperG_class)&B_OrdG_methods, @@ -356,6 +362,7 @@ struct B_OrdD_float B_OrdD_float_instance = {&B_OrdD_floatG_methods}; B_OrdD_float B_OrdD_floatG_witness = &B_OrdD_float_instance; struct B_HashableD_floatG_class B_HashableD_floatG_methods = { + 0, "B_HashableD_float", UNASSIGNED, ($SuperG_class)&B_HashableG_methods, diff --git a/builtin/float.h b/builtin/float.h index 8ea58722c..9b04d9a37 100644 --- a/builtin/float.h +++ b/builtin/float.h @@ -3,6 +3,7 @@ struct B_float { struct B_floatG_class *$class; double val; }; +extern GC_word B_floatD_gcbm[GC_BITMAP_SIZE(struct B_float)]; // #define B_RealD_floatG_new(...) B_RealFloatG_new(__VA_ARGS__) // #define B_RealD_float B_RealFloat diff --git a/builtin/function.c b/builtin/function.c index 9f5e7be57..c048c5241 100644 --- a/builtin/function.c +++ b/builtin/function.c @@ -69,6 +69,7 @@ void $ContD___serialize__($Cont self, $Serial$state state) { } struct $ContG_class $ContG_methods = { + 0, "$Cont", UNASSIGNED, NULL, @@ -81,6 +82,7 @@ struct $ContG_class $ContG_methods = { NULL /* __call__ */ }; struct $procG_class $procG_methods = { + 0, "$proc", UNASSIGNED, NULL, @@ -94,6 +96,7 @@ struct $procG_class $procG_methods = { NULL /* __exec__ */ }; struct $actionG_class $actionG_methods = { + 0, "$action", UNASSIGNED, NULL, @@ -108,6 +111,7 @@ struct $actionG_class $actionG_methods = { NULL /* __asyn__ */ }; struct $mutG_class $mutG_methods = { + 0, "$mut", UNASSIGNED, NULL, @@ -122,6 +126,7 @@ struct $mutG_class $mutG_methods = { NULL /* __eval__ */ }; struct $pureG_class $pureG_methods = { + 0, "$pure", UNASSIGNED, NULL, diff --git a/builtin/function.h b/builtin/function.h index b8eacb852..63505e6da 100644 --- a/builtin/function.h +++ b/builtin/function.h @@ -1,7 +1,8 @@ #pragma once struct $ContG_class { - char *$GCINFO; + GC_descr $GCdescr; + char *$name; int $class_id; $SuperG_class $superclass; void (*__init__)($Cont); @@ -15,6 +16,7 @@ struct $ContG_class { struct $Cont { struct $ContG_class *$class; }; +extern GC_word $ContD_gcbm[GC_BITMAP_SIZE(struct $Cont)]; extern struct $ContG_class $ContG_methods; void $ContD___init__($Cont); @@ -25,7 +27,8 @@ void $ContD___serialize__($Cont, $Serial$state); struct $procG_class { - char *$GCINFO; + GC_descr $GCdescr; + char *$name; int $class_id; $SuperG_class $superclass; void (*__init__)($proc); @@ -40,11 +43,13 @@ struct $procG_class { struct $proc { struct $procG_class *$class; }; +extern GC_word $procD_gcbm[GC_BITMAP_SIZE(struct $proc)]; extern struct $procG_class $procG_methods; struct $actionG_class { - char *$GCINFO; + GC_descr $GCdescr; + char *$name; int $class_id; $SuperG_class $superclass; void (*__init__)($action); @@ -60,11 +65,13 @@ struct $actionG_class { struct $action { struct $actionG_class *$class; }; +extern GC_word $actionD_gcbm[GC_BITMAP_SIZE(struct $action)]; extern struct $actionG_class $actionG_methods; struct $mutG_class { - char *$GCINFO; + GC_descr $GCdescr; + char *$name; int $class_id; $SuperG_class $superclass; void (*__init__)($mut); @@ -80,11 +87,13 @@ struct $mutG_class { struct $mut { struct $mutG_class *$class; }; +extern GC_word $mutD_gcbm[GC_BITMAP_SIZE(struct $mut)]; extern struct $mutG_class $mutG_methods; struct $pureG_class { - char *$GCINFO; + GC_descr $GCdescr; + char *$name; int $class_id; $SuperG_class $superclass; void (*__init__)($pure); @@ -100,6 +109,7 @@ struct $pureG_class { struct $pure { struct $pureG_class *$class; }; +extern GC_word $pureD_gcbm[GC_BITMAP_SIZE(struct $pure)]; extern struct $pureG_class $pureG_methods; @@ -107,7 +117,8 @@ extern struct $pureG_class $pureG_methods; struct $action2; typedef struct $action2 *$action2; struct $action2G_class { - char *$GCINFO; + GC_descr $GCdescr; + char *$name; int $class_id; $SuperG_class $superclass; void (*__init__)($action2); @@ -123,11 +134,13 @@ struct $action2G_class { struct $action2 { struct $action2G_class *$class; }; +extern GC_word $action2D_gcbm[GC_BITMAP_SIZE(struct $action2)]; struct $action3; typedef struct $action3 *$action3; struct $action3G_class { - char *$GCINFO; + GC_descr $GCdescr; + char *$name; int $class_id; $SuperG_class $superclass; void (*__init__)($action3); @@ -143,3 +156,4 @@ struct $action3G_class { struct $action3 { struct $action3G_class *$class; }; +extern GC_word $action3D_gcbm[GC_BITMAP_SIZE(struct $action3)]; diff --git a/builtin/i16.c b/builtin/i16.c index 80517bd57..85fe3c725 100644 --- a/builtin/i16.c +++ b/builtin/i16.c @@ -12,6 +12,8 @@ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +GC_word B_i16D_gcbm[GC_BITMAP_SIZE(struct B_i16)]; + // Auxiliary ////////////////////////////////////////////////////////////////////////////// // only called with e>=0. @@ -109,7 +111,7 @@ B_str B_i16D___repr__(B_i16 n) { } B_i16 toB_i16(short i) { - B_i16 res = malloc(sizeof(struct B_i16)); + B_i16 res = GC_MALLOC_EXPLICITLY_TYPED(sizeof(struct B_i16), B_i16G_methods.$GCdescr); res->$class = &B_i16G_methods; res->val = i; return res; diff --git a/builtin/i16.h b/builtin/i16.h index e05ad66c3..8de22a4f9 100644 --- a/builtin/i16.h +++ b/builtin/i16.h @@ -2,6 +2,7 @@ struct B_i16 { struct B_i16G_class *$class; short val; }; +extern GC_word B_i16D_gcbm[GC_BITMAP_SIZE(struct B_i16)]; B_i16 toB_i16(short n); diff --git a/builtin/i32.c b/builtin/i32.c index 7696cbd8c..9adc5939a 100644 --- a/builtin/i32.c +++ b/builtin/i32.c @@ -12,6 +12,8 @@ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +GC_word B_i32D_gcbm[GC_BITMAP_SIZE(struct B_i32)]; + // Auxiliary ////////////////////////////////////////////////////////////////////////////// // only called with e>=0. @@ -99,7 +101,7 @@ B_str B_i32D___repr__(B_i32 n) { } B_i32 toB_i32(int i) { - B_i32 res = malloc(sizeof(struct B_i32)); + B_i32 res = GC_MALLOC_EXPLICITLY_TYPED(sizeof(struct B_i32), B_i32G_methods.$GCdescr); res->$class = &B_i32G_methods; res->val = i; return res; diff --git a/builtin/i32.h b/builtin/i32.h index 37e4a10b2..81c37edad 100644 --- a/builtin/i32.h +++ b/builtin/i32.h @@ -2,6 +2,7 @@ struct B_i32 { struct B_i32G_class *$class; int val; }; +extern GC_word B_i32D_gcbm[GC_BITMAP_SIZE(struct B_i32)]; B_i32 toB_i32(int n); diff --git a/builtin/i64.c b/builtin/i64.c index a146b6b76..e3fdc3f05 100644 --- a/builtin/i64.c +++ b/builtin/i64.c @@ -12,6 +12,8 @@ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +GC_word B_i64D_gcbm[GC_BITMAP_SIZE(struct B_i64)]; + // Auxiliary ////////////////////////////////////////////////////////////////////////////// // only called with e>=0. @@ -88,7 +90,7 @@ B_str B_i64D___repr__(B_i64 n) { } B_i64 toB_i64(long i) { - B_i64 res = malloc(sizeof(struct B_i64)); + B_i64 res = GC_MALLOC_EXPLICITLY_TYPED(sizeof(struct B_i64), B_i64G_methods.$GCdescr); res->$class = &B_i64G_methods; res->val = i; return res; diff --git a/builtin/i64.h b/builtin/i64.h index 47d31454a..c9aa56b2a 100644 --- a/builtin/i64.h +++ b/builtin/i64.h @@ -2,6 +2,7 @@ struct B_i64 { struct B_i64G_class *$class; long val; }; +extern GC_word B_i64D_gcbm[GC_BITMAP_SIZE(struct B_i64)]; B_i64 toB_i64(long n); diff --git a/builtin/int.c b/builtin/int.c index 3ed103a2d..d20159108 100644 --- a/builtin/int.c +++ b/builtin/int.c @@ -15,13 +15,15 @@ #define GC_THREADS 1 #include "gc.h" +GC_word B_intD_gcbm[GC_BITMAP_SIZE(struct B_int)]; + // General methods /////////////////////////////////////////////////////////////////////// int set_str(zz_ptr a, char *str); char *get_str(zz_ptr n); B_int malloc_int() { - B_int res = malloc(sizeof(struct B_int)); + B_int res = GC_MALLOC_EXPLICITLY_TYPED(sizeof(struct B_int), B_intG_methods.$GCdescr); res->$class = &B_intG_methods; res->val.n = GC_MALLOC_ATOMIC(sizeof(unsigned long)); res->val.size = 0; diff --git a/builtin/int.h b/builtin/int.h index 56b291cf5..22612e9cd 100644 --- a/builtin/int.h +++ b/builtin/int.h @@ -4,6 +4,7 @@ struct B_int { struct B_intG_class *$class; zz_struct val; }; +extern GC_word B_intD_gcbm[GC_BITMAP_SIZE(struct B_int)]; B_int zz$to$int(zz_ptr val); diff --git a/builtin/list.c b/builtin/list.c index 75ab239c9..420ae7ada 100644 --- a/builtin/list.c +++ b/builtin/list.c @@ -12,6 +12,8 @@ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +GC_word B_listD_gcbm[GC_BITMAP_SIZE(struct B_list)]; + // Auxiliary functions ///////////////////////////////////////////////////////////////////////////////////////////////////// // For now, expansion doubles capacity. @@ -47,7 +49,7 @@ B_list B_listD_new(int capacity) { fprintf(stderr,"Internal error list_new: negative capacity"); exit(-1); } - B_list lst = malloc(sizeof(struct B_list)); + B_list lst = GC_MALLOC_EXPLICITLY_TYPED(sizeof(struct B_list), B_listG_methods.$GCdescr); if (lst == NULL) { $RAISE((B_BaseException)$NEW(B_MemoryError,to$str("memory allocation failed"))); } @@ -296,8 +298,7 @@ B_IteratorD_list B_IteratorD_list$_deserialize(B_IteratorD_list res, $Serial$sta return res; } -struct B_IteratorD_listG_class B_IteratorD_listG_methods = {"B_IteratorD_list",UNASSIGNED,($SuperG_class)&B_IteratorG_methods, B_IteratorD_listD_init, - B_IteratorD_listD_serialize, B_IteratorD_list$_deserialize,B_IteratorD_listD_bool,B_IteratorD_listD_str,B_IteratorD_listD_str,B_IteratorD_listD_next}; +struct B_IteratorD_listG_class B_IteratorD_listG_methods = {0,"B_IteratorD_list",UNASSIGNED,($SuperG_class)&B_IteratorG_methods, B_IteratorD_listD_init, B_IteratorD_listD_serialize, B_IteratorD_list$_deserialize,B_IteratorD_listD_bool,B_IteratorD_listD_str,B_IteratorD_listD_str,B_IteratorD_listD_next}; // Now, we can define the protocol methods @@ -495,6 +496,7 @@ B_bool B_ContainerD_listD___containsnot__(B_ContainerD_list wit, B_list lst, $WO // so we need to initialize the below method table here, even if it is done in B___init__. struct B_SequenceD_listG_class B_SequenceD_listG_methods = { + 0, "B_SequenceD_list", UNASSIGNED, ($SuperG_class)&B_SequenceG_methods, diff --git a/builtin/list.h b/builtin/list.h index b6c5d668a..03ee4a7ef 100644 --- a/builtin/list.h +++ b/builtin/list.h @@ -5,6 +5,7 @@ struct B_list { int length; int capacity; }; +extern GC_word B_listD_gcbm[GC_BITMAP_SIZE(struct B_list)]; /* extern struct B_SequenceD_list *B_SequenceD_listG_witness; extern struct B_CollectionD_SequenceD_list *B_CollectionD_SequenceD_listG_witness; @@ -15,7 +16,8 @@ extern struct B_CollectionD_SequenceD_list *B_CollectionD_SequenceD_listG_witnes typedef struct B_IteratorD_list *B_IteratorD_list; ; struct B_IteratorD_listG_class { - char *$GCINFO; + GC_descr $GCdescr; + char *$name; int $class_id; $SuperG_class $superclass; void (*__init__)(B_IteratorD_list, B_list); @@ -32,6 +34,7 @@ struct B_IteratorD_list { B_list src; int nxt; }; +extern GC_word B_IteratorD_listD_gcbm[GC_BITMAP_SIZE(struct B_IteratorD_list)]; extern struct B_IteratorD_listG_class B_IteratorD_listG_methods; B_IteratorD_list B_IteratorD_listG_new(B_list); diff --git a/builtin/none.c b/builtin/none.c index df80b8a8c..b0109c862 100644 --- a/builtin/none.c +++ b/builtin/none.c @@ -35,5 +35,4 @@ B_str B_NoneTypeD__str__(B_NoneType self) { return to$str("None"); } -struct B_NoneTypeG_class B_NoneTypeG_methods = {"B_NoneType",UNASSIGNED,($SuperG_class)&B_valueG_methods,(void (*)(B_NoneType))$default__init__, - B_NoneTypeD__serialize__, B_NoneTypeD__deserialize__, B_NoneTypeD__bool__, B_NoneTypeD__str__, B_NoneTypeD__str__}; +struct B_NoneTypeG_class B_NoneTypeG_methods = {0,"B_NoneType",UNASSIGNED,($SuperG_class)&B_valueG_methods,(void (*)(B_NoneType))$default__init__, B_NoneTypeD__serialize__, B_NoneTypeD__deserialize__, B_NoneTypeD__bool__, B_NoneTypeD__str__, B_NoneTypeD__str__}; diff --git a/builtin/none.h b/builtin/none.h index 3796d69c4..103fab030 100644 --- a/builtin/none.h +++ b/builtin/none.h @@ -1,5 +1,6 @@ struct B_NoneTypeG_class { - char *$GCINFO; + GC_descr $GCdescr; + char *$name; int $class_id; $SuperG_class $superclass; void (*__init__)(B_NoneType); @@ -13,6 +14,7 @@ struct B_NoneTypeG_class { struct B_NoneType { struct B_NoneTypeG_class *$class; }; +extern GC_word B_NoneTypeD_gcbm[GC_BITMAP_SIZE(struct B_NoneType)]; extern struct B_NoneTypeG_class B_NoneTypeG_methods; B_NoneType B_NoneTypeG_new(); diff --git a/builtin/range.c b/builtin/range.c index 6dca2ccaf..61b01259f 100644 --- a/builtin/range.c +++ b/builtin/range.c @@ -12,6 +12,8 @@ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +GC_word B_rangeD_gcbm[GC_BITMAP_SIZE(struct B_range)]; + B_range B_rangeG_new(B_int start, B_int stop, B_int step) { return $NEW(B_range, start, stop, step); } @@ -65,7 +67,7 @@ B_range B_rangeD___deserialize__(B_range self, $Serial$state state) { $ROW this = state->row; state->row = this->next; state->row_no++; - B_range res = malloc(sizeof(struct B_range)); + B_range res = GC_MALLOC_EXPLICITLY_TYPED(sizeof(struct B_range), B_rangeG_methods.$GCdescr); res->$class = &B_rangeG_methods; res->start = (long)this->blob[0]; res->stop = (long)this->blob[1]; @@ -109,6 +111,7 @@ B_IteratorB_range B_IteratorB_range$_deserialize(B_IteratorB_range self, $Serial } struct B_IteratorB_rangeG_class B_IteratorB_rangeG_methods = { + 0, "B_IteratorB_range", UNASSIGNED, ($SuperG_class)&B_IteratorG_methods, diff --git a/builtin/range.h b/builtin/range.h index 3ca93e9fd..e85bef69a 100644 --- a/builtin/range.h +++ b/builtin/range.h @@ -5,13 +5,15 @@ struct B_range { long stop; long step; }; +extern GC_word B_rangeD_gcbm[GC_BITMAP_SIZE(struct B_range)]; // Iterators over ranges /////////////////////////////////////////////////////// typedef struct B_IteratorB_range *B_IteratorB_range; struct B_IteratorB_rangeG_class { - char *$GCINFO; + GC_descr $GCdescr; + char *$name; int $class_id; $SuperG_class $superclass; void (*__init__)(B_IteratorB_range, B_range); @@ -28,6 +30,7 @@ struct B_IteratorB_range { B_range src; int nxt; }; +extern GC_word B_IteratorB_rangeD_gcbm[GC_BITMAP_SIZE(struct B_IteratorB_range)]; extern struct B_IteratorB_rangeG_class B_IteratorB_rangeG_methods; B_IteratorB_range B_IteratorB_rangeG_new(B_range); diff --git a/builtin/serialize.c b/builtin/serialize.c index 752355219..8ab8b1155 100644 --- a/builtin/serialize.c +++ b/builtin/serialize.c @@ -54,6 +54,7 @@ B_int B_HashableD_WORD_hash(B_HashableD_WORD wit, $WORD a) { } struct B_HashableD_WORDG_class B_HashableD_WORDG_methods = { + 0, "B_HashableD_WORD", UNASSIGNED, ($SuperG_class)&B_HashableG_methods, diff --git a/builtin/serialize.h b/builtin/serialize.h index 6d818e4be..04d6107b1 100644 --- a/builtin/serialize.h +++ b/builtin/serialize.h @@ -23,13 +23,15 @@ struct $ROWLISTHEADER { //typedef struct $Serial$state *$Serial$state; struct $Serial$state { - char *$GCINFO; + GC_descr $GCdescr; + char *$name; B_dict done; $WORD (*globmap)($WORD); long row_no; $ROW row; $ROW fst; //not used in deserialization }; +extern GC_word $Serial$stateD_gcbm[GC_BITMAP_SIZE(struct $Serial$state)]; // small-step helpers for defining serializations ////////////////////////////////////////////////// @@ -64,7 +66,8 @@ void $serialize_file($Serializable s, char *file); typedef struct B_HashableD_WORD *B_HashableD_WORD; struct B_HashableD_WORDG_class { - char *$GCINFO; + GC_descr $GCdescr; + char *$name; int $class_id; $SuperG_class superclass; void (*__init__)(B_HashableD_WORD); @@ -81,6 +84,7 @@ struct B_HashableD_WORDG_class { struct B_HashableD_WORD { struct B_HashableD_WORDG_class *$class; }; +extern GC_word B_HashableD_WORDD_gcbm[GC_BITMAP_SIZE(struct B_HashableD_WORD)]; extern struct B_HashableD_WORDG_class B_HashableD_WORDG_methods; B_HashableD_WORD B_HashableD_WORDG_new(); diff --git a/builtin/set.c b/builtin/set.c index 9938fc54e..81ce0d78a 100644 --- a/builtin/set.c +++ b/builtin/set.c @@ -21,6 +21,7 @@ static $WORD _dummy; #define dummy (&_dummy) +GC_word B_setD_gcbm[GC_BITMAP_SIZE(struct B_set)]; // Auxiliary functions /////////////////////////////////////////////////////////////////////////////// @@ -178,7 +179,7 @@ void B_set_add_entry(B_set set, B_Hashable hashwit, $WORD key, long hash) { B_set B_set_copy(B_set set, B_Hashable hashwit) { - B_set res = malloc(sizeof(struct B_set)); + B_set res = GC_MALLOC_EXPLICITLY_TYPED(sizeof(struct B_set), B_setG_methods.$GCdescr); memcpy(res,set,sizeof(struct B_set)); res->table = malloc((set->mask+1)*sizeof(B_setentry)); memcpy(res->table,set->table,(set->mask+1)*sizeof(B_setentry)); @@ -267,7 +268,7 @@ B_set B_setD___deserialize__ (B_set res, $Serial$state state) { return B_dictD_get(state->done,(B_Hashable)B_HashableD_intG_witness,to$int((long)this->blob[0]),NULL); } else { if (!res) - res = malloc(sizeof(struct B_set)); + res = GC_MALLOC_EXPLICITLY_TYPED(sizeof(struct B_set), B_setG_methods.$GCdescr); B_dictD_setitem(state->done,(B_Hashable)B_HashableD_intG_witness,to$int(state->row_no-1),res); res->$class = &B_setG_methods; res->numelements = (long)this->blob[0]; @@ -308,8 +309,8 @@ static $WORD B_IteratorD_set_next_entry(B_IteratorD_set self) { } static B_Iterator B_set_iter_entry(B_set set) { - B_IteratorD_set iter = malloc(sizeof(struct B_IteratorD_set)); - struct B_IteratorD_setG_class *methods = malloc(sizeof(struct B_IteratorD_setG_class)); + B_IteratorD_set iter = GC_MALLOC_EXPLICITLY_TYPED(sizeof(struct B_IteratorD_set), B_IteratorD_setG_methods.$GCdescr); + struct B_IteratorD_setG_class *methods = malloc(sizeof(struct B_IteratorD_setG_class)); // TODO: use GC_MALLOC_ATOMIC here? iter->$class = methods; methods->__next__ = B_IteratorD_set_next_entry; iter->src = set; @@ -357,8 +358,7 @@ B_IteratorD_set B_IteratorD_setD__deserialize(B_IteratorD_set res, $Serial$state return res; } -struct B_IteratorD_setG_class B_IteratorD_setG_methods = {"B_IteratorD_set",UNASSIGNED,($SuperG_class)&B_IteratorG_methods, B_IteratorD_set_init, - B_IteratorD_set_serialize, B_IteratorD_setD__deserialize,B_IteratorD_set_bool,B_IteratorD_set_str,B_IteratorD_set_str, B_IteratorD_set_next}; +struct B_IteratorD_setG_class B_IteratorD_setG_methods = {0,"B_IteratorD_set",UNASSIGNED,($SuperG_class)&B_IteratorG_methods, B_IteratorD_set_init, B_IteratorD_set_serialize, B_IteratorD_setD__deserialize,B_IteratorD_set_bool,B_IteratorD_set_str,B_IteratorD_set_str, B_IteratorD_set_next}; B_Iterator B_SetD_setD___iter__ (B_SetD_set wit, B_set set) { diff --git a/builtin/set.h b/builtin/set.h index ad64d25ae..674b183fc 100644 --- a/builtin/set.h +++ b/builtin/set.h @@ -12,6 +12,7 @@ struct B_set { long finger; // Search finger for pop() B_setentry *table; // the hashtable }; +extern GC_word B_setD_gcbm[GC_BITMAP_SIZE(struct B_set)]; // Iterators over sets /////////////////////////////////////////////////////// @@ -19,7 +20,8 @@ struct B_set { typedef struct B_IteratorD_set *B_IteratorD_set; ; struct B_IteratorD_setG_class { - char *$GCINFO; + GC_descr $GCdescr; + char *$name; int $class_id; $SuperG_class $superclass; void (*__init__)(B_IteratorD_set, B_set); @@ -36,6 +38,7 @@ struct B_IteratorD_set { B_set src; int nxt; }; +extern GC_word B_IteratorD_setD_gcbm[GC_BITMAP_SIZE(struct B_IteratorD_set)]; extern struct B_IteratorD_setG_class B_IteratorD_setG_methods; B_IteratorD_set B_IteratorD_setG_new(B_set); diff --git a/builtin/slice.c b/builtin/slice.c index e259a6695..98fd66f5d 100644 --- a/builtin/slice.c +++ b/builtin/slice.c @@ -12,6 +12,7 @@ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +GC_word B_sliceD_gcbm[GC_BITMAP_SIZE(struct B_slice)]; /* Normalize slice notation, so that - if step == 0, VALUEERROR is raised @@ -55,7 +56,7 @@ void normalize_slice(B_slice slc, long len, long *slen, long *start, long *stop, } B_slice B_sliceG_new(B_int start,B_int stop,B_int step) { - return $NEW(B_slice,start,stop,step); + return $NEW(B_slice, start, stop, step); } B_NoneType B_sliceD___init__(B_slice s, B_int start, B_int stop, B_int step) { @@ -87,7 +88,7 @@ B_slice B_sliceD___deserialize__ (B_slice self, $Serial$state state) { $ROW this = state->row; state->row = this->next; state->row_no++; - B_slice res = malloc(sizeof(struct B_slice)); + B_slice res = GC_MALLOC_EXPLICITLY_TYPED(sizeof(struct B_slice), B_sliceG_methods.$GCdescr); res->$class = &B_sliceG_methods; res->start = malloc(sizeof(long)); res->stop = malloc(sizeof(long)); diff --git a/builtin/slice.h b/builtin/slice.h index 92f636e4b..c0f405ee1 100644 --- a/builtin/slice.h +++ b/builtin/slice.h @@ -5,5 +5,6 @@ struct B_slice { long *stop; long *step; }; +extern GC_word B_sliceD_gcbm[GC_BITMAP_SIZE(struct B_slice)]; void normalize_slice(B_slice slc, long len, long *slen, long *start, long *stop, long *step); diff --git a/builtin/src/__builtin__.ext.c b/builtin/src/__builtin__.ext.c new file mode 100644 index 000000000..df298c207 --- /dev/null +++ b/builtin/src/__builtin__.ext.c @@ -0,0 +1,43 @@ + +void B___ext_init__() { + // Here is a list of things that have no fields that need to be scanned. It + // is noted down as an explicit negative list of things so we don't have to + // think "did we miss this". No, we did not, it just does not need scanning + // and the GC bitmap is already initialized to 0 due to the GC malloc + // actually being a calloc. + // - B_bool / B_boolD_gcbm + // - B_complex / B_complexD_gcbm + // - B_float / B_floatD_gcbm + // - B_i16 / B_i16D_gcbm + // - B_i32 / B_i32D_gcbm + // - B_i64 / B_i64D_gcbm + // - B_u16 / B_u16D_gcbm + // - B_u32 / B_u32D_gcbm + // - B_u64 / B_u64D_gcbm + // - B_range / B_rangeD_gcbm + GC_set_bit(B_bytearrayD_gcbm, GC_WORD_OFFSET(struct B_bytearray, str)); + GC_set_bit(B_bytesD_gcbm, GC_WORD_OFFSET(struct B_bytes, str)); + GC_set_bit(B_dictD_gcbm, GC_WORD_OFFSET(struct B_dict, table)); + GC_set_bit(B_intD_gcbm, GC_WORD_OFFSET(struct B_int, val.n)); + GC_set_bit(B_listD_gcbm, GC_WORD_OFFSET(struct B_list, data)); + GC_set_bit(B_setD_gcbm, GC_WORD_OFFSET(struct B_set, table)); + GC_set_bit(B_sliceD_gcbm, GC_WORD_OFFSET(struct B_slice, start)); + GC_set_bit(B_sliceD_gcbm, GC_WORD_OFFSET(struct B_slice, step)); + GC_set_bit(B_sliceD_gcbm, GC_WORD_OFFSET(struct B_slice, stop)); + GC_set_bit(B_strD_gcbm, GC_WORD_OFFSET(struct B_str, str)); + + B_HashableD_intG_methods.__eq__ = (B_bool (*)(B_HashableD_int, B_int, B_int))B_OrdD_intD___eq__; + B_HashableD_i64G_methods.__eq__ = (B_bool (*)(B_HashableD_i64, B_i64, B_i64))B_OrdD_i64D___eq__; + B_HashableD_i32G_methods.__eq__ = (B_bool (*)(B_HashableD_i32, B_i32, B_i32))B_OrdD_i32D___eq__; + B_HashableD_i16G_methods.__eq__ = (B_bool (*)(B_HashableD_i16, B_i16, B_i16))B_OrdD_i16D___eq__; + B_HashableD_u64G_methods.__eq__ = (B_bool (*)(B_HashableD_u64, B_u64, B_u64))B_OrdD_u64D___eq__; + B_HashableD_u32G_methods.__eq__ = (B_bool (*)(B_HashableD_u32, B_u32, B_u32))B_OrdD_u32D___eq__; + B_HashableD_u16G_methods.__eq__ = (B_bool (*)(B_HashableD_u16, B_u16, B_u16))B_OrdD_u16D___eq__; + B_HashableD_floatG_methods.__eq__ = (B_bool (*)(B_HashableD_float, B_float, B_float))B_OrdD_floatD___eq__; + B_HashableD_strG_methods.__eq__ = (B_bool (*)(B_HashableD_str, B_str, B_str))B_OrdD_strD___eq__; + B_HashableD_bytesG_methods.__eq__ = (B_bool (*)(B_HashableD_bytes, B_bytes, B_bytes))B_OrdD_bytesD___eq__; + + B_ContainerD_listG_methods.__len__ = (B_int (*)(B_ContainerD_list, B_list))B_CollectionD_SequenceD_listD___len__; + B_ContainerD_listG_methods.__fromiter__ = (B_list (*)(B_ContainerD_list, B_Iterable, $WORD))B_CollectionD_SequenceD_listD___fromiter__; + B_ContainerD_listG_methods.__iter__ = (B_Iterator (*)(B_ContainerD_list, B_list))B_CollectionD_SequenceD_listD___iter__; +} diff --git a/builtin/str.c b/builtin/str.c index 5ae5ed822..7f742d8bb 100644 --- a/builtin/str.c +++ b/builtin/str.c @@ -23,6 +23,10 @@ #include "../deps/libutf8proc/utf8proc.h" +GC_word B_strD_gcbm[GC_BITMAP_SIZE(struct B_str)]; +GC_word B_bytearrayD_gcbm[GC_BITMAP_SIZE(struct B_bytearray)]; +GC_word B_bytesD_gcbm[GC_BITMAP_SIZE(struct B_bytes)]; + // Auxiliaries, some used for both str and bytearray implementations //////////////////////////////////////////////////////// static unsigned char nul = 0; @@ -40,7 +44,7 @@ static struct B_str whitespace_struct = {&B_strG_methods,6,6,(unsigned char *)" static B_str whitespace_str = &whitespace_struct; #define NEW_UNFILLED_STR(nm,nchrs,nbtes) \ - nm = malloc(sizeof(struct B_str)); \ + nm = GC_MALLOC_EXPLICITLY_TYPED(sizeof(struct B_str), B_strG_methods.$GCdescr); \ (nm)->$class = &B_strG_methods; \ (nm)->nchars = nchrs; \ (nm)->nbytes = nbtes; \ @@ -48,7 +52,7 @@ static B_str whitespace_str = &whitespace_struct; (nm)->str[nbtes] = 0 #define NEW_UNFILLED_BYTEARRAY(nm,nbtes) \ - nm = malloc(sizeof(struct B_bytearray)); \ + nm = GC_MALLOC_EXPLICITLY_TYPED(sizeof(struct B_bytearray), B_bytearrayG_methods.$GCdescr); \ (nm)->$class = &B_bytearrayG_methods; \ (nm)->nbytes = nbtes; \ (nm)->capacity = nbtes; \ @@ -56,7 +60,7 @@ static B_str whitespace_str = &whitespace_struct; (nm)->str[nbtes] = 0 #define NEW_UNFILLED_BYTES(nm,nbtes) \ - nm = malloc(sizeof(struct B_bytes)); \ + nm = GC_MALLOC_EXPLICITLY_TYPED(sizeof(struct B_bytes), B_bytesG_methods.$GCdescr); \ (nm)->$class = &B_bytesG_methods; \ (nm)->nbytes = nbtes; \ (nm)->str = GC_MALLOC_ATOMIC(nbtes + 1); \ @@ -201,7 +205,7 @@ static int get_index(int i, int nchars) { static int fix_start_end(int nchars, B_int *start, B_int *end) { if (*start==NULL) { - *start = malloc(sizeof(struct B_int)); + *start = GC_MALLOC_EXPLICITLY_TYPED(sizeof(struct B_int), B_intG_methods.$GCdescr); *start = to$int(0); } int st = from$int(*start); @@ -213,7 +217,7 @@ static int fix_start_end(int nchars, B_int *start, B_int *end) { *start = to$int(st); if (*end==NULL) { - *end = malloc(sizeof(struct B_int)); + *end = GC_MALLOC_EXPLICITLY_TYPED(sizeof(struct B_int), B_intG_methods.$GCdescr); *end = to$int(nchars); } int en = from$int(*end); @@ -420,7 +424,7 @@ B_str B_strD___deserialize__(B_str self, $Serial$state state) { $ROW this = state->row; state->row =this->next; state->row_no++; - B_str res = malloc(sizeof(struct B_str)); + B_str res = GC_MALLOC_EXPLICITLY_TYPED(sizeof(struct B_str), B_strG_methods.$GCdescr); long nbytes; memcpy(&nbytes,this->blob,sizeof($WORD)); res->$class = &B_strG_methods; @@ -1256,8 +1260,7 @@ static B_str B_IteratorB_strD_next(B_IteratorB_str self) { } -struct B_IteratorB_strG_class B_IteratorB_strG_methods = {"B_IteratorB_str",UNASSIGNED,($SuperG_class)&B_IteratorG_methods, B_IteratorB_strD_init, - B_IteratorB_strD_serialize, B_IteratorB_str$_deserialize, +struct B_IteratorB_strG_class B_IteratorB_strG_methods = {0,"B_IteratorB_str",UNASSIGNED,($SuperG_class)&B_IteratorG_methods, B_IteratorB_strD_init, B_IteratorB_strD_serialize, B_IteratorB_str$_deserialize, B_IteratorB_strD_bool, B_IteratorB_strD_str, B_IteratorB_strD_str, B_IteratorB_strD_next}; // now, define __iter__ @@ -1423,7 +1426,7 @@ B_bytearray B_bytearrayD___deserialize__(B_bytearray res, $Serial$state state) { state->row =this->next; state->row_no++; if(!res) - res = malloc(sizeof(struct B_bytearray)); + res = GC_MALLOC_EXPLICITLY_TYPED(sizeof(struct B_bytearray), B_bytearrayG_methods.$GCdescr); long nbytes; memcpy(&nbytes,this->blob,sizeof($WORD)); res->$class = &B_bytearrayG_methods; @@ -2088,6 +2091,7 @@ B_IteratorB_bytearray B_IteratorB_bytearray$_deserialize(B_IteratorB_bytearray r } struct B_IteratorB_bytearrayG_class B_IteratorB_bytearrayG_methods = { + 0, "", UNASSIGNED, ($SuperG_class)&B_IteratorG_methods, @@ -2411,7 +2415,7 @@ B_bytes B_bytesD___deserialize__(B_bytes self, $Serial$state state) { $ROW this = state->row; state->row =this->next; state->row_no++; - B_bytes res = malloc(sizeof(struct B_bytes)); + B_bytes res = GC_MALLOC_EXPLICITLY_TYPED(sizeof(struct B_bytes), B_bytesG_methods.$GCdescr); long nbytes; memcpy(&nbytes,this->blob,sizeof($WORD)); res->$class = &B_bytesG_methods; @@ -3104,8 +3108,7 @@ static B_int B_IteratorB_bytesD_next(B_IteratorB_bytes self) { return self->nxt >= self->src->nbytes ? NULL : to$int(self->src->str[self->nxt++]); } -struct B_IteratorB_bytesG_class B_IteratorB_bytesG_methods = {"B_IteratorB_bytes",UNASSIGNED,($SuperG_class)&B_IteratorG_methods, B_IteratorB_bytesD_init, - B_IteratorB_bytesD_serialize, B_IteratorB_bytes$_deserialize, +struct B_IteratorB_bytesG_class B_IteratorB_bytesG_methods = {0,"B_IteratorB_bytes",UNASSIGNED,($SuperG_class)&B_IteratorG_methods, B_IteratorB_bytesD_init, B_IteratorB_bytesD_serialize, B_IteratorB_bytes$_deserialize, B_IteratorB_bytesD_bool, B_IteratorB_bytesD_str, B_IteratorB_bytesD_str, B_IteratorB_bytesD_next}; B_Iterator B_ContainerD_bytesD___iter__ (B_ContainerD_bytes wit, B_bytes str) { @@ -3375,7 +3378,7 @@ B_str B_strD_join_par(char lpar, B_list elems, char rpar) { B_str $default__str__(B_value self) { char *s; - asprintf(&s,"<%s object at %p>",self->$class->$GCINFO,self); + asprintf(&s,"<%s object at %p>",self->$class->$name,self); return to$str(s); } @@ -3510,6 +3513,7 @@ struct B_OrdD_bytearray B_OrdD_bytearray_instance = {&B_OrdD_bytearrayG_methods} B_OrdD_bytearray B_OrdD_bytearrayG_witness = &B_OrdD_bytearray_instance; struct B_SequenceD_bytearrayG_class B_SequenceD_bytearrayG_methods = { + 0, "B_SequenceD_bytearray", UNASSIGNED, ($SuperG_class)&B_SequenceG_methods, @@ -3540,6 +3544,7 @@ struct B_SequenceD_bytearray B_SequenceD_bytearray_instance = { B_SequenceD_bytearray B_SequenceD_bytearrayG_witness = &B_SequenceD_bytearray_instance; struct B_CollectionD_SequenceD_bytearrayG_class B_CollectionD_SequenceD_bytearrayG_methods = { + 0, "B_CollectionD_SequenceD_bytearray", UNASSIGNED, ($SuperG_class)&B_CollectionG_methods, @@ -3577,6 +3582,7 @@ struct B_TimesD_SequenceD_bytearray B_TimesD_SequenceD_bytearray_instance = {&B_ B_TimesD_SequenceD_bytearray B_TimesD_SequenceD_bytearrayG_witness = &B_TimesD_SequenceD_bytearray_instance; struct B_ContainerD_bytearrayG_class B_ContainerD_bytearrayG_methods = { + 0, "B_ContainerD_bytearray", UNASSIGNED, ($SuperG_class)&B_ContainerG_methods, diff --git a/builtin/str.h b/builtin/str.h index 5b3ab1232..eb65a7b6b 100644 --- a/builtin/str.h +++ b/builtin/str.h @@ -6,6 +6,7 @@ struct B_str { int nchars; // length of str in Unicode chars unsigned char *str; // str is UTF-8 encoded. }; +extern GC_word B_strD_gcbm[GC_BITMAP_SIZE(struct B_str)]; // Constructor; str must be a null-terminated, correctly UTF-8-encoded string. // The constructor checks this and returns a B_str value. @@ -18,7 +19,8 @@ unsigned char *fromB_str(B_str str); typedef struct B_IteratorB_str *B_IteratorB_str; ; struct B_IteratorB_strG_class { - char *$GCINFO; + GC_descr $GCdescr; + char *$name; int $class_id; $SuperG_class $superclass; B_NoneType (*__init__)(B_IteratorB_str, B_str); @@ -35,6 +37,7 @@ struct B_IteratorB_str { B_str src; int nxt; }; +extern GC_word B_IteratorB_strD_gcbm[GC_BITMAP_SIZE(struct B_IteratorB_str)]; extern struct B_IteratorB_strG_class B_IteratorB_strG_methods; B_IteratorB_str B_IteratorB_strG_new(B_str); @@ -49,6 +52,7 @@ struct B_bytearray { unsigned char *str; int capacity; }; +extern GC_word B_bytearrayD_gcbm[GC_BITMAP_SIZE(struct B_bytearray)]; B_bytearray toB_bytearray(char *str); @@ -59,7 +63,8 @@ unsigned char *fromB_bytearray(B_bytearray b); typedef struct B_IteratorB_bytearray *B_IteratorB_bytearray; ; struct B_IteratorB_bytearrayG_class { - char *$GCINFO; + GC_descr $GCdescr; + char *$name; int $class_id; $SuperG_class $superclass; B_NoneType (*__init__)(B_IteratorB_bytearray, B_bytearray); @@ -76,6 +81,7 @@ struct B_IteratorB_bytearray { B_bytearray src; int nxt; }; +extern GC_word B_IteratorB_bytearrayD_gcbm[GC_BITMAP_SIZE(struct B_IteratorB_bytearray)]; extern struct B_IteratorB_bytearrayG_class B_IteratorB_bytearrayG_methods; B_IteratorB_bytearray B_IteratorB_bytearrayG_new(B_bytearray); @@ -88,6 +94,7 @@ struct B_bytes { int nbytes; unsigned char *str; }; +extern GC_word B_bytesD_gcbm[GC_BITMAP_SIZE(struct B_bytes)]; B_bytes to$bytes(char *str); B_bytes to$bytesD_len(char *str, int len); @@ -100,7 +107,8 @@ unsigned char *fromB_bytes(B_bytes b); typedef struct B_IteratorB_bytes *B_IteratorB_bytes; ; struct B_IteratorB_bytesG_class { - char *$GCINFO; + GC_descr $GCdescr; + char *$name; int $class_id; $SuperG_class $superclass; B_NoneType (*__init__)(B_IteratorB_bytes, B_bytes); @@ -117,6 +125,7 @@ struct B_IteratorB_bytes { B_bytes src; int nxt; }; +extern GC_word B_IteratorB_bytesD_gcbm[GC_BITMAP_SIZE(struct B_IteratorB_bytes)]; extern struct B_IteratorB_bytesG_class B_IteratorB_bytesG_methods; B_IteratorB_bytes B_IteratorB_bytesG_new(B_bytes); diff --git a/builtin/tests/Pingpong.c b/builtin/tests/Pingpong.c index 5ef0da095..c5d7c80f4 100644 --- a/builtin/tests/Pingpong.c +++ b/builtin/tests/Pingpong.c @@ -82,6 +82,7 @@ Pingpong PingpongD___deserialize__(B_NoneType state) { } struct lambda$1G_class lambda$1G_methods = { + 0, "lambda$1", NULL, lambda$1D___init__, @@ -90,6 +91,7 @@ struct lambda$1G_class lambda$1G_methods = { lambda$1D___call__ }; struct lambda$2G_class lambda$2G_methods = { + 0, "lambda$2", NULL, lambda$2D___init__, @@ -98,6 +100,7 @@ struct lambda$2G_class lambda$2G_methods = { lambda$2D___call__ }; struct PingpongG_class PingpongG_methods = { + 0, "Pingpong", NULL, PingpongD___init__, @@ -108,7 +111,7 @@ struct PingpongG_class PingpongG_methods = { }; $R PingpongG_new(B_Env env, $Cont cont) { - Pingpong $tmp = malloc(sizeof(struct Pingpong)); + Pingpong $tmp = GC_MALLOC_EXPLICITLY_TYPED(sizeof(struct Pingpong), PingpongG_methods.$GCdescr); $tmp->$class = &PingpongG_methods; return PingpongG_methods.__init__($tmp, env, $CONSTCONT($tmp, cont)); } diff --git a/builtin/tests/Pingpong.h b/builtin/tests/Pingpong.h index f79442e3b..e33eef484 100644 --- a/builtin/tests/Pingpong.h +++ b/builtin/tests/Pingpong.h @@ -13,7 +13,8 @@ typedef struct lambda$2 *lambda$2; typedef struct Pingpong *Pingpong; struct lambda$1G_class { - char *$GCINFO; + GC_descr $GCdescr; + char *$name; $SuperG_class $superclass; void (*__init__)(lambda$1, Pingpong, B_int); void (*__serialize__)(lambda$1, B_NoneType); @@ -28,9 +29,11 @@ struct lambda$1 { Pingpong self; B_int count; }; +extern GC_word lambda$1D_gcbm[GC_BITMAP_SIZE(struct lambda$1)]; struct lambda$2G_class { - char *$GCINFO; + GC_descr $GCdescr; + char *$name; $SuperG_class $superclass; void (*__init__)(lambda$2, Pingpong); void (*__serialize__)(lambda$2, B_NoneType); @@ -44,9 +47,11 @@ struct lambda$2 { }; Pingpong self; }; +extern GC_word lambda$2D_gcbm[GC_BITMAP_SIZE(struct lambda$2)]; struct PingpongG_class { - char *$GCINFO; + GC_descr $GCdescr; + char *$name; $SuperG_class $superclass; $R (*__init__)(Pingpong, B_Env, $Cont); void (*__serialize__)(Pingpong, B_NoneType); @@ -62,6 +67,7 @@ struct Pingpong { B_int i; B_int count; }; +extern GC_word PingpongD_gcbm[GC_BITMAP_SIZE(struct Pingpong)]; extern struct lambda$1G_class lambda$1G_methods; extern struct lambda$2G_class lambda$2G_methods; diff --git a/builtin/tuple.c b/builtin/tuple.c index a924ce265..101d6e234 100644 --- a/builtin/tuple.c +++ b/builtin/tuple.c @@ -62,7 +62,7 @@ B_tuple B_tupleD___deserialize__(B_tuple self, $Serial$state state) { return (B_tuple)B_dictD_get(state->done,(B_Hashable)B_HashableD_intG_witness,to$int((long)this->blob[0]),NULL); } else { int len = (int)(long)this->blob[0]; - B_tuple res = malloc(sizeof(struct B_tuple)); + B_tuple res = GC_MALLOC_EXPLICITLY_TYPED(sizeof(struct B_tuple), B_tupleG_methods.$GCdescr); B_dictD_setitem(state->done,(B_Hashable)B_HashableD_intG_witness,to$int(state->row_no-1),res); res->components = malloc(len * sizeof($WORD)); res->$class = &B_tupleG_methods; @@ -74,6 +74,7 @@ B_tuple B_tupleD___deserialize__(B_tuple self, $Serial$state state) { } struct B_tupleG_class B_tupleG_methods = { + 0, "tuple", UNASSIGNED, ($SuperG_class)&B_valueG_methods, @@ -118,8 +119,7 @@ B_IteratorD_tuple B_IteratorD_tuple$_deserialize(B_IteratorD_tuple res, $Serial$ return res; } -struct B_IteratorD_tupleG_class B_IteratorD_tupleG_methods = {"B_IteratorD_tuple",UNASSIGNED,($SuperG_class)&B_IteratorG_methods,B_IteratorD_tupleD_init, - B_IteratorD_tupleD_serialize,B_IteratorD_tuple$_deserialize,B_IteratorD_tupleD_bool,B_IteratorD_tupleD_str,B_IteratorD_tupleD_str,B_IteratorD_tupleD_next}; +struct B_IteratorD_tupleG_class B_IteratorD_tupleG_methods = {0,"B_IteratorD_tuple",UNASSIGNED,($SuperG_class)&B_IteratorG_methods,B_IteratorD_tupleD_init, B_IteratorD_tupleD_serialize,B_IteratorD_tuple$_deserialize,B_IteratorD_tupleD_bool,B_IteratorD_tupleD_str,B_IteratorD_tupleD_str,B_IteratorD_tupleD_next}; // Iterable /////////////////////////////////////////////////////////////// @@ -140,6 +140,7 @@ B_IterableD_tuple B_IterableD_tupleD___deserialize__(B_IterableD_tuple self, $Se return res; } struct B_IterableD_tupleG_class B_IterableD_tupleG_methods = { + 0, "B_IterableD_tuple", UNASSIGNED, ($SuperG_class)&B_IterableG_methods, @@ -196,7 +197,7 @@ B_tuple B_SliceableD_tupleD___getslice__ (B_SliceableD_tuple wit, B_tuple self, normalize_slice(slc, size, &slen, &start, &stop, &step); //slice notation have been eliminated and default values applied. // slen now is the length of the slice - B_tuple res = malloc(sizeof(struct B_tuple)); + B_tuple res = GC_MALLOC_EXPLICITLY_TYPED(sizeof(struct B_tuple), B_tupleG_methods.$GCdescr); res->$class = self->$class; res->size = slen; res->components = malloc(slen * sizeof($WORD)); @@ -219,6 +220,7 @@ B_NoneType B_SliceableD_tupleD___delslice__ (B_SliceableD_tuple wit, B_tuple sel } struct B_SliceableD_tupleG_class B_SliceableD_tupleG_methods = { + 0, "B_SliceableD_tuple", UNASSIGNED, ($SuperG_class)&B_SliceableG_methods, @@ -274,6 +276,7 @@ B_int B_HashableD_tupleD___hash__ (B_HashableD_tuple wit, B_tuple tup) { } struct B_HashableD_tupleG_class B_HashableD_tupleG_methods = { + 0, "B_HashableD_tuple", UNASSIGNED, ($SuperG_class)&B_HashableG_methods, diff --git a/builtin/tuple.h b/builtin/tuple.h index 237c492a3..853f557f9 100644 --- a/builtin/tuple.h +++ b/builtin/tuple.h @@ -1,5 +1,6 @@ struct B_tupleG_class { - char *$GCINFO; + GC_descr $GCdescr; + char *$name; int $class_id; $SuperG_class $superclass; B_NoneType (*__init__)(B_tuple,int,...); @@ -15,6 +16,7 @@ struct B_tuple { int size; $WORD *components; }; +extern GC_word B_tupleD_gcbm[GC_BITMAP_SIZE(struct B_tuple)]; extern struct B_tupleG_class B_tupleG_methods; B_tuple B_tupleG_new(int,...); @@ -57,9 +59,11 @@ typedef struct B_HashableD_tupleG_class *B_HashableD_tupleG_class; struct B_IterableD_tuple { B_IterableD_tupleG_class $class; }; +extern GC_word B_IterableD_tupleD_gcbm[GC_BITMAP_SIZE(struct B_IterableD_tuple)]; struct B_IterableD_tupleG_class { - char *$GCINFO; + GC_descr $GCdescr; + char *$name; int $class_id; $SuperG_class $superclass; B_NoneType (*__init__)(B_IterableD_tuple); @@ -86,9 +90,11 @@ B_IterableD_tuple B_IterableD_tupleG_new(); struct B_SliceableD_tuple { B_SliceableD_tupleG_class $class; }; +extern GC_word B_SliceableD_tupleD_gcbm[GC_BITMAP_SIZE(struct B_SliceableD_tuple)]; struct B_SliceableD_tupleG_class { - char *$GCINFO; + GC_descr $GCdescr; + char *$name; int $class_id; $SuperG_class $superclass; B_NoneType (*__init__)(B_SliceableD_tuple); @@ -125,9 +131,11 @@ struct B_HashableD_tuple { int W_HashableB_tuple$size; B_Hashable *W_Hashable; }; +extern GC_word B_HashableD_tupleD_gcbm[GC_BITMAP_SIZE(struct B_HashableD_tuple)]; struct B_HashableD_tupleG_class { - char *$GCINFO; + GC_descr $GCdescr; + char *$name; int $class_id; $SuperG_class $superclass; B_NoneType (*__init__)(B_HashableD_tuple,int,B_Hashable*); @@ -165,7 +173,8 @@ extern struct B_HashableD_tuple *B_HashableD_tuple_new(int,B_Hashable*); typedef struct B_IteratorD_tuple *B_IteratorD_tuple; struct B_IteratorD_tupleG_class { - char *$GCINFO; + GC_descr $GCdescr; + char *$name; int $class_id; $SuperG_class $superclass; B_NoneType (*__init__)(B_IteratorD_tuple, B_tuple); @@ -182,6 +191,7 @@ struct B_IteratorD_tuple { B_tuple src; int nxt; }; +extern GC_word B_IteratorD_tupleD_gcbm[GC_BITMAP_SIZE(struct B_IteratorD_tuple)]; extern struct B_IteratorD_tupleG_class B_IteratorD_tupleG_methods; B_IteratorD_tuple B_IteratorD_tupleG_new(B_tuple); diff --git a/builtin/u16.c b/builtin/u16.c index 34e5d85c0..26e3d8389 100644 --- a/builtin/u16.c +++ b/builtin/u16.c @@ -12,6 +12,8 @@ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +GC_word B_u16D_gcbm[GC_BITMAP_SIZE(struct B_u16)]; + // Auxiliary ////////////////////////////////////////////////////////////////////////////// // only called with e>=0. @@ -114,7 +116,7 @@ B_str B_u16D___repr__(B_u16 n) { } B_u16 toB_u16(unsigned short i) { - B_u16 res = malloc(sizeof(struct B_u16)); + B_u16 res = GC_MALLOC_EXPLICITLY_TYPED(sizeof(struct B_u16), B_u16G_methods.$GCdescr); res->$class = &B_u16G_methods; res->val = i; return res; diff --git a/builtin/u16.h b/builtin/u16.h index 5b3929720..c4926ecbd 100644 --- a/builtin/u16.h +++ b/builtin/u16.h @@ -2,6 +2,7 @@ struct B_u16 { struct B_u16G_class *$class; unsigned short val; }; +extern GC_word B_u16D_gcbm[GC_BITMAP_SIZE(struct B_u16)]; B_u16 toB_u16(unsigned short n); unsigned short fromB_u16(B_u16 n); diff --git a/builtin/u32.c b/builtin/u32.c index f6aa87bc5..a6a5fb0d8 100644 --- a/builtin/u32.c +++ b/builtin/u32.c @@ -12,6 +12,8 @@ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +GC_word B_u32D_gcbm[GC_BITMAP_SIZE(struct B_u32)]; + // Auxiliary ////////////////////////////////////////////////////////////////////////////// // only called with e>=0. @@ -109,7 +111,7 @@ B_str B_u32D___repr__(B_u32 n) { } B_u32 toB_u32(unsigned int i) { - B_u32 res = malloc(sizeof(struct B_u32)); + B_u32 res = GC_MALLOC_EXPLICITLY_TYPED(sizeof(struct B_u32), B_u32G_methods.$GCdescr); res->$class = &B_u32G_methods; res->val = i; return res; diff --git a/builtin/u32.h b/builtin/u32.h index 0c1490b22..75d8a4c01 100644 --- a/builtin/u32.h +++ b/builtin/u32.h @@ -2,6 +2,7 @@ struct B_u32 { struct B_u32G_class *$class; unsigned int val; }; +extern GC_word B_u32D_gcbm[GC_BITMAP_SIZE(struct B_u32)]; B_u32 toB_u32(unsigned int n); unsigned int fromB_u32(B_u32 n); diff --git a/builtin/u64.c b/builtin/u64.c index ca6fdfdfc..eb0dfc217 100644 --- a/builtin/u64.c +++ b/builtin/u64.c @@ -12,6 +12,8 @@ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +GC_word B_u64D_gcbm[GC_BITMAP_SIZE(struct B_u64)]; + // Auxiliary ////////////////////////////////////////////////////////////////////////////// // only called with e>=0. @@ -104,7 +106,7 @@ B_str B_u64D___repr__(B_u64 n) { } B_u64 toB_u64(unsigned long i) { - B_u64 res = malloc(sizeof(struct B_u64)); + B_u64 res = GC_MALLOC_EXPLICITLY_TYPED(sizeof(struct B_u64), B_u64G_methods.$GCdescr); res->$class = &B_u64G_methods; res->val = i; return res; diff --git a/builtin/u64.h b/builtin/u64.h index 2582053b5..e413985ac 100644 --- a/builtin/u64.h +++ b/builtin/u64.h @@ -2,6 +2,7 @@ struct B_u64 { struct B_u64G_class *$class; unsigned long val; }; +extern GC_word B_u64D_gcbm[GC_BITMAP_SIZE(struct B_u64)]; B_u64 toB_u64(unsigned long n); unsigned long fromB_u64(B_u64 n); diff --git a/compiler/Acton/CodeGen.hs b/compiler/Acton/CodeGen.hs index 276380d04..62ba98e6e 100644 --- a/compiler/Acton/CodeGen.hs +++ b/compiler/Acton/CodeGen.hs @@ -141,7 +141,9 @@ hModule env (Module m imps stmts) = text "#pragma" <+> text "once" $+$ (if inBuiltin env then empty else include env "builtin" (modName ["builtin"]) $+$ + include env "builtin" (modName ["env"]) $+$ include env "rts" (modName ["rts"])) $+$ + text "#include" <+> doubleQuotes (text "gc/gc_typed.h") $+$ vcat (map (include env "types") $ modNames imps) $+$ hSuite env stmts $+$ text "void" <+> genTopName env initKW <+> parens empty <> semi @@ -163,7 +165,7 @@ declstub env Def{} = empty typedef env (Class _ n q a b) = text "typedef" <+> text "struct" <+> genTopName env n <+> char '*' <> genTopName env n <> semi typedef env Def{} = empty -decl env (Class _ n q a b) = (text "struct" <+> classname env n <+> char '{') $+$ +decl env (Class _ n q a b) = (text "struct" <+> classname env n <+> char '{') $+$ nest 4 (vcat $ stdprefix env ++ initdef : serialize env tc : deserialize env tc : meths) $+$ char '}' <> semi $+$ inst_struct @@ -173,7 +175,8 @@ decl env (Class _ n q a b) = (text "struct" <+> classname env n <+> cha inst_struct | initNotImpl = empty | otherwise = (text "struct" <+> genTopName env n <+> char '{') $+$ nest 4 (classlink env n $+$ vcat properties) $+$ - char '}' <> semi + char '}' <> semi $+$ + text "extern" <+> gcbm env n initNotImpl = any hasNotImpl [ b' | Decl _ ds <- b, Def{dname=n',dbody=b'} <- ds, n' == initKW ] decl env (Def _ n q p _ a _ _ fx) = gen env (exposeMsg fx $ fromJust a) <+> genTopName env n <+> parens (params env $ prowOf p) <> semi @@ -215,9 +218,11 @@ exposeMsg' t = t varsig env n t = gen env t <+> gen env n -stdprefix env = [gcinfo env, classid env, superlink env] +stdprefix env = [gcdescr env, class_name env, classid env, superlink env] -gcinfo env = text "char" <+> text "*" <> gen env gcinfoKW <> semi +gcdescr env = text "GC_descr" <+> gen env gcdescrKW <> semi +gcbm env n = text "GC_word" <+> genTopName env n <> text "D_gcbm" <> brackets (text "GC_BITMAP_SIZE" <> parens (text "struct" <+> genTopName env n)) <> semi +class_name env = text "char" <+> text "*" <> gen env classnameKW <> semi classid env = text "int" <+> gen env classidKW <> semi @@ -256,7 +261,8 @@ serializeSup env c = methodtable' env c <> dot <> gen env seria deserializeSup env c = methodtable' env c <> dot <> gen env deserializeKW classKW = primKW "class" -gcinfoKW = primKW "GCINFO" +gcdescrKW = primKW "GCdescr" +classnameKW = primKW "name" classidKW = primKW "class_id" superclassKW = primKW "superclass" componentsKW = name "components" @@ -301,11 +307,11 @@ cModule env srcbase (Module m imps stmts) ext_init $+$ initImports $+$ initModule env stmts) $+$ - if inBuiltin env then empty else char '}' -- Temporary fix until __builtin__ADD.c not necessary + char '}' where initImports = vcat [ gen env (GName m initKW) <> parens empty <> semi | m <- modNames imps ] external = hasNotImpl stmts && not (inBuiltin env) - ext_include = if external then text "#include" <+> doubleQuotes (text srcbase <> text ".ext.c") else empty - ext_init = if external then genTopName env (name "__ext_init__") <+> parens empty <> semi else empty + ext_include = if hasNotImpl stmts then text "#include" <+> doubleQuotes (text srcbase <> text ".ext.c") else empty + ext_init = if hasNotImpl stmts then genTopName env (name "__ext_init__") <+> parens empty <> semi else empty declModule env [] = empty @@ -335,7 +341,8 @@ declDecl env (Class _ n q as b) declSerialize env1 n c props sup_c $+$ declDeserialize env1 n c props sup_c $+$ declCon env1 n q b $+$ - text "struct" <+> classname env n <+> methodtable env n <> semi + text "struct" <+> classname env n <+> methodtable env n <> semi $+$ + gcbm env n where b' = subst [(tvSelf, tCon c)] b c = TC (NoQ n) (map tVar $ qbound q) env1 = defineTVars q env @@ -369,7 +376,7 @@ declDeserialize env n c props sup_c = (gen env (tCon c) <+> genTopName env (meth create) $+$ char '}' create = gen env self <+> text "=" <+> gen env primDNEW <> parens (genTopName env n <> comma <+> gen env st) <> semi - alloc = gen env self <+> equals <+> malloc env (gname env n) <> semi $+$ + alloc = gen env self <+> equals <+> typed_malloc env (gname env n) (methodtable env1 n) <> semi $+$ gen env self <> text "->" <> gen env1 classKW <+> equals <+> char '&' <> methodtable env1 n <> semi super_step | [c] <- sup_c = deserializeSup env (tcname c) <> parens (parens (gen env $ tcname c) <> gen env self <> comma <+> gen env st) <> semi | otherwise = empty @@ -391,7 +398,11 @@ initModule env (s : ss) = genStmt env s $+$ where te = envOf s `exclude` defined env env1 = gdefine te env -initClassBase env c q as hasCDef = methodtable env c <> dot <> gen env gcinfoKW <+> equals <+> doubleQuotes (genTopName env c) <> semi $+$ +-- TODO: complete GC_set_bit +initClassBase env c q as hasCDef = text "//" <+> genTopName env c <> text "D_gcbm" <+> text "is already initalized to 0 as bdwgc malloc is actually calloc" $+$ + vcat [ text "GC_set_bit" <> parens (genTopName env c <> text "D_gcbm" <> comma <+> text "GC_WORD_OFFSET" <> parens (text "struct" <+> genTopName env c <> comma <+> gen env n))<> semi | (n, NSig sc Property) <- fullAttrEnv env tc ] $+$ + methodtable env c <> dot <> gen env gcdescrKW <+> equals <+> text "GC_make_descriptor" <> parens (genTopName env c <> text "D_gcbm" <> comma <+> text "GC_WORD_LEN" <> parens (text "struct" <+> genTopName env c)) <> semi $+$ + methodtable env c <> dot <> gen env classnameKW <+> equals <+> doubleQuotes (genTopName env c) <> semi $+$ methodtable env c <> dot <> gen env superclassKW <+> equals <+> super <> semi $+$ vcat [ inherit c' n | (c',n) <- inheritedAttrs env (NoQ c) ] $+$ text "\n\n" where super = if null as then text "NULL" else parens (gen env qnSuperClass) <> text "&" <> methodtable' env (tcname $ head as) @@ -678,7 +689,7 @@ genNew env n p = newcon' env n <> parens (gen env p) declCon env n q b | null abstr || hasNotImpl b = (gen env tRes <+> newcon env n <> parens (gen env pars) <+> char '{') $+$ - nest 4 (gen env tObj <+> gen env tmpV <+> equals <+> malloc env (gname env n) <> semi $+$ + nest 4 (gen env tObj <+> gen env tmpV <+> equals <+> typed_malloc env (gname env n) (methodtable env1 n) <> semi $+$ gen env tmpV <> text "->" <> gen env1 classKW <+> equals <+> char '&' <> methodtable env1 n <> semi $+$ initcall env1) $+$ char '}' @@ -696,6 +707,7 @@ declCon env n q b env1 = ldefine ((tmpV, NVar tObj) : envOf pars) env abstr = abstractAttrs env (NoQ n) +typed_malloc env n mt = text "GC_MALLOC_EXPLICITLY_TYPED" <> parens (text "sizeof" <> parens (text "struct" <+> gen env n) <> comma <+> mt <> dot <> gen env gcdescrKW) malloc env n = text "malloc" <> parens (text "sizeof" <> parens (text "struct" <+> gen env n)) comma' x = if isEmpty x then empty else comma <+> x diff --git a/rts/pingpong.c b/rts/pingpong.c index a2ac0df14..05cdb1de6 100644 --- a/rts/pingpong.c +++ b/rts/pingpong.c @@ -200,6 +200,7 @@ Pingpong PingpongD___deserialize__(Pingpong res, B_NoneType state) { //////////////////////////////////////////////////////////////////////////////////////// struct lambda$1G_class lambda$1G_methods = { + 0, "lambda$1", UNASSIGNED, ($SuperG_class)&$ContG_methods, @@ -211,6 +212,7 @@ struct lambda$1G_class lambda$1G_methods = { lambda$1D___call__ }; struct lambda$2G_class lambda$2G_methods = { + 0, "lambda$2", UNASSIGNED, ($SuperG_class)&$ContG_methods, @@ -222,6 +224,7 @@ struct lambda$2G_class lambda$2G_methods = { lambda$2D___call__ }; struct lambda$3G_class lambda$3G_methods = { + 0, "lambda$3", UNASSIGNED, ($SuperG_class)&$ContG_methods, @@ -233,6 +236,7 @@ struct lambda$3G_class lambda$3G_methods = { lambda$3D___call__ }; struct PingpongG_class PingpongG_methods = { + 0, "Pingpong", UNASSIGNED, ($SuperG_class)&$ActorG_methods, diff --git a/rts/pingpong.h b/rts/pingpong.h index 5909e3888..47f45fed5 100644 --- a/rts/pingpong.h +++ b/rts/pingpong.h @@ -13,7 +13,8 @@ typedef struct lambda$3 *lambda$3; typedef struct Pingpong *Pingpong; struct lambda$1G_class { - char *$GCINFO; + GC_descr $GCdescr; + char *$name; int $class_id; $SuperG_class $superclass; void (*__init__)(lambda$1, Pingpong, B_int, B_int); @@ -29,10 +30,12 @@ struct lambda$1 { B_int count; B_int q; }; +extern GC_word lambda$1D_gcbm[GC_BITMAP_SIZE(struct lambda$1)]; lambda$1 lambda$1G_new(Pingpong, B_int, B_int); struct lambda$2G_class { - char *$GCINFO; + GC_descr $GCdescr; + char *$name; int $class_id; $SuperG_class $superclass; void (*__init__)(lambda$2, Pingpong, B_int); @@ -47,10 +50,12 @@ struct lambda$2 { Pingpong self; B_int q; }; +extern GC_word lambda$2D_gcbm[GC_BITMAP_SIZE(struct lambda$2)]; lambda$2 lambda$2G_new(Pingpong, B_int); struct lambda$3G_class { - char *$GCINFO; + GC_descr $GCdescr; + char *$name; int $class_id; $SuperG_class $superclass; void (*__init__)(lambda$3, $Cont); @@ -64,10 +69,12 @@ struct lambda$3 { struct lambda$3G_class *$class; $Cont cont; }; +extern GC_word lambda$3D_gcbm[GC_BITMAP_SIZE(struct lambda$3)]; lambda$3 lambda$3G_new($Cont); struct PingpongG_class { - char *$GCINFO; + GC_descr $GCdescr; + char *$name; int $class_id; $SuperG_class $superclass; $R (*__init__)(Pingpong, B_int, $Cont); @@ -92,6 +99,7 @@ struct Pingpong { B_int i; B_int count; }; +extern GC_word PingpongD_gcbm[GC_BITMAP_SIZE(struct Pingpong)]; $R PingpongG_new(B_int, $Cont); extern struct lambda$1G_class lambda$1G_methods; diff --git a/rts/rts.c b/rts/rts.c index c05236014..dd3c0a04a 100644 --- a/rts/rts.c +++ b/rts/rts.c @@ -230,7 +230,7 @@ pthread_cond_t rts_exit_signal = PTHREAD_COND_INITIALIZER; void pin_actor_affinity() { $Actor a = ($Actor)pthread_getspecific(self_key); int i = (int)pthread_getspecific(pkey_wtid); - log_debug("Pinning affinity for %s actor %ld to current WT %d", a->$class->$GCINFO, a->$globkey, i); + log_debug("Pinning affinity for %s actor %ld to current WT %d", a->$class->$name, a->$globkey, i); a->$affinity = i; } @@ -298,6 +298,7 @@ The strangeness of the next 30 lines are caused by the unfortunate presence of M */ +GC_word B_MsgD_gcbm[GC_BITMAP_SIZE(struct B_Msg)]; void B_MsgD___init__() { // Must (and will) never be called! } @@ -385,7 +386,7 @@ void $ActorD___init__($Actor a) { atomic_flag_clear(&a->B_Msg_lock); a->$globkey = get_next_key(); a->$affinity = 0; - rtsd_printf("# New Actor %ld at %p of class %s", a->$globkey, a, a->$class->$GCINFO); + rtsd_printf("# New Actor %ld at %p of class %s", a->$globkey, a, a->$class->$name); } B_bool $ActorD___bool__($Actor self) { @@ -394,7 +395,7 @@ B_bool $ActorD___bool__($Actor self) { B_str $ActorD___str__($Actor self) { char *s; - asprintf(&s,"<$Actor %ld %s at %p>", self->$globkey, self->$class->$GCINFO, self); + asprintf(&s,"<$Actor %ld %s at %p>", self->$globkey, self->$class->$name, self); return to$str(s); } @@ -501,6 +502,7 @@ void $ConstContD___serialize__($ConstCont self, $Serial$state state) { /* struct B_MsgG_class B_MsgG_methods = { + 0, MSG_HEADER, UNASSIGNED, NULL, @@ -514,6 +516,7 @@ struct B_MsgG_class B_MsgG_methods = { */ struct $ActorG_class $ActorG_methods = { + 0, ACTOR_HEADER, UNASSIGNED, NULL, @@ -527,6 +530,7 @@ struct $ActorG_class $ActorG_methods = { }; struct $CatcherG_class $CatcherG_methods = { + 0, CATCHER_HEADER, UNASSIGNED, NULL, @@ -539,6 +543,7 @@ struct $CatcherG_class $CatcherG_methods = { }; struct $ConstContG_class $ConstContG_methods = { + 0, "$ConstCont", UNASSIGNED, NULL, @@ -742,6 +747,7 @@ void $Done__serialize__($Cont self, $Serial$state state) { } struct $ContG_class $DoneG_methods = { + 0, "$Done", UNASSIGNED, NULL, @@ -782,6 +788,7 @@ void $Fail__serialize__($Cont self, $Serial$state state) { } struct $ContG_class $FailG_methods = { + 0, "$Fail", UNASSIGNED, NULL, @@ -803,6 +810,7 @@ struct $Cont $Fail$instance = { } struct $ContG_class $InitRootG_methods = { + 0, "$InitRoot", UNASSIGNED, NULL, @@ -1202,7 +1210,7 @@ void deserialize_system(snode_t *actors_start) { B_Msg msg = (B_Msg)$GET_METHODS(head->class_id)->__deserialize__(NULL, NULL); msg->$globkey = key; B_dictD_setitem(globdict, (B_Hashable)B_HashableD_intG_witness, to$int(key), msg); - rtsd_printf("# Allocated Msg %p = %ld of class %s = %d", msg, msg->$globkey, msg->$class->$GCINFO, msg->$class->$class_id); + rtsd_printf("# Allocated Msg %p = %ld of class %s = %d", msg, msg->$globkey, msg->$class->$name, msg->$class->$class_id); if (key < min_key) min_key = key; } @@ -1219,7 +1227,7 @@ void deserialize_system(snode_t *actors_start) { $Actor act = ($Actor)$GET_METHODS(head->class_id)->__deserialize__(NULL, NULL); act->$globkey = key; B_dictD_setitem(globdict, (B_Hashable)B_HashableD_intG_witness, to$int(key), act); - rtsd_printf("# Allocated Actor %p = %ld of class %s = %d", act, act->$globkey, act->$class->$GCINFO, act->$class->$class_id); + rtsd_printf("# Allocated Actor %p = %ld of class %s = %d", act, act->$globkey, act->$class->$name, act->$class->$class_id); if (key < min_key) min_key = key; } @@ -1237,7 +1245,7 @@ void deserialize_system(snode_t *actors_start) { int blob_size = r2->last_blob_size; $ROW row = extract_row(blob, blob_size); B_Msg msg = (B_Msg)B_dictD_get(globdict, (B_Hashable)B_HashableD_intG_witness, to$int(key), NULL); - rtsd_printf("####### Deserializing msg %p = %ld of class %s = %d", msg, msg->$globkey, msg->$class->$GCINFO, msg->$class->$class_id); + rtsd_printf("####### Deserializing msg %p = %ld of class %s = %d", msg, msg->$globkey, msg->$class->$name, msg->$class->$class_id); print_rows(row); $glob_deserialize(($Serializable)msg, row, try_globdict); print_msg(msg); @@ -1254,7 +1262,7 @@ void deserialize_system(snode_t *actors_start) { int blob_size = r2->last_blob_size; $ROW row = extract_row(blob, blob_size); $Actor act = ($Actor)B_dictD_get(globdict, (B_Hashable)B_HashableD_intG_witness, to$int(key), NULL); - rtsd_printf("####### Deserializing actor %p = %ld of class %s = %d", act, act->$globkey, act->$class->$GCINFO, act->$class->$class_id); + rtsd_printf("####### Deserializing actor %p = %ld of class %s = %d", act, act->$globkey, act->$class->$name, act->$class->$class_id); print_rows(row); $glob_deserialize(($Serializable)act, row, try_globdict); @@ -1291,7 +1299,7 @@ void deserialize_system(snode_t *actors_start) { db_row_t* r = (db_row_t*) node->value; long key = (long)r->key; $Actor act = ($Actor)B_dictD_get(globdict, (B_Hashable)B_HashableD_intG_witness, to$int(key), NULL); - rtsd_printf("####### Resuming actor %p = %ld of class %s = %d", act, act->$globkey, act->$class->$GCINFO, act->$class->$class_id); + rtsd_printf("####### Resuming actor %p = %ld of class %s = %d", act, act->$globkey, act->$class->$name, act->$class->$class_id); act->$class->__resume__(act); } @@ -1565,7 +1573,7 @@ void wt_work_cb(uv_check_t *ev) { clock_gettime(CLOCK_MONOTONIC, &ts1); wt_stats[wtid].state = WT_Working; - rtsd_printf("## Running actor %ld : %s", current->$globkey, current->$class->$GCINFO); + rtsd_printf("## Running actor %ld : %s", current->$globkey, current->$class->$name); $R r = cont->$class->__call__(cont, val); clock_gettime(CLOCK_MONOTONIC, &ts2); @@ -1596,10 +1604,10 @@ void wt_work_cb(uv_check_t *ev) { b->$waitsfor = NULL; $Actor c = b->$next; ENQ_ready(b); - rtsd_printf("## Waking up actor %ld : %s", b->$globkey, b->$class->$GCINFO); + rtsd_printf("## Waking up actor %ld : %s", b->$globkey, b->$class->$name); b = c; } - rtsd_printf("## DONE actor %ld : %s", current->$globkey, current->$class->$GCINFO); + rtsd_printf("## DONE actor %ld : %s", current->$globkey, current->$class->$name); if (DEQ_msg(current)) { ENQ_ready(current); } @@ -1608,7 +1616,7 @@ void wt_work_cb(uv_check_t *ev) { case $RCONT: { m->$cont = r.cont; m->B_value = r.value; - rtsd_printf("## CONT actor %ld : %s", current->$globkey, current->$class->$GCINFO); + rtsd_printf("## CONT actor %ld : %s", current->$globkey, current->$class->$name); ENQ_ready(current); break; } @@ -1617,7 +1625,7 @@ void wt_work_cb(uv_check_t *ev) { if (c) { // Normal exception handling m->$cont = c->$cont; m->B_value = r.value; - rtsd_printf("## FAIL/handle actor %ld : %s", current->$globkey, current->$class->$GCINFO); + rtsd_printf("## FAIL/handle actor %ld : %s", current->$globkey, current->$class->$name); ENQ_ready(current); } else { // An unhandled exception save_actor_state(current, m); @@ -1629,10 +1637,10 @@ void wt_work_cb(uv_check_t *ev) { b->$waitsfor = NULL; $Actor c = b->$next; ENQ_ready(b); - rtsd_printf("## Propagating exception to actor %ld : %s", b->$globkey, b->$class->$GCINFO); + rtsd_printf("## Propagating exception to actor %ld : %s", b->$globkey, b->$class->$name); b = c; } - rtsd_printf("## FAIL actor %ld : %s", current->$globkey, current->$class->$GCINFO); + rtsd_printf("## FAIL actor %ld : %s", current->$globkey, current->$class->$name); if (DEQ_msg(current)) { ENQ_ready(current); } @@ -1665,15 +1673,15 @@ void wt_work_cb(uv_check_t *ev) { m->$cont = r.cont; B_Msg x = (B_Msg)r.value; if (ADD_waiting(current, x)) { // x->cont is a proper $Cont: x is still being processed so current was added to x->waiting - rtsd_printf("## AWAIT actor %ld : %s", current->$globkey, current->$class->$GCINFO); + rtsd_printf("## AWAIT actor %ld : %s", current->$globkey, current->$class->$name); current->$waitsfor = x; } else if (EXCEPTIONAL(x)) { // x->cont == MARK_EXCEPTION: x->value holds the raised exception, current is not in x->waiting - rtsd_printf("## AWAIT/fail actor %ld : %s", current->$globkey, current->$class->$GCINFO); + rtsd_printf("## AWAIT/fail actor %ld : %s", current->$globkey, current->$class->$name); m->$cont = &$Fail$instance; m->B_value = x->B_value; ENQ_ready(current); } else { // x->cont == MARK_RESULT: x->value holds the final response, current is not in x->waiting - rtsd_printf("## AWAIT/wakeup actor %ld : %s", current->$globkey, current->$class->$GCINFO); + rtsd_printf("## AWAIT/wakeup actor %ld : %s", current->$globkey, current->$class->$name); m->B_value = x->B_value; ENQ_ready(current); } diff --git a/rts/rts.h b/rts/rts.h index fa2345913..f1be3edb0 100644 --- a/rts/rts.h +++ b/rts/rts.h @@ -45,7 +45,8 @@ extern struct $ConstContG_class $ConstContG_methods; /* Defined in builtin/__builtin__.h with wrong type for __init__ struct B_MsgG_class { - char *$GCINFO; + GC_descr $GCdescr; + char *$name; int $class_id; $SuperG_class $superclass; void (*__init__)(B_Msg, $Actor, $Cont, time_t, $WORD); @@ -67,9 +68,11 @@ struct B_Msg { $WORD B_value; $long $globkey; }; +extern GC_word B_MsgD_gcbm[GC_BITMAP_SIZE(struct B_Msg)]; struct $ActorG_class { - char *$GCINFO; + GC_descr $GCdescr; + char *$name; int $class_id; $SuperG_class $superclass; void (*__init__)($Actor); @@ -92,9 +95,11 @@ struct $Actor { $long $globkey; $int64 $affinity; }; +extern GC_word $ActorD_gcbm[GC_BITMAP_SIZE(struct $Actor)]; struct $CatcherG_class { - char *$GCINFO; + GC_descr $GCdescr; + char *$name; int $class_id; $SuperG_class $superclass; void (*__init__)($Catcher, $Cont); @@ -109,10 +114,12 @@ struct $Catcher { $Catcher $next; $Cont $cont; }; +extern GC_word $CatcherD_gcbm[GC_BITMAP_SIZE(struct $Catcher)]; struct $ConstContG_class { - char *$GCINFO; + GC_descr $GCdescr; + char *$name; int $class_id; $SuperG_class $superclass; void (*__init__)($ConstCont, $WORD, $Cont); @@ -128,6 +135,7 @@ struct $ConstCont { $WORD val; $Cont cont; }; +extern GC_word $ConstContD_gcbm[GC_BITMAP_SIZE(struct $ConstCont)]; $Cont $CONSTCONT($WORD, $Cont); B_Msg $ASYNC($Actor, $Cont); diff --git a/stdlib/c_src/numpy/ndarray.c b/stdlib/c_src/numpy/ndarray.c index df0961cb7..8d169b0ff 100644 --- a/stdlib/c_src/numpy/ndarray.c +++ b/stdlib/c_src/numpy/ndarray.c @@ -363,6 +363,7 @@ numpyQ_ndarray numpyQ_ndarrayD___ndgetslice__(numpyQ_ndarray a, B_list ix) { } struct numpyQ_ndarrayG_class numpyQ_ndarrayG_methods = { + 0, "numpyQ_ndarray", UNASSIGNED, ($SuperG_class)&B_valueG_methods, @@ -849,8 +850,7 @@ numpyQ_IteratorD_ndarray numpyQ_IteratorD_ndarray$_deserialize(numpyQ_IteratorD_ return NULL; } -struct numpyQ_IteratorD_ndarrayG_class numpyQ_IteratorD_ndarrayG_methods = {"",UNASSIGNED,($SuperG_class)&B_IteratorG_methods, numpyQ_IteratorD_init, - numpyQ_IteratorD_$serialize, numpyQ_IteratorD_ndarray$_deserialize,numpyQ_IteratorB_bool, +struct numpyQ_IteratorD_ndarrayG_class numpyQ_IteratorD_ndarrayG_methods = {0,"",UNASSIGNED,($SuperG_class)&B_IteratorG_methods, numpyQ_IteratorD_init, numpyQ_IteratorD_$serialize, numpyQ_IteratorD_ndarray$_deserialize,numpyQ_IteratorB_bool, numpyQ_IteratorB_str,numpyQ_IteratorB_str,numpyQ_IteratorD_ndarrayD___next__}; numpyQ_ndarray numpyQ_roll(numpyQ_Primitive pwit, numpyQ_ndarray a, B_int n) { diff --git a/stdlib/c_src/numpy/ndselect.c b/stdlib/c_src/numpy/ndselect.c index 206921ac3..fd3ee43e2 100644 --- a/stdlib/c_src/numpy/ndselect.c +++ b/stdlib/c_src/numpy/ndselect.c @@ -25,6 +25,7 @@ numpyQ_ndselect numpyQ_ndselectD___deserialize__(numpyQ_ndselect wit, $Serial$st } struct numpyQ_ndselectG_class numpyQ_ndselectG_methods = { + 0, "numpyQ_ndselect", UNASSIGNED, ($SuperG_class)&B_valueG_methods, @@ -63,6 +64,7 @@ numpyQ_ndindex numpyQ_ndindexD___deserialize__(numpyQ_ndindex self, $Serial$stat } struct numpyQ_ndindexG_class numpyQ_ndindexG_methods = { + 0, "numpyQ_ndindex", UNASSIGNED, ($SuperG_class)&B_valueG_methods, @@ -100,6 +102,7 @@ numpyQ_ndslice numpyQ_ndsliceD___deserialize__(numpyQ_ndslice self, $Serial$stat } struct numpyQ_ndsliceG_class numpyQ_ndsliceG_methods = { + 0, "numpyQ_ndslice", UNASSIGNED, ($SuperG_class)&B_valueG_methods, diff --git a/stdlib/c_src/numpy/primitive.c b/stdlib/c_src/numpy/primitive.c index cdb0f7299..f3659a49b 100644 --- a/stdlib/c_src/numpy/primitive.c +++ b/stdlib/c_src/numpy/primitive.c @@ -180,16 +180,14 @@ numpyQ_PrimitiveD_float numpyQ_PrimitiveD_floatD_deserialize(numpyQ_PrimitiveD_f } -struct numpyQ_PrimitiveD_intG_class numpyQ_PrimitiveD_intG_methods = {"numpyQ_PrimitiveD_int",UNASSIGNED,NULL,(B_NoneType (*)(numpyQ_PrimitiveD_int))$default__init__, - numpyQ_PrimitiveD_intD_serialize,numpyQ_PrimitiveD_intD_deserialize,NULL,NULL,NULL, +struct numpyQ_PrimitiveD_intG_class numpyQ_PrimitiveD_intG_methods = {0,"numpyQ_PrimitiveD_int",UNASSIGNED,NULL,(B_NoneType (*)(numpyQ_PrimitiveD_int))$default__init__, numpyQ_PrimitiveD_intD_serialize,numpyQ_PrimitiveD_intD_deserialize,NULL,NULL,NULL, LongType,to$objB_int,from$objB_int,B_l_prim_str, B_l_add,B_l_sub,B_l_mul,B_l_truediv,B_l_floordiv,B_l_mod,B_l_land,B_l_lor,B_l_band,B_l_bor,B_l_bxor,B_l_lsh,B_l_rsh,lB_pow, B_l_iadd,B_l_isub,B_l_imul,B_l_itruediv,B_l_ifloordiv,B_l_imod,B_l_iband,B_l_ibor,B_l_ibxor,B_l_ilsh,B_l_irsh, B_l_eq,B_l_neq,B_l_lt,B_l_le,B_l_gt,B_l_ge,lB_abs,B_l_neg,B_l_lnot,B_l_bnot}; -struct numpyQ_PrimitiveD_floatG_class numpyQ_PrimitiveD_floatG_methods = {"numpyQ_PrimitiveD_float",UNASSIGNED,NULL,(B_NoneType (*)(numpyQ_PrimitiveD_float))$default__init__, - numpyQ_PrimitiveD_floatD_serialize,numpyQ_PrimitiveD_floatD_deserialize,NULL,NULL,NULL, +struct numpyQ_PrimitiveD_floatG_class numpyQ_PrimitiveD_floatG_methods = {0,"numpyQ_PrimitiveD_float",UNASSIGNED,NULL,(B_NoneType (*)(numpyQ_PrimitiveD_float))$default__init__, numpyQ_PrimitiveD_floatD_serialize,numpyQ_PrimitiveD_floatD_deserialize,NULL,NULL,NULL, DblType,to$objB_float,from$objB_float,B_d_prim_str, B_d_add,B_d_sub,B_d_mul,B_d_truediv,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,dB_pow, B_d_iadd,B_d_isub,B_d_imul,B_d_itruediv,NULL,NULL,NULL,NULL,NULL,NULL,NULL, diff --git a/stdlib/c_src/numpy/protocol_impls.c b/stdlib/c_src/numpy/protocol_impls.c index 44e9a98af..bcc87ae8b 100644 --- a/stdlib/c_src/numpy/protocol_impls.c +++ b/stdlib/c_src/numpy/protocol_impls.c @@ -428,6 +428,7 @@ struct numpyQ_MinusD_ndarray numpyQ_MinusD_ndarray$instance; struct numpyQ_SliceableD_ndarray numpyQ_SliceableD_ndarray$instance; struct numpyQ_IntegralD_ndarrayD_intG_class numpyQ_IntegralD_ndarrayD_intG_methods = { + 0, "numpyQ_IntegralD_ndarrayD_int", UNASSIGNED, ($SuperG_class)&B_IntegralG_methods, @@ -477,6 +478,7 @@ struct numpyQ_IntegralD_ndarrayD_int numpyQ_IntegralD_ndarrayD_int$instance = {& numpyQ_IntegralD_ndarrayD_int numpyQ_IntegralD_ndarrayD_intG_witness = &numpyQ_IntegralD_ndarrayD_int$instance; struct numpyQ_LogicalD_ndarrayD_intG_class numpyQ_LogicalD_ndarrayD_intG_methods = { + 0, "numpyQ_LogicalD_ndarrayD_int", UNASSIGNED, ($SuperG_class)&B_LogicalG_methods, @@ -498,6 +500,7 @@ struct numpyQ_LogicalD_ndarrayD_int numpyQ_LogicalD_ndarrayD_int$instance = {&nu numpyQ_LogicalD_ndarrayD_int numpyQ_LogicalD_ndarrayD_intG_witness = &numpyQ_LogicalD_ndarrayD_int$instance; struct numpyQ_MinusD_ndarrayD_intG_class numpyQ_MinusD_ndarrayD_intG_methods = { + 0, "numpyQ_MinusD_ndarrayD_int", UNASSIGNED, ($SuperG_class)&B_MinusG_methods, @@ -514,6 +517,7 @@ struct numpyQ_MinusD_ndarrayD_int numpyQ_MinusD_ndarrayD_int$instance = {&numpyQ numpyQ_MinusD_ndarrayD_int numpyQ_MinusD_ndarrayD_intG_witness = &numpyQ_MinusD_ndarrayD_int$instance; struct numpyQ_RealD_ndarrayG_class numpyQ_RealD_ndarrayG_methods = { + 0, "numpyQ_RealD_ndarray", UNASSIGNED, ($SuperG_class)&B_IntegralG_methods, @@ -545,6 +549,7 @@ struct numpyQ_RealD_ndarrayG_class numpyQ_RealD_ndarrayG_methods = { }; struct numpyQ_MinusD_ndarrayG_class numpyQ_MinusD_ndarrayG_methods = { + 0, "numpyQ_MinusD_ndarray", UNASSIGNED, ($SuperG_class)&B_MinusG_methods, @@ -562,6 +567,7 @@ struct numpyQ_MinusD_ndarray numpyQ_MinusD_ndarray$instance = {&numpyQ_MinusD_nd numpyQ_MinusD_ndarray numpyQ_MinusD_ndarrayG_witness = &numpyQ_MinusD_ndarray$instance; struct numpyQ_DivD_ndarrayD_intG_class numpyQ_DivD_ndarrayD_intG_methods = { + 0, "numpyQ_DivD_ndarrayD_int", UNASSIGNED, ($SuperG_class)&B_MinusG_methods, @@ -579,6 +585,7 @@ struct numpyQ_DivD_ndarrayD_int numpyQ_DivD_ndarrayD_int$instance = {&numpyQ_Div numpyQ_DivD_ndarrayD_int numpyQ_DivD_ndarrayD_intG_witness = &numpyQ_DivD_ndarrayD_int$instance; struct numpyQ_DivD_ndarrayD_floatG_class numpyQ_DivD_ndarrayD_floatG_methods = { + 0, "numpyQ_DivD_ndarrayD_float", UNASSIGNED, ($SuperG_class)&B_MinusG_methods, @@ -596,6 +603,7 @@ struct numpyQ_DivD_ndarrayD_float numpyQ_DivD_ndarrayD_float$instance = {&numpyQ numpyQ_DivD_ndarrayD_float numpyQ_DivD_ndarrayD_floatG_witness = &numpyQ_DivD_ndarrayD_float$instance; struct numpyQ_SliceableD_ndarrayG_class numpyQ_SliceableD_ndarrayG_methods = { + 0, "numpyQ_SliceableD_ndarray", UNASSIGNED, ($SuperG_class)&B_SliceableG_methods, @@ -617,6 +625,7 @@ numpyQ_SliceableD_ndarray numpyQ_SliceableD_ndarrayG_witness = &numpyQ_Sliceable struct numpyQ_CollectionD_ndarrayG_class numpyQ_CollectionD_ndarrayG_methods = { + 0, "numpyQ_CollectionD_ndarray", UNASSIGNED, ($SuperG_class)&B_CollectionG_methods, @@ -728,6 +737,7 @@ numpyQ_RealFunsD_mathD_ndarray numpyQ_RealFunsD_mathD_ndarrayG_new(numpyQ_Primit return $tmp; } struct numpyQ_RealFunsD_mathD_ndarrayG_class numpyQ_RealFunsD_mathD_ndarrayG_methods = { + 0, "numpyQ_RealFunsD_mathD_ndarray", UNASSIGNED, ($SuperG_class)&mathQ_RealFunsG_methods, diff --git a/stdlib/src/json.ext.c b/stdlib/src/json.ext.c index c7b777af1..8d5663b29 100644 --- a/stdlib/src/json.ext.c +++ b/stdlib/src/json.ext.c @@ -17,7 +17,7 @@ void jsonQ_encode_dict(yyjson_mut_doc *doc, yyjson_mut_val *node, B_dict data) { char *key = (char *)fromB_str((B_str)item->components[0]); char *value = (char *)fromB_str((B_str)item->components[1]); B_value v = item->components[1]; - //log_info("key: %s class_id: %d type: %s", key, v->$class->$class_id, v->$class->$GCINFO); + //log_info("key: %s class_id: %d type: %s", key, v->$class->$class_id, v->$class->$name); switch (v->$class->$class_id) { case INT_ID:; yyjson_mut_obj_add_int(doc, node, key, from$int((B_int)v)); diff --git a/stdlib/src/math.c b/stdlib/src/math.c index 0778aacea..4136c9cf0 100644 --- a/stdlib/src/math.c +++ b/stdlib/src/math.c @@ -19,12 +19,13 @@ B_NoneType mathQ_RealFunsD___init__ (mathQ_RealFuns W_self) { return B_None; } mathQ_RealFuns mathQ_RealFunsG_new() { - mathQ_RealFuns $tmp = malloc(sizeof(struct mathQ_RealFuns)); + mathQ_RealFuns $tmp = GC_MALLOC_EXPLICITLY_TYPED(sizeof(struct mathQ_RealFuns), mathQ_RealFunsG_methods.$GCdescr); $tmp->$class = &mathQ_RealFunsG_methods; mathQ_RealFunsG_methods.__init__($tmp); return $tmp; } struct mathQ_RealFunsG_class mathQ_RealFunsG_methods; +GC_word mathQ_RealFunsD_gcbm[GC_BITMAP_SIZE(struct mathQ_RealFuns)]; B_NoneType mathQ_RealFunsD_floatD___init__ (mathQ_RealFunsD_float W_self) { mathQ_RealFunsG_methods.__init__((mathQ_RealFuns)W_self); return B_None; @@ -86,24 +87,29 @@ B_float mathQ_RealFunsD_float$atanh(mathQ_RealFunsD_float wit, B_float x) { mathQ_RealFunsD_float mathQ_RealFunsD_floatG_new() { - mathQ_RealFunsD_float $tmp = malloc(sizeof(struct mathQ_RealFunsD_float)); + mathQ_RealFunsD_float $tmp = GC_MALLOC_EXPLICITLY_TYPED(sizeof(struct mathQ_RealFunsD_float), mathQ_RealFunsD_floatG_methods.$GCdescr); $tmp->$class = &mathQ_RealFunsD_floatG_methods; mathQ_RealFunsD_floatG_methods.__init__($tmp); return $tmp; } struct mathQ_RealFunsD_floatG_class mathQ_RealFunsD_floatG_methods; +GC_word mathQ_RealFunsD_floatD_gcbm[GC_BITMAP_SIZE(struct mathQ_RealFunsD_float)]; int mathQ_done$ = 0; void mathQ___init__ () { if (mathQ_done$) return; mathQ_done$ = 1; { - mathQ_RealFunsG_methods.$GCINFO = "mathQ_RealFuns"; + memset(mathQ_RealFunsD_gcbm, 0xFF, sizeof(mathQ_RealFunsD_gcbm)); + mathQ_RealFunsG_methods.$GCdescr = GC_make_descriptor(mathQ_RealFunsD_gcbm, GC_WORD_LEN(struct mathQ_RealFuns)); + mathQ_RealFunsG_methods.$name = "mathQ_RealFuns"; mathQ_RealFunsG_methods.$superclass = NULL; mathQ_RealFunsG_methods.__init__ = mathQ_RealFunsD___init__; $register(&mathQ_RealFunsG_methods); } { - mathQ_RealFunsD_floatG_methods.$GCINFO = "mathQ_RealFunsD_float"; + memset(mathQ_RealFunsD_floatD_gcbm, 0xFF, sizeof(mathQ_RealFunsD_floatD_gcbm)); + mathQ_RealFunsD_floatG_methods.$GCdescr = GC_make_descriptor(mathQ_RealFunsD_floatD_gcbm, GC_WORD_LEN(struct mathQ_RealFunsD_float)); + mathQ_RealFunsD_floatG_methods.$name = "mathQ_RealFunsD_float"; mathQ_RealFunsD_floatG_methods.$superclass = ($SuperG_class)&mathQ_RealFunsG_methods; mathQ_RealFunsD_floatG_methods.__serialize__ = mathQ_RealFunsD_floatD___serialize__, mathQ_RealFunsD_floatG_methods.__deserialize__ = mathQ_RealFunsD_floatD___deserialize__, diff --git a/stdlib/src/math.h b/stdlib/src/math.h index 3dd41be1a..03671958c 100644 --- a/stdlib/src/math.h +++ b/stdlib/src/math.h @@ -5,7 +5,8 @@ struct mathQ_RealFuns; typedef struct mathQ_RealFuns *mathQ_RealFuns; struct mathQ_RealFunsG_class { - char *$GCINFO; + GC_descr $GCdescr; + char *$name; B_int $class_id; $SuperG_class $superclass; B_NoneType (*__init__) (mathQ_RealFuns); @@ -33,12 +34,14 @@ struct mathQ_RealFunsG_class { struct mathQ_RealFuns { struct mathQ_RealFunsG_class *$class; }; +extern GC_word mathQ_RealFunsD_gcbm[GC_BITMAP_SIZE(struct mathQ_RealFuns)]; extern struct mathQ_RealFunsG_class mathQ_RealFunsG_methods; mathQ_RealFuns mathQ_RealFunsG_new(); struct mathQ_RealFunsD_float; typedef struct mathQ_RealFunsD_float *mathQ_RealFunsD_float; struct mathQ_RealFunsD_floatG_class { - char *$GCINFO; + GC_descr $GCdescr; + char *$name; B_int $class_id; $SuperG_class $superclass; B_NoneType (*__init__) (mathQ_RealFunsD_float); @@ -66,6 +69,7 @@ struct mathQ_RealFunsD_floatG_class { struct mathQ_RealFunsD_float { struct mathQ_RealFunsD_floatG_class *$class; }; +extern GC_word mathQ_RealFunsD_floatD_gcbm[GC_BITMAP_SIZE(struct mathQ_RealFunsD_float)]; extern struct mathQ_RealFunsD_floatG_class mathQ_RealFunsD_floatG_methods; mathQ_RealFunsD_float mathQ_RealFunsD_floatG_new(); $WORD mathQ_sqrt (mathQ_RealFuns, $WORD); diff --git a/stdlib/src/numpy.h b/stdlib/src/numpy.h index 0fdc7633c..f93a7b8ca 100644 --- a/stdlib/src/numpy.h +++ b/stdlib/src/numpy.h @@ -6,7 +6,8 @@ struct numpyQ_ndselect; typedef struct numpyQ_ndselect *numpyQ_ndselect; struct numpyQ_ndselectG_class { - char *$GCINFO; + GC_descr $GCdescr; + char *$name; int $class_id; $SuperG_class $superclass; B_NoneType (*__init__) (numpyQ_ndselect); @@ -19,12 +20,14 @@ struct numpyQ_ndselectG_class { struct numpyQ_ndselect { struct numpyQ_ndselectG_class *$class; }; +extern GC_word numpyQ_ndselectD_gcbm[GC_BITMAP_SIZE(struct numpyQ_ndselect)]; extern struct numpyQ_ndselectG_class numpyQ_ndselectG_methods; numpyQ_ndselect numpyQ_ndselectG_new(); struct numpyQ_ndindex; typedef struct numpyQ_ndindex *numpyQ_ndindex; struct numpyQ_ndindexG_class { - char *$GCINFO; + GC_descr $GCdescr; + char *$name; int $class_id; $SuperG_class $superclass; B_NoneType (*__init__) (numpyQ_ndindex, B_int); @@ -38,6 +41,7 @@ struct numpyQ_ndindex { struct numpyQ_ndindexG_class *$class; B_int index; }; +extern GC_word numpyQ_ndindexD_gcbm[GC_BITMAP_SIZE(struct numpyQ_ndindex)]; extern struct numpyQ_ndindexG_class numpyQ_ndindexG_methods; numpyQ_ndindex numpyQ_ndindexG_new(B_int); @@ -45,7 +49,8 @@ numpyQ_ndindex numpyQ_ndindexG_new(B_int); struct numpyQ_ndslice; typedef struct numpyQ_ndslice *numpyQ_ndslice; struct numpyQ_ndsliceG_class { - char *$GCINFO; + GC_descr $GCdescr; + char *$name; int $class_id; $SuperG_class $superclass; B_NoneType (*__init__) (numpyQ_ndslice, B_slice); @@ -59,6 +64,7 @@ struct numpyQ_ndslice { struct numpyQ_ndsliceG_class *$class; B_slice slc; }; +extern GC_word numpyQ_ndsliceD_gcbm[GC_BITMAP_SIZE(struct numpyQ_ndslice)]; extern struct numpyQ_ndsliceG_class numpyQ_ndsliceG_methods; numpyQ_ndslice numpyQ_ndsliceG_new(B_slice); @@ -92,6 +98,7 @@ typedef struct numpyQ_PrimitiveD_floatG_class *numpyQ_PrimitiveD_floatG_class; struct numpyQ_Primitive { numpyQ_PrimitiveG_class $class; }; +extern GC_word numpyQ_PrimitiveD_gcbm[GC_BITMAP_SIZE(struct numpyQ_Primitive)]; union $Bytes8 { long l; @@ -103,7 +110,8 @@ enum ElemType {LongType,DblType}; int $elem_size(enum ElemType typ); struct numpyQ_PrimitiveG_class { - char *$GCINFO; + GC_descr $GCdescr; + char *$name; int $class_id; $SuperG_class $superclass; B_NoneType (*__init__)(numpyQ_Primitive); @@ -161,9 +169,11 @@ B_str B_l_prim_str(union $Bytes8 n); struct numpyQ_PrimitiveD_int { numpyQ_PrimitiveD_intG_class $class; }; +extern GC_word numpyQ_PrimitiveD_intD_gcbm[GC_BITMAP_SIZE(struct numpyQ_PrimitiveD_int)]; struct numpyQ_PrimitiveD_intG_class { - char *$GCINFO; + GC_descr $GCdescr; + char *$name; int $class_id; $SuperG_class $superclass; B_NoneType (*__init__)(numpyQ_PrimitiveD_int); @@ -218,9 +228,11 @@ struct numpyQ_PrimitiveD_intG_class { struct numpyQ_PrimitiveD_float { numpyQ_PrimitiveD_floatG_class $class; }; +extern GC_word numpyQ_PrimitiveD_floatD_gcbm[GC_BITMAP_SIZE(struct numpyQ_PrimitiveD_float)]; struct numpyQ_PrimitiveD_floatG_class { - char *$GCINFO; + GC_descr $GCdescr; + char *$name; int $class_id; $SuperG_class $superclass; B_NoneType (*__init__)(numpyQ_PrimitiveD_float); @@ -287,7 +299,8 @@ struct numpyQ_ndarray; typedef struct numpyQ_ndarray *numpyQ_ndarray; struct numpyQ_ndarrayG_class { - char *$GCINFO; + GC_descr $GCdescr; + char *$name; int $class_id; $SuperG_class $superclass; B_NoneType (*__init__)(numpyQ_ndarray,numpyQ_Primitive,B_atom); @@ -314,6 +327,7 @@ struct numpyQ_ndarray { B_list strides; union $Bytes8 *data; }; +extern GC_word numpyQ_ndarrayD_gcbm[GC_BITMAP_SIZE(struct numpyQ_ndarray)]; extern struct numpyQ_ndarrayG_class numpyQ_ndarrayG_methods; @@ -338,7 +352,8 @@ typedef struct numpyQ_array_iterator_state { typedef struct numpyQ_IteratorD_ndarray *numpyQ_IteratorD_ndarray; ; struct numpyQ_IteratorD_ndarrayG_class { - char *$GCINFO; + GC_descr $GCdescr; + char *$name; int $class_id; $SuperG_class $superclass; B_NoneType (*__init__)(numpyQ_IteratorD_ndarray, numpyQ_Primitive, numpyQ_ndarray); @@ -357,6 +372,7 @@ struct numpyQ_IteratorD_ndarray { numpyQ_Primitive pwit; numpyQ_array_iterator_state it; }; +extern GC_word numpyQ_IteratorD_ndarrayD_gcbm[GC_BITMAP_SIZE(struct numpyQ_IteratorD_ndarray)]; extern struct numpyQ_IteratorD_ndarrayG_class numpyQ_IteratorD_ndarrayG_methods; @@ -466,9 +482,11 @@ struct numpyQ_IntegralD_ndarrayD_int { B_Logical W_Logical; B_Minus W_Minus; }; +extern GC_word numpyQ_IntegralD_ndarrayD_intD_gcbm[GC_BITMAP_SIZE(struct numpyQ_IntegralD_ndarrayD_int)]; struct numpyQ_IntegralD_ndarrayD_intG_class { - char *$GCINFO; + GC_descr $GCdescr; + char *$name; int $class_id; $SuperG_class $superclass; B_NoneType (*__init__)(numpyQ_IntegralD_ndarrayD_int); @@ -549,9 +567,11 @@ struct numpyQ_LogicalD_ndarrayD_int { numpyQ_LogicalD_ndarrayD_intG_class $class; B_Integral W_Integral; }; +extern GC_word numpyQ_LogicalD_ndarrayD_intD_gcbm[GC_BITMAP_SIZE(struct numpyQ_LogicalD_ndarrayD_int)]; struct numpyQ_LogicalD_ndarrayD_intG_class { - char *$GCINFO; + GC_descr $GCdescr; + char *$name; int $class_id; $SuperG_class $superclass; B_NoneType (*__init__)(numpyQ_LogicalD_ndarrayD_int, B_Integral); @@ -581,9 +601,11 @@ struct numpyQ_MinusD_ndarrayD_int { numpyQ_MinusD_ndarrayD_intG_class $class; B_Integral W_Integral; }; +extern GC_word numpyQ_MinusD_ndarrayD_intD_gcbm[GC_BITMAP_SIZE(struct numpyQ_MinusD_ndarrayD_int)]; struct numpyQ_MinusD_ndarrayD_intG_class { - char *$GCINFO; + GC_descr $GCdescr; + char *$name; int $class_id; $SuperG_class $superclass; B_NoneType (*__init__)(numpyQ_MinusD_ndarrayD_int, B_Integral); @@ -608,9 +630,11 @@ struct numpyQ_RealD_ndarray { B_Minus W_Minus; numpyQ_Primitive W_PrimitiveD_AD_RealD_ndarray; }; +extern GC_word numpyQ_RealD_ndarrayD_gcbm[GC_BITMAP_SIZE(struct numpyQ_RealD_ndarray)]; struct numpyQ_RealD_ndarrayG_class { - char *$GCINFO; + GC_descr $GCdescr; + char *$name; int $class_id; $SuperG_class $superclass; B_NoneType (*__init__)(numpyQ_RealD_ndarray, numpyQ_Primitive); @@ -667,9 +691,11 @@ struct numpyQ_MinusD_ndarray { numpyQ_MinusD_ndarrayG_class $class; B_Real W_Real; }; +extern GC_word numpyQ_MinusD_ndarrayD_gcbm[GC_BITMAP_SIZE(struct numpyQ_MinusD_ndarray)]; struct numpyQ_MinusD_ndarrayG_class { - char *$GCINFO; + GC_descr $GCdescr; + char *$name; int $class_id; $SuperG_class $superclass; B_NoneType (*__init__)(numpyQ_MinusD_ndarray, B_Real); @@ -693,9 +719,11 @@ struct numpyQ_DivD_ndarrayD_int { numpyQ_DivD_ndarrayD_intG_class $class; B_Real W_Real; }; +extern GC_word numpyQ_DivD_ndarrayD_intD_gcbm[GC_BITMAP_SIZE(struct numpyQ_DivD_ndarrayD_int)]; struct numpyQ_DivD_ndarrayD_intG_class { - char *$GCINFO; + GC_descr $GCdescr; + char *$name; int $class_id; $SuperG_class $superclass; B_NoneType (*__init__)(numpyQ_DivD_ndarrayD_int); @@ -719,9 +747,11 @@ struct numpyQ_DivD_ndarrayD_float { numpyQ_DivD_ndarrayD_floatG_class $class; B_Real W_Real; }; +extern GC_word numpyQ_DivD_ndarrayD_floatD_gcbm[GC_BITMAP_SIZE(struct numpyQ_DivD_ndarrayD_float)]; struct numpyQ_DivD_ndarrayD_floatG_class { - char *$GCINFO; + GC_descr $GCdescr; + char *$name; int $class_id; $SuperG_class $superclass; B_NoneType (*__init__)(numpyQ_DivD_ndarrayD_float); @@ -745,7 +775,8 @@ struct numpyQ_SliceableD_ndarray; typedef struct numpyQ_SliceableD_ndarray *numpyQ_SliceableD_ndarray; struct numpyQ_SliceableD_ndarrayG_class { - char *$GCINFO; + GC_descr $GCdescr; + char *$name; int $class_id; $SuperG_class $superclass; B_NoneType (*__init__) (numpyQ_SliceableD_ndarray, numpyQ_Primitive); @@ -765,6 +796,7 @@ struct numpyQ_SliceableD_ndarray { numpyQ_SliceableD_ndarrayG_class $class; numpyQ_Primitive pwit; }; +extern GC_word numpyQ_SliceableD_ndarrayD_gcbm[GC_BITMAP_SIZE(struct numpyQ_SliceableD_ndarray)]; // numpyQ_CollectionD_ndarray //////////////////////////////////////////////////////////// @@ -773,9 +805,11 @@ struct numpyQ_CollectionD_ndarray { numpyQ_CollectionD_ndarrayG_class $class; numpyQ_Primitive pwit; }; +extern GC_word numpyQ_CollectionD_ndarrayD_gcbm[GC_BITMAP_SIZE(struct numpyQ_CollectionD_ndarray)]; struct numpyQ_CollectionD_ndarrayG_class { - char *$GCINFO; + GC_descr $GCdescr; + char *$name; int $class_id; $SuperG_class $superclass; B_NoneType (*__init__)(numpyQ_CollectionD_ndarray, numpyQ_Primitive); @@ -806,7 +840,8 @@ numpyQ_RealD_ndarray numpyQ_RealFloat$ndarrayG_new(numpyQ_Primitive,B_RealFloat) struct numpyQ_RealFunsD_mathD_ndarray; typedef struct numpyQ_RealFunsD_mathD_ndarray *numpyQ_RealFunsD_mathD_ndarray; struct numpyQ_RealFunsD_mathD_ndarrayG_class { - char *$GCINFO; + GC_descr $GCdescr; + char *$name; int $class_id; $SuperG_class $superclass; B_NoneType (*__init__) (numpyQ_RealFunsD_mathD_ndarray, numpyQ_Primitive, mathQ_RealFuns); @@ -836,6 +871,7 @@ struct numpyQ_RealFunsD_mathD_ndarray { numpyQ_Primitive W_PrimitiveD_AD_RealFuns$math$ndarray; mathQ_RealFuns W_RealFuns$mathD_AD_RealFuns$math$ndarray; }; +extern GC_word numpyQ_RealFunsD_mathD_ndarrayD_gcbm[GC_BITMAP_SIZE(struct numpyQ_RealFunsD_mathD_ndarray)]; extern struct numpyQ_RealFunsD_mathD_ndarrayG_class numpyQ_RealFunsD_mathD_ndarrayG_methods; diff --git a/utils/gc/check.py b/utils/gc/check.py new file mode 100755 index 000000000..37e25e39c --- /dev/null +++ b/utils/gc/check.py @@ -0,0 +1,161 @@ +#!/usr/bin/env python3 + +import argparse +import os +import re + +found_classes = {} + +def found_class(name, + gcbm_declared=None, + gcbm_defined=None, + gcbm_zeroinit=None, + gcbm_safeinit=None, + gcbm_set=None, + gcdescr_declared=None, + gcdescr_zeroinit=None, + gcdescr_set=None, + malloc=0, + tmalloc=0): + if name not in found_classes: + found_classes[name] = { + "gcbm_declared": gcbm_declared, + 'gcbm_defined': gcbm_defined, + 'gcbm_zeroinit': gcbm_zeroinit, + 'gcbm_safeinit': gcbm_safeinit, + 'gcbm_set': gcbm_set, + 'gcdescr_declared': gcdescr_declared, + 'gcdescr_zeroinit': gcdescr_zeroinit, + 'gcdescr_set': gcdescr_set, + 'malloc': 0, + 'tmalloc': 0, + } + + if gcbm_declared is not None: + found_classes[name]['gcbm_declared'] = gcbm_declared + if gcbm_defined is not None: + found_classes[name]["gcbm_defined"] = gcbm_defined + if gcbm_zeroinit is not None: + found_classes[name]["gcbm_zeroinit"] = gcbm_zeroinit + if gcbm_safeinit is not None: + found_classes[name]["gcbm_safeinit"] = gcbm_safeinit + if gcdescr_declared is not None: + found_classes[name]["gcdescr_declared"] = gcdescr_declared + if gcdescr_zeroinit is not None: + found_classes[name]["gcdescr_zeroinit"] = gcdescr_zeroinit + if gcdescr_set is not None: + found_classes[name]["gcdescr_set"] = gcdescr_set + + found_classes[name]["malloc"] += malloc + found_classes[name]["tmalloc"] += tmalloc + + +def find_c_and_h_files(root_dir): + for dirpath, dirnames, filenames in os.walk(root_dir): + for filename in filenames: + if filename.endswith(".c") or filename.endswith(".h"): + file_path = os.path.join(dirpath, filename) + if filename.endswith(".c"): + process_file(file_path, check_c_file) + elif filename.endswith(".h"): + process_file(file_path, check_h_file) + +def process_file(file_path, check_function): + print(f"Processing {file_path}") + lines = read_file(file_path) + check_function(lines) + +def read_file(file_path): + with open(file_path, 'r') as f: + lines = f.readlines() + return lines + +def check_c_file(lines): + for line in lines: + # Look for definition of the GC bitmap + m = re.match(r"^GC_word ([^ ]+)D_gcbm\[", line) + if m: + found_class(m.group(1), gcbm_defined=True) + + # Check if memset is used to initialize the GC bitmap _gcbm + m = re.search(r"memset\(&([^ ]+)D_gcbm, 0, sizeof\([^ ]+D_gcbm\)\);", line) + if m: + found_class(m.group(1), gcbm_safeinit=True) + + # Find struct definitions for our classes, i.e. the struct used will end + # with G_class and the name will end with G_methods + m = re.match(r"^struct\s+([^ ]+)G_class ([^ ]+)G_methods = {", line) + if m: + found_class(m.group(2), gcdescr_zeroinit=True) + + # Look for GCdescr in the method table being set using GC_make_descriptor + m = re.match(r" +([^ ]+)G_methods.\$GCdescr = GC_make_descriptor", line) + if m: + found_class(m.group(1), gcdescr_set=True) + + # Look for plain malloc + m = re.search(r"malloc\(sizeof\(struct ([^)]+)\)", line) + if m: + found_class(m.group(1), malloc=1) + + # Look for GC_MALLOC_EXPLICITLY_TYPED using the class name and GCdescr + m = re.search(r"GC_MALLOC_EXPLICITLY_TYPED\(sizeof\(struct ([^ ]+)\), ([^ ]+)G_methods.\$GCdescr\)", line) + if m: + found_class(m.group(1), tmalloc=1) + + +def check_h_file(lines): + in_struct = None + for line in lines: + m = re.match(r"^struct ([^ ]+)G_class {", line) + if m: + in_struct = m.group(1) + + if in_struct is not None: + if line.strip() == "};": + in_struct = None + if re.match(r"^ +GC_descr \$GCdescr;", line): + found_class(in_struct, gcdescr_declared=True) + + m = re.match(r"extern GC_word ([^ ]+)D_gcbm", line) + if m: + found_class(m.group(1), gcbm_declared=True) + + +if __name__ == "__main__": + parser = argparse.ArgumentParser(description="Find and patch .c and .h files.") + parser.add_argument( + "-d", "--directory", type=str, default=".", help="The directory to scan (default: current directory)" + ) + args = parser.parse_args() + + find_c_and_h_files("builtin") + find_c_and_h_files("rts") + find_c_and_h_files("stdlib") + # Show found classes and their status as indicated in the found_classes + # dict. Each field is marked with an X if set to True or an empty space if + # set to False. The fields are: + # - gcbm_declared: _gcbm declared in .h file + # - gcbm_defined: _gcbm defined in .c file but not initialized + # - gcbm_zeroinit: _gcbm initialized in .c file to 0 + # - gcbm_safeinit: _gcbm initialized in .c file to 1 (will be scanned, thus safe) + # - gcbm_set: _gcbm set to proper value + # - gcdescr_defined: gcdescr defined in .h file + # - gcdescr_set: gcdescr set to proper value + # - malloc: malloc is used in a struct definition + for c in sorted(found_classes.keys()): + cl = found_classes[c] + # Skip classes that don't have anything set, they're likely not relevant + # for us, e.g. plain mallocs of entirely different classes + print(f"{c:40} BM:" + + f"{cl['gcbm_declared'] and 'd' or ' '}" + + f"{cl['gcbm_defined'] and 'D' or ' '}" + + f"{cl['gcbm_zeroinit'] and '0' or ' '}" + + f"{cl['gcbm_safeinit'] and '1' or ' '}" + + f"{cl['gcbm_set'] and '+' or ' '}" + + " GCdescr:" + + f"{cl['gcdescr_declared'] and 'd' or ' '}" + + f"{cl['gcdescr_declared'] and 'D' or ' '}" + + f"{cl['gcdescr_zeroinit'] and '0' or ' '}" + + f"{cl['gcdescr_set'] and '+' or ' '}" + + f" malloc: {cl['malloc']} / {cl['tmalloc']}") diff --git a/utils/gc/patchy.py b/utils/gc/patchy.py new file mode 100755 index 000000000..1cb20acab --- /dev/null +++ b/utils/gc/patchy.py @@ -0,0 +1,190 @@ +#!/usr/bin/env python3 + +import argparse +import os +import re + +found_classes = {} + +def found_class(name, gcbm_declared=None, gcbm_defined=None, gcbm_initialized=None, gcbm_set=None, gcdescr_defined=None, gcdescr_set=None, malloc=None): + if name not in found_classes: + found_classes[name] = { + "gcbm_declared": gcbm_declared, + 'gcbm_defined': gcbm_defined, + 'gcbm_initialized': gcbm_initialized, + 'gcbm_set': gcbm_set, + 'gcdescr_defined': gcdescr_defined, + 'gcdescr_set': gcdescr_set, + 'malloc': malloc, + } + if gcbm_declared is not None: + found_classes[name]['gcbm_declared'] = gcbm_declared + if gcbm_defined is not None: + found_classes[name]["gcbm_defined"] = gcbm_defined + if gcbm_initialized is not None: + found_classes[name]["gcbm_initialized"] = gcbm_initialized + if gcdescr_defined is not None: + found_classes[name]["gcdescr_defined"] = gcdescr_defined + if gcdescr_set is not None: + found_classes[name]["gcdescr_set"] = gcdescr_set + if malloc is not None: + found_classes[name]["malloc"] = malloc + +def find_c_and_h_files(root_dir): + for dirpath, dirnames, filenames in os.walk(root_dir): + for filename in filenames: + if filename.endswith(".c") or filename.endswith(".h"): + file_path = os.path.join(dirpath, filename) + if filename.endswith(".c"): + process_file(file_path, patch_c_file) + elif filename.endswith(".h"): + process_file(file_path, patch_h_file) + +def process_file(file_path, patch_function): + print(f"Processing {file_path}") + lines = read_file(file_path) + modified_lines = patch_function(lines) + write_file(file_path, modified_lines) + +def read_file(file_path): + with open(file_path, 'r') as f: + lines = f.readlines() + return lines + +def write_file(file_path, lines): + with open(file_path, 'w') as f: + # For __builtin__.h and __builtin__.c, add include at the top. + if file_path.endswith("__builtin__.h") or file_path.endswith("__builtin__.c"): + f.write('#include "gc/gc_typed.h"\n') + f.writelines(lines) + +def patch_c_file(lines): + res = [] + malloc_line = None + for line in lines: + m = re.match(r"^struct (([^ ]+)G_class) ([^ ]+)_methods;", line) + if m: + found_class(m.group(2), gcbm_defined=True) + res.append(line) + res.append(f"GC_word {m.group(2)}D_gcbm[GC_BITMAP_SIZE(struct {m.group(2)})];\n") + continue + + # Find struct definitions of method tables, which match a struct + # definition name ending with _class and a variable name ending with + # _methods. Insert 0 as the first element when initializing the struct. + m = re.match(r"^struct ([^ ]+)G_class ([^ ]+)G_methods = {$", line) + if m: + found_class(m.group(2), gcbm_initialized=True) + res.append(f"struct {m.group(1)}G_class {m.group(2)}G_methods = {{\n 0,\n") + continue + + m = re.match(r"^struct ([^ ]+)G_class ([^ ]+)G_methods = {(.*)", line) + if m: + found_class(m.group(2), gcbm_initialized=True) + res.append(f"struct {m.group(1)}G_class {m.group(2)}G_methods = {{0," + m.group(3)) + continue + + # Replace $GCINFO with $name + m = re.match(r"^( +)([^ ]+)\.\$GCINFO =(.*)", line) + if m: + oname = re.sub(r"G_methods", "", m.group(2)) + gcbm = re.sub(r"G_methods", "D_gcbm", m.group(2)) + res.append(f"{m.group(1)}memset({gcbm}, 0xFF, sizeof({gcbm}));\n") + found_class(m.group(2).replace("G_methods", ""), gcbm_initialized=True) + res.append(f"{m.group(1)}{m.group(2)}.$GCdescr = GC_make_descriptor({gcbm}, GC_WORD_LEN(struct {oname}));\n") + found_class(m.group(2).replace("G_methods", ""), gcdescr_set=True) + res.append(f"{m.group(1)}{m.group(2)}.$name ={m.group(3)}\n") + continue + + m = re.search(r"\$class->\$GCINFO", line) + if m: + res.append(re.sub(r"\$class->\$GCINFO", "$class->$name", line)) + continue + + # Replace malloc with GC_MALLOC_EXPLICITLY_TYPED + m = re.match(r"^( +)self = malloc\(sizeof\(struct ([^)]+)\)\);", line) + if m: + # Suppress malloc here and emit it on next loop + malloc_line = m + #res.append(f"{m.group(1)}{m.group(2)} = GC_MALLOC_EXPLICITLY_TYPED(sizeof(struct {m.group(3)}), );\n") + continue + + m = re.match(r"^( +)self->\$class = &([^;]+G_methods);", line) + if malloc_line is not None and m: + if malloc_line.group(2) != m.group(2).replace("G_methods", ""): + raise ValueError(f"ERROR: malloc and class name mismatch: {malloc_line.group(2)} != {m.group(1)}") + + res.append(f"{malloc_line.group(1)}self = GC_MALLOC_EXPLICITLY_TYPED(sizeof(struct {malloc_line.group(2)}), {m.group(2)}.$GCdescr);\n") + res.append(line) + found_class(malloc_line.group(2).replace("G_methods", ""), malloc=True) + malloc_line = None + continue + + # In line like this: + # B_TimesD_str $tmp = malloc(sizeof(struct B_TimesD_str)); + # replace malloc with GC_MALLOC_EXPLICITLY_TYPED + m = re.match(r"^( +)([^ ]+) \$tmp = malloc\(sizeof\(struct ([^)]+)\)\);", line) + if m: + res.append(f"{m.group(1)}{m.group(2)} $tmp = GC_MALLOC_EXPLICITLY_TYPED(sizeof(struct {m.group(3)}), {m.group(3)}G_methods.$GCdescr);\n") + found_class(m.group(3), malloc=True) + continue + + res.append(line) + return res + +def patch_h_file(lines): + res = [] + in_struct = False + add_after = None + for line in lines: + + m = re.match(r"^struct ([^ ]+) {", line) + if m and m.group(1) not in ("$R", "$ROW", "$ROWLISTHEADER"): + in_struct = True + if not m.group(1).endswith('_class'): + found_class(m.group(1), gcbm_declared=True) + found_class(m.group(1), gcdescr_defined=True) + add_after = f"extern GC_word {m.group(1)}D_gcbm[GC_BITMAP_SIZE(struct {m.group(1)})];\n" + + if in_struct: + if line.strip() == "};": + in_struct = False + # Replace $GCINFO with $GCdescr + m = re.match(r"^( +)char.*GCINFO;", line) + if m: + res.append(f"{m.group(1)}GC_descr $GCdescr;\n") + res.append(f"{m.group(1)}char *$name;\n") + continue + + res.append(line) + + if add_after and re.match(r"^};", line): + res.append(add_after) + add_after = None + + return res + + +if __name__ == "__main__": + parser = argparse.ArgumentParser(description="Find and patch .c and .h files.") + parser.add_argument( + "-d", "--directory", type=str, default=".", help="The directory to scan (default: current directory)" + ) + args = parser.parse_args() + + find_c_and_h_files("builtin") + find_c_and_h_files("rts") + find_c_and_h_files("stdlib") + # Show found classes and their status as indicated in the found_classes + # dict. Each field is marked with an X if set to True or an empty space if + # set to False. The fields are: + # - gcbm_declared: _gcbm declared in .h file + # - gcbm_defined: _gcbm defined in .c file + # - gcbm_initialized: _gcbm initialized in .c file to 0 + # - gcbm_set: _gcbm set to proper value + # - gcdescr_defined: gcdescr defined in .h file + # - gcdescr_set: gcdescr set to proper value + # - malloc: malloc is used in a struct definition + for c in sorted(found_classes.keys()): + cl = found_classes[c] + print(f"{c:40} {cl['gcbm_declared'] and 'X' or ' '}{cl['gcbm_defined'] and 'X' or ' '}{cl['gcbm_initialized'] and 'X' or ' '}{cl['gcbm_set'] and 'X' or ' '}{cl['gcdescr_defined'] and 'X' or ' '}{cl['gcdescr_set'] and 'X' or ' '}{cl['malloc'] and 'X' or ' '}")