Skip to content

Commit 90b0b11

Browse files
committed
Fix remaining issues with CONFIG_EXPERIMENTAL_MMAP_DEC
With this, deemon is able to run `util/test.dee` without any issues. Next step will be for me to build deemon on my various test systems with `CONFIG_EXPERIMENTAL_MMAP_DEC` enabled, and make sure that everything works. And can I just say: hot damn! These new .dec files may be way larger than the old ones, but man: do they ever load **way** faster. The `misc-import-lib` is now pretty much one of the fastest tests of them all!
1 parent f382a3c commit 90b0b11

File tree

3 files changed

+124
-3
lines changed

3 files changed

+124
-3
lines changed

include/deemon/api.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -497,7 +497,7 @@ __pragma_GCC_diagnostic_ignored(Wstringop_overread)
497497
#define CONFIG_NO_EXPERIMENTAL_MMAP_DEC
498498
#elif (!defined(CONFIG_EXPERIMENTAL_MMAP_DEC) && \
499499
!defined(CONFIG_NO_EXPERIMENTAL_MMAP_DEC))
500-
#if 0 /* TODO: Implementation is incomplete */
500+
#if 0 /* TODO: Implementation is complete -- do testing in different environments, then enable by default */
501501
#define CONFIG_EXPERIMENTAL_MMAP_DEC
502502
#else
503503
#define CONFIG_NO_EXPERIMENTAL_MMAP_DEC

