Skip to content

Commit 9005dba

Browse files
committed
Improve type-safety of DeeModuleObject
1 parent 98a1e7e commit 9005dba

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+858
-857
lines changed

include/deemon/abi/time.h

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ DECL_BEGIN
5757
static PDEETIME_NEWUNIX _c_DeeTime_NewUnix = NULL; \
5858
if (*(void **)&_c_DeeTime_NewUnix != (void *)-1) { \
5959
if (_c_DeeTime_NewUnix == NULL) { \
60-
DeeObject *time_module = get_time_module(); \
60+
DeeModuleObject *time_module = get_time_module(); \
6161
if unlikely(time_module == NULL) \
6262
return NULL; \
6363
*(void **)&_c_DeeTime_NewUnix = DeeModule_GetNativeSymbol( \
@@ -70,12 +70,13 @@ DECL_BEGIN
7070
return (*_c_DeeTime_NewUnix)(seconds_since_01_01_1970, \
7171
extra_nanoseconds); \
7272
} else { \
73-
DeeObject *time_module; \
73+
DeeModuleObject *time_module; \
7474
fallback: \
7575
time_module = get_time_module(); \
7676
if unlikely(time_module == NULL) \
7777
return NULL; \
78-
return DeeObject_CallAttrStringf(time_module, "_mkunix", \
78+
return DeeObject_CallAttrStringf(Dee_AsObject(time_module), \
79+
"_mkunix", \
7980
DEE_PCKd64 DEE_PCKu32, \
8081
seconds_since_01_01_1970, \
8182
extra_nanoseconds); \
@@ -94,7 +95,7 @@ DECL_BEGIN
9495
static PDEETIME_NEWFILETIME _c_DeeTime_NewFILETIME = NULL; \
9596
if (*(void **)&_c_DeeTime_NewFILETIME != (void *)-1) { \
9697
if (_c_DeeTime_NewFILETIME == NULL) { \
97-
DeeObject *time_module = get_time_module(); \
98+
DeeModuleObject *time_module = get_time_module(); \
9899
if unlikely(time_module == NULL) \
99100
return NULL; \
100101
*(void **)&_c_DeeTime_NewFILETIME = DeeModule_GetNativeSymbol( \
@@ -106,12 +107,13 @@ DECL_BEGIN
106107
} \
107108
return (*_c_DeeTime_NewFILETIME)(p_filetime); \
108109
} else { \
109-
DeeObject *time_module; \
110+
DeeModuleObject *time_module; \
110111
fallback: \
111112
time_module = get_time_module(); \
112113
if unlikely(time_module == NULL) \
113114
return NULL; \
114-
return DeeObject_CallAttrStringf(time_module, "_mkFILETIME", DEE_PCKu64, \
115+
return DeeObject_CallAttrStringf(Dee_AsObject(time_module), \
116+
"_mkFILETIME", DEE_PCKu64, \
115117
__hybrid_unaligned_get64(p_filetime)); \
116118
} \
117119
}

include/deemon/code.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1208,7 +1208,7 @@ DDATDEF DeeTypeObject DeeYieldFunctionIterator_Type; /* foo().operator iter(); *
12081208

12091209
/* Create a new function object. */
12101210
DFUNDEF WUNUSED NONNULL((1)) DREF DeeObject *DCALL
1211-
DeeFunction_New(DeeObject *code, size_t refc,
1211+
DeeFunction_New(DeeCodeObject *code, size_t refc,
12121212
DeeObject *const *refv);
12131213

12141214

@@ -1284,10 +1284,10 @@ INTDEF NONNULL((1, 2, 3, 4)) DREF DeeObject *DCALL DeeFunction_OptimizeAndThisCa
12841284
#define DeeFunction_ThisCallTupleKw(self, this_arg, args, kw) DeeObject_ThisCallTupleKw(Dee_AsObject(self), this_arg, args, kw)
12851285
#else /* !CONFIG_BUILDING_DEEMON */
12861286
INTDEF WUNUSED NONNULL((1, 3)) DREF DeeObject *DCALL
1287-
DeeFunction_NewInherited(DeeObject *code, size_t refc,
1287+
DeeFunction_NewInherited(DeeCodeObject *code, size_t refc,
12881288
/*inherit(on_success)*/ DREF DeeObject *const *__restrict refv);
12891289
INTDEF WUNUSED NONNULL((1)) DREF DeeObject *DCALL
1290-
DeeFunction_NewNoRefs(DeeObject *__restrict code);
1290+
DeeFunction_NewNoRefs(DeeCodeObject *__restrict code);
12911291

12921292
INTDEF WUNUSED NONNULL((1)) DREF DeeObject *DCALL
12931293
DeeFunction_Call(DeeFunctionObject *self, size_t argc, DeeObject *const *argv);

include/deemon/compiler/lexer.def

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -605,7 +605,7 @@ DEF_WARNING(W_ASM_CANNOT_UNBIND_SYMBOL, (WG_SYMBOL), WSTATE_ERROR, { struct symb
605605
DEF_WARNING(W_ASM_CANNOT_UNBIND_UNDESIGNATED_STACK_VARIABLE, (WG_SYMBOL), WSTATE_ERROR, { struct symbol const *sym = ARG(struct symbol const *); WARNF("Cannot unbind undesignated stack variable `%s' at this time", SYMBOL_NAME(sym)); PRINT_SYMBOL_DECLARATION(sym); })
606606
DEF_WARNING(W_ASM_DELETED_STACK_VARIABLE_ISNT_UNBOUND, (WG_SYMBOL), WSTATE_WARN, { struct symbol const *sym = ARG(struct symbol const *); WARNF("Deleting stack variable `%s' will not cause the symbol to become unbound", SYMBOL_NAME(sym)); PRINT_SYMBOL_DECLARATION(sym); })
607607
DEF_WARNING(W_ASM_CANNOT_WRITE_SYMBOL, (WG_SYMBOL), WSTATE_ERROR, { struct symbol const *sym = ARG(struct symbol const *); WARNF("Cannot write to symbol `%s' of class `%s'", SYMBOL_NAME(sym), SYMBOL_TYPE_NAME(sym->s_type)); PRINT_SYMBOL_DECLARATION(sym); })
608-
DEF_WARNING(W_ASM_EXTERNAL_SYMBOL_IS_READONLY, (WG_SYMBOL), WSTATE_ERROR, { struct symbol const *sym = ARG(struct symbol const *); WARNF("Cannot modify read-only external symbol `%s from %s'", SYMBOL_EXTERN_SYMBOL(sym)->ss_name, DeeModule_GetShortName((DeeObject *)sym->s_extern.e_module)); PRINT_SYMBOL_DECLARATION(sym); })
608+
DEF_WARNING(W_ASM_EXTERNAL_SYMBOL_IS_READONLY, (WG_SYMBOL), WSTATE_ERROR, { struct symbol const *sym = ARG(struct symbol const *); WARNF("Cannot modify read-only external symbol `%s from %s'", SYMBOL_EXTERN_SYMBOL(sym)->ss_name, DeeModule_GetShortName(sym->s_extern.e_module)); PRINT_SYMBOL_DECLARATION(sym); })
609609
DEF_WARNING(W_ASM_MULTIPLE_WRITES_TO_FINAL, (WG_READONLY), WSTATE_DISABLED, { struct symbol const *sym = ARG(struct symbol const *); WARNF("Multiple writes to final variable `%s' generate additional checks", SYMBOL_NAME(sym)); PRINT_SYMBOL_DECLARATION(sym); })
610610
DEF_WARNING(W_ASM_UNBIND_FINAL_SYMBOL, (WG_READONLY), WSTATE_WARN, { struct symbol const *sym = ARG(struct symbol const *); WARNF("Cannot delete final variable `%s'", SYMBOL_NAME(sym)); PRINT_SYMBOL_DECLARATION(sym); })
611611
DEF_WARNING(W_ASM_UNSUPPORTED_FINAL_SYMBOL_TYPE, (WG_READONLY), WSTATE_ERROR, { struct symbol const *sym = ARG(struct symbol const *); WARNF("Multiple writes to final symbol `%s' of type `%s' cannot be handled", SYMBOL_NAME(sym), SYMBOL_TYPE_NAME(sym->s_type)); PRINT_SYMBOL_DECLARATION(sym); })

include/deemon/exec.h

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ DECL_BEGIN
3434
#ifdef DEE_SOURCE
3535
#define Dee_compiler_options compiler_options
3636
#define Dee_list_object list_object
37+
#define Dee_module_object module_object
3738
#endif /* DEE_SOURCE */
3839

3940

@@ -247,6 +248,7 @@ DeeExec_RunStreamString(DeeObject *source_stream, unsigned int mode,
247248
* generated, before that module's root is returned, or if the given user-code
248249
* is only executed when the function is called, potentially allowing for
249250
* JIT-like execution of simple expressions such as `10 + 20' */
251+
struct Dee_module_object;
250252
#ifdef CONFIG_EXPERIMENTAL_MODULE_DIRECTORIES
251253
#ifdef CONFIG_BUILDING_DEEMON
252254
#ifdef CONFIG_EXPERIMENTAL_MMAP_DEC
@@ -256,13 +258,13 @@ DeeExec_CompileModuleStream_impl(struct Dee_serial *__restrict writer, DeeObject
256258
int start_line, int start_col, unsigned int mode,
257259
struct Dee_compiler_options *options, DeeObject *default_symbols);
258260
#else /* CONFIG_EXPERIMENTAL_MMAP_DEC */
259-
INTDEF WUNUSED NONNULL((1)) DREF /*untracked*/ /*Module*/ DeeObject *DCALL
261+
INTDEF WUNUSED NONNULL((1)) DREF /*untracked*/ struct Dee_module_object *DCALL
260262
DeeExec_CompileModuleStream_impl(DeeObject *source_stream,
261263
int start_line, int start_col, unsigned int mode,
262264
struct Dee_compiler_options *options, DeeObject *default_symbols);
263265
#endif /* !CONFIG_EXPERIMENTAL_MMAP_DEC */
264266
#endif /* CONFIG_BUILDING_DEEMON */
265-
DFUNDEF WUNUSED NONNULL((1)) DREF /*Module*/ DeeObject *DCALL
267+
DFUNDEF WUNUSED NONNULL((1)) DREF struct Dee_module_object *DCALL
266268
DeeExec_CompileModuleStream(DeeObject *source_stream,
267269
int start_line, int start_col, unsigned int mode,
268270
struct Dee_compiler_options *options, DeeObject *default_symbols);
@@ -271,7 +273,7 @@ DeeExec_CompileFunctionStream(DeeObject *source_stream,
271273
int start_line, int start_col, unsigned int mode,
272274
struct Dee_compiler_options *options, DeeObject *default_symbols);
273275
#else /* CONFIG_EXPERIMENTAL_MODULE_DIRECTORIES */
274-
DFUNDEF WUNUSED NONNULL((1)) DREF /*Module*/ DeeObject *DCALL
276+
DFUNDEF WUNUSED NONNULL((1)) DREF struct Dee_module_object *DCALL
275277
DeeExec_CompileModuleStream(DeeObject *source_stream,
276278
unsigned int mode, int start_line, int start_col,
277279
struct Dee_compiler_options *options, DeeObject *default_symbols,
@@ -281,7 +283,7 @@ DeeExec_CompileFunctionStream(DeeObject *source_stream,
281283
unsigned int mode, int start_line, int start_col,
282284
struct Dee_compiler_options *options, DeeObject *default_symbols,
283285
DeeObject *source_pathname, DeeObject *module_name);
284-
DFUNDEF WUNUSED NONNULL((1)) DREF /*Module*/ DeeObject *DCALL
286+
DFUNDEF WUNUSED NONNULL((1)) DREF struct Dee_module_object *DCALL
285287
DeeExec_CompileModuleStreamString(DeeObject *source_stream,
286288
unsigned int mode, int start_line, int start_col,
287289
struct Dee_compiler_options *options, DeeObject *default_symbols,
@@ -303,7 +305,7 @@ DeeExec_RunMemory(/*utf-8*/ char const *__restrict data, size_t data_size,
303305
size_t argc, DeeObject *const *argv,
304306
int start_line, int start_col, unsigned int mode,
305307
struct Dee_compiler_options *options, DeeObject *default_symbols);
306-
DFUNDEF WUNUSED NONNULL((1)) DREF /*Module*/ DeeObject *DCALL
308+
DFUNDEF WUNUSED NONNULL((1)) DREF struct Dee_module_object *DCALL
307309
DeeExec_CompileModuleMemory(/*utf-8*/ char const *__restrict data, size_t data_size,
308310
int start_line, int start_col, unsigned int mode,
309311
struct Dee_compiler_options *options, DeeObject *default_symbols);
@@ -325,7 +327,7 @@ DeeExec_RunMemoryString(/*utf-8*/ char const *__restrict data, size_t data_size,
325327
struct Dee_compiler_options *options, DeeObject *default_symbols,
326328
/*utf-8*/ char const *source_pathname, size_t source_pathsize,
327329
/*utf-8*/ char const *module_name, size_t module_namesize);
328-
DFUNDEF WUNUSED NONNULL((1)) DREF /*Module*/ DeeObject *DCALL
330+
DFUNDEF WUNUSED NONNULL((1)) DREF struct Dee_module_object *DCALL
329331
DeeExec_CompileModuleMemory(/*utf-8*/ char const *__restrict data, size_t data_size,
330332
unsigned int mode, int start_line, int start_col,
331333
struct Dee_compiler_options *options, DeeObject *default_symbols,
@@ -335,7 +337,7 @@ DeeExec_CompileFunctionMemory(/*utf-8*/ char const *__restrict data, size_t data
335337
unsigned int mode, int start_line, int start_col,
336338
struct Dee_compiler_options *options, DeeObject *default_symbols,
337339
DeeObject *source_pathname, DeeObject *module_name);
338-
DFUNDEF WUNUSED NONNULL((1)) DREF /*Module*/ DeeObject *DCALL
340+
DFUNDEF WUNUSED NONNULL((1)) DREF struct Dee_module_object *DCALL
339341
DeeExec_CompileModuleMemoryString(/*utf-8*/ char const *__restrict data, size_t data_size,
340342
unsigned int mode, int start_line, int start_col,
341343
struct Dee_compiler_options *options, DeeObject *default_symbols,

include/deemon/filetypes.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -280,9 +280,7 @@ DDATDEF DeeFileTypeObject DeeMemoryFile_Type;
280280
* of action, dependent on whether the file is being shared with some other
281281
* part of deemon. If it is, it will replace the view's data with a heap-allocated
282282
* copy of that data, and if that isn't possible, modify the view to represent
283-
* an empty data set.
284-
* The main use of this functionality is to allow the use of `DeeModule_LoadSourceStream()'
285-
* with a stream backed by source code located in memory. */
283+
* an empty data set. */
286284
DFUNDEF WUNUSED NONNULL((1)) DREF /*File*/ DeeObject *DCALL
287285
DeeFile_OpenRoMemory(void const *data, size_t data_size);
288286
DFUNDEF NONNULL((1)) void DCALL

include/deemon/gc.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,8 @@ DFUNDEF ATTR_RETNONNULL NONNULL((1)) DeeObject *DCALL DeeGC_Untrack(DeeObject *_
112112
DFUNDEF NONNULL((1, 2)) void DCALL
113113
DeeGC_TrackAll(DeeObject *first, DeeObject *last);
114114

115-
#define DeeGC_TRACK(T, ob) ((DREF T *)DeeGC_Track(Dee_AsObject(ob)))
115+
#define DeeGC_TRACK(T, ob) ((DREF T *)DeeGC_Track(Dee_AsObject(ob)))
116+
#define DeeGC_UNTRACK(T, ob) ((DREF T *)DeeGC_Untrack(Dee_AsObject(ob)))
116117

117118
/* Try to collect at most `max_objects' GC-objects,
118119
* returning the actual amount collected. */

0 commit comments

Comments
 (0)