Name change weird
I edited one of my librarys and found my programs crashing. At first, I couldn't find what was wrong but used GitHub to review my changes. I found an enum[0] that had a name change - that my programs weren't even using. All the change that was from 'enum g_Draw {text, input}' to 'enum g_draw {text, input}' (just changed the D to lowercase). I fixed it by making the D uppercase again - D Programming Language (code-d) marks it as not the right style. https://github.com/joelcnz [0] JecLib - base.d
Re: What is "dual-context" ?
On Friday, 13 September 2019 at 02:49:33 UTC, SrMordred wrote: source\app.d(37,10): Error: function `app.main.match!((some) => print(some), (none) => print("none")).match` requires a dual-context, which is not yet supported by LDC I was playing with my home made "sumtypes". The code below works fine in dmd, but in ldc it triggers that error. x.match!(some => print(some), none => print("none")); What exactly is this "dual-context"? "Dual context" is the compiler feature that allows you to pass delegates as template arguments to member functions. For a long time, limitations in the frontend made this impossible [1]. It was recently fixed in dmd [2], but the fix hasn't made it into ldc yet [3], so code that takes advantage of this feature is currently dmd-only. The easiest way to work around the issue is to make `match` a non-member function, and call it using UFCS. This is what the dub package `sumtype` does [4]. [1] https://issues.dlang.org/show_bug.cgi?id=5710 [2] https://github.com/dlang/dmd/pull/9282 [3] https://github.com/ldc-developers/ldc/issues/3125 [4] https://github.com/pbackus/sumtype/blob/v0.8.13/src/sumtype.d#L1091-L1106
Re: Make executable archive just like Java's .jar archive?
On Thursday, 12 September 2019 at 12:52:48 UTC, BoQsc wrote: Is there a way to archive multiple .d source code files and make that archive executable, or something similar? You can achieve something similar with rdmd and shell; $ tar -zcvf source_files.tar.gz source1.d source2.d ... sourceN.d $ rdmd $(tar -xvf source_files.tar.gz) I imagine it wouldn't take much for rdmd to support ZIP or tarballs directly but I'm sure there are corner cases to consider. Bye, norm
What is "dual-context" ?
source\app.d(37,10): Error: function `app.main.match!((some) => print(some), (none) => print("none")).match` requires a dual-context, which is not yet supported by LDC I was playing with my home made "sumtypes". The code below works fine in dmd, but in ldc it triggers that error. x.match!(some => print(some), none => print("none")); What exactly is this "dual-context"?
Re: Using CSS Data from Within My Code
On 09/12/2019 02:54 AM, Ron Tarrant wrote: > I thought it was odd having 'q' in front of the opening curly brace... I think my index can be useful in such searches. Both q"" and q{} are there: http://ddili.org/ders/d.en/ix.html Ali
Re: Using CSS Data from Within My Code
On Thursday, 12 September 2019 at 13:09:16 UTC, Mike Parker wrote: On Thursday, 12 September 2019 at 11:40:33 UTC, Ron Tarrant wrote: string myCSS = "tab { background-color: #f2f2f2; }"; enum will work just as well here and without the need for the variable: enum myCSS = "tab { background-color: #f2f2f2; }"; The original error was because q strings have to be valid D, not because of the enum. Ah! Thanks for clearing that up, Mike. My D knowledge is still rather sparse, so this fills in another blank for me.
Re: Make executable archive just like Java's .jar archive?
On Thursday, 12 September 2019 at 12:53:27 UTC, BoQsc wrote: On Thursday, 12 September 2019 at 12:52:48 UTC, BoQsc wrote: Is there a way to archive multiple .d source code files and make that archive executable, or something similar? https://en.wikipedia.org/wiki/JAR_(file_format) A JAR file is just a standard zip file. The Java Virtual Machine loads .class files (which are Java bytecode files, not Java source) and executes them at runtime. It doesn't matter if they're in a jar file or not. Java was designed for this from the beginning. If you're really talking about loading .d *source* files, that means they either have to be interpreted like a scripting language, in which case you'll need a D interpreter, or they'll need to be compiled at runtime into bytecode (in which case you'll need a bytecode interpreter), or compiled at runtime into object files, in which case you'll need a mechanism for loading object files into a program (there was an object loader library around back in the D1 days). If you want to do what Java does and compile ahead of time to a bytecode format and distribute the bytecode in an archive to be loaded at runtime, then that requires implementing a bytecode compiler, a loader, and a bytecode interpreter. I know that LLVM can output bytecode, so with LDC that's the first step out of the way. Now all you need is for someone to implement a loader and bytecode interpreter.
Re: Using CSS Data from Within My Code
On Thursday, 12 September 2019 at 11:40:33 UTC, Ron Tarrant wrote: string myCSS = "tab { background-color: #f2f2f2; }"; enum will work just as well here and without the need for the variable: enum myCSS = "tab { background-color: #f2f2f2; }"; The original error was because q strings have to be valid D, not because of the enum.
Make executable archive just like Java's .jar archive?
Is there a way to archive multiple .d source code files and make that archive executable, or something similar?
Re: Make executable archive just like Java's .jar archive?
On Thursday, 12 September 2019 at 12:52:48 UTC, BoQsc wrote: Is there a way to archive multiple .d source code files and make that archive executable, or something similar? https://en.wikipedia.org/wiki/JAR_(file_format)
Re: Using CSS Data from Within My Code
On Thursday, 12 September 2019 at 11:35:04 UTC, Ron Tarrant wrote: On Thursday, 12 September 2019 at 10:09:06 UTC, Andrea Fontana wrote: On Thursday, 12 September 2019 at 09:54:35 UTC, Ron Tarrant wrote: I found this presented as a solution in a 2016 post: On Wednesday, 15 June 2016 at 22:05:37 UTC, captaindet wrote: enum myCSS = q{ GtkNotebook { background-color: #e9e9e9; } GtkNotebook tab { background-color: #d6d6d6; } }; But when I try to use it, I get the following errors: Warning: C preprocessor directive #e9e9e9 is not supported Warning: C preprocessor directive #d6d6d6 is not supported I thought it was odd having 'q' in front of the opening curly brace... is this a typo? Shorthand for "string quote"? Something like that? Or do I need to escape these somehow? They are named "token string" and contained code must be a valid d code. See https://dlang.org/spec/lex.html#token_strings Thanks, Andrea and Max. Turns out there's a simpler way to inject CSS into D code. In case anyone else comes looking, I found that instead of an enum, a string will do. Here's the solution I came up with to make visible tabs in a Notebook: That should have been: class CSS // GTK4 compliant { CssProvider provider; string myCSS = "tab { background-color: #f2f2f2; }"; this(StyleContext styleContext) { provider = new CssProvider(); provider.loadFromData(myCSS); styleContext.addProvider(provider, GTK_STYLE_PROVIDER_PRIORITY_APPLICATION); } // this() } // class CSS The CSS path/file name isn't needed.
Re: Using CSS Data from Within My Code
On Thursday, 12 September 2019 at 10:09:06 UTC, Andrea Fontana wrote: On Thursday, 12 September 2019 at 09:54:35 UTC, Ron Tarrant wrote: I found this presented as a solution in a 2016 post: On Wednesday, 15 June 2016 at 22:05:37 UTC, captaindet wrote: enum myCSS = q{ GtkNotebook { background-color: #e9e9e9; } GtkNotebook tab { background-color: #d6d6d6; } }; But when I try to use it, I get the following errors: Warning: C preprocessor directive #e9e9e9 is not supported Warning: C preprocessor directive #d6d6d6 is not supported I thought it was odd having 'q' in front of the opening curly brace... is this a typo? Shorthand for "string quote"? Something like that? Or do I need to escape these somehow? They are named "token string" and contained code must be a valid d code. See https://dlang.org/spec/lex.html#token_strings Thanks, Andrea and Max. Turns out there's a simpler way to inject CSS into D code. In case anyone else comes looking, I found that instead of an enum, a string will do. Here's the solution I came up with to make visible tabs in a Notebook: class CSS // GTK4 compliant { CssProvider provider; string cssPath = "./css/visible_tabs.css"; string myCSS = "tab { background-color: #f2f2f2; }"; this(StyleContext styleContext) { provider = new CssProvider(); provider.loadFromData(myCSS); styleContext.addProvider(provider, GTK_STYLE_PROVIDER_PRIORITY_APPLICATION); } // this() } // class CSS And in the class that will use it, this line does it: css = new CSS(getStyleContext());
Re: Using CSS Data from Within My Code
On Thursday, 12 September 2019 at 09:54:35 UTC, Ron Tarrant wrote: I found this presented as a solution in a 2016 post: On Wednesday, 15 June 2016 at 22:05:37 UTC, captaindet wrote: enum myCSS = q{ GtkNotebook { background-color: #e9e9e9; } GtkNotebook tab { background-color: #d6d6d6; } }; But when I try to use it, I get the following errors: Warning: C preprocessor directive #e9e9e9 is not supported Warning: C preprocessor directive #d6d6d6 is not supported I thought it was odd having 'q' in front of the opening curly brace... is this a typo? Shorthand for "string quote"? Something like that? Or do I need to escape these somehow? They are named "token string" and contained code must be a valid d code. See https://dlang.org/spec/lex.html#token_strings
Re: Using CSS Data from Within My Code
On Thursday, 12 September 2019 at 09:54:35 UTC, Ron Tarrant wrote: I found this presented as a solution in a 2016 post: On Wednesday, 15 June 2016 at 22:05:37 UTC, captaindet wrote: enum myCSS = q{ GtkNotebook { background-color: #e9e9e9; } GtkNotebook tab { background-color: #d6d6d6; } }; But when I try to use it, I get the following errors: Warning: C preprocessor directive #e9e9e9 is not supported Warning: C preprocessor directive #d6d6d6 is not supported I thought it was odd having 'q' in front of the opening curly brace... is this a typo? Shorthand for "string quote"? Something like that? Or do I need to escape these somehow? q{} is a string that must only contain valid D tokens. D lexer does not like C directives. https://dlang.org/spec/lex.html#token_strings
Using CSS Data from Within My Code
I found this presented as a solution in a 2016 post: On Wednesday, 15 June 2016 at 22:05:37 UTC, captaindet wrote: enum myCSS = q{ GtkNotebook { background-color: #e9e9e9; } GtkNotebook tab { background-color: #d6d6d6; } }; But when I try to use it, I get the following errors: Warning: C preprocessor directive #e9e9e9 is not supported Warning: C preprocessor directive #d6d6d6 is not supported I thought it was odd having 'q' in front of the opening curly brace... is this a typo? Shorthand for "string quote"? Something like that? Or do I need to escape these somehow?
Re: How to force an array literal into a read-only data segment?
On Thursday, 12 September 2019 at 08:54:09 UTC, a11e99z wrote: On Thursday, 12 September 2019 at 07:04:19 UTC, Max Samukha wrote: How to achieve the same for an array literal? The closest I could come: enum immutable(int[3]) _tmp = [1, 2, 3]; __gshared a = _tmp.ptr; Is it possible to force the array into rodata? https://p0nce.github.io/d-idioms/#Precomputed-tables-at-compile-time-through-CTFE static immutable(int[3]) _tmp = [1, 2, 3]; ? That looks the same as my example, where 'static' is redundant at the module level, and enum just removes the unneeded reference to the temporary from the object file. However, __gshared in my example does seem to be redundant - 'immutable' implies thread-shared in this case.
Re: problems with swig generated code
On Tuesday, 3 September 2019 at 20:03:37 UTC, Martin DeMello wrote: On Sunday, 1 September 2019 at 11:19:11 UTC, DanielG wrote: Do you know whether SWIG's D generator is even being maintained? I've searched for it on the forums in the past and got the impression that it's outdated. I didn't realise that :( It was included in the current release of swig, so I figured it was maintained. It's pretty sad if it's not, because trying to access C++ libraries directly from D has some limitations (most notably not being able to create new C++ objects from D) and swig would have let things just work. Not true, with the core.stdcpp.new_ module it is possible to allocate the memory to create an object directly from D! Just allocate the memory (YourCPPClass.sizeof) and call std.conv.emplace to use the constructor If you want there is also a wrapper that simplifies the operation https://github.com/ErnyTech/CPPNew A small example: // test.cpp #include class Test { public: Test(int); ~Test(); void set(int); void print(); private: int a; }; Test::Test(int number) { this->set(number); } Test::~Test() { std::cout << "Destructor called" << std::endl; } void Test::set(int number) { this->a = number; } void Test::print() { std::cout << this->a << std::endl; } // test.d extern(C++) { class Test { final this(int); final ~this(); final void set(int); final void print(); } } void main() { import cppnew : CPPNew; import cppnew : CPPDelete; auto test = CPPNew!Test(67); test.print(); // will print 67 test.setNumber(12); test.print(); // will print 12 CPPDelete(test); // will print Destructor called }
Re: How to force an array literal into a read-only data segment?
On Thursday, 12 September 2019 at 07:04:19 UTC, Max Samukha wrote: How to achieve the same for an array literal? The closest I could come: enum immutable(int[3]) _tmp = [1, 2, 3]; __gshared a = _tmp.ptr; Is it possible to force the array into rodata? https://p0nce.github.io/d-idioms/#Precomputed-tables-at-compile-time-through-CTFE static immutable(int[3]) _tmp = [1, 2, 3]; ?
Limitation in number of symbols in a single compilation unit
Is there still a limitation in the number of symbols DMD/LDC can handle for a single compilation unit? Is this limitation target specific and related to a specific linker?
How to force an array literal into a read-only data segment?
test.d: __gshared t = "text".ptr; As expected, the "text" literal ends up in a read-only data segment, with a pointer to it stored in a writable data segment (_TMP0 pointing into .rodata.str1.1): .data segment _D4test1tPya: dd offset FLAT:_TMP0@64 db 000h,000h,000h,000h ; .data ends Hex dump of section '.rodata.str1.1': 0x 74657874 00 text. How to achieve the same for an array literal? The closest I could come: enum immutable(int[3]) _tmp = [1, 2, 3]; __gshared a = _tmp.ptr; But the array is still placed into the writable segment: .data segment internal: db 001h,000h,000h,000h,002h,000h,000h,000h ; db 003h,000h,000h,000h,000h,000h,000h,000h ; _D4test1aPyi: dd offset FLAT:internal@64 db 000h,000h,000h,000h ; .data ends Is it possible to force the array into rodata?