src/deemon/compiler/compiler.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,10 @@ DeeExec_CompileModuleStream_impl(DeeObject *source_stream,
464464
DREF DeeModuleObject *result;
465465
#endif /* !CONFIG_EXPERIMENTAL_MMAP_DEC */
466466
uint16_t assembler_flags;
467-
uint64_t ctime = DeeSystem_GetWalltime();
467+
uint64_t ctime;
468+
#ifndef CONFIG_EXPERIMENTAL_MMAP_DEC
469+
ctime = DeeSystem_GetWalltime();
470+
#endif /* !CONFIG_EXPERIMENTAL_MMAP_DEC */
468471

469472
compiler = DeeCompiler_New(options ? options->co_compiler : COMPILER_FNORMAL);
470473
if unlikely(!compiler)
@@ -649,6 +652,11 @@ DeeExec_CompileModuleStream_impl(DeeObject *source_stream,
649652

650653
/* Finally, put together the module itself. */
651654
#ifdef CONFIG_EXPERIMENTAL_MMAP_DEC
655+
/* Use timestamp of compilation having completed. Otherwise, the .dec file we'd
656+
* eventually produce would have a timestamp less than those of our dependencies,
657+
* which would mean we'd be considered as older than our dependencies and in need
658+
* of a re-compilation. */
659+
ctime = DeeSystem_GetWalltime();
652660
result = module_compile(writer, root_code, ctime);
653661
#else /* CONFIG_EXPERIMENTAL_MMAP_DEC */
654662
result = module_compile(root_code, ctime);

src/deemon/objects/class_desc.c

Lines changed: 114 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
#include <deemon/object.h>
4141
#include <deemon/property.h>
4242
#include <deemon/seq.h>
43+
#include <deemon/serial.h>
4344
#include <deemon/string.h>
4445
#include <deemon/super.h>
4546
#include <deemon/system-features.h> /* memcpy(), ... */
@@ -1371,6 +1372,118 @@ cd_visit(ClassDescriptor *__restrict self, Dee_visit_t proc, void *arg) {
13711372
Dee_XVisit(self->cd_doc);
13721373
}
13731374

1375+
PRIVATE WUNUSED NONNULL((1)) Dee_seraddr_t DCALL
1376+
cd_serialize(ClassDescriptor *__restrict self, DeeSerial *__restrict writer) {
1377+
ClassDescriptor *out;
1378+
Dee_seraddr_t out_addr;
1379+
size_t i, sizeof_self;
1380+
sizeof_self = offsetof(ClassDescriptor, cd_iattr_list) +
1381+
(self->cd_iattr_mask + 1) *
1382+
sizeof(struct Dee_class_attribute);
1383+
out_addr = DeeSerial_ObjectMalloc(writer, sizeof_self, self);
1384+
if (!Dee_SERADDR_ISOK(out_addr))
1385+
goto err;
1386+
out = DeeSerial_Addr2Mem(writer, out_addr, ClassDescriptor);
1387+
#define ADDROF(field) (out_addr + offsetof(ClassDescriptor, field))
1388+
out->cd_flags = self->cd_flags;
1389+
out->cd_cmemb_size = self->cd_cmemb_size;
1390+
out->cd_imemb_size = self->cd_imemb_size;
1391+
out->cd_clsop_mask = self->cd_clsop_mask;
1392+
out->cd_cattr_mask = self->cd_cattr_mask;
1393+
out->cd_iattr_mask = self->cd_iattr_mask;
1394+
memcpyc(out->cd_iattr_list, self->cd_iattr_list,
1395+
self->cd_iattr_mask + 1,
1396+
sizeof(struct Dee_class_attribute));
1397+
1398+
/* Write class name and doc-string */
1399+
if (DeeSerial_XPutObject(writer, ADDROF(cd_name), self->cd_name))
1400+
goto err;
1401+
if (DeeSerial_XPutObject(writer, ADDROF(cd_doc), self->cd_doc))
1402+
goto err;
1403+
1404+
/* Write instance attribute table. */
1405+
for (i = 0; i <= self->cd_iattr_mask; ++i) {
1406+
Dee_seraddr_t out_addr__cd_iattr_list__i;
1407+
if (!self->cd_iattr_list[i].ca_name)
1408+
continue;
1409+
out_addr__cd_iattr_list__i = ADDROF(cd_iattr_list);
1410+
out_addr__cd_iattr_list__i += i * sizeof(struct Dee_class_attribute);
1411+
if (DeeSerial_PutObject(writer,
1412+
out_addr__cd_iattr_list__i +
1413+
offsetof(struct Dee_class_attribute, ca_name),
1414+
self->cd_iattr_list[i].ca_name))
1415+
goto err;
1416+
if (DeeSerial_XPutObject(writer,
1417+
out_addr__cd_iattr_list__i +
1418+
offsetof(struct Dee_class_attribute, ca_doc),
1419+
self->cd_iattr_list[i].ca_doc))
1420+
goto err;
1421+
}
1422+
1423+
/* Write class attribute table. */
1424+
if (self->cd_cattr_list == empty_class_attributes) {
1425+
if (DeeSerial_PutStaticDeemon(writer, ADDROF(cd_cattr_list), empty_class_attributes))
1426+
goto err;
1427+
} else {
1428+
size_t sizeof__cd_cattr_list;
1429+
struct Dee_class_attribute *in__cd_cattr_list;
1430+
struct Dee_class_attribute *out__cd_cattr_list;
1431+
Dee_seraddr_t addrof_out__cd_cattr_list;
1432+
in__cd_cattr_list = self->cd_cattr_list;
1433+
sizeof__cd_cattr_list = (self->cd_cattr_mask + 1) * sizeof(struct Dee_class_attribute);
1434+
addrof_out__cd_cattr_list = DeeSerial_Malloc(writer, sizeof__cd_cattr_list);
1435+
if (!Dee_SERADDR_ISOK(addrof_out__cd_cattr_list))
1436+
goto err;
1437+
if (DeeSerial_PutAddr(writer, ADDROF(cd_cattr_list), addrof_out__cd_cattr_list))
1438+
goto err;
1439+
out__cd_cattr_list = DeeSerial_Addr2Mem(writer, addrof_out__cd_cattr_list,
1440+
struct Dee_class_attribute);
1441+
memcpy(out__cd_cattr_list, in__cd_cattr_list, sizeof__cd_cattr_list);
1442+
for (i = 0; i <= self->cd_cattr_mask; ++i) {
1443+
Dee_seraddr_t addrof_out__cd_cattr_list__i;
1444+
if (!in__cd_cattr_list[i].ca_name)
1445+
continue;
1446+
addrof_out__cd_cattr_list__i = addrof_out__cd_cattr_list;
1447+
addrof_out__cd_cattr_list__i += i * sizeof(struct Dee_class_attribute);
1448+
if (DeeSerial_PutObject(writer,
1449+
addrof_out__cd_cattr_list__i +
1450+
offsetof(struct Dee_class_attribute, ca_name),
1451+
in__cd_cattr_list[i].ca_name))
1452+
goto err;
1453+
if (DeeSerial_XPutObject(writer,
1454+
addrof_out__cd_cattr_list__i +
1455+
offsetof(struct Dee_class_attribute, ca_doc),
1456+
in__cd_cattr_list[i].ca_doc))
1457+
goto err;
1458+
}
1459+
}
1460+
1461+
/* Write class operator table. */
1462+
if (self->cd_clsop_list == empty_class_operators) {
1463+
if (DeeSerial_PutStaticDeemon(writer, ADDROF(cd_clsop_list), empty_class_operators))
1464+
goto err;
1465+
} else {
1466+
size_t sizeof__cd_clsop_list;
1467+
Dee_seraddr_t addrof_out__cd_clsop_list;
1468+
struct Dee_class_operator *in__cd_clsop_list;
1469+
struct Dee_class_operator *out__cd_clsop_list;
1470+
in__cd_clsop_list = self->cd_clsop_list;
1471+
sizeof__cd_clsop_list = (self->cd_clsop_mask + 1) * sizeof(struct Dee_class_operator);
1472+
addrof_out__cd_clsop_list = DeeSerial_Malloc(writer, sizeof__cd_clsop_list);
1473+
if (!Dee_SERADDR_ISOK(addrof_out__cd_clsop_list))
1474+
goto err;
1475+
if (DeeSerial_PutAddr(writer, ADDROF(cd_clsop_list), addrof_out__cd_clsop_list))
1476+
goto err;
1477+
out__cd_clsop_list = DeeSerial_Addr2Mem(writer, addrof_out__cd_clsop_list,
1478+
struct Dee_class_operator);
1479+
memcpy(out__cd_clsop_list, in__cd_clsop_list, sizeof__cd_clsop_list);
1480+
}
1481+
#undef ADDROF
1482+
return out_addr;
1483+
err:
1484+
return Dee_SERADDR_INVALID;
1485+
}
1486+
13741487

13751488
PRIVATE WUNUSED NONNULL((1, 2)) bool DCALL
13761489
class_attribute_eq(struct class_attribute *__restrict lhs,
@@ -2403,7 +2516,7 @@ PUBLIC DeeTypeObject DeeClassDescriptor_Type = {
24032516
/* tp_deep_ctor: */ &DeeObject_NewRef,
24042517
/* tp_any_ctor: */ NULL,
24052518
/* tp_any_ctor_kw: */ &cd_init_kw,
2406-
/* tp_serialize: */ NULL, /* TODO */
2519+
/* tp_serialize: */ &cd_serialize,
24072520
/* tp_free: */ NULL
24082521
),
24092522
/* .tp_dtor = */ (void (DCALL *)(DeeObject *__restrict))&cd_fini,

0 commit comments

Comments
 (0)