GithubHelp home page GithubHelp logo

Comments (14)

kripken avatar kripken commented on July 4, 2024

Implemented in 414f1dc.

Runtime.typeInfo.X contains the type info for type X. Enabled with RUNTIME_TYPE_INFO, currently defaulted to off.

from emscripten.

max99x avatar max99x commented on July 4, 2024

Any way to have it as easily accessible at compile-time without overhead?

from emscripten.

kripken avatar kripken commented on July 4, 2024

We can write {{{ exp }}} in library.js, so you can in theory use Types.types there. However, this is evaluated before the type info is present I think, so it won't work. But, what is the use case for this?

from emscripten.

max99x avatar max99x commented on July 4, 2024

If I need to allocate a struct and set its members in a library function, I have to know its layout. Since I know the exact type I need, there's no reason to require specific compilation settings and include extra runtime overhead in terms of code size. An ugly version of this can be seen in the time.h implementation (struct tm is described manually).

from emscripten.

kripken avatar kripken commented on July 4, 2024

Good point, I am working on a patch now.

from emscripten.

max99x avatar max99x commented on July 4, 2024

Awesome!

from emscripten.

kripken avatar kripken commented on July 4, 2024

Enabled type info in library in ab56efe. Rewrote struct_tm to use that (so it functions as a test for this).

from emscripten.

max99x avatar max99x commented on July 4, 2024

Nevermind. There was a GCC-specific field I didn't add to the list. Might be a good idea to verify that the number of fields passed to Runtime.generateStructInfo matches the number of fields in the type.

Previous message for reference:

Thanks for the patch! However, I've found a miscalculation (most likely not a result of this patch). Calling Runtime.generateStructInfo on struct dirent, defined in <bits/dirent.h> produces:

{"__size__":268,
 "d_ino":0,
 "d_off":4,
 "d_reclen":8,
 "d_name":10}

However, d_name should have an offset of 11. This is true for both native size and the generated JS code.

from emscripten.

kripken avatar kripken commented on July 4, 2024

What does the .ll look like?

from emscripten.

max99x avatar max99x commented on July 4, 2024

As I've mentioned in my edit, it was a mistake on my side.

from emscripten.

kripken avatar kripken commented on July 4, 2024

Ah, I missed the edit.

Adding that check sounds like a good idea, I'll do that.

from emscripten.

kripken avatar kripken commented on July 4, 2024

Pushed followup following IRC discussion, 9bcf21d

Allows generateStructInfo to process nested structs, for example

Runtime.generateStructInfo(['x', { us: ['x', 'y', 'z'] }, 'y'], 'StructType')

where the 2nd field is a struct as well.

from emscripten.

lucidvizion avatar lucidvizion commented on July 4, 2024

If I need to allocate a struct and set its members in a library function, I have to know its layout.

What is the solution to this problem with FastComp? I see that Runtime.typeInfo is not available anymore.

from emscripten.

kripken avatar kripken commented on July 4, 2024

You can create a method in C that returns the size and/or positions of elements, and compile that, then call it. This is essentially what the webidl binder and embind do, so might be useful to look at their code or output.

from emscripten.

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.