From 4afb064530fad9a46c82781b414657205e0f2ad4 Mon Sep 17 00:00:00 2001 From: hyung-hwan Date: Mon, 26 Feb 2024 13:34:09 +0900 Subject: [PATCH] writing full oop bootstrapping code --- lib/gc.c | 40 ++++++++++++++++++++++++++++++++++++++++ lib/hcl.h | 5 +++++ 2 files changed, 45 insertions(+) diff --git a/lib/gc.c b/lib/gc.c index aab2215..b9bb48e 100644 --- a/lib/gc.c +++ b/lib/gc.c @@ -757,6 +757,44 @@ hcl_oop_t hcl_shallowcopy (hcl_t* hcl, hcl_oop_t oop) /* ========================================================================= */ +static struct +{ + const char* name; + hcl_oow_t offset; +} ctab[] = { + { "Object", HCL_OFFSETOF(hcl_t, class_object) }, + { "Class", HCL_OFFSETOF(hcl_t, class_class) }, + { "Symbol", HCL_OFFSETOF(hcl_t, class_symbol) }, + { "String", HCL_OFFSETOF(hcl_t, class_string) }, +}; + +static int make_classes (hcl_t* hcl) +{ + hcl_oop_class_t c; + hcl_oow_t i; + +#if 0 + /* create class objects */ + for (i = 0; i < HCL_COUNTOF(ctab); i++) + { + if (*ctab[i].ref) continue; + + c = (hcl_oop_class_t)hcl_makeclass(hcl, hcl->_nil, nivars, ncvars, "ivars_str", "cvars_str"); + if (HCL_UNLIKELY(!c)) return -1; + + *(hcl_oop_class_t*)((hcl_uint8_t*)hcl + ctab[i].offset) = c; + } + + /* update the superclass field */ + for (i = 0; i < HCL_COUNTOF(ctab); i++) + { + c = *(hcl_oop_class_t*)((hcl_uint8_t*)hcl + ctab[i].offset); + //c->superclass = + } +#endif + + return 0; +} int hcl_ignite (hcl_t* hcl, hcl_oow_t heapsize) { @@ -847,6 +885,8 @@ int hcl_ignite (hcl_t* hcl, hcl_oow_t heapsize) hcl->sp = HCL_OOP_TO_SMOOI(hcl->processor->active->sp); } + if (make_classes(hcl) <= -1) return -1; + /* TODO: move this initialization to hcl_init? */ if (hcl_brewcode(hcl, &hcl->code) <= -1) return -1; diff --git a/lib/hcl.h b/lib/hcl.h index 2210e0d..0d1938f 100644 --- a/lib/hcl.h +++ b/lib/hcl.h @@ -1632,6 +1632,11 @@ struct hcl_t hcl_oop_process_scheduler_t processor; /* instance of ProcessScheduler */ hcl_oop_process_t nil_process; /* instance of Process */ + hcl_oop_class_t class_object; /* class 'Object' */ + hcl_oop_class_t class_class; /* class 'Class' */ + hcl_oop_class_t class_symbol; /* class 'Symbol' */ + hcl_oop_class_t class_string; /* class 'String' */ + /* ============================================================================= */ /* pending asynchronous semaphores */