4 ms·
Pity that Nim was not part of the article.
by nimmer 6y ago
Pity that Nim was not part of the article.
- fwsgonzo 6y agoIt's weird because out of all the languages I have made a special environment for, Zig is the only one I couldn't figure out how to. For example, how to write global asm? How to call the Zig main function? I guess I need a trampoline? I have an emulated env with no filesystems and such things, where you just communicate using system calls - so nothing special, however since you can't just use the standard libraries I have to set the environment up myself. That is fine. It's also cross-compiled. For rust I had to add some custom linker flags, use global_asm for the startup code, and then with no_std I could just call my own main function. The only really annoying part of the whole thing is that there is no feature in Rust to force a function to not be removed. I could override the global allocator to make allocations very fast. For C/C++, it's the same as in Rust, except you can use __attribute__((used)) to make a function not get removed. It's also easy to override memory- and string-functions if you have system calls that do these things faster. Overall the C/C++ environment was the fastest. For Nim, I only had to use C++ as a backend, and then call NimMain(), add a few extra flags, and it would just work. I only wish that Nim was more popular.
- IridescentRose 6y agoGlobal Asm: comptime{ asm("nop"); //Your asm here } Calling Main From an arbitrary point: const root = @import("root"); //.... root.main();
- lzutao 6y ago> there is no feature in Rust to force a function to not be removed Can we use `pub` to make it public and not to be removed ?
- fwsgonzo 6y agono I think I tried just about everything: pub, extern etc. The only thing that worked was adding a linker argumment: "-C", "link_args=--undefined=<name_of_function>" That will force the linker to assume it's referenced.
- lzutao 6y agoIf the function you trying to keep is in non-pub module, it will be removed. Maybe you could move it out of private module: <https://rust.godbolt.org/z/PYPbG8 https://rust.godbolt.org/z/PYPbG8>. There's also an `#[used]`[1] attribute, but only for static items. If your use case is special, consider open a feature request in Rust repo. [1]: https://doc.rust-lang.org/nightly/reference/abi.html#the-used-attribute https://doc.rust-lang.org/nightly/reference/abi.html#the-use...