Replies: 1 comment 6 replies
-
There's no way to attach methods to code-generated types. If we could, the easy way would be to create a generic function that takes a Type parameter and returns a Type with the methods attached. Changing foo.incref() to foo.obj.incref() would require modifying some existing code. Maybe the simplest immediate solution would be to add an incref method directly to each type in pydust/src/types. composition was bad: pub fn PyObjectMixin(comptime root: type) type {
return struct {
_data: root,
pub fn incref() {}
};
} then PyBool would be: const PyBool = PyObjectMixin(_PyBool); using comptime funtion looks like same to pub fn incref(root: anytype) void {
root.obj.incref();
} |
Beta Was this translation helpful? Give feedback.
6 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
On the heels of @bridgeQiao's excellent work on #441, we should discuss what to do about ziglang/zig#20663. @mlugg suggests an alternative for mixins that involves the slightly esoteric
@fieldParentPtr
. Unfortunately, it also requires replacingfoo.incrementCounter()
byfoo.counter.increment()
per this comment.There are 13 occurrences of
usingnamespace PyObjectMixin
in Ziggy Pydust as well as countless calls to the corresponding methods (search for.incref()
or.decref()
to see a few). This is less intrusive than global mutable comptime state but tedious nonetheless. Who has clever ideas to minimize the effort?Beta Was this translation helpful? Give feedback.
All reactions