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
A simple helper could be added to structures definitions to allocate them in the heap.
C code
structlisting {
inta;
intb;
};
Should generate
Scala code
importscala.scalanative._importscala.scalanative.native.Nat._@native.link("example")
@native.extern
objectexample {
typestruct_listing= native.CStruct2[native.CInt, native.CInt]
}
importexample._objectexampleHelpers {
implicitclassstruct_listing_ops(valp: native.Ptr[struct_listing]) extendsAnyVal {
defa: native.CInt=!p._1
defa_=(value: native.CInt):Unit=!p._1 = value
defb: native.CInt=!p._2
defb_=(value: native.CInt):Unit=!p._2 = value
}
// New Helper to be addeddefstruct_listing()(implicitz: native.Zone): native.Ptr[struct_listing] = native.alloc[struct_listing]
}
Motivations
native.Zone {z =>// Current way of doing itvallist= native.alloc[example.struct_listing]
// With the new helper, closer to scala syntaxvallist= struct_listing()
list.a =22;
list.b =23;
println("list: {"+ list.a +", "+ list.b +"}")
}
Implementation help
This should be implemented in TreeVisitor.cpp. In the VisitRecordDecl function. It's possible to look at the existing code that generate the current helpers to access each field in a struct.
The text was updated successfully, but these errors were encountered:
A simple helper could be added to structures definitions to allocate them in the heap.
C code
Should generate
Scala code
Motivations
Implementation help
This should be implemented in TreeVisitor.cpp. In the
VisitRecordDecl
function. It's possible to look at the existing code that generate the current helpers to access each field in a struct.The text was updated successfully, but these errors were encountered: