From fb2571213389ae74648b1369ebf3748642f7236d Mon Sep 17 00:00:00 2001 From: hyung-hwan Date: Thu, 25 Jul 2024 02:44:43 +0900 Subject: [PATCH] removed the nivars and ncvars fields from class --- lib/exec.c | 8 ++++++-- lib/gc.c | 5 ++--- lib/hcl.h | 4 +--- lib/obj.c | 14 +++++++++++--- 4 files changed, 20 insertions(+), 11 deletions(-) diff --git a/lib/exec.c b/lib/exec.c index 2a7ba93..39cdc14 100644 --- a/lib/exec.c +++ b/lib/exec.c @@ -3933,9 +3933,13 @@ static int execute (hcl_t* hcl) /* 0(non-kernel object), 1(incomplete kernel object), 2(complete kernel object) */ if (HCL_OBJ_GET_FLAGS_KERNEL(class_obj) == 1) { -hcl_logbfmt (hcl, HCL_LOG_STDERR, ">>>%O c->sc=%O sc=%O b2=%d b3=%d nivars=%d ncvars=%d<<<\n", class_obj, class_obj->superclass, superclass, b2, b3, (int)HCL_OOP_TO_SMOOI(class_obj->nivars), (int)HCL_OOP_TO_SMOOI(class_obj->ncvars)); /* check if the new definition is compatible with kernel definition */ - if (class_obj->superclass != superclass || HCL_OOP_TO_SMOOI(class_obj->nivars) != b2 || HCL_OOP_TO_SMOOI(class_obj->ncvars) != b3) + hcl_ooi_t spec, selfspec; + + spec = HCL_OOP_TO_SMOOI(class_obj->spec); + selfspec = HCL_OOP_TO_SMOOI(class_obj->selfspec); +hcl_logbfmt (hcl, HCL_LOG_STDERR, ">>>%O c->sc=%O sc=%O b2=%d b3=%d nivars=%d ncvars=%d<<<\n", class_obj, class_obj->superclass, superclass, b2, b3, (int)HCL_CLASS_SPEC_NAMED_INSTVARS(spec), (int)HCL_CLASS_SELFSPEC_CLASSVARS(spec)); + if (class_obj->superclass != superclass || HCL_CLASS_SPEC_NAMED_INSTVARS(spec) != b2 || HCL_CLASS_SELFSPEC_CLASSVARS(selfspec) != b3) { hcl_seterrbfmt (hcl, HCL_EPERM, "incompatible redefintion of %.*js", HCL_OBJ_GET_SIZE(class_name), HCL_OBJ_GET_CHAR_SLOT(class_name)); if (do_throw_with_internal_errmsg(hcl, fetched_instruction_pointer) >= 0) break; diff --git a/lib/gc.c b/lib/gc.c index 01e4abb..34922af 100644 --- a/lib/gc.c +++ b/lib/gc.c @@ -1185,9 +1185,8 @@ static hcl_oop_class_t alloc_kernel_class (hcl_t* hcl, int class_flags, hcl_oow_ c->selfspec = HCL_SMOOI_TO_OOP(HCL_CLASS_SELFSPEC_MAKE(num_classvars, 0, class_flags)); /* TODO: remove the following two duplicate fields with the spec fields */ - c->nivars = HCL_SMOOI_TO_OOP(HCL_CLASS_SPEC_NAMED_INSTVARS(spec)); - //c->nivars = HCL_SMOOI_TO_OOP(0); - c->ncvars = HCL_SMOOI_TO_OOP(num_classvars); + //c->nivars = HCL_SMOOI_TO_OOP(HCL_CLASS_SPEC_NAMED_INSTVARS(spec)); + //c->ncvars = HCL_SMOOI_TO_OOP(num_classvars); c->nivars_super = HCL_SMOOI_TO_OOP(0); /* TODO: encode it into spec? */ c->ibrand = HCL_SMOOI_TO_OOP(ibrand); diff --git a/lib/hcl.h b/lib/hcl.h index 2523279..f10ef32 100644 --- a/lib/hcl.h +++ b/lib/hcl.h @@ -858,7 +858,7 @@ struct hcl_process_scheduler_t }; -#define HCL_CLASS_NAMED_INSTVARS 11 +#define HCL_CLASS_NAMED_INSTVARS 9 typedef struct hcl_class_t hcl_class_t; typedef struct hcl_class_t* hcl_oop_class_t; struct hcl_class_t @@ -872,8 +872,6 @@ struct hcl_class_t hcl_oop_t selfspec; /* SmallInteger. specification of the class object itself */ hcl_oop_t superclass; - hcl_oop_t nivars; /* SmallInteger. */ - hcl_oop_t ncvars; /* SmallInteger. */ hcl_oop_t nivars_super; /* SmallInteger */ hcl_oop_t ibrand; /* SmallInteger */ diff --git a/lib/obj.c b/lib/obj.c index 9901b81..1f0f6e1 100644 --- a/lib/obj.c +++ b/lib/obj.c @@ -488,14 +488,22 @@ hcl_oop_t hcl_makeclass (hcl_t* hcl, hcl_oop_t class_name, hcl_oop_t superclass, /* TODO: other flags... indexable? byte? word?*/ spec = HCL_CLASS_SPEC_MAKE(nivars, 0, 0); /* TODO: how to include nivars_super ? */ selfspec = HCL_CLASS_SELFSPEC_MAKE(ncvars, 0, 0); - nivars_super = HCL_IS_NIL(hcl, superclass)? 0: HCL_OOP_TO_SMOOI(((hcl_oop_class_t)superclass)->nivars_super) + HCL_OOP_TO_SMOOI(((hcl_oop_class_t)superclass)->nivars); + + if (!HCL_IS_NIL(hcl, superclass)) + { + hcl_ooi_t superspec; + superspec = HCL_OOP_TO_SMOOI(((hcl_oop_class_t)superclass)->spec); + nivars_super = HCL_OOP_TO_SMOOI(((hcl_oop_class_t)superclass)->nivars_super) + HCL_CLASS_SPEC_NAMED_INSTVARS(superspec); + } + else + { + nivars_super = 0; + } c->spec = HCL_SMOOI_TO_OOP(spec); c->selfspec = HCL_SMOOI_TO_OOP(selfspec); c->name = class_name; c->superclass = superclass; - c->nivars = HCL_SMOOI_TO_OOP(nivars); - c->ncvars = HCL_SMOOI_TO_OOP(ncvars); c->nivars_super = HCL_SMOOI_TO_OOP(nivars_super); c->ibrand = HCL_SMOOI_TO_OOP(HCL_BRAND_INSTANCE); /* TODO: really need ibrand??? */