mrrosset / scala-native-bindgen Goto Github PK
View Code? Open in Web Editor NEWScala native binding generator
Home Page: http://scala-native.org
License: BSD 3-Clause "New" or "Revised" License
Scala native binding generator
Home Page: http://scala-native.org
License: BSD 3-Clause "New" or "Revised" License
A simple helper could be added to structures definitions to allocate them in the heap.
C code
struct listing {
int a;
int b;
};
Should generate
Scala code
import scala.scalanative._
import scala.scalanative.native.Nat._
@native.link("example")
@native.extern
object example {
type struct_listing = native.CStruct2[native.CInt, native.CInt]
}
import example._
object exampleHelpers {
implicit class struct_listing_ops(val p: native.Ptr[struct_listing]) extends AnyVal {
def a: native.CInt = !p._1
def a_=(value: native.CInt):Unit = !p._1 = value
def b: native.CInt = !p._2
def b_=(value: native.CInt):Unit = !p._2 = value
}
// New Helper to be added
def struct_listing()(implicit z: native.Zone): native.Ptr[struct_listing] = native.alloc[struct_listing]
}
native.Zone {z =>
// Current way of doing it
val list = native.alloc[example.struct_listing]
// With the new helper, closer to scala syntax
val list = struct_listing()
list.a = 22;
list.b = 23;
println("list: {" + list.a + ", " + list.b + "}")
}
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.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.