Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Eliminate usingnamespace and runtime initialization #19

Merged
merged 4 commits into from
Aug 21, 2024

Conversation

mjbshaw
Copy link
Contributor

@mjbshaw mjbshaw commented Aug 21, 2024

The commit messages explain things. I'm happy to elaborate further.

  • By selecting this checkbox, I agree to license my contributions to this project under the license(s) described in the LICENSE file, and I have the right to do so or have received permission to do so by an employer or client I am producing work for whom has this right.

The Objective-C class `Foo` has a symbol named `_OBJC_CLASS_$_Foo`.
Storing a reference to it in a symbol named
`_OBJC_CLASSLIST_REFERENCES_$_XXX` and then loading it through that
symbol allows the linker to refer to the class directly instead of
having to go through the Objective-C runtime.

Ideally we could use volatile loads to load this symbol, but my testing
shows Zig generates weird (incompatible, and possibly semantically
incorrect) asm when loading a volatile pointer to an extern. So this
uses inline assembly to force the load.

This also adds a helper function named `as()`. It's a way to safely cast
an Objective-C object pointer to a base class or a protocol it
implements. If you try to cast to an unsupported protocol or incorrect
base class it will result in a compile-time error.
We can use the `as()` helper method to use base functions. Some very
common base functions (`release`, `retain`, and `autorelease`) are
imported into every class/protocol. We can expand this  list as needed
to include convenient inherited methods. We could include all inherited
methods if that ends up being preferable.
We don't really need @cImport. And dual namespacing (e.g., foundation.ns
or quartz_core.ca) just increases verbosity.
@emidoots emidoots merged commit 773066d into hexops:main Aug 21, 2024
1 of 2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants