www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Can we do system calls like that in D?

reply rempas <rempas tutanota.com> writes:
There is an amazing feature in a language that is is in alpha 
called [vox](https://github.com/MrSmith33/vox). Vox is actually 
inspired from the D language. This feature is described 
[here](https://github.com/MrSmith33/vox/blob/master/spec/index.md#
uilt-in-attributes) and It's an attribute. I'm talking specifically about the
` extern(syscall, <num>)` attribute that let's you make an system call and bind
it under a name without having any library linked or without having to write
any assembly. Is this possible in D?
Nov 09 2021
parent reply Adam D Ruppe <destructionator gmail.com> writes:
On Tuesday, 9 November 2021 at 11:52:10 UTC, rempas wrote:
 It's an attribute. I'm talking specifically about the 
 ` extern(syscall, <num>)` attribute that let's you make an 
 system call and bind it under a name without having any library 
 linked or without having to write any assembly. Is this 
 possible in D?
I'd be very easy to do that as a library mixin. You'd write syscall(45) void whatever(); mixin BindSyscalls; and then the library generates the bodies as inline asm.
Nov 09 2021
parent rempas <rempas tutanota.com> writes:
On Tuesday, 9 November 2021 at 12:28:59 UTC, Adam D Ruppe wrote:
 I'd be very easy to do that as a library mixin. You'd write

  syscall(45) void whatever();

 mixin BindSyscalls;

 and then the library generates the bodies as inline asm.
Hello Adam! Well this is not exactly the behavior I was looking for, you see in this solution, there are two problems: 1. The mixins will get generated by the compiler (if I'm not mistaken) so it will worsen the compilation times VS if it was a simple function like in Vox. 2. I don't care about the syntax, neither than the fact that you can give the function an name you want (aliases can be used for that) but for the fact that with these way in Vox, you don't have to manually write inline assembly. It seems that I'm out of luck so inline assembly, here I go (unfortunately)! Thanks for your time and have a great day!
Nov 09 2021