-
Notifications
You must be signed in to change notification settings - Fork 48
run.dlang.io
This page describes a few features of run.dlang.io If you need help, please open an issue.
Keyboard shortcut | Command |
---|---|
CTRL+Enter | run |
CTRL+R | reset |
CTRL+S | shorten (URL will be directly copied to the clipboard) |
ALT+F | format |
Example | Instructions |
---|---|
ASM | Assembly output |
ASM | Try adding-inline
|
ASM | Try adding -O
|
AST | AST of DMD frontend (after semantic analysis) |
IR | LDC only |
JSON | JSON output from DMD |
DDoc | DDoc output of DMD |
It compares the output of all compiler from 2.060 to latest.
Example:
void main()
{
import std.experimental.allocator; // so when was this added to Phobos?
}
https://run.dlang.io/is/3R4r1U
Tip: if you search for compiler errors, use -c -o-
to speed up the run.
You can learn more about dreg
here.
While most functionality is available via UI buttons, a few very infrequently used options aren't exposed. An additional benefit of adding the flag directly, is that - if a link is shared - it will be displayed immediately when the user hits on run. Thus, an incomplete of common LDC and DMD flags for which the Tour has added additional support.
Flag | Effect |
---|---|
-vcg-ast |
Display the AST tree |
-asm (DMD) / -output-s (LDC) |
Show assembly |
-c |
Just compile |
-Xf- |
Show JSON output |
-unittest |
Run unttests |
-D |
Documentation build (HTML is shown) |
run.dlang.io supports HAR which allows to use multiple files in a readable way:
When a DPP file is detected, dpp
will get called instead:
#include <stdio.h>
void main() {
printf("Hello DPP.");
}
https://run.dlang.io/is/QnRbFt
run.dlang.io supports third-party libraries. A few examples:
/+dub.sdl:
dependency "mir" version="~>1.1.1"
+/
import std.stdio;
import mir.combinatorics;
void main(string[] args)
{
writeln([1, 2].combinations);
}
https://run.dlang.io/is/FIc6rd
/+dub.sdl:
dependency "mir-algorithm" version="~>0.6.14"
+/
import std.stdio;
void main(string[] args)
{
import mir.ndslice.topology : iota;
import mir.ndslice.algorithm : reduce;
auto sl = iota(2, 3);
size_t(0).reduce!"a + b"(sl).writeln;
}
https://run.dlang.io/is/3pNRH8
/+dub.sdl:
dependency "emsi_containers" version="~>0.6.0"
+/
import std.stdio;
void main(string[] args)
{
import containers;
DynamicArray!int arr;
arr ~= 1;
foreach (e; arr)
e.writeln;
}
https://run.dlang.io/is/AOBExl
/+dub.sdl:
dependency "libdparse" version="~>0.7.2-alpha.5"
+/
import dparse.ast;
import std.stdio;
class TestVisitor : ASTVisitor
{
alias visit = ASTVisitor.visit;
override void visit(const FunctionDeclaration decl)
{
decl.name.text.writeln;
}
}
void main()
{
import dparse.lexer;
import dparse.parser : parseModule;
import dparse.rollback_allocator : RollbackAllocator;
import std.array : array;
import std.string : representation;
auto sourceCode = q{
void foo() @safe {}
}.dup;
LexerConfig config;
auto cache = StringCache(StringCache.defaultBucketCount);
auto tokens = getTokensForParser(sourceCode.representation, config, &cache);
RollbackAllocator rba;
auto m = parseModule(tokens.array, "test.d", &rba);
auto visitor = new TestVisitor();
visitor.visit(m);
}
https://run.dlang.io/is/kW7gQr
/+ dub.sdl:
dependency "vibe-d" version="~>0.8.2"
+/
import vibe.d;
import std.stdio;
void main()
{
listenHTTP(":8080", (req, res) {
res.writeBody("Hello, World: " ~ req.path);
});
runTask({
scope (exit) exitEventLoop();
auto req = requestHTTP("http://localhost:8080");
req.bodyReader.readAllUTF8.writeln;
});
runApplication();
}
https://run.dlang.io/is/gI1NA5
/+dub.sdl:
dependency "automem" version="~>0.0.10"
+/
import std.stdio;
import automem;
import core.stdc.stdio;
void main() @nogc
{
import std.experimental.allocator.mallocator : Mallocator;
import std.algorithm : move;
struct Point
{
int x;
int y;
}
// the constructor can also take (size, init) or (size, range) values
auto arr = UniqueArray!(Point, Mallocator)(3);
const Point[3] expected1 = [Point(), Point(), Point()]; // because array literals aren't @nogc
assert(arr[] == expected1);
const Point[1] expected2 = [Point()];
arr.length = 1;
assert(*arr == expected2); //deferencing is the same as slicing all of it
arr ~= UniqueArray!(Point, Mallocator)(1, Point(6, 7));
const Point[2] expected3 = [Point(), Point(6, 7)];
assert(arr[] == expected3);
foreach (a; arr)
printf("%d,%d\n", a.x, a.y);
}
https://run.dlang.io/is/hZE7IT
Add it here: https://github.com/dlang-tour/core-exec/blob/master/Dockerfile
DMD's new JSON output can sometimes be helpful. Simply compile with these parameters:
-Xi=compilerInfo -Xf=-