Git Product home page Git Product logo

scala-native-bindgen's People

Contributors

jonas avatar kornilova203 avatar mrrosset avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

scala-native-bindgen's Issues

Struct Alloc Helper

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]
  
}

Motivations

  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 + "}")

  }

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.