GithubHelp home page GithubHelp logo

Comments (4)

kornilova203 avatar kornilova203 commented on June 14, 2024

Field that causes recursion is changed to pointer to CArray only in the case when struct references itself struct node { struct node *next };

It happens in TypeTranslator, but TypeTranslator cannot handle more difficult cases as the one above because while translating struct a it cannot know that struct a -> struct b -> struct c -> struct a cycle exist (it may only detect cycle in struct c when all types are known).

Cycles should be fixed after all types are generated. Before generating Scala code Structs and Unions should check whether their fields cause cycle, if so a field should be replace with a pointer to Byte.

from scala-native-bindgen.

kornilova203 avatar kornilova203 commented on June 14, 2024

But on the other hand it is okay to break cycle in only one place, so there is no need to detect cycle in all 3 structures.
Original type of replaced type should be remembered to generate proper helper methods.

from scala-native-bindgen.

kornilova203 avatar kornilova203 commented on June 14, 2024

Following issues should be considered:

  • CycleDetection adds dependency only for value types and pointer types.
    Field may be of any type (for example function pointer), so CycleDetection should "unroll" all types. I suppose it will be reasonable to modify Type::usesType method such that it stops if cycle is found. Then the method may be used in Struct and Union to detect cyclic fields. CycleDetection then may be removed.
  • We should "brake" cycle on a pointer type filed because only pointer type field may be replaced with pointer to Byte.
    So in this case:
    struct b;
    
    struct a {
         struct b *sb;
    };
    struct b {
         struct a sa;
    };
    field of struct a should be replace by native.Ptr[Byte].
    Note: pointer type field always exists because otherwise structs will have never-ending recursion.

from scala-native-bindgen.

kornilova203 avatar kornilova203 commented on June 14, 2024

Case with function pointers is pretty complicated because there might not be a pointer where cycle should be broken:

struct a;

struct b {
    int (*func)(struct a);
};

struct a {
    struct b sb;
};

There are two possible solutions:

  • Change type of function pointer to native.CFunctionPtr1[native.CArray[...], native.CInt], so it uses CArray instead of struct type.
  • Change type of field to CArray

Seems like Scala Native supports casting function pointers and it should not break anything:

A pointer to a function of one type may be converted to a pointer to a function of another type and back again; the result shall compare equal to the original pointer.

from scala-native-bindgen.

Related Issues (20)

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.