Comments (14)
Implemented in 414f1dc.
Runtime.typeInfo.X contains the type info for type X. Enabled with RUNTIME_TYPE_INFO, currently defaulted to off.
from emscripten.
Any way to have it as easily accessible at compile-time without overhead?
from emscripten.
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.
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.
Good point, I am working on a patch now.
from emscripten.
Awesome!
from emscripten.
Enabled type info in library in ab56efe. Rewrote struct_tm to use that (so it functions as a test for this).
from emscripten.
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.
What does the .ll look like?
from emscripten.
As I've mentioned in my edit, it was a mistake on my side.
from emscripten.
Ah, I missed the edit.
Adding that check sounds like a good idea, I'll do that.
from emscripten.
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.
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.
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)
- Are we allowed to pass null as options to navigator_gpu_request_adapter_sync()? HOT 3
- Impossible to run multithread functions without blocking the UI thread. HOT 2
- --preload-file works when running locally but not when deployed as a github page HOT 5
- How to re-generate libdlmalloc.a after changed dlmalloc (system/lib/dlmalloc.c)? HOT 2
- PRINTF_LONG_DOUBLE is not compatible with MAIN_MODULE HOT 6
- Compilation error when binding custom types as field in a value_object HOT 2
- Unable to add _emscripten_thread_exit_joinable to EXPORTED_FUNCTIONS HOT 13
- There are no definitions of functions for working with std::complex and boost::multiprecision::number HOT 1
- Unable to reliably determine memory usage at runtime HOT 2
- Refused to execute script from 'http://localhost/undefined' because its MIME type ('text/html') is not executable, and strict MIME type checking is enabled HOT 4
- `charconv` function `to_chars` silently casts `long double` to `double` HOT 2
- `std::log1p(x)` with long double appears to use double precision HOT 7
- Support `rpath` to locate shared libraries? HOT 1
- compile gmp 6.3.0,there are some error HOT 1
- pthread workers 100% CPU usage... HOT 12
- 3.1.61 ignores wasmMemory when creating module HOT 3
- (0, 0) mouse click in emscripten_set_mousedown_callback HOT 4
- IGNORE_MISSING_MAIN compiler has no effect HOT 11
- `emscripten_set_mousedown_callback` does not call the callback function from Qt Creator HOT 38
- WebIDL Binder does not support the full range of values for unsigned integers HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from emscripten.