News for hackers. Stuff that matters.
Re:Adding ANSI C11 C compiler to D so it can import and comp... by crazypython on Monday May 10, 2021 @07:43AM (#27104858)
Context: Walter Bright created the first native C++ compiler, Zortech C++. This pull request actually implements its own C compiler! For Walter, considering he's implemented C++98 alone, implementing C must be nothing :)

He implemented the ANSI C compiler here in just 5 days.

Semi-related project, using libclang to import C++ directly (with C++ templates and all the other features, regular D has C++ linking and exception support built-in): https://github.com/Syniurge/Calypso

Some quotes from the forum https://forum.dlang.org/post/[email protected] :

- Writing a C preprocessor is a nightmare. Fortunately, I already did that https://github.com/facebookarchive/warp and we can use it if we choose.

- The D code will be able to inline C code, and even CTFE it.

- There are a lot of wacky C extensions out there. We only need to implement currently used ones (not the 16 bit stuff), and only the stuff that appears in C headers.

- Without a C compiler, we're stuck with, wedded to, and beholden to libclang. I wouldn't be surprised that the eventual cost of adapting ourselves to libclang will exceed the cost of doing our own C compiler.

Re:Adding ANSI C11 C compiler to D so it can import and comp... by mhh__ on Monday May 10, 2021 @08:12AM (#27105095)
>ANSI C compiler here in just 5 days

This is good work but let's be realistic - it doesn't work yet on any real C code I've tried it with.

Re:Adding ANSI C11 C compiler to D so it can import and comp... by crazypython on Monday May 10, 2021 @09:56AM (#27106011)
Hey, fellow Dlanger!

Yeah, it doesn't support C headers yet. But an excellent prototype nonetheless.

Re:Adding ANSI C11 C compiler to D so it can import and comp... by greatgoat420 on Monday May 10, 2021 @11:22AM (#27106979)
> Hey, fellow Dlanger!

Lol, he is a paid hype man for the Dlang community, and you should ask him about Symmetry Investments and if they are hiring.

Re:Adding ANSI C11 C compiler to D so it can import and comp... by mhh__ on Monday May 10, 2021 @11:54AM (#27107441)
> and you should ask him about Symmetry Investments and if they are hiring.

I'm starting in July.

Re:Adding ANSI C11 C compiler to D so it can import and comp... by greatgoat420 on Monday May 10, 2021 @12:10PM (#27107609)
That's great man, congratulations! People did not take my comment as the joke it was intended as.
Re:Adding ANSI C11 C compiler to D so it can import and comp... by fithisux on Tuesday May 11, 2021 @10:44AM (#27118673)
Congratulations
Re:Adding ANSI C11 C compiler to D so it can import and comp... by a9h74j on Monday May 10, 2021 @12:58PM (#27108149)
That was quick.
Re:Adding ANSI C11 C compiler to D so it can import and comp... by mingodad on Monday May 10, 2021 @01:07PM (#27108264)
But dlang has a long problem of change constantly without backward compatibility and a lot of projects just die because of it, for example the mentioned https://github.com/facebookarchive/warp :

====

make

dmd -c -O -inline -release -ofwarp.o cmdline.d constexpr.d context.d directive.d expanded.d file.d id.d lexer.d loc.d macros.d main.d number.d outdeps.d ranges.d skip.d sources.d stringlit.d textbuf.d charclass.d

context.d(222): Error: Implicit string concatenation is error-prone and disallowed in D

context.d(222): Use the explicit syntax instead (concatenating literals is @nogc): "# 1 \"%2$s//\"\x0a" ~ "# 1 \"<command-line>\"\x0a"

context.d(223): Error: Implicit string concatenation is error-prone and disallowed in D

context.d(223): Use the explicit syntax instead (concatenating literals is @nogc): "# 1 \"<command-line>\"\x0a" ~ "# 1 \"%1$s\"\x0a"

macros.d(329): Error: Built-in hex string literals are obsolete, use std.conv.hexString!"FD 61 FD" instead.

macros.d(333): Error: Built-in hex string literals are obsolete, use std.conv.hexString!"FD" instead.

macros.d(338): Error: Built-in hex string literals are obsolete, use std.conv.hexString!"FD 61 62 FD FD" instead.

ranges.d(71): Error: Implicit string concatenation is error-prone and disallowed in D

ranges.d(71): Use the explicit syntax instead (concatenating literals is @nogc): "Buffer overflowed. Possibly caused by forgetting to " ~ "complete a git merge in your code."

Makefile:44: recipe for target 'warp.o' failed

make: ** [warp.o] Error 1

====

Re:Adding ANSI C11 C compiler to D so it can import and comp... by WalterBright on Monday May 10, 2021 @02:50PM (#27109443)
> die because of it

That isn't why Warp was discontinued. (My last change to Warp was 7 years ago.) Even with my C code, it's unsurprising to have to update a few things after 7 years.

My version of the repository is:

https://github.com/DigitalMars/dmpp

and compiles with DMD 2.067. I'll see about updating it later today. Stay tuned!

Re:Adding ANSI C11 C compiler to D so it can import and comp... by WalterBright on Monday May 10, 2021 @06:21PM (#27111604)
Updated!
Re:Adding ANSI C11 C compiler to D so it can import and comp... by crazypython on Monday May 10, 2021 @01:17PM (#27108369)
Those are 8 errors, all from 1 language change, which can be fixed by inserting 8 characters.
Re:Adding ANSI C11 C compiler to D so it can import and comp... by mingodad on Monday May 10, 2021 @01:23PM (#27108448)
After following the compiler suggestions (several times more):

====

make

dmd -c -O -inline -release -ofwarp.o cmdline.d constexpr.d context.d directive.d expanded.d file.d id.d lexer.d loc.d macros.d main.d number.d outdeps.d ranges.d skip.d sources.d stringlit.d textbuf.d charclass.d

util.d(20): Error: function `loc.Loc.write(File* f)` is not callable using argument types `(File function() nothrow @nogc @property ref @system)`

util.d(20): cannot pass argument `& makeGlobal` of type `File function() nothrow @nogc @property ref @system` to parameter `File* f`

directive.d(470): Error: template instance `util.err_warning!(string, string)` error instantiating

context.d(264): instantiated from here: `parseDirective!(Lexer!(Context!(LockingTextWriter)))`

main.d(39): instantiated from here: `Context!(LockingTextWriter)`

Makefile:44: recipe for target 'warp.o' failed

make: * [warp.o] Error 1

====

Re:Adding ANSI C11 C compiler to D so it can import and comp... by crazypython on Monday May 10, 2021 @07:55PM (#27112468)
Less than 30 line changes to get it to compile with latest DMD. https://github.com/DigitalMars/dmpp/commit/a9b879983130cf3a3...

Small price to pay for an elegant language.

Re:Adding ANSI C11 C compiler to D so it can import and comp... by WalterBright on Monday May 10, 2021 @06:28PM (#27111656)
Put () after the stderr and it'll compile.