You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The importc pragma works ok for single objc classes, but can't be used to model hierarchies of external classes. The following code illustrates in valid Nimrod code what I want to do:
block:
{.passL: "-lobjc".}
{.passL: "-framework AppKit".}
typeTNSObject*=objectofTObjectPNSObject*=refTNSObjectTNSString*=objectofTNSObjectPNSString*=refTNSStringproccheck_isa*(x: PNSObject) =echo"The isa value is ", repr(x)
whenisMainModule:
var a: PNSStringcheck_isa(a)
Essentially, this models the objc NSObject with NSString being a subclass. Now, trying to do the same with importc:
Nimrod compiles fine but fails during backend compilation:
/private/tmp/cycle/nimcache/cycle_h.m:109:27: error: 'NSString' does not have a
member named 'Sup'
checkisa_80015(&a_80026->Sup);
~~~~~~~ ^
/private/tmp/cycle/nimcache/cycle_h.m:115:17: error: application of 'sizeof' to
interface 'NSObject' is not supported on this architecture and platform
NTI80007.size = sizeof(NSObject);
^ ~~~~~~~~~~
2 errors generated.
Error: execution of an external program failed
As far as I can see in the generated code, the compiler is generating code for the imported classes as if they were normal nimrod structs, hence the access of the Sup field or trying to initialize the structure with sizeof.
How could this be avoided? It seems that the only way to make something like this work is teach the codegen part about objc classes. If on the Nimrod side they can't be expressed as object of XXX then the only other solution I can see is adding converters for all types to their base types or manual casting between them.
Maybe this has been already solved for C++ interfacing?
The text was updated successfully, but these errors were encountered:
<!--- The Pull Request (=PR) message is what will get automatically used
as
the commit message when the PR is merged. Make sure that no line is
longer
than 72 characters -->
Removed obsolete comments related to nimsuggest from the `nimsuggest`
and `suggest` modules.
The
importc
pragma works ok for single objc classes, but can't be used to model hierarchies of external classes. The following code illustrates in valid Nimrod code what I want to do:Essentially, this models the objc
NSObject
withNSString
being a subclass. Now, trying to do the same withimportc
:Nimrod compiles fine but fails during backend compilation:
As far as I can see in the generated code, the compiler is generating code for the imported classes as if they were normal nimrod structs, hence the access of the
Sup
field or trying to initialize the structure withsizeof
.How could this be avoided? It seems that the only way to make something like this work is teach the codegen part about objc classes. If on the Nimrod side they can't be expressed as
object of XXX
then the only other solution I can see is adding converters for all types to their base types or manual casting between them.Maybe this has been already solved for C++ interfacing?
The text was updated successfully, but these errors were encountered